Annotation of loncom/interface/loncommon.pm, revision 1.797
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.797 ! www 4: # $Id: loncommon.pm,v 1.796 2009/04/25 20:22:07 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);
1.552 banghart 934: if ($env{'browser.interface'} eq 'textual') {
1.79 www 935: $stayOnPage=1;
936: }
1.44 bowersj2 937: $width = 350 if (not defined $width);
938: $height = 400 if (not defined $height);
939: my $filename = $topic;
940: $filename =~ s/ /_/g;
941:
1.48 bowersj2 942: my $template = "";
943: my $link;
1.572 banghart 944:
1.159 www 945: $topic=~s/\W/\_/g;
1.44 bowersj2 946:
1.572 banghart 947: if (!$stayOnPage) {
1.72 bowersj2 948: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 949: } else {
1.48 bowersj2 950: $link = "/adm/help/${filename}.hlp";
951: }
952:
953: # Add the text
1.755 neumanie 954: if ($text ne "") {
1.763 bisitz 955: $template.='<span class="LC_help_open_topic">'
956: .'<a target="_top" href="'.$link.'">'
957: .$text.'</a>';
1.48 bowersj2 958: }
959:
1.763 bisitz 960: # (Always) Add the graphic
1.179 matthew 961: my $title = &mt('Online Help');
1.667 raeburn 962: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 963: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
964: .'<img src="'.$helpicon.'" border="0"'
965: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 966: .' title="'.$title.'"'
1.763 bisitz 967: .' /></a>';
968: if ($text ne "") {
969: $template.='</span>';
970: }
1.44 bowersj2 971: return $template;
972:
1.106 bowersj2 973: }
974:
975: # This is a quicky function for Latex cheatsheet editing, since it
976: # appears in at least four places
977: sub helpLatexCheatsheet {
1.732 raeburn 978: my ($topic,$text,$not_author) = @_;
979: my $out;
1.106 bowersj2 980: my $addOther = '';
1.732 raeburn 981: if ($topic) {
1.763 bisitz 982: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
983: undef, undef, 600).
984: '</span> ';
985: }
986: $out = '<span>' # Start cheatsheet
987: .$addOther
988: .'<span>'
989: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
990: undef,undef,600)
991: .'</span> <span>'
992: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
993: undef,undef,600)
994: .'</span>';
1.732 raeburn 995: unless ($not_author) {
1.763 bisitz 996: $out .= ' <span>'
997: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
998: undef,undef,600)
999: .'</span>';
1.732 raeburn 1000: }
1.763 bisitz 1001: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1002: return $out;
1.172 www 1003: }
1004:
1.430 albertel 1005: sub general_help {
1006: my $helptopic='Student_Intro';
1007: if ($env{'request.role'}=~/^(ca|au)/) {
1008: $helptopic='Authoring_Intro';
1009: } elsif ($env{'request.role'}=~/^cc/) {
1010: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1011: } elsif ($env{'request.role'}=~/^dc/) {
1012: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1013: }
1014: return $helptopic;
1015: }
1016:
1017: sub update_help_link {
1018: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1019: my $origurl = $ENV{'REQUEST_URI'};
1020: $origurl=~s|^/~|/priv/|;
1021: my $timestamp = time;
1022: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1023: $$datum = &escape($$datum);
1024: }
1025:
1026: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1027: my $output .= <<"ENDOUTPUT";
1028: <script type="text/javascript">
1029: banner_link = '$banner_link';
1030: </script>
1031: ENDOUTPUT
1032: return $output;
1033: }
1034:
1035: # now just updates the help link and generates a blue icon
1.193 raeburn 1036: sub help_open_menu {
1.430 albertel 1037: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1038: = @_;
1.430 albertel 1039: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1040: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1041: # if environment.remote is on (using remote control UI)
1.572 banghart 1042: if ($env{'browser.interface'} eq 'textual' ||
1043: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1044: $stayOnPage=1;
1.430 albertel 1045: }
1046: my $output;
1047: if ($component_help) {
1048: if (!$text) {
1049: $output=&help_open_topic($component_help,undef,$stayOnPage,
1050: $width,$height);
1051: } else {
1052: my $help_text;
1053: $help_text=&unescape($topic);
1054: $output='<table><tr><td>'.
1055: &help_open_topic($component_help,$help_text,$stayOnPage,
1056: $width,$height).'</td></tr></table>';
1057: }
1058: }
1059: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1060: return $output.$banner_link;
1061: }
1062:
1063: sub top_nav_help {
1064: my ($text) = @_;
1.436 albertel 1065: $text = &mt($text);
1.572 banghart 1066: my $stay_on_page =
1.436 albertel 1067: ($env{'browser.interface'} eq 'textual' ||
1068: $env{'environment.remote'} eq 'off' );
1.572 banghart 1069: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1070: : "javascript:helpMenu('open')";
1.572 banghart 1071: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1072:
1.201 raeburn 1073: my $title = &mt('Get help');
1.436 albertel 1074:
1075: return <<"END";
1076: $banner_link
1077: <a href="$link" title="$title">$text</a>
1078: END
1079: }
1080:
1081: sub help_menu_js {
1082: my ($text) = @_;
1083:
1084: my $stayOnPage =
1085: ($env{'browser.interface'} eq 'textual' ||
1086: $env{'environment.remote'} eq 'off' );
1087:
1088: my $width = 620;
1089: my $height = 600;
1.430 albertel 1090: my $helptopic=&general_help();
1091: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1092: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1093: my $start_page =
1094: &Apache::loncommon::start_page('Help Menu', undef,
1095: {'frameset' => 1,
1096: 'js_ready' => 1,
1097: 'add_entries' => {
1098: 'border' => '0',
1.579 raeburn 1099: 'rows' => "110,*",},});
1.331 albertel 1100: my $end_page =
1101: &Apache::loncommon::end_page({'frameset' => 1,
1102: 'js_ready' => 1,});
1103:
1.436 albertel 1104: my $template .= <<"ENDTEMPLATE";
1105: <script type="text/javascript">
1.253 albertel 1106: // <!-- BEGIN LON-CAPA Internal
1107: // <![CDATA[
1.430 albertel 1108: var banner_link = '';
1.243 raeburn 1109: function helpMenu(target) {
1110: var caller = this;
1111: if (target == 'open') {
1112: var newWindow = null;
1113: try {
1.262 albertel 1114: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1115: }
1116: catch(error) {
1117: writeHelp(caller);
1118: return;
1119: }
1120: if (newWindow) {
1121: caller = newWindow;
1122: }
1.193 raeburn 1123: }
1.243 raeburn 1124: writeHelp(caller);
1125: return;
1126: }
1127: function writeHelp(caller) {
1.430 albertel 1128: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1129: caller.document.close()
1130: caller.focus()
1.193 raeburn 1131: }
1.253 albertel 1132: // ]]>
1.219 albertel 1133: // END LON-CAPA Internal -->
1.436 albertel 1134: </script>
1.193 raeburn 1135: ENDTEMPLATE
1136: return $template;
1137: }
1138:
1.172 www 1139: sub help_open_bug {
1140: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1141: unless ($env{'user.adv'}) { return ''; }
1.172 www 1142: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1143: $text = "" if (not defined $text);
1144: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1145: if ($env{'browser.interface'} eq 'textual' ||
1146: $env{'environment.remote'} eq 'off' ) {
1.172 www 1147: $stayOnPage=1;
1148: }
1.184 albertel 1149: $width = 600 if (not defined $width);
1150: $height = 600 if (not defined $height);
1.172 www 1151:
1152: $topic=~s/\W+/\+/g;
1153: my $link='';
1154: my $template='';
1.379 albertel 1155: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1156: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1157: if (!$stayOnPage)
1158: {
1159: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1160: }
1161: else
1162: {
1163: $link = $url;
1164: }
1165: # Add the text
1166: if ($text ne "")
1167: {
1168: $template .=
1169: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1170: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1171: }
1172:
1173: # Add the graphic
1.179 matthew 1174: my $title = &mt('Report a Bug');
1.215 albertel 1175: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1176: $template .= <<"ENDTEMPLATE";
1.436 albertel 1177: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1178: ENDTEMPLATE
1179: if ($text ne '') { $template.='</td></tr></table>' };
1180: return $template;
1181:
1182: }
1183:
1184: sub help_open_faq {
1185: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1186: unless ($env{'user.adv'}) { return ''; }
1.172 www 1187: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1188: $text = "" if (not defined $text);
1189: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1190: if ($env{'browser.interface'} eq 'textual' ||
1191: $env{'environment.remote'} eq 'off' ) {
1.172 www 1192: $stayOnPage=1;
1193: }
1194: $width = 350 if (not defined $width);
1195: $height = 400 if (not defined $height);
1196:
1197: $topic=~s/\W+/\+/g;
1198: my $link='';
1199: my $template='';
1200: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1201: if (!$stayOnPage)
1202: {
1203: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1204: }
1205: else
1206: {
1207: $link = $url;
1208: }
1209:
1210: # Add the text
1211: if ($text ne "")
1212: {
1213: $template .=
1.173 www 1214: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1215: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1216: }
1217:
1218: # Add the graphic
1.179 matthew 1219: my $title = &mt('View the FAQ');
1.215 albertel 1220: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1221: $template .= <<"ENDTEMPLATE";
1.436 albertel 1222: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1223: ENDTEMPLATE
1224: if ($text ne '') { $template.='</td></tr></table>' };
1225: return $template;
1226:
1.44 bowersj2 1227: }
1.37 matthew 1228:
1.180 matthew 1229: ###############################################################
1230: ###############################################################
1231:
1.45 matthew 1232: =pod
1233:
1.648 raeburn 1234: =item * &change_content_javascript():
1.256 matthew 1235:
1236: This and the next function allow you to create small sections of an
1237: otherwise static HTML page that you can update on the fly with
1238: Javascript, even in Netscape 4.
1239:
1240: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1241: must be written to the HTML page once. It will prove the Javascript
1242: function "change(name, content)". Calling the change function with the
1243: name of the section
1244: you want to update, matching the name passed to C<changable_area>, and
1245: the new content you want to put in there, will put the content into
1246: that area.
1247:
1248: B<Note>: Netscape 4 only reserves enough space for the changable area
1249: to contain room for the original contents. You need to "make space"
1250: for whatever changes you wish to make, and be B<sure> to check your
1251: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1252: it's adequate for updating a one-line status display, but little more.
1253: This script will set the space to 100% width, so you only need to
1254: worry about height in Netscape 4.
1255:
1256: Modern browsers are much less limiting, and if you can commit to the
1257: user not using Netscape 4, this feature may be used freely with
1258: pretty much any HTML.
1259:
1260: =cut
1261:
1262: sub change_content_javascript {
1263: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1264: if ($env{'browser.type'} eq 'netscape' &&
1265: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1266: return (<<NETSCAPE4);
1267: function change(name, content) {
1268: doc = document.layers[name+"___escape"].layers[0].document;
1269: doc.open();
1270: doc.write(content);
1271: doc.close();
1272: }
1273: NETSCAPE4
1274: } else {
1275: # Otherwise, we need to use semi-standards-compliant code
1276: # (technically, "innerHTML" isn't standard but the equivalent
1277: # is really scary, and every useful browser supports it
1278: return (<<DOMBASED);
1279: function change(name, content) {
1280: element = document.getElementById(name);
1281: element.innerHTML = content;
1282: }
1283: DOMBASED
1284: }
1285: }
1286:
1287: =pod
1288:
1.648 raeburn 1289: =item * &changable_area($name,$origContent):
1.256 matthew 1290:
1291: This provides a "changable area" that can be modified on the fly via
1292: the Javascript code provided in C<change_content_javascript>. $name is
1293: the name you will use to reference the area later; do not repeat the
1294: same name on a given HTML page more then once. $origContent is what
1295: the area will originally contain, which can be left blank.
1296:
1297: =cut
1298:
1299: sub changable_area {
1300: my ($name, $origContent) = @_;
1301:
1.258 albertel 1302: if ($env{'browser.type'} eq 'netscape' &&
1303: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1304: # If this is netscape 4, we need to use the Layer tag
1305: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1306: } else {
1307: return "<span id='$name'>$origContent</span>";
1308: }
1309: }
1310:
1311: =pod
1312:
1.648 raeburn 1313: =item * &viewport_geometry_js
1.590 raeburn 1314:
1315: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1316:
1317: =cut
1318:
1319:
1320: sub viewport_geometry_js {
1321: return <<"GEOMETRY";
1322: var Geometry = {};
1323: function init_geometry() {
1324: if (Geometry.init) { return };
1325: Geometry.init=1;
1326: if (window.innerHeight) {
1327: Geometry.getViewportHeight = function() { return window.innerHeight; };
1328: Geometry.getViewportWidth = function() { return window.innerWidth; };
1329: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1330: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1331: }
1332: else if (document.documentElement && document.documentElement.clientHeight) {
1333: Geometry.getViewportHeight =
1334: function() { return document.documentElement.clientHeight; };
1335: Geometry.getViewportWidth =
1336: function() { return document.documentElement.clientWidth; };
1337:
1338: Geometry.getHorizontalScroll =
1339: function() { return document.documentElement.scrollLeft; };
1340: Geometry.getVerticalScroll =
1341: function() { return document.documentElement.scrollTop; };
1342: }
1343: else if (document.body.clientHeight) {
1344: Geometry.getViewportHeight =
1345: function() { return document.body.clientHeight; };
1346: Geometry.getViewportWidth =
1347: function() { return document.body.clientWidth; };
1348: Geometry.getHorizontalScroll =
1349: function() { return document.body.scrollLeft; };
1350: Geometry.getVerticalScroll =
1351: function() { return document.body.scrollTop; };
1352: }
1353: }
1354:
1355: GEOMETRY
1356: }
1357:
1358: =pod
1359:
1.648 raeburn 1360: =item * &viewport_size_js()
1.590 raeburn 1361:
1362: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1363:
1364: =cut
1365:
1366: sub viewport_size_js {
1367: my $geometry = &viewport_geometry_js();
1368: return <<"DIMS";
1369:
1370: $geometry
1371:
1372: function getViewportDims(width,height) {
1373: init_geometry();
1374: width.value = Geometry.getViewportWidth();
1375: height.value = Geometry.getViewportHeight();
1376: return;
1377: }
1378:
1379: DIMS
1380: }
1381:
1382: =pod
1383:
1.648 raeburn 1384: =item * &resize_textarea_js()
1.565 albertel 1385:
1386: emits the needed javascript to resize a textarea to be as big as possible
1387:
1388: creates a function resize_textrea that takes two IDs first should be
1389: the id of the element to resize, second should be the id of a div that
1390: surrounds everything that comes after the textarea, this routine needs
1391: to be attached to the <body> for the onload and onresize events.
1392:
1.648 raeburn 1393: =back
1.565 albertel 1394:
1395: =cut
1396:
1397: sub resize_textarea_js {
1.590 raeburn 1398: my $geometry = &viewport_geometry_js();
1.565 albertel 1399: return <<"RESIZE";
1400: <script type="text/javascript">
1.590 raeburn 1401: $geometry
1.565 albertel 1402:
1.588 albertel 1403: function getX(element) {
1404: var x = 0;
1405: while (element) {
1406: x += element.offsetLeft;
1407: element = element.offsetParent;
1408: }
1409: return x;
1410: }
1411: function getY(element) {
1412: var y = 0;
1413: while (element) {
1414: y += element.offsetTop;
1415: element = element.offsetParent;
1416: }
1417: return y;
1418: }
1419:
1420:
1.565 albertel 1421: function resize_textarea(textarea_id,bottom_id) {
1422: init_geometry();
1423: var textarea = document.getElementById(textarea_id);
1424: //alert(textarea);
1425:
1.588 albertel 1426: var textarea_top = getY(textarea);
1.565 albertel 1427: var textarea_height = textarea.offsetHeight;
1428: var bottom = document.getElementById(bottom_id);
1.588 albertel 1429: var bottom_top = getY(bottom);
1.565 albertel 1430: var bottom_height = bottom.offsetHeight;
1431: var window_height = Geometry.getViewportHeight();
1.588 albertel 1432: var fudge = 23;
1.565 albertel 1433: var new_height = window_height-fudge-textarea_top-bottom_height;
1434: if (new_height < 300) {
1435: new_height = 300;
1436: }
1437: textarea.style.height=new_height+'px';
1438: }
1439: </script>
1440: RESIZE
1441:
1442: }
1443:
1444: =pod
1445:
1.256 matthew 1446: =head1 Excel and CSV file utility routines
1447:
1448: =over 4
1449:
1450: =cut
1451:
1452: ###############################################################
1453: ###############################################################
1454:
1455: =pod
1456:
1.648 raeburn 1457: =item * &csv_translate($text)
1.37 matthew 1458:
1.185 www 1459: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1460: format.
1461:
1462: =cut
1463:
1.180 matthew 1464: ###############################################################
1465: ###############################################################
1.37 matthew 1466: sub csv_translate {
1467: my $text = shift;
1468: $text =~ s/\"/\"\"/g;
1.209 albertel 1469: $text =~ s/\n/ /g;
1.37 matthew 1470: return $text;
1471: }
1.180 matthew 1472:
1473: ###############################################################
1474: ###############################################################
1475:
1476: =pod
1477:
1.648 raeburn 1478: =item * &define_excel_formats()
1.180 matthew 1479:
1480: Define some commonly used Excel cell formats.
1481:
1482: Currently supported formats:
1483:
1484: =over 4
1485:
1486: =item header
1487:
1488: =item bold
1489:
1490: =item h1
1491:
1492: =item h2
1493:
1494: =item h3
1495:
1.256 matthew 1496: =item h4
1497:
1498: =item i
1499:
1.180 matthew 1500: =item date
1501:
1502: =back
1503:
1504: Inputs: $workbook
1505:
1506: Returns: $format, a hash reference.
1507:
1508: =cut
1509:
1510: ###############################################################
1511: ###############################################################
1512: sub define_excel_formats {
1513: my ($workbook) = @_;
1514: my $format;
1515: $format->{'header'} = $workbook->add_format(bold => 1,
1516: bottom => 1,
1517: align => 'center');
1518: $format->{'bold'} = $workbook->add_format(bold=>1);
1519: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1520: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1521: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1522: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1523: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1524: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1525: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1526: return $format;
1527: }
1528:
1529: ###############################################################
1530: ###############################################################
1.113 bowersj2 1531:
1532: =pod
1533:
1.648 raeburn 1534: =item * &create_workbook()
1.255 matthew 1535:
1536: Create an Excel worksheet. If it fails, output message on the
1537: request object and return undefs.
1538:
1539: Inputs: Apache request object
1540:
1541: Returns (undef) on failure,
1542: Excel worksheet object, scalar with filename, and formats
1543: from &Apache::loncommon::define_excel_formats on success
1544:
1545: =cut
1546:
1547: ###############################################################
1548: ###############################################################
1549: sub create_workbook {
1550: my ($r) = @_;
1551: #
1552: # Create the excel spreadsheet
1553: my $filename = '/prtspool/'.
1.258 albertel 1554: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1555: time.'_'.rand(1000000000).'.xls';
1556: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1557: if (! defined($workbook)) {
1558: $r->log_error("Error creating excel spreadsheet $filename: $!");
1559: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1560: "This error has been logged. ".
1561: "Please alert your LON-CAPA administrator").
1562: '</p>');
1563: return (undef);
1564: }
1565: #
1566: $workbook->set_tempdir('/home/httpd/perl/tmp');
1567: #
1568: my $format = &Apache::loncommon::define_excel_formats($workbook);
1569: return ($workbook,$filename,$format);
1570: }
1571:
1572: ###############################################################
1573: ###############################################################
1574:
1575: =pod
1576:
1.648 raeburn 1577: =item * &create_text_file()
1.113 bowersj2 1578:
1.542 raeburn 1579: Create a file to write to and eventually make available to the user.
1.256 matthew 1580: If file creation fails, outputs an error message on the request object and
1581: return undefs.
1.113 bowersj2 1582:
1.256 matthew 1583: Inputs: Apache request object, and file suffix
1.113 bowersj2 1584:
1.256 matthew 1585: Returns (undef) on failure,
1586: Filehandle and filename on success.
1.113 bowersj2 1587:
1588: =cut
1589:
1.256 matthew 1590: ###############################################################
1591: ###############################################################
1592: sub create_text_file {
1593: my ($r,$suffix) = @_;
1594: if (! defined($suffix)) { $suffix = 'txt'; };
1595: my $fh;
1596: my $filename = '/prtspool/'.
1.258 albertel 1597: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1598: time.'_'.rand(1000000000).'.'.$suffix;
1599: $fh = Apache::File->new('>/home/httpd'.$filename);
1600: if (! defined($fh)) {
1601: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1602: $r->print(&mt('Problems occurred in creating the output file. '
1603: .'This error has been logged. '
1604: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1605: }
1.256 matthew 1606: return ($fh,$filename)
1.113 bowersj2 1607: }
1608:
1609:
1.256 matthew 1610: =pod
1.113 bowersj2 1611:
1612: =back
1613:
1614: =cut
1.37 matthew 1615:
1616: ###############################################################
1.33 matthew 1617: ## Home server <option> list generating code ##
1618: ###############################################################
1.35 matthew 1619:
1.169 www 1620: # ------------------------------------------
1621:
1622: sub domain_select {
1623: my ($name,$value,$multiple)=@_;
1624: my %domains=map {
1.514 albertel 1625: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1626: } &Apache::lonnet::all_domains();
1.169 www 1627: if ($multiple) {
1628: $domains{''}=&mt('Any domain');
1.550 albertel 1629: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1630: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1631: } else {
1.550 albertel 1632: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1633: return &select_form($name,$value,%domains);
1634: }
1635: }
1636:
1.282 albertel 1637: #-------------------------------------------
1638:
1639: =pod
1640:
1.519 raeburn 1641: =head1 Routines for form select boxes
1642:
1643: =over 4
1644:
1.648 raeburn 1645: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1646:
1647: Returns a string containing a <select> element int multiple mode
1648:
1649:
1650: Args:
1651: $name - name of the <select> element
1.506 raeburn 1652: $value - scalar or array ref of values that should already be selected
1.282 albertel 1653: $size - number of rows long the select element is
1.283 albertel 1654: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1655: (shown text should already have been &mt())
1.506 raeburn 1656: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1657:
1.282 albertel 1658: =cut
1659:
1660: #-------------------------------------------
1.169 www 1661: sub multiple_select_form {
1.284 albertel 1662: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1663: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1664: my $output='';
1.191 matthew 1665: if (! defined($size)) {
1666: $size = 4;
1.283 albertel 1667: if (scalar(keys(%$hash))<4) {
1668: $size = scalar(keys(%$hash));
1.191 matthew 1669: }
1670: }
1.734 bisitz 1671: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1672: my @order;
1.506 raeburn 1673: if (ref($order) eq 'ARRAY') {
1674: @order = @{$order};
1675: } else {
1676: @order = sort(keys(%$hash));
1.501 banghart 1677: }
1678: if (exists($$hash{'select_form_order'})) {
1679: @order = @{$$hash{'select_form_order'}};
1680: }
1681:
1.284 albertel 1682: foreach my $key (@order) {
1.356 albertel 1683: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1684: $output.='selected="selected" ' if ($selected{$key});
1685: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1686: }
1687: $output.="</select>\n";
1688: return $output;
1689: }
1690:
1.88 www 1691: #-------------------------------------------
1692:
1693: =pod
1694:
1.648 raeburn 1695: =item * &select_form($defdom,$name,%hash)
1.88 www 1696:
1697: Returns a string containing a <select name='$name' size='1'> form to
1698: allow a user to select options from a hash option_name => displayed text.
1699: See lonrights.pm for an example invocation and use.
1700:
1701: =cut
1702:
1703: #-------------------------------------------
1704: sub select_form {
1705: my ($def,$name,%hash) = @_;
1706: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1707: my @keys;
1708: if (exists($hash{'select_form_order'})) {
1709: @keys=@{$hash{'select_form_order'}};
1710: } else {
1711: @keys=sort(keys(%hash));
1712: }
1.356 albertel 1713: foreach my $key (@keys) {
1714: $selectform.=
1715: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1716: ($key eq $def ? 'selected="selected" ' : '').
1717: ">".&mt($hash{$key})."</option>\n";
1.88 www 1718: }
1719: $selectform.="</select>";
1720: return $selectform;
1721: }
1722:
1.475 www 1723: # For display filters
1724:
1725: sub display_filter {
1726: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1727: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1728: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1729: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1730: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1731: '</label></span> <span class="LC_nobreak">'.
1.475 www 1732: &mt('Filter [_1]',
1.477 www 1733: &select_form($env{'form.displayfilter'},
1734: 'displayfilter',
1735: ('currentfolder' => 'Current folder/page',
1736: 'containing' => 'Containing phrase',
1737: 'none' => 'None'))).
1.714 bisitz 1738: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1739: }
1740:
1.167 www 1741: sub gradeleveldescription {
1742: my $gradelevel=shift;
1743: my %gradelevels=(0 => 'Not specified',
1744: 1 => 'Grade 1',
1745: 2 => 'Grade 2',
1746: 3 => 'Grade 3',
1747: 4 => 'Grade 4',
1748: 5 => 'Grade 5',
1749: 6 => 'Grade 6',
1750: 7 => 'Grade 7',
1751: 8 => 'Grade 8',
1752: 9 => 'Grade 9',
1753: 10 => 'Grade 10',
1754: 11 => 'Grade 11',
1755: 12 => 'Grade 12',
1756: 13 => 'Grade 13',
1757: 14 => '100 Level',
1758: 15 => '200 Level',
1759: 16 => '300 Level',
1760: 17 => '400 Level',
1761: 18 => 'Graduate Level');
1762: return &mt($gradelevels{$gradelevel});
1763: }
1764:
1.163 www 1765: sub select_level_form {
1766: my ($deflevel,$name)=@_;
1767: unless ($deflevel) { $deflevel=0; }
1.167 www 1768: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1769: for (my $i=0; $i<=18; $i++) {
1770: $selectform.="<option value=\"$i\" ".
1.253 albertel 1771: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1772: ">".&gradeleveldescription($i)."</option>\n";
1773: }
1774: $selectform.="</select>";
1775: return $selectform;
1.163 www 1776: }
1.167 www 1777:
1.35 matthew 1778: #-------------------------------------------
1779:
1.45 matthew 1780: =pod
1781:
1.743 raeburn 1782: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1783:
1784: Returns a string containing a <select name='$name' size='1'> form to
1785: allow a user to select the domain to preform an operation in.
1786: See loncreateuser.pm for an example invocation and use.
1787:
1.90 www 1788: If the $includeempty flag is set, it also includes an empty choice ("no domain
1789: selected");
1790:
1.743 raeburn 1791: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1792:
1793: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1794:
1.35 matthew 1795: =cut
1796:
1797: #-------------------------------------------
1.34 matthew 1798: sub select_dom_form {
1.743 raeburn 1799: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1800: my $onchange;
1801: if ($autosubmit) {
1802: $onchange = ' onchange="this.form.submit()"';
1803: }
1.550 albertel 1804: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1805: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1806: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1807: foreach my $dom (@domains) {
1808: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1809: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1810: if ($showdomdesc) {
1811: if ($dom ne '') {
1812: my $domdesc = &Apache::lonnet::domain($dom,'description');
1813: if ($domdesc ne '') {
1814: $selectdomain .= ' ('.$domdesc.')';
1815: }
1816: }
1817: }
1818: $selectdomain .= "</option>\n";
1.34 matthew 1819: }
1820: $selectdomain.="</select>";
1821: return $selectdomain;
1822: }
1823:
1.35 matthew 1824: #-------------------------------------------
1825:
1.45 matthew 1826: =pod
1827:
1.648 raeburn 1828: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1829:
1.586 raeburn 1830: input: 4 arguments (two required, two optional) -
1831: $domain - domain of new user
1832: $name - name of form element
1833: $default - Value of 'default' causes a default item to be first
1834: option, and selected by default.
1835: $hide - Value of 'hide' causes hiding of the name of the server,
1836: if 1 server found, or default, if 0 found.
1.594 raeburn 1837: output: returns 2 items:
1.586 raeburn 1838: (a) form element which contains either:
1839: (i) <select name="$name">
1840: <option value="$hostid1">$hostid $servers{$hostid}</option>
1841: <option value="$hostid2">$hostid $servers{$hostid}</option>
1842: </select>
1843: form item if there are multiple library servers in $domain, or
1844: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1845: if there is only one library server in $domain.
1846:
1847: (b) number of library servers found.
1848:
1849: See loncreateuser.pm for example of use.
1.35 matthew 1850:
1851: =cut
1852:
1853: #-------------------------------------------
1.586 raeburn 1854: sub home_server_form_item {
1855: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1856: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1857: my $result;
1858: my $numlib = keys(%servers);
1859: if ($numlib > 1) {
1860: $result .= '<select name="'.$name.'" />'."\n";
1861: if ($default) {
1862: $result .= '<option value="default" selected>'.&mt('default').
1863: '</option>'."\n";
1864: }
1865: foreach my $hostid (sort(keys(%servers))) {
1866: $result.= '<option value="'.$hostid.'">'.
1867: $hostid.' '.$servers{$hostid}."</option>\n";
1868: }
1869: $result .= '</select>'."\n";
1870: } elsif ($numlib == 1) {
1871: my $hostid;
1872: foreach my $item (keys(%servers)) {
1873: $hostid = $item;
1874: }
1875: $result .= '<input type="hidden" name="'.$name.'" value="'.
1876: $hostid.'" />';
1877: if (!$hide) {
1878: $result .= $hostid.' '.$servers{$hostid};
1879: }
1880: $result .= "\n";
1881: } elsif ($default) {
1882: $result .= '<input type="hidden" name="'.$name.
1883: '" value="default" />';
1884: if (!$hide) {
1885: $result .= &mt('default');
1886: }
1887: $result .= "\n";
1.33 matthew 1888: }
1.586 raeburn 1889: return ($result,$numlib);
1.33 matthew 1890: }
1.112 bowersj2 1891:
1892: =pod
1893:
1.534 albertel 1894: =back
1895:
1.112 bowersj2 1896: =cut
1.87 matthew 1897:
1898: ###############################################################
1.112 bowersj2 1899: ## Decoding User Agent ##
1.87 matthew 1900: ###############################################################
1901:
1902: =pod
1903:
1.112 bowersj2 1904: =head1 Decoding the User Agent
1905:
1906: =over 4
1907:
1908: =item * &decode_user_agent()
1.87 matthew 1909:
1910: Inputs: $r
1911:
1912: Outputs:
1913:
1914: =over 4
1915:
1.112 bowersj2 1916: =item * $httpbrowser
1.87 matthew 1917:
1.112 bowersj2 1918: =item * $clientbrowser
1.87 matthew 1919:
1.112 bowersj2 1920: =item * $clientversion
1.87 matthew 1921:
1.112 bowersj2 1922: =item * $clientmathml
1.87 matthew 1923:
1.112 bowersj2 1924: =item * $clientunicode
1.87 matthew 1925:
1.112 bowersj2 1926: =item * $clientos
1.87 matthew 1927:
1928: =back
1929:
1.157 matthew 1930: =back
1931:
1.87 matthew 1932: =cut
1933:
1934: ###############################################################
1935: ###############################################################
1936: sub decode_user_agent {
1.247 albertel 1937: my ($r)=@_;
1.87 matthew 1938: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1939: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1940: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1941: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1942: my $clientbrowser='unknown';
1943: my $clientversion='0';
1944: my $clientmathml='';
1945: my $clientunicode='0';
1946: for (my $i=0;$i<=$#browsertype;$i++) {
1947: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1948: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1949: $clientbrowser=$bname;
1950: $httpbrowser=~/$vreg/i;
1951: $clientversion=$1;
1952: $clientmathml=($clientversion>=$minv);
1953: $clientunicode=($clientversion>=$univ);
1954: }
1955: }
1956: my $clientos='unknown';
1957: if (($httpbrowser=~/linux/i) ||
1958: ($httpbrowser=~/unix/i) ||
1959: ($httpbrowser=~/ux/i) ||
1960: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1961: if (($httpbrowser=~/vax/i) ||
1962: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1963: if ($httpbrowser=~/next/i) { $clientos='next'; }
1964: if (($httpbrowser=~/mac/i) ||
1965: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1966: if ($httpbrowser=~/win/i) { $clientos='win'; }
1967: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1968: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1969: $clientunicode,$clientos,);
1970: }
1971:
1.32 matthew 1972: ###############################################################
1973: ## Authentication changing form generation subroutines ##
1974: ###############################################################
1975: ##
1976: ## All of the authform_xxxxxxx subroutines take their inputs in a
1977: ## hash, and have reasonable default values.
1978: ##
1979: ## formname = the name given in the <form> tag.
1.35 matthew 1980: #-------------------------------------------
1981:
1.45 matthew 1982: =pod
1983:
1.112 bowersj2 1984: =head1 Authentication Routines
1985:
1986: =over 4
1987:
1.648 raeburn 1988: =item * &authform_xxxxxx()
1.35 matthew 1989:
1990: The authform_xxxxxx subroutines provide javascript and html forms which
1991: handle some of the conveniences required for authentication forms.
1992: This is not an optimal method, but it works.
1993:
1994: =over 4
1995:
1.112 bowersj2 1996: =item * authform_header
1.35 matthew 1997:
1.112 bowersj2 1998: =item * authform_authorwarning
1.35 matthew 1999:
1.112 bowersj2 2000: =item * authform_nochange
1.35 matthew 2001:
1.112 bowersj2 2002: =item * authform_kerberos
1.35 matthew 2003:
1.112 bowersj2 2004: =item * authform_internal
1.35 matthew 2005:
1.112 bowersj2 2006: =item * authform_filesystem
1.35 matthew 2007:
2008: =back
2009:
1.648 raeburn 2010: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2011:
1.35 matthew 2012: =cut
2013:
2014: #-------------------------------------------
1.32 matthew 2015: sub authform_header{
2016: my %in = (
2017: formname => 'cu',
1.80 albertel 2018: kerb_def_dom => '',
1.32 matthew 2019: @_,
2020: );
2021: $in{'formname'} = 'document.' . $in{'formname'};
2022: my $result='';
1.80 albertel 2023:
2024: #---------------------------------------------- Code for upper case translation
2025: my $Javascript_toUpperCase;
2026: unless ($in{kerb_def_dom}) {
2027: $Javascript_toUpperCase =<<"END";
2028: switch (choice) {
2029: case 'krb': currentform.elements[choicearg].value =
2030: currentform.elements[choicearg].value.toUpperCase();
2031: break;
2032: default:
2033: }
2034: END
2035: } else {
2036: $Javascript_toUpperCase = "";
2037: }
2038:
1.165 raeburn 2039: my $radioval = "'nochange'";
1.591 raeburn 2040: if (defined($in{'curr_authtype'})) {
2041: if ($in{'curr_authtype'} ne '') {
2042: $radioval = "'".$in{'curr_authtype'}."arg'";
2043: }
1.174 matthew 2044: }
1.165 raeburn 2045: my $argfield = 'null';
1.591 raeburn 2046: if (defined($in{'mode'})) {
1.165 raeburn 2047: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2048: if (defined($in{'curr_autharg'})) {
2049: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2050: $argfield = "'$in{'curr_autharg'}'";
2051: }
2052: }
2053: }
2054: }
2055:
1.32 matthew 2056: $result.=<<"END";
2057: var current = new Object();
1.165 raeburn 2058: current.radiovalue = $radioval;
2059: current.argfield = $argfield;
1.32 matthew 2060:
2061: function changed_radio(choice,currentform) {
2062: var choicearg = choice + 'arg';
2063: // If a radio button in changed, we need to change the argfield
2064: if (current.radiovalue != choice) {
2065: current.radiovalue = choice;
2066: if (current.argfield != null) {
2067: currentform.elements[current.argfield].value = '';
2068: }
2069: if (choice == 'nochange') {
2070: current.argfield = null;
2071: } else {
2072: current.argfield = choicearg;
2073: switch(choice) {
2074: case 'krb':
2075: currentform.elements[current.argfield].value =
2076: "$in{'kerb_def_dom'}";
2077: break;
2078: default:
2079: break;
2080: }
2081: }
2082: }
2083: return;
2084: }
1.22 www 2085:
1.32 matthew 2086: function changed_text(choice,currentform) {
2087: var choicearg = choice + 'arg';
2088: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2089: $Javascript_toUpperCase
1.32 matthew 2090: // clear old field
2091: if ((current.argfield != choicearg) && (current.argfield != null)) {
2092: currentform.elements[current.argfield].value = '';
2093: }
2094: current.argfield = choicearg;
2095: }
2096: set_auth_radio_buttons(choice,currentform);
2097: return;
1.20 www 2098: }
1.32 matthew 2099:
2100: function set_auth_radio_buttons(newvalue,currentform) {
2101: var i=0;
2102: while (i < currentform.login.length) {
2103: if (currentform.login[i].value == newvalue) { break; }
2104: i++;
2105: }
2106: if (i == currentform.login.length) {
2107: return;
2108: }
2109: current.radiovalue = newvalue;
2110: currentform.login[i].checked = true;
2111: return;
2112: }
2113: END
2114: return $result;
2115: }
2116:
2117: sub authform_authorwarning{
2118: my $result='';
1.144 matthew 2119: $result='<i>'.
2120: &mt('As a general rule, only authors or co-authors should be '.
2121: 'filesystem authenticated '.
2122: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2123: return $result;
2124: }
2125:
2126: sub authform_nochange{
2127: my %in = (
2128: formname => 'document.cu',
2129: kerb_def_dom => 'MSU.EDU',
2130: @_,
2131: );
1.586 raeburn 2132: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2133: my $result;
2134: if (keys(%can_assign) == 0) {
2135: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2136: } else {
2137: $result = '<label>'.&mt('[_1] Do not change login data',
2138: '<input type="radio" name="login" value="nochange" '.
2139: 'checked="checked" onclick="'.
1.281 albertel 2140: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2141: '</label>';
1.586 raeburn 2142: }
1.32 matthew 2143: return $result;
2144: }
2145:
1.591 raeburn 2146: sub authform_kerberos {
1.32 matthew 2147: my %in = (
2148: formname => 'document.cu',
2149: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2150: kerb_def_auth => 'krb4',
1.32 matthew 2151: @_,
2152: );
1.586 raeburn 2153: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2154: $autharg,$jscall);
2155: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2156: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2157: $check5 = ' checked="checked"';
1.80 albertel 2158: } else {
1.772 bisitz 2159: $check4 = ' checked="checked"';
1.80 albertel 2160: }
1.165 raeburn 2161: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2162: if (defined($in{'curr_authtype'})) {
2163: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2164: $krbcheck = ' checked="checked"';
1.623 raeburn 2165: if (defined($in{'mode'})) {
2166: if ($in{'mode'} eq 'modifyuser') {
2167: $krbcheck = '';
2168: }
2169: }
1.591 raeburn 2170: if (defined($in{'curr_kerb_ver'})) {
2171: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2172: $check5 = ' checked="checked"';
1.591 raeburn 2173: $check4 = '';
2174: } else {
1.772 bisitz 2175: $check4 = ' checked="checked"';
1.591 raeburn 2176: $check5 = '';
2177: }
1.586 raeburn 2178: }
1.591 raeburn 2179: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2180: $krbarg = $in{'curr_autharg'};
2181: }
1.586 raeburn 2182: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2183: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2184: $result =
2185: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2186: $in{'curr_autharg'},$krbver);
2187: } else {
2188: $result =
2189: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2190: }
2191: return $result;
2192: }
2193: }
2194: } else {
2195: if ($authnum == 1) {
1.784 bisitz 2196: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2197: }
2198: }
1.586 raeburn 2199: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2200: return;
1.587 raeburn 2201: } elsif ($authtype eq '') {
1.591 raeburn 2202: if (defined($in{'mode'})) {
1.587 raeburn 2203: if ($in{'mode'} eq 'modifycourse') {
2204: if ($authnum == 1) {
1.784 bisitz 2205: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2206: }
2207: }
2208: }
1.586 raeburn 2209: }
2210: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2211: if ($authtype eq '') {
2212: $authtype = '<input type="radio" name="login" value="krb" '.
2213: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2214: $krbcheck.' />';
2215: }
2216: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2217: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2218: $in{'curr_authtype'} eq 'krb5') ||
2219: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2220: $in{'curr_authtype'} eq 'krb4')) {
2221: $result .= &mt
1.144 matthew 2222: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2223: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2224: '<label>'.$authtype,
1.281 albertel 2225: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2226: 'value="'.$krbarg.'" '.
1.144 matthew 2227: 'onchange="'.$jscall.'" />',
1.281 albertel 2228: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2229: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2230: '</label>');
1.586 raeburn 2231: } elsif ($can_assign{'krb4'}) {
2232: $result .= &mt
2233: ('[_1] Kerberos authenticated with domain [_2] '.
2234: '[_3] Version 4 [_4]',
2235: '<label>'.$authtype,
2236: '</label><input type="text" size="10" name="krbarg" '.
2237: 'value="'.$krbarg.'" '.
2238: 'onchange="'.$jscall.'" />',
2239: '<label><input type="hidden" name="krbver" value="4" />',
2240: '</label>');
2241: } elsif ($can_assign{'krb5'}) {
2242: $result .= &mt
2243: ('[_1] Kerberos authenticated with domain [_2] '.
2244: '[_3] Version 5 [_4]',
2245: '<label>'.$authtype,
2246: '</label><input type="text" size="10" name="krbarg" '.
2247: 'value="'.$krbarg.'" '.
2248: 'onchange="'.$jscall.'" />',
2249: '<label><input type="hidden" name="krbver" value="5" />',
2250: '</label>');
2251: }
1.32 matthew 2252: return $result;
2253: }
2254:
2255: sub authform_internal{
1.586 raeburn 2256: my %in = (
1.32 matthew 2257: formname => 'document.cu',
2258: kerb_def_dom => 'MSU.EDU',
2259: @_,
2260: );
1.586 raeburn 2261: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2262: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2263: if (defined($in{'curr_authtype'})) {
2264: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2265: if ($can_assign{'int'}) {
1.772 bisitz 2266: $intcheck = 'checked="checked" ';
1.623 raeburn 2267: if (defined($in{'mode'})) {
2268: if ($in{'mode'} eq 'modifyuser') {
2269: $intcheck = '';
2270: }
2271: }
1.591 raeburn 2272: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2273: $intarg = $in{'curr_autharg'};
2274: }
2275: } else {
2276: $result = &mt('Currently internally authenticated.');
2277: return $result;
1.165 raeburn 2278: }
2279: }
1.586 raeburn 2280: } else {
2281: if ($authnum == 1) {
1.784 bisitz 2282: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2283: }
2284: }
2285: if (!$can_assign{'int'}) {
2286: return;
1.587 raeburn 2287: } elsif ($authtype eq '') {
1.591 raeburn 2288: if (defined($in{'mode'})) {
1.587 raeburn 2289: if ($in{'mode'} eq 'modifycourse') {
2290: if ($authnum == 1) {
1.784 bisitz 2291: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2292: }
2293: }
2294: }
1.165 raeburn 2295: }
1.586 raeburn 2296: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2297: if ($authtype eq '') {
2298: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2299: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2300: }
1.605 bisitz 2301: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2302: $intarg.'" onchange="'.$jscall.'" />';
2303: $result = &mt
1.144 matthew 2304: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2305: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2306: $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2307: return $result;
2308: }
2309:
2310: sub authform_local{
2311: my %in = (
2312: formname => 'document.cu',
2313: kerb_def_dom => 'MSU.EDU',
2314: @_,
2315: );
1.586 raeburn 2316: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2317: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2318: if (defined($in{'curr_authtype'})) {
2319: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2320: if ($can_assign{'loc'}) {
1.772 bisitz 2321: $loccheck = 'checked="checked" ';
1.623 raeburn 2322: if (defined($in{'mode'})) {
2323: if ($in{'mode'} eq 'modifyuser') {
2324: $loccheck = '';
2325: }
2326: }
1.591 raeburn 2327: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2328: $locarg = $in{'curr_autharg'};
2329: }
2330: } else {
2331: $result = &mt('Currently using local (institutional) authentication.');
2332: return $result;
1.165 raeburn 2333: }
2334: }
1.586 raeburn 2335: } else {
2336: if ($authnum == 1) {
1.784 bisitz 2337: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2338: }
2339: }
2340: if (!$can_assign{'loc'}) {
2341: return;
1.587 raeburn 2342: } elsif ($authtype eq '') {
1.591 raeburn 2343: if (defined($in{'mode'})) {
1.587 raeburn 2344: if ($in{'mode'} eq 'modifycourse') {
2345: if ($authnum == 1) {
1.784 bisitz 2346: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2347: }
2348: }
2349: }
1.165 raeburn 2350: }
1.586 raeburn 2351: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2352: if ($authtype eq '') {
2353: $authtype = '<input type="radio" name="login" value="loc" '.
2354: $loccheck.' onchange="'.$jscall.'" onclick="'.
2355: $jscall.'" />';
2356: }
2357: $autharg = '<input type="text" size="10" name="locarg" value="'.
2358: $locarg.'" onchange="'.$jscall.'" />';
2359: $result = &mt('[_1] Local Authentication with argument [_2]',
2360: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2361: return $result;
2362: }
2363:
2364: sub authform_filesystem{
2365: my %in = (
2366: formname => 'document.cu',
2367: kerb_def_dom => 'MSU.EDU',
2368: @_,
2369: );
1.586 raeburn 2370: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2371: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2372: if (defined($in{'curr_authtype'})) {
2373: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2374: if ($can_assign{'fsys'}) {
1.772 bisitz 2375: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2376: if (defined($in{'mode'})) {
2377: if ($in{'mode'} eq 'modifyuser') {
2378: $fsyscheck = '';
2379: }
2380: }
1.586 raeburn 2381: } else {
2382: $result = &mt('Currently Filesystem Authenticated.');
2383: return $result;
2384: }
2385: }
2386: } else {
2387: if ($authnum == 1) {
1.784 bisitz 2388: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2389: }
2390: }
2391: if (!$can_assign{'fsys'}) {
2392: return;
1.587 raeburn 2393: } elsif ($authtype eq '') {
1.591 raeburn 2394: if (defined($in{'mode'})) {
1.587 raeburn 2395: if ($in{'mode'} eq 'modifycourse') {
2396: if ($authnum == 1) {
1.784 bisitz 2397: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2398: }
2399: }
2400: }
1.586 raeburn 2401: }
2402: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2403: if ($authtype eq '') {
2404: $authtype = '<input type="radio" name="login" value="fsys" '.
2405: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2406: $jscall.'" />';
2407: }
2408: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2409: ' onchange="'.$jscall.'" />';
2410: $result = &mt
1.144 matthew 2411: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2412: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2413: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2414: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2415: 'onchange="'.$jscall.'" />');
1.32 matthew 2416: return $result;
2417: }
2418:
1.586 raeburn 2419: sub get_assignable_auth {
2420: my ($dom) = @_;
2421: if ($dom eq '') {
2422: $dom = $env{'request.role.domain'};
2423: }
2424: my %can_assign = (
2425: krb4 => 1,
2426: krb5 => 1,
2427: int => 1,
2428: loc => 1,
2429: );
2430: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2431: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2432: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2433: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2434: my $context;
2435: if ($env{'request.role'} =~ /^au/) {
2436: $context = 'author';
2437: } elsif ($env{'request.role'} =~ /^dc/) {
2438: $context = 'domain';
2439: } elsif ($env{'request.course.id'}) {
2440: $context = 'course';
2441: }
2442: if ($context) {
2443: if (ref($authhash->{$context}) eq 'HASH') {
2444: %can_assign = %{$authhash->{$context}};
2445: }
2446: }
2447: }
2448: }
2449: my $authnum = 0;
2450: foreach my $key (keys(%can_assign)) {
2451: if ($can_assign{$key}) {
2452: $authnum ++;
2453: }
2454: }
2455: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2456: $authnum --;
2457: }
2458: return ($authnum,%can_assign);
2459: }
2460:
1.80 albertel 2461: ###############################################################
2462: ## Get Kerberos Defaults for Domain ##
2463: ###############################################################
2464: ##
2465: ## Returns default kerberos version and an associated argument
2466: ## as listed in file domain.tab. If not listed, provides
2467: ## appropriate default domain and kerberos version.
2468: ##
2469: #-------------------------------------------
2470:
2471: =pod
2472:
1.648 raeburn 2473: =item * &get_kerberos_defaults()
1.80 albertel 2474:
2475: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2476: version and domain. If not found, it defaults to version 4 and the
2477: domain of the server.
1.80 albertel 2478:
1.648 raeburn 2479: =over 4
2480:
1.80 albertel 2481: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2482:
1.648 raeburn 2483: =back
2484:
2485: =back
2486:
1.80 albertel 2487: =cut
2488:
2489: #-------------------------------------------
2490: sub get_kerberos_defaults {
2491: my $domain=shift;
1.641 raeburn 2492: my ($krbdef,$krbdefdom);
2493: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2494: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2495: $krbdef = $domdefaults{'auth_def'};
2496: $krbdefdom = $domdefaults{'auth_arg_def'};
2497: } else {
1.80 albertel 2498: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2499: my $krbdefdom=$1;
2500: $krbdefdom=~tr/a-z/A-Z/;
2501: $krbdef = "krb4";
2502: }
2503: return ($krbdef,$krbdefdom);
2504: }
1.112 bowersj2 2505:
1.32 matthew 2506:
1.46 matthew 2507: ###############################################################
2508: ## Thesaurus Functions ##
2509: ###############################################################
1.20 www 2510:
1.46 matthew 2511: =pod
1.20 www 2512:
1.112 bowersj2 2513: =head1 Thesaurus Functions
2514:
2515: =over 4
2516:
1.648 raeburn 2517: =item * &initialize_keywords()
1.46 matthew 2518:
2519: Initializes the package variable %Keywords if it is empty. Uses the
2520: package variable $thesaurus_db_file.
2521:
2522: =cut
2523:
2524: ###################################################
2525:
2526: sub initialize_keywords {
2527: return 1 if (scalar keys(%Keywords));
2528: # If we are here, %Keywords is empty, so fill it up
2529: # Make sure the file we need exists...
2530: if (! -e $thesaurus_db_file) {
2531: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2532: " failed because it does not exist");
2533: return 0;
2534: }
2535: # Set up the hash as a database
2536: my %thesaurus_db;
2537: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2538: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2539: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2540: $thesaurus_db_file);
2541: return 0;
2542: }
2543: # Get the average number of appearances of a word.
2544: my $avecount = $thesaurus_db{'average.count'};
2545: # Put keywords (those that appear > average) into %Keywords
2546: while (my ($word,$data)=each (%thesaurus_db)) {
2547: my ($count,undef) = split /:/,$data;
2548: $Keywords{$word}++ if ($count > $avecount);
2549: }
2550: untie %thesaurus_db;
2551: # Remove special values from %Keywords.
1.356 albertel 2552: foreach my $value ('total.count','average.count') {
2553: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2554: }
1.46 matthew 2555: return 1;
2556: }
2557:
2558: ###################################################
2559:
2560: =pod
2561:
1.648 raeburn 2562: =item * &keyword($word)
1.46 matthew 2563:
2564: Returns true if $word is a keyword. A keyword is a word that appears more
2565: than the average number of times in the thesaurus database. Calls
2566: &initialize_keywords
2567:
2568: =cut
2569:
2570: ###################################################
1.20 www 2571:
2572: sub keyword {
1.46 matthew 2573: return if (!&initialize_keywords());
2574: my $word=lc(shift());
2575: $word=~s/\W//g;
2576: return exists($Keywords{$word});
1.20 www 2577: }
1.46 matthew 2578:
2579: ###############################################################
2580:
2581: =pod
1.20 www 2582:
1.648 raeburn 2583: =item * &get_related_words()
1.46 matthew 2584:
1.160 matthew 2585: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2586: an array of words. If the keyword is not in the thesaurus, an empty array
2587: will be returned. The order of the words returned is determined by the
2588: database which holds them.
2589:
2590: Uses global $thesaurus_db_file.
2591:
2592: =cut
2593:
2594: ###############################################################
2595: sub get_related_words {
2596: my $keyword = shift;
2597: my %thesaurus_db;
2598: if (! -e $thesaurus_db_file) {
2599: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2600: "failed because the file does not exist");
2601: return ();
2602: }
2603: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2604: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2605: return ();
2606: }
2607: my @Words=();
1.429 www 2608: my $count=0;
1.46 matthew 2609: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2610: # The first element is the number of times
2611: # the word appears. We do not need it now.
1.429 www 2612: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2613: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2614: my $threshold=$mostfrequentcount/10;
2615: foreach my $possibleword (@RelatedWords) {
2616: my ($word,$wordcount)=split(/\,/,$possibleword);
2617: if ($wordcount>$threshold) {
2618: push(@Words,$word);
2619: $count++;
2620: if ($count>10) { last; }
2621: }
1.20 www 2622: }
2623: }
1.46 matthew 2624: untie %thesaurus_db;
2625: return @Words;
1.14 harris41 2626: }
1.46 matthew 2627:
1.112 bowersj2 2628: =pod
2629:
2630: =back
2631:
2632: =cut
1.61 www 2633:
2634: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2635: =pod
2636:
1.112 bowersj2 2637: =head1 User Name Functions
2638:
2639: =over 4
2640:
1.648 raeburn 2641: =item * &plainname($uname,$udom,$first)
1.81 albertel 2642:
1.112 bowersj2 2643: Takes a users logon name and returns it as a string in
1.226 albertel 2644: "first middle last generation" form
2645: if $first is set to 'lastname' then it returns it as
2646: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2647:
2648: =cut
1.61 www 2649:
1.295 www 2650:
1.81 albertel 2651: ###############################################################
1.61 www 2652: sub plainname {
1.226 albertel 2653: my ($uname,$udom,$first)=@_;
1.537 albertel 2654: return if (!defined($uname) || !defined($udom));
1.295 www 2655: my %names=&getnames($uname,$udom);
1.226 albertel 2656: my $name=&Apache::lonnet::format_name($names{'firstname'},
2657: $names{'middlename'},
2658: $names{'lastname'},
2659: $names{'generation'},$first);
2660: $name=~s/^\s+//;
1.62 www 2661: $name=~s/\s+$//;
2662: $name=~s/\s+/ /g;
1.353 albertel 2663: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2664: return $name;
1.61 www 2665: }
1.66 www 2666:
2667: # -------------------------------------------------------------------- Nickname
1.81 albertel 2668: =pod
2669:
1.648 raeburn 2670: =item * &nickname($uname,$udom)
1.81 albertel 2671:
2672: Gets a users name and returns it as a string as
2673:
2674: ""nickname""
1.66 www 2675:
1.81 albertel 2676: if the user has a nickname or
2677:
2678: "first middle last generation"
2679:
2680: if the user does not
2681:
2682: =cut
1.66 www 2683:
2684: sub nickname {
2685: my ($uname,$udom)=@_;
1.537 albertel 2686: return if (!defined($uname) || !defined($udom));
1.295 www 2687: my %names=&getnames($uname,$udom);
1.68 albertel 2688: my $name=$names{'nickname'};
1.66 www 2689: if ($name) {
2690: $name='"'.$name.'"';
2691: } else {
2692: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2693: $names{'lastname'}.' '.$names{'generation'};
2694: $name=~s/\s+$//;
2695: $name=~s/\s+/ /g;
2696: }
2697: return $name;
2698: }
2699:
1.295 www 2700: sub getnames {
2701: my ($uname,$udom)=@_;
1.537 albertel 2702: return if (!defined($uname) || !defined($udom));
1.433 albertel 2703: if ($udom eq 'public' && $uname eq 'public') {
2704: return ('lastname' => &mt('Public'));
2705: }
1.295 www 2706: my $id=$uname.':'.$udom;
2707: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2708: if ($cached) {
2709: return %{$names};
2710: } else {
2711: my %loadnames=&Apache::lonnet::get('environment',
2712: ['firstname','middlename','lastname','generation','nickname'],
2713: $udom,$uname);
2714: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2715: return %loadnames;
2716: }
2717: }
1.61 www 2718:
1.542 raeburn 2719: # -------------------------------------------------------------------- getemails
1.648 raeburn 2720:
1.542 raeburn 2721: =pod
2722:
1.648 raeburn 2723: =item * &getemails($uname,$udom)
1.542 raeburn 2724:
2725: Gets a user's email information and returns it as a hash with keys:
2726: notification, critnotification, permanentemail
2727:
2728: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2729: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2730:
1.648 raeburn 2731:
1.542 raeburn 2732: =cut
2733:
1.648 raeburn 2734:
1.466 albertel 2735: sub getemails {
2736: my ($uname,$udom)=@_;
2737: if ($udom eq 'public' && $uname eq 'public') {
2738: return;
2739: }
1.467 www 2740: if (!$udom) { $udom=$env{'user.domain'}; }
2741: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2742: my $id=$uname.':'.$udom;
2743: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2744: if ($cached) {
2745: return %{$names};
2746: } else {
2747: my %loadnames=&Apache::lonnet::get('environment',
2748: ['notification','critnotification',
2749: 'permanentemail'],
2750: $udom,$uname);
2751: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2752: return %loadnames;
2753: }
2754: }
2755:
1.551 albertel 2756: sub flush_email_cache {
2757: my ($uname,$udom)=@_;
2758: if (!$udom) { $udom =$env{'user.domain'}; }
2759: if (!$uname) { $uname=$env{'user.name'}; }
2760: return if ($udom eq 'public' && $uname eq 'public');
2761: my $id=$uname.':'.$udom;
2762: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2763: }
2764:
1.728 raeburn 2765: # -------------------------------------------------------------------- getlangs
2766:
2767: =pod
2768:
2769: =item * &getlangs($uname,$udom)
2770:
2771: Gets a user's language preference and returns it as a hash with key:
2772: language.
2773:
2774: =cut
2775:
2776:
2777: sub getlangs {
2778: my ($uname,$udom) = @_;
2779: if (!$udom) { $udom =$env{'user.domain'}; }
2780: if (!$uname) { $uname=$env{'user.name'}; }
2781: my $id=$uname.':'.$udom;
2782: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2783: if ($cached) {
2784: return %{$langs};
2785: } else {
2786: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2787: $udom,$uname);
2788: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2789: return %loadlangs;
2790: }
2791: }
2792:
2793: sub flush_langs_cache {
2794: my ($uname,$udom)=@_;
2795: if (!$udom) { $udom =$env{'user.domain'}; }
2796: if (!$uname) { $uname=$env{'user.name'}; }
2797: return if ($udom eq 'public' && $uname eq 'public');
2798: my $id=$uname.':'.$udom;
2799: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2800: }
2801:
1.61 www 2802: # ------------------------------------------------------------------ Screenname
1.81 albertel 2803:
2804: =pod
2805:
1.648 raeburn 2806: =item * &screenname($uname,$udom)
1.81 albertel 2807:
2808: Gets a users screenname and returns it as a string
2809:
2810: =cut
1.61 www 2811:
2812: sub screenname {
2813: my ($uname,$udom)=@_;
1.258 albertel 2814: if ($uname eq $env{'user.name'} &&
2815: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2816: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2817: return $names{'screenname'};
1.62 www 2818: }
2819:
1.212 albertel 2820:
1.62 www 2821: # ------------------------------------------------------------- Message Wrapper
2822:
2823: sub messagewrapper {
1.369 www 2824: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2825: return
1.441 albertel 2826: '<a href="/adm/email?compose=individual&'.
2827: 'recname='.$username.'&recdom='.$domain.
2828: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2829: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2830: }
2831: # --------------------------------------------------------------- Notes Wrapper
2832:
2833: sub noteswrapper {
2834: my ($link,$un,$do)=@_;
2835: return
2836: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2837: }
2838: # ------------------------------------------------------------- Aboutme Wrapper
2839:
2840: sub aboutmewrapper {
1.166 www 2841: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2842: if (!defined($username) && !defined($domain)) {
2843: return;
2844: }
1.205 www 2845: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2846: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2847: }
2848:
2849: # ------------------------------------------------------------ Syllabus Wrapper
2850:
2851:
2852: sub syllabuswrapper {
1.707 bisitz 2853: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2854: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2855: }
1.14 harris41 2856:
1.208 matthew 2857: sub track_student_link {
1.268 albertel 2858: my ($linktext,$sname,$sdom,$target,$start) = @_;
2859: my $link ="/adm/trackstudent?";
1.208 matthew 2860: my $title = 'View recent activity';
2861: if (defined($sname) && $sname !~ /^\s*$/ &&
2862: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2863: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2864: $title .= ' of this student';
1.268 albertel 2865: }
1.208 matthew 2866: if (defined($target) && $target !~ /^\s*$/) {
2867: $target = qq{target="$target"};
2868: } else {
2869: $target = '';
2870: }
1.268 albertel 2871: if ($start) { $link.='&start='.$start; }
1.554 albertel 2872: $title = &mt($title);
2873: $linktext = &mt($linktext);
1.448 albertel 2874: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2875: &help_open_topic('View_recent_activity');
1.208 matthew 2876: }
2877:
1.781 raeburn 2878: sub slot_reservations_link {
2879: my ($linktext,$sname,$sdom,$target) = @_;
2880: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2881: my $title = 'View slot reservation history';
2882: if (defined($sname) && $sname !~ /^\s*$/ &&
2883: defined($sdom) && $sdom !~ /^\s*$/) {
2884: $link .= "&uname=$sname&udom=$sdom";
2885: $title .= ' of this student';
2886: }
2887: if (defined($target) && $target !~ /^\s*$/) {
2888: $target = qq{target="$target"};
2889: } else {
2890: $target = '';
2891: }
2892: $title = &mt($title);
2893: $linktext = &mt($linktext);
2894: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2895: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2896:
2897: }
2898:
1.508 www 2899: # ===================================================== Display a student photo
2900:
2901:
1.509 albertel 2902: sub student_image_tag {
1.508 www 2903: my ($domain,$user)=@_;
2904: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2905: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2906: return '<img src="'.$imgsrc.'" align="right" />';
2907: } else {
2908: return '';
2909: }
2910: }
2911:
1.112 bowersj2 2912: =pod
2913:
2914: =back
2915:
2916: =head1 Access .tab File Data
2917:
2918: =over 4
2919:
1.648 raeburn 2920: =item * &languageids()
1.112 bowersj2 2921:
2922: returns list of all language ids
2923:
2924: =cut
2925:
1.14 harris41 2926: sub languageids {
1.16 harris41 2927: return sort(keys(%language));
1.14 harris41 2928: }
2929:
1.112 bowersj2 2930: =pod
2931:
1.648 raeburn 2932: =item * &languagedescription()
1.112 bowersj2 2933:
2934: returns description of a specified language id
2935:
2936: =cut
2937:
1.14 harris41 2938: sub languagedescription {
1.125 www 2939: my $code=shift;
2940: return ($supported_language{$code}?'* ':'').
2941: $language{$code}.
1.126 www 2942: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2943: }
2944:
2945: sub plainlanguagedescription {
2946: my $code=shift;
2947: return $language{$code};
2948: }
2949:
2950: sub supportedlanguagecode {
2951: my $code=shift;
2952: return $supported_language{$code};
1.97 www 2953: }
2954:
1.112 bowersj2 2955: =pod
2956:
1.648 raeburn 2957: =item * ©rightids()
1.112 bowersj2 2958:
2959: returns list of all copyrights
2960:
2961: =cut
2962:
2963: sub copyrightids {
2964: return sort(keys(%cprtag));
2965: }
2966:
2967: =pod
2968:
1.648 raeburn 2969: =item * ©rightdescription()
1.112 bowersj2 2970:
2971: returns description of a specified copyright id
2972:
2973: =cut
2974:
2975: sub copyrightdescription {
1.166 www 2976: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2977: }
1.197 matthew 2978:
2979: =pod
2980:
1.648 raeburn 2981: =item * &source_copyrightids()
1.192 taceyjo1 2982:
2983: returns list of all source copyrights
2984:
2985: =cut
2986:
2987: sub source_copyrightids {
2988: return sort(keys(%scprtag));
2989: }
2990:
2991: =pod
2992:
1.648 raeburn 2993: =item * &source_copyrightdescription()
1.192 taceyjo1 2994:
2995: returns description of a specified source copyright id
2996:
2997: =cut
2998:
2999: sub source_copyrightdescription {
3000: return &mt($scprtag{shift(@_)});
3001: }
1.112 bowersj2 3002:
3003: =pod
3004:
1.648 raeburn 3005: =item * &filecategories()
1.112 bowersj2 3006:
3007: returns list of all file categories
3008:
3009: =cut
3010:
3011: sub filecategories {
3012: return sort(keys(%category_extensions));
3013: }
3014:
3015: =pod
3016:
1.648 raeburn 3017: =item * &filecategorytypes()
1.112 bowersj2 3018:
3019: returns list of file types belonging to a given file
3020: category
3021:
3022: =cut
3023:
3024: sub filecategorytypes {
1.356 albertel 3025: my ($cat) = @_;
3026: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3027: }
3028:
3029: =pod
3030:
1.648 raeburn 3031: =item * &fileembstyle()
1.112 bowersj2 3032:
3033: returns embedding style for a specified file type
3034:
3035: =cut
3036:
3037: sub fileembstyle {
3038: return $fe{lc(shift(@_))};
1.169 www 3039: }
3040:
1.351 www 3041: sub filemimetype {
3042: return $fm{lc(shift(@_))};
3043: }
3044:
1.169 www 3045:
3046: sub filecategoryselect {
3047: my ($name,$value)=@_;
1.189 matthew 3048: return &select_form($value,$name,
1.169 www 3049: '' => &mt('Any category'),
3050: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3051: }
3052:
3053: =pod
3054:
1.648 raeburn 3055: =item * &filedescription()
1.112 bowersj2 3056:
3057: returns description for a specified file type
3058:
3059: =cut
3060:
3061: sub filedescription {
1.188 matthew 3062: my $file_description = $fd{lc(shift())};
3063: $file_description =~ s:([\[\]]):~$1:g;
3064: return &mt($file_description);
1.112 bowersj2 3065: }
3066:
3067: =pod
3068:
1.648 raeburn 3069: =item * &filedescriptionex()
1.112 bowersj2 3070:
3071: returns description for a specified file type with
3072: extra formatting
3073:
3074: =cut
3075:
3076: sub filedescriptionex {
3077: my $ex=shift;
1.188 matthew 3078: my $file_description = $fd{lc($ex)};
3079: $file_description =~ s:([\[\]]):~$1:g;
3080: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3081: }
3082:
3083: # End of .tab access
3084: =pod
3085:
3086: =back
3087:
3088: =cut
3089:
3090: # ------------------------------------------------------------------ File Types
3091: sub fileextensions {
3092: return sort(keys(%fe));
3093: }
3094:
1.97 www 3095: # ----------------------------------------------------------- Display Languages
3096: # returns a hash with all desired display languages
3097: #
3098:
3099: sub display_languages {
3100: my %languages=();
1.695 raeburn 3101: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3102: $languages{$lang}=1;
1.97 www 3103: }
3104: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3105: if ($env{'form.displaylanguage'}) {
1.356 albertel 3106: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3107: $languages{$lang}=1;
1.97 www 3108: }
3109: }
3110: return %languages;
1.14 harris41 3111: }
3112:
1.582 albertel 3113: sub languages {
3114: my ($possible_langs) = @_;
1.695 raeburn 3115: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3116: if (!ref($possible_langs)) {
3117: if( wantarray ) {
3118: return @preferred_langs;
3119: } else {
3120: return $preferred_langs[0];
3121: }
3122: }
3123: my %possibilities = map { $_ => 1 } (@$possible_langs);
3124: my @preferred_possibilities;
3125: foreach my $preferred_lang (@preferred_langs) {
3126: if (exists($possibilities{$preferred_lang})) {
3127: push(@preferred_possibilities, $preferred_lang);
3128: }
3129: }
3130: if( wantarray ) {
3131: return @preferred_possibilities;
3132: }
3133: return $preferred_possibilities[0];
3134: }
3135:
1.742 raeburn 3136: sub user_lang {
3137: my ($touname,$toudom,$fromcid) = @_;
3138: my @userlangs;
3139: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3140: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3141: $env{'course.'.$fromcid.'.languages'}));
3142: } else {
3143: my %langhash = &getlangs($touname,$toudom);
3144: if ($langhash{'languages'} ne '') {
3145: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3146: } else {
3147: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3148: if ($domdefs{'lang_def'} ne '') {
3149: @userlangs = ($domdefs{'lang_def'});
3150: }
3151: }
3152: }
3153: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3154: my $user_lh = Apache::localize->get_handle(@languages);
3155: return $user_lh;
3156: }
3157:
3158:
1.112 bowersj2 3159: ###############################################################
3160: ## Student Answer Attempts ##
3161: ###############################################################
3162:
3163: =pod
3164:
3165: =head1 Alternate Problem Views
3166:
3167: =over 4
3168:
1.648 raeburn 3169: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3170: $getattempt, $regexp, $gradesub)
3171:
3172: Return string with previous attempt on problem. Arguments:
3173:
3174: =over 4
3175:
3176: =item * $symb: Problem, including path
3177:
3178: =item * $username: username of the desired student
3179:
3180: =item * $domain: domain of the desired student
1.14 harris41 3181:
1.112 bowersj2 3182: =item * $course: Course ID
1.14 harris41 3183:
1.112 bowersj2 3184: =item * $getattempt: Leave blank for all attempts, otherwise put
3185: something
1.14 harris41 3186:
1.112 bowersj2 3187: =item * $regexp: if string matches this regexp, the string will be
3188: sent to $gradesub
1.14 harris41 3189:
1.112 bowersj2 3190: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3191:
1.112 bowersj2 3192: =back
1.14 harris41 3193:
1.112 bowersj2 3194: The output string is a table containing all desired attempts, if any.
1.16 harris41 3195:
1.112 bowersj2 3196: =cut
1.1 albertel 3197:
3198: sub get_previous_attempt {
1.43 ng 3199: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3200: my $prevattempts='';
1.43 ng 3201: no strict 'refs';
1.1 albertel 3202: if ($symb) {
1.3 albertel 3203: my (%returnhash)=
3204: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3205: if ($returnhash{'version'}) {
3206: my %lasthash=();
3207: my $version;
3208: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3209: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3210: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3211: }
1.1 albertel 3212: }
1.596 albertel 3213: $prevattempts=&start_data_table().&start_data_table_header_row();
3214: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3215: foreach my $key (sort(keys(%lasthash))) {
3216: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3217: if ($#parts > 0) {
1.31 albertel 3218: my $data=$parts[-1];
3219: pop(@parts);
1.596 albertel 3220: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3221: } else {
1.41 ng 3222: if ($#parts == 0) {
3223: $prevattempts.='<th>'.$parts[0].'</th>';
3224: } else {
3225: $prevattempts.='<th>'.$ign.'</th>';
3226: }
1.31 albertel 3227: }
1.16 harris41 3228: }
1.596 albertel 3229: $prevattempts.=&end_data_table_header_row();
1.40 ng 3230: if ($getattempt eq '') {
3231: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3232: $prevattempts.=&start_data_table_row().
3233: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3234: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3235: my $value = &format_previous_attempt_value($key,
3236: $returnhash{$version.':'.$key});
3237: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3238: }
1.596 albertel 3239: $prevattempts.=&end_data_table_row();
1.40 ng 3240: }
1.1 albertel 3241: }
1.596 albertel 3242: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3243: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3244: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3245: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3246: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3247: }
1.596 albertel 3248: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3249: } else {
1.596 albertel 3250: $prevattempts=
3251: &start_data_table().&start_data_table_row().
3252: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3253: &end_data_table_row().&end_data_table();
1.1 albertel 3254: }
3255: } else {
1.596 albertel 3256: $prevattempts=
3257: &start_data_table().&start_data_table_row().
3258: '<td>'.&mt('No data.').'</td>'.
3259: &end_data_table_row().&end_data_table();
1.1 albertel 3260: }
1.10 albertel 3261: }
3262:
1.581 albertel 3263: sub format_previous_attempt_value {
3264: my ($key,$value) = @_;
3265: if ($key =~ /timestamp/) {
3266: $value = &Apache::lonlocal::locallocaltime($value);
3267: } elsif (ref($value) eq 'ARRAY') {
3268: $value = '('.join(', ', @{ $value }).')';
3269: } else {
3270: $value = &unescape($value);
3271: }
3272: return $value;
3273: }
3274:
3275:
1.107 albertel 3276: sub relative_to_absolute {
3277: my ($url,$output)=@_;
3278: my $parser=HTML::TokeParser->new(\$output);
3279: my $token;
3280: my $thisdir=$url;
3281: my @rlinks=();
3282: while ($token=$parser->get_token) {
3283: if ($token->[0] eq 'S') {
3284: if ($token->[1] eq 'a') {
3285: if ($token->[2]->{'href'}) {
3286: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3287: }
3288: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3289: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3290: } elsif ($token->[1] eq 'base') {
3291: $thisdir=$token->[2]->{'href'};
3292: }
3293: }
3294: }
3295: $thisdir=~s-/[^/]*$--;
1.356 albertel 3296: foreach my $link (@rlinks) {
1.726 raeburn 3297: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3298: ($link=~/^\//) ||
3299: ($link=~/^javascript:/i) ||
3300: ($link=~/^mailto:/i) ||
3301: ($link=~/^\#/)) {
3302: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3303: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3304: }
3305: }
3306: # -------------------------------------------------- Deal with Applet codebases
3307: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3308: return $output;
3309: }
3310:
1.112 bowersj2 3311: =pod
3312:
1.648 raeburn 3313: =item * &get_student_view()
1.112 bowersj2 3314:
3315: show a snapshot of what student was looking at
3316:
3317: =cut
3318:
1.10 albertel 3319: sub get_student_view {
1.186 albertel 3320: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3321: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3322: my (%form);
1.10 albertel 3323: my @elements=('symb','courseid','domain','username');
3324: foreach my $element (@elements) {
1.186 albertel 3325: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3326: }
1.186 albertel 3327: if (defined($moreenv)) {
3328: %form=(%form,%{$moreenv});
3329: }
1.236 albertel 3330: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3331: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3332: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3333: $userview=~s/\<body[^\>]*\>//gi;
3334: $userview=~s/\<\/body\>//gi;
3335: $userview=~s/\<html\>//gi;
3336: $userview=~s/\<\/html\>//gi;
3337: $userview=~s/\<head\>//gi;
3338: $userview=~s/\<\/head\>//gi;
3339: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3340: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3341: if (wantarray) {
3342: return ($userview,$response);
3343: } else {
3344: return $userview;
3345: }
3346: }
3347:
3348: sub get_student_view_with_retries {
3349: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3350:
3351: my $ok = 0; # True if we got a good response.
3352: my $content;
3353: my $response;
3354:
3355: # Try to get the student_view done. within the retries count:
3356:
3357: do {
3358: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3359: $ok = $response->is_success;
3360: if (!$ok) {
3361: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3362: }
3363: $retries--;
3364: } while (!$ok && ($retries > 0));
3365:
3366: if (!$ok) {
3367: $content = ''; # On error return an empty content.
3368: }
1.651 www 3369: if (wantarray) {
3370: return ($content, $response);
3371: } else {
3372: return $content;
3373: }
1.11 albertel 3374: }
3375:
1.112 bowersj2 3376: =pod
3377:
1.648 raeburn 3378: =item * &get_student_answers()
1.112 bowersj2 3379:
3380: show a snapshot of how student was answering problem
3381:
3382: =cut
3383:
1.11 albertel 3384: sub get_student_answers {
1.100 sakharuk 3385: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3386: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3387: my (%moreenv);
1.11 albertel 3388: my @elements=('symb','courseid','domain','username');
3389: foreach my $element (@elements) {
1.186 albertel 3390: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3391: }
1.186 albertel 3392: $moreenv{'grade_target'}='answer';
3393: %moreenv=(%form,%moreenv);
1.497 raeburn 3394: $feedurl = &Apache::lonnet::clutter($feedurl);
3395: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3396: return $userview;
1.1 albertel 3397: }
1.116 albertel 3398:
3399: =pod
3400:
3401: =item * &submlink()
3402:
1.242 albertel 3403: Inputs: $text $uname $udom $symb $target
1.116 albertel 3404:
3405: Returns: A link to grades.pm such as to see the SUBM view of a student
3406:
3407: =cut
3408:
3409: ###############################################
3410: sub submlink {
1.242 albertel 3411: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3412: if (!($uname && $udom)) {
3413: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3414: &Apache::lonnet::whichuser($symb);
1.116 albertel 3415: if (!$symb) { $symb=$cursymb; }
3416: }
1.254 matthew 3417: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3418: $symb=&escape($symb);
1.242 albertel 3419: if ($target) { $target="target=\"$target\""; }
3420: return '<a href="/adm/grades?&command=submission&'.
3421: 'symb='.$symb.'&student='.$uname.
3422: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3423: }
3424: ##############################################
3425:
3426: =pod
3427:
3428: =item * &pgrdlink()
3429:
3430: Inputs: $text $uname $udom $symb $target
3431:
3432: Returns: A link to grades.pm such as to see the PGRD view of a student
3433:
3434: =cut
3435:
3436: ###############################################
3437: sub pgrdlink {
3438: my $link=&submlink(@_);
3439: $link=~s/(&command=submission)/$1&showgrading=yes/;
3440: return $link;
3441: }
3442: ##############################################
3443:
3444: =pod
3445:
3446: =item * &pprmlink()
3447:
3448: Inputs: $text $uname $udom $symb $target
3449:
3450: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3451: student and a specific resource
1.242 albertel 3452:
3453: =cut
3454:
3455: ###############################################
3456: sub pprmlink {
3457: my ($text,$uname,$udom,$symb,$target)=@_;
3458: if (!($uname && $udom)) {
3459: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3460: &Apache::lonnet::whichuser($symb);
1.242 albertel 3461: if (!$symb) { $symb=$cursymb; }
3462: }
1.254 matthew 3463: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3464: $symb=&escape($symb);
1.242 albertel 3465: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3466: return '<a href="/adm/parmset?command=set&'.
3467: 'symb='.$symb.'&uname='.$uname.
3468: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3469: }
3470: ##############################################
1.37 matthew 3471:
1.112 bowersj2 3472: =pod
3473:
3474: =back
3475:
3476: =cut
3477:
1.37 matthew 3478: ###############################################
1.51 www 3479:
3480:
3481: sub timehash {
1.687 raeburn 3482: my ($thistime) = @_;
3483: my $timezone = &Apache::lonlocal::gettimezone();
3484: my $dt = DateTime->from_epoch(epoch => $thistime)
3485: ->set_time_zone($timezone);
3486: my $wday = $dt->day_of_week();
3487: if ($wday == 7) { $wday = 0; }
3488: return ( 'second' => $dt->second(),
3489: 'minute' => $dt->minute(),
3490: 'hour' => $dt->hour(),
3491: 'day' => $dt->day_of_month(),
3492: 'month' => $dt->month(),
3493: 'year' => $dt->year(),
3494: 'weekday' => $wday,
3495: 'dayyear' => $dt->day_of_year(),
3496: 'dlsav' => $dt->is_dst() );
1.51 www 3497: }
3498:
1.370 www 3499: sub utc_string {
3500: my ($date)=@_;
1.371 www 3501: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3502: }
3503:
1.51 www 3504: sub maketime {
3505: my %th=@_;
1.687 raeburn 3506: my ($epoch_time,$timezone,$dt);
3507: $timezone = &Apache::lonlocal::gettimezone();
3508: eval {
3509: $dt = DateTime->new( year => $th{'year'},
3510: month => $th{'month'},
3511: day => $th{'day'},
3512: hour => $th{'hour'},
3513: minute => $th{'minute'},
3514: second => $th{'second'},
3515: time_zone => $timezone,
3516: );
3517: };
3518: if (!$@) {
3519: $epoch_time = $dt->epoch;
3520: if ($epoch_time) {
3521: return $epoch_time;
3522: }
3523: }
1.51 www 3524: return POSIX::mktime(
3525: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3526: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3527: }
3528:
3529: #########################################
1.51 www 3530:
3531: sub findallcourses {
1.482 raeburn 3532: my ($roles,$uname,$udom) = @_;
1.355 albertel 3533: my %roles;
3534: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3535: my %courses;
1.51 www 3536: my $now=time;
1.482 raeburn 3537: if (!defined($uname)) {
3538: $uname = $env{'user.name'};
3539: }
3540: if (!defined($udom)) {
3541: $udom = $env{'user.domain'};
3542: }
3543: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3544: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3545: if (!%roles) {
3546: %roles = (
3547: cc => 1,
3548: in => 1,
3549: ep => 1,
3550: ta => 1,
3551: cr => 1,
3552: st => 1,
3553: );
3554: }
3555: foreach my $entry (keys(%roleshash)) {
3556: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3557: if ($trole =~ /^cr/) {
3558: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3559: } else {
3560: next if (!exists($roles{$trole}));
3561: }
3562: if ($tend) {
3563: next if ($tend < $now);
3564: }
3565: if ($tstart) {
3566: next if ($tstart > $now);
3567: }
3568: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3569: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3570: if ($secpart eq '') {
3571: ($cnum,$role) = split(/_/,$cnumpart);
3572: $sec = 'none';
3573: $realsec = '';
3574: } else {
3575: $cnum = $cnumpart;
3576: ($sec,$role) = split(/_/,$secpart);
3577: $realsec = $sec;
1.490 raeburn 3578: }
1.482 raeburn 3579: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3580: }
3581: } else {
3582: foreach my $key (keys(%env)) {
1.483 albertel 3583: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3584: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3585: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3586: next if ($role eq 'ca' || $role eq 'aa');
3587: next if (%roles && !exists($roles{$role}));
3588: my ($starttime,$endtime)=split(/\./,$env{$key});
3589: my $active=1;
3590: if ($starttime) {
3591: if ($now<$starttime) { $active=0; }
3592: }
3593: if ($endtime) {
3594: if ($now>$endtime) { $active=0; }
3595: }
3596: if ($active) {
3597: if ($sec eq '') {
3598: $sec = 'none';
3599: }
3600: $courses{$cdom.'_'.$cnum}{$sec} =
3601: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3602: }
3603: }
1.51 www 3604: }
3605: }
1.474 raeburn 3606: return %courses;
1.51 www 3607: }
1.37 matthew 3608:
1.54 www 3609: ###############################################
1.474 raeburn 3610:
3611: sub blockcheck {
1.482 raeburn 3612: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3613:
3614: if (!defined($udom)) {
3615: $udom = $env{'user.domain'};
3616: }
3617: if (!defined($uname)) {
3618: $uname = $env{'user.name'};
3619: }
3620:
3621: # If uname and udom are for a course, check for blocks in the course.
3622:
3623: if (&Apache::lonnet::is_course($udom,$uname)) {
3624: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3625: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3626: return ($startblock,$endblock);
3627: }
1.474 raeburn 3628:
1.502 raeburn 3629: my $startblock = 0;
3630: my $endblock = 0;
1.482 raeburn 3631: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3632:
1.490 raeburn 3633: # If uname is for a user, and activity is course-specific, i.e.,
3634: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3635:
1.490 raeburn 3636: if (($activity eq 'boards' || $activity eq 'chat' ||
3637: $activity eq 'groups') && ($env{'request.course.id'})) {
3638: foreach my $key (keys(%live_courses)) {
3639: if ($key ne $env{'request.course.id'}) {
3640: delete($live_courses{$key});
3641: }
3642: }
3643: }
3644:
3645: my $otheruser = 0;
3646: my %own_courses;
3647: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3648: # Resource belongs to user other than current user.
3649: $otheruser = 1;
3650: # Gather courses for current user
3651: %own_courses =
3652: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3653: }
3654:
3655: # Gather active course roles - course coordinator, instructor,
3656: # exam proctor, ta, student, or custom role.
1.474 raeburn 3657:
3658: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3659: my ($cdom,$cnum);
3660: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3661: $cdom = $env{'course.'.$course.'.domain'};
3662: $cnum = $env{'course.'.$course.'.num'};
3663: } else {
1.490 raeburn 3664: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3665: }
3666: my $no_ownblock = 0;
3667: my $no_userblock = 0;
1.533 raeburn 3668: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3669: # Check if current user has 'evb' priv for this
3670: if (defined($own_courses{$course})) {
3671: foreach my $sec (keys(%{$own_courses{$course}})) {
3672: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3673: if ($sec ne 'none') {
3674: $checkrole .= '/'.$sec;
3675: }
3676: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3677: $no_ownblock = 1;
3678: last;
3679: }
3680: }
3681: }
3682: # if they have 'evb' priv and are currently not playing student
3683: next if (($no_ownblock) &&
3684: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3685: }
1.474 raeburn 3686: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3687: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3688: if ($sec ne 'none') {
1.482 raeburn 3689: $checkrole .= '/'.$sec;
1.474 raeburn 3690: }
1.490 raeburn 3691: if ($otheruser) {
3692: # Resource belongs to user other than current user.
3693: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3694: my ($trole,$tdom,$tnum,$tsec);
3695: my $entry = $live_courses{$course}{$sec};
3696: if ($entry =~ /^cr/) {
3697: ($trole,$tdom,$tnum,$tsec) =
3698: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3699: } else {
3700: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3701: }
3702: my ($spec,$area,$trest,%allroles,%userroles);
3703: $area = '/'.$tdom.'/'.$tnum;
3704: $trest = $tnum;
3705: if ($tsec ne '') {
3706: $area .= '/'.$tsec;
3707: $trest .= '/'.$tsec;
3708: }
3709: $spec = $trole.'.'.$area;
3710: if ($trole =~ /^cr/) {
3711: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3712: $tdom,$spec,$trest,$area);
3713: } else {
3714: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3715: $tdom,$spec,$trest,$area);
3716: }
3717: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3718: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3719: if ($1) {
3720: $no_userblock = 1;
3721: last;
3722: }
3723: }
1.490 raeburn 3724: } else {
3725: # Resource belongs to current user
3726: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3727: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3728: $no_ownblock = 1;
3729: last;
3730: }
1.474 raeburn 3731: }
3732: }
3733: # if they have the evb priv and are currently not playing student
1.482 raeburn 3734: next if (($no_ownblock) &&
1.491 albertel 3735: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3736: next if ($no_userblock);
1.474 raeburn 3737:
1.490 raeburn 3738: # Retrieve blocking times and identity of blocker for course
3739: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3740:
3741: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3742: if (($start != 0) &&
3743: (($startblock == 0) || ($startblock > $start))) {
3744: $startblock = $start;
3745: }
3746: if (($end != 0) &&
3747: (($endblock == 0) || ($endblock < $end))) {
3748: $endblock = $end;
3749: }
1.490 raeburn 3750: }
3751: return ($startblock,$endblock);
3752: }
3753:
3754: sub get_blocks {
3755: my ($setters,$activity,$cdom,$cnum) = @_;
3756: my $startblock = 0;
3757: my $endblock = 0;
3758: my $course = $cdom.'_'.$cnum;
3759: $setters->{$course} = {};
3760: $setters->{$course}{'staff'} = [];
3761: $setters->{$course}{'times'} = [];
3762: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3763: foreach my $record (keys(%records)) {
3764: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3765: if ($start <= time && $end >= time) {
3766: my ($staff_name,$staff_dom,$title,$blocks) =
3767: &parse_block_record($records{$record});
3768: if ($blocks->{$activity} eq 'on') {
3769: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3770: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3771: if ( ($startblock == 0) || ($startblock > $start) ) {
3772: $startblock = $start;
1.490 raeburn 3773: }
1.491 albertel 3774: if ( ($endblock == 0) || ($endblock < $end) ) {
3775: $endblock = $end;
1.474 raeburn 3776: }
3777: }
3778: }
3779: }
3780: return ($startblock,$endblock);
3781: }
3782:
3783: sub parse_block_record {
3784: my ($record) = @_;
3785: my ($setuname,$setudom,$title,$blocks);
3786: if (ref($record) eq 'HASH') {
3787: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3788: $title = &unescape($record->{'event'});
3789: $blocks = $record->{'blocks'};
3790: } else {
3791: my @data = split(/:/,$record,3);
3792: if (scalar(@data) eq 2) {
3793: $title = $data[1];
3794: ($setuname,$setudom) = split(/@/,$data[0]);
3795: } else {
3796: ($setuname,$setudom,$title) = @data;
3797: }
3798: $blocks = { 'com' => 'on' };
3799: }
3800: return ($setuname,$setudom,$title,$blocks);
3801: }
3802:
3803: sub build_block_table {
3804: my ($startblock,$endblock,$setters) = @_;
3805: my %lt = &Apache::lonlocal::texthash(
3806: 'cacb' => 'Currently active communication blocks',
3807: 'cour' => 'Course',
3808: 'dura' => 'Duration',
3809: 'blse' => 'Block set by'
3810: );
3811: my $output;
1.476 raeburn 3812: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3813: $output .= &start_data_table();
3814: $output .= '
3815: <tr>
3816: <th>'.$lt{'cour'}.'</th>
3817: <th>'.$lt{'dura'}.'</th>
3818: <th>'.$lt{'blse'}.'</th>
3819: </tr>
3820: ';
3821: foreach my $course (keys(%{$setters})) {
3822: my %courseinfo=&Apache::lonnet::coursedescription($course);
3823: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3824: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3825: my $fullname = &plainname($uname,$udom);
3826: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3827: && $env{'user.name'} ne 'public'
3828: && $env{'user.domain'} ne 'public') {
3829: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3830: }
1.474 raeburn 3831: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3832: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3833: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3834: $output .= &Apache::loncommon::start_data_table_row().
3835: '<td>'.$courseinfo{'description'}.'</td>'.
3836: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3837: '<td>'.$fullname.'</td>'.
1.474 raeburn 3838: &Apache::loncommon::end_data_table_row();
3839: }
3840: }
3841: $output .= &end_data_table();
3842: }
3843:
1.490 raeburn 3844: sub blocking_status {
3845: my ($activity,$uname,$udom) = @_;
3846: my %setters;
3847: my ($blocked,$output,$ownitem,$is_course);
3848: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3849: if ($startblock && $endblock) {
3850: $blocked = 1;
3851: if (wantarray) {
3852: my $category;
3853: if ($activity eq 'boards') {
3854: $category = 'Discussion posts in this course';
3855: } elsif ($activity eq 'blogs') {
3856: $category = 'Blogs';
3857: } elsif ($activity eq 'port') {
3858: if (defined($uname) && defined($udom)) {
3859: if ($uname eq $env{'user.name'} &&
3860: $udom eq $env{'user.domain'}) {
3861: $ownitem = 1;
3862: }
3863: }
3864: $is_course = &Apache::lonnet::is_course($udom,$uname);
3865: if ($ownitem) {
3866: $category = 'Your portfolio files';
3867: } elsif ($is_course) {
3868: my $coursedesc;
3869: foreach my $course (keys(%setters)) {
3870: my %courseinfo =
3871: &Apache::lonnet::coursedescription($course);
3872: $coursedesc = $courseinfo{'description'};
3873: }
1.764 weissno 3874: $category = "Group portfolio in the course '$coursedesc'";
1.490 raeburn 3875: } else {
3876: $category = 'Portfolio files belonging to ';
3877: if ($env{'user.name'} eq 'public' &&
3878: $env{'user.domain'} eq 'public') {
3879: $category .= &plainname($uname,$udom);
3880: } else {
3881: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3882: }
3883: }
3884: } elsif ($activity eq 'groups') {
3885: $category = 'Groups in this course';
3886: }
3887: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3888: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3889: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3890: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3891: $output .= &build_block_table($startblock,$endblock,\%setters);
3892: }
3893: }
3894: }
3895: if (wantarray) {
3896: return ($blocked,$output);
3897: } else {
3898: return $blocked;
3899: }
3900: }
3901:
1.60 matthew 3902: ###############################################
3903:
1.682 raeburn 3904: sub check_ip_acc {
3905: my ($acc)=@_;
3906: &Apache::lonxml::debug("acc is $acc");
3907: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3908: return 1;
3909: }
3910: my $allowed=0;
3911: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3912:
3913: my $name;
3914: foreach my $pattern (split(',',$acc)) {
3915: $pattern =~ s/^\s*//;
3916: $pattern =~ s/\s*$//;
3917: if ($pattern =~ /\*$/) {
3918: #35.8.*
3919: $pattern=~s/\*//;
3920: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3921: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3922: #35.8.3.[34-56]
3923: my $low=$2;
3924: my $high=$3;
3925: $pattern=$1;
3926: if ($ip =~ /^\Q$pattern\E/) {
3927: my $last=(split(/\./,$ip))[3];
3928: if ($last <=$high && $last >=$low) { $allowed=1; }
3929: }
3930: } elsif ($pattern =~ /^\*/) {
3931: #*.msu.edu
3932: $pattern=~s/\*//;
3933: if (!defined($name)) {
3934: use Socket;
3935: my $netaddr=inet_aton($ip);
3936: ($name)=gethostbyaddr($netaddr,AF_INET);
3937: }
3938: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3939: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3940: #127.0.0.1
3941: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3942: } else {
3943: #some.name.com
3944: if (!defined($name)) {
3945: use Socket;
3946: my $netaddr=inet_aton($ip);
3947: ($name)=gethostbyaddr($netaddr,AF_INET);
3948: }
3949: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3950: }
3951: if ($allowed) { last; }
3952: }
3953: return $allowed;
3954: }
3955:
3956: ###############################################
3957:
1.60 matthew 3958: =pod
3959:
1.112 bowersj2 3960: =head1 Domain Template Functions
3961:
3962: =over 4
3963:
3964: =item * &determinedomain()
1.60 matthew 3965:
3966: Inputs: $domain (usually will be undef)
3967:
1.63 www 3968: Returns: Determines which domain should be used for designs
1.60 matthew 3969:
3970: =cut
1.54 www 3971:
1.60 matthew 3972: ###############################################
1.63 www 3973: sub determinedomain {
3974: my $domain=shift;
1.531 albertel 3975: if (! $domain) {
1.60 matthew 3976: # Determine domain if we have not been given one
3977: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3978: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3979: if ($env{'request.role.domain'}) {
3980: $domain=$env{'request.role.domain'};
1.60 matthew 3981: }
3982: }
1.63 www 3983: return $domain;
3984: }
3985: ###############################################
1.517 raeburn 3986:
1.518 albertel 3987: sub devalidate_domconfig_cache {
3988: my ($udom)=@_;
3989: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3990: }
3991:
3992: # ---------------------- Get domain configuration for a domain
3993: sub get_domainconf {
3994: my ($udom) = @_;
3995: my $cachetime=1800;
3996: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3997: if (defined($cached)) { return %{$result}; }
3998:
3999: my %domconfig = &Apache::lonnet::get_dom('configuration',
4000: ['login','rolecolors'],$udom);
1.632 raeburn 4001: my (%designhash,%legacy);
1.518 albertel 4002: if (keys(%domconfig) > 0) {
4003: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4004: if (keys(%{$domconfig{'login'}})) {
4005: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4006: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4007: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4008: $designhash{$udom.'.login.'.$key.'_'.$img} =
4009: $domconfig{'login'}{$key}{$img};
4010: }
4011: } else {
4012: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4013: }
1.632 raeburn 4014: }
4015: } else {
4016: $legacy{'login'} = 1;
1.518 albertel 4017: }
1.632 raeburn 4018: } else {
4019: $legacy{'login'} = 1;
1.518 albertel 4020: }
4021: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4022: if (keys(%{$domconfig{'rolecolors'}})) {
4023: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4024: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4025: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4026: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4027: }
1.518 albertel 4028: }
4029: }
1.632 raeburn 4030: } else {
4031: $legacy{'rolecolors'} = 1;
1.518 albertel 4032: }
1.632 raeburn 4033: } else {
4034: $legacy{'rolecolors'} = 1;
1.518 albertel 4035: }
1.632 raeburn 4036: if (keys(%legacy) > 0) {
4037: my %legacyhash = &get_legacy_domconf($udom);
4038: foreach my $item (keys(%legacyhash)) {
4039: if ($item =~ /^\Q$udom\E\.login/) {
4040: if ($legacy{'login'}) {
4041: $designhash{$item} = $legacyhash{$item};
4042: }
4043: } else {
4044: if ($legacy{'rolecolors'}) {
4045: $designhash{$item} = $legacyhash{$item};
4046: }
1.518 albertel 4047: }
4048: }
4049: }
1.632 raeburn 4050: } else {
4051: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4052: }
4053: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4054: $cachetime);
4055: return %designhash;
4056: }
4057:
1.632 raeburn 4058: sub get_legacy_domconf {
4059: my ($udom) = @_;
4060: my %legacyhash;
4061: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4062: my $designfile = $designdir.'/'.$udom.'.tab';
4063: if (-e $designfile) {
4064: if ( open (my $fh,"<$designfile") ) {
4065: while (my $line = <$fh>) {
4066: next if ($line =~ /^\#/);
4067: chomp($line);
4068: my ($key,$val)=(split(/\=/,$line));
4069: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4070: }
4071: close($fh);
4072: }
4073: }
4074: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4075: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4076: }
4077: return %legacyhash;
4078: }
4079:
1.63 www 4080: =pod
4081:
1.112 bowersj2 4082: =item * &domainlogo()
1.63 www 4083:
4084: Inputs: $domain (usually will be undef)
4085:
4086: Returns: A link to a domain logo, if the domain logo exists.
4087: If the domain logo does not exist, a description of the domain.
4088:
4089: =cut
1.112 bowersj2 4090:
1.63 www 4091: ###############################################
4092: sub domainlogo {
1.517 raeburn 4093: my $domain = &determinedomain(shift);
1.518 albertel 4094: my %designhash = &get_domainconf($domain);
1.517 raeburn 4095: # See if there is a logo
4096: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4097: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4098: if ($imgsrc =~ m{^/(adm|res)/}) {
4099: if ($imgsrc =~ m{^/res/}) {
4100: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4101: &Apache::lonnet::repcopy($local_name);
4102: }
4103: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4104: }
4105: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4106: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4107: return &Apache::lonnet::domain($domain,'description');
1.59 www 4108: } else {
1.60 matthew 4109: return '';
1.59 www 4110: }
4111: }
1.63 www 4112: ##############################################
4113:
4114: =pod
4115:
1.112 bowersj2 4116: =item * &designparm()
1.63 www 4117:
4118: Inputs: $which parameter; $domain (usually will be undef)
4119:
4120: Returns: value of designparamter $which
4121:
4122: =cut
1.112 bowersj2 4123:
1.397 albertel 4124:
1.400 albertel 4125: ##############################################
1.397 albertel 4126: sub designparm {
4127: my ($which,$domain)=@_;
1.258 albertel 4128: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4129: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4130: return '#000000';
4131: }
1.635 raeburn 4132: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4133: return '#FFFFFF';
4134: }
4135: if ($which=~/\.tabbg$/) {
4136: return '#CCCCCC';
4137: }
4138: }
1.397 albertel 4139: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4140: return $env{'environment.color.'.$which};
1.96 www 4141: }
1.63 www 4142: $domain=&determinedomain($domain);
1.518 albertel 4143: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4144: my $output;
1.517 raeburn 4145: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4146: $output = $domdesign{$domain.'.'.$which};
1.63 www 4147: } else {
1.520 raeburn 4148: $output = $defaultdesign{$which};
4149: }
4150: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4151: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4152: if ($output =~ m{^/(adm|res)/}) {
4153: if ($output =~ m{^/res/}) {
4154: my $local_name = &Apache::lonnet::filelocation('',$output);
4155: &Apache::lonnet::repcopy($local_name);
4156: }
1.520 raeburn 4157: $output = &lonhttpdurl($output);
4158: }
1.63 www 4159: }
1.520 raeburn 4160: return $output;
1.63 www 4161: }
1.59 www 4162:
1.60 matthew 4163: ###############################################
4164: ###############################################
4165:
4166: =pod
4167:
1.112 bowersj2 4168: =back
4169:
1.549 albertel 4170: =head1 HTML Helpers
1.112 bowersj2 4171:
4172: =over 4
4173:
4174: =item * &bodytag()
1.60 matthew 4175:
4176: Returns a uniform header for LON-CAPA web pages.
4177:
4178: Inputs:
4179:
1.112 bowersj2 4180: =over 4
4181:
4182: =item * $title, A title to be displayed on the page.
4183:
4184: =item * $function, the current role (can be undef).
4185:
4186: =item * $addentries, extra parameters for the <body> tag.
4187:
4188: =item * $bodyonly, if defined, only return the <body> tag.
4189:
4190: =item * $domain, if defined, force a given domain.
4191:
4192: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4193: text interface only)
1.60 matthew 4194:
1.326 albertel 4195: =item * $customtitle, alternate text to use instead of $title
4196: in the title box that appears, this text
4197: is not auto translated like the $title is
1.309 albertel 4198:
4199: =item * $notopbar, if true, keep the 'what is this' info but remove the
4200: navigational links
1.317 albertel 4201:
1.338 albertel 4202: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4203:
4204: =item * $notitle, if true keep the nav controls, but remove the title bar
4205:
1.361 albertel 4206: =item * $no_inline_link, if true and in remote mode, don't show the
4207: 'Switch To Inline Menu' link
4208:
1.460 albertel 4209: =item * $args, optional argument valid values are
4210: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4211: inherit_jsmath -> when creating popup window in a page,
4212: should it have jsmath forced on by the
4213: current page
1.460 albertel 4214:
1.112 bowersj2 4215: =back
4216:
1.60 matthew 4217: Returns: A uniform header for LON-CAPA web pages.
4218: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4219: If $bodyonly is undef or zero, an html string containing a <body> tag and
4220: other decorations will be returned.
4221:
4222: =cut
4223:
1.54 www 4224: sub bodytag {
1.309 albertel 4225: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4226: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4227:
1.460 albertel 4228: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4229:
1.183 matthew 4230: $function = &get_users_function() if (!$function);
1.339 albertel 4231: my $img = &designparm($function.'.img',$domain);
4232: my $font = &designparm($function.'.font',$domain);
4233: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4234:
4235: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4236: 'bgcolor' => $pgbg,
1.339 albertel 4237: 'text' => $font,
4238: 'alink' => &designparm($function.'.alink',$domain),
4239: 'vlink' => &designparm($function.'.vlink',$domain),
4240: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4241: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4242:
1.63 www 4243: # role and realm
1.378 raeburn 4244: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4245: if ($role eq 'ca') {
1.479 albertel 4246: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4247: $realm = &plainname($rname,$rdom);
1.378 raeburn 4248: }
1.55 www 4249: # realm
1.258 albertel 4250: if ($env{'request.course.id'}) {
1.378 raeburn 4251: if ($env{'request.role'} !~ /^cr/) {
4252: $role = &Apache::lonnet::plaintext($role,&course_type());
4253: }
1.359 albertel 4254: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4255: } else {
4256: $role = &Apache::lonnet::plaintext($role);
1.54 www 4257: }
1.433 albertel 4258:
1.359 albertel 4259: if (!$realm) { $realm=' '; }
1.55 www 4260: # Set messages
1.60 matthew 4261: my $messages=&domainlogo($domain);
1.330 albertel 4262:
1.438 albertel 4263: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4264:
1.101 www 4265: # construct main body tag
1.359 albertel 4266: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4267: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4268:
1.530 albertel 4269: if ($bodyonly) {
1.60 matthew 4270: return $bodytag;
1.258 albertel 4271: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4272: # Accessibility
1.224 raeburn 4273:
1.337 albertel 4274: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4275: if (!$notitle) {
1.337 albertel 4276: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4277: }
4278: return $bodytag;
1.359 albertel 4279: }
4280:
1.410 albertel 4281: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4282: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4283: undef($role);
1.434 albertel 4284: } else {
4285: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4286: }
1.359 albertel 4287:
4288: my $roleinfo=(<<ENDROLE);
4289: <td class="LC_title_bar_who">
4290: <div class="LC_title_bar_name">
1.410 albertel 4291: $name
1.361 albertel 4292:
1.359 albertel 4293: </div>
4294: <div class="LC_title_bar_role">
1.361 albertel 4295: $role
1.359 albertel 4296: </div>
4297: <div class="LC_title_bar_realm">
1.361 albertel 4298: $realm
1.359 albertel 4299: </div>
1.206 albertel 4300: </td>
4301: ENDROLE
1.235 raeburn 4302:
1.762 bisitz 4303: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4304: if ($customtitle) {
4305: $titleinfo = $customtitle;
4306: }
4307: #
4308: # Extra info if you are the DC
4309: my $dc_info = '';
4310: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4311: $env{'course.'.$env{'request.course.id'}.
4312: '.domain'}.'/'})) {
4313: my $cid = $env{'request.course.id'};
4314: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4315: $dc_info =~ s/\s+$//;
1.359 albertel 4316: $dc_info = '('.$dc_info.')';
4317: }
4318:
1.644 www 4319: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4320: # No Remote
1.258 albertel 4321: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4322: $forcereg=1;
4323: }
4324:
4325: if (!$customtitle && $env{'request.state'} eq 'construct') {
4326: # this is for resources; directories have customtitle, and crumbs
4327: # and select recent are created in lonpubdir.pm
1.229 albertel 4328: my ($uname,$thisdisfn)=
1.258 albertel 4329: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4330: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4331: $formaction=~s/\/+/\//g;
4332:
1.359 albertel 4333: my $parentpath = '';
4334: my $lastitem = '';
4335: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4336: $parentpath = $1;
4337: $lastitem = $2;
4338: } else {
4339: $lastitem = $thisdisfn;
4340: }
4341: $titleinfo =
1.640 bisitz 4342: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4343: .'<b>'.&mt('Construction Space').'</b>: '
4344: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4345: .'" target="_top"><tt><b>'
1.705 tempelho 4346: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4347: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4348: .'</form>'
4349: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4350: }
1.359 albertel 4351:
1.337 albertel 4352: my $titletable;
1.338 albertel 4353: if (!$notitle) {
1.337 albertel 4354: $titletable =
1.359 albertel 4355: '<table id="LC_title_bar">'.
4356: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4357: '</tr></table>';
1.337 albertel 4358: }
1.359 albertel 4359: if ($notopbar) {
4360: $bodytag .= $titletable;
4361: } else {
4362: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4363: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4364: $titletable);
1.272 raeburn 4365: } else {
1.336 albertel 4366: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4367: $titletable;
1.272 raeburn 4368: }
1.235 raeburn 4369: }
4370: return $bodytag;
1.94 www 4371: }
1.95 www 4372:
1.93 www 4373: #
1.95 www 4374: # Top frame rendering, Remote is up
1.93 www 4375: #
1.359 albertel 4376:
1.517 raeburn 4377: my $imgsrc = $img;
4378: if ($img =~ /^\/adm/) {
1.575 albertel 4379: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4380: }
4381: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4382:
1.305 www 4383: # Explicit link to get inline menu
1.361 albertel 4384: my $menu= ($no_inline_link?''
4385: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4386: #
1.338 albertel 4387: if ($notitle) {
1.337 albertel 4388: return $bodytag;
4389: }
1.94 www 4390: return(<<ENDBODY);
1.60 matthew 4391: $bodytag
1.359 albertel 4392: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4393: <tr><td>$upperleft</td>
4394: <td>$messages </td>
1.54 www 4395: </tr>
1.359 albertel 4396: <tr><td>$titleinfo $dc_info $menu</td>
4397: $roleinfo
1.368 albertel 4398: </tr>
1.356 albertel 4399: </table>
1.54 www 4400: ENDBODY
1.182 matthew 4401: }
4402:
1.330 albertel 4403: sub make_attr_string {
4404: my ($register,$attr_ref) = @_;
4405:
4406: if ($attr_ref && !ref($attr_ref)) {
4407: die("addentries Must be a hash ref ".
4408: join(':',caller(1))." ".
4409: join(':',caller(0))." ");
4410: }
4411:
4412: if ($register) {
1.339 albertel 4413: my ($on_load,$on_unload);
4414: foreach my $key (keys(%{$attr_ref})) {
4415: if (lc($key) eq 'onload') {
4416: $on_load.=$attr_ref->{$key}.';';
4417: delete($attr_ref->{$key});
4418:
4419: } elsif (lc($key) eq 'onunload') {
4420: $on_unload.=$attr_ref->{$key}.';';
4421: delete($attr_ref->{$key});
4422: }
4423: }
4424: $attr_ref->{'onload'} =
4425: &Apache::lonmenu::loadevents(). $on_load;
4426: $attr_ref->{'onunload'}=
4427: &Apache::lonmenu::unloadevents().$on_unload;
4428: }
4429:
4430: # Accessibility font enhance
4431: if ($env{'browser.fontenhance'} eq 'on') {
4432: my $style;
4433: foreach my $key (keys(%{$attr_ref})) {
4434: if (lc($key) eq 'style') {
4435: $style.=$attr_ref->{$key}.';';
4436: delete($attr_ref->{$key});
4437: }
4438: }
4439: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4440: }
1.339 albertel 4441:
4442: if ($env{'browser.blackwhite'} eq 'on') {
4443: delete($attr_ref->{'font'});
4444: delete($attr_ref->{'link'});
4445: delete($attr_ref->{'alink'});
4446: delete($attr_ref->{'vlink'});
4447: delete($attr_ref->{'bgcolor'});
4448: delete($attr_ref->{'background'});
4449: }
4450:
1.330 albertel 4451: my $attr_string;
4452: foreach my $attr (keys(%$attr_ref)) {
4453: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4454: }
4455: return $attr_string;
4456: }
4457:
4458:
1.182 matthew 4459: ###############################################
1.251 albertel 4460: ###############################################
4461:
4462: =pod
4463:
4464: =item * &endbodytag()
4465:
4466: Returns a uniform footer for LON-CAPA web pages.
4467:
1.635 raeburn 4468: Inputs: 1 - optional reference to an args hash
4469: If in the hash, key for noredirectlink has a value which evaluates to true,
4470: a 'Continue' link is not displayed if the page contains an
4471: internal redirect in the <head></head> section,
4472: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4473:
4474: =cut
4475:
4476: sub endbodytag {
1.635 raeburn 4477: my ($args) = @_;
1.251 albertel 4478: my $endbodytag='</body>';
1.269 albertel 4479: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4480: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4481: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4482: $endbodytag=
4483: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4484: &mt('Continue').'</a>'.
4485: $endbodytag;
4486: }
1.315 albertel 4487: }
1.251 albertel 4488: return $endbodytag;
4489: }
4490:
1.352 albertel 4491: =pod
4492:
4493: =item * &standard_css()
4494:
4495: Returns a style sheet
4496:
4497: Inputs: (all optional)
4498: domain -> force to color decorate a page for a specific
4499: domain
4500: function -> force usage of a specific rolish color scheme
4501: bgcolor -> override the default page bgcolor
4502:
4503: =cut
4504:
1.343 albertel 4505: sub standard_css {
1.345 albertel 4506: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4507: $function = &get_users_function() if (!$function);
4508: my $img = &designparm($function.'.img', $domain);
4509: my $tabbg = &designparm($function.'.tabbg', $domain);
4510: my $font = &designparm($function.'.font', $domain);
1.791 tempelho 4511: #second colour for later usage
1.345 albertel 4512: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4513: my $pgbg_or_bgcolor =
4514: $bgcolor ||
1.352 albertel 4515: &designparm($function.'.pgbg', $domain);
1.382 albertel 4516: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4517: my $alink = &designparm($function.'.alink', $domain);
4518: my $vlink = &designparm($function.'.vlink', $domain);
4519: my $link = &designparm($function.'.link', $domain);
4520:
1.704 muellerd 4521: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4522: my $bgcol = &designparm('login.bgcol',$domain);
4523: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4524:
1.602 albertel 4525: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4526: my $mono = 'monospace';
1.352 albertel 4527: my $data_table_head = $tabbg;
4528: my $data_table_light = '#EEEEEE';
1.470 banghart 4529: my $data_table_dark = '#DDDDDD';
4530: my $data_table_darker = '#CCCCCC';
1.349 albertel 4531: my $data_table_highlight = '#FFFF00';
1.352 albertel 4532: my $mail_new = '#FFBB77';
4533: my $mail_new_hover = '#DD9955';
4534: my $mail_read = '#BBBB77';
4535: my $mail_read_hover = '#999944';
4536: my $mail_replied = '#AAAA88';
4537: my $mail_replied_hover = '#888855';
4538: my $mail_other = '#99BBBB';
4539: my $mail_other_hover = '#669999';
1.391 albertel 4540: my $table_header = '#DDDDDD';
1.489 raeburn 4541: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4542: my $lg_border_color = '#C8C8C8';
1.392 albertel 4543:
1.608 albertel 4544: my $border = ($env{'browser.type'} eq 'explorer' ||
4545: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4546: : '0px 3px 0px 4px';
1.448 albertel 4547:
1.523 albertel 4548:
1.343 albertel 4549: return <<END;
1.795 www 4550: body {
4551: font-family: $sans;
4552: line-height:130%;
4553: font-size:0.83em;
4554: color:$font;
4555: }
4556:
4557: a:link, a:visited {
4558: font-size:100%;
4559: }
4560:
4561: a:focus {
4562: color: red;
4563: background: yellow
4564: }
1.698 harmsja 4565:
1.510 albertel 4566: table.thinborder,
4567: table.thinborder tr th {
4568: border-style: solid;
4569: border-width: 1px;
1.698 harmsja 4570: border-color: $lg_border_color;
1.510 albertel 4571: background: $tabbg;
4572: }
1.795 www 4573:
1.523 albertel 4574: table.thinborder tr td {
1.510 albertel 4575: border-style: solid;
1.698 harmsja 4576: border-width: 1px;
4577: border-color: $lg_border_color;
1.510 albertel 4578: }
1.426 albertel 4579:
1.795 www 4580: form, .inline {
4581: display: inline;
4582: }
1.721 harmsja 4583:
1.795 www 4584: .LC_right {
4585: text-align:right;
4586: }
4587:
4588: .LC_middle {
4589: vertical-align:middle;
4590: }
1.721 harmsja 4591:
4592: /* just for tests */
1.754 droeschl 4593: .LC_400Box {width:400px; }
1.721 harmsja 4594: /* end */
4595:
1.778 bisitz 4596: .LC_filename {
4597: font-family: $mono;
4598: white-space:pre;
4599: }
4600:
4601: .LC_fileicon {
4602: border: none;
4603: height: 1.3em;
4604: vertical-align: text-bottom;
4605: margin-right: 0.3em;
4606: text-decoration:none;
4607: }
4608:
1.350 albertel 4609: .LC_error {
4610: color: red;
4611: font-size: larger;
4612: }
1.795 www 4613:
1.457 albertel 4614: .LC_warning,
4615: .LC_diff_removed {
1.733 bisitz 4616: color: red;
1.394 albertel 4617: }
1.532 albertel 4618:
4619: .LC_info,
1.457 albertel 4620: .LC_success,
4621: .LC_diff_added {
1.350 albertel 4622: color: green;
4623: }
1.795 www 4624:
1.543 albertel 4625: .LC_unknown {
4626: color: yellow;
4627: }
4628:
1.440 albertel 4629: .LC_icon {
1.771 droeschl 4630: border: none;
1.790 droeschl 4631: vertical-align: middle;
1.771 droeschl 4632: }
4633:
1.539 albertel 4634: .LC_indexer_icon {
4635: border: 0px;
4636: height: 22px;
4637: }
1.795 www 4638:
1.543 albertel 4639: .LC_docs_spacer {
4640: width: 25px;
4641: height: 1px;
1.771 droeschl 4642: border: none;
1.543 albertel 4643: }
1.346 albertel 4644:
1.532 albertel 4645: .LC_internal_info {
1.735 bisitz 4646: color: #999999;
1.532 albertel 4647: }
4648:
1.794 www 4649: .LC_discussion {
4650: background: $tabbg;
4651: border: 1px solid black;
4652: margin: 2px;
4653: }
4654:
4655: .LC_disc_action_links_bar {
4656: background: $tabbg;
4657: font-family: $sans;
4658: border: 0px;
1.795 www 4659: margin: 4px;
1.794 www 4660: }
4661:
4662: .LC_disc_action_left {
4663: text-align: left;
4664: }
4665:
4666: .LC_disc_action_right {
4667: text-align: right;
4668: }
4669:
4670: .LC_disc_new_item {
4671: background: white;
4672: border: 2px solid red;
4673: margin: 2px;
4674: }
4675:
4676: .LC_disc_old_item {
4677: background: white;
4678: border: 1px solid black;
4679: margin: 2px;
4680: }
4681:
1.458 albertel 4682: table.LC_pastsubmission {
4683: border: 1px solid black;
4684: margin: 2px;
4685: }
4686:
1.795 www 4687: table#LC_top_nav,
4688: table#LC_menubuttons,
4689: table#LC_nav_location {
1.345 albertel 4690: width: 100%;
4691: background: $pgbg;
1.392 albertel 4692: border: 2px;
1.402 albertel 4693: border-collapse: separate;
1.403 albertel 4694: padding: 0px;
1.345 albertel 4695: }
1.392 albertel 4696:
1.795 www 4697: table#LC_title_bar,
4698: table.LC_breadcrumbs,
1.393 albertel 4699: table#LC_title_bar.LC_with_remote {
1.359 albertel 4700: width: 100%;
1.392 albertel 4701: border-color: $pgbg;
4702: border-style: solid;
4703: border-width: $border;
1.379 albertel 4704: background: $pgbg;
4705: font-family: $sans;
1.392 albertel 4706: border-collapse: collapse;
1.403 albertel 4707: padding: 0px;
1.359 albertel 4708: }
1.795 www 4709:
1.409 albertel 4710: table.LC_docs_path {
4711: width: 100%;
4712: border: 0;
4713: background: $pgbg;
4714: font-family: $sans;
4715: border-collapse: collapse;
4716: padding: 0px;
4717: }
4718:
1.359 albertel 4719: table#LC_title_bar td {
4720: background: $tabbg;
4721: }
1.795 www 4722:
1.773 ehlerst 4723: table#LC_title_bar .LC_title_bar_who {
1.359 albertel 4724: background: $tabbg;
4725: color: $font;
1.427 albertel 4726: font: small $sans;
1.359 albertel 4727: text-align: right;
1.773 ehlerst 4728: margin: 0px;
4729: }
1.795 www 4730:
1.773 ehlerst 4731: table#LC_title_bar .LC_title_bar_name {
4732: margin: 0px;
4733: }
1.795 www 4734:
1.773 ehlerst 4735: table#LC_title_bar .LC_title_bar_role {
4736: margin: 0px;
4737: }
1.795 www 4738:
1.775 bisitz 4739: table#LC_title_bar .LC_title_bar_realm {
1.773 ehlerst 4740: margin: 0px;
1.359 albertel 4741: }
1.795 www 4742:
1.469 banghart 4743: span.LC_metadata {
1.795 www 4744: font-family: $sans;
1.469 banghart 4745: }
1.359 albertel 4746:
1.706 harmsja 4747: table#LC_menubuttons img{
1.346 albertel 4748: border: 0px;
4749: }
1.795 www 4750:
1.345 albertel 4751: table#LC_top_nav td {
4752: background: $tabbg;
1.392 albertel 4753: border: 0px;
1.407 albertel 4754: font-size: small;
1.706 harmsja 4755: vertical-align:top;
4756: padding:2px 5px 2px 5px;
1.345 albertel 4757: }
1.795 www 4758:
4759: table#LC_top_nav td a,
4760: div#LC_top_nav a {
1.345 albertel 4761: color: $font;
4762: font-family: $sans;
4763: }
1.795 www 4764:
1.364 albertel 4765: table#LC_top_nav td.LC_top_nav_logo {
4766: background: $tabbg;
1.432 albertel 4767: text-align: left;
1.408 albertel 4768: white-space: nowrap;
1.432 albertel 4769: width: 31px;
1.408 albertel 4770: }
1.795 www 4771:
1.408 albertel 4772: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4773: border: 0px;
1.408 albertel 4774: vertical-align: bottom;
1.364 albertel 4775: }
1.795 www 4776:
1.777 tempelho 4777: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4778: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4779: width: 2.0em;
4780: }
1.795 www 4781:
1.442 albertel 4782: table#LC_top_nav td.LC_top_nav_login {
4783: width: 4.0em;
4784: text-align: center;
4785: }
1.795 www 4786:
4787: table.LC_breadcrumbs td,
4788: table.LC_docs_path td {
1.357 albertel 4789: background: $tabbg;
4790: color: $font;
4791: font-family: $sans;
1.358 albertel 4792: font-size: smaller;
1.357 albertel 4793: }
1.795 www 4794:
1.777 tempelho 4795: table.LC_breadcrumbs td.LC_breadcrumbs_component,
4796: table.LC_docs_path td.LC_docs_path_component {
1.779 bisitz 4797: background: $tabbg;
1.777 tempelho 4798: color: $font;
4799: font-family: $sans;
1.779 bisitz 4800: font-size: larger;
4801: text-align: right;
1.777 tempelho 4802: }
1.795 www 4803:
1.383 albertel 4804: td.LC_table_cell_checkbox {
4805: text-align: center;
4806: }
1.795 www 4807:
1.779 bisitz 4808: table#LC_mainmenu td.LC_mainmenu_column {
4809: vertical-align: top;
1.777 tempelho 4810: }
1.522 albertel 4811:
1.795 www 4812: .LC_fontsize_small {
1.705 tempelho 4813: font-size: 70%;
4814: }
4815:
1.795 www 4816: .LC_fontsize_medium {
1.705 tempelho 4817: font-size: 85%;
4818: }
4819:
1.795 www 4820: .LC_fontsize_large {
1.705 tempelho 4821: font-size: 120%;
4822: }
4823:
1.346 albertel 4824: .LC_menubuttons_inline_text {
4825: color: $font;
4826: font-family: $sans;
1.698 harmsja 4827: font-size: 90%;
1.701 harmsja 4828: padding-left:3px;
1.346 albertel 4829: }
4830:
1.526 www 4831: .LC_menubuttons_link {
4832: text-decoration: none;
4833: }
1.795 www 4834:
1.522 albertel 4835: .LC_menubuttons_category {
1.521 www 4836: color: $font;
1.526 www 4837: background: $pgbg;
1.521 www 4838: font-family: $sans;
4839: font-size: larger;
4840: font-weight: bold;
4841: }
4842:
1.346 albertel 4843: td.LC_menubuttons_text {
1.779 bisitz 4844: color: $font;
1.346 albertel 4845: }
1.706 harmsja 4846:
1.346 albertel 4847: .LC_current_location {
4848: font-family: $sans;
4849: background: $tabbg;
4850: }
1.795 www 4851:
1.346 albertel 4852: .LC_new_mail {
4853: font-family: $sans;
1.634 www 4854: background: $tabbg;
1.346 albertel 4855: font-weight: bold;
4856: }
1.347 albertel 4857:
1.527 www 4858: .LC_dropadd_labeltext {
4859: font-family: $sans;
4860: text-align: right;
4861: }
4862:
4863: .LC_preferences_labeltext {
4864: font-family: $sans;
4865: text-align: right;
4866: }
4867:
1.666 raeburn 4868: .LC_roleslog_note {
1.701 harmsja 4869: font-size: small;
1.666 raeburn 4870: }
4871:
1.715 raeburn 4872: .LC_mail_functions {
4873: font-weight: bold;
4874: }
4875:
1.440 albertel 4876: table.LC_aboutme_port {
4877: border: 0px;
4878: border-collapse: collapse;
4879: border-spacing: 0px;
4880: }
1.795 www 4881:
4882: table.LC_data_table,
4883: table.LC_mail_list {
1.347 albertel 4884: border: 1px solid #000000;
1.402 albertel 4885: border-collapse: separate;
1.426 albertel 4886: border-spacing: 1px;
1.610 albertel 4887: background: $pgbg;
1.347 albertel 4888: }
1.795 www 4889:
1.422 albertel 4890: .LC_data_table_dense {
4891: font-size: small;
4892: }
1.795 www 4893:
1.507 raeburn 4894: table.LC_nested_outer {
4895: border: 1px solid #000000;
1.589 raeburn 4896: border-collapse: collapse;
1.507 raeburn 4897: border-spacing: 0px;
4898: width: 100%;
4899: }
1.795 www 4900:
1.507 raeburn 4901: table.LC_nested {
4902: border: 0px;
1.589 raeburn 4903: border-collapse: collapse;
1.507 raeburn 4904: border-spacing: 0px;
4905: width: 100%;
4906: }
1.795 www 4907:
4908: table.LC_data_table tr th,
4909: table.LC_calendar tr th,
4910: table.LC_mail_list tr th,
1.523 albertel 4911: table.LC_prior_tries tr th {
1.349 albertel 4912: font-weight: bold;
4913: background-color: $data_table_head;
1.701 harmsja 4914: font-size:90%;
1.347 albertel 4915: }
1.795 www 4916:
1.711 raeburn 4917: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4918: background-color: #CCCCCC;
1.711 raeburn 4919: font-weight: bold;
4920: text-align: left;
4921: }
1.795 www 4922:
1.779 bisitz 4923: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4924: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4925: table.LC_aboutme_port tr td {
1.349 albertel 4926: background-color: $data_table_light;
1.425 albertel 4927: padding: 2px;
1.347 albertel 4928: }
1.795 www 4929:
1.610 albertel 4930: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4931: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4932: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4933: background-color: $data_table_dark;
1.709 bisitz 4934: padding: 2px;
1.347 albertel 4935: }
1.795 www 4936:
1.425 albertel 4937: table.LC_data_table tr.LC_data_table_highlight td {
4938: background-color: $data_table_darker;
4939: }
1.795 www 4940:
1.639 raeburn 4941: table.LC_data_table tr td.LC_leftcol_header {
4942: background-color: $data_table_head;
4943: font-weight: bold;
4944: }
1.795 www 4945:
1.451 albertel 4946: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4947: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4948: background-color: #FFFFFF;
1.421 albertel 4949: font-weight: bold;
4950: font-style: italic;
4951: text-align: center;
4952: padding: 8px;
1.347 albertel 4953: }
1.795 www 4954:
1.507 raeburn 4955: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4956: padding: 4ex
4957: }
1.795 www 4958:
1.507 raeburn 4959: table.LC_nested_outer tr th {
4960: font-weight: bold;
4961: background-color: $data_table_head;
1.701 harmsja 4962: font-size: small;
1.507 raeburn 4963: border-bottom: 1px solid #000000;
4964: }
1.795 www 4965:
1.507 raeburn 4966: table.LC_nested_outer tr td.LC_subheader {
4967: background-color: $data_table_head;
4968: font-weight: bold;
4969: font-size: small;
4970: border-bottom: 1px solid #000000;
4971: text-align: right;
1.451 albertel 4972: }
1.795 www 4973:
1.507 raeburn 4974: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4975: background-color: #CCCCCC;
1.451 albertel 4976: font-weight: bold;
4977: font-size: small;
1.507 raeburn 4978: text-align: center;
4979: }
1.795 www 4980:
1.589 raeburn 4981: table.LC_nested tr.LC_info_row td.LC_left_item,
4982: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4983: text-align: left;
1.451 albertel 4984: }
1.795 www 4985:
1.507 raeburn 4986: table.LC_nested td {
1.735 bisitz 4987: background-color: #FFFFFF;
1.451 albertel 4988: font-size: small;
1.507 raeburn 4989: }
1.795 www 4990:
1.507 raeburn 4991: table.LC_nested_outer tr th.LC_right_item,
4992: table.LC_nested tr.LC_info_row td.LC_right_item,
4993: table.LC_nested tr.LC_odd_row td.LC_right_item,
4994: table.LC_nested tr td.LC_right_item {
1.451 albertel 4995: text-align: right;
4996: }
4997:
1.507 raeburn 4998: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4999: background-color: #EEEEEE;
1.451 albertel 5000: }
5001:
1.473 raeburn 5002: table.LC_createuser {
5003: }
5004:
5005: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5006: font-size: small;
1.473 raeburn 5007: }
5008:
5009: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5010: background-color: #CCCCCC;
1.473 raeburn 5011: font-weight: bold;
5012: text-align: center;
5013: }
5014:
1.349 albertel 5015: table.LC_calendar {
5016: border: 1px solid #000000;
5017: border-collapse: collapse;
5018: }
1.795 www 5019:
1.349 albertel 5020: table.LC_calendar_pickdate {
5021: font-size: xx-small;
5022: }
1.795 www 5023:
1.349 albertel 5024: table.LC_calendar tr td {
5025: border: 1px solid #000000;
5026: vertical-align: top;
5027: }
1.795 www 5028:
1.349 albertel 5029: table.LC_calendar tr td.LC_calendar_day_empty {
5030: background-color: $data_table_dark;
5031: }
1.795 www 5032:
1.779 bisitz 5033: table.LC_calendar tr td.LC_calendar_day_current {
5034: background-color: $data_table_highlight;
1.777 tempelho 5035: }
1.795 www 5036:
1.349 albertel 5037: table.LC_mail_list tr.LC_mail_new {
5038: background-color: $mail_new;
5039: }
1.795 www 5040:
1.349 albertel 5041: table.LC_mail_list tr.LC_mail_new:hover {
5042: background-color: $mail_new_hover;
5043: }
1.795 www 5044:
5045: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5046: }
1.795 www 5047:
5048: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5049: }
1.795 www 5050:
1.349 albertel 5051: table.LC_mail_list tr.LC_mail_read {
5052: background-color: $mail_read;
5053: }
1.795 www 5054:
1.349 albertel 5055: table.LC_mail_list tr.LC_mail_read:hover {
5056: background-color: $mail_read_hover;
5057: }
1.795 www 5058:
1.349 albertel 5059: table.LC_mail_list tr.LC_mail_replied {
5060: background-color: $mail_replied;
5061: }
1.795 www 5062:
1.349 albertel 5063: table.LC_mail_list tr.LC_mail_replied:hover {
5064: background-color: $mail_replied_hover;
5065: }
1.795 www 5066:
1.349 albertel 5067: table.LC_mail_list tr.LC_mail_other {
5068: background-color: $mail_other;
5069: }
1.795 www 5070:
1.349 albertel 5071: table.LC_mail_list tr.LC_mail_other:hover {
5072: background-color: $mail_other_hover;
5073: }
1.494 raeburn 5074:
1.777 tempelho 5075: table.LC_data_table tr > td.LC_browser_file,
5076: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 5077: background: #CCFF88;
5078: }
1.795 www 5079:
1.777 tempelho 5080: table.LC_data_table tr > td.LC_browser_file_locked,
5081: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5082: background: #FFAA99;
1.387 albertel 5083: }
1.795 www 5084:
1.777 tempelho 5085: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779 bisitz 5086: background: #AAAAAA;
5087: }
1.795 www 5088:
1.777 tempelho 5089: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5090: table.LC_data_table tr > td.LC_browser_file_metamodified {
5091: background: #FFFF77;
1.777 tempelho 5092: }
1.795 www 5093:
1.696 bisitz 5094: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 5095: background: #CCCCFF;
1.387 albertel 5096: }
1.696 bisitz 5097:
1.707 bisitz 5098: table.LC_data_table tr > td.LC_roles_is {
5099: /* background: #77FF77; */
5100: }
1.795 www 5101:
1.707 bisitz 5102: table.LC_data_table tr > td.LC_roles_future {
5103: background: #FFFF77;
5104: }
1.795 www 5105:
1.707 bisitz 5106: table.LC_data_table tr > td.LC_roles_will {
5107: background: #FFAA77;
5108: }
1.795 www 5109:
1.707 bisitz 5110: table.LC_data_table tr > td.LC_roles_expired {
5111: background: #FF7777;
5112: }
1.795 www 5113:
1.707 bisitz 5114: table.LC_data_table tr > td.LC_roles_will_not {
5115: background: #AAFF77;
5116: }
1.795 www 5117:
1.707 bisitz 5118: table.LC_data_table tr > td.LC_roles_selected {
5119: background: #11CC55;
5120: }
5121:
1.388 albertel 5122: span.LC_current_location {
1.701 harmsja 5123: font-size:larger;
1.388 albertel 5124: background: $pgbg;
5125: }
1.387 albertel 5126:
1.395 albertel 5127: span.LC_parm_menu_item {
5128: font-size: larger;
5129: font-family: $sans;
5130: }
1.795 www 5131:
1.395 albertel 5132: span.LC_parm_scope_all {
5133: color: red;
5134: }
1.795 www 5135:
1.395 albertel 5136: span.LC_parm_scope_folder {
5137: color: green;
5138: }
1.795 www 5139:
1.395 albertel 5140: span.LC_parm_scope_resource {
5141: color: orange;
5142: }
1.795 www 5143:
1.395 albertel 5144: span.LC_parm_part {
5145: color: blue;
5146: }
1.795 www 5147:
1.395 albertel 5148: span.LC_parm_folder, span.LC_parm_symb {
5149: font-size: x-small;
5150: font-family: $mono;
5151: color: #AAAAAA;
5152: }
5153:
1.795 www 5154: td.LC_parm_overview_level_menu,
5155: td.LC_parm_overview_map_menu,
5156: td.LC_parm_overview_parm_selectors,
5157: td.LC_parm_overview_restrictions {
1.396 albertel 5158: border: 1px solid black;
5159: border-collapse: collapse;
5160: }
1.795 www 5161:
1.396 albertel 5162: table.LC_parm_overview_restrictions td {
5163: border-width: 1px 4px 1px 4px;
5164: border-style: solid;
5165: border-color: $pgbg;
5166: text-align: center;
5167: }
1.795 www 5168:
1.396 albertel 5169: table.LC_parm_overview_restrictions th {
5170: background: $tabbg;
5171: border-width: 1px 4px 1px 4px;
5172: border-style: solid;
5173: border-color: $pgbg;
5174: }
1.795 www 5175:
1.398 albertel 5176: table#LC_helpmenu {
5177: border: 0px;
5178: height: 55px;
5179: border-spacing: 0px;
5180: }
5181:
5182: table#LC_helpmenu fieldset legend {
5183: font-size: larger;
5184: font-weight: bold;
5185: }
1.795 www 5186:
1.397 albertel 5187: table#LC_helpmenu_links {
5188: width: 100%;
5189: border: 1px solid black;
5190: background: $pgbg;
5191: padding: 0px;
5192: border-spacing: 1px;
5193: }
1.795 www 5194:
1.397 albertel 5195: table#LC_helpmenu_links tr td {
5196: padding: 1px;
5197: background: $tabbg;
1.399 albertel 5198: text-align: center;
5199: font-weight: bold;
1.397 albertel 5200: }
1.396 albertel 5201:
1.795 www 5202: table#LC_helpmenu_links a:link,
5203: table#LC_helpmenu_links a:visited,
1.397 albertel 5204: table#LC_helpmenu_links a:active {
5205: text-decoration: none;
5206: color: $font;
5207: }
1.795 www 5208:
1.397 albertel 5209: table#LC_helpmenu_links a:hover {
5210: text-decoration: underline;
5211: color: $vlink;
5212: }
1.396 albertel 5213:
1.417 albertel 5214: .LC_chrt_popup_exists {
5215: border: 1px solid #339933;
5216: margin: -1px;
5217: }
1.795 www 5218:
1.417 albertel 5219: .LC_chrt_popup_up {
5220: border: 1px solid yellow;
5221: margin: -1px;
5222: }
1.795 www 5223:
1.417 albertel 5224: .LC_chrt_popup {
5225: border: 1px solid #8888FF;
5226: background: #CCCCFF;
5227: }
1.795 www 5228:
1.421 albertel 5229: table.LC_pick_box {
5230: border-collapse: separate;
5231: background: white;
5232: border: 1px solid black;
5233: border-spacing: 1px;
5234: }
1.795 www 5235:
1.421 albertel 5236: table.LC_pick_box td.LC_pick_box_title {
5237: background: $tabbg;
5238: font-weight: bold;
5239: text-align: right;
1.740 bisitz 5240: vertical-align: top;
1.421 albertel 5241: width: 184px;
5242: padding: 8px;
5243: }
1.795 www 5244:
1.645 raeburn 5245: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5246: background: $tabbg;
5247: font-weight: bold;
5248: text-align: right;
5249: width: 350px;
5250: padding: 8px;
5251: }
5252:
1.579 raeburn 5253: table.LC_pick_box td.LC_pick_box_value {
5254: text-align: left;
5255: padding: 8px;
5256: }
1.795 www 5257:
1.579 raeburn 5258: table.LC_pick_box td.LC_pick_box_select {
5259: text-align: left;
5260: padding: 8px;
5261: }
1.795 www 5262:
1.424 albertel 5263: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5264: padding: 0px;
5265: height: 1px;
5266: background: black;
5267: }
1.795 www 5268:
1.421 albertel 5269: table.LC_pick_box td.LC_pick_box_submit {
5270: text-align: right;
5271: }
1.795 www 5272:
1.579 raeburn 5273: table.LC_pick_box td.LC_evenrow_value {
5274: text-align: left;
5275: padding: 8px;
5276: background-color: $data_table_light;
5277: }
1.795 www 5278:
1.579 raeburn 5279: table.LC_pick_box td.LC_oddrow_value {
5280: text-align: left;
5281: padding: 8px;
5282: background-color: $data_table_light;
5283: }
1.795 www 5284:
1.579 raeburn 5285: table.LC_helpform_receipt {
5286: width: 620px;
5287: border-collapse: separate;
5288: background: white;
5289: border: 1px solid black;
5290: border-spacing: 1px;
5291: }
1.795 www 5292:
1.579 raeburn 5293: table.LC_helpform_receipt td.LC_pick_box_title {
5294: background: $tabbg;
5295: font-weight: bold;
5296: text-align: right;
5297: width: 184px;
5298: padding: 8px;
5299: }
1.795 www 5300:
1.579 raeburn 5301: table.LC_helpform_receipt td.LC_evenrow_value {
5302: text-align: left;
5303: padding: 8px;
5304: background-color: $data_table_light;
5305: }
1.795 www 5306:
1.579 raeburn 5307: table.LC_helpform_receipt td.LC_oddrow_value {
5308: text-align: left;
5309: padding: 8px;
5310: background-color: $data_table_light;
5311: }
1.795 www 5312:
1.579 raeburn 5313: table.LC_helpform_receipt td.LC_pick_box_separator {
5314: padding: 0px;
5315: height: 1px;
5316: background: black;
5317: }
1.795 www 5318:
1.579 raeburn 5319: span.LC_helpform_receipt_cat {
5320: font-weight: bold;
5321: }
1.795 www 5322:
1.424 albertel 5323: table.LC_group_priv_box {
5324: background: white;
5325: border: 1px solid black;
5326: border-spacing: 1px;
5327: }
1.795 www 5328:
1.424 albertel 5329: table.LC_group_priv_box td.LC_pick_box_title {
5330: background: $tabbg;
5331: font-weight: bold;
5332: text-align: right;
5333: width: 184px;
5334: }
1.795 www 5335:
1.424 albertel 5336: table.LC_group_priv_box td.LC_groups_fixed {
5337: background: $data_table_light;
5338: text-align: center;
5339: }
1.795 www 5340:
1.424 albertel 5341: table.LC_group_priv_box td.LC_groups_optional {
5342: background: $data_table_dark;
5343: text-align: center;
5344: }
1.795 www 5345:
1.424 albertel 5346: table.LC_group_priv_box td.LC_groups_functionality {
5347: background: $data_table_darker;
5348: text-align: center;
5349: font-weight: bold;
5350: }
1.795 www 5351:
1.424 albertel 5352: table.LC_group_priv td {
5353: text-align: left;
5354: padding: 0px;
5355: }
5356:
1.421 albertel 5357: table.LC_notify_front_page {
5358: background: white;
5359: border: 1px solid black;
5360: padding: 8px;
5361: }
1.795 www 5362:
1.421 albertel 5363: table.LC_notify_front_page td {
5364: padding: 8px;
5365: }
1.795 www 5366:
1.424 albertel 5367: .LC_navbuttons {
5368: margin: 2ex 0ex 2ex 0ex;
5369: }
1.795 www 5370:
1.423 albertel 5371: .LC_topic_bar {
5372: font-family: $sans;
5373: font-weight: bold;
5374: width: 100%;
5375: background: $tabbg;
5376: vertical-align: middle;
5377: margin: 2ex 0ex 2ex 0ex;
5378: }
1.795 www 5379:
1.423 albertel 5380: .LC_topic_bar span {
5381: vertical-align: middle;
5382: }
1.795 www 5383:
1.423 albertel 5384: .LC_topic_bar img {
5385: vertical-align: bottom;
5386: }
1.795 www 5387:
1.423 albertel 5388: table.LC_course_group_status {
5389: margin: 20px;
5390: }
1.795 www 5391:
1.423 albertel 5392: table.LC_status_selector td {
5393: vertical-align: top;
5394: text-align: center;
1.424 albertel 5395: padding: 4px;
5396: }
1.795 www 5397:
1.424 albertel 5398: table.LC_descriptive_input td.LC_description {
5399: vertical-align: top;
5400: text-align: right;
5401: font-weight: bold;
1.423 albertel 5402: }
1.795 www 5403:
1.599 albertel 5404: div.LC_feedback_link {
1.616 albertel 5405: clear: both;
1.599 albertel 5406: background: white;
1.779 bisitz 5407: width: 100%;
1.489 raeburn 5408: }
1.795 www 5409:
1.489 raeburn 5410: span.LC_feedback_link {
1.599 albertel 5411: background: $feedback_link_bg;
5412: font-size: larger;
5413: }
1.795 www 5414:
1.599 albertel 5415: span.LC_message_link {
5416: background: $feedback_link_bg;
5417: font-size: larger;
5418: position: absolute;
5419: right: 1em;
1.489 raeburn 5420: }
1.421 albertel 5421:
1.515 albertel 5422: table.LC_prior_tries {
1.524 albertel 5423: border: 1px solid #000000;
5424: border-collapse: separate;
5425: border-spacing: 1px;
1.515 albertel 5426: }
1.523 albertel 5427:
1.515 albertel 5428: table.LC_prior_tries td {
1.524 albertel 5429: padding: 2px;
1.515 albertel 5430: }
1.523 albertel 5431:
5432: .LC_answer_correct {
1.795 www 5433: background: lightgreen;
5434: font-family: $sans;
5435: color: darkgreen;
5436: padding: 6px;
1.523 albertel 5437: }
1.795 www 5438:
1.523 albertel 5439: .LC_answer_charged_try {
1.797 ! www 5440: background: #FFAAAA;
1.795 www 5441: font-family: $sans;
5442: color: darkred;
5443: padding: 6px;
1.523 albertel 5444: }
1.795 www 5445:
1.779 bisitz 5446: .LC_answer_not_charged_try,
1.523 albertel 5447: .LC_answer_no_grade,
5448: .LC_answer_late {
1.795 www 5449: background: lightyellow;
5450: font-family: $sans;
1.523 albertel 5451: color: black;
1.795 www 5452: padding: 6px;
1.523 albertel 5453: }
1.795 www 5454:
1.523 albertel 5455: .LC_answer_previous {
1.795 www 5456: background: lightblue;
5457: font-family: $sans;
5458: color: darkblue;
5459: padding: 6px;
1.523 albertel 5460: }
1.795 www 5461:
1.779 bisitz 5462: .LC_answer_no_message {
1.777 tempelho 5463: background: #FFFFFF;
1.795 www 5464: font-family: $sans;
1.777 tempelho 5465: color: black;
1.795 www 5466: padding: 6px;
1.779 bisitz 5467: }
1.795 www 5468:
1.779 bisitz 5469: .LC_answer_unknown {
5470: background: orange;
1.795 www 5471: font-family: $sans;
1.779 bisitz 5472: color: black;
1.795 www 5473: padding: 6px;
1.777 tempelho 5474: }
1.795 www 5475:
1.529 albertel 5476: span.LC_prior_numerical,
5477: span.LC_prior_string,
5478: span.LC_prior_custom,
5479: span.LC_prior_reaction,
5480: span.LC_prior_math {
1.523 albertel 5481: font-family: monospace;
5482: white-space: pre;
5483: }
5484:
1.525 albertel 5485: span.LC_prior_string {
5486: font-family: monospace;
5487: white-space: pre;
5488: }
5489:
1.523 albertel 5490: table.LC_prior_option {
5491: width: 100%;
5492: border-collapse: collapse;
5493: }
1.795 www 5494:
5495: table.LC_prior_rank,
5496: table.LC_prior_match {
1.528 albertel 5497: border-collapse: collapse;
5498: }
1.795 www 5499:
1.528 albertel 5500: table.LC_prior_option tr td,
5501: table.LC_prior_rank tr td,
5502: table.LC_prior_match tr td {
1.524 albertel 5503: border: 1px solid #000000;
1.515 albertel 5504: }
5505:
1.770 droeschl 5506: td.LC_nobreak,
1.519 raeburn 5507: span.LC_nobreak {
1.544 albertel 5508: white-space: nowrap;
1.519 raeburn 5509: }
5510:
1.576 raeburn 5511: span.LC_cusr_emph {
5512: font-style: italic;
5513: }
5514:
1.633 raeburn 5515: span.LC_cusr_subheading {
5516: font-weight: normal;
5517: font-size: 85%;
5518: }
5519:
1.545 albertel 5520: table.LC_docs_documents {
5521: background: #BBBBBB;
1.547 albertel 5522: border-width: 0px;
1.545 albertel 5523: border-collapse: collapse;
5524: }
1.795 www 5525:
1.777 tempelho 5526: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5527: border: 2px solid black;
5528: padding: 4px;
1.777 tempelho 5529: }
1.795 www 5530:
1.545 albertel 5531: .LC_docs_entry_move {
5532: border: 0px;
5533: border-collapse: collapse;
1.544 albertel 5534: }
5535:
1.545 albertel 5536: .LC_docs_entry_move td {
5537: border: 2px solid #BBBBBB;
5538: background: #DDDDDD;
5539: }
5540:
5541: .LC_docs_editor td.LC_docs_entry_commands {
5542: background: #DDDDDD;
5543: font-size: x-small;
5544: }
1.795 www 5545:
1.544 albertel 5546: .LC_docs_copy {
1.545 albertel 5547: color: #000099;
1.544 albertel 5548: }
1.795 www 5549:
1.544 albertel 5550: .LC_docs_cut {
1.545 albertel 5551: color: #550044;
1.544 albertel 5552: }
1.795 www 5553:
1.544 albertel 5554: .LC_docs_rename {
1.545 albertel 5555: color: #009900;
1.544 albertel 5556: }
1.795 www 5557:
1.544 albertel 5558: .LC_docs_remove {
1.545 albertel 5559: color: #990000;
5560: }
5561:
1.547 albertel 5562: .LC_docs_reinit_warn,
5563: .LC_docs_ext_edit {
5564: font-size: x-small;
5565: }
5566:
1.545 albertel 5567: .LC_docs_editor td.LC_docs_entry_title,
5568: .LC_docs_editor td.LC_docs_entry_icon {
5569: background: #FFFFBB;
5570: }
1.795 www 5571:
1.545 albertel 5572: .LC_docs_editor td.LC_docs_entry_parameter {
5573: background: #BBBBFF;
5574: font-size: x-small;
5575: white-space: nowrap;
5576: }
5577:
5578: table.LC_docs_adddocs td,
5579: table.LC_docs_adddocs th {
5580: border: 1px solid #BBBBBB;
5581: padding: 4px;
5582: background: #DDDDDD;
1.543 albertel 5583: }
5584:
1.584 albertel 5585: table.LC_sty_begin {
5586: background: #BBFFBB;
5587: }
1.795 www 5588:
1.584 albertel 5589: table.LC_sty_end {
5590: background: #FFBBBB;
5591: }
5592:
1.589 raeburn 5593: table.LC_double_column {
5594: border-width: 0px;
5595: border-collapse: collapse;
5596: width: 100%;
5597: padding: 2px;
5598: }
5599:
5600: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5601: top: 2px;
1.589 raeburn 5602: left: 2px;
5603: width: 47%;
5604: vertical-align: top;
5605: }
5606:
5607: table.LC_double_column tr td.LC_right_col {
5608: top: 2px;
1.779 bisitz 5609: right: 2px;
1.589 raeburn 5610: width: 47%;
5611: vertical-align: top;
5612: }
5613:
1.594 raeburn 5614: span.LC_role_level {
5615: font-weight: bold;
5616: }
5617:
1.591 raeburn 5618: div.LC_left_float {
5619: float: left;
5620: padding-right: 5%;
1.597 albertel 5621: padding-bottom: 4px;
1.591 raeburn 5622: }
5623:
5624: div.LC_clear_float_header {
1.597 albertel 5625: padding-bottom: 2px;
1.591 raeburn 5626: }
5627:
5628: div.LC_clear_float_footer {
1.597 albertel 5629: padding-top: 10px;
1.591 raeburn 5630: clear: both;
5631: }
5632:
1.597 albertel 5633: div.LC_grade_show_user {
5634: margin-top: 20px;
5635: border: 1px solid black;
5636: }
1.795 www 5637:
1.597 albertel 5638: div.LC_grade_user_name {
5639: background: #DDDDEE;
5640: border-bottom: 1px solid black;
1.705 tempelho 5641: font-weight: bold;
5642: font-size: large;
1.597 albertel 5643: }
1.795 www 5644:
1.597 albertel 5645: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5646: background: #DDEEDD;
5647: }
5648:
5649: div.LC_grade_show_problem,
5650: div.LC_grade_submissions,
5651: div.LC_grade_message_center,
5652: div.LC_grade_info_links,
5653: div.LC_grade_assign {
5654: margin: 5px;
5655: width: 99%;
5656: background: #FFFFFF;
5657: }
1.795 www 5658:
1.597 albertel 5659: div.LC_grade_show_problem_header,
5660: div.LC_grade_submissions_header,
5661: div.LC_grade_message_center_header,
5662: div.LC_grade_assign_header {
1.705 tempelho 5663: font-weight: bold;
5664: font-size: large;
1.597 albertel 5665: }
1.795 www 5666:
1.597 albertel 5667: div.LC_grade_show_problem_problem,
5668: div.LC_grade_submissions_body,
5669: div.LC_grade_message_center_body,
5670: div.LC_grade_assign_body {
5671: border: 1px solid black;
5672: width: 99%;
5673: background: #FFFFFF;
5674: }
1.795 www 5675:
1.598 albertel 5676: span.LC_grade_check_note {
1.705 tempelho 5677: font-weight: normal;
5678: font-size: medium;
1.598 albertel 5679: display: inline;
5680: position: absolute;
5681: right: 1em;
5682: }
1.597 albertel 5683:
1.613 albertel 5684: table.LC_scantron_action {
5685: width: 100%;
5686: }
1.795 www 5687:
1.613 albertel 5688: table.LC_scantron_action tr th {
1.698 harmsja 5689: font-weight:bold;
5690: font-style:normal;
1.613 albertel 5691: }
1.795 www 5692:
1.779 bisitz 5693: .LC_edit_problem_header,
1.614 albertel 5694: div.LC_edit_problem_footer {
1.705 tempelho 5695: font-weight: normal;
5696: font-size: medium;
1.602 albertel 5697: margin: 2px;
1.600 albertel 5698: }
1.795 www 5699:
1.600 albertel 5700: div.LC_edit_problem_header,
1.602 albertel 5701: div.LC_edit_problem_header div,
1.614 albertel 5702: div.LC_edit_problem_footer,
5703: div.LC_edit_problem_footer div,
1.602 albertel 5704: div.LC_edit_problem_editxml_header,
5705: div.LC_edit_problem_editxml_header div {
1.600 albertel 5706: margin-top: 5px;
5707: }
1.795 www 5708:
1.602 albertel 5709: div.LC_edit_problem_header_edit_row {
5710: background: $tabbg;
5711: padding: 3px;
5712: margin-bottom: 5px;
5713: }
1.795 www 5714:
1.600 albertel 5715: div.LC_edit_problem_header_title {
1.705 tempelho 5716: font-weight: bold;
5717: font-size: larger;
1.602 albertel 5718: background: $tabbg;
5719: padding: 3px;
5720: }
1.795 www 5721:
1.602 albertel 5722: table.LC_edit_problem_header_title {
1.705 tempelho 5723: font-size: larger;
5724: font-weight: bold;
1.602 albertel 5725: width: 100%;
5726: border-color: $pgbg;
5727: border-style: solid;
5728: border-width: $border;
1.600 albertel 5729: background: $tabbg;
1.602 albertel 5730: border-collapse: collapse;
5731: padding: 0px
5732: }
5733:
5734: div.LC_edit_problem_discards {
5735: float: left;
5736: padding-bottom: 5px;
5737: }
1.795 www 5738:
1.602 albertel 5739: div.LC_edit_problem_saves {
5740: float: right;
5741: padding-bottom: 5px;
1.600 albertel 5742: }
1.795 www 5743:
1.600 albertel 5744: hr.LC_edit_problem_divide {
1.602 albertel 5745: clear: both;
1.600 albertel 5746: color: $tabbg;
5747: background-color: $tabbg;
5748: height: 3px;
5749: border: 0px;
5750: }
1.795 www 5751:
1.679 riegler 5752: img.stift{
1.678 riegler 5753: border-width:0;
1.679 riegler 5754: vertical-align:middle;
1.677 riegler 5755: }
1.680 riegler 5756:
1.681 riegler 5757: table#LC_mainmenu{
5758: margin-top:10px;
5759: width:80%;
5760: }
5761:
1.680 riegler 5762: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5763: vertical-align: top;
5764: width: 45%;
5765: }
1.795 www 5766:
1.779 bisitz 5767: .LC_mainmenu_fieldset_category {
5768: color: $font;
5769: background: $pgbg;
5770: font-family: $sans;
5771: font-size: small;
5772: font-weight: bold;
1.777 tempelho 5773: }
1.795 www 5774:
1.716 raeburn 5775: div.LC_createcourse {
5776: margin: 10px 10px 10px 10px;
5777: }
5778:
1.693 droeschl 5779: /* ---- Remove when done ----
5780: # The following styles is part of the redesign of LON-CAPA and are
5781: # subject to change during this project.
5782: # Don't rely on their current functionality as they might be
5783: # changed or removed.
5784: # --------------------------*/
5785:
1.698 harmsja 5786: a:hover,
1.721 harmsja 5787: ol.LC_smallMenu a:hover,
5788: ol#LC_MenuBreadcrumbs a:hover,
5789: ol#LC_PathBreadcrumbs a:hover,
5790: ul#LC_TabMainMenuContent a:hover,
5791: .LC_FormSectionClearButton input:hover
1.795 www 5792: ul.LC_TabContent li:hover a {
1.698 harmsja 5793: color:#BF2317;
5794: text-decoration:none;
1.693 droeschl 5795: }
5796:
1.779 bisitz 5797: h1 {
1.721 harmsja 5798: padding:5px 10px 5px 20px;
1.693 droeschl 5799: line-height:130%;
5800: }
1.698 harmsja 5801:
1.795 www 5802: h2,h3,h4,h5,h6 {
1.721 harmsja 5803: margin:5px 0px 5px 0px;
5804: padding:0px;
5805: line-height:130%;
1.693 droeschl 5806: }
1.795 www 5807:
5808: .LC_hcell {
1.698 harmsja 5809: padding:3px 15px 3px 15px;
5810: margin:0px;
1.703 harmsja 5811: background-color:$tabbg;
1.779 bisitz 5812: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5813: }
1.795 www 5814:
1.721 harmsja 5815: .LC_noBorder {
1.698 harmsja 5816: border:0px;
5817: }
1.693 droeschl 5818:
5819:
1.698 harmsja 5820: /* Main Header with discription of Person, Course, etc. */
1.693 droeschl 5821:
1.761 tempelho 5822: .LC_Right {
5823: float: right;
5824: margin: 0px;
5825: padding: 0px;
5826: }
5827:
1.721 harmsja 5828: .LC_FormSectionClearButton input {
1.779 bisitz 5829: background-color:transparent;
1.698 harmsja 5830: border:0px;
5831: cursor:pointer;
5832: text-decoration:underline;
1.693 droeschl 5833: }
1.763 bisitz 5834:
5835: .LC_help_open_topic {
5836: color: #FFFFFF;
5837: background-color: #EEEEFF;
5838: margin: 1px;
5839: padding: 4px;
5840: border: 1px solid #000033;
5841: white-space: nowrap;
1.783 amueller 5842: /* vertical-align: middle; */
1.759 neumanie 5843: }
1.693 droeschl 5844:
1.698 harmsja 5845: dl,ul,div,fieldset {
5846: margin: 10px 10px 10px 0px;
1.693 droeschl 5847: overflow:hidden;
5848: }
1.795 www 5849:
1.721 harmsja 5850: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5851: margin: 0px;
1.693 droeschl 5852: }
5853:
1.721 harmsja 5854: ol.LC_smallMenu li {
1.693 droeschl 5855: display: inline;
5856: padding: 5px 5px 0px 10px;
5857: vertical-align: top;
5858: }
5859:
1.721 harmsja 5860: ol.LC_smallMenu li img {
1.693 droeschl 5861: vertical-align: bottom;
5862: }
5863:
1.721 harmsja 5864: ol.LC_smallMenu a {
1.693 droeschl 5865: font-size: 90%;
5866: color: RGB(80, 80, 80);
5867: text-decoration: none;
5868: }
1.795 www 5869:
5870: ol#LC_TabMainMenuContent,
5871: ul.LC_TabContent ,
1.741 harmsja 5872: ul.LC_TabContentBigger {
1.721 harmsja 5873: display:block;
5874: list-style:none;
1.741 harmsja 5875: margin: 0px;
1.693 droeschl 5876: padding: 0px;
5877: }
5878:
1.795 www 5879: ol#LC_TabMainMenuContent li,
5880: ul.LC_TabContent li,
5881: ul.LC_TabContentBigger li {
1.693 droeschl 5882: display: inline;
1.741 harmsja 5883: border-right: solid 1px $lg_border_color;
5884: float:left;
5885: line-height:140%;
5886: white-space:nowrap;
5887: }
1.795 www 5888:
5889: ol#LC_TabMainMenuContent li {
1.693 droeschl 5890: vertical-align: bottom;
5891: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5892: padding: 5px 10px 5px 10px;
1.741 harmsja 5893: margin-right:5px;
5894: margin-bottom:3px;
1.693 droeschl 5895: font-weight: bold;
1.723 riegler 5896: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5897: }
5898:
1.795 www 5899: ol#LC_TabMainMenuContent li a {
1.693 droeschl 5900: color: RGB(47, 47, 47);
5901: text-decoration: none;
5902: }
1.795 www 5903:
1.721 harmsja 5904: ul.LC_TabContent {
1.741 harmsja 5905: min-height:1.6em;
1.721 harmsja 5906: }
1.795 www 5907:
5908: ul.LC_TabContent li {
1.741 harmsja 5909: vertical-align:middle;
5910: padding:0px 10px 0px 10px;
1.745 ehlerst 5911: background-color:$tabbg;
5912: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5913: }
1.795 www 5914:
5915: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 5916: color:rgb(47,47,47);
5917: text-decoration:none;
5918: font-size:95%;
5919: font-weight:bold;
1.761 tempelho 5920: padding-right: 16px;
1.721 harmsja 5921: }
1.795 www 5922:
5923: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 5924: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745 ehlerst 5925: border-bottom:solid 1px #FFFFFF;
1.761 tempelho 5926: padding-right: 16px;
1.744 ehlerst 5927: }
1.795 www 5928:
5929: ul.LC_TabContentBigger li {
1.741 harmsja 5930: vertical-align:bottom;
5931: border-top:solid 1px $lg_border_color;
5932: border-left:solid 1px $lg_border_color;
5933: padding:5px 10px 5px 10px;
5934: margin-left:2px;
5935: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5936: }
1.795 www 5937:
5938: ul.LC_TabContentBigger li:hover,
5939: ul.LC_TabContentBigger li.active {
1.744 ehlerst 5940: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5941: }
1.795 www 5942:
5943: ul.LC_TabContentBigger li,
5944: ul.LC_TabContentBigger li a {
1.741 harmsja 5945: font-size:110%;
5946: font-weight:bold;
5947: }
1.693 droeschl 5948:
1.795 www 5949: ol#LC_MenuBreadcrumbs,
5950: ol#LC_PathBreadcrumbs,
5951: ul.LC_CourseBreadcrumbs {
1.693 droeschl 5952: border-top: solid 1px RGB(255, 255, 255);
5953: height: 20px;
5954: line-height: 20px;
5955: vertical-align: bottom;
5956: margin: 0px 0px 30px 0px;
5957: padding-left: 10px;
5958: list-style-position: inside;
1.723 riegler 5959: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5960: }
5961:
1.795 www 5962: ol#LC_MenuBreadcrumbs li,
5963: ol#LC_PathBreadcrumbs li,
5964: ul.LC_CourseBreadcrumbs li {
1.741 harmsja 5965: /*
1.723 riegler 5966: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779 bisitz 5967: */
1.693 droeschl 5968: display: inline;
5969: padding: 0px 0px 0px 10px;
1.783 amueller 5970: /* vertical-align: bottom; */
1.693 droeschl 5971: overflow:hidden;
5972: }
5973:
1.783 amueller 5974: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 5975: text-decoration: none;
5976: font-size:90%;
5977: }
1.795 www 5978:
5979: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 5980: text-decoration:none;
5981: font-size:100%;
5982: font-weight:bold;
1.693 droeschl 5983: }
1.795 www 5984:
5985: .LC_BoxPadding {
1.786 neumanie 5986: padding: 10px;
5987: }
1.795 www 5988:
5989: .LC_ContentBoxSpecial {
1.701 harmsja 5990: border: solid 1px $lg_border_color;
1.746 neumanie 5991: }
1.795 www 5992:
5993: .LC_ContentBoxSpecialContactInfo {
1.746 neumanie 5994: border: solid 1px $lg_border_color;
5995: max-width:25%;
5996: min-width:25%;
1.698 harmsja 5997: }
1.795 www 5998:
5999: .LC_AboutMe_Image {
1.747 neumanie 6000: float:left;
6001: margin-right:10px;
6002: }
1.795 www 6003:
6004: .LC_Clear_AboutMe_Image {
1.747 neumanie 6005: clear:left;
6006: }
1.795 www 6007:
1.721 harmsja 6008: dl.LC_ListStyleClean dt {
1.693 droeschl 6009: padding-right: 5px;
6010: display: table-header-group;
6011: }
6012:
1.721 harmsja 6013: dl.LC_ListStyleClean dd {
1.693 droeschl 6014: display: table-row;
6015: }
6016:
1.721 harmsja 6017: .LC_ListStyleClean,
6018: .LC_ListStyleSimple,
6019: .LC_ListStyleNormal,
1.777 tempelho 6020: .LC_ListStyle_Border,
1.795 www 6021: .LC_ListStyleSpecial {
1.693 droeschl 6022: /*display:block; */
6023: list-style-position: inside;
6024: list-style-type: none;
6025: overflow: hidden;
6026: padding: 0px;
6027: }
6028:
1.721 harmsja 6029: .LC_ListStyleSimple li,
6030: .LC_ListStyleSimple dd,
6031: .LC_ListStyleNormal li,
6032: .LC_ListStyleNormal dd,
6033: .LC_ListStyleSpecial li,
1.795 www 6034: .LC_ListStyleSpecial dd {
1.693 droeschl 6035: margin: 0px;
6036: padding: 5px 5px 5px 10px;
6037: clear: both;
6038: }
6039:
1.721 harmsja 6040: .LC_ListStyleClean li,
6041: .LC_ListStyleClean dd {
1.693 droeschl 6042: padding-top: 0px;
6043: padding-bottom: 0px;
6044: }
6045:
1.721 harmsja 6046: .LC_ListStyleSimple dd,
1.795 www 6047: .LC_ListStyleSimple li {
1.698 harmsja 6048: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6049: }
6050:
1.721 harmsja 6051: .LC_ListStyleSpecial li,
6052: .LC_ListStyleSpecial dd {
1.693 droeschl 6053: list-style-type: none;
6054: background-color: RGB(220, 220, 220);
6055: margin-bottom: 4px;
6056: }
6057:
1.721 harmsja 6058: table.LC_SimpleTable {
1.698 harmsja 6059: margin:5px;
6060: border:solid 1px $lg_border_color;
1.795 www 6061: }
1.693 droeschl 6062:
1.721 harmsja 6063: table.LC_SimpleTable tr {
1.698 harmsja 6064: padding:0px;
6065: border:solid 1px $lg_border_color;
1.693 droeschl 6066: }
1.795 www 6067:
6068: table.LC_SimpleTable thead {
1.698 harmsja 6069: background:rgb(220,220,220);
1.693 droeschl 6070: }
6071:
1.721 harmsja 6072: div.LC_columnSection {
1.693 droeschl 6073: display: block;
6074: clear: both;
6075: overflow: hidden;
6076: margin:0px;
6077: }
6078:
1.721 harmsja 6079: div.LC_columnSection>* {
1.693 droeschl 6080: float: left;
6081: margin: 10px 20px 10px 0px;
1.747 neumanie 6082: overflow:hidden;
1.693 droeschl 6083: }
1.721 harmsja 6084:
1.795 www 6085: .ContentBoxSpecialTemplate {
1.747 neumanie 6086: border: solid 1px $lg_border_color;
1.719 ehlerst 6087: }
1.795 www 6088:
1.719 ehlerst 6089: .ContentBoxTemplate {
6090: padding:10px;
6091: }
6092:
1.721 harmsja 6093: div.LC_columnSection > .ContentBoxTemplate,
1.795 www 6094: div.LC_columnSection > .ContentBoxSpecialTemplate {
1.719 ehlerst 6095: width: 600px;
6096: }
1.753 droeschl 6097:
1.795 www 6098: .clear {
1.720 ehlerst 6099: clear: both;
6100: line-height: 0px;
6101: font-size: 0px;
6102: height: 0px;
6103: }
1.693 droeschl 6104:
1.694 tempelho 6105: .LC_loginpage_container {
6106: text-align:left;
6107: margin : 0 auto;
1.785 tempelho 6108: width:90%;
1.694 tempelho 6109: padding: 10px;
6110: height: auto;
1.712 muellerd 6111: background-color:#FFFFFF;
1.694 tempelho 6112: border:1px solid #CCCCCC;
6113: }
6114:
6115:
6116: .LC_loginpage_loginContainer {
6117: float:left;
1.712 muellerd 6118: width: 182px;
1.785 tempelho 6119: padding: 2px;
1.712 muellerd 6120: border:1px solid #CCCCCC;
6121: background-color:$loginbg;
1.694 tempelho 6122: }
6123:
1.795 www 6124: .LC_loginpage_loginContainer h2 {
1.712 muellerd 6125: margin-top:0;
6126: display:block;
6127: background:$bgcol;
6128: color:$textcol;
6129: padding-left:5px;
6130: }
1.785 tempelho 6131:
1.694 tempelho 6132: .LC_loginpage_loginInfo {
6133: float:left;
1.785 tempelho 6134: width:182px;
1.694 tempelho 6135: border:1px solid #CCCCCC;
1.785 tempelho 6136: padding:2px;
1.712 muellerd 6137: }
6138:
1.694 tempelho 6139: .LC_loginpage_space {
1.754 droeschl 6140: clear: both;
6141: margin-bottom: 20px;
1.694 tempelho 6142: border-bottom: 1px solid #CCCCCC;
6143: }
6144:
1.785 tempelho 6145: .LC_loginpage_floatLeft {
6146: float: left;
6147: width: 200px;
6148: margin: 0;
6149: }
6150:
1.795 www 6151: table em {
1.754 droeschl 6152: font-weight: bold;
6153: font-style: normal;
1.748 schulted 6154: }
1.795 www 6155:
1.779 bisitz 6156: table.LC_tableBrowseRes,
1.795 www 6157: table.LC_tableOfContent {
1.769 schulted 6158: border:none;
6159: border-spacing: 1;
1.754 droeschl 6160: padding: 3px;
6161: background-color: #FFFFFF;
6162: font-size: 90%;
1.753 droeschl 6163: }
1.789 droeschl 6164:
6165: table.LC_tableOfContent{
6166: border-collapse: collapse;
6167: }
6168:
1.771 droeschl 6169: table.LC_tableBrowseRes a,
1.768 schulted 6170: table.LC_tableOfContent a {
1.771 droeschl 6171: background-color: transparent;
1.753 droeschl 6172: text-decoration: none;
6173: }
6174:
1.771 droeschl 6175: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6176: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6177: background-color: #EEEEEE;
1.753 droeschl 6178: }
6179:
1.795 www 6180: table.LC_tableOfContent img {
1.753 droeschl 6181: border: none;
6182: height: 1.3em;
6183: vertical-align: text-bottom;
6184: margin-right: 0.3em;
6185: }
1.757 schulted 6186:
1.795 www 6187: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6188: background-image:url(/res/adm/pages/open-first-problem.gif);
6189: }
6190:
1.795 www 6191: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6192: background-image:url(/res/adm/pages/start-navigation.gif);
6193: }
6194:
1.795 www 6195: a#LC_content_toolbar_closenav {
1.774 ehlerst 6196: background-image:url(/res/adm/pages/close-navigation.gif);
6197: }
6198:
1.795 www 6199: a#LC_content_toolbar_everything {
1.774 ehlerst 6200: background-image:url(/res/adm/pages/show-all.gif);
6201: }
6202:
1.795 www 6203: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6204: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6205: }
6206:
1.795 www 6207: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6208: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6209: }
6210:
1.795 www 6211: a#LC_content_toolbar_changefolder {
1.757 schulted 6212: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6213: }
6214:
1.795 www 6215: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6216: background-image:url(/res/adm/pages/open-all-folders.gif);
6217: }
6218:
1.795 www 6219: ul#LC_toolbar li a:hover {
1.757 schulted 6220: background-position: bottom center;
6221: }
6222:
1.795 www 6223: ul#LC_toolbar {
1.779 bisitz 6224: padding:0;
1.757 schulted 6225: margin: 2px;
6226: list-style:none;
6227: position:relative;
6228: background-color:white;
6229: }
6230:
1.795 www 6231: ul#LC_toolbar li {
1.757 schulted 6232: border:1px solid white;
6233: padding:0;
6234: margin: 0;
1.795 www 6235: float: left;
1.767 droeschl 6236: display:inline;
1.757 schulted 6237: vertical-align:middle;
1.795 www 6238: }
1.757 schulted 6239:
1.783 amueller 6240:
1.795 www 6241: a.LC_toolbarItem {
1.767 droeschl 6242: display:block;
1.757 schulted 6243: padding:0;
6244: margin:0;
6245: height: 32px;
6246: width: 32px;
1.779 bisitz 6247: color:white;
6248: border:0 none;
1.757 schulted 6249: background-repeat:no-repeat;
6250: background-color:transparent;
6251: }
6252:
1.782 bisitz 6253: ul.LC_functionslist li {
6254: float: left;
6255: white-space: nowrap;
6256: height: 35px; /* at least as high as heighest list item */
6257: margin: 0px 15px 15px 10px;
6258: }
6259:
1.757 schulted 6260:
1.343 albertel 6261: END
6262: }
6263:
1.306 albertel 6264: =pod
6265:
6266: =item * &headtag()
6267:
6268: Returns a uniform footer for LON-CAPA web pages.
6269:
1.307 albertel 6270: Inputs: $title - optional title for the head
6271: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6272: $args - optional arguments
1.319 albertel 6273: force_register - if is true call registerurl so the remote is
6274: informed
1.415 albertel 6275: redirect -> array ref of
6276: 1- seconds before redirect occurs
6277: 2- url to redirect to
6278: 3- whether the side effect should occur
1.315 albertel 6279: (side effect of setting
6280: $env{'internal.head.redirect'} to the url
6281: redirected too)
1.352 albertel 6282: domain -> force to color decorate a page for a specific
6283: domain
6284: function -> force usage of a specific rolish color scheme
6285: bgcolor -> override the default page bgcolor
1.460 albertel 6286: no_auto_mt_title
6287: -> prevent &mt()ing the title arg
1.464 albertel 6288:
1.306 albertel 6289: =cut
6290:
6291: sub headtag {
1.313 albertel 6292: my ($title,$head_extra,$args) = @_;
1.306 albertel 6293:
1.363 albertel 6294: my $function = $args->{'function'} || &get_users_function();
6295: my $domain = $args->{'domain'} || &determinedomain();
6296: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6297: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6298: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6299: #time(),
1.418 albertel 6300: $env{'environment.color.timestamp'},
1.363 albertel 6301: $function,$domain,$bgcolor);
6302:
1.369 www 6303: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6304:
1.308 albertel 6305: my $result =
6306: '<head>'.
1.461 albertel 6307: &font_settings();
1.319 albertel 6308:
1.461 albertel 6309: if (!$args->{'frameset'}) {
6310: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6311: }
1.319 albertel 6312: if ($args->{'force_register'}) {
6313: $result .= &Apache::lonmenu::registerurl(1);
6314: }
1.436 albertel 6315: if (!$args->{'no_nav_bar'}
6316: && !$args->{'only_body'}
6317: && !$args->{'frameset'}) {
6318: $result .= &help_menu_js();
6319: }
1.319 albertel 6320:
1.314 albertel 6321: if (ref($args->{'redirect'})) {
1.414 albertel 6322: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6323: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6324: if (!$inhibit_continue) {
6325: $env{'internal.head.redirect'} = $url;
6326: }
1.313 albertel 6327: $result.=<<ADDMETA
6328: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6329: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6330: ADDMETA
6331: }
1.306 albertel 6332: if (!defined($title)) {
6333: $title = 'The LearningOnline Network with CAPA';
6334: }
1.460 albertel 6335: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6336: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6337: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6338: .$head_extra;
1.306 albertel 6339: return $result;
6340: }
6341:
6342: =pod
6343:
1.340 albertel 6344: =item * &font_settings()
6345:
6346: Returns neccessary <meta> to set the proper encoding
6347:
6348: Inputs: none
6349:
6350: =cut
6351:
6352: sub font_settings {
6353: my $headerstring='';
1.647 www 6354: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6355: $headerstring.=
6356: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6357: }
6358: return $headerstring;
6359: }
6360:
1.341 albertel 6361: =pod
6362:
6363: =item * &xml_begin()
6364:
6365: Returns the needed doctype and <html>
6366:
6367: Inputs: none
6368:
6369: =cut
6370:
6371: sub xml_begin {
6372: my $output='';
6373:
1.592 albertel 6374: if ($env{'internal.start_page'}==1) {
6375: &Apache::lonhtmlcommon::init_htmlareafields();
6376: }
1.342 albertel 6377:
1.341 albertel 6378: if ($env{'browser.mathml'}) {
6379: $output='<?xml version="1.0"?>'
6380: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6381: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6382:
6383: # .'<!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">] >'
6384: .'<!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">'
6385: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6386: .'xmlns="http://www.w3.org/1999/xhtml">';
6387: } else {
6388: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6389: }
6390: return $output;
6391: }
1.340 albertel 6392:
6393: =pod
6394:
1.306 albertel 6395: =item * &endheadtag()
6396:
6397: Returns a uniform </head> for LON-CAPA web pages.
6398:
6399: Inputs: none
6400:
6401: =cut
6402:
6403: sub endheadtag {
6404: return '</head>';
6405: }
6406:
6407: =pod
6408:
6409: =item * &head()
6410:
6411: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6412:
1.648 raeburn 6413: Inputs:
6414:
6415: =over 4
6416:
6417: $title - optional title for the page
6418:
6419: $head_extra - optional extra HTML to put inside the <head>
6420:
6421: =back
1.405 albertel 6422:
1.306 albertel 6423: =cut
6424:
6425: sub head {
1.325 albertel 6426: my ($title,$head_extra,$args) = @_;
6427: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6428: }
6429:
6430: =pod
6431:
6432: =item * &start_page()
6433:
6434: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6435:
1.648 raeburn 6436: Inputs:
6437:
6438: =over 4
6439:
6440: $title - optional title for the page
6441:
6442: $head_extra - optional extra HTML to incude inside the <head>
6443:
6444: $args - additional optional args supported are:
6445:
6446: =over 8
6447:
6448: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6449: arg on
1.648 raeburn 6450: no_nav_bar -> is true will set &bodytag() notopbar arg on
6451: add_entries -> additional attributes to add to the <body>
6452: domain -> force to color decorate a page for a
1.317 albertel 6453: specific domain
1.648 raeburn 6454: function -> force usage of a specific rolish color
1.317 albertel 6455: scheme
1.648 raeburn 6456: redirect -> see &headtag()
6457: bgcolor -> override the default page bg color
6458: js_ready -> return a string ready for being used in
1.317 albertel 6459: a javascript writeln
1.648 raeburn 6460: html_encode -> return a string ready for being used in
1.320 albertel 6461: a html attribute
1.648 raeburn 6462: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6463: $forcereg arg
1.648 raeburn 6464: body_title -> alternate text to use instead of $title
1.326 albertel 6465: in the title box that appears, this text
6466: is not auto translated like the $title is
1.648 raeburn 6467: frameset -> if true will start with a <frameset>
1.330 albertel 6468: rather than <body>
1.648 raeburn 6469: no_title -> if true the title bar won't be shown
6470: skip_phases -> hash ref of
1.338 albertel 6471: head -> skip the <html><head> generation
6472: body -> skip all <body> generation
1.648 raeburn 6473: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6474: 'Switch To Inline Menu' link
1.648 raeburn 6475: no_auto_mt_title -> prevent &mt()ing the title arg
6476: inherit_jsmath -> when creating popup window in a page,
6477: should it have jsmath forced on by the
6478: current page
1.361 albertel 6479:
1.648 raeburn 6480: =back
1.460 albertel 6481:
1.648 raeburn 6482: =back
1.562 albertel 6483:
1.306 albertel 6484: =cut
6485:
6486: sub start_page {
1.309 albertel 6487: my ($title,$head_extra,$args) = @_;
1.318 albertel 6488: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6489: my %head_args;
1.352 albertel 6490: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6491: 'bgcolor','frameset','no_nav_bar','only_body',
6492: 'no_auto_mt_title') {
1.319 albertel 6493: if (defined($args->{$arg})) {
1.324 raeburn 6494: $head_args{$arg} = $args->{$arg};
1.319 albertel 6495: }
1.313 albertel 6496: }
1.319 albertel 6497:
1.315 albertel 6498: $env{'internal.start_page'}++;
1.338 albertel 6499: my $result;
6500: if (! exists($args->{'skip_phases'}{'head'}) ) {
6501: $result.=
1.341 albertel 6502: &xml_begin().
1.338 albertel 6503: &headtag($title,$head_extra,\%head_args).&endheadtag();
6504: }
6505:
6506: if (! exists($args->{'skip_phases'}{'body'}) ) {
6507: if ($args->{'frameset'}) {
6508: my $attr_string = &make_attr_string($args->{'force_register'},
6509: $args->{'add_entries'});
6510: $result .= "\n<frameset $attr_string>\n";
6511: } else {
6512: $result .=
6513: &bodytag($title,
6514: $args->{'function'}, $args->{'add_entries'},
6515: $args->{'only_body'}, $args->{'domain'},
6516: $args->{'force_register'}, $args->{'body_title'},
6517: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6518: $args->{'no_title'}, $args->{'no_inline_link'},
6519: $args);
1.338 albertel 6520: }
1.330 albertel 6521: }
1.338 albertel 6522:
1.315 albertel 6523: if ($args->{'js_ready'}) {
1.713 kaisler 6524: $result = &js_ready($result);
1.315 albertel 6525: }
1.320 albertel 6526: if ($args->{'html_encode'}) {
1.713 kaisler 6527: $result = &html_encode($result);
6528: }
6529:
1.758 kaisler 6530: #Breadcrumbs
6531: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6532: &Apache::lonhtmlcommon::clear_breadcrumbs();
6533: #if any br links exists, add them to the breadcrumbs
6534: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6535: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6536: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6537: }
6538: }
6539:
6540: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6541: if(exists($args->{'bread_crumbs_component'})){
6542: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6543: }else{
6544: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6545: }
1.320 albertel 6546: }
1.315 albertel 6547: return $result;
1.306 albertel 6548: }
6549:
1.330 albertel 6550:
1.306 albertel 6551: =pod
6552:
6553: =item * &head()
6554:
6555: Returns a complete </body></html> section for LON-CAPA web pages.
6556:
1.315 albertel 6557: Inputs: $args - additional optional args supported are:
6558: js_ready -> return a string ready for being used in
6559: a javascript writeln
1.320 albertel 6560: html_encode -> return a string ready for being used in
6561: a html attribute
1.330 albertel 6562: frameset -> if true will start with a <frameset>
6563: rather than <body>
1.493 albertel 6564: dicsussion -> if true will get discussion from
6565: lonxml::xmlend
6566: (you can pass the target and parser arguments
6567: through optional 'target' and 'parser' args
6568: to this routine)
1.306 albertel 6569:
6570: =cut
6571:
6572: sub end_page {
1.315 albertel 6573: my ($args) = @_;
6574: $env{'internal.end_page'}++;
1.330 albertel 6575: my $result;
1.335 albertel 6576: if ($args->{'discussion'}) {
6577: my ($target,$parser);
6578: if (ref($args->{'discussion'})) {
6579: ($target,$parser) =($args->{'discussion'}{'target'},
6580: $args->{'discussion'}{'parser'});
6581: }
6582: $result .= &Apache::lonxml::xmlend($target,$parser);
6583: }
6584:
1.330 albertel 6585: if ($args->{'frameset'}) {
6586: $result .= '</frameset>';
6587: } else {
1.635 raeburn 6588: $result .= &endbodytag($args);
1.330 albertel 6589: }
6590: $result .= "\n</html>";
6591:
1.315 albertel 6592: if ($args->{'js_ready'}) {
1.317 albertel 6593: $result = &js_ready($result);
1.315 albertel 6594: }
1.335 albertel 6595:
1.320 albertel 6596: if ($args->{'html_encode'}) {
6597: $result = &html_encode($result);
6598: }
1.335 albertel 6599:
1.315 albertel 6600: return $result;
6601: }
6602:
1.320 albertel 6603: sub html_encode {
6604: my ($result) = @_;
6605:
1.322 albertel 6606: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6607:
6608: return $result;
6609: }
1.317 albertel 6610: sub js_ready {
6611: my ($result) = @_;
6612:
1.323 albertel 6613: $result =~ s/[\n\r]/ /xmsg;
6614: $result =~ s/\\/\\\\/xmsg;
6615: $result =~ s/'/\\'/xmsg;
1.372 albertel 6616: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6617:
6618: return $result;
6619: }
6620:
1.315 albertel 6621: sub validate_page {
6622: if ( exists($env{'internal.start_page'})
1.316 albertel 6623: && $env{'internal.start_page'} > 1) {
6624: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6625: $env{'internal.start_page'}.' '.
1.316 albertel 6626: $ENV{'request.filename'});
1.315 albertel 6627: }
6628: if ( exists($env{'internal.end_page'})
1.316 albertel 6629: && $env{'internal.end_page'} > 1) {
6630: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6631: $env{'internal.end_page'}.' '.
1.316 albertel 6632: $env{'request.filename'});
1.315 albertel 6633: }
6634: if ( exists($env{'internal.start_page'})
6635: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6636: &Apache::lonnet::logthis('start_page called without end_page '.
6637: $env{'request.filename'});
1.315 albertel 6638: }
6639: if ( ! exists($env{'internal.start_page'})
6640: && exists($env{'internal.end_page'})) {
1.316 albertel 6641: &Apache::lonnet::logthis('end_page called without start_page'.
6642: $env{'request.filename'});
1.315 albertel 6643: }
1.306 albertel 6644: }
1.315 albertel 6645:
1.318 albertel 6646: sub simple_error_page {
6647: my ($r,$title,$msg) = @_;
6648: my $page =
6649: &Apache::loncommon::start_page($title).
6650: &mt($msg).
6651: &Apache::loncommon::end_page();
6652: if (ref($r)) {
6653: $r->print($page);
1.327 albertel 6654: return;
1.318 albertel 6655: }
6656: return $page;
6657: }
1.347 albertel 6658:
6659: {
1.610 albertel 6660: my @row_count;
1.347 albertel 6661: sub start_data_table {
1.422 albertel 6662: my ($add_class) = @_;
6663: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6664: unshift(@row_count,0);
1.422 albertel 6665: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6666: }
6667:
6668: sub end_data_table {
1.610 albertel 6669: shift(@row_count);
1.389 albertel 6670: return '</table>'."\n";;
1.347 albertel 6671: }
6672:
6673: sub start_data_table_row {
1.422 albertel 6674: my ($add_class) = @_;
1.610 albertel 6675: $row_count[0]++;
6676: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6677: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6678: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6679: }
1.471 banghart 6680:
6681: sub continue_data_table_row {
6682: my ($add_class) = @_;
1.610 albertel 6683: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6684: $css_class = (join(' ',$css_class,$add_class));
6685: return '<tr class="'.$css_class.'">'."\n";;
6686: }
1.347 albertel 6687:
6688: sub end_data_table_row {
1.389 albertel 6689: return '</tr>'."\n";;
1.347 albertel 6690: }
1.367 www 6691:
1.421 albertel 6692: sub start_data_table_empty_row {
1.707 bisitz 6693: # $row_count[0]++;
1.421 albertel 6694: return '<tr class="LC_empty_row" >'."\n";;
6695: }
6696:
6697: sub end_data_table_empty_row {
6698: return '</tr>'."\n";;
6699: }
6700:
1.367 www 6701: sub start_data_table_header_row {
1.389 albertel 6702: return '<tr class="LC_header_row">'."\n";;
1.367 www 6703: }
6704:
6705: sub end_data_table_header_row {
1.389 albertel 6706: return '</tr>'."\n";;
1.367 www 6707: }
1.347 albertel 6708: }
6709:
1.548 albertel 6710: =pod
6711:
6712: =item * &inhibit_menu_check($arg)
6713:
6714: Checks for a inhibitmenu state and generates output to preserve it
6715:
6716: Inputs: $arg - can be any of
6717: - undef - in which case the return value is a string
6718: to add into arguments list of a uri
6719: - 'input' - in which case the return value is a HTML
6720: <form> <input> field of type hidden to
6721: preserve the value
6722: - a url - in which case the return value is the url with
6723: the neccesary cgi args added to preserve the
6724: inhibitmenu state
6725: - a ref to a url - no return value, but the string is
6726: updated to include the neccessary cgi
6727: args to preserve the inhibitmenu state
6728:
6729: =cut
6730:
6731: sub inhibit_menu_check {
6732: my ($arg) = @_;
6733: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6734: if ($arg eq 'input') {
6735: if ($env{'form.inhibitmenu'}) {
6736: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6737: } else {
6738: return
6739: }
6740: }
6741: if ($env{'form.inhibitmenu'}) {
6742: if (ref($arg)) {
6743: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6744: } elsif ($arg eq '') {
6745: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6746: } else {
6747: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6748: }
6749: }
6750: if (!ref($arg)) {
6751: return $arg;
6752: }
6753: }
6754:
1.251 albertel 6755: ###############################################
1.182 matthew 6756:
6757: =pod
6758:
1.549 albertel 6759: =back
6760:
6761: =head1 User Information Routines
6762:
6763: =over 4
6764:
1.405 albertel 6765: =item * &get_users_function()
1.182 matthew 6766:
6767: Used by &bodytag to determine the current users primary role.
6768: Returns either 'student','coordinator','admin', or 'author'.
6769:
6770: =cut
6771:
6772: ###############################################
6773: sub get_users_function {
6774: my $function = 'student';
1.258 albertel 6775: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6776: $function='coordinator';
6777: }
1.258 albertel 6778: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6779: $function='admin';
6780: }
1.258 albertel 6781: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6782: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6783: $function='author';
6784: }
6785: return $function;
1.54 www 6786: }
1.99 www 6787:
6788: ###############################################
6789:
1.233 raeburn 6790: =pod
6791:
1.542 raeburn 6792: =item * &check_user_status()
1.274 raeburn 6793:
6794: Determines current status of supplied role for a
6795: specific user. Roles can be active, previous or future.
6796:
6797: Inputs:
6798: user's domain, user's username, course's domain,
1.375 raeburn 6799: course's number, optional section ID.
1.274 raeburn 6800:
6801: Outputs:
6802: role status: active, previous or future.
6803:
6804: =cut
6805:
6806: sub check_user_status {
1.412 raeburn 6807: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6808: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6809: my @uroles = keys %userinfo;
6810: my $srchstr;
6811: my $active_chk = 'none';
1.412 raeburn 6812: my $now = time;
1.274 raeburn 6813: if (@uroles > 0) {
1.412 raeburn 6814: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6815: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6816: } else {
1.412 raeburn 6817: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6818: }
6819: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6820: my $role_end = 0;
6821: my $role_start = 0;
6822: $active_chk = 'active';
1.412 raeburn 6823: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6824: $role_end = $1;
6825: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6826: $role_start = $1;
1.274 raeburn 6827: }
6828: }
6829: if ($role_start > 0) {
1.412 raeburn 6830: if ($now < $role_start) {
1.274 raeburn 6831: $active_chk = 'future';
6832: }
6833: }
6834: if ($role_end > 0) {
1.412 raeburn 6835: if ($now > $role_end) {
1.274 raeburn 6836: $active_chk = 'previous';
6837: }
6838: }
6839: }
6840: }
6841: return $active_chk;
6842: }
6843:
6844: ###############################################
6845:
6846: =pod
6847:
1.405 albertel 6848: =item * &get_sections()
1.233 raeburn 6849:
6850: Determines all the sections for a course including
6851: sections with students and sections containing other roles.
1.419 raeburn 6852: Incoming parameters:
6853:
6854: 1. domain
6855: 2. course number
6856: 3. reference to array containing roles for which sections should
6857: be gathered (optional).
6858: 4. reference to array containing status types for which sections
6859: should be gathered (optional).
6860:
6861: If the third argument is undefined, sections are gathered for any role.
6862: If the fourth argument is undefined, sections are gathered for any status.
6863: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6864:
1.374 raeburn 6865: Returns section hash (keys are section IDs, values are
6866: number of users in each section), subject to the
1.419 raeburn 6867: optional roles filter, optional status filter
1.233 raeburn 6868:
6869: =cut
6870:
6871: ###############################################
6872: sub get_sections {
1.419 raeburn 6873: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6874: if (!defined($cdom) || !defined($cnum)) {
6875: my $cid = $env{'request.course.id'};
6876:
6877: return if (!defined($cid));
6878:
6879: $cdom = $env{'course.'.$cid.'.domain'};
6880: $cnum = $env{'course.'.$cid.'.num'};
6881: }
6882:
6883: my %sectioncount;
1.419 raeburn 6884: my $now = time;
1.240 albertel 6885:
1.366 albertel 6886: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6887: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6888: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6889: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6890: my $start_index = &Apache::loncoursedata::CL_START();
6891: my $end_index = &Apache::loncoursedata::CL_END();
6892: my $status;
1.366 albertel 6893: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6894: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6895: $data->[$status_index],
6896: $data->[$start_index],
6897: $data->[$end_index]);
6898: if ($stu_status eq 'Active') {
6899: $status = 'active';
6900: } elsif ($end < $now) {
6901: $status = 'previous';
6902: } elsif ($start > $now) {
6903: $status = 'future';
6904: }
6905: if ($section ne '-1' && $section !~ /^\s*$/) {
6906: if ((!defined($possible_status)) || (($status ne '') &&
6907: (grep/^\Q$status\E$/,@{$possible_status}))) {
6908: $sectioncount{$section}++;
6909: }
1.240 albertel 6910: }
6911: }
6912: }
6913: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6914: foreach my $user (sort(keys(%courseroles))) {
6915: if ($user !~ /^(\w{2})/) { next; }
6916: my ($role) = ($user =~ /^(\w{2})/);
6917: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6918: my ($section,$status);
1.240 albertel 6919: if ($role eq 'cr' &&
6920: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6921: $section=$1;
6922: }
6923: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6924: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6925: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6926: if ($end == -1 && $start == -1) {
6927: next; #deleted role
6928: }
6929: if (!defined($possible_status)) {
6930: $sectioncount{$section}++;
6931: } else {
6932: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6933: $status = 'active';
6934: } elsif ($end < $now) {
6935: $status = 'future';
6936: } elsif ($start > $now) {
6937: $status = 'previous';
6938: }
6939: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6940: $sectioncount{$section}++;
6941: }
6942: }
1.233 raeburn 6943: }
1.366 albertel 6944: return %sectioncount;
1.233 raeburn 6945: }
6946:
1.274 raeburn 6947: ###############################################
1.294 raeburn 6948:
6949: =pod
1.405 albertel 6950:
6951: =item * &get_course_users()
6952:
1.275 raeburn 6953: Retrieves usernames:domains for users in the specified course
6954: with specific role(s), and access status.
6955:
6956: Incoming parameters:
1.277 albertel 6957: 1. course domain
6958: 2. course number
6959: 3. access status: users must have - either active,
1.275 raeburn 6960: previous, future, or all.
1.277 albertel 6961: 4. reference to array of permissible roles
1.288 raeburn 6962: 5. reference to array of section restrictions (optional)
6963: 6. reference to results object (hash of hashes).
6964: 7. reference to optional userdata hash
1.609 raeburn 6965: 8. reference to optional statushash
1.630 raeburn 6966: 9. flag if privileged users (except those set to unhide in
6967: course settings) should be excluded
1.609 raeburn 6968: Keys of top level results hash are roles.
1.275 raeburn 6969: Keys of inner hashes are username:domain, with
6970: values set to access type.
1.288 raeburn 6971: Optional userdata hash returns an array with arguments in the
6972: same order as loncoursedata::get_classlist() for student data.
6973:
1.609 raeburn 6974: Optional statushash returns
6975:
1.288 raeburn 6976: Entries for end, start, section and status are blank because
6977: of the possibility of multiple values for non-student roles.
6978:
1.275 raeburn 6979: =cut
1.405 albertel 6980:
1.275 raeburn 6981: ###############################################
1.405 albertel 6982:
1.275 raeburn 6983: sub get_course_users {
1.630 raeburn 6984: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6985: my %idx = ();
1.419 raeburn 6986: my %seclists;
1.288 raeburn 6987:
6988: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6989: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6990: $idx{end} = &Apache::loncoursedata::CL_END();
6991: $idx{start} = &Apache::loncoursedata::CL_START();
6992: $idx{id} = &Apache::loncoursedata::CL_ID();
6993: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6994: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6995: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6996:
1.290 albertel 6997: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6998: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6999: my $now = time;
1.277 albertel 7000: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7001: my $match = 0;
1.412 raeburn 7002: my $secmatch = 0;
1.419 raeburn 7003: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7004: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7005: if ($section eq '') {
7006: $section = 'none';
7007: }
1.291 albertel 7008: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7009: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7010: $secmatch = 1;
7011: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7012: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7013: $secmatch = 1;
7014: }
7015: } else {
1.419 raeburn 7016: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7017: $secmatch = 1;
7018: }
1.290 albertel 7019: }
1.412 raeburn 7020: if (!$secmatch) {
7021: next;
7022: }
1.419 raeburn 7023: }
1.275 raeburn 7024: if (defined($$types{'active'})) {
1.288 raeburn 7025: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7026: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7027: $match = 1;
1.275 raeburn 7028: }
7029: }
7030: if (defined($$types{'previous'})) {
1.609 raeburn 7031: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7032: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7033: $match = 1;
1.275 raeburn 7034: }
7035: }
7036: if (defined($$types{'future'})) {
1.609 raeburn 7037: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7038: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7039: $match = 1;
1.275 raeburn 7040: }
7041: }
1.609 raeburn 7042: if ($match) {
7043: push(@{$seclists{$student}},$section);
7044: if (ref($userdata) eq 'HASH') {
7045: $$userdata{$student} = $$classlist{$student};
7046: }
7047: if (ref($statushash) eq 'HASH') {
7048: $statushash->{$student}{'st'}{$section} = $status;
7049: }
1.288 raeburn 7050: }
1.275 raeburn 7051: }
7052: }
1.412 raeburn 7053: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7054: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7055: my $now = time;
1.609 raeburn 7056: my %displaystatus = ( previous => 'Expired',
7057: active => 'Active',
7058: future => 'Future',
7059: );
1.630 raeburn 7060: my %nothide;
7061: if ($hidepriv) {
7062: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7063: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7064: if ($user !~ /:/) {
7065: $nothide{join(':',split(/[\@]/,$user))}=1;
7066: } else {
7067: $nothide{$user} = 1;
7068: }
7069: }
7070: }
1.439 raeburn 7071: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7072: my $match = 0;
1.412 raeburn 7073: my $secmatch = 0;
1.439 raeburn 7074: my $status;
1.412 raeburn 7075: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7076: $user =~ s/:$//;
1.439 raeburn 7077: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7078: if ($end == -1 || $start == -1) {
7079: next;
7080: }
7081: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7082: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7083: my ($uname,$udom) = split(/:/,$user);
7084: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7085: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7086: $secmatch = 1;
7087: } elsif ($usec eq '') {
1.420 albertel 7088: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7089: $secmatch = 1;
7090: }
7091: } else {
7092: if (grep(/^\Q$usec\E$/,@{$sections})) {
7093: $secmatch = 1;
7094: }
7095: }
7096: if (!$secmatch) {
7097: next;
7098: }
1.288 raeburn 7099: }
1.419 raeburn 7100: if ($usec eq '') {
7101: $usec = 'none';
7102: }
1.275 raeburn 7103: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7104: if ($hidepriv) {
7105: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7106: (!$nothide{$uname.':'.$udom})) {
7107: next;
7108: }
7109: }
1.503 raeburn 7110: if ($end > 0 && $end < $now) {
1.439 raeburn 7111: $status = 'previous';
7112: } elsif ($start > $now) {
7113: $status = 'future';
7114: } else {
7115: $status = 'active';
7116: }
1.277 albertel 7117: foreach my $type (keys(%{$types})) {
1.275 raeburn 7118: if ($status eq $type) {
1.420 albertel 7119: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7120: push(@{$$users{$role}{$user}},$type);
7121: }
1.288 raeburn 7122: $match = 1;
7123: }
7124: }
1.419 raeburn 7125: if (($match) && (ref($userdata) eq 'HASH')) {
7126: if (!exists($$userdata{$uname.':'.$udom})) {
7127: &get_user_info($udom,$uname,\%idx,$userdata);
7128: }
1.420 albertel 7129: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7130: push(@{$seclists{$uname.':'.$udom}},$usec);
7131: }
1.609 raeburn 7132: if (ref($statushash) eq 'HASH') {
7133: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7134: }
1.275 raeburn 7135: }
7136: }
7137: }
7138: }
1.290 albertel 7139: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7140: if ((defined($cdom)) && (defined($cnum))) {
7141: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7142: if ( defined($csettings{'internal.courseowner'}) ) {
7143: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7144: next if ($owner eq '');
7145: my ($ownername,$ownerdom);
7146: if ($owner =~ /^([^:]+):([^:]+)$/) {
7147: $ownername = $1;
7148: $ownerdom = $2;
7149: } else {
7150: $ownername = $owner;
7151: $ownerdom = $cdom;
7152: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7153: }
7154: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7155: if (defined($userdata) &&
1.609 raeburn 7156: !exists($$userdata{$owner})) {
7157: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7158: if (!grep(/^none$/,@{$seclists{$owner}})) {
7159: push(@{$seclists{$owner}},'none');
7160: }
7161: if (ref($statushash) eq 'HASH') {
7162: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7163: }
1.290 albertel 7164: }
1.279 raeburn 7165: }
7166: }
7167: }
1.419 raeburn 7168: foreach my $user (keys(%seclists)) {
7169: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7170: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7171: }
1.275 raeburn 7172: }
7173: return;
7174: }
7175:
1.288 raeburn 7176: sub get_user_info {
7177: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7178: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7179: &plainname($uname,$udom,'lastname');
1.291 albertel 7180: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7181: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7182: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7183: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7184: return;
7185: }
1.275 raeburn 7186:
1.472 raeburn 7187: ###############################################
7188:
7189: =pod
7190:
7191: =item * &get_user_quota()
7192:
7193: Retrieves quota assigned for storage of portfolio files for a user
7194:
7195: Incoming parameters:
7196: 1. user's username
7197: 2. user's domain
7198:
7199: Returns:
1.536 raeburn 7200: 1. Disk quota (in Mb) assigned to student.
7201: 2. (Optional) Type of setting: custom or default
7202: (individually assigned or default for user's
7203: institutional status).
7204: 3. (Optional) - User's institutional status (e.g., faculty, staff
7205: or student - types as defined in localenroll::inst_usertypes
7206: for user's domain, which determines default quota for user.
7207: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7208:
7209: If a value has been stored in the user's environment,
1.536 raeburn 7210: it will return that, otherwise it returns the maximal default
7211: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7212:
7213: =cut
7214:
7215: ###############################################
7216:
7217:
7218: sub get_user_quota {
7219: my ($uname,$udom) = @_;
1.536 raeburn 7220: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7221: if (!defined($udom)) {
7222: $udom = $env{'user.domain'};
7223: }
7224: if (!defined($uname)) {
7225: $uname = $env{'user.name'};
7226: }
7227: if (($udom eq '' || $uname eq '') ||
7228: ($udom eq 'public') && ($uname eq 'public')) {
7229: $quota = 0;
1.536 raeburn 7230: $quotatype = 'default';
7231: $defquota = 0;
1.472 raeburn 7232: } else {
1.536 raeburn 7233: my $inststatus;
1.472 raeburn 7234: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7235: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7236: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7237: } else {
1.536 raeburn 7238: my %userenv =
7239: &Apache::lonnet::get('environment',['portfolioquota',
7240: 'inststatus'],$udom,$uname);
1.472 raeburn 7241: my ($tmp) = keys(%userenv);
7242: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7243: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7244: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7245: } else {
7246: undef(%userenv);
7247: }
7248: }
1.536 raeburn 7249: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7250: if ($quota eq '') {
1.536 raeburn 7251: $quota = $defquota;
7252: $quotatype = 'default';
7253: } else {
7254: $quotatype = 'custom';
1.472 raeburn 7255: }
7256: }
1.536 raeburn 7257: if (wantarray) {
7258: return ($quota,$quotatype,$settingstatus,$defquota);
7259: } else {
7260: return $quota;
7261: }
1.472 raeburn 7262: }
7263:
7264: ###############################################
7265:
7266: =pod
7267:
7268: =item * &default_quota()
7269:
1.536 raeburn 7270: Retrieves default quota assigned for storage of user portfolio files,
7271: given an (optional) user's institutional status.
1.472 raeburn 7272:
7273: Incoming parameters:
7274: 1. domain
1.536 raeburn 7275: 2. (Optional) institutional status(es). This is a : separated list of
7276: status types (e.g., faculty, staff, student etc.)
7277: which apply to the user for whom the default is being retrieved.
7278: If the institutional status string in undefined, the domain
7279: default quota will be returned.
1.472 raeburn 7280:
7281: Returns:
7282: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7283: 2. (Optional) institutional type which determined the value of the
7284: default quota.
1.472 raeburn 7285:
7286: If a value has been stored in the domain's configuration db,
7287: it will return that, otherwise it returns 20 (for backwards
7288: compatibility with domains which have not set up a configuration
7289: db file; the original statically defined portfolio quota was 20 Mb).
7290:
1.536 raeburn 7291: If the user's status includes multiple types (e.g., staff and student),
7292: the largest default quota which applies to the user determines the
7293: default quota returned.
7294:
1.780 raeburn 7295: =back
7296:
1.472 raeburn 7297: =cut
7298:
7299: ###############################################
7300:
7301:
7302: sub default_quota {
1.536 raeburn 7303: my ($udom,$inststatus) = @_;
7304: my ($defquota,$settingstatus);
7305: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7306: ['quotas'],$udom);
7307: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7308: if ($inststatus ne '') {
1.765 raeburn 7309: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7310: foreach my $item (@statuses) {
1.711 raeburn 7311: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7312: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7313: if ($defquota eq '') {
7314: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7315: $settingstatus = $item;
7316: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7317: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7318: $settingstatus = $item;
7319: }
7320: }
7321: } else {
7322: if ($quotahash{'quotas'}{$item} ne '') {
7323: if ($defquota eq '') {
7324: $defquota = $quotahash{'quotas'}{$item};
7325: $settingstatus = $item;
7326: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7327: $defquota = $quotahash{'quotas'}{$item};
7328: $settingstatus = $item;
7329: }
1.536 raeburn 7330: }
7331: }
7332: }
7333: }
7334: if ($defquota eq '') {
1.711 raeburn 7335: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7336: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7337: } else {
7338: $defquota = $quotahash{'quotas'}{'default'};
7339: }
1.536 raeburn 7340: $settingstatus = 'default';
7341: }
7342: } else {
7343: $settingstatus = 'default';
7344: $defquota = 20;
7345: }
7346: if (wantarray) {
7347: return ($defquota,$settingstatus);
1.472 raeburn 7348: } else {
1.536 raeburn 7349: return $defquota;
1.472 raeburn 7350: }
7351: }
7352:
1.384 raeburn 7353: sub get_secgrprole_info {
7354: my ($cdom,$cnum,$needroles,$type) = @_;
7355: my %sections_count = &get_sections($cdom,$cnum);
7356: my @sections = (sort {$a <=> $b} keys(%sections_count));
7357: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7358: my @groups = sort(keys(%curr_groups));
7359: my $allroles = [];
7360: my $rolehash;
7361: my $accesshash = {
7362: active => 'Currently has access',
7363: future => 'Will have future access',
7364: previous => 'Previously had access',
7365: };
7366: if ($needroles) {
7367: $rolehash = {'all' => 'all'};
1.385 albertel 7368: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7369: if (&Apache::lonnet::error(%user_roles)) {
7370: undef(%user_roles);
7371: }
7372: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7373: my ($role)=split(/\:/,$item,2);
7374: if ($role eq 'cr') { next; }
7375: if ($role =~ /^cr/) {
7376: $$rolehash{$role} = (split('/',$role))[3];
7377: } else {
7378: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7379: }
7380: }
7381: foreach my $key (sort(keys(%{$rolehash}))) {
7382: push(@{$allroles},$key);
7383: }
7384: push (@{$allroles},'st');
7385: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7386: }
7387: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7388: }
7389:
1.555 raeburn 7390: sub user_picker {
1.627 raeburn 7391: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7392: my $currdom = $dom;
7393: my %curr_selected = (
7394: srchin => 'dom',
1.580 raeburn 7395: srchby => 'lastname',
1.555 raeburn 7396: );
7397: my $srchterm;
1.625 raeburn 7398: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7399: if ($srch->{'srchby'} ne '') {
7400: $curr_selected{'srchby'} = $srch->{'srchby'};
7401: }
7402: if ($srch->{'srchin'} ne '') {
7403: $curr_selected{'srchin'} = $srch->{'srchin'};
7404: }
7405: if ($srch->{'srchtype'} ne '') {
7406: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7407: }
7408: if ($srch->{'srchdomain'} ne '') {
7409: $currdom = $srch->{'srchdomain'};
7410: }
7411: $srchterm = $srch->{'srchterm'};
7412: }
7413: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7414: 'usr' => 'Search criteria',
1.563 raeburn 7415: 'doma' => 'Domain/institution to search',
1.558 albertel 7416: 'uname' => 'username',
7417: 'lastname' => 'last name',
1.555 raeburn 7418: 'lastfirst' => 'last name, first name',
1.558 albertel 7419: 'crs' => 'in this course',
1.576 raeburn 7420: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7421: 'alc' => 'all LON-CAPA',
1.573 raeburn 7422: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7423: 'exact' => 'is',
7424: 'contains' => 'contains',
1.569 raeburn 7425: 'begins' => 'begins with',
1.571 raeburn 7426: 'youm' => "You must include some text to search for.",
7427: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7428: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7429: 'yomc' => "You must choose a domain when using an institutional directory search.",
7430: 'ymcd' => "You must choose a domain when using a domain search.",
7431: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7432: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7433: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7434: );
1.563 raeburn 7435: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7436: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7437:
7438: my @srchins = ('crs','dom','alc','instd');
7439:
7440: foreach my $option (@srchins) {
7441: # FIXME 'alc' option unavailable until
7442: # loncreateuser::print_user_query_page()
7443: # has been completed.
7444: next if ($option eq 'alc');
7445: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7446: if ($curr_selected{'srchin'} eq $option) {
7447: $srchinsel .= '
7448: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7449: } else {
7450: $srchinsel .= '
7451: <option value="'.$option.'">'.$lt{$option}.'</option>';
7452: }
1.555 raeburn 7453: }
1.563 raeburn 7454: $srchinsel .= "\n </select>\n";
1.555 raeburn 7455:
7456: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7457: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7458: if ($curr_selected{'srchby'} eq $option) {
7459: $srchbysel .= '
7460: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7461: } else {
7462: $srchbysel .= '
7463: <option value="'.$option.'">'.$lt{$option}.'</option>';
7464: }
7465: }
7466: $srchbysel .= "\n </select>\n";
7467:
7468: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7469: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7470: if ($curr_selected{'srchtype'} eq $option) {
7471: $srchtypesel .= '
7472: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7473: } else {
7474: $srchtypesel .= '
7475: <option value="'.$option.'">'.$lt{$option}.'</option>';
7476: }
7477: }
7478: $srchtypesel .= "\n </select>\n";
7479:
1.558 albertel 7480: my ($newuserscript,$new_user_create);
1.556 raeburn 7481:
7482: if ($forcenewuser) {
1.576 raeburn 7483: if (ref($srch) eq 'HASH') {
7484: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7485: if ($cancreate) {
7486: $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>';
7487: } else {
7488: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7489: my %usertypetext = (
7490: official => 'institutional',
7491: unofficial => 'non-institutional',
7492: );
7493: $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 />';
7494: }
1.576 raeburn 7495: }
7496: }
7497:
1.556 raeburn 7498: $newuserscript = <<"ENDSCRIPT";
7499:
1.570 raeburn 7500: function setSearch(createnew,callingForm) {
1.556 raeburn 7501: if (createnew == 1) {
1.570 raeburn 7502: for (var i=0; i<callingForm.srchby.length; i++) {
7503: if (callingForm.srchby.options[i].value == 'uname') {
7504: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7505: }
7506: }
1.570 raeburn 7507: for (var i=0; i<callingForm.srchin.length; i++) {
7508: if ( callingForm.srchin.options[i].value == 'dom') {
7509: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7510: }
7511: }
1.570 raeburn 7512: for (var i=0; i<callingForm.srchtype.length; i++) {
7513: if (callingForm.srchtype.options[i].value == 'exact') {
7514: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7515: }
7516: }
1.570 raeburn 7517: for (var i=0; i<callingForm.srchdomain.length; i++) {
7518: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7519: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7520: }
7521: }
7522: }
7523: }
7524: ENDSCRIPT
1.558 albertel 7525:
1.556 raeburn 7526: }
7527:
1.555 raeburn 7528: my $output = <<"END_BLOCK";
1.556 raeburn 7529: <script type="text/javascript">
1.570 raeburn 7530: function validateEntry(callingForm) {
1.558 albertel 7531:
1.556 raeburn 7532: var checkok = 1;
1.558 albertel 7533: var srchin;
1.570 raeburn 7534: for (var i=0; i<callingForm.srchin.length; i++) {
7535: if ( callingForm.srchin[i].checked ) {
7536: srchin = callingForm.srchin[i].value;
1.558 albertel 7537: }
7538: }
7539:
1.570 raeburn 7540: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7541: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7542: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7543: var srchterm = callingForm.srchterm.value;
7544: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7545: var msg = "";
7546:
7547: if (srchterm == "") {
7548: checkok = 0;
1.571 raeburn 7549: msg += "$lt{'youm'}\\n";
1.556 raeburn 7550: }
7551:
1.569 raeburn 7552: if (srchtype== 'begins') {
7553: if (srchterm.length < 2) {
7554: checkok = 0;
1.571 raeburn 7555: msg += "$lt{'thte'}\\n";
1.569 raeburn 7556: }
7557: }
7558:
1.556 raeburn 7559: if (srchtype== 'contains') {
7560: if (srchterm.length < 3) {
7561: checkok = 0;
1.571 raeburn 7562: msg += "$lt{'thet'}\\n";
1.556 raeburn 7563: }
7564: }
7565: if (srchin == 'instd') {
7566: if (srchdomain == '') {
7567: checkok = 0;
1.571 raeburn 7568: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7569: }
7570: }
7571: if (srchin == 'dom') {
7572: if (srchdomain == '') {
7573: checkok = 0;
1.571 raeburn 7574: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7575: }
7576: }
7577: if (srchby == 'lastfirst') {
7578: if (srchterm.indexOf(",") == -1) {
7579: checkok = 0;
1.571 raeburn 7580: msg += "$lt{'whus'}\\n";
1.556 raeburn 7581: }
7582: if (srchterm.indexOf(",") == srchterm.length -1) {
7583: checkok = 0;
1.571 raeburn 7584: msg += "$lt{'whse'}\\n";
1.556 raeburn 7585: }
7586: }
7587: if (checkok == 0) {
1.571 raeburn 7588: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7589: return;
7590: }
7591: if (checkok == 1) {
1.570 raeburn 7592: callingForm.submit();
1.556 raeburn 7593: }
7594: }
7595:
7596: $newuserscript
7597:
7598: </script>
1.558 albertel 7599:
7600: $new_user_create
7601:
1.555 raeburn 7602: <table>
1.558 albertel 7603: <tr>
1.573 raeburn 7604: <td>$lt{'doma'}:</td>
7605: <td>$domform</td>
7606: </td>
7607: </tr>
7608: <tr>
7609: <td>$lt{'usr'}:</td>
1.563 raeburn 7610: <td>$srchbysel
7611: $srchtypesel
7612: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7613: $srchinsel
1.563 raeburn 7614: </td>
7615: </tr>
1.555 raeburn 7616: </table>
7617: <br />
7618: END_BLOCK
1.558 albertel 7619:
1.555 raeburn 7620: return $output;
7621: }
7622:
1.612 raeburn 7623: sub user_rule_check {
1.615 raeburn 7624: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7625: my $response;
7626: if (ref($usershash) eq 'HASH') {
7627: foreach my $user (keys(%{$usershash})) {
7628: my ($uname,$udom) = split(/:/,$user);
7629: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7630: my ($id,$newuser);
1.612 raeburn 7631: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7632: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7633: $id = $usershash->{$user}->{'id'};
7634: }
7635: my $inst_response;
7636: if (ref($checks) eq 'HASH') {
7637: if (defined($checks->{'username'})) {
1.615 raeburn 7638: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7639: &Apache::lonnet::get_instuser($udom,$uname);
7640: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7641: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7642: &Apache::lonnet::get_instuser($udom,undef,$id);
7643: }
1.615 raeburn 7644: } else {
7645: ($inst_response,%{$inst_results->{$user}}) =
7646: &Apache::lonnet::get_instuser($udom,$uname);
7647: return;
1.612 raeburn 7648: }
1.615 raeburn 7649: if (!$got_rules->{$udom}) {
1.612 raeburn 7650: my %domconfig = &Apache::lonnet::get_dom('configuration',
7651: ['usercreation'],$udom);
7652: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7653: foreach my $item ('username','id') {
1.612 raeburn 7654: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7655: $$curr_rules{$udom}{$item} =
7656: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7657: }
7658: }
7659: }
1.615 raeburn 7660: $got_rules->{$udom} = 1;
1.585 raeburn 7661: }
1.612 raeburn 7662: foreach my $item (keys(%{$checks})) {
7663: if (ref($$curr_rules{$udom}) eq 'HASH') {
7664: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7665: if (@{$$curr_rules{$udom}{$item}} > 0) {
7666: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7667: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7668: if ($rule_check{$rule}) {
7669: $$rulematch{$user}{$item} = $rule;
7670: if ($inst_response eq 'ok') {
1.615 raeburn 7671: if (ref($inst_results) eq 'HASH') {
7672: if (ref($inst_results->{$user}) eq 'HASH') {
7673: if (keys(%{$inst_results->{$user}}) == 0) {
7674: $$alerts{$item}{$udom}{$uname} = 1;
7675: }
1.612 raeburn 7676: }
7677: }
1.615 raeburn 7678: }
7679: last;
1.585 raeburn 7680: }
7681: }
7682: }
7683: }
7684: }
7685: }
7686: }
7687: }
1.612 raeburn 7688: return;
7689: }
7690:
7691: sub user_rule_formats {
7692: my ($domain,$domdesc,$curr_rules,$check) = @_;
7693: my %text = (
7694: 'username' => 'Usernames',
7695: 'id' => 'IDs',
7696: );
7697: my $output;
7698: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7699: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7700: if (@{$ruleorder} > 0) {
7701: $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>';
7702: foreach my $rule (@{$ruleorder}) {
7703: if (ref($curr_rules) eq 'ARRAY') {
7704: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7705: if (ref($rules->{$rule}) eq 'HASH') {
7706: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7707: $rules->{$rule}{'desc'}.'</li>';
7708: }
7709: }
7710: }
7711: }
7712: $output .= '</ul>';
7713: }
7714: }
7715: return $output;
7716: }
7717:
7718: sub instrule_disallow_msg {
1.615 raeburn 7719: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7720: my $response;
7721: my %text = (
7722: item => 'username',
7723: items => 'usernames',
7724: match => 'matches',
7725: do => 'does',
7726: action => 'a username',
7727: one => 'one',
7728: );
7729: if ($count > 1) {
7730: $text{'item'} = 'usernames';
7731: $text{'match'} ='match';
7732: $text{'do'} = 'do';
7733: $text{'action'} = 'usernames',
7734: $text{'one'} = 'ones';
7735: }
7736: if ($checkitem eq 'id') {
7737: $text{'items'} = 'IDs';
7738: $text{'item'} = 'ID';
7739: $text{'action'} = 'an ID';
1.615 raeburn 7740: if ($count > 1) {
7741: $text{'item'} = 'IDs';
7742: $text{'action'} = 'IDs';
7743: }
1.612 raeburn 7744: }
1.674 bisitz 7745: $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 7746: if ($mode eq 'upload') {
7747: if ($checkitem eq 'username') {
7748: $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'}.");
7749: } elsif ($checkitem eq 'id') {
1.674 bisitz 7750: $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 7751: }
1.669 raeburn 7752: } elsif ($mode eq 'selfcreate') {
7753: if ($checkitem eq 'id') {
7754: $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.");
7755: }
1.615 raeburn 7756: } else {
7757: if ($checkitem eq 'username') {
7758: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7759: } elsif ($checkitem eq 'id') {
7760: $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.");
7761: }
1.612 raeburn 7762: }
7763: return $response;
1.585 raeburn 7764: }
7765:
1.624 raeburn 7766: sub personal_data_fieldtitles {
7767: my %fieldtitles = &Apache::lonlocal::texthash (
7768: id => 'Student/Employee ID',
7769: permanentemail => 'E-mail address',
7770: lastname => 'Last Name',
7771: firstname => 'First Name',
7772: middlename => 'Middle Name',
7773: generation => 'Generation',
7774: gen => 'Generation',
1.765 raeburn 7775: inststatus => 'Affiliation',
1.624 raeburn 7776: );
7777: return %fieldtitles;
7778: }
7779:
1.642 raeburn 7780: sub sorted_inst_types {
7781: my ($dom) = @_;
7782: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7783: my $othertitle = &mt('All users');
7784: if ($env{'request.course.id'}) {
1.668 raeburn 7785: $othertitle = &mt('Any users');
1.642 raeburn 7786: }
7787: my @types;
7788: if (ref($order) eq 'ARRAY') {
7789: @types = @{$order};
7790: }
7791: if (@types == 0) {
7792: if (ref($usertypes) eq 'HASH') {
7793: @types = sort(keys(%{$usertypes}));
7794: }
7795: }
7796: if (keys(%{$usertypes}) > 0) {
7797: $othertitle = &mt('Other users');
7798: }
7799: return ($othertitle,$usertypes,\@types);
7800: }
7801:
1.645 raeburn 7802: sub get_institutional_codes {
7803: my ($settings,$allcourses,$LC_code) = @_;
7804: # Get complete list of course sections to update
7805: my @currsections = ();
7806: my @currxlists = ();
7807: my $coursecode = $$settings{'internal.coursecode'};
7808:
7809: if ($$settings{'internal.sectionnums'} ne '') {
7810: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7811: }
7812:
7813: if ($$settings{'internal.crosslistings'} ne '') {
7814: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7815: }
7816:
7817: if (@currxlists > 0) {
7818: foreach (@currxlists) {
7819: if (m/^([^:]+):(\w*)$/) {
7820: unless (grep/^$1$/,@{$allcourses}) {
7821: push @{$allcourses},$1;
7822: $$LC_code{$1} = $2;
7823: }
7824: }
7825: }
7826: }
7827:
7828: if (@currsections > 0) {
7829: foreach (@currsections) {
7830: if (m/^(\w+):(\w*)$/) {
7831: my $sec = $coursecode.$1;
7832: my $lc_sec = $2;
7833: unless (grep/^$sec$/,@{$allcourses}) {
7834: push @{$allcourses},$sec;
7835: $$LC_code{$sec} = $lc_sec;
7836: }
7837: }
7838: }
7839: }
7840: return;
7841: }
7842:
1.112 bowersj2 7843: =pod
7844:
1.780 raeburn 7845: =head1 Slot Helpers
7846:
7847: =over 4
7848:
7849: =item * sorted_slots()
7850:
7851: Sorts an array of slot names in order of slot start time (earliest first).
7852:
7853: Inputs:
7854:
7855: =over 4
7856:
7857: slotsarr - Reference to array of unsorted slot names.
7858:
7859: slots - Reference to hash of hash, where outer hash keys are slot names.
7860:
1.549 albertel 7861: =back
7862:
1.780 raeburn 7863: Returns:
7864:
7865: =over 4
7866:
7867: sorted - An array of slot names sorted by the start time of the slot.
7868:
7869: =back
7870:
7871: =back
7872:
7873: =cut
7874:
7875:
7876: sub sorted_slots {
7877: my ($slotsarr,$slots) = @_;
7878: my @sorted;
7879: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7880: @sorted =
7881: sort {
7882: if (ref($slots->{$a}) && ref($slots->{$b})) {
7883: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7884: }
7885: if (ref($slots->{$a})) { return -1;}
7886: if (ref($slots->{$b})) { return 1;}
7887: return 0;
7888: } @{$slotsarr};
7889: }
7890: return @sorted;
7891: }
7892:
7893:
7894: =pod
7895:
1.549 albertel 7896: =head1 HTTP Helpers
7897:
7898: =over 4
7899:
1.648 raeburn 7900: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7901:
1.258 albertel 7902: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7903: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7904: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7905:
7906: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7907: $possible_names is an ref to an array of form element names. As an example:
7908: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7909: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7910:
7911: =cut
1.1 albertel 7912:
1.6 albertel 7913: sub get_unprocessed_cgi {
1.25 albertel 7914: my ($query,$possible_names)= @_;
1.26 matthew 7915: # $Apache::lonxml::debug=1;
1.356 albertel 7916: foreach my $pair (split(/&/,$query)) {
7917: my ($name, $value) = split(/=/,$pair);
1.369 www 7918: $name = &unescape($name);
1.25 albertel 7919: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7920: $value =~ tr/+/ /;
7921: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7922: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7923: }
1.16 harris41 7924: }
1.6 albertel 7925: }
7926:
1.112 bowersj2 7927: =pod
7928:
1.648 raeburn 7929: =item * &cacheheader()
1.112 bowersj2 7930:
7931: returns cache-controlling header code
7932:
7933: =cut
7934:
1.7 albertel 7935: sub cacheheader {
1.258 albertel 7936: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7937: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7938: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7939: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7940: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7941: return $output;
1.7 albertel 7942: }
7943:
1.112 bowersj2 7944: =pod
7945:
1.648 raeburn 7946: =item * &no_cache($r)
1.112 bowersj2 7947:
7948: specifies header code to not have cache
7949:
7950: =cut
7951:
1.9 albertel 7952: sub no_cache {
1.216 albertel 7953: my ($r) = @_;
7954: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7955: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7956: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7957: $r->no_cache(1);
7958: $r->header_out("Expires" => $date);
7959: $r->header_out("Pragma" => "no-cache");
1.123 www 7960: }
7961:
7962: sub content_type {
1.181 albertel 7963: my ($r,$type,$charset) = @_;
1.299 foxr 7964: if ($r) {
7965: # Note that printout.pl calls this with undef for $r.
7966: &no_cache($r);
7967: }
1.258 albertel 7968: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7969: unless ($charset) {
7970: $charset=&Apache::lonlocal::current_encoding;
7971: }
7972: if ($charset) { $type.='; charset='.$charset; }
7973: if ($r) {
7974: $r->content_type($type);
7975: } else {
7976: print("Content-type: $type\n\n");
7977: }
1.9 albertel 7978: }
1.25 albertel 7979:
1.112 bowersj2 7980: =pod
7981:
1.648 raeburn 7982: =item * &add_to_env($name,$value)
1.112 bowersj2 7983:
1.258 albertel 7984: adds $name to the %env hash with value
1.112 bowersj2 7985: $value, if $name already exists, the entry is converted to an array
7986: reference and $value is added to the array.
7987:
7988: =cut
7989:
1.25 albertel 7990: sub add_to_env {
7991: my ($name,$value)=@_;
1.258 albertel 7992: if (defined($env{$name})) {
7993: if (ref($env{$name})) {
1.25 albertel 7994: #already have multiple values
1.258 albertel 7995: push(@{ $env{$name} },$value);
1.25 albertel 7996: } else {
7997: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7998: my $first=$env{$name};
7999: undef($env{$name});
8000: push(@{ $env{$name} },$first,$value);
1.25 albertel 8001: }
8002: } else {
1.258 albertel 8003: $env{$name}=$value;
1.25 albertel 8004: }
1.31 albertel 8005: }
1.149 albertel 8006:
8007: =pod
8008:
1.648 raeburn 8009: =item * &get_env_multiple($name)
1.149 albertel 8010:
1.258 albertel 8011: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8012: values may be defined and end up as an array ref.
8013:
8014: returns an array of values
8015:
8016: =cut
8017:
8018: sub get_env_multiple {
8019: my ($name) = @_;
8020: my @values;
1.258 albertel 8021: if (defined($env{$name})) {
1.149 albertel 8022: # exists is it an array
1.258 albertel 8023: if (ref($env{$name})) {
8024: @values=@{ $env{$name} };
1.149 albertel 8025: } else {
1.258 albertel 8026: $values[0]=$env{$name};
1.149 albertel 8027: }
8028: }
8029: return(@values);
8030: }
8031:
1.660 raeburn 8032: sub ask_for_embedded_content {
8033: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8034: my $upload_output = '
8035: <form name="upload_embedded" action="'.$actionurl.'"
8036: method="post" enctype="multipart/form-data">';
8037: $upload_output .= $state;
1.661 raeburn 8038: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8039:
8040: my $num = 0;
8041: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8042: $upload_output .= &start_data_table_row().
8043: '<td>'.$embed_file.'</td><td>';
8044: if ($args->{'ignore_remote_references'}
8045: && $embed_file =~ m{^\w+://}) {
8046: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8047: } elsif ($args->{'error_on_invalid_names'}
8048: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8049:
8050: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8051:
8052: } else {
8053: $upload_output .='
1.661 raeburn 8054: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8055: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8056: my $attrib = join(':',@{$$allfiles{$embed_file}});
8057: $upload_output .=
8058: "\n\t\t".
8059: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8060: $attrib.'" />';
8061: if (exists($$codebase{$embed_file})) {
8062: $upload_output .=
8063: "\n\t\t".
8064: '<input name="codebase_'.$num.'" type="hidden" value="'.
8065: &escape($$codebase{$embed_file}).'" />';
8066: }
8067: }
8068: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8069: $num++;
8070: }
8071: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8072: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8073: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8074: '.&mt('(only files for which a location has been provided will be uploaded)').'
8075: </form>';
8076: return $upload_output;
8077: }
8078:
1.661 raeburn 8079: sub upload_embedded {
8080: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8081: $current_disk_usage) = @_;
8082: my $output;
8083: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8084: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8085: my $orig_uploaded_filename =
8086: $env{'form.embedded_item_'.$i.'.filename'};
8087:
8088: $env{'form.embedded_orig_'.$i} =
8089: &unescape($env{'form.embedded_orig_'.$i});
8090: my ($path,$fname) =
8091: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8092: # no path, whole string is fname
8093: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8094:
8095: $path = $env{'form.currentpath'}.$path;
8096: $fname = &Apache::lonnet::clean_filename($fname);
8097: # See if there is anything left
8098: next if ($fname eq '');
8099:
8100: # Check if file already exists as a file or directory.
8101: my ($state,$msg);
8102: if ($context eq 'portfolio') {
8103: my $port_path = $dirpath;
8104: if ($group ne '') {
8105: $port_path = "groups/$group/$port_path";
8106: }
8107: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8108: $dir_root,$port_path,$disk_quota,
8109: $current_disk_usage,$uname,$udom);
8110: if ($state eq 'will_exceed_quota'
8111: || $state eq 'file_locked'
8112: || $state eq 'file_exists' ) {
8113: $output .= $msg;
8114: next;
8115: }
8116: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8117: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8118: if ($state eq 'exists') {
8119: $output .= $msg;
8120: next;
8121: }
8122: }
8123: # Check if extension is valid
8124: if (($fname =~ /\.(\w+)$/) &&
8125: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8126: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8127: next;
8128: } elsif (($fname =~ /\.(\w+)$/) &&
8129: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8130: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8131: next;
8132: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8133: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8134: next;
8135: }
8136:
8137: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8138: if ($context eq 'portfolio') {
8139: my $result=
8140: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8141: $dirpath.$path);
8142: if ($result !~ m|^/uploaded/|) {
8143: $output .= '<span class="LC_error">'
8144: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8145: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8146: .'</span><br />';
8147: next;
8148: } else {
8149: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8150: $path.$fname.'</span>').'</p>';
8151: }
8152: } else {
8153: # Save the file
8154: my $target = $env{'form.embedded_item_'.$i};
8155: my $fullpath = $dir_root.$dirpath.'/'.$path;
8156: my $dest = $fullpath.$fname;
8157: my $url = $url_root.$dirpath.'/'.$path.$fname;
8158: my @parts=split(/\//,$fullpath);
8159: my $count;
8160: my $filepath = $dir_root;
8161: for ($count=4;$count<=$#parts;$count++) {
8162: $filepath .= "/$parts[$count]";
8163: if ((-e $filepath)!=1) {
8164: mkdir($filepath,0770);
8165: }
8166: }
8167: my $fh;
8168: if (!open($fh,'>'.$dest)) {
8169: &Apache::lonnet::logthis('Failed to create '.$dest);
8170: $output .= '<span class="LC_error">'.
8171: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8172: '</span><br />';
8173: } else {
8174: if (!print $fh $env{'form.embedded_item_'.$i}) {
8175: &Apache::lonnet::logthis('Failed to write to '.$dest);
8176: $output .= '<span class="LC_error">'.
8177: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8178: '</span><br />';
8179: } else {
8180: if ($context eq 'testbank') {
8181: $output .= &mt('Embedded file uploaded successfully:').
8182: ' <a href="'.$url.'">'.
8183: $orig_uploaded_filename.'</a><br />';
8184: } else {
1.705 tempelho 8185: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8186: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8187: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8188: }
8189: }
8190: close($fh);
8191: }
8192: }
8193: }
8194: return $output;
8195: }
8196:
8197: sub check_for_existing {
8198: my ($path,$fname,$element) = @_;
8199: my ($state,$msg);
8200: if (-d $path.'/'.$fname) {
8201: $state = 'exists';
8202: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8203: } elsif (-e $path.'/'.$fname) {
8204: $state = 'exists';
8205: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8206: }
8207: if ($state eq 'exists') {
8208: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8209: }
8210: return ($state,$msg);
8211: }
8212:
8213: sub check_for_upload {
8214: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8215: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8216: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8217: my $getpropath = 1;
8218: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8219: $getpropath);
8220: my $found_file = 0;
8221: my $locked_file = 0;
8222: foreach my $line (@dir_list) {
8223: my ($file_name)=split(/\&/,$line,2);
8224: if ($file_name eq $fname){
8225: $file_name = $path.$file_name;
8226: if ($group ne '') {
8227: $file_name = $group.$file_name;
8228: }
8229: $found_file = 1;
8230: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8231: $locked_file = 1;
8232: }
8233: }
8234: }
8235: if (($current_disk_usage + $filesize) > $disk_quota){
8236: my $msg = '<span class="LC_error">'.
8237: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8238: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8239: return ('will_exceed_quota',$msg);
8240: } elsif ($found_file) {
8241: if ($locked_file) {
8242: my $msg = '<span class="LC_error">';
8243: $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>');
8244: $msg .= '</span><br />';
8245: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8246: return ('file_locked',$msg);
8247: } else {
8248: my $msg = '<span class="LC_error">';
8249: $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'});
8250: $msg .= '</span>';
8251: $msg .= '<br />';
8252: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8253: return ('file_exists',$msg);
8254: }
8255: }
8256: }
8257:
1.31 albertel 8258:
1.41 ng 8259: =pod
1.45 matthew 8260:
1.464 albertel 8261: =back
1.41 ng 8262:
1.112 bowersj2 8263: =head1 CSV Upload/Handling functions
1.38 albertel 8264:
1.41 ng 8265: =over 4
8266:
1.648 raeburn 8267: =item * &upfile_store($r)
1.41 ng 8268:
8269: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8270: needs $env{'form.upfile'}
1.41 ng 8271: returns $datatoken to be put into hidden field
8272:
8273: =cut
1.31 albertel 8274:
8275: sub upfile_store {
8276: my $r=shift;
1.258 albertel 8277: $env{'form.upfile'}=~s/\r/\n/gs;
8278: $env{'form.upfile'}=~s/\f/\n/gs;
8279: $env{'form.upfile'}=~s/\n+/\n/gs;
8280: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8281:
1.258 albertel 8282: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8283: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8284: {
1.158 raeburn 8285: my $datafile = $r->dir_config('lonDaemons').
8286: '/tmp/'.$datatoken.'.tmp';
8287: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8288: print $fh $env{'form.upfile'};
1.158 raeburn 8289: close($fh);
8290: }
1.31 albertel 8291: }
8292: return $datatoken;
8293: }
8294:
1.56 matthew 8295: =pod
8296:
1.648 raeburn 8297: =item * &load_tmp_file($r)
1.41 ng 8298:
8299: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8300: needs $env{'form.datatoken'},
8301: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8302:
8303: =cut
1.31 albertel 8304:
8305: sub load_tmp_file {
8306: my $r=shift;
8307: my @studentdata=();
8308: {
1.158 raeburn 8309: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8310: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8311: if ( open(my $fh,"<$studentfile") ) {
8312: @studentdata=<$fh>;
8313: close($fh);
8314: }
1.31 albertel 8315: }
1.258 albertel 8316: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8317: }
8318:
1.56 matthew 8319: =pod
8320:
1.648 raeburn 8321: =item * &upfile_record_sep()
1.41 ng 8322:
8323: Separate uploaded file into records
8324: returns array of records,
1.258 albertel 8325: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8326:
8327: =cut
1.31 albertel 8328:
8329: sub upfile_record_sep {
1.258 albertel 8330: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8331: } else {
1.248 albertel 8332: my @records;
1.258 albertel 8333: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8334: if ($line=~/^\s*$/) { next; }
8335: push(@records,$line);
8336: }
8337: return @records;
1.31 albertel 8338: }
8339: }
8340:
1.56 matthew 8341: =pod
8342:
1.648 raeburn 8343: =item * &record_sep($record)
1.41 ng 8344:
1.258 albertel 8345: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8346:
8347: =cut
8348:
1.263 www 8349: sub takeleft {
8350: my $index=shift;
8351: return substr('0000'.$index,-4,4);
8352: }
8353:
1.31 albertel 8354: sub record_sep {
8355: my $record=shift;
8356: my %components=();
1.258 albertel 8357: if ($env{'form.upfiletype'} eq 'xml') {
8358: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8359: my $i=0;
1.356 albertel 8360: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8361: $field=~s/^(\"|\')//;
8362: $field=~s/(\"|\')$//;
1.263 www 8363: $components{&takeleft($i)}=$field;
1.31 albertel 8364: $i++;
8365: }
1.258 albertel 8366: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8367: my $i=0;
1.356 albertel 8368: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8369: $field=~s/^(\"|\')//;
8370: $field=~s/(\"|\')$//;
1.263 www 8371: $components{&takeleft($i)}=$field;
1.31 albertel 8372: $i++;
8373: }
8374: } else {
1.561 www 8375: my $separator=',';
1.480 banghart 8376: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8377: $separator=';';
1.480 banghart 8378: }
1.31 albertel 8379: my $i=0;
1.561 www 8380: # the character we are looking for to indicate the end of a quote or a record
8381: my $looking_for=$separator;
8382: # do not add the characters to the fields
8383: my $ignore=0;
8384: # we just encountered a separator (or the beginning of the record)
8385: my $just_found_separator=1;
8386: # store the field we are working on here
8387: my $field='';
8388: # work our way through all characters in record
8389: foreach my $character ($record=~/(.)/g) {
8390: if ($character eq $looking_for) {
8391: if ($character ne $separator) {
8392: # Found the end of a quote, again looking for separator
8393: $looking_for=$separator;
8394: $ignore=1;
8395: } else {
8396: # Found a separator, store away what we got
8397: $components{&takeleft($i)}=$field;
8398: $i++;
8399: $just_found_separator=1;
8400: $ignore=0;
8401: $field='';
8402: }
8403: next;
8404: }
8405: # single or double quotation marks after a separator indicate beginning of a quote
8406: # we are now looking for the end of the quote and need to ignore separators
8407: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8408: $looking_for=$character;
8409: next;
8410: }
8411: # ignore would be true after we reached the end of a quote
8412: if ($ignore) { next; }
8413: if (($just_found_separator) && ($character=~/\s/)) { next; }
8414: $field.=$character;
8415: $just_found_separator=0;
1.31 albertel 8416: }
1.561 www 8417: # catch the very last entry, since we never encountered the separator
8418: $components{&takeleft($i)}=$field;
1.31 albertel 8419: }
8420: return %components;
8421: }
8422:
1.144 matthew 8423: ######################################################
8424: ######################################################
8425:
1.56 matthew 8426: =pod
8427:
1.648 raeburn 8428: =item * &upfile_select_html()
1.41 ng 8429:
1.144 matthew 8430: Return HTML code to select a file from the users machine and specify
8431: the file type.
1.41 ng 8432:
8433: =cut
8434:
1.144 matthew 8435: ######################################################
8436: ######################################################
1.31 albertel 8437: sub upfile_select_html {
1.144 matthew 8438: my %Types = (
8439: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8440: semisv => &mt('Semicolon separated values'),
1.144 matthew 8441: space => &mt('Space separated'),
8442: tab => &mt('Tabulator separated'),
8443: # xml => &mt('HTML/XML'),
8444: );
8445: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8446: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8447: foreach my $type (sort(keys(%Types))) {
8448: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8449: }
8450: $Str .= "</select>\n";
8451: return $Str;
1.31 albertel 8452: }
8453:
1.301 albertel 8454: sub get_samples {
8455: my ($records,$toget) = @_;
8456: my @samples=({});
8457: my $got=0;
8458: foreach my $rec (@$records) {
8459: my %temp = &record_sep($rec);
8460: if (! grep(/\S/, values(%temp))) { next; }
8461: if (%temp) {
8462: $samples[$got]=\%temp;
8463: $got++;
8464: if ($got == $toget) { last; }
8465: }
8466: }
8467: return \@samples;
8468: }
8469:
1.144 matthew 8470: ######################################################
8471: ######################################################
8472:
1.56 matthew 8473: =pod
8474:
1.648 raeburn 8475: =item * &csv_print_samples($r,$records)
1.41 ng 8476:
8477: Prints a table of sample values from each column uploaded $r is an
8478: Apache Request ref, $records is an arrayref from
8479: &Apache::loncommon::upfile_record_sep
8480:
8481: =cut
8482:
1.144 matthew 8483: ######################################################
8484: ######################################################
1.31 albertel 8485: sub csv_print_samples {
8486: my ($r,$records) = @_;
1.662 bisitz 8487: my $samples = &get_samples($records,5);
1.301 albertel 8488:
1.594 raeburn 8489: $r->print(&mt('Samples').'<br />'.&start_data_table().
8490: &start_data_table_header_row());
1.356 albertel 8491: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8492: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8493: $r->print(&end_data_table_header_row());
1.301 albertel 8494: foreach my $hash (@$samples) {
1.594 raeburn 8495: $r->print(&start_data_table_row());
1.356 albertel 8496: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8497: $r->print('<td>');
1.356 albertel 8498: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8499: $r->print('</td>');
8500: }
1.594 raeburn 8501: $r->print(&end_data_table_row());
1.31 albertel 8502: }
1.594 raeburn 8503: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8504: }
8505:
1.144 matthew 8506: ######################################################
8507: ######################################################
8508:
1.56 matthew 8509: =pod
8510:
1.648 raeburn 8511: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8512:
8513: Prints a table to create associations between values and table columns.
1.144 matthew 8514:
1.41 ng 8515: $r is an Apache Request ref,
8516: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8517: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8518:
8519: =cut
8520:
1.144 matthew 8521: ######################################################
8522: ######################################################
1.31 albertel 8523: sub csv_print_select_table {
8524: my ($r,$records,$d) = @_;
1.301 albertel 8525: my $i=0;
8526: my $samples = &get_samples($records,1);
1.144 matthew 8527: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8528: &start_data_table().&start_data_table_header_row().
1.144 matthew 8529: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8530: '<th>'.&mt('Column').'</th>'.
8531: &end_data_table_header_row()."\n");
1.356 albertel 8532: foreach my $array_ref (@$d) {
8533: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8534: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8535:
8536: $r->print('<td><select name=f'.$i.
1.32 matthew 8537: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8538: $r->print('<option value="none"></option>');
1.356 albertel 8539: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8540: $r->print('<option value="'.$sample.'"'.
8541: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8542: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8543: }
1.594 raeburn 8544: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8545: $i++;
8546: }
1.594 raeburn 8547: $r->print(&end_data_table());
1.31 albertel 8548: $i--;
8549: return $i;
8550: }
1.56 matthew 8551:
1.144 matthew 8552: ######################################################
8553: ######################################################
8554:
1.56 matthew 8555: =pod
1.31 albertel 8556:
1.648 raeburn 8557: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8558:
8559: Prints a table of sample values from the upload and can make associate samples to internal names.
8560:
8561: $r is an Apache Request ref,
8562: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8563: $d is an array of 2 element arrays (internal name, displayed name)
8564:
8565: =cut
8566:
1.144 matthew 8567: ######################################################
8568: ######################################################
1.31 albertel 8569: sub csv_samples_select_table {
8570: my ($r,$records,$d) = @_;
8571: my $i=0;
1.144 matthew 8572: #
1.662 bisitz 8573: my $max_samples = 5;
8574: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8575: $r->print(&start_data_table().
8576: &start_data_table_header_row().'<th>'.
8577: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8578: &end_data_table_header_row());
1.301 albertel 8579:
8580: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8581: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8582: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8583: foreach my $option (@$d) {
8584: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8585: $r->print('<option value="'.$value.'"'.
1.253 albertel 8586: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8587: $display.'</option>');
1.31 albertel 8588: }
8589: $r->print('</select></td><td>');
1.662 bisitz 8590: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8591: if (defined($samples->[$line]{$key})) {
8592: $r->print($samples->[$line]{$key}."<br />\n");
8593: }
8594: }
1.594 raeburn 8595: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8596: $i++;
8597: }
1.594 raeburn 8598: $r->print(&end_data_table());
1.31 albertel 8599: $i--;
8600: return($i);
1.115 matthew 8601: }
8602:
1.144 matthew 8603: ######################################################
8604: ######################################################
8605:
1.115 matthew 8606: =pod
8607:
1.648 raeburn 8608: =item * &clean_excel_name($name)
1.115 matthew 8609:
8610: Returns a replacement for $name which does not contain any illegal characters.
8611:
8612: =cut
8613:
1.144 matthew 8614: ######################################################
8615: ######################################################
1.115 matthew 8616: sub clean_excel_name {
8617: my ($name) = @_;
8618: $name =~ s/[:\*\?\/\\]//g;
8619: if (length($name) > 31) {
8620: $name = substr($name,0,31);
8621: }
8622: return $name;
1.25 albertel 8623: }
1.84 albertel 8624:
1.85 albertel 8625: =pod
8626:
1.648 raeburn 8627: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8628:
8629: Returns either 1 or undef
8630:
8631: 1 if the part is to be hidden, undef if it is to be shown
8632:
8633: Arguments are:
8634:
8635: $id the id of the part to be checked
8636: $symb, optional the symb of the resource to check
8637: $udom, optional the domain of the user to check for
8638: $uname, optional the username of the user to check for
8639:
8640: =cut
1.84 albertel 8641:
8642: sub check_if_partid_hidden {
8643: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8644: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8645: $symb,$udom,$uname);
1.141 albertel 8646: my $truth=1;
8647: #if the string starts with !, then the list is the list to show not hide
8648: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8649: my @hiddenlist=split(/,/,$hiddenparts);
8650: foreach my $checkid (@hiddenlist) {
1.141 albertel 8651: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8652: }
1.141 albertel 8653: return !$truth;
1.84 albertel 8654: }
1.127 matthew 8655:
1.138 matthew 8656:
8657: ############################################################
8658: ############################################################
8659:
8660: =pod
8661:
1.157 matthew 8662: =back
8663:
1.138 matthew 8664: =head1 cgi-bin script and graphing routines
8665:
1.157 matthew 8666: =over 4
8667:
1.648 raeburn 8668: =item * &get_cgi_id()
1.138 matthew 8669:
8670: Inputs: none
8671:
8672: Returns an id which can be used to pass environment variables
8673: to various cgi-bin scripts. These environment variables will
8674: be removed from the users environment after a given time by
8675: the routine &Apache::lonnet::transfer_profile_to_env.
8676:
8677: =cut
8678:
8679: ############################################################
8680: ############################################################
1.152 albertel 8681: my $uniq=0;
1.136 matthew 8682: sub get_cgi_id {
1.154 albertel 8683: $uniq=($uniq+1)%100000;
1.280 albertel 8684: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8685: }
8686:
1.127 matthew 8687: ############################################################
8688: ############################################################
8689:
8690: =pod
8691:
1.648 raeburn 8692: =item * &DrawBarGraph()
1.127 matthew 8693:
1.138 matthew 8694: Facilitates the plotting of data in a (stacked) bar graph.
8695: Puts plot definition data into the users environment in order for
8696: graph.png to plot it. Returns an <img> tag for the plot.
8697: The bars on the plot are labeled '1','2',...,'n'.
8698:
8699: Inputs:
8700:
8701: =over 4
8702:
8703: =item $Title: string, the title of the plot
8704:
8705: =item $xlabel: string, text describing the X-axis of the plot
8706:
8707: =item $ylabel: string, text describing the Y-axis of the plot
8708:
8709: =item $Max: scalar, the maximum Y value to use in the plot
8710: If $Max is < any data point, the graph will not be rendered.
8711:
1.140 matthew 8712: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8713: they are plotted. If undefined, default values will be used.
8714:
1.178 matthew 8715: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8716:
1.138 matthew 8717: =item @Values: An array of array references. Each array reference holds data
8718: to be plotted in a stacked bar chart.
8719:
1.239 matthew 8720: =item If the final element of @Values is a hash reference the key/value
8721: pairs will be added to the graph definition.
8722:
1.138 matthew 8723: =back
8724:
8725: Returns:
8726:
8727: An <img> tag which references graph.png and the appropriate identifying
8728: information for the plot.
8729:
1.127 matthew 8730: =cut
8731:
8732: ############################################################
8733: ############################################################
1.134 matthew 8734: sub DrawBarGraph {
1.178 matthew 8735: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8736: #
8737: if (! defined($colors)) {
8738: $colors = ['#33ff00',
8739: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8740: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8741: ];
8742: }
1.228 matthew 8743: my $extra_settings = {};
8744: if (ref($Values[-1]) eq 'HASH') {
8745: $extra_settings = pop(@Values);
8746: }
1.127 matthew 8747: #
1.136 matthew 8748: my $identifier = &get_cgi_id();
8749: my $id = 'cgi.'.$identifier;
1.129 matthew 8750: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8751: return '';
8752: }
1.225 matthew 8753: #
8754: my @Labels;
8755: if (defined($labels)) {
8756: @Labels = @$labels;
8757: } else {
8758: for (my $i=0;$i<@{$Values[0]};$i++) {
8759: push (@Labels,$i+1);
8760: }
8761: }
8762: #
1.129 matthew 8763: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8764: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8765: my %ValuesHash;
8766: my $NumSets=1;
8767: foreach my $array (@Values) {
8768: next if (! ref($array));
1.136 matthew 8769: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8770: join(',',@$array);
1.129 matthew 8771: }
1.127 matthew 8772: #
1.136 matthew 8773: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8774: if ($NumBars < 3) {
8775: $width = 120+$NumBars*32;
1.220 matthew 8776: $xskip = 1;
1.225 matthew 8777: $bar_width = 30;
8778: } elsif ($NumBars < 5) {
8779: $width = 120+$NumBars*20;
8780: $xskip = 1;
8781: $bar_width = 20;
1.220 matthew 8782: } elsif ($NumBars < 10) {
1.136 matthew 8783: $width = 120+$NumBars*15;
8784: $xskip = 1;
8785: $bar_width = 15;
8786: } elsif ($NumBars <= 25) {
8787: $width = 120+$NumBars*11;
8788: $xskip = 5;
8789: $bar_width = 8;
8790: } elsif ($NumBars <= 50) {
8791: $width = 120+$NumBars*8;
8792: $xskip = 5;
8793: $bar_width = 4;
8794: } else {
8795: $width = 120+$NumBars*8;
8796: $xskip = 5;
8797: $bar_width = 4;
8798: }
8799: #
1.137 matthew 8800: $Max = 1 if ($Max < 1);
8801: if ( int($Max) < $Max ) {
8802: $Max++;
8803: $Max = int($Max);
8804: }
1.127 matthew 8805: $Title = '' if (! defined($Title));
8806: $xlabel = '' if (! defined($xlabel));
8807: $ylabel = '' if (! defined($ylabel));
1.369 www 8808: $ValuesHash{$id.'.title'} = &escape($Title);
8809: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8810: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8811: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8812: $ValuesHash{$id.'.NumBars'} = $NumBars;
8813: $ValuesHash{$id.'.NumSets'} = $NumSets;
8814: $ValuesHash{$id.'.PlotType'} = 'bar';
8815: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8816: $ValuesHash{$id.'.height'} = $height;
8817: $ValuesHash{$id.'.width'} = $width;
8818: $ValuesHash{$id.'.xskip'} = $xskip;
8819: $ValuesHash{$id.'.bar_width'} = $bar_width;
8820: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8821: #
1.228 matthew 8822: # Deal with other parameters
8823: while (my ($key,$value) = each(%$extra_settings)) {
8824: $ValuesHash{$id.'.'.$key} = $value;
8825: }
8826: #
1.646 raeburn 8827: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8828: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8829: }
8830:
8831: ############################################################
8832: ############################################################
8833:
8834: =pod
8835:
1.648 raeburn 8836: =item * &DrawXYGraph()
1.137 matthew 8837:
1.138 matthew 8838: Facilitates the plotting of data in an XY graph.
8839: Puts plot definition data into the users environment in order for
8840: graph.png to plot it. Returns an <img> tag for the plot.
8841:
8842: Inputs:
8843:
8844: =over 4
8845:
8846: =item $Title: string, the title of the plot
8847:
8848: =item $xlabel: string, text describing the X-axis of the plot
8849:
8850: =item $ylabel: string, text describing the Y-axis of the plot
8851:
8852: =item $Max: scalar, the maximum Y value to use in the plot
8853: If $Max is < any data point, the graph will not be rendered.
8854:
8855: =item $colors: Array ref containing the hex color codes for the data to be
8856: plotted in. If undefined, default values will be used.
8857:
8858: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8859:
8860: =item $Ydata: Array ref containing Array refs.
1.185 www 8861: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8862:
8863: =item %Values: hash indicating or overriding any default values which are
8864: passed to graph.png.
8865: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8866:
8867: =back
8868:
8869: Returns:
8870:
8871: An <img> tag which references graph.png and the appropriate identifying
8872: information for the plot.
8873:
1.137 matthew 8874: =cut
8875:
8876: ############################################################
8877: ############################################################
8878: sub DrawXYGraph {
8879: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8880: #
8881: # Create the identifier for the graph
8882: my $identifier = &get_cgi_id();
8883: my $id = 'cgi.'.$identifier;
8884: #
8885: $Title = '' if (! defined($Title));
8886: $xlabel = '' if (! defined($xlabel));
8887: $ylabel = '' if (! defined($ylabel));
8888: my %ValuesHash =
8889: (
1.369 www 8890: $id.'.title' => &escape($Title),
8891: $id.'.xlabel' => &escape($xlabel),
8892: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8893: $id.'.y_max_value'=> $Max,
8894: $id.'.labels' => join(',',@$Xlabels),
8895: $id.'.PlotType' => 'XY',
8896: );
8897: #
8898: if (defined($colors) && ref($colors) eq 'ARRAY') {
8899: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8900: }
8901: #
8902: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8903: return '';
8904: }
8905: my $NumSets=1;
1.138 matthew 8906: foreach my $array (@{$Ydata}){
1.137 matthew 8907: next if (! ref($array));
8908: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8909: }
1.138 matthew 8910: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8911: #
8912: # Deal with other parameters
8913: while (my ($key,$value) = each(%Values)) {
8914: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8915: }
8916: #
1.646 raeburn 8917: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8918: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8919: }
8920:
8921: ############################################################
8922: ############################################################
8923:
8924: =pod
8925:
1.648 raeburn 8926: =item * &DrawXYYGraph()
1.138 matthew 8927:
8928: Facilitates the plotting of data in an XY graph with two Y axes.
8929: Puts plot definition data into the users environment in order for
8930: graph.png to plot it. Returns an <img> tag for the plot.
8931:
8932: Inputs:
8933:
8934: =over 4
8935:
8936: =item $Title: string, the title of the plot
8937:
8938: =item $xlabel: string, text describing the X-axis of the plot
8939:
8940: =item $ylabel: string, text describing the Y-axis of the plot
8941:
8942: =item $colors: Array ref containing the hex color codes for the data to be
8943: plotted in. If undefined, default values will be used.
8944:
8945: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8946:
8947: =item $Ydata1: The first data set
8948:
8949: =item $Min1: The minimum value of the left Y-axis
8950:
8951: =item $Max1: The maximum value of the left Y-axis
8952:
8953: =item $Ydata2: The second data set
8954:
8955: =item $Min2: The minimum value of the right Y-axis
8956:
8957: =item $Max2: The maximum value of the left Y-axis
8958:
8959: =item %Values: hash indicating or overriding any default values which are
8960: passed to graph.png.
8961: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8962:
8963: =back
8964:
8965: Returns:
8966:
8967: An <img> tag which references graph.png and the appropriate identifying
8968: information for the plot.
1.136 matthew 8969:
8970: =cut
8971:
8972: ############################################################
8973: ############################################################
1.137 matthew 8974: sub DrawXYYGraph {
8975: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8976: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8977: #
8978: # Create the identifier for the graph
8979: my $identifier = &get_cgi_id();
8980: my $id = 'cgi.'.$identifier;
8981: #
8982: $Title = '' if (! defined($Title));
8983: $xlabel = '' if (! defined($xlabel));
8984: $ylabel = '' if (! defined($ylabel));
8985: my %ValuesHash =
8986: (
1.369 www 8987: $id.'.title' => &escape($Title),
8988: $id.'.xlabel' => &escape($xlabel),
8989: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8990: $id.'.labels' => join(',',@$Xlabels),
8991: $id.'.PlotType' => 'XY',
8992: $id.'.NumSets' => 2,
1.137 matthew 8993: $id.'.two_axes' => 1,
8994: $id.'.y1_max_value' => $Max1,
8995: $id.'.y1_min_value' => $Min1,
8996: $id.'.y2_max_value' => $Max2,
8997: $id.'.y2_min_value' => $Min2,
1.136 matthew 8998: );
8999: #
1.137 matthew 9000: if (defined($colors) && ref($colors) eq 'ARRAY') {
9001: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9002: }
9003: #
9004: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9005: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9006: return '';
9007: }
9008: my $NumSets=1;
1.137 matthew 9009: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9010: next if (! ref($array));
9011: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9012: }
9013: #
9014: # Deal with other parameters
9015: while (my ($key,$value) = each(%Values)) {
9016: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9017: }
9018: #
1.646 raeburn 9019: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9020: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9021: }
9022:
9023: ############################################################
9024: ############################################################
9025:
9026: =pod
9027:
1.157 matthew 9028: =back
9029:
1.139 matthew 9030: =head1 Statistics helper routines?
9031:
9032: Bad place for them but what the hell.
9033:
1.157 matthew 9034: =over 4
9035:
1.648 raeburn 9036: =item * &chartlink()
1.139 matthew 9037:
9038: Returns a link to the chart for a specific student.
9039:
9040: Inputs:
9041:
9042: =over 4
9043:
9044: =item $linktext: The text of the link
9045:
9046: =item $sname: The students username
9047:
9048: =item $sdomain: The students domain
9049:
9050: =back
9051:
1.157 matthew 9052: =back
9053:
1.139 matthew 9054: =cut
9055:
9056: ############################################################
9057: ############################################################
9058: sub chartlink {
9059: my ($linktext, $sname, $sdomain) = @_;
9060: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9061: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9062: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9063: '">'.$linktext.'</a>';
1.153 matthew 9064: }
9065:
9066: #######################################################
9067: #######################################################
9068:
9069: =pod
9070:
9071: =head1 Course Environment Routines
1.157 matthew 9072:
9073: =over 4
1.153 matthew 9074:
1.648 raeburn 9075: =item * &restore_course_settings()
1.153 matthew 9076:
1.648 raeburn 9077: =item * &store_course_settings()
1.153 matthew 9078:
9079: Restores/Store indicated form parameters from the course environment.
9080: Will not overwrite existing values of the form parameters.
9081:
9082: Inputs:
9083: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9084:
9085: a hash ref describing the data to be stored. For example:
9086:
9087: %Save_Parameters = ('Status' => 'scalar',
9088: 'chartoutputmode' => 'scalar',
9089: 'chartoutputdata' => 'scalar',
9090: 'Section' => 'array',
1.373 raeburn 9091: 'Group' => 'array',
1.153 matthew 9092: 'StudentData' => 'array',
9093: 'Maps' => 'array');
9094:
9095: Returns: both routines return nothing
9096:
1.631 raeburn 9097: =back
9098:
1.153 matthew 9099: =cut
9100:
9101: #######################################################
9102: #######################################################
9103: sub store_course_settings {
1.496 albertel 9104: return &store_settings($env{'request.course.id'},@_);
9105: }
9106:
9107: sub store_settings {
1.153 matthew 9108: # save to the environment
9109: # appenv the same items, just to be safe
1.300 albertel 9110: my $udom = $env{'user.domain'};
9111: my $uname = $env{'user.name'};
1.496 albertel 9112: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9113: my %SaveHash;
9114: my %AppHash;
9115: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9116: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9117: my $envname = 'environment.'.$basename;
1.258 albertel 9118: if (exists($env{'form.'.$setting})) {
1.153 matthew 9119: # Save this value away
9120: if ($type eq 'scalar' &&
1.258 albertel 9121: (! exists($env{$envname}) ||
9122: $env{$envname} ne $env{'form.'.$setting})) {
9123: $SaveHash{$basename} = $env{'form.'.$setting};
9124: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9125: } elsif ($type eq 'array') {
9126: my $stored_form;
1.258 albertel 9127: if (ref($env{'form.'.$setting})) {
1.153 matthew 9128: $stored_form = join(',',
9129: map {
1.369 www 9130: &escape($_);
1.258 albertel 9131: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9132: } else {
9133: $stored_form =
1.369 www 9134: &escape($env{'form.'.$setting});
1.153 matthew 9135: }
9136: # Determine if the array contents are the same.
1.258 albertel 9137: if ($stored_form ne $env{$envname}) {
1.153 matthew 9138: $SaveHash{$basename} = $stored_form;
9139: $AppHash{$envname} = $stored_form;
9140: }
9141: }
9142: }
9143: }
9144: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9145: $udom,$uname);
1.153 matthew 9146: if ($put_result !~ /^(ok|delayed)/) {
9147: &Apache::lonnet::logthis('unable to save form parameters, '.
9148: 'got error:'.$put_result);
9149: }
9150: # Make sure these settings stick around in this session, too
1.646 raeburn 9151: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9152: return;
9153: }
9154:
9155: sub restore_course_settings {
1.499 albertel 9156: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9157: }
9158:
9159: sub restore_settings {
9160: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9161: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9162: next if (exists($env{'form.'.$setting}));
1.496 albertel 9163: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9164: '.'.$setting;
1.258 albertel 9165: if (exists($env{$envname})) {
1.153 matthew 9166: if ($type eq 'scalar') {
1.258 albertel 9167: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9168: } elsif ($type eq 'array') {
1.258 albertel 9169: $env{'form.'.$setting} = [
1.153 matthew 9170: map {
1.369 www 9171: &unescape($_);
1.258 albertel 9172: } split(',',$env{$envname})
1.153 matthew 9173: ];
9174: }
9175: }
9176: }
1.127 matthew 9177: }
9178:
1.618 raeburn 9179: #######################################################
9180: #######################################################
9181:
9182: =pod
9183:
9184: =head1 Domain E-mail Routines
9185:
9186: =over 4
9187:
1.648 raeburn 9188: =item * &build_recipient_list()
1.618 raeburn 9189:
1.766 raeburn 9190: Build recipient lists for four types of e-mail:
9191: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
9192: (d) Help requests, generated by
9193: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 9194:
9195: Inputs:
1.619 raeburn 9196: defmail (scalar - email address of default recipient),
1.618 raeburn 9197: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9198: defdom (domain for which to retrieve configuration settings),
9199: origmail (scalar - email address of recipient from loncapa.conf,
9200: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9201:
1.655 raeburn 9202: Returns: comma separated list of addresses to which to send e-mail.
9203:
9204: =back
1.618 raeburn 9205:
9206: =cut
9207:
9208: ############################################################
9209: ############################################################
9210: sub build_recipient_list {
1.619 raeburn 9211: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9212: my @recipients;
9213: my $otheremails;
9214: my %domconfig =
9215: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9216: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9217: if (exists($domconfig{'contacts'}{$mailing})) {
9218: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9219: my @contacts = ('adminemail','supportemail');
9220: foreach my $item (@contacts) {
9221: if ($domconfig{'contacts'}{$mailing}{$item}) {
9222: my $addr = $domconfig{'contacts'}{$item};
9223: if (!grep(/^\Q$addr\E$/,@recipients)) {
9224: push(@recipients,$addr);
9225: }
1.619 raeburn 9226: }
1.766 raeburn 9227: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9228: }
9229: }
1.766 raeburn 9230: } elsif ($origmail ne '') {
9231: push(@recipients,$origmail);
1.618 raeburn 9232: }
1.619 raeburn 9233: } elsif ($origmail ne '') {
9234: push(@recipients,$origmail);
1.618 raeburn 9235: }
1.688 raeburn 9236: if (defined($defmail)) {
9237: if ($defmail ne '') {
9238: push(@recipients,$defmail);
9239: }
1.618 raeburn 9240: }
9241: if ($otheremails) {
1.619 raeburn 9242: my @others;
9243: if ($otheremails =~ /,/) {
9244: @others = split(/,/,$otheremails);
1.618 raeburn 9245: } else {
1.619 raeburn 9246: push(@others,$otheremails);
9247: }
9248: foreach my $addr (@others) {
9249: if (!grep(/^\Q$addr\E$/,@recipients)) {
9250: push(@recipients,$addr);
9251: }
1.618 raeburn 9252: }
9253: }
1.619 raeburn 9254: my $recipientlist = join(',',@recipients);
1.618 raeburn 9255: return $recipientlist;
9256: }
9257:
1.127 matthew 9258: ############################################################
9259: ############################################################
1.154 albertel 9260:
1.655 raeburn 9261: =pod
9262:
9263: =head1 Course Catalog Routines
9264:
9265: =over 4
9266:
9267: =item * &gather_categories()
9268:
9269: Converts category definitions - keys of categories hash stored in
9270: coursecategories in configuration.db on the primary library server in a
9271: domain - to an array. Also generates javascript and idx hash used to
9272: generate Domain Coordinator interface for editing Course Categories.
9273:
9274: Inputs:
1.663 raeburn 9275:
1.655 raeburn 9276: categories (reference to hash of category definitions).
1.663 raeburn 9277:
1.655 raeburn 9278: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9279: categories and subcategories).
1.663 raeburn 9280:
1.655 raeburn 9281: idx (reference to hash of counters used in Domain Coordinator interface for
9282: editing Course Categories).
1.663 raeburn 9283:
1.655 raeburn 9284: jsarray (reference to array of categories used to create Javascript arrays for
9285: Domain Coordinator interface for editing Course Categories).
9286:
9287: Returns: nothing
9288:
9289: Side effects: populates cats, idx and jsarray.
9290:
9291: =cut
9292:
9293: sub gather_categories {
9294: my ($categories,$cats,$idx,$jsarray) = @_;
9295: my %counters;
9296: my $num = 0;
9297: foreach my $item (keys(%{$categories})) {
9298: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9299: if ($container eq '' && $depth == 0) {
9300: $cats->[$depth][$categories->{$item}] = $cat;
9301: } else {
9302: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9303: }
9304: my ($escitem,$tail) = split(/:/,$item,2);
9305: if ($counters{$tail} eq '') {
9306: $counters{$tail} = $num;
9307: $num ++;
9308: }
9309: if (ref($idx) eq 'HASH') {
9310: $idx->{$item} = $counters{$tail};
9311: }
9312: if (ref($jsarray) eq 'ARRAY') {
9313: push(@{$jsarray->[$counters{$tail}]},$item);
9314: }
9315: }
9316: return;
9317: }
9318:
9319: =pod
9320:
9321: =item * &extract_categories()
9322:
9323: Used to generate breadcrumb trails for course categories.
9324:
9325: Inputs:
1.663 raeburn 9326:
1.655 raeburn 9327: categories (reference to hash of category definitions).
1.663 raeburn 9328:
1.655 raeburn 9329: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9330: categories and subcategories).
1.663 raeburn 9331:
1.655 raeburn 9332: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9333:
1.655 raeburn 9334: allitems (reference to hash - key is category key
9335: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9336:
1.655 raeburn 9337: idx (reference to hash of counters used in Domain Coordinator interface for
9338: editing Course Categories).
1.663 raeburn 9339:
1.655 raeburn 9340: jsarray (reference to array of categories used to create Javascript arrays for
9341: Domain Coordinator interface for editing Course Categories).
9342:
1.665 raeburn 9343: subcats (reference to hash of arrays containing all subcategories within each
9344: category, -recursive)
9345:
1.655 raeburn 9346: Returns: nothing
9347:
9348: Side effects: populates trails and allitems hash references.
9349:
9350: =cut
9351:
9352: sub extract_categories {
1.665 raeburn 9353: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9354: if (ref($categories) eq 'HASH') {
9355: &gather_categories($categories,$cats,$idx,$jsarray);
9356: if (ref($cats->[0]) eq 'ARRAY') {
9357: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9358: my $name = $cats->[0][$i];
9359: my $item = &escape($name).'::0';
9360: my $trailstr;
9361: if ($name eq 'instcode') {
9362: $trailstr = &mt('Official courses (with institutional codes)');
9363: } else {
9364: $trailstr = $name;
9365: }
9366: if ($allitems->{$item} eq '') {
9367: push(@{$trails},$trailstr);
9368: $allitems->{$item} = scalar(@{$trails})-1;
9369: }
9370: my @parents = ($name);
9371: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9372: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9373: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9374: if (ref($subcats) eq 'HASH') {
9375: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9376: }
9377: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9378: }
9379: } else {
9380: if (ref($subcats) eq 'HASH') {
9381: $subcats->{$item} = [];
1.655 raeburn 9382: }
9383: }
9384: }
9385: }
9386: }
9387: return;
9388: }
9389:
9390: =pod
9391:
9392: =item *&recurse_categories()
9393:
9394: Recursively used to generate breadcrumb trails for course categories.
9395:
9396: Inputs:
1.663 raeburn 9397:
1.655 raeburn 9398: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9399: categories and subcategories).
1.663 raeburn 9400:
1.655 raeburn 9401: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9402:
9403: category (current course category, for which breadcrumb trail is being generated).
9404:
9405: trails (reference to array of breadcrumb trails for each category).
9406:
1.655 raeburn 9407: allitems (reference to hash - key is category key
9408: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9409:
1.655 raeburn 9410: parents (array containing containers directories for current category,
9411: back to top level).
9412:
9413: Returns: nothing
9414:
9415: Side effects: populates trails and allitems hash references
9416:
9417: =cut
9418:
9419: sub recurse_categories {
1.665 raeburn 9420: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9421: my $shallower = $depth - 1;
9422: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9423: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9424: my $name = $cats->[$depth]{$category}[$k];
9425: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9426: my $trailstr = join(' -> ',(@{$parents},$category));
9427: if ($allitems->{$item} eq '') {
9428: push(@{$trails},$trailstr);
9429: $allitems->{$item} = scalar(@{$trails})-1;
9430: }
9431: my $deeper = $depth+1;
9432: push(@{$parents},$category);
1.665 raeburn 9433: if (ref($subcats) eq 'HASH') {
9434: my $subcat = &escape($name).':'.$category.':'.$depth;
9435: for (my $j=@{$parents}; $j>=0; $j--) {
9436: my $higher;
9437: if ($j > 0) {
9438: $higher = &escape($parents->[$j]).':'.
9439: &escape($parents->[$j-1]).':'.$j;
9440: } else {
9441: $higher = &escape($parents->[$j]).'::'.$j;
9442: }
9443: push(@{$subcats->{$higher}},$subcat);
9444: }
9445: }
9446: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9447: $subcats);
1.655 raeburn 9448: pop(@{$parents});
9449: }
9450: } else {
9451: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9452: my $trailstr = join(' -> ',(@{$parents},$category));
9453: if ($allitems->{$item} eq '') {
9454: push(@{$trails},$trailstr);
9455: $allitems->{$item} = scalar(@{$trails})-1;
9456: }
9457: }
9458: return;
9459: }
9460:
1.663 raeburn 9461: =pod
9462:
9463: =item *&assign_categories_table()
9464:
9465: Create a datatable for display of hierarchical categories in a domain,
9466: with checkboxes to allow a course to be categorized.
9467:
9468: Inputs:
9469:
9470: cathash - reference to hash of categories defined for the domain (from
9471: configuration.db)
9472:
9473: currcat - scalar with an & separated list of categories assigned to a course.
9474:
9475: Returns: $output (markup to be displayed)
9476:
9477: =cut
9478:
9479: sub assign_categories_table {
9480: my ($cathash,$currcat) = @_;
9481: my $output;
9482: if (ref($cathash) eq 'HASH') {
9483: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9484: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9485: $maxdepth = scalar(@cats);
9486: if (@cats > 0) {
9487: my $itemcount = 0;
9488: if (ref($cats[0]) eq 'ARRAY') {
9489: $output = &Apache::loncommon::start_data_table();
9490: my @currcategories;
9491: if ($currcat ne '') {
9492: @currcategories = split('&',$currcat);
9493: }
9494: for (my $i=0; $i<@{$cats[0]}; $i++) {
9495: my $parent = $cats[0][$i];
9496: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9497: next if ($parent eq 'instcode');
9498: my $item = &escape($parent).'::0';
9499: my $checked = '';
9500: if (@currcategories > 0) {
9501: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9502: $checked = ' checked="checked"';
1.663 raeburn 9503: }
9504: }
1.675 raeburn 9505: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9506: '<input type="checkbox" name="usecategory" value="'.
9507: $item.'"'.$checked.' />'.$parent.'</span>'.
9508: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9509: my $depth = 1;
9510: push(@path,$parent);
9511: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9512: pop(@path);
9513: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9514: $itemcount ++;
9515: }
9516: $output .= &Apache::loncommon::end_data_table();
9517: }
9518: }
9519: }
9520: return $output;
9521: }
9522:
9523: =pod
9524:
9525: =item *&assign_category_rows()
9526:
9527: Create a datatable row for display of nested categories in a domain,
9528: with checkboxes to allow a course to be categorized,called recursively.
9529:
9530: Inputs:
9531:
9532: itemcount - track row number for alternating colors
9533:
9534: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9535: categories and subcategories.
9536:
9537: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9538:
9539: parent - parent of current category item
9540:
9541: path - Array containing all categories back up through the hierarchy from the
9542: current category to the top level.
9543:
9544: currcategories - reference to array of current categories assigned to the course
9545:
9546: Returns: $output (markup to be displayed).
9547:
9548: =cut
9549:
9550: sub assign_category_rows {
9551: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9552: my ($text,$name,$item,$chgstr);
9553: if (ref($cats) eq 'ARRAY') {
9554: my $maxdepth = scalar(@{$cats});
9555: if (ref($cats->[$depth]) eq 'HASH') {
9556: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9557: my $numchildren = @{$cats->[$depth]{$parent}};
9558: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9559: $text .= '<td><table class="LC_datatable">';
9560: for (my $j=0; $j<$numchildren; $j++) {
9561: $name = $cats->[$depth]{$parent}[$j];
9562: $item = &escape($name).':'.&escape($parent).':'.$depth;
9563: my $deeper = $depth+1;
9564: my $checked = '';
9565: if (ref($currcategories) eq 'ARRAY') {
9566: if (@{$currcategories} > 0) {
9567: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9568: $checked = ' checked="checked"';
1.663 raeburn 9569: }
9570: }
9571: }
1.664 raeburn 9572: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9573: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9574: $item.'"'.$checked.' />'.$name.'</label></span>'.
9575: '<input type="hidden" name="catname" value="'.$name.'" />'.
9576: '</td><td>';
1.663 raeburn 9577: if (ref($path) eq 'ARRAY') {
9578: push(@{$path},$name);
9579: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9580: pop(@{$path});
9581: }
9582: $text .= '</td></tr>';
9583: }
9584: $text .= '</table></td>';
9585: }
9586: }
9587: }
9588: return $text;
9589: }
9590:
1.655 raeburn 9591: ############################################################
9592: ############################################################
9593:
9594:
1.443 albertel 9595: sub commit_customrole {
1.664 raeburn 9596: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9597: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9598: ($start?', '.&mt('starting').' '.localtime($start):'').
9599: ($end?', ending '.localtime($end):'').': <b>'.
9600: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9601: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9602: '</b><br />';
9603: return $output;
9604: }
9605:
9606: sub commit_standardrole {
1.541 raeburn 9607: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9608: my ($output,$logmsg,$linefeed);
9609: if ($context eq 'auto') {
9610: $linefeed = "\n";
9611: } else {
9612: $linefeed = "<br />\n";
9613: }
1.443 albertel 9614: if ($three eq 'st') {
1.541 raeburn 9615: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9616: $one,$two,$sec,$context);
9617: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9618: ($result eq 'unknown_course') || ($result eq 'refused')) {
9619: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9620: } else {
1.541 raeburn 9621: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9622: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9623: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9624: if ($context eq 'auto') {
9625: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9626: } else {
9627: $output .= '<b>'.$result.'</b>'.$linefeed.
9628: &mt('Add to classlist').': <b>ok</b>';
9629: }
9630: $output .= $linefeed;
1.443 albertel 9631: }
9632: } else {
9633: $output = &mt('Assigning').' '.$three.' in '.$url.
9634: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9635: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9636: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9637: if ($context eq 'auto') {
9638: $output .= $result.$linefeed;
9639: } else {
9640: $output .= '<b>'.$result.'</b>'.$linefeed;
9641: }
1.443 albertel 9642: }
9643: return $output;
9644: }
9645:
9646: sub commit_studentrole {
1.541 raeburn 9647: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9648: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9649: if ($context eq 'auto') {
9650: $linefeed = "\n";
9651: } else {
9652: $linefeed = '<br />'."\n";
9653: }
1.443 albertel 9654: if (defined($one) && defined($two)) {
9655: my $cid=$one.'_'.$two;
9656: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9657: my $secchange = 0;
9658: my $expire_role_result;
9659: my $modify_section_result;
1.628 raeburn 9660: if ($oldsec ne '-1') {
9661: if ($oldsec ne $sec) {
1.443 albertel 9662: $secchange = 1;
1.628 raeburn 9663: my $now = time;
1.443 albertel 9664: my $uurl='/'.$cid;
9665: $uurl=~s/\_/\//g;
9666: if ($oldsec) {
9667: $uurl.='/'.$oldsec;
9668: }
1.626 raeburn 9669: $oldsecurl = $uurl;
1.628 raeburn 9670: $expire_role_result =
1.652 raeburn 9671: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9672: if ($env{'request.course.sec'} ne '') {
9673: if ($expire_role_result eq 'refused') {
9674: my @roles = ('st');
9675: my @statuses = ('previous');
9676: my @roledoms = ($one);
9677: my $withsec = 1;
9678: my %roleshash =
9679: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9680: \@statuses,\@roles,\@roledoms,$withsec);
9681: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9682: my ($oldstart,$oldend) =
9683: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9684: if ($oldend > 0 && $oldend <= $now) {
9685: $expire_role_result = 'ok';
9686: }
9687: }
9688: }
9689: }
1.443 albertel 9690: $result = $expire_role_result;
9691: }
9692: }
9693: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9694: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9695: if ($modify_section_result =~ /^ok/) {
9696: if ($secchange == 1) {
1.628 raeburn 9697: if ($sec eq '') {
9698: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9699: } else {
9700: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9701: }
1.443 albertel 9702: } elsif ($oldsec eq '-1') {
1.628 raeburn 9703: if ($sec eq '') {
9704: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9705: } else {
9706: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9707: }
1.443 albertel 9708: } else {
1.628 raeburn 9709: if ($sec eq '') {
9710: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9711: } else {
9712: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9713: }
1.443 albertel 9714: }
9715: } else {
1.628 raeburn 9716: if ($secchange) {
9717: $$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;
9718: } else {
9719: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9720: }
1.443 albertel 9721: }
9722: $result = $modify_section_result;
9723: } elsif ($secchange == 1) {
1.628 raeburn 9724: if ($oldsec eq '') {
9725: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9726: } else {
9727: $$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;
9728: }
1.626 raeburn 9729: if ($expire_role_result eq 'refused') {
9730: my $newsecurl = '/'.$cid;
9731: $newsecurl =~ s/\_/\//g;
9732: if ($sec ne '') {
9733: $newsecurl.='/'.$sec;
9734: }
9735: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9736: if ($sec eq '') {
9737: $$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;
9738: } else {
9739: $$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;
9740: }
9741: }
9742: }
1.443 albertel 9743: }
9744: } else {
1.626 raeburn 9745: $$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 9746: $result = "error: incomplete course id\n";
9747: }
9748: return $result;
9749: }
9750:
9751: ############################################################
9752: ############################################################
9753:
1.566 albertel 9754: sub check_clone {
1.578 raeburn 9755: my ($args,$linefeed) = @_;
1.566 albertel 9756: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9757: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9758: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9759: my $clonemsg;
9760: my $can_clone = 0;
9761:
9762: if ($clonehome eq 'no_host') {
1.578 raeburn 9763: $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 9764: } else {
9765: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9766: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9767: $can_clone = 1;
9768: } else {
9769: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9770: $args->{'clonedomain'},$args->{'clonecourse'});
9771: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9772: if (grep(/^\*$/,@cloners)) {
9773: $can_clone = 1;
9774: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9775: $can_clone = 1;
9776: } else {
9777: my %roleshash =
9778: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9779: $args->{'ccdomain'},
9780: 'userroles',['active'],['cc'],
9781: [$args->{'clonedomain'}]);
9782: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9783: $can_clone = 1;
9784: } else {
9785: $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'});
9786: }
1.566 albertel 9787: }
1.578 raeburn 9788: }
1.566 albertel 9789: }
9790: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9791: }
9792:
1.444 albertel 9793: sub construct_course {
1.541 raeburn 9794: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9795: my $outcome;
1.541 raeburn 9796: my $linefeed = '<br />'."\n";
9797: if ($context eq 'auto') {
9798: $linefeed = "\n";
9799: }
1.566 albertel 9800:
9801: #
9802: # Are we cloning?
9803: #
9804: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9805: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9806: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9807: if ($context ne 'auto') {
1.578 raeburn 9808: if ($clonemsg ne '') {
9809: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9810: }
1.566 albertel 9811: }
9812: $outcome .= $clonemsg.$linefeed;
9813:
9814: if (!$can_clone) {
9815: return (0,$outcome);
9816: }
9817: }
9818:
1.444 albertel 9819: #
9820: # Open course
9821: #
9822: my $crstype = lc($args->{'crstype'});
9823: my %cenv=();
9824: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9825: $args->{'cdescr'},
9826: $args->{'curl'},
9827: $args->{'course_home'},
9828: $args->{'nonstandard'},
9829: $args->{'crscode'},
9830: $args->{'ccuname'}.':'.
9831: $args->{'ccdomain'},
9832: $args->{'crstype'});
9833:
9834: # Note: The testing routines depend on this being output; see
9835: # Utils::Course. This needs to at least be output as a comment
9836: # if anyone ever decides to not show this, and Utils::Course::new
9837: # will need to be suitably modified.
1.541 raeburn 9838: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9839: #
9840: # Check if created correctly
9841: #
1.479 albertel 9842: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9843: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9844: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9845:
1.444 albertel 9846: #
1.566 albertel 9847: # Do the cloning
9848: #
9849: if ($can_clone && $cloneid) {
9850: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9851: if ($context ne 'auto') {
9852: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9853: }
9854: $outcome .= $clonemsg.$linefeed;
9855: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9856: # Copy all files
1.637 www 9857: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9858: # Restore URL
1.566 albertel 9859: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9860: # Restore title
1.566 albertel 9861: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9862: # Mark as cloned
1.566 albertel 9863: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9864: # Need to clone grading mode
9865: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9866: $cenv{'grading'}=$newenv{'grading'};
9867: # Do not clone these environment entries
9868: &Apache::lonnet::del('environment',
9869: ['default_enrollment_start_date',
9870: 'default_enrollment_end_date',
9871: 'question.email',
9872: 'policy.email',
9873: 'comment.email',
9874: 'pch.users.denied',
1.725 raeburn 9875: 'plc.users.denied',
9876: 'hidefromcat',
9877: 'categories'],
1.638 www 9878: $$crsudom,$$crsunum);
1.444 albertel 9879: }
1.566 albertel 9880:
1.444 albertel 9881: #
9882: # Set environment (will override cloned, if existing)
9883: #
9884: my @sections = ();
9885: my @xlists = ();
9886: if ($args->{'crstype'}) {
9887: $cenv{'type'}=$args->{'crstype'};
9888: }
9889: if ($args->{'crsid'}) {
9890: $cenv{'courseid'}=$args->{'crsid'};
9891: }
9892: if ($args->{'crscode'}) {
9893: $cenv{'internal.coursecode'}=$args->{'crscode'};
9894: }
9895: if ($args->{'crsquota'} ne '') {
9896: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9897: } else {
9898: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9899: }
9900: if ($args->{'ccuname'}) {
9901: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9902: ':'.$args->{'ccdomain'};
9903: } else {
9904: $cenv{'internal.courseowner'} = $args->{'curruser'};
9905: }
9906: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9907: if ($args->{'crssections'}) {
9908: $cenv{'internal.sectionnums'} = '';
9909: if ($args->{'crssections'} =~ m/,/) {
9910: @sections = split/,/,$args->{'crssections'};
9911: } else {
9912: $sections[0] = $args->{'crssections'};
9913: }
9914: if (@sections > 0) {
9915: foreach my $item (@sections) {
9916: my ($sec,$gp) = split/:/,$item;
9917: my $class = $args->{'crscode'}.$sec;
9918: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9919: $cenv{'internal.sectionnums'} .= $item.',';
9920: unless ($addcheck eq 'ok') {
9921: push @badclasses, $class;
9922: }
9923: }
9924: $cenv{'internal.sectionnums'} =~ s/,$//;
9925: }
9926: }
9927: # do not hide course coordinator from staff listing,
9928: # even if privileged
9929: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9930: # add crosslistings
9931: if ($args->{'crsxlist'}) {
9932: $cenv{'internal.crosslistings'}='';
9933: if ($args->{'crsxlist'} =~ m/,/) {
9934: @xlists = split/,/,$args->{'crsxlist'};
9935: } else {
9936: $xlists[0] = $args->{'crsxlist'};
9937: }
9938: if (@xlists > 0) {
9939: foreach my $item (@xlists) {
9940: my ($xl,$gp) = split/:/,$item;
9941: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9942: $cenv{'internal.crosslistings'} .= $item.',';
9943: unless ($addcheck eq 'ok') {
9944: push @badclasses, $xl;
9945: }
9946: }
9947: $cenv{'internal.crosslistings'} =~ s/,$//;
9948: }
9949: }
9950: if ($args->{'autoadds'}) {
9951: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9952: }
9953: if ($args->{'autodrops'}) {
9954: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9955: }
9956: # check for notification of enrollment changes
9957: my @notified = ();
9958: if ($args->{'notify_owner'}) {
9959: if ($args->{'ccuname'} ne '') {
9960: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9961: }
9962: }
9963: if ($args->{'notify_dc'}) {
9964: if ($uname ne '') {
1.630 raeburn 9965: push(@notified,$uname.':'.$udom);
1.444 albertel 9966: }
9967: }
9968: if (@notified > 0) {
9969: my $notifylist;
9970: if (@notified > 1) {
9971: $notifylist = join(',',@notified);
9972: } else {
9973: $notifylist = $notified[0];
9974: }
9975: $cenv{'internal.notifylist'} = $notifylist;
9976: }
9977: if (@badclasses > 0) {
9978: my %lt=&Apache::lonlocal::texthash(
9979: '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',
9980: 'dnhr' => 'does not have rights to access enrollment in these classes',
9981: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9982: );
1.541 raeburn 9983: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9984: ' ('.$lt{'adby'}.')';
9985: if ($context eq 'auto') {
9986: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9987: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9988: foreach my $item (@badclasses) {
9989: if ($context eq 'auto') {
9990: $outcome .= " - $item\n";
9991: } else {
9992: $outcome .= "<li>$item</li>\n";
9993: }
9994: }
9995: if ($context eq 'auto') {
9996: $outcome .= $linefeed;
9997: } else {
1.566 albertel 9998: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9999: }
10000: }
1.444 albertel 10001: }
10002: if ($args->{'no_end_date'}) {
10003: $args->{'endaccess'} = 0;
10004: }
10005: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10006: $cenv{'internal.autoend'}=$args->{'enrollend'};
10007: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10008: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10009: if ($args->{'showphotos'}) {
10010: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10011: }
10012: $cenv{'internal.authtype'} = $args->{'authtype'};
10013: $cenv{'internal.autharg'} = $args->{'autharg'};
10014: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10015: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10016: 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');
10017: if ($context eq 'auto') {
10018: $outcome .= $krb_msg;
10019: } else {
1.566 albertel 10020: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10021: }
10022: $outcome .= $linefeed;
1.444 albertel 10023: }
10024: }
10025: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10026: if ($args->{'setpolicy'}) {
10027: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10028: }
10029: if ($args->{'setcontent'}) {
10030: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10031: }
10032: }
10033: if ($args->{'reshome'}) {
10034: $cenv{'reshome'}=$args->{'reshome'}.'/';
10035: $cenv{'reshome'}=~s/\/+$/\//;
10036: }
10037: #
10038: # course has keyed access
10039: #
10040: if ($args->{'setkeys'}) {
10041: $cenv{'keyaccess'}='yes';
10042: }
10043: # if specified, key authority is not course, but user
10044: # only active if keyaccess is yes
10045: if ($args->{'keyauth'}) {
1.487 albertel 10046: my ($user,$domain) = split(':',$args->{'keyauth'});
10047: $user = &LONCAPA::clean_username($user);
10048: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10049: if ($user ne '' && $domain ne '') {
1.487 albertel 10050: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10051: }
10052: }
10053:
10054: if ($args->{'disresdis'}) {
10055: $cenv{'pch.roles.denied'}='st';
10056: }
10057: if ($args->{'disablechat'}) {
10058: $cenv{'plc.roles.denied'}='st';
10059: }
10060:
10061: # Record we've not yet viewed the Course Initialization Helper for this
10062: # course
10063: $cenv{'course.helper.not.run'} = 1;
10064: #
10065: # Use new Randomseed
10066: #
10067: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10068: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10069: #
10070: # The encryption code and receipt prefix for this course
10071: #
10072: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10073: $cenv{'internal.encpref'}=100+int(9*rand(99));
10074: #
10075: # By default, use standard grading
10076: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10077:
1.541 raeburn 10078: $outcome .= $linefeed.&mt('Setting environment').': '.
10079: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10080: #
10081: # Open all assignments
10082: #
10083: if ($args->{'openall'}) {
10084: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10085: my %storecontent = ($storeunder => time,
10086: $storeunder.'.type' => 'date_start');
10087:
10088: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10089: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10090: }
10091: #
10092: # Set first page
10093: #
10094: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10095: || ($cloneid)) {
1.445 albertel 10096: use LONCAPA::map;
1.444 albertel 10097: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10098:
10099: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10100: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10101:
1.444 albertel 10102: $outcome .= ($fatal?$errtext:'read ok').' - ';
10103: my $title; my $url;
10104: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10105: $title=&mt('Syllabus');
1.444 albertel 10106: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10107: } else {
1.690 bisitz 10108: $title=&mt('Navigate Contents');
1.444 albertel 10109: $url='/adm/navmaps';
10110: }
1.445 albertel 10111:
10112: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10113: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10114:
10115: if ($errtext) { $fatal=2; }
1.541 raeburn 10116: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10117: }
1.566 albertel 10118:
10119: return (1,$outcome);
1.444 albertel 10120: }
10121:
10122: ############################################################
10123: ############################################################
10124:
1.378 raeburn 10125: sub course_type {
10126: my ($cid) = @_;
10127: if (!defined($cid)) {
10128: $cid = $env{'request.course.id'};
10129: }
1.404 albertel 10130: if (defined($env{'course.'.$cid.'.type'})) {
10131: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10132: } else {
10133: return 'Course';
1.377 raeburn 10134: }
10135: }
1.156 albertel 10136:
1.406 raeburn 10137: sub group_term {
10138: my $crstype = &course_type();
10139: my %names = (
10140: 'Course' => 'group',
10141: 'Group' => 'team',
10142: );
10143: return $names{$crstype};
10144: }
10145:
1.156 albertel 10146: sub icon {
10147: my ($file)=@_;
1.505 albertel 10148: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10149: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10150: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10151: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10152: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10153: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10154: $curfext.".gif") {
10155: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10156: $curfext.".gif";
10157: }
10158: }
1.249 albertel 10159: return &lonhttpdurl($iconname);
1.154 albertel 10160: }
1.84 albertel 10161:
1.575 albertel 10162: sub lonhttpdurl {
1.692 www 10163: #
10164: # Had been used for "small fry" static images on separate port 8080.
10165: # Modify here if lightweight http functionality desired again.
10166: # Currently eliminated due to increasing firewall issues.
10167: #
1.575 albertel 10168: my ($url)=@_;
1.692 www 10169: return $url;
1.215 albertel 10170: }
10171:
1.213 albertel 10172: sub connection_aborted {
10173: my ($r)=@_;
10174: $r->print(" ");$r->rflush();
10175: my $c = $r->connection;
10176: return $c->aborted();
10177: }
10178:
1.221 foxr 10179: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10180: # strings as 'strings'.
10181: sub escape_single {
1.221 foxr 10182: my ($input) = @_;
1.223 albertel 10183: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10184: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10185: return $input;
10186: }
1.223 albertel 10187:
1.222 foxr 10188: # Same as escape_single, but escape's "'s This
10189: # can be used for "strings"
10190: sub escape_double {
10191: my ($input) = @_;
10192: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10193: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10194: return $input;
10195: }
1.223 albertel 10196:
1.222 foxr 10197: # Escapes the last element of a full URL.
10198: sub escape_url {
10199: my ($url) = @_;
1.238 raeburn 10200: my @urlslices = split(/\//, $url,-1);
1.369 www 10201: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10202: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10203: }
1.462 albertel 10204:
10205: # -------------------------------------------------------- Initliaze user login
10206: sub init_user_environment {
1.463 albertel 10207: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10208: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10209:
10210: my $public=($username eq 'public' && $domain eq 'public');
10211:
10212: # See if old ID present, if so, remove
10213:
10214: my ($filename,$cookie,$userroles);
10215: my $now=time;
10216:
10217: if ($public) {
10218: my $max_public=100;
10219: my $oldest;
10220: my $oldest_time=0;
10221: for(my $next=1;$next<=$max_public;$next++) {
10222: if (-e $lonids."/publicuser_$next.id") {
10223: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10224: if ($mtime<$oldest_time || !$oldest_time) {
10225: $oldest_time=$mtime;
10226: $oldest=$next;
10227: }
10228: } else {
10229: $cookie="publicuser_$next";
10230: last;
10231: }
10232: }
10233: if (!$cookie) { $cookie="publicuser_$oldest"; }
10234: } else {
1.463 albertel 10235: # if this isn't a robot, kill any existing non-robot sessions
10236: if (!$args->{'robot'}) {
10237: opendir(DIR,$lonids);
10238: while ($filename=readdir(DIR)) {
10239: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10240: unlink($lonids.'/'.$filename);
10241: }
1.462 albertel 10242: }
1.463 albertel 10243: closedir(DIR);
1.462 albertel 10244: }
10245: # Give them a new cookie
1.463 albertel 10246: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10247: : $now.$$.int(rand(10000)));
1.463 albertel 10248: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10249:
10250: # Initialize roles
10251:
10252: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10253: }
10254: # ------------------------------------ Check browser type and MathML capability
10255:
10256: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10257: $clientunicode,$clientos) = &decode_user_agent($r);
10258:
10259: # -------------------------------------- Any accessibility options to remember?
10260: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
10261: foreach my $option ('imagesuppress','appletsuppress',
10262: 'embedsuppress','fontenhance','blackwhite') {
10263: if ($form->{$option} eq 'true') {
10264: &Apache::lonnet::put('environment',{$option => 'on'},
10265: $domain,$username);
10266: } else {
10267: &Apache::lonnet::del('environment',[$option],
10268: $domain,$username);
10269: }
10270: }
10271: }
10272: # ------------------------------------------------------------- Get environment
10273:
10274: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10275: my ($tmp) = keys(%userenv);
10276: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10277: # default remote control to off
10278: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10279: } else {
10280: undef(%userenv);
10281: }
10282: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10283: $form->{'interface'}=$userenv{'interface'};
10284: }
10285: $env{'environment.remote'}=$userenv{'remote'};
10286: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10287:
10288: # --------------- Do not trust query string to be put directly into environment
10289: foreach my $option ('imagesuppress','appletsuppress',
10290: 'embedsuppress','fontenhance','blackwhite',
10291: 'interface','localpath','localres') {
10292: $form->{$option}=~s/[\n\r\=]//gs;
10293: }
10294: # --------------------------------------------------------- Write first profile
10295:
10296: {
10297: my %initial_env =
10298: ("user.name" => $username,
10299: "user.domain" => $domain,
10300: "user.home" => $authhost,
10301: "browser.type" => $clientbrowser,
10302: "browser.version" => $clientversion,
10303: "browser.mathml" => $clientmathml,
10304: "browser.unicode" => $clientunicode,
10305: "browser.os" => $clientos,
10306: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10307: "request.course.fn" => '',
10308: "request.course.uri" => '',
10309: "request.course.sec" => '',
10310: "request.role" => 'cm',
10311: "request.role.adv" => $env{'user.adv'},
10312: "request.host" => $ENV{'REMOTE_ADDR'},);
10313:
10314: if ($form->{'localpath'}) {
10315: $initial_env{"browser.localpath"} = $form->{'localpath'};
10316: $initial_env{"browser.localres"} = $form->{'localres'};
10317: }
10318:
10319: if ($public) {
10320: $initial_env{"environment.remote"} = "off";
10321: }
10322: if ($form->{'interface'}) {
10323: $form->{'interface'}=~s/\W//gs;
10324: $initial_env{"browser.interface"} = $form->{'interface'};
10325: $env{'browser.interface'}=$form->{'interface'};
10326: foreach my $option ('imagesuppress','appletsuppress',
10327: 'embedsuppress','fontenhance','blackwhite') {
10328: if (($form->{$option} eq 'true') ||
10329: ($userenv{$option} eq 'on')) {
10330: $initial_env{"browser.$option"} = "on";
10331: }
10332: }
10333: }
10334:
1.724 raeburn 10335: foreach my $tool ('aboutme','blog','portfolio') {
10336: $userenv{'availabletools.'.$tool} =
10337: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10338: }
10339:
1.765 raeburn 10340: foreach my $crstype ('official','unofficial') {
10341: $userenv{'canrequest.'.$crstype} =
10342: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10343: 'reload','requestcourses');
10344: }
10345:
1.462 albertel 10346: $env{'user.environment'} = "$lonids/$cookie.id";
10347:
10348: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10349: &GDBM_WRCREAT(),0640)) {
10350: &_add_to_env(\%disk_env,\%initial_env);
10351: &_add_to_env(\%disk_env,\%userenv,'environment.');
10352: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10353: if (ref($args->{'extra_env'})) {
10354: &_add_to_env(\%disk_env,$args->{'extra_env'});
10355: }
1.462 albertel 10356: untie(%disk_env);
10357: } else {
1.705 tempelho 10358: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10359: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10360: return 'error: '.$!;
10361: }
10362: }
10363: $env{'request.role'}='cm';
10364: $env{'request.role.adv'}=$env{'user.adv'};
10365: $env{'browser.type'}=$clientbrowser;
10366:
10367: return $cookie;
10368:
10369: }
10370:
10371: sub _add_to_env {
10372: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10373: if (ref($env_data) eq 'HASH') {
10374: while (my ($key,$value) = each(%$env_data)) {
10375: $idf->{$prefix.$key} = $value;
10376: $env{$prefix.$key} = $value;
10377: }
1.462 albertel 10378: }
10379: }
10380:
1.685 tempelho 10381: # --- Get the symbolic name of a problem and the url
10382: sub get_symb {
10383: my ($request,$silent) = @_;
1.726 raeburn 10384: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10385: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10386: if ($symb eq '') {
10387: if (!$silent) {
10388: $request->print("Unable to handle ambiguous references:$url:.");
10389: return ();
10390: }
10391: }
10392: &Apache::lonenc::check_decrypt(\$symb);
10393: return ($symb);
10394: }
10395:
10396: # --------------------------------------------------------------Get annotation
10397:
10398: sub get_annotation {
10399: my ($symb,$enc) = @_;
10400:
10401: my $key = $symb;
10402: if (!$enc) {
10403: $key =
10404: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10405: }
10406: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10407: return $annotation{$key};
10408: }
10409:
10410: sub clean_symb {
1.731 raeburn 10411: my ($symb,$delete_enc) = @_;
1.685 tempelho 10412:
10413: &Apache::lonenc::check_decrypt(\$symb);
10414: my $enc = $env{'request.enc'};
1.731 raeburn 10415: if ($delete_enc) {
1.730 raeburn 10416: delete($env{'request.enc'});
10417: }
1.685 tempelho 10418:
10419: return ($symb,$enc);
10420: }
1.462 albertel 10421:
1.41 ng 10422: =pod
10423:
10424: =back
10425:
1.112 bowersj2 10426: =cut
1.41 ng 10427:
1.112 bowersj2 10428: 1;
10429: __END__;
1.41 ng 10430:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>