Annotation of loncom/interface/loncommon.pm, revision 1.793
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.793 ! raeburn 4: # $Id: loncommon.pm,v 1.792 2009/04/24 05:14:09 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.74 www 410: var stdeditbrowser;
1.793 ! raeburn 411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
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.793 ! raeburn 425: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 426: var title = 'Student_Browser';
1.74 www 427: var options = 'scrollbars=1,resizable=1,menubar=0';
428: options += ',width=700,height=600';
429: stdeditbrowser = open(url,title,options,'1');
430: stdeditbrowser.focus();
431: }
432: </script>
433: ENDSTDBRW
434: }
1.42 matthew 435:
1.74 www 436: sub selectstudent_link {
1.793 ! raeburn 437: my ($form,$unameele,$udomele,$courseadvonly)=@_;
! 438: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 439: if ($env{'request.course.id'}) {
1.302 albertel 440: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
441: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
442: '/'.$env{'request.course.sec'})) {
1.111 www 443: return '';
444: }
1.793 ! raeburn 445: if ($courseadvonly) {
! 446: $callargs .= ",'',1,1";
! 447: }
! 448: return '<span class="LC_nobreak">'.
! 449: '<a href="javascript:openstdbrowser('.$callargs.');">'.
! 450: &mt('Select User').'</a></span>';
1.74 www 451: }
1.258 albertel 452: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 ! raeburn 453: $callargs .= ",1";
! 454: return '<span class="LC_nobreak">'.
! 455: '<a href="javascript:openstdbrowser('.$callargs.');">'.
! 456: &mt('Select User').'</a></span>';
1.111 www 457: }
458: return '';
1.91 www 459: }
460:
1.653 raeburn 461: sub authorbrowser_javascript {
462: return <<"ENDAUTHORBRW";
1.776 bisitz 463: <script type="text/javascript" language="JavaScript">
1.653 raeburn 464: var stdeditbrowser;
465:
466: function openauthorbrowser(formname,udom) {
467: var url = '/adm/pickauthor?';
468: url += 'form='+formname+'&roledom='+udom;
469: var title = 'Author_Browser';
470: var options = 'scrollbars=1,resizable=1,menubar=0';
471: options += ',width=700,height=600';
472: stdeditbrowser = open(url,title,options,'1');
473: stdeditbrowser.focus();
474: }
475:
476: </script>
477: ENDAUTHORBRW
478: }
479:
1.91 www 480: sub coursebrowser_javascript {
1.468 raeburn 481: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 482: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468 raeburn 483: my $output = '
1.776 bisitz 484: <script type="text/javascript" language="JavaScript">
1.468 raeburn 485: var stdeditbrowser;'."\n";
486: $output .= <<"ENDSTDBRW";
1.377 raeburn 487: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 488: var url = '/adm/pickcourse?';
1.468 raeburn 489: var domainfilter = '';
490: var formid = getFormIdByName(formname);
491: if (formid > -1) {
492: var domid = getIndexByName(formid,udom);
493: if (domid > -1) {
494: if (document.forms[formid].elements[domid].type == 'select-one') {
495: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
496: }
497: if (document.forms[formid].elements[domid].type == 'hidden') {
498: domainfilter=document.forms[formid].elements[domid].value;
499: }
500: }
1.91 www 501: }
1.128 albertel 502: if (domainfilter != null) {
503: if (domainfilter != '') {
504: url += 'domainfilter='+domainfilter+'&';
505: }
506: }
1.91 www 507: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 508: '&cdomelement='+udom+
509: '&cnameelement='+desc;
1.468 raeburn 510: if (extra_element !=null && extra_element != '') {
1.594 raeburn 511: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 512: url += '&roleelement='+extra_element;
513: if (domainfilter == null || domainfilter == '') {
514: url += '&domainfilter='+extra_element;
515: }
1.234 raeburn 516: }
1.468 raeburn 517: else {
518: if (formname == 'portform') {
519: url += '&setroles='+extra_element;
520: }
521: }
1.230 raeburn 522: }
1.293 raeburn 523: if (multflag !=null && multflag != '') {
524: url += '&multiple='+multflag;
525: }
1.377 raeburn 526: if (crstype == 'Course/Group') {
527: if (formname == 'cu') {
528: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
529: if (crstype == "") {
530: alert("$crs_or_grp_alert");
531: return;
532: }
533: }
534: }
535: if (crstype !=null && crstype != '') {
536: url += '&type='+crstype;
537: }
1.102 www 538: var title = 'Course_Browser';
1.91 www 539: var options = 'scrollbars=1,resizable=1,menubar=0';
540: options += ',width=700,height=600';
541: stdeditbrowser = open(url,title,options,'1');
542: stdeditbrowser.focus();
543: }
1.468 raeburn 544:
545: function getFormIdByName(formname) {
546: for (var i=0;i<document.forms.length;i++) {
547: if (document.forms[i].name == formname) {
548: return i;
549: }
550: }
551: return -1;
552: }
553:
554: function getIndexByName(formid,item) {
555: for (var i=0;i<document.forms[formid].elements.length;i++) {
556: if (document.forms[formid].elements[i].name == item) {
557: return i;
558: }
559: }
560: return -1;
561: }
1.91 www 562: ENDSTDBRW
1.468 raeburn 563: if ($sec_element ne '') {
564: $output .= &setsec_javascript($sec_element,$formname);
565: }
566: $output .= '
567: </script>';
568: return $output;
569: }
570:
571: sub setsec_javascript {
572: my ($sec_element,$formname) = @_;
573: my $setsections = qq|
574: function setSect(sectionlist) {
1.629 raeburn 575: var sectionsArray = new Array();
576: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
577: sectionsArray = sectionlist.split(",");
578: }
1.468 raeburn 579: var numSections = sectionsArray.length;
580: document.$formname.$sec_element.length = 0;
581: if (numSections == 0) {
582: document.$formname.$sec_element.multiple=false;
583: document.$formname.$sec_element.size=1;
584: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
585: } else {
586: if (numSections == 1) {
587: document.$formname.$sec_element.multiple=false;
588: document.$formname.$sec_element.size=1;
589: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
590: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
591: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
592: } else {
593: for (var i=0; i<numSections; i++) {
594: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
595: }
596: document.$formname.$sec_element.multiple=true
597: if (numSections < 3) {
598: document.$formname.$sec_element.size=numSections;
599: } else {
600: document.$formname.$sec_element.size=3;
601: }
602: document.$formname.$sec_element.options[0].selected = false
603: }
604: }
1.91 www 605: }
1.468 raeburn 606: |;
607: return $setsections;
608: }
609:
1.91 www 610:
611: sub selectcourse_link {
1.377 raeburn 612: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787 bisitz 613: return '<span class="LC_nobreak">'
614: ."<a href='"
615: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
616: .'","'.$udomele.'","'.$desc.'","'.$extra_element
617: .'","'.$multflag.'","'.$selecttype.'");'
618: ."'>".&mt('Select Course').'</a>'
619: .'</span>';
1.74 www 620: }
1.42 matthew 621:
1.653 raeburn 622: sub selectauthor_link {
623: my ($form,$udom)=@_;
624: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
625: &mt('Select Author').'</a>';
626: }
627:
1.273 raeburn 628: sub check_uncheck_jscript {
629: my $jscript = <<"ENDSCRT";
630: function checkAll(field) {
631: if (field.length > 0) {
632: for (i = 0; i < field.length; i++) {
633: field[i].checked = true ;
634: }
635: } else {
636: field.checked = true
637: }
638: }
639:
640: function uncheckAll(field) {
641: if (field.length > 0) {
642: for (i = 0; i < field.length; i++) {
643: field[i].checked = false ;
1.543 albertel 644: }
645: } else {
1.273 raeburn 646: field.checked = false ;
647: }
648: }
649: ENDSCRT
650: return $jscript;
651: }
652:
1.656 www 653: sub select_timezone {
1.659 raeburn 654: my ($name,$selected,$onchange,$includeempty)=@_;
655: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
656: if ($includeempty) {
657: $output .= '<option value=""';
658: if (($selected eq '') || ($selected eq 'local')) {
659: $output .= ' selected="selected" ';
660: }
661: $output .= '> </option>';
662: }
1.657 raeburn 663: my @timezones = DateTime::TimeZone->all_names;
664: foreach my $tzone (@timezones) {
665: $output.= '<option value="'.$tzone.'"';
666: if ($tzone eq $selected) {
667: $output.=' selected="selected"';
668: }
669: $output.=">$tzone</option>\n";
1.656 www 670: }
671: $output.="</select>";
672: return $output;
673: }
1.273 raeburn 674:
1.687 raeburn 675: sub select_datelocale {
676: my ($name,$selected,$onchange,$includeempty)=@_;
677: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
678: if ($includeempty) {
679: $output .= '<option value=""';
680: if ($selected eq '') {
681: $output .= ' selected="selected" ';
682: }
683: $output .= '> </option>';
684: }
685: my (@possibles,%locale_names);
686: my @locales = DateTime::Locale::Catalog::Locales;
687: foreach my $locale (@locales) {
688: if (ref($locale) eq 'HASH') {
689: my $id = $locale->{'id'};
690: if ($id ne '') {
691: my $en_terr = $locale->{'en_territory'};
692: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 693: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 694: if (grep(/^en$/,@languages) || !@languages) {
695: if ($en_terr ne '') {
696: $locale_names{$id} = '('.$en_terr.')';
697: } elsif ($native_terr ne '') {
698: $locale_names{$id} = $native_terr;
699: }
700: } else {
701: if ($native_terr ne '') {
702: $locale_names{$id} = $native_terr.' ';
703: } elsif ($en_terr ne '') {
704: $locale_names{$id} = '('.$en_terr.')';
705: }
706: }
707: push (@possibles,$id);
708: }
709: }
710: }
711: foreach my $item (sort(@possibles)) {
712: $output.= '<option value="'.$item.'"';
713: if ($item eq $selected) {
714: $output.=' selected="selected"';
715: }
716: $output.=">$item";
717: if ($locale_names{$item} ne '') {
718: $output.=" $locale_names{$item}</option>\n";
719: }
720: $output.="</option>\n";
721: }
722: $output.="</select>";
723: return $output;
724: }
725:
1.792 raeburn 726: sub select_language {
727: my ($name,$selected,$includeempty) = @_;
728: my %langchoices;
729: if ($includeempty) {
730: %langchoices = ('' => 'No language preference');
731: }
732: foreach my $id (&languageids()) {
733: my $code = &supportedlanguagecode($id);
734: if ($code) {
735: $langchoices{$code} = &plainlanguagedescription($id);
736: }
737: }
738: return &select_form($selected,$name,%langchoices);
739: }
740:
1.42 matthew 741: =pod
1.36 matthew 742:
1.648 raeburn 743: =item * &linked_select_forms(...)
1.36 matthew 744:
745: linked_select_forms returns a string containing a <script></script> block
746: and html for two <select> menus. The select menus will be linked in that
747: changing the value of the first menu will result in new values being placed
748: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 749: order unless a defined order is provided.
1.36 matthew 750:
751: linked_select_forms takes the following ordered inputs:
752:
753: =over 4
754:
1.112 bowersj2 755: =item * $formname, the name of the <form> tag
1.36 matthew 756:
1.112 bowersj2 757: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 758:
1.112 bowersj2 759: =item * $firstdefault, the default value for the first menu
1.36 matthew 760:
1.112 bowersj2 761: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 762:
1.112 bowersj2 763: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 764:
1.112 bowersj2 765: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 766:
1.609 raeburn 767: =item * $menuorder, the order of values in the first menu
768:
1.41 ng 769: =back
770:
1.36 matthew 771: Below is an example of such a hash. Only the 'text', 'default', and
772: 'select2' keys must appear as stated. keys(%menu) are the possible
773: values for the first select menu. The text that coincides with the
1.41 ng 774: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 775: and text for the second menu are given in the hash pointed to by
776: $menu{$choice1}->{'select2'}.
777:
1.112 bowersj2 778: my %menu = ( A1 => { text =>"Choice A1" ,
779: default => "B3",
780: select2 => {
781: B1 => "Choice B1",
782: B2 => "Choice B2",
783: B3 => "Choice B3",
784: B4 => "Choice B4"
1.609 raeburn 785: },
786: order => ['B4','B3','B1','B2'],
1.112 bowersj2 787: },
788: A2 => { text =>"Choice A2" ,
789: default => "C2",
790: select2 => {
791: C1 => "Choice C1",
792: C2 => "Choice C2",
793: C3 => "Choice C3"
1.609 raeburn 794: },
795: order => ['C2','C1','C3'],
1.112 bowersj2 796: },
797: A3 => { text =>"Choice A3" ,
798: default => "D6",
799: select2 => {
800: D1 => "Choice D1",
801: D2 => "Choice D2",
802: D3 => "Choice D3",
803: D4 => "Choice D4",
804: D5 => "Choice D5",
805: D6 => "Choice D6",
806: D7 => "Choice D7"
1.609 raeburn 807: },
808: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 809: }
810: );
1.36 matthew 811:
812: =cut
813:
814: sub linked_select_forms {
815: my ($formname,
816: $middletext,
817: $firstdefault,
818: $firstselectname,
819: $secondselectname,
1.609 raeburn 820: $hashref,
821: $menuorder,
1.36 matthew 822: ) = @_;
823: my $second = "document.$formname.$secondselectname";
824: my $first = "document.$formname.$firstselectname";
825: # output the javascript to do the changing
826: my $result = '';
1.776 bisitz 827: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36 matthew 828: $result.="var select2data = new Object();\n";
829: $" = '","';
830: my $debug = '';
831: foreach my $s1 (sort(keys(%$hashref))) {
832: $result.="select2data.d_$s1 = new Object();\n";
833: $result.="select2data.d_$s1.def = new String('".
834: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 835: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 836: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 837: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
838: @s2values = @{$hashref->{$s1}->{'order'}};
839: }
1.36 matthew 840: $result.="\"@s2values\");\n";
841: $result.="select2data.d_$s1.texts = new Array(";
842: my @s2texts;
843: foreach my $value (@s2values) {
844: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
845: }
846: $result.="\"@s2texts\");\n";
847: }
848: $"=' ';
849: $result.= <<"END";
850:
851: function select1_changed() {
852: // Determine new choice
853: var newvalue = "d_" + $first.value;
854: // update select2
855: var values = select2data[newvalue].values;
856: var texts = select2data[newvalue].texts;
857: var select2def = select2data[newvalue].def;
858: var i;
859: // out with the old
860: for (i = 0; i < $second.options.length; i++) {
861: $second.options[i] = null;
862: }
863: // in with the nuclear
864: for (i=0;i<values.length; i++) {
865: $second.options[i] = new Option(values[i]);
1.143 matthew 866: $second.options[i].value = values[i];
1.36 matthew 867: $second.options[i].text = texts[i];
868: if (values[i] == select2def) {
869: $second.options[i].selected = true;
870: }
871: }
872: }
873: </script>
874: END
875: # output the initial values for the selection lists
876: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 877: my @order = sort(keys(%{$hashref}));
878: if (ref($menuorder) eq 'ARRAY') {
879: @order = @{$menuorder};
880: }
881: foreach my $value (@order) {
1.36 matthew 882: $result.=" <option value=\"$value\" ";
1.253 albertel 883: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 884: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 885: }
886: $result .= "</select>\n";
887: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
888: $result .= $middletext;
889: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
890: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 891:
892: my @secondorder = sort(keys(%select2));
893: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
894: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
895: }
896: foreach my $value (@secondorder) {
1.36 matthew 897: $result.=" <option value=\"$value\" ";
1.253 albertel 898: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 899: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 900: }
901: $result .= "</select>\n";
902: # return $debug;
903: return $result;
904: } # end of sub linked_select_forms {
905:
1.45 matthew 906: =pod
1.44 bowersj2 907:
1.648 raeburn 908: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 909:
1.112 bowersj2 910: Returns a string corresponding to an HTML link to the given help
911: $topic, where $topic corresponds to the name of a .tex file in
912: /home/httpd/html/adm/help/tex, with underscores replaced by
913: spaces.
914:
915: $text will optionally be linked to the same topic, allowing you to
916: link text in addition to the graphic. If you do not want to link
917: text, but wish to specify one of the later parameters, pass an
918: empty string.
919:
920: $stayOnPage is a value that will be interpreted as a boolean. If true,
921: the link will not open a new window. If false, the link will open
922: a new window using Javascript. (Default is false.)
923:
924: $width and $height are optional numerical parameters that will
925: override the width and height of the popped up window, which may
926: be useful for certain help topics with big pictures included.
1.44 bowersj2 927:
928: =cut
929:
930: sub help_open_topic {
1.48 bowersj2 931: my ($topic, $text, $stayOnPage, $width, $height) = @_;
932: $text = "" if (not defined $text);
1.44 bowersj2 933: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 934: if ($env{'browser.interface'} eq 'textual') {
1.79 www 935: $stayOnPage=1;
936: }
1.44 bowersj2 937: $width = 350 if (not defined $width);
938: $height = 400 if (not defined $height);
939: my $filename = $topic;
940: $filename =~ s/ /_/g;
941:
1.48 bowersj2 942: my $template = "";
943: my $link;
1.572 banghart 944:
1.159 www 945: $topic=~s/\W/\_/g;
1.44 bowersj2 946:
1.572 banghart 947: if (!$stayOnPage) {
1.72 bowersj2 948: $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 949: } else {
1.48 bowersj2 950: $link = "/adm/help/${filename}.hlp";
951: }
952:
953: # Add the text
1.755 neumanie 954: if ($text ne "") {
1.763 bisitz 955: $template.='<span class="LC_help_open_topic">'
956: .'<a target="_top" href="'.$link.'">'
957: .$text.'</a>';
1.48 bowersj2 958: }
959:
1.763 bisitz 960: # (Always) Add the graphic
1.179 matthew 961: my $title = &mt('Online Help');
1.667 raeburn 962: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 963: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
964: .'<img src="'.$helpicon.'" border="0"'
965: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 966: .' title="'.$title.'"'
1.763 bisitz 967: .' /></a>';
968: if ($text ne "") {
969: $template.='</span>';
970: }
1.44 bowersj2 971: return $template;
972:
1.106 bowersj2 973: }
974:
975: # This is a quicky function for Latex cheatsheet editing, since it
976: # appears in at least four places
977: sub helpLatexCheatsheet {
1.732 raeburn 978: my ($topic,$text,$not_author) = @_;
979: my $out;
1.106 bowersj2 980: my $addOther = '';
1.732 raeburn 981: if ($topic) {
1.763 bisitz 982: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
983: undef, undef, 600).
984: '</span> ';
985: }
986: $out = '<span>' # Start cheatsheet
987: .$addOther
988: .'<span>'
989: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
990: undef,undef,600)
991: .'</span> <span>'
992: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
993: undef,undef,600)
994: .'</span>';
1.732 raeburn 995: unless ($not_author) {
1.763 bisitz 996: $out .= ' <span>'
997: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
998: undef,undef,600)
999: .'</span>';
1.732 raeburn 1000: }
1.763 bisitz 1001: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1002: return $out;
1.172 www 1003: }
1004:
1.430 albertel 1005: sub general_help {
1006: my $helptopic='Student_Intro';
1007: if ($env{'request.role'}=~/^(ca|au)/) {
1008: $helptopic='Authoring_Intro';
1009: } elsif ($env{'request.role'}=~/^cc/) {
1010: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1011: } elsif ($env{'request.role'}=~/^dc/) {
1012: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1013: }
1014: return $helptopic;
1015: }
1016:
1017: sub update_help_link {
1018: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1019: my $origurl = $ENV{'REQUEST_URI'};
1020: $origurl=~s|^/~|/priv/|;
1021: my $timestamp = time;
1022: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1023: $$datum = &escape($$datum);
1024: }
1025:
1026: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1027: my $output .= <<"ENDOUTPUT";
1028: <script type="text/javascript">
1029: banner_link = '$banner_link';
1030: </script>
1031: ENDOUTPUT
1032: return $output;
1033: }
1034:
1035: # now just updates the help link and generates a blue icon
1.193 raeburn 1036: sub help_open_menu {
1.430 albertel 1037: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1038: = @_;
1.430 albertel 1039: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1040: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1041: # if environment.remote is on (using remote control UI)
1.572 banghart 1042: if ($env{'browser.interface'} eq 'textual' ||
1043: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1044: $stayOnPage=1;
1.430 albertel 1045: }
1046: my $output;
1047: if ($component_help) {
1048: if (!$text) {
1049: $output=&help_open_topic($component_help,undef,$stayOnPage,
1050: $width,$height);
1051: } else {
1052: my $help_text;
1053: $help_text=&unescape($topic);
1054: $output='<table><tr><td>'.
1055: &help_open_topic($component_help,$help_text,$stayOnPage,
1056: $width,$height).'</td></tr></table>';
1057: }
1058: }
1059: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1060: return $output.$banner_link;
1061: }
1062:
1063: sub top_nav_help {
1064: my ($text) = @_;
1.436 albertel 1065: $text = &mt($text);
1.572 banghart 1066: my $stay_on_page =
1.436 albertel 1067: ($env{'browser.interface'} eq 'textual' ||
1068: $env{'environment.remote'} eq 'off' );
1.572 banghart 1069: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1070: : "javascript:helpMenu('open')";
1.572 banghart 1071: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1072:
1.201 raeburn 1073: my $title = &mt('Get help');
1.436 albertel 1074:
1075: return <<"END";
1076: $banner_link
1077: <a href="$link" title="$title">$text</a>
1078: END
1079: }
1080:
1081: sub help_menu_js {
1082: my ($text) = @_;
1083:
1084: my $stayOnPage =
1085: ($env{'browser.interface'} eq 'textual' ||
1086: $env{'environment.remote'} eq 'off' );
1087:
1088: my $width = 620;
1089: my $height = 600;
1.430 albertel 1090: my $helptopic=&general_help();
1091: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1092: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1093: my $start_page =
1094: &Apache::loncommon::start_page('Help Menu', undef,
1095: {'frameset' => 1,
1096: 'js_ready' => 1,
1097: 'add_entries' => {
1098: 'border' => '0',
1.579 raeburn 1099: 'rows' => "110,*",},});
1.331 albertel 1100: my $end_page =
1101: &Apache::loncommon::end_page({'frameset' => 1,
1102: 'js_ready' => 1,});
1103:
1.436 albertel 1104: my $template .= <<"ENDTEMPLATE";
1105: <script type="text/javascript">
1.253 albertel 1106: // <!-- BEGIN LON-CAPA Internal
1107: // <![CDATA[
1.430 albertel 1108: var banner_link = '';
1.243 raeburn 1109: function helpMenu(target) {
1110: var caller = this;
1111: if (target == 'open') {
1112: var newWindow = null;
1113: try {
1.262 albertel 1114: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1115: }
1116: catch(error) {
1117: writeHelp(caller);
1118: return;
1119: }
1120: if (newWindow) {
1121: caller = newWindow;
1122: }
1.193 raeburn 1123: }
1.243 raeburn 1124: writeHelp(caller);
1125: return;
1126: }
1127: function writeHelp(caller) {
1.430 albertel 1128: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1129: caller.document.close()
1130: caller.focus()
1.193 raeburn 1131: }
1.253 albertel 1132: // ]]>
1.219 albertel 1133: // END LON-CAPA Internal -->
1.436 albertel 1134: </script>
1.193 raeburn 1135: ENDTEMPLATE
1136: return $template;
1137: }
1138:
1.172 www 1139: sub help_open_bug {
1140: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1141: unless ($env{'user.adv'}) { return ''; }
1.172 www 1142: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1143: $text = "" if (not defined $text);
1144: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1145: if ($env{'browser.interface'} eq 'textual' ||
1146: $env{'environment.remote'} eq 'off' ) {
1.172 www 1147: $stayOnPage=1;
1148: }
1.184 albertel 1149: $width = 600 if (not defined $width);
1150: $height = 600 if (not defined $height);
1.172 www 1151:
1152: $topic=~s/\W+/\+/g;
1153: my $link='';
1154: my $template='';
1.379 albertel 1155: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1156: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1157: if (!$stayOnPage)
1158: {
1159: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1160: }
1161: else
1162: {
1163: $link = $url;
1164: }
1165: # Add the text
1166: if ($text ne "")
1167: {
1168: $template .=
1169: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1170: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1171: }
1172:
1173: # Add the graphic
1.179 matthew 1174: my $title = &mt('Report a Bug');
1.215 albertel 1175: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1176: $template .= <<"ENDTEMPLATE";
1.436 albertel 1177: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1178: ENDTEMPLATE
1179: if ($text ne '') { $template.='</td></tr></table>' };
1180: return $template;
1181:
1182: }
1183:
1184: sub help_open_faq {
1185: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1186: unless ($env{'user.adv'}) { return ''; }
1.172 www 1187: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1188: $text = "" if (not defined $text);
1189: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1190: if ($env{'browser.interface'} eq 'textual' ||
1191: $env{'environment.remote'} eq 'off' ) {
1.172 www 1192: $stayOnPage=1;
1193: }
1194: $width = 350 if (not defined $width);
1195: $height = 400 if (not defined $height);
1196:
1197: $topic=~s/\W+/\+/g;
1198: my $link='';
1199: my $template='';
1200: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1201: if (!$stayOnPage)
1202: {
1203: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1204: }
1205: else
1206: {
1207: $link = $url;
1208: }
1209:
1210: # Add the text
1211: if ($text ne "")
1212: {
1213: $template .=
1.173 www 1214: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1215: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1216: }
1217:
1218: # Add the graphic
1.179 matthew 1219: my $title = &mt('View the FAQ');
1.215 albertel 1220: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1221: $template .= <<"ENDTEMPLATE";
1.436 albertel 1222: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1223: ENDTEMPLATE
1224: if ($text ne '') { $template.='</td></tr></table>' };
1225: return $template;
1226:
1.44 bowersj2 1227: }
1.37 matthew 1228:
1.180 matthew 1229: ###############################################################
1230: ###############################################################
1231:
1.45 matthew 1232: =pod
1233:
1.648 raeburn 1234: =item * &change_content_javascript():
1.256 matthew 1235:
1236: This and the next function allow you to create small sections of an
1237: otherwise static HTML page that you can update on the fly with
1238: Javascript, even in Netscape 4.
1239:
1240: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1241: must be written to the HTML page once. It will prove the Javascript
1242: function "change(name, content)". Calling the change function with the
1243: name of the section
1244: you want to update, matching the name passed to C<changable_area>, and
1245: the new content you want to put in there, will put the content into
1246: that area.
1247:
1248: B<Note>: Netscape 4 only reserves enough space for the changable area
1249: to contain room for the original contents. You need to "make space"
1250: for whatever changes you wish to make, and be B<sure> to check your
1251: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1252: it's adequate for updating a one-line status display, but little more.
1253: This script will set the space to 100% width, so you only need to
1254: worry about height in Netscape 4.
1255:
1256: Modern browsers are much less limiting, and if you can commit to the
1257: user not using Netscape 4, this feature may be used freely with
1258: pretty much any HTML.
1259:
1260: =cut
1261:
1262: sub change_content_javascript {
1263: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1264: if ($env{'browser.type'} eq 'netscape' &&
1265: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1266: return (<<NETSCAPE4);
1267: function change(name, content) {
1268: doc = document.layers[name+"___escape"].layers[0].document;
1269: doc.open();
1270: doc.write(content);
1271: doc.close();
1272: }
1273: NETSCAPE4
1274: } else {
1275: # Otherwise, we need to use semi-standards-compliant code
1276: # (technically, "innerHTML" isn't standard but the equivalent
1277: # is really scary, and every useful browser supports it
1278: return (<<DOMBASED);
1279: function change(name, content) {
1280: element = document.getElementById(name);
1281: element.innerHTML = content;
1282: }
1283: DOMBASED
1284: }
1285: }
1286:
1287: =pod
1288:
1.648 raeburn 1289: =item * &changable_area($name,$origContent):
1.256 matthew 1290:
1291: This provides a "changable area" that can be modified on the fly via
1292: the Javascript code provided in C<change_content_javascript>. $name is
1293: the name you will use to reference the area later; do not repeat the
1294: same name on a given HTML page more then once. $origContent is what
1295: the area will originally contain, which can be left blank.
1296:
1297: =cut
1298:
1299: sub changable_area {
1300: my ($name, $origContent) = @_;
1301:
1.258 albertel 1302: if ($env{'browser.type'} eq 'netscape' &&
1303: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1304: # If this is netscape 4, we need to use the Layer tag
1305: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1306: } else {
1307: return "<span id='$name'>$origContent</span>";
1308: }
1309: }
1310:
1311: =pod
1312:
1.648 raeburn 1313: =item * &viewport_geometry_js
1.590 raeburn 1314:
1315: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1316:
1317: =cut
1318:
1319:
1320: sub viewport_geometry_js {
1321: return <<"GEOMETRY";
1322: var Geometry = {};
1323: function init_geometry() {
1324: if (Geometry.init) { return };
1325: Geometry.init=1;
1326: if (window.innerHeight) {
1327: Geometry.getViewportHeight = function() { return window.innerHeight; };
1328: Geometry.getViewportWidth = function() { return window.innerWidth; };
1329: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1330: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1331: }
1332: else if (document.documentElement && document.documentElement.clientHeight) {
1333: Geometry.getViewportHeight =
1334: function() { return document.documentElement.clientHeight; };
1335: Geometry.getViewportWidth =
1336: function() { return document.documentElement.clientWidth; };
1337:
1338: Geometry.getHorizontalScroll =
1339: function() { return document.documentElement.scrollLeft; };
1340: Geometry.getVerticalScroll =
1341: function() { return document.documentElement.scrollTop; };
1342: }
1343: else if (document.body.clientHeight) {
1344: Geometry.getViewportHeight =
1345: function() { return document.body.clientHeight; };
1346: Geometry.getViewportWidth =
1347: function() { return document.body.clientWidth; };
1348: Geometry.getHorizontalScroll =
1349: function() { return document.body.scrollLeft; };
1350: Geometry.getVerticalScroll =
1351: function() { return document.body.scrollTop; };
1352: }
1353: }
1354:
1355: GEOMETRY
1356: }
1357:
1358: =pod
1359:
1.648 raeburn 1360: =item * &viewport_size_js()
1.590 raeburn 1361:
1362: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1363:
1364: =cut
1365:
1366: sub viewport_size_js {
1367: my $geometry = &viewport_geometry_js();
1368: return <<"DIMS";
1369:
1370: $geometry
1371:
1372: function getViewportDims(width,height) {
1373: init_geometry();
1374: width.value = Geometry.getViewportWidth();
1375: height.value = Geometry.getViewportHeight();
1376: return;
1377: }
1378:
1379: DIMS
1380: }
1381:
1382: =pod
1383:
1.648 raeburn 1384: =item * &resize_textarea_js()
1.565 albertel 1385:
1386: emits the needed javascript to resize a textarea to be as big as possible
1387:
1388: creates a function resize_textrea that takes two IDs first should be
1389: the id of the element to resize, second should be the id of a div that
1390: surrounds everything that comes after the textarea, this routine needs
1391: to be attached to the <body> for the onload and onresize events.
1392:
1.648 raeburn 1393: =back
1.565 albertel 1394:
1395: =cut
1396:
1397: sub resize_textarea_js {
1.590 raeburn 1398: my $geometry = &viewport_geometry_js();
1.565 albertel 1399: return <<"RESIZE";
1400: <script type="text/javascript">
1.590 raeburn 1401: $geometry
1.565 albertel 1402:
1.588 albertel 1403: function getX(element) {
1404: var x = 0;
1405: while (element) {
1406: x += element.offsetLeft;
1407: element = element.offsetParent;
1408: }
1409: return x;
1410: }
1411: function getY(element) {
1412: var y = 0;
1413: while (element) {
1414: y += element.offsetTop;
1415: element = element.offsetParent;
1416: }
1417: return y;
1418: }
1419:
1420:
1.565 albertel 1421: function resize_textarea(textarea_id,bottom_id) {
1422: init_geometry();
1423: var textarea = document.getElementById(textarea_id);
1424: //alert(textarea);
1425:
1.588 albertel 1426: var textarea_top = getY(textarea);
1.565 albertel 1427: var textarea_height = textarea.offsetHeight;
1428: var bottom = document.getElementById(bottom_id);
1.588 albertel 1429: var bottom_top = getY(bottom);
1.565 albertel 1430: var bottom_height = bottom.offsetHeight;
1431: var window_height = Geometry.getViewportHeight();
1.588 albertel 1432: var fudge = 23;
1.565 albertel 1433: var new_height = window_height-fudge-textarea_top-bottom_height;
1434: if (new_height < 300) {
1435: new_height = 300;
1436: }
1437: textarea.style.height=new_height+'px';
1438: }
1439: </script>
1440: RESIZE
1441:
1442: }
1443:
1444: =pod
1445:
1.256 matthew 1446: =head1 Excel and CSV file utility routines
1447:
1448: =over 4
1449:
1450: =cut
1451:
1452: ###############################################################
1453: ###############################################################
1454:
1455: =pod
1456:
1.648 raeburn 1457: =item * &csv_translate($text)
1.37 matthew 1458:
1.185 www 1459: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1460: format.
1461:
1462: =cut
1463:
1.180 matthew 1464: ###############################################################
1465: ###############################################################
1.37 matthew 1466: sub csv_translate {
1467: my $text = shift;
1468: $text =~ s/\"/\"\"/g;
1.209 albertel 1469: $text =~ s/\n/ /g;
1.37 matthew 1470: return $text;
1471: }
1.180 matthew 1472:
1473: ###############################################################
1474: ###############################################################
1475:
1476: =pod
1477:
1.648 raeburn 1478: =item * &define_excel_formats()
1.180 matthew 1479:
1480: Define some commonly used Excel cell formats.
1481:
1482: Currently supported formats:
1483:
1484: =over 4
1485:
1486: =item header
1487:
1488: =item bold
1489:
1490: =item h1
1491:
1492: =item h2
1493:
1494: =item h3
1495:
1.256 matthew 1496: =item h4
1497:
1498: =item i
1499:
1.180 matthew 1500: =item date
1501:
1502: =back
1503:
1504: Inputs: $workbook
1505:
1506: Returns: $format, a hash reference.
1507:
1508: =cut
1509:
1510: ###############################################################
1511: ###############################################################
1512: sub define_excel_formats {
1513: my ($workbook) = @_;
1514: my $format;
1515: $format->{'header'} = $workbook->add_format(bold => 1,
1516: bottom => 1,
1517: align => 'center');
1518: $format->{'bold'} = $workbook->add_format(bold=>1);
1519: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1520: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1521: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1522: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1523: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1524: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1525: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1526: return $format;
1527: }
1528:
1529: ###############################################################
1530: ###############################################################
1.113 bowersj2 1531:
1532: =pod
1533:
1.648 raeburn 1534: =item * &create_workbook()
1.255 matthew 1535:
1536: Create an Excel worksheet. If it fails, output message on the
1537: request object and return undefs.
1538:
1539: Inputs: Apache request object
1540:
1541: Returns (undef) on failure,
1542: Excel worksheet object, scalar with filename, and formats
1543: from &Apache::loncommon::define_excel_formats on success
1544:
1545: =cut
1546:
1547: ###############################################################
1548: ###############################################################
1549: sub create_workbook {
1550: my ($r) = @_;
1551: #
1552: # Create the excel spreadsheet
1553: my $filename = '/prtspool/'.
1.258 albertel 1554: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1555: time.'_'.rand(1000000000).'.xls';
1556: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1557: if (! defined($workbook)) {
1558: $r->log_error("Error creating excel spreadsheet $filename: $!");
1559: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1560: "This error has been logged. ".
1561: "Please alert your LON-CAPA administrator").
1562: '</p>');
1563: return (undef);
1564: }
1565: #
1566: $workbook->set_tempdir('/home/httpd/perl/tmp');
1567: #
1568: my $format = &Apache::loncommon::define_excel_formats($workbook);
1569: return ($workbook,$filename,$format);
1570: }
1571:
1572: ###############################################################
1573: ###############################################################
1574:
1575: =pod
1576:
1.648 raeburn 1577: =item * &create_text_file()
1.113 bowersj2 1578:
1.542 raeburn 1579: Create a file to write to and eventually make available to the user.
1.256 matthew 1580: If file creation fails, outputs an error message on the request object and
1581: return undefs.
1.113 bowersj2 1582:
1.256 matthew 1583: Inputs: Apache request object, and file suffix
1.113 bowersj2 1584:
1.256 matthew 1585: Returns (undef) on failure,
1586: Filehandle and filename on success.
1.113 bowersj2 1587:
1588: =cut
1589:
1.256 matthew 1590: ###############################################################
1591: ###############################################################
1592: sub create_text_file {
1593: my ($r,$suffix) = @_;
1594: if (! defined($suffix)) { $suffix = 'txt'; };
1595: my $fh;
1596: my $filename = '/prtspool/'.
1.258 albertel 1597: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1598: time.'_'.rand(1000000000).'.'.$suffix;
1599: $fh = Apache::File->new('>/home/httpd'.$filename);
1600: if (! defined($fh)) {
1601: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1602: $r->print(&mt('Problems occurred in creating the output file. '
1603: .'This error has been logged. '
1604: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1605: }
1.256 matthew 1606: return ($fh,$filename)
1.113 bowersj2 1607: }
1608:
1609:
1.256 matthew 1610: =pod
1.113 bowersj2 1611:
1612: =back
1613:
1614: =cut
1.37 matthew 1615:
1616: ###############################################################
1.33 matthew 1617: ## Home server <option> list generating code ##
1618: ###############################################################
1.35 matthew 1619:
1.169 www 1620: # ------------------------------------------
1621:
1622: sub domain_select {
1623: my ($name,$value,$multiple)=@_;
1624: my %domains=map {
1.514 albertel 1625: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1626: } &Apache::lonnet::all_domains();
1.169 www 1627: if ($multiple) {
1628: $domains{''}=&mt('Any domain');
1.550 albertel 1629: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1630: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1631: } else {
1.550 albertel 1632: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1633: return &select_form($name,$value,%domains);
1634: }
1635: }
1636:
1.282 albertel 1637: #-------------------------------------------
1638:
1639: =pod
1640:
1.519 raeburn 1641: =head1 Routines for form select boxes
1642:
1643: =over 4
1644:
1.648 raeburn 1645: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1646:
1647: Returns a string containing a <select> element int multiple mode
1648:
1649:
1650: Args:
1651: $name - name of the <select> element
1.506 raeburn 1652: $value - scalar or array ref of values that should already be selected
1.282 albertel 1653: $size - number of rows long the select element is
1.283 albertel 1654: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1655: (shown text should already have been &mt())
1.506 raeburn 1656: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1657:
1.282 albertel 1658: =cut
1659:
1660: #-------------------------------------------
1.169 www 1661: sub multiple_select_form {
1.284 albertel 1662: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1663: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1664: my $output='';
1.191 matthew 1665: if (! defined($size)) {
1666: $size = 4;
1.283 albertel 1667: if (scalar(keys(%$hash))<4) {
1668: $size = scalar(keys(%$hash));
1.191 matthew 1669: }
1670: }
1.734 bisitz 1671: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1672: my @order;
1.506 raeburn 1673: if (ref($order) eq 'ARRAY') {
1674: @order = @{$order};
1675: } else {
1676: @order = sort(keys(%$hash));
1.501 banghart 1677: }
1678: if (exists($$hash{'select_form_order'})) {
1679: @order = @{$$hash{'select_form_order'}};
1680: }
1681:
1.284 albertel 1682: foreach my $key (@order) {
1.356 albertel 1683: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1684: $output.='selected="selected" ' if ($selected{$key});
1685: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1686: }
1687: $output.="</select>\n";
1688: return $output;
1689: }
1690:
1.88 www 1691: #-------------------------------------------
1692:
1693: =pod
1694:
1.648 raeburn 1695: =item * &select_form($defdom,$name,%hash)
1.88 www 1696:
1697: Returns a string containing a <select name='$name' size='1'> form to
1698: allow a user to select options from a hash option_name => displayed text.
1699: See lonrights.pm for an example invocation and use.
1700:
1701: =cut
1702:
1703: #-------------------------------------------
1704: sub select_form {
1705: my ($def,$name,%hash) = @_;
1706: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1707: my @keys;
1708: if (exists($hash{'select_form_order'})) {
1709: @keys=@{$hash{'select_form_order'}};
1710: } else {
1711: @keys=sort(keys(%hash));
1712: }
1.356 albertel 1713: foreach my $key (@keys) {
1714: $selectform.=
1715: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1716: ($key eq $def ? 'selected="selected" ' : '').
1717: ">".&mt($hash{$key})."</option>\n";
1.88 www 1718: }
1719: $selectform.="</select>";
1720: return $selectform;
1721: }
1722:
1.475 www 1723: # For display filters
1724:
1725: sub display_filter {
1726: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1727: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1728: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1729: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1730: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1731: '</label></span> <span class="LC_nobreak">'.
1.475 www 1732: &mt('Filter [_1]',
1.477 www 1733: &select_form($env{'form.displayfilter'},
1734: 'displayfilter',
1735: ('currentfolder' => 'Current folder/page',
1736: 'containing' => 'Containing phrase',
1737: 'none' => 'None'))).
1.714 bisitz 1738: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1739: }
1740:
1.167 www 1741: sub gradeleveldescription {
1742: my $gradelevel=shift;
1743: my %gradelevels=(0 => 'Not specified',
1744: 1 => 'Grade 1',
1745: 2 => 'Grade 2',
1746: 3 => 'Grade 3',
1747: 4 => 'Grade 4',
1748: 5 => 'Grade 5',
1749: 6 => 'Grade 6',
1750: 7 => 'Grade 7',
1751: 8 => 'Grade 8',
1752: 9 => 'Grade 9',
1753: 10 => 'Grade 10',
1754: 11 => 'Grade 11',
1755: 12 => 'Grade 12',
1756: 13 => 'Grade 13',
1757: 14 => '100 Level',
1758: 15 => '200 Level',
1759: 16 => '300 Level',
1760: 17 => '400 Level',
1761: 18 => 'Graduate Level');
1762: return &mt($gradelevels{$gradelevel});
1763: }
1764:
1.163 www 1765: sub select_level_form {
1766: my ($deflevel,$name)=@_;
1767: unless ($deflevel) { $deflevel=0; }
1.167 www 1768: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1769: for (my $i=0; $i<=18; $i++) {
1770: $selectform.="<option value=\"$i\" ".
1.253 albertel 1771: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1772: ">".&gradeleveldescription($i)."</option>\n";
1773: }
1774: $selectform.="</select>";
1775: return $selectform;
1.163 www 1776: }
1.167 www 1777:
1.35 matthew 1778: #-------------------------------------------
1779:
1.45 matthew 1780: =pod
1781:
1.743 raeburn 1782: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1783:
1784: Returns a string containing a <select name='$name' size='1'> form to
1785: allow a user to select the domain to preform an operation in.
1786: See loncreateuser.pm for an example invocation and use.
1787:
1.90 www 1788: If the $includeempty flag is set, it also includes an empty choice ("no domain
1789: selected");
1790:
1.743 raeburn 1791: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1792:
1793: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1794:
1.35 matthew 1795: =cut
1796:
1797: #-------------------------------------------
1.34 matthew 1798: sub select_dom_form {
1.743 raeburn 1799: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1800: my $onchange;
1801: if ($autosubmit) {
1802: $onchange = ' onchange="this.form.submit()"';
1803: }
1.550 albertel 1804: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1805: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1806: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1807: foreach my $dom (@domains) {
1808: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1809: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1810: if ($showdomdesc) {
1811: if ($dom ne '') {
1812: my $domdesc = &Apache::lonnet::domain($dom,'description');
1813: if ($domdesc ne '') {
1814: $selectdomain .= ' ('.$domdesc.')';
1815: }
1816: }
1817: }
1818: $selectdomain .= "</option>\n";
1.34 matthew 1819: }
1820: $selectdomain.="</select>";
1821: return $selectdomain;
1822: }
1823:
1.35 matthew 1824: #-------------------------------------------
1825:
1.45 matthew 1826: =pod
1827:
1.648 raeburn 1828: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1829:
1.586 raeburn 1830: input: 4 arguments (two required, two optional) -
1831: $domain - domain of new user
1832: $name - name of form element
1833: $default - Value of 'default' causes a default item to be first
1834: option, and selected by default.
1835: $hide - Value of 'hide' causes hiding of the name of the server,
1836: if 1 server found, or default, if 0 found.
1.594 raeburn 1837: output: returns 2 items:
1.586 raeburn 1838: (a) form element which contains either:
1839: (i) <select name="$name">
1840: <option value="$hostid1">$hostid $servers{$hostid}</option>
1841: <option value="$hostid2">$hostid $servers{$hostid}</option>
1842: </select>
1843: form item if there are multiple library servers in $domain, or
1844: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1845: if there is only one library server in $domain.
1846:
1847: (b) number of library servers found.
1848:
1849: See loncreateuser.pm for example of use.
1.35 matthew 1850:
1851: =cut
1852:
1853: #-------------------------------------------
1.586 raeburn 1854: sub home_server_form_item {
1855: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1856: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1857: my $result;
1858: my $numlib = keys(%servers);
1859: if ($numlib > 1) {
1860: $result .= '<select name="'.$name.'" />'."\n";
1861: if ($default) {
1862: $result .= '<option value="default" selected>'.&mt('default').
1863: '</option>'."\n";
1864: }
1865: foreach my $hostid (sort(keys(%servers))) {
1866: $result.= '<option value="'.$hostid.'">'.
1867: $hostid.' '.$servers{$hostid}."</option>\n";
1868: }
1869: $result .= '</select>'."\n";
1870: } elsif ($numlib == 1) {
1871: my $hostid;
1872: foreach my $item (keys(%servers)) {
1873: $hostid = $item;
1874: }
1875: $result .= '<input type="hidden" name="'.$name.'" value="'.
1876: $hostid.'" />';
1877: if (!$hide) {
1878: $result .= $hostid.' '.$servers{$hostid};
1879: }
1880: $result .= "\n";
1881: } elsif ($default) {
1882: $result .= '<input type="hidden" name="'.$name.
1883: '" value="default" />';
1884: if (!$hide) {
1885: $result .= &mt('default');
1886: }
1887: $result .= "\n";
1.33 matthew 1888: }
1.586 raeburn 1889: return ($result,$numlib);
1.33 matthew 1890: }
1.112 bowersj2 1891:
1892: =pod
1893:
1.534 albertel 1894: =back
1895:
1.112 bowersj2 1896: =cut
1.87 matthew 1897:
1898: ###############################################################
1.112 bowersj2 1899: ## Decoding User Agent ##
1.87 matthew 1900: ###############################################################
1901:
1902: =pod
1903:
1.112 bowersj2 1904: =head1 Decoding the User Agent
1905:
1906: =over 4
1907:
1908: =item * &decode_user_agent()
1.87 matthew 1909:
1910: Inputs: $r
1911:
1912: Outputs:
1913:
1914: =over 4
1915:
1.112 bowersj2 1916: =item * $httpbrowser
1.87 matthew 1917:
1.112 bowersj2 1918: =item * $clientbrowser
1.87 matthew 1919:
1.112 bowersj2 1920: =item * $clientversion
1.87 matthew 1921:
1.112 bowersj2 1922: =item * $clientmathml
1.87 matthew 1923:
1.112 bowersj2 1924: =item * $clientunicode
1.87 matthew 1925:
1.112 bowersj2 1926: =item * $clientos
1.87 matthew 1927:
1928: =back
1929:
1.157 matthew 1930: =back
1931:
1.87 matthew 1932: =cut
1933:
1934: ###############################################################
1935: ###############################################################
1936: sub decode_user_agent {
1.247 albertel 1937: my ($r)=@_;
1.87 matthew 1938: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1939: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1940: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1941: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1942: my $clientbrowser='unknown';
1943: my $clientversion='0';
1944: my $clientmathml='';
1945: my $clientunicode='0';
1946: for (my $i=0;$i<=$#browsertype;$i++) {
1947: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1948: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1949: $clientbrowser=$bname;
1950: $httpbrowser=~/$vreg/i;
1951: $clientversion=$1;
1952: $clientmathml=($clientversion>=$minv);
1953: $clientunicode=($clientversion>=$univ);
1954: }
1955: }
1956: my $clientos='unknown';
1957: if (($httpbrowser=~/linux/i) ||
1958: ($httpbrowser=~/unix/i) ||
1959: ($httpbrowser=~/ux/i) ||
1960: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1961: if (($httpbrowser=~/vax/i) ||
1962: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1963: if ($httpbrowser=~/next/i) { $clientos='next'; }
1964: if (($httpbrowser=~/mac/i) ||
1965: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1966: if ($httpbrowser=~/win/i) { $clientos='win'; }
1967: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1968: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1969: $clientunicode,$clientos,);
1970: }
1971:
1.32 matthew 1972: ###############################################################
1973: ## Authentication changing form generation subroutines ##
1974: ###############################################################
1975: ##
1976: ## All of the authform_xxxxxxx subroutines take their inputs in a
1977: ## hash, and have reasonable default values.
1978: ##
1979: ## formname = the name given in the <form> tag.
1.35 matthew 1980: #-------------------------------------------
1981:
1.45 matthew 1982: =pod
1983:
1.112 bowersj2 1984: =head1 Authentication Routines
1985:
1986: =over 4
1987:
1.648 raeburn 1988: =item * &authform_xxxxxx()
1.35 matthew 1989:
1990: The authform_xxxxxx subroutines provide javascript and html forms which
1991: handle some of the conveniences required for authentication forms.
1992: This is not an optimal method, but it works.
1993:
1994: =over 4
1995:
1.112 bowersj2 1996: =item * authform_header
1.35 matthew 1997:
1.112 bowersj2 1998: =item * authform_authorwarning
1.35 matthew 1999:
1.112 bowersj2 2000: =item * authform_nochange
1.35 matthew 2001:
1.112 bowersj2 2002: =item * authform_kerberos
1.35 matthew 2003:
1.112 bowersj2 2004: =item * authform_internal
1.35 matthew 2005:
1.112 bowersj2 2006: =item * authform_filesystem
1.35 matthew 2007:
2008: =back
2009:
1.648 raeburn 2010: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2011:
1.35 matthew 2012: =cut
2013:
2014: #-------------------------------------------
1.32 matthew 2015: sub authform_header{
2016: my %in = (
2017: formname => 'cu',
1.80 albertel 2018: kerb_def_dom => '',
1.32 matthew 2019: @_,
2020: );
2021: $in{'formname'} = 'document.' . $in{'formname'};
2022: my $result='';
1.80 albertel 2023:
2024: #---------------------------------------------- Code for upper case translation
2025: my $Javascript_toUpperCase;
2026: unless ($in{kerb_def_dom}) {
2027: $Javascript_toUpperCase =<<"END";
2028: switch (choice) {
2029: case 'krb': currentform.elements[choicearg].value =
2030: currentform.elements[choicearg].value.toUpperCase();
2031: break;
2032: default:
2033: }
2034: END
2035: } else {
2036: $Javascript_toUpperCase = "";
2037: }
2038:
1.165 raeburn 2039: my $radioval = "'nochange'";
1.591 raeburn 2040: if (defined($in{'curr_authtype'})) {
2041: if ($in{'curr_authtype'} ne '') {
2042: $radioval = "'".$in{'curr_authtype'}."arg'";
2043: }
1.174 matthew 2044: }
1.165 raeburn 2045: my $argfield = 'null';
1.591 raeburn 2046: if (defined($in{'mode'})) {
1.165 raeburn 2047: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2048: if (defined($in{'curr_autharg'})) {
2049: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2050: $argfield = "'$in{'curr_autharg'}'";
2051: }
2052: }
2053: }
2054: }
2055:
1.32 matthew 2056: $result.=<<"END";
2057: var current = new Object();
1.165 raeburn 2058: current.radiovalue = $radioval;
2059: current.argfield = $argfield;
1.32 matthew 2060:
2061: function changed_radio(choice,currentform) {
2062: var choicearg = choice + 'arg';
2063: // If a radio button in changed, we need to change the argfield
2064: if (current.radiovalue != choice) {
2065: current.radiovalue = choice;
2066: if (current.argfield != null) {
2067: currentform.elements[current.argfield].value = '';
2068: }
2069: if (choice == 'nochange') {
2070: current.argfield = null;
2071: } else {
2072: current.argfield = choicearg;
2073: switch(choice) {
2074: case 'krb':
2075: currentform.elements[current.argfield].value =
2076: "$in{'kerb_def_dom'}";
2077: break;
2078: default:
2079: break;
2080: }
2081: }
2082: }
2083: return;
2084: }
1.22 www 2085:
1.32 matthew 2086: function changed_text(choice,currentform) {
2087: var choicearg = choice + 'arg';
2088: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2089: $Javascript_toUpperCase
1.32 matthew 2090: // clear old field
2091: if ((current.argfield != choicearg) && (current.argfield != null)) {
2092: currentform.elements[current.argfield].value = '';
2093: }
2094: current.argfield = choicearg;
2095: }
2096: set_auth_radio_buttons(choice,currentform);
2097: return;
1.20 www 2098: }
1.32 matthew 2099:
2100: function set_auth_radio_buttons(newvalue,currentform) {
2101: var i=0;
2102: while (i < currentform.login.length) {
2103: if (currentform.login[i].value == newvalue) { break; }
2104: i++;
2105: }
2106: if (i == currentform.login.length) {
2107: return;
2108: }
2109: current.radiovalue = newvalue;
2110: currentform.login[i].checked = true;
2111: return;
2112: }
2113: END
2114: return $result;
2115: }
2116:
2117: sub authform_authorwarning{
2118: my $result='';
1.144 matthew 2119: $result='<i>'.
2120: &mt('As a general rule, only authors or co-authors should be '.
2121: 'filesystem authenticated '.
2122: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2123: return $result;
2124: }
2125:
2126: sub authform_nochange{
2127: my %in = (
2128: formname => 'document.cu',
2129: kerb_def_dom => 'MSU.EDU',
2130: @_,
2131: );
1.586 raeburn 2132: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2133: my $result;
2134: if (keys(%can_assign) == 0) {
2135: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2136: } else {
2137: $result = '<label>'.&mt('[_1] Do not change login data',
2138: '<input type="radio" name="login" value="nochange" '.
2139: 'checked="checked" onclick="'.
1.281 albertel 2140: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2141: '</label>';
1.586 raeburn 2142: }
1.32 matthew 2143: return $result;
2144: }
2145:
1.591 raeburn 2146: sub authform_kerberos {
1.32 matthew 2147: my %in = (
2148: formname => 'document.cu',
2149: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2150: kerb_def_auth => 'krb4',
1.32 matthew 2151: @_,
2152: );
1.586 raeburn 2153: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2154: $autharg,$jscall);
2155: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2156: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2157: $check5 = ' checked="checked"';
1.80 albertel 2158: } else {
1.772 bisitz 2159: $check4 = ' checked="checked"';
1.80 albertel 2160: }
1.165 raeburn 2161: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2162: if (defined($in{'curr_authtype'})) {
2163: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2164: $krbcheck = ' checked="checked"';
1.623 raeburn 2165: if (defined($in{'mode'})) {
2166: if ($in{'mode'} eq 'modifyuser') {
2167: $krbcheck = '';
2168: }
2169: }
1.591 raeburn 2170: if (defined($in{'curr_kerb_ver'})) {
2171: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2172: $check5 = ' checked="checked"';
1.591 raeburn 2173: $check4 = '';
2174: } else {
1.772 bisitz 2175: $check4 = ' checked="checked"';
1.591 raeburn 2176: $check5 = '';
2177: }
1.586 raeburn 2178: }
1.591 raeburn 2179: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2180: $krbarg = $in{'curr_autharg'};
2181: }
1.586 raeburn 2182: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2183: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2184: $result =
2185: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2186: $in{'curr_autharg'},$krbver);
2187: } else {
2188: $result =
2189: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2190: }
2191: return $result;
2192: }
2193: }
2194: } else {
2195: if ($authnum == 1) {
1.784 bisitz 2196: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2197: }
2198: }
1.586 raeburn 2199: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2200: return;
1.587 raeburn 2201: } elsif ($authtype eq '') {
1.591 raeburn 2202: if (defined($in{'mode'})) {
1.587 raeburn 2203: if ($in{'mode'} eq 'modifycourse') {
2204: if ($authnum == 1) {
1.784 bisitz 2205: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2206: }
2207: }
2208: }
1.586 raeburn 2209: }
2210: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2211: if ($authtype eq '') {
2212: $authtype = '<input type="radio" name="login" value="krb" '.
2213: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2214: $krbcheck.' />';
2215: }
2216: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2217: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2218: $in{'curr_authtype'} eq 'krb5') ||
2219: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2220: $in{'curr_authtype'} eq 'krb4')) {
2221: $result .= &mt
1.144 matthew 2222: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2223: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2224: '<label>'.$authtype,
1.281 albertel 2225: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2226: 'value="'.$krbarg.'" '.
1.144 matthew 2227: 'onchange="'.$jscall.'" />',
1.281 albertel 2228: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2229: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2230: '</label>');
1.586 raeburn 2231: } elsif ($can_assign{'krb4'}) {
2232: $result .= &mt
2233: ('[_1] Kerberos authenticated with domain [_2] '.
2234: '[_3] Version 4 [_4]',
2235: '<label>'.$authtype,
2236: '</label><input type="text" size="10" name="krbarg" '.
2237: 'value="'.$krbarg.'" '.
2238: 'onchange="'.$jscall.'" />',
2239: '<label><input type="hidden" name="krbver" value="4" />',
2240: '</label>');
2241: } elsif ($can_assign{'krb5'}) {
2242: $result .= &mt
2243: ('[_1] Kerberos authenticated with domain [_2] '.
2244: '[_3] Version 5 [_4]',
2245: '<label>'.$authtype,
2246: '</label><input type="text" size="10" name="krbarg" '.
2247: 'value="'.$krbarg.'" '.
2248: 'onchange="'.$jscall.'" />',
2249: '<label><input type="hidden" name="krbver" value="5" />',
2250: '</label>');
2251: }
1.32 matthew 2252: return $result;
2253: }
2254:
2255: sub authform_internal{
1.586 raeburn 2256: my %in = (
1.32 matthew 2257: formname => 'document.cu',
2258: kerb_def_dom => 'MSU.EDU',
2259: @_,
2260: );
1.586 raeburn 2261: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2262: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2263: if (defined($in{'curr_authtype'})) {
2264: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2265: if ($can_assign{'int'}) {
1.772 bisitz 2266: $intcheck = 'checked="checked" ';
1.623 raeburn 2267: if (defined($in{'mode'})) {
2268: if ($in{'mode'} eq 'modifyuser') {
2269: $intcheck = '';
2270: }
2271: }
1.591 raeburn 2272: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2273: $intarg = $in{'curr_autharg'};
2274: }
2275: } else {
2276: $result = &mt('Currently internally authenticated.');
2277: return $result;
1.165 raeburn 2278: }
2279: }
1.586 raeburn 2280: } else {
2281: if ($authnum == 1) {
1.784 bisitz 2282: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2283: }
2284: }
2285: if (!$can_assign{'int'}) {
2286: return;
1.587 raeburn 2287: } elsif ($authtype eq '') {
1.591 raeburn 2288: if (defined($in{'mode'})) {
1.587 raeburn 2289: if ($in{'mode'} eq 'modifycourse') {
2290: if ($authnum == 1) {
1.784 bisitz 2291: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2292: }
2293: }
2294: }
1.165 raeburn 2295: }
1.586 raeburn 2296: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2297: if ($authtype eq '') {
2298: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2299: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2300: }
1.605 bisitz 2301: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2302: $intarg.'" onchange="'.$jscall.'" />';
2303: $result = &mt
1.144 matthew 2304: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2305: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2306: $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2307: return $result;
2308: }
2309:
2310: sub authform_local{
2311: my %in = (
2312: formname => 'document.cu',
2313: kerb_def_dom => 'MSU.EDU',
2314: @_,
2315: );
1.586 raeburn 2316: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2317: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2318: if (defined($in{'curr_authtype'})) {
2319: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2320: if ($can_assign{'loc'}) {
1.772 bisitz 2321: $loccheck = 'checked="checked" ';
1.623 raeburn 2322: if (defined($in{'mode'})) {
2323: if ($in{'mode'} eq 'modifyuser') {
2324: $loccheck = '';
2325: }
2326: }
1.591 raeburn 2327: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2328: $locarg = $in{'curr_autharg'};
2329: }
2330: } else {
2331: $result = &mt('Currently using local (institutional) authentication.');
2332: return $result;
1.165 raeburn 2333: }
2334: }
1.586 raeburn 2335: } else {
2336: if ($authnum == 1) {
1.784 bisitz 2337: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2338: }
2339: }
2340: if (!$can_assign{'loc'}) {
2341: return;
1.587 raeburn 2342: } elsif ($authtype eq '') {
1.591 raeburn 2343: if (defined($in{'mode'})) {
1.587 raeburn 2344: if ($in{'mode'} eq 'modifycourse') {
2345: if ($authnum == 1) {
1.784 bisitz 2346: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2347: }
2348: }
2349: }
1.165 raeburn 2350: }
1.586 raeburn 2351: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2352: if ($authtype eq '') {
2353: $authtype = '<input type="radio" name="login" value="loc" '.
2354: $loccheck.' onchange="'.$jscall.'" onclick="'.
2355: $jscall.'" />';
2356: }
2357: $autharg = '<input type="text" size="10" name="locarg" value="'.
2358: $locarg.'" onchange="'.$jscall.'" />';
2359: $result = &mt('[_1] Local Authentication with argument [_2]',
2360: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2361: return $result;
2362: }
2363:
2364: sub authform_filesystem{
2365: my %in = (
2366: formname => 'document.cu',
2367: kerb_def_dom => 'MSU.EDU',
2368: @_,
2369: );
1.586 raeburn 2370: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2371: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2372: if (defined($in{'curr_authtype'})) {
2373: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2374: if ($can_assign{'fsys'}) {
1.772 bisitz 2375: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2376: if (defined($in{'mode'})) {
2377: if ($in{'mode'} eq 'modifyuser') {
2378: $fsyscheck = '';
2379: }
2380: }
1.586 raeburn 2381: } else {
2382: $result = &mt('Currently Filesystem Authenticated.');
2383: return $result;
2384: }
2385: }
2386: } else {
2387: if ($authnum == 1) {
1.784 bisitz 2388: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2389: }
2390: }
2391: if (!$can_assign{'fsys'}) {
2392: return;
1.587 raeburn 2393: } elsif ($authtype eq '') {
1.591 raeburn 2394: if (defined($in{'mode'})) {
1.587 raeburn 2395: if ($in{'mode'} eq 'modifycourse') {
2396: if ($authnum == 1) {
1.784 bisitz 2397: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2398: }
2399: }
2400: }
1.586 raeburn 2401: }
2402: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2403: if ($authtype eq '') {
2404: $authtype = '<input type="radio" name="login" value="fsys" '.
2405: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2406: $jscall.'" />';
2407: }
2408: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2409: ' onchange="'.$jscall.'" />';
2410: $result = &mt
1.144 matthew 2411: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2412: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2413: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2414: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2415: 'onchange="'.$jscall.'" />');
1.32 matthew 2416: return $result;
2417: }
2418:
1.586 raeburn 2419: sub get_assignable_auth {
2420: my ($dom) = @_;
2421: if ($dom eq '') {
2422: $dom = $env{'request.role.domain'};
2423: }
2424: my %can_assign = (
2425: krb4 => 1,
2426: krb5 => 1,
2427: int => 1,
2428: loc => 1,
2429: );
2430: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2431: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2432: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2433: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2434: my $context;
2435: if ($env{'request.role'} =~ /^au/) {
2436: $context = 'author';
2437: } elsif ($env{'request.role'} =~ /^dc/) {
2438: $context = 'domain';
2439: } elsif ($env{'request.course.id'}) {
2440: $context = 'course';
2441: }
2442: if ($context) {
2443: if (ref($authhash->{$context}) eq 'HASH') {
2444: %can_assign = %{$authhash->{$context}};
2445: }
2446: }
2447: }
2448: }
2449: my $authnum = 0;
2450: foreach my $key (keys(%can_assign)) {
2451: if ($can_assign{$key}) {
2452: $authnum ++;
2453: }
2454: }
2455: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2456: $authnum --;
2457: }
2458: return ($authnum,%can_assign);
2459: }
2460:
1.80 albertel 2461: ###############################################################
2462: ## Get Kerberos Defaults for Domain ##
2463: ###############################################################
2464: ##
2465: ## Returns default kerberos version and an associated argument
2466: ## as listed in file domain.tab. If not listed, provides
2467: ## appropriate default domain and kerberos version.
2468: ##
2469: #-------------------------------------------
2470:
2471: =pod
2472:
1.648 raeburn 2473: =item * &get_kerberos_defaults()
1.80 albertel 2474:
2475: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2476: version and domain. If not found, it defaults to version 4 and the
2477: domain of the server.
1.80 albertel 2478:
1.648 raeburn 2479: =over 4
2480:
1.80 albertel 2481: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2482:
1.648 raeburn 2483: =back
2484:
2485: =back
2486:
1.80 albertel 2487: =cut
2488:
2489: #-------------------------------------------
2490: sub get_kerberos_defaults {
2491: my $domain=shift;
1.641 raeburn 2492: my ($krbdef,$krbdefdom);
2493: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2494: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2495: $krbdef = $domdefaults{'auth_def'};
2496: $krbdefdom = $domdefaults{'auth_arg_def'};
2497: } else {
1.80 albertel 2498: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2499: my $krbdefdom=$1;
2500: $krbdefdom=~tr/a-z/A-Z/;
2501: $krbdef = "krb4";
2502: }
2503: return ($krbdef,$krbdefdom);
2504: }
1.112 bowersj2 2505:
1.32 matthew 2506:
1.46 matthew 2507: ###############################################################
2508: ## Thesaurus Functions ##
2509: ###############################################################
1.20 www 2510:
1.46 matthew 2511: =pod
1.20 www 2512:
1.112 bowersj2 2513: =head1 Thesaurus Functions
2514:
2515: =over 4
2516:
1.648 raeburn 2517: =item * &initialize_keywords()
1.46 matthew 2518:
2519: Initializes the package variable %Keywords if it is empty. Uses the
2520: package variable $thesaurus_db_file.
2521:
2522: =cut
2523:
2524: ###################################################
2525:
2526: sub initialize_keywords {
2527: return 1 if (scalar keys(%Keywords));
2528: # If we are here, %Keywords is empty, so fill it up
2529: # Make sure the file we need exists...
2530: if (! -e $thesaurus_db_file) {
2531: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2532: " failed because it does not exist");
2533: return 0;
2534: }
2535: # Set up the hash as a database
2536: my %thesaurus_db;
2537: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2538: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2539: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2540: $thesaurus_db_file);
2541: return 0;
2542: }
2543: # Get the average number of appearances of a word.
2544: my $avecount = $thesaurus_db{'average.count'};
2545: # Put keywords (those that appear > average) into %Keywords
2546: while (my ($word,$data)=each (%thesaurus_db)) {
2547: my ($count,undef) = split /:/,$data;
2548: $Keywords{$word}++ if ($count > $avecount);
2549: }
2550: untie %thesaurus_db;
2551: # Remove special values from %Keywords.
1.356 albertel 2552: foreach my $value ('total.count','average.count') {
2553: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2554: }
1.46 matthew 2555: return 1;
2556: }
2557:
2558: ###################################################
2559:
2560: =pod
2561:
1.648 raeburn 2562: =item * &keyword($word)
1.46 matthew 2563:
2564: Returns true if $word is a keyword. A keyword is a word that appears more
2565: than the average number of times in the thesaurus database. Calls
2566: &initialize_keywords
2567:
2568: =cut
2569:
2570: ###################################################
1.20 www 2571:
2572: sub keyword {
1.46 matthew 2573: return if (!&initialize_keywords());
2574: my $word=lc(shift());
2575: $word=~s/\W//g;
2576: return exists($Keywords{$word});
1.20 www 2577: }
1.46 matthew 2578:
2579: ###############################################################
2580:
2581: =pod
1.20 www 2582:
1.648 raeburn 2583: =item * &get_related_words()
1.46 matthew 2584:
1.160 matthew 2585: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2586: an array of words. If the keyword is not in the thesaurus, an empty array
2587: will be returned. The order of the words returned is determined by the
2588: database which holds them.
2589:
2590: Uses global $thesaurus_db_file.
2591:
2592: =cut
2593:
2594: ###############################################################
2595: sub get_related_words {
2596: my $keyword = shift;
2597: my %thesaurus_db;
2598: if (! -e $thesaurus_db_file) {
2599: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2600: "failed because the file does not exist");
2601: return ();
2602: }
2603: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2604: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2605: return ();
2606: }
2607: my @Words=();
1.429 www 2608: my $count=0;
1.46 matthew 2609: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2610: # The first element is the number of times
2611: # the word appears. We do not need it now.
1.429 www 2612: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2613: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2614: my $threshold=$mostfrequentcount/10;
2615: foreach my $possibleword (@RelatedWords) {
2616: my ($word,$wordcount)=split(/\,/,$possibleword);
2617: if ($wordcount>$threshold) {
2618: push(@Words,$word);
2619: $count++;
2620: if ($count>10) { last; }
2621: }
1.20 www 2622: }
2623: }
1.46 matthew 2624: untie %thesaurus_db;
2625: return @Words;
1.14 harris41 2626: }
1.46 matthew 2627:
1.112 bowersj2 2628: =pod
2629:
2630: =back
2631:
2632: =cut
1.61 www 2633:
2634: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2635: =pod
2636:
1.112 bowersj2 2637: =head1 User Name Functions
2638:
2639: =over 4
2640:
1.648 raeburn 2641: =item * &plainname($uname,$udom,$first)
1.81 albertel 2642:
1.112 bowersj2 2643: Takes a users logon name and returns it as a string in
1.226 albertel 2644: "first middle last generation" form
2645: if $first is set to 'lastname' then it returns it as
2646: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2647:
2648: =cut
1.61 www 2649:
1.295 www 2650:
1.81 albertel 2651: ###############################################################
1.61 www 2652: sub plainname {
1.226 albertel 2653: my ($uname,$udom,$first)=@_;
1.537 albertel 2654: return if (!defined($uname) || !defined($udom));
1.295 www 2655: my %names=&getnames($uname,$udom);
1.226 albertel 2656: my $name=&Apache::lonnet::format_name($names{'firstname'},
2657: $names{'middlename'},
2658: $names{'lastname'},
2659: $names{'generation'},$first);
2660: $name=~s/^\s+//;
1.62 www 2661: $name=~s/\s+$//;
2662: $name=~s/\s+/ /g;
1.353 albertel 2663: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2664: return $name;
1.61 www 2665: }
1.66 www 2666:
2667: # -------------------------------------------------------------------- Nickname
1.81 albertel 2668: =pod
2669:
1.648 raeburn 2670: =item * &nickname($uname,$udom)
1.81 albertel 2671:
2672: Gets a users name and returns it as a string as
2673:
2674: ""nickname""
1.66 www 2675:
1.81 albertel 2676: if the user has a nickname or
2677:
2678: "first middle last generation"
2679:
2680: if the user does not
2681:
2682: =cut
1.66 www 2683:
2684: sub nickname {
2685: my ($uname,$udom)=@_;
1.537 albertel 2686: return if (!defined($uname) || !defined($udom));
1.295 www 2687: my %names=&getnames($uname,$udom);
1.68 albertel 2688: my $name=$names{'nickname'};
1.66 www 2689: if ($name) {
2690: $name='"'.$name.'"';
2691: } else {
2692: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2693: $names{'lastname'}.' '.$names{'generation'};
2694: $name=~s/\s+$//;
2695: $name=~s/\s+/ /g;
2696: }
2697: return $name;
2698: }
2699:
1.295 www 2700: sub getnames {
2701: my ($uname,$udom)=@_;
1.537 albertel 2702: return if (!defined($uname) || !defined($udom));
1.433 albertel 2703: if ($udom eq 'public' && $uname eq 'public') {
2704: return ('lastname' => &mt('Public'));
2705: }
1.295 www 2706: my $id=$uname.':'.$udom;
2707: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2708: if ($cached) {
2709: return %{$names};
2710: } else {
2711: my %loadnames=&Apache::lonnet::get('environment',
2712: ['firstname','middlename','lastname','generation','nickname'],
2713: $udom,$uname);
2714: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2715: return %loadnames;
2716: }
2717: }
1.61 www 2718:
1.542 raeburn 2719: # -------------------------------------------------------------------- getemails
1.648 raeburn 2720:
1.542 raeburn 2721: =pod
2722:
1.648 raeburn 2723: =item * &getemails($uname,$udom)
1.542 raeburn 2724:
2725: Gets a user's email information and returns it as a hash with keys:
2726: notification, critnotification, permanentemail
2727:
2728: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2729: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2730:
1.648 raeburn 2731:
1.542 raeburn 2732: =cut
2733:
1.648 raeburn 2734:
1.466 albertel 2735: sub getemails {
2736: my ($uname,$udom)=@_;
2737: if ($udom eq 'public' && $uname eq 'public') {
2738: return;
2739: }
1.467 www 2740: if (!$udom) { $udom=$env{'user.domain'}; }
2741: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2742: my $id=$uname.':'.$udom;
2743: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2744: if ($cached) {
2745: return %{$names};
2746: } else {
2747: my %loadnames=&Apache::lonnet::get('environment',
2748: ['notification','critnotification',
2749: 'permanentemail'],
2750: $udom,$uname);
2751: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2752: return %loadnames;
2753: }
2754: }
2755:
1.551 albertel 2756: sub flush_email_cache {
2757: my ($uname,$udom)=@_;
2758: if (!$udom) { $udom =$env{'user.domain'}; }
2759: if (!$uname) { $uname=$env{'user.name'}; }
2760: return if ($udom eq 'public' && $uname eq 'public');
2761: my $id=$uname.':'.$udom;
2762: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2763: }
2764:
1.728 raeburn 2765: # -------------------------------------------------------------------- getlangs
2766:
2767: =pod
2768:
2769: =item * &getlangs($uname,$udom)
2770:
2771: Gets a user's language preference and returns it as a hash with key:
2772: language.
2773:
2774: =cut
2775:
2776:
2777: sub getlangs {
2778: my ($uname,$udom) = @_;
2779: if (!$udom) { $udom =$env{'user.domain'}; }
2780: if (!$uname) { $uname=$env{'user.name'}; }
2781: my $id=$uname.':'.$udom;
2782: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2783: if ($cached) {
2784: return %{$langs};
2785: } else {
2786: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2787: $udom,$uname);
2788: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2789: return %loadlangs;
2790: }
2791: }
2792:
2793: sub flush_langs_cache {
2794: my ($uname,$udom)=@_;
2795: if (!$udom) { $udom =$env{'user.domain'}; }
2796: if (!$uname) { $uname=$env{'user.name'}; }
2797: return if ($udom eq 'public' && $uname eq 'public');
2798: my $id=$uname.':'.$udom;
2799: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2800: }
2801:
1.61 www 2802: # ------------------------------------------------------------------ Screenname
1.81 albertel 2803:
2804: =pod
2805:
1.648 raeburn 2806: =item * &screenname($uname,$udom)
1.81 albertel 2807:
2808: Gets a users screenname and returns it as a string
2809:
2810: =cut
1.61 www 2811:
2812: sub screenname {
2813: my ($uname,$udom)=@_;
1.258 albertel 2814: if ($uname eq $env{'user.name'} &&
2815: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2816: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2817: return $names{'screenname'};
1.62 www 2818: }
2819:
1.212 albertel 2820:
1.62 www 2821: # ------------------------------------------------------------- Message Wrapper
2822:
2823: sub messagewrapper {
1.369 www 2824: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2825: return
1.441 albertel 2826: '<a href="/adm/email?compose=individual&'.
2827: 'recname='.$username.'&recdom='.$domain.
2828: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2829: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2830: }
2831: # --------------------------------------------------------------- Notes Wrapper
2832:
2833: sub noteswrapper {
2834: my ($link,$un,$do)=@_;
2835: return
2836: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2837: }
2838: # ------------------------------------------------------------- Aboutme Wrapper
2839:
2840: sub aboutmewrapper {
1.166 www 2841: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2842: if (!defined($username) && !defined($domain)) {
2843: return;
2844: }
1.205 www 2845: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2846: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2847: }
2848:
2849: # ------------------------------------------------------------ Syllabus Wrapper
2850:
2851:
2852: sub syllabuswrapper {
1.707 bisitz 2853: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2854: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2855: }
1.14 harris41 2856:
1.208 matthew 2857: sub track_student_link {
1.268 albertel 2858: my ($linktext,$sname,$sdom,$target,$start) = @_;
2859: my $link ="/adm/trackstudent?";
1.208 matthew 2860: my $title = 'View recent activity';
2861: if (defined($sname) && $sname !~ /^\s*$/ &&
2862: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2863: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2864: $title .= ' of this student';
1.268 albertel 2865: }
1.208 matthew 2866: if (defined($target) && $target !~ /^\s*$/) {
2867: $target = qq{target="$target"};
2868: } else {
2869: $target = '';
2870: }
1.268 albertel 2871: if ($start) { $link.='&start='.$start; }
1.554 albertel 2872: $title = &mt($title);
2873: $linktext = &mt($linktext);
1.448 albertel 2874: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2875: &help_open_topic('View_recent_activity');
1.208 matthew 2876: }
2877:
1.781 raeburn 2878: sub slot_reservations_link {
2879: my ($linktext,$sname,$sdom,$target) = @_;
2880: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2881: my $title = 'View slot reservation history';
2882: if (defined($sname) && $sname !~ /^\s*$/ &&
2883: defined($sdom) && $sdom !~ /^\s*$/) {
2884: $link .= "&uname=$sname&udom=$sdom";
2885: $title .= ' of this student';
2886: }
2887: if (defined($target) && $target !~ /^\s*$/) {
2888: $target = qq{target="$target"};
2889: } else {
2890: $target = '';
2891: }
2892: $title = &mt($title);
2893: $linktext = &mt($linktext);
2894: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2895: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2896:
2897: }
2898:
1.508 www 2899: # ===================================================== Display a student photo
2900:
2901:
1.509 albertel 2902: sub student_image_tag {
1.508 www 2903: my ($domain,$user)=@_;
2904: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2905: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2906: return '<img src="'.$imgsrc.'" align="right" />';
2907: } else {
2908: return '';
2909: }
2910: }
2911:
1.112 bowersj2 2912: =pod
2913:
2914: =back
2915:
2916: =head1 Access .tab File Data
2917:
2918: =over 4
2919:
1.648 raeburn 2920: =item * &languageids()
1.112 bowersj2 2921:
2922: returns list of all language ids
2923:
2924: =cut
2925:
1.14 harris41 2926: sub languageids {
1.16 harris41 2927: return sort(keys(%language));
1.14 harris41 2928: }
2929:
1.112 bowersj2 2930: =pod
2931:
1.648 raeburn 2932: =item * &languagedescription()
1.112 bowersj2 2933:
2934: returns description of a specified language id
2935:
2936: =cut
2937:
1.14 harris41 2938: sub languagedescription {
1.125 www 2939: my $code=shift;
2940: return ($supported_language{$code}?'* ':'').
2941: $language{$code}.
1.126 www 2942: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2943: }
2944:
2945: sub plainlanguagedescription {
2946: my $code=shift;
2947: return $language{$code};
2948: }
2949:
2950: sub supportedlanguagecode {
2951: my $code=shift;
2952: return $supported_language{$code};
1.97 www 2953: }
2954:
1.112 bowersj2 2955: =pod
2956:
1.648 raeburn 2957: =item * ©rightids()
1.112 bowersj2 2958:
2959: returns list of all copyrights
2960:
2961: =cut
2962:
2963: sub copyrightids {
2964: return sort(keys(%cprtag));
2965: }
2966:
2967: =pod
2968:
1.648 raeburn 2969: =item * ©rightdescription()
1.112 bowersj2 2970:
2971: returns description of a specified copyright id
2972:
2973: =cut
2974:
2975: sub copyrightdescription {
1.166 www 2976: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2977: }
1.197 matthew 2978:
2979: =pod
2980:
1.648 raeburn 2981: =item * &source_copyrightids()
1.192 taceyjo1 2982:
2983: returns list of all source copyrights
2984:
2985: =cut
2986:
2987: sub source_copyrightids {
2988: return sort(keys(%scprtag));
2989: }
2990:
2991: =pod
2992:
1.648 raeburn 2993: =item * &source_copyrightdescription()
1.192 taceyjo1 2994:
2995: returns description of a specified source copyright id
2996:
2997: =cut
2998:
2999: sub source_copyrightdescription {
3000: return &mt($scprtag{shift(@_)});
3001: }
1.112 bowersj2 3002:
3003: =pod
3004:
1.648 raeburn 3005: =item * &filecategories()
1.112 bowersj2 3006:
3007: returns list of all file categories
3008:
3009: =cut
3010:
3011: sub filecategories {
3012: return sort(keys(%category_extensions));
3013: }
3014:
3015: =pod
3016:
1.648 raeburn 3017: =item * &filecategorytypes()
1.112 bowersj2 3018:
3019: returns list of file types belonging to a given file
3020: category
3021:
3022: =cut
3023:
3024: sub filecategorytypes {
1.356 albertel 3025: my ($cat) = @_;
3026: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3027: }
3028:
3029: =pod
3030:
1.648 raeburn 3031: =item * &fileembstyle()
1.112 bowersj2 3032:
3033: returns embedding style for a specified file type
3034:
3035: =cut
3036:
3037: sub fileembstyle {
3038: return $fe{lc(shift(@_))};
1.169 www 3039: }
3040:
1.351 www 3041: sub filemimetype {
3042: return $fm{lc(shift(@_))};
3043: }
3044:
1.169 www 3045:
3046: sub filecategoryselect {
3047: my ($name,$value)=@_;
1.189 matthew 3048: return &select_form($value,$name,
1.169 www 3049: '' => &mt('Any category'),
3050: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3051: }
3052:
3053: =pod
3054:
1.648 raeburn 3055: =item * &filedescription()
1.112 bowersj2 3056:
3057: returns description for a specified file type
3058:
3059: =cut
3060:
3061: sub filedescription {
1.188 matthew 3062: my $file_description = $fd{lc(shift())};
3063: $file_description =~ s:([\[\]]):~$1:g;
3064: return &mt($file_description);
1.112 bowersj2 3065: }
3066:
3067: =pod
3068:
1.648 raeburn 3069: =item * &filedescriptionex()
1.112 bowersj2 3070:
3071: returns description for a specified file type with
3072: extra formatting
3073:
3074: =cut
3075:
3076: sub filedescriptionex {
3077: my $ex=shift;
1.188 matthew 3078: my $file_description = $fd{lc($ex)};
3079: $file_description =~ s:([\[\]]):~$1:g;
3080: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3081: }
3082:
3083: # End of .tab access
3084: =pod
3085:
3086: =back
3087:
3088: =cut
3089:
3090: # ------------------------------------------------------------------ File Types
3091: sub fileextensions {
3092: return sort(keys(%fe));
3093: }
3094:
1.97 www 3095: # ----------------------------------------------------------- Display Languages
3096: # returns a hash with all desired display languages
3097: #
3098:
3099: sub display_languages {
3100: my %languages=();
1.695 raeburn 3101: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3102: $languages{$lang}=1;
1.97 www 3103: }
3104: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3105: if ($env{'form.displaylanguage'}) {
1.356 albertel 3106: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3107: $languages{$lang}=1;
1.97 www 3108: }
3109: }
3110: return %languages;
1.14 harris41 3111: }
3112:
1.582 albertel 3113: sub languages {
3114: my ($possible_langs) = @_;
1.695 raeburn 3115: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3116: if (!ref($possible_langs)) {
3117: if( wantarray ) {
3118: return @preferred_langs;
3119: } else {
3120: return $preferred_langs[0];
3121: }
3122: }
3123: my %possibilities = map { $_ => 1 } (@$possible_langs);
3124: my @preferred_possibilities;
3125: foreach my $preferred_lang (@preferred_langs) {
3126: if (exists($possibilities{$preferred_lang})) {
3127: push(@preferred_possibilities, $preferred_lang);
3128: }
3129: }
3130: if( wantarray ) {
3131: return @preferred_possibilities;
3132: }
3133: return $preferred_possibilities[0];
3134: }
3135:
1.742 raeburn 3136: sub user_lang {
3137: my ($touname,$toudom,$fromcid) = @_;
3138: my @userlangs;
3139: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3140: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3141: $env{'course.'.$fromcid.'.languages'}));
3142: } else {
3143: my %langhash = &getlangs($touname,$toudom);
3144: if ($langhash{'languages'} ne '') {
3145: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3146: } else {
3147: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3148: if ($domdefs{'lang_def'} ne '') {
3149: @userlangs = ($domdefs{'lang_def'});
3150: }
3151: }
3152: }
3153: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3154: my $user_lh = Apache::localize->get_handle(@languages);
3155: return $user_lh;
3156: }
3157:
3158:
1.112 bowersj2 3159: ###############################################################
3160: ## Student Answer Attempts ##
3161: ###############################################################
3162:
3163: =pod
3164:
3165: =head1 Alternate Problem Views
3166:
3167: =over 4
3168:
1.648 raeburn 3169: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3170: $getattempt, $regexp, $gradesub)
3171:
3172: Return string with previous attempt on problem. Arguments:
3173:
3174: =over 4
3175:
3176: =item * $symb: Problem, including path
3177:
3178: =item * $username: username of the desired student
3179:
3180: =item * $domain: domain of the desired student
1.14 harris41 3181:
1.112 bowersj2 3182: =item * $course: Course ID
1.14 harris41 3183:
1.112 bowersj2 3184: =item * $getattempt: Leave blank for all attempts, otherwise put
3185: something
1.14 harris41 3186:
1.112 bowersj2 3187: =item * $regexp: if string matches this regexp, the string will be
3188: sent to $gradesub
1.14 harris41 3189:
1.112 bowersj2 3190: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3191:
1.112 bowersj2 3192: =back
1.14 harris41 3193:
1.112 bowersj2 3194: The output string is a table containing all desired attempts, if any.
1.16 harris41 3195:
1.112 bowersj2 3196: =cut
1.1 albertel 3197:
3198: sub get_previous_attempt {
1.43 ng 3199: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3200: my $prevattempts='';
1.43 ng 3201: no strict 'refs';
1.1 albertel 3202: if ($symb) {
1.3 albertel 3203: my (%returnhash)=
3204: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3205: if ($returnhash{'version'}) {
3206: my %lasthash=();
3207: my $version;
3208: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3209: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3210: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3211: }
1.1 albertel 3212: }
1.596 albertel 3213: $prevattempts=&start_data_table().&start_data_table_header_row();
3214: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3215: foreach my $key (sort(keys(%lasthash))) {
3216: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3217: if ($#parts > 0) {
1.31 albertel 3218: my $data=$parts[-1];
3219: pop(@parts);
1.596 albertel 3220: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3221: } else {
1.41 ng 3222: if ($#parts == 0) {
3223: $prevattempts.='<th>'.$parts[0].'</th>';
3224: } else {
3225: $prevattempts.='<th>'.$ign.'</th>';
3226: }
1.31 albertel 3227: }
1.16 harris41 3228: }
1.596 albertel 3229: $prevattempts.=&end_data_table_header_row();
1.40 ng 3230: if ($getattempt eq '') {
3231: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3232: $prevattempts.=&start_data_table_row().
3233: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3234: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3235: my $value = &format_previous_attempt_value($key,
3236: $returnhash{$version.':'.$key});
3237: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3238: }
1.596 albertel 3239: $prevattempts.=&end_data_table_row();
1.40 ng 3240: }
1.1 albertel 3241: }
1.596 albertel 3242: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3243: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3244: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3245: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3246: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3247: }
1.596 albertel 3248: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3249: } else {
1.596 albertel 3250: $prevattempts=
3251: &start_data_table().&start_data_table_row().
3252: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3253: &end_data_table_row().&end_data_table();
1.1 albertel 3254: }
3255: } else {
1.596 albertel 3256: $prevattempts=
3257: &start_data_table().&start_data_table_row().
3258: '<td>'.&mt('No data.').'</td>'.
3259: &end_data_table_row().&end_data_table();
1.1 albertel 3260: }
1.10 albertel 3261: }
3262:
1.581 albertel 3263: sub format_previous_attempt_value {
3264: my ($key,$value) = @_;
3265: if ($key =~ /timestamp/) {
3266: $value = &Apache::lonlocal::locallocaltime($value);
3267: } elsif (ref($value) eq 'ARRAY') {
3268: $value = '('.join(', ', @{ $value }).')';
3269: } else {
3270: $value = &unescape($value);
3271: }
3272: return $value;
3273: }
3274:
3275:
1.107 albertel 3276: sub relative_to_absolute {
3277: my ($url,$output)=@_;
3278: my $parser=HTML::TokeParser->new(\$output);
3279: my $token;
3280: my $thisdir=$url;
3281: my @rlinks=();
3282: while ($token=$parser->get_token) {
3283: if ($token->[0] eq 'S') {
3284: if ($token->[1] eq 'a') {
3285: if ($token->[2]->{'href'}) {
3286: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3287: }
3288: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3289: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3290: } elsif ($token->[1] eq 'base') {
3291: $thisdir=$token->[2]->{'href'};
3292: }
3293: }
3294: }
3295: $thisdir=~s-/[^/]*$--;
1.356 albertel 3296: foreach my $link (@rlinks) {
1.726 raeburn 3297: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3298: ($link=~/^\//) ||
3299: ($link=~/^javascript:/i) ||
3300: ($link=~/^mailto:/i) ||
3301: ($link=~/^\#/)) {
3302: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3303: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3304: }
3305: }
3306: # -------------------------------------------------- Deal with Applet codebases
3307: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3308: return $output;
3309: }
3310:
1.112 bowersj2 3311: =pod
3312:
1.648 raeburn 3313: =item * &get_student_view()
1.112 bowersj2 3314:
3315: show a snapshot of what student was looking at
3316:
3317: =cut
3318:
1.10 albertel 3319: sub get_student_view {
1.186 albertel 3320: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3321: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3322: my (%form);
1.10 albertel 3323: my @elements=('symb','courseid','domain','username');
3324: foreach my $element (@elements) {
1.186 albertel 3325: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3326: }
1.186 albertel 3327: if (defined($moreenv)) {
3328: %form=(%form,%{$moreenv});
3329: }
1.236 albertel 3330: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3331: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3332: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3333: $userview=~s/\<body[^\>]*\>//gi;
3334: $userview=~s/\<\/body\>//gi;
3335: $userview=~s/\<html\>//gi;
3336: $userview=~s/\<\/html\>//gi;
3337: $userview=~s/\<head\>//gi;
3338: $userview=~s/\<\/head\>//gi;
3339: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3340: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3341: if (wantarray) {
3342: return ($userview,$response);
3343: } else {
3344: return $userview;
3345: }
3346: }
3347:
3348: sub get_student_view_with_retries {
3349: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3350:
3351: my $ok = 0; # True if we got a good response.
3352: my $content;
3353: my $response;
3354:
3355: # Try to get the student_view done. within the retries count:
3356:
3357: do {
3358: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3359: $ok = $response->is_success;
3360: if (!$ok) {
3361: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3362: }
3363: $retries--;
3364: } while (!$ok && ($retries > 0));
3365:
3366: if (!$ok) {
3367: $content = ''; # On error return an empty content.
3368: }
1.651 www 3369: if (wantarray) {
3370: return ($content, $response);
3371: } else {
3372: return $content;
3373: }
1.11 albertel 3374: }
3375:
1.112 bowersj2 3376: =pod
3377:
1.648 raeburn 3378: =item * &get_student_answers()
1.112 bowersj2 3379:
3380: show a snapshot of how student was answering problem
3381:
3382: =cut
3383:
1.11 albertel 3384: sub get_student_answers {
1.100 sakharuk 3385: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3386: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3387: my (%moreenv);
1.11 albertel 3388: my @elements=('symb','courseid','domain','username');
3389: foreach my $element (@elements) {
1.186 albertel 3390: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3391: }
1.186 albertel 3392: $moreenv{'grade_target'}='answer';
3393: %moreenv=(%form,%moreenv);
1.497 raeburn 3394: $feedurl = &Apache::lonnet::clutter($feedurl);
3395: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3396: return $userview;
1.1 albertel 3397: }
1.116 albertel 3398:
3399: =pod
3400:
3401: =item * &submlink()
3402:
1.242 albertel 3403: Inputs: $text $uname $udom $symb $target
1.116 albertel 3404:
3405: Returns: A link to grades.pm such as to see the SUBM view of a student
3406:
3407: =cut
3408:
3409: ###############################################
3410: sub submlink {
1.242 albertel 3411: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3412: if (!($uname && $udom)) {
3413: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3414: &Apache::lonnet::whichuser($symb);
1.116 albertel 3415: if (!$symb) { $symb=$cursymb; }
3416: }
1.254 matthew 3417: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3418: $symb=&escape($symb);
1.242 albertel 3419: if ($target) { $target="target=\"$target\""; }
3420: return '<a href="/adm/grades?&command=submission&'.
3421: 'symb='.$symb.'&student='.$uname.
3422: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3423: }
3424: ##############################################
3425:
3426: =pod
3427:
3428: =item * &pgrdlink()
3429:
3430: Inputs: $text $uname $udom $symb $target
3431:
3432: Returns: A link to grades.pm such as to see the PGRD view of a student
3433:
3434: =cut
3435:
3436: ###############################################
3437: sub pgrdlink {
3438: my $link=&submlink(@_);
3439: $link=~s/(&command=submission)/$1&showgrading=yes/;
3440: return $link;
3441: }
3442: ##############################################
3443:
3444: =pod
3445:
3446: =item * &pprmlink()
3447:
3448: Inputs: $text $uname $udom $symb $target
3449:
3450: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3451: student and a specific resource
1.242 albertel 3452:
3453: =cut
3454:
3455: ###############################################
3456: sub pprmlink {
3457: my ($text,$uname,$udom,$symb,$target)=@_;
3458: if (!($uname && $udom)) {
3459: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3460: &Apache::lonnet::whichuser($symb);
1.242 albertel 3461: if (!$symb) { $symb=$cursymb; }
3462: }
1.254 matthew 3463: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3464: $symb=&escape($symb);
1.242 albertel 3465: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3466: return '<a href="/adm/parmset?command=set&'.
3467: 'symb='.$symb.'&uname='.$uname.
3468: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3469: }
3470: ##############################################
1.37 matthew 3471:
1.112 bowersj2 3472: =pod
3473:
3474: =back
3475:
3476: =cut
3477:
1.37 matthew 3478: ###############################################
1.51 www 3479:
3480:
3481: sub timehash {
1.687 raeburn 3482: my ($thistime) = @_;
3483: my $timezone = &Apache::lonlocal::gettimezone();
3484: my $dt = DateTime->from_epoch(epoch => $thistime)
3485: ->set_time_zone($timezone);
3486: my $wday = $dt->day_of_week();
3487: if ($wday == 7) { $wday = 0; }
3488: return ( 'second' => $dt->second(),
3489: 'minute' => $dt->minute(),
3490: 'hour' => $dt->hour(),
3491: 'day' => $dt->day_of_month(),
3492: 'month' => $dt->month(),
3493: 'year' => $dt->year(),
3494: 'weekday' => $wday,
3495: 'dayyear' => $dt->day_of_year(),
3496: 'dlsav' => $dt->is_dst() );
1.51 www 3497: }
3498:
1.370 www 3499: sub utc_string {
3500: my ($date)=@_;
1.371 www 3501: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3502: }
3503:
1.51 www 3504: sub maketime {
3505: my %th=@_;
1.687 raeburn 3506: my ($epoch_time,$timezone,$dt);
3507: $timezone = &Apache::lonlocal::gettimezone();
3508: eval {
3509: $dt = DateTime->new( year => $th{'year'},
3510: month => $th{'month'},
3511: day => $th{'day'},
3512: hour => $th{'hour'},
3513: minute => $th{'minute'},
3514: second => $th{'second'},
3515: time_zone => $timezone,
3516: );
3517: };
3518: if (!$@) {
3519: $epoch_time = $dt->epoch;
3520: if ($epoch_time) {
3521: return $epoch_time;
3522: }
3523: }
1.51 www 3524: return POSIX::mktime(
3525: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3526: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3527: }
3528:
3529: #########################################
1.51 www 3530:
3531: sub findallcourses {
1.482 raeburn 3532: my ($roles,$uname,$udom) = @_;
1.355 albertel 3533: my %roles;
3534: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3535: my %courses;
1.51 www 3536: my $now=time;
1.482 raeburn 3537: if (!defined($uname)) {
3538: $uname = $env{'user.name'};
3539: }
3540: if (!defined($udom)) {
3541: $udom = $env{'user.domain'};
3542: }
3543: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3544: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3545: if (!%roles) {
3546: %roles = (
3547: cc => 1,
3548: in => 1,
3549: ep => 1,
3550: ta => 1,
3551: cr => 1,
3552: st => 1,
3553: );
3554: }
3555: foreach my $entry (keys(%roleshash)) {
3556: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3557: if ($trole =~ /^cr/) {
3558: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3559: } else {
3560: next if (!exists($roles{$trole}));
3561: }
3562: if ($tend) {
3563: next if ($tend < $now);
3564: }
3565: if ($tstart) {
3566: next if ($tstart > $now);
3567: }
3568: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3569: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3570: if ($secpart eq '') {
3571: ($cnum,$role) = split(/_/,$cnumpart);
3572: $sec = 'none';
3573: $realsec = '';
3574: } else {
3575: $cnum = $cnumpart;
3576: ($sec,$role) = split(/_/,$secpart);
3577: $realsec = $sec;
1.490 raeburn 3578: }
1.482 raeburn 3579: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3580: }
3581: } else {
3582: foreach my $key (keys(%env)) {
1.483 albertel 3583: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3584: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3585: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3586: next if ($role eq 'ca' || $role eq 'aa');
3587: next if (%roles && !exists($roles{$role}));
3588: my ($starttime,$endtime)=split(/\./,$env{$key});
3589: my $active=1;
3590: if ($starttime) {
3591: if ($now<$starttime) { $active=0; }
3592: }
3593: if ($endtime) {
3594: if ($now>$endtime) { $active=0; }
3595: }
3596: if ($active) {
3597: if ($sec eq '') {
3598: $sec = 'none';
3599: }
3600: $courses{$cdom.'_'.$cnum}{$sec} =
3601: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3602: }
3603: }
1.51 www 3604: }
3605: }
1.474 raeburn 3606: return %courses;
1.51 www 3607: }
1.37 matthew 3608:
1.54 www 3609: ###############################################
1.474 raeburn 3610:
3611: sub blockcheck {
1.482 raeburn 3612: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3613:
3614: if (!defined($udom)) {
3615: $udom = $env{'user.domain'};
3616: }
3617: if (!defined($uname)) {
3618: $uname = $env{'user.name'};
3619: }
3620:
3621: # If uname and udom are for a course, check for blocks in the course.
3622:
3623: if (&Apache::lonnet::is_course($udom,$uname)) {
3624: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3625: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3626: return ($startblock,$endblock);
3627: }
1.474 raeburn 3628:
1.502 raeburn 3629: my $startblock = 0;
3630: my $endblock = 0;
1.482 raeburn 3631: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3632:
1.490 raeburn 3633: # If uname is for a user, and activity is course-specific, i.e.,
3634: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3635:
1.490 raeburn 3636: if (($activity eq 'boards' || $activity eq 'chat' ||
3637: $activity eq 'groups') && ($env{'request.course.id'})) {
3638: foreach my $key (keys(%live_courses)) {
3639: if ($key ne $env{'request.course.id'}) {
3640: delete($live_courses{$key});
3641: }
3642: }
3643: }
3644:
3645: my $otheruser = 0;
3646: my %own_courses;
3647: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3648: # Resource belongs to user other than current user.
3649: $otheruser = 1;
3650: # Gather courses for current user
3651: %own_courses =
3652: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3653: }
3654:
3655: # Gather active course roles - course coordinator, instructor,
3656: # exam proctor, ta, student, or custom role.
1.474 raeburn 3657:
3658: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3659: my ($cdom,$cnum);
3660: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3661: $cdom = $env{'course.'.$course.'.domain'};
3662: $cnum = $env{'course.'.$course.'.num'};
3663: } else {
1.490 raeburn 3664: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3665: }
3666: my $no_ownblock = 0;
3667: my $no_userblock = 0;
1.533 raeburn 3668: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3669: # Check if current user has 'evb' priv for this
3670: if (defined($own_courses{$course})) {
3671: foreach my $sec (keys(%{$own_courses{$course}})) {
3672: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3673: if ($sec ne 'none') {
3674: $checkrole .= '/'.$sec;
3675: }
3676: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3677: $no_ownblock = 1;
3678: last;
3679: }
3680: }
3681: }
3682: # if they have 'evb' priv and are currently not playing student
3683: next if (($no_ownblock) &&
3684: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3685: }
1.474 raeburn 3686: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3687: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3688: if ($sec ne 'none') {
1.482 raeburn 3689: $checkrole .= '/'.$sec;
1.474 raeburn 3690: }
1.490 raeburn 3691: if ($otheruser) {
3692: # Resource belongs to user other than current user.
3693: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3694: my ($trole,$tdom,$tnum,$tsec);
3695: my $entry = $live_courses{$course}{$sec};
3696: if ($entry =~ /^cr/) {
3697: ($trole,$tdom,$tnum,$tsec) =
3698: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3699: } else {
3700: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3701: }
3702: my ($spec,$area,$trest,%allroles,%userroles);
3703: $area = '/'.$tdom.'/'.$tnum;
3704: $trest = $tnum;
3705: if ($tsec ne '') {
3706: $area .= '/'.$tsec;
3707: $trest .= '/'.$tsec;
3708: }
3709: $spec = $trole.'.'.$area;
3710: if ($trole =~ /^cr/) {
3711: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3712: $tdom,$spec,$trest,$area);
3713: } else {
3714: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3715: $tdom,$spec,$trest,$area);
3716: }
3717: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3718: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3719: if ($1) {
3720: $no_userblock = 1;
3721: last;
3722: }
3723: }
1.490 raeburn 3724: } else {
3725: # Resource belongs to current user
3726: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3727: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3728: $no_ownblock = 1;
3729: last;
3730: }
1.474 raeburn 3731: }
3732: }
3733: # if they have the evb priv and are currently not playing student
1.482 raeburn 3734: next if (($no_ownblock) &&
1.491 albertel 3735: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3736: next if ($no_userblock);
1.474 raeburn 3737:
1.490 raeburn 3738: # Retrieve blocking times and identity of blocker for course
3739: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3740:
3741: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3742: if (($start != 0) &&
3743: (($startblock == 0) || ($startblock > $start))) {
3744: $startblock = $start;
3745: }
3746: if (($end != 0) &&
3747: (($endblock == 0) || ($endblock < $end))) {
3748: $endblock = $end;
3749: }
1.490 raeburn 3750: }
3751: return ($startblock,$endblock);
3752: }
3753:
3754: sub get_blocks {
3755: my ($setters,$activity,$cdom,$cnum) = @_;
3756: my $startblock = 0;
3757: my $endblock = 0;
3758: my $course = $cdom.'_'.$cnum;
3759: $setters->{$course} = {};
3760: $setters->{$course}{'staff'} = [];
3761: $setters->{$course}{'times'} = [];
3762: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3763: foreach my $record (keys(%records)) {
3764: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3765: if ($start <= time && $end >= time) {
3766: my ($staff_name,$staff_dom,$title,$blocks) =
3767: &parse_block_record($records{$record});
3768: if ($blocks->{$activity} eq 'on') {
3769: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3770: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3771: if ( ($startblock == 0) || ($startblock > $start) ) {
3772: $startblock = $start;
1.490 raeburn 3773: }
1.491 albertel 3774: if ( ($endblock == 0) || ($endblock < $end) ) {
3775: $endblock = $end;
1.474 raeburn 3776: }
3777: }
3778: }
3779: }
3780: return ($startblock,$endblock);
3781: }
3782:
3783: sub parse_block_record {
3784: my ($record) = @_;
3785: my ($setuname,$setudom,$title,$blocks);
3786: if (ref($record) eq 'HASH') {
3787: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3788: $title = &unescape($record->{'event'});
3789: $blocks = $record->{'blocks'};
3790: } else {
3791: my @data = split(/:/,$record,3);
3792: if (scalar(@data) eq 2) {
3793: $title = $data[1];
3794: ($setuname,$setudom) = split(/@/,$data[0]);
3795: } else {
3796: ($setuname,$setudom,$title) = @data;
3797: }
3798: $blocks = { 'com' => 'on' };
3799: }
3800: return ($setuname,$setudom,$title,$blocks);
3801: }
3802:
3803: sub build_block_table {
3804: my ($startblock,$endblock,$setters) = @_;
3805: my %lt = &Apache::lonlocal::texthash(
3806: 'cacb' => 'Currently active communication blocks',
3807: 'cour' => 'Course',
3808: 'dura' => 'Duration',
3809: 'blse' => 'Block set by'
3810: );
3811: my $output;
1.476 raeburn 3812: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3813: $output .= &start_data_table();
3814: $output .= '
3815: <tr>
3816: <th>'.$lt{'cour'}.'</th>
3817: <th>'.$lt{'dura'}.'</th>
3818: <th>'.$lt{'blse'}.'</th>
3819: </tr>
3820: ';
3821: foreach my $course (keys(%{$setters})) {
3822: my %courseinfo=&Apache::lonnet::coursedescription($course);
3823: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3824: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3825: my $fullname = &plainname($uname,$udom);
3826: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3827: && $env{'user.name'} ne 'public'
3828: && $env{'user.domain'} ne 'public') {
3829: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3830: }
1.474 raeburn 3831: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3832: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3833: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3834: $output .= &Apache::loncommon::start_data_table_row().
3835: '<td>'.$courseinfo{'description'}.'</td>'.
3836: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3837: '<td>'.$fullname.'</td>'.
1.474 raeburn 3838: &Apache::loncommon::end_data_table_row();
3839: }
3840: }
3841: $output .= &end_data_table();
3842: }
3843:
1.490 raeburn 3844: sub blocking_status {
3845: my ($activity,$uname,$udom) = @_;
3846: my %setters;
3847: my ($blocked,$output,$ownitem,$is_course);
3848: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3849: if ($startblock && $endblock) {
3850: $blocked = 1;
3851: if (wantarray) {
3852: my $category;
3853: if ($activity eq 'boards') {
3854: $category = 'Discussion posts in this course';
3855: } elsif ($activity eq 'blogs') {
3856: $category = 'Blogs';
3857: } elsif ($activity eq 'port') {
3858: if (defined($uname) && defined($udom)) {
3859: if ($uname eq $env{'user.name'} &&
3860: $udom eq $env{'user.domain'}) {
3861: $ownitem = 1;
3862: }
3863: }
3864: $is_course = &Apache::lonnet::is_course($udom,$uname);
3865: if ($ownitem) {
3866: $category = 'Your portfolio files';
3867: } elsif ($is_course) {
3868: my $coursedesc;
3869: foreach my $course (keys(%setters)) {
3870: my %courseinfo =
3871: &Apache::lonnet::coursedescription($course);
3872: $coursedesc = $courseinfo{'description'};
3873: }
1.764 weissno 3874: $category = "Group portfolio in the course '$coursedesc'";
1.490 raeburn 3875: } else {
3876: $category = 'Portfolio files belonging to ';
3877: if ($env{'user.name'} eq 'public' &&
3878: $env{'user.domain'} eq 'public') {
3879: $category .= &plainname($uname,$udom);
3880: } else {
3881: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3882: }
3883: }
3884: } elsif ($activity eq 'groups') {
3885: $category = 'Groups in this course';
3886: }
3887: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3888: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3889: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3890: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3891: $output .= &build_block_table($startblock,$endblock,\%setters);
3892: }
3893: }
3894: }
3895: if (wantarray) {
3896: return ($blocked,$output);
3897: } else {
3898: return $blocked;
3899: }
3900: }
3901:
1.60 matthew 3902: ###############################################
3903:
1.682 raeburn 3904: sub check_ip_acc {
3905: my ($acc)=@_;
3906: &Apache::lonxml::debug("acc is $acc");
3907: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3908: return 1;
3909: }
3910: my $allowed=0;
3911: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3912:
3913: my $name;
3914: foreach my $pattern (split(',',$acc)) {
3915: $pattern =~ s/^\s*//;
3916: $pattern =~ s/\s*$//;
3917: if ($pattern =~ /\*$/) {
3918: #35.8.*
3919: $pattern=~s/\*//;
3920: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3921: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3922: #35.8.3.[34-56]
3923: my $low=$2;
3924: my $high=$3;
3925: $pattern=$1;
3926: if ($ip =~ /^\Q$pattern\E/) {
3927: my $last=(split(/\./,$ip))[3];
3928: if ($last <=$high && $last >=$low) { $allowed=1; }
3929: }
3930: } elsif ($pattern =~ /^\*/) {
3931: #*.msu.edu
3932: $pattern=~s/\*//;
3933: if (!defined($name)) {
3934: use Socket;
3935: my $netaddr=inet_aton($ip);
3936: ($name)=gethostbyaddr($netaddr,AF_INET);
3937: }
3938: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3939: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3940: #127.0.0.1
3941: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3942: } else {
3943: #some.name.com
3944: if (!defined($name)) {
3945: use Socket;
3946: my $netaddr=inet_aton($ip);
3947: ($name)=gethostbyaddr($netaddr,AF_INET);
3948: }
3949: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3950: }
3951: if ($allowed) { last; }
3952: }
3953: return $allowed;
3954: }
3955:
3956: ###############################################
3957:
1.60 matthew 3958: =pod
3959:
1.112 bowersj2 3960: =head1 Domain Template Functions
3961:
3962: =over 4
3963:
3964: =item * &determinedomain()
1.60 matthew 3965:
3966: Inputs: $domain (usually will be undef)
3967:
1.63 www 3968: Returns: Determines which domain should be used for designs
1.60 matthew 3969:
3970: =cut
1.54 www 3971:
1.60 matthew 3972: ###############################################
1.63 www 3973: sub determinedomain {
3974: my $domain=shift;
1.531 albertel 3975: if (! $domain) {
1.60 matthew 3976: # Determine domain if we have not been given one
3977: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3978: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3979: if ($env{'request.role.domain'}) {
3980: $domain=$env{'request.role.domain'};
1.60 matthew 3981: }
3982: }
1.63 www 3983: return $domain;
3984: }
3985: ###############################################
1.517 raeburn 3986:
1.518 albertel 3987: sub devalidate_domconfig_cache {
3988: my ($udom)=@_;
3989: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3990: }
3991:
3992: # ---------------------- Get domain configuration for a domain
3993: sub get_domainconf {
3994: my ($udom) = @_;
3995: my $cachetime=1800;
3996: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3997: if (defined($cached)) { return %{$result}; }
3998:
3999: my %domconfig = &Apache::lonnet::get_dom('configuration',
4000: ['login','rolecolors'],$udom);
1.632 raeburn 4001: my (%designhash,%legacy);
1.518 albertel 4002: if (keys(%domconfig) > 0) {
4003: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4004: if (keys(%{$domconfig{'login'}})) {
4005: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4006: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4007: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4008: $designhash{$udom.'.login.'.$key.'_'.$img} =
4009: $domconfig{'login'}{$key}{$img};
4010: }
4011: } else {
4012: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4013: }
1.632 raeburn 4014: }
4015: } else {
4016: $legacy{'login'} = 1;
1.518 albertel 4017: }
1.632 raeburn 4018: } else {
4019: $legacy{'login'} = 1;
1.518 albertel 4020: }
4021: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4022: if (keys(%{$domconfig{'rolecolors'}})) {
4023: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4024: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4025: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4026: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4027: }
1.518 albertel 4028: }
4029: }
1.632 raeburn 4030: } else {
4031: $legacy{'rolecolors'} = 1;
1.518 albertel 4032: }
1.632 raeburn 4033: } else {
4034: $legacy{'rolecolors'} = 1;
1.518 albertel 4035: }
1.632 raeburn 4036: if (keys(%legacy) > 0) {
4037: my %legacyhash = &get_legacy_domconf($udom);
4038: foreach my $item (keys(%legacyhash)) {
4039: if ($item =~ /^\Q$udom\E\.login/) {
4040: if ($legacy{'login'}) {
4041: $designhash{$item} = $legacyhash{$item};
4042: }
4043: } else {
4044: if ($legacy{'rolecolors'}) {
4045: $designhash{$item} = $legacyhash{$item};
4046: }
1.518 albertel 4047: }
4048: }
4049: }
1.632 raeburn 4050: } else {
4051: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4052: }
4053: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4054: $cachetime);
4055: return %designhash;
4056: }
4057:
1.632 raeburn 4058: sub get_legacy_domconf {
4059: my ($udom) = @_;
4060: my %legacyhash;
4061: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4062: my $designfile = $designdir.'/'.$udom.'.tab';
4063: if (-e $designfile) {
4064: if ( open (my $fh,"<$designfile") ) {
4065: while (my $line = <$fh>) {
4066: next if ($line =~ /^\#/);
4067: chomp($line);
4068: my ($key,$val)=(split(/\=/,$line));
4069: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4070: }
4071: close($fh);
4072: }
4073: }
4074: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4075: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4076: }
4077: return %legacyhash;
4078: }
4079:
1.63 www 4080: =pod
4081:
1.112 bowersj2 4082: =item * &domainlogo()
1.63 www 4083:
4084: Inputs: $domain (usually will be undef)
4085:
4086: Returns: A link to a domain logo, if the domain logo exists.
4087: If the domain logo does not exist, a description of the domain.
4088:
4089: =cut
1.112 bowersj2 4090:
1.63 www 4091: ###############################################
4092: sub domainlogo {
1.517 raeburn 4093: my $domain = &determinedomain(shift);
1.518 albertel 4094: my %designhash = &get_domainconf($domain);
1.517 raeburn 4095: # See if there is a logo
4096: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4097: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4098: if ($imgsrc =~ m{^/(adm|res)/}) {
4099: if ($imgsrc =~ m{^/res/}) {
4100: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4101: &Apache::lonnet::repcopy($local_name);
4102: }
4103: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4104: }
4105: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4106: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4107: return &Apache::lonnet::domain($domain,'description');
1.59 www 4108: } else {
1.60 matthew 4109: return '';
1.59 www 4110: }
4111: }
1.63 www 4112: ##############################################
4113:
4114: =pod
4115:
1.112 bowersj2 4116: =item * &designparm()
1.63 www 4117:
4118: Inputs: $which parameter; $domain (usually will be undef)
4119:
4120: Returns: value of designparamter $which
4121:
4122: =cut
1.112 bowersj2 4123:
1.397 albertel 4124:
1.400 albertel 4125: ##############################################
1.397 albertel 4126: sub designparm {
4127: my ($which,$domain)=@_;
1.258 albertel 4128: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4129: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4130: return '#000000';
4131: }
1.635 raeburn 4132: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4133: return '#FFFFFF';
4134: }
4135: if ($which=~/\.tabbg$/) {
4136: return '#CCCCCC';
4137: }
4138: }
1.397 albertel 4139: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4140: return $env{'environment.color.'.$which};
1.96 www 4141: }
1.63 www 4142: $domain=&determinedomain($domain);
1.518 albertel 4143: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4144: my $output;
1.517 raeburn 4145: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4146: $output = $domdesign{$domain.'.'.$which};
1.63 www 4147: } else {
1.520 raeburn 4148: $output = $defaultdesign{$which};
4149: }
4150: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4151: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4152: if ($output =~ m{^/(adm|res)/}) {
4153: if ($output =~ m{^/res/}) {
4154: my $local_name = &Apache::lonnet::filelocation('',$output);
4155: &Apache::lonnet::repcopy($local_name);
4156: }
1.520 raeburn 4157: $output = &lonhttpdurl($output);
4158: }
1.63 www 4159: }
1.520 raeburn 4160: return $output;
1.63 www 4161: }
1.59 www 4162:
1.60 matthew 4163: ###############################################
4164: ###############################################
4165:
4166: =pod
4167:
1.112 bowersj2 4168: =back
4169:
1.549 albertel 4170: =head1 HTML Helpers
1.112 bowersj2 4171:
4172: =over 4
4173:
4174: =item * &bodytag()
1.60 matthew 4175:
4176: Returns a uniform header for LON-CAPA web pages.
4177:
4178: Inputs:
4179:
1.112 bowersj2 4180: =over 4
4181:
4182: =item * $title, A title to be displayed on the page.
4183:
4184: =item * $function, the current role (can be undef).
4185:
4186: =item * $addentries, extra parameters for the <body> tag.
4187:
4188: =item * $bodyonly, if defined, only return the <body> tag.
4189:
4190: =item * $domain, if defined, force a given domain.
4191:
4192: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4193: text interface only)
1.60 matthew 4194:
1.326 albertel 4195: =item * $customtitle, alternate text to use instead of $title
4196: in the title box that appears, this text
4197: is not auto translated like the $title is
1.309 albertel 4198:
4199: =item * $notopbar, if true, keep the 'what is this' info but remove the
4200: navigational links
1.317 albertel 4201:
1.338 albertel 4202: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4203:
4204: =item * $notitle, if true keep the nav controls, but remove the title bar
4205:
1.361 albertel 4206: =item * $no_inline_link, if true and in remote mode, don't show the
4207: 'Switch To Inline Menu' link
4208:
1.460 albertel 4209: =item * $args, optional argument valid values are
4210: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4211: inherit_jsmath -> when creating popup window in a page,
4212: should it have jsmath forced on by the
4213: current page
1.460 albertel 4214:
1.112 bowersj2 4215: =back
4216:
1.60 matthew 4217: Returns: A uniform header for LON-CAPA web pages.
4218: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4219: If $bodyonly is undef or zero, an html string containing a <body> tag and
4220: other decorations will be returned.
4221:
4222: =cut
4223:
1.54 www 4224: sub bodytag {
1.309 albertel 4225: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4226: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4227:
1.460 albertel 4228: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4229:
1.183 matthew 4230: $function = &get_users_function() if (!$function);
1.339 albertel 4231: my $img = &designparm($function.'.img',$domain);
4232: my $font = &designparm($function.'.font',$domain);
4233: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4234:
4235: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4236: 'bgcolor' => $pgbg,
1.339 albertel 4237: 'text' => $font,
4238: 'alink' => &designparm($function.'.alink',$domain),
4239: 'vlink' => &designparm($function.'.vlink',$domain),
4240: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4241: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4242:
1.63 www 4243: # role and realm
1.378 raeburn 4244: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4245: if ($role eq 'ca') {
1.479 albertel 4246: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4247: $realm = &plainname($rname,$rdom);
1.378 raeburn 4248: }
1.55 www 4249: # realm
1.258 albertel 4250: if ($env{'request.course.id'}) {
1.378 raeburn 4251: if ($env{'request.role'} !~ /^cr/) {
4252: $role = &Apache::lonnet::plaintext($role,&course_type());
4253: }
1.359 albertel 4254: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4255: } else {
4256: $role = &Apache::lonnet::plaintext($role);
1.54 www 4257: }
1.433 albertel 4258:
1.359 albertel 4259: if (!$realm) { $realm=' '; }
1.55 www 4260: # Set messages
1.60 matthew 4261: my $messages=&domainlogo($domain);
1.330 albertel 4262:
1.438 albertel 4263: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4264:
1.101 www 4265: # construct main body tag
1.359 albertel 4266: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4267: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4268:
1.530 albertel 4269: if ($bodyonly) {
1.60 matthew 4270: return $bodytag;
1.258 albertel 4271: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4272: # Accessibility
1.224 raeburn 4273:
1.337 albertel 4274: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4275: if (!$notitle) {
1.337 albertel 4276: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4277: }
4278: return $bodytag;
1.359 albertel 4279: }
4280:
1.410 albertel 4281: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4282: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4283: undef($role);
1.434 albertel 4284: } else {
4285: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4286: }
1.359 albertel 4287:
4288: my $roleinfo=(<<ENDROLE);
4289: <td class="LC_title_bar_who">
4290: <div class="LC_title_bar_name">
1.410 albertel 4291: $name
1.361 albertel 4292:
1.359 albertel 4293: </div>
4294: <div class="LC_title_bar_role">
1.361 albertel 4295: $role
1.359 albertel 4296: </div>
4297: <div class="LC_title_bar_realm">
1.361 albertel 4298: $realm
1.359 albertel 4299: </div>
1.206 albertel 4300: </td>
4301: ENDROLE
1.235 raeburn 4302:
1.762 bisitz 4303: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4304: if ($customtitle) {
4305: $titleinfo = $customtitle;
4306: }
4307: #
4308: # Extra info if you are the DC
4309: my $dc_info = '';
4310: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4311: $env{'course.'.$env{'request.course.id'}.
4312: '.domain'}.'/'})) {
4313: my $cid = $env{'request.course.id'};
4314: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4315: $dc_info =~ s/\s+$//;
1.359 albertel 4316: $dc_info = '('.$dc_info.')';
4317: }
4318:
1.644 www 4319: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4320: # No Remote
1.258 albertel 4321: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4322: $forcereg=1;
4323: }
4324:
4325: if (!$customtitle && $env{'request.state'} eq 'construct') {
4326: # this is for resources; directories have customtitle, and crumbs
4327: # and select recent are created in lonpubdir.pm
1.229 albertel 4328: my ($uname,$thisdisfn)=
1.258 albertel 4329: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4330: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4331: $formaction=~s/\/+/\//g;
4332:
1.359 albertel 4333: my $parentpath = '';
4334: my $lastitem = '';
4335: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4336: $parentpath = $1;
4337: $lastitem = $2;
4338: } else {
4339: $lastitem = $thisdisfn;
4340: }
4341: $titleinfo =
1.640 bisitz 4342: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4343: .'<b>'.&mt('Construction Space').'</b>: '
4344: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4345: .'" target="_top"><tt><b>'
1.705 tempelho 4346: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4347: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4348: .'</form>'
4349: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4350: }
1.359 albertel 4351:
1.337 albertel 4352: my $titletable;
1.338 albertel 4353: if (!$notitle) {
1.337 albertel 4354: $titletable =
1.359 albertel 4355: '<table id="LC_title_bar">'.
4356: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4357: '</tr></table>';
1.337 albertel 4358: }
1.359 albertel 4359: if ($notopbar) {
4360: $bodytag .= $titletable;
4361: } else {
4362: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4363: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4364: $titletable);
1.272 raeburn 4365: } else {
1.336 albertel 4366: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4367: $titletable;
1.272 raeburn 4368: }
1.235 raeburn 4369: }
4370: return $bodytag;
1.94 www 4371: }
1.95 www 4372:
1.93 www 4373: #
1.95 www 4374: # Top frame rendering, Remote is up
1.93 www 4375: #
1.359 albertel 4376:
1.517 raeburn 4377: my $imgsrc = $img;
4378: if ($img =~ /^\/adm/) {
1.575 albertel 4379: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4380: }
4381: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4382:
1.305 www 4383: # Explicit link to get inline menu
1.361 albertel 4384: my $menu= ($no_inline_link?''
4385: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4386: #
1.338 albertel 4387: if ($notitle) {
1.337 albertel 4388: return $bodytag;
4389: }
1.94 www 4390: return(<<ENDBODY);
1.60 matthew 4391: $bodytag
1.359 albertel 4392: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4393: <tr><td>$upperleft</td>
4394: <td>$messages </td>
1.54 www 4395: </tr>
1.359 albertel 4396: <tr><td>$titleinfo $dc_info $menu</td>
4397: $roleinfo
1.368 albertel 4398: </tr>
1.356 albertel 4399: </table>
1.54 www 4400: ENDBODY
1.182 matthew 4401: }
4402:
1.330 albertel 4403: sub make_attr_string {
4404: my ($register,$attr_ref) = @_;
4405:
4406: if ($attr_ref && !ref($attr_ref)) {
4407: die("addentries Must be a hash ref ".
4408: join(':',caller(1))." ".
4409: join(':',caller(0))." ");
4410: }
4411:
4412: if ($register) {
1.339 albertel 4413: my ($on_load,$on_unload);
4414: foreach my $key (keys(%{$attr_ref})) {
4415: if (lc($key) eq 'onload') {
4416: $on_load.=$attr_ref->{$key}.';';
4417: delete($attr_ref->{$key});
4418:
4419: } elsif (lc($key) eq 'onunload') {
4420: $on_unload.=$attr_ref->{$key}.';';
4421: delete($attr_ref->{$key});
4422: }
4423: }
4424: $attr_ref->{'onload'} =
4425: &Apache::lonmenu::loadevents(). $on_load;
4426: $attr_ref->{'onunload'}=
4427: &Apache::lonmenu::unloadevents().$on_unload;
4428: }
4429:
4430: # Accessibility font enhance
4431: if ($env{'browser.fontenhance'} eq 'on') {
4432: my $style;
4433: foreach my $key (keys(%{$attr_ref})) {
4434: if (lc($key) eq 'style') {
4435: $style.=$attr_ref->{$key}.';';
4436: delete($attr_ref->{$key});
4437: }
4438: }
4439: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4440: }
1.339 albertel 4441:
4442: if ($env{'browser.blackwhite'} eq 'on') {
4443: delete($attr_ref->{'font'});
4444: delete($attr_ref->{'link'});
4445: delete($attr_ref->{'alink'});
4446: delete($attr_ref->{'vlink'});
4447: delete($attr_ref->{'bgcolor'});
4448: delete($attr_ref->{'background'});
4449: }
4450:
1.330 albertel 4451: my $attr_string;
4452: foreach my $attr (keys(%$attr_ref)) {
4453: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4454: }
4455: return $attr_string;
4456: }
4457:
4458:
1.182 matthew 4459: ###############################################
1.251 albertel 4460: ###############################################
4461:
4462: =pod
4463:
4464: =item * &endbodytag()
4465:
4466: Returns a uniform footer for LON-CAPA web pages.
4467:
1.635 raeburn 4468: Inputs: 1 - optional reference to an args hash
4469: If in the hash, key for noredirectlink has a value which evaluates to true,
4470: a 'Continue' link is not displayed if the page contains an
4471: internal redirect in the <head></head> section,
4472: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4473:
4474: =cut
4475:
4476: sub endbodytag {
1.635 raeburn 4477: my ($args) = @_;
1.251 albertel 4478: my $endbodytag='</body>';
1.269 albertel 4479: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4480: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4481: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4482: $endbodytag=
4483: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4484: &mt('Continue').'</a>'.
4485: $endbodytag;
4486: }
1.315 albertel 4487: }
1.251 albertel 4488: return $endbodytag;
4489: }
4490:
1.352 albertel 4491: =pod
4492:
4493: =item * &standard_css()
4494:
4495: Returns a style sheet
4496:
4497: Inputs: (all optional)
4498: domain -> force to color decorate a page for a specific
4499: domain
4500: function -> force usage of a specific rolish color scheme
4501: bgcolor -> override the default page bgcolor
4502:
4503: =cut
4504:
1.343 albertel 4505: sub standard_css {
1.345 albertel 4506: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4507: $function = &get_users_function() if (!$function);
4508: my $img = &designparm($function.'.img', $domain);
4509: my $tabbg = &designparm($function.'.tabbg', $domain);
4510: my $font = &designparm($function.'.font', $domain);
1.791 tempelho 4511: #second colour for later usage
1.345 albertel 4512: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4513: my $pgbg_or_bgcolor =
4514: $bgcolor ||
1.352 albertel 4515: &designparm($function.'.pgbg', $domain);
1.382 albertel 4516: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4517: my $alink = &designparm($function.'.alink', $domain);
4518: my $vlink = &designparm($function.'.vlink', $domain);
4519: my $link = &designparm($function.'.link', $domain);
4520:
1.704 muellerd 4521: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4522: my $bgcol = &designparm('login.bgcol',$domain);
4523: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4524:
1.602 albertel 4525: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4526: my $mono = 'monospace';
1.352 albertel 4527: my $data_table_head = $tabbg;
4528: my $data_table_light = '#EEEEEE';
1.470 banghart 4529: my $data_table_dark = '#DDDDDD';
4530: my $data_table_darker = '#CCCCCC';
1.349 albertel 4531: my $data_table_highlight = '#FFFF00';
1.352 albertel 4532: my $mail_new = '#FFBB77';
4533: my $mail_new_hover = '#DD9955';
4534: my $mail_read = '#BBBB77';
4535: my $mail_read_hover = '#999944';
4536: my $mail_replied = '#AAAA88';
4537: my $mail_replied_hover = '#888855';
4538: my $mail_other = '#99BBBB';
4539: my $mail_other_hover = '#669999';
1.391 albertel 4540: my $table_header = '#DDDDDD';
1.489 raeburn 4541: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4542: my $lg_border_color = '#C8C8C8';
1.392 albertel 4543:
1.608 albertel 4544: my $border = ($env{'browser.type'} eq 'explorer' ||
4545: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4546: : '0px 3px 0px 4px';
1.448 albertel 4547:
1.523 albertel 4548:
1.343 albertel 4549: return <<END;
1.698 harmsja 4550: body{
4551: font-family: $sans;
4552: line-height:130%;
1.701 harmsja 4553: font-size:0.83em;
1.698 harmsja 4554: color:$font;
4555: }
1.701 harmsja 4556: a:link, a:visited { font-size:100%; }
1.698 harmsja 4557:
1.779 bisitz 4558: a:focus { color: red; background: yellow }
1.510 albertel 4559: table.thinborder,
4560: table.thinborder tr th {
4561: border-style: solid;
4562: border-width: 1px;
1.698 harmsja 4563: border-color: $lg_border_color;
1.510 albertel 4564: background: $tabbg;
4565: }
1.523 albertel 4566: table.thinborder tr td {
1.510 albertel 4567: border-style: solid;
1.698 harmsja 4568: border-width: 1px;
4569: border-color: $lg_border_color;
1.510 albertel 4570: }
1.426 albertel 4571:
1.343 albertel 4572: form, .inline { display: inline; }
1.721 harmsja 4573:
4574: .LC_right {text-align:right;}
4575: .LC_middle {vertical-align:middle;}
4576:
4577: /* just for tests */
1.754 droeschl 4578: .LC_400Box {width:400px; }
1.721 harmsja 4579: /* end */
4580:
1.778 bisitz 4581: .LC_filename {
4582: font-family: $mono;
4583: white-space:pre;
4584: }
4585:
4586: .LC_fileicon {
4587: border: none;
4588: height: 1.3em;
4589: vertical-align: text-bottom;
4590: margin-right: 0.3em;
4591: text-decoration:none;
4592: }
4593:
1.350 albertel 4594: .LC_error {
4595: color: red;
4596: font-size: larger;
4597: }
1.457 albertel 4598: .LC_warning,
4599: .LC_diff_removed {
1.733 bisitz 4600: color: red;
1.394 albertel 4601: }
1.532 albertel 4602:
4603: .LC_info,
1.457 albertel 4604: .LC_success,
4605: .LC_diff_added {
1.350 albertel 4606: color: green;
4607: }
1.543 albertel 4608: .LC_unknown {
4609: color: yellow;
4610: }
4611:
1.440 albertel 4612: .LC_icon {
1.771 droeschl 4613: border: none;
1.790 droeschl 4614: vertical-align: middle;
1.771 droeschl 4615: }
4616:
1.539 albertel 4617: .LC_indexer_icon {
4618: border: 0px;
4619: height: 22px;
4620: }
1.543 albertel 4621: .LC_docs_spacer {
4622: width: 25px;
4623: height: 1px;
1.771 droeschl 4624: border: none;
1.543 albertel 4625: }
1.346 albertel 4626:
1.532 albertel 4627: .LC_internal_info {
1.735 bisitz 4628: color: #999999;
1.532 albertel 4629: }
4630:
1.458 albertel 4631: table.LC_pastsubmission {
4632: border: 1px solid black;
4633: margin: 2px;
4634: }
4635:
1.606 albertel 4636: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4637: width: 100%;
4638: background: $pgbg;
1.392 albertel 4639: border: 2px;
1.402 albertel 4640: border-collapse: separate;
1.403 albertel 4641: padding: 0px;
1.345 albertel 4642: }
1.392 albertel 4643:
1.779 bisitz 4644: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4645: table#LC_title_bar.LC_with_remote {
1.359 albertel 4646: width: 100%;
1.392 albertel 4647: border-color: $pgbg;
4648: border-style: solid;
4649: border-width: $border;
4650:
1.379 albertel 4651: background: $pgbg;
4652: font-family: $sans;
1.392 albertel 4653: border-collapse: collapse;
1.403 albertel 4654: padding: 0px;
1.359 albertel 4655: }
1.409 albertel 4656: table.LC_docs_path {
4657: width: 100%;
4658: border: 0;
4659: background: $pgbg;
4660: font-family: $sans;
4661: border-collapse: collapse;
4662: padding: 0px;
4663: }
4664:
1.359 albertel 4665: table#LC_title_bar td {
4666: background: $tabbg;
4667: }
1.773 ehlerst 4668: table#LC_title_bar .LC_title_bar_who {
1.359 albertel 4669: background: $tabbg;
4670: color: $font;
1.427 albertel 4671: font: small $sans;
1.359 albertel 4672: text-align: right;
1.773 ehlerst 4673: margin: 0px;
4674: }
4675: table#LC_title_bar .LC_title_bar_name {
4676: margin: 0px;
4677: }
4678: table#LC_title_bar .LC_title_bar_role {
4679: margin: 0px;
4680: }
1.775 bisitz 4681: table#LC_title_bar .LC_title_bar_realm {
1.773 ehlerst 4682: margin: 0px;
1.359 albertel 4683: }
1.469 banghart 4684: span.LC_metadata {
4685: font-family: $sans;
4686: }
1.359 albertel 4687:
1.706 harmsja 4688: table#LC_menubuttons img{
1.346 albertel 4689: border: 0px;
4690: }
1.345 albertel 4691: table#LC_top_nav td {
4692: background: $tabbg;
1.392 albertel 4693: border: 0px;
1.407 albertel 4694: font-size: small;
1.706 harmsja 4695: vertical-align:top;
4696: padding:2px 5px 2px 5px;
1.345 albertel 4697: }
4698: table#LC_top_nav td a, div#LC_top_nav a {
4699: color: $font;
4700: font-family: $sans;
4701: }
1.364 albertel 4702: table#LC_top_nav td.LC_top_nav_logo {
4703: background: $tabbg;
1.432 albertel 4704: text-align: left;
1.408 albertel 4705: white-space: nowrap;
1.432 albertel 4706: width: 31px;
1.408 albertel 4707: }
4708: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4709: border: 0px;
1.408 albertel 4710: vertical-align: bottom;
1.364 albertel 4711: }
1.777 tempelho 4712: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4713: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4714: width: 2.0em;
4715: }
1.442 albertel 4716: table#LC_top_nav td.LC_top_nav_login {
4717: width: 4.0em;
4718: text-align: center;
4719: }
1.409 albertel 4720: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4721: background: $tabbg;
4722: color: $font;
4723: font-family: $sans;
1.358 albertel 4724: font-size: smaller;
1.357 albertel 4725: }
1.777 tempelho 4726: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4727: table.LC_docs_path td.LC_docs_path_component {
1.779 bisitz 4728: background: $tabbg;
1.777 tempelho 4729: color: $font;
4730: font-family: $sans;
1.779 bisitz 4731: font-size: larger;
4732: text-align: right;
1.777 tempelho 4733: }
1.383 albertel 4734: td.LC_table_cell_checkbox {
4735: text-align: center;
4736: }
1.779 bisitz 4737: table#LC_mainmenu td.LC_mainmenu_column {
4738: vertical-align: top;
1.777 tempelho 4739: }
1.522 albertel 4740:
1.705 tempelho 4741: .LC_fontsize_small
4742: {
4743: font-size: 70%;
4744: }
4745:
4746: .LC_fontsize_medium
4747: {
4748: font-size: 85%;
4749: }
4750:
4751: .LC_fontsize_large
4752: {
4753: font-size: 120%;
4754: }
4755:
1.346 albertel 4756: .LC_menubuttons_inline_text {
4757: color: $font;
4758: font-family: $sans;
1.698 harmsja 4759: font-size: 90%;
1.701 harmsja 4760: padding-left:3px;
1.346 albertel 4761: }
4762:
1.526 www 4763: .LC_menubuttons_link {
4764: text-decoration: none;
4765: }
1.698 harmsja 4766: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4767: .LC_menubuttons_category {
1.521 www 4768: color: $font;
1.526 www 4769: background: $pgbg;
1.521 www 4770: font-family: $sans;
4771: font-size: larger;
4772: font-weight: bold;
4773: }
4774:
1.346 albertel 4775: td.LC_menubuttons_text {
1.779 bisitz 4776: color: $font;
1.346 albertel 4777: }
1.706 harmsja 4778:
4779:
1.526 www 4780:
1.346 albertel 4781: .LC_current_location {
4782: font-family: $sans;
4783: background: $tabbg;
4784: }
4785: .LC_new_mail {
4786: font-family: $sans;
1.634 www 4787: background: $tabbg;
1.346 albertel 4788: font-weight: bold;
4789: }
1.347 albertel 4790:
1.526 www 4791:
1.527 www 4792: .LC_dropadd_labeltext {
4793: font-family: $sans;
4794: text-align: right;
4795: }
4796:
4797: .LC_preferences_labeltext {
4798: font-family: $sans;
4799: text-align: right;
4800: }
4801:
1.666 raeburn 4802: .LC_roleslog_note {
1.701 harmsja 4803: font-size: small;
1.666 raeburn 4804: }
4805:
1.715 raeburn 4806: .LC_mail_functions {
4807: font-weight: bold;
4808: }
4809:
1.440 albertel 4810: table.LC_aboutme_port {
4811: border: 0px;
4812: border-collapse: collapse;
4813: border-spacing: 0px;
4814: }
1.349 albertel 4815: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4816: border: 1px solid #000000;
1.402 albertel 4817: border-collapse: separate;
1.426 albertel 4818: border-spacing: 1px;
1.610 albertel 4819: background: $pgbg;
1.347 albertel 4820: }
1.422 albertel 4821: .LC_data_table_dense {
4822: font-size: small;
4823: }
1.507 raeburn 4824: table.LC_nested_outer {
4825: border: 1px solid #000000;
1.589 raeburn 4826: border-collapse: collapse;
1.507 raeburn 4827: border-spacing: 0px;
4828: width: 100%;
4829: }
4830: table.LC_nested {
4831: border: 0px;
1.589 raeburn 4832: border-collapse: collapse;
1.507 raeburn 4833: border-spacing: 0px;
4834: width: 100%;
4835: }
1.523 albertel 4836: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4837: table.LC_prior_tries tr th {
1.349 albertel 4838: font-weight: bold;
4839: background-color: $data_table_head;
1.701 harmsja 4840: font-size:90%;
1.347 albertel 4841: }
1.711 raeburn 4842: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4843: background-color: #CCCCCC;
1.711 raeburn 4844: font-weight: bold;
4845: text-align: left;
4846: }
1.779 bisitz 4847: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4848: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4849: table.LC_aboutme_port tr td {
1.349 albertel 4850: background-color: $data_table_light;
1.425 albertel 4851: padding: 2px;
1.347 albertel 4852: }
1.610 albertel 4853: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4854: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4855: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4856: background-color: $data_table_dark;
1.709 bisitz 4857: padding: 2px;
1.347 albertel 4858: }
1.425 albertel 4859: table.LC_data_table tr.LC_data_table_highlight td {
4860: background-color: $data_table_darker;
4861: }
1.639 raeburn 4862: table.LC_data_table tr td.LC_leftcol_header {
4863: background-color: $data_table_head;
4864: font-weight: bold;
4865: }
1.451 albertel 4866: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4867: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4868: background-color: #FFFFFF;
1.421 albertel 4869: font-weight: bold;
4870: font-style: italic;
4871: text-align: center;
4872: padding: 8px;
1.347 albertel 4873: }
1.507 raeburn 4874: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4875: padding: 4ex
4876: }
1.507 raeburn 4877: table.LC_nested_outer tr th {
4878: font-weight: bold;
4879: background-color: $data_table_head;
1.701 harmsja 4880: font-size: small;
1.507 raeburn 4881: border-bottom: 1px solid #000000;
4882: }
4883: table.LC_nested_outer tr td.LC_subheader {
4884: background-color: $data_table_head;
4885: font-weight: bold;
4886: font-size: small;
4887: border-bottom: 1px solid #000000;
4888: text-align: right;
1.451 albertel 4889: }
1.507 raeburn 4890: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4891: background-color: #CCCCCC;
1.451 albertel 4892: font-weight: bold;
4893: font-size: small;
1.507 raeburn 4894: text-align: center;
4895: }
1.589 raeburn 4896: table.LC_nested tr.LC_info_row td.LC_left_item,
4897: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4898: text-align: left;
1.451 albertel 4899: }
1.507 raeburn 4900: table.LC_nested td {
1.735 bisitz 4901: background-color: #FFFFFF;
1.451 albertel 4902: font-size: small;
1.507 raeburn 4903: }
4904: table.LC_nested_outer tr th.LC_right_item,
4905: table.LC_nested tr.LC_info_row td.LC_right_item,
4906: table.LC_nested tr.LC_odd_row td.LC_right_item,
4907: table.LC_nested tr td.LC_right_item {
1.451 albertel 4908: text-align: right;
4909: }
4910:
1.507 raeburn 4911: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4912: background-color: #EEEEEE;
1.451 albertel 4913: }
4914:
1.473 raeburn 4915: table.LC_createuser {
4916: }
4917:
4918: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4919: font-size: small;
1.473 raeburn 4920: }
4921:
4922: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4923: background-color: #CCCCCC;
1.473 raeburn 4924: font-weight: bold;
4925: text-align: center;
4926: }
4927:
1.349 albertel 4928: table.LC_calendar {
4929: border: 1px solid #000000;
4930: border-collapse: collapse;
4931: }
4932: table.LC_calendar_pickdate {
4933: font-size: xx-small;
4934: }
4935: table.LC_calendar tr td {
4936: border: 1px solid #000000;
4937: vertical-align: top;
4938: }
4939: table.LC_calendar tr td.LC_calendar_day_empty {
4940: background-color: $data_table_dark;
4941: }
1.779 bisitz 4942: table.LC_calendar tr td.LC_calendar_day_current {
4943: background-color: $data_table_highlight;
1.777 tempelho 4944: }
1.349 albertel 4945: table.LC_mail_list tr.LC_mail_new {
4946: background-color: $mail_new;
4947: }
4948: table.LC_mail_list tr.LC_mail_new:hover {
4949: background-color: $mail_new_hover;
4950: }
1.777 tempelho 4951: table.LC_mail_list tr.LC_mail_even{
4952: }
4953: table.LC_mail_list tr.LC_mail_odd{
4954: }
1.349 albertel 4955: table.LC_mail_list tr.LC_mail_read {
4956: background-color: $mail_read;
4957: }
4958: table.LC_mail_list tr.LC_mail_read:hover {
4959: background-color: $mail_read_hover;
4960: }
4961: table.LC_mail_list tr.LC_mail_replied {
4962: background-color: $mail_replied;
4963: }
4964: table.LC_mail_list tr.LC_mail_replied:hover {
4965: background-color: $mail_replied_hover;
4966: }
4967: table.LC_mail_list tr.LC_mail_other {
4968: background-color: $mail_other;
4969: }
4970: table.LC_mail_list tr.LC_mail_other:hover {
4971: background-color: $mail_other_hover;
4972: }
1.494 raeburn 4973:
1.777 tempelho 4974: table.LC_data_table tr > td.LC_browser_file,
4975: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 4976: background: #CCFF88;
4977: }
1.777 tempelho 4978: table.LC_data_table tr > td.LC_browser_file_locked,
4979: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 4980: background: #FFAA99;
1.387 albertel 4981: }
1.777 tempelho 4982: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 4983: background: #AAAAAA;
4984: }
1.777 tempelho 4985: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 4986: table.LC_data_table tr > td.LC_browser_file_metamodified {
4987: background: #FFFF77;
1.777 tempelho 4988: }
1.696 bisitz 4989: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 4990: background: #CCCCFF;
1.387 albertel 4991: }
1.696 bisitz 4992:
1.707 bisitz 4993: table.LC_data_table tr > td.LC_roles_is {
4994: /* background: #77FF77; */
4995: }
4996: table.LC_data_table tr > td.LC_roles_future {
4997: background: #FFFF77;
4998: }
4999: table.LC_data_table tr > td.LC_roles_will {
5000: background: #FFAA77;
5001: }
5002: table.LC_data_table tr > td.LC_roles_expired {
5003: background: #FF7777;
5004: }
5005: table.LC_data_table tr > td.LC_roles_will_not {
5006: background: #AAFF77;
5007: }
5008: table.LC_data_table tr > td.LC_roles_selected {
5009: background: #11CC55;
5010: }
5011:
1.388 albertel 5012: span.LC_current_location {
1.701 harmsja 5013: font-size:larger;
1.388 albertel 5014: background: $pgbg;
5015: }
1.387 albertel 5016:
1.395 albertel 5017: span.LC_parm_menu_item {
5018: font-size: larger;
5019: font-family: $sans;
5020: }
5021: span.LC_parm_scope_all {
5022: color: red;
5023: }
5024: span.LC_parm_scope_folder {
5025: color: green;
5026: }
5027: span.LC_parm_scope_resource {
5028: color: orange;
5029: }
5030: span.LC_parm_part {
5031: color: blue;
5032: }
5033: span.LC_parm_folder, span.LC_parm_symb {
5034: font-size: x-small;
5035: font-family: $mono;
5036: color: #AAAAAA;
5037: }
5038:
1.396 albertel 5039: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
1.777 tempelho 5040: td.LC_parm_overview_parm_selectors,td.LC_parm_overview_restrictions {
1.396 albertel 5041: border: 1px solid black;
5042: border-collapse: collapse;
5043: }
5044: table.LC_parm_overview_restrictions td {
5045: border-width: 1px 4px 1px 4px;
5046: border-style: solid;
5047: border-color: $pgbg;
5048: text-align: center;
5049: }
5050: table.LC_parm_overview_restrictions th {
5051: background: $tabbg;
5052: border-width: 1px 4px 1px 4px;
5053: border-style: solid;
5054: border-color: $pgbg;
5055: }
1.398 albertel 5056: table#LC_helpmenu {
5057: border: 0px;
5058: height: 55px;
5059: border-spacing: 0px;
5060: }
5061:
5062: table#LC_helpmenu fieldset legend {
5063: font-size: larger;
5064: font-weight: bold;
5065: }
1.397 albertel 5066: table#LC_helpmenu_links {
5067: width: 100%;
5068: border: 1px solid black;
5069: background: $pgbg;
5070: padding: 0px;
5071: border-spacing: 1px;
5072: }
5073: table#LC_helpmenu_links tr td {
5074: padding: 1px;
5075: background: $tabbg;
1.399 albertel 5076: text-align: center;
5077: font-weight: bold;
1.397 albertel 5078: }
1.396 albertel 5079:
1.397 albertel 5080: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5081: table#LC_helpmenu_links a:active {
5082: text-decoration: none;
5083: color: $font;
5084: }
5085: table#LC_helpmenu_links a:hover {
5086: text-decoration: underline;
5087: color: $vlink;
5088: }
1.396 albertel 5089:
1.417 albertel 5090: .LC_chrt_popup_exists {
5091: border: 1px solid #339933;
5092: margin: -1px;
5093: }
5094: .LC_chrt_popup_up {
5095: border: 1px solid yellow;
5096: margin: -1px;
5097: }
5098: .LC_chrt_popup {
5099: border: 1px solid #8888FF;
5100: background: #CCCCFF;
5101: }
1.421 albertel 5102: table.LC_pick_box {
5103: border-collapse: separate;
5104: background: white;
5105: border: 1px solid black;
5106: border-spacing: 1px;
5107: }
5108: table.LC_pick_box td.LC_pick_box_title {
5109: background: $tabbg;
5110: font-weight: bold;
5111: text-align: right;
1.740 bisitz 5112: vertical-align: top;
1.421 albertel 5113: width: 184px;
5114: padding: 8px;
5115: }
1.645 raeburn 5116: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5117: background: $tabbg;
5118: font-weight: bold;
5119: text-align: right;
5120: width: 350px;
5121: padding: 8px;
5122: }
5123:
1.579 raeburn 5124: table.LC_pick_box td.LC_pick_box_value {
5125: text-align: left;
5126: padding: 8px;
5127: }
5128: table.LC_pick_box td.LC_pick_box_select {
5129: text-align: left;
5130: padding: 8px;
5131: }
1.424 albertel 5132: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5133: padding: 0px;
5134: height: 1px;
5135: background: black;
5136: }
5137: table.LC_pick_box td.LC_pick_box_submit {
5138: text-align: right;
5139: }
1.579 raeburn 5140: table.LC_pick_box td.LC_evenrow_value {
5141: text-align: left;
5142: padding: 8px;
5143: background-color: $data_table_light;
5144: }
5145: table.LC_pick_box td.LC_oddrow_value {
5146: text-align: left;
5147: padding: 8px;
5148: background-color: $data_table_light;
5149: }
5150: table.LC_helpform_receipt {
5151: width: 620px;
5152: border-collapse: separate;
5153: background: white;
5154: border: 1px solid black;
5155: border-spacing: 1px;
5156: }
5157: table.LC_helpform_receipt td.LC_pick_box_title {
5158: background: $tabbg;
5159: font-weight: bold;
5160: text-align: right;
5161: width: 184px;
5162: padding: 8px;
5163: }
5164: table.LC_helpform_receipt td.LC_evenrow_value {
5165: text-align: left;
5166: padding: 8px;
5167: background-color: $data_table_light;
5168: }
5169: table.LC_helpform_receipt td.LC_oddrow_value {
5170: text-align: left;
5171: padding: 8px;
5172: background-color: $data_table_light;
5173: }
5174: table.LC_helpform_receipt td.LC_pick_box_separator {
5175: padding: 0px;
5176: height: 1px;
5177: background: black;
5178: }
5179: span.LC_helpform_receipt_cat {
5180: font-weight: bold;
5181: }
1.424 albertel 5182: table.LC_group_priv_box {
5183: background: white;
5184: border: 1px solid black;
5185: border-spacing: 1px;
5186: }
5187: table.LC_group_priv_box td.LC_pick_box_title {
5188: background: $tabbg;
5189: font-weight: bold;
5190: text-align: right;
5191: width: 184px;
5192: }
5193: table.LC_group_priv_box td.LC_groups_fixed {
5194: background: $data_table_light;
5195: text-align: center;
5196: }
5197: table.LC_group_priv_box td.LC_groups_optional {
5198: background: $data_table_dark;
5199: text-align: center;
5200: }
5201: table.LC_group_priv_box td.LC_groups_functionality {
5202: background: $data_table_darker;
5203: text-align: center;
5204: font-weight: bold;
5205: }
5206: table.LC_group_priv td {
5207: text-align: left;
5208: padding: 0px;
5209: }
5210:
1.421 albertel 5211: table.LC_notify_front_page {
5212: background: white;
5213: border: 1px solid black;
5214: padding: 8px;
5215: }
5216: table.LC_notify_front_page td {
5217: padding: 8px;
5218: }
1.424 albertel 5219: .LC_navbuttons {
5220: margin: 2ex 0ex 2ex 0ex;
5221: }
1.423 albertel 5222: .LC_topic_bar {
5223: font-family: $sans;
5224: font-weight: bold;
5225: width: 100%;
5226: background: $tabbg;
5227: vertical-align: middle;
5228: margin: 2ex 0ex 2ex 0ex;
5229: }
5230: .LC_topic_bar span {
5231: vertical-align: middle;
5232: }
5233: .LC_topic_bar img {
5234: vertical-align: bottom;
5235: }
5236: table.LC_course_group_status {
5237: margin: 20px;
5238: }
5239: table.LC_status_selector td {
5240: vertical-align: top;
5241: text-align: center;
1.424 albertel 5242: padding: 4px;
5243: }
5244: table.LC_descriptive_input td.LC_description {
5245: vertical-align: top;
5246: text-align: right;
5247: font-weight: bold;
1.423 albertel 5248: }
1.599 albertel 5249: div.LC_feedback_link {
1.616 albertel 5250: clear: both;
1.599 albertel 5251: background: white;
1.779 bisitz 5252: width: 100%;
1.489 raeburn 5253: }
5254: span.LC_feedback_link {
1.599 albertel 5255: background: $feedback_link_bg;
5256: font-size: larger;
5257: }
5258: span.LC_message_link {
5259: background: $feedback_link_bg;
5260: font-size: larger;
5261: position: absolute;
5262: right: 1em;
1.489 raeburn 5263: }
1.421 albertel 5264:
1.515 albertel 5265: table.LC_prior_tries {
1.524 albertel 5266: border: 1px solid #000000;
5267: border-collapse: separate;
5268: border-spacing: 1px;
1.515 albertel 5269: }
1.523 albertel 5270:
1.515 albertel 5271: table.LC_prior_tries td {
1.524 albertel 5272: padding: 2px;
1.515 albertel 5273: }
1.523 albertel 5274:
5275: .LC_answer_correct {
5276: background: #AAFFAA;
5277: color: black;
5278: }
5279: .LC_answer_charged_try {
5280: background: #FFAAAA ! important;
5281: color: black;
5282: }
1.779 bisitz 5283: .LC_answer_not_charged_try,
1.523 albertel 5284: .LC_answer_no_grade,
5285: .LC_answer_late {
5286: background: #FFFFAA;
5287: color: black;
5288: }
5289: .LC_answer_previous {
5290: background: #AAAAFF;
5291: color: black;
5292: }
1.779 bisitz 5293: .LC_answer_no_message {
1.777 tempelho 5294: background: #FFFFFF;
5295: color: black;
1.779 bisitz 5296: }
5297: .LC_answer_unknown {
5298: background: orange;
5299: color: black;
1.777 tempelho 5300: }
1.529 albertel 5301: span.LC_prior_numerical,
5302: span.LC_prior_string,
5303: span.LC_prior_custom,
5304: span.LC_prior_reaction,
5305: span.LC_prior_math {
1.523 albertel 5306: font-family: monospace;
5307: white-space: pre;
5308: }
5309:
1.525 albertel 5310: span.LC_prior_string {
5311: font-family: monospace;
5312: white-space: pre;
5313: }
5314:
1.523 albertel 5315: table.LC_prior_option {
5316: width: 100%;
5317: border-collapse: collapse;
5318: }
1.528 albertel 5319: table.LC_prior_rank, table.LC_prior_match {
5320: border-collapse: collapse;
5321: }
5322: table.LC_prior_option tr td,
5323: table.LC_prior_rank tr td,
5324: table.LC_prior_match tr td {
1.524 albertel 5325: border: 1px solid #000000;
1.515 albertel 5326: }
5327:
1.770 droeschl 5328: td.LC_nobreak,
1.519 raeburn 5329: span.LC_nobreak {
1.544 albertel 5330: white-space: nowrap;
1.519 raeburn 5331: }
5332:
1.576 raeburn 5333: span.LC_cusr_emph {
5334: font-style: italic;
5335: }
5336:
1.633 raeburn 5337: span.LC_cusr_subheading {
5338: font-weight: normal;
5339: font-size: 85%;
5340: }
5341:
1.545 albertel 5342: table.LC_docs_documents {
5343: background: #BBBBBB;
1.547 albertel 5344: border-width: 0px;
1.545 albertel 5345: border-collapse: collapse;
5346: }
1.777 tempelho 5347: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5348: border: 2px solid black;
5349: padding: 4px;
1.777 tempelho 5350: }
1.545 albertel 5351: .LC_docs_entry_move {
5352: border: 0px;
5353: border-collapse: collapse;
1.544 albertel 5354: }
5355:
1.545 albertel 5356: .LC_docs_entry_move td {
5357: border: 2px solid #BBBBBB;
5358: background: #DDDDDD;
5359: }
5360:
5361: .LC_docs_editor td.LC_docs_entry_commands {
5362: background: #DDDDDD;
5363: font-size: x-small;
5364: }
1.544 albertel 5365: .LC_docs_copy {
1.545 albertel 5366: color: #000099;
1.544 albertel 5367: }
5368: .LC_docs_cut {
1.545 albertel 5369: color: #550044;
1.544 albertel 5370: }
5371: .LC_docs_rename {
1.545 albertel 5372: color: #009900;
1.544 albertel 5373: }
5374: .LC_docs_remove {
1.545 albertel 5375: color: #990000;
5376: }
5377:
1.547 albertel 5378: .LC_docs_reinit_warn,
5379: .LC_docs_ext_edit {
5380: font-size: x-small;
5381: }
5382:
1.545 albertel 5383: .LC_docs_editor td.LC_docs_entry_title,
5384: .LC_docs_editor td.LC_docs_entry_icon {
5385: background: #FFFFBB;
5386: }
5387: .LC_docs_editor td.LC_docs_entry_parameter {
5388: background: #BBBBFF;
5389: font-size: x-small;
5390: white-space: nowrap;
5391: }
5392:
5393: table.LC_docs_adddocs td,
5394: table.LC_docs_adddocs th {
5395: border: 1px solid #BBBBBB;
5396: padding: 4px;
5397: background: #DDDDDD;
1.543 albertel 5398: }
5399:
1.584 albertel 5400: table.LC_sty_begin {
5401: background: #BBFFBB;
5402: }
5403: table.LC_sty_end {
5404: background: #FFBBBB;
5405: }
5406:
1.589 raeburn 5407: table.LC_double_column {
5408: border-width: 0px;
5409: border-collapse: collapse;
5410: width: 100%;
5411: padding: 2px;
5412: }
5413:
5414: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5415: top: 2px;
1.589 raeburn 5416: left: 2px;
5417: width: 47%;
5418: vertical-align: top;
5419: }
5420:
5421: table.LC_double_column tr td.LC_right_col {
5422: top: 2px;
1.779 bisitz 5423: right: 2px;
1.589 raeburn 5424: width: 47%;
5425: vertical-align: top;
5426: }
5427:
1.594 raeburn 5428: span.LC_role_level {
5429: font-weight: bold;
5430: }
5431:
1.591 raeburn 5432: div.LC_left_float {
5433: float: left;
5434: padding-right: 5%;
1.597 albertel 5435: padding-bottom: 4px;
1.591 raeburn 5436: }
5437:
5438: div.LC_clear_float_header {
1.597 albertel 5439: padding-bottom: 2px;
1.591 raeburn 5440: }
5441:
5442: div.LC_clear_float_footer {
1.597 albertel 5443: padding-top: 10px;
1.591 raeburn 5444: clear: both;
5445: }
5446:
1.597 albertel 5447:
5448: div.LC_grade_show_user {
5449: margin-top: 20px;
5450: border: 1px solid black;
5451: }
5452: div.LC_grade_user_name {
5453: background: #DDDDEE;
5454: border-bottom: 1px solid black;
1.705 tempelho 5455: font-weight: bold;
5456: font-size: large;
1.597 albertel 5457: }
5458: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5459: background: #DDEEDD;
5460: }
5461:
5462: div.LC_grade_show_problem,
5463: div.LC_grade_submissions,
5464: div.LC_grade_message_center,
5465: div.LC_grade_info_links,
5466: div.LC_grade_assign {
5467: margin: 5px;
5468: width: 99%;
5469: background: #FFFFFF;
5470: }
5471: div.LC_grade_show_problem_header,
5472: div.LC_grade_submissions_header,
5473: div.LC_grade_message_center_header,
5474: div.LC_grade_assign_header {
1.705 tempelho 5475: font-weight: bold;
5476: font-size: large;
1.597 albertel 5477: }
5478: div.LC_grade_show_problem_problem,
5479: div.LC_grade_submissions_body,
5480: div.LC_grade_message_center_body,
5481: div.LC_grade_assign_body {
5482: border: 1px solid black;
5483: width: 99%;
5484: background: #FFFFFF;
5485: }
1.598 albertel 5486: span.LC_grade_check_note {
1.705 tempelho 5487: font-weight: normal;
5488: font-size: medium;
1.598 albertel 5489: display: inline;
5490: position: absolute;
5491: right: 1em;
5492: }
1.597 albertel 5493:
1.613 albertel 5494: table.LC_scantron_action {
5495: width: 100%;
5496: }
5497: table.LC_scantron_action tr th {
1.698 harmsja 5498: font-weight:bold;
5499: font-style:normal;
1.613 albertel 5500: }
1.779 bisitz 5501: .LC_edit_problem_header,
1.614 albertel 5502: div.LC_edit_problem_footer {
1.705 tempelho 5503: font-weight: normal;
5504: font-size: medium;
1.602 albertel 5505: margin: 2px;
1.600 albertel 5506: }
5507: div.LC_edit_problem_header,
1.602 albertel 5508: div.LC_edit_problem_header div,
1.614 albertel 5509: div.LC_edit_problem_footer,
5510: div.LC_edit_problem_footer div,
1.602 albertel 5511: div.LC_edit_problem_editxml_header,
5512: div.LC_edit_problem_editxml_header div {
1.600 albertel 5513: margin-top: 5px;
5514: }
1.602 albertel 5515: div.LC_edit_problem_header_edit_row {
5516: background: $tabbg;
5517: padding: 3px;
5518: margin-bottom: 5px;
5519: }
1.600 albertel 5520: div.LC_edit_problem_header_title {
1.705 tempelho 5521: font-weight: bold;
5522: font-size: larger;
1.602 albertel 5523: background: $tabbg;
5524: padding: 3px;
5525: }
5526: table.LC_edit_problem_header_title {
1.705 tempelho 5527: font-size: larger;
5528: font-weight: bold;
1.602 albertel 5529: width: 100%;
5530: border-color: $pgbg;
5531: border-style: solid;
5532: border-width: $border;
5533:
1.600 albertel 5534: background: $tabbg;
1.602 albertel 5535: border-collapse: collapse;
5536: padding: 0px
5537: }
5538:
5539: div.LC_edit_problem_discards {
5540: float: left;
5541: padding-bottom: 5px;
5542: }
5543: div.LC_edit_problem_saves {
5544: float: right;
5545: padding-bottom: 5px;
1.600 albertel 5546: }
5547: hr.LC_edit_problem_divide {
1.602 albertel 5548: clear: both;
1.600 albertel 5549: color: $tabbg;
5550: background-color: $tabbg;
5551: height: 3px;
5552: border: 0px;
5553: }
1.679 riegler 5554: img.stift{
1.678 riegler 5555: border-width:0;
1.679 riegler 5556: vertical-align:middle;
1.677 riegler 5557: }
1.680 riegler 5558:
1.681 riegler 5559: table#LC_mainmenu{
5560: margin-top:10px;
5561: width:80%;
5562:
5563: }
5564:
1.680 riegler 5565: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5566: vertical-align: top;
5567: width: 45%;
5568: }
1.779 bisitz 5569: .LC_mainmenu_fieldset_category {
5570: color: $font;
5571: background: $pgbg;
5572: font-family: $sans;
5573: font-size: small;
5574: font-weight: bold;
1.777 tempelho 5575: }
1.716 raeburn 5576: div.LC_createcourse {
5577: margin: 10px 10px 10px 10px;
5578: }
5579:
1.693 droeschl 5580: /* ---- Remove when done ----
5581: # The following styles is part of the redesign of LON-CAPA and are
5582: # subject to change during this project.
5583: # Don't rely on their current functionality as they might be
5584: # changed or removed.
5585: # --------------------------*/
5586:
1.698 harmsja 5587: a:hover,
1.721 harmsja 5588: ol.LC_smallMenu a:hover,
5589: ol#LC_MenuBreadcrumbs a:hover,
5590: ol#LC_PathBreadcrumbs a:hover,
5591: ul#LC_TabMainMenuContent a:hover,
5592: .LC_FormSectionClearButton input:hover
5593: ul.LC_TabContent li:hover a{
1.698 harmsja 5594: color:#BF2317;
5595: text-decoration:none;
1.693 droeschl 5596: }
5597:
1.779 bisitz 5598: h1 {
1.721 harmsja 5599: padding:5px 10px 5px 20px;
1.693 droeschl 5600: line-height:130%;
5601: }
1.698 harmsja 5602:
1.693 droeschl 5603: h2,h3,h4,h5,h6
5604: {
1.721 harmsja 5605: margin:5px 0px 5px 0px;
5606: padding:0px;
5607: line-height:130%;
1.693 droeschl 5608: }
1.721 harmsja 5609: .LC_hcell{
1.698 harmsja 5610: padding:3px 15px 3px 15px;
5611: margin:0px;
1.703 harmsja 5612: background-color:$tabbg;
1.779 bisitz 5613: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5614: }
1.721 harmsja 5615: .LC_noBorder {
1.698 harmsja 5616: border:0px;
5617: }
1.693 droeschl 5618:
5619:
1.698 harmsja 5620: /* Main Header with discription of Person, Course, etc. */
1.693 droeschl 5621:
1.761 tempelho 5622: .LC_Right {
5623: float: right;
5624: margin: 0px;
5625: padding: 0px;
5626: }
5627:
1.721 harmsja 5628: p, .LC_ContentBox {
1.698 harmsja 5629: padding: 10px;
5630:
5631: }
1.721 harmsja 5632: .LC_FormSectionClearButton input {
1.779 bisitz 5633: background-color:transparent;
1.698 harmsja 5634: border:0px;
5635: cursor:pointer;
5636: text-decoration:underline;
1.693 droeschl 5637: }
1.763 bisitz 5638:
5639: .LC_help_open_topic {
5640: color: #FFFFFF;
5641: background-color: #EEEEFF;
5642: margin: 1px;
5643: padding: 4px;
5644: border: 1px solid #000033;
5645: white-space: nowrap;
1.783 amueller 5646: /* vertical-align: middle; */
1.759 neumanie 5647: }
1.693 droeschl 5648:
1.698 harmsja 5649: dl,ul,div,fieldset {
5650: margin: 10px 10px 10px 0px;
1.693 droeschl 5651: overflow:hidden;
5652: }
1.721 harmsja 5653: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5654: margin: 0px;
1.693 droeschl 5655: }
5656:
1.721 harmsja 5657: ol.LC_smallMenu li {
1.693 droeschl 5658: display: inline;
5659: padding: 5px 5px 0px 10px;
5660: vertical-align: top;
5661: }
5662:
1.721 harmsja 5663: ol.LC_smallMenu li img {
1.693 droeschl 5664: vertical-align: bottom;
5665: }
5666:
1.721 harmsja 5667: ol.LC_smallMenu a {
1.693 droeschl 5668: font-size: 90%;
5669: color: RGB(80, 80, 80);
5670: text-decoration: none;
5671: }
1.760 harmsja 5672: ol#LC_TabMainMenuContent, ul.LC_TabContent ,
1.741 harmsja 5673: ul.LC_TabContentBigger {
1.721 harmsja 5674: display:block;
5675: list-style:none;
1.741 harmsja 5676: margin: 0px;
1.693 droeschl 5677: padding: 0px;
5678: }
5679:
1.744 ehlerst 5680: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741 harmsja 5681: ul.LC_TabContentBigger li{
1.693 droeschl 5682: display: inline;
1.741 harmsja 5683: border-right: solid 1px $lg_border_color;
5684: float:left;
5685: line-height:140%;
5686: white-space:nowrap;
5687: }
5688: ol#LC_TabMainMenuContent li{
1.693 droeschl 5689: vertical-align: bottom;
5690: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5691: padding: 5px 10px 5px 10px;
1.741 harmsja 5692: margin-right:5px;
5693: margin-bottom:3px;
1.693 droeschl 5694: font-weight: bold;
1.723 riegler 5695: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5696: }
5697:
1.721 harmsja 5698: ol#LC_TabMainMenuContent li a{
1.693 droeschl 5699: color: RGB(47, 47, 47);
5700: text-decoration: none;
5701: }
1.721 harmsja 5702: ul.LC_TabContent {
1.741 harmsja 5703: min-height:1.6em;
1.721 harmsja 5704: }
5705: ul.LC_TabContent li{
1.741 harmsja 5706: vertical-align:middle;
5707: padding:0px 10px 0px 10px;
1.745 ehlerst 5708: background-color:$tabbg;
5709: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5710: }
1.779 bisitz 5711: ul.LC_TabContent li a, ul.LC_TabContent li{
1.721 harmsja 5712: color:rgb(47,47,47);
5713: text-decoration:none;
5714: font-size:95%;
5715: font-weight:bold;
1.761 tempelho 5716: padding-right: 16px;
1.721 harmsja 5717: }
1.744 ehlerst 5718: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
1.761 tempelho 5719: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745 ehlerst 5720: border-bottom:solid 1px #FFFFFF;
1.761 tempelho 5721: padding-right: 16px;
1.744 ehlerst 5722: }
1.741 harmsja 5723: ul.LC_TabContentBigger li{
5724: vertical-align:bottom;
5725: border-top:solid 1px $lg_border_color;
5726: border-left:solid 1px $lg_border_color;
5727: padding:5px 10px 5px 10px;
5728: margin-left:2px;
5729: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5730: }
1.744 ehlerst 5731: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
5732: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5733: }
1.741 harmsja 5734: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5735: font-size:110%;
5736: font-weight:bold;
5737: }
1.693 droeschl 5738:
1.783 amueller 5739: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs, ul.LC_CourseBreadcrumbs{
1.693 droeschl 5740: border-top: solid 1px RGB(255, 255, 255);
5741: height: 20px;
5742: line-height: 20px;
5743: vertical-align: bottom;
5744: margin: 0px 0px 30px 0px;
5745: padding-left: 10px;
5746: list-style-position: inside;
1.723 riegler 5747: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5748: }
5749:
1.783 amueller 5750: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li, ul.LC_CourseBreadcrumbs li {
1.741 harmsja 5751: /*
1.723 riegler 5752: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779 bisitz 5753: */
1.693 droeschl 5754: display: inline;
5755: padding: 0px 0px 0px 10px;
1.783 amueller 5756: /* vertical-align: bottom; */
1.693 droeschl 5757: overflow:hidden;
5758: }
5759:
1.783 amueller 5760: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 5761: text-decoration: none;
5762: font-size:90%;
5763: }
1.721 harmsja 5764: ol#LC_PathBreadcrumbs li a{
1.698 harmsja 5765: text-decoration:none;
5766: font-size:100%;
5767: font-weight:bold;
1.693 droeschl 5768: }
1.786 neumanie 5769: .LC_BoxPadding
5770: {
5771: padding: 10px;
5772: }
1.721 harmsja 5773: .LC_ContentBoxSpecial
1.693 droeschl 5774: {
1.701 harmsja 5775: border: solid 1px $lg_border_color;
1.746 neumanie 5776: }
5777: .LC_ContentBoxSpecialContactInfo
5778: {
5779: border: solid 1px $lg_border_color;
5780: max-width:25%;
5781: min-width:25%;
1.698 harmsja 5782: }
1.747 neumanie 5783: .LC_AboutMe_Image
5784: {
5785: float:left;
5786: margin-right:10px;
5787: }
5788: .LC_Clear_AboutMe_Image
5789: {
5790: clear:left;
5791: }
1.721 harmsja 5792: dl.LC_ListStyleClean dt {
1.693 droeschl 5793: padding-right: 5px;
5794: display: table-header-group;
5795: }
5796:
1.721 harmsja 5797: dl.LC_ListStyleClean dd {
1.693 droeschl 5798: display: table-row;
5799: }
5800:
1.721 harmsja 5801: .LC_ListStyleClean,
5802: .LC_ListStyleSimple,
5803: .LC_ListStyleNormal,
1.777 tempelho 5804: .LC_ListStyle_Border,
1.721 harmsja 5805: .LC_ListStyleSpecial
1.693 droeschl 5806: {
5807: /*display:block; */
5808: list-style-position: inside;
5809: list-style-type: none;
5810: overflow: hidden;
5811: padding: 0px;
5812: }
5813:
1.721 harmsja 5814: .LC_ListStyleSimple li,
5815: .LC_ListStyleSimple dd,
5816: .LC_ListStyleNormal li,
5817: .LC_ListStyleNormal dd,
5818: .LC_ListStyleSpecial li,
5819: .LC_ListStyleSpecial dd
1.693 droeschl 5820: {
5821: margin: 0px;
5822: padding: 5px 5px 5px 10px;
5823: clear: both;
5824: }
5825:
1.721 harmsja 5826: .LC_ListStyleClean li,
5827: .LC_ListStyleClean dd {
1.693 droeschl 5828: padding-top: 0px;
5829: padding-bottom: 0px;
5830: }
5831:
1.721 harmsja 5832: .LC_ListStyleSimple dd,
5833: .LC_ListStyleSimple li{
1.698 harmsja 5834: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 5835: }
5836:
1.721 harmsja 5837: .LC_ListStyleSpecial li,
5838: .LC_ListStyleSpecial dd {
1.693 droeschl 5839: list-style-type: none;
5840: background-color: RGB(220, 220, 220);
5841: margin-bottom: 4px;
5842: }
5843:
1.721 harmsja 5844: table.LC_SimpleTable {
1.698 harmsja 5845: margin:5px;
5846: border:solid 1px $lg_border_color;
1.693 droeschl 5847: }
5848:
1.721 harmsja 5849: table.LC_SimpleTable tr {
1.698 harmsja 5850: padding:0px;
5851: border:solid 1px $lg_border_color;
1.693 droeschl 5852: }
1.721 harmsja 5853: table.LC_SimpleTable thead{
1.698 harmsja 5854: background:rgb(220,220,220);
1.693 droeschl 5855: }
5856:
1.721 harmsja 5857: div.LC_columnSection {
1.693 droeschl 5858: display: block;
5859: clear: both;
5860: overflow: hidden;
5861: margin:0px;
5862: }
5863:
1.721 harmsja 5864: div.LC_columnSection>* {
1.693 droeschl 5865: float: left;
5866: margin: 10px 20px 10px 0px;
1.747 neumanie 5867: overflow:hidden;
1.693 droeschl 5868: }
1.721 harmsja 5869:
1.719 ehlerst 5870: .ContentBoxSpecialTemplate
5871: {
1.747 neumanie 5872: border: solid 1px $lg_border_color;
1.719 ehlerst 5873: }
5874: .ContentBoxTemplate {
5875: padding:10px;
5876: }
5877:
1.721 harmsja 5878: div.LC_columnSection > .ContentBoxTemplate,
5879: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719 ehlerst 5880: {
5881: width: 600px;
5882: }
1.753 droeschl 5883:
1.720 ehlerst 5884: .clear{
5885: clear: both;
5886: line-height: 0px;
5887: font-size: 0px;
5888: height: 0px;
5889: }
1.693 droeschl 5890:
1.694 tempelho 5891: .LC_loginpage_container {
5892: text-align:left;
5893: margin : 0 auto;
1.785 tempelho 5894: width:90%;
1.694 tempelho 5895: padding: 10px;
5896: height: auto;
1.712 muellerd 5897: background-color:#FFFFFF;
1.694 tempelho 5898: border:1px solid #CCCCCC;
5899: }
5900:
5901:
5902: .LC_loginpage_loginContainer {
5903: float:left;
1.712 muellerd 5904: width: 182px;
1.785 tempelho 5905: padding: 2px;
1.712 muellerd 5906: border:1px solid #CCCCCC;
5907: background-color:$loginbg;
1.694 tempelho 5908: }
5909:
1.717 tempelho 5910: .LC_loginpage_loginContainer h2{
1.712 muellerd 5911: margin-top:0;
5912: display:block;
5913: background:$bgcol;
5914: color:$textcol;
5915: padding-left:5px;
5916: }
1.785 tempelho 5917:
1.694 tempelho 5918: .LC_loginpage_loginInfo {
5919: float:left;
1.785 tempelho 5920: width:182px;
1.694 tempelho 5921: border:1px solid #CCCCCC;
1.785 tempelho 5922: padding:2px;
1.712 muellerd 5923: }
5924:
1.694 tempelho 5925: .LC_loginpage_space {
1.754 droeschl 5926: clear: both;
5927: margin-bottom: 20px;
1.694 tempelho 5928: border-bottom: 1px solid #CCCCCC;
5929: }
5930:
1.785 tempelho 5931: .LC_loginpage_floatLeft {
5932: float: left;
5933: width: 200px;
5934: margin: 0;
5935: }
5936:
1.748 schulted 5937: table em{
1.754 droeschl 5938: font-weight: bold;
5939: font-style: normal;
1.748 schulted 5940: }
1.779 bisitz 5941: table.LC_tableBrowseRes,
1.768 schulted 5942: table.LC_tableOfContent{
1.769 schulted 5943: border:none;
5944: border-spacing: 1;
1.754 droeschl 5945: padding: 3px;
5946: background-color: #FFFFFF;
5947: font-size: 90%;
1.753 droeschl 5948: }
1.789 droeschl 5949:
5950: table.LC_tableOfContent{
5951: border-collapse: collapse;
5952: }
5953:
1.771 droeschl 5954: table.LC_tableBrowseRes a,
1.768 schulted 5955: table.LC_tableOfContent a {
1.771 droeschl 5956: background-color: transparent;
1.753 droeschl 5957: text-decoration: none;
5958: }
5959:
1.771 droeschl 5960: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 5961: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 5962: background-color: #EEEEEE;
1.753 droeschl 5963: }
5964:
1.768 schulted 5965: table.LC_tableOfContent img{
1.753 droeschl 5966: border: none;
5967: height: 1.3em;
5968: vertical-align: text-bottom;
5969: margin-right: 0.3em;
5970: }
1.757 schulted 5971:
1.774 ehlerst 5972: a#LC_content_toolbar_firsthomework{
5973: background-image:url(/res/adm/pages/open-first-problem.gif);
5974: }
5975:
5976: a#LC_content_toolbar_launchnav{
5977: background-image:url(/res/adm/pages/start-navigation.gif);
5978: }
5979:
5980: a#LC_content_toolbar_closenav{
5981: background-image:url(/res/adm/pages/close-navigation.gif);
5982: }
5983:
5984: a#LC_content_toolbar_everything{
5985: background-image:url(/res/adm/pages/show-all.gif);
5986: }
5987:
5988: a#LC_content_toolbar_uncompleted{
5989: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
5990: }
5991:
5992: #LC_content_toolbar_clearbubbles{
5993: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
5994: }
5995:
1.757 schulted 5996: a#LC_content_toolbar_changefolder{
5997: background : url(/res/adm/pages/close-all-folders.gif) top center ;
5998: }
5999:
6000: a#LC_content_toolbar_changefolder_toggled{
6001: background-image:url(/res/adm/pages/open-all-folders.gif);
6002: }
6003:
6004: ul#LC_toolbar li a:hover{
6005: background-position: bottom center;
6006: }
6007:
6008: ul#LC_toolbar{
1.779 bisitz 6009: padding:0;
1.757 schulted 6010: margin: 2px;
6011: list-style:none;
6012: position:relative;
6013: background-color:white;
6014: }
6015:
6016: ul#LC_toolbar li{
6017: border:1px solid white;
6018: padding:0;
6019: margin: 0;
1.767 droeschl 6020: float: left;
6021: display:inline;
1.757 schulted 6022: vertical-align:middle;
6023: }
6024:
1.783 amueller 6025:
1.757 schulted 6026: a.LC_toolbarItem{
1.767 droeschl 6027: display:block;
1.757 schulted 6028: padding:0;
6029: margin:0;
6030: height: 32px;
6031: width: 32px;
1.779 bisitz 6032: color:white;
6033: border:0 none;
1.757 schulted 6034: background-repeat:no-repeat;
6035: background-color:transparent;
6036: }
6037:
1.782 bisitz 6038: ul.LC_functionslist li {
6039: float: left;
6040: white-space: nowrap;
6041: height: 35px; /* at least as high as heighest list item */
6042: margin: 0px 15px 15px 10px;
6043: }
6044:
1.757 schulted 6045:
1.343 albertel 6046: END
6047: }
6048:
1.306 albertel 6049: =pod
6050:
6051: =item * &headtag()
6052:
6053: Returns a uniform footer for LON-CAPA web pages.
6054:
1.307 albertel 6055: Inputs: $title - optional title for the head
6056: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6057: $args - optional arguments
1.319 albertel 6058: force_register - if is true call registerurl so the remote is
6059: informed
1.415 albertel 6060: redirect -> array ref of
6061: 1- seconds before redirect occurs
6062: 2- url to redirect to
6063: 3- whether the side effect should occur
1.315 albertel 6064: (side effect of setting
6065: $env{'internal.head.redirect'} to the url
6066: redirected too)
1.352 albertel 6067: domain -> force to color decorate a page for a specific
6068: domain
6069: function -> force usage of a specific rolish color scheme
6070: bgcolor -> override the default page bgcolor
1.460 albertel 6071: no_auto_mt_title
6072: -> prevent &mt()ing the title arg
1.464 albertel 6073:
1.306 albertel 6074: =cut
6075:
6076: sub headtag {
1.313 albertel 6077: my ($title,$head_extra,$args) = @_;
1.306 albertel 6078:
1.363 albertel 6079: my $function = $args->{'function'} || &get_users_function();
6080: my $domain = $args->{'domain'} || &determinedomain();
6081: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6082: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6083: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6084: #time(),
1.418 albertel 6085: $env{'environment.color.timestamp'},
1.363 albertel 6086: $function,$domain,$bgcolor);
6087:
1.369 www 6088: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6089:
1.308 albertel 6090: my $result =
6091: '<head>'.
1.461 albertel 6092: &font_settings();
1.319 albertel 6093:
1.461 albertel 6094: if (!$args->{'frameset'}) {
6095: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6096: }
1.319 albertel 6097: if ($args->{'force_register'}) {
6098: $result .= &Apache::lonmenu::registerurl(1);
6099: }
1.436 albertel 6100: if (!$args->{'no_nav_bar'}
6101: && !$args->{'only_body'}
6102: && !$args->{'frameset'}) {
6103: $result .= &help_menu_js();
6104: }
1.319 albertel 6105:
1.314 albertel 6106: if (ref($args->{'redirect'})) {
1.414 albertel 6107: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6108: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6109: if (!$inhibit_continue) {
6110: $env{'internal.head.redirect'} = $url;
6111: }
1.313 albertel 6112: $result.=<<ADDMETA
6113: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6114: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6115: ADDMETA
6116: }
1.306 albertel 6117: if (!defined($title)) {
6118: $title = 'The LearningOnline Network with CAPA';
6119: }
1.460 albertel 6120: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6121: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6122: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6123: .$head_extra;
1.306 albertel 6124: return $result;
6125: }
6126:
6127: =pod
6128:
1.340 albertel 6129: =item * &font_settings()
6130:
6131: Returns neccessary <meta> to set the proper encoding
6132:
6133: Inputs: none
6134:
6135: =cut
6136:
6137: sub font_settings {
6138: my $headerstring='';
1.647 www 6139: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6140: $headerstring.=
6141: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6142: }
6143: return $headerstring;
6144: }
6145:
1.341 albertel 6146: =pod
6147:
6148: =item * &xml_begin()
6149:
6150: Returns the needed doctype and <html>
6151:
6152: Inputs: none
6153:
6154: =cut
6155:
6156: sub xml_begin {
6157: my $output='';
6158:
1.592 albertel 6159: if ($env{'internal.start_page'}==1) {
6160: &Apache::lonhtmlcommon::init_htmlareafields();
6161: }
1.342 albertel 6162:
1.341 albertel 6163: if ($env{'browser.mathml'}) {
6164: $output='<?xml version="1.0"?>'
6165: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6166: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6167:
6168: # .'<!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">] >'
6169: .'<!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">'
6170: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6171: .'xmlns="http://www.w3.org/1999/xhtml">';
6172: } else {
6173: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6174: }
6175: return $output;
6176: }
1.340 albertel 6177:
6178: =pod
6179:
1.306 albertel 6180: =item * &endheadtag()
6181:
6182: Returns a uniform </head> for LON-CAPA web pages.
6183:
6184: Inputs: none
6185:
6186: =cut
6187:
6188: sub endheadtag {
6189: return '</head>';
6190: }
6191:
6192: =pod
6193:
6194: =item * &head()
6195:
6196: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6197:
1.648 raeburn 6198: Inputs:
6199:
6200: =over 4
6201:
6202: $title - optional title for the page
6203:
6204: $head_extra - optional extra HTML to put inside the <head>
6205:
6206: =back
1.405 albertel 6207:
1.306 albertel 6208: =cut
6209:
6210: sub head {
1.325 albertel 6211: my ($title,$head_extra,$args) = @_;
6212: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6213: }
6214:
6215: =pod
6216:
6217: =item * &start_page()
6218:
6219: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6220:
1.648 raeburn 6221: Inputs:
6222:
6223: =over 4
6224:
6225: $title - optional title for the page
6226:
6227: $head_extra - optional extra HTML to incude inside the <head>
6228:
6229: $args - additional optional args supported are:
6230:
6231: =over 8
6232:
6233: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6234: arg on
1.648 raeburn 6235: no_nav_bar -> is true will set &bodytag() notopbar arg on
6236: add_entries -> additional attributes to add to the <body>
6237: domain -> force to color decorate a page for a
1.317 albertel 6238: specific domain
1.648 raeburn 6239: function -> force usage of a specific rolish color
1.317 albertel 6240: scheme
1.648 raeburn 6241: redirect -> see &headtag()
6242: bgcolor -> override the default page bg color
6243: js_ready -> return a string ready for being used in
1.317 albertel 6244: a javascript writeln
1.648 raeburn 6245: html_encode -> return a string ready for being used in
1.320 albertel 6246: a html attribute
1.648 raeburn 6247: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6248: $forcereg arg
1.648 raeburn 6249: body_title -> alternate text to use instead of $title
1.326 albertel 6250: in the title box that appears, this text
6251: is not auto translated like the $title is
1.648 raeburn 6252: frameset -> if true will start with a <frameset>
1.330 albertel 6253: rather than <body>
1.648 raeburn 6254: no_title -> if true the title bar won't be shown
6255: skip_phases -> hash ref of
1.338 albertel 6256: head -> skip the <html><head> generation
6257: body -> skip all <body> generation
1.648 raeburn 6258: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6259: 'Switch To Inline Menu' link
1.648 raeburn 6260: no_auto_mt_title -> prevent &mt()ing the title arg
6261: inherit_jsmath -> when creating popup window in a page,
6262: should it have jsmath forced on by the
6263: current page
1.361 albertel 6264:
1.648 raeburn 6265: =back
1.460 albertel 6266:
1.648 raeburn 6267: =back
1.562 albertel 6268:
1.306 albertel 6269: =cut
6270:
6271: sub start_page {
1.309 albertel 6272: my ($title,$head_extra,$args) = @_;
1.318 albertel 6273: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6274: my %head_args;
1.352 albertel 6275: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6276: 'bgcolor','frameset','no_nav_bar','only_body',
6277: 'no_auto_mt_title') {
1.319 albertel 6278: if (defined($args->{$arg})) {
1.324 raeburn 6279: $head_args{$arg} = $args->{$arg};
1.319 albertel 6280: }
1.313 albertel 6281: }
1.319 albertel 6282:
1.315 albertel 6283: $env{'internal.start_page'}++;
1.338 albertel 6284: my $result;
6285: if (! exists($args->{'skip_phases'}{'head'}) ) {
6286: $result.=
1.341 albertel 6287: &xml_begin().
1.338 albertel 6288: &headtag($title,$head_extra,\%head_args).&endheadtag();
6289: }
6290:
6291: if (! exists($args->{'skip_phases'}{'body'}) ) {
6292: if ($args->{'frameset'}) {
6293: my $attr_string = &make_attr_string($args->{'force_register'},
6294: $args->{'add_entries'});
6295: $result .= "\n<frameset $attr_string>\n";
6296: } else {
6297: $result .=
6298: &bodytag($title,
6299: $args->{'function'}, $args->{'add_entries'},
6300: $args->{'only_body'}, $args->{'domain'},
6301: $args->{'force_register'}, $args->{'body_title'},
6302: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6303: $args->{'no_title'}, $args->{'no_inline_link'},
6304: $args);
1.338 albertel 6305: }
1.330 albertel 6306: }
1.338 albertel 6307:
1.315 albertel 6308: if ($args->{'js_ready'}) {
1.713 kaisler 6309: $result = &js_ready($result);
1.315 albertel 6310: }
1.320 albertel 6311: if ($args->{'html_encode'}) {
1.713 kaisler 6312: $result = &html_encode($result);
6313: }
6314:
1.758 kaisler 6315: #Breadcrumbs
6316: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6317: &Apache::lonhtmlcommon::clear_breadcrumbs();
6318: #if any br links exists, add them to the breadcrumbs
6319: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6320: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6321: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6322: }
6323: }
6324:
6325: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6326: if(exists($args->{'bread_crumbs_component'})){
6327: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6328: }else{
6329: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6330: }
1.320 albertel 6331: }
1.315 albertel 6332: return $result;
1.306 albertel 6333: }
6334:
1.330 albertel 6335:
1.306 albertel 6336: =pod
6337:
6338: =item * &head()
6339:
6340: Returns a complete </body></html> section for LON-CAPA web pages.
6341:
1.315 albertel 6342: Inputs: $args - additional optional args supported are:
6343: js_ready -> return a string ready for being used in
6344: a javascript writeln
1.320 albertel 6345: html_encode -> return a string ready for being used in
6346: a html attribute
1.330 albertel 6347: frameset -> if true will start with a <frameset>
6348: rather than <body>
1.493 albertel 6349: dicsussion -> if true will get discussion from
6350: lonxml::xmlend
6351: (you can pass the target and parser arguments
6352: through optional 'target' and 'parser' args
6353: to this routine)
1.306 albertel 6354:
6355: =cut
6356:
6357: sub end_page {
1.315 albertel 6358: my ($args) = @_;
6359: $env{'internal.end_page'}++;
1.330 albertel 6360: my $result;
1.335 albertel 6361: if ($args->{'discussion'}) {
6362: my ($target,$parser);
6363: if (ref($args->{'discussion'})) {
6364: ($target,$parser) =($args->{'discussion'}{'target'},
6365: $args->{'discussion'}{'parser'});
6366: }
6367: $result .= &Apache::lonxml::xmlend($target,$parser);
6368: }
6369:
1.330 albertel 6370: if ($args->{'frameset'}) {
6371: $result .= '</frameset>';
6372: } else {
1.635 raeburn 6373: $result .= &endbodytag($args);
1.330 albertel 6374: }
6375: $result .= "\n</html>";
6376:
1.315 albertel 6377: if ($args->{'js_ready'}) {
1.317 albertel 6378: $result = &js_ready($result);
1.315 albertel 6379: }
1.335 albertel 6380:
1.320 albertel 6381: if ($args->{'html_encode'}) {
6382: $result = &html_encode($result);
6383: }
1.335 albertel 6384:
1.315 albertel 6385: return $result;
6386: }
6387:
1.320 albertel 6388: sub html_encode {
6389: my ($result) = @_;
6390:
1.322 albertel 6391: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6392:
6393: return $result;
6394: }
1.317 albertel 6395: sub js_ready {
6396: my ($result) = @_;
6397:
1.323 albertel 6398: $result =~ s/[\n\r]/ /xmsg;
6399: $result =~ s/\\/\\\\/xmsg;
6400: $result =~ s/'/\\'/xmsg;
1.372 albertel 6401: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6402:
6403: return $result;
6404: }
6405:
1.315 albertel 6406: sub validate_page {
6407: if ( exists($env{'internal.start_page'})
1.316 albertel 6408: && $env{'internal.start_page'} > 1) {
6409: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6410: $env{'internal.start_page'}.' '.
1.316 albertel 6411: $ENV{'request.filename'});
1.315 albertel 6412: }
6413: if ( exists($env{'internal.end_page'})
1.316 albertel 6414: && $env{'internal.end_page'} > 1) {
6415: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6416: $env{'internal.end_page'}.' '.
1.316 albertel 6417: $env{'request.filename'});
1.315 albertel 6418: }
6419: if ( exists($env{'internal.start_page'})
6420: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6421: &Apache::lonnet::logthis('start_page called without end_page '.
6422: $env{'request.filename'});
1.315 albertel 6423: }
6424: if ( ! exists($env{'internal.start_page'})
6425: && exists($env{'internal.end_page'})) {
1.316 albertel 6426: &Apache::lonnet::logthis('end_page called without start_page'.
6427: $env{'request.filename'});
1.315 albertel 6428: }
1.306 albertel 6429: }
1.315 albertel 6430:
1.318 albertel 6431: sub simple_error_page {
6432: my ($r,$title,$msg) = @_;
6433: my $page =
6434: &Apache::loncommon::start_page($title).
6435: &mt($msg).
6436: &Apache::loncommon::end_page();
6437: if (ref($r)) {
6438: $r->print($page);
1.327 albertel 6439: return;
1.318 albertel 6440: }
6441: return $page;
6442: }
1.347 albertel 6443:
6444: {
1.610 albertel 6445: my @row_count;
1.347 albertel 6446: sub start_data_table {
1.422 albertel 6447: my ($add_class) = @_;
6448: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6449: unshift(@row_count,0);
1.422 albertel 6450: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6451: }
6452:
6453: sub end_data_table {
1.610 albertel 6454: shift(@row_count);
1.389 albertel 6455: return '</table>'."\n";;
1.347 albertel 6456: }
6457:
6458: sub start_data_table_row {
1.422 albertel 6459: my ($add_class) = @_;
1.610 albertel 6460: $row_count[0]++;
6461: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6462: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6463: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6464: }
1.471 banghart 6465:
6466: sub continue_data_table_row {
6467: my ($add_class) = @_;
1.610 albertel 6468: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6469: $css_class = (join(' ',$css_class,$add_class));
6470: return '<tr class="'.$css_class.'">'."\n";;
6471: }
1.347 albertel 6472:
6473: sub end_data_table_row {
1.389 albertel 6474: return '</tr>'."\n";;
1.347 albertel 6475: }
1.367 www 6476:
1.421 albertel 6477: sub start_data_table_empty_row {
1.707 bisitz 6478: # $row_count[0]++;
1.421 albertel 6479: return '<tr class="LC_empty_row" >'."\n";;
6480: }
6481:
6482: sub end_data_table_empty_row {
6483: return '</tr>'."\n";;
6484: }
6485:
1.367 www 6486: sub start_data_table_header_row {
1.389 albertel 6487: return '<tr class="LC_header_row">'."\n";;
1.367 www 6488: }
6489:
6490: sub end_data_table_header_row {
1.389 albertel 6491: return '</tr>'."\n";;
1.367 www 6492: }
1.347 albertel 6493: }
6494:
1.548 albertel 6495: =pod
6496:
6497: =item * &inhibit_menu_check($arg)
6498:
6499: Checks for a inhibitmenu state and generates output to preserve it
6500:
6501: Inputs: $arg - can be any of
6502: - undef - in which case the return value is a string
6503: to add into arguments list of a uri
6504: - 'input' - in which case the return value is a HTML
6505: <form> <input> field of type hidden to
6506: preserve the value
6507: - a url - in which case the return value is the url with
6508: the neccesary cgi args added to preserve the
6509: inhibitmenu state
6510: - a ref to a url - no return value, but the string is
6511: updated to include the neccessary cgi
6512: args to preserve the inhibitmenu state
6513:
6514: =cut
6515:
6516: sub inhibit_menu_check {
6517: my ($arg) = @_;
6518: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6519: if ($arg eq 'input') {
6520: if ($env{'form.inhibitmenu'}) {
6521: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6522: } else {
6523: return
6524: }
6525: }
6526: if ($env{'form.inhibitmenu'}) {
6527: if (ref($arg)) {
6528: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6529: } elsif ($arg eq '') {
6530: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6531: } else {
6532: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6533: }
6534: }
6535: if (!ref($arg)) {
6536: return $arg;
6537: }
6538: }
6539:
1.251 albertel 6540: ###############################################
1.182 matthew 6541:
6542: =pod
6543:
1.549 albertel 6544: =back
6545:
6546: =head1 User Information Routines
6547:
6548: =over 4
6549:
1.405 albertel 6550: =item * &get_users_function()
1.182 matthew 6551:
6552: Used by &bodytag to determine the current users primary role.
6553: Returns either 'student','coordinator','admin', or 'author'.
6554:
6555: =cut
6556:
6557: ###############################################
6558: sub get_users_function {
6559: my $function = 'student';
1.258 albertel 6560: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6561: $function='coordinator';
6562: }
1.258 albertel 6563: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6564: $function='admin';
6565: }
1.258 albertel 6566: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6567: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6568: $function='author';
6569: }
6570: return $function;
1.54 www 6571: }
1.99 www 6572:
6573: ###############################################
6574:
1.233 raeburn 6575: =pod
6576:
1.542 raeburn 6577: =item * &check_user_status()
1.274 raeburn 6578:
6579: Determines current status of supplied role for a
6580: specific user. Roles can be active, previous or future.
6581:
6582: Inputs:
6583: user's domain, user's username, course's domain,
1.375 raeburn 6584: course's number, optional section ID.
1.274 raeburn 6585:
6586: Outputs:
6587: role status: active, previous or future.
6588:
6589: =cut
6590:
6591: sub check_user_status {
1.412 raeburn 6592: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6593: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6594: my @uroles = keys %userinfo;
6595: my $srchstr;
6596: my $active_chk = 'none';
1.412 raeburn 6597: my $now = time;
1.274 raeburn 6598: if (@uroles > 0) {
1.412 raeburn 6599: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6600: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6601: } else {
1.412 raeburn 6602: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6603: }
6604: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6605: my $role_end = 0;
6606: my $role_start = 0;
6607: $active_chk = 'active';
1.412 raeburn 6608: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6609: $role_end = $1;
6610: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6611: $role_start = $1;
1.274 raeburn 6612: }
6613: }
6614: if ($role_start > 0) {
1.412 raeburn 6615: if ($now < $role_start) {
1.274 raeburn 6616: $active_chk = 'future';
6617: }
6618: }
6619: if ($role_end > 0) {
1.412 raeburn 6620: if ($now > $role_end) {
1.274 raeburn 6621: $active_chk = 'previous';
6622: }
6623: }
6624: }
6625: }
6626: return $active_chk;
6627: }
6628:
6629: ###############################################
6630:
6631: =pod
6632:
1.405 albertel 6633: =item * &get_sections()
1.233 raeburn 6634:
6635: Determines all the sections for a course including
6636: sections with students and sections containing other roles.
1.419 raeburn 6637: Incoming parameters:
6638:
6639: 1. domain
6640: 2. course number
6641: 3. reference to array containing roles for which sections should
6642: be gathered (optional).
6643: 4. reference to array containing status types for which sections
6644: should be gathered (optional).
6645:
6646: If the third argument is undefined, sections are gathered for any role.
6647: If the fourth argument is undefined, sections are gathered for any status.
6648: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6649:
1.374 raeburn 6650: Returns section hash (keys are section IDs, values are
6651: number of users in each section), subject to the
1.419 raeburn 6652: optional roles filter, optional status filter
1.233 raeburn 6653:
6654: =cut
6655:
6656: ###############################################
6657: sub get_sections {
1.419 raeburn 6658: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6659: if (!defined($cdom) || !defined($cnum)) {
6660: my $cid = $env{'request.course.id'};
6661:
6662: return if (!defined($cid));
6663:
6664: $cdom = $env{'course.'.$cid.'.domain'};
6665: $cnum = $env{'course.'.$cid.'.num'};
6666: }
6667:
6668: my %sectioncount;
1.419 raeburn 6669: my $now = time;
1.240 albertel 6670:
1.366 albertel 6671: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6672: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6673: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6674: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6675: my $start_index = &Apache::loncoursedata::CL_START();
6676: my $end_index = &Apache::loncoursedata::CL_END();
6677: my $status;
1.366 albertel 6678: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6679: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6680: $data->[$status_index],
6681: $data->[$start_index],
6682: $data->[$end_index]);
6683: if ($stu_status eq 'Active') {
6684: $status = 'active';
6685: } elsif ($end < $now) {
6686: $status = 'previous';
6687: } elsif ($start > $now) {
6688: $status = 'future';
6689: }
6690: if ($section ne '-1' && $section !~ /^\s*$/) {
6691: if ((!defined($possible_status)) || (($status ne '') &&
6692: (grep/^\Q$status\E$/,@{$possible_status}))) {
6693: $sectioncount{$section}++;
6694: }
1.240 albertel 6695: }
6696: }
6697: }
6698: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6699: foreach my $user (sort(keys(%courseroles))) {
6700: if ($user !~ /^(\w{2})/) { next; }
6701: my ($role) = ($user =~ /^(\w{2})/);
6702: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6703: my ($section,$status);
1.240 albertel 6704: if ($role eq 'cr' &&
6705: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6706: $section=$1;
6707: }
6708: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6709: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6710: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6711: if ($end == -1 && $start == -1) {
6712: next; #deleted role
6713: }
6714: if (!defined($possible_status)) {
6715: $sectioncount{$section}++;
6716: } else {
6717: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6718: $status = 'active';
6719: } elsif ($end < $now) {
6720: $status = 'future';
6721: } elsif ($start > $now) {
6722: $status = 'previous';
6723: }
6724: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6725: $sectioncount{$section}++;
6726: }
6727: }
1.233 raeburn 6728: }
1.366 albertel 6729: return %sectioncount;
1.233 raeburn 6730: }
6731:
1.274 raeburn 6732: ###############################################
1.294 raeburn 6733:
6734: =pod
1.405 albertel 6735:
6736: =item * &get_course_users()
6737:
1.275 raeburn 6738: Retrieves usernames:domains for users in the specified course
6739: with specific role(s), and access status.
6740:
6741: Incoming parameters:
1.277 albertel 6742: 1. course domain
6743: 2. course number
6744: 3. access status: users must have - either active,
1.275 raeburn 6745: previous, future, or all.
1.277 albertel 6746: 4. reference to array of permissible roles
1.288 raeburn 6747: 5. reference to array of section restrictions (optional)
6748: 6. reference to results object (hash of hashes).
6749: 7. reference to optional userdata hash
1.609 raeburn 6750: 8. reference to optional statushash
1.630 raeburn 6751: 9. flag if privileged users (except those set to unhide in
6752: course settings) should be excluded
1.609 raeburn 6753: Keys of top level results hash are roles.
1.275 raeburn 6754: Keys of inner hashes are username:domain, with
6755: values set to access type.
1.288 raeburn 6756: Optional userdata hash returns an array with arguments in the
6757: same order as loncoursedata::get_classlist() for student data.
6758:
1.609 raeburn 6759: Optional statushash returns
6760:
1.288 raeburn 6761: Entries for end, start, section and status are blank because
6762: of the possibility of multiple values for non-student roles.
6763:
1.275 raeburn 6764: =cut
1.405 albertel 6765:
1.275 raeburn 6766: ###############################################
1.405 albertel 6767:
1.275 raeburn 6768: sub get_course_users {
1.630 raeburn 6769: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6770: my %idx = ();
1.419 raeburn 6771: my %seclists;
1.288 raeburn 6772:
6773: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6774: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6775: $idx{end} = &Apache::loncoursedata::CL_END();
6776: $idx{start} = &Apache::loncoursedata::CL_START();
6777: $idx{id} = &Apache::loncoursedata::CL_ID();
6778: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6779: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6780: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6781:
1.290 albertel 6782: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6783: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6784: my $now = time;
1.277 albertel 6785: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6786: my $match = 0;
1.412 raeburn 6787: my $secmatch = 0;
1.419 raeburn 6788: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6789: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6790: if ($section eq '') {
6791: $section = 'none';
6792: }
1.291 albertel 6793: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6794: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6795: $secmatch = 1;
6796: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6797: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6798: $secmatch = 1;
6799: }
6800: } else {
1.419 raeburn 6801: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6802: $secmatch = 1;
6803: }
1.290 albertel 6804: }
1.412 raeburn 6805: if (!$secmatch) {
6806: next;
6807: }
1.419 raeburn 6808: }
1.275 raeburn 6809: if (defined($$types{'active'})) {
1.288 raeburn 6810: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6811: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6812: $match = 1;
1.275 raeburn 6813: }
6814: }
6815: if (defined($$types{'previous'})) {
1.609 raeburn 6816: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6817: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6818: $match = 1;
1.275 raeburn 6819: }
6820: }
6821: if (defined($$types{'future'})) {
1.609 raeburn 6822: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6823: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6824: $match = 1;
1.275 raeburn 6825: }
6826: }
1.609 raeburn 6827: if ($match) {
6828: push(@{$seclists{$student}},$section);
6829: if (ref($userdata) eq 'HASH') {
6830: $$userdata{$student} = $$classlist{$student};
6831: }
6832: if (ref($statushash) eq 'HASH') {
6833: $statushash->{$student}{'st'}{$section} = $status;
6834: }
1.288 raeburn 6835: }
1.275 raeburn 6836: }
6837: }
1.412 raeburn 6838: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6839: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6840: my $now = time;
1.609 raeburn 6841: my %displaystatus = ( previous => 'Expired',
6842: active => 'Active',
6843: future => 'Future',
6844: );
1.630 raeburn 6845: my %nothide;
6846: if ($hidepriv) {
6847: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6848: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6849: if ($user !~ /:/) {
6850: $nothide{join(':',split(/[\@]/,$user))}=1;
6851: } else {
6852: $nothide{$user} = 1;
6853: }
6854: }
6855: }
1.439 raeburn 6856: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6857: my $match = 0;
1.412 raeburn 6858: my $secmatch = 0;
1.439 raeburn 6859: my $status;
1.412 raeburn 6860: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6861: $user =~ s/:$//;
1.439 raeburn 6862: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6863: if ($end == -1 || $start == -1) {
6864: next;
6865: }
6866: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6867: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6868: my ($uname,$udom) = split(/:/,$user);
6869: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6870: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6871: $secmatch = 1;
6872: } elsif ($usec eq '') {
1.420 albertel 6873: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6874: $secmatch = 1;
6875: }
6876: } else {
6877: if (grep(/^\Q$usec\E$/,@{$sections})) {
6878: $secmatch = 1;
6879: }
6880: }
6881: if (!$secmatch) {
6882: next;
6883: }
1.288 raeburn 6884: }
1.419 raeburn 6885: if ($usec eq '') {
6886: $usec = 'none';
6887: }
1.275 raeburn 6888: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6889: if ($hidepriv) {
6890: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6891: (!$nothide{$uname.':'.$udom})) {
6892: next;
6893: }
6894: }
1.503 raeburn 6895: if ($end > 0 && $end < $now) {
1.439 raeburn 6896: $status = 'previous';
6897: } elsif ($start > $now) {
6898: $status = 'future';
6899: } else {
6900: $status = 'active';
6901: }
1.277 albertel 6902: foreach my $type (keys(%{$types})) {
1.275 raeburn 6903: if ($status eq $type) {
1.420 albertel 6904: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6905: push(@{$$users{$role}{$user}},$type);
6906: }
1.288 raeburn 6907: $match = 1;
6908: }
6909: }
1.419 raeburn 6910: if (($match) && (ref($userdata) eq 'HASH')) {
6911: if (!exists($$userdata{$uname.':'.$udom})) {
6912: &get_user_info($udom,$uname,\%idx,$userdata);
6913: }
1.420 albertel 6914: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6915: push(@{$seclists{$uname.':'.$udom}},$usec);
6916: }
1.609 raeburn 6917: if (ref($statushash) eq 'HASH') {
6918: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6919: }
1.275 raeburn 6920: }
6921: }
6922: }
6923: }
1.290 albertel 6924: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6925: if ((defined($cdom)) && (defined($cnum))) {
6926: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6927: if ( defined($csettings{'internal.courseowner'}) ) {
6928: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6929: next if ($owner eq '');
6930: my ($ownername,$ownerdom);
6931: if ($owner =~ /^([^:]+):([^:]+)$/) {
6932: $ownername = $1;
6933: $ownerdom = $2;
6934: } else {
6935: $ownername = $owner;
6936: $ownerdom = $cdom;
6937: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6938: }
6939: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6940: if (defined($userdata) &&
1.609 raeburn 6941: !exists($$userdata{$owner})) {
6942: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6943: if (!grep(/^none$/,@{$seclists{$owner}})) {
6944: push(@{$seclists{$owner}},'none');
6945: }
6946: if (ref($statushash) eq 'HASH') {
6947: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6948: }
1.290 albertel 6949: }
1.279 raeburn 6950: }
6951: }
6952: }
1.419 raeburn 6953: foreach my $user (keys(%seclists)) {
6954: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6955: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6956: }
1.275 raeburn 6957: }
6958: return;
6959: }
6960:
1.288 raeburn 6961: sub get_user_info {
6962: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6963: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6964: &plainname($uname,$udom,'lastname');
1.291 albertel 6965: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6966: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6967: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6968: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6969: return;
6970: }
1.275 raeburn 6971:
1.472 raeburn 6972: ###############################################
6973:
6974: =pod
6975:
6976: =item * &get_user_quota()
6977:
6978: Retrieves quota assigned for storage of portfolio files for a user
6979:
6980: Incoming parameters:
6981: 1. user's username
6982: 2. user's domain
6983:
6984: Returns:
1.536 raeburn 6985: 1. Disk quota (in Mb) assigned to student.
6986: 2. (Optional) Type of setting: custom or default
6987: (individually assigned or default for user's
6988: institutional status).
6989: 3. (Optional) - User's institutional status (e.g., faculty, staff
6990: or student - types as defined in localenroll::inst_usertypes
6991: for user's domain, which determines default quota for user.
6992: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6993:
6994: If a value has been stored in the user's environment,
1.536 raeburn 6995: it will return that, otherwise it returns the maximal default
6996: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6997:
6998: =cut
6999:
7000: ###############################################
7001:
7002:
7003: sub get_user_quota {
7004: my ($uname,$udom) = @_;
1.536 raeburn 7005: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7006: if (!defined($udom)) {
7007: $udom = $env{'user.domain'};
7008: }
7009: if (!defined($uname)) {
7010: $uname = $env{'user.name'};
7011: }
7012: if (($udom eq '' || $uname eq '') ||
7013: ($udom eq 'public') && ($uname eq 'public')) {
7014: $quota = 0;
1.536 raeburn 7015: $quotatype = 'default';
7016: $defquota = 0;
1.472 raeburn 7017: } else {
1.536 raeburn 7018: my $inststatus;
1.472 raeburn 7019: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7020: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7021: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7022: } else {
1.536 raeburn 7023: my %userenv =
7024: &Apache::lonnet::get('environment',['portfolioquota',
7025: 'inststatus'],$udom,$uname);
1.472 raeburn 7026: my ($tmp) = keys(%userenv);
7027: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7028: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7029: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7030: } else {
7031: undef(%userenv);
7032: }
7033: }
1.536 raeburn 7034: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7035: if ($quota eq '') {
1.536 raeburn 7036: $quota = $defquota;
7037: $quotatype = 'default';
7038: } else {
7039: $quotatype = 'custom';
1.472 raeburn 7040: }
7041: }
1.536 raeburn 7042: if (wantarray) {
7043: return ($quota,$quotatype,$settingstatus,$defquota);
7044: } else {
7045: return $quota;
7046: }
1.472 raeburn 7047: }
7048:
7049: ###############################################
7050:
7051: =pod
7052:
7053: =item * &default_quota()
7054:
1.536 raeburn 7055: Retrieves default quota assigned for storage of user portfolio files,
7056: given an (optional) user's institutional status.
1.472 raeburn 7057:
7058: Incoming parameters:
7059: 1. domain
1.536 raeburn 7060: 2. (Optional) institutional status(es). This is a : separated list of
7061: status types (e.g., faculty, staff, student etc.)
7062: which apply to the user for whom the default is being retrieved.
7063: If the institutional status string in undefined, the domain
7064: default quota will be returned.
1.472 raeburn 7065:
7066: Returns:
7067: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7068: 2. (Optional) institutional type which determined the value of the
7069: default quota.
1.472 raeburn 7070:
7071: If a value has been stored in the domain's configuration db,
7072: it will return that, otherwise it returns 20 (for backwards
7073: compatibility with domains which have not set up a configuration
7074: db file; the original statically defined portfolio quota was 20 Mb).
7075:
1.536 raeburn 7076: If the user's status includes multiple types (e.g., staff and student),
7077: the largest default quota which applies to the user determines the
7078: default quota returned.
7079:
1.780 raeburn 7080: =back
7081:
1.472 raeburn 7082: =cut
7083:
7084: ###############################################
7085:
7086:
7087: sub default_quota {
1.536 raeburn 7088: my ($udom,$inststatus) = @_;
7089: my ($defquota,$settingstatus);
7090: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7091: ['quotas'],$udom);
7092: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7093: if ($inststatus ne '') {
1.765 raeburn 7094: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7095: foreach my $item (@statuses) {
1.711 raeburn 7096: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7097: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7098: if ($defquota eq '') {
7099: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7100: $settingstatus = $item;
7101: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7102: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7103: $settingstatus = $item;
7104: }
7105: }
7106: } else {
7107: if ($quotahash{'quotas'}{$item} ne '') {
7108: if ($defquota eq '') {
7109: $defquota = $quotahash{'quotas'}{$item};
7110: $settingstatus = $item;
7111: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7112: $defquota = $quotahash{'quotas'}{$item};
7113: $settingstatus = $item;
7114: }
1.536 raeburn 7115: }
7116: }
7117: }
7118: }
7119: if ($defquota eq '') {
1.711 raeburn 7120: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7121: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7122: } else {
7123: $defquota = $quotahash{'quotas'}{'default'};
7124: }
1.536 raeburn 7125: $settingstatus = 'default';
7126: }
7127: } else {
7128: $settingstatus = 'default';
7129: $defquota = 20;
7130: }
7131: if (wantarray) {
7132: return ($defquota,$settingstatus);
1.472 raeburn 7133: } else {
1.536 raeburn 7134: return $defquota;
1.472 raeburn 7135: }
7136: }
7137:
1.384 raeburn 7138: sub get_secgrprole_info {
7139: my ($cdom,$cnum,$needroles,$type) = @_;
7140: my %sections_count = &get_sections($cdom,$cnum);
7141: my @sections = (sort {$a <=> $b} keys(%sections_count));
7142: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7143: my @groups = sort(keys(%curr_groups));
7144: my $allroles = [];
7145: my $rolehash;
7146: my $accesshash = {
7147: active => 'Currently has access',
7148: future => 'Will have future access',
7149: previous => 'Previously had access',
7150: };
7151: if ($needroles) {
7152: $rolehash = {'all' => 'all'};
1.385 albertel 7153: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7154: if (&Apache::lonnet::error(%user_roles)) {
7155: undef(%user_roles);
7156: }
7157: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7158: my ($role)=split(/\:/,$item,2);
7159: if ($role eq 'cr') { next; }
7160: if ($role =~ /^cr/) {
7161: $$rolehash{$role} = (split('/',$role))[3];
7162: } else {
7163: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7164: }
7165: }
7166: foreach my $key (sort(keys(%{$rolehash}))) {
7167: push(@{$allroles},$key);
7168: }
7169: push (@{$allroles},'st');
7170: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7171: }
7172: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7173: }
7174:
1.555 raeburn 7175: sub user_picker {
1.627 raeburn 7176: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7177: my $currdom = $dom;
7178: my %curr_selected = (
7179: srchin => 'dom',
1.580 raeburn 7180: srchby => 'lastname',
1.555 raeburn 7181: );
7182: my $srchterm;
1.625 raeburn 7183: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7184: if ($srch->{'srchby'} ne '') {
7185: $curr_selected{'srchby'} = $srch->{'srchby'};
7186: }
7187: if ($srch->{'srchin'} ne '') {
7188: $curr_selected{'srchin'} = $srch->{'srchin'};
7189: }
7190: if ($srch->{'srchtype'} ne '') {
7191: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7192: }
7193: if ($srch->{'srchdomain'} ne '') {
7194: $currdom = $srch->{'srchdomain'};
7195: }
7196: $srchterm = $srch->{'srchterm'};
7197: }
7198: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7199: 'usr' => 'Search criteria',
1.563 raeburn 7200: 'doma' => 'Domain/institution to search',
1.558 albertel 7201: 'uname' => 'username',
7202: 'lastname' => 'last name',
1.555 raeburn 7203: 'lastfirst' => 'last name, first name',
1.558 albertel 7204: 'crs' => 'in this course',
1.576 raeburn 7205: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7206: 'alc' => 'all LON-CAPA',
1.573 raeburn 7207: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7208: 'exact' => 'is',
7209: 'contains' => 'contains',
1.569 raeburn 7210: 'begins' => 'begins with',
1.571 raeburn 7211: 'youm' => "You must include some text to search for.",
7212: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7213: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7214: 'yomc' => "You must choose a domain when using an institutional directory search.",
7215: 'ymcd' => "You must choose a domain when using a domain search.",
7216: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7217: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7218: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7219: );
1.563 raeburn 7220: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7221: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7222:
7223: my @srchins = ('crs','dom','alc','instd');
7224:
7225: foreach my $option (@srchins) {
7226: # FIXME 'alc' option unavailable until
7227: # loncreateuser::print_user_query_page()
7228: # has been completed.
7229: next if ($option eq 'alc');
7230: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7231: if ($curr_selected{'srchin'} eq $option) {
7232: $srchinsel .= '
7233: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7234: } else {
7235: $srchinsel .= '
7236: <option value="'.$option.'">'.$lt{$option}.'</option>';
7237: }
1.555 raeburn 7238: }
1.563 raeburn 7239: $srchinsel .= "\n </select>\n";
1.555 raeburn 7240:
7241: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7242: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7243: if ($curr_selected{'srchby'} eq $option) {
7244: $srchbysel .= '
7245: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7246: } else {
7247: $srchbysel .= '
7248: <option value="'.$option.'">'.$lt{$option}.'</option>';
7249: }
7250: }
7251: $srchbysel .= "\n </select>\n";
7252:
7253: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7254: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7255: if ($curr_selected{'srchtype'} eq $option) {
7256: $srchtypesel .= '
7257: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7258: } else {
7259: $srchtypesel .= '
7260: <option value="'.$option.'">'.$lt{$option}.'</option>';
7261: }
7262: }
7263: $srchtypesel .= "\n </select>\n";
7264:
1.558 albertel 7265: my ($newuserscript,$new_user_create);
1.556 raeburn 7266:
7267: if ($forcenewuser) {
1.576 raeburn 7268: if (ref($srch) eq 'HASH') {
7269: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7270: if ($cancreate) {
7271: $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>';
7272: } else {
7273: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7274: my %usertypetext = (
7275: official => 'institutional',
7276: unofficial => 'non-institutional',
7277: );
7278: $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 />';
7279: }
1.576 raeburn 7280: }
7281: }
7282:
1.556 raeburn 7283: $newuserscript = <<"ENDSCRIPT";
7284:
1.570 raeburn 7285: function setSearch(createnew,callingForm) {
1.556 raeburn 7286: if (createnew == 1) {
1.570 raeburn 7287: for (var i=0; i<callingForm.srchby.length; i++) {
7288: if (callingForm.srchby.options[i].value == 'uname') {
7289: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7290: }
7291: }
1.570 raeburn 7292: for (var i=0; i<callingForm.srchin.length; i++) {
7293: if ( callingForm.srchin.options[i].value == 'dom') {
7294: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7295: }
7296: }
1.570 raeburn 7297: for (var i=0; i<callingForm.srchtype.length; i++) {
7298: if (callingForm.srchtype.options[i].value == 'exact') {
7299: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7300: }
7301: }
1.570 raeburn 7302: for (var i=0; i<callingForm.srchdomain.length; i++) {
7303: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7304: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7305: }
7306: }
7307: }
7308: }
7309: ENDSCRIPT
1.558 albertel 7310:
1.556 raeburn 7311: }
7312:
1.555 raeburn 7313: my $output = <<"END_BLOCK";
1.556 raeburn 7314: <script type="text/javascript">
1.570 raeburn 7315: function validateEntry(callingForm) {
1.558 albertel 7316:
1.556 raeburn 7317: var checkok = 1;
1.558 albertel 7318: var srchin;
1.570 raeburn 7319: for (var i=0; i<callingForm.srchin.length; i++) {
7320: if ( callingForm.srchin[i].checked ) {
7321: srchin = callingForm.srchin[i].value;
1.558 albertel 7322: }
7323: }
7324:
1.570 raeburn 7325: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7326: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7327: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7328: var srchterm = callingForm.srchterm.value;
7329: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7330: var msg = "";
7331:
7332: if (srchterm == "") {
7333: checkok = 0;
1.571 raeburn 7334: msg += "$lt{'youm'}\\n";
1.556 raeburn 7335: }
7336:
1.569 raeburn 7337: if (srchtype== 'begins') {
7338: if (srchterm.length < 2) {
7339: checkok = 0;
1.571 raeburn 7340: msg += "$lt{'thte'}\\n";
1.569 raeburn 7341: }
7342: }
7343:
1.556 raeburn 7344: if (srchtype== 'contains') {
7345: if (srchterm.length < 3) {
7346: checkok = 0;
1.571 raeburn 7347: msg += "$lt{'thet'}\\n";
1.556 raeburn 7348: }
7349: }
7350: if (srchin == 'instd') {
7351: if (srchdomain == '') {
7352: checkok = 0;
1.571 raeburn 7353: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7354: }
7355: }
7356: if (srchin == 'dom') {
7357: if (srchdomain == '') {
7358: checkok = 0;
1.571 raeburn 7359: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7360: }
7361: }
7362: if (srchby == 'lastfirst') {
7363: if (srchterm.indexOf(",") == -1) {
7364: checkok = 0;
1.571 raeburn 7365: msg += "$lt{'whus'}\\n";
1.556 raeburn 7366: }
7367: if (srchterm.indexOf(",") == srchterm.length -1) {
7368: checkok = 0;
1.571 raeburn 7369: msg += "$lt{'whse'}\\n";
1.556 raeburn 7370: }
7371: }
7372: if (checkok == 0) {
1.571 raeburn 7373: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7374: return;
7375: }
7376: if (checkok == 1) {
1.570 raeburn 7377: callingForm.submit();
1.556 raeburn 7378: }
7379: }
7380:
7381: $newuserscript
7382:
7383: </script>
1.558 albertel 7384:
7385: $new_user_create
7386:
1.555 raeburn 7387: <table>
1.558 albertel 7388: <tr>
1.573 raeburn 7389: <td>$lt{'doma'}:</td>
7390: <td>$domform</td>
7391: </td>
7392: </tr>
7393: <tr>
7394: <td>$lt{'usr'}:</td>
1.563 raeburn 7395: <td>$srchbysel
7396: $srchtypesel
7397: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7398: $srchinsel
1.563 raeburn 7399: </td>
7400: </tr>
1.555 raeburn 7401: </table>
7402: <br />
7403: END_BLOCK
1.558 albertel 7404:
1.555 raeburn 7405: return $output;
7406: }
7407:
1.612 raeburn 7408: sub user_rule_check {
1.615 raeburn 7409: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7410: my $response;
7411: if (ref($usershash) eq 'HASH') {
7412: foreach my $user (keys(%{$usershash})) {
7413: my ($uname,$udom) = split(/:/,$user);
7414: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7415: my ($id,$newuser);
1.612 raeburn 7416: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7417: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7418: $id = $usershash->{$user}->{'id'};
7419: }
7420: my $inst_response;
7421: if (ref($checks) eq 'HASH') {
7422: if (defined($checks->{'username'})) {
1.615 raeburn 7423: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7424: &Apache::lonnet::get_instuser($udom,$uname);
7425: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7426: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7427: &Apache::lonnet::get_instuser($udom,undef,$id);
7428: }
1.615 raeburn 7429: } else {
7430: ($inst_response,%{$inst_results->{$user}}) =
7431: &Apache::lonnet::get_instuser($udom,$uname);
7432: return;
1.612 raeburn 7433: }
1.615 raeburn 7434: if (!$got_rules->{$udom}) {
1.612 raeburn 7435: my %domconfig = &Apache::lonnet::get_dom('configuration',
7436: ['usercreation'],$udom);
7437: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7438: foreach my $item ('username','id') {
1.612 raeburn 7439: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7440: $$curr_rules{$udom}{$item} =
7441: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7442: }
7443: }
7444: }
1.615 raeburn 7445: $got_rules->{$udom} = 1;
1.585 raeburn 7446: }
1.612 raeburn 7447: foreach my $item (keys(%{$checks})) {
7448: if (ref($$curr_rules{$udom}) eq 'HASH') {
7449: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7450: if (@{$$curr_rules{$udom}{$item}} > 0) {
7451: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7452: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7453: if ($rule_check{$rule}) {
7454: $$rulematch{$user}{$item} = $rule;
7455: if ($inst_response eq 'ok') {
1.615 raeburn 7456: if (ref($inst_results) eq 'HASH') {
7457: if (ref($inst_results->{$user}) eq 'HASH') {
7458: if (keys(%{$inst_results->{$user}}) == 0) {
7459: $$alerts{$item}{$udom}{$uname} = 1;
7460: }
1.612 raeburn 7461: }
7462: }
1.615 raeburn 7463: }
7464: last;
1.585 raeburn 7465: }
7466: }
7467: }
7468: }
7469: }
7470: }
7471: }
7472: }
1.612 raeburn 7473: return;
7474: }
7475:
7476: sub user_rule_formats {
7477: my ($domain,$domdesc,$curr_rules,$check) = @_;
7478: my %text = (
7479: 'username' => 'Usernames',
7480: 'id' => 'IDs',
7481: );
7482: my $output;
7483: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7484: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7485: if (@{$ruleorder} > 0) {
7486: $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>';
7487: foreach my $rule (@{$ruleorder}) {
7488: if (ref($curr_rules) eq 'ARRAY') {
7489: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7490: if (ref($rules->{$rule}) eq 'HASH') {
7491: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7492: $rules->{$rule}{'desc'}.'</li>';
7493: }
7494: }
7495: }
7496: }
7497: $output .= '</ul>';
7498: }
7499: }
7500: return $output;
7501: }
7502:
7503: sub instrule_disallow_msg {
1.615 raeburn 7504: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7505: my $response;
7506: my %text = (
7507: item => 'username',
7508: items => 'usernames',
7509: match => 'matches',
7510: do => 'does',
7511: action => 'a username',
7512: one => 'one',
7513: );
7514: if ($count > 1) {
7515: $text{'item'} = 'usernames';
7516: $text{'match'} ='match';
7517: $text{'do'} = 'do';
7518: $text{'action'} = 'usernames',
7519: $text{'one'} = 'ones';
7520: }
7521: if ($checkitem eq 'id') {
7522: $text{'items'} = 'IDs';
7523: $text{'item'} = 'ID';
7524: $text{'action'} = 'an ID';
1.615 raeburn 7525: if ($count > 1) {
7526: $text{'item'} = 'IDs';
7527: $text{'action'} = 'IDs';
7528: }
1.612 raeburn 7529: }
1.674 bisitz 7530: $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 7531: if ($mode eq 'upload') {
7532: if ($checkitem eq 'username') {
7533: $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'}.");
7534: } elsif ($checkitem eq 'id') {
1.674 bisitz 7535: $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 7536: }
1.669 raeburn 7537: } elsif ($mode eq 'selfcreate') {
7538: if ($checkitem eq 'id') {
7539: $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.");
7540: }
1.615 raeburn 7541: } else {
7542: if ($checkitem eq 'username') {
7543: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7544: } elsif ($checkitem eq 'id') {
7545: $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.");
7546: }
1.612 raeburn 7547: }
7548: return $response;
1.585 raeburn 7549: }
7550:
1.624 raeburn 7551: sub personal_data_fieldtitles {
7552: my %fieldtitles = &Apache::lonlocal::texthash (
7553: id => 'Student/Employee ID',
7554: permanentemail => 'E-mail address',
7555: lastname => 'Last Name',
7556: firstname => 'First Name',
7557: middlename => 'Middle Name',
7558: generation => 'Generation',
7559: gen => 'Generation',
1.765 raeburn 7560: inststatus => 'Affiliation',
1.624 raeburn 7561: );
7562: return %fieldtitles;
7563: }
7564:
1.642 raeburn 7565: sub sorted_inst_types {
7566: my ($dom) = @_;
7567: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7568: my $othertitle = &mt('All users');
7569: if ($env{'request.course.id'}) {
1.668 raeburn 7570: $othertitle = &mt('Any users');
1.642 raeburn 7571: }
7572: my @types;
7573: if (ref($order) eq 'ARRAY') {
7574: @types = @{$order};
7575: }
7576: if (@types == 0) {
7577: if (ref($usertypes) eq 'HASH') {
7578: @types = sort(keys(%{$usertypes}));
7579: }
7580: }
7581: if (keys(%{$usertypes}) > 0) {
7582: $othertitle = &mt('Other users');
7583: }
7584: return ($othertitle,$usertypes,\@types);
7585: }
7586:
1.645 raeburn 7587: sub get_institutional_codes {
7588: my ($settings,$allcourses,$LC_code) = @_;
7589: # Get complete list of course sections to update
7590: my @currsections = ();
7591: my @currxlists = ();
7592: my $coursecode = $$settings{'internal.coursecode'};
7593:
7594: if ($$settings{'internal.sectionnums'} ne '') {
7595: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7596: }
7597:
7598: if ($$settings{'internal.crosslistings'} ne '') {
7599: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7600: }
7601:
7602: if (@currxlists > 0) {
7603: foreach (@currxlists) {
7604: if (m/^([^:]+):(\w*)$/) {
7605: unless (grep/^$1$/,@{$allcourses}) {
7606: push @{$allcourses},$1;
7607: $$LC_code{$1} = $2;
7608: }
7609: }
7610: }
7611: }
7612:
7613: if (@currsections > 0) {
7614: foreach (@currsections) {
7615: if (m/^(\w+):(\w*)$/) {
7616: my $sec = $coursecode.$1;
7617: my $lc_sec = $2;
7618: unless (grep/^$sec$/,@{$allcourses}) {
7619: push @{$allcourses},$sec;
7620: $$LC_code{$sec} = $lc_sec;
7621: }
7622: }
7623: }
7624: }
7625: return;
7626: }
7627:
1.112 bowersj2 7628: =pod
7629:
1.780 raeburn 7630: =head1 Slot Helpers
7631:
7632: =over 4
7633:
7634: =item * sorted_slots()
7635:
7636: Sorts an array of slot names in order of slot start time (earliest first).
7637:
7638: Inputs:
7639:
7640: =over 4
7641:
7642: slotsarr - Reference to array of unsorted slot names.
7643:
7644: slots - Reference to hash of hash, where outer hash keys are slot names.
7645:
1.549 albertel 7646: =back
7647:
1.780 raeburn 7648: Returns:
7649:
7650: =over 4
7651:
7652: sorted - An array of slot names sorted by the start time of the slot.
7653:
7654: =back
7655:
7656: =back
7657:
7658: =cut
7659:
7660:
7661: sub sorted_slots {
7662: my ($slotsarr,$slots) = @_;
7663: my @sorted;
7664: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7665: @sorted =
7666: sort {
7667: if (ref($slots->{$a}) && ref($slots->{$b})) {
7668: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7669: }
7670: if (ref($slots->{$a})) { return -1;}
7671: if (ref($slots->{$b})) { return 1;}
7672: return 0;
7673: } @{$slotsarr};
7674: }
7675: return @sorted;
7676: }
7677:
7678:
7679: =pod
7680:
1.549 albertel 7681: =head1 HTTP Helpers
7682:
7683: =over 4
7684:
1.648 raeburn 7685: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7686:
1.258 albertel 7687: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7688: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7689: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7690:
7691: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7692: $possible_names is an ref to an array of form element names. As an example:
7693: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7694: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7695:
7696: =cut
1.1 albertel 7697:
1.6 albertel 7698: sub get_unprocessed_cgi {
1.25 albertel 7699: my ($query,$possible_names)= @_;
1.26 matthew 7700: # $Apache::lonxml::debug=1;
1.356 albertel 7701: foreach my $pair (split(/&/,$query)) {
7702: my ($name, $value) = split(/=/,$pair);
1.369 www 7703: $name = &unescape($name);
1.25 albertel 7704: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7705: $value =~ tr/+/ /;
7706: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7707: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7708: }
1.16 harris41 7709: }
1.6 albertel 7710: }
7711:
1.112 bowersj2 7712: =pod
7713:
1.648 raeburn 7714: =item * &cacheheader()
1.112 bowersj2 7715:
7716: returns cache-controlling header code
7717:
7718: =cut
7719:
1.7 albertel 7720: sub cacheheader {
1.258 albertel 7721: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7722: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7723: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7724: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7725: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7726: return $output;
1.7 albertel 7727: }
7728:
1.112 bowersj2 7729: =pod
7730:
1.648 raeburn 7731: =item * &no_cache($r)
1.112 bowersj2 7732:
7733: specifies header code to not have cache
7734:
7735: =cut
7736:
1.9 albertel 7737: sub no_cache {
1.216 albertel 7738: my ($r) = @_;
7739: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7740: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7741: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7742: $r->no_cache(1);
7743: $r->header_out("Expires" => $date);
7744: $r->header_out("Pragma" => "no-cache");
1.123 www 7745: }
7746:
7747: sub content_type {
1.181 albertel 7748: my ($r,$type,$charset) = @_;
1.299 foxr 7749: if ($r) {
7750: # Note that printout.pl calls this with undef for $r.
7751: &no_cache($r);
7752: }
1.258 albertel 7753: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7754: unless ($charset) {
7755: $charset=&Apache::lonlocal::current_encoding;
7756: }
7757: if ($charset) { $type.='; charset='.$charset; }
7758: if ($r) {
7759: $r->content_type($type);
7760: } else {
7761: print("Content-type: $type\n\n");
7762: }
1.9 albertel 7763: }
1.25 albertel 7764:
1.112 bowersj2 7765: =pod
7766:
1.648 raeburn 7767: =item * &add_to_env($name,$value)
1.112 bowersj2 7768:
1.258 albertel 7769: adds $name to the %env hash with value
1.112 bowersj2 7770: $value, if $name already exists, the entry is converted to an array
7771: reference and $value is added to the array.
7772:
7773: =cut
7774:
1.25 albertel 7775: sub add_to_env {
7776: my ($name,$value)=@_;
1.258 albertel 7777: if (defined($env{$name})) {
7778: if (ref($env{$name})) {
1.25 albertel 7779: #already have multiple values
1.258 albertel 7780: push(@{ $env{$name} },$value);
1.25 albertel 7781: } else {
7782: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7783: my $first=$env{$name};
7784: undef($env{$name});
7785: push(@{ $env{$name} },$first,$value);
1.25 albertel 7786: }
7787: } else {
1.258 albertel 7788: $env{$name}=$value;
1.25 albertel 7789: }
1.31 albertel 7790: }
1.149 albertel 7791:
7792: =pod
7793:
1.648 raeburn 7794: =item * &get_env_multiple($name)
1.149 albertel 7795:
1.258 albertel 7796: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7797: values may be defined and end up as an array ref.
7798:
7799: returns an array of values
7800:
7801: =cut
7802:
7803: sub get_env_multiple {
7804: my ($name) = @_;
7805: my @values;
1.258 albertel 7806: if (defined($env{$name})) {
1.149 albertel 7807: # exists is it an array
1.258 albertel 7808: if (ref($env{$name})) {
7809: @values=@{ $env{$name} };
1.149 albertel 7810: } else {
1.258 albertel 7811: $values[0]=$env{$name};
1.149 albertel 7812: }
7813: }
7814: return(@values);
7815: }
7816:
1.660 raeburn 7817: sub ask_for_embedded_content {
7818: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7819: my $upload_output = '
7820: <form name="upload_embedded" action="'.$actionurl.'"
7821: method="post" enctype="multipart/form-data">';
7822: $upload_output .= $state;
1.661 raeburn 7823: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7824:
7825: my $num = 0;
7826: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7827: $upload_output .= &start_data_table_row().
7828: '<td>'.$embed_file.'</td><td>';
7829: if ($args->{'ignore_remote_references'}
7830: && $embed_file =~ m{^\w+://}) {
7831: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7832: } elsif ($args->{'error_on_invalid_names'}
7833: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7834:
7835: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7836:
7837: } else {
7838: $upload_output .='
1.661 raeburn 7839: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7840: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7841: my $attrib = join(':',@{$$allfiles{$embed_file}});
7842: $upload_output .=
7843: "\n\t\t".
7844: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7845: $attrib.'" />';
7846: if (exists($$codebase{$embed_file})) {
7847: $upload_output .=
7848: "\n\t\t".
7849: '<input name="codebase_'.$num.'" type="hidden" value="'.
7850: &escape($$codebase{$embed_file}).'" />';
7851: }
7852: }
7853: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7854: $num++;
7855: }
7856: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7857: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7858: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7859: '.&mt('(only files for which a location has been provided will be uploaded)').'
7860: </form>';
7861: return $upload_output;
7862: }
7863:
1.661 raeburn 7864: sub upload_embedded {
7865: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7866: $current_disk_usage) = @_;
7867: my $output;
7868: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7869: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7870: my $orig_uploaded_filename =
7871: $env{'form.embedded_item_'.$i.'.filename'};
7872:
7873: $env{'form.embedded_orig_'.$i} =
7874: &unescape($env{'form.embedded_orig_'.$i});
7875: my ($path,$fname) =
7876: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7877: # no path, whole string is fname
7878: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7879:
7880: $path = $env{'form.currentpath'}.$path;
7881: $fname = &Apache::lonnet::clean_filename($fname);
7882: # See if there is anything left
7883: next if ($fname eq '');
7884:
7885: # Check if file already exists as a file or directory.
7886: my ($state,$msg);
7887: if ($context eq 'portfolio') {
7888: my $port_path = $dirpath;
7889: if ($group ne '') {
7890: $port_path = "groups/$group/$port_path";
7891: }
7892: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7893: $dir_root,$port_path,$disk_quota,
7894: $current_disk_usage,$uname,$udom);
7895: if ($state eq 'will_exceed_quota'
7896: || $state eq 'file_locked'
7897: || $state eq 'file_exists' ) {
7898: $output .= $msg;
7899: next;
7900: }
7901: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7902: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7903: if ($state eq 'exists') {
7904: $output .= $msg;
7905: next;
7906: }
7907: }
7908: # Check if extension is valid
7909: if (($fname =~ /\.(\w+)$/) &&
7910: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7911: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7912: next;
7913: } elsif (($fname =~ /\.(\w+)$/) &&
7914: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7915: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7916: next;
7917: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7918: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7919: next;
7920: }
7921:
7922: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7923: if ($context eq 'portfolio') {
7924: my $result=
7925: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7926: $dirpath.$path);
7927: if ($result !~ m|^/uploaded/|) {
7928: $output .= '<span class="LC_error">'
7929: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7930: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7931: .'</span><br />';
7932: next;
7933: } else {
7934: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7935: $path.$fname.'</span>').'</p>';
7936: }
7937: } else {
7938: # Save the file
7939: my $target = $env{'form.embedded_item_'.$i};
7940: my $fullpath = $dir_root.$dirpath.'/'.$path;
7941: my $dest = $fullpath.$fname;
7942: my $url = $url_root.$dirpath.'/'.$path.$fname;
7943: my @parts=split(/\//,$fullpath);
7944: my $count;
7945: my $filepath = $dir_root;
7946: for ($count=4;$count<=$#parts;$count++) {
7947: $filepath .= "/$parts[$count]";
7948: if ((-e $filepath)!=1) {
7949: mkdir($filepath,0770);
7950: }
7951: }
7952: my $fh;
7953: if (!open($fh,'>'.$dest)) {
7954: &Apache::lonnet::logthis('Failed to create '.$dest);
7955: $output .= '<span class="LC_error">'.
7956: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7957: '</span><br />';
7958: } else {
7959: if (!print $fh $env{'form.embedded_item_'.$i}) {
7960: &Apache::lonnet::logthis('Failed to write to '.$dest);
7961: $output .= '<span class="LC_error">'.
7962: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7963: '</span><br />';
7964: } else {
7965: if ($context eq 'testbank') {
7966: $output .= &mt('Embedded file uploaded successfully:').
7967: ' <a href="'.$url.'">'.
7968: $orig_uploaded_filename.'</a><br />';
7969: } else {
1.705 tempelho 7970: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 7971: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 7972: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 7973: }
7974: }
7975: close($fh);
7976: }
7977: }
7978: }
7979: return $output;
7980: }
7981:
7982: sub check_for_existing {
7983: my ($path,$fname,$element) = @_;
7984: my ($state,$msg);
7985: if (-d $path.'/'.$fname) {
7986: $state = 'exists';
7987: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7988: } elsif (-e $path.'/'.$fname) {
7989: $state = 'exists';
7990: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7991: }
7992: if ($state eq 'exists') {
7993: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7994: }
7995: return ($state,$msg);
7996: }
7997:
7998: sub check_for_upload {
7999: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8000: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8001: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8002: my $getpropath = 1;
8003: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8004: $getpropath);
8005: my $found_file = 0;
8006: my $locked_file = 0;
8007: foreach my $line (@dir_list) {
8008: my ($file_name)=split(/\&/,$line,2);
8009: if ($file_name eq $fname){
8010: $file_name = $path.$file_name;
8011: if ($group ne '') {
8012: $file_name = $group.$file_name;
8013: }
8014: $found_file = 1;
8015: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8016: $locked_file = 1;
8017: }
8018: }
8019: }
8020: if (($current_disk_usage + $filesize) > $disk_quota){
8021: my $msg = '<span class="LC_error">'.
8022: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8023: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8024: return ('will_exceed_quota',$msg);
8025: } elsif ($found_file) {
8026: if ($locked_file) {
8027: my $msg = '<span class="LC_error">';
8028: $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>');
8029: $msg .= '</span><br />';
8030: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8031: return ('file_locked',$msg);
8032: } else {
8033: my $msg = '<span class="LC_error">';
8034: $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'});
8035: $msg .= '</span>';
8036: $msg .= '<br />';
8037: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8038: return ('file_exists',$msg);
8039: }
8040: }
8041: }
8042:
1.31 albertel 8043:
1.41 ng 8044: =pod
1.45 matthew 8045:
1.464 albertel 8046: =back
1.41 ng 8047:
1.112 bowersj2 8048: =head1 CSV Upload/Handling functions
1.38 albertel 8049:
1.41 ng 8050: =over 4
8051:
1.648 raeburn 8052: =item * &upfile_store($r)
1.41 ng 8053:
8054: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8055: needs $env{'form.upfile'}
1.41 ng 8056: returns $datatoken to be put into hidden field
8057:
8058: =cut
1.31 albertel 8059:
8060: sub upfile_store {
8061: my $r=shift;
1.258 albertel 8062: $env{'form.upfile'}=~s/\r/\n/gs;
8063: $env{'form.upfile'}=~s/\f/\n/gs;
8064: $env{'form.upfile'}=~s/\n+/\n/gs;
8065: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8066:
1.258 albertel 8067: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8068: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8069: {
1.158 raeburn 8070: my $datafile = $r->dir_config('lonDaemons').
8071: '/tmp/'.$datatoken.'.tmp';
8072: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8073: print $fh $env{'form.upfile'};
1.158 raeburn 8074: close($fh);
8075: }
1.31 albertel 8076: }
8077: return $datatoken;
8078: }
8079:
1.56 matthew 8080: =pod
8081:
1.648 raeburn 8082: =item * &load_tmp_file($r)
1.41 ng 8083:
8084: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8085: needs $env{'form.datatoken'},
8086: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8087:
8088: =cut
1.31 albertel 8089:
8090: sub load_tmp_file {
8091: my $r=shift;
8092: my @studentdata=();
8093: {
1.158 raeburn 8094: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8095: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8096: if ( open(my $fh,"<$studentfile") ) {
8097: @studentdata=<$fh>;
8098: close($fh);
8099: }
1.31 albertel 8100: }
1.258 albertel 8101: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8102: }
8103:
1.56 matthew 8104: =pod
8105:
1.648 raeburn 8106: =item * &upfile_record_sep()
1.41 ng 8107:
8108: Separate uploaded file into records
8109: returns array of records,
1.258 albertel 8110: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8111:
8112: =cut
1.31 albertel 8113:
8114: sub upfile_record_sep {
1.258 albertel 8115: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8116: } else {
1.248 albertel 8117: my @records;
1.258 albertel 8118: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8119: if ($line=~/^\s*$/) { next; }
8120: push(@records,$line);
8121: }
8122: return @records;
1.31 albertel 8123: }
8124: }
8125:
1.56 matthew 8126: =pod
8127:
1.648 raeburn 8128: =item * &record_sep($record)
1.41 ng 8129:
1.258 albertel 8130: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8131:
8132: =cut
8133:
1.263 www 8134: sub takeleft {
8135: my $index=shift;
8136: return substr('0000'.$index,-4,4);
8137: }
8138:
1.31 albertel 8139: sub record_sep {
8140: my $record=shift;
8141: my %components=();
1.258 albertel 8142: if ($env{'form.upfiletype'} eq 'xml') {
8143: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8144: my $i=0;
1.356 albertel 8145: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8146: $field=~s/^(\"|\')//;
8147: $field=~s/(\"|\')$//;
1.263 www 8148: $components{&takeleft($i)}=$field;
1.31 albertel 8149: $i++;
8150: }
1.258 albertel 8151: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8152: my $i=0;
1.356 albertel 8153: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8154: $field=~s/^(\"|\')//;
8155: $field=~s/(\"|\')$//;
1.263 www 8156: $components{&takeleft($i)}=$field;
1.31 albertel 8157: $i++;
8158: }
8159: } else {
1.561 www 8160: my $separator=',';
1.480 banghart 8161: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8162: $separator=';';
1.480 banghart 8163: }
1.31 albertel 8164: my $i=0;
1.561 www 8165: # the character we are looking for to indicate the end of a quote or a record
8166: my $looking_for=$separator;
8167: # do not add the characters to the fields
8168: my $ignore=0;
8169: # we just encountered a separator (or the beginning of the record)
8170: my $just_found_separator=1;
8171: # store the field we are working on here
8172: my $field='';
8173: # work our way through all characters in record
8174: foreach my $character ($record=~/(.)/g) {
8175: if ($character eq $looking_for) {
8176: if ($character ne $separator) {
8177: # Found the end of a quote, again looking for separator
8178: $looking_for=$separator;
8179: $ignore=1;
8180: } else {
8181: # Found a separator, store away what we got
8182: $components{&takeleft($i)}=$field;
8183: $i++;
8184: $just_found_separator=1;
8185: $ignore=0;
8186: $field='';
8187: }
8188: next;
8189: }
8190: # single or double quotation marks after a separator indicate beginning of a quote
8191: # we are now looking for the end of the quote and need to ignore separators
8192: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8193: $looking_for=$character;
8194: next;
8195: }
8196: # ignore would be true after we reached the end of a quote
8197: if ($ignore) { next; }
8198: if (($just_found_separator) && ($character=~/\s/)) { next; }
8199: $field.=$character;
8200: $just_found_separator=0;
1.31 albertel 8201: }
1.561 www 8202: # catch the very last entry, since we never encountered the separator
8203: $components{&takeleft($i)}=$field;
1.31 albertel 8204: }
8205: return %components;
8206: }
8207:
1.144 matthew 8208: ######################################################
8209: ######################################################
8210:
1.56 matthew 8211: =pod
8212:
1.648 raeburn 8213: =item * &upfile_select_html()
1.41 ng 8214:
1.144 matthew 8215: Return HTML code to select a file from the users machine and specify
8216: the file type.
1.41 ng 8217:
8218: =cut
8219:
1.144 matthew 8220: ######################################################
8221: ######################################################
1.31 albertel 8222: sub upfile_select_html {
1.144 matthew 8223: my %Types = (
8224: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8225: semisv => &mt('Semicolon separated values'),
1.144 matthew 8226: space => &mt('Space separated'),
8227: tab => &mt('Tabulator separated'),
8228: # xml => &mt('HTML/XML'),
8229: );
8230: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8231: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8232: foreach my $type (sort(keys(%Types))) {
8233: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8234: }
8235: $Str .= "</select>\n";
8236: return $Str;
1.31 albertel 8237: }
8238:
1.301 albertel 8239: sub get_samples {
8240: my ($records,$toget) = @_;
8241: my @samples=({});
8242: my $got=0;
8243: foreach my $rec (@$records) {
8244: my %temp = &record_sep($rec);
8245: if (! grep(/\S/, values(%temp))) { next; }
8246: if (%temp) {
8247: $samples[$got]=\%temp;
8248: $got++;
8249: if ($got == $toget) { last; }
8250: }
8251: }
8252: return \@samples;
8253: }
8254:
1.144 matthew 8255: ######################################################
8256: ######################################################
8257:
1.56 matthew 8258: =pod
8259:
1.648 raeburn 8260: =item * &csv_print_samples($r,$records)
1.41 ng 8261:
8262: Prints a table of sample values from each column uploaded $r is an
8263: Apache Request ref, $records is an arrayref from
8264: &Apache::loncommon::upfile_record_sep
8265:
8266: =cut
8267:
1.144 matthew 8268: ######################################################
8269: ######################################################
1.31 albertel 8270: sub csv_print_samples {
8271: my ($r,$records) = @_;
1.662 bisitz 8272: my $samples = &get_samples($records,5);
1.301 albertel 8273:
1.594 raeburn 8274: $r->print(&mt('Samples').'<br />'.&start_data_table().
8275: &start_data_table_header_row());
1.356 albertel 8276: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8277: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8278: $r->print(&end_data_table_header_row());
1.301 albertel 8279: foreach my $hash (@$samples) {
1.594 raeburn 8280: $r->print(&start_data_table_row());
1.356 albertel 8281: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8282: $r->print('<td>');
1.356 albertel 8283: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8284: $r->print('</td>');
8285: }
1.594 raeburn 8286: $r->print(&end_data_table_row());
1.31 albertel 8287: }
1.594 raeburn 8288: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8289: }
8290:
1.144 matthew 8291: ######################################################
8292: ######################################################
8293:
1.56 matthew 8294: =pod
8295:
1.648 raeburn 8296: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8297:
8298: Prints a table to create associations between values and table columns.
1.144 matthew 8299:
1.41 ng 8300: $r is an Apache Request ref,
8301: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8302: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8303:
8304: =cut
8305:
1.144 matthew 8306: ######################################################
8307: ######################################################
1.31 albertel 8308: sub csv_print_select_table {
8309: my ($r,$records,$d) = @_;
1.301 albertel 8310: my $i=0;
8311: my $samples = &get_samples($records,1);
1.144 matthew 8312: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8313: &start_data_table().&start_data_table_header_row().
1.144 matthew 8314: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8315: '<th>'.&mt('Column').'</th>'.
8316: &end_data_table_header_row()."\n");
1.356 albertel 8317: foreach my $array_ref (@$d) {
8318: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8319: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8320:
8321: $r->print('<td><select name=f'.$i.
1.32 matthew 8322: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8323: $r->print('<option value="none"></option>');
1.356 albertel 8324: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8325: $r->print('<option value="'.$sample.'"'.
8326: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8327: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8328: }
1.594 raeburn 8329: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8330: $i++;
8331: }
1.594 raeburn 8332: $r->print(&end_data_table());
1.31 albertel 8333: $i--;
8334: return $i;
8335: }
1.56 matthew 8336:
1.144 matthew 8337: ######################################################
8338: ######################################################
8339:
1.56 matthew 8340: =pod
1.31 albertel 8341:
1.648 raeburn 8342: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8343:
8344: Prints a table of sample values from the upload and can make associate samples to internal names.
8345:
8346: $r is an Apache Request ref,
8347: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8348: $d is an array of 2 element arrays (internal name, displayed name)
8349:
8350: =cut
8351:
1.144 matthew 8352: ######################################################
8353: ######################################################
1.31 albertel 8354: sub csv_samples_select_table {
8355: my ($r,$records,$d) = @_;
8356: my $i=0;
1.144 matthew 8357: #
1.662 bisitz 8358: my $max_samples = 5;
8359: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8360: $r->print(&start_data_table().
8361: &start_data_table_header_row().'<th>'.
8362: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8363: &end_data_table_header_row());
1.301 albertel 8364:
8365: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8366: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8367: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8368: foreach my $option (@$d) {
8369: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8370: $r->print('<option value="'.$value.'"'.
1.253 albertel 8371: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8372: $display.'</option>');
1.31 albertel 8373: }
8374: $r->print('</select></td><td>');
1.662 bisitz 8375: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8376: if (defined($samples->[$line]{$key})) {
8377: $r->print($samples->[$line]{$key}."<br />\n");
8378: }
8379: }
1.594 raeburn 8380: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8381: $i++;
8382: }
1.594 raeburn 8383: $r->print(&end_data_table());
1.31 albertel 8384: $i--;
8385: return($i);
1.115 matthew 8386: }
8387:
1.144 matthew 8388: ######################################################
8389: ######################################################
8390:
1.115 matthew 8391: =pod
8392:
1.648 raeburn 8393: =item * &clean_excel_name($name)
1.115 matthew 8394:
8395: Returns a replacement for $name which does not contain any illegal characters.
8396:
8397: =cut
8398:
1.144 matthew 8399: ######################################################
8400: ######################################################
1.115 matthew 8401: sub clean_excel_name {
8402: my ($name) = @_;
8403: $name =~ s/[:\*\?\/\\]//g;
8404: if (length($name) > 31) {
8405: $name = substr($name,0,31);
8406: }
8407: return $name;
1.25 albertel 8408: }
1.84 albertel 8409:
1.85 albertel 8410: =pod
8411:
1.648 raeburn 8412: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8413:
8414: Returns either 1 or undef
8415:
8416: 1 if the part is to be hidden, undef if it is to be shown
8417:
8418: Arguments are:
8419:
8420: $id the id of the part to be checked
8421: $symb, optional the symb of the resource to check
8422: $udom, optional the domain of the user to check for
8423: $uname, optional the username of the user to check for
8424:
8425: =cut
1.84 albertel 8426:
8427: sub check_if_partid_hidden {
8428: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8429: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8430: $symb,$udom,$uname);
1.141 albertel 8431: my $truth=1;
8432: #if the string starts with !, then the list is the list to show not hide
8433: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8434: my @hiddenlist=split(/,/,$hiddenparts);
8435: foreach my $checkid (@hiddenlist) {
1.141 albertel 8436: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8437: }
1.141 albertel 8438: return !$truth;
1.84 albertel 8439: }
1.127 matthew 8440:
1.138 matthew 8441:
8442: ############################################################
8443: ############################################################
8444:
8445: =pod
8446:
1.157 matthew 8447: =back
8448:
1.138 matthew 8449: =head1 cgi-bin script and graphing routines
8450:
1.157 matthew 8451: =over 4
8452:
1.648 raeburn 8453: =item * &get_cgi_id()
1.138 matthew 8454:
8455: Inputs: none
8456:
8457: Returns an id which can be used to pass environment variables
8458: to various cgi-bin scripts. These environment variables will
8459: be removed from the users environment after a given time by
8460: the routine &Apache::lonnet::transfer_profile_to_env.
8461:
8462: =cut
8463:
8464: ############################################################
8465: ############################################################
1.152 albertel 8466: my $uniq=0;
1.136 matthew 8467: sub get_cgi_id {
1.154 albertel 8468: $uniq=($uniq+1)%100000;
1.280 albertel 8469: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8470: }
8471:
1.127 matthew 8472: ############################################################
8473: ############################################################
8474:
8475: =pod
8476:
1.648 raeburn 8477: =item * &DrawBarGraph()
1.127 matthew 8478:
1.138 matthew 8479: Facilitates the plotting of data in a (stacked) bar graph.
8480: Puts plot definition data into the users environment in order for
8481: graph.png to plot it. Returns an <img> tag for the plot.
8482: The bars on the plot are labeled '1','2',...,'n'.
8483:
8484: Inputs:
8485:
8486: =over 4
8487:
8488: =item $Title: string, the title of the plot
8489:
8490: =item $xlabel: string, text describing the X-axis of the plot
8491:
8492: =item $ylabel: string, text describing the Y-axis of the plot
8493:
8494: =item $Max: scalar, the maximum Y value to use in the plot
8495: If $Max is < any data point, the graph will not be rendered.
8496:
1.140 matthew 8497: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8498: they are plotted. If undefined, default values will be used.
8499:
1.178 matthew 8500: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8501:
1.138 matthew 8502: =item @Values: An array of array references. Each array reference holds data
8503: to be plotted in a stacked bar chart.
8504:
1.239 matthew 8505: =item If the final element of @Values is a hash reference the key/value
8506: pairs will be added to the graph definition.
8507:
1.138 matthew 8508: =back
8509:
8510: Returns:
8511:
8512: An <img> tag which references graph.png and the appropriate identifying
8513: information for the plot.
8514:
1.127 matthew 8515: =cut
8516:
8517: ############################################################
8518: ############################################################
1.134 matthew 8519: sub DrawBarGraph {
1.178 matthew 8520: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8521: #
8522: if (! defined($colors)) {
8523: $colors = ['#33ff00',
8524: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8525: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8526: ];
8527: }
1.228 matthew 8528: my $extra_settings = {};
8529: if (ref($Values[-1]) eq 'HASH') {
8530: $extra_settings = pop(@Values);
8531: }
1.127 matthew 8532: #
1.136 matthew 8533: my $identifier = &get_cgi_id();
8534: my $id = 'cgi.'.$identifier;
1.129 matthew 8535: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8536: return '';
8537: }
1.225 matthew 8538: #
8539: my @Labels;
8540: if (defined($labels)) {
8541: @Labels = @$labels;
8542: } else {
8543: for (my $i=0;$i<@{$Values[0]};$i++) {
8544: push (@Labels,$i+1);
8545: }
8546: }
8547: #
1.129 matthew 8548: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8549: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8550: my %ValuesHash;
8551: my $NumSets=1;
8552: foreach my $array (@Values) {
8553: next if (! ref($array));
1.136 matthew 8554: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8555: join(',',@$array);
1.129 matthew 8556: }
1.127 matthew 8557: #
1.136 matthew 8558: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8559: if ($NumBars < 3) {
8560: $width = 120+$NumBars*32;
1.220 matthew 8561: $xskip = 1;
1.225 matthew 8562: $bar_width = 30;
8563: } elsif ($NumBars < 5) {
8564: $width = 120+$NumBars*20;
8565: $xskip = 1;
8566: $bar_width = 20;
1.220 matthew 8567: } elsif ($NumBars < 10) {
1.136 matthew 8568: $width = 120+$NumBars*15;
8569: $xskip = 1;
8570: $bar_width = 15;
8571: } elsif ($NumBars <= 25) {
8572: $width = 120+$NumBars*11;
8573: $xskip = 5;
8574: $bar_width = 8;
8575: } elsif ($NumBars <= 50) {
8576: $width = 120+$NumBars*8;
8577: $xskip = 5;
8578: $bar_width = 4;
8579: } else {
8580: $width = 120+$NumBars*8;
8581: $xskip = 5;
8582: $bar_width = 4;
8583: }
8584: #
1.137 matthew 8585: $Max = 1 if ($Max < 1);
8586: if ( int($Max) < $Max ) {
8587: $Max++;
8588: $Max = int($Max);
8589: }
1.127 matthew 8590: $Title = '' if (! defined($Title));
8591: $xlabel = '' if (! defined($xlabel));
8592: $ylabel = '' if (! defined($ylabel));
1.369 www 8593: $ValuesHash{$id.'.title'} = &escape($Title);
8594: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8595: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8596: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8597: $ValuesHash{$id.'.NumBars'} = $NumBars;
8598: $ValuesHash{$id.'.NumSets'} = $NumSets;
8599: $ValuesHash{$id.'.PlotType'} = 'bar';
8600: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8601: $ValuesHash{$id.'.height'} = $height;
8602: $ValuesHash{$id.'.width'} = $width;
8603: $ValuesHash{$id.'.xskip'} = $xskip;
8604: $ValuesHash{$id.'.bar_width'} = $bar_width;
8605: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8606: #
1.228 matthew 8607: # Deal with other parameters
8608: while (my ($key,$value) = each(%$extra_settings)) {
8609: $ValuesHash{$id.'.'.$key} = $value;
8610: }
8611: #
1.646 raeburn 8612: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8613: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8614: }
8615:
8616: ############################################################
8617: ############################################################
8618:
8619: =pod
8620:
1.648 raeburn 8621: =item * &DrawXYGraph()
1.137 matthew 8622:
1.138 matthew 8623: Facilitates the plotting of data in an XY graph.
8624: Puts plot definition data into the users environment in order for
8625: graph.png to plot it. Returns an <img> tag for the plot.
8626:
8627: Inputs:
8628:
8629: =over 4
8630:
8631: =item $Title: string, the title of the plot
8632:
8633: =item $xlabel: string, text describing the X-axis of the plot
8634:
8635: =item $ylabel: string, text describing the Y-axis of the plot
8636:
8637: =item $Max: scalar, the maximum Y value to use in the plot
8638: If $Max is < any data point, the graph will not be rendered.
8639:
8640: =item $colors: Array ref containing the hex color codes for the data to be
8641: plotted in. If undefined, default values will be used.
8642:
8643: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8644:
8645: =item $Ydata: Array ref containing Array refs.
1.185 www 8646: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8647:
8648: =item %Values: hash indicating or overriding any default values which are
8649: passed to graph.png.
8650: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8651:
8652: =back
8653:
8654: Returns:
8655:
8656: An <img> tag which references graph.png and the appropriate identifying
8657: information for the plot.
8658:
1.137 matthew 8659: =cut
8660:
8661: ############################################################
8662: ############################################################
8663: sub DrawXYGraph {
8664: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8665: #
8666: # Create the identifier for the graph
8667: my $identifier = &get_cgi_id();
8668: my $id = 'cgi.'.$identifier;
8669: #
8670: $Title = '' if (! defined($Title));
8671: $xlabel = '' if (! defined($xlabel));
8672: $ylabel = '' if (! defined($ylabel));
8673: my %ValuesHash =
8674: (
1.369 www 8675: $id.'.title' => &escape($Title),
8676: $id.'.xlabel' => &escape($xlabel),
8677: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8678: $id.'.y_max_value'=> $Max,
8679: $id.'.labels' => join(',',@$Xlabels),
8680: $id.'.PlotType' => 'XY',
8681: );
8682: #
8683: if (defined($colors) && ref($colors) eq 'ARRAY') {
8684: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8685: }
8686: #
8687: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8688: return '';
8689: }
8690: my $NumSets=1;
1.138 matthew 8691: foreach my $array (@{$Ydata}){
1.137 matthew 8692: next if (! ref($array));
8693: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8694: }
1.138 matthew 8695: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8696: #
8697: # Deal with other parameters
8698: while (my ($key,$value) = each(%Values)) {
8699: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8700: }
8701: #
1.646 raeburn 8702: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8703: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8704: }
8705:
8706: ############################################################
8707: ############################################################
8708:
8709: =pod
8710:
1.648 raeburn 8711: =item * &DrawXYYGraph()
1.138 matthew 8712:
8713: Facilitates the plotting of data in an XY graph with two Y axes.
8714: Puts plot definition data into the users environment in order for
8715: graph.png to plot it. Returns an <img> tag for the plot.
8716:
8717: Inputs:
8718:
8719: =over 4
8720:
8721: =item $Title: string, the title of the plot
8722:
8723: =item $xlabel: string, text describing the X-axis of the plot
8724:
8725: =item $ylabel: string, text describing the Y-axis of the plot
8726:
8727: =item $colors: Array ref containing the hex color codes for the data to be
8728: plotted in. If undefined, default values will be used.
8729:
8730: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8731:
8732: =item $Ydata1: The first data set
8733:
8734: =item $Min1: The minimum value of the left Y-axis
8735:
8736: =item $Max1: The maximum value of the left Y-axis
8737:
8738: =item $Ydata2: The second data set
8739:
8740: =item $Min2: The minimum value of the right Y-axis
8741:
8742: =item $Max2: The maximum value of the left Y-axis
8743:
8744: =item %Values: hash indicating or overriding any default values which are
8745: passed to graph.png.
8746: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8747:
8748: =back
8749:
8750: Returns:
8751:
8752: An <img> tag which references graph.png and the appropriate identifying
8753: information for the plot.
1.136 matthew 8754:
8755: =cut
8756:
8757: ############################################################
8758: ############################################################
1.137 matthew 8759: sub DrawXYYGraph {
8760: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8761: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8762: #
8763: # Create the identifier for the graph
8764: my $identifier = &get_cgi_id();
8765: my $id = 'cgi.'.$identifier;
8766: #
8767: $Title = '' if (! defined($Title));
8768: $xlabel = '' if (! defined($xlabel));
8769: $ylabel = '' if (! defined($ylabel));
8770: my %ValuesHash =
8771: (
1.369 www 8772: $id.'.title' => &escape($Title),
8773: $id.'.xlabel' => &escape($xlabel),
8774: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8775: $id.'.labels' => join(',',@$Xlabels),
8776: $id.'.PlotType' => 'XY',
8777: $id.'.NumSets' => 2,
1.137 matthew 8778: $id.'.two_axes' => 1,
8779: $id.'.y1_max_value' => $Max1,
8780: $id.'.y1_min_value' => $Min1,
8781: $id.'.y2_max_value' => $Max2,
8782: $id.'.y2_min_value' => $Min2,
1.136 matthew 8783: );
8784: #
1.137 matthew 8785: if (defined($colors) && ref($colors) eq 'ARRAY') {
8786: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8787: }
8788: #
8789: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8790: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8791: return '';
8792: }
8793: my $NumSets=1;
1.137 matthew 8794: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8795: next if (! ref($array));
8796: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8797: }
8798: #
8799: # Deal with other parameters
8800: while (my ($key,$value) = each(%Values)) {
8801: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8802: }
8803: #
1.646 raeburn 8804: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8805: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8806: }
8807:
8808: ############################################################
8809: ############################################################
8810:
8811: =pod
8812:
1.157 matthew 8813: =back
8814:
1.139 matthew 8815: =head1 Statistics helper routines?
8816:
8817: Bad place for them but what the hell.
8818:
1.157 matthew 8819: =over 4
8820:
1.648 raeburn 8821: =item * &chartlink()
1.139 matthew 8822:
8823: Returns a link to the chart for a specific student.
8824:
8825: Inputs:
8826:
8827: =over 4
8828:
8829: =item $linktext: The text of the link
8830:
8831: =item $sname: The students username
8832:
8833: =item $sdomain: The students domain
8834:
8835: =back
8836:
1.157 matthew 8837: =back
8838:
1.139 matthew 8839: =cut
8840:
8841: ############################################################
8842: ############################################################
8843: sub chartlink {
8844: my ($linktext, $sname, $sdomain) = @_;
8845: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8846: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8847: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8848: '">'.$linktext.'</a>';
1.153 matthew 8849: }
8850:
8851: #######################################################
8852: #######################################################
8853:
8854: =pod
8855:
8856: =head1 Course Environment Routines
1.157 matthew 8857:
8858: =over 4
1.153 matthew 8859:
1.648 raeburn 8860: =item * &restore_course_settings()
1.153 matthew 8861:
1.648 raeburn 8862: =item * &store_course_settings()
1.153 matthew 8863:
8864: Restores/Store indicated form parameters from the course environment.
8865: Will not overwrite existing values of the form parameters.
8866:
8867: Inputs:
8868: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8869:
8870: a hash ref describing the data to be stored. For example:
8871:
8872: %Save_Parameters = ('Status' => 'scalar',
8873: 'chartoutputmode' => 'scalar',
8874: 'chartoutputdata' => 'scalar',
8875: 'Section' => 'array',
1.373 raeburn 8876: 'Group' => 'array',
1.153 matthew 8877: 'StudentData' => 'array',
8878: 'Maps' => 'array');
8879:
8880: Returns: both routines return nothing
8881:
1.631 raeburn 8882: =back
8883:
1.153 matthew 8884: =cut
8885:
8886: #######################################################
8887: #######################################################
8888: sub store_course_settings {
1.496 albertel 8889: return &store_settings($env{'request.course.id'},@_);
8890: }
8891:
8892: sub store_settings {
1.153 matthew 8893: # save to the environment
8894: # appenv the same items, just to be safe
1.300 albertel 8895: my $udom = $env{'user.domain'};
8896: my $uname = $env{'user.name'};
1.496 albertel 8897: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8898: my %SaveHash;
8899: my %AppHash;
8900: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8901: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8902: my $envname = 'environment.'.$basename;
1.258 albertel 8903: if (exists($env{'form.'.$setting})) {
1.153 matthew 8904: # Save this value away
8905: if ($type eq 'scalar' &&
1.258 albertel 8906: (! exists($env{$envname}) ||
8907: $env{$envname} ne $env{'form.'.$setting})) {
8908: $SaveHash{$basename} = $env{'form.'.$setting};
8909: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8910: } elsif ($type eq 'array') {
8911: my $stored_form;
1.258 albertel 8912: if (ref($env{'form.'.$setting})) {
1.153 matthew 8913: $stored_form = join(',',
8914: map {
1.369 www 8915: &escape($_);
1.258 albertel 8916: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8917: } else {
8918: $stored_form =
1.369 www 8919: &escape($env{'form.'.$setting});
1.153 matthew 8920: }
8921: # Determine if the array contents are the same.
1.258 albertel 8922: if ($stored_form ne $env{$envname}) {
1.153 matthew 8923: $SaveHash{$basename} = $stored_form;
8924: $AppHash{$envname} = $stored_form;
8925: }
8926: }
8927: }
8928: }
8929: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8930: $udom,$uname);
1.153 matthew 8931: if ($put_result !~ /^(ok|delayed)/) {
8932: &Apache::lonnet::logthis('unable to save form parameters, '.
8933: 'got error:'.$put_result);
8934: }
8935: # Make sure these settings stick around in this session, too
1.646 raeburn 8936: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8937: return;
8938: }
8939:
8940: sub restore_course_settings {
1.499 albertel 8941: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8942: }
8943:
8944: sub restore_settings {
8945: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8946: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8947: next if (exists($env{'form.'.$setting}));
1.496 albertel 8948: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8949: '.'.$setting;
1.258 albertel 8950: if (exists($env{$envname})) {
1.153 matthew 8951: if ($type eq 'scalar') {
1.258 albertel 8952: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8953: } elsif ($type eq 'array') {
1.258 albertel 8954: $env{'form.'.$setting} = [
1.153 matthew 8955: map {
1.369 www 8956: &unescape($_);
1.258 albertel 8957: } split(',',$env{$envname})
1.153 matthew 8958: ];
8959: }
8960: }
8961: }
1.127 matthew 8962: }
8963:
1.618 raeburn 8964: #######################################################
8965: #######################################################
8966:
8967: =pod
8968:
8969: =head1 Domain E-mail Routines
8970:
8971: =over 4
8972:
1.648 raeburn 8973: =item * &build_recipient_list()
1.618 raeburn 8974:
1.766 raeburn 8975: Build recipient lists for four types of e-mail:
8976: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
8977: (d) Help requests, generated by
8978: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 8979:
8980: Inputs:
1.619 raeburn 8981: defmail (scalar - email address of default recipient),
1.618 raeburn 8982: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8983: defdom (domain for which to retrieve configuration settings),
8984: origmail (scalar - email address of recipient from loncapa.conf,
8985: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8986:
1.655 raeburn 8987: Returns: comma separated list of addresses to which to send e-mail.
8988:
8989: =back
1.618 raeburn 8990:
8991: =cut
8992:
8993: ############################################################
8994: ############################################################
8995: sub build_recipient_list {
1.619 raeburn 8996: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8997: my @recipients;
8998: my $otheremails;
8999: my %domconfig =
9000: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9001: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9002: if (exists($domconfig{'contacts'}{$mailing})) {
9003: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9004: my @contacts = ('adminemail','supportemail');
9005: foreach my $item (@contacts) {
9006: if ($domconfig{'contacts'}{$mailing}{$item}) {
9007: my $addr = $domconfig{'contacts'}{$item};
9008: if (!grep(/^\Q$addr\E$/,@recipients)) {
9009: push(@recipients,$addr);
9010: }
1.619 raeburn 9011: }
1.766 raeburn 9012: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9013: }
9014: }
1.766 raeburn 9015: } elsif ($origmail ne '') {
9016: push(@recipients,$origmail);
1.618 raeburn 9017: }
1.619 raeburn 9018: } elsif ($origmail ne '') {
9019: push(@recipients,$origmail);
1.618 raeburn 9020: }
1.688 raeburn 9021: if (defined($defmail)) {
9022: if ($defmail ne '') {
9023: push(@recipients,$defmail);
9024: }
1.618 raeburn 9025: }
9026: if ($otheremails) {
1.619 raeburn 9027: my @others;
9028: if ($otheremails =~ /,/) {
9029: @others = split(/,/,$otheremails);
1.618 raeburn 9030: } else {
1.619 raeburn 9031: push(@others,$otheremails);
9032: }
9033: foreach my $addr (@others) {
9034: if (!grep(/^\Q$addr\E$/,@recipients)) {
9035: push(@recipients,$addr);
9036: }
1.618 raeburn 9037: }
9038: }
1.619 raeburn 9039: my $recipientlist = join(',',@recipients);
1.618 raeburn 9040: return $recipientlist;
9041: }
9042:
1.127 matthew 9043: ############################################################
9044: ############################################################
1.154 albertel 9045:
1.655 raeburn 9046: =pod
9047:
9048: =head1 Course Catalog Routines
9049:
9050: =over 4
9051:
9052: =item * &gather_categories()
9053:
9054: Converts category definitions - keys of categories hash stored in
9055: coursecategories in configuration.db on the primary library server in a
9056: domain - to an array. Also generates javascript and idx hash used to
9057: generate Domain Coordinator interface for editing Course Categories.
9058:
9059: Inputs:
1.663 raeburn 9060:
1.655 raeburn 9061: categories (reference to hash of category definitions).
1.663 raeburn 9062:
1.655 raeburn 9063: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9064: categories and subcategories).
1.663 raeburn 9065:
1.655 raeburn 9066: idx (reference to hash of counters used in Domain Coordinator interface for
9067: editing Course Categories).
1.663 raeburn 9068:
1.655 raeburn 9069: jsarray (reference to array of categories used to create Javascript arrays for
9070: Domain Coordinator interface for editing Course Categories).
9071:
9072: Returns: nothing
9073:
9074: Side effects: populates cats, idx and jsarray.
9075:
9076: =cut
9077:
9078: sub gather_categories {
9079: my ($categories,$cats,$idx,$jsarray) = @_;
9080: my %counters;
9081: my $num = 0;
9082: foreach my $item (keys(%{$categories})) {
9083: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9084: if ($container eq '' && $depth == 0) {
9085: $cats->[$depth][$categories->{$item}] = $cat;
9086: } else {
9087: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9088: }
9089: my ($escitem,$tail) = split(/:/,$item,2);
9090: if ($counters{$tail} eq '') {
9091: $counters{$tail} = $num;
9092: $num ++;
9093: }
9094: if (ref($idx) eq 'HASH') {
9095: $idx->{$item} = $counters{$tail};
9096: }
9097: if (ref($jsarray) eq 'ARRAY') {
9098: push(@{$jsarray->[$counters{$tail}]},$item);
9099: }
9100: }
9101: return;
9102: }
9103:
9104: =pod
9105:
9106: =item * &extract_categories()
9107:
9108: Used to generate breadcrumb trails for course categories.
9109:
9110: Inputs:
1.663 raeburn 9111:
1.655 raeburn 9112: categories (reference to hash of category definitions).
1.663 raeburn 9113:
1.655 raeburn 9114: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9115: categories and subcategories).
1.663 raeburn 9116:
1.655 raeburn 9117: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9118:
1.655 raeburn 9119: allitems (reference to hash - key is category key
9120: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9121:
1.655 raeburn 9122: idx (reference to hash of counters used in Domain Coordinator interface for
9123: editing Course Categories).
1.663 raeburn 9124:
1.655 raeburn 9125: jsarray (reference to array of categories used to create Javascript arrays for
9126: Domain Coordinator interface for editing Course Categories).
9127:
1.665 raeburn 9128: subcats (reference to hash of arrays containing all subcategories within each
9129: category, -recursive)
9130:
1.655 raeburn 9131: Returns: nothing
9132:
9133: Side effects: populates trails and allitems hash references.
9134:
9135: =cut
9136:
9137: sub extract_categories {
1.665 raeburn 9138: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9139: if (ref($categories) eq 'HASH') {
9140: &gather_categories($categories,$cats,$idx,$jsarray);
9141: if (ref($cats->[0]) eq 'ARRAY') {
9142: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9143: my $name = $cats->[0][$i];
9144: my $item = &escape($name).'::0';
9145: my $trailstr;
9146: if ($name eq 'instcode') {
9147: $trailstr = &mt('Official courses (with institutional codes)');
9148: } else {
9149: $trailstr = $name;
9150: }
9151: if ($allitems->{$item} eq '') {
9152: push(@{$trails},$trailstr);
9153: $allitems->{$item} = scalar(@{$trails})-1;
9154: }
9155: my @parents = ($name);
9156: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9157: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9158: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9159: if (ref($subcats) eq 'HASH') {
9160: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9161: }
9162: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9163: }
9164: } else {
9165: if (ref($subcats) eq 'HASH') {
9166: $subcats->{$item} = [];
1.655 raeburn 9167: }
9168: }
9169: }
9170: }
9171: }
9172: return;
9173: }
9174:
9175: =pod
9176:
9177: =item *&recurse_categories()
9178:
9179: Recursively used to generate breadcrumb trails for course categories.
9180:
9181: Inputs:
1.663 raeburn 9182:
1.655 raeburn 9183: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9184: categories and subcategories).
1.663 raeburn 9185:
1.655 raeburn 9186: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9187:
9188: category (current course category, for which breadcrumb trail is being generated).
9189:
9190: trails (reference to array of breadcrumb trails for each category).
9191:
1.655 raeburn 9192: allitems (reference to hash - key is category key
9193: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9194:
1.655 raeburn 9195: parents (array containing containers directories for current category,
9196: back to top level).
9197:
9198: Returns: nothing
9199:
9200: Side effects: populates trails and allitems hash references
9201:
9202: =cut
9203:
9204: sub recurse_categories {
1.665 raeburn 9205: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9206: my $shallower = $depth - 1;
9207: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9208: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9209: my $name = $cats->[$depth]{$category}[$k];
9210: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9211: my $trailstr = join(' -> ',(@{$parents},$category));
9212: if ($allitems->{$item} eq '') {
9213: push(@{$trails},$trailstr);
9214: $allitems->{$item} = scalar(@{$trails})-1;
9215: }
9216: my $deeper = $depth+1;
9217: push(@{$parents},$category);
1.665 raeburn 9218: if (ref($subcats) eq 'HASH') {
9219: my $subcat = &escape($name).':'.$category.':'.$depth;
9220: for (my $j=@{$parents}; $j>=0; $j--) {
9221: my $higher;
9222: if ($j > 0) {
9223: $higher = &escape($parents->[$j]).':'.
9224: &escape($parents->[$j-1]).':'.$j;
9225: } else {
9226: $higher = &escape($parents->[$j]).'::'.$j;
9227: }
9228: push(@{$subcats->{$higher}},$subcat);
9229: }
9230: }
9231: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9232: $subcats);
1.655 raeburn 9233: pop(@{$parents});
9234: }
9235: } else {
9236: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9237: my $trailstr = join(' -> ',(@{$parents},$category));
9238: if ($allitems->{$item} eq '') {
9239: push(@{$trails},$trailstr);
9240: $allitems->{$item} = scalar(@{$trails})-1;
9241: }
9242: }
9243: return;
9244: }
9245:
1.663 raeburn 9246: =pod
9247:
9248: =item *&assign_categories_table()
9249:
9250: Create a datatable for display of hierarchical categories in a domain,
9251: with checkboxes to allow a course to be categorized.
9252:
9253: Inputs:
9254:
9255: cathash - reference to hash of categories defined for the domain (from
9256: configuration.db)
9257:
9258: currcat - scalar with an & separated list of categories assigned to a course.
9259:
9260: Returns: $output (markup to be displayed)
9261:
9262: =cut
9263:
9264: sub assign_categories_table {
9265: my ($cathash,$currcat) = @_;
9266: my $output;
9267: if (ref($cathash) eq 'HASH') {
9268: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9269: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9270: $maxdepth = scalar(@cats);
9271: if (@cats > 0) {
9272: my $itemcount = 0;
9273: if (ref($cats[0]) eq 'ARRAY') {
9274: $output = &Apache::loncommon::start_data_table();
9275: my @currcategories;
9276: if ($currcat ne '') {
9277: @currcategories = split('&',$currcat);
9278: }
9279: for (my $i=0; $i<@{$cats[0]}; $i++) {
9280: my $parent = $cats[0][$i];
9281: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9282: next if ($parent eq 'instcode');
9283: my $item = &escape($parent).'::0';
9284: my $checked = '';
9285: if (@currcategories > 0) {
9286: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9287: $checked = ' checked="checked"';
1.663 raeburn 9288: }
9289: }
1.675 raeburn 9290: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9291: '<input type="checkbox" name="usecategory" value="'.
9292: $item.'"'.$checked.' />'.$parent.'</span>'.
9293: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9294: my $depth = 1;
9295: push(@path,$parent);
9296: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9297: pop(@path);
9298: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9299: $itemcount ++;
9300: }
9301: $output .= &Apache::loncommon::end_data_table();
9302: }
9303: }
9304: }
9305: return $output;
9306: }
9307:
9308: =pod
9309:
9310: =item *&assign_category_rows()
9311:
9312: Create a datatable row for display of nested categories in a domain,
9313: with checkboxes to allow a course to be categorized,called recursively.
9314:
9315: Inputs:
9316:
9317: itemcount - track row number for alternating colors
9318:
9319: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9320: categories and subcategories.
9321:
9322: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9323:
9324: parent - parent of current category item
9325:
9326: path - Array containing all categories back up through the hierarchy from the
9327: current category to the top level.
9328:
9329: currcategories - reference to array of current categories assigned to the course
9330:
9331: Returns: $output (markup to be displayed).
9332:
9333: =cut
9334:
9335: sub assign_category_rows {
9336: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9337: my ($text,$name,$item,$chgstr);
9338: if (ref($cats) eq 'ARRAY') {
9339: my $maxdepth = scalar(@{$cats});
9340: if (ref($cats->[$depth]) eq 'HASH') {
9341: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9342: my $numchildren = @{$cats->[$depth]{$parent}};
9343: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9344: $text .= '<td><table class="LC_datatable">';
9345: for (my $j=0; $j<$numchildren; $j++) {
9346: $name = $cats->[$depth]{$parent}[$j];
9347: $item = &escape($name).':'.&escape($parent).':'.$depth;
9348: my $deeper = $depth+1;
9349: my $checked = '';
9350: if (ref($currcategories) eq 'ARRAY') {
9351: if (@{$currcategories} > 0) {
9352: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9353: $checked = ' checked="checked"';
1.663 raeburn 9354: }
9355: }
9356: }
1.664 raeburn 9357: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9358: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9359: $item.'"'.$checked.' />'.$name.'</label></span>'.
9360: '<input type="hidden" name="catname" value="'.$name.'" />'.
9361: '</td><td>';
1.663 raeburn 9362: if (ref($path) eq 'ARRAY') {
9363: push(@{$path},$name);
9364: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9365: pop(@{$path});
9366: }
9367: $text .= '</td></tr>';
9368: }
9369: $text .= '</table></td>';
9370: }
9371: }
9372: }
9373: return $text;
9374: }
9375:
1.655 raeburn 9376: ############################################################
9377: ############################################################
9378:
9379:
1.443 albertel 9380: sub commit_customrole {
1.664 raeburn 9381: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9382: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9383: ($start?', '.&mt('starting').' '.localtime($start):'').
9384: ($end?', ending '.localtime($end):'').': <b>'.
9385: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9386: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9387: '</b><br />';
9388: return $output;
9389: }
9390:
9391: sub commit_standardrole {
1.541 raeburn 9392: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9393: my ($output,$logmsg,$linefeed);
9394: if ($context eq 'auto') {
9395: $linefeed = "\n";
9396: } else {
9397: $linefeed = "<br />\n";
9398: }
1.443 albertel 9399: if ($three eq 'st') {
1.541 raeburn 9400: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9401: $one,$two,$sec,$context);
9402: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9403: ($result eq 'unknown_course') || ($result eq 'refused')) {
9404: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9405: } else {
1.541 raeburn 9406: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9407: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9408: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9409: if ($context eq 'auto') {
9410: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9411: } else {
9412: $output .= '<b>'.$result.'</b>'.$linefeed.
9413: &mt('Add to classlist').': <b>ok</b>';
9414: }
9415: $output .= $linefeed;
1.443 albertel 9416: }
9417: } else {
9418: $output = &mt('Assigning').' '.$three.' in '.$url.
9419: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9420: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9421: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9422: if ($context eq 'auto') {
9423: $output .= $result.$linefeed;
9424: } else {
9425: $output .= '<b>'.$result.'</b>'.$linefeed;
9426: }
1.443 albertel 9427: }
9428: return $output;
9429: }
9430:
9431: sub commit_studentrole {
1.541 raeburn 9432: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9433: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9434: if ($context eq 'auto') {
9435: $linefeed = "\n";
9436: } else {
9437: $linefeed = '<br />'."\n";
9438: }
1.443 albertel 9439: if (defined($one) && defined($two)) {
9440: my $cid=$one.'_'.$two;
9441: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9442: my $secchange = 0;
9443: my $expire_role_result;
9444: my $modify_section_result;
1.628 raeburn 9445: if ($oldsec ne '-1') {
9446: if ($oldsec ne $sec) {
1.443 albertel 9447: $secchange = 1;
1.628 raeburn 9448: my $now = time;
1.443 albertel 9449: my $uurl='/'.$cid;
9450: $uurl=~s/\_/\//g;
9451: if ($oldsec) {
9452: $uurl.='/'.$oldsec;
9453: }
1.626 raeburn 9454: $oldsecurl = $uurl;
1.628 raeburn 9455: $expire_role_result =
1.652 raeburn 9456: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9457: if ($env{'request.course.sec'} ne '') {
9458: if ($expire_role_result eq 'refused') {
9459: my @roles = ('st');
9460: my @statuses = ('previous');
9461: my @roledoms = ($one);
9462: my $withsec = 1;
9463: my %roleshash =
9464: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9465: \@statuses,\@roles,\@roledoms,$withsec);
9466: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9467: my ($oldstart,$oldend) =
9468: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9469: if ($oldend > 0 && $oldend <= $now) {
9470: $expire_role_result = 'ok';
9471: }
9472: }
9473: }
9474: }
1.443 albertel 9475: $result = $expire_role_result;
9476: }
9477: }
9478: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9479: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9480: if ($modify_section_result =~ /^ok/) {
9481: if ($secchange == 1) {
1.628 raeburn 9482: if ($sec eq '') {
9483: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9484: } else {
9485: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9486: }
1.443 albertel 9487: } elsif ($oldsec eq '-1') {
1.628 raeburn 9488: if ($sec eq '') {
9489: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9490: } else {
9491: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9492: }
1.443 albertel 9493: } else {
1.628 raeburn 9494: if ($sec eq '') {
9495: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9496: } else {
9497: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9498: }
1.443 albertel 9499: }
9500: } else {
1.628 raeburn 9501: if ($secchange) {
9502: $$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;
9503: } else {
9504: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9505: }
1.443 albertel 9506: }
9507: $result = $modify_section_result;
9508: } elsif ($secchange == 1) {
1.628 raeburn 9509: if ($oldsec eq '') {
9510: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9511: } else {
9512: $$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;
9513: }
1.626 raeburn 9514: if ($expire_role_result eq 'refused') {
9515: my $newsecurl = '/'.$cid;
9516: $newsecurl =~ s/\_/\//g;
9517: if ($sec ne '') {
9518: $newsecurl.='/'.$sec;
9519: }
9520: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9521: if ($sec eq '') {
9522: $$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;
9523: } else {
9524: $$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;
9525: }
9526: }
9527: }
1.443 albertel 9528: }
9529: } else {
1.626 raeburn 9530: $$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 9531: $result = "error: incomplete course id\n";
9532: }
9533: return $result;
9534: }
9535:
9536: ############################################################
9537: ############################################################
9538:
1.566 albertel 9539: sub check_clone {
1.578 raeburn 9540: my ($args,$linefeed) = @_;
1.566 albertel 9541: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9542: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9543: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9544: my $clonemsg;
9545: my $can_clone = 0;
9546:
9547: if ($clonehome eq 'no_host') {
1.578 raeburn 9548: $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 9549: } else {
9550: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9551: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9552: $can_clone = 1;
9553: } else {
9554: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9555: $args->{'clonedomain'},$args->{'clonecourse'});
9556: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9557: if (grep(/^\*$/,@cloners)) {
9558: $can_clone = 1;
9559: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9560: $can_clone = 1;
9561: } else {
9562: my %roleshash =
9563: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9564: $args->{'ccdomain'},
9565: 'userroles',['active'],['cc'],
9566: [$args->{'clonedomain'}]);
9567: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9568: $can_clone = 1;
9569: } else {
9570: $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'});
9571: }
1.566 albertel 9572: }
1.578 raeburn 9573: }
1.566 albertel 9574: }
9575: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9576: }
9577:
1.444 albertel 9578: sub construct_course {
1.541 raeburn 9579: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9580: my $outcome;
1.541 raeburn 9581: my $linefeed = '<br />'."\n";
9582: if ($context eq 'auto') {
9583: $linefeed = "\n";
9584: }
1.566 albertel 9585:
9586: #
9587: # Are we cloning?
9588: #
9589: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9590: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9591: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9592: if ($context ne 'auto') {
1.578 raeburn 9593: if ($clonemsg ne '') {
9594: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9595: }
1.566 albertel 9596: }
9597: $outcome .= $clonemsg.$linefeed;
9598:
9599: if (!$can_clone) {
9600: return (0,$outcome);
9601: }
9602: }
9603:
1.444 albertel 9604: #
9605: # Open course
9606: #
9607: my $crstype = lc($args->{'crstype'});
9608: my %cenv=();
9609: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9610: $args->{'cdescr'},
9611: $args->{'curl'},
9612: $args->{'course_home'},
9613: $args->{'nonstandard'},
9614: $args->{'crscode'},
9615: $args->{'ccuname'}.':'.
9616: $args->{'ccdomain'},
9617: $args->{'crstype'});
9618:
9619: # Note: The testing routines depend on this being output; see
9620: # Utils::Course. This needs to at least be output as a comment
9621: # if anyone ever decides to not show this, and Utils::Course::new
9622: # will need to be suitably modified.
1.541 raeburn 9623: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9624: #
9625: # Check if created correctly
9626: #
1.479 albertel 9627: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9628: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9629: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9630:
1.444 albertel 9631: #
1.566 albertel 9632: # Do the cloning
9633: #
9634: if ($can_clone && $cloneid) {
9635: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9636: if ($context ne 'auto') {
9637: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9638: }
9639: $outcome .= $clonemsg.$linefeed;
9640: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9641: # Copy all files
1.637 www 9642: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9643: # Restore URL
1.566 albertel 9644: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9645: # Restore title
1.566 albertel 9646: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9647: # Mark as cloned
1.566 albertel 9648: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9649: # Need to clone grading mode
9650: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9651: $cenv{'grading'}=$newenv{'grading'};
9652: # Do not clone these environment entries
9653: &Apache::lonnet::del('environment',
9654: ['default_enrollment_start_date',
9655: 'default_enrollment_end_date',
9656: 'question.email',
9657: 'policy.email',
9658: 'comment.email',
9659: 'pch.users.denied',
1.725 raeburn 9660: 'plc.users.denied',
9661: 'hidefromcat',
9662: 'categories'],
1.638 www 9663: $$crsudom,$$crsunum);
1.444 albertel 9664: }
1.566 albertel 9665:
1.444 albertel 9666: #
9667: # Set environment (will override cloned, if existing)
9668: #
9669: my @sections = ();
9670: my @xlists = ();
9671: if ($args->{'crstype'}) {
9672: $cenv{'type'}=$args->{'crstype'};
9673: }
9674: if ($args->{'crsid'}) {
9675: $cenv{'courseid'}=$args->{'crsid'};
9676: }
9677: if ($args->{'crscode'}) {
9678: $cenv{'internal.coursecode'}=$args->{'crscode'};
9679: }
9680: if ($args->{'crsquota'} ne '') {
9681: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9682: } else {
9683: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9684: }
9685: if ($args->{'ccuname'}) {
9686: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9687: ':'.$args->{'ccdomain'};
9688: } else {
9689: $cenv{'internal.courseowner'} = $args->{'curruser'};
9690: }
9691: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9692: if ($args->{'crssections'}) {
9693: $cenv{'internal.sectionnums'} = '';
9694: if ($args->{'crssections'} =~ m/,/) {
9695: @sections = split/,/,$args->{'crssections'};
9696: } else {
9697: $sections[0] = $args->{'crssections'};
9698: }
9699: if (@sections > 0) {
9700: foreach my $item (@sections) {
9701: my ($sec,$gp) = split/:/,$item;
9702: my $class = $args->{'crscode'}.$sec;
9703: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9704: $cenv{'internal.sectionnums'} .= $item.',';
9705: unless ($addcheck eq 'ok') {
9706: push @badclasses, $class;
9707: }
9708: }
9709: $cenv{'internal.sectionnums'} =~ s/,$//;
9710: }
9711: }
9712: # do not hide course coordinator from staff listing,
9713: # even if privileged
9714: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9715: # add crosslistings
9716: if ($args->{'crsxlist'}) {
9717: $cenv{'internal.crosslistings'}='';
9718: if ($args->{'crsxlist'} =~ m/,/) {
9719: @xlists = split/,/,$args->{'crsxlist'};
9720: } else {
9721: $xlists[0] = $args->{'crsxlist'};
9722: }
9723: if (@xlists > 0) {
9724: foreach my $item (@xlists) {
9725: my ($xl,$gp) = split/:/,$item;
9726: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9727: $cenv{'internal.crosslistings'} .= $item.',';
9728: unless ($addcheck eq 'ok') {
9729: push @badclasses, $xl;
9730: }
9731: }
9732: $cenv{'internal.crosslistings'} =~ s/,$//;
9733: }
9734: }
9735: if ($args->{'autoadds'}) {
9736: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9737: }
9738: if ($args->{'autodrops'}) {
9739: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9740: }
9741: # check for notification of enrollment changes
9742: my @notified = ();
9743: if ($args->{'notify_owner'}) {
9744: if ($args->{'ccuname'} ne '') {
9745: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9746: }
9747: }
9748: if ($args->{'notify_dc'}) {
9749: if ($uname ne '') {
1.630 raeburn 9750: push(@notified,$uname.':'.$udom);
1.444 albertel 9751: }
9752: }
9753: if (@notified > 0) {
9754: my $notifylist;
9755: if (@notified > 1) {
9756: $notifylist = join(',',@notified);
9757: } else {
9758: $notifylist = $notified[0];
9759: }
9760: $cenv{'internal.notifylist'} = $notifylist;
9761: }
9762: if (@badclasses > 0) {
9763: my %lt=&Apache::lonlocal::texthash(
9764: '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',
9765: 'dnhr' => 'does not have rights to access enrollment in these classes',
9766: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9767: );
1.541 raeburn 9768: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9769: ' ('.$lt{'adby'}.')';
9770: if ($context eq 'auto') {
9771: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9772: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9773: foreach my $item (@badclasses) {
9774: if ($context eq 'auto') {
9775: $outcome .= " - $item\n";
9776: } else {
9777: $outcome .= "<li>$item</li>\n";
9778: }
9779: }
9780: if ($context eq 'auto') {
9781: $outcome .= $linefeed;
9782: } else {
1.566 albertel 9783: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9784: }
9785: }
1.444 albertel 9786: }
9787: if ($args->{'no_end_date'}) {
9788: $args->{'endaccess'} = 0;
9789: }
9790: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9791: $cenv{'internal.autoend'}=$args->{'enrollend'};
9792: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9793: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9794: if ($args->{'showphotos'}) {
9795: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9796: }
9797: $cenv{'internal.authtype'} = $args->{'authtype'};
9798: $cenv{'internal.autharg'} = $args->{'autharg'};
9799: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9800: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9801: 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');
9802: if ($context eq 'auto') {
9803: $outcome .= $krb_msg;
9804: } else {
1.566 albertel 9805: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9806: }
9807: $outcome .= $linefeed;
1.444 albertel 9808: }
9809: }
9810: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9811: if ($args->{'setpolicy'}) {
9812: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9813: }
9814: if ($args->{'setcontent'}) {
9815: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9816: }
9817: }
9818: if ($args->{'reshome'}) {
9819: $cenv{'reshome'}=$args->{'reshome'}.'/';
9820: $cenv{'reshome'}=~s/\/+$/\//;
9821: }
9822: #
9823: # course has keyed access
9824: #
9825: if ($args->{'setkeys'}) {
9826: $cenv{'keyaccess'}='yes';
9827: }
9828: # if specified, key authority is not course, but user
9829: # only active if keyaccess is yes
9830: if ($args->{'keyauth'}) {
1.487 albertel 9831: my ($user,$domain) = split(':',$args->{'keyauth'});
9832: $user = &LONCAPA::clean_username($user);
9833: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9834: if ($user ne '' && $domain ne '') {
1.487 albertel 9835: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9836: }
9837: }
9838:
9839: if ($args->{'disresdis'}) {
9840: $cenv{'pch.roles.denied'}='st';
9841: }
9842: if ($args->{'disablechat'}) {
9843: $cenv{'plc.roles.denied'}='st';
9844: }
9845:
9846: # Record we've not yet viewed the Course Initialization Helper for this
9847: # course
9848: $cenv{'course.helper.not.run'} = 1;
9849: #
9850: # Use new Randomseed
9851: #
9852: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9853: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9854: #
9855: # The encryption code and receipt prefix for this course
9856: #
9857: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9858: $cenv{'internal.encpref'}=100+int(9*rand(99));
9859: #
9860: # By default, use standard grading
9861: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9862:
1.541 raeburn 9863: $outcome .= $linefeed.&mt('Setting environment').': '.
9864: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9865: #
9866: # Open all assignments
9867: #
9868: if ($args->{'openall'}) {
9869: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9870: my %storecontent = ($storeunder => time,
9871: $storeunder.'.type' => 'date_start');
9872:
9873: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9874: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9875: }
9876: #
9877: # Set first page
9878: #
9879: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9880: || ($cloneid)) {
1.445 albertel 9881: use LONCAPA::map;
1.444 albertel 9882: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9883:
9884: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9885: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9886:
1.444 albertel 9887: $outcome .= ($fatal?$errtext:'read ok').' - ';
9888: my $title; my $url;
9889: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9890: $title=&mt('Syllabus');
1.444 albertel 9891: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9892: } else {
1.690 bisitz 9893: $title=&mt('Navigate Contents');
1.444 albertel 9894: $url='/adm/navmaps';
9895: }
1.445 albertel 9896:
9897: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9898: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9899:
9900: if ($errtext) { $fatal=2; }
1.541 raeburn 9901: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9902: }
1.566 albertel 9903:
9904: return (1,$outcome);
1.444 albertel 9905: }
9906:
9907: ############################################################
9908: ############################################################
9909:
1.378 raeburn 9910: sub course_type {
9911: my ($cid) = @_;
9912: if (!defined($cid)) {
9913: $cid = $env{'request.course.id'};
9914: }
1.404 albertel 9915: if (defined($env{'course.'.$cid.'.type'})) {
9916: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9917: } else {
9918: return 'Course';
1.377 raeburn 9919: }
9920: }
1.156 albertel 9921:
1.406 raeburn 9922: sub group_term {
9923: my $crstype = &course_type();
9924: my %names = (
9925: 'Course' => 'group',
9926: 'Group' => 'team',
9927: );
9928: return $names{$crstype};
9929: }
9930:
1.156 albertel 9931: sub icon {
9932: my ($file)=@_;
1.505 albertel 9933: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9934: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9935: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9936: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9937: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9938: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9939: $curfext.".gif") {
9940: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9941: $curfext.".gif";
9942: }
9943: }
1.249 albertel 9944: return &lonhttpdurl($iconname);
1.154 albertel 9945: }
1.84 albertel 9946:
1.575 albertel 9947: sub lonhttpdurl {
1.692 www 9948: #
9949: # Had been used for "small fry" static images on separate port 8080.
9950: # Modify here if lightweight http functionality desired again.
9951: # Currently eliminated due to increasing firewall issues.
9952: #
1.575 albertel 9953: my ($url)=@_;
1.692 www 9954: return $url;
1.215 albertel 9955: }
9956:
1.213 albertel 9957: sub connection_aborted {
9958: my ($r)=@_;
9959: $r->print(" ");$r->rflush();
9960: my $c = $r->connection;
9961: return $c->aborted();
9962: }
9963:
1.221 foxr 9964: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9965: # strings as 'strings'.
9966: sub escape_single {
1.221 foxr 9967: my ($input) = @_;
1.223 albertel 9968: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9969: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9970: return $input;
9971: }
1.223 albertel 9972:
1.222 foxr 9973: # Same as escape_single, but escape's "'s This
9974: # can be used for "strings"
9975: sub escape_double {
9976: my ($input) = @_;
9977: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9978: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9979: return $input;
9980: }
1.223 albertel 9981:
1.222 foxr 9982: # Escapes the last element of a full URL.
9983: sub escape_url {
9984: my ($url) = @_;
1.238 raeburn 9985: my @urlslices = split(/\//, $url,-1);
1.369 www 9986: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9987: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9988: }
1.462 albertel 9989:
9990: # -------------------------------------------------------- Initliaze user login
9991: sub init_user_environment {
1.463 albertel 9992: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9993: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9994:
9995: my $public=($username eq 'public' && $domain eq 'public');
9996:
9997: # See if old ID present, if so, remove
9998:
9999: my ($filename,$cookie,$userroles);
10000: my $now=time;
10001:
10002: if ($public) {
10003: my $max_public=100;
10004: my $oldest;
10005: my $oldest_time=0;
10006: for(my $next=1;$next<=$max_public;$next++) {
10007: if (-e $lonids."/publicuser_$next.id") {
10008: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10009: if ($mtime<$oldest_time || !$oldest_time) {
10010: $oldest_time=$mtime;
10011: $oldest=$next;
10012: }
10013: } else {
10014: $cookie="publicuser_$next";
10015: last;
10016: }
10017: }
10018: if (!$cookie) { $cookie="publicuser_$oldest"; }
10019: } else {
1.463 albertel 10020: # if this isn't a robot, kill any existing non-robot sessions
10021: if (!$args->{'robot'}) {
10022: opendir(DIR,$lonids);
10023: while ($filename=readdir(DIR)) {
10024: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10025: unlink($lonids.'/'.$filename);
10026: }
1.462 albertel 10027: }
1.463 albertel 10028: closedir(DIR);
1.462 albertel 10029: }
10030: # Give them a new cookie
1.463 albertel 10031: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10032: : $now.$$.int(rand(10000)));
1.463 albertel 10033: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10034:
10035: # Initialize roles
10036:
10037: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10038: }
10039: # ------------------------------------ Check browser type and MathML capability
10040:
10041: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10042: $clientunicode,$clientos) = &decode_user_agent($r);
10043:
10044: # -------------------------------------- Any accessibility options to remember?
10045: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
10046: foreach my $option ('imagesuppress','appletsuppress',
10047: 'embedsuppress','fontenhance','blackwhite') {
10048: if ($form->{$option} eq 'true') {
10049: &Apache::lonnet::put('environment',{$option => 'on'},
10050: $domain,$username);
10051: } else {
10052: &Apache::lonnet::del('environment',[$option],
10053: $domain,$username);
10054: }
10055: }
10056: }
10057: # ------------------------------------------------------------- Get environment
10058:
10059: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10060: my ($tmp) = keys(%userenv);
10061: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10062: # default remote control to off
10063: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10064: } else {
10065: undef(%userenv);
10066: }
10067: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10068: $form->{'interface'}=$userenv{'interface'};
10069: }
10070: $env{'environment.remote'}=$userenv{'remote'};
10071: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10072:
10073: # --------------- Do not trust query string to be put directly into environment
10074: foreach my $option ('imagesuppress','appletsuppress',
10075: 'embedsuppress','fontenhance','blackwhite',
10076: 'interface','localpath','localres') {
10077: $form->{$option}=~s/[\n\r\=]//gs;
10078: }
10079: # --------------------------------------------------------- Write first profile
10080:
10081: {
10082: my %initial_env =
10083: ("user.name" => $username,
10084: "user.domain" => $domain,
10085: "user.home" => $authhost,
10086: "browser.type" => $clientbrowser,
10087: "browser.version" => $clientversion,
10088: "browser.mathml" => $clientmathml,
10089: "browser.unicode" => $clientunicode,
10090: "browser.os" => $clientos,
10091: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10092: "request.course.fn" => '',
10093: "request.course.uri" => '',
10094: "request.course.sec" => '',
10095: "request.role" => 'cm',
10096: "request.role.adv" => $env{'user.adv'},
10097: "request.host" => $ENV{'REMOTE_ADDR'},);
10098:
10099: if ($form->{'localpath'}) {
10100: $initial_env{"browser.localpath"} = $form->{'localpath'};
10101: $initial_env{"browser.localres"} = $form->{'localres'};
10102: }
10103:
10104: if ($public) {
10105: $initial_env{"environment.remote"} = "off";
10106: }
10107: if ($form->{'interface'}) {
10108: $form->{'interface'}=~s/\W//gs;
10109: $initial_env{"browser.interface"} = $form->{'interface'};
10110: $env{'browser.interface'}=$form->{'interface'};
10111: foreach my $option ('imagesuppress','appletsuppress',
10112: 'embedsuppress','fontenhance','blackwhite') {
10113: if (($form->{$option} eq 'true') ||
10114: ($userenv{$option} eq 'on')) {
10115: $initial_env{"browser.$option"} = "on";
10116: }
10117: }
10118: }
10119:
1.724 raeburn 10120: foreach my $tool ('aboutme','blog','portfolio') {
10121: $userenv{'availabletools.'.$tool} =
10122: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10123: }
10124:
1.765 raeburn 10125: foreach my $crstype ('official','unofficial') {
10126: $userenv{'canrequest.'.$crstype} =
10127: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10128: 'reload','requestcourses');
10129: }
10130:
1.462 albertel 10131: $env{'user.environment'} = "$lonids/$cookie.id";
10132:
10133: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10134: &GDBM_WRCREAT(),0640)) {
10135: &_add_to_env(\%disk_env,\%initial_env);
10136: &_add_to_env(\%disk_env,\%userenv,'environment.');
10137: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10138: if (ref($args->{'extra_env'})) {
10139: &_add_to_env(\%disk_env,$args->{'extra_env'});
10140: }
1.462 albertel 10141: untie(%disk_env);
10142: } else {
1.705 tempelho 10143: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10144: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10145: return 'error: '.$!;
10146: }
10147: }
10148: $env{'request.role'}='cm';
10149: $env{'request.role.adv'}=$env{'user.adv'};
10150: $env{'browser.type'}=$clientbrowser;
10151:
10152: return $cookie;
10153:
10154: }
10155:
10156: sub _add_to_env {
10157: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10158: if (ref($env_data) eq 'HASH') {
10159: while (my ($key,$value) = each(%$env_data)) {
10160: $idf->{$prefix.$key} = $value;
10161: $env{$prefix.$key} = $value;
10162: }
1.462 albertel 10163: }
10164: }
10165:
1.685 tempelho 10166: # --- Get the symbolic name of a problem and the url
10167: sub get_symb {
10168: my ($request,$silent) = @_;
1.726 raeburn 10169: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10170: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10171: if ($symb eq '') {
10172: if (!$silent) {
10173: $request->print("Unable to handle ambiguous references:$url:.");
10174: return ();
10175: }
10176: }
10177: &Apache::lonenc::check_decrypt(\$symb);
10178: return ($symb);
10179: }
10180:
10181: # --------------------------------------------------------------Get annotation
10182:
10183: sub get_annotation {
10184: my ($symb,$enc) = @_;
10185:
10186: my $key = $symb;
10187: if (!$enc) {
10188: $key =
10189: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10190: }
10191: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10192: return $annotation{$key};
10193: }
10194:
10195: sub clean_symb {
1.731 raeburn 10196: my ($symb,$delete_enc) = @_;
1.685 tempelho 10197:
10198: &Apache::lonenc::check_decrypt(\$symb);
10199: my $enc = $env{'request.enc'};
1.731 raeburn 10200: if ($delete_enc) {
1.730 raeburn 10201: delete($env{'request.enc'});
10202: }
1.685 tempelho 10203:
10204: return ($symb,$enc);
10205: }
1.462 albertel 10206:
1.41 ng 10207: =pod
10208:
10209: =back
10210:
1.112 bowersj2 10211: =cut
1.41 ng 10212:
1.112 bowersj2 10213: 1;
10214: __END__;
1.41 ng 10215:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>