Annotation of loncom/interface/loncommon.pm, revision 1.948.2.11
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.11! raeburn 4: # $Id: loncommon.pm,v 1.948.2.10 2010/09/24 03:33:37 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.793 raeburn 455: $callargs .= ",1";
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:
599: sub userbrowser_javascript {
600: my $id_functions = &javascript_index_functions();
601: return <<"ENDUSERBRW";
602:
1.888 raeburn 603: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 604: var url = '/adm/pickuser?';
605: var userdom = getDomainFromSelectbox(formname,udom);
606: if (userdom != null) {
607: if (userdom != '') {
608: url += 'srchdom='+userdom+'&';
609: }
610: }
611: url += 'form=' + formname + '&unameelement='+uname+
612: '&udomelement='+udom+
613: '&ulastelement='+ulast+
614: '&ufirstelement='+ufirst+
615: '&uemailelement='+uemail+
1.881 raeburn 616: '&hideudomelement='+hideudom+
617: '&coursedom='+crsdom;
1.888 raeburn 618: if ((caller != null) && (caller != undefined)) {
619: url += '&caller='+caller;
620: }
1.876 raeburn 621: var title = 'User_Browser';
622: var options = 'scrollbars=1,resizable=1,menubar=0';
623: options += ',width=700,height=600';
624: var stdeditbrowser = open(url,title,options,'1');
625: stdeditbrowser.focus();
626: }
627:
1.888 raeburn 628: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 629: var formid = getFormIdByName(formname);
630: if (formid > -1) {
1.888 raeburn 631: var unameid = getIndexByName(formid,uname);
1.876 raeburn 632: var domid = getIndexByName(formid,udom);
633: var hidedomid = getIndexByName(formid,origdom);
634: if (hidedomid > -1) {
635: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 636: var unameval = document.forms[formid].elements[unameid].value;
637: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
638: if (domid > -1) {
639: var slct = document.forms[formid].elements[domid];
640: if (slct.type == 'select-one') {
641: var i;
642: for (i=0;i<slct.length;i++) {
643: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
644: }
645: }
646: if (slct.type == 'hidden') {
647: slct.value = fixeddom;
1.876 raeburn 648: }
649: }
1.468 raeburn 650: }
651: }
652: }
1.876 raeburn 653: return;
654: }
655:
656: $id_functions
657: ENDUSERBRW
1.468 raeburn 658: }
659:
660: sub setsec_javascript {
1.905 raeburn 661: my ($sec_element,$formname,$role_element) = @_;
662: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
663: $communityrolestr);
664: if ($role_element ne '') {
665: my @allroles = ('st','ta','ep','in','ad');
666: foreach my $crstype ('Course','Community') {
667: if ($crstype eq 'Community') {
668: foreach my $role (@allroles) {
669: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
670: }
671: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
672: } else {
673: foreach my $role (@allroles) {
674: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
675: }
676: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
677: }
678: }
679: $rolestr = '"'.join('","',@allroles).'"';
680: $courserolestr = '"'.join('","',@courserolenames).'"';
681: $communityrolestr = '"'.join('","',@communityrolenames).'"';
682: }
1.468 raeburn 683: my $setsections = qq|
684: function setSect(sectionlist) {
1.629 raeburn 685: var sectionsArray = new Array();
686: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
687: sectionsArray = sectionlist.split(",");
688: }
1.468 raeburn 689: var numSections = sectionsArray.length;
690: document.$formname.$sec_element.length = 0;
691: if (numSections == 0) {
692: document.$formname.$sec_element.multiple=false;
693: document.$formname.$sec_element.size=1;
694: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
695: } else {
696: if (numSections == 1) {
697: document.$formname.$sec_element.multiple=false;
698: document.$formname.$sec_element.size=1;
699: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
700: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
701: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
702: } else {
703: for (var i=0; i<numSections; i++) {
704: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
705: }
706: document.$formname.$sec_element.multiple=true
707: if (numSections < 3) {
708: document.$formname.$sec_element.size=numSections;
709: } else {
710: document.$formname.$sec_element.size=3;
711: }
712: document.$formname.$sec_element.options[0].selected = false
713: }
714: }
1.91 www 715: }
1.905 raeburn 716:
717: function setRole(crstype) {
1.468 raeburn 718: |;
1.905 raeburn 719: if ($role_element eq '') {
720: $setsections .= ' return;
721: }
722: ';
723: } else {
724: $setsections .= qq|
725: var elementLength = document.$formname.$role_element.length;
726: var allroles = Array($rolestr);
727: var courserolenames = Array($courserolestr);
728: var communityrolenames = Array($communityrolestr);
729: if (elementLength != undefined) {
730: if (document.$formname.$role_element.options[5].value == 'cc') {
731: if (crstype == 'Course') {
732: return;
733: } else {
734: allroles[5] = 'co';
735: for (var i=0; i<6; i++) {
736: document.$formname.$role_element.options[i].value = allroles[i];
737: document.$formname.$role_element.options[i].text = communityrolenames[i];
738: }
739: }
740: } else {
741: if (crstype == 'Community') {
742: return;
743: } else {
744: allroles[5] = 'cc';
745: for (var i=0; i<6; i++) {
746: document.$formname.$role_element.options[i].value = allroles[i];
747: document.$formname.$role_element.options[i].text = courserolenames[i];
748: }
749: }
750: }
751: }
752: return;
753: }
754: |;
755: }
1.468 raeburn 756: return $setsections;
757: }
758:
1.91 www 759: sub selectcourse_link {
1.909 raeburn 760: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
761: $typeelement) = @_;
762: my $type = $selecttype;
1.871 raeburn 763: my $linktext = &mt('Select Course');
764: if ($selecttype eq 'Community') {
1.909 raeburn 765: $linktext = &mt('Select Community');
1.906 raeburn 766: } elsif ($selecttype eq 'Course/Community') {
767: $linktext = &mt('Select Course/Community');
1.909 raeburn 768: $type = '';
1.871 raeburn 769: }
1.787 bisitz 770: return '<span class="LC_nobreak">'
771: ."<a href='"
772: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
773: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 774: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 775: ."'>".$linktext.'</a>'
1.787 bisitz 776: .'</span>';
1.74 www 777: }
1.42 matthew 778:
1.653 raeburn 779: sub selectauthor_link {
780: my ($form,$udom)=@_;
781: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
782: &mt('Select Author').'</a>';
783: }
784:
1.876 raeburn 785: sub selectuser_link {
1.881 raeburn 786: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 787: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 788: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 789: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 790: ');">'.$linktext.'</a>';
1.876 raeburn 791: }
792:
1.273 raeburn 793: sub check_uncheck_jscript {
794: my $jscript = <<"ENDSCRT";
795: function checkAll(field) {
796: if (field.length > 0) {
797: for (i = 0; i < field.length; i++) {
798: field[i].checked = true ;
799: }
800: } else {
801: field.checked = true
802: }
803: }
804:
805: function uncheckAll(field) {
806: if (field.length > 0) {
807: for (i = 0; i < field.length; i++) {
808: field[i].checked = false ;
1.543 albertel 809: }
810: } else {
1.273 raeburn 811: field.checked = false ;
812: }
813: }
814: ENDSCRT
815: return $jscript;
816: }
817:
1.656 www 818: sub select_timezone {
1.659 raeburn 819: my ($name,$selected,$onchange,$includeempty)=@_;
820: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
821: if ($includeempty) {
822: $output .= '<option value=""';
823: if (($selected eq '') || ($selected eq 'local')) {
824: $output .= ' selected="selected" ';
825: }
826: $output .= '> </option>';
827: }
1.657 raeburn 828: my @timezones = DateTime::TimeZone->all_names;
829: foreach my $tzone (@timezones) {
830: $output.= '<option value="'.$tzone.'"';
831: if ($tzone eq $selected) {
832: $output.=' selected="selected"';
833: }
834: $output.=">$tzone</option>\n";
1.656 www 835: }
836: $output.="</select>";
837: return $output;
838: }
1.273 raeburn 839:
1.687 raeburn 840: sub select_datelocale {
841: my ($name,$selected,$onchange,$includeempty)=@_;
842: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
843: if ($includeempty) {
844: $output .= '<option value=""';
845: if ($selected eq '') {
846: $output .= ' selected="selected" ';
847: }
848: $output .= '> </option>';
849: }
850: my (@possibles,%locale_names);
851: my @locales = DateTime::Locale::Catalog::Locales;
852: foreach my $locale (@locales) {
853: if (ref($locale) eq 'HASH') {
854: my $id = $locale->{'id'};
855: if ($id ne '') {
856: my $en_terr = $locale->{'en_territory'};
857: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 858: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 859: if (grep(/^en$/,@languages) || !@languages) {
860: if ($en_terr ne '') {
861: $locale_names{$id} = '('.$en_terr.')';
862: } elsif ($native_terr ne '') {
863: $locale_names{$id} = $native_terr;
864: }
865: } else {
866: if ($native_terr ne '') {
867: $locale_names{$id} = $native_terr.' ';
868: } elsif ($en_terr ne '') {
869: $locale_names{$id} = '('.$en_terr.')';
870: }
871: }
872: push (@possibles,$id);
873: }
874: }
875: }
876: foreach my $item (sort(@possibles)) {
877: $output.= '<option value="'.$item.'"';
878: if ($item eq $selected) {
879: $output.=' selected="selected"';
880: }
881: $output.=">$item";
882: if ($locale_names{$item} ne '') {
883: $output.=" $locale_names{$item}</option>\n";
884: }
885: $output.="</option>\n";
886: }
887: $output.="</select>";
888: return $output;
889: }
890:
1.792 raeburn 891: sub select_language {
892: my ($name,$selected,$includeempty) = @_;
893: my %langchoices;
894: if ($includeempty) {
895: %langchoices = ('' => 'No language preference');
896: }
897: foreach my $id (&languageids()) {
898: my $code = &supportedlanguagecode($id);
899: if ($code) {
900: $langchoices{$code} = &plainlanguagedescription($id);
901: }
902: }
1.948.2.7 raeburn 903: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 904: }
905:
1.42 matthew 906: =pod
1.36 matthew 907:
1.648 raeburn 908: =item * &linked_select_forms(...)
1.36 matthew 909:
910: linked_select_forms returns a string containing a <script></script> block
911: and html for two <select> menus. The select menus will be linked in that
912: changing the value of the first menu will result in new values being placed
913: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 914: order unless a defined order is provided.
1.36 matthew 915:
916: linked_select_forms takes the following ordered inputs:
917:
918: =over 4
919:
1.112 bowersj2 920: =item * $formname, the name of the <form> tag
1.36 matthew 921:
1.112 bowersj2 922: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 923:
1.112 bowersj2 924: =item * $firstdefault, the default value for the first menu
1.36 matthew 925:
1.112 bowersj2 926: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 927:
1.112 bowersj2 928: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 929:
1.112 bowersj2 930: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 931:
1.609 raeburn 932: =item * $menuorder, the order of values in the first menu
933:
1.41 ng 934: =back
935:
1.36 matthew 936: Below is an example of such a hash. Only the 'text', 'default', and
937: 'select2' keys must appear as stated. keys(%menu) are the possible
938: values for the first select menu. The text that coincides with the
1.41 ng 939: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 940: and text for the second menu are given in the hash pointed to by
941: $menu{$choice1}->{'select2'}.
942:
1.112 bowersj2 943: my %menu = ( A1 => { text =>"Choice A1" ,
944: default => "B3",
945: select2 => {
946: B1 => "Choice B1",
947: B2 => "Choice B2",
948: B3 => "Choice B3",
949: B4 => "Choice B4"
1.609 raeburn 950: },
951: order => ['B4','B3','B1','B2'],
1.112 bowersj2 952: },
953: A2 => { text =>"Choice A2" ,
954: default => "C2",
955: select2 => {
956: C1 => "Choice C1",
957: C2 => "Choice C2",
958: C3 => "Choice C3"
1.609 raeburn 959: },
960: order => ['C2','C1','C3'],
1.112 bowersj2 961: },
962: A3 => { text =>"Choice A3" ,
963: default => "D6",
964: select2 => {
965: D1 => "Choice D1",
966: D2 => "Choice D2",
967: D3 => "Choice D3",
968: D4 => "Choice D4",
969: D5 => "Choice D5",
970: D6 => "Choice D6",
971: D7 => "Choice D7"
1.609 raeburn 972: },
973: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 974: }
975: );
1.36 matthew 976:
977: =cut
978:
979: sub linked_select_forms {
980: my ($formname,
981: $middletext,
982: $firstdefault,
983: $firstselectname,
984: $secondselectname,
1.609 raeburn 985: $hashref,
986: $menuorder,
1.36 matthew 987: ) = @_;
988: my $second = "document.$formname.$secondselectname";
989: my $first = "document.$formname.$firstselectname";
990: # output the javascript to do the changing
991: my $result = '';
1.776 bisitz 992: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 993: $result.="// <![CDATA[\n";
1.36 matthew 994: $result.="var select2data = new Object();\n";
995: $" = '","';
996: my $debug = '';
997: foreach my $s1 (sort(keys(%$hashref))) {
998: $result.="select2data.d_$s1 = new Object();\n";
999: $result.="select2data.d_$s1.def = new String('".
1000: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1001: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1002: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1003: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1004: @s2values = @{$hashref->{$s1}->{'order'}};
1005: }
1.36 matthew 1006: $result.="\"@s2values\");\n";
1007: $result.="select2data.d_$s1.texts = new Array(";
1008: my @s2texts;
1009: foreach my $value (@s2values) {
1010: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1011: }
1012: $result.="\"@s2texts\");\n";
1013: }
1014: $"=' ';
1015: $result.= <<"END";
1016:
1017: function select1_changed() {
1018: // Determine new choice
1019: var newvalue = "d_" + $first.value;
1020: // update select2
1021: var values = select2data[newvalue].values;
1022: var texts = select2data[newvalue].texts;
1023: var select2def = select2data[newvalue].def;
1024: var i;
1025: // out with the old
1026: for (i = 0; i < $second.options.length; i++) {
1027: $second.options[i] = null;
1028: }
1029: // in with the nuclear
1030: for (i=0;i<values.length; i++) {
1031: $second.options[i] = new Option(values[i]);
1.143 matthew 1032: $second.options[i].value = values[i];
1.36 matthew 1033: $second.options[i].text = texts[i];
1034: if (values[i] == select2def) {
1035: $second.options[i].selected = true;
1036: }
1037: }
1038: }
1.824 bisitz 1039: // ]]>
1.36 matthew 1040: </script>
1041: END
1042: # output the initial values for the selection lists
1043: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1044: my @order = sort(keys(%{$hashref}));
1045: if (ref($menuorder) eq 'ARRAY') {
1046: @order = @{$menuorder};
1047: }
1048: foreach my $value (@order) {
1.36 matthew 1049: $result.=" <option value=\"$value\" ";
1.253 albertel 1050: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1051: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1052: }
1053: $result .= "</select>\n";
1054: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1055: $result .= $middletext;
1056: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1057: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1058:
1059: my @secondorder = sort(keys(%select2));
1060: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1061: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1062: }
1063: foreach my $value (@secondorder) {
1.36 matthew 1064: $result.=" <option value=\"$value\" ";
1.253 albertel 1065: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1066: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1067: }
1068: $result .= "</select>\n";
1069: # return $debug;
1070: return $result;
1071: } # end of sub linked_select_forms {
1072:
1.45 matthew 1073: =pod
1.44 bowersj2 1074:
1.948.2.7 raeburn 1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1076:
1.112 bowersj2 1077: Returns a string corresponding to an HTML link to the given help
1078: $topic, where $topic corresponds to the name of a .tex file in
1079: /home/httpd/html/adm/help/tex, with underscores replaced by
1080: spaces.
1081:
1082: $text will optionally be linked to the same topic, allowing you to
1083: link text in addition to the graphic. If you do not want to link
1084: text, but wish to specify one of the later parameters, pass an
1085: empty string.
1086:
1087: $stayOnPage is a value that will be interpreted as a boolean. If true,
1088: the link will not open a new window. If false, the link will open
1089: a new window using Javascript. (Default is false.)
1090:
1091: $width and $height are optional numerical parameters that will
1092: override the width and height of the popped up window, which may
1093: be useful for certain help topics with big pictures included.
1.44 bowersj2 1094:
1095: =cut
1096:
1097: sub help_open_topic {
1.948.2.7 raeburn 1098: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1099: $text = "" if (not defined $text);
1.44 bowersj2 1100: $stayOnPage = 0 if (not defined $stayOnPage);
1101: $width = 350 if (not defined $width);
1102: $height = 400 if (not defined $height);
1103: my $filename = $topic;
1104: $filename =~ s/ /_/g;
1105:
1.48 bowersj2 1106: my $template = "";
1107: my $link;
1.572 banghart 1108:
1.159 www 1109: $topic=~s/\W/\_/g;
1.44 bowersj2 1110:
1.572 banghart 1111: if (!$stayOnPage) {
1.72 bowersj2 1112: $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 1113: } else {
1.48 bowersj2 1114: $link = "/adm/help/${filename}.hlp";
1115: }
1116:
1117: # Add the text
1.755 neumanie 1118: if ($text ne "") {
1.763 bisitz 1119: $template.='<span class="LC_help_open_topic">'
1120: .'<a target="_top" href="'.$link.'">'
1121: .$text.'</a>';
1.48 bowersj2 1122: }
1123:
1.763 bisitz 1124: # (Always) Add the graphic
1.179 matthew 1125: my $title = &mt('Online Help');
1.667 raeburn 1126: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.948.2.7 raeburn 1127: if ($imgid ne '') {
1128: $imgid = ' id="'.$imgid.'"';
1129: }
1.763 bisitz 1130: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1131: .'<img src="'.$helpicon.'" border="0"'
1132: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.948.2.7 raeburn 1133: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1134: .' /></a>';
1.948.2.7 raeburn 1135: if ($text ne "") {
1.763 bisitz 1136: $template.='</span>';
1137: }
1.44 bowersj2 1138: return $template;
1139:
1.106 bowersj2 1140: }
1141:
1142: # This is a quicky function for Latex cheatsheet editing, since it
1143: # appears in at least four places
1144: sub helpLatexCheatsheet {
1.732 raeburn 1145: my ($topic,$text,$not_author) = @_;
1146: my $out;
1.106 bowersj2 1147: my $addOther = '';
1.732 raeburn 1148: if ($topic) {
1.763 bisitz 1149: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1150: undef, undef, 600).
1151: '</span> ';
1152: }
1153: $out = '<span>' # Start cheatsheet
1154: .$addOther
1155: .'<span>'
1156: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1157: undef,undef,600)
1158: .'</span> <span>'
1159: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1160: undef,undef,600)
1161: .'</span>';
1.732 raeburn 1162: unless ($not_author) {
1.763 bisitz 1163: $out .= ' <span>'
1164: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1165: undef,undef,600)
1166: .'</span>';
1.732 raeburn 1167: }
1.763 bisitz 1168: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1169: return $out;
1.172 www 1170: }
1171:
1.430 albertel 1172: sub general_help {
1173: my $helptopic='Student_Intro';
1174: if ($env{'request.role'}=~/^(ca|au)/) {
1175: $helptopic='Authoring_Intro';
1.907 raeburn 1176: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1177: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1178: } elsif ($env{'request.role'}=~/^dc/) {
1179: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1180: }
1181: return $helptopic;
1182: }
1183:
1184: sub update_help_link {
1185: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1186: my $origurl = $ENV{'REQUEST_URI'};
1187: $origurl=~s|^/~|/priv/|;
1188: my $timestamp = time;
1189: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1190: $$datum = &escape($$datum);
1191: }
1192:
1193: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1194: my $output .= <<"ENDOUTPUT";
1195: <script type="text/javascript">
1.824 bisitz 1196: // <![CDATA[
1.430 albertel 1197: banner_link = '$banner_link';
1.824 bisitz 1198: // ]]>
1.430 albertel 1199: </script>
1200: ENDOUTPUT
1201: return $output;
1202: }
1203:
1204: # now just updates the help link and generates a blue icon
1.193 raeburn 1205: sub help_open_menu {
1.430 albertel 1206: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1207: = @_;
1.430 albertel 1208: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1209: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1210: # if environment.remote is on (using remote control UI)
1.798 tempelho 1211: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1212: $stayOnPage=1;
1.430 albertel 1213: }
1214: my $output;
1215: if ($component_help) {
1216: if (!$text) {
1217: $output=&help_open_topic($component_help,undef,$stayOnPage,
1218: $width,$height);
1219: } else {
1220: my $help_text;
1221: $help_text=&unescape($topic);
1222: $output='<table><tr><td>'.
1223: &help_open_topic($component_help,$help_text,$stayOnPage,
1224: $width,$height).'</td></tr></table>';
1225: }
1226: }
1227: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1228: return $output.$banner_link;
1229: }
1230:
1231: sub top_nav_help {
1232: my ($text) = @_;
1.436 albertel 1233: $text = &mt($text);
1.572 banghart 1234: my $stay_on_page =
1.798 tempelho 1235: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1236: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1237: : "javascript:helpMenu('open')";
1.572 banghart 1238: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1239:
1.201 raeburn 1240: my $title = &mt('Get help');
1.436 albertel 1241:
1242: return <<"END";
1243: $banner_link
1244: <a href="$link" title="$title">$text</a>
1245: END
1246: }
1247:
1248: sub help_menu_js {
1249: my ($text) = @_;
1250:
1251: my $stayOnPage =
1.798 tempelho 1252: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1253:
1254: my $width = 620;
1255: my $height = 600;
1.430 albertel 1256: my $helptopic=&general_help();
1257: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1258: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1259: my $start_page =
1260: &Apache::loncommon::start_page('Help Menu', undef,
1261: {'frameset' => 1,
1262: 'js_ready' => 1,
1263: 'add_entries' => {
1264: 'border' => '0',
1.579 raeburn 1265: 'rows' => "110,*",},});
1.331 albertel 1266: my $end_page =
1267: &Apache::loncommon::end_page({'frameset' => 1,
1268: 'js_ready' => 1,});
1269:
1.436 albertel 1270: my $template .= <<"ENDTEMPLATE";
1271: <script type="text/javascript">
1.877 bisitz 1272: // <![CDATA[
1.253 albertel 1273: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1274: var banner_link = '';
1.243 raeburn 1275: function helpMenu(target) {
1276: var caller = this;
1277: if (target == 'open') {
1278: var newWindow = null;
1279: try {
1.262 albertel 1280: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1281: }
1282: catch(error) {
1283: writeHelp(caller);
1284: return;
1285: }
1286: if (newWindow) {
1287: caller = newWindow;
1288: }
1.193 raeburn 1289: }
1.243 raeburn 1290: writeHelp(caller);
1291: return;
1292: }
1293: function writeHelp(caller) {
1.430 albertel 1294: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1295: caller.document.close()
1296: caller.focus()
1.193 raeburn 1297: }
1.877 bisitz 1298: // END LON-CAPA Internal -->
1.253 albertel 1299: // ]]>
1.436 albertel 1300: </script>
1.193 raeburn 1301: ENDTEMPLATE
1302: return $template;
1303: }
1304:
1.172 www 1305: sub help_open_bug {
1306: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1307: unless ($env{'user.adv'}) { return ''; }
1.172 www 1308: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1309: $text = "" if (not defined $text);
1310: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1311: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1312: $stayOnPage=1;
1313: }
1.184 albertel 1314: $width = 600 if (not defined $width);
1315: $height = 600 if (not defined $height);
1.172 www 1316:
1317: $topic=~s/\W+/\+/g;
1318: my $link='';
1319: my $template='';
1.379 albertel 1320: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1321: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1322: if (!$stayOnPage)
1323: {
1324: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1325: }
1326: else
1327: {
1328: $link = $url;
1329: }
1330: # Add the text
1331: if ($text ne "")
1332: {
1333: $template .=
1334: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1335: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1336: }
1337:
1338: # Add the graphic
1.179 matthew 1339: my $title = &mt('Report a Bug');
1.215 albertel 1340: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1341: $template .= <<"ENDTEMPLATE";
1.436 albertel 1342: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1343: ENDTEMPLATE
1344: if ($text ne '') { $template.='</td></tr></table>' };
1345: return $template;
1346:
1347: }
1348:
1349: sub help_open_faq {
1350: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1351: unless ($env{'user.adv'}) { return ''; }
1.172 www 1352: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1353: $text = "" if (not defined $text);
1354: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1355: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1356: $stayOnPage=1;
1357: }
1358: $width = 350 if (not defined $width);
1359: $height = 400 if (not defined $height);
1360:
1361: $topic=~s/\W+/\+/g;
1362: my $link='';
1363: my $template='';
1364: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1365: if (!$stayOnPage)
1366: {
1367: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1368: }
1369: else
1370: {
1371: $link = $url;
1372: }
1373:
1374: # Add the text
1375: if ($text ne "")
1376: {
1377: $template .=
1.173 www 1378: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1379: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1380: }
1381:
1382: # Add the graphic
1.179 matthew 1383: my $title = &mt('View the FAQ');
1.215 albertel 1384: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1385: $template .= <<"ENDTEMPLATE";
1.436 albertel 1386: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1387: ENDTEMPLATE
1388: if ($text ne '') { $template.='</td></tr></table>' };
1389: return $template;
1390:
1.44 bowersj2 1391: }
1.37 matthew 1392:
1.180 matthew 1393: ###############################################################
1394: ###############################################################
1395:
1.45 matthew 1396: =pod
1397:
1.648 raeburn 1398: =item * &change_content_javascript():
1.256 matthew 1399:
1400: This and the next function allow you to create small sections of an
1401: otherwise static HTML page that you can update on the fly with
1402: Javascript, even in Netscape 4.
1403:
1404: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1405: must be written to the HTML page once. It will prove the Javascript
1406: function "change(name, content)". Calling the change function with the
1407: name of the section
1408: you want to update, matching the name passed to C<changable_area>, and
1409: the new content you want to put in there, will put the content into
1410: that area.
1411:
1412: B<Note>: Netscape 4 only reserves enough space for the changable area
1413: to contain room for the original contents. You need to "make space"
1414: for whatever changes you wish to make, and be B<sure> to check your
1415: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1416: it's adequate for updating a one-line status display, but little more.
1417: This script will set the space to 100% width, so you only need to
1418: worry about height in Netscape 4.
1419:
1420: Modern browsers are much less limiting, and if you can commit to the
1421: user not using Netscape 4, this feature may be used freely with
1422: pretty much any HTML.
1423:
1424: =cut
1425:
1426: sub change_content_javascript {
1427: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1428: if ($env{'browser.type'} eq 'netscape' &&
1429: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1430: return (<<NETSCAPE4);
1431: function change(name, content) {
1432: doc = document.layers[name+"___escape"].layers[0].document;
1433: doc.open();
1434: doc.write(content);
1435: doc.close();
1436: }
1437: NETSCAPE4
1438: } else {
1439: # Otherwise, we need to use semi-standards-compliant code
1440: # (technically, "innerHTML" isn't standard but the equivalent
1441: # is really scary, and every useful browser supports it
1442: return (<<DOMBASED);
1443: function change(name, content) {
1444: element = document.getElementById(name);
1445: element.innerHTML = content;
1446: }
1447: DOMBASED
1448: }
1449: }
1450:
1451: =pod
1452:
1.648 raeburn 1453: =item * &changable_area($name,$origContent):
1.256 matthew 1454:
1455: This provides a "changable area" that can be modified on the fly via
1456: the Javascript code provided in C<change_content_javascript>. $name is
1457: the name you will use to reference the area later; do not repeat the
1458: same name on a given HTML page more then once. $origContent is what
1459: the area will originally contain, which can be left blank.
1460:
1461: =cut
1462:
1463: sub changable_area {
1464: my ($name, $origContent) = @_;
1465:
1.258 albertel 1466: if ($env{'browser.type'} eq 'netscape' &&
1467: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1468: # If this is netscape 4, we need to use the Layer tag
1469: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1470: } else {
1471: return "<span id='$name'>$origContent</span>";
1472: }
1473: }
1474:
1475: =pod
1476:
1.648 raeburn 1477: =item * &viewport_geometry_js
1.590 raeburn 1478:
1479: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1480:
1481: =cut
1482:
1483:
1484: sub viewport_geometry_js {
1485: return <<"GEOMETRY";
1486: var Geometry = {};
1487: function init_geometry() {
1488: if (Geometry.init) { return };
1489: Geometry.init=1;
1490: if (window.innerHeight) {
1491: Geometry.getViewportHeight = function() { return window.innerHeight; };
1492: Geometry.getViewportWidth = function() { return window.innerWidth; };
1493: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1494: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1495: }
1496: else if (document.documentElement && document.documentElement.clientHeight) {
1497: Geometry.getViewportHeight =
1498: function() { return document.documentElement.clientHeight; };
1499: Geometry.getViewportWidth =
1500: function() { return document.documentElement.clientWidth; };
1501:
1502: Geometry.getHorizontalScroll =
1503: function() { return document.documentElement.scrollLeft; };
1504: Geometry.getVerticalScroll =
1505: function() { return document.documentElement.scrollTop; };
1506: }
1507: else if (document.body.clientHeight) {
1508: Geometry.getViewportHeight =
1509: function() { return document.body.clientHeight; };
1510: Geometry.getViewportWidth =
1511: function() { return document.body.clientWidth; };
1512: Geometry.getHorizontalScroll =
1513: function() { return document.body.scrollLeft; };
1514: Geometry.getVerticalScroll =
1515: function() { return document.body.scrollTop; };
1516: }
1517: }
1518:
1519: GEOMETRY
1520: }
1521:
1522: =pod
1523:
1.648 raeburn 1524: =item * &viewport_size_js()
1.590 raeburn 1525:
1526: 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.
1527:
1528: =cut
1529:
1530: sub viewport_size_js {
1531: my $geometry = &viewport_geometry_js();
1532: return <<"DIMS";
1533:
1534: $geometry
1535:
1536: function getViewportDims(width,height) {
1537: init_geometry();
1538: width.value = Geometry.getViewportWidth();
1539: height.value = Geometry.getViewportHeight();
1540: return;
1541: }
1542:
1543: DIMS
1544: }
1545:
1546: =pod
1547:
1.648 raeburn 1548: =item * &resize_textarea_js()
1.565 albertel 1549:
1550: emits the needed javascript to resize a textarea to be as big as possible
1551:
1552: creates a function resize_textrea that takes two IDs first should be
1553: the id of the element to resize, second should be the id of a div that
1554: surrounds everything that comes after the textarea, this routine needs
1555: to be attached to the <body> for the onload and onresize events.
1556:
1.648 raeburn 1557: =back
1.565 albertel 1558:
1559: =cut
1560:
1561: sub resize_textarea_js {
1.590 raeburn 1562: my $geometry = &viewport_geometry_js();
1.565 albertel 1563: return <<"RESIZE";
1564: <script type="text/javascript">
1.824 bisitz 1565: // <![CDATA[
1.590 raeburn 1566: $geometry
1.565 albertel 1567:
1.588 albertel 1568: function getX(element) {
1569: var x = 0;
1570: while (element) {
1571: x += element.offsetLeft;
1572: element = element.offsetParent;
1573: }
1574: return x;
1575: }
1576: function getY(element) {
1577: var y = 0;
1578: while (element) {
1579: y += element.offsetTop;
1580: element = element.offsetParent;
1581: }
1582: return y;
1583: }
1584:
1585:
1.565 albertel 1586: function resize_textarea(textarea_id,bottom_id) {
1587: init_geometry();
1588: var textarea = document.getElementById(textarea_id);
1589: //alert(textarea);
1590:
1.588 albertel 1591: var textarea_top = getY(textarea);
1.565 albertel 1592: var textarea_height = textarea.offsetHeight;
1593: var bottom = document.getElementById(bottom_id);
1.588 albertel 1594: var bottom_top = getY(bottom);
1.565 albertel 1595: var bottom_height = bottom.offsetHeight;
1596: var window_height = Geometry.getViewportHeight();
1.588 albertel 1597: var fudge = 23;
1.565 albertel 1598: var new_height = window_height-fudge-textarea_top-bottom_height;
1599: if (new_height < 300) {
1600: new_height = 300;
1601: }
1602: textarea.style.height=new_height+'px';
1603: }
1.824 bisitz 1604: // ]]>
1.565 albertel 1605: </script>
1606: RESIZE
1607:
1608: }
1609:
1610: =pod
1611:
1.256 matthew 1612: =head1 Excel and CSV file utility routines
1613:
1614: =over 4
1615:
1616: =cut
1617:
1618: ###############################################################
1619: ###############################################################
1620:
1621: =pod
1622:
1.648 raeburn 1623: =item * &csv_translate($text)
1.37 matthew 1624:
1.185 www 1625: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1626: format.
1627:
1628: =cut
1629:
1.180 matthew 1630: ###############################################################
1631: ###############################################################
1.37 matthew 1632: sub csv_translate {
1633: my $text = shift;
1634: $text =~ s/\"/\"\"/g;
1.209 albertel 1635: $text =~ s/\n/ /g;
1.37 matthew 1636: return $text;
1637: }
1.180 matthew 1638:
1639: ###############################################################
1640: ###############################################################
1641:
1642: =pod
1643:
1.648 raeburn 1644: =item * &define_excel_formats()
1.180 matthew 1645:
1646: Define some commonly used Excel cell formats.
1647:
1648: Currently supported formats:
1649:
1650: =over 4
1651:
1652: =item header
1653:
1654: =item bold
1655:
1656: =item h1
1657:
1658: =item h2
1659:
1660: =item h3
1661:
1.256 matthew 1662: =item h4
1663:
1664: =item i
1665:
1.180 matthew 1666: =item date
1667:
1668: =back
1669:
1670: Inputs: $workbook
1671:
1672: Returns: $format, a hash reference.
1673:
1674: =cut
1675:
1676: ###############################################################
1677: ###############################################################
1678: sub define_excel_formats {
1679: my ($workbook) = @_;
1680: my $format;
1681: $format->{'header'} = $workbook->add_format(bold => 1,
1682: bottom => 1,
1683: align => 'center');
1684: $format->{'bold'} = $workbook->add_format(bold=>1);
1685: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1686: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1687: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1688: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1689: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1690: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1691: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1692: return $format;
1693: }
1694:
1695: ###############################################################
1696: ###############################################################
1.113 bowersj2 1697:
1698: =pod
1699:
1.648 raeburn 1700: =item * &create_workbook()
1.255 matthew 1701:
1702: Create an Excel worksheet. If it fails, output message on the
1703: request object and return undefs.
1704:
1705: Inputs: Apache request object
1706:
1707: Returns (undef) on failure,
1708: Excel worksheet object, scalar with filename, and formats
1709: from &Apache::loncommon::define_excel_formats on success
1710:
1711: =cut
1712:
1713: ###############################################################
1714: ###############################################################
1715: sub create_workbook {
1716: my ($r) = @_;
1717: #
1718: # Create the excel spreadsheet
1719: my $filename = '/prtspool/'.
1.258 albertel 1720: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1721: time.'_'.rand(1000000000).'.xls';
1722: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1723: if (! defined($workbook)) {
1724: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1725: $r->print(
1726: '<p class="LC_error">'
1727: .&mt('Problems occurred in creating the new Excel file.')
1728: .' '.&mt('This error has been logged.')
1729: .' '.&mt('Please alert your LON-CAPA administrator.')
1730: .'</p>'
1731: );
1.255 matthew 1732: return (undef);
1733: }
1734: #
1735: $workbook->set_tempdir('/home/httpd/perl/tmp');
1736: #
1737: my $format = &Apache::loncommon::define_excel_formats($workbook);
1738: return ($workbook,$filename,$format);
1739: }
1740:
1741: ###############################################################
1742: ###############################################################
1743:
1744: =pod
1745:
1.648 raeburn 1746: =item * &create_text_file()
1.113 bowersj2 1747:
1.542 raeburn 1748: Create a file to write to and eventually make available to the user.
1.256 matthew 1749: If file creation fails, outputs an error message on the request object and
1750: return undefs.
1.113 bowersj2 1751:
1.256 matthew 1752: Inputs: Apache request object, and file suffix
1.113 bowersj2 1753:
1.256 matthew 1754: Returns (undef) on failure,
1755: Filehandle and filename on success.
1.113 bowersj2 1756:
1757: =cut
1758:
1.256 matthew 1759: ###############################################################
1760: ###############################################################
1761: sub create_text_file {
1762: my ($r,$suffix) = @_;
1763: if (! defined($suffix)) { $suffix = 'txt'; };
1764: my $fh;
1765: my $filename = '/prtspool/'.
1.258 albertel 1766: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1767: time.'_'.rand(1000000000).'.'.$suffix;
1768: $fh = Apache::File->new('>/home/httpd'.$filename);
1769: if (! defined($fh)) {
1770: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1771: $r->print(
1772: '<p class="LC_error">'
1773: .&mt('Problems occurred in creating the output file.')
1774: .' '.&mt('This error has been logged.')
1775: .' '.&mt('Please alert your LON-CAPA administrator.')
1776: .'</p>'
1777: );
1.113 bowersj2 1778: }
1.256 matthew 1779: return ($fh,$filename)
1.113 bowersj2 1780: }
1781:
1782:
1.256 matthew 1783: =pod
1.113 bowersj2 1784:
1785: =back
1786:
1787: =cut
1.37 matthew 1788:
1789: ###############################################################
1.33 matthew 1790: ## Home server <option> list generating code ##
1791: ###############################################################
1.35 matthew 1792:
1.169 www 1793: # ------------------------------------------
1794:
1795: sub domain_select {
1796: my ($name,$value,$multiple)=@_;
1797: my %domains=map {
1.514 albertel 1798: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1799: } &Apache::lonnet::all_domains();
1.169 www 1800: if ($multiple) {
1801: $domains{''}=&mt('Any domain');
1.550 albertel 1802: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1803: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1804: } else {
1.550 albertel 1805: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.948.2.7 raeburn 1806: return &select_form($name,$value,\%domains);
1.169 www 1807: }
1808: }
1809:
1.282 albertel 1810: #-------------------------------------------
1811:
1812: =pod
1813:
1.519 raeburn 1814: =head1 Routines for form select boxes
1815:
1816: =over 4
1817:
1.648 raeburn 1818: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1819:
1820: Returns a string containing a <select> element int multiple mode
1821:
1822:
1823: Args:
1824: $name - name of the <select> element
1.506 raeburn 1825: $value - scalar or array ref of values that should already be selected
1.282 albertel 1826: $size - number of rows long the select element is
1.283 albertel 1827: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1828: (shown text should already have been &mt())
1.506 raeburn 1829: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1830:
1.282 albertel 1831: =cut
1832:
1833: #-------------------------------------------
1.169 www 1834: sub multiple_select_form {
1.284 albertel 1835: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1836: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1837: my $output='';
1.191 matthew 1838: if (! defined($size)) {
1839: $size = 4;
1.283 albertel 1840: if (scalar(keys(%$hash))<4) {
1841: $size = scalar(keys(%$hash));
1.191 matthew 1842: }
1843: }
1.734 bisitz 1844: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1845: my @order;
1.506 raeburn 1846: if (ref($order) eq 'ARRAY') {
1847: @order = @{$order};
1848: } else {
1849: @order = sort(keys(%$hash));
1.501 banghart 1850: }
1851: if (exists($$hash{'select_form_order'})) {
1852: @order = @{$$hash{'select_form_order'}};
1853: }
1854:
1.284 albertel 1855: foreach my $key (@order) {
1.356 albertel 1856: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1857: $output.='selected="selected" ' if ($selected{$key});
1858: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1859: }
1860: $output.="</select>\n";
1861: return $output;
1862: }
1863:
1.88 www 1864: #-------------------------------------------
1865:
1866: =pod
1867:
1.948.2.7 raeburn 1868: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1869:
1870: Returns a string containing a <select name='$name' size='1'> form to
1.948.2.7 raeburn 1871: allow a user to select options from a ref to a hash containing:
1872: option_name => displayed text. An optional $onchange can include
1873: a javascript onchange item, e.g., onchange="this.form.submit();"
1874:
1.88 www 1875: See lonrights.pm for an example invocation and use.
1876:
1877: =cut
1878:
1879: #-------------------------------------------
1880: sub select_form {
1.948.2.7 raeburn 1881: my ($def,$name,$hashref,$onchange) = @_;
1882: return unless (ref($hashref) eq 'HASH');
1883: if ($onchange) {
1884: $onchange = ' onchange="'.$onchange.'"';
1885: }
1886: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1887: my @keys;
1.948.2.7 raeburn 1888: if (exists($hashref->{'select_form_order'})) {
1889: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1890: } else {
1.948.2.7 raeburn 1891: @keys=sort(keys(%{$hashref}));
1.128 albertel 1892: }
1.356 albertel 1893: foreach my $key (@keys) {
1894: $selectform.=
1895: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1896: ($key eq $def ? 'selected="selected" ' : '').
1.948.2.7 raeburn 1897: ">".$hashref->{$key}."</option>\n";
1.88 www 1898: }
1899: $selectform.="</select>";
1900: return $selectform;
1901: }
1902:
1.475 www 1903: # For display filters
1904:
1905: sub display_filter {
1906: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1907: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1908: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1909: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1910: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1911: '</label></span> <span class="LC_nobreak">'.
1.475 www 1912: &mt('Filter [_1]',
1.477 www 1913: &select_form($env{'form.displayfilter'},
1914: 'displayfilter',
1.948.2.7 raeburn 1915: {'currentfolder' => 'Current folder/page',
1.477 www 1916: 'containing' => 'Containing phrase',
1.948.2.7 raeburn 1917: 'none' => 'None'})).
1.714 bisitz 1918: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1919: }
1920:
1.167 www 1921: sub gradeleveldescription {
1922: my $gradelevel=shift;
1923: my %gradelevels=(0 => 'Not specified',
1924: 1 => 'Grade 1',
1925: 2 => 'Grade 2',
1926: 3 => 'Grade 3',
1927: 4 => 'Grade 4',
1928: 5 => 'Grade 5',
1929: 6 => 'Grade 6',
1930: 7 => 'Grade 7',
1931: 8 => 'Grade 8',
1932: 9 => 'Grade 9',
1933: 10 => 'Grade 10',
1934: 11 => 'Grade 11',
1935: 12 => 'Grade 12',
1936: 13 => 'Grade 13',
1937: 14 => '100 Level',
1938: 15 => '200 Level',
1939: 16 => '300 Level',
1940: 17 => '400 Level',
1941: 18 => 'Graduate Level');
1942: return &mt($gradelevels{$gradelevel});
1943: }
1944:
1.163 www 1945: sub select_level_form {
1946: my ($deflevel,$name)=@_;
1947: unless ($deflevel) { $deflevel=0; }
1.167 www 1948: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1949: for (my $i=0; $i<=18; $i++) {
1950: $selectform.="<option value=\"$i\" ".
1.253 albertel 1951: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1952: ">".&gradeleveldescription($i)."</option>\n";
1953: }
1954: $selectform.="</select>";
1955: return $selectform;
1.163 www 1956: }
1.167 www 1957:
1.35 matthew 1958: #-------------------------------------------
1959:
1.45 matthew 1960: =pod
1961:
1.910 raeburn 1962: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1963:
1964: Returns a string containing a <select name='$name' size='1'> form to
1965: allow a user to select the domain to preform an operation in.
1966: See loncreateuser.pm for an example invocation and use.
1967:
1.90 www 1968: If the $includeempty flag is set, it also includes an empty choice ("no domain
1969: selected");
1970:
1.743 raeburn 1971: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1972:
1.910 raeburn 1973: 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.
1974:
1975: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 1976:
1.35 matthew 1977: =cut
1978:
1979: #-------------------------------------------
1.34 matthew 1980: sub select_dom_form {
1.910 raeburn 1981: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 1982: if ($onchange) {
1.874 raeburn 1983: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1984: }
1.910 raeburn 1985: my @domains;
1986: if (ref($incdoms) eq 'ARRAY') {
1987: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
1988: } else {
1989: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1990: }
1.90 www 1991: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1992: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1993: foreach my $dom (@domains) {
1994: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1995: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1996: if ($showdomdesc) {
1997: if ($dom ne '') {
1998: my $domdesc = &Apache::lonnet::domain($dom,'description');
1999: if ($domdesc ne '') {
2000: $selectdomain .= ' ('.$domdesc.')';
2001: }
2002: }
2003: }
2004: $selectdomain .= "</option>\n";
1.34 matthew 2005: }
2006: $selectdomain.="</select>";
2007: return $selectdomain;
2008: }
2009:
1.35 matthew 2010: #-------------------------------------------
2011:
1.45 matthew 2012: =pod
2013:
1.648 raeburn 2014: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2015:
1.586 raeburn 2016: input: 4 arguments (two required, two optional) -
2017: $domain - domain of new user
2018: $name - name of form element
2019: $default - Value of 'default' causes a default item to be first
2020: option, and selected by default.
2021: $hide - Value of 'hide' causes hiding of the name of the server,
2022: if 1 server found, or default, if 0 found.
1.594 raeburn 2023: output: returns 2 items:
1.586 raeburn 2024: (a) form element which contains either:
2025: (i) <select name="$name">
2026: <option value="$hostid1">$hostid $servers{$hostid}</option>
2027: <option value="$hostid2">$hostid $servers{$hostid}</option>
2028: </select>
2029: form item if there are multiple library servers in $domain, or
2030: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2031: if there is only one library server in $domain.
2032:
2033: (b) number of library servers found.
2034:
2035: See loncreateuser.pm for example of use.
1.35 matthew 2036:
2037: =cut
2038:
2039: #-------------------------------------------
1.586 raeburn 2040: sub home_server_form_item {
2041: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2042: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2043: my $result;
2044: my $numlib = keys(%servers);
2045: if ($numlib > 1) {
2046: $result .= '<select name="'.$name.'" />'."\n";
2047: if ($default) {
1.804 bisitz 2048: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2049: '</option>'."\n";
2050: }
2051: foreach my $hostid (sort(keys(%servers))) {
2052: $result.= '<option value="'.$hostid.'">'.
2053: $hostid.' '.$servers{$hostid}."</option>\n";
2054: }
2055: $result .= '</select>'."\n";
2056: } elsif ($numlib == 1) {
2057: my $hostid;
2058: foreach my $item (keys(%servers)) {
2059: $hostid = $item;
2060: }
2061: $result .= '<input type="hidden" name="'.$name.'" value="'.
2062: $hostid.'" />';
2063: if (!$hide) {
2064: $result .= $hostid.' '.$servers{$hostid};
2065: }
2066: $result .= "\n";
2067: } elsif ($default) {
2068: $result .= '<input type="hidden" name="'.$name.
2069: '" value="default" />';
2070: if (!$hide) {
2071: $result .= &mt('default');
2072: }
2073: $result .= "\n";
1.33 matthew 2074: }
1.586 raeburn 2075: return ($result,$numlib);
1.33 matthew 2076: }
1.112 bowersj2 2077:
2078: =pod
2079:
1.534 albertel 2080: =back
2081:
1.112 bowersj2 2082: =cut
1.87 matthew 2083:
2084: ###############################################################
1.112 bowersj2 2085: ## Decoding User Agent ##
1.87 matthew 2086: ###############################################################
2087:
2088: =pod
2089:
1.112 bowersj2 2090: =head1 Decoding the User Agent
2091:
2092: =over 4
2093:
2094: =item * &decode_user_agent()
1.87 matthew 2095:
2096: Inputs: $r
2097:
2098: Outputs:
2099:
2100: =over 4
2101:
1.112 bowersj2 2102: =item * $httpbrowser
1.87 matthew 2103:
1.112 bowersj2 2104: =item * $clientbrowser
1.87 matthew 2105:
1.112 bowersj2 2106: =item * $clientversion
1.87 matthew 2107:
1.112 bowersj2 2108: =item * $clientmathml
1.87 matthew 2109:
1.112 bowersj2 2110: =item * $clientunicode
1.87 matthew 2111:
1.112 bowersj2 2112: =item * $clientos
1.87 matthew 2113:
2114: =back
2115:
1.157 matthew 2116: =back
2117:
1.87 matthew 2118: =cut
2119:
2120: ###############################################################
2121: ###############################################################
2122: sub decode_user_agent {
1.247 albertel 2123: my ($r)=@_;
1.87 matthew 2124: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2125: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2126: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2127: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2128: my $clientbrowser='unknown';
2129: my $clientversion='0';
2130: my $clientmathml='';
2131: my $clientunicode='0';
2132: for (my $i=0;$i<=$#browsertype;$i++) {
2133: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2134: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2135: $clientbrowser=$bname;
2136: $httpbrowser=~/$vreg/i;
2137: $clientversion=$1;
2138: $clientmathml=($clientversion>=$minv);
2139: $clientunicode=($clientversion>=$univ);
2140: }
2141: }
2142: my $clientos='unknown';
2143: if (($httpbrowser=~/linux/i) ||
2144: ($httpbrowser=~/unix/i) ||
2145: ($httpbrowser=~/ux/i) ||
2146: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2147: if (($httpbrowser=~/vax/i) ||
2148: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2149: if ($httpbrowser=~/next/i) { $clientos='next'; }
2150: if (($httpbrowser=~/mac/i) ||
2151: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2152: if ($httpbrowser=~/win/i) { $clientos='win'; }
2153: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2154: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2155: $clientunicode,$clientos,);
2156: }
2157:
1.32 matthew 2158: ###############################################################
2159: ## Authentication changing form generation subroutines ##
2160: ###############################################################
2161: ##
2162: ## All of the authform_xxxxxxx subroutines take their inputs in a
2163: ## hash, and have reasonable default values.
2164: ##
2165: ## formname = the name given in the <form> tag.
1.35 matthew 2166: #-------------------------------------------
2167:
1.45 matthew 2168: =pod
2169:
1.112 bowersj2 2170: =head1 Authentication Routines
2171:
2172: =over 4
2173:
1.648 raeburn 2174: =item * &authform_xxxxxx()
1.35 matthew 2175:
2176: The authform_xxxxxx subroutines provide javascript and html forms which
2177: handle some of the conveniences required for authentication forms.
2178: This is not an optimal method, but it works.
2179:
2180: =over 4
2181:
1.112 bowersj2 2182: =item * authform_header
1.35 matthew 2183:
1.112 bowersj2 2184: =item * authform_authorwarning
1.35 matthew 2185:
1.112 bowersj2 2186: =item * authform_nochange
1.35 matthew 2187:
1.112 bowersj2 2188: =item * authform_kerberos
1.35 matthew 2189:
1.112 bowersj2 2190: =item * authform_internal
1.35 matthew 2191:
1.112 bowersj2 2192: =item * authform_filesystem
1.35 matthew 2193:
2194: =back
2195:
1.648 raeburn 2196: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2197:
1.35 matthew 2198: =cut
2199:
2200: #-------------------------------------------
1.32 matthew 2201: sub authform_header{
2202: my %in = (
2203: formname => 'cu',
1.80 albertel 2204: kerb_def_dom => '',
1.32 matthew 2205: @_,
2206: );
2207: $in{'formname'} = 'document.' . $in{'formname'};
2208: my $result='';
1.80 albertel 2209:
2210: #---------------------------------------------- Code for upper case translation
2211: my $Javascript_toUpperCase;
2212: unless ($in{kerb_def_dom}) {
2213: $Javascript_toUpperCase =<<"END";
2214: switch (choice) {
2215: case 'krb': currentform.elements[choicearg].value =
2216: currentform.elements[choicearg].value.toUpperCase();
2217: break;
2218: default:
2219: }
2220: END
2221: } else {
2222: $Javascript_toUpperCase = "";
2223: }
2224:
1.165 raeburn 2225: my $radioval = "'nochange'";
1.591 raeburn 2226: if (defined($in{'curr_authtype'})) {
2227: if ($in{'curr_authtype'} ne '') {
2228: $radioval = "'".$in{'curr_authtype'}."arg'";
2229: }
1.174 matthew 2230: }
1.165 raeburn 2231: my $argfield = 'null';
1.591 raeburn 2232: if (defined($in{'mode'})) {
1.165 raeburn 2233: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2234: if (defined($in{'curr_autharg'})) {
2235: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2236: $argfield = "'$in{'curr_autharg'}'";
2237: }
2238: }
2239: }
2240: }
2241:
1.32 matthew 2242: $result.=<<"END";
2243: var current = new Object();
1.165 raeburn 2244: current.radiovalue = $radioval;
2245: current.argfield = $argfield;
1.32 matthew 2246:
2247: function changed_radio(choice,currentform) {
2248: var choicearg = choice + 'arg';
2249: // If a radio button in changed, we need to change the argfield
2250: if (current.radiovalue != choice) {
2251: current.radiovalue = choice;
2252: if (current.argfield != null) {
2253: currentform.elements[current.argfield].value = '';
2254: }
2255: if (choice == 'nochange') {
2256: current.argfield = null;
2257: } else {
2258: current.argfield = choicearg;
2259: switch(choice) {
2260: case 'krb':
2261: currentform.elements[current.argfield].value =
2262: "$in{'kerb_def_dom'}";
2263: break;
2264: default:
2265: break;
2266: }
2267: }
2268: }
2269: return;
2270: }
1.22 www 2271:
1.32 matthew 2272: function changed_text(choice,currentform) {
2273: var choicearg = choice + 'arg';
2274: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2275: $Javascript_toUpperCase
1.32 matthew 2276: // clear old field
2277: if ((current.argfield != choicearg) && (current.argfield != null)) {
2278: currentform.elements[current.argfield].value = '';
2279: }
2280: current.argfield = choicearg;
2281: }
2282: set_auth_radio_buttons(choice,currentform);
2283: return;
1.20 www 2284: }
1.32 matthew 2285:
2286: function set_auth_radio_buttons(newvalue,currentform) {
2287: var i=0;
2288: while (i < currentform.login.length) {
2289: if (currentform.login[i].value == newvalue) { break; }
2290: i++;
2291: }
2292: if (i == currentform.login.length) {
2293: return;
2294: }
2295: current.radiovalue = newvalue;
2296: currentform.login[i].checked = true;
2297: return;
2298: }
2299: END
2300: return $result;
2301: }
2302:
2303: sub authform_authorwarning{
2304: my $result='';
1.144 matthew 2305: $result='<i>'.
2306: &mt('As a general rule, only authors or co-authors should be '.
2307: 'filesystem authenticated '.
2308: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2309: return $result;
2310: }
2311:
2312: sub authform_nochange{
2313: my %in = (
2314: formname => 'document.cu',
2315: kerb_def_dom => 'MSU.EDU',
2316: @_,
2317: );
1.586 raeburn 2318: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2319: my $result;
2320: if (keys(%can_assign) == 0) {
2321: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2322: } else {
2323: $result = '<label>'.&mt('[_1] Do not change login data',
2324: '<input type="radio" name="login" value="nochange" '.
2325: 'checked="checked" onclick="'.
1.281 albertel 2326: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2327: '</label>';
1.586 raeburn 2328: }
1.32 matthew 2329: return $result;
2330: }
2331:
1.591 raeburn 2332: sub authform_kerberos {
1.32 matthew 2333: my %in = (
2334: formname => 'document.cu',
2335: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2336: kerb_def_auth => 'krb4',
1.32 matthew 2337: @_,
2338: );
1.586 raeburn 2339: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2340: $autharg,$jscall);
2341: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2342: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2343: $check5 = ' checked="checked"';
1.80 albertel 2344: } else {
1.772 bisitz 2345: $check4 = ' checked="checked"';
1.80 albertel 2346: }
1.165 raeburn 2347: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2348: if (defined($in{'curr_authtype'})) {
2349: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2350: $krbcheck = ' checked="checked"';
1.623 raeburn 2351: if (defined($in{'mode'})) {
2352: if ($in{'mode'} eq 'modifyuser') {
2353: $krbcheck = '';
2354: }
2355: }
1.591 raeburn 2356: if (defined($in{'curr_kerb_ver'})) {
2357: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2358: $check5 = ' checked="checked"';
1.591 raeburn 2359: $check4 = '';
2360: } else {
1.772 bisitz 2361: $check4 = ' checked="checked"';
1.591 raeburn 2362: $check5 = '';
2363: }
1.586 raeburn 2364: }
1.591 raeburn 2365: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2366: $krbarg = $in{'curr_autharg'};
2367: }
1.586 raeburn 2368: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2369: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2370: $result =
2371: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2372: $in{'curr_autharg'},$krbver);
2373: } else {
2374: $result =
2375: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2376: }
2377: return $result;
2378: }
2379: }
2380: } else {
2381: if ($authnum == 1) {
1.784 bisitz 2382: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2383: }
2384: }
1.586 raeburn 2385: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2386: return;
1.587 raeburn 2387: } elsif ($authtype eq '') {
1.591 raeburn 2388: if (defined($in{'mode'})) {
1.587 raeburn 2389: if ($in{'mode'} eq 'modifycourse') {
2390: if ($authnum == 1) {
1.784 bisitz 2391: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2392: }
2393: }
2394: }
1.586 raeburn 2395: }
2396: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2397: if ($authtype eq '') {
2398: $authtype = '<input type="radio" name="login" value="krb" '.
2399: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2400: $krbcheck.' />';
2401: }
2402: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2403: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2404: $in{'curr_authtype'} eq 'krb5') ||
2405: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2406: $in{'curr_authtype'} eq 'krb4')) {
2407: $result .= &mt
1.144 matthew 2408: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2409: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2410: '<label>'.$authtype,
1.281 albertel 2411: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2412: 'value="'.$krbarg.'" '.
1.144 matthew 2413: 'onchange="'.$jscall.'" />',
1.281 albertel 2414: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2415: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2416: '</label>');
1.586 raeburn 2417: } elsif ($can_assign{'krb4'}) {
2418: $result .= &mt
2419: ('[_1] Kerberos authenticated with domain [_2] '.
2420: '[_3] Version 4 [_4]',
2421: '<label>'.$authtype,
2422: '</label><input type="text" size="10" name="krbarg" '.
2423: 'value="'.$krbarg.'" '.
2424: 'onchange="'.$jscall.'" />',
2425: '<label><input type="hidden" name="krbver" value="4" />',
2426: '</label>');
2427: } elsif ($can_assign{'krb5'}) {
2428: $result .= &mt
2429: ('[_1] Kerberos authenticated with domain [_2] '.
2430: '[_3] Version 5 [_4]',
2431: '<label>'.$authtype,
2432: '</label><input type="text" size="10" name="krbarg" '.
2433: 'value="'.$krbarg.'" '.
2434: 'onchange="'.$jscall.'" />',
2435: '<label><input type="hidden" name="krbver" value="5" />',
2436: '</label>');
2437: }
1.32 matthew 2438: return $result;
2439: }
2440:
2441: sub authform_internal{
1.586 raeburn 2442: my %in = (
1.32 matthew 2443: formname => 'document.cu',
2444: kerb_def_dom => 'MSU.EDU',
2445: @_,
2446: );
1.586 raeburn 2447: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2448: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2449: if (defined($in{'curr_authtype'})) {
2450: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2451: if ($can_assign{'int'}) {
1.772 bisitz 2452: $intcheck = 'checked="checked" ';
1.623 raeburn 2453: if (defined($in{'mode'})) {
2454: if ($in{'mode'} eq 'modifyuser') {
2455: $intcheck = '';
2456: }
2457: }
1.591 raeburn 2458: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2459: $intarg = $in{'curr_autharg'};
2460: }
2461: } else {
2462: $result = &mt('Currently internally authenticated.');
2463: return $result;
1.165 raeburn 2464: }
2465: }
1.586 raeburn 2466: } else {
2467: if ($authnum == 1) {
1.784 bisitz 2468: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2469: }
2470: }
2471: if (!$can_assign{'int'}) {
2472: return;
1.587 raeburn 2473: } elsif ($authtype eq '') {
1.591 raeburn 2474: if (defined($in{'mode'})) {
1.587 raeburn 2475: if ($in{'mode'} eq 'modifycourse') {
2476: if ($authnum == 1) {
1.784 bisitz 2477: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2478: }
2479: }
2480: }
1.165 raeburn 2481: }
1.586 raeburn 2482: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2483: if ($authtype eq '') {
2484: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2485: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2486: }
1.605 bisitz 2487: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2488: $intarg.'" onchange="'.$jscall.'" />';
2489: $result = &mt
1.144 matthew 2490: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2491: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2492: $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 2493: return $result;
2494: }
2495:
2496: sub authform_local{
2497: my %in = (
2498: formname => 'document.cu',
2499: kerb_def_dom => 'MSU.EDU',
2500: @_,
2501: );
1.586 raeburn 2502: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2503: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2504: if (defined($in{'curr_authtype'})) {
2505: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2506: if ($can_assign{'loc'}) {
1.772 bisitz 2507: $loccheck = 'checked="checked" ';
1.623 raeburn 2508: if (defined($in{'mode'})) {
2509: if ($in{'mode'} eq 'modifyuser') {
2510: $loccheck = '';
2511: }
2512: }
1.591 raeburn 2513: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2514: $locarg = $in{'curr_autharg'};
2515: }
2516: } else {
2517: $result = &mt('Currently using local (institutional) authentication.');
2518: return $result;
1.165 raeburn 2519: }
2520: }
1.586 raeburn 2521: } else {
2522: if ($authnum == 1) {
1.784 bisitz 2523: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2524: }
2525: }
2526: if (!$can_assign{'loc'}) {
2527: return;
1.587 raeburn 2528: } elsif ($authtype eq '') {
1.591 raeburn 2529: if (defined($in{'mode'})) {
1.587 raeburn 2530: if ($in{'mode'} eq 'modifycourse') {
2531: if ($authnum == 1) {
1.784 bisitz 2532: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2533: }
2534: }
2535: }
1.165 raeburn 2536: }
1.586 raeburn 2537: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2538: if ($authtype eq '') {
2539: $authtype = '<input type="radio" name="login" value="loc" '.
2540: $loccheck.' onchange="'.$jscall.'" onclick="'.
2541: $jscall.'" />';
2542: }
2543: $autharg = '<input type="text" size="10" name="locarg" value="'.
2544: $locarg.'" onchange="'.$jscall.'" />';
2545: $result = &mt('[_1] Local Authentication with argument [_2]',
2546: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2547: return $result;
2548: }
2549:
2550: sub authform_filesystem{
2551: my %in = (
2552: formname => 'document.cu',
2553: kerb_def_dom => 'MSU.EDU',
2554: @_,
2555: );
1.586 raeburn 2556: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2557: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2558: if (defined($in{'curr_authtype'})) {
2559: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2560: if ($can_assign{'fsys'}) {
1.772 bisitz 2561: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2562: if (defined($in{'mode'})) {
2563: if ($in{'mode'} eq 'modifyuser') {
2564: $fsyscheck = '';
2565: }
2566: }
1.586 raeburn 2567: } else {
2568: $result = &mt('Currently Filesystem Authenticated.');
2569: return $result;
2570: }
2571: }
2572: } else {
2573: if ($authnum == 1) {
1.784 bisitz 2574: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2575: }
2576: }
2577: if (!$can_assign{'fsys'}) {
2578: return;
1.587 raeburn 2579: } elsif ($authtype eq '') {
1.591 raeburn 2580: if (defined($in{'mode'})) {
1.587 raeburn 2581: if ($in{'mode'} eq 'modifycourse') {
2582: if ($authnum == 1) {
1.784 bisitz 2583: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2584: }
2585: }
2586: }
1.586 raeburn 2587: }
2588: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2589: if ($authtype eq '') {
2590: $authtype = '<input type="radio" name="login" value="fsys" '.
2591: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2592: $jscall.'" />';
2593: }
2594: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2595: ' onchange="'.$jscall.'" />';
2596: $result = &mt
1.144 matthew 2597: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2598: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2599: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2600: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2601: 'onchange="'.$jscall.'" />');
1.32 matthew 2602: return $result;
2603: }
2604:
1.586 raeburn 2605: sub get_assignable_auth {
2606: my ($dom) = @_;
2607: if ($dom eq '') {
2608: $dom = $env{'request.role.domain'};
2609: }
2610: my %can_assign = (
2611: krb4 => 1,
2612: krb5 => 1,
2613: int => 1,
2614: loc => 1,
2615: );
2616: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2617: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2618: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2619: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2620: my $context;
2621: if ($env{'request.role'} =~ /^au/) {
2622: $context = 'author';
2623: } elsif ($env{'request.role'} =~ /^dc/) {
2624: $context = 'domain';
2625: } elsif ($env{'request.course.id'}) {
2626: $context = 'course';
2627: }
2628: if ($context) {
2629: if (ref($authhash->{$context}) eq 'HASH') {
2630: %can_assign = %{$authhash->{$context}};
2631: }
2632: }
2633: }
2634: }
2635: my $authnum = 0;
2636: foreach my $key (keys(%can_assign)) {
2637: if ($can_assign{$key}) {
2638: $authnum ++;
2639: }
2640: }
2641: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2642: $authnum --;
2643: }
2644: return ($authnum,%can_assign);
2645: }
2646:
1.80 albertel 2647: ###############################################################
2648: ## Get Kerberos Defaults for Domain ##
2649: ###############################################################
2650: ##
2651: ## Returns default kerberos version and an associated argument
2652: ## as listed in file domain.tab. If not listed, provides
2653: ## appropriate default domain and kerberos version.
2654: ##
2655: #-------------------------------------------
2656:
2657: =pod
2658:
1.648 raeburn 2659: =item * &get_kerberos_defaults()
1.80 albertel 2660:
2661: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2662: version and domain. If not found, it defaults to version 4 and the
2663: domain of the server.
1.80 albertel 2664:
1.648 raeburn 2665: =over 4
2666:
1.80 albertel 2667: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2668:
1.648 raeburn 2669: =back
2670:
2671: =back
2672:
1.80 albertel 2673: =cut
2674:
2675: #-------------------------------------------
2676: sub get_kerberos_defaults {
2677: my $domain=shift;
1.641 raeburn 2678: my ($krbdef,$krbdefdom);
2679: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2680: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2681: $krbdef = $domdefaults{'auth_def'};
2682: $krbdefdom = $domdefaults{'auth_arg_def'};
2683: } else {
1.80 albertel 2684: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2685: my $krbdefdom=$1;
2686: $krbdefdom=~tr/a-z/A-Z/;
2687: $krbdef = "krb4";
2688: }
2689: return ($krbdef,$krbdefdom);
2690: }
1.112 bowersj2 2691:
1.32 matthew 2692:
1.46 matthew 2693: ###############################################################
2694: ## Thesaurus Functions ##
2695: ###############################################################
1.20 www 2696:
1.46 matthew 2697: =pod
1.20 www 2698:
1.112 bowersj2 2699: =head1 Thesaurus Functions
2700:
2701: =over 4
2702:
1.648 raeburn 2703: =item * &initialize_keywords()
1.46 matthew 2704:
2705: Initializes the package variable %Keywords if it is empty. Uses the
2706: package variable $thesaurus_db_file.
2707:
2708: =cut
2709:
2710: ###################################################
2711:
2712: sub initialize_keywords {
2713: return 1 if (scalar keys(%Keywords));
2714: # If we are here, %Keywords is empty, so fill it up
2715: # Make sure the file we need exists...
2716: if (! -e $thesaurus_db_file) {
2717: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2718: " failed because it does not exist");
2719: return 0;
2720: }
2721: # Set up the hash as a database
2722: my %thesaurus_db;
2723: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2724: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2725: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2726: $thesaurus_db_file);
2727: return 0;
2728: }
2729: # Get the average number of appearances of a word.
2730: my $avecount = $thesaurus_db{'average.count'};
2731: # Put keywords (those that appear > average) into %Keywords
2732: while (my ($word,$data)=each (%thesaurus_db)) {
2733: my ($count,undef) = split /:/,$data;
2734: $Keywords{$word}++ if ($count > $avecount);
2735: }
2736: untie %thesaurus_db;
2737: # Remove special values from %Keywords.
1.356 albertel 2738: foreach my $value ('total.count','average.count') {
2739: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2740: }
1.46 matthew 2741: return 1;
2742: }
2743:
2744: ###################################################
2745:
2746: =pod
2747:
1.648 raeburn 2748: =item * &keyword($word)
1.46 matthew 2749:
2750: Returns true if $word is a keyword. A keyword is a word that appears more
2751: than the average number of times in the thesaurus database. Calls
2752: &initialize_keywords
2753:
2754: =cut
2755:
2756: ###################################################
1.20 www 2757:
2758: sub keyword {
1.46 matthew 2759: return if (!&initialize_keywords());
2760: my $word=lc(shift());
2761: $word=~s/\W//g;
2762: return exists($Keywords{$word});
1.20 www 2763: }
1.46 matthew 2764:
2765: ###############################################################
2766:
2767: =pod
1.20 www 2768:
1.648 raeburn 2769: =item * &get_related_words()
1.46 matthew 2770:
1.160 matthew 2771: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2772: an array of words. If the keyword is not in the thesaurus, an empty array
2773: will be returned. The order of the words returned is determined by the
2774: database which holds them.
2775:
2776: Uses global $thesaurus_db_file.
2777:
2778: =cut
2779:
2780: ###############################################################
2781: sub get_related_words {
2782: my $keyword = shift;
2783: my %thesaurus_db;
2784: if (! -e $thesaurus_db_file) {
2785: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2786: "failed because the file does not exist");
2787: return ();
2788: }
2789: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2790: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2791: return ();
2792: }
2793: my @Words=();
1.429 www 2794: my $count=0;
1.46 matthew 2795: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2796: # The first element is the number of times
2797: # the word appears. We do not need it now.
1.429 www 2798: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2799: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2800: my $threshold=$mostfrequentcount/10;
2801: foreach my $possibleword (@RelatedWords) {
2802: my ($word,$wordcount)=split(/\,/,$possibleword);
2803: if ($wordcount>$threshold) {
2804: push(@Words,$word);
2805: $count++;
2806: if ($count>10) { last; }
2807: }
1.20 www 2808: }
2809: }
1.46 matthew 2810: untie %thesaurus_db;
2811: return @Words;
1.14 harris41 2812: }
1.46 matthew 2813:
1.112 bowersj2 2814: =pod
2815:
2816: =back
2817:
2818: =cut
1.61 www 2819:
2820: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2821: =pod
2822:
1.112 bowersj2 2823: =head1 User Name Functions
2824:
2825: =over 4
2826:
1.648 raeburn 2827: =item * &plainname($uname,$udom,$first)
1.81 albertel 2828:
1.112 bowersj2 2829: Takes a users logon name and returns it as a string in
1.226 albertel 2830: "first middle last generation" form
2831: if $first is set to 'lastname' then it returns it as
2832: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2833:
2834: =cut
1.61 www 2835:
1.295 www 2836:
1.81 albertel 2837: ###############################################################
1.61 www 2838: sub plainname {
1.226 albertel 2839: my ($uname,$udom,$first)=@_;
1.537 albertel 2840: return if (!defined($uname) || !defined($udom));
1.295 www 2841: my %names=&getnames($uname,$udom);
1.226 albertel 2842: my $name=&Apache::lonnet::format_name($names{'firstname'},
2843: $names{'middlename'},
2844: $names{'lastname'},
2845: $names{'generation'},$first);
2846: $name=~s/^\s+//;
1.62 www 2847: $name=~s/\s+$//;
2848: $name=~s/\s+/ /g;
1.353 albertel 2849: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2850: return $name;
1.61 www 2851: }
1.66 www 2852:
2853: # -------------------------------------------------------------------- Nickname
1.81 albertel 2854: =pod
2855:
1.648 raeburn 2856: =item * &nickname($uname,$udom)
1.81 albertel 2857:
2858: Gets a users name and returns it as a string as
2859:
2860: ""nickname""
1.66 www 2861:
1.81 albertel 2862: if the user has a nickname or
2863:
2864: "first middle last generation"
2865:
2866: if the user does not
2867:
2868: =cut
1.66 www 2869:
2870: sub nickname {
2871: my ($uname,$udom)=@_;
1.537 albertel 2872: return if (!defined($uname) || !defined($udom));
1.295 www 2873: my %names=&getnames($uname,$udom);
1.68 albertel 2874: my $name=$names{'nickname'};
1.66 www 2875: if ($name) {
2876: $name='"'.$name.'"';
2877: } else {
2878: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2879: $names{'lastname'}.' '.$names{'generation'};
2880: $name=~s/\s+$//;
2881: $name=~s/\s+/ /g;
2882: }
2883: return $name;
2884: }
2885:
1.295 www 2886: sub getnames {
2887: my ($uname,$udom)=@_;
1.537 albertel 2888: return if (!defined($uname) || !defined($udom));
1.433 albertel 2889: if ($udom eq 'public' && $uname eq 'public') {
2890: return ('lastname' => &mt('Public'));
2891: }
1.295 www 2892: my $id=$uname.':'.$udom;
2893: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2894: if ($cached) {
2895: return %{$names};
2896: } else {
2897: my %loadnames=&Apache::lonnet::get('environment',
2898: ['firstname','middlename','lastname','generation','nickname'],
2899: $udom,$uname);
2900: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2901: return %loadnames;
2902: }
2903: }
1.61 www 2904:
1.542 raeburn 2905: # -------------------------------------------------------------------- getemails
1.648 raeburn 2906:
1.542 raeburn 2907: =pod
2908:
1.648 raeburn 2909: =item * &getemails($uname,$udom)
1.542 raeburn 2910:
2911: Gets a user's email information and returns it as a hash with keys:
2912: notification, critnotification, permanentemail
2913:
2914: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2915: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2916:
1.648 raeburn 2917:
1.542 raeburn 2918: =cut
2919:
1.648 raeburn 2920:
1.466 albertel 2921: sub getemails {
2922: my ($uname,$udom)=@_;
2923: if ($udom eq 'public' && $uname eq 'public') {
2924: return;
2925: }
1.467 www 2926: if (!$udom) { $udom=$env{'user.domain'}; }
2927: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2928: my $id=$uname.':'.$udom;
2929: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2930: if ($cached) {
2931: return %{$names};
2932: } else {
2933: my %loadnames=&Apache::lonnet::get('environment',
2934: ['notification','critnotification',
2935: 'permanentemail'],
2936: $udom,$uname);
2937: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2938: return %loadnames;
2939: }
2940: }
2941:
1.551 albertel 2942: sub flush_email_cache {
2943: my ($uname,$udom)=@_;
2944: if (!$udom) { $udom =$env{'user.domain'}; }
2945: if (!$uname) { $uname=$env{'user.name'}; }
2946: return if ($udom eq 'public' && $uname eq 'public');
2947: my $id=$uname.':'.$udom;
2948: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2949: }
2950:
1.728 raeburn 2951: # -------------------------------------------------------------------- getlangs
2952:
2953: =pod
2954:
2955: =item * &getlangs($uname,$udom)
2956:
2957: Gets a user's language preference and returns it as a hash with key:
2958: language.
2959:
2960: =cut
2961:
2962:
2963: sub getlangs {
2964: my ($uname,$udom) = @_;
2965: if (!$udom) { $udom =$env{'user.domain'}; }
2966: if (!$uname) { $uname=$env{'user.name'}; }
2967: my $id=$uname.':'.$udom;
2968: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2969: if ($cached) {
2970: return %{$langs};
2971: } else {
2972: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2973: $udom,$uname);
2974: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2975: return %loadlangs;
2976: }
2977: }
2978:
2979: sub flush_langs_cache {
2980: my ($uname,$udom)=@_;
2981: if (!$udom) { $udom =$env{'user.domain'}; }
2982: if (!$uname) { $uname=$env{'user.name'}; }
2983: return if ($udom eq 'public' && $uname eq 'public');
2984: my $id=$uname.':'.$udom;
2985: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2986: }
2987:
1.61 www 2988: # ------------------------------------------------------------------ Screenname
1.81 albertel 2989:
2990: =pod
2991:
1.648 raeburn 2992: =item * &screenname($uname,$udom)
1.81 albertel 2993:
2994: Gets a users screenname and returns it as a string
2995:
2996: =cut
1.61 www 2997:
2998: sub screenname {
2999: my ($uname,$udom)=@_;
1.258 albertel 3000: if ($uname eq $env{'user.name'} &&
3001: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3002: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3003: return $names{'screenname'};
1.62 www 3004: }
3005:
1.212 albertel 3006:
1.802 bisitz 3007: # ------------------------------------------------------------- Confirm Wrapper
3008: =pod
3009:
3010: =item confirmwrapper
3011:
3012: Wrap messages about completion of operation in box
3013:
3014: =cut
3015:
3016: sub confirmwrapper {
3017: my ($message)=@_;
3018: if ($message) {
3019: return "\n".'<div class="LC_confirm_box">'."\n"
3020: .$message."\n"
3021: .'</div>'."\n";
3022: } else {
3023: return $message;
3024: }
3025: }
3026:
1.62 www 3027: # ------------------------------------------------------------- Message Wrapper
3028:
3029: sub messagewrapper {
1.369 www 3030: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3031: return
1.441 albertel 3032: '<a href="/adm/email?compose=individual&'.
3033: 'recname='.$username.'&recdom='.$domain.
3034: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3035: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3036: }
1.802 bisitz 3037:
1.74 www 3038: # --------------------------------------------------------------- Notes Wrapper
3039:
3040: sub noteswrapper {
3041: my ($link,$un,$do)=@_;
3042: return
1.896 amueller 3043: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3044: }
1.802 bisitz 3045:
1.62 www 3046: # ------------------------------------------------------------- Aboutme Wrapper
3047:
3048: sub aboutmewrapper {
1.166 www 3049: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3050: if (!defined($username) && !defined($domain)) {
3051: return;
3052: }
1.892 amueller 3053: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3054: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3055: }
3056:
3057: # ------------------------------------------------------------ Syllabus Wrapper
3058:
3059: sub syllabuswrapper {
1.707 bisitz 3060: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3061: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3062: }
1.14 harris41 3063:
1.802 bisitz 3064: # -----------------------------------------------------------------------------
3065:
1.208 matthew 3066: sub track_student_link {
1.887 raeburn 3067: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3068: my $link ="/adm/trackstudent?";
1.208 matthew 3069: my $title = 'View recent activity';
3070: if (defined($sname) && $sname !~ /^\s*$/ &&
3071: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3072: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3073: $title .= ' of this student';
1.268 albertel 3074: }
1.208 matthew 3075: if (defined($target) && $target !~ /^\s*$/) {
3076: $target = qq{target="$target"};
3077: } else {
3078: $target = '';
3079: }
1.268 albertel 3080: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3081: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3082: $title = &mt($title);
3083: $linktext = &mt($linktext);
1.448 albertel 3084: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3085: &help_open_topic('View_recent_activity');
1.208 matthew 3086: }
3087:
1.781 raeburn 3088: sub slot_reservations_link {
3089: my ($linktext,$sname,$sdom,$target) = @_;
3090: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3091: my $title = 'View slot reservation history';
3092: if (defined($sname) && $sname !~ /^\s*$/ &&
3093: defined($sdom) && $sdom !~ /^\s*$/) {
3094: $link .= "&uname=$sname&udom=$sdom";
3095: $title .= ' of this student';
3096: }
3097: if (defined($target) && $target !~ /^\s*$/) {
3098: $target = qq{target="$target"};
3099: } else {
3100: $target = '';
3101: }
3102: $title = &mt($title);
3103: $linktext = &mt($linktext);
3104: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3105: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3106:
3107: }
3108:
1.508 www 3109: # ===================================================== Display a student photo
3110:
3111:
1.509 albertel 3112: sub student_image_tag {
1.508 www 3113: my ($domain,$user)=@_;
3114: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3115: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3116: return '<img src="'.$imgsrc.'" align="right" />';
3117: } else {
3118: return '';
3119: }
3120: }
3121:
1.112 bowersj2 3122: =pod
3123:
3124: =back
3125:
3126: =head1 Access .tab File Data
3127:
3128: =over 4
3129:
1.648 raeburn 3130: =item * &languageids()
1.112 bowersj2 3131:
3132: returns list of all language ids
3133:
3134: =cut
3135:
1.14 harris41 3136: sub languageids {
1.16 harris41 3137: return sort(keys(%language));
1.14 harris41 3138: }
3139:
1.112 bowersj2 3140: =pod
3141:
1.648 raeburn 3142: =item * &languagedescription()
1.112 bowersj2 3143:
3144: returns description of a specified language id
3145:
3146: =cut
3147:
1.14 harris41 3148: sub languagedescription {
1.125 www 3149: my $code=shift;
3150: return ($supported_language{$code}?'* ':'').
3151: $language{$code}.
1.126 www 3152: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3153: }
3154:
3155: sub plainlanguagedescription {
3156: my $code=shift;
3157: return $language{$code};
3158: }
3159:
3160: sub supportedlanguagecode {
3161: my $code=shift;
3162: return $supported_language{$code};
1.97 www 3163: }
3164:
1.112 bowersj2 3165: =pod
3166:
1.648 raeburn 3167: =item * ©rightids()
1.112 bowersj2 3168:
3169: returns list of all copyrights
3170:
3171: =cut
3172:
3173: sub copyrightids {
3174: return sort(keys(%cprtag));
3175: }
3176:
3177: =pod
3178:
1.648 raeburn 3179: =item * ©rightdescription()
1.112 bowersj2 3180:
3181: returns description of a specified copyright id
3182:
3183: =cut
3184:
3185: sub copyrightdescription {
1.166 www 3186: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3187: }
1.197 matthew 3188:
3189: =pod
3190:
1.648 raeburn 3191: =item * &source_copyrightids()
1.192 taceyjo1 3192:
3193: returns list of all source copyrights
3194:
3195: =cut
3196:
3197: sub source_copyrightids {
3198: return sort(keys(%scprtag));
3199: }
3200:
3201: =pod
3202:
1.648 raeburn 3203: =item * &source_copyrightdescription()
1.192 taceyjo1 3204:
3205: returns description of a specified source copyright id
3206:
3207: =cut
3208:
3209: sub source_copyrightdescription {
3210: return &mt($scprtag{shift(@_)});
3211: }
1.112 bowersj2 3212:
3213: =pod
3214:
1.648 raeburn 3215: =item * &filecategories()
1.112 bowersj2 3216:
3217: returns list of all file categories
3218:
3219: =cut
3220:
3221: sub filecategories {
3222: return sort(keys(%category_extensions));
3223: }
3224:
3225: =pod
3226:
1.648 raeburn 3227: =item * &filecategorytypes()
1.112 bowersj2 3228:
3229: returns list of file types belonging to a given file
3230: category
3231:
3232: =cut
3233:
3234: sub filecategorytypes {
1.356 albertel 3235: my ($cat) = @_;
3236: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3237: }
3238:
3239: =pod
3240:
1.648 raeburn 3241: =item * &fileembstyle()
1.112 bowersj2 3242:
3243: returns embedding style for a specified file type
3244:
3245: =cut
3246:
3247: sub fileembstyle {
3248: return $fe{lc(shift(@_))};
1.169 www 3249: }
3250:
1.351 www 3251: sub filemimetype {
3252: return $fm{lc(shift(@_))};
3253: }
3254:
1.169 www 3255:
3256: sub filecategoryselect {
3257: my ($name,$value)=@_;
1.189 matthew 3258: return &select_form($value,$name,
1.169 www 3259: '' => &mt('Any category'),
1.948.2.7 raeburn 3260: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3261: }
3262:
3263: =pod
3264:
1.648 raeburn 3265: =item * &filedescription()
1.112 bowersj2 3266:
3267: returns description for a specified file type
3268:
3269: =cut
3270:
3271: sub filedescription {
1.188 matthew 3272: my $file_description = $fd{lc(shift())};
3273: $file_description =~ s:([\[\]]):~$1:g;
3274: return &mt($file_description);
1.112 bowersj2 3275: }
3276:
3277: =pod
3278:
1.648 raeburn 3279: =item * &filedescriptionex()
1.112 bowersj2 3280:
3281: returns description for a specified file type with
3282: extra formatting
3283:
3284: =cut
3285:
3286: sub filedescriptionex {
3287: my $ex=shift;
1.188 matthew 3288: my $file_description = $fd{lc($ex)};
3289: $file_description =~ s:([\[\]]):~$1:g;
3290: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3291: }
3292:
3293: # End of .tab access
3294: =pod
3295:
3296: =back
3297:
3298: =cut
3299:
3300: # ------------------------------------------------------------------ File Types
3301: sub fileextensions {
3302: return sort(keys(%fe));
3303: }
3304:
1.97 www 3305: # ----------------------------------------------------------- Display Languages
3306: # returns a hash with all desired display languages
3307: #
3308:
3309: sub display_languages {
3310: my %languages=();
1.695 raeburn 3311: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3312: $languages{$lang}=1;
1.97 www 3313: }
3314: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3315: if ($env{'form.displaylanguage'}) {
1.356 albertel 3316: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3317: $languages{$lang}=1;
1.97 www 3318: }
3319: }
3320: return %languages;
1.14 harris41 3321: }
3322:
1.582 albertel 3323: sub languages {
3324: my ($possible_langs) = @_;
1.695 raeburn 3325: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3326: if (!ref($possible_langs)) {
3327: if( wantarray ) {
3328: return @preferred_langs;
3329: } else {
3330: return $preferred_langs[0];
3331: }
3332: }
3333: my %possibilities = map { $_ => 1 } (@$possible_langs);
3334: my @preferred_possibilities;
3335: foreach my $preferred_lang (@preferred_langs) {
3336: if (exists($possibilities{$preferred_lang})) {
3337: push(@preferred_possibilities, $preferred_lang);
3338: }
3339: }
3340: if( wantarray ) {
3341: return @preferred_possibilities;
3342: }
3343: return $preferred_possibilities[0];
3344: }
3345:
1.742 raeburn 3346: sub user_lang {
3347: my ($touname,$toudom,$fromcid) = @_;
3348: my @userlangs;
3349: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3350: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3351: $env{'course.'.$fromcid.'.languages'}));
3352: } else {
3353: my %langhash = &getlangs($touname,$toudom);
3354: if ($langhash{'languages'} ne '') {
3355: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3356: } else {
3357: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3358: if ($domdefs{'lang_def'} ne '') {
3359: @userlangs = ($domdefs{'lang_def'});
3360: }
3361: }
3362: }
3363: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3364: my $user_lh = Apache::localize->get_handle(@languages);
3365: return $user_lh;
3366: }
3367:
3368:
1.112 bowersj2 3369: ###############################################################
3370: ## Student Answer Attempts ##
3371: ###############################################################
3372:
3373: =pod
3374:
3375: =head1 Alternate Problem Views
3376:
3377: =over 4
3378:
1.648 raeburn 3379: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3380: $getattempt, $regexp, $gradesub)
3381:
3382: Return string with previous attempt on problem. Arguments:
3383:
3384: =over 4
3385:
3386: =item * $symb: Problem, including path
3387:
3388: =item * $username: username of the desired student
3389:
3390: =item * $domain: domain of the desired student
1.14 harris41 3391:
1.112 bowersj2 3392: =item * $course: Course ID
1.14 harris41 3393:
1.112 bowersj2 3394: =item * $getattempt: Leave blank for all attempts, otherwise put
3395: something
1.14 harris41 3396:
1.112 bowersj2 3397: =item * $regexp: if string matches this regexp, the string will be
3398: sent to $gradesub
1.14 harris41 3399:
1.112 bowersj2 3400: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3401:
1.112 bowersj2 3402: =back
1.14 harris41 3403:
1.112 bowersj2 3404: The output string is a table containing all desired attempts, if any.
1.16 harris41 3405:
1.112 bowersj2 3406: =cut
1.1 albertel 3407:
3408: sub get_previous_attempt {
1.43 ng 3409: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3410: my $prevattempts='';
1.43 ng 3411: no strict 'refs';
1.1 albertel 3412: if ($symb) {
1.3 albertel 3413: my (%returnhash)=
3414: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3415: if ($returnhash{'version'}) {
3416: my %lasthash=();
3417: my $version;
3418: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3419: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3420: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3421: }
1.1 albertel 3422: }
1.596 albertel 3423: $prevattempts=&start_data_table().&start_data_table_header_row();
3424: $prevattempts.='<th>'.&mt('History').'</th>';
1.948.2.8 raeburn 3425: my (%typeparts,%lasthidden);
1.945 raeburn 3426: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3427: foreach my $key (sort(keys(%lasthash))) {
3428: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3429: if ($#parts > 0) {
1.31 albertel 3430: my $data=$parts[-1];
3431: pop(@parts);
1.945 raeburn 3432: if ($data eq 'type') {
3433: unless ($showsurv) {
3434: my $id = join(',',@parts);
3435: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.948.2.8 raeburn 3436: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3437: $lasthidden{$ign.'.'.$id} = 1;
3438: }
1.945 raeburn 3439: }
3440: delete($lasthash{$key});
3441: } else {
3442: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3443: }
1.31 albertel 3444: } else {
1.41 ng 3445: if ($#parts == 0) {
3446: $prevattempts.='<th>'.$parts[0].'</th>';
3447: } else {
3448: $prevattempts.='<th>'.$ign.'</th>';
3449: }
1.31 albertel 3450: }
1.16 harris41 3451: }
1.596 albertel 3452: $prevattempts.=&end_data_table_header_row();
1.40 ng 3453: if ($getattempt eq '') {
3454: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3455: my @hidden;
3456: if (%typeparts) {
3457: foreach my $id (keys(%typeparts)) {
3458: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3459: push(@hidden,$id);
3460: }
3461: }
3462: }
3463: $prevattempts.=&start_data_table_row().
3464: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3465: if (@hidden) {
3466: foreach my $key (sort(keys(%lasthash))) {
3467: my $hide;
3468: foreach my $id (@hidden) {
3469: if ($key =~ /^\Q$id\E/) {
3470: $hide = 1;
3471: last;
3472: }
3473: }
3474: if ($hide) {
3475: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3476: if (($data eq 'award') || ($data eq 'awarddetail')) {
3477: my $value = &format_previous_attempt_value($key,
3478: $returnhash{$version.':'.$key});
3479: $prevattempts.='<td>'.$value.' </td>';
3480: } else {
3481: $prevattempts.='<td> </td>';
3482: }
3483: } else {
3484: if ($key =~ /\./) {
3485: my $value = &format_previous_attempt_value($key,
3486: $returnhash{$version.':'.$key});
3487: $prevattempts.='<td>'.$value.' </td>';
3488: } else {
3489: $prevattempts.='<td> </td>';
3490: }
3491: }
3492: }
3493: } else {
3494: foreach my $key (sort(keys(%lasthash))) {
3495: my $value = &format_previous_attempt_value($key,
3496: $returnhash{$version.':'.$key});
3497: $prevattempts.='<td>'.$value.' </td>';
3498: }
3499: }
3500: $prevattempts.=&end_data_table_row();
1.40 ng 3501: }
1.1 albertel 3502: }
1.945 raeburn 3503: my @currhidden = keys(%lasthidden);
1.596 albertel 3504: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3505: foreach my $key (sort(keys(%lasthash))) {
1.945 raeburn 3506: if (%typeparts) {
3507: my $hidden;
3508: foreach my $id (@currhidden) {
3509: if ($key =~ /^\Q$id\E/) {
3510: $hidden = 1;
3511: last;
3512: }
3513: }
3514: if ($hidden) {
3515: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3516: if (($data eq 'award') || ($data eq 'awarddetail')) {
3517: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3518: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3519: $value = &$gradesub($value);
3520: }
3521: $prevattempts.='<td>'.$value.' </td>';
3522: } else {
3523: $prevattempts.='<td> </td>';
3524: }
3525: } else {
3526: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3527: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3528: $value = &$gradesub($value);
3529: }
3530: $prevattempts.='<td>'.$value.' </td>';
3531: }
3532: } else {
3533: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3534: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3535: $value = &$gradesub($value);
3536: }
3537: $prevattempts.='<td>'.$value.' </td>';
3538: }
1.16 harris41 3539: }
1.596 albertel 3540: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3541: } else {
1.596 albertel 3542: $prevattempts=
3543: &start_data_table().&start_data_table_row().
3544: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3545: &end_data_table_row().&end_data_table();
1.1 albertel 3546: }
3547: } else {
1.596 albertel 3548: $prevattempts=
3549: &start_data_table().&start_data_table_row().
3550: '<td>'.&mt('No data.').'</td>'.
3551: &end_data_table_row().&end_data_table();
1.1 albertel 3552: }
1.10 albertel 3553: }
3554:
1.581 albertel 3555: sub format_previous_attempt_value {
3556: my ($key,$value) = @_;
3557: if ($key =~ /timestamp/) {
3558: $value = &Apache::lonlocal::locallocaltime($value);
3559: } elsif (ref($value) eq 'ARRAY') {
3560: $value = '('.join(', ', @{ $value }).')';
3561: } else {
3562: $value = &unescape($value);
3563: }
3564: return $value;
3565: }
3566:
3567:
1.107 albertel 3568: sub relative_to_absolute {
3569: my ($url,$output)=@_;
3570: my $parser=HTML::TokeParser->new(\$output);
3571: my $token;
3572: my $thisdir=$url;
3573: my @rlinks=();
3574: while ($token=$parser->get_token) {
3575: if ($token->[0] eq 'S') {
3576: if ($token->[1] eq 'a') {
3577: if ($token->[2]->{'href'}) {
3578: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3579: }
3580: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3581: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3582: } elsif ($token->[1] eq 'base') {
3583: $thisdir=$token->[2]->{'href'};
3584: }
3585: }
3586: }
3587: $thisdir=~s-/[^/]*$--;
1.356 albertel 3588: foreach my $link (@rlinks) {
1.726 raeburn 3589: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3590: ($link=~/^\//) ||
3591: ($link=~/^javascript:/i) ||
3592: ($link=~/^mailto:/i) ||
3593: ($link=~/^\#/)) {
3594: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3595: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3596: }
3597: }
3598: # -------------------------------------------------- Deal with Applet codebases
3599: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3600: return $output;
3601: }
3602:
1.112 bowersj2 3603: =pod
3604:
1.648 raeburn 3605: =item * &get_student_view()
1.112 bowersj2 3606:
3607: show a snapshot of what student was looking at
3608:
3609: =cut
3610:
1.10 albertel 3611: sub get_student_view {
1.186 albertel 3612: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3613: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3614: my (%form);
1.10 albertel 3615: my @elements=('symb','courseid','domain','username');
3616: foreach my $element (@elements) {
1.186 albertel 3617: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3618: }
1.186 albertel 3619: if (defined($moreenv)) {
3620: %form=(%form,%{$moreenv});
3621: }
1.236 albertel 3622: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3623: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3624: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3625: $userview=~s/\<body[^\>]*\>//gi;
3626: $userview=~s/\<\/body\>//gi;
3627: $userview=~s/\<html\>//gi;
3628: $userview=~s/\<\/html\>//gi;
3629: $userview=~s/\<head\>//gi;
3630: $userview=~s/\<\/head\>//gi;
3631: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3632: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3633: if (wantarray) {
3634: return ($userview,$response);
3635: } else {
3636: return $userview;
3637: }
3638: }
3639:
3640: sub get_student_view_with_retries {
3641: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3642:
3643: my $ok = 0; # True if we got a good response.
3644: my $content;
3645: my $response;
3646:
3647: # Try to get the student_view done. within the retries count:
3648:
3649: do {
3650: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3651: $ok = $response->is_success;
3652: if (!$ok) {
3653: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3654: }
3655: $retries--;
3656: } while (!$ok && ($retries > 0));
3657:
3658: if (!$ok) {
3659: $content = ''; # On error return an empty content.
3660: }
1.651 www 3661: if (wantarray) {
3662: return ($content, $response);
3663: } else {
3664: return $content;
3665: }
1.11 albertel 3666: }
3667:
1.112 bowersj2 3668: =pod
3669:
1.648 raeburn 3670: =item * &get_student_answers()
1.112 bowersj2 3671:
3672: show a snapshot of how student was answering problem
3673:
3674: =cut
3675:
1.11 albertel 3676: sub get_student_answers {
1.100 sakharuk 3677: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3678: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3679: my (%moreenv);
1.11 albertel 3680: my @elements=('symb','courseid','domain','username');
3681: foreach my $element (@elements) {
1.186 albertel 3682: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3683: }
1.186 albertel 3684: $moreenv{'grade_target'}='answer';
3685: %moreenv=(%form,%moreenv);
1.497 raeburn 3686: $feedurl = &Apache::lonnet::clutter($feedurl);
3687: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3688: return $userview;
1.1 albertel 3689: }
1.116 albertel 3690:
3691: =pod
3692:
3693: =item * &submlink()
3694:
1.242 albertel 3695: Inputs: $text $uname $udom $symb $target
1.116 albertel 3696:
3697: Returns: A link to grades.pm such as to see the SUBM view of a student
3698:
3699: =cut
3700:
3701: ###############################################
3702: sub submlink {
1.242 albertel 3703: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3704: if (!($uname && $udom)) {
3705: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3706: &Apache::lonnet::whichuser($symb);
1.116 albertel 3707: if (!$symb) { $symb=$cursymb; }
3708: }
1.254 matthew 3709: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3710: $symb=&escape($symb);
1.948.2.4 raeburn 3711: if ($target) { $target=" target=\"$target\""; }
3712: return
3713: '<a href="/adm/grades?command=submission'.
3714: '&symb='.$symb.
3715: '&student='.$uname.
3716: '&userdom='.$udom.'"'.
3717: $target.'>'.$text.'</a>';
1.242 albertel 3718: }
3719: ##############################################
3720:
3721: =pod
3722:
3723: =item * &pgrdlink()
3724:
3725: Inputs: $text $uname $udom $symb $target
3726:
3727: Returns: A link to grades.pm such as to see the PGRD view of a student
3728:
3729: =cut
3730:
3731: ###############################################
3732: sub pgrdlink {
3733: my $link=&submlink(@_);
3734: $link=~s/(&command=submission)/$1&showgrading=yes/;
3735: return $link;
3736: }
3737: ##############################################
3738:
3739: =pod
3740:
3741: =item * &pprmlink()
3742:
3743: Inputs: $text $uname $udom $symb $target
3744:
3745: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3746: student and a specific resource
1.242 albertel 3747:
3748: =cut
3749:
3750: ###############################################
3751: sub pprmlink {
3752: my ($text,$uname,$udom,$symb,$target)=@_;
3753: if (!($uname && $udom)) {
3754: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3755: &Apache::lonnet::whichuser($symb);
1.242 albertel 3756: if (!$symb) { $symb=$cursymb; }
3757: }
1.254 matthew 3758: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3759: $symb=&escape($symb);
1.242 albertel 3760: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3761: return '<a href="/adm/parmset?command=set&'.
3762: 'symb='.$symb.'&uname='.$uname.
3763: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3764: }
3765: ##############################################
1.37 matthew 3766:
1.112 bowersj2 3767: =pod
3768:
3769: =back
3770:
3771: =cut
3772:
1.37 matthew 3773: ###############################################
1.51 www 3774:
3775:
3776: sub timehash {
1.687 raeburn 3777: my ($thistime) = @_;
3778: my $timezone = &Apache::lonlocal::gettimezone();
3779: my $dt = DateTime->from_epoch(epoch => $thistime)
3780: ->set_time_zone($timezone);
3781: my $wday = $dt->day_of_week();
3782: if ($wday == 7) { $wday = 0; }
3783: return ( 'second' => $dt->second(),
3784: 'minute' => $dt->minute(),
3785: 'hour' => $dt->hour(),
3786: 'day' => $dt->day_of_month(),
3787: 'month' => $dt->month(),
3788: 'year' => $dt->year(),
3789: 'weekday' => $wday,
3790: 'dayyear' => $dt->day_of_year(),
3791: 'dlsav' => $dt->is_dst() );
1.51 www 3792: }
3793:
1.370 www 3794: sub utc_string {
3795: my ($date)=@_;
1.371 www 3796: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3797: }
3798:
1.51 www 3799: sub maketime {
3800: my %th=@_;
1.687 raeburn 3801: my ($epoch_time,$timezone,$dt);
3802: $timezone = &Apache::lonlocal::gettimezone();
3803: eval {
3804: $dt = DateTime->new( year => $th{'year'},
3805: month => $th{'month'},
3806: day => $th{'day'},
3807: hour => $th{'hour'},
3808: minute => $th{'minute'},
3809: second => $th{'second'},
3810: time_zone => $timezone,
3811: );
3812: };
3813: if (!$@) {
3814: $epoch_time = $dt->epoch;
3815: if ($epoch_time) {
3816: return $epoch_time;
3817: }
3818: }
1.51 www 3819: return POSIX::mktime(
3820: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3821: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3822: }
3823:
3824: #########################################
1.51 www 3825:
3826: sub findallcourses {
1.482 raeburn 3827: my ($roles,$uname,$udom) = @_;
1.355 albertel 3828: my %roles;
3829: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3830: my %courses;
1.51 www 3831: my $now=time;
1.482 raeburn 3832: if (!defined($uname)) {
3833: $uname = $env{'user.name'};
3834: }
3835: if (!defined($udom)) {
3836: $udom = $env{'user.domain'};
3837: }
3838: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.948.2.11! raeburn 3839: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
! 3840: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
! 3841: $extra);
1.482 raeburn 3842: if (!%roles) {
3843: %roles = (
3844: cc => 1,
1.907 raeburn 3845: co => 1,
1.482 raeburn 3846: in => 1,
3847: ep => 1,
3848: ta => 1,
3849: cr => 1,
3850: st => 1,
3851: );
3852: }
3853: foreach my $entry (keys(%roleshash)) {
3854: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3855: if ($trole =~ /^cr/) {
3856: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3857: } else {
3858: next if (!exists($roles{$trole}));
3859: }
3860: if ($tend) {
3861: next if ($tend < $now);
3862: }
3863: if ($tstart) {
3864: next if ($tstart > $now);
3865: }
3866: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3867: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3868: if ($secpart eq '') {
3869: ($cnum,$role) = split(/_/,$cnumpart);
3870: $sec = 'none';
3871: $realsec = '';
3872: } else {
3873: $cnum = $cnumpart;
3874: ($sec,$role) = split(/_/,$secpart);
3875: $realsec = $sec;
1.490 raeburn 3876: }
1.482 raeburn 3877: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3878: }
3879: } else {
3880: foreach my $key (keys(%env)) {
1.483 albertel 3881: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3882: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3883: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3884: next if ($role eq 'ca' || $role eq 'aa');
3885: next if (%roles && !exists($roles{$role}));
3886: my ($starttime,$endtime)=split(/\./,$env{$key});
3887: my $active=1;
3888: if ($starttime) {
3889: if ($now<$starttime) { $active=0; }
3890: }
3891: if ($endtime) {
3892: if ($now>$endtime) { $active=0; }
3893: }
3894: if ($active) {
3895: if ($sec eq '') {
3896: $sec = 'none';
3897: }
3898: $courses{$cdom.'_'.$cnum}{$sec} =
3899: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3900: }
3901: }
1.51 www 3902: }
3903: }
1.474 raeburn 3904: return %courses;
1.51 www 3905: }
1.37 matthew 3906:
1.54 www 3907: ###############################################
1.474 raeburn 3908:
3909: sub blockcheck {
1.482 raeburn 3910: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3911:
3912: if (!defined($udom)) {
3913: $udom = $env{'user.domain'};
3914: }
3915: if (!defined($uname)) {
3916: $uname = $env{'user.name'};
3917: }
3918:
3919: # If uname and udom are for a course, check for blocks in the course.
3920:
3921: if (&Apache::lonnet::is_course($udom,$uname)) {
3922: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3923: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3924: return ($startblock,$endblock);
3925: }
1.474 raeburn 3926:
1.502 raeburn 3927: my $startblock = 0;
3928: my $endblock = 0;
1.482 raeburn 3929: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3930:
1.490 raeburn 3931: # If uname is for a user, and activity is course-specific, i.e.,
3932: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3933:
1.490 raeburn 3934: if (($activity eq 'boards' || $activity eq 'chat' ||
3935: $activity eq 'groups') && ($env{'request.course.id'})) {
3936: foreach my $key (keys(%live_courses)) {
3937: if ($key ne $env{'request.course.id'}) {
3938: delete($live_courses{$key});
3939: }
3940: }
3941: }
3942:
3943: my $otheruser = 0;
3944: my %own_courses;
3945: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3946: # Resource belongs to user other than current user.
3947: $otheruser = 1;
3948: # Gather courses for current user
3949: %own_courses =
3950: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3951: }
3952:
3953: # Gather active course roles - course coordinator, instructor,
3954: # exam proctor, ta, student, or custom role.
1.474 raeburn 3955:
3956: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3957: my ($cdom,$cnum);
3958: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3959: $cdom = $env{'course.'.$course.'.domain'};
3960: $cnum = $env{'course.'.$course.'.num'};
3961: } else {
1.490 raeburn 3962: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3963: }
3964: my $no_ownblock = 0;
3965: my $no_userblock = 0;
1.533 raeburn 3966: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3967: # Check if current user has 'evb' priv for this
3968: if (defined($own_courses{$course})) {
3969: foreach my $sec (keys(%{$own_courses{$course}})) {
3970: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3971: if ($sec ne 'none') {
3972: $checkrole .= '/'.$sec;
3973: }
3974: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3975: $no_ownblock = 1;
3976: last;
3977: }
3978: }
3979: }
3980: # if they have 'evb' priv and are currently not playing student
3981: next if (($no_ownblock) &&
3982: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3983: }
1.474 raeburn 3984: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3985: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3986: if ($sec ne 'none') {
1.482 raeburn 3987: $checkrole .= '/'.$sec;
1.474 raeburn 3988: }
1.490 raeburn 3989: if ($otheruser) {
3990: # Resource belongs to user other than current user.
3991: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3992: my ($trole,$tdom,$tnum,$tsec);
3993: my $entry = $live_courses{$course}{$sec};
3994: if ($entry =~ /^cr/) {
3995: ($trole,$tdom,$tnum,$tsec) =
3996: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3997: } else {
3998: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3999: }
4000: my ($spec,$area,$trest,%allroles,%userroles);
4001: $area = '/'.$tdom.'/'.$tnum;
4002: $trest = $tnum;
4003: if ($tsec ne '') {
4004: $area .= '/'.$tsec;
4005: $trest .= '/'.$tsec;
4006: }
4007: $spec = $trole.'.'.$area;
4008: if ($trole =~ /^cr/) {
4009: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4010: $tdom,$spec,$trest,$area);
4011: } else {
4012: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4013: $tdom,$spec,$trest,$area);
4014: }
4015: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4016: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4017: if ($1) {
4018: $no_userblock = 1;
4019: last;
4020: }
4021: }
1.490 raeburn 4022: } else {
4023: # Resource belongs to current user
4024: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4025: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4026: $no_ownblock = 1;
4027: last;
4028: }
1.474 raeburn 4029: }
4030: }
4031: # if they have the evb priv and are currently not playing student
1.482 raeburn 4032: next if (($no_ownblock) &&
1.491 albertel 4033: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4034: next if ($no_userblock);
1.474 raeburn 4035:
1.866 kalberla 4036: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4037: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4038:
4039: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4040: if (($start != 0) &&
4041: (($startblock == 0) || ($startblock > $start))) {
4042: $startblock = $start;
4043: }
4044: if (($end != 0) &&
4045: (($endblock == 0) || ($endblock < $end))) {
4046: $endblock = $end;
4047: }
1.490 raeburn 4048: }
4049: return ($startblock,$endblock);
4050: }
4051:
4052: sub get_blocks {
4053: my ($setters,$activity,$cdom,$cnum) = @_;
4054: my $startblock = 0;
4055: my $endblock = 0;
4056: my $course = $cdom.'_'.$cnum;
4057: $setters->{$course} = {};
4058: $setters->{$course}{'staff'} = [];
4059: $setters->{$course}{'times'} = [];
4060: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4061: foreach my $record (keys(%records)) {
4062: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4063: if ($start <= time && $end >= time) {
4064: my ($staff_name,$staff_dom,$title,$blocks) =
4065: &parse_block_record($records{$record});
4066: if ($blocks->{$activity} eq 'on') {
4067: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4068: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4069: if ( ($startblock == 0) || ($startblock > $start) ) {
4070: $startblock = $start;
1.490 raeburn 4071: }
1.491 albertel 4072: if ( ($endblock == 0) || ($endblock < $end) ) {
4073: $endblock = $end;
1.474 raeburn 4074: }
4075: }
4076: }
4077: }
4078: return ($startblock,$endblock);
4079: }
4080:
4081: sub parse_block_record {
4082: my ($record) = @_;
4083: my ($setuname,$setudom,$title,$blocks);
4084: if (ref($record) eq 'HASH') {
4085: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4086: $title = &unescape($record->{'event'});
4087: $blocks = $record->{'blocks'};
4088: } else {
4089: my @data = split(/:/,$record,3);
4090: if (scalar(@data) eq 2) {
4091: $title = $data[1];
4092: ($setuname,$setudom) = split(/@/,$data[0]);
4093: } else {
4094: ($setuname,$setudom,$title) = @data;
4095: }
4096: $blocks = { 'com' => 'on' };
4097: }
4098: return ($setuname,$setudom,$title,$blocks);
4099: }
4100:
1.854 kalberla 4101: sub blocking_status {
4102: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4103: my %setters;
1.890 droeschl 4104:
4105: # check for active blocking
1.867 kalberla 4106: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4107:
1.890 droeschl 4108: my $blocked = $startblock && $endblock ? 1 : 0;
4109:
4110: # caller just wants to know whether a block is active
4111: if (!wantarray) { return $blocked; }
4112:
4113: # build a link to a popup window containing the details
4114: my $querystring = "?activity=$activity";
4115: # $uname and $udom decide whose portfolio the user is trying to look at
4116: $querystring .= "&udom=$udom" if $udom;
4117: $querystring .= "&uname=$uname" if $uname;
4118:
4119: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4120: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4121: var options = "width=" + w + ",height=" + h + ",";
4122: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4123: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4124: var newWin = window.open(url, wdwName, options);
4125: newWin.focus();
4126: }
1.890 droeschl 4127: END_MYBLOCK
1.854 kalberla 4128:
1.890 droeschl 4129: $output = Apache::lonhtmlcommon::scripttag($output);
4130:
1.854 kalberla 4131: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4132: my $text = mt('Communication Blocked');
4133:
1.867 kalberla 4134: $output .= <<"END_BLOCK";
4135: <div class='LC_comblock'>
1.869 kalberla 4136: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4137: title='$text'>
4138: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4139: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4140: title='$text'>$text</a>
1.867 kalberla 4141: </div>
4142:
4143: END_BLOCK
1.474 raeburn 4144:
1.854 kalberla 4145: return ($blocked, $output);
4146: }
1.490 raeburn 4147:
1.60 matthew 4148: ###############################################
4149:
1.682 raeburn 4150: sub check_ip_acc {
4151: my ($acc)=@_;
4152: &Apache::lonxml::debug("acc is $acc");
4153: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4154: return 1;
4155: }
4156: my $allowed=0;
4157: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4158:
4159: my $name;
4160: foreach my $pattern (split(',',$acc)) {
4161: $pattern =~ s/^\s*//;
4162: $pattern =~ s/\s*$//;
4163: if ($pattern =~ /\*$/) {
4164: #35.8.*
4165: $pattern=~s/\*//;
4166: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4167: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4168: #35.8.3.[34-56]
4169: my $low=$2;
4170: my $high=$3;
4171: $pattern=$1;
4172: if ($ip =~ /^\Q$pattern\E/) {
4173: my $last=(split(/\./,$ip))[3];
4174: if ($last <=$high && $last >=$low) { $allowed=1; }
4175: }
4176: } elsif ($pattern =~ /^\*/) {
4177: #*.msu.edu
4178: $pattern=~s/\*//;
4179: if (!defined($name)) {
4180: use Socket;
4181: my $netaddr=inet_aton($ip);
4182: ($name)=gethostbyaddr($netaddr,AF_INET);
4183: }
4184: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4185: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4186: #127.0.0.1
4187: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4188: } else {
4189: #some.name.com
4190: if (!defined($name)) {
4191: use Socket;
4192: my $netaddr=inet_aton($ip);
4193: ($name)=gethostbyaddr($netaddr,AF_INET);
4194: }
4195: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4196: }
4197: if ($allowed) { last; }
4198: }
4199: return $allowed;
4200: }
4201:
4202: ###############################################
4203:
1.60 matthew 4204: =pod
4205:
1.112 bowersj2 4206: =head1 Domain Template Functions
4207:
4208: =over 4
4209:
4210: =item * &determinedomain()
1.60 matthew 4211:
4212: Inputs: $domain (usually will be undef)
4213:
1.63 www 4214: Returns: Determines which domain should be used for designs
1.60 matthew 4215:
4216: =cut
1.54 www 4217:
1.60 matthew 4218: ###############################################
1.63 www 4219: sub determinedomain {
4220: my $domain=shift;
1.531 albertel 4221: if (! $domain) {
1.60 matthew 4222: # Determine domain if we have not been given one
1.893 raeburn 4223: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4224: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4225: if ($env{'request.role.domain'}) {
4226: $domain=$env{'request.role.domain'};
1.60 matthew 4227: }
4228: }
1.63 www 4229: return $domain;
4230: }
4231: ###############################################
1.517 raeburn 4232:
1.518 albertel 4233: sub devalidate_domconfig_cache {
4234: my ($udom)=@_;
4235: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4236: }
4237:
4238: # ---------------------- Get domain configuration for a domain
4239: sub get_domainconf {
4240: my ($udom) = @_;
4241: my $cachetime=1800;
4242: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4243: if (defined($cached)) { return %{$result}; }
4244:
4245: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4246: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4247: my (%designhash,%legacy);
1.518 albertel 4248: if (keys(%domconfig) > 0) {
4249: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4250: if (keys(%{$domconfig{'login'}})) {
4251: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4252: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4253: if ($key eq 'loginvia') {
4254: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4255: my @ids = &Apache::lonnet::current_machine_ids();
4256: foreach my $hostname (@ids) {
1.948 raeburn 4257: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4258: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4259: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4260: $designhash{$udom.'.login.loginvia'} = $server;
4261: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4262:
4263: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4264: } else {
4265: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4266: }
4267: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4268: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4269: }
1.946 raeburn 4270: }
4271: }
4272: }
4273: }
4274: } else {
4275: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4276: $designhash{$udom.'.login.'.$key.'_'.$img} =
4277: $domconfig{'login'}{$key}{$img};
4278: }
1.699 raeburn 4279: }
4280: } else {
4281: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4282: }
1.632 raeburn 4283: }
4284: } else {
4285: $legacy{'login'} = 1;
1.518 albertel 4286: }
1.632 raeburn 4287: } else {
4288: $legacy{'login'} = 1;
1.518 albertel 4289: }
4290: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4291: if (keys(%{$domconfig{'rolecolors'}})) {
4292: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4293: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4294: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4295: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4296: }
1.518 albertel 4297: }
4298: }
1.632 raeburn 4299: } else {
4300: $legacy{'rolecolors'} = 1;
1.518 albertel 4301: }
1.632 raeburn 4302: } else {
4303: $legacy{'rolecolors'} = 1;
1.518 albertel 4304: }
1.948 raeburn 4305: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4306: if ($domconfig{'autoenroll'}{'co-owners'}) {
4307: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4308: }
4309: }
1.632 raeburn 4310: if (keys(%legacy) > 0) {
4311: my %legacyhash = &get_legacy_domconf($udom);
4312: foreach my $item (keys(%legacyhash)) {
4313: if ($item =~ /^\Q$udom\E\.login/) {
4314: if ($legacy{'login'}) {
4315: $designhash{$item} = $legacyhash{$item};
4316: }
4317: } else {
4318: if ($legacy{'rolecolors'}) {
4319: $designhash{$item} = $legacyhash{$item};
4320: }
1.518 albertel 4321: }
4322: }
4323: }
1.632 raeburn 4324: } else {
4325: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4326: }
4327: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4328: $cachetime);
4329: return %designhash;
4330: }
4331:
1.632 raeburn 4332: sub get_legacy_domconf {
4333: my ($udom) = @_;
4334: my %legacyhash;
4335: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4336: my $designfile = $designdir.'/'.$udom.'.tab';
4337: if (-e $designfile) {
4338: if ( open (my $fh,"<$designfile") ) {
4339: while (my $line = <$fh>) {
4340: next if ($line =~ /^\#/);
4341: chomp($line);
4342: my ($key,$val)=(split(/\=/,$line));
4343: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4344: }
4345: close($fh);
4346: }
4347: }
4348: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4349: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4350: }
4351: return %legacyhash;
4352: }
4353:
1.63 www 4354: =pod
4355:
1.112 bowersj2 4356: =item * &domainlogo()
1.63 www 4357:
4358: Inputs: $domain (usually will be undef)
4359:
4360: Returns: A link to a domain logo, if the domain logo exists.
4361: If the domain logo does not exist, a description of the domain.
4362:
4363: =cut
1.112 bowersj2 4364:
1.63 www 4365: ###############################################
4366: sub domainlogo {
1.517 raeburn 4367: my $domain = &determinedomain(shift);
1.518 albertel 4368: my %designhash = &get_domainconf($domain);
1.517 raeburn 4369: # See if there is a logo
4370: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4371: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4372: if ($imgsrc =~ m{^/(adm|res)/}) {
4373: if ($imgsrc =~ m{^/res/}) {
4374: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4375: &Apache::lonnet::repcopy($local_name);
4376: }
4377: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4378: }
4379: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4380: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4381: return &Apache::lonnet::domain($domain,'description');
1.59 www 4382: } else {
1.60 matthew 4383: return '';
1.59 www 4384: }
4385: }
1.63 www 4386: ##############################################
4387:
4388: =pod
4389:
1.112 bowersj2 4390: =item * &designparm()
1.63 www 4391:
4392: Inputs: $which parameter; $domain (usually will be undef)
4393:
4394: Returns: value of designparamter $which
4395:
4396: =cut
1.112 bowersj2 4397:
1.397 albertel 4398:
1.400 albertel 4399: ##############################################
1.397 albertel 4400: sub designparm {
4401: my ($which,$domain)=@_;
4402: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4403: return $env{'environment.color.'.$which};
1.96 www 4404: }
1.63 www 4405: $domain=&determinedomain($domain);
1.518 albertel 4406: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4407: my $output;
1.517 raeburn 4408: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4409: $output = $domdesign{$domain.'.'.$which};
1.63 www 4410: } else {
1.520 raeburn 4411: $output = $defaultdesign{$which};
4412: }
4413: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4414: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4415: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4416: if ($output =~ m{^/res/}) {
4417: my $local_name = &Apache::lonnet::filelocation('',$output);
4418: &Apache::lonnet::repcopy($local_name);
4419: }
1.520 raeburn 4420: $output = &lonhttpdurl($output);
4421: }
1.63 www 4422: }
1.520 raeburn 4423: return $output;
1.63 www 4424: }
1.59 www 4425:
1.822 bisitz 4426: ##############################################
4427: =pod
4428:
1.832 bisitz 4429: =item * &authorspace()
4430:
4431: Inputs: ./.
4432:
4433: Returns: Path to the Construction Space of the current user's
4434: accessed author space
4435: The author space will be that of the current user
4436: when accessing the own author space
4437: and that of the co-author/assistent co-author
4438: when accessing the co-author's/assistent co-author's
4439: space
4440:
4441: =cut
4442:
4443: sub authorspace {
4444: my $caname = '';
4445: if ($env{'request.role'} =~ /^ca|^aa/) {
4446: (undef,$caname) =
4447: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4448: } else {
4449: $caname = $env{'user.name'};
4450: }
4451: return '/priv/'.$caname.'/';
4452: }
4453:
4454: ##############################################
4455: =pod
4456:
1.822 bisitz 4457: =item * &head_subbox()
4458:
4459: Inputs: $content (contains HTML code with page functions, etc.)
4460:
4461: Returns: HTML div with $content
4462: To be included in page header
4463:
4464: =cut
4465:
4466: sub head_subbox {
4467: my ($content)=@_;
4468: my $output =
1.844 bisitz 4469: '<div id="LC_head_subbox">'
1.822 bisitz 4470: .$content
4471: .'</div>'
4472: }
4473:
4474: ##############################################
4475: =pod
4476:
4477: =item * &CSTR_pageheader()
4478:
4479: Inputs: ./.
4480:
4481: Returns: HTML div with CSTR path and recent box
4482: To be included on Construction Space pages
4483:
4484: =cut
4485:
4486: sub CSTR_pageheader {
4487: # this is for resources; directories have customtitle, and crumbs
4488: # and select recent are created in lonpubdir.pm
4489: my ($uname,$thisdisfn)=
4490: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4491: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4492: $formaction=~s/\/+/\//g;
4493:
4494: my $parentpath = '';
4495: my $lastitem = '';
4496: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4497: $parentpath = $1;
4498: $lastitem = $2;
4499: } else {
4500: $lastitem = $thisdisfn;
4501: }
1.921 bisitz 4502:
4503: my $output =
1.822 bisitz 4504: '<div>'
4505: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4506: .'<b>'.&mt('Construction Space:').'</b> '
4507: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4508: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4509: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4510:
4511: if ($lastitem) {
4512: $output .=
4513: '<span class="LC_filename">'
4514: .$lastitem
4515: .'</span>';
4516: }
4517: $output .=
4518: '<br />'
1.822 bisitz 4519: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4520: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4521: .'</form>'
4522: .&Apache::lonmenu::constspaceform()
4523: .'</div>';
1.921 bisitz 4524:
4525: return $output;
1.822 bisitz 4526: }
4527:
1.60 matthew 4528: ###############################################
4529: ###############################################
4530:
4531: =pod
4532:
1.112 bowersj2 4533: =back
4534:
1.549 albertel 4535: =head1 HTML Helpers
1.112 bowersj2 4536:
4537: =over 4
4538:
4539: =item * &bodytag()
1.60 matthew 4540:
4541: Returns a uniform header for LON-CAPA web pages.
4542:
4543: Inputs:
4544:
1.112 bowersj2 4545: =over 4
4546:
4547: =item * $title, A title to be displayed on the page.
4548:
4549: =item * $function, the current role (can be undef).
4550:
4551: =item * $addentries, extra parameters for the <body> tag.
4552:
4553: =item * $bodyonly, if defined, only return the <body> tag.
4554:
4555: =item * $domain, if defined, force a given domain.
4556:
4557: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4558: text interface only)
1.60 matthew 4559:
1.814 bisitz 4560: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4561: navigational links
1.317 albertel 4562:
1.338 albertel 4563: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4564:
1.361 albertel 4565: =item * $no_inline_link, if true and in remote mode, don't show the
4566: 'Switch To Inline Menu' link
4567:
1.460 albertel 4568: =item * $args, optional argument valid values are
4569: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4570: inherit_jsmath -> when creating popup window in a page,
4571: should it have jsmath forced on by the
4572: current page
1.460 albertel 4573:
1.112 bowersj2 4574: =back
4575:
1.60 matthew 4576: Returns: A uniform header for LON-CAPA web pages.
4577: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4578: If $bodyonly is undef or zero, an html string containing a <body> tag and
4579: other decorations will be returned.
4580:
4581: =cut
4582:
1.54 www 4583: sub bodytag {
1.831 bisitz 4584: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4585: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4586:
1.948.2.2 raeburn 4587: my $public;
4588: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4589: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4590: $public = 1;
4591: }
1.460 albertel 4592: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4593:
1.183 matthew 4594: $function = &get_users_function() if (!$function);
1.339 albertel 4595: my $img = &designparm($function.'.img',$domain);
4596: my $font = &designparm($function.'.font',$domain);
4597: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4598:
1.803 bisitz 4599: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4600: 'bgcolor' => $pgbg,
1.339 albertel 4601: 'text' => $font,
4602: 'alink' => &designparm($function.'.alink',$domain),
4603: 'vlink' => &designparm($function.'.vlink',$domain),
4604: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4605: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4606:
1.63 www 4607: # role and realm
1.378 raeburn 4608: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4609: if ($role eq 'ca') {
1.479 albertel 4610: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4611: $realm = &plainname($rname,$rdom);
1.378 raeburn 4612: }
1.55 www 4613: # realm
1.258 albertel 4614: if ($env{'request.course.id'}) {
1.378 raeburn 4615: if ($env{'request.role'} !~ /^cr/) {
4616: $role = &Apache::lonnet::plaintext($role,&course_type());
4617: }
1.898 raeburn 4618: if ($env{'request.course.sec'}) {
4619: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4620: }
1.359 albertel 4621: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4622: } else {
4623: $role = &Apache::lonnet::plaintext($role);
1.54 www 4624: }
1.433 albertel 4625:
1.359 albertel 4626: if (!$realm) { $realm=' '; }
1.55 www 4627: # Set messages
1.60 matthew 4628: my $messages=&domainlogo($domain);
1.330 albertel 4629:
1.438 albertel 4630: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4631:
1.101 www 4632: # construct main body tag
1.359 albertel 4633: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4634: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4635:
1.530 albertel 4636: if ($bodyonly) {
1.60 matthew 4637: return $bodytag;
1.798 tempelho 4638: }
1.359 albertel 4639:
1.410 albertel 4640: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.948.2.2 raeburn 4641: if ($public) {
1.433 albertel 4642: undef($role);
1.434 albertel 4643: } else {
4644: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4645: }
1.948.2.2 raeburn 4646:
1.762 bisitz 4647: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4648: #
4649: # Extra info if you are the DC
4650: my $dc_info = '';
4651: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4652: $env{'course.'.$env{'request.course.id'}.
4653: '.domain'}.'/'})) {
4654: my $cid = $env{'request.course.id'};
1.917 raeburn 4655: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4656: $dc_info =~ s/\s+$//;
1.359 albertel 4657: }
4658:
1.898 raeburn 4659: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4660: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4661:
1.837 bisitz 4662: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4663: # No Remote
1.916 droeschl 4664: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4665: return $bodytag;
4666: }
1.903 droeschl 4667:
4668: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4669:
4670: # if ($env{'request.state'} eq 'construct') {
4671: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4672: # }
4673:
1.359 albertel 4674:
4675:
1.916 droeschl 4676: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4677: if ($dc_info) {
4678: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4679: }
1.916 droeschl 4680: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4681: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4682: return $bodytag;
4683: }
1.894 droeschl 4684:
1.927 raeburn 4685: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4686: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4687: }
1.916 droeschl 4688:
1.903 droeschl 4689: $bodytag .= Apache::lonhtmlcommon::scripttag(
4690: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4691:
1.903 droeschl 4692: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4693:
1.917 raeburn 4694: if ($dc_info) {
4695: $dc_info = &dc_courseid_toggle($dc_info);
4696: }
4697: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4698:
1.903 droeschl 4699: #don't show menus for public users
1.948.2.2 raeburn 4700: if (!$public){
1.903 droeschl 4701: $bodytag .= Apache::lonmenu::secondary_menu();
4702: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4703: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4704: if ($env{'request.state'} eq 'construct') {
4705: $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
4706: $args->{'bread_crumbs'});
4707: } elsif ($forcereg) {
4708: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4709: }
1.903 droeschl 4710: }else{
4711: # this is to seperate menu from content when there's no secondary
4712: # menu. Especially needed for public accessible ressources.
4713: $bodytag .= '<hr style="clear:both" />';
4714: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4715: }
1.903 droeschl 4716:
1.235 raeburn 4717: return $bodytag;
1.94 www 4718: }
1.95 www 4719:
1.93 www 4720: #
1.95 www 4721: # Top frame rendering, Remote is up
1.93 www 4722: #
1.359 albertel 4723:
1.517 raeburn 4724: my $imgsrc = $img;
4725: if ($img =~ /^\/adm/) {
1.575 albertel 4726: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4727: }
4728: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4729:
1.305 www 4730: # Explicit link to get inline menu
1.361 albertel 4731: my $menu= ($no_inline_link?''
1.883 droeschl 4732: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917 raeburn 4733:
4734: if ($dc_info) {
4735: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
4736: }
4737:
1.916 droeschl 4738: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.897 wenzelju 4739: <ol class="LC_primary_menu LC_right">
1.853 droeschl 4740: <li>$menu</li>
1.917 raeburn 4741: </ol><div id="LC_realm"> $realm $dc_info</div>| unless $env{'form.inhibitmenu'};
1.94 www 4742: return(<<ENDBODY);
1.60 matthew 4743: $bodytag
1.359 albertel 4744: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4745: <tr><td>$upperleft</td>
4746: <td>$messages </td>
1.54 www 4747: </tr>
1.359 albertel 4748: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4749: </tr>
1.356 albertel 4750: </table>
1.54 www 4751: ENDBODY
1.182 matthew 4752: }
4753:
1.917 raeburn 4754: sub dc_courseid_toggle {
4755: my ($dc_info) = @_;
1.948.2.10 raeburn 4756: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4757: '<a href="javascript:showCourseID();">'.
4758: &mt('(More ...)').'</a></span>'.
4759: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4760: }
4761:
1.330 albertel 4762: sub make_attr_string {
4763: my ($register,$attr_ref) = @_;
4764:
4765: if ($attr_ref && !ref($attr_ref)) {
4766: die("addentries Must be a hash ref ".
4767: join(':',caller(1))." ".
4768: join(':',caller(0))." ");
4769: }
4770:
4771: if ($register) {
1.339 albertel 4772: my ($on_load,$on_unload);
4773: foreach my $key (keys(%{$attr_ref})) {
4774: if (lc($key) eq 'onload') {
4775: $on_load.=$attr_ref->{$key}.';';
4776: delete($attr_ref->{$key});
4777:
4778: } elsif (lc($key) eq 'onunload') {
4779: $on_unload.=$attr_ref->{$key}.';';
4780: delete($attr_ref->{$key});
4781: }
4782: }
4783: $attr_ref->{'onload'} =
4784: &Apache::lonmenu::loadevents(). $on_load;
4785: $attr_ref->{'onunload'}=
4786: &Apache::lonmenu::unloadevents().$on_unload;
4787: }
4788:
4789: # Accessibility font enhance
4790: if ($env{'browser.fontenhance'} eq 'on') {
4791: my $style;
4792: foreach my $key (keys(%{$attr_ref})) {
4793: if (lc($key) eq 'style') {
4794: $style.=$attr_ref->{$key}.';';
4795: delete($attr_ref->{$key});
4796: }
4797: }
4798: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4799: }
1.339 albertel 4800:
1.330 albertel 4801: my $attr_string;
4802: foreach my $attr (keys(%$attr_ref)) {
4803: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4804: }
4805: return $attr_string;
4806: }
4807:
4808:
1.182 matthew 4809: ###############################################
1.251 albertel 4810: ###############################################
4811:
4812: =pod
4813:
4814: =item * &endbodytag()
4815:
4816: Returns a uniform footer for LON-CAPA web pages.
4817:
1.635 raeburn 4818: Inputs: 1 - optional reference to an args hash
4819: If in the hash, key for noredirectlink has a value which evaluates to true,
4820: a 'Continue' link is not displayed if the page contains an
4821: internal redirect in the <head></head> section,
4822: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4823:
4824: =cut
4825:
4826: sub endbodytag {
1.635 raeburn 4827: my ($args) = @_;
1.251 albertel 4828: my $endbodytag='</body>';
1.269 albertel 4829: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4830: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4831: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4832: $endbodytag=
4833: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4834: &mt('Continue').'</a>'.
4835: $endbodytag;
4836: }
1.315 albertel 4837: }
1.251 albertel 4838: return $endbodytag;
4839: }
4840:
1.352 albertel 4841: =pod
4842:
4843: =item * &standard_css()
4844:
4845: Returns a style sheet
4846:
4847: Inputs: (all optional)
4848: domain -> force to color decorate a page for a specific
4849: domain
4850: function -> force usage of a specific rolish color scheme
4851: bgcolor -> override the default page bgcolor
4852:
4853: =cut
4854:
1.343 albertel 4855: sub standard_css {
1.345 albertel 4856: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4857: $function = &get_users_function() if (!$function);
4858: my $img = &designparm($function.'.img', $domain);
4859: my $tabbg = &designparm($function.'.tabbg', $domain);
4860: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4861: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4862: #second colour for later usage
1.345 albertel 4863: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4864: my $pgbg_or_bgcolor =
4865: $bgcolor ||
1.352 albertel 4866: &designparm($function.'.pgbg', $domain);
1.382 albertel 4867: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4868: my $alink = &designparm($function.'.alink', $domain);
4869: my $vlink = &designparm($function.'.vlink', $domain);
4870: my $link = &designparm($function.'.link', $domain);
4871:
1.602 albertel 4872: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4873: my $mono = 'monospace';
1.850 bisitz 4874: my $data_table_head = $sidebg;
4875: my $data_table_light = '#FAFAFA';
4876: my $data_table_dark = '#F0F0F0';
1.470 banghart 4877: my $data_table_darker = '#CCCCCC';
1.349 albertel 4878: my $data_table_highlight = '#FFFF00';
1.352 albertel 4879: my $mail_new = '#FFBB77';
4880: my $mail_new_hover = '#DD9955';
4881: my $mail_read = '#BBBB77';
4882: my $mail_read_hover = '#999944';
4883: my $mail_replied = '#AAAA88';
4884: my $mail_replied_hover = '#888855';
4885: my $mail_other = '#99BBBB';
4886: my $mail_other_hover = '#669999';
1.391 albertel 4887: my $table_header = '#DDDDDD';
1.489 raeburn 4888: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4889: my $lg_border_color = '#C8C8C8';
1.948.2.1 raeburn 4890: my $button_hover = '#BF2317';
1.392 albertel 4891:
1.608 albertel 4892: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4893: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4894: : '0 3px 0 4px';
1.448 albertel 4895:
1.343 albertel 4896: return <<END;
1.947 droeschl 4897:
4898: /* needed for iframe to allow 100% height in FF */
4899: body, html {
4900: margin: 0;
4901: padding: 0 0.5%;
4902: height: 99%; /* to avoid scrollbars */
4903: }
4904:
1.795 www 4905: body {
1.911 bisitz 4906: font-family: $sans;
4907: line-height:130%;
4908: font-size:0.83em;
4909: color:$font;
1.795 www 4910: }
4911:
1.948.2.9 raeburn 4912: a:focus,
4913: a:focus img {
1.795 www 4914: color: red;
1.911 bisitz 4915: background: yellow;
1.795 www 4916: }
1.698 harmsja 4917:
1.911 bisitz 4918: form, .inline {
4919: display: inline;
1.795 www 4920: }
1.721 harmsja 4921:
1.795 www 4922: .LC_right {
1.911 bisitz 4923: text-align:right;
1.795 www 4924: }
4925:
4926: .LC_middle {
1.911 bisitz 4927: vertical-align:middle;
1.795 www 4928: }
1.721 harmsja 4929:
1.911 bisitz 4930: .LC_400Box {
4931: width:400px;
4932: }
1.721 harmsja 4933:
1.947 droeschl 4934: .LC_iframecontainer {
4935: width: 98%;
4936: margin: 0;
4937: position: fixed;
4938: top: 8.5em;
4939: bottom: 0;
4940: }
4941:
4942: .LC_iframecontainer iframe{
4943: border: none;
4944: width: 100%;
4945: height: 100%;
4946: }
4947:
1.778 bisitz 4948: .LC_filename {
4949: font-family: $mono;
4950: white-space:pre;
1.921 bisitz 4951: font-size: 120%;
1.778 bisitz 4952: }
4953:
4954: .LC_fileicon {
4955: border: none;
4956: height: 1.3em;
4957: vertical-align: text-bottom;
4958: margin-right: 0.3em;
4959: text-decoration:none;
4960: }
4961:
1.350 albertel 4962: .LC_error {
4963: color: red;
4964: font-size: larger;
4965: }
1.795 www 4966:
1.457 albertel 4967: .LC_warning,
4968: .LC_diff_removed {
1.733 bisitz 4969: color: red;
1.394 albertel 4970: }
1.532 albertel 4971:
4972: .LC_info,
1.457 albertel 4973: .LC_success,
4974: .LC_diff_added {
1.350 albertel 4975: color: green;
4976: }
1.795 www 4977:
1.802 bisitz 4978: div.LC_confirm_box {
4979: background-color: #FAFAFA;
4980: border: 1px solid $lg_border_color;
4981: margin-right: 0;
4982: padding: 5px;
4983: }
4984:
4985: div.LC_confirm_box .LC_error img,
4986: div.LC_confirm_box .LC_success img {
4987: vertical-align: middle;
4988: }
4989:
1.440 albertel 4990: .LC_icon {
1.771 droeschl 4991: border: none;
1.790 droeschl 4992: vertical-align: middle;
1.771 droeschl 4993: }
4994:
1.543 albertel 4995: .LC_docs_spacer {
4996: width: 25px;
4997: height: 1px;
1.771 droeschl 4998: border: none;
1.543 albertel 4999: }
1.346 albertel 5000:
1.532 albertel 5001: .LC_internal_info {
1.735 bisitz 5002: color: #999999;
1.532 albertel 5003: }
5004:
1.794 www 5005: .LC_discussion {
1.911 bisitz 5006: background: $tabbg;
5007: border: 1px solid black;
5008: margin: 2px;
1.794 www 5009: }
5010:
5011: .LC_disc_action_links_bar {
1.911 bisitz 5012: background: $tabbg;
5013: border: none;
5014: margin: 4px;
1.794 www 5015: }
5016:
5017: .LC_disc_action_left {
1.911 bisitz 5018: text-align: left;
1.794 www 5019: }
5020:
5021: .LC_disc_action_right {
1.911 bisitz 5022: text-align: right;
1.794 www 5023: }
5024:
5025: .LC_disc_new_item {
1.911 bisitz 5026: background: white;
5027: border: 2px solid red;
5028: margin: 2px;
1.794 www 5029: }
5030:
5031: .LC_disc_old_item {
1.911 bisitz 5032: background: white;
5033: border: 1px solid black;
5034: margin: 2px;
1.794 www 5035: }
5036:
1.458 albertel 5037: table.LC_pastsubmission {
5038: border: 1px solid black;
5039: margin: 2px;
5040: }
5041:
1.924 bisitz 5042: table#LC_menubuttons {
1.345 albertel 5043: width: 100%;
5044: background: $pgbg;
1.392 albertel 5045: border: 2px;
1.402 albertel 5046: border-collapse: separate;
1.803 bisitz 5047: padding: 0;
1.345 albertel 5048: }
1.392 albertel 5049:
1.801 tempelho 5050: table#LC_title_bar a {
5051: color: $fontmenu;
5052: }
1.836 bisitz 5053:
1.807 droeschl 5054: table#LC_title_bar {
1.819 tempelho 5055: clear: both;
1.836 bisitz 5056: display: none;
1.807 droeschl 5057: }
5058:
1.795 www 5059: table#LC_title_bar,
1.933 droeschl 5060: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5061: table#LC_title_bar.LC_with_remote {
1.359 albertel 5062: width: 100%;
1.392 albertel 5063: border-color: $pgbg;
5064: border-style: solid;
5065: border-width: $border;
1.379 albertel 5066: background: $pgbg;
1.801 tempelho 5067: color: $fontmenu;
1.392 albertel 5068: border-collapse: collapse;
1.803 bisitz 5069: padding: 0;
1.819 tempelho 5070: margin: 0;
1.359 albertel 5071: }
1.795 www 5072:
1.933 droeschl 5073: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5074: margin: 0;
5075: padding: 0;
1.933 droeschl 5076: position: relative;
5077: list-style: none;
1.913 droeschl 5078: }
1.933 droeschl 5079: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5080: display: inline;
5081: }
1.933 droeschl 5082:
5083: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5084: padding: 0;
1.933 droeschl 5085: margin: 0;
5086: float: left;
1.913 droeschl 5087: }
1.933 droeschl 5088: .LC_breadcrumb_tools_tools {
5089: padding: 0;
5090: margin: 0;
1.913 droeschl 5091: float: right;
5092: }
5093:
1.359 albertel 5094: table#LC_title_bar td {
5095: background: $tabbg;
5096: }
1.795 www 5097:
1.911 bisitz 5098: table#LC_menubuttons img {
1.803 bisitz 5099: border: none;
1.346 albertel 5100: }
1.795 www 5101:
1.842 droeschl 5102: .LC_breadcrumbs_component {
1.911 bisitz 5103: float: right;
5104: margin: 0 1em;
1.357 albertel 5105: }
1.842 droeschl 5106: .LC_breadcrumbs_component img {
1.911 bisitz 5107: vertical-align: middle;
1.777 tempelho 5108: }
1.795 www 5109:
1.383 albertel 5110: td.LC_table_cell_checkbox {
5111: text-align: center;
5112: }
1.795 www 5113:
5114: .LC_fontsize_small {
1.911 bisitz 5115: font-size: 70%;
1.705 tempelho 5116: }
5117:
1.844 bisitz 5118: #LC_breadcrumbs {
1.911 bisitz 5119: clear:both;
5120: background: $sidebg;
5121: border-bottom: 1px solid $lg_border_color;
5122: line-height: 2.5em;
1.933 droeschl 5123: overflow: hidden;
1.911 bisitz 5124: margin: 0;
5125: padding: 0;
1.819 tempelho 5126: }
1.862 bisitz 5127:
1.839 droeschl 5128: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 5129: #LC_remote #LC_breadcrumbs {
1.911 bisitz 5130: display:none;
1.839 droeschl 5131: }
1.819 tempelho 5132:
1.844 bisitz 5133: #LC_head_subbox {
1.911 bisitz 5134: clear:both;
5135: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5136: border: 1px solid $sidebg;
5137: margin: 0 0 10px 0;
1.948.2.6 raeburn 5138: padding: 3px;
1.822 bisitz 5139: }
5140:
1.795 www 5141: .LC_fontsize_medium {
1.911 bisitz 5142: font-size: 85%;
1.705 tempelho 5143: }
5144:
1.795 www 5145: .LC_fontsize_large {
1.911 bisitz 5146: font-size: 120%;
1.705 tempelho 5147: }
5148:
1.346 albertel 5149: .LC_menubuttons_inline_text {
5150: color: $font;
1.698 harmsja 5151: font-size: 90%;
1.701 harmsja 5152: padding-left:3px;
1.346 albertel 5153: }
5154:
1.934 droeschl 5155: .LC_menubuttons_inline_text img{
5156: vertical-align: middle;
5157: }
5158:
1.948.2.1 raeburn 5159: li.LC_menubuttons_inline_text img,a {
5160: cursor:pointer;
5161: }
5162:
1.526 www 5163: .LC_menubuttons_link {
5164: text-decoration: none;
5165: }
1.795 www 5166:
1.522 albertel 5167: .LC_menubuttons_category {
1.521 www 5168: color: $font;
1.526 www 5169: background: $pgbg;
1.521 www 5170: font-size: larger;
5171: font-weight: bold;
5172: }
5173:
1.346 albertel 5174: td.LC_menubuttons_text {
1.911 bisitz 5175: color: $font;
1.346 albertel 5176: }
1.706 harmsja 5177:
1.346 albertel 5178: .LC_current_location {
5179: background: $tabbg;
5180: }
1.795 www 5181:
1.938 bisitz 5182: table.LC_data_table {
1.347 albertel 5183: border: 1px solid #000000;
1.402 albertel 5184: border-collapse: separate;
1.426 albertel 5185: border-spacing: 1px;
1.610 albertel 5186: background: $pgbg;
1.347 albertel 5187: }
1.795 www 5188:
1.422 albertel 5189: .LC_data_table_dense {
5190: font-size: small;
5191: }
1.795 www 5192:
1.507 raeburn 5193: table.LC_nested_outer {
5194: border: 1px solid #000000;
1.589 raeburn 5195: border-collapse: collapse;
1.803 bisitz 5196: border-spacing: 0;
1.507 raeburn 5197: width: 100%;
5198: }
1.795 www 5199:
1.879 raeburn 5200: table.LC_innerpickbox,
1.507 raeburn 5201: table.LC_nested {
1.803 bisitz 5202: border: none;
1.589 raeburn 5203: border-collapse: collapse;
1.803 bisitz 5204: border-spacing: 0;
1.507 raeburn 5205: width: 100%;
5206: }
1.795 www 5207:
1.930 faziophi 5208: .ui-accordion,
5209: .ui-accordion table.LC_data_table,
5210: .ui-accordion table.LC_nested_outer{
5211: border: 0px;
5212: border-spacing: 0px;
5213: margin: 3px;
5214: }
5215:
1.911 bisitz 5216: table.LC_data_table tr th,
5217: table.LC_calendar tr th,
1.879 raeburn 5218: table.LC_prior_tries tr th,
5219: table.LC_innerpickbox tr th {
1.349 albertel 5220: font-weight: bold;
5221: background-color: $data_table_head;
1.801 tempelho 5222: color:$fontmenu;
1.701 harmsja 5223: font-size:90%;
1.347 albertel 5224: }
1.795 www 5225:
1.879 raeburn 5226: table.LC_innerpickbox tr th,
5227: table.LC_innerpickbox tr td {
5228: vertical-align: top;
5229: }
5230:
1.711 raeburn 5231: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5232: background-color: #CCCCCC;
1.711 raeburn 5233: font-weight: bold;
5234: text-align: left;
5235: }
1.795 www 5236:
1.912 bisitz 5237: table.LC_data_table tr.LC_odd_row > td {
5238: background-color: $data_table_light;
5239: padding: 2px;
5240: vertical-align: top;
5241: }
5242:
1.809 bisitz 5243: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5244: background-color: $data_table_light;
1.912 bisitz 5245: vertical-align: top;
5246: }
5247:
5248: table.LC_data_table tr.LC_even_row > td {
5249: background-color: $data_table_dark;
1.425 albertel 5250: padding: 2px;
1.900 bisitz 5251: vertical-align: top;
1.347 albertel 5252: }
1.795 www 5253:
1.809 bisitz 5254: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5255: background-color: $data_table_dark;
1.900 bisitz 5256: vertical-align: top;
1.347 albertel 5257: }
1.795 www 5258:
1.425 albertel 5259: table.LC_data_table tr.LC_data_table_highlight td {
5260: background-color: $data_table_darker;
5261: }
1.795 www 5262:
1.639 raeburn 5263: table.LC_data_table tr td.LC_leftcol_header {
5264: background-color: $data_table_head;
5265: font-weight: bold;
5266: }
1.795 www 5267:
1.451 albertel 5268: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5269: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5270: font-weight: bold;
5271: font-style: italic;
5272: text-align: center;
5273: padding: 8px;
1.347 albertel 5274: }
1.795 www 5275:
1.940 bisitz 5276: table.LC_data_table tr.LC_empty_row td {
5277: background-color: $sidebg;
5278: }
5279:
5280: table.LC_nested tr.LC_empty_row td {
5281: background-color: #FFFFFF;
5282: }
5283:
1.890 droeschl 5284: table.LC_caption {
5285: }
5286:
1.507 raeburn 5287: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5288: padding: 4ex
5289: }
1.795 www 5290:
1.507 raeburn 5291: table.LC_nested_outer tr th {
5292: font-weight: bold;
1.801 tempelho 5293: color:$fontmenu;
1.507 raeburn 5294: background-color: $data_table_head;
1.701 harmsja 5295: font-size: small;
1.507 raeburn 5296: border-bottom: 1px solid #000000;
5297: }
1.795 www 5298:
1.507 raeburn 5299: table.LC_nested_outer tr td.LC_subheader {
5300: background-color: $data_table_head;
5301: font-weight: bold;
5302: font-size: small;
5303: border-bottom: 1px solid #000000;
5304: text-align: right;
1.451 albertel 5305: }
1.795 www 5306:
1.507 raeburn 5307: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5308: background-color: #CCCCCC;
1.451 albertel 5309: font-weight: bold;
5310: font-size: small;
1.507 raeburn 5311: text-align: center;
5312: }
1.795 www 5313:
1.589 raeburn 5314: table.LC_nested tr.LC_info_row td.LC_left_item,
5315: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5316: text-align: left;
1.451 albertel 5317: }
1.795 www 5318:
1.507 raeburn 5319: table.LC_nested td {
1.735 bisitz 5320: background-color: #FFFFFF;
1.451 albertel 5321: font-size: small;
1.507 raeburn 5322: }
1.795 www 5323:
1.507 raeburn 5324: table.LC_nested_outer tr th.LC_right_item,
5325: table.LC_nested tr.LC_info_row td.LC_right_item,
5326: table.LC_nested tr.LC_odd_row td.LC_right_item,
5327: table.LC_nested tr td.LC_right_item {
1.451 albertel 5328: text-align: right;
5329: }
5330:
1.930 faziophi 5331: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5332: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5333: text-align: right;
5334: width: 40%;
5335: padding-right:10px;
5336: vertical-align: top;
5337: padding: 5px;
5338: }
5339:
5340: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5341: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5342: text-align: left;
5343: width: 60%;
5344: padding: 2px 4px;
5345: }
5346:
1.507 raeburn 5347: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5348: background-color: #EEEEEE;
1.451 albertel 5349: }
5350:
1.473 raeburn 5351: table.LC_createuser {
5352: }
5353:
5354: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5355: font-size: small;
1.473 raeburn 5356: }
5357:
5358: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5359: background-color: #CCCCCC;
1.473 raeburn 5360: font-weight: bold;
5361: text-align: center;
5362: }
5363:
1.349 albertel 5364: table.LC_calendar {
5365: border: 1px solid #000000;
5366: border-collapse: collapse;
1.917 raeburn 5367: width: 98%;
1.349 albertel 5368: }
1.795 www 5369:
1.349 albertel 5370: table.LC_calendar_pickdate {
5371: font-size: xx-small;
5372: }
1.795 www 5373:
1.349 albertel 5374: table.LC_calendar tr td {
5375: border: 1px solid #000000;
5376: vertical-align: top;
1.917 raeburn 5377: width: 14%;
1.349 albertel 5378: }
1.795 www 5379:
1.349 albertel 5380: table.LC_calendar tr td.LC_calendar_day_empty {
5381: background-color: $data_table_dark;
5382: }
1.795 www 5383:
1.779 bisitz 5384: table.LC_calendar tr td.LC_calendar_day_current {
5385: background-color: $data_table_highlight;
1.777 tempelho 5386: }
1.795 www 5387:
1.938 bisitz 5388: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5389: background-color: $mail_new;
5390: }
1.795 www 5391:
1.938 bisitz 5392: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5393: background-color: $mail_new_hover;
5394: }
1.795 www 5395:
1.938 bisitz 5396: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5397: background-color: $mail_read;
5398: }
1.795 www 5399:
1.938 bisitz 5400: /*
5401: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5402: background-color: $mail_read_hover;
5403: }
1.938 bisitz 5404: */
1.795 www 5405:
1.938 bisitz 5406: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5407: background-color: $mail_replied;
5408: }
1.795 www 5409:
1.938 bisitz 5410: /*
5411: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5412: background-color: $mail_replied_hover;
5413: }
1.938 bisitz 5414: */
1.795 www 5415:
1.938 bisitz 5416: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5417: background-color: $mail_other;
5418: }
1.795 www 5419:
1.938 bisitz 5420: /*
5421: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5422: background-color: $mail_other_hover;
5423: }
1.938 bisitz 5424: */
1.494 raeburn 5425:
1.777 tempelho 5426: table.LC_data_table tr > td.LC_browser_file,
5427: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5428: background: #AAEE77;
1.389 albertel 5429: }
1.795 www 5430:
1.777 tempelho 5431: table.LC_data_table tr > td.LC_browser_file_locked,
5432: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5433: background: #FFAA99;
1.387 albertel 5434: }
1.795 www 5435:
1.777 tempelho 5436: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5437: background: #888888;
1.779 bisitz 5438: }
1.795 www 5439:
1.777 tempelho 5440: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5441: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5442: background: #F8F866;
1.777 tempelho 5443: }
1.795 www 5444:
1.696 bisitz 5445: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5446: background: #E0E8FF;
1.387 albertel 5447: }
1.696 bisitz 5448:
1.707 bisitz 5449: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5450: /* background: #77FF77; */
1.707 bisitz 5451: }
1.795 www 5452:
1.707 bisitz 5453: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5454: border-right: 8px solid #FFFF77;
1.707 bisitz 5455: }
1.795 www 5456:
1.707 bisitz 5457: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5458: border-right: 8px solid #FFAA77;
1.707 bisitz 5459: }
1.795 www 5460:
1.707 bisitz 5461: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5462: border-right: 8px solid #FF7777;
1.707 bisitz 5463: }
1.795 www 5464:
1.707 bisitz 5465: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5466: border-right: 8px solid #AAFF77;
1.707 bisitz 5467: }
1.795 www 5468:
1.707 bisitz 5469: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5470: border-right: 8px solid #11CC55;
1.707 bisitz 5471: }
5472:
1.388 albertel 5473: span.LC_current_location {
1.701 harmsja 5474: font-size:larger;
1.388 albertel 5475: background: $pgbg;
5476: }
1.387 albertel 5477:
1.395 albertel 5478: span.LC_parm_menu_item {
5479: font-size: larger;
5480: }
1.795 www 5481:
1.395 albertel 5482: span.LC_parm_scope_all {
5483: color: red;
5484: }
1.795 www 5485:
1.395 albertel 5486: span.LC_parm_scope_folder {
5487: color: green;
5488: }
1.795 www 5489:
1.395 albertel 5490: span.LC_parm_scope_resource {
5491: color: orange;
5492: }
1.795 www 5493:
1.395 albertel 5494: span.LC_parm_part {
5495: color: blue;
5496: }
1.795 www 5497:
1.911 bisitz 5498: span.LC_parm_folder,
5499: span.LC_parm_symb {
1.395 albertel 5500: font-size: x-small;
5501: font-family: $mono;
5502: color: #AAAAAA;
5503: }
5504:
1.948.2.8 raeburn 5505: ul.LC_parm_parmlist li {
5506: display: inline-block;
5507: padding: 0.3em 0.8em;
5508: vertical-align: top;
5509: width: 150px;
5510: border-top:1px solid $lg_border_color;
5511: }
5512:
1.795 www 5513: td.LC_parm_overview_level_menu,
5514: td.LC_parm_overview_map_menu,
5515: td.LC_parm_overview_parm_selectors,
5516: td.LC_parm_overview_restrictions {
1.396 albertel 5517: border: 1px solid black;
5518: border-collapse: collapse;
5519: }
1.795 www 5520:
1.396 albertel 5521: table.LC_parm_overview_restrictions td {
5522: border-width: 1px 4px 1px 4px;
5523: border-style: solid;
5524: border-color: $pgbg;
5525: text-align: center;
5526: }
1.795 www 5527:
1.396 albertel 5528: table.LC_parm_overview_restrictions th {
5529: background: $tabbg;
5530: border-width: 1px 4px 1px 4px;
5531: border-style: solid;
5532: border-color: $pgbg;
5533: }
1.795 www 5534:
1.398 albertel 5535: table#LC_helpmenu {
1.803 bisitz 5536: border: none;
1.398 albertel 5537: height: 55px;
1.803 bisitz 5538: border-spacing: 0;
1.398 albertel 5539: }
5540:
5541: table#LC_helpmenu fieldset legend {
5542: font-size: larger;
5543: }
1.795 www 5544:
1.397 albertel 5545: table#LC_helpmenu_links {
5546: width: 100%;
5547: border: 1px solid black;
5548: background: $pgbg;
1.803 bisitz 5549: padding: 0;
1.397 albertel 5550: border-spacing: 1px;
5551: }
1.795 www 5552:
1.397 albertel 5553: table#LC_helpmenu_links tr td {
5554: padding: 1px;
5555: background: $tabbg;
1.399 albertel 5556: text-align: center;
5557: font-weight: bold;
1.397 albertel 5558: }
1.396 albertel 5559:
1.795 www 5560: table#LC_helpmenu_links a:link,
5561: table#LC_helpmenu_links a:visited,
1.397 albertel 5562: table#LC_helpmenu_links a:active {
5563: text-decoration: none;
5564: color: $font;
5565: }
1.795 www 5566:
1.397 albertel 5567: table#LC_helpmenu_links a:hover {
5568: text-decoration: underline;
5569: color: $vlink;
5570: }
1.396 albertel 5571:
1.417 albertel 5572: .LC_chrt_popup_exists {
5573: border: 1px solid #339933;
5574: margin: -1px;
5575: }
1.795 www 5576:
1.417 albertel 5577: .LC_chrt_popup_up {
5578: border: 1px solid yellow;
5579: margin: -1px;
5580: }
1.795 www 5581:
1.417 albertel 5582: .LC_chrt_popup {
5583: border: 1px solid #8888FF;
5584: background: #CCCCFF;
5585: }
1.795 www 5586:
1.421 albertel 5587: table.LC_pick_box {
5588: border-collapse: separate;
5589: background: white;
5590: border: 1px solid black;
5591: border-spacing: 1px;
5592: }
1.795 www 5593:
1.421 albertel 5594: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5595: background: $sidebg;
1.421 albertel 5596: font-weight: bold;
1.900 bisitz 5597: text-align: left;
1.740 bisitz 5598: vertical-align: top;
1.421 albertel 5599: width: 184px;
5600: padding: 8px;
5601: }
1.795 www 5602:
1.579 raeburn 5603: table.LC_pick_box td.LC_pick_box_value {
5604: text-align: left;
5605: padding: 8px;
5606: }
1.795 www 5607:
1.579 raeburn 5608: table.LC_pick_box td.LC_pick_box_select {
5609: text-align: left;
5610: padding: 8px;
5611: }
1.795 www 5612:
1.424 albertel 5613: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5614: padding: 0;
1.421 albertel 5615: height: 1px;
5616: background: black;
5617: }
1.795 www 5618:
1.421 albertel 5619: table.LC_pick_box td.LC_pick_box_submit {
5620: text-align: right;
5621: }
1.795 www 5622:
1.579 raeburn 5623: table.LC_pick_box td.LC_evenrow_value {
5624: text-align: left;
5625: padding: 8px;
5626: background-color: $data_table_light;
5627: }
1.795 www 5628:
1.579 raeburn 5629: table.LC_pick_box td.LC_oddrow_value {
5630: text-align: left;
5631: padding: 8px;
5632: background-color: $data_table_light;
5633: }
1.795 www 5634:
1.579 raeburn 5635: span.LC_helpform_receipt_cat {
5636: font-weight: bold;
5637: }
1.795 www 5638:
1.424 albertel 5639: table.LC_group_priv_box {
5640: background: white;
5641: border: 1px solid black;
5642: border-spacing: 1px;
5643: }
1.795 www 5644:
1.424 albertel 5645: table.LC_group_priv_box td.LC_pick_box_title {
5646: background: $tabbg;
5647: font-weight: bold;
5648: text-align: right;
5649: width: 184px;
5650: }
1.795 www 5651:
1.424 albertel 5652: table.LC_group_priv_box td.LC_groups_fixed {
5653: background: $data_table_light;
5654: text-align: center;
5655: }
1.795 www 5656:
1.424 albertel 5657: table.LC_group_priv_box td.LC_groups_optional {
5658: background: $data_table_dark;
5659: text-align: center;
5660: }
1.795 www 5661:
1.424 albertel 5662: table.LC_group_priv_box td.LC_groups_functionality {
5663: background: $data_table_darker;
5664: text-align: center;
5665: font-weight: bold;
5666: }
1.795 www 5667:
1.424 albertel 5668: table.LC_group_priv td {
5669: text-align: left;
1.803 bisitz 5670: padding: 0;
1.424 albertel 5671: }
5672:
1.421 albertel 5673: table.LC_notify_front_page {
5674: background: white;
5675: border: 1px solid black;
5676: padding: 8px;
5677: }
1.795 www 5678:
1.421 albertel 5679: table.LC_notify_front_page td {
5680: padding: 8px;
5681: }
1.795 www 5682:
1.424 albertel 5683: .LC_navbuttons {
5684: margin: 2ex 0ex 2ex 0ex;
5685: }
1.795 www 5686:
1.423 albertel 5687: .LC_topic_bar {
5688: font-weight: bold;
5689: background: $tabbg;
1.918 wenzelju 5690: margin: 1em 0em 1em 2em;
1.805 bisitz 5691: padding: 3px;
1.918 wenzelju 5692: font-size: 1.2em;
1.423 albertel 5693: }
1.795 www 5694:
1.423 albertel 5695: .LC_topic_bar span {
1.918 wenzelju 5696: left: 0.5em;
5697: position: absolute;
1.423 albertel 5698: vertical-align: middle;
1.918 wenzelju 5699: font-size: 1.2em;
1.423 albertel 5700: }
1.795 www 5701:
1.423 albertel 5702: table.LC_course_group_status {
5703: margin: 20px;
5704: }
1.795 www 5705:
1.423 albertel 5706: table.LC_status_selector td {
5707: vertical-align: top;
5708: text-align: center;
1.424 albertel 5709: padding: 4px;
5710: }
1.795 www 5711:
1.599 albertel 5712: div.LC_feedback_link {
1.616 albertel 5713: clear: both;
1.829 kalberla 5714: background: $sidebg;
1.779 bisitz 5715: width: 100%;
1.829 kalberla 5716: padding-bottom: 10px;
5717: border: 1px $tabbg solid;
1.833 kalberla 5718: height: 22px;
5719: line-height: 22px;
5720: padding-top: 5px;
5721: }
5722:
5723: div.LC_feedback_link img {
5724: height: 22px;
1.867 kalberla 5725: vertical-align:middle;
1.829 kalberla 5726: }
5727:
1.911 bisitz 5728: div.LC_feedback_link a {
1.829 kalberla 5729: text-decoration: none;
1.489 raeburn 5730: }
1.795 www 5731:
1.867 kalberla 5732: div.LC_comblock {
1.911 bisitz 5733: display:inline;
1.867 kalberla 5734: color:$font;
5735: font-size:90%;
5736: }
5737:
5738: div.LC_feedback_link div.LC_comblock {
5739: padding-left:5px;
5740: }
5741:
5742: div.LC_feedback_link div.LC_comblock a {
5743: color:$font;
5744: }
5745:
1.489 raeburn 5746: span.LC_feedback_link {
1.858 bisitz 5747: /* background: $feedback_link_bg; */
1.599 albertel 5748: font-size: larger;
5749: }
1.795 www 5750:
1.599 albertel 5751: span.LC_message_link {
1.858 bisitz 5752: /* background: $feedback_link_bg; */
1.599 albertel 5753: font-size: larger;
5754: position: absolute;
5755: right: 1em;
1.489 raeburn 5756: }
1.421 albertel 5757:
1.515 albertel 5758: table.LC_prior_tries {
1.524 albertel 5759: border: 1px solid #000000;
5760: border-collapse: separate;
5761: border-spacing: 1px;
1.515 albertel 5762: }
1.523 albertel 5763:
1.515 albertel 5764: table.LC_prior_tries td {
1.524 albertel 5765: padding: 2px;
1.515 albertel 5766: }
1.523 albertel 5767:
5768: .LC_answer_correct {
1.795 www 5769: background: lightgreen;
5770: color: darkgreen;
5771: padding: 6px;
1.523 albertel 5772: }
1.795 www 5773:
1.523 albertel 5774: .LC_answer_charged_try {
1.797 www 5775: background: #FFAAAA;
1.795 www 5776: color: darkred;
5777: padding: 6px;
1.523 albertel 5778: }
1.795 www 5779:
1.779 bisitz 5780: .LC_answer_not_charged_try,
1.523 albertel 5781: .LC_answer_no_grade,
5782: .LC_answer_late {
1.795 www 5783: background: lightyellow;
1.523 albertel 5784: color: black;
1.795 www 5785: padding: 6px;
1.523 albertel 5786: }
1.795 www 5787:
1.523 albertel 5788: .LC_answer_previous {
1.795 www 5789: background: lightblue;
5790: color: darkblue;
5791: padding: 6px;
1.523 albertel 5792: }
1.795 www 5793:
1.779 bisitz 5794: .LC_answer_no_message {
1.777 tempelho 5795: background: #FFFFFF;
5796: color: black;
1.795 www 5797: padding: 6px;
1.779 bisitz 5798: }
1.795 www 5799:
1.779 bisitz 5800: .LC_answer_unknown {
5801: background: orange;
5802: color: black;
1.795 www 5803: padding: 6px;
1.777 tempelho 5804: }
1.795 www 5805:
1.529 albertel 5806: span.LC_prior_numerical,
5807: span.LC_prior_string,
5808: span.LC_prior_custom,
5809: span.LC_prior_reaction,
5810: span.LC_prior_math {
1.925 bisitz 5811: font-family: $mono;
1.523 albertel 5812: white-space: pre;
5813: }
5814:
1.525 albertel 5815: span.LC_prior_string {
1.925 bisitz 5816: font-family: $mono;
1.525 albertel 5817: white-space: pre;
5818: }
5819:
1.523 albertel 5820: table.LC_prior_option {
5821: width: 100%;
5822: border-collapse: collapse;
5823: }
1.795 www 5824:
1.911 bisitz 5825: table.LC_prior_rank,
1.795 www 5826: table.LC_prior_match {
1.528 albertel 5827: border-collapse: collapse;
5828: }
1.795 www 5829:
1.528 albertel 5830: table.LC_prior_option tr td,
5831: table.LC_prior_rank tr td,
5832: table.LC_prior_match tr td {
1.524 albertel 5833: border: 1px solid #000000;
1.515 albertel 5834: }
5835:
1.855 bisitz 5836: .LC_nobreak {
1.544 albertel 5837: white-space: nowrap;
1.519 raeburn 5838: }
5839:
1.576 raeburn 5840: span.LC_cusr_emph {
5841: font-style: italic;
5842: }
5843:
1.633 raeburn 5844: span.LC_cusr_subheading {
5845: font-weight: normal;
5846: font-size: 85%;
5847: }
5848:
1.861 bisitz 5849: div.LC_docs_entry_move {
1.859 bisitz 5850: border: 1px solid #BBBBBB;
1.545 albertel 5851: background: #DDDDDD;
1.861 bisitz 5852: width: 22px;
1.859 bisitz 5853: padding: 1px;
5854: margin: 0;
1.545 albertel 5855: }
5856:
1.861 bisitz 5857: table.LC_data_table tr > td.LC_docs_entry_commands,
5858: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5859: background: #DDDDDD;
5860: font-size: x-small;
5861: }
1.795 www 5862:
1.861 bisitz 5863: .LC_docs_entry_parameter {
5864: white-space: nowrap;
5865: }
5866:
1.544 albertel 5867: .LC_docs_copy {
1.545 albertel 5868: color: #000099;
1.544 albertel 5869: }
1.795 www 5870:
1.544 albertel 5871: .LC_docs_cut {
1.545 albertel 5872: color: #550044;
1.544 albertel 5873: }
1.795 www 5874:
1.544 albertel 5875: .LC_docs_rename {
1.545 albertel 5876: color: #009900;
1.544 albertel 5877: }
1.795 www 5878:
1.544 albertel 5879: .LC_docs_remove {
1.545 albertel 5880: color: #990000;
5881: }
5882:
1.547 albertel 5883: .LC_docs_reinit_warn,
5884: .LC_docs_ext_edit {
5885: font-size: x-small;
5886: }
5887:
1.545 albertel 5888: table.LC_docs_adddocs td,
5889: table.LC_docs_adddocs th {
5890: border: 1px solid #BBBBBB;
5891: padding: 4px;
5892: background: #DDDDDD;
1.543 albertel 5893: }
5894:
1.584 albertel 5895: table.LC_sty_begin {
5896: background: #BBFFBB;
5897: }
1.795 www 5898:
1.584 albertel 5899: table.LC_sty_end {
5900: background: #FFBBBB;
5901: }
5902:
1.589 raeburn 5903: table.LC_double_column {
1.803 bisitz 5904: border-width: 0;
1.589 raeburn 5905: border-collapse: collapse;
5906: width: 100%;
5907: padding: 2px;
5908: }
5909:
5910: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5911: top: 2px;
1.589 raeburn 5912: left: 2px;
5913: width: 47%;
5914: vertical-align: top;
5915: }
5916:
5917: table.LC_double_column tr td.LC_right_col {
5918: top: 2px;
1.779 bisitz 5919: right: 2px;
1.589 raeburn 5920: width: 47%;
5921: vertical-align: top;
5922: }
5923:
1.591 raeburn 5924: div.LC_left_float {
5925: float: left;
5926: padding-right: 5%;
1.597 albertel 5927: padding-bottom: 4px;
1.591 raeburn 5928: }
5929:
5930: div.LC_clear_float_header {
1.597 albertel 5931: padding-bottom: 2px;
1.591 raeburn 5932: }
5933:
5934: div.LC_clear_float_footer {
1.597 albertel 5935: padding-top: 10px;
1.591 raeburn 5936: clear: both;
5937: }
5938:
1.597 albertel 5939: div.LC_grade_show_user {
1.941 bisitz 5940: /* border-left: 5px solid $sidebg; */
5941: border-top: 5px solid #000000;
5942: margin: 50px 0 0 0;
1.936 bisitz 5943: padding: 15px 0 5px 10px;
1.597 albertel 5944: }
1.795 www 5945:
1.936 bisitz 5946: div.LC_grade_show_user_odd_row {
1.941 bisitz 5947: /* border-left: 5px solid #000000; */
5948: }
5949:
5950: div.LC_grade_show_user div.LC_Box {
5951: margin-right: 50px;
1.597 albertel 5952: }
5953:
5954: div.LC_grade_submissions,
5955: div.LC_grade_message_center,
1.936 bisitz 5956: div.LC_grade_info_links {
1.597 albertel 5957: margin: 5px;
5958: width: 99%;
5959: background: #FFFFFF;
5960: }
1.795 www 5961:
1.597 albertel 5962: div.LC_grade_submissions_header,
1.936 bisitz 5963: div.LC_grade_message_center_header {
1.705 tempelho 5964: font-weight: bold;
5965: font-size: large;
1.597 albertel 5966: }
1.795 www 5967:
1.597 albertel 5968: div.LC_grade_submissions_body,
1.936 bisitz 5969: div.LC_grade_message_center_body {
1.597 albertel 5970: border: 1px solid black;
5971: width: 99%;
5972: background: #FFFFFF;
5973: }
1.795 www 5974:
1.613 albertel 5975: table.LC_scantron_action {
5976: width: 100%;
5977: }
1.795 www 5978:
1.613 albertel 5979: table.LC_scantron_action tr th {
1.698 harmsja 5980: font-weight:bold;
5981: font-style:normal;
1.613 albertel 5982: }
1.795 www 5983:
1.779 bisitz 5984: .LC_edit_problem_header,
1.614 albertel 5985: div.LC_edit_problem_footer {
1.705 tempelho 5986: font-weight: normal;
5987: font-size: medium;
1.602 albertel 5988: margin: 2px;
1.600 albertel 5989: }
1.795 www 5990:
1.600 albertel 5991: div.LC_edit_problem_header,
1.602 albertel 5992: div.LC_edit_problem_header div,
1.614 albertel 5993: div.LC_edit_problem_footer,
5994: div.LC_edit_problem_footer div,
1.602 albertel 5995: div.LC_edit_problem_editxml_header,
5996: div.LC_edit_problem_editxml_header div {
1.600 albertel 5997: margin-top: 5px;
5998: }
1.795 www 5999:
1.600 albertel 6000: div.LC_edit_problem_header_title {
1.705 tempelho 6001: font-weight: bold;
6002: font-size: larger;
1.602 albertel 6003: background: $tabbg;
6004: padding: 3px;
6005: }
1.795 www 6006:
1.602 albertel 6007: table.LC_edit_problem_header_title {
6008: width: 100%;
1.600 albertel 6009: background: $tabbg;
1.602 albertel 6010: }
6011:
6012: div.LC_edit_problem_discards {
6013: float: left;
6014: padding-bottom: 5px;
6015: }
1.795 www 6016:
1.602 albertel 6017: div.LC_edit_problem_saves {
6018: float: right;
6019: padding-bottom: 5px;
1.600 albertel 6020: }
1.795 www 6021:
1.911 bisitz 6022: img.stift {
1.803 bisitz 6023: border-width: 0;
6024: vertical-align: middle;
1.677 riegler 6025: }
1.680 riegler 6026:
1.923 bisitz 6027: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6028: vertical-align: top;
1.777 tempelho 6029: }
1.795 www 6030:
1.716 raeburn 6031: div.LC_createcourse {
1.911 bisitz 6032: margin: 10px 10px 10px 10px;
1.716 raeburn 6033: }
6034:
1.917 raeburn 6035: .LC_dccid {
6036: margin: 0.2em 0 0 0;
6037: padding: 0;
6038: font-size: 90%;
6039: display:none;
6040: }
6041:
1.698 harmsja 6042: a:hover,
1.897 wenzelju 6043: ol.LC_primary_menu a:hover,
1.721 harmsja 6044: ol#LC_MenuBreadcrumbs a:hover,
6045: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6046: ul#LC_secondary_menu a:hover,
1.721 harmsja 6047: .LC_FormSectionClearButton input:hover
1.795 www 6048: ul.LC_TabContent li:hover a {
1.948.2.1 raeburn 6049: color:$button_hover;
1.911 bisitz 6050: text-decoration:none;
1.693 droeschl 6051: }
6052:
1.779 bisitz 6053: h1 {
1.911 bisitz 6054: padding: 0;
6055: line-height:130%;
1.693 droeschl 6056: }
1.698 harmsja 6057:
1.911 bisitz 6058: h2,
6059: h3,
6060: h4,
6061: h5,
6062: h6 {
6063: margin: 5px 0 5px 0;
6064: padding: 0;
6065: line-height:130%;
1.693 droeschl 6066: }
1.795 www 6067:
6068: .LC_hcell {
1.911 bisitz 6069: padding:3px 15px 3px 15px;
6070: margin: 0;
6071: background-color:$tabbg;
6072: color:$fontmenu;
6073: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6074: }
1.795 www 6075:
1.840 bisitz 6076: .LC_Box > .LC_hcell {
1.911 bisitz 6077: margin: 0 -10px 10px -10px;
1.835 bisitz 6078: }
6079:
1.721 harmsja 6080: .LC_noBorder {
1.911 bisitz 6081: border: 0;
1.698 harmsja 6082: }
1.693 droeschl 6083:
1.721 harmsja 6084: .LC_FormSectionClearButton input {
1.911 bisitz 6085: background-color:transparent;
6086: border: none;
6087: cursor:pointer;
6088: text-decoration:underline;
1.693 droeschl 6089: }
1.763 bisitz 6090:
6091: .LC_help_open_topic {
1.911 bisitz 6092: color: #FFFFFF;
6093: background-color: #EEEEFF;
6094: margin: 1px;
6095: padding: 4px;
6096: border: 1px solid #000033;
6097: white-space: nowrap;
6098: /* vertical-align: middle; */
1.759 neumanie 6099: }
1.693 droeschl 6100:
1.911 bisitz 6101: dl,
6102: ul,
6103: div,
6104: fieldset {
6105: margin: 10px 10px 10px 0;
6106: /* overflow: hidden; */
1.693 droeschl 6107: }
1.795 www 6108:
1.838 bisitz 6109: fieldset > legend {
1.911 bisitz 6110: font-weight: bold;
6111: padding: 0 5px 0 5px;
1.838 bisitz 6112: }
6113:
1.813 bisitz 6114: #LC_nav_bar {
1.911 bisitz 6115: float: left;
1.948.2.6 raeburn 6116: margin: 0 0 2px 0;
1.807 droeschl 6117: }
6118:
1.916 droeschl 6119: #LC_realm {
6120: margin: 0.2em 0 0 0;
6121: padding: 0;
6122: font-weight: bold;
6123: text-align: center;
6124: }
6125:
1.911 bisitz 6126: #LC_nav_bar em {
6127: font-weight: bold;
6128: font-style: normal;
1.807 droeschl 6129: }
6130:
1.948.2.6 raeburn 6131: /* Preliminary fix to hide nav_bar inside bookmarks window */
6132: #LC_bookmarks #LC_nav_bar {
6133: display:none;
6134: }
6135:
1.897 wenzelju 6136: ol.LC_primary_menu {
1.911 bisitz 6137: float: right;
1.934 droeschl 6138: margin: 0;
1.807 droeschl 6139: }
6140:
1.929 wenzelju 6141: span.LC_new_message{
6142: font-weight:bold;
6143: color: darkred;
6144: }
6145:
1.852 droeschl 6146: ol#LC_PathBreadcrumbs {
1.911 bisitz 6147: margin: 0;
1.693 droeschl 6148: }
6149:
1.897 wenzelju 6150: ol.LC_primary_menu li {
1.911 bisitz 6151: display: inline;
6152: padding: 5px 5px 0 10px;
6153: vertical-align: top;
1.693 droeschl 6154: }
6155:
1.897 wenzelju 6156: ol.LC_primary_menu li img {
1.911 bisitz 6157: vertical-align: bottom;
1.934 droeschl 6158: height: 1.1em;
1.693 droeschl 6159: }
6160:
1.897 wenzelju 6161: ol.LC_primary_menu a {
1.911 bisitz 6162: color: RGB(80, 80, 80);
6163: text-decoration: none;
1.693 droeschl 6164: }
1.795 www 6165:
1.948.2.7 raeburn 6166: ol.LC_docs_parameters {
6167: margin-left: 0;
6168: padding: 0;
6169: list-style: none;
6170: }
6171:
6172: ol.LC_docs_parameters li {
6173: margin: 0;
6174: padding-right: 20px;
6175: display: inline;
6176: }
6177:
6178: ol.LC_docs_parameters li:before {
6179: content: "\\002022 \\0020";
6180: }
6181:
6182: li.LC_docs_parameters_title {
6183: font-weight: bold;
6184: }
6185:
6186: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6187: content: "";
6188: }
6189:
1.897 wenzelju 6190: ul#LC_secondary_menu {
1.911 bisitz 6191: clear: both;
6192: color: $fontmenu;
6193: background: $tabbg;
6194: list-style: none;
6195: padding: 0;
6196: margin: 0;
6197: width: 100%;
1.808 droeschl 6198: }
6199:
1.897 wenzelju 6200: ul#LC_secondary_menu li {
1.911 bisitz 6201: font-weight: bold;
6202: line-height: 1.8em;
6203: padding: 0 0.8em;
6204: border-right: 1px solid black;
6205: display: inline;
6206: vertical-align: middle;
1.807 droeschl 6207: }
6208:
1.847 tempelho 6209: ul.LC_TabContent {
1.911 bisitz 6210: display:block;
6211: background: $sidebg;
6212: border-bottom: solid 1px $lg_border_color;
6213: list-style:none;
6214: margin: 0 -10px;
6215: padding: 0;
1.693 droeschl 6216: }
6217:
1.795 www 6218: ul.LC_TabContent li,
6219: ul.LC_TabContentBigger li {
1.911 bisitz 6220: float:left;
1.741 harmsja 6221: }
1.795 www 6222:
1.897 wenzelju 6223: ul#LC_secondary_menu li a {
1.911 bisitz 6224: color: $fontmenu;
6225: text-decoration: none;
1.693 droeschl 6226: }
1.795 www 6227:
1.721 harmsja 6228: ul.LC_TabContent {
1.948.2.1 raeburn 6229: min-height:20px;
1.721 harmsja 6230: }
1.795 www 6231:
6232: ul.LC_TabContent li {
1.911 bisitz 6233: vertical-align:middle;
1.948.2.3 raeburn 6234: padding: 0 16px 0 10px;
1.911 bisitz 6235: background-color:$tabbg;
6236: border-bottom:solid 1px $lg_border_color;
1.948.2.1 raeburn 6237: border-right: solid 1px $font;
1.721 harmsja 6238: }
1.795 www 6239:
1.847 tempelho 6240: ul.LC_TabContent .right {
1.911 bisitz 6241: float:right;
1.847 tempelho 6242: }
6243:
1.911 bisitz 6244: ul.LC_TabContent li a,
6245: ul.LC_TabContent li {
6246: color:rgb(47,47,47);
6247: text-decoration:none;
6248: font-size:95%;
6249: font-weight:bold;
1.948.2.1 raeburn 6250: min-height:20px;
6251: }
6252:
1.948.2.3 raeburn 6253: ul.LC_TabContent li a:hover,
6254: ul.LC_TabContent li a:focus {
1.948.2.1 raeburn 6255: color: $button_hover;
1.948.2.3 raeburn 6256: background:none;
6257: outline:none;
1.948.2.1 raeburn 6258: }
6259:
6260: ul.LC_TabContent li:hover {
6261: color: $button_hover;
6262: cursor:pointer;
1.721 harmsja 6263: }
1.795 www 6264:
1.911 bisitz 6265: ul.LC_TabContent li.active {
1.948.2.1 raeburn 6266: color: $font;
1.911 bisitz 6267: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.948.2.1 raeburn 6268: border-bottom:solid 1px #FFFFFF;
6269: cursor: default;
1.744 ehlerst 6270: }
1.795 www 6271:
1.948.2.3 raeburn 6272: ul.LC_TabContent li.active a {
6273: color:$font;
6274: background:#FFFFFF;
6275: outline: none;
6276: }
1.870 tempelho 6277: #maincoursedoc {
1.911 bisitz 6278: clear:both;
1.870 tempelho 6279: }
6280:
6281: ul.LC_TabContentBigger {
1.911 bisitz 6282: display:block;
6283: list-style:none;
6284: padding: 0;
1.870 tempelho 6285: }
6286:
1.795 www 6287: ul.LC_TabContentBigger li {
1.911 bisitz 6288: vertical-align:bottom;
6289: height: 30px;
6290: font-size:110%;
6291: font-weight:bold;
6292: color: #737373;
1.841 tempelho 6293: }
6294:
1.948.2.3 raeburn 6295: ul.LC_TabContentBigger li.active {
6296: position: relative;
6297: top: 1px;
6298: }
1.870 tempelho 6299:
6300: ul.LC_TabContentBigger li a {
1.911 bisitz 6301: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6302: height: 30px;
6303: line-height: 30px;
6304: text-align: center;
6305: display: block;
6306: text-decoration: none;
1.948.2.3 raeburn 6307: outline: none;
1.741 harmsja 6308: }
1.795 www 6309:
1.870 tempelho 6310: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6311: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6312: color:$font;
1.744 ehlerst 6313: }
1.795 www 6314:
1.870 tempelho 6315: ul.LC_TabContentBigger li b {
1.911 bisitz 6316: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6317: display: block;
6318: float: left;
6319: padding: 0 30px;
1.948.2.3 raeburn 6320: border-bottom: 1px solid $lg_border_color;
6321: }
6322:
6323: ul.LC_TabContentBigger li:hover b {
6324: color:$button_hover;
1.870 tempelho 6325: }
6326:
6327: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6328: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6329: color:$font;
1.948.2.3 raeburn 6330: border: 0;
6331: cursor:default;
1.741 harmsja 6332: }
1.693 droeschl 6333:
1.862 bisitz 6334: ul.LC_CourseBreadcrumbs {
6335: background: $sidebg;
6336: line-height: 32px;
6337: padding-left: 10px;
6338: margin: 0 0 10px 0;
6339: list-style-position: inside;
6340:
6341: }
6342:
1.911 bisitz 6343: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6344: ol#LC_PathBreadcrumbs {
1.911 bisitz 6345: padding-left: 10px;
6346: margin: 0;
1.933 droeschl 6347: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6348: }
6349:
1.911 bisitz 6350: ol#LC_MenuBreadcrumbs li,
6351: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6352: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6353: display: inline;
1.933 droeschl 6354: white-space: normal;
1.693 droeschl 6355: }
6356:
1.823 bisitz 6357: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6358: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6359: text-decoration: none;
6360: font-size:90%;
1.693 droeschl 6361: }
1.795 www 6362:
1.948.2.7 raeburn 6363: ol#LC_MenuBreadcrumbs h1 {
6364: display: inline;
6365: font-size: 90%;
6366: line-height: 2.5em;
6367: margin: 0;
6368: padding: 0;
6369: }
6370:
1.795 www 6371: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6372: text-decoration:none;
6373: font-size:100%;
6374: font-weight:bold;
1.693 droeschl 6375: }
1.795 www 6376:
1.840 bisitz 6377: .LC_Box {
1.911 bisitz 6378: border: solid 1px $lg_border_color;
6379: padding: 0 10px 10px 10px;
1.746 neumanie 6380: }
1.795 www 6381:
6382: .LC_AboutMe_Image {
1.911 bisitz 6383: float:left;
6384: margin-right:10px;
1.747 neumanie 6385: }
1.795 www 6386:
6387: .LC_Clear_AboutMe_Image {
1.911 bisitz 6388: clear:left;
1.747 neumanie 6389: }
1.795 www 6390:
1.721 harmsja 6391: dl.LC_ListStyleClean dt {
1.911 bisitz 6392: padding-right: 5px;
6393: display: table-header-group;
1.693 droeschl 6394: }
6395:
1.721 harmsja 6396: dl.LC_ListStyleClean dd {
1.911 bisitz 6397: display: table-row;
1.693 droeschl 6398: }
6399:
1.721 harmsja 6400: .LC_ListStyleClean,
6401: .LC_ListStyleSimple,
6402: .LC_ListStyleNormal,
1.795 www 6403: .LC_ListStyleSpecial {
1.911 bisitz 6404: /* display:block; */
6405: list-style-position: inside;
6406: list-style-type: none;
6407: overflow: hidden;
6408: padding: 0;
1.693 droeschl 6409: }
6410:
1.721 harmsja 6411: .LC_ListStyleSimple li,
6412: .LC_ListStyleSimple dd,
6413: .LC_ListStyleNormal li,
6414: .LC_ListStyleNormal dd,
6415: .LC_ListStyleSpecial li,
1.795 www 6416: .LC_ListStyleSpecial dd {
1.911 bisitz 6417: margin: 0;
6418: padding: 5px 5px 5px 10px;
6419: clear: both;
1.693 droeschl 6420: }
6421:
1.721 harmsja 6422: .LC_ListStyleClean li,
6423: .LC_ListStyleClean dd {
1.911 bisitz 6424: padding-top: 0;
6425: padding-bottom: 0;
1.693 droeschl 6426: }
6427:
1.721 harmsja 6428: .LC_ListStyleSimple dd,
1.795 www 6429: .LC_ListStyleSimple li {
1.911 bisitz 6430: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6431: }
6432:
1.721 harmsja 6433: .LC_ListStyleSpecial li,
6434: .LC_ListStyleSpecial dd {
1.911 bisitz 6435: list-style-type: none;
6436: background-color: RGB(220, 220, 220);
6437: margin-bottom: 4px;
1.693 droeschl 6438: }
6439:
1.721 harmsja 6440: table.LC_SimpleTable {
1.911 bisitz 6441: margin:5px;
6442: border:solid 1px $lg_border_color;
1.795 www 6443: }
1.693 droeschl 6444:
1.721 harmsja 6445: table.LC_SimpleTable tr {
1.911 bisitz 6446: padding: 0;
6447: border:solid 1px $lg_border_color;
1.693 droeschl 6448: }
1.795 www 6449:
6450: table.LC_SimpleTable thead {
1.911 bisitz 6451: background:rgb(220,220,220);
1.693 droeschl 6452: }
6453:
1.721 harmsja 6454: div.LC_columnSection {
1.911 bisitz 6455: display: block;
6456: clear: both;
6457: overflow: hidden;
6458: margin: 0;
1.693 droeschl 6459: }
6460:
1.721 harmsja 6461: div.LC_columnSection>* {
1.911 bisitz 6462: float: left;
6463: margin: 10px 20px 10px 0;
6464: overflow:hidden;
1.693 droeschl 6465: }
1.721 harmsja 6466:
1.795 www 6467: table em {
1.911 bisitz 6468: font-weight: bold;
6469: font-style: normal;
1.748 schulted 6470: }
1.795 www 6471:
1.779 bisitz 6472: table.LC_tableBrowseRes,
1.795 www 6473: table.LC_tableOfContent {
1.911 bisitz 6474: border:none;
6475: border-spacing: 1px;
6476: padding: 3px;
6477: background-color: #FFFFFF;
6478: font-size: 90%;
1.753 droeschl 6479: }
1.789 droeschl 6480:
1.911 bisitz 6481: table.LC_tableOfContent {
6482: border-collapse: collapse;
1.789 droeschl 6483: }
6484:
1.771 droeschl 6485: table.LC_tableBrowseRes a,
1.768 schulted 6486: table.LC_tableOfContent a {
1.911 bisitz 6487: background-color: transparent;
6488: text-decoration: none;
1.753 droeschl 6489: }
6490:
1.795 www 6491: table.LC_tableOfContent img {
1.911 bisitz 6492: border: none;
6493: height: 1.3em;
6494: vertical-align: text-bottom;
6495: margin-right: 0.3em;
1.753 droeschl 6496: }
1.757 schulted 6497:
1.795 www 6498: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6499: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6500: }
6501:
1.795 www 6502: a#LC_content_toolbar_launchnav {
1.911 bisitz 6503: background-image:url(/res/adm/pages/start-navigation.gif);
1.774 ehlerst 6504: }
6505:
1.795 www 6506: a#LC_content_toolbar_closenav {
1.911 bisitz 6507: background-image:url(/res/adm/pages/close-navigation.gif);
1.774 ehlerst 6508: }
6509:
1.795 www 6510: a#LC_content_toolbar_everything {
1.911 bisitz 6511: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6512: }
6513:
1.795 www 6514: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6515: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6516: }
6517:
1.795 www 6518: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6519: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6520: }
6521:
1.795 www 6522: a#LC_content_toolbar_changefolder {
1.911 bisitz 6523: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6524: }
6525:
1.795 www 6526: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6527: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6528: }
6529:
1.795 www 6530: ul#LC_toolbar li a:hover {
1.911 bisitz 6531: background-position: bottom center;
1.757 schulted 6532: }
6533:
1.795 www 6534: ul#LC_toolbar {
1.911 bisitz 6535: padding: 0;
6536: margin: 2px;
6537: list-style:none;
6538: position:relative;
6539: background-color:white;
1.757 schulted 6540: }
6541:
1.795 www 6542: ul#LC_toolbar li {
1.911 bisitz 6543: border:1px solid white;
6544: padding: 0;
6545: margin: 0;
6546: float: left;
6547: display:inline;
6548: vertical-align:middle;
6549: }
1.757 schulted 6550:
1.783 amueller 6551:
1.795 www 6552: a.LC_toolbarItem {
1.911 bisitz 6553: display:block;
6554: padding: 0;
6555: margin: 0;
6556: height: 32px;
6557: width: 32px;
6558: color:white;
6559: border: none;
6560: background-repeat:no-repeat;
6561: background-color:transparent;
1.757 schulted 6562: }
6563:
1.915 droeschl 6564: ul.LC_funclist {
6565: margin: 0;
6566: padding: 0.5em 1em 0.5em 0;
6567: }
6568:
1.933 droeschl 6569: ul.LC_funclist > li:first-child {
6570: font-weight:bold;
6571: margin-left:0.8em;
6572: }
6573:
1.915 droeschl 6574: ul.LC_funclist + ul.LC_funclist {
6575: /*
6576: left border as a seperator if we have more than
6577: one list
6578: */
6579: border-left: 1px solid $sidebg;
6580: /*
6581: this hides the left border behind the border of the
6582: outer box if element is wrapped to the next 'line'
6583: */
6584: margin-left: -1px;
6585: }
6586:
1.843 bisitz 6587: ul.LC_funclist li {
1.915 droeschl 6588: display: inline;
1.782 bisitz 6589: white-space: nowrap;
1.915 droeschl 6590: margin: 0 0 0 25px;
6591: line-height: 150%;
1.782 bisitz 6592: }
6593:
1.930 faziophi 6594: .ui-accordion .LC_advanced_toggle {
6595: float: right;
6596: font-size: 90%;
6597: padding: 0px 4px
6598: }
1.757 schulted 6599:
1.343 albertel 6600: END
6601: }
6602:
1.306 albertel 6603: =pod
6604:
6605: =item * &headtag()
6606:
6607: Returns a uniform footer for LON-CAPA web pages.
6608:
1.307 albertel 6609: Inputs: $title - optional title for the head
6610: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6611: $args - optional arguments
1.319 albertel 6612: force_register - if is true call registerurl so the remote is
6613: informed
1.415 albertel 6614: redirect -> array ref of
6615: 1- seconds before redirect occurs
6616: 2- url to redirect to
6617: 3- whether the side effect should occur
1.315 albertel 6618: (side effect of setting
6619: $env{'internal.head.redirect'} to the url
6620: redirected too)
1.352 albertel 6621: domain -> force to color decorate a page for a specific
6622: domain
6623: function -> force usage of a specific rolish color scheme
6624: bgcolor -> override the default page bgcolor
1.460 albertel 6625: no_auto_mt_title
6626: -> prevent &mt()ing the title arg
1.464 albertel 6627:
1.306 albertel 6628: =cut
6629:
6630: sub headtag {
1.313 albertel 6631: my ($title,$head_extra,$args) = @_;
1.306 albertel 6632:
1.363 albertel 6633: my $function = $args->{'function'} || &get_users_function();
6634: my $domain = $args->{'domain'} || &determinedomain();
6635: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6636: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6637: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6638: #time(),
1.418 albertel 6639: $env{'environment.color.timestamp'},
1.363 albertel 6640: $function,$domain,$bgcolor);
6641:
1.369 www 6642: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6643:
1.308 albertel 6644: my $result =
6645: '<head>'.
1.461 albertel 6646: &font_settings();
1.319 albertel 6647:
1.461 albertel 6648: if (!$args->{'frameset'}) {
6649: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6650: }
1.319 albertel 6651: if ($args->{'force_register'}) {
6652: $result .= &Apache::lonmenu::registerurl(1);
6653: }
1.436 albertel 6654: if (!$args->{'no_nav_bar'}
6655: && !$args->{'only_body'}
6656: && !$args->{'frameset'}) {
6657: $result .= &help_menu_js();
6658: }
1.319 albertel 6659:
1.314 albertel 6660: if (ref($args->{'redirect'})) {
1.414 albertel 6661: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6662: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6663: if (!$inhibit_continue) {
6664: $env{'internal.head.redirect'} = $url;
6665: }
1.313 albertel 6666: $result.=<<ADDMETA
6667: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6668: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6669: ADDMETA
6670: }
1.306 albertel 6671: if (!defined($title)) {
6672: $title = 'The LearningOnline Network with CAPA';
6673: }
1.460 albertel 6674: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6675: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6676: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6677: .$head_extra;
1.306 albertel 6678: return $result;
6679: }
6680:
6681: =pod
6682:
1.340 albertel 6683: =item * &font_settings()
6684:
6685: Returns neccessary <meta> to set the proper encoding
6686:
6687: Inputs: none
6688:
6689: =cut
6690:
6691: sub font_settings {
6692: my $headerstring='';
1.647 www 6693: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6694: $headerstring.=
6695: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6696: }
6697: return $headerstring;
6698: }
6699:
1.341 albertel 6700: =pod
6701:
6702: =item * &xml_begin()
6703:
6704: Returns the needed doctype and <html>
6705:
6706: Inputs: none
6707:
6708: =cut
6709:
6710: sub xml_begin {
6711: my $output='';
6712:
6713: if ($env{'browser.mathml'}) {
6714: $output='<?xml version="1.0"?>'
6715: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6716: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6717:
6718: # .'<!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">] >'
6719: .'<!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">'
6720: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6721: .'xmlns="http://www.w3.org/1999/xhtml">';
6722: } else {
1.849 bisitz 6723: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6724: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6725: }
6726: return $output;
6727: }
1.340 albertel 6728:
6729: =pod
6730:
1.306 albertel 6731: =item * &endheadtag()
6732:
6733: Returns a uniform </head> for LON-CAPA web pages.
6734:
6735: Inputs: none
6736:
6737: =cut
6738:
6739: sub endheadtag {
6740: return '</head>';
6741: }
6742:
6743: =pod
6744:
6745: =item * &head()
6746:
6747: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6748:
1.648 raeburn 6749: Inputs:
6750:
6751: =over 4
6752:
6753: $title - optional title for the page
6754:
6755: $head_extra - optional extra HTML to put inside the <head>
6756:
6757: =back
1.405 albertel 6758:
1.306 albertel 6759: =cut
6760:
6761: sub head {
1.325 albertel 6762: my ($title,$head_extra,$args) = @_;
6763: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6764: }
6765:
6766: =pod
6767:
6768: =item * &start_page()
6769:
6770: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6771:
1.648 raeburn 6772: Inputs:
6773:
6774: =over 4
6775:
6776: $title - optional title for the page
6777:
6778: $head_extra - optional extra HTML to incude inside the <head>
6779:
6780: $args - additional optional args supported are:
6781:
6782: =over 8
6783:
6784: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6785: arg on
1.814 bisitz 6786: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6787: add_entries -> additional attributes to add to the <body>
6788: domain -> force to color decorate a page for a
1.317 albertel 6789: specific domain
1.648 raeburn 6790: function -> force usage of a specific rolish color
1.317 albertel 6791: scheme
1.648 raeburn 6792: redirect -> see &headtag()
6793: bgcolor -> override the default page bg color
6794: js_ready -> return a string ready for being used in
1.317 albertel 6795: a javascript writeln
1.648 raeburn 6796: html_encode -> return a string ready for being used in
1.320 albertel 6797: a html attribute
1.648 raeburn 6798: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6799: $forcereg arg
1.648 raeburn 6800: frameset -> if true will start with a <frameset>
1.330 albertel 6801: rather than <body>
1.648 raeburn 6802: skip_phases -> hash ref of
1.338 albertel 6803: head -> skip the <html><head> generation
6804: body -> skip all <body> generation
1.648 raeburn 6805: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6806: 'Switch To Inline Menu' link
1.648 raeburn 6807: no_auto_mt_title -> prevent &mt()ing the title arg
6808: inherit_jsmath -> when creating popup window in a page,
6809: should it have jsmath forced on by the
6810: current page
1.867 kalberla 6811: bread_crumbs -> Array containing breadcrumbs
6812: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6813:
1.648 raeburn 6814: =back
1.460 albertel 6815:
1.648 raeburn 6816: =back
1.562 albertel 6817:
1.306 albertel 6818: =cut
6819:
6820: sub start_page {
1.309 albertel 6821: my ($title,$head_extra,$args) = @_;
1.318 albertel 6822: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6823: my %head_args;
1.352 albertel 6824: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6825: 'bgcolor','frameset','no_nav_bar','only_body',
6826: 'no_auto_mt_title') {
1.319 albertel 6827: if (defined($args->{$arg})) {
1.324 raeburn 6828: $head_args{$arg} = $args->{$arg};
1.319 albertel 6829: }
1.313 albertel 6830: }
1.319 albertel 6831:
1.315 albertel 6832: $env{'internal.start_page'}++;
1.338 albertel 6833: my $result;
6834: if (! exists($args->{'skip_phases'}{'head'}) ) {
6835: $result.=
1.341 albertel 6836: &xml_begin().
1.338 albertel 6837: &headtag($title,$head_extra,\%head_args).&endheadtag();
6838: }
6839:
6840: if (! exists($args->{'skip_phases'}{'body'}) ) {
6841: if ($args->{'frameset'}) {
6842: my $attr_string = &make_attr_string($args->{'force_register'},
6843: $args->{'add_entries'});
6844: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6845: } else {
6846: $result .=
6847: &bodytag($title,
6848: $args->{'function'}, $args->{'add_entries'},
6849: $args->{'only_body'}, $args->{'domain'},
6850: $args->{'force_register'}, $args->{'no_nav_bar'},
6851: $args->{'bgcolor'}, $args->{'no_inline_link'},
6852: $args);
6853: }
1.330 albertel 6854: }
1.338 albertel 6855:
1.315 albertel 6856: if ($args->{'js_ready'}) {
1.713 kaisler 6857: $result = &js_ready($result);
1.315 albertel 6858: }
1.320 albertel 6859: if ($args->{'html_encode'}) {
1.713 kaisler 6860: $result = &html_encode($result);
6861: }
6862:
1.813 bisitz 6863: # Preparation for new and consistent functionlist at top of screen
6864: # if ($args->{'functionlist'}) {
6865: # $result .= &build_functionlist();
6866: #}
6867:
6868: # Don't add anything more if only_body wanted
6869: return $result if $args->{'only_body'};
6870:
1.920 raeburn 6871: #Breadcrumbs for Construction Space provided by &bodytag.
6872: if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
6873: return $result;
6874: }
6875:
1.813 bisitz 6876: #Breadcrumbs
1.758 kaisler 6877: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6878: &Apache::lonhtmlcommon::clear_breadcrumbs();
6879: #if any br links exists, add them to the breadcrumbs
6880: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6881: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6882: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6883: }
6884: }
6885:
6886: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6887: if(exists($args->{'bread_crumbs_component'})){
6888: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6889: }else{
6890: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6891: }
1.320 albertel 6892: }
1.315 albertel 6893: return $result;
1.306 albertel 6894: }
6895:
1.330 albertel 6896:
1.306 albertel 6897: =pod
6898:
6899: =item * &head()
6900:
6901: Returns a complete </body></html> section for LON-CAPA web pages.
6902:
1.315 albertel 6903: Inputs: $args - additional optional args supported are:
6904: js_ready -> return a string ready for being used in
6905: a javascript writeln
1.320 albertel 6906: html_encode -> return a string ready for being used in
6907: a html attribute
1.330 albertel 6908: frameset -> if true will start with a <frameset>
6909: rather than <body>
1.493 albertel 6910: dicsussion -> if true will get discussion from
6911: lonxml::xmlend
6912: (you can pass the target and parser arguments
6913: through optional 'target' and 'parser' args
6914: to this routine)
1.306 albertel 6915:
6916: =cut
6917:
6918: sub end_page {
1.315 albertel 6919: my ($args) = @_;
6920: $env{'internal.end_page'}++;
1.330 albertel 6921: my $result;
1.335 albertel 6922: if ($args->{'discussion'}) {
6923: my ($target,$parser);
6924: if (ref($args->{'discussion'})) {
6925: ($target,$parser) =($args->{'discussion'}{'target'},
6926: $args->{'discussion'}{'parser'});
6927: }
6928: $result .= &Apache::lonxml::xmlend($target,$parser);
6929: }
6930:
1.330 albertel 6931: if ($args->{'frameset'}) {
6932: $result .= '</frameset>';
6933: } else {
1.635 raeburn 6934: $result .= &endbodytag($args);
1.330 albertel 6935: }
6936: $result .= "\n</html>";
6937:
1.315 albertel 6938: if ($args->{'js_ready'}) {
1.317 albertel 6939: $result = &js_ready($result);
1.315 albertel 6940: }
1.335 albertel 6941:
1.320 albertel 6942: if ($args->{'html_encode'}) {
6943: $result = &html_encode($result);
6944: }
1.335 albertel 6945:
1.315 albertel 6946: return $result;
6947: }
6948:
1.320 albertel 6949: sub html_encode {
6950: my ($result) = @_;
6951:
1.322 albertel 6952: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6953:
6954: return $result;
6955: }
1.317 albertel 6956: sub js_ready {
6957: my ($result) = @_;
6958:
1.323 albertel 6959: $result =~ s/[\n\r]/ /xmsg;
6960: $result =~ s/\\/\\\\/xmsg;
6961: $result =~ s/'/\\'/xmsg;
1.372 albertel 6962: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6963:
6964: return $result;
6965: }
6966:
1.315 albertel 6967: sub validate_page {
6968: if ( exists($env{'internal.start_page'})
1.316 albertel 6969: && $env{'internal.start_page'} > 1) {
6970: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6971: $env{'internal.start_page'}.' '.
1.316 albertel 6972: $ENV{'request.filename'});
1.315 albertel 6973: }
6974: if ( exists($env{'internal.end_page'})
1.316 albertel 6975: && $env{'internal.end_page'} > 1) {
6976: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6977: $env{'internal.end_page'}.' '.
1.316 albertel 6978: $env{'request.filename'});
1.315 albertel 6979: }
6980: if ( exists($env{'internal.start_page'})
6981: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6982: &Apache::lonnet::logthis('start_page called without end_page '.
6983: $env{'request.filename'});
1.315 albertel 6984: }
6985: if ( ! exists($env{'internal.start_page'})
6986: && exists($env{'internal.end_page'})) {
1.316 albertel 6987: &Apache::lonnet::logthis('end_page called without start_page'.
6988: $env{'request.filename'});
1.315 albertel 6989: }
1.306 albertel 6990: }
1.315 albertel 6991:
1.318 albertel 6992: sub simple_error_page {
6993: my ($r,$title,$msg) = @_;
6994: my $page =
6995: &Apache::loncommon::start_page($title).
6996: &mt($msg).
6997: &Apache::loncommon::end_page();
6998: if (ref($r)) {
6999: $r->print($page);
1.327 albertel 7000: return;
1.318 albertel 7001: }
7002: return $page;
7003: }
1.347 albertel 7004:
7005: {
1.610 albertel 7006: my @row_count;
1.948.2.5 raeburn 7007:
7008: sub start_data_table_count {
7009: unshift(@row_count, 0);
7010: return;
7011: }
7012:
7013: sub end_data_table_count {
7014: shift(@row_count);
7015: return;
7016: }
7017:
1.347 albertel 7018: sub start_data_table {
1.422 albertel 7019: my ($add_class) = @_;
7020: my $css_class = (join(' ','LC_data_table',$add_class));
1.948.2.5 raeburn 7021: &start_data_table_count();
1.422 albertel 7022: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 7023: }
7024:
7025: sub end_data_table {
1.948.2.5 raeburn 7026: &end_data_table_count();
1.389 albertel 7027: return '</table>'."\n";;
1.347 albertel 7028: }
7029:
7030: sub start_data_table_row {
1.422 albertel 7031: my ($add_class) = @_;
1.610 albertel 7032: $row_count[0]++;
7033: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7034: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 7035: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 7036: }
1.471 banghart 7037:
7038: sub continue_data_table_row {
7039: my ($add_class) = @_;
1.610 albertel 7040: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7041: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 7042: return '<tr class="'.$css_class.'">'."\n";;
7043: }
1.347 albertel 7044:
7045: sub end_data_table_row {
1.389 albertel 7046: return '</tr>'."\n";;
1.347 albertel 7047: }
1.367 www 7048:
1.421 albertel 7049: sub start_data_table_empty_row {
1.707 bisitz 7050: # $row_count[0]++;
1.421 albertel 7051: return '<tr class="LC_empty_row" >'."\n";;
7052: }
7053:
7054: sub end_data_table_empty_row {
7055: return '</tr>'."\n";;
7056: }
7057:
1.367 www 7058: sub start_data_table_header_row {
1.389 albertel 7059: return '<tr class="LC_header_row">'."\n";;
1.367 www 7060: }
7061:
7062: sub end_data_table_header_row {
1.389 albertel 7063: return '</tr>'."\n";;
1.367 www 7064: }
1.890 droeschl 7065:
7066: sub data_table_caption {
7067: my $caption = shift;
7068: return "<caption class=\"LC_caption\">$caption</caption>";
7069: }
1.347 albertel 7070: }
7071:
1.548 albertel 7072: =pod
7073:
7074: =item * &inhibit_menu_check($arg)
7075:
7076: Checks for a inhibitmenu state and generates output to preserve it
7077:
7078: Inputs: $arg - can be any of
7079: - undef - in which case the return value is a string
7080: to add into arguments list of a uri
7081: - 'input' - in which case the return value is a HTML
7082: <form> <input> field of type hidden to
7083: preserve the value
7084: - a url - in which case the return value is the url with
7085: the neccesary cgi args added to preserve the
7086: inhibitmenu state
7087: - a ref to a url - no return value, but the string is
7088: updated to include the neccessary cgi
7089: args to preserve the inhibitmenu state
7090:
7091: =cut
7092:
7093: sub inhibit_menu_check {
7094: my ($arg) = @_;
7095: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7096: if ($arg eq 'input') {
7097: if ($env{'form.inhibitmenu'}) {
7098: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7099: } else {
7100: return
7101: }
7102: }
7103: if ($env{'form.inhibitmenu'}) {
7104: if (ref($arg)) {
7105: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7106: } elsif ($arg eq '') {
7107: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7108: } else {
7109: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7110: }
7111: }
7112: if (!ref($arg)) {
7113: return $arg;
7114: }
7115: }
7116:
1.251 albertel 7117: ###############################################
1.182 matthew 7118:
7119: =pod
7120:
1.549 albertel 7121: =back
7122:
7123: =head1 User Information Routines
7124:
7125: =over 4
7126:
1.405 albertel 7127: =item * &get_users_function()
1.182 matthew 7128:
7129: Used by &bodytag to determine the current users primary role.
7130: Returns either 'student','coordinator','admin', or 'author'.
7131:
7132: =cut
7133:
7134: ###############################################
7135: sub get_users_function {
1.815 tempelho 7136: my $function = 'norole';
1.818 tempelho 7137: if ($env{'request.role'}=~/^(st)/) {
7138: $function='student';
7139: }
1.907 raeburn 7140: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7141: $function='coordinator';
7142: }
1.258 albertel 7143: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7144: $function='admin';
7145: }
1.826 bisitz 7146: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7147: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7148: $function='author';
7149: }
7150: return $function;
1.54 www 7151: }
1.99 www 7152:
7153: ###############################################
7154:
1.233 raeburn 7155: =pod
7156:
1.821 raeburn 7157: =item * &show_course()
7158:
7159: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7160: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7161:
7162: Inputs:
7163: None
7164:
7165: Outputs:
7166: Scalar: 1 if 'Course' to be used, 0 otherwise.
7167:
7168: =cut
7169:
7170: ###############################################
7171: sub show_course {
7172: my $course = !$env{'user.adv'};
7173: if (!$env{'user.adv'}) {
7174: foreach my $env (keys(%env)) {
7175: next if ($env !~ m/^user\.priv\./);
7176: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7177: $course = 0;
7178: last;
7179: }
7180: }
7181: }
7182: return $course;
7183: }
7184:
7185: ###############################################
7186:
7187: =pod
7188:
1.542 raeburn 7189: =item * &check_user_status()
1.274 raeburn 7190:
7191: Determines current status of supplied role for a
7192: specific user. Roles can be active, previous or future.
7193:
7194: Inputs:
7195: user's domain, user's username, course's domain,
1.375 raeburn 7196: course's number, optional section ID.
1.274 raeburn 7197:
7198: Outputs:
7199: role status: active, previous or future.
7200:
7201: =cut
7202:
7203: sub check_user_status {
1.412 raeburn 7204: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.948.2.11! raeburn 7205: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
! 7206: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7207: my @uroles = keys %userinfo;
7208: my $srchstr;
7209: my $active_chk = 'none';
1.412 raeburn 7210: my $now = time;
1.274 raeburn 7211: if (@uroles > 0) {
1.908 raeburn 7212: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7213: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7214: } else {
1.412 raeburn 7215: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7216: }
7217: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7218: my $role_end = 0;
7219: my $role_start = 0;
7220: $active_chk = 'active';
1.412 raeburn 7221: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7222: $role_end = $1;
7223: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7224: $role_start = $1;
1.274 raeburn 7225: }
7226: }
7227: if ($role_start > 0) {
1.412 raeburn 7228: if ($now < $role_start) {
1.274 raeburn 7229: $active_chk = 'future';
7230: }
7231: }
7232: if ($role_end > 0) {
1.412 raeburn 7233: if ($now > $role_end) {
1.274 raeburn 7234: $active_chk = 'previous';
7235: }
7236: }
7237: }
7238: }
7239: return $active_chk;
7240: }
7241:
7242: ###############################################
7243:
7244: =pod
7245:
1.405 albertel 7246: =item * &get_sections()
1.233 raeburn 7247:
7248: Determines all the sections for a course including
7249: sections with students and sections containing other roles.
1.419 raeburn 7250: Incoming parameters:
7251:
7252: 1. domain
7253: 2. course number
7254: 3. reference to array containing roles for which sections should
7255: be gathered (optional).
7256: 4. reference to array containing status types for which sections
7257: should be gathered (optional).
7258:
7259: If the third argument is undefined, sections are gathered for any role.
7260: If the fourth argument is undefined, sections are gathered for any status.
7261: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7262:
1.374 raeburn 7263: Returns section hash (keys are section IDs, values are
7264: number of users in each section), subject to the
1.419 raeburn 7265: optional roles filter, optional status filter
1.233 raeburn 7266:
7267: =cut
7268:
7269: ###############################################
7270: sub get_sections {
1.419 raeburn 7271: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7272: if (!defined($cdom) || !defined($cnum)) {
7273: my $cid = $env{'request.course.id'};
7274:
7275: return if (!defined($cid));
7276:
7277: $cdom = $env{'course.'.$cid.'.domain'};
7278: $cnum = $env{'course.'.$cid.'.num'};
7279: }
7280:
7281: my %sectioncount;
1.419 raeburn 7282: my $now = time;
1.240 albertel 7283:
1.366 albertel 7284: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7285: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7286: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7287: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7288: my $start_index = &Apache::loncoursedata::CL_START();
7289: my $end_index = &Apache::loncoursedata::CL_END();
7290: my $status;
1.366 albertel 7291: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7292: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7293: $data->[$status_index],
7294: $data->[$start_index],
7295: $data->[$end_index]);
7296: if ($stu_status eq 'Active') {
7297: $status = 'active';
7298: } elsif ($end < $now) {
7299: $status = 'previous';
7300: } elsif ($start > $now) {
7301: $status = 'future';
7302: }
7303: if ($section ne '-1' && $section !~ /^\s*$/) {
7304: if ((!defined($possible_status)) || (($status ne '') &&
7305: (grep/^\Q$status\E$/,@{$possible_status}))) {
7306: $sectioncount{$section}++;
7307: }
1.240 albertel 7308: }
7309: }
7310: }
7311: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7312: foreach my $user (sort(keys(%courseroles))) {
7313: if ($user !~ /^(\w{2})/) { next; }
7314: my ($role) = ($user =~ /^(\w{2})/);
7315: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7316: my ($section,$status);
1.240 albertel 7317: if ($role eq 'cr' &&
7318: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7319: $section=$1;
7320: }
7321: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7322: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7323: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7324: if ($end == -1 && $start == -1) {
7325: next; #deleted role
7326: }
7327: if (!defined($possible_status)) {
7328: $sectioncount{$section}++;
7329: } else {
7330: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7331: $status = 'active';
7332: } elsif ($end < $now) {
7333: $status = 'future';
7334: } elsif ($start > $now) {
7335: $status = 'previous';
7336: }
7337: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7338: $sectioncount{$section}++;
7339: }
7340: }
1.233 raeburn 7341: }
1.366 albertel 7342: return %sectioncount;
1.233 raeburn 7343: }
7344:
1.274 raeburn 7345: ###############################################
1.294 raeburn 7346:
7347: =pod
1.405 albertel 7348:
7349: =item * &get_course_users()
7350:
1.275 raeburn 7351: Retrieves usernames:domains for users in the specified course
7352: with specific role(s), and access status.
7353:
7354: Incoming parameters:
1.277 albertel 7355: 1. course domain
7356: 2. course number
7357: 3. access status: users must have - either active,
1.275 raeburn 7358: previous, future, or all.
1.277 albertel 7359: 4. reference to array of permissible roles
1.288 raeburn 7360: 5. reference to array of section restrictions (optional)
7361: 6. reference to results object (hash of hashes).
7362: 7. reference to optional userdata hash
1.609 raeburn 7363: 8. reference to optional statushash
1.630 raeburn 7364: 9. flag if privileged users (except those set to unhide in
7365: course settings) should be excluded
1.609 raeburn 7366: Keys of top level results hash are roles.
1.275 raeburn 7367: Keys of inner hashes are username:domain, with
7368: values set to access type.
1.288 raeburn 7369: Optional userdata hash returns an array with arguments in the
7370: same order as loncoursedata::get_classlist() for student data.
7371:
1.609 raeburn 7372: Optional statushash returns
7373:
1.288 raeburn 7374: Entries for end, start, section and status are blank because
7375: of the possibility of multiple values for non-student roles.
7376:
1.275 raeburn 7377: =cut
1.405 albertel 7378:
1.275 raeburn 7379: ###############################################
1.405 albertel 7380:
1.275 raeburn 7381: sub get_course_users {
1.630 raeburn 7382: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7383: my %idx = ();
1.419 raeburn 7384: my %seclists;
1.288 raeburn 7385:
7386: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7387: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7388: $idx{end} = &Apache::loncoursedata::CL_END();
7389: $idx{start} = &Apache::loncoursedata::CL_START();
7390: $idx{id} = &Apache::loncoursedata::CL_ID();
7391: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7392: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7393: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7394:
1.290 albertel 7395: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7396: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7397: my $now = time;
1.277 albertel 7398: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7399: my $match = 0;
1.412 raeburn 7400: my $secmatch = 0;
1.419 raeburn 7401: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7402: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7403: if ($section eq '') {
7404: $section = 'none';
7405: }
1.291 albertel 7406: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7407: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7408: $secmatch = 1;
7409: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7410: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7411: $secmatch = 1;
7412: }
7413: } else {
1.419 raeburn 7414: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7415: $secmatch = 1;
7416: }
1.290 albertel 7417: }
1.412 raeburn 7418: if (!$secmatch) {
7419: next;
7420: }
1.419 raeburn 7421: }
1.275 raeburn 7422: if (defined($$types{'active'})) {
1.288 raeburn 7423: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7424: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7425: $match = 1;
1.275 raeburn 7426: }
7427: }
7428: if (defined($$types{'previous'})) {
1.609 raeburn 7429: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7430: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7431: $match = 1;
1.275 raeburn 7432: }
7433: }
7434: if (defined($$types{'future'})) {
1.609 raeburn 7435: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7436: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7437: $match = 1;
1.275 raeburn 7438: }
7439: }
1.609 raeburn 7440: if ($match) {
7441: push(@{$seclists{$student}},$section);
7442: if (ref($userdata) eq 'HASH') {
7443: $$userdata{$student} = $$classlist{$student};
7444: }
7445: if (ref($statushash) eq 'HASH') {
7446: $statushash->{$student}{'st'}{$section} = $status;
7447: }
1.288 raeburn 7448: }
1.275 raeburn 7449: }
7450: }
1.412 raeburn 7451: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7452: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7453: my $now = time;
1.609 raeburn 7454: my %displaystatus = ( previous => 'Expired',
7455: active => 'Active',
7456: future => 'Future',
7457: );
1.630 raeburn 7458: my %nothide;
7459: if ($hidepriv) {
7460: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7461: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7462: if ($user !~ /:/) {
7463: $nothide{join(':',split(/[\@]/,$user))}=1;
7464: } else {
7465: $nothide{$user} = 1;
7466: }
7467: }
7468: }
1.439 raeburn 7469: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7470: my $match = 0;
1.412 raeburn 7471: my $secmatch = 0;
1.439 raeburn 7472: my $status;
1.412 raeburn 7473: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7474: $user =~ s/:$//;
1.439 raeburn 7475: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7476: if ($end == -1 || $start == -1) {
7477: next;
7478: }
7479: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7480: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7481: my ($uname,$udom) = split(/:/,$user);
7482: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7483: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7484: $secmatch = 1;
7485: } elsif ($usec eq '') {
1.420 albertel 7486: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7487: $secmatch = 1;
7488: }
7489: } else {
7490: if (grep(/^\Q$usec\E$/,@{$sections})) {
7491: $secmatch = 1;
7492: }
7493: }
7494: if (!$secmatch) {
7495: next;
7496: }
1.288 raeburn 7497: }
1.419 raeburn 7498: if ($usec eq '') {
7499: $usec = 'none';
7500: }
1.275 raeburn 7501: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7502: if ($hidepriv) {
7503: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7504: (!$nothide{$uname.':'.$udom})) {
7505: next;
7506: }
7507: }
1.503 raeburn 7508: if ($end > 0 && $end < $now) {
1.439 raeburn 7509: $status = 'previous';
7510: } elsif ($start > $now) {
7511: $status = 'future';
7512: } else {
7513: $status = 'active';
7514: }
1.277 albertel 7515: foreach my $type (keys(%{$types})) {
1.275 raeburn 7516: if ($status eq $type) {
1.420 albertel 7517: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7518: push(@{$$users{$role}{$user}},$type);
7519: }
1.288 raeburn 7520: $match = 1;
7521: }
7522: }
1.419 raeburn 7523: if (($match) && (ref($userdata) eq 'HASH')) {
7524: if (!exists($$userdata{$uname.':'.$udom})) {
7525: &get_user_info($udom,$uname,\%idx,$userdata);
7526: }
1.420 albertel 7527: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7528: push(@{$seclists{$uname.':'.$udom}},$usec);
7529: }
1.609 raeburn 7530: if (ref($statushash) eq 'HASH') {
7531: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7532: }
1.275 raeburn 7533: }
7534: }
7535: }
7536: }
1.290 albertel 7537: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7538: if ((defined($cdom)) && (defined($cnum))) {
7539: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7540: if ( defined($csettings{'internal.courseowner'}) ) {
7541: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7542: next if ($owner eq '');
7543: my ($ownername,$ownerdom);
7544: if ($owner =~ /^([^:]+):([^:]+)$/) {
7545: $ownername = $1;
7546: $ownerdom = $2;
7547: } else {
7548: $ownername = $owner;
7549: $ownerdom = $cdom;
7550: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7551: }
7552: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7553: if (defined($userdata) &&
1.609 raeburn 7554: !exists($$userdata{$owner})) {
7555: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7556: if (!grep(/^none$/,@{$seclists{$owner}})) {
7557: push(@{$seclists{$owner}},'none');
7558: }
7559: if (ref($statushash) eq 'HASH') {
7560: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7561: }
1.290 albertel 7562: }
1.279 raeburn 7563: }
7564: }
7565: }
1.419 raeburn 7566: foreach my $user (keys(%seclists)) {
7567: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7568: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7569: }
1.275 raeburn 7570: }
7571: return;
7572: }
7573:
1.288 raeburn 7574: sub get_user_info {
7575: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7576: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7577: &plainname($uname,$udom,'lastname');
1.291 albertel 7578: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7579: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7580: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7581: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7582: return;
7583: }
1.275 raeburn 7584:
1.472 raeburn 7585: ###############################################
7586:
7587: =pod
7588:
7589: =item * &get_user_quota()
7590:
7591: Retrieves quota assigned for storage of portfolio files for a user
7592:
7593: Incoming parameters:
7594: 1. user's username
7595: 2. user's domain
7596:
7597: Returns:
1.536 raeburn 7598: 1. Disk quota (in Mb) assigned to student.
7599: 2. (Optional) Type of setting: custom or default
7600: (individually assigned or default for user's
7601: institutional status).
7602: 3. (Optional) - User's institutional status (e.g., faculty, staff
7603: or student - types as defined in localenroll::inst_usertypes
7604: for user's domain, which determines default quota for user.
7605: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7606:
7607: If a value has been stored in the user's environment,
1.536 raeburn 7608: it will return that, otherwise it returns the maximal default
7609: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7610:
7611: =cut
7612:
7613: ###############################################
7614:
7615:
7616: sub get_user_quota {
7617: my ($uname,$udom) = @_;
1.536 raeburn 7618: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7619: if (!defined($udom)) {
7620: $udom = $env{'user.domain'};
7621: }
7622: if (!defined($uname)) {
7623: $uname = $env{'user.name'};
7624: }
7625: if (($udom eq '' || $uname eq '') ||
7626: ($udom eq 'public') && ($uname eq 'public')) {
7627: $quota = 0;
1.536 raeburn 7628: $quotatype = 'default';
7629: $defquota = 0;
1.472 raeburn 7630: } else {
1.536 raeburn 7631: my $inststatus;
1.472 raeburn 7632: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7633: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7634: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7635: } else {
1.536 raeburn 7636: my %userenv =
7637: &Apache::lonnet::get('environment',['portfolioquota',
7638: 'inststatus'],$udom,$uname);
1.472 raeburn 7639: my ($tmp) = keys(%userenv);
7640: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7641: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7642: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7643: } else {
7644: undef(%userenv);
7645: }
7646: }
1.536 raeburn 7647: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7648: if ($quota eq '') {
1.536 raeburn 7649: $quota = $defquota;
7650: $quotatype = 'default';
7651: } else {
7652: $quotatype = 'custom';
1.472 raeburn 7653: }
7654: }
1.536 raeburn 7655: if (wantarray) {
7656: return ($quota,$quotatype,$settingstatus,$defquota);
7657: } else {
7658: return $quota;
7659: }
1.472 raeburn 7660: }
7661:
7662: ###############################################
7663:
7664: =pod
7665:
7666: =item * &default_quota()
7667:
1.536 raeburn 7668: Retrieves default quota assigned for storage of user portfolio files,
7669: given an (optional) user's institutional status.
1.472 raeburn 7670:
7671: Incoming parameters:
7672: 1. domain
1.536 raeburn 7673: 2. (Optional) institutional status(es). This is a : separated list of
7674: status types (e.g., faculty, staff, student etc.)
7675: which apply to the user for whom the default is being retrieved.
7676: If the institutional status string in undefined, the domain
7677: default quota will be returned.
1.472 raeburn 7678:
7679: Returns:
7680: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7681: 2. (Optional) institutional type which determined the value of the
7682: default quota.
1.472 raeburn 7683:
7684: If a value has been stored in the domain's configuration db,
7685: it will return that, otherwise it returns 20 (for backwards
7686: compatibility with domains which have not set up a configuration
7687: db file; the original statically defined portfolio quota was 20 Mb).
7688:
1.536 raeburn 7689: If the user's status includes multiple types (e.g., staff and student),
7690: the largest default quota which applies to the user determines the
7691: default quota returned.
7692:
1.780 raeburn 7693: =back
7694:
1.472 raeburn 7695: =cut
7696:
7697: ###############################################
7698:
7699:
7700: sub default_quota {
1.536 raeburn 7701: my ($udom,$inststatus) = @_;
7702: my ($defquota,$settingstatus);
7703: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7704: ['quotas'],$udom);
7705: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7706: if ($inststatus ne '') {
1.765 raeburn 7707: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7708: foreach my $item (@statuses) {
1.711 raeburn 7709: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7710: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7711: if ($defquota eq '') {
7712: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7713: $settingstatus = $item;
7714: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7715: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7716: $settingstatus = $item;
7717: }
7718: }
7719: } else {
7720: if ($quotahash{'quotas'}{$item} ne '') {
7721: if ($defquota eq '') {
7722: $defquota = $quotahash{'quotas'}{$item};
7723: $settingstatus = $item;
7724: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7725: $defquota = $quotahash{'quotas'}{$item};
7726: $settingstatus = $item;
7727: }
1.536 raeburn 7728: }
7729: }
7730: }
7731: }
7732: if ($defquota eq '') {
1.711 raeburn 7733: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7734: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7735: } else {
7736: $defquota = $quotahash{'quotas'}{'default'};
7737: }
1.536 raeburn 7738: $settingstatus = 'default';
7739: }
7740: } else {
7741: $settingstatus = 'default';
7742: $defquota = 20;
7743: }
7744: if (wantarray) {
7745: return ($defquota,$settingstatus);
1.472 raeburn 7746: } else {
1.536 raeburn 7747: return $defquota;
1.472 raeburn 7748: }
7749: }
7750:
1.384 raeburn 7751: sub get_secgrprole_info {
7752: my ($cdom,$cnum,$needroles,$type) = @_;
7753: my %sections_count = &get_sections($cdom,$cnum);
7754: my @sections = (sort {$a <=> $b} keys(%sections_count));
7755: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7756: my @groups = sort(keys(%curr_groups));
7757: my $allroles = [];
7758: my $rolehash;
7759: my $accesshash = {
7760: active => 'Currently has access',
7761: future => 'Will have future access',
7762: previous => 'Previously had access',
7763: };
7764: if ($needroles) {
7765: $rolehash = {'all' => 'all'};
1.385 albertel 7766: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7767: if (&Apache::lonnet::error(%user_roles)) {
7768: undef(%user_roles);
7769: }
7770: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7771: my ($role)=split(/\:/,$item,2);
7772: if ($role eq 'cr') { next; }
7773: if ($role =~ /^cr/) {
7774: $$rolehash{$role} = (split('/',$role))[3];
7775: } else {
7776: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7777: }
7778: }
7779: foreach my $key (sort(keys(%{$rolehash}))) {
7780: push(@{$allroles},$key);
7781: }
7782: push (@{$allroles},'st');
7783: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7784: }
7785: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7786: }
7787:
1.555 raeburn 7788: sub user_picker {
1.627 raeburn 7789: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7790: my $currdom = $dom;
7791: my %curr_selected = (
7792: srchin => 'dom',
1.580 raeburn 7793: srchby => 'lastname',
1.555 raeburn 7794: );
7795: my $srchterm;
1.625 raeburn 7796: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7797: if ($srch->{'srchby'} ne '') {
7798: $curr_selected{'srchby'} = $srch->{'srchby'};
7799: }
7800: if ($srch->{'srchin'} ne '') {
7801: $curr_selected{'srchin'} = $srch->{'srchin'};
7802: }
7803: if ($srch->{'srchtype'} ne '') {
7804: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7805: }
7806: if ($srch->{'srchdomain'} ne '') {
7807: $currdom = $srch->{'srchdomain'};
7808: }
7809: $srchterm = $srch->{'srchterm'};
7810: }
7811: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7812: 'usr' => 'Search criteria',
1.563 raeburn 7813: 'doma' => 'Domain/institution to search',
1.558 albertel 7814: 'uname' => 'username',
7815: 'lastname' => 'last name',
1.555 raeburn 7816: 'lastfirst' => 'last name, first name',
1.558 albertel 7817: 'crs' => 'in this course',
1.576 raeburn 7818: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7819: 'alc' => 'all LON-CAPA',
1.573 raeburn 7820: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7821: 'exact' => 'is',
7822: 'contains' => 'contains',
1.569 raeburn 7823: 'begins' => 'begins with',
1.571 raeburn 7824: 'youm' => "You must include some text to search for.",
7825: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7826: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7827: 'yomc' => "You must choose a domain when using an institutional directory search.",
7828: 'ymcd' => "You must choose a domain when using a domain search.",
7829: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7830: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7831: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7832: );
1.563 raeburn 7833: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7834: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7835:
7836: my @srchins = ('crs','dom','alc','instd');
7837:
7838: foreach my $option (@srchins) {
7839: # FIXME 'alc' option unavailable until
7840: # loncreateuser::print_user_query_page()
7841: # has been completed.
7842: next if ($option eq 'alc');
1.880 raeburn 7843: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7844: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7845: if ($curr_selected{'srchin'} eq $option) {
7846: $srchinsel .= '
7847: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7848: } else {
7849: $srchinsel .= '
7850: <option value="'.$option.'">'.$lt{$option}.'</option>';
7851: }
1.555 raeburn 7852: }
1.563 raeburn 7853: $srchinsel .= "\n </select>\n";
1.555 raeburn 7854:
7855: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7856: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7857: if ($curr_selected{'srchby'} eq $option) {
7858: $srchbysel .= '
7859: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7860: } else {
7861: $srchbysel .= '
7862: <option value="'.$option.'">'.$lt{$option}.'</option>';
7863: }
7864: }
7865: $srchbysel .= "\n </select>\n";
7866:
7867: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7868: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7869: if ($curr_selected{'srchtype'} eq $option) {
7870: $srchtypesel .= '
7871: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7872: } else {
7873: $srchtypesel .= '
7874: <option value="'.$option.'">'.$lt{$option}.'</option>';
7875: }
7876: }
7877: $srchtypesel .= "\n </select>\n";
7878:
1.558 albertel 7879: my ($newuserscript,$new_user_create);
1.556 raeburn 7880:
7881: if ($forcenewuser) {
1.576 raeburn 7882: if (ref($srch) eq 'HASH') {
7883: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7884: if ($cancreate) {
7885: $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>';
7886: } else {
1.799 bisitz 7887: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7888: my %usertypetext = (
7889: official => 'institutional',
7890: unofficial => 'non-institutional',
7891: );
1.799 bisitz 7892: $new_user_create = '<p class="LC_warning">'
7893: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7894: .' '
7895: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7896: ,'<a href="'.$helplink.'">','</a>')
7897: .'</p><br />';
1.627 raeburn 7898: }
1.576 raeburn 7899: }
7900: }
7901:
1.556 raeburn 7902: $newuserscript = <<"ENDSCRIPT";
7903:
1.570 raeburn 7904: function setSearch(createnew,callingForm) {
1.556 raeburn 7905: if (createnew == 1) {
1.570 raeburn 7906: for (var i=0; i<callingForm.srchby.length; i++) {
7907: if (callingForm.srchby.options[i].value == 'uname') {
7908: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7909: }
7910: }
1.570 raeburn 7911: for (var i=0; i<callingForm.srchin.length; i++) {
7912: if ( callingForm.srchin.options[i].value == 'dom') {
7913: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7914: }
7915: }
1.570 raeburn 7916: for (var i=0; i<callingForm.srchtype.length; i++) {
7917: if (callingForm.srchtype.options[i].value == 'exact') {
7918: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7919: }
7920: }
1.570 raeburn 7921: for (var i=0; i<callingForm.srchdomain.length; i++) {
7922: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7923: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7924: }
7925: }
7926: }
7927: }
7928: ENDSCRIPT
1.558 albertel 7929:
1.556 raeburn 7930: }
7931:
1.555 raeburn 7932: my $output = <<"END_BLOCK";
1.556 raeburn 7933: <script type="text/javascript">
1.824 bisitz 7934: // <![CDATA[
1.570 raeburn 7935: function validateEntry(callingForm) {
1.558 albertel 7936:
1.556 raeburn 7937: var checkok = 1;
1.558 albertel 7938: var srchin;
1.570 raeburn 7939: for (var i=0; i<callingForm.srchin.length; i++) {
7940: if ( callingForm.srchin[i].checked ) {
7941: srchin = callingForm.srchin[i].value;
1.558 albertel 7942: }
7943: }
7944:
1.570 raeburn 7945: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7946: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7947: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7948: var srchterm = callingForm.srchterm.value;
7949: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7950: var msg = "";
7951:
7952: if (srchterm == "") {
7953: checkok = 0;
1.571 raeburn 7954: msg += "$lt{'youm'}\\n";
1.556 raeburn 7955: }
7956:
1.569 raeburn 7957: if (srchtype== 'begins') {
7958: if (srchterm.length < 2) {
7959: checkok = 0;
1.571 raeburn 7960: msg += "$lt{'thte'}\\n";
1.569 raeburn 7961: }
7962: }
7963:
1.556 raeburn 7964: if (srchtype== 'contains') {
7965: if (srchterm.length < 3) {
7966: checkok = 0;
1.571 raeburn 7967: msg += "$lt{'thet'}\\n";
1.556 raeburn 7968: }
7969: }
7970: if (srchin == 'instd') {
7971: if (srchdomain == '') {
7972: checkok = 0;
1.571 raeburn 7973: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7974: }
7975: }
7976: if (srchin == 'dom') {
7977: if (srchdomain == '') {
7978: checkok = 0;
1.571 raeburn 7979: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7980: }
7981: }
7982: if (srchby == 'lastfirst') {
7983: if (srchterm.indexOf(",") == -1) {
7984: checkok = 0;
1.571 raeburn 7985: msg += "$lt{'whus'}\\n";
1.556 raeburn 7986: }
7987: if (srchterm.indexOf(",") == srchterm.length -1) {
7988: checkok = 0;
1.571 raeburn 7989: msg += "$lt{'whse'}\\n";
1.556 raeburn 7990: }
7991: }
7992: if (checkok == 0) {
1.571 raeburn 7993: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7994: return;
7995: }
7996: if (checkok == 1) {
1.570 raeburn 7997: callingForm.submit();
1.556 raeburn 7998: }
7999: }
8000:
8001: $newuserscript
8002:
1.824 bisitz 8003: // ]]>
1.556 raeburn 8004: </script>
1.558 albertel 8005:
8006: $new_user_create
8007:
1.555 raeburn 8008: END_BLOCK
1.558 albertel 8009:
1.876 raeburn 8010: $output .= &Apache::lonhtmlcommon::start_pick_box().
8011: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8012: $domform.
8013: &Apache::lonhtmlcommon::row_closure().
8014: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8015: $srchbysel.
8016: $srchtypesel.
8017: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8018: $srchinsel.
8019: &Apache::lonhtmlcommon::row_closure(1).
8020: &Apache::lonhtmlcommon::end_pick_box().
8021: '<br />';
1.555 raeburn 8022: return $output;
8023: }
8024:
1.612 raeburn 8025: sub user_rule_check {
1.615 raeburn 8026: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8027: my $response;
8028: if (ref($usershash) eq 'HASH') {
8029: foreach my $user (keys(%{$usershash})) {
8030: my ($uname,$udom) = split(/:/,$user);
8031: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8032: my ($id,$newuser);
1.612 raeburn 8033: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8034: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8035: $id = $usershash->{$user}->{'id'};
8036: }
8037: my $inst_response;
8038: if (ref($checks) eq 'HASH') {
8039: if (defined($checks->{'username'})) {
1.615 raeburn 8040: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8041: &Apache::lonnet::get_instuser($udom,$uname);
8042: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8043: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8044: &Apache::lonnet::get_instuser($udom,undef,$id);
8045: }
1.615 raeburn 8046: } else {
8047: ($inst_response,%{$inst_results->{$user}}) =
8048: &Apache::lonnet::get_instuser($udom,$uname);
8049: return;
1.612 raeburn 8050: }
1.615 raeburn 8051: if (!$got_rules->{$udom}) {
1.612 raeburn 8052: my %domconfig = &Apache::lonnet::get_dom('configuration',
8053: ['usercreation'],$udom);
8054: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8055: foreach my $item ('username','id') {
1.612 raeburn 8056: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8057: $$curr_rules{$udom}{$item} =
8058: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8059: }
8060: }
8061: }
1.615 raeburn 8062: $got_rules->{$udom} = 1;
1.585 raeburn 8063: }
1.612 raeburn 8064: foreach my $item (keys(%{$checks})) {
8065: if (ref($$curr_rules{$udom}) eq 'HASH') {
8066: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8067: if (@{$$curr_rules{$udom}{$item}} > 0) {
8068: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8069: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8070: if ($rule_check{$rule}) {
8071: $$rulematch{$user}{$item} = $rule;
8072: if ($inst_response eq 'ok') {
1.615 raeburn 8073: if (ref($inst_results) eq 'HASH') {
8074: if (ref($inst_results->{$user}) eq 'HASH') {
8075: if (keys(%{$inst_results->{$user}}) == 0) {
8076: $$alerts{$item}{$udom}{$uname} = 1;
8077: }
1.612 raeburn 8078: }
8079: }
1.615 raeburn 8080: }
8081: last;
1.585 raeburn 8082: }
8083: }
8084: }
8085: }
8086: }
8087: }
8088: }
8089: }
1.612 raeburn 8090: return;
8091: }
8092:
8093: sub user_rule_formats {
8094: my ($domain,$domdesc,$curr_rules,$check) = @_;
8095: my %text = (
8096: 'username' => 'Usernames',
8097: 'id' => 'IDs',
8098: );
8099: my $output;
8100: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8101: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8102: if (@{$ruleorder} > 0) {
8103: $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>';
8104: foreach my $rule (@{$ruleorder}) {
8105: if (ref($curr_rules) eq 'ARRAY') {
8106: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8107: if (ref($rules->{$rule}) eq 'HASH') {
8108: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8109: $rules->{$rule}{'desc'}.'</li>';
8110: }
8111: }
8112: }
8113: }
8114: $output .= '</ul>';
8115: }
8116: }
8117: return $output;
8118: }
8119:
8120: sub instrule_disallow_msg {
1.615 raeburn 8121: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8122: my $response;
8123: my %text = (
8124: item => 'username',
8125: items => 'usernames',
8126: match => 'matches',
8127: do => 'does',
8128: action => 'a username',
8129: one => 'one',
8130: );
8131: if ($count > 1) {
8132: $text{'item'} = 'usernames';
8133: $text{'match'} ='match';
8134: $text{'do'} = 'do';
8135: $text{'action'} = 'usernames',
8136: $text{'one'} = 'ones';
8137: }
8138: if ($checkitem eq 'id') {
8139: $text{'items'} = 'IDs';
8140: $text{'item'} = 'ID';
8141: $text{'action'} = 'an ID';
1.615 raeburn 8142: if ($count > 1) {
8143: $text{'item'} = 'IDs';
8144: $text{'action'} = 'IDs';
8145: }
1.612 raeburn 8146: }
1.674 bisitz 8147: $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 8148: if ($mode eq 'upload') {
8149: if ($checkitem eq 'username') {
8150: $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'}.");
8151: } elsif ($checkitem eq 'id') {
1.674 bisitz 8152: $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 8153: }
1.669 raeburn 8154: } elsif ($mode eq 'selfcreate') {
8155: if ($checkitem eq 'id') {
8156: $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.");
8157: }
1.615 raeburn 8158: } else {
8159: if ($checkitem eq 'username') {
8160: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8161: } elsif ($checkitem eq 'id') {
8162: $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.");
8163: }
1.612 raeburn 8164: }
8165: return $response;
1.585 raeburn 8166: }
8167:
1.624 raeburn 8168: sub personal_data_fieldtitles {
8169: my %fieldtitles = &Apache::lonlocal::texthash (
8170: id => 'Student/Employee ID',
8171: permanentemail => 'E-mail address',
8172: lastname => 'Last Name',
8173: firstname => 'First Name',
8174: middlename => 'Middle Name',
8175: generation => 'Generation',
8176: gen => 'Generation',
1.765 raeburn 8177: inststatus => 'Affiliation',
1.624 raeburn 8178: );
8179: return %fieldtitles;
8180: }
8181:
1.642 raeburn 8182: sub sorted_inst_types {
8183: my ($dom) = @_;
8184: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8185: my $othertitle = &mt('All users');
8186: if ($env{'request.course.id'}) {
1.668 raeburn 8187: $othertitle = &mt('Any users');
1.642 raeburn 8188: }
8189: my @types;
8190: if (ref($order) eq 'ARRAY') {
8191: @types = @{$order};
8192: }
8193: if (@types == 0) {
8194: if (ref($usertypes) eq 'HASH') {
8195: @types = sort(keys(%{$usertypes}));
8196: }
8197: }
8198: if (keys(%{$usertypes}) > 0) {
8199: $othertitle = &mt('Other users');
8200: }
8201: return ($othertitle,$usertypes,\@types);
8202: }
8203:
1.645 raeburn 8204: sub get_institutional_codes {
8205: my ($settings,$allcourses,$LC_code) = @_;
8206: # Get complete list of course sections to update
8207: my @currsections = ();
8208: my @currxlists = ();
8209: my $coursecode = $$settings{'internal.coursecode'};
8210:
8211: if ($$settings{'internal.sectionnums'} ne '') {
8212: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8213: }
8214:
8215: if ($$settings{'internal.crosslistings'} ne '') {
8216: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8217: }
8218:
8219: if (@currxlists > 0) {
8220: foreach (@currxlists) {
8221: if (m/^([^:]+):(\w*)$/) {
8222: unless (grep/^$1$/,@{$allcourses}) {
8223: push @{$allcourses},$1;
8224: $$LC_code{$1} = $2;
8225: }
8226: }
8227: }
8228: }
8229:
8230: if (@currsections > 0) {
8231: foreach (@currsections) {
8232: if (m/^(\w+):(\w*)$/) {
8233: my $sec = $coursecode.$1;
8234: my $lc_sec = $2;
8235: unless (grep/^$sec$/,@{$allcourses}) {
8236: push @{$allcourses},$sec;
8237: $$LC_code{$sec} = $lc_sec;
8238: }
8239: }
8240: }
8241: }
8242: return;
8243: }
8244:
1.948.2.7 raeburn 8245: sub get_standard_codeitems {
8246: return ('Year','Semester','Department','Number','Section');
8247: }
8248:
1.112 bowersj2 8249: =pod
8250:
1.780 raeburn 8251: =head1 Slot Helpers
8252:
8253: =over 4
8254:
8255: =item * sorted_slots()
8256:
8257: Sorts an array of slot names in order of slot start time (earliest first).
8258:
8259: Inputs:
8260:
8261: =over 4
8262:
8263: slotsarr - Reference to array of unsorted slot names.
8264:
8265: slots - Reference to hash of hash, where outer hash keys are slot names.
8266:
1.549 albertel 8267: =back
8268:
1.780 raeburn 8269: Returns:
8270:
8271: =over 4
8272:
8273: sorted - An array of slot names sorted by the start time of the slot.
8274:
8275: =back
8276:
8277: =back
8278:
8279: =cut
8280:
8281:
8282: sub sorted_slots {
8283: my ($slotsarr,$slots) = @_;
8284: my @sorted;
8285: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8286: @sorted =
8287: sort {
8288: if (ref($slots->{$a}) && ref($slots->{$b})) {
8289: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8290: }
8291: if (ref($slots->{$a})) { return -1;}
8292: if (ref($slots->{$b})) { return 1;}
8293: return 0;
8294: } @{$slotsarr};
8295: }
8296: return @sorted;
8297: }
8298:
8299:
8300: =pod
8301:
1.549 albertel 8302: =head1 HTTP Helpers
8303:
8304: =over 4
8305:
1.648 raeburn 8306: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8307:
1.258 albertel 8308: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8309: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8310: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8311:
8312: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8313: $possible_names is an ref to an array of form element names. As an example:
8314: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8315: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8316:
8317: =cut
1.1 albertel 8318:
1.6 albertel 8319: sub get_unprocessed_cgi {
1.25 albertel 8320: my ($query,$possible_names)= @_;
1.26 matthew 8321: # $Apache::lonxml::debug=1;
1.356 albertel 8322: foreach my $pair (split(/&/,$query)) {
8323: my ($name, $value) = split(/=/,$pair);
1.369 www 8324: $name = &unescape($name);
1.25 albertel 8325: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8326: $value =~ tr/+/ /;
8327: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8328: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8329: }
1.16 harris41 8330: }
1.6 albertel 8331: }
8332:
1.112 bowersj2 8333: =pod
8334:
1.648 raeburn 8335: =item * &cacheheader()
1.112 bowersj2 8336:
8337: returns cache-controlling header code
8338:
8339: =cut
8340:
1.7 albertel 8341: sub cacheheader {
1.258 albertel 8342: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8343: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8344: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8345: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8346: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8347: return $output;
1.7 albertel 8348: }
8349:
1.112 bowersj2 8350: =pod
8351:
1.648 raeburn 8352: =item * &no_cache($r)
1.112 bowersj2 8353:
8354: specifies header code to not have cache
8355:
8356: =cut
8357:
1.9 albertel 8358: sub no_cache {
1.216 albertel 8359: my ($r) = @_;
8360: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8361: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8362: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8363: $r->no_cache(1);
8364: $r->header_out("Expires" => $date);
8365: $r->header_out("Pragma" => "no-cache");
1.123 www 8366: }
8367:
8368: sub content_type {
1.181 albertel 8369: my ($r,$type,$charset) = @_;
1.299 foxr 8370: if ($r) {
8371: # Note that printout.pl calls this with undef for $r.
8372: &no_cache($r);
8373: }
1.258 albertel 8374: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8375: unless ($charset) {
8376: $charset=&Apache::lonlocal::current_encoding;
8377: }
8378: if ($charset) { $type.='; charset='.$charset; }
8379: if ($r) {
8380: $r->content_type($type);
8381: } else {
8382: print("Content-type: $type\n\n");
8383: }
1.9 albertel 8384: }
1.25 albertel 8385:
1.112 bowersj2 8386: =pod
8387:
1.648 raeburn 8388: =item * &add_to_env($name,$value)
1.112 bowersj2 8389:
1.258 albertel 8390: adds $name to the %env hash with value
1.112 bowersj2 8391: $value, if $name already exists, the entry is converted to an array
8392: reference and $value is added to the array.
8393:
8394: =cut
8395:
1.25 albertel 8396: sub add_to_env {
8397: my ($name,$value)=@_;
1.258 albertel 8398: if (defined($env{$name})) {
8399: if (ref($env{$name})) {
1.25 albertel 8400: #already have multiple values
1.258 albertel 8401: push(@{ $env{$name} },$value);
1.25 albertel 8402: } else {
8403: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8404: my $first=$env{$name};
8405: undef($env{$name});
8406: push(@{ $env{$name} },$first,$value);
1.25 albertel 8407: }
8408: } else {
1.258 albertel 8409: $env{$name}=$value;
1.25 albertel 8410: }
1.31 albertel 8411: }
1.149 albertel 8412:
8413: =pod
8414:
1.648 raeburn 8415: =item * &get_env_multiple($name)
1.149 albertel 8416:
1.258 albertel 8417: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8418: values may be defined and end up as an array ref.
8419:
8420: returns an array of values
8421:
8422: =cut
8423:
8424: sub get_env_multiple {
8425: my ($name) = @_;
8426: my @values;
1.258 albertel 8427: if (defined($env{$name})) {
1.149 albertel 8428: # exists is it an array
1.258 albertel 8429: if (ref($env{$name})) {
8430: @values=@{ $env{$name} };
1.149 albertel 8431: } else {
1.258 albertel 8432: $values[0]=$env{$name};
1.149 albertel 8433: }
8434: }
8435: return(@values);
8436: }
8437:
1.660 raeburn 8438: sub ask_for_embedded_content {
8439: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8440: my $upload_output = '
8441: <form name="upload_embedded" action="'.$actionurl.'"
8442: method="post" enctype="multipart/form-data">';
8443: $upload_output .= $state;
1.661 raeburn 8444: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8445:
8446: my $num = 0;
8447: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8448: $upload_output .= &start_data_table_row().
8449: '<td>'.$embed_file.'</td><td>';
8450: if ($args->{'ignore_remote_references'}
8451: && $embed_file =~ m{^\w+://}) {
8452: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8453: } elsif ($args->{'error_on_invalid_names'}
8454: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8455:
8456: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8457:
8458: } else {
8459: $upload_output .='
1.661 raeburn 8460: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8461: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8462: my $attrib = join(':',@{$$allfiles{$embed_file}});
8463: $upload_output .=
8464: "\n\t\t".
8465: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8466: $attrib.'" />';
8467: if (exists($$codebase{$embed_file})) {
8468: $upload_output .=
8469: "\n\t\t".
8470: '<input name="codebase_'.$num.'" type="hidden" value="'.
8471: &escape($$codebase{$embed_file}).'" />';
8472: }
8473: }
8474: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8475: $num++;
8476: }
8477: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8478: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8479: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8480: '.&mt('(only files for which a location has been provided will be uploaded)').'
8481: </form>';
8482: return $upload_output;
8483: }
8484:
1.661 raeburn 8485: sub upload_embedded {
8486: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8487: $current_disk_usage) = @_;
8488: my $output;
8489: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8490: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8491: my $orig_uploaded_filename =
8492: $env{'form.embedded_item_'.$i.'.filename'};
8493:
8494: $env{'form.embedded_orig_'.$i} =
8495: &unescape($env{'form.embedded_orig_'.$i});
8496: my ($path,$fname) =
8497: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8498: # no path, whole string is fname
8499: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8500:
8501: $path = $env{'form.currentpath'}.$path;
8502: $fname = &Apache::lonnet::clean_filename($fname);
8503: # See if there is anything left
8504: next if ($fname eq '');
8505:
8506: # Check if file already exists as a file or directory.
8507: my ($state,$msg);
8508: if ($context eq 'portfolio') {
8509: my $port_path = $dirpath;
8510: if ($group ne '') {
8511: $port_path = "groups/$group/$port_path";
8512: }
8513: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8514: $dir_root,$port_path,$disk_quota,
8515: $current_disk_usage,$uname,$udom);
8516: if ($state eq 'will_exceed_quota'
8517: || $state eq 'file_locked'
8518: || $state eq 'file_exists' ) {
8519: $output .= $msg;
8520: next;
8521: }
8522: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8523: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8524: if ($state eq 'exists') {
8525: $output .= $msg;
8526: next;
8527: }
8528: }
8529: # Check if extension is valid
8530: if (($fname =~ /\.(\w+)$/) &&
8531: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8532: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8533: next;
8534: } elsif (($fname =~ /\.(\w+)$/) &&
8535: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8536: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8537: next;
8538: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8539: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8540: next;
8541: }
8542:
8543: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8544: if ($context eq 'portfolio') {
8545: my $result=
8546: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8547: $dirpath.$path);
8548: if ($result !~ m|^/uploaded/|) {
8549: $output .= '<span class="LC_error">'
8550: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8551: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8552: .'</span><br />';
8553: next;
8554: } else {
8555: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8556: $path.$fname.'</span>').'</p>';
8557: }
8558: } else {
8559: # Save the file
8560: my $target = $env{'form.embedded_item_'.$i};
8561: my $fullpath = $dir_root.$dirpath.'/'.$path;
8562: my $dest = $fullpath.$fname;
8563: my $url = $url_root.$dirpath.'/'.$path.$fname;
8564: my @parts=split(/\//,$fullpath);
8565: my $count;
8566: my $filepath = $dir_root;
8567: for ($count=4;$count<=$#parts;$count++) {
8568: $filepath .= "/$parts[$count]";
8569: if ((-e $filepath)!=1) {
8570: mkdir($filepath,0770);
8571: }
8572: }
8573: my $fh;
8574: if (!open($fh,'>'.$dest)) {
8575: &Apache::lonnet::logthis('Failed to create '.$dest);
8576: $output .= '<span class="LC_error">'.
8577: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8578: '</span><br />';
8579: } else {
8580: if (!print $fh $env{'form.embedded_item_'.$i}) {
8581: &Apache::lonnet::logthis('Failed to write to '.$dest);
8582: $output .= '<span class="LC_error">'.
8583: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8584: '</span><br />';
8585: } else {
8586: if ($context eq 'testbank') {
8587: $output .= &mt('Embedded file uploaded successfully:').
8588: ' <a href="'.$url.'">'.
8589: $orig_uploaded_filename.'</a><br />';
8590: } else {
1.705 tempelho 8591: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8592: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8593: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8594: }
8595: }
8596: close($fh);
8597: }
8598: }
8599: }
8600: return $output;
8601: }
8602:
8603: sub check_for_existing {
8604: my ($path,$fname,$element) = @_;
8605: my ($state,$msg);
8606: if (-d $path.'/'.$fname) {
8607: $state = 'exists';
8608: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8609: } elsif (-e $path.'/'.$fname) {
8610: $state = 'exists';
8611: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8612: }
8613: if ($state eq 'exists') {
8614: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8615: }
8616: return ($state,$msg);
8617: }
8618:
8619: sub check_for_upload {
8620: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8621: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8622: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8623: my $getpropath = 1;
8624: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8625: $getpropath);
8626: my $found_file = 0;
8627: my $locked_file = 0;
8628: foreach my $line (@dir_list) {
8629: my ($file_name)=split(/\&/,$line,2);
8630: if ($file_name eq $fname){
8631: $file_name = $path.$file_name;
8632: if ($group ne '') {
8633: $file_name = $group.$file_name;
8634: }
8635: $found_file = 1;
8636: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8637: $locked_file = 1;
8638: }
8639: }
8640: }
8641: if (($current_disk_usage + $filesize) > $disk_quota){
8642: my $msg = '<span class="LC_error">'.
8643: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8644: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8645: return ('will_exceed_quota',$msg);
8646: } elsif ($found_file) {
8647: if ($locked_file) {
8648: my $msg = '<span class="LC_error">';
8649: $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>');
8650: $msg .= '</span><br />';
8651: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8652: return ('file_locked',$msg);
8653: } else {
8654: my $msg = '<span class="LC_error">';
8655: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
8656: $msg .= '</span>';
8657: $msg .= '<br />';
8658: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8659: return ('file_exists',$msg);
8660: }
8661: }
8662: }
8663:
1.31 albertel 8664:
1.41 ng 8665: =pod
1.45 matthew 8666:
1.464 albertel 8667: =back
1.41 ng 8668:
1.112 bowersj2 8669: =head1 CSV Upload/Handling functions
1.38 albertel 8670:
1.41 ng 8671: =over 4
8672:
1.648 raeburn 8673: =item * &upfile_store($r)
1.41 ng 8674:
8675: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8676: needs $env{'form.upfile'}
1.41 ng 8677: returns $datatoken to be put into hidden field
8678:
8679: =cut
1.31 albertel 8680:
8681: sub upfile_store {
8682: my $r=shift;
1.258 albertel 8683: $env{'form.upfile'}=~s/\r/\n/gs;
8684: $env{'form.upfile'}=~s/\f/\n/gs;
8685: $env{'form.upfile'}=~s/\n+/\n/gs;
8686: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8687:
1.258 albertel 8688: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8689: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8690: {
1.158 raeburn 8691: my $datafile = $r->dir_config('lonDaemons').
8692: '/tmp/'.$datatoken.'.tmp';
8693: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8694: print $fh $env{'form.upfile'};
1.158 raeburn 8695: close($fh);
8696: }
1.31 albertel 8697: }
8698: return $datatoken;
8699: }
8700:
1.56 matthew 8701: =pod
8702:
1.648 raeburn 8703: =item * &load_tmp_file($r)
1.41 ng 8704:
8705: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8706: needs $env{'form.datatoken'},
8707: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8708:
8709: =cut
1.31 albertel 8710:
8711: sub load_tmp_file {
8712: my $r=shift;
8713: my @studentdata=();
8714: {
1.158 raeburn 8715: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8716: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8717: if ( open(my $fh,"<$studentfile") ) {
8718: @studentdata=<$fh>;
8719: close($fh);
8720: }
1.31 albertel 8721: }
1.258 albertel 8722: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8723: }
8724:
1.56 matthew 8725: =pod
8726:
1.648 raeburn 8727: =item * &upfile_record_sep()
1.41 ng 8728:
8729: Separate uploaded file into records
8730: returns array of records,
1.258 albertel 8731: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8732:
8733: =cut
1.31 albertel 8734:
8735: sub upfile_record_sep {
1.258 albertel 8736: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8737: } else {
1.248 albertel 8738: my @records;
1.258 albertel 8739: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8740: if ($line=~/^\s*$/) { next; }
8741: push(@records,$line);
8742: }
8743: return @records;
1.31 albertel 8744: }
8745: }
8746:
1.56 matthew 8747: =pod
8748:
1.648 raeburn 8749: =item * &record_sep($record)
1.41 ng 8750:
1.258 albertel 8751: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8752:
8753: =cut
8754:
1.263 www 8755: sub takeleft {
8756: my $index=shift;
8757: return substr('0000'.$index,-4,4);
8758: }
8759:
1.31 albertel 8760: sub record_sep {
8761: my $record=shift;
8762: my %components=();
1.258 albertel 8763: if ($env{'form.upfiletype'} eq 'xml') {
8764: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8765: my $i=0;
1.356 albertel 8766: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8767: $field=~s/^(\"|\')//;
8768: $field=~s/(\"|\')$//;
1.263 www 8769: $components{&takeleft($i)}=$field;
1.31 albertel 8770: $i++;
8771: }
1.258 albertel 8772: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8773: my $i=0;
1.356 albertel 8774: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8775: $field=~s/^(\"|\')//;
8776: $field=~s/(\"|\')$//;
1.263 www 8777: $components{&takeleft($i)}=$field;
1.31 albertel 8778: $i++;
8779: }
8780: } else {
1.561 www 8781: my $separator=',';
1.480 banghart 8782: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8783: $separator=';';
1.480 banghart 8784: }
1.31 albertel 8785: my $i=0;
1.561 www 8786: # the character we are looking for to indicate the end of a quote or a record
8787: my $looking_for=$separator;
8788: # do not add the characters to the fields
8789: my $ignore=0;
8790: # we just encountered a separator (or the beginning of the record)
8791: my $just_found_separator=1;
8792: # store the field we are working on here
8793: my $field='';
8794: # work our way through all characters in record
8795: foreach my $character ($record=~/(.)/g) {
8796: if ($character eq $looking_for) {
8797: if ($character ne $separator) {
8798: # Found the end of a quote, again looking for separator
8799: $looking_for=$separator;
8800: $ignore=1;
8801: } else {
8802: # Found a separator, store away what we got
8803: $components{&takeleft($i)}=$field;
8804: $i++;
8805: $just_found_separator=1;
8806: $ignore=0;
8807: $field='';
8808: }
8809: next;
8810: }
8811: # single or double quotation marks after a separator indicate beginning of a quote
8812: # we are now looking for the end of the quote and need to ignore separators
8813: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8814: $looking_for=$character;
8815: next;
8816: }
8817: # ignore would be true after we reached the end of a quote
8818: if ($ignore) { next; }
8819: if (($just_found_separator) && ($character=~/\s/)) { next; }
8820: $field.=$character;
8821: $just_found_separator=0;
1.31 albertel 8822: }
1.561 www 8823: # catch the very last entry, since we never encountered the separator
8824: $components{&takeleft($i)}=$field;
1.31 albertel 8825: }
8826: return %components;
8827: }
8828:
1.144 matthew 8829: ######################################################
8830: ######################################################
8831:
1.56 matthew 8832: =pod
8833:
1.648 raeburn 8834: =item * &upfile_select_html()
1.41 ng 8835:
1.144 matthew 8836: Return HTML code to select a file from the users machine and specify
8837: the file type.
1.41 ng 8838:
8839: =cut
8840:
1.144 matthew 8841: ######################################################
8842: ######################################################
1.31 albertel 8843: sub upfile_select_html {
1.144 matthew 8844: my %Types = (
8845: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8846: semisv => &mt('Semicolon separated values'),
1.144 matthew 8847: space => &mt('Space separated'),
8848: tab => &mt('Tabulator separated'),
8849: # xml => &mt('HTML/XML'),
8850: );
8851: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8852: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8853: foreach my $type (sort(keys(%Types))) {
8854: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8855: }
8856: $Str .= "</select>\n";
8857: return $Str;
1.31 albertel 8858: }
8859:
1.301 albertel 8860: sub get_samples {
8861: my ($records,$toget) = @_;
8862: my @samples=({});
8863: my $got=0;
8864: foreach my $rec (@$records) {
8865: my %temp = &record_sep($rec);
8866: if (! grep(/\S/, values(%temp))) { next; }
8867: if (%temp) {
8868: $samples[$got]=\%temp;
8869: $got++;
8870: if ($got == $toget) { last; }
8871: }
8872: }
8873: return \@samples;
8874: }
8875:
1.144 matthew 8876: ######################################################
8877: ######################################################
8878:
1.56 matthew 8879: =pod
8880:
1.648 raeburn 8881: =item * &csv_print_samples($r,$records)
1.41 ng 8882:
8883: Prints a table of sample values from each column uploaded $r is an
8884: Apache Request ref, $records is an arrayref from
8885: &Apache::loncommon::upfile_record_sep
8886:
8887: =cut
8888:
1.144 matthew 8889: ######################################################
8890: ######################################################
1.31 albertel 8891: sub csv_print_samples {
8892: my ($r,$records) = @_;
1.662 bisitz 8893: my $samples = &get_samples($records,5);
1.301 albertel 8894:
1.594 raeburn 8895: $r->print(&mt('Samples').'<br />'.&start_data_table().
8896: &start_data_table_header_row());
1.356 albertel 8897: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8898: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8899: $r->print(&end_data_table_header_row());
1.301 albertel 8900: foreach my $hash (@$samples) {
1.594 raeburn 8901: $r->print(&start_data_table_row());
1.356 albertel 8902: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8903: $r->print('<td>');
1.356 albertel 8904: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8905: $r->print('</td>');
8906: }
1.594 raeburn 8907: $r->print(&end_data_table_row());
1.31 albertel 8908: }
1.594 raeburn 8909: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8910: }
8911:
1.144 matthew 8912: ######################################################
8913: ######################################################
8914:
1.56 matthew 8915: =pod
8916:
1.648 raeburn 8917: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8918:
8919: Prints a table to create associations between values and table columns.
1.144 matthew 8920:
1.41 ng 8921: $r is an Apache Request ref,
8922: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8923: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8924:
8925: =cut
8926:
1.144 matthew 8927: ######################################################
8928: ######################################################
1.31 albertel 8929: sub csv_print_select_table {
8930: my ($r,$records,$d) = @_;
1.301 albertel 8931: my $i=0;
8932: my $samples = &get_samples($records,1);
1.144 matthew 8933: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8934: &start_data_table().&start_data_table_header_row().
1.144 matthew 8935: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8936: '<th>'.&mt('Column').'</th>'.
8937: &end_data_table_header_row()."\n");
1.356 albertel 8938: foreach my $array_ref (@$d) {
8939: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8940: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8941:
1.875 bisitz 8942: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8943: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8944: $r->print('<option value="none"></option>');
1.356 albertel 8945: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8946: $r->print('<option value="'.$sample.'"'.
8947: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8948: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8949: }
1.594 raeburn 8950: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8951: $i++;
8952: }
1.594 raeburn 8953: $r->print(&end_data_table());
1.31 albertel 8954: $i--;
8955: return $i;
8956: }
1.56 matthew 8957:
1.144 matthew 8958: ######################################################
8959: ######################################################
8960:
1.56 matthew 8961: =pod
1.31 albertel 8962:
1.648 raeburn 8963: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8964:
8965: Prints a table of sample values from the upload and can make associate samples to internal names.
8966:
8967: $r is an Apache Request ref,
8968: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8969: $d is an array of 2 element arrays (internal name, displayed name)
8970:
8971: =cut
8972:
1.144 matthew 8973: ######################################################
8974: ######################################################
1.31 albertel 8975: sub csv_samples_select_table {
8976: my ($r,$records,$d) = @_;
8977: my $i=0;
1.144 matthew 8978: #
1.662 bisitz 8979: my $max_samples = 5;
8980: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8981: $r->print(&start_data_table().
8982: &start_data_table_header_row().'<th>'.
8983: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8984: &end_data_table_header_row());
1.301 albertel 8985:
8986: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8987: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8988: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8989: foreach my $option (@$d) {
8990: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8991: $r->print('<option value="'.$value.'"'.
1.253 albertel 8992: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8993: $display.'</option>');
1.31 albertel 8994: }
8995: $r->print('</select></td><td>');
1.662 bisitz 8996: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8997: if (defined($samples->[$line]{$key})) {
8998: $r->print($samples->[$line]{$key}."<br />\n");
8999: }
9000: }
1.594 raeburn 9001: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9002: $i++;
9003: }
1.594 raeburn 9004: $r->print(&end_data_table());
1.31 albertel 9005: $i--;
9006: return($i);
1.115 matthew 9007: }
9008:
1.144 matthew 9009: ######################################################
9010: ######################################################
9011:
1.115 matthew 9012: =pod
9013:
1.648 raeburn 9014: =item * &clean_excel_name($name)
1.115 matthew 9015:
9016: Returns a replacement for $name which does not contain any illegal characters.
9017:
9018: =cut
9019:
1.144 matthew 9020: ######################################################
9021: ######################################################
1.115 matthew 9022: sub clean_excel_name {
9023: my ($name) = @_;
9024: $name =~ s/[:\*\?\/\\]//g;
9025: if (length($name) > 31) {
9026: $name = substr($name,0,31);
9027: }
9028: return $name;
1.25 albertel 9029: }
1.84 albertel 9030:
1.85 albertel 9031: =pod
9032:
1.648 raeburn 9033: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9034:
9035: Returns either 1 or undef
9036:
9037: 1 if the part is to be hidden, undef if it is to be shown
9038:
9039: Arguments are:
9040:
9041: $id the id of the part to be checked
9042: $symb, optional the symb of the resource to check
9043: $udom, optional the domain of the user to check for
9044: $uname, optional the username of the user to check for
9045:
9046: =cut
1.84 albertel 9047:
9048: sub check_if_partid_hidden {
9049: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9050: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9051: $symb,$udom,$uname);
1.141 albertel 9052: my $truth=1;
9053: #if the string starts with !, then the list is the list to show not hide
9054: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9055: my @hiddenlist=split(/,/,$hiddenparts);
9056: foreach my $checkid (@hiddenlist) {
1.141 albertel 9057: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9058: }
1.141 albertel 9059: return !$truth;
1.84 albertel 9060: }
1.127 matthew 9061:
1.138 matthew 9062:
9063: ############################################################
9064: ############################################################
9065:
9066: =pod
9067:
1.157 matthew 9068: =back
9069:
1.138 matthew 9070: =head1 cgi-bin script and graphing routines
9071:
1.157 matthew 9072: =over 4
9073:
1.648 raeburn 9074: =item * &get_cgi_id()
1.138 matthew 9075:
9076: Inputs: none
9077:
9078: Returns an id which can be used to pass environment variables
9079: to various cgi-bin scripts. These environment variables will
9080: be removed from the users environment after a given time by
9081: the routine &Apache::lonnet::transfer_profile_to_env.
9082:
9083: =cut
9084:
9085: ############################################################
9086: ############################################################
1.152 albertel 9087: my $uniq=0;
1.136 matthew 9088: sub get_cgi_id {
1.154 albertel 9089: $uniq=($uniq+1)%100000;
1.280 albertel 9090: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9091: }
9092:
1.127 matthew 9093: ############################################################
9094: ############################################################
9095:
9096: =pod
9097:
1.648 raeburn 9098: =item * &DrawBarGraph()
1.127 matthew 9099:
1.138 matthew 9100: Facilitates the plotting of data in a (stacked) bar graph.
9101: Puts plot definition data into the users environment in order for
9102: graph.png to plot it. Returns an <img> tag for the plot.
9103: The bars on the plot are labeled '1','2',...,'n'.
9104:
9105: Inputs:
9106:
9107: =over 4
9108:
9109: =item $Title: string, the title of the plot
9110:
9111: =item $xlabel: string, text describing the X-axis of the plot
9112:
9113: =item $ylabel: string, text describing the Y-axis of the plot
9114:
9115: =item $Max: scalar, the maximum Y value to use in the plot
9116: If $Max is < any data point, the graph will not be rendered.
9117:
1.140 matthew 9118: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9119: they are plotted. If undefined, default values will be used.
9120:
1.178 matthew 9121: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9122:
1.138 matthew 9123: =item @Values: An array of array references. Each array reference holds data
9124: to be plotted in a stacked bar chart.
9125:
1.239 matthew 9126: =item If the final element of @Values is a hash reference the key/value
9127: pairs will be added to the graph definition.
9128:
1.138 matthew 9129: =back
9130:
9131: Returns:
9132:
9133: An <img> tag which references graph.png and the appropriate identifying
9134: information for the plot.
9135:
1.127 matthew 9136: =cut
9137:
9138: ############################################################
9139: ############################################################
1.134 matthew 9140: sub DrawBarGraph {
1.178 matthew 9141: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9142: #
9143: if (! defined($colors)) {
9144: $colors = ['#33ff00',
9145: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9146: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9147: ];
9148: }
1.228 matthew 9149: my $extra_settings = {};
9150: if (ref($Values[-1]) eq 'HASH') {
9151: $extra_settings = pop(@Values);
9152: }
1.127 matthew 9153: #
1.136 matthew 9154: my $identifier = &get_cgi_id();
9155: my $id = 'cgi.'.$identifier;
1.129 matthew 9156: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9157: return '';
9158: }
1.225 matthew 9159: #
9160: my @Labels;
9161: if (defined($labels)) {
9162: @Labels = @$labels;
9163: } else {
9164: for (my $i=0;$i<@{$Values[0]};$i++) {
9165: push (@Labels,$i+1);
9166: }
9167: }
9168: #
1.129 matthew 9169: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9170: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9171: my %ValuesHash;
9172: my $NumSets=1;
9173: foreach my $array (@Values) {
9174: next if (! ref($array));
1.136 matthew 9175: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9176: join(',',@$array);
1.129 matthew 9177: }
1.127 matthew 9178: #
1.136 matthew 9179: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9180: if ($NumBars < 3) {
9181: $width = 120+$NumBars*32;
1.220 matthew 9182: $xskip = 1;
1.225 matthew 9183: $bar_width = 30;
9184: } elsif ($NumBars < 5) {
9185: $width = 120+$NumBars*20;
9186: $xskip = 1;
9187: $bar_width = 20;
1.220 matthew 9188: } elsif ($NumBars < 10) {
1.136 matthew 9189: $width = 120+$NumBars*15;
9190: $xskip = 1;
9191: $bar_width = 15;
9192: } elsif ($NumBars <= 25) {
9193: $width = 120+$NumBars*11;
9194: $xskip = 5;
9195: $bar_width = 8;
9196: } elsif ($NumBars <= 50) {
9197: $width = 120+$NumBars*8;
9198: $xskip = 5;
9199: $bar_width = 4;
9200: } else {
9201: $width = 120+$NumBars*8;
9202: $xskip = 5;
9203: $bar_width = 4;
9204: }
9205: #
1.137 matthew 9206: $Max = 1 if ($Max < 1);
9207: if ( int($Max) < $Max ) {
9208: $Max++;
9209: $Max = int($Max);
9210: }
1.127 matthew 9211: $Title = '' if (! defined($Title));
9212: $xlabel = '' if (! defined($xlabel));
9213: $ylabel = '' if (! defined($ylabel));
1.369 www 9214: $ValuesHash{$id.'.title'} = &escape($Title);
9215: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9216: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9217: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9218: $ValuesHash{$id.'.NumBars'} = $NumBars;
9219: $ValuesHash{$id.'.NumSets'} = $NumSets;
9220: $ValuesHash{$id.'.PlotType'} = 'bar';
9221: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9222: $ValuesHash{$id.'.height'} = $height;
9223: $ValuesHash{$id.'.width'} = $width;
9224: $ValuesHash{$id.'.xskip'} = $xskip;
9225: $ValuesHash{$id.'.bar_width'} = $bar_width;
9226: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9227: #
1.228 matthew 9228: # Deal with other parameters
9229: while (my ($key,$value) = each(%$extra_settings)) {
9230: $ValuesHash{$id.'.'.$key} = $value;
9231: }
9232: #
1.646 raeburn 9233: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9234: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9235: }
9236:
9237: ############################################################
9238: ############################################################
9239:
9240: =pod
9241:
1.648 raeburn 9242: =item * &DrawXYGraph()
1.137 matthew 9243:
1.138 matthew 9244: Facilitates the plotting of data in an XY graph.
9245: Puts plot definition data into the users environment in order for
9246: graph.png to plot it. Returns an <img> tag for the plot.
9247:
9248: Inputs:
9249:
9250: =over 4
9251:
9252: =item $Title: string, the title of the plot
9253:
9254: =item $xlabel: string, text describing the X-axis of the plot
9255:
9256: =item $ylabel: string, text describing the Y-axis of the plot
9257:
9258: =item $Max: scalar, the maximum Y value to use in the plot
9259: If $Max is < any data point, the graph will not be rendered.
9260:
9261: =item $colors: Array ref containing the hex color codes for the data to be
9262: plotted in. If undefined, default values will be used.
9263:
9264: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9265:
9266: =item $Ydata: Array ref containing Array refs.
1.185 www 9267: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9268:
9269: =item %Values: hash indicating or overriding any default values which are
9270: passed to graph.png.
9271: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9272:
9273: =back
9274:
9275: Returns:
9276:
9277: An <img> tag which references graph.png and the appropriate identifying
9278: information for the plot.
9279:
1.137 matthew 9280: =cut
9281:
9282: ############################################################
9283: ############################################################
9284: sub DrawXYGraph {
9285: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9286: #
9287: # Create the identifier for the graph
9288: my $identifier = &get_cgi_id();
9289: my $id = 'cgi.'.$identifier;
9290: #
9291: $Title = '' if (! defined($Title));
9292: $xlabel = '' if (! defined($xlabel));
9293: $ylabel = '' if (! defined($ylabel));
9294: my %ValuesHash =
9295: (
1.369 www 9296: $id.'.title' => &escape($Title),
9297: $id.'.xlabel' => &escape($xlabel),
9298: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9299: $id.'.y_max_value'=> $Max,
9300: $id.'.labels' => join(',',@$Xlabels),
9301: $id.'.PlotType' => 'XY',
9302: );
9303: #
9304: if (defined($colors) && ref($colors) eq 'ARRAY') {
9305: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9306: }
9307: #
9308: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9309: return '';
9310: }
9311: my $NumSets=1;
1.138 matthew 9312: foreach my $array (@{$Ydata}){
1.137 matthew 9313: next if (! ref($array));
9314: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9315: }
1.138 matthew 9316: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9317: #
9318: # Deal with other parameters
9319: while (my ($key,$value) = each(%Values)) {
9320: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9321: }
9322: #
1.646 raeburn 9323: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9324: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9325: }
9326:
9327: ############################################################
9328: ############################################################
9329:
9330: =pod
9331:
1.648 raeburn 9332: =item * &DrawXYYGraph()
1.138 matthew 9333:
9334: Facilitates the plotting of data in an XY graph with two Y axes.
9335: Puts plot definition data into the users environment in order for
9336: graph.png to plot it. Returns an <img> tag for the plot.
9337:
9338: Inputs:
9339:
9340: =over 4
9341:
9342: =item $Title: string, the title of the plot
9343:
9344: =item $xlabel: string, text describing the X-axis of the plot
9345:
9346: =item $ylabel: string, text describing the Y-axis of the plot
9347:
9348: =item $colors: Array ref containing the hex color codes for the data to be
9349: plotted in. If undefined, default values will be used.
9350:
9351: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9352:
9353: =item $Ydata1: The first data set
9354:
9355: =item $Min1: The minimum value of the left Y-axis
9356:
9357: =item $Max1: The maximum value of the left Y-axis
9358:
9359: =item $Ydata2: The second data set
9360:
9361: =item $Min2: The minimum value of the right Y-axis
9362:
9363: =item $Max2: The maximum value of the left Y-axis
9364:
9365: =item %Values: hash indicating or overriding any default values which are
9366: passed to graph.png.
9367: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9368:
9369: =back
9370:
9371: Returns:
9372:
9373: An <img> tag which references graph.png and the appropriate identifying
9374: information for the plot.
1.136 matthew 9375:
9376: =cut
9377:
9378: ############################################################
9379: ############################################################
1.137 matthew 9380: sub DrawXYYGraph {
9381: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9382: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9383: #
9384: # Create the identifier for the graph
9385: my $identifier = &get_cgi_id();
9386: my $id = 'cgi.'.$identifier;
9387: #
9388: $Title = '' if (! defined($Title));
9389: $xlabel = '' if (! defined($xlabel));
9390: $ylabel = '' if (! defined($ylabel));
9391: my %ValuesHash =
9392: (
1.369 www 9393: $id.'.title' => &escape($Title),
9394: $id.'.xlabel' => &escape($xlabel),
9395: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9396: $id.'.labels' => join(',',@$Xlabels),
9397: $id.'.PlotType' => 'XY',
9398: $id.'.NumSets' => 2,
1.137 matthew 9399: $id.'.two_axes' => 1,
9400: $id.'.y1_max_value' => $Max1,
9401: $id.'.y1_min_value' => $Min1,
9402: $id.'.y2_max_value' => $Max2,
9403: $id.'.y2_min_value' => $Min2,
1.136 matthew 9404: );
9405: #
1.137 matthew 9406: if (defined($colors) && ref($colors) eq 'ARRAY') {
9407: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9408: }
9409: #
9410: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9411: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9412: return '';
9413: }
9414: my $NumSets=1;
1.137 matthew 9415: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9416: next if (! ref($array));
9417: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9418: }
9419: #
9420: # Deal with other parameters
9421: while (my ($key,$value) = each(%Values)) {
9422: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9423: }
9424: #
1.646 raeburn 9425: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9426: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9427: }
9428:
9429: ############################################################
9430: ############################################################
9431:
9432: =pod
9433:
1.157 matthew 9434: =back
9435:
1.139 matthew 9436: =head1 Statistics helper routines?
9437:
9438: Bad place for them but what the hell.
9439:
1.157 matthew 9440: =over 4
9441:
1.648 raeburn 9442: =item * &chartlink()
1.139 matthew 9443:
9444: Returns a link to the chart for a specific student.
9445:
9446: Inputs:
9447:
9448: =over 4
9449:
9450: =item $linktext: The text of the link
9451:
9452: =item $sname: The students username
9453:
9454: =item $sdomain: The students domain
9455:
9456: =back
9457:
1.157 matthew 9458: =back
9459:
1.139 matthew 9460: =cut
9461:
9462: ############################################################
9463: ############################################################
9464: sub chartlink {
9465: my ($linktext, $sname, $sdomain) = @_;
9466: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9467: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9468: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9469: '">'.$linktext.'</a>';
1.153 matthew 9470: }
9471:
9472: #######################################################
9473: #######################################################
9474:
9475: =pod
9476:
9477: =head1 Course Environment Routines
1.157 matthew 9478:
9479: =over 4
1.153 matthew 9480:
1.648 raeburn 9481: =item * &restore_course_settings()
1.153 matthew 9482:
1.648 raeburn 9483: =item * &store_course_settings()
1.153 matthew 9484:
9485: Restores/Store indicated form parameters from the course environment.
9486: Will not overwrite existing values of the form parameters.
9487:
9488: Inputs:
9489: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9490:
9491: a hash ref describing the data to be stored. For example:
9492:
9493: %Save_Parameters = ('Status' => 'scalar',
9494: 'chartoutputmode' => 'scalar',
9495: 'chartoutputdata' => 'scalar',
9496: 'Section' => 'array',
1.373 raeburn 9497: 'Group' => 'array',
1.153 matthew 9498: 'StudentData' => 'array',
9499: 'Maps' => 'array');
9500:
9501: Returns: both routines return nothing
9502:
1.631 raeburn 9503: =back
9504:
1.153 matthew 9505: =cut
9506:
9507: #######################################################
9508: #######################################################
9509: sub store_course_settings {
1.496 albertel 9510: return &store_settings($env{'request.course.id'},@_);
9511: }
9512:
9513: sub store_settings {
1.153 matthew 9514: # save to the environment
9515: # appenv the same items, just to be safe
1.300 albertel 9516: my $udom = $env{'user.domain'};
9517: my $uname = $env{'user.name'};
1.496 albertel 9518: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9519: my %SaveHash;
9520: my %AppHash;
9521: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9522: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9523: my $envname = 'environment.'.$basename;
1.258 albertel 9524: if (exists($env{'form.'.$setting})) {
1.153 matthew 9525: # Save this value away
9526: if ($type eq 'scalar' &&
1.258 albertel 9527: (! exists($env{$envname}) ||
9528: $env{$envname} ne $env{'form.'.$setting})) {
9529: $SaveHash{$basename} = $env{'form.'.$setting};
9530: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9531: } elsif ($type eq 'array') {
9532: my $stored_form;
1.258 albertel 9533: if (ref($env{'form.'.$setting})) {
1.153 matthew 9534: $stored_form = join(',',
9535: map {
1.369 www 9536: &escape($_);
1.258 albertel 9537: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9538: } else {
9539: $stored_form =
1.369 www 9540: &escape($env{'form.'.$setting});
1.153 matthew 9541: }
9542: # Determine if the array contents are the same.
1.258 albertel 9543: if ($stored_form ne $env{$envname}) {
1.153 matthew 9544: $SaveHash{$basename} = $stored_form;
9545: $AppHash{$envname} = $stored_form;
9546: }
9547: }
9548: }
9549: }
9550: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9551: $udom,$uname);
1.153 matthew 9552: if ($put_result !~ /^(ok|delayed)/) {
9553: &Apache::lonnet::logthis('unable to save form parameters, '.
9554: 'got error:'.$put_result);
9555: }
9556: # Make sure these settings stick around in this session, too
1.646 raeburn 9557: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9558: return;
9559: }
9560:
9561: sub restore_course_settings {
1.499 albertel 9562: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9563: }
9564:
9565: sub restore_settings {
9566: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9567: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9568: next if (exists($env{'form.'.$setting}));
1.496 albertel 9569: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9570: '.'.$setting;
1.258 albertel 9571: if (exists($env{$envname})) {
1.153 matthew 9572: if ($type eq 'scalar') {
1.258 albertel 9573: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9574: } elsif ($type eq 'array') {
1.258 albertel 9575: $env{'form.'.$setting} = [
1.153 matthew 9576: map {
1.369 www 9577: &unescape($_);
1.258 albertel 9578: } split(',',$env{$envname})
1.153 matthew 9579: ];
9580: }
9581: }
9582: }
1.127 matthew 9583: }
9584:
1.618 raeburn 9585: #######################################################
9586: #######################################################
9587:
9588: =pod
9589:
9590: =head1 Domain E-mail Routines
9591:
9592: =over 4
9593:
1.648 raeburn 9594: =item * &build_recipient_list()
1.618 raeburn 9595:
1.884 raeburn 9596: Build recipient lists for five types of e-mail:
1.766 raeburn 9597: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9598: (d) Help requests, (e) Course requests needing approval, generated by
9599: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9600: loncoursequeueadmin.pm respectively.
1.618 raeburn 9601:
9602: Inputs:
1.619 raeburn 9603: defmail (scalar - email address of default recipient),
1.618 raeburn 9604: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9605: defdom (domain for which to retrieve configuration settings),
9606: origmail (scalar - email address of recipient from loncapa.conf,
9607: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9608:
1.655 raeburn 9609: Returns: comma separated list of addresses to which to send e-mail.
9610:
9611: =back
1.618 raeburn 9612:
9613: =cut
9614:
9615: ############################################################
9616: ############################################################
9617: sub build_recipient_list {
1.619 raeburn 9618: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9619: my @recipients;
9620: my $otheremails;
9621: my %domconfig =
9622: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9623: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9624: if (exists($domconfig{'contacts'}{$mailing})) {
9625: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9626: my @contacts = ('adminemail','supportemail');
9627: foreach my $item (@contacts) {
9628: if ($domconfig{'contacts'}{$mailing}{$item}) {
9629: my $addr = $domconfig{'contacts'}{$item};
9630: if (!grep(/^\Q$addr\E$/,@recipients)) {
9631: push(@recipients,$addr);
9632: }
1.619 raeburn 9633: }
1.766 raeburn 9634: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9635: }
9636: }
1.766 raeburn 9637: } elsif ($origmail ne '') {
9638: push(@recipients,$origmail);
1.618 raeburn 9639: }
1.619 raeburn 9640: } elsif ($origmail ne '') {
9641: push(@recipients,$origmail);
1.618 raeburn 9642: }
1.688 raeburn 9643: if (defined($defmail)) {
9644: if ($defmail ne '') {
9645: push(@recipients,$defmail);
9646: }
1.618 raeburn 9647: }
9648: if ($otheremails) {
1.619 raeburn 9649: my @others;
9650: if ($otheremails =~ /,/) {
9651: @others = split(/,/,$otheremails);
1.618 raeburn 9652: } else {
1.619 raeburn 9653: push(@others,$otheremails);
9654: }
9655: foreach my $addr (@others) {
9656: if (!grep(/^\Q$addr\E$/,@recipients)) {
9657: push(@recipients,$addr);
9658: }
1.618 raeburn 9659: }
9660: }
1.619 raeburn 9661: my $recipientlist = join(',',@recipients);
1.618 raeburn 9662: return $recipientlist;
9663: }
9664:
1.127 matthew 9665: ############################################################
9666: ############################################################
1.154 albertel 9667:
1.655 raeburn 9668: =pod
9669:
9670: =head1 Course Catalog Routines
9671:
9672: =over 4
9673:
9674: =item * &gather_categories()
9675:
9676: Converts category definitions - keys of categories hash stored in
9677: coursecategories in configuration.db on the primary library server in a
9678: domain - to an array. Also generates javascript and idx hash used to
9679: generate Domain Coordinator interface for editing Course Categories.
9680:
9681: Inputs:
1.663 raeburn 9682:
1.655 raeburn 9683: categories (reference to hash of category definitions).
1.663 raeburn 9684:
1.655 raeburn 9685: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9686: categories and subcategories).
1.663 raeburn 9687:
1.655 raeburn 9688: idx (reference to hash of counters used in Domain Coordinator interface for
9689: editing Course Categories).
1.663 raeburn 9690:
1.655 raeburn 9691: jsarray (reference to array of categories used to create Javascript arrays for
9692: Domain Coordinator interface for editing Course Categories).
9693:
9694: Returns: nothing
9695:
9696: Side effects: populates cats, idx and jsarray.
9697:
9698: =cut
9699:
9700: sub gather_categories {
9701: my ($categories,$cats,$idx,$jsarray) = @_;
9702: my %counters;
9703: my $num = 0;
9704: foreach my $item (keys(%{$categories})) {
9705: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9706: if ($container eq '' && $depth == 0) {
9707: $cats->[$depth][$categories->{$item}] = $cat;
9708: } else {
9709: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9710: }
9711: my ($escitem,$tail) = split(/:/,$item,2);
9712: if ($counters{$tail} eq '') {
9713: $counters{$tail} = $num;
9714: $num ++;
9715: }
9716: if (ref($idx) eq 'HASH') {
9717: $idx->{$item} = $counters{$tail};
9718: }
9719: if (ref($jsarray) eq 'ARRAY') {
9720: push(@{$jsarray->[$counters{$tail}]},$item);
9721: }
9722: }
9723: return;
9724: }
9725:
9726: =pod
9727:
9728: =item * &extract_categories()
9729:
9730: Used to generate breadcrumb trails for course categories.
9731:
9732: Inputs:
1.663 raeburn 9733:
1.655 raeburn 9734: categories (reference to hash of category definitions).
1.663 raeburn 9735:
1.655 raeburn 9736: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9737: categories and subcategories).
1.663 raeburn 9738:
1.655 raeburn 9739: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9740:
1.655 raeburn 9741: allitems (reference to hash - key is category key
9742: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9743:
1.655 raeburn 9744: idx (reference to hash of counters used in Domain Coordinator interface for
9745: editing Course Categories).
1.663 raeburn 9746:
1.655 raeburn 9747: jsarray (reference to array of categories used to create Javascript arrays for
9748: Domain Coordinator interface for editing Course Categories).
9749:
1.665 raeburn 9750: subcats (reference to hash of arrays containing all subcategories within each
9751: category, -recursive)
9752:
1.655 raeburn 9753: Returns: nothing
9754:
9755: Side effects: populates trails and allitems hash references.
9756:
9757: =cut
9758:
9759: sub extract_categories {
1.665 raeburn 9760: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9761: if (ref($categories) eq 'HASH') {
9762: &gather_categories($categories,$cats,$idx,$jsarray);
9763: if (ref($cats->[0]) eq 'ARRAY') {
9764: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9765: my $name = $cats->[0][$i];
9766: my $item = &escape($name).'::0';
9767: my $trailstr;
9768: if ($name eq 'instcode') {
9769: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 9770: } elsif ($name eq 'communities') {
9771: $trailstr = &mt('Communities');
1.655 raeburn 9772: } else {
9773: $trailstr = $name;
9774: }
9775: if ($allitems->{$item} eq '') {
9776: push(@{$trails},$trailstr);
9777: $allitems->{$item} = scalar(@{$trails})-1;
9778: }
9779: my @parents = ($name);
9780: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9781: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9782: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9783: if (ref($subcats) eq 'HASH') {
9784: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9785: }
9786: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9787: }
9788: } else {
9789: if (ref($subcats) eq 'HASH') {
9790: $subcats->{$item} = [];
1.655 raeburn 9791: }
9792: }
9793: }
9794: }
9795: }
9796: return;
9797: }
9798:
9799: =pod
9800:
9801: =item *&recurse_categories()
9802:
9803: Recursively used to generate breadcrumb trails for course categories.
9804:
9805: Inputs:
1.663 raeburn 9806:
1.655 raeburn 9807: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9808: categories and subcategories).
1.663 raeburn 9809:
1.655 raeburn 9810: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9811:
9812: category (current course category, for which breadcrumb trail is being generated).
9813:
9814: trails (reference to array of breadcrumb trails for each category).
9815:
1.655 raeburn 9816: allitems (reference to hash - key is category key
9817: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9818:
1.655 raeburn 9819: parents (array containing containers directories for current category,
9820: back to top level).
9821:
9822: Returns: nothing
9823:
9824: Side effects: populates trails and allitems hash references
9825:
9826: =cut
9827:
9828: sub recurse_categories {
1.665 raeburn 9829: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9830: my $shallower = $depth - 1;
9831: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9832: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9833: my $name = $cats->[$depth]{$category}[$k];
9834: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9835: my $trailstr = join(' -> ',(@{$parents},$category));
9836: if ($allitems->{$item} eq '') {
9837: push(@{$trails},$trailstr);
9838: $allitems->{$item} = scalar(@{$trails})-1;
9839: }
9840: my $deeper = $depth+1;
9841: push(@{$parents},$category);
1.665 raeburn 9842: if (ref($subcats) eq 'HASH') {
9843: my $subcat = &escape($name).':'.$category.':'.$depth;
9844: for (my $j=@{$parents}; $j>=0; $j--) {
9845: my $higher;
9846: if ($j > 0) {
9847: $higher = &escape($parents->[$j]).':'.
9848: &escape($parents->[$j-1]).':'.$j;
9849: } else {
9850: $higher = &escape($parents->[$j]).'::'.$j;
9851: }
9852: push(@{$subcats->{$higher}},$subcat);
9853: }
9854: }
9855: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9856: $subcats);
1.655 raeburn 9857: pop(@{$parents});
9858: }
9859: } else {
9860: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9861: my $trailstr = join(' -> ',(@{$parents},$category));
9862: if ($allitems->{$item} eq '') {
9863: push(@{$trails},$trailstr);
9864: $allitems->{$item} = scalar(@{$trails})-1;
9865: }
9866: }
9867: return;
9868: }
9869:
1.663 raeburn 9870: =pod
9871:
9872: =item *&assign_categories_table()
9873:
9874: Create a datatable for display of hierarchical categories in a domain,
9875: with checkboxes to allow a course to be categorized.
9876:
9877: Inputs:
9878:
9879: cathash - reference to hash of categories defined for the domain (from
9880: configuration.db)
9881:
9882: currcat - scalar with an & separated list of categories assigned to a course.
9883:
1.919 raeburn 9884: type - scalar contains course type (Course or Community).
9885:
1.663 raeburn 9886: Returns: $output (markup to be displayed)
9887:
9888: =cut
9889:
9890: sub assign_categories_table {
1.919 raeburn 9891: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 9892: my $output;
9893: if (ref($cathash) eq 'HASH') {
9894: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9895: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9896: $maxdepth = scalar(@cats);
9897: if (@cats > 0) {
9898: my $itemcount = 0;
9899: if (ref($cats[0]) eq 'ARRAY') {
9900: my @currcategories;
9901: if ($currcat ne '') {
9902: @currcategories = split('&',$currcat);
9903: }
1.919 raeburn 9904: my $table;
1.663 raeburn 9905: for (my $i=0; $i<@{$cats[0]}; $i++) {
9906: my $parent = $cats[0][$i];
1.919 raeburn 9907: next if ($parent eq 'instcode');
9908: if ($type eq 'Community') {
9909: next unless ($parent eq 'communities');
9910: } else {
9911: next if ($parent eq 'communities');
9912: }
1.663 raeburn 9913: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9914: my $item = &escape($parent).'::0';
9915: my $checked = '';
9916: if (@currcategories > 0) {
9917: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9918: $checked = ' checked="checked"';
1.663 raeburn 9919: }
9920: }
1.919 raeburn 9921: my $parent_title = $parent;
9922: if ($parent eq 'communities') {
9923: $parent_title = &mt('Communities');
9924: }
9925: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9926: '<input type="checkbox" name="usecategory" value="'.
9927: $item.'"'.$checked.' />'.$parent_title.'</span>'.
9928: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9929: my $depth = 1;
9930: push(@path,$parent);
1.919 raeburn 9931: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 9932: pop(@path);
1.919 raeburn 9933: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 9934: $itemcount ++;
9935: }
1.919 raeburn 9936: if ($itemcount) {
9937: $output = &Apache::loncommon::start_data_table().
9938: $table.
9939: &Apache::loncommon::end_data_table();
9940: }
1.663 raeburn 9941: }
9942: }
9943: }
9944: return $output;
9945: }
9946:
9947: =pod
9948:
9949: =item *&assign_category_rows()
9950:
9951: Create a datatable row for display of nested categories in a domain,
9952: with checkboxes to allow a course to be categorized,called recursively.
9953:
9954: Inputs:
9955:
9956: itemcount - track row number for alternating colors
9957:
9958: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9959: categories and subcategories.
9960:
9961: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9962:
9963: parent - parent of current category item
9964:
9965: path - Array containing all categories back up through the hierarchy from the
9966: current category to the top level.
9967:
9968: currcategories - reference to array of current categories assigned to the course
9969:
9970: Returns: $output (markup to be displayed).
9971:
9972: =cut
9973:
9974: sub assign_category_rows {
9975: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9976: my ($text,$name,$item,$chgstr);
9977: if (ref($cats) eq 'ARRAY') {
9978: my $maxdepth = scalar(@{$cats});
9979: if (ref($cats->[$depth]) eq 'HASH') {
9980: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9981: my $numchildren = @{$cats->[$depth]{$parent}};
9982: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9983: $text .= '<td><table class="LC_datatable">';
9984: for (my $j=0; $j<$numchildren; $j++) {
9985: $name = $cats->[$depth]{$parent}[$j];
9986: $item = &escape($name).':'.&escape($parent).':'.$depth;
9987: my $deeper = $depth+1;
9988: my $checked = '';
9989: if (ref($currcategories) eq 'ARRAY') {
9990: if (@{$currcategories} > 0) {
9991: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9992: $checked = ' checked="checked"';
1.663 raeburn 9993: }
9994: }
9995: }
1.664 raeburn 9996: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9997: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9998: $item.'"'.$checked.' />'.$name.'</label></span>'.
9999: '<input type="hidden" name="catname" value="'.$name.'" />'.
10000: '</td><td>';
1.663 raeburn 10001: if (ref($path) eq 'ARRAY') {
10002: push(@{$path},$name);
10003: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10004: pop(@{$path});
10005: }
10006: $text .= '</td></tr>';
10007: }
10008: $text .= '</table></td>';
10009: }
10010: }
10011: }
10012: return $text;
10013: }
10014:
1.655 raeburn 10015: ############################################################
10016: ############################################################
10017:
10018:
1.443 albertel 10019: sub commit_customrole {
1.664 raeburn 10020: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10021: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10022: ($start?', '.&mt('starting').' '.localtime($start):'').
10023: ($end?', ending '.localtime($end):'').': <b>'.
10024: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10025: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10026: '</b><br />';
10027: return $output;
10028: }
10029:
10030: sub commit_standardrole {
1.541 raeburn 10031: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10032: my ($output,$logmsg,$linefeed);
10033: if ($context eq 'auto') {
10034: $linefeed = "\n";
10035: } else {
10036: $linefeed = "<br />\n";
10037: }
1.443 albertel 10038: if ($three eq 'st') {
1.541 raeburn 10039: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10040: $one,$two,$sec,$context);
10041: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10042: ($result eq 'unknown_course') || ($result eq 'refused')) {
10043: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10044: } else {
1.541 raeburn 10045: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10046: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10047: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10048: if ($context eq 'auto') {
10049: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10050: } else {
10051: $output .= '<b>'.$result.'</b>'.$linefeed.
10052: &mt('Add to classlist').': <b>ok</b>';
10053: }
10054: $output .= $linefeed;
1.443 albertel 10055: }
10056: } else {
10057: $output = &mt('Assigning').' '.$three.' in '.$url.
10058: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10059: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10060: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10061: if ($context eq 'auto') {
10062: $output .= $result.$linefeed;
10063: } else {
10064: $output .= '<b>'.$result.'</b>'.$linefeed;
10065: }
1.443 albertel 10066: }
10067: return $output;
10068: }
10069:
10070: sub commit_studentrole {
1.541 raeburn 10071: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10072: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10073: if ($context eq 'auto') {
10074: $linefeed = "\n";
10075: } else {
10076: $linefeed = '<br />'."\n";
10077: }
1.443 albertel 10078: if (defined($one) && defined($two)) {
10079: my $cid=$one.'_'.$two;
10080: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10081: my $secchange = 0;
10082: my $expire_role_result;
10083: my $modify_section_result;
1.628 raeburn 10084: if ($oldsec ne '-1') {
10085: if ($oldsec ne $sec) {
1.443 albertel 10086: $secchange = 1;
1.628 raeburn 10087: my $now = time;
1.443 albertel 10088: my $uurl='/'.$cid;
10089: $uurl=~s/\_/\//g;
10090: if ($oldsec) {
10091: $uurl.='/'.$oldsec;
10092: }
1.626 raeburn 10093: $oldsecurl = $uurl;
1.628 raeburn 10094: $expire_role_result =
1.652 raeburn 10095: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10096: if ($env{'request.course.sec'} ne '') {
10097: if ($expire_role_result eq 'refused') {
10098: my @roles = ('st');
10099: my @statuses = ('previous');
10100: my @roledoms = ($one);
10101: my $withsec = 1;
10102: my %roleshash =
10103: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10104: \@statuses,\@roles,\@roledoms,$withsec);
10105: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10106: my ($oldstart,$oldend) =
10107: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10108: if ($oldend > 0 && $oldend <= $now) {
10109: $expire_role_result = 'ok';
10110: }
10111: }
10112: }
10113: }
1.443 albertel 10114: $result = $expire_role_result;
10115: }
10116: }
10117: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10118: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10119: if ($modify_section_result =~ /^ok/) {
10120: if ($secchange == 1) {
1.628 raeburn 10121: if ($sec eq '') {
10122: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10123: } else {
10124: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10125: }
1.443 albertel 10126: } elsif ($oldsec eq '-1') {
1.628 raeburn 10127: if ($sec eq '') {
10128: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10129: } else {
10130: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10131: }
1.443 albertel 10132: } else {
1.628 raeburn 10133: if ($sec eq '') {
10134: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10135: } else {
10136: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10137: }
1.443 albertel 10138: }
10139: } else {
1.628 raeburn 10140: if ($secchange) {
10141: $$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;
10142: } else {
10143: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10144: }
1.443 albertel 10145: }
10146: $result = $modify_section_result;
10147: } elsif ($secchange == 1) {
1.628 raeburn 10148: if ($oldsec eq '') {
10149: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10150: } else {
10151: $$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;
10152: }
1.626 raeburn 10153: if ($expire_role_result eq 'refused') {
10154: my $newsecurl = '/'.$cid;
10155: $newsecurl =~ s/\_/\//g;
10156: if ($sec ne '') {
10157: $newsecurl.='/'.$sec;
10158: }
10159: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10160: if ($sec eq '') {
10161: $$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;
10162: } else {
10163: $$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;
10164: }
10165: }
10166: }
1.443 albertel 10167: }
10168: } else {
1.626 raeburn 10169: $$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 10170: $result = "error: incomplete course id\n";
10171: }
10172: return $result;
10173: }
10174:
10175: ############################################################
10176: ############################################################
10177:
1.566 albertel 10178: sub check_clone {
1.578 raeburn 10179: my ($args,$linefeed) = @_;
1.566 albertel 10180: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10181: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10182: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10183: my $clonemsg;
10184: my $can_clone = 0;
1.944 raeburn 10185: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10186: if ($lctype ne 'community') {
10187: $lctype = 'course';
10188: }
1.566 albertel 10189: if ($clonehome eq 'no_host') {
1.944 raeburn 10190: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10191: $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'});
10192: } else {
10193: $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'});
10194: }
1.566 albertel 10195: } else {
10196: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10197: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10198: if ($clonedesc{'type'} ne 'Community') {
10199: $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'});
10200: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10201: }
10202: }
1.882 raeburn 10203: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10204: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10205: $can_clone = 1;
10206: } else {
10207: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10208: $args->{'clonedomain'},$args->{'clonecourse'});
10209: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10210: if (grep(/^\*$/,@cloners)) {
10211: $can_clone = 1;
10212: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10213: $can_clone = 1;
10214: } else {
1.908 raeburn 10215: my $ccrole = 'cc';
1.944 raeburn 10216: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10217: $ccrole = 'co';
10218: }
1.578 raeburn 10219: my %roleshash =
10220: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10221: $args->{'ccdomain'},
1.908 raeburn 10222: 'userroles',['active'],[$ccrole],
1.578 raeburn 10223: [$args->{'clonedomain'}]);
1.908 raeburn 10224: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10225: $can_clone = 1;
10226: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10227: $can_clone = 1;
10228: } else {
1.944 raeburn 10229: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10230: $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'});
10231: } else {
10232: $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'});
10233: }
1.578 raeburn 10234: }
1.566 albertel 10235: }
1.578 raeburn 10236: }
1.566 albertel 10237: }
10238: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10239: }
10240:
1.444 albertel 10241: sub construct_course {
1.885 raeburn 10242: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10243: my $outcome;
1.541 raeburn 10244: my $linefeed = '<br />'."\n";
10245: if ($context eq 'auto') {
10246: $linefeed = "\n";
10247: }
1.566 albertel 10248:
10249: #
10250: # Are we cloning?
10251: #
10252: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10253: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10254: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10255: if ($context ne 'auto') {
1.578 raeburn 10256: if ($clonemsg ne '') {
10257: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10258: }
1.566 albertel 10259: }
10260: $outcome .= $clonemsg.$linefeed;
10261:
10262: if (!$can_clone) {
10263: return (0,$outcome);
10264: }
10265: }
10266:
1.444 albertel 10267: #
10268: # Open course
10269: #
10270: my $crstype = lc($args->{'crstype'});
10271: my %cenv=();
10272: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10273: $args->{'cdescr'},
10274: $args->{'curl'},
10275: $args->{'course_home'},
10276: $args->{'nonstandard'},
10277: $args->{'crscode'},
10278: $args->{'ccuname'}.':'.
10279: $args->{'ccdomain'},
1.882 raeburn 10280: $args->{'crstype'},
1.885 raeburn 10281: $cnum,$context,$category);
1.444 albertel 10282:
10283: # Note: The testing routines depend on this being output; see
10284: # Utils::Course. This needs to at least be output as a comment
10285: # if anyone ever decides to not show this, and Utils::Course::new
10286: # will need to be suitably modified.
1.541 raeburn 10287: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10288: if ($$courseid =~ /^error:/) {
10289: return (0,$outcome);
10290: }
10291:
1.444 albertel 10292: #
10293: # Check if created correctly
10294: #
1.479 albertel 10295: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10296: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10297: if ($crsuhome eq 'no_host') {
10298: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10299: return (0,$outcome);
10300: }
1.541 raeburn 10301: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10302:
1.444 albertel 10303: #
1.566 albertel 10304: # Do the cloning
10305: #
10306: if ($can_clone && $cloneid) {
10307: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10308: if ($context ne 'auto') {
10309: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10310: }
10311: $outcome .= $clonemsg.$linefeed;
10312: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10313: # Copy all files
1.637 www 10314: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10315: # Restore URL
1.566 albertel 10316: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10317: # Restore title
1.566 albertel 10318: $cenv{'description'}=$oldcenv{'description'};
1.948.2.2 raeburn 10319: # Restore creation date, creator and creation context.
10320: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10321: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10322: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10323: # Mark as cloned
1.566 albertel 10324: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10325: # Need to clone grading mode
10326: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10327: $cenv{'grading'}=$newenv{'grading'};
10328: # Do not clone these environment entries
10329: &Apache::lonnet::del('environment',
10330: ['default_enrollment_start_date',
10331: 'default_enrollment_end_date',
10332: 'question.email',
10333: 'policy.email',
10334: 'comment.email',
10335: 'pch.users.denied',
1.725 raeburn 10336: 'plc.users.denied',
10337: 'hidefromcat',
10338: 'categories'],
1.638 www 10339: $$crsudom,$$crsunum);
1.444 albertel 10340: }
1.566 albertel 10341:
1.444 albertel 10342: #
10343: # Set environment (will override cloned, if existing)
10344: #
10345: my @sections = ();
10346: my @xlists = ();
10347: if ($args->{'crstype'}) {
10348: $cenv{'type'}=$args->{'crstype'};
10349: }
10350: if ($args->{'crsid'}) {
10351: $cenv{'courseid'}=$args->{'crsid'};
10352: }
10353: if ($args->{'crscode'}) {
10354: $cenv{'internal.coursecode'}=$args->{'crscode'};
10355: }
10356: if ($args->{'crsquota'} ne '') {
10357: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10358: } else {
10359: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10360: }
10361: if ($args->{'ccuname'}) {
10362: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10363: ':'.$args->{'ccdomain'};
10364: } else {
10365: $cenv{'internal.courseowner'} = $args->{'curruser'};
10366: }
10367: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10368: if ($args->{'crssections'}) {
10369: $cenv{'internal.sectionnums'} = '';
10370: if ($args->{'crssections'} =~ m/,/) {
10371: @sections = split/,/,$args->{'crssections'};
10372: } else {
10373: $sections[0] = $args->{'crssections'};
10374: }
10375: if (@sections > 0) {
10376: foreach my $item (@sections) {
10377: my ($sec,$gp) = split/:/,$item;
10378: my $class = $args->{'crscode'}.$sec;
10379: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10380: $cenv{'internal.sectionnums'} .= $item.',';
10381: unless ($addcheck eq 'ok') {
10382: push @badclasses, $class;
10383: }
10384: }
10385: $cenv{'internal.sectionnums'} =~ s/,$//;
10386: }
10387: }
10388: # do not hide course coordinator from staff listing,
10389: # even if privileged
10390: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10391: # add crosslistings
10392: if ($args->{'crsxlist'}) {
10393: $cenv{'internal.crosslistings'}='';
10394: if ($args->{'crsxlist'} =~ m/,/) {
10395: @xlists = split/,/,$args->{'crsxlist'};
10396: } else {
10397: $xlists[0] = $args->{'crsxlist'};
10398: }
10399: if (@xlists > 0) {
10400: foreach my $item (@xlists) {
10401: my ($xl,$gp) = split/:/,$item;
10402: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10403: $cenv{'internal.crosslistings'} .= $item.',';
10404: unless ($addcheck eq 'ok') {
10405: push @badclasses, $xl;
10406: }
10407: }
10408: $cenv{'internal.crosslistings'} =~ s/,$//;
10409: }
10410: }
10411: if ($args->{'autoadds'}) {
10412: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10413: }
10414: if ($args->{'autodrops'}) {
10415: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10416: }
10417: # check for notification of enrollment changes
10418: my @notified = ();
10419: if ($args->{'notify_owner'}) {
10420: if ($args->{'ccuname'} ne '') {
10421: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10422: }
10423: }
10424: if ($args->{'notify_dc'}) {
10425: if ($uname ne '') {
1.630 raeburn 10426: push(@notified,$uname.':'.$udom);
1.444 albertel 10427: }
10428: }
10429: if (@notified > 0) {
10430: my $notifylist;
10431: if (@notified > 1) {
10432: $notifylist = join(',',@notified);
10433: } else {
10434: $notifylist = $notified[0];
10435: }
10436: $cenv{'internal.notifylist'} = $notifylist;
10437: }
10438: if (@badclasses > 0) {
10439: my %lt=&Apache::lonlocal::texthash(
10440: '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',
10441: 'dnhr' => 'does not have rights to access enrollment in these classes',
10442: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10443: );
1.541 raeburn 10444: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10445: ' ('.$lt{'adby'}.')';
10446: if ($context eq 'auto') {
10447: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10448: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10449: foreach my $item (@badclasses) {
10450: if ($context eq 'auto') {
10451: $outcome .= " - $item\n";
10452: } else {
10453: $outcome .= "<li>$item</li>\n";
10454: }
10455: }
10456: if ($context eq 'auto') {
10457: $outcome .= $linefeed;
10458: } else {
1.566 albertel 10459: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10460: }
10461: }
1.444 albertel 10462: }
10463: if ($args->{'no_end_date'}) {
10464: $args->{'endaccess'} = 0;
10465: }
10466: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10467: $cenv{'internal.autoend'}=$args->{'enrollend'};
10468: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10469: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10470: if ($args->{'showphotos'}) {
10471: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10472: }
10473: $cenv{'internal.authtype'} = $args->{'authtype'};
10474: $cenv{'internal.autharg'} = $args->{'autharg'};
10475: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10476: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10477: 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');
10478: if ($context eq 'auto') {
10479: $outcome .= $krb_msg;
10480: } else {
1.566 albertel 10481: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10482: }
10483: $outcome .= $linefeed;
1.444 albertel 10484: }
10485: }
10486: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10487: if ($args->{'setpolicy'}) {
10488: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10489: }
10490: if ($args->{'setcontent'}) {
10491: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10492: }
10493: }
10494: if ($args->{'reshome'}) {
10495: $cenv{'reshome'}=$args->{'reshome'}.'/';
10496: $cenv{'reshome'}=~s/\/+$/\//;
10497: }
10498: #
10499: # course has keyed access
10500: #
10501: if ($args->{'setkeys'}) {
10502: $cenv{'keyaccess'}='yes';
10503: }
10504: # if specified, key authority is not course, but user
10505: # only active if keyaccess is yes
10506: if ($args->{'keyauth'}) {
1.487 albertel 10507: my ($user,$domain) = split(':',$args->{'keyauth'});
10508: $user = &LONCAPA::clean_username($user);
10509: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10510: if ($user ne '' && $domain ne '') {
1.487 albertel 10511: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10512: }
10513: }
10514:
10515: if ($args->{'disresdis'}) {
10516: $cenv{'pch.roles.denied'}='st';
10517: }
10518: if ($args->{'disablechat'}) {
10519: $cenv{'plc.roles.denied'}='st';
10520: }
10521:
10522: # Record we've not yet viewed the Course Initialization Helper for this
10523: # course
10524: $cenv{'course.helper.not.run'} = 1;
10525: #
10526: # Use new Randomseed
10527: #
10528: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10529: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10530: #
10531: # The encryption code and receipt prefix for this course
10532: #
10533: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10534: $cenv{'internal.encpref'}=100+int(9*rand(99));
10535: #
10536: # By default, use standard grading
10537: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10538:
1.541 raeburn 10539: $outcome .= $linefeed.&mt('Setting environment').': '.
10540: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10541: #
10542: # Open all assignments
10543: #
10544: if ($args->{'openall'}) {
10545: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10546: my %storecontent = ($storeunder => time,
10547: $storeunder.'.type' => 'date_start');
10548:
10549: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10550: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10551: }
10552: #
10553: # Set first page
10554: #
10555: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10556: || ($cloneid)) {
1.445 albertel 10557: use LONCAPA::map;
1.444 albertel 10558: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10559:
10560: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10561: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10562:
1.444 albertel 10563: $outcome .= ($fatal?$errtext:'read ok').' - ';
10564: my $title; my $url;
10565: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10566: $title=&mt('Syllabus');
1.444 albertel 10567: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10568: } else {
1.948.2.5 raeburn 10569: $title=&mt('Table of Contents');
1.444 albertel 10570: $url='/adm/navmaps';
10571: }
1.445 albertel 10572:
10573: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10574: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10575:
10576: if ($errtext) { $fatal=2; }
1.541 raeburn 10577: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10578: }
1.566 albertel 10579:
10580: return (1,$outcome);
1.444 albertel 10581: }
10582:
10583: ############################################################
10584: ############################################################
10585:
1.378 raeburn 10586: sub course_type {
10587: my ($cid) = @_;
10588: if (!defined($cid)) {
10589: $cid = $env{'request.course.id'};
10590: }
1.404 albertel 10591: if (defined($env{'course.'.$cid.'.type'})) {
10592: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10593: } else {
10594: return 'Course';
1.377 raeburn 10595: }
10596: }
1.156 albertel 10597:
1.406 raeburn 10598: sub group_term {
10599: my $crstype = &course_type();
10600: my %names = (
10601: 'Course' => 'group',
1.865 raeburn 10602: 'Community' => 'group',
1.406 raeburn 10603: );
10604: return $names{$crstype};
10605: }
10606:
1.902 raeburn 10607: sub course_types {
10608: my @types = ('official','unofficial','community');
10609: my %typename = (
10610: official => 'Official course',
10611: unofficial => 'Unofficial course',
10612: community => 'Community',
10613: );
10614: return (\@types,\%typename);
10615: }
10616:
1.156 albertel 10617: sub icon {
10618: my ($file)=@_;
1.505 albertel 10619: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10620: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10621: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10622: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10623: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10624: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10625: $curfext.".gif") {
10626: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10627: $curfext.".gif";
10628: }
10629: }
1.249 albertel 10630: return &lonhttpdurl($iconname);
1.154 albertel 10631: }
1.84 albertel 10632:
1.575 albertel 10633: sub lonhttpdurl {
1.692 www 10634: #
10635: # Had been used for "small fry" static images on separate port 8080.
10636: # Modify here if lightweight http functionality desired again.
10637: # Currently eliminated due to increasing firewall issues.
10638: #
1.575 albertel 10639: my ($url)=@_;
1.692 www 10640: return $url;
1.215 albertel 10641: }
10642:
1.213 albertel 10643: sub connection_aborted {
10644: my ($r)=@_;
10645: $r->print(" ");$r->rflush();
10646: my $c = $r->connection;
10647: return $c->aborted();
10648: }
10649:
1.221 foxr 10650: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10651: # strings as 'strings'.
10652: sub escape_single {
1.221 foxr 10653: my ($input) = @_;
1.223 albertel 10654: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10655: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10656: return $input;
10657: }
1.223 albertel 10658:
1.222 foxr 10659: # Same as escape_single, but escape's "'s This
10660: # can be used for "strings"
10661: sub escape_double {
10662: my ($input) = @_;
10663: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10664: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10665: return $input;
10666: }
1.223 albertel 10667:
1.222 foxr 10668: # Escapes the last element of a full URL.
10669: sub escape_url {
10670: my ($url) = @_;
1.238 raeburn 10671: my @urlslices = split(/\//, $url,-1);
1.369 www 10672: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10673: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10674: }
1.462 albertel 10675:
1.820 raeburn 10676: sub compare_arrays {
10677: my ($arrayref1,$arrayref2) = @_;
10678: my (@difference,%count);
10679: @difference = ();
10680: %count = ();
10681: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10682: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10683: foreach my $element (keys(%count)) {
10684: if ($count{$element} == 1) {
10685: push(@difference,$element);
10686: }
10687: }
10688: }
10689: return @difference;
10690: }
10691:
1.817 bisitz 10692: # -------------------------------------------------------- Initialize user login
1.462 albertel 10693: sub init_user_environment {
1.463 albertel 10694: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10695: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10696:
10697: my $public=($username eq 'public' && $domain eq 'public');
10698:
10699: # See if old ID present, if so, remove
10700:
10701: my ($filename,$cookie,$userroles);
10702: my $now=time;
10703:
10704: if ($public) {
10705: my $max_public=100;
10706: my $oldest;
10707: my $oldest_time=0;
10708: for(my $next=1;$next<=$max_public;$next++) {
10709: if (-e $lonids."/publicuser_$next.id") {
10710: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10711: if ($mtime<$oldest_time || !$oldest_time) {
10712: $oldest_time=$mtime;
10713: $oldest=$next;
10714: }
10715: } else {
10716: $cookie="publicuser_$next";
10717: last;
10718: }
10719: }
10720: if (!$cookie) { $cookie="publicuser_$oldest"; }
10721: } else {
1.463 albertel 10722: # if this isn't a robot, kill any existing non-robot sessions
10723: if (!$args->{'robot'}) {
10724: opendir(DIR,$lonids);
10725: while ($filename=readdir(DIR)) {
10726: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10727: unlink($lonids.'/'.$filename);
10728: }
1.462 albertel 10729: }
1.463 albertel 10730: closedir(DIR);
1.462 albertel 10731: }
10732: # Give them a new cookie
1.463 albertel 10733: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10734: : $now.$$.int(rand(10000)));
1.463 albertel 10735: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10736:
10737: # Initialize roles
10738:
10739: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10740: }
10741: # ------------------------------------ Check browser type and MathML capability
10742:
10743: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10744: $clientunicode,$clientos) = &decode_user_agent($r);
10745:
10746: # ------------------------------------------------------------- Get environment
10747:
10748: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10749: my ($tmp) = keys(%userenv);
10750: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10751: # default remote control to off
10752: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10753: } else {
10754: undef(%userenv);
10755: }
10756: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10757: $form->{'interface'}=$userenv{'interface'};
10758: }
10759: $env{'environment.remote'}=$userenv{'remote'};
10760: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10761:
10762: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10763: foreach my $option ('interface','localpath','localres') {
10764: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10765: }
10766: # --------------------------------------------------------- Write first profile
10767:
10768: {
10769: my %initial_env =
10770: ("user.name" => $username,
10771: "user.domain" => $domain,
10772: "user.home" => $authhost,
10773: "browser.type" => $clientbrowser,
10774: "browser.version" => $clientversion,
10775: "browser.mathml" => $clientmathml,
10776: "browser.unicode" => $clientunicode,
10777: "browser.os" => $clientos,
10778: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10779: "request.course.fn" => '',
10780: "request.course.uri" => '',
10781: "request.course.sec" => '',
10782: "request.role" => 'cm',
10783: "request.role.adv" => $env{'user.adv'},
10784: "request.host" => $ENV{'REMOTE_ADDR'},);
10785:
10786: if ($form->{'localpath'}) {
10787: $initial_env{"browser.localpath"} = $form->{'localpath'};
10788: $initial_env{"browser.localres"} = $form->{'localres'};
10789: }
10790:
10791: if ($public) {
10792: $initial_env{"environment.remote"} = "off";
10793: }
10794: if ($form->{'interface'}) {
10795: $form->{'interface'}=~s/\W//gs;
10796: $initial_env{"browser.interface"} = $form->{'interface'};
10797: $env{'browser.interface'}=$form->{'interface'};
10798: }
1.948.2.11! raeburn 10799: my %is_adv = ( is_adv => $env{'user.adv'} );
1.948.2.10 raeburn 10800: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.462 albertel 10801:
1.724 raeburn 10802: foreach my $tool ('aboutme','blog','portfolio') {
10803: $userenv{'availabletools.'.$tool} =
1.948.2.10 raeburn 10804: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
10805: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 10806: }
10807:
1.864 raeburn 10808: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10809: $userenv{'canrequest.'.$crstype} =
10810: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.948.2.10 raeburn 10811: 'reload','requestcourses',
10812: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 10813: }
10814:
1.462 albertel 10815: $env{'user.environment'} = "$lonids/$cookie.id";
10816:
10817: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10818: &GDBM_WRCREAT(),0640)) {
10819: &_add_to_env(\%disk_env,\%initial_env);
10820: &_add_to_env(\%disk_env,\%userenv,'environment.');
10821: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10822: if (ref($args->{'extra_env'})) {
10823: &_add_to_env(\%disk_env,$args->{'extra_env'});
10824: }
1.462 albertel 10825: untie(%disk_env);
10826: } else {
1.705 tempelho 10827: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10828: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10829: return 'error: '.$!;
10830: }
10831: }
10832: $env{'request.role'}='cm';
10833: $env{'request.role.adv'}=$env{'user.adv'};
10834: $env{'browser.type'}=$clientbrowser;
10835:
10836: return $cookie;
10837:
10838: }
10839:
10840: sub _add_to_env {
10841: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10842: if (ref($env_data) eq 'HASH') {
10843: while (my ($key,$value) = each(%$env_data)) {
10844: $idf->{$prefix.$key} = $value;
10845: $env{$prefix.$key} = $value;
10846: }
1.462 albertel 10847: }
10848: }
10849:
1.685 tempelho 10850: # --- Get the symbolic name of a problem and the url
10851: sub get_symb {
10852: my ($request,$silent) = @_;
1.726 raeburn 10853: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10854: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10855: if ($symb eq '') {
10856: if (!$silent) {
10857: $request->print("Unable to handle ambiguous references:$url:.");
10858: return ();
10859: }
10860: }
10861: &Apache::lonenc::check_decrypt(\$symb);
10862: return ($symb);
10863: }
10864:
10865: # --------------------------------------------------------------Get annotation
10866:
10867: sub get_annotation {
10868: my ($symb,$enc) = @_;
10869:
10870: my $key = $symb;
10871: if (!$enc) {
10872: $key =
10873: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10874: }
10875: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10876: return $annotation{$key};
10877: }
10878:
10879: sub clean_symb {
1.731 raeburn 10880: my ($symb,$delete_enc) = @_;
1.685 tempelho 10881:
10882: &Apache::lonenc::check_decrypt(\$symb);
10883: my $enc = $env{'request.enc'};
1.731 raeburn 10884: if ($delete_enc) {
1.730 raeburn 10885: delete($env{'request.enc'});
10886: }
1.685 tempelho 10887:
10888: return ($symb,$enc);
10889: }
1.462 albertel 10890:
1.41 ng 10891: =pod
10892:
10893: =back
10894:
1.112 bowersj2 10895: =cut
1.41 ng 10896:
1.112 bowersj2 10897: 1;
10898: __END__;
1.41 ng 10899:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>