Annotation of loncom/interface/loncommon.pm, revision 1.1011
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1011 ! www 4: # $Id: loncommon.pm,v 1.1010 2011/06/06 21:25:59 www Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.999 www 412: function openstdbrowser(formname,uname,udom,clicker,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+
1.999 www 424: '&udomelement='+udom+
425: '&clicker='+clicker;
1.111 www 426: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 427: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 428: var title = 'Student_Browser';
1.74 www 429: var options = 'scrollbars=1,resizable=1,menubar=0';
430: options += ',width=700,height=600';
431: stdeditbrowser = open(url,title,options,'1');
432: stdeditbrowser.focus();
433: }
1.824 bisitz 434: // ]]>
1.74 www 435: </script>
436: ENDSTDBRW
437: }
1.42 matthew 438:
1.1003 www 439: sub resourcebrowser_javascript {
440: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 441: return (<<'ENDRESBRW');
1.1003 www 442: <script type="text/javascript" language="Javascript">
443: // <![CDATA[
444: var reseditbrowser;
1.1004 www 445: function openresbrowser(formname,reslink) {
1.1005 www 446: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 447: var title = 'Resource_Browser';
448: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 449: options += ',width=700,height=500';
1.1004 www 450: reseditbrowser = open(url,title,options,'1');
451: reseditbrowser.focus();
1.1003 www 452: }
453: // ]]>
454: </script>
1.1004 www 455: ENDRESBRW
1.1003 www 456: }
457:
1.74 www 458: sub selectstudent_link {
1.999 www 459: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
460: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
461: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
462: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 463: if ($env{'request.course.id'}) {
1.302 albertel 464: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
465: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
466: '/'.$env{'request.course.sec'})) {
1.111 www 467: return '';
468: }
1.999 www 469: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 470: if ($courseadvonly) {
471: $callargs .= ",'',1,1";
472: }
473: return '<span class="LC_nobreak">'.
474: '<a href="javascript:openstdbrowser('.$callargs.');">'.
475: &mt('Select User').'</a></span>';
1.74 www 476: }
1.258 albertel 477: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 478: $callargs .= ",1";
479: return '<span class="LC_nobreak">'.
480: '<a href="javascript:openstdbrowser('.$callargs.');">'.
481: &mt('Select User').'</a></span>';
1.111 www 482: }
483: return '';
1.91 www 484: }
485:
1.1004 www 486: sub selectresource_link {
487: my ($form,$reslink,$arg)=@_;
488:
489: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
490: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
491: unless ($env{'request.course.id'}) { return $arg; }
492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openresbrowser('.$callargs.');">'.
494: $arg.'</a></span>';
495: }
496:
497:
498:
1.653 raeburn 499: sub authorbrowser_javascript {
500: return <<"ENDAUTHORBRW";
1.776 bisitz 501: <script type="text/javascript" language="JavaScript">
1.824 bisitz 502: // <![CDATA[
1.653 raeburn 503: var stdeditbrowser;
504:
505: function openauthorbrowser(formname,udom) {
506: var url = '/adm/pickauthor?';
507: url += 'form='+formname+'&roledom='+udom;
508: var title = 'Author_Browser';
509: var options = 'scrollbars=1,resizable=1,menubar=0';
510: options += ',width=700,height=600';
511: stdeditbrowser = open(url,title,options,'1');
512: stdeditbrowser.focus();
513: }
514:
1.824 bisitz 515: // ]]>
1.653 raeburn 516: </script>
517: ENDAUTHORBRW
518: }
519:
1.91 www 520: sub coursebrowser_javascript {
1.909 raeburn 521: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 522: my $wintitle = 'Course_Browser';
1.931 raeburn 523: if ($crstype eq 'Community') {
1.932 raeburn 524: $wintitle = 'Community_Browser';
1.909 raeburn 525: }
1.876 raeburn 526: my $id_functions = &javascript_index_functions();
527: my $output = '
1.776 bisitz 528: <script type="text/javascript" language="JavaScript">
1.824 bisitz 529: // <![CDATA[
1.468 raeburn 530: var stdeditbrowser;'."\n";
1.876 raeburn 531:
532: $output .= <<"ENDSTDBRW";
1.909 raeburn 533: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 534: var url = '/adm/pickcourse?';
1.895 raeburn 535: var formid = getFormIdByName(formname);
1.876 raeburn 536: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 537: if (domainfilter != null) {
538: if (domainfilter != '') {
539: url += 'domainfilter='+domainfilter+'&';
540: }
541: }
1.91 www 542: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 543: '&cdomelement='+udom+
544: '&cnameelement='+desc;
1.468 raeburn 545: if (extra_element !=null && extra_element != '') {
1.594 raeburn 546: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 547: url += '&roleelement='+extra_element;
548: if (domainfilter == null || domainfilter == '') {
549: url += '&domainfilter='+extra_element;
550: }
1.234 raeburn 551: }
1.468 raeburn 552: else {
553: if (formname == 'portform') {
554: url += '&setroles='+extra_element;
1.800 raeburn 555: } else {
556: if (formname == 'rules') {
557: url += '&fixeddom='+extra_element;
558: }
1.468 raeburn 559: }
560: }
1.230 raeburn 561: }
1.909 raeburn 562: if (type != null && type != '') {
563: url += '&type='+type;
564: }
565: if (type_elem != null && type_elem != '') {
566: url += '&typeelement='+type_elem;
567: }
1.872 raeburn 568: if (formname == 'ccrs') {
569: var ownername = document.forms[formid].ccuname.value;
570: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
571: url += '&cloner='+ownername+':'+ownerdom;
572: }
1.293 raeburn 573: if (multflag !=null && multflag != '') {
574: url += '&multiple='+multflag;
575: }
1.909 raeburn 576: var title = '$wintitle';
1.91 www 577: var options = 'scrollbars=1,resizable=1,menubar=0';
578: options += ',width=700,height=600';
579: stdeditbrowser = open(url,title,options,'1');
580: stdeditbrowser.focus();
581: }
1.876 raeburn 582: $id_functions
583: ENDSTDBRW
1.905 raeburn 584: if (($sec_element ne '') || ($role_element ne '')) {
585: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 586: }
587: $output .= '
588: // ]]>
589: </script>';
590: return $output;
591: }
592:
593: sub javascript_index_functions {
594: return <<"ENDJS";
595:
596: function getFormIdByName(formname) {
597: for (var i=0;i<document.forms.length;i++) {
598: if (document.forms[i].name == formname) {
599: return i;
600: }
601: }
602: return -1;
603: }
604:
605: function getIndexByName(formid,item) {
606: for (var i=0;i<document.forms[formid].elements.length;i++) {
607: if (document.forms[formid].elements[i].name == item) {
608: return i;
609: }
610: }
611: return -1;
612: }
1.468 raeburn 613:
1.876 raeburn 614: function getDomainFromSelectbox(formname,udom) {
615: var userdom;
616: var formid = getFormIdByName(formname);
617: if (formid > -1) {
618: var domid = getIndexByName(formid,udom);
619: if (domid > -1) {
620: if (document.forms[formid].elements[domid].type == 'select-one') {
621: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
622: }
623: if (document.forms[formid].elements[domid].type == 'hidden') {
624: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 625: }
626: }
627: }
1.876 raeburn 628: return userdom;
629: }
630:
631: ENDJS
1.468 raeburn 632:
1.876 raeburn 633: }
634:
635: sub userbrowser_javascript {
636: my $id_functions = &javascript_index_functions();
637: return <<"ENDUSERBRW";
638:
1.888 raeburn 639: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 640: var url = '/adm/pickuser?';
641: var userdom = getDomainFromSelectbox(formname,udom);
642: if (userdom != null) {
643: if (userdom != '') {
644: url += 'srchdom='+userdom+'&';
645: }
646: }
647: url += 'form=' + formname + '&unameelement='+uname+
648: '&udomelement='+udom+
649: '&ulastelement='+ulast+
650: '&ufirstelement='+ufirst+
651: '&uemailelement='+uemail+
1.881 raeburn 652: '&hideudomelement='+hideudom+
653: '&coursedom='+crsdom;
1.888 raeburn 654: if ((caller != null) && (caller != undefined)) {
655: url += '&caller='+caller;
656: }
1.876 raeburn 657: var title = 'User_Browser';
658: var options = 'scrollbars=1,resizable=1,menubar=0';
659: options += ',width=700,height=600';
660: var stdeditbrowser = open(url,title,options,'1');
661: stdeditbrowser.focus();
662: }
663:
1.888 raeburn 664: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 665: var formid = getFormIdByName(formname);
666: if (formid > -1) {
1.888 raeburn 667: var unameid = getIndexByName(formid,uname);
1.876 raeburn 668: var domid = getIndexByName(formid,udom);
669: var hidedomid = getIndexByName(formid,origdom);
670: if (hidedomid > -1) {
671: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 672: var unameval = document.forms[formid].elements[unameid].value;
673: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
674: if (domid > -1) {
675: var slct = document.forms[formid].elements[domid];
676: if (slct.type == 'select-one') {
677: var i;
678: for (i=0;i<slct.length;i++) {
679: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
680: }
681: }
682: if (slct.type == 'hidden') {
683: slct.value = fixeddom;
1.876 raeburn 684: }
685: }
1.468 raeburn 686: }
687: }
688: }
1.876 raeburn 689: return;
690: }
691:
692: $id_functions
693: ENDUSERBRW
1.468 raeburn 694: }
695:
696: sub setsec_javascript {
1.905 raeburn 697: my ($sec_element,$formname,$role_element) = @_;
698: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
699: $communityrolestr);
700: if ($role_element ne '') {
701: my @allroles = ('st','ta','ep','in','ad');
702: foreach my $crstype ('Course','Community') {
703: if ($crstype eq 'Community') {
704: foreach my $role (@allroles) {
705: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
706: }
707: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
708: } else {
709: foreach my $role (@allroles) {
710: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
711: }
712: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
713: }
714: }
715: $rolestr = '"'.join('","',@allroles).'"';
716: $courserolestr = '"'.join('","',@courserolenames).'"';
717: $communityrolestr = '"'.join('","',@communityrolenames).'"';
718: }
1.468 raeburn 719: my $setsections = qq|
720: function setSect(sectionlist) {
1.629 raeburn 721: var sectionsArray = new Array();
722: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
723: sectionsArray = sectionlist.split(",");
724: }
1.468 raeburn 725: var numSections = sectionsArray.length;
726: document.$formname.$sec_element.length = 0;
727: if (numSections == 0) {
728: document.$formname.$sec_element.multiple=false;
729: document.$formname.$sec_element.size=1;
730: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
731: } else {
732: if (numSections == 1) {
733: document.$formname.$sec_element.multiple=false;
734: document.$formname.$sec_element.size=1;
735: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
736: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
737: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
738: } else {
739: for (var i=0; i<numSections; i++) {
740: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
741: }
742: document.$formname.$sec_element.multiple=true
743: if (numSections < 3) {
744: document.$formname.$sec_element.size=numSections;
745: } else {
746: document.$formname.$sec_element.size=3;
747: }
748: document.$formname.$sec_element.options[0].selected = false
749: }
750: }
1.91 www 751: }
1.905 raeburn 752:
753: function setRole(crstype) {
1.468 raeburn 754: |;
1.905 raeburn 755: if ($role_element eq '') {
756: $setsections .= ' return;
757: }
758: ';
759: } else {
760: $setsections .= qq|
761: var elementLength = document.$formname.$role_element.length;
762: var allroles = Array($rolestr);
763: var courserolenames = Array($courserolestr);
764: var communityrolenames = Array($communityrolestr);
765: if (elementLength != undefined) {
766: if (document.$formname.$role_element.options[5].value == 'cc') {
767: if (crstype == 'Course') {
768: return;
769: } else {
770: allroles[5] = 'co';
771: for (var i=0; i<6; i++) {
772: document.$formname.$role_element.options[i].value = allroles[i];
773: document.$formname.$role_element.options[i].text = communityrolenames[i];
774: }
775: }
776: } else {
777: if (crstype == 'Community') {
778: return;
779: } else {
780: allroles[5] = 'cc';
781: for (var i=0; i<6; i++) {
782: document.$formname.$role_element.options[i].value = allroles[i];
783: document.$formname.$role_element.options[i].text = courserolenames[i];
784: }
785: }
786: }
787: }
788: return;
789: }
790: |;
791: }
1.468 raeburn 792: return $setsections;
793: }
794:
1.91 www 795: sub selectcourse_link {
1.909 raeburn 796: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
797: $typeelement) = @_;
798: my $type = $selecttype;
1.871 raeburn 799: my $linktext = &mt('Select Course');
800: if ($selecttype eq 'Community') {
1.909 raeburn 801: $linktext = &mt('Select Community');
1.906 raeburn 802: } elsif ($selecttype eq 'Course/Community') {
803: $linktext = &mt('Select Course/Community');
1.909 raeburn 804: $type = '';
1.871 raeburn 805: }
1.787 bisitz 806: return '<span class="LC_nobreak">'
807: ."<a href='"
808: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
809: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 810: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 811: ."'>".$linktext.'</a>'
1.787 bisitz 812: .'</span>';
1.74 www 813: }
1.42 matthew 814:
1.653 raeburn 815: sub selectauthor_link {
816: my ($form,$udom)=@_;
817: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
818: &mt('Select Author').'</a>';
819: }
820:
1.876 raeburn 821: sub selectuser_link {
1.881 raeburn 822: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 823: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 824: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 825: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 826: ');">'.$linktext.'</a>';
1.876 raeburn 827: }
828:
1.273 raeburn 829: sub check_uncheck_jscript {
830: my $jscript = <<"ENDSCRT";
831: function checkAll(field) {
832: if (field.length > 0) {
833: for (i = 0; i < field.length; i++) {
834: field[i].checked = true ;
835: }
836: } else {
837: field.checked = true
838: }
839: }
840:
841: function uncheckAll(field) {
842: if (field.length > 0) {
843: for (i = 0; i < field.length; i++) {
844: field[i].checked = false ;
1.543 albertel 845: }
846: } else {
1.273 raeburn 847: field.checked = false ;
848: }
849: }
850: ENDSCRT
851: return $jscript;
852: }
853:
1.656 www 854: sub select_timezone {
1.659 raeburn 855: my ($name,$selected,$onchange,$includeempty)=@_;
856: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
857: if ($includeempty) {
858: $output .= '<option value=""';
859: if (($selected eq '') || ($selected eq 'local')) {
860: $output .= ' selected="selected" ';
861: }
862: $output .= '> </option>';
863: }
1.657 raeburn 864: my @timezones = DateTime::TimeZone->all_names;
865: foreach my $tzone (@timezones) {
866: $output.= '<option value="'.$tzone.'"';
867: if ($tzone eq $selected) {
868: $output.=' selected="selected"';
869: }
870: $output.=">$tzone</option>\n";
1.656 www 871: }
872: $output.="</select>";
873: return $output;
874: }
1.273 raeburn 875:
1.687 raeburn 876: sub select_datelocale {
877: my ($name,$selected,$onchange,$includeempty)=@_;
878: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
879: if ($includeempty) {
880: $output .= '<option value=""';
881: if ($selected eq '') {
882: $output .= ' selected="selected" ';
883: }
884: $output .= '> </option>';
885: }
886: my (@possibles,%locale_names);
887: my @locales = DateTime::Locale::Catalog::Locales;
888: foreach my $locale (@locales) {
889: if (ref($locale) eq 'HASH') {
890: my $id = $locale->{'id'};
891: if ($id ne '') {
892: my $en_terr = $locale->{'en_territory'};
893: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 894: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 895: if (grep(/^en$/,@languages) || !@languages) {
896: if ($en_terr ne '') {
897: $locale_names{$id} = '('.$en_terr.')';
898: } elsif ($native_terr ne '') {
899: $locale_names{$id} = $native_terr;
900: }
901: } else {
902: if ($native_terr ne '') {
903: $locale_names{$id} = $native_terr.' ';
904: } elsif ($en_terr ne '') {
905: $locale_names{$id} = '('.$en_terr.')';
906: }
907: }
908: push (@possibles,$id);
909: }
910: }
911: }
912: foreach my $item (sort(@possibles)) {
913: $output.= '<option value="'.$item.'"';
914: if ($item eq $selected) {
915: $output.=' selected="selected"';
916: }
917: $output.=">$item";
918: if ($locale_names{$item} ne '') {
919: $output.=" $locale_names{$item}</option>\n";
920: }
921: $output.="</option>\n";
922: }
923: $output.="</select>";
924: return $output;
925: }
926:
1.792 raeburn 927: sub select_language {
928: my ($name,$selected,$includeempty) = @_;
929: my %langchoices;
930: if ($includeempty) {
931: %langchoices = ('' => 'No language preference');
932: }
933: foreach my $id (&languageids()) {
934: my $code = &supportedlanguagecode($id);
935: if ($code) {
936: $langchoices{$code} = &plainlanguagedescription($id);
937: }
938: }
1.970 raeburn 939: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 940: }
941:
1.42 matthew 942: =pod
1.36 matthew 943:
1.648 raeburn 944: =item * &linked_select_forms(...)
1.36 matthew 945:
946: linked_select_forms returns a string containing a <script></script> block
947: and html for two <select> menus. The select menus will be linked in that
948: changing the value of the first menu will result in new values being placed
949: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 950: order unless a defined order is provided.
1.36 matthew 951:
952: linked_select_forms takes the following ordered inputs:
953:
954: =over 4
955:
1.112 bowersj2 956: =item * $formname, the name of the <form> tag
1.36 matthew 957:
1.112 bowersj2 958: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 959:
1.112 bowersj2 960: =item * $firstdefault, the default value for the first menu
1.36 matthew 961:
1.112 bowersj2 962: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 963:
1.112 bowersj2 964: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 965:
1.112 bowersj2 966: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 967:
1.609 raeburn 968: =item * $menuorder, the order of values in the first menu
969:
1.41 ng 970: =back
971:
1.36 matthew 972: Below is an example of such a hash. Only the 'text', 'default', and
973: 'select2' keys must appear as stated. keys(%menu) are the possible
974: values for the first select menu. The text that coincides with the
1.41 ng 975: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 976: and text for the second menu are given in the hash pointed to by
977: $menu{$choice1}->{'select2'}.
978:
1.112 bowersj2 979: my %menu = ( A1 => { text =>"Choice A1" ,
980: default => "B3",
981: select2 => {
982: B1 => "Choice B1",
983: B2 => "Choice B2",
984: B3 => "Choice B3",
985: B4 => "Choice B4"
1.609 raeburn 986: },
987: order => ['B4','B3','B1','B2'],
1.112 bowersj2 988: },
989: A2 => { text =>"Choice A2" ,
990: default => "C2",
991: select2 => {
992: C1 => "Choice C1",
993: C2 => "Choice C2",
994: C3 => "Choice C3"
1.609 raeburn 995: },
996: order => ['C2','C1','C3'],
1.112 bowersj2 997: },
998: A3 => { text =>"Choice A3" ,
999: default => "D6",
1000: select2 => {
1001: D1 => "Choice D1",
1002: D2 => "Choice D2",
1003: D3 => "Choice D3",
1004: D4 => "Choice D4",
1005: D5 => "Choice D5",
1006: D6 => "Choice D6",
1007: D7 => "Choice D7"
1.609 raeburn 1008: },
1009: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1010: }
1011: );
1.36 matthew 1012:
1013: =cut
1014:
1015: sub linked_select_forms {
1016: my ($formname,
1017: $middletext,
1018: $firstdefault,
1019: $firstselectname,
1020: $secondselectname,
1.609 raeburn 1021: $hashref,
1022: $menuorder,
1.36 matthew 1023: ) = @_;
1024: my $second = "document.$formname.$secondselectname";
1025: my $first = "document.$formname.$firstselectname";
1026: # output the javascript to do the changing
1027: my $result = '';
1.776 bisitz 1028: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1029: $result.="// <![CDATA[\n";
1.36 matthew 1030: $result.="var select2data = new Object();\n";
1031: $" = '","';
1032: my $debug = '';
1033: foreach my $s1 (sort(keys(%$hashref))) {
1034: $result.="select2data.d_$s1 = new Object();\n";
1035: $result.="select2data.d_$s1.def = new String('".
1036: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1037: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1038: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1039: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1040: @s2values = @{$hashref->{$s1}->{'order'}};
1041: }
1.36 matthew 1042: $result.="\"@s2values\");\n";
1043: $result.="select2data.d_$s1.texts = new Array(";
1044: my @s2texts;
1045: foreach my $value (@s2values) {
1046: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1047: }
1048: $result.="\"@s2texts\");\n";
1049: }
1050: $"=' ';
1051: $result.= <<"END";
1052:
1053: function select1_changed() {
1054: // Determine new choice
1055: var newvalue = "d_" + $first.value;
1056: // update select2
1057: var values = select2data[newvalue].values;
1058: var texts = select2data[newvalue].texts;
1059: var select2def = select2data[newvalue].def;
1060: var i;
1061: // out with the old
1062: for (i = 0; i < $second.options.length; i++) {
1063: $second.options[i] = null;
1064: }
1065: // in with the nuclear
1066: for (i=0;i<values.length; i++) {
1067: $second.options[i] = new Option(values[i]);
1.143 matthew 1068: $second.options[i].value = values[i];
1.36 matthew 1069: $second.options[i].text = texts[i];
1070: if (values[i] == select2def) {
1071: $second.options[i].selected = true;
1072: }
1073: }
1074: }
1.824 bisitz 1075: // ]]>
1.36 matthew 1076: </script>
1077: END
1078: # output the initial values for the selection lists
1079: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1080: my @order = sort(keys(%{$hashref}));
1081: if (ref($menuorder) eq 'ARRAY') {
1082: @order = @{$menuorder};
1083: }
1084: foreach my $value (@order) {
1.36 matthew 1085: $result.=" <option value=\"$value\" ";
1.253 albertel 1086: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1087: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1088: }
1089: $result .= "</select>\n";
1090: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1091: $result .= $middletext;
1092: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1093: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1094:
1095: my @secondorder = sort(keys(%select2));
1096: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1097: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1098: }
1099: foreach my $value (@secondorder) {
1.36 matthew 1100: $result.=" <option value=\"$value\" ";
1.253 albertel 1101: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1102: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1103: }
1104: $result .= "</select>\n";
1105: # return $debug;
1106: return $result;
1107: } # end of sub linked_select_forms {
1108:
1.45 matthew 1109: =pod
1.44 bowersj2 1110:
1.973 raeburn 1111: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1112:
1.112 bowersj2 1113: Returns a string corresponding to an HTML link to the given help
1114: $topic, where $topic corresponds to the name of a .tex file in
1115: /home/httpd/html/adm/help/tex, with underscores replaced by
1116: spaces.
1117:
1118: $text will optionally be linked to the same topic, allowing you to
1119: link text in addition to the graphic. If you do not want to link
1120: text, but wish to specify one of the later parameters, pass an
1121: empty string.
1122:
1123: $stayOnPage is a value that will be interpreted as a boolean. If true,
1124: the link will not open a new window. If false, the link will open
1125: a new window using Javascript. (Default is false.)
1126:
1127: $width and $height are optional numerical parameters that will
1128: override the width and height of the popped up window, which may
1.973 raeburn 1129: be useful for certain help topics with big pictures included.
1130:
1131: $imgid is the id of the img tag used for the help icon. This may be
1132: used in a javascript call to switch the image src. See
1133: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1134:
1135: =cut
1136:
1137: sub help_open_topic {
1.973 raeburn 1138: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1139: $text = "" if (not defined $text);
1.44 bowersj2 1140: $stayOnPage = 0 if (not defined $stayOnPage);
1141: $width = 350 if (not defined $width);
1142: $height = 400 if (not defined $height);
1143: my $filename = $topic;
1144: $filename =~ s/ /_/g;
1145:
1.48 bowersj2 1146: my $template = "";
1147: my $link;
1.572 banghart 1148:
1.159 www 1149: $topic=~s/\W/\_/g;
1.44 bowersj2 1150:
1.572 banghart 1151: if (!$stayOnPage) {
1.72 bowersj2 1152: $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 1153: } else {
1.48 bowersj2 1154: $link = "/adm/help/${filename}.hlp";
1155: }
1156:
1157: # Add the text
1.755 neumanie 1158: if ($text ne "") {
1.763 bisitz 1159: $template.='<span class="LC_help_open_topic">'
1160: .'<a target="_top" href="'.$link.'">'
1161: .$text.'</a>';
1.48 bowersj2 1162: }
1163:
1.763 bisitz 1164: # (Always) Add the graphic
1.179 matthew 1165: my $title = &mt('Online Help');
1.667 raeburn 1166: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1167: if ($imgid ne '') {
1168: $imgid = ' id="'.$imgid.'"';
1169: }
1.763 bisitz 1170: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1171: .'<img src="'.$helpicon.'" border="0"'
1172: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1173: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1174: .' /></a>';
1175: if ($text ne "") {
1176: $template.='</span>';
1177: }
1.44 bowersj2 1178: return $template;
1179:
1.106 bowersj2 1180: }
1181:
1182: # This is a quicky function for Latex cheatsheet editing, since it
1183: # appears in at least four places
1184: sub helpLatexCheatsheet {
1.732 raeburn 1185: my ($topic,$text,$not_author) = @_;
1186: my $out;
1.106 bowersj2 1187: my $addOther = '';
1.732 raeburn 1188: if ($topic) {
1.763 bisitz 1189: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1190: undef, undef, 600).
1191: '</span> ';
1192: }
1193: $out = '<span>' # Start cheatsheet
1194: .$addOther
1195: .'<span>'
1196: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1197: undef,undef,600)
1198: .'</span> <span>'
1199: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1200: undef,undef,600)
1201: .'</span>';
1.732 raeburn 1202: unless ($not_author) {
1.763 bisitz 1203: $out .= ' <span>'
1204: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1205: undef,undef,600)
1206: .'</span>';
1.732 raeburn 1207: }
1.763 bisitz 1208: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1209: return $out;
1.172 www 1210: }
1211:
1.430 albertel 1212: sub general_help {
1213: my $helptopic='Student_Intro';
1214: if ($env{'request.role'}=~/^(ca|au)/) {
1215: $helptopic='Authoring_Intro';
1.907 raeburn 1216: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1217: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1218: } elsif ($env{'request.role'}=~/^dc/) {
1219: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1220: }
1221: return $helptopic;
1222: }
1223:
1224: sub update_help_link {
1225: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1226: my $origurl = $ENV{'REQUEST_URI'};
1227: $origurl=~s|^/~|/priv/|;
1228: my $timestamp = time;
1229: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1230: $$datum = &escape($$datum);
1231: }
1232:
1233: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1234: my $output .= <<"ENDOUTPUT";
1235: <script type="text/javascript">
1.824 bisitz 1236: // <![CDATA[
1.430 albertel 1237: banner_link = '$banner_link';
1.824 bisitz 1238: // ]]>
1.430 albertel 1239: </script>
1240: ENDOUTPUT
1241: return $output;
1242: }
1243:
1244: # now just updates the help link and generates a blue icon
1.193 raeburn 1245: sub help_open_menu {
1.430 albertel 1246: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1247: = @_;
1.949 droeschl 1248: $stayOnPage = 1;
1.430 albertel 1249: my $output;
1250: if ($component_help) {
1251: if (!$text) {
1252: $output=&help_open_topic($component_help,undef,$stayOnPage,
1253: $width,$height);
1254: } else {
1255: my $help_text;
1256: $help_text=&unescape($topic);
1257: $output='<table><tr><td>'.
1258: &help_open_topic($component_help,$help_text,$stayOnPage,
1259: $width,$height).'</td></tr></table>';
1260: }
1261: }
1262: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1263: return $output.$banner_link;
1264: }
1265:
1266: sub top_nav_help {
1267: my ($text) = @_;
1.436 albertel 1268: $text = &mt($text);
1.949 droeschl 1269: my $stay_on_page = 1;
1270:
1.572 banghart 1271: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1272: : "javascript:helpMenu('open')";
1.572 banghart 1273: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1274:
1.201 raeburn 1275: my $title = &mt('Get help');
1.436 albertel 1276:
1277: return <<"END";
1278: $banner_link
1279: <a href="$link" title="$title">$text</a>
1280: END
1281: }
1282:
1283: sub help_menu_js {
1284: my ($text) = @_;
1.949 droeschl 1285: my $stayOnPage = 1;
1.436 albertel 1286: my $width = 620;
1287: my $height = 600;
1.430 albertel 1288: my $helptopic=&general_help();
1289: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1290: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1291: my $start_page =
1292: &Apache::loncommon::start_page('Help Menu', undef,
1293: {'frameset' => 1,
1294: 'js_ready' => 1,
1295: 'add_entries' => {
1296: 'border' => '0',
1.579 raeburn 1297: 'rows' => "110,*",},});
1.331 albertel 1298: my $end_page =
1299: &Apache::loncommon::end_page({'frameset' => 1,
1300: 'js_ready' => 1,});
1301:
1.436 albertel 1302: my $template .= <<"ENDTEMPLATE";
1303: <script type="text/javascript">
1.877 bisitz 1304: // <![CDATA[
1.253 albertel 1305: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1306: var banner_link = '';
1.243 raeburn 1307: function helpMenu(target) {
1308: var caller = this;
1309: if (target == 'open') {
1310: var newWindow = null;
1311: try {
1.262 albertel 1312: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1313: }
1314: catch(error) {
1315: writeHelp(caller);
1316: return;
1317: }
1318: if (newWindow) {
1319: caller = newWindow;
1320: }
1.193 raeburn 1321: }
1.243 raeburn 1322: writeHelp(caller);
1323: return;
1324: }
1325: function writeHelp(caller) {
1.430 albertel 1326: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1327: caller.document.close()
1328: caller.focus()
1.193 raeburn 1329: }
1.877 bisitz 1330: // END LON-CAPA Internal -->
1.253 albertel 1331: // ]]>
1.436 albertel 1332: </script>
1.193 raeburn 1333: ENDTEMPLATE
1334: return $template;
1335: }
1336:
1.172 www 1337: sub help_open_bug {
1338: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1339: unless ($env{'user.adv'}) { return ''; }
1.172 www 1340: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1341: $text = "" if (not defined $text);
1342: $stayOnPage=1;
1.184 albertel 1343: $width = 600 if (not defined $width);
1344: $height = 600 if (not defined $height);
1.172 www 1345:
1346: $topic=~s/\W+/\+/g;
1347: my $link='';
1348: my $template='';
1.379 albertel 1349: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1350: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1351: if (!$stayOnPage)
1352: {
1353: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1354: }
1355: else
1356: {
1357: $link = $url;
1358: }
1359: # Add the text
1360: if ($text ne "")
1361: {
1362: $template .=
1363: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1364: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1365: }
1366:
1367: # Add the graphic
1.179 matthew 1368: my $title = &mt('Report a Bug');
1.215 albertel 1369: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1370: $template .= <<"ENDTEMPLATE";
1.436 albertel 1371: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1372: ENDTEMPLATE
1373: if ($text ne '') { $template.='</td></tr></table>' };
1374: return $template;
1375:
1376: }
1377:
1378: sub help_open_faq {
1379: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1380: unless ($env{'user.adv'}) { return ''; }
1.172 www 1381: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1382: $text = "" if (not defined $text);
1383: $stayOnPage=1;
1384: $width = 350 if (not defined $width);
1385: $height = 400 if (not defined $height);
1386:
1387: $topic=~s/\W+/\+/g;
1388: my $link='';
1389: my $template='';
1390: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1391: if (!$stayOnPage)
1392: {
1393: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1394: }
1395: else
1396: {
1397: $link = $url;
1398: }
1399:
1400: # Add the text
1401: if ($text ne "")
1402: {
1403: $template .=
1.173 www 1404: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1405: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1406: }
1407:
1408: # Add the graphic
1.179 matthew 1409: my $title = &mt('View the FAQ');
1.215 albertel 1410: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1411: $template .= <<"ENDTEMPLATE";
1.436 albertel 1412: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1413: ENDTEMPLATE
1414: if ($text ne '') { $template.='</td></tr></table>' };
1415: return $template;
1416:
1.44 bowersj2 1417: }
1.37 matthew 1418:
1.180 matthew 1419: ###############################################################
1420: ###############################################################
1421:
1.45 matthew 1422: =pod
1423:
1.648 raeburn 1424: =item * &change_content_javascript():
1.256 matthew 1425:
1426: This and the next function allow you to create small sections of an
1427: otherwise static HTML page that you can update on the fly with
1428: Javascript, even in Netscape 4.
1429:
1430: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1431: must be written to the HTML page once. It will prove the Javascript
1432: function "change(name, content)". Calling the change function with the
1433: name of the section
1434: you want to update, matching the name passed to C<changable_area>, and
1435: the new content you want to put in there, will put the content into
1436: that area.
1437:
1438: B<Note>: Netscape 4 only reserves enough space for the changable area
1439: to contain room for the original contents. You need to "make space"
1440: for whatever changes you wish to make, and be B<sure> to check your
1441: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1442: it's adequate for updating a one-line status display, but little more.
1443: This script will set the space to 100% width, so you only need to
1444: worry about height in Netscape 4.
1445:
1446: Modern browsers are much less limiting, and if you can commit to the
1447: user not using Netscape 4, this feature may be used freely with
1448: pretty much any HTML.
1449:
1450: =cut
1451:
1452: sub change_content_javascript {
1453: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1454: if ($env{'browser.type'} eq 'netscape' &&
1455: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1456: return (<<NETSCAPE4);
1457: function change(name, content) {
1458: doc = document.layers[name+"___escape"].layers[0].document;
1459: doc.open();
1460: doc.write(content);
1461: doc.close();
1462: }
1463: NETSCAPE4
1464: } else {
1465: # Otherwise, we need to use semi-standards-compliant code
1466: # (technically, "innerHTML" isn't standard but the equivalent
1467: # is really scary, and every useful browser supports it
1468: return (<<DOMBASED);
1469: function change(name, content) {
1470: element = document.getElementById(name);
1471: element.innerHTML = content;
1472: }
1473: DOMBASED
1474: }
1475: }
1476:
1477: =pod
1478:
1.648 raeburn 1479: =item * &changable_area($name,$origContent):
1.256 matthew 1480:
1481: This provides a "changable area" that can be modified on the fly via
1482: the Javascript code provided in C<change_content_javascript>. $name is
1483: the name you will use to reference the area later; do not repeat the
1484: same name on a given HTML page more then once. $origContent is what
1485: the area will originally contain, which can be left blank.
1486:
1487: =cut
1488:
1489: sub changable_area {
1490: my ($name, $origContent) = @_;
1491:
1.258 albertel 1492: if ($env{'browser.type'} eq 'netscape' &&
1493: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1494: # If this is netscape 4, we need to use the Layer tag
1495: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1496: } else {
1497: return "<span id='$name'>$origContent</span>";
1498: }
1499: }
1500:
1501: =pod
1502:
1.648 raeburn 1503: =item * &viewport_geometry_js
1.590 raeburn 1504:
1505: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1506:
1507: =cut
1508:
1509:
1510: sub viewport_geometry_js {
1511: return <<"GEOMETRY";
1512: var Geometry = {};
1513: function init_geometry() {
1514: if (Geometry.init) { return };
1515: Geometry.init=1;
1516: if (window.innerHeight) {
1517: Geometry.getViewportHeight = function() { return window.innerHeight; };
1518: Geometry.getViewportWidth = function() { return window.innerWidth; };
1519: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1520: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1521: }
1522: else if (document.documentElement && document.documentElement.clientHeight) {
1523: Geometry.getViewportHeight =
1524: function() { return document.documentElement.clientHeight; };
1525: Geometry.getViewportWidth =
1526: function() { return document.documentElement.clientWidth; };
1527:
1528: Geometry.getHorizontalScroll =
1529: function() { return document.documentElement.scrollLeft; };
1530: Geometry.getVerticalScroll =
1531: function() { return document.documentElement.scrollTop; };
1532: }
1533: else if (document.body.clientHeight) {
1534: Geometry.getViewportHeight =
1535: function() { return document.body.clientHeight; };
1536: Geometry.getViewportWidth =
1537: function() { return document.body.clientWidth; };
1538: Geometry.getHorizontalScroll =
1539: function() { return document.body.scrollLeft; };
1540: Geometry.getVerticalScroll =
1541: function() { return document.body.scrollTop; };
1542: }
1543: }
1544:
1545: GEOMETRY
1546: }
1547:
1548: =pod
1549:
1.648 raeburn 1550: =item * &viewport_size_js()
1.590 raeburn 1551:
1552: 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.
1553:
1554: =cut
1555:
1556: sub viewport_size_js {
1557: my $geometry = &viewport_geometry_js();
1558: return <<"DIMS";
1559:
1560: $geometry
1561:
1562: function getViewportDims(width,height) {
1563: init_geometry();
1564: width.value = Geometry.getViewportWidth();
1565: height.value = Geometry.getViewportHeight();
1566: return;
1567: }
1568:
1569: DIMS
1570: }
1571:
1572: =pod
1573:
1.648 raeburn 1574: =item * &resize_textarea_js()
1.565 albertel 1575:
1576: emits the needed javascript to resize a textarea to be as big as possible
1577:
1578: creates a function resize_textrea that takes two IDs first should be
1579: the id of the element to resize, second should be the id of a div that
1580: surrounds everything that comes after the textarea, this routine needs
1581: to be attached to the <body> for the onload and onresize events.
1582:
1.648 raeburn 1583: =back
1.565 albertel 1584:
1585: =cut
1586:
1587: sub resize_textarea_js {
1.590 raeburn 1588: my $geometry = &viewport_geometry_js();
1.565 albertel 1589: return <<"RESIZE";
1590: <script type="text/javascript">
1.824 bisitz 1591: // <![CDATA[
1.590 raeburn 1592: $geometry
1.565 albertel 1593:
1.588 albertel 1594: function getX(element) {
1595: var x = 0;
1596: while (element) {
1597: x += element.offsetLeft;
1598: element = element.offsetParent;
1599: }
1600: return x;
1601: }
1602: function getY(element) {
1603: var y = 0;
1604: while (element) {
1605: y += element.offsetTop;
1606: element = element.offsetParent;
1607: }
1608: return y;
1609: }
1610:
1611:
1.565 albertel 1612: function resize_textarea(textarea_id,bottom_id) {
1613: init_geometry();
1614: var textarea = document.getElementById(textarea_id);
1615: //alert(textarea);
1616:
1.588 albertel 1617: var textarea_top = getY(textarea);
1.565 albertel 1618: var textarea_height = textarea.offsetHeight;
1619: var bottom = document.getElementById(bottom_id);
1.588 albertel 1620: var bottom_top = getY(bottom);
1.565 albertel 1621: var bottom_height = bottom.offsetHeight;
1622: var window_height = Geometry.getViewportHeight();
1.588 albertel 1623: var fudge = 23;
1.565 albertel 1624: var new_height = window_height-fudge-textarea_top-bottom_height;
1625: if (new_height < 300) {
1626: new_height = 300;
1627: }
1628: textarea.style.height=new_height+'px';
1629: }
1.824 bisitz 1630: // ]]>
1.565 albertel 1631: </script>
1632: RESIZE
1633:
1634: }
1635:
1636: =pod
1637:
1.256 matthew 1638: =head1 Excel and CSV file utility routines
1639:
1640: =over 4
1641:
1642: =cut
1643:
1644: ###############################################################
1645: ###############################################################
1646:
1647: =pod
1648:
1.648 raeburn 1649: =item * &csv_translate($text)
1.37 matthew 1650:
1.185 www 1651: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1652: format.
1653:
1654: =cut
1655:
1.180 matthew 1656: ###############################################################
1657: ###############################################################
1.37 matthew 1658: sub csv_translate {
1659: my $text = shift;
1660: $text =~ s/\"/\"\"/g;
1.209 albertel 1661: $text =~ s/\n/ /g;
1.37 matthew 1662: return $text;
1663: }
1.180 matthew 1664:
1665: ###############################################################
1666: ###############################################################
1667:
1668: =pod
1669:
1.648 raeburn 1670: =item * &define_excel_formats()
1.180 matthew 1671:
1672: Define some commonly used Excel cell formats.
1673:
1674: Currently supported formats:
1675:
1676: =over 4
1677:
1678: =item header
1679:
1680: =item bold
1681:
1682: =item h1
1683:
1684: =item h2
1685:
1686: =item h3
1687:
1.256 matthew 1688: =item h4
1689:
1690: =item i
1691:
1.180 matthew 1692: =item date
1693:
1694: =back
1695:
1696: Inputs: $workbook
1697:
1698: Returns: $format, a hash reference.
1699:
1700: =cut
1701:
1702: ###############################################################
1703: ###############################################################
1704: sub define_excel_formats {
1705: my ($workbook) = @_;
1706: my $format;
1707: $format->{'header'} = $workbook->add_format(bold => 1,
1708: bottom => 1,
1709: align => 'center');
1710: $format->{'bold'} = $workbook->add_format(bold=>1);
1711: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1712: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1713: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1714: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1715: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1716: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1717: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1718: return $format;
1719: }
1720:
1721: ###############################################################
1722: ###############################################################
1.113 bowersj2 1723:
1724: =pod
1725:
1.648 raeburn 1726: =item * &create_workbook()
1.255 matthew 1727:
1728: Create an Excel worksheet. If it fails, output message on the
1729: request object and return undefs.
1730:
1731: Inputs: Apache request object
1732:
1733: Returns (undef) on failure,
1734: Excel worksheet object, scalar with filename, and formats
1735: from &Apache::loncommon::define_excel_formats on success
1736:
1737: =cut
1738:
1739: ###############################################################
1740: ###############################################################
1741: sub create_workbook {
1742: my ($r) = @_;
1743: #
1744: # Create the excel spreadsheet
1745: my $filename = '/prtspool/'.
1.258 albertel 1746: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1747: time.'_'.rand(1000000000).'.xls';
1748: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1749: if (! defined($workbook)) {
1750: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1751: $r->print(
1752: '<p class="LC_error">'
1753: .&mt('Problems occurred in creating the new Excel file.')
1754: .' '.&mt('This error has been logged.')
1755: .' '.&mt('Please alert your LON-CAPA administrator.')
1756: .'</p>'
1757: );
1.255 matthew 1758: return (undef);
1759: }
1760: #
1761: $workbook->set_tempdir('/home/httpd/perl/tmp');
1762: #
1763: my $format = &Apache::loncommon::define_excel_formats($workbook);
1764: return ($workbook,$filename,$format);
1765: }
1766:
1767: ###############################################################
1768: ###############################################################
1769:
1770: =pod
1771:
1.648 raeburn 1772: =item * &create_text_file()
1.113 bowersj2 1773:
1.542 raeburn 1774: Create a file to write to and eventually make available to the user.
1.256 matthew 1775: If file creation fails, outputs an error message on the request object and
1776: return undefs.
1.113 bowersj2 1777:
1.256 matthew 1778: Inputs: Apache request object, and file suffix
1.113 bowersj2 1779:
1.256 matthew 1780: Returns (undef) on failure,
1781: Filehandle and filename on success.
1.113 bowersj2 1782:
1783: =cut
1784:
1.256 matthew 1785: ###############################################################
1786: ###############################################################
1787: sub create_text_file {
1788: my ($r,$suffix) = @_;
1789: if (! defined($suffix)) { $suffix = 'txt'; };
1790: my $fh;
1791: my $filename = '/prtspool/'.
1.258 albertel 1792: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1793: time.'_'.rand(1000000000).'.'.$suffix;
1794: $fh = Apache::File->new('>/home/httpd'.$filename);
1795: if (! defined($fh)) {
1796: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1797: $r->print(
1798: '<p class="LC_error">'
1799: .&mt('Problems occurred in creating the output file.')
1800: .' '.&mt('This error has been logged.')
1801: .' '.&mt('Please alert your LON-CAPA administrator.')
1802: .'</p>'
1803: );
1.113 bowersj2 1804: }
1.256 matthew 1805: return ($fh,$filename)
1.113 bowersj2 1806: }
1807:
1808:
1.256 matthew 1809: =pod
1.113 bowersj2 1810:
1811: =back
1812:
1813: =cut
1.37 matthew 1814:
1815: ###############################################################
1.33 matthew 1816: ## Home server <option> list generating code ##
1817: ###############################################################
1.35 matthew 1818:
1.169 www 1819: # ------------------------------------------
1820:
1821: sub domain_select {
1822: my ($name,$value,$multiple)=@_;
1823: my %domains=map {
1.514 albertel 1824: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1825: } &Apache::lonnet::all_domains();
1.169 www 1826: if ($multiple) {
1827: $domains{''}=&mt('Any domain');
1.550 albertel 1828: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1829: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1830: } else {
1.550 albertel 1831: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1832: return &select_form($name,$value,\%domains);
1.169 www 1833: }
1834: }
1835:
1.282 albertel 1836: #-------------------------------------------
1837:
1838: =pod
1839:
1.519 raeburn 1840: =head1 Routines for form select boxes
1841:
1842: =over 4
1843:
1.648 raeburn 1844: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1845:
1846: Returns a string containing a <select> element int multiple mode
1847:
1848:
1849: Args:
1850: $name - name of the <select> element
1.506 raeburn 1851: $value - scalar or array ref of values that should already be selected
1.282 albertel 1852: $size - number of rows long the select element is
1.283 albertel 1853: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1854: (shown text should already have been &mt())
1.506 raeburn 1855: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1856:
1.282 albertel 1857: =cut
1858:
1859: #-------------------------------------------
1.169 www 1860: sub multiple_select_form {
1.284 albertel 1861: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1862: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1863: my $output='';
1.191 matthew 1864: if (! defined($size)) {
1865: $size = 4;
1.283 albertel 1866: if (scalar(keys(%$hash))<4) {
1867: $size = scalar(keys(%$hash));
1.191 matthew 1868: }
1869: }
1.734 bisitz 1870: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1871: my @order;
1.506 raeburn 1872: if (ref($order) eq 'ARRAY') {
1873: @order = @{$order};
1874: } else {
1875: @order = sort(keys(%$hash));
1.501 banghart 1876: }
1877: if (exists($$hash{'select_form_order'})) {
1878: @order = @{$$hash{'select_form_order'}};
1879: }
1880:
1.284 albertel 1881: foreach my $key (@order) {
1.356 albertel 1882: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1883: $output.='selected="selected" ' if ($selected{$key});
1884: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1885: }
1886: $output.="</select>\n";
1887: return $output;
1888: }
1889:
1.88 www 1890: #-------------------------------------------
1891:
1892: =pod
1893:
1.970 raeburn 1894: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1895:
1896: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1897: allow a user to select options from a ref to a hash containing:
1898: option_name => displayed text. An optional $onchange can include
1899: a javascript onchange item, e.g., onchange="this.form.submit();"
1900:
1.88 www 1901: See lonrights.pm for an example invocation and use.
1902:
1903: =cut
1904:
1905: #-------------------------------------------
1906: sub select_form {
1.970 raeburn 1907: my ($def,$name,$hashref,$onchange) = @_;
1908: return unless (ref($hashref) eq 'HASH');
1909: if ($onchange) {
1910: $onchange = ' onchange="'.$onchange.'"';
1911: }
1912: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1913: my @keys;
1.970 raeburn 1914: if (exists($hashref->{'select_form_order'})) {
1915: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1916: } else {
1.970 raeburn 1917: @keys=sort(keys(%{$hashref}));
1.128 albertel 1918: }
1.356 albertel 1919: foreach my $key (@keys) {
1920: $selectform.=
1921: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1922: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 1923: ">".$hashref->{$key}."</option>\n";
1.88 www 1924: }
1925: $selectform.="</select>";
1926: return $selectform;
1927: }
1928:
1.475 www 1929: # For display filters
1930:
1931: sub display_filter {
1932: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1933: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1934: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1935: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1936: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1937: '</label></span> <span class="LC_nobreak">'.
1.475 www 1938: &mt('Filter [_1]',
1.477 www 1939: &select_form($env{'form.displayfilter'},
1940: 'displayfilter',
1.970 raeburn 1941: {'currentfolder' => 'Current folder/page',
1.477 www 1942: 'containing' => 'Containing phrase',
1.970 raeburn 1943: 'none' => 'None'})).
1.714 bisitz 1944: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1945: }
1946:
1.167 www 1947: sub gradeleveldescription {
1948: my $gradelevel=shift;
1949: my %gradelevels=(0 => 'Not specified',
1950: 1 => 'Grade 1',
1951: 2 => 'Grade 2',
1952: 3 => 'Grade 3',
1953: 4 => 'Grade 4',
1954: 5 => 'Grade 5',
1955: 6 => 'Grade 6',
1956: 7 => 'Grade 7',
1957: 8 => 'Grade 8',
1958: 9 => 'Grade 9',
1959: 10 => 'Grade 10',
1960: 11 => 'Grade 11',
1961: 12 => 'Grade 12',
1962: 13 => 'Grade 13',
1963: 14 => '100 Level',
1964: 15 => '200 Level',
1965: 16 => '300 Level',
1966: 17 => '400 Level',
1967: 18 => 'Graduate Level');
1968: return &mt($gradelevels{$gradelevel});
1969: }
1970:
1.163 www 1971: sub select_level_form {
1972: my ($deflevel,$name)=@_;
1973: unless ($deflevel) { $deflevel=0; }
1.167 www 1974: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1975: for (my $i=0; $i<=18; $i++) {
1976: $selectform.="<option value=\"$i\" ".
1.253 albertel 1977: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1978: ">".&gradeleveldescription($i)."</option>\n";
1979: }
1980: $selectform.="</select>";
1981: return $selectform;
1.163 www 1982: }
1.167 www 1983:
1.35 matthew 1984: #-------------------------------------------
1985:
1.45 matthew 1986: =pod
1987:
1.910 raeburn 1988: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1989:
1990: Returns a string containing a <select name='$name' size='1'> form to
1991: allow a user to select the domain to preform an operation in.
1992: See loncreateuser.pm for an example invocation and use.
1993:
1.90 www 1994: If the $includeempty flag is set, it also includes an empty choice ("no domain
1995: selected");
1996:
1.743 raeburn 1997: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1998:
1.910 raeburn 1999: 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.
2000:
2001: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2002:
1.35 matthew 2003: =cut
2004:
2005: #-------------------------------------------
1.34 matthew 2006: sub select_dom_form {
1.910 raeburn 2007: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2008: if ($onchange) {
1.874 raeburn 2009: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2010: }
1.910 raeburn 2011: my @domains;
2012: if (ref($incdoms) eq 'ARRAY') {
2013: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2014: } else {
2015: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2016: }
1.90 www 2017: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2018: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2019: foreach my $dom (@domains) {
2020: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2021: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2022: if ($showdomdesc) {
2023: if ($dom ne '') {
2024: my $domdesc = &Apache::lonnet::domain($dom,'description');
2025: if ($domdesc ne '') {
2026: $selectdomain .= ' ('.$domdesc.')';
2027: }
2028: }
2029: }
2030: $selectdomain .= "</option>\n";
1.34 matthew 2031: }
2032: $selectdomain.="</select>";
2033: return $selectdomain;
2034: }
2035:
1.35 matthew 2036: #-------------------------------------------
2037:
1.45 matthew 2038: =pod
2039:
1.648 raeburn 2040: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2041:
1.586 raeburn 2042: input: 4 arguments (two required, two optional) -
2043: $domain - domain of new user
2044: $name - name of form element
2045: $default - Value of 'default' causes a default item to be first
2046: option, and selected by default.
2047: $hide - Value of 'hide' causes hiding of the name of the server,
2048: if 1 server found, or default, if 0 found.
1.594 raeburn 2049: output: returns 2 items:
1.586 raeburn 2050: (a) form element which contains either:
2051: (i) <select name="$name">
2052: <option value="$hostid1">$hostid $servers{$hostid}</option>
2053: <option value="$hostid2">$hostid $servers{$hostid}</option>
2054: </select>
2055: form item if there are multiple library servers in $domain, or
2056: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2057: if there is only one library server in $domain.
2058:
2059: (b) number of library servers found.
2060:
2061: See loncreateuser.pm for example of use.
1.35 matthew 2062:
2063: =cut
2064:
2065: #-------------------------------------------
1.586 raeburn 2066: sub home_server_form_item {
2067: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2068: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2069: my $result;
2070: my $numlib = keys(%servers);
2071: if ($numlib > 1) {
2072: $result .= '<select name="'.$name.'" />'."\n";
2073: if ($default) {
1.804 bisitz 2074: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2075: '</option>'."\n";
2076: }
2077: foreach my $hostid (sort(keys(%servers))) {
2078: $result.= '<option value="'.$hostid.'">'.
2079: $hostid.' '.$servers{$hostid}."</option>\n";
2080: }
2081: $result .= '</select>'."\n";
2082: } elsif ($numlib == 1) {
2083: my $hostid;
2084: foreach my $item (keys(%servers)) {
2085: $hostid = $item;
2086: }
2087: $result .= '<input type="hidden" name="'.$name.'" value="'.
2088: $hostid.'" />';
2089: if (!$hide) {
2090: $result .= $hostid.' '.$servers{$hostid};
2091: }
2092: $result .= "\n";
2093: } elsif ($default) {
2094: $result .= '<input type="hidden" name="'.$name.
2095: '" value="default" />';
2096: if (!$hide) {
2097: $result .= &mt('default');
2098: }
2099: $result .= "\n";
1.33 matthew 2100: }
1.586 raeburn 2101: return ($result,$numlib);
1.33 matthew 2102: }
1.112 bowersj2 2103:
2104: =pod
2105:
1.534 albertel 2106: =back
2107:
1.112 bowersj2 2108: =cut
1.87 matthew 2109:
2110: ###############################################################
1.112 bowersj2 2111: ## Decoding User Agent ##
1.87 matthew 2112: ###############################################################
2113:
2114: =pod
2115:
1.112 bowersj2 2116: =head1 Decoding the User Agent
2117:
2118: =over 4
2119:
2120: =item * &decode_user_agent()
1.87 matthew 2121:
2122: Inputs: $r
2123:
2124: Outputs:
2125:
2126: =over 4
2127:
1.112 bowersj2 2128: =item * $httpbrowser
1.87 matthew 2129:
1.112 bowersj2 2130: =item * $clientbrowser
1.87 matthew 2131:
1.112 bowersj2 2132: =item * $clientversion
1.87 matthew 2133:
1.112 bowersj2 2134: =item * $clientmathml
1.87 matthew 2135:
1.112 bowersj2 2136: =item * $clientunicode
1.87 matthew 2137:
1.112 bowersj2 2138: =item * $clientos
1.87 matthew 2139:
2140: =back
2141:
1.157 matthew 2142: =back
2143:
1.87 matthew 2144: =cut
2145:
2146: ###############################################################
2147: ###############################################################
2148: sub decode_user_agent {
1.247 albertel 2149: my ($r)=@_;
1.87 matthew 2150: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2151: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2152: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2153: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2154: my $clientbrowser='unknown';
2155: my $clientversion='0';
2156: my $clientmathml='';
2157: my $clientunicode='0';
2158: for (my $i=0;$i<=$#browsertype;$i++) {
2159: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2160: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2161: $clientbrowser=$bname;
2162: $httpbrowser=~/$vreg/i;
2163: $clientversion=$1;
2164: $clientmathml=($clientversion>=$minv);
2165: $clientunicode=($clientversion>=$univ);
2166: }
2167: }
2168: my $clientos='unknown';
2169: if (($httpbrowser=~/linux/i) ||
2170: ($httpbrowser=~/unix/i) ||
2171: ($httpbrowser=~/ux/i) ||
2172: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2173: if (($httpbrowser=~/vax/i) ||
2174: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2175: if ($httpbrowser=~/next/i) { $clientos='next'; }
2176: if (($httpbrowser=~/mac/i) ||
2177: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2178: if ($httpbrowser=~/win/i) { $clientos='win'; }
2179: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2180: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2181: $clientunicode,$clientos,);
2182: }
2183:
1.32 matthew 2184: ###############################################################
2185: ## Authentication changing form generation subroutines ##
2186: ###############################################################
2187: ##
2188: ## All of the authform_xxxxxxx subroutines take their inputs in a
2189: ## hash, and have reasonable default values.
2190: ##
2191: ## formname = the name given in the <form> tag.
1.35 matthew 2192: #-------------------------------------------
2193:
1.45 matthew 2194: =pod
2195:
1.112 bowersj2 2196: =head1 Authentication Routines
2197:
2198: =over 4
2199:
1.648 raeburn 2200: =item * &authform_xxxxxx()
1.35 matthew 2201:
2202: The authform_xxxxxx subroutines provide javascript and html forms which
2203: handle some of the conveniences required for authentication forms.
2204: This is not an optimal method, but it works.
2205:
2206: =over 4
2207:
1.112 bowersj2 2208: =item * authform_header
1.35 matthew 2209:
1.112 bowersj2 2210: =item * authform_authorwarning
1.35 matthew 2211:
1.112 bowersj2 2212: =item * authform_nochange
1.35 matthew 2213:
1.112 bowersj2 2214: =item * authform_kerberos
1.35 matthew 2215:
1.112 bowersj2 2216: =item * authform_internal
1.35 matthew 2217:
1.112 bowersj2 2218: =item * authform_filesystem
1.35 matthew 2219:
2220: =back
2221:
1.648 raeburn 2222: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2223:
1.35 matthew 2224: =cut
2225:
2226: #-------------------------------------------
1.32 matthew 2227: sub authform_header{
2228: my %in = (
2229: formname => 'cu',
1.80 albertel 2230: kerb_def_dom => '',
1.32 matthew 2231: @_,
2232: );
2233: $in{'formname'} = 'document.' . $in{'formname'};
2234: my $result='';
1.80 albertel 2235:
2236: #---------------------------------------------- Code for upper case translation
2237: my $Javascript_toUpperCase;
2238: unless ($in{kerb_def_dom}) {
2239: $Javascript_toUpperCase =<<"END";
2240: switch (choice) {
2241: case 'krb': currentform.elements[choicearg].value =
2242: currentform.elements[choicearg].value.toUpperCase();
2243: break;
2244: default:
2245: }
2246: END
2247: } else {
2248: $Javascript_toUpperCase = "";
2249: }
2250:
1.165 raeburn 2251: my $radioval = "'nochange'";
1.591 raeburn 2252: if (defined($in{'curr_authtype'})) {
2253: if ($in{'curr_authtype'} ne '') {
2254: $radioval = "'".$in{'curr_authtype'}."arg'";
2255: }
1.174 matthew 2256: }
1.165 raeburn 2257: my $argfield = 'null';
1.591 raeburn 2258: if (defined($in{'mode'})) {
1.165 raeburn 2259: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2260: if (defined($in{'curr_autharg'})) {
2261: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2262: $argfield = "'$in{'curr_autharg'}'";
2263: }
2264: }
2265: }
2266: }
2267:
1.32 matthew 2268: $result.=<<"END";
2269: var current = new Object();
1.165 raeburn 2270: current.radiovalue = $radioval;
2271: current.argfield = $argfield;
1.32 matthew 2272:
2273: function changed_radio(choice,currentform) {
2274: var choicearg = choice + 'arg';
2275: // If a radio button in changed, we need to change the argfield
2276: if (current.radiovalue != choice) {
2277: current.radiovalue = choice;
2278: if (current.argfield != null) {
2279: currentform.elements[current.argfield].value = '';
2280: }
2281: if (choice == 'nochange') {
2282: current.argfield = null;
2283: } else {
2284: current.argfield = choicearg;
2285: switch(choice) {
2286: case 'krb':
2287: currentform.elements[current.argfield].value =
2288: "$in{'kerb_def_dom'}";
2289: break;
2290: default:
2291: break;
2292: }
2293: }
2294: }
2295: return;
2296: }
1.22 www 2297:
1.32 matthew 2298: function changed_text(choice,currentform) {
2299: var choicearg = choice + 'arg';
2300: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2301: $Javascript_toUpperCase
1.32 matthew 2302: // clear old field
2303: if ((current.argfield != choicearg) && (current.argfield != null)) {
2304: currentform.elements[current.argfield].value = '';
2305: }
2306: current.argfield = choicearg;
2307: }
2308: set_auth_radio_buttons(choice,currentform);
2309: return;
1.20 www 2310: }
1.32 matthew 2311:
2312: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2313: var numauthchoices = currentform.login.length;
2314: if (typeof numauthchoices == "undefined") {
2315: return;
2316: }
1.32 matthew 2317: var i=0;
1.986 raeburn 2318: while (i < numauthchoices) {
1.32 matthew 2319: if (currentform.login[i].value == newvalue) { break; }
2320: i++;
2321: }
1.986 raeburn 2322: if (i == numauthchoices) {
1.32 matthew 2323: return;
2324: }
2325: current.radiovalue = newvalue;
2326: currentform.login[i].checked = true;
2327: return;
2328: }
2329: END
2330: return $result;
2331: }
2332:
2333: sub authform_authorwarning{
2334: my $result='';
1.144 matthew 2335: $result='<i>'.
2336: &mt('As a general rule, only authors or co-authors should be '.
2337: 'filesystem authenticated '.
2338: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2339: return $result;
2340: }
2341:
2342: sub authform_nochange{
2343: my %in = (
2344: formname => 'document.cu',
2345: kerb_def_dom => 'MSU.EDU',
2346: @_,
2347: );
1.586 raeburn 2348: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2349: my $result;
2350: if (keys(%can_assign) == 0) {
2351: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2352: } else {
2353: $result = '<label>'.&mt('[_1] Do not change login data',
2354: '<input type="radio" name="login" value="nochange" '.
2355: 'checked="checked" onclick="'.
1.281 albertel 2356: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2357: '</label>';
1.586 raeburn 2358: }
1.32 matthew 2359: return $result;
2360: }
2361:
1.591 raeburn 2362: sub authform_kerberos {
1.32 matthew 2363: my %in = (
2364: formname => 'document.cu',
2365: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2366: kerb_def_auth => 'krb4',
1.32 matthew 2367: @_,
2368: );
1.586 raeburn 2369: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2370: $autharg,$jscall);
2371: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2372: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2373: $check5 = ' checked="checked"';
1.80 albertel 2374: } else {
1.772 bisitz 2375: $check4 = ' checked="checked"';
1.80 albertel 2376: }
1.165 raeburn 2377: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2378: if (defined($in{'curr_authtype'})) {
2379: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2380: $krbcheck = ' checked="checked"';
1.623 raeburn 2381: if (defined($in{'mode'})) {
2382: if ($in{'mode'} eq 'modifyuser') {
2383: $krbcheck = '';
2384: }
2385: }
1.591 raeburn 2386: if (defined($in{'curr_kerb_ver'})) {
2387: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2388: $check5 = ' checked="checked"';
1.591 raeburn 2389: $check4 = '';
2390: } else {
1.772 bisitz 2391: $check4 = ' checked="checked"';
1.591 raeburn 2392: $check5 = '';
2393: }
1.586 raeburn 2394: }
1.591 raeburn 2395: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2396: $krbarg = $in{'curr_autharg'};
2397: }
1.586 raeburn 2398: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2399: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2400: $result =
2401: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2402: $in{'curr_autharg'},$krbver);
2403: } else {
2404: $result =
2405: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2406: }
2407: return $result;
2408: }
2409: }
2410: } else {
2411: if ($authnum == 1) {
1.784 bisitz 2412: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2413: }
2414: }
1.586 raeburn 2415: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2416: return;
1.587 raeburn 2417: } elsif ($authtype eq '') {
1.591 raeburn 2418: if (defined($in{'mode'})) {
1.587 raeburn 2419: if ($in{'mode'} eq 'modifycourse') {
2420: if ($authnum == 1) {
1.784 bisitz 2421: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2422: }
2423: }
2424: }
1.586 raeburn 2425: }
2426: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2427: if ($authtype eq '') {
2428: $authtype = '<input type="radio" name="login" value="krb" '.
2429: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2430: $krbcheck.' />';
2431: }
2432: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2433: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2434: $in{'curr_authtype'} eq 'krb5') ||
2435: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2436: $in{'curr_authtype'} eq 'krb4')) {
2437: $result .= &mt
1.144 matthew 2438: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2439: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2440: '<label>'.$authtype,
1.281 albertel 2441: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2442: 'value="'.$krbarg.'" '.
1.144 matthew 2443: 'onchange="'.$jscall.'" />',
1.281 albertel 2444: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2445: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2446: '</label>');
1.586 raeburn 2447: } elsif ($can_assign{'krb4'}) {
2448: $result .= &mt
2449: ('[_1] Kerberos authenticated with domain [_2] '.
2450: '[_3] Version 4 [_4]',
2451: '<label>'.$authtype,
2452: '</label><input type="text" size="10" name="krbarg" '.
2453: 'value="'.$krbarg.'" '.
2454: 'onchange="'.$jscall.'" />',
2455: '<label><input type="hidden" name="krbver" value="4" />',
2456: '</label>');
2457: } elsif ($can_assign{'krb5'}) {
2458: $result .= &mt
2459: ('[_1] Kerberos authenticated with domain [_2] '.
2460: '[_3] Version 5 [_4]',
2461: '<label>'.$authtype,
2462: '</label><input type="text" size="10" name="krbarg" '.
2463: 'value="'.$krbarg.'" '.
2464: 'onchange="'.$jscall.'" />',
2465: '<label><input type="hidden" name="krbver" value="5" />',
2466: '</label>');
2467: }
1.32 matthew 2468: return $result;
2469: }
2470:
2471: sub authform_internal{
1.586 raeburn 2472: my %in = (
1.32 matthew 2473: formname => 'document.cu',
2474: kerb_def_dom => 'MSU.EDU',
2475: @_,
2476: );
1.586 raeburn 2477: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2478: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2479: if (defined($in{'curr_authtype'})) {
2480: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2481: if ($can_assign{'int'}) {
1.772 bisitz 2482: $intcheck = 'checked="checked" ';
1.623 raeburn 2483: if (defined($in{'mode'})) {
2484: if ($in{'mode'} eq 'modifyuser') {
2485: $intcheck = '';
2486: }
2487: }
1.591 raeburn 2488: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2489: $intarg = $in{'curr_autharg'};
2490: }
2491: } else {
2492: $result = &mt('Currently internally authenticated.');
2493: return $result;
1.165 raeburn 2494: }
2495: }
1.586 raeburn 2496: } else {
2497: if ($authnum == 1) {
1.784 bisitz 2498: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2499: }
2500: }
2501: if (!$can_assign{'int'}) {
2502: return;
1.587 raeburn 2503: } elsif ($authtype eq '') {
1.591 raeburn 2504: if (defined($in{'mode'})) {
1.587 raeburn 2505: if ($in{'mode'} eq 'modifycourse') {
2506: if ($authnum == 1) {
1.784 bisitz 2507: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2508: }
2509: }
2510: }
1.165 raeburn 2511: }
1.586 raeburn 2512: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2513: if ($authtype eq '') {
2514: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2515: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2516: }
1.605 bisitz 2517: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2518: $intarg.'" onchange="'.$jscall.'" />';
2519: $result = &mt
1.144 matthew 2520: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2521: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2522: $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 2523: return $result;
2524: }
2525:
2526: sub authform_local{
2527: my %in = (
2528: formname => 'document.cu',
2529: kerb_def_dom => 'MSU.EDU',
2530: @_,
2531: );
1.586 raeburn 2532: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2533: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2534: if (defined($in{'curr_authtype'})) {
2535: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2536: if ($can_assign{'loc'}) {
1.772 bisitz 2537: $loccheck = 'checked="checked" ';
1.623 raeburn 2538: if (defined($in{'mode'})) {
2539: if ($in{'mode'} eq 'modifyuser') {
2540: $loccheck = '';
2541: }
2542: }
1.591 raeburn 2543: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2544: $locarg = $in{'curr_autharg'};
2545: }
2546: } else {
2547: $result = &mt('Currently using local (institutional) authentication.');
2548: return $result;
1.165 raeburn 2549: }
2550: }
1.586 raeburn 2551: } else {
2552: if ($authnum == 1) {
1.784 bisitz 2553: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2554: }
2555: }
2556: if (!$can_assign{'loc'}) {
2557: return;
1.587 raeburn 2558: } elsif ($authtype eq '') {
1.591 raeburn 2559: if (defined($in{'mode'})) {
1.587 raeburn 2560: if ($in{'mode'} eq 'modifycourse') {
2561: if ($authnum == 1) {
1.784 bisitz 2562: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2563: }
2564: }
2565: }
1.165 raeburn 2566: }
1.586 raeburn 2567: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2568: if ($authtype eq '') {
2569: $authtype = '<input type="radio" name="login" value="loc" '.
2570: $loccheck.' onchange="'.$jscall.'" onclick="'.
2571: $jscall.'" />';
2572: }
2573: $autharg = '<input type="text" size="10" name="locarg" value="'.
2574: $locarg.'" onchange="'.$jscall.'" />';
2575: $result = &mt('[_1] Local Authentication with argument [_2]',
2576: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2577: return $result;
2578: }
2579:
2580: sub authform_filesystem{
2581: my %in = (
2582: formname => 'document.cu',
2583: kerb_def_dom => 'MSU.EDU',
2584: @_,
2585: );
1.586 raeburn 2586: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2587: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2588: if (defined($in{'curr_authtype'})) {
2589: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2590: if ($can_assign{'fsys'}) {
1.772 bisitz 2591: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2592: if (defined($in{'mode'})) {
2593: if ($in{'mode'} eq 'modifyuser') {
2594: $fsyscheck = '';
2595: }
2596: }
1.586 raeburn 2597: } else {
2598: $result = &mt('Currently Filesystem Authenticated.');
2599: return $result;
2600: }
2601: }
2602: } else {
2603: if ($authnum == 1) {
1.784 bisitz 2604: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2605: }
2606: }
2607: if (!$can_assign{'fsys'}) {
2608: return;
1.587 raeburn 2609: } elsif ($authtype eq '') {
1.591 raeburn 2610: if (defined($in{'mode'})) {
1.587 raeburn 2611: if ($in{'mode'} eq 'modifycourse') {
2612: if ($authnum == 1) {
1.784 bisitz 2613: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2614: }
2615: }
2616: }
1.586 raeburn 2617: }
2618: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2619: if ($authtype eq '') {
2620: $authtype = '<input type="radio" name="login" value="fsys" '.
2621: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2622: $jscall.'" />';
2623: }
2624: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2625: ' onchange="'.$jscall.'" />';
2626: $result = &mt
1.144 matthew 2627: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2628: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2629: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2630: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2631: 'onchange="'.$jscall.'" />');
1.32 matthew 2632: return $result;
2633: }
2634:
1.586 raeburn 2635: sub get_assignable_auth {
2636: my ($dom) = @_;
2637: if ($dom eq '') {
2638: $dom = $env{'request.role.domain'};
2639: }
2640: my %can_assign = (
2641: krb4 => 1,
2642: krb5 => 1,
2643: int => 1,
2644: loc => 1,
2645: );
2646: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2647: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2648: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2649: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2650: my $context;
2651: if ($env{'request.role'} =~ /^au/) {
2652: $context = 'author';
2653: } elsif ($env{'request.role'} =~ /^dc/) {
2654: $context = 'domain';
2655: } elsif ($env{'request.course.id'}) {
2656: $context = 'course';
2657: }
2658: if ($context) {
2659: if (ref($authhash->{$context}) eq 'HASH') {
2660: %can_assign = %{$authhash->{$context}};
2661: }
2662: }
2663: }
2664: }
2665: my $authnum = 0;
2666: foreach my $key (keys(%can_assign)) {
2667: if ($can_assign{$key}) {
2668: $authnum ++;
2669: }
2670: }
2671: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2672: $authnum --;
2673: }
2674: return ($authnum,%can_assign);
2675: }
2676:
1.80 albertel 2677: ###############################################################
2678: ## Get Kerberos Defaults for Domain ##
2679: ###############################################################
2680: ##
2681: ## Returns default kerberos version and an associated argument
2682: ## as listed in file domain.tab. If not listed, provides
2683: ## appropriate default domain and kerberos version.
2684: ##
2685: #-------------------------------------------
2686:
2687: =pod
2688:
1.648 raeburn 2689: =item * &get_kerberos_defaults()
1.80 albertel 2690:
2691: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2692: version and domain. If not found, it defaults to version 4 and the
2693: domain of the server.
1.80 albertel 2694:
1.648 raeburn 2695: =over 4
2696:
1.80 albertel 2697: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2698:
1.648 raeburn 2699: =back
2700:
2701: =back
2702:
1.80 albertel 2703: =cut
2704:
2705: #-------------------------------------------
2706: sub get_kerberos_defaults {
2707: my $domain=shift;
1.641 raeburn 2708: my ($krbdef,$krbdefdom);
2709: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2710: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2711: $krbdef = $domdefaults{'auth_def'};
2712: $krbdefdom = $domdefaults{'auth_arg_def'};
2713: } else {
1.80 albertel 2714: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2715: my $krbdefdom=$1;
2716: $krbdefdom=~tr/a-z/A-Z/;
2717: $krbdef = "krb4";
2718: }
2719: return ($krbdef,$krbdefdom);
2720: }
1.112 bowersj2 2721:
1.32 matthew 2722:
1.46 matthew 2723: ###############################################################
2724: ## Thesaurus Functions ##
2725: ###############################################################
1.20 www 2726:
1.46 matthew 2727: =pod
1.20 www 2728:
1.112 bowersj2 2729: =head1 Thesaurus Functions
2730:
2731: =over 4
2732:
1.648 raeburn 2733: =item * &initialize_keywords()
1.46 matthew 2734:
2735: Initializes the package variable %Keywords if it is empty. Uses the
2736: package variable $thesaurus_db_file.
2737:
2738: =cut
2739:
2740: ###################################################
2741:
2742: sub initialize_keywords {
2743: return 1 if (scalar keys(%Keywords));
2744: # If we are here, %Keywords is empty, so fill it up
2745: # Make sure the file we need exists...
2746: if (! -e $thesaurus_db_file) {
2747: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2748: " failed because it does not exist");
2749: return 0;
2750: }
2751: # Set up the hash as a database
2752: my %thesaurus_db;
2753: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2754: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2755: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2756: $thesaurus_db_file);
2757: return 0;
2758: }
2759: # Get the average number of appearances of a word.
2760: my $avecount = $thesaurus_db{'average.count'};
2761: # Put keywords (those that appear > average) into %Keywords
2762: while (my ($word,$data)=each (%thesaurus_db)) {
2763: my ($count,undef) = split /:/,$data;
2764: $Keywords{$word}++ if ($count > $avecount);
2765: }
2766: untie %thesaurus_db;
2767: # Remove special values from %Keywords.
1.356 albertel 2768: foreach my $value ('total.count','average.count') {
2769: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2770: }
1.46 matthew 2771: return 1;
2772: }
2773:
2774: ###################################################
2775:
2776: =pod
2777:
1.648 raeburn 2778: =item * &keyword($word)
1.46 matthew 2779:
2780: Returns true if $word is a keyword. A keyword is a word that appears more
2781: than the average number of times in the thesaurus database. Calls
2782: &initialize_keywords
2783:
2784: =cut
2785:
2786: ###################################################
1.20 www 2787:
2788: sub keyword {
1.46 matthew 2789: return if (!&initialize_keywords());
2790: my $word=lc(shift());
2791: $word=~s/\W//g;
2792: return exists($Keywords{$word});
1.20 www 2793: }
1.46 matthew 2794:
2795: ###############################################################
2796:
2797: =pod
1.20 www 2798:
1.648 raeburn 2799: =item * &get_related_words()
1.46 matthew 2800:
1.160 matthew 2801: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2802: an array of words. If the keyword is not in the thesaurus, an empty array
2803: will be returned. The order of the words returned is determined by the
2804: database which holds them.
2805:
2806: Uses global $thesaurus_db_file.
2807:
2808: =cut
2809:
2810: ###############################################################
2811: sub get_related_words {
2812: my $keyword = shift;
2813: my %thesaurus_db;
2814: if (! -e $thesaurus_db_file) {
2815: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2816: "failed because the file does not exist");
2817: return ();
2818: }
2819: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2820: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2821: return ();
2822: }
2823: my @Words=();
1.429 www 2824: my $count=0;
1.46 matthew 2825: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2826: # The first element is the number of times
2827: # the word appears. We do not need it now.
1.429 www 2828: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2829: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2830: my $threshold=$mostfrequentcount/10;
2831: foreach my $possibleword (@RelatedWords) {
2832: my ($word,$wordcount)=split(/\,/,$possibleword);
2833: if ($wordcount>$threshold) {
2834: push(@Words,$word);
2835: $count++;
2836: if ($count>10) { last; }
2837: }
1.20 www 2838: }
2839: }
1.46 matthew 2840: untie %thesaurus_db;
2841: return @Words;
1.14 harris41 2842: }
1.46 matthew 2843:
1.112 bowersj2 2844: =pod
2845:
2846: =back
2847:
2848: =cut
1.61 www 2849:
2850: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2851: =pod
2852:
1.112 bowersj2 2853: =head1 User Name Functions
2854:
2855: =over 4
2856:
1.648 raeburn 2857: =item * &plainname($uname,$udom,$first)
1.81 albertel 2858:
1.112 bowersj2 2859: Takes a users logon name and returns it as a string in
1.226 albertel 2860: "first middle last generation" form
2861: if $first is set to 'lastname' then it returns it as
2862: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2863:
2864: =cut
1.61 www 2865:
1.295 www 2866:
1.81 albertel 2867: ###############################################################
1.61 www 2868: sub plainname {
1.226 albertel 2869: my ($uname,$udom,$first)=@_;
1.537 albertel 2870: return if (!defined($uname) || !defined($udom));
1.295 www 2871: my %names=&getnames($uname,$udom);
1.226 albertel 2872: my $name=&Apache::lonnet::format_name($names{'firstname'},
2873: $names{'middlename'},
2874: $names{'lastname'},
2875: $names{'generation'},$first);
2876: $name=~s/^\s+//;
1.62 www 2877: $name=~s/\s+$//;
2878: $name=~s/\s+/ /g;
1.353 albertel 2879: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2880: return $name;
1.61 www 2881: }
1.66 www 2882:
2883: # -------------------------------------------------------------------- Nickname
1.81 albertel 2884: =pod
2885:
1.648 raeburn 2886: =item * &nickname($uname,$udom)
1.81 albertel 2887:
2888: Gets a users name and returns it as a string as
2889:
2890: ""nickname""
1.66 www 2891:
1.81 albertel 2892: if the user has a nickname or
2893:
2894: "first middle last generation"
2895:
2896: if the user does not
2897:
2898: =cut
1.66 www 2899:
2900: sub nickname {
2901: my ($uname,$udom)=@_;
1.537 albertel 2902: return if (!defined($uname) || !defined($udom));
1.295 www 2903: my %names=&getnames($uname,$udom);
1.68 albertel 2904: my $name=$names{'nickname'};
1.66 www 2905: if ($name) {
2906: $name='"'.$name.'"';
2907: } else {
2908: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2909: $names{'lastname'}.' '.$names{'generation'};
2910: $name=~s/\s+$//;
2911: $name=~s/\s+/ /g;
2912: }
2913: return $name;
2914: }
2915:
1.295 www 2916: sub getnames {
2917: my ($uname,$udom)=@_;
1.537 albertel 2918: return if (!defined($uname) || !defined($udom));
1.433 albertel 2919: if ($udom eq 'public' && $uname eq 'public') {
2920: return ('lastname' => &mt('Public'));
2921: }
1.295 www 2922: my $id=$uname.':'.$udom;
2923: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2924: if ($cached) {
2925: return %{$names};
2926: } else {
2927: my %loadnames=&Apache::lonnet::get('environment',
2928: ['firstname','middlename','lastname','generation','nickname'],
2929: $udom,$uname);
2930: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2931: return %loadnames;
2932: }
2933: }
1.61 www 2934:
1.542 raeburn 2935: # -------------------------------------------------------------------- getemails
1.648 raeburn 2936:
1.542 raeburn 2937: =pod
2938:
1.648 raeburn 2939: =item * &getemails($uname,$udom)
1.542 raeburn 2940:
2941: Gets a user's email information and returns it as a hash with keys:
2942: notification, critnotification, permanentemail
2943:
2944: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2945: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2946:
1.648 raeburn 2947:
1.542 raeburn 2948: =cut
2949:
1.648 raeburn 2950:
1.466 albertel 2951: sub getemails {
2952: my ($uname,$udom)=@_;
2953: if ($udom eq 'public' && $uname eq 'public') {
2954: return;
2955: }
1.467 www 2956: if (!$udom) { $udom=$env{'user.domain'}; }
2957: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2958: my $id=$uname.':'.$udom;
2959: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2960: if ($cached) {
2961: return %{$names};
2962: } else {
2963: my %loadnames=&Apache::lonnet::get('environment',
2964: ['notification','critnotification',
2965: 'permanentemail'],
2966: $udom,$uname);
2967: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2968: return %loadnames;
2969: }
2970: }
2971:
1.551 albertel 2972: sub flush_email_cache {
2973: my ($uname,$udom)=@_;
2974: if (!$udom) { $udom =$env{'user.domain'}; }
2975: if (!$uname) { $uname=$env{'user.name'}; }
2976: return if ($udom eq 'public' && $uname eq 'public');
2977: my $id=$uname.':'.$udom;
2978: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2979: }
2980:
1.728 raeburn 2981: # -------------------------------------------------------------------- getlangs
2982:
2983: =pod
2984:
2985: =item * &getlangs($uname,$udom)
2986:
2987: Gets a user's language preference and returns it as a hash with key:
2988: language.
2989:
2990: =cut
2991:
2992:
2993: sub getlangs {
2994: my ($uname,$udom) = @_;
2995: if (!$udom) { $udom =$env{'user.domain'}; }
2996: if (!$uname) { $uname=$env{'user.name'}; }
2997: my $id=$uname.':'.$udom;
2998: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2999: if ($cached) {
3000: return %{$langs};
3001: } else {
3002: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3003: $udom,$uname);
3004: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3005: return %loadlangs;
3006: }
3007: }
3008:
3009: sub flush_langs_cache {
3010: my ($uname,$udom)=@_;
3011: if (!$udom) { $udom =$env{'user.domain'}; }
3012: if (!$uname) { $uname=$env{'user.name'}; }
3013: return if ($udom eq 'public' && $uname eq 'public');
3014: my $id=$uname.':'.$udom;
3015: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3016: }
3017:
1.61 www 3018: # ------------------------------------------------------------------ Screenname
1.81 albertel 3019:
3020: =pod
3021:
1.648 raeburn 3022: =item * &screenname($uname,$udom)
1.81 albertel 3023:
3024: Gets a users screenname and returns it as a string
3025:
3026: =cut
1.61 www 3027:
3028: sub screenname {
3029: my ($uname,$udom)=@_;
1.258 albertel 3030: if ($uname eq $env{'user.name'} &&
3031: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3032: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3033: return $names{'screenname'};
1.62 www 3034: }
3035:
1.212 albertel 3036:
1.802 bisitz 3037: # ------------------------------------------------------------- Confirm Wrapper
3038: =pod
3039:
3040: =item confirmwrapper
3041:
3042: Wrap messages about completion of operation in box
3043:
3044: =cut
3045:
3046: sub confirmwrapper {
3047: my ($message)=@_;
3048: if ($message) {
3049: return "\n".'<div class="LC_confirm_box">'."\n"
3050: .$message."\n"
3051: .'</div>'."\n";
3052: } else {
3053: return $message;
3054: }
3055: }
3056:
1.62 www 3057: # ------------------------------------------------------------- Message Wrapper
3058:
3059: sub messagewrapper {
1.369 www 3060: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3061: return
1.441 albertel 3062: '<a href="/adm/email?compose=individual&'.
3063: 'recname='.$username.'&recdom='.$domain.
3064: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3065: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3066: }
1.802 bisitz 3067:
1.74 www 3068: # --------------------------------------------------------------- Notes Wrapper
3069:
3070: sub noteswrapper {
3071: my ($link,$un,$do)=@_;
3072: return
1.896 amueller 3073: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3074: }
1.802 bisitz 3075:
1.62 www 3076: # ------------------------------------------------------------- Aboutme Wrapper
3077:
3078: sub aboutmewrapper {
1.166 www 3079: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3080: if (!defined($username) && !defined($domain)) {
3081: return;
3082: }
1.892 amueller 3083: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3084: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3085: }
3086:
3087: # ------------------------------------------------------------ Syllabus Wrapper
3088:
3089: sub syllabuswrapper {
1.707 bisitz 3090: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3091: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3092: }
1.14 harris41 3093:
1.802 bisitz 3094: # -----------------------------------------------------------------------------
3095:
1.208 matthew 3096: sub track_student_link {
1.887 raeburn 3097: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3098: my $link ="/adm/trackstudent?";
1.208 matthew 3099: my $title = 'View recent activity';
3100: if (defined($sname) && $sname !~ /^\s*$/ &&
3101: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3102: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3103: $title .= ' of this student';
1.268 albertel 3104: }
1.208 matthew 3105: if (defined($target) && $target !~ /^\s*$/) {
3106: $target = qq{target="$target"};
3107: } else {
3108: $target = '';
3109: }
1.268 albertel 3110: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3111: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3112: $title = &mt($title);
3113: $linktext = &mt($linktext);
1.448 albertel 3114: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3115: &help_open_topic('View_recent_activity');
1.208 matthew 3116: }
3117:
1.781 raeburn 3118: sub slot_reservations_link {
3119: my ($linktext,$sname,$sdom,$target) = @_;
3120: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3121: my $title = 'View slot reservation history';
3122: if (defined($sname) && $sname !~ /^\s*$/ &&
3123: defined($sdom) && $sdom !~ /^\s*$/) {
3124: $link .= "&uname=$sname&udom=$sdom";
3125: $title .= ' of this student';
3126: }
3127: if (defined($target) && $target !~ /^\s*$/) {
3128: $target = qq{target="$target"};
3129: } else {
3130: $target = '';
3131: }
3132: $title = &mt($title);
3133: $linktext = &mt($linktext);
3134: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3135: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3136:
3137: }
3138:
1.508 www 3139: # ===================================================== Display a student photo
3140:
3141:
1.509 albertel 3142: sub student_image_tag {
1.508 www 3143: my ($domain,$user)=@_;
3144: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3145: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3146: return '<img src="'.$imgsrc.'" align="right" />';
3147: } else {
3148: return '';
3149: }
3150: }
3151:
1.112 bowersj2 3152: =pod
3153:
3154: =back
3155:
3156: =head1 Access .tab File Data
3157:
3158: =over 4
3159:
1.648 raeburn 3160: =item * &languageids()
1.112 bowersj2 3161:
3162: returns list of all language ids
3163:
3164: =cut
3165:
1.14 harris41 3166: sub languageids {
1.16 harris41 3167: return sort(keys(%language));
1.14 harris41 3168: }
3169:
1.112 bowersj2 3170: =pod
3171:
1.648 raeburn 3172: =item * &languagedescription()
1.112 bowersj2 3173:
3174: returns description of a specified language id
3175:
3176: =cut
3177:
1.14 harris41 3178: sub languagedescription {
1.125 www 3179: my $code=shift;
3180: return ($supported_language{$code}?'* ':'').
3181: $language{$code}.
1.126 www 3182: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3183: }
3184:
3185: sub plainlanguagedescription {
3186: my $code=shift;
3187: return $language{$code};
3188: }
3189:
3190: sub supportedlanguagecode {
3191: my $code=shift;
3192: return $supported_language{$code};
1.97 www 3193: }
3194:
1.112 bowersj2 3195: =pod
3196:
1.648 raeburn 3197: =item * ©rightids()
1.112 bowersj2 3198:
3199: returns list of all copyrights
3200:
3201: =cut
3202:
3203: sub copyrightids {
3204: return sort(keys(%cprtag));
3205: }
3206:
3207: =pod
3208:
1.648 raeburn 3209: =item * ©rightdescription()
1.112 bowersj2 3210:
3211: returns description of a specified copyright id
3212:
3213: =cut
3214:
3215: sub copyrightdescription {
1.166 www 3216: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3217: }
1.197 matthew 3218:
3219: =pod
3220:
1.648 raeburn 3221: =item * &source_copyrightids()
1.192 taceyjo1 3222:
3223: returns list of all source copyrights
3224:
3225: =cut
3226:
3227: sub source_copyrightids {
3228: return sort(keys(%scprtag));
3229: }
3230:
3231: =pod
3232:
1.648 raeburn 3233: =item * &source_copyrightdescription()
1.192 taceyjo1 3234:
3235: returns description of a specified source copyright id
3236:
3237: =cut
3238:
3239: sub source_copyrightdescription {
3240: return &mt($scprtag{shift(@_)});
3241: }
1.112 bowersj2 3242:
3243: =pod
3244:
1.648 raeburn 3245: =item * &filecategories()
1.112 bowersj2 3246:
3247: returns list of all file categories
3248:
3249: =cut
3250:
3251: sub filecategories {
3252: return sort(keys(%category_extensions));
3253: }
3254:
3255: =pod
3256:
1.648 raeburn 3257: =item * &filecategorytypes()
1.112 bowersj2 3258:
3259: returns list of file types belonging to a given file
3260: category
3261:
3262: =cut
3263:
3264: sub filecategorytypes {
1.356 albertel 3265: my ($cat) = @_;
3266: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3267: }
3268:
3269: =pod
3270:
1.648 raeburn 3271: =item * &fileembstyle()
1.112 bowersj2 3272:
3273: returns embedding style for a specified file type
3274:
3275: =cut
3276:
3277: sub fileembstyle {
3278: return $fe{lc(shift(@_))};
1.169 www 3279: }
3280:
1.351 www 3281: sub filemimetype {
3282: return $fm{lc(shift(@_))};
3283: }
3284:
1.169 www 3285:
3286: sub filecategoryselect {
3287: my ($name,$value)=@_;
1.189 matthew 3288: return &select_form($value,$name,
1.970 raeburn 3289: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3290: }
3291:
3292: =pod
3293:
1.648 raeburn 3294: =item * &filedescription()
1.112 bowersj2 3295:
3296: returns description for a specified file type
3297:
3298: =cut
3299:
3300: sub filedescription {
1.188 matthew 3301: my $file_description = $fd{lc(shift())};
3302: $file_description =~ s:([\[\]]):~$1:g;
3303: return &mt($file_description);
1.112 bowersj2 3304: }
3305:
3306: =pod
3307:
1.648 raeburn 3308: =item * &filedescriptionex()
1.112 bowersj2 3309:
3310: returns description for a specified file type with
3311: extra formatting
3312:
3313: =cut
3314:
3315: sub filedescriptionex {
3316: my $ex=shift;
1.188 matthew 3317: my $file_description = $fd{lc($ex)};
3318: $file_description =~ s:([\[\]]):~$1:g;
3319: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3320: }
3321:
3322: # End of .tab access
3323: =pod
3324:
3325: =back
3326:
3327: =cut
3328:
3329: # ------------------------------------------------------------------ File Types
3330: sub fileextensions {
3331: return sort(keys(%fe));
3332: }
3333:
1.97 www 3334: # ----------------------------------------------------------- Display Languages
3335: # returns a hash with all desired display languages
3336: #
3337:
3338: sub display_languages {
3339: my %languages=();
1.695 raeburn 3340: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3341: $languages{$lang}=1;
1.97 www 3342: }
3343: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3344: if ($env{'form.displaylanguage'}) {
1.356 albertel 3345: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3346: $languages{$lang}=1;
1.97 www 3347: }
3348: }
3349: return %languages;
1.14 harris41 3350: }
3351:
1.582 albertel 3352: sub languages {
3353: my ($possible_langs) = @_;
1.695 raeburn 3354: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3355: if (!ref($possible_langs)) {
3356: if( wantarray ) {
3357: return @preferred_langs;
3358: } else {
3359: return $preferred_langs[0];
3360: }
3361: }
3362: my %possibilities = map { $_ => 1 } (@$possible_langs);
3363: my @preferred_possibilities;
3364: foreach my $preferred_lang (@preferred_langs) {
3365: if (exists($possibilities{$preferred_lang})) {
3366: push(@preferred_possibilities, $preferred_lang);
3367: }
3368: }
3369: if( wantarray ) {
3370: return @preferred_possibilities;
3371: }
3372: return $preferred_possibilities[0];
3373: }
3374:
1.742 raeburn 3375: sub user_lang {
3376: my ($touname,$toudom,$fromcid) = @_;
3377: my @userlangs;
3378: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3379: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3380: $env{'course.'.$fromcid.'.languages'}));
3381: } else {
3382: my %langhash = &getlangs($touname,$toudom);
3383: if ($langhash{'languages'} ne '') {
3384: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3385: } else {
3386: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3387: if ($domdefs{'lang_def'} ne '') {
3388: @userlangs = ($domdefs{'lang_def'});
3389: }
3390: }
3391: }
3392: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3393: my $user_lh = Apache::localize->get_handle(@languages);
3394: return $user_lh;
3395: }
3396:
3397:
1.112 bowersj2 3398: ###############################################################
3399: ## Student Answer Attempts ##
3400: ###############################################################
3401:
3402: =pod
3403:
3404: =head1 Alternate Problem Views
3405:
3406: =over 4
3407:
1.648 raeburn 3408: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3409: $getattempt, $regexp, $gradesub)
3410:
3411: Return string with previous attempt on problem. Arguments:
3412:
3413: =over 4
3414:
3415: =item * $symb: Problem, including path
3416:
3417: =item * $username: username of the desired student
3418:
3419: =item * $domain: domain of the desired student
1.14 harris41 3420:
1.112 bowersj2 3421: =item * $course: Course ID
1.14 harris41 3422:
1.112 bowersj2 3423: =item * $getattempt: Leave blank for all attempts, otherwise put
3424: something
1.14 harris41 3425:
1.112 bowersj2 3426: =item * $regexp: if string matches this regexp, the string will be
3427: sent to $gradesub
1.14 harris41 3428:
1.112 bowersj2 3429: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3430:
1.112 bowersj2 3431: =back
1.14 harris41 3432:
1.112 bowersj2 3433: The output string is a table containing all desired attempts, if any.
1.16 harris41 3434:
1.112 bowersj2 3435: =cut
1.1 albertel 3436:
3437: sub get_previous_attempt {
1.43 ng 3438: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3439: my $prevattempts='';
1.43 ng 3440: no strict 'refs';
1.1 albertel 3441: if ($symb) {
1.3 albertel 3442: my (%returnhash)=
3443: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3444: if ($returnhash{'version'}) {
3445: my %lasthash=();
3446: my $version;
3447: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3448: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3449: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3450: }
1.1 albertel 3451: }
1.596 albertel 3452: $prevattempts=&start_data_table().&start_data_table_header_row();
3453: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3454: my (%typeparts,%lasthidden);
1.945 raeburn 3455: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3456: foreach my $key (sort(keys(%lasthash))) {
3457: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3458: if ($#parts > 0) {
1.31 albertel 3459: my $data=$parts[-1];
1.989 raeburn 3460: next if ($data eq 'foilorder');
1.31 albertel 3461: pop(@parts);
1.1010 www 3462: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3463: if ($data eq 'type') {
3464: unless ($showsurv) {
3465: my $id = join(',',@parts);
3466: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3467: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3468: $lasthidden{$ign.'.'.$id} = 1;
3469: }
1.945 raeburn 3470: }
1.1010 www 3471: }
1.31 albertel 3472: } else {
1.41 ng 3473: if ($#parts == 0) {
3474: $prevattempts.='<th>'.$parts[0].'</th>';
3475: } else {
3476: $prevattempts.='<th>'.$ign.'</th>';
3477: }
1.31 albertel 3478: }
1.16 harris41 3479: }
1.596 albertel 3480: $prevattempts.=&end_data_table_header_row();
1.40 ng 3481: if ($getattempt eq '') {
3482: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3483: my @hidden;
3484: if (%typeparts) {
3485: foreach my $id (keys(%typeparts)) {
3486: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3487: push(@hidden,$id);
3488: }
3489: }
3490: }
3491: $prevattempts.=&start_data_table_row().
3492: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3493: if (@hidden) {
3494: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3495: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3496: my $hide;
3497: foreach my $id (@hidden) {
3498: if ($key =~ /^\Q$id\E/) {
3499: $hide = 1;
3500: last;
3501: }
3502: }
3503: if ($hide) {
3504: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3505: if (($data eq 'award') || ($data eq 'awarddetail')) {
3506: my $value = &format_previous_attempt_value($key,
3507: $returnhash{$version.':'.$key});
3508: $prevattempts.='<td>'.$value.' </td>';
3509: } else {
3510: $prevattempts.='<td> </td>';
3511: }
3512: } else {
3513: if ($key =~ /\./) {
3514: my $value = &format_previous_attempt_value($key,
3515: $returnhash{$version.':'.$key});
3516: $prevattempts.='<td>'.$value.' </td>';
3517: } else {
3518: $prevattempts.='<td> </td>';
3519: }
3520: }
3521: }
3522: } else {
3523: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3524: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3525: my $value = &format_previous_attempt_value($key,
3526: $returnhash{$version.':'.$key});
3527: $prevattempts.='<td>'.$value.' </td>';
3528: }
3529: }
3530: $prevattempts.=&end_data_table_row();
1.40 ng 3531: }
1.1 albertel 3532: }
1.945 raeburn 3533: my @currhidden = keys(%lasthidden);
1.596 albertel 3534: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3535: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3536: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3537: if (%typeparts) {
3538: my $hidden;
3539: foreach my $id (@currhidden) {
3540: if ($key =~ /^\Q$id\E/) {
3541: $hidden = 1;
3542: last;
3543: }
3544: }
3545: if ($hidden) {
3546: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3547: if (($data eq 'award') || ($data eq 'awarddetail')) {
3548: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3549: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3550: $value = &$gradesub($value);
3551: }
3552: $prevattempts.='<td>'.$value.' </td>';
3553: } else {
3554: $prevattempts.='<td> </td>';
3555: }
3556: } else {
3557: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3558: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3559: $value = &$gradesub($value);
3560: }
3561: $prevattempts.='<td>'.$value.' </td>';
3562: }
3563: } else {
3564: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3565: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3566: $value = &$gradesub($value);
3567: }
3568: $prevattempts.='<td>'.$value.' </td>';
3569: }
1.16 harris41 3570: }
1.596 albertel 3571: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3572: } else {
1.596 albertel 3573: $prevattempts=
3574: &start_data_table().&start_data_table_row().
3575: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3576: &end_data_table_row().&end_data_table();
1.1 albertel 3577: }
3578: } else {
1.596 albertel 3579: $prevattempts=
3580: &start_data_table().&start_data_table_row().
3581: '<td>'.&mt('No data.').'</td>'.
3582: &end_data_table_row().&end_data_table();
1.1 albertel 3583: }
1.10 albertel 3584: }
3585:
1.581 albertel 3586: sub format_previous_attempt_value {
3587: my ($key,$value) = @_;
1.1011 ! www 3588: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3589: $value = &Apache::lonlocal::locallocaltime($value);
3590: } elsif (ref($value) eq 'ARRAY') {
3591: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3592: } elsif ($key =~ /answerstring$/) {
3593: my %answers = &Apache::lonnet::str2hash($value);
3594: my @anskeys = sort(keys(%answers));
3595: if (@anskeys == 1) {
3596: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3597: if ($answer =~ m{\0}) {
3598: $answer =~ s{\0}{,}g;
1.988 raeburn 3599: }
3600: my $tag_internal_answer_name = 'INTERNAL';
3601: if ($anskeys[0] eq $tag_internal_answer_name) {
3602: $value = $answer;
3603: } else {
3604: $value = $anskeys[0].'='.$answer;
3605: }
3606: } else {
3607: foreach my $ans (@anskeys) {
3608: my $answer = $answers{$ans};
1.1001 raeburn 3609: if ($answer =~ m{\0}) {
3610: $answer =~ s{\0}{,}g;
1.988 raeburn 3611: }
3612: $value .= $ans.'='.$answer.'<br />';;
3613: }
3614: }
1.581 albertel 3615: } else {
3616: $value = &unescape($value);
3617: }
3618: return $value;
3619: }
3620:
3621:
1.107 albertel 3622: sub relative_to_absolute {
3623: my ($url,$output)=@_;
3624: my $parser=HTML::TokeParser->new(\$output);
3625: my $token;
3626: my $thisdir=$url;
3627: my @rlinks=();
3628: while ($token=$parser->get_token) {
3629: if ($token->[0] eq 'S') {
3630: if ($token->[1] eq 'a') {
3631: if ($token->[2]->{'href'}) {
3632: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3633: }
3634: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3635: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3636: } elsif ($token->[1] eq 'base') {
3637: $thisdir=$token->[2]->{'href'};
3638: }
3639: }
3640: }
3641: $thisdir=~s-/[^/]*$--;
1.356 albertel 3642: foreach my $link (@rlinks) {
1.726 raeburn 3643: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3644: ($link=~/^\//) ||
3645: ($link=~/^javascript:/i) ||
3646: ($link=~/^mailto:/i) ||
3647: ($link=~/^\#/)) {
3648: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3649: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3650: }
3651: }
3652: # -------------------------------------------------- Deal with Applet codebases
3653: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3654: return $output;
3655: }
3656:
1.112 bowersj2 3657: =pod
3658:
1.648 raeburn 3659: =item * &get_student_view()
1.112 bowersj2 3660:
3661: show a snapshot of what student was looking at
3662:
3663: =cut
3664:
1.10 albertel 3665: sub get_student_view {
1.186 albertel 3666: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3667: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3668: my (%form);
1.10 albertel 3669: my @elements=('symb','courseid','domain','username');
3670: foreach my $element (@elements) {
1.186 albertel 3671: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3672: }
1.186 albertel 3673: if (defined($moreenv)) {
3674: %form=(%form,%{$moreenv});
3675: }
1.236 albertel 3676: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3677: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3678: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3679: $userview=~s/\<body[^\>]*\>//gi;
3680: $userview=~s/\<\/body\>//gi;
3681: $userview=~s/\<html\>//gi;
3682: $userview=~s/\<\/html\>//gi;
3683: $userview=~s/\<head\>//gi;
3684: $userview=~s/\<\/head\>//gi;
3685: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3686: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3687: if (wantarray) {
3688: return ($userview,$response);
3689: } else {
3690: return $userview;
3691: }
3692: }
3693:
3694: sub get_student_view_with_retries {
3695: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3696:
3697: my $ok = 0; # True if we got a good response.
3698: my $content;
3699: my $response;
3700:
3701: # Try to get the student_view done. within the retries count:
3702:
3703: do {
3704: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3705: $ok = $response->is_success;
3706: if (!$ok) {
3707: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3708: }
3709: $retries--;
3710: } while (!$ok && ($retries > 0));
3711:
3712: if (!$ok) {
3713: $content = ''; # On error return an empty content.
3714: }
1.651 www 3715: if (wantarray) {
3716: return ($content, $response);
3717: } else {
3718: return $content;
3719: }
1.11 albertel 3720: }
3721:
1.112 bowersj2 3722: =pod
3723:
1.648 raeburn 3724: =item * &get_student_answers()
1.112 bowersj2 3725:
3726: show a snapshot of how student was answering problem
3727:
3728: =cut
3729:
1.11 albertel 3730: sub get_student_answers {
1.100 sakharuk 3731: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3732: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3733: my (%moreenv);
1.11 albertel 3734: my @elements=('symb','courseid','domain','username');
3735: foreach my $element (@elements) {
1.186 albertel 3736: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3737: }
1.186 albertel 3738: $moreenv{'grade_target'}='answer';
3739: %moreenv=(%form,%moreenv);
1.497 raeburn 3740: $feedurl = &Apache::lonnet::clutter($feedurl);
3741: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3742: return $userview;
1.1 albertel 3743: }
1.116 albertel 3744:
3745: =pod
3746:
3747: =item * &submlink()
3748:
1.242 albertel 3749: Inputs: $text $uname $udom $symb $target
1.116 albertel 3750:
3751: Returns: A link to grades.pm such as to see the SUBM view of a student
3752:
3753: =cut
3754:
3755: ###############################################
3756: sub submlink {
1.242 albertel 3757: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3758: if (!($uname && $udom)) {
3759: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3760: &Apache::lonnet::whichuser($symb);
1.116 albertel 3761: if (!$symb) { $symb=$cursymb; }
3762: }
1.254 matthew 3763: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3764: $symb=&escape($symb);
1.960 bisitz 3765: if ($target) { $target=" target=\"$target\""; }
3766: return
3767: '<a href="/adm/grades?command=submission'.
3768: '&symb='.$symb.
3769: '&student='.$uname.
3770: '&userdom='.$udom.'"'.
3771: $target.'>'.$text.'</a>';
1.242 albertel 3772: }
3773: ##############################################
3774:
3775: =pod
3776:
3777: =item * &pgrdlink()
3778:
3779: Inputs: $text $uname $udom $symb $target
3780:
3781: Returns: A link to grades.pm such as to see the PGRD view of a student
3782:
3783: =cut
3784:
3785: ###############################################
3786: sub pgrdlink {
3787: my $link=&submlink(@_);
3788: $link=~s/(&command=submission)/$1&showgrading=yes/;
3789: return $link;
3790: }
3791: ##############################################
3792:
3793: =pod
3794:
3795: =item * &pprmlink()
3796:
3797: Inputs: $text $uname $udom $symb $target
3798:
3799: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3800: student and a specific resource
1.242 albertel 3801:
3802: =cut
3803:
3804: ###############################################
3805: sub pprmlink {
3806: my ($text,$uname,$udom,$symb,$target)=@_;
3807: if (!($uname && $udom)) {
3808: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3809: &Apache::lonnet::whichuser($symb);
1.242 albertel 3810: if (!$symb) { $symb=$cursymb; }
3811: }
1.254 matthew 3812: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3813: $symb=&escape($symb);
1.242 albertel 3814: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3815: return '<a href="/adm/parmset?command=set&'.
3816: 'symb='.$symb.'&uname='.$uname.
3817: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3818: }
3819: ##############################################
1.37 matthew 3820:
1.112 bowersj2 3821: =pod
3822:
3823: =back
3824:
3825: =cut
3826:
1.37 matthew 3827: ###############################################
1.51 www 3828:
3829:
3830: sub timehash {
1.687 raeburn 3831: my ($thistime) = @_;
3832: my $timezone = &Apache::lonlocal::gettimezone();
3833: my $dt = DateTime->from_epoch(epoch => $thistime)
3834: ->set_time_zone($timezone);
3835: my $wday = $dt->day_of_week();
3836: if ($wday == 7) { $wday = 0; }
3837: return ( 'second' => $dt->second(),
3838: 'minute' => $dt->minute(),
3839: 'hour' => $dt->hour(),
3840: 'day' => $dt->day_of_month(),
3841: 'month' => $dt->month(),
3842: 'year' => $dt->year(),
3843: 'weekday' => $wday,
3844: 'dayyear' => $dt->day_of_year(),
3845: 'dlsav' => $dt->is_dst() );
1.51 www 3846: }
3847:
1.370 www 3848: sub utc_string {
3849: my ($date)=@_;
1.371 www 3850: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3851: }
3852:
1.51 www 3853: sub maketime {
3854: my %th=@_;
1.687 raeburn 3855: my ($epoch_time,$timezone,$dt);
3856: $timezone = &Apache::lonlocal::gettimezone();
3857: eval {
3858: $dt = DateTime->new( year => $th{'year'},
3859: month => $th{'month'},
3860: day => $th{'day'},
3861: hour => $th{'hour'},
3862: minute => $th{'minute'},
3863: second => $th{'second'},
3864: time_zone => $timezone,
3865: );
3866: };
3867: if (!$@) {
3868: $epoch_time = $dt->epoch;
3869: if ($epoch_time) {
3870: return $epoch_time;
3871: }
3872: }
1.51 www 3873: return POSIX::mktime(
3874: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3875: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3876: }
3877:
3878: #########################################
1.51 www 3879:
3880: sub findallcourses {
1.482 raeburn 3881: my ($roles,$uname,$udom) = @_;
1.355 albertel 3882: my %roles;
3883: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3884: my %courses;
1.51 www 3885: my $now=time;
1.482 raeburn 3886: if (!defined($uname)) {
3887: $uname = $env{'user.name'};
3888: }
3889: if (!defined($udom)) {
3890: $udom = $env{'user.domain'};
3891: }
3892: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.982 raeburn 3893: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3894: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3895: $extra);
1.482 raeburn 3896: if (!%roles) {
3897: %roles = (
3898: cc => 1,
1.907 raeburn 3899: co => 1,
1.482 raeburn 3900: in => 1,
3901: ep => 1,
3902: ta => 1,
3903: cr => 1,
3904: st => 1,
3905: );
3906: }
3907: foreach my $entry (keys(%roleshash)) {
3908: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3909: if ($trole =~ /^cr/) {
3910: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3911: } else {
3912: next if (!exists($roles{$trole}));
3913: }
3914: if ($tend) {
3915: next if ($tend < $now);
3916: }
3917: if ($tstart) {
3918: next if ($tstart > $now);
3919: }
3920: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3921: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3922: if ($secpart eq '') {
3923: ($cnum,$role) = split(/_/,$cnumpart);
3924: $sec = 'none';
3925: $realsec = '';
3926: } else {
3927: $cnum = $cnumpart;
3928: ($sec,$role) = split(/_/,$secpart);
3929: $realsec = $sec;
1.490 raeburn 3930: }
1.482 raeburn 3931: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3932: }
3933: } else {
3934: foreach my $key (keys(%env)) {
1.483 albertel 3935: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3936: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3937: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3938: next if ($role eq 'ca' || $role eq 'aa');
3939: next if (%roles && !exists($roles{$role}));
3940: my ($starttime,$endtime)=split(/\./,$env{$key});
3941: my $active=1;
3942: if ($starttime) {
3943: if ($now<$starttime) { $active=0; }
3944: }
3945: if ($endtime) {
3946: if ($now>$endtime) { $active=0; }
3947: }
3948: if ($active) {
3949: if ($sec eq '') {
3950: $sec = 'none';
3951: }
3952: $courses{$cdom.'_'.$cnum}{$sec} =
3953: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3954: }
3955: }
1.51 www 3956: }
3957: }
1.474 raeburn 3958: return %courses;
1.51 www 3959: }
1.37 matthew 3960:
1.54 www 3961: ###############################################
1.474 raeburn 3962:
3963: sub blockcheck {
1.482 raeburn 3964: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3965:
3966: if (!defined($udom)) {
3967: $udom = $env{'user.domain'};
3968: }
3969: if (!defined($uname)) {
3970: $uname = $env{'user.name'};
3971: }
3972:
3973: # If uname and udom are for a course, check for blocks in the course.
3974:
3975: if (&Apache::lonnet::is_course($udom,$uname)) {
3976: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3977: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3978: return ($startblock,$endblock);
3979: }
1.474 raeburn 3980:
1.502 raeburn 3981: my $startblock = 0;
3982: my $endblock = 0;
1.482 raeburn 3983: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3984:
1.490 raeburn 3985: # If uname is for a user, and activity is course-specific, i.e.,
3986: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3987:
1.490 raeburn 3988: if (($activity eq 'boards' || $activity eq 'chat' ||
3989: $activity eq 'groups') && ($env{'request.course.id'})) {
3990: foreach my $key (keys(%live_courses)) {
3991: if ($key ne $env{'request.course.id'}) {
3992: delete($live_courses{$key});
3993: }
3994: }
3995: }
3996:
3997: my $otheruser = 0;
3998: my %own_courses;
3999: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4000: # Resource belongs to user other than current user.
4001: $otheruser = 1;
4002: # Gather courses for current user
4003: %own_courses =
4004: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4005: }
4006:
4007: # Gather active course roles - course coordinator, instructor,
4008: # exam proctor, ta, student, or custom role.
1.474 raeburn 4009:
4010: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4011: my ($cdom,$cnum);
4012: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4013: $cdom = $env{'course.'.$course.'.domain'};
4014: $cnum = $env{'course.'.$course.'.num'};
4015: } else {
1.490 raeburn 4016: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4017: }
4018: my $no_ownblock = 0;
4019: my $no_userblock = 0;
1.533 raeburn 4020: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4021: # Check if current user has 'evb' priv for this
4022: if (defined($own_courses{$course})) {
4023: foreach my $sec (keys(%{$own_courses{$course}})) {
4024: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4025: if ($sec ne 'none') {
4026: $checkrole .= '/'.$sec;
4027: }
4028: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4029: $no_ownblock = 1;
4030: last;
4031: }
4032: }
4033: }
4034: # if they have 'evb' priv and are currently not playing student
4035: next if (($no_ownblock) &&
4036: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4037: }
1.474 raeburn 4038: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4039: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4040: if ($sec ne 'none') {
1.482 raeburn 4041: $checkrole .= '/'.$sec;
1.474 raeburn 4042: }
1.490 raeburn 4043: if ($otheruser) {
4044: # Resource belongs to user other than current user.
4045: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 4046: my ($trole,$tdom,$tnum,$tsec);
4047: my $entry = $live_courses{$course}{$sec};
4048: if ($entry =~ /^cr/) {
4049: ($trole,$tdom,$tnum,$tsec) =
4050: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4051: } else {
4052: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4053: }
4054: my ($spec,$area,$trest,%allroles,%userroles);
4055: $area = '/'.$tdom.'/'.$tnum;
4056: $trest = $tnum;
4057: if ($tsec ne '') {
4058: $area .= '/'.$tsec;
4059: $trest .= '/'.$tsec;
4060: }
4061: $spec = $trole.'.'.$area;
4062: if ($trole =~ /^cr/) {
4063: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4064: $tdom,$spec,$trest,$area);
4065: } else {
4066: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4067: $tdom,$spec,$trest,$area);
4068: }
4069: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4070: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4071: if ($1) {
4072: $no_userblock = 1;
4073: last;
4074: }
4075: }
1.490 raeburn 4076: } else {
4077: # Resource belongs to current user
4078: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4079: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4080: $no_ownblock = 1;
4081: last;
4082: }
1.474 raeburn 4083: }
4084: }
4085: # if they have the evb priv and are currently not playing student
1.482 raeburn 4086: next if (($no_ownblock) &&
1.491 albertel 4087: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4088: next if ($no_userblock);
1.474 raeburn 4089:
1.866 kalberla 4090: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4091: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4092:
4093: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4094: if (($start != 0) &&
4095: (($startblock == 0) || ($startblock > $start))) {
4096: $startblock = $start;
4097: }
4098: if (($end != 0) &&
4099: (($endblock == 0) || ($endblock < $end))) {
4100: $endblock = $end;
4101: }
1.490 raeburn 4102: }
4103: return ($startblock,$endblock);
4104: }
4105:
4106: sub get_blocks {
4107: my ($setters,$activity,$cdom,$cnum) = @_;
4108: my $startblock = 0;
4109: my $endblock = 0;
4110: my $course = $cdom.'_'.$cnum;
4111: $setters->{$course} = {};
4112: $setters->{$course}{'staff'} = [];
4113: $setters->{$course}{'times'} = [];
4114: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4115: foreach my $record (keys(%records)) {
4116: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4117: if ($start <= time && $end >= time) {
4118: my ($staff_name,$staff_dom,$title,$blocks) =
4119: &parse_block_record($records{$record});
4120: if ($blocks->{$activity} eq 'on') {
4121: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4122: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4123: if ( ($startblock == 0) || ($startblock > $start) ) {
4124: $startblock = $start;
1.490 raeburn 4125: }
1.491 albertel 4126: if ( ($endblock == 0) || ($endblock < $end) ) {
4127: $endblock = $end;
1.474 raeburn 4128: }
4129: }
4130: }
4131: }
4132: return ($startblock,$endblock);
4133: }
4134:
4135: sub parse_block_record {
4136: my ($record) = @_;
4137: my ($setuname,$setudom,$title,$blocks);
4138: if (ref($record) eq 'HASH') {
4139: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4140: $title = &unescape($record->{'event'});
4141: $blocks = $record->{'blocks'};
4142: } else {
4143: my @data = split(/:/,$record,3);
4144: if (scalar(@data) eq 2) {
4145: $title = $data[1];
4146: ($setuname,$setudom) = split(/@/,$data[0]);
4147: } else {
4148: ($setuname,$setudom,$title) = @data;
4149: }
4150: $blocks = { 'com' => 'on' };
4151: }
4152: return ($setuname,$setudom,$title,$blocks);
4153: }
4154:
1.854 kalberla 4155: sub blocking_status {
4156: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4157: my %setters;
1.890 droeschl 4158:
4159: # check for active blocking
1.867 kalberla 4160: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4161:
1.890 droeschl 4162: my $blocked = $startblock && $endblock ? 1 : 0;
4163:
4164: # caller just wants to know whether a block is active
4165: if (!wantarray) { return $blocked; }
4166:
4167: # build a link to a popup window containing the details
4168: my $querystring = "?activity=$activity";
4169: # $uname and $udom decide whose portfolio the user is trying to look at
4170: $querystring .= "&udom=$udom" if $udom;
4171: $querystring .= "&uname=$uname" if $uname;
4172:
4173: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4174: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4175: var options = "width=" + w + ",height=" + h + ",";
4176: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4177: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4178: var newWin = window.open(url, wdwName, options);
4179: newWin.focus();
4180: }
1.890 droeschl 4181: END_MYBLOCK
1.854 kalberla 4182:
1.890 droeschl 4183: $output = Apache::lonhtmlcommon::scripttag($output);
4184:
1.854 kalberla 4185: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4186: my $text = mt('Communication Blocked');
4187:
1.867 kalberla 4188: $output .= <<"END_BLOCK";
4189: <div class='LC_comblock'>
1.869 kalberla 4190: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4191: title='$text'>
4192: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4193: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4194: title='$text'>$text</a>
1.867 kalberla 4195: </div>
4196:
4197: END_BLOCK
1.474 raeburn 4198:
1.854 kalberla 4199: return ($blocked, $output);
4200: }
1.490 raeburn 4201:
1.60 matthew 4202: ###############################################
4203:
1.682 raeburn 4204: sub check_ip_acc {
4205: my ($acc)=@_;
4206: &Apache::lonxml::debug("acc is $acc");
4207: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4208: return 1;
4209: }
4210: my $allowed=0;
4211: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4212:
4213: my $name;
4214: foreach my $pattern (split(',',$acc)) {
4215: $pattern =~ s/^\s*//;
4216: $pattern =~ s/\s*$//;
4217: if ($pattern =~ /\*$/) {
4218: #35.8.*
4219: $pattern=~s/\*//;
4220: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4221: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4222: #35.8.3.[34-56]
4223: my $low=$2;
4224: my $high=$3;
4225: $pattern=$1;
4226: if ($ip =~ /^\Q$pattern\E/) {
4227: my $last=(split(/\./,$ip))[3];
4228: if ($last <=$high && $last >=$low) { $allowed=1; }
4229: }
4230: } elsif ($pattern =~ /^\*/) {
4231: #*.msu.edu
4232: $pattern=~s/\*//;
4233: if (!defined($name)) {
4234: use Socket;
4235: my $netaddr=inet_aton($ip);
4236: ($name)=gethostbyaddr($netaddr,AF_INET);
4237: }
4238: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4239: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4240: #127.0.0.1
4241: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4242: } else {
4243: #some.name.com
4244: if (!defined($name)) {
4245: use Socket;
4246: my $netaddr=inet_aton($ip);
4247: ($name)=gethostbyaddr($netaddr,AF_INET);
4248: }
4249: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4250: }
4251: if ($allowed) { last; }
4252: }
4253: return $allowed;
4254: }
4255:
4256: ###############################################
4257:
1.60 matthew 4258: =pod
4259:
1.112 bowersj2 4260: =head1 Domain Template Functions
4261:
4262: =over 4
4263:
4264: =item * &determinedomain()
1.60 matthew 4265:
4266: Inputs: $domain (usually will be undef)
4267:
1.63 www 4268: Returns: Determines which domain should be used for designs
1.60 matthew 4269:
4270: =cut
1.54 www 4271:
1.60 matthew 4272: ###############################################
1.63 www 4273: sub determinedomain {
4274: my $domain=shift;
1.531 albertel 4275: if (! $domain) {
1.60 matthew 4276: # Determine domain if we have not been given one
1.893 raeburn 4277: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4278: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4279: if ($env{'request.role.domain'}) {
4280: $domain=$env{'request.role.domain'};
1.60 matthew 4281: }
4282: }
1.63 www 4283: return $domain;
4284: }
4285: ###############################################
1.517 raeburn 4286:
1.518 albertel 4287: sub devalidate_domconfig_cache {
4288: my ($udom)=@_;
4289: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4290: }
4291:
4292: # ---------------------- Get domain configuration for a domain
4293: sub get_domainconf {
4294: my ($udom) = @_;
4295: my $cachetime=1800;
4296: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4297: if (defined($cached)) { return %{$result}; }
4298:
4299: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4300: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4301: my (%designhash,%legacy);
1.518 albertel 4302: if (keys(%domconfig) > 0) {
4303: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4304: if (keys(%{$domconfig{'login'}})) {
4305: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4306: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4307: if ($key eq 'loginvia') {
4308: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4309: my @ids = &Apache::lonnet::current_machine_ids();
4310: foreach my $hostname (@ids) {
1.948 raeburn 4311: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4312: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4313: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4314: $designhash{$udom.'.login.loginvia'} = $server;
4315: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4316:
4317: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4318: } else {
4319: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4320: }
4321: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4322: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4323: }
1.946 raeburn 4324: }
4325: }
4326: }
4327: }
4328: } else {
4329: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4330: $designhash{$udom.'.login.'.$key.'_'.$img} =
4331: $domconfig{'login'}{$key}{$img};
4332: }
1.699 raeburn 4333: }
4334: } else {
4335: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4336: }
1.632 raeburn 4337: }
4338: } else {
4339: $legacy{'login'} = 1;
1.518 albertel 4340: }
1.632 raeburn 4341: } else {
4342: $legacy{'login'} = 1;
1.518 albertel 4343: }
4344: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4345: if (keys(%{$domconfig{'rolecolors'}})) {
4346: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4347: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4348: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4349: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4350: }
1.518 albertel 4351: }
4352: }
1.632 raeburn 4353: } else {
4354: $legacy{'rolecolors'} = 1;
1.518 albertel 4355: }
1.632 raeburn 4356: } else {
4357: $legacy{'rolecolors'} = 1;
1.518 albertel 4358: }
1.948 raeburn 4359: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4360: if ($domconfig{'autoenroll'}{'co-owners'}) {
4361: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4362: }
4363: }
1.632 raeburn 4364: if (keys(%legacy) > 0) {
4365: my %legacyhash = &get_legacy_domconf($udom);
4366: foreach my $item (keys(%legacyhash)) {
4367: if ($item =~ /^\Q$udom\E\.login/) {
4368: if ($legacy{'login'}) {
4369: $designhash{$item} = $legacyhash{$item};
4370: }
4371: } else {
4372: if ($legacy{'rolecolors'}) {
4373: $designhash{$item} = $legacyhash{$item};
4374: }
1.518 albertel 4375: }
4376: }
4377: }
1.632 raeburn 4378: } else {
4379: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4380: }
4381: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4382: $cachetime);
4383: return %designhash;
4384: }
4385:
1.632 raeburn 4386: sub get_legacy_domconf {
4387: my ($udom) = @_;
4388: my %legacyhash;
4389: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4390: my $designfile = $designdir.'/'.$udom.'.tab';
4391: if (-e $designfile) {
4392: if ( open (my $fh,"<$designfile") ) {
4393: while (my $line = <$fh>) {
4394: next if ($line =~ /^\#/);
4395: chomp($line);
4396: my ($key,$val)=(split(/\=/,$line));
4397: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4398: }
4399: close($fh);
4400: }
4401: }
4402: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4403: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4404: }
4405: return %legacyhash;
4406: }
4407:
1.63 www 4408: =pod
4409:
1.112 bowersj2 4410: =item * &domainlogo()
1.63 www 4411:
4412: Inputs: $domain (usually will be undef)
4413:
4414: Returns: A link to a domain logo, if the domain logo exists.
4415: If the domain logo does not exist, a description of the domain.
4416:
4417: =cut
1.112 bowersj2 4418:
1.63 www 4419: ###############################################
4420: sub domainlogo {
1.517 raeburn 4421: my $domain = &determinedomain(shift);
1.518 albertel 4422: my %designhash = &get_domainconf($domain);
1.517 raeburn 4423: # See if there is a logo
4424: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4425: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4426: if ($imgsrc =~ m{^/(adm|res)/}) {
4427: if ($imgsrc =~ m{^/res/}) {
4428: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4429: &Apache::lonnet::repcopy($local_name);
4430: }
4431: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4432: }
4433: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4434: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4435: return &Apache::lonnet::domain($domain,'description');
1.59 www 4436: } else {
1.60 matthew 4437: return '';
1.59 www 4438: }
4439: }
1.63 www 4440: ##############################################
4441:
4442: =pod
4443:
1.112 bowersj2 4444: =item * &designparm()
1.63 www 4445:
4446: Inputs: $which parameter; $domain (usually will be undef)
4447:
4448: Returns: value of designparamter $which
4449:
4450: =cut
1.112 bowersj2 4451:
1.397 albertel 4452:
1.400 albertel 4453: ##############################################
1.397 albertel 4454: sub designparm {
4455: my ($which,$domain)=@_;
4456: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4457: return $env{'environment.color.'.$which};
1.96 www 4458: }
1.63 www 4459: $domain=&determinedomain($domain);
1.518 albertel 4460: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4461: my $output;
1.517 raeburn 4462: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4463: $output = $domdesign{$domain.'.'.$which};
1.63 www 4464: } else {
1.520 raeburn 4465: $output = $defaultdesign{$which};
4466: }
4467: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4468: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4469: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4470: if ($output =~ m{^/res/}) {
4471: my $local_name = &Apache::lonnet::filelocation('',$output);
4472: &Apache::lonnet::repcopy($local_name);
4473: }
1.520 raeburn 4474: $output = &lonhttpdurl($output);
4475: }
1.63 www 4476: }
1.520 raeburn 4477: return $output;
1.63 www 4478: }
1.59 www 4479:
1.822 bisitz 4480: ##############################################
4481: =pod
4482:
1.832 bisitz 4483: =item * &authorspace()
4484:
4485: Inputs: ./.
4486:
4487: Returns: Path to the Construction Space of the current user's
4488: accessed author space
4489: The author space will be that of the current user
4490: when accessing the own author space
4491: and that of the co-author/assistent co-author
4492: when accessing the co-author's/assistent co-author's
4493: space
4494:
4495: =cut
4496:
4497: sub authorspace {
4498: my $caname = '';
4499: if ($env{'request.role'} =~ /^ca|^aa/) {
4500: (undef,$caname) =
4501: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4502: } else {
4503: $caname = $env{'user.name'};
4504: }
4505: return '/priv/'.$caname.'/';
4506: }
4507:
4508: ##############################################
4509: =pod
4510:
1.822 bisitz 4511: =item * &head_subbox()
4512:
4513: Inputs: $content (contains HTML code with page functions, etc.)
4514:
4515: Returns: HTML div with $content
4516: To be included in page header
4517:
4518: =cut
4519:
4520: sub head_subbox {
4521: my ($content)=@_;
4522: my $output =
1.993 raeburn 4523: '<div class="LC_head_subbox">'
1.822 bisitz 4524: .$content
4525: .'</div>'
4526: }
4527:
4528: ##############################################
4529: =pod
4530:
4531: =item * &CSTR_pageheader()
4532:
4533: Inputs: ./.
4534:
4535: Returns: HTML div with CSTR path and recent box
4536: To be included on Construction Space pages
4537:
4538: =cut
4539:
4540: sub CSTR_pageheader {
4541: # this is for resources; directories have customtitle, and crumbs
4542: # and select recent are created in lonpubdir.pm
4543: my ($uname,$thisdisfn)=
4544: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4545: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4546: $formaction=~s/\/+/\//g;
4547:
4548: my $parentpath = '';
4549: my $lastitem = '';
4550: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4551: $parentpath = $1;
4552: $lastitem = $2;
4553: } else {
4554: $lastitem = $thisdisfn;
4555: }
1.921 bisitz 4556:
4557: my $output =
1.822 bisitz 4558: '<div>'
4559: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4560: .'<b>'.&mt('Construction Space:').'</b> '
4561: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4562: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4563: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4564:
4565: if ($lastitem) {
4566: $output .=
4567: '<span class="LC_filename">'
4568: .$lastitem
4569: .'</span>';
4570: }
4571: $output .=
4572: '<br />'
1.822 bisitz 4573: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4574: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4575: .'</form>'
4576: .&Apache::lonmenu::constspaceform()
4577: .'</div>';
1.921 bisitz 4578:
4579: return $output;
1.822 bisitz 4580: }
4581:
1.60 matthew 4582: ###############################################
4583: ###############################################
4584:
4585: =pod
4586:
1.112 bowersj2 4587: =back
4588:
1.549 albertel 4589: =head1 HTML Helpers
1.112 bowersj2 4590:
4591: =over 4
4592:
4593: =item * &bodytag()
1.60 matthew 4594:
4595: Returns a uniform header for LON-CAPA web pages.
4596:
4597: Inputs:
4598:
1.112 bowersj2 4599: =over 4
4600:
4601: =item * $title, A title to be displayed on the page.
4602:
4603: =item * $function, the current role (can be undef).
4604:
4605: =item * $addentries, extra parameters for the <body> tag.
4606:
4607: =item * $bodyonly, if defined, only return the <body> tag.
4608:
4609: =item * $domain, if defined, force a given domain.
4610:
4611: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4612: text interface only)
1.60 matthew 4613:
1.814 bisitz 4614: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4615: navigational links
1.317 albertel 4616:
1.338 albertel 4617: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4618:
1.460 albertel 4619: =item * $args, optional argument valid values are
4620: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4621: inherit_jsmath -> when creating popup window in a page,
4622: should it have jsmath forced on by the
4623: current page
1.460 albertel 4624:
1.112 bowersj2 4625: =back
4626:
1.60 matthew 4627: Returns: A uniform header for LON-CAPA web pages.
4628: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4629: If $bodyonly is undef or zero, an html string containing a <body> tag and
4630: other decorations will be returned.
4631:
4632: =cut
4633:
1.54 www 4634: sub bodytag {
1.831 bisitz 4635: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962 droeschl 4636: $no_nav_bar,$bgcolor,$args)=@_;
1.339 albertel 4637:
1.954 raeburn 4638: my $public;
4639: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4640: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4641: $public = 1;
4642: }
1.460 albertel 4643: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4644:
1.183 matthew 4645: $function = &get_users_function() if (!$function);
1.339 albertel 4646: my $img = &designparm($function.'.img',$domain);
4647: my $font = &designparm($function.'.font',$domain);
4648: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4649:
1.803 bisitz 4650: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4651: 'bgcolor' => $pgbg,
1.339 albertel 4652: 'text' => $font,
4653: 'alink' => &designparm($function.'.alink',$domain),
4654: 'vlink' => &designparm($function.'.vlink',$domain),
4655: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4656: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4657:
1.63 www 4658: # role and realm
1.378 raeburn 4659: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4660: if ($role eq 'ca') {
1.479 albertel 4661: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4662: $realm = &plainname($rname,$rdom);
1.378 raeburn 4663: }
1.55 www 4664: # realm
1.258 albertel 4665: if ($env{'request.course.id'}) {
1.378 raeburn 4666: if ($env{'request.role'} !~ /^cr/) {
4667: $role = &Apache::lonnet::plaintext($role,&course_type());
4668: }
1.898 raeburn 4669: if ($env{'request.course.sec'}) {
4670: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4671: }
1.359 albertel 4672: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4673: } else {
4674: $role = &Apache::lonnet::plaintext($role);
1.54 www 4675: }
1.433 albertel 4676:
1.359 albertel 4677: if (!$realm) { $realm=' '; }
1.330 albertel 4678:
1.438 albertel 4679: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4680:
1.101 www 4681: # construct main body tag
1.359 albertel 4682: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4683: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4684:
1.530 albertel 4685: if ($bodyonly) {
1.60 matthew 4686: return $bodytag;
1.798 tempelho 4687: }
1.359 albertel 4688:
1.410 albertel 4689: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 4690: if ($public) {
1.433 albertel 4691: undef($role);
1.434 albertel 4692: } else {
4693: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4694: }
1.359 albertel 4695:
1.762 bisitz 4696: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4697: #
4698: # Extra info if you are the DC
4699: my $dc_info = '';
4700: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4701: $env{'course.'.$env{'request.course.id'}.
4702: '.domain'}.'/'})) {
4703: my $cid = $env{'request.course.id'};
1.917 raeburn 4704: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4705: $dc_info =~ s/\s+$//;
1.359 albertel 4706: }
4707:
1.898 raeburn 4708: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4709: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4710:
1.916 droeschl 4711: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4712: return $bodytag;
4713: }
1.903 droeschl 4714:
4715: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4716:
4717: # if ($env{'request.state'} eq 'construct') {
4718: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4719: # }
4720:
1.359 albertel 4721:
4722:
1.916 droeschl 4723: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4724: if ($dc_info) {
4725: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4726: }
1.916 droeschl 4727: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4728: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4729: return $bodytag;
4730: }
1.894 droeschl 4731:
1.927 raeburn 4732: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4733: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4734: }
1.916 droeschl 4735:
1.903 droeschl 4736: $bodytag .= Apache::lonhtmlcommon::scripttag(
4737: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4738:
1.903 droeschl 4739: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4740:
1.917 raeburn 4741: if ($dc_info) {
4742: $dc_info = &dc_courseid_toggle($dc_info);
4743: }
4744: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4745:
1.903 droeschl 4746: #don't show menus for public users
1.954 raeburn 4747: if (!$public){
1.903 droeschl 4748: $bodytag .= Apache::lonmenu::secondary_menu();
4749: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4750: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4751: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 4752: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 4753: $args->{'bread_crumbs'});
4754: } elsif ($forcereg) {
4755: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4756: }
1.903 droeschl 4757: }else{
4758: # this is to seperate menu from content when there's no secondary
4759: # menu. Especially needed for public accessible ressources.
4760: $bodytag .= '<hr style="clear:both" />';
4761: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4762: }
1.903 droeschl 4763:
1.235 raeburn 4764: return $bodytag;
1.182 matthew 4765: }
4766:
1.917 raeburn 4767: sub dc_courseid_toggle {
4768: my ($dc_info) = @_;
1.980 raeburn 4769: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4770: '<a href="javascript:showCourseID();">'.
4771: &mt('(More ...)').'</a></span>'.
4772: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4773: }
4774:
1.330 albertel 4775: sub make_attr_string {
4776: my ($register,$attr_ref) = @_;
4777:
4778: if ($attr_ref && !ref($attr_ref)) {
4779: die("addentries Must be a hash ref ".
4780: join(':',caller(1))." ".
4781: join(':',caller(0))." ");
4782: }
4783:
4784: if ($register) {
1.339 albertel 4785: my ($on_load,$on_unload);
4786: foreach my $key (keys(%{$attr_ref})) {
4787: if (lc($key) eq 'onload') {
4788: $on_load.=$attr_ref->{$key}.';';
4789: delete($attr_ref->{$key});
4790:
4791: } elsif (lc($key) eq 'onunload') {
4792: $on_unload.=$attr_ref->{$key}.';';
4793: delete($attr_ref->{$key});
4794: }
4795: }
1.953 droeschl 4796: $attr_ref->{'onload'} = $on_load;
4797: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 4798: }
1.339 albertel 4799:
1.330 albertel 4800: my $attr_string;
4801: foreach my $attr (keys(%$attr_ref)) {
4802: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4803: }
4804: return $attr_string;
4805: }
4806:
4807:
1.182 matthew 4808: ###############################################
1.251 albertel 4809: ###############################################
4810:
4811: =pod
4812:
4813: =item * &endbodytag()
4814:
4815: Returns a uniform footer for LON-CAPA web pages.
4816:
1.635 raeburn 4817: Inputs: 1 - optional reference to an args hash
4818: If in the hash, key for noredirectlink has a value which evaluates to true,
4819: a 'Continue' link is not displayed if the page contains an
4820: internal redirect in the <head></head> section,
4821: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4822:
4823: =cut
4824:
4825: sub endbodytag {
1.635 raeburn 4826: my ($args) = @_;
1.251 albertel 4827: my $endbodytag='</body>';
1.269 albertel 4828: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4829: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4830: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4831: $endbodytag=
4832: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4833: &mt('Continue').'</a>'.
4834: $endbodytag;
4835: }
1.315 albertel 4836: }
1.251 albertel 4837: return $endbodytag;
4838: }
4839:
1.352 albertel 4840: =pod
4841:
4842: =item * &standard_css()
4843:
4844: Returns a style sheet
4845:
4846: Inputs: (all optional)
4847: domain -> force to color decorate a page for a specific
4848: domain
4849: function -> force usage of a specific rolish color scheme
4850: bgcolor -> override the default page bgcolor
4851:
4852: =cut
4853:
1.343 albertel 4854: sub standard_css {
1.345 albertel 4855: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4856: $function = &get_users_function() if (!$function);
4857: my $img = &designparm($function.'.img', $domain);
4858: my $tabbg = &designparm($function.'.tabbg', $domain);
4859: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4860: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4861: #second colour for later usage
1.345 albertel 4862: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4863: my $pgbg_or_bgcolor =
4864: $bgcolor ||
1.352 albertel 4865: &designparm($function.'.pgbg', $domain);
1.382 albertel 4866: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4867: my $alink = &designparm($function.'.alink', $domain);
4868: my $vlink = &designparm($function.'.vlink', $domain);
4869: my $link = &designparm($function.'.link', $domain);
4870:
1.602 albertel 4871: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4872: my $mono = 'monospace';
1.850 bisitz 4873: my $data_table_head = $sidebg;
4874: my $data_table_light = '#FAFAFA';
4875: my $data_table_dark = '#F0F0F0';
1.470 banghart 4876: my $data_table_darker = '#CCCCCC';
1.349 albertel 4877: my $data_table_highlight = '#FFFF00';
1.352 albertel 4878: my $mail_new = '#FFBB77';
4879: my $mail_new_hover = '#DD9955';
4880: my $mail_read = '#BBBB77';
4881: my $mail_read_hover = '#999944';
4882: my $mail_replied = '#AAAA88';
4883: my $mail_replied_hover = '#888855';
4884: my $mail_other = '#99BBBB';
4885: my $mail_other_hover = '#669999';
1.391 albertel 4886: my $table_header = '#DDDDDD';
1.489 raeburn 4887: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4888: my $lg_border_color = '#C8C8C8';
1.952 onken 4889: my $button_hover = '#BF2317';
1.392 albertel 4890:
1.608 albertel 4891: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4892: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4893: : '0 3px 0 4px';
1.448 albertel 4894:
1.523 albertel 4895:
1.343 albertel 4896: return <<END;
1.947 droeschl 4897:
4898: /* needed for iframe to allow 100% height in FF */
4899: body, html {
4900: margin: 0;
4901: padding: 0 0.5%;
4902: height: 99%; /* to avoid scrollbars */
4903: }
4904:
1.795 www 4905: body {
1.911 bisitz 4906: font-family: $sans;
4907: line-height:130%;
4908: font-size:0.83em;
4909: color:$font;
1.795 www 4910: }
4911:
1.959 onken 4912: a:focus,
4913: a:focus img {
1.795 www 4914: color: red;
1.911 bisitz 4915: background: yellow;
1.795 www 4916: }
1.698 harmsja 4917:
1.911 bisitz 4918: form, .inline {
4919: display: inline;
1.795 www 4920: }
1.721 harmsja 4921:
1.795 www 4922: .LC_right {
1.911 bisitz 4923: text-align:right;
1.795 www 4924: }
4925:
4926: .LC_middle {
1.911 bisitz 4927: vertical-align:middle;
1.795 www 4928: }
1.721 harmsja 4929:
1.911 bisitz 4930: .LC_400Box {
4931: width:400px;
4932: }
1.721 harmsja 4933:
1.947 droeschl 4934: .LC_iframecontainer {
4935: width: 98%;
4936: margin: 0;
4937: position: fixed;
4938: top: 8.5em;
4939: bottom: 0;
4940: }
4941:
4942: .LC_iframecontainer iframe{
4943: border: none;
4944: width: 100%;
4945: height: 100%;
4946: }
4947:
1.778 bisitz 4948: .LC_filename {
4949: font-family: $mono;
4950: white-space:pre;
1.921 bisitz 4951: font-size: 120%;
1.778 bisitz 4952: }
4953:
4954: .LC_fileicon {
4955: border: none;
4956: height: 1.3em;
4957: vertical-align: text-bottom;
4958: margin-right: 0.3em;
4959: text-decoration:none;
4960: }
4961:
1.1008 www 4962: .LC_setting {
4963: text-decoration:underline;
4964: }
4965:
1.350 albertel 4966: .LC_error {
4967: color: red;
4968: font-size: larger;
4969: }
1.795 www 4970:
1.457 albertel 4971: .LC_warning,
4972: .LC_diff_removed {
1.733 bisitz 4973: color: red;
1.394 albertel 4974: }
1.532 albertel 4975:
4976: .LC_info,
1.457 albertel 4977: .LC_success,
4978: .LC_diff_added {
1.350 albertel 4979: color: green;
4980: }
1.795 www 4981:
1.802 bisitz 4982: div.LC_confirm_box {
4983: background-color: #FAFAFA;
4984: border: 1px solid $lg_border_color;
4985: margin-right: 0;
4986: padding: 5px;
4987: }
4988:
4989: div.LC_confirm_box .LC_error img,
4990: div.LC_confirm_box .LC_success img {
4991: vertical-align: middle;
4992: }
4993:
1.440 albertel 4994: .LC_icon {
1.771 droeschl 4995: border: none;
1.790 droeschl 4996: vertical-align: middle;
1.771 droeschl 4997: }
4998:
1.543 albertel 4999: .LC_docs_spacer {
5000: width: 25px;
5001: height: 1px;
1.771 droeschl 5002: border: none;
1.543 albertel 5003: }
1.346 albertel 5004:
1.532 albertel 5005: .LC_internal_info {
1.735 bisitz 5006: color: #999999;
1.532 albertel 5007: }
5008:
1.794 www 5009: .LC_discussion {
1.911 bisitz 5010: background: $tabbg;
5011: border: 1px solid black;
5012: margin: 2px;
1.794 www 5013: }
5014:
5015: .LC_disc_action_links_bar {
1.911 bisitz 5016: background: $tabbg;
5017: border: none;
5018: margin: 4px;
1.794 www 5019: }
5020:
5021: .LC_disc_action_left {
1.911 bisitz 5022: text-align: left;
1.794 www 5023: }
5024:
5025: .LC_disc_action_right {
1.911 bisitz 5026: text-align: right;
1.794 www 5027: }
5028:
5029: .LC_disc_new_item {
1.911 bisitz 5030: background: white;
5031: border: 2px solid red;
5032: margin: 2px;
1.794 www 5033: }
5034:
5035: .LC_disc_old_item {
1.911 bisitz 5036: background: white;
5037: border: 1px solid black;
5038: margin: 2px;
1.794 www 5039: }
5040:
1.458 albertel 5041: table.LC_pastsubmission {
5042: border: 1px solid black;
5043: margin: 2px;
5044: }
5045:
1.924 bisitz 5046: table#LC_menubuttons {
1.345 albertel 5047: width: 100%;
5048: background: $pgbg;
1.392 albertel 5049: border: 2px;
1.402 albertel 5050: border-collapse: separate;
1.803 bisitz 5051: padding: 0;
1.345 albertel 5052: }
1.392 albertel 5053:
1.801 tempelho 5054: table#LC_title_bar a {
5055: color: $fontmenu;
5056: }
1.836 bisitz 5057:
1.807 droeschl 5058: table#LC_title_bar {
1.819 tempelho 5059: clear: both;
1.836 bisitz 5060: display: none;
1.807 droeschl 5061: }
5062:
1.795 www 5063: table#LC_title_bar,
1.933 droeschl 5064: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5065: table#LC_title_bar.LC_with_remote {
1.359 albertel 5066: width: 100%;
1.392 albertel 5067: border-color: $pgbg;
5068: border-style: solid;
5069: border-width: $border;
1.379 albertel 5070: background: $pgbg;
1.801 tempelho 5071: color: $fontmenu;
1.392 albertel 5072: border-collapse: collapse;
1.803 bisitz 5073: padding: 0;
1.819 tempelho 5074: margin: 0;
1.359 albertel 5075: }
1.795 www 5076:
1.933 droeschl 5077: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5078: margin: 0;
5079: padding: 0;
1.933 droeschl 5080: position: relative;
5081: list-style: none;
1.913 droeschl 5082: }
1.933 droeschl 5083: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5084: display: inline;
5085: }
1.933 droeschl 5086:
5087: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5088: padding: 0;
1.933 droeschl 5089: margin: 0;
5090: float: left;
1.913 droeschl 5091: }
1.933 droeschl 5092: .LC_breadcrumb_tools_tools {
5093: padding: 0;
5094: margin: 0;
1.913 droeschl 5095: float: right;
5096: }
5097:
1.359 albertel 5098: table#LC_title_bar td {
5099: background: $tabbg;
5100: }
1.795 www 5101:
1.911 bisitz 5102: table#LC_menubuttons img {
1.803 bisitz 5103: border: none;
1.346 albertel 5104: }
1.795 www 5105:
1.842 droeschl 5106: .LC_breadcrumbs_component {
1.911 bisitz 5107: float: right;
5108: margin: 0 1em;
1.357 albertel 5109: }
1.842 droeschl 5110: .LC_breadcrumbs_component img {
1.911 bisitz 5111: vertical-align: middle;
1.777 tempelho 5112: }
1.795 www 5113:
1.383 albertel 5114: td.LC_table_cell_checkbox {
5115: text-align: center;
5116: }
1.795 www 5117:
5118: .LC_fontsize_small {
1.911 bisitz 5119: font-size: 70%;
1.705 tempelho 5120: }
5121:
1.844 bisitz 5122: #LC_breadcrumbs {
1.911 bisitz 5123: clear:both;
5124: background: $sidebg;
5125: border-bottom: 1px solid $lg_border_color;
5126: line-height: 2.5em;
1.933 droeschl 5127: overflow: hidden;
1.911 bisitz 5128: margin: 0;
5129: padding: 0;
1.995 raeburn 5130: text-align: left;
1.819 tempelho 5131: }
1.862 bisitz 5132:
1.993 raeburn 5133: .LC_head_subbox {
1.911 bisitz 5134: clear:both;
5135: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5136: border: 1px solid $sidebg;
5137: margin: 0 0 10px 0;
1.966 bisitz 5138: padding: 3px;
1.995 raeburn 5139: text-align: left;
1.822 bisitz 5140: }
5141:
1.795 www 5142: .LC_fontsize_medium {
1.911 bisitz 5143: font-size: 85%;
1.705 tempelho 5144: }
5145:
1.795 www 5146: .LC_fontsize_large {
1.911 bisitz 5147: font-size: 120%;
1.705 tempelho 5148: }
5149:
1.346 albertel 5150: .LC_menubuttons_inline_text {
5151: color: $font;
1.698 harmsja 5152: font-size: 90%;
1.701 harmsja 5153: padding-left:3px;
1.346 albertel 5154: }
5155:
1.934 droeschl 5156: .LC_menubuttons_inline_text img{
5157: vertical-align: middle;
5158: }
5159:
1.951 onken 5160: li.LC_menubuttons_inline_text img,a {
5161: cursor:pointer;
1.1002 droeschl 5162: text-decoration: none;
1.951 onken 5163: }
5164:
1.526 www 5165: .LC_menubuttons_link {
5166: text-decoration: none;
5167: }
1.795 www 5168:
1.522 albertel 5169: .LC_menubuttons_category {
1.521 www 5170: color: $font;
1.526 www 5171: background: $pgbg;
1.521 www 5172: font-size: larger;
5173: font-weight: bold;
5174: }
5175:
1.346 albertel 5176: td.LC_menubuttons_text {
1.911 bisitz 5177: color: $font;
1.346 albertel 5178: }
1.706 harmsja 5179:
1.346 albertel 5180: .LC_current_location {
5181: background: $tabbg;
5182: }
1.795 www 5183:
1.938 bisitz 5184: table.LC_data_table {
1.347 albertel 5185: border: 1px solid #000000;
1.402 albertel 5186: border-collapse: separate;
1.426 albertel 5187: border-spacing: 1px;
1.610 albertel 5188: background: $pgbg;
1.347 albertel 5189: }
1.795 www 5190:
1.422 albertel 5191: .LC_data_table_dense {
5192: font-size: small;
5193: }
1.795 www 5194:
1.507 raeburn 5195: table.LC_nested_outer {
5196: border: 1px solid #000000;
1.589 raeburn 5197: border-collapse: collapse;
1.803 bisitz 5198: border-spacing: 0;
1.507 raeburn 5199: width: 100%;
5200: }
1.795 www 5201:
1.879 raeburn 5202: table.LC_innerpickbox,
1.507 raeburn 5203: table.LC_nested {
1.803 bisitz 5204: border: none;
1.589 raeburn 5205: border-collapse: collapse;
1.803 bisitz 5206: border-spacing: 0;
1.507 raeburn 5207: width: 100%;
5208: }
1.795 www 5209:
1.911 bisitz 5210: table.LC_data_table tr th,
5211: table.LC_calendar tr th,
1.879 raeburn 5212: table.LC_prior_tries tr th,
5213: table.LC_innerpickbox tr th {
1.349 albertel 5214: font-weight: bold;
5215: background-color: $data_table_head;
1.801 tempelho 5216: color:$fontmenu;
1.701 harmsja 5217: font-size:90%;
1.347 albertel 5218: }
1.795 www 5219:
1.879 raeburn 5220: table.LC_innerpickbox tr th,
5221: table.LC_innerpickbox tr td {
5222: vertical-align: top;
5223: }
5224:
1.711 raeburn 5225: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5226: background-color: #CCCCCC;
1.711 raeburn 5227: font-weight: bold;
5228: text-align: left;
5229: }
1.795 www 5230:
1.912 bisitz 5231: table.LC_data_table tr.LC_odd_row > td {
5232: background-color: $data_table_light;
5233: padding: 2px;
5234: vertical-align: top;
5235: }
5236:
1.809 bisitz 5237: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5238: background-color: $data_table_light;
1.912 bisitz 5239: vertical-align: top;
5240: }
5241:
5242: table.LC_data_table tr.LC_even_row > td {
5243: background-color: $data_table_dark;
1.425 albertel 5244: padding: 2px;
1.900 bisitz 5245: vertical-align: top;
1.347 albertel 5246: }
1.795 www 5247:
1.809 bisitz 5248: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5249: background-color: $data_table_dark;
1.900 bisitz 5250: vertical-align: top;
1.347 albertel 5251: }
1.795 www 5252:
1.425 albertel 5253: table.LC_data_table tr.LC_data_table_highlight td {
5254: background-color: $data_table_darker;
5255: }
1.795 www 5256:
1.639 raeburn 5257: table.LC_data_table tr td.LC_leftcol_header {
5258: background-color: $data_table_head;
5259: font-weight: bold;
5260: }
1.795 www 5261:
1.451 albertel 5262: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5263: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5264: font-weight: bold;
5265: font-style: italic;
5266: text-align: center;
5267: padding: 8px;
1.347 albertel 5268: }
1.795 www 5269:
1.940 bisitz 5270: table.LC_data_table tr.LC_empty_row td {
5271: background-color: $sidebg;
5272: }
5273:
5274: table.LC_nested tr.LC_empty_row td {
5275: background-color: #FFFFFF;
5276: }
5277:
1.890 droeschl 5278: table.LC_caption {
5279: }
5280:
1.507 raeburn 5281: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5282: padding: 4ex
5283: }
1.795 www 5284:
1.507 raeburn 5285: table.LC_nested_outer tr th {
5286: font-weight: bold;
1.801 tempelho 5287: color:$fontmenu;
1.507 raeburn 5288: background-color: $data_table_head;
1.701 harmsja 5289: font-size: small;
1.507 raeburn 5290: border-bottom: 1px solid #000000;
5291: }
1.795 www 5292:
1.507 raeburn 5293: table.LC_nested_outer tr td.LC_subheader {
5294: background-color: $data_table_head;
5295: font-weight: bold;
5296: font-size: small;
5297: border-bottom: 1px solid #000000;
5298: text-align: right;
1.451 albertel 5299: }
1.795 www 5300:
1.507 raeburn 5301: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5302: background-color: #CCCCCC;
1.451 albertel 5303: font-weight: bold;
5304: font-size: small;
1.507 raeburn 5305: text-align: center;
5306: }
1.795 www 5307:
1.589 raeburn 5308: table.LC_nested tr.LC_info_row td.LC_left_item,
5309: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5310: text-align: left;
1.451 albertel 5311: }
1.795 www 5312:
1.507 raeburn 5313: table.LC_nested td {
1.735 bisitz 5314: background-color: #FFFFFF;
1.451 albertel 5315: font-size: small;
1.507 raeburn 5316: }
1.795 www 5317:
1.507 raeburn 5318: table.LC_nested_outer tr th.LC_right_item,
5319: table.LC_nested tr.LC_info_row td.LC_right_item,
5320: table.LC_nested tr.LC_odd_row td.LC_right_item,
5321: table.LC_nested tr td.LC_right_item {
1.451 albertel 5322: text-align: right;
5323: }
5324:
1.507 raeburn 5325: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5326: background-color: #EEEEEE;
1.451 albertel 5327: }
5328:
1.473 raeburn 5329: table.LC_createuser {
5330: }
5331:
5332: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5333: font-size: small;
1.473 raeburn 5334: }
5335:
5336: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5337: background-color: #CCCCCC;
1.473 raeburn 5338: font-weight: bold;
5339: text-align: center;
5340: }
5341:
1.349 albertel 5342: table.LC_calendar {
5343: border: 1px solid #000000;
5344: border-collapse: collapse;
1.917 raeburn 5345: width: 98%;
1.349 albertel 5346: }
1.795 www 5347:
1.349 albertel 5348: table.LC_calendar_pickdate {
5349: font-size: xx-small;
5350: }
1.795 www 5351:
1.349 albertel 5352: table.LC_calendar tr td {
5353: border: 1px solid #000000;
5354: vertical-align: top;
1.917 raeburn 5355: width: 14%;
1.349 albertel 5356: }
1.795 www 5357:
1.349 albertel 5358: table.LC_calendar tr td.LC_calendar_day_empty {
5359: background-color: $data_table_dark;
5360: }
1.795 www 5361:
1.779 bisitz 5362: table.LC_calendar tr td.LC_calendar_day_current {
5363: background-color: $data_table_highlight;
1.777 tempelho 5364: }
1.795 www 5365:
1.938 bisitz 5366: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5367: background-color: $mail_new;
5368: }
1.795 www 5369:
1.938 bisitz 5370: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5371: background-color: $mail_new_hover;
5372: }
1.795 www 5373:
1.938 bisitz 5374: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5375: background-color: $mail_read;
5376: }
1.795 www 5377:
1.938 bisitz 5378: /*
5379: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5380: background-color: $mail_read_hover;
5381: }
1.938 bisitz 5382: */
1.795 www 5383:
1.938 bisitz 5384: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5385: background-color: $mail_replied;
5386: }
1.795 www 5387:
1.938 bisitz 5388: /*
5389: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5390: background-color: $mail_replied_hover;
5391: }
1.938 bisitz 5392: */
1.795 www 5393:
1.938 bisitz 5394: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5395: background-color: $mail_other;
5396: }
1.795 www 5397:
1.938 bisitz 5398: /*
5399: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5400: background-color: $mail_other_hover;
5401: }
1.938 bisitz 5402: */
1.494 raeburn 5403:
1.777 tempelho 5404: table.LC_data_table tr > td.LC_browser_file,
5405: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5406: background: #AAEE77;
1.389 albertel 5407: }
1.795 www 5408:
1.777 tempelho 5409: table.LC_data_table tr > td.LC_browser_file_locked,
5410: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5411: background: #FFAA99;
1.387 albertel 5412: }
1.795 www 5413:
1.777 tempelho 5414: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5415: background: #888888;
1.779 bisitz 5416: }
1.795 www 5417:
1.777 tempelho 5418: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5419: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5420: background: #F8F866;
1.777 tempelho 5421: }
1.795 www 5422:
1.696 bisitz 5423: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5424: background: #E0E8FF;
1.387 albertel 5425: }
1.696 bisitz 5426:
1.707 bisitz 5427: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5428: /* background: #77FF77; */
1.707 bisitz 5429: }
1.795 www 5430:
1.707 bisitz 5431: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5432: border-right: 8px solid #FFFF77;
1.707 bisitz 5433: }
1.795 www 5434:
1.707 bisitz 5435: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5436: border-right: 8px solid #FFAA77;
1.707 bisitz 5437: }
1.795 www 5438:
1.707 bisitz 5439: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5440: border-right: 8px solid #FF7777;
1.707 bisitz 5441: }
1.795 www 5442:
1.707 bisitz 5443: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5444: border-right: 8px solid #AAFF77;
1.707 bisitz 5445: }
1.795 www 5446:
1.707 bisitz 5447: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5448: border-right: 8px solid #11CC55;
1.707 bisitz 5449: }
5450:
1.388 albertel 5451: span.LC_current_location {
1.701 harmsja 5452: font-size:larger;
1.388 albertel 5453: background: $pgbg;
5454: }
1.387 albertel 5455:
1.395 albertel 5456: span.LC_parm_menu_item {
5457: font-size: larger;
5458: }
1.795 www 5459:
1.395 albertel 5460: span.LC_parm_scope_all {
5461: color: red;
5462: }
1.795 www 5463:
1.395 albertel 5464: span.LC_parm_scope_folder {
5465: color: green;
5466: }
1.795 www 5467:
1.395 albertel 5468: span.LC_parm_scope_resource {
5469: color: orange;
5470: }
1.795 www 5471:
1.395 albertel 5472: span.LC_parm_part {
5473: color: blue;
5474: }
1.795 www 5475:
1.911 bisitz 5476: span.LC_parm_folder,
5477: span.LC_parm_symb {
1.395 albertel 5478: font-size: x-small;
5479: font-family: $mono;
5480: color: #AAAAAA;
5481: }
5482:
1.977 bisitz 5483: ul.LC_parm_parmlist li {
5484: display: inline-block;
5485: padding: 0.3em 0.8em;
5486: vertical-align: top;
5487: width: 150px;
5488: border-top:1px solid $lg_border_color;
5489: }
5490:
1.795 www 5491: td.LC_parm_overview_level_menu,
5492: td.LC_parm_overview_map_menu,
5493: td.LC_parm_overview_parm_selectors,
5494: td.LC_parm_overview_restrictions {
1.396 albertel 5495: border: 1px solid black;
5496: border-collapse: collapse;
5497: }
1.795 www 5498:
1.396 albertel 5499: table.LC_parm_overview_restrictions td {
5500: border-width: 1px 4px 1px 4px;
5501: border-style: solid;
5502: border-color: $pgbg;
5503: text-align: center;
5504: }
1.795 www 5505:
1.396 albertel 5506: table.LC_parm_overview_restrictions th {
5507: background: $tabbg;
5508: border-width: 1px 4px 1px 4px;
5509: border-style: solid;
5510: border-color: $pgbg;
5511: }
1.795 www 5512:
1.398 albertel 5513: table#LC_helpmenu {
1.803 bisitz 5514: border: none;
1.398 albertel 5515: height: 55px;
1.803 bisitz 5516: border-spacing: 0;
1.398 albertel 5517: }
5518:
5519: table#LC_helpmenu fieldset legend {
5520: font-size: larger;
5521: }
1.795 www 5522:
1.397 albertel 5523: table#LC_helpmenu_links {
5524: width: 100%;
5525: border: 1px solid black;
5526: background: $pgbg;
1.803 bisitz 5527: padding: 0;
1.397 albertel 5528: border-spacing: 1px;
5529: }
1.795 www 5530:
1.397 albertel 5531: table#LC_helpmenu_links tr td {
5532: padding: 1px;
5533: background: $tabbg;
1.399 albertel 5534: text-align: center;
5535: font-weight: bold;
1.397 albertel 5536: }
1.396 albertel 5537:
1.795 www 5538: table#LC_helpmenu_links a:link,
5539: table#LC_helpmenu_links a:visited,
1.397 albertel 5540: table#LC_helpmenu_links a:active {
5541: text-decoration: none;
5542: color: $font;
5543: }
1.795 www 5544:
1.397 albertel 5545: table#LC_helpmenu_links a:hover {
5546: text-decoration: underline;
5547: color: $vlink;
5548: }
1.396 albertel 5549:
1.417 albertel 5550: .LC_chrt_popup_exists {
5551: border: 1px solid #339933;
5552: margin: -1px;
5553: }
1.795 www 5554:
1.417 albertel 5555: .LC_chrt_popup_up {
5556: border: 1px solid yellow;
5557: margin: -1px;
5558: }
1.795 www 5559:
1.417 albertel 5560: .LC_chrt_popup {
5561: border: 1px solid #8888FF;
5562: background: #CCCCFF;
5563: }
1.795 www 5564:
1.421 albertel 5565: table.LC_pick_box {
5566: border-collapse: separate;
5567: background: white;
5568: border: 1px solid black;
5569: border-spacing: 1px;
5570: }
1.795 www 5571:
1.421 albertel 5572: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5573: background: $sidebg;
1.421 albertel 5574: font-weight: bold;
1.900 bisitz 5575: text-align: left;
1.740 bisitz 5576: vertical-align: top;
1.421 albertel 5577: width: 184px;
5578: padding: 8px;
5579: }
1.795 www 5580:
1.579 raeburn 5581: table.LC_pick_box td.LC_pick_box_value {
5582: text-align: left;
5583: padding: 8px;
5584: }
1.795 www 5585:
1.579 raeburn 5586: table.LC_pick_box td.LC_pick_box_select {
5587: text-align: left;
5588: padding: 8px;
5589: }
1.795 www 5590:
1.424 albertel 5591: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5592: padding: 0;
1.421 albertel 5593: height: 1px;
5594: background: black;
5595: }
1.795 www 5596:
1.421 albertel 5597: table.LC_pick_box td.LC_pick_box_submit {
5598: text-align: right;
5599: }
1.795 www 5600:
1.579 raeburn 5601: table.LC_pick_box td.LC_evenrow_value {
5602: text-align: left;
5603: padding: 8px;
5604: background-color: $data_table_light;
5605: }
1.795 www 5606:
1.579 raeburn 5607: table.LC_pick_box td.LC_oddrow_value {
5608: text-align: left;
5609: padding: 8px;
5610: background-color: $data_table_light;
5611: }
1.795 www 5612:
1.579 raeburn 5613: span.LC_helpform_receipt_cat {
5614: font-weight: bold;
5615: }
1.795 www 5616:
1.424 albertel 5617: table.LC_group_priv_box {
5618: background: white;
5619: border: 1px solid black;
5620: border-spacing: 1px;
5621: }
1.795 www 5622:
1.424 albertel 5623: table.LC_group_priv_box td.LC_pick_box_title {
5624: background: $tabbg;
5625: font-weight: bold;
5626: text-align: right;
5627: width: 184px;
5628: }
1.795 www 5629:
1.424 albertel 5630: table.LC_group_priv_box td.LC_groups_fixed {
5631: background: $data_table_light;
5632: text-align: center;
5633: }
1.795 www 5634:
1.424 albertel 5635: table.LC_group_priv_box td.LC_groups_optional {
5636: background: $data_table_dark;
5637: text-align: center;
5638: }
1.795 www 5639:
1.424 albertel 5640: table.LC_group_priv_box td.LC_groups_functionality {
5641: background: $data_table_darker;
5642: text-align: center;
5643: font-weight: bold;
5644: }
1.795 www 5645:
1.424 albertel 5646: table.LC_group_priv td {
5647: text-align: left;
1.803 bisitz 5648: padding: 0;
1.424 albertel 5649: }
5650:
5651: .LC_navbuttons {
5652: margin: 2ex 0ex 2ex 0ex;
5653: }
1.795 www 5654:
1.423 albertel 5655: .LC_topic_bar {
5656: font-weight: bold;
5657: background: $tabbg;
1.918 wenzelju 5658: margin: 1em 0em 1em 2em;
1.805 bisitz 5659: padding: 3px;
1.918 wenzelju 5660: font-size: 1.2em;
1.423 albertel 5661: }
1.795 www 5662:
1.423 albertel 5663: .LC_topic_bar span {
1.918 wenzelju 5664: left: 0.5em;
5665: position: absolute;
1.423 albertel 5666: vertical-align: middle;
1.918 wenzelju 5667: font-size: 1.2em;
1.423 albertel 5668: }
1.795 www 5669:
1.423 albertel 5670: table.LC_course_group_status {
5671: margin: 20px;
5672: }
1.795 www 5673:
1.423 albertel 5674: table.LC_status_selector td {
5675: vertical-align: top;
5676: text-align: center;
1.424 albertel 5677: padding: 4px;
5678: }
1.795 www 5679:
1.599 albertel 5680: div.LC_feedback_link {
1.616 albertel 5681: clear: both;
1.829 kalberla 5682: background: $sidebg;
1.779 bisitz 5683: width: 100%;
1.829 kalberla 5684: padding-bottom: 10px;
5685: border: 1px $tabbg solid;
1.833 kalberla 5686: height: 22px;
5687: line-height: 22px;
5688: padding-top: 5px;
5689: }
5690:
5691: div.LC_feedback_link img {
5692: height: 22px;
1.867 kalberla 5693: vertical-align:middle;
1.829 kalberla 5694: }
5695:
1.911 bisitz 5696: div.LC_feedback_link a {
1.829 kalberla 5697: text-decoration: none;
1.489 raeburn 5698: }
1.795 www 5699:
1.867 kalberla 5700: div.LC_comblock {
1.911 bisitz 5701: display:inline;
1.867 kalberla 5702: color:$font;
5703: font-size:90%;
5704: }
5705:
5706: div.LC_feedback_link div.LC_comblock {
5707: padding-left:5px;
5708: }
5709:
5710: div.LC_feedback_link div.LC_comblock a {
5711: color:$font;
5712: }
5713:
1.489 raeburn 5714: span.LC_feedback_link {
1.858 bisitz 5715: /* background: $feedback_link_bg; */
1.599 albertel 5716: font-size: larger;
5717: }
1.795 www 5718:
1.599 albertel 5719: span.LC_message_link {
1.858 bisitz 5720: /* background: $feedback_link_bg; */
1.599 albertel 5721: font-size: larger;
5722: position: absolute;
5723: right: 1em;
1.489 raeburn 5724: }
1.421 albertel 5725:
1.515 albertel 5726: table.LC_prior_tries {
1.524 albertel 5727: border: 1px solid #000000;
5728: border-collapse: separate;
5729: border-spacing: 1px;
1.515 albertel 5730: }
1.523 albertel 5731:
1.515 albertel 5732: table.LC_prior_tries td {
1.524 albertel 5733: padding: 2px;
1.515 albertel 5734: }
1.523 albertel 5735:
5736: .LC_answer_correct {
1.795 www 5737: background: lightgreen;
5738: color: darkgreen;
5739: padding: 6px;
1.523 albertel 5740: }
1.795 www 5741:
1.523 albertel 5742: .LC_answer_charged_try {
1.797 www 5743: background: #FFAAAA;
1.795 www 5744: color: darkred;
5745: padding: 6px;
1.523 albertel 5746: }
1.795 www 5747:
1.779 bisitz 5748: .LC_answer_not_charged_try,
1.523 albertel 5749: .LC_answer_no_grade,
5750: .LC_answer_late {
1.795 www 5751: background: lightyellow;
1.523 albertel 5752: color: black;
1.795 www 5753: padding: 6px;
1.523 albertel 5754: }
1.795 www 5755:
1.523 albertel 5756: .LC_answer_previous {
1.795 www 5757: background: lightblue;
5758: color: darkblue;
5759: padding: 6px;
1.523 albertel 5760: }
1.795 www 5761:
1.779 bisitz 5762: .LC_answer_no_message {
1.777 tempelho 5763: background: #FFFFFF;
5764: color: black;
1.795 www 5765: padding: 6px;
1.779 bisitz 5766: }
1.795 www 5767:
1.779 bisitz 5768: .LC_answer_unknown {
5769: background: orange;
5770: color: black;
1.795 www 5771: padding: 6px;
1.777 tempelho 5772: }
1.795 www 5773:
1.529 albertel 5774: span.LC_prior_numerical,
5775: span.LC_prior_string,
5776: span.LC_prior_custom,
5777: span.LC_prior_reaction,
5778: span.LC_prior_math {
1.925 bisitz 5779: font-family: $mono;
1.523 albertel 5780: white-space: pre;
5781: }
5782:
1.525 albertel 5783: span.LC_prior_string {
1.925 bisitz 5784: font-family: $mono;
1.525 albertel 5785: white-space: pre;
5786: }
5787:
1.523 albertel 5788: table.LC_prior_option {
5789: width: 100%;
5790: border-collapse: collapse;
5791: }
1.795 www 5792:
1.911 bisitz 5793: table.LC_prior_rank,
1.795 www 5794: table.LC_prior_match {
1.528 albertel 5795: border-collapse: collapse;
5796: }
1.795 www 5797:
1.528 albertel 5798: table.LC_prior_option tr td,
5799: table.LC_prior_rank tr td,
5800: table.LC_prior_match tr td {
1.524 albertel 5801: border: 1px solid #000000;
1.515 albertel 5802: }
5803:
1.855 bisitz 5804: .LC_nobreak {
1.544 albertel 5805: white-space: nowrap;
1.519 raeburn 5806: }
5807:
1.576 raeburn 5808: span.LC_cusr_emph {
5809: font-style: italic;
5810: }
5811:
1.633 raeburn 5812: span.LC_cusr_subheading {
5813: font-weight: normal;
5814: font-size: 85%;
5815: }
5816:
1.861 bisitz 5817: div.LC_docs_entry_move {
1.859 bisitz 5818: border: 1px solid #BBBBBB;
1.545 albertel 5819: background: #DDDDDD;
1.861 bisitz 5820: width: 22px;
1.859 bisitz 5821: padding: 1px;
5822: margin: 0;
1.545 albertel 5823: }
5824:
1.861 bisitz 5825: table.LC_data_table tr > td.LC_docs_entry_commands,
5826: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5827: background: #DDDDDD;
5828: font-size: x-small;
5829: }
1.795 www 5830:
1.861 bisitz 5831: .LC_docs_entry_parameter {
5832: white-space: nowrap;
5833: }
5834:
1.544 albertel 5835: .LC_docs_copy {
1.545 albertel 5836: color: #000099;
1.544 albertel 5837: }
1.795 www 5838:
1.544 albertel 5839: .LC_docs_cut {
1.545 albertel 5840: color: #550044;
1.544 albertel 5841: }
1.795 www 5842:
1.544 albertel 5843: .LC_docs_rename {
1.545 albertel 5844: color: #009900;
1.544 albertel 5845: }
1.795 www 5846:
1.544 albertel 5847: .LC_docs_remove {
1.545 albertel 5848: color: #990000;
5849: }
5850:
1.547 albertel 5851: .LC_docs_reinit_warn,
5852: .LC_docs_ext_edit {
5853: font-size: x-small;
5854: }
5855:
1.545 albertel 5856: table.LC_docs_adddocs td,
5857: table.LC_docs_adddocs th {
5858: border: 1px solid #BBBBBB;
5859: padding: 4px;
5860: background: #DDDDDD;
1.543 albertel 5861: }
5862:
1.584 albertel 5863: table.LC_sty_begin {
5864: background: #BBFFBB;
5865: }
1.795 www 5866:
1.584 albertel 5867: table.LC_sty_end {
5868: background: #FFBBBB;
5869: }
5870:
1.589 raeburn 5871: table.LC_double_column {
1.803 bisitz 5872: border-width: 0;
1.589 raeburn 5873: border-collapse: collapse;
5874: width: 100%;
5875: padding: 2px;
5876: }
5877:
5878: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5879: top: 2px;
1.589 raeburn 5880: left: 2px;
5881: width: 47%;
5882: vertical-align: top;
5883: }
5884:
5885: table.LC_double_column tr td.LC_right_col {
5886: top: 2px;
1.779 bisitz 5887: right: 2px;
1.589 raeburn 5888: width: 47%;
5889: vertical-align: top;
5890: }
5891:
1.591 raeburn 5892: div.LC_left_float {
5893: float: left;
5894: padding-right: 5%;
1.597 albertel 5895: padding-bottom: 4px;
1.591 raeburn 5896: }
5897:
5898: div.LC_clear_float_header {
1.597 albertel 5899: padding-bottom: 2px;
1.591 raeburn 5900: }
5901:
5902: div.LC_clear_float_footer {
1.597 albertel 5903: padding-top: 10px;
1.591 raeburn 5904: clear: both;
5905: }
5906:
1.597 albertel 5907: div.LC_grade_show_user {
1.941 bisitz 5908: /* border-left: 5px solid $sidebg; */
5909: border-top: 5px solid #000000;
5910: margin: 50px 0 0 0;
1.936 bisitz 5911: padding: 15px 0 5px 10px;
1.597 albertel 5912: }
1.795 www 5913:
1.936 bisitz 5914: div.LC_grade_show_user_odd_row {
1.941 bisitz 5915: /* border-left: 5px solid #000000; */
5916: }
5917:
5918: div.LC_grade_show_user div.LC_Box {
5919: margin-right: 50px;
1.597 albertel 5920: }
5921:
5922: div.LC_grade_submissions,
5923: div.LC_grade_message_center,
1.936 bisitz 5924: div.LC_grade_info_links {
1.597 albertel 5925: margin: 5px;
5926: width: 99%;
5927: background: #FFFFFF;
5928: }
1.795 www 5929:
1.597 albertel 5930: div.LC_grade_submissions_header,
1.936 bisitz 5931: div.LC_grade_message_center_header {
1.705 tempelho 5932: font-weight: bold;
5933: font-size: large;
1.597 albertel 5934: }
1.795 www 5935:
1.597 albertel 5936: div.LC_grade_submissions_body,
1.936 bisitz 5937: div.LC_grade_message_center_body {
1.597 albertel 5938: border: 1px solid black;
5939: width: 99%;
5940: background: #FFFFFF;
5941: }
1.795 www 5942:
1.613 albertel 5943: table.LC_scantron_action {
5944: width: 100%;
5945: }
1.795 www 5946:
1.613 albertel 5947: table.LC_scantron_action tr th {
1.698 harmsja 5948: font-weight:bold;
5949: font-style:normal;
1.613 albertel 5950: }
1.795 www 5951:
1.779 bisitz 5952: .LC_edit_problem_header,
1.614 albertel 5953: div.LC_edit_problem_footer {
1.705 tempelho 5954: font-weight: normal;
5955: font-size: medium;
1.602 albertel 5956: margin: 2px;
1.600 albertel 5957: }
1.795 www 5958:
1.600 albertel 5959: div.LC_edit_problem_header,
1.602 albertel 5960: div.LC_edit_problem_header div,
1.614 albertel 5961: div.LC_edit_problem_footer,
5962: div.LC_edit_problem_footer div,
1.602 albertel 5963: div.LC_edit_problem_editxml_header,
5964: div.LC_edit_problem_editxml_header div {
1.600 albertel 5965: margin-top: 5px;
5966: }
1.795 www 5967:
1.600 albertel 5968: div.LC_edit_problem_header_title {
1.705 tempelho 5969: font-weight: bold;
5970: font-size: larger;
1.602 albertel 5971: background: $tabbg;
5972: padding: 3px;
5973: }
1.795 www 5974:
1.602 albertel 5975: table.LC_edit_problem_header_title {
5976: width: 100%;
1.600 albertel 5977: background: $tabbg;
1.602 albertel 5978: }
5979:
5980: div.LC_edit_problem_discards {
5981: float: left;
5982: padding-bottom: 5px;
5983: }
1.795 www 5984:
1.602 albertel 5985: div.LC_edit_problem_saves {
5986: float: right;
5987: padding-bottom: 5px;
1.600 albertel 5988: }
1.795 www 5989:
1.911 bisitz 5990: img.stift {
1.803 bisitz 5991: border-width: 0;
5992: vertical-align: middle;
1.677 riegler 5993: }
1.680 riegler 5994:
1.923 bisitz 5995: table td.LC_mainmenu_col_fieldset {
1.680 riegler 5996: vertical-align: top;
1.777 tempelho 5997: }
1.795 www 5998:
1.716 raeburn 5999: div.LC_createcourse {
1.911 bisitz 6000: margin: 10px 10px 10px 10px;
1.716 raeburn 6001: }
6002:
1.917 raeburn 6003: .LC_dccid {
6004: margin: 0.2em 0 0 0;
6005: padding: 0;
6006: font-size: 90%;
6007: display:none;
6008: }
6009:
1.698 harmsja 6010: a:hover,
1.897 wenzelju 6011: ol.LC_primary_menu a:hover,
1.721 harmsja 6012: ol#LC_MenuBreadcrumbs a:hover,
6013: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6014: ul#LC_secondary_menu a:hover,
1.721 harmsja 6015: .LC_FormSectionClearButton input:hover
1.795 www 6016: ul.LC_TabContent li:hover a {
1.952 onken 6017: color:$button_hover;
1.911 bisitz 6018: text-decoration:none;
1.693 droeschl 6019: }
6020:
1.779 bisitz 6021: h1 {
1.911 bisitz 6022: padding: 0;
6023: line-height:130%;
1.693 droeschl 6024: }
1.698 harmsja 6025:
1.911 bisitz 6026: h2,
6027: h3,
6028: h4,
6029: h5,
6030: h6 {
6031: margin: 5px 0 5px 0;
6032: padding: 0;
6033: line-height:130%;
1.693 droeschl 6034: }
1.795 www 6035:
6036: .LC_hcell {
1.911 bisitz 6037: padding:3px 15px 3px 15px;
6038: margin: 0;
6039: background-color:$tabbg;
6040: color:$fontmenu;
6041: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6042: }
1.795 www 6043:
1.840 bisitz 6044: .LC_Box > .LC_hcell {
1.911 bisitz 6045: margin: 0 -10px 10px -10px;
1.835 bisitz 6046: }
6047:
1.721 harmsja 6048: .LC_noBorder {
1.911 bisitz 6049: border: 0;
1.698 harmsja 6050: }
1.693 droeschl 6051:
1.721 harmsja 6052: .LC_FormSectionClearButton input {
1.911 bisitz 6053: background-color:transparent;
6054: border: none;
6055: cursor:pointer;
6056: text-decoration:underline;
1.693 droeschl 6057: }
1.763 bisitz 6058:
6059: .LC_help_open_topic {
1.911 bisitz 6060: color: #FFFFFF;
6061: background-color: #EEEEFF;
6062: margin: 1px;
6063: padding: 4px;
6064: border: 1px solid #000033;
6065: white-space: nowrap;
6066: /* vertical-align: middle; */
1.759 neumanie 6067: }
1.693 droeschl 6068:
1.911 bisitz 6069: dl,
6070: ul,
6071: div,
6072: fieldset {
6073: margin: 10px 10px 10px 0;
6074: /* overflow: hidden; */
1.693 droeschl 6075: }
1.795 www 6076:
1.838 bisitz 6077: fieldset > legend {
1.911 bisitz 6078: font-weight: bold;
6079: padding: 0 5px 0 5px;
1.838 bisitz 6080: }
6081:
1.813 bisitz 6082: #LC_nav_bar {
1.911 bisitz 6083: float: left;
1.995 raeburn 6084: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6085: margin: 0 0 2px 0;
1.807 droeschl 6086: }
6087:
1.916 droeschl 6088: #LC_realm {
6089: margin: 0.2em 0 0 0;
6090: padding: 0;
6091: font-weight: bold;
6092: text-align: center;
1.995 raeburn 6093: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6094: }
6095:
1.911 bisitz 6096: #LC_nav_bar em {
6097: font-weight: bold;
6098: font-style: normal;
1.807 droeschl 6099: }
6100:
1.897 wenzelju 6101: ol.LC_primary_menu {
1.911 bisitz 6102: float: right;
1.934 droeschl 6103: margin: 0;
1.995 raeburn 6104: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6105: }
6106:
1.852 droeschl 6107: ol#LC_PathBreadcrumbs {
1.911 bisitz 6108: margin: 0;
1.693 droeschl 6109: }
6110:
1.897 wenzelju 6111: ol.LC_primary_menu li {
1.911 bisitz 6112: display: inline;
6113: padding: 5px 5px 0 10px;
6114: vertical-align: top;
1.693 droeschl 6115: }
6116:
1.897 wenzelju 6117: ol.LC_primary_menu li img {
1.911 bisitz 6118: vertical-align: bottom;
1.934 droeschl 6119: height: 1.1em;
1.693 droeschl 6120: }
6121:
1.897 wenzelju 6122: ol.LC_primary_menu a {
1.911 bisitz 6123: color: RGB(80, 80, 80);
6124: text-decoration: none;
1.693 droeschl 6125: }
1.795 www 6126:
1.949 droeschl 6127: ol.LC_primary_menu a.LC_new_message {
6128: font-weight:bold;
6129: color: darkred;
6130: }
6131:
1.975 raeburn 6132: ol.LC_docs_parameters {
6133: margin-left: 0;
6134: padding: 0;
6135: list-style: none;
6136: }
6137:
6138: ol.LC_docs_parameters li {
6139: margin: 0;
6140: padding-right: 20px;
6141: display: inline;
6142: }
6143:
1.976 raeburn 6144: ol.LC_docs_parameters li:before {
6145: content: "\\002022 \\0020";
6146: }
6147:
6148: li.LC_docs_parameters_title {
6149: font-weight: bold;
6150: }
6151:
6152: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6153: content: "";
6154: }
6155:
1.897 wenzelju 6156: ul#LC_secondary_menu {
1.911 bisitz 6157: clear: both;
6158: color: $fontmenu;
6159: background: $tabbg;
6160: list-style: none;
6161: padding: 0;
6162: margin: 0;
6163: width: 100%;
1.995 raeburn 6164: text-align: left;
1.808 droeschl 6165: }
6166:
1.897 wenzelju 6167: ul#LC_secondary_menu li {
1.911 bisitz 6168: font-weight: bold;
6169: line-height: 1.8em;
6170: padding: 0 0.8em;
6171: border-right: 1px solid black;
6172: display: inline;
6173: vertical-align: middle;
1.807 droeschl 6174: }
6175:
1.847 tempelho 6176: ul.LC_TabContent {
1.911 bisitz 6177: display:block;
6178: background: $sidebg;
6179: border-bottom: solid 1px $lg_border_color;
6180: list-style:none;
6181: margin: 0 -10px;
6182: padding: 0;
1.693 droeschl 6183: }
6184:
1.795 www 6185: ul.LC_TabContent li,
6186: ul.LC_TabContentBigger li {
1.911 bisitz 6187: float:left;
1.741 harmsja 6188: }
1.795 www 6189:
1.897 wenzelju 6190: ul#LC_secondary_menu li a {
1.911 bisitz 6191: color: $fontmenu;
6192: text-decoration: none;
1.693 droeschl 6193: }
1.795 www 6194:
1.721 harmsja 6195: ul.LC_TabContent {
1.952 onken 6196: min-height:20px;
1.721 harmsja 6197: }
1.795 www 6198:
6199: ul.LC_TabContent li {
1.911 bisitz 6200: vertical-align:middle;
1.959 onken 6201: padding: 0 16px 0 10px;
1.911 bisitz 6202: background-color:$tabbg;
6203: border-bottom:solid 1px $lg_border_color;
1.952 onken 6204: border-right: solid 1px $font;
1.721 harmsja 6205: }
1.795 www 6206:
1.847 tempelho 6207: ul.LC_TabContent .right {
1.911 bisitz 6208: float:right;
1.847 tempelho 6209: }
6210:
1.911 bisitz 6211: ul.LC_TabContent li a,
6212: ul.LC_TabContent li {
6213: color:rgb(47,47,47);
6214: text-decoration:none;
6215: font-size:95%;
6216: font-weight:bold;
1.952 onken 6217: min-height:20px;
6218: }
6219:
1.959 onken 6220: ul.LC_TabContent li a:hover,
6221: ul.LC_TabContent li a:focus {
1.952 onken 6222: color: $button_hover;
1.959 onken 6223: background:none;
6224: outline:none;
1.952 onken 6225: }
6226:
6227: ul.LC_TabContent li:hover {
6228: color: $button_hover;
6229: cursor:pointer;
1.721 harmsja 6230: }
1.795 www 6231:
1.911 bisitz 6232: ul.LC_TabContent li.active {
1.952 onken 6233: color: $font;
1.911 bisitz 6234: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6235: border-bottom:solid 1px #FFFFFF;
6236: cursor: default;
1.744 ehlerst 6237: }
1.795 www 6238:
1.959 onken 6239: ul.LC_TabContent li.active a {
6240: color:$font;
6241: background:#FFFFFF;
6242: outline: none;
6243: }
1.870 tempelho 6244: #maincoursedoc {
1.911 bisitz 6245: clear:both;
1.870 tempelho 6246: }
6247:
6248: ul.LC_TabContentBigger {
1.911 bisitz 6249: display:block;
6250: list-style:none;
6251: padding: 0;
1.870 tempelho 6252: }
6253:
1.795 www 6254: ul.LC_TabContentBigger li {
1.911 bisitz 6255: vertical-align:bottom;
6256: height: 30px;
6257: font-size:110%;
6258: font-weight:bold;
6259: color: #737373;
1.841 tempelho 6260: }
6261:
1.957 onken 6262: ul.LC_TabContentBigger li.active {
6263: position: relative;
6264: top: 1px;
6265: }
6266:
1.870 tempelho 6267: ul.LC_TabContentBigger li a {
1.911 bisitz 6268: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6269: height: 30px;
6270: line-height: 30px;
6271: text-align: center;
6272: display: block;
6273: text-decoration: none;
1.958 onken 6274: outline: none;
1.741 harmsja 6275: }
1.795 www 6276:
1.870 tempelho 6277: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6278: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6279: color:$font;
1.744 ehlerst 6280: }
1.795 www 6281:
1.870 tempelho 6282: ul.LC_TabContentBigger li b {
1.911 bisitz 6283: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6284: display: block;
6285: float: left;
6286: padding: 0 30px;
1.957 onken 6287: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6288: }
6289:
1.956 onken 6290: ul.LC_TabContentBigger li:hover b {
6291: color:$button_hover;
6292: }
6293:
1.870 tempelho 6294: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6295: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6296: color:$font;
1.957 onken 6297: border: 0;
1.741 harmsja 6298: }
1.693 droeschl 6299:
1.870 tempelho 6300:
1.862 bisitz 6301: ul.LC_CourseBreadcrumbs {
6302: background: $sidebg;
6303: line-height: 32px;
6304: padding-left: 10px;
6305: margin: 0 0 10px 0;
6306: list-style-position: inside;
6307:
6308: }
6309:
1.911 bisitz 6310: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6311: ol#LC_PathBreadcrumbs {
1.911 bisitz 6312: padding-left: 10px;
6313: margin: 0;
1.933 droeschl 6314: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6315: }
6316:
1.911 bisitz 6317: ol#LC_MenuBreadcrumbs li,
6318: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6319: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6320: display: inline;
1.933 droeschl 6321: white-space: normal;
1.693 droeschl 6322: }
6323:
1.823 bisitz 6324: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6325: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6326: text-decoration: none;
6327: font-size:90%;
1.693 droeschl 6328: }
1.795 www 6329:
1.969 droeschl 6330: ol#LC_MenuBreadcrumbs h1 {
6331: display: inline;
6332: font-size: 90%;
6333: line-height: 2.5em;
6334: margin: 0;
6335: padding: 0;
6336: }
6337:
1.795 www 6338: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6339: text-decoration:none;
6340: font-size:100%;
6341: font-weight:bold;
1.693 droeschl 6342: }
1.795 www 6343:
1.840 bisitz 6344: .LC_Box {
1.911 bisitz 6345: border: solid 1px $lg_border_color;
6346: padding: 0 10px 10px 10px;
1.746 neumanie 6347: }
1.795 www 6348:
6349: .LC_AboutMe_Image {
1.911 bisitz 6350: float:left;
6351: margin-right:10px;
1.747 neumanie 6352: }
1.795 www 6353:
6354: .LC_Clear_AboutMe_Image {
1.911 bisitz 6355: clear:left;
1.747 neumanie 6356: }
1.795 www 6357:
1.721 harmsja 6358: dl.LC_ListStyleClean dt {
1.911 bisitz 6359: padding-right: 5px;
6360: display: table-header-group;
1.693 droeschl 6361: }
6362:
1.721 harmsja 6363: dl.LC_ListStyleClean dd {
1.911 bisitz 6364: display: table-row;
1.693 droeschl 6365: }
6366:
1.721 harmsja 6367: .LC_ListStyleClean,
6368: .LC_ListStyleSimple,
6369: .LC_ListStyleNormal,
1.795 www 6370: .LC_ListStyleSpecial {
1.911 bisitz 6371: /* display:block; */
6372: list-style-position: inside;
6373: list-style-type: none;
6374: overflow: hidden;
6375: padding: 0;
1.693 droeschl 6376: }
6377:
1.721 harmsja 6378: .LC_ListStyleSimple li,
6379: .LC_ListStyleSimple dd,
6380: .LC_ListStyleNormal li,
6381: .LC_ListStyleNormal dd,
6382: .LC_ListStyleSpecial li,
1.795 www 6383: .LC_ListStyleSpecial dd {
1.911 bisitz 6384: margin: 0;
6385: padding: 5px 5px 5px 10px;
6386: clear: both;
1.693 droeschl 6387: }
6388:
1.721 harmsja 6389: .LC_ListStyleClean li,
6390: .LC_ListStyleClean dd {
1.911 bisitz 6391: padding-top: 0;
6392: padding-bottom: 0;
1.693 droeschl 6393: }
6394:
1.721 harmsja 6395: .LC_ListStyleSimple dd,
1.795 www 6396: .LC_ListStyleSimple li {
1.911 bisitz 6397: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6398: }
6399:
1.721 harmsja 6400: .LC_ListStyleSpecial li,
6401: .LC_ListStyleSpecial dd {
1.911 bisitz 6402: list-style-type: none;
6403: background-color: RGB(220, 220, 220);
6404: margin-bottom: 4px;
1.693 droeschl 6405: }
6406:
1.721 harmsja 6407: table.LC_SimpleTable {
1.911 bisitz 6408: margin:5px;
6409: border:solid 1px $lg_border_color;
1.795 www 6410: }
1.693 droeschl 6411:
1.721 harmsja 6412: table.LC_SimpleTable tr {
1.911 bisitz 6413: padding: 0;
6414: border:solid 1px $lg_border_color;
1.693 droeschl 6415: }
1.795 www 6416:
6417: table.LC_SimpleTable thead {
1.911 bisitz 6418: background:rgb(220,220,220);
1.693 droeschl 6419: }
6420:
1.721 harmsja 6421: div.LC_columnSection {
1.911 bisitz 6422: display: block;
6423: clear: both;
6424: overflow: hidden;
6425: margin: 0;
1.693 droeschl 6426: }
6427:
1.721 harmsja 6428: div.LC_columnSection>* {
1.911 bisitz 6429: float: left;
6430: margin: 10px 20px 10px 0;
6431: overflow:hidden;
1.693 droeschl 6432: }
1.721 harmsja 6433:
1.795 www 6434: table em {
1.911 bisitz 6435: font-weight: bold;
6436: font-style: normal;
1.748 schulted 6437: }
1.795 www 6438:
1.779 bisitz 6439: table.LC_tableBrowseRes,
1.795 www 6440: table.LC_tableOfContent {
1.911 bisitz 6441: border:none;
6442: border-spacing: 1px;
6443: padding: 3px;
6444: background-color: #FFFFFF;
6445: font-size: 90%;
1.753 droeschl 6446: }
1.789 droeschl 6447:
1.911 bisitz 6448: table.LC_tableOfContent {
6449: border-collapse: collapse;
1.789 droeschl 6450: }
6451:
1.771 droeschl 6452: table.LC_tableBrowseRes a,
1.768 schulted 6453: table.LC_tableOfContent a {
1.911 bisitz 6454: background-color: transparent;
6455: text-decoration: none;
1.753 droeschl 6456: }
6457:
1.795 www 6458: table.LC_tableOfContent img {
1.911 bisitz 6459: border: none;
6460: height: 1.3em;
6461: vertical-align: text-bottom;
6462: margin-right: 0.3em;
1.753 droeschl 6463: }
1.757 schulted 6464:
1.795 www 6465: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6466: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6467: }
6468:
1.795 www 6469: a#LC_content_toolbar_everything {
1.911 bisitz 6470: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6471: }
6472:
1.795 www 6473: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6474: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6475: }
6476:
1.795 www 6477: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6478: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6479: }
6480:
1.795 www 6481: a#LC_content_toolbar_changefolder {
1.911 bisitz 6482: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6483: }
6484:
1.795 www 6485: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6486: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6487: }
6488:
1.795 www 6489: ul#LC_toolbar li a:hover {
1.911 bisitz 6490: background-position: bottom center;
1.757 schulted 6491: }
6492:
1.795 www 6493: ul#LC_toolbar {
1.911 bisitz 6494: padding: 0;
6495: margin: 2px;
6496: list-style:none;
6497: position:relative;
6498: background-color:white;
1.757 schulted 6499: }
6500:
1.795 www 6501: ul#LC_toolbar li {
1.911 bisitz 6502: border:1px solid white;
6503: padding: 0;
6504: margin: 0;
6505: float: left;
6506: display:inline;
6507: vertical-align:middle;
6508: }
1.757 schulted 6509:
1.783 amueller 6510:
1.795 www 6511: a.LC_toolbarItem {
1.911 bisitz 6512: display:block;
6513: padding: 0;
6514: margin: 0;
6515: height: 32px;
6516: width: 32px;
6517: color:white;
6518: border: none;
6519: background-repeat:no-repeat;
6520: background-color:transparent;
1.757 schulted 6521: }
6522:
1.915 droeschl 6523: ul.LC_funclist {
6524: margin: 0;
6525: padding: 0.5em 1em 0.5em 0;
6526: }
6527:
1.933 droeschl 6528: ul.LC_funclist > li:first-child {
6529: font-weight:bold;
6530: margin-left:0.8em;
6531: }
6532:
1.915 droeschl 6533: ul.LC_funclist + ul.LC_funclist {
6534: /*
6535: left border as a seperator if we have more than
6536: one list
6537: */
6538: border-left: 1px solid $sidebg;
6539: /*
6540: this hides the left border behind the border of the
6541: outer box if element is wrapped to the next 'line'
6542: */
6543: margin-left: -1px;
6544: }
6545:
1.843 bisitz 6546: ul.LC_funclist li {
1.915 droeschl 6547: display: inline;
1.782 bisitz 6548: white-space: nowrap;
1.915 droeschl 6549: margin: 0 0 0 25px;
6550: line-height: 150%;
1.782 bisitz 6551: }
6552:
1.974 wenzelju 6553: .LC_hidden {
6554: display: none;
6555: }
6556:
1.343 albertel 6557: END
6558: }
6559:
1.306 albertel 6560: =pod
6561:
6562: =item * &headtag()
6563:
6564: Returns a uniform footer for LON-CAPA web pages.
6565:
1.307 albertel 6566: Inputs: $title - optional title for the head
6567: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6568: $args - optional arguments
1.319 albertel 6569: force_register - if is true call registerurl so the remote is
6570: informed
1.415 albertel 6571: redirect -> array ref of
6572: 1- seconds before redirect occurs
6573: 2- url to redirect to
6574: 3- whether the side effect should occur
1.315 albertel 6575: (side effect of setting
6576: $env{'internal.head.redirect'} to the url
6577: redirected too)
1.352 albertel 6578: domain -> force to color decorate a page for a specific
6579: domain
6580: function -> force usage of a specific rolish color scheme
6581: bgcolor -> override the default page bgcolor
1.460 albertel 6582: no_auto_mt_title
6583: -> prevent &mt()ing the title arg
1.464 albertel 6584:
1.306 albertel 6585: =cut
6586:
6587: sub headtag {
1.313 albertel 6588: my ($title,$head_extra,$args) = @_;
1.306 albertel 6589:
1.363 albertel 6590: my $function = $args->{'function'} || &get_users_function();
6591: my $domain = $args->{'domain'} || &determinedomain();
6592: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6593: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6594: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6595: #time(),
1.418 albertel 6596: $env{'environment.color.timestamp'},
1.363 albertel 6597: $function,$domain,$bgcolor);
6598:
1.369 www 6599: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6600:
1.308 albertel 6601: my $result =
6602: '<head>'.
1.461 albertel 6603: &font_settings();
1.319 albertel 6604:
1.461 albertel 6605: if (!$args->{'frameset'}) {
6606: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6607: }
1.962 droeschl 6608: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
6609: $result .= Apache::lonxml::display_title();
1.319 albertel 6610: }
1.436 albertel 6611: if (!$args->{'no_nav_bar'}
6612: && !$args->{'only_body'}
6613: && !$args->{'frameset'}) {
6614: $result .= &help_menu_js();
6615: }
1.319 albertel 6616:
1.314 albertel 6617: if (ref($args->{'redirect'})) {
1.414 albertel 6618: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6619: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6620: if (!$inhibit_continue) {
6621: $env{'internal.head.redirect'} = $url;
6622: }
1.313 albertel 6623: $result.=<<ADDMETA
6624: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6625: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6626: ADDMETA
6627: }
1.306 albertel 6628: if (!defined($title)) {
6629: $title = 'The LearningOnline Network with CAPA';
6630: }
1.460 albertel 6631: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6632: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6633: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6634: .$head_extra;
1.962 droeschl 6635: return $result.'</head>';
1.306 albertel 6636: }
6637:
6638: =pod
6639:
1.340 albertel 6640: =item * &font_settings()
6641:
6642: Returns neccessary <meta> to set the proper encoding
6643:
6644: Inputs: none
6645:
6646: =cut
6647:
6648: sub font_settings {
6649: my $headerstring='';
1.647 www 6650: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6651: $headerstring.=
6652: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6653: }
6654: return $headerstring;
6655: }
6656:
1.341 albertel 6657: =pod
6658:
6659: =item * &xml_begin()
6660:
6661: Returns the needed doctype and <html>
6662:
6663: Inputs: none
6664:
6665: =cut
6666:
6667: sub xml_begin {
6668: my $output='';
6669:
6670: if ($env{'browser.mathml'}) {
6671: $output='<?xml version="1.0"?>'
6672: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6673: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6674:
6675: # .'<!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">] >'
6676: .'<!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">'
6677: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6678: .'xmlns="http://www.w3.org/1999/xhtml">';
6679: } else {
1.849 bisitz 6680: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6681: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6682: }
6683: return $output;
6684: }
1.340 albertel 6685:
6686: =pod
6687:
1.306 albertel 6688: =item * &start_page()
6689:
6690: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6691:
1.648 raeburn 6692: Inputs:
6693:
6694: =over 4
6695:
6696: $title - optional title for the page
6697:
6698: $head_extra - optional extra HTML to incude inside the <head>
6699:
6700: $args - additional optional args supported are:
6701:
6702: =over 8
6703:
6704: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6705: arg on
1.814 bisitz 6706: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6707: add_entries -> additional attributes to add to the <body>
6708: domain -> force to color decorate a page for a
1.317 albertel 6709: specific domain
1.648 raeburn 6710: function -> force usage of a specific rolish color
1.317 albertel 6711: scheme
1.648 raeburn 6712: redirect -> see &headtag()
6713: bgcolor -> override the default page bg color
6714: js_ready -> return a string ready for being used in
1.317 albertel 6715: a javascript writeln
1.648 raeburn 6716: html_encode -> return a string ready for being used in
1.320 albertel 6717: a html attribute
1.648 raeburn 6718: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6719: $forcereg arg
1.648 raeburn 6720: frameset -> if true will start with a <frameset>
1.330 albertel 6721: rather than <body>
1.648 raeburn 6722: skip_phases -> hash ref of
1.338 albertel 6723: head -> skip the <html><head> generation
6724: body -> skip all <body> generation
1.648 raeburn 6725: no_auto_mt_title -> prevent &mt()ing the title arg
6726: inherit_jsmath -> when creating popup window in a page,
6727: should it have jsmath forced on by the
6728: current page
1.867 kalberla 6729: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 6730: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6731:
1.648 raeburn 6732: =back
1.460 albertel 6733:
1.648 raeburn 6734: =back
1.562 albertel 6735:
1.306 albertel 6736: =cut
6737:
6738: sub start_page {
1.309 albertel 6739: my ($title,$head_extra,$args) = @_;
1.318 albertel 6740: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.964 droeschl 6741: #SD
6742: #I don't see why we copy certain elements of %$args to %head_args
6743: #head args is passed to headtag() and this routine only reads those
6744: #keys that are needed. There doesn't happen any writes or any processing
6745: #of other keys.
6746: #proposal: just pass $args to headtag instead of \%head_args and delete
6747: #marked lines
6748: #<- MARK
1.313 albertel 6749: my %head_args;
1.352 albertel 6750: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6751: 'bgcolor','frameset','no_nav_bar','only_body',
6752: 'no_auto_mt_title') {
1.319 albertel 6753: if (defined($args->{$arg})) {
1.324 raeburn 6754: $head_args{$arg} = $args->{$arg};
1.319 albertel 6755: }
1.313 albertel 6756: }
1.964 droeschl 6757: #MARK ->
1.319 albertel 6758:
1.315 albertel 6759: $env{'internal.start_page'}++;
1.338 albertel 6760: my $result;
1.964 droeschl 6761:
1.338 albertel 6762: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.964 droeschl 6763: $result .=
6764: &xml_begin() . &headtag($title,$head_extra,\%head_args);
6765: #replace prev line by
6766: # &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 6767: }
6768:
6769: if (! exists($args->{'skip_phases'}{'body'}) ) {
6770: if ($args->{'frameset'}) {
6771: my $attr_string = &make_attr_string($args->{'force_register'},
6772: $args->{'add_entries'});
6773: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6774: } else {
6775: $result .=
6776: &bodytag($title,
6777: $args->{'function'}, $args->{'add_entries'},
6778: $args->{'only_body'}, $args->{'domain'},
6779: $args->{'force_register'}, $args->{'no_nav_bar'},
1.962 droeschl 6780: $args->{'bgcolor'}, $args);
1.831 bisitz 6781: }
1.330 albertel 6782: }
1.338 albertel 6783:
1.315 albertel 6784: if ($args->{'js_ready'}) {
1.713 kaisler 6785: $result = &js_ready($result);
1.315 albertel 6786: }
1.320 albertel 6787: if ($args->{'html_encode'}) {
1.713 kaisler 6788: $result = &html_encode($result);
6789: }
6790:
1.813 bisitz 6791: # Preparation for new and consistent functionlist at top of screen
6792: # if ($args->{'functionlist'}) {
6793: # $result .= &build_functionlist();
6794: #}
6795:
1.964 droeschl 6796: # Don't add anything more if only_body wanted or in const space
6797: return $result if $args->{'only_body'}
6798: || $env{'request.state'} eq 'construct';
1.813 bisitz 6799:
6800: #Breadcrumbs
1.758 kaisler 6801: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6802: &Apache::lonhtmlcommon::clear_breadcrumbs();
6803: #if any br links exists, add them to the breadcrumbs
6804: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6805: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6806: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6807: }
6808: }
6809:
6810: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6811: if(exists($args->{'bread_crumbs_component'})){
6812: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6813: }else{
6814: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6815: }
1.320 albertel 6816: }
1.315 albertel 6817: return $result;
1.306 albertel 6818: }
6819:
6820: sub end_page {
1.315 albertel 6821: my ($args) = @_;
6822: $env{'internal.end_page'}++;
1.330 albertel 6823: my $result;
1.335 albertel 6824: if ($args->{'discussion'}) {
6825: my ($target,$parser);
6826: if (ref($args->{'discussion'})) {
6827: ($target,$parser) =($args->{'discussion'}{'target'},
6828: $args->{'discussion'}{'parser'});
6829: }
6830: $result .= &Apache::lonxml::xmlend($target,$parser);
6831: }
6832:
1.330 albertel 6833: if ($args->{'frameset'}) {
6834: $result .= '</frameset>';
6835: } else {
1.635 raeburn 6836: $result .= &endbodytag($args);
1.330 albertel 6837: }
6838: $result .= "\n</html>";
6839:
1.315 albertel 6840: if ($args->{'js_ready'}) {
1.317 albertel 6841: $result = &js_ready($result);
1.315 albertel 6842: }
1.335 albertel 6843:
1.320 albertel 6844: if ($args->{'html_encode'}) {
6845: $result = &html_encode($result);
6846: }
1.335 albertel 6847:
1.315 albertel 6848: return $result;
6849: }
6850:
1.320 albertel 6851: sub html_encode {
6852: my ($result) = @_;
6853:
1.322 albertel 6854: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6855:
6856: return $result;
6857: }
1.317 albertel 6858: sub js_ready {
6859: my ($result) = @_;
6860:
1.323 albertel 6861: $result =~ s/[\n\r]/ /xmsg;
6862: $result =~ s/\\/\\\\/xmsg;
6863: $result =~ s/'/\\'/xmsg;
1.372 albertel 6864: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6865:
6866: return $result;
6867: }
6868:
1.315 albertel 6869: sub validate_page {
6870: if ( exists($env{'internal.start_page'})
1.316 albertel 6871: && $env{'internal.start_page'} > 1) {
6872: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6873: $env{'internal.start_page'}.' '.
1.316 albertel 6874: $ENV{'request.filename'});
1.315 albertel 6875: }
6876: if ( exists($env{'internal.end_page'})
1.316 albertel 6877: && $env{'internal.end_page'} > 1) {
6878: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6879: $env{'internal.end_page'}.' '.
1.316 albertel 6880: $env{'request.filename'});
1.315 albertel 6881: }
6882: if ( exists($env{'internal.start_page'})
6883: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6884: &Apache::lonnet::logthis('start_page called without end_page '.
6885: $env{'request.filename'});
1.315 albertel 6886: }
6887: if ( ! exists($env{'internal.start_page'})
6888: && exists($env{'internal.end_page'})) {
1.316 albertel 6889: &Apache::lonnet::logthis('end_page called without start_page'.
6890: $env{'request.filename'});
1.315 albertel 6891: }
1.306 albertel 6892: }
1.315 albertel 6893:
1.996 www 6894:
6895: sub start_scrollbox {
1.998 raeburn 6896: my ($outerwidth,$width,$height)=@_;
6897: unless ($outerwidth) { $outerwidth='520px'; }
6898: unless ($width) { $width='500px'; }
6899: unless ($height) { $height='200px'; }
6900: return "<table style='width: $outerwidth; border: 1px solid black;'><tr><td style='width: $width;' bgcolor='#FFFFFF'><div style='overflow:auto; width:$width; height: $height;'>";
1.996 www 6901: }
6902:
6903: sub end_scrollbox {
1.998 raeburn 6904: return '</td></tr></table>';
1.996 www 6905: }
6906:
1.318 albertel 6907: sub simple_error_page {
6908: my ($r,$title,$msg) = @_;
6909: my $page =
6910: &Apache::loncommon::start_page($title).
6911: &mt($msg).
6912: &Apache::loncommon::end_page();
6913: if (ref($r)) {
6914: $r->print($page);
1.327 albertel 6915: return;
1.318 albertel 6916: }
6917: return $page;
6918: }
1.347 albertel 6919:
6920: {
1.610 albertel 6921: my @row_count;
1.961 onken 6922:
6923: sub start_data_table_count {
6924: unshift(@row_count, 0);
6925: return;
6926: }
6927:
6928: sub end_data_table_count {
6929: shift(@row_count);
6930: return;
6931: }
6932:
1.347 albertel 6933: sub start_data_table {
1.422 albertel 6934: my ($add_class) = @_;
6935: my $css_class = (join(' ','LC_data_table',$add_class));
1.961 onken 6936: &start_data_table_count();
1.422 albertel 6937: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6938: }
6939:
6940: sub end_data_table {
1.961 onken 6941: &end_data_table_count();
1.389 albertel 6942: return '</table>'."\n";;
1.347 albertel 6943: }
6944:
6945: sub start_data_table_row {
1.974 wenzelju 6946: my ($add_class, $id) = @_;
1.610 albertel 6947: $row_count[0]++;
6948: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6949: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 6950: $id = (' id="'.$id.'"') unless ($id eq '');
6951: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 6952: }
1.471 banghart 6953:
6954: sub continue_data_table_row {
1.974 wenzelju 6955: my ($add_class, $id) = @_;
1.610 albertel 6956: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 6957: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
6958: $id = (' id="'.$id.'"') unless ($id eq '');
6959: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 6960: }
1.347 albertel 6961:
6962: sub end_data_table_row {
1.389 albertel 6963: return '</tr>'."\n";;
1.347 albertel 6964: }
1.367 www 6965:
1.421 albertel 6966: sub start_data_table_empty_row {
1.707 bisitz 6967: # $row_count[0]++;
1.421 albertel 6968: return '<tr class="LC_empty_row" >'."\n";;
6969: }
6970:
6971: sub end_data_table_empty_row {
6972: return '</tr>'."\n";;
6973: }
6974:
1.367 www 6975: sub start_data_table_header_row {
1.389 albertel 6976: return '<tr class="LC_header_row">'."\n";;
1.367 www 6977: }
6978:
6979: sub end_data_table_header_row {
1.389 albertel 6980: return '</tr>'."\n";;
1.367 www 6981: }
1.890 droeschl 6982:
6983: sub data_table_caption {
6984: my $caption = shift;
6985: return "<caption class=\"LC_caption\">$caption</caption>";
6986: }
1.347 albertel 6987: }
6988:
1.548 albertel 6989: =pod
6990:
6991: =item * &inhibit_menu_check($arg)
6992:
6993: Checks for a inhibitmenu state and generates output to preserve it
6994:
6995: Inputs: $arg - can be any of
6996: - undef - in which case the return value is a string
6997: to add into arguments list of a uri
6998: - 'input' - in which case the return value is a HTML
6999: <form> <input> field of type hidden to
7000: preserve the value
7001: - a url - in which case the return value is the url with
7002: the neccesary cgi args added to preserve the
7003: inhibitmenu state
7004: - a ref to a url - no return value, but the string is
7005: updated to include the neccessary cgi
7006: args to preserve the inhibitmenu state
7007:
7008: =cut
7009:
7010: sub inhibit_menu_check {
7011: my ($arg) = @_;
7012: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7013: if ($arg eq 'input') {
7014: if ($env{'form.inhibitmenu'}) {
7015: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7016: } else {
7017: return
7018: }
7019: }
7020: if ($env{'form.inhibitmenu'}) {
7021: if (ref($arg)) {
7022: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7023: } elsif ($arg eq '') {
7024: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7025: } else {
7026: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7027: }
7028: }
7029: if (!ref($arg)) {
7030: return $arg;
7031: }
7032: }
7033:
1.251 albertel 7034: ###############################################
1.182 matthew 7035:
7036: =pod
7037:
1.549 albertel 7038: =back
7039:
7040: =head1 User Information Routines
7041:
7042: =over 4
7043:
1.405 albertel 7044: =item * &get_users_function()
1.182 matthew 7045:
7046: Used by &bodytag to determine the current users primary role.
7047: Returns either 'student','coordinator','admin', or 'author'.
7048:
7049: =cut
7050:
7051: ###############################################
7052: sub get_users_function {
1.815 tempelho 7053: my $function = 'norole';
1.818 tempelho 7054: if ($env{'request.role'}=~/^(st)/) {
7055: $function='student';
7056: }
1.907 raeburn 7057: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7058: $function='coordinator';
7059: }
1.258 albertel 7060: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7061: $function='admin';
7062: }
1.826 bisitz 7063: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7064: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7065: $function='author';
7066: }
7067: return $function;
1.54 www 7068: }
1.99 www 7069:
7070: ###############################################
7071:
1.233 raeburn 7072: =pod
7073:
1.821 raeburn 7074: =item * &show_course()
7075:
7076: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7077: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7078:
7079: Inputs:
7080: None
7081:
7082: Outputs:
7083: Scalar: 1 if 'Course' to be used, 0 otherwise.
7084:
7085: =cut
7086:
7087: ###############################################
7088: sub show_course {
7089: my $course = !$env{'user.adv'};
7090: if (!$env{'user.adv'}) {
7091: foreach my $env (keys(%env)) {
7092: next if ($env !~ m/^user\.priv\./);
7093: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7094: $course = 0;
7095: last;
7096: }
7097: }
7098: }
7099: return $course;
7100: }
7101:
7102: ###############################################
7103:
7104: =pod
7105:
1.542 raeburn 7106: =item * &check_user_status()
1.274 raeburn 7107:
7108: Determines current status of supplied role for a
7109: specific user. Roles can be active, previous or future.
7110:
7111: Inputs:
7112: user's domain, user's username, course's domain,
1.375 raeburn 7113: course's number, optional section ID.
1.274 raeburn 7114:
7115: Outputs:
7116: role status: active, previous or future.
7117:
7118: =cut
7119:
7120: sub check_user_status {
1.412 raeburn 7121: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.982 raeburn 7122: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7123: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7124: my @uroles = keys %userinfo;
7125: my $srchstr;
7126: my $active_chk = 'none';
1.412 raeburn 7127: my $now = time;
1.274 raeburn 7128: if (@uroles > 0) {
1.908 raeburn 7129: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7130: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7131: } else {
1.412 raeburn 7132: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7133: }
7134: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7135: my $role_end = 0;
7136: my $role_start = 0;
7137: $active_chk = 'active';
1.412 raeburn 7138: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7139: $role_end = $1;
7140: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7141: $role_start = $1;
1.274 raeburn 7142: }
7143: }
7144: if ($role_start > 0) {
1.412 raeburn 7145: if ($now < $role_start) {
1.274 raeburn 7146: $active_chk = 'future';
7147: }
7148: }
7149: if ($role_end > 0) {
1.412 raeburn 7150: if ($now > $role_end) {
1.274 raeburn 7151: $active_chk = 'previous';
7152: }
7153: }
7154: }
7155: }
7156: return $active_chk;
7157: }
7158:
7159: ###############################################
7160:
7161: =pod
7162:
1.405 albertel 7163: =item * &get_sections()
1.233 raeburn 7164:
7165: Determines all the sections for a course including
7166: sections with students and sections containing other roles.
1.419 raeburn 7167: Incoming parameters:
7168:
7169: 1. domain
7170: 2. course number
7171: 3. reference to array containing roles for which sections should
7172: be gathered (optional).
7173: 4. reference to array containing status types for which sections
7174: should be gathered (optional).
7175:
7176: If the third argument is undefined, sections are gathered for any role.
7177: If the fourth argument is undefined, sections are gathered for any status.
7178: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7179:
1.374 raeburn 7180: Returns section hash (keys are section IDs, values are
7181: number of users in each section), subject to the
1.419 raeburn 7182: optional roles filter, optional status filter
1.233 raeburn 7183:
7184: =cut
7185:
7186: ###############################################
7187: sub get_sections {
1.419 raeburn 7188: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7189: if (!defined($cdom) || !defined($cnum)) {
7190: my $cid = $env{'request.course.id'};
7191:
7192: return if (!defined($cid));
7193:
7194: $cdom = $env{'course.'.$cid.'.domain'};
7195: $cnum = $env{'course.'.$cid.'.num'};
7196: }
7197:
7198: my %sectioncount;
1.419 raeburn 7199: my $now = time;
1.240 albertel 7200:
1.366 albertel 7201: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7202: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7203: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7204: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7205: my $start_index = &Apache::loncoursedata::CL_START();
7206: my $end_index = &Apache::loncoursedata::CL_END();
7207: my $status;
1.366 albertel 7208: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7209: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7210: $data->[$status_index],
7211: $data->[$start_index],
7212: $data->[$end_index]);
7213: if ($stu_status eq 'Active') {
7214: $status = 'active';
7215: } elsif ($end < $now) {
7216: $status = 'previous';
7217: } elsif ($start > $now) {
7218: $status = 'future';
7219: }
7220: if ($section ne '-1' && $section !~ /^\s*$/) {
7221: if ((!defined($possible_status)) || (($status ne '') &&
7222: (grep/^\Q$status\E$/,@{$possible_status}))) {
7223: $sectioncount{$section}++;
7224: }
1.240 albertel 7225: }
7226: }
7227: }
7228: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7229: foreach my $user (sort(keys(%courseroles))) {
7230: if ($user !~ /^(\w{2})/) { next; }
7231: my ($role) = ($user =~ /^(\w{2})/);
7232: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7233: my ($section,$status);
1.240 albertel 7234: if ($role eq 'cr' &&
7235: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7236: $section=$1;
7237: }
7238: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7239: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7240: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7241: if ($end == -1 && $start == -1) {
7242: next; #deleted role
7243: }
7244: if (!defined($possible_status)) {
7245: $sectioncount{$section}++;
7246: } else {
7247: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7248: $status = 'active';
7249: } elsif ($end < $now) {
7250: $status = 'future';
7251: } elsif ($start > $now) {
7252: $status = 'previous';
7253: }
7254: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7255: $sectioncount{$section}++;
7256: }
7257: }
1.233 raeburn 7258: }
1.366 albertel 7259: return %sectioncount;
1.233 raeburn 7260: }
7261:
1.274 raeburn 7262: ###############################################
1.294 raeburn 7263:
7264: =pod
1.405 albertel 7265:
7266: =item * &get_course_users()
7267:
1.275 raeburn 7268: Retrieves usernames:domains for users in the specified course
7269: with specific role(s), and access status.
7270:
7271: Incoming parameters:
1.277 albertel 7272: 1. course domain
7273: 2. course number
7274: 3. access status: users must have - either active,
1.275 raeburn 7275: previous, future, or all.
1.277 albertel 7276: 4. reference to array of permissible roles
1.288 raeburn 7277: 5. reference to array of section restrictions (optional)
7278: 6. reference to results object (hash of hashes).
7279: 7. reference to optional userdata hash
1.609 raeburn 7280: 8. reference to optional statushash
1.630 raeburn 7281: 9. flag if privileged users (except those set to unhide in
7282: course settings) should be excluded
1.609 raeburn 7283: Keys of top level results hash are roles.
1.275 raeburn 7284: Keys of inner hashes are username:domain, with
7285: values set to access type.
1.288 raeburn 7286: Optional userdata hash returns an array with arguments in the
7287: same order as loncoursedata::get_classlist() for student data.
7288:
1.609 raeburn 7289: Optional statushash returns
7290:
1.288 raeburn 7291: Entries for end, start, section and status are blank because
7292: of the possibility of multiple values for non-student roles.
7293:
1.275 raeburn 7294: =cut
1.405 albertel 7295:
1.275 raeburn 7296: ###############################################
1.405 albertel 7297:
1.275 raeburn 7298: sub get_course_users {
1.630 raeburn 7299: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7300: my %idx = ();
1.419 raeburn 7301: my %seclists;
1.288 raeburn 7302:
7303: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7304: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7305: $idx{end} = &Apache::loncoursedata::CL_END();
7306: $idx{start} = &Apache::loncoursedata::CL_START();
7307: $idx{id} = &Apache::loncoursedata::CL_ID();
7308: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7309: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7310: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7311:
1.290 albertel 7312: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7313: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7314: my $now = time;
1.277 albertel 7315: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7316: my $match = 0;
1.412 raeburn 7317: my $secmatch = 0;
1.419 raeburn 7318: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7319: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7320: if ($section eq '') {
7321: $section = 'none';
7322: }
1.291 albertel 7323: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7324: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7325: $secmatch = 1;
7326: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7327: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7328: $secmatch = 1;
7329: }
7330: } else {
1.419 raeburn 7331: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7332: $secmatch = 1;
7333: }
1.290 albertel 7334: }
1.412 raeburn 7335: if (!$secmatch) {
7336: next;
7337: }
1.419 raeburn 7338: }
1.275 raeburn 7339: if (defined($$types{'active'})) {
1.288 raeburn 7340: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7341: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7342: $match = 1;
1.275 raeburn 7343: }
7344: }
7345: if (defined($$types{'previous'})) {
1.609 raeburn 7346: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7347: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7348: $match = 1;
1.275 raeburn 7349: }
7350: }
7351: if (defined($$types{'future'})) {
1.609 raeburn 7352: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7353: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7354: $match = 1;
1.275 raeburn 7355: }
7356: }
1.609 raeburn 7357: if ($match) {
7358: push(@{$seclists{$student}},$section);
7359: if (ref($userdata) eq 'HASH') {
7360: $$userdata{$student} = $$classlist{$student};
7361: }
7362: if (ref($statushash) eq 'HASH') {
7363: $statushash->{$student}{'st'}{$section} = $status;
7364: }
1.288 raeburn 7365: }
1.275 raeburn 7366: }
7367: }
1.412 raeburn 7368: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7369: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7370: my $now = time;
1.609 raeburn 7371: my %displaystatus = ( previous => 'Expired',
7372: active => 'Active',
7373: future => 'Future',
7374: );
1.630 raeburn 7375: my %nothide;
7376: if ($hidepriv) {
7377: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7378: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7379: if ($user !~ /:/) {
7380: $nothide{join(':',split(/[\@]/,$user))}=1;
7381: } else {
7382: $nothide{$user} = 1;
7383: }
7384: }
7385: }
1.439 raeburn 7386: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7387: my $match = 0;
1.412 raeburn 7388: my $secmatch = 0;
1.439 raeburn 7389: my $status;
1.412 raeburn 7390: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7391: $user =~ s/:$//;
1.439 raeburn 7392: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7393: if ($end == -1 || $start == -1) {
7394: next;
7395: }
7396: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7397: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7398: my ($uname,$udom) = split(/:/,$user);
7399: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7400: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7401: $secmatch = 1;
7402: } elsif ($usec eq '') {
1.420 albertel 7403: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7404: $secmatch = 1;
7405: }
7406: } else {
7407: if (grep(/^\Q$usec\E$/,@{$sections})) {
7408: $secmatch = 1;
7409: }
7410: }
7411: if (!$secmatch) {
7412: next;
7413: }
1.288 raeburn 7414: }
1.419 raeburn 7415: if ($usec eq '') {
7416: $usec = 'none';
7417: }
1.275 raeburn 7418: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7419: if ($hidepriv) {
7420: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7421: (!$nothide{$uname.':'.$udom})) {
7422: next;
7423: }
7424: }
1.503 raeburn 7425: if ($end > 0 && $end < $now) {
1.439 raeburn 7426: $status = 'previous';
7427: } elsif ($start > $now) {
7428: $status = 'future';
7429: } else {
7430: $status = 'active';
7431: }
1.277 albertel 7432: foreach my $type (keys(%{$types})) {
1.275 raeburn 7433: if ($status eq $type) {
1.420 albertel 7434: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7435: push(@{$$users{$role}{$user}},$type);
7436: }
1.288 raeburn 7437: $match = 1;
7438: }
7439: }
1.419 raeburn 7440: if (($match) && (ref($userdata) eq 'HASH')) {
7441: if (!exists($$userdata{$uname.':'.$udom})) {
7442: &get_user_info($udom,$uname,\%idx,$userdata);
7443: }
1.420 albertel 7444: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7445: push(@{$seclists{$uname.':'.$udom}},$usec);
7446: }
1.609 raeburn 7447: if (ref($statushash) eq 'HASH') {
7448: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7449: }
1.275 raeburn 7450: }
7451: }
7452: }
7453: }
1.290 albertel 7454: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7455: if ((defined($cdom)) && (defined($cnum))) {
7456: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7457: if ( defined($csettings{'internal.courseowner'}) ) {
7458: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7459: next if ($owner eq '');
7460: my ($ownername,$ownerdom);
7461: if ($owner =~ /^([^:]+):([^:]+)$/) {
7462: $ownername = $1;
7463: $ownerdom = $2;
7464: } else {
7465: $ownername = $owner;
7466: $ownerdom = $cdom;
7467: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7468: }
7469: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7470: if (defined($userdata) &&
1.609 raeburn 7471: !exists($$userdata{$owner})) {
7472: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7473: if (!grep(/^none$/,@{$seclists{$owner}})) {
7474: push(@{$seclists{$owner}},'none');
7475: }
7476: if (ref($statushash) eq 'HASH') {
7477: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7478: }
1.290 albertel 7479: }
1.279 raeburn 7480: }
7481: }
7482: }
1.419 raeburn 7483: foreach my $user (keys(%seclists)) {
7484: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7485: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7486: }
1.275 raeburn 7487: }
7488: return;
7489: }
7490:
1.288 raeburn 7491: sub get_user_info {
7492: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7493: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7494: &plainname($uname,$udom,'lastname');
1.291 albertel 7495: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7496: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7497: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7498: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7499: return;
7500: }
1.275 raeburn 7501:
1.472 raeburn 7502: ###############################################
7503:
7504: =pod
7505:
7506: =item * &get_user_quota()
7507:
7508: Retrieves quota assigned for storage of portfolio files for a user
7509:
7510: Incoming parameters:
7511: 1. user's username
7512: 2. user's domain
7513:
7514: Returns:
1.536 raeburn 7515: 1. Disk quota (in Mb) assigned to student.
7516: 2. (Optional) Type of setting: custom or default
7517: (individually assigned or default for user's
7518: institutional status).
7519: 3. (Optional) - User's institutional status (e.g., faculty, staff
7520: or student - types as defined in localenroll::inst_usertypes
7521: for user's domain, which determines default quota for user.
7522: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7523:
7524: If a value has been stored in the user's environment,
1.536 raeburn 7525: it will return that, otherwise it returns the maximal default
7526: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7527:
7528: =cut
7529:
7530: ###############################################
7531:
7532:
7533: sub get_user_quota {
7534: my ($uname,$udom) = @_;
1.536 raeburn 7535: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7536: if (!defined($udom)) {
7537: $udom = $env{'user.domain'};
7538: }
7539: if (!defined($uname)) {
7540: $uname = $env{'user.name'};
7541: }
7542: if (($udom eq '' || $uname eq '') ||
7543: ($udom eq 'public') && ($uname eq 'public')) {
7544: $quota = 0;
1.536 raeburn 7545: $quotatype = 'default';
7546: $defquota = 0;
1.472 raeburn 7547: } else {
1.536 raeburn 7548: my $inststatus;
1.472 raeburn 7549: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7550: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7551: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7552: } else {
1.536 raeburn 7553: my %userenv =
7554: &Apache::lonnet::get('environment',['portfolioquota',
7555: 'inststatus'],$udom,$uname);
1.472 raeburn 7556: my ($tmp) = keys(%userenv);
7557: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7558: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7559: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7560: } else {
7561: undef(%userenv);
7562: }
7563: }
1.536 raeburn 7564: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7565: if ($quota eq '') {
1.536 raeburn 7566: $quota = $defquota;
7567: $quotatype = 'default';
7568: } else {
7569: $quotatype = 'custom';
1.472 raeburn 7570: }
7571: }
1.536 raeburn 7572: if (wantarray) {
7573: return ($quota,$quotatype,$settingstatus,$defquota);
7574: } else {
7575: return $quota;
7576: }
1.472 raeburn 7577: }
7578:
7579: ###############################################
7580:
7581: =pod
7582:
7583: =item * &default_quota()
7584:
1.536 raeburn 7585: Retrieves default quota assigned for storage of user portfolio files,
7586: given an (optional) user's institutional status.
1.472 raeburn 7587:
7588: Incoming parameters:
7589: 1. domain
1.536 raeburn 7590: 2. (Optional) institutional status(es). This is a : separated list of
7591: status types (e.g., faculty, staff, student etc.)
7592: which apply to the user for whom the default is being retrieved.
7593: If the institutional status string in undefined, the domain
7594: default quota will be returned.
1.472 raeburn 7595:
7596: Returns:
7597: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7598: 2. (Optional) institutional type which determined the value of the
7599: default quota.
1.472 raeburn 7600:
7601: If a value has been stored in the domain's configuration db,
7602: it will return that, otherwise it returns 20 (for backwards
7603: compatibility with domains which have not set up a configuration
7604: db file; the original statically defined portfolio quota was 20 Mb).
7605:
1.536 raeburn 7606: If the user's status includes multiple types (e.g., staff and student),
7607: the largest default quota which applies to the user determines the
7608: default quota returned.
7609:
1.780 raeburn 7610: =back
7611:
1.472 raeburn 7612: =cut
7613:
7614: ###############################################
7615:
7616:
7617: sub default_quota {
1.536 raeburn 7618: my ($udom,$inststatus) = @_;
7619: my ($defquota,$settingstatus);
7620: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7621: ['quotas'],$udom);
7622: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7623: if ($inststatus ne '') {
1.765 raeburn 7624: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7625: foreach my $item (@statuses) {
1.711 raeburn 7626: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7627: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7628: if ($defquota eq '') {
7629: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7630: $settingstatus = $item;
7631: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7632: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7633: $settingstatus = $item;
7634: }
7635: }
7636: } else {
7637: if ($quotahash{'quotas'}{$item} ne '') {
7638: if ($defquota eq '') {
7639: $defquota = $quotahash{'quotas'}{$item};
7640: $settingstatus = $item;
7641: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7642: $defquota = $quotahash{'quotas'}{$item};
7643: $settingstatus = $item;
7644: }
1.536 raeburn 7645: }
7646: }
7647: }
7648: }
7649: if ($defquota eq '') {
1.711 raeburn 7650: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7651: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7652: } else {
7653: $defquota = $quotahash{'quotas'}{'default'};
7654: }
1.536 raeburn 7655: $settingstatus = 'default';
7656: }
7657: } else {
7658: $settingstatus = 'default';
7659: $defquota = 20;
7660: }
7661: if (wantarray) {
7662: return ($defquota,$settingstatus);
1.472 raeburn 7663: } else {
1.536 raeburn 7664: return $defquota;
1.472 raeburn 7665: }
7666: }
7667:
1.384 raeburn 7668: sub get_secgrprole_info {
7669: my ($cdom,$cnum,$needroles,$type) = @_;
7670: my %sections_count = &get_sections($cdom,$cnum);
7671: my @sections = (sort {$a <=> $b} keys(%sections_count));
7672: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7673: my @groups = sort(keys(%curr_groups));
7674: my $allroles = [];
7675: my $rolehash;
7676: my $accesshash = {
7677: active => 'Currently has access',
7678: future => 'Will have future access',
7679: previous => 'Previously had access',
7680: };
7681: if ($needroles) {
7682: $rolehash = {'all' => 'all'};
1.385 albertel 7683: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7684: if (&Apache::lonnet::error(%user_roles)) {
7685: undef(%user_roles);
7686: }
7687: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7688: my ($role)=split(/\:/,$item,2);
7689: if ($role eq 'cr') { next; }
7690: if ($role =~ /^cr/) {
7691: $$rolehash{$role} = (split('/',$role))[3];
7692: } else {
7693: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7694: }
7695: }
7696: foreach my $key (sort(keys(%{$rolehash}))) {
7697: push(@{$allroles},$key);
7698: }
7699: push (@{$allroles},'st');
7700: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7701: }
7702: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7703: }
7704:
1.555 raeburn 7705: sub user_picker {
1.994 raeburn 7706: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 7707: my $currdom = $dom;
7708: my %curr_selected = (
7709: srchin => 'dom',
1.580 raeburn 7710: srchby => 'lastname',
1.555 raeburn 7711: );
7712: my $srchterm;
1.625 raeburn 7713: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7714: if ($srch->{'srchby'} ne '') {
7715: $curr_selected{'srchby'} = $srch->{'srchby'};
7716: }
7717: if ($srch->{'srchin'} ne '') {
7718: $curr_selected{'srchin'} = $srch->{'srchin'};
7719: }
7720: if ($srch->{'srchtype'} ne '') {
7721: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7722: }
7723: if ($srch->{'srchdomain'} ne '') {
7724: $currdom = $srch->{'srchdomain'};
7725: }
7726: $srchterm = $srch->{'srchterm'};
7727: }
7728: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7729: 'usr' => 'Search criteria',
1.563 raeburn 7730: 'doma' => 'Domain/institution to search',
1.558 albertel 7731: 'uname' => 'username',
7732: 'lastname' => 'last name',
1.555 raeburn 7733: 'lastfirst' => 'last name, first name',
1.558 albertel 7734: 'crs' => 'in this course',
1.576 raeburn 7735: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7736: 'alc' => 'all LON-CAPA',
1.573 raeburn 7737: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7738: 'exact' => 'is',
7739: 'contains' => 'contains',
1.569 raeburn 7740: 'begins' => 'begins with',
1.571 raeburn 7741: 'youm' => "You must include some text to search for.",
7742: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7743: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7744: 'yomc' => "You must choose a domain when using an institutional directory search.",
7745: 'ymcd' => "You must choose a domain when using a domain search.",
7746: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7747: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7748: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7749: );
1.563 raeburn 7750: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7751: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7752:
7753: my @srchins = ('crs','dom','alc','instd');
7754:
7755: foreach my $option (@srchins) {
7756: # FIXME 'alc' option unavailable until
7757: # loncreateuser::print_user_query_page()
7758: # has been completed.
7759: next if ($option eq 'alc');
1.880 raeburn 7760: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7761: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7762: if ($curr_selected{'srchin'} eq $option) {
7763: $srchinsel .= '
7764: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7765: } else {
7766: $srchinsel .= '
7767: <option value="'.$option.'">'.$lt{$option}.'</option>';
7768: }
1.555 raeburn 7769: }
1.563 raeburn 7770: $srchinsel .= "\n </select>\n";
1.555 raeburn 7771:
7772: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7773: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7774: if ($curr_selected{'srchby'} eq $option) {
7775: $srchbysel .= '
7776: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7777: } else {
7778: $srchbysel .= '
7779: <option value="'.$option.'">'.$lt{$option}.'</option>';
7780: }
7781: }
7782: $srchbysel .= "\n </select>\n";
7783:
7784: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7785: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7786: if ($curr_selected{'srchtype'} eq $option) {
7787: $srchtypesel .= '
7788: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7789: } else {
7790: $srchtypesel .= '
7791: <option value="'.$option.'">'.$lt{$option}.'</option>';
7792: }
7793: }
7794: $srchtypesel .= "\n </select>\n";
7795:
1.558 albertel 7796: my ($newuserscript,$new_user_create);
1.994 raeburn 7797: my $context_dom = $env{'request.role.domain'};
7798: if ($context eq 'requestcrs') {
7799: if ($env{'form.coursedom'} ne '') {
7800: $context_dom = $env{'form.coursedom'};
7801: }
7802: }
1.556 raeburn 7803: if ($forcenewuser) {
1.576 raeburn 7804: if (ref($srch) eq 'HASH') {
1.994 raeburn 7805: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 7806: if ($cancreate) {
7807: $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>';
7808: } else {
1.799 bisitz 7809: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7810: my %usertypetext = (
7811: official => 'institutional',
7812: unofficial => 'non-institutional',
7813: );
1.799 bisitz 7814: $new_user_create = '<p class="LC_warning">'
7815: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7816: .' '
7817: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7818: ,'<a href="'.$helplink.'">','</a>')
7819: .'</p><br />';
1.627 raeburn 7820: }
1.576 raeburn 7821: }
7822: }
7823:
1.556 raeburn 7824: $newuserscript = <<"ENDSCRIPT";
7825:
1.570 raeburn 7826: function setSearch(createnew,callingForm) {
1.556 raeburn 7827: if (createnew == 1) {
1.570 raeburn 7828: for (var i=0; i<callingForm.srchby.length; i++) {
7829: if (callingForm.srchby.options[i].value == 'uname') {
7830: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7831: }
7832: }
1.570 raeburn 7833: for (var i=0; i<callingForm.srchin.length; i++) {
7834: if ( callingForm.srchin.options[i].value == 'dom') {
7835: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7836: }
7837: }
1.570 raeburn 7838: for (var i=0; i<callingForm.srchtype.length; i++) {
7839: if (callingForm.srchtype.options[i].value == 'exact') {
7840: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7841: }
7842: }
1.570 raeburn 7843: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 7844: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 7845: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7846: }
7847: }
7848: }
7849: }
7850: ENDSCRIPT
1.558 albertel 7851:
1.556 raeburn 7852: }
7853:
1.555 raeburn 7854: my $output = <<"END_BLOCK";
1.556 raeburn 7855: <script type="text/javascript">
1.824 bisitz 7856: // <![CDATA[
1.570 raeburn 7857: function validateEntry(callingForm) {
1.558 albertel 7858:
1.556 raeburn 7859: var checkok = 1;
1.558 albertel 7860: var srchin;
1.570 raeburn 7861: for (var i=0; i<callingForm.srchin.length; i++) {
7862: if ( callingForm.srchin[i].checked ) {
7863: srchin = callingForm.srchin[i].value;
1.558 albertel 7864: }
7865: }
7866:
1.570 raeburn 7867: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7868: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7869: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7870: var srchterm = callingForm.srchterm.value;
7871: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7872: var msg = "";
7873:
7874: if (srchterm == "") {
7875: checkok = 0;
1.571 raeburn 7876: msg += "$lt{'youm'}\\n";
1.556 raeburn 7877: }
7878:
1.569 raeburn 7879: if (srchtype== 'begins') {
7880: if (srchterm.length < 2) {
7881: checkok = 0;
1.571 raeburn 7882: msg += "$lt{'thte'}\\n";
1.569 raeburn 7883: }
7884: }
7885:
1.556 raeburn 7886: if (srchtype== 'contains') {
7887: if (srchterm.length < 3) {
7888: checkok = 0;
1.571 raeburn 7889: msg += "$lt{'thet'}\\n";
1.556 raeburn 7890: }
7891: }
7892: if (srchin == 'instd') {
7893: if (srchdomain == '') {
7894: checkok = 0;
1.571 raeburn 7895: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7896: }
7897: }
7898: if (srchin == 'dom') {
7899: if (srchdomain == '') {
7900: checkok = 0;
1.571 raeburn 7901: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7902: }
7903: }
7904: if (srchby == 'lastfirst') {
7905: if (srchterm.indexOf(",") == -1) {
7906: checkok = 0;
1.571 raeburn 7907: msg += "$lt{'whus'}\\n";
1.556 raeburn 7908: }
7909: if (srchterm.indexOf(",") == srchterm.length -1) {
7910: checkok = 0;
1.571 raeburn 7911: msg += "$lt{'whse'}\\n";
1.556 raeburn 7912: }
7913: }
7914: if (checkok == 0) {
1.571 raeburn 7915: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7916: return;
7917: }
7918: if (checkok == 1) {
1.570 raeburn 7919: callingForm.submit();
1.556 raeburn 7920: }
7921: }
7922:
7923: $newuserscript
7924:
1.824 bisitz 7925: // ]]>
1.556 raeburn 7926: </script>
1.558 albertel 7927:
7928: $new_user_create
7929:
1.555 raeburn 7930: END_BLOCK
1.558 albertel 7931:
1.876 raeburn 7932: $output .= &Apache::lonhtmlcommon::start_pick_box().
7933: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7934: $domform.
7935: &Apache::lonhtmlcommon::row_closure().
7936: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7937: $srchbysel.
7938: $srchtypesel.
7939: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7940: $srchinsel.
7941: &Apache::lonhtmlcommon::row_closure(1).
7942: &Apache::lonhtmlcommon::end_pick_box().
7943: '<br />';
1.555 raeburn 7944: return $output;
7945: }
7946:
1.612 raeburn 7947: sub user_rule_check {
1.615 raeburn 7948: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7949: my $response;
7950: if (ref($usershash) eq 'HASH') {
7951: foreach my $user (keys(%{$usershash})) {
7952: my ($uname,$udom) = split(/:/,$user);
7953: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7954: my ($id,$newuser);
1.612 raeburn 7955: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7956: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7957: $id = $usershash->{$user}->{'id'};
7958: }
7959: my $inst_response;
7960: if (ref($checks) eq 'HASH') {
7961: if (defined($checks->{'username'})) {
1.615 raeburn 7962: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7963: &Apache::lonnet::get_instuser($udom,$uname);
7964: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7965: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7966: &Apache::lonnet::get_instuser($udom,undef,$id);
7967: }
1.615 raeburn 7968: } else {
7969: ($inst_response,%{$inst_results->{$user}}) =
7970: &Apache::lonnet::get_instuser($udom,$uname);
7971: return;
1.612 raeburn 7972: }
1.615 raeburn 7973: if (!$got_rules->{$udom}) {
1.612 raeburn 7974: my %domconfig = &Apache::lonnet::get_dom('configuration',
7975: ['usercreation'],$udom);
7976: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7977: foreach my $item ('username','id') {
1.612 raeburn 7978: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7979: $$curr_rules{$udom}{$item} =
7980: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7981: }
7982: }
7983: }
1.615 raeburn 7984: $got_rules->{$udom} = 1;
1.585 raeburn 7985: }
1.612 raeburn 7986: foreach my $item (keys(%{$checks})) {
7987: if (ref($$curr_rules{$udom}) eq 'HASH') {
7988: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7989: if (@{$$curr_rules{$udom}{$item}} > 0) {
7990: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7991: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7992: if ($rule_check{$rule}) {
7993: $$rulematch{$user}{$item} = $rule;
7994: if ($inst_response eq 'ok') {
1.615 raeburn 7995: if (ref($inst_results) eq 'HASH') {
7996: if (ref($inst_results->{$user}) eq 'HASH') {
7997: if (keys(%{$inst_results->{$user}}) == 0) {
7998: $$alerts{$item}{$udom}{$uname} = 1;
7999: }
1.612 raeburn 8000: }
8001: }
1.615 raeburn 8002: }
8003: last;
1.585 raeburn 8004: }
8005: }
8006: }
8007: }
8008: }
8009: }
8010: }
8011: }
1.612 raeburn 8012: return;
8013: }
8014:
8015: sub user_rule_formats {
8016: my ($domain,$domdesc,$curr_rules,$check) = @_;
8017: my %text = (
8018: 'username' => 'Usernames',
8019: 'id' => 'IDs',
8020: );
8021: my $output;
8022: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8023: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8024: if (@{$ruleorder} > 0) {
8025: $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>';
8026: foreach my $rule (@{$ruleorder}) {
8027: if (ref($curr_rules) eq 'ARRAY') {
8028: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8029: if (ref($rules->{$rule}) eq 'HASH') {
8030: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8031: $rules->{$rule}{'desc'}.'</li>';
8032: }
8033: }
8034: }
8035: }
8036: $output .= '</ul>';
8037: }
8038: }
8039: return $output;
8040: }
8041:
8042: sub instrule_disallow_msg {
1.615 raeburn 8043: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8044: my $response;
8045: my %text = (
8046: item => 'username',
8047: items => 'usernames',
8048: match => 'matches',
8049: do => 'does',
8050: action => 'a username',
8051: one => 'one',
8052: );
8053: if ($count > 1) {
8054: $text{'item'} = 'usernames';
8055: $text{'match'} ='match';
8056: $text{'do'} = 'do';
8057: $text{'action'} = 'usernames',
8058: $text{'one'} = 'ones';
8059: }
8060: if ($checkitem eq 'id') {
8061: $text{'items'} = 'IDs';
8062: $text{'item'} = 'ID';
8063: $text{'action'} = 'an ID';
1.615 raeburn 8064: if ($count > 1) {
8065: $text{'item'} = 'IDs';
8066: $text{'action'} = 'IDs';
8067: }
1.612 raeburn 8068: }
1.674 bisitz 8069: $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 8070: if ($mode eq 'upload') {
8071: if ($checkitem eq 'username') {
8072: $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'}.");
8073: } elsif ($checkitem eq 'id') {
1.674 bisitz 8074: $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 8075: }
1.669 raeburn 8076: } elsif ($mode eq 'selfcreate') {
8077: if ($checkitem eq 'id') {
8078: $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.");
8079: }
1.615 raeburn 8080: } else {
8081: if ($checkitem eq 'username') {
8082: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8083: } elsif ($checkitem eq 'id') {
8084: $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.");
8085: }
1.612 raeburn 8086: }
8087: return $response;
1.585 raeburn 8088: }
8089:
1.624 raeburn 8090: sub personal_data_fieldtitles {
8091: my %fieldtitles = &Apache::lonlocal::texthash (
8092: id => 'Student/Employee ID',
8093: permanentemail => 'E-mail address',
8094: lastname => 'Last Name',
8095: firstname => 'First Name',
8096: middlename => 'Middle Name',
8097: generation => 'Generation',
8098: gen => 'Generation',
1.765 raeburn 8099: inststatus => 'Affiliation',
1.624 raeburn 8100: );
8101: return %fieldtitles;
8102: }
8103:
1.642 raeburn 8104: sub sorted_inst_types {
8105: my ($dom) = @_;
8106: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8107: my $othertitle = &mt('All users');
8108: if ($env{'request.course.id'}) {
1.668 raeburn 8109: $othertitle = &mt('Any users');
1.642 raeburn 8110: }
8111: my @types;
8112: if (ref($order) eq 'ARRAY') {
8113: @types = @{$order};
8114: }
8115: if (@types == 0) {
8116: if (ref($usertypes) eq 'HASH') {
8117: @types = sort(keys(%{$usertypes}));
8118: }
8119: }
8120: if (keys(%{$usertypes}) > 0) {
8121: $othertitle = &mt('Other users');
8122: }
8123: return ($othertitle,$usertypes,\@types);
8124: }
8125:
1.645 raeburn 8126: sub get_institutional_codes {
8127: my ($settings,$allcourses,$LC_code) = @_;
8128: # Get complete list of course sections to update
8129: my @currsections = ();
8130: my @currxlists = ();
8131: my $coursecode = $$settings{'internal.coursecode'};
8132:
8133: if ($$settings{'internal.sectionnums'} ne '') {
8134: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8135: }
8136:
8137: if ($$settings{'internal.crosslistings'} ne '') {
8138: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8139: }
8140:
8141: if (@currxlists > 0) {
8142: foreach (@currxlists) {
8143: if (m/^([^:]+):(\w*)$/) {
8144: unless (grep/^$1$/,@{$allcourses}) {
8145: push @{$allcourses},$1;
8146: $$LC_code{$1} = $2;
8147: }
8148: }
8149: }
8150: }
8151:
8152: if (@currsections > 0) {
8153: foreach (@currsections) {
8154: if (m/^(\w+):(\w*)$/) {
8155: my $sec = $coursecode.$1;
8156: my $lc_sec = $2;
8157: unless (grep/^$sec$/,@{$allcourses}) {
8158: push @{$allcourses},$sec;
8159: $$LC_code{$sec} = $lc_sec;
8160: }
8161: }
8162: }
8163: }
8164: return;
8165: }
8166:
1.971 raeburn 8167: sub get_standard_codeitems {
8168: return ('Year','Semester','Department','Number','Section');
8169: }
8170:
1.112 bowersj2 8171: =pod
8172:
1.780 raeburn 8173: =head1 Slot Helpers
8174:
8175: =over 4
8176:
8177: =item * sorted_slots()
8178:
8179: Sorts an array of slot names in order of slot start time (earliest first).
8180:
8181: Inputs:
8182:
8183: =over 4
8184:
8185: slotsarr - Reference to array of unsorted slot names.
8186:
8187: slots - Reference to hash of hash, where outer hash keys are slot names.
8188:
1.549 albertel 8189: =back
8190:
1.780 raeburn 8191: Returns:
8192:
8193: =over 4
8194:
8195: sorted - An array of slot names sorted by the start time of the slot.
8196:
8197: =back
8198:
8199: =back
8200:
8201: =cut
8202:
8203:
8204: sub sorted_slots {
8205: my ($slotsarr,$slots) = @_;
8206: my @sorted;
8207: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8208: @sorted =
8209: sort {
8210: if (ref($slots->{$a}) && ref($slots->{$b})) {
8211: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8212: }
8213: if (ref($slots->{$a})) { return -1;}
8214: if (ref($slots->{$b})) { return 1;}
8215: return 0;
8216: } @{$slotsarr};
8217: }
8218: return @sorted;
8219: }
8220:
8221:
8222: =pod
8223:
1.549 albertel 8224: =head1 HTTP Helpers
8225:
8226: =over 4
8227:
1.648 raeburn 8228: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8229:
1.258 albertel 8230: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8231: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8232: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8233:
8234: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8235: $possible_names is an ref to an array of form element names. As an example:
8236: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8237: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8238:
8239: =cut
1.1 albertel 8240:
1.6 albertel 8241: sub get_unprocessed_cgi {
1.25 albertel 8242: my ($query,$possible_names)= @_;
1.26 matthew 8243: # $Apache::lonxml::debug=1;
1.356 albertel 8244: foreach my $pair (split(/&/,$query)) {
8245: my ($name, $value) = split(/=/,$pair);
1.369 www 8246: $name = &unescape($name);
1.25 albertel 8247: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8248: $value =~ tr/+/ /;
8249: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8250: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8251: }
1.16 harris41 8252: }
1.6 albertel 8253: }
8254:
1.112 bowersj2 8255: =pod
8256:
1.648 raeburn 8257: =item * &cacheheader()
1.112 bowersj2 8258:
8259: returns cache-controlling header code
8260:
8261: =cut
8262:
1.7 albertel 8263: sub cacheheader {
1.258 albertel 8264: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8265: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8266: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8267: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8268: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8269: return $output;
1.7 albertel 8270: }
8271:
1.112 bowersj2 8272: =pod
8273:
1.648 raeburn 8274: =item * &no_cache($r)
1.112 bowersj2 8275:
8276: specifies header code to not have cache
8277:
8278: =cut
8279:
1.9 albertel 8280: sub no_cache {
1.216 albertel 8281: my ($r) = @_;
8282: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8283: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8284: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8285: $r->no_cache(1);
8286: $r->header_out("Expires" => $date);
8287: $r->header_out("Pragma" => "no-cache");
1.123 www 8288: }
8289:
8290: sub content_type {
1.181 albertel 8291: my ($r,$type,$charset) = @_;
1.299 foxr 8292: if ($r) {
8293: # Note that printout.pl calls this with undef for $r.
8294: &no_cache($r);
8295: }
1.258 albertel 8296: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8297: unless ($charset) {
8298: $charset=&Apache::lonlocal::current_encoding;
8299: }
8300: if ($charset) { $type.='; charset='.$charset; }
8301: if ($r) {
8302: $r->content_type($type);
8303: } else {
8304: print("Content-type: $type\n\n");
8305: }
1.9 albertel 8306: }
1.25 albertel 8307:
1.112 bowersj2 8308: =pod
8309:
1.648 raeburn 8310: =item * &add_to_env($name,$value)
1.112 bowersj2 8311:
1.258 albertel 8312: adds $name to the %env hash with value
1.112 bowersj2 8313: $value, if $name already exists, the entry is converted to an array
8314: reference and $value is added to the array.
8315:
8316: =cut
8317:
1.25 albertel 8318: sub add_to_env {
8319: my ($name,$value)=@_;
1.258 albertel 8320: if (defined($env{$name})) {
8321: if (ref($env{$name})) {
1.25 albertel 8322: #already have multiple values
1.258 albertel 8323: push(@{ $env{$name} },$value);
1.25 albertel 8324: } else {
8325: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8326: my $first=$env{$name};
8327: undef($env{$name});
8328: push(@{ $env{$name} },$first,$value);
1.25 albertel 8329: }
8330: } else {
1.258 albertel 8331: $env{$name}=$value;
1.25 albertel 8332: }
1.31 albertel 8333: }
1.149 albertel 8334:
8335: =pod
8336:
1.648 raeburn 8337: =item * &get_env_multiple($name)
1.149 albertel 8338:
1.258 albertel 8339: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8340: values may be defined and end up as an array ref.
8341:
8342: returns an array of values
8343:
8344: =cut
8345:
8346: sub get_env_multiple {
8347: my ($name) = @_;
8348: my @values;
1.258 albertel 8349: if (defined($env{$name})) {
1.149 albertel 8350: # exists is it an array
1.258 albertel 8351: if (ref($env{$name})) {
8352: @values=@{ $env{$name} };
1.149 albertel 8353: } else {
1.258 albertel 8354: $values[0]=$env{$name};
1.149 albertel 8355: }
8356: }
8357: return(@values);
8358: }
8359:
1.660 raeburn 8360: sub ask_for_embedded_content {
8361: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.987 raeburn 8362: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660 raeburn 8363: my $num = 0;
1.987 raeburn 8364: my $numremref = 0;
8365: my $numinvalid = 0;
8366: my $numpathchg = 0;
8367: my $numexisting = 0;
8368: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.984 raeburn 8369: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8370: my $current_path='/';
8371: if ($env{'form.currentpath'}) {
8372: $current_path = $env{'form.currentpath'};
8373: }
8374: if ($actionurl eq '/adm/coursegrp_portfolio') {
8375: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8376: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8377: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8378: } else {
8379: $udom = $env{'user.domain'};
8380: $uname = $env{'user.name'};
8381: $url = '/userfiles/portfolio';
8382: }
1.987 raeburn 8383: $toplevel = $url.'/';
1.984 raeburn 8384: $url .= $current_path;
8385: $getpropath = 1;
1.987 raeburn 8386: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8387: ($actionurl eq '/adm/imsimport')) {
1.984 raeburn 8388: ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
1.987 raeburn 8389: $url = '/home/'.$uname.'/public_html/';
8390: $toplevel = $url;
1.984 raeburn 8391: if ($rest ne '') {
1.987 raeburn 8392: $url .= $rest;
8393: }
8394: } elsif ($actionurl eq '/adm/coursedocs') {
8395: if (ref($args) eq 'HASH') {
8396: $url = $args->{'docs_url'};
8397: $toplevel = $url;
8398: }
8399: }
8400: my $now = time();
8401: foreach my $embed_file (keys(%{$allfiles})) {
8402: my $absolutepath;
8403: if ($embed_file =~ m{^\w+://}) {
8404: $newfiles{$embed_file} = 1;
8405: $mapping{$embed_file} = $embed_file;
8406: } else {
8407: if ($embed_file =~ m{^/}) {
8408: $absolutepath = $embed_file;
8409: $embed_file =~ s{^(/+)}{};
8410: }
8411: if ($embed_file =~ m{/}) {
8412: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8413: $path = &check_for_traversal($path,$url,$toplevel);
8414: my $item = $fname;
8415: if ($path ne '') {
8416: $item = $path.'/'.$fname;
8417: $subdependencies{$path}{$fname} = 1;
8418: } else {
8419: $dependencies{$item} = 1;
8420: }
8421: if ($absolutepath) {
8422: $mapping{$item} = $absolutepath;
8423: } else {
8424: $mapping{$item} = $embed_file;
8425: }
8426: } else {
8427: $dependencies{$embed_file} = 1;
8428: if ($absolutepath) {
8429: $mapping{$embed_file} = $absolutepath;
8430: } else {
8431: $mapping{$embed_file} = $embed_file;
8432: }
8433: }
1.984 raeburn 8434: }
8435: }
8436: foreach my $path (keys(%subdependencies)) {
8437: my %currsubfile;
8438: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8439: my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8440: foreach my $line (@subdir_list) {
8441: my ($file_name,$rest) = split(/\&/,$line,2);
8442: $currsubfile{$file_name} = 1;
8443: }
1.987 raeburn 8444: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 8445: if (opendir(my $dir,$url.'/'.$path)) {
8446: my @subdir_list = grep(!/^\./,readdir($dir));
8447: map {$currsubfile{$_} = 1;} @subdir_list;
8448: }
8449: }
8450: foreach my $file (keys(%{$subdependencies{$path}})) {
1.987 raeburn 8451: if ($currsubfile{$file}) {
8452: my $item = $path.'/'.$file;
8453: unless ($mapping{$item} eq $item) {
8454: $pathchanges{$item} = 1;
8455: }
8456: $existing{$item} = 1;
8457: $numexisting ++;
8458: } else {
8459: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 8460: }
8461: }
8462: }
1.987 raeburn 8463: my %currfile;
1.984 raeburn 8464: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8465: my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8466: foreach my $line (@dir_list) {
8467: my ($file_name,$rest) = split(/\&/,$line,2);
8468: $currfile{$file_name} = 1;
8469: }
1.987 raeburn 8470: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 8471: if (opendir(my $dir,$url)) {
1.987 raeburn 8472: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 8473: map {$currfile{$_} = 1;} @dir_list;
8474: }
8475: }
8476: foreach my $file (keys(%dependencies)) {
1.987 raeburn 8477: if ($currfile{$file}) {
8478: unless ($mapping{$file} eq $file) {
8479: $pathchanges{$file} = 1;
8480: }
8481: $existing{$file} = 1;
8482: $numexisting ++;
8483: } else {
1.984 raeburn 8484: $newfiles{$file} = 1;
8485: }
8486: }
8487: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8488: $upload_output .= &start_data_table_row().
1.987 raeburn 8489: '<td><span class="LC_filename">'.$embed_file.'</span>';
8490: unless ($mapping{$embed_file} eq $embed_file) {
8491: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
8492: }
8493: $upload_output .= '</td><td>';
1.660 raeburn 8494: if ($args->{'ignore_remote_references'}
8495: && $embed_file =~ m{^\w+://}) {
8496: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 8497: $numremref++;
1.660 raeburn 8498: } elsif ($args->{'error_on_invalid_names'}
8499: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8500:
1.987 raeburn 8501: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
8502: $numinvalid++;
1.660 raeburn 8503: } else {
1.987 raeburn 8504: $upload_output .= &embedded_file_element('upload_embedded',$num,
8505: $embed_file,\%mapping,
8506: $allfiles,$codebase);
8507: $num++;
8508: }
8509: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
8510: }
8511: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
8512: $upload_output .= &start_data_table_row().
8513: '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
8514: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
8515: &Apache::loncommon::end_data_table_row()."\n";
8516: }
8517: if ($upload_output) {
8518: $upload_output = &start_data_table().
8519: $upload_output.
8520: &end_data_table()."\n";
8521: }
8522: my $applies = 0;
8523: if ($numremref) {
8524: $applies ++;
8525: }
8526: if ($numinvalid) {
8527: $applies ++;
8528: }
8529: if ($numexisting) {
8530: $applies ++;
8531: }
8532: if ($num) {
8533: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8534: ' method="post" enctype="multipart/form-data">'."\n".
8535: $state.
8536: '<h3>'.&mt('Upload embedded files').
8537: ':</h3>'.$upload_output.'<br />'."\n".
8538: '<input type ="hidden" name="number_embedded_items" value="'.
8539: $num.'" />'."\n";
8540: if ($actionurl eq '') {
8541: $output .= '<input type="hidden" name="phase" value="three" />';
8542: }
8543: } elsif ($applies) {
8544: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
8545: if ($applies > 1) {
8546: $output .=
8547: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
8548: if ($numremref) {
8549: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
8550: }
8551: if ($numinvalid) {
8552: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
8553: }
8554: if ($numexisting) {
8555: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
8556: }
8557: $output .= '</ul><br />';
8558: } elsif ($numremref) {
8559: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
8560: } elsif ($numinvalid) {
8561: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
8562: } elsif ($numexisting) {
8563: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
8564: }
8565: $output .= $upload_output.'<br />';
8566: }
8567: my ($pathchange_output,$chgcount);
8568: $chgcount = $num;
8569: if (keys(%pathchanges) > 0) {
8570: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
8571: if ($num) {
8572: $output .= &embedded_file_element('pathchange',$chgcount,
8573: $embed_file,\%mapping,
8574: $allfiles,$codebase);
8575: } else {
8576: $pathchange_output .=
8577: &start_data_table_row().
8578: '<td><input type ="checkbox" name="namechange" value="'.
8579: $chgcount.'" checked="checked" /></td>'.
8580: '<td>'.$mapping{$embed_file}.'</td>'.
8581: '<td>'.$embed_file.
8582: &embedded_file_element('pathchange',$numpathchg,$embed_file,
8583: \%mapping,$allfiles,$codebase).
8584: '</td>'.&end_data_table_row();
1.660 raeburn 8585: }
1.987 raeburn 8586: $numpathchg ++;
8587: $chgcount ++;
1.660 raeburn 8588: }
8589: }
1.984 raeburn 8590: if ($num) {
1.987 raeburn 8591: if ($numpathchg) {
8592: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
8593: $numpathchg.'" />'."\n";
8594: }
8595: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8596: ($actionurl eq '/adm/imsimport')) {
8597: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
8598: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
8599: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
8600: }
8601: $output .= '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8602: &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
8603: } elsif ($numpathchg) {
8604: my %pathchange = ();
8605: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
8606: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8607: $output .= '<p>'.&mt('or').'</p>';
8608: }
8609: }
8610: return ($output,$num,$numpathchg);
8611: }
8612:
8613: sub embedded_file_element {
8614: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
8615: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
8616: (ref($codebase) eq 'HASH'));
8617: my $output;
8618: if ($context eq 'upload_embedded') {
8619: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
8620: }
8621: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
8622: &escape($embed_file).'" />';
8623: unless (($context eq 'upload_embedded') &&
8624: ($mapping->{$embed_file} eq $embed_file)) {
8625: $output .='
8626: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
8627: }
8628: my $attrib;
8629: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
8630: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
8631: }
8632: $output .=
8633: "\n\t\t".
8634: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8635: $attrib.'" />';
8636: if (exists($codebase->{$mapping->{$embed_file}})) {
8637: $output .=
8638: "\n\t\t".
8639: '<input name="codebase_'.$num.'" type="hidden" value="'.
8640: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 8641: }
1.987 raeburn 8642: return $output;
1.660 raeburn 8643: }
8644:
1.661 raeburn 8645: sub upload_embedded {
8646: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 8647: $current_disk_usage,$hiddenstate,$actionurl) = @_;
8648: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 8649: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8650: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8651: my $orig_uploaded_filename =
8652: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 8653: foreach my $type ('orig','ref','attrib','codebase') {
8654: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
8655: $env{'form.embedded_'.$type.'_'.$i} =
8656: &unescape($env{'form.embedded_'.$type.'_'.$i});
8657: }
8658: }
1.661 raeburn 8659: my ($path,$fname) =
8660: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8661: # no path, whole string is fname
8662: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8663: $fname = &Apache::lonnet::clean_filename($fname);
8664: # See if there is anything left
8665: next if ($fname eq '');
8666:
8667: # Check if file already exists as a file or directory.
8668: my ($state,$msg);
8669: if ($context eq 'portfolio') {
8670: my $port_path = $dirpath;
8671: if ($group ne '') {
8672: $port_path = "groups/$group/$port_path";
8673: }
1.987 raeburn 8674: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
8675: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 8676: $dir_root,$port_path,$disk_quota,
8677: $current_disk_usage,$uname,$udom);
8678: if ($state eq 'will_exceed_quota'
1.984 raeburn 8679: || $state eq 'file_locked') {
1.661 raeburn 8680: $output .= $msg;
8681: next;
8682: }
8683: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8684: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8685: if ($state eq 'exists') {
8686: $output .= $msg;
8687: next;
8688: }
8689: }
8690: # Check if extension is valid
8691: if (($fname =~ /\.(\w+)$/) &&
8692: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 8693: $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 8694: next;
8695: } elsif (($fname =~ /\.(\w+)$/) &&
8696: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 8697: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 8698: next;
8699: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 8700: $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 8701: next;
8702: }
8703:
8704: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8705: if ($context eq 'portfolio') {
1.984 raeburn 8706: my $result;
8707: if ($state eq 'existingfile') {
8708: $result=
8709: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 8710: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 8711: } else {
1.984 raeburn 8712: $result=
8713: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 8714: $dirpath.
8715: $env{'form.currentpath'}.$path);
1.984 raeburn 8716: if ($result !~ m|^/uploaded/|) {
8717: $output .= '<span class="LC_error">'
8718: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8719: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8720: .'</span><br />';
8721: next;
8722: } else {
1.987 raeburn 8723: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8724: $path.$fname.'</span>').'<br />';
1.984 raeburn 8725: }
1.661 raeburn 8726: }
1.987 raeburn 8727: } elsif ($context eq 'coursedoc') {
8728: my $result =
8729: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
8730: $dirpath.'/'.$path);
8731: if ($result !~ m|^/uploaded/|) {
8732: $output .= '<span class="LC_error">'
8733: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8734: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8735: .'</span><br />';
8736: next;
8737: } else {
8738: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8739: $path.$fname.'</span>').'<br />';
8740: }
1.661 raeburn 8741: } else {
8742: # Save the file
8743: my $target = $env{'form.embedded_item_'.$i};
8744: my $fullpath = $dir_root.$dirpath.'/'.$path;
8745: my $dest = $fullpath.$fname;
8746: my $url = $url_root.$dirpath.'/'.$path.$fname;
8747: my @parts=split(/\//,$fullpath);
8748: my $count;
8749: my $filepath = $dir_root;
8750: for ($count=4;$count<=$#parts;$count++) {
8751: $filepath .= "/$parts[$count]";
8752: if ((-e $filepath)!=1) {
8753: mkdir($filepath,0770);
8754: }
8755: }
8756: my $fh;
8757: if (!open($fh,'>'.$dest)) {
8758: &Apache::lonnet::logthis('Failed to create '.$dest);
8759: $output .= '<span class="LC_error">'.
8760: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8761: '</span><br />';
8762: } else {
8763: if (!print $fh $env{'form.embedded_item_'.$i}) {
8764: &Apache::lonnet::logthis('Failed to write to '.$dest);
8765: $output .= '<span class="LC_error">'.
8766: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8767: '</span><br />';
8768: } else {
1.987 raeburn 8769: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8770: $url.'</span>').'<br />';
8771: unless ($context eq 'testbank') {
8772: $footer .= &mt('View embedded file: [_1]',
8773: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
8774: }
8775: }
8776: close($fh);
8777: }
8778: }
8779: if ($env{'form.embedded_ref_'.$i}) {
8780: $pathchange{$i} = 1;
8781: }
8782: }
8783: if ($output) {
8784: $output = '<p>'.$output.'</p>';
8785: }
8786: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
8787: $returnflag = 'ok';
8788: if (keys(%pathchange) > 0) {
8789: if ($context eq 'portfolio') {
8790: $output .= '<p>'.&mt('or').'</p>';
8791: } elsif ($context eq 'testbank') {
1.988 raeburn 8792: $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 8793: $returnflag = 'modify_orightml';
8794: }
8795: }
8796: return ($output.$footer,$returnflag);
8797: }
8798:
8799: sub modify_html_form {
8800: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
8801: my $end = 0;
8802: my $modifyform;
8803: if ($context eq 'upload_embedded') {
8804: return unless (ref($pathchange) eq 'HASH');
8805: if ($env{'form.number_embedded_items'}) {
8806: $end += $env{'form.number_embedded_items'};
8807: }
8808: if ($env{'form.number_pathchange_items'}) {
8809: $end += $env{'form.number_pathchange_items'};
8810: }
8811: if ($end) {
8812: for (my $i=0; $i<$end; $i++) {
8813: if ($i < $env{'form.number_embedded_items'}) {
8814: next unless($pathchange->{$i});
8815: }
8816: $modifyform .=
8817: &start_data_table_row().
8818: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
8819: 'checked="checked" /></td>'.
8820: '<td>'.$env{'form.embedded_ref_'.$i}.
8821: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
8822: &escape($env{'form.embedded_ref_'.$i}).'" />'.
8823: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
8824: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
8825: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
8826: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
8827: '<td>'.$env{'form.embedded_orig_'.$i}.
8828: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
8829: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
8830: &end_data_table_row();
8831: }
8832: }
8833: } else {
8834: $modifyform = $pathchgtable;
8835: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
8836: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
8837: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8838: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
8839: }
8840: }
8841: if ($modifyform) {
8842: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
8843: '<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".
8844: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
8845: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
8846: '</ol></p>'."\n".'<p>'.
8847: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
8848: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
8849: &start_data_table()."\n".
8850: &start_data_table_header_row().
8851: '<th>'.&mt('Change?').'</th>'.
8852: '<th>'.&mt('Current reference').'</th>'.
8853: '<th>'.&mt('Required reference').'</th>'.
8854: &end_data_table_header_row()."\n".
8855: $modifyform.
8856: &end_data_table().'<br />'."\n".$hiddenstate.
8857: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
8858: '</form>'."\n";
8859: }
8860: return;
8861: }
8862:
8863: sub modify_html_refs {
8864: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
8865: my $container;
8866: if ($context eq 'portfolio') {
8867: $container = $env{'form.container'};
8868: } elsif ($context eq 'coursedoc') {
8869: $container = $env{'form.primaryurl'};
8870: } else {
8871: $container = $env{'form.filename'};
8872: $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
8873: }
8874: my (%allfiles,%codebase,$output,$content);
8875: my @changes = &get_env_multiple('form.namechange');
8876: return unless (@changes > 0);
8877: if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
8878: return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
8879: $content = &Apache::lonnet::getfile($container);
8880: return if ($content eq '-1');
8881: } else {
8882: return unless ($container =~ /^\Q$dir_root\E/);
8883: if (open(my $fh,"<$container")) {
8884: $content = join('', <$fh>);
8885: close($fh);
8886: } else {
8887: return;
8888: }
8889: }
8890: my ($count,$codebasecount) = (0,0);
8891: my $mm = new File::MMagic;
8892: my $mime_type = $mm->checktype_contents($content);
8893: if ($mime_type eq 'text/html') {
8894: my $parse_result =
8895: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
8896: \%codebase,\$content);
8897: if ($parse_result eq 'ok') {
8898: foreach my $i (@changes) {
8899: my $orig = &unescape($env{'form.embedded_orig_'.$i});
8900: my $ref = &unescape($env{'form.embedded_ref_'.$i});
8901: if ($allfiles{$ref}) {
8902: my $newname = $orig;
8903: my ($attrib_regexp,$codebase);
1.1006 raeburn 8904: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 8905: if ($attrib_regexp =~ /:/) {
8906: $attrib_regexp =~ s/\:/|/g;
8907: }
8908: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
8909: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
8910: $count += $numchg;
8911: }
8912: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 8913: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 8914: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
8915: $codebasecount ++;
8916: }
8917: }
8918: }
8919: if ($count || $codebasecount) {
8920: my $saveresult;
8921: if ($context eq 'portfolio' || $context eq 'coursedoc') {
8922: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
8923: if ($url eq $container) {
8924: my ($fname) = ($container =~ m{/([^/]+)$});
8925: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
8926: $count,'<span class="LC_filename">'.
8927: $fname.'</span>').'</p>';
8928: } else {
8929: $output = '<p class="LC_error">'.
8930: &mt('Error: update failed for: [_1].',
8931: '<span class="LC_filename">'.
8932: $container.'</span>').'</p>';
8933: }
8934: } else {
8935: if (open(my $fh,">$container")) {
8936: print $fh $content;
8937: close($fh);
8938: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
8939: $count,'<span class="LC_filename">'.
8940: $container.'</span>').'</p>';
1.661 raeburn 8941: } else {
1.987 raeburn 8942: $output = '<p class="LC_error">'.
8943: &mt('Error: could not update [_1].',
8944: '<span class="LC_filename">'.
8945: $container.'</span>').'</p>';
1.661 raeburn 8946: }
8947: }
8948: }
1.987 raeburn 8949: } else {
8950: &logthis('Failed to parse '.$container.
8951: ' to modify references: '.$parse_result);
1.661 raeburn 8952: }
8953: }
8954: return $output;
8955: }
8956:
8957: sub check_for_existing {
8958: my ($path,$fname,$element) = @_;
8959: my ($state,$msg);
8960: if (-d $path.'/'.$fname) {
8961: $state = 'exists';
8962: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8963: } elsif (-e $path.'/'.$fname) {
8964: $state = 'exists';
8965: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8966: }
8967: if ($state eq 'exists') {
8968: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8969: }
8970: return ($state,$msg);
8971: }
8972:
8973: sub check_for_upload {
8974: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8975: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 8976: my $filesize = length($env{'form.'.$element});
8977: if (!$filesize) {
8978: my $msg = '<span class="LC_error">'.
8979: &mt('Unable to upload [_1]. (size = [_2] bytes)',
8980: '<span class="LC_filename">'.$fname.'</span>',
8981: $filesize).'<br />'.
1.1007 raeburn 8982: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 8983: '</span>';
8984: return ('zero_bytes',$msg);
8985: }
8986: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 8987: my $getpropath = 1;
8988: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8989: $getpropath);
8990: my $found_file = 0;
8991: my $locked_file = 0;
1.991 raeburn 8992: my @lockers;
8993: my $navmap;
8994: if ($env{'request.course.id'}) {
8995: $navmap = Apache::lonnavmaps::navmap->new();
8996: }
1.661 raeburn 8997: foreach my $line (@dir_list) {
1.984 raeburn 8998: my ($file_name,$rest)=split(/\&/,$line,2);
1.661 raeburn 8999: if ($file_name eq $fname){
9000: $file_name = $path.$file_name;
9001: if ($group ne '') {
9002: $file_name = $group.$file_name;
9003: }
9004: $found_file = 1;
1.991 raeburn 9005: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
9006: foreach my $lock (@lockers) {
9007: if (ref($lock) eq 'ARRAY') {
9008: my ($symb,$crsid) = @{$lock};
9009: if ($crsid eq $env{'request.course.id'}) {
9010: if (ref($navmap)) {
9011: my $res = $navmap->getBySymb($symb);
9012: foreach my $part (@{$res->parts()}) {
9013: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
9014: unless (($slot_status == $res->RESERVED) ||
9015: ($slot_status == $res->RESERVED_LOCATION)) {
9016: $locked_file = 1;
9017: }
9018: }
9019: } else {
9020: $locked_file = 1;
9021: }
9022: } else {
9023: $locked_file = 1;
9024: }
9025: }
9026: }
1.984 raeburn 9027: } else {
9028: my @info = split(/\&/,$rest);
9029: my $currsize = $info[6]/1000;
9030: if ($currsize < $filesize) {
9031: my $extra = $filesize - $currsize;
9032: if (($current_disk_usage + $extra) > $disk_quota) {
9033: my $msg = '<span class="LC_error">'.
9034: &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.',
9035: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
9036: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
9037: $disk_quota,$current_disk_usage);
9038: return ('will_exceed_quota',$msg);
9039: }
9040: }
1.661 raeburn 9041: }
9042: }
9043: }
9044: if (($current_disk_usage + $filesize) > $disk_quota){
9045: my $msg = '<span class="LC_error">'.
9046: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
9047: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
9048: return ('will_exceed_quota',$msg);
9049: } elsif ($found_file) {
9050: if ($locked_file) {
9051: my $msg = '<span class="LC_error">';
9052: $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>');
9053: $msg .= '</span><br />';
9054: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
9055: return ('file_locked',$msg);
9056: } else {
9057: my $msg = '<span class="LC_error">';
1.984 raeburn 9058: $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 9059: $msg .= '</span>';
1.984 raeburn 9060: return ('existingfile',$msg);
1.661 raeburn 9061: }
9062: }
9063: }
9064:
1.987 raeburn 9065: sub check_for_traversal {
9066: my ($path,$url,$toplevel) = @_;
9067: my @parts=split(/\//,$path);
9068: my $cleanpath;
9069: my $fullpath = $url;
9070: for (my $i=0;$i<@parts;$i++) {
9071: next if ($parts[$i] eq '.');
9072: if ($parts[$i] eq '..') {
9073: $fullpath =~ s{([^/]+/)$}{};
9074: } else {
9075: $fullpath .= $parts[$i].'/';
9076: }
9077: }
9078: if ($fullpath =~ /^\Q$url\E(.*)$/) {
9079: $cleanpath = $1;
9080: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
9081: my $curr_toprel = $1;
9082: my @parts = split(/\//,$curr_toprel);
9083: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
9084: my @urlparts = split(/\//,$url_toprel);
9085: my $doubledots;
9086: my $startdiff = -1;
9087: for (my $i=0; $i<@urlparts; $i++) {
9088: if ($startdiff == -1) {
9089: unless ($urlparts[$i] eq $parts[$i]) {
9090: $startdiff = $i;
9091: $doubledots .= '../';
9092: }
9093: } else {
9094: $doubledots .= '../';
9095: }
9096: }
9097: if ($startdiff > -1) {
9098: $cleanpath = $doubledots;
9099: for (my $i=$startdiff; $i<@parts; $i++) {
9100: $cleanpath .= $parts[$i].'/';
9101: }
9102: }
9103: }
9104: $cleanpath =~ s{(/)$}{};
9105: return $cleanpath;
9106: }
1.31 albertel 9107:
1.41 ng 9108: =pod
1.45 matthew 9109:
1.464 albertel 9110: =back
1.41 ng 9111:
1.112 bowersj2 9112: =head1 CSV Upload/Handling functions
1.38 albertel 9113:
1.41 ng 9114: =over 4
9115:
1.648 raeburn 9116: =item * &upfile_store($r)
1.41 ng 9117:
9118: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 9119: needs $env{'form.upfile'}
1.41 ng 9120: returns $datatoken to be put into hidden field
9121:
9122: =cut
1.31 albertel 9123:
9124: sub upfile_store {
9125: my $r=shift;
1.258 albertel 9126: $env{'form.upfile'}=~s/\r/\n/gs;
9127: $env{'form.upfile'}=~s/\f/\n/gs;
9128: $env{'form.upfile'}=~s/\n+/\n/gs;
9129: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 9130:
1.258 albertel 9131: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
9132: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 9133: {
1.158 raeburn 9134: my $datafile = $r->dir_config('lonDaemons').
9135: '/tmp/'.$datatoken.'.tmp';
9136: if ( open(my $fh,">$datafile") ) {
1.258 albertel 9137: print $fh $env{'form.upfile'};
1.158 raeburn 9138: close($fh);
9139: }
1.31 albertel 9140: }
9141: return $datatoken;
9142: }
9143:
1.56 matthew 9144: =pod
9145:
1.648 raeburn 9146: =item * &load_tmp_file($r)
1.41 ng 9147:
9148: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 9149: needs $env{'form.datatoken'},
9150: sets $env{'form.upfile'} to the contents of the file
1.41 ng 9151:
9152: =cut
1.31 albertel 9153:
9154: sub load_tmp_file {
9155: my $r=shift;
9156: my @studentdata=();
9157: {
1.158 raeburn 9158: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 9159: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 9160: if ( open(my $fh,"<$studentfile") ) {
9161: @studentdata=<$fh>;
9162: close($fh);
9163: }
1.31 albertel 9164: }
1.258 albertel 9165: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 9166: }
9167:
1.56 matthew 9168: =pod
9169:
1.648 raeburn 9170: =item * &upfile_record_sep()
1.41 ng 9171:
9172: Separate uploaded file into records
9173: returns array of records,
1.258 albertel 9174: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 9175:
9176: =cut
1.31 albertel 9177:
9178: sub upfile_record_sep {
1.258 albertel 9179: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 9180: } else {
1.248 albertel 9181: my @records;
1.258 albertel 9182: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 9183: if ($line=~/^\s*$/) { next; }
9184: push(@records,$line);
9185: }
9186: return @records;
1.31 albertel 9187: }
9188: }
9189:
1.56 matthew 9190: =pod
9191:
1.648 raeburn 9192: =item * &record_sep($record)
1.41 ng 9193:
1.258 albertel 9194: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 9195:
9196: =cut
9197:
1.263 www 9198: sub takeleft {
9199: my $index=shift;
9200: return substr('0000'.$index,-4,4);
9201: }
9202:
1.31 albertel 9203: sub record_sep {
9204: my $record=shift;
9205: my %components=();
1.258 albertel 9206: if ($env{'form.upfiletype'} eq 'xml') {
9207: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 9208: my $i=0;
1.356 albertel 9209: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 9210: $field=~s/^(\"|\')//;
9211: $field=~s/(\"|\')$//;
1.263 www 9212: $components{&takeleft($i)}=$field;
1.31 albertel 9213: $i++;
9214: }
1.258 albertel 9215: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 9216: my $i=0;
1.356 albertel 9217: foreach my $field (split(/\t/,$record)) {
1.31 albertel 9218: $field=~s/^(\"|\')//;
9219: $field=~s/(\"|\')$//;
1.263 www 9220: $components{&takeleft($i)}=$field;
1.31 albertel 9221: $i++;
9222: }
9223: } else {
1.561 www 9224: my $separator=',';
1.480 banghart 9225: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 9226: $separator=';';
1.480 banghart 9227: }
1.31 albertel 9228: my $i=0;
1.561 www 9229: # the character we are looking for to indicate the end of a quote or a record
9230: my $looking_for=$separator;
9231: # do not add the characters to the fields
9232: my $ignore=0;
9233: # we just encountered a separator (or the beginning of the record)
9234: my $just_found_separator=1;
9235: # store the field we are working on here
9236: my $field='';
9237: # work our way through all characters in record
9238: foreach my $character ($record=~/(.)/g) {
9239: if ($character eq $looking_for) {
9240: if ($character ne $separator) {
9241: # Found the end of a quote, again looking for separator
9242: $looking_for=$separator;
9243: $ignore=1;
9244: } else {
9245: # Found a separator, store away what we got
9246: $components{&takeleft($i)}=$field;
9247: $i++;
9248: $just_found_separator=1;
9249: $ignore=0;
9250: $field='';
9251: }
9252: next;
9253: }
9254: # single or double quotation marks after a separator indicate beginning of a quote
9255: # we are now looking for the end of the quote and need to ignore separators
9256: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
9257: $looking_for=$character;
9258: next;
9259: }
9260: # ignore would be true after we reached the end of a quote
9261: if ($ignore) { next; }
9262: if (($just_found_separator) && ($character=~/\s/)) { next; }
9263: $field.=$character;
9264: $just_found_separator=0;
1.31 albertel 9265: }
1.561 www 9266: # catch the very last entry, since we never encountered the separator
9267: $components{&takeleft($i)}=$field;
1.31 albertel 9268: }
9269: return %components;
9270: }
9271:
1.144 matthew 9272: ######################################################
9273: ######################################################
9274:
1.56 matthew 9275: =pod
9276:
1.648 raeburn 9277: =item * &upfile_select_html()
1.41 ng 9278:
1.144 matthew 9279: Return HTML code to select a file from the users machine and specify
9280: the file type.
1.41 ng 9281:
9282: =cut
9283:
1.144 matthew 9284: ######################################################
9285: ######################################################
1.31 albertel 9286: sub upfile_select_html {
1.144 matthew 9287: my %Types = (
9288: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 9289: semisv => &mt('Semicolon separated values'),
1.144 matthew 9290: space => &mt('Space separated'),
9291: tab => &mt('Tabulator separated'),
9292: # xml => &mt('HTML/XML'),
9293: );
9294: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 9295: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 9296: foreach my $type (sort(keys(%Types))) {
9297: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
9298: }
9299: $Str .= "</select>\n";
9300: return $Str;
1.31 albertel 9301: }
9302:
1.301 albertel 9303: sub get_samples {
9304: my ($records,$toget) = @_;
9305: my @samples=({});
9306: my $got=0;
9307: foreach my $rec (@$records) {
9308: my %temp = &record_sep($rec);
9309: if (! grep(/\S/, values(%temp))) { next; }
9310: if (%temp) {
9311: $samples[$got]=\%temp;
9312: $got++;
9313: if ($got == $toget) { last; }
9314: }
9315: }
9316: return \@samples;
9317: }
9318:
1.144 matthew 9319: ######################################################
9320: ######################################################
9321:
1.56 matthew 9322: =pod
9323:
1.648 raeburn 9324: =item * &csv_print_samples($r,$records)
1.41 ng 9325:
9326: Prints a table of sample values from each column uploaded $r is an
9327: Apache Request ref, $records is an arrayref from
9328: &Apache::loncommon::upfile_record_sep
9329:
9330: =cut
9331:
1.144 matthew 9332: ######################################################
9333: ######################################################
1.31 albertel 9334: sub csv_print_samples {
9335: my ($r,$records) = @_;
1.662 bisitz 9336: my $samples = &get_samples($records,5);
1.301 albertel 9337:
1.594 raeburn 9338: $r->print(&mt('Samples').'<br />'.&start_data_table().
9339: &start_data_table_header_row());
1.356 albertel 9340: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 9341: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 9342: $r->print(&end_data_table_header_row());
1.301 albertel 9343: foreach my $hash (@$samples) {
1.594 raeburn 9344: $r->print(&start_data_table_row());
1.356 albertel 9345: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 9346: $r->print('<td>');
1.356 albertel 9347: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 9348: $r->print('</td>');
9349: }
1.594 raeburn 9350: $r->print(&end_data_table_row());
1.31 albertel 9351: }
1.594 raeburn 9352: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 9353: }
9354:
1.144 matthew 9355: ######################################################
9356: ######################################################
9357:
1.56 matthew 9358: =pod
9359:
1.648 raeburn 9360: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 9361:
9362: Prints a table to create associations between values and table columns.
1.144 matthew 9363:
1.41 ng 9364: $r is an Apache Request ref,
9365: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 9366: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 9367:
9368: =cut
9369:
1.144 matthew 9370: ######################################################
9371: ######################################################
1.31 albertel 9372: sub csv_print_select_table {
9373: my ($r,$records,$d) = @_;
1.301 albertel 9374: my $i=0;
9375: my $samples = &get_samples($records,1);
1.144 matthew 9376: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 9377: &start_data_table().&start_data_table_header_row().
1.144 matthew 9378: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 9379: '<th>'.&mt('Column').'</th>'.
9380: &end_data_table_header_row()."\n");
1.356 albertel 9381: foreach my $array_ref (@$d) {
9382: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 9383: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 9384:
1.875 bisitz 9385: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 9386: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 9387: $r->print('<option value="none"></option>');
1.356 albertel 9388: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
9389: $r->print('<option value="'.$sample.'"'.
9390: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 9391: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 9392: }
1.594 raeburn 9393: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 9394: $i++;
9395: }
1.594 raeburn 9396: $r->print(&end_data_table());
1.31 albertel 9397: $i--;
9398: return $i;
9399: }
1.56 matthew 9400:
1.144 matthew 9401: ######################################################
9402: ######################################################
9403:
1.56 matthew 9404: =pod
1.31 albertel 9405:
1.648 raeburn 9406: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 9407:
9408: Prints a table of sample values from the upload and can make associate samples to internal names.
9409:
9410: $r is an Apache Request ref,
9411: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
9412: $d is an array of 2 element arrays (internal name, displayed name)
9413:
9414: =cut
9415:
1.144 matthew 9416: ######################################################
9417: ######################################################
1.31 albertel 9418: sub csv_samples_select_table {
9419: my ($r,$records,$d) = @_;
9420: my $i=0;
1.144 matthew 9421: #
1.662 bisitz 9422: my $max_samples = 5;
9423: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 9424: $r->print(&start_data_table().
9425: &start_data_table_header_row().'<th>'.
9426: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
9427: &end_data_table_header_row());
1.301 albertel 9428:
9429: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 9430: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 9431: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 9432: foreach my $option (@$d) {
9433: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 9434: $r->print('<option value="'.$value.'"'.
1.253 albertel 9435: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 9436: $display.'</option>');
1.31 albertel 9437: }
9438: $r->print('</select></td><td>');
1.662 bisitz 9439: foreach my $line (0..($max_samples-1)) {
1.301 albertel 9440: if (defined($samples->[$line]{$key})) {
9441: $r->print($samples->[$line]{$key}."<br />\n");
9442: }
9443: }
1.594 raeburn 9444: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9445: $i++;
9446: }
1.594 raeburn 9447: $r->print(&end_data_table());
1.31 albertel 9448: $i--;
9449: return($i);
1.115 matthew 9450: }
9451:
1.144 matthew 9452: ######################################################
9453: ######################################################
9454:
1.115 matthew 9455: =pod
9456:
1.648 raeburn 9457: =item * &clean_excel_name($name)
1.115 matthew 9458:
9459: Returns a replacement for $name which does not contain any illegal characters.
9460:
9461: =cut
9462:
1.144 matthew 9463: ######################################################
9464: ######################################################
1.115 matthew 9465: sub clean_excel_name {
9466: my ($name) = @_;
9467: $name =~ s/[:\*\?\/\\]//g;
9468: if (length($name) > 31) {
9469: $name = substr($name,0,31);
9470: }
9471: return $name;
1.25 albertel 9472: }
1.84 albertel 9473:
1.85 albertel 9474: =pod
9475:
1.648 raeburn 9476: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9477:
9478: Returns either 1 or undef
9479:
9480: 1 if the part is to be hidden, undef if it is to be shown
9481:
9482: Arguments are:
9483:
9484: $id the id of the part to be checked
9485: $symb, optional the symb of the resource to check
9486: $udom, optional the domain of the user to check for
9487: $uname, optional the username of the user to check for
9488:
9489: =cut
1.84 albertel 9490:
9491: sub check_if_partid_hidden {
9492: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9493: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9494: $symb,$udom,$uname);
1.141 albertel 9495: my $truth=1;
9496: #if the string starts with !, then the list is the list to show not hide
9497: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9498: my @hiddenlist=split(/,/,$hiddenparts);
9499: foreach my $checkid (@hiddenlist) {
1.141 albertel 9500: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9501: }
1.141 albertel 9502: return !$truth;
1.84 albertel 9503: }
1.127 matthew 9504:
1.138 matthew 9505:
9506: ############################################################
9507: ############################################################
9508:
9509: =pod
9510:
1.157 matthew 9511: =back
9512:
1.138 matthew 9513: =head1 cgi-bin script and graphing routines
9514:
1.157 matthew 9515: =over 4
9516:
1.648 raeburn 9517: =item * &get_cgi_id()
1.138 matthew 9518:
9519: Inputs: none
9520:
9521: Returns an id which can be used to pass environment variables
9522: to various cgi-bin scripts. These environment variables will
9523: be removed from the users environment after a given time by
9524: the routine &Apache::lonnet::transfer_profile_to_env.
9525:
9526: =cut
9527:
9528: ############################################################
9529: ############################################################
1.152 albertel 9530: my $uniq=0;
1.136 matthew 9531: sub get_cgi_id {
1.154 albertel 9532: $uniq=($uniq+1)%100000;
1.280 albertel 9533: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9534: }
9535:
1.127 matthew 9536: ############################################################
9537: ############################################################
9538:
9539: =pod
9540:
1.648 raeburn 9541: =item * &DrawBarGraph()
1.127 matthew 9542:
1.138 matthew 9543: Facilitates the plotting of data in a (stacked) bar graph.
9544: Puts plot definition data into the users environment in order for
9545: graph.png to plot it. Returns an <img> tag for the plot.
9546: The bars on the plot are labeled '1','2',...,'n'.
9547:
9548: Inputs:
9549:
9550: =over 4
9551:
9552: =item $Title: string, the title of the plot
9553:
9554: =item $xlabel: string, text describing the X-axis of the plot
9555:
9556: =item $ylabel: string, text describing the Y-axis of the plot
9557:
9558: =item $Max: scalar, the maximum Y value to use in the plot
9559: If $Max is < any data point, the graph will not be rendered.
9560:
1.140 matthew 9561: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9562: they are plotted. If undefined, default values will be used.
9563:
1.178 matthew 9564: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9565:
1.138 matthew 9566: =item @Values: An array of array references. Each array reference holds data
9567: to be plotted in a stacked bar chart.
9568:
1.239 matthew 9569: =item If the final element of @Values is a hash reference the key/value
9570: pairs will be added to the graph definition.
9571:
1.138 matthew 9572: =back
9573:
9574: Returns:
9575:
9576: An <img> tag which references graph.png and the appropriate identifying
9577: information for the plot.
9578:
1.127 matthew 9579: =cut
9580:
9581: ############################################################
9582: ############################################################
1.134 matthew 9583: sub DrawBarGraph {
1.178 matthew 9584: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9585: #
9586: if (! defined($colors)) {
9587: $colors = ['#33ff00',
9588: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9589: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9590: ];
9591: }
1.228 matthew 9592: my $extra_settings = {};
9593: if (ref($Values[-1]) eq 'HASH') {
9594: $extra_settings = pop(@Values);
9595: }
1.127 matthew 9596: #
1.136 matthew 9597: my $identifier = &get_cgi_id();
9598: my $id = 'cgi.'.$identifier;
1.129 matthew 9599: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9600: return '';
9601: }
1.225 matthew 9602: #
9603: my @Labels;
9604: if (defined($labels)) {
9605: @Labels = @$labels;
9606: } else {
9607: for (my $i=0;$i<@{$Values[0]};$i++) {
9608: push (@Labels,$i+1);
9609: }
9610: }
9611: #
1.129 matthew 9612: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9613: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9614: my %ValuesHash;
9615: my $NumSets=1;
9616: foreach my $array (@Values) {
9617: next if (! ref($array));
1.136 matthew 9618: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9619: join(',',@$array);
1.129 matthew 9620: }
1.127 matthew 9621: #
1.136 matthew 9622: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9623: if ($NumBars < 3) {
9624: $width = 120+$NumBars*32;
1.220 matthew 9625: $xskip = 1;
1.225 matthew 9626: $bar_width = 30;
9627: } elsif ($NumBars < 5) {
9628: $width = 120+$NumBars*20;
9629: $xskip = 1;
9630: $bar_width = 20;
1.220 matthew 9631: } elsif ($NumBars < 10) {
1.136 matthew 9632: $width = 120+$NumBars*15;
9633: $xskip = 1;
9634: $bar_width = 15;
9635: } elsif ($NumBars <= 25) {
9636: $width = 120+$NumBars*11;
9637: $xskip = 5;
9638: $bar_width = 8;
9639: } elsif ($NumBars <= 50) {
9640: $width = 120+$NumBars*8;
9641: $xskip = 5;
9642: $bar_width = 4;
9643: } else {
9644: $width = 120+$NumBars*8;
9645: $xskip = 5;
9646: $bar_width = 4;
9647: }
9648: #
1.137 matthew 9649: $Max = 1 if ($Max < 1);
9650: if ( int($Max) < $Max ) {
9651: $Max++;
9652: $Max = int($Max);
9653: }
1.127 matthew 9654: $Title = '' if (! defined($Title));
9655: $xlabel = '' if (! defined($xlabel));
9656: $ylabel = '' if (! defined($ylabel));
1.369 www 9657: $ValuesHash{$id.'.title'} = &escape($Title);
9658: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9659: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9660: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9661: $ValuesHash{$id.'.NumBars'} = $NumBars;
9662: $ValuesHash{$id.'.NumSets'} = $NumSets;
9663: $ValuesHash{$id.'.PlotType'} = 'bar';
9664: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9665: $ValuesHash{$id.'.height'} = $height;
9666: $ValuesHash{$id.'.width'} = $width;
9667: $ValuesHash{$id.'.xskip'} = $xskip;
9668: $ValuesHash{$id.'.bar_width'} = $bar_width;
9669: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9670: #
1.228 matthew 9671: # Deal with other parameters
9672: while (my ($key,$value) = each(%$extra_settings)) {
9673: $ValuesHash{$id.'.'.$key} = $value;
9674: }
9675: #
1.646 raeburn 9676: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9677: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9678: }
9679:
9680: ############################################################
9681: ############################################################
9682:
9683: =pod
9684:
1.648 raeburn 9685: =item * &DrawXYGraph()
1.137 matthew 9686:
1.138 matthew 9687: Facilitates the plotting of data in an XY graph.
9688: Puts plot definition data into the users environment in order for
9689: graph.png to plot it. Returns an <img> tag for the plot.
9690:
9691: Inputs:
9692:
9693: =over 4
9694:
9695: =item $Title: string, the title of the plot
9696:
9697: =item $xlabel: string, text describing the X-axis of the plot
9698:
9699: =item $ylabel: string, text describing the Y-axis of the plot
9700:
9701: =item $Max: scalar, the maximum Y value to use in the plot
9702: If $Max is < any data point, the graph will not be rendered.
9703:
9704: =item $colors: Array ref containing the hex color codes for the data to be
9705: plotted in. If undefined, default values will be used.
9706:
9707: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9708:
9709: =item $Ydata: Array ref containing Array refs.
1.185 www 9710: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9711:
9712: =item %Values: hash indicating or overriding any default values which are
9713: passed to graph.png.
9714: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9715:
9716: =back
9717:
9718: Returns:
9719:
9720: An <img> tag which references graph.png and the appropriate identifying
9721: information for the plot.
9722:
1.137 matthew 9723: =cut
9724:
9725: ############################################################
9726: ############################################################
9727: sub DrawXYGraph {
9728: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9729: #
9730: # Create the identifier for the graph
9731: my $identifier = &get_cgi_id();
9732: my $id = 'cgi.'.$identifier;
9733: #
9734: $Title = '' if (! defined($Title));
9735: $xlabel = '' if (! defined($xlabel));
9736: $ylabel = '' if (! defined($ylabel));
9737: my %ValuesHash =
9738: (
1.369 www 9739: $id.'.title' => &escape($Title),
9740: $id.'.xlabel' => &escape($xlabel),
9741: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9742: $id.'.y_max_value'=> $Max,
9743: $id.'.labels' => join(',',@$Xlabels),
9744: $id.'.PlotType' => 'XY',
9745: );
9746: #
9747: if (defined($colors) && ref($colors) eq 'ARRAY') {
9748: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9749: }
9750: #
9751: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9752: return '';
9753: }
9754: my $NumSets=1;
1.138 matthew 9755: foreach my $array (@{$Ydata}){
1.137 matthew 9756: next if (! ref($array));
9757: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9758: }
1.138 matthew 9759: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9760: #
9761: # Deal with other parameters
9762: while (my ($key,$value) = each(%Values)) {
9763: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9764: }
9765: #
1.646 raeburn 9766: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9767: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9768: }
9769:
9770: ############################################################
9771: ############################################################
9772:
9773: =pod
9774:
1.648 raeburn 9775: =item * &DrawXYYGraph()
1.138 matthew 9776:
9777: Facilitates the plotting of data in an XY graph with two Y axes.
9778: Puts plot definition data into the users environment in order for
9779: graph.png to plot it. Returns an <img> tag for the plot.
9780:
9781: Inputs:
9782:
9783: =over 4
9784:
9785: =item $Title: string, the title of the plot
9786:
9787: =item $xlabel: string, text describing the X-axis of the plot
9788:
9789: =item $ylabel: string, text describing the Y-axis of the plot
9790:
9791: =item $colors: Array ref containing the hex color codes for the data to be
9792: plotted in. If undefined, default values will be used.
9793:
9794: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9795:
9796: =item $Ydata1: The first data set
9797:
9798: =item $Min1: The minimum value of the left Y-axis
9799:
9800: =item $Max1: The maximum value of the left Y-axis
9801:
9802: =item $Ydata2: The second data set
9803:
9804: =item $Min2: The minimum value of the right Y-axis
9805:
9806: =item $Max2: The maximum value of the left Y-axis
9807:
9808: =item %Values: hash indicating or overriding any default values which are
9809: passed to graph.png.
9810: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9811:
9812: =back
9813:
9814: Returns:
9815:
9816: An <img> tag which references graph.png and the appropriate identifying
9817: information for the plot.
1.136 matthew 9818:
9819: =cut
9820:
9821: ############################################################
9822: ############################################################
1.137 matthew 9823: sub DrawXYYGraph {
9824: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9825: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9826: #
9827: # Create the identifier for the graph
9828: my $identifier = &get_cgi_id();
9829: my $id = 'cgi.'.$identifier;
9830: #
9831: $Title = '' if (! defined($Title));
9832: $xlabel = '' if (! defined($xlabel));
9833: $ylabel = '' if (! defined($ylabel));
9834: my %ValuesHash =
9835: (
1.369 www 9836: $id.'.title' => &escape($Title),
9837: $id.'.xlabel' => &escape($xlabel),
9838: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9839: $id.'.labels' => join(',',@$Xlabels),
9840: $id.'.PlotType' => 'XY',
9841: $id.'.NumSets' => 2,
1.137 matthew 9842: $id.'.two_axes' => 1,
9843: $id.'.y1_max_value' => $Max1,
9844: $id.'.y1_min_value' => $Min1,
9845: $id.'.y2_max_value' => $Max2,
9846: $id.'.y2_min_value' => $Min2,
1.136 matthew 9847: );
9848: #
1.137 matthew 9849: if (defined($colors) && ref($colors) eq 'ARRAY') {
9850: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9851: }
9852: #
9853: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9854: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9855: return '';
9856: }
9857: my $NumSets=1;
1.137 matthew 9858: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9859: next if (! ref($array));
9860: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9861: }
9862: #
9863: # Deal with other parameters
9864: while (my ($key,$value) = each(%Values)) {
9865: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9866: }
9867: #
1.646 raeburn 9868: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9869: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9870: }
9871:
9872: ############################################################
9873: ############################################################
9874:
9875: =pod
9876:
1.157 matthew 9877: =back
9878:
1.139 matthew 9879: =head1 Statistics helper routines?
9880:
9881: Bad place for them but what the hell.
9882:
1.157 matthew 9883: =over 4
9884:
1.648 raeburn 9885: =item * &chartlink()
1.139 matthew 9886:
9887: Returns a link to the chart for a specific student.
9888:
9889: Inputs:
9890:
9891: =over 4
9892:
9893: =item $linktext: The text of the link
9894:
9895: =item $sname: The students username
9896:
9897: =item $sdomain: The students domain
9898:
9899: =back
9900:
1.157 matthew 9901: =back
9902:
1.139 matthew 9903: =cut
9904:
9905: ############################################################
9906: ############################################################
9907: sub chartlink {
9908: my ($linktext, $sname, $sdomain) = @_;
9909: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9910: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9911: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9912: '">'.$linktext.'</a>';
1.153 matthew 9913: }
9914:
9915: #######################################################
9916: #######################################################
9917:
9918: =pod
9919:
9920: =head1 Course Environment Routines
1.157 matthew 9921:
9922: =over 4
1.153 matthew 9923:
1.648 raeburn 9924: =item * &restore_course_settings()
1.153 matthew 9925:
1.648 raeburn 9926: =item * &store_course_settings()
1.153 matthew 9927:
9928: Restores/Store indicated form parameters from the course environment.
9929: Will not overwrite existing values of the form parameters.
9930:
9931: Inputs:
9932: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9933:
9934: a hash ref describing the data to be stored. For example:
9935:
9936: %Save_Parameters = ('Status' => 'scalar',
9937: 'chartoutputmode' => 'scalar',
9938: 'chartoutputdata' => 'scalar',
9939: 'Section' => 'array',
1.373 raeburn 9940: 'Group' => 'array',
1.153 matthew 9941: 'StudentData' => 'array',
9942: 'Maps' => 'array');
9943:
9944: Returns: both routines return nothing
9945:
1.631 raeburn 9946: =back
9947:
1.153 matthew 9948: =cut
9949:
9950: #######################################################
9951: #######################################################
9952: sub store_course_settings {
1.496 albertel 9953: return &store_settings($env{'request.course.id'},@_);
9954: }
9955:
9956: sub store_settings {
1.153 matthew 9957: # save to the environment
9958: # appenv the same items, just to be safe
1.300 albertel 9959: my $udom = $env{'user.domain'};
9960: my $uname = $env{'user.name'};
1.496 albertel 9961: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9962: my %SaveHash;
9963: my %AppHash;
9964: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9965: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9966: my $envname = 'environment.'.$basename;
1.258 albertel 9967: if (exists($env{'form.'.$setting})) {
1.153 matthew 9968: # Save this value away
9969: if ($type eq 'scalar' &&
1.258 albertel 9970: (! exists($env{$envname}) ||
9971: $env{$envname} ne $env{'form.'.$setting})) {
9972: $SaveHash{$basename} = $env{'form.'.$setting};
9973: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9974: } elsif ($type eq 'array') {
9975: my $stored_form;
1.258 albertel 9976: if (ref($env{'form.'.$setting})) {
1.153 matthew 9977: $stored_form = join(',',
9978: map {
1.369 www 9979: &escape($_);
1.258 albertel 9980: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9981: } else {
9982: $stored_form =
1.369 www 9983: &escape($env{'form.'.$setting});
1.153 matthew 9984: }
9985: # Determine if the array contents are the same.
1.258 albertel 9986: if ($stored_form ne $env{$envname}) {
1.153 matthew 9987: $SaveHash{$basename} = $stored_form;
9988: $AppHash{$envname} = $stored_form;
9989: }
9990: }
9991: }
9992: }
9993: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9994: $udom,$uname);
1.153 matthew 9995: if ($put_result !~ /^(ok|delayed)/) {
9996: &Apache::lonnet::logthis('unable to save form parameters, '.
9997: 'got error:'.$put_result);
9998: }
9999: # Make sure these settings stick around in this session, too
1.646 raeburn 10000: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 10001: return;
10002: }
10003:
10004: sub restore_course_settings {
1.499 albertel 10005: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 10006: }
10007:
10008: sub restore_settings {
10009: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10010: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 10011: next if (exists($env{'form.'.$setting}));
1.496 albertel 10012: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 10013: '.'.$setting;
1.258 albertel 10014: if (exists($env{$envname})) {
1.153 matthew 10015: if ($type eq 'scalar') {
1.258 albertel 10016: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 10017: } elsif ($type eq 'array') {
1.258 albertel 10018: $env{'form.'.$setting} = [
1.153 matthew 10019: map {
1.369 www 10020: &unescape($_);
1.258 albertel 10021: } split(',',$env{$envname})
1.153 matthew 10022: ];
10023: }
10024: }
10025: }
1.127 matthew 10026: }
10027:
1.618 raeburn 10028: #######################################################
10029: #######################################################
10030:
10031: =pod
10032:
10033: =head1 Domain E-mail Routines
10034:
10035: =over 4
10036:
1.648 raeburn 10037: =item * &build_recipient_list()
1.618 raeburn 10038:
1.884 raeburn 10039: Build recipient lists for five types of e-mail:
1.766 raeburn 10040: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 10041: (d) Help requests, (e) Course requests needing approval, generated by
10042: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
10043: loncoursequeueadmin.pm respectively.
1.618 raeburn 10044:
10045: Inputs:
1.619 raeburn 10046: defmail (scalar - email address of default recipient),
1.618 raeburn 10047: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 10048: defdom (domain for which to retrieve configuration settings),
10049: origmail (scalar - email address of recipient from loncapa.conf,
10050: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 10051:
1.655 raeburn 10052: Returns: comma separated list of addresses to which to send e-mail.
10053:
10054: =back
1.618 raeburn 10055:
10056: =cut
10057:
10058: ############################################################
10059: ############################################################
10060: sub build_recipient_list {
1.619 raeburn 10061: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 10062: my @recipients;
10063: my $otheremails;
10064: my %domconfig =
10065: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
10066: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 10067: if (exists($domconfig{'contacts'}{$mailing})) {
10068: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
10069: my @contacts = ('adminemail','supportemail');
10070: foreach my $item (@contacts) {
10071: if ($domconfig{'contacts'}{$mailing}{$item}) {
10072: my $addr = $domconfig{'contacts'}{$item};
10073: if (!grep(/^\Q$addr\E$/,@recipients)) {
10074: push(@recipients,$addr);
10075: }
1.619 raeburn 10076: }
1.766 raeburn 10077: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 10078: }
10079: }
1.766 raeburn 10080: } elsif ($origmail ne '') {
10081: push(@recipients,$origmail);
1.618 raeburn 10082: }
1.619 raeburn 10083: } elsif ($origmail ne '') {
10084: push(@recipients,$origmail);
1.618 raeburn 10085: }
1.688 raeburn 10086: if (defined($defmail)) {
10087: if ($defmail ne '') {
10088: push(@recipients,$defmail);
10089: }
1.618 raeburn 10090: }
10091: if ($otheremails) {
1.619 raeburn 10092: my @others;
10093: if ($otheremails =~ /,/) {
10094: @others = split(/,/,$otheremails);
1.618 raeburn 10095: } else {
1.619 raeburn 10096: push(@others,$otheremails);
10097: }
10098: foreach my $addr (@others) {
10099: if (!grep(/^\Q$addr\E$/,@recipients)) {
10100: push(@recipients,$addr);
10101: }
1.618 raeburn 10102: }
10103: }
1.619 raeburn 10104: my $recipientlist = join(',',@recipients);
1.618 raeburn 10105: return $recipientlist;
10106: }
10107:
1.127 matthew 10108: ############################################################
10109: ############################################################
1.154 albertel 10110:
1.655 raeburn 10111: =pod
10112:
10113: =head1 Course Catalog Routines
10114:
10115: =over 4
10116:
10117: =item * &gather_categories()
10118:
10119: Converts category definitions - keys of categories hash stored in
10120: coursecategories in configuration.db on the primary library server in a
10121: domain - to an array. Also generates javascript and idx hash used to
10122: generate Domain Coordinator interface for editing Course Categories.
10123:
10124: Inputs:
1.663 raeburn 10125:
1.655 raeburn 10126: categories (reference to hash of category definitions).
1.663 raeburn 10127:
1.655 raeburn 10128: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10129: categories and subcategories).
1.663 raeburn 10130:
1.655 raeburn 10131: idx (reference to hash of counters used in Domain Coordinator interface for
10132: editing Course Categories).
1.663 raeburn 10133:
1.655 raeburn 10134: jsarray (reference to array of categories used to create Javascript arrays for
10135: Domain Coordinator interface for editing Course Categories).
10136:
10137: Returns: nothing
10138:
10139: Side effects: populates cats, idx and jsarray.
10140:
10141: =cut
10142:
10143: sub gather_categories {
10144: my ($categories,$cats,$idx,$jsarray) = @_;
10145: my %counters;
10146: my $num = 0;
10147: foreach my $item (keys(%{$categories})) {
10148: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10149: if ($container eq '' && $depth == 0) {
10150: $cats->[$depth][$categories->{$item}] = $cat;
10151: } else {
10152: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
10153: }
10154: my ($escitem,$tail) = split(/:/,$item,2);
10155: if ($counters{$tail} eq '') {
10156: $counters{$tail} = $num;
10157: $num ++;
10158: }
10159: if (ref($idx) eq 'HASH') {
10160: $idx->{$item} = $counters{$tail};
10161: }
10162: if (ref($jsarray) eq 'ARRAY') {
10163: push(@{$jsarray->[$counters{$tail}]},$item);
10164: }
10165: }
10166: return;
10167: }
10168:
10169: =pod
10170:
10171: =item * &extract_categories()
10172:
10173: Used to generate breadcrumb trails for course categories.
10174:
10175: Inputs:
1.663 raeburn 10176:
1.655 raeburn 10177: categories (reference to hash of category definitions).
1.663 raeburn 10178:
1.655 raeburn 10179: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10180: categories and subcategories).
1.663 raeburn 10181:
1.655 raeburn 10182: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 10183:
1.655 raeburn 10184: allitems (reference to hash - key is category key
10185: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10186:
1.655 raeburn 10187: idx (reference to hash of counters used in Domain Coordinator interface for
10188: editing Course Categories).
1.663 raeburn 10189:
1.655 raeburn 10190: jsarray (reference to array of categories used to create Javascript arrays for
10191: Domain Coordinator interface for editing Course Categories).
10192:
1.665 raeburn 10193: subcats (reference to hash of arrays containing all subcategories within each
10194: category, -recursive)
10195:
1.655 raeburn 10196: Returns: nothing
10197:
10198: Side effects: populates trails and allitems hash references.
10199:
10200: =cut
10201:
10202: sub extract_categories {
1.665 raeburn 10203: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 10204: if (ref($categories) eq 'HASH') {
10205: &gather_categories($categories,$cats,$idx,$jsarray);
10206: if (ref($cats->[0]) eq 'ARRAY') {
10207: for (my $i=0; $i<@{$cats->[0]}; $i++) {
10208: my $name = $cats->[0][$i];
10209: my $item = &escape($name).'::0';
10210: my $trailstr;
10211: if ($name eq 'instcode') {
10212: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 10213: } elsif ($name eq 'communities') {
10214: $trailstr = &mt('Communities');
1.655 raeburn 10215: } else {
10216: $trailstr = $name;
10217: }
10218: if ($allitems->{$item} eq '') {
10219: push(@{$trails},$trailstr);
10220: $allitems->{$item} = scalar(@{$trails})-1;
10221: }
10222: my @parents = ($name);
10223: if (ref($cats->[1]{$name}) eq 'ARRAY') {
10224: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
10225: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 10226: if (ref($subcats) eq 'HASH') {
10227: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
10228: }
10229: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
10230: }
10231: } else {
10232: if (ref($subcats) eq 'HASH') {
10233: $subcats->{$item} = [];
1.655 raeburn 10234: }
10235: }
10236: }
10237: }
10238: }
10239: return;
10240: }
10241:
10242: =pod
10243:
10244: =item *&recurse_categories()
10245:
10246: Recursively used to generate breadcrumb trails for course categories.
10247:
10248: Inputs:
1.663 raeburn 10249:
1.655 raeburn 10250: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10251: categories and subcategories).
1.663 raeburn 10252:
1.655 raeburn 10253: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 10254:
10255: category (current course category, for which breadcrumb trail is being generated).
10256:
10257: trails (reference to array of breadcrumb trails for each category).
10258:
1.655 raeburn 10259: allitems (reference to hash - key is category key
10260: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10261:
1.655 raeburn 10262: parents (array containing containers directories for current category,
10263: back to top level).
10264:
10265: Returns: nothing
10266:
10267: Side effects: populates trails and allitems hash references
10268:
10269: =cut
10270:
10271: sub recurse_categories {
1.665 raeburn 10272: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 10273: my $shallower = $depth - 1;
10274: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
10275: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
10276: my $name = $cats->[$depth]{$category}[$k];
10277: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10278: my $trailstr = join(' -> ',(@{$parents},$category));
10279: if ($allitems->{$item} eq '') {
10280: push(@{$trails},$trailstr);
10281: $allitems->{$item} = scalar(@{$trails})-1;
10282: }
10283: my $deeper = $depth+1;
10284: push(@{$parents},$category);
1.665 raeburn 10285: if (ref($subcats) eq 'HASH') {
10286: my $subcat = &escape($name).':'.$category.':'.$depth;
10287: for (my $j=@{$parents}; $j>=0; $j--) {
10288: my $higher;
10289: if ($j > 0) {
10290: $higher = &escape($parents->[$j]).':'.
10291: &escape($parents->[$j-1]).':'.$j;
10292: } else {
10293: $higher = &escape($parents->[$j]).'::'.$j;
10294: }
10295: push(@{$subcats->{$higher}},$subcat);
10296: }
10297: }
10298: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
10299: $subcats);
1.655 raeburn 10300: pop(@{$parents});
10301: }
10302: } else {
10303: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10304: my $trailstr = join(' -> ',(@{$parents},$category));
10305: if ($allitems->{$item} eq '') {
10306: push(@{$trails},$trailstr);
10307: $allitems->{$item} = scalar(@{$trails})-1;
10308: }
10309: }
10310: return;
10311: }
10312:
1.663 raeburn 10313: =pod
10314:
10315: =item *&assign_categories_table()
10316:
10317: Create a datatable for display of hierarchical categories in a domain,
10318: with checkboxes to allow a course to be categorized.
10319:
10320: Inputs:
10321:
10322: cathash - reference to hash of categories defined for the domain (from
10323: configuration.db)
10324:
10325: currcat - scalar with an & separated list of categories assigned to a course.
10326:
1.919 raeburn 10327: type - scalar contains course type (Course or Community).
10328:
1.663 raeburn 10329: Returns: $output (markup to be displayed)
10330:
10331: =cut
10332:
10333: sub assign_categories_table {
1.919 raeburn 10334: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 10335: my $output;
10336: if (ref($cathash) eq 'HASH') {
10337: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
10338: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
10339: $maxdepth = scalar(@cats);
10340: if (@cats > 0) {
10341: my $itemcount = 0;
10342: if (ref($cats[0]) eq 'ARRAY') {
10343: my @currcategories;
10344: if ($currcat ne '') {
10345: @currcategories = split('&',$currcat);
10346: }
1.919 raeburn 10347: my $table;
1.663 raeburn 10348: for (my $i=0; $i<@{$cats[0]}; $i++) {
10349: my $parent = $cats[0][$i];
1.919 raeburn 10350: next if ($parent eq 'instcode');
10351: if ($type eq 'Community') {
10352: next unless ($parent eq 'communities');
10353: } else {
10354: next if ($parent eq 'communities');
10355: }
1.663 raeburn 10356: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10357: my $item = &escape($parent).'::0';
10358: my $checked = '';
10359: if (@currcategories > 0) {
10360: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 10361: $checked = ' checked="checked"';
1.663 raeburn 10362: }
10363: }
1.919 raeburn 10364: my $parent_title = $parent;
10365: if ($parent eq 'communities') {
10366: $parent_title = &mt('Communities');
10367: }
10368: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
10369: '<input type="checkbox" name="usecategory" value="'.
10370: $item.'"'.$checked.' />'.$parent_title.'</span>'.
10371: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 10372: my $depth = 1;
10373: push(@path,$parent);
1.919 raeburn 10374: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 10375: pop(@path);
1.919 raeburn 10376: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 10377: $itemcount ++;
10378: }
1.919 raeburn 10379: if ($itemcount) {
10380: $output = &Apache::loncommon::start_data_table().
10381: $table.
10382: &Apache::loncommon::end_data_table();
10383: }
1.663 raeburn 10384: }
10385: }
10386: }
10387: return $output;
10388: }
10389:
10390: =pod
10391:
10392: =item *&assign_category_rows()
10393:
10394: Create a datatable row for display of nested categories in a domain,
10395: with checkboxes to allow a course to be categorized,called recursively.
10396:
10397: Inputs:
10398:
10399: itemcount - track row number for alternating colors
10400:
10401: cats - reference to array of arrays/hashes which encapsulates hierarchy of
10402: categories and subcategories.
10403:
10404: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
10405:
10406: parent - parent of current category item
10407:
10408: path - Array containing all categories back up through the hierarchy from the
10409: current category to the top level.
10410:
10411: currcategories - reference to array of current categories assigned to the course
10412:
10413: Returns: $output (markup to be displayed).
10414:
10415: =cut
10416:
10417: sub assign_category_rows {
10418: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
10419: my ($text,$name,$item,$chgstr);
10420: if (ref($cats) eq 'ARRAY') {
10421: my $maxdepth = scalar(@{$cats});
10422: if (ref($cats->[$depth]) eq 'HASH') {
10423: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10424: my $numchildren = @{$cats->[$depth]{$parent}};
10425: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10426: $text .= '<td><table class="LC_datatable">';
10427: for (my $j=0; $j<$numchildren; $j++) {
10428: $name = $cats->[$depth]{$parent}[$j];
10429: $item = &escape($name).':'.&escape($parent).':'.$depth;
10430: my $deeper = $depth+1;
10431: my $checked = '';
10432: if (ref($currcategories) eq 'ARRAY') {
10433: if (@{$currcategories} > 0) {
10434: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 10435: $checked = ' checked="checked"';
1.663 raeburn 10436: }
10437: }
10438: }
1.664 raeburn 10439: $text .= '<tr><td><span class="LC_nobreak"><label>'.
10440: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 10441: $item.'"'.$checked.' />'.$name.'</label></span>'.
10442: '<input type="hidden" name="catname" value="'.$name.'" />'.
10443: '</td><td>';
1.663 raeburn 10444: if (ref($path) eq 'ARRAY') {
10445: push(@{$path},$name);
10446: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10447: pop(@{$path});
10448: }
10449: $text .= '</td></tr>';
10450: }
10451: $text .= '</table></td>';
10452: }
10453: }
10454: }
10455: return $text;
10456: }
10457:
1.655 raeburn 10458: ############################################################
10459: ############################################################
10460:
10461:
1.443 albertel 10462: sub commit_customrole {
1.664 raeburn 10463: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10464: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10465: ($start?', '.&mt('starting').' '.localtime($start):'').
10466: ($end?', ending '.localtime($end):'').': <b>'.
10467: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10468: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10469: '</b><br />';
10470: return $output;
10471: }
10472:
10473: sub commit_standardrole {
1.541 raeburn 10474: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10475: my ($output,$logmsg,$linefeed);
10476: if ($context eq 'auto') {
10477: $linefeed = "\n";
10478: } else {
10479: $linefeed = "<br />\n";
10480: }
1.443 albertel 10481: if ($three eq 'st') {
1.541 raeburn 10482: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10483: $one,$two,$sec,$context);
10484: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10485: ($result eq 'unknown_course') || ($result eq 'refused')) {
10486: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10487: } else {
1.541 raeburn 10488: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10489: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10490: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10491: if ($context eq 'auto') {
10492: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10493: } else {
10494: $output .= '<b>'.$result.'</b>'.$linefeed.
10495: &mt('Add to classlist').': <b>ok</b>';
10496: }
10497: $output .= $linefeed;
1.443 albertel 10498: }
10499: } else {
10500: $output = &mt('Assigning').' '.$three.' in '.$url.
10501: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10502: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10503: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10504: if ($context eq 'auto') {
10505: $output .= $result.$linefeed;
10506: } else {
10507: $output .= '<b>'.$result.'</b>'.$linefeed;
10508: }
1.443 albertel 10509: }
10510: return $output;
10511: }
10512:
10513: sub commit_studentrole {
1.541 raeburn 10514: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10515: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10516: if ($context eq 'auto') {
10517: $linefeed = "\n";
10518: } else {
10519: $linefeed = '<br />'."\n";
10520: }
1.443 albertel 10521: if (defined($one) && defined($two)) {
10522: my $cid=$one.'_'.$two;
10523: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10524: my $secchange = 0;
10525: my $expire_role_result;
10526: my $modify_section_result;
1.628 raeburn 10527: if ($oldsec ne '-1') {
10528: if ($oldsec ne $sec) {
1.443 albertel 10529: $secchange = 1;
1.628 raeburn 10530: my $now = time;
1.443 albertel 10531: my $uurl='/'.$cid;
10532: $uurl=~s/\_/\//g;
10533: if ($oldsec) {
10534: $uurl.='/'.$oldsec;
10535: }
1.626 raeburn 10536: $oldsecurl = $uurl;
1.628 raeburn 10537: $expire_role_result =
1.652 raeburn 10538: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10539: if ($env{'request.course.sec'} ne '') {
10540: if ($expire_role_result eq 'refused') {
10541: my @roles = ('st');
10542: my @statuses = ('previous');
10543: my @roledoms = ($one);
10544: my $withsec = 1;
10545: my %roleshash =
10546: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10547: \@statuses,\@roles,\@roledoms,$withsec);
10548: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10549: my ($oldstart,$oldend) =
10550: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10551: if ($oldend > 0 && $oldend <= $now) {
10552: $expire_role_result = 'ok';
10553: }
10554: }
10555: }
10556: }
1.443 albertel 10557: $result = $expire_role_result;
10558: }
10559: }
10560: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10561: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10562: if ($modify_section_result =~ /^ok/) {
10563: if ($secchange == 1) {
1.628 raeburn 10564: if ($sec eq '') {
10565: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10566: } else {
10567: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10568: }
1.443 albertel 10569: } elsif ($oldsec eq '-1') {
1.628 raeburn 10570: if ($sec eq '') {
10571: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10572: } else {
10573: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10574: }
1.443 albertel 10575: } else {
1.628 raeburn 10576: if ($sec eq '') {
10577: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10578: } else {
10579: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10580: }
1.443 albertel 10581: }
10582: } else {
1.628 raeburn 10583: if ($secchange) {
10584: $$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;
10585: } else {
10586: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10587: }
1.443 albertel 10588: }
10589: $result = $modify_section_result;
10590: } elsif ($secchange == 1) {
1.628 raeburn 10591: if ($oldsec eq '') {
10592: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10593: } else {
10594: $$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;
10595: }
1.626 raeburn 10596: if ($expire_role_result eq 'refused') {
10597: my $newsecurl = '/'.$cid;
10598: $newsecurl =~ s/\_/\//g;
10599: if ($sec ne '') {
10600: $newsecurl.='/'.$sec;
10601: }
10602: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10603: if ($sec eq '') {
10604: $$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;
10605: } else {
10606: $$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;
10607: }
10608: }
10609: }
1.443 albertel 10610: }
10611: } else {
1.626 raeburn 10612: $$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 10613: $result = "error: incomplete course id\n";
10614: }
10615: return $result;
10616: }
10617:
10618: ############################################################
10619: ############################################################
10620:
1.566 albertel 10621: sub check_clone {
1.578 raeburn 10622: my ($args,$linefeed) = @_;
1.566 albertel 10623: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10624: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10625: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10626: my $clonemsg;
10627: my $can_clone = 0;
1.944 raeburn 10628: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10629: if ($lctype ne 'community') {
10630: $lctype = 'course';
10631: }
1.566 albertel 10632: if ($clonehome eq 'no_host') {
1.944 raeburn 10633: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10634: $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'});
10635: } else {
10636: $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'});
10637: }
1.566 albertel 10638: } else {
10639: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10640: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10641: if ($clonedesc{'type'} ne 'Community') {
10642: $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'});
10643: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10644: }
10645: }
1.882 raeburn 10646: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10647: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10648: $can_clone = 1;
10649: } else {
10650: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10651: $args->{'clonedomain'},$args->{'clonecourse'});
10652: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10653: if (grep(/^\*$/,@cloners)) {
10654: $can_clone = 1;
10655: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10656: $can_clone = 1;
10657: } else {
1.908 raeburn 10658: my $ccrole = 'cc';
1.944 raeburn 10659: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10660: $ccrole = 'co';
10661: }
1.578 raeburn 10662: my %roleshash =
10663: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10664: $args->{'ccdomain'},
1.908 raeburn 10665: 'userroles',['active'],[$ccrole],
1.578 raeburn 10666: [$args->{'clonedomain'}]);
1.908 raeburn 10667: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10668: $can_clone = 1;
10669: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10670: $can_clone = 1;
10671: } else {
1.944 raeburn 10672: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10673: $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'});
10674: } else {
10675: $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'});
10676: }
1.578 raeburn 10677: }
1.566 albertel 10678: }
1.578 raeburn 10679: }
1.566 albertel 10680: }
10681: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10682: }
10683:
1.444 albertel 10684: sub construct_course {
1.885 raeburn 10685: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10686: my $outcome;
1.541 raeburn 10687: my $linefeed = '<br />'."\n";
10688: if ($context eq 'auto') {
10689: $linefeed = "\n";
10690: }
1.566 albertel 10691:
10692: #
10693: # Are we cloning?
10694: #
10695: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10696: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10697: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10698: if ($context ne 'auto') {
1.578 raeburn 10699: if ($clonemsg ne '') {
10700: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10701: }
1.566 albertel 10702: }
10703: $outcome .= $clonemsg.$linefeed;
10704:
10705: if (!$can_clone) {
10706: return (0,$outcome);
10707: }
10708: }
10709:
1.444 albertel 10710: #
10711: # Open course
10712: #
10713: my $crstype = lc($args->{'crstype'});
10714: my %cenv=();
10715: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10716: $args->{'cdescr'},
10717: $args->{'curl'},
10718: $args->{'course_home'},
10719: $args->{'nonstandard'},
10720: $args->{'crscode'},
10721: $args->{'ccuname'}.':'.
10722: $args->{'ccdomain'},
1.882 raeburn 10723: $args->{'crstype'},
1.885 raeburn 10724: $cnum,$context,$category);
1.444 albertel 10725:
10726: # Note: The testing routines depend on this being output; see
10727: # Utils::Course. This needs to at least be output as a comment
10728: # if anyone ever decides to not show this, and Utils::Course::new
10729: # will need to be suitably modified.
1.541 raeburn 10730: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10731: if ($$courseid =~ /^error:/) {
10732: return (0,$outcome);
10733: }
10734:
1.444 albertel 10735: #
10736: # Check if created correctly
10737: #
1.479 albertel 10738: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10739: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10740: if ($crsuhome eq 'no_host') {
10741: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10742: return (0,$outcome);
10743: }
1.541 raeburn 10744: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10745:
1.444 albertel 10746: #
1.566 albertel 10747: # Do the cloning
10748: #
10749: if ($can_clone && $cloneid) {
10750: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10751: if ($context ne 'auto') {
10752: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10753: }
10754: $outcome .= $clonemsg.$linefeed;
10755: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10756: # Copy all files
1.637 www 10757: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10758: # Restore URL
1.566 albertel 10759: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10760: # Restore title
1.566 albertel 10761: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 10762: # Restore creation date, creator and creation context.
10763: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10764: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10765: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10766: # Mark as cloned
1.566 albertel 10767: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10768: # Need to clone grading mode
10769: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10770: $cenv{'grading'}=$newenv{'grading'};
10771: # Do not clone these environment entries
10772: &Apache::lonnet::del('environment',
10773: ['default_enrollment_start_date',
10774: 'default_enrollment_end_date',
10775: 'question.email',
10776: 'policy.email',
10777: 'comment.email',
10778: 'pch.users.denied',
1.725 raeburn 10779: 'plc.users.denied',
10780: 'hidefromcat',
10781: 'categories'],
1.638 www 10782: $$crsudom,$$crsunum);
1.444 albertel 10783: }
1.566 albertel 10784:
1.444 albertel 10785: #
10786: # Set environment (will override cloned, if existing)
10787: #
10788: my @sections = ();
10789: my @xlists = ();
10790: if ($args->{'crstype'}) {
10791: $cenv{'type'}=$args->{'crstype'};
10792: }
10793: if ($args->{'crsid'}) {
10794: $cenv{'courseid'}=$args->{'crsid'};
10795: }
10796: if ($args->{'crscode'}) {
10797: $cenv{'internal.coursecode'}=$args->{'crscode'};
10798: }
10799: if ($args->{'crsquota'} ne '') {
10800: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10801: } else {
10802: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10803: }
10804: if ($args->{'ccuname'}) {
10805: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10806: ':'.$args->{'ccdomain'};
10807: } else {
10808: $cenv{'internal.courseowner'} = $args->{'curruser'};
10809: }
10810: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10811: if ($args->{'crssections'}) {
10812: $cenv{'internal.sectionnums'} = '';
10813: if ($args->{'crssections'} =~ m/,/) {
10814: @sections = split/,/,$args->{'crssections'};
10815: } else {
10816: $sections[0] = $args->{'crssections'};
10817: }
10818: if (@sections > 0) {
10819: foreach my $item (@sections) {
10820: my ($sec,$gp) = split/:/,$item;
10821: my $class = $args->{'crscode'}.$sec;
10822: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10823: $cenv{'internal.sectionnums'} .= $item.',';
10824: unless ($addcheck eq 'ok') {
10825: push @badclasses, $class;
10826: }
10827: }
10828: $cenv{'internal.sectionnums'} =~ s/,$//;
10829: }
10830: }
10831: # do not hide course coordinator from staff listing,
10832: # even if privileged
10833: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10834: # add crosslistings
10835: if ($args->{'crsxlist'}) {
10836: $cenv{'internal.crosslistings'}='';
10837: if ($args->{'crsxlist'} =~ m/,/) {
10838: @xlists = split/,/,$args->{'crsxlist'};
10839: } else {
10840: $xlists[0] = $args->{'crsxlist'};
10841: }
10842: if (@xlists > 0) {
10843: foreach my $item (@xlists) {
10844: my ($xl,$gp) = split/:/,$item;
10845: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10846: $cenv{'internal.crosslistings'} .= $item.',';
10847: unless ($addcheck eq 'ok') {
10848: push @badclasses, $xl;
10849: }
10850: }
10851: $cenv{'internal.crosslistings'} =~ s/,$//;
10852: }
10853: }
10854: if ($args->{'autoadds'}) {
10855: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10856: }
10857: if ($args->{'autodrops'}) {
10858: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10859: }
10860: # check for notification of enrollment changes
10861: my @notified = ();
10862: if ($args->{'notify_owner'}) {
10863: if ($args->{'ccuname'} ne '') {
10864: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10865: }
10866: }
10867: if ($args->{'notify_dc'}) {
10868: if ($uname ne '') {
1.630 raeburn 10869: push(@notified,$uname.':'.$udom);
1.444 albertel 10870: }
10871: }
10872: if (@notified > 0) {
10873: my $notifylist;
10874: if (@notified > 1) {
10875: $notifylist = join(',',@notified);
10876: } else {
10877: $notifylist = $notified[0];
10878: }
10879: $cenv{'internal.notifylist'} = $notifylist;
10880: }
10881: if (@badclasses > 0) {
10882: my %lt=&Apache::lonlocal::texthash(
10883: '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',
10884: 'dnhr' => 'does not have rights to access enrollment in these classes',
10885: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10886: );
1.541 raeburn 10887: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10888: ' ('.$lt{'adby'}.')';
10889: if ($context eq 'auto') {
10890: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10891: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10892: foreach my $item (@badclasses) {
10893: if ($context eq 'auto') {
10894: $outcome .= " - $item\n";
10895: } else {
10896: $outcome .= "<li>$item</li>\n";
10897: }
10898: }
10899: if ($context eq 'auto') {
10900: $outcome .= $linefeed;
10901: } else {
1.566 albertel 10902: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10903: }
10904: }
1.444 albertel 10905: }
10906: if ($args->{'no_end_date'}) {
10907: $args->{'endaccess'} = 0;
10908: }
10909: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10910: $cenv{'internal.autoend'}=$args->{'enrollend'};
10911: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10912: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10913: if ($args->{'showphotos'}) {
10914: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10915: }
10916: $cenv{'internal.authtype'} = $args->{'authtype'};
10917: $cenv{'internal.autharg'} = $args->{'autharg'};
10918: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10919: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10920: 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');
10921: if ($context eq 'auto') {
10922: $outcome .= $krb_msg;
10923: } else {
1.566 albertel 10924: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10925: }
10926: $outcome .= $linefeed;
1.444 albertel 10927: }
10928: }
10929: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10930: if ($args->{'setpolicy'}) {
10931: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10932: }
10933: if ($args->{'setcontent'}) {
10934: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10935: }
10936: }
10937: if ($args->{'reshome'}) {
10938: $cenv{'reshome'}=$args->{'reshome'}.'/';
10939: $cenv{'reshome'}=~s/\/+$/\//;
10940: }
10941: #
10942: # course has keyed access
10943: #
10944: if ($args->{'setkeys'}) {
10945: $cenv{'keyaccess'}='yes';
10946: }
10947: # if specified, key authority is not course, but user
10948: # only active if keyaccess is yes
10949: if ($args->{'keyauth'}) {
1.487 albertel 10950: my ($user,$domain) = split(':',$args->{'keyauth'});
10951: $user = &LONCAPA::clean_username($user);
10952: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10953: if ($user ne '' && $domain ne '') {
1.487 albertel 10954: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10955: }
10956: }
10957:
10958: if ($args->{'disresdis'}) {
10959: $cenv{'pch.roles.denied'}='st';
10960: }
10961: if ($args->{'disablechat'}) {
10962: $cenv{'plc.roles.denied'}='st';
10963: }
10964:
10965: # Record we've not yet viewed the Course Initialization Helper for this
10966: # course
10967: $cenv{'course.helper.not.run'} = 1;
10968: #
10969: # Use new Randomseed
10970: #
10971: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10972: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10973: #
10974: # The encryption code and receipt prefix for this course
10975: #
10976: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10977: $cenv{'internal.encpref'}=100+int(9*rand(99));
10978: #
10979: # By default, use standard grading
10980: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10981:
1.541 raeburn 10982: $outcome .= $linefeed.&mt('Setting environment').': '.
10983: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10984: #
10985: # Open all assignments
10986: #
10987: if ($args->{'openall'}) {
10988: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10989: my %storecontent = ($storeunder => time,
10990: $storeunder.'.type' => 'date_start');
10991:
10992: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10993: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10994: }
10995: #
10996: # Set first page
10997: #
10998: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10999: || ($cloneid)) {
1.445 albertel 11000: use LONCAPA::map;
1.444 albertel 11001: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 11002:
11003: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
11004: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
11005:
1.444 albertel 11006: $outcome .= ($fatal?$errtext:'read ok').' - ';
11007: my $title; my $url;
11008: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 11009: $title=&mt('Syllabus');
1.444 albertel 11010: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
11011: } else {
1.963 raeburn 11012: $title=&mt('Table of Contents');
1.444 albertel 11013: $url='/adm/navmaps';
11014: }
1.445 albertel 11015:
11016: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
11017: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
11018:
11019: if ($errtext) { $fatal=2; }
1.541 raeburn 11020: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 11021: }
1.566 albertel 11022:
11023: return (1,$outcome);
1.444 albertel 11024: }
11025:
11026: ############################################################
11027: ############################################################
11028:
1.953 droeschl 11029: #SD
11030: # only Community and Course, or anything else?
1.378 raeburn 11031: sub course_type {
11032: my ($cid) = @_;
11033: if (!defined($cid)) {
11034: $cid = $env{'request.course.id'};
11035: }
1.404 albertel 11036: if (defined($env{'course.'.$cid.'.type'})) {
11037: return $env{'course.'.$cid.'.type'};
1.378 raeburn 11038: } else {
11039: return 'Course';
1.377 raeburn 11040: }
11041: }
1.156 albertel 11042:
1.406 raeburn 11043: sub group_term {
11044: my $crstype = &course_type();
11045: my %names = (
11046: 'Course' => 'group',
1.865 raeburn 11047: 'Community' => 'group',
1.406 raeburn 11048: );
11049: return $names{$crstype};
11050: }
11051:
1.902 raeburn 11052: sub course_types {
11053: my @types = ('official','unofficial','community');
11054: my %typename = (
11055: official => 'Official course',
11056: unofficial => 'Unofficial course',
11057: community => 'Community',
11058: );
11059: return (\@types,\%typename);
11060: }
11061:
1.156 albertel 11062: sub icon {
11063: my ($file)=@_;
1.505 albertel 11064: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 11065: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 11066: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 11067: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
11068: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
11069: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11070: $curfext.".gif") {
11071: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11072: $curfext.".gif";
11073: }
11074: }
1.249 albertel 11075: return &lonhttpdurl($iconname);
1.154 albertel 11076: }
1.84 albertel 11077:
1.575 albertel 11078: sub lonhttpdurl {
1.692 www 11079: #
11080: # Had been used for "small fry" static images on separate port 8080.
11081: # Modify here if lightweight http functionality desired again.
11082: # Currently eliminated due to increasing firewall issues.
11083: #
1.575 albertel 11084: my ($url)=@_;
1.692 www 11085: return $url;
1.215 albertel 11086: }
11087:
1.213 albertel 11088: sub connection_aborted {
11089: my ($r)=@_;
11090: $r->print(" ");$r->rflush();
11091: my $c = $r->connection;
11092: return $c->aborted();
11093: }
11094:
1.221 foxr 11095: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 11096: # strings as 'strings'.
11097: sub escape_single {
1.221 foxr 11098: my ($input) = @_;
1.223 albertel 11099: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 11100: $input =~ s/\'/\\\'/g; # Esacpe the 's....
11101: return $input;
11102: }
1.223 albertel 11103:
1.222 foxr 11104: # Same as escape_single, but escape's "'s This
11105: # can be used for "strings"
11106: sub escape_double {
11107: my ($input) = @_;
11108: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
11109: $input =~ s/\"/\\\"/g; # Esacpe the "s....
11110: return $input;
11111: }
1.223 albertel 11112:
1.222 foxr 11113: # Escapes the last element of a full URL.
11114: sub escape_url {
11115: my ($url) = @_;
1.238 raeburn 11116: my @urlslices = split(/\//, $url,-1);
1.369 www 11117: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 11118: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 11119: }
1.462 albertel 11120:
1.820 raeburn 11121: sub compare_arrays {
11122: my ($arrayref1,$arrayref2) = @_;
11123: my (@difference,%count);
11124: @difference = ();
11125: %count = ();
11126: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
11127: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
11128: foreach my $element (keys(%count)) {
11129: if ($count{$element} == 1) {
11130: push(@difference,$element);
11131: }
11132: }
11133: }
11134: return @difference;
11135: }
11136:
1.817 bisitz 11137: # -------------------------------------------------------- Initialize user login
1.462 albertel 11138: sub init_user_environment {
1.463 albertel 11139: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 11140: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
11141:
11142: my $public=($username eq 'public' && $domain eq 'public');
11143:
11144: # See if old ID present, if so, remove
11145:
11146: my ($filename,$cookie,$userroles);
11147: my $now=time;
11148:
11149: if ($public) {
11150: my $max_public=100;
11151: my $oldest;
11152: my $oldest_time=0;
11153: for(my $next=1;$next<=$max_public;$next++) {
11154: if (-e $lonids."/publicuser_$next.id") {
11155: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
11156: if ($mtime<$oldest_time || !$oldest_time) {
11157: $oldest_time=$mtime;
11158: $oldest=$next;
11159: }
11160: } else {
11161: $cookie="publicuser_$next";
11162: last;
11163: }
11164: }
11165: if (!$cookie) { $cookie="publicuser_$oldest"; }
11166: } else {
1.463 albertel 11167: # if this isn't a robot, kill any existing non-robot sessions
11168: if (!$args->{'robot'}) {
11169: opendir(DIR,$lonids);
11170: while ($filename=readdir(DIR)) {
11171: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
11172: unlink($lonids.'/'.$filename);
11173: }
1.462 albertel 11174: }
1.463 albertel 11175: closedir(DIR);
1.462 albertel 11176: }
11177: # Give them a new cookie
1.463 albertel 11178: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 11179: : $now.$$.int(rand(10000)));
1.463 albertel 11180: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 11181:
11182: # Initialize roles
11183:
11184: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
11185: }
11186: # ------------------------------------ Check browser type and MathML capability
11187:
11188: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
11189: $clientunicode,$clientos) = &decode_user_agent($r);
11190:
11191: # ------------------------------------------------------------- Get environment
11192:
11193: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
11194: my ($tmp) = keys(%userenv);
11195: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11196: } else {
11197: undef(%userenv);
11198: }
11199: if (($userenv{'interface'}) && (!$form->{'interface'})) {
11200: $form->{'interface'}=$userenv{'interface'};
11201: }
11202: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
11203:
11204: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 11205: foreach my $option ('interface','localpath','localres') {
11206: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 11207: }
11208: # --------------------------------------------------------- Write first profile
11209:
11210: {
11211: my %initial_env =
11212: ("user.name" => $username,
11213: "user.domain" => $domain,
11214: "user.home" => $authhost,
11215: "browser.type" => $clientbrowser,
11216: "browser.version" => $clientversion,
11217: "browser.mathml" => $clientmathml,
11218: "browser.unicode" => $clientunicode,
11219: "browser.os" => $clientos,
11220: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
11221: "request.course.fn" => '',
11222: "request.course.uri" => '',
11223: "request.course.sec" => '',
11224: "request.role" => 'cm',
11225: "request.role.adv" => $env{'user.adv'},
11226: "request.host" => $ENV{'REMOTE_ADDR'},);
11227:
11228: if ($form->{'localpath'}) {
11229: $initial_env{"browser.localpath"} = $form->{'localpath'};
11230: $initial_env{"browser.localres"} = $form->{'localres'};
11231: }
11232:
11233: if ($form->{'interface'}) {
11234: $form->{'interface'}=~s/\W//gs;
11235: $initial_env{"browser.interface"} = $form->{'interface'};
11236: $env{'browser.interface'}=$form->{'interface'};
11237: }
11238:
1.981 raeburn 11239: my %is_adv = ( is_adv => $env{'user.adv'} );
1.980 raeburn 11240: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
11241:
1.724 raeburn 11242: foreach my $tool ('aboutme','blog','portfolio') {
11243: $userenv{'availabletools.'.$tool} =
1.980 raeburn 11244: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
11245: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 11246: }
11247:
1.864 raeburn 11248: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 11249: $userenv{'canrequest.'.$crstype} =
11250: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 11251: 'reload','requestcourses',
11252: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 11253: }
11254:
1.462 albertel 11255: $env{'user.environment'} = "$lonids/$cookie.id";
11256:
11257: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
11258: &GDBM_WRCREAT(),0640)) {
11259: &_add_to_env(\%disk_env,\%initial_env);
11260: &_add_to_env(\%disk_env,\%userenv,'environment.');
11261: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 11262: if (ref($args->{'extra_env'})) {
11263: &_add_to_env(\%disk_env,$args->{'extra_env'});
11264: }
1.462 albertel 11265: untie(%disk_env);
11266: } else {
1.705 tempelho 11267: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
11268: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 11269: return 'error: '.$!;
11270: }
11271: }
11272: $env{'request.role'}='cm';
11273: $env{'request.role.adv'}=$env{'user.adv'};
11274: $env{'browser.type'}=$clientbrowser;
11275:
11276: return $cookie;
11277:
11278: }
11279:
11280: sub _add_to_env {
11281: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 11282: if (ref($env_data) eq 'HASH') {
11283: while (my ($key,$value) = each(%$env_data)) {
11284: $idf->{$prefix.$key} = $value;
11285: $env{$prefix.$key} = $value;
11286: }
1.462 albertel 11287: }
11288: }
11289:
1.685 tempelho 11290: # --- Get the symbolic name of a problem and the url
11291: sub get_symb {
11292: my ($request,$silent) = @_;
1.726 raeburn 11293: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 11294: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
11295: if ($symb eq '') {
11296: if (!$silent) {
11297: $request->print("Unable to handle ambiguous references:$url:.");
11298: return ();
11299: }
11300: }
11301: &Apache::lonenc::check_decrypt(\$symb);
11302: return ($symb);
11303: }
11304:
11305: # --------------------------------------------------------------Get annotation
11306:
11307: sub get_annotation {
11308: my ($symb,$enc) = @_;
11309:
11310: my $key = $symb;
11311: if (!$enc) {
11312: $key =
11313: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
11314: }
11315: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
11316: return $annotation{$key};
11317: }
11318:
11319: sub clean_symb {
1.731 raeburn 11320: my ($symb,$delete_enc) = @_;
1.685 tempelho 11321:
11322: &Apache::lonenc::check_decrypt(\$symb);
11323: my $enc = $env{'request.enc'};
1.731 raeburn 11324: if ($delete_enc) {
1.730 raeburn 11325: delete($env{'request.enc'});
11326: }
1.685 tempelho 11327:
11328: return ($symb,$enc);
11329: }
1.462 albertel 11330:
1.990 raeburn 11331: sub build_release_hashes {
11332: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
11333: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
11334: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
11335: (ref($randomizetry) eq 'HASH'));
11336: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
11337: my ($item,$name,$value) = split(/:/,$key);
11338: if ($item eq 'parameter') {
11339: if (ref($checkparms->{$name}) eq 'ARRAY') {
11340: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
11341: push(@{$checkparms->{$name}},$value);
11342: }
11343: } else {
11344: push(@{$checkparms->{$name}},$value);
11345: }
11346: } elsif ($item eq 'resourcetag') {
11347: if ($name eq 'responsetype') {
11348: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
11349: }
11350: } elsif ($item eq 'course') {
11351: if ($name eq 'crstype') {
11352: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
11353: }
11354: }
11355: }
11356: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
11357: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
11358: return;
11359: }
11360:
1.41 ng 11361: =pod
11362:
11363: =back
11364:
1.112 bowersj2 11365: =cut
1.41 ng 11366:
1.112 bowersj2 11367: 1;
11368: __END__;
1.41 ng 11369:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>