Annotation of loncom/interface/loncommon.pm, revision 1.988
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.988 ! raeburn 4: # $Id: loncommon.pm,v 1.987 2010/11/28 00:04:05 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.970 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.973 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
1.973 raeburn 1093: be useful for certain help topics with big pictures included.
1094:
1095: $imgid is the id of the img tag used for the help icon. This may be
1096: used in a javascript call to switch the image src. See
1097: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1098:
1099: =cut
1100:
1101: sub help_open_topic {
1.973 raeburn 1102: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1103: $text = "" if (not defined $text);
1.44 bowersj2 1104: $stayOnPage = 0 if (not defined $stayOnPage);
1105: $width = 350 if (not defined $width);
1106: $height = 400 if (not defined $height);
1107: my $filename = $topic;
1108: $filename =~ s/ /_/g;
1109:
1.48 bowersj2 1110: my $template = "";
1111: my $link;
1.572 banghart 1112:
1.159 www 1113: $topic=~s/\W/\_/g;
1.44 bowersj2 1114:
1.572 banghart 1115: if (!$stayOnPage) {
1.72 bowersj2 1116: $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 1117: } else {
1.48 bowersj2 1118: $link = "/adm/help/${filename}.hlp";
1119: }
1120:
1121: # Add the text
1.755 neumanie 1122: if ($text ne "") {
1.763 bisitz 1123: $template.='<span class="LC_help_open_topic">'
1124: .'<a target="_top" href="'.$link.'">'
1125: .$text.'</a>';
1.48 bowersj2 1126: }
1127:
1.763 bisitz 1128: # (Always) Add the graphic
1.179 matthew 1129: my $title = &mt('Online Help');
1.667 raeburn 1130: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1131: if ($imgid ne '') {
1132: $imgid = ' id="'.$imgid.'"';
1133: }
1.763 bisitz 1134: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1135: .'<img src="'.$helpicon.'" border="0"'
1136: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1137: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1138: .' /></a>';
1139: if ($text ne "") {
1140: $template.='</span>';
1141: }
1.44 bowersj2 1142: return $template;
1143:
1.106 bowersj2 1144: }
1145:
1146: # This is a quicky function for Latex cheatsheet editing, since it
1147: # appears in at least four places
1148: sub helpLatexCheatsheet {
1.732 raeburn 1149: my ($topic,$text,$not_author) = @_;
1150: my $out;
1.106 bowersj2 1151: my $addOther = '';
1.732 raeburn 1152: if ($topic) {
1.763 bisitz 1153: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1154: undef, undef, 600).
1155: '</span> ';
1156: }
1157: $out = '<span>' # Start cheatsheet
1158: .$addOther
1159: .'<span>'
1160: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1161: undef,undef,600)
1162: .'</span> <span>'
1163: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1164: undef,undef,600)
1165: .'</span>';
1.732 raeburn 1166: unless ($not_author) {
1.763 bisitz 1167: $out .= ' <span>'
1168: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1169: undef,undef,600)
1170: .'</span>';
1.732 raeburn 1171: }
1.763 bisitz 1172: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1173: return $out;
1.172 www 1174: }
1175:
1.430 albertel 1176: sub general_help {
1177: my $helptopic='Student_Intro';
1178: if ($env{'request.role'}=~/^(ca|au)/) {
1179: $helptopic='Authoring_Intro';
1.907 raeburn 1180: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1181: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1182: } elsif ($env{'request.role'}=~/^dc/) {
1183: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1184: }
1185: return $helptopic;
1186: }
1187:
1188: sub update_help_link {
1189: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1190: my $origurl = $ENV{'REQUEST_URI'};
1191: $origurl=~s|^/~|/priv/|;
1192: my $timestamp = time;
1193: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1194: $$datum = &escape($$datum);
1195: }
1196:
1197: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1198: my $output .= <<"ENDOUTPUT";
1199: <script type="text/javascript">
1.824 bisitz 1200: // <![CDATA[
1.430 albertel 1201: banner_link = '$banner_link';
1.824 bisitz 1202: // ]]>
1.430 albertel 1203: </script>
1204: ENDOUTPUT
1205: return $output;
1206: }
1207:
1208: # now just updates the help link and generates a blue icon
1.193 raeburn 1209: sub help_open_menu {
1.430 albertel 1210: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1211: = @_;
1.949 droeschl 1212: $stayOnPage = 1;
1.430 albertel 1213: my $output;
1214: if ($component_help) {
1215: if (!$text) {
1216: $output=&help_open_topic($component_help,undef,$stayOnPage,
1217: $width,$height);
1218: } else {
1219: my $help_text;
1220: $help_text=&unescape($topic);
1221: $output='<table><tr><td>'.
1222: &help_open_topic($component_help,$help_text,$stayOnPage,
1223: $width,$height).'</td></tr></table>';
1224: }
1225: }
1226: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1227: return $output.$banner_link;
1228: }
1229:
1230: sub top_nav_help {
1231: my ($text) = @_;
1.436 albertel 1232: $text = &mt($text);
1.949 droeschl 1233: my $stay_on_page = 1;
1234:
1.572 banghart 1235: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1236: : "javascript:helpMenu('open')";
1.572 banghart 1237: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1238:
1.201 raeburn 1239: my $title = &mt('Get help');
1.436 albertel 1240:
1241: return <<"END";
1242: $banner_link
1243: <a href="$link" title="$title">$text</a>
1244: END
1245: }
1246:
1247: sub help_menu_js {
1248: my ($text) = @_;
1.949 droeschl 1249: my $stayOnPage = 1;
1.436 albertel 1250: my $width = 620;
1251: my $height = 600;
1.430 albertel 1252: my $helptopic=&general_help();
1253: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1254: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1255: my $start_page =
1256: &Apache::loncommon::start_page('Help Menu', undef,
1257: {'frameset' => 1,
1258: 'js_ready' => 1,
1259: 'add_entries' => {
1260: 'border' => '0',
1.579 raeburn 1261: 'rows' => "110,*",},});
1.331 albertel 1262: my $end_page =
1263: &Apache::loncommon::end_page({'frameset' => 1,
1264: 'js_ready' => 1,});
1265:
1.436 albertel 1266: my $template .= <<"ENDTEMPLATE";
1267: <script type="text/javascript">
1.877 bisitz 1268: // <![CDATA[
1.253 albertel 1269: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1270: var banner_link = '';
1.243 raeburn 1271: function helpMenu(target) {
1272: var caller = this;
1273: if (target == 'open') {
1274: var newWindow = null;
1275: try {
1.262 albertel 1276: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1277: }
1278: catch(error) {
1279: writeHelp(caller);
1280: return;
1281: }
1282: if (newWindow) {
1283: caller = newWindow;
1284: }
1.193 raeburn 1285: }
1.243 raeburn 1286: writeHelp(caller);
1287: return;
1288: }
1289: function writeHelp(caller) {
1.430 albertel 1290: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1291: caller.document.close()
1292: caller.focus()
1.193 raeburn 1293: }
1.877 bisitz 1294: // END LON-CAPA Internal -->
1.253 albertel 1295: // ]]>
1.436 albertel 1296: </script>
1.193 raeburn 1297: ENDTEMPLATE
1298: return $template;
1299: }
1300:
1.172 www 1301: sub help_open_bug {
1302: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1303: unless ($env{'user.adv'}) { return ''; }
1.172 www 1304: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1305: $text = "" if (not defined $text);
1306: $stayOnPage=1;
1.184 albertel 1307: $width = 600 if (not defined $width);
1308: $height = 600 if (not defined $height);
1.172 www 1309:
1310: $topic=~s/\W+/\+/g;
1311: my $link='';
1312: my $template='';
1.379 albertel 1313: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1314: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1315: if (!$stayOnPage)
1316: {
1317: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1318: }
1319: else
1320: {
1321: $link = $url;
1322: }
1323: # Add the text
1324: if ($text ne "")
1325: {
1326: $template .=
1327: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1328: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1329: }
1330:
1331: # Add the graphic
1.179 matthew 1332: my $title = &mt('Report a Bug');
1.215 albertel 1333: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1334: $template .= <<"ENDTEMPLATE";
1.436 albertel 1335: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1336: ENDTEMPLATE
1337: if ($text ne '') { $template.='</td></tr></table>' };
1338: return $template;
1339:
1340: }
1341:
1342: sub help_open_faq {
1343: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1344: unless ($env{'user.adv'}) { return ''; }
1.172 www 1345: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1346: $text = "" if (not defined $text);
1347: $stayOnPage=1;
1348: $width = 350 if (not defined $width);
1349: $height = 400 if (not defined $height);
1350:
1351: $topic=~s/\W+/\+/g;
1352: my $link='';
1353: my $template='';
1354: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1355: if (!$stayOnPage)
1356: {
1357: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1358: }
1359: else
1360: {
1361: $link = $url;
1362: }
1363:
1364: # Add the text
1365: if ($text ne "")
1366: {
1367: $template .=
1.173 www 1368: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1369: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1370: }
1371:
1372: # Add the graphic
1.179 matthew 1373: my $title = &mt('View the FAQ');
1.215 albertel 1374: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1375: $template .= <<"ENDTEMPLATE";
1.436 albertel 1376: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1377: ENDTEMPLATE
1378: if ($text ne '') { $template.='</td></tr></table>' };
1379: return $template;
1380:
1.44 bowersj2 1381: }
1.37 matthew 1382:
1.180 matthew 1383: ###############################################################
1384: ###############################################################
1385:
1.45 matthew 1386: =pod
1387:
1.648 raeburn 1388: =item * &change_content_javascript():
1.256 matthew 1389:
1390: This and the next function allow you to create small sections of an
1391: otherwise static HTML page that you can update on the fly with
1392: Javascript, even in Netscape 4.
1393:
1394: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1395: must be written to the HTML page once. It will prove the Javascript
1396: function "change(name, content)". Calling the change function with the
1397: name of the section
1398: you want to update, matching the name passed to C<changable_area>, and
1399: the new content you want to put in there, will put the content into
1400: that area.
1401:
1402: B<Note>: Netscape 4 only reserves enough space for the changable area
1403: to contain room for the original contents. You need to "make space"
1404: for whatever changes you wish to make, and be B<sure> to check your
1405: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1406: it's adequate for updating a one-line status display, but little more.
1407: This script will set the space to 100% width, so you only need to
1408: worry about height in Netscape 4.
1409:
1410: Modern browsers are much less limiting, and if you can commit to the
1411: user not using Netscape 4, this feature may be used freely with
1412: pretty much any HTML.
1413:
1414: =cut
1415:
1416: sub change_content_javascript {
1417: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1418: if ($env{'browser.type'} eq 'netscape' &&
1419: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1420: return (<<NETSCAPE4);
1421: function change(name, content) {
1422: doc = document.layers[name+"___escape"].layers[0].document;
1423: doc.open();
1424: doc.write(content);
1425: doc.close();
1426: }
1427: NETSCAPE4
1428: } else {
1429: # Otherwise, we need to use semi-standards-compliant code
1430: # (technically, "innerHTML" isn't standard but the equivalent
1431: # is really scary, and every useful browser supports it
1432: return (<<DOMBASED);
1433: function change(name, content) {
1434: element = document.getElementById(name);
1435: element.innerHTML = content;
1436: }
1437: DOMBASED
1438: }
1439: }
1440:
1441: =pod
1442:
1.648 raeburn 1443: =item * &changable_area($name,$origContent):
1.256 matthew 1444:
1445: This provides a "changable area" that can be modified on the fly via
1446: the Javascript code provided in C<change_content_javascript>. $name is
1447: the name you will use to reference the area later; do not repeat the
1448: same name on a given HTML page more then once. $origContent is what
1449: the area will originally contain, which can be left blank.
1450:
1451: =cut
1452:
1453: sub changable_area {
1454: my ($name, $origContent) = @_;
1455:
1.258 albertel 1456: if ($env{'browser.type'} eq 'netscape' &&
1457: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1458: # If this is netscape 4, we need to use the Layer tag
1459: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1460: } else {
1461: return "<span id='$name'>$origContent</span>";
1462: }
1463: }
1464:
1465: =pod
1466:
1.648 raeburn 1467: =item * &viewport_geometry_js
1.590 raeburn 1468:
1469: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1470:
1471: =cut
1472:
1473:
1474: sub viewport_geometry_js {
1475: return <<"GEOMETRY";
1476: var Geometry = {};
1477: function init_geometry() {
1478: if (Geometry.init) { return };
1479: Geometry.init=1;
1480: if (window.innerHeight) {
1481: Geometry.getViewportHeight = function() { return window.innerHeight; };
1482: Geometry.getViewportWidth = function() { return window.innerWidth; };
1483: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1484: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1485: }
1486: else if (document.documentElement && document.documentElement.clientHeight) {
1487: Geometry.getViewportHeight =
1488: function() { return document.documentElement.clientHeight; };
1489: Geometry.getViewportWidth =
1490: function() { return document.documentElement.clientWidth; };
1491:
1492: Geometry.getHorizontalScroll =
1493: function() { return document.documentElement.scrollLeft; };
1494: Geometry.getVerticalScroll =
1495: function() { return document.documentElement.scrollTop; };
1496: }
1497: else if (document.body.clientHeight) {
1498: Geometry.getViewportHeight =
1499: function() { return document.body.clientHeight; };
1500: Geometry.getViewportWidth =
1501: function() { return document.body.clientWidth; };
1502: Geometry.getHorizontalScroll =
1503: function() { return document.body.scrollLeft; };
1504: Geometry.getVerticalScroll =
1505: function() { return document.body.scrollTop; };
1506: }
1507: }
1508:
1509: GEOMETRY
1510: }
1511:
1512: =pod
1513:
1.648 raeburn 1514: =item * &viewport_size_js()
1.590 raeburn 1515:
1516: 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.
1517:
1518: =cut
1519:
1520: sub viewport_size_js {
1521: my $geometry = &viewport_geometry_js();
1522: return <<"DIMS";
1523:
1524: $geometry
1525:
1526: function getViewportDims(width,height) {
1527: init_geometry();
1528: width.value = Geometry.getViewportWidth();
1529: height.value = Geometry.getViewportHeight();
1530: return;
1531: }
1532:
1533: DIMS
1534: }
1535:
1536: =pod
1537:
1.648 raeburn 1538: =item * &resize_textarea_js()
1.565 albertel 1539:
1540: emits the needed javascript to resize a textarea to be as big as possible
1541:
1542: creates a function resize_textrea that takes two IDs first should be
1543: the id of the element to resize, second should be the id of a div that
1544: surrounds everything that comes after the textarea, this routine needs
1545: to be attached to the <body> for the onload and onresize events.
1546:
1.648 raeburn 1547: =back
1.565 albertel 1548:
1549: =cut
1550:
1551: sub resize_textarea_js {
1.590 raeburn 1552: my $geometry = &viewport_geometry_js();
1.565 albertel 1553: return <<"RESIZE";
1554: <script type="text/javascript">
1.824 bisitz 1555: // <![CDATA[
1.590 raeburn 1556: $geometry
1.565 albertel 1557:
1.588 albertel 1558: function getX(element) {
1559: var x = 0;
1560: while (element) {
1561: x += element.offsetLeft;
1562: element = element.offsetParent;
1563: }
1564: return x;
1565: }
1566: function getY(element) {
1567: var y = 0;
1568: while (element) {
1569: y += element.offsetTop;
1570: element = element.offsetParent;
1571: }
1572: return y;
1573: }
1574:
1575:
1.565 albertel 1576: function resize_textarea(textarea_id,bottom_id) {
1577: init_geometry();
1578: var textarea = document.getElementById(textarea_id);
1579: //alert(textarea);
1580:
1.588 albertel 1581: var textarea_top = getY(textarea);
1.565 albertel 1582: var textarea_height = textarea.offsetHeight;
1583: var bottom = document.getElementById(bottom_id);
1.588 albertel 1584: var bottom_top = getY(bottom);
1.565 albertel 1585: var bottom_height = bottom.offsetHeight;
1586: var window_height = Geometry.getViewportHeight();
1.588 albertel 1587: var fudge = 23;
1.565 albertel 1588: var new_height = window_height-fudge-textarea_top-bottom_height;
1589: if (new_height < 300) {
1590: new_height = 300;
1591: }
1592: textarea.style.height=new_height+'px';
1593: }
1.824 bisitz 1594: // ]]>
1.565 albertel 1595: </script>
1596: RESIZE
1597:
1598: }
1599:
1600: =pod
1601:
1.256 matthew 1602: =head1 Excel and CSV file utility routines
1603:
1604: =over 4
1605:
1606: =cut
1607:
1608: ###############################################################
1609: ###############################################################
1610:
1611: =pod
1612:
1.648 raeburn 1613: =item * &csv_translate($text)
1.37 matthew 1614:
1.185 www 1615: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1616: format.
1617:
1618: =cut
1619:
1.180 matthew 1620: ###############################################################
1621: ###############################################################
1.37 matthew 1622: sub csv_translate {
1623: my $text = shift;
1624: $text =~ s/\"/\"\"/g;
1.209 albertel 1625: $text =~ s/\n/ /g;
1.37 matthew 1626: return $text;
1627: }
1.180 matthew 1628:
1629: ###############################################################
1630: ###############################################################
1631:
1632: =pod
1633:
1.648 raeburn 1634: =item * &define_excel_formats()
1.180 matthew 1635:
1636: Define some commonly used Excel cell formats.
1637:
1638: Currently supported formats:
1639:
1640: =over 4
1641:
1642: =item header
1643:
1644: =item bold
1645:
1646: =item h1
1647:
1648: =item h2
1649:
1650: =item h3
1651:
1.256 matthew 1652: =item h4
1653:
1654: =item i
1655:
1.180 matthew 1656: =item date
1657:
1658: =back
1659:
1660: Inputs: $workbook
1661:
1662: Returns: $format, a hash reference.
1663:
1664: =cut
1665:
1666: ###############################################################
1667: ###############################################################
1668: sub define_excel_formats {
1669: my ($workbook) = @_;
1670: my $format;
1671: $format->{'header'} = $workbook->add_format(bold => 1,
1672: bottom => 1,
1673: align => 'center');
1674: $format->{'bold'} = $workbook->add_format(bold=>1);
1675: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1676: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1677: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1678: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1679: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1680: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1681: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1682: return $format;
1683: }
1684:
1685: ###############################################################
1686: ###############################################################
1.113 bowersj2 1687:
1688: =pod
1689:
1.648 raeburn 1690: =item * &create_workbook()
1.255 matthew 1691:
1692: Create an Excel worksheet. If it fails, output message on the
1693: request object and return undefs.
1694:
1695: Inputs: Apache request object
1696:
1697: Returns (undef) on failure,
1698: Excel worksheet object, scalar with filename, and formats
1699: from &Apache::loncommon::define_excel_formats on success
1700:
1701: =cut
1702:
1703: ###############################################################
1704: ###############################################################
1705: sub create_workbook {
1706: my ($r) = @_;
1707: #
1708: # Create the excel spreadsheet
1709: my $filename = '/prtspool/'.
1.258 albertel 1710: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1711: time.'_'.rand(1000000000).'.xls';
1712: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1713: if (! defined($workbook)) {
1714: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1715: $r->print(
1716: '<p class="LC_error">'
1717: .&mt('Problems occurred in creating the new Excel file.')
1718: .' '.&mt('This error has been logged.')
1719: .' '.&mt('Please alert your LON-CAPA administrator.')
1720: .'</p>'
1721: );
1.255 matthew 1722: return (undef);
1723: }
1724: #
1725: $workbook->set_tempdir('/home/httpd/perl/tmp');
1726: #
1727: my $format = &Apache::loncommon::define_excel_formats($workbook);
1728: return ($workbook,$filename,$format);
1729: }
1730:
1731: ###############################################################
1732: ###############################################################
1733:
1734: =pod
1735:
1.648 raeburn 1736: =item * &create_text_file()
1.113 bowersj2 1737:
1.542 raeburn 1738: Create a file to write to and eventually make available to the user.
1.256 matthew 1739: If file creation fails, outputs an error message on the request object and
1740: return undefs.
1.113 bowersj2 1741:
1.256 matthew 1742: Inputs: Apache request object, and file suffix
1.113 bowersj2 1743:
1.256 matthew 1744: Returns (undef) on failure,
1745: Filehandle and filename on success.
1.113 bowersj2 1746:
1747: =cut
1748:
1.256 matthew 1749: ###############################################################
1750: ###############################################################
1751: sub create_text_file {
1752: my ($r,$suffix) = @_;
1753: if (! defined($suffix)) { $suffix = 'txt'; };
1754: my $fh;
1755: my $filename = '/prtspool/'.
1.258 albertel 1756: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1757: time.'_'.rand(1000000000).'.'.$suffix;
1758: $fh = Apache::File->new('>/home/httpd'.$filename);
1759: if (! defined($fh)) {
1760: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1761: $r->print(
1762: '<p class="LC_error">'
1763: .&mt('Problems occurred in creating the output file.')
1764: .' '.&mt('This error has been logged.')
1765: .' '.&mt('Please alert your LON-CAPA administrator.')
1766: .'</p>'
1767: );
1.113 bowersj2 1768: }
1.256 matthew 1769: return ($fh,$filename)
1.113 bowersj2 1770: }
1771:
1772:
1.256 matthew 1773: =pod
1.113 bowersj2 1774:
1775: =back
1776:
1777: =cut
1.37 matthew 1778:
1779: ###############################################################
1.33 matthew 1780: ## Home server <option> list generating code ##
1781: ###############################################################
1.35 matthew 1782:
1.169 www 1783: # ------------------------------------------
1784:
1785: sub domain_select {
1786: my ($name,$value,$multiple)=@_;
1787: my %domains=map {
1.514 albertel 1788: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1789: } &Apache::lonnet::all_domains();
1.169 www 1790: if ($multiple) {
1791: $domains{''}=&mt('Any domain');
1.550 albertel 1792: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1793: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1794: } else {
1.550 albertel 1795: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1796: return &select_form($name,$value,\%domains);
1.169 www 1797: }
1798: }
1799:
1.282 albertel 1800: #-------------------------------------------
1801:
1802: =pod
1803:
1.519 raeburn 1804: =head1 Routines for form select boxes
1805:
1806: =over 4
1807:
1.648 raeburn 1808: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1809:
1810: Returns a string containing a <select> element int multiple mode
1811:
1812:
1813: Args:
1814: $name - name of the <select> element
1.506 raeburn 1815: $value - scalar or array ref of values that should already be selected
1.282 albertel 1816: $size - number of rows long the select element is
1.283 albertel 1817: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1818: (shown text should already have been &mt())
1.506 raeburn 1819: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1820:
1.282 albertel 1821: =cut
1822:
1823: #-------------------------------------------
1.169 www 1824: sub multiple_select_form {
1.284 albertel 1825: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1826: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1827: my $output='';
1.191 matthew 1828: if (! defined($size)) {
1829: $size = 4;
1.283 albertel 1830: if (scalar(keys(%$hash))<4) {
1831: $size = scalar(keys(%$hash));
1.191 matthew 1832: }
1833: }
1.734 bisitz 1834: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1835: my @order;
1.506 raeburn 1836: if (ref($order) eq 'ARRAY') {
1837: @order = @{$order};
1838: } else {
1839: @order = sort(keys(%$hash));
1.501 banghart 1840: }
1841: if (exists($$hash{'select_form_order'})) {
1842: @order = @{$$hash{'select_form_order'}};
1843: }
1844:
1.284 albertel 1845: foreach my $key (@order) {
1.356 albertel 1846: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1847: $output.='selected="selected" ' if ($selected{$key});
1848: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1849: }
1850: $output.="</select>\n";
1851: return $output;
1852: }
1853:
1.88 www 1854: #-------------------------------------------
1855:
1856: =pod
1857:
1.970 raeburn 1858: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1859:
1860: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1861: allow a user to select options from a ref to a hash containing:
1862: option_name => displayed text. An optional $onchange can include
1863: a javascript onchange item, e.g., onchange="this.form.submit();"
1864:
1.88 www 1865: See lonrights.pm for an example invocation and use.
1866:
1867: =cut
1868:
1869: #-------------------------------------------
1870: sub select_form {
1.970 raeburn 1871: my ($def,$name,$hashref,$onchange) = @_;
1872: return unless (ref($hashref) eq 'HASH');
1873: if ($onchange) {
1874: $onchange = ' onchange="'.$onchange.'"';
1875: }
1876: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1877: my @keys;
1.970 raeburn 1878: if (exists($hashref->{'select_form_order'})) {
1879: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1880: } else {
1.970 raeburn 1881: @keys=sort(keys(%{$hashref}));
1.128 albertel 1882: }
1.356 albertel 1883: foreach my $key (@keys) {
1884: $selectform.=
1885: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1886: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 1887: ">".$hashref->{$key}."</option>\n";
1.88 www 1888: }
1889: $selectform.="</select>";
1890: return $selectform;
1891: }
1892:
1.475 www 1893: # For display filters
1894:
1895: sub display_filter {
1896: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1897: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1898: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1899: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1900: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1901: '</label></span> <span class="LC_nobreak">'.
1.475 www 1902: &mt('Filter [_1]',
1.477 www 1903: &select_form($env{'form.displayfilter'},
1904: 'displayfilter',
1.970 raeburn 1905: {'currentfolder' => 'Current folder/page',
1.477 www 1906: 'containing' => 'Containing phrase',
1.970 raeburn 1907: 'none' => 'None'})).
1.714 bisitz 1908: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1909: }
1910:
1.167 www 1911: sub gradeleveldescription {
1912: my $gradelevel=shift;
1913: my %gradelevels=(0 => 'Not specified',
1914: 1 => 'Grade 1',
1915: 2 => 'Grade 2',
1916: 3 => 'Grade 3',
1917: 4 => 'Grade 4',
1918: 5 => 'Grade 5',
1919: 6 => 'Grade 6',
1920: 7 => 'Grade 7',
1921: 8 => 'Grade 8',
1922: 9 => 'Grade 9',
1923: 10 => 'Grade 10',
1924: 11 => 'Grade 11',
1925: 12 => 'Grade 12',
1926: 13 => 'Grade 13',
1927: 14 => '100 Level',
1928: 15 => '200 Level',
1929: 16 => '300 Level',
1930: 17 => '400 Level',
1931: 18 => 'Graduate Level');
1932: return &mt($gradelevels{$gradelevel});
1933: }
1934:
1.163 www 1935: sub select_level_form {
1936: my ($deflevel,$name)=@_;
1937: unless ($deflevel) { $deflevel=0; }
1.167 www 1938: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1939: for (my $i=0; $i<=18; $i++) {
1940: $selectform.="<option value=\"$i\" ".
1.253 albertel 1941: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1942: ">".&gradeleveldescription($i)."</option>\n";
1943: }
1944: $selectform.="</select>";
1945: return $selectform;
1.163 www 1946: }
1.167 www 1947:
1.35 matthew 1948: #-------------------------------------------
1949:
1.45 matthew 1950: =pod
1951:
1.910 raeburn 1952: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1953:
1954: Returns a string containing a <select name='$name' size='1'> form to
1955: allow a user to select the domain to preform an operation in.
1956: See loncreateuser.pm for an example invocation and use.
1957:
1.90 www 1958: If the $includeempty flag is set, it also includes an empty choice ("no domain
1959: selected");
1960:
1.743 raeburn 1961: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1962:
1.910 raeburn 1963: 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.
1964:
1965: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 1966:
1.35 matthew 1967: =cut
1968:
1969: #-------------------------------------------
1.34 matthew 1970: sub select_dom_form {
1.910 raeburn 1971: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 1972: if ($onchange) {
1.874 raeburn 1973: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1974: }
1.910 raeburn 1975: my @domains;
1976: if (ref($incdoms) eq 'ARRAY') {
1977: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
1978: } else {
1979: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1980: }
1.90 www 1981: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1982: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1983: foreach my $dom (@domains) {
1984: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1985: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1986: if ($showdomdesc) {
1987: if ($dom ne '') {
1988: my $domdesc = &Apache::lonnet::domain($dom,'description');
1989: if ($domdesc ne '') {
1990: $selectdomain .= ' ('.$domdesc.')';
1991: }
1992: }
1993: }
1994: $selectdomain .= "</option>\n";
1.34 matthew 1995: }
1996: $selectdomain.="</select>";
1997: return $selectdomain;
1998: }
1999:
1.35 matthew 2000: #-------------------------------------------
2001:
1.45 matthew 2002: =pod
2003:
1.648 raeburn 2004: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2005:
1.586 raeburn 2006: input: 4 arguments (two required, two optional) -
2007: $domain - domain of new user
2008: $name - name of form element
2009: $default - Value of 'default' causes a default item to be first
2010: option, and selected by default.
2011: $hide - Value of 'hide' causes hiding of the name of the server,
2012: if 1 server found, or default, if 0 found.
1.594 raeburn 2013: output: returns 2 items:
1.586 raeburn 2014: (a) form element which contains either:
2015: (i) <select name="$name">
2016: <option value="$hostid1">$hostid $servers{$hostid}</option>
2017: <option value="$hostid2">$hostid $servers{$hostid}</option>
2018: </select>
2019: form item if there are multiple library servers in $domain, or
2020: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2021: if there is only one library server in $domain.
2022:
2023: (b) number of library servers found.
2024:
2025: See loncreateuser.pm for example of use.
1.35 matthew 2026:
2027: =cut
2028:
2029: #-------------------------------------------
1.586 raeburn 2030: sub home_server_form_item {
2031: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2032: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2033: my $result;
2034: my $numlib = keys(%servers);
2035: if ($numlib > 1) {
2036: $result .= '<select name="'.$name.'" />'."\n";
2037: if ($default) {
1.804 bisitz 2038: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2039: '</option>'."\n";
2040: }
2041: foreach my $hostid (sort(keys(%servers))) {
2042: $result.= '<option value="'.$hostid.'">'.
2043: $hostid.' '.$servers{$hostid}."</option>\n";
2044: }
2045: $result .= '</select>'."\n";
2046: } elsif ($numlib == 1) {
2047: my $hostid;
2048: foreach my $item (keys(%servers)) {
2049: $hostid = $item;
2050: }
2051: $result .= '<input type="hidden" name="'.$name.'" value="'.
2052: $hostid.'" />';
2053: if (!$hide) {
2054: $result .= $hostid.' '.$servers{$hostid};
2055: }
2056: $result .= "\n";
2057: } elsif ($default) {
2058: $result .= '<input type="hidden" name="'.$name.
2059: '" value="default" />';
2060: if (!$hide) {
2061: $result .= &mt('default');
2062: }
2063: $result .= "\n";
1.33 matthew 2064: }
1.586 raeburn 2065: return ($result,$numlib);
1.33 matthew 2066: }
1.112 bowersj2 2067:
2068: =pod
2069:
1.534 albertel 2070: =back
2071:
1.112 bowersj2 2072: =cut
1.87 matthew 2073:
2074: ###############################################################
1.112 bowersj2 2075: ## Decoding User Agent ##
1.87 matthew 2076: ###############################################################
2077:
2078: =pod
2079:
1.112 bowersj2 2080: =head1 Decoding the User Agent
2081:
2082: =over 4
2083:
2084: =item * &decode_user_agent()
1.87 matthew 2085:
2086: Inputs: $r
2087:
2088: Outputs:
2089:
2090: =over 4
2091:
1.112 bowersj2 2092: =item * $httpbrowser
1.87 matthew 2093:
1.112 bowersj2 2094: =item * $clientbrowser
1.87 matthew 2095:
1.112 bowersj2 2096: =item * $clientversion
1.87 matthew 2097:
1.112 bowersj2 2098: =item * $clientmathml
1.87 matthew 2099:
1.112 bowersj2 2100: =item * $clientunicode
1.87 matthew 2101:
1.112 bowersj2 2102: =item * $clientos
1.87 matthew 2103:
2104: =back
2105:
1.157 matthew 2106: =back
2107:
1.87 matthew 2108: =cut
2109:
2110: ###############################################################
2111: ###############################################################
2112: sub decode_user_agent {
1.247 albertel 2113: my ($r)=@_;
1.87 matthew 2114: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2115: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2116: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2117: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2118: my $clientbrowser='unknown';
2119: my $clientversion='0';
2120: my $clientmathml='';
2121: my $clientunicode='0';
2122: for (my $i=0;$i<=$#browsertype;$i++) {
2123: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2124: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2125: $clientbrowser=$bname;
2126: $httpbrowser=~/$vreg/i;
2127: $clientversion=$1;
2128: $clientmathml=($clientversion>=$minv);
2129: $clientunicode=($clientversion>=$univ);
2130: }
2131: }
2132: my $clientos='unknown';
2133: if (($httpbrowser=~/linux/i) ||
2134: ($httpbrowser=~/unix/i) ||
2135: ($httpbrowser=~/ux/i) ||
2136: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2137: if (($httpbrowser=~/vax/i) ||
2138: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2139: if ($httpbrowser=~/next/i) { $clientos='next'; }
2140: if (($httpbrowser=~/mac/i) ||
2141: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2142: if ($httpbrowser=~/win/i) { $clientos='win'; }
2143: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2144: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2145: $clientunicode,$clientos,);
2146: }
2147:
1.32 matthew 2148: ###############################################################
2149: ## Authentication changing form generation subroutines ##
2150: ###############################################################
2151: ##
2152: ## All of the authform_xxxxxxx subroutines take their inputs in a
2153: ## hash, and have reasonable default values.
2154: ##
2155: ## formname = the name given in the <form> tag.
1.35 matthew 2156: #-------------------------------------------
2157:
1.45 matthew 2158: =pod
2159:
1.112 bowersj2 2160: =head1 Authentication Routines
2161:
2162: =over 4
2163:
1.648 raeburn 2164: =item * &authform_xxxxxx()
1.35 matthew 2165:
2166: The authform_xxxxxx subroutines provide javascript and html forms which
2167: handle some of the conveniences required for authentication forms.
2168: This is not an optimal method, but it works.
2169:
2170: =over 4
2171:
1.112 bowersj2 2172: =item * authform_header
1.35 matthew 2173:
1.112 bowersj2 2174: =item * authform_authorwarning
1.35 matthew 2175:
1.112 bowersj2 2176: =item * authform_nochange
1.35 matthew 2177:
1.112 bowersj2 2178: =item * authform_kerberos
1.35 matthew 2179:
1.112 bowersj2 2180: =item * authform_internal
1.35 matthew 2181:
1.112 bowersj2 2182: =item * authform_filesystem
1.35 matthew 2183:
2184: =back
2185:
1.648 raeburn 2186: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2187:
1.35 matthew 2188: =cut
2189:
2190: #-------------------------------------------
1.32 matthew 2191: sub authform_header{
2192: my %in = (
2193: formname => 'cu',
1.80 albertel 2194: kerb_def_dom => '',
1.32 matthew 2195: @_,
2196: );
2197: $in{'formname'} = 'document.' . $in{'formname'};
2198: my $result='';
1.80 albertel 2199:
2200: #---------------------------------------------- Code for upper case translation
2201: my $Javascript_toUpperCase;
2202: unless ($in{kerb_def_dom}) {
2203: $Javascript_toUpperCase =<<"END";
2204: switch (choice) {
2205: case 'krb': currentform.elements[choicearg].value =
2206: currentform.elements[choicearg].value.toUpperCase();
2207: break;
2208: default:
2209: }
2210: END
2211: } else {
2212: $Javascript_toUpperCase = "";
2213: }
2214:
1.165 raeburn 2215: my $radioval = "'nochange'";
1.591 raeburn 2216: if (defined($in{'curr_authtype'})) {
2217: if ($in{'curr_authtype'} ne '') {
2218: $radioval = "'".$in{'curr_authtype'}."arg'";
2219: }
1.174 matthew 2220: }
1.165 raeburn 2221: my $argfield = 'null';
1.591 raeburn 2222: if (defined($in{'mode'})) {
1.165 raeburn 2223: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2224: if (defined($in{'curr_autharg'})) {
2225: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2226: $argfield = "'$in{'curr_autharg'}'";
2227: }
2228: }
2229: }
2230: }
2231:
1.32 matthew 2232: $result.=<<"END";
2233: var current = new Object();
1.165 raeburn 2234: current.radiovalue = $radioval;
2235: current.argfield = $argfield;
1.32 matthew 2236:
2237: function changed_radio(choice,currentform) {
2238: var choicearg = choice + 'arg';
2239: // If a radio button in changed, we need to change the argfield
2240: if (current.radiovalue != choice) {
2241: current.radiovalue = choice;
2242: if (current.argfield != null) {
2243: currentform.elements[current.argfield].value = '';
2244: }
2245: if (choice == 'nochange') {
2246: current.argfield = null;
2247: } else {
2248: current.argfield = choicearg;
2249: switch(choice) {
2250: case 'krb':
2251: currentform.elements[current.argfield].value =
2252: "$in{'kerb_def_dom'}";
2253: break;
2254: default:
2255: break;
2256: }
2257: }
2258: }
2259: return;
2260: }
1.22 www 2261:
1.32 matthew 2262: function changed_text(choice,currentform) {
2263: var choicearg = choice + 'arg';
2264: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2265: $Javascript_toUpperCase
1.32 matthew 2266: // clear old field
2267: if ((current.argfield != choicearg) && (current.argfield != null)) {
2268: currentform.elements[current.argfield].value = '';
2269: }
2270: current.argfield = choicearg;
2271: }
2272: set_auth_radio_buttons(choice,currentform);
2273: return;
1.20 www 2274: }
1.32 matthew 2275:
2276: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2277: var numauthchoices = currentform.login.length;
2278: if (typeof numauthchoices == "undefined") {
2279: return;
2280: }
1.32 matthew 2281: var i=0;
1.986 raeburn 2282: while (i < numauthchoices) {
1.32 matthew 2283: if (currentform.login[i].value == newvalue) { break; }
2284: i++;
2285: }
1.986 raeburn 2286: if (i == numauthchoices) {
1.32 matthew 2287: return;
2288: }
2289: current.radiovalue = newvalue;
2290: currentform.login[i].checked = true;
2291: return;
2292: }
2293: END
2294: return $result;
2295: }
2296:
2297: sub authform_authorwarning{
2298: my $result='';
1.144 matthew 2299: $result='<i>'.
2300: &mt('As a general rule, only authors or co-authors should be '.
2301: 'filesystem authenticated '.
2302: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2303: return $result;
2304: }
2305:
2306: sub authform_nochange{
2307: my %in = (
2308: formname => 'document.cu',
2309: kerb_def_dom => 'MSU.EDU',
2310: @_,
2311: );
1.586 raeburn 2312: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2313: my $result;
2314: if (keys(%can_assign) == 0) {
2315: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2316: } else {
2317: $result = '<label>'.&mt('[_1] Do not change login data',
2318: '<input type="radio" name="login" value="nochange" '.
2319: 'checked="checked" onclick="'.
1.281 albertel 2320: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2321: '</label>';
1.586 raeburn 2322: }
1.32 matthew 2323: return $result;
2324: }
2325:
1.591 raeburn 2326: sub authform_kerberos {
1.32 matthew 2327: my %in = (
2328: formname => 'document.cu',
2329: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2330: kerb_def_auth => 'krb4',
1.32 matthew 2331: @_,
2332: );
1.586 raeburn 2333: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2334: $autharg,$jscall);
2335: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2336: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2337: $check5 = ' checked="checked"';
1.80 albertel 2338: } else {
1.772 bisitz 2339: $check4 = ' checked="checked"';
1.80 albertel 2340: }
1.165 raeburn 2341: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2342: if (defined($in{'curr_authtype'})) {
2343: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2344: $krbcheck = ' checked="checked"';
1.623 raeburn 2345: if (defined($in{'mode'})) {
2346: if ($in{'mode'} eq 'modifyuser') {
2347: $krbcheck = '';
2348: }
2349: }
1.591 raeburn 2350: if (defined($in{'curr_kerb_ver'})) {
2351: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2352: $check5 = ' checked="checked"';
1.591 raeburn 2353: $check4 = '';
2354: } else {
1.772 bisitz 2355: $check4 = ' checked="checked"';
1.591 raeburn 2356: $check5 = '';
2357: }
1.586 raeburn 2358: }
1.591 raeburn 2359: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2360: $krbarg = $in{'curr_autharg'};
2361: }
1.586 raeburn 2362: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2363: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2364: $result =
2365: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2366: $in{'curr_autharg'},$krbver);
2367: } else {
2368: $result =
2369: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2370: }
2371: return $result;
2372: }
2373: }
2374: } else {
2375: if ($authnum == 1) {
1.784 bisitz 2376: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2377: }
2378: }
1.586 raeburn 2379: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2380: return;
1.587 raeburn 2381: } elsif ($authtype eq '') {
1.591 raeburn 2382: if (defined($in{'mode'})) {
1.587 raeburn 2383: if ($in{'mode'} eq 'modifycourse') {
2384: if ($authnum == 1) {
1.784 bisitz 2385: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2386: }
2387: }
2388: }
1.586 raeburn 2389: }
2390: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2391: if ($authtype eq '') {
2392: $authtype = '<input type="radio" name="login" value="krb" '.
2393: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2394: $krbcheck.' />';
2395: }
2396: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2397: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2398: $in{'curr_authtype'} eq 'krb5') ||
2399: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2400: $in{'curr_authtype'} eq 'krb4')) {
2401: $result .= &mt
1.144 matthew 2402: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2403: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2404: '<label>'.$authtype,
1.281 albertel 2405: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2406: 'value="'.$krbarg.'" '.
1.144 matthew 2407: 'onchange="'.$jscall.'" />',
1.281 albertel 2408: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2409: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2410: '</label>');
1.586 raeburn 2411: } elsif ($can_assign{'krb4'}) {
2412: $result .= &mt
2413: ('[_1] Kerberos authenticated with domain [_2] '.
2414: '[_3] Version 4 [_4]',
2415: '<label>'.$authtype,
2416: '</label><input type="text" size="10" name="krbarg" '.
2417: 'value="'.$krbarg.'" '.
2418: 'onchange="'.$jscall.'" />',
2419: '<label><input type="hidden" name="krbver" value="4" />',
2420: '</label>');
2421: } elsif ($can_assign{'krb5'}) {
2422: $result .= &mt
2423: ('[_1] Kerberos authenticated with domain [_2] '.
2424: '[_3] Version 5 [_4]',
2425: '<label>'.$authtype,
2426: '</label><input type="text" size="10" name="krbarg" '.
2427: 'value="'.$krbarg.'" '.
2428: 'onchange="'.$jscall.'" />',
2429: '<label><input type="hidden" name="krbver" value="5" />',
2430: '</label>');
2431: }
1.32 matthew 2432: return $result;
2433: }
2434:
2435: sub authform_internal{
1.586 raeburn 2436: my %in = (
1.32 matthew 2437: formname => 'document.cu',
2438: kerb_def_dom => 'MSU.EDU',
2439: @_,
2440: );
1.586 raeburn 2441: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2442: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2443: if (defined($in{'curr_authtype'})) {
2444: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2445: if ($can_assign{'int'}) {
1.772 bisitz 2446: $intcheck = 'checked="checked" ';
1.623 raeburn 2447: if (defined($in{'mode'})) {
2448: if ($in{'mode'} eq 'modifyuser') {
2449: $intcheck = '';
2450: }
2451: }
1.591 raeburn 2452: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2453: $intarg = $in{'curr_autharg'};
2454: }
2455: } else {
2456: $result = &mt('Currently internally authenticated.');
2457: return $result;
1.165 raeburn 2458: }
2459: }
1.586 raeburn 2460: } else {
2461: if ($authnum == 1) {
1.784 bisitz 2462: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2463: }
2464: }
2465: if (!$can_assign{'int'}) {
2466: return;
1.587 raeburn 2467: } elsif ($authtype eq '') {
1.591 raeburn 2468: if (defined($in{'mode'})) {
1.587 raeburn 2469: if ($in{'mode'} eq 'modifycourse') {
2470: if ($authnum == 1) {
1.784 bisitz 2471: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2472: }
2473: }
2474: }
1.165 raeburn 2475: }
1.586 raeburn 2476: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2477: if ($authtype eq '') {
2478: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2479: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2480: }
1.605 bisitz 2481: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2482: $intarg.'" onchange="'.$jscall.'" />';
2483: $result = &mt
1.144 matthew 2484: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2485: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2486: $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 2487: return $result;
2488: }
2489:
2490: sub authform_local{
2491: my %in = (
2492: formname => 'document.cu',
2493: kerb_def_dom => 'MSU.EDU',
2494: @_,
2495: );
1.586 raeburn 2496: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2497: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2498: if (defined($in{'curr_authtype'})) {
2499: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2500: if ($can_assign{'loc'}) {
1.772 bisitz 2501: $loccheck = 'checked="checked" ';
1.623 raeburn 2502: if (defined($in{'mode'})) {
2503: if ($in{'mode'} eq 'modifyuser') {
2504: $loccheck = '';
2505: }
2506: }
1.591 raeburn 2507: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2508: $locarg = $in{'curr_autharg'};
2509: }
2510: } else {
2511: $result = &mt('Currently using local (institutional) authentication.');
2512: return $result;
1.165 raeburn 2513: }
2514: }
1.586 raeburn 2515: } else {
2516: if ($authnum == 1) {
1.784 bisitz 2517: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2518: }
2519: }
2520: if (!$can_assign{'loc'}) {
2521: return;
1.587 raeburn 2522: } elsif ($authtype eq '') {
1.591 raeburn 2523: if (defined($in{'mode'})) {
1.587 raeburn 2524: if ($in{'mode'} eq 'modifycourse') {
2525: if ($authnum == 1) {
1.784 bisitz 2526: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2527: }
2528: }
2529: }
1.165 raeburn 2530: }
1.586 raeburn 2531: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2532: if ($authtype eq '') {
2533: $authtype = '<input type="radio" name="login" value="loc" '.
2534: $loccheck.' onchange="'.$jscall.'" onclick="'.
2535: $jscall.'" />';
2536: }
2537: $autharg = '<input type="text" size="10" name="locarg" value="'.
2538: $locarg.'" onchange="'.$jscall.'" />';
2539: $result = &mt('[_1] Local Authentication with argument [_2]',
2540: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2541: return $result;
2542: }
2543:
2544: sub authform_filesystem{
2545: my %in = (
2546: formname => 'document.cu',
2547: kerb_def_dom => 'MSU.EDU',
2548: @_,
2549: );
1.586 raeburn 2550: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2551: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2552: if (defined($in{'curr_authtype'})) {
2553: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2554: if ($can_assign{'fsys'}) {
1.772 bisitz 2555: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2556: if (defined($in{'mode'})) {
2557: if ($in{'mode'} eq 'modifyuser') {
2558: $fsyscheck = '';
2559: }
2560: }
1.586 raeburn 2561: } else {
2562: $result = &mt('Currently Filesystem Authenticated.');
2563: return $result;
2564: }
2565: }
2566: } else {
2567: if ($authnum == 1) {
1.784 bisitz 2568: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2569: }
2570: }
2571: if (!$can_assign{'fsys'}) {
2572: return;
1.587 raeburn 2573: } elsif ($authtype eq '') {
1.591 raeburn 2574: if (defined($in{'mode'})) {
1.587 raeburn 2575: if ($in{'mode'} eq 'modifycourse') {
2576: if ($authnum == 1) {
1.784 bisitz 2577: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2578: }
2579: }
2580: }
1.586 raeburn 2581: }
2582: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2583: if ($authtype eq '') {
2584: $authtype = '<input type="radio" name="login" value="fsys" '.
2585: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2586: $jscall.'" />';
2587: }
2588: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2589: ' onchange="'.$jscall.'" />';
2590: $result = &mt
1.144 matthew 2591: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2592: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2593: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2594: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2595: 'onchange="'.$jscall.'" />');
1.32 matthew 2596: return $result;
2597: }
2598:
1.586 raeburn 2599: sub get_assignable_auth {
2600: my ($dom) = @_;
2601: if ($dom eq '') {
2602: $dom = $env{'request.role.domain'};
2603: }
2604: my %can_assign = (
2605: krb4 => 1,
2606: krb5 => 1,
2607: int => 1,
2608: loc => 1,
2609: );
2610: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2611: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2612: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2613: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2614: my $context;
2615: if ($env{'request.role'} =~ /^au/) {
2616: $context = 'author';
2617: } elsif ($env{'request.role'} =~ /^dc/) {
2618: $context = 'domain';
2619: } elsif ($env{'request.course.id'}) {
2620: $context = 'course';
2621: }
2622: if ($context) {
2623: if (ref($authhash->{$context}) eq 'HASH') {
2624: %can_assign = %{$authhash->{$context}};
2625: }
2626: }
2627: }
2628: }
2629: my $authnum = 0;
2630: foreach my $key (keys(%can_assign)) {
2631: if ($can_assign{$key}) {
2632: $authnum ++;
2633: }
2634: }
2635: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2636: $authnum --;
2637: }
2638: return ($authnum,%can_assign);
2639: }
2640:
1.80 albertel 2641: ###############################################################
2642: ## Get Kerberos Defaults for Domain ##
2643: ###############################################################
2644: ##
2645: ## Returns default kerberos version and an associated argument
2646: ## as listed in file domain.tab. If not listed, provides
2647: ## appropriate default domain and kerberos version.
2648: ##
2649: #-------------------------------------------
2650:
2651: =pod
2652:
1.648 raeburn 2653: =item * &get_kerberos_defaults()
1.80 albertel 2654:
2655: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2656: version and domain. If not found, it defaults to version 4 and the
2657: domain of the server.
1.80 albertel 2658:
1.648 raeburn 2659: =over 4
2660:
1.80 albertel 2661: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2662:
1.648 raeburn 2663: =back
2664:
2665: =back
2666:
1.80 albertel 2667: =cut
2668:
2669: #-------------------------------------------
2670: sub get_kerberos_defaults {
2671: my $domain=shift;
1.641 raeburn 2672: my ($krbdef,$krbdefdom);
2673: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2674: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2675: $krbdef = $domdefaults{'auth_def'};
2676: $krbdefdom = $domdefaults{'auth_arg_def'};
2677: } else {
1.80 albertel 2678: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2679: my $krbdefdom=$1;
2680: $krbdefdom=~tr/a-z/A-Z/;
2681: $krbdef = "krb4";
2682: }
2683: return ($krbdef,$krbdefdom);
2684: }
1.112 bowersj2 2685:
1.32 matthew 2686:
1.46 matthew 2687: ###############################################################
2688: ## Thesaurus Functions ##
2689: ###############################################################
1.20 www 2690:
1.46 matthew 2691: =pod
1.20 www 2692:
1.112 bowersj2 2693: =head1 Thesaurus Functions
2694:
2695: =over 4
2696:
1.648 raeburn 2697: =item * &initialize_keywords()
1.46 matthew 2698:
2699: Initializes the package variable %Keywords if it is empty. Uses the
2700: package variable $thesaurus_db_file.
2701:
2702: =cut
2703:
2704: ###################################################
2705:
2706: sub initialize_keywords {
2707: return 1 if (scalar keys(%Keywords));
2708: # If we are here, %Keywords is empty, so fill it up
2709: # Make sure the file we need exists...
2710: if (! -e $thesaurus_db_file) {
2711: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2712: " failed because it does not exist");
2713: return 0;
2714: }
2715: # Set up the hash as a database
2716: my %thesaurus_db;
2717: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2718: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2719: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2720: $thesaurus_db_file);
2721: return 0;
2722: }
2723: # Get the average number of appearances of a word.
2724: my $avecount = $thesaurus_db{'average.count'};
2725: # Put keywords (those that appear > average) into %Keywords
2726: while (my ($word,$data)=each (%thesaurus_db)) {
2727: my ($count,undef) = split /:/,$data;
2728: $Keywords{$word}++ if ($count > $avecount);
2729: }
2730: untie %thesaurus_db;
2731: # Remove special values from %Keywords.
1.356 albertel 2732: foreach my $value ('total.count','average.count') {
2733: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2734: }
1.46 matthew 2735: return 1;
2736: }
2737:
2738: ###################################################
2739:
2740: =pod
2741:
1.648 raeburn 2742: =item * &keyword($word)
1.46 matthew 2743:
2744: Returns true if $word is a keyword. A keyword is a word that appears more
2745: than the average number of times in the thesaurus database. Calls
2746: &initialize_keywords
2747:
2748: =cut
2749:
2750: ###################################################
1.20 www 2751:
2752: sub keyword {
1.46 matthew 2753: return if (!&initialize_keywords());
2754: my $word=lc(shift());
2755: $word=~s/\W//g;
2756: return exists($Keywords{$word});
1.20 www 2757: }
1.46 matthew 2758:
2759: ###############################################################
2760:
2761: =pod
1.20 www 2762:
1.648 raeburn 2763: =item * &get_related_words()
1.46 matthew 2764:
1.160 matthew 2765: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2766: an array of words. If the keyword is not in the thesaurus, an empty array
2767: will be returned. The order of the words returned is determined by the
2768: database which holds them.
2769:
2770: Uses global $thesaurus_db_file.
2771:
2772: =cut
2773:
2774: ###############################################################
2775: sub get_related_words {
2776: my $keyword = shift;
2777: my %thesaurus_db;
2778: if (! -e $thesaurus_db_file) {
2779: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2780: "failed because the file does not exist");
2781: return ();
2782: }
2783: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2784: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2785: return ();
2786: }
2787: my @Words=();
1.429 www 2788: my $count=0;
1.46 matthew 2789: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2790: # The first element is the number of times
2791: # the word appears. We do not need it now.
1.429 www 2792: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2793: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2794: my $threshold=$mostfrequentcount/10;
2795: foreach my $possibleword (@RelatedWords) {
2796: my ($word,$wordcount)=split(/\,/,$possibleword);
2797: if ($wordcount>$threshold) {
2798: push(@Words,$word);
2799: $count++;
2800: if ($count>10) { last; }
2801: }
1.20 www 2802: }
2803: }
1.46 matthew 2804: untie %thesaurus_db;
2805: return @Words;
1.14 harris41 2806: }
1.46 matthew 2807:
1.112 bowersj2 2808: =pod
2809:
2810: =back
2811:
2812: =cut
1.61 www 2813:
2814: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2815: =pod
2816:
1.112 bowersj2 2817: =head1 User Name Functions
2818:
2819: =over 4
2820:
1.648 raeburn 2821: =item * &plainname($uname,$udom,$first)
1.81 albertel 2822:
1.112 bowersj2 2823: Takes a users logon name and returns it as a string in
1.226 albertel 2824: "first middle last generation" form
2825: if $first is set to 'lastname' then it returns it as
2826: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2827:
2828: =cut
1.61 www 2829:
1.295 www 2830:
1.81 albertel 2831: ###############################################################
1.61 www 2832: sub plainname {
1.226 albertel 2833: my ($uname,$udom,$first)=@_;
1.537 albertel 2834: return if (!defined($uname) || !defined($udom));
1.295 www 2835: my %names=&getnames($uname,$udom);
1.226 albertel 2836: my $name=&Apache::lonnet::format_name($names{'firstname'},
2837: $names{'middlename'},
2838: $names{'lastname'},
2839: $names{'generation'},$first);
2840: $name=~s/^\s+//;
1.62 www 2841: $name=~s/\s+$//;
2842: $name=~s/\s+/ /g;
1.353 albertel 2843: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2844: return $name;
1.61 www 2845: }
1.66 www 2846:
2847: # -------------------------------------------------------------------- Nickname
1.81 albertel 2848: =pod
2849:
1.648 raeburn 2850: =item * &nickname($uname,$udom)
1.81 albertel 2851:
2852: Gets a users name and returns it as a string as
2853:
2854: ""nickname""
1.66 www 2855:
1.81 albertel 2856: if the user has a nickname or
2857:
2858: "first middle last generation"
2859:
2860: if the user does not
2861:
2862: =cut
1.66 www 2863:
2864: sub nickname {
2865: my ($uname,$udom)=@_;
1.537 albertel 2866: return if (!defined($uname) || !defined($udom));
1.295 www 2867: my %names=&getnames($uname,$udom);
1.68 albertel 2868: my $name=$names{'nickname'};
1.66 www 2869: if ($name) {
2870: $name='"'.$name.'"';
2871: } else {
2872: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2873: $names{'lastname'}.' '.$names{'generation'};
2874: $name=~s/\s+$//;
2875: $name=~s/\s+/ /g;
2876: }
2877: return $name;
2878: }
2879:
1.295 www 2880: sub getnames {
2881: my ($uname,$udom)=@_;
1.537 albertel 2882: return if (!defined($uname) || !defined($udom));
1.433 albertel 2883: if ($udom eq 'public' && $uname eq 'public') {
2884: return ('lastname' => &mt('Public'));
2885: }
1.295 www 2886: my $id=$uname.':'.$udom;
2887: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2888: if ($cached) {
2889: return %{$names};
2890: } else {
2891: my %loadnames=&Apache::lonnet::get('environment',
2892: ['firstname','middlename','lastname','generation','nickname'],
2893: $udom,$uname);
2894: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2895: return %loadnames;
2896: }
2897: }
1.61 www 2898:
1.542 raeburn 2899: # -------------------------------------------------------------------- getemails
1.648 raeburn 2900:
1.542 raeburn 2901: =pod
2902:
1.648 raeburn 2903: =item * &getemails($uname,$udom)
1.542 raeburn 2904:
2905: Gets a user's email information and returns it as a hash with keys:
2906: notification, critnotification, permanentemail
2907:
2908: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2909: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2910:
1.648 raeburn 2911:
1.542 raeburn 2912: =cut
2913:
1.648 raeburn 2914:
1.466 albertel 2915: sub getemails {
2916: my ($uname,$udom)=@_;
2917: if ($udom eq 'public' && $uname eq 'public') {
2918: return;
2919: }
1.467 www 2920: if (!$udom) { $udom=$env{'user.domain'}; }
2921: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2922: my $id=$uname.':'.$udom;
2923: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2924: if ($cached) {
2925: return %{$names};
2926: } else {
2927: my %loadnames=&Apache::lonnet::get('environment',
2928: ['notification','critnotification',
2929: 'permanentemail'],
2930: $udom,$uname);
2931: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2932: return %loadnames;
2933: }
2934: }
2935:
1.551 albertel 2936: sub flush_email_cache {
2937: my ($uname,$udom)=@_;
2938: if (!$udom) { $udom =$env{'user.domain'}; }
2939: if (!$uname) { $uname=$env{'user.name'}; }
2940: return if ($udom eq 'public' && $uname eq 'public');
2941: my $id=$uname.':'.$udom;
2942: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2943: }
2944:
1.728 raeburn 2945: # -------------------------------------------------------------------- getlangs
2946:
2947: =pod
2948:
2949: =item * &getlangs($uname,$udom)
2950:
2951: Gets a user's language preference and returns it as a hash with key:
2952: language.
2953:
2954: =cut
2955:
2956:
2957: sub getlangs {
2958: my ($uname,$udom) = @_;
2959: if (!$udom) { $udom =$env{'user.domain'}; }
2960: if (!$uname) { $uname=$env{'user.name'}; }
2961: my $id=$uname.':'.$udom;
2962: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2963: if ($cached) {
2964: return %{$langs};
2965: } else {
2966: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2967: $udom,$uname);
2968: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2969: return %loadlangs;
2970: }
2971: }
2972:
2973: sub flush_langs_cache {
2974: my ($uname,$udom)=@_;
2975: if (!$udom) { $udom =$env{'user.domain'}; }
2976: if (!$uname) { $uname=$env{'user.name'}; }
2977: return if ($udom eq 'public' && $uname eq 'public');
2978: my $id=$uname.':'.$udom;
2979: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2980: }
2981:
1.61 www 2982: # ------------------------------------------------------------------ Screenname
1.81 albertel 2983:
2984: =pod
2985:
1.648 raeburn 2986: =item * &screenname($uname,$udom)
1.81 albertel 2987:
2988: Gets a users screenname and returns it as a string
2989:
2990: =cut
1.61 www 2991:
2992: sub screenname {
2993: my ($uname,$udom)=@_;
1.258 albertel 2994: if ($uname eq $env{'user.name'} &&
2995: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2996: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2997: return $names{'screenname'};
1.62 www 2998: }
2999:
1.212 albertel 3000:
1.802 bisitz 3001: # ------------------------------------------------------------- Confirm Wrapper
3002: =pod
3003:
3004: =item confirmwrapper
3005:
3006: Wrap messages about completion of operation in box
3007:
3008: =cut
3009:
3010: sub confirmwrapper {
3011: my ($message)=@_;
3012: if ($message) {
3013: return "\n".'<div class="LC_confirm_box">'."\n"
3014: .$message."\n"
3015: .'</div>'."\n";
3016: } else {
3017: return $message;
3018: }
3019: }
3020:
1.62 www 3021: # ------------------------------------------------------------- Message Wrapper
3022:
3023: sub messagewrapper {
1.369 www 3024: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3025: return
1.441 albertel 3026: '<a href="/adm/email?compose=individual&'.
3027: 'recname='.$username.'&recdom='.$domain.
3028: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3029: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3030: }
1.802 bisitz 3031:
1.74 www 3032: # --------------------------------------------------------------- Notes Wrapper
3033:
3034: sub noteswrapper {
3035: my ($link,$un,$do)=@_;
3036: return
1.896 amueller 3037: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3038: }
1.802 bisitz 3039:
1.62 www 3040: # ------------------------------------------------------------- Aboutme Wrapper
3041:
3042: sub aboutmewrapper {
1.166 www 3043: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3044: if (!defined($username) && !defined($domain)) {
3045: return;
3046: }
1.892 amueller 3047: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3048: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3049: }
3050:
3051: # ------------------------------------------------------------ Syllabus Wrapper
3052:
3053: sub syllabuswrapper {
1.707 bisitz 3054: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3055: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3056: }
1.14 harris41 3057:
1.802 bisitz 3058: # -----------------------------------------------------------------------------
3059:
1.208 matthew 3060: sub track_student_link {
1.887 raeburn 3061: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3062: my $link ="/adm/trackstudent?";
1.208 matthew 3063: my $title = 'View recent activity';
3064: if (defined($sname) && $sname !~ /^\s*$/ &&
3065: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3066: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3067: $title .= ' of this student';
1.268 albertel 3068: }
1.208 matthew 3069: if (defined($target) && $target !~ /^\s*$/) {
3070: $target = qq{target="$target"};
3071: } else {
3072: $target = '';
3073: }
1.268 albertel 3074: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3075: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3076: $title = &mt($title);
3077: $linktext = &mt($linktext);
1.448 albertel 3078: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3079: &help_open_topic('View_recent_activity');
1.208 matthew 3080: }
3081:
1.781 raeburn 3082: sub slot_reservations_link {
3083: my ($linktext,$sname,$sdom,$target) = @_;
3084: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3085: my $title = 'View slot reservation history';
3086: if (defined($sname) && $sname !~ /^\s*$/ &&
3087: defined($sdom) && $sdom !~ /^\s*$/) {
3088: $link .= "&uname=$sname&udom=$sdom";
3089: $title .= ' of this student';
3090: }
3091: if (defined($target) && $target !~ /^\s*$/) {
3092: $target = qq{target="$target"};
3093: } else {
3094: $target = '';
3095: }
3096: $title = &mt($title);
3097: $linktext = &mt($linktext);
3098: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3099: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3100:
3101: }
3102:
1.508 www 3103: # ===================================================== Display a student photo
3104:
3105:
1.509 albertel 3106: sub student_image_tag {
1.508 www 3107: my ($domain,$user)=@_;
3108: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3109: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3110: return '<img src="'.$imgsrc.'" align="right" />';
3111: } else {
3112: return '';
3113: }
3114: }
3115:
1.112 bowersj2 3116: =pod
3117:
3118: =back
3119:
3120: =head1 Access .tab File Data
3121:
3122: =over 4
3123:
1.648 raeburn 3124: =item * &languageids()
1.112 bowersj2 3125:
3126: returns list of all language ids
3127:
3128: =cut
3129:
1.14 harris41 3130: sub languageids {
1.16 harris41 3131: return sort(keys(%language));
1.14 harris41 3132: }
3133:
1.112 bowersj2 3134: =pod
3135:
1.648 raeburn 3136: =item * &languagedescription()
1.112 bowersj2 3137:
3138: returns description of a specified language id
3139:
3140: =cut
3141:
1.14 harris41 3142: sub languagedescription {
1.125 www 3143: my $code=shift;
3144: return ($supported_language{$code}?'* ':'').
3145: $language{$code}.
1.126 www 3146: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3147: }
3148:
3149: sub plainlanguagedescription {
3150: my $code=shift;
3151: return $language{$code};
3152: }
3153:
3154: sub supportedlanguagecode {
3155: my $code=shift;
3156: return $supported_language{$code};
1.97 www 3157: }
3158:
1.112 bowersj2 3159: =pod
3160:
1.648 raeburn 3161: =item * ©rightids()
1.112 bowersj2 3162:
3163: returns list of all copyrights
3164:
3165: =cut
3166:
3167: sub copyrightids {
3168: return sort(keys(%cprtag));
3169: }
3170:
3171: =pod
3172:
1.648 raeburn 3173: =item * ©rightdescription()
1.112 bowersj2 3174:
3175: returns description of a specified copyright id
3176:
3177: =cut
3178:
3179: sub copyrightdescription {
1.166 www 3180: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3181: }
1.197 matthew 3182:
3183: =pod
3184:
1.648 raeburn 3185: =item * &source_copyrightids()
1.192 taceyjo1 3186:
3187: returns list of all source copyrights
3188:
3189: =cut
3190:
3191: sub source_copyrightids {
3192: return sort(keys(%scprtag));
3193: }
3194:
3195: =pod
3196:
1.648 raeburn 3197: =item * &source_copyrightdescription()
1.192 taceyjo1 3198:
3199: returns description of a specified source copyright id
3200:
3201: =cut
3202:
3203: sub source_copyrightdescription {
3204: return &mt($scprtag{shift(@_)});
3205: }
1.112 bowersj2 3206:
3207: =pod
3208:
1.648 raeburn 3209: =item * &filecategories()
1.112 bowersj2 3210:
3211: returns list of all file categories
3212:
3213: =cut
3214:
3215: sub filecategories {
3216: return sort(keys(%category_extensions));
3217: }
3218:
3219: =pod
3220:
1.648 raeburn 3221: =item * &filecategorytypes()
1.112 bowersj2 3222:
3223: returns list of file types belonging to a given file
3224: category
3225:
3226: =cut
3227:
3228: sub filecategorytypes {
1.356 albertel 3229: my ($cat) = @_;
3230: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3231: }
3232:
3233: =pod
3234:
1.648 raeburn 3235: =item * &fileembstyle()
1.112 bowersj2 3236:
3237: returns embedding style for a specified file type
3238:
3239: =cut
3240:
3241: sub fileembstyle {
3242: return $fe{lc(shift(@_))};
1.169 www 3243: }
3244:
1.351 www 3245: sub filemimetype {
3246: return $fm{lc(shift(@_))};
3247: }
3248:
1.169 www 3249:
3250: sub filecategoryselect {
3251: my ($name,$value)=@_;
1.189 matthew 3252: return &select_form($value,$name,
1.970 raeburn 3253: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3254: }
3255:
3256: =pod
3257:
1.648 raeburn 3258: =item * &filedescription()
1.112 bowersj2 3259:
3260: returns description for a specified file type
3261:
3262: =cut
3263:
3264: sub filedescription {
1.188 matthew 3265: my $file_description = $fd{lc(shift())};
3266: $file_description =~ s:([\[\]]):~$1:g;
3267: return &mt($file_description);
1.112 bowersj2 3268: }
3269:
3270: =pod
3271:
1.648 raeburn 3272: =item * &filedescriptionex()
1.112 bowersj2 3273:
3274: returns description for a specified file type with
3275: extra formatting
3276:
3277: =cut
3278:
3279: sub filedescriptionex {
3280: my $ex=shift;
1.188 matthew 3281: my $file_description = $fd{lc($ex)};
3282: $file_description =~ s:([\[\]]):~$1:g;
3283: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3284: }
3285:
3286: # End of .tab access
3287: =pod
3288:
3289: =back
3290:
3291: =cut
3292:
3293: # ------------------------------------------------------------------ File Types
3294: sub fileextensions {
3295: return sort(keys(%fe));
3296: }
3297:
1.97 www 3298: # ----------------------------------------------------------- Display Languages
3299: # returns a hash with all desired display languages
3300: #
3301:
3302: sub display_languages {
3303: my %languages=();
1.695 raeburn 3304: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3305: $languages{$lang}=1;
1.97 www 3306: }
3307: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3308: if ($env{'form.displaylanguage'}) {
1.356 albertel 3309: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3310: $languages{$lang}=1;
1.97 www 3311: }
3312: }
3313: return %languages;
1.14 harris41 3314: }
3315:
1.582 albertel 3316: sub languages {
3317: my ($possible_langs) = @_;
1.695 raeburn 3318: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3319: if (!ref($possible_langs)) {
3320: if( wantarray ) {
3321: return @preferred_langs;
3322: } else {
3323: return $preferred_langs[0];
3324: }
3325: }
3326: my %possibilities = map { $_ => 1 } (@$possible_langs);
3327: my @preferred_possibilities;
3328: foreach my $preferred_lang (@preferred_langs) {
3329: if (exists($possibilities{$preferred_lang})) {
3330: push(@preferred_possibilities, $preferred_lang);
3331: }
3332: }
3333: if( wantarray ) {
3334: return @preferred_possibilities;
3335: }
3336: return $preferred_possibilities[0];
3337: }
3338:
1.742 raeburn 3339: sub user_lang {
3340: my ($touname,$toudom,$fromcid) = @_;
3341: my @userlangs;
3342: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3343: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3344: $env{'course.'.$fromcid.'.languages'}));
3345: } else {
3346: my %langhash = &getlangs($touname,$toudom);
3347: if ($langhash{'languages'} ne '') {
3348: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3349: } else {
3350: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3351: if ($domdefs{'lang_def'} ne '') {
3352: @userlangs = ($domdefs{'lang_def'});
3353: }
3354: }
3355: }
3356: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3357: my $user_lh = Apache::localize->get_handle(@languages);
3358: return $user_lh;
3359: }
3360:
3361:
1.112 bowersj2 3362: ###############################################################
3363: ## Student Answer Attempts ##
3364: ###############################################################
3365:
3366: =pod
3367:
3368: =head1 Alternate Problem Views
3369:
3370: =over 4
3371:
1.648 raeburn 3372: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3373: $getattempt, $regexp, $gradesub)
3374:
3375: Return string with previous attempt on problem. Arguments:
3376:
3377: =over 4
3378:
3379: =item * $symb: Problem, including path
3380:
3381: =item * $username: username of the desired student
3382:
3383: =item * $domain: domain of the desired student
1.14 harris41 3384:
1.112 bowersj2 3385: =item * $course: Course ID
1.14 harris41 3386:
1.112 bowersj2 3387: =item * $getattempt: Leave blank for all attempts, otherwise put
3388: something
1.14 harris41 3389:
1.112 bowersj2 3390: =item * $regexp: if string matches this regexp, the string will be
3391: sent to $gradesub
1.14 harris41 3392:
1.112 bowersj2 3393: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3394:
1.112 bowersj2 3395: =back
1.14 harris41 3396:
1.112 bowersj2 3397: The output string is a table containing all desired attempts, if any.
1.16 harris41 3398:
1.112 bowersj2 3399: =cut
1.1 albertel 3400:
3401: sub get_previous_attempt {
1.43 ng 3402: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3403: my $prevattempts='';
1.43 ng 3404: no strict 'refs';
1.1 albertel 3405: if ($symb) {
1.3 albertel 3406: my (%returnhash)=
3407: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3408: if ($returnhash{'version'}) {
3409: my %lasthash=();
3410: my $version;
3411: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3412: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3413: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3414: }
1.1 albertel 3415: }
1.596 albertel 3416: $prevattempts=&start_data_table().&start_data_table_header_row();
3417: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3418: my (%typeparts,%lasthidden);
1.945 raeburn 3419: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3420: foreach my $key (sort(keys(%lasthash))) {
3421: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3422: if ($#parts > 0) {
1.31 albertel 3423: my $data=$parts[-1];
3424: pop(@parts);
1.945 raeburn 3425: if ($data eq 'type') {
3426: unless ($showsurv) {
3427: my $id = join(',',@parts);
3428: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3429: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3430: $lasthidden{$ign.'.'.$id} = 1;
3431: }
1.945 raeburn 3432: }
3433: delete($lasthash{$key});
3434: } else {
3435: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3436: }
1.31 albertel 3437: } else {
1.41 ng 3438: if ($#parts == 0) {
3439: $prevattempts.='<th>'.$parts[0].'</th>';
3440: } else {
3441: $prevattempts.='<th>'.$ign.'</th>';
3442: }
1.31 albertel 3443: }
1.16 harris41 3444: }
1.596 albertel 3445: $prevattempts.=&end_data_table_header_row();
1.40 ng 3446: if ($getattempt eq '') {
3447: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3448: my @hidden;
3449: if (%typeparts) {
3450: foreach my $id (keys(%typeparts)) {
3451: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3452: push(@hidden,$id);
3453: }
3454: }
3455: }
3456: $prevattempts.=&start_data_table_row().
3457: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3458: if (@hidden) {
3459: foreach my $key (sort(keys(%lasthash))) {
3460: my $hide;
3461: foreach my $id (@hidden) {
3462: if ($key =~ /^\Q$id\E/) {
3463: $hide = 1;
3464: last;
3465: }
3466: }
3467: if ($hide) {
3468: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3469: if (($data eq 'award') || ($data eq 'awarddetail')) {
3470: my $value = &format_previous_attempt_value($key,
3471: $returnhash{$version.':'.$key});
3472: $prevattempts.='<td>'.$value.' </td>';
3473: } else {
3474: $prevattempts.='<td> </td>';
3475: }
3476: } else {
3477: if ($key =~ /\./) {
3478: my $value = &format_previous_attempt_value($key,
3479: $returnhash{$version.':'.$key});
3480: $prevattempts.='<td>'.$value.' </td>';
3481: } else {
3482: $prevattempts.='<td> </td>';
3483: }
3484: }
3485: }
3486: } else {
3487: foreach my $key (sort(keys(%lasthash))) {
3488: my $value = &format_previous_attempt_value($key,
3489: $returnhash{$version.':'.$key});
3490: $prevattempts.='<td>'.$value.' </td>';
3491: }
3492: }
3493: $prevattempts.=&end_data_table_row();
1.40 ng 3494: }
1.1 albertel 3495: }
1.945 raeburn 3496: my @currhidden = keys(%lasthidden);
1.596 albertel 3497: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3498: foreach my $key (sort(keys(%lasthash))) {
1.945 raeburn 3499: if (%typeparts) {
3500: my $hidden;
3501: foreach my $id (@currhidden) {
3502: if ($key =~ /^\Q$id\E/) {
3503: $hidden = 1;
3504: last;
3505: }
3506: }
3507: if ($hidden) {
3508: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3509: if (($data eq 'award') || ($data eq 'awarddetail')) {
3510: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3511: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3512: $value = &$gradesub($value);
3513: }
3514: $prevattempts.='<td>'.$value.' </td>';
3515: } else {
3516: $prevattempts.='<td> </td>';
3517: }
3518: } else {
3519: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3520: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3521: $value = &$gradesub($value);
3522: }
3523: $prevattempts.='<td>'.$value.' </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: }
1.16 harris41 3532: }
1.596 albertel 3533: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3534: } else {
1.596 albertel 3535: $prevattempts=
3536: &start_data_table().&start_data_table_row().
3537: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3538: &end_data_table_row().&end_data_table();
1.1 albertel 3539: }
3540: } else {
1.596 albertel 3541: $prevattempts=
3542: &start_data_table().&start_data_table_row().
3543: '<td>'.&mt('No data.').'</td>'.
3544: &end_data_table_row().&end_data_table();
1.1 albertel 3545: }
1.10 albertel 3546: }
3547:
1.581 albertel 3548: sub format_previous_attempt_value {
3549: my ($key,$value) = @_;
3550: if ($key =~ /timestamp/) {
3551: $value = &Apache::lonlocal::locallocaltime($value);
3552: } elsif (ref($value) eq 'ARRAY') {
3553: $value = '('.join(', ', @{ $value }).')';
1.988 ! raeburn 3554: } elsif ($key =~ /answerstring$/) {
! 3555: my %answers = &Apache::lonnet::str2hash($value);
! 3556: my @anskeys = sort(keys(%answers));
! 3557: if (@anskeys == 1) {
! 3558: my $answer = $answers{$anskeys[0]};
! 3559: if ($answer =~ m{\Q\0\E}) {
! 3560: $answer =~ s{\Q\0\E}{, }g;
! 3561: }
! 3562: my $tag_internal_answer_name = 'INTERNAL';
! 3563: if ($anskeys[0] eq $tag_internal_answer_name) {
! 3564: $value = $answer;
! 3565: } else {
! 3566: $value = $anskeys[0].'='.$answer;
! 3567: }
! 3568: } else {
! 3569: foreach my $ans (@anskeys) {
! 3570: my $answer = $answers{$ans};
! 3571: if ($answer =~ m{\Q\0\E}) {
! 3572: $answer =~ s{\Q\0\E}{, }g;
! 3573: }
! 3574: $value .= $ans.'='.$answer.'<br />';;
! 3575: }
! 3576: }
1.581 albertel 3577: } else {
3578: $value = &unescape($value);
3579: }
3580: return $value;
3581: }
3582:
3583:
1.107 albertel 3584: sub relative_to_absolute {
3585: my ($url,$output)=@_;
3586: my $parser=HTML::TokeParser->new(\$output);
3587: my $token;
3588: my $thisdir=$url;
3589: my @rlinks=();
3590: while ($token=$parser->get_token) {
3591: if ($token->[0] eq 'S') {
3592: if ($token->[1] eq 'a') {
3593: if ($token->[2]->{'href'}) {
3594: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3595: }
3596: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3597: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3598: } elsif ($token->[1] eq 'base') {
3599: $thisdir=$token->[2]->{'href'};
3600: }
3601: }
3602: }
3603: $thisdir=~s-/[^/]*$--;
1.356 albertel 3604: foreach my $link (@rlinks) {
1.726 raeburn 3605: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3606: ($link=~/^\//) ||
3607: ($link=~/^javascript:/i) ||
3608: ($link=~/^mailto:/i) ||
3609: ($link=~/^\#/)) {
3610: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3611: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3612: }
3613: }
3614: # -------------------------------------------------- Deal with Applet codebases
3615: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3616: return $output;
3617: }
3618:
1.112 bowersj2 3619: =pod
3620:
1.648 raeburn 3621: =item * &get_student_view()
1.112 bowersj2 3622:
3623: show a snapshot of what student was looking at
3624:
3625: =cut
3626:
1.10 albertel 3627: sub get_student_view {
1.186 albertel 3628: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3629: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3630: my (%form);
1.10 albertel 3631: my @elements=('symb','courseid','domain','username');
3632: foreach my $element (@elements) {
1.186 albertel 3633: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3634: }
1.186 albertel 3635: if (defined($moreenv)) {
3636: %form=(%form,%{$moreenv});
3637: }
1.236 albertel 3638: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3639: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3640: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3641: $userview=~s/\<body[^\>]*\>//gi;
3642: $userview=~s/\<\/body\>//gi;
3643: $userview=~s/\<html\>//gi;
3644: $userview=~s/\<\/html\>//gi;
3645: $userview=~s/\<head\>//gi;
3646: $userview=~s/\<\/head\>//gi;
3647: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3648: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3649: if (wantarray) {
3650: return ($userview,$response);
3651: } else {
3652: return $userview;
3653: }
3654: }
3655:
3656: sub get_student_view_with_retries {
3657: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3658:
3659: my $ok = 0; # True if we got a good response.
3660: my $content;
3661: my $response;
3662:
3663: # Try to get the student_view done. within the retries count:
3664:
3665: do {
3666: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3667: $ok = $response->is_success;
3668: if (!$ok) {
3669: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3670: }
3671: $retries--;
3672: } while (!$ok && ($retries > 0));
3673:
3674: if (!$ok) {
3675: $content = ''; # On error return an empty content.
3676: }
1.651 www 3677: if (wantarray) {
3678: return ($content, $response);
3679: } else {
3680: return $content;
3681: }
1.11 albertel 3682: }
3683:
1.112 bowersj2 3684: =pod
3685:
1.648 raeburn 3686: =item * &get_student_answers()
1.112 bowersj2 3687:
3688: show a snapshot of how student was answering problem
3689:
3690: =cut
3691:
1.11 albertel 3692: sub get_student_answers {
1.100 sakharuk 3693: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3694: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3695: my (%moreenv);
1.11 albertel 3696: my @elements=('symb','courseid','domain','username');
3697: foreach my $element (@elements) {
1.186 albertel 3698: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3699: }
1.186 albertel 3700: $moreenv{'grade_target'}='answer';
3701: %moreenv=(%form,%moreenv);
1.497 raeburn 3702: $feedurl = &Apache::lonnet::clutter($feedurl);
3703: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3704: return $userview;
1.1 albertel 3705: }
1.116 albertel 3706:
3707: =pod
3708:
3709: =item * &submlink()
3710:
1.242 albertel 3711: Inputs: $text $uname $udom $symb $target
1.116 albertel 3712:
3713: Returns: A link to grades.pm such as to see the SUBM view of a student
3714:
3715: =cut
3716:
3717: ###############################################
3718: sub submlink {
1.242 albertel 3719: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3720: if (!($uname && $udom)) {
3721: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3722: &Apache::lonnet::whichuser($symb);
1.116 albertel 3723: if (!$symb) { $symb=$cursymb; }
3724: }
1.254 matthew 3725: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3726: $symb=&escape($symb);
1.960 bisitz 3727: if ($target) { $target=" target=\"$target\""; }
3728: return
3729: '<a href="/adm/grades?command=submission'.
3730: '&symb='.$symb.
3731: '&student='.$uname.
3732: '&userdom='.$udom.'"'.
3733: $target.'>'.$text.'</a>';
1.242 albertel 3734: }
3735: ##############################################
3736:
3737: =pod
3738:
3739: =item * &pgrdlink()
3740:
3741: Inputs: $text $uname $udom $symb $target
3742:
3743: Returns: A link to grades.pm such as to see the PGRD view of a student
3744:
3745: =cut
3746:
3747: ###############################################
3748: sub pgrdlink {
3749: my $link=&submlink(@_);
3750: $link=~s/(&command=submission)/$1&showgrading=yes/;
3751: return $link;
3752: }
3753: ##############################################
3754:
3755: =pod
3756:
3757: =item * &pprmlink()
3758:
3759: Inputs: $text $uname $udom $symb $target
3760:
3761: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3762: student and a specific resource
1.242 albertel 3763:
3764: =cut
3765:
3766: ###############################################
3767: sub pprmlink {
3768: my ($text,$uname,$udom,$symb,$target)=@_;
3769: if (!($uname && $udom)) {
3770: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3771: &Apache::lonnet::whichuser($symb);
1.242 albertel 3772: if (!$symb) { $symb=$cursymb; }
3773: }
1.254 matthew 3774: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3775: $symb=&escape($symb);
1.242 albertel 3776: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3777: return '<a href="/adm/parmset?command=set&'.
3778: 'symb='.$symb.'&uname='.$uname.
3779: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3780: }
3781: ##############################################
1.37 matthew 3782:
1.112 bowersj2 3783: =pod
3784:
3785: =back
3786:
3787: =cut
3788:
1.37 matthew 3789: ###############################################
1.51 www 3790:
3791:
3792: sub timehash {
1.687 raeburn 3793: my ($thistime) = @_;
3794: my $timezone = &Apache::lonlocal::gettimezone();
3795: my $dt = DateTime->from_epoch(epoch => $thistime)
3796: ->set_time_zone($timezone);
3797: my $wday = $dt->day_of_week();
3798: if ($wday == 7) { $wday = 0; }
3799: return ( 'second' => $dt->second(),
3800: 'minute' => $dt->minute(),
3801: 'hour' => $dt->hour(),
3802: 'day' => $dt->day_of_month(),
3803: 'month' => $dt->month(),
3804: 'year' => $dt->year(),
3805: 'weekday' => $wday,
3806: 'dayyear' => $dt->day_of_year(),
3807: 'dlsav' => $dt->is_dst() );
1.51 www 3808: }
3809:
1.370 www 3810: sub utc_string {
3811: my ($date)=@_;
1.371 www 3812: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3813: }
3814:
1.51 www 3815: sub maketime {
3816: my %th=@_;
1.687 raeburn 3817: my ($epoch_time,$timezone,$dt);
3818: $timezone = &Apache::lonlocal::gettimezone();
3819: eval {
3820: $dt = DateTime->new( year => $th{'year'},
3821: month => $th{'month'},
3822: day => $th{'day'},
3823: hour => $th{'hour'},
3824: minute => $th{'minute'},
3825: second => $th{'second'},
3826: time_zone => $timezone,
3827: );
3828: };
3829: if (!$@) {
3830: $epoch_time = $dt->epoch;
3831: if ($epoch_time) {
3832: return $epoch_time;
3833: }
3834: }
1.51 www 3835: return POSIX::mktime(
3836: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3837: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3838: }
3839:
3840: #########################################
1.51 www 3841:
3842: sub findallcourses {
1.482 raeburn 3843: my ($roles,$uname,$udom) = @_;
1.355 albertel 3844: my %roles;
3845: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3846: my %courses;
1.51 www 3847: my $now=time;
1.482 raeburn 3848: if (!defined($uname)) {
3849: $uname = $env{'user.name'};
3850: }
3851: if (!defined($udom)) {
3852: $udom = $env{'user.domain'};
3853: }
3854: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.982 raeburn 3855: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3856: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3857: $extra);
1.482 raeburn 3858: if (!%roles) {
3859: %roles = (
3860: cc => 1,
1.907 raeburn 3861: co => 1,
1.482 raeburn 3862: in => 1,
3863: ep => 1,
3864: ta => 1,
3865: cr => 1,
3866: st => 1,
3867: );
3868: }
3869: foreach my $entry (keys(%roleshash)) {
3870: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3871: if ($trole =~ /^cr/) {
3872: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3873: } else {
3874: next if (!exists($roles{$trole}));
3875: }
3876: if ($tend) {
3877: next if ($tend < $now);
3878: }
3879: if ($tstart) {
3880: next if ($tstart > $now);
3881: }
3882: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3883: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3884: if ($secpart eq '') {
3885: ($cnum,$role) = split(/_/,$cnumpart);
3886: $sec = 'none';
3887: $realsec = '';
3888: } else {
3889: $cnum = $cnumpart;
3890: ($sec,$role) = split(/_/,$secpart);
3891: $realsec = $sec;
1.490 raeburn 3892: }
1.482 raeburn 3893: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3894: }
3895: } else {
3896: foreach my $key (keys(%env)) {
1.483 albertel 3897: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3898: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3899: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3900: next if ($role eq 'ca' || $role eq 'aa');
3901: next if (%roles && !exists($roles{$role}));
3902: my ($starttime,$endtime)=split(/\./,$env{$key});
3903: my $active=1;
3904: if ($starttime) {
3905: if ($now<$starttime) { $active=0; }
3906: }
3907: if ($endtime) {
3908: if ($now>$endtime) { $active=0; }
3909: }
3910: if ($active) {
3911: if ($sec eq '') {
3912: $sec = 'none';
3913: }
3914: $courses{$cdom.'_'.$cnum}{$sec} =
3915: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3916: }
3917: }
1.51 www 3918: }
3919: }
1.474 raeburn 3920: return %courses;
1.51 www 3921: }
1.37 matthew 3922:
1.54 www 3923: ###############################################
1.474 raeburn 3924:
3925: sub blockcheck {
1.482 raeburn 3926: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3927:
3928: if (!defined($udom)) {
3929: $udom = $env{'user.domain'};
3930: }
3931: if (!defined($uname)) {
3932: $uname = $env{'user.name'};
3933: }
3934:
3935: # If uname and udom are for a course, check for blocks in the course.
3936:
3937: if (&Apache::lonnet::is_course($udom,$uname)) {
3938: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3939: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3940: return ($startblock,$endblock);
3941: }
1.474 raeburn 3942:
1.502 raeburn 3943: my $startblock = 0;
3944: my $endblock = 0;
1.482 raeburn 3945: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3946:
1.490 raeburn 3947: # If uname is for a user, and activity is course-specific, i.e.,
3948: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3949:
1.490 raeburn 3950: if (($activity eq 'boards' || $activity eq 'chat' ||
3951: $activity eq 'groups') && ($env{'request.course.id'})) {
3952: foreach my $key (keys(%live_courses)) {
3953: if ($key ne $env{'request.course.id'}) {
3954: delete($live_courses{$key});
3955: }
3956: }
3957: }
3958:
3959: my $otheruser = 0;
3960: my %own_courses;
3961: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3962: # Resource belongs to user other than current user.
3963: $otheruser = 1;
3964: # Gather courses for current user
3965: %own_courses =
3966: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3967: }
3968:
3969: # Gather active course roles - course coordinator, instructor,
3970: # exam proctor, ta, student, or custom role.
1.474 raeburn 3971:
3972: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3973: my ($cdom,$cnum);
3974: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3975: $cdom = $env{'course.'.$course.'.domain'};
3976: $cnum = $env{'course.'.$course.'.num'};
3977: } else {
1.490 raeburn 3978: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3979: }
3980: my $no_ownblock = 0;
3981: my $no_userblock = 0;
1.533 raeburn 3982: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3983: # Check if current user has 'evb' priv for this
3984: if (defined($own_courses{$course})) {
3985: foreach my $sec (keys(%{$own_courses{$course}})) {
3986: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3987: if ($sec ne 'none') {
3988: $checkrole .= '/'.$sec;
3989: }
3990: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3991: $no_ownblock = 1;
3992: last;
3993: }
3994: }
3995: }
3996: # if they have 'evb' priv and are currently not playing student
3997: next if (($no_ownblock) &&
3998: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3999: }
1.474 raeburn 4000: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4001: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4002: if ($sec ne 'none') {
1.482 raeburn 4003: $checkrole .= '/'.$sec;
1.474 raeburn 4004: }
1.490 raeburn 4005: if ($otheruser) {
4006: # Resource belongs to user other than current user.
4007: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 4008: my ($trole,$tdom,$tnum,$tsec);
4009: my $entry = $live_courses{$course}{$sec};
4010: if ($entry =~ /^cr/) {
4011: ($trole,$tdom,$tnum,$tsec) =
4012: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4013: } else {
4014: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4015: }
4016: my ($spec,$area,$trest,%allroles,%userroles);
4017: $area = '/'.$tdom.'/'.$tnum;
4018: $trest = $tnum;
4019: if ($tsec ne '') {
4020: $area .= '/'.$tsec;
4021: $trest .= '/'.$tsec;
4022: }
4023: $spec = $trole.'.'.$area;
4024: if ($trole =~ /^cr/) {
4025: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4026: $tdom,$spec,$trest,$area);
4027: } else {
4028: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4029: $tdom,$spec,$trest,$area);
4030: }
4031: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4032: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4033: if ($1) {
4034: $no_userblock = 1;
4035: last;
4036: }
4037: }
1.490 raeburn 4038: } else {
4039: # Resource belongs to current user
4040: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4041: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4042: $no_ownblock = 1;
4043: last;
4044: }
1.474 raeburn 4045: }
4046: }
4047: # if they have the evb priv and are currently not playing student
1.482 raeburn 4048: next if (($no_ownblock) &&
1.491 albertel 4049: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4050: next if ($no_userblock);
1.474 raeburn 4051:
1.866 kalberla 4052: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4053: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4054:
4055: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4056: if (($start != 0) &&
4057: (($startblock == 0) || ($startblock > $start))) {
4058: $startblock = $start;
4059: }
4060: if (($end != 0) &&
4061: (($endblock == 0) || ($endblock < $end))) {
4062: $endblock = $end;
4063: }
1.490 raeburn 4064: }
4065: return ($startblock,$endblock);
4066: }
4067:
4068: sub get_blocks {
4069: my ($setters,$activity,$cdom,$cnum) = @_;
4070: my $startblock = 0;
4071: my $endblock = 0;
4072: my $course = $cdom.'_'.$cnum;
4073: $setters->{$course} = {};
4074: $setters->{$course}{'staff'} = [];
4075: $setters->{$course}{'times'} = [];
4076: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4077: foreach my $record (keys(%records)) {
4078: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4079: if ($start <= time && $end >= time) {
4080: my ($staff_name,$staff_dom,$title,$blocks) =
4081: &parse_block_record($records{$record});
4082: if ($blocks->{$activity} eq 'on') {
4083: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4084: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4085: if ( ($startblock == 0) || ($startblock > $start) ) {
4086: $startblock = $start;
1.490 raeburn 4087: }
1.491 albertel 4088: if ( ($endblock == 0) || ($endblock < $end) ) {
4089: $endblock = $end;
1.474 raeburn 4090: }
4091: }
4092: }
4093: }
4094: return ($startblock,$endblock);
4095: }
4096:
4097: sub parse_block_record {
4098: my ($record) = @_;
4099: my ($setuname,$setudom,$title,$blocks);
4100: if (ref($record) eq 'HASH') {
4101: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4102: $title = &unescape($record->{'event'});
4103: $blocks = $record->{'blocks'};
4104: } else {
4105: my @data = split(/:/,$record,3);
4106: if (scalar(@data) eq 2) {
4107: $title = $data[1];
4108: ($setuname,$setudom) = split(/@/,$data[0]);
4109: } else {
4110: ($setuname,$setudom,$title) = @data;
4111: }
4112: $blocks = { 'com' => 'on' };
4113: }
4114: return ($setuname,$setudom,$title,$blocks);
4115: }
4116:
1.854 kalberla 4117: sub blocking_status {
4118: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4119: my %setters;
1.890 droeschl 4120:
4121: # check for active blocking
1.867 kalberla 4122: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4123:
1.890 droeschl 4124: my $blocked = $startblock && $endblock ? 1 : 0;
4125:
4126: # caller just wants to know whether a block is active
4127: if (!wantarray) { return $blocked; }
4128:
4129: # build a link to a popup window containing the details
4130: my $querystring = "?activity=$activity";
4131: # $uname and $udom decide whose portfolio the user is trying to look at
4132: $querystring .= "&udom=$udom" if $udom;
4133: $querystring .= "&uname=$uname" if $uname;
4134:
4135: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4136: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4137: var options = "width=" + w + ",height=" + h + ",";
4138: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4139: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4140: var newWin = window.open(url, wdwName, options);
4141: newWin.focus();
4142: }
1.890 droeschl 4143: END_MYBLOCK
1.854 kalberla 4144:
1.890 droeschl 4145: $output = Apache::lonhtmlcommon::scripttag($output);
4146:
1.854 kalberla 4147: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4148: my $text = mt('Communication Blocked');
4149:
1.867 kalberla 4150: $output .= <<"END_BLOCK";
4151: <div class='LC_comblock'>
1.869 kalberla 4152: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4153: title='$text'>
4154: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4155: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4156: title='$text'>$text</a>
1.867 kalberla 4157: </div>
4158:
4159: END_BLOCK
1.474 raeburn 4160:
1.854 kalberla 4161: return ($blocked, $output);
4162: }
1.490 raeburn 4163:
1.60 matthew 4164: ###############################################
4165:
1.682 raeburn 4166: sub check_ip_acc {
4167: my ($acc)=@_;
4168: &Apache::lonxml::debug("acc is $acc");
4169: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4170: return 1;
4171: }
4172: my $allowed=0;
4173: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4174:
4175: my $name;
4176: foreach my $pattern (split(',',$acc)) {
4177: $pattern =~ s/^\s*//;
4178: $pattern =~ s/\s*$//;
4179: if ($pattern =~ /\*$/) {
4180: #35.8.*
4181: $pattern=~s/\*//;
4182: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4183: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4184: #35.8.3.[34-56]
4185: my $low=$2;
4186: my $high=$3;
4187: $pattern=$1;
4188: if ($ip =~ /^\Q$pattern\E/) {
4189: my $last=(split(/\./,$ip))[3];
4190: if ($last <=$high && $last >=$low) { $allowed=1; }
4191: }
4192: } elsif ($pattern =~ /^\*/) {
4193: #*.msu.edu
4194: $pattern=~s/\*//;
4195: if (!defined($name)) {
4196: use Socket;
4197: my $netaddr=inet_aton($ip);
4198: ($name)=gethostbyaddr($netaddr,AF_INET);
4199: }
4200: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4201: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4202: #127.0.0.1
4203: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4204: } else {
4205: #some.name.com
4206: if (!defined($name)) {
4207: use Socket;
4208: my $netaddr=inet_aton($ip);
4209: ($name)=gethostbyaddr($netaddr,AF_INET);
4210: }
4211: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4212: }
4213: if ($allowed) { last; }
4214: }
4215: return $allowed;
4216: }
4217:
4218: ###############################################
4219:
1.60 matthew 4220: =pod
4221:
1.112 bowersj2 4222: =head1 Domain Template Functions
4223:
4224: =over 4
4225:
4226: =item * &determinedomain()
1.60 matthew 4227:
4228: Inputs: $domain (usually will be undef)
4229:
1.63 www 4230: Returns: Determines which domain should be used for designs
1.60 matthew 4231:
4232: =cut
1.54 www 4233:
1.60 matthew 4234: ###############################################
1.63 www 4235: sub determinedomain {
4236: my $domain=shift;
1.531 albertel 4237: if (! $domain) {
1.60 matthew 4238: # Determine domain if we have not been given one
1.893 raeburn 4239: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4240: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4241: if ($env{'request.role.domain'}) {
4242: $domain=$env{'request.role.domain'};
1.60 matthew 4243: }
4244: }
1.63 www 4245: return $domain;
4246: }
4247: ###############################################
1.517 raeburn 4248:
1.518 albertel 4249: sub devalidate_domconfig_cache {
4250: my ($udom)=@_;
4251: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4252: }
4253:
4254: # ---------------------- Get domain configuration for a domain
4255: sub get_domainconf {
4256: my ($udom) = @_;
4257: my $cachetime=1800;
4258: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4259: if (defined($cached)) { return %{$result}; }
4260:
4261: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4262: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4263: my (%designhash,%legacy);
1.518 albertel 4264: if (keys(%domconfig) > 0) {
4265: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4266: if (keys(%{$domconfig{'login'}})) {
4267: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4268: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4269: if ($key eq 'loginvia') {
4270: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4271: my @ids = &Apache::lonnet::current_machine_ids();
4272: foreach my $hostname (@ids) {
1.948 raeburn 4273: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4274: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4275: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4276: $designhash{$udom.'.login.loginvia'} = $server;
4277: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4278:
4279: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4280: } else {
4281: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4282: }
4283: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4284: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4285: }
1.946 raeburn 4286: }
4287: }
4288: }
4289: }
4290: } else {
4291: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4292: $designhash{$udom.'.login.'.$key.'_'.$img} =
4293: $domconfig{'login'}{$key}{$img};
4294: }
1.699 raeburn 4295: }
4296: } else {
4297: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4298: }
1.632 raeburn 4299: }
4300: } else {
4301: $legacy{'login'} = 1;
1.518 albertel 4302: }
1.632 raeburn 4303: } else {
4304: $legacy{'login'} = 1;
1.518 albertel 4305: }
4306: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4307: if (keys(%{$domconfig{'rolecolors'}})) {
4308: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4309: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4310: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4311: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4312: }
1.518 albertel 4313: }
4314: }
1.632 raeburn 4315: } else {
4316: $legacy{'rolecolors'} = 1;
1.518 albertel 4317: }
1.632 raeburn 4318: } else {
4319: $legacy{'rolecolors'} = 1;
1.518 albertel 4320: }
1.948 raeburn 4321: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4322: if ($domconfig{'autoenroll'}{'co-owners'}) {
4323: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4324: }
4325: }
1.632 raeburn 4326: if (keys(%legacy) > 0) {
4327: my %legacyhash = &get_legacy_domconf($udom);
4328: foreach my $item (keys(%legacyhash)) {
4329: if ($item =~ /^\Q$udom\E\.login/) {
4330: if ($legacy{'login'}) {
4331: $designhash{$item} = $legacyhash{$item};
4332: }
4333: } else {
4334: if ($legacy{'rolecolors'}) {
4335: $designhash{$item} = $legacyhash{$item};
4336: }
1.518 albertel 4337: }
4338: }
4339: }
1.632 raeburn 4340: } else {
4341: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4342: }
4343: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4344: $cachetime);
4345: return %designhash;
4346: }
4347:
1.632 raeburn 4348: sub get_legacy_domconf {
4349: my ($udom) = @_;
4350: my %legacyhash;
4351: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4352: my $designfile = $designdir.'/'.$udom.'.tab';
4353: if (-e $designfile) {
4354: if ( open (my $fh,"<$designfile") ) {
4355: while (my $line = <$fh>) {
4356: next if ($line =~ /^\#/);
4357: chomp($line);
4358: my ($key,$val)=(split(/\=/,$line));
4359: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4360: }
4361: close($fh);
4362: }
4363: }
4364: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4365: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4366: }
4367: return %legacyhash;
4368: }
4369:
1.63 www 4370: =pod
4371:
1.112 bowersj2 4372: =item * &domainlogo()
1.63 www 4373:
4374: Inputs: $domain (usually will be undef)
4375:
4376: Returns: A link to a domain logo, if the domain logo exists.
4377: If the domain logo does not exist, a description of the domain.
4378:
4379: =cut
1.112 bowersj2 4380:
1.63 www 4381: ###############################################
4382: sub domainlogo {
1.517 raeburn 4383: my $domain = &determinedomain(shift);
1.518 albertel 4384: my %designhash = &get_domainconf($domain);
1.517 raeburn 4385: # See if there is a logo
4386: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4387: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4388: if ($imgsrc =~ m{^/(adm|res)/}) {
4389: if ($imgsrc =~ m{^/res/}) {
4390: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4391: &Apache::lonnet::repcopy($local_name);
4392: }
4393: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4394: }
4395: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4396: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4397: return &Apache::lonnet::domain($domain,'description');
1.59 www 4398: } else {
1.60 matthew 4399: return '';
1.59 www 4400: }
4401: }
1.63 www 4402: ##############################################
4403:
4404: =pod
4405:
1.112 bowersj2 4406: =item * &designparm()
1.63 www 4407:
4408: Inputs: $which parameter; $domain (usually will be undef)
4409:
4410: Returns: value of designparamter $which
4411:
4412: =cut
1.112 bowersj2 4413:
1.397 albertel 4414:
1.400 albertel 4415: ##############################################
1.397 albertel 4416: sub designparm {
4417: my ($which,$domain)=@_;
4418: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4419: return $env{'environment.color.'.$which};
1.96 www 4420: }
1.63 www 4421: $domain=&determinedomain($domain);
1.518 albertel 4422: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4423: my $output;
1.517 raeburn 4424: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4425: $output = $domdesign{$domain.'.'.$which};
1.63 www 4426: } else {
1.520 raeburn 4427: $output = $defaultdesign{$which};
4428: }
4429: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4430: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4431: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4432: if ($output =~ m{^/res/}) {
4433: my $local_name = &Apache::lonnet::filelocation('',$output);
4434: &Apache::lonnet::repcopy($local_name);
4435: }
1.520 raeburn 4436: $output = &lonhttpdurl($output);
4437: }
1.63 www 4438: }
1.520 raeburn 4439: return $output;
1.63 www 4440: }
1.59 www 4441:
1.822 bisitz 4442: ##############################################
4443: =pod
4444:
1.832 bisitz 4445: =item * &authorspace()
4446:
4447: Inputs: ./.
4448:
4449: Returns: Path to the Construction Space of the current user's
4450: accessed author space
4451: The author space will be that of the current user
4452: when accessing the own author space
4453: and that of the co-author/assistent co-author
4454: when accessing the co-author's/assistent co-author's
4455: space
4456:
4457: =cut
4458:
4459: sub authorspace {
4460: my $caname = '';
4461: if ($env{'request.role'} =~ /^ca|^aa/) {
4462: (undef,$caname) =
4463: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4464: } else {
4465: $caname = $env{'user.name'};
4466: }
4467: return '/priv/'.$caname.'/';
4468: }
4469:
4470: ##############################################
4471: =pod
4472:
1.822 bisitz 4473: =item * &head_subbox()
4474:
4475: Inputs: $content (contains HTML code with page functions, etc.)
4476:
4477: Returns: HTML div with $content
4478: To be included in page header
4479:
4480: =cut
4481:
4482: sub head_subbox {
4483: my ($content)=@_;
4484: my $output =
1.844 bisitz 4485: '<div id="LC_head_subbox">'
1.822 bisitz 4486: .$content
4487: .'</div>'
4488: }
4489:
4490: ##############################################
4491: =pod
4492:
4493: =item * &CSTR_pageheader()
4494:
4495: Inputs: ./.
4496:
4497: Returns: HTML div with CSTR path and recent box
4498: To be included on Construction Space pages
4499:
4500: =cut
4501:
4502: sub CSTR_pageheader {
4503: # this is for resources; directories have customtitle, and crumbs
4504: # and select recent are created in lonpubdir.pm
4505: my ($uname,$thisdisfn)=
4506: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4507: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4508: $formaction=~s/\/+/\//g;
4509:
4510: my $parentpath = '';
4511: my $lastitem = '';
4512: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4513: $parentpath = $1;
4514: $lastitem = $2;
4515: } else {
4516: $lastitem = $thisdisfn;
4517: }
1.921 bisitz 4518:
4519: my $output =
1.822 bisitz 4520: '<div>'
4521: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4522: .'<b>'.&mt('Construction Space:').'</b> '
4523: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4524: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4525: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4526:
4527: if ($lastitem) {
4528: $output .=
4529: '<span class="LC_filename">'
4530: .$lastitem
4531: .'</span>';
4532: }
4533: $output .=
4534: '<br />'
1.822 bisitz 4535: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4536: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4537: .'</form>'
4538: .&Apache::lonmenu::constspaceform()
4539: .'</div>';
1.921 bisitz 4540:
4541: return $output;
1.822 bisitz 4542: }
4543:
1.60 matthew 4544: ###############################################
4545: ###############################################
4546:
4547: =pod
4548:
1.112 bowersj2 4549: =back
4550:
1.549 albertel 4551: =head1 HTML Helpers
1.112 bowersj2 4552:
4553: =over 4
4554:
4555: =item * &bodytag()
1.60 matthew 4556:
4557: Returns a uniform header for LON-CAPA web pages.
4558:
4559: Inputs:
4560:
1.112 bowersj2 4561: =over 4
4562:
4563: =item * $title, A title to be displayed on the page.
4564:
4565: =item * $function, the current role (can be undef).
4566:
4567: =item * $addentries, extra parameters for the <body> tag.
4568:
4569: =item * $bodyonly, if defined, only return the <body> tag.
4570:
4571: =item * $domain, if defined, force a given domain.
4572:
4573: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4574: text interface only)
1.60 matthew 4575:
1.814 bisitz 4576: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4577: navigational links
1.317 albertel 4578:
1.338 albertel 4579: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4580:
1.460 albertel 4581: =item * $args, optional argument valid values are
4582: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4583: inherit_jsmath -> when creating popup window in a page,
4584: should it have jsmath forced on by the
4585: current page
1.460 albertel 4586:
1.112 bowersj2 4587: =back
4588:
1.60 matthew 4589: Returns: A uniform header for LON-CAPA web pages.
4590: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4591: If $bodyonly is undef or zero, an html string containing a <body> tag and
4592: other decorations will be returned.
4593:
4594: =cut
4595:
1.54 www 4596: sub bodytag {
1.831 bisitz 4597: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962 droeschl 4598: $no_nav_bar,$bgcolor,$args)=@_;
1.339 albertel 4599:
1.954 raeburn 4600: my $public;
4601: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4602: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4603: $public = 1;
4604: }
1.460 albertel 4605: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4606:
1.183 matthew 4607: $function = &get_users_function() if (!$function);
1.339 albertel 4608: my $img = &designparm($function.'.img',$domain);
4609: my $font = &designparm($function.'.font',$domain);
4610: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4611:
1.803 bisitz 4612: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4613: 'bgcolor' => $pgbg,
1.339 albertel 4614: 'text' => $font,
4615: 'alink' => &designparm($function.'.alink',$domain),
4616: 'vlink' => &designparm($function.'.vlink',$domain),
4617: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4618: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4619:
1.63 www 4620: # role and realm
1.378 raeburn 4621: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4622: if ($role eq 'ca') {
1.479 albertel 4623: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4624: $realm = &plainname($rname,$rdom);
1.378 raeburn 4625: }
1.55 www 4626: # realm
1.258 albertel 4627: if ($env{'request.course.id'}) {
1.378 raeburn 4628: if ($env{'request.role'} !~ /^cr/) {
4629: $role = &Apache::lonnet::plaintext($role,&course_type());
4630: }
1.898 raeburn 4631: if ($env{'request.course.sec'}) {
4632: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4633: }
1.359 albertel 4634: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4635: } else {
4636: $role = &Apache::lonnet::plaintext($role);
1.54 www 4637: }
1.433 albertel 4638:
1.359 albertel 4639: if (!$realm) { $realm=' '; }
1.330 albertel 4640:
1.438 albertel 4641: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4642:
1.101 www 4643: # construct main body tag
1.359 albertel 4644: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4645: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4646:
1.530 albertel 4647: if ($bodyonly) {
1.60 matthew 4648: return $bodytag;
1.798 tempelho 4649: }
1.359 albertel 4650:
1.410 albertel 4651: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 4652: if ($public) {
1.433 albertel 4653: undef($role);
1.434 albertel 4654: } else {
4655: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4656: }
1.359 albertel 4657:
1.762 bisitz 4658: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4659: #
4660: # Extra info if you are the DC
4661: my $dc_info = '';
4662: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4663: $env{'course.'.$env{'request.course.id'}.
4664: '.domain'}.'/'})) {
4665: my $cid = $env{'request.course.id'};
1.917 raeburn 4666: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4667: $dc_info =~ s/\s+$//;
1.359 albertel 4668: }
4669:
1.898 raeburn 4670: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4671: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4672:
1.916 droeschl 4673: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4674: return $bodytag;
4675: }
1.903 droeschl 4676:
4677: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4678:
4679: # if ($env{'request.state'} eq 'construct') {
4680: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4681: # }
4682:
1.359 albertel 4683:
4684:
1.916 droeschl 4685: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4686: if ($dc_info) {
4687: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4688: }
1.916 droeschl 4689: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4690: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4691: return $bodytag;
4692: }
1.894 droeschl 4693:
1.927 raeburn 4694: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4695: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4696: }
1.916 droeschl 4697:
1.903 droeschl 4698: $bodytag .= Apache::lonhtmlcommon::scripttag(
4699: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4700:
1.903 droeschl 4701: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4702:
1.917 raeburn 4703: if ($dc_info) {
4704: $dc_info = &dc_courseid_toggle($dc_info);
4705: }
4706: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4707:
1.903 droeschl 4708: #don't show menus for public users
1.954 raeburn 4709: if (!$public){
1.903 droeschl 4710: $bodytag .= Apache::lonmenu::secondary_menu();
4711: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4712: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4713: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 4714: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 4715: $args->{'bread_crumbs'});
4716: } elsif ($forcereg) {
4717: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4718: }
1.903 droeschl 4719: }else{
4720: # this is to seperate menu from content when there's no secondary
4721: # menu. Especially needed for public accessible ressources.
4722: $bodytag .= '<hr style="clear:both" />';
4723: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4724: }
1.903 droeschl 4725:
1.235 raeburn 4726: return $bodytag;
1.182 matthew 4727: }
4728:
1.917 raeburn 4729: sub dc_courseid_toggle {
4730: my ($dc_info) = @_;
1.980 raeburn 4731: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4732: '<a href="javascript:showCourseID();">'.
4733: &mt('(More ...)').'</a></span>'.
4734: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4735: }
4736:
1.330 albertel 4737: sub make_attr_string {
4738: my ($register,$attr_ref) = @_;
4739:
4740: if ($attr_ref && !ref($attr_ref)) {
4741: die("addentries Must be a hash ref ".
4742: join(':',caller(1))." ".
4743: join(':',caller(0))." ");
4744: }
4745:
4746: if ($register) {
1.339 albertel 4747: my ($on_load,$on_unload);
4748: foreach my $key (keys(%{$attr_ref})) {
4749: if (lc($key) eq 'onload') {
4750: $on_load.=$attr_ref->{$key}.';';
4751: delete($attr_ref->{$key});
4752:
4753: } elsif (lc($key) eq 'onunload') {
4754: $on_unload.=$attr_ref->{$key}.';';
4755: delete($attr_ref->{$key});
4756: }
4757: }
1.953 droeschl 4758: $attr_ref->{'onload'} = $on_load;
4759: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 4760: }
1.339 albertel 4761:
1.330 albertel 4762: my $attr_string;
4763: foreach my $attr (keys(%$attr_ref)) {
4764: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4765: }
4766: return $attr_string;
4767: }
4768:
4769:
1.182 matthew 4770: ###############################################
1.251 albertel 4771: ###############################################
4772:
4773: =pod
4774:
4775: =item * &endbodytag()
4776:
4777: Returns a uniform footer for LON-CAPA web pages.
4778:
1.635 raeburn 4779: Inputs: 1 - optional reference to an args hash
4780: If in the hash, key for noredirectlink has a value which evaluates to true,
4781: a 'Continue' link is not displayed if the page contains an
4782: internal redirect in the <head></head> section,
4783: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4784:
4785: =cut
4786:
4787: sub endbodytag {
1.635 raeburn 4788: my ($args) = @_;
1.251 albertel 4789: my $endbodytag='</body>';
1.269 albertel 4790: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4791: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4792: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4793: $endbodytag=
4794: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4795: &mt('Continue').'</a>'.
4796: $endbodytag;
4797: }
1.315 albertel 4798: }
1.251 albertel 4799: return $endbodytag;
4800: }
4801:
1.352 albertel 4802: =pod
4803:
4804: =item * &standard_css()
4805:
4806: Returns a style sheet
4807:
4808: Inputs: (all optional)
4809: domain -> force to color decorate a page for a specific
4810: domain
4811: function -> force usage of a specific rolish color scheme
4812: bgcolor -> override the default page bgcolor
4813:
4814: =cut
4815:
1.343 albertel 4816: sub standard_css {
1.345 albertel 4817: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4818: $function = &get_users_function() if (!$function);
4819: my $img = &designparm($function.'.img', $domain);
4820: my $tabbg = &designparm($function.'.tabbg', $domain);
4821: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4822: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4823: #second colour for later usage
1.345 albertel 4824: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4825: my $pgbg_or_bgcolor =
4826: $bgcolor ||
1.352 albertel 4827: &designparm($function.'.pgbg', $domain);
1.382 albertel 4828: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4829: my $alink = &designparm($function.'.alink', $domain);
4830: my $vlink = &designparm($function.'.vlink', $domain);
4831: my $link = &designparm($function.'.link', $domain);
4832:
1.602 albertel 4833: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4834: my $mono = 'monospace';
1.850 bisitz 4835: my $data_table_head = $sidebg;
4836: my $data_table_light = '#FAFAFA';
4837: my $data_table_dark = '#F0F0F0';
1.470 banghart 4838: my $data_table_darker = '#CCCCCC';
1.349 albertel 4839: my $data_table_highlight = '#FFFF00';
1.352 albertel 4840: my $mail_new = '#FFBB77';
4841: my $mail_new_hover = '#DD9955';
4842: my $mail_read = '#BBBB77';
4843: my $mail_read_hover = '#999944';
4844: my $mail_replied = '#AAAA88';
4845: my $mail_replied_hover = '#888855';
4846: my $mail_other = '#99BBBB';
4847: my $mail_other_hover = '#669999';
1.391 albertel 4848: my $table_header = '#DDDDDD';
1.489 raeburn 4849: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4850: my $lg_border_color = '#C8C8C8';
1.952 onken 4851: my $button_hover = '#BF2317';
1.392 albertel 4852:
1.608 albertel 4853: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4854: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4855: : '0 3px 0 4px';
1.448 albertel 4856:
1.523 albertel 4857:
1.343 albertel 4858: return <<END;
1.947 droeschl 4859:
4860: /* needed for iframe to allow 100% height in FF */
4861: body, html {
4862: margin: 0;
4863: padding: 0 0.5%;
4864: height: 99%; /* to avoid scrollbars */
4865: }
4866:
1.795 www 4867: body {
1.911 bisitz 4868: font-family: $sans;
4869: line-height:130%;
4870: font-size:0.83em;
4871: color:$font;
1.795 www 4872: }
4873:
1.959 onken 4874: a:focus,
4875: a:focus img {
1.795 www 4876: color: red;
1.911 bisitz 4877: background: yellow;
1.795 www 4878: }
1.698 harmsja 4879:
1.911 bisitz 4880: form, .inline {
4881: display: inline;
1.795 www 4882: }
1.721 harmsja 4883:
1.795 www 4884: .LC_right {
1.911 bisitz 4885: text-align:right;
1.795 www 4886: }
4887:
4888: .LC_middle {
1.911 bisitz 4889: vertical-align:middle;
1.795 www 4890: }
1.721 harmsja 4891:
1.911 bisitz 4892: .LC_400Box {
4893: width:400px;
4894: }
1.721 harmsja 4895:
1.947 droeschl 4896: .LC_iframecontainer {
4897: width: 98%;
4898: margin: 0;
4899: position: fixed;
4900: top: 8.5em;
4901: bottom: 0;
4902: }
4903:
4904: .LC_iframecontainer iframe{
4905: border: none;
4906: width: 100%;
4907: height: 100%;
4908: }
4909:
1.778 bisitz 4910: .LC_filename {
4911: font-family: $mono;
4912: white-space:pre;
1.921 bisitz 4913: font-size: 120%;
1.778 bisitz 4914: }
4915:
4916: .LC_fileicon {
4917: border: none;
4918: height: 1.3em;
4919: vertical-align: text-bottom;
4920: margin-right: 0.3em;
4921: text-decoration:none;
4922: }
4923:
1.350 albertel 4924: .LC_error {
4925: color: red;
4926: font-size: larger;
4927: }
1.795 www 4928:
1.457 albertel 4929: .LC_warning,
4930: .LC_diff_removed {
1.733 bisitz 4931: color: red;
1.394 albertel 4932: }
1.532 albertel 4933:
4934: .LC_info,
1.457 albertel 4935: .LC_success,
4936: .LC_diff_added {
1.350 albertel 4937: color: green;
4938: }
1.795 www 4939:
1.802 bisitz 4940: div.LC_confirm_box {
4941: background-color: #FAFAFA;
4942: border: 1px solid $lg_border_color;
4943: margin-right: 0;
4944: padding: 5px;
4945: }
4946:
4947: div.LC_confirm_box .LC_error img,
4948: div.LC_confirm_box .LC_success img {
4949: vertical-align: middle;
4950: }
4951:
1.440 albertel 4952: .LC_icon {
1.771 droeschl 4953: border: none;
1.790 droeschl 4954: vertical-align: middle;
1.771 droeschl 4955: }
4956:
1.543 albertel 4957: .LC_docs_spacer {
4958: width: 25px;
4959: height: 1px;
1.771 droeschl 4960: border: none;
1.543 albertel 4961: }
1.346 albertel 4962:
1.532 albertel 4963: .LC_internal_info {
1.735 bisitz 4964: color: #999999;
1.532 albertel 4965: }
4966:
1.794 www 4967: .LC_discussion {
1.911 bisitz 4968: background: $tabbg;
4969: border: 1px solid black;
4970: margin: 2px;
1.794 www 4971: }
4972:
4973: .LC_disc_action_links_bar {
1.911 bisitz 4974: background: $tabbg;
4975: border: none;
4976: margin: 4px;
1.794 www 4977: }
4978:
4979: .LC_disc_action_left {
1.911 bisitz 4980: text-align: left;
1.794 www 4981: }
4982:
4983: .LC_disc_action_right {
1.911 bisitz 4984: text-align: right;
1.794 www 4985: }
4986:
4987: .LC_disc_new_item {
1.911 bisitz 4988: background: white;
4989: border: 2px solid red;
4990: margin: 2px;
1.794 www 4991: }
4992:
4993: .LC_disc_old_item {
1.911 bisitz 4994: background: white;
4995: border: 1px solid black;
4996: margin: 2px;
1.794 www 4997: }
4998:
1.458 albertel 4999: table.LC_pastsubmission {
5000: border: 1px solid black;
5001: margin: 2px;
5002: }
5003:
1.924 bisitz 5004: table#LC_menubuttons {
1.345 albertel 5005: width: 100%;
5006: background: $pgbg;
1.392 albertel 5007: border: 2px;
1.402 albertel 5008: border-collapse: separate;
1.803 bisitz 5009: padding: 0;
1.345 albertel 5010: }
1.392 albertel 5011:
1.801 tempelho 5012: table#LC_title_bar a {
5013: color: $fontmenu;
5014: }
1.836 bisitz 5015:
1.807 droeschl 5016: table#LC_title_bar {
1.819 tempelho 5017: clear: both;
1.836 bisitz 5018: display: none;
1.807 droeschl 5019: }
5020:
1.795 www 5021: table#LC_title_bar,
1.933 droeschl 5022: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5023: table#LC_title_bar.LC_with_remote {
1.359 albertel 5024: width: 100%;
1.392 albertel 5025: border-color: $pgbg;
5026: border-style: solid;
5027: border-width: $border;
1.379 albertel 5028: background: $pgbg;
1.801 tempelho 5029: color: $fontmenu;
1.392 albertel 5030: border-collapse: collapse;
1.803 bisitz 5031: padding: 0;
1.819 tempelho 5032: margin: 0;
1.359 albertel 5033: }
1.795 www 5034:
1.933 droeschl 5035: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5036: margin: 0;
5037: padding: 0;
1.933 droeschl 5038: position: relative;
5039: list-style: none;
1.913 droeschl 5040: }
1.933 droeschl 5041: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5042: display: inline;
5043: }
1.933 droeschl 5044:
5045: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5046: padding: 0;
1.933 droeschl 5047: margin: 0;
5048: float: left;
1.913 droeschl 5049: }
1.933 droeschl 5050: .LC_breadcrumb_tools_tools {
5051: padding: 0;
5052: margin: 0;
1.913 droeschl 5053: float: right;
5054: }
5055:
1.359 albertel 5056: table#LC_title_bar td {
5057: background: $tabbg;
5058: }
1.795 www 5059:
1.911 bisitz 5060: table#LC_menubuttons img {
1.803 bisitz 5061: border: none;
1.346 albertel 5062: }
1.795 www 5063:
1.842 droeschl 5064: .LC_breadcrumbs_component {
1.911 bisitz 5065: float: right;
5066: margin: 0 1em;
1.357 albertel 5067: }
1.842 droeschl 5068: .LC_breadcrumbs_component img {
1.911 bisitz 5069: vertical-align: middle;
1.777 tempelho 5070: }
1.795 www 5071:
1.383 albertel 5072: td.LC_table_cell_checkbox {
5073: text-align: center;
5074: }
1.795 www 5075:
5076: .LC_fontsize_small {
1.911 bisitz 5077: font-size: 70%;
1.705 tempelho 5078: }
5079:
1.844 bisitz 5080: #LC_breadcrumbs {
1.911 bisitz 5081: clear:both;
5082: background: $sidebg;
5083: border-bottom: 1px solid $lg_border_color;
5084: line-height: 2.5em;
1.933 droeschl 5085: overflow: hidden;
1.911 bisitz 5086: margin: 0;
5087: padding: 0;
1.819 tempelho 5088: }
1.862 bisitz 5089:
1.844 bisitz 5090: #LC_head_subbox {
1.911 bisitz 5091: clear:both;
5092: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5093: border: 1px solid $sidebg;
5094: margin: 0 0 10px 0;
1.966 bisitz 5095: padding: 3px;
1.822 bisitz 5096: }
5097:
1.795 www 5098: .LC_fontsize_medium {
1.911 bisitz 5099: font-size: 85%;
1.705 tempelho 5100: }
5101:
1.795 www 5102: .LC_fontsize_large {
1.911 bisitz 5103: font-size: 120%;
1.705 tempelho 5104: }
5105:
1.346 albertel 5106: .LC_menubuttons_inline_text {
5107: color: $font;
1.698 harmsja 5108: font-size: 90%;
1.701 harmsja 5109: padding-left:3px;
1.346 albertel 5110: }
5111:
1.934 droeschl 5112: .LC_menubuttons_inline_text img{
5113: vertical-align: middle;
5114: }
5115:
1.951 onken 5116: li.LC_menubuttons_inline_text img,a {
5117: cursor:pointer;
5118: }
5119:
1.526 www 5120: .LC_menubuttons_link {
5121: text-decoration: none;
5122: }
1.795 www 5123:
1.522 albertel 5124: .LC_menubuttons_category {
1.521 www 5125: color: $font;
1.526 www 5126: background: $pgbg;
1.521 www 5127: font-size: larger;
5128: font-weight: bold;
5129: }
5130:
1.346 albertel 5131: td.LC_menubuttons_text {
1.911 bisitz 5132: color: $font;
1.346 albertel 5133: }
1.706 harmsja 5134:
1.346 albertel 5135: .LC_current_location {
5136: background: $tabbg;
5137: }
1.795 www 5138:
1.938 bisitz 5139: table.LC_data_table {
1.347 albertel 5140: border: 1px solid #000000;
1.402 albertel 5141: border-collapse: separate;
1.426 albertel 5142: border-spacing: 1px;
1.610 albertel 5143: background: $pgbg;
1.347 albertel 5144: }
1.795 www 5145:
1.422 albertel 5146: .LC_data_table_dense {
5147: font-size: small;
5148: }
1.795 www 5149:
1.507 raeburn 5150: table.LC_nested_outer {
5151: border: 1px solid #000000;
1.589 raeburn 5152: border-collapse: collapse;
1.803 bisitz 5153: border-spacing: 0;
1.507 raeburn 5154: width: 100%;
5155: }
1.795 www 5156:
1.879 raeburn 5157: table.LC_innerpickbox,
1.507 raeburn 5158: table.LC_nested {
1.803 bisitz 5159: border: none;
1.589 raeburn 5160: border-collapse: collapse;
1.803 bisitz 5161: border-spacing: 0;
1.507 raeburn 5162: width: 100%;
5163: }
1.795 www 5164:
1.930 faziophi 5165: .ui-accordion,
5166: .ui-accordion table.LC_data_table,
5167: .ui-accordion table.LC_nested_outer{
5168: border: 0px;
5169: border-spacing: 0px;
5170: margin: 3px;
5171: }
5172:
1.911 bisitz 5173: table.LC_data_table tr th,
5174: table.LC_calendar tr th,
1.879 raeburn 5175: table.LC_prior_tries tr th,
5176: table.LC_innerpickbox tr th {
1.349 albertel 5177: font-weight: bold;
5178: background-color: $data_table_head;
1.801 tempelho 5179: color:$fontmenu;
1.701 harmsja 5180: font-size:90%;
1.347 albertel 5181: }
1.795 www 5182:
1.879 raeburn 5183: table.LC_innerpickbox tr th,
5184: table.LC_innerpickbox tr td {
5185: vertical-align: top;
5186: }
5187:
1.711 raeburn 5188: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5189: background-color: #CCCCCC;
1.711 raeburn 5190: font-weight: bold;
5191: text-align: left;
5192: }
1.795 www 5193:
1.912 bisitz 5194: table.LC_data_table tr.LC_odd_row > td {
5195: background-color: $data_table_light;
5196: padding: 2px;
5197: vertical-align: top;
5198: }
5199:
1.809 bisitz 5200: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5201: background-color: $data_table_light;
1.912 bisitz 5202: vertical-align: top;
5203: }
5204:
5205: table.LC_data_table tr.LC_even_row > td {
5206: background-color: $data_table_dark;
1.425 albertel 5207: padding: 2px;
1.900 bisitz 5208: vertical-align: top;
1.347 albertel 5209: }
1.795 www 5210:
1.809 bisitz 5211: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5212: background-color: $data_table_dark;
1.900 bisitz 5213: vertical-align: top;
1.347 albertel 5214: }
1.795 www 5215:
1.425 albertel 5216: table.LC_data_table tr.LC_data_table_highlight td {
5217: background-color: $data_table_darker;
5218: }
1.795 www 5219:
1.639 raeburn 5220: table.LC_data_table tr td.LC_leftcol_header {
5221: background-color: $data_table_head;
5222: font-weight: bold;
5223: }
1.795 www 5224:
1.451 albertel 5225: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5226: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5227: font-weight: bold;
5228: font-style: italic;
5229: text-align: center;
5230: padding: 8px;
1.347 albertel 5231: }
1.795 www 5232:
1.940 bisitz 5233: table.LC_data_table tr.LC_empty_row td {
5234: background-color: $sidebg;
5235: }
5236:
5237: table.LC_nested tr.LC_empty_row td {
5238: background-color: #FFFFFF;
5239: }
5240:
1.890 droeschl 5241: table.LC_caption {
5242: }
5243:
1.507 raeburn 5244: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5245: padding: 4ex
5246: }
1.795 www 5247:
1.507 raeburn 5248: table.LC_nested_outer tr th {
5249: font-weight: bold;
1.801 tempelho 5250: color:$fontmenu;
1.507 raeburn 5251: background-color: $data_table_head;
1.701 harmsja 5252: font-size: small;
1.507 raeburn 5253: border-bottom: 1px solid #000000;
5254: }
1.795 www 5255:
1.507 raeburn 5256: table.LC_nested_outer tr td.LC_subheader {
5257: background-color: $data_table_head;
5258: font-weight: bold;
5259: font-size: small;
5260: border-bottom: 1px solid #000000;
5261: text-align: right;
1.451 albertel 5262: }
1.795 www 5263:
1.507 raeburn 5264: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5265: background-color: #CCCCCC;
1.451 albertel 5266: font-weight: bold;
5267: font-size: small;
1.507 raeburn 5268: text-align: center;
5269: }
1.795 www 5270:
1.589 raeburn 5271: table.LC_nested tr.LC_info_row td.LC_left_item,
5272: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5273: text-align: left;
1.451 albertel 5274: }
1.795 www 5275:
1.507 raeburn 5276: table.LC_nested td {
1.735 bisitz 5277: background-color: #FFFFFF;
1.451 albertel 5278: font-size: small;
1.507 raeburn 5279: }
1.795 www 5280:
1.507 raeburn 5281: table.LC_nested_outer tr th.LC_right_item,
5282: table.LC_nested tr.LC_info_row td.LC_right_item,
5283: table.LC_nested tr.LC_odd_row td.LC_right_item,
5284: table.LC_nested tr td.LC_right_item {
1.451 albertel 5285: text-align: right;
5286: }
5287:
1.930 faziophi 5288: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5289: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5290: text-align: right;
5291: width: 40%;
5292: padding-right:10px;
5293: vertical-align: top;
5294: padding: 5px;
5295: }
5296:
5297: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5298: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5299: text-align: left;
5300: width: 60%;
5301: padding: 2px 4px;
5302: }
5303:
1.507 raeburn 5304: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5305: background-color: #EEEEEE;
1.451 albertel 5306: }
5307:
1.473 raeburn 5308: table.LC_createuser {
5309: }
5310:
5311: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5312: font-size: small;
1.473 raeburn 5313: }
5314:
5315: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5316: background-color: #CCCCCC;
1.473 raeburn 5317: font-weight: bold;
5318: text-align: center;
5319: }
5320:
1.349 albertel 5321: table.LC_calendar {
5322: border: 1px solid #000000;
5323: border-collapse: collapse;
1.917 raeburn 5324: width: 98%;
1.349 albertel 5325: }
1.795 www 5326:
1.349 albertel 5327: table.LC_calendar_pickdate {
5328: font-size: xx-small;
5329: }
1.795 www 5330:
1.349 albertel 5331: table.LC_calendar tr td {
5332: border: 1px solid #000000;
5333: vertical-align: top;
1.917 raeburn 5334: width: 14%;
1.349 albertel 5335: }
1.795 www 5336:
1.349 albertel 5337: table.LC_calendar tr td.LC_calendar_day_empty {
5338: background-color: $data_table_dark;
5339: }
1.795 www 5340:
1.779 bisitz 5341: table.LC_calendar tr td.LC_calendar_day_current {
5342: background-color: $data_table_highlight;
1.777 tempelho 5343: }
1.795 www 5344:
1.938 bisitz 5345: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5346: background-color: $mail_new;
5347: }
1.795 www 5348:
1.938 bisitz 5349: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5350: background-color: $mail_new_hover;
5351: }
1.795 www 5352:
1.938 bisitz 5353: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5354: background-color: $mail_read;
5355: }
1.795 www 5356:
1.938 bisitz 5357: /*
5358: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5359: background-color: $mail_read_hover;
5360: }
1.938 bisitz 5361: */
1.795 www 5362:
1.938 bisitz 5363: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5364: background-color: $mail_replied;
5365: }
1.795 www 5366:
1.938 bisitz 5367: /*
5368: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5369: background-color: $mail_replied_hover;
5370: }
1.938 bisitz 5371: */
1.795 www 5372:
1.938 bisitz 5373: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5374: background-color: $mail_other;
5375: }
1.795 www 5376:
1.938 bisitz 5377: /*
5378: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5379: background-color: $mail_other_hover;
5380: }
1.938 bisitz 5381: */
1.494 raeburn 5382:
1.777 tempelho 5383: table.LC_data_table tr > td.LC_browser_file,
5384: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5385: background: #AAEE77;
1.389 albertel 5386: }
1.795 www 5387:
1.777 tempelho 5388: table.LC_data_table tr > td.LC_browser_file_locked,
5389: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5390: background: #FFAA99;
1.387 albertel 5391: }
1.795 www 5392:
1.777 tempelho 5393: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5394: background: #888888;
1.779 bisitz 5395: }
1.795 www 5396:
1.777 tempelho 5397: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5398: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5399: background: #F8F866;
1.777 tempelho 5400: }
1.795 www 5401:
1.696 bisitz 5402: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5403: background: #E0E8FF;
1.387 albertel 5404: }
1.696 bisitz 5405:
1.707 bisitz 5406: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5407: /* background: #77FF77; */
1.707 bisitz 5408: }
1.795 www 5409:
1.707 bisitz 5410: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5411: border-right: 8px solid #FFFF77;
1.707 bisitz 5412: }
1.795 www 5413:
1.707 bisitz 5414: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5415: border-right: 8px solid #FFAA77;
1.707 bisitz 5416: }
1.795 www 5417:
1.707 bisitz 5418: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5419: border-right: 8px solid #FF7777;
1.707 bisitz 5420: }
1.795 www 5421:
1.707 bisitz 5422: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5423: border-right: 8px solid #AAFF77;
1.707 bisitz 5424: }
1.795 www 5425:
1.707 bisitz 5426: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5427: border-right: 8px solid #11CC55;
1.707 bisitz 5428: }
5429:
1.388 albertel 5430: span.LC_current_location {
1.701 harmsja 5431: font-size:larger;
1.388 albertel 5432: background: $pgbg;
5433: }
1.387 albertel 5434:
1.395 albertel 5435: span.LC_parm_menu_item {
5436: font-size: larger;
5437: }
1.795 www 5438:
1.395 albertel 5439: span.LC_parm_scope_all {
5440: color: red;
5441: }
1.795 www 5442:
1.395 albertel 5443: span.LC_parm_scope_folder {
5444: color: green;
5445: }
1.795 www 5446:
1.395 albertel 5447: span.LC_parm_scope_resource {
5448: color: orange;
5449: }
1.795 www 5450:
1.395 albertel 5451: span.LC_parm_part {
5452: color: blue;
5453: }
1.795 www 5454:
1.911 bisitz 5455: span.LC_parm_folder,
5456: span.LC_parm_symb {
1.395 albertel 5457: font-size: x-small;
5458: font-family: $mono;
5459: color: #AAAAAA;
5460: }
5461:
1.977 bisitz 5462: ul.LC_parm_parmlist li {
5463: display: inline-block;
5464: padding: 0.3em 0.8em;
5465: vertical-align: top;
5466: width: 150px;
5467: border-top:1px solid $lg_border_color;
5468: }
5469:
1.795 www 5470: td.LC_parm_overview_level_menu,
5471: td.LC_parm_overview_map_menu,
5472: td.LC_parm_overview_parm_selectors,
5473: td.LC_parm_overview_restrictions {
1.396 albertel 5474: border: 1px solid black;
5475: border-collapse: collapse;
5476: }
1.795 www 5477:
1.396 albertel 5478: table.LC_parm_overview_restrictions td {
5479: border-width: 1px 4px 1px 4px;
5480: border-style: solid;
5481: border-color: $pgbg;
5482: text-align: center;
5483: }
1.795 www 5484:
1.396 albertel 5485: table.LC_parm_overview_restrictions th {
5486: background: $tabbg;
5487: border-width: 1px 4px 1px 4px;
5488: border-style: solid;
5489: border-color: $pgbg;
5490: }
1.795 www 5491:
1.398 albertel 5492: table#LC_helpmenu {
1.803 bisitz 5493: border: none;
1.398 albertel 5494: height: 55px;
1.803 bisitz 5495: border-spacing: 0;
1.398 albertel 5496: }
5497:
5498: table#LC_helpmenu fieldset legend {
5499: font-size: larger;
5500: }
1.795 www 5501:
1.397 albertel 5502: table#LC_helpmenu_links {
5503: width: 100%;
5504: border: 1px solid black;
5505: background: $pgbg;
1.803 bisitz 5506: padding: 0;
1.397 albertel 5507: border-spacing: 1px;
5508: }
1.795 www 5509:
1.397 albertel 5510: table#LC_helpmenu_links tr td {
5511: padding: 1px;
5512: background: $tabbg;
1.399 albertel 5513: text-align: center;
5514: font-weight: bold;
1.397 albertel 5515: }
1.396 albertel 5516:
1.795 www 5517: table#LC_helpmenu_links a:link,
5518: table#LC_helpmenu_links a:visited,
1.397 albertel 5519: table#LC_helpmenu_links a:active {
5520: text-decoration: none;
5521: color: $font;
5522: }
1.795 www 5523:
1.397 albertel 5524: table#LC_helpmenu_links a:hover {
5525: text-decoration: underline;
5526: color: $vlink;
5527: }
1.396 albertel 5528:
1.417 albertel 5529: .LC_chrt_popup_exists {
5530: border: 1px solid #339933;
5531: margin: -1px;
5532: }
1.795 www 5533:
1.417 albertel 5534: .LC_chrt_popup_up {
5535: border: 1px solid yellow;
5536: margin: -1px;
5537: }
1.795 www 5538:
1.417 albertel 5539: .LC_chrt_popup {
5540: border: 1px solid #8888FF;
5541: background: #CCCCFF;
5542: }
1.795 www 5543:
1.421 albertel 5544: table.LC_pick_box {
5545: border-collapse: separate;
5546: background: white;
5547: border: 1px solid black;
5548: border-spacing: 1px;
5549: }
1.795 www 5550:
1.421 albertel 5551: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5552: background: $sidebg;
1.421 albertel 5553: font-weight: bold;
1.900 bisitz 5554: text-align: left;
1.740 bisitz 5555: vertical-align: top;
1.421 albertel 5556: width: 184px;
5557: padding: 8px;
5558: }
1.795 www 5559:
1.579 raeburn 5560: table.LC_pick_box td.LC_pick_box_value {
5561: text-align: left;
5562: padding: 8px;
5563: }
1.795 www 5564:
1.579 raeburn 5565: table.LC_pick_box td.LC_pick_box_select {
5566: text-align: left;
5567: padding: 8px;
5568: }
1.795 www 5569:
1.424 albertel 5570: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5571: padding: 0;
1.421 albertel 5572: height: 1px;
5573: background: black;
5574: }
1.795 www 5575:
1.421 albertel 5576: table.LC_pick_box td.LC_pick_box_submit {
5577: text-align: right;
5578: }
1.795 www 5579:
1.579 raeburn 5580: table.LC_pick_box td.LC_evenrow_value {
5581: text-align: left;
5582: padding: 8px;
5583: background-color: $data_table_light;
5584: }
1.795 www 5585:
1.579 raeburn 5586: table.LC_pick_box td.LC_oddrow_value {
5587: text-align: left;
5588: padding: 8px;
5589: background-color: $data_table_light;
5590: }
1.795 www 5591:
1.579 raeburn 5592: span.LC_helpform_receipt_cat {
5593: font-weight: bold;
5594: }
1.795 www 5595:
1.424 albertel 5596: table.LC_group_priv_box {
5597: background: white;
5598: border: 1px solid black;
5599: border-spacing: 1px;
5600: }
1.795 www 5601:
1.424 albertel 5602: table.LC_group_priv_box td.LC_pick_box_title {
5603: background: $tabbg;
5604: font-weight: bold;
5605: text-align: right;
5606: width: 184px;
5607: }
1.795 www 5608:
1.424 albertel 5609: table.LC_group_priv_box td.LC_groups_fixed {
5610: background: $data_table_light;
5611: text-align: center;
5612: }
1.795 www 5613:
1.424 albertel 5614: table.LC_group_priv_box td.LC_groups_optional {
5615: background: $data_table_dark;
5616: text-align: center;
5617: }
1.795 www 5618:
1.424 albertel 5619: table.LC_group_priv_box td.LC_groups_functionality {
5620: background: $data_table_darker;
5621: text-align: center;
5622: font-weight: bold;
5623: }
1.795 www 5624:
1.424 albertel 5625: table.LC_group_priv td {
5626: text-align: left;
1.803 bisitz 5627: padding: 0;
1.424 albertel 5628: }
5629:
5630: .LC_navbuttons {
5631: margin: 2ex 0ex 2ex 0ex;
5632: }
1.795 www 5633:
1.423 albertel 5634: .LC_topic_bar {
5635: font-weight: bold;
5636: background: $tabbg;
1.918 wenzelju 5637: margin: 1em 0em 1em 2em;
1.805 bisitz 5638: padding: 3px;
1.918 wenzelju 5639: font-size: 1.2em;
1.423 albertel 5640: }
1.795 www 5641:
1.423 albertel 5642: .LC_topic_bar span {
1.918 wenzelju 5643: left: 0.5em;
5644: position: absolute;
1.423 albertel 5645: vertical-align: middle;
1.918 wenzelju 5646: font-size: 1.2em;
1.423 albertel 5647: }
1.795 www 5648:
1.423 albertel 5649: table.LC_course_group_status {
5650: margin: 20px;
5651: }
1.795 www 5652:
1.423 albertel 5653: table.LC_status_selector td {
5654: vertical-align: top;
5655: text-align: center;
1.424 albertel 5656: padding: 4px;
5657: }
1.795 www 5658:
1.599 albertel 5659: div.LC_feedback_link {
1.616 albertel 5660: clear: both;
1.829 kalberla 5661: background: $sidebg;
1.779 bisitz 5662: width: 100%;
1.829 kalberla 5663: padding-bottom: 10px;
5664: border: 1px $tabbg solid;
1.833 kalberla 5665: height: 22px;
5666: line-height: 22px;
5667: padding-top: 5px;
5668: }
5669:
5670: div.LC_feedback_link img {
5671: height: 22px;
1.867 kalberla 5672: vertical-align:middle;
1.829 kalberla 5673: }
5674:
1.911 bisitz 5675: div.LC_feedback_link a {
1.829 kalberla 5676: text-decoration: none;
1.489 raeburn 5677: }
1.795 www 5678:
1.867 kalberla 5679: div.LC_comblock {
1.911 bisitz 5680: display:inline;
1.867 kalberla 5681: color:$font;
5682: font-size:90%;
5683: }
5684:
5685: div.LC_feedback_link div.LC_comblock {
5686: padding-left:5px;
5687: }
5688:
5689: div.LC_feedback_link div.LC_comblock a {
5690: color:$font;
5691: }
5692:
1.489 raeburn 5693: span.LC_feedback_link {
1.858 bisitz 5694: /* background: $feedback_link_bg; */
1.599 albertel 5695: font-size: larger;
5696: }
1.795 www 5697:
1.599 albertel 5698: span.LC_message_link {
1.858 bisitz 5699: /* background: $feedback_link_bg; */
1.599 albertel 5700: font-size: larger;
5701: position: absolute;
5702: right: 1em;
1.489 raeburn 5703: }
1.421 albertel 5704:
1.515 albertel 5705: table.LC_prior_tries {
1.524 albertel 5706: border: 1px solid #000000;
5707: border-collapse: separate;
5708: border-spacing: 1px;
1.515 albertel 5709: }
1.523 albertel 5710:
1.515 albertel 5711: table.LC_prior_tries td {
1.524 albertel 5712: padding: 2px;
1.515 albertel 5713: }
1.523 albertel 5714:
5715: .LC_answer_correct {
1.795 www 5716: background: lightgreen;
5717: color: darkgreen;
5718: padding: 6px;
1.523 albertel 5719: }
1.795 www 5720:
1.523 albertel 5721: .LC_answer_charged_try {
1.797 www 5722: background: #FFAAAA;
1.795 www 5723: color: darkred;
5724: padding: 6px;
1.523 albertel 5725: }
1.795 www 5726:
1.779 bisitz 5727: .LC_answer_not_charged_try,
1.523 albertel 5728: .LC_answer_no_grade,
5729: .LC_answer_late {
1.795 www 5730: background: lightyellow;
1.523 albertel 5731: color: black;
1.795 www 5732: padding: 6px;
1.523 albertel 5733: }
1.795 www 5734:
1.523 albertel 5735: .LC_answer_previous {
1.795 www 5736: background: lightblue;
5737: color: darkblue;
5738: padding: 6px;
1.523 albertel 5739: }
1.795 www 5740:
1.779 bisitz 5741: .LC_answer_no_message {
1.777 tempelho 5742: background: #FFFFFF;
5743: color: black;
1.795 www 5744: padding: 6px;
1.779 bisitz 5745: }
1.795 www 5746:
1.779 bisitz 5747: .LC_answer_unknown {
5748: background: orange;
5749: color: black;
1.795 www 5750: padding: 6px;
1.777 tempelho 5751: }
1.795 www 5752:
1.529 albertel 5753: span.LC_prior_numerical,
5754: span.LC_prior_string,
5755: span.LC_prior_custom,
5756: span.LC_prior_reaction,
5757: span.LC_prior_math {
1.925 bisitz 5758: font-family: $mono;
1.523 albertel 5759: white-space: pre;
5760: }
5761:
1.525 albertel 5762: span.LC_prior_string {
1.925 bisitz 5763: font-family: $mono;
1.525 albertel 5764: white-space: pre;
5765: }
5766:
1.523 albertel 5767: table.LC_prior_option {
5768: width: 100%;
5769: border-collapse: collapse;
5770: }
1.795 www 5771:
1.911 bisitz 5772: table.LC_prior_rank,
1.795 www 5773: table.LC_prior_match {
1.528 albertel 5774: border-collapse: collapse;
5775: }
1.795 www 5776:
1.528 albertel 5777: table.LC_prior_option tr td,
5778: table.LC_prior_rank tr td,
5779: table.LC_prior_match tr td {
1.524 albertel 5780: border: 1px solid #000000;
1.515 albertel 5781: }
5782:
1.855 bisitz 5783: .LC_nobreak {
1.544 albertel 5784: white-space: nowrap;
1.519 raeburn 5785: }
5786:
1.576 raeburn 5787: span.LC_cusr_emph {
5788: font-style: italic;
5789: }
5790:
1.633 raeburn 5791: span.LC_cusr_subheading {
5792: font-weight: normal;
5793: font-size: 85%;
5794: }
5795:
1.861 bisitz 5796: div.LC_docs_entry_move {
1.859 bisitz 5797: border: 1px solid #BBBBBB;
1.545 albertel 5798: background: #DDDDDD;
1.861 bisitz 5799: width: 22px;
1.859 bisitz 5800: padding: 1px;
5801: margin: 0;
1.545 albertel 5802: }
5803:
1.861 bisitz 5804: table.LC_data_table tr > td.LC_docs_entry_commands,
5805: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5806: background: #DDDDDD;
5807: font-size: x-small;
5808: }
1.795 www 5809:
1.861 bisitz 5810: .LC_docs_entry_parameter {
5811: white-space: nowrap;
5812: }
5813:
1.544 albertel 5814: .LC_docs_copy {
1.545 albertel 5815: color: #000099;
1.544 albertel 5816: }
1.795 www 5817:
1.544 albertel 5818: .LC_docs_cut {
1.545 albertel 5819: color: #550044;
1.544 albertel 5820: }
1.795 www 5821:
1.544 albertel 5822: .LC_docs_rename {
1.545 albertel 5823: color: #009900;
1.544 albertel 5824: }
1.795 www 5825:
1.544 albertel 5826: .LC_docs_remove {
1.545 albertel 5827: color: #990000;
5828: }
5829:
1.547 albertel 5830: .LC_docs_reinit_warn,
5831: .LC_docs_ext_edit {
5832: font-size: x-small;
5833: }
5834:
1.545 albertel 5835: table.LC_docs_adddocs td,
5836: table.LC_docs_adddocs th {
5837: border: 1px solid #BBBBBB;
5838: padding: 4px;
5839: background: #DDDDDD;
1.543 albertel 5840: }
5841:
1.584 albertel 5842: table.LC_sty_begin {
5843: background: #BBFFBB;
5844: }
1.795 www 5845:
1.584 albertel 5846: table.LC_sty_end {
5847: background: #FFBBBB;
5848: }
5849:
1.589 raeburn 5850: table.LC_double_column {
1.803 bisitz 5851: border-width: 0;
1.589 raeburn 5852: border-collapse: collapse;
5853: width: 100%;
5854: padding: 2px;
5855: }
5856:
5857: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5858: top: 2px;
1.589 raeburn 5859: left: 2px;
5860: width: 47%;
5861: vertical-align: top;
5862: }
5863:
5864: table.LC_double_column tr td.LC_right_col {
5865: top: 2px;
1.779 bisitz 5866: right: 2px;
1.589 raeburn 5867: width: 47%;
5868: vertical-align: top;
5869: }
5870:
1.591 raeburn 5871: div.LC_left_float {
5872: float: left;
5873: padding-right: 5%;
1.597 albertel 5874: padding-bottom: 4px;
1.591 raeburn 5875: }
5876:
5877: div.LC_clear_float_header {
1.597 albertel 5878: padding-bottom: 2px;
1.591 raeburn 5879: }
5880:
5881: div.LC_clear_float_footer {
1.597 albertel 5882: padding-top: 10px;
1.591 raeburn 5883: clear: both;
5884: }
5885:
1.597 albertel 5886: div.LC_grade_show_user {
1.941 bisitz 5887: /* border-left: 5px solid $sidebg; */
5888: border-top: 5px solid #000000;
5889: margin: 50px 0 0 0;
1.936 bisitz 5890: padding: 15px 0 5px 10px;
1.597 albertel 5891: }
1.795 www 5892:
1.936 bisitz 5893: div.LC_grade_show_user_odd_row {
1.941 bisitz 5894: /* border-left: 5px solid #000000; */
5895: }
5896:
5897: div.LC_grade_show_user div.LC_Box {
5898: margin-right: 50px;
1.597 albertel 5899: }
5900:
5901: div.LC_grade_submissions,
5902: div.LC_grade_message_center,
1.936 bisitz 5903: div.LC_grade_info_links {
1.597 albertel 5904: margin: 5px;
5905: width: 99%;
5906: background: #FFFFFF;
5907: }
1.795 www 5908:
1.597 albertel 5909: div.LC_grade_submissions_header,
1.936 bisitz 5910: div.LC_grade_message_center_header {
1.705 tempelho 5911: font-weight: bold;
5912: font-size: large;
1.597 albertel 5913: }
1.795 www 5914:
1.597 albertel 5915: div.LC_grade_submissions_body,
1.936 bisitz 5916: div.LC_grade_message_center_body {
1.597 albertel 5917: border: 1px solid black;
5918: width: 99%;
5919: background: #FFFFFF;
5920: }
1.795 www 5921:
1.613 albertel 5922: table.LC_scantron_action {
5923: width: 100%;
5924: }
1.795 www 5925:
1.613 albertel 5926: table.LC_scantron_action tr th {
1.698 harmsja 5927: font-weight:bold;
5928: font-style:normal;
1.613 albertel 5929: }
1.795 www 5930:
1.779 bisitz 5931: .LC_edit_problem_header,
1.614 albertel 5932: div.LC_edit_problem_footer {
1.705 tempelho 5933: font-weight: normal;
5934: font-size: medium;
1.602 albertel 5935: margin: 2px;
1.600 albertel 5936: }
1.795 www 5937:
1.600 albertel 5938: div.LC_edit_problem_header,
1.602 albertel 5939: div.LC_edit_problem_header div,
1.614 albertel 5940: div.LC_edit_problem_footer,
5941: div.LC_edit_problem_footer div,
1.602 albertel 5942: div.LC_edit_problem_editxml_header,
5943: div.LC_edit_problem_editxml_header div {
1.600 albertel 5944: margin-top: 5px;
5945: }
1.795 www 5946:
1.600 albertel 5947: div.LC_edit_problem_header_title {
1.705 tempelho 5948: font-weight: bold;
5949: font-size: larger;
1.602 albertel 5950: background: $tabbg;
5951: padding: 3px;
5952: }
1.795 www 5953:
1.602 albertel 5954: table.LC_edit_problem_header_title {
5955: width: 100%;
1.600 albertel 5956: background: $tabbg;
1.602 albertel 5957: }
5958:
5959: div.LC_edit_problem_discards {
5960: float: left;
5961: padding-bottom: 5px;
5962: }
1.795 www 5963:
1.602 albertel 5964: div.LC_edit_problem_saves {
5965: float: right;
5966: padding-bottom: 5px;
1.600 albertel 5967: }
1.795 www 5968:
1.911 bisitz 5969: img.stift {
1.803 bisitz 5970: border-width: 0;
5971: vertical-align: middle;
1.677 riegler 5972: }
1.680 riegler 5973:
1.923 bisitz 5974: table td.LC_mainmenu_col_fieldset {
1.680 riegler 5975: vertical-align: top;
1.777 tempelho 5976: }
1.795 www 5977:
1.716 raeburn 5978: div.LC_createcourse {
1.911 bisitz 5979: margin: 10px 10px 10px 10px;
1.716 raeburn 5980: }
5981:
1.917 raeburn 5982: .LC_dccid {
5983: margin: 0.2em 0 0 0;
5984: padding: 0;
5985: font-size: 90%;
5986: display:none;
5987: }
5988:
1.698 harmsja 5989: a:hover,
1.897 wenzelju 5990: ol.LC_primary_menu a:hover,
1.721 harmsja 5991: ol#LC_MenuBreadcrumbs a:hover,
5992: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5993: ul#LC_secondary_menu a:hover,
1.721 harmsja 5994: .LC_FormSectionClearButton input:hover
1.795 www 5995: ul.LC_TabContent li:hover a {
1.952 onken 5996: color:$button_hover;
1.911 bisitz 5997: text-decoration:none;
1.693 droeschl 5998: }
5999:
1.779 bisitz 6000: h1 {
1.911 bisitz 6001: padding: 0;
6002: line-height:130%;
1.693 droeschl 6003: }
1.698 harmsja 6004:
1.911 bisitz 6005: h2,
6006: h3,
6007: h4,
6008: h5,
6009: h6 {
6010: margin: 5px 0 5px 0;
6011: padding: 0;
6012: line-height:130%;
1.693 droeschl 6013: }
1.795 www 6014:
6015: .LC_hcell {
1.911 bisitz 6016: padding:3px 15px 3px 15px;
6017: margin: 0;
6018: background-color:$tabbg;
6019: color:$fontmenu;
6020: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6021: }
1.795 www 6022:
1.840 bisitz 6023: .LC_Box > .LC_hcell {
1.911 bisitz 6024: margin: 0 -10px 10px -10px;
1.835 bisitz 6025: }
6026:
1.721 harmsja 6027: .LC_noBorder {
1.911 bisitz 6028: border: 0;
1.698 harmsja 6029: }
1.693 droeschl 6030:
1.721 harmsja 6031: .LC_FormSectionClearButton input {
1.911 bisitz 6032: background-color:transparent;
6033: border: none;
6034: cursor:pointer;
6035: text-decoration:underline;
1.693 droeschl 6036: }
1.763 bisitz 6037:
6038: .LC_help_open_topic {
1.911 bisitz 6039: color: #FFFFFF;
6040: background-color: #EEEEFF;
6041: margin: 1px;
6042: padding: 4px;
6043: border: 1px solid #000033;
6044: white-space: nowrap;
6045: /* vertical-align: middle; */
1.759 neumanie 6046: }
1.693 droeschl 6047:
1.911 bisitz 6048: dl,
6049: ul,
6050: div,
6051: fieldset {
6052: margin: 10px 10px 10px 0;
6053: /* overflow: hidden; */
1.693 droeschl 6054: }
1.795 www 6055:
1.838 bisitz 6056: fieldset > legend {
1.911 bisitz 6057: font-weight: bold;
6058: padding: 0 5px 0 5px;
1.838 bisitz 6059: }
6060:
1.813 bisitz 6061: #LC_nav_bar {
1.911 bisitz 6062: float: left;
1.966 bisitz 6063: margin: 0 0 2px 0;
1.807 droeschl 6064: }
6065:
1.916 droeschl 6066: #LC_realm {
6067: margin: 0.2em 0 0 0;
6068: padding: 0;
6069: font-weight: bold;
6070: text-align: center;
6071: }
6072:
1.911 bisitz 6073: #LC_nav_bar em {
6074: font-weight: bold;
6075: font-style: normal;
1.807 droeschl 6076: }
6077:
1.897 wenzelju 6078: ol.LC_primary_menu {
1.911 bisitz 6079: float: right;
1.934 droeschl 6080: margin: 0;
1.807 droeschl 6081: }
6082:
1.852 droeschl 6083: ol#LC_PathBreadcrumbs {
1.911 bisitz 6084: margin: 0;
1.693 droeschl 6085: }
6086:
1.897 wenzelju 6087: ol.LC_primary_menu li {
1.911 bisitz 6088: display: inline;
6089: padding: 5px 5px 0 10px;
6090: vertical-align: top;
1.693 droeschl 6091: }
6092:
1.897 wenzelju 6093: ol.LC_primary_menu li img {
1.911 bisitz 6094: vertical-align: bottom;
1.934 droeschl 6095: height: 1.1em;
1.693 droeschl 6096: }
6097:
1.897 wenzelju 6098: ol.LC_primary_menu a {
1.911 bisitz 6099: color: RGB(80, 80, 80);
6100: text-decoration: none;
1.693 droeschl 6101: }
1.795 www 6102:
1.949 droeschl 6103: ol.LC_primary_menu a.LC_new_message {
6104: font-weight:bold;
6105: color: darkred;
6106: }
6107:
1.975 raeburn 6108: ol.LC_docs_parameters {
6109: margin-left: 0;
6110: padding: 0;
6111: list-style: none;
6112: }
6113:
6114: ol.LC_docs_parameters li {
6115: margin: 0;
6116: padding-right: 20px;
6117: display: inline;
6118: }
6119:
1.976 raeburn 6120: ol.LC_docs_parameters li:before {
6121: content: "\\002022 \\0020";
6122: }
6123:
6124: li.LC_docs_parameters_title {
6125: font-weight: bold;
6126: }
6127:
6128: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6129: content: "";
6130: }
6131:
1.897 wenzelju 6132: ul#LC_secondary_menu {
1.911 bisitz 6133: clear: both;
6134: color: $fontmenu;
6135: background: $tabbg;
6136: list-style: none;
6137: padding: 0;
6138: margin: 0;
6139: width: 100%;
1.808 droeschl 6140: }
6141:
1.897 wenzelju 6142: ul#LC_secondary_menu li {
1.911 bisitz 6143: font-weight: bold;
6144: line-height: 1.8em;
6145: padding: 0 0.8em;
6146: border-right: 1px solid black;
6147: display: inline;
6148: vertical-align: middle;
1.807 droeschl 6149: }
6150:
1.847 tempelho 6151: ul.LC_TabContent {
1.911 bisitz 6152: display:block;
6153: background: $sidebg;
6154: border-bottom: solid 1px $lg_border_color;
6155: list-style:none;
6156: margin: 0 -10px;
6157: padding: 0;
1.693 droeschl 6158: }
6159:
1.795 www 6160: ul.LC_TabContent li,
6161: ul.LC_TabContentBigger li {
1.911 bisitz 6162: float:left;
1.741 harmsja 6163: }
1.795 www 6164:
1.897 wenzelju 6165: ul#LC_secondary_menu li a {
1.911 bisitz 6166: color: $fontmenu;
6167: text-decoration: none;
1.693 droeschl 6168: }
1.795 www 6169:
1.721 harmsja 6170: ul.LC_TabContent {
1.952 onken 6171: min-height:20px;
1.721 harmsja 6172: }
1.795 www 6173:
6174: ul.LC_TabContent li {
1.911 bisitz 6175: vertical-align:middle;
1.959 onken 6176: padding: 0 16px 0 10px;
1.911 bisitz 6177: background-color:$tabbg;
6178: border-bottom:solid 1px $lg_border_color;
1.952 onken 6179: border-right: solid 1px $font;
1.721 harmsja 6180: }
1.795 www 6181:
1.847 tempelho 6182: ul.LC_TabContent .right {
1.911 bisitz 6183: float:right;
1.847 tempelho 6184: }
6185:
1.911 bisitz 6186: ul.LC_TabContent li a,
6187: ul.LC_TabContent li {
6188: color:rgb(47,47,47);
6189: text-decoration:none;
6190: font-size:95%;
6191: font-weight:bold;
1.952 onken 6192: min-height:20px;
6193: }
6194:
1.959 onken 6195: ul.LC_TabContent li a:hover,
6196: ul.LC_TabContent li a:focus {
1.952 onken 6197: color: $button_hover;
1.959 onken 6198: background:none;
6199: outline:none;
1.952 onken 6200: }
6201:
6202: ul.LC_TabContent li:hover {
6203: color: $button_hover;
6204: cursor:pointer;
1.721 harmsja 6205: }
1.795 www 6206:
1.911 bisitz 6207: ul.LC_TabContent li.active {
1.952 onken 6208: color: $font;
1.911 bisitz 6209: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6210: border-bottom:solid 1px #FFFFFF;
6211: cursor: default;
1.744 ehlerst 6212: }
1.795 www 6213:
1.959 onken 6214: ul.LC_TabContent li.active a {
6215: color:$font;
6216: background:#FFFFFF;
6217: outline: none;
6218: }
1.870 tempelho 6219: #maincoursedoc {
1.911 bisitz 6220: clear:both;
1.870 tempelho 6221: }
6222:
6223: ul.LC_TabContentBigger {
1.911 bisitz 6224: display:block;
6225: list-style:none;
6226: padding: 0;
1.870 tempelho 6227: }
6228:
1.795 www 6229: ul.LC_TabContentBigger li {
1.911 bisitz 6230: vertical-align:bottom;
6231: height: 30px;
6232: font-size:110%;
6233: font-weight:bold;
6234: color: #737373;
1.841 tempelho 6235: }
6236:
1.957 onken 6237: ul.LC_TabContentBigger li.active {
6238: position: relative;
6239: top: 1px;
6240: }
6241:
1.870 tempelho 6242: ul.LC_TabContentBigger li a {
1.911 bisitz 6243: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6244: height: 30px;
6245: line-height: 30px;
6246: text-align: center;
6247: display: block;
6248: text-decoration: none;
1.958 onken 6249: outline: none;
1.741 harmsja 6250: }
1.795 www 6251:
1.870 tempelho 6252: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6253: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6254: color:$font;
1.744 ehlerst 6255: }
1.795 www 6256:
1.870 tempelho 6257: ul.LC_TabContentBigger li b {
1.911 bisitz 6258: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6259: display: block;
6260: float: left;
6261: padding: 0 30px;
1.957 onken 6262: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6263: }
6264:
1.956 onken 6265: ul.LC_TabContentBigger li:hover b {
6266: color:$button_hover;
6267: }
6268:
1.870 tempelho 6269: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6270: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6271: color:$font;
1.957 onken 6272: border: 0;
1.956 onken 6273: cursor:default;
1.741 harmsja 6274: }
1.693 droeschl 6275:
1.870 tempelho 6276:
1.862 bisitz 6277: ul.LC_CourseBreadcrumbs {
6278: background: $sidebg;
6279: line-height: 32px;
6280: padding-left: 10px;
6281: margin: 0 0 10px 0;
6282: list-style-position: inside;
6283:
6284: }
6285:
1.911 bisitz 6286: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6287: ol#LC_PathBreadcrumbs {
1.911 bisitz 6288: padding-left: 10px;
6289: margin: 0;
1.933 droeschl 6290: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6291: }
6292:
1.911 bisitz 6293: ol#LC_MenuBreadcrumbs li,
6294: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6295: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6296: display: inline;
1.933 droeschl 6297: white-space: normal;
1.693 droeschl 6298: }
6299:
1.823 bisitz 6300: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6301: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6302: text-decoration: none;
6303: font-size:90%;
1.693 droeschl 6304: }
1.795 www 6305:
1.969 droeschl 6306: ol#LC_MenuBreadcrumbs h1 {
6307: display: inline;
6308: font-size: 90%;
6309: line-height: 2.5em;
6310: margin: 0;
6311: padding: 0;
6312: }
6313:
1.795 www 6314: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6315: text-decoration:none;
6316: font-size:100%;
6317: font-weight:bold;
1.693 droeschl 6318: }
1.795 www 6319:
1.840 bisitz 6320: .LC_Box {
1.911 bisitz 6321: border: solid 1px $lg_border_color;
6322: padding: 0 10px 10px 10px;
1.746 neumanie 6323: }
1.795 www 6324:
6325: .LC_AboutMe_Image {
1.911 bisitz 6326: float:left;
6327: margin-right:10px;
1.747 neumanie 6328: }
1.795 www 6329:
6330: .LC_Clear_AboutMe_Image {
1.911 bisitz 6331: clear:left;
1.747 neumanie 6332: }
1.795 www 6333:
1.721 harmsja 6334: dl.LC_ListStyleClean dt {
1.911 bisitz 6335: padding-right: 5px;
6336: display: table-header-group;
1.693 droeschl 6337: }
6338:
1.721 harmsja 6339: dl.LC_ListStyleClean dd {
1.911 bisitz 6340: display: table-row;
1.693 droeschl 6341: }
6342:
1.721 harmsja 6343: .LC_ListStyleClean,
6344: .LC_ListStyleSimple,
6345: .LC_ListStyleNormal,
1.795 www 6346: .LC_ListStyleSpecial {
1.911 bisitz 6347: /* display:block; */
6348: list-style-position: inside;
6349: list-style-type: none;
6350: overflow: hidden;
6351: padding: 0;
1.693 droeschl 6352: }
6353:
1.721 harmsja 6354: .LC_ListStyleSimple li,
6355: .LC_ListStyleSimple dd,
6356: .LC_ListStyleNormal li,
6357: .LC_ListStyleNormal dd,
6358: .LC_ListStyleSpecial li,
1.795 www 6359: .LC_ListStyleSpecial dd {
1.911 bisitz 6360: margin: 0;
6361: padding: 5px 5px 5px 10px;
6362: clear: both;
1.693 droeschl 6363: }
6364:
1.721 harmsja 6365: .LC_ListStyleClean li,
6366: .LC_ListStyleClean dd {
1.911 bisitz 6367: padding-top: 0;
6368: padding-bottom: 0;
1.693 droeschl 6369: }
6370:
1.721 harmsja 6371: .LC_ListStyleSimple dd,
1.795 www 6372: .LC_ListStyleSimple li {
1.911 bisitz 6373: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6374: }
6375:
1.721 harmsja 6376: .LC_ListStyleSpecial li,
6377: .LC_ListStyleSpecial dd {
1.911 bisitz 6378: list-style-type: none;
6379: background-color: RGB(220, 220, 220);
6380: margin-bottom: 4px;
1.693 droeschl 6381: }
6382:
1.721 harmsja 6383: table.LC_SimpleTable {
1.911 bisitz 6384: margin:5px;
6385: border:solid 1px $lg_border_color;
1.795 www 6386: }
1.693 droeschl 6387:
1.721 harmsja 6388: table.LC_SimpleTable tr {
1.911 bisitz 6389: padding: 0;
6390: border:solid 1px $lg_border_color;
1.693 droeschl 6391: }
1.795 www 6392:
6393: table.LC_SimpleTable thead {
1.911 bisitz 6394: background:rgb(220,220,220);
1.693 droeschl 6395: }
6396:
1.721 harmsja 6397: div.LC_columnSection {
1.911 bisitz 6398: display: block;
6399: clear: both;
6400: overflow: hidden;
6401: margin: 0;
1.693 droeschl 6402: }
6403:
1.721 harmsja 6404: div.LC_columnSection>* {
1.911 bisitz 6405: float: left;
6406: margin: 10px 20px 10px 0;
6407: overflow:hidden;
1.693 droeschl 6408: }
1.721 harmsja 6409:
1.795 www 6410: table em {
1.911 bisitz 6411: font-weight: bold;
6412: font-style: normal;
1.748 schulted 6413: }
1.795 www 6414:
1.779 bisitz 6415: table.LC_tableBrowseRes,
1.795 www 6416: table.LC_tableOfContent {
1.911 bisitz 6417: border:none;
6418: border-spacing: 1px;
6419: padding: 3px;
6420: background-color: #FFFFFF;
6421: font-size: 90%;
1.753 droeschl 6422: }
1.789 droeschl 6423:
1.911 bisitz 6424: table.LC_tableOfContent {
6425: border-collapse: collapse;
1.789 droeschl 6426: }
6427:
1.771 droeschl 6428: table.LC_tableBrowseRes a,
1.768 schulted 6429: table.LC_tableOfContent a {
1.911 bisitz 6430: background-color: transparent;
6431: text-decoration: none;
1.753 droeschl 6432: }
6433:
1.795 www 6434: table.LC_tableOfContent img {
1.911 bisitz 6435: border: none;
6436: height: 1.3em;
6437: vertical-align: text-bottom;
6438: margin-right: 0.3em;
1.753 droeschl 6439: }
1.757 schulted 6440:
1.795 www 6441: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6442: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6443: }
6444:
1.795 www 6445: a#LC_content_toolbar_everything {
1.911 bisitz 6446: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6447: }
6448:
1.795 www 6449: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6450: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6451: }
6452:
1.795 www 6453: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6454: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6455: }
6456:
1.795 www 6457: a#LC_content_toolbar_changefolder {
1.911 bisitz 6458: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6459: }
6460:
1.795 www 6461: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6462: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6463: }
6464:
1.795 www 6465: ul#LC_toolbar li a:hover {
1.911 bisitz 6466: background-position: bottom center;
1.757 schulted 6467: }
6468:
1.795 www 6469: ul#LC_toolbar {
1.911 bisitz 6470: padding: 0;
6471: margin: 2px;
6472: list-style:none;
6473: position:relative;
6474: background-color:white;
1.757 schulted 6475: }
6476:
1.795 www 6477: ul#LC_toolbar li {
1.911 bisitz 6478: border:1px solid white;
6479: padding: 0;
6480: margin: 0;
6481: float: left;
6482: display:inline;
6483: vertical-align:middle;
6484: }
1.757 schulted 6485:
1.783 amueller 6486:
1.795 www 6487: a.LC_toolbarItem {
1.911 bisitz 6488: display:block;
6489: padding: 0;
6490: margin: 0;
6491: height: 32px;
6492: width: 32px;
6493: color:white;
6494: border: none;
6495: background-repeat:no-repeat;
6496: background-color:transparent;
1.757 schulted 6497: }
6498:
1.915 droeschl 6499: ul.LC_funclist {
6500: margin: 0;
6501: padding: 0.5em 1em 0.5em 0;
6502: }
6503:
1.933 droeschl 6504: ul.LC_funclist > li:first-child {
6505: font-weight:bold;
6506: margin-left:0.8em;
6507: }
6508:
1.915 droeschl 6509: ul.LC_funclist + ul.LC_funclist {
6510: /*
6511: left border as a seperator if we have more than
6512: one list
6513: */
6514: border-left: 1px solid $sidebg;
6515: /*
6516: this hides the left border behind the border of the
6517: outer box if element is wrapped to the next 'line'
6518: */
6519: margin-left: -1px;
6520: }
6521:
1.843 bisitz 6522: ul.LC_funclist li {
1.915 droeschl 6523: display: inline;
1.782 bisitz 6524: white-space: nowrap;
1.915 droeschl 6525: margin: 0 0 0 25px;
6526: line-height: 150%;
1.782 bisitz 6527: }
6528:
1.930 faziophi 6529: .ui-accordion .LC_advanced_toggle {
6530: float: right;
6531: font-size: 90%;
6532: padding: 0px 4px
6533: }
1.757 schulted 6534:
1.974 wenzelju 6535: .LC_hidden {
6536: display: none;
6537: }
6538:
1.343 albertel 6539: END
6540: }
6541:
1.306 albertel 6542: =pod
6543:
6544: =item * &headtag()
6545:
6546: Returns a uniform footer for LON-CAPA web pages.
6547:
1.307 albertel 6548: Inputs: $title - optional title for the head
6549: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6550: $args - optional arguments
1.319 albertel 6551: force_register - if is true call registerurl so the remote is
6552: informed
1.415 albertel 6553: redirect -> array ref of
6554: 1- seconds before redirect occurs
6555: 2- url to redirect to
6556: 3- whether the side effect should occur
1.315 albertel 6557: (side effect of setting
6558: $env{'internal.head.redirect'} to the url
6559: redirected too)
1.352 albertel 6560: domain -> force to color decorate a page for a specific
6561: domain
6562: function -> force usage of a specific rolish color scheme
6563: bgcolor -> override the default page bgcolor
1.460 albertel 6564: no_auto_mt_title
6565: -> prevent &mt()ing the title arg
1.464 albertel 6566:
1.306 albertel 6567: =cut
6568:
6569: sub headtag {
1.313 albertel 6570: my ($title,$head_extra,$args) = @_;
1.306 albertel 6571:
1.363 albertel 6572: my $function = $args->{'function'} || &get_users_function();
6573: my $domain = $args->{'domain'} || &determinedomain();
6574: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6575: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6576: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6577: #time(),
1.418 albertel 6578: $env{'environment.color.timestamp'},
1.363 albertel 6579: $function,$domain,$bgcolor);
6580:
1.369 www 6581: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6582:
1.308 albertel 6583: my $result =
6584: '<head>'.
1.461 albertel 6585: &font_settings();
1.319 albertel 6586:
1.461 albertel 6587: if (!$args->{'frameset'}) {
6588: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6589: }
1.962 droeschl 6590: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
6591: $result .= Apache::lonxml::display_title();
1.319 albertel 6592: }
1.436 albertel 6593: if (!$args->{'no_nav_bar'}
6594: && !$args->{'only_body'}
6595: && !$args->{'frameset'}) {
6596: $result .= &help_menu_js();
6597: }
1.319 albertel 6598:
1.314 albertel 6599: if (ref($args->{'redirect'})) {
1.414 albertel 6600: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6601: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6602: if (!$inhibit_continue) {
6603: $env{'internal.head.redirect'} = $url;
6604: }
1.313 albertel 6605: $result.=<<ADDMETA
6606: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6607: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6608: ADDMETA
6609: }
1.306 albertel 6610: if (!defined($title)) {
6611: $title = 'The LearningOnline Network with CAPA';
6612: }
1.460 albertel 6613: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6614: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6615: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6616: .$head_extra;
1.962 droeschl 6617: return $result.'</head>';
1.306 albertel 6618: }
6619:
6620: =pod
6621:
1.340 albertel 6622: =item * &font_settings()
6623:
6624: Returns neccessary <meta> to set the proper encoding
6625:
6626: Inputs: none
6627:
6628: =cut
6629:
6630: sub font_settings {
6631: my $headerstring='';
1.647 www 6632: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6633: $headerstring.=
6634: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6635: }
6636: return $headerstring;
6637: }
6638:
1.341 albertel 6639: =pod
6640:
6641: =item * &xml_begin()
6642:
6643: Returns the needed doctype and <html>
6644:
6645: Inputs: none
6646:
6647: =cut
6648:
6649: sub xml_begin {
6650: my $output='';
6651:
6652: if ($env{'browser.mathml'}) {
6653: $output='<?xml version="1.0"?>'
6654: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6655: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6656:
6657: # .'<!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">] >'
6658: .'<!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">'
6659: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6660: .'xmlns="http://www.w3.org/1999/xhtml">';
6661: } else {
1.849 bisitz 6662: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6663: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6664: }
6665: return $output;
6666: }
1.340 albertel 6667:
6668: =pod
6669:
1.306 albertel 6670: =item * &start_page()
6671:
6672: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6673:
1.648 raeburn 6674: Inputs:
6675:
6676: =over 4
6677:
6678: $title - optional title for the page
6679:
6680: $head_extra - optional extra HTML to incude inside the <head>
6681:
6682: $args - additional optional args supported are:
6683:
6684: =over 8
6685:
6686: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6687: arg on
1.814 bisitz 6688: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6689: add_entries -> additional attributes to add to the <body>
6690: domain -> force to color decorate a page for a
1.317 albertel 6691: specific domain
1.648 raeburn 6692: function -> force usage of a specific rolish color
1.317 albertel 6693: scheme
1.648 raeburn 6694: redirect -> see &headtag()
6695: bgcolor -> override the default page bg color
6696: js_ready -> return a string ready for being used in
1.317 albertel 6697: a javascript writeln
1.648 raeburn 6698: html_encode -> return a string ready for being used in
1.320 albertel 6699: a html attribute
1.648 raeburn 6700: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6701: $forcereg arg
1.648 raeburn 6702: frameset -> if true will start with a <frameset>
1.330 albertel 6703: rather than <body>
1.648 raeburn 6704: skip_phases -> hash ref of
1.338 albertel 6705: head -> skip the <html><head> generation
6706: body -> skip all <body> generation
1.648 raeburn 6707: no_auto_mt_title -> prevent &mt()ing the title arg
6708: inherit_jsmath -> when creating popup window in a page,
6709: should it have jsmath forced on by the
6710: current page
1.867 kalberla 6711: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 6712: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6713:
1.648 raeburn 6714: =back
1.460 albertel 6715:
1.648 raeburn 6716: =back
1.562 albertel 6717:
1.306 albertel 6718: =cut
6719:
6720: sub start_page {
1.309 albertel 6721: my ($title,$head_extra,$args) = @_;
1.318 albertel 6722: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.964 droeschl 6723: #SD
6724: #I don't see why we copy certain elements of %$args to %head_args
6725: #head args is passed to headtag() and this routine only reads those
6726: #keys that are needed. There doesn't happen any writes or any processing
6727: #of other keys.
6728: #proposal: just pass $args to headtag instead of \%head_args and delete
6729: #marked lines
6730: #<- MARK
1.313 albertel 6731: my %head_args;
1.352 albertel 6732: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6733: 'bgcolor','frameset','no_nav_bar','only_body',
6734: 'no_auto_mt_title') {
1.319 albertel 6735: if (defined($args->{$arg})) {
1.324 raeburn 6736: $head_args{$arg} = $args->{$arg};
1.319 albertel 6737: }
1.313 albertel 6738: }
1.964 droeschl 6739: #MARK ->
1.319 albertel 6740:
1.315 albertel 6741: $env{'internal.start_page'}++;
1.338 albertel 6742: my $result;
1.964 droeschl 6743:
1.338 albertel 6744: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.964 droeschl 6745: $result .=
6746: &xml_begin() . &headtag($title,$head_extra,\%head_args);
6747: #replace prev line by
6748: # &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 6749: }
6750:
6751: if (! exists($args->{'skip_phases'}{'body'}) ) {
6752: if ($args->{'frameset'}) {
6753: my $attr_string = &make_attr_string($args->{'force_register'},
6754: $args->{'add_entries'});
6755: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6756: } else {
6757: $result .=
6758: &bodytag($title,
6759: $args->{'function'}, $args->{'add_entries'},
6760: $args->{'only_body'}, $args->{'domain'},
6761: $args->{'force_register'}, $args->{'no_nav_bar'},
1.962 droeschl 6762: $args->{'bgcolor'}, $args);
1.831 bisitz 6763: }
1.330 albertel 6764: }
1.338 albertel 6765:
1.315 albertel 6766: if ($args->{'js_ready'}) {
1.713 kaisler 6767: $result = &js_ready($result);
1.315 albertel 6768: }
1.320 albertel 6769: if ($args->{'html_encode'}) {
1.713 kaisler 6770: $result = &html_encode($result);
6771: }
6772:
1.813 bisitz 6773: # Preparation for new and consistent functionlist at top of screen
6774: # if ($args->{'functionlist'}) {
6775: # $result .= &build_functionlist();
6776: #}
6777:
1.964 droeschl 6778: # Don't add anything more if only_body wanted or in const space
6779: return $result if $args->{'only_body'}
6780: || $env{'request.state'} eq 'construct';
1.813 bisitz 6781:
6782: #Breadcrumbs
1.758 kaisler 6783: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6784: &Apache::lonhtmlcommon::clear_breadcrumbs();
6785: #if any br links exists, add them to the breadcrumbs
6786: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6787: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6788: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6789: }
6790: }
6791:
6792: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6793: if(exists($args->{'bread_crumbs_component'})){
6794: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6795: }else{
6796: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6797: }
1.320 albertel 6798: }
1.315 albertel 6799: return $result;
1.306 albertel 6800: }
6801:
6802: sub end_page {
1.315 albertel 6803: my ($args) = @_;
6804: $env{'internal.end_page'}++;
1.330 albertel 6805: my $result;
1.335 albertel 6806: if ($args->{'discussion'}) {
6807: my ($target,$parser);
6808: if (ref($args->{'discussion'})) {
6809: ($target,$parser) =($args->{'discussion'}{'target'},
6810: $args->{'discussion'}{'parser'});
6811: }
6812: $result .= &Apache::lonxml::xmlend($target,$parser);
6813: }
6814:
1.330 albertel 6815: if ($args->{'frameset'}) {
6816: $result .= '</frameset>';
6817: } else {
1.635 raeburn 6818: $result .= &endbodytag($args);
1.330 albertel 6819: }
6820: $result .= "\n</html>";
6821:
1.315 albertel 6822: if ($args->{'js_ready'}) {
1.317 albertel 6823: $result = &js_ready($result);
1.315 albertel 6824: }
1.335 albertel 6825:
1.320 albertel 6826: if ($args->{'html_encode'}) {
6827: $result = &html_encode($result);
6828: }
1.335 albertel 6829:
1.315 albertel 6830: return $result;
6831: }
6832:
1.320 albertel 6833: sub html_encode {
6834: my ($result) = @_;
6835:
1.322 albertel 6836: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6837:
6838: return $result;
6839: }
1.317 albertel 6840: sub js_ready {
6841: my ($result) = @_;
6842:
1.323 albertel 6843: $result =~ s/[\n\r]/ /xmsg;
6844: $result =~ s/\\/\\\\/xmsg;
6845: $result =~ s/'/\\'/xmsg;
1.372 albertel 6846: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6847:
6848: return $result;
6849: }
6850:
1.315 albertel 6851: sub validate_page {
6852: if ( exists($env{'internal.start_page'})
1.316 albertel 6853: && $env{'internal.start_page'} > 1) {
6854: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6855: $env{'internal.start_page'}.' '.
1.316 albertel 6856: $ENV{'request.filename'});
1.315 albertel 6857: }
6858: if ( exists($env{'internal.end_page'})
1.316 albertel 6859: && $env{'internal.end_page'} > 1) {
6860: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6861: $env{'internal.end_page'}.' '.
1.316 albertel 6862: $env{'request.filename'});
1.315 albertel 6863: }
6864: if ( exists($env{'internal.start_page'})
6865: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6866: &Apache::lonnet::logthis('start_page called without end_page '.
6867: $env{'request.filename'});
1.315 albertel 6868: }
6869: if ( ! exists($env{'internal.start_page'})
6870: && exists($env{'internal.end_page'})) {
1.316 albertel 6871: &Apache::lonnet::logthis('end_page called without start_page'.
6872: $env{'request.filename'});
1.315 albertel 6873: }
1.306 albertel 6874: }
1.315 albertel 6875:
1.318 albertel 6876: sub simple_error_page {
6877: my ($r,$title,$msg) = @_;
6878: my $page =
6879: &Apache::loncommon::start_page($title).
6880: &mt($msg).
6881: &Apache::loncommon::end_page();
6882: if (ref($r)) {
6883: $r->print($page);
1.327 albertel 6884: return;
1.318 albertel 6885: }
6886: return $page;
6887: }
1.347 albertel 6888:
6889: {
1.610 albertel 6890: my @row_count;
1.961 onken 6891:
6892: sub start_data_table_count {
6893: unshift(@row_count, 0);
6894: return;
6895: }
6896:
6897: sub end_data_table_count {
6898: shift(@row_count);
6899: return;
6900: }
6901:
1.347 albertel 6902: sub start_data_table {
1.422 albertel 6903: my ($add_class) = @_;
6904: my $css_class = (join(' ','LC_data_table',$add_class));
1.961 onken 6905: &start_data_table_count();
1.422 albertel 6906: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6907: }
6908:
6909: sub end_data_table {
1.961 onken 6910: &end_data_table_count();
1.389 albertel 6911: return '</table>'."\n";;
1.347 albertel 6912: }
6913:
6914: sub start_data_table_row {
1.974 wenzelju 6915: my ($add_class, $id) = @_;
1.610 albertel 6916: $row_count[0]++;
6917: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6918: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 6919: $id = (' id="'.$id.'"') unless ($id eq '');
6920: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 6921: }
1.471 banghart 6922:
6923: sub continue_data_table_row {
1.974 wenzelju 6924: my ($add_class, $id) = @_;
1.610 albertel 6925: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 6926: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
6927: $id = (' id="'.$id.'"') unless ($id eq '');
6928: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 6929: }
1.347 albertel 6930:
6931: sub end_data_table_row {
1.389 albertel 6932: return '</tr>'."\n";;
1.347 albertel 6933: }
1.367 www 6934:
1.421 albertel 6935: sub start_data_table_empty_row {
1.707 bisitz 6936: # $row_count[0]++;
1.421 albertel 6937: return '<tr class="LC_empty_row" >'."\n";;
6938: }
6939:
6940: sub end_data_table_empty_row {
6941: return '</tr>'."\n";;
6942: }
6943:
1.367 www 6944: sub start_data_table_header_row {
1.389 albertel 6945: return '<tr class="LC_header_row">'."\n";;
1.367 www 6946: }
6947:
6948: sub end_data_table_header_row {
1.389 albertel 6949: return '</tr>'."\n";;
1.367 www 6950: }
1.890 droeschl 6951:
6952: sub data_table_caption {
6953: my $caption = shift;
6954: return "<caption class=\"LC_caption\">$caption</caption>";
6955: }
1.347 albertel 6956: }
6957:
1.548 albertel 6958: =pod
6959:
6960: =item * &inhibit_menu_check($arg)
6961:
6962: Checks for a inhibitmenu state and generates output to preserve it
6963:
6964: Inputs: $arg - can be any of
6965: - undef - in which case the return value is a string
6966: to add into arguments list of a uri
6967: - 'input' - in which case the return value is a HTML
6968: <form> <input> field of type hidden to
6969: preserve the value
6970: - a url - in which case the return value is the url with
6971: the neccesary cgi args added to preserve the
6972: inhibitmenu state
6973: - a ref to a url - no return value, but the string is
6974: updated to include the neccessary cgi
6975: args to preserve the inhibitmenu state
6976:
6977: =cut
6978:
6979: sub inhibit_menu_check {
6980: my ($arg) = @_;
6981: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6982: if ($arg eq 'input') {
6983: if ($env{'form.inhibitmenu'}) {
6984: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6985: } else {
6986: return
6987: }
6988: }
6989: if ($env{'form.inhibitmenu'}) {
6990: if (ref($arg)) {
6991: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6992: } elsif ($arg eq '') {
6993: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6994: } else {
6995: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6996: }
6997: }
6998: if (!ref($arg)) {
6999: return $arg;
7000: }
7001: }
7002:
1.251 albertel 7003: ###############################################
1.182 matthew 7004:
7005: =pod
7006:
1.549 albertel 7007: =back
7008:
7009: =head1 User Information Routines
7010:
7011: =over 4
7012:
1.405 albertel 7013: =item * &get_users_function()
1.182 matthew 7014:
7015: Used by &bodytag to determine the current users primary role.
7016: Returns either 'student','coordinator','admin', or 'author'.
7017:
7018: =cut
7019:
7020: ###############################################
7021: sub get_users_function {
1.815 tempelho 7022: my $function = 'norole';
1.818 tempelho 7023: if ($env{'request.role'}=~/^(st)/) {
7024: $function='student';
7025: }
1.907 raeburn 7026: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7027: $function='coordinator';
7028: }
1.258 albertel 7029: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7030: $function='admin';
7031: }
1.826 bisitz 7032: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7033: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7034: $function='author';
7035: }
7036: return $function;
1.54 www 7037: }
1.99 www 7038:
7039: ###############################################
7040:
1.233 raeburn 7041: =pod
7042:
1.821 raeburn 7043: =item * &show_course()
7044:
7045: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7046: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7047:
7048: Inputs:
7049: None
7050:
7051: Outputs:
7052: Scalar: 1 if 'Course' to be used, 0 otherwise.
7053:
7054: =cut
7055:
7056: ###############################################
7057: sub show_course {
7058: my $course = !$env{'user.adv'};
7059: if (!$env{'user.adv'}) {
7060: foreach my $env (keys(%env)) {
7061: next if ($env !~ m/^user\.priv\./);
7062: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7063: $course = 0;
7064: last;
7065: }
7066: }
7067: }
7068: return $course;
7069: }
7070:
7071: ###############################################
7072:
7073: =pod
7074:
1.542 raeburn 7075: =item * &check_user_status()
1.274 raeburn 7076:
7077: Determines current status of supplied role for a
7078: specific user. Roles can be active, previous or future.
7079:
7080: Inputs:
7081: user's domain, user's username, course's domain,
1.375 raeburn 7082: course's number, optional section ID.
1.274 raeburn 7083:
7084: Outputs:
7085: role status: active, previous or future.
7086:
7087: =cut
7088:
7089: sub check_user_status {
1.412 raeburn 7090: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.982 raeburn 7091: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7092: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7093: my @uroles = keys %userinfo;
7094: my $srchstr;
7095: my $active_chk = 'none';
1.412 raeburn 7096: my $now = time;
1.274 raeburn 7097: if (@uroles > 0) {
1.908 raeburn 7098: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7099: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7100: } else {
1.412 raeburn 7101: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7102: }
7103: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7104: my $role_end = 0;
7105: my $role_start = 0;
7106: $active_chk = 'active';
1.412 raeburn 7107: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7108: $role_end = $1;
7109: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7110: $role_start = $1;
1.274 raeburn 7111: }
7112: }
7113: if ($role_start > 0) {
1.412 raeburn 7114: if ($now < $role_start) {
1.274 raeburn 7115: $active_chk = 'future';
7116: }
7117: }
7118: if ($role_end > 0) {
1.412 raeburn 7119: if ($now > $role_end) {
1.274 raeburn 7120: $active_chk = 'previous';
7121: }
7122: }
7123: }
7124: }
7125: return $active_chk;
7126: }
7127:
7128: ###############################################
7129:
7130: =pod
7131:
1.405 albertel 7132: =item * &get_sections()
1.233 raeburn 7133:
7134: Determines all the sections for a course including
7135: sections with students and sections containing other roles.
1.419 raeburn 7136: Incoming parameters:
7137:
7138: 1. domain
7139: 2. course number
7140: 3. reference to array containing roles for which sections should
7141: be gathered (optional).
7142: 4. reference to array containing status types for which sections
7143: should be gathered (optional).
7144:
7145: If the third argument is undefined, sections are gathered for any role.
7146: If the fourth argument is undefined, sections are gathered for any status.
7147: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7148:
1.374 raeburn 7149: Returns section hash (keys are section IDs, values are
7150: number of users in each section), subject to the
1.419 raeburn 7151: optional roles filter, optional status filter
1.233 raeburn 7152:
7153: =cut
7154:
7155: ###############################################
7156: sub get_sections {
1.419 raeburn 7157: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7158: if (!defined($cdom) || !defined($cnum)) {
7159: my $cid = $env{'request.course.id'};
7160:
7161: return if (!defined($cid));
7162:
7163: $cdom = $env{'course.'.$cid.'.domain'};
7164: $cnum = $env{'course.'.$cid.'.num'};
7165: }
7166:
7167: my %sectioncount;
1.419 raeburn 7168: my $now = time;
1.240 albertel 7169:
1.366 albertel 7170: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7171: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7172: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7173: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7174: my $start_index = &Apache::loncoursedata::CL_START();
7175: my $end_index = &Apache::loncoursedata::CL_END();
7176: my $status;
1.366 albertel 7177: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7178: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7179: $data->[$status_index],
7180: $data->[$start_index],
7181: $data->[$end_index]);
7182: if ($stu_status eq 'Active') {
7183: $status = 'active';
7184: } elsif ($end < $now) {
7185: $status = 'previous';
7186: } elsif ($start > $now) {
7187: $status = 'future';
7188: }
7189: if ($section ne '-1' && $section !~ /^\s*$/) {
7190: if ((!defined($possible_status)) || (($status ne '') &&
7191: (grep/^\Q$status\E$/,@{$possible_status}))) {
7192: $sectioncount{$section}++;
7193: }
1.240 albertel 7194: }
7195: }
7196: }
7197: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7198: foreach my $user (sort(keys(%courseroles))) {
7199: if ($user !~ /^(\w{2})/) { next; }
7200: my ($role) = ($user =~ /^(\w{2})/);
7201: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7202: my ($section,$status);
1.240 albertel 7203: if ($role eq 'cr' &&
7204: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7205: $section=$1;
7206: }
7207: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7208: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7209: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7210: if ($end == -1 && $start == -1) {
7211: next; #deleted role
7212: }
7213: if (!defined($possible_status)) {
7214: $sectioncount{$section}++;
7215: } else {
7216: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7217: $status = 'active';
7218: } elsif ($end < $now) {
7219: $status = 'future';
7220: } elsif ($start > $now) {
7221: $status = 'previous';
7222: }
7223: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7224: $sectioncount{$section}++;
7225: }
7226: }
1.233 raeburn 7227: }
1.366 albertel 7228: return %sectioncount;
1.233 raeburn 7229: }
7230:
1.274 raeburn 7231: ###############################################
1.294 raeburn 7232:
7233: =pod
1.405 albertel 7234:
7235: =item * &get_course_users()
7236:
1.275 raeburn 7237: Retrieves usernames:domains for users in the specified course
7238: with specific role(s), and access status.
7239:
7240: Incoming parameters:
1.277 albertel 7241: 1. course domain
7242: 2. course number
7243: 3. access status: users must have - either active,
1.275 raeburn 7244: previous, future, or all.
1.277 albertel 7245: 4. reference to array of permissible roles
1.288 raeburn 7246: 5. reference to array of section restrictions (optional)
7247: 6. reference to results object (hash of hashes).
7248: 7. reference to optional userdata hash
1.609 raeburn 7249: 8. reference to optional statushash
1.630 raeburn 7250: 9. flag if privileged users (except those set to unhide in
7251: course settings) should be excluded
1.609 raeburn 7252: Keys of top level results hash are roles.
1.275 raeburn 7253: Keys of inner hashes are username:domain, with
7254: values set to access type.
1.288 raeburn 7255: Optional userdata hash returns an array with arguments in the
7256: same order as loncoursedata::get_classlist() for student data.
7257:
1.609 raeburn 7258: Optional statushash returns
7259:
1.288 raeburn 7260: Entries for end, start, section and status are blank because
7261: of the possibility of multiple values for non-student roles.
7262:
1.275 raeburn 7263: =cut
1.405 albertel 7264:
1.275 raeburn 7265: ###############################################
1.405 albertel 7266:
1.275 raeburn 7267: sub get_course_users {
1.630 raeburn 7268: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7269: my %idx = ();
1.419 raeburn 7270: my %seclists;
1.288 raeburn 7271:
7272: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7273: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7274: $idx{end} = &Apache::loncoursedata::CL_END();
7275: $idx{start} = &Apache::loncoursedata::CL_START();
7276: $idx{id} = &Apache::loncoursedata::CL_ID();
7277: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7278: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7279: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7280:
1.290 albertel 7281: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7282: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7283: my $now = time;
1.277 albertel 7284: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7285: my $match = 0;
1.412 raeburn 7286: my $secmatch = 0;
1.419 raeburn 7287: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7288: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7289: if ($section eq '') {
7290: $section = 'none';
7291: }
1.291 albertel 7292: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7293: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7294: $secmatch = 1;
7295: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7296: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7297: $secmatch = 1;
7298: }
7299: } else {
1.419 raeburn 7300: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7301: $secmatch = 1;
7302: }
1.290 albertel 7303: }
1.412 raeburn 7304: if (!$secmatch) {
7305: next;
7306: }
1.419 raeburn 7307: }
1.275 raeburn 7308: if (defined($$types{'active'})) {
1.288 raeburn 7309: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7310: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7311: $match = 1;
1.275 raeburn 7312: }
7313: }
7314: if (defined($$types{'previous'})) {
1.609 raeburn 7315: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7316: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7317: $match = 1;
1.275 raeburn 7318: }
7319: }
7320: if (defined($$types{'future'})) {
1.609 raeburn 7321: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7322: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7323: $match = 1;
1.275 raeburn 7324: }
7325: }
1.609 raeburn 7326: if ($match) {
7327: push(@{$seclists{$student}},$section);
7328: if (ref($userdata) eq 'HASH') {
7329: $$userdata{$student} = $$classlist{$student};
7330: }
7331: if (ref($statushash) eq 'HASH') {
7332: $statushash->{$student}{'st'}{$section} = $status;
7333: }
1.288 raeburn 7334: }
1.275 raeburn 7335: }
7336: }
1.412 raeburn 7337: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7338: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7339: my $now = time;
1.609 raeburn 7340: my %displaystatus = ( previous => 'Expired',
7341: active => 'Active',
7342: future => 'Future',
7343: );
1.630 raeburn 7344: my %nothide;
7345: if ($hidepriv) {
7346: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7347: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7348: if ($user !~ /:/) {
7349: $nothide{join(':',split(/[\@]/,$user))}=1;
7350: } else {
7351: $nothide{$user} = 1;
7352: }
7353: }
7354: }
1.439 raeburn 7355: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7356: my $match = 0;
1.412 raeburn 7357: my $secmatch = 0;
1.439 raeburn 7358: my $status;
1.412 raeburn 7359: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7360: $user =~ s/:$//;
1.439 raeburn 7361: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7362: if ($end == -1 || $start == -1) {
7363: next;
7364: }
7365: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7366: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7367: my ($uname,$udom) = split(/:/,$user);
7368: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7369: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7370: $secmatch = 1;
7371: } elsif ($usec eq '') {
1.420 albertel 7372: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7373: $secmatch = 1;
7374: }
7375: } else {
7376: if (grep(/^\Q$usec\E$/,@{$sections})) {
7377: $secmatch = 1;
7378: }
7379: }
7380: if (!$secmatch) {
7381: next;
7382: }
1.288 raeburn 7383: }
1.419 raeburn 7384: if ($usec eq '') {
7385: $usec = 'none';
7386: }
1.275 raeburn 7387: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7388: if ($hidepriv) {
7389: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7390: (!$nothide{$uname.':'.$udom})) {
7391: next;
7392: }
7393: }
1.503 raeburn 7394: if ($end > 0 && $end < $now) {
1.439 raeburn 7395: $status = 'previous';
7396: } elsif ($start > $now) {
7397: $status = 'future';
7398: } else {
7399: $status = 'active';
7400: }
1.277 albertel 7401: foreach my $type (keys(%{$types})) {
1.275 raeburn 7402: if ($status eq $type) {
1.420 albertel 7403: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7404: push(@{$$users{$role}{$user}},$type);
7405: }
1.288 raeburn 7406: $match = 1;
7407: }
7408: }
1.419 raeburn 7409: if (($match) && (ref($userdata) eq 'HASH')) {
7410: if (!exists($$userdata{$uname.':'.$udom})) {
7411: &get_user_info($udom,$uname,\%idx,$userdata);
7412: }
1.420 albertel 7413: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7414: push(@{$seclists{$uname.':'.$udom}},$usec);
7415: }
1.609 raeburn 7416: if (ref($statushash) eq 'HASH') {
7417: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7418: }
1.275 raeburn 7419: }
7420: }
7421: }
7422: }
1.290 albertel 7423: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7424: if ((defined($cdom)) && (defined($cnum))) {
7425: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7426: if ( defined($csettings{'internal.courseowner'}) ) {
7427: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7428: next if ($owner eq '');
7429: my ($ownername,$ownerdom);
7430: if ($owner =~ /^([^:]+):([^:]+)$/) {
7431: $ownername = $1;
7432: $ownerdom = $2;
7433: } else {
7434: $ownername = $owner;
7435: $ownerdom = $cdom;
7436: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7437: }
7438: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7439: if (defined($userdata) &&
1.609 raeburn 7440: !exists($$userdata{$owner})) {
7441: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7442: if (!grep(/^none$/,@{$seclists{$owner}})) {
7443: push(@{$seclists{$owner}},'none');
7444: }
7445: if (ref($statushash) eq 'HASH') {
7446: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7447: }
1.290 albertel 7448: }
1.279 raeburn 7449: }
7450: }
7451: }
1.419 raeburn 7452: foreach my $user (keys(%seclists)) {
7453: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7454: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7455: }
1.275 raeburn 7456: }
7457: return;
7458: }
7459:
1.288 raeburn 7460: sub get_user_info {
7461: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7462: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7463: &plainname($uname,$udom,'lastname');
1.291 albertel 7464: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7465: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7466: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7467: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7468: return;
7469: }
1.275 raeburn 7470:
1.472 raeburn 7471: ###############################################
7472:
7473: =pod
7474:
7475: =item * &get_user_quota()
7476:
7477: Retrieves quota assigned for storage of portfolio files for a user
7478:
7479: Incoming parameters:
7480: 1. user's username
7481: 2. user's domain
7482:
7483: Returns:
1.536 raeburn 7484: 1. Disk quota (in Mb) assigned to student.
7485: 2. (Optional) Type of setting: custom or default
7486: (individually assigned or default for user's
7487: institutional status).
7488: 3. (Optional) - User's institutional status (e.g., faculty, staff
7489: or student - types as defined in localenroll::inst_usertypes
7490: for user's domain, which determines default quota for user.
7491: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7492:
7493: If a value has been stored in the user's environment,
1.536 raeburn 7494: it will return that, otherwise it returns the maximal default
7495: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7496:
7497: =cut
7498:
7499: ###############################################
7500:
7501:
7502: sub get_user_quota {
7503: my ($uname,$udom) = @_;
1.536 raeburn 7504: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7505: if (!defined($udom)) {
7506: $udom = $env{'user.domain'};
7507: }
7508: if (!defined($uname)) {
7509: $uname = $env{'user.name'};
7510: }
7511: if (($udom eq '' || $uname eq '') ||
7512: ($udom eq 'public') && ($uname eq 'public')) {
7513: $quota = 0;
1.536 raeburn 7514: $quotatype = 'default';
7515: $defquota = 0;
1.472 raeburn 7516: } else {
1.536 raeburn 7517: my $inststatus;
1.472 raeburn 7518: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7519: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7520: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7521: } else {
1.536 raeburn 7522: my %userenv =
7523: &Apache::lonnet::get('environment',['portfolioquota',
7524: 'inststatus'],$udom,$uname);
1.472 raeburn 7525: my ($tmp) = keys(%userenv);
7526: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7527: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7528: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7529: } else {
7530: undef(%userenv);
7531: }
7532: }
1.536 raeburn 7533: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7534: if ($quota eq '') {
1.536 raeburn 7535: $quota = $defquota;
7536: $quotatype = 'default';
7537: } else {
7538: $quotatype = 'custom';
1.472 raeburn 7539: }
7540: }
1.536 raeburn 7541: if (wantarray) {
7542: return ($quota,$quotatype,$settingstatus,$defquota);
7543: } else {
7544: return $quota;
7545: }
1.472 raeburn 7546: }
7547:
7548: ###############################################
7549:
7550: =pod
7551:
7552: =item * &default_quota()
7553:
1.536 raeburn 7554: Retrieves default quota assigned for storage of user portfolio files,
7555: given an (optional) user's institutional status.
1.472 raeburn 7556:
7557: Incoming parameters:
7558: 1. domain
1.536 raeburn 7559: 2. (Optional) institutional status(es). This is a : separated list of
7560: status types (e.g., faculty, staff, student etc.)
7561: which apply to the user for whom the default is being retrieved.
7562: If the institutional status string in undefined, the domain
7563: default quota will be returned.
1.472 raeburn 7564:
7565: Returns:
7566: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7567: 2. (Optional) institutional type which determined the value of the
7568: default quota.
1.472 raeburn 7569:
7570: If a value has been stored in the domain's configuration db,
7571: it will return that, otherwise it returns 20 (for backwards
7572: compatibility with domains which have not set up a configuration
7573: db file; the original statically defined portfolio quota was 20 Mb).
7574:
1.536 raeburn 7575: If the user's status includes multiple types (e.g., staff and student),
7576: the largest default quota which applies to the user determines the
7577: default quota returned.
7578:
1.780 raeburn 7579: =back
7580:
1.472 raeburn 7581: =cut
7582:
7583: ###############################################
7584:
7585:
7586: sub default_quota {
1.536 raeburn 7587: my ($udom,$inststatus) = @_;
7588: my ($defquota,$settingstatus);
7589: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7590: ['quotas'],$udom);
7591: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7592: if ($inststatus ne '') {
1.765 raeburn 7593: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7594: foreach my $item (@statuses) {
1.711 raeburn 7595: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7596: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7597: if ($defquota eq '') {
7598: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7599: $settingstatus = $item;
7600: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7601: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7602: $settingstatus = $item;
7603: }
7604: }
7605: } else {
7606: if ($quotahash{'quotas'}{$item} ne '') {
7607: if ($defquota eq '') {
7608: $defquota = $quotahash{'quotas'}{$item};
7609: $settingstatus = $item;
7610: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7611: $defquota = $quotahash{'quotas'}{$item};
7612: $settingstatus = $item;
7613: }
1.536 raeburn 7614: }
7615: }
7616: }
7617: }
7618: if ($defquota eq '') {
1.711 raeburn 7619: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7620: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7621: } else {
7622: $defquota = $quotahash{'quotas'}{'default'};
7623: }
1.536 raeburn 7624: $settingstatus = 'default';
7625: }
7626: } else {
7627: $settingstatus = 'default';
7628: $defquota = 20;
7629: }
7630: if (wantarray) {
7631: return ($defquota,$settingstatus);
1.472 raeburn 7632: } else {
1.536 raeburn 7633: return $defquota;
1.472 raeburn 7634: }
7635: }
7636:
1.384 raeburn 7637: sub get_secgrprole_info {
7638: my ($cdom,$cnum,$needroles,$type) = @_;
7639: my %sections_count = &get_sections($cdom,$cnum);
7640: my @sections = (sort {$a <=> $b} keys(%sections_count));
7641: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7642: my @groups = sort(keys(%curr_groups));
7643: my $allroles = [];
7644: my $rolehash;
7645: my $accesshash = {
7646: active => 'Currently has access',
7647: future => 'Will have future access',
7648: previous => 'Previously had access',
7649: };
7650: if ($needroles) {
7651: $rolehash = {'all' => 'all'};
1.385 albertel 7652: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7653: if (&Apache::lonnet::error(%user_roles)) {
7654: undef(%user_roles);
7655: }
7656: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7657: my ($role)=split(/\:/,$item,2);
7658: if ($role eq 'cr') { next; }
7659: if ($role =~ /^cr/) {
7660: $$rolehash{$role} = (split('/',$role))[3];
7661: } else {
7662: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7663: }
7664: }
7665: foreach my $key (sort(keys(%{$rolehash}))) {
7666: push(@{$allroles},$key);
7667: }
7668: push (@{$allroles},'st');
7669: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7670: }
7671: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7672: }
7673:
1.555 raeburn 7674: sub user_picker {
1.627 raeburn 7675: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7676: my $currdom = $dom;
7677: my %curr_selected = (
7678: srchin => 'dom',
1.580 raeburn 7679: srchby => 'lastname',
1.555 raeburn 7680: );
7681: my $srchterm;
1.625 raeburn 7682: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7683: if ($srch->{'srchby'} ne '') {
7684: $curr_selected{'srchby'} = $srch->{'srchby'};
7685: }
7686: if ($srch->{'srchin'} ne '') {
7687: $curr_selected{'srchin'} = $srch->{'srchin'};
7688: }
7689: if ($srch->{'srchtype'} ne '') {
7690: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7691: }
7692: if ($srch->{'srchdomain'} ne '') {
7693: $currdom = $srch->{'srchdomain'};
7694: }
7695: $srchterm = $srch->{'srchterm'};
7696: }
7697: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7698: 'usr' => 'Search criteria',
1.563 raeburn 7699: 'doma' => 'Domain/institution to search',
1.558 albertel 7700: 'uname' => 'username',
7701: 'lastname' => 'last name',
1.555 raeburn 7702: 'lastfirst' => 'last name, first name',
1.558 albertel 7703: 'crs' => 'in this course',
1.576 raeburn 7704: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7705: 'alc' => 'all LON-CAPA',
1.573 raeburn 7706: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7707: 'exact' => 'is',
7708: 'contains' => 'contains',
1.569 raeburn 7709: 'begins' => 'begins with',
1.571 raeburn 7710: 'youm' => "You must include some text to search for.",
7711: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7712: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7713: 'yomc' => "You must choose a domain when using an institutional directory search.",
7714: 'ymcd' => "You must choose a domain when using a domain search.",
7715: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7716: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7717: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7718: );
1.563 raeburn 7719: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7720: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7721:
7722: my @srchins = ('crs','dom','alc','instd');
7723:
7724: foreach my $option (@srchins) {
7725: # FIXME 'alc' option unavailable until
7726: # loncreateuser::print_user_query_page()
7727: # has been completed.
7728: next if ($option eq 'alc');
1.880 raeburn 7729: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7730: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7731: if ($curr_selected{'srchin'} eq $option) {
7732: $srchinsel .= '
7733: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7734: } else {
7735: $srchinsel .= '
7736: <option value="'.$option.'">'.$lt{$option}.'</option>';
7737: }
1.555 raeburn 7738: }
1.563 raeburn 7739: $srchinsel .= "\n </select>\n";
1.555 raeburn 7740:
7741: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7742: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7743: if ($curr_selected{'srchby'} eq $option) {
7744: $srchbysel .= '
7745: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7746: } else {
7747: $srchbysel .= '
7748: <option value="'.$option.'">'.$lt{$option}.'</option>';
7749: }
7750: }
7751: $srchbysel .= "\n </select>\n";
7752:
7753: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7754: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7755: if ($curr_selected{'srchtype'} eq $option) {
7756: $srchtypesel .= '
7757: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7758: } else {
7759: $srchtypesel .= '
7760: <option value="'.$option.'">'.$lt{$option}.'</option>';
7761: }
7762: }
7763: $srchtypesel .= "\n </select>\n";
7764:
1.558 albertel 7765: my ($newuserscript,$new_user_create);
1.556 raeburn 7766:
7767: if ($forcenewuser) {
1.576 raeburn 7768: if (ref($srch) eq 'HASH') {
7769: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7770: if ($cancreate) {
7771: $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>';
7772: } else {
1.799 bisitz 7773: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7774: my %usertypetext = (
7775: official => 'institutional',
7776: unofficial => 'non-institutional',
7777: );
1.799 bisitz 7778: $new_user_create = '<p class="LC_warning">'
7779: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7780: .' '
7781: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7782: ,'<a href="'.$helplink.'">','</a>')
7783: .'</p><br />';
1.627 raeburn 7784: }
1.576 raeburn 7785: }
7786: }
7787:
1.556 raeburn 7788: $newuserscript = <<"ENDSCRIPT";
7789:
1.570 raeburn 7790: function setSearch(createnew,callingForm) {
1.556 raeburn 7791: if (createnew == 1) {
1.570 raeburn 7792: for (var i=0; i<callingForm.srchby.length; i++) {
7793: if (callingForm.srchby.options[i].value == 'uname') {
7794: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7795: }
7796: }
1.570 raeburn 7797: for (var i=0; i<callingForm.srchin.length; i++) {
7798: if ( callingForm.srchin.options[i].value == 'dom') {
7799: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7800: }
7801: }
1.570 raeburn 7802: for (var i=0; i<callingForm.srchtype.length; i++) {
7803: if (callingForm.srchtype.options[i].value == 'exact') {
7804: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7805: }
7806: }
1.570 raeburn 7807: for (var i=0; i<callingForm.srchdomain.length; i++) {
7808: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7809: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7810: }
7811: }
7812: }
7813: }
7814: ENDSCRIPT
1.558 albertel 7815:
1.556 raeburn 7816: }
7817:
1.555 raeburn 7818: my $output = <<"END_BLOCK";
1.556 raeburn 7819: <script type="text/javascript">
1.824 bisitz 7820: // <![CDATA[
1.570 raeburn 7821: function validateEntry(callingForm) {
1.558 albertel 7822:
1.556 raeburn 7823: var checkok = 1;
1.558 albertel 7824: var srchin;
1.570 raeburn 7825: for (var i=0; i<callingForm.srchin.length; i++) {
7826: if ( callingForm.srchin[i].checked ) {
7827: srchin = callingForm.srchin[i].value;
1.558 albertel 7828: }
7829: }
7830:
1.570 raeburn 7831: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7832: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7833: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7834: var srchterm = callingForm.srchterm.value;
7835: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7836: var msg = "";
7837:
7838: if (srchterm == "") {
7839: checkok = 0;
1.571 raeburn 7840: msg += "$lt{'youm'}\\n";
1.556 raeburn 7841: }
7842:
1.569 raeburn 7843: if (srchtype== 'begins') {
7844: if (srchterm.length < 2) {
7845: checkok = 0;
1.571 raeburn 7846: msg += "$lt{'thte'}\\n";
1.569 raeburn 7847: }
7848: }
7849:
1.556 raeburn 7850: if (srchtype== 'contains') {
7851: if (srchterm.length < 3) {
7852: checkok = 0;
1.571 raeburn 7853: msg += "$lt{'thet'}\\n";
1.556 raeburn 7854: }
7855: }
7856: if (srchin == 'instd') {
7857: if (srchdomain == '') {
7858: checkok = 0;
1.571 raeburn 7859: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7860: }
7861: }
7862: if (srchin == 'dom') {
7863: if (srchdomain == '') {
7864: checkok = 0;
1.571 raeburn 7865: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7866: }
7867: }
7868: if (srchby == 'lastfirst') {
7869: if (srchterm.indexOf(",") == -1) {
7870: checkok = 0;
1.571 raeburn 7871: msg += "$lt{'whus'}\\n";
1.556 raeburn 7872: }
7873: if (srchterm.indexOf(",") == srchterm.length -1) {
7874: checkok = 0;
1.571 raeburn 7875: msg += "$lt{'whse'}\\n";
1.556 raeburn 7876: }
7877: }
7878: if (checkok == 0) {
1.571 raeburn 7879: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7880: return;
7881: }
7882: if (checkok == 1) {
1.570 raeburn 7883: callingForm.submit();
1.556 raeburn 7884: }
7885: }
7886:
7887: $newuserscript
7888:
1.824 bisitz 7889: // ]]>
1.556 raeburn 7890: </script>
1.558 albertel 7891:
7892: $new_user_create
7893:
1.555 raeburn 7894: END_BLOCK
1.558 albertel 7895:
1.876 raeburn 7896: $output .= &Apache::lonhtmlcommon::start_pick_box().
7897: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7898: $domform.
7899: &Apache::lonhtmlcommon::row_closure().
7900: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7901: $srchbysel.
7902: $srchtypesel.
7903: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7904: $srchinsel.
7905: &Apache::lonhtmlcommon::row_closure(1).
7906: &Apache::lonhtmlcommon::end_pick_box().
7907: '<br />';
1.555 raeburn 7908: return $output;
7909: }
7910:
1.612 raeburn 7911: sub user_rule_check {
1.615 raeburn 7912: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7913: my $response;
7914: if (ref($usershash) eq 'HASH') {
7915: foreach my $user (keys(%{$usershash})) {
7916: my ($uname,$udom) = split(/:/,$user);
7917: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7918: my ($id,$newuser);
1.612 raeburn 7919: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7920: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7921: $id = $usershash->{$user}->{'id'};
7922: }
7923: my $inst_response;
7924: if (ref($checks) eq 'HASH') {
7925: if (defined($checks->{'username'})) {
1.615 raeburn 7926: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7927: &Apache::lonnet::get_instuser($udom,$uname);
7928: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7929: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7930: &Apache::lonnet::get_instuser($udom,undef,$id);
7931: }
1.615 raeburn 7932: } else {
7933: ($inst_response,%{$inst_results->{$user}}) =
7934: &Apache::lonnet::get_instuser($udom,$uname);
7935: return;
1.612 raeburn 7936: }
1.615 raeburn 7937: if (!$got_rules->{$udom}) {
1.612 raeburn 7938: my %domconfig = &Apache::lonnet::get_dom('configuration',
7939: ['usercreation'],$udom);
7940: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7941: foreach my $item ('username','id') {
1.612 raeburn 7942: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7943: $$curr_rules{$udom}{$item} =
7944: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7945: }
7946: }
7947: }
1.615 raeburn 7948: $got_rules->{$udom} = 1;
1.585 raeburn 7949: }
1.612 raeburn 7950: foreach my $item (keys(%{$checks})) {
7951: if (ref($$curr_rules{$udom}) eq 'HASH') {
7952: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7953: if (@{$$curr_rules{$udom}{$item}} > 0) {
7954: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7955: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7956: if ($rule_check{$rule}) {
7957: $$rulematch{$user}{$item} = $rule;
7958: if ($inst_response eq 'ok') {
1.615 raeburn 7959: if (ref($inst_results) eq 'HASH') {
7960: if (ref($inst_results->{$user}) eq 'HASH') {
7961: if (keys(%{$inst_results->{$user}}) == 0) {
7962: $$alerts{$item}{$udom}{$uname} = 1;
7963: }
1.612 raeburn 7964: }
7965: }
1.615 raeburn 7966: }
7967: last;
1.585 raeburn 7968: }
7969: }
7970: }
7971: }
7972: }
7973: }
7974: }
7975: }
1.612 raeburn 7976: return;
7977: }
7978:
7979: sub user_rule_formats {
7980: my ($domain,$domdesc,$curr_rules,$check) = @_;
7981: my %text = (
7982: 'username' => 'Usernames',
7983: 'id' => 'IDs',
7984: );
7985: my $output;
7986: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7987: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7988: if (@{$ruleorder} > 0) {
7989: $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>';
7990: foreach my $rule (@{$ruleorder}) {
7991: if (ref($curr_rules) eq 'ARRAY') {
7992: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7993: if (ref($rules->{$rule}) eq 'HASH') {
7994: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7995: $rules->{$rule}{'desc'}.'</li>';
7996: }
7997: }
7998: }
7999: }
8000: $output .= '</ul>';
8001: }
8002: }
8003: return $output;
8004: }
8005:
8006: sub instrule_disallow_msg {
1.615 raeburn 8007: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8008: my $response;
8009: my %text = (
8010: item => 'username',
8011: items => 'usernames',
8012: match => 'matches',
8013: do => 'does',
8014: action => 'a username',
8015: one => 'one',
8016: );
8017: if ($count > 1) {
8018: $text{'item'} = 'usernames';
8019: $text{'match'} ='match';
8020: $text{'do'} = 'do';
8021: $text{'action'} = 'usernames',
8022: $text{'one'} = 'ones';
8023: }
8024: if ($checkitem eq 'id') {
8025: $text{'items'} = 'IDs';
8026: $text{'item'} = 'ID';
8027: $text{'action'} = 'an ID';
1.615 raeburn 8028: if ($count > 1) {
8029: $text{'item'} = 'IDs';
8030: $text{'action'} = 'IDs';
8031: }
1.612 raeburn 8032: }
1.674 bisitz 8033: $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 8034: if ($mode eq 'upload') {
8035: if ($checkitem eq 'username') {
8036: $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'}.");
8037: } elsif ($checkitem eq 'id') {
1.674 bisitz 8038: $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 8039: }
1.669 raeburn 8040: } elsif ($mode eq 'selfcreate') {
8041: if ($checkitem eq 'id') {
8042: $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.");
8043: }
1.615 raeburn 8044: } else {
8045: if ($checkitem eq 'username') {
8046: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8047: } elsif ($checkitem eq 'id') {
8048: $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.");
8049: }
1.612 raeburn 8050: }
8051: return $response;
1.585 raeburn 8052: }
8053:
1.624 raeburn 8054: sub personal_data_fieldtitles {
8055: my %fieldtitles = &Apache::lonlocal::texthash (
8056: id => 'Student/Employee ID',
8057: permanentemail => 'E-mail address',
8058: lastname => 'Last Name',
8059: firstname => 'First Name',
8060: middlename => 'Middle Name',
8061: generation => 'Generation',
8062: gen => 'Generation',
1.765 raeburn 8063: inststatus => 'Affiliation',
1.624 raeburn 8064: );
8065: return %fieldtitles;
8066: }
8067:
1.642 raeburn 8068: sub sorted_inst_types {
8069: my ($dom) = @_;
8070: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8071: my $othertitle = &mt('All users');
8072: if ($env{'request.course.id'}) {
1.668 raeburn 8073: $othertitle = &mt('Any users');
1.642 raeburn 8074: }
8075: my @types;
8076: if (ref($order) eq 'ARRAY') {
8077: @types = @{$order};
8078: }
8079: if (@types == 0) {
8080: if (ref($usertypes) eq 'HASH') {
8081: @types = sort(keys(%{$usertypes}));
8082: }
8083: }
8084: if (keys(%{$usertypes}) > 0) {
8085: $othertitle = &mt('Other users');
8086: }
8087: return ($othertitle,$usertypes,\@types);
8088: }
8089:
1.645 raeburn 8090: sub get_institutional_codes {
8091: my ($settings,$allcourses,$LC_code) = @_;
8092: # Get complete list of course sections to update
8093: my @currsections = ();
8094: my @currxlists = ();
8095: my $coursecode = $$settings{'internal.coursecode'};
8096:
8097: if ($$settings{'internal.sectionnums'} ne '') {
8098: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8099: }
8100:
8101: if ($$settings{'internal.crosslistings'} ne '') {
8102: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8103: }
8104:
8105: if (@currxlists > 0) {
8106: foreach (@currxlists) {
8107: if (m/^([^:]+):(\w*)$/) {
8108: unless (grep/^$1$/,@{$allcourses}) {
8109: push @{$allcourses},$1;
8110: $$LC_code{$1} = $2;
8111: }
8112: }
8113: }
8114: }
8115:
8116: if (@currsections > 0) {
8117: foreach (@currsections) {
8118: if (m/^(\w+):(\w*)$/) {
8119: my $sec = $coursecode.$1;
8120: my $lc_sec = $2;
8121: unless (grep/^$sec$/,@{$allcourses}) {
8122: push @{$allcourses},$sec;
8123: $$LC_code{$sec} = $lc_sec;
8124: }
8125: }
8126: }
8127: }
8128: return;
8129: }
8130:
1.971 raeburn 8131: sub get_standard_codeitems {
8132: return ('Year','Semester','Department','Number','Section');
8133: }
8134:
1.112 bowersj2 8135: =pod
8136:
1.780 raeburn 8137: =head1 Slot Helpers
8138:
8139: =over 4
8140:
8141: =item * sorted_slots()
8142:
8143: Sorts an array of slot names in order of slot start time (earliest first).
8144:
8145: Inputs:
8146:
8147: =over 4
8148:
8149: slotsarr - Reference to array of unsorted slot names.
8150:
8151: slots - Reference to hash of hash, where outer hash keys are slot names.
8152:
1.549 albertel 8153: =back
8154:
1.780 raeburn 8155: Returns:
8156:
8157: =over 4
8158:
8159: sorted - An array of slot names sorted by the start time of the slot.
8160:
8161: =back
8162:
8163: =back
8164:
8165: =cut
8166:
8167:
8168: sub sorted_slots {
8169: my ($slotsarr,$slots) = @_;
8170: my @sorted;
8171: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8172: @sorted =
8173: sort {
8174: if (ref($slots->{$a}) && ref($slots->{$b})) {
8175: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8176: }
8177: if (ref($slots->{$a})) { return -1;}
8178: if (ref($slots->{$b})) { return 1;}
8179: return 0;
8180: } @{$slotsarr};
8181: }
8182: return @sorted;
8183: }
8184:
8185:
8186: =pod
8187:
1.549 albertel 8188: =head1 HTTP Helpers
8189:
8190: =over 4
8191:
1.648 raeburn 8192: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8193:
1.258 albertel 8194: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8195: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8196: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8197:
8198: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8199: $possible_names is an ref to an array of form element names. As an example:
8200: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8201: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8202:
8203: =cut
1.1 albertel 8204:
1.6 albertel 8205: sub get_unprocessed_cgi {
1.25 albertel 8206: my ($query,$possible_names)= @_;
1.26 matthew 8207: # $Apache::lonxml::debug=1;
1.356 albertel 8208: foreach my $pair (split(/&/,$query)) {
8209: my ($name, $value) = split(/=/,$pair);
1.369 www 8210: $name = &unescape($name);
1.25 albertel 8211: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8212: $value =~ tr/+/ /;
8213: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8214: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8215: }
1.16 harris41 8216: }
1.6 albertel 8217: }
8218:
1.112 bowersj2 8219: =pod
8220:
1.648 raeburn 8221: =item * &cacheheader()
1.112 bowersj2 8222:
8223: returns cache-controlling header code
8224:
8225: =cut
8226:
1.7 albertel 8227: sub cacheheader {
1.258 albertel 8228: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8229: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8230: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8231: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8232: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8233: return $output;
1.7 albertel 8234: }
8235:
1.112 bowersj2 8236: =pod
8237:
1.648 raeburn 8238: =item * &no_cache($r)
1.112 bowersj2 8239:
8240: specifies header code to not have cache
8241:
8242: =cut
8243:
1.9 albertel 8244: sub no_cache {
1.216 albertel 8245: my ($r) = @_;
8246: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8247: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8248: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8249: $r->no_cache(1);
8250: $r->header_out("Expires" => $date);
8251: $r->header_out("Pragma" => "no-cache");
1.123 www 8252: }
8253:
8254: sub content_type {
1.181 albertel 8255: my ($r,$type,$charset) = @_;
1.299 foxr 8256: if ($r) {
8257: # Note that printout.pl calls this with undef for $r.
8258: &no_cache($r);
8259: }
1.258 albertel 8260: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8261: unless ($charset) {
8262: $charset=&Apache::lonlocal::current_encoding;
8263: }
8264: if ($charset) { $type.='; charset='.$charset; }
8265: if ($r) {
8266: $r->content_type($type);
8267: } else {
8268: print("Content-type: $type\n\n");
8269: }
1.9 albertel 8270: }
1.25 albertel 8271:
1.112 bowersj2 8272: =pod
8273:
1.648 raeburn 8274: =item * &add_to_env($name,$value)
1.112 bowersj2 8275:
1.258 albertel 8276: adds $name to the %env hash with value
1.112 bowersj2 8277: $value, if $name already exists, the entry is converted to an array
8278: reference and $value is added to the array.
8279:
8280: =cut
8281:
1.25 albertel 8282: sub add_to_env {
8283: my ($name,$value)=@_;
1.258 albertel 8284: if (defined($env{$name})) {
8285: if (ref($env{$name})) {
1.25 albertel 8286: #already have multiple values
1.258 albertel 8287: push(@{ $env{$name} },$value);
1.25 albertel 8288: } else {
8289: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8290: my $first=$env{$name};
8291: undef($env{$name});
8292: push(@{ $env{$name} },$first,$value);
1.25 albertel 8293: }
8294: } else {
1.258 albertel 8295: $env{$name}=$value;
1.25 albertel 8296: }
1.31 albertel 8297: }
1.149 albertel 8298:
8299: =pod
8300:
1.648 raeburn 8301: =item * &get_env_multiple($name)
1.149 albertel 8302:
1.258 albertel 8303: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8304: values may be defined and end up as an array ref.
8305:
8306: returns an array of values
8307:
8308: =cut
8309:
8310: sub get_env_multiple {
8311: my ($name) = @_;
8312: my @values;
1.258 albertel 8313: if (defined($env{$name})) {
1.149 albertel 8314: # exists is it an array
1.258 albertel 8315: if (ref($env{$name})) {
8316: @values=@{ $env{$name} };
1.149 albertel 8317: } else {
1.258 albertel 8318: $values[0]=$env{$name};
1.149 albertel 8319: }
8320: }
8321: return(@values);
8322: }
8323:
1.660 raeburn 8324: sub ask_for_embedded_content {
8325: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.987 raeburn 8326: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660 raeburn 8327: my $num = 0;
1.987 raeburn 8328: my $numremref = 0;
8329: my $numinvalid = 0;
8330: my $numpathchg = 0;
8331: my $numexisting = 0;
8332: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.984 raeburn 8333: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8334: my $current_path='/';
8335: if ($env{'form.currentpath'}) {
8336: $current_path = $env{'form.currentpath'};
8337: }
8338: if ($actionurl eq '/adm/coursegrp_portfolio') {
8339: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8340: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8341: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8342: } else {
8343: $udom = $env{'user.domain'};
8344: $uname = $env{'user.name'};
8345: $url = '/userfiles/portfolio';
8346: }
1.987 raeburn 8347: $toplevel = $url.'/';
1.984 raeburn 8348: $url .= $current_path;
8349: $getpropath = 1;
1.987 raeburn 8350: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8351: ($actionurl eq '/adm/imsimport')) {
1.984 raeburn 8352: ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
1.987 raeburn 8353: $url = '/home/'.$uname.'/public_html/';
8354: $toplevel = $url;
1.984 raeburn 8355: if ($rest ne '') {
1.987 raeburn 8356: $url .= $rest;
8357: }
8358: } elsif ($actionurl eq '/adm/coursedocs') {
8359: if (ref($args) eq 'HASH') {
8360: $url = $args->{'docs_url'};
8361: $toplevel = $url;
8362: }
8363: }
8364: my $now = time();
8365: foreach my $embed_file (keys(%{$allfiles})) {
8366: my $absolutepath;
8367: if ($embed_file =~ m{^\w+://}) {
8368: $newfiles{$embed_file} = 1;
8369: $mapping{$embed_file} = $embed_file;
8370: } else {
8371: if ($embed_file =~ m{^/}) {
8372: $absolutepath = $embed_file;
8373: $embed_file =~ s{^(/+)}{};
8374: }
8375: if ($embed_file =~ m{/}) {
8376: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8377: $path = &check_for_traversal($path,$url,$toplevel);
8378: my $item = $fname;
8379: if ($path ne '') {
8380: $item = $path.'/'.$fname;
8381: $subdependencies{$path}{$fname} = 1;
8382: } else {
8383: $dependencies{$item} = 1;
8384: }
8385: if ($absolutepath) {
8386: $mapping{$item} = $absolutepath;
8387: } else {
8388: $mapping{$item} = $embed_file;
8389: }
8390: } else {
8391: $dependencies{$embed_file} = 1;
8392: if ($absolutepath) {
8393: $mapping{$embed_file} = $absolutepath;
8394: } else {
8395: $mapping{$embed_file} = $embed_file;
8396: }
8397: }
1.984 raeburn 8398: }
8399: }
8400: foreach my $path (keys(%subdependencies)) {
8401: my %currsubfile;
8402: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8403: my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8404: foreach my $line (@subdir_list) {
8405: my ($file_name,$rest) = split(/\&/,$line,2);
8406: $currsubfile{$file_name} = 1;
8407: }
1.987 raeburn 8408: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 8409: if (opendir(my $dir,$url.'/'.$path)) {
8410: my @subdir_list = grep(!/^\./,readdir($dir));
8411: map {$currsubfile{$_} = 1;} @subdir_list;
8412: }
8413: }
8414: foreach my $file (keys(%{$subdependencies{$path}})) {
1.987 raeburn 8415: if ($currsubfile{$file}) {
8416: my $item = $path.'/'.$file;
8417: unless ($mapping{$item} eq $item) {
8418: $pathchanges{$item} = 1;
8419: }
8420: $existing{$item} = 1;
8421: $numexisting ++;
8422: } else {
8423: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 8424: }
8425: }
8426: }
1.987 raeburn 8427: my %currfile;
1.984 raeburn 8428: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8429: my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8430: foreach my $line (@dir_list) {
8431: my ($file_name,$rest) = split(/\&/,$line,2);
8432: $currfile{$file_name} = 1;
8433: }
1.987 raeburn 8434: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 8435: if (opendir(my $dir,$url)) {
1.987 raeburn 8436: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 8437: map {$currfile{$_} = 1;} @dir_list;
8438: }
8439: }
8440: foreach my $file (keys(%dependencies)) {
1.987 raeburn 8441: if ($currfile{$file}) {
8442: unless ($mapping{$file} eq $file) {
8443: $pathchanges{$file} = 1;
8444: }
8445: $existing{$file} = 1;
8446: $numexisting ++;
8447: } else {
1.984 raeburn 8448: $newfiles{$file} = 1;
8449: }
8450: }
8451: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8452: $upload_output .= &start_data_table_row().
1.987 raeburn 8453: '<td><span class="LC_filename">'.$embed_file.'</span>';
8454: unless ($mapping{$embed_file} eq $embed_file) {
8455: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
8456: }
8457: $upload_output .= '</td><td>';
1.660 raeburn 8458: if ($args->{'ignore_remote_references'}
8459: && $embed_file =~ m{^\w+://}) {
8460: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 8461: $numremref++;
1.660 raeburn 8462: } elsif ($args->{'error_on_invalid_names'}
8463: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8464:
1.987 raeburn 8465: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
8466: $numinvalid++;
1.660 raeburn 8467: } else {
1.987 raeburn 8468: $upload_output .= &embedded_file_element('upload_embedded',$num,
8469: $embed_file,\%mapping,
8470: $allfiles,$codebase);
8471: $num++;
8472: }
8473: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
8474: }
8475: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
8476: $upload_output .= &start_data_table_row().
8477: '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
8478: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
8479: &Apache::loncommon::end_data_table_row()."\n";
8480: }
8481: if ($upload_output) {
8482: $upload_output = &start_data_table().
8483: $upload_output.
8484: &end_data_table()."\n";
8485: }
8486: my $applies = 0;
8487: if ($numremref) {
8488: $applies ++;
8489: }
8490: if ($numinvalid) {
8491: $applies ++;
8492: }
8493: if ($numexisting) {
8494: $applies ++;
8495: }
8496: if ($num) {
8497: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8498: ' method="post" enctype="multipart/form-data">'."\n".
8499: $state.
8500: '<h3>'.&mt('Upload embedded files').
8501: ':</h3>'.$upload_output.'<br />'."\n".
8502: '<input type ="hidden" name="number_embedded_items" value="'.
8503: $num.'" />'."\n";
8504: if ($actionurl eq '') {
8505: $output .= '<input type="hidden" name="phase" value="three" />';
8506: }
8507: } elsif ($applies) {
8508: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
8509: if ($applies > 1) {
8510: $output .=
8511: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
8512: if ($numremref) {
8513: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
8514: }
8515: if ($numinvalid) {
8516: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
8517: }
8518: if ($numexisting) {
8519: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
8520: }
8521: $output .= '</ul><br />';
8522: } elsif ($numremref) {
8523: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
8524: } elsif ($numinvalid) {
8525: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
8526: } elsif ($numexisting) {
8527: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
8528: }
8529: $output .= $upload_output.'<br />';
8530: }
8531: my ($pathchange_output,$chgcount);
8532: $chgcount = $num;
8533: if (keys(%pathchanges) > 0) {
8534: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
8535: if ($num) {
8536: $output .= &embedded_file_element('pathchange',$chgcount,
8537: $embed_file,\%mapping,
8538: $allfiles,$codebase);
8539: } else {
8540: $pathchange_output .=
8541: &start_data_table_row().
8542: '<td><input type ="checkbox" name="namechange" value="'.
8543: $chgcount.'" checked="checked" /></td>'.
8544: '<td>'.$mapping{$embed_file}.'</td>'.
8545: '<td>'.$embed_file.
8546: &embedded_file_element('pathchange',$numpathchg,$embed_file,
8547: \%mapping,$allfiles,$codebase).
8548: '</td>'.&end_data_table_row();
1.660 raeburn 8549: }
1.987 raeburn 8550: $numpathchg ++;
8551: $chgcount ++;
1.660 raeburn 8552: }
8553: }
1.984 raeburn 8554: if ($num) {
1.987 raeburn 8555: if ($numpathchg) {
8556: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
8557: $numpathchg.'" />'."\n";
8558: }
8559: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8560: ($actionurl eq '/adm/imsimport')) {
8561: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
8562: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
8563: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
8564: }
8565: $output .= '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8566: &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
8567: } elsif ($numpathchg) {
8568: my %pathchange = ();
8569: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
8570: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8571: $output .= '<p>'.&mt('or').'</p>';
8572: }
8573: }
8574: return ($output,$num,$numpathchg);
8575: }
8576:
8577: sub embedded_file_element {
8578: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
8579: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
8580: (ref($codebase) eq 'HASH'));
8581: my $output;
8582: if ($context eq 'upload_embedded') {
8583: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
8584: }
8585: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
8586: &escape($embed_file).'" />';
8587: unless (($context eq 'upload_embedded') &&
8588: ($mapping->{$embed_file} eq $embed_file)) {
8589: $output .='
8590: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
8591: }
8592: my $attrib;
8593: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
8594: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
8595: }
8596: $output .=
8597: "\n\t\t".
8598: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8599: $attrib.'" />';
8600: if (exists($codebase->{$mapping->{$embed_file}})) {
8601: $output .=
8602: "\n\t\t".
8603: '<input name="codebase_'.$num.'" type="hidden" value="'.
8604: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 8605: }
1.987 raeburn 8606: return $output;
1.660 raeburn 8607: }
8608:
1.661 raeburn 8609: sub upload_embedded {
8610: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 8611: $current_disk_usage,$hiddenstate,$actionurl) = @_;
8612: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 8613: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8614: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8615: my $orig_uploaded_filename =
8616: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 8617: foreach my $type ('orig','ref','attrib','codebase') {
8618: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
8619: $env{'form.embedded_'.$type.'_'.$i} =
8620: &unescape($env{'form.embedded_'.$type.'_'.$i});
8621: }
8622: }
1.661 raeburn 8623: my ($path,$fname) =
8624: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8625: # no path, whole string is fname
8626: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8627: $fname = &Apache::lonnet::clean_filename($fname);
8628: # See if there is anything left
8629: next if ($fname eq '');
8630:
8631: # Check if file already exists as a file or directory.
8632: my ($state,$msg);
8633: if ($context eq 'portfolio') {
8634: my $port_path = $dirpath;
8635: if ($group ne '') {
8636: $port_path = "groups/$group/$port_path";
8637: }
1.987 raeburn 8638: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
8639: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 8640: $dir_root,$port_path,$disk_quota,
8641: $current_disk_usage,$uname,$udom);
8642: if ($state eq 'will_exceed_quota'
1.984 raeburn 8643: || $state eq 'file_locked') {
1.661 raeburn 8644: $output .= $msg;
8645: next;
8646: }
8647: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8648: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8649: if ($state eq 'exists') {
8650: $output .= $msg;
8651: next;
8652: }
8653: }
8654: # Check if extension is valid
8655: if (($fname =~ /\.(\w+)$/) &&
8656: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 8657: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 8658: next;
8659: } elsif (($fname =~ /\.(\w+)$/) &&
8660: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 8661: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 8662: next;
8663: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 8664: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 8665: next;
8666: }
8667:
8668: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8669: if ($context eq 'portfolio') {
1.984 raeburn 8670: my $result;
8671: if ($state eq 'existingfile') {
8672: $result=
8673: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 8674: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 8675: } else {
1.984 raeburn 8676: $result=
8677: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 8678: $dirpath.
8679: $env{'form.currentpath'}.$path);
1.984 raeburn 8680: if ($result !~ m|^/uploaded/|) {
8681: $output .= '<span class="LC_error">'
8682: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8683: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8684: .'</span><br />';
8685: next;
8686: } else {
1.987 raeburn 8687: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8688: $path.$fname.'</span>').'<br />';
1.984 raeburn 8689: }
1.661 raeburn 8690: }
1.987 raeburn 8691: } elsif ($context eq 'coursedoc') {
8692: my $result =
8693: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
8694: $dirpath.'/'.$path);
8695: if ($result !~ m|^/uploaded/|) {
8696: $output .= '<span class="LC_error">'
8697: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8698: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8699: .'</span><br />';
8700: next;
8701: } else {
8702: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8703: $path.$fname.'</span>').'<br />';
8704: }
1.661 raeburn 8705: } else {
8706: # Save the file
8707: my $target = $env{'form.embedded_item_'.$i};
8708: my $fullpath = $dir_root.$dirpath.'/'.$path;
8709: my $dest = $fullpath.$fname;
8710: my $url = $url_root.$dirpath.'/'.$path.$fname;
8711: my @parts=split(/\//,$fullpath);
8712: my $count;
8713: my $filepath = $dir_root;
8714: for ($count=4;$count<=$#parts;$count++) {
8715: $filepath .= "/$parts[$count]";
8716: if ((-e $filepath)!=1) {
8717: mkdir($filepath,0770);
8718: }
8719: }
8720: my $fh;
8721: if (!open($fh,'>'.$dest)) {
8722: &Apache::lonnet::logthis('Failed to create '.$dest);
8723: $output .= '<span class="LC_error">'.
8724: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8725: '</span><br />';
8726: } else {
8727: if (!print $fh $env{'form.embedded_item_'.$i}) {
8728: &Apache::lonnet::logthis('Failed to write to '.$dest);
8729: $output .= '<span class="LC_error">'.
8730: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8731: '</span><br />';
8732: } else {
1.987 raeburn 8733: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8734: $url.'</span>').'<br />';
8735: unless ($context eq 'testbank') {
8736: $footer .= &mt('View embedded file: [_1]',
8737: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
8738: }
8739: }
8740: close($fh);
8741: }
8742: }
8743: if ($env{'form.embedded_ref_'.$i}) {
8744: $pathchange{$i} = 1;
8745: }
8746: }
8747: if ($output) {
8748: $output = '<p>'.$output.'</p>';
8749: }
8750: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
8751: $returnflag = 'ok';
8752: if (keys(%pathchange) > 0) {
8753: if ($context eq 'portfolio') {
8754: $output .= '<p>'.&mt('or').'</p>';
8755: } elsif ($context eq 'testbank') {
1.988 ! raeburn 8756: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 8757: $returnflag = 'modify_orightml';
8758: }
8759: }
8760: return ($output.$footer,$returnflag);
8761: }
8762:
8763: sub modify_html_form {
8764: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
8765: my $end = 0;
8766: my $modifyform;
8767: if ($context eq 'upload_embedded') {
8768: return unless (ref($pathchange) eq 'HASH');
8769: if ($env{'form.number_embedded_items'}) {
8770: $end += $env{'form.number_embedded_items'};
8771: }
8772: if ($env{'form.number_pathchange_items'}) {
8773: $end += $env{'form.number_pathchange_items'};
8774: }
8775: if ($end) {
8776: for (my $i=0; $i<$end; $i++) {
8777: if ($i < $env{'form.number_embedded_items'}) {
8778: next unless($pathchange->{$i});
8779: }
8780: $modifyform .=
8781: &start_data_table_row().
8782: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
8783: 'checked="checked" /></td>'.
8784: '<td>'.$env{'form.embedded_ref_'.$i}.
8785: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
8786: &escape($env{'form.embedded_ref_'.$i}).'" />'.
8787: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
8788: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
8789: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
8790: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
8791: '<td>'.$env{'form.embedded_orig_'.$i}.
8792: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
8793: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
8794: &end_data_table_row();
8795: }
8796: }
8797: } else {
8798: $modifyform = $pathchgtable;
8799: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
8800: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
8801: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8802: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
8803: }
8804: }
8805: if ($modifyform) {
8806: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
8807: '<p>'.&mt('Changes need to be made to the reference(s) used for one or more of the dependencies, if your HTML file is to work correctly:').'<ol>'."\n".
8808: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
8809: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
8810: '</ol></p>'."\n".'<p>'.
8811: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
8812: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
8813: &start_data_table()."\n".
8814: &start_data_table_header_row().
8815: '<th>'.&mt('Change?').'</th>'.
8816: '<th>'.&mt('Current reference').'</th>'.
8817: '<th>'.&mt('Required reference').'</th>'.
8818: &end_data_table_header_row()."\n".
8819: $modifyform.
8820: &end_data_table().'<br />'."\n".$hiddenstate.
8821: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
8822: '</form>'."\n";
8823: }
8824: return;
8825: }
8826:
8827: sub modify_html_refs {
8828: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
8829: my $container;
8830: if ($context eq 'portfolio') {
8831: $container = $env{'form.container'};
8832: } elsif ($context eq 'coursedoc') {
8833: $container = $env{'form.primaryurl'};
8834: } else {
8835: $container = $env{'form.filename'};
8836: $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
8837: }
8838: my (%allfiles,%codebase,$output,$content);
8839: my @changes = &get_env_multiple('form.namechange');
8840: return unless (@changes > 0);
8841: if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
8842: return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
8843: $content = &Apache::lonnet::getfile($container);
8844: return if ($content eq '-1');
8845: } else {
8846: return unless ($container =~ /^\Q$dir_root\E/);
8847: if (open(my $fh,"<$container")) {
8848: $content = join('', <$fh>);
8849: close($fh);
8850: } else {
8851: return;
8852: }
8853: }
8854: my ($count,$codebasecount) = (0,0);
8855: my $mm = new File::MMagic;
8856: my $mime_type = $mm->checktype_contents($content);
8857: if ($mime_type eq 'text/html') {
8858: my $parse_result =
8859: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
8860: \%codebase,\$content);
8861: if ($parse_result eq 'ok') {
8862: foreach my $i (@changes) {
8863: my $orig = &unescape($env{'form.embedded_orig_'.$i});
8864: my $ref = &unescape($env{'form.embedded_ref_'.$i});
8865: if ($allfiles{$ref}) {
8866: my $newname = $orig;
8867: my ($attrib_regexp,$codebase);
8868: my $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
8869: if ($attrib_regexp =~ /:/) {
8870: $attrib_regexp =~ s/\:/|/g;
8871: }
8872: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
8873: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
8874: $count += $numchg;
8875: }
8876: if ($env{'form.embedded_codebase_'.$i} ne '') {
8877: my $codebase = &unescape($env{'form.embedded_codebase_'.$i});
8878: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
8879: $codebasecount ++;
8880: }
8881: }
8882: }
8883: if ($count || $codebasecount) {
8884: my $saveresult;
8885: if ($context eq 'portfolio' || $context eq 'coursedoc') {
8886: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
8887: if ($url eq $container) {
8888: my ($fname) = ($container =~ m{/([^/]+)$});
8889: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
8890: $count,'<span class="LC_filename">'.
8891: $fname.'</span>').'</p>';
8892: } else {
8893: $output = '<p class="LC_error">'.
8894: &mt('Error: update failed for: [_1].',
8895: '<span class="LC_filename">'.
8896: $container.'</span>').'</p>';
8897: }
8898: } else {
8899: if (open(my $fh,">$container")) {
8900: print $fh $content;
8901: close($fh);
8902: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
8903: $count,'<span class="LC_filename">'.
8904: $container.'</span>').'</p>';
1.661 raeburn 8905: } else {
1.987 raeburn 8906: $output = '<p class="LC_error">'.
8907: &mt('Error: could not update [_1].',
8908: '<span class="LC_filename">'.
8909: $container.'</span>').'</p>';
1.661 raeburn 8910: }
8911: }
8912: }
1.987 raeburn 8913: } else {
8914: &logthis('Failed to parse '.$container.
8915: ' to modify references: '.$parse_result);
1.661 raeburn 8916: }
8917: }
8918: return $output;
8919: }
8920:
8921: sub check_for_existing {
8922: my ($path,$fname,$element) = @_;
8923: my ($state,$msg);
8924: if (-d $path.'/'.$fname) {
8925: $state = 'exists';
8926: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8927: } elsif (-e $path.'/'.$fname) {
8928: $state = 'exists';
8929: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8930: }
8931: if ($state eq 'exists') {
8932: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8933: }
8934: return ($state,$msg);
8935: }
8936:
8937: sub check_for_upload {
8938: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8939: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 8940: my $filesize = length($env{'form.'.$element});
8941: if (!$filesize) {
8942: my $msg = '<span class="LC_error">'.
8943: &mt('Unable to upload [_1]. (size = [_2] bytes)',
8944: '<span class="LC_filename">'.$fname.'</span>',
8945: $filesize).'<br />'.
8946: &mt('Either the file you uploaded was empty, or your web browser was unable to read its contents.').'<br />';
8947: '</span>';
8948: return ('zero_bytes',$msg);
8949: }
8950: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 8951: my $getpropath = 1;
8952: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8953: $getpropath);
8954: my $found_file = 0;
8955: my $locked_file = 0;
8956: foreach my $line (@dir_list) {
1.984 raeburn 8957: my ($file_name,$rest)=split(/\&/,$line,2);
1.661 raeburn 8958: if ($file_name eq $fname){
8959: $file_name = $path.$file_name;
8960: if ($group ne '') {
8961: $file_name = $group.$file_name;
8962: }
8963: $found_file = 1;
8964: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8965: $locked_file = 1;
1.984 raeburn 8966: } else {
8967: my @info = split(/\&/,$rest);
8968: my $currsize = $info[6]/1000;
8969: if ($currsize < $filesize) {
8970: my $extra = $filesize - $currsize;
8971: if (($current_disk_usage + $extra) > $disk_quota) {
8972: my $msg = '<span class="LC_error">'.
8973: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
8974: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
8975: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8976: $disk_quota,$current_disk_usage);
8977: return ('will_exceed_quota',$msg);
8978: }
8979: }
1.661 raeburn 8980: }
8981: }
8982: }
8983: if (($current_disk_usage + $filesize) > $disk_quota){
8984: my $msg = '<span class="LC_error">'.
8985: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8986: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8987: return ('will_exceed_quota',$msg);
8988: } elsif ($found_file) {
8989: if ($locked_file) {
8990: my $msg = '<span class="LC_error">';
8991: $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>');
8992: $msg .= '</span><br />';
8993: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8994: return ('file_locked',$msg);
8995: } else {
8996: my $msg = '<span class="LC_error">';
1.984 raeburn 8997: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661 raeburn 8998: $msg .= '</span>';
1.984 raeburn 8999: return ('existingfile',$msg);
1.661 raeburn 9000: }
9001: }
9002: }
9003:
1.987 raeburn 9004: sub check_for_traversal {
9005: my ($path,$url,$toplevel) = @_;
9006: my @parts=split(/\//,$path);
9007: my $cleanpath;
9008: my $fullpath = $url;
9009: for (my $i=0;$i<@parts;$i++) {
9010: next if ($parts[$i] eq '.');
9011: if ($parts[$i] eq '..') {
9012: $fullpath =~ s{([^/]+/)$}{};
9013: } else {
9014: $fullpath .= $parts[$i].'/';
9015: }
9016: }
9017: if ($fullpath =~ /^\Q$url\E(.*)$/) {
9018: $cleanpath = $1;
9019: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
9020: my $curr_toprel = $1;
9021: my @parts = split(/\//,$curr_toprel);
9022: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
9023: my @urlparts = split(/\//,$url_toprel);
9024: my $doubledots;
9025: my $startdiff = -1;
9026: for (my $i=0; $i<@urlparts; $i++) {
9027: if ($startdiff == -1) {
9028: unless ($urlparts[$i] eq $parts[$i]) {
9029: $startdiff = $i;
9030: $doubledots .= '../';
9031: }
9032: } else {
9033: $doubledots .= '../';
9034: }
9035: }
9036: if ($startdiff > -1) {
9037: $cleanpath = $doubledots;
9038: for (my $i=$startdiff; $i<@parts; $i++) {
9039: $cleanpath .= $parts[$i].'/';
9040: }
9041: }
9042: }
9043: $cleanpath =~ s{(/)$}{};
9044: return $cleanpath;
9045: }
1.31 albertel 9046:
1.41 ng 9047: =pod
1.45 matthew 9048:
1.464 albertel 9049: =back
1.41 ng 9050:
1.112 bowersj2 9051: =head1 CSV Upload/Handling functions
1.38 albertel 9052:
1.41 ng 9053: =over 4
9054:
1.648 raeburn 9055: =item * &upfile_store($r)
1.41 ng 9056:
9057: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 9058: needs $env{'form.upfile'}
1.41 ng 9059: returns $datatoken to be put into hidden field
9060:
9061: =cut
1.31 albertel 9062:
9063: sub upfile_store {
9064: my $r=shift;
1.258 albertel 9065: $env{'form.upfile'}=~s/\r/\n/gs;
9066: $env{'form.upfile'}=~s/\f/\n/gs;
9067: $env{'form.upfile'}=~s/\n+/\n/gs;
9068: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 9069:
1.258 albertel 9070: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
9071: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 9072: {
1.158 raeburn 9073: my $datafile = $r->dir_config('lonDaemons').
9074: '/tmp/'.$datatoken.'.tmp';
9075: if ( open(my $fh,">$datafile") ) {
1.258 albertel 9076: print $fh $env{'form.upfile'};
1.158 raeburn 9077: close($fh);
9078: }
1.31 albertel 9079: }
9080: return $datatoken;
9081: }
9082:
1.56 matthew 9083: =pod
9084:
1.648 raeburn 9085: =item * &load_tmp_file($r)
1.41 ng 9086:
9087: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 9088: needs $env{'form.datatoken'},
9089: sets $env{'form.upfile'} to the contents of the file
1.41 ng 9090:
9091: =cut
1.31 albertel 9092:
9093: sub load_tmp_file {
9094: my $r=shift;
9095: my @studentdata=();
9096: {
1.158 raeburn 9097: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 9098: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 9099: if ( open(my $fh,"<$studentfile") ) {
9100: @studentdata=<$fh>;
9101: close($fh);
9102: }
1.31 albertel 9103: }
1.258 albertel 9104: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 9105: }
9106:
1.56 matthew 9107: =pod
9108:
1.648 raeburn 9109: =item * &upfile_record_sep()
1.41 ng 9110:
9111: Separate uploaded file into records
9112: returns array of records,
1.258 albertel 9113: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 9114:
9115: =cut
1.31 albertel 9116:
9117: sub upfile_record_sep {
1.258 albertel 9118: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 9119: } else {
1.248 albertel 9120: my @records;
1.258 albertel 9121: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 9122: if ($line=~/^\s*$/) { next; }
9123: push(@records,$line);
9124: }
9125: return @records;
1.31 albertel 9126: }
9127: }
9128:
1.56 matthew 9129: =pod
9130:
1.648 raeburn 9131: =item * &record_sep($record)
1.41 ng 9132:
1.258 albertel 9133: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 9134:
9135: =cut
9136:
1.263 www 9137: sub takeleft {
9138: my $index=shift;
9139: return substr('0000'.$index,-4,4);
9140: }
9141:
1.31 albertel 9142: sub record_sep {
9143: my $record=shift;
9144: my %components=();
1.258 albertel 9145: if ($env{'form.upfiletype'} eq 'xml') {
9146: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 9147: my $i=0;
1.356 albertel 9148: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 9149: $field=~s/^(\"|\')//;
9150: $field=~s/(\"|\')$//;
1.263 www 9151: $components{&takeleft($i)}=$field;
1.31 albertel 9152: $i++;
9153: }
1.258 albertel 9154: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 9155: my $i=0;
1.356 albertel 9156: foreach my $field (split(/\t/,$record)) {
1.31 albertel 9157: $field=~s/^(\"|\')//;
9158: $field=~s/(\"|\')$//;
1.263 www 9159: $components{&takeleft($i)}=$field;
1.31 albertel 9160: $i++;
9161: }
9162: } else {
1.561 www 9163: my $separator=',';
1.480 banghart 9164: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 9165: $separator=';';
1.480 banghart 9166: }
1.31 albertel 9167: my $i=0;
1.561 www 9168: # the character we are looking for to indicate the end of a quote or a record
9169: my $looking_for=$separator;
9170: # do not add the characters to the fields
9171: my $ignore=0;
9172: # we just encountered a separator (or the beginning of the record)
9173: my $just_found_separator=1;
9174: # store the field we are working on here
9175: my $field='';
9176: # work our way through all characters in record
9177: foreach my $character ($record=~/(.)/g) {
9178: if ($character eq $looking_for) {
9179: if ($character ne $separator) {
9180: # Found the end of a quote, again looking for separator
9181: $looking_for=$separator;
9182: $ignore=1;
9183: } else {
9184: # Found a separator, store away what we got
9185: $components{&takeleft($i)}=$field;
9186: $i++;
9187: $just_found_separator=1;
9188: $ignore=0;
9189: $field='';
9190: }
9191: next;
9192: }
9193: # single or double quotation marks after a separator indicate beginning of a quote
9194: # we are now looking for the end of the quote and need to ignore separators
9195: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
9196: $looking_for=$character;
9197: next;
9198: }
9199: # ignore would be true after we reached the end of a quote
9200: if ($ignore) { next; }
9201: if (($just_found_separator) && ($character=~/\s/)) { next; }
9202: $field.=$character;
9203: $just_found_separator=0;
1.31 albertel 9204: }
1.561 www 9205: # catch the very last entry, since we never encountered the separator
9206: $components{&takeleft($i)}=$field;
1.31 albertel 9207: }
9208: return %components;
9209: }
9210:
1.144 matthew 9211: ######################################################
9212: ######################################################
9213:
1.56 matthew 9214: =pod
9215:
1.648 raeburn 9216: =item * &upfile_select_html()
1.41 ng 9217:
1.144 matthew 9218: Return HTML code to select a file from the users machine and specify
9219: the file type.
1.41 ng 9220:
9221: =cut
9222:
1.144 matthew 9223: ######################################################
9224: ######################################################
1.31 albertel 9225: sub upfile_select_html {
1.144 matthew 9226: my %Types = (
9227: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 9228: semisv => &mt('Semicolon separated values'),
1.144 matthew 9229: space => &mt('Space separated'),
9230: tab => &mt('Tabulator separated'),
9231: # xml => &mt('HTML/XML'),
9232: );
9233: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 9234: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 9235: foreach my $type (sort(keys(%Types))) {
9236: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
9237: }
9238: $Str .= "</select>\n";
9239: return $Str;
1.31 albertel 9240: }
9241:
1.301 albertel 9242: sub get_samples {
9243: my ($records,$toget) = @_;
9244: my @samples=({});
9245: my $got=0;
9246: foreach my $rec (@$records) {
9247: my %temp = &record_sep($rec);
9248: if (! grep(/\S/, values(%temp))) { next; }
9249: if (%temp) {
9250: $samples[$got]=\%temp;
9251: $got++;
9252: if ($got == $toget) { last; }
9253: }
9254: }
9255: return \@samples;
9256: }
9257:
1.144 matthew 9258: ######################################################
9259: ######################################################
9260:
1.56 matthew 9261: =pod
9262:
1.648 raeburn 9263: =item * &csv_print_samples($r,$records)
1.41 ng 9264:
9265: Prints a table of sample values from each column uploaded $r is an
9266: Apache Request ref, $records is an arrayref from
9267: &Apache::loncommon::upfile_record_sep
9268:
9269: =cut
9270:
1.144 matthew 9271: ######################################################
9272: ######################################################
1.31 albertel 9273: sub csv_print_samples {
9274: my ($r,$records) = @_;
1.662 bisitz 9275: my $samples = &get_samples($records,5);
1.301 albertel 9276:
1.594 raeburn 9277: $r->print(&mt('Samples').'<br />'.&start_data_table().
9278: &start_data_table_header_row());
1.356 albertel 9279: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 9280: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 9281: $r->print(&end_data_table_header_row());
1.301 albertel 9282: foreach my $hash (@$samples) {
1.594 raeburn 9283: $r->print(&start_data_table_row());
1.356 albertel 9284: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 9285: $r->print('<td>');
1.356 albertel 9286: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 9287: $r->print('</td>');
9288: }
1.594 raeburn 9289: $r->print(&end_data_table_row());
1.31 albertel 9290: }
1.594 raeburn 9291: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 9292: }
9293:
1.144 matthew 9294: ######################################################
9295: ######################################################
9296:
1.56 matthew 9297: =pod
9298:
1.648 raeburn 9299: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 9300:
9301: Prints a table to create associations between values and table columns.
1.144 matthew 9302:
1.41 ng 9303: $r is an Apache Request ref,
9304: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 9305: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 9306:
9307: =cut
9308:
1.144 matthew 9309: ######################################################
9310: ######################################################
1.31 albertel 9311: sub csv_print_select_table {
9312: my ($r,$records,$d) = @_;
1.301 albertel 9313: my $i=0;
9314: my $samples = &get_samples($records,1);
1.144 matthew 9315: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 9316: &start_data_table().&start_data_table_header_row().
1.144 matthew 9317: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 9318: '<th>'.&mt('Column').'</th>'.
9319: &end_data_table_header_row()."\n");
1.356 albertel 9320: foreach my $array_ref (@$d) {
9321: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 9322: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 9323:
1.875 bisitz 9324: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 9325: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 9326: $r->print('<option value="none"></option>');
1.356 albertel 9327: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
9328: $r->print('<option value="'.$sample.'"'.
9329: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 9330: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 9331: }
1.594 raeburn 9332: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 9333: $i++;
9334: }
1.594 raeburn 9335: $r->print(&end_data_table());
1.31 albertel 9336: $i--;
9337: return $i;
9338: }
1.56 matthew 9339:
1.144 matthew 9340: ######################################################
9341: ######################################################
9342:
1.56 matthew 9343: =pod
1.31 albertel 9344:
1.648 raeburn 9345: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 9346:
9347: Prints a table of sample values from the upload and can make associate samples to internal names.
9348:
9349: $r is an Apache Request ref,
9350: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
9351: $d is an array of 2 element arrays (internal name, displayed name)
9352:
9353: =cut
9354:
1.144 matthew 9355: ######################################################
9356: ######################################################
1.31 albertel 9357: sub csv_samples_select_table {
9358: my ($r,$records,$d) = @_;
9359: my $i=0;
1.144 matthew 9360: #
1.662 bisitz 9361: my $max_samples = 5;
9362: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 9363: $r->print(&start_data_table().
9364: &start_data_table_header_row().'<th>'.
9365: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
9366: &end_data_table_header_row());
1.301 albertel 9367:
9368: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 9369: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 9370: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 9371: foreach my $option (@$d) {
9372: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 9373: $r->print('<option value="'.$value.'"'.
1.253 albertel 9374: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 9375: $display.'</option>');
1.31 albertel 9376: }
9377: $r->print('</select></td><td>');
1.662 bisitz 9378: foreach my $line (0..($max_samples-1)) {
1.301 albertel 9379: if (defined($samples->[$line]{$key})) {
9380: $r->print($samples->[$line]{$key}."<br />\n");
9381: }
9382: }
1.594 raeburn 9383: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9384: $i++;
9385: }
1.594 raeburn 9386: $r->print(&end_data_table());
1.31 albertel 9387: $i--;
9388: return($i);
1.115 matthew 9389: }
9390:
1.144 matthew 9391: ######################################################
9392: ######################################################
9393:
1.115 matthew 9394: =pod
9395:
1.648 raeburn 9396: =item * &clean_excel_name($name)
1.115 matthew 9397:
9398: Returns a replacement for $name which does not contain any illegal characters.
9399:
9400: =cut
9401:
1.144 matthew 9402: ######################################################
9403: ######################################################
1.115 matthew 9404: sub clean_excel_name {
9405: my ($name) = @_;
9406: $name =~ s/[:\*\?\/\\]//g;
9407: if (length($name) > 31) {
9408: $name = substr($name,0,31);
9409: }
9410: return $name;
1.25 albertel 9411: }
1.84 albertel 9412:
1.85 albertel 9413: =pod
9414:
1.648 raeburn 9415: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9416:
9417: Returns either 1 or undef
9418:
9419: 1 if the part is to be hidden, undef if it is to be shown
9420:
9421: Arguments are:
9422:
9423: $id the id of the part to be checked
9424: $symb, optional the symb of the resource to check
9425: $udom, optional the domain of the user to check for
9426: $uname, optional the username of the user to check for
9427:
9428: =cut
1.84 albertel 9429:
9430: sub check_if_partid_hidden {
9431: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9432: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9433: $symb,$udom,$uname);
1.141 albertel 9434: my $truth=1;
9435: #if the string starts with !, then the list is the list to show not hide
9436: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9437: my @hiddenlist=split(/,/,$hiddenparts);
9438: foreach my $checkid (@hiddenlist) {
1.141 albertel 9439: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9440: }
1.141 albertel 9441: return !$truth;
1.84 albertel 9442: }
1.127 matthew 9443:
1.138 matthew 9444:
9445: ############################################################
9446: ############################################################
9447:
9448: =pod
9449:
1.157 matthew 9450: =back
9451:
1.138 matthew 9452: =head1 cgi-bin script and graphing routines
9453:
1.157 matthew 9454: =over 4
9455:
1.648 raeburn 9456: =item * &get_cgi_id()
1.138 matthew 9457:
9458: Inputs: none
9459:
9460: Returns an id which can be used to pass environment variables
9461: to various cgi-bin scripts. These environment variables will
9462: be removed from the users environment after a given time by
9463: the routine &Apache::lonnet::transfer_profile_to_env.
9464:
9465: =cut
9466:
9467: ############################################################
9468: ############################################################
1.152 albertel 9469: my $uniq=0;
1.136 matthew 9470: sub get_cgi_id {
1.154 albertel 9471: $uniq=($uniq+1)%100000;
1.280 albertel 9472: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9473: }
9474:
1.127 matthew 9475: ############################################################
9476: ############################################################
9477:
9478: =pod
9479:
1.648 raeburn 9480: =item * &DrawBarGraph()
1.127 matthew 9481:
1.138 matthew 9482: Facilitates the plotting of data in a (stacked) bar graph.
9483: Puts plot definition data into the users environment in order for
9484: graph.png to plot it. Returns an <img> tag for the plot.
9485: The bars on the plot are labeled '1','2',...,'n'.
9486:
9487: Inputs:
9488:
9489: =over 4
9490:
9491: =item $Title: string, the title of the plot
9492:
9493: =item $xlabel: string, text describing the X-axis of the plot
9494:
9495: =item $ylabel: string, text describing the Y-axis of the plot
9496:
9497: =item $Max: scalar, the maximum Y value to use in the plot
9498: If $Max is < any data point, the graph will not be rendered.
9499:
1.140 matthew 9500: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9501: they are plotted. If undefined, default values will be used.
9502:
1.178 matthew 9503: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9504:
1.138 matthew 9505: =item @Values: An array of array references. Each array reference holds data
9506: to be plotted in a stacked bar chart.
9507:
1.239 matthew 9508: =item If the final element of @Values is a hash reference the key/value
9509: pairs will be added to the graph definition.
9510:
1.138 matthew 9511: =back
9512:
9513: Returns:
9514:
9515: An <img> tag which references graph.png and the appropriate identifying
9516: information for the plot.
9517:
1.127 matthew 9518: =cut
9519:
9520: ############################################################
9521: ############################################################
1.134 matthew 9522: sub DrawBarGraph {
1.178 matthew 9523: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9524: #
9525: if (! defined($colors)) {
9526: $colors = ['#33ff00',
9527: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9528: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9529: ];
9530: }
1.228 matthew 9531: my $extra_settings = {};
9532: if (ref($Values[-1]) eq 'HASH') {
9533: $extra_settings = pop(@Values);
9534: }
1.127 matthew 9535: #
1.136 matthew 9536: my $identifier = &get_cgi_id();
9537: my $id = 'cgi.'.$identifier;
1.129 matthew 9538: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9539: return '';
9540: }
1.225 matthew 9541: #
9542: my @Labels;
9543: if (defined($labels)) {
9544: @Labels = @$labels;
9545: } else {
9546: for (my $i=0;$i<@{$Values[0]};$i++) {
9547: push (@Labels,$i+1);
9548: }
9549: }
9550: #
1.129 matthew 9551: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9552: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9553: my %ValuesHash;
9554: my $NumSets=1;
9555: foreach my $array (@Values) {
9556: next if (! ref($array));
1.136 matthew 9557: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9558: join(',',@$array);
1.129 matthew 9559: }
1.127 matthew 9560: #
1.136 matthew 9561: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9562: if ($NumBars < 3) {
9563: $width = 120+$NumBars*32;
1.220 matthew 9564: $xskip = 1;
1.225 matthew 9565: $bar_width = 30;
9566: } elsif ($NumBars < 5) {
9567: $width = 120+$NumBars*20;
9568: $xskip = 1;
9569: $bar_width = 20;
1.220 matthew 9570: } elsif ($NumBars < 10) {
1.136 matthew 9571: $width = 120+$NumBars*15;
9572: $xskip = 1;
9573: $bar_width = 15;
9574: } elsif ($NumBars <= 25) {
9575: $width = 120+$NumBars*11;
9576: $xskip = 5;
9577: $bar_width = 8;
9578: } elsif ($NumBars <= 50) {
9579: $width = 120+$NumBars*8;
9580: $xskip = 5;
9581: $bar_width = 4;
9582: } else {
9583: $width = 120+$NumBars*8;
9584: $xskip = 5;
9585: $bar_width = 4;
9586: }
9587: #
1.137 matthew 9588: $Max = 1 if ($Max < 1);
9589: if ( int($Max) < $Max ) {
9590: $Max++;
9591: $Max = int($Max);
9592: }
1.127 matthew 9593: $Title = '' if (! defined($Title));
9594: $xlabel = '' if (! defined($xlabel));
9595: $ylabel = '' if (! defined($ylabel));
1.369 www 9596: $ValuesHash{$id.'.title'} = &escape($Title);
9597: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9598: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9599: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9600: $ValuesHash{$id.'.NumBars'} = $NumBars;
9601: $ValuesHash{$id.'.NumSets'} = $NumSets;
9602: $ValuesHash{$id.'.PlotType'} = 'bar';
9603: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9604: $ValuesHash{$id.'.height'} = $height;
9605: $ValuesHash{$id.'.width'} = $width;
9606: $ValuesHash{$id.'.xskip'} = $xskip;
9607: $ValuesHash{$id.'.bar_width'} = $bar_width;
9608: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9609: #
1.228 matthew 9610: # Deal with other parameters
9611: while (my ($key,$value) = each(%$extra_settings)) {
9612: $ValuesHash{$id.'.'.$key} = $value;
9613: }
9614: #
1.646 raeburn 9615: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9616: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9617: }
9618:
9619: ############################################################
9620: ############################################################
9621:
9622: =pod
9623:
1.648 raeburn 9624: =item * &DrawXYGraph()
1.137 matthew 9625:
1.138 matthew 9626: Facilitates the plotting of data in an XY graph.
9627: Puts plot definition data into the users environment in order for
9628: graph.png to plot it. Returns an <img> tag for the plot.
9629:
9630: Inputs:
9631:
9632: =over 4
9633:
9634: =item $Title: string, the title of the plot
9635:
9636: =item $xlabel: string, text describing the X-axis of the plot
9637:
9638: =item $ylabel: string, text describing the Y-axis of the plot
9639:
9640: =item $Max: scalar, the maximum Y value to use in the plot
9641: If $Max is < any data point, the graph will not be rendered.
9642:
9643: =item $colors: Array ref containing the hex color codes for the data to be
9644: plotted in. If undefined, default values will be used.
9645:
9646: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9647:
9648: =item $Ydata: Array ref containing Array refs.
1.185 www 9649: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9650:
9651: =item %Values: hash indicating or overriding any default values which are
9652: passed to graph.png.
9653: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9654:
9655: =back
9656:
9657: Returns:
9658:
9659: An <img> tag which references graph.png and the appropriate identifying
9660: information for the plot.
9661:
1.137 matthew 9662: =cut
9663:
9664: ############################################################
9665: ############################################################
9666: sub DrawXYGraph {
9667: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9668: #
9669: # Create the identifier for the graph
9670: my $identifier = &get_cgi_id();
9671: my $id = 'cgi.'.$identifier;
9672: #
9673: $Title = '' if (! defined($Title));
9674: $xlabel = '' if (! defined($xlabel));
9675: $ylabel = '' if (! defined($ylabel));
9676: my %ValuesHash =
9677: (
1.369 www 9678: $id.'.title' => &escape($Title),
9679: $id.'.xlabel' => &escape($xlabel),
9680: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9681: $id.'.y_max_value'=> $Max,
9682: $id.'.labels' => join(',',@$Xlabels),
9683: $id.'.PlotType' => 'XY',
9684: );
9685: #
9686: if (defined($colors) && ref($colors) eq 'ARRAY') {
9687: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9688: }
9689: #
9690: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9691: return '';
9692: }
9693: my $NumSets=1;
1.138 matthew 9694: foreach my $array (@{$Ydata}){
1.137 matthew 9695: next if (! ref($array));
9696: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9697: }
1.138 matthew 9698: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9699: #
9700: # Deal with other parameters
9701: while (my ($key,$value) = each(%Values)) {
9702: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9703: }
9704: #
1.646 raeburn 9705: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9706: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9707: }
9708:
9709: ############################################################
9710: ############################################################
9711:
9712: =pod
9713:
1.648 raeburn 9714: =item * &DrawXYYGraph()
1.138 matthew 9715:
9716: Facilitates the plotting of data in an XY graph with two Y axes.
9717: Puts plot definition data into the users environment in order for
9718: graph.png to plot it. Returns an <img> tag for the plot.
9719:
9720: Inputs:
9721:
9722: =over 4
9723:
9724: =item $Title: string, the title of the plot
9725:
9726: =item $xlabel: string, text describing the X-axis of the plot
9727:
9728: =item $ylabel: string, text describing the Y-axis of the plot
9729:
9730: =item $colors: Array ref containing the hex color codes for the data to be
9731: plotted in. If undefined, default values will be used.
9732:
9733: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9734:
9735: =item $Ydata1: The first data set
9736:
9737: =item $Min1: The minimum value of the left Y-axis
9738:
9739: =item $Max1: The maximum value of the left Y-axis
9740:
9741: =item $Ydata2: The second data set
9742:
9743: =item $Min2: The minimum value of the right Y-axis
9744:
9745: =item $Max2: The maximum value of the left Y-axis
9746:
9747: =item %Values: hash indicating or overriding any default values which are
9748: passed to graph.png.
9749: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9750:
9751: =back
9752:
9753: Returns:
9754:
9755: An <img> tag which references graph.png and the appropriate identifying
9756: information for the plot.
1.136 matthew 9757:
9758: =cut
9759:
9760: ############################################################
9761: ############################################################
1.137 matthew 9762: sub DrawXYYGraph {
9763: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9764: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9765: #
9766: # Create the identifier for the graph
9767: my $identifier = &get_cgi_id();
9768: my $id = 'cgi.'.$identifier;
9769: #
9770: $Title = '' if (! defined($Title));
9771: $xlabel = '' if (! defined($xlabel));
9772: $ylabel = '' if (! defined($ylabel));
9773: my %ValuesHash =
9774: (
1.369 www 9775: $id.'.title' => &escape($Title),
9776: $id.'.xlabel' => &escape($xlabel),
9777: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9778: $id.'.labels' => join(',',@$Xlabels),
9779: $id.'.PlotType' => 'XY',
9780: $id.'.NumSets' => 2,
1.137 matthew 9781: $id.'.two_axes' => 1,
9782: $id.'.y1_max_value' => $Max1,
9783: $id.'.y1_min_value' => $Min1,
9784: $id.'.y2_max_value' => $Max2,
9785: $id.'.y2_min_value' => $Min2,
1.136 matthew 9786: );
9787: #
1.137 matthew 9788: if (defined($colors) && ref($colors) eq 'ARRAY') {
9789: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9790: }
9791: #
9792: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9793: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9794: return '';
9795: }
9796: my $NumSets=1;
1.137 matthew 9797: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9798: next if (! ref($array));
9799: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9800: }
9801: #
9802: # Deal with other parameters
9803: while (my ($key,$value) = each(%Values)) {
9804: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9805: }
9806: #
1.646 raeburn 9807: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9808: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9809: }
9810:
9811: ############################################################
9812: ############################################################
9813:
9814: =pod
9815:
1.157 matthew 9816: =back
9817:
1.139 matthew 9818: =head1 Statistics helper routines?
9819:
9820: Bad place for them but what the hell.
9821:
1.157 matthew 9822: =over 4
9823:
1.648 raeburn 9824: =item * &chartlink()
1.139 matthew 9825:
9826: Returns a link to the chart for a specific student.
9827:
9828: Inputs:
9829:
9830: =over 4
9831:
9832: =item $linktext: The text of the link
9833:
9834: =item $sname: The students username
9835:
9836: =item $sdomain: The students domain
9837:
9838: =back
9839:
1.157 matthew 9840: =back
9841:
1.139 matthew 9842: =cut
9843:
9844: ############################################################
9845: ############################################################
9846: sub chartlink {
9847: my ($linktext, $sname, $sdomain) = @_;
9848: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9849: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9850: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9851: '">'.$linktext.'</a>';
1.153 matthew 9852: }
9853:
9854: #######################################################
9855: #######################################################
9856:
9857: =pod
9858:
9859: =head1 Course Environment Routines
1.157 matthew 9860:
9861: =over 4
1.153 matthew 9862:
1.648 raeburn 9863: =item * &restore_course_settings()
1.153 matthew 9864:
1.648 raeburn 9865: =item * &store_course_settings()
1.153 matthew 9866:
9867: Restores/Store indicated form parameters from the course environment.
9868: Will not overwrite existing values of the form parameters.
9869:
9870: Inputs:
9871: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9872:
9873: a hash ref describing the data to be stored. For example:
9874:
9875: %Save_Parameters = ('Status' => 'scalar',
9876: 'chartoutputmode' => 'scalar',
9877: 'chartoutputdata' => 'scalar',
9878: 'Section' => 'array',
1.373 raeburn 9879: 'Group' => 'array',
1.153 matthew 9880: 'StudentData' => 'array',
9881: 'Maps' => 'array');
9882:
9883: Returns: both routines return nothing
9884:
1.631 raeburn 9885: =back
9886:
1.153 matthew 9887: =cut
9888:
9889: #######################################################
9890: #######################################################
9891: sub store_course_settings {
1.496 albertel 9892: return &store_settings($env{'request.course.id'},@_);
9893: }
9894:
9895: sub store_settings {
1.153 matthew 9896: # save to the environment
9897: # appenv the same items, just to be safe
1.300 albertel 9898: my $udom = $env{'user.domain'};
9899: my $uname = $env{'user.name'};
1.496 albertel 9900: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9901: my %SaveHash;
9902: my %AppHash;
9903: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9904: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9905: my $envname = 'environment.'.$basename;
1.258 albertel 9906: if (exists($env{'form.'.$setting})) {
1.153 matthew 9907: # Save this value away
9908: if ($type eq 'scalar' &&
1.258 albertel 9909: (! exists($env{$envname}) ||
9910: $env{$envname} ne $env{'form.'.$setting})) {
9911: $SaveHash{$basename} = $env{'form.'.$setting};
9912: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9913: } elsif ($type eq 'array') {
9914: my $stored_form;
1.258 albertel 9915: if (ref($env{'form.'.$setting})) {
1.153 matthew 9916: $stored_form = join(',',
9917: map {
1.369 www 9918: &escape($_);
1.258 albertel 9919: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9920: } else {
9921: $stored_form =
1.369 www 9922: &escape($env{'form.'.$setting});
1.153 matthew 9923: }
9924: # Determine if the array contents are the same.
1.258 albertel 9925: if ($stored_form ne $env{$envname}) {
1.153 matthew 9926: $SaveHash{$basename} = $stored_form;
9927: $AppHash{$envname} = $stored_form;
9928: }
9929: }
9930: }
9931: }
9932: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9933: $udom,$uname);
1.153 matthew 9934: if ($put_result !~ /^(ok|delayed)/) {
9935: &Apache::lonnet::logthis('unable to save form parameters, '.
9936: 'got error:'.$put_result);
9937: }
9938: # Make sure these settings stick around in this session, too
1.646 raeburn 9939: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9940: return;
9941: }
9942:
9943: sub restore_course_settings {
1.499 albertel 9944: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9945: }
9946:
9947: sub restore_settings {
9948: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9949: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9950: next if (exists($env{'form.'.$setting}));
1.496 albertel 9951: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9952: '.'.$setting;
1.258 albertel 9953: if (exists($env{$envname})) {
1.153 matthew 9954: if ($type eq 'scalar') {
1.258 albertel 9955: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9956: } elsif ($type eq 'array') {
1.258 albertel 9957: $env{'form.'.$setting} = [
1.153 matthew 9958: map {
1.369 www 9959: &unescape($_);
1.258 albertel 9960: } split(',',$env{$envname})
1.153 matthew 9961: ];
9962: }
9963: }
9964: }
1.127 matthew 9965: }
9966:
1.618 raeburn 9967: #######################################################
9968: #######################################################
9969:
9970: =pod
9971:
9972: =head1 Domain E-mail Routines
9973:
9974: =over 4
9975:
1.648 raeburn 9976: =item * &build_recipient_list()
1.618 raeburn 9977:
1.884 raeburn 9978: Build recipient lists for five types of e-mail:
1.766 raeburn 9979: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9980: (d) Help requests, (e) Course requests needing approval, generated by
9981: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9982: loncoursequeueadmin.pm respectively.
1.618 raeburn 9983:
9984: Inputs:
1.619 raeburn 9985: defmail (scalar - email address of default recipient),
1.618 raeburn 9986: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9987: defdom (domain for which to retrieve configuration settings),
9988: origmail (scalar - email address of recipient from loncapa.conf,
9989: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9990:
1.655 raeburn 9991: Returns: comma separated list of addresses to which to send e-mail.
9992:
9993: =back
1.618 raeburn 9994:
9995: =cut
9996:
9997: ############################################################
9998: ############################################################
9999: sub build_recipient_list {
1.619 raeburn 10000: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 10001: my @recipients;
10002: my $otheremails;
10003: my %domconfig =
10004: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
10005: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 10006: if (exists($domconfig{'contacts'}{$mailing})) {
10007: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
10008: my @contacts = ('adminemail','supportemail');
10009: foreach my $item (@contacts) {
10010: if ($domconfig{'contacts'}{$mailing}{$item}) {
10011: my $addr = $domconfig{'contacts'}{$item};
10012: if (!grep(/^\Q$addr\E$/,@recipients)) {
10013: push(@recipients,$addr);
10014: }
1.619 raeburn 10015: }
1.766 raeburn 10016: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 10017: }
10018: }
1.766 raeburn 10019: } elsif ($origmail ne '') {
10020: push(@recipients,$origmail);
1.618 raeburn 10021: }
1.619 raeburn 10022: } elsif ($origmail ne '') {
10023: push(@recipients,$origmail);
1.618 raeburn 10024: }
1.688 raeburn 10025: if (defined($defmail)) {
10026: if ($defmail ne '') {
10027: push(@recipients,$defmail);
10028: }
1.618 raeburn 10029: }
10030: if ($otheremails) {
1.619 raeburn 10031: my @others;
10032: if ($otheremails =~ /,/) {
10033: @others = split(/,/,$otheremails);
1.618 raeburn 10034: } else {
1.619 raeburn 10035: push(@others,$otheremails);
10036: }
10037: foreach my $addr (@others) {
10038: if (!grep(/^\Q$addr\E$/,@recipients)) {
10039: push(@recipients,$addr);
10040: }
1.618 raeburn 10041: }
10042: }
1.619 raeburn 10043: my $recipientlist = join(',',@recipients);
1.618 raeburn 10044: return $recipientlist;
10045: }
10046:
1.127 matthew 10047: ############################################################
10048: ############################################################
1.154 albertel 10049:
1.655 raeburn 10050: =pod
10051:
10052: =head1 Course Catalog Routines
10053:
10054: =over 4
10055:
10056: =item * &gather_categories()
10057:
10058: Converts category definitions - keys of categories hash stored in
10059: coursecategories in configuration.db on the primary library server in a
10060: domain - to an array. Also generates javascript and idx hash used to
10061: generate Domain Coordinator interface for editing Course Categories.
10062:
10063: Inputs:
1.663 raeburn 10064:
1.655 raeburn 10065: categories (reference to hash of category definitions).
1.663 raeburn 10066:
1.655 raeburn 10067: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10068: categories and subcategories).
1.663 raeburn 10069:
1.655 raeburn 10070: idx (reference to hash of counters used in Domain Coordinator interface for
10071: editing Course Categories).
1.663 raeburn 10072:
1.655 raeburn 10073: jsarray (reference to array of categories used to create Javascript arrays for
10074: Domain Coordinator interface for editing Course Categories).
10075:
10076: Returns: nothing
10077:
10078: Side effects: populates cats, idx and jsarray.
10079:
10080: =cut
10081:
10082: sub gather_categories {
10083: my ($categories,$cats,$idx,$jsarray) = @_;
10084: my %counters;
10085: my $num = 0;
10086: foreach my $item (keys(%{$categories})) {
10087: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10088: if ($container eq '' && $depth == 0) {
10089: $cats->[$depth][$categories->{$item}] = $cat;
10090: } else {
10091: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
10092: }
10093: my ($escitem,$tail) = split(/:/,$item,2);
10094: if ($counters{$tail} eq '') {
10095: $counters{$tail} = $num;
10096: $num ++;
10097: }
10098: if (ref($idx) eq 'HASH') {
10099: $idx->{$item} = $counters{$tail};
10100: }
10101: if (ref($jsarray) eq 'ARRAY') {
10102: push(@{$jsarray->[$counters{$tail}]},$item);
10103: }
10104: }
10105: return;
10106: }
10107:
10108: =pod
10109:
10110: =item * &extract_categories()
10111:
10112: Used to generate breadcrumb trails for course categories.
10113:
10114: Inputs:
1.663 raeburn 10115:
1.655 raeburn 10116: categories (reference to hash of category definitions).
1.663 raeburn 10117:
1.655 raeburn 10118: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10119: categories and subcategories).
1.663 raeburn 10120:
1.655 raeburn 10121: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 10122:
1.655 raeburn 10123: allitems (reference to hash - key is category key
10124: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10125:
1.655 raeburn 10126: idx (reference to hash of counters used in Domain Coordinator interface for
10127: editing Course Categories).
1.663 raeburn 10128:
1.655 raeburn 10129: jsarray (reference to array of categories used to create Javascript arrays for
10130: Domain Coordinator interface for editing Course Categories).
10131:
1.665 raeburn 10132: subcats (reference to hash of arrays containing all subcategories within each
10133: category, -recursive)
10134:
1.655 raeburn 10135: Returns: nothing
10136:
10137: Side effects: populates trails and allitems hash references.
10138:
10139: =cut
10140:
10141: sub extract_categories {
1.665 raeburn 10142: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 10143: if (ref($categories) eq 'HASH') {
10144: &gather_categories($categories,$cats,$idx,$jsarray);
10145: if (ref($cats->[0]) eq 'ARRAY') {
10146: for (my $i=0; $i<@{$cats->[0]}; $i++) {
10147: my $name = $cats->[0][$i];
10148: my $item = &escape($name).'::0';
10149: my $trailstr;
10150: if ($name eq 'instcode') {
10151: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 10152: } elsif ($name eq 'communities') {
10153: $trailstr = &mt('Communities');
1.655 raeburn 10154: } else {
10155: $trailstr = $name;
10156: }
10157: if ($allitems->{$item} eq '') {
10158: push(@{$trails},$trailstr);
10159: $allitems->{$item} = scalar(@{$trails})-1;
10160: }
10161: my @parents = ($name);
10162: if (ref($cats->[1]{$name}) eq 'ARRAY') {
10163: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
10164: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 10165: if (ref($subcats) eq 'HASH') {
10166: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
10167: }
10168: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
10169: }
10170: } else {
10171: if (ref($subcats) eq 'HASH') {
10172: $subcats->{$item} = [];
1.655 raeburn 10173: }
10174: }
10175: }
10176: }
10177: }
10178: return;
10179: }
10180:
10181: =pod
10182:
10183: =item *&recurse_categories()
10184:
10185: Recursively used to generate breadcrumb trails for course categories.
10186:
10187: Inputs:
1.663 raeburn 10188:
1.655 raeburn 10189: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10190: categories and subcategories).
1.663 raeburn 10191:
1.655 raeburn 10192: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 10193:
10194: category (current course category, for which breadcrumb trail is being generated).
10195:
10196: trails (reference to array of breadcrumb trails for each category).
10197:
1.655 raeburn 10198: allitems (reference to hash - key is category key
10199: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10200:
1.655 raeburn 10201: parents (array containing containers directories for current category,
10202: back to top level).
10203:
10204: Returns: nothing
10205:
10206: Side effects: populates trails and allitems hash references
10207:
10208: =cut
10209:
10210: sub recurse_categories {
1.665 raeburn 10211: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 10212: my $shallower = $depth - 1;
10213: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
10214: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
10215: my $name = $cats->[$depth]{$category}[$k];
10216: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10217: my $trailstr = join(' -> ',(@{$parents},$category));
10218: if ($allitems->{$item} eq '') {
10219: push(@{$trails},$trailstr);
10220: $allitems->{$item} = scalar(@{$trails})-1;
10221: }
10222: my $deeper = $depth+1;
10223: push(@{$parents},$category);
1.665 raeburn 10224: if (ref($subcats) eq 'HASH') {
10225: my $subcat = &escape($name).':'.$category.':'.$depth;
10226: for (my $j=@{$parents}; $j>=0; $j--) {
10227: my $higher;
10228: if ($j > 0) {
10229: $higher = &escape($parents->[$j]).':'.
10230: &escape($parents->[$j-1]).':'.$j;
10231: } else {
10232: $higher = &escape($parents->[$j]).'::'.$j;
10233: }
10234: push(@{$subcats->{$higher}},$subcat);
10235: }
10236: }
10237: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
10238: $subcats);
1.655 raeburn 10239: pop(@{$parents});
10240: }
10241: } else {
10242: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10243: my $trailstr = join(' -> ',(@{$parents},$category));
10244: if ($allitems->{$item} eq '') {
10245: push(@{$trails},$trailstr);
10246: $allitems->{$item} = scalar(@{$trails})-1;
10247: }
10248: }
10249: return;
10250: }
10251:
1.663 raeburn 10252: =pod
10253:
10254: =item *&assign_categories_table()
10255:
10256: Create a datatable for display of hierarchical categories in a domain,
10257: with checkboxes to allow a course to be categorized.
10258:
10259: Inputs:
10260:
10261: cathash - reference to hash of categories defined for the domain (from
10262: configuration.db)
10263:
10264: currcat - scalar with an & separated list of categories assigned to a course.
10265:
1.919 raeburn 10266: type - scalar contains course type (Course or Community).
10267:
1.663 raeburn 10268: Returns: $output (markup to be displayed)
10269:
10270: =cut
10271:
10272: sub assign_categories_table {
1.919 raeburn 10273: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 10274: my $output;
10275: if (ref($cathash) eq 'HASH') {
10276: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
10277: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
10278: $maxdepth = scalar(@cats);
10279: if (@cats > 0) {
10280: my $itemcount = 0;
10281: if (ref($cats[0]) eq 'ARRAY') {
10282: my @currcategories;
10283: if ($currcat ne '') {
10284: @currcategories = split('&',$currcat);
10285: }
1.919 raeburn 10286: my $table;
1.663 raeburn 10287: for (my $i=0; $i<@{$cats[0]}; $i++) {
10288: my $parent = $cats[0][$i];
1.919 raeburn 10289: next if ($parent eq 'instcode');
10290: if ($type eq 'Community') {
10291: next unless ($parent eq 'communities');
10292: } else {
10293: next if ($parent eq 'communities');
10294: }
1.663 raeburn 10295: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10296: my $item = &escape($parent).'::0';
10297: my $checked = '';
10298: if (@currcategories > 0) {
10299: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 10300: $checked = ' checked="checked"';
1.663 raeburn 10301: }
10302: }
1.919 raeburn 10303: my $parent_title = $parent;
10304: if ($parent eq 'communities') {
10305: $parent_title = &mt('Communities');
10306: }
10307: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
10308: '<input type="checkbox" name="usecategory" value="'.
10309: $item.'"'.$checked.' />'.$parent_title.'</span>'.
10310: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 10311: my $depth = 1;
10312: push(@path,$parent);
1.919 raeburn 10313: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 10314: pop(@path);
1.919 raeburn 10315: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 10316: $itemcount ++;
10317: }
1.919 raeburn 10318: if ($itemcount) {
10319: $output = &Apache::loncommon::start_data_table().
10320: $table.
10321: &Apache::loncommon::end_data_table();
10322: }
1.663 raeburn 10323: }
10324: }
10325: }
10326: return $output;
10327: }
10328:
10329: =pod
10330:
10331: =item *&assign_category_rows()
10332:
10333: Create a datatable row for display of nested categories in a domain,
10334: with checkboxes to allow a course to be categorized,called recursively.
10335:
10336: Inputs:
10337:
10338: itemcount - track row number for alternating colors
10339:
10340: cats - reference to array of arrays/hashes which encapsulates hierarchy of
10341: categories and subcategories.
10342:
10343: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
10344:
10345: parent - parent of current category item
10346:
10347: path - Array containing all categories back up through the hierarchy from the
10348: current category to the top level.
10349:
10350: currcategories - reference to array of current categories assigned to the course
10351:
10352: Returns: $output (markup to be displayed).
10353:
10354: =cut
10355:
10356: sub assign_category_rows {
10357: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
10358: my ($text,$name,$item,$chgstr);
10359: if (ref($cats) eq 'ARRAY') {
10360: my $maxdepth = scalar(@{$cats});
10361: if (ref($cats->[$depth]) eq 'HASH') {
10362: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10363: my $numchildren = @{$cats->[$depth]{$parent}};
10364: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10365: $text .= '<td><table class="LC_datatable">';
10366: for (my $j=0; $j<$numchildren; $j++) {
10367: $name = $cats->[$depth]{$parent}[$j];
10368: $item = &escape($name).':'.&escape($parent).':'.$depth;
10369: my $deeper = $depth+1;
10370: my $checked = '';
10371: if (ref($currcategories) eq 'ARRAY') {
10372: if (@{$currcategories} > 0) {
10373: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 10374: $checked = ' checked="checked"';
1.663 raeburn 10375: }
10376: }
10377: }
1.664 raeburn 10378: $text .= '<tr><td><span class="LC_nobreak"><label>'.
10379: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 10380: $item.'"'.$checked.' />'.$name.'</label></span>'.
10381: '<input type="hidden" name="catname" value="'.$name.'" />'.
10382: '</td><td>';
1.663 raeburn 10383: if (ref($path) eq 'ARRAY') {
10384: push(@{$path},$name);
10385: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10386: pop(@{$path});
10387: }
10388: $text .= '</td></tr>';
10389: }
10390: $text .= '</table></td>';
10391: }
10392: }
10393: }
10394: return $text;
10395: }
10396:
1.655 raeburn 10397: ############################################################
10398: ############################################################
10399:
10400:
1.443 albertel 10401: sub commit_customrole {
1.664 raeburn 10402: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10403: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10404: ($start?', '.&mt('starting').' '.localtime($start):'').
10405: ($end?', ending '.localtime($end):'').': <b>'.
10406: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10407: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10408: '</b><br />';
10409: return $output;
10410: }
10411:
10412: sub commit_standardrole {
1.541 raeburn 10413: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10414: my ($output,$logmsg,$linefeed);
10415: if ($context eq 'auto') {
10416: $linefeed = "\n";
10417: } else {
10418: $linefeed = "<br />\n";
10419: }
1.443 albertel 10420: if ($three eq 'st') {
1.541 raeburn 10421: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10422: $one,$two,$sec,$context);
10423: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10424: ($result eq 'unknown_course') || ($result eq 'refused')) {
10425: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10426: } else {
1.541 raeburn 10427: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10428: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10429: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10430: if ($context eq 'auto') {
10431: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10432: } else {
10433: $output .= '<b>'.$result.'</b>'.$linefeed.
10434: &mt('Add to classlist').': <b>ok</b>';
10435: }
10436: $output .= $linefeed;
1.443 albertel 10437: }
10438: } else {
10439: $output = &mt('Assigning').' '.$three.' in '.$url.
10440: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10441: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10442: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10443: if ($context eq 'auto') {
10444: $output .= $result.$linefeed;
10445: } else {
10446: $output .= '<b>'.$result.'</b>'.$linefeed;
10447: }
1.443 albertel 10448: }
10449: return $output;
10450: }
10451:
10452: sub commit_studentrole {
1.541 raeburn 10453: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10454: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10455: if ($context eq 'auto') {
10456: $linefeed = "\n";
10457: } else {
10458: $linefeed = '<br />'."\n";
10459: }
1.443 albertel 10460: if (defined($one) && defined($two)) {
10461: my $cid=$one.'_'.$two;
10462: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10463: my $secchange = 0;
10464: my $expire_role_result;
10465: my $modify_section_result;
1.628 raeburn 10466: if ($oldsec ne '-1') {
10467: if ($oldsec ne $sec) {
1.443 albertel 10468: $secchange = 1;
1.628 raeburn 10469: my $now = time;
1.443 albertel 10470: my $uurl='/'.$cid;
10471: $uurl=~s/\_/\//g;
10472: if ($oldsec) {
10473: $uurl.='/'.$oldsec;
10474: }
1.626 raeburn 10475: $oldsecurl = $uurl;
1.628 raeburn 10476: $expire_role_result =
1.652 raeburn 10477: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10478: if ($env{'request.course.sec'} ne '') {
10479: if ($expire_role_result eq 'refused') {
10480: my @roles = ('st');
10481: my @statuses = ('previous');
10482: my @roledoms = ($one);
10483: my $withsec = 1;
10484: my %roleshash =
10485: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10486: \@statuses,\@roles,\@roledoms,$withsec);
10487: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10488: my ($oldstart,$oldend) =
10489: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10490: if ($oldend > 0 && $oldend <= $now) {
10491: $expire_role_result = 'ok';
10492: }
10493: }
10494: }
10495: }
1.443 albertel 10496: $result = $expire_role_result;
10497: }
10498: }
10499: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10500: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10501: if ($modify_section_result =~ /^ok/) {
10502: if ($secchange == 1) {
1.628 raeburn 10503: if ($sec eq '') {
10504: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10505: } else {
10506: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10507: }
1.443 albertel 10508: } elsif ($oldsec eq '-1') {
1.628 raeburn 10509: if ($sec eq '') {
10510: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10511: } else {
10512: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10513: }
1.443 albertel 10514: } else {
1.628 raeburn 10515: if ($sec eq '') {
10516: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10517: } else {
10518: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10519: }
1.443 albertel 10520: }
10521: } else {
1.628 raeburn 10522: if ($secchange) {
10523: $$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;
10524: } else {
10525: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10526: }
1.443 albertel 10527: }
10528: $result = $modify_section_result;
10529: } elsif ($secchange == 1) {
1.628 raeburn 10530: if ($oldsec eq '') {
10531: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10532: } else {
10533: $$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;
10534: }
1.626 raeburn 10535: if ($expire_role_result eq 'refused') {
10536: my $newsecurl = '/'.$cid;
10537: $newsecurl =~ s/\_/\//g;
10538: if ($sec ne '') {
10539: $newsecurl.='/'.$sec;
10540: }
10541: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10542: if ($sec eq '') {
10543: $$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;
10544: } else {
10545: $$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;
10546: }
10547: }
10548: }
1.443 albertel 10549: }
10550: } else {
1.626 raeburn 10551: $$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 10552: $result = "error: incomplete course id\n";
10553: }
10554: return $result;
10555: }
10556:
10557: ############################################################
10558: ############################################################
10559:
1.566 albertel 10560: sub check_clone {
1.578 raeburn 10561: my ($args,$linefeed) = @_;
1.566 albertel 10562: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10563: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10564: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10565: my $clonemsg;
10566: my $can_clone = 0;
1.944 raeburn 10567: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10568: if ($lctype ne 'community') {
10569: $lctype = 'course';
10570: }
1.566 albertel 10571: if ($clonehome eq 'no_host') {
1.944 raeburn 10572: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10573: $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'});
10574: } else {
10575: $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'});
10576: }
1.566 albertel 10577: } else {
10578: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10579: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10580: if ($clonedesc{'type'} ne 'Community') {
10581: $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'});
10582: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10583: }
10584: }
1.882 raeburn 10585: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10586: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10587: $can_clone = 1;
10588: } else {
10589: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10590: $args->{'clonedomain'},$args->{'clonecourse'});
10591: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10592: if (grep(/^\*$/,@cloners)) {
10593: $can_clone = 1;
10594: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10595: $can_clone = 1;
10596: } else {
1.908 raeburn 10597: my $ccrole = 'cc';
1.944 raeburn 10598: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10599: $ccrole = 'co';
10600: }
1.578 raeburn 10601: my %roleshash =
10602: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10603: $args->{'ccdomain'},
1.908 raeburn 10604: 'userroles',['active'],[$ccrole],
1.578 raeburn 10605: [$args->{'clonedomain'}]);
1.908 raeburn 10606: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10607: $can_clone = 1;
10608: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10609: $can_clone = 1;
10610: } else {
1.944 raeburn 10611: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10612: $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'});
10613: } else {
10614: $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'});
10615: }
1.578 raeburn 10616: }
1.566 albertel 10617: }
1.578 raeburn 10618: }
1.566 albertel 10619: }
10620: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10621: }
10622:
1.444 albertel 10623: sub construct_course {
1.885 raeburn 10624: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10625: my $outcome;
1.541 raeburn 10626: my $linefeed = '<br />'."\n";
10627: if ($context eq 'auto') {
10628: $linefeed = "\n";
10629: }
1.566 albertel 10630:
10631: #
10632: # Are we cloning?
10633: #
10634: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10635: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10636: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10637: if ($context ne 'auto') {
1.578 raeburn 10638: if ($clonemsg ne '') {
10639: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10640: }
1.566 albertel 10641: }
10642: $outcome .= $clonemsg.$linefeed;
10643:
10644: if (!$can_clone) {
10645: return (0,$outcome);
10646: }
10647: }
10648:
1.444 albertel 10649: #
10650: # Open course
10651: #
10652: my $crstype = lc($args->{'crstype'});
10653: my %cenv=();
10654: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10655: $args->{'cdescr'},
10656: $args->{'curl'},
10657: $args->{'course_home'},
10658: $args->{'nonstandard'},
10659: $args->{'crscode'},
10660: $args->{'ccuname'}.':'.
10661: $args->{'ccdomain'},
1.882 raeburn 10662: $args->{'crstype'},
1.885 raeburn 10663: $cnum,$context,$category);
1.444 albertel 10664:
10665: # Note: The testing routines depend on this being output; see
10666: # Utils::Course. This needs to at least be output as a comment
10667: # if anyone ever decides to not show this, and Utils::Course::new
10668: # will need to be suitably modified.
1.541 raeburn 10669: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10670: if ($$courseid =~ /^error:/) {
10671: return (0,$outcome);
10672: }
10673:
1.444 albertel 10674: #
10675: # Check if created correctly
10676: #
1.479 albertel 10677: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10678: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10679: if ($crsuhome eq 'no_host') {
10680: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10681: return (0,$outcome);
10682: }
1.541 raeburn 10683: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10684:
1.444 albertel 10685: #
1.566 albertel 10686: # Do the cloning
10687: #
10688: if ($can_clone && $cloneid) {
10689: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10690: if ($context ne 'auto') {
10691: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10692: }
10693: $outcome .= $clonemsg.$linefeed;
10694: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10695: # Copy all files
1.637 www 10696: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10697: # Restore URL
1.566 albertel 10698: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10699: # Restore title
1.566 albertel 10700: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 10701: # Restore creation date, creator and creation context.
10702: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10703: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10704: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10705: # Mark as cloned
1.566 albertel 10706: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10707: # Need to clone grading mode
10708: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10709: $cenv{'grading'}=$newenv{'grading'};
10710: # Do not clone these environment entries
10711: &Apache::lonnet::del('environment',
10712: ['default_enrollment_start_date',
10713: 'default_enrollment_end_date',
10714: 'question.email',
10715: 'policy.email',
10716: 'comment.email',
10717: 'pch.users.denied',
1.725 raeburn 10718: 'plc.users.denied',
10719: 'hidefromcat',
10720: 'categories'],
1.638 www 10721: $$crsudom,$$crsunum);
1.444 albertel 10722: }
1.566 albertel 10723:
1.444 albertel 10724: #
10725: # Set environment (will override cloned, if existing)
10726: #
10727: my @sections = ();
10728: my @xlists = ();
10729: if ($args->{'crstype'}) {
10730: $cenv{'type'}=$args->{'crstype'};
10731: }
10732: if ($args->{'crsid'}) {
10733: $cenv{'courseid'}=$args->{'crsid'};
10734: }
10735: if ($args->{'crscode'}) {
10736: $cenv{'internal.coursecode'}=$args->{'crscode'};
10737: }
10738: if ($args->{'crsquota'} ne '') {
10739: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10740: } else {
10741: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10742: }
10743: if ($args->{'ccuname'}) {
10744: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10745: ':'.$args->{'ccdomain'};
10746: } else {
10747: $cenv{'internal.courseowner'} = $args->{'curruser'};
10748: }
10749: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10750: if ($args->{'crssections'}) {
10751: $cenv{'internal.sectionnums'} = '';
10752: if ($args->{'crssections'} =~ m/,/) {
10753: @sections = split/,/,$args->{'crssections'};
10754: } else {
10755: $sections[0] = $args->{'crssections'};
10756: }
10757: if (@sections > 0) {
10758: foreach my $item (@sections) {
10759: my ($sec,$gp) = split/:/,$item;
10760: my $class = $args->{'crscode'}.$sec;
10761: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10762: $cenv{'internal.sectionnums'} .= $item.',';
10763: unless ($addcheck eq 'ok') {
10764: push @badclasses, $class;
10765: }
10766: }
10767: $cenv{'internal.sectionnums'} =~ s/,$//;
10768: }
10769: }
10770: # do not hide course coordinator from staff listing,
10771: # even if privileged
10772: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10773: # add crosslistings
10774: if ($args->{'crsxlist'}) {
10775: $cenv{'internal.crosslistings'}='';
10776: if ($args->{'crsxlist'} =~ m/,/) {
10777: @xlists = split/,/,$args->{'crsxlist'};
10778: } else {
10779: $xlists[0] = $args->{'crsxlist'};
10780: }
10781: if (@xlists > 0) {
10782: foreach my $item (@xlists) {
10783: my ($xl,$gp) = split/:/,$item;
10784: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10785: $cenv{'internal.crosslistings'} .= $item.',';
10786: unless ($addcheck eq 'ok') {
10787: push @badclasses, $xl;
10788: }
10789: }
10790: $cenv{'internal.crosslistings'} =~ s/,$//;
10791: }
10792: }
10793: if ($args->{'autoadds'}) {
10794: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10795: }
10796: if ($args->{'autodrops'}) {
10797: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10798: }
10799: # check for notification of enrollment changes
10800: my @notified = ();
10801: if ($args->{'notify_owner'}) {
10802: if ($args->{'ccuname'} ne '') {
10803: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10804: }
10805: }
10806: if ($args->{'notify_dc'}) {
10807: if ($uname ne '') {
1.630 raeburn 10808: push(@notified,$uname.':'.$udom);
1.444 albertel 10809: }
10810: }
10811: if (@notified > 0) {
10812: my $notifylist;
10813: if (@notified > 1) {
10814: $notifylist = join(',',@notified);
10815: } else {
10816: $notifylist = $notified[0];
10817: }
10818: $cenv{'internal.notifylist'} = $notifylist;
10819: }
10820: if (@badclasses > 0) {
10821: my %lt=&Apache::lonlocal::texthash(
10822: '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',
10823: 'dnhr' => 'does not have rights to access enrollment in these classes',
10824: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10825: );
1.541 raeburn 10826: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10827: ' ('.$lt{'adby'}.')';
10828: if ($context eq 'auto') {
10829: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10830: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10831: foreach my $item (@badclasses) {
10832: if ($context eq 'auto') {
10833: $outcome .= " - $item\n";
10834: } else {
10835: $outcome .= "<li>$item</li>\n";
10836: }
10837: }
10838: if ($context eq 'auto') {
10839: $outcome .= $linefeed;
10840: } else {
1.566 albertel 10841: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10842: }
10843: }
1.444 albertel 10844: }
10845: if ($args->{'no_end_date'}) {
10846: $args->{'endaccess'} = 0;
10847: }
10848: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10849: $cenv{'internal.autoend'}=$args->{'enrollend'};
10850: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10851: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10852: if ($args->{'showphotos'}) {
10853: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10854: }
10855: $cenv{'internal.authtype'} = $args->{'authtype'};
10856: $cenv{'internal.autharg'} = $args->{'autharg'};
10857: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10858: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10859: 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');
10860: if ($context eq 'auto') {
10861: $outcome .= $krb_msg;
10862: } else {
1.566 albertel 10863: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10864: }
10865: $outcome .= $linefeed;
1.444 albertel 10866: }
10867: }
10868: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10869: if ($args->{'setpolicy'}) {
10870: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10871: }
10872: if ($args->{'setcontent'}) {
10873: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10874: }
10875: }
10876: if ($args->{'reshome'}) {
10877: $cenv{'reshome'}=$args->{'reshome'}.'/';
10878: $cenv{'reshome'}=~s/\/+$/\//;
10879: }
10880: #
10881: # course has keyed access
10882: #
10883: if ($args->{'setkeys'}) {
10884: $cenv{'keyaccess'}='yes';
10885: }
10886: # if specified, key authority is not course, but user
10887: # only active if keyaccess is yes
10888: if ($args->{'keyauth'}) {
1.487 albertel 10889: my ($user,$domain) = split(':',$args->{'keyauth'});
10890: $user = &LONCAPA::clean_username($user);
10891: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10892: if ($user ne '' && $domain ne '') {
1.487 albertel 10893: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10894: }
10895: }
10896:
10897: if ($args->{'disresdis'}) {
10898: $cenv{'pch.roles.denied'}='st';
10899: }
10900: if ($args->{'disablechat'}) {
10901: $cenv{'plc.roles.denied'}='st';
10902: }
10903:
10904: # Record we've not yet viewed the Course Initialization Helper for this
10905: # course
10906: $cenv{'course.helper.not.run'} = 1;
10907: #
10908: # Use new Randomseed
10909: #
10910: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10911: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10912: #
10913: # The encryption code and receipt prefix for this course
10914: #
10915: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10916: $cenv{'internal.encpref'}=100+int(9*rand(99));
10917: #
10918: # By default, use standard grading
10919: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10920:
1.541 raeburn 10921: $outcome .= $linefeed.&mt('Setting environment').': '.
10922: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10923: #
10924: # Open all assignments
10925: #
10926: if ($args->{'openall'}) {
10927: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10928: my %storecontent = ($storeunder => time,
10929: $storeunder.'.type' => 'date_start');
10930:
10931: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10932: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10933: }
10934: #
10935: # Set first page
10936: #
10937: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10938: || ($cloneid)) {
1.445 albertel 10939: use LONCAPA::map;
1.444 albertel 10940: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10941:
10942: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10943: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10944:
1.444 albertel 10945: $outcome .= ($fatal?$errtext:'read ok').' - ';
10946: my $title; my $url;
10947: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10948: $title=&mt('Syllabus');
1.444 albertel 10949: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10950: } else {
1.963 raeburn 10951: $title=&mt('Table of Contents');
1.444 albertel 10952: $url='/adm/navmaps';
10953: }
1.445 albertel 10954:
10955: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10956: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10957:
10958: if ($errtext) { $fatal=2; }
1.541 raeburn 10959: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10960: }
1.566 albertel 10961:
10962: return (1,$outcome);
1.444 albertel 10963: }
10964:
10965: ############################################################
10966: ############################################################
10967:
1.953 droeschl 10968: #SD
10969: # only Community and Course, or anything else?
1.378 raeburn 10970: sub course_type {
10971: my ($cid) = @_;
10972: if (!defined($cid)) {
10973: $cid = $env{'request.course.id'};
10974: }
1.404 albertel 10975: if (defined($env{'course.'.$cid.'.type'})) {
10976: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10977: } else {
10978: return 'Course';
1.377 raeburn 10979: }
10980: }
1.156 albertel 10981:
1.406 raeburn 10982: sub group_term {
10983: my $crstype = &course_type();
10984: my %names = (
10985: 'Course' => 'group',
1.865 raeburn 10986: 'Community' => 'group',
1.406 raeburn 10987: );
10988: return $names{$crstype};
10989: }
10990:
1.902 raeburn 10991: sub course_types {
10992: my @types = ('official','unofficial','community');
10993: my %typename = (
10994: official => 'Official course',
10995: unofficial => 'Unofficial course',
10996: community => 'Community',
10997: );
10998: return (\@types,\%typename);
10999: }
11000:
1.156 albertel 11001: sub icon {
11002: my ($file)=@_;
1.505 albertel 11003: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 11004: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 11005: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 11006: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
11007: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
11008: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11009: $curfext.".gif") {
11010: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11011: $curfext.".gif";
11012: }
11013: }
1.249 albertel 11014: return &lonhttpdurl($iconname);
1.154 albertel 11015: }
1.84 albertel 11016:
1.575 albertel 11017: sub lonhttpdurl {
1.692 www 11018: #
11019: # Had been used for "small fry" static images on separate port 8080.
11020: # Modify here if lightweight http functionality desired again.
11021: # Currently eliminated due to increasing firewall issues.
11022: #
1.575 albertel 11023: my ($url)=@_;
1.692 www 11024: return $url;
1.215 albertel 11025: }
11026:
1.213 albertel 11027: sub connection_aborted {
11028: my ($r)=@_;
11029: $r->print(" ");$r->rflush();
11030: my $c = $r->connection;
11031: return $c->aborted();
11032: }
11033:
1.221 foxr 11034: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 11035: # strings as 'strings'.
11036: sub escape_single {
1.221 foxr 11037: my ($input) = @_;
1.223 albertel 11038: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 11039: $input =~ s/\'/\\\'/g; # Esacpe the 's....
11040: return $input;
11041: }
1.223 albertel 11042:
1.222 foxr 11043: # Same as escape_single, but escape's "'s This
11044: # can be used for "strings"
11045: sub escape_double {
11046: my ($input) = @_;
11047: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
11048: $input =~ s/\"/\\\"/g; # Esacpe the "s....
11049: return $input;
11050: }
1.223 albertel 11051:
1.222 foxr 11052: # Escapes the last element of a full URL.
11053: sub escape_url {
11054: my ($url) = @_;
1.238 raeburn 11055: my @urlslices = split(/\//, $url,-1);
1.369 www 11056: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 11057: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 11058: }
1.462 albertel 11059:
1.820 raeburn 11060: sub compare_arrays {
11061: my ($arrayref1,$arrayref2) = @_;
11062: my (@difference,%count);
11063: @difference = ();
11064: %count = ();
11065: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
11066: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
11067: foreach my $element (keys(%count)) {
11068: if ($count{$element} == 1) {
11069: push(@difference,$element);
11070: }
11071: }
11072: }
11073: return @difference;
11074: }
11075:
1.817 bisitz 11076: # -------------------------------------------------------- Initialize user login
1.462 albertel 11077: sub init_user_environment {
1.463 albertel 11078: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 11079: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
11080:
11081: my $public=($username eq 'public' && $domain eq 'public');
11082:
11083: # See if old ID present, if so, remove
11084:
11085: my ($filename,$cookie,$userroles);
11086: my $now=time;
11087:
11088: if ($public) {
11089: my $max_public=100;
11090: my $oldest;
11091: my $oldest_time=0;
11092: for(my $next=1;$next<=$max_public;$next++) {
11093: if (-e $lonids."/publicuser_$next.id") {
11094: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
11095: if ($mtime<$oldest_time || !$oldest_time) {
11096: $oldest_time=$mtime;
11097: $oldest=$next;
11098: }
11099: } else {
11100: $cookie="publicuser_$next";
11101: last;
11102: }
11103: }
11104: if (!$cookie) { $cookie="publicuser_$oldest"; }
11105: } else {
1.463 albertel 11106: # if this isn't a robot, kill any existing non-robot sessions
11107: if (!$args->{'robot'}) {
11108: opendir(DIR,$lonids);
11109: while ($filename=readdir(DIR)) {
11110: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
11111: unlink($lonids.'/'.$filename);
11112: }
1.462 albertel 11113: }
1.463 albertel 11114: closedir(DIR);
1.462 albertel 11115: }
11116: # Give them a new cookie
1.463 albertel 11117: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 11118: : $now.$$.int(rand(10000)));
1.463 albertel 11119: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 11120:
11121: # Initialize roles
11122:
11123: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
11124: }
11125: # ------------------------------------ Check browser type and MathML capability
11126:
11127: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
11128: $clientunicode,$clientos) = &decode_user_agent($r);
11129:
11130: # ------------------------------------------------------------- Get environment
11131:
11132: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
11133: my ($tmp) = keys(%userenv);
11134: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11135: } else {
11136: undef(%userenv);
11137: }
11138: if (($userenv{'interface'}) && (!$form->{'interface'})) {
11139: $form->{'interface'}=$userenv{'interface'};
11140: }
11141: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
11142:
11143: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 11144: foreach my $option ('interface','localpath','localres') {
11145: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 11146: }
11147: # --------------------------------------------------------- Write first profile
11148:
11149: {
11150: my %initial_env =
11151: ("user.name" => $username,
11152: "user.domain" => $domain,
11153: "user.home" => $authhost,
11154: "browser.type" => $clientbrowser,
11155: "browser.version" => $clientversion,
11156: "browser.mathml" => $clientmathml,
11157: "browser.unicode" => $clientunicode,
11158: "browser.os" => $clientos,
11159: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
11160: "request.course.fn" => '',
11161: "request.course.uri" => '',
11162: "request.course.sec" => '',
11163: "request.role" => 'cm',
11164: "request.role.adv" => $env{'user.adv'},
11165: "request.host" => $ENV{'REMOTE_ADDR'},);
11166:
11167: if ($form->{'localpath'}) {
11168: $initial_env{"browser.localpath"} = $form->{'localpath'};
11169: $initial_env{"browser.localres"} = $form->{'localres'};
11170: }
11171:
11172: if ($form->{'interface'}) {
11173: $form->{'interface'}=~s/\W//gs;
11174: $initial_env{"browser.interface"} = $form->{'interface'};
11175: $env{'browser.interface'}=$form->{'interface'};
11176: }
11177:
1.981 raeburn 11178: my %is_adv = ( is_adv => $env{'user.adv'} );
1.980 raeburn 11179: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
11180:
1.724 raeburn 11181: foreach my $tool ('aboutme','blog','portfolio') {
11182: $userenv{'availabletools.'.$tool} =
1.980 raeburn 11183: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
11184: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 11185: }
11186:
1.864 raeburn 11187: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 11188: $userenv{'canrequest.'.$crstype} =
11189: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 11190: 'reload','requestcourses',
11191: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 11192: }
11193:
1.462 albertel 11194: $env{'user.environment'} = "$lonids/$cookie.id";
11195:
11196: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
11197: &GDBM_WRCREAT(),0640)) {
11198: &_add_to_env(\%disk_env,\%initial_env);
11199: &_add_to_env(\%disk_env,\%userenv,'environment.');
11200: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 11201: if (ref($args->{'extra_env'})) {
11202: &_add_to_env(\%disk_env,$args->{'extra_env'});
11203: }
1.462 albertel 11204: untie(%disk_env);
11205: } else {
1.705 tempelho 11206: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
11207: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 11208: return 'error: '.$!;
11209: }
11210: }
11211: $env{'request.role'}='cm';
11212: $env{'request.role.adv'}=$env{'user.adv'};
11213: $env{'browser.type'}=$clientbrowser;
11214:
11215: return $cookie;
11216:
11217: }
11218:
11219: sub _add_to_env {
11220: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 11221: if (ref($env_data) eq 'HASH') {
11222: while (my ($key,$value) = each(%$env_data)) {
11223: $idf->{$prefix.$key} = $value;
11224: $env{$prefix.$key} = $value;
11225: }
1.462 albertel 11226: }
11227: }
11228:
1.685 tempelho 11229: # --- Get the symbolic name of a problem and the url
11230: sub get_symb {
11231: my ($request,$silent) = @_;
1.726 raeburn 11232: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 11233: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
11234: if ($symb eq '') {
11235: if (!$silent) {
11236: $request->print("Unable to handle ambiguous references:$url:.");
11237: return ();
11238: }
11239: }
11240: &Apache::lonenc::check_decrypt(\$symb);
11241: return ($symb);
11242: }
11243:
11244: # --------------------------------------------------------------Get annotation
11245:
11246: sub get_annotation {
11247: my ($symb,$enc) = @_;
11248:
11249: my $key = $symb;
11250: if (!$enc) {
11251: $key =
11252: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
11253: }
11254: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
11255: return $annotation{$key};
11256: }
11257:
11258: sub clean_symb {
1.731 raeburn 11259: my ($symb,$delete_enc) = @_;
1.685 tempelho 11260:
11261: &Apache::lonenc::check_decrypt(\$symb);
11262: my $enc = $env{'request.enc'};
1.731 raeburn 11263: if ($delete_enc) {
1.730 raeburn 11264: delete($env{'request.enc'});
11265: }
1.685 tempelho 11266:
11267: return ($symb,$enc);
11268: }
1.462 albertel 11269:
1.41 ng 11270: =pod
11271:
11272: =back
11273:
1.112 bowersj2 11274: =cut
1.41 ng 11275:
1.112 bowersj2 11276: 1;
11277: __END__;
1.41 ng 11278:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>