Annotation of loncom/interface/loncommon.pm, revision 1.948.2.31
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.948.2.31! raeburn 4: # $Id: loncommon.pm,v 1.948.2.30 2011/09/28 15:44:16 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.948.2.31! raeburn 455: $callargs .= ",'',1";
1.793 raeburn 456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.909 raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 486: my $wintitle = 'Course_Browser';
1.931 raeburn 487: if ($crstype eq 'Community') {
1.932 raeburn 488: $wintitle = 'Community_Browser';
1.909 raeburn 489: }
1.876 raeburn 490: my $id_functions = &javascript_index_functions();
491: my $output = '
1.776 bisitz 492: <script type="text/javascript" language="JavaScript">
1.824 bisitz 493: // <![CDATA[
1.468 raeburn 494: var stdeditbrowser;'."\n";
1.876 raeburn 495:
496: $output .= <<"ENDSTDBRW";
1.909 raeburn 497: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 498: var url = '/adm/pickcourse?';
1.895 raeburn 499: var formid = getFormIdByName(formname);
1.876 raeburn 500: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 501: if (domainfilter != null) {
502: if (domainfilter != '') {
503: url += 'domainfilter='+domainfilter+'&';
504: }
505: }
1.91 www 506: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 507: '&cdomelement='+udom+
508: '&cnameelement='+desc;
1.468 raeburn 509: if (extra_element !=null && extra_element != '') {
1.594 raeburn 510: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 511: url += '&roleelement='+extra_element;
512: if (domainfilter == null || domainfilter == '') {
513: url += '&domainfilter='+extra_element;
514: }
1.234 raeburn 515: }
1.468 raeburn 516: else {
517: if (formname == 'portform') {
518: url += '&setroles='+extra_element;
1.800 raeburn 519: } else {
520: if (formname == 'rules') {
521: url += '&fixeddom='+extra_element;
522: }
1.468 raeburn 523: }
524: }
1.230 raeburn 525: }
1.909 raeburn 526: if (type != null && type != '') {
527: url += '&type='+type;
528: }
529: if (type_elem != null && type_elem != '') {
530: url += '&typeelement='+type_elem;
531: }
1.872 raeburn 532: if (formname == 'ccrs') {
533: var ownername = document.forms[formid].ccuname.value;
534: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
535: url += '&cloner='+ownername+':'+ownerdom;
536: }
1.293 raeburn 537: if (multflag !=null && multflag != '') {
538: url += '&multiple='+multflag;
539: }
1.909 raeburn 540: var title = '$wintitle';
1.91 www 541: var options = 'scrollbars=1,resizable=1,menubar=0';
542: options += ',width=700,height=600';
543: stdeditbrowser = open(url,title,options,'1');
544: stdeditbrowser.focus();
545: }
1.876 raeburn 546: $id_functions
547: ENDSTDBRW
1.905 raeburn 548: if (($sec_element ne '') || ($role_element ne '')) {
549: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 550: }
551: $output .= '
552: // ]]>
553: </script>';
554: return $output;
555: }
556:
557: sub javascript_index_functions {
558: return <<"ENDJS";
559:
560: function getFormIdByName(formname) {
561: for (var i=0;i<document.forms.length;i++) {
562: if (document.forms[i].name == formname) {
563: return i;
564: }
565: }
566: return -1;
567: }
568:
569: function getIndexByName(formid,item) {
570: for (var i=0;i<document.forms[formid].elements.length;i++) {
571: if (document.forms[formid].elements[i].name == item) {
572: return i;
573: }
574: }
575: return -1;
576: }
1.468 raeburn 577:
1.876 raeburn 578: function getDomainFromSelectbox(formname,udom) {
579: var userdom;
580: var formid = getFormIdByName(formname);
581: if (formid > -1) {
582: var domid = getIndexByName(formid,udom);
583: if (domid > -1) {
584: if (document.forms[formid].elements[domid].type == 'select-one') {
585: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
586: }
587: if (document.forms[formid].elements[domid].type == 'hidden') {
588: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 589: }
590: }
591: }
1.876 raeburn 592: return userdom;
593: }
594:
595: ENDJS
1.468 raeburn 596:
1.876 raeburn 597: }
598:
1.948.2.31! raeburn 599: sub javascript_array_indexof {
! 600: return <<ENDJS;
! 601: <script type="text/javascript" language="JavaScript">
! 602: // <![CDATA[
! 603:
! 604: if (!Array.prototype.indexOf) {
! 605: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
! 606: "use strict";
! 607: if (this === void 0 || this === null) {
! 608: throw new TypeError();
! 609: }
! 610: var t = Object(this);
! 611: var len = t.length >>> 0;
! 612: if (len === 0) {
! 613: return -1;
! 614: }
! 615: var n = 0;
! 616: if (arguments.length > 0) {
! 617: n = Number(arguments[1]);
! 618: if (n !== n) { // shortcut for verifying if it's NaN
! 619: n = 0;
! 620: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
! 621: n = (n > 0 || -1) * Math.floor(Math.abs(n));
! 622: }
! 623: }
! 624: if (n >= len) {
! 625: return -1;
! 626: }
! 627: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
! 628: for (; k < len; k++) {
! 629: if (k in t && t[k] === searchElement) {
! 630: return k;
! 631: }
! 632: }
! 633: return -1;
! 634: }
! 635: }
! 636:
! 637: // ]]>
! 638: </script>
! 639:
! 640: ENDJS
! 641:
! 642: }
! 643:
1.876 raeburn 644: sub userbrowser_javascript {
645: my $id_functions = &javascript_index_functions();
646: return <<"ENDUSERBRW";
647:
1.888 raeburn 648: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 649: var url = '/adm/pickuser?';
650: var userdom = getDomainFromSelectbox(formname,udom);
651: if (userdom != null) {
652: if (userdom != '') {
653: url += 'srchdom='+userdom+'&';
654: }
655: }
656: url += 'form=' + formname + '&unameelement='+uname+
657: '&udomelement='+udom+
658: '&ulastelement='+ulast+
659: '&ufirstelement='+ufirst+
660: '&uemailelement='+uemail+
1.881 raeburn 661: '&hideudomelement='+hideudom+
662: '&coursedom='+crsdom;
1.888 raeburn 663: if ((caller != null) && (caller != undefined)) {
664: url += '&caller='+caller;
665: }
1.876 raeburn 666: var title = 'User_Browser';
667: var options = 'scrollbars=1,resizable=1,menubar=0';
668: options += ',width=700,height=600';
669: var stdeditbrowser = open(url,title,options,'1');
670: stdeditbrowser.focus();
671: }
672:
1.888 raeburn 673: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 674: var formid = getFormIdByName(formname);
675: if (formid > -1) {
1.888 raeburn 676: var unameid = getIndexByName(formid,uname);
1.876 raeburn 677: var domid = getIndexByName(formid,udom);
678: var hidedomid = getIndexByName(formid,origdom);
679: if (hidedomid > -1) {
680: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 681: var unameval = document.forms[formid].elements[unameid].value;
682: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
683: if (domid > -1) {
684: var slct = document.forms[formid].elements[domid];
685: if (slct.type == 'select-one') {
686: var i;
687: for (i=0;i<slct.length;i++) {
688: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
689: }
690: }
691: if (slct.type == 'hidden') {
692: slct.value = fixeddom;
1.876 raeburn 693: }
694: }
1.468 raeburn 695: }
696: }
697: }
1.876 raeburn 698: return;
699: }
700:
701: $id_functions
702: ENDUSERBRW
1.468 raeburn 703: }
704:
705: sub setsec_javascript {
1.905 raeburn 706: my ($sec_element,$formname,$role_element) = @_;
707: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
708: $communityrolestr);
709: if ($role_element ne '') {
710: my @allroles = ('st','ta','ep','in','ad');
711: foreach my $crstype ('Course','Community') {
712: if ($crstype eq 'Community') {
713: foreach my $role (@allroles) {
714: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
715: }
716: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
717: } else {
718: foreach my $role (@allroles) {
719: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
720: }
721: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
722: }
723: }
724: $rolestr = '"'.join('","',@allroles).'"';
725: $courserolestr = '"'.join('","',@courserolenames).'"';
726: $communityrolestr = '"'.join('","',@communityrolenames).'"';
727: }
1.468 raeburn 728: my $setsections = qq|
729: function setSect(sectionlist) {
1.629 raeburn 730: var sectionsArray = new Array();
731: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
732: sectionsArray = sectionlist.split(",");
733: }
1.468 raeburn 734: var numSections = sectionsArray.length;
735: document.$formname.$sec_element.length = 0;
736: if (numSections == 0) {
737: document.$formname.$sec_element.multiple=false;
738: document.$formname.$sec_element.size=1;
739: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
740: } else {
741: if (numSections == 1) {
742: document.$formname.$sec_element.multiple=false;
743: document.$formname.$sec_element.size=1;
744: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
745: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
746: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
747: } else {
748: for (var i=0; i<numSections; i++) {
749: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
750: }
751: document.$formname.$sec_element.multiple=true
752: if (numSections < 3) {
753: document.$formname.$sec_element.size=numSections;
754: } else {
755: document.$formname.$sec_element.size=3;
756: }
757: document.$formname.$sec_element.options[0].selected = false
758: }
759: }
1.91 www 760: }
1.905 raeburn 761:
762: function setRole(crstype) {
1.468 raeburn 763: |;
1.905 raeburn 764: if ($role_element eq '') {
765: $setsections .= ' return;
766: }
767: ';
768: } else {
769: $setsections .= qq|
770: var elementLength = document.$formname.$role_element.length;
771: var allroles = Array($rolestr);
772: var courserolenames = Array($courserolestr);
773: var communityrolenames = Array($communityrolestr);
774: if (elementLength != undefined) {
775: if (document.$formname.$role_element.options[5].value == 'cc') {
776: if (crstype == 'Course') {
777: return;
778: } else {
779: allroles[5] = 'co';
780: for (var i=0; i<6; i++) {
781: document.$formname.$role_element.options[i].value = allroles[i];
782: document.$formname.$role_element.options[i].text = communityrolenames[i];
783: }
784: }
785: } else {
786: if (crstype == 'Community') {
787: return;
788: } else {
789: allroles[5] = 'cc';
790: for (var i=0; i<6; i++) {
791: document.$formname.$role_element.options[i].value = allroles[i];
792: document.$formname.$role_element.options[i].text = courserolenames[i];
793: }
794: }
795: }
796: }
797: return;
798: }
799: |;
800: }
1.468 raeburn 801: return $setsections;
802: }
803:
1.91 www 804: sub selectcourse_link {
1.909 raeburn 805: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
806: $typeelement) = @_;
807: my $type = $selecttype;
1.871 raeburn 808: my $linktext = &mt('Select Course');
809: if ($selecttype eq 'Community') {
1.909 raeburn 810: $linktext = &mt('Select Community');
1.906 raeburn 811: } elsif ($selecttype eq 'Course/Community') {
812: $linktext = &mt('Select Course/Community');
1.909 raeburn 813: $type = '';
1.948.2.31! raeburn 814: } elsif ($selecttype eq 'Select') {
! 815: $linktext = &mt('Select');
! 816: $type = '';
1.871 raeburn 817: }
1.787 bisitz 818: return '<span class="LC_nobreak">'
819: ."<a href='"
820: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
821: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 822: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 823: ."'>".$linktext.'</a>'
1.787 bisitz 824: .'</span>';
1.74 www 825: }
1.42 matthew 826:
1.653 raeburn 827: sub selectauthor_link {
828: my ($form,$udom)=@_;
829: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
830: &mt('Select Author').'</a>';
831: }
832:
1.876 raeburn 833: sub selectuser_link {
1.881 raeburn 834: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 835: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 836: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 837: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 838: ');">'.$linktext.'</a>';
1.876 raeburn 839: }
840:
1.273 raeburn 841: sub check_uncheck_jscript {
842: my $jscript = <<"ENDSCRT";
843: function checkAll(field) {
844: if (field.length > 0) {
845: for (i = 0; i < field.length; i++) {
846: field[i].checked = true ;
847: }
848: } else {
849: field.checked = true
850: }
851: }
852:
853: function uncheckAll(field) {
854: if (field.length > 0) {
855: for (i = 0; i < field.length; i++) {
856: field[i].checked = false ;
1.543 albertel 857: }
858: } else {
1.273 raeburn 859: field.checked = false ;
860: }
861: }
862: ENDSCRT
863: return $jscript;
864: }
865:
1.656 www 866: sub select_timezone {
1.659 raeburn 867: my ($name,$selected,$onchange,$includeempty)=@_;
868: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
869: if ($includeempty) {
870: $output .= '<option value=""';
871: if (($selected eq '') || ($selected eq 'local')) {
872: $output .= ' selected="selected" ';
873: }
874: $output .= '> </option>';
875: }
1.657 raeburn 876: my @timezones = DateTime::TimeZone->all_names;
877: foreach my $tzone (@timezones) {
878: $output.= '<option value="'.$tzone.'"';
879: if ($tzone eq $selected) {
880: $output.=' selected="selected"';
881: }
882: $output.=">$tzone</option>\n";
1.656 www 883: }
884: $output.="</select>";
885: return $output;
886: }
1.273 raeburn 887:
1.687 raeburn 888: sub select_datelocale {
889: my ($name,$selected,$onchange,$includeempty)=@_;
890: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
891: if ($includeempty) {
892: $output .= '<option value=""';
893: if ($selected eq '') {
894: $output .= ' selected="selected" ';
895: }
896: $output .= '> </option>';
897: }
898: my (@possibles,%locale_names);
899: my @locales = DateTime::Locale::Catalog::Locales;
900: foreach my $locale (@locales) {
901: if (ref($locale) eq 'HASH') {
902: my $id = $locale->{'id'};
903: if ($id ne '') {
904: my $en_terr = $locale->{'en_territory'};
905: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 906: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 907: if (grep(/^en$/,@languages) || !@languages) {
908: if ($en_terr ne '') {
909: $locale_names{$id} = '('.$en_terr.')';
910: } elsif ($native_terr ne '') {
911: $locale_names{$id} = $native_terr;
912: }
913: } else {
914: if ($native_terr ne '') {
915: $locale_names{$id} = $native_terr.' ';
916: } elsif ($en_terr ne '') {
917: $locale_names{$id} = '('.$en_terr.')';
918: }
919: }
920: push (@possibles,$id);
921: }
922: }
923: }
924: foreach my $item (sort(@possibles)) {
925: $output.= '<option value="'.$item.'"';
926: if ($item eq $selected) {
927: $output.=' selected="selected"';
928: }
929: $output.=">$item";
930: if ($locale_names{$item} ne '') {
931: $output.=" $locale_names{$item}</option>\n";
932: }
933: $output.="</option>\n";
934: }
935: $output.="</select>";
936: return $output;
937: }
938:
1.792 raeburn 939: sub select_language {
940: my ($name,$selected,$includeempty) = @_;
941: my %langchoices;
942: if ($includeempty) {
943: %langchoices = ('' => 'No language preference');
944: }
945: foreach my $id (&languageids()) {
946: my $code = &supportedlanguagecode($id);
947: if ($code) {
948: $langchoices{$code} = &plainlanguagedescription($id);
949: }
950: }
1.948.2.7 raeburn 951: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 952: }
953:
1.42 matthew 954: =pod
1.36 matthew 955:
1.648 raeburn 956: =item * &linked_select_forms(...)
1.36 matthew 957:
958: linked_select_forms returns a string containing a <script></script> block
959: and html for two <select> menus. The select menus will be linked in that
960: changing the value of the first menu will result in new values being placed
961: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 962: order unless a defined order is provided.
1.36 matthew 963:
964: linked_select_forms takes the following ordered inputs:
965:
966: =over 4
967:
1.112 bowersj2 968: =item * $formname, the name of the <form> tag
1.36 matthew 969:
1.112 bowersj2 970: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 971:
1.112 bowersj2 972: =item * $firstdefault, the default value for the first menu
1.36 matthew 973:
1.112 bowersj2 974: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 975:
1.112 bowersj2 976: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 977:
1.112 bowersj2 978: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 979:
1.609 raeburn 980: =item * $menuorder, the order of values in the first menu
981:
1.41 ng 982: =back
983:
1.36 matthew 984: Below is an example of such a hash. Only the 'text', 'default', and
985: 'select2' keys must appear as stated. keys(%menu) are the possible
986: values for the first select menu. The text that coincides with the
1.41 ng 987: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 988: and text for the second menu are given in the hash pointed to by
989: $menu{$choice1}->{'select2'}.
990:
1.112 bowersj2 991: my %menu = ( A1 => { text =>"Choice A1" ,
992: default => "B3",
993: select2 => {
994: B1 => "Choice B1",
995: B2 => "Choice B2",
996: B3 => "Choice B3",
997: B4 => "Choice B4"
1.609 raeburn 998: },
999: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1000: },
1001: A2 => { text =>"Choice A2" ,
1002: default => "C2",
1003: select2 => {
1004: C1 => "Choice C1",
1005: C2 => "Choice C2",
1006: C3 => "Choice C3"
1.609 raeburn 1007: },
1008: order => ['C2','C1','C3'],
1.112 bowersj2 1009: },
1010: A3 => { text =>"Choice A3" ,
1011: default => "D6",
1012: select2 => {
1013: D1 => "Choice D1",
1014: D2 => "Choice D2",
1015: D3 => "Choice D3",
1016: D4 => "Choice D4",
1017: D5 => "Choice D5",
1018: D6 => "Choice D6",
1019: D7 => "Choice D7"
1.609 raeburn 1020: },
1021: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1022: }
1023: );
1.36 matthew 1024:
1025: =cut
1026:
1027: sub linked_select_forms {
1028: my ($formname,
1029: $middletext,
1030: $firstdefault,
1031: $firstselectname,
1032: $secondselectname,
1.609 raeburn 1033: $hashref,
1034: $menuorder,
1.36 matthew 1035: ) = @_;
1036: my $second = "document.$formname.$secondselectname";
1037: my $first = "document.$formname.$firstselectname";
1038: # output the javascript to do the changing
1039: my $result = '';
1.776 bisitz 1040: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1041: $result.="// <![CDATA[\n";
1.36 matthew 1042: $result.="var select2data = new Object();\n";
1043: $" = '","';
1044: my $debug = '';
1045: foreach my $s1 (sort(keys(%$hashref))) {
1046: $result.="select2data.d_$s1 = new Object();\n";
1047: $result.="select2data.d_$s1.def = new String('".
1048: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1049: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1050: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1051: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1052: @s2values = @{$hashref->{$s1}->{'order'}};
1053: }
1.36 matthew 1054: $result.="\"@s2values\");\n";
1055: $result.="select2data.d_$s1.texts = new Array(";
1056: my @s2texts;
1057: foreach my $value (@s2values) {
1058: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1059: }
1060: $result.="\"@s2texts\");\n";
1061: }
1062: $"=' ';
1063: $result.= <<"END";
1064:
1065: function select1_changed() {
1066: // Determine new choice
1067: var newvalue = "d_" + $first.value;
1068: // update select2
1069: var values = select2data[newvalue].values;
1070: var texts = select2data[newvalue].texts;
1071: var select2def = select2data[newvalue].def;
1072: var i;
1073: // out with the old
1074: for (i = 0; i < $second.options.length; i++) {
1075: $second.options[i] = null;
1076: }
1077: // in with the nuclear
1078: for (i=0;i<values.length; i++) {
1079: $second.options[i] = new Option(values[i]);
1.143 matthew 1080: $second.options[i].value = values[i];
1.36 matthew 1081: $second.options[i].text = texts[i];
1082: if (values[i] == select2def) {
1083: $second.options[i].selected = true;
1084: }
1085: }
1086: }
1.824 bisitz 1087: // ]]>
1.36 matthew 1088: </script>
1089: END
1090: # output the initial values for the selection lists
1091: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1092: my @order = sort(keys(%{$hashref}));
1093: if (ref($menuorder) eq 'ARRAY') {
1094: @order = @{$menuorder};
1095: }
1096: foreach my $value (@order) {
1.36 matthew 1097: $result.=" <option value=\"$value\" ";
1.253 albertel 1098: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1099: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1100: }
1101: $result .= "</select>\n";
1102: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1103: $result .= $middletext;
1104: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1105: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1106:
1107: my @secondorder = sort(keys(%select2));
1108: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1109: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1110: }
1111: foreach my $value (@secondorder) {
1.36 matthew 1112: $result.=" <option value=\"$value\" ";
1.253 albertel 1113: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1114: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1115: }
1116: $result .= "</select>\n";
1117: # return $debug;
1118: return $result;
1119: } # end of sub linked_select_forms {
1120:
1.45 matthew 1121: =pod
1.44 bowersj2 1122:
1.948.2.7 raeburn 1123: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1124:
1.112 bowersj2 1125: Returns a string corresponding to an HTML link to the given help
1126: $topic, where $topic corresponds to the name of a .tex file in
1127: /home/httpd/html/adm/help/tex, with underscores replaced by
1128: spaces.
1129:
1130: $text will optionally be linked to the same topic, allowing you to
1131: link text in addition to the graphic. If you do not want to link
1132: text, but wish to specify one of the later parameters, pass an
1133: empty string.
1134:
1135: $stayOnPage is a value that will be interpreted as a boolean. If true,
1136: the link will not open a new window. If false, the link will open
1137: a new window using Javascript. (Default is false.)
1138:
1139: $width and $height are optional numerical parameters that will
1140: override the width and height of the popped up window, which may
1141: be useful for certain help topics with big pictures included.
1.44 bowersj2 1142:
1143: =cut
1144:
1145: sub help_open_topic {
1.948.2.7 raeburn 1146: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1147: $text = "" if (not defined $text);
1.44 bowersj2 1148: $stayOnPage = 0 if (not defined $stayOnPage);
1149: $width = 350 if (not defined $width);
1150: $height = 400 if (not defined $height);
1151: my $filename = $topic;
1152: $filename =~ s/ /_/g;
1153:
1.48 bowersj2 1154: my $template = "";
1155: my $link;
1.572 banghart 1156:
1.159 www 1157: $topic=~s/\W/\_/g;
1.44 bowersj2 1158:
1.572 banghart 1159: if (!$stayOnPage) {
1.72 bowersj2 1160: $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 1161: } else {
1.48 bowersj2 1162: $link = "/adm/help/${filename}.hlp";
1163: }
1164:
1165: # Add the text
1.755 neumanie 1166: if ($text ne "") {
1.763 bisitz 1167: $template.='<span class="LC_help_open_topic">'
1168: .'<a target="_top" href="'.$link.'">'
1169: .$text.'</a>';
1.48 bowersj2 1170: }
1171:
1.763 bisitz 1172: # (Always) Add the graphic
1.179 matthew 1173: my $title = &mt('Online Help');
1.667 raeburn 1174: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.948.2.7 raeburn 1175: if ($imgid ne '') {
1176: $imgid = ' id="'.$imgid.'"';
1177: }
1.763 bisitz 1178: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1179: .'<img src="'.$helpicon.'" border="0"'
1180: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.948.2.7 raeburn 1181: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1182: .' /></a>';
1.948.2.7 raeburn 1183: if ($text ne "") {
1.763 bisitz 1184: $template.='</span>';
1185: }
1.44 bowersj2 1186: return $template;
1187:
1.106 bowersj2 1188: }
1189:
1190: # This is a quicky function for Latex cheatsheet editing, since it
1191: # appears in at least four places
1192: sub helpLatexCheatsheet {
1.732 raeburn 1193: my ($topic,$text,$not_author) = @_;
1194: my $out;
1.106 bowersj2 1195: my $addOther = '';
1.732 raeburn 1196: if ($topic) {
1.763 bisitz 1197: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1198: undef, undef, 600).
1199: '</span> ';
1200: }
1201: $out = '<span>' # Start cheatsheet
1202: .$addOther
1203: .'<span>'
1204: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1205: undef,undef,600)
1206: .'</span> <span>'
1207: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1208: undef,undef,600)
1209: .'</span>';
1.732 raeburn 1210: unless ($not_author) {
1.763 bisitz 1211: $out .= ' <span>'
1212: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1213: undef,undef,600)
1214: .'</span>';
1.732 raeburn 1215: }
1.763 bisitz 1216: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1217: return $out;
1.172 www 1218: }
1219:
1.430 albertel 1220: sub general_help {
1221: my $helptopic='Student_Intro';
1222: if ($env{'request.role'}=~/^(ca|au)/) {
1223: $helptopic='Authoring_Intro';
1.907 raeburn 1224: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1225: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1226: } elsif ($env{'request.role'}=~/^dc/) {
1227: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1228: }
1229: return $helptopic;
1230: }
1231:
1232: sub update_help_link {
1233: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1234: my $origurl = $ENV{'REQUEST_URI'};
1235: $origurl=~s|^/~|/priv/|;
1236: my $timestamp = time;
1237: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1238: $$datum = &escape($$datum);
1239: }
1240:
1241: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1242: my $output .= <<"ENDOUTPUT";
1243: <script type="text/javascript">
1.824 bisitz 1244: // <![CDATA[
1.430 albertel 1245: banner_link = '$banner_link';
1.824 bisitz 1246: // ]]>
1.430 albertel 1247: </script>
1248: ENDOUTPUT
1249: return $output;
1250: }
1251:
1252: # now just updates the help link and generates a blue icon
1.193 raeburn 1253: sub help_open_menu {
1.430 albertel 1254: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1255: = @_;
1.430 albertel 1256: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1257: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1258: # if environment.remote is on (using remote control UI)
1.798 tempelho 1259: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1260: $stayOnPage=1;
1.430 albertel 1261: }
1262: my $output;
1263: if ($component_help) {
1264: if (!$text) {
1265: $output=&help_open_topic($component_help,undef,$stayOnPage,
1266: $width,$height);
1267: } else {
1268: my $help_text;
1269: $help_text=&unescape($topic);
1270: $output='<table><tr><td>'.
1271: &help_open_topic($component_help,$help_text,$stayOnPage,
1272: $width,$height).'</td></tr></table>';
1273: }
1274: }
1275: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1276: return $output.$banner_link;
1277: }
1278:
1279: sub top_nav_help {
1280: my ($text) = @_;
1.436 albertel 1281: $text = &mt($text);
1.572 banghart 1282: my $stay_on_page =
1.798 tempelho 1283: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1284: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1285: : "javascript:helpMenu('open')";
1.572 banghart 1286: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1287:
1.201 raeburn 1288: my $title = &mt('Get help');
1.436 albertel 1289:
1290: return <<"END";
1291: $banner_link
1292: <a href="$link" title="$title">$text</a>
1293: END
1294: }
1295:
1296: sub help_menu_js {
1297: my ($text) = @_;
1298:
1299: my $stayOnPage =
1.798 tempelho 1300: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1301:
1302: my $width = 620;
1303: my $height = 600;
1.430 albertel 1304: my $helptopic=&general_help();
1305: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1306: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1307: my $start_page =
1308: &Apache::loncommon::start_page('Help Menu', undef,
1309: {'frameset' => 1,
1310: 'js_ready' => 1,
1311: 'add_entries' => {
1312: 'border' => '0',
1.579 raeburn 1313: 'rows' => "110,*",},});
1.331 albertel 1314: my $end_page =
1315: &Apache::loncommon::end_page({'frameset' => 1,
1316: 'js_ready' => 1,});
1317:
1.436 albertel 1318: my $template .= <<"ENDTEMPLATE";
1319: <script type="text/javascript">
1.877 bisitz 1320: // <![CDATA[
1.253 albertel 1321: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1322: var banner_link = '';
1.243 raeburn 1323: function helpMenu(target) {
1324: var caller = this;
1325: if (target == 'open') {
1326: var newWindow = null;
1327: try {
1.262 albertel 1328: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1329: }
1330: catch(error) {
1331: writeHelp(caller);
1332: return;
1333: }
1334: if (newWindow) {
1335: caller = newWindow;
1336: }
1.193 raeburn 1337: }
1.243 raeburn 1338: writeHelp(caller);
1339: return;
1340: }
1341: function writeHelp(caller) {
1.430 albertel 1342: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1343: caller.document.close()
1344: caller.focus()
1.193 raeburn 1345: }
1.877 bisitz 1346: // END LON-CAPA Internal -->
1.253 albertel 1347: // ]]>
1.436 albertel 1348: </script>
1.193 raeburn 1349: ENDTEMPLATE
1350: return $template;
1351: }
1352:
1.172 www 1353: sub help_open_bug {
1354: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1355: unless ($env{'user.adv'}) { return ''; }
1.172 www 1356: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1357: $text = "" if (not defined $text);
1358: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1359: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1360: $stayOnPage=1;
1361: }
1.184 albertel 1362: $width = 600 if (not defined $width);
1363: $height = 600 if (not defined $height);
1.172 www 1364:
1365: $topic=~s/\W+/\+/g;
1366: my $link='';
1367: my $template='';
1.379 albertel 1368: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1369: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1370: if (!$stayOnPage)
1371: {
1372: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1373: }
1374: else
1375: {
1376: $link = $url;
1377: }
1378: # Add the text
1379: if ($text ne "")
1380: {
1381: $template .=
1382: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1383: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1384: }
1385:
1386: # Add the graphic
1.179 matthew 1387: my $title = &mt('Report a Bug');
1.215 albertel 1388: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1389: $template .= <<"ENDTEMPLATE";
1.436 albertel 1390: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1391: ENDTEMPLATE
1392: if ($text ne '') { $template.='</td></tr></table>' };
1393: return $template;
1394:
1395: }
1396:
1397: sub help_open_faq {
1398: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1399: unless ($env{'user.adv'}) { return ''; }
1.172 www 1400: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1401: $text = "" if (not defined $text);
1402: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1403: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1404: $stayOnPage=1;
1405: }
1406: $width = 350 if (not defined $width);
1407: $height = 400 if (not defined $height);
1408:
1409: $topic=~s/\W+/\+/g;
1410: my $link='';
1411: my $template='';
1412: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1413: if (!$stayOnPage)
1414: {
1415: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1416: }
1417: else
1418: {
1419: $link = $url;
1420: }
1421:
1422: # Add the text
1423: if ($text ne "")
1424: {
1425: $template .=
1.173 www 1426: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1427: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1428: }
1429:
1430: # Add the graphic
1.179 matthew 1431: my $title = &mt('View the FAQ');
1.215 albertel 1432: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1433: $template .= <<"ENDTEMPLATE";
1.436 albertel 1434: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1435: ENDTEMPLATE
1436: if ($text ne '') { $template.='</td></tr></table>' };
1437: return $template;
1438:
1.44 bowersj2 1439: }
1.37 matthew 1440:
1.180 matthew 1441: ###############################################################
1442: ###############################################################
1443:
1.45 matthew 1444: =pod
1445:
1.648 raeburn 1446: =item * &change_content_javascript():
1.256 matthew 1447:
1448: This and the next function allow you to create small sections of an
1449: otherwise static HTML page that you can update on the fly with
1450: Javascript, even in Netscape 4.
1451:
1452: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1453: must be written to the HTML page once. It will prove the Javascript
1454: function "change(name, content)". Calling the change function with the
1455: name of the section
1456: you want to update, matching the name passed to C<changable_area>, and
1457: the new content you want to put in there, will put the content into
1458: that area.
1459:
1460: B<Note>: Netscape 4 only reserves enough space for the changable area
1461: to contain room for the original contents. You need to "make space"
1462: for whatever changes you wish to make, and be B<sure> to check your
1463: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1464: it's adequate for updating a one-line status display, but little more.
1465: This script will set the space to 100% width, so you only need to
1466: worry about height in Netscape 4.
1467:
1468: Modern browsers are much less limiting, and if you can commit to the
1469: user not using Netscape 4, this feature may be used freely with
1470: pretty much any HTML.
1471:
1472: =cut
1473:
1474: sub change_content_javascript {
1475: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1476: if ($env{'browser.type'} eq 'netscape' &&
1477: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1478: return (<<NETSCAPE4);
1479: function change(name, content) {
1480: doc = document.layers[name+"___escape"].layers[0].document;
1481: doc.open();
1482: doc.write(content);
1483: doc.close();
1484: }
1485: NETSCAPE4
1486: } else {
1487: # Otherwise, we need to use semi-standards-compliant code
1488: # (technically, "innerHTML" isn't standard but the equivalent
1489: # is really scary, and every useful browser supports it
1490: return (<<DOMBASED);
1491: function change(name, content) {
1492: element = document.getElementById(name);
1493: element.innerHTML = content;
1494: }
1495: DOMBASED
1496: }
1497: }
1498:
1499: =pod
1500:
1.648 raeburn 1501: =item * &changable_area($name,$origContent):
1.256 matthew 1502:
1503: This provides a "changable area" that can be modified on the fly via
1504: the Javascript code provided in C<change_content_javascript>. $name is
1505: the name you will use to reference the area later; do not repeat the
1506: same name on a given HTML page more then once. $origContent is what
1507: the area will originally contain, which can be left blank.
1508:
1509: =cut
1510:
1511: sub changable_area {
1512: my ($name, $origContent) = @_;
1513:
1.258 albertel 1514: if ($env{'browser.type'} eq 'netscape' &&
1515: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1516: # If this is netscape 4, we need to use the Layer tag
1517: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1518: } else {
1519: return "<span id='$name'>$origContent</span>";
1520: }
1521: }
1522:
1523: =pod
1524:
1.648 raeburn 1525: =item * &viewport_geometry_js
1.590 raeburn 1526:
1527: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1528:
1529: =cut
1530:
1531:
1532: sub viewport_geometry_js {
1533: return <<"GEOMETRY";
1534: var Geometry = {};
1535: function init_geometry() {
1536: if (Geometry.init) { return };
1537: Geometry.init=1;
1538: if (window.innerHeight) {
1539: Geometry.getViewportHeight = function() { return window.innerHeight; };
1540: Geometry.getViewportWidth = function() { return window.innerWidth; };
1541: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1542: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1543: }
1544: else if (document.documentElement && document.documentElement.clientHeight) {
1545: Geometry.getViewportHeight =
1546: function() { return document.documentElement.clientHeight; };
1547: Geometry.getViewportWidth =
1548: function() { return document.documentElement.clientWidth; };
1549:
1550: Geometry.getHorizontalScroll =
1551: function() { return document.documentElement.scrollLeft; };
1552: Geometry.getVerticalScroll =
1553: function() { return document.documentElement.scrollTop; };
1554: }
1555: else if (document.body.clientHeight) {
1556: Geometry.getViewportHeight =
1557: function() { return document.body.clientHeight; };
1558: Geometry.getViewportWidth =
1559: function() { return document.body.clientWidth; };
1560: Geometry.getHorizontalScroll =
1561: function() { return document.body.scrollLeft; };
1562: Geometry.getVerticalScroll =
1563: function() { return document.body.scrollTop; };
1564: }
1565: }
1566:
1567: GEOMETRY
1568: }
1569:
1570: =pod
1571:
1.648 raeburn 1572: =item * &viewport_size_js()
1.590 raeburn 1573:
1574: 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.
1575:
1576: =cut
1577:
1578: sub viewport_size_js {
1579: my $geometry = &viewport_geometry_js();
1580: return <<"DIMS";
1581:
1582: $geometry
1583:
1584: function getViewportDims(width,height) {
1585: init_geometry();
1586: width.value = Geometry.getViewportWidth();
1587: height.value = Geometry.getViewportHeight();
1588: return;
1589: }
1590:
1591: DIMS
1592: }
1593:
1594: =pod
1595:
1.648 raeburn 1596: =item * &resize_textarea_js()
1.565 albertel 1597:
1598: emits the needed javascript to resize a textarea to be as big as possible
1599:
1600: creates a function resize_textrea that takes two IDs first should be
1601: the id of the element to resize, second should be the id of a div that
1602: surrounds everything that comes after the textarea, this routine needs
1603: to be attached to the <body> for the onload and onresize events.
1604:
1.648 raeburn 1605: =back
1.565 albertel 1606:
1607: =cut
1608:
1609: sub resize_textarea_js {
1.590 raeburn 1610: my $geometry = &viewport_geometry_js();
1.565 albertel 1611: return <<"RESIZE";
1612: <script type="text/javascript">
1.824 bisitz 1613: // <![CDATA[
1.590 raeburn 1614: $geometry
1.565 albertel 1615:
1.588 albertel 1616: function getX(element) {
1617: var x = 0;
1618: while (element) {
1619: x += element.offsetLeft;
1620: element = element.offsetParent;
1621: }
1622: return x;
1623: }
1624: function getY(element) {
1625: var y = 0;
1626: while (element) {
1627: y += element.offsetTop;
1628: element = element.offsetParent;
1629: }
1630: return y;
1631: }
1632:
1633:
1.565 albertel 1634: function resize_textarea(textarea_id,bottom_id) {
1635: init_geometry();
1636: var textarea = document.getElementById(textarea_id);
1637: //alert(textarea);
1638:
1.588 albertel 1639: var textarea_top = getY(textarea);
1.565 albertel 1640: var textarea_height = textarea.offsetHeight;
1641: var bottom = document.getElementById(bottom_id);
1.588 albertel 1642: var bottom_top = getY(bottom);
1.565 albertel 1643: var bottom_height = bottom.offsetHeight;
1644: var window_height = Geometry.getViewportHeight();
1.588 albertel 1645: var fudge = 23;
1.565 albertel 1646: var new_height = window_height-fudge-textarea_top-bottom_height;
1647: if (new_height < 300) {
1648: new_height = 300;
1649: }
1650: textarea.style.height=new_height+'px';
1651: }
1.824 bisitz 1652: // ]]>
1.565 albertel 1653: </script>
1654: RESIZE
1655:
1656: }
1657:
1658: =pod
1659:
1.256 matthew 1660: =head1 Excel and CSV file utility routines
1661:
1662: =over 4
1663:
1664: =cut
1665:
1666: ###############################################################
1667: ###############################################################
1668:
1669: =pod
1670:
1.648 raeburn 1671: =item * &csv_translate($text)
1.37 matthew 1672:
1.185 www 1673: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1674: format.
1675:
1676: =cut
1677:
1.180 matthew 1678: ###############################################################
1679: ###############################################################
1.37 matthew 1680: sub csv_translate {
1681: my $text = shift;
1682: $text =~ s/\"/\"\"/g;
1.209 albertel 1683: $text =~ s/\n/ /g;
1.37 matthew 1684: return $text;
1685: }
1.180 matthew 1686:
1687: ###############################################################
1688: ###############################################################
1689:
1690: =pod
1691:
1.648 raeburn 1692: =item * &define_excel_formats()
1.180 matthew 1693:
1694: Define some commonly used Excel cell formats.
1695:
1696: Currently supported formats:
1697:
1698: =over 4
1699:
1700: =item header
1701:
1702: =item bold
1703:
1704: =item h1
1705:
1706: =item h2
1707:
1708: =item h3
1709:
1.256 matthew 1710: =item h4
1711:
1712: =item i
1713:
1.180 matthew 1714: =item date
1715:
1716: =back
1717:
1718: Inputs: $workbook
1719:
1720: Returns: $format, a hash reference.
1721:
1722: =cut
1723:
1724: ###############################################################
1725: ###############################################################
1726: sub define_excel_formats {
1727: my ($workbook) = @_;
1728: my $format;
1729: $format->{'header'} = $workbook->add_format(bold => 1,
1730: bottom => 1,
1731: align => 'center');
1732: $format->{'bold'} = $workbook->add_format(bold=>1);
1733: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1734: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1735: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1736: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1737: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1738: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1739: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1740: return $format;
1741: }
1742:
1743: ###############################################################
1744: ###############################################################
1.113 bowersj2 1745:
1746: =pod
1747:
1.648 raeburn 1748: =item * &create_workbook()
1.255 matthew 1749:
1750: Create an Excel worksheet. If it fails, output message on the
1751: request object and return undefs.
1752:
1753: Inputs: Apache request object
1754:
1755: Returns (undef) on failure,
1756: Excel worksheet object, scalar with filename, and formats
1757: from &Apache::loncommon::define_excel_formats on success
1758:
1759: =cut
1760:
1761: ###############################################################
1762: ###############################################################
1763: sub create_workbook {
1764: my ($r) = @_;
1765: #
1766: # Create the excel spreadsheet
1767: my $filename = '/prtspool/'.
1.258 albertel 1768: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1769: time.'_'.rand(1000000000).'.xls';
1770: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1771: if (! defined($workbook)) {
1772: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1773: $r->print(
1774: '<p class="LC_error">'
1775: .&mt('Problems occurred in creating the new Excel file.')
1776: .' '.&mt('This error has been logged.')
1777: .' '.&mt('Please alert your LON-CAPA administrator.')
1778: .'</p>'
1779: );
1.255 matthew 1780: return (undef);
1781: }
1782: #
1783: $workbook->set_tempdir('/home/httpd/perl/tmp');
1784: #
1785: my $format = &Apache::loncommon::define_excel_formats($workbook);
1786: return ($workbook,$filename,$format);
1787: }
1788:
1789: ###############################################################
1790: ###############################################################
1791:
1792: =pod
1793:
1.648 raeburn 1794: =item * &create_text_file()
1.113 bowersj2 1795:
1.542 raeburn 1796: Create a file to write to and eventually make available to the user.
1.256 matthew 1797: If file creation fails, outputs an error message on the request object and
1798: return undefs.
1.113 bowersj2 1799:
1.256 matthew 1800: Inputs: Apache request object, and file suffix
1.113 bowersj2 1801:
1.256 matthew 1802: Returns (undef) on failure,
1803: Filehandle and filename on success.
1.113 bowersj2 1804:
1805: =cut
1806:
1.256 matthew 1807: ###############################################################
1808: ###############################################################
1809: sub create_text_file {
1810: my ($r,$suffix) = @_;
1811: if (! defined($suffix)) { $suffix = 'txt'; };
1812: my $fh;
1813: my $filename = '/prtspool/'.
1.258 albertel 1814: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1815: time.'_'.rand(1000000000).'.'.$suffix;
1816: $fh = Apache::File->new('>/home/httpd'.$filename);
1817: if (! defined($fh)) {
1818: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1819: $r->print(
1820: '<p class="LC_error">'
1821: .&mt('Problems occurred in creating the output file.')
1822: .' '.&mt('This error has been logged.')
1823: .' '.&mt('Please alert your LON-CAPA administrator.')
1824: .'</p>'
1825: );
1.113 bowersj2 1826: }
1.256 matthew 1827: return ($fh,$filename)
1.113 bowersj2 1828: }
1829:
1830:
1.256 matthew 1831: =pod
1.113 bowersj2 1832:
1833: =back
1834:
1835: =cut
1.37 matthew 1836:
1837: ###############################################################
1.33 matthew 1838: ## Home server <option> list generating code ##
1839: ###############################################################
1.35 matthew 1840:
1.169 www 1841: # ------------------------------------------
1842:
1843: sub domain_select {
1844: my ($name,$value,$multiple)=@_;
1845: my %domains=map {
1.514 albertel 1846: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1847: } &Apache::lonnet::all_domains();
1.169 www 1848: if ($multiple) {
1849: $domains{''}=&mt('Any domain');
1.550 albertel 1850: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1851: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1852: } else {
1.550 albertel 1853: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.948.2.7 raeburn 1854: return &select_form($name,$value,\%domains);
1.169 www 1855: }
1856: }
1857:
1.282 albertel 1858: #-------------------------------------------
1859:
1860: =pod
1861:
1.519 raeburn 1862: =head1 Routines for form select boxes
1863:
1864: =over 4
1865:
1.648 raeburn 1866: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1867:
1868: Returns a string containing a <select> element int multiple mode
1869:
1870:
1871: Args:
1872: $name - name of the <select> element
1.506 raeburn 1873: $value - scalar or array ref of values that should already be selected
1.282 albertel 1874: $size - number of rows long the select element is
1.283 albertel 1875: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1876: (shown text should already have been &mt())
1.506 raeburn 1877: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1878:
1.282 albertel 1879: =cut
1880:
1881: #-------------------------------------------
1.169 www 1882: sub multiple_select_form {
1.284 albertel 1883: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1884: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1885: my $output='';
1.191 matthew 1886: if (! defined($size)) {
1887: $size = 4;
1.283 albertel 1888: if (scalar(keys(%$hash))<4) {
1889: $size = scalar(keys(%$hash));
1.191 matthew 1890: }
1891: }
1.734 bisitz 1892: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1893: my @order;
1.506 raeburn 1894: if (ref($order) eq 'ARRAY') {
1895: @order = @{$order};
1896: } else {
1897: @order = sort(keys(%$hash));
1.501 banghart 1898: }
1899: if (exists($$hash{'select_form_order'})) {
1900: @order = @{$$hash{'select_form_order'}};
1901: }
1902:
1.284 albertel 1903: foreach my $key (@order) {
1.356 albertel 1904: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1905: $output.='selected="selected" ' if ($selected{$key});
1906: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1907: }
1908: $output.="</select>\n";
1909: return $output;
1910: }
1911:
1.88 www 1912: #-------------------------------------------
1913:
1914: =pod
1915:
1.948.2.7 raeburn 1916: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1917:
1918: Returns a string containing a <select name='$name' size='1'> form to
1.948.2.7 raeburn 1919: allow a user to select options from a ref to a hash containing:
1920: option_name => displayed text. An optional $onchange can include
1921: a javascript onchange item, e.g., onchange="this.form.submit();"
1922:
1.88 www 1923: See lonrights.pm for an example invocation and use.
1924:
1925: =cut
1926:
1927: #-------------------------------------------
1928: sub select_form {
1.948.2.7 raeburn 1929: my ($def,$name,$hashref,$onchange) = @_;
1930: return unless (ref($hashref) eq 'HASH');
1931: if ($onchange) {
1932: $onchange = ' onchange="'.$onchange.'"';
1933: }
1934: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1935: my @keys;
1.948.2.7 raeburn 1936: if (exists($hashref->{'select_form_order'})) {
1937: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1938: } else {
1.948.2.7 raeburn 1939: @keys=sort(keys(%{$hashref}));
1.128 albertel 1940: }
1.356 albertel 1941: foreach my $key (@keys) {
1942: $selectform.=
1943: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1944: ($key eq $def ? 'selected="selected" ' : '').
1.948.2.7 raeburn 1945: ">".$hashref->{$key}."</option>\n";
1.88 www 1946: }
1947: $selectform.="</select>";
1948: return $selectform;
1949: }
1950:
1.475 www 1951: # For display filters
1952:
1953: sub display_filter {
1954: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1955: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1956: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1957: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1958: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1959: '</label></span> <span class="LC_nobreak">'.
1.475 www 1960: &mt('Filter [_1]',
1.477 www 1961: &select_form($env{'form.displayfilter'},
1962: 'displayfilter',
1.948.2.7 raeburn 1963: {'currentfolder' => 'Current folder/page',
1.477 www 1964: 'containing' => 'Containing phrase',
1.948.2.7 raeburn 1965: 'none' => 'None'})).
1.714 bisitz 1966: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1967: }
1968:
1.167 www 1969: sub gradeleveldescription {
1970: my $gradelevel=shift;
1971: my %gradelevels=(0 => 'Not specified',
1972: 1 => 'Grade 1',
1973: 2 => 'Grade 2',
1974: 3 => 'Grade 3',
1975: 4 => 'Grade 4',
1976: 5 => 'Grade 5',
1977: 6 => 'Grade 6',
1978: 7 => 'Grade 7',
1979: 8 => 'Grade 8',
1980: 9 => 'Grade 9',
1981: 10 => 'Grade 10',
1982: 11 => 'Grade 11',
1983: 12 => 'Grade 12',
1984: 13 => 'Grade 13',
1985: 14 => '100 Level',
1986: 15 => '200 Level',
1987: 16 => '300 Level',
1988: 17 => '400 Level',
1989: 18 => 'Graduate Level');
1990: return &mt($gradelevels{$gradelevel});
1991: }
1992:
1.163 www 1993: sub select_level_form {
1994: my ($deflevel,$name)=@_;
1995: unless ($deflevel) { $deflevel=0; }
1.167 www 1996: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1997: for (my $i=0; $i<=18; $i++) {
1998: $selectform.="<option value=\"$i\" ".
1.253 albertel 1999: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2000: ">".&gradeleveldescription($i)."</option>\n";
2001: }
2002: $selectform.="</select>";
2003: return $selectform;
1.163 www 2004: }
1.167 www 2005:
1.35 matthew 2006: #-------------------------------------------
2007:
1.45 matthew 2008: =pod
2009:
1.910 raeburn 2010: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2011:
2012: Returns a string containing a <select name='$name' size='1'> form to
2013: allow a user to select the domain to preform an operation in.
2014: See loncreateuser.pm for an example invocation and use.
2015:
1.90 www 2016: If the $includeempty flag is set, it also includes an empty choice ("no domain
2017: selected");
2018:
1.743 raeburn 2019: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2020:
1.910 raeburn 2021: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2022:
2023: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2024:
1.35 matthew 2025: =cut
2026:
2027: #-------------------------------------------
1.34 matthew 2028: sub select_dom_form {
1.910 raeburn 2029: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2030: if ($onchange) {
1.874 raeburn 2031: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2032: }
1.910 raeburn 2033: my @domains;
2034: if (ref($incdoms) eq 'ARRAY') {
2035: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2036: } else {
2037: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2038: }
1.90 www 2039: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2040: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2041: foreach my $dom (@domains) {
2042: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2043: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2044: if ($showdomdesc) {
2045: if ($dom ne '') {
2046: my $domdesc = &Apache::lonnet::domain($dom,'description');
2047: if ($domdesc ne '') {
2048: $selectdomain .= ' ('.$domdesc.')';
2049: }
2050: }
2051: }
2052: $selectdomain .= "</option>\n";
1.34 matthew 2053: }
2054: $selectdomain.="</select>";
2055: return $selectdomain;
2056: }
2057:
1.35 matthew 2058: #-------------------------------------------
2059:
1.45 matthew 2060: =pod
2061:
1.648 raeburn 2062: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2063:
1.586 raeburn 2064: input: 4 arguments (two required, two optional) -
2065: $domain - domain of new user
2066: $name - name of form element
2067: $default - Value of 'default' causes a default item to be first
2068: option, and selected by default.
2069: $hide - Value of 'hide' causes hiding of the name of the server,
2070: if 1 server found, or default, if 0 found.
1.594 raeburn 2071: output: returns 2 items:
1.586 raeburn 2072: (a) form element which contains either:
2073: (i) <select name="$name">
2074: <option value="$hostid1">$hostid $servers{$hostid}</option>
2075: <option value="$hostid2">$hostid $servers{$hostid}</option>
2076: </select>
2077: form item if there are multiple library servers in $domain, or
2078: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2079: if there is only one library server in $domain.
2080:
2081: (b) number of library servers found.
2082:
2083: See loncreateuser.pm for example of use.
1.35 matthew 2084:
2085: =cut
2086:
2087: #-------------------------------------------
1.586 raeburn 2088: sub home_server_form_item {
2089: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2090: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2091: my $result;
2092: my $numlib = keys(%servers);
2093: if ($numlib > 1) {
2094: $result .= '<select name="'.$name.'" />'."\n";
2095: if ($default) {
1.804 bisitz 2096: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2097: '</option>'."\n";
2098: }
2099: foreach my $hostid (sort(keys(%servers))) {
2100: $result.= '<option value="'.$hostid.'">'.
2101: $hostid.' '.$servers{$hostid}."</option>\n";
2102: }
2103: $result .= '</select>'."\n";
2104: } elsif ($numlib == 1) {
2105: my $hostid;
2106: foreach my $item (keys(%servers)) {
2107: $hostid = $item;
2108: }
2109: $result .= '<input type="hidden" name="'.$name.'" value="'.
2110: $hostid.'" />';
2111: if (!$hide) {
2112: $result .= $hostid.' '.$servers{$hostid};
2113: }
2114: $result .= "\n";
2115: } elsif ($default) {
2116: $result .= '<input type="hidden" name="'.$name.
2117: '" value="default" />';
2118: if (!$hide) {
2119: $result .= &mt('default');
2120: }
2121: $result .= "\n";
1.33 matthew 2122: }
1.586 raeburn 2123: return ($result,$numlib);
1.33 matthew 2124: }
1.112 bowersj2 2125:
2126: =pod
2127:
1.534 albertel 2128: =back
2129:
1.112 bowersj2 2130: =cut
1.87 matthew 2131:
2132: ###############################################################
1.112 bowersj2 2133: ## Decoding User Agent ##
1.87 matthew 2134: ###############################################################
2135:
2136: =pod
2137:
1.112 bowersj2 2138: =head1 Decoding the User Agent
2139:
2140: =over 4
2141:
2142: =item * &decode_user_agent()
1.87 matthew 2143:
2144: Inputs: $r
2145:
2146: Outputs:
2147:
2148: =over 4
2149:
1.112 bowersj2 2150: =item * $httpbrowser
1.87 matthew 2151:
1.112 bowersj2 2152: =item * $clientbrowser
1.87 matthew 2153:
1.112 bowersj2 2154: =item * $clientversion
1.87 matthew 2155:
1.112 bowersj2 2156: =item * $clientmathml
1.87 matthew 2157:
1.112 bowersj2 2158: =item * $clientunicode
1.87 matthew 2159:
1.112 bowersj2 2160: =item * $clientos
1.87 matthew 2161:
2162: =back
2163:
1.157 matthew 2164: =back
2165:
1.87 matthew 2166: =cut
2167:
2168: ###############################################################
2169: ###############################################################
2170: sub decode_user_agent {
1.247 albertel 2171: my ($r)=@_;
1.87 matthew 2172: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2173: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2174: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2175: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2176: my $clientbrowser='unknown';
2177: my $clientversion='0';
2178: my $clientmathml='';
2179: my $clientunicode='0';
2180: for (my $i=0;$i<=$#browsertype;$i++) {
2181: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2182: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2183: $clientbrowser=$bname;
2184: $httpbrowser=~/$vreg/i;
2185: $clientversion=$1;
2186: $clientmathml=($clientversion>=$minv);
2187: $clientunicode=($clientversion>=$univ);
2188: }
2189: }
2190: my $clientos='unknown';
2191: if (($httpbrowser=~/linux/i) ||
2192: ($httpbrowser=~/unix/i) ||
2193: ($httpbrowser=~/ux/i) ||
2194: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2195: if (($httpbrowser=~/vax/i) ||
2196: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2197: if ($httpbrowser=~/next/i) { $clientos='next'; }
2198: if (($httpbrowser=~/mac/i) ||
2199: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2200: if ($httpbrowser=~/win/i) { $clientos='win'; }
2201: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2202: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2203: $clientunicode,$clientos,);
2204: }
2205:
1.32 matthew 2206: ###############################################################
2207: ## Authentication changing form generation subroutines ##
2208: ###############################################################
2209: ##
2210: ## All of the authform_xxxxxxx subroutines take their inputs in a
2211: ## hash, and have reasonable default values.
2212: ##
2213: ## formname = the name given in the <form> tag.
1.35 matthew 2214: #-------------------------------------------
2215:
1.45 matthew 2216: =pod
2217:
1.112 bowersj2 2218: =head1 Authentication Routines
2219:
2220: =over 4
2221:
1.648 raeburn 2222: =item * &authform_xxxxxx()
1.35 matthew 2223:
2224: The authform_xxxxxx subroutines provide javascript and html forms which
2225: handle some of the conveniences required for authentication forms.
2226: This is not an optimal method, but it works.
2227:
2228: =over 4
2229:
1.112 bowersj2 2230: =item * authform_header
1.35 matthew 2231:
1.112 bowersj2 2232: =item * authform_authorwarning
1.35 matthew 2233:
1.112 bowersj2 2234: =item * authform_nochange
1.35 matthew 2235:
1.112 bowersj2 2236: =item * authform_kerberos
1.35 matthew 2237:
1.112 bowersj2 2238: =item * authform_internal
1.35 matthew 2239:
1.112 bowersj2 2240: =item * authform_filesystem
1.35 matthew 2241:
2242: =back
2243:
1.648 raeburn 2244: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2245:
1.35 matthew 2246: =cut
2247:
2248: #-------------------------------------------
1.32 matthew 2249: sub authform_header{
2250: my %in = (
2251: formname => 'cu',
1.80 albertel 2252: kerb_def_dom => '',
1.32 matthew 2253: @_,
2254: );
2255: $in{'formname'} = 'document.' . $in{'formname'};
2256: my $result='';
1.80 albertel 2257:
2258: #---------------------------------------------- Code for upper case translation
2259: my $Javascript_toUpperCase;
2260: unless ($in{kerb_def_dom}) {
2261: $Javascript_toUpperCase =<<"END";
2262: switch (choice) {
2263: case 'krb': currentform.elements[choicearg].value =
2264: currentform.elements[choicearg].value.toUpperCase();
2265: break;
2266: default:
2267: }
2268: END
2269: } else {
2270: $Javascript_toUpperCase = "";
2271: }
2272:
1.165 raeburn 2273: my $radioval = "'nochange'";
1.591 raeburn 2274: if (defined($in{'curr_authtype'})) {
2275: if ($in{'curr_authtype'} ne '') {
2276: $radioval = "'".$in{'curr_authtype'}."arg'";
2277: }
1.174 matthew 2278: }
1.165 raeburn 2279: my $argfield = 'null';
1.591 raeburn 2280: if (defined($in{'mode'})) {
1.165 raeburn 2281: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2282: if (defined($in{'curr_autharg'})) {
2283: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2284: $argfield = "'$in{'curr_autharg'}'";
2285: }
2286: }
2287: }
2288: }
2289:
1.32 matthew 2290: $result.=<<"END";
2291: var current = new Object();
1.165 raeburn 2292: current.radiovalue = $radioval;
2293: current.argfield = $argfield;
1.32 matthew 2294:
2295: function changed_radio(choice,currentform) {
2296: var choicearg = choice + 'arg';
2297: // If a radio button in changed, we need to change the argfield
2298: if (current.radiovalue != choice) {
2299: current.radiovalue = choice;
2300: if (current.argfield != null) {
2301: currentform.elements[current.argfield].value = '';
2302: }
2303: if (choice == 'nochange') {
2304: current.argfield = null;
2305: } else {
2306: current.argfield = choicearg;
2307: switch(choice) {
2308: case 'krb':
2309: currentform.elements[current.argfield].value =
2310: "$in{'kerb_def_dom'}";
2311: break;
2312: default:
2313: break;
2314: }
2315: }
2316: }
2317: return;
2318: }
1.22 www 2319:
1.32 matthew 2320: function changed_text(choice,currentform) {
2321: var choicearg = choice + 'arg';
2322: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2323: $Javascript_toUpperCase
1.32 matthew 2324: // clear old field
2325: if ((current.argfield != choicearg) && (current.argfield != null)) {
2326: currentform.elements[current.argfield].value = '';
2327: }
2328: current.argfield = choicearg;
2329: }
2330: set_auth_radio_buttons(choice,currentform);
2331: return;
1.20 www 2332: }
1.32 matthew 2333:
2334: function set_auth_radio_buttons(newvalue,currentform) {
1.948.2.13 raeburn 2335: var numauthchoices = currentform.login.length;
2336: if (typeof numauthchoices == "undefined") {
2337: return;
2338: }
1.32 matthew 2339: var i=0;
1.948.2.17 raeburn 2340: while (i < numauthchoices) {
1.32 matthew 2341: if (currentform.login[i].value == newvalue) { break; }
2342: i++;
2343: }
1.948.2.13 raeburn 2344: if (i == numauthchoices) {
1.32 matthew 2345: return;
2346: }
2347: current.radiovalue = newvalue;
2348: currentform.login[i].checked = true;
2349: return;
2350: }
2351: END
2352: return $result;
2353: }
2354:
2355: sub authform_authorwarning{
2356: my $result='';
1.144 matthew 2357: $result='<i>'.
2358: &mt('As a general rule, only authors or co-authors should be '.
2359: 'filesystem authenticated '.
2360: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2361: return $result;
2362: }
2363:
2364: sub authform_nochange{
2365: my %in = (
2366: formname => 'document.cu',
2367: kerb_def_dom => 'MSU.EDU',
2368: @_,
2369: );
1.586 raeburn 2370: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2371: my $result;
2372: if (keys(%can_assign) == 0) {
2373: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2374: } else {
2375: $result = '<label>'.&mt('[_1] Do not change login data',
2376: '<input type="radio" name="login" value="nochange" '.
2377: 'checked="checked" onclick="'.
1.281 albertel 2378: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2379: '</label>';
1.586 raeburn 2380: }
1.32 matthew 2381: return $result;
2382: }
2383:
1.591 raeburn 2384: sub authform_kerberos {
1.32 matthew 2385: my %in = (
2386: formname => 'document.cu',
2387: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2388: kerb_def_auth => 'krb4',
1.32 matthew 2389: @_,
2390: );
1.586 raeburn 2391: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2392: $autharg,$jscall);
2393: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2394: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2395: $check5 = ' checked="checked"';
1.80 albertel 2396: } else {
1.772 bisitz 2397: $check4 = ' checked="checked"';
1.80 albertel 2398: }
1.165 raeburn 2399: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2400: if (defined($in{'curr_authtype'})) {
2401: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2402: $krbcheck = ' checked="checked"';
1.623 raeburn 2403: if (defined($in{'mode'})) {
2404: if ($in{'mode'} eq 'modifyuser') {
2405: $krbcheck = '';
2406: }
2407: }
1.591 raeburn 2408: if (defined($in{'curr_kerb_ver'})) {
2409: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2410: $check5 = ' checked="checked"';
1.591 raeburn 2411: $check4 = '';
2412: } else {
1.772 bisitz 2413: $check4 = ' checked="checked"';
1.591 raeburn 2414: $check5 = '';
2415: }
1.586 raeburn 2416: }
1.591 raeburn 2417: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2418: $krbarg = $in{'curr_autharg'};
2419: }
1.586 raeburn 2420: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2421: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2422: $result =
2423: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2424: $in{'curr_autharg'},$krbver);
2425: } else {
2426: $result =
2427: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2428: }
2429: return $result;
2430: }
2431: }
2432: } else {
2433: if ($authnum == 1) {
1.784 bisitz 2434: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2435: }
2436: }
1.586 raeburn 2437: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2438: return;
1.587 raeburn 2439: } elsif ($authtype eq '') {
1.591 raeburn 2440: if (defined($in{'mode'})) {
1.587 raeburn 2441: if ($in{'mode'} eq 'modifycourse') {
2442: if ($authnum == 1) {
1.784 bisitz 2443: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2444: }
2445: }
2446: }
1.586 raeburn 2447: }
2448: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2449: if ($authtype eq '') {
2450: $authtype = '<input type="radio" name="login" value="krb" '.
2451: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2452: $krbcheck.' />';
2453: }
2454: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2455: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2456: $in{'curr_authtype'} eq 'krb5') ||
2457: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2458: $in{'curr_authtype'} eq 'krb4')) {
2459: $result .= &mt
1.144 matthew 2460: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2461: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2462: '<label>'.$authtype,
1.281 albertel 2463: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2464: 'value="'.$krbarg.'" '.
1.144 matthew 2465: 'onchange="'.$jscall.'" />',
1.281 albertel 2466: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2467: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2468: '</label>');
1.586 raeburn 2469: } elsif ($can_assign{'krb4'}) {
2470: $result .= &mt
2471: ('[_1] Kerberos authenticated with domain [_2] '.
2472: '[_3] Version 4 [_4]',
2473: '<label>'.$authtype,
2474: '</label><input type="text" size="10" name="krbarg" '.
2475: 'value="'.$krbarg.'" '.
2476: 'onchange="'.$jscall.'" />',
2477: '<label><input type="hidden" name="krbver" value="4" />',
2478: '</label>');
2479: } elsif ($can_assign{'krb5'}) {
2480: $result .= &mt
2481: ('[_1] Kerberos authenticated with domain [_2] '.
2482: '[_3] Version 5 [_4]',
2483: '<label>'.$authtype,
2484: '</label><input type="text" size="10" name="krbarg" '.
2485: 'value="'.$krbarg.'" '.
2486: 'onchange="'.$jscall.'" />',
2487: '<label><input type="hidden" name="krbver" value="5" />',
2488: '</label>');
2489: }
1.32 matthew 2490: return $result;
2491: }
2492:
2493: sub authform_internal{
1.586 raeburn 2494: my %in = (
1.32 matthew 2495: formname => 'document.cu',
2496: kerb_def_dom => 'MSU.EDU',
2497: @_,
2498: );
1.586 raeburn 2499: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2500: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2501: if (defined($in{'curr_authtype'})) {
2502: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2503: if ($can_assign{'int'}) {
1.772 bisitz 2504: $intcheck = 'checked="checked" ';
1.623 raeburn 2505: if (defined($in{'mode'})) {
2506: if ($in{'mode'} eq 'modifyuser') {
2507: $intcheck = '';
2508: }
2509: }
1.591 raeburn 2510: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2511: $intarg = $in{'curr_autharg'};
2512: }
2513: } else {
2514: $result = &mt('Currently internally authenticated.');
2515: return $result;
1.165 raeburn 2516: }
2517: }
1.586 raeburn 2518: } else {
2519: if ($authnum == 1) {
1.784 bisitz 2520: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2521: }
2522: }
2523: if (!$can_assign{'int'}) {
2524: return;
1.587 raeburn 2525: } elsif ($authtype eq '') {
1.591 raeburn 2526: if (defined($in{'mode'})) {
1.587 raeburn 2527: if ($in{'mode'} eq 'modifycourse') {
2528: if ($authnum == 1) {
1.784 bisitz 2529: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2530: }
2531: }
2532: }
1.165 raeburn 2533: }
1.586 raeburn 2534: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2535: if ($authtype eq '') {
2536: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2537: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2538: }
1.605 bisitz 2539: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2540: $intarg.'" onchange="'.$jscall.'" />';
2541: $result = &mt
1.144 matthew 2542: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2543: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2544: $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 2545: return $result;
2546: }
2547:
2548: sub authform_local{
2549: my %in = (
2550: formname => 'document.cu',
2551: kerb_def_dom => 'MSU.EDU',
2552: @_,
2553: );
1.586 raeburn 2554: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2555: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2556: if (defined($in{'curr_authtype'})) {
2557: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2558: if ($can_assign{'loc'}) {
1.772 bisitz 2559: $loccheck = 'checked="checked" ';
1.623 raeburn 2560: if (defined($in{'mode'})) {
2561: if ($in{'mode'} eq 'modifyuser') {
2562: $loccheck = '';
2563: }
2564: }
1.591 raeburn 2565: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2566: $locarg = $in{'curr_autharg'};
2567: }
2568: } else {
2569: $result = &mt('Currently using local (institutional) authentication.');
2570: return $result;
1.165 raeburn 2571: }
2572: }
1.586 raeburn 2573: } else {
2574: if ($authnum == 1) {
1.784 bisitz 2575: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2576: }
2577: }
2578: if (!$can_assign{'loc'}) {
2579: return;
1.587 raeburn 2580: } elsif ($authtype eq '') {
1.591 raeburn 2581: if (defined($in{'mode'})) {
1.587 raeburn 2582: if ($in{'mode'} eq 'modifycourse') {
2583: if ($authnum == 1) {
1.784 bisitz 2584: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2585: }
2586: }
2587: }
1.165 raeburn 2588: }
1.586 raeburn 2589: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2590: if ($authtype eq '') {
2591: $authtype = '<input type="radio" name="login" value="loc" '.
2592: $loccheck.' onchange="'.$jscall.'" onclick="'.
2593: $jscall.'" />';
2594: }
2595: $autharg = '<input type="text" size="10" name="locarg" value="'.
2596: $locarg.'" onchange="'.$jscall.'" />';
2597: $result = &mt('[_1] Local Authentication with argument [_2]',
2598: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2599: return $result;
2600: }
2601:
2602: sub authform_filesystem{
2603: my %in = (
2604: formname => 'document.cu',
2605: kerb_def_dom => 'MSU.EDU',
2606: @_,
2607: );
1.586 raeburn 2608: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2609: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2610: if (defined($in{'curr_authtype'})) {
2611: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2612: if ($can_assign{'fsys'}) {
1.772 bisitz 2613: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2614: if (defined($in{'mode'})) {
2615: if ($in{'mode'} eq 'modifyuser') {
2616: $fsyscheck = '';
2617: }
2618: }
1.586 raeburn 2619: } else {
2620: $result = &mt('Currently Filesystem Authenticated.');
2621: return $result;
2622: }
2623: }
2624: } else {
2625: if ($authnum == 1) {
1.784 bisitz 2626: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2627: }
2628: }
2629: if (!$can_assign{'fsys'}) {
2630: return;
1.587 raeburn 2631: } elsif ($authtype eq '') {
1.591 raeburn 2632: if (defined($in{'mode'})) {
1.587 raeburn 2633: if ($in{'mode'} eq 'modifycourse') {
2634: if ($authnum == 1) {
1.784 bisitz 2635: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2636: }
2637: }
2638: }
1.586 raeburn 2639: }
2640: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2641: if ($authtype eq '') {
2642: $authtype = '<input type="radio" name="login" value="fsys" '.
2643: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2644: $jscall.'" />';
2645: }
2646: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2647: ' onchange="'.$jscall.'" />';
2648: $result = &mt
1.144 matthew 2649: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2650: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2651: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2652: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2653: 'onchange="'.$jscall.'" />');
1.32 matthew 2654: return $result;
2655: }
2656:
1.586 raeburn 2657: sub get_assignable_auth {
2658: my ($dom) = @_;
2659: if ($dom eq '') {
2660: $dom = $env{'request.role.domain'};
2661: }
2662: my %can_assign = (
2663: krb4 => 1,
2664: krb5 => 1,
2665: int => 1,
2666: loc => 1,
2667: );
2668: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2669: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2670: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2671: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2672: my $context;
2673: if ($env{'request.role'} =~ /^au/) {
2674: $context = 'author';
2675: } elsif ($env{'request.role'} =~ /^dc/) {
2676: $context = 'domain';
2677: } elsif ($env{'request.course.id'}) {
2678: $context = 'course';
2679: }
2680: if ($context) {
2681: if (ref($authhash->{$context}) eq 'HASH') {
2682: %can_assign = %{$authhash->{$context}};
2683: }
2684: }
2685: }
2686: }
2687: my $authnum = 0;
2688: foreach my $key (keys(%can_assign)) {
2689: if ($can_assign{$key}) {
2690: $authnum ++;
2691: }
2692: }
2693: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2694: $authnum --;
2695: }
2696: return ($authnum,%can_assign);
2697: }
2698:
1.80 albertel 2699: ###############################################################
2700: ## Get Kerberos Defaults for Domain ##
2701: ###############################################################
2702: ##
2703: ## Returns default kerberos version and an associated argument
2704: ## as listed in file domain.tab. If not listed, provides
2705: ## appropriate default domain and kerberos version.
2706: ##
2707: #-------------------------------------------
2708:
2709: =pod
2710:
1.648 raeburn 2711: =item * &get_kerberos_defaults()
1.80 albertel 2712:
2713: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2714: version and domain. If not found, it defaults to version 4 and the
2715: domain of the server.
1.80 albertel 2716:
1.648 raeburn 2717: =over 4
2718:
1.80 albertel 2719: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2720:
1.648 raeburn 2721: =back
2722:
2723: =back
2724:
1.80 albertel 2725: =cut
2726:
2727: #-------------------------------------------
2728: sub get_kerberos_defaults {
2729: my $domain=shift;
1.641 raeburn 2730: my ($krbdef,$krbdefdom);
2731: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2732: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2733: $krbdef = $domdefaults{'auth_def'};
2734: $krbdefdom = $domdefaults{'auth_arg_def'};
2735: } else {
1.80 albertel 2736: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2737: my $krbdefdom=$1;
2738: $krbdefdom=~tr/a-z/A-Z/;
2739: $krbdef = "krb4";
2740: }
2741: return ($krbdef,$krbdefdom);
2742: }
1.112 bowersj2 2743:
1.32 matthew 2744:
1.46 matthew 2745: ###############################################################
2746: ## Thesaurus Functions ##
2747: ###############################################################
1.20 www 2748:
1.46 matthew 2749: =pod
1.20 www 2750:
1.112 bowersj2 2751: =head1 Thesaurus Functions
2752:
2753: =over 4
2754:
1.648 raeburn 2755: =item * &initialize_keywords()
1.46 matthew 2756:
2757: Initializes the package variable %Keywords if it is empty. Uses the
2758: package variable $thesaurus_db_file.
2759:
2760: =cut
2761:
2762: ###################################################
2763:
2764: sub initialize_keywords {
2765: return 1 if (scalar keys(%Keywords));
2766: # If we are here, %Keywords is empty, so fill it up
2767: # Make sure the file we need exists...
2768: if (! -e $thesaurus_db_file) {
2769: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2770: " failed because it does not exist");
2771: return 0;
2772: }
2773: # Set up the hash as a database
2774: my %thesaurus_db;
2775: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2776: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2777: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2778: $thesaurus_db_file);
2779: return 0;
2780: }
2781: # Get the average number of appearances of a word.
2782: my $avecount = $thesaurus_db{'average.count'};
2783: # Put keywords (those that appear > average) into %Keywords
2784: while (my ($word,$data)=each (%thesaurus_db)) {
2785: my ($count,undef) = split /:/,$data;
2786: $Keywords{$word}++ if ($count > $avecount);
2787: }
2788: untie %thesaurus_db;
2789: # Remove special values from %Keywords.
1.356 albertel 2790: foreach my $value ('total.count','average.count') {
2791: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2792: }
1.46 matthew 2793: return 1;
2794: }
2795:
2796: ###################################################
2797:
2798: =pod
2799:
1.648 raeburn 2800: =item * &keyword($word)
1.46 matthew 2801:
2802: Returns true if $word is a keyword. A keyword is a word that appears more
2803: than the average number of times in the thesaurus database. Calls
2804: &initialize_keywords
2805:
2806: =cut
2807:
2808: ###################################################
1.20 www 2809:
2810: sub keyword {
1.46 matthew 2811: return if (!&initialize_keywords());
2812: my $word=lc(shift());
2813: $word=~s/\W//g;
2814: return exists($Keywords{$word});
1.20 www 2815: }
1.46 matthew 2816:
2817: ###############################################################
2818:
2819: =pod
1.20 www 2820:
1.648 raeburn 2821: =item * &get_related_words()
1.46 matthew 2822:
1.160 matthew 2823: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2824: an array of words. If the keyword is not in the thesaurus, an empty array
2825: will be returned. The order of the words returned is determined by the
2826: database which holds them.
2827:
2828: Uses global $thesaurus_db_file.
2829:
2830: =cut
2831:
2832: ###############################################################
2833: sub get_related_words {
2834: my $keyword = shift;
2835: my %thesaurus_db;
2836: if (! -e $thesaurus_db_file) {
2837: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2838: "failed because the file does not exist");
2839: return ();
2840: }
2841: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2842: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2843: return ();
2844: }
2845: my @Words=();
1.429 www 2846: my $count=0;
1.46 matthew 2847: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2848: # The first element is the number of times
2849: # the word appears. We do not need it now.
1.429 www 2850: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2851: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2852: my $threshold=$mostfrequentcount/10;
2853: foreach my $possibleword (@RelatedWords) {
2854: my ($word,$wordcount)=split(/\,/,$possibleword);
2855: if ($wordcount>$threshold) {
2856: push(@Words,$word);
2857: $count++;
2858: if ($count>10) { last; }
2859: }
1.20 www 2860: }
2861: }
1.46 matthew 2862: untie %thesaurus_db;
2863: return @Words;
1.14 harris41 2864: }
1.46 matthew 2865:
1.112 bowersj2 2866: =pod
2867:
2868: =back
2869:
2870: =cut
1.61 www 2871:
2872: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2873: =pod
2874:
1.112 bowersj2 2875: =head1 User Name Functions
2876:
2877: =over 4
2878:
1.648 raeburn 2879: =item * &plainname($uname,$udom,$first)
1.81 albertel 2880:
1.112 bowersj2 2881: Takes a users logon name and returns it as a string in
1.226 albertel 2882: "first middle last generation" form
2883: if $first is set to 'lastname' then it returns it as
2884: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2885:
2886: =cut
1.61 www 2887:
1.295 www 2888:
1.81 albertel 2889: ###############################################################
1.61 www 2890: sub plainname {
1.226 albertel 2891: my ($uname,$udom,$first)=@_;
1.537 albertel 2892: return if (!defined($uname) || !defined($udom));
1.295 www 2893: my %names=&getnames($uname,$udom);
1.226 albertel 2894: my $name=&Apache::lonnet::format_name($names{'firstname'},
2895: $names{'middlename'},
2896: $names{'lastname'},
2897: $names{'generation'},$first);
2898: $name=~s/^\s+//;
1.62 www 2899: $name=~s/\s+$//;
2900: $name=~s/\s+/ /g;
1.353 albertel 2901: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2902: return $name;
1.61 www 2903: }
1.66 www 2904:
2905: # -------------------------------------------------------------------- Nickname
1.81 albertel 2906: =pod
2907:
1.648 raeburn 2908: =item * &nickname($uname,$udom)
1.81 albertel 2909:
2910: Gets a users name and returns it as a string as
2911:
2912: ""nickname""
1.66 www 2913:
1.81 albertel 2914: if the user has a nickname or
2915:
2916: "first middle last generation"
2917:
2918: if the user does not
2919:
2920: =cut
1.66 www 2921:
2922: sub nickname {
2923: my ($uname,$udom)=@_;
1.537 albertel 2924: return if (!defined($uname) || !defined($udom));
1.295 www 2925: my %names=&getnames($uname,$udom);
1.68 albertel 2926: my $name=$names{'nickname'};
1.66 www 2927: if ($name) {
2928: $name='"'.$name.'"';
2929: } else {
2930: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2931: $names{'lastname'}.' '.$names{'generation'};
2932: $name=~s/\s+$//;
2933: $name=~s/\s+/ /g;
2934: }
2935: return $name;
2936: }
2937:
1.295 www 2938: sub getnames {
2939: my ($uname,$udom)=@_;
1.537 albertel 2940: return if (!defined($uname) || !defined($udom));
1.433 albertel 2941: if ($udom eq 'public' && $uname eq 'public') {
2942: return ('lastname' => &mt('Public'));
2943: }
1.295 www 2944: my $id=$uname.':'.$udom;
2945: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2946: if ($cached) {
2947: return %{$names};
2948: } else {
2949: my %loadnames=&Apache::lonnet::get('environment',
2950: ['firstname','middlename','lastname','generation','nickname'],
2951: $udom,$uname);
2952: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2953: return %loadnames;
2954: }
2955: }
1.61 www 2956:
1.542 raeburn 2957: # -------------------------------------------------------------------- getemails
1.648 raeburn 2958:
1.542 raeburn 2959: =pod
2960:
1.648 raeburn 2961: =item * &getemails($uname,$udom)
1.542 raeburn 2962:
2963: Gets a user's email information and returns it as a hash with keys:
2964: notification, critnotification, permanentemail
2965:
2966: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2967: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2968:
1.648 raeburn 2969:
1.542 raeburn 2970: =cut
2971:
1.648 raeburn 2972:
1.466 albertel 2973: sub getemails {
2974: my ($uname,$udom)=@_;
2975: if ($udom eq 'public' && $uname eq 'public') {
2976: return;
2977: }
1.467 www 2978: if (!$udom) { $udom=$env{'user.domain'}; }
2979: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2980: my $id=$uname.':'.$udom;
2981: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2982: if ($cached) {
2983: return %{$names};
2984: } else {
2985: my %loadnames=&Apache::lonnet::get('environment',
2986: ['notification','critnotification',
2987: 'permanentemail'],
2988: $udom,$uname);
2989: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2990: return %loadnames;
2991: }
2992: }
2993:
1.551 albertel 2994: sub flush_email_cache {
2995: my ($uname,$udom)=@_;
2996: if (!$udom) { $udom =$env{'user.domain'}; }
2997: if (!$uname) { $uname=$env{'user.name'}; }
2998: return if ($udom eq 'public' && $uname eq 'public');
2999: my $id=$uname.':'.$udom;
3000: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3001: }
3002:
1.728 raeburn 3003: # -------------------------------------------------------------------- getlangs
3004:
3005: =pod
3006:
3007: =item * &getlangs($uname,$udom)
3008:
3009: Gets a user's language preference and returns it as a hash with key:
3010: language.
3011:
3012: =cut
3013:
3014:
3015: sub getlangs {
3016: my ($uname,$udom) = @_;
3017: if (!$udom) { $udom =$env{'user.domain'}; }
3018: if (!$uname) { $uname=$env{'user.name'}; }
3019: my $id=$uname.':'.$udom;
3020: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3021: if ($cached) {
3022: return %{$langs};
3023: } else {
3024: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3025: $udom,$uname);
3026: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3027: return %loadlangs;
3028: }
3029: }
3030:
3031: sub flush_langs_cache {
3032: my ($uname,$udom)=@_;
3033: if (!$udom) { $udom =$env{'user.domain'}; }
3034: if (!$uname) { $uname=$env{'user.name'}; }
3035: return if ($udom eq 'public' && $uname eq 'public');
3036: my $id=$uname.':'.$udom;
3037: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3038: }
3039:
1.61 www 3040: # ------------------------------------------------------------------ Screenname
1.81 albertel 3041:
3042: =pod
3043:
1.648 raeburn 3044: =item * &screenname($uname,$udom)
1.81 albertel 3045:
3046: Gets a users screenname and returns it as a string
3047:
3048: =cut
1.61 www 3049:
3050: sub screenname {
3051: my ($uname,$udom)=@_;
1.258 albertel 3052: if ($uname eq $env{'user.name'} &&
3053: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3054: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3055: return $names{'screenname'};
1.62 www 3056: }
3057:
1.212 albertel 3058:
1.802 bisitz 3059: # ------------------------------------------------------------- Confirm Wrapper
3060: =pod
3061:
3062: =item confirmwrapper
3063:
3064: Wrap messages about completion of operation in box
3065:
3066: =cut
3067:
3068: sub confirmwrapper {
3069: my ($message)=@_;
3070: if ($message) {
3071: return "\n".'<div class="LC_confirm_box">'."\n"
3072: .$message."\n"
3073: .'</div>'."\n";
3074: } else {
3075: return $message;
3076: }
3077: }
3078:
1.62 www 3079: # ------------------------------------------------------------- Message Wrapper
3080:
3081: sub messagewrapper {
1.369 www 3082: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3083: return
1.441 albertel 3084: '<a href="/adm/email?compose=individual&'.
3085: 'recname='.$username.'&recdom='.$domain.
3086: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3087: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3088: }
1.802 bisitz 3089:
1.74 www 3090: # --------------------------------------------------------------- Notes Wrapper
3091:
3092: sub noteswrapper {
3093: my ($link,$un,$do)=@_;
3094: return
1.896 amueller 3095: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3096: }
1.802 bisitz 3097:
1.62 www 3098: # ------------------------------------------------------------- Aboutme Wrapper
3099:
3100: sub aboutmewrapper {
1.166 www 3101: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3102: if (!defined($username) && !defined($domain)) {
3103: return;
3104: }
1.892 amueller 3105: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3106: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3107: }
3108:
3109: # ------------------------------------------------------------ Syllabus Wrapper
3110:
3111: sub syllabuswrapper {
1.707 bisitz 3112: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3113: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3114: }
1.14 harris41 3115:
1.802 bisitz 3116: # -----------------------------------------------------------------------------
3117:
1.208 matthew 3118: sub track_student_link {
1.887 raeburn 3119: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3120: my $link ="/adm/trackstudent?";
1.208 matthew 3121: my $title = 'View recent activity';
3122: if (defined($sname) && $sname !~ /^\s*$/ &&
3123: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3124: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3125: $title .= ' of this student';
1.268 albertel 3126: }
1.208 matthew 3127: if (defined($target) && $target !~ /^\s*$/) {
3128: $target = qq{target="$target"};
3129: } else {
3130: $target = '';
3131: }
1.268 albertel 3132: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3133: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3134: $title = &mt($title);
3135: $linktext = &mt($linktext);
1.448 albertel 3136: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3137: &help_open_topic('View_recent_activity');
1.208 matthew 3138: }
3139:
1.781 raeburn 3140: sub slot_reservations_link {
3141: my ($linktext,$sname,$sdom,$target) = @_;
3142: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3143: my $title = 'View slot reservation history';
3144: if (defined($sname) && $sname !~ /^\s*$/ &&
3145: defined($sdom) && $sdom !~ /^\s*$/) {
3146: $link .= "&uname=$sname&udom=$sdom";
3147: $title .= ' of this student';
3148: }
3149: if (defined($target) && $target !~ /^\s*$/) {
3150: $target = qq{target="$target"};
3151: } else {
3152: $target = '';
3153: }
3154: $title = &mt($title);
3155: $linktext = &mt($linktext);
3156: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3157: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3158:
3159: }
3160:
1.508 www 3161: # ===================================================== Display a student photo
3162:
3163:
1.509 albertel 3164: sub student_image_tag {
1.508 www 3165: my ($domain,$user)=@_;
3166: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3167: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3168: return '<img src="'.$imgsrc.'" align="right" />';
3169: } else {
3170: return '';
3171: }
3172: }
3173:
1.112 bowersj2 3174: =pod
3175:
3176: =back
3177:
3178: =head1 Access .tab File Data
3179:
3180: =over 4
3181:
1.648 raeburn 3182: =item * &languageids()
1.112 bowersj2 3183:
3184: returns list of all language ids
3185:
3186: =cut
3187:
1.14 harris41 3188: sub languageids {
1.16 harris41 3189: return sort(keys(%language));
1.14 harris41 3190: }
3191:
1.112 bowersj2 3192: =pod
3193:
1.648 raeburn 3194: =item * &languagedescription()
1.112 bowersj2 3195:
3196: returns description of a specified language id
3197:
3198: =cut
3199:
1.14 harris41 3200: sub languagedescription {
1.125 www 3201: my $code=shift;
3202: return ($supported_language{$code}?'* ':'').
3203: $language{$code}.
1.126 www 3204: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3205: }
3206:
3207: sub plainlanguagedescription {
3208: my $code=shift;
3209: return $language{$code};
3210: }
3211:
3212: sub supportedlanguagecode {
3213: my $code=shift;
3214: return $supported_language{$code};
1.97 www 3215: }
3216:
1.112 bowersj2 3217: =pod
3218:
1.648 raeburn 3219: =item * ©rightids()
1.112 bowersj2 3220:
3221: returns list of all copyrights
3222:
3223: =cut
3224:
3225: sub copyrightids {
3226: return sort(keys(%cprtag));
3227: }
3228:
3229: =pod
3230:
1.648 raeburn 3231: =item * ©rightdescription()
1.112 bowersj2 3232:
3233: returns description of a specified copyright id
3234:
3235: =cut
3236:
3237: sub copyrightdescription {
1.166 www 3238: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3239: }
1.197 matthew 3240:
3241: =pod
3242:
1.648 raeburn 3243: =item * &source_copyrightids()
1.192 taceyjo1 3244:
3245: returns list of all source copyrights
3246:
3247: =cut
3248:
3249: sub source_copyrightids {
3250: return sort(keys(%scprtag));
3251: }
3252:
3253: =pod
3254:
1.648 raeburn 3255: =item * &source_copyrightdescription()
1.192 taceyjo1 3256:
3257: returns description of a specified source copyright id
3258:
3259: =cut
3260:
3261: sub source_copyrightdescription {
3262: return &mt($scprtag{shift(@_)});
3263: }
1.112 bowersj2 3264:
3265: =pod
3266:
1.648 raeburn 3267: =item * &filecategories()
1.112 bowersj2 3268:
3269: returns list of all file categories
3270:
3271: =cut
3272:
3273: sub filecategories {
3274: return sort(keys(%category_extensions));
3275: }
3276:
3277: =pod
3278:
1.648 raeburn 3279: =item * &filecategorytypes()
1.112 bowersj2 3280:
3281: returns list of file types belonging to a given file
3282: category
3283:
3284: =cut
3285:
3286: sub filecategorytypes {
1.356 albertel 3287: my ($cat) = @_;
3288: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3289: }
3290:
3291: =pod
3292:
1.648 raeburn 3293: =item * &fileembstyle()
1.112 bowersj2 3294:
3295: returns embedding style for a specified file type
3296:
3297: =cut
3298:
3299: sub fileembstyle {
3300: return $fe{lc(shift(@_))};
1.169 www 3301: }
3302:
1.351 www 3303: sub filemimetype {
3304: return $fm{lc(shift(@_))};
3305: }
3306:
1.169 www 3307:
3308: sub filecategoryselect {
3309: my ($name,$value)=@_;
1.189 matthew 3310: return &select_form($value,$name,
1.948.2.7 raeburn 3311: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3312: }
3313:
3314: =pod
3315:
1.648 raeburn 3316: =item * &filedescription()
1.112 bowersj2 3317:
3318: returns description for a specified file type
3319:
3320: =cut
3321:
3322: sub filedescription {
1.188 matthew 3323: my $file_description = $fd{lc(shift())};
3324: $file_description =~ s:([\[\]]):~$1:g;
3325: return &mt($file_description);
1.112 bowersj2 3326: }
3327:
3328: =pod
3329:
1.648 raeburn 3330: =item * &filedescriptionex()
1.112 bowersj2 3331:
3332: returns description for a specified file type with
3333: extra formatting
3334:
3335: =cut
3336:
3337: sub filedescriptionex {
3338: my $ex=shift;
1.188 matthew 3339: my $file_description = $fd{lc($ex)};
3340: $file_description =~ s:([\[\]]):~$1:g;
3341: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3342: }
3343:
3344: # End of .tab access
3345: =pod
3346:
3347: =back
3348:
3349: =cut
3350:
3351: # ------------------------------------------------------------------ File Types
3352: sub fileextensions {
3353: return sort(keys(%fe));
3354: }
3355:
1.97 www 3356: # ----------------------------------------------------------- Display Languages
3357: # returns a hash with all desired display languages
3358: #
3359:
3360: sub display_languages {
3361: my %languages=();
1.695 raeburn 3362: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3363: $languages{$lang}=1;
1.97 www 3364: }
3365: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3366: if ($env{'form.displaylanguage'}) {
1.356 albertel 3367: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3368: $languages{$lang}=1;
1.97 www 3369: }
3370: }
3371: return %languages;
1.14 harris41 3372: }
3373:
1.582 albertel 3374: sub languages {
3375: my ($possible_langs) = @_;
1.695 raeburn 3376: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3377: if (!ref($possible_langs)) {
3378: if( wantarray ) {
3379: return @preferred_langs;
3380: } else {
3381: return $preferred_langs[0];
3382: }
3383: }
3384: my %possibilities = map { $_ => 1 } (@$possible_langs);
3385: my @preferred_possibilities;
3386: foreach my $preferred_lang (@preferred_langs) {
3387: if (exists($possibilities{$preferred_lang})) {
3388: push(@preferred_possibilities, $preferred_lang);
3389: }
3390: }
3391: if( wantarray ) {
3392: return @preferred_possibilities;
3393: }
3394: return $preferred_possibilities[0];
3395: }
3396:
1.742 raeburn 3397: sub user_lang {
3398: my ($touname,$toudom,$fromcid) = @_;
3399: my @userlangs;
3400: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3401: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3402: $env{'course.'.$fromcid.'.languages'}));
3403: } else {
3404: my %langhash = &getlangs($touname,$toudom);
3405: if ($langhash{'languages'} ne '') {
3406: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3407: } else {
3408: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3409: if ($domdefs{'lang_def'} ne '') {
3410: @userlangs = ($domdefs{'lang_def'});
3411: }
3412: }
3413: }
3414: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3415: my $user_lh = Apache::localize->get_handle(@languages);
3416: return $user_lh;
3417: }
3418:
3419:
1.112 bowersj2 3420: ###############################################################
3421: ## Student Answer Attempts ##
3422: ###############################################################
3423:
3424: =pod
3425:
3426: =head1 Alternate Problem Views
3427:
3428: =over 4
3429:
1.648 raeburn 3430: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3431: $getattempt, $regexp, $gradesub)
3432:
3433: Return string with previous attempt on problem. Arguments:
3434:
3435: =over 4
3436:
3437: =item * $symb: Problem, including path
3438:
3439: =item * $username: username of the desired student
3440:
3441: =item * $domain: domain of the desired student
1.14 harris41 3442:
1.112 bowersj2 3443: =item * $course: Course ID
1.14 harris41 3444:
1.112 bowersj2 3445: =item * $getattempt: Leave blank for all attempts, otherwise put
3446: something
1.14 harris41 3447:
1.112 bowersj2 3448: =item * $regexp: if string matches this regexp, the string will be
3449: sent to $gradesub
1.14 harris41 3450:
1.112 bowersj2 3451: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3452:
1.112 bowersj2 3453: =back
1.14 harris41 3454:
1.112 bowersj2 3455: The output string is a table containing all desired attempts, if any.
1.16 harris41 3456:
1.112 bowersj2 3457: =cut
1.1 albertel 3458:
3459: sub get_previous_attempt {
1.43 ng 3460: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3461: my $prevattempts='';
1.43 ng 3462: no strict 'refs';
1.1 albertel 3463: if ($symb) {
1.3 albertel 3464: my (%returnhash)=
3465: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3466: if ($returnhash{'version'}) {
3467: my %lasthash=();
3468: my $version;
3469: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3470: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3471: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3472: }
1.1 albertel 3473: }
1.596 albertel 3474: $prevattempts=&start_data_table().&start_data_table_header_row();
3475: $prevattempts.='<th>'.&mt('History').'</th>';
1.948.2.8 raeburn 3476: my (%typeparts,%lasthidden);
1.945 raeburn 3477: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3478: foreach my $key (sort(keys(%lasthash))) {
3479: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3480: if ($#parts > 0) {
1.31 albertel 3481: my $data=$parts[-1];
1.948.2.15 raeburn 3482: next if ($data eq 'foilorder');
1.31 albertel 3483: pop(@parts);
1.945 raeburn 3484: if ($data eq 'type') {
3485: unless ($showsurv) {
3486: my $id = join(',',@parts);
3487: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.948.2.8 raeburn 3488: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3489: $lasthidden{$ign.'.'.$id} = 1;
3490: }
1.945 raeburn 3491: }
3492: delete($lasthash{$key});
3493: } else {
3494: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3495: }
1.31 albertel 3496: } else {
1.41 ng 3497: if ($#parts == 0) {
3498: $prevattempts.='<th>'.$parts[0].'</th>';
3499: } else {
3500: $prevattempts.='<th>'.$ign.'</th>';
3501: }
1.31 albertel 3502: }
1.16 harris41 3503: }
1.596 albertel 3504: $prevattempts.=&end_data_table_header_row();
1.40 ng 3505: if ($getattempt eq '') {
3506: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3507: my @hidden;
3508: if (%typeparts) {
3509: foreach my $id (keys(%typeparts)) {
3510: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3511: push(@hidden,$id);
3512: }
3513: }
3514: }
3515: $prevattempts.=&start_data_table_row().
3516: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3517: if (@hidden) {
3518: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3519: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3520: my $hide;
3521: foreach my $id (@hidden) {
3522: if ($key =~ /^\Q$id\E/) {
3523: $hide = 1;
3524: last;
3525: }
3526: }
3527: if ($hide) {
3528: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3529: if (($data eq 'award') || ($data eq 'awarddetail')) {
3530: my $value = &format_previous_attempt_value($key,
3531: $returnhash{$version.':'.$key});
3532: $prevattempts.='<td>'.$value.' </td>';
3533: } else {
3534: $prevattempts.='<td> </td>';
3535: }
3536: } else {
3537: if ($key =~ /\./) {
3538: my $value = &format_previous_attempt_value($key,
3539: $returnhash{$version.':'.$key});
3540: $prevattempts.='<td>'.$value.' </td>';
3541: } else {
3542: $prevattempts.='<td> </td>';
3543: }
3544: }
3545: }
3546: } else {
3547: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3548: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3549: my $value = &format_previous_attempt_value($key,
3550: $returnhash{$version.':'.$key});
3551: $prevattempts.='<td>'.$value.' </td>';
3552: }
3553: }
3554: $prevattempts.=&end_data_table_row();
1.40 ng 3555: }
1.1 albertel 3556: }
1.945 raeburn 3557: my @currhidden = keys(%lasthidden);
1.596 albertel 3558: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3559: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3560: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3561: if (%typeparts) {
3562: my $hidden;
3563: foreach my $id (@currhidden) {
3564: if ($key =~ /^\Q$id\E/) {
3565: $hidden = 1;
3566: last;
3567: }
3568: }
3569: if ($hidden) {
3570: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3571: if (($data eq 'award') || ($data eq 'awarddetail')) {
3572: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3573: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3574: $value = &$gradesub($value);
3575: }
3576: $prevattempts.='<td>'.$value.' </td>';
3577: } else {
3578: $prevattempts.='<td> </td>';
3579: }
3580: } else {
3581: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3582: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3583: $value = &$gradesub($value);
3584: }
3585: $prevattempts.='<td>'.$value.' </td>';
3586: }
3587: } else {
3588: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3589: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3590: $value = &$gradesub($value);
3591: }
3592: $prevattempts.='<td>'.$value.' </td>';
3593: }
1.16 harris41 3594: }
1.596 albertel 3595: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3596: } else {
1.596 albertel 3597: $prevattempts=
3598: &start_data_table().&start_data_table_row().
3599: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3600: &end_data_table_row().&end_data_table();
1.1 albertel 3601: }
3602: } else {
1.596 albertel 3603: $prevattempts=
3604: &start_data_table().&start_data_table_row().
3605: '<td>'.&mt('No data.').'</td>'.
3606: &end_data_table_row().&end_data_table();
1.1 albertel 3607: }
1.10 albertel 3608: }
3609:
1.581 albertel 3610: sub format_previous_attempt_value {
3611: my ($key,$value) = @_;
3612: if ($key =~ /timestamp/) {
3613: $value = &Apache::lonlocal::locallocaltime($value);
3614: } elsif (ref($value) eq 'ARRAY') {
3615: $value = '('.join(', ', @{ $value }).')';
1.948.2.14 raeburn 3616: } elsif ($key =~ /answerstring$/) {
3617: my %answers = &Apache::lonnet::str2hash($value);
3618: my @anskeys = sort(keys(%answers));
3619: if (@anskeys == 1) {
3620: my $answer = $answers{$anskeys[0]};
1.948.2.27 raeburn 3621: if ($answer =~ m{\0}) {
3622: $answer =~ s{\0}{,}g;
1.948.2.14 raeburn 3623: }
3624: my $tag_internal_answer_name = 'INTERNAL';
3625: if ($anskeys[0] eq $tag_internal_answer_name) {
3626: $value = $answer;
3627: } else {
3628: $value = $anskeys[0].'='.$answer;
3629: }
3630: } else {
3631: foreach my $ans (@anskeys) {
3632: my $answer = $answers{$ans};
1.948.2.27 raeburn 3633: if ($answer =~ m{\0}) {
3634: $answer =~ s{\0}{,}g;
1.948.2.14 raeburn 3635: }
3636: $value .= $ans.'='.$answer.'<br />';;
3637: }
3638: }
1.581 albertel 3639: } else {
3640: $value = &unescape($value);
3641: }
3642: return $value;
3643: }
3644:
3645:
1.107 albertel 3646: sub relative_to_absolute {
3647: my ($url,$output)=@_;
3648: my $parser=HTML::TokeParser->new(\$output);
3649: my $token;
3650: my $thisdir=$url;
3651: my @rlinks=();
3652: while ($token=$parser->get_token) {
3653: if ($token->[0] eq 'S') {
3654: if ($token->[1] eq 'a') {
3655: if ($token->[2]->{'href'}) {
3656: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3657: }
3658: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3659: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3660: } elsif ($token->[1] eq 'base') {
3661: $thisdir=$token->[2]->{'href'};
3662: }
3663: }
3664: }
3665: $thisdir=~s-/[^/]*$--;
1.356 albertel 3666: foreach my $link (@rlinks) {
1.726 raeburn 3667: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3668: ($link=~/^\//) ||
3669: ($link=~/^javascript:/i) ||
3670: ($link=~/^mailto:/i) ||
3671: ($link=~/^\#/)) {
3672: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3673: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3674: }
3675: }
3676: # -------------------------------------------------- Deal with Applet codebases
3677: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3678: return $output;
3679: }
3680:
1.112 bowersj2 3681: =pod
3682:
1.648 raeburn 3683: =item * &get_student_view()
1.112 bowersj2 3684:
3685: show a snapshot of what student was looking at
3686:
3687: =cut
3688:
1.10 albertel 3689: sub get_student_view {
1.186 albertel 3690: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3691: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3692: my (%form);
1.10 albertel 3693: my @elements=('symb','courseid','domain','username');
3694: foreach my $element (@elements) {
1.186 albertel 3695: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3696: }
1.186 albertel 3697: if (defined($moreenv)) {
3698: %form=(%form,%{$moreenv});
3699: }
1.236 albertel 3700: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3701: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3702: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3703: $userview=~s/\<body[^\>]*\>//gi;
3704: $userview=~s/\<\/body\>//gi;
3705: $userview=~s/\<html\>//gi;
3706: $userview=~s/\<\/html\>//gi;
3707: $userview=~s/\<head\>//gi;
3708: $userview=~s/\<\/head\>//gi;
3709: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3710: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3711: if (wantarray) {
3712: return ($userview,$response);
3713: } else {
3714: return $userview;
3715: }
3716: }
3717:
3718: sub get_student_view_with_retries {
3719: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3720:
3721: my $ok = 0; # True if we got a good response.
3722: my $content;
3723: my $response;
3724:
3725: # Try to get the student_view done. within the retries count:
3726:
3727: do {
3728: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3729: $ok = $response->is_success;
3730: if (!$ok) {
3731: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3732: }
3733: $retries--;
3734: } while (!$ok && ($retries > 0));
3735:
3736: if (!$ok) {
3737: $content = ''; # On error return an empty content.
3738: }
1.651 www 3739: if (wantarray) {
3740: return ($content, $response);
3741: } else {
3742: return $content;
3743: }
1.11 albertel 3744: }
3745:
1.112 bowersj2 3746: =pod
3747:
1.648 raeburn 3748: =item * &get_student_answers()
1.112 bowersj2 3749:
3750: show a snapshot of how student was answering problem
3751:
3752: =cut
3753:
1.11 albertel 3754: sub get_student_answers {
1.100 sakharuk 3755: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3756: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3757: my (%moreenv);
1.11 albertel 3758: my @elements=('symb','courseid','domain','username');
3759: foreach my $element (@elements) {
1.186 albertel 3760: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3761: }
1.186 albertel 3762: $moreenv{'grade_target'}='answer';
3763: %moreenv=(%form,%moreenv);
1.497 raeburn 3764: $feedurl = &Apache::lonnet::clutter($feedurl);
3765: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3766: return $userview;
1.1 albertel 3767: }
1.116 albertel 3768:
3769: =pod
3770:
3771: =item * &submlink()
3772:
1.242 albertel 3773: Inputs: $text $uname $udom $symb $target
1.116 albertel 3774:
3775: Returns: A link to grades.pm such as to see the SUBM view of a student
3776:
3777: =cut
3778:
3779: ###############################################
3780: sub submlink {
1.242 albertel 3781: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3782: if (!($uname && $udom)) {
3783: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3784: &Apache::lonnet::whichuser($symb);
1.116 albertel 3785: if (!$symb) { $symb=$cursymb; }
3786: }
1.254 matthew 3787: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3788: $symb=&escape($symb);
1.948.2.4 raeburn 3789: if ($target) { $target=" target=\"$target\""; }
3790: return
3791: '<a href="/adm/grades?command=submission'.
3792: '&symb='.$symb.
3793: '&student='.$uname.
3794: '&userdom='.$udom.'"'.
3795: $target.'>'.$text.'</a>';
1.242 albertel 3796: }
3797: ##############################################
3798:
3799: =pod
3800:
3801: =item * &pgrdlink()
3802:
3803: Inputs: $text $uname $udom $symb $target
3804:
3805: Returns: A link to grades.pm such as to see the PGRD view of a student
3806:
3807: =cut
3808:
3809: ###############################################
3810: sub pgrdlink {
3811: my $link=&submlink(@_);
3812: $link=~s/(&command=submission)/$1&showgrading=yes/;
3813: return $link;
3814: }
3815: ##############################################
3816:
3817: =pod
3818:
3819: =item * &pprmlink()
3820:
3821: Inputs: $text $uname $udom $symb $target
3822:
3823: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3824: student and a specific resource
1.242 albertel 3825:
3826: =cut
3827:
3828: ###############################################
3829: sub pprmlink {
3830: my ($text,$uname,$udom,$symb,$target)=@_;
3831: if (!($uname && $udom)) {
3832: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3833: &Apache::lonnet::whichuser($symb);
1.242 albertel 3834: if (!$symb) { $symb=$cursymb; }
3835: }
1.254 matthew 3836: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3837: $symb=&escape($symb);
1.242 albertel 3838: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3839: return '<a href="/adm/parmset?command=set&'.
3840: 'symb='.$symb.'&uname='.$uname.
3841: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3842: }
3843: ##############################################
1.37 matthew 3844:
1.112 bowersj2 3845: =pod
3846:
3847: =back
3848:
3849: =cut
3850:
1.37 matthew 3851: ###############################################
1.51 www 3852:
3853:
3854: sub timehash {
1.687 raeburn 3855: my ($thistime) = @_;
3856: my $timezone = &Apache::lonlocal::gettimezone();
3857: my $dt = DateTime->from_epoch(epoch => $thistime)
3858: ->set_time_zone($timezone);
3859: my $wday = $dt->day_of_week();
3860: if ($wday == 7) { $wday = 0; }
3861: return ( 'second' => $dt->second(),
3862: 'minute' => $dt->minute(),
3863: 'hour' => $dt->hour(),
3864: 'day' => $dt->day_of_month(),
3865: 'month' => $dt->month(),
3866: 'year' => $dt->year(),
3867: 'weekday' => $wday,
3868: 'dayyear' => $dt->day_of_year(),
3869: 'dlsav' => $dt->is_dst() );
1.51 www 3870: }
3871:
1.370 www 3872: sub utc_string {
3873: my ($date)=@_;
1.371 www 3874: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3875: }
3876:
1.51 www 3877: sub maketime {
3878: my %th=@_;
1.687 raeburn 3879: my ($epoch_time,$timezone,$dt);
3880: $timezone = &Apache::lonlocal::gettimezone();
3881: eval {
3882: $dt = DateTime->new( year => $th{'year'},
3883: month => $th{'month'},
3884: day => $th{'day'},
3885: hour => $th{'hour'},
3886: minute => $th{'minute'},
3887: second => $th{'second'},
3888: time_zone => $timezone,
3889: );
3890: };
3891: if (!$@) {
3892: $epoch_time = $dt->epoch;
3893: if ($epoch_time) {
3894: return $epoch_time;
3895: }
3896: }
1.51 www 3897: return POSIX::mktime(
3898: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3899: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3900: }
3901:
3902: #########################################
1.51 www 3903:
3904: sub findallcourses {
1.482 raeburn 3905: my ($roles,$uname,$udom) = @_;
1.355 albertel 3906: my %roles;
3907: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3908: my %courses;
1.51 www 3909: my $now=time;
1.482 raeburn 3910: if (!defined($uname)) {
3911: $uname = $env{'user.name'};
3912: }
3913: if (!defined($udom)) {
3914: $udom = $env{'user.domain'};
3915: }
3916: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.948.2.11 raeburn 3917: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3918: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3919: $extra);
1.482 raeburn 3920: if (!%roles) {
3921: %roles = (
3922: cc => 1,
1.907 raeburn 3923: co => 1,
1.482 raeburn 3924: in => 1,
3925: ep => 1,
3926: ta => 1,
3927: cr => 1,
3928: st => 1,
3929: );
3930: }
3931: foreach my $entry (keys(%roleshash)) {
3932: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3933: if ($trole =~ /^cr/) {
3934: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3935: } else {
3936: next if (!exists($roles{$trole}));
3937: }
3938: if ($tend) {
3939: next if ($tend < $now);
3940: }
3941: if ($tstart) {
3942: next if ($tstart > $now);
3943: }
3944: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3945: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3946: if ($secpart eq '') {
3947: ($cnum,$role) = split(/_/,$cnumpart);
3948: $sec = 'none';
3949: $realsec = '';
3950: } else {
3951: $cnum = $cnumpart;
3952: ($sec,$role) = split(/_/,$secpart);
3953: $realsec = $sec;
1.490 raeburn 3954: }
1.482 raeburn 3955: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3956: }
3957: } else {
3958: foreach my $key (keys(%env)) {
1.483 albertel 3959: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3960: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3961: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3962: next if ($role eq 'ca' || $role eq 'aa');
3963: next if (%roles && !exists($roles{$role}));
3964: my ($starttime,$endtime)=split(/\./,$env{$key});
3965: my $active=1;
3966: if ($starttime) {
3967: if ($now<$starttime) { $active=0; }
3968: }
3969: if ($endtime) {
3970: if ($now>$endtime) { $active=0; }
3971: }
3972: if ($active) {
3973: if ($sec eq '') {
3974: $sec = 'none';
3975: }
3976: $courses{$cdom.'_'.$cnum}{$sec} =
3977: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3978: }
3979: }
1.51 www 3980: }
3981: }
1.474 raeburn 3982: return %courses;
1.51 www 3983: }
1.37 matthew 3984:
1.54 www 3985: ###############################################
1.474 raeburn 3986:
3987: sub blockcheck {
1.482 raeburn 3988: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3989:
3990: if (!defined($udom)) {
3991: $udom = $env{'user.domain'};
3992: }
3993: if (!defined($uname)) {
3994: $uname = $env{'user.name'};
3995: }
3996:
3997: # If uname and udom are for a course, check for blocks in the course.
3998:
3999: if (&Apache::lonnet::is_course($udom,$uname)) {
4000: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 4001: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 4002: return ($startblock,$endblock);
4003: }
1.474 raeburn 4004:
1.502 raeburn 4005: my $startblock = 0;
4006: my $endblock = 0;
1.482 raeburn 4007: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4008:
1.490 raeburn 4009: # If uname is for a user, and activity is course-specific, i.e.,
4010: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4011:
1.490 raeburn 4012: if (($activity eq 'boards' || $activity eq 'chat' ||
4013: $activity eq 'groups') && ($env{'request.course.id'})) {
4014: foreach my $key (keys(%live_courses)) {
4015: if ($key ne $env{'request.course.id'}) {
4016: delete($live_courses{$key});
4017: }
4018: }
4019: }
4020:
4021: my $otheruser = 0;
4022: my %own_courses;
4023: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4024: # Resource belongs to user other than current user.
4025: $otheruser = 1;
4026: # Gather courses for current user
4027: %own_courses =
4028: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4029: }
4030:
4031: # Gather active course roles - course coordinator, instructor,
4032: # exam proctor, ta, student, or custom role.
1.474 raeburn 4033:
4034: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4035: my ($cdom,$cnum);
4036: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4037: $cdom = $env{'course.'.$course.'.domain'};
4038: $cnum = $env{'course.'.$course.'.num'};
4039: } else {
1.490 raeburn 4040: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4041: }
4042: my $no_ownblock = 0;
4043: my $no_userblock = 0;
1.533 raeburn 4044: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4045: # Check if current user has 'evb' priv for this
4046: if (defined($own_courses{$course})) {
4047: foreach my $sec (keys(%{$own_courses{$course}})) {
4048: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4049: if ($sec ne 'none') {
4050: $checkrole .= '/'.$sec;
4051: }
4052: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4053: $no_ownblock = 1;
4054: last;
4055: }
4056: }
4057: }
4058: # if they have 'evb' priv and are currently not playing student
4059: next if (($no_ownblock) &&
4060: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4061: }
1.474 raeburn 4062: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4063: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4064: if ($sec ne 'none') {
1.482 raeburn 4065: $checkrole .= '/'.$sec;
1.474 raeburn 4066: }
1.490 raeburn 4067: if ($otheruser) {
4068: # Resource belongs to user other than current user.
4069: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 4070: my ($trole,$tdom,$tnum,$tsec);
4071: my $entry = $live_courses{$course}{$sec};
4072: if ($entry =~ /^cr/) {
4073: ($trole,$tdom,$tnum,$tsec) =
4074: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4075: } else {
4076: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4077: }
4078: my ($spec,$area,$trest,%allroles,%userroles);
4079: $area = '/'.$tdom.'/'.$tnum;
4080: $trest = $tnum;
4081: if ($tsec ne '') {
4082: $area .= '/'.$tsec;
4083: $trest .= '/'.$tsec;
4084: }
4085: $spec = $trole.'.'.$area;
4086: if ($trole =~ /^cr/) {
4087: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4088: $tdom,$spec,$trest,$area);
4089: } else {
4090: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4091: $tdom,$spec,$trest,$area);
4092: }
4093: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4094: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4095: if ($1) {
4096: $no_userblock = 1;
4097: last;
4098: }
4099: }
1.490 raeburn 4100: } else {
4101: # Resource belongs to current user
4102: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4103: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4104: $no_ownblock = 1;
4105: last;
4106: }
1.474 raeburn 4107: }
4108: }
4109: # if they have the evb priv and are currently not playing student
1.482 raeburn 4110: next if (($no_ownblock) &&
1.491 albertel 4111: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4112: next if ($no_userblock);
1.474 raeburn 4113:
1.866 kalberla 4114: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4115: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4116:
4117: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4118: if (($start != 0) &&
4119: (($startblock == 0) || ($startblock > $start))) {
4120: $startblock = $start;
4121: }
4122: if (($end != 0) &&
4123: (($endblock == 0) || ($endblock < $end))) {
4124: $endblock = $end;
4125: }
1.490 raeburn 4126: }
4127: return ($startblock,$endblock);
4128: }
4129:
4130: sub get_blocks {
4131: my ($setters,$activity,$cdom,$cnum) = @_;
4132: my $startblock = 0;
4133: my $endblock = 0;
4134: my $course = $cdom.'_'.$cnum;
4135: $setters->{$course} = {};
4136: $setters->{$course}{'staff'} = [];
4137: $setters->{$course}{'times'} = [];
4138: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4139: foreach my $record (keys(%records)) {
4140: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4141: if ($start <= time && $end >= time) {
4142: my ($staff_name,$staff_dom,$title,$blocks) =
4143: &parse_block_record($records{$record});
4144: if ($blocks->{$activity} eq 'on') {
4145: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4146: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4147: if ( ($startblock == 0) || ($startblock > $start) ) {
4148: $startblock = $start;
1.490 raeburn 4149: }
1.491 albertel 4150: if ( ($endblock == 0) || ($endblock < $end) ) {
4151: $endblock = $end;
1.474 raeburn 4152: }
4153: }
4154: }
4155: }
4156: return ($startblock,$endblock);
4157: }
4158:
4159: sub parse_block_record {
4160: my ($record) = @_;
4161: my ($setuname,$setudom,$title,$blocks);
4162: if (ref($record) eq 'HASH') {
4163: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4164: $title = &unescape($record->{'event'});
4165: $blocks = $record->{'blocks'};
4166: } else {
4167: my @data = split(/:/,$record,3);
4168: if (scalar(@data) eq 2) {
4169: $title = $data[1];
4170: ($setuname,$setudom) = split(/@/,$data[0]);
4171: } else {
4172: ($setuname,$setudom,$title) = @data;
4173: }
4174: $blocks = { 'com' => 'on' };
4175: }
4176: return ($setuname,$setudom,$title,$blocks);
4177: }
4178:
1.854 kalberla 4179: sub blocking_status {
4180: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4181: my %setters;
1.890 droeschl 4182:
4183: # check for active blocking
1.867 kalberla 4184: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4185:
1.890 droeschl 4186: my $blocked = $startblock && $endblock ? 1 : 0;
4187:
4188: # caller just wants to know whether a block is active
4189: if (!wantarray) { return $blocked; }
4190:
4191: # build a link to a popup window containing the details
4192: my $querystring = "?activity=$activity";
4193: # $uname and $udom decide whose portfolio the user is trying to look at
4194: $querystring .= "&udom=$udom" if $udom;
4195: $querystring .= "&uname=$uname" if $uname;
4196:
4197: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4198: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4199: var options = "width=" + w + ",height=" + h + ",";
4200: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4201: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4202: var newWin = window.open(url, wdwName, options);
4203: newWin.focus();
4204: }
1.890 droeschl 4205: END_MYBLOCK
1.854 kalberla 4206:
1.890 droeschl 4207: $output = Apache::lonhtmlcommon::scripttag($output);
4208:
1.854 kalberla 4209: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4210: my $text = mt('Communication Blocked');
4211:
1.867 kalberla 4212: $output .= <<"END_BLOCK";
4213: <div class='LC_comblock'>
1.869 kalberla 4214: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4215: title='$text'>
4216: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4217: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4218: title='$text'>$text</a>
1.867 kalberla 4219: </div>
4220:
4221: END_BLOCK
1.474 raeburn 4222:
1.854 kalberla 4223: return ($blocked, $output);
4224: }
1.490 raeburn 4225:
1.60 matthew 4226: ###############################################
4227:
1.682 raeburn 4228: sub check_ip_acc {
4229: my ($acc)=@_;
4230: &Apache::lonxml::debug("acc is $acc");
4231: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4232: return 1;
4233: }
4234: my $allowed=0;
4235: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4236:
4237: my $name;
4238: foreach my $pattern (split(',',$acc)) {
4239: $pattern =~ s/^\s*//;
4240: $pattern =~ s/\s*$//;
4241: if ($pattern =~ /\*$/) {
4242: #35.8.*
4243: $pattern=~s/\*//;
4244: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4245: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4246: #35.8.3.[34-56]
4247: my $low=$2;
4248: my $high=$3;
4249: $pattern=$1;
4250: if ($ip =~ /^\Q$pattern\E/) {
4251: my $last=(split(/\./,$ip))[3];
4252: if ($last <=$high && $last >=$low) { $allowed=1; }
4253: }
4254: } elsif ($pattern =~ /^\*/) {
4255: #*.msu.edu
4256: $pattern=~s/\*//;
4257: if (!defined($name)) {
4258: use Socket;
4259: my $netaddr=inet_aton($ip);
4260: ($name)=gethostbyaddr($netaddr,AF_INET);
4261: }
4262: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4263: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4264: #127.0.0.1
4265: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4266: } else {
4267: #some.name.com
4268: if (!defined($name)) {
4269: use Socket;
4270: my $netaddr=inet_aton($ip);
4271: ($name)=gethostbyaddr($netaddr,AF_INET);
4272: }
4273: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4274: }
4275: if ($allowed) { last; }
4276: }
4277: return $allowed;
4278: }
4279:
4280: ###############################################
4281:
1.60 matthew 4282: =pod
4283:
1.112 bowersj2 4284: =head1 Domain Template Functions
4285:
4286: =over 4
4287:
4288: =item * &determinedomain()
1.60 matthew 4289:
4290: Inputs: $domain (usually will be undef)
4291:
1.63 www 4292: Returns: Determines which domain should be used for designs
1.60 matthew 4293:
4294: =cut
1.54 www 4295:
1.60 matthew 4296: ###############################################
1.63 www 4297: sub determinedomain {
4298: my $domain=shift;
1.531 albertel 4299: if (! $domain) {
1.60 matthew 4300: # Determine domain if we have not been given one
1.893 raeburn 4301: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4302: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4303: if ($env{'request.role.domain'}) {
4304: $domain=$env{'request.role.domain'};
1.60 matthew 4305: }
4306: }
1.63 www 4307: return $domain;
4308: }
4309: ###############################################
1.517 raeburn 4310:
1.518 albertel 4311: sub devalidate_domconfig_cache {
4312: my ($udom)=@_;
4313: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4314: }
4315:
4316: # ---------------------- Get domain configuration for a domain
4317: sub get_domainconf {
4318: my ($udom) = @_;
4319: my $cachetime=1800;
4320: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4321: if (defined($cached)) { return %{$result}; }
4322:
4323: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4324: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4325: my (%designhash,%legacy);
1.518 albertel 4326: if (keys(%domconfig) > 0) {
4327: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4328: if (keys(%{$domconfig{'login'}})) {
4329: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4330: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4331: if ($key eq 'loginvia') {
4332: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.948.2.30 raeburn 4333: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4334: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4335: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4336: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4337: $designhash{$udom.'.login.loginvia'} = $server;
4338: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4339:
4340: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4341: } else {
1.948.2.30 raeburn 4342: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4343: }
4344: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4345: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4346: }
1.946 raeburn 4347: }
4348: }
4349: }
4350: }
4351: } else {
4352: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4353: $designhash{$udom.'.login.'.$key.'_'.$img} =
4354: $domconfig{'login'}{$key}{$img};
4355: }
1.699 raeburn 4356: }
4357: } else {
4358: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4359: }
1.632 raeburn 4360: }
4361: } else {
4362: $legacy{'login'} = 1;
1.518 albertel 4363: }
1.632 raeburn 4364: } else {
4365: $legacy{'login'} = 1;
1.518 albertel 4366: }
4367: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4368: if (keys(%{$domconfig{'rolecolors'}})) {
4369: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4370: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4371: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4372: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4373: }
1.518 albertel 4374: }
4375: }
1.632 raeburn 4376: } else {
4377: $legacy{'rolecolors'} = 1;
1.518 albertel 4378: }
1.632 raeburn 4379: } else {
4380: $legacy{'rolecolors'} = 1;
1.518 albertel 4381: }
1.948 raeburn 4382: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4383: if ($domconfig{'autoenroll'}{'co-owners'}) {
4384: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4385: }
4386: }
1.632 raeburn 4387: if (keys(%legacy) > 0) {
4388: my %legacyhash = &get_legacy_domconf($udom);
4389: foreach my $item (keys(%legacyhash)) {
4390: if ($item =~ /^\Q$udom\E\.login/) {
4391: if ($legacy{'login'}) {
4392: $designhash{$item} = $legacyhash{$item};
4393: }
4394: } else {
4395: if ($legacy{'rolecolors'}) {
4396: $designhash{$item} = $legacyhash{$item};
4397: }
1.518 albertel 4398: }
4399: }
4400: }
1.632 raeburn 4401: } else {
4402: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4403: }
4404: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4405: $cachetime);
4406: return %designhash;
4407: }
4408:
1.632 raeburn 4409: sub get_legacy_domconf {
4410: my ($udom) = @_;
4411: my %legacyhash;
4412: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4413: my $designfile = $designdir.'/'.$udom.'.tab';
4414: if (-e $designfile) {
4415: if ( open (my $fh,"<$designfile") ) {
4416: while (my $line = <$fh>) {
4417: next if ($line =~ /^\#/);
4418: chomp($line);
4419: my ($key,$val)=(split(/\=/,$line));
4420: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4421: }
4422: close($fh);
4423: }
4424: }
4425: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4426: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4427: }
4428: return %legacyhash;
4429: }
4430:
1.63 www 4431: =pod
4432:
1.112 bowersj2 4433: =item * &domainlogo()
1.63 www 4434:
4435: Inputs: $domain (usually will be undef)
4436:
4437: Returns: A link to a domain logo, if the domain logo exists.
4438: If the domain logo does not exist, a description of the domain.
4439:
4440: =cut
1.112 bowersj2 4441:
1.63 www 4442: ###############################################
4443: sub domainlogo {
1.517 raeburn 4444: my $domain = &determinedomain(shift);
1.518 albertel 4445: my %designhash = &get_domainconf($domain);
1.517 raeburn 4446: # See if there is a logo
4447: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4448: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4449: if ($imgsrc =~ m{^/(adm|res)/}) {
4450: if ($imgsrc =~ m{^/res/}) {
4451: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4452: &Apache::lonnet::repcopy($local_name);
4453: }
4454: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4455: }
4456: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4457: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4458: return &Apache::lonnet::domain($domain,'description');
1.59 www 4459: } else {
1.60 matthew 4460: return '';
1.59 www 4461: }
4462: }
1.63 www 4463: ##############################################
4464:
4465: =pod
4466:
1.112 bowersj2 4467: =item * &designparm()
1.63 www 4468:
4469: Inputs: $which parameter; $domain (usually will be undef)
4470:
4471: Returns: value of designparamter $which
4472:
4473: =cut
1.112 bowersj2 4474:
1.397 albertel 4475:
1.400 albertel 4476: ##############################################
1.397 albertel 4477: sub designparm {
4478: my ($which,$domain)=@_;
4479: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4480: return $env{'environment.color.'.$which};
1.96 www 4481: }
1.63 www 4482: $domain=&determinedomain($domain);
1.948.2.31! raeburn 4483: my %domdesign;
! 4484: unless ($domain eq 'public') {
! 4485: %domdesign = &get_domainconf($domain);
! 4486: }
1.520 raeburn 4487: my $output;
1.517 raeburn 4488: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4489: $output = $domdesign{$domain.'.'.$which};
1.63 www 4490: } else {
1.520 raeburn 4491: $output = $defaultdesign{$which};
4492: }
4493: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4494: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4495: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4496: if ($output =~ m{^/res/}) {
4497: my $local_name = &Apache::lonnet::filelocation('',$output);
4498: &Apache::lonnet::repcopy($local_name);
4499: }
1.520 raeburn 4500: $output = &lonhttpdurl($output);
4501: }
1.63 www 4502: }
1.520 raeburn 4503: return $output;
1.63 www 4504: }
1.59 www 4505:
1.822 bisitz 4506: ##############################################
4507: =pod
4508:
1.832 bisitz 4509: =item * &authorspace()
4510:
4511: Inputs: ./.
4512:
4513: Returns: Path to the Construction Space of the current user's
4514: accessed author space
4515: The author space will be that of the current user
4516: when accessing the own author space
4517: and that of the co-author/assistent co-author
4518: when accessing the co-author's/assistent co-author's
4519: space
4520:
4521: =cut
4522:
4523: sub authorspace {
4524: my $caname = '';
4525: if ($env{'request.role'} =~ /^ca|^aa/) {
4526: (undef,$caname) =
4527: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4528: } else {
4529: $caname = $env{'user.name'};
4530: }
4531: return '/priv/'.$caname.'/';
4532: }
4533:
4534: ##############################################
4535: =pod
4536:
1.822 bisitz 4537: =item * &head_subbox()
4538:
4539: Inputs: $content (contains HTML code with page functions, etc.)
4540:
4541: Returns: HTML div with $content
4542: To be included in page header
4543:
4544: =cut
4545:
4546: sub head_subbox {
4547: my ($content)=@_;
4548: my $output =
1.948.2.22 raeburn 4549: '<div class="LC_head_subbox">'
1.822 bisitz 4550: .$content
4551: .'</div>'
4552: }
4553:
4554: ##############################################
4555: =pod
4556:
4557: =item * &CSTR_pageheader()
4558:
4559: Inputs: ./.
4560:
4561: Returns: HTML div with CSTR path and recent box
4562: To be included on Construction Space pages
4563:
4564: =cut
4565:
4566: sub CSTR_pageheader {
4567: # this is for resources; directories have customtitle, and crumbs
4568: # and select recent are created in lonpubdir.pm
4569: my ($uname,$thisdisfn)=
4570: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4571: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4572: $formaction=~s/\/+/\//g;
4573:
4574: my $parentpath = '';
4575: my $lastitem = '';
4576: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4577: $parentpath = $1;
4578: $lastitem = $2;
4579: } else {
4580: $lastitem = $thisdisfn;
4581: }
1.921 bisitz 4582:
4583: my $output =
1.822 bisitz 4584: '<div>'
4585: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4586: .'<b>'.&mt('Construction Space:').'</b> '
4587: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4588: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4589: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4590:
4591: if ($lastitem) {
4592: $output .=
4593: '<span class="LC_filename">'
4594: .$lastitem
4595: .'</span>';
4596: }
4597: $output .=
4598: '<br />'
1.822 bisitz 4599: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4600: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4601: .'</form>'
4602: .&Apache::lonmenu::constspaceform()
4603: .'</div>';
1.921 bisitz 4604:
4605: return $output;
1.822 bisitz 4606: }
4607:
1.60 matthew 4608: ###############################################
4609: ###############################################
4610:
4611: =pod
4612:
1.112 bowersj2 4613: =back
4614:
1.549 albertel 4615: =head1 HTML Helpers
1.112 bowersj2 4616:
4617: =over 4
4618:
4619: =item * &bodytag()
1.60 matthew 4620:
4621: Returns a uniform header for LON-CAPA web pages.
4622:
4623: Inputs:
4624:
1.112 bowersj2 4625: =over 4
4626:
4627: =item * $title, A title to be displayed on the page.
4628:
4629: =item * $function, the current role (can be undef).
4630:
4631: =item * $addentries, extra parameters for the <body> tag.
4632:
4633: =item * $bodyonly, if defined, only return the <body> tag.
4634:
4635: =item * $domain, if defined, force a given domain.
4636:
4637: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4638: text interface only)
1.60 matthew 4639:
1.814 bisitz 4640: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4641: navigational links
1.317 albertel 4642:
1.338 albertel 4643: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4644:
1.361 albertel 4645: =item * $no_inline_link, if true and in remote mode, don't show the
4646: 'Switch To Inline Menu' link
4647:
1.460 albertel 4648: =item * $args, optional argument valid values are
4649: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4650: inherit_jsmath -> when creating popup window in a page,
4651: should it have jsmath forced on by the
4652: current page
1.460 albertel 4653:
1.112 bowersj2 4654: =back
4655:
1.60 matthew 4656: Returns: A uniform header for LON-CAPA web pages.
4657: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4658: If $bodyonly is undef or zero, an html string containing a <body> tag and
4659: other decorations will be returned.
4660:
4661: =cut
4662:
1.54 www 4663: sub bodytag {
1.831 bisitz 4664: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4665: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4666:
1.948.2.2 raeburn 4667: my $public;
4668: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4669: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4670: $public = 1;
4671: }
1.460 albertel 4672: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4673:
1.183 matthew 4674: $function = &get_users_function() if (!$function);
1.339 albertel 4675: my $img = &designparm($function.'.img',$domain);
4676: my $font = &designparm($function.'.font',$domain);
4677: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4678:
1.803 bisitz 4679: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4680: 'bgcolor' => $pgbg,
1.339 albertel 4681: 'text' => $font,
4682: 'alink' => &designparm($function.'.alink',$domain),
4683: 'vlink' => &designparm($function.'.vlink',$domain),
4684: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4685: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4686:
1.63 www 4687: # role and realm
1.378 raeburn 4688: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4689: if ($role eq 'ca') {
1.479 albertel 4690: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4691: $realm = &plainname($rname,$rdom);
1.378 raeburn 4692: }
1.55 www 4693: # realm
1.258 albertel 4694: if ($env{'request.course.id'}) {
1.378 raeburn 4695: if ($env{'request.role'} !~ /^cr/) {
4696: $role = &Apache::lonnet::plaintext($role,&course_type());
4697: }
1.898 raeburn 4698: if ($env{'request.course.sec'}) {
4699: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4700: }
1.359 albertel 4701: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4702: } else {
4703: $role = &Apache::lonnet::plaintext($role);
1.54 www 4704: }
1.433 albertel 4705:
1.359 albertel 4706: if (!$realm) { $realm=' '; }
1.55 www 4707: # Set messages
1.60 matthew 4708: my $messages=&domainlogo($domain);
1.330 albertel 4709:
1.438 albertel 4710: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4711:
1.101 www 4712: # construct main body tag
1.359 albertel 4713: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4714: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4715:
1.530 albertel 4716: if ($bodyonly) {
1.60 matthew 4717: return $bodytag;
1.798 tempelho 4718: }
1.359 albertel 4719:
1.410 albertel 4720: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.948.2.2 raeburn 4721: if ($public) {
1.433 albertel 4722: undef($role);
1.434 albertel 4723: } else {
4724: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4725: }
1.948.2.2 raeburn 4726:
1.762 bisitz 4727: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4728: #
4729: # Extra info if you are the DC
4730: my $dc_info = '';
4731: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4732: $env{'course.'.$env{'request.course.id'}.
4733: '.domain'}.'/'})) {
4734: my $cid = $env{'request.course.id'};
1.917 raeburn 4735: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4736: $dc_info =~ s/\s+$//;
1.359 albertel 4737: }
4738:
1.898 raeburn 4739: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4740: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4741:
1.948.2.19 raeburn 4742: if ($env{'environment.remote'} ne 'on') {
1.359 albertel 4743: # No Remote
1.916 droeschl 4744: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
1.948.2.19 raeburn 4745: return $bodytag;
4746: }
1.903 droeschl 4747:
4748: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4749:
4750: # if ($env{'request.state'} eq 'construct') {
4751: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4752: # }
4753:
1.359 albertel 4754:
4755:
1.916 droeschl 4756: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4757: if ($dc_info) {
4758: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4759: }
1.916 droeschl 4760: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4761: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4762: return $bodytag;
4763: }
1.948.2.19 raeburn 4764: if (($env{'request.noversionuri'} =~ m{^/adm/navmaps}) &&
4765: ($env{'environment.remotenavmap'} eq 'on')) {
4766: return $bodytag;
4767: }
1.894 droeschl 4768:
1.927 raeburn 4769: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4770: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4771: }
1.916 droeschl 4772:
1.903 droeschl 4773: $bodytag .= Apache::lonhtmlcommon::scripttag(
4774: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4775:
1.903 droeschl 4776: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4777:
1.917 raeburn 4778: if ($dc_info) {
4779: $dc_info = &dc_courseid_toggle($dc_info);
4780: }
4781: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4782:
1.903 droeschl 4783: #don't show menus for public users
1.948.2.2 raeburn 4784: if (!$public){
1.903 droeschl 4785: $bodytag .= Apache::lonmenu::secondary_menu();
4786: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4787: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4788: if ($env{'request.state'} eq 'construct') {
4789: $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
4790: $args->{'bread_crumbs'});
4791: } elsif ($forcereg) {
4792: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4793: }
1.903 droeschl 4794: }else{
4795: # this is to seperate menu from content when there's no secondary
4796: # menu. Especially needed for public accessible ressources.
4797: $bodytag .= '<hr style="clear:both" />';
4798: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4799: }
1.903 droeschl 4800:
1.235 raeburn 4801: return $bodytag;
1.94 www 4802: }
1.95 www 4803:
1.93 www 4804: #
1.95 www 4805: # Top frame rendering, Remote is up
1.93 www 4806: #
1.359 albertel 4807:
1.517 raeburn 4808: my $imgsrc = $img;
4809: if ($img =~ /^\/adm/) {
1.575 albertel 4810: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4811: }
4812: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4813:
1.305 www 4814: # Explicit link to get inline menu
1.361 albertel 4815: my $menu= ($no_inline_link?''
1.883 droeschl 4816: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917 raeburn 4817:
4818: if ($dc_info) {
4819: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
4820: }
4821:
1.948.2.25 raeburn 4822: unless ($env{'form.inhibitmenu'}) {
4823: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
4824: <ol class="LC_primary_menu LC_right">
4825: <li>$menu</li>
4826: </ol><div id="LC_realm"> $realm $dc_info</div>|;
4827: }
4828:
1.94 www 4829: return(<<ENDBODY);
1.60 matthew 4830: $bodytag
1.359 albertel 4831: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4832: <tr><td>$upperleft</td>
4833: <td>$messages </td>
1.54 www 4834: </tr>
1.359 albertel 4835: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4836: </tr>
1.356 albertel 4837: </table>
1.54 www 4838: ENDBODY
1.182 matthew 4839: }
4840:
1.917 raeburn 4841: sub dc_courseid_toggle {
4842: my ($dc_info) = @_;
1.948.2.10 raeburn 4843: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4844: '<a href="javascript:showCourseID();">'.
4845: &mt('(More ...)').'</a></span>'.
4846: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4847: }
4848:
1.330 albertel 4849: sub make_attr_string {
4850: my ($register,$attr_ref) = @_;
4851:
4852: if ($attr_ref && !ref($attr_ref)) {
4853: die("addentries Must be a hash ref ".
4854: join(':',caller(1))." ".
4855: join(':',caller(0))." ");
4856: }
4857:
4858: if ($register) {
1.339 albertel 4859: my ($on_load,$on_unload);
4860: foreach my $key (keys(%{$attr_ref})) {
4861: if (lc($key) eq 'onload') {
4862: $on_load.=$attr_ref->{$key}.';';
4863: delete($attr_ref->{$key});
4864:
4865: } elsif (lc($key) eq 'onunload') {
4866: $on_unload.=$attr_ref->{$key}.';';
4867: delete($attr_ref->{$key});
4868: }
4869: }
4870: $attr_ref->{'onload'} =
4871: &Apache::lonmenu::loadevents(). $on_load;
4872: $attr_ref->{'onunload'}=
4873: &Apache::lonmenu::unloadevents().$on_unload;
4874: }
4875:
4876: # Accessibility font enhance
4877: if ($env{'browser.fontenhance'} eq 'on') {
4878: my $style;
4879: foreach my $key (keys(%{$attr_ref})) {
4880: if (lc($key) eq 'style') {
4881: $style.=$attr_ref->{$key}.';';
4882: delete($attr_ref->{$key});
4883: }
4884: }
4885: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4886: }
1.339 albertel 4887:
1.330 albertel 4888: my $attr_string;
4889: foreach my $attr (keys(%$attr_ref)) {
4890: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4891: }
4892: return $attr_string;
4893: }
4894:
4895:
1.182 matthew 4896: ###############################################
1.251 albertel 4897: ###############################################
4898:
4899: =pod
4900:
4901: =item * &endbodytag()
4902:
4903: Returns a uniform footer for LON-CAPA web pages.
4904:
1.635 raeburn 4905: Inputs: 1 - optional reference to an args hash
4906: If in the hash, key for noredirectlink has a value which evaluates to true,
4907: a 'Continue' link is not displayed if the page contains an
4908: internal redirect in the <head></head> section,
4909: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4910:
4911: =cut
4912:
4913: sub endbodytag {
1.635 raeburn 4914: my ($args) = @_;
1.251 albertel 4915: my $endbodytag='</body>';
1.269 albertel 4916: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4917: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4918: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4919: $endbodytag=
4920: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4921: &mt('Continue').'</a>'.
4922: $endbodytag;
4923: }
1.315 albertel 4924: }
1.251 albertel 4925: return $endbodytag;
4926: }
4927:
1.352 albertel 4928: =pod
4929:
4930: =item * &standard_css()
4931:
4932: Returns a style sheet
4933:
4934: Inputs: (all optional)
4935: domain -> force to color decorate a page for a specific
4936: domain
4937: function -> force usage of a specific rolish color scheme
4938: bgcolor -> override the default page bgcolor
4939:
4940: =cut
4941:
1.343 albertel 4942: sub standard_css {
1.345 albertel 4943: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4944: $function = &get_users_function() if (!$function);
4945: my $img = &designparm($function.'.img', $domain);
4946: my $tabbg = &designparm($function.'.tabbg', $domain);
4947: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4948: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4949: #second colour for later usage
1.345 albertel 4950: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4951: my $pgbg_or_bgcolor =
4952: $bgcolor ||
1.352 albertel 4953: &designparm($function.'.pgbg', $domain);
1.382 albertel 4954: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4955: my $alink = &designparm($function.'.alink', $domain);
4956: my $vlink = &designparm($function.'.vlink', $domain);
4957: my $link = &designparm($function.'.link', $domain);
4958:
1.602 albertel 4959: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4960: my $mono = 'monospace';
1.850 bisitz 4961: my $data_table_head = $sidebg;
4962: my $data_table_light = '#FAFAFA';
4963: my $data_table_dark = '#F0F0F0';
1.470 banghart 4964: my $data_table_darker = '#CCCCCC';
1.349 albertel 4965: my $data_table_highlight = '#FFFF00';
1.352 albertel 4966: my $mail_new = '#FFBB77';
4967: my $mail_new_hover = '#DD9955';
4968: my $mail_read = '#BBBB77';
4969: my $mail_read_hover = '#999944';
4970: my $mail_replied = '#AAAA88';
4971: my $mail_replied_hover = '#888855';
4972: my $mail_other = '#99BBBB';
4973: my $mail_other_hover = '#669999';
1.391 albertel 4974: my $table_header = '#DDDDDD';
1.489 raeburn 4975: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4976: my $lg_border_color = '#C8C8C8';
1.948.2.1 raeburn 4977: my $button_hover = '#BF2317';
1.392 albertel 4978:
1.608 albertel 4979: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4980: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4981: : '0 3px 0 4px';
1.448 albertel 4982:
1.343 albertel 4983: return <<END;
1.947 droeschl 4984:
4985: /* needed for iframe to allow 100% height in FF */
4986: body, html {
4987: margin: 0;
4988: padding: 0 0.5%;
4989: height: 99%; /* to avoid scrollbars */
4990: }
4991:
1.795 www 4992: body {
1.911 bisitz 4993: font-family: $sans;
4994: line-height:130%;
4995: font-size:0.83em;
4996: color:$font;
1.795 www 4997: }
4998:
1.948.2.9 raeburn 4999: a:focus,
5000: a:focus img {
1.795 www 5001: color: red;
1.911 bisitz 5002: background: yellow;
1.795 www 5003: }
1.698 harmsja 5004:
1.911 bisitz 5005: form, .inline {
5006: display: inline;
1.795 www 5007: }
1.721 harmsja 5008:
1.795 www 5009: .LC_right {
1.911 bisitz 5010: text-align:right;
1.795 www 5011: }
5012:
5013: .LC_middle {
1.911 bisitz 5014: vertical-align:middle;
1.795 www 5015: }
1.721 harmsja 5016:
1.911 bisitz 5017: .LC_400Box {
5018: width:400px;
5019: }
1.721 harmsja 5020:
1.947 droeschl 5021: .LC_iframecontainer {
5022: width: 98%;
5023: margin: 0;
5024: position: fixed;
5025: top: 8.5em;
5026: bottom: 0;
5027: }
5028:
5029: .LC_iframecontainer iframe{
5030: border: none;
5031: width: 100%;
5032: height: 100%;
5033: }
5034:
1.778 bisitz 5035: .LC_filename {
5036: font-family: $mono;
5037: white-space:pre;
1.921 bisitz 5038: font-size: 120%;
1.778 bisitz 5039: }
5040:
5041: .LC_fileicon {
5042: border: none;
5043: height: 1.3em;
5044: vertical-align: text-bottom;
5045: margin-right: 0.3em;
5046: text-decoration:none;
5047: }
5048:
1.350 albertel 5049: .LC_error {
5050: color: red;
5051: font-size: larger;
5052: }
1.795 www 5053:
1.457 albertel 5054: .LC_warning,
5055: .LC_diff_removed {
1.733 bisitz 5056: color: red;
1.394 albertel 5057: }
1.532 albertel 5058:
5059: .LC_info,
1.457 albertel 5060: .LC_success,
5061: .LC_diff_added {
1.350 albertel 5062: color: green;
5063: }
1.795 www 5064:
1.802 bisitz 5065: div.LC_confirm_box {
5066: background-color: #FAFAFA;
5067: border: 1px solid $lg_border_color;
5068: margin-right: 0;
5069: padding: 5px;
5070: }
5071:
5072: div.LC_confirm_box .LC_error img,
5073: div.LC_confirm_box .LC_success img {
5074: vertical-align: middle;
5075: }
5076:
1.440 albertel 5077: .LC_icon {
1.771 droeschl 5078: border: none;
1.790 droeschl 5079: vertical-align: middle;
1.771 droeschl 5080: }
5081:
1.543 albertel 5082: .LC_docs_spacer {
5083: width: 25px;
5084: height: 1px;
1.771 droeschl 5085: border: none;
1.543 albertel 5086: }
1.346 albertel 5087:
1.532 albertel 5088: .LC_internal_info {
1.735 bisitz 5089: color: #999999;
1.532 albertel 5090: }
5091:
1.794 www 5092: .LC_discussion {
1.911 bisitz 5093: background: $tabbg;
5094: border: 1px solid black;
5095: margin: 2px;
1.794 www 5096: }
5097:
5098: .LC_disc_action_links_bar {
1.911 bisitz 5099: background: $tabbg;
5100: border: none;
5101: margin: 4px;
1.794 www 5102: }
5103:
5104: .LC_disc_action_left {
1.911 bisitz 5105: text-align: left;
1.794 www 5106: }
5107:
5108: .LC_disc_action_right {
1.911 bisitz 5109: text-align: right;
1.794 www 5110: }
5111:
5112: .LC_disc_new_item {
1.911 bisitz 5113: background: white;
5114: border: 2px solid red;
5115: margin: 2px;
1.794 www 5116: }
5117:
5118: .LC_disc_old_item {
1.911 bisitz 5119: background: white;
5120: border: 1px solid black;
5121: margin: 2px;
1.794 www 5122: }
5123:
1.458 albertel 5124: table.LC_pastsubmission {
5125: border: 1px solid black;
5126: margin: 2px;
5127: }
5128:
1.924 bisitz 5129: table#LC_menubuttons {
1.345 albertel 5130: width: 100%;
5131: background: $pgbg;
1.392 albertel 5132: border: 2px;
1.402 albertel 5133: border-collapse: separate;
1.803 bisitz 5134: padding: 0;
1.345 albertel 5135: }
1.392 albertel 5136:
1.801 tempelho 5137: table#LC_title_bar a {
5138: color: $fontmenu;
5139: }
1.836 bisitz 5140:
1.807 droeschl 5141: table#LC_title_bar {
1.819 tempelho 5142: clear: both;
1.836 bisitz 5143: display: none;
1.807 droeschl 5144: }
5145:
1.795 www 5146: table#LC_title_bar,
1.933 droeschl 5147: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5148: table#LC_title_bar.LC_with_remote {
1.359 albertel 5149: width: 100%;
1.392 albertel 5150: border-color: $pgbg;
5151: border-style: solid;
5152: border-width: $border;
1.379 albertel 5153: background: $pgbg;
1.801 tempelho 5154: color: $fontmenu;
1.392 albertel 5155: border-collapse: collapse;
1.803 bisitz 5156: padding: 0;
1.819 tempelho 5157: margin: 0;
1.359 albertel 5158: }
1.795 www 5159:
1.933 droeschl 5160: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5161: margin: 0;
5162: padding: 0;
1.933 droeschl 5163: position: relative;
5164: list-style: none;
1.913 droeschl 5165: }
1.933 droeschl 5166: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5167: display: inline;
5168: }
1.933 droeschl 5169:
5170: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5171: padding: 0;
1.933 droeschl 5172: margin: 0;
5173: float: left;
1.913 droeschl 5174: }
1.933 droeschl 5175: .LC_breadcrumb_tools_tools {
5176: padding: 0;
5177: margin: 0;
1.913 droeschl 5178: float: right;
5179: }
5180:
1.359 albertel 5181: table#LC_title_bar td {
5182: background: $tabbg;
5183: }
1.795 www 5184:
1.911 bisitz 5185: table#LC_menubuttons img {
1.803 bisitz 5186: border: none;
1.346 albertel 5187: }
1.795 www 5188:
1.842 droeschl 5189: .LC_breadcrumbs_component {
1.911 bisitz 5190: float: right;
5191: margin: 0 1em;
1.357 albertel 5192: }
1.842 droeschl 5193: .LC_breadcrumbs_component img {
1.911 bisitz 5194: vertical-align: middle;
1.777 tempelho 5195: }
1.795 www 5196:
1.383 albertel 5197: td.LC_table_cell_checkbox {
5198: text-align: center;
5199: }
1.795 www 5200:
5201: .LC_fontsize_small {
1.911 bisitz 5202: font-size: 70%;
1.705 tempelho 5203: }
5204:
1.844 bisitz 5205: #LC_breadcrumbs {
1.911 bisitz 5206: clear:both;
5207: background: $sidebg;
5208: border-bottom: 1px solid $lg_border_color;
5209: line-height: 2.5em;
1.933 droeschl 5210: overflow: hidden;
1.911 bisitz 5211: margin: 0;
5212: padding: 0;
1.948.2.24 raeburn 5213: text-align: left;
1.819 tempelho 5214: }
1.862 bisitz 5215:
1.839 droeschl 5216: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 5217: #LC_remote #LC_breadcrumbs {
1.911 bisitz 5218: display:none;
1.839 droeschl 5219: }
1.819 tempelho 5220:
1.948.2.22 raeburn 5221: .LC_head_subbox {
1.911 bisitz 5222: clear:both;
5223: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5224: border: 1px solid $sidebg;
5225: margin: 0 0 10px 0;
1.948.2.6 raeburn 5226: padding: 3px;
1.948.2.24 raeburn 5227: text-align: left;
1.822 bisitz 5228: }
5229:
1.795 www 5230: .LC_fontsize_medium {
1.911 bisitz 5231: font-size: 85%;
1.705 tempelho 5232: }
5233:
1.795 www 5234: .LC_fontsize_large {
1.911 bisitz 5235: font-size: 120%;
1.705 tempelho 5236: }
5237:
1.346 albertel 5238: .LC_menubuttons_inline_text {
5239: color: $font;
1.698 harmsja 5240: font-size: 90%;
1.701 harmsja 5241: padding-left:3px;
1.346 albertel 5242: }
5243:
1.934 droeschl 5244: .LC_menubuttons_inline_text img{
5245: vertical-align: middle;
5246: }
5247:
1.948.2.1 raeburn 5248: li.LC_menubuttons_inline_text img,a {
5249: cursor:pointer;
1.948.2.27 raeburn 5250: text-decoration: none;
1.948.2.1 raeburn 5251: }
5252:
1.526 www 5253: .LC_menubuttons_link {
5254: text-decoration: none;
5255: }
1.795 www 5256:
1.522 albertel 5257: .LC_menubuttons_category {
1.521 www 5258: color: $font;
1.526 www 5259: background: $pgbg;
1.521 www 5260: font-size: larger;
5261: font-weight: bold;
5262: }
5263:
1.346 albertel 5264: td.LC_menubuttons_text {
1.911 bisitz 5265: color: $font;
1.346 albertel 5266: }
1.706 harmsja 5267:
1.346 albertel 5268: .LC_current_location {
5269: background: $tabbg;
5270: }
1.795 www 5271:
1.938 bisitz 5272: table.LC_data_table {
1.347 albertel 5273: border: 1px solid #000000;
1.402 albertel 5274: border-collapse: separate;
1.426 albertel 5275: border-spacing: 1px;
1.610 albertel 5276: background: $pgbg;
1.347 albertel 5277: }
1.795 www 5278:
1.422 albertel 5279: .LC_data_table_dense {
5280: font-size: small;
5281: }
1.795 www 5282:
1.507 raeburn 5283: table.LC_nested_outer {
5284: border: 1px solid #000000;
1.589 raeburn 5285: border-collapse: collapse;
1.803 bisitz 5286: border-spacing: 0;
1.507 raeburn 5287: width: 100%;
5288: }
1.795 www 5289:
1.879 raeburn 5290: table.LC_innerpickbox,
1.507 raeburn 5291: table.LC_nested {
1.803 bisitz 5292: border: none;
1.589 raeburn 5293: border-collapse: collapse;
1.803 bisitz 5294: border-spacing: 0;
1.507 raeburn 5295: width: 100%;
5296: }
1.795 www 5297:
1.930 faziophi 5298: .ui-accordion,
5299: .ui-accordion table.LC_data_table,
5300: .ui-accordion table.LC_nested_outer{
5301: border: 0px;
5302: border-spacing: 0px;
5303: margin: 3px;
5304: }
5305:
1.911 bisitz 5306: table.LC_data_table tr th,
5307: table.LC_calendar tr th,
1.879 raeburn 5308: table.LC_prior_tries tr th,
5309: table.LC_innerpickbox tr th {
1.349 albertel 5310: font-weight: bold;
5311: background-color: $data_table_head;
1.801 tempelho 5312: color:$fontmenu;
1.701 harmsja 5313: font-size:90%;
1.347 albertel 5314: }
1.795 www 5315:
1.879 raeburn 5316: table.LC_innerpickbox tr th,
5317: table.LC_innerpickbox tr td {
5318: vertical-align: top;
5319: }
5320:
1.711 raeburn 5321: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5322: background-color: #CCCCCC;
1.711 raeburn 5323: font-weight: bold;
5324: text-align: left;
5325: }
1.795 www 5326:
1.912 bisitz 5327: table.LC_data_table tr.LC_odd_row > td {
5328: background-color: $data_table_light;
5329: padding: 2px;
5330: vertical-align: top;
5331: }
5332:
1.809 bisitz 5333: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5334: background-color: $data_table_light;
1.912 bisitz 5335: vertical-align: top;
5336: }
5337:
5338: table.LC_data_table tr.LC_even_row > td {
5339: background-color: $data_table_dark;
1.425 albertel 5340: padding: 2px;
1.900 bisitz 5341: vertical-align: top;
1.347 albertel 5342: }
1.795 www 5343:
1.809 bisitz 5344: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5345: background-color: $data_table_dark;
1.900 bisitz 5346: vertical-align: top;
1.347 albertel 5347: }
1.795 www 5348:
1.425 albertel 5349: table.LC_data_table tr.LC_data_table_highlight td {
5350: background-color: $data_table_darker;
5351: }
1.795 www 5352:
1.639 raeburn 5353: table.LC_data_table tr td.LC_leftcol_header {
5354: background-color: $data_table_head;
5355: font-weight: bold;
5356: }
1.795 www 5357:
1.451 albertel 5358: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5359: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5360: font-weight: bold;
5361: font-style: italic;
5362: text-align: center;
5363: padding: 8px;
1.347 albertel 5364: }
1.795 www 5365:
1.940 bisitz 5366: table.LC_data_table tr.LC_empty_row td {
5367: background-color: $sidebg;
5368: }
5369:
5370: table.LC_nested tr.LC_empty_row td {
5371: background-color: #FFFFFF;
5372: }
5373:
1.890 droeschl 5374: table.LC_caption {
5375: }
5376:
1.507 raeburn 5377: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5378: padding: 4ex
5379: }
1.795 www 5380:
1.507 raeburn 5381: table.LC_nested_outer tr th {
5382: font-weight: bold;
1.801 tempelho 5383: color:$fontmenu;
1.507 raeburn 5384: background-color: $data_table_head;
1.701 harmsja 5385: font-size: small;
1.507 raeburn 5386: border-bottom: 1px solid #000000;
5387: }
1.795 www 5388:
1.507 raeburn 5389: table.LC_nested_outer tr td.LC_subheader {
5390: background-color: $data_table_head;
5391: font-weight: bold;
5392: font-size: small;
5393: border-bottom: 1px solid #000000;
5394: text-align: right;
1.451 albertel 5395: }
1.795 www 5396:
1.507 raeburn 5397: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5398: background-color: #CCCCCC;
1.451 albertel 5399: font-weight: bold;
5400: font-size: small;
1.507 raeburn 5401: text-align: center;
5402: }
1.795 www 5403:
1.589 raeburn 5404: table.LC_nested tr.LC_info_row td.LC_left_item,
5405: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5406: text-align: left;
1.451 albertel 5407: }
1.795 www 5408:
1.507 raeburn 5409: table.LC_nested td {
1.735 bisitz 5410: background-color: #FFFFFF;
1.451 albertel 5411: font-size: small;
1.507 raeburn 5412: }
1.795 www 5413:
1.507 raeburn 5414: table.LC_nested_outer tr th.LC_right_item,
5415: table.LC_nested tr.LC_info_row td.LC_right_item,
5416: table.LC_nested tr.LC_odd_row td.LC_right_item,
5417: table.LC_nested tr td.LC_right_item {
1.451 albertel 5418: text-align: right;
5419: }
5420:
1.930 faziophi 5421: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5422: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5423: text-align: right;
5424: width: 40%;
5425: padding-right:10px;
5426: vertical-align: top;
5427: padding: 5px;
5428: }
5429:
5430: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5431: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5432: text-align: left;
5433: width: 60%;
5434: padding: 2px 4px;
5435: }
5436:
1.507 raeburn 5437: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5438: background-color: #EEEEEE;
1.451 albertel 5439: }
5440:
1.473 raeburn 5441: table.LC_createuser {
5442: }
5443:
5444: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5445: font-size: small;
1.473 raeburn 5446: }
5447:
5448: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5449: background-color: #CCCCCC;
1.473 raeburn 5450: font-weight: bold;
5451: text-align: center;
5452: }
5453:
1.349 albertel 5454: table.LC_calendar {
5455: border: 1px solid #000000;
5456: border-collapse: collapse;
1.917 raeburn 5457: width: 98%;
1.349 albertel 5458: }
1.795 www 5459:
1.349 albertel 5460: table.LC_calendar_pickdate {
5461: font-size: xx-small;
5462: }
1.795 www 5463:
1.349 albertel 5464: table.LC_calendar tr td {
5465: border: 1px solid #000000;
5466: vertical-align: top;
1.917 raeburn 5467: width: 14%;
1.349 albertel 5468: }
1.795 www 5469:
1.349 albertel 5470: table.LC_calendar tr td.LC_calendar_day_empty {
5471: background-color: $data_table_dark;
5472: }
1.795 www 5473:
1.779 bisitz 5474: table.LC_calendar tr td.LC_calendar_day_current {
5475: background-color: $data_table_highlight;
1.777 tempelho 5476: }
1.795 www 5477:
1.938 bisitz 5478: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5479: background-color: $mail_new;
5480: }
1.795 www 5481:
1.938 bisitz 5482: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5483: background-color: $mail_new_hover;
5484: }
1.795 www 5485:
1.938 bisitz 5486: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5487: background-color: $mail_read;
5488: }
1.795 www 5489:
1.938 bisitz 5490: /*
5491: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5492: background-color: $mail_read_hover;
5493: }
1.938 bisitz 5494: */
1.795 www 5495:
1.938 bisitz 5496: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5497: background-color: $mail_replied;
5498: }
1.795 www 5499:
1.938 bisitz 5500: /*
5501: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5502: background-color: $mail_replied_hover;
5503: }
1.938 bisitz 5504: */
1.795 www 5505:
1.938 bisitz 5506: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5507: background-color: $mail_other;
5508: }
1.795 www 5509:
1.938 bisitz 5510: /*
5511: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5512: background-color: $mail_other_hover;
5513: }
1.938 bisitz 5514: */
1.494 raeburn 5515:
1.777 tempelho 5516: table.LC_data_table tr > td.LC_browser_file,
5517: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5518: background: #AAEE77;
1.389 albertel 5519: }
1.795 www 5520:
1.777 tempelho 5521: table.LC_data_table tr > td.LC_browser_file_locked,
5522: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5523: background: #FFAA99;
1.387 albertel 5524: }
1.795 www 5525:
1.777 tempelho 5526: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5527: background: #888888;
1.779 bisitz 5528: }
1.795 www 5529:
1.777 tempelho 5530: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5531: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5532: background: #F8F866;
1.777 tempelho 5533: }
1.795 www 5534:
1.696 bisitz 5535: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5536: background: #E0E8FF;
1.387 albertel 5537: }
1.696 bisitz 5538:
1.707 bisitz 5539: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5540: /* background: #77FF77; */
1.707 bisitz 5541: }
1.795 www 5542:
1.707 bisitz 5543: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5544: border-right: 8px solid #FFFF77;
1.707 bisitz 5545: }
1.795 www 5546:
1.707 bisitz 5547: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5548: border-right: 8px solid #FFAA77;
1.707 bisitz 5549: }
1.795 www 5550:
1.707 bisitz 5551: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5552: border-right: 8px solid #FF7777;
1.707 bisitz 5553: }
1.795 www 5554:
1.707 bisitz 5555: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5556: border-right: 8px solid #AAFF77;
1.707 bisitz 5557: }
1.795 www 5558:
1.707 bisitz 5559: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5560: border-right: 8px solid #11CC55;
1.707 bisitz 5561: }
5562:
1.388 albertel 5563: span.LC_current_location {
1.701 harmsja 5564: font-size:larger;
1.388 albertel 5565: background: $pgbg;
5566: }
1.387 albertel 5567:
1.395 albertel 5568: span.LC_parm_menu_item {
5569: font-size: larger;
5570: }
1.795 www 5571:
1.395 albertel 5572: span.LC_parm_scope_all {
5573: color: red;
5574: }
1.795 www 5575:
1.395 albertel 5576: span.LC_parm_scope_folder {
5577: color: green;
5578: }
1.795 www 5579:
1.395 albertel 5580: span.LC_parm_scope_resource {
5581: color: orange;
5582: }
1.795 www 5583:
1.395 albertel 5584: span.LC_parm_part {
5585: color: blue;
5586: }
1.795 www 5587:
1.911 bisitz 5588: span.LC_parm_folder,
5589: span.LC_parm_symb {
1.395 albertel 5590: font-size: x-small;
5591: font-family: $mono;
5592: color: #AAAAAA;
5593: }
5594:
1.948.2.8 raeburn 5595: ul.LC_parm_parmlist li {
5596: display: inline-block;
5597: padding: 0.3em 0.8em;
5598: vertical-align: top;
5599: width: 150px;
5600: border-top:1px solid $lg_border_color;
5601: }
5602:
1.795 www 5603: td.LC_parm_overview_level_menu,
5604: td.LC_parm_overview_map_menu,
5605: td.LC_parm_overview_parm_selectors,
5606: td.LC_parm_overview_restrictions {
1.396 albertel 5607: border: 1px solid black;
5608: border-collapse: collapse;
5609: }
1.795 www 5610:
1.396 albertel 5611: table.LC_parm_overview_restrictions td {
5612: border-width: 1px 4px 1px 4px;
5613: border-style: solid;
5614: border-color: $pgbg;
5615: text-align: center;
5616: }
1.795 www 5617:
1.396 albertel 5618: table.LC_parm_overview_restrictions th {
5619: background: $tabbg;
5620: border-width: 1px 4px 1px 4px;
5621: border-style: solid;
5622: border-color: $pgbg;
5623: }
1.795 www 5624:
1.398 albertel 5625: table#LC_helpmenu {
1.803 bisitz 5626: border: none;
1.398 albertel 5627: height: 55px;
1.803 bisitz 5628: border-spacing: 0;
1.398 albertel 5629: }
5630:
5631: table#LC_helpmenu fieldset legend {
5632: font-size: larger;
5633: }
1.795 www 5634:
1.397 albertel 5635: table#LC_helpmenu_links {
5636: width: 100%;
5637: border: 1px solid black;
5638: background: $pgbg;
1.803 bisitz 5639: padding: 0;
1.397 albertel 5640: border-spacing: 1px;
5641: }
1.795 www 5642:
1.397 albertel 5643: table#LC_helpmenu_links tr td {
5644: padding: 1px;
5645: background: $tabbg;
1.399 albertel 5646: text-align: center;
5647: font-weight: bold;
1.397 albertel 5648: }
1.396 albertel 5649:
1.795 www 5650: table#LC_helpmenu_links a:link,
5651: table#LC_helpmenu_links a:visited,
1.397 albertel 5652: table#LC_helpmenu_links a:active {
5653: text-decoration: none;
5654: color: $font;
5655: }
1.795 www 5656:
1.397 albertel 5657: table#LC_helpmenu_links a:hover {
5658: text-decoration: underline;
5659: color: $vlink;
5660: }
1.396 albertel 5661:
1.417 albertel 5662: .LC_chrt_popup_exists {
5663: border: 1px solid #339933;
5664: margin: -1px;
5665: }
1.795 www 5666:
1.417 albertel 5667: .LC_chrt_popup_up {
5668: border: 1px solid yellow;
5669: margin: -1px;
5670: }
1.795 www 5671:
1.417 albertel 5672: .LC_chrt_popup {
5673: border: 1px solid #8888FF;
5674: background: #CCCCFF;
5675: }
1.795 www 5676:
1.421 albertel 5677: table.LC_pick_box {
5678: border-collapse: separate;
5679: background: white;
5680: border: 1px solid black;
5681: border-spacing: 1px;
5682: }
1.795 www 5683:
1.421 albertel 5684: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5685: background: $sidebg;
1.421 albertel 5686: font-weight: bold;
1.900 bisitz 5687: text-align: left;
1.740 bisitz 5688: vertical-align: top;
1.421 albertel 5689: width: 184px;
5690: padding: 8px;
5691: }
1.795 www 5692:
1.579 raeburn 5693: table.LC_pick_box td.LC_pick_box_value {
5694: text-align: left;
5695: padding: 8px;
5696: }
1.795 www 5697:
1.579 raeburn 5698: table.LC_pick_box td.LC_pick_box_select {
5699: text-align: left;
5700: padding: 8px;
5701: }
1.795 www 5702:
1.424 albertel 5703: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5704: padding: 0;
1.421 albertel 5705: height: 1px;
5706: background: black;
5707: }
1.795 www 5708:
1.421 albertel 5709: table.LC_pick_box td.LC_pick_box_submit {
5710: text-align: right;
5711: }
1.795 www 5712:
1.579 raeburn 5713: table.LC_pick_box td.LC_evenrow_value {
5714: text-align: left;
5715: padding: 8px;
5716: background-color: $data_table_light;
5717: }
1.795 www 5718:
1.579 raeburn 5719: table.LC_pick_box td.LC_oddrow_value {
5720: text-align: left;
5721: padding: 8px;
5722: background-color: $data_table_light;
5723: }
1.795 www 5724:
1.579 raeburn 5725: span.LC_helpform_receipt_cat {
5726: font-weight: bold;
5727: }
1.795 www 5728:
1.424 albertel 5729: table.LC_group_priv_box {
5730: background: white;
5731: border: 1px solid black;
5732: border-spacing: 1px;
5733: }
1.795 www 5734:
1.424 albertel 5735: table.LC_group_priv_box td.LC_pick_box_title {
5736: background: $tabbg;
5737: font-weight: bold;
5738: text-align: right;
5739: width: 184px;
5740: }
1.795 www 5741:
1.424 albertel 5742: table.LC_group_priv_box td.LC_groups_fixed {
5743: background: $data_table_light;
5744: text-align: center;
5745: }
1.795 www 5746:
1.424 albertel 5747: table.LC_group_priv_box td.LC_groups_optional {
5748: background: $data_table_dark;
5749: text-align: center;
5750: }
1.795 www 5751:
1.424 albertel 5752: table.LC_group_priv_box td.LC_groups_functionality {
5753: background: $data_table_darker;
5754: text-align: center;
5755: font-weight: bold;
5756: }
1.795 www 5757:
1.424 albertel 5758: table.LC_group_priv td {
5759: text-align: left;
1.803 bisitz 5760: padding: 0;
1.424 albertel 5761: }
5762:
1.421 albertel 5763: table.LC_notify_front_page {
5764: background: white;
5765: border: 1px solid black;
5766: padding: 8px;
5767: }
1.795 www 5768:
1.421 albertel 5769: table.LC_notify_front_page td {
5770: padding: 8px;
5771: }
1.795 www 5772:
1.424 albertel 5773: .LC_navbuttons {
5774: margin: 2ex 0ex 2ex 0ex;
5775: }
1.795 www 5776:
1.423 albertel 5777: .LC_topic_bar {
5778: font-weight: bold;
5779: background: $tabbg;
1.918 wenzelju 5780: margin: 1em 0em 1em 2em;
1.805 bisitz 5781: padding: 3px;
1.918 wenzelju 5782: font-size: 1.2em;
1.423 albertel 5783: }
1.795 www 5784:
1.423 albertel 5785: .LC_topic_bar span {
1.918 wenzelju 5786: left: 0.5em;
5787: position: absolute;
1.423 albertel 5788: vertical-align: middle;
1.918 wenzelju 5789: font-size: 1.2em;
1.423 albertel 5790: }
1.795 www 5791:
1.423 albertel 5792: table.LC_course_group_status {
5793: margin: 20px;
5794: }
1.795 www 5795:
1.423 albertel 5796: table.LC_status_selector td {
5797: vertical-align: top;
5798: text-align: center;
1.424 albertel 5799: padding: 4px;
5800: }
1.795 www 5801:
1.599 albertel 5802: div.LC_feedback_link {
1.616 albertel 5803: clear: both;
1.829 kalberla 5804: background: $sidebg;
1.779 bisitz 5805: width: 100%;
1.829 kalberla 5806: padding-bottom: 10px;
5807: border: 1px $tabbg solid;
1.833 kalberla 5808: height: 22px;
5809: line-height: 22px;
5810: padding-top: 5px;
5811: }
5812:
5813: div.LC_feedback_link img {
5814: height: 22px;
1.867 kalberla 5815: vertical-align:middle;
1.829 kalberla 5816: }
5817:
1.911 bisitz 5818: div.LC_feedback_link a {
1.829 kalberla 5819: text-decoration: none;
1.489 raeburn 5820: }
1.795 www 5821:
1.867 kalberla 5822: div.LC_comblock {
1.911 bisitz 5823: display:inline;
1.867 kalberla 5824: color:$font;
5825: font-size:90%;
5826: }
5827:
5828: div.LC_feedback_link div.LC_comblock {
5829: padding-left:5px;
5830: }
5831:
5832: div.LC_feedback_link div.LC_comblock a {
5833: color:$font;
5834: }
5835:
1.489 raeburn 5836: span.LC_feedback_link {
1.858 bisitz 5837: /* background: $feedback_link_bg; */
1.599 albertel 5838: font-size: larger;
5839: }
1.795 www 5840:
1.599 albertel 5841: span.LC_message_link {
1.858 bisitz 5842: /* background: $feedback_link_bg; */
1.599 albertel 5843: font-size: larger;
5844: position: absolute;
5845: right: 1em;
1.489 raeburn 5846: }
1.421 albertel 5847:
1.515 albertel 5848: table.LC_prior_tries {
1.524 albertel 5849: border: 1px solid #000000;
5850: border-collapse: separate;
5851: border-spacing: 1px;
1.515 albertel 5852: }
1.523 albertel 5853:
1.515 albertel 5854: table.LC_prior_tries td {
1.524 albertel 5855: padding: 2px;
1.515 albertel 5856: }
1.523 albertel 5857:
5858: .LC_answer_correct {
1.795 www 5859: background: lightgreen;
5860: color: darkgreen;
5861: padding: 6px;
1.523 albertel 5862: }
1.795 www 5863:
1.523 albertel 5864: .LC_answer_charged_try {
1.797 www 5865: background: #FFAAAA;
1.795 www 5866: color: darkred;
5867: padding: 6px;
1.523 albertel 5868: }
1.795 www 5869:
1.779 bisitz 5870: .LC_answer_not_charged_try,
1.523 albertel 5871: .LC_answer_no_grade,
5872: .LC_answer_late {
1.795 www 5873: background: lightyellow;
1.523 albertel 5874: color: black;
1.795 www 5875: padding: 6px;
1.523 albertel 5876: }
1.795 www 5877:
1.523 albertel 5878: .LC_answer_previous {
1.795 www 5879: background: lightblue;
5880: color: darkblue;
5881: padding: 6px;
1.523 albertel 5882: }
1.795 www 5883:
1.779 bisitz 5884: .LC_answer_no_message {
1.777 tempelho 5885: background: #FFFFFF;
5886: color: black;
1.795 www 5887: padding: 6px;
1.779 bisitz 5888: }
1.795 www 5889:
1.779 bisitz 5890: .LC_answer_unknown {
5891: background: orange;
5892: color: black;
1.795 www 5893: padding: 6px;
1.777 tempelho 5894: }
1.795 www 5895:
1.529 albertel 5896: span.LC_prior_numerical,
5897: span.LC_prior_string,
5898: span.LC_prior_custom,
5899: span.LC_prior_reaction,
5900: span.LC_prior_math {
1.925 bisitz 5901: font-family: $mono;
1.523 albertel 5902: white-space: pre;
5903: }
5904:
1.525 albertel 5905: span.LC_prior_string {
1.925 bisitz 5906: font-family: $mono;
1.525 albertel 5907: white-space: pre;
5908: }
5909:
1.523 albertel 5910: table.LC_prior_option {
5911: width: 100%;
5912: border-collapse: collapse;
5913: }
1.795 www 5914:
1.911 bisitz 5915: table.LC_prior_rank,
1.795 www 5916: table.LC_prior_match {
1.528 albertel 5917: border-collapse: collapse;
5918: }
1.795 www 5919:
1.528 albertel 5920: table.LC_prior_option tr td,
5921: table.LC_prior_rank tr td,
5922: table.LC_prior_match tr td {
1.524 albertel 5923: border: 1px solid #000000;
1.515 albertel 5924: }
5925:
1.855 bisitz 5926: .LC_nobreak {
1.544 albertel 5927: white-space: nowrap;
1.519 raeburn 5928: }
5929:
1.576 raeburn 5930: span.LC_cusr_emph {
5931: font-style: italic;
5932: }
5933:
1.633 raeburn 5934: span.LC_cusr_subheading {
5935: font-weight: normal;
5936: font-size: 85%;
5937: }
5938:
1.861 bisitz 5939: div.LC_docs_entry_move {
1.859 bisitz 5940: border: 1px solid #BBBBBB;
1.545 albertel 5941: background: #DDDDDD;
1.861 bisitz 5942: width: 22px;
1.859 bisitz 5943: padding: 1px;
5944: margin: 0;
1.545 albertel 5945: }
5946:
1.861 bisitz 5947: table.LC_data_table tr > td.LC_docs_entry_commands,
5948: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5949: background: #DDDDDD;
5950: font-size: x-small;
5951: }
1.795 www 5952:
1.861 bisitz 5953: .LC_docs_entry_parameter {
5954: white-space: nowrap;
5955: }
5956:
1.544 albertel 5957: .LC_docs_copy {
1.545 albertel 5958: color: #000099;
1.544 albertel 5959: }
1.795 www 5960:
1.544 albertel 5961: .LC_docs_cut {
1.545 albertel 5962: color: #550044;
1.544 albertel 5963: }
1.795 www 5964:
1.544 albertel 5965: .LC_docs_rename {
1.545 albertel 5966: color: #009900;
1.544 albertel 5967: }
1.795 www 5968:
1.544 albertel 5969: .LC_docs_remove {
1.545 albertel 5970: color: #990000;
5971: }
5972:
1.547 albertel 5973: .LC_docs_reinit_warn,
5974: .LC_docs_ext_edit {
5975: font-size: x-small;
5976: }
5977:
1.545 albertel 5978: table.LC_docs_adddocs td,
5979: table.LC_docs_adddocs th {
5980: border: 1px solid #BBBBBB;
5981: padding: 4px;
5982: background: #DDDDDD;
1.543 albertel 5983: }
5984:
1.584 albertel 5985: table.LC_sty_begin {
5986: background: #BBFFBB;
5987: }
1.795 www 5988:
1.584 albertel 5989: table.LC_sty_end {
5990: background: #FFBBBB;
5991: }
5992:
1.589 raeburn 5993: table.LC_double_column {
1.803 bisitz 5994: border-width: 0;
1.589 raeburn 5995: border-collapse: collapse;
5996: width: 100%;
5997: padding: 2px;
5998: }
5999:
6000: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6001: top: 2px;
1.589 raeburn 6002: left: 2px;
6003: width: 47%;
6004: vertical-align: top;
6005: }
6006:
6007: table.LC_double_column tr td.LC_right_col {
6008: top: 2px;
1.779 bisitz 6009: right: 2px;
1.589 raeburn 6010: width: 47%;
6011: vertical-align: top;
6012: }
6013:
1.591 raeburn 6014: div.LC_left_float {
6015: float: left;
6016: padding-right: 5%;
1.597 albertel 6017: padding-bottom: 4px;
1.591 raeburn 6018: }
6019:
6020: div.LC_clear_float_header {
1.597 albertel 6021: padding-bottom: 2px;
1.591 raeburn 6022: }
6023:
6024: div.LC_clear_float_footer {
1.597 albertel 6025: padding-top: 10px;
1.591 raeburn 6026: clear: both;
6027: }
6028:
1.597 albertel 6029: div.LC_grade_show_user {
1.941 bisitz 6030: /* border-left: 5px solid $sidebg; */
6031: border-top: 5px solid #000000;
6032: margin: 50px 0 0 0;
1.936 bisitz 6033: padding: 15px 0 5px 10px;
1.597 albertel 6034: }
1.795 www 6035:
1.936 bisitz 6036: div.LC_grade_show_user_odd_row {
1.941 bisitz 6037: /* border-left: 5px solid #000000; */
6038: }
6039:
6040: div.LC_grade_show_user div.LC_Box {
6041: margin-right: 50px;
1.597 albertel 6042: }
6043:
6044: div.LC_grade_submissions,
6045: div.LC_grade_message_center,
1.936 bisitz 6046: div.LC_grade_info_links {
1.597 albertel 6047: margin: 5px;
6048: width: 99%;
6049: background: #FFFFFF;
6050: }
1.795 www 6051:
1.597 albertel 6052: div.LC_grade_submissions_header,
1.936 bisitz 6053: div.LC_grade_message_center_header {
1.705 tempelho 6054: font-weight: bold;
6055: font-size: large;
1.597 albertel 6056: }
1.795 www 6057:
1.597 albertel 6058: div.LC_grade_submissions_body,
1.936 bisitz 6059: div.LC_grade_message_center_body {
1.597 albertel 6060: border: 1px solid black;
6061: width: 99%;
6062: background: #FFFFFF;
6063: }
1.795 www 6064:
1.613 albertel 6065: table.LC_scantron_action {
6066: width: 100%;
6067: }
1.795 www 6068:
1.613 albertel 6069: table.LC_scantron_action tr th {
1.698 harmsja 6070: font-weight:bold;
6071: font-style:normal;
1.613 albertel 6072: }
1.795 www 6073:
1.779 bisitz 6074: .LC_edit_problem_header,
1.614 albertel 6075: div.LC_edit_problem_footer {
1.705 tempelho 6076: font-weight: normal;
6077: font-size: medium;
1.602 albertel 6078: margin: 2px;
1.600 albertel 6079: }
1.795 www 6080:
1.600 albertel 6081: div.LC_edit_problem_header,
1.602 albertel 6082: div.LC_edit_problem_header div,
1.614 albertel 6083: div.LC_edit_problem_footer,
6084: div.LC_edit_problem_footer div,
1.602 albertel 6085: div.LC_edit_problem_editxml_header,
6086: div.LC_edit_problem_editxml_header div {
1.600 albertel 6087: margin-top: 5px;
6088: }
1.795 www 6089:
1.600 albertel 6090: div.LC_edit_problem_header_title {
1.705 tempelho 6091: font-weight: bold;
6092: font-size: larger;
1.602 albertel 6093: background: $tabbg;
6094: padding: 3px;
6095: }
1.795 www 6096:
1.602 albertel 6097: table.LC_edit_problem_header_title {
6098: width: 100%;
1.600 albertel 6099: background: $tabbg;
1.602 albertel 6100: }
6101:
6102: div.LC_edit_problem_discards {
6103: float: left;
6104: padding-bottom: 5px;
6105: }
1.795 www 6106:
1.602 albertel 6107: div.LC_edit_problem_saves {
6108: float: right;
6109: padding-bottom: 5px;
1.600 albertel 6110: }
1.795 www 6111:
1.911 bisitz 6112: img.stift {
1.803 bisitz 6113: border-width: 0;
6114: vertical-align: middle;
1.677 riegler 6115: }
1.680 riegler 6116:
1.923 bisitz 6117: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6118: vertical-align: top;
1.777 tempelho 6119: }
1.795 www 6120:
1.716 raeburn 6121: div.LC_createcourse {
1.911 bisitz 6122: margin: 10px 10px 10px 10px;
1.716 raeburn 6123: }
6124:
1.917 raeburn 6125: .LC_dccid {
6126: margin: 0.2em 0 0 0;
6127: padding: 0;
6128: font-size: 90%;
6129: display:none;
6130: }
6131:
1.698 harmsja 6132: a:hover,
1.897 wenzelju 6133: ol.LC_primary_menu a:hover,
1.721 harmsja 6134: ol#LC_MenuBreadcrumbs a:hover,
6135: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6136: ul#LC_secondary_menu a:hover,
1.721 harmsja 6137: .LC_FormSectionClearButton input:hover
1.795 www 6138: ul.LC_TabContent li:hover a {
1.948.2.1 raeburn 6139: color:$button_hover;
1.911 bisitz 6140: text-decoration:none;
1.693 droeschl 6141: }
6142:
1.779 bisitz 6143: h1 {
1.911 bisitz 6144: padding: 0;
6145: line-height:130%;
1.693 droeschl 6146: }
1.698 harmsja 6147:
1.911 bisitz 6148: h2,
6149: h3,
6150: h4,
6151: h5,
6152: h6 {
6153: margin: 5px 0 5px 0;
6154: padding: 0;
6155: line-height:130%;
1.693 droeschl 6156: }
1.795 www 6157:
6158: .LC_hcell {
1.911 bisitz 6159: padding:3px 15px 3px 15px;
6160: margin: 0;
6161: background-color:$tabbg;
6162: color:$fontmenu;
6163: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6164: }
1.795 www 6165:
1.840 bisitz 6166: .LC_Box > .LC_hcell {
1.911 bisitz 6167: margin: 0 -10px 10px -10px;
1.835 bisitz 6168: }
6169:
1.721 harmsja 6170: .LC_noBorder {
1.911 bisitz 6171: border: 0;
1.698 harmsja 6172: }
1.693 droeschl 6173:
1.721 harmsja 6174: .LC_FormSectionClearButton input {
1.911 bisitz 6175: background-color:transparent;
6176: border: none;
6177: cursor:pointer;
6178: text-decoration:underline;
1.693 droeschl 6179: }
1.763 bisitz 6180:
6181: .LC_help_open_topic {
1.911 bisitz 6182: color: #FFFFFF;
6183: background-color: #EEEEFF;
6184: margin: 1px;
6185: padding: 4px;
6186: border: 1px solid #000033;
6187: white-space: nowrap;
6188: /* vertical-align: middle; */
1.759 neumanie 6189: }
1.693 droeschl 6190:
1.911 bisitz 6191: dl,
6192: ul,
6193: div,
6194: fieldset {
6195: margin: 10px 10px 10px 0;
6196: /* overflow: hidden; */
1.693 droeschl 6197: }
1.795 www 6198:
1.838 bisitz 6199: fieldset > legend {
1.911 bisitz 6200: font-weight: bold;
6201: padding: 0 5px 0 5px;
1.838 bisitz 6202: }
6203:
1.813 bisitz 6204: #LC_nav_bar {
1.911 bisitz 6205: float: left;
1.948.2.24 raeburn 6206: background-color: $pgbg_or_bgcolor;
1.948.2.6 raeburn 6207: margin: 0 0 2px 0;
1.807 droeschl 6208: }
6209:
1.916 droeschl 6210: #LC_realm {
6211: margin: 0.2em 0 0 0;
6212: padding: 0;
6213: font-weight: bold;
6214: text-align: center;
1.948.2.24 raeburn 6215: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6216: }
6217:
1.911 bisitz 6218: #LC_nav_bar em {
6219: font-weight: bold;
6220: font-style: normal;
1.807 droeschl 6221: }
6222:
1.948.2.6 raeburn 6223: /* Preliminary fix to hide nav_bar inside bookmarks window */
6224: #LC_bookmarks #LC_nav_bar {
6225: display:none;
6226: }
6227:
1.897 wenzelju 6228: ol.LC_primary_menu {
1.911 bisitz 6229: float: right;
1.934 droeschl 6230: margin: 0;
1.948.2.24 raeburn 6231: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6232: }
6233:
1.948.2.26 raeburn 6234: ol.LC_primary_menu a.LC_new_message {
1.929 wenzelju 6235: font-weight:bold;
6236: color: darkred;
6237: }
6238:
1.852 droeschl 6239: ol#LC_PathBreadcrumbs {
1.911 bisitz 6240: margin: 0;
1.693 droeschl 6241: }
6242:
1.897 wenzelju 6243: ol.LC_primary_menu li {
1.911 bisitz 6244: display: inline;
6245: padding: 5px 5px 0 10px;
6246: vertical-align: top;
1.693 droeschl 6247: }
6248:
1.897 wenzelju 6249: ol.LC_primary_menu li img {
1.911 bisitz 6250: vertical-align: bottom;
1.934 droeschl 6251: height: 1.1em;
1.693 droeschl 6252: }
6253:
1.897 wenzelju 6254: ol.LC_primary_menu a {
1.911 bisitz 6255: color: RGB(80, 80, 80);
6256: text-decoration: none;
1.693 droeschl 6257: }
1.795 www 6258:
1.948.2.7 raeburn 6259: ol.LC_docs_parameters {
6260: margin-left: 0;
6261: padding: 0;
6262: list-style: none;
6263: }
6264:
6265: ol.LC_docs_parameters li {
6266: margin: 0;
6267: padding-right: 20px;
6268: display: inline;
6269: }
6270:
6271: ol.LC_docs_parameters li:before {
6272: content: "\\002022 \\0020";
6273: }
6274:
6275: li.LC_docs_parameters_title {
6276: font-weight: bold;
6277: }
6278:
6279: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6280: content: "";
6281: }
6282:
1.897 wenzelju 6283: ul#LC_secondary_menu {
1.911 bisitz 6284: clear: both;
6285: color: $fontmenu;
6286: background: $tabbg;
6287: list-style: none;
6288: padding: 0;
6289: margin: 0;
6290: width: 100%;
1.948.2.24 raeburn 6291: text-align: left;
1.808 droeschl 6292: }
6293:
1.897 wenzelju 6294: ul#LC_secondary_menu li {
1.911 bisitz 6295: font-weight: bold;
6296: line-height: 1.8em;
6297: padding: 0 0.8em;
6298: border-right: 1px solid black;
6299: display: inline;
6300: vertical-align: middle;
1.807 droeschl 6301: }
6302:
1.847 tempelho 6303: ul.LC_TabContent {
1.911 bisitz 6304: display:block;
6305: background: $sidebg;
6306: border-bottom: solid 1px $lg_border_color;
6307: list-style:none;
6308: margin: 0 -10px;
6309: padding: 0;
1.693 droeschl 6310: }
6311:
1.795 www 6312: ul.LC_TabContent li,
6313: ul.LC_TabContentBigger li {
1.911 bisitz 6314: float:left;
1.741 harmsja 6315: }
1.795 www 6316:
1.897 wenzelju 6317: ul#LC_secondary_menu li a {
1.911 bisitz 6318: color: $fontmenu;
6319: text-decoration: none;
1.693 droeschl 6320: }
1.795 www 6321:
1.721 harmsja 6322: ul.LC_TabContent {
1.948.2.1 raeburn 6323: min-height:20px;
1.721 harmsja 6324: }
1.795 www 6325:
6326: ul.LC_TabContent li {
1.911 bisitz 6327: vertical-align:middle;
1.948.2.3 raeburn 6328: padding: 0 16px 0 10px;
1.911 bisitz 6329: background-color:$tabbg;
6330: border-bottom:solid 1px $lg_border_color;
1.948.2.1 raeburn 6331: border-right: solid 1px $font;
1.721 harmsja 6332: }
1.795 www 6333:
1.847 tempelho 6334: ul.LC_TabContent .right {
1.911 bisitz 6335: float:right;
1.847 tempelho 6336: }
6337:
1.911 bisitz 6338: ul.LC_TabContent li a,
6339: ul.LC_TabContent li {
6340: color:rgb(47,47,47);
6341: text-decoration:none;
6342: font-size:95%;
6343: font-weight:bold;
1.948.2.1 raeburn 6344: min-height:20px;
6345: }
6346:
1.948.2.3 raeburn 6347: ul.LC_TabContent li a:hover,
6348: ul.LC_TabContent li a:focus {
1.948.2.1 raeburn 6349: color: $button_hover;
1.948.2.3 raeburn 6350: background:none;
6351: outline:none;
1.948.2.1 raeburn 6352: }
6353:
6354: ul.LC_TabContent li:hover {
6355: color: $button_hover;
6356: cursor:pointer;
1.721 harmsja 6357: }
1.795 www 6358:
1.911 bisitz 6359: ul.LC_TabContent li.active {
1.948.2.1 raeburn 6360: color: $font;
1.911 bisitz 6361: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.948.2.1 raeburn 6362: border-bottom:solid 1px #FFFFFF;
6363: cursor: default;
1.744 ehlerst 6364: }
1.795 www 6365:
1.948.2.3 raeburn 6366: ul.LC_TabContent li.active a {
6367: color:$font;
6368: background:#FFFFFF;
6369: outline: none;
6370: }
1.870 tempelho 6371: #maincoursedoc {
1.911 bisitz 6372: clear:both;
1.870 tempelho 6373: }
6374:
6375: ul.LC_TabContentBigger {
1.911 bisitz 6376: display:block;
6377: list-style:none;
6378: padding: 0;
1.870 tempelho 6379: }
6380:
1.795 www 6381: ul.LC_TabContentBigger li {
1.911 bisitz 6382: vertical-align:bottom;
6383: height: 30px;
6384: font-size:110%;
6385: font-weight:bold;
6386: color: #737373;
1.841 tempelho 6387: }
6388:
1.948.2.3 raeburn 6389: ul.LC_TabContentBigger li.active {
6390: position: relative;
6391: top: 1px;
6392: }
1.870 tempelho 6393:
6394: ul.LC_TabContentBigger li a {
1.911 bisitz 6395: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6396: height: 30px;
6397: line-height: 30px;
6398: text-align: center;
6399: display: block;
6400: text-decoration: none;
1.948.2.3 raeburn 6401: outline: none;
1.741 harmsja 6402: }
1.795 www 6403:
1.870 tempelho 6404: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6405: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6406: color:$font;
1.744 ehlerst 6407: }
1.795 www 6408:
1.870 tempelho 6409: ul.LC_TabContentBigger li b {
1.911 bisitz 6410: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6411: display: block;
6412: float: left;
6413: padding: 0 30px;
1.948.2.3 raeburn 6414: border-bottom: 1px solid $lg_border_color;
6415: }
6416:
6417: ul.LC_TabContentBigger li:hover b {
6418: color:$button_hover;
1.870 tempelho 6419: }
6420:
6421: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6422: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6423: color:$font;
1.948.2.3 raeburn 6424: border: 0;
6425: cursor:default;
1.741 harmsja 6426: }
1.693 droeschl 6427:
1.862 bisitz 6428: ul.LC_CourseBreadcrumbs {
6429: background: $sidebg;
6430: line-height: 32px;
6431: padding-left: 10px;
6432: margin: 0 0 10px 0;
6433: list-style-position: inside;
6434:
6435: }
6436:
1.911 bisitz 6437: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6438: ol#LC_PathBreadcrumbs {
1.911 bisitz 6439: padding-left: 10px;
6440: margin: 0;
1.933 droeschl 6441: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6442: }
6443:
1.911 bisitz 6444: ol#LC_MenuBreadcrumbs li,
6445: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6446: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6447: display: inline;
1.933 droeschl 6448: white-space: normal;
1.693 droeschl 6449: }
6450:
1.823 bisitz 6451: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6452: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6453: text-decoration: none;
6454: font-size:90%;
1.693 droeschl 6455: }
1.795 www 6456:
1.948.2.7 raeburn 6457: ol#LC_MenuBreadcrumbs h1 {
6458: display: inline;
6459: font-size: 90%;
6460: line-height: 2.5em;
6461: margin: 0;
6462: padding: 0;
6463: }
6464:
1.795 www 6465: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6466: text-decoration:none;
6467: font-size:100%;
6468: font-weight:bold;
1.693 droeschl 6469: }
1.795 www 6470:
1.840 bisitz 6471: .LC_Box {
1.911 bisitz 6472: border: solid 1px $lg_border_color;
6473: padding: 0 10px 10px 10px;
1.746 neumanie 6474: }
1.795 www 6475:
6476: .LC_AboutMe_Image {
1.911 bisitz 6477: float:left;
6478: margin-right:10px;
1.747 neumanie 6479: }
1.795 www 6480:
6481: .LC_Clear_AboutMe_Image {
1.911 bisitz 6482: clear:left;
1.747 neumanie 6483: }
1.795 www 6484:
1.721 harmsja 6485: dl.LC_ListStyleClean dt {
1.911 bisitz 6486: padding-right: 5px;
6487: display: table-header-group;
1.693 droeschl 6488: }
6489:
1.721 harmsja 6490: dl.LC_ListStyleClean dd {
1.911 bisitz 6491: display: table-row;
1.693 droeschl 6492: }
6493:
1.721 harmsja 6494: .LC_ListStyleClean,
6495: .LC_ListStyleSimple,
6496: .LC_ListStyleNormal,
1.795 www 6497: .LC_ListStyleSpecial {
1.911 bisitz 6498: /* display:block; */
6499: list-style-position: inside;
6500: list-style-type: none;
6501: overflow: hidden;
6502: padding: 0;
1.693 droeschl 6503: }
6504:
1.721 harmsja 6505: .LC_ListStyleSimple li,
6506: .LC_ListStyleSimple dd,
6507: .LC_ListStyleNormal li,
6508: .LC_ListStyleNormal dd,
6509: .LC_ListStyleSpecial li,
1.795 www 6510: .LC_ListStyleSpecial dd {
1.911 bisitz 6511: margin: 0;
6512: padding: 5px 5px 5px 10px;
6513: clear: both;
1.693 droeschl 6514: }
6515:
1.721 harmsja 6516: .LC_ListStyleClean li,
6517: .LC_ListStyleClean dd {
1.911 bisitz 6518: padding-top: 0;
6519: padding-bottom: 0;
1.693 droeschl 6520: }
6521:
1.721 harmsja 6522: .LC_ListStyleSimple dd,
1.795 www 6523: .LC_ListStyleSimple li {
1.911 bisitz 6524: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6525: }
6526:
1.721 harmsja 6527: .LC_ListStyleSpecial li,
6528: .LC_ListStyleSpecial dd {
1.911 bisitz 6529: list-style-type: none;
6530: background-color: RGB(220, 220, 220);
6531: margin-bottom: 4px;
1.693 droeschl 6532: }
6533:
1.721 harmsja 6534: table.LC_SimpleTable {
1.911 bisitz 6535: margin:5px;
6536: border:solid 1px $lg_border_color;
1.795 www 6537: }
1.693 droeschl 6538:
1.721 harmsja 6539: table.LC_SimpleTable tr {
1.911 bisitz 6540: padding: 0;
6541: border:solid 1px $lg_border_color;
1.693 droeschl 6542: }
1.795 www 6543:
6544: table.LC_SimpleTable thead {
1.911 bisitz 6545: background:rgb(220,220,220);
1.693 droeschl 6546: }
6547:
1.721 harmsja 6548: div.LC_columnSection {
1.911 bisitz 6549: display: block;
6550: clear: both;
6551: overflow: hidden;
6552: margin: 0;
1.693 droeschl 6553: }
6554:
1.721 harmsja 6555: div.LC_columnSection>* {
1.911 bisitz 6556: float: left;
6557: margin: 10px 20px 10px 0;
6558: overflow:hidden;
1.693 droeschl 6559: }
1.721 harmsja 6560:
1.795 www 6561: table em {
1.911 bisitz 6562: font-weight: bold;
6563: font-style: normal;
1.748 schulted 6564: }
1.795 www 6565:
1.779 bisitz 6566: table.LC_tableBrowseRes,
1.795 www 6567: table.LC_tableOfContent {
1.911 bisitz 6568: border:none;
6569: border-spacing: 1px;
6570: padding: 3px;
6571: background-color: #FFFFFF;
6572: font-size: 90%;
1.753 droeschl 6573: }
1.789 droeschl 6574:
1.911 bisitz 6575: table.LC_tableOfContent {
6576: border-collapse: collapse;
1.789 droeschl 6577: }
6578:
1.771 droeschl 6579: table.LC_tableBrowseRes a,
1.768 schulted 6580: table.LC_tableOfContent a {
1.911 bisitz 6581: background-color: transparent;
6582: text-decoration: none;
1.753 droeschl 6583: }
6584:
1.795 www 6585: table.LC_tableOfContent img {
1.911 bisitz 6586: border: none;
6587: height: 1.3em;
6588: vertical-align: text-bottom;
6589: margin-right: 0.3em;
1.753 droeschl 6590: }
1.757 schulted 6591:
1.795 www 6592: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6593: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6594: }
6595:
1.795 www 6596: a#LC_content_toolbar_launchnav {
1.911 bisitz 6597: background-image:url(/res/adm/pages/start-navigation.gif);
1.774 ehlerst 6598: }
6599:
1.795 www 6600: a#LC_content_toolbar_closenav {
1.911 bisitz 6601: background-image:url(/res/adm/pages/close-navigation.gif);
1.774 ehlerst 6602: }
6603:
1.795 www 6604: a#LC_content_toolbar_everything {
1.911 bisitz 6605: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6606: }
6607:
1.795 www 6608: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6609: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6610: }
6611:
1.795 www 6612: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6613: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6614: }
6615:
1.795 www 6616: a#LC_content_toolbar_changefolder {
1.911 bisitz 6617: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6618: }
6619:
1.795 www 6620: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6621: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6622: }
6623:
1.795 www 6624: ul#LC_toolbar li a:hover {
1.911 bisitz 6625: background-position: bottom center;
1.757 schulted 6626: }
6627:
1.795 www 6628: ul#LC_toolbar {
1.911 bisitz 6629: padding: 0;
6630: margin: 2px;
6631: list-style:none;
6632: position:relative;
6633: background-color:white;
1.757 schulted 6634: }
6635:
1.795 www 6636: ul#LC_toolbar li {
1.911 bisitz 6637: border:1px solid white;
6638: padding: 0;
6639: margin: 0;
6640: float: left;
6641: display:inline;
6642: vertical-align:middle;
6643: }
1.757 schulted 6644:
1.783 amueller 6645:
1.795 www 6646: a.LC_toolbarItem {
1.911 bisitz 6647: display:block;
6648: padding: 0;
6649: margin: 0;
6650: height: 32px;
6651: width: 32px;
6652: color:white;
6653: border: none;
6654: background-repeat:no-repeat;
6655: background-color:transparent;
1.757 schulted 6656: }
6657:
1.915 droeschl 6658: ul.LC_funclist {
6659: margin: 0;
6660: padding: 0.5em 1em 0.5em 0;
6661: }
6662:
1.933 droeschl 6663: ul.LC_funclist > li:first-child {
6664: font-weight:bold;
6665: margin-left:0.8em;
6666: }
6667:
1.915 droeschl 6668: ul.LC_funclist + ul.LC_funclist {
6669: /*
6670: left border as a seperator if we have more than
6671: one list
6672: */
6673: border-left: 1px solid $sidebg;
6674: /*
6675: this hides the left border behind the border of the
6676: outer box if element is wrapped to the next 'line'
6677: */
6678: margin-left: -1px;
6679: }
6680:
1.843 bisitz 6681: ul.LC_funclist li {
1.915 droeschl 6682: display: inline;
1.782 bisitz 6683: white-space: nowrap;
1.915 droeschl 6684: margin: 0 0 0 25px;
6685: line-height: 150%;
1.782 bisitz 6686: }
6687:
1.930 faziophi 6688: .ui-accordion .LC_advanced_toggle {
6689: float: right;
6690: font-size: 90%;
6691: padding: 0px 4px
6692: }
1.757 schulted 6693:
1.343 albertel 6694: END
6695: }
6696:
1.306 albertel 6697: =pod
6698:
6699: =item * &headtag()
6700:
6701: Returns a uniform footer for LON-CAPA web pages.
6702:
1.307 albertel 6703: Inputs: $title - optional title for the head
6704: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6705: $args - optional arguments
1.319 albertel 6706: force_register - if is true call registerurl so the remote is
6707: informed
1.415 albertel 6708: redirect -> array ref of
6709: 1- seconds before redirect occurs
6710: 2- url to redirect to
6711: 3- whether the side effect should occur
1.315 albertel 6712: (side effect of setting
6713: $env{'internal.head.redirect'} to the url
6714: redirected too)
1.352 albertel 6715: domain -> force to color decorate a page for a specific
6716: domain
6717: function -> force usage of a specific rolish color scheme
6718: bgcolor -> override the default page bgcolor
1.460 albertel 6719: no_auto_mt_title
6720: -> prevent &mt()ing the title arg
1.464 albertel 6721:
1.306 albertel 6722: =cut
6723:
6724: sub headtag {
1.313 albertel 6725: my ($title,$head_extra,$args) = @_;
1.306 albertel 6726:
1.363 albertel 6727: my $function = $args->{'function'} || &get_users_function();
6728: my $domain = $args->{'domain'} || &determinedomain();
6729: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6730: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6731: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6732: #time(),
1.418 albertel 6733: $env{'environment.color.timestamp'},
1.363 albertel 6734: $function,$domain,$bgcolor);
6735:
1.369 www 6736: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6737:
1.308 albertel 6738: my $result =
6739: '<head>'.
1.461 albertel 6740: &font_settings();
1.319 albertel 6741:
1.461 albertel 6742: if (!$args->{'frameset'}) {
6743: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6744: }
1.319 albertel 6745: if ($args->{'force_register'}) {
6746: $result .= &Apache::lonmenu::registerurl(1);
6747: }
1.436 albertel 6748: if (!$args->{'no_nav_bar'}
6749: && !$args->{'only_body'}
6750: && !$args->{'frameset'}) {
6751: $result .= &help_menu_js();
6752: }
1.319 albertel 6753:
1.314 albertel 6754: if (ref($args->{'redirect'})) {
1.414 albertel 6755: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6756: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6757: if (!$inhibit_continue) {
6758: $env{'internal.head.redirect'} = $url;
6759: }
1.313 albertel 6760: $result.=<<ADDMETA
6761: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6762: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6763: ADDMETA
6764: }
1.306 albertel 6765: if (!defined($title)) {
6766: $title = 'The LearningOnline Network with CAPA';
6767: }
1.460 albertel 6768: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6769: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6770: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6771: .$head_extra;
1.306 albertel 6772: return $result;
6773: }
6774:
6775: =pod
6776:
1.340 albertel 6777: =item * &font_settings()
6778:
6779: Returns neccessary <meta> to set the proper encoding
6780:
6781: Inputs: none
6782:
6783: =cut
6784:
6785: sub font_settings {
6786: my $headerstring='';
1.647 www 6787: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6788: $headerstring.=
6789: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6790: }
6791: return $headerstring;
6792: }
6793:
1.341 albertel 6794: =pod
6795:
6796: =item * &xml_begin()
6797:
6798: Returns the needed doctype and <html>
6799:
6800: Inputs: none
6801:
6802: =cut
6803:
6804: sub xml_begin {
6805: my $output='';
6806:
6807: if ($env{'browser.mathml'}) {
6808: $output='<?xml version="1.0"?>'
6809: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6810: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6811:
6812: # .'<!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">] >'
6813: .'<!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">'
6814: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6815: .'xmlns="http://www.w3.org/1999/xhtml">';
6816: } else {
1.849 bisitz 6817: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6818: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6819: }
6820: return $output;
6821: }
1.340 albertel 6822:
6823: =pod
6824:
1.306 albertel 6825: =item * &endheadtag()
6826:
6827: Returns a uniform </head> for LON-CAPA web pages.
6828:
6829: Inputs: none
6830:
6831: =cut
6832:
6833: sub endheadtag {
6834: return '</head>';
6835: }
6836:
6837: =pod
6838:
6839: =item * &head()
6840:
6841: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6842:
1.648 raeburn 6843: Inputs:
6844:
6845: =over 4
6846:
6847: $title - optional title for the page
6848:
6849: $head_extra - optional extra HTML to put inside the <head>
6850:
6851: =back
1.405 albertel 6852:
1.306 albertel 6853: =cut
6854:
6855: sub head {
1.325 albertel 6856: my ($title,$head_extra,$args) = @_;
6857: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6858: }
6859:
6860: =pod
6861:
6862: =item * &start_page()
6863:
6864: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6865:
1.648 raeburn 6866: Inputs:
6867:
6868: =over 4
6869:
6870: $title - optional title for the page
6871:
6872: $head_extra - optional extra HTML to incude inside the <head>
6873:
6874: $args - additional optional args supported are:
6875:
6876: =over 8
6877:
6878: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6879: arg on
1.814 bisitz 6880: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6881: add_entries -> additional attributes to add to the <body>
6882: domain -> force to color decorate a page for a
1.317 albertel 6883: specific domain
1.648 raeburn 6884: function -> force usage of a specific rolish color
1.317 albertel 6885: scheme
1.648 raeburn 6886: redirect -> see &headtag()
6887: bgcolor -> override the default page bg color
6888: js_ready -> return a string ready for being used in
1.317 albertel 6889: a javascript writeln
1.648 raeburn 6890: html_encode -> return a string ready for being used in
1.320 albertel 6891: a html attribute
1.648 raeburn 6892: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6893: $forcereg arg
1.648 raeburn 6894: frameset -> if true will start with a <frameset>
1.330 albertel 6895: rather than <body>
1.648 raeburn 6896: skip_phases -> hash ref of
1.338 albertel 6897: head -> skip the <html><head> generation
6898: body -> skip all <body> generation
1.648 raeburn 6899: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6900: 'Switch To Inline Menu' link
1.648 raeburn 6901: no_auto_mt_title -> prevent &mt()ing the title arg
6902: inherit_jsmath -> when creating popup window in a page,
6903: should it have jsmath forced on by the
6904: current page
1.867 kalberla 6905: bread_crumbs -> Array containing breadcrumbs
1.948.2.12 raeburn 6906: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6907:
1.648 raeburn 6908: =back
1.460 albertel 6909:
1.648 raeburn 6910: =back
1.562 albertel 6911:
1.306 albertel 6912: =cut
6913:
6914: sub start_page {
1.309 albertel 6915: my ($title,$head_extra,$args) = @_;
1.318 albertel 6916: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6917: my %head_args;
1.352 albertel 6918: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6919: 'bgcolor','frameset','no_nav_bar','only_body',
6920: 'no_auto_mt_title') {
1.319 albertel 6921: if (defined($args->{$arg})) {
1.324 raeburn 6922: $head_args{$arg} = $args->{$arg};
1.319 albertel 6923: }
1.313 albertel 6924: }
1.319 albertel 6925:
1.315 albertel 6926: $env{'internal.start_page'}++;
1.338 albertel 6927: my $result;
6928: if (! exists($args->{'skip_phases'}{'head'}) ) {
6929: $result.=
1.341 albertel 6930: &xml_begin().
1.338 albertel 6931: &headtag($title,$head_extra,\%head_args).&endheadtag();
6932: }
6933:
6934: if (! exists($args->{'skip_phases'}{'body'}) ) {
6935: if ($args->{'frameset'}) {
6936: my $attr_string = &make_attr_string($args->{'force_register'},
6937: $args->{'add_entries'});
6938: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6939: } else {
6940: $result .=
6941: &bodytag($title,
6942: $args->{'function'}, $args->{'add_entries'},
6943: $args->{'only_body'}, $args->{'domain'},
6944: $args->{'force_register'}, $args->{'no_nav_bar'},
6945: $args->{'bgcolor'}, $args->{'no_inline_link'},
6946: $args);
6947: }
1.330 albertel 6948: }
1.338 albertel 6949:
1.315 albertel 6950: if ($args->{'js_ready'}) {
1.713 kaisler 6951: $result = &js_ready($result);
1.315 albertel 6952: }
1.320 albertel 6953: if ($args->{'html_encode'}) {
1.713 kaisler 6954: $result = &html_encode($result);
6955: }
6956:
1.813 bisitz 6957: # Preparation for new and consistent functionlist at top of screen
6958: # if ($args->{'functionlist'}) {
6959: # $result .= &build_functionlist();
6960: #}
6961:
6962: # Don't add anything more if only_body wanted
6963: return $result if $args->{'only_body'};
6964:
1.920 raeburn 6965: #Breadcrumbs for Construction Space provided by &bodytag.
6966: if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
6967: return $result;
6968: }
6969:
1.813 bisitz 6970: #Breadcrumbs
1.758 kaisler 6971: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6972: &Apache::lonhtmlcommon::clear_breadcrumbs();
6973: #if any br links exists, add them to the breadcrumbs
6974: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6975: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6976: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6977: }
6978: }
6979:
6980: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6981: if(exists($args->{'bread_crumbs_component'})){
6982: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6983: }else{
6984: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6985: }
1.320 albertel 6986: }
1.315 albertel 6987: return $result;
1.306 albertel 6988: }
6989:
1.330 albertel 6990:
1.306 albertel 6991: =pod
6992:
6993: =item * &head()
6994:
6995: Returns a complete </body></html> section for LON-CAPA web pages.
6996:
1.315 albertel 6997: Inputs: $args - additional optional args supported are:
6998: js_ready -> return a string ready for being used in
6999: a javascript writeln
1.320 albertel 7000: html_encode -> return a string ready for being used in
7001: a html attribute
1.330 albertel 7002: frameset -> if true will start with a <frameset>
7003: rather than <body>
1.493 albertel 7004: dicsussion -> if true will get discussion from
7005: lonxml::xmlend
7006: (you can pass the target and parser arguments
7007: through optional 'target' and 'parser' args
7008: to this routine)
1.306 albertel 7009:
7010: =cut
7011:
7012: sub end_page {
1.315 albertel 7013: my ($args) = @_;
7014: $env{'internal.end_page'}++;
1.330 albertel 7015: my $result;
1.335 albertel 7016: if ($args->{'discussion'}) {
7017: my ($target,$parser);
7018: if (ref($args->{'discussion'})) {
7019: ($target,$parser) =($args->{'discussion'}{'target'},
7020: $args->{'discussion'}{'parser'});
7021: }
7022: $result .= &Apache::lonxml::xmlend($target,$parser);
7023: }
7024:
1.330 albertel 7025: if ($args->{'frameset'}) {
7026: $result .= '</frameset>';
7027: } else {
1.635 raeburn 7028: $result .= &endbodytag($args);
1.330 albertel 7029: }
7030: $result .= "\n</html>";
7031:
1.315 albertel 7032: if ($args->{'js_ready'}) {
1.317 albertel 7033: $result = &js_ready($result);
1.315 albertel 7034: }
1.335 albertel 7035:
1.320 albertel 7036: if ($args->{'html_encode'}) {
7037: $result = &html_encode($result);
7038: }
1.335 albertel 7039:
1.315 albertel 7040: return $result;
7041: }
7042:
1.320 albertel 7043: sub html_encode {
7044: my ($result) = @_;
7045:
1.322 albertel 7046: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7047:
7048: return $result;
7049: }
1.317 albertel 7050: sub js_ready {
7051: my ($result) = @_;
7052:
1.323 albertel 7053: $result =~ s/[\n\r]/ /xmsg;
7054: $result =~ s/\\/\\\\/xmsg;
7055: $result =~ s/'/\\'/xmsg;
1.372 albertel 7056: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7057:
7058: return $result;
7059: }
7060:
1.315 albertel 7061: sub validate_page {
7062: if ( exists($env{'internal.start_page'})
1.316 albertel 7063: && $env{'internal.start_page'} > 1) {
7064: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7065: $env{'internal.start_page'}.' '.
1.316 albertel 7066: $ENV{'request.filename'});
1.315 albertel 7067: }
7068: if ( exists($env{'internal.end_page'})
1.316 albertel 7069: && $env{'internal.end_page'} > 1) {
7070: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7071: $env{'internal.end_page'}.' '.
1.316 albertel 7072: $env{'request.filename'});
1.315 albertel 7073: }
7074: if ( exists($env{'internal.start_page'})
7075: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7076: &Apache::lonnet::logthis('start_page called without end_page '.
7077: $env{'request.filename'});
1.315 albertel 7078: }
7079: if ( ! exists($env{'internal.start_page'})
7080: && exists($env{'internal.end_page'})) {
1.316 albertel 7081: &Apache::lonnet::logthis('end_page called without start_page'.
7082: $env{'request.filename'});
1.315 albertel 7083: }
1.306 albertel 7084: }
1.315 albertel 7085:
1.318 albertel 7086: sub simple_error_page {
7087: my ($r,$title,$msg) = @_;
7088: my $page =
7089: &Apache::loncommon::start_page($title).
7090: &mt($msg).
7091: &Apache::loncommon::end_page();
7092: if (ref($r)) {
7093: $r->print($page);
1.327 albertel 7094: return;
1.318 albertel 7095: }
7096: return $page;
7097: }
1.347 albertel 7098:
7099: {
1.610 albertel 7100: my @row_count;
1.948.2.5 raeburn 7101:
7102: sub start_data_table_count {
7103: unshift(@row_count, 0);
7104: return;
7105: }
7106:
7107: sub end_data_table_count {
7108: shift(@row_count);
7109: return;
7110: }
7111:
1.347 albertel 7112: sub start_data_table {
1.422 albertel 7113: my ($add_class) = @_;
7114: my $css_class = (join(' ','LC_data_table',$add_class));
1.948.2.5 raeburn 7115: &start_data_table_count();
1.422 albertel 7116: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 7117: }
7118:
7119: sub end_data_table {
1.948.2.5 raeburn 7120: &end_data_table_count();
1.389 albertel 7121: return '</table>'."\n";;
1.347 albertel 7122: }
7123:
7124: sub start_data_table_row {
1.422 albertel 7125: my ($add_class) = @_;
1.610 albertel 7126: $row_count[0]++;
7127: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7128: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 7129: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 7130: }
1.471 banghart 7131:
7132: sub continue_data_table_row {
7133: my ($add_class) = @_;
1.610 albertel 7134: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7135: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 7136: return '<tr class="'.$css_class.'">'."\n";;
7137: }
1.347 albertel 7138:
7139: sub end_data_table_row {
1.389 albertel 7140: return '</tr>'."\n";;
1.347 albertel 7141: }
1.367 www 7142:
1.421 albertel 7143: sub start_data_table_empty_row {
1.707 bisitz 7144: # $row_count[0]++;
1.421 albertel 7145: return '<tr class="LC_empty_row" >'."\n";;
7146: }
7147:
7148: sub end_data_table_empty_row {
7149: return '</tr>'."\n";;
7150: }
7151:
1.367 www 7152: sub start_data_table_header_row {
1.389 albertel 7153: return '<tr class="LC_header_row">'."\n";;
1.367 www 7154: }
7155:
7156: sub end_data_table_header_row {
1.389 albertel 7157: return '</tr>'."\n";;
1.367 www 7158: }
1.890 droeschl 7159:
7160: sub data_table_caption {
7161: my $caption = shift;
7162: return "<caption class=\"LC_caption\">$caption</caption>";
7163: }
1.347 albertel 7164: }
7165:
1.548 albertel 7166: =pod
7167:
7168: =item * &inhibit_menu_check($arg)
7169:
7170: Checks for a inhibitmenu state and generates output to preserve it
7171:
7172: Inputs: $arg - can be any of
7173: - undef - in which case the return value is a string
7174: to add into arguments list of a uri
7175: - 'input' - in which case the return value is a HTML
7176: <form> <input> field of type hidden to
7177: preserve the value
7178: - a url - in which case the return value is the url with
7179: the neccesary cgi args added to preserve the
7180: inhibitmenu state
7181: - a ref to a url - no return value, but the string is
7182: updated to include the neccessary cgi
7183: args to preserve the inhibitmenu state
7184:
7185: =cut
7186:
7187: sub inhibit_menu_check {
7188: my ($arg) = @_;
7189: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7190: if ($arg eq 'input') {
7191: if ($env{'form.inhibitmenu'}) {
7192: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7193: } else {
7194: return
7195: }
7196: }
7197: if ($env{'form.inhibitmenu'}) {
7198: if (ref($arg)) {
7199: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7200: } elsif ($arg eq '') {
7201: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7202: } else {
7203: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7204: }
7205: }
7206: if (!ref($arg)) {
7207: return $arg;
7208: }
7209: }
7210:
1.251 albertel 7211: ###############################################
1.182 matthew 7212:
7213: =pod
7214:
1.549 albertel 7215: =back
7216:
7217: =head1 User Information Routines
7218:
7219: =over 4
7220:
1.405 albertel 7221: =item * &get_users_function()
1.182 matthew 7222:
7223: Used by &bodytag to determine the current users primary role.
7224: Returns either 'student','coordinator','admin', or 'author'.
7225:
7226: =cut
7227:
7228: ###############################################
7229: sub get_users_function {
1.815 tempelho 7230: my $function = 'norole';
1.818 tempelho 7231: if ($env{'request.role'}=~/^(st)/) {
7232: $function='student';
7233: }
1.907 raeburn 7234: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7235: $function='coordinator';
7236: }
1.258 albertel 7237: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7238: $function='admin';
7239: }
1.826 bisitz 7240: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7241: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7242: $function='author';
7243: }
7244: return $function;
1.54 www 7245: }
1.99 www 7246:
7247: ###############################################
7248:
1.233 raeburn 7249: =pod
7250:
1.821 raeburn 7251: =item * &show_course()
7252:
7253: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7254: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7255:
7256: Inputs:
7257: None
7258:
7259: Outputs:
7260: Scalar: 1 if 'Course' to be used, 0 otherwise.
7261:
7262: =cut
7263:
7264: ###############################################
7265: sub show_course {
7266: my $course = !$env{'user.adv'};
7267: if (!$env{'user.adv'}) {
7268: foreach my $env (keys(%env)) {
7269: next if ($env !~ m/^user\.priv\./);
7270: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7271: $course = 0;
7272: last;
7273: }
7274: }
7275: }
7276: return $course;
7277: }
7278:
7279: ###############################################
7280:
7281: =pod
7282:
1.542 raeburn 7283: =item * &check_user_status()
1.274 raeburn 7284:
7285: Determines current status of supplied role for a
7286: specific user. Roles can be active, previous or future.
7287:
7288: Inputs:
7289: user's domain, user's username, course's domain,
1.375 raeburn 7290: course's number, optional section ID.
1.274 raeburn 7291:
7292: Outputs:
7293: role status: active, previous or future.
7294:
7295: =cut
7296:
7297: sub check_user_status {
1.412 raeburn 7298: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.948.2.11 raeburn 7299: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7300: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7301: my @uroles = keys %userinfo;
7302: my $srchstr;
7303: my $active_chk = 'none';
1.412 raeburn 7304: my $now = time;
1.274 raeburn 7305: if (@uroles > 0) {
1.908 raeburn 7306: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7307: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7308: } else {
1.412 raeburn 7309: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7310: }
7311: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7312: my $role_end = 0;
7313: my $role_start = 0;
7314: $active_chk = 'active';
1.412 raeburn 7315: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7316: $role_end = $1;
7317: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7318: $role_start = $1;
1.274 raeburn 7319: }
7320: }
7321: if ($role_start > 0) {
1.412 raeburn 7322: if ($now < $role_start) {
1.274 raeburn 7323: $active_chk = 'future';
7324: }
7325: }
7326: if ($role_end > 0) {
1.412 raeburn 7327: if ($now > $role_end) {
1.274 raeburn 7328: $active_chk = 'previous';
7329: }
7330: }
7331: }
7332: }
7333: return $active_chk;
7334: }
7335:
7336: ###############################################
7337:
7338: =pod
7339:
1.405 albertel 7340: =item * &get_sections()
1.233 raeburn 7341:
7342: Determines all the sections for a course including
7343: sections with students and sections containing other roles.
1.419 raeburn 7344: Incoming parameters:
7345:
7346: 1. domain
7347: 2. course number
7348: 3. reference to array containing roles for which sections should
7349: be gathered (optional).
7350: 4. reference to array containing status types for which sections
7351: should be gathered (optional).
7352:
7353: If the third argument is undefined, sections are gathered for any role.
7354: If the fourth argument is undefined, sections are gathered for any status.
7355: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7356:
1.374 raeburn 7357: Returns section hash (keys are section IDs, values are
7358: number of users in each section), subject to the
1.419 raeburn 7359: optional roles filter, optional status filter
1.233 raeburn 7360:
7361: =cut
7362:
7363: ###############################################
7364: sub get_sections {
1.419 raeburn 7365: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7366: if (!defined($cdom) || !defined($cnum)) {
7367: my $cid = $env{'request.course.id'};
7368:
7369: return if (!defined($cid));
7370:
7371: $cdom = $env{'course.'.$cid.'.domain'};
7372: $cnum = $env{'course.'.$cid.'.num'};
7373: }
7374:
7375: my %sectioncount;
1.419 raeburn 7376: my $now = time;
1.240 albertel 7377:
1.366 albertel 7378: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7379: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7380: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7381: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7382: my $start_index = &Apache::loncoursedata::CL_START();
7383: my $end_index = &Apache::loncoursedata::CL_END();
7384: my $status;
1.366 albertel 7385: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7386: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7387: $data->[$status_index],
7388: $data->[$start_index],
7389: $data->[$end_index]);
7390: if ($stu_status eq 'Active') {
7391: $status = 'active';
7392: } elsif ($end < $now) {
7393: $status = 'previous';
7394: } elsif ($start > $now) {
7395: $status = 'future';
7396: }
7397: if ($section ne '-1' && $section !~ /^\s*$/) {
7398: if ((!defined($possible_status)) || (($status ne '') &&
7399: (grep/^\Q$status\E$/,@{$possible_status}))) {
7400: $sectioncount{$section}++;
7401: }
1.240 albertel 7402: }
7403: }
7404: }
7405: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7406: foreach my $user (sort(keys(%courseroles))) {
7407: if ($user !~ /^(\w{2})/) { next; }
7408: my ($role) = ($user =~ /^(\w{2})/);
7409: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7410: my ($section,$status);
1.240 albertel 7411: if ($role eq 'cr' &&
7412: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7413: $section=$1;
7414: }
7415: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7416: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7417: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7418: if ($end == -1 && $start == -1) {
7419: next; #deleted role
7420: }
7421: if (!defined($possible_status)) {
7422: $sectioncount{$section}++;
7423: } else {
7424: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7425: $status = 'active';
7426: } elsif ($end < $now) {
7427: $status = 'future';
7428: } elsif ($start > $now) {
7429: $status = 'previous';
7430: }
7431: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7432: $sectioncount{$section}++;
7433: }
7434: }
1.233 raeburn 7435: }
1.366 albertel 7436: return %sectioncount;
1.233 raeburn 7437: }
7438:
1.274 raeburn 7439: ###############################################
1.294 raeburn 7440:
7441: =pod
1.405 albertel 7442:
7443: =item * &get_course_users()
7444:
1.275 raeburn 7445: Retrieves usernames:domains for users in the specified course
7446: with specific role(s), and access status.
7447:
7448: Incoming parameters:
1.277 albertel 7449: 1. course domain
7450: 2. course number
7451: 3. access status: users must have - either active,
1.275 raeburn 7452: previous, future, or all.
1.277 albertel 7453: 4. reference to array of permissible roles
1.288 raeburn 7454: 5. reference to array of section restrictions (optional)
7455: 6. reference to results object (hash of hashes).
7456: 7. reference to optional userdata hash
1.609 raeburn 7457: 8. reference to optional statushash
1.630 raeburn 7458: 9. flag if privileged users (except those set to unhide in
7459: course settings) should be excluded
1.609 raeburn 7460: Keys of top level results hash are roles.
1.275 raeburn 7461: Keys of inner hashes are username:domain, with
7462: values set to access type.
1.288 raeburn 7463: Optional userdata hash returns an array with arguments in the
7464: same order as loncoursedata::get_classlist() for student data.
7465:
1.609 raeburn 7466: Optional statushash returns
7467:
1.288 raeburn 7468: Entries for end, start, section and status are blank because
7469: of the possibility of multiple values for non-student roles.
7470:
1.275 raeburn 7471: =cut
1.405 albertel 7472:
1.275 raeburn 7473: ###############################################
1.405 albertel 7474:
1.275 raeburn 7475: sub get_course_users {
1.630 raeburn 7476: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7477: my %idx = ();
1.419 raeburn 7478: my %seclists;
1.288 raeburn 7479:
7480: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7481: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7482: $idx{end} = &Apache::loncoursedata::CL_END();
7483: $idx{start} = &Apache::loncoursedata::CL_START();
7484: $idx{id} = &Apache::loncoursedata::CL_ID();
7485: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7486: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7487: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7488:
1.290 albertel 7489: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7490: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7491: my $now = time;
1.277 albertel 7492: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7493: my $match = 0;
1.412 raeburn 7494: my $secmatch = 0;
1.419 raeburn 7495: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7496: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7497: if ($section eq '') {
7498: $section = 'none';
7499: }
1.291 albertel 7500: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7501: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7502: $secmatch = 1;
7503: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7504: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7505: $secmatch = 1;
7506: }
7507: } else {
1.419 raeburn 7508: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7509: $secmatch = 1;
7510: }
1.290 albertel 7511: }
1.412 raeburn 7512: if (!$secmatch) {
7513: next;
7514: }
1.419 raeburn 7515: }
1.275 raeburn 7516: if (defined($$types{'active'})) {
1.288 raeburn 7517: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7518: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7519: $match = 1;
1.275 raeburn 7520: }
7521: }
7522: if (defined($$types{'previous'})) {
1.609 raeburn 7523: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7524: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7525: $match = 1;
1.275 raeburn 7526: }
7527: }
7528: if (defined($$types{'future'})) {
1.609 raeburn 7529: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7530: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7531: $match = 1;
1.275 raeburn 7532: }
7533: }
1.609 raeburn 7534: if ($match) {
7535: push(@{$seclists{$student}},$section);
7536: if (ref($userdata) eq 'HASH') {
7537: $$userdata{$student} = $$classlist{$student};
7538: }
7539: if (ref($statushash) eq 'HASH') {
7540: $statushash->{$student}{'st'}{$section} = $status;
7541: }
1.288 raeburn 7542: }
1.275 raeburn 7543: }
7544: }
1.412 raeburn 7545: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7546: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7547: my $now = time;
1.609 raeburn 7548: my %displaystatus = ( previous => 'Expired',
7549: active => 'Active',
7550: future => 'Future',
7551: );
1.630 raeburn 7552: my %nothide;
7553: if ($hidepriv) {
7554: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7555: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7556: if ($user !~ /:/) {
7557: $nothide{join(':',split(/[\@]/,$user))}=1;
7558: } else {
7559: $nothide{$user} = 1;
7560: }
7561: }
7562: }
1.439 raeburn 7563: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7564: my $match = 0;
1.412 raeburn 7565: my $secmatch = 0;
1.439 raeburn 7566: my $status;
1.412 raeburn 7567: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7568: $user =~ s/:$//;
1.439 raeburn 7569: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7570: if ($end == -1 || $start == -1) {
7571: next;
7572: }
7573: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7574: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7575: my ($uname,$udom) = split(/:/,$user);
7576: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7577: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7578: $secmatch = 1;
7579: } elsif ($usec eq '') {
1.420 albertel 7580: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7581: $secmatch = 1;
7582: }
7583: } else {
7584: if (grep(/^\Q$usec\E$/,@{$sections})) {
7585: $secmatch = 1;
7586: }
7587: }
7588: if (!$secmatch) {
7589: next;
7590: }
1.288 raeburn 7591: }
1.419 raeburn 7592: if ($usec eq '') {
7593: $usec = 'none';
7594: }
1.275 raeburn 7595: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7596: if ($hidepriv) {
7597: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7598: (!$nothide{$uname.':'.$udom})) {
7599: next;
7600: }
7601: }
1.503 raeburn 7602: if ($end > 0 && $end < $now) {
1.439 raeburn 7603: $status = 'previous';
7604: } elsif ($start > $now) {
7605: $status = 'future';
7606: } else {
7607: $status = 'active';
7608: }
1.277 albertel 7609: foreach my $type (keys(%{$types})) {
1.275 raeburn 7610: if ($status eq $type) {
1.420 albertel 7611: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7612: push(@{$$users{$role}{$user}},$type);
7613: }
1.288 raeburn 7614: $match = 1;
7615: }
7616: }
1.419 raeburn 7617: if (($match) && (ref($userdata) eq 'HASH')) {
7618: if (!exists($$userdata{$uname.':'.$udom})) {
7619: &get_user_info($udom,$uname,\%idx,$userdata);
7620: }
1.420 albertel 7621: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7622: push(@{$seclists{$uname.':'.$udom}},$usec);
7623: }
1.609 raeburn 7624: if (ref($statushash) eq 'HASH') {
7625: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7626: }
1.275 raeburn 7627: }
7628: }
7629: }
7630: }
1.290 albertel 7631: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7632: if ((defined($cdom)) && (defined($cnum))) {
7633: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7634: if ( defined($csettings{'internal.courseowner'}) ) {
7635: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7636: next if ($owner eq '');
7637: my ($ownername,$ownerdom);
7638: if ($owner =~ /^([^:]+):([^:]+)$/) {
7639: $ownername = $1;
7640: $ownerdom = $2;
7641: } else {
7642: $ownername = $owner;
7643: $ownerdom = $cdom;
7644: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7645: }
7646: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7647: if (defined($userdata) &&
1.609 raeburn 7648: !exists($$userdata{$owner})) {
7649: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7650: if (!grep(/^none$/,@{$seclists{$owner}})) {
7651: push(@{$seclists{$owner}},'none');
7652: }
7653: if (ref($statushash) eq 'HASH') {
7654: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7655: }
1.290 albertel 7656: }
1.279 raeburn 7657: }
7658: }
7659: }
1.419 raeburn 7660: foreach my $user (keys(%seclists)) {
7661: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7662: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7663: }
1.275 raeburn 7664: }
7665: return;
7666: }
7667:
1.288 raeburn 7668: sub get_user_info {
7669: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7670: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7671: &plainname($uname,$udom,'lastname');
1.291 albertel 7672: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7673: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7674: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7675: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7676: return;
7677: }
1.275 raeburn 7678:
1.472 raeburn 7679: ###############################################
7680:
7681: =pod
7682:
7683: =item * &get_user_quota()
7684:
7685: Retrieves quota assigned for storage of portfolio files for a user
7686:
7687: Incoming parameters:
7688: 1. user's username
7689: 2. user's domain
7690:
7691: Returns:
1.536 raeburn 7692: 1. Disk quota (in Mb) assigned to student.
7693: 2. (Optional) Type of setting: custom or default
7694: (individually assigned or default for user's
7695: institutional status).
7696: 3. (Optional) - User's institutional status (e.g., faculty, staff
7697: or student - types as defined in localenroll::inst_usertypes
7698: for user's domain, which determines default quota for user.
7699: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7700:
7701: If a value has been stored in the user's environment,
1.536 raeburn 7702: it will return that, otherwise it returns the maximal default
7703: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7704:
7705: =cut
7706:
7707: ###############################################
7708:
7709:
7710: sub get_user_quota {
7711: my ($uname,$udom) = @_;
1.536 raeburn 7712: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7713: if (!defined($udom)) {
7714: $udom = $env{'user.domain'};
7715: }
7716: if (!defined($uname)) {
7717: $uname = $env{'user.name'};
7718: }
7719: if (($udom eq '' || $uname eq '') ||
7720: ($udom eq 'public') && ($uname eq 'public')) {
7721: $quota = 0;
1.536 raeburn 7722: $quotatype = 'default';
7723: $defquota = 0;
1.472 raeburn 7724: } else {
1.536 raeburn 7725: my $inststatus;
1.472 raeburn 7726: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7727: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7728: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7729: } else {
1.536 raeburn 7730: my %userenv =
7731: &Apache::lonnet::get('environment',['portfolioquota',
7732: 'inststatus'],$udom,$uname);
1.472 raeburn 7733: my ($tmp) = keys(%userenv);
7734: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7735: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7736: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7737: } else {
7738: undef(%userenv);
7739: }
7740: }
1.536 raeburn 7741: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7742: if ($quota eq '') {
1.536 raeburn 7743: $quota = $defquota;
7744: $quotatype = 'default';
7745: } else {
7746: $quotatype = 'custom';
1.472 raeburn 7747: }
7748: }
1.536 raeburn 7749: if (wantarray) {
7750: return ($quota,$quotatype,$settingstatus,$defquota);
7751: } else {
7752: return $quota;
7753: }
1.472 raeburn 7754: }
7755:
7756: ###############################################
7757:
7758: =pod
7759:
7760: =item * &default_quota()
7761:
1.536 raeburn 7762: Retrieves default quota assigned for storage of user portfolio files,
7763: given an (optional) user's institutional status.
1.472 raeburn 7764:
7765: Incoming parameters:
7766: 1. domain
1.536 raeburn 7767: 2. (Optional) institutional status(es). This is a : separated list of
7768: status types (e.g., faculty, staff, student etc.)
7769: which apply to the user for whom the default is being retrieved.
7770: If the institutional status string in undefined, the domain
7771: default quota will be returned.
1.472 raeburn 7772:
7773: Returns:
7774: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7775: 2. (Optional) institutional type which determined the value of the
7776: default quota.
1.472 raeburn 7777:
7778: If a value has been stored in the domain's configuration db,
7779: it will return that, otherwise it returns 20 (for backwards
7780: compatibility with domains which have not set up a configuration
7781: db file; the original statically defined portfolio quota was 20 Mb).
7782:
1.536 raeburn 7783: If the user's status includes multiple types (e.g., staff and student),
7784: the largest default quota which applies to the user determines the
7785: default quota returned.
7786:
1.780 raeburn 7787: =back
7788:
1.472 raeburn 7789: =cut
7790:
7791: ###############################################
7792:
7793:
7794: sub default_quota {
1.536 raeburn 7795: my ($udom,$inststatus) = @_;
7796: my ($defquota,$settingstatus);
7797: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7798: ['quotas'],$udom);
7799: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7800: if ($inststatus ne '') {
1.765 raeburn 7801: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7802: foreach my $item (@statuses) {
1.711 raeburn 7803: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7804: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7805: if ($defquota eq '') {
7806: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7807: $settingstatus = $item;
7808: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7809: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7810: $settingstatus = $item;
7811: }
7812: }
7813: } else {
7814: if ($quotahash{'quotas'}{$item} ne '') {
7815: if ($defquota eq '') {
7816: $defquota = $quotahash{'quotas'}{$item};
7817: $settingstatus = $item;
7818: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7819: $defquota = $quotahash{'quotas'}{$item};
7820: $settingstatus = $item;
7821: }
1.536 raeburn 7822: }
7823: }
7824: }
7825: }
7826: if ($defquota eq '') {
1.711 raeburn 7827: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7828: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7829: } else {
7830: $defquota = $quotahash{'quotas'}{'default'};
7831: }
1.536 raeburn 7832: $settingstatus = 'default';
7833: }
7834: } else {
7835: $settingstatus = 'default';
7836: $defquota = 20;
7837: }
7838: if (wantarray) {
7839: return ($defquota,$settingstatus);
1.472 raeburn 7840: } else {
1.536 raeburn 7841: return $defquota;
1.472 raeburn 7842: }
7843: }
7844:
1.384 raeburn 7845: sub get_secgrprole_info {
7846: my ($cdom,$cnum,$needroles,$type) = @_;
7847: my %sections_count = &get_sections($cdom,$cnum);
7848: my @sections = (sort {$a <=> $b} keys(%sections_count));
7849: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7850: my @groups = sort(keys(%curr_groups));
7851: my $allroles = [];
7852: my $rolehash;
7853: my $accesshash = {
7854: active => 'Currently has access',
7855: future => 'Will have future access',
7856: previous => 'Previously had access',
7857: };
7858: if ($needroles) {
7859: $rolehash = {'all' => 'all'};
1.385 albertel 7860: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7861: if (&Apache::lonnet::error(%user_roles)) {
7862: undef(%user_roles);
7863: }
7864: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7865: my ($role)=split(/\:/,$item,2);
7866: if ($role eq 'cr') { next; }
7867: if ($role =~ /^cr/) {
7868: $$rolehash{$role} = (split('/',$role))[3];
7869: } else {
7870: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7871: }
7872: }
7873: foreach my $key (sort(keys(%{$rolehash}))) {
7874: push(@{$allroles},$key);
7875: }
7876: push (@{$allroles},'st');
7877: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7878: }
7879: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7880: }
7881:
1.555 raeburn 7882: sub user_picker {
1.948.2.23 raeburn 7883: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 7884: my $currdom = $dom;
7885: my %curr_selected = (
7886: srchin => 'dom',
1.580 raeburn 7887: srchby => 'lastname',
1.555 raeburn 7888: );
7889: my $srchterm;
1.625 raeburn 7890: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7891: if ($srch->{'srchby'} ne '') {
7892: $curr_selected{'srchby'} = $srch->{'srchby'};
7893: }
7894: if ($srch->{'srchin'} ne '') {
7895: $curr_selected{'srchin'} = $srch->{'srchin'};
7896: }
7897: if ($srch->{'srchtype'} ne '') {
7898: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7899: }
7900: if ($srch->{'srchdomain'} ne '') {
7901: $currdom = $srch->{'srchdomain'};
7902: }
7903: $srchterm = $srch->{'srchterm'};
7904: }
7905: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7906: 'usr' => 'Search criteria',
1.563 raeburn 7907: 'doma' => 'Domain/institution to search',
1.558 albertel 7908: 'uname' => 'username',
7909: 'lastname' => 'last name',
1.555 raeburn 7910: 'lastfirst' => 'last name, first name',
1.558 albertel 7911: 'crs' => 'in this course',
1.576 raeburn 7912: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7913: 'alc' => 'all LON-CAPA',
1.573 raeburn 7914: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7915: 'exact' => 'is',
7916: 'contains' => 'contains',
1.569 raeburn 7917: 'begins' => 'begins with',
1.571 raeburn 7918: 'youm' => "You must include some text to search for.",
7919: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7920: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7921: 'yomc' => "You must choose a domain when using an institutional directory search.",
7922: 'ymcd' => "You must choose a domain when using a domain search.",
7923: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7924: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7925: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7926: );
1.563 raeburn 7927: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7928: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7929:
7930: my @srchins = ('crs','dom','alc','instd');
7931:
7932: foreach my $option (@srchins) {
7933: # FIXME 'alc' option unavailable until
7934: # loncreateuser::print_user_query_page()
7935: # has been completed.
7936: next if ($option eq 'alc');
1.880 raeburn 7937: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7938: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7939: if ($curr_selected{'srchin'} eq $option) {
7940: $srchinsel .= '
7941: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7942: } else {
7943: $srchinsel .= '
7944: <option value="'.$option.'">'.$lt{$option}.'</option>';
7945: }
1.555 raeburn 7946: }
1.563 raeburn 7947: $srchinsel .= "\n </select>\n";
1.555 raeburn 7948:
7949: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7950: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7951: if ($curr_selected{'srchby'} eq $option) {
7952: $srchbysel .= '
7953: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7954: } else {
7955: $srchbysel .= '
7956: <option value="'.$option.'">'.$lt{$option}.'</option>';
7957: }
7958: }
7959: $srchbysel .= "\n </select>\n";
7960:
7961: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7962: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7963: if ($curr_selected{'srchtype'} eq $option) {
7964: $srchtypesel .= '
7965: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7966: } else {
7967: $srchtypesel .= '
7968: <option value="'.$option.'">'.$lt{$option}.'</option>';
7969: }
7970: }
7971: $srchtypesel .= "\n </select>\n";
7972:
1.558 albertel 7973: my ($newuserscript,$new_user_create);
1.948.2.23 raeburn 7974: my $context_dom = $env{'request.role.domain'};
7975: if ($context eq 'requestcrs') {
7976: if ($env{'form.coursedom'} ne '') {
7977: $context_dom = $env{'form.coursedom'};
7978: }
7979: }
1.556 raeburn 7980: if ($forcenewuser) {
1.576 raeburn 7981: if (ref($srch) eq 'HASH') {
1.948.2.23 raeburn 7982: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 7983: if ($cancreate) {
7984: $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>';
7985: } else {
1.799 bisitz 7986: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7987: my %usertypetext = (
7988: official => 'institutional',
7989: unofficial => 'non-institutional',
7990: );
1.799 bisitz 7991: $new_user_create = '<p class="LC_warning">'
7992: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7993: .' '
7994: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7995: ,'<a href="'.$helplink.'">','</a>')
7996: .'</p><br />';
1.627 raeburn 7997: }
1.576 raeburn 7998: }
7999: }
8000:
1.556 raeburn 8001: $newuserscript = <<"ENDSCRIPT";
8002:
1.570 raeburn 8003: function setSearch(createnew,callingForm) {
1.556 raeburn 8004: if (createnew == 1) {
1.570 raeburn 8005: for (var i=0; i<callingForm.srchby.length; i++) {
8006: if (callingForm.srchby.options[i].value == 'uname') {
8007: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8008: }
8009: }
1.570 raeburn 8010: for (var i=0; i<callingForm.srchin.length; i++) {
8011: if ( callingForm.srchin.options[i].value == 'dom') {
8012: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8013: }
8014: }
1.570 raeburn 8015: for (var i=0; i<callingForm.srchtype.length; i++) {
8016: if (callingForm.srchtype.options[i].value == 'exact') {
8017: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8018: }
8019: }
1.570 raeburn 8020: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.948.2.23 raeburn 8021: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8022: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8023: }
8024: }
8025: }
8026: }
8027: ENDSCRIPT
1.558 albertel 8028:
1.556 raeburn 8029: }
8030:
1.555 raeburn 8031: my $output = <<"END_BLOCK";
1.556 raeburn 8032: <script type="text/javascript">
1.824 bisitz 8033: // <![CDATA[
1.570 raeburn 8034: function validateEntry(callingForm) {
1.558 albertel 8035:
1.556 raeburn 8036: var checkok = 1;
1.558 albertel 8037: var srchin;
1.570 raeburn 8038: for (var i=0; i<callingForm.srchin.length; i++) {
8039: if ( callingForm.srchin[i].checked ) {
8040: srchin = callingForm.srchin[i].value;
1.558 albertel 8041: }
8042: }
8043:
1.570 raeburn 8044: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8045: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8046: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8047: var srchterm = callingForm.srchterm.value;
8048: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8049: var msg = "";
8050:
8051: if (srchterm == "") {
8052: checkok = 0;
1.571 raeburn 8053: msg += "$lt{'youm'}\\n";
1.556 raeburn 8054: }
8055:
1.569 raeburn 8056: if (srchtype== 'begins') {
8057: if (srchterm.length < 2) {
8058: checkok = 0;
1.571 raeburn 8059: msg += "$lt{'thte'}\\n";
1.569 raeburn 8060: }
8061: }
8062:
1.556 raeburn 8063: if (srchtype== 'contains') {
8064: if (srchterm.length < 3) {
8065: checkok = 0;
1.571 raeburn 8066: msg += "$lt{'thet'}\\n";
1.556 raeburn 8067: }
8068: }
8069: if (srchin == 'instd') {
8070: if (srchdomain == '') {
8071: checkok = 0;
1.571 raeburn 8072: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8073: }
8074: }
8075: if (srchin == 'dom') {
8076: if (srchdomain == '') {
8077: checkok = 0;
1.571 raeburn 8078: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8079: }
8080: }
8081: if (srchby == 'lastfirst') {
8082: if (srchterm.indexOf(",") == -1) {
8083: checkok = 0;
1.571 raeburn 8084: msg += "$lt{'whus'}\\n";
1.556 raeburn 8085: }
8086: if (srchterm.indexOf(",") == srchterm.length -1) {
8087: checkok = 0;
1.571 raeburn 8088: msg += "$lt{'whse'}\\n";
1.556 raeburn 8089: }
8090: }
8091: if (checkok == 0) {
1.571 raeburn 8092: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8093: return;
8094: }
8095: if (checkok == 1) {
1.570 raeburn 8096: callingForm.submit();
1.556 raeburn 8097: }
8098: }
8099:
8100: $newuserscript
8101:
1.824 bisitz 8102: // ]]>
1.556 raeburn 8103: </script>
1.558 albertel 8104:
8105: $new_user_create
8106:
1.555 raeburn 8107: END_BLOCK
1.558 albertel 8108:
1.876 raeburn 8109: $output .= &Apache::lonhtmlcommon::start_pick_box().
8110: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8111: $domform.
8112: &Apache::lonhtmlcommon::row_closure().
8113: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8114: $srchbysel.
8115: $srchtypesel.
8116: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8117: $srchinsel.
8118: &Apache::lonhtmlcommon::row_closure(1).
8119: &Apache::lonhtmlcommon::end_pick_box().
8120: '<br />';
1.555 raeburn 8121: return $output;
8122: }
8123:
1.612 raeburn 8124: sub user_rule_check {
1.615 raeburn 8125: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8126: my $response;
8127: if (ref($usershash) eq 'HASH') {
8128: foreach my $user (keys(%{$usershash})) {
8129: my ($uname,$udom) = split(/:/,$user);
8130: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8131: my ($id,$newuser);
1.612 raeburn 8132: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8133: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8134: $id = $usershash->{$user}->{'id'};
8135: }
8136: my $inst_response;
8137: if (ref($checks) eq 'HASH') {
8138: if (defined($checks->{'username'})) {
1.615 raeburn 8139: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8140: &Apache::lonnet::get_instuser($udom,$uname);
8141: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8142: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8143: &Apache::lonnet::get_instuser($udom,undef,$id);
8144: }
1.615 raeburn 8145: } else {
8146: ($inst_response,%{$inst_results->{$user}}) =
8147: &Apache::lonnet::get_instuser($udom,$uname);
8148: return;
1.612 raeburn 8149: }
1.615 raeburn 8150: if (!$got_rules->{$udom}) {
1.612 raeburn 8151: my %domconfig = &Apache::lonnet::get_dom('configuration',
8152: ['usercreation'],$udom);
8153: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8154: foreach my $item ('username','id') {
1.612 raeburn 8155: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8156: $$curr_rules{$udom}{$item} =
8157: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8158: }
8159: }
8160: }
1.615 raeburn 8161: $got_rules->{$udom} = 1;
1.585 raeburn 8162: }
1.612 raeburn 8163: foreach my $item (keys(%{$checks})) {
8164: if (ref($$curr_rules{$udom}) eq 'HASH') {
8165: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8166: if (@{$$curr_rules{$udom}{$item}} > 0) {
8167: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8168: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8169: if ($rule_check{$rule}) {
8170: $$rulematch{$user}{$item} = $rule;
8171: if ($inst_response eq 'ok') {
1.615 raeburn 8172: if (ref($inst_results) eq 'HASH') {
8173: if (ref($inst_results->{$user}) eq 'HASH') {
8174: if (keys(%{$inst_results->{$user}}) == 0) {
8175: $$alerts{$item}{$udom}{$uname} = 1;
8176: }
1.612 raeburn 8177: }
8178: }
1.615 raeburn 8179: }
8180: last;
1.585 raeburn 8181: }
8182: }
8183: }
8184: }
8185: }
8186: }
8187: }
8188: }
1.612 raeburn 8189: return;
8190: }
8191:
8192: sub user_rule_formats {
8193: my ($domain,$domdesc,$curr_rules,$check) = @_;
8194: my %text = (
8195: 'username' => 'Usernames',
8196: 'id' => 'IDs',
8197: );
8198: my $output;
8199: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8200: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8201: if (@{$ruleorder} > 0) {
8202: $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>';
8203: foreach my $rule (@{$ruleorder}) {
8204: if (ref($curr_rules) eq 'ARRAY') {
8205: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8206: if (ref($rules->{$rule}) eq 'HASH') {
8207: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8208: $rules->{$rule}{'desc'}.'</li>';
8209: }
8210: }
8211: }
8212: }
8213: $output .= '</ul>';
8214: }
8215: }
8216: return $output;
8217: }
8218:
8219: sub instrule_disallow_msg {
1.615 raeburn 8220: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8221: my $response;
8222: my %text = (
8223: item => 'username',
8224: items => 'usernames',
8225: match => 'matches',
8226: do => 'does',
8227: action => 'a username',
8228: one => 'one',
8229: );
8230: if ($count > 1) {
8231: $text{'item'} = 'usernames';
8232: $text{'match'} ='match';
8233: $text{'do'} = 'do';
8234: $text{'action'} = 'usernames',
8235: $text{'one'} = 'ones';
8236: }
8237: if ($checkitem eq 'id') {
8238: $text{'items'} = 'IDs';
8239: $text{'item'} = 'ID';
8240: $text{'action'} = 'an ID';
1.615 raeburn 8241: if ($count > 1) {
8242: $text{'item'} = 'IDs';
8243: $text{'action'} = 'IDs';
8244: }
1.612 raeburn 8245: }
1.674 bisitz 8246: $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 8247: if ($mode eq 'upload') {
8248: if ($checkitem eq 'username') {
8249: $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'}.");
8250: } elsif ($checkitem eq 'id') {
1.674 bisitz 8251: $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 8252: }
1.669 raeburn 8253: } elsif ($mode eq 'selfcreate') {
8254: if ($checkitem eq 'id') {
8255: $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.");
8256: }
1.615 raeburn 8257: } else {
8258: if ($checkitem eq 'username') {
8259: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8260: } elsif ($checkitem eq 'id') {
8261: $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.");
8262: }
1.612 raeburn 8263: }
8264: return $response;
1.585 raeburn 8265: }
8266:
1.624 raeburn 8267: sub personal_data_fieldtitles {
8268: my %fieldtitles = &Apache::lonlocal::texthash (
8269: id => 'Student/Employee ID',
8270: permanentemail => 'E-mail address',
8271: lastname => 'Last Name',
8272: firstname => 'First Name',
8273: middlename => 'Middle Name',
8274: generation => 'Generation',
8275: gen => 'Generation',
1.765 raeburn 8276: inststatus => 'Affiliation',
1.624 raeburn 8277: );
8278: return %fieldtitles;
8279: }
8280:
1.642 raeburn 8281: sub sorted_inst_types {
8282: my ($dom) = @_;
8283: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8284: my $othertitle = &mt('All users');
8285: if ($env{'request.course.id'}) {
1.668 raeburn 8286: $othertitle = &mt('Any users');
1.642 raeburn 8287: }
8288: my @types;
8289: if (ref($order) eq 'ARRAY') {
8290: @types = @{$order};
8291: }
8292: if (@types == 0) {
8293: if (ref($usertypes) eq 'HASH') {
8294: @types = sort(keys(%{$usertypes}));
8295: }
8296: }
8297: if (keys(%{$usertypes}) > 0) {
8298: $othertitle = &mt('Other users');
8299: }
8300: return ($othertitle,$usertypes,\@types);
8301: }
8302:
1.645 raeburn 8303: sub get_institutional_codes {
8304: my ($settings,$allcourses,$LC_code) = @_;
8305: # Get complete list of course sections to update
8306: my @currsections = ();
8307: my @currxlists = ();
8308: my $coursecode = $$settings{'internal.coursecode'};
8309:
8310: if ($$settings{'internal.sectionnums'} ne '') {
8311: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8312: }
8313:
8314: if ($$settings{'internal.crosslistings'} ne '') {
8315: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8316: }
8317:
8318: if (@currxlists > 0) {
8319: foreach (@currxlists) {
8320: if (m/^([^:]+):(\w*)$/) {
8321: unless (grep/^$1$/,@{$allcourses}) {
8322: push @{$allcourses},$1;
8323: $$LC_code{$1} = $2;
8324: }
8325: }
8326: }
8327: }
8328:
8329: if (@currsections > 0) {
8330: foreach (@currsections) {
8331: if (m/^(\w+):(\w*)$/) {
8332: my $sec = $coursecode.$1;
8333: my $lc_sec = $2;
8334: unless (grep/^$sec$/,@{$allcourses}) {
8335: push @{$allcourses},$sec;
8336: $$LC_code{$sec} = $lc_sec;
8337: }
8338: }
8339: }
8340: }
8341: return;
8342: }
8343:
1.948.2.7 raeburn 8344: sub get_standard_codeitems {
8345: return ('Year','Semester','Department','Number','Section');
8346: }
8347:
1.112 bowersj2 8348: =pod
8349:
1.780 raeburn 8350: =head1 Slot Helpers
8351:
8352: =over 4
8353:
8354: =item * sorted_slots()
8355:
8356: Sorts an array of slot names in order of slot start time (earliest first).
8357:
8358: Inputs:
8359:
8360: =over 4
8361:
8362: slotsarr - Reference to array of unsorted slot names.
8363:
8364: slots - Reference to hash of hash, where outer hash keys are slot names.
8365:
1.549 albertel 8366: =back
8367:
1.780 raeburn 8368: Returns:
8369:
8370: =over 4
8371:
8372: sorted - An array of slot names sorted by the start time of the slot.
8373:
8374: =back
8375:
8376: =back
8377:
8378: =cut
8379:
8380:
8381: sub sorted_slots {
8382: my ($slotsarr,$slots) = @_;
8383: my @sorted;
8384: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8385: @sorted =
8386: sort {
8387: if (ref($slots->{$a}) && ref($slots->{$b})) {
8388: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8389: }
8390: if (ref($slots->{$a})) { return -1;}
8391: if (ref($slots->{$b})) { return 1;}
8392: return 0;
8393: } @{$slotsarr};
8394: }
8395: return @sorted;
8396: }
8397:
8398:
8399: =pod
8400:
1.549 albertel 8401: =head1 HTTP Helpers
8402:
8403: =over 4
8404:
1.648 raeburn 8405: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8406:
1.258 albertel 8407: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8408: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8409: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8410:
8411: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8412: $possible_names is an ref to an array of form element names. As an example:
8413: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8414: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8415:
8416: =cut
1.1 albertel 8417:
1.6 albertel 8418: sub get_unprocessed_cgi {
1.25 albertel 8419: my ($query,$possible_names)= @_;
1.26 matthew 8420: # $Apache::lonxml::debug=1;
1.356 albertel 8421: foreach my $pair (split(/&/,$query)) {
8422: my ($name, $value) = split(/=/,$pair);
1.369 www 8423: $name = &unescape($name);
1.25 albertel 8424: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8425: $value =~ tr/+/ /;
8426: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8427: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8428: }
1.16 harris41 8429: }
1.6 albertel 8430: }
8431:
1.112 bowersj2 8432: =pod
8433:
1.648 raeburn 8434: =item * &cacheheader()
1.112 bowersj2 8435:
8436: returns cache-controlling header code
8437:
8438: =cut
8439:
1.7 albertel 8440: sub cacheheader {
1.258 albertel 8441: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8442: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8443: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8444: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8445: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8446: return $output;
1.7 albertel 8447: }
8448:
1.112 bowersj2 8449: =pod
8450:
1.648 raeburn 8451: =item * &no_cache($r)
1.112 bowersj2 8452:
8453: specifies header code to not have cache
8454:
8455: =cut
8456:
1.9 albertel 8457: sub no_cache {
1.216 albertel 8458: my ($r) = @_;
8459: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8460: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8461: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8462: $r->no_cache(1);
8463: $r->header_out("Expires" => $date);
8464: $r->header_out("Pragma" => "no-cache");
1.123 www 8465: }
8466:
8467: sub content_type {
1.181 albertel 8468: my ($r,$type,$charset) = @_;
1.299 foxr 8469: if ($r) {
8470: # Note that printout.pl calls this with undef for $r.
8471: &no_cache($r);
8472: }
1.258 albertel 8473: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8474: unless ($charset) {
8475: $charset=&Apache::lonlocal::current_encoding;
8476: }
8477: if ($charset) { $type.='; charset='.$charset; }
8478: if ($r) {
8479: $r->content_type($type);
8480: } else {
8481: print("Content-type: $type\n\n");
8482: }
1.9 albertel 8483: }
1.25 albertel 8484:
1.112 bowersj2 8485: =pod
8486:
1.648 raeburn 8487: =item * &add_to_env($name,$value)
1.112 bowersj2 8488:
1.258 albertel 8489: adds $name to the %env hash with value
1.112 bowersj2 8490: $value, if $name already exists, the entry is converted to an array
8491: reference and $value is added to the array.
8492:
8493: =cut
8494:
1.25 albertel 8495: sub add_to_env {
8496: my ($name,$value)=@_;
1.258 albertel 8497: if (defined($env{$name})) {
8498: if (ref($env{$name})) {
1.25 albertel 8499: #already have multiple values
1.258 albertel 8500: push(@{ $env{$name} },$value);
1.25 albertel 8501: } else {
8502: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8503: my $first=$env{$name};
8504: undef($env{$name});
8505: push(@{ $env{$name} },$first,$value);
1.25 albertel 8506: }
8507: } else {
1.258 albertel 8508: $env{$name}=$value;
1.25 albertel 8509: }
1.31 albertel 8510: }
1.149 albertel 8511:
8512: =pod
8513:
1.648 raeburn 8514: =item * &get_env_multiple($name)
1.149 albertel 8515:
1.258 albertel 8516: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8517: values may be defined and end up as an array ref.
8518:
8519: returns an array of values
8520:
8521: =cut
8522:
8523: sub get_env_multiple {
8524: my ($name) = @_;
8525: my @values;
1.258 albertel 8526: if (defined($env{$name})) {
1.149 albertel 8527: # exists is it an array
1.258 albertel 8528: if (ref($env{$name})) {
8529: @values=@{ $env{$name} };
1.149 albertel 8530: } else {
1.258 albertel 8531: $values[0]=$env{$name};
1.149 albertel 8532: }
8533: }
8534: return(@values);
8535: }
8536:
1.660 raeburn 8537: sub ask_for_embedded_content {
8538: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.948.2.17 raeburn 8539: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660 raeburn 8540: my $num = 0;
1.948.2.17 raeburn 8541: my $numremref = 0;
8542: my $numinvalid = 0;
8543: my $numpathchg = 0;
8544: my $numexisting = 0;
8545: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.948.2.12 raeburn 8546: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8547: my $current_path='/';
8548: if ($env{'form.currentpath'}) {
8549: $current_path = $env{'form.currentpath'};
8550: }
8551: if ($actionurl eq '/adm/coursegrp_portfolio') {
8552: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8553: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8554: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8555: } else {
8556: $udom = $env{'user.domain'};
8557: $uname = $env{'user.name'};
8558: $url = '/userfiles/portfolio';
8559: }
1.948.2.17 raeburn 8560: $toplevel = $url.'/';
1.948.2.12 raeburn 8561: $url .= $current_path;
8562: $getpropath = 1;
1.948.2.17 raeburn 8563: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8564: ($actionurl eq '/adm/imsimport')) {
1.948.2.12 raeburn 8565: ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
1.948.2.17 raeburn 8566: $url = '/home/'.$uname.'/public_html/';
8567: $toplevel = $url;
1.948.2.12 raeburn 8568: if ($rest ne '') {
1.948.2.17 raeburn 8569: $url .= $rest;
8570: }
8571: } elsif ($actionurl eq '/adm/coursedocs') {
8572: if (ref($args) eq 'HASH') {
8573: $url = $args->{'docs_url'};
8574: $toplevel = $url;
8575: }
8576: }
8577: my $now = time();
8578: foreach my $embed_file (keys(%{$allfiles})) {
8579: my $absolutepath;
8580: if ($embed_file =~ m{^\w+://}) {
8581: $newfiles{$embed_file} = 1;
8582: $mapping{$embed_file} = $embed_file;
8583: } else {
8584: if ($embed_file =~ m{^/}) {
8585: $absolutepath = $embed_file;
8586: $embed_file =~ s{^(/+)}{};
8587: }
8588: if ($embed_file =~ m{/}) {
8589: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8590: $path = &check_for_traversal($path,$url,$toplevel);
8591: my $item = $fname;
8592: if ($path ne '') {
8593: $item = $path.'/'.$fname;
8594: $subdependencies{$path}{$fname} = 1;
8595: } else {
8596: $dependencies{$item} = 1;
8597: }
8598: if ($absolutepath) {
8599: $mapping{$item} = $absolutepath;
8600: } else {
8601: $mapping{$item} = $embed_file;
8602: }
8603: } else {
8604: $dependencies{$embed_file} = 1;
8605: if ($absolutepath) {
8606: $mapping{$embed_file} = $absolutepath;
8607: } else {
8608: $mapping{$embed_file} = $embed_file;
8609: }
8610: }
1.948.2.12 raeburn 8611: }
8612: }
8613: foreach my $path (keys(%subdependencies)) {
8614: my %currsubfile;
8615: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8616: my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8617: foreach my $line (@subdir_list) {
8618: my ($file_name,$rest) = split(/\&/,$line,2);
8619: $currsubfile{$file_name} = 1;
8620: }
1.948.2.17 raeburn 8621: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.948.2.12 raeburn 8622: if (opendir(my $dir,$url.'/'.$path)) {
8623: my @subdir_list = grep(!/^\./,readdir($dir));
8624: map {$currsubfile{$_} = 1;} @subdir_list;
8625: }
8626: }
8627: foreach my $file (keys(%{$subdependencies{$path}})) {
1.948.2.17 raeburn 8628: if ($currsubfile{$file}) {
8629: my $item = $path.'/'.$file;
8630: unless ($mapping{$item} eq $item) {
8631: $pathchanges{$item} = 1;
8632: }
8633: $existing{$item} = 1;
8634: $numexisting ++;
8635: } else {
8636: $newfiles{$path.'/'.$file} = 1;
1.948.2.12 raeburn 8637: }
8638: }
8639: }
1.948.2.17 raeburn 8640: my %currfile;
1.948.2.12 raeburn 8641: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8642: my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8643: foreach my $line (@dir_list) {
8644: my ($file_name,$rest) = split(/\&/,$line,2);
8645: $currfile{$file_name} = 1;
8646: }
1.948.2.17 raeburn 8647: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.948.2.12 raeburn 8648: if (opendir(my $dir,$url)) {
1.948.2.17 raeburn 8649: my @dir_list = grep(!/^\./,readdir($dir));
1.948.2.12 raeburn 8650: map {$currfile{$_} = 1;} @dir_list;
8651: }
8652: }
8653: foreach my $file (keys(%dependencies)) {
1.948.2.17 raeburn 8654: if ($currfile{$file}) {
8655: unless ($mapping{$file} eq $file) {
8656: $pathchanges{$file} = 1;
8657: }
8658: $existing{$file} = 1;
8659: $numexisting ++;
8660: } else {
1.948.2.12 raeburn 8661: $newfiles{$file} = 1;
8662: }
8663: }
8664: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8665: $upload_output .= &start_data_table_row().
1.948.2.17 raeburn 8666: '<td><span class="LC_filename">'.$embed_file.'</span>';
8667: unless ($mapping{$embed_file} eq $embed_file) {
8668: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
8669: }
8670: $upload_output .= '</td><td>';
1.660 raeburn 8671: if ($args->{'ignore_remote_references'}
8672: && $embed_file =~ m{^\w+://}) {
8673: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.948.2.17 raeburn 8674: $numremref++;
1.660 raeburn 8675: } elsif ($args->{'error_on_invalid_names'}
8676: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8677:
1.948.2.17 raeburn 8678: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
8679: $numinvalid++;
1.660 raeburn 8680: } else {
1.948.2.17 raeburn 8681: $upload_output .= &embedded_file_element('upload_embedded',$num,
8682: $embed_file,\%mapping,
8683: $allfiles,$codebase);
8684: $num++;
1.660 raeburn 8685: }
1.948.2.12 raeburn 8686: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
1.660 raeburn 8687: }
1.948.2.17 raeburn 8688: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
8689: $upload_output .= &start_data_table_row().
8690: '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
8691: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
8692: &Apache::loncommon::end_data_table_row()."\n";
8693: }
8694: if ($upload_output) {
8695: $upload_output = &start_data_table().
1.948.2.12 raeburn 8696: $upload_output.
1.948.2.17 raeburn 8697: &end_data_table()."\n";
8698: }
8699: my $applies = 0;
8700: if ($numremref) {
8701: $applies ++;
8702: }
8703: if ($numinvalid) {
8704: $applies ++;
8705: }
8706: if ($numexisting) {
8707: $applies ++;
8708: }
8709: if ($num) {
8710: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8711: ' method="post" enctype="multipart/form-data">'."\n".
8712: $state.
8713: '<h3>'.&mt('Upload embedded files').
8714: ':</h3>'.$upload_output.'<br />'."\n".
8715: '<input type ="hidden" name="number_embedded_items" value="'.
8716: $num.'" />'."\n";
8717: if ($actionurl eq '') {
8718: $output .= '<input type="hidden" name="phase" value="three" />';
8719: }
8720: } elsif ($applies) {
8721: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
8722: if ($applies > 1) {
8723: $output .=
8724: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
8725: if ($numremref) {
8726: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
8727: }
8728: if ($numinvalid) {
8729: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
8730: }
8731: if ($numexisting) {
8732: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
8733: }
8734: $output .= '</ul><br />';
8735: } elsif ($numremref) {
8736: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
8737: } elsif ($numinvalid) {
8738: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
8739: } elsif ($numexisting) {
8740: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
8741: }
8742: $output .= $upload_output.'<br />';
8743: }
8744: my ($pathchange_output,$chgcount);
8745: $chgcount = $num;
8746: if (keys(%pathchanges) > 0) {
8747: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
8748: if ($num) {
8749: $output .= &embedded_file_element('pathchange',$chgcount,
8750: $embed_file,\%mapping,
8751: $allfiles,$codebase);
8752: } else {
8753: $pathchange_output .=
8754: &start_data_table_row().
8755: '<td><input type ="checkbox" name="namechange" value="'.
8756: $chgcount.'" checked="checked" /></td>'.
8757: '<td>'.$mapping{$embed_file}.'</td>'.
8758: '<td>'.$embed_file.
8759: &embedded_file_element('pathchange',$numpathchg,$embed_file,
8760: \%mapping,$allfiles,$codebase).
8761: '</td>'.&end_data_table_row();
8762: }
8763: $numpathchg ++;
8764: $chgcount ++;
8765: }
8766: }
8767: if ($num) {
8768: if ($numpathchg) {
8769: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
8770: $numpathchg.'" />'."\n";
8771: }
8772: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8773: ($actionurl eq '/adm/imsimport')) {
8774: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
8775: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
8776: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
8777: }
8778: $output .= '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8779: &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
8780: } elsif ($numpathchg) {
8781: my %pathchange = ();
8782: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
8783: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8784: $output .= '<p>'.&mt('or').'</p>';
8785: }
8786: }
8787: return ($output,$num,$numpathchg);
8788: }
8789:
8790: sub embedded_file_element {
8791: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
8792: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
8793: (ref($codebase) eq 'HASH'));
8794: my $output;
8795: if ($context eq 'upload_embedded') {
8796: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
8797: }
8798: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
8799: &escape($embed_file).'" />';
8800: unless (($context eq 'upload_embedded') &&
8801: ($mapping->{$embed_file} eq $embed_file)) {
8802: $output .='
8803: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
8804: }
8805: my $attrib;
8806: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
8807: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
1.948.2.12 raeburn 8808: }
1.948.2.17 raeburn 8809: $output .=
8810: "\n\t\t".
8811: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8812: $attrib.'" />';
8813: if (exists($codebase->{$mapping->{$embed_file}})) {
8814: $output .=
8815: "\n\t\t".
8816: '<input name="codebase_'.$num.'" type="hidden" value="'.
8817: &escape($codebase->{$mapping->{$embed_file}}).'" />';
8818: }
8819: return $output;
1.660 raeburn 8820: }
8821:
1.661 raeburn 8822: sub upload_embedded {
8823: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.948.2.17 raeburn 8824: $current_disk_usage,$hiddenstate,$actionurl) = @_;
8825: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 8826: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8827: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8828: my $orig_uploaded_filename =
8829: $env{'form.embedded_item_'.$i.'.filename'};
1.948.2.17 raeburn 8830: foreach my $type ('orig','ref','attrib','codebase') {
8831: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
8832: $env{'form.embedded_'.$type.'_'.$i} =
8833: &unescape($env{'form.embedded_'.$type.'_'.$i});
8834: }
8835: }
1.661 raeburn 8836: my ($path,$fname) =
8837: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8838: # no path, whole string is fname
8839: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8840: $fname = &Apache::lonnet::clean_filename($fname);
8841: # See if there is anything left
8842: next if ($fname eq '');
8843:
8844: # Check if file already exists as a file or directory.
8845: my ($state,$msg);
8846: if ($context eq 'portfolio') {
8847: my $port_path = $dirpath;
8848: if ($group ne '') {
8849: $port_path = "groups/$group/$port_path";
8850: }
1.948.2.17 raeburn 8851: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
8852: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 8853: $dir_root,$port_path,$disk_quota,
8854: $current_disk_usage,$uname,$udom);
8855: if ($state eq 'will_exceed_quota'
1.948.2.12 raeburn 8856: || $state eq 'file_locked') {
1.661 raeburn 8857: $output .= $msg;
8858: next;
8859: }
8860: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8861: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8862: if ($state eq 'exists') {
8863: $output .= $msg;
8864: next;
8865: }
8866: }
8867: # Check if extension is valid
8868: if (($fname =~ /\.(\w+)$/) &&
8869: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.948.2.17 raeburn 8870: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 8871: next;
8872: } elsif (($fname =~ /\.(\w+)$/) &&
8873: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.948.2.17 raeburn 8874: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 8875: next;
8876: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.948.2.17 raeburn 8877: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 8878: next;
8879: }
8880:
8881: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8882: if ($context eq 'portfolio') {
1.948.2.12 raeburn 8883: my $result;
8884: if ($state eq 'existingfile') {
8885: $result=
8886: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.948.2.17 raeburn 8887: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 8888: } else {
1.948.2.12 raeburn 8889: $result=
8890: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.948.2.17 raeburn 8891: $dirpath.
8892: $env{'form.currentpath'}.$path);
1.948.2.12 raeburn 8893: if ($result !~ m|^/uploaded/|) {
8894: $output .= '<span class="LC_error">'
8895: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8896: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8897: .'</span><br />';
8898: next;
8899: } else {
1.948.2.17 raeburn 8900: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8901: $path.$fname.'</span>').'<br />';
1.948.2.12 raeburn 8902: }
1.661 raeburn 8903: }
1.948.2.17 raeburn 8904: } elsif ($context eq 'coursedoc') {
8905: my $result =
8906: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
8907: $dirpath.'/'.$path);
8908: if ($result !~ m|^/uploaded/|) {
8909: $output .= '<span class="LC_error">'
8910: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8911: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8912: .'</span><br />';
8913: next;
8914: } else {
8915: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8916: $path.$fname.'</span>').'<br />';
8917: }
1.661 raeburn 8918: } else {
8919: # Save the file
8920: my $target = $env{'form.embedded_item_'.$i};
8921: my $fullpath = $dir_root.$dirpath.'/'.$path;
8922: my $dest = $fullpath.$fname;
8923: my $url = $url_root.$dirpath.'/'.$path.$fname;
8924: my @parts=split(/\//,$fullpath);
8925: my $count;
8926: my $filepath = $dir_root;
8927: for ($count=4;$count<=$#parts;$count++) {
8928: $filepath .= "/$parts[$count]";
8929: if ((-e $filepath)!=1) {
8930: mkdir($filepath,0770);
8931: }
8932: }
8933: my $fh;
8934: if (!open($fh,'>'.$dest)) {
8935: &Apache::lonnet::logthis('Failed to create '.$dest);
8936: $output .= '<span class="LC_error">'.
8937: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8938: '</span><br />';
8939: } else {
8940: if (!print $fh $env{'form.embedded_item_'.$i}) {
8941: &Apache::lonnet::logthis('Failed to write to '.$dest);
8942: $output .= '<span class="LC_error">'.
8943: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8944: '</span><br />';
8945: } else {
1.948.2.17 raeburn 8946: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8947: $url.'</span>').'<br />';
8948: unless ($context eq 'testbank') {
8949: $footer .= &mt('View embedded file: [_1]',
8950: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
1.661 raeburn 8951: }
8952: }
8953: close($fh);
8954: }
8955: }
1.948.2.17 raeburn 8956: if ($env{'form.embedded_ref_'.$i}) {
8957: $pathchange{$i} = 1;
8958: }
1.948.2.18 raeburn 8959: }
1.948.2.17 raeburn 8960: if ($output) {
8961: $output = '<p>'.$output.'</p>';
8962: }
8963: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
8964: $returnflag = 'ok';
8965: if (keys(%pathchange) > 0) {
8966: if ($context eq 'portfolio') {
8967: $output .= '<p>'.&mt('or').'</p>';
8968: } elsif ($context eq 'testbank') {
8969: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
8970: $returnflag = 'modify_orightml';
8971: }
8972: }
8973: return ($output.$footer,$returnflag);
8974: }
8975:
8976: sub modify_html_form {
8977: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
8978: my $end = 0;
8979: my $modifyform;
8980: if ($context eq 'upload_embedded') {
8981: return unless (ref($pathchange) eq 'HASH');
8982: if ($env{'form.number_embedded_items'}) {
8983: $end += $env{'form.number_embedded_items'};
8984: }
8985: if ($env{'form.number_pathchange_items'}) {
8986: $end += $env{'form.number_pathchange_items'};
8987: }
8988: if ($end) {
8989: for (my $i=0; $i<$end; $i++) {
8990: if ($i < $env{'form.number_embedded_items'}) {
8991: next unless($pathchange->{$i});
8992: }
8993: $modifyform .=
8994: &start_data_table_row().
8995: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
8996: 'checked="checked" /></td>'.
8997: '<td>'.$env{'form.embedded_ref_'.$i}.
8998: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
8999: &escape($env{'form.embedded_ref_'.$i}).'" />'.
9000: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
9001: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
9002: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
9003: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
9004: '<td>'.$env{'form.embedded_orig_'.$i}.
9005: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
9006: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
9007: &end_data_table_row();
9008: }
9009: }
9010: } else {
9011: $modifyform = $pathchgtable;
9012: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
9013: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
9014: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9015: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
9016: }
9017: }
9018: if ($modifyform) {
9019: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
9020: '<p>'.&mt('Changes need to be made to the reference(s) used for one or more of the dependencies, if your HTML file is to work correctly:').'<ol>'."\n".
9021: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
9022: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
9023: '</ol></p>'."\n".'<p>'.
9024: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
9025: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
9026: &start_data_table()."\n".
9027: &start_data_table_header_row().
9028: '<th>'.&mt('Change?').'</th>'.
9029: '<th>'.&mt('Current reference').'</th>'.
9030: '<th>'.&mt('Required reference').'</th>'.
9031: &end_data_table_header_row()."\n".
9032: $modifyform.
9033: &end_data_table().'<br />'."\n".$hiddenstate.
9034: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
9035: '</form>'."\n";
9036: }
9037: return;
9038: }
9039:
9040: sub modify_html_refs {
9041: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
9042: my $container;
9043: if ($context eq 'portfolio') {
9044: $container = $env{'form.container'};
9045: } elsif ($context eq 'coursedoc') {
9046: $container = $env{'form.primaryurl'};
9047: } else {
9048: $container = $env{'form.filename'};
9049: $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
9050: }
9051: my (%allfiles,%codebase,$output,$content);
9052: my @changes = &get_env_multiple('form.namechange');
9053: return unless (@changes > 0);
9054: if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
9055: return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
9056: $content = &Apache::lonnet::getfile($container);
9057: return if ($content eq '-1');
9058: } else {
9059: return unless ($container =~ /^\Q$dir_root\E/);
9060: if (open(my $fh,"<$container")) {
9061: $content = join('', <$fh>);
9062: close($fh);
9063: } else {
9064: return;
9065: }
9066: }
9067: my ($count,$codebasecount) = (0,0);
9068: my $mm = new File::MMagic;
9069: my $mime_type = $mm->checktype_contents($content);
9070: if ($mime_type eq 'text/html') {
9071: my $parse_result =
9072: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
9073: \%codebase,\$content);
9074: if ($parse_result eq 'ok') {
9075: foreach my $i (@changes) {
9076: my $orig = &unescape($env{'form.embedded_orig_'.$i});
9077: my $ref = &unescape($env{'form.embedded_ref_'.$i});
9078: if ($allfiles{$ref}) {
9079: my $newname = $orig;
9080: my ($attrib_regexp,$codebase);
1.948.2.28 raeburn 9081: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.948.2.17 raeburn 9082: if ($attrib_regexp =~ /:/) {
9083: $attrib_regexp =~ s/\:/|/g;
9084: }
9085: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
9086: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
9087: $count += $numchg;
9088: }
9089: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.948.2.28 raeburn 9090: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.948.2.17 raeburn 9091: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
9092: $codebasecount ++;
9093: }
9094: }
9095: }
9096: if ($count || $codebasecount) {
9097: my $saveresult;
9098: if ($context eq 'portfolio' || $context eq 'coursedoc') {
9099: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
9100: if ($url eq $container) {
9101: my ($fname) = ($container =~ m{/([^/]+)$});
9102: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9103: $count,'<span class="LC_filename">'.
9104: $fname.'</span>').'</p>';
9105: } else {
9106: $output = '<p class="LC_error">'.
9107: &mt('Error: update failed for: [_1].',
9108: '<span class="LC_filename">'.
9109: $container.'</span>').'</p>';
9110: }
9111: } else {
9112: if (open(my $fh,">$container")) {
9113: print $fh $content;
9114: close($fh);
9115: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9116: $count,'<span class="LC_filename">'.
9117: $container.'</span>').'</p>';
9118: } else {
9119: $output = '<p class="LC_error">'.
9120: &mt('Error: could not update [_1].',
9121: '<span class="LC_filename">'.
9122: $container.'</span>').'</p>';
9123: }
9124: }
9125: }
9126: } else {
9127: &logthis('Failed to parse '.$container.
9128: ' to modify references: '.$parse_result);
9129: }
1.661 raeburn 9130: }
9131: return $output;
9132: }
9133:
9134: sub check_for_existing {
9135: my ($path,$fname,$element) = @_;
9136: my ($state,$msg);
9137: if (-d $path.'/'.$fname) {
9138: $state = 'exists';
9139: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9140: } elsif (-e $path.'/'.$fname) {
9141: $state = 'exists';
9142: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9143: }
9144: if ($state eq 'exists') {
9145: $msg = '<span class="LC_error">'.$msg.'</span><br />';
9146: }
9147: return ($state,$msg);
9148: }
9149:
9150: sub check_for_upload {
9151: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
9152: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.948.2.12 raeburn 9153: my $filesize = length($env{'form.'.$element});
9154: if (!$filesize) {
9155: my $msg = '<span class="LC_error">'.
9156: &mt('Unable to upload [_1]. (size = [_2] bytes)',
9157: '<span class="LC_filename">'.$fname.'</span>',
9158: $filesize).'<br />'.
1.948.2.29 raeburn 9159: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.948.2.12 raeburn 9160: '</span>';
9161: return ('zero_bytes',$msg);
9162: }
9163: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 9164: my $getpropath = 1;
9165: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
9166: $getpropath);
9167: my $found_file = 0;
9168: my $locked_file = 0;
1.948.2.20 raeburn 9169: my @lockers;
9170: my $navmap;
9171: if ($env{'request.course.id'}) {
9172: $navmap = Apache::lonnavmaps::navmap->new();
9173: }
1.661 raeburn 9174: foreach my $line (@dir_list) {
1.948.2.12 raeburn 9175: my ($file_name,$rest)=split(/\&/,$line,2);
1.661 raeburn 9176: if ($file_name eq $fname){
9177: $file_name = $path.$file_name;
9178: if ($group ne '') {
9179: $file_name = $group.$file_name;
9180: }
9181: $found_file = 1;
1.948.2.20 raeburn 9182: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
9183: foreach my $lock (@lockers) {
9184: if (ref($lock) eq 'ARRAY') {
9185: my ($symb,$crsid) = @{$lock};
9186: if ($crsid eq $env{'request.course.id'}) {
9187: if (ref($navmap)) {
9188: my $res = $navmap->getBySymb($symb);
9189: foreach my $part (@{$res->parts()}) {
9190: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
9191: unless (($slot_status == $res->RESERVED) ||
9192: ($slot_status == $res->RESERVED_LOCATION)) {
9193: $locked_file = 1;
9194: }
9195: }
9196: } else {
9197: $locked_file = 1;
9198: }
9199: } else {
9200: $locked_file = 1;
9201: }
9202: }
9203: }
1.948.2.12 raeburn 9204: } else {
9205: my @info = split(/\&/,$rest);
9206: my $currsize = $info[6]/1000;
9207: if ($currsize < $filesize) {
9208: my $extra = $filesize - $currsize;
9209: if (($current_disk_usage + $extra) > $disk_quota) {
9210: my $msg = '<span class="LC_error">'.
9211: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
9212: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
9213: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
9214: $disk_quota,$current_disk_usage);
9215: return ('will_exceed_quota',$msg);
9216: }
9217: }
1.661 raeburn 9218: }
9219: }
9220: }
9221: if (($current_disk_usage + $filesize) > $disk_quota){
9222: my $msg = '<span class="LC_error">'.
9223: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
9224: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
9225: return ('will_exceed_quota',$msg);
9226: } elsif ($found_file) {
9227: if ($locked_file) {
9228: my $msg = '<span class="LC_error">';
9229: $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>');
9230: $msg .= '</span><br />';
9231: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
9232: return ('file_locked',$msg);
9233: } else {
9234: my $msg = '<span class="LC_error">';
1.948.2.12 raeburn 9235: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661 raeburn 9236: $msg .= '</span>';
1.948.2.12 raeburn 9237: return ('existingfile',$msg);
1.661 raeburn 9238: }
9239: }
9240: }
9241:
1.948.2.17 raeburn 9242: sub check_for_traversal {
9243: my ($path,$url,$toplevel) = @_;
9244: my @parts=split(/\//,$path);
9245: my $cleanpath;
9246: my $fullpath = $url;
9247: for (my $i=0;$i<@parts;$i++) {
9248: next if ($parts[$i] eq '.');
9249: if ($parts[$i] eq '..') {
9250: $fullpath =~ s{([^/]+/)$}{};
9251: } else {
9252: $fullpath .= $parts[$i].'/';
9253: }
9254: }
9255: if ($fullpath =~ /^\Q$url\E(.*)$/) {
9256: $cleanpath = $1;
9257: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
9258: my $curr_toprel = $1;
9259: my @parts = split(/\//,$curr_toprel);
9260: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
9261: my @urlparts = split(/\//,$url_toprel);
9262: my $doubledots;
9263: my $startdiff = -1;
9264: for (my $i=0; $i<@urlparts; $i++) {
9265: if ($startdiff == -1) {
9266: unless ($urlparts[$i] eq $parts[$i]) {
9267: $startdiff = $i;
9268: $doubledots .= '../';
9269: }
9270: } else {
9271: $doubledots .= '../';
9272: }
9273: }
9274: if ($startdiff > -1) {
9275: $cleanpath = $doubledots;
9276: for (my $i=$startdiff; $i<@parts; $i++) {
9277: $cleanpath .= $parts[$i].'/';
9278: }
9279: }
9280: }
9281: $cleanpath =~ s{(/)$}{};
9282: return $cleanpath;
9283: }
1.31 albertel 9284:
1.41 ng 9285: =pod
1.45 matthew 9286:
1.464 albertel 9287: =back
1.41 ng 9288:
1.112 bowersj2 9289: =head1 CSV Upload/Handling functions
1.38 albertel 9290:
1.41 ng 9291: =over 4
9292:
1.648 raeburn 9293: =item * &upfile_store($r)
1.41 ng 9294:
9295: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 9296: needs $env{'form.upfile'}
1.41 ng 9297: returns $datatoken to be put into hidden field
9298:
9299: =cut
1.31 albertel 9300:
9301: sub upfile_store {
9302: my $r=shift;
1.258 albertel 9303: $env{'form.upfile'}=~s/\r/\n/gs;
9304: $env{'form.upfile'}=~s/\f/\n/gs;
9305: $env{'form.upfile'}=~s/\n+/\n/gs;
9306: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 9307:
1.258 albertel 9308: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
9309: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 9310: {
1.158 raeburn 9311: my $datafile = $r->dir_config('lonDaemons').
9312: '/tmp/'.$datatoken.'.tmp';
9313: if ( open(my $fh,">$datafile") ) {
1.258 albertel 9314: print $fh $env{'form.upfile'};
1.158 raeburn 9315: close($fh);
9316: }
1.31 albertel 9317: }
9318: return $datatoken;
9319: }
9320:
1.56 matthew 9321: =pod
9322:
1.648 raeburn 9323: =item * &load_tmp_file($r)
1.41 ng 9324:
9325: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 9326: needs $env{'form.datatoken'},
9327: sets $env{'form.upfile'} to the contents of the file
1.41 ng 9328:
9329: =cut
1.31 albertel 9330:
9331: sub load_tmp_file {
9332: my $r=shift;
9333: my @studentdata=();
9334: {
1.158 raeburn 9335: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 9336: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 9337: if ( open(my $fh,"<$studentfile") ) {
9338: @studentdata=<$fh>;
9339: close($fh);
9340: }
1.31 albertel 9341: }
1.258 albertel 9342: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 9343: }
9344:
1.56 matthew 9345: =pod
9346:
1.648 raeburn 9347: =item * &upfile_record_sep()
1.41 ng 9348:
9349: Separate uploaded file into records
9350: returns array of records,
1.258 albertel 9351: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 9352:
9353: =cut
1.31 albertel 9354:
9355: sub upfile_record_sep {
1.258 albertel 9356: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 9357: } else {
1.248 albertel 9358: my @records;
1.258 albertel 9359: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 9360: if ($line=~/^\s*$/) { next; }
9361: push(@records,$line);
9362: }
9363: return @records;
1.31 albertel 9364: }
9365: }
9366:
1.56 matthew 9367: =pod
9368:
1.648 raeburn 9369: =item * &record_sep($record)
1.41 ng 9370:
1.258 albertel 9371: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 9372:
9373: =cut
9374:
1.263 www 9375: sub takeleft {
9376: my $index=shift;
9377: return substr('0000'.$index,-4,4);
9378: }
9379:
1.31 albertel 9380: sub record_sep {
9381: my $record=shift;
9382: my %components=();
1.258 albertel 9383: if ($env{'form.upfiletype'} eq 'xml') {
9384: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 9385: my $i=0;
1.356 albertel 9386: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 9387: $field=~s/^(\"|\')//;
9388: $field=~s/(\"|\')$//;
1.263 www 9389: $components{&takeleft($i)}=$field;
1.31 albertel 9390: $i++;
9391: }
1.258 albertel 9392: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 9393: my $i=0;
1.356 albertel 9394: foreach my $field (split(/\t/,$record)) {
1.31 albertel 9395: $field=~s/^(\"|\')//;
9396: $field=~s/(\"|\')$//;
1.263 www 9397: $components{&takeleft($i)}=$field;
1.31 albertel 9398: $i++;
9399: }
9400: } else {
1.561 www 9401: my $separator=',';
1.480 banghart 9402: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 9403: $separator=';';
1.480 banghart 9404: }
1.31 albertel 9405: my $i=0;
1.561 www 9406: # the character we are looking for to indicate the end of a quote or a record
9407: my $looking_for=$separator;
9408: # do not add the characters to the fields
9409: my $ignore=0;
9410: # we just encountered a separator (or the beginning of the record)
9411: my $just_found_separator=1;
9412: # store the field we are working on here
9413: my $field='';
9414: # work our way through all characters in record
9415: foreach my $character ($record=~/(.)/g) {
9416: if ($character eq $looking_for) {
9417: if ($character ne $separator) {
9418: # Found the end of a quote, again looking for separator
9419: $looking_for=$separator;
9420: $ignore=1;
9421: } else {
9422: # Found a separator, store away what we got
9423: $components{&takeleft($i)}=$field;
9424: $i++;
9425: $just_found_separator=1;
9426: $ignore=0;
9427: $field='';
9428: }
9429: next;
9430: }
9431: # single or double quotation marks after a separator indicate beginning of a quote
9432: # we are now looking for the end of the quote and need to ignore separators
9433: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
9434: $looking_for=$character;
9435: next;
9436: }
9437: # ignore would be true after we reached the end of a quote
9438: if ($ignore) { next; }
9439: if (($just_found_separator) && ($character=~/\s/)) { next; }
9440: $field.=$character;
9441: $just_found_separator=0;
1.31 albertel 9442: }
1.561 www 9443: # catch the very last entry, since we never encountered the separator
9444: $components{&takeleft($i)}=$field;
1.31 albertel 9445: }
9446: return %components;
9447: }
9448:
1.144 matthew 9449: ######################################################
9450: ######################################################
9451:
1.56 matthew 9452: =pod
9453:
1.648 raeburn 9454: =item * &upfile_select_html()
1.41 ng 9455:
1.144 matthew 9456: Return HTML code to select a file from the users machine and specify
9457: the file type.
1.41 ng 9458:
9459: =cut
9460:
1.144 matthew 9461: ######################################################
9462: ######################################################
1.31 albertel 9463: sub upfile_select_html {
1.144 matthew 9464: my %Types = (
9465: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 9466: semisv => &mt('Semicolon separated values'),
1.144 matthew 9467: space => &mt('Space separated'),
9468: tab => &mt('Tabulator separated'),
9469: # xml => &mt('HTML/XML'),
9470: );
9471: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 9472: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 9473: foreach my $type (sort(keys(%Types))) {
9474: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
9475: }
9476: $Str .= "</select>\n";
9477: return $Str;
1.31 albertel 9478: }
9479:
1.301 albertel 9480: sub get_samples {
9481: my ($records,$toget) = @_;
9482: my @samples=({});
9483: my $got=0;
9484: foreach my $rec (@$records) {
9485: my %temp = &record_sep($rec);
9486: if (! grep(/\S/, values(%temp))) { next; }
9487: if (%temp) {
9488: $samples[$got]=\%temp;
9489: $got++;
9490: if ($got == $toget) { last; }
9491: }
9492: }
9493: return \@samples;
9494: }
9495:
1.144 matthew 9496: ######################################################
9497: ######################################################
9498:
1.56 matthew 9499: =pod
9500:
1.648 raeburn 9501: =item * &csv_print_samples($r,$records)
1.41 ng 9502:
9503: Prints a table of sample values from each column uploaded $r is an
9504: Apache Request ref, $records is an arrayref from
9505: &Apache::loncommon::upfile_record_sep
9506:
9507: =cut
9508:
1.144 matthew 9509: ######################################################
9510: ######################################################
1.31 albertel 9511: sub csv_print_samples {
9512: my ($r,$records) = @_;
1.662 bisitz 9513: my $samples = &get_samples($records,5);
1.301 albertel 9514:
1.594 raeburn 9515: $r->print(&mt('Samples').'<br />'.&start_data_table().
9516: &start_data_table_header_row());
1.356 albertel 9517: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 9518: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 9519: $r->print(&end_data_table_header_row());
1.301 albertel 9520: foreach my $hash (@$samples) {
1.594 raeburn 9521: $r->print(&start_data_table_row());
1.356 albertel 9522: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 9523: $r->print('<td>');
1.356 albertel 9524: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 9525: $r->print('</td>');
9526: }
1.594 raeburn 9527: $r->print(&end_data_table_row());
1.31 albertel 9528: }
1.594 raeburn 9529: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 9530: }
9531:
1.144 matthew 9532: ######################################################
9533: ######################################################
9534:
1.56 matthew 9535: =pod
9536:
1.648 raeburn 9537: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 9538:
9539: Prints a table to create associations between values and table columns.
1.144 matthew 9540:
1.41 ng 9541: $r is an Apache Request ref,
9542: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 9543: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 9544:
9545: =cut
9546:
1.144 matthew 9547: ######################################################
9548: ######################################################
1.31 albertel 9549: sub csv_print_select_table {
9550: my ($r,$records,$d) = @_;
1.301 albertel 9551: my $i=0;
9552: my $samples = &get_samples($records,1);
1.144 matthew 9553: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 9554: &start_data_table().&start_data_table_header_row().
1.144 matthew 9555: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 9556: '<th>'.&mt('Column').'</th>'.
9557: &end_data_table_header_row()."\n");
1.356 albertel 9558: foreach my $array_ref (@$d) {
9559: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 9560: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 9561:
1.875 bisitz 9562: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 9563: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 9564: $r->print('<option value="none"></option>');
1.356 albertel 9565: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
9566: $r->print('<option value="'.$sample.'"'.
9567: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 9568: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 9569: }
1.594 raeburn 9570: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 9571: $i++;
9572: }
1.594 raeburn 9573: $r->print(&end_data_table());
1.31 albertel 9574: $i--;
9575: return $i;
9576: }
1.56 matthew 9577:
1.144 matthew 9578: ######################################################
9579: ######################################################
9580:
1.56 matthew 9581: =pod
1.31 albertel 9582:
1.648 raeburn 9583: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 9584:
9585: Prints a table of sample values from the upload and can make associate samples to internal names.
9586:
9587: $r is an Apache Request ref,
9588: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
9589: $d is an array of 2 element arrays (internal name, displayed name)
9590:
9591: =cut
9592:
1.144 matthew 9593: ######################################################
9594: ######################################################
1.31 albertel 9595: sub csv_samples_select_table {
9596: my ($r,$records,$d) = @_;
9597: my $i=0;
1.144 matthew 9598: #
1.662 bisitz 9599: my $max_samples = 5;
9600: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 9601: $r->print(&start_data_table().
9602: &start_data_table_header_row().'<th>'.
9603: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
9604: &end_data_table_header_row());
1.301 albertel 9605:
9606: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 9607: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 9608: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 9609: foreach my $option (@$d) {
9610: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 9611: $r->print('<option value="'.$value.'"'.
1.253 albertel 9612: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 9613: $display.'</option>');
1.31 albertel 9614: }
9615: $r->print('</select></td><td>');
1.662 bisitz 9616: foreach my $line (0..($max_samples-1)) {
1.301 albertel 9617: if (defined($samples->[$line]{$key})) {
9618: $r->print($samples->[$line]{$key}."<br />\n");
9619: }
9620: }
1.594 raeburn 9621: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9622: $i++;
9623: }
1.594 raeburn 9624: $r->print(&end_data_table());
1.31 albertel 9625: $i--;
9626: return($i);
1.115 matthew 9627: }
9628:
1.144 matthew 9629: ######################################################
9630: ######################################################
9631:
1.115 matthew 9632: =pod
9633:
1.648 raeburn 9634: =item * &clean_excel_name($name)
1.115 matthew 9635:
9636: Returns a replacement for $name which does not contain any illegal characters.
9637:
9638: =cut
9639:
1.144 matthew 9640: ######################################################
9641: ######################################################
1.115 matthew 9642: sub clean_excel_name {
9643: my ($name) = @_;
9644: $name =~ s/[:\*\?\/\\]//g;
9645: if (length($name) > 31) {
9646: $name = substr($name,0,31);
9647: }
9648: return $name;
1.25 albertel 9649: }
1.84 albertel 9650:
1.85 albertel 9651: =pod
9652:
1.648 raeburn 9653: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9654:
9655: Returns either 1 or undef
9656:
9657: 1 if the part is to be hidden, undef if it is to be shown
9658:
9659: Arguments are:
9660:
9661: $id the id of the part to be checked
9662: $symb, optional the symb of the resource to check
9663: $udom, optional the domain of the user to check for
9664: $uname, optional the username of the user to check for
9665:
9666: =cut
1.84 albertel 9667:
9668: sub check_if_partid_hidden {
9669: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9670: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9671: $symb,$udom,$uname);
1.141 albertel 9672: my $truth=1;
9673: #if the string starts with !, then the list is the list to show not hide
9674: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9675: my @hiddenlist=split(/,/,$hiddenparts);
9676: foreach my $checkid (@hiddenlist) {
1.141 albertel 9677: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9678: }
1.141 albertel 9679: return !$truth;
1.84 albertel 9680: }
1.127 matthew 9681:
1.138 matthew 9682:
9683: ############################################################
9684: ############################################################
9685:
9686: =pod
9687:
1.157 matthew 9688: =back
9689:
1.138 matthew 9690: =head1 cgi-bin script and graphing routines
9691:
1.157 matthew 9692: =over 4
9693:
1.648 raeburn 9694: =item * &get_cgi_id()
1.138 matthew 9695:
9696: Inputs: none
9697:
9698: Returns an id which can be used to pass environment variables
9699: to various cgi-bin scripts. These environment variables will
9700: be removed from the users environment after a given time by
9701: the routine &Apache::lonnet::transfer_profile_to_env.
9702:
9703: =cut
9704:
9705: ############################################################
9706: ############################################################
1.152 albertel 9707: my $uniq=0;
1.136 matthew 9708: sub get_cgi_id {
1.154 albertel 9709: $uniq=($uniq+1)%100000;
1.280 albertel 9710: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9711: }
9712:
1.127 matthew 9713: ############################################################
9714: ############################################################
9715:
9716: =pod
9717:
1.648 raeburn 9718: =item * &DrawBarGraph()
1.127 matthew 9719:
1.138 matthew 9720: Facilitates the plotting of data in a (stacked) bar graph.
9721: Puts plot definition data into the users environment in order for
9722: graph.png to plot it. Returns an <img> tag for the plot.
9723: The bars on the plot are labeled '1','2',...,'n'.
9724:
9725: Inputs:
9726:
9727: =over 4
9728:
9729: =item $Title: string, the title of the plot
9730:
9731: =item $xlabel: string, text describing the X-axis of the plot
9732:
9733: =item $ylabel: string, text describing the Y-axis of the plot
9734:
9735: =item $Max: scalar, the maximum Y value to use in the plot
9736: If $Max is < any data point, the graph will not be rendered.
9737:
1.140 matthew 9738: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9739: they are plotted. If undefined, default values will be used.
9740:
1.178 matthew 9741: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9742:
1.138 matthew 9743: =item @Values: An array of array references. Each array reference holds data
9744: to be plotted in a stacked bar chart.
9745:
1.239 matthew 9746: =item If the final element of @Values is a hash reference the key/value
9747: pairs will be added to the graph definition.
9748:
1.138 matthew 9749: =back
9750:
9751: Returns:
9752:
9753: An <img> tag which references graph.png and the appropriate identifying
9754: information for the plot.
9755:
1.127 matthew 9756: =cut
9757:
9758: ############################################################
9759: ############################################################
1.134 matthew 9760: sub DrawBarGraph {
1.178 matthew 9761: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9762: #
9763: if (! defined($colors)) {
9764: $colors = ['#33ff00',
9765: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9766: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9767: ];
9768: }
1.228 matthew 9769: my $extra_settings = {};
9770: if (ref($Values[-1]) eq 'HASH') {
9771: $extra_settings = pop(@Values);
9772: }
1.127 matthew 9773: #
1.136 matthew 9774: my $identifier = &get_cgi_id();
9775: my $id = 'cgi.'.$identifier;
1.129 matthew 9776: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9777: return '';
9778: }
1.225 matthew 9779: #
9780: my @Labels;
9781: if (defined($labels)) {
9782: @Labels = @$labels;
9783: } else {
9784: for (my $i=0;$i<@{$Values[0]};$i++) {
9785: push (@Labels,$i+1);
9786: }
9787: }
9788: #
1.129 matthew 9789: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9790: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9791: my %ValuesHash;
9792: my $NumSets=1;
9793: foreach my $array (@Values) {
9794: next if (! ref($array));
1.136 matthew 9795: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9796: join(',',@$array);
1.129 matthew 9797: }
1.127 matthew 9798: #
1.136 matthew 9799: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9800: if ($NumBars < 3) {
9801: $width = 120+$NumBars*32;
1.220 matthew 9802: $xskip = 1;
1.225 matthew 9803: $bar_width = 30;
9804: } elsif ($NumBars < 5) {
9805: $width = 120+$NumBars*20;
9806: $xskip = 1;
9807: $bar_width = 20;
1.220 matthew 9808: } elsif ($NumBars < 10) {
1.136 matthew 9809: $width = 120+$NumBars*15;
9810: $xskip = 1;
9811: $bar_width = 15;
9812: } elsif ($NumBars <= 25) {
9813: $width = 120+$NumBars*11;
9814: $xskip = 5;
9815: $bar_width = 8;
9816: } elsif ($NumBars <= 50) {
9817: $width = 120+$NumBars*8;
9818: $xskip = 5;
9819: $bar_width = 4;
9820: } else {
9821: $width = 120+$NumBars*8;
9822: $xskip = 5;
9823: $bar_width = 4;
9824: }
9825: #
1.137 matthew 9826: $Max = 1 if ($Max < 1);
9827: if ( int($Max) < $Max ) {
9828: $Max++;
9829: $Max = int($Max);
9830: }
1.127 matthew 9831: $Title = '' if (! defined($Title));
9832: $xlabel = '' if (! defined($xlabel));
9833: $ylabel = '' if (! defined($ylabel));
1.369 www 9834: $ValuesHash{$id.'.title'} = &escape($Title);
9835: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9836: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9837: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9838: $ValuesHash{$id.'.NumBars'} = $NumBars;
9839: $ValuesHash{$id.'.NumSets'} = $NumSets;
9840: $ValuesHash{$id.'.PlotType'} = 'bar';
9841: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9842: $ValuesHash{$id.'.height'} = $height;
9843: $ValuesHash{$id.'.width'} = $width;
9844: $ValuesHash{$id.'.xskip'} = $xskip;
9845: $ValuesHash{$id.'.bar_width'} = $bar_width;
9846: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9847: #
1.228 matthew 9848: # Deal with other parameters
9849: while (my ($key,$value) = each(%$extra_settings)) {
9850: $ValuesHash{$id.'.'.$key} = $value;
9851: }
9852: #
1.646 raeburn 9853: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9854: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9855: }
9856:
9857: ############################################################
9858: ############################################################
9859:
9860: =pod
9861:
1.648 raeburn 9862: =item * &DrawXYGraph()
1.137 matthew 9863:
1.138 matthew 9864: Facilitates the plotting of data in an XY graph.
9865: Puts plot definition data into the users environment in order for
9866: graph.png to plot it. Returns an <img> tag for the plot.
9867:
9868: Inputs:
9869:
9870: =over 4
9871:
9872: =item $Title: string, the title of the plot
9873:
9874: =item $xlabel: string, text describing the X-axis of the plot
9875:
9876: =item $ylabel: string, text describing the Y-axis of the plot
9877:
9878: =item $Max: scalar, the maximum Y value to use in the plot
9879: If $Max is < any data point, the graph will not be rendered.
9880:
9881: =item $colors: Array ref containing the hex color codes for the data to be
9882: plotted in. If undefined, default values will be used.
9883:
9884: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9885:
9886: =item $Ydata: Array ref containing Array refs.
1.185 www 9887: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9888:
9889: =item %Values: hash indicating or overriding any default values which are
9890: passed to graph.png.
9891: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9892:
9893: =back
9894:
9895: Returns:
9896:
9897: An <img> tag which references graph.png and the appropriate identifying
9898: information for the plot.
9899:
1.137 matthew 9900: =cut
9901:
9902: ############################################################
9903: ############################################################
9904: sub DrawXYGraph {
9905: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9906: #
9907: # Create the identifier for the graph
9908: my $identifier = &get_cgi_id();
9909: my $id = 'cgi.'.$identifier;
9910: #
9911: $Title = '' if (! defined($Title));
9912: $xlabel = '' if (! defined($xlabel));
9913: $ylabel = '' if (! defined($ylabel));
9914: my %ValuesHash =
9915: (
1.369 www 9916: $id.'.title' => &escape($Title),
9917: $id.'.xlabel' => &escape($xlabel),
9918: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9919: $id.'.y_max_value'=> $Max,
9920: $id.'.labels' => join(',',@$Xlabels),
9921: $id.'.PlotType' => 'XY',
9922: );
9923: #
9924: if (defined($colors) && ref($colors) eq 'ARRAY') {
9925: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9926: }
9927: #
9928: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9929: return '';
9930: }
9931: my $NumSets=1;
1.138 matthew 9932: foreach my $array (@{$Ydata}){
1.137 matthew 9933: next if (! ref($array));
9934: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9935: }
1.138 matthew 9936: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9937: #
9938: # Deal with other parameters
9939: while (my ($key,$value) = each(%Values)) {
9940: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9941: }
9942: #
1.646 raeburn 9943: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9944: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9945: }
9946:
9947: ############################################################
9948: ############################################################
9949:
9950: =pod
9951:
1.648 raeburn 9952: =item * &DrawXYYGraph()
1.138 matthew 9953:
9954: Facilitates the plotting of data in an XY graph with two Y axes.
9955: Puts plot definition data into the users environment in order for
9956: graph.png to plot it. Returns an <img> tag for the plot.
9957:
9958: Inputs:
9959:
9960: =over 4
9961:
9962: =item $Title: string, the title of the plot
9963:
9964: =item $xlabel: string, text describing the X-axis of the plot
9965:
9966: =item $ylabel: string, text describing the Y-axis of the plot
9967:
9968: =item $colors: Array ref containing the hex color codes for the data to be
9969: plotted in. If undefined, default values will be used.
9970:
9971: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9972:
9973: =item $Ydata1: The first data set
9974:
9975: =item $Min1: The minimum value of the left Y-axis
9976:
9977: =item $Max1: The maximum value of the left Y-axis
9978:
9979: =item $Ydata2: The second data set
9980:
9981: =item $Min2: The minimum value of the right Y-axis
9982:
9983: =item $Max2: The maximum value of the left Y-axis
9984:
9985: =item %Values: hash indicating or overriding any default values which are
9986: passed to graph.png.
9987: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9988:
9989: =back
9990:
9991: Returns:
9992:
9993: An <img> tag which references graph.png and the appropriate identifying
9994: information for the plot.
1.136 matthew 9995:
9996: =cut
9997:
9998: ############################################################
9999: ############################################################
1.137 matthew 10000: sub DrawXYYGraph {
10001: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
10002: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 10003: #
10004: # Create the identifier for the graph
10005: my $identifier = &get_cgi_id();
10006: my $id = 'cgi.'.$identifier;
10007: #
10008: $Title = '' if (! defined($Title));
10009: $xlabel = '' if (! defined($xlabel));
10010: $ylabel = '' if (! defined($ylabel));
10011: my %ValuesHash =
10012: (
1.369 www 10013: $id.'.title' => &escape($Title),
10014: $id.'.xlabel' => &escape($xlabel),
10015: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 10016: $id.'.labels' => join(',',@$Xlabels),
10017: $id.'.PlotType' => 'XY',
10018: $id.'.NumSets' => 2,
1.137 matthew 10019: $id.'.two_axes' => 1,
10020: $id.'.y1_max_value' => $Max1,
10021: $id.'.y1_min_value' => $Min1,
10022: $id.'.y2_max_value' => $Max2,
10023: $id.'.y2_min_value' => $Min2,
1.136 matthew 10024: );
10025: #
1.137 matthew 10026: if (defined($colors) && ref($colors) eq 'ARRAY') {
10027: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
10028: }
10029: #
10030: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
10031: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 10032: return '';
10033: }
10034: my $NumSets=1;
1.137 matthew 10035: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 10036: next if (! ref($array));
10037: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 10038: }
10039: #
10040: # Deal with other parameters
10041: while (my ($key,$value) = each(%Values)) {
10042: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 10043: }
10044: #
1.646 raeburn 10045: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 10046: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 10047: }
10048:
10049: ############################################################
10050: ############################################################
10051:
10052: =pod
10053:
1.157 matthew 10054: =back
10055:
1.139 matthew 10056: =head1 Statistics helper routines?
10057:
10058: Bad place for them but what the hell.
10059:
1.157 matthew 10060: =over 4
10061:
1.648 raeburn 10062: =item * &chartlink()
1.139 matthew 10063:
10064: Returns a link to the chart for a specific student.
10065:
10066: Inputs:
10067:
10068: =over 4
10069:
10070: =item $linktext: The text of the link
10071:
10072: =item $sname: The students username
10073:
10074: =item $sdomain: The students domain
10075:
10076: =back
10077:
1.157 matthew 10078: =back
10079:
1.139 matthew 10080: =cut
10081:
10082: ############################################################
10083: ############################################################
10084: sub chartlink {
10085: my ($linktext, $sname, $sdomain) = @_;
10086: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 10087: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 10088: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 10089: '">'.$linktext.'</a>';
1.153 matthew 10090: }
10091:
10092: #######################################################
10093: #######################################################
10094:
10095: =pod
10096:
10097: =head1 Course Environment Routines
1.157 matthew 10098:
10099: =over 4
1.153 matthew 10100:
1.648 raeburn 10101: =item * &restore_course_settings()
1.153 matthew 10102:
1.648 raeburn 10103: =item * &store_course_settings()
1.153 matthew 10104:
10105: Restores/Store indicated form parameters from the course environment.
10106: Will not overwrite existing values of the form parameters.
10107:
10108: Inputs:
10109: a scalar describing the data (e.g. 'chart', 'problem_analysis')
10110:
10111: a hash ref describing the data to be stored. For example:
10112:
10113: %Save_Parameters = ('Status' => 'scalar',
10114: 'chartoutputmode' => 'scalar',
10115: 'chartoutputdata' => 'scalar',
10116: 'Section' => 'array',
1.373 raeburn 10117: 'Group' => 'array',
1.153 matthew 10118: 'StudentData' => 'array',
10119: 'Maps' => 'array');
10120:
10121: Returns: both routines return nothing
10122:
1.631 raeburn 10123: =back
10124:
1.153 matthew 10125: =cut
10126:
10127: #######################################################
10128: #######################################################
10129: sub store_course_settings {
1.496 albertel 10130: return &store_settings($env{'request.course.id'},@_);
10131: }
10132:
10133: sub store_settings {
1.153 matthew 10134: # save to the environment
10135: # appenv the same items, just to be safe
1.300 albertel 10136: my $udom = $env{'user.domain'};
10137: my $uname = $env{'user.name'};
1.496 albertel 10138: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10139: my %SaveHash;
10140: my %AppHash;
10141: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 10142: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 10143: my $envname = 'environment.'.$basename;
1.258 albertel 10144: if (exists($env{'form.'.$setting})) {
1.153 matthew 10145: # Save this value away
10146: if ($type eq 'scalar' &&
1.258 albertel 10147: (! exists($env{$envname}) ||
10148: $env{$envname} ne $env{'form.'.$setting})) {
10149: $SaveHash{$basename} = $env{'form.'.$setting};
10150: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 10151: } elsif ($type eq 'array') {
10152: my $stored_form;
1.258 albertel 10153: if (ref($env{'form.'.$setting})) {
1.153 matthew 10154: $stored_form = join(',',
10155: map {
1.369 www 10156: &escape($_);
1.258 albertel 10157: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 10158: } else {
10159: $stored_form =
1.369 www 10160: &escape($env{'form.'.$setting});
1.153 matthew 10161: }
10162: # Determine if the array contents are the same.
1.258 albertel 10163: if ($stored_form ne $env{$envname}) {
1.153 matthew 10164: $SaveHash{$basename} = $stored_form;
10165: $AppHash{$envname} = $stored_form;
10166: }
10167: }
10168: }
10169: }
10170: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 10171: $udom,$uname);
1.153 matthew 10172: if ($put_result !~ /^(ok|delayed)/) {
10173: &Apache::lonnet::logthis('unable to save form parameters, '.
10174: 'got error:'.$put_result);
10175: }
10176: # Make sure these settings stick around in this session, too
1.646 raeburn 10177: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 10178: return;
10179: }
10180:
10181: sub restore_course_settings {
1.499 albertel 10182: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 10183: }
10184:
10185: sub restore_settings {
10186: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10187: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 10188: next if (exists($env{'form.'.$setting}));
1.496 albertel 10189: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 10190: '.'.$setting;
1.258 albertel 10191: if (exists($env{$envname})) {
1.153 matthew 10192: if ($type eq 'scalar') {
1.258 albertel 10193: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 10194: } elsif ($type eq 'array') {
1.258 albertel 10195: $env{'form.'.$setting} = [
1.153 matthew 10196: map {
1.369 www 10197: &unescape($_);
1.258 albertel 10198: } split(',',$env{$envname})
1.153 matthew 10199: ];
10200: }
10201: }
10202: }
1.127 matthew 10203: }
10204:
1.618 raeburn 10205: #######################################################
10206: #######################################################
10207:
10208: =pod
10209:
10210: =head1 Domain E-mail Routines
10211:
10212: =over 4
10213:
1.648 raeburn 10214: =item * &build_recipient_list()
1.618 raeburn 10215:
1.884 raeburn 10216: Build recipient lists for five types of e-mail:
1.766 raeburn 10217: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 10218: (d) Help requests, (e) Course requests needing approval, generated by
10219: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
10220: loncoursequeueadmin.pm respectively.
1.618 raeburn 10221:
10222: Inputs:
1.619 raeburn 10223: defmail (scalar - email address of default recipient),
1.618 raeburn 10224: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 10225: defdom (domain for which to retrieve configuration settings),
10226: origmail (scalar - email address of recipient from loncapa.conf,
10227: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 10228:
1.655 raeburn 10229: Returns: comma separated list of addresses to which to send e-mail.
10230:
10231: =back
1.618 raeburn 10232:
10233: =cut
10234:
10235: ############################################################
10236: ############################################################
10237: sub build_recipient_list {
1.619 raeburn 10238: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 10239: my @recipients;
10240: my $otheremails;
10241: my %domconfig =
10242: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
10243: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 10244: if (exists($domconfig{'contacts'}{$mailing})) {
10245: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
10246: my @contacts = ('adminemail','supportemail');
10247: foreach my $item (@contacts) {
10248: if ($domconfig{'contacts'}{$mailing}{$item}) {
10249: my $addr = $domconfig{'contacts'}{$item};
10250: if (!grep(/^\Q$addr\E$/,@recipients)) {
10251: push(@recipients,$addr);
10252: }
1.619 raeburn 10253: }
1.766 raeburn 10254: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 10255: }
10256: }
1.766 raeburn 10257: } elsif ($origmail ne '') {
10258: push(@recipients,$origmail);
1.618 raeburn 10259: }
1.619 raeburn 10260: } elsif ($origmail ne '') {
10261: push(@recipients,$origmail);
1.618 raeburn 10262: }
1.688 raeburn 10263: if (defined($defmail)) {
10264: if ($defmail ne '') {
10265: push(@recipients,$defmail);
10266: }
1.618 raeburn 10267: }
10268: if ($otheremails) {
1.619 raeburn 10269: my @others;
10270: if ($otheremails =~ /,/) {
10271: @others = split(/,/,$otheremails);
1.618 raeburn 10272: } else {
1.619 raeburn 10273: push(@others,$otheremails);
10274: }
10275: foreach my $addr (@others) {
10276: if (!grep(/^\Q$addr\E$/,@recipients)) {
10277: push(@recipients,$addr);
10278: }
1.618 raeburn 10279: }
10280: }
1.619 raeburn 10281: my $recipientlist = join(',',@recipients);
1.618 raeburn 10282: return $recipientlist;
10283: }
10284:
1.127 matthew 10285: ############################################################
10286: ############################################################
1.154 albertel 10287:
1.655 raeburn 10288: =pod
10289:
10290: =head1 Course Catalog Routines
10291:
10292: =over 4
10293:
10294: =item * &gather_categories()
10295:
10296: Converts category definitions - keys of categories hash stored in
10297: coursecategories in configuration.db on the primary library server in a
10298: domain - to an array. Also generates javascript and idx hash used to
10299: generate Domain Coordinator interface for editing Course Categories.
10300:
10301: Inputs:
1.663 raeburn 10302:
1.655 raeburn 10303: categories (reference to hash of category definitions).
1.663 raeburn 10304:
1.655 raeburn 10305: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10306: categories and subcategories).
1.663 raeburn 10307:
1.655 raeburn 10308: idx (reference to hash of counters used in Domain Coordinator interface for
10309: editing Course Categories).
1.663 raeburn 10310:
1.655 raeburn 10311: jsarray (reference to array of categories used to create Javascript arrays for
10312: Domain Coordinator interface for editing Course Categories).
10313:
10314: Returns: nothing
10315:
10316: Side effects: populates cats, idx and jsarray.
10317:
10318: =cut
10319:
10320: sub gather_categories {
10321: my ($categories,$cats,$idx,$jsarray) = @_;
10322: my %counters;
10323: my $num = 0;
10324: foreach my $item (keys(%{$categories})) {
10325: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10326: if ($container eq '' && $depth == 0) {
10327: $cats->[$depth][$categories->{$item}] = $cat;
10328: } else {
10329: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
10330: }
10331: my ($escitem,$tail) = split(/:/,$item,2);
10332: if ($counters{$tail} eq '') {
10333: $counters{$tail} = $num;
10334: $num ++;
10335: }
10336: if (ref($idx) eq 'HASH') {
10337: $idx->{$item} = $counters{$tail};
10338: }
10339: if (ref($jsarray) eq 'ARRAY') {
10340: push(@{$jsarray->[$counters{$tail}]},$item);
10341: }
10342: }
10343: return;
10344: }
10345:
10346: =pod
10347:
10348: =item * &extract_categories()
10349:
10350: Used to generate breadcrumb trails for course categories.
10351:
10352: Inputs:
1.663 raeburn 10353:
1.655 raeburn 10354: categories (reference to hash of category definitions).
1.663 raeburn 10355:
1.655 raeburn 10356: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10357: categories and subcategories).
1.663 raeburn 10358:
1.655 raeburn 10359: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 10360:
1.655 raeburn 10361: allitems (reference to hash - key is category key
10362: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10363:
1.655 raeburn 10364: idx (reference to hash of counters used in Domain Coordinator interface for
10365: editing Course Categories).
1.663 raeburn 10366:
1.655 raeburn 10367: jsarray (reference to array of categories used to create Javascript arrays for
10368: Domain Coordinator interface for editing Course Categories).
10369:
1.665 raeburn 10370: subcats (reference to hash of arrays containing all subcategories within each
10371: category, -recursive)
10372:
1.655 raeburn 10373: Returns: nothing
10374:
10375: Side effects: populates trails and allitems hash references.
10376:
10377: =cut
10378:
10379: sub extract_categories {
1.665 raeburn 10380: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 10381: if (ref($categories) eq 'HASH') {
10382: &gather_categories($categories,$cats,$idx,$jsarray);
10383: if (ref($cats->[0]) eq 'ARRAY') {
10384: for (my $i=0; $i<@{$cats->[0]}; $i++) {
10385: my $name = $cats->[0][$i];
10386: my $item = &escape($name).'::0';
10387: my $trailstr;
10388: if ($name eq 'instcode') {
10389: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 10390: } elsif ($name eq 'communities') {
10391: $trailstr = &mt('Communities');
1.655 raeburn 10392: } else {
10393: $trailstr = $name;
10394: }
10395: if ($allitems->{$item} eq '') {
10396: push(@{$trails},$trailstr);
10397: $allitems->{$item} = scalar(@{$trails})-1;
10398: }
10399: my @parents = ($name);
10400: if (ref($cats->[1]{$name}) eq 'ARRAY') {
10401: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
10402: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 10403: if (ref($subcats) eq 'HASH') {
10404: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
10405: }
10406: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
10407: }
10408: } else {
10409: if (ref($subcats) eq 'HASH') {
10410: $subcats->{$item} = [];
1.655 raeburn 10411: }
10412: }
10413: }
10414: }
10415: }
10416: return;
10417: }
10418:
10419: =pod
10420:
10421: =item *&recurse_categories()
10422:
10423: Recursively used to generate breadcrumb trails for course categories.
10424:
10425: Inputs:
1.663 raeburn 10426:
1.655 raeburn 10427: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10428: categories and subcategories).
1.663 raeburn 10429:
1.655 raeburn 10430: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 10431:
10432: category (current course category, for which breadcrumb trail is being generated).
10433:
10434: trails (reference to array of breadcrumb trails for each category).
10435:
1.655 raeburn 10436: allitems (reference to hash - key is category key
10437: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10438:
1.655 raeburn 10439: parents (array containing containers directories for current category,
10440: back to top level).
10441:
10442: Returns: nothing
10443:
10444: Side effects: populates trails and allitems hash references
10445:
10446: =cut
10447:
10448: sub recurse_categories {
1.665 raeburn 10449: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 10450: my $shallower = $depth - 1;
10451: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
10452: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
10453: my $name = $cats->[$depth]{$category}[$k];
10454: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10455: my $trailstr = join(' -> ',(@{$parents},$category));
10456: if ($allitems->{$item} eq '') {
10457: push(@{$trails},$trailstr);
10458: $allitems->{$item} = scalar(@{$trails})-1;
10459: }
10460: my $deeper = $depth+1;
10461: push(@{$parents},$category);
1.665 raeburn 10462: if (ref($subcats) eq 'HASH') {
10463: my $subcat = &escape($name).':'.$category.':'.$depth;
10464: for (my $j=@{$parents}; $j>=0; $j--) {
10465: my $higher;
10466: if ($j > 0) {
10467: $higher = &escape($parents->[$j]).':'.
10468: &escape($parents->[$j-1]).':'.$j;
10469: } else {
10470: $higher = &escape($parents->[$j]).'::'.$j;
10471: }
10472: push(@{$subcats->{$higher}},$subcat);
10473: }
10474: }
10475: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
10476: $subcats);
1.655 raeburn 10477: pop(@{$parents});
10478: }
10479: } else {
10480: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10481: my $trailstr = join(' -> ',(@{$parents},$category));
10482: if ($allitems->{$item} eq '') {
10483: push(@{$trails},$trailstr);
10484: $allitems->{$item} = scalar(@{$trails})-1;
10485: }
10486: }
10487: return;
10488: }
10489:
1.663 raeburn 10490: =pod
10491:
10492: =item *&assign_categories_table()
10493:
10494: Create a datatable for display of hierarchical categories in a domain,
10495: with checkboxes to allow a course to be categorized.
10496:
10497: Inputs:
10498:
10499: cathash - reference to hash of categories defined for the domain (from
10500: configuration.db)
10501:
10502: currcat - scalar with an & separated list of categories assigned to a course.
10503:
1.919 raeburn 10504: type - scalar contains course type (Course or Community).
10505:
1.663 raeburn 10506: Returns: $output (markup to be displayed)
10507:
10508: =cut
10509:
10510: sub assign_categories_table {
1.919 raeburn 10511: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 10512: my $output;
10513: if (ref($cathash) eq 'HASH') {
10514: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
10515: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
10516: $maxdepth = scalar(@cats);
10517: if (@cats > 0) {
10518: my $itemcount = 0;
10519: if (ref($cats[0]) eq 'ARRAY') {
10520: my @currcategories;
10521: if ($currcat ne '') {
10522: @currcategories = split('&',$currcat);
10523: }
1.919 raeburn 10524: my $table;
1.663 raeburn 10525: for (my $i=0; $i<@{$cats[0]}; $i++) {
10526: my $parent = $cats[0][$i];
1.919 raeburn 10527: next if ($parent eq 'instcode');
10528: if ($type eq 'Community') {
10529: next unless ($parent eq 'communities');
10530: } else {
10531: next if ($parent eq 'communities');
10532: }
1.663 raeburn 10533: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10534: my $item = &escape($parent).'::0';
10535: my $checked = '';
10536: if (@currcategories > 0) {
10537: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 10538: $checked = ' checked="checked"';
1.663 raeburn 10539: }
10540: }
1.919 raeburn 10541: my $parent_title = $parent;
10542: if ($parent eq 'communities') {
10543: $parent_title = &mt('Communities');
10544: }
10545: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
10546: '<input type="checkbox" name="usecategory" value="'.
10547: $item.'"'.$checked.' />'.$parent_title.'</span>'.
10548: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 10549: my $depth = 1;
10550: push(@path,$parent);
1.919 raeburn 10551: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 10552: pop(@path);
1.919 raeburn 10553: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 10554: $itemcount ++;
10555: }
1.919 raeburn 10556: if ($itemcount) {
10557: $output = &Apache::loncommon::start_data_table().
10558: $table.
10559: &Apache::loncommon::end_data_table();
10560: }
1.663 raeburn 10561: }
10562: }
10563: }
10564: return $output;
10565: }
10566:
10567: =pod
10568:
10569: =item *&assign_category_rows()
10570:
10571: Create a datatable row for display of nested categories in a domain,
10572: with checkboxes to allow a course to be categorized,called recursively.
10573:
10574: Inputs:
10575:
10576: itemcount - track row number for alternating colors
10577:
10578: cats - reference to array of arrays/hashes which encapsulates hierarchy of
10579: categories and subcategories.
10580:
10581: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
10582:
10583: parent - parent of current category item
10584:
10585: path - Array containing all categories back up through the hierarchy from the
10586: current category to the top level.
10587:
10588: currcategories - reference to array of current categories assigned to the course
10589:
10590: Returns: $output (markup to be displayed).
10591:
10592: =cut
10593:
10594: sub assign_category_rows {
10595: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
10596: my ($text,$name,$item,$chgstr);
10597: if (ref($cats) eq 'ARRAY') {
10598: my $maxdepth = scalar(@{$cats});
10599: if (ref($cats->[$depth]) eq 'HASH') {
10600: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10601: my $numchildren = @{$cats->[$depth]{$parent}};
10602: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10603: $text .= '<td><table class="LC_datatable">';
10604: for (my $j=0; $j<$numchildren; $j++) {
10605: $name = $cats->[$depth]{$parent}[$j];
10606: $item = &escape($name).':'.&escape($parent).':'.$depth;
10607: my $deeper = $depth+1;
10608: my $checked = '';
10609: if (ref($currcategories) eq 'ARRAY') {
10610: if (@{$currcategories} > 0) {
10611: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 10612: $checked = ' checked="checked"';
1.663 raeburn 10613: }
10614: }
10615: }
1.664 raeburn 10616: $text .= '<tr><td><span class="LC_nobreak"><label>'.
10617: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 10618: $item.'"'.$checked.' />'.$name.'</label></span>'.
10619: '<input type="hidden" name="catname" value="'.$name.'" />'.
10620: '</td><td>';
1.663 raeburn 10621: if (ref($path) eq 'ARRAY') {
10622: push(@{$path},$name);
10623: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10624: pop(@{$path});
10625: }
10626: $text .= '</td></tr>';
10627: }
10628: $text .= '</table></td>';
10629: }
10630: }
10631: }
10632: return $text;
10633: }
10634:
1.655 raeburn 10635: ############################################################
10636: ############################################################
10637:
10638:
1.443 albertel 10639: sub commit_customrole {
1.664 raeburn 10640: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10641: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10642: ($start?', '.&mt('starting').' '.localtime($start):'').
10643: ($end?', ending '.localtime($end):'').': <b>'.
10644: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10645: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10646: '</b><br />';
10647: return $output;
10648: }
10649:
10650: sub commit_standardrole {
1.541 raeburn 10651: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10652: my ($output,$logmsg,$linefeed);
10653: if ($context eq 'auto') {
10654: $linefeed = "\n";
10655: } else {
10656: $linefeed = "<br />\n";
10657: }
1.443 albertel 10658: if ($three eq 'st') {
1.541 raeburn 10659: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10660: $one,$two,$sec,$context);
10661: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10662: ($result eq 'unknown_course') || ($result eq 'refused')) {
10663: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10664: } else {
1.541 raeburn 10665: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10666: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10667: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10668: if ($context eq 'auto') {
10669: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10670: } else {
10671: $output .= '<b>'.$result.'</b>'.$linefeed.
10672: &mt('Add to classlist').': <b>ok</b>';
10673: }
10674: $output .= $linefeed;
1.443 albertel 10675: }
10676: } else {
10677: $output = &mt('Assigning').' '.$three.' in '.$url.
10678: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10679: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10680: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10681: if ($context eq 'auto') {
10682: $output .= $result.$linefeed;
10683: } else {
10684: $output .= '<b>'.$result.'</b>'.$linefeed;
10685: }
1.443 albertel 10686: }
10687: return $output;
10688: }
10689:
10690: sub commit_studentrole {
1.541 raeburn 10691: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10692: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10693: if ($context eq 'auto') {
10694: $linefeed = "\n";
10695: } else {
10696: $linefeed = '<br />'."\n";
10697: }
1.443 albertel 10698: if (defined($one) && defined($two)) {
10699: my $cid=$one.'_'.$two;
10700: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10701: my $secchange = 0;
10702: my $expire_role_result;
10703: my $modify_section_result;
1.628 raeburn 10704: if ($oldsec ne '-1') {
10705: if ($oldsec ne $sec) {
1.443 albertel 10706: $secchange = 1;
1.628 raeburn 10707: my $now = time;
1.443 albertel 10708: my $uurl='/'.$cid;
10709: $uurl=~s/\_/\//g;
10710: if ($oldsec) {
10711: $uurl.='/'.$oldsec;
10712: }
1.626 raeburn 10713: $oldsecurl = $uurl;
1.628 raeburn 10714: $expire_role_result =
1.652 raeburn 10715: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10716: if ($env{'request.course.sec'} ne '') {
10717: if ($expire_role_result eq 'refused') {
10718: my @roles = ('st');
10719: my @statuses = ('previous');
10720: my @roledoms = ($one);
10721: my $withsec = 1;
10722: my %roleshash =
10723: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10724: \@statuses,\@roles,\@roledoms,$withsec);
10725: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10726: my ($oldstart,$oldend) =
10727: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10728: if ($oldend > 0 && $oldend <= $now) {
10729: $expire_role_result = 'ok';
10730: }
10731: }
10732: }
10733: }
1.443 albertel 10734: $result = $expire_role_result;
10735: }
10736: }
10737: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10738: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10739: if ($modify_section_result =~ /^ok/) {
10740: if ($secchange == 1) {
1.628 raeburn 10741: if ($sec eq '') {
10742: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10743: } else {
10744: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10745: }
1.443 albertel 10746: } elsif ($oldsec eq '-1') {
1.628 raeburn 10747: if ($sec eq '') {
10748: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10749: } else {
10750: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10751: }
1.443 albertel 10752: } else {
1.628 raeburn 10753: if ($sec eq '') {
10754: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10755: } else {
10756: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10757: }
1.443 albertel 10758: }
10759: } else {
1.628 raeburn 10760: if ($secchange) {
10761: $$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;
10762: } else {
10763: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10764: }
1.443 albertel 10765: }
10766: $result = $modify_section_result;
10767: } elsif ($secchange == 1) {
1.628 raeburn 10768: if ($oldsec eq '') {
10769: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10770: } else {
10771: $$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;
10772: }
1.626 raeburn 10773: if ($expire_role_result eq 'refused') {
10774: my $newsecurl = '/'.$cid;
10775: $newsecurl =~ s/\_/\//g;
10776: if ($sec ne '') {
10777: $newsecurl.='/'.$sec;
10778: }
10779: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10780: if ($sec eq '') {
10781: $$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;
10782: } else {
10783: $$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;
10784: }
10785: }
10786: }
1.443 albertel 10787: }
10788: } else {
1.626 raeburn 10789: $$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 10790: $result = "error: incomplete course id\n";
10791: }
10792: return $result;
10793: }
10794:
10795: ############################################################
10796: ############################################################
10797:
1.566 albertel 10798: sub check_clone {
1.578 raeburn 10799: my ($args,$linefeed) = @_;
1.566 albertel 10800: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10801: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10802: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10803: my $clonemsg;
10804: my $can_clone = 0;
1.944 raeburn 10805: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10806: if ($lctype ne 'community') {
10807: $lctype = 'course';
10808: }
1.566 albertel 10809: if ($clonehome eq 'no_host') {
1.944 raeburn 10810: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10811: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
10812: } else {
10813: $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'});
10814: }
1.566 albertel 10815: } else {
10816: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10817: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10818: if ($clonedesc{'type'} ne 'Community') {
10819: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
10820: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10821: }
10822: }
1.882 raeburn 10823: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10824: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10825: $can_clone = 1;
10826: } else {
10827: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10828: $args->{'clonedomain'},$args->{'clonecourse'});
10829: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10830: if (grep(/^\*$/,@cloners)) {
10831: $can_clone = 1;
10832: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10833: $can_clone = 1;
10834: } else {
1.908 raeburn 10835: my $ccrole = 'cc';
1.944 raeburn 10836: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10837: $ccrole = 'co';
10838: }
1.578 raeburn 10839: my %roleshash =
10840: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10841: $args->{'ccdomain'},
1.908 raeburn 10842: 'userroles',['active'],[$ccrole],
1.578 raeburn 10843: [$args->{'clonedomain'}]);
1.908 raeburn 10844: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10845: $can_clone = 1;
10846: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10847: $can_clone = 1;
10848: } else {
1.944 raeburn 10849: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10850: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
10851: } else {
10852: $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'});
10853: }
1.578 raeburn 10854: }
1.566 albertel 10855: }
1.578 raeburn 10856: }
1.566 albertel 10857: }
10858: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10859: }
10860:
1.444 albertel 10861: sub construct_course {
1.885 raeburn 10862: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10863: my $outcome;
1.541 raeburn 10864: my $linefeed = '<br />'."\n";
10865: if ($context eq 'auto') {
10866: $linefeed = "\n";
10867: }
1.566 albertel 10868:
10869: #
10870: # Are we cloning?
10871: #
10872: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10873: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10874: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10875: if ($context ne 'auto') {
1.578 raeburn 10876: if ($clonemsg ne '') {
10877: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10878: }
1.566 albertel 10879: }
10880: $outcome .= $clonemsg.$linefeed;
10881:
10882: if (!$can_clone) {
10883: return (0,$outcome);
10884: }
10885: }
10886:
1.444 albertel 10887: #
10888: # Open course
10889: #
10890: my $crstype = lc($args->{'crstype'});
10891: my %cenv=();
10892: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10893: $args->{'cdescr'},
10894: $args->{'curl'},
10895: $args->{'course_home'},
10896: $args->{'nonstandard'},
10897: $args->{'crscode'},
10898: $args->{'ccuname'}.':'.
10899: $args->{'ccdomain'},
1.882 raeburn 10900: $args->{'crstype'},
1.885 raeburn 10901: $cnum,$context,$category);
1.444 albertel 10902:
10903: # Note: The testing routines depend on this being output; see
10904: # Utils::Course. This needs to at least be output as a comment
10905: # if anyone ever decides to not show this, and Utils::Course::new
10906: # will need to be suitably modified.
1.541 raeburn 10907: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10908: if ($$courseid =~ /^error:/) {
10909: return (0,$outcome);
10910: }
10911:
1.444 albertel 10912: #
10913: # Check if created correctly
10914: #
1.479 albertel 10915: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10916: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10917: if ($crsuhome eq 'no_host') {
10918: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10919: return (0,$outcome);
10920: }
1.541 raeburn 10921: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10922:
1.444 albertel 10923: #
1.566 albertel 10924: # Do the cloning
10925: #
10926: if ($can_clone && $cloneid) {
10927: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10928: if ($context ne 'auto') {
10929: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10930: }
10931: $outcome .= $clonemsg.$linefeed;
10932: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10933: # Copy all files
1.637 www 10934: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10935: # Restore URL
1.566 albertel 10936: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10937: # Restore title
1.566 albertel 10938: $cenv{'description'}=$oldcenv{'description'};
1.948.2.2 raeburn 10939: # Restore creation date, creator and creation context.
10940: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10941: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10942: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10943: # Mark as cloned
1.566 albertel 10944: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10945: # Need to clone grading mode
10946: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10947: $cenv{'grading'}=$newenv{'grading'};
10948: # Do not clone these environment entries
10949: &Apache::lonnet::del('environment',
10950: ['default_enrollment_start_date',
10951: 'default_enrollment_end_date',
10952: 'question.email',
10953: 'policy.email',
10954: 'comment.email',
10955: 'pch.users.denied',
1.725 raeburn 10956: 'plc.users.denied',
10957: 'hidefromcat',
10958: 'categories'],
1.638 www 10959: $$crsudom,$$crsunum);
1.444 albertel 10960: }
1.566 albertel 10961:
1.444 albertel 10962: #
10963: # Set environment (will override cloned, if existing)
10964: #
10965: my @sections = ();
10966: my @xlists = ();
10967: if ($args->{'crstype'}) {
10968: $cenv{'type'}=$args->{'crstype'};
10969: }
10970: if ($args->{'crsid'}) {
10971: $cenv{'courseid'}=$args->{'crsid'};
10972: }
10973: if ($args->{'crscode'}) {
10974: $cenv{'internal.coursecode'}=$args->{'crscode'};
10975: }
10976: if ($args->{'crsquota'} ne '') {
10977: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10978: } else {
10979: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10980: }
10981: if ($args->{'ccuname'}) {
10982: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10983: ':'.$args->{'ccdomain'};
10984: } else {
10985: $cenv{'internal.courseowner'} = $args->{'curruser'};
10986: }
10987: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10988: if ($args->{'crssections'}) {
10989: $cenv{'internal.sectionnums'} = '';
10990: if ($args->{'crssections'} =~ m/,/) {
10991: @sections = split/,/,$args->{'crssections'};
10992: } else {
10993: $sections[0] = $args->{'crssections'};
10994: }
10995: if (@sections > 0) {
10996: foreach my $item (@sections) {
10997: my ($sec,$gp) = split/:/,$item;
10998: my $class = $args->{'crscode'}.$sec;
10999: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
11000: $cenv{'internal.sectionnums'} .= $item.',';
11001: unless ($addcheck eq 'ok') {
11002: push @badclasses, $class;
11003: }
11004: }
11005: $cenv{'internal.sectionnums'} =~ s/,$//;
11006: }
11007: }
11008: # do not hide course coordinator from staff listing,
11009: # even if privileged
11010: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11011: # add crosslistings
11012: if ($args->{'crsxlist'}) {
11013: $cenv{'internal.crosslistings'}='';
11014: if ($args->{'crsxlist'} =~ m/,/) {
11015: @xlists = split/,/,$args->{'crsxlist'};
11016: } else {
11017: $xlists[0] = $args->{'crsxlist'};
11018: }
11019: if (@xlists > 0) {
11020: foreach my $item (@xlists) {
11021: my ($xl,$gp) = split/:/,$item;
11022: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
11023: $cenv{'internal.crosslistings'} .= $item.',';
11024: unless ($addcheck eq 'ok') {
11025: push @badclasses, $xl;
11026: }
11027: }
11028: $cenv{'internal.crosslistings'} =~ s/,$//;
11029: }
11030: }
11031: if ($args->{'autoadds'}) {
11032: $cenv{'internal.autoadds'}=$args->{'autoadds'};
11033: }
11034: if ($args->{'autodrops'}) {
11035: $cenv{'internal.autodrops'}=$args->{'autodrops'};
11036: }
11037: # check for notification of enrollment changes
11038: my @notified = ();
11039: if ($args->{'notify_owner'}) {
11040: if ($args->{'ccuname'} ne '') {
11041: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
11042: }
11043: }
11044: if ($args->{'notify_dc'}) {
11045: if ($uname ne '') {
1.630 raeburn 11046: push(@notified,$uname.':'.$udom);
1.444 albertel 11047: }
11048: }
11049: if (@notified > 0) {
11050: my $notifylist;
11051: if (@notified > 1) {
11052: $notifylist = join(',',@notified);
11053: } else {
11054: $notifylist = $notified[0];
11055: }
11056: $cenv{'internal.notifylist'} = $notifylist;
11057: }
11058: if (@badclasses > 0) {
11059: my %lt=&Apache::lonlocal::texthash(
11060: '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',
11061: 'dnhr' => 'does not have rights to access enrollment in these classes',
11062: 'adby' => 'as determined by the policies of your institution on access to official classlists'
11063: );
1.541 raeburn 11064: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
11065: ' ('.$lt{'adby'}.')';
11066: if ($context eq 'auto') {
11067: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 11068: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 11069: foreach my $item (@badclasses) {
11070: if ($context eq 'auto') {
11071: $outcome .= " - $item\n";
11072: } else {
11073: $outcome .= "<li>$item</li>\n";
11074: }
11075: }
11076: if ($context eq 'auto') {
11077: $outcome .= $linefeed;
11078: } else {
1.566 albertel 11079: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 11080: }
11081: }
1.444 albertel 11082: }
11083: if ($args->{'no_end_date'}) {
11084: $args->{'endaccess'} = 0;
11085: }
11086: $cenv{'internal.autostart'}=$args->{'enrollstart'};
11087: $cenv{'internal.autoend'}=$args->{'enrollend'};
11088: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
11089: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
11090: if ($args->{'showphotos'}) {
11091: $cenv{'internal.showphotos'}=$args->{'showphotos'};
11092: }
11093: $cenv{'internal.authtype'} = $args->{'authtype'};
11094: $cenv{'internal.autharg'} = $args->{'autharg'};
11095: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
11096: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 11097: 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');
11098: if ($context eq 'auto') {
11099: $outcome .= $krb_msg;
11100: } else {
1.566 albertel 11101: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 11102: }
11103: $outcome .= $linefeed;
1.444 albertel 11104: }
11105: }
11106: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
11107: if ($args->{'setpolicy'}) {
11108: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11109: }
11110: if ($args->{'setcontent'}) {
11111: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11112: }
11113: }
11114: if ($args->{'reshome'}) {
11115: $cenv{'reshome'}=$args->{'reshome'}.'/';
11116: $cenv{'reshome'}=~s/\/+$/\//;
11117: }
11118: #
11119: # course has keyed access
11120: #
11121: if ($args->{'setkeys'}) {
11122: $cenv{'keyaccess'}='yes';
11123: }
11124: # if specified, key authority is not course, but user
11125: # only active if keyaccess is yes
11126: if ($args->{'keyauth'}) {
1.487 albertel 11127: my ($user,$domain) = split(':',$args->{'keyauth'});
11128: $user = &LONCAPA::clean_username($user);
11129: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 11130: if ($user ne '' && $domain ne '') {
1.487 albertel 11131: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 11132: }
11133: }
11134:
11135: if ($args->{'disresdis'}) {
11136: $cenv{'pch.roles.denied'}='st';
11137: }
11138: if ($args->{'disablechat'}) {
11139: $cenv{'plc.roles.denied'}='st';
11140: }
11141:
11142: # Record we've not yet viewed the Course Initialization Helper for this
11143: # course
11144: $cenv{'course.helper.not.run'} = 1;
11145: #
11146: # Use new Randomseed
11147: #
11148: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
11149: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
11150: #
11151: # The encryption code and receipt prefix for this course
11152: #
11153: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
11154: $cenv{'internal.encpref'}=100+int(9*rand(99));
11155: #
11156: # By default, use standard grading
11157: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
11158:
1.541 raeburn 11159: $outcome .= $linefeed.&mt('Setting environment').': '.
11160: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11161: #
11162: # Open all assignments
11163: #
11164: if ($args->{'openall'}) {
11165: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
11166: my %storecontent = ($storeunder => time,
11167: $storeunder.'.type' => 'date_start');
11168:
11169: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 11170: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11171: }
11172: #
11173: # Set first page
11174: #
11175: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
11176: || ($cloneid)) {
1.445 albertel 11177: use LONCAPA::map;
1.444 albertel 11178: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 11179:
11180: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
11181: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
11182:
1.444 albertel 11183: $outcome .= ($fatal?$errtext:'read ok').' - ';
11184: my $title; my $url;
11185: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 11186: $title=&mt('Syllabus');
1.444 albertel 11187: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
11188: } else {
1.948.2.5 raeburn 11189: $title=&mt('Table of Contents');
1.444 albertel 11190: $url='/adm/navmaps';
11191: }
1.445 albertel 11192:
11193: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
11194: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
11195:
11196: if ($errtext) { $fatal=2; }
1.541 raeburn 11197: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 11198: }
1.566 albertel 11199:
11200: return (1,$outcome);
1.444 albertel 11201: }
11202:
11203: ############################################################
11204: ############################################################
11205:
1.378 raeburn 11206: sub course_type {
11207: my ($cid) = @_;
11208: if (!defined($cid)) {
11209: $cid = $env{'request.course.id'};
11210: }
1.404 albertel 11211: if (defined($env{'course.'.$cid.'.type'})) {
11212: return $env{'course.'.$cid.'.type'};
1.378 raeburn 11213: } else {
11214: return 'Course';
1.377 raeburn 11215: }
11216: }
1.156 albertel 11217:
1.406 raeburn 11218: sub group_term {
11219: my $crstype = &course_type();
11220: my %names = (
11221: 'Course' => 'group',
1.865 raeburn 11222: 'Community' => 'group',
1.406 raeburn 11223: );
11224: return $names{$crstype};
11225: }
11226:
1.902 raeburn 11227: sub course_types {
11228: my @types = ('official','unofficial','community');
11229: my %typename = (
11230: official => 'Official course',
11231: unofficial => 'Unofficial course',
11232: community => 'Community',
11233: );
11234: return (\@types,\%typename);
11235: }
11236:
1.156 albertel 11237: sub icon {
11238: my ($file)=@_;
1.505 albertel 11239: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 11240: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 11241: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 11242: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
11243: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
11244: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11245: $curfext.".gif") {
11246: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11247: $curfext.".gif";
11248: }
11249: }
1.249 albertel 11250: return &lonhttpdurl($iconname);
1.154 albertel 11251: }
1.84 albertel 11252:
1.575 albertel 11253: sub lonhttpdurl {
1.692 www 11254: #
11255: # Had been used for "small fry" static images on separate port 8080.
11256: # Modify here if lightweight http functionality desired again.
11257: # Currently eliminated due to increasing firewall issues.
11258: #
1.575 albertel 11259: my ($url)=@_;
1.692 www 11260: return $url;
1.215 albertel 11261: }
11262:
1.213 albertel 11263: sub connection_aborted {
11264: my ($r)=@_;
11265: $r->print(" ");$r->rflush();
11266: my $c = $r->connection;
11267: return $c->aborted();
11268: }
11269:
1.221 foxr 11270: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 11271: # strings as 'strings'.
11272: sub escape_single {
1.221 foxr 11273: my ($input) = @_;
1.223 albertel 11274: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 11275: $input =~ s/\'/\\\'/g; # Esacpe the 's....
11276: return $input;
11277: }
1.223 albertel 11278:
1.222 foxr 11279: # Same as escape_single, but escape's "'s This
11280: # can be used for "strings"
11281: sub escape_double {
11282: my ($input) = @_;
11283: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
11284: $input =~ s/\"/\\\"/g; # Esacpe the "s....
11285: return $input;
11286: }
1.223 albertel 11287:
1.222 foxr 11288: # Escapes the last element of a full URL.
11289: sub escape_url {
11290: my ($url) = @_;
1.238 raeburn 11291: my @urlslices = split(/\//, $url,-1);
1.369 www 11292: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 11293: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 11294: }
1.462 albertel 11295:
1.820 raeburn 11296: sub compare_arrays {
11297: my ($arrayref1,$arrayref2) = @_;
11298: my (@difference,%count);
11299: @difference = ();
11300: %count = ();
11301: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
11302: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
11303: foreach my $element (keys(%count)) {
11304: if ($count{$element} == 1) {
11305: push(@difference,$element);
11306: }
11307: }
11308: }
11309: return @difference;
11310: }
11311:
1.817 bisitz 11312: # -------------------------------------------------------- Initialize user login
1.462 albertel 11313: sub init_user_environment {
1.463 albertel 11314: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 11315: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
11316:
11317: my $public=($username eq 'public' && $domain eq 'public');
11318:
11319: # See if old ID present, if so, remove
11320:
11321: my ($filename,$cookie,$userroles);
11322: my $now=time;
11323:
11324: if ($public) {
11325: my $max_public=100;
11326: my $oldest;
11327: my $oldest_time=0;
11328: for(my $next=1;$next<=$max_public;$next++) {
11329: if (-e $lonids."/publicuser_$next.id") {
11330: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
11331: if ($mtime<$oldest_time || !$oldest_time) {
11332: $oldest_time=$mtime;
11333: $oldest=$next;
11334: }
11335: } else {
11336: $cookie="publicuser_$next";
11337: last;
11338: }
11339: }
11340: if (!$cookie) { $cookie="publicuser_$oldest"; }
11341: } else {
1.463 albertel 11342: # if this isn't a robot, kill any existing non-robot sessions
11343: if (!$args->{'robot'}) {
11344: opendir(DIR,$lonids);
11345: while ($filename=readdir(DIR)) {
11346: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
11347: unlink($lonids.'/'.$filename);
11348: }
1.462 albertel 11349: }
1.463 albertel 11350: closedir(DIR);
1.462 albertel 11351: }
11352: # Give them a new cookie
1.463 albertel 11353: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 11354: : $now.$$.int(rand(10000)));
1.463 albertel 11355: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 11356:
11357: # Initialize roles
11358:
11359: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
11360: }
11361: # ------------------------------------ Check browser type and MathML capability
11362:
11363: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
11364: $clientunicode,$clientos) = &decode_user_agent($r);
11365:
11366: # ------------------------------------------------------------- Get environment
11367:
11368: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
11369: my ($tmp) = keys(%userenv);
11370: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11371: # default remote control to off
11372: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
11373: } else {
11374: undef(%userenv);
11375: }
11376: if (($userenv{'interface'}) && (!$form->{'interface'})) {
11377: $form->{'interface'}=$userenv{'interface'};
11378: }
11379: $env{'environment.remote'}=$userenv{'remote'};
11380: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
11381:
11382: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 11383: foreach my $option ('interface','localpath','localres') {
11384: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 11385: }
11386: # --------------------------------------------------------- Write first profile
11387:
11388: {
11389: my %initial_env =
11390: ("user.name" => $username,
11391: "user.domain" => $domain,
11392: "user.home" => $authhost,
11393: "browser.type" => $clientbrowser,
11394: "browser.version" => $clientversion,
11395: "browser.mathml" => $clientmathml,
11396: "browser.unicode" => $clientunicode,
11397: "browser.os" => $clientos,
11398: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
11399: "request.course.fn" => '',
11400: "request.course.uri" => '',
11401: "request.course.sec" => '',
11402: "request.role" => 'cm',
11403: "request.role.adv" => $env{'user.adv'},
11404: "request.host" => $ENV{'REMOTE_ADDR'},);
11405:
11406: if ($form->{'localpath'}) {
11407: $initial_env{"browser.localpath"} = $form->{'localpath'};
11408: $initial_env{"browser.localres"} = $form->{'localres'};
11409: }
11410:
11411: if ($public) {
11412: $initial_env{"environment.remote"} = "off";
11413: }
11414: if ($form->{'interface'}) {
11415: $form->{'interface'}=~s/\W//gs;
11416: $initial_env{"browser.interface"} = $form->{'interface'};
11417: $env{'browser.interface'}=$form->{'interface'};
11418: }
1.948.2.11 raeburn 11419: my %is_adv = ( is_adv => $env{'user.adv'} );
1.948.2.31! raeburn 11420: my %domdef;
! 11421: unless ($domain eq 'public') {
! 11422: %domdef = &Apache::lonnet::get_domain_defaults($domain);
! 11423: }
1.462 albertel 11424:
1.724 raeburn 11425: foreach my $tool ('aboutme','blog','portfolio') {
11426: $userenv{'availabletools.'.$tool} =
1.948.2.10 raeburn 11427: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
11428: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 11429: }
11430:
1.864 raeburn 11431: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 11432: $userenv{'canrequest.'.$crstype} =
11433: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.948.2.10 raeburn 11434: 'reload','requestcourses',
11435: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 11436: }
11437:
1.462 albertel 11438: $env{'user.environment'} = "$lonids/$cookie.id";
11439:
11440: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
11441: &GDBM_WRCREAT(),0640)) {
11442: &_add_to_env(\%disk_env,\%initial_env);
11443: &_add_to_env(\%disk_env,\%userenv,'environment.');
11444: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 11445: if (ref($args->{'extra_env'})) {
11446: &_add_to_env(\%disk_env,$args->{'extra_env'});
11447: }
1.462 albertel 11448: untie(%disk_env);
11449: } else {
1.705 tempelho 11450: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
11451: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 11452: return 'error: '.$!;
11453: }
11454: }
11455: $env{'request.role'}='cm';
11456: $env{'request.role.adv'}=$env{'user.adv'};
11457: $env{'browser.type'}=$clientbrowser;
11458:
11459: return $cookie;
11460:
11461: }
11462:
11463: sub _add_to_env {
11464: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 11465: if (ref($env_data) eq 'HASH') {
11466: while (my ($key,$value) = each(%$env_data)) {
11467: $idf->{$prefix.$key} = $value;
11468: $env{$prefix.$key} = $value;
11469: }
1.462 albertel 11470: }
11471: }
11472:
1.685 tempelho 11473: # --- Get the symbolic name of a problem and the url
11474: sub get_symb {
11475: my ($request,$silent) = @_;
1.726 raeburn 11476: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 11477: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
11478: if ($symb eq '') {
11479: if (!$silent) {
11480: $request->print("Unable to handle ambiguous references:$url:.");
11481: return ();
11482: }
11483: }
11484: &Apache::lonenc::check_decrypt(\$symb);
11485: return ($symb);
11486: }
11487:
11488: # --------------------------------------------------------------Get annotation
11489:
11490: sub get_annotation {
11491: my ($symb,$enc) = @_;
11492:
11493: my $key = $symb;
11494: if (!$enc) {
11495: $key =
11496: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
11497: }
11498: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
11499: return $annotation{$key};
11500: }
11501:
11502: sub clean_symb {
1.731 raeburn 11503: my ($symb,$delete_enc) = @_;
1.685 tempelho 11504:
11505: &Apache::lonenc::check_decrypt(\$symb);
11506: my $enc = $env{'request.enc'};
1.731 raeburn 11507: if ($delete_enc) {
1.730 raeburn 11508: delete($env{'request.enc'});
11509: }
1.685 tempelho 11510:
11511: return ($symb,$enc);
11512: }
1.462 albertel 11513:
1.948.2.16 raeburn 11514: sub build_release_hashes {
11515: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
11516: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
11517: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
11518: (ref($randomizetry) eq 'HASH'));
11519: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
11520: my ($item,$name,$value) = split(/:/,$key);
11521: if ($item eq 'parameter') {
11522: if (ref($checkparms->{$name}) eq 'ARRAY') {
11523: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
11524: push(@{$checkparms->{$name}},$value);
11525: }
11526: } else {
11527: push(@{$checkparms->{$name}},$value);
11528: }
11529: } elsif ($item eq 'resourcetag') {
11530: if ($name eq 'responsetype') {
11531: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
11532: }
11533: } elsif ($item eq 'course') {
11534: if ($name eq 'crstype') {
11535: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
11536: }
11537: }
11538: }
11539: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
11540: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
11541: return;
11542: }
11543:
1.41 ng 11544: =pod
11545:
11546: =back
11547:
1.112 bowersj2 11548: =cut
1.41 ng 11549:
1.112 bowersj2 11550: 1;
11551: __END__;
1.41 ng 11552:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>