Annotation of loncom/interface/loncommon.pm, revision 1.798
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.798 ! tempelho 4: # $Id: loncommon.pm,v 1.797 2009/04/25 21:35:13 www 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);
934: $width = 350 if (not defined $width);
935: $height = 400 if (not defined $height);
936: my $filename = $topic;
937: $filename =~ s/ /_/g;
938:
1.48 bowersj2 939: my $template = "";
940: my $link;
1.572 banghart 941:
1.159 www 942: $topic=~s/\W/\_/g;
1.44 bowersj2 943:
1.572 banghart 944: if (!$stayOnPage) {
1.72 bowersj2 945: $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 946: } else {
1.48 bowersj2 947: $link = "/adm/help/${filename}.hlp";
948: }
949:
950: # Add the text
1.755 neumanie 951: if ($text ne "") {
1.763 bisitz 952: $template.='<span class="LC_help_open_topic">'
953: .'<a target="_top" href="'.$link.'">'
954: .$text.'</a>';
1.48 bowersj2 955: }
956:
1.763 bisitz 957: # (Always) Add the graphic
1.179 matthew 958: my $title = &mt('Online Help');
1.667 raeburn 959: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 960: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
961: .'<img src="'.$helpicon.'" border="0"'
962: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 963: .' title="'.$title.'"'
1.763 bisitz 964: .' /></a>';
965: if ($text ne "") {
966: $template.='</span>';
967: }
1.44 bowersj2 968: return $template;
969:
1.106 bowersj2 970: }
971:
972: # This is a quicky function for Latex cheatsheet editing, since it
973: # appears in at least four places
974: sub helpLatexCheatsheet {
1.732 raeburn 975: my ($topic,$text,$not_author) = @_;
976: my $out;
1.106 bowersj2 977: my $addOther = '';
1.732 raeburn 978: if ($topic) {
1.763 bisitz 979: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
980: undef, undef, 600).
981: '</span> ';
982: }
983: $out = '<span>' # Start cheatsheet
984: .$addOther
985: .'<span>'
986: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
987: undef,undef,600)
988: .'</span> <span>'
989: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
990: undef,undef,600)
991: .'</span>';
1.732 raeburn 992: unless ($not_author) {
1.763 bisitz 993: $out .= ' <span>'
994: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
995: undef,undef,600)
996: .'</span>';
1.732 raeburn 997: }
1.763 bisitz 998: $out .= '</span>'; # End cheatsheet
1.732 raeburn 999: return $out;
1.172 www 1000: }
1001:
1.430 albertel 1002: sub general_help {
1003: my $helptopic='Student_Intro';
1004: if ($env{'request.role'}=~/^(ca|au)/) {
1005: $helptopic='Authoring_Intro';
1006: } elsif ($env{'request.role'}=~/^cc/) {
1007: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1008: } elsif ($env{'request.role'}=~/^dc/) {
1009: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1010: }
1011: return $helptopic;
1012: }
1013:
1014: sub update_help_link {
1015: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1016: my $origurl = $ENV{'REQUEST_URI'};
1017: $origurl=~s|^/~|/priv/|;
1018: my $timestamp = time;
1019: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1020: $$datum = &escape($$datum);
1021: }
1022:
1023: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1024: my $output .= <<"ENDOUTPUT";
1025: <script type="text/javascript">
1026: banner_link = '$banner_link';
1027: </script>
1028: ENDOUTPUT
1029: return $output;
1030: }
1031:
1032: # now just updates the help link and generates a blue icon
1.193 raeburn 1033: sub help_open_menu {
1.430 albertel 1034: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1035: = @_;
1.430 albertel 1036: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1037: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1038: # if environment.remote is on (using remote control UI)
1.798 ! tempelho 1039: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1040: $stayOnPage=1;
1.430 albertel 1041: }
1042: my $output;
1043: if ($component_help) {
1044: if (!$text) {
1045: $output=&help_open_topic($component_help,undef,$stayOnPage,
1046: $width,$height);
1047: } else {
1048: my $help_text;
1049: $help_text=&unescape($topic);
1050: $output='<table><tr><td>'.
1051: &help_open_topic($component_help,$help_text,$stayOnPage,
1052: $width,$height).'</td></tr></table>';
1053: }
1054: }
1055: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1056: return $output.$banner_link;
1057: }
1058:
1059: sub top_nav_help {
1060: my ($text) = @_;
1.436 albertel 1061: $text = &mt($text);
1.572 banghart 1062: my $stay_on_page =
1.798 ! tempelho 1063: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1064: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1065: : "javascript:helpMenu('open')";
1.572 banghart 1066: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1067:
1.201 raeburn 1068: my $title = &mt('Get help');
1.436 albertel 1069:
1070: return <<"END";
1071: $banner_link
1072: <a href="$link" title="$title">$text</a>
1073: END
1074: }
1075:
1076: sub help_menu_js {
1077: my ($text) = @_;
1078:
1079: my $stayOnPage =
1.798 ! tempelho 1080: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1081:
1082: my $width = 620;
1083: my $height = 600;
1.430 albertel 1084: my $helptopic=&general_help();
1085: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1086: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1087: my $start_page =
1088: &Apache::loncommon::start_page('Help Menu', undef,
1089: {'frameset' => 1,
1090: 'js_ready' => 1,
1091: 'add_entries' => {
1092: 'border' => '0',
1.579 raeburn 1093: 'rows' => "110,*",},});
1.331 albertel 1094: my $end_page =
1095: &Apache::loncommon::end_page({'frameset' => 1,
1096: 'js_ready' => 1,});
1097:
1.436 albertel 1098: my $template .= <<"ENDTEMPLATE";
1099: <script type="text/javascript">
1.253 albertel 1100: // <!-- BEGIN LON-CAPA Internal
1101: // <![CDATA[
1.430 albertel 1102: var banner_link = '';
1.243 raeburn 1103: function helpMenu(target) {
1104: var caller = this;
1105: if (target == 'open') {
1106: var newWindow = null;
1107: try {
1.262 albertel 1108: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1109: }
1110: catch(error) {
1111: writeHelp(caller);
1112: return;
1113: }
1114: if (newWindow) {
1115: caller = newWindow;
1116: }
1.193 raeburn 1117: }
1.243 raeburn 1118: writeHelp(caller);
1119: return;
1120: }
1121: function writeHelp(caller) {
1.430 albertel 1122: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1123: caller.document.close()
1124: caller.focus()
1.193 raeburn 1125: }
1.253 albertel 1126: // ]]>
1.219 albertel 1127: // END LON-CAPA Internal -->
1.436 albertel 1128: </script>
1.193 raeburn 1129: ENDTEMPLATE
1130: return $template;
1131: }
1132:
1.172 www 1133: sub help_open_bug {
1134: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1135: unless ($env{'user.adv'}) { return ''; }
1.172 www 1136: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1137: $text = "" if (not defined $text);
1138: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 ! tempelho 1139: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1140: $stayOnPage=1;
1141: }
1.184 albertel 1142: $width = 600 if (not defined $width);
1143: $height = 600 if (not defined $height);
1.172 www 1144:
1145: $topic=~s/\W+/\+/g;
1146: my $link='';
1147: my $template='';
1.379 albertel 1148: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1149: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1150: if (!$stayOnPage)
1151: {
1152: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1153: }
1154: else
1155: {
1156: $link = $url;
1157: }
1158: # Add the text
1159: if ($text ne "")
1160: {
1161: $template .=
1162: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1163: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1164: }
1165:
1166: # Add the graphic
1.179 matthew 1167: my $title = &mt('Report a Bug');
1.215 albertel 1168: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1169: $template .= <<"ENDTEMPLATE";
1.436 albertel 1170: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1171: ENDTEMPLATE
1172: if ($text ne '') { $template.='</td></tr></table>' };
1173: return $template;
1174:
1175: }
1176:
1177: sub help_open_faq {
1178: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1179: unless ($env{'user.adv'}) { return ''; }
1.172 www 1180: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1181: $text = "" if (not defined $text);
1182: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 ! tempelho 1183: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1184: $stayOnPage=1;
1185: }
1186: $width = 350 if (not defined $width);
1187: $height = 400 if (not defined $height);
1188:
1189: $topic=~s/\W+/\+/g;
1190: my $link='';
1191: my $template='';
1192: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1193: if (!$stayOnPage)
1194: {
1195: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1196: }
1197: else
1198: {
1199: $link = $url;
1200: }
1201:
1202: # Add the text
1203: if ($text ne "")
1204: {
1205: $template .=
1.173 www 1206: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1207: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1208: }
1209:
1210: # Add the graphic
1.179 matthew 1211: my $title = &mt('View the FAQ');
1.215 albertel 1212: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1213: $template .= <<"ENDTEMPLATE";
1.436 albertel 1214: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1215: ENDTEMPLATE
1216: if ($text ne '') { $template.='</td></tr></table>' };
1217: return $template;
1218:
1.44 bowersj2 1219: }
1.37 matthew 1220:
1.180 matthew 1221: ###############################################################
1222: ###############################################################
1223:
1.45 matthew 1224: =pod
1225:
1.648 raeburn 1226: =item * &change_content_javascript():
1.256 matthew 1227:
1228: This and the next function allow you to create small sections of an
1229: otherwise static HTML page that you can update on the fly with
1230: Javascript, even in Netscape 4.
1231:
1232: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1233: must be written to the HTML page once. It will prove the Javascript
1234: function "change(name, content)". Calling the change function with the
1235: name of the section
1236: you want to update, matching the name passed to C<changable_area>, and
1237: the new content you want to put in there, will put the content into
1238: that area.
1239:
1240: B<Note>: Netscape 4 only reserves enough space for the changable area
1241: to contain room for the original contents. You need to "make space"
1242: for whatever changes you wish to make, and be B<sure> to check your
1243: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1244: it's adequate for updating a one-line status display, but little more.
1245: This script will set the space to 100% width, so you only need to
1246: worry about height in Netscape 4.
1247:
1248: Modern browsers are much less limiting, and if you can commit to the
1249: user not using Netscape 4, this feature may be used freely with
1250: pretty much any HTML.
1251:
1252: =cut
1253:
1254: sub change_content_javascript {
1255: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1256: if ($env{'browser.type'} eq 'netscape' &&
1257: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1258: return (<<NETSCAPE4);
1259: function change(name, content) {
1260: doc = document.layers[name+"___escape"].layers[0].document;
1261: doc.open();
1262: doc.write(content);
1263: doc.close();
1264: }
1265: NETSCAPE4
1266: } else {
1267: # Otherwise, we need to use semi-standards-compliant code
1268: # (technically, "innerHTML" isn't standard but the equivalent
1269: # is really scary, and every useful browser supports it
1270: return (<<DOMBASED);
1271: function change(name, content) {
1272: element = document.getElementById(name);
1273: element.innerHTML = content;
1274: }
1275: DOMBASED
1276: }
1277: }
1278:
1279: =pod
1280:
1.648 raeburn 1281: =item * &changable_area($name,$origContent):
1.256 matthew 1282:
1283: This provides a "changable area" that can be modified on the fly via
1284: the Javascript code provided in C<change_content_javascript>. $name is
1285: the name you will use to reference the area later; do not repeat the
1286: same name on a given HTML page more then once. $origContent is what
1287: the area will originally contain, which can be left blank.
1288:
1289: =cut
1290:
1291: sub changable_area {
1292: my ($name, $origContent) = @_;
1293:
1.258 albertel 1294: if ($env{'browser.type'} eq 'netscape' &&
1295: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1296: # If this is netscape 4, we need to use the Layer tag
1297: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1298: } else {
1299: return "<span id='$name'>$origContent</span>";
1300: }
1301: }
1302:
1303: =pod
1304:
1.648 raeburn 1305: =item * &viewport_geometry_js
1.590 raeburn 1306:
1307: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1308:
1309: =cut
1310:
1311:
1312: sub viewport_geometry_js {
1313: return <<"GEOMETRY";
1314: var Geometry = {};
1315: function init_geometry() {
1316: if (Geometry.init) { return };
1317: Geometry.init=1;
1318: if (window.innerHeight) {
1319: Geometry.getViewportHeight = function() { return window.innerHeight; };
1320: Geometry.getViewportWidth = function() { return window.innerWidth; };
1321: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1322: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1323: }
1324: else if (document.documentElement && document.documentElement.clientHeight) {
1325: Geometry.getViewportHeight =
1326: function() { return document.documentElement.clientHeight; };
1327: Geometry.getViewportWidth =
1328: function() { return document.documentElement.clientWidth; };
1329:
1330: Geometry.getHorizontalScroll =
1331: function() { return document.documentElement.scrollLeft; };
1332: Geometry.getVerticalScroll =
1333: function() { return document.documentElement.scrollTop; };
1334: }
1335: else if (document.body.clientHeight) {
1336: Geometry.getViewportHeight =
1337: function() { return document.body.clientHeight; };
1338: Geometry.getViewportWidth =
1339: function() { return document.body.clientWidth; };
1340: Geometry.getHorizontalScroll =
1341: function() { return document.body.scrollLeft; };
1342: Geometry.getVerticalScroll =
1343: function() { return document.body.scrollTop; };
1344: }
1345: }
1346:
1347: GEOMETRY
1348: }
1349:
1350: =pod
1351:
1.648 raeburn 1352: =item * &viewport_size_js()
1.590 raeburn 1353:
1354: 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.
1355:
1356: =cut
1357:
1358: sub viewport_size_js {
1359: my $geometry = &viewport_geometry_js();
1360: return <<"DIMS";
1361:
1362: $geometry
1363:
1364: function getViewportDims(width,height) {
1365: init_geometry();
1366: width.value = Geometry.getViewportWidth();
1367: height.value = Geometry.getViewportHeight();
1368: return;
1369: }
1370:
1371: DIMS
1372: }
1373:
1374: =pod
1375:
1.648 raeburn 1376: =item * &resize_textarea_js()
1.565 albertel 1377:
1378: emits the needed javascript to resize a textarea to be as big as possible
1379:
1380: creates a function resize_textrea that takes two IDs first should be
1381: the id of the element to resize, second should be the id of a div that
1382: surrounds everything that comes after the textarea, this routine needs
1383: to be attached to the <body> for the onload and onresize events.
1384:
1.648 raeburn 1385: =back
1.565 albertel 1386:
1387: =cut
1388:
1389: sub resize_textarea_js {
1.590 raeburn 1390: my $geometry = &viewport_geometry_js();
1.565 albertel 1391: return <<"RESIZE";
1392: <script type="text/javascript">
1.590 raeburn 1393: $geometry
1.565 albertel 1394:
1.588 albertel 1395: function getX(element) {
1396: var x = 0;
1397: while (element) {
1398: x += element.offsetLeft;
1399: element = element.offsetParent;
1400: }
1401: return x;
1402: }
1403: function getY(element) {
1404: var y = 0;
1405: while (element) {
1406: y += element.offsetTop;
1407: element = element.offsetParent;
1408: }
1409: return y;
1410: }
1411:
1412:
1.565 albertel 1413: function resize_textarea(textarea_id,bottom_id) {
1414: init_geometry();
1415: var textarea = document.getElementById(textarea_id);
1416: //alert(textarea);
1417:
1.588 albertel 1418: var textarea_top = getY(textarea);
1.565 albertel 1419: var textarea_height = textarea.offsetHeight;
1420: var bottom = document.getElementById(bottom_id);
1.588 albertel 1421: var bottom_top = getY(bottom);
1.565 albertel 1422: var bottom_height = bottom.offsetHeight;
1423: var window_height = Geometry.getViewportHeight();
1.588 albertel 1424: var fudge = 23;
1.565 albertel 1425: var new_height = window_height-fudge-textarea_top-bottom_height;
1426: if (new_height < 300) {
1427: new_height = 300;
1428: }
1429: textarea.style.height=new_height+'px';
1430: }
1431: </script>
1432: RESIZE
1433:
1434: }
1435:
1436: =pod
1437:
1.256 matthew 1438: =head1 Excel and CSV file utility routines
1439:
1440: =over 4
1441:
1442: =cut
1443:
1444: ###############################################################
1445: ###############################################################
1446:
1447: =pod
1448:
1.648 raeburn 1449: =item * &csv_translate($text)
1.37 matthew 1450:
1.185 www 1451: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1452: format.
1453:
1454: =cut
1455:
1.180 matthew 1456: ###############################################################
1457: ###############################################################
1.37 matthew 1458: sub csv_translate {
1459: my $text = shift;
1460: $text =~ s/\"/\"\"/g;
1.209 albertel 1461: $text =~ s/\n/ /g;
1.37 matthew 1462: return $text;
1463: }
1.180 matthew 1464:
1465: ###############################################################
1466: ###############################################################
1467:
1468: =pod
1469:
1.648 raeburn 1470: =item * &define_excel_formats()
1.180 matthew 1471:
1472: Define some commonly used Excel cell formats.
1473:
1474: Currently supported formats:
1475:
1476: =over 4
1477:
1478: =item header
1479:
1480: =item bold
1481:
1482: =item h1
1483:
1484: =item h2
1485:
1486: =item h3
1487:
1.256 matthew 1488: =item h4
1489:
1490: =item i
1491:
1.180 matthew 1492: =item date
1493:
1494: =back
1495:
1496: Inputs: $workbook
1497:
1498: Returns: $format, a hash reference.
1499:
1500: =cut
1501:
1502: ###############################################################
1503: ###############################################################
1504: sub define_excel_formats {
1505: my ($workbook) = @_;
1506: my $format;
1507: $format->{'header'} = $workbook->add_format(bold => 1,
1508: bottom => 1,
1509: align => 'center');
1510: $format->{'bold'} = $workbook->add_format(bold=>1);
1511: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1512: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1513: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1514: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1515: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1516: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1517: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1518: return $format;
1519: }
1520:
1521: ###############################################################
1522: ###############################################################
1.113 bowersj2 1523:
1524: =pod
1525:
1.648 raeburn 1526: =item * &create_workbook()
1.255 matthew 1527:
1528: Create an Excel worksheet. If it fails, output message on the
1529: request object and return undefs.
1530:
1531: Inputs: Apache request object
1532:
1533: Returns (undef) on failure,
1534: Excel worksheet object, scalar with filename, and formats
1535: from &Apache::loncommon::define_excel_formats on success
1536:
1537: =cut
1538:
1539: ###############################################################
1540: ###############################################################
1541: sub create_workbook {
1542: my ($r) = @_;
1543: #
1544: # Create the excel spreadsheet
1545: my $filename = '/prtspool/'.
1.258 albertel 1546: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1547: time.'_'.rand(1000000000).'.xls';
1548: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1549: if (! defined($workbook)) {
1550: $r->log_error("Error creating excel spreadsheet $filename: $!");
1551: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1552: "This error has been logged. ".
1553: "Please alert your LON-CAPA administrator").
1554: '</p>');
1555: return (undef);
1556: }
1557: #
1558: $workbook->set_tempdir('/home/httpd/perl/tmp');
1559: #
1560: my $format = &Apache::loncommon::define_excel_formats($workbook);
1561: return ($workbook,$filename,$format);
1562: }
1563:
1564: ###############################################################
1565: ###############################################################
1566:
1567: =pod
1568:
1.648 raeburn 1569: =item * &create_text_file()
1.113 bowersj2 1570:
1.542 raeburn 1571: Create a file to write to and eventually make available to the user.
1.256 matthew 1572: If file creation fails, outputs an error message on the request object and
1573: return undefs.
1.113 bowersj2 1574:
1.256 matthew 1575: Inputs: Apache request object, and file suffix
1.113 bowersj2 1576:
1.256 matthew 1577: Returns (undef) on failure,
1578: Filehandle and filename on success.
1.113 bowersj2 1579:
1580: =cut
1581:
1.256 matthew 1582: ###############################################################
1583: ###############################################################
1584: sub create_text_file {
1585: my ($r,$suffix) = @_;
1586: if (! defined($suffix)) { $suffix = 'txt'; };
1587: my $fh;
1588: my $filename = '/prtspool/'.
1.258 albertel 1589: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1590: time.'_'.rand(1000000000).'.'.$suffix;
1591: $fh = Apache::File->new('>/home/httpd'.$filename);
1592: if (! defined($fh)) {
1593: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1594: $r->print(&mt('Problems occurred in creating the output file. '
1595: .'This error has been logged. '
1596: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1597: }
1.256 matthew 1598: return ($fh,$filename)
1.113 bowersj2 1599: }
1600:
1601:
1.256 matthew 1602: =pod
1.113 bowersj2 1603:
1604: =back
1605:
1606: =cut
1.37 matthew 1607:
1608: ###############################################################
1.33 matthew 1609: ## Home server <option> list generating code ##
1610: ###############################################################
1.35 matthew 1611:
1.169 www 1612: # ------------------------------------------
1613:
1614: sub domain_select {
1615: my ($name,$value,$multiple)=@_;
1616: my %domains=map {
1.514 albertel 1617: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1618: } &Apache::lonnet::all_domains();
1.169 www 1619: if ($multiple) {
1620: $domains{''}=&mt('Any domain');
1.550 albertel 1621: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1622: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1623: } else {
1.550 albertel 1624: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1625: return &select_form($name,$value,%domains);
1626: }
1627: }
1628:
1.282 albertel 1629: #-------------------------------------------
1630:
1631: =pod
1632:
1.519 raeburn 1633: =head1 Routines for form select boxes
1634:
1635: =over 4
1636:
1.648 raeburn 1637: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1638:
1639: Returns a string containing a <select> element int multiple mode
1640:
1641:
1642: Args:
1643: $name - name of the <select> element
1.506 raeburn 1644: $value - scalar or array ref of values that should already be selected
1.282 albertel 1645: $size - number of rows long the select element is
1.283 albertel 1646: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1647: (shown text should already have been &mt())
1.506 raeburn 1648: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1649:
1.282 albertel 1650: =cut
1651:
1652: #-------------------------------------------
1.169 www 1653: sub multiple_select_form {
1.284 albertel 1654: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1655: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1656: my $output='';
1.191 matthew 1657: if (! defined($size)) {
1658: $size = 4;
1.283 albertel 1659: if (scalar(keys(%$hash))<4) {
1660: $size = scalar(keys(%$hash));
1.191 matthew 1661: }
1662: }
1.734 bisitz 1663: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1664: my @order;
1.506 raeburn 1665: if (ref($order) eq 'ARRAY') {
1666: @order = @{$order};
1667: } else {
1668: @order = sort(keys(%$hash));
1.501 banghart 1669: }
1670: if (exists($$hash{'select_form_order'})) {
1671: @order = @{$$hash{'select_form_order'}};
1672: }
1673:
1.284 albertel 1674: foreach my $key (@order) {
1.356 albertel 1675: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1676: $output.='selected="selected" ' if ($selected{$key});
1677: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1678: }
1679: $output.="</select>\n";
1680: return $output;
1681: }
1682:
1.88 www 1683: #-------------------------------------------
1684:
1685: =pod
1686:
1.648 raeburn 1687: =item * &select_form($defdom,$name,%hash)
1.88 www 1688:
1689: Returns a string containing a <select name='$name' size='1'> form to
1690: allow a user to select options from a hash option_name => displayed text.
1691: See lonrights.pm for an example invocation and use.
1692:
1693: =cut
1694:
1695: #-------------------------------------------
1696: sub select_form {
1697: my ($def,$name,%hash) = @_;
1698: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1699: my @keys;
1700: if (exists($hash{'select_form_order'})) {
1701: @keys=@{$hash{'select_form_order'}};
1702: } else {
1703: @keys=sort(keys(%hash));
1704: }
1.356 albertel 1705: foreach my $key (@keys) {
1706: $selectform.=
1707: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1708: ($key eq $def ? 'selected="selected" ' : '').
1709: ">".&mt($hash{$key})."</option>\n";
1.88 www 1710: }
1711: $selectform.="</select>";
1712: return $selectform;
1713: }
1714:
1.475 www 1715: # For display filters
1716:
1717: sub display_filter {
1718: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1719: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1720: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1721: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1722: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1723: '</label></span> <span class="LC_nobreak">'.
1.475 www 1724: &mt('Filter [_1]',
1.477 www 1725: &select_form($env{'form.displayfilter'},
1726: 'displayfilter',
1727: ('currentfolder' => 'Current folder/page',
1728: 'containing' => 'Containing phrase',
1729: 'none' => 'None'))).
1.714 bisitz 1730: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1731: }
1732:
1.167 www 1733: sub gradeleveldescription {
1734: my $gradelevel=shift;
1735: my %gradelevels=(0 => 'Not specified',
1736: 1 => 'Grade 1',
1737: 2 => 'Grade 2',
1738: 3 => 'Grade 3',
1739: 4 => 'Grade 4',
1740: 5 => 'Grade 5',
1741: 6 => 'Grade 6',
1742: 7 => 'Grade 7',
1743: 8 => 'Grade 8',
1744: 9 => 'Grade 9',
1745: 10 => 'Grade 10',
1746: 11 => 'Grade 11',
1747: 12 => 'Grade 12',
1748: 13 => 'Grade 13',
1749: 14 => '100 Level',
1750: 15 => '200 Level',
1751: 16 => '300 Level',
1752: 17 => '400 Level',
1753: 18 => 'Graduate Level');
1754: return &mt($gradelevels{$gradelevel});
1755: }
1756:
1.163 www 1757: sub select_level_form {
1758: my ($deflevel,$name)=@_;
1759: unless ($deflevel) { $deflevel=0; }
1.167 www 1760: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1761: for (my $i=0; $i<=18; $i++) {
1762: $selectform.="<option value=\"$i\" ".
1.253 albertel 1763: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1764: ">".&gradeleveldescription($i)."</option>\n";
1765: }
1766: $selectform.="</select>";
1767: return $selectform;
1.163 www 1768: }
1.167 www 1769:
1.35 matthew 1770: #-------------------------------------------
1771:
1.45 matthew 1772: =pod
1773:
1.743 raeburn 1774: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1775:
1776: Returns a string containing a <select name='$name' size='1'> form to
1777: allow a user to select the domain to preform an operation in.
1778: See loncreateuser.pm for an example invocation and use.
1779:
1.90 www 1780: If the $includeempty flag is set, it also includes an empty choice ("no domain
1781: selected");
1782:
1.743 raeburn 1783: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1784:
1785: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1786:
1.35 matthew 1787: =cut
1788:
1789: #-------------------------------------------
1.34 matthew 1790: sub select_dom_form {
1.743 raeburn 1791: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1792: my $onchange;
1793: if ($autosubmit) {
1794: $onchange = ' onchange="this.form.submit()"';
1795: }
1.550 albertel 1796: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1797: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1798: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1799: foreach my $dom (@domains) {
1800: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1801: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1802: if ($showdomdesc) {
1803: if ($dom ne '') {
1804: my $domdesc = &Apache::lonnet::domain($dom,'description');
1805: if ($domdesc ne '') {
1806: $selectdomain .= ' ('.$domdesc.')';
1807: }
1808: }
1809: }
1810: $selectdomain .= "</option>\n";
1.34 matthew 1811: }
1812: $selectdomain.="</select>";
1813: return $selectdomain;
1814: }
1815:
1.35 matthew 1816: #-------------------------------------------
1817:
1.45 matthew 1818: =pod
1819:
1.648 raeburn 1820: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1821:
1.586 raeburn 1822: input: 4 arguments (two required, two optional) -
1823: $domain - domain of new user
1824: $name - name of form element
1825: $default - Value of 'default' causes a default item to be first
1826: option, and selected by default.
1827: $hide - Value of 'hide' causes hiding of the name of the server,
1828: if 1 server found, or default, if 0 found.
1.594 raeburn 1829: output: returns 2 items:
1.586 raeburn 1830: (a) form element which contains either:
1831: (i) <select name="$name">
1832: <option value="$hostid1">$hostid $servers{$hostid}</option>
1833: <option value="$hostid2">$hostid $servers{$hostid}</option>
1834: </select>
1835: form item if there are multiple library servers in $domain, or
1836: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1837: if there is only one library server in $domain.
1838:
1839: (b) number of library servers found.
1840:
1841: See loncreateuser.pm for example of use.
1.35 matthew 1842:
1843: =cut
1844:
1845: #-------------------------------------------
1.586 raeburn 1846: sub home_server_form_item {
1847: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1848: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1849: my $result;
1850: my $numlib = keys(%servers);
1851: if ($numlib > 1) {
1852: $result .= '<select name="'.$name.'" />'."\n";
1853: if ($default) {
1854: $result .= '<option value="default" selected>'.&mt('default').
1855: '</option>'."\n";
1856: }
1857: foreach my $hostid (sort(keys(%servers))) {
1858: $result.= '<option value="'.$hostid.'">'.
1859: $hostid.' '.$servers{$hostid}."</option>\n";
1860: }
1861: $result .= '</select>'."\n";
1862: } elsif ($numlib == 1) {
1863: my $hostid;
1864: foreach my $item (keys(%servers)) {
1865: $hostid = $item;
1866: }
1867: $result .= '<input type="hidden" name="'.$name.'" value="'.
1868: $hostid.'" />';
1869: if (!$hide) {
1870: $result .= $hostid.' '.$servers{$hostid};
1871: }
1872: $result .= "\n";
1873: } elsif ($default) {
1874: $result .= '<input type="hidden" name="'.$name.
1875: '" value="default" />';
1876: if (!$hide) {
1877: $result .= &mt('default');
1878: }
1879: $result .= "\n";
1.33 matthew 1880: }
1.586 raeburn 1881: return ($result,$numlib);
1.33 matthew 1882: }
1.112 bowersj2 1883:
1884: =pod
1885:
1.534 albertel 1886: =back
1887:
1.112 bowersj2 1888: =cut
1.87 matthew 1889:
1890: ###############################################################
1.112 bowersj2 1891: ## Decoding User Agent ##
1.87 matthew 1892: ###############################################################
1893:
1894: =pod
1895:
1.112 bowersj2 1896: =head1 Decoding the User Agent
1897:
1898: =over 4
1899:
1900: =item * &decode_user_agent()
1.87 matthew 1901:
1902: Inputs: $r
1903:
1904: Outputs:
1905:
1906: =over 4
1907:
1.112 bowersj2 1908: =item * $httpbrowser
1.87 matthew 1909:
1.112 bowersj2 1910: =item * $clientbrowser
1.87 matthew 1911:
1.112 bowersj2 1912: =item * $clientversion
1.87 matthew 1913:
1.112 bowersj2 1914: =item * $clientmathml
1.87 matthew 1915:
1.112 bowersj2 1916: =item * $clientunicode
1.87 matthew 1917:
1.112 bowersj2 1918: =item * $clientos
1.87 matthew 1919:
1920: =back
1921:
1.157 matthew 1922: =back
1923:
1.87 matthew 1924: =cut
1925:
1926: ###############################################################
1927: ###############################################################
1928: sub decode_user_agent {
1.247 albertel 1929: my ($r)=@_;
1.87 matthew 1930: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1931: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1932: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1933: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1934: my $clientbrowser='unknown';
1935: my $clientversion='0';
1936: my $clientmathml='';
1937: my $clientunicode='0';
1938: for (my $i=0;$i<=$#browsertype;$i++) {
1939: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1940: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1941: $clientbrowser=$bname;
1942: $httpbrowser=~/$vreg/i;
1943: $clientversion=$1;
1944: $clientmathml=($clientversion>=$minv);
1945: $clientunicode=($clientversion>=$univ);
1946: }
1947: }
1948: my $clientos='unknown';
1949: if (($httpbrowser=~/linux/i) ||
1950: ($httpbrowser=~/unix/i) ||
1951: ($httpbrowser=~/ux/i) ||
1952: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1953: if (($httpbrowser=~/vax/i) ||
1954: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1955: if ($httpbrowser=~/next/i) { $clientos='next'; }
1956: if (($httpbrowser=~/mac/i) ||
1957: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1958: if ($httpbrowser=~/win/i) { $clientos='win'; }
1959: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1960: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1961: $clientunicode,$clientos,);
1962: }
1963:
1.32 matthew 1964: ###############################################################
1965: ## Authentication changing form generation subroutines ##
1966: ###############################################################
1967: ##
1968: ## All of the authform_xxxxxxx subroutines take their inputs in a
1969: ## hash, and have reasonable default values.
1970: ##
1971: ## formname = the name given in the <form> tag.
1.35 matthew 1972: #-------------------------------------------
1973:
1.45 matthew 1974: =pod
1975:
1.112 bowersj2 1976: =head1 Authentication Routines
1977:
1978: =over 4
1979:
1.648 raeburn 1980: =item * &authform_xxxxxx()
1.35 matthew 1981:
1982: The authform_xxxxxx subroutines provide javascript and html forms which
1983: handle some of the conveniences required for authentication forms.
1984: This is not an optimal method, but it works.
1985:
1986: =over 4
1987:
1.112 bowersj2 1988: =item * authform_header
1.35 matthew 1989:
1.112 bowersj2 1990: =item * authform_authorwarning
1.35 matthew 1991:
1.112 bowersj2 1992: =item * authform_nochange
1.35 matthew 1993:
1.112 bowersj2 1994: =item * authform_kerberos
1.35 matthew 1995:
1.112 bowersj2 1996: =item * authform_internal
1.35 matthew 1997:
1.112 bowersj2 1998: =item * authform_filesystem
1.35 matthew 1999:
2000: =back
2001:
1.648 raeburn 2002: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2003:
1.35 matthew 2004: =cut
2005:
2006: #-------------------------------------------
1.32 matthew 2007: sub authform_header{
2008: my %in = (
2009: formname => 'cu',
1.80 albertel 2010: kerb_def_dom => '',
1.32 matthew 2011: @_,
2012: );
2013: $in{'formname'} = 'document.' . $in{'formname'};
2014: my $result='';
1.80 albertel 2015:
2016: #---------------------------------------------- Code for upper case translation
2017: my $Javascript_toUpperCase;
2018: unless ($in{kerb_def_dom}) {
2019: $Javascript_toUpperCase =<<"END";
2020: switch (choice) {
2021: case 'krb': currentform.elements[choicearg].value =
2022: currentform.elements[choicearg].value.toUpperCase();
2023: break;
2024: default:
2025: }
2026: END
2027: } else {
2028: $Javascript_toUpperCase = "";
2029: }
2030:
1.165 raeburn 2031: my $radioval = "'nochange'";
1.591 raeburn 2032: if (defined($in{'curr_authtype'})) {
2033: if ($in{'curr_authtype'} ne '') {
2034: $radioval = "'".$in{'curr_authtype'}."arg'";
2035: }
1.174 matthew 2036: }
1.165 raeburn 2037: my $argfield = 'null';
1.591 raeburn 2038: if (defined($in{'mode'})) {
1.165 raeburn 2039: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2040: if (defined($in{'curr_autharg'})) {
2041: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2042: $argfield = "'$in{'curr_autharg'}'";
2043: }
2044: }
2045: }
2046: }
2047:
1.32 matthew 2048: $result.=<<"END";
2049: var current = new Object();
1.165 raeburn 2050: current.radiovalue = $radioval;
2051: current.argfield = $argfield;
1.32 matthew 2052:
2053: function changed_radio(choice,currentform) {
2054: var choicearg = choice + 'arg';
2055: // If a radio button in changed, we need to change the argfield
2056: if (current.radiovalue != choice) {
2057: current.radiovalue = choice;
2058: if (current.argfield != null) {
2059: currentform.elements[current.argfield].value = '';
2060: }
2061: if (choice == 'nochange') {
2062: current.argfield = null;
2063: } else {
2064: current.argfield = choicearg;
2065: switch(choice) {
2066: case 'krb':
2067: currentform.elements[current.argfield].value =
2068: "$in{'kerb_def_dom'}";
2069: break;
2070: default:
2071: break;
2072: }
2073: }
2074: }
2075: return;
2076: }
1.22 www 2077:
1.32 matthew 2078: function changed_text(choice,currentform) {
2079: var choicearg = choice + 'arg';
2080: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2081: $Javascript_toUpperCase
1.32 matthew 2082: // clear old field
2083: if ((current.argfield != choicearg) && (current.argfield != null)) {
2084: currentform.elements[current.argfield].value = '';
2085: }
2086: current.argfield = choicearg;
2087: }
2088: set_auth_radio_buttons(choice,currentform);
2089: return;
1.20 www 2090: }
1.32 matthew 2091:
2092: function set_auth_radio_buttons(newvalue,currentform) {
2093: var i=0;
2094: while (i < currentform.login.length) {
2095: if (currentform.login[i].value == newvalue) { break; }
2096: i++;
2097: }
2098: if (i == currentform.login.length) {
2099: return;
2100: }
2101: current.radiovalue = newvalue;
2102: currentform.login[i].checked = true;
2103: return;
2104: }
2105: END
2106: return $result;
2107: }
2108:
2109: sub authform_authorwarning{
2110: my $result='';
1.144 matthew 2111: $result='<i>'.
2112: &mt('As a general rule, only authors or co-authors should be '.
2113: 'filesystem authenticated '.
2114: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2115: return $result;
2116: }
2117:
2118: sub authform_nochange{
2119: my %in = (
2120: formname => 'document.cu',
2121: kerb_def_dom => 'MSU.EDU',
2122: @_,
2123: );
1.586 raeburn 2124: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2125: my $result;
2126: if (keys(%can_assign) == 0) {
2127: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2128: } else {
2129: $result = '<label>'.&mt('[_1] Do not change login data',
2130: '<input type="radio" name="login" value="nochange" '.
2131: 'checked="checked" onclick="'.
1.281 albertel 2132: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2133: '</label>';
1.586 raeburn 2134: }
1.32 matthew 2135: return $result;
2136: }
2137:
1.591 raeburn 2138: sub authform_kerberos {
1.32 matthew 2139: my %in = (
2140: formname => 'document.cu',
2141: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2142: kerb_def_auth => 'krb4',
1.32 matthew 2143: @_,
2144: );
1.586 raeburn 2145: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2146: $autharg,$jscall);
2147: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2148: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2149: $check5 = ' checked="checked"';
1.80 albertel 2150: } else {
1.772 bisitz 2151: $check4 = ' checked="checked"';
1.80 albertel 2152: }
1.165 raeburn 2153: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2154: if (defined($in{'curr_authtype'})) {
2155: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2156: $krbcheck = ' checked="checked"';
1.623 raeburn 2157: if (defined($in{'mode'})) {
2158: if ($in{'mode'} eq 'modifyuser') {
2159: $krbcheck = '';
2160: }
2161: }
1.591 raeburn 2162: if (defined($in{'curr_kerb_ver'})) {
2163: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2164: $check5 = ' checked="checked"';
1.591 raeburn 2165: $check4 = '';
2166: } else {
1.772 bisitz 2167: $check4 = ' checked="checked"';
1.591 raeburn 2168: $check5 = '';
2169: }
1.586 raeburn 2170: }
1.591 raeburn 2171: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2172: $krbarg = $in{'curr_autharg'};
2173: }
1.586 raeburn 2174: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2175: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2176: $result =
2177: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2178: $in{'curr_autharg'},$krbver);
2179: } else {
2180: $result =
2181: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2182: }
2183: return $result;
2184: }
2185: }
2186: } else {
2187: if ($authnum == 1) {
1.784 bisitz 2188: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2189: }
2190: }
1.586 raeburn 2191: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2192: return;
1.587 raeburn 2193: } elsif ($authtype eq '') {
1.591 raeburn 2194: if (defined($in{'mode'})) {
1.587 raeburn 2195: if ($in{'mode'} eq 'modifycourse') {
2196: if ($authnum == 1) {
1.784 bisitz 2197: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2198: }
2199: }
2200: }
1.586 raeburn 2201: }
2202: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2203: if ($authtype eq '') {
2204: $authtype = '<input type="radio" name="login" value="krb" '.
2205: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2206: $krbcheck.' />';
2207: }
2208: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2209: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2210: $in{'curr_authtype'} eq 'krb5') ||
2211: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2212: $in{'curr_authtype'} eq 'krb4')) {
2213: $result .= &mt
1.144 matthew 2214: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2215: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2216: '<label>'.$authtype,
1.281 albertel 2217: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2218: 'value="'.$krbarg.'" '.
1.144 matthew 2219: 'onchange="'.$jscall.'" />',
1.281 albertel 2220: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2221: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2222: '</label>');
1.586 raeburn 2223: } elsif ($can_assign{'krb4'}) {
2224: $result .= &mt
2225: ('[_1] Kerberos authenticated with domain [_2] '.
2226: '[_3] Version 4 [_4]',
2227: '<label>'.$authtype,
2228: '</label><input type="text" size="10" name="krbarg" '.
2229: 'value="'.$krbarg.'" '.
2230: 'onchange="'.$jscall.'" />',
2231: '<label><input type="hidden" name="krbver" value="4" />',
2232: '</label>');
2233: } elsif ($can_assign{'krb5'}) {
2234: $result .= &mt
2235: ('[_1] Kerberos authenticated with domain [_2] '.
2236: '[_3] Version 5 [_4]',
2237: '<label>'.$authtype,
2238: '</label><input type="text" size="10" name="krbarg" '.
2239: 'value="'.$krbarg.'" '.
2240: 'onchange="'.$jscall.'" />',
2241: '<label><input type="hidden" name="krbver" value="5" />',
2242: '</label>');
2243: }
1.32 matthew 2244: return $result;
2245: }
2246:
2247: sub authform_internal{
1.586 raeburn 2248: my %in = (
1.32 matthew 2249: formname => 'document.cu',
2250: kerb_def_dom => 'MSU.EDU',
2251: @_,
2252: );
1.586 raeburn 2253: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2254: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2255: if (defined($in{'curr_authtype'})) {
2256: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2257: if ($can_assign{'int'}) {
1.772 bisitz 2258: $intcheck = 'checked="checked" ';
1.623 raeburn 2259: if (defined($in{'mode'})) {
2260: if ($in{'mode'} eq 'modifyuser') {
2261: $intcheck = '';
2262: }
2263: }
1.591 raeburn 2264: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2265: $intarg = $in{'curr_autharg'};
2266: }
2267: } else {
2268: $result = &mt('Currently internally authenticated.');
2269: return $result;
1.165 raeburn 2270: }
2271: }
1.586 raeburn 2272: } else {
2273: if ($authnum == 1) {
1.784 bisitz 2274: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2275: }
2276: }
2277: if (!$can_assign{'int'}) {
2278: return;
1.587 raeburn 2279: } elsif ($authtype eq '') {
1.591 raeburn 2280: if (defined($in{'mode'})) {
1.587 raeburn 2281: if ($in{'mode'} eq 'modifycourse') {
2282: if ($authnum == 1) {
1.784 bisitz 2283: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2284: }
2285: }
2286: }
1.165 raeburn 2287: }
1.586 raeburn 2288: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2289: if ($authtype eq '') {
2290: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2291: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2292: }
1.605 bisitz 2293: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2294: $intarg.'" onchange="'.$jscall.'" />';
2295: $result = &mt
1.144 matthew 2296: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2297: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2298: $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 2299: return $result;
2300: }
2301:
2302: sub authform_local{
2303: my %in = (
2304: formname => 'document.cu',
2305: kerb_def_dom => 'MSU.EDU',
2306: @_,
2307: );
1.586 raeburn 2308: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2309: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2310: if (defined($in{'curr_authtype'})) {
2311: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2312: if ($can_assign{'loc'}) {
1.772 bisitz 2313: $loccheck = 'checked="checked" ';
1.623 raeburn 2314: if (defined($in{'mode'})) {
2315: if ($in{'mode'} eq 'modifyuser') {
2316: $loccheck = '';
2317: }
2318: }
1.591 raeburn 2319: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2320: $locarg = $in{'curr_autharg'};
2321: }
2322: } else {
2323: $result = &mt('Currently using local (institutional) authentication.');
2324: return $result;
1.165 raeburn 2325: }
2326: }
1.586 raeburn 2327: } else {
2328: if ($authnum == 1) {
1.784 bisitz 2329: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2330: }
2331: }
2332: if (!$can_assign{'loc'}) {
2333: return;
1.587 raeburn 2334: } elsif ($authtype eq '') {
1.591 raeburn 2335: if (defined($in{'mode'})) {
1.587 raeburn 2336: if ($in{'mode'} eq 'modifycourse') {
2337: if ($authnum == 1) {
1.784 bisitz 2338: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2339: }
2340: }
2341: }
1.165 raeburn 2342: }
1.586 raeburn 2343: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2344: if ($authtype eq '') {
2345: $authtype = '<input type="radio" name="login" value="loc" '.
2346: $loccheck.' onchange="'.$jscall.'" onclick="'.
2347: $jscall.'" />';
2348: }
2349: $autharg = '<input type="text" size="10" name="locarg" value="'.
2350: $locarg.'" onchange="'.$jscall.'" />';
2351: $result = &mt('[_1] Local Authentication with argument [_2]',
2352: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2353: return $result;
2354: }
2355:
2356: sub authform_filesystem{
2357: my %in = (
2358: formname => 'document.cu',
2359: kerb_def_dom => 'MSU.EDU',
2360: @_,
2361: );
1.586 raeburn 2362: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2363: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2364: if (defined($in{'curr_authtype'})) {
2365: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2366: if ($can_assign{'fsys'}) {
1.772 bisitz 2367: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2368: if (defined($in{'mode'})) {
2369: if ($in{'mode'} eq 'modifyuser') {
2370: $fsyscheck = '';
2371: }
2372: }
1.586 raeburn 2373: } else {
2374: $result = &mt('Currently Filesystem Authenticated.');
2375: return $result;
2376: }
2377: }
2378: } else {
2379: if ($authnum == 1) {
1.784 bisitz 2380: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2381: }
2382: }
2383: if (!$can_assign{'fsys'}) {
2384: return;
1.587 raeburn 2385: } elsif ($authtype eq '') {
1.591 raeburn 2386: if (defined($in{'mode'})) {
1.587 raeburn 2387: if ($in{'mode'} eq 'modifycourse') {
2388: if ($authnum == 1) {
1.784 bisitz 2389: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2390: }
2391: }
2392: }
1.586 raeburn 2393: }
2394: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2395: if ($authtype eq '') {
2396: $authtype = '<input type="radio" name="login" value="fsys" '.
2397: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2398: $jscall.'" />';
2399: }
2400: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2401: ' onchange="'.$jscall.'" />';
2402: $result = &mt
1.144 matthew 2403: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2404: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2405: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2406: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2407: 'onchange="'.$jscall.'" />');
1.32 matthew 2408: return $result;
2409: }
2410:
1.586 raeburn 2411: sub get_assignable_auth {
2412: my ($dom) = @_;
2413: if ($dom eq '') {
2414: $dom = $env{'request.role.domain'};
2415: }
2416: my %can_assign = (
2417: krb4 => 1,
2418: krb5 => 1,
2419: int => 1,
2420: loc => 1,
2421: );
2422: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2423: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2424: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2425: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2426: my $context;
2427: if ($env{'request.role'} =~ /^au/) {
2428: $context = 'author';
2429: } elsif ($env{'request.role'} =~ /^dc/) {
2430: $context = 'domain';
2431: } elsif ($env{'request.course.id'}) {
2432: $context = 'course';
2433: }
2434: if ($context) {
2435: if (ref($authhash->{$context}) eq 'HASH') {
2436: %can_assign = %{$authhash->{$context}};
2437: }
2438: }
2439: }
2440: }
2441: my $authnum = 0;
2442: foreach my $key (keys(%can_assign)) {
2443: if ($can_assign{$key}) {
2444: $authnum ++;
2445: }
2446: }
2447: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2448: $authnum --;
2449: }
2450: return ($authnum,%can_assign);
2451: }
2452:
1.80 albertel 2453: ###############################################################
2454: ## Get Kerberos Defaults for Domain ##
2455: ###############################################################
2456: ##
2457: ## Returns default kerberos version and an associated argument
2458: ## as listed in file domain.tab. If not listed, provides
2459: ## appropriate default domain and kerberos version.
2460: ##
2461: #-------------------------------------------
2462:
2463: =pod
2464:
1.648 raeburn 2465: =item * &get_kerberos_defaults()
1.80 albertel 2466:
2467: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2468: version and domain. If not found, it defaults to version 4 and the
2469: domain of the server.
1.80 albertel 2470:
1.648 raeburn 2471: =over 4
2472:
1.80 albertel 2473: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2474:
1.648 raeburn 2475: =back
2476:
2477: =back
2478:
1.80 albertel 2479: =cut
2480:
2481: #-------------------------------------------
2482: sub get_kerberos_defaults {
2483: my $domain=shift;
1.641 raeburn 2484: my ($krbdef,$krbdefdom);
2485: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2486: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2487: $krbdef = $domdefaults{'auth_def'};
2488: $krbdefdom = $domdefaults{'auth_arg_def'};
2489: } else {
1.80 albertel 2490: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2491: my $krbdefdom=$1;
2492: $krbdefdom=~tr/a-z/A-Z/;
2493: $krbdef = "krb4";
2494: }
2495: return ($krbdef,$krbdefdom);
2496: }
1.112 bowersj2 2497:
1.32 matthew 2498:
1.46 matthew 2499: ###############################################################
2500: ## Thesaurus Functions ##
2501: ###############################################################
1.20 www 2502:
1.46 matthew 2503: =pod
1.20 www 2504:
1.112 bowersj2 2505: =head1 Thesaurus Functions
2506:
2507: =over 4
2508:
1.648 raeburn 2509: =item * &initialize_keywords()
1.46 matthew 2510:
2511: Initializes the package variable %Keywords if it is empty. Uses the
2512: package variable $thesaurus_db_file.
2513:
2514: =cut
2515:
2516: ###################################################
2517:
2518: sub initialize_keywords {
2519: return 1 if (scalar keys(%Keywords));
2520: # If we are here, %Keywords is empty, so fill it up
2521: # Make sure the file we need exists...
2522: if (! -e $thesaurus_db_file) {
2523: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2524: " failed because it does not exist");
2525: return 0;
2526: }
2527: # Set up the hash as a database
2528: my %thesaurus_db;
2529: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2530: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2531: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2532: $thesaurus_db_file);
2533: return 0;
2534: }
2535: # Get the average number of appearances of a word.
2536: my $avecount = $thesaurus_db{'average.count'};
2537: # Put keywords (those that appear > average) into %Keywords
2538: while (my ($word,$data)=each (%thesaurus_db)) {
2539: my ($count,undef) = split /:/,$data;
2540: $Keywords{$word}++ if ($count > $avecount);
2541: }
2542: untie %thesaurus_db;
2543: # Remove special values from %Keywords.
1.356 albertel 2544: foreach my $value ('total.count','average.count') {
2545: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2546: }
1.46 matthew 2547: return 1;
2548: }
2549:
2550: ###################################################
2551:
2552: =pod
2553:
1.648 raeburn 2554: =item * &keyword($word)
1.46 matthew 2555:
2556: Returns true if $word is a keyword. A keyword is a word that appears more
2557: than the average number of times in the thesaurus database. Calls
2558: &initialize_keywords
2559:
2560: =cut
2561:
2562: ###################################################
1.20 www 2563:
2564: sub keyword {
1.46 matthew 2565: return if (!&initialize_keywords());
2566: my $word=lc(shift());
2567: $word=~s/\W//g;
2568: return exists($Keywords{$word});
1.20 www 2569: }
1.46 matthew 2570:
2571: ###############################################################
2572:
2573: =pod
1.20 www 2574:
1.648 raeburn 2575: =item * &get_related_words()
1.46 matthew 2576:
1.160 matthew 2577: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2578: an array of words. If the keyword is not in the thesaurus, an empty array
2579: will be returned. The order of the words returned is determined by the
2580: database which holds them.
2581:
2582: Uses global $thesaurus_db_file.
2583:
2584: =cut
2585:
2586: ###############################################################
2587: sub get_related_words {
2588: my $keyword = shift;
2589: my %thesaurus_db;
2590: if (! -e $thesaurus_db_file) {
2591: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2592: "failed because the file does not exist");
2593: return ();
2594: }
2595: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2596: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2597: return ();
2598: }
2599: my @Words=();
1.429 www 2600: my $count=0;
1.46 matthew 2601: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2602: # The first element is the number of times
2603: # the word appears. We do not need it now.
1.429 www 2604: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2605: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2606: my $threshold=$mostfrequentcount/10;
2607: foreach my $possibleword (@RelatedWords) {
2608: my ($word,$wordcount)=split(/\,/,$possibleword);
2609: if ($wordcount>$threshold) {
2610: push(@Words,$word);
2611: $count++;
2612: if ($count>10) { last; }
2613: }
1.20 www 2614: }
2615: }
1.46 matthew 2616: untie %thesaurus_db;
2617: return @Words;
1.14 harris41 2618: }
1.46 matthew 2619:
1.112 bowersj2 2620: =pod
2621:
2622: =back
2623:
2624: =cut
1.61 www 2625:
2626: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2627: =pod
2628:
1.112 bowersj2 2629: =head1 User Name Functions
2630:
2631: =over 4
2632:
1.648 raeburn 2633: =item * &plainname($uname,$udom,$first)
1.81 albertel 2634:
1.112 bowersj2 2635: Takes a users logon name and returns it as a string in
1.226 albertel 2636: "first middle last generation" form
2637: if $first is set to 'lastname' then it returns it as
2638: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2639:
2640: =cut
1.61 www 2641:
1.295 www 2642:
1.81 albertel 2643: ###############################################################
1.61 www 2644: sub plainname {
1.226 albertel 2645: my ($uname,$udom,$first)=@_;
1.537 albertel 2646: return if (!defined($uname) || !defined($udom));
1.295 www 2647: my %names=&getnames($uname,$udom);
1.226 albertel 2648: my $name=&Apache::lonnet::format_name($names{'firstname'},
2649: $names{'middlename'},
2650: $names{'lastname'},
2651: $names{'generation'},$first);
2652: $name=~s/^\s+//;
1.62 www 2653: $name=~s/\s+$//;
2654: $name=~s/\s+/ /g;
1.353 albertel 2655: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2656: return $name;
1.61 www 2657: }
1.66 www 2658:
2659: # -------------------------------------------------------------------- Nickname
1.81 albertel 2660: =pod
2661:
1.648 raeburn 2662: =item * &nickname($uname,$udom)
1.81 albertel 2663:
2664: Gets a users name and returns it as a string as
2665:
2666: ""nickname""
1.66 www 2667:
1.81 albertel 2668: if the user has a nickname or
2669:
2670: "first middle last generation"
2671:
2672: if the user does not
2673:
2674: =cut
1.66 www 2675:
2676: sub nickname {
2677: my ($uname,$udom)=@_;
1.537 albertel 2678: return if (!defined($uname) || !defined($udom));
1.295 www 2679: my %names=&getnames($uname,$udom);
1.68 albertel 2680: my $name=$names{'nickname'};
1.66 www 2681: if ($name) {
2682: $name='"'.$name.'"';
2683: } else {
2684: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2685: $names{'lastname'}.' '.$names{'generation'};
2686: $name=~s/\s+$//;
2687: $name=~s/\s+/ /g;
2688: }
2689: return $name;
2690: }
2691:
1.295 www 2692: sub getnames {
2693: my ($uname,$udom)=@_;
1.537 albertel 2694: return if (!defined($uname) || !defined($udom));
1.433 albertel 2695: if ($udom eq 'public' && $uname eq 'public') {
2696: return ('lastname' => &mt('Public'));
2697: }
1.295 www 2698: my $id=$uname.':'.$udom;
2699: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2700: if ($cached) {
2701: return %{$names};
2702: } else {
2703: my %loadnames=&Apache::lonnet::get('environment',
2704: ['firstname','middlename','lastname','generation','nickname'],
2705: $udom,$uname);
2706: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2707: return %loadnames;
2708: }
2709: }
1.61 www 2710:
1.542 raeburn 2711: # -------------------------------------------------------------------- getemails
1.648 raeburn 2712:
1.542 raeburn 2713: =pod
2714:
1.648 raeburn 2715: =item * &getemails($uname,$udom)
1.542 raeburn 2716:
2717: Gets a user's email information and returns it as a hash with keys:
2718: notification, critnotification, permanentemail
2719:
2720: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2721: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2722:
1.648 raeburn 2723:
1.542 raeburn 2724: =cut
2725:
1.648 raeburn 2726:
1.466 albertel 2727: sub getemails {
2728: my ($uname,$udom)=@_;
2729: if ($udom eq 'public' && $uname eq 'public') {
2730: return;
2731: }
1.467 www 2732: if (!$udom) { $udom=$env{'user.domain'}; }
2733: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2734: my $id=$uname.':'.$udom;
2735: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2736: if ($cached) {
2737: return %{$names};
2738: } else {
2739: my %loadnames=&Apache::lonnet::get('environment',
2740: ['notification','critnotification',
2741: 'permanentemail'],
2742: $udom,$uname);
2743: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2744: return %loadnames;
2745: }
2746: }
2747:
1.551 albertel 2748: sub flush_email_cache {
2749: my ($uname,$udom)=@_;
2750: if (!$udom) { $udom =$env{'user.domain'}; }
2751: if (!$uname) { $uname=$env{'user.name'}; }
2752: return if ($udom eq 'public' && $uname eq 'public');
2753: my $id=$uname.':'.$udom;
2754: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2755: }
2756:
1.728 raeburn 2757: # -------------------------------------------------------------------- getlangs
2758:
2759: =pod
2760:
2761: =item * &getlangs($uname,$udom)
2762:
2763: Gets a user's language preference and returns it as a hash with key:
2764: language.
2765:
2766: =cut
2767:
2768:
2769: sub getlangs {
2770: my ($uname,$udom) = @_;
2771: if (!$udom) { $udom =$env{'user.domain'}; }
2772: if (!$uname) { $uname=$env{'user.name'}; }
2773: my $id=$uname.':'.$udom;
2774: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2775: if ($cached) {
2776: return %{$langs};
2777: } else {
2778: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2779: $udom,$uname);
2780: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2781: return %loadlangs;
2782: }
2783: }
2784:
2785: sub flush_langs_cache {
2786: my ($uname,$udom)=@_;
2787: if (!$udom) { $udom =$env{'user.domain'}; }
2788: if (!$uname) { $uname=$env{'user.name'}; }
2789: return if ($udom eq 'public' && $uname eq 'public');
2790: my $id=$uname.':'.$udom;
2791: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2792: }
2793:
1.61 www 2794: # ------------------------------------------------------------------ Screenname
1.81 albertel 2795:
2796: =pod
2797:
1.648 raeburn 2798: =item * &screenname($uname,$udom)
1.81 albertel 2799:
2800: Gets a users screenname and returns it as a string
2801:
2802: =cut
1.61 www 2803:
2804: sub screenname {
2805: my ($uname,$udom)=@_;
1.258 albertel 2806: if ($uname eq $env{'user.name'} &&
2807: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2808: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2809: return $names{'screenname'};
1.62 www 2810: }
2811:
1.212 albertel 2812:
1.62 www 2813: # ------------------------------------------------------------- Message Wrapper
2814:
2815: sub messagewrapper {
1.369 www 2816: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2817: return
1.441 albertel 2818: '<a href="/adm/email?compose=individual&'.
2819: 'recname='.$username.'&recdom='.$domain.
2820: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2821: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2822: }
2823: # --------------------------------------------------------------- Notes Wrapper
2824:
2825: sub noteswrapper {
2826: my ($link,$un,$do)=@_;
2827: return
2828: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2829: }
2830: # ------------------------------------------------------------- Aboutme Wrapper
2831:
2832: sub aboutmewrapper {
1.166 www 2833: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2834: if (!defined($username) && !defined($domain)) {
2835: return;
2836: }
1.205 www 2837: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2838: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2839: }
2840:
2841: # ------------------------------------------------------------ Syllabus Wrapper
2842:
2843:
2844: sub syllabuswrapper {
1.707 bisitz 2845: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2846: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2847: }
1.14 harris41 2848:
1.208 matthew 2849: sub track_student_link {
1.268 albertel 2850: my ($linktext,$sname,$sdom,$target,$start) = @_;
2851: my $link ="/adm/trackstudent?";
1.208 matthew 2852: my $title = 'View recent activity';
2853: if (defined($sname) && $sname !~ /^\s*$/ &&
2854: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2855: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2856: $title .= ' of this student';
1.268 albertel 2857: }
1.208 matthew 2858: if (defined($target) && $target !~ /^\s*$/) {
2859: $target = qq{target="$target"};
2860: } else {
2861: $target = '';
2862: }
1.268 albertel 2863: if ($start) { $link.='&start='.$start; }
1.554 albertel 2864: $title = &mt($title);
2865: $linktext = &mt($linktext);
1.448 albertel 2866: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2867: &help_open_topic('View_recent_activity');
1.208 matthew 2868: }
2869:
1.781 raeburn 2870: sub slot_reservations_link {
2871: my ($linktext,$sname,$sdom,$target) = @_;
2872: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2873: my $title = 'View slot reservation history';
2874: if (defined($sname) && $sname !~ /^\s*$/ &&
2875: defined($sdom) && $sdom !~ /^\s*$/) {
2876: $link .= "&uname=$sname&udom=$sdom";
2877: $title .= ' of this student';
2878: }
2879: if (defined($target) && $target !~ /^\s*$/) {
2880: $target = qq{target="$target"};
2881: } else {
2882: $target = '';
2883: }
2884: $title = &mt($title);
2885: $linktext = &mt($linktext);
2886: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2887: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2888:
2889: }
2890:
1.508 www 2891: # ===================================================== Display a student photo
2892:
2893:
1.509 albertel 2894: sub student_image_tag {
1.508 www 2895: my ($domain,$user)=@_;
2896: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2897: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2898: return '<img src="'.$imgsrc.'" align="right" />';
2899: } else {
2900: return '';
2901: }
2902: }
2903:
1.112 bowersj2 2904: =pod
2905:
2906: =back
2907:
2908: =head1 Access .tab File Data
2909:
2910: =over 4
2911:
1.648 raeburn 2912: =item * &languageids()
1.112 bowersj2 2913:
2914: returns list of all language ids
2915:
2916: =cut
2917:
1.14 harris41 2918: sub languageids {
1.16 harris41 2919: return sort(keys(%language));
1.14 harris41 2920: }
2921:
1.112 bowersj2 2922: =pod
2923:
1.648 raeburn 2924: =item * &languagedescription()
1.112 bowersj2 2925:
2926: returns description of a specified language id
2927:
2928: =cut
2929:
1.14 harris41 2930: sub languagedescription {
1.125 www 2931: my $code=shift;
2932: return ($supported_language{$code}?'* ':'').
2933: $language{$code}.
1.126 www 2934: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2935: }
2936:
2937: sub plainlanguagedescription {
2938: my $code=shift;
2939: return $language{$code};
2940: }
2941:
2942: sub supportedlanguagecode {
2943: my $code=shift;
2944: return $supported_language{$code};
1.97 www 2945: }
2946:
1.112 bowersj2 2947: =pod
2948:
1.648 raeburn 2949: =item * ©rightids()
1.112 bowersj2 2950:
2951: returns list of all copyrights
2952:
2953: =cut
2954:
2955: sub copyrightids {
2956: return sort(keys(%cprtag));
2957: }
2958:
2959: =pod
2960:
1.648 raeburn 2961: =item * ©rightdescription()
1.112 bowersj2 2962:
2963: returns description of a specified copyright id
2964:
2965: =cut
2966:
2967: sub copyrightdescription {
1.166 www 2968: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2969: }
1.197 matthew 2970:
2971: =pod
2972:
1.648 raeburn 2973: =item * &source_copyrightids()
1.192 taceyjo1 2974:
2975: returns list of all source copyrights
2976:
2977: =cut
2978:
2979: sub source_copyrightids {
2980: return sort(keys(%scprtag));
2981: }
2982:
2983: =pod
2984:
1.648 raeburn 2985: =item * &source_copyrightdescription()
1.192 taceyjo1 2986:
2987: returns description of a specified source copyright id
2988:
2989: =cut
2990:
2991: sub source_copyrightdescription {
2992: return &mt($scprtag{shift(@_)});
2993: }
1.112 bowersj2 2994:
2995: =pod
2996:
1.648 raeburn 2997: =item * &filecategories()
1.112 bowersj2 2998:
2999: returns list of all file categories
3000:
3001: =cut
3002:
3003: sub filecategories {
3004: return sort(keys(%category_extensions));
3005: }
3006:
3007: =pod
3008:
1.648 raeburn 3009: =item * &filecategorytypes()
1.112 bowersj2 3010:
3011: returns list of file types belonging to a given file
3012: category
3013:
3014: =cut
3015:
3016: sub filecategorytypes {
1.356 albertel 3017: my ($cat) = @_;
3018: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3019: }
3020:
3021: =pod
3022:
1.648 raeburn 3023: =item * &fileembstyle()
1.112 bowersj2 3024:
3025: returns embedding style for a specified file type
3026:
3027: =cut
3028:
3029: sub fileembstyle {
3030: return $fe{lc(shift(@_))};
1.169 www 3031: }
3032:
1.351 www 3033: sub filemimetype {
3034: return $fm{lc(shift(@_))};
3035: }
3036:
1.169 www 3037:
3038: sub filecategoryselect {
3039: my ($name,$value)=@_;
1.189 matthew 3040: return &select_form($value,$name,
1.169 www 3041: '' => &mt('Any category'),
3042: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3043: }
3044:
3045: =pod
3046:
1.648 raeburn 3047: =item * &filedescription()
1.112 bowersj2 3048:
3049: returns description for a specified file type
3050:
3051: =cut
3052:
3053: sub filedescription {
1.188 matthew 3054: my $file_description = $fd{lc(shift())};
3055: $file_description =~ s:([\[\]]):~$1:g;
3056: return &mt($file_description);
1.112 bowersj2 3057: }
3058:
3059: =pod
3060:
1.648 raeburn 3061: =item * &filedescriptionex()
1.112 bowersj2 3062:
3063: returns description for a specified file type with
3064: extra formatting
3065:
3066: =cut
3067:
3068: sub filedescriptionex {
3069: my $ex=shift;
1.188 matthew 3070: my $file_description = $fd{lc($ex)};
3071: $file_description =~ s:([\[\]]):~$1:g;
3072: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3073: }
3074:
3075: # End of .tab access
3076: =pod
3077:
3078: =back
3079:
3080: =cut
3081:
3082: # ------------------------------------------------------------------ File Types
3083: sub fileextensions {
3084: return sort(keys(%fe));
3085: }
3086:
1.97 www 3087: # ----------------------------------------------------------- Display Languages
3088: # returns a hash with all desired display languages
3089: #
3090:
3091: sub display_languages {
3092: my %languages=();
1.695 raeburn 3093: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3094: $languages{$lang}=1;
1.97 www 3095: }
3096: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3097: if ($env{'form.displaylanguage'}) {
1.356 albertel 3098: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3099: $languages{$lang}=1;
1.97 www 3100: }
3101: }
3102: return %languages;
1.14 harris41 3103: }
3104:
1.582 albertel 3105: sub languages {
3106: my ($possible_langs) = @_;
1.695 raeburn 3107: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3108: if (!ref($possible_langs)) {
3109: if( wantarray ) {
3110: return @preferred_langs;
3111: } else {
3112: return $preferred_langs[0];
3113: }
3114: }
3115: my %possibilities = map { $_ => 1 } (@$possible_langs);
3116: my @preferred_possibilities;
3117: foreach my $preferred_lang (@preferred_langs) {
3118: if (exists($possibilities{$preferred_lang})) {
3119: push(@preferred_possibilities, $preferred_lang);
3120: }
3121: }
3122: if( wantarray ) {
3123: return @preferred_possibilities;
3124: }
3125: return $preferred_possibilities[0];
3126: }
3127:
1.742 raeburn 3128: sub user_lang {
3129: my ($touname,$toudom,$fromcid) = @_;
3130: my @userlangs;
3131: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3132: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3133: $env{'course.'.$fromcid.'.languages'}));
3134: } else {
3135: my %langhash = &getlangs($touname,$toudom);
3136: if ($langhash{'languages'} ne '') {
3137: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3138: } else {
3139: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3140: if ($domdefs{'lang_def'} ne '') {
3141: @userlangs = ($domdefs{'lang_def'});
3142: }
3143: }
3144: }
3145: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3146: my $user_lh = Apache::localize->get_handle(@languages);
3147: return $user_lh;
3148: }
3149:
3150:
1.112 bowersj2 3151: ###############################################################
3152: ## Student Answer Attempts ##
3153: ###############################################################
3154:
3155: =pod
3156:
3157: =head1 Alternate Problem Views
3158:
3159: =over 4
3160:
1.648 raeburn 3161: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3162: $getattempt, $regexp, $gradesub)
3163:
3164: Return string with previous attempt on problem. Arguments:
3165:
3166: =over 4
3167:
3168: =item * $symb: Problem, including path
3169:
3170: =item * $username: username of the desired student
3171:
3172: =item * $domain: domain of the desired student
1.14 harris41 3173:
1.112 bowersj2 3174: =item * $course: Course ID
1.14 harris41 3175:
1.112 bowersj2 3176: =item * $getattempt: Leave blank for all attempts, otherwise put
3177: something
1.14 harris41 3178:
1.112 bowersj2 3179: =item * $regexp: if string matches this regexp, the string will be
3180: sent to $gradesub
1.14 harris41 3181:
1.112 bowersj2 3182: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3183:
1.112 bowersj2 3184: =back
1.14 harris41 3185:
1.112 bowersj2 3186: The output string is a table containing all desired attempts, if any.
1.16 harris41 3187:
1.112 bowersj2 3188: =cut
1.1 albertel 3189:
3190: sub get_previous_attempt {
1.43 ng 3191: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3192: my $prevattempts='';
1.43 ng 3193: no strict 'refs';
1.1 albertel 3194: if ($symb) {
1.3 albertel 3195: my (%returnhash)=
3196: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3197: if ($returnhash{'version'}) {
3198: my %lasthash=();
3199: my $version;
3200: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3201: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3202: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3203: }
1.1 albertel 3204: }
1.596 albertel 3205: $prevattempts=&start_data_table().&start_data_table_header_row();
3206: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3207: foreach my $key (sort(keys(%lasthash))) {
3208: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3209: if ($#parts > 0) {
1.31 albertel 3210: my $data=$parts[-1];
3211: pop(@parts);
1.596 albertel 3212: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3213: } else {
1.41 ng 3214: if ($#parts == 0) {
3215: $prevattempts.='<th>'.$parts[0].'</th>';
3216: } else {
3217: $prevattempts.='<th>'.$ign.'</th>';
3218: }
1.31 albertel 3219: }
1.16 harris41 3220: }
1.596 albertel 3221: $prevattempts.=&end_data_table_header_row();
1.40 ng 3222: if ($getattempt eq '') {
3223: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3224: $prevattempts.=&start_data_table_row().
3225: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3226: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3227: my $value = &format_previous_attempt_value($key,
3228: $returnhash{$version.':'.$key});
3229: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3230: }
1.596 albertel 3231: $prevattempts.=&end_data_table_row();
1.40 ng 3232: }
1.1 albertel 3233: }
1.596 albertel 3234: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3235: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3236: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3237: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3238: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3239: }
1.596 albertel 3240: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3241: } else {
1.596 albertel 3242: $prevattempts=
3243: &start_data_table().&start_data_table_row().
3244: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3245: &end_data_table_row().&end_data_table();
1.1 albertel 3246: }
3247: } else {
1.596 albertel 3248: $prevattempts=
3249: &start_data_table().&start_data_table_row().
3250: '<td>'.&mt('No data.').'</td>'.
3251: &end_data_table_row().&end_data_table();
1.1 albertel 3252: }
1.10 albertel 3253: }
3254:
1.581 albertel 3255: sub format_previous_attempt_value {
3256: my ($key,$value) = @_;
3257: if ($key =~ /timestamp/) {
3258: $value = &Apache::lonlocal::locallocaltime($value);
3259: } elsif (ref($value) eq 'ARRAY') {
3260: $value = '('.join(', ', @{ $value }).')';
3261: } else {
3262: $value = &unescape($value);
3263: }
3264: return $value;
3265: }
3266:
3267:
1.107 albertel 3268: sub relative_to_absolute {
3269: my ($url,$output)=@_;
3270: my $parser=HTML::TokeParser->new(\$output);
3271: my $token;
3272: my $thisdir=$url;
3273: my @rlinks=();
3274: while ($token=$parser->get_token) {
3275: if ($token->[0] eq 'S') {
3276: if ($token->[1] eq 'a') {
3277: if ($token->[2]->{'href'}) {
3278: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3279: }
3280: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3281: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3282: } elsif ($token->[1] eq 'base') {
3283: $thisdir=$token->[2]->{'href'};
3284: }
3285: }
3286: }
3287: $thisdir=~s-/[^/]*$--;
1.356 albertel 3288: foreach my $link (@rlinks) {
1.726 raeburn 3289: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3290: ($link=~/^\//) ||
3291: ($link=~/^javascript:/i) ||
3292: ($link=~/^mailto:/i) ||
3293: ($link=~/^\#/)) {
3294: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3295: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3296: }
3297: }
3298: # -------------------------------------------------- Deal with Applet codebases
3299: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3300: return $output;
3301: }
3302:
1.112 bowersj2 3303: =pod
3304:
1.648 raeburn 3305: =item * &get_student_view()
1.112 bowersj2 3306:
3307: show a snapshot of what student was looking at
3308:
3309: =cut
3310:
1.10 albertel 3311: sub get_student_view {
1.186 albertel 3312: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3313: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3314: my (%form);
1.10 albertel 3315: my @elements=('symb','courseid','domain','username');
3316: foreach my $element (@elements) {
1.186 albertel 3317: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3318: }
1.186 albertel 3319: if (defined($moreenv)) {
3320: %form=(%form,%{$moreenv});
3321: }
1.236 albertel 3322: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3323: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3324: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3325: $userview=~s/\<body[^\>]*\>//gi;
3326: $userview=~s/\<\/body\>//gi;
3327: $userview=~s/\<html\>//gi;
3328: $userview=~s/\<\/html\>//gi;
3329: $userview=~s/\<head\>//gi;
3330: $userview=~s/\<\/head\>//gi;
3331: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3332: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3333: if (wantarray) {
3334: return ($userview,$response);
3335: } else {
3336: return $userview;
3337: }
3338: }
3339:
3340: sub get_student_view_with_retries {
3341: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3342:
3343: my $ok = 0; # True if we got a good response.
3344: my $content;
3345: my $response;
3346:
3347: # Try to get the student_view done. within the retries count:
3348:
3349: do {
3350: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3351: $ok = $response->is_success;
3352: if (!$ok) {
3353: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3354: }
3355: $retries--;
3356: } while (!$ok && ($retries > 0));
3357:
3358: if (!$ok) {
3359: $content = ''; # On error return an empty content.
3360: }
1.651 www 3361: if (wantarray) {
3362: return ($content, $response);
3363: } else {
3364: return $content;
3365: }
1.11 albertel 3366: }
3367:
1.112 bowersj2 3368: =pod
3369:
1.648 raeburn 3370: =item * &get_student_answers()
1.112 bowersj2 3371:
3372: show a snapshot of how student was answering problem
3373:
3374: =cut
3375:
1.11 albertel 3376: sub get_student_answers {
1.100 sakharuk 3377: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3378: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3379: my (%moreenv);
1.11 albertel 3380: my @elements=('symb','courseid','domain','username');
3381: foreach my $element (@elements) {
1.186 albertel 3382: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3383: }
1.186 albertel 3384: $moreenv{'grade_target'}='answer';
3385: %moreenv=(%form,%moreenv);
1.497 raeburn 3386: $feedurl = &Apache::lonnet::clutter($feedurl);
3387: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3388: return $userview;
1.1 albertel 3389: }
1.116 albertel 3390:
3391: =pod
3392:
3393: =item * &submlink()
3394:
1.242 albertel 3395: Inputs: $text $uname $udom $symb $target
1.116 albertel 3396:
3397: Returns: A link to grades.pm such as to see the SUBM view of a student
3398:
3399: =cut
3400:
3401: ###############################################
3402: sub submlink {
1.242 albertel 3403: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3404: if (!($uname && $udom)) {
3405: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3406: &Apache::lonnet::whichuser($symb);
1.116 albertel 3407: if (!$symb) { $symb=$cursymb; }
3408: }
1.254 matthew 3409: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3410: $symb=&escape($symb);
1.242 albertel 3411: if ($target) { $target="target=\"$target\""; }
3412: return '<a href="/adm/grades?&command=submission&'.
3413: 'symb='.$symb.'&student='.$uname.
3414: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3415: }
3416: ##############################################
3417:
3418: =pod
3419:
3420: =item * &pgrdlink()
3421:
3422: Inputs: $text $uname $udom $symb $target
3423:
3424: Returns: A link to grades.pm such as to see the PGRD view of a student
3425:
3426: =cut
3427:
3428: ###############################################
3429: sub pgrdlink {
3430: my $link=&submlink(@_);
3431: $link=~s/(&command=submission)/$1&showgrading=yes/;
3432: return $link;
3433: }
3434: ##############################################
3435:
3436: =pod
3437:
3438: =item * &pprmlink()
3439:
3440: Inputs: $text $uname $udom $symb $target
3441:
3442: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3443: student and a specific resource
1.242 albertel 3444:
3445: =cut
3446:
3447: ###############################################
3448: sub pprmlink {
3449: my ($text,$uname,$udom,$symb,$target)=@_;
3450: if (!($uname && $udom)) {
3451: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3452: &Apache::lonnet::whichuser($symb);
1.242 albertel 3453: if (!$symb) { $symb=$cursymb; }
3454: }
1.254 matthew 3455: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3456: $symb=&escape($symb);
1.242 albertel 3457: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3458: return '<a href="/adm/parmset?command=set&'.
3459: 'symb='.$symb.'&uname='.$uname.
3460: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3461: }
3462: ##############################################
1.37 matthew 3463:
1.112 bowersj2 3464: =pod
3465:
3466: =back
3467:
3468: =cut
3469:
1.37 matthew 3470: ###############################################
1.51 www 3471:
3472:
3473: sub timehash {
1.687 raeburn 3474: my ($thistime) = @_;
3475: my $timezone = &Apache::lonlocal::gettimezone();
3476: my $dt = DateTime->from_epoch(epoch => $thistime)
3477: ->set_time_zone($timezone);
3478: my $wday = $dt->day_of_week();
3479: if ($wday == 7) { $wday = 0; }
3480: return ( 'second' => $dt->second(),
3481: 'minute' => $dt->minute(),
3482: 'hour' => $dt->hour(),
3483: 'day' => $dt->day_of_month(),
3484: 'month' => $dt->month(),
3485: 'year' => $dt->year(),
3486: 'weekday' => $wday,
3487: 'dayyear' => $dt->day_of_year(),
3488: 'dlsav' => $dt->is_dst() );
1.51 www 3489: }
3490:
1.370 www 3491: sub utc_string {
3492: my ($date)=@_;
1.371 www 3493: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3494: }
3495:
1.51 www 3496: sub maketime {
3497: my %th=@_;
1.687 raeburn 3498: my ($epoch_time,$timezone,$dt);
3499: $timezone = &Apache::lonlocal::gettimezone();
3500: eval {
3501: $dt = DateTime->new( year => $th{'year'},
3502: month => $th{'month'},
3503: day => $th{'day'},
3504: hour => $th{'hour'},
3505: minute => $th{'minute'},
3506: second => $th{'second'},
3507: time_zone => $timezone,
3508: );
3509: };
3510: if (!$@) {
3511: $epoch_time = $dt->epoch;
3512: if ($epoch_time) {
3513: return $epoch_time;
3514: }
3515: }
1.51 www 3516: return POSIX::mktime(
3517: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3518: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3519: }
3520:
3521: #########################################
1.51 www 3522:
3523: sub findallcourses {
1.482 raeburn 3524: my ($roles,$uname,$udom) = @_;
1.355 albertel 3525: my %roles;
3526: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3527: my %courses;
1.51 www 3528: my $now=time;
1.482 raeburn 3529: if (!defined($uname)) {
3530: $uname = $env{'user.name'};
3531: }
3532: if (!defined($udom)) {
3533: $udom = $env{'user.domain'};
3534: }
3535: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3536: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3537: if (!%roles) {
3538: %roles = (
3539: cc => 1,
3540: in => 1,
3541: ep => 1,
3542: ta => 1,
3543: cr => 1,
3544: st => 1,
3545: );
3546: }
3547: foreach my $entry (keys(%roleshash)) {
3548: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3549: if ($trole =~ /^cr/) {
3550: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3551: } else {
3552: next if (!exists($roles{$trole}));
3553: }
3554: if ($tend) {
3555: next if ($tend < $now);
3556: }
3557: if ($tstart) {
3558: next if ($tstart > $now);
3559: }
3560: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3561: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3562: if ($secpart eq '') {
3563: ($cnum,$role) = split(/_/,$cnumpart);
3564: $sec = 'none';
3565: $realsec = '';
3566: } else {
3567: $cnum = $cnumpart;
3568: ($sec,$role) = split(/_/,$secpart);
3569: $realsec = $sec;
1.490 raeburn 3570: }
1.482 raeburn 3571: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3572: }
3573: } else {
3574: foreach my $key (keys(%env)) {
1.483 albertel 3575: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3576: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3577: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3578: next if ($role eq 'ca' || $role eq 'aa');
3579: next if (%roles && !exists($roles{$role}));
3580: my ($starttime,$endtime)=split(/\./,$env{$key});
3581: my $active=1;
3582: if ($starttime) {
3583: if ($now<$starttime) { $active=0; }
3584: }
3585: if ($endtime) {
3586: if ($now>$endtime) { $active=0; }
3587: }
3588: if ($active) {
3589: if ($sec eq '') {
3590: $sec = 'none';
3591: }
3592: $courses{$cdom.'_'.$cnum}{$sec} =
3593: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3594: }
3595: }
1.51 www 3596: }
3597: }
1.474 raeburn 3598: return %courses;
1.51 www 3599: }
1.37 matthew 3600:
1.54 www 3601: ###############################################
1.474 raeburn 3602:
3603: sub blockcheck {
1.482 raeburn 3604: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3605:
3606: if (!defined($udom)) {
3607: $udom = $env{'user.domain'};
3608: }
3609: if (!defined($uname)) {
3610: $uname = $env{'user.name'};
3611: }
3612:
3613: # If uname and udom are for a course, check for blocks in the course.
3614:
3615: if (&Apache::lonnet::is_course($udom,$uname)) {
3616: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3617: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3618: return ($startblock,$endblock);
3619: }
1.474 raeburn 3620:
1.502 raeburn 3621: my $startblock = 0;
3622: my $endblock = 0;
1.482 raeburn 3623: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3624:
1.490 raeburn 3625: # If uname is for a user, and activity is course-specific, i.e.,
3626: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3627:
1.490 raeburn 3628: if (($activity eq 'boards' || $activity eq 'chat' ||
3629: $activity eq 'groups') && ($env{'request.course.id'})) {
3630: foreach my $key (keys(%live_courses)) {
3631: if ($key ne $env{'request.course.id'}) {
3632: delete($live_courses{$key});
3633: }
3634: }
3635: }
3636:
3637: my $otheruser = 0;
3638: my %own_courses;
3639: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3640: # Resource belongs to user other than current user.
3641: $otheruser = 1;
3642: # Gather courses for current user
3643: %own_courses =
3644: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3645: }
3646:
3647: # Gather active course roles - course coordinator, instructor,
3648: # exam proctor, ta, student, or custom role.
1.474 raeburn 3649:
3650: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3651: my ($cdom,$cnum);
3652: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3653: $cdom = $env{'course.'.$course.'.domain'};
3654: $cnum = $env{'course.'.$course.'.num'};
3655: } else {
1.490 raeburn 3656: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3657: }
3658: my $no_ownblock = 0;
3659: my $no_userblock = 0;
1.533 raeburn 3660: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3661: # Check if current user has 'evb' priv for this
3662: if (defined($own_courses{$course})) {
3663: foreach my $sec (keys(%{$own_courses{$course}})) {
3664: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3665: if ($sec ne 'none') {
3666: $checkrole .= '/'.$sec;
3667: }
3668: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3669: $no_ownblock = 1;
3670: last;
3671: }
3672: }
3673: }
3674: # if they have 'evb' priv and are currently not playing student
3675: next if (($no_ownblock) &&
3676: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3677: }
1.474 raeburn 3678: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3679: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3680: if ($sec ne 'none') {
1.482 raeburn 3681: $checkrole .= '/'.$sec;
1.474 raeburn 3682: }
1.490 raeburn 3683: if ($otheruser) {
3684: # Resource belongs to user other than current user.
3685: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3686: my ($trole,$tdom,$tnum,$tsec);
3687: my $entry = $live_courses{$course}{$sec};
3688: if ($entry =~ /^cr/) {
3689: ($trole,$tdom,$tnum,$tsec) =
3690: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3691: } else {
3692: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3693: }
3694: my ($spec,$area,$trest,%allroles,%userroles);
3695: $area = '/'.$tdom.'/'.$tnum;
3696: $trest = $tnum;
3697: if ($tsec ne '') {
3698: $area .= '/'.$tsec;
3699: $trest .= '/'.$tsec;
3700: }
3701: $spec = $trole.'.'.$area;
3702: if ($trole =~ /^cr/) {
3703: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3704: $tdom,$spec,$trest,$area);
3705: } else {
3706: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3707: $tdom,$spec,$trest,$area);
3708: }
3709: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3710: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3711: if ($1) {
3712: $no_userblock = 1;
3713: last;
3714: }
3715: }
1.490 raeburn 3716: } else {
3717: # Resource belongs to current user
3718: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3719: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3720: $no_ownblock = 1;
3721: last;
3722: }
1.474 raeburn 3723: }
3724: }
3725: # if they have the evb priv and are currently not playing student
1.482 raeburn 3726: next if (($no_ownblock) &&
1.491 albertel 3727: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3728: next if ($no_userblock);
1.474 raeburn 3729:
1.490 raeburn 3730: # Retrieve blocking times and identity of blocker for course
3731: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3732:
3733: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3734: if (($start != 0) &&
3735: (($startblock == 0) || ($startblock > $start))) {
3736: $startblock = $start;
3737: }
3738: if (($end != 0) &&
3739: (($endblock == 0) || ($endblock < $end))) {
3740: $endblock = $end;
3741: }
1.490 raeburn 3742: }
3743: return ($startblock,$endblock);
3744: }
3745:
3746: sub get_blocks {
3747: my ($setters,$activity,$cdom,$cnum) = @_;
3748: my $startblock = 0;
3749: my $endblock = 0;
3750: my $course = $cdom.'_'.$cnum;
3751: $setters->{$course} = {};
3752: $setters->{$course}{'staff'} = [];
3753: $setters->{$course}{'times'} = [];
3754: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3755: foreach my $record (keys(%records)) {
3756: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3757: if ($start <= time && $end >= time) {
3758: my ($staff_name,$staff_dom,$title,$blocks) =
3759: &parse_block_record($records{$record});
3760: if ($blocks->{$activity} eq 'on') {
3761: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3762: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3763: if ( ($startblock == 0) || ($startblock > $start) ) {
3764: $startblock = $start;
1.490 raeburn 3765: }
1.491 albertel 3766: if ( ($endblock == 0) || ($endblock < $end) ) {
3767: $endblock = $end;
1.474 raeburn 3768: }
3769: }
3770: }
3771: }
3772: return ($startblock,$endblock);
3773: }
3774:
3775: sub parse_block_record {
3776: my ($record) = @_;
3777: my ($setuname,$setudom,$title,$blocks);
3778: if (ref($record) eq 'HASH') {
3779: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3780: $title = &unescape($record->{'event'});
3781: $blocks = $record->{'blocks'};
3782: } else {
3783: my @data = split(/:/,$record,3);
3784: if (scalar(@data) eq 2) {
3785: $title = $data[1];
3786: ($setuname,$setudom) = split(/@/,$data[0]);
3787: } else {
3788: ($setuname,$setudom,$title) = @data;
3789: }
3790: $blocks = { 'com' => 'on' };
3791: }
3792: return ($setuname,$setudom,$title,$blocks);
3793: }
3794:
3795: sub build_block_table {
3796: my ($startblock,$endblock,$setters) = @_;
3797: my %lt = &Apache::lonlocal::texthash(
3798: 'cacb' => 'Currently active communication blocks',
3799: 'cour' => 'Course',
3800: 'dura' => 'Duration',
3801: 'blse' => 'Block set by'
3802: );
3803: my $output;
1.476 raeburn 3804: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3805: $output .= &start_data_table();
3806: $output .= '
3807: <tr>
3808: <th>'.$lt{'cour'}.'</th>
3809: <th>'.$lt{'dura'}.'</th>
3810: <th>'.$lt{'blse'}.'</th>
3811: </tr>
3812: ';
3813: foreach my $course (keys(%{$setters})) {
3814: my %courseinfo=&Apache::lonnet::coursedescription($course);
3815: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3816: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3817: my $fullname = &plainname($uname,$udom);
3818: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3819: && $env{'user.name'} ne 'public'
3820: && $env{'user.domain'} ne 'public') {
3821: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3822: }
1.474 raeburn 3823: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3824: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3825: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3826: $output .= &Apache::loncommon::start_data_table_row().
3827: '<td>'.$courseinfo{'description'}.'</td>'.
3828: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3829: '<td>'.$fullname.'</td>'.
1.474 raeburn 3830: &Apache::loncommon::end_data_table_row();
3831: }
3832: }
3833: $output .= &end_data_table();
3834: }
3835:
1.490 raeburn 3836: sub blocking_status {
3837: my ($activity,$uname,$udom) = @_;
3838: my %setters;
3839: my ($blocked,$output,$ownitem,$is_course);
3840: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3841: if ($startblock && $endblock) {
3842: $blocked = 1;
3843: if (wantarray) {
3844: my $category;
3845: if ($activity eq 'boards') {
3846: $category = 'Discussion posts in this course';
3847: } elsif ($activity eq 'blogs') {
3848: $category = 'Blogs';
3849: } elsif ($activity eq 'port') {
3850: if (defined($uname) && defined($udom)) {
3851: if ($uname eq $env{'user.name'} &&
3852: $udom eq $env{'user.domain'}) {
3853: $ownitem = 1;
3854: }
3855: }
3856: $is_course = &Apache::lonnet::is_course($udom,$uname);
3857: if ($ownitem) {
3858: $category = 'Your portfolio files';
3859: } elsif ($is_course) {
3860: my $coursedesc;
3861: foreach my $course (keys(%setters)) {
3862: my %courseinfo =
3863: &Apache::lonnet::coursedescription($course);
3864: $coursedesc = $courseinfo{'description'};
3865: }
1.764 weissno 3866: $category = "Group portfolio in the course '$coursedesc'";
1.490 raeburn 3867: } else {
3868: $category = 'Portfolio files belonging to ';
3869: if ($env{'user.name'} eq 'public' &&
3870: $env{'user.domain'} eq 'public') {
3871: $category .= &plainname($uname,$udom);
3872: } else {
3873: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3874: }
3875: }
3876: } elsif ($activity eq 'groups') {
3877: $category = 'Groups in this course';
3878: }
3879: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3880: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3881: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3882: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3883: $output .= &build_block_table($startblock,$endblock,\%setters);
3884: }
3885: }
3886: }
3887: if (wantarray) {
3888: return ($blocked,$output);
3889: } else {
3890: return $blocked;
3891: }
3892: }
3893:
1.60 matthew 3894: ###############################################
3895:
1.682 raeburn 3896: sub check_ip_acc {
3897: my ($acc)=@_;
3898: &Apache::lonxml::debug("acc is $acc");
3899: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3900: return 1;
3901: }
3902: my $allowed=0;
3903: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3904:
3905: my $name;
3906: foreach my $pattern (split(',',$acc)) {
3907: $pattern =~ s/^\s*//;
3908: $pattern =~ s/\s*$//;
3909: if ($pattern =~ /\*$/) {
3910: #35.8.*
3911: $pattern=~s/\*//;
3912: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3913: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3914: #35.8.3.[34-56]
3915: my $low=$2;
3916: my $high=$3;
3917: $pattern=$1;
3918: if ($ip =~ /^\Q$pattern\E/) {
3919: my $last=(split(/\./,$ip))[3];
3920: if ($last <=$high && $last >=$low) { $allowed=1; }
3921: }
3922: } elsif ($pattern =~ /^\*/) {
3923: #*.msu.edu
3924: $pattern=~s/\*//;
3925: if (!defined($name)) {
3926: use Socket;
3927: my $netaddr=inet_aton($ip);
3928: ($name)=gethostbyaddr($netaddr,AF_INET);
3929: }
3930: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3931: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3932: #127.0.0.1
3933: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3934: } else {
3935: #some.name.com
3936: if (!defined($name)) {
3937: use Socket;
3938: my $netaddr=inet_aton($ip);
3939: ($name)=gethostbyaddr($netaddr,AF_INET);
3940: }
3941: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3942: }
3943: if ($allowed) { last; }
3944: }
3945: return $allowed;
3946: }
3947:
3948: ###############################################
3949:
1.60 matthew 3950: =pod
3951:
1.112 bowersj2 3952: =head1 Domain Template Functions
3953:
3954: =over 4
3955:
3956: =item * &determinedomain()
1.60 matthew 3957:
3958: Inputs: $domain (usually will be undef)
3959:
1.63 www 3960: Returns: Determines which domain should be used for designs
1.60 matthew 3961:
3962: =cut
1.54 www 3963:
1.60 matthew 3964: ###############################################
1.63 www 3965: sub determinedomain {
3966: my $domain=shift;
1.531 albertel 3967: if (! $domain) {
1.60 matthew 3968: # Determine domain if we have not been given one
3969: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3970: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3971: if ($env{'request.role.domain'}) {
3972: $domain=$env{'request.role.domain'};
1.60 matthew 3973: }
3974: }
1.63 www 3975: return $domain;
3976: }
3977: ###############################################
1.517 raeburn 3978:
1.518 albertel 3979: sub devalidate_domconfig_cache {
3980: my ($udom)=@_;
3981: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3982: }
3983:
3984: # ---------------------- Get domain configuration for a domain
3985: sub get_domainconf {
3986: my ($udom) = @_;
3987: my $cachetime=1800;
3988: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3989: if (defined($cached)) { return %{$result}; }
3990:
3991: my %domconfig = &Apache::lonnet::get_dom('configuration',
3992: ['login','rolecolors'],$udom);
1.632 raeburn 3993: my (%designhash,%legacy);
1.518 albertel 3994: if (keys(%domconfig) > 0) {
3995: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3996: if (keys(%{$domconfig{'login'}})) {
3997: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3998: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3999: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4000: $designhash{$udom.'.login.'.$key.'_'.$img} =
4001: $domconfig{'login'}{$key}{$img};
4002: }
4003: } else {
4004: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4005: }
1.632 raeburn 4006: }
4007: } else {
4008: $legacy{'login'} = 1;
1.518 albertel 4009: }
1.632 raeburn 4010: } else {
4011: $legacy{'login'} = 1;
1.518 albertel 4012: }
4013: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4014: if (keys(%{$domconfig{'rolecolors'}})) {
4015: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4016: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4017: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4018: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4019: }
1.518 albertel 4020: }
4021: }
1.632 raeburn 4022: } else {
4023: $legacy{'rolecolors'} = 1;
1.518 albertel 4024: }
1.632 raeburn 4025: } else {
4026: $legacy{'rolecolors'} = 1;
1.518 albertel 4027: }
1.632 raeburn 4028: if (keys(%legacy) > 0) {
4029: my %legacyhash = &get_legacy_domconf($udom);
4030: foreach my $item (keys(%legacyhash)) {
4031: if ($item =~ /^\Q$udom\E\.login/) {
4032: if ($legacy{'login'}) {
4033: $designhash{$item} = $legacyhash{$item};
4034: }
4035: } else {
4036: if ($legacy{'rolecolors'}) {
4037: $designhash{$item} = $legacyhash{$item};
4038: }
1.518 albertel 4039: }
4040: }
4041: }
1.632 raeburn 4042: } else {
4043: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4044: }
4045: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4046: $cachetime);
4047: return %designhash;
4048: }
4049:
1.632 raeburn 4050: sub get_legacy_domconf {
4051: my ($udom) = @_;
4052: my %legacyhash;
4053: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4054: my $designfile = $designdir.'/'.$udom.'.tab';
4055: if (-e $designfile) {
4056: if ( open (my $fh,"<$designfile") ) {
4057: while (my $line = <$fh>) {
4058: next if ($line =~ /^\#/);
4059: chomp($line);
4060: my ($key,$val)=(split(/\=/,$line));
4061: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4062: }
4063: close($fh);
4064: }
4065: }
4066: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4067: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4068: }
4069: return %legacyhash;
4070: }
4071:
1.63 www 4072: =pod
4073:
1.112 bowersj2 4074: =item * &domainlogo()
1.63 www 4075:
4076: Inputs: $domain (usually will be undef)
4077:
4078: Returns: A link to a domain logo, if the domain logo exists.
4079: If the domain logo does not exist, a description of the domain.
4080:
4081: =cut
1.112 bowersj2 4082:
1.63 www 4083: ###############################################
4084: sub domainlogo {
1.517 raeburn 4085: my $domain = &determinedomain(shift);
1.518 albertel 4086: my %designhash = &get_domainconf($domain);
1.517 raeburn 4087: # See if there is a logo
4088: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4089: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4090: if ($imgsrc =~ m{^/(adm|res)/}) {
4091: if ($imgsrc =~ m{^/res/}) {
4092: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4093: &Apache::lonnet::repcopy($local_name);
4094: }
4095: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4096: }
4097: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4098: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4099: return &Apache::lonnet::domain($domain,'description');
1.59 www 4100: } else {
1.60 matthew 4101: return '';
1.59 www 4102: }
4103: }
1.63 www 4104: ##############################################
4105:
4106: =pod
4107:
1.112 bowersj2 4108: =item * &designparm()
1.63 www 4109:
4110: Inputs: $which parameter; $domain (usually will be undef)
4111:
4112: Returns: value of designparamter $which
4113:
4114: =cut
1.112 bowersj2 4115:
1.397 albertel 4116:
1.400 albertel 4117: ##############################################
1.397 albertel 4118: sub designparm {
4119: my ($which,$domain)=@_;
1.258 albertel 4120: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4121: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4122: return '#000000';
4123: }
1.635 raeburn 4124: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4125: return '#FFFFFF';
4126: }
4127: if ($which=~/\.tabbg$/) {
4128: return '#CCCCCC';
4129: }
4130: }
1.397 albertel 4131: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4132: return $env{'environment.color.'.$which};
1.96 www 4133: }
1.63 www 4134: $domain=&determinedomain($domain);
1.518 albertel 4135: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4136: my $output;
1.517 raeburn 4137: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4138: $output = $domdesign{$domain.'.'.$which};
1.63 www 4139: } else {
1.520 raeburn 4140: $output = $defaultdesign{$which};
4141: }
4142: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4143: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4144: if ($output =~ m{^/(adm|res)/}) {
4145: if ($output =~ m{^/res/}) {
4146: my $local_name = &Apache::lonnet::filelocation('',$output);
4147: &Apache::lonnet::repcopy($local_name);
4148: }
1.520 raeburn 4149: $output = &lonhttpdurl($output);
4150: }
1.63 www 4151: }
1.520 raeburn 4152: return $output;
1.63 www 4153: }
1.59 www 4154:
1.60 matthew 4155: ###############################################
4156: ###############################################
4157:
4158: =pod
4159:
1.112 bowersj2 4160: =back
4161:
1.549 albertel 4162: =head1 HTML Helpers
1.112 bowersj2 4163:
4164: =over 4
4165:
4166: =item * &bodytag()
1.60 matthew 4167:
4168: Returns a uniform header for LON-CAPA web pages.
4169:
4170: Inputs:
4171:
1.112 bowersj2 4172: =over 4
4173:
4174: =item * $title, A title to be displayed on the page.
4175:
4176: =item * $function, the current role (can be undef).
4177:
4178: =item * $addentries, extra parameters for the <body> tag.
4179:
4180: =item * $bodyonly, if defined, only return the <body> tag.
4181:
4182: =item * $domain, if defined, force a given domain.
4183:
4184: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4185: text interface only)
1.60 matthew 4186:
1.326 albertel 4187: =item * $customtitle, alternate text to use instead of $title
4188: in the title box that appears, this text
4189: is not auto translated like the $title is
1.309 albertel 4190:
4191: =item * $notopbar, if true, keep the 'what is this' info but remove the
4192: navigational links
1.317 albertel 4193:
1.338 albertel 4194: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4195:
4196: =item * $notitle, if true keep the nav controls, but remove the title bar
4197:
1.361 albertel 4198: =item * $no_inline_link, if true and in remote mode, don't show the
4199: 'Switch To Inline Menu' link
4200:
1.460 albertel 4201: =item * $args, optional argument valid values are
4202: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4203: inherit_jsmath -> when creating popup window in a page,
4204: should it have jsmath forced on by the
4205: current page
1.460 albertel 4206:
1.112 bowersj2 4207: =back
4208:
1.60 matthew 4209: Returns: A uniform header for LON-CAPA web pages.
4210: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4211: If $bodyonly is undef or zero, an html string containing a <body> tag and
4212: other decorations will be returned.
4213:
4214: =cut
4215:
1.54 www 4216: sub bodytag {
1.309 albertel 4217: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4218: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4219:
1.460 albertel 4220: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4221:
1.183 matthew 4222: $function = &get_users_function() if (!$function);
1.339 albertel 4223: my $img = &designparm($function.'.img',$domain);
4224: my $font = &designparm($function.'.font',$domain);
4225: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4226:
4227: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4228: 'bgcolor' => $pgbg,
1.339 albertel 4229: 'text' => $font,
4230: 'alink' => &designparm($function.'.alink',$domain),
4231: 'vlink' => &designparm($function.'.vlink',$domain),
4232: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4233: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4234:
1.63 www 4235: # role and realm
1.378 raeburn 4236: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4237: if ($role eq 'ca') {
1.479 albertel 4238: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4239: $realm = &plainname($rname,$rdom);
1.378 raeburn 4240: }
1.55 www 4241: # realm
1.258 albertel 4242: if ($env{'request.course.id'}) {
1.378 raeburn 4243: if ($env{'request.role'} !~ /^cr/) {
4244: $role = &Apache::lonnet::plaintext($role,&course_type());
4245: }
1.359 albertel 4246: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4247: } else {
4248: $role = &Apache::lonnet::plaintext($role);
1.54 www 4249: }
1.433 albertel 4250:
1.359 albertel 4251: if (!$realm) { $realm=' '; }
1.55 www 4252: # Set messages
1.60 matthew 4253: my $messages=&domainlogo($domain);
1.330 albertel 4254:
1.438 albertel 4255: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4256:
1.101 www 4257: # construct main body tag
1.359 albertel 4258: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4259: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4260:
1.530 albertel 4261: if ($bodyonly) {
1.60 matthew 4262: return $bodytag;
1.798 ! tempelho 4263: }
1.359 albertel 4264:
1.410 albertel 4265: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4266: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4267: undef($role);
1.434 albertel 4268: } else {
4269: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4270: }
1.359 albertel 4271:
4272: my $roleinfo=(<<ENDROLE);
4273: <td class="LC_title_bar_who">
4274: <div class="LC_title_bar_name">
1.410 albertel 4275: $name
1.361 albertel 4276:
1.359 albertel 4277: </div>
4278: <div class="LC_title_bar_role">
1.361 albertel 4279: $role
1.359 albertel 4280: </div>
4281: <div class="LC_title_bar_realm">
1.361 albertel 4282: $realm
1.359 albertel 4283: </div>
1.206 albertel 4284: </td>
4285: ENDROLE
1.235 raeburn 4286:
1.762 bisitz 4287: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4288: if ($customtitle) {
4289: $titleinfo = $customtitle;
4290: }
4291: #
4292: # Extra info if you are the DC
4293: my $dc_info = '';
4294: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4295: $env{'course.'.$env{'request.course.id'}.
4296: '.domain'}.'/'})) {
4297: my $cid = $env{'request.course.id'};
4298: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4299: $dc_info =~ s/\s+$//;
1.359 albertel 4300: $dc_info = '('.$dc_info.')';
4301: }
4302:
1.644 www 4303: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4304: # No Remote
1.258 albertel 4305: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4306: $forcereg=1;
4307: }
4308:
4309: if (!$customtitle && $env{'request.state'} eq 'construct') {
4310: # this is for resources; directories have customtitle, and crumbs
4311: # and select recent are created in lonpubdir.pm
1.229 albertel 4312: my ($uname,$thisdisfn)=
1.258 albertel 4313: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4314: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4315: $formaction=~s/\/+/\//g;
4316:
1.359 albertel 4317: my $parentpath = '';
4318: my $lastitem = '';
4319: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4320: $parentpath = $1;
4321: $lastitem = $2;
4322: } else {
4323: $lastitem = $thisdisfn;
4324: }
4325: $titleinfo =
1.640 bisitz 4326: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4327: .'<b>'.&mt('Construction Space').'</b>: '
4328: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4329: .'" target="_top"><tt><b>'
1.705 tempelho 4330: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4331: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4332: .'</form>'
4333: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4334: }
1.359 albertel 4335:
1.337 albertel 4336: my $titletable;
1.338 albertel 4337: if (!$notitle) {
1.337 albertel 4338: $titletable =
1.359 albertel 4339: '<table id="LC_title_bar">'.
4340: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4341: '</tr></table>';
1.337 albertel 4342: }
1.359 albertel 4343: if ($notopbar) {
4344: $bodytag .= $titletable;
4345: } else {
4346: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4347: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4348: $titletable);
1.272 raeburn 4349: } else {
1.336 albertel 4350: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4351: $titletable;
1.272 raeburn 4352: }
1.235 raeburn 4353: }
4354: return $bodytag;
1.94 www 4355: }
1.95 www 4356:
1.93 www 4357: #
1.95 www 4358: # Top frame rendering, Remote is up
1.93 www 4359: #
1.359 albertel 4360:
1.517 raeburn 4361: my $imgsrc = $img;
4362: if ($img =~ /^\/adm/) {
1.575 albertel 4363: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4364: }
4365: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4366:
1.305 www 4367: # Explicit link to get inline menu
1.361 albertel 4368: my $menu= ($no_inline_link?''
4369: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4370: #
1.338 albertel 4371: if ($notitle) {
1.337 albertel 4372: return $bodytag;
4373: }
1.94 www 4374: return(<<ENDBODY);
1.60 matthew 4375: $bodytag
1.359 albertel 4376: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4377: <tr><td>$upperleft</td>
4378: <td>$messages </td>
1.54 www 4379: </tr>
1.359 albertel 4380: <tr><td>$titleinfo $dc_info $menu</td>
4381: $roleinfo
1.368 albertel 4382: </tr>
1.356 albertel 4383: </table>
1.54 www 4384: ENDBODY
1.182 matthew 4385: }
4386:
1.330 albertel 4387: sub make_attr_string {
4388: my ($register,$attr_ref) = @_;
4389:
4390: if ($attr_ref && !ref($attr_ref)) {
4391: die("addentries Must be a hash ref ".
4392: join(':',caller(1))." ".
4393: join(':',caller(0))." ");
4394: }
4395:
4396: if ($register) {
1.339 albertel 4397: my ($on_load,$on_unload);
4398: foreach my $key (keys(%{$attr_ref})) {
4399: if (lc($key) eq 'onload') {
4400: $on_load.=$attr_ref->{$key}.';';
4401: delete($attr_ref->{$key});
4402:
4403: } elsif (lc($key) eq 'onunload') {
4404: $on_unload.=$attr_ref->{$key}.';';
4405: delete($attr_ref->{$key});
4406: }
4407: }
4408: $attr_ref->{'onload'} =
4409: &Apache::lonmenu::loadevents(). $on_load;
4410: $attr_ref->{'onunload'}=
4411: &Apache::lonmenu::unloadevents().$on_unload;
4412: }
4413:
4414: # Accessibility font enhance
4415: if ($env{'browser.fontenhance'} eq 'on') {
4416: my $style;
4417: foreach my $key (keys(%{$attr_ref})) {
4418: if (lc($key) eq 'style') {
4419: $style.=$attr_ref->{$key}.';';
4420: delete($attr_ref->{$key});
4421: }
4422: }
4423: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4424: }
1.339 albertel 4425:
4426: if ($env{'browser.blackwhite'} eq 'on') {
4427: delete($attr_ref->{'font'});
4428: delete($attr_ref->{'link'});
4429: delete($attr_ref->{'alink'});
4430: delete($attr_ref->{'vlink'});
4431: delete($attr_ref->{'bgcolor'});
4432: delete($attr_ref->{'background'});
4433: }
4434:
1.330 albertel 4435: my $attr_string;
4436: foreach my $attr (keys(%$attr_ref)) {
4437: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4438: }
4439: return $attr_string;
4440: }
4441:
4442:
1.182 matthew 4443: ###############################################
1.251 albertel 4444: ###############################################
4445:
4446: =pod
4447:
4448: =item * &endbodytag()
4449:
4450: Returns a uniform footer for LON-CAPA web pages.
4451:
1.635 raeburn 4452: Inputs: 1 - optional reference to an args hash
4453: If in the hash, key for noredirectlink has a value which evaluates to true,
4454: a 'Continue' link is not displayed if the page contains an
4455: internal redirect in the <head></head> section,
4456: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4457:
4458: =cut
4459:
4460: sub endbodytag {
1.635 raeburn 4461: my ($args) = @_;
1.251 albertel 4462: my $endbodytag='</body>';
1.269 albertel 4463: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4464: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4465: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4466: $endbodytag=
4467: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4468: &mt('Continue').'</a>'.
4469: $endbodytag;
4470: }
1.315 albertel 4471: }
1.251 albertel 4472: return $endbodytag;
4473: }
4474:
1.352 albertel 4475: =pod
4476:
4477: =item * &standard_css()
4478:
4479: Returns a style sheet
4480:
4481: Inputs: (all optional)
4482: domain -> force to color decorate a page for a specific
4483: domain
4484: function -> force usage of a specific rolish color scheme
4485: bgcolor -> override the default page bgcolor
4486:
4487: =cut
4488:
1.343 albertel 4489: sub standard_css {
1.345 albertel 4490: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4491: $function = &get_users_function() if (!$function);
4492: my $img = &designparm($function.'.img', $domain);
4493: my $tabbg = &designparm($function.'.tabbg', $domain);
4494: my $font = &designparm($function.'.font', $domain);
1.791 tempelho 4495: #second colour for later usage
1.345 albertel 4496: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4497: my $pgbg_or_bgcolor =
4498: $bgcolor ||
1.352 albertel 4499: &designparm($function.'.pgbg', $domain);
1.382 albertel 4500: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4501: my $alink = &designparm($function.'.alink', $domain);
4502: my $vlink = &designparm($function.'.vlink', $domain);
4503: my $link = &designparm($function.'.link', $domain);
4504:
1.704 muellerd 4505: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4506: my $bgcol = &designparm('login.bgcol',$domain);
4507: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4508:
1.602 albertel 4509: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4510: my $mono = 'monospace';
1.352 albertel 4511: my $data_table_head = $tabbg;
4512: my $data_table_light = '#EEEEEE';
1.470 banghart 4513: my $data_table_dark = '#DDDDDD';
4514: my $data_table_darker = '#CCCCCC';
1.349 albertel 4515: my $data_table_highlight = '#FFFF00';
1.352 albertel 4516: my $mail_new = '#FFBB77';
4517: my $mail_new_hover = '#DD9955';
4518: my $mail_read = '#BBBB77';
4519: my $mail_read_hover = '#999944';
4520: my $mail_replied = '#AAAA88';
4521: my $mail_replied_hover = '#888855';
4522: my $mail_other = '#99BBBB';
4523: my $mail_other_hover = '#669999';
1.391 albertel 4524: my $table_header = '#DDDDDD';
1.489 raeburn 4525: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4526: my $lg_border_color = '#C8C8C8';
1.392 albertel 4527:
1.608 albertel 4528: my $border = ($env{'browser.type'} eq 'explorer' ||
4529: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4530: : '0px 3px 0px 4px';
1.448 albertel 4531:
1.523 albertel 4532:
1.343 albertel 4533: return <<END;
1.795 www 4534: body {
4535: font-family: $sans;
4536: line-height:130%;
4537: font-size:0.83em;
4538: color:$font;
4539: }
4540:
4541: a:link, a:visited {
4542: font-size:100%;
4543: }
4544:
4545: a:focus {
4546: color: red;
4547: background: yellow
4548: }
1.698 harmsja 4549:
1.510 albertel 4550: table.thinborder,
4551: table.thinborder tr th {
4552: border-style: solid;
4553: border-width: 1px;
1.698 harmsja 4554: border-color: $lg_border_color;
1.510 albertel 4555: background: $tabbg;
4556: }
1.795 www 4557:
1.523 albertel 4558: table.thinborder tr td {
1.510 albertel 4559: border-style: solid;
1.698 harmsja 4560: border-width: 1px;
4561: border-color: $lg_border_color;
1.510 albertel 4562: }
1.426 albertel 4563:
1.795 www 4564: form, .inline {
4565: display: inline;
4566: }
1.721 harmsja 4567:
1.795 www 4568: .LC_right {
4569: text-align:right;
4570: }
4571:
4572: .LC_middle {
4573: vertical-align:middle;
4574: }
1.721 harmsja 4575:
4576: /* just for tests */
1.754 droeschl 4577: .LC_400Box {width:400px; }
1.721 harmsja 4578: /* end */
4579:
1.778 bisitz 4580: .LC_filename {
4581: font-family: $mono;
4582: white-space:pre;
4583: }
4584:
4585: .LC_fileicon {
4586: border: none;
4587: height: 1.3em;
4588: vertical-align: text-bottom;
4589: margin-right: 0.3em;
4590: text-decoration:none;
4591: }
4592:
1.350 albertel 4593: .LC_error {
4594: color: red;
4595: font-size: larger;
4596: }
1.795 www 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.795 www 4608:
1.543 albertel 4609: .LC_unknown {
4610: color: yellow;
4611: }
4612:
1.440 albertel 4613: .LC_icon {
1.771 droeschl 4614: border: none;
1.790 droeschl 4615: vertical-align: middle;
1.771 droeschl 4616: }
4617:
1.539 albertel 4618: .LC_indexer_icon {
4619: border: 0px;
4620: height: 22px;
4621: }
1.795 www 4622:
1.543 albertel 4623: .LC_docs_spacer {
4624: width: 25px;
4625: height: 1px;
1.771 droeschl 4626: border: none;
1.543 albertel 4627: }
1.346 albertel 4628:
1.532 albertel 4629: .LC_internal_info {
1.735 bisitz 4630: color: #999999;
1.532 albertel 4631: }
4632:
1.794 www 4633: .LC_discussion {
4634: background: $tabbg;
4635: border: 1px solid black;
4636: margin: 2px;
4637: }
4638:
4639: .LC_disc_action_links_bar {
4640: background: $tabbg;
4641: font-family: $sans;
4642: border: 0px;
1.795 www 4643: margin: 4px;
1.794 www 4644: }
4645:
4646: .LC_disc_action_left {
4647: text-align: left;
4648: }
4649:
4650: .LC_disc_action_right {
4651: text-align: right;
4652: }
4653:
4654: .LC_disc_new_item {
4655: background: white;
4656: border: 2px solid red;
4657: margin: 2px;
4658: }
4659:
4660: .LC_disc_old_item {
4661: background: white;
4662: border: 1px solid black;
4663: margin: 2px;
4664: }
4665:
1.458 albertel 4666: table.LC_pastsubmission {
4667: border: 1px solid black;
4668: margin: 2px;
4669: }
4670:
1.795 www 4671: table#LC_top_nav,
4672: table#LC_menubuttons,
4673: table#LC_nav_location {
1.345 albertel 4674: width: 100%;
4675: background: $pgbg;
1.392 albertel 4676: border: 2px;
1.402 albertel 4677: border-collapse: separate;
1.403 albertel 4678: padding: 0px;
1.345 albertel 4679: }
1.392 albertel 4680:
1.795 www 4681: table#LC_title_bar,
4682: table.LC_breadcrumbs,
1.393 albertel 4683: table#LC_title_bar.LC_with_remote {
1.359 albertel 4684: width: 100%;
1.392 albertel 4685: border-color: $pgbg;
4686: border-style: solid;
4687: border-width: $border;
1.379 albertel 4688: background: $pgbg;
4689: font-family: $sans;
1.392 albertel 4690: border-collapse: collapse;
1.403 albertel 4691: padding: 0px;
1.359 albertel 4692: }
1.795 www 4693:
1.409 albertel 4694: table.LC_docs_path {
4695: width: 100%;
4696: border: 0;
4697: background: $pgbg;
4698: font-family: $sans;
4699: border-collapse: collapse;
4700: padding: 0px;
4701: }
4702:
1.359 albertel 4703: table#LC_title_bar td {
4704: background: $tabbg;
4705: }
1.795 www 4706:
1.773 ehlerst 4707: table#LC_title_bar .LC_title_bar_who {
1.359 albertel 4708: background: $tabbg;
4709: color: $font;
1.427 albertel 4710: font: small $sans;
1.359 albertel 4711: text-align: right;
1.773 ehlerst 4712: margin: 0px;
4713: }
1.795 www 4714:
1.773 ehlerst 4715: table#LC_title_bar .LC_title_bar_name {
4716: margin: 0px;
4717: }
1.795 www 4718:
1.773 ehlerst 4719: table#LC_title_bar .LC_title_bar_role {
4720: margin: 0px;
4721: }
1.795 www 4722:
1.775 bisitz 4723: table#LC_title_bar .LC_title_bar_realm {
1.773 ehlerst 4724: margin: 0px;
1.359 albertel 4725: }
1.795 www 4726:
1.469 banghart 4727: span.LC_metadata {
1.795 www 4728: font-family: $sans;
1.469 banghart 4729: }
1.359 albertel 4730:
1.706 harmsja 4731: table#LC_menubuttons img{
1.346 albertel 4732: border: 0px;
4733: }
1.795 www 4734:
1.345 albertel 4735: table#LC_top_nav td {
4736: background: $tabbg;
1.392 albertel 4737: border: 0px;
1.407 albertel 4738: font-size: small;
1.706 harmsja 4739: vertical-align:top;
4740: padding:2px 5px 2px 5px;
1.345 albertel 4741: }
1.795 www 4742:
4743: table#LC_top_nav td a,
4744: div#LC_top_nav a {
1.345 albertel 4745: color: $font;
4746: font-family: $sans;
4747: }
1.795 www 4748:
1.364 albertel 4749: table#LC_top_nav td.LC_top_nav_logo {
4750: background: $tabbg;
1.432 albertel 4751: text-align: left;
1.408 albertel 4752: white-space: nowrap;
1.432 albertel 4753: width: 31px;
1.408 albertel 4754: }
1.795 www 4755:
1.408 albertel 4756: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4757: border: 0px;
1.408 albertel 4758: vertical-align: bottom;
1.364 albertel 4759: }
1.795 www 4760:
1.777 tempelho 4761: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4762: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4763: width: 2.0em;
4764: }
1.795 www 4765:
1.442 albertel 4766: table#LC_top_nav td.LC_top_nav_login {
4767: width: 4.0em;
4768: text-align: center;
4769: }
1.795 www 4770:
4771: table.LC_breadcrumbs td,
4772: table.LC_docs_path td {
1.357 albertel 4773: background: $tabbg;
4774: color: $font;
4775: font-family: $sans;
1.358 albertel 4776: font-size: smaller;
1.357 albertel 4777: }
1.795 www 4778:
1.777 tempelho 4779: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4780: table.LC_docs_path td.LC_docs_path_component {
1.779 bisitz 4781: background: $tabbg;
1.777 tempelho 4782: color: $font;
4783: font-family: $sans;
1.779 bisitz 4784: font-size: larger;
4785: text-align: right;
1.777 tempelho 4786: }
1.795 www 4787:
1.383 albertel 4788: td.LC_table_cell_checkbox {
4789: text-align: center;
4790: }
1.795 www 4791:
1.779 bisitz 4792: table#LC_mainmenu td.LC_mainmenu_column {
4793: vertical-align: top;
1.777 tempelho 4794: }
1.522 albertel 4795:
1.795 www 4796: .LC_fontsize_small {
1.705 tempelho 4797: font-size: 70%;
4798: }
4799:
1.795 www 4800: .LC_fontsize_medium {
1.705 tempelho 4801: font-size: 85%;
4802: }
4803:
1.795 www 4804: .LC_fontsize_large {
1.705 tempelho 4805: font-size: 120%;
4806: }
4807:
1.346 albertel 4808: .LC_menubuttons_inline_text {
4809: color: $font;
4810: font-family: $sans;
1.698 harmsja 4811: font-size: 90%;
1.701 harmsja 4812: padding-left:3px;
1.346 albertel 4813: }
4814:
1.526 www 4815: .LC_menubuttons_link {
4816: text-decoration: none;
4817: }
1.795 www 4818:
1.522 albertel 4819: .LC_menubuttons_category {
1.521 www 4820: color: $font;
1.526 www 4821: background: $pgbg;
1.521 www 4822: font-family: $sans;
4823: font-size: larger;
4824: font-weight: bold;
4825: }
4826:
1.346 albertel 4827: td.LC_menubuttons_text {
1.779 bisitz 4828: color: $font;
1.346 albertel 4829: }
1.706 harmsja 4830:
1.346 albertel 4831: .LC_current_location {
4832: font-family: $sans;
4833: background: $tabbg;
4834: }
1.795 www 4835:
1.346 albertel 4836: .LC_new_mail {
4837: font-family: $sans;
1.634 www 4838: background: $tabbg;
1.346 albertel 4839: font-weight: bold;
4840: }
1.347 albertel 4841:
1.527 www 4842: .LC_dropadd_labeltext {
4843: font-family: $sans;
4844: text-align: right;
4845: }
4846:
4847: .LC_preferences_labeltext {
4848: font-family: $sans;
4849: text-align: right;
4850: }
4851:
1.666 raeburn 4852: .LC_roleslog_note {
1.701 harmsja 4853: font-size: small;
1.666 raeburn 4854: }
4855:
1.715 raeburn 4856: .LC_mail_functions {
4857: font-weight: bold;
4858: }
4859:
1.440 albertel 4860: table.LC_aboutme_port {
4861: border: 0px;
4862: border-collapse: collapse;
4863: border-spacing: 0px;
4864: }
1.795 www 4865:
4866: table.LC_data_table,
4867: table.LC_mail_list {
1.347 albertel 4868: border: 1px solid #000000;
1.402 albertel 4869: border-collapse: separate;
1.426 albertel 4870: border-spacing: 1px;
1.610 albertel 4871: background: $pgbg;
1.347 albertel 4872: }
1.795 www 4873:
1.422 albertel 4874: .LC_data_table_dense {
4875: font-size: small;
4876: }
1.795 www 4877:
1.507 raeburn 4878: table.LC_nested_outer {
4879: border: 1px solid #000000;
1.589 raeburn 4880: border-collapse: collapse;
1.507 raeburn 4881: border-spacing: 0px;
4882: width: 100%;
4883: }
1.795 www 4884:
1.507 raeburn 4885: table.LC_nested {
4886: border: 0px;
1.589 raeburn 4887: border-collapse: collapse;
1.507 raeburn 4888: border-spacing: 0px;
4889: width: 100%;
4890: }
1.795 www 4891:
4892: table.LC_data_table tr th,
4893: table.LC_calendar tr th,
4894: table.LC_mail_list tr th,
1.523 albertel 4895: table.LC_prior_tries tr th {
1.349 albertel 4896: font-weight: bold;
4897: background-color: $data_table_head;
1.701 harmsja 4898: font-size:90%;
1.347 albertel 4899: }
1.795 www 4900:
1.711 raeburn 4901: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4902: background-color: #CCCCCC;
1.711 raeburn 4903: font-weight: bold;
4904: text-align: left;
4905: }
1.795 www 4906:
1.779 bisitz 4907: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4908: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4909: table.LC_aboutme_port tr td {
1.349 albertel 4910: background-color: $data_table_light;
1.425 albertel 4911: padding: 2px;
1.347 albertel 4912: }
1.795 www 4913:
1.610 albertel 4914: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4915: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4916: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4917: background-color: $data_table_dark;
1.709 bisitz 4918: padding: 2px;
1.347 albertel 4919: }
1.795 www 4920:
1.425 albertel 4921: table.LC_data_table tr.LC_data_table_highlight td {
4922: background-color: $data_table_darker;
4923: }
1.795 www 4924:
1.639 raeburn 4925: table.LC_data_table tr td.LC_leftcol_header {
4926: background-color: $data_table_head;
4927: font-weight: bold;
4928: }
1.795 www 4929:
1.451 albertel 4930: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4931: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4932: background-color: #FFFFFF;
1.421 albertel 4933: font-weight: bold;
4934: font-style: italic;
4935: text-align: center;
4936: padding: 8px;
1.347 albertel 4937: }
1.795 www 4938:
1.507 raeburn 4939: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4940: padding: 4ex
4941: }
1.795 www 4942:
1.507 raeburn 4943: table.LC_nested_outer tr th {
4944: font-weight: bold;
4945: background-color: $data_table_head;
1.701 harmsja 4946: font-size: small;
1.507 raeburn 4947: border-bottom: 1px solid #000000;
4948: }
1.795 www 4949:
1.507 raeburn 4950: table.LC_nested_outer tr td.LC_subheader {
4951: background-color: $data_table_head;
4952: font-weight: bold;
4953: font-size: small;
4954: border-bottom: 1px solid #000000;
4955: text-align: right;
1.451 albertel 4956: }
1.795 www 4957:
1.507 raeburn 4958: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4959: background-color: #CCCCCC;
1.451 albertel 4960: font-weight: bold;
4961: font-size: small;
1.507 raeburn 4962: text-align: center;
4963: }
1.795 www 4964:
1.589 raeburn 4965: table.LC_nested tr.LC_info_row td.LC_left_item,
4966: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4967: text-align: left;
1.451 albertel 4968: }
1.795 www 4969:
1.507 raeburn 4970: table.LC_nested td {
1.735 bisitz 4971: background-color: #FFFFFF;
1.451 albertel 4972: font-size: small;
1.507 raeburn 4973: }
1.795 www 4974:
1.507 raeburn 4975: table.LC_nested_outer tr th.LC_right_item,
4976: table.LC_nested tr.LC_info_row td.LC_right_item,
4977: table.LC_nested tr.LC_odd_row td.LC_right_item,
4978: table.LC_nested tr td.LC_right_item {
1.451 albertel 4979: text-align: right;
4980: }
4981:
1.507 raeburn 4982: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4983: background-color: #EEEEEE;
1.451 albertel 4984: }
4985:
1.473 raeburn 4986: table.LC_createuser {
4987: }
4988:
4989: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4990: font-size: small;
1.473 raeburn 4991: }
4992:
4993: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4994: background-color: #CCCCCC;
1.473 raeburn 4995: font-weight: bold;
4996: text-align: center;
4997: }
4998:
1.349 albertel 4999: table.LC_calendar {
5000: border: 1px solid #000000;
5001: border-collapse: collapse;
5002: }
1.795 www 5003:
1.349 albertel 5004: table.LC_calendar_pickdate {
5005: font-size: xx-small;
5006: }
1.795 www 5007:
1.349 albertel 5008: table.LC_calendar tr td {
5009: border: 1px solid #000000;
5010: vertical-align: top;
5011: }
1.795 www 5012:
1.349 albertel 5013: table.LC_calendar tr td.LC_calendar_day_empty {
5014: background-color: $data_table_dark;
5015: }
1.795 www 5016:
1.779 bisitz 5017: table.LC_calendar tr td.LC_calendar_day_current {
5018: background-color: $data_table_highlight;
1.777 tempelho 5019: }
1.795 www 5020:
1.349 albertel 5021: table.LC_mail_list tr.LC_mail_new {
5022: background-color: $mail_new;
5023: }
1.795 www 5024:
1.349 albertel 5025: table.LC_mail_list tr.LC_mail_new:hover {
5026: background-color: $mail_new_hover;
5027: }
1.795 www 5028:
5029: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5030: }
1.795 www 5031:
5032: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5033: }
1.795 www 5034:
1.349 albertel 5035: table.LC_mail_list tr.LC_mail_read {
5036: background-color: $mail_read;
5037: }
1.795 www 5038:
1.349 albertel 5039: table.LC_mail_list tr.LC_mail_read:hover {
5040: background-color: $mail_read_hover;
5041: }
1.795 www 5042:
1.349 albertel 5043: table.LC_mail_list tr.LC_mail_replied {
5044: background-color: $mail_replied;
5045: }
1.795 www 5046:
1.349 albertel 5047: table.LC_mail_list tr.LC_mail_replied:hover {
5048: background-color: $mail_replied_hover;
5049: }
1.795 www 5050:
1.349 albertel 5051: table.LC_mail_list tr.LC_mail_other {
5052: background-color: $mail_other;
5053: }
1.795 www 5054:
1.349 albertel 5055: table.LC_mail_list tr.LC_mail_other:hover {
5056: background-color: $mail_other_hover;
5057: }
1.494 raeburn 5058:
1.777 tempelho 5059: table.LC_data_table tr > td.LC_browser_file,
5060: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5061: background: #CCFF88;
5062: }
1.795 www 5063:
1.777 tempelho 5064: table.LC_data_table tr > td.LC_browser_file_locked,
5065: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5066: background: #FFAA99;
1.387 albertel 5067: }
1.795 www 5068:
1.777 tempelho 5069: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5070: background: #AAAAAA;
5071: }
1.795 www 5072:
1.777 tempelho 5073: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5074: table.LC_data_table tr > td.LC_browser_file_metamodified {
5075: background: #FFFF77;
1.777 tempelho 5076: }
1.795 www 5077:
1.696 bisitz 5078: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5079: background: #CCCCFF;
1.387 albertel 5080: }
1.696 bisitz 5081:
1.707 bisitz 5082: table.LC_data_table tr > td.LC_roles_is {
5083: /* background: #77FF77; */
5084: }
1.795 www 5085:
1.707 bisitz 5086: table.LC_data_table tr > td.LC_roles_future {
5087: background: #FFFF77;
5088: }
1.795 www 5089:
1.707 bisitz 5090: table.LC_data_table tr > td.LC_roles_will {
5091: background: #FFAA77;
5092: }
1.795 www 5093:
1.707 bisitz 5094: table.LC_data_table tr > td.LC_roles_expired {
5095: background: #FF7777;
5096: }
1.795 www 5097:
1.707 bisitz 5098: table.LC_data_table tr > td.LC_roles_will_not {
5099: background: #AAFF77;
5100: }
1.795 www 5101:
1.707 bisitz 5102: table.LC_data_table tr > td.LC_roles_selected {
5103: background: #11CC55;
5104: }
5105:
1.388 albertel 5106: span.LC_current_location {
1.701 harmsja 5107: font-size:larger;
1.388 albertel 5108: background: $pgbg;
5109: }
1.387 albertel 5110:
1.395 albertel 5111: span.LC_parm_menu_item {
5112: font-size: larger;
5113: font-family: $sans;
5114: }
1.795 www 5115:
1.395 albertel 5116: span.LC_parm_scope_all {
5117: color: red;
5118: }
1.795 www 5119:
1.395 albertel 5120: span.LC_parm_scope_folder {
5121: color: green;
5122: }
1.795 www 5123:
1.395 albertel 5124: span.LC_parm_scope_resource {
5125: color: orange;
5126: }
1.795 www 5127:
1.395 albertel 5128: span.LC_parm_part {
5129: color: blue;
5130: }
1.795 www 5131:
1.395 albertel 5132: span.LC_parm_folder, span.LC_parm_symb {
5133: font-size: x-small;
5134: font-family: $mono;
5135: color: #AAAAAA;
5136: }
5137:
1.795 www 5138: td.LC_parm_overview_level_menu,
5139: td.LC_parm_overview_map_menu,
5140: td.LC_parm_overview_parm_selectors,
5141: td.LC_parm_overview_restrictions {
1.396 albertel 5142: border: 1px solid black;
5143: border-collapse: collapse;
5144: }
1.795 www 5145:
1.396 albertel 5146: table.LC_parm_overview_restrictions td {
5147: border-width: 1px 4px 1px 4px;
5148: border-style: solid;
5149: border-color: $pgbg;
5150: text-align: center;
5151: }
1.795 www 5152:
1.396 albertel 5153: table.LC_parm_overview_restrictions th {
5154: background: $tabbg;
5155: border-width: 1px 4px 1px 4px;
5156: border-style: solid;
5157: border-color: $pgbg;
5158: }
1.795 www 5159:
1.398 albertel 5160: table#LC_helpmenu {
5161: border: 0px;
5162: height: 55px;
5163: border-spacing: 0px;
5164: }
5165:
5166: table#LC_helpmenu fieldset legend {
5167: font-size: larger;
5168: font-weight: bold;
5169: }
1.795 www 5170:
1.397 albertel 5171: table#LC_helpmenu_links {
5172: width: 100%;
5173: border: 1px solid black;
5174: background: $pgbg;
5175: padding: 0px;
5176: border-spacing: 1px;
5177: }
1.795 www 5178:
1.397 albertel 5179: table#LC_helpmenu_links tr td {
5180: padding: 1px;
5181: background: $tabbg;
1.399 albertel 5182: text-align: center;
5183: font-weight: bold;
1.397 albertel 5184: }
1.396 albertel 5185:
1.795 www 5186: table#LC_helpmenu_links a:link,
5187: table#LC_helpmenu_links a:visited,
1.397 albertel 5188: table#LC_helpmenu_links a:active {
5189: text-decoration: none;
5190: color: $font;
5191: }
1.795 www 5192:
1.397 albertel 5193: table#LC_helpmenu_links a:hover {
5194: text-decoration: underline;
5195: color: $vlink;
5196: }
1.396 albertel 5197:
1.417 albertel 5198: .LC_chrt_popup_exists {
5199: border: 1px solid #339933;
5200: margin: -1px;
5201: }
1.795 www 5202:
1.417 albertel 5203: .LC_chrt_popup_up {
5204: border: 1px solid yellow;
5205: margin: -1px;
5206: }
1.795 www 5207:
1.417 albertel 5208: .LC_chrt_popup {
5209: border: 1px solid #8888FF;
5210: background: #CCCCFF;
5211: }
1.795 www 5212:
1.421 albertel 5213: table.LC_pick_box {
5214: border-collapse: separate;
5215: background: white;
5216: border: 1px solid black;
5217: border-spacing: 1px;
5218: }
1.795 www 5219:
1.421 albertel 5220: table.LC_pick_box td.LC_pick_box_title {
5221: background: $tabbg;
5222: font-weight: bold;
5223: text-align: right;
1.740 bisitz 5224: vertical-align: top;
1.421 albertel 5225: width: 184px;
5226: padding: 8px;
5227: }
1.795 www 5228:
1.645 raeburn 5229: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5230: background: $tabbg;
5231: font-weight: bold;
5232: text-align: right;
5233: width: 350px;
5234: padding: 8px;
5235: }
5236:
1.579 raeburn 5237: table.LC_pick_box td.LC_pick_box_value {
5238: text-align: left;
5239: padding: 8px;
5240: }
1.795 www 5241:
1.579 raeburn 5242: table.LC_pick_box td.LC_pick_box_select {
5243: text-align: left;
5244: padding: 8px;
5245: }
1.795 www 5246:
1.424 albertel 5247: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5248: padding: 0px;
5249: height: 1px;
5250: background: black;
5251: }
1.795 www 5252:
1.421 albertel 5253: table.LC_pick_box td.LC_pick_box_submit {
5254: text-align: right;
5255: }
1.795 www 5256:
1.579 raeburn 5257: table.LC_pick_box td.LC_evenrow_value {
5258: text-align: left;
5259: padding: 8px;
5260: background-color: $data_table_light;
5261: }
1.795 www 5262:
1.579 raeburn 5263: table.LC_pick_box td.LC_oddrow_value {
5264: text-align: left;
5265: padding: 8px;
5266: background-color: $data_table_light;
5267: }
1.795 www 5268:
1.579 raeburn 5269: table.LC_helpform_receipt {
5270: width: 620px;
5271: border-collapse: separate;
5272: background: white;
5273: border: 1px solid black;
5274: border-spacing: 1px;
5275: }
1.795 www 5276:
1.579 raeburn 5277: table.LC_helpform_receipt td.LC_pick_box_title {
5278: background: $tabbg;
5279: font-weight: bold;
5280: text-align: right;
5281: width: 184px;
5282: padding: 8px;
5283: }
1.795 www 5284:
1.579 raeburn 5285: table.LC_helpform_receipt td.LC_evenrow_value {
5286: text-align: left;
5287: padding: 8px;
5288: background-color: $data_table_light;
5289: }
1.795 www 5290:
1.579 raeburn 5291: table.LC_helpform_receipt td.LC_oddrow_value {
5292: text-align: left;
5293: padding: 8px;
5294: background-color: $data_table_light;
5295: }
1.795 www 5296:
1.579 raeburn 5297: table.LC_helpform_receipt td.LC_pick_box_separator {
5298: padding: 0px;
5299: height: 1px;
5300: background: black;
5301: }
1.795 www 5302:
1.579 raeburn 5303: span.LC_helpform_receipt_cat {
5304: font-weight: bold;
5305: }
1.795 www 5306:
1.424 albertel 5307: table.LC_group_priv_box {
5308: background: white;
5309: border: 1px solid black;
5310: border-spacing: 1px;
5311: }
1.795 www 5312:
1.424 albertel 5313: table.LC_group_priv_box td.LC_pick_box_title {
5314: background: $tabbg;
5315: font-weight: bold;
5316: text-align: right;
5317: width: 184px;
5318: }
1.795 www 5319:
1.424 albertel 5320: table.LC_group_priv_box td.LC_groups_fixed {
5321: background: $data_table_light;
5322: text-align: center;
5323: }
1.795 www 5324:
1.424 albertel 5325: table.LC_group_priv_box td.LC_groups_optional {
5326: background: $data_table_dark;
5327: text-align: center;
5328: }
1.795 www 5329:
1.424 albertel 5330: table.LC_group_priv_box td.LC_groups_functionality {
5331: background: $data_table_darker;
5332: text-align: center;
5333: font-weight: bold;
5334: }
1.795 www 5335:
1.424 albertel 5336: table.LC_group_priv td {
5337: text-align: left;
5338: padding: 0px;
5339: }
5340:
1.421 albertel 5341: table.LC_notify_front_page {
5342: background: white;
5343: border: 1px solid black;
5344: padding: 8px;
5345: }
1.795 www 5346:
1.421 albertel 5347: table.LC_notify_front_page td {
5348: padding: 8px;
5349: }
1.795 www 5350:
1.424 albertel 5351: .LC_navbuttons {
5352: margin: 2ex 0ex 2ex 0ex;
5353: }
1.795 www 5354:
1.423 albertel 5355: .LC_topic_bar {
5356: font-family: $sans;
5357: font-weight: bold;
5358: width: 100%;
5359: background: $tabbg;
5360: vertical-align: middle;
5361: margin: 2ex 0ex 2ex 0ex;
5362: }
1.795 www 5363:
1.423 albertel 5364: .LC_topic_bar span {
5365: vertical-align: middle;
5366: }
1.795 www 5367:
1.423 albertel 5368: .LC_topic_bar img {
5369: vertical-align: bottom;
5370: }
1.795 www 5371:
1.423 albertel 5372: table.LC_course_group_status {
5373: margin: 20px;
5374: }
1.795 www 5375:
1.423 albertel 5376: table.LC_status_selector td {
5377: vertical-align: top;
5378: text-align: center;
1.424 albertel 5379: padding: 4px;
5380: }
1.795 www 5381:
1.424 albertel 5382: table.LC_descriptive_input td.LC_description {
5383: vertical-align: top;
5384: text-align: right;
5385: font-weight: bold;
1.423 albertel 5386: }
1.795 www 5387:
1.599 albertel 5388: div.LC_feedback_link {
1.616 albertel 5389: clear: both;
1.599 albertel 5390: background: white;
1.779 bisitz 5391: width: 100%;
1.489 raeburn 5392: }
1.795 www 5393:
1.489 raeburn 5394: span.LC_feedback_link {
1.599 albertel 5395: background: $feedback_link_bg;
5396: font-size: larger;
5397: }
1.795 www 5398:
1.599 albertel 5399: span.LC_message_link {
5400: background: $feedback_link_bg;
5401: font-size: larger;
5402: position: absolute;
5403: right: 1em;
1.489 raeburn 5404: }
1.421 albertel 5405:
1.515 albertel 5406: table.LC_prior_tries {
1.524 albertel 5407: border: 1px solid #000000;
5408: border-collapse: separate;
5409: border-spacing: 1px;
1.515 albertel 5410: }
1.523 albertel 5411:
1.515 albertel 5412: table.LC_prior_tries td {
1.524 albertel 5413: padding: 2px;
1.515 albertel 5414: }
1.523 albertel 5415:
5416: .LC_answer_correct {
1.795 www 5417: background: lightgreen;
5418: font-family: $sans;
5419: color: darkgreen;
5420: padding: 6px;
1.523 albertel 5421: }
1.795 www 5422:
1.523 albertel 5423: .LC_answer_charged_try {
1.797 www 5424: background: #FFAAAA;
1.795 www 5425: font-family: $sans;
5426: color: darkred;
5427: padding: 6px;
1.523 albertel 5428: }
1.795 www 5429:
1.779 bisitz 5430: .LC_answer_not_charged_try,
1.523 albertel 5431: .LC_answer_no_grade,
5432: .LC_answer_late {
1.795 www 5433: background: lightyellow;
5434: font-family: $sans;
1.523 albertel 5435: color: black;
1.795 www 5436: padding: 6px;
1.523 albertel 5437: }
1.795 www 5438:
1.523 albertel 5439: .LC_answer_previous {
1.795 www 5440: background: lightblue;
5441: font-family: $sans;
5442: color: darkblue;
5443: padding: 6px;
1.523 albertel 5444: }
1.795 www 5445:
1.779 bisitz 5446: .LC_answer_no_message {
1.777 tempelho 5447: background: #FFFFFF;
1.795 www 5448: font-family: $sans;
1.777 tempelho 5449: color: black;
1.795 www 5450: padding: 6px;
1.779 bisitz 5451: }
1.795 www 5452:
1.779 bisitz 5453: .LC_answer_unknown {
5454: background: orange;
1.795 www 5455: font-family: $sans;
1.779 bisitz 5456: color: black;
1.795 www 5457: padding: 6px;
1.777 tempelho 5458: }
1.795 www 5459:
1.529 albertel 5460: span.LC_prior_numerical,
5461: span.LC_prior_string,
5462: span.LC_prior_custom,
5463: span.LC_prior_reaction,
5464: span.LC_prior_math {
1.523 albertel 5465: font-family: monospace;
5466: white-space: pre;
5467: }
5468:
1.525 albertel 5469: span.LC_prior_string {
5470: font-family: monospace;
5471: white-space: pre;
5472: }
5473:
1.523 albertel 5474: table.LC_prior_option {
5475: width: 100%;
5476: border-collapse: collapse;
5477: }
1.795 www 5478:
5479: table.LC_prior_rank,
5480: table.LC_prior_match {
1.528 albertel 5481: border-collapse: collapse;
5482: }
1.795 www 5483:
1.528 albertel 5484: table.LC_prior_option tr td,
5485: table.LC_prior_rank tr td,
5486: table.LC_prior_match tr td {
1.524 albertel 5487: border: 1px solid #000000;
1.515 albertel 5488: }
5489:
1.770 droeschl 5490: td.LC_nobreak,
1.519 raeburn 5491: span.LC_nobreak {
1.544 albertel 5492: white-space: nowrap;
1.519 raeburn 5493: }
5494:
1.576 raeburn 5495: span.LC_cusr_emph {
5496: font-style: italic;
5497: }
5498:
1.633 raeburn 5499: span.LC_cusr_subheading {
5500: font-weight: normal;
5501: font-size: 85%;
5502: }
5503:
1.545 albertel 5504: table.LC_docs_documents {
5505: background: #BBBBBB;
1.547 albertel 5506: border-width: 0px;
1.545 albertel 5507: border-collapse: collapse;
5508: }
1.795 www 5509:
1.777 tempelho 5510: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5511: border: 2px solid black;
5512: padding: 4px;
1.777 tempelho 5513: }
1.795 www 5514:
1.545 albertel 5515: .LC_docs_entry_move {
5516: border: 0px;
5517: border-collapse: collapse;
1.544 albertel 5518: }
5519:
1.545 albertel 5520: .LC_docs_entry_move td {
5521: border: 2px solid #BBBBBB;
5522: background: #DDDDDD;
5523: }
5524:
5525: .LC_docs_editor td.LC_docs_entry_commands {
5526: background: #DDDDDD;
5527: font-size: x-small;
5528: }
1.795 www 5529:
1.544 albertel 5530: .LC_docs_copy {
1.545 albertel 5531: color: #000099;
1.544 albertel 5532: }
1.795 www 5533:
1.544 albertel 5534: .LC_docs_cut {
1.545 albertel 5535: color: #550044;
1.544 albertel 5536: }
1.795 www 5537:
1.544 albertel 5538: .LC_docs_rename {
1.545 albertel 5539: color: #009900;
1.544 albertel 5540: }
1.795 www 5541:
1.544 albertel 5542: .LC_docs_remove {
1.545 albertel 5543: color: #990000;
5544: }
5545:
1.547 albertel 5546: .LC_docs_reinit_warn,
5547: .LC_docs_ext_edit {
5548: font-size: x-small;
5549: }
5550:
1.545 albertel 5551: .LC_docs_editor td.LC_docs_entry_title,
5552: .LC_docs_editor td.LC_docs_entry_icon {
5553: background: #FFFFBB;
5554: }
1.795 www 5555:
1.545 albertel 5556: .LC_docs_editor td.LC_docs_entry_parameter {
5557: background: #BBBBFF;
5558: font-size: x-small;
5559: white-space: nowrap;
5560: }
5561:
5562: table.LC_docs_adddocs td,
5563: table.LC_docs_adddocs th {
5564: border: 1px solid #BBBBBB;
5565: padding: 4px;
5566: background: #DDDDDD;
1.543 albertel 5567: }
5568:
1.584 albertel 5569: table.LC_sty_begin {
5570: background: #BBFFBB;
5571: }
1.795 www 5572:
1.584 albertel 5573: table.LC_sty_end {
5574: background: #FFBBBB;
5575: }
5576:
1.589 raeburn 5577: table.LC_double_column {
5578: border-width: 0px;
5579: border-collapse: collapse;
5580: width: 100%;
5581: padding: 2px;
5582: }
5583:
5584: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5585: top: 2px;
1.589 raeburn 5586: left: 2px;
5587: width: 47%;
5588: vertical-align: top;
5589: }
5590:
5591: table.LC_double_column tr td.LC_right_col {
5592: top: 2px;
1.779 bisitz 5593: right: 2px;
1.589 raeburn 5594: width: 47%;
5595: vertical-align: top;
5596: }
5597:
1.594 raeburn 5598: span.LC_role_level {
5599: font-weight: bold;
5600: }
5601:
1.591 raeburn 5602: div.LC_left_float {
5603: float: left;
5604: padding-right: 5%;
1.597 albertel 5605: padding-bottom: 4px;
1.591 raeburn 5606: }
5607:
5608: div.LC_clear_float_header {
1.597 albertel 5609: padding-bottom: 2px;
1.591 raeburn 5610: }
5611:
5612: div.LC_clear_float_footer {
1.597 albertel 5613: padding-top: 10px;
1.591 raeburn 5614: clear: both;
5615: }
5616:
1.597 albertel 5617: div.LC_grade_show_user {
5618: margin-top: 20px;
5619: border: 1px solid black;
5620: }
1.795 www 5621:
1.597 albertel 5622: div.LC_grade_user_name {
5623: background: #DDDDEE;
5624: border-bottom: 1px solid black;
1.705 tempelho 5625: font-weight: bold;
5626: font-size: large;
1.597 albertel 5627: }
1.795 www 5628:
1.597 albertel 5629: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5630: background: #DDEEDD;
5631: }
5632:
5633: div.LC_grade_show_problem,
5634: div.LC_grade_submissions,
5635: div.LC_grade_message_center,
5636: div.LC_grade_info_links,
5637: div.LC_grade_assign {
5638: margin: 5px;
5639: width: 99%;
5640: background: #FFFFFF;
5641: }
1.795 www 5642:
1.597 albertel 5643: div.LC_grade_show_problem_header,
5644: div.LC_grade_submissions_header,
5645: div.LC_grade_message_center_header,
5646: div.LC_grade_assign_header {
1.705 tempelho 5647: font-weight: bold;
5648: font-size: large;
1.597 albertel 5649: }
1.795 www 5650:
1.597 albertel 5651: div.LC_grade_show_problem_problem,
5652: div.LC_grade_submissions_body,
5653: div.LC_grade_message_center_body,
5654: div.LC_grade_assign_body {
5655: border: 1px solid black;
5656: width: 99%;
5657: background: #FFFFFF;
5658: }
1.795 www 5659:
1.598 albertel 5660: span.LC_grade_check_note {
1.705 tempelho 5661: font-weight: normal;
5662: font-size: medium;
1.598 albertel 5663: display: inline;
5664: position: absolute;
5665: right: 1em;
5666: }
1.597 albertel 5667:
1.613 albertel 5668: table.LC_scantron_action {
5669: width: 100%;
5670: }
1.795 www 5671:
1.613 albertel 5672: table.LC_scantron_action tr th {
1.698 harmsja 5673: font-weight:bold;
5674: font-style:normal;
1.613 albertel 5675: }
1.795 www 5676:
1.779 bisitz 5677: .LC_edit_problem_header,
1.614 albertel 5678: div.LC_edit_problem_footer {
1.705 tempelho 5679: font-weight: normal;
5680: font-size: medium;
1.602 albertel 5681: margin: 2px;
1.600 albertel 5682: }
1.795 www 5683:
1.600 albertel 5684: div.LC_edit_problem_header,
1.602 albertel 5685: div.LC_edit_problem_header div,
1.614 albertel 5686: div.LC_edit_problem_footer,
5687: div.LC_edit_problem_footer div,
1.602 albertel 5688: div.LC_edit_problem_editxml_header,
5689: div.LC_edit_problem_editxml_header div {
1.600 albertel 5690: margin-top: 5px;
5691: }
1.795 www 5692:
1.602 albertel 5693: div.LC_edit_problem_header_edit_row {
5694: background: $tabbg;
5695: padding: 3px;
5696: margin-bottom: 5px;
5697: }
1.795 www 5698:
1.600 albertel 5699: div.LC_edit_problem_header_title {
1.705 tempelho 5700: font-weight: bold;
5701: font-size: larger;
1.602 albertel 5702: background: $tabbg;
5703: padding: 3px;
5704: }
1.795 www 5705:
1.602 albertel 5706: table.LC_edit_problem_header_title {
1.705 tempelho 5707: font-size: larger;
5708: font-weight: bold;
1.602 albertel 5709: width: 100%;
5710: border-color: $pgbg;
5711: border-style: solid;
5712: border-width: $border;
1.600 albertel 5713: background: $tabbg;
1.602 albertel 5714: border-collapse: collapse;
5715: padding: 0px
5716: }
5717:
5718: div.LC_edit_problem_discards {
5719: float: left;
5720: padding-bottom: 5px;
5721: }
1.795 www 5722:
1.602 albertel 5723: div.LC_edit_problem_saves {
5724: float: right;
5725: padding-bottom: 5px;
1.600 albertel 5726: }
1.795 www 5727:
1.600 albertel 5728: hr.LC_edit_problem_divide {
1.602 albertel 5729: clear: both;
1.600 albertel 5730: color: $tabbg;
5731: background-color: $tabbg;
5732: height: 3px;
5733: border: 0px;
5734: }
1.795 www 5735:
1.679 riegler 5736: img.stift{
1.678 riegler 5737: border-width:0;
1.679 riegler 5738: vertical-align:middle;
1.677 riegler 5739: }
1.680 riegler 5740:
1.681 riegler 5741: table#LC_mainmenu{
5742: margin-top:10px;
5743: width:80%;
5744: }
5745:
1.680 riegler 5746: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5747: vertical-align: top;
5748: width: 45%;
5749: }
1.795 www 5750:
1.779 bisitz 5751: .LC_mainmenu_fieldset_category {
5752: color: $font;
5753: background: $pgbg;
5754: font-family: $sans;
5755: font-size: small;
5756: font-weight: bold;
1.777 tempelho 5757: }
1.795 www 5758:
1.716 raeburn 5759: div.LC_createcourse {
5760: margin: 10px 10px 10px 10px;
5761: }
5762:
1.693 droeschl 5763: /* ---- Remove when done ----
5764: # The following styles is part of the redesign of LON-CAPA and are
5765: # subject to change during this project.
5766: # Don't rely on their current functionality as they might be
5767: # changed or removed.
5768: # --------------------------*/
5769:
1.698 harmsja 5770: a:hover,
1.721 harmsja 5771: ol.LC_smallMenu a:hover,
5772: ol#LC_MenuBreadcrumbs a:hover,
5773: ol#LC_PathBreadcrumbs a:hover,
5774: ul#LC_TabMainMenuContent a:hover,
5775: .LC_FormSectionClearButton input:hover
1.795 www 5776: ul.LC_TabContent li:hover a {
1.698 harmsja 5777: color:#BF2317;
5778: text-decoration:none;
1.693 droeschl 5779: }
5780:
1.779 bisitz 5781: h1 {
1.721 harmsja 5782: padding:5px 10px 5px 20px;
1.693 droeschl 5783: line-height:130%;
5784: }
1.698 harmsja 5785:
1.795 www 5786: h2,h3,h4,h5,h6 {
1.721 harmsja 5787: margin:5px 0px 5px 0px;
5788: padding:0px;
5789: line-height:130%;
1.693 droeschl 5790: }
1.795 www 5791:
5792: .LC_hcell {
1.698 harmsja 5793: padding:3px 15px 3px 15px;
5794: margin:0px;
1.703 harmsja 5795: background-color:$tabbg;
1.779 bisitz 5796: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5797: }
1.795 www 5798:
1.721 harmsja 5799: .LC_noBorder {
1.698 harmsja 5800: border:0px;
5801: }
1.693 droeschl 5802:
5803:
1.698 harmsja 5804: /* Main Header with discription of Person, Course, etc. */
1.693 droeschl 5805:
1.761 tempelho 5806: .LC_Right {
5807: float: right;
5808: margin: 0px;
5809: padding: 0px;
5810: }
5811:
1.721 harmsja 5812: .LC_FormSectionClearButton input {
1.779 bisitz 5813: background-color:transparent;
1.698 harmsja 5814: border:0px;
5815: cursor:pointer;
5816: text-decoration:underline;
1.693 droeschl 5817: }
1.763 bisitz 5818:
5819: .LC_help_open_topic {
5820: color: #FFFFFF;
5821: background-color: #EEEEFF;
5822: margin: 1px;
5823: padding: 4px;
5824: border: 1px solid #000033;
5825: white-space: nowrap;
1.783 amueller 5826: /* vertical-align: middle; */
1.759 neumanie 5827: }
1.693 droeschl 5828:
1.698 harmsja 5829: dl,ul,div,fieldset {
5830: margin: 10px 10px 10px 0px;
1.693 droeschl 5831: overflow:hidden;
5832: }
1.795 www 5833:
1.721 harmsja 5834: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5835: margin: 0px;
1.693 droeschl 5836: }
5837:
1.721 harmsja 5838: ol.LC_smallMenu li {
1.693 droeschl 5839: display: inline;
5840: padding: 5px 5px 0px 10px;
5841: vertical-align: top;
5842: }
5843:
1.721 harmsja 5844: ol.LC_smallMenu li img {
1.693 droeschl 5845: vertical-align: bottom;
5846: }
5847:
1.721 harmsja 5848: ol.LC_smallMenu a {
1.693 droeschl 5849: font-size: 90%;
5850: color: RGB(80, 80, 80);
5851: text-decoration: none;
5852: }
1.795 www 5853:
5854: ol#LC_TabMainMenuContent,
5855: ul.LC_TabContent ,
1.741 harmsja 5856: ul.LC_TabContentBigger {
1.721 harmsja 5857: display:block;
5858: list-style:none;
1.741 harmsja 5859: margin: 0px;
1.693 droeschl 5860: padding: 0px;
5861: }
5862:
1.795 www 5863: ol#LC_TabMainMenuContent li,
5864: ul.LC_TabContent li,
5865: ul.LC_TabContentBigger li {
1.693 droeschl 5866: display: inline;
1.741 harmsja 5867: border-right: solid 1px $lg_border_color;
5868: float:left;
5869: line-height:140%;
5870: white-space:nowrap;
5871: }
1.795 www 5872:
5873: ol#LC_TabMainMenuContent li {
1.693 droeschl 5874: vertical-align: bottom;
5875: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5876: padding: 5px 10px 5px 10px;
1.741 harmsja 5877: margin-right:5px;
5878: margin-bottom:3px;
1.693 droeschl 5879: font-weight: bold;
1.723 riegler 5880: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5881: }
5882:
1.795 www 5883: ol#LC_TabMainMenuContent li a {
1.693 droeschl 5884: color: RGB(47, 47, 47);
5885: text-decoration: none;
5886: }
1.795 www 5887:
1.721 harmsja 5888: ul.LC_TabContent {
1.741 harmsja 5889: min-height:1.6em;
1.721 harmsja 5890: }
1.795 www 5891:
5892: ul.LC_TabContent li {
1.741 harmsja 5893: vertical-align:middle;
5894: padding:0px 10px 0px 10px;
1.745 ehlerst 5895: background-color:$tabbg;
5896: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5897: }
1.795 www 5898:
5899: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5900: color:rgb(47,47,47);
5901: text-decoration:none;
5902: font-size:95%;
5903: font-weight:bold;
1.761 tempelho 5904: padding-right: 16px;
1.721 harmsja 5905: }
1.795 www 5906:
5907: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5908: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745 ehlerst 5909: border-bottom:solid 1px #FFFFFF;
1.761 tempelho 5910: padding-right: 16px;
1.744 ehlerst 5911: }
1.795 www 5912:
5913: ul.LC_TabContentBigger li {
1.741 harmsja 5914: vertical-align:bottom;
5915: border-top:solid 1px $lg_border_color;
5916: border-left:solid 1px $lg_border_color;
5917: padding:5px 10px 5px 10px;
5918: margin-left:2px;
5919: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5920: }
1.795 www 5921:
5922: ul.LC_TabContentBigger li:hover,
5923: ul.LC_TabContentBigger li.active {
1.744 ehlerst 5924: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5925: }
1.795 www 5926:
5927: ul.LC_TabContentBigger li,
5928: ul.LC_TabContentBigger li a {
1.741 harmsja 5929: font-size:110%;
5930: font-weight:bold;
5931: }
1.693 droeschl 5932:
1.795 www 5933: ol#LC_MenuBreadcrumbs,
5934: ol#LC_PathBreadcrumbs,
5935: ul.LC_CourseBreadcrumbs {
1.693 droeschl 5936: border-top: solid 1px RGB(255, 255, 255);
5937: height: 20px;
5938: line-height: 20px;
5939: vertical-align: bottom;
5940: margin: 0px 0px 30px 0px;
5941: padding-left: 10px;
5942: list-style-position: inside;
1.723 riegler 5943: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5944: }
5945:
1.795 www 5946: ol#LC_MenuBreadcrumbs li,
5947: ol#LC_PathBreadcrumbs li,
5948: ul.LC_CourseBreadcrumbs li {
1.741 harmsja 5949: /*
1.723 riegler 5950: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779 bisitz 5951: */
1.693 droeschl 5952: display: inline;
5953: padding: 0px 0px 0px 10px;
1.783 amueller 5954: /* vertical-align: bottom; */
1.693 droeschl 5955: overflow:hidden;
5956: }
5957:
1.783 amueller 5958: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 5959: text-decoration: none;
5960: font-size:90%;
5961: }
1.795 www 5962:
5963: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 5964: text-decoration:none;
5965: font-size:100%;
5966: font-weight:bold;
1.693 droeschl 5967: }
1.795 www 5968:
5969: .LC_BoxPadding {
1.786 neumanie 5970: padding: 10px;
5971: }
1.795 www 5972:
5973: .LC_ContentBoxSpecial {
1.701 harmsja 5974: border: solid 1px $lg_border_color;
1.746 neumanie 5975: }
1.795 www 5976:
5977: .LC_ContentBoxSpecialContactInfo {
1.746 neumanie 5978: border: solid 1px $lg_border_color;
5979: max-width:25%;
5980: min-width:25%;
1.698 harmsja 5981: }
1.795 www 5982:
5983: .LC_AboutMe_Image {
1.747 neumanie 5984: float:left;
5985: margin-right:10px;
5986: }
1.795 www 5987:
5988: .LC_Clear_AboutMe_Image {
1.747 neumanie 5989: clear:left;
5990: }
1.795 www 5991:
1.721 harmsja 5992: dl.LC_ListStyleClean dt {
1.693 droeschl 5993: padding-right: 5px;
5994: display: table-header-group;
5995: }
5996:
1.721 harmsja 5997: dl.LC_ListStyleClean dd {
1.693 droeschl 5998: display: table-row;
5999: }
6000:
1.721 harmsja 6001: .LC_ListStyleClean,
6002: .LC_ListStyleSimple,
6003: .LC_ListStyleNormal,
1.777 tempelho 6004: .LC_ListStyle_Border,
1.795 www 6005: .LC_ListStyleSpecial {
1.693 droeschl 6006: /*display:block; */
6007: list-style-position: inside;
6008: list-style-type: none;
6009: overflow: hidden;
6010: padding: 0px;
6011: }
6012:
1.721 harmsja 6013: .LC_ListStyleSimple li,
6014: .LC_ListStyleSimple dd,
6015: .LC_ListStyleNormal li,
6016: .LC_ListStyleNormal dd,
6017: .LC_ListStyleSpecial li,
1.795 www 6018: .LC_ListStyleSpecial dd {
1.693 droeschl 6019: margin: 0px;
6020: padding: 5px 5px 5px 10px;
6021: clear: both;
6022: }
6023:
1.721 harmsja 6024: .LC_ListStyleClean li,
6025: .LC_ListStyleClean dd {
1.693 droeschl 6026: padding-top: 0px;
6027: padding-bottom: 0px;
6028: }
6029:
1.721 harmsja 6030: .LC_ListStyleSimple dd,
1.795 www 6031: .LC_ListStyleSimple li {
1.698 harmsja 6032: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6033: }
6034:
1.721 harmsja 6035: .LC_ListStyleSpecial li,
6036: .LC_ListStyleSpecial dd {
1.693 droeschl 6037: list-style-type: none;
6038: background-color: RGB(220, 220, 220);
6039: margin-bottom: 4px;
6040: }
6041:
1.721 harmsja 6042: table.LC_SimpleTable {
1.698 harmsja 6043: margin:5px;
6044: border:solid 1px $lg_border_color;
1.795 www 6045: }
1.693 droeschl 6046:
1.721 harmsja 6047: table.LC_SimpleTable tr {
1.698 harmsja 6048: padding:0px;
6049: border:solid 1px $lg_border_color;
1.693 droeschl 6050: }
1.795 www 6051:
6052: table.LC_SimpleTable thead {
1.698 harmsja 6053: background:rgb(220,220,220);
1.693 droeschl 6054: }
6055:
1.721 harmsja 6056: div.LC_columnSection {
1.693 droeschl 6057: display: block;
6058: clear: both;
6059: overflow: hidden;
6060: margin:0px;
6061: }
6062:
1.721 harmsja 6063: div.LC_columnSection>* {
1.693 droeschl 6064: float: left;
6065: margin: 10px 20px 10px 0px;
1.747 neumanie 6066: overflow:hidden;
1.693 droeschl 6067: }
1.721 harmsja 6068:
1.795 www 6069: .ContentBoxSpecialTemplate {
1.747 neumanie 6070: border: solid 1px $lg_border_color;
1.719 ehlerst 6071: }
1.795 www 6072:
1.719 ehlerst 6073: .ContentBoxTemplate {
6074: padding:10px;
6075: }
6076:
1.721 harmsja 6077: div.LC_columnSection > .ContentBoxTemplate,
1.795 www 6078: div.LC_columnSection > .ContentBoxSpecialTemplate {
1.719 ehlerst 6079: width: 600px;
6080: }
1.753 droeschl 6081:
1.795 www 6082: .clear {
1.720 ehlerst 6083: clear: both;
6084: line-height: 0px;
6085: font-size: 0px;
6086: height: 0px;
6087: }
1.693 droeschl 6088:
1.694 tempelho 6089: .LC_loginpage_container {
6090: text-align:left;
6091: margin : 0 auto;
1.785 tempelho 6092: width:90%;
1.694 tempelho 6093: padding: 10px;
6094: height: auto;
1.712 muellerd 6095: background-color:#FFFFFF;
1.694 tempelho 6096: border:1px solid #CCCCCC;
6097: }
6098:
6099:
6100: .LC_loginpage_loginContainer {
6101: float:left;
1.712 muellerd 6102: width: 182px;
1.785 tempelho 6103: padding: 2px;
1.712 muellerd 6104: border:1px solid #CCCCCC;
6105: background-color:$loginbg;
1.694 tempelho 6106: }
6107:
1.795 www 6108: .LC_loginpage_loginContainer h2 {
1.712 muellerd 6109: margin-top:0;
6110: display:block;
6111: background:$bgcol;
6112: color:$textcol;
6113: padding-left:5px;
6114: }
1.785 tempelho 6115:
1.694 tempelho 6116: .LC_loginpage_loginInfo {
6117: float:left;
1.785 tempelho 6118: width:182px;
1.694 tempelho 6119: border:1px solid #CCCCCC;
1.785 tempelho 6120: padding:2px;
1.712 muellerd 6121: }
6122:
1.694 tempelho 6123: .LC_loginpage_space {
1.754 droeschl 6124: clear: both;
6125: margin-bottom: 20px;
1.694 tempelho 6126: border-bottom: 1px solid #CCCCCC;
6127: }
6128:
1.785 tempelho 6129: .LC_loginpage_floatLeft {
6130: float: left;
6131: width: 200px;
6132: margin: 0;
6133: }
6134:
1.795 www 6135: table em {
1.754 droeschl 6136: font-weight: bold;
6137: font-style: normal;
1.748 schulted 6138: }
1.795 www 6139:
1.779 bisitz 6140: table.LC_tableBrowseRes,
1.795 www 6141: table.LC_tableOfContent {
1.769 schulted 6142: border:none;
6143: border-spacing: 1;
1.754 droeschl 6144: padding: 3px;
6145: background-color: #FFFFFF;
6146: font-size: 90%;
1.753 droeschl 6147: }
1.789 droeschl 6148:
6149: table.LC_tableOfContent{
6150: border-collapse: collapse;
6151: }
6152:
1.771 droeschl 6153: table.LC_tableBrowseRes a,
1.768 schulted 6154: table.LC_tableOfContent a {
1.771 droeschl 6155: background-color: transparent;
1.753 droeschl 6156: text-decoration: none;
6157: }
6158:
1.771 droeschl 6159: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6160: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6161: background-color: #EEEEEE;
1.753 droeschl 6162: }
6163:
1.795 www 6164: table.LC_tableOfContent img {
1.753 droeschl 6165: border: none;
6166: height: 1.3em;
6167: vertical-align: text-bottom;
6168: margin-right: 0.3em;
6169: }
1.757 schulted 6170:
1.795 www 6171: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6172: background-image:url(/res/adm/pages/open-first-problem.gif);
6173: }
6174:
1.795 www 6175: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6176: background-image:url(/res/adm/pages/start-navigation.gif);
6177: }
6178:
1.795 www 6179: a#LC_content_toolbar_closenav {
1.774 ehlerst 6180: background-image:url(/res/adm/pages/close-navigation.gif);
6181: }
6182:
1.795 www 6183: a#LC_content_toolbar_everything {
1.774 ehlerst 6184: background-image:url(/res/adm/pages/show-all.gif);
6185: }
6186:
1.795 www 6187: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6188: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6189: }
6190:
1.795 www 6191: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6192: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6193: }
6194:
1.795 www 6195: a#LC_content_toolbar_changefolder {
1.757 schulted 6196: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6197: }
6198:
1.795 www 6199: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6200: background-image:url(/res/adm/pages/open-all-folders.gif);
6201: }
6202:
1.795 www 6203: ul#LC_toolbar li a:hover {
1.757 schulted 6204: background-position: bottom center;
6205: }
6206:
1.795 www 6207: ul#LC_toolbar {
1.779 bisitz 6208: padding:0;
1.757 schulted 6209: margin: 2px;
6210: list-style:none;
6211: position:relative;
6212: background-color:white;
6213: }
6214:
1.795 www 6215: ul#LC_toolbar li {
1.757 schulted 6216: border:1px solid white;
6217: padding:0;
6218: margin: 0;
1.795 www 6219: float: left;
1.767 droeschl 6220: display:inline;
1.757 schulted 6221: vertical-align:middle;
1.795 www 6222: }
1.757 schulted 6223:
1.783 amueller 6224:
1.795 www 6225: a.LC_toolbarItem {
1.767 droeschl 6226: display:block;
1.757 schulted 6227: padding:0;
6228: margin:0;
6229: height: 32px;
6230: width: 32px;
1.779 bisitz 6231: color:white;
6232: border:0 none;
1.757 schulted 6233: background-repeat:no-repeat;
6234: background-color:transparent;
6235: }
6236:
1.782 bisitz 6237: ul.LC_functionslist li {
6238: float: left;
6239: white-space: nowrap;
6240: height: 35px; /* at least as high as heighest list item */
6241: margin: 0px 15px 15px 10px;
6242: }
6243:
1.757 schulted 6244:
1.343 albertel 6245: END
6246: }
6247:
1.306 albertel 6248: =pod
6249:
6250: =item * &headtag()
6251:
6252: Returns a uniform footer for LON-CAPA web pages.
6253:
1.307 albertel 6254: Inputs: $title - optional title for the head
6255: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6256: $args - optional arguments
1.319 albertel 6257: force_register - if is true call registerurl so the remote is
6258: informed
1.415 albertel 6259: redirect -> array ref of
6260: 1- seconds before redirect occurs
6261: 2- url to redirect to
6262: 3- whether the side effect should occur
1.315 albertel 6263: (side effect of setting
6264: $env{'internal.head.redirect'} to the url
6265: redirected too)
1.352 albertel 6266: domain -> force to color decorate a page for a specific
6267: domain
6268: function -> force usage of a specific rolish color scheme
6269: bgcolor -> override the default page bgcolor
1.460 albertel 6270: no_auto_mt_title
6271: -> prevent &mt()ing the title arg
1.464 albertel 6272:
1.306 albertel 6273: =cut
6274:
6275: sub headtag {
1.313 albertel 6276: my ($title,$head_extra,$args) = @_;
1.306 albertel 6277:
1.363 albertel 6278: my $function = $args->{'function'} || &get_users_function();
6279: my $domain = $args->{'domain'} || &determinedomain();
6280: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6281: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6282: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6283: #time(),
1.418 albertel 6284: $env{'environment.color.timestamp'},
1.363 albertel 6285: $function,$domain,$bgcolor);
6286:
1.369 www 6287: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6288:
1.308 albertel 6289: my $result =
6290: '<head>'.
1.461 albertel 6291: &font_settings();
1.319 albertel 6292:
1.461 albertel 6293: if (!$args->{'frameset'}) {
6294: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6295: }
1.319 albertel 6296: if ($args->{'force_register'}) {
6297: $result .= &Apache::lonmenu::registerurl(1);
6298: }
1.436 albertel 6299: if (!$args->{'no_nav_bar'}
6300: && !$args->{'only_body'}
6301: && !$args->{'frameset'}) {
6302: $result .= &help_menu_js();
6303: }
1.319 albertel 6304:
1.314 albertel 6305: if (ref($args->{'redirect'})) {
1.414 albertel 6306: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6307: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6308: if (!$inhibit_continue) {
6309: $env{'internal.head.redirect'} = $url;
6310: }
1.313 albertel 6311: $result.=<<ADDMETA
6312: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6313: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6314: ADDMETA
6315: }
1.306 albertel 6316: if (!defined($title)) {
6317: $title = 'The LearningOnline Network with CAPA';
6318: }
1.460 albertel 6319: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6320: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6321: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6322: .$head_extra;
1.306 albertel 6323: return $result;
6324: }
6325:
6326: =pod
6327:
1.340 albertel 6328: =item * &font_settings()
6329:
6330: Returns neccessary <meta> to set the proper encoding
6331:
6332: Inputs: none
6333:
6334: =cut
6335:
6336: sub font_settings {
6337: my $headerstring='';
1.647 www 6338: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6339: $headerstring.=
6340: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6341: }
6342: return $headerstring;
6343: }
6344:
1.341 albertel 6345: =pod
6346:
6347: =item * &xml_begin()
6348:
6349: Returns the needed doctype and <html>
6350:
6351: Inputs: none
6352:
6353: =cut
6354:
6355: sub xml_begin {
6356: my $output='';
6357:
1.592 albertel 6358: if ($env{'internal.start_page'}==1) {
6359: &Apache::lonhtmlcommon::init_htmlareafields();
6360: }
1.342 albertel 6361:
1.341 albertel 6362: if ($env{'browser.mathml'}) {
6363: $output='<?xml version="1.0"?>'
6364: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6365: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6366:
6367: # .'<!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">] >'
6368: .'<!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">'
6369: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6370: .'xmlns="http://www.w3.org/1999/xhtml">';
6371: } else {
6372: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6373: }
6374: return $output;
6375: }
1.340 albertel 6376:
6377: =pod
6378:
1.306 albertel 6379: =item * &endheadtag()
6380:
6381: Returns a uniform </head> for LON-CAPA web pages.
6382:
6383: Inputs: none
6384:
6385: =cut
6386:
6387: sub endheadtag {
6388: return '</head>';
6389: }
6390:
6391: =pod
6392:
6393: =item * &head()
6394:
6395: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6396:
1.648 raeburn 6397: Inputs:
6398:
6399: =over 4
6400:
6401: $title - optional title for the page
6402:
6403: $head_extra - optional extra HTML to put inside the <head>
6404:
6405: =back
1.405 albertel 6406:
1.306 albertel 6407: =cut
6408:
6409: sub head {
1.325 albertel 6410: my ($title,$head_extra,$args) = @_;
6411: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6412: }
6413:
6414: =pod
6415:
6416: =item * &start_page()
6417:
6418: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6419:
1.648 raeburn 6420: Inputs:
6421:
6422: =over 4
6423:
6424: $title - optional title for the page
6425:
6426: $head_extra - optional extra HTML to incude inside the <head>
6427:
6428: $args - additional optional args supported are:
6429:
6430: =over 8
6431:
6432: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6433: arg on
1.648 raeburn 6434: no_nav_bar -> is true will set &bodytag() notopbar arg on
6435: add_entries -> additional attributes to add to the <body>
6436: domain -> force to color decorate a page for a
1.317 albertel 6437: specific domain
1.648 raeburn 6438: function -> force usage of a specific rolish color
1.317 albertel 6439: scheme
1.648 raeburn 6440: redirect -> see &headtag()
6441: bgcolor -> override the default page bg color
6442: js_ready -> return a string ready for being used in
1.317 albertel 6443: a javascript writeln
1.648 raeburn 6444: html_encode -> return a string ready for being used in
1.320 albertel 6445: a html attribute
1.648 raeburn 6446: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6447: $forcereg arg
1.648 raeburn 6448: body_title -> alternate text to use instead of $title
1.326 albertel 6449: in the title box that appears, this text
6450: is not auto translated like the $title is
1.648 raeburn 6451: frameset -> if true will start with a <frameset>
1.330 albertel 6452: rather than <body>
1.648 raeburn 6453: no_title -> if true the title bar won't be shown
6454: skip_phases -> hash ref of
1.338 albertel 6455: head -> skip the <html><head> generation
6456: body -> skip all <body> generation
1.648 raeburn 6457: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6458: 'Switch To Inline Menu' link
1.648 raeburn 6459: no_auto_mt_title -> prevent &mt()ing the title arg
6460: inherit_jsmath -> when creating popup window in a page,
6461: should it have jsmath forced on by the
6462: current page
1.361 albertel 6463:
1.648 raeburn 6464: =back
1.460 albertel 6465:
1.648 raeburn 6466: =back
1.562 albertel 6467:
1.306 albertel 6468: =cut
6469:
6470: sub start_page {
1.309 albertel 6471: my ($title,$head_extra,$args) = @_;
1.318 albertel 6472: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6473: my %head_args;
1.352 albertel 6474: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6475: 'bgcolor','frameset','no_nav_bar','only_body',
6476: 'no_auto_mt_title') {
1.319 albertel 6477: if (defined($args->{$arg})) {
1.324 raeburn 6478: $head_args{$arg} = $args->{$arg};
1.319 albertel 6479: }
1.313 albertel 6480: }
1.319 albertel 6481:
1.315 albertel 6482: $env{'internal.start_page'}++;
1.338 albertel 6483: my $result;
6484: if (! exists($args->{'skip_phases'}{'head'}) ) {
6485: $result.=
1.341 albertel 6486: &xml_begin().
1.338 albertel 6487: &headtag($title,$head_extra,\%head_args).&endheadtag();
6488: }
6489:
6490: if (! exists($args->{'skip_phases'}{'body'}) ) {
6491: if ($args->{'frameset'}) {
6492: my $attr_string = &make_attr_string($args->{'force_register'},
6493: $args->{'add_entries'});
6494: $result .= "\n<frameset $attr_string>\n";
6495: } else {
6496: $result .=
6497: &bodytag($title,
6498: $args->{'function'}, $args->{'add_entries'},
6499: $args->{'only_body'}, $args->{'domain'},
6500: $args->{'force_register'}, $args->{'body_title'},
6501: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6502: $args->{'no_title'}, $args->{'no_inline_link'},
6503: $args);
1.338 albertel 6504: }
1.330 albertel 6505: }
1.338 albertel 6506:
1.315 albertel 6507: if ($args->{'js_ready'}) {
1.713 kaisler 6508: $result = &js_ready($result);
1.315 albertel 6509: }
1.320 albertel 6510: if ($args->{'html_encode'}) {
1.713 kaisler 6511: $result = &html_encode($result);
6512: }
6513:
1.758 kaisler 6514: #Breadcrumbs
6515: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6516: &Apache::lonhtmlcommon::clear_breadcrumbs();
6517: #if any br links exists, add them to the breadcrumbs
6518: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6519: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6520: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6521: }
6522: }
6523:
6524: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6525: if(exists($args->{'bread_crumbs_component'})){
6526: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6527: }else{
6528: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6529: }
1.320 albertel 6530: }
1.315 albertel 6531: return $result;
1.306 albertel 6532: }
6533:
1.330 albertel 6534:
1.306 albertel 6535: =pod
6536:
6537: =item * &head()
6538:
6539: Returns a complete </body></html> section for LON-CAPA web pages.
6540:
1.315 albertel 6541: Inputs: $args - additional optional args supported are:
6542: js_ready -> return a string ready for being used in
6543: a javascript writeln
1.320 albertel 6544: html_encode -> return a string ready for being used in
6545: a html attribute
1.330 albertel 6546: frameset -> if true will start with a <frameset>
6547: rather than <body>
1.493 albertel 6548: dicsussion -> if true will get discussion from
6549: lonxml::xmlend
6550: (you can pass the target and parser arguments
6551: through optional 'target' and 'parser' args
6552: to this routine)
1.306 albertel 6553:
6554: =cut
6555:
6556: sub end_page {
1.315 albertel 6557: my ($args) = @_;
6558: $env{'internal.end_page'}++;
1.330 albertel 6559: my $result;
1.335 albertel 6560: if ($args->{'discussion'}) {
6561: my ($target,$parser);
6562: if (ref($args->{'discussion'})) {
6563: ($target,$parser) =($args->{'discussion'}{'target'},
6564: $args->{'discussion'}{'parser'});
6565: }
6566: $result .= &Apache::lonxml::xmlend($target,$parser);
6567: }
6568:
1.330 albertel 6569: if ($args->{'frameset'}) {
6570: $result .= '</frameset>';
6571: } else {
1.635 raeburn 6572: $result .= &endbodytag($args);
1.330 albertel 6573: }
6574: $result .= "\n</html>";
6575:
1.315 albertel 6576: if ($args->{'js_ready'}) {
1.317 albertel 6577: $result = &js_ready($result);
1.315 albertel 6578: }
1.335 albertel 6579:
1.320 albertel 6580: if ($args->{'html_encode'}) {
6581: $result = &html_encode($result);
6582: }
1.335 albertel 6583:
1.315 albertel 6584: return $result;
6585: }
6586:
1.320 albertel 6587: sub html_encode {
6588: my ($result) = @_;
6589:
1.322 albertel 6590: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6591:
6592: return $result;
6593: }
1.317 albertel 6594: sub js_ready {
6595: my ($result) = @_;
6596:
1.323 albertel 6597: $result =~ s/[\n\r]/ /xmsg;
6598: $result =~ s/\\/\\\\/xmsg;
6599: $result =~ s/'/\\'/xmsg;
1.372 albertel 6600: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6601:
6602: return $result;
6603: }
6604:
1.315 albertel 6605: sub validate_page {
6606: if ( exists($env{'internal.start_page'})
1.316 albertel 6607: && $env{'internal.start_page'} > 1) {
6608: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6609: $env{'internal.start_page'}.' '.
1.316 albertel 6610: $ENV{'request.filename'});
1.315 albertel 6611: }
6612: if ( exists($env{'internal.end_page'})
1.316 albertel 6613: && $env{'internal.end_page'} > 1) {
6614: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6615: $env{'internal.end_page'}.' '.
1.316 albertel 6616: $env{'request.filename'});
1.315 albertel 6617: }
6618: if ( exists($env{'internal.start_page'})
6619: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6620: &Apache::lonnet::logthis('start_page called without end_page '.
6621: $env{'request.filename'});
1.315 albertel 6622: }
6623: if ( ! exists($env{'internal.start_page'})
6624: && exists($env{'internal.end_page'})) {
1.316 albertel 6625: &Apache::lonnet::logthis('end_page called without start_page'.
6626: $env{'request.filename'});
1.315 albertel 6627: }
1.306 albertel 6628: }
1.315 albertel 6629:
1.318 albertel 6630: sub simple_error_page {
6631: my ($r,$title,$msg) = @_;
6632: my $page =
6633: &Apache::loncommon::start_page($title).
6634: &mt($msg).
6635: &Apache::loncommon::end_page();
6636: if (ref($r)) {
6637: $r->print($page);
1.327 albertel 6638: return;
1.318 albertel 6639: }
6640: return $page;
6641: }
1.347 albertel 6642:
6643: {
1.610 albertel 6644: my @row_count;
1.347 albertel 6645: sub start_data_table {
1.422 albertel 6646: my ($add_class) = @_;
6647: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6648: unshift(@row_count,0);
1.422 albertel 6649: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6650: }
6651:
6652: sub end_data_table {
1.610 albertel 6653: shift(@row_count);
1.389 albertel 6654: return '</table>'."\n";;
1.347 albertel 6655: }
6656:
6657: sub start_data_table_row {
1.422 albertel 6658: my ($add_class) = @_;
1.610 albertel 6659: $row_count[0]++;
6660: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6661: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6662: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6663: }
1.471 banghart 6664:
6665: sub continue_data_table_row {
6666: my ($add_class) = @_;
1.610 albertel 6667: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6668: $css_class = (join(' ',$css_class,$add_class));
6669: return '<tr class="'.$css_class.'">'."\n";;
6670: }
1.347 albertel 6671:
6672: sub end_data_table_row {
1.389 albertel 6673: return '</tr>'."\n";;
1.347 albertel 6674: }
1.367 www 6675:
1.421 albertel 6676: sub start_data_table_empty_row {
1.707 bisitz 6677: # $row_count[0]++;
1.421 albertel 6678: return '<tr class="LC_empty_row" >'."\n";;
6679: }
6680:
6681: sub end_data_table_empty_row {
6682: return '</tr>'."\n";;
6683: }
6684:
1.367 www 6685: sub start_data_table_header_row {
1.389 albertel 6686: return '<tr class="LC_header_row">'."\n";;
1.367 www 6687: }
6688:
6689: sub end_data_table_header_row {
1.389 albertel 6690: return '</tr>'."\n";;
1.367 www 6691: }
1.347 albertel 6692: }
6693:
1.548 albertel 6694: =pod
6695:
6696: =item * &inhibit_menu_check($arg)
6697:
6698: Checks for a inhibitmenu state and generates output to preserve it
6699:
6700: Inputs: $arg - can be any of
6701: - undef - in which case the return value is a string
6702: to add into arguments list of a uri
6703: - 'input' - in which case the return value is a HTML
6704: <form> <input> field of type hidden to
6705: preserve the value
6706: - a url - in which case the return value is the url with
6707: the neccesary cgi args added to preserve the
6708: inhibitmenu state
6709: - a ref to a url - no return value, but the string is
6710: updated to include the neccessary cgi
6711: args to preserve the inhibitmenu state
6712:
6713: =cut
6714:
6715: sub inhibit_menu_check {
6716: my ($arg) = @_;
6717: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6718: if ($arg eq 'input') {
6719: if ($env{'form.inhibitmenu'}) {
6720: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6721: } else {
6722: return
6723: }
6724: }
6725: if ($env{'form.inhibitmenu'}) {
6726: if (ref($arg)) {
6727: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6728: } elsif ($arg eq '') {
6729: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6730: } else {
6731: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6732: }
6733: }
6734: if (!ref($arg)) {
6735: return $arg;
6736: }
6737: }
6738:
1.251 albertel 6739: ###############################################
1.182 matthew 6740:
6741: =pod
6742:
1.549 albertel 6743: =back
6744:
6745: =head1 User Information Routines
6746:
6747: =over 4
6748:
1.405 albertel 6749: =item * &get_users_function()
1.182 matthew 6750:
6751: Used by &bodytag to determine the current users primary role.
6752: Returns either 'student','coordinator','admin', or 'author'.
6753:
6754: =cut
6755:
6756: ###############################################
6757: sub get_users_function {
6758: my $function = 'student';
1.258 albertel 6759: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6760: $function='coordinator';
6761: }
1.258 albertel 6762: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6763: $function='admin';
6764: }
1.258 albertel 6765: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6766: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6767: $function='author';
6768: }
6769: return $function;
1.54 www 6770: }
1.99 www 6771:
6772: ###############################################
6773:
1.233 raeburn 6774: =pod
6775:
1.542 raeburn 6776: =item * &check_user_status()
1.274 raeburn 6777:
6778: Determines current status of supplied role for a
6779: specific user. Roles can be active, previous or future.
6780:
6781: Inputs:
6782: user's domain, user's username, course's domain,
1.375 raeburn 6783: course's number, optional section ID.
1.274 raeburn 6784:
6785: Outputs:
6786: role status: active, previous or future.
6787:
6788: =cut
6789:
6790: sub check_user_status {
1.412 raeburn 6791: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6792: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6793: my @uroles = keys %userinfo;
6794: my $srchstr;
6795: my $active_chk = 'none';
1.412 raeburn 6796: my $now = time;
1.274 raeburn 6797: if (@uroles > 0) {
1.412 raeburn 6798: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6799: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6800: } else {
1.412 raeburn 6801: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6802: }
6803: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6804: my $role_end = 0;
6805: my $role_start = 0;
6806: $active_chk = 'active';
1.412 raeburn 6807: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6808: $role_end = $1;
6809: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6810: $role_start = $1;
1.274 raeburn 6811: }
6812: }
6813: if ($role_start > 0) {
1.412 raeburn 6814: if ($now < $role_start) {
1.274 raeburn 6815: $active_chk = 'future';
6816: }
6817: }
6818: if ($role_end > 0) {
1.412 raeburn 6819: if ($now > $role_end) {
1.274 raeburn 6820: $active_chk = 'previous';
6821: }
6822: }
6823: }
6824: }
6825: return $active_chk;
6826: }
6827:
6828: ###############################################
6829:
6830: =pod
6831:
1.405 albertel 6832: =item * &get_sections()
1.233 raeburn 6833:
6834: Determines all the sections for a course including
6835: sections with students and sections containing other roles.
1.419 raeburn 6836: Incoming parameters:
6837:
6838: 1. domain
6839: 2. course number
6840: 3. reference to array containing roles for which sections should
6841: be gathered (optional).
6842: 4. reference to array containing status types for which sections
6843: should be gathered (optional).
6844:
6845: If the third argument is undefined, sections are gathered for any role.
6846: If the fourth argument is undefined, sections are gathered for any status.
6847: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6848:
1.374 raeburn 6849: Returns section hash (keys are section IDs, values are
6850: number of users in each section), subject to the
1.419 raeburn 6851: optional roles filter, optional status filter
1.233 raeburn 6852:
6853: =cut
6854:
6855: ###############################################
6856: sub get_sections {
1.419 raeburn 6857: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6858: if (!defined($cdom) || !defined($cnum)) {
6859: my $cid = $env{'request.course.id'};
6860:
6861: return if (!defined($cid));
6862:
6863: $cdom = $env{'course.'.$cid.'.domain'};
6864: $cnum = $env{'course.'.$cid.'.num'};
6865: }
6866:
6867: my %sectioncount;
1.419 raeburn 6868: my $now = time;
1.240 albertel 6869:
1.366 albertel 6870: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6871: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6872: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6873: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6874: my $start_index = &Apache::loncoursedata::CL_START();
6875: my $end_index = &Apache::loncoursedata::CL_END();
6876: my $status;
1.366 albertel 6877: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6878: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6879: $data->[$status_index],
6880: $data->[$start_index],
6881: $data->[$end_index]);
6882: if ($stu_status eq 'Active') {
6883: $status = 'active';
6884: } elsif ($end < $now) {
6885: $status = 'previous';
6886: } elsif ($start > $now) {
6887: $status = 'future';
6888: }
6889: if ($section ne '-1' && $section !~ /^\s*$/) {
6890: if ((!defined($possible_status)) || (($status ne '') &&
6891: (grep/^\Q$status\E$/,@{$possible_status}))) {
6892: $sectioncount{$section}++;
6893: }
1.240 albertel 6894: }
6895: }
6896: }
6897: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6898: foreach my $user (sort(keys(%courseroles))) {
6899: if ($user !~ /^(\w{2})/) { next; }
6900: my ($role) = ($user =~ /^(\w{2})/);
6901: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6902: my ($section,$status);
1.240 albertel 6903: if ($role eq 'cr' &&
6904: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6905: $section=$1;
6906: }
6907: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6908: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6909: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6910: if ($end == -1 && $start == -1) {
6911: next; #deleted role
6912: }
6913: if (!defined($possible_status)) {
6914: $sectioncount{$section}++;
6915: } else {
6916: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6917: $status = 'active';
6918: } elsif ($end < $now) {
6919: $status = 'future';
6920: } elsif ($start > $now) {
6921: $status = 'previous';
6922: }
6923: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6924: $sectioncount{$section}++;
6925: }
6926: }
1.233 raeburn 6927: }
1.366 albertel 6928: return %sectioncount;
1.233 raeburn 6929: }
6930:
1.274 raeburn 6931: ###############################################
1.294 raeburn 6932:
6933: =pod
1.405 albertel 6934:
6935: =item * &get_course_users()
6936:
1.275 raeburn 6937: Retrieves usernames:domains for users in the specified course
6938: with specific role(s), and access status.
6939:
6940: Incoming parameters:
1.277 albertel 6941: 1. course domain
6942: 2. course number
6943: 3. access status: users must have - either active,
1.275 raeburn 6944: previous, future, or all.
1.277 albertel 6945: 4. reference to array of permissible roles
1.288 raeburn 6946: 5. reference to array of section restrictions (optional)
6947: 6. reference to results object (hash of hashes).
6948: 7. reference to optional userdata hash
1.609 raeburn 6949: 8. reference to optional statushash
1.630 raeburn 6950: 9. flag if privileged users (except those set to unhide in
6951: course settings) should be excluded
1.609 raeburn 6952: Keys of top level results hash are roles.
1.275 raeburn 6953: Keys of inner hashes are username:domain, with
6954: values set to access type.
1.288 raeburn 6955: Optional userdata hash returns an array with arguments in the
6956: same order as loncoursedata::get_classlist() for student data.
6957:
1.609 raeburn 6958: Optional statushash returns
6959:
1.288 raeburn 6960: Entries for end, start, section and status are blank because
6961: of the possibility of multiple values for non-student roles.
6962:
1.275 raeburn 6963: =cut
1.405 albertel 6964:
1.275 raeburn 6965: ###############################################
1.405 albertel 6966:
1.275 raeburn 6967: sub get_course_users {
1.630 raeburn 6968: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6969: my %idx = ();
1.419 raeburn 6970: my %seclists;
1.288 raeburn 6971:
6972: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6973: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6974: $idx{end} = &Apache::loncoursedata::CL_END();
6975: $idx{start} = &Apache::loncoursedata::CL_START();
6976: $idx{id} = &Apache::loncoursedata::CL_ID();
6977: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6978: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6979: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6980:
1.290 albertel 6981: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6982: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6983: my $now = time;
1.277 albertel 6984: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6985: my $match = 0;
1.412 raeburn 6986: my $secmatch = 0;
1.419 raeburn 6987: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6988: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6989: if ($section eq '') {
6990: $section = 'none';
6991: }
1.291 albertel 6992: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6993: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6994: $secmatch = 1;
6995: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6996: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6997: $secmatch = 1;
6998: }
6999: } else {
1.419 raeburn 7000: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7001: $secmatch = 1;
7002: }
1.290 albertel 7003: }
1.412 raeburn 7004: if (!$secmatch) {
7005: next;
7006: }
1.419 raeburn 7007: }
1.275 raeburn 7008: if (defined($$types{'active'})) {
1.288 raeburn 7009: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7010: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7011: $match = 1;
1.275 raeburn 7012: }
7013: }
7014: if (defined($$types{'previous'})) {
1.609 raeburn 7015: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7016: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7017: $match = 1;
1.275 raeburn 7018: }
7019: }
7020: if (defined($$types{'future'})) {
1.609 raeburn 7021: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7022: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7023: $match = 1;
1.275 raeburn 7024: }
7025: }
1.609 raeburn 7026: if ($match) {
7027: push(@{$seclists{$student}},$section);
7028: if (ref($userdata) eq 'HASH') {
7029: $$userdata{$student} = $$classlist{$student};
7030: }
7031: if (ref($statushash) eq 'HASH') {
7032: $statushash->{$student}{'st'}{$section} = $status;
7033: }
1.288 raeburn 7034: }
1.275 raeburn 7035: }
7036: }
1.412 raeburn 7037: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7038: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7039: my $now = time;
1.609 raeburn 7040: my %displaystatus = ( previous => 'Expired',
7041: active => 'Active',
7042: future => 'Future',
7043: );
1.630 raeburn 7044: my %nothide;
7045: if ($hidepriv) {
7046: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7047: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7048: if ($user !~ /:/) {
7049: $nothide{join(':',split(/[\@]/,$user))}=1;
7050: } else {
7051: $nothide{$user} = 1;
7052: }
7053: }
7054: }
1.439 raeburn 7055: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7056: my $match = 0;
1.412 raeburn 7057: my $secmatch = 0;
1.439 raeburn 7058: my $status;
1.412 raeburn 7059: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7060: $user =~ s/:$//;
1.439 raeburn 7061: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7062: if ($end == -1 || $start == -1) {
7063: next;
7064: }
7065: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7066: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7067: my ($uname,$udom) = split(/:/,$user);
7068: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7069: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7070: $secmatch = 1;
7071: } elsif ($usec eq '') {
1.420 albertel 7072: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7073: $secmatch = 1;
7074: }
7075: } else {
7076: if (grep(/^\Q$usec\E$/,@{$sections})) {
7077: $secmatch = 1;
7078: }
7079: }
7080: if (!$secmatch) {
7081: next;
7082: }
1.288 raeburn 7083: }
1.419 raeburn 7084: if ($usec eq '') {
7085: $usec = 'none';
7086: }
1.275 raeburn 7087: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7088: if ($hidepriv) {
7089: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7090: (!$nothide{$uname.':'.$udom})) {
7091: next;
7092: }
7093: }
1.503 raeburn 7094: if ($end > 0 && $end < $now) {
1.439 raeburn 7095: $status = 'previous';
7096: } elsif ($start > $now) {
7097: $status = 'future';
7098: } else {
7099: $status = 'active';
7100: }
1.277 albertel 7101: foreach my $type (keys(%{$types})) {
1.275 raeburn 7102: if ($status eq $type) {
1.420 albertel 7103: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7104: push(@{$$users{$role}{$user}},$type);
7105: }
1.288 raeburn 7106: $match = 1;
7107: }
7108: }
1.419 raeburn 7109: if (($match) && (ref($userdata) eq 'HASH')) {
7110: if (!exists($$userdata{$uname.':'.$udom})) {
7111: &get_user_info($udom,$uname,\%idx,$userdata);
7112: }
1.420 albertel 7113: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7114: push(@{$seclists{$uname.':'.$udom}},$usec);
7115: }
1.609 raeburn 7116: if (ref($statushash) eq 'HASH') {
7117: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7118: }
1.275 raeburn 7119: }
7120: }
7121: }
7122: }
1.290 albertel 7123: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7124: if ((defined($cdom)) && (defined($cnum))) {
7125: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7126: if ( defined($csettings{'internal.courseowner'}) ) {
7127: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7128: next if ($owner eq '');
7129: my ($ownername,$ownerdom);
7130: if ($owner =~ /^([^:]+):([^:]+)$/) {
7131: $ownername = $1;
7132: $ownerdom = $2;
7133: } else {
7134: $ownername = $owner;
7135: $ownerdom = $cdom;
7136: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7137: }
7138: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7139: if (defined($userdata) &&
1.609 raeburn 7140: !exists($$userdata{$owner})) {
7141: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7142: if (!grep(/^none$/,@{$seclists{$owner}})) {
7143: push(@{$seclists{$owner}},'none');
7144: }
7145: if (ref($statushash) eq 'HASH') {
7146: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7147: }
1.290 albertel 7148: }
1.279 raeburn 7149: }
7150: }
7151: }
1.419 raeburn 7152: foreach my $user (keys(%seclists)) {
7153: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7154: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7155: }
1.275 raeburn 7156: }
7157: return;
7158: }
7159:
1.288 raeburn 7160: sub get_user_info {
7161: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7162: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7163: &plainname($uname,$udom,'lastname');
1.291 albertel 7164: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7165: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7166: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7167: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7168: return;
7169: }
1.275 raeburn 7170:
1.472 raeburn 7171: ###############################################
7172:
7173: =pod
7174:
7175: =item * &get_user_quota()
7176:
7177: Retrieves quota assigned for storage of portfolio files for a user
7178:
7179: Incoming parameters:
7180: 1. user's username
7181: 2. user's domain
7182:
7183: Returns:
1.536 raeburn 7184: 1. Disk quota (in Mb) assigned to student.
7185: 2. (Optional) Type of setting: custom or default
7186: (individually assigned or default for user's
7187: institutional status).
7188: 3. (Optional) - User's institutional status (e.g., faculty, staff
7189: or student - types as defined in localenroll::inst_usertypes
7190: for user's domain, which determines default quota for user.
7191: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7192:
7193: If a value has been stored in the user's environment,
1.536 raeburn 7194: it will return that, otherwise it returns the maximal default
7195: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7196:
7197: =cut
7198:
7199: ###############################################
7200:
7201:
7202: sub get_user_quota {
7203: my ($uname,$udom) = @_;
1.536 raeburn 7204: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7205: if (!defined($udom)) {
7206: $udom = $env{'user.domain'};
7207: }
7208: if (!defined($uname)) {
7209: $uname = $env{'user.name'};
7210: }
7211: if (($udom eq '' || $uname eq '') ||
7212: ($udom eq 'public') && ($uname eq 'public')) {
7213: $quota = 0;
1.536 raeburn 7214: $quotatype = 'default';
7215: $defquota = 0;
1.472 raeburn 7216: } else {
1.536 raeburn 7217: my $inststatus;
1.472 raeburn 7218: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7219: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7220: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7221: } else {
1.536 raeburn 7222: my %userenv =
7223: &Apache::lonnet::get('environment',['portfolioquota',
7224: 'inststatus'],$udom,$uname);
1.472 raeburn 7225: my ($tmp) = keys(%userenv);
7226: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7227: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7228: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7229: } else {
7230: undef(%userenv);
7231: }
7232: }
1.536 raeburn 7233: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7234: if ($quota eq '') {
1.536 raeburn 7235: $quota = $defquota;
7236: $quotatype = 'default';
7237: } else {
7238: $quotatype = 'custom';
1.472 raeburn 7239: }
7240: }
1.536 raeburn 7241: if (wantarray) {
7242: return ($quota,$quotatype,$settingstatus,$defquota);
7243: } else {
7244: return $quota;
7245: }
1.472 raeburn 7246: }
7247:
7248: ###############################################
7249:
7250: =pod
7251:
7252: =item * &default_quota()
7253:
1.536 raeburn 7254: Retrieves default quota assigned for storage of user portfolio files,
7255: given an (optional) user's institutional status.
1.472 raeburn 7256:
7257: Incoming parameters:
7258: 1. domain
1.536 raeburn 7259: 2. (Optional) institutional status(es). This is a : separated list of
7260: status types (e.g., faculty, staff, student etc.)
7261: which apply to the user for whom the default is being retrieved.
7262: If the institutional status string in undefined, the domain
7263: default quota will be returned.
1.472 raeburn 7264:
7265: Returns:
7266: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7267: 2. (Optional) institutional type which determined the value of the
7268: default quota.
1.472 raeburn 7269:
7270: If a value has been stored in the domain's configuration db,
7271: it will return that, otherwise it returns 20 (for backwards
7272: compatibility with domains which have not set up a configuration
7273: db file; the original statically defined portfolio quota was 20 Mb).
7274:
1.536 raeburn 7275: If the user's status includes multiple types (e.g., staff and student),
7276: the largest default quota which applies to the user determines the
7277: default quota returned.
7278:
1.780 raeburn 7279: =back
7280:
1.472 raeburn 7281: =cut
7282:
7283: ###############################################
7284:
7285:
7286: sub default_quota {
1.536 raeburn 7287: my ($udom,$inststatus) = @_;
7288: my ($defquota,$settingstatus);
7289: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7290: ['quotas'],$udom);
7291: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7292: if ($inststatus ne '') {
1.765 raeburn 7293: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7294: foreach my $item (@statuses) {
1.711 raeburn 7295: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7296: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7297: if ($defquota eq '') {
7298: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7299: $settingstatus = $item;
7300: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7301: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7302: $settingstatus = $item;
7303: }
7304: }
7305: } else {
7306: if ($quotahash{'quotas'}{$item} ne '') {
7307: if ($defquota eq '') {
7308: $defquota = $quotahash{'quotas'}{$item};
7309: $settingstatus = $item;
7310: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7311: $defquota = $quotahash{'quotas'}{$item};
7312: $settingstatus = $item;
7313: }
1.536 raeburn 7314: }
7315: }
7316: }
7317: }
7318: if ($defquota eq '') {
1.711 raeburn 7319: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7320: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7321: } else {
7322: $defquota = $quotahash{'quotas'}{'default'};
7323: }
1.536 raeburn 7324: $settingstatus = 'default';
7325: }
7326: } else {
7327: $settingstatus = 'default';
7328: $defquota = 20;
7329: }
7330: if (wantarray) {
7331: return ($defquota,$settingstatus);
1.472 raeburn 7332: } else {
1.536 raeburn 7333: return $defquota;
1.472 raeburn 7334: }
7335: }
7336:
1.384 raeburn 7337: sub get_secgrprole_info {
7338: my ($cdom,$cnum,$needroles,$type) = @_;
7339: my %sections_count = &get_sections($cdom,$cnum);
7340: my @sections = (sort {$a <=> $b} keys(%sections_count));
7341: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7342: my @groups = sort(keys(%curr_groups));
7343: my $allroles = [];
7344: my $rolehash;
7345: my $accesshash = {
7346: active => 'Currently has access',
7347: future => 'Will have future access',
7348: previous => 'Previously had access',
7349: };
7350: if ($needroles) {
7351: $rolehash = {'all' => 'all'};
1.385 albertel 7352: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7353: if (&Apache::lonnet::error(%user_roles)) {
7354: undef(%user_roles);
7355: }
7356: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7357: my ($role)=split(/\:/,$item,2);
7358: if ($role eq 'cr') { next; }
7359: if ($role =~ /^cr/) {
7360: $$rolehash{$role} = (split('/',$role))[3];
7361: } else {
7362: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7363: }
7364: }
7365: foreach my $key (sort(keys(%{$rolehash}))) {
7366: push(@{$allroles},$key);
7367: }
7368: push (@{$allroles},'st');
7369: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7370: }
7371: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7372: }
7373:
1.555 raeburn 7374: sub user_picker {
1.627 raeburn 7375: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7376: my $currdom = $dom;
7377: my %curr_selected = (
7378: srchin => 'dom',
1.580 raeburn 7379: srchby => 'lastname',
1.555 raeburn 7380: );
7381: my $srchterm;
1.625 raeburn 7382: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7383: if ($srch->{'srchby'} ne '') {
7384: $curr_selected{'srchby'} = $srch->{'srchby'};
7385: }
7386: if ($srch->{'srchin'} ne '') {
7387: $curr_selected{'srchin'} = $srch->{'srchin'};
7388: }
7389: if ($srch->{'srchtype'} ne '') {
7390: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7391: }
7392: if ($srch->{'srchdomain'} ne '') {
7393: $currdom = $srch->{'srchdomain'};
7394: }
7395: $srchterm = $srch->{'srchterm'};
7396: }
7397: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7398: 'usr' => 'Search criteria',
1.563 raeburn 7399: 'doma' => 'Domain/institution to search',
1.558 albertel 7400: 'uname' => 'username',
7401: 'lastname' => 'last name',
1.555 raeburn 7402: 'lastfirst' => 'last name, first name',
1.558 albertel 7403: 'crs' => 'in this course',
1.576 raeburn 7404: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7405: 'alc' => 'all LON-CAPA',
1.573 raeburn 7406: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7407: 'exact' => 'is',
7408: 'contains' => 'contains',
1.569 raeburn 7409: 'begins' => 'begins with',
1.571 raeburn 7410: 'youm' => "You must include some text to search for.",
7411: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7412: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7413: 'yomc' => "You must choose a domain when using an institutional directory search.",
7414: 'ymcd' => "You must choose a domain when using a domain search.",
7415: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7416: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7417: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7418: );
1.563 raeburn 7419: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7420: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7421:
7422: my @srchins = ('crs','dom','alc','instd');
7423:
7424: foreach my $option (@srchins) {
7425: # FIXME 'alc' option unavailable until
7426: # loncreateuser::print_user_query_page()
7427: # has been completed.
7428: next if ($option eq 'alc');
7429: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7430: if ($curr_selected{'srchin'} eq $option) {
7431: $srchinsel .= '
7432: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7433: } else {
7434: $srchinsel .= '
7435: <option value="'.$option.'">'.$lt{$option}.'</option>';
7436: }
1.555 raeburn 7437: }
1.563 raeburn 7438: $srchinsel .= "\n </select>\n";
1.555 raeburn 7439:
7440: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7441: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7442: if ($curr_selected{'srchby'} eq $option) {
7443: $srchbysel .= '
7444: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7445: } else {
7446: $srchbysel .= '
7447: <option value="'.$option.'">'.$lt{$option}.'</option>';
7448: }
7449: }
7450: $srchbysel .= "\n </select>\n";
7451:
7452: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7453: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7454: if ($curr_selected{'srchtype'} eq $option) {
7455: $srchtypesel .= '
7456: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7457: } else {
7458: $srchtypesel .= '
7459: <option value="'.$option.'">'.$lt{$option}.'</option>';
7460: }
7461: }
7462: $srchtypesel .= "\n </select>\n";
7463:
1.558 albertel 7464: my ($newuserscript,$new_user_create);
1.556 raeburn 7465:
7466: if ($forcenewuser) {
1.576 raeburn 7467: if (ref($srch) eq 'HASH') {
7468: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7469: if ($cancreate) {
7470: $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>';
7471: } else {
7472: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7473: my %usertypetext = (
7474: official => 'institutional',
7475: unofficial => 'non-institutional',
7476: );
7477: $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 />';
7478: }
1.576 raeburn 7479: }
7480: }
7481:
1.556 raeburn 7482: $newuserscript = <<"ENDSCRIPT";
7483:
1.570 raeburn 7484: function setSearch(createnew,callingForm) {
1.556 raeburn 7485: if (createnew == 1) {
1.570 raeburn 7486: for (var i=0; i<callingForm.srchby.length; i++) {
7487: if (callingForm.srchby.options[i].value == 'uname') {
7488: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7489: }
7490: }
1.570 raeburn 7491: for (var i=0; i<callingForm.srchin.length; i++) {
7492: if ( callingForm.srchin.options[i].value == 'dom') {
7493: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7494: }
7495: }
1.570 raeburn 7496: for (var i=0; i<callingForm.srchtype.length; i++) {
7497: if (callingForm.srchtype.options[i].value == 'exact') {
7498: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7499: }
7500: }
1.570 raeburn 7501: for (var i=0; i<callingForm.srchdomain.length; i++) {
7502: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7503: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7504: }
7505: }
7506: }
7507: }
7508: ENDSCRIPT
1.558 albertel 7509:
1.556 raeburn 7510: }
7511:
1.555 raeburn 7512: my $output = <<"END_BLOCK";
1.556 raeburn 7513: <script type="text/javascript">
1.570 raeburn 7514: function validateEntry(callingForm) {
1.558 albertel 7515:
1.556 raeburn 7516: var checkok = 1;
1.558 albertel 7517: var srchin;
1.570 raeburn 7518: for (var i=0; i<callingForm.srchin.length; i++) {
7519: if ( callingForm.srchin[i].checked ) {
7520: srchin = callingForm.srchin[i].value;
1.558 albertel 7521: }
7522: }
7523:
1.570 raeburn 7524: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7525: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7526: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7527: var srchterm = callingForm.srchterm.value;
7528: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7529: var msg = "";
7530:
7531: if (srchterm == "") {
7532: checkok = 0;
1.571 raeburn 7533: msg += "$lt{'youm'}\\n";
1.556 raeburn 7534: }
7535:
1.569 raeburn 7536: if (srchtype== 'begins') {
7537: if (srchterm.length < 2) {
7538: checkok = 0;
1.571 raeburn 7539: msg += "$lt{'thte'}\\n";
1.569 raeburn 7540: }
7541: }
7542:
1.556 raeburn 7543: if (srchtype== 'contains') {
7544: if (srchterm.length < 3) {
7545: checkok = 0;
1.571 raeburn 7546: msg += "$lt{'thet'}\\n";
1.556 raeburn 7547: }
7548: }
7549: if (srchin == 'instd') {
7550: if (srchdomain == '') {
7551: checkok = 0;
1.571 raeburn 7552: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7553: }
7554: }
7555: if (srchin == 'dom') {
7556: if (srchdomain == '') {
7557: checkok = 0;
1.571 raeburn 7558: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7559: }
7560: }
7561: if (srchby == 'lastfirst') {
7562: if (srchterm.indexOf(",") == -1) {
7563: checkok = 0;
1.571 raeburn 7564: msg += "$lt{'whus'}\\n";
1.556 raeburn 7565: }
7566: if (srchterm.indexOf(",") == srchterm.length -1) {
7567: checkok = 0;
1.571 raeburn 7568: msg += "$lt{'whse'}\\n";
1.556 raeburn 7569: }
7570: }
7571: if (checkok == 0) {
1.571 raeburn 7572: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7573: return;
7574: }
7575: if (checkok == 1) {
1.570 raeburn 7576: callingForm.submit();
1.556 raeburn 7577: }
7578: }
7579:
7580: $newuserscript
7581:
7582: </script>
1.558 albertel 7583:
7584: $new_user_create
7585:
1.555 raeburn 7586: <table>
1.558 albertel 7587: <tr>
1.573 raeburn 7588: <td>$lt{'doma'}:</td>
7589: <td>$domform</td>
7590: </td>
7591: </tr>
7592: <tr>
7593: <td>$lt{'usr'}:</td>
1.563 raeburn 7594: <td>$srchbysel
7595: $srchtypesel
7596: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7597: $srchinsel
1.563 raeburn 7598: </td>
7599: </tr>
1.555 raeburn 7600: </table>
7601: <br />
7602: END_BLOCK
1.558 albertel 7603:
1.555 raeburn 7604: return $output;
7605: }
7606:
1.612 raeburn 7607: sub user_rule_check {
1.615 raeburn 7608: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7609: my $response;
7610: if (ref($usershash) eq 'HASH') {
7611: foreach my $user (keys(%{$usershash})) {
7612: my ($uname,$udom) = split(/:/,$user);
7613: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7614: my ($id,$newuser);
1.612 raeburn 7615: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7616: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7617: $id = $usershash->{$user}->{'id'};
7618: }
7619: my $inst_response;
7620: if (ref($checks) eq 'HASH') {
7621: if (defined($checks->{'username'})) {
1.615 raeburn 7622: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7623: &Apache::lonnet::get_instuser($udom,$uname);
7624: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7625: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7626: &Apache::lonnet::get_instuser($udom,undef,$id);
7627: }
1.615 raeburn 7628: } else {
7629: ($inst_response,%{$inst_results->{$user}}) =
7630: &Apache::lonnet::get_instuser($udom,$uname);
7631: return;
1.612 raeburn 7632: }
1.615 raeburn 7633: if (!$got_rules->{$udom}) {
1.612 raeburn 7634: my %domconfig = &Apache::lonnet::get_dom('configuration',
7635: ['usercreation'],$udom);
7636: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7637: foreach my $item ('username','id') {
1.612 raeburn 7638: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7639: $$curr_rules{$udom}{$item} =
7640: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7641: }
7642: }
7643: }
1.615 raeburn 7644: $got_rules->{$udom} = 1;
1.585 raeburn 7645: }
1.612 raeburn 7646: foreach my $item (keys(%{$checks})) {
7647: if (ref($$curr_rules{$udom}) eq 'HASH') {
7648: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7649: if (@{$$curr_rules{$udom}{$item}} > 0) {
7650: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7651: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7652: if ($rule_check{$rule}) {
7653: $$rulematch{$user}{$item} = $rule;
7654: if ($inst_response eq 'ok') {
1.615 raeburn 7655: if (ref($inst_results) eq 'HASH') {
7656: if (ref($inst_results->{$user}) eq 'HASH') {
7657: if (keys(%{$inst_results->{$user}}) == 0) {
7658: $$alerts{$item}{$udom}{$uname} = 1;
7659: }
1.612 raeburn 7660: }
7661: }
1.615 raeburn 7662: }
7663: last;
1.585 raeburn 7664: }
7665: }
7666: }
7667: }
7668: }
7669: }
7670: }
7671: }
1.612 raeburn 7672: return;
7673: }
7674:
7675: sub user_rule_formats {
7676: my ($domain,$domdesc,$curr_rules,$check) = @_;
7677: my %text = (
7678: 'username' => 'Usernames',
7679: 'id' => 'IDs',
7680: );
7681: my $output;
7682: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7683: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7684: if (@{$ruleorder} > 0) {
7685: $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>';
7686: foreach my $rule (@{$ruleorder}) {
7687: if (ref($curr_rules) eq 'ARRAY') {
7688: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7689: if (ref($rules->{$rule}) eq 'HASH') {
7690: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7691: $rules->{$rule}{'desc'}.'</li>';
7692: }
7693: }
7694: }
7695: }
7696: $output .= '</ul>';
7697: }
7698: }
7699: return $output;
7700: }
7701:
7702: sub instrule_disallow_msg {
1.615 raeburn 7703: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7704: my $response;
7705: my %text = (
7706: item => 'username',
7707: items => 'usernames',
7708: match => 'matches',
7709: do => 'does',
7710: action => 'a username',
7711: one => 'one',
7712: );
7713: if ($count > 1) {
7714: $text{'item'} = 'usernames';
7715: $text{'match'} ='match';
7716: $text{'do'} = 'do';
7717: $text{'action'} = 'usernames',
7718: $text{'one'} = 'ones';
7719: }
7720: if ($checkitem eq 'id') {
7721: $text{'items'} = 'IDs';
7722: $text{'item'} = 'ID';
7723: $text{'action'} = 'an ID';
1.615 raeburn 7724: if ($count > 1) {
7725: $text{'item'} = 'IDs';
7726: $text{'action'} = 'IDs';
7727: }
1.612 raeburn 7728: }
1.674 bisitz 7729: $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 7730: if ($mode eq 'upload') {
7731: if ($checkitem eq 'username') {
7732: $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'}.");
7733: } elsif ($checkitem eq 'id') {
1.674 bisitz 7734: $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 7735: }
1.669 raeburn 7736: } elsif ($mode eq 'selfcreate') {
7737: if ($checkitem eq 'id') {
7738: $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.");
7739: }
1.615 raeburn 7740: } else {
7741: if ($checkitem eq 'username') {
7742: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7743: } elsif ($checkitem eq 'id') {
7744: $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.");
7745: }
1.612 raeburn 7746: }
7747: return $response;
1.585 raeburn 7748: }
7749:
1.624 raeburn 7750: sub personal_data_fieldtitles {
7751: my %fieldtitles = &Apache::lonlocal::texthash (
7752: id => 'Student/Employee ID',
7753: permanentemail => 'E-mail address',
7754: lastname => 'Last Name',
7755: firstname => 'First Name',
7756: middlename => 'Middle Name',
7757: generation => 'Generation',
7758: gen => 'Generation',
1.765 raeburn 7759: inststatus => 'Affiliation',
1.624 raeburn 7760: );
7761: return %fieldtitles;
7762: }
7763:
1.642 raeburn 7764: sub sorted_inst_types {
7765: my ($dom) = @_;
7766: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7767: my $othertitle = &mt('All users');
7768: if ($env{'request.course.id'}) {
1.668 raeburn 7769: $othertitle = &mt('Any users');
1.642 raeburn 7770: }
7771: my @types;
7772: if (ref($order) eq 'ARRAY') {
7773: @types = @{$order};
7774: }
7775: if (@types == 0) {
7776: if (ref($usertypes) eq 'HASH') {
7777: @types = sort(keys(%{$usertypes}));
7778: }
7779: }
7780: if (keys(%{$usertypes}) > 0) {
7781: $othertitle = &mt('Other users');
7782: }
7783: return ($othertitle,$usertypes,\@types);
7784: }
7785:
1.645 raeburn 7786: sub get_institutional_codes {
7787: my ($settings,$allcourses,$LC_code) = @_;
7788: # Get complete list of course sections to update
7789: my @currsections = ();
7790: my @currxlists = ();
7791: my $coursecode = $$settings{'internal.coursecode'};
7792:
7793: if ($$settings{'internal.sectionnums'} ne '') {
7794: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7795: }
7796:
7797: if ($$settings{'internal.crosslistings'} ne '') {
7798: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7799: }
7800:
7801: if (@currxlists > 0) {
7802: foreach (@currxlists) {
7803: if (m/^([^:]+):(\w*)$/) {
7804: unless (grep/^$1$/,@{$allcourses}) {
7805: push @{$allcourses},$1;
7806: $$LC_code{$1} = $2;
7807: }
7808: }
7809: }
7810: }
7811:
7812: if (@currsections > 0) {
7813: foreach (@currsections) {
7814: if (m/^(\w+):(\w*)$/) {
7815: my $sec = $coursecode.$1;
7816: my $lc_sec = $2;
7817: unless (grep/^$sec$/,@{$allcourses}) {
7818: push @{$allcourses},$sec;
7819: $$LC_code{$sec} = $lc_sec;
7820: }
7821: }
7822: }
7823: }
7824: return;
7825: }
7826:
1.112 bowersj2 7827: =pod
7828:
1.780 raeburn 7829: =head1 Slot Helpers
7830:
7831: =over 4
7832:
7833: =item * sorted_slots()
7834:
7835: Sorts an array of slot names in order of slot start time (earliest first).
7836:
7837: Inputs:
7838:
7839: =over 4
7840:
7841: slotsarr - Reference to array of unsorted slot names.
7842:
7843: slots - Reference to hash of hash, where outer hash keys are slot names.
7844:
1.549 albertel 7845: =back
7846:
1.780 raeburn 7847: Returns:
7848:
7849: =over 4
7850:
7851: sorted - An array of slot names sorted by the start time of the slot.
7852:
7853: =back
7854:
7855: =back
7856:
7857: =cut
7858:
7859:
7860: sub sorted_slots {
7861: my ($slotsarr,$slots) = @_;
7862: my @sorted;
7863: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7864: @sorted =
7865: sort {
7866: if (ref($slots->{$a}) && ref($slots->{$b})) {
7867: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7868: }
7869: if (ref($slots->{$a})) { return -1;}
7870: if (ref($slots->{$b})) { return 1;}
7871: return 0;
7872: } @{$slotsarr};
7873: }
7874: return @sorted;
7875: }
7876:
7877:
7878: =pod
7879:
1.549 albertel 7880: =head1 HTTP Helpers
7881:
7882: =over 4
7883:
1.648 raeburn 7884: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7885:
1.258 albertel 7886: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7887: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7888: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7889:
7890: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7891: $possible_names is an ref to an array of form element names. As an example:
7892: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7893: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7894:
7895: =cut
1.1 albertel 7896:
1.6 albertel 7897: sub get_unprocessed_cgi {
1.25 albertel 7898: my ($query,$possible_names)= @_;
1.26 matthew 7899: # $Apache::lonxml::debug=1;
1.356 albertel 7900: foreach my $pair (split(/&/,$query)) {
7901: my ($name, $value) = split(/=/,$pair);
1.369 www 7902: $name = &unescape($name);
1.25 albertel 7903: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7904: $value =~ tr/+/ /;
7905: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7906: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7907: }
1.16 harris41 7908: }
1.6 albertel 7909: }
7910:
1.112 bowersj2 7911: =pod
7912:
1.648 raeburn 7913: =item * &cacheheader()
1.112 bowersj2 7914:
7915: returns cache-controlling header code
7916:
7917: =cut
7918:
1.7 albertel 7919: sub cacheheader {
1.258 albertel 7920: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7921: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7922: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7923: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7924: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7925: return $output;
1.7 albertel 7926: }
7927:
1.112 bowersj2 7928: =pod
7929:
1.648 raeburn 7930: =item * &no_cache($r)
1.112 bowersj2 7931:
7932: specifies header code to not have cache
7933:
7934: =cut
7935:
1.9 albertel 7936: sub no_cache {
1.216 albertel 7937: my ($r) = @_;
7938: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7939: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7940: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7941: $r->no_cache(1);
7942: $r->header_out("Expires" => $date);
7943: $r->header_out("Pragma" => "no-cache");
1.123 www 7944: }
7945:
7946: sub content_type {
1.181 albertel 7947: my ($r,$type,$charset) = @_;
1.299 foxr 7948: if ($r) {
7949: # Note that printout.pl calls this with undef for $r.
7950: &no_cache($r);
7951: }
1.258 albertel 7952: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7953: unless ($charset) {
7954: $charset=&Apache::lonlocal::current_encoding;
7955: }
7956: if ($charset) { $type.='; charset='.$charset; }
7957: if ($r) {
7958: $r->content_type($type);
7959: } else {
7960: print("Content-type: $type\n\n");
7961: }
1.9 albertel 7962: }
1.25 albertel 7963:
1.112 bowersj2 7964: =pod
7965:
1.648 raeburn 7966: =item * &add_to_env($name,$value)
1.112 bowersj2 7967:
1.258 albertel 7968: adds $name to the %env hash with value
1.112 bowersj2 7969: $value, if $name already exists, the entry is converted to an array
7970: reference and $value is added to the array.
7971:
7972: =cut
7973:
1.25 albertel 7974: sub add_to_env {
7975: my ($name,$value)=@_;
1.258 albertel 7976: if (defined($env{$name})) {
7977: if (ref($env{$name})) {
1.25 albertel 7978: #already have multiple values
1.258 albertel 7979: push(@{ $env{$name} },$value);
1.25 albertel 7980: } else {
7981: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7982: my $first=$env{$name};
7983: undef($env{$name});
7984: push(@{ $env{$name} },$first,$value);
1.25 albertel 7985: }
7986: } else {
1.258 albertel 7987: $env{$name}=$value;
1.25 albertel 7988: }
1.31 albertel 7989: }
1.149 albertel 7990:
7991: =pod
7992:
1.648 raeburn 7993: =item * &get_env_multiple($name)
1.149 albertel 7994:
1.258 albertel 7995: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7996: values may be defined and end up as an array ref.
7997:
7998: returns an array of values
7999:
8000: =cut
8001:
8002: sub get_env_multiple {
8003: my ($name) = @_;
8004: my @values;
1.258 albertel 8005: if (defined($env{$name})) {
1.149 albertel 8006: # exists is it an array
1.258 albertel 8007: if (ref($env{$name})) {
8008: @values=@{ $env{$name} };
1.149 albertel 8009: } else {
1.258 albertel 8010: $values[0]=$env{$name};
1.149 albertel 8011: }
8012: }
8013: return(@values);
8014: }
8015:
1.660 raeburn 8016: sub ask_for_embedded_content {
8017: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8018: my $upload_output = '
8019: <form name="upload_embedded" action="'.$actionurl.'"
8020: method="post" enctype="multipart/form-data">';
8021: $upload_output .= $state;
1.661 raeburn 8022: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8023:
8024: my $num = 0;
8025: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8026: $upload_output .= &start_data_table_row().
8027: '<td>'.$embed_file.'</td><td>';
8028: if ($args->{'ignore_remote_references'}
8029: && $embed_file =~ m{^\w+://}) {
8030: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8031: } elsif ($args->{'error_on_invalid_names'}
8032: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8033:
8034: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8035:
8036: } else {
8037: $upload_output .='
1.661 raeburn 8038: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8039: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8040: my $attrib = join(':',@{$$allfiles{$embed_file}});
8041: $upload_output .=
8042: "\n\t\t".
8043: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8044: $attrib.'" />';
8045: if (exists($$codebase{$embed_file})) {
8046: $upload_output .=
8047: "\n\t\t".
8048: '<input name="codebase_'.$num.'" type="hidden" value="'.
8049: &escape($$codebase{$embed_file}).'" />';
8050: }
8051: }
8052: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8053: $num++;
8054: }
8055: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8056: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8057: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8058: '.&mt('(only files for which a location has been provided will be uploaded)').'
8059: </form>';
8060: return $upload_output;
8061: }
8062:
1.661 raeburn 8063: sub upload_embedded {
8064: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8065: $current_disk_usage) = @_;
8066: my $output;
8067: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8068: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8069: my $orig_uploaded_filename =
8070: $env{'form.embedded_item_'.$i.'.filename'};
8071:
8072: $env{'form.embedded_orig_'.$i} =
8073: &unescape($env{'form.embedded_orig_'.$i});
8074: my ($path,$fname) =
8075: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8076: # no path, whole string is fname
8077: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8078:
8079: $path = $env{'form.currentpath'}.$path;
8080: $fname = &Apache::lonnet::clean_filename($fname);
8081: # See if there is anything left
8082: next if ($fname eq '');
8083:
8084: # Check if file already exists as a file or directory.
8085: my ($state,$msg);
8086: if ($context eq 'portfolio') {
8087: my $port_path = $dirpath;
8088: if ($group ne '') {
8089: $port_path = "groups/$group/$port_path";
8090: }
8091: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8092: $dir_root,$port_path,$disk_quota,
8093: $current_disk_usage,$uname,$udom);
8094: if ($state eq 'will_exceed_quota'
8095: || $state eq 'file_locked'
8096: || $state eq 'file_exists' ) {
8097: $output .= $msg;
8098: next;
8099: }
8100: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8101: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8102: if ($state eq 'exists') {
8103: $output .= $msg;
8104: next;
8105: }
8106: }
8107: # Check if extension is valid
8108: if (($fname =~ /\.(\w+)$/) &&
8109: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8110: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8111: next;
8112: } elsif (($fname =~ /\.(\w+)$/) &&
8113: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8114: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8115: next;
8116: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8117: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8118: next;
8119: }
8120:
8121: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8122: if ($context eq 'portfolio') {
8123: my $result=
8124: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8125: $dirpath.$path);
8126: if ($result !~ m|^/uploaded/|) {
8127: $output .= '<span class="LC_error">'
8128: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8129: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8130: .'</span><br />';
8131: next;
8132: } else {
8133: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8134: $path.$fname.'</span>').'</p>';
8135: }
8136: } else {
8137: # Save the file
8138: my $target = $env{'form.embedded_item_'.$i};
8139: my $fullpath = $dir_root.$dirpath.'/'.$path;
8140: my $dest = $fullpath.$fname;
8141: my $url = $url_root.$dirpath.'/'.$path.$fname;
8142: my @parts=split(/\//,$fullpath);
8143: my $count;
8144: my $filepath = $dir_root;
8145: for ($count=4;$count<=$#parts;$count++) {
8146: $filepath .= "/$parts[$count]";
8147: if ((-e $filepath)!=1) {
8148: mkdir($filepath,0770);
8149: }
8150: }
8151: my $fh;
8152: if (!open($fh,'>'.$dest)) {
8153: &Apache::lonnet::logthis('Failed to create '.$dest);
8154: $output .= '<span class="LC_error">'.
8155: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8156: '</span><br />';
8157: } else {
8158: if (!print $fh $env{'form.embedded_item_'.$i}) {
8159: &Apache::lonnet::logthis('Failed to write to '.$dest);
8160: $output .= '<span class="LC_error">'.
8161: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8162: '</span><br />';
8163: } else {
8164: if ($context eq 'testbank') {
8165: $output .= &mt('Embedded file uploaded successfully:').
8166: ' <a href="'.$url.'">'.
8167: $orig_uploaded_filename.'</a><br />';
8168: } else {
1.705 tempelho 8169: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8170: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8171: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8172: }
8173: }
8174: close($fh);
8175: }
8176: }
8177: }
8178: return $output;
8179: }
8180:
8181: sub check_for_existing {
8182: my ($path,$fname,$element) = @_;
8183: my ($state,$msg);
8184: if (-d $path.'/'.$fname) {
8185: $state = 'exists';
8186: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8187: } elsif (-e $path.'/'.$fname) {
8188: $state = 'exists';
8189: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8190: }
8191: if ($state eq 'exists') {
8192: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8193: }
8194: return ($state,$msg);
8195: }
8196:
8197: sub check_for_upload {
8198: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8199: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8200: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8201: my $getpropath = 1;
8202: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8203: $getpropath);
8204: my $found_file = 0;
8205: my $locked_file = 0;
8206: foreach my $line (@dir_list) {
8207: my ($file_name)=split(/\&/,$line,2);
8208: if ($file_name eq $fname){
8209: $file_name = $path.$file_name;
8210: if ($group ne '') {
8211: $file_name = $group.$file_name;
8212: }
8213: $found_file = 1;
8214: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8215: $locked_file = 1;
8216: }
8217: }
8218: }
8219: if (($current_disk_usage + $filesize) > $disk_quota){
8220: my $msg = '<span class="LC_error">'.
8221: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8222: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8223: return ('will_exceed_quota',$msg);
8224: } elsif ($found_file) {
8225: if ($locked_file) {
8226: my $msg = '<span class="LC_error">';
8227: $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>');
8228: $msg .= '</span><br />';
8229: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8230: return ('file_locked',$msg);
8231: } else {
8232: my $msg = '<span class="LC_error">';
8233: $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'});
8234: $msg .= '</span>';
8235: $msg .= '<br />';
8236: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8237: return ('file_exists',$msg);
8238: }
8239: }
8240: }
8241:
1.31 albertel 8242:
1.41 ng 8243: =pod
1.45 matthew 8244:
1.464 albertel 8245: =back
1.41 ng 8246:
1.112 bowersj2 8247: =head1 CSV Upload/Handling functions
1.38 albertel 8248:
1.41 ng 8249: =over 4
8250:
1.648 raeburn 8251: =item * &upfile_store($r)
1.41 ng 8252:
8253: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8254: needs $env{'form.upfile'}
1.41 ng 8255: returns $datatoken to be put into hidden field
8256:
8257: =cut
1.31 albertel 8258:
8259: sub upfile_store {
8260: my $r=shift;
1.258 albertel 8261: $env{'form.upfile'}=~s/\r/\n/gs;
8262: $env{'form.upfile'}=~s/\f/\n/gs;
8263: $env{'form.upfile'}=~s/\n+/\n/gs;
8264: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8265:
1.258 albertel 8266: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8267: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8268: {
1.158 raeburn 8269: my $datafile = $r->dir_config('lonDaemons').
8270: '/tmp/'.$datatoken.'.tmp';
8271: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8272: print $fh $env{'form.upfile'};
1.158 raeburn 8273: close($fh);
8274: }
1.31 albertel 8275: }
8276: return $datatoken;
8277: }
8278:
1.56 matthew 8279: =pod
8280:
1.648 raeburn 8281: =item * &load_tmp_file($r)
1.41 ng 8282:
8283: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8284: needs $env{'form.datatoken'},
8285: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8286:
8287: =cut
1.31 albertel 8288:
8289: sub load_tmp_file {
8290: my $r=shift;
8291: my @studentdata=();
8292: {
1.158 raeburn 8293: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8294: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8295: if ( open(my $fh,"<$studentfile") ) {
8296: @studentdata=<$fh>;
8297: close($fh);
8298: }
1.31 albertel 8299: }
1.258 albertel 8300: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8301: }
8302:
1.56 matthew 8303: =pod
8304:
1.648 raeburn 8305: =item * &upfile_record_sep()
1.41 ng 8306:
8307: Separate uploaded file into records
8308: returns array of records,
1.258 albertel 8309: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8310:
8311: =cut
1.31 albertel 8312:
8313: sub upfile_record_sep {
1.258 albertel 8314: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8315: } else {
1.248 albertel 8316: my @records;
1.258 albertel 8317: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8318: if ($line=~/^\s*$/) { next; }
8319: push(@records,$line);
8320: }
8321: return @records;
1.31 albertel 8322: }
8323: }
8324:
1.56 matthew 8325: =pod
8326:
1.648 raeburn 8327: =item * &record_sep($record)
1.41 ng 8328:
1.258 albertel 8329: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8330:
8331: =cut
8332:
1.263 www 8333: sub takeleft {
8334: my $index=shift;
8335: return substr('0000'.$index,-4,4);
8336: }
8337:
1.31 albertel 8338: sub record_sep {
8339: my $record=shift;
8340: my %components=();
1.258 albertel 8341: if ($env{'form.upfiletype'} eq 'xml') {
8342: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8343: my $i=0;
1.356 albertel 8344: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8345: $field=~s/^(\"|\')//;
8346: $field=~s/(\"|\')$//;
1.263 www 8347: $components{&takeleft($i)}=$field;
1.31 albertel 8348: $i++;
8349: }
1.258 albertel 8350: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8351: my $i=0;
1.356 albertel 8352: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8353: $field=~s/^(\"|\')//;
8354: $field=~s/(\"|\')$//;
1.263 www 8355: $components{&takeleft($i)}=$field;
1.31 albertel 8356: $i++;
8357: }
8358: } else {
1.561 www 8359: my $separator=',';
1.480 banghart 8360: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8361: $separator=';';
1.480 banghart 8362: }
1.31 albertel 8363: my $i=0;
1.561 www 8364: # the character we are looking for to indicate the end of a quote or a record
8365: my $looking_for=$separator;
8366: # do not add the characters to the fields
8367: my $ignore=0;
8368: # we just encountered a separator (or the beginning of the record)
8369: my $just_found_separator=1;
8370: # store the field we are working on here
8371: my $field='';
8372: # work our way through all characters in record
8373: foreach my $character ($record=~/(.)/g) {
8374: if ($character eq $looking_for) {
8375: if ($character ne $separator) {
8376: # Found the end of a quote, again looking for separator
8377: $looking_for=$separator;
8378: $ignore=1;
8379: } else {
8380: # Found a separator, store away what we got
8381: $components{&takeleft($i)}=$field;
8382: $i++;
8383: $just_found_separator=1;
8384: $ignore=0;
8385: $field='';
8386: }
8387: next;
8388: }
8389: # single or double quotation marks after a separator indicate beginning of a quote
8390: # we are now looking for the end of the quote and need to ignore separators
8391: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8392: $looking_for=$character;
8393: next;
8394: }
8395: # ignore would be true after we reached the end of a quote
8396: if ($ignore) { next; }
8397: if (($just_found_separator) && ($character=~/\s/)) { next; }
8398: $field.=$character;
8399: $just_found_separator=0;
1.31 albertel 8400: }
1.561 www 8401: # catch the very last entry, since we never encountered the separator
8402: $components{&takeleft($i)}=$field;
1.31 albertel 8403: }
8404: return %components;
8405: }
8406:
1.144 matthew 8407: ######################################################
8408: ######################################################
8409:
1.56 matthew 8410: =pod
8411:
1.648 raeburn 8412: =item * &upfile_select_html()
1.41 ng 8413:
1.144 matthew 8414: Return HTML code to select a file from the users machine and specify
8415: the file type.
1.41 ng 8416:
8417: =cut
8418:
1.144 matthew 8419: ######################################################
8420: ######################################################
1.31 albertel 8421: sub upfile_select_html {
1.144 matthew 8422: my %Types = (
8423: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8424: semisv => &mt('Semicolon separated values'),
1.144 matthew 8425: space => &mt('Space separated'),
8426: tab => &mt('Tabulator separated'),
8427: # xml => &mt('HTML/XML'),
8428: );
8429: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8430: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8431: foreach my $type (sort(keys(%Types))) {
8432: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8433: }
8434: $Str .= "</select>\n";
8435: return $Str;
1.31 albertel 8436: }
8437:
1.301 albertel 8438: sub get_samples {
8439: my ($records,$toget) = @_;
8440: my @samples=({});
8441: my $got=0;
8442: foreach my $rec (@$records) {
8443: my %temp = &record_sep($rec);
8444: if (! grep(/\S/, values(%temp))) { next; }
8445: if (%temp) {
8446: $samples[$got]=\%temp;
8447: $got++;
8448: if ($got == $toget) { last; }
8449: }
8450: }
8451: return \@samples;
8452: }
8453:
1.144 matthew 8454: ######################################################
8455: ######################################################
8456:
1.56 matthew 8457: =pod
8458:
1.648 raeburn 8459: =item * &csv_print_samples($r,$records)
1.41 ng 8460:
8461: Prints a table of sample values from each column uploaded $r is an
8462: Apache Request ref, $records is an arrayref from
8463: &Apache::loncommon::upfile_record_sep
8464:
8465: =cut
8466:
1.144 matthew 8467: ######################################################
8468: ######################################################
1.31 albertel 8469: sub csv_print_samples {
8470: my ($r,$records) = @_;
1.662 bisitz 8471: my $samples = &get_samples($records,5);
1.301 albertel 8472:
1.594 raeburn 8473: $r->print(&mt('Samples').'<br />'.&start_data_table().
8474: &start_data_table_header_row());
1.356 albertel 8475: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8476: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8477: $r->print(&end_data_table_header_row());
1.301 albertel 8478: foreach my $hash (@$samples) {
1.594 raeburn 8479: $r->print(&start_data_table_row());
1.356 albertel 8480: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8481: $r->print('<td>');
1.356 albertel 8482: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8483: $r->print('</td>');
8484: }
1.594 raeburn 8485: $r->print(&end_data_table_row());
1.31 albertel 8486: }
1.594 raeburn 8487: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8488: }
8489:
1.144 matthew 8490: ######################################################
8491: ######################################################
8492:
1.56 matthew 8493: =pod
8494:
1.648 raeburn 8495: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8496:
8497: Prints a table to create associations between values and table columns.
1.144 matthew 8498:
1.41 ng 8499: $r is an Apache Request ref,
8500: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8501: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8502:
8503: =cut
8504:
1.144 matthew 8505: ######################################################
8506: ######################################################
1.31 albertel 8507: sub csv_print_select_table {
8508: my ($r,$records,$d) = @_;
1.301 albertel 8509: my $i=0;
8510: my $samples = &get_samples($records,1);
1.144 matthew 8511: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8512: &start_data_table().&start_data_table_header_row().
1.144 matthew 8513: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8514: '<th>'.&mt('Column').'</th>'.
8515: &end_data_table_header_row()."\n");
1.356 albertel 8516: foreach my $array_ref (@$d) {
8517: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8518: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8519:
8520: $r->print('<td><select name=f'.$i.
1.32 matthew 8521: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8522: $r->print('<option value="none"></option>');
1.356 albertel 8523: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8524: $r->print('<option value="'.$sample.'"'.
8525: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8526: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8527: }
1.594 raeburn 8528: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8529: $i++;
8530: }
1.594 raeburn 8531: $r->print(&end_data_table());
1.31 albertel 8532: $i--;
8533: return $i;
8534: }
1.56 matthew 8535:
1.144 matthew 8536: ######################################################
8537: ######################################################
8538:
1.56 matthew 8539: =pod
1.31 albertel 8540:
1.648 raeburn 8541: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8542:
8543: Prints a table of sample values from the upload and can make associate samples to internal names.
8544:
8545: $r is an Apache Request ref,
8546: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8547: $d is an array of 2 element arrays (internal name, displayed name)
8548:
8549: =cut
8550:
1.144 matthew 8551: ######################################################
8552: ######################################################
1.31 albertel 8553: sub csv_samples_select_table {
8554: my ($r,$records,$d) = @_;
8555: my $i=0;
1.144 matthew 8556: #
1.662 bisitz 8557: my $max_samples = 5;
8558: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8559: $r->print(&start_data_table().
8560: &start_data_table_header_row().'<th>'.
8561: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8562: &end_data_table_header_row());
1.301 albertel 8563:
8564: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8565: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8566: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8567: foreach my $option (@$d) {
8568: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8569: $r->print('<option value="'.$value.'"'.
1.253 albertel 8570: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8571: $display.'</option>');
1.31 albertel 8572: }
8573: $r->print('</select></td><td>');
1.662 bisitz 8574: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8575: if (defined($samples->[$line]{$key})) {
8576: $r->print($samples->[$line]{$key}."<br />\n");
8577: }
8578: }
1.594 raeburn 8579: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8580: $i++;
8581: }
1.594 raeburn 8582: $r->print(&end_data_table());
1.31 albertel 8583: $i--;
8584: return($i);
1.115 matthew 8585: }
8586:
1.144 matthew 8587: ######################################################
8588: ######################################################
8589:
1.115 matthew 8590: =pod
8591:
1.648 raeburn 8592: =item * &clean_excel_name($name)
1.115 matthew 8593:
8594: Returns a replacement for $name which does not contain any illegal characters.
8595:
8596: =cut
8597:
1.144 matthew 8598: ######################################################
8599: ######################################################
1.115 matthew 8600: sub clean_excel_name {
8601: my ($name) = @_;
8602: $name =~ s/[:\*\?\/\\]//g;
8603: if (length($name) > 31) {
8604: $name = substr($name,0,31);
8605: }
8606: return $name;
1.25 albertel 8607: }
1.84 albertel 8608:
1.85 albertel 8609: =pod
8610:
1.648 raeburn 8611: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8612:
8613: Returns either 1 or undef
8614:
8615: 1 if the part is to be hidden, undef if it is to be shown
8616:
8617: Arguments are:
8618:
8619: $id the id of the part to be checked
8620: $symb, optional the symb of the resource to check
8621: $udom, optional the domain of the user to check for
8622: $uname, optional the username of the user to check for
8623:
8624: =cut
1.84 albertel 8625:
8626: sub check_if_partid_hidden {
8627: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8628: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8629: $symb,$udom,$uname);
1.141 albertel 8630: my $truth=1;
8631: #if the string starts with !, then the list is the list to show not hide
8632: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8633: my @hiddenlist=split(/,/,$hiddenparts);
8634: foreach my $checkid (@hiddenlist) {
1.141 albertel 8635: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8636: }
1.141 albertel 8637: return !$truth;
1.84 albertel 8638: }
1.127 matthew 8639:
1.138 matthew 8640:
8641: ############################################################
8642: ############################################################
8643:
8644: =pod
8645:
1.157 matthew 8646: =back
8647:
1.138 matthew 8648: =head1 cgi-bin script and graphing routines
8649:
1.157 matthew 8650: =over 4
8651:
1.648 raeburn 8652: =item * &get_cgi_id()
1.138 matthew 8653:
8654: Inputs: none
8655:
8656: Returns an id which can be used to pass environment variables
8657: to various cgi-bin scripts. These environment variables will
8658: be removed from the users environment after a given time by
8659: the routine &Apache::lonnet::transfer_profile_to_env.
8660:
8661: =cut
8662:
8663: ############################################################
8664: ############################################################
1.152 albertel 8665: my $uniq=0;
1.136 matthew 8666: sub get_cgi_id {
1.154 albertel 8667: $uniq=($uniq+1)%100000;
1.280 albertel 8668: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8669: }
8670:
1.127 matthew 8671: ############################################################
8672: ############################################################
8673:
8674: =pod
8675:
1.648 raeburn 8676: =item * &DrawBarGraph()
1.127 matthew 8677:
1.138 matthew 8678: Facilitates the plotting of data in a (stacked) bar graph.
8679: Puts plot definition data into the users environment in order for
8680: graph.png to plot it. Returns an <img> tag for the plot.
8681: The bars on the plot are labeled '1','2',...,'n'.
8682:
8683: Inputs:
8684:
8685: =over 4
8686:
8687: =item $Title: string, the title of the plot
8688:
8689: =item $xlabel: string, text describing the X-axis of the plot
8690:
8691: =item $ylabel: string, text describing the Y-axis of the plot
8692:
8693: =item $Max: scalar, the maximum Y value to use in the plot
8694: If $Max is < any data point, the graph will not be rendered.
8695:
1.140 matthew 8696: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8697: they are plotted. If undefined, default values will be used.
8698:
1.178 matthew 8699: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8700:
1.138 matthew 8701: =item @Values: An array of array references. Each array reference holds data
8702: to be plotted in a stacked bar chart.
8703:
1.239 matthew 8704: =item If the final element of @Values is a hash reference the key/value
8705: pairs will be added to the graph definition.
8706:
1.138 matthew 8707: =back
8708:
8709: Returns:
8710:
8711: An <img> tag which references graph.png and the appropriate identifying
8712: information for the plot.
8713:
1.127 matthew 8714: =cut
8715:
8716: ############################################################
8717: ############################################################
1.134 matthew 8718: sub DrawBarGraph {
1.178 matthew 8719: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8720: #
8721: if (! defined($colors)) {
8722: $colors = ['#33ff00',
8723: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8724: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8725: ];
8726: }
1.228 matthew 8727: my $extra_settings = {};
8728: if (ref($Values[-1]) eq 'HASH') {
8729: $extra_settings = pop(@Values);
8730: }
1.127 matthew 8731: #
1.136 matthew 8732: my $identifier = &get_cgi_id();
8733: my $id = 'cgi.'.$identifier;
1.129 matthew 8734: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8735: return '';
8736: }
1.225 matthew 8737: #
8738: my @Labels;
8739: if (defined($labels)) {
8740: @Labels = @$labels;
8741: } else {
8742: for (my $i=0;$i<@{$Values[0]};$i++) {
8743: push (@Labels,$i+1);
8744: }
8745: }
8746: #
1.129 matthew 8747: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8748: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8749: my %ValuesHash;
8750: my $NumSets=1;
8751: foreach my $array (@Values) {
8752: next if (! ref($array));
1.136 matthew 8753: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8754: join(',',@$array);
1.129 matthew 8755: }
1.127 matthew 8756: #
1.136 matthew 8757: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8758: if ($NumBars < 3) {
8759: $width = 120+$NumBars*32;
1.220 matthew 8760: $xskip = 1;
1.225 matthew 8761: $bar_width = 30;
8762: } elsif ($NumBars < 5) {
8763: $width = 120+$NumBars*20;
8764: $xskip = 1;
8765: $bar_width = 20;
1.220 matthew 8766: } elsif ($NumBars < 10) {
1.136 matthew 8767: $width = 120+$NumBars*15;
8768: $xskip = 1;
8769: $bar_width = 15;
8770: } elsif ($NumBars <= 25) {
8771: $width = 120+$NumBars*11;
8772: $xskip = 5;
8773: $bar_width = 8;
8774: } elsif ($NumBars <= 50) {
8775: $width = 120+$NumBars*8;
8776: $xskip = 5;
8777: $bar_width = 4;
8778: } else {
8779: $width = 120+$NumBars*8;
8780: $xskip = 5;
8781: $bar_width = 4;
8782: }
8783: #
1.137 matthew 8784: $Max = 1 if ($Max < 1);
8785: if ( int($Max) < $Max ) {
8786: $Max++;
8787: $Max = int($Max);
8788: }
1.127 matthew 8789: $Title = '' if (! defined($Title));
8790: $xlabel = '' if (! defined($xlabel));
8791: $ylabel = '' if (! defined($ylabel));
1.369 www 8792: $ValuesHash{$id.'.title'} = &escape($Title);
8793: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8794: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8795: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8796: $ValuesHash{$id.'.NumBars'} = $NumBars;
8797: $ValuesHash{$id.'.NumSets'} = $NumSets;
8798: $ValuesHash{$id.'.PlotType'} = 'bar';
8799: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8800: $ValuesHash{$id.'.height'} = $height;
8801: $ValuesHash{$id.'.width'} = $width;
8802: $ValuesHash{$id.'.xskip'} = $xskip;
8803: $ValuesHash{$id.'.bar_width'} = $bar_width;
8804: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8805: #
1.228 matthew 8806: # Deal with other parameters
8807: while (my ($key,$value) = each(%$extra_settings)) {
8808: $ValuesHash{$id.'.'.$key} = $value;
8809: }
8810: #
1.646 raeburn 8811: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8812: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8813: }
8814:
8815: ############################################################
8816: ############################################################
8817:
8818: =pod
8819:
1.648 raeburn 8820: =item * &DrawXYGraph()
1.137 matthew 8821:
1.138 matthew 8822: Facilitates the plotting of data in an XY graph.
8823: Puts plot definition data into the users environment in order for
8824: graph.png to plot it. Returns an <img> tag for the plot.
8825:
8826: Inputs:
8827:
8828: =over 4
8829:
8830: =item $Title: string, the title of the plot
8831:
8832: =item $xlabel: string, text describing the X-axis of the plot
8833:
8834: =item $ylabel: string, text describing the Y-axis of the plot
8835:
8836: =item $Max: scalar, the maximum Y value to use in the plot
8837: If $Max is < any data point, the graph will not be rendered.
8838:
8839: =item $colors: Array ref containing the hex color codes for the data to be
8840: plotted in. If undefined, default values will be used.
8841:
8842: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8843:
8844: =item $Ydata: Array ref containing Array refs.
1.185 www 8845: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8846:
8847: =item %Values: hash indicating or overriding any default values which are
8848: passed to graph.png.
8849: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8850:
8851: =back
8852:
8853: Returns:
8854:
8855: An <img> tag which references graph.png and the appropriate identifying
8856: information for the plot.
8857:
1.137 matthew 8858: =cut
8859:
8860: ############################################################
8861: ############################################################
8862: sub DrawXYGraph {
8863: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8864: #
8865: # Create the identifier for the graph
8866: my $identifier = &get_cgi_id();
8867: my $id = 'cgi.'.$identifier;
8868: #
8869: $Title = '' if (! defined($Title));
8870: $xlabel = '' if (! defined($xlabel));
8871: $ylabel = '' if (! defined($ylabel));
8872: my %ValuesHash =
8873: (
1.369 www 8874: $id.'.title' => &escape($Title),
8875: $id.'.xlabel' => &escape($xlabel),
8876: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8877: $id.'.y_max_value'=> $Max,
8878: $id.'.labels' => join(',',@$Xlabels),
8879: $id.'.PlotType' => 'XY',
8880: );
8881: #
8882: if (defined($colors) && ref($colors) eq 'ARRAY') {
8883: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8884: }
8885: #
8886: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8887: return '';
8888: }
8889: my $NumSets=1;
1.138 matthew 8890: foreach my $array (@{$Ydata}){
1.137 matthew 8891: next if (! ref($array));
8892: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8893: }
1.138 matthew 8894: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8895: #
8896: # Deal with other parameters
8897: while (my ($key,$value) = each(%Values)) {
8898: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8899: }
8900: #
1.646 raeburn 8901: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8902: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8903: }
8904:
8905: ############################################################
8906: ############################################################
8907:
8908: =pod
8909:
1.648 raeburn 8910: =item * &DrawXYYGraph()
1.138 matthew 8911:
8912: Facilitates the plotting of data in an XY graph with two Y axes.
8913: Puts plot definition data into the users environment in order for
8914: graph.png to plot it. Returns an <img> tag for the plot.
8915:
8916: Inputs:
8917:
8918: =over 4
8919:
8920: =item $Title: string, the title of the plot
8921:
8922: =item $xlabel: string, text describing the X-axis of the plot
8923:
8924: =item $ylabel: string, text describing the Y-axis of the plot
8925:
8926: =item $colors: Array ref containing the hex color codes for the data to be
8927: plotted in. If undefined, default values will be used.
8928:
8929: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8930:
8931: =item $Ydata1: The first data set
8932:
8933: =item $Min1: The minimum value of the left Y-axis
8934:
8935: =item $Max1: The maximum value of the left Y-axis
8936:
8937: =item $Ydata2: The second data set
8938:
8939: =item $Min2: The minimum value of the right Y-axis
8940:
8941: =item $Max2: The maximum value of the left Y-axis
8942:
8943: =item %Values: hash indicating or overriding any default values which are
8944: passed to graph.png.
8945: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8946:
8947: =back
8948:
8949: Returns:
8950:
8951: An <img> tag which references graph.png and the appropriate identifying
8952: information for the plot.
1.136 matthew 8953:
8954: =cut
8955:
8956: ############################################################
8957: ############################################################
1.137 matthew 8958: sub DrawXYYGraph {
8959: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8960: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8961: #
8962: # Create the identifier for the graph
8963: my $identifier = &get_cgi_id();
8964: my $id = 'cgi.'.$identifier;
8965: #
8966: $Title = '' if (! defined($Title));
8967: $xlabel = '' if (! defined($xlabel));
8968: $ylabel = '' if (! defined($ylabel));
8969: my %ValuesHash =
8970: (
1.369 www 8971: $id.'.title' => &escape($Title),
8972: $id.'.xlabel' => &escape($xlabel),
8973: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8974: $id.'.labels' => join(',',@$Xlabels),
8975: $id.'.PlotType' => 'XY',
8976: $id.'.NumSets' => 2,
1.137 matthew 8977: $id.'.two_axes' => 1,
8978: $id.'.y1_max_value' => $Max1,
8979: $id.'.y1_min_value' => $Min1,
8980: $id.'.y2_max_value' => $Max2,
8981: $id.'.y2_min_value' => $Min2,
1.136 matthew 8982: );
8983: #
1.137 matthew 8984: if (defined($colors) && ref($colors) eq 'ARRAY') {
8985: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8986: }
8987: #
8988: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8989: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8990: return '';
8991: }
8992: my $NumSets=1;
1.137 matthew 8993: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8994: next if (! ref($array));
8995: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8996: }
8997: #
8998: # Deal with other parameters
8999: while (my ($key,$value) = each(%Values)) {
9000: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9001: }
9002: #
1.646 raeburn 9003: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9004: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9005: }
9006:
9007: ############################################################
9008: ############################################################
9009:
9010: =pod
9011:
1.157 matthew 9012: =back
9013:
1.139 matthew 9014: =head1 Statistics helper routines?
9015:
9016: Bad place for them but what the hell.
9017:
1.157 matthew 9018: =over 4
9019:
1.648 raeburn 9020: =item * &chartlink()
1.139 matthew 9021:
9022: Returns a link to the chart for a specific student.
9023:
9024: Inputs:
9025:
9026: =over 4
9027:
9028: =item $linktext: The text of the link
9029:
9030: =item $sname: The students username
9031:
9032: =item $sdomain: The students domain
9033:
9034: =back
9035:
1.157 matthew 9036: =back
9037:
1.139 matthew 9038: =cut
9039:
9040: ############################################################
9041: ############################################################
9042: sub chartlink {
9043: my ($linktext, $sname, $sdomain) = @_;
9044: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9045: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9046: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9047: '">'.$linktext.'</a>';
1.153 matthew 9048: }
9049:
9050: #######################################################
9051: #######################################################
9052:
9053: =pod
9054:
9055: =head1 Course Environment Routines
1.157 matthew 9056:
9057: =over 4
1.153 matthew 9058:
1.648 raeburn 9059: =item * &restore_course_settings()
1.153 matthew 9060:
1.648 raeburn 9061: =item * &store_course_settings()
1.153 matthew 9062:
9063: Restores/Store indicated form parameters from the course environment.
9064: Will not overwrite existing values of the form parameters.
9065:
9066: Inputs:
9067: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9068:
9069: a hash ref describing the data to be stored. For example:
9070:
9071: %Save_Parameters = ('Status' => 'scalar',
9072: 'chartoutputmode' => 'scalar',
9073: 'chartoutputdata' => 'scalar',
9074: 'Section' => 'array',
1.373 raeburn 9075: 'Group' => 'array',
1.153 matthew 9076: 'StudentData' => 'array',
9077: 'Maps' => 'array');
9078:
9079: Returns: both routines return nothing
9080:
1.631 raeburn 9081: =back
9082:
1.153 matthew 9083: =cut
9084:
9085: #######################################################
9086: #######################################################
9087: sub store_course_settings {
1.496 albertel 9088: return &store_settings($env{'request.course.id'},@_);
9089: }
9090:
9091: sub store_settings {
1.153 matthew 9092: # save to the environment
9093: # appenv the same items, just to be safe
1.300 albertel 9094: my $udom = $env{'user.domain'};
9095: my $uname = $env{'user.name'};
1.496 albertel 9096: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9097: my %SaveHash;
9098: my %AppHash;
9099: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9100: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9101: my $envname = 'environment.'.$basename;
1.258 albertel 9102: if (exists($env{'form.'.$setting})) {
1.153 matthew 9103: # Save this value away
9104: if ($type eq 'scalar' &&
1.258 albertel 9105: (! exists($env{$envname}) ||
9106: $env{$envname} ne $env{'form.'.$setting})) {
9107: $SaveHash{$basename} = $env{'form.'.$setting};
9108: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9109: } elsif ($type eq 'array') {
9110: my $stored_form;
1.258 albertel 9111: if (ref($env{'form.'.$setting})) {
1.153 matthew 9112: $stored_form = join(',',
9113: map {
1.369 www 9114: &escape($_);
1.258 albertel 9115: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9116: } else {
9117: $stored_form =
1.369 www 9118: &escape($env{'form.'.$setting});
1.153 matthew 9119: }
9120: # Determine if the array contents are the same.
1.258 albertel 9121: if ($stored_form ne $env{$envname}) {
1.153 matthew 9122: $SaveHash{$basename} = $stored_form;
9123: $AppHash{$envname} = $stored_form;
9124: }
9125: }
9126: }
9127: }
9128: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9129: $udom,$uname);
1.153 matthew 9130: if ($put_result !~ /^(ok|delayed)/) {
9131: &Apache::lonnet::logthis('unable to save form parameters, '.
9132: 'got error:'.$put_result);
9133: }
9134: # Make sure these settings stick around in this session, too
1.646 raeburn 9135: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9136: return;
9137: }
9138:
9139: sub restore_course_settings {
1.499 albertel 9140: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9141: }
9142:
9143: sub restore_settings {
9144: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9145: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9146: next if (exists($env{'form.'.$setting}));
1.496 albertel 9147: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9148: '.'.$setting;
1.258 albertel 9149: if (exists($env{$envname})) {
1.153 matthew 9150: if ($type eq 'scalar') {
1.258 albertel 9151: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9152: } elsif ($type eq 'array') {
1.258 albertel 9153: $env{'form.'.$setting} = [
1.153 matthew 9154: map {
1.369 www 9155: &unescape($_);
1.258 albertel 9156: } split(',',$env{$envname})
1.153 matthew 9157: ];
9158: }
9159: }
9160: }
1.127 matthew 9161: }
9162:
1.618 raeburn 9163: #######################################################
9164: #######################################################
9165:
9166: =pod
9167:
9168: =head1 Domain E-mail Routines
9169:
9170: =over 4
9171:
1.648 raeburn 9172: =item * &build_recipient_list()
1.618 raeburn 9173:
1.766 raeburn 9174: Build recipient lists for four types of e-mail:
9175: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9176: (d) Help requests, generated by
9177: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9178:
9179: Inputs:
1.619 raeburn 9180: defmail (scalar - email address of default recipient),
1.618 raeburn 9181: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9182: defdom (domain for which to retrieve configuration settings),
9183: origmail (scalar - email address of recipient from loncapa.conf,
9184: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9185:
1.655 raeburn 9186: Returns: comma separated list of addresses to which to send e-mail.
9187:
9188: =back
1.618 raeburn 9189:
9190: =cut
9191:
9192: ############################################################
9193: ############################################################
9194: sub build_recipient_list {
1.619 raeburn 9195: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9196: my @recipients;
9197: my $otheremails;
9198: my %domconfig =
9199: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9200: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9201: if (exists($domconfig{'contacts'}{$mailing})) {
9202: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9203: my @contacts = ('adminemail','supportemail');
9204: foreach my $item (@contacts) {
9205: if ($domconfig{'contacts'}{$mailing}{$item}) {
9206: my $addr = $domconfig{'contacts'}{$item};
9207: if (!grep(/^\Q$addr\E$/,@recipients)) {
9208: push(@recipients,$addr);
9209: }
1.619 raeburn 9210: }
1.766 raeburn 9211: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9212: }
9213: }
1.766 raeburn 9214: } elsif ($origmail ne '') {
9215: push(@recipients,$origmail);
1.618 raeburn 9216: }
1.619 raeburn 9217: } elsif ($origmail ne '') {
9218: push(@recipients,$origmail);
1.618 raeburn 9219: }
1.688 raeburn 9220: if (defined($defmail)) {
9221: if ($defmail ne '') {
9222: push(@recipients,$defmail);
9223: }
1.618 raeburn 9224: }
9225: if ($otheremails) {
1.619 raeburn 9226: my @others;
9227: if ($otheremails =~ /,/) {
9228: @others = split(/,/,$otheremails);
1.618 raeburn 9229: } else {
1.619 raeburn 9230: push(@others,$otheremails);
9231: }
9232: foreach my $addr (@others) {
9233: if (!grep(/^\Q$addr\E$/,@recipients)) {
9234: push(@recipients,$addr);
9235: }
1.618 raeburn 9236: }
9237: }
1.619 raeburn 9238: my $recipientlist = join(',',@recipients);
1.618 raeburn 9239: return $recipientlist;
9240: }
9241:
1.127 matthew 9242: ############################################################
9243: ############################################################
1.154 albertel 9244:
1.655 raeburn 9245: =pod
9246:
9247: =head1 Course Catalog Routines
9248:
9249: =over 4
9250:
9251: =item * &gather_categories()
9252:
9253: Converts category definitions - keys of categories hash stored in
9254: coursecategories in configuration.db on the primary library server in a
9255: domain - to an array. Also generates javascript and idx hash used to
9256: generate Domain Coordinator interface for editing Course Categories.
9257:
9258: Inputs:
1.663 raeburn 9259:
1.655 raeburn 9260: categories (reference to hash of category definitions).
1.663 raeburn 9261:
1.655 raeburn 9262: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9263: categories and subcategories).
1.663 raeburn 9264:
1.655 raeburn 9265: idx (reference to hash of counters used in Domain Coordinator interface for
9266: editing Course Categories).
1.663 raeburn 9267:
1.655 raeburn 9268: jsarray (reference to array of categories used to create Javascript arrays for
9269: Domain Coordinator interface for editing Course Categories).
9270:
9271: Returns: nothing
9272:
9273: Side effects: populates cats, idx and jsarray.
9274:
9275: =cut
9276:
9277: sub gather_categories {
9278: my ($categories,$cats,$idx,$jsarray) = @_;
9279: my %counters;
9280: my $num = 0;
9281: foreach my $item (keys(%{$categories})) {
9282: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9283: if ($container eq '' && $depth == 0) {
9284: $cats->[$depth][$categories->{$item}] = $cat;
9285: } else {
9286: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9287: }
9288: my ($escitem,$tail) = split(/:/,$item,2);
9289: if ($counters{$tail} eq '') {
9290: $counters{$tail} = $num;
9291: $num ++;
9292: }
9293: if (ref($idx) eq 'HASH') {
9294: $idx->{$item} = $counters{$tail};
9295: }
9296: if (ref($jsarray) eq 'ARRAY') {
9297: push(@{$jsarray->[$counters{$tail}]},$item);
9298: }
9299: }
9300: return;
9301: }
9302:
9303: =pod
9304:
9305: =item * &extract_categories()
9306:
9307: Used to generate breadcrumb trails for course categories.
9308:
9309: Inputs:
1.663 raeburn 9310:
1.655 raeburn 9311: categories (reference to hash of category definitions).
1.663 raeburn 9312:
1.655 raeburn 9313: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9314: categories and subcategories).
1.663 raeburn 9315:
1.655 raeburn 9316: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9317:
1.655 raeburn 9318: allitems (reference to hash - key is category key
9319: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9320:
1.655 raeburn 9321: idx (reference to hash of counters used in Domain Coordinator interface for
9322: editing Course Categories).
1.663 raeburn 9323:
1.655 raeburn 9324: jsarray (reference to array of categories used to create Javascript arrays for
9325: Domain Coordinator interface for editing Course Categories).
9326:
1.665 raeburn 9327: subcats (reference to hash of arrays containing all subcategories within each
9328: category, -recursive)
9329:
1.655 raeburn 9330: Returns: nothing
9331:
9332: Side effects: populates trails and allitems hash references.
9333:
9334: =cut
9335:
9336: sub extract_categories {
1.665 raeburn 9337: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9338: if (ref($categories) eq 'HASH') {
9339: &gather_categories($categories,$cats,$idx,$jsarray);
9340: if (ref($cats->[0]) eq 'ARRAY') {
9341: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9342: my $name = $cats->[0][$i];
9343: my $item = &escape($name).'::0';
9344: my $trailstr;
9345: if ($name eq 'instcode') {
9346: $trailstr = &mt('Official courses (with institutional codes)');
9347: } else {
9348: $trailstr = $name;
9349: }
9350: if ($allitems->{$item} eq '') {
9351: push(@{$trails},$trailstr);
9352: $allitems->{$item} = scalar(@{$trails})-1;
9353: }
9354: my @parents = ($name);
9355: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9356: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9357: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9358: if (ref($subcats) eq 'HASH') {
9359: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9360: }
9361: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9362: }
9363: } else {
9364: if (ref($subcats) eq 'HASH') {
9365: $subcats->{$item} = [];
1.655 raeburn 9366: }
9367: }
9368: }
9369: }
9370: }
9371: return;
9372: }
9373:
9374: =pod
9375:
9376: =item *&recurse_categories()
9377:
9378: Recursively used to generate breadcrumb trails for course categories.
9379:
9380: Inputs:
1.663 raeburn 9381:
1.655 raeburn 9382: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9383: categories and subcategories).
1.663 raeburn 9384:
1.655 raeburn 9385: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9386:
9387: category (current course category, for which breadcrumb trail is being generated).
9388:
9389: trails (reference to array of breadcrumb trails for each category).
9390:
1.655 raeburn 9391: allitems (reference to hash - key is category key
9392: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9393:
1.655 raeburn 9394: parents (array containing containers directories for current category,
9395: back to top level).
9396:
9397: Returns: nothing
9398:
9399: Side effects: populates trails and allitems hash references
9400:
9401: =cut
9402:
9403: sub recurse_categories {
1.665 raeburn 9404: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9405: my $shallower = $depth - 1;
9406: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9407: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9408: my $name = $cats->[$depth]{$category}[$k];
9409: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9410: my $trailstr = join(' -> ',(@{$parents},$category));
9411: if ($allitems->{$item} eq '') {
9412: push(@{$trails},$trailstr);
9413: $allitems->{$item} = scalar(@{$trails})-1;
9414: }
9415: my $deeper = $depth+1;
9416: push(@{$parents},$category);
1.665 raeburn 9417: if (ref($subcats) eq 'HASH') {
9418: my $subcat = &escape($name).':'.$category.':'.$depth;
9419: for (my $j=@{$parents}; $j>=0; $j--) {
9420: my $higher;
9421: if ($j > 0) {
9422: $higher = &escape($parents->[$j]).':'.
9423: &escape($parents->[$j-1]).':'.$j;
9424: } else {
9425: $higher = &escape($parents->[$j]).'::'.$j;
9426: }
9427: push(@{$subcats->{$higher}},$subcat);
9428: }
9429: }
9430: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9431: $subcats);
1.655 raeburn 9432: pop(@{$parents});
9433: }
9434: } else {
9435: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9436: my $trailstr = join(' -> ',(@{$parents},$category));
9437: if ($allitems->{$item} eq '') {
9438: push(@{$trails},$trailstr);
9439: $allitems->{$item} = scalar(@{$trails})-1;
9440: }
9441: }
9442: return;
9443: }
9444:
1.663 raeburn 9445: =pod
9446:
9447: =item *&assign_categories_table()
9448:
9449: Create a datatable for display of hierarchical categories in a domain,
9450: with checkboxes to allow a course to be categorized.
9451:
9452: Inputs:
9453:
9454: cathash - reference to hash of categories defined for the domain (from
9455: configuration.db)
9456:
9457: currcat - scalar with an & separated list of categories assigned to a course.
9458:
9459: Returns: $output (markup to be displayed)
9460:
9461: =cut
9462:
9463: sub assign_categories_table {
9464: my ($cathash,$currcat) = @_;
9465: my $output;
9466: if (ref($cathash) eq 'HASH') {
9467: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9468: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9469: $maxdepth = scalar(@cats);
9470: if (@cats > 0) {
9471: my $itemcount = 0;
9472: if (ref($cats[0]) eq 'ARRAY') {
9473: $output = &Apache::loncommon::start_data_table();
9474: my @currcategories;
9475: if ($currcat ne '') {
9476: @currcategories = split('&',$currcat);
9477: }
9478: for (my $i=0; $i<@{$cats[0]}; $i++) {
9479: my $parent = $cats[0][$i];
9480: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9481: next if ($parent eq 'instcode');
9482: my $item = &escape($parent).'::0';
9483: my $checked = '';
9484: if (@currcategories > 0) {
9485: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9486: $checked = ' checked="checked"';
1.663 raeburn 9487: }
9488: }
1.675 raeburn 9489: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9490: '<input type="checkbox" name="usecategory" value="'.
9491: $item.'"'.$checked.' />'.$parent.'</span>'.
9492: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9493: my $depth = 1;
9494: push(@path,$parent);
9495: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9496: pop(@path);
9497: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9498: $itemcount ++;
9499: }
9500: $output .= &Apache::loncommon::end_data_table();
9501: }
9502: }
9503: }
9504: return $output;
9505: }
9506:
9507: =pod
9508:
9509: =item *&assign_category_rows()
9510:
9511: Create a datatable row for display of nested categories in a domain,
9512: with checkboxes to allow a course to be categorized,called recursively.
9513:
9514: Inputs:
9515:
9516: itemcount - track row number for alternating colors
9517:
9518: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9519: categories and subcategories.
9520:
9521: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9522:
9523: parent - parent of current category item
9524:
9525: path - Array containing all categories back up through the hierarchy from the
9526: current category to the top level.
9527:
9528: currcategories - reference to array of current categories assigned to the course
9529:
9530: Returns: $output (markup to be displayed).
9531:
9532: =cut
9533:
9534: sub assign_category_rows {
9535: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9536: my ($text,$name,$item,$chgstr);
9537: if (ref($cats) eq 'ARRAY') {
9538: my $maxdepth = scalar(@{$cats});
9539: if (ref($cats->[$depth]) eq 'HASH') {
9540: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9541: my $numchildren = @{$cats->[$depth]{$parent}};
9542: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9543: $text .= '<td><table class="LC_datatable">';
9544: for (my $j=0; $j<$numchildren; $j++) {
9545: $name = $cats->[$depth]{$parent}[$j];
9546: $item = &escape($name).':'.&escape($parent).':'.$depth;
9547: my $deeper = $depth+1;
9548: my $checked = '';
9549: if (ref($currcategories) eq 'ARRAY') {
9550: if (@{$currcategories} > 0) {
9551: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9552: $checked = ' checked="checked"';
1.663 raeburn 9553: }
9554: }
9555: }
1.664 raeburn 9556: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9557: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9558: $item.'"'.$checked.' />'.$name.'</label></span>'.
9559: '<input type="hidden" name="catname" value="'.$name.'" />'.
9560: '</td><td>';
1.663 raeburn 9561: if (ref($path) eq 'ARRAY') {
9562: push(@{$path},$name);
9563: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9564: pop(@{$path});
9565: }
9566: $text .= '</td></tr>';
9567: }
9568: $text .= '</table></td>';
9569: }
9570: }
9571: }
9572: return $text;
9573: }
9574:
1.655 raeburn 9575: ############################################################
9576: ############################################################
9577:
9578:
1.443 albertel 9579: sub commit_customrole {
1.664 raeburn 9580: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9581: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9582: ($start?', '.&mt('starting').' '.localtime($start):'').
9583: ($end?', ending '.localtime($end):'').': <b>'.
9584: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9585: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9586: '</b><br />';
9587: return $output;
9588: }
9589:
9590: sub commit_standardrole {
1.541 raeburn 9591: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9592: my ($output,$logmsg,$linefeed);
9593: if ($context eq 'auto') {
9594: $linefeed = "\n";
9595: } else {
9596: $linefeed = "<br />\n";
9597: }
1.443 albertel 9598: if ($three eq 'st') {
1.541 raeburn 9599: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9600: $one,$two,$sec,$context);
9601: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9602: ($result eq 'unknown_course') || ($result eq 'refused')) {
9603: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9604: } else {
1.541 raeburn 9605: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9606: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9607: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9608: if ($context eq 'auto') {
9609: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9610: } else {
9611: $output .= '<b>'.$result.'</b>'.$linefeed.
9612: &mt('Add to classlist').': <b>ok</b>';
9613: }
9614: $output .= $linefeed;
1.443 albertel 9615: }
9616: } else {
9617: $output = &mt('Assigning').' '.$three.' in '.$url.
9618: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9619: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9620: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9621: if ($context eq 'auto') {
9622: $output .= $result.$linefeed;
9623: } else {
9624: $output .= '<b>'.$result.'</b>'.$linefeed;
9625: }
1.443 albertel 9626: }
9627: return $output;
9628: }
9629:
9630: sub commit_studentrole {
1.541 raeburn 9631: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9632: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9633: if ($context eq 'auto') {
9634: $linefeed = "\n";
9635: } else {
9636: $linefeed = '<br />'."\n";
9637: }
1.443 albertel 9638: if (defined($one) && defined($two)) {
9639: my $cid=$one.'_'.$two;
9640: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9641: my $secchange = 0;
9642: my $expire_role_result;
9643: my $modify_section_result;
1.628 raeburn 9644: if ($oldsec ne '-1') {
9645: if ($oldsec ne $sec) {
1.443 albertel 9646: $secchange = 1;
1.628 raeburn 9647: my $now = time;
1.443 albertel 9648: my $uurl='/'.$cid;
9649: $uurl=~s/\_/\//g;
9650: if ($oldsec) {
9651: $uurl.='/'.$oldsec;
9652: }
1.626 raeburn 9653: $oldsecurl = $uurl;
1.628 raeburn 9654: $expire_role_result =
1.652 raeburn 9655: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9656: if ($env{'request.course.sec'} ne '') {
9657: if ($expire_role_result eq 'refused') {
9658: my @roles = ('st');
9659: my @statuses = ('previous');
9660: my @roledoms = ($one);
9661: my $withsec = 1;
9662: my %roleshash =
9663: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9664: \@statuses,\@roles,\@roledoms,$withsec);
9665: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9666: my ($oldstart,$oldend) =
9667: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9668: if ($oldend > 0 && $oldend <= $now) {
9669: $expire_role_result = 'ok';
9670: }
9671: }
9672: }
9673: }
1.443 albertel 9674: $result = $expire_role_result;
9675: }
9676: }
9677: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9678: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9679: if ($modify_section_result =~ /^ok/) {
9680: if ($secchange == 1) {
1.628 raeburn 9681: if ($sec eq '') {
9682: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9683: } else {
9684: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9685: }
1.443 albertel 9686: } elsif ($oldsec eq '-1') {
1.628 raeburn 9687: if ($sec eq '') {
9688: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9689: } else {
9690: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9691: }
1.443 albertel 9692: } else {
1.628 raeburn 9693: if ($sec eq '') {
9694: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9695: } else {
9696: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9697: }
1.443 albertel 9698: }
9699: } else {
1.628 raeburn 9700: if ($secchange) {
9701: $$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;
9702: } else {
9703: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9704: }
1.443 albertel 9705: }
9706: $result = $modify_section_result;
9707: } elsif ($secchange == 1) {
1.628 raeburn 9708: if ($oldsec eq '') {
9709: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9710: } else {
9711: $$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;
9712: }
1.626 raeburn 9713: if ($expire_role_result eq 'refused') {
9714: my $newsecurl = '/'.$cid;
9715: $newsecurl =~ s/\_/\//g;
9716: if ($sec ne '') {
9717: $newsecurl.='/'.$sec;
9718: }
9719: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9720: if ($sec eq '') {
9721: $$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;
9722: } else {
9723: $$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;
9724: }
9725: }
9726: }
1.443 albertel 9727: }
9728: } else {
1.626 raeburn 9729: $$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 9730: $result = "error: incomplete course id\n";
9731: }
9732: return $result;
9733: }
9734:
9735: ############################################################
9736: ############################################################
9737:
1.566 albertel 9738: sub check_clone {
1.578 raeburn 9739: my ($args,$linefeed) = @_;
1.566 albertel 9740: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9741: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9742: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9743: my $clonemsg;
9744: my $can_clone = 0;
9745:
9746: if ($clonehome eq 'no_host') {
1.578 raeburn 9747: $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 9748: } else {
9749: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9750: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9751: $can_clone = 1;
9752: } else {
9753: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9754: $args->{'clonedomain'},$args->{'clonecourse'});
9755: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9756: if (grep(/^\*$/,@cloners)) {
9757: $can_clone = 1;
9758: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9759: $can_clone = 1;
9760: } else {
9761: my %roleshash =
9762: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9763: $args->{'ccdomain'},
9764: 'userroles',['active'],['cc'],
9765: [$args->{'clonedomain'}]);
9766: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9767: $can_clone = 1;
9768: } else {
9769: $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'});
9770: }
1.566 albertel 9771: }
1.578 raeburn 9772: }
1.566 albertel 9773: }
9774: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9775: }
9776:
1.444 albertel 9777: sub construct_course {
1.541 raeburn 9778: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9779: my $outcome;
1.541 raeburn 9780: my $linefeed = '<br />'."\n";
9781: if ($context eq 'auto') {
9782: $linefeed = "\n";
9783: }
1.566 albertel 9784:
9785: #
9786: # Are we cloning?
9787: #
9788: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9789: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9790: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9791: if ($context ne 'auto') {
1.578 raeburn 9792: if ($clonemsg ne '') {
9793: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9794: }
1.566 albertel 9795: }
9796: $outcome .= $clonemsg.$linefeed;
9797:
9798: if (!$can_clone) {
9799: return (0,$outcome);
9800: }
9801: }
9802:
1.444 albertel 9803: #
9804: # Open course
9805: #
9806: my $crstype = lc($args->{'crstype'});
9807: my %cenv=();
9808: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9809: $args->{'cdescr'},
9810: $args->{'curl'},
9811: $args->{'course_home'},
9812: $args->{'nonstandard'},
9813: $args->{'crscode'},
9814: $args->{'ccuname'}.':'.
9815: $args->{'ccdomain'},
9816: $args->{'crstype'});
9817:
9818: # Note: The testing routines depend on this being output; see
9819: # Utils::Course. This needs to at least be output as a comment
9820: # if anyone ever decides to not show this, and Utils::Course::new
9821: # will need to be suitably modified.
1.541 raeburn 9822: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9823: #
9824: # Check if created correctly
9825: #
1.479 albertel 9826: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9827: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9828: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9829:
1.444 albertel 9830: #
1.566 albertel 9831: # Do the cloning
9832: #
9833: if ($can_clone && $cloneid) {
9834: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9835: if ($context ne 'auto') {
9836: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9837: }
9838: $outcome .= $clonemsg.$linefeed;
9839: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9840: # Copy all files
1.637 www 9841: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9842: # Restore URL
1.566 albertel 9843: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9844: # Restore title
1.566 albertel 9845: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9846: # Mark as cloned
1.566 albertel 9847: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9848: # Need to clone grading mode
9849: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9850: $cenv{'grading'}=$newenv{'grading'};
9851: # Do not clone these environment entries
9852: &Apache::lonnet::del('environment',
9853: ['default_enrollment_start_date',
9854: 'default_enrollment_end_date',
9855: 'question.email',
9856: 'policy.email',
9857: 'comment.email',
9858: 'pch.users.denied',
1.725 raeburn 9859: 'plc.users.denied',
9860: 'hidefromcat',
9861: 'categories'],
1.638 www 9862: $$crsudom,$$crsunum);
1.444 albertel 9863: }
1.566 albertel 9864:
1.444 albertel 9865: #
9866: # Set environment (will override cloned, if existing)
9867: #
9868: my @sections = ();
9869: my @xlists = ();
9870: if ($args->{'crstype'}) {
9871: $cenv{'type'}=$args->{'crstype'};
9872: }
9873: if ($args->{'crsid'}) {
9874: $cenv{'courseid'}=$args->{'crsid'};
9875: }
9876: if ($args->{'crscode'}) {
9877: $cenv{'internal.coursecode'}=$args->{'crscode'};
9878: }
9879: if ($args->{'crsquota'} ne '') {
9880: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9881: } else {
9882: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9883: }
9884: if ($args->{'ccuname'}) {
9885: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9886: ':'.$args->{'ccdomain'};
9887: } else {
9888: $cenv{'internal.courseowner'} = $args->{'curruser'};
9889: }
9890: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9891: if ($args->{'crssections'}) {
9892: $cenv{'internal.sectionnums'} = '';
9893: if ($args->{'crssections'} =~ m/,/) {
9894: @sections = split/,/,$args->{'crssections'};
9895: } else {
9896: $sections[0] = $args->{'crssections'};
9897: }
9898: if (@sections > 0) {
9899: foreach my $item (@sections) {
9900: my ($sec,$gp) = split/:/,$item;
9901: my $class = $args->{'crscode'}.$sec;
9902: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9903: $cenv{'internal.sectionnums'} .= $item.',';
9904: unless ($addcheck eq 'ok') {
9905: push @badclasses, $class;
9906: }
9907: }
9908: $cenv{'internal.sectionnums'} =~ s/,$//;
9909: }
9910: }
9911: # do not hide course coordinator from staff listing,
9912: # even if privileged
9913: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9914: # add crosslistings
9915: if ($args->{'crsxlist'}) {
9916: $cenv{'internal.crosslistings'}='';
9917: if ($args->{'crsxlist'} =~ m/,/) {
9918: @xlists = split/,/,$args->{'crsxlist'};
9919: } else {
9920: $xlists[0] = $args->{'crsxlist'};
9921: }
9922: if (@xlists > 0) {
9923: foreach my $item (@xlists) {
9924: my ($xl,$gp) = split/:/,$item;
9925: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9926: $cenv{'internal.crosslistings'} .= $item.',';
9927: unless ($addcheck eq 'ok') {
9928: push @badclasses, $xl;
9929: }
9930: }
9931: $cenv{'internal.crosslistings'} =~ s/,$//;
9932: }
9933: }
9934: if ($args->{'autoadds'}) {
9935: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9936: }
9937: if ($args->{'autodrops'}) {
9938: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9939: }
9940: # check for notification of enrollment changes
9941: my @notified = ();
9942: if ($args->{'notify_owner'}) {
9943: if ($args->{'ccuname'} ne '') {
9944: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9945: }
9946: }
9947: if ($args->{'notify_dc'}) {
9948: if ($uname ne '') {
1.630 raeburn 9949: push(@notified,$uname.':'.$udom);
1.444 albertel 9950: }
9951: }
9952: if (@notified > 0) {
9953: my $notifylist;
9954: if (@notified > 1) {
9955: $notifylist = join(',',@notified);
9956: } else {
9957: $notifylist = $notified[0];
9958: }
9959: $cenv{'internal.notifylist'} = $notifylist;
9960: }
9961: if (@badclasses > 0) {
9962: my %lt=&Apache::lonlocal::texthash(
9963: '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',
9964: 'dnhr' => 'does not have rights to access enrollment in these classes',
9965: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9966: );
1.541 raeburn 9967: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9968: ' ('.$lt{'adby'}.')';
9969: if ($context eq 'auto') {
9970: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9971: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9972: foreach my $item (@badclasses) {
9973: if ($context eq 'auto') {
9974: $outcome .= " - $item\n";
9975: } else {
9976: $outcome .= "<li>$item</li>\n";
9977: }
9978: }
9979: if ($context eq 'auto') {
9980: $outcome .= $linefeed;
9981: } else {
1.566 albertel 9982: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9983: }
9984: }
1.444 albertel 9985: }
9986: if ($args->{'no_end_date'}) {
9987: $args->{'endaccess'} = 0;
9988: }
9989: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9990: $cenv{'internal.autoend'}=$args->{'enrollend'};
9991: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9992: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9993: if ($args->{'showphotos'}) {
9994: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9995: }
9996: $cenv{'internal.authtype'} = $args->{'authtype'};
9997: $cenv{'internal.autharg'} = $args->{'autharg'};
9998: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9999: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10000: 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');
10001: if ($context eq 'auto') {
10002: $outcome .= $krb_msg;
10003: } else {
1.566 albertel 10004: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10005: }
10006: $outcome .= $linefeed;
1.444 albertel 10007: }
10008: }
10009: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10010: if ($args->{'setpolicy'}) {
10011: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10012: }
10013: if ($args->{'setcontent'}) {
10014: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10015: }
10016: }
10017: if ($args->{'reshome'}) {
10018: $cenv{'reshome'}=$args->{'reshome'}.'/';
10019: $cenv{'reshome'}=~s/\/+$/\//;
10020: }
10021: #
10022: # course has keyed access
10023: #
10024: if ($args->{'setkeys'}) {
10025: $cenv{'keyaccess'}='yes';
10026: }
10027: # if specified, key authority is not course, but user
10028: # only active if keyaccess is yes
10029: if ($args->{'keyauth'}) {
1.487 albertel 10030: my ($user,$domain) = split(':',$args->{'keyauth'});
10031: $user = &LONCAPA::clean_username($user);
10032: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10033: if ($user ne '' && $domain ne '') {
1.487 albertel 10034: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10035: }
10036: }
10037:
10038: if ($args->{'disresdis'}) {
10039: $cenv{'pch.roles.denied'}='st';
10040: }
10041: if ($args->{'disablechat'}) {
10042: $cenv{'plc.roles.denied'}='st';
10043: }
10044:
10045: # Record we've not yet viewed the Course Initialization Helper for this
10046: # course
10047: $cenv{'course.helper.not.run'} = 1;
10048: #
10049: # Use new Randomseed
10050: #
10051: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10052: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10053: #
10054: # The encryption code and receipt prefix for this course
10055: #
10056: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10057: $cenv{'internal.encpref'}=100+int(9*rand(99));
10058: #
10059: # By default, use standard grading
10060: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10061:
1.541 raeburn 10062: $outcome .= $linefeed.&mt('Setting environment').': '.
10063: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10064: #
10065: # Open all assignments
10066: #
10067: if ($args->{'openall'}) {
10068: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10069: my %storecontent = ($storeunder => time,
10070: $storeunder.'.type' => 'date_start');
10071:
10072: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10073: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10074: }
10075: #
10076: # Set first page
10077: #
10078: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10079: || ($cloneid)) {
1.445 albertel 10080: use LONCAPA::map;
1.444 albertel 10081: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10082:
10083: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10084: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10085:
1.444 albertel 10086: $outcome .= ($fatal?$errtext:'read ok').' - ';
10087: my $title; my $url;
10088: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10089: $title=&mt('Syllabus');
1.444 albertel 10090: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10091: } else {
1.690 bisitz 10092: $title=&mt('Navigate Contents');
1.444 albertel 10093: $url='/adm/navmaps';
10094: }
1.445 albertel 10095:
10096: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10097: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10098:
10099: if ($errtext) { $fatal=2; }
1.541 raeburn 10100: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10101: }
1.566 albertel 10102:
10103: return (1,$outcome);
1.444 albertel 10104: }
10105:
10106: ############################################################
10107: ############################################################
10108:
1.378 raeburn 10109: sub course_type {
10110: my ($cid) = @_;
10111: if (!defined($cid)) {
10112: $cid = $env{'request.course.id'};
10113: }
1.404 albertel 10114: if (defined($env{'course.'.$cid.'.type'})) {
10115: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10116: } else {
10117: return 'Course';
1.377 raeburn 10118: }
10119: }
1.156 albertel 10120:
1.406 raeburn 10121: sub group_term {
10122: my $crstype = &course_type();
10123: my %names = (
10124: 'Course' => 'group',
10125: 'Group' => 'team',
10126: );
10127: return $names{$crstype};
10128: }
10129:
1.156 albertel 10130: sub icon {
10131: my ($file)=@_;
1.505 albertel 10132: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10133: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10134: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10135: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10136: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10137: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10138: $curfext.".gif") {
10139: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10140: $curfext.".gif";
10141: }
10142: }
1.249 albertel 10143: return &lonhttpdurl($iconname);
1.154 albertel 10144: }
1.84 albertel 10145:
1.575 albertel 10146: sub lonhttpdurl {
1.692 www 10147: #
10148: # Had been used for "small fry" static images on separate port 8080.
10149: # Modify here if lightweight http functionality desired again.
10150: # Currently eliminated due to increasing firewall issues.
10151: #
1.575 albertel 10152: my ($url)=@_;
1.692 www 10153: return $url;
1.215 albertel 10154: }
10155:
1.213 albertel 10156: sub connection_aborted {
10157: my ($r)=@_;
10158: $r->print(" ");$r->rflush();
10159: my $c = $r->connection;
10160: return $c->aborted();
10161: }
10162:
1.221 foxr 10163: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10164: # strings as 'strings'.
10165: sub escape_single {
1.221 foxr 10166: my ($input) = @_;
1.223 albertel 10167: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10168: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10169: return $input;
10170: }
1.223 albertel 10171:
1.222 foxr 10172: # Same as escape_single, but escape's "'s This
10173: # can be used for "strings"
10174: sub escape_double {
10175: my ($input) = @_;
10176: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10177: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10178: return $input;
10179: }
1.223 albertel 10180:
1.222 foxr 10181: # Escapes the last element of a full URL.
10182: sub escape_url {
10183: my ($url) = @_;
1.238 raeburn 10184: my @urlslices = split(/\//, $url,-1);
1.369 www 10185: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10186: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10187: }
1.462 albertel 10188:
10189: # -------------------------------------------------------- Initliaze user login
10190: sub init_user_environment {
1.463 albertel 10191: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10192: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10193:
10194: my $public=($username eq 'public' && $domain eq 'public');
10195:
10196: # See if old ID present, if so, remove
10197:
10198: my ($filename,$cookie,$userroles);
10199: my $now=time;
10200:
10201: if ($public) {
10202: my $max_public=100;
10203: my $oldest;
10204: my $oldest_time=0;
10205: for(my $next=1;$next<=$max_public;$next++) {
10206: if (-e $lonids."/publicuser_$next.id") {
10207: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10208: if ($mtime<$oldest_time || !$oldest_time) {
10209: $oldest_time=$mtime;
10210: $oldest=$next;
10211: }
10212: } else {
10213: $cookie="publicuser_$next";
10214: last;
10215: }
10216: }
10217: if (!$cookie) { $cookie="publicuser_$oldest"; }
10218: } else {
1.463 albertel 10219: # if this isn't a robot, kill any existing non-robot sessions
10220: if (!$args->{'robot'}) {
10221: opendir(DIR,$lonids);
10222: while ($filename=readdir(DIR)) {
10223: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10224: unlink($lonids.'/'.$filename);
10225: }
1.462 albertel 10226: }
1.463 albertel 10227: closedir(DIR);
1.462 albertel 10228: }
10229: # Give them a new cookie
1.463 albertel 10230: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10231: : $now.$$.int(rand(10000)));
1.463 albertel 10232: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10233:
10234: # Initialize roles
10235:
10236: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10237: }
10238: # ------------------------------------ Check browser type and MathML capability
10239:
10240: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10241: $clientunicode,$clientos) = &decode_user_agent($r);
10242:
10243: # -------------------------------------- Any accessibility options to remember?
10244: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
10245: foreach my $option ('imagesuppress','appletsuppress',
10246: 'embedsuppress','fontenhance','blackwhite') {
10247: if ($form->{$option} eq 'true') {
10248: &Apache::lonnet::put('environment',{$option => 'on'},
10249: $domain,$username);
10250: } else {
10251: &Apache::lonnet::del('environment',[$option],
10252: $domain,$username);
10253: }
10254: }
10255: }
10256: # ------------------------------------------------------------- Get environment
10257:
10258: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10259: my ($tmp) = keys(%userenv);
10260: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10261: # default remote control to off
10262: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10263: } else {
10264: undef(%userenv);
10265: }
10266: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10267: $form->{'interface'}=$userenv{'interface'};
10268: }
10269: $env{'environment.remote'}=$userenv{'remote'};
10270: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10271:
10272: # --------------- Do not trust query string to be put directly into environment
10273: foreach my $option ('imagesuppress','appletsuppress',
10274: 'embedsuppress','fontenhance','blackwhite',
10275: 'interface','localpath','localres') {
10276: $form->{$option}=~s/[\n\r\=]//gs;
10277: }
10278: # --------------------------------------------------------- Write first profile
10279:
10280: {
10281: my %initial_env =
10282: ("user.name" => $username,
10283: "user.domain" => $domain,
10284: "user.home" => $authhost,
10285: "browser.type" => $clientbrowser,
10286: "browser.version" => $clientversion,
10287: "browser.mathml" => $clientmathml,
10288: "browser.unicode" => $clientunicode,
10289: "browser.os" => $clientos,
10290: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10291: "request.course.fn" => '',
10292: "request.course.uri" => '',
10293: "request.course.sec" => '',
10294: "request.role" => 'cm',
10295: "request.role.adv" => $env{'user.adv'},
10296: "request.host" => $ENV{'REMOTE_ADDR'},);
10297:
10298: if ($form->{'localpath'}) {
10299: $initial_env{"browser.localpath"} = $form->{'localpath'};
10300: $initial_env{"browser.localres"} = $form->{'localres'};
10301: }
10302:
10303: if ($public) {
10304: $initial_env{"environment.remote"} = "off";
10305: }
10306: if ($form->{'interface'}) {
10307: $form->{'interface'}=~s/\W//gs;
10308: $initial_env{"browser.interface"} = $form->{'interface'};
10309: $env{'browser.interface'}=$form->{'interface'};
10310: foreach my $option ('imagesuppress','appletsuppress',
10311: 'embedsuppress','fontenhance','blackwhite') {
10312: if (($form->{$option} eq 'true') ||
10313: ($userenv{$option} eq 'on')) {
10314: $initial_env{"browser.$option"} = "on";
10315: }
10316: }
10317: }
10318:
1.724 raeburn 10319: foreach my $tool ('aboutme','blog','portfolio') {
10320: $userenv{'availabletools.'.$tool} =
10321: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10322: }
10323:
1.765 raeburn 10324: foreach my $crstype ('official','unofficial') {
10325: $userenv{'canrequest.'.$crstype} =
10326: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10327: 'reload','requestcourses');
10328: }
10329:
1.462 albertel 10330: $env{'user.environment'} = "$lonids/$cookie.id";
10331:
10332: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10333: &GDBM_WRCREAT(),0640)) {
10334: &_add_to_env(\%disk_env,\%initial_env);
10335: &_add_to_env(\%disk_env,\%userenv,'environment.');
10336: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10337: if (ref($args->{'extra_env'})) {
10338: &_add_to_env(\%disk_env,$args->{'extra_env'});
10339: }
1.462 albertel 10340: untie(%disk_env);
10341: } else {
1.705 tempelho 10342: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10343: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10344: return 'error: '.$!;
10345: }
10346: }
10347: $env{'request.role'}='cm';
10348: $env{'request.role.adv'}=$env{'user.adv'};
10349: $env{'browser.type'}=$clientbrowser;
10350:
10351: return $cookie;
10352:
10353: }
10354:
10355: sub _add_to_env {
10356: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10357: if (ref($env_data) eq 'HASH') {
10358: while (my ($key,$value) = each(%$env_data)) {
10359: $idf->{$prefix.$key} = $value;
10360: $env{$prefix.$key} = $value;
10361: }
1.462 albertel 10362: }
10363: }
10364:
1.685 tempelho 10365: # --- Get the symbolic name of a problem and the url
10366: sub get_symb {
10367: my ($request,$silent) = @_;
1.726 raeburn 10368: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10369: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10370: if ($symb eq '') {
10371: if (!$silent) {
10372: $request->print("Unable to handle ambiguous references:$url:.");
10373: return ();
10374: }
10375: }
10376: &Apache::lonenc::check_decrypt(\$symb);
10377: return ($symb);
10378: }
10379:
10380: # --------------------------------------------------------------Get annotation
10381:
10382: sub get_annotation {
10383: my ($symb,$enc) = @_;
10384:
10385: my $key = $symb;
10386: if (!$enc) {
10387: $key =
10388: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10389: }
10390: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10391: return $annotation{$key};
10392: }
10393:
10394: sub clean_symb {
1.731 raeburn 10395: my ($symb,$delete_enc) = @_;
1.685 tempelho 10396:
10397: &Apache::lonenc::check_decrypt(\$symb);
10398: my $enc = $env{'request.enc'};
1.731 raeburn 10399: if ($delete_enc) {
1.730 raeburn 10400: delete($env{'request.enc'});
10401: }
1.685 tempelho 10402:
10403: return ($symb,$enc);
10404: }
1.462 albertel 10405:
1.41 ng 10406: =pod
10407:
10408: =back
10409:
1.112 bowersj2 10410: =cut
1.41 ng 10411:
1.112 bowersj2 10412: 1;
10413: __END__;
1.41 ng 10414:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>