Annotation of loncom/interface/loncommon.pm, revision 1.948.2.24
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.948.2.24! raeburn 4: # $Id: loncommon.pm,v 1.948.2.23 2011/01/05 19:57:17 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.909 raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 486: my $wintitle = 'Course_Browser';
1.931 raeburn 487: if ($crstype eq 'Community') {
1.932 raeburn 488: $wintitle = 'Community_Browser';
1.909 raeburn 489: }
1.876 raeburn 490: my $id_functions = &javascript_index_functions();
491: my $output = '
1.776 bisitz 492: <script type="text/javascript" language="JavaScript">
1.824 bisitz 493: // <![CDATA[
1.468 raeburn 494: var stdeditbrowser;'."\n";
1.876 raeburn 495:
496: $output .= <<"ENDSTDBRW";
1.909 raeburn 497: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 498: var url = '/adm/pickcourse?';
1.895 raeburn 499: var formid = getFormIdByName(formname);
1.876 raeburn 500: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 501: if (domainfilter != null) {
502: if (domainfilter != '') {
503: url += 'domainfilter='+domainfilter+'&';
504: }
505: }
1.91 www 506: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 507: '&cdomelement='+udom+
508: '&cnameelement='+desc;
1.468 raeburn 509: if (extra_element !=null && extra_element != '') {
1.594 raeburn 510: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 511: url += '&roleelement='+extra_element;
512: if (domainfilter == null || domainfilter == '') {
513: url += '&domainfilter='+extra_element;
514: }
1.234 raeburn 515: }
1.468 raeburn 516: else {
517: if (formname == 'portform') {
518: url += '&setroles='+extra_element;
1.800 raeburn 519: } else {
520: if (formname == 'rules') {
521: url += '&fixeddom='+extra_element;
522: }
1.468 raeburn 523: }
524: }
1.230 raeburn 525: }
1.909 raeburn 526: if (type != null && type != '') {
527: url += '&type='+type;
528: }
529: if (type_elem != null && type_elem != '') {
530: url += '&typeelement='+type_elem;
531: }
1.872 raeburn 532: if (formname == 'ccrs') {
533: var ownername = document.forms[formid].ccuname.value;
534: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
535: url += '&cloner='+ownername+':'+ownerdom;
536: }
1.293 raeburn 537: if (multflag !=null && multflag != '') {
538: url += '&multiple='+multflag;
539: }
1.909 raeburn 540: var title = '$wintitle';
1.91 www 541: var options = 'scrollbars=1,resizable=1,menubar=0';
542: options += ',width=700,height=600';
543: stdeditbrowser = open(url,title,options,'1');
544: stdeditbrowser.focus();
545: }
1.876 raeburn 546: $id_functions
547: ENDSTDBRW
1.905 raeburn 548: if (($sec_element ne '') || ($role_element ne '')) {
549: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 550: }
551: $output .= '
552: // ]]>
553: </script>';
554: return $output;
555: }
556:
557: sub javascript_index_functions {
558: return <<"ENDJS";
559:
560: function getFormIdByName(formname) {
561: for (var i=0;i<document.forms.length;i++) {
562: if (document.forms[i].name == formname) {
563: return i;
564: }
565: }
566: return -1;
567: }
568:
569: function getIndexByName(formid,item) {
570: for (var i=0;i<document.forms[formid].elements.length;i++) {
571: if (document.forms[formid].elements[i].name == item) {
572: return i;
573: }
574: }
575: return -1;
576: }
1.468 raeburn 577:
1.876 raeburn 578: function getDomainFromSelectbox(formname,udom) {
579: var userdom;
580: var formid = getFormIdByName(formname);
581: if (formid > -1) {
582: var domid = getIndexByName(formid,udom);
583: if (domid > -1) {
584: if (document.forms[formid].elements[domid].type == 'select-one') {
585: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
586: }
587: if (document.forms[formid].elements[domid].type == 'hidden') {
588: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 589: }
590: }
591: }
1.876 raeburn 592: return userdom;
593: }
594:
595: ENDJS
1.468 raeburn 596:
1.876 raeburn 597: }
598:
599: sub userbrowser_javascript {
600: my $id_functions = &javascript_index_functions();
601: return <<"ENDUSERBRW";
602:
1.888 raeburn 603: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 604: var url = '/adm/pickuser?';
605: var userdom = getDomainFromSelectbox(formname,udom);
606: if (userdom != null) {
607: if (userdom != '') {
608: url += 'srchdom='+userdom+'&';
609: }
610: }
611: url += 'form=' + formname + '&unameelement='+uname+
612: '&udomelement='+udom+
613: '&ulastelement='+ulast+
614: '&ufirstelement='+ufirst+
615: '&uemailelement='+uemail+
1.881 raeburn 616: '&hideudomelement='+hideudom+
617: '&coursedom='+crsdom;
1.888 raeburn 618: if ((caller != null) && (caller != undefined)) {
619: url += '&caller='+caller;
620: }
1.876 raeburn 621: var title = 'User_Browser';
622: var options = 'scrollbars=1,resizable=1,menubar=0';
623: options += ',width=700,height=600';
624: var stdeditbrowser = open(url,title,options,'1');
625: stdeditbrowser.focus();
626: }
627:
1.888 raeburn 628: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 629: var formid = getFormIdByName(formname);
630: if (formid > -1) {
1.888 raeburn 631: var unameid = getIndexByName(formid,uname);
1.876 raeburn 632: var domid = getIndexByName(formid,udom);
633: var hidedomid = getIndexByName(formid,origdom);
634: if (hidedomid > -1) {
635: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 636: var unameval = document.forms[formid].elements[unameid].value;
637: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
638: if (domid > -1) {
639: var slct = document.forms[formid].elements[domid];
640: if (slct.type == 'select-one') {
641: var i;
642: for (i=0;i<slct.length;i++) {
643: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
644: }
645: }
646: if (slct.type == 'hidden') {
647: slct.value = fixeddom;
1.876 raeburn 648: }
649: }
1.468 raeburn 650: }
651: }
652: }
1.876 raeburn 653: return;
654: }
655:
656: $id_functions
657: ENDUSERBRW
1.468 raeburn 658: }
659:
660: sub setsec_javascript {
1.905 raeburn 661: my ($sec_element,$formname,$role_element) = @_;
662: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
663: $communityrolestr);
664: if ($role_element ne '') {
665: my @allroles = ('st','ta','ep','in','ad');
666: foreach my $crstype ('Course','Community') {
667: if ($crstype eq 'Community') {
668: foreach my $role (@allroles) {
669: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
670: }
671: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
672: } else {
673: foreach my $role (@allroles) {
674: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
675: }
676: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
677: }
678: }
679: $rolestr = '"'.join('","',@allroles).'"';
680: $courserolestr = '"'.join('","',@courserolenames).'"';
681: $communityrolestr = '"'.join('","',@communityrolenames).'"';
682: }
1.468 raeburn 683: my $setsections = qq|
684: function setSect(sectionlist) {
1.629 raeburn 685: var sectionsArray = new Array();
686: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
687: sectionsArray = sectionlist.split(",");
688: }
1.468 raeburn 689: var numSections = sectionsArray.length;
690: document.$formname.$sec_element.length = 0;
691: if (numSections == 0) {
692: document.$formname.$sec_element.multiple=false;
693: document.$formname.$sec_element.size=1;
694: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
695: } else {
696: if (numSections == 1) {
697: document.$formname.$sec_element.multiple=false;
698: document.$formname.$sec_element.size=1;
699: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
700: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
701: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
702: } else {
703: for (var i=0; i<numSections; i++) {
704: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
705: }
706: document.$formname.$sec_element.multiple=true
707: if (numSections < 3) {
708: document.$formname.$sec_element.size=numSections;
709: } else {
710: document.$formname.$sec_element.size=3;
711: }
712: document.$formname.$sec_element.options[0].selected = false
713: }
714: }
1.91 www 715: }
1.905 raeburn 716:
717: function setRole(crstype) {
1.468 raeburn 718: |;
1.905 raeburn 719: if ($role_element eq '') {
720: $setsections .= ' return;
721: }
722: ';
723: } else {
724: $setsections .= qq|
725: var elementLength = document.$formname.$role_element.length;
726: var allroles = Array($rolestr);
727: var courserolenames = Array($courserolestr);
728: var communityrolenames = Array($communityrolestr);
729: if (elementLength != undefined) {
730: if (document.$formname.$role_element.options[5].value == 'cc') {
731: if (crstype == 'Course') {
732: return;
733: } else {
734: allroles[5] = 'co';
735: for (var i=0; i<6; i++) {
736: document.$formname.$role_element.options[i].value = allroles[i];
737: document.$formname.$role_element.options[i].text = communityrolenames[i];
738: }
739: }
740: } else {
741: if (crstype == 'Community') {
742: return;
743: } else {
744: allroles[5] = 'cc';
745: for (var i=0; i<6; i++) {
746: document.$formname.$role_element.options[i].value = allroles[i];
747: document.$formname.$role_element.options[i].text = courserolenames[i];
748: }
749: }
750: }
751: }
752: return;
753: }
754: |;
755: }
1.468 raeburn 756: return $setsections;
757: }
758:
1.91 www 759: sub selectcourse_link {
1.909 raeburn 760: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
761: $typeelement) = @_;
762: my $type = $selecttype;
1.871 raeburn 763: my $linktext = &mt('Select Course');
764: if ($selecttype eq 'Community') {
1.909 raeburn 765: $linktext = &mt('Select Community');
1.906 raeburn 766: } elsif ($selecttype eq 'Course/Community') {
767: $linktext = &mt('Select Course/Community');
1.909 raeburn 768: $type = '';
1.871 raeburn 769: }
1.787 bisitz 770: return '<span class="LC_nobreak">'
771: ."<a href='"
772: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
773: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 774: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 775: ."'>".$linktext.'</a>'
1.787 bisitz 776: .'</span>';
1.74 www 777: }
1.42 matthew 778:
1.653 raeburn 779: sub selectauthor_link {
780: my ($form,$udom)=@_;
781: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
782: &mt('Select Author').'</a>';
783: }
784:
1.876 raeburn 785: sub selectuser_link {
1.881 raeburn 786: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 787: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 788: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 789: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 790: ');">'.$linktext.'</a>';
1.876 raeburn 791: }
792:
1.273 raeburn 793: sub check_uncheck_jscript {
794: my $jscript = <<"ENDSCRT";
795: function checkAll(field) {
796: if (field.length > 0) {
797: for (i = 0; i < field.length; i++) {
798: field[i].checked = true ;
799: }
800: } else {
801: field.checked = true
802: }
803: }
804:
805: function uncheckAll(field) {
806: if (field.length > 0) {
807: for (i = 0; i < field.length; i++) {
808: field[i].checked = false ;
1.543 albertel 809: }
810: } else {
1.273 raeburn 811: field.checked = false ;
812: }
813: }
814: ENDSCRT
815: return $jscript;
816: }
817:
1.656 www 818: sub select_timezone {
1.659 raeburn 819: my ($name,$selected,$onchange,$includeempty)=@_;
820: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
821: if ($includeempty) {
822: $output .= '<option value=""';
823: if (($selected eq '') || ($selected eq 'local')) {
824: $output .= ' selected="selected" ';
825: }
826: $output .= '> </option>';
827: }
1.657 raeburn 828: my @timezones = DateTime::TimeZone->all_names;
829: foreach my $tzone (@timezones) {
830: $output.= '<option value="'.$tzone.'"';
831: if ($tzone eq $selected) {
832: $output.=' selected="selected"';
833: }
834: $output.=">$tzone</option>\n";
1.656 www 835: }
836: $output.="</select>";
837: return $output;
838: }
1.273 raeburn 839:
1.687 raeburn 840: sub select_datelocale {
841: my ($name,$selected,$onchange,$includeempty)=@_;
842: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
843: if ($includeempty) {
844: $output .= '<option value=""';
845: if ($selected eq '') {
846: $output .= ' selected="selected" ';
847: }
848: $output .= '> </option>';
849: }
850: my (@possibles,%locale_names);
851: my @locales = DateTime::Locale::Catalog::Locales;
852: foreach my $locale (@locales) {
853: if (ref($locale) eq 'HASH') {
854: my $id = $locale->{'id'};
855: if ($id ne '') {
856: my $en_terr = $locale->{'en_territory'};
857: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 858: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 859: if (grep(/^en$/,@languages) || !@languages) {
860: if ($en_terr ne '') {
861: $locale_names{$id} = '('.$en_terr.')';
862: } elsif ($native_terr ne '') {
863: $locale_names{$id} = $native_terr;
864: }
865: } else {
866: if ($native_terr ne '') {
867: $locale_names{$id} = $native_terr.' ';
868: } elsif ($en_terr ne '') {
869: $locale_names{$id} = '('.$en_terr.')';
870: }
871: }
872: push (@possibles,$id);
873: }
874: }
875: }
876: foreach my $item (sort(@possibles)) {
877: $output.= '<option value="'.$item.'"';
878: if ($item eq $selected) {
879: $output.=' selected="selected"';
880: }
881: $output.=">$item";
882: if ($locale_names{$item} ne '') {
883: $output.=" $locale_names{$item}</option>\n";
884: }
885: $output.="</option>\n";
886: }
887: $output.="</select>";
888: return $output;
889: }
890:
1.792 raeburn 891: sub select_language {
892: my ($name,$selected,$includeempty) = @_;
893: my %langchoices;
894: if ($includeempty) {
895: %langchoices = ('' => 'No language preference');
896: }
897: foreach my $id (&languageids()) {
898: my $code = &supportedlanguagecode($id);
899: if ($code) {
900: $langchoices{$code} = &plainlanguagedescription($id);
901: }
902: }
1.948.2.7 raeburn 903: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 904: }
905:
1.42 matthew 906: =pod
1.36 matthew 907:
1.648 raeburn 908: =item * &linked_select_forms(...)
1.36 matthew 909:
910: linked_select_forms returns a string containing a <script></script> block
911: and html for two <select> menus. The select menus will be linked in that
912: changing the value of the first menu will result in new values being placed
913: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 914: order unless a defined order is provided.
1.36 matthew 915:
916: linked_select_forms takes the following ordered inputs:
917:
918: =over 4
919:
1.112 bowersj2 920: =item * $formname, the name of the <form> tag
1.36 matthew 921:
1.112 bowersj2 922: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 923:
1.112 bowersj2 924: =item * $firstdefault, the default value for the first menu
1.36 matthew 925:
1.112 bowersj2 926: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 927:
1.112 bowersj2 928: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 929:
1.112 bowersj2 930: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 931:
1.609 raeburn 932: =item * $menuorder, the order of values in the first menu
933:
1.41 ng 934: =back
935:
1.36 matthew 936: Below is an example of such a hash. Only the 'text', 'default', and
937: 'select2' keys must appear as stated. keys(%menu) are the possible
938: values for the first select menu. The text that coincides with the
1.41 ng 939: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 940: and text for the second menu are given in the hash pointed to by
941: $menu{$choice1}->{'select2'}.
942:
1.112 bowersj2 943: my %menu = ( A1 => { text =>"Choice A1" ,
944: default => "B3",
945: select2 => {
946: B1 => "Choice B1",
947: B2 => "Choice B2",
948: B3 => "Choice B3",
949: B4 => "Choice B4"
1.609 raeburn 950: },
951: order => ['B4','B3','B1','B2'],
1.112 bowersj2 952: },
953: A2 => { text =>"Choice A2" ,
954: default => "C2",
955: select2 => {
956: C1 => "Choice C1",
957: C2 => "Choice C2",
958: C3 => "Choice C3"
1.609 raeburn 959: },
960: order => ['C2','C1','C3'],
1.112 bowersj2 961: },
962: A3 => { text =>"Choice A3" ,
963: default => "D6",
964: select2 => {
965: D1 => "Choice D1",
966: D2 => "Choice D2",
967: D3 => "Choice D3",
968: D4 => "Choice D4",
969: D5 => "Choice D5",
970: D6 => "Choice D6",
971: D7 => "Choice D7"
1.609 raeburn 972: },
973: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 974: }
975: );
1.36 matthew 976:
977: =cut
978:
979: sub linked_select_forms {
980: my ($formname,
981: $middletext,
982: $firstdefault,
983: $firstselectname,
984: $secondselectname,
1.609 raeburn 985: $hashref,
986: $menuorder,
1.36 matthew 987: ) = @_;
988: my $second = "document.$formname.$secondselectname";
989: my $first = "document.$formname.$firstselectname";
990: # output the javascript to do the changing
991: my $result = '';
1.776 bisitz 992: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 993: $result.="// <![CDATA[\n";
1.36 matthew 994: $result.="var select2data = new Object();\n";
995: $" = '","';
996: my $debug = '';
997: foreach my $s1 (sort(keys(%$hashref))) {
998: $result.="select2data.d_$s1 = new Object();\n";
999: $result.="select2data.d_$s1.def = new String('".
1000: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1001: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1002: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1003: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1004: @s2values = @{$hashref->{$s1}->{'order'}};
1005: }
1.36 matthew 1006: $result.="\"@s2values\");\n";
1007: $result.="select2data.d_$s1.texts = new Array(";
1008: my @s2texts;
1009: foreach my $value (@s2values) {
1010: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1011: }
1012: $result.="\"@s2texts\");\n";
1013: }
1014: $"=' ';
1015: $result.= <<"END";
1016:
1017: function select1_changed() {
1018: // Determine new choice
1019: var newvalue = "d_" + $first.value;
1020: // update select2
1021: var values = select2data[newvalue].values;
1022: var texts = select2data[newvalue].texts;
1023: var select2def = select2data[newvalue].def;
1024: var i;
1025: // out with the old
1026: for (i = 0; i < $second.options.length; i++) {
1027: $second.options[i] = null;
1028: }
1029: // in with the nuclear
1030: for (i=0;i<values.length; i++) {
1031: $second.options[i] = new Option(values[i]);
1.143 matthew 1032: $second.options[i].value = values[i];
1.36 matthew 1033: $second.options[i].text = texts[i];
1034: if (values[i] == select2def) {
1035: $second.options[i].selected = true;
1036: }
1037: }
1038: }
1.824 bisitz 1039: // ]]>
1.36 matthew 1040: </script>
1041: END
1042: # output the initial values for the selection lists
1043: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1044: my @order = sort(keys(%{$hashref}));
1045: if (ref($menuorder) eq 'ARRAY') {
1046: @order = @{$menuorder};
1047: }
1048: foreach my $value (@order) {
1.36 matthew 1049: $result.=" <option value=\"$value\" ";
1.253 albertel 1050: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1051: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1052: }
1053: $result .= "</select>\n";
1054: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1055: $result .= $middletext;
1056: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1057: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1058:
1059: my @secondorder = sort(keys(%select2));
1060: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1061: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1062: }
1063: foreach my $value (@secondorder) {
1.36 matthew 1064: $result.=" <option value=\"$value\" ";
1.253 albertel 1065: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1066: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1067: }
1068: $result .= "</select>\n";
1069: # return $debug;
1070: return $result;
1071: } # end of sub linked_select_forms {
1072:
1.45 matthew 1073: =pod
1.44 bowersj2 1074:
1.948.2.7 raeburn 1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1076:
1.112 bowersj2 1077: Returns a string corresponding to an HTML link to the given help
1078: $topic, where $topic corresponds to the name of a .tex file in
1079: /home/httpd/html/adm/help/tex, with underscores replaced by
1080: spaces.
1081:
1082: $text will optionally be linked to the same topic, allowing you to
1083: link text in addition to the graphic. If you do not want to link
1084: text, but wish to specify one of the later parameters, pass an
1085: empty string.
1086:
1087: $stayOnPage is a value that will be interpreted as a boolean. If true,
1088: the link will not open a new window. If false, the link will open
1089: a new window using Javascript. (Default is false.)
1090:
1091: $width and $height are optional numerical parameters that will
1092: override the width and height of the popped up window, which may
1093: be useful for certain help topics with big pictures included.
1.44 bowersj2 1094:
1095: =cut
1096:
1097: sub help_open_topic {
1.948.2.7 raeburn 1098: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1099: $text = "" if (not defined $text);
1.44 bowersj2 1100: $stayOnPage = 0 if (not defined $stayOnPage);
1101: $width = 350 if (not defined $width);
1102: $height = 400 if (not defined $height);
1103: my $filename = $topic;
1104: $filename =~ s/ /_/g;
1105:
1.48 bowersj2 1106: my $template = "";
1107: my $link;
1.572 banghart 1108:
1.159 www 1109: $topic=~s/\W/\_/g;
1.44 bowersj2 1110:
1.572 banghart 1111: if (!$stayOnPage) {
1.72 bowersj2 1112: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1113: } else {
1.48 bowersj2 1114: $link = "/adm/help/${filename}.hlp";
1115: }
1116:
1117: # Add the text
1.755 neumanie 1118: if ($text ne "") {
1.763 bisitz 1119: $template.='<span class="LC_help_open_topic">'
1120: .'<a target="_top" href="'.$link.'">'
1121: .$text.'</a>';
1.48 bowersj2 1122: }
1123:
1.763 bisitz 1124: # (Always) Add the graphic
1.179 matthew 1125: my $title = &mt('Online Help');
1.667 raeburn 1126: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.948.2.7 raeburn 1127: if ($imgid ne '') {
1128: $imgid = ' id="'.$imgid.'"';
1129: }
1.763 bisitz 1130: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1131: .'<img src="'.$helpicon.'" border="0"'
1132: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.948.2.7 raeburn 1133: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1134: .' /></a>';
1.948.2.7 raeburn 1135: if ($text ne "") {
1.763 bisitz 1136: $template.='</span>';
1137: }
1.44 bowersj2 1138: return $template;
1139:
1.106 bowersj2 1140: }
1141:
1142: # This is a quicky function for Latex cheatsheet editing, since it
1143: # appears in at least four places
1144: sub helpLatexCheatsheet {
1.732 raeburn 1145: my ($topic,$text,$not_author) = @_;
1146: my $out;
1.106 bowersj2 1147: my $addOther = '';
1.732 raeburn 1148: if ($topic) {
1.763 bisitz 1149: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1150: undef, undef, 600).
1151: '</span> ';
1152: }
1153: $out = '<span>' # Start cheatsheet
1154: .$addOther
1155: .'<span>'
1156: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1157: undef,undef,600)
1158: .'</span> <span>'
1159: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1160: undef,undef,600)
1161: .'</span>';
1.732 raeburn 1162: unless ($not_author) {
1.763 bisitz 1163: $out .= ' <span>'
1164: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1165: undef,undef,600)
1166: .'</span>';
1.732 raeburn 1167: }
1.763 bisitz 1168: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1169: return $out;
1.172 www 1170: }
1171:
1.430 albertel 1172: sub general_help {
1173: my $helptopic='Student_Intro';
1174: if ($env{'request.role'}=~/^(ca|au)/) {
1175: $helptopic='Authoring_Intro';
1.907 raeburn 1176: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1177: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1178: } elsif ($env{'request.role'}=~/^dc/) {
1179: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1180: }
1181: return $helptopic;
1182: }
1183:
1184: sub update_help_link {
1185: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1186: my $origurl = $ENV{'REQUEST_URI'};
1187: $origurl=~s|^/~|/priv/|;
1188: my $timestamp = time;
1189: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1190: $$datum = &escape($$datum);
1191: }
1192:
1193: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1194: my $output .= <<"ENDOUTPUT";
1195: <script type="text/javascript">
1.824 bisitz 1196: // <![CDATA[
1.430 albertel 1197: banner_link = '$banner_link';
1.824 bisitz 1198: // ]]>
1.430 albertel 1199: </script>
1200: ENDOUTPUT
1201: return $output;
1202: }
1203:
1204: # now just updates the help link and generates a blue icon
1.193 raeburn 1205: sub help_open_menu {
1.430 albertel 1206: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1207: = @_;
1.430 albertel 1208: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1209: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1210: # if environment.remote is on (using remote control UI)
1.798 tempelho 1211: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1212: $stayOnPage=1;
1.430 albertel 1213: }
1214: my $output;
1215: if ($component_help) {
1216: if (!$text) {
1217: $output=&help_open_topic($component_help,undef,$stayOnPage,
1218: $width,$height);
1219: } else {
1220: my $help_text;
1221: $help_text=&unescape($topic);
1222: $output='<table><tr><td>'.
1223: &help_open_topic($component_help,$help_text,$stayOnPage,
1224: $width,$height).'</td></tr></table>';
1225: }
1226: }
1227: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1228: return $output.$banner_link;
1229: }
1230:
1231: sub top_nav_help {
1232: my ($text) = @_;
1.436 albertel 1233: $text = &mt($text);
1.572 banghart 1234: my $stay_on_page =
1.798 tempelho 1235: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1236: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1237: : "javascript:helpMenu('open')";
1.572 banghart 1238: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1239:
1.201 raeburn 1240: my $title = &mt('Get help');
1.436 albertel 1241:
1242: return <<"END";
1243: $banner_link
1244: <a href="$link" title="$title">$text</a>
1245: END
1246: }
1247:
1248: sub help_menu_js {
1249: my ($text) = @_;
1250:
1251: my $stayOnPage =
1.798 tempelho 1252: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1253:
1254: my $width = 620;
1255: my $height = 600;
1.430 albertel 1256: my $helptopic=&general_help();
1257: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1258: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1259: my $start_page =
1260: &Apache::loncommon::start_page('Help Menu', undef,
1261: {'frameset' => 1,
1262: 'js_ready' => 1,
1263: 'add_entries' => {
1264: 'border' => '0',
1.579 raeburn 1265: 'rows' => "110,*",},});
1.331 albertel 1266: my $end_page =
1267: &Apache::loncommon::end_page({'frameset' => 1,
1268: 'js_ready' => 1,});
1269:
1.436 albertel 1270: my $template .= <<"ENDTEMPLATE";
1271: <script type="text/javascript">
1.877 bisitz 1272: // <![CDATA[
1.253 albertel 1273: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1274: var banner_link = '';
1.243 raeburn 1275: function helpMenu(target) {
1276: var caller = this;
1277: if (target == 'open') {
1278: var newWindow = null;
1279: try {
1.262 albertel 1280: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1281: }
1282: catch(error) {
1283: writeHelp(caller);
1284: return;
1285: }
1286: if (newWindow) {
1287: caller = newWindow;
1288: }
1.193 raeburn 1289: }
1.243 raeburn 1290: writeHelp(caller);
1291: return;
1292: }
1293: function writeHelp(caller) {
1.430 albertel 1294: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1295: caller.document.close()
1296: caller.focus()
1.193 raeburn 1297: }
1.877 bisitz 1298: // END LON-CAPA Internal -->
1.253 albertel 1299: // ]]>
1.436 albertel 1300: </script>
1.193 raeburn 1301: ENDTEMPLATE
1302: return $template;
1303: }
1304:
1.172 www 1305: sub help_open_bug {
1306: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1307: unless ($env{'user.adv'}) { return ''; }
1.172 www 1308: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1309: $text = "" if (not defined $text);
1310: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1311: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1312: $stayOnPage=1;
1313: }
1.184 albertel 1314: $width = 600 if (not defined $width);
1315: $height = 600 if (not defined $height);
1.172 www 1316:
1317: $topic=~s/\W+/\+/g;
1318: my $link='';
1319: my $template='';
1.379 albertel 1320: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1321: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1322: if (!$stayOnPage)
1323: {
1324: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1325: }
1326: else
1327: {
1328: $link = $url;
1329: }
1330: # Add the text
1331: if ($text ne "")
1332: {
1333: $template .=
1334: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1335: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1336: }
1337:
1338: # Add the graphic
1.179 matthew 1339: my $title = &mt('Report a Bug');
1.215 albertel 1340: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1341: $template .= <<"ENDTEMPLATE";
1.436 albertel 1342: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1343: ENDTEMPLATE
1344: if ($text ne '') { $template.='</td></tr></table>' };
1345: return $template;
1346:
1347: }
1348:
1349: sub help_open_faq {
1350: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1351: unless ($env{'user.adv'}) { return ''; }
1.172 www 1352: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1353: $text = "" if (not defined $text);
1354: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1355: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1356: $stayOnPage=1;
1357: }
1358: $width = 350 if (not defined $width);
1359: $height = 400 if (not defined $height);
1360:
1361: $topic=~s/\W+/\+/g;
1362: my $link='';
1363: my $template='';
1364: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1365: if (!$stayOnPage)
1366: {
1367: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1368: }
1369: else
1370: {
1371: $link = $url;
1372: }
1373:
1374: # Add the text
1375: if ($text ne "")
1376: {
1377: $template .=
1.173 www 1378: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1379: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1380: }
1381:
1382: # Add the graphic
1.179 matthew 1383: my $title = &mt('View the FAQ');
1.215 albertel 1384: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1385: $template .= <<"ENDTEMPLATE";
1.436 albertel 1386: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1387: ENDTEMPLATE
1388: if ($text ne '') { $template.='</td></tr></table>' };
1389: return $template;
1390:
1.44 bowersj2 1391: }
1.37 matthew 1392:
1.180 matthew 1393: ###############################################################
1394: ###############################################################
1395:
1.45 matthew 1396: =pod
1397:
1.648 raeburn 1398: =item * &change_content_javascript():
1.256 matthew 1399:
1400: This and the next function allow you to create small sections of an
1401: otherwise static HTML page that you can update on the fly with
1402: Javascript, even in Netscape 4.
1403:
1404: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1405: must be written to the HTML page once. It will prove the Javascript
1406: function "change(name, content)". Calling the change function with the
1407: name of the section
1408: you want to update, matching the name passed to C<changable_area>, and
1409: the new content you want to put in there, will put the content into
1410: that area.
1411:
1412: B<Note>: Netscape 4 only reserves enough space for the changable area
1413: to contain room for the original contents. You need to "make space"
1414: for whatever changes you wish to make, and be B<sure> to check your
1415: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1416: it's adequate for updating a one-line status display, but little more.
1417: This script will set the space to 100% width, so you only need to
1418: worry about height in Netscape 4.
1419:
1420: Modern browsers are much less limiting, and if you can commit to the
1421: user not using Netscape 4, this feature may be used freely with
1422: pretty much any HTML.
1423:
1424: =cut
1425:
1426: sub change_content_javascript {
1427: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1428: if ($env{'browser.type'} eq 'netscape' &&
1429: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1430: return (<<NETSCAPE4);
1431: function change(name, content) {
1432: doc = document.layers[name+"___escape"].layers[0].document;
1433: doc.open();
1434: doc.write(content);
1435: doc.close();
1436: }
1437: NETSCAPE4
1438: } else {
1439: # Otherwise, we need to use semi-standards-compliant code
1440: # (technically, "innerHTML" isn't standard but the equivalent
1441: # is really scary, and every useful browser supports it
1442: return (<<DOMBASED);
1443: function change(name, content) {
1444: element = document.getElementById(name);
1445: element.innerHTML = content;
1446: }
1447: DOMBASED
1448: }
1449: }
1450:
1451: =pod
1452:
1.648 raeburn 1453: =item * &changable_area($name,$origContent):
1.256 matthew 1454:
1455: This provides a "changable area" that can be modified on the fly via
1456: the Javascript code provided in C<change_content_javascript>. $name is
1457: the name you will use to reference the area later; do not repeat the
1458: same name on a given HTML page more then once. $origContent is what
1459: the area will originally contain, which can be left blank.
1460:
1461: =cut
1462:
1463: sub changable_area {
1464: my ($name, $origContent) = @_;
1465:
1.258 albertel 1466: if ($env{'browser.type'} eq 'netscape' &&
1467: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1468: # If this is netscape 4, we need to use the Layer tag
1469: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1470: } else {
1471: return "<span id='$name'>$origContent</span>";
1472: }
1473: }
1474:
1475: =pod
1476:
1.648 raeburn 1477: =item * &viewport_geometry_js
1.590 raeburn 1478:
1479: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1480:
1481: =cut
1482:
1483:
1484: sub viewport_geometry_js {
1485: return <<"GEOMETRY";
1486: var Geometry = {};
1487: function init_geometry() {
1488: if (Geometry.init) { return };
1489: Geometry.init=1;
1490: if (window.innerHeight) {
1491: Geometry.getViewportHeight = function() { return window.innerHeight; };
1492: Geometry.getViewportWidth = function() { return window.innerWidth; };
1493: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1494: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1495: }
1496: else if (document.documentElement && document.documentElement.clientHeight) {
1497: Geometry.getViewportHeight =
1498: function() { return document.documentElement.clientHeight; };
1499: Geometry.getViewportWidth =
1500: function() { return document.documentElement.clientWidth; };
1501:
1502: Geometry.getHorizontalScroll =
1503: function() { return document.documentElement.scrollLeft; };
1504: Geometry.getVerticalScroll =
1505: function() { return document.documentElement.scrollTop; };
1506: }
1507: else if (document.body.clientHeight) {
1508: Geometry.getViewportHeight =
1509: function() { return document.body.clientHeight; };
1510: Geometry.getViewportWidth =
1511: function() { return document.body.clientWidth; };
1512: Geometry.getHorizontalScroll =
1513: function() { return document.body.scrollLeft; };
1514: Geometry.getVerticalScroll =
1515: function() { return document.body.scrollTop; };
1516: }
1517: }
1518:
1519: GEOMETRY
1520: }
1521:
1522: =pod
1523:
1.648 raeburn 1524: =item * &viewport_size_js()
1.590 raeburn 1525:
1526: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1527:
1528: =cut
1529:
1530: sub viewport_size_js {
1531: my $geometry = &viewport_geometry_js();
1532: return <<"DIMS";
1533:
1534: $geometry
1535:
1536: function getViewportDims(width,height) {
1537: init_geometry();
1538: width.value = Geometry.getViewportWidth();
1539: height.value = Geometry.getViewportHeight();
1540: return;
1541: }
1542:
1543: DIMS
1544: }
1545:
1546: =pod
1547:
1.648 raeburn 1548: =item * &resize_textarea_js()
1.565 albertel 1549:
1550: emits the needed javascript to resize a textarea to be as big as possible
1551:
1552: creates a function resize_textrea that takes two IDs first should be
1553: the id of the element to resize, second should be the id of a div that
1554: surrounds everything that comes after the textarea, this routine needs
1555: to be attached to the <body> for the onload and onresize events.
1556:
1.648 raeburn 1557: =back
1.565 albertel 1558:
1559: =cut
1560:
1561: sub resize_textarea_js {
1.590 raeburn 1562: my $geometry = &viewport_geometry_js();
1.565 albertel 1563: return <<"RESIZE";
1564: <script type="text/javascript">
1.824 bisitz 1565: // <![CDATA[
1.590 raeburn 1566: $geometry
1.565 albertel 1567:
1.588 albertel 1568: function getX(element) {
1569: var x = 0;
1570: while (element) {
1571: x += element.offsetLeft;
1572: element = element.offsetParent;
1573: }
1574: return x;
1575: }
1576: function getY(element) {
1577: var y = 0;
1578: while (element) {
1579: y += element.offsetTop;
1580: element = element.offsetParent;
1581: }
1582: return y;
1583: }
1584:
1585:
1.565 albertel 1586: function resize_textarea(textarea_id,bottom_id) {
1587: init_geometry();
1588: var textarea = document.getElementById(textarea_id);
1589: //alert(textarea);
1590:
1.588 albertel 1591: var textarea_top = getY(textarea);
1.565 albertel 1592: var textarea_height = textarea.offsetHeight;
1593: var bottom = document.getElementById(bottom_id);
1.588 albertel 1594: var bottom_top = getY(bottom);
1.565 albertel 1595: var bottom_height = bottom.offsetHeight;
1596: var window_height = Geometry.getViewportHeight();
1.588 albertel 1597: var fudge = 23;
1.565 albertel 1598: var new_height = window_height-fudge-textarea_top-bottom_height;
1599: if (new_height < 300) {
1600: new_height = 300;
1601: }
1602: textarea.style.height=new_height+'px';
1603: }
1.824 bisitz 1604: // ]]>
1.565 albertel 1605: </script>
1606: RESIZE
1607:
1608: }
1609:
1610: =pod
1611:
1.256 matthew 1612: =head1 Excel and CSV file utility routines
1613:
1614: =over 4
1615:
1616: =cut
1617:
1618: ###############################################################
1619: ###############################################################
1620:
1621: =pod
1622:
1.648 raeburn 1623: =item * &csv_translate($text)
1.37 matthew 1624:
1.185 www 1625: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1626: format.
1627:
1628: =cut
1629:
1.180 matthew 1630: ###############################################################
1631: ###############################################################
1.37 matthew 1632: sub csv_translate {
1633: my $text = shift;
1634: $text =~ s/\"/\"\"/g;
1.209 albertel 1635: $text =~ s/\n/ /g;
1.37 matthew 1636: return $text;
1637: }
1.180 matthew 1638:
1639: ###############################################################
1640: ###############################################################
1641:
1642: =pod
1643:
1.648 raeburn 1644: =item * &define_excel_formats()
1.180 matthew 1645:
1646: Define some commonly used Excel cell formats.
1647:
1648: Currently supported formats:
1649:
1650: =over 4
1651:
1652: =item header
1653:
1654: =item bold
1655:
1656: =item h1
1657:
1658: =item h2
1659:
1660: =item h3
1661:
1.256 matthew 1662: =item h4
1663:
1664: =item i
1665:
1.180 matthew 1666: =item date
1667:
1668: =back
1669:
1670: Inputs: $workbook
1671:
1672: Returns: $format, a hash reference.
1673:
1674: =cut
1675:
1676: ###############################################################
1677: ###############################################################
1678: sub define_excel_formats {
1679: my ($workbook) = @_;
1680: my $format;
1681: $format->{'header'} = $workbook->add_format(bold => 1,
1682: bottom => 1,
1683: align => 'center');
1684: $format->{'bold'} = $workbook->add_format(bold=>1);
1685: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1686: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1687: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1688: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1689: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1690: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1691: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1692: return $format;
1693: }
1694:
1695: ###############################################################
1696: ###############################################################
1.113 bowersj2 1697:
1698: =pod
1699:
1.648 raeburn 1700: =item * &create_workbook()
1.255 matthew 1701:
1702: Create an Excel worksheet. If it fails, output message on the
1703: request object and return undefs.
1704:
1705: Inputs: Apache request object
1706:
1707: Returns (undef) on failure,
1708: Excel worksheet object, scalar with filename, and formats
1709: from &Apache::loncommon::define_excel_formats on success
1710:
1711: =cut
1712:
1713: ###############################################################
1714: ###############################################################
1715: sub create_workbook {
1716: my ($r) = @_;
1717: #
1718: # Create the excel spreadsheet
1719: my $filename = '/prtspool/'.
1.258 albertel 1720: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1721: time.'_'.rand(1000000000).'.xls';
1722: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1723: if (! defined($workbook)) {
1724: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1725: $r->print(
1726: '<p class="LC_error">'
1727: .&mt('Problems occurred in creating the new Excel file.')
1728: .' '.&mt('This error has been logged.')
1729: .' '.&mt('Please alert your LON-CAPA administrator.')
1730: .'</p>'
1731: );
1.255 matthew 1732: return (undef);
1733: }
1734: #
1735: $workbook->set_tempdir('/home/httpd/perl/tmp');
1736: #
1737: my $format = &Apache::loncommon::define_excel_formats($workbook);
1738: return ($workbook,$filename,$format);
1739: }
1740:
1741: ###############################################################
1742: ###############################################################
1743:
1744: =pod
1745:
1.648 raeburn 1746: =item * &create_text_file()
1.113 bowersj2 1747:
1.542 raeburn 1748: Create a file to write to and eventually make available to the user.
1.256 matthew 1749: If file creation fails, outputs an error message on the request object and
1750: return undefs.
1.113 bowersj2 1751:
1.256 matthew 1752: Inputs: Apache request object, and file suffix
1.113 bowersj2 1753:
1.256 matthew 1754: Returns (undef) on failure,
1755: Filehandle and filename on success.
1.113 bowersj2 1756:
1757: =cut
1758:
1.256 matthew 1759: ###############################################################
1760: ###############################################################
1761: sub create_text_file {
1762: my ($r,$suffix) = @_;
1763: if (! defined($suffix)) { $suffix = 'txt'; };
1764: my $fh;
1765: my $filename = '/prtspool/'.
1.258 albertel 1766: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1767: time.'_'.rand(1000000000).'.'.$suffix;
1768: $fh = Apache::File->new('>/home/httpd'.$filename);
1769: if (! defined($fh)) {
1770: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1771: $r->print(
1772: '<p class="LC_error">'
1773: .&mt('Problems occurred in creating the output file.')
1774: .' '.&mt('This error has been logged.')
1775: .' '.&mt('Please alert your LON-CAPA administrator.')
1776: .'</p>'
1777: );
1.113 bowersj2 1778: }
1.256 matthew 1779: return ($fh,$filename)
1.113 bowersj2 1780: }
1781:
1782:
1.256 matthew 1783: =pod
1.113 bowersj2 1784:
1785: =back
1786:
1787: =cut
1.37 matthew 1788:
1789: ###############################################################
1.33 matthew 1790: ## Home server <option> list generating code ##
1791: ###############################################################
1.35 matthew 1792:
1.169 www 1793: # ------------------------------------------
1794:
1795: sub domain_select {
1796: my ($name,$value,$multiple)=@_;
1797: my %domains=map {
1.514 albertel 1798: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1799: } &Apache::lonnet::all_domains();
1.169 www 1800: if ($multiple) {
1801: $domains{''}=&mt('Any domain');
1.550 albertel 1802: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1803: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1804: } else {
1.550 albertel 1805: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.948.2.7 raeburn 1806: return &select_form($name,$value,\%domains);
1.169 www 1807: }
1808: }
1809:
1.282 albertel 1810: #-------------------------------------------
1811:
1812: =pod
1813:
1.519 raeburn 1814: =head1 Routines for form select boxes
1815:
1816: =over 4
1817:
1.648 raeburn 1818: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1819:
1820: Returns a string containing a <select> element int multiple mode
1821:
1822:
1823: Args:
1824: $name - name of the <select> element
1.506 raeburn 1825: $value - scalar or array ref of values that should already be selected
1.282 albertel 1826: $size - number of rows long the select element is
1.283 albertel 1827: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1828: (shown text should already have been &mt())
1.506 raeburn 1829: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1830:
1.282 albertel 1831: =cut
1832:
1833: #-------------------------------------------
1.169 www 1834: sub multiple_select_form {
1.284 albertel 1835: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1836: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1837: my $output='';
1.191 matthew 1838: if (! defined($size)) {
1839: $size = 4;
1.283 albertel 1840: if (scalar(keys(%$hash))<4) {
1841: $size = scalar(keys(%$hash));
1.191 matthew 1842: }
1843: }
1.734 bisitz 1844: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1845: my @order;
1.506 raeburn 1846: if (ref($order) eq 'ARRAY') {
1847: @order = @{$order};
1848: } else {
1849: @order = sort(keys(%$hash));
1.501 banghart 1850: }
1851: if (exists($$hash{'select_form_order'})) {
1852: @order = @{$$hash{'select_form_order'}};
1853: }
1854:
1.284 albertel 1855: foreach my $key (@order) {
1.356 albertel 1856: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1857: $output.='selected="selected" ' if ($selected{$key});
1858: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1859: }
1860: $output.="</select>\n";
1861: return $output;
1862: }
1863:
1.88 www 1864: #-------------------------------------------
1865:
1866: =pod
1867:
1.948.2.7 raeburn 1868: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1869:
1870: Returns a string containing a <select name='$name' size='1'> form to
1.948.2.7 raeburn 1871: allow a user to select options from a ref to a hash containing:
1872: option_name => displayed text. An optional $onchange can include
1873: a javascript onchange item, e.g., onchange="this.form.submit();"
1874:
1.88 www 1875: See lonrights.pm for an example invocation and use.
1876:
1877: =cut
1878:
1879: #-------------------------------------------
1880: sub select_form {
1.948.2.7 raeburn 1881: my ($def,$name,$hashref,$onchange) = @_;
1882: return unless (ref($hashref) eq 'HASH');
1883: if ($onchange) {
1884: $onchange = ' onchange="'.$onchange.'"';
1885: }
1886: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1887: my @keys;
1.948.2.7 raeburn 1888: if (exists($hashref->{'select_form_order'})) {
1889: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1890: } else {
1.948.2.7 raeburn 1891: @keys=sort(keys(%{$hashref}));
1.128 albertel 1892: }
1.356 albertel 1893: foreach my $key (@keys) {
1894: $selectform.=
1895: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1896: ($key eq $def ? 'selected="selected" ' : '').
1.948.2.7 raeburn 1897: ">".$hashref->{$key}."</option>\n";
1.88 www 1898: }
1899: $selectform.="</select>";
1900: return $selectform;
1901: }
1902:
1.475 www 1903: # For display filters
1904:
1905: sub display_filter {
1906: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1907: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1908: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1909: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1910: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1911: '</label></span> <span class="LC_nobreak">'.
1.475 www 1912: &mt('Filter [_1]',
1.477 www 1913: &select_form($env{'form.displayfilter'},
1914: 'displayfilter',
1.948.2.7 raeburn 1915: {'currentfolder' => 'Current folder/page',
1.477 www 1916: 'containing' => 'Containing phrase',
1.948.2.7 raeburn 1917: 'none' => 'None'})).
1.714 bisitz 1918: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1919: }
1920:
1.167 www 1921: sub gradeleveldescription {
1922: my $gradelevel=shift;
1923: my %gradelevels=(0 => 'Not specified',
1924: 1 => 'Grade 1',
1925: 2 => 'Grade 2',
1926: 3 => 'Grade 3',
1927: 4 => 'Grade 4',
1928: 5 => 'Grade 5',
1929: 6 => 'Grade 6',
1930: 7 => 'Grade 7',
1931: 8 => 'Grade 8',
1932: 9 => 'Grade 9',
1933: 10 => 'Grade 10',
1934: 11 => 'Grade 11',
1935: 12 => 'Grade 12',
1936: 13 => 'Grade 13',
1937: 14 => '100 Level',
1938: 15 => '200 Level',
1939: 16 => '300 Level',
1940: 17 => '400 Level',
1941: 18 => 'Graduate Level');
1942: return &mt($gradelevels{$gradelevel});
1943: }
1944:
1.163 www 1945: sub select_level_form {
1946: my ($deflevel,$name)=@_;
1947: unless ($deflevel) { $deflevel=0; }
1.167 www 1948: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1949: for (my $i=0; $i<=18; $i++) {
1950: $selectform.="<option value=\"$i\" ".
1.253 albertel 1951: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1952: ">".&gradeleveldescription($i)."</option>\n";
1953: }
1954: $selectform.="</select>";
1955: return $selectform;
1.163 www 1956: }
1.167 www 1957:
1.35 matthew 1958: #-------------------------------------------
1959:
1.45 matthew 1960: =pod
1961:
1.910 raeburn 1962: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1963:
1964: Returns a string containing a <select name='$name' size='1'> form to
1965: allow a user to select the domain to preform an operation in.
1966: See loncreateuser.pm for an example invocation and use.
1967:
1.90 www 1968: If the $includeempty flag is set, it also includes an empty choice ("no domain
1969: selected");
1970:
1.743 raeburn 1971: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1972:
1.910 raeburn 1973: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
1974:
1975: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 1976:
1.35 matthew 1977: =cut
1978:
1979: #-------------------------------------------
1.34 matthew 1980: sub select_dom_form {
1.910 raeburn 1981: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 1982: if ($onchange) {
1.874 raeburn 1983: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1984: }
1.910 raeburn 1985: my @domains;
1986: if (ref($incdoms) eq 'ARRAY') {
1987: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
1988: } else {
1989: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1990: }
1.90 www 1991: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1992: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1993: foreach my $dom (@domains) {
1994: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1995: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1996: if ($showdomdesc) {
1997: if ($dom ne '') {
1998: my $domdesc = &Apache::lonnet::domain($dom,'description');
1999: if ($domdesc ne '') {
2000: $selectdomain .= ' ('.$domdesc.')';
2001: }
2002: }
2003: }
2004: $selectdomain .= "</option>\n";
1.34 matthew 2005: }
2006: $selectdomain.="</select>";
2007: return $selectdomain;
2008: }
2009:
1.35 matthew 2010: #-------------------------------------------
2011:
1.45 matthew 2012: =pod
2013:
1.648 raeburn 2014: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2015:
1.586 raeburn 2016: input: 4 arguments (two required, two optional) -
2017: $domain - domain of new user
2018: $name - name of form element
2019: $default - Value of 'default' causes a default item to be first
2020: option, and selected by default.
2021: $hide - Value of 'hide' causes hiding of the name of the server,
2022: if 1 server found, or default, if 0 found.
1.594 raeburn 2023: output: returns 2 items:
1.586 raeburn 2024: (a) form element which contains either:
2025: (i) <select name="$name">
2026: <option value="$hostid1">$hostid $servers{$hostid}</option>
2027: <option value="$hostid2">$hostid $servers{$hostid}</option>
2028: </select>
2029: form item if there are multiple library servers in $domain, or
2030: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2031: if there is only one library server in $domain.
2032:
2033: (b) number of library servers found.
2034:
2035: See loncreateuser.pm for example of use.
1.35 matthew 2036:
2037: =cut
2038:
2039: #-------------------------------------------
1.586 raeburn 2040: sub home_server_form_item {
2041: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2042: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2043: my $result;
2044: my $numlib = keys(%servers);
2045: if ($numlib > 1) {
2046: $result .= '<select name="'.$name.'" />'."\n";
2047: if ($default) {
1.804 bisitz 2048: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2049: '</option>'."\n";
2050: }
2051: foreach my $hostid (sort(keys(%servers))) {
2052: $result.= '<option value="'.$hostid.'">'.
2053: $hostid.' '.$servers{$hostid}."</option>\n";
2054: }
2055: $result .= '</select>'."\n";
2056: } elsif ($numlib == 1) {
2057: my $hostid;
2058: foreach my $item (keys(%servers)) {
2059: $hostid = $item;
2060: }
2061: $result .= '<input type="hidden" name="'.$name.'" value="'.
2062: $hostid.'" />';
2063: if (!$hide) {
2064: $result .= $hostid.' '.$servers{$hostid};
2065: }
2066: $result .= "\n";
2067: } elsif ($default) {
2068: $result .= '<input type="hidden" name="'.$name.
2069: '" value="default" />';
2070: if (!$hide) {
2071: $result .= &mt('default');
2072: }
2073: $result .= "\n";
1.33 matthew 2074: }
1.586 raeburn 2075: return ($result,$numlib);
1.33 matthew 2076: }
1.112 bowersj2 2077:
2078: =pod
2079:
1.534 albertel 2080: =back
2081:
1.112 bowersj2 2082: =cut
1.87 matthew 2083:
2084: ###############################################################
1.112 bowersj2 2085: ## Decoding User Agent ##
1.87 matthew 2086: ###############################################################
2087:
2088: =pod
2089:
1.112 bowersj2 2090: =head1 Decoding the User Agent
2091:
2092: =over 4
2093:
2094: =item * &decode_user_agent()
1.87 matthew 2095:
2096: Inputs: $r
2097:
2098: Outputs:
2099:
2100: =over 4
2101:
1.112 bowersj2 2102: =item * $httpbrowser
1.87 matthew 2103:
1.112 bowersj2 2104: =item * $clientbrowser
1.87 matthew 2105:
1.112 bowersj2 2106: =item * $clientversion
1.87 matthew 2107:
1.112 bowersj2 2108: =item * $clientmathml
1.87 matthew 2109:
1.112 bowersj2 2110: =item * $clientunicode
1.87 matthew 2111:
1.112 bowersj2 2112: =item * $clientos
1.87 matthew 2113:
2114: =back
2115:
1.157 matthew 2116: =back
2117:
1.87 matthew 2118: =cut
2119:
2120: ###############################################################
2121: ###############################################################
2122: sub decode_user_agent {
1.247 albertel 2123: my ($r)=@_;
1.87 matthew 2124: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2125: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2126: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2127: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2128: my $clientbrowser='unknown';
2129: my $clientversion='0';
2130: my $clientmathml='';
2131: my $clientunicode='0';
2132: for (my $i=0;$i<=$#browsertype;$i++) {
2133: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2134: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2135: $clientbrowser=$bname;
2136: $httpbrowser=~/$vreg/i;
2137: $clientversion=$1;
2138: $clientmathml=($clientversion>=$minv);
2139: $clientunicode=($clientversion>=$univ);
2140: }
2141: }
2142: my $clientos='unknown';
2143: if (($httpbrowser=~/linux/i) ||
2144: ($httpbrowser=~/unix/i) ||
2145: ($httpbrowser=~/ux/i) ||
2146: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2147: if (($httpbrowser=~/vax/i) ||
2148: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2149: if ($httpbrowser=~/next/i) { $clientos='next'; }
2150: if (($httpbrowser=~/mac/i) ||
2151: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2152: if ($httpbrowser=~/win/i) { $clientos='win'; }
2153: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2154: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2155: $clientunicode,$clientos,);
2156: }
2157:
1.32 matthew 2158: ###############################################################
2159: ## Authentication changing form generation subroutines ##
2160: ###############################################################
2161: ##
2162: ## All of the authform_xxxxxxx subroutines take their inputs in a
2163: ## hash, and have reasonable default values.
2164: ##
2165: ## formname = the name given in the <form> tag.
1.35 matthew 2166: #-------------------------------------------
2167:
1.45 matthew 2168: =pod
2169:
1.112 bowersj2 2170: =head1 Authentication Routines
2171:
2172: =over 4
2173:
1.648 raeburn 2174: =item * &authform_xxxxxx()
1.35 matthew 2175:
2176: The authform_xxxxxx subroutines provide javascript and html forms which
2177: handle some of the conveniences required for authentication forms.
2178: This is not an optimal method, but it works.
2179:
2180: =over 4
2181:
1.112 bowersj2 2182: =item * authform_header
1.35 matthew 2183:
1.112 bowersj2 2184: =item * authform_authorwarning
1.35 matthew 2185:
1.112 bowersj2 2186: =item * authform_nochange
1.35 matthew 2187:
1.112 bowersj2 2188: =item * authform_kerberos
1.35 matthew 2189:
1.112 bowersj2 2190: =item * authform_internal
1.35 matthew 2191:
1.112 bowersj2 2192: =item * authform_filesystem
1.35 matthew 2193:
2194: =back
2195:
1.648 raeburn 2196: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2197:
1.35 matthew 2198: =cut
2199:
2200: #-------------------------------------------
1.32 matthew 2201: sub authform_header{
2202: my %in = (
2203: formname => 'cu',
1.80 albertel 2204: kerb_def_dom => '',
1.32 matthew 2205: @_,
2206: );
2207: $in{'formname'} = 'document.' . $in{'formname'};
2208: my $result='';
1.80 albertel 2209:
2210: #---------------------------------------------- Code for upper case translation
2211: my $Javascript_toUpperCase;
2212: unless ($in{kerb_def_dom}) {
2213: $Javascript_toUpperCase =<<"END";
2214: switch (choice) {
2215: case 'krb': currentform.elements[choicearg].value =
2216: currentform.elements[choicearg].value.toUpperCase();
2217: break;
2218: default:
2219: }
2220: END
2221: } else {
2222: $Javascript_toUpperCase = "";
2223: }
2224:
1.165 raeburn 2225: my $radioval = "'nochange'";
1.591 raeburn 2226: if (defined($in{'curr_authtype'})) {
2227: if ($in{'curr_authtype'} ne '') {
2228: $radioval = "'".$in{'curr_authtype'}."arg'";
2229: }
1.174 matthew 2230: }
1.165 raeburn 2231: my $argfield = 'null';
1.591 raeburn 2232: if (defined($in{'mode'})) {
1.165 raeburn 2233: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2234: if (defined($in{'curr_autharg'})) {
2235: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2236: $argfield = "'$in{'curr_autharg'}'";
2237: }
2238: }
2239: }
2240: }
2241:
1.32 matthew 2242: $result.=<<"END";
2243: var current = new Object();
1.165 raeburn 2244: current.radiovalue = $radioval;
2245: current.argfield = $argfield;
1.32 matthew 2246:
2247: function changed_radio(choice,currentform) {
2248: var choicearg = choice + 'arg';
2249: // If a radio button in changed, we need to change the argfield
2250: if (current.radiovalue != choice) {
2251: current.radiovalue = choice;
2252: if (current.argfield != null) {
2253: currentform.elements[current.argfield].value = '';
2254: }
2255: if (choice == 'nochange') {
2256: current.argfield = null;
2257: } else {
2258: current.argfield = choicearg;
2259: switch(choice) {
2260: case 'krb':
2261: currentform.elements[current.argfield].value =
2262: "$in{'kerb_def_dom'}";
2263: break;
2264: default:
2265: break;
2266: }
2267: }
2268: }
2269: return;
2270: }
1.22 www 2271:
1.32 matthew 2272: function changed_text(choice,currentform) {
2273: var choicearg = choice + 'arg';
2274: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2275: $Javascript_toUpperCase
1.32 matthew 2276: // clear old field
2277: if ((current.argfield != choicearg) && (current.argfield != null)) {
2278: currentform.elements[current.argfield].value = '';
2279: }
2280: current.argfield = choicearg;
2281: }
2282: set_auth_radio_buttons(choice,currentform);
2283: return;
1.20 www 2284: }
1.32 matthew 2285:
2286: function set_auth_radio_buttons(newvalue,currentform) {
1.948.2.13 raeburn 2287: var numauthchoices = currentform.login.length;
2288: if (typeof numauthchoices == "undefined") {
2289: return;
2290: }
1.32 matthew 2291: var i=0;
1.948.2.17 raeburn 2292: while (i < numauthchoices) {
1.32 matthew 2293: if (currentform.login[i].value == newvalue) { break; }
2294: i++;
2295: }
1.948.2.13 raeburn 2296: if (i == numauthchoices) {
1.32 matthew 2297: return;
2298: }
2299: current.radiovalue = newvalue;
2300: currentform.login[i].checked = true;
2301: return;
2302: }
2303: END
2304: return $result;
2305: }
2306:
2307: sub authform_authorwarning{
2308: my $result='';
1.144 matthew 2309: $result='<i>'.
2310: &mt('As a general rule, only authors or co-authors should be '.
2311: 'filesystem authenticated '.
2312: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2313: return $result;
2314: }
2315:
2316: sub authform_nochange{
2317: my %in = (
2318: formname => 'document.cu',
2319: kerb_def_dom => 'MSU.EDU',
2320: @_,
2321: );
1.586 raeburn 2322: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2323: my $result;
2324: if (keys(%can_assign) == 0) {
2325: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2326: } else {
2327: $result = '<label>'.&mt('[_1] Do not change login data',
2328: '<input type="radio" name="login" value="nochange" '.
2329: 'checked="checked" onclick="'.
1.281 albertel 2330: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2331: '</label>';
1.586 raeburn 2332: }
1.32 matthew 2333: return $result;
2334: }
2335:
1.591 raeburn 2336: sub authform_kerberos {
1.32 matthew 2337: my %in = (
2338: formname => 'document.cu',
2339: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2340: kerb_def_auth => 'krb4',
1.32 matthew 2341: @_,
2342: );
1.586 raeburn 2343: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2344: $autharg,$jscall);
2345: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2346: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2347: $check5 = ' checked="checked"';
1.80 albertel 2348: } else {
1.772 bisitz 2349: $check4 = ' checked="checked"';
1.80 albertel 2350: }
1.165 raeburn 2351: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2352: if (defined($in{'curr_authtype'})) {
2353: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2354: $krbcheck = ' checked="checked"';
1.623 raeburn 2355: if (defined($in{'mode'})) {
2356: if ($in{'mode'} eq 'modifyuser') {
2357: $krbcheck = '';
2358: }
2359: }
1.591 raeburn 2360: if (defined($in{'curr_kerb_ver'})) {
2361: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2362: $check5 = ' checked="checked"';
1.591 raeburn 2363: $check4 = '';
2364: } else {
1.772 bisitz 2365: $check4 = ' checked="checked"';
1.591 raeburn 2366: $check5 = '';
2367: }
1.586 raeburn 2368: }
1.591 raeburn 2369: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2370: $krbarg = $in{'curr_autharg'};
2371: }
1.586 raeburn 2372: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2373: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2374: $result =
2375: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2376: $in{'curr_autharg'},$krbver);
2377: } else {
2378: $result =
2379: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2380: }
2381: return $result;
2382: }
2383: }
2384: } else {
2385: if ($authnum == 1) {
1.784 bisitz 2386: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2387: }
2388: }
1.586 raeburn 2389: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2390: return;
1.587 raeburn 2391: } elsif ($authtype eq '') {
1.591 raeburn 2392: if (defined($in{'mode'})) {
1.587 raeburn 2393: if ($in{'mode'} eq 'modifycourse') {
2394: if ($authnum == 1) {
1.784 bisitz 2395: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2396: }
2397: }
2398: }
1.586 raeburn 2399: }
2400: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2401: if ($authtype eq '') {
2402: $authtype = '<input type="radio" name="login" value="krb" '.
2403: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2404: $krbcheck.' />';
2405: }
2406: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2407: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2408: $in{'curr_authtype'} eq 'krb5') ||
2409: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2410: $in{'curr_authtype'} eq 'krb4')) {
2411: $result .= &mt
1.144 matthew 2412: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2413: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2414: '<label>'.$authtype,
1.281 albertel 2415: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2416: 'value="'.$krbarg.'" '.
1.144 matthew 2417: 'onchange="'.$jscall.'" />',
1.281 albertel 2418: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2419: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2420: '</label>');
1.586 raeburn 2421: } elsif ($can_assign{'krb4'}) {
2422: $result .= &mt
2423: ('[_1] Kerberos authenticated with domain [_2] '.
2424: '[_3] Version 4 [_4]',
2425: '<label>'.$authtype,
2426: '</label><input type="text" size="10" name="krbarg" '.
2427: 'value="'.$krbarg.'" '.
2428: 'onchange="'.$jscall.'" />',
2429: '<label><input type="hidden" name="krbver" value="4" />',
2430: '</label>');
2431: } elsif ($can_assign{'krb5'}) {
2432: $result .= &mt
2433: ('[_1] Kerberos authenticated with domain [_2] '.
2434: '[_3] Version 5 [_4]',
2435: '<label>'.$authtype,
2436: '</label><input type="text" size="10" name="krbarg" '.
2437: 'value="'.$krbarg.'" '.
2438: 'onchange="'.$jscall.'" />',
2439: '<label><input type="hidden" name="krbver" value="5" />',
2440: '</label>');
2441: }
1.32 matthew 2442: return $result;
2443: }
2444:
2445: sub authform_internal{
1.586 raeburn 2446: my %in = (
1.32 matthew 2447: formname => 'document.cu',
2448: kerb_def_dom => 'MSU.EDU',
2449: @_,
2450: );
1.586 raeburn 2451: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2452: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2453: if (defined($in{'curr_authtype'})) {
2454: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2455: if ($can_assign{'int'}) {
1.772 bisitz 2456: $intcheck = 'checked="checked" ';
1.623 raeburn 2457: if (defined($in{'mode'})) {
2458: if ($in{'mode'} eq 'modifyuser') {
2459: $intcheck = '';
2460: }
2461: }
1.591 raeburn 2462: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2463: $intarg = $in{'curr_autharg'};
2464: }
2465: } else {
2466: $result = &mt('Currently internally authenticated.');
2467: return $result;
1.165 raeburn 2468: }
2469: }
1.586 raeburn 2470: } else {
2471: if ($authnum == 1) {
1.784 bisitz 2472: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2473: }
2474: }
2475: if (!$can_assign{'int'}) {
2476: return;
1.587 raeburn 2477: } elsif ($authtype eq '') {
1.591 raeburn 2478: if (defined($in{'mode'})) {
1.587 raeburn 2479: if ($in{'mode'} eq 'modifycourse') {
2480: if ($authnum == 1) {
1.784 bisitz 2481: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2482: }
2483: }
2484: }
1.165 raeburn 2485: }
1.586 raeburn 2486: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2487: if ($authtype eq '') {
2488: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2489: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2490: }
1.605 bisitz 2491: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2492: $intarg.'" onchange="'.$jscall.'" />';
2493: $result = &mt
1.144 matthew 2494: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2495: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2496: $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 2497: return $result;
2498: }
2499:
2500: sub authform_local{
2501: my %in = (
2502: formname => 'document.cu',
2503: kerb_def_dom => 'MSU.EDU',
2504: @_,
2505: );
1.586 raeburn 2506: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2507: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2508: if (defined($in{'curr_authtype'})) {
2509: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2510: if ($can_assign{'loc'}) {
1.772 bisitz 2511: $loccheck = 'checked="checked" ';
1.623 raeburn 2512: if (defined($in{'mode'})) {
2513: if ($in{'mode'} eq 'modifyuser') {
2514: $loccheck = '';
2515: }
2516: }
1.591 raeburn 2517: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2518: $locarg = $in{'curr_autharg'};
2519: }
2520: } else {
2521: $result = &mt('Currently using local (institutional) authentication.');
2522: return $result;
1.165 raeburn 2523: }
2524: }
1.586 raeburn 2525: } else {
2526: if ($authnum == 1) {
1.784 bisitz 2527: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2528: }
2529: }
2530: if (!$can_assign{'loc'}) {
2531: return;
1.587 raeburn 2532: } elsif ($authtype eq '') {
1.591 raeburn 2533: if (defined($in{'mode'})) {
1.587 raeburn 2534: if ($in{'mode'} eq 'modifycourse') {
2535: if ($authnum == 1) {
1.784 bisitz 2536: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2537: }
2538: }
2539: }
1.165 raeburn 2540: }
1.586 raeburn 2541: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2542: if ($authtype eq '') {
2543: $authtype = '<input type="radio" name="login" value="loc" '.
2544: $loccheck.' onchange="'.$jscall.'" onclick="'.
2545: $jscall.'" />';
2546: }
2547: $autharg = '<input type="text" size="10" name="locarg" value="'.
2548: $locarg.'" onchange="'.$jscall.'" />';
2549: $result = &mt('[_1] Local Authentication with argument [_2]',
2550: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2551: return $result;
2552: }
2553:
2554: sub authform_filesystem{
2555: my %in = (
2556: formname => 'document.cu',
2557: kerb_def_dom => 'MSU.EDU',
2558: @_,
2559: );
1.586 raeburn 2560: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2561: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2562: if (defined($in{'curr_authtype'})) {
2563: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2564: if ($can_assign{'fsys'}) {
1.772 bisitz 2565: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2566: if (defined($in{'mode'})) {
2567: if ($in{'mode'} eq 'modifyuser') {
2568: $fsyscheck = '';
2569: }
2570: }
1.586 raeburn 2571: } else {
2572: $result = &mt('Currently Filesystem Authenticated.');
2573: return $result;
2574: }
2575: }
2576: } else {
2577: if ($authnum == 1) {
1.784 bisitz 2578: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2579: }
2580: }
2581: if (!$can_assign{'fsys'}) {
2582: return;
1.587 raeburn 2583: } elsif ($authtype eq '') {
1.591 raeburn 2584: if (defined($in{'mode'})) {
1.587 raeburn 2585: if ($in{'mode'} eq 'modifycourse') {
2586: if ($authnum == 1) {
1.784 bisitz 2587: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2588: }
2589: }
2590: }
1.586 raeburn 2591: }
2592: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2593: if ($authtype eq '') {
2594: $authtype = '<input type="radio" name="login" value="fsys" '.
2595: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2596: $jscall.'" />';
2597: }
2598: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2599: ' onchange="'.$jscall.'" />';
2600: $result = &mt
1.144 matthew 2601: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2602: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2603: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2604: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2605: 'onchange="'.$jscall.'" />');
1.32 matthew 2606: return $result;
2607: }
2608:
1.586 raeburn 2609: sub get_assignable_auth {
2610: my ($dom) = @_;
2611: if ($dom eq '') {
2612: $dom = $env{'request.role.domain'};
2613: }
2614: my %can_assign = (
2615: krb4 => 1,
2616: krb5 => 1,
2617: int => 1,
2618: loc => 1,
2619: );
2620: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2621: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2622: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2623: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2624: my $context;
2625: if ($env{'request.role'} =~ /^au/) {
2626: $context = 'author';
2627: } elsif ($env{'request.role'} =~ /^dc/) {
2628: $context = 'domain';
2629: } elsif ($env{'request.course.id'}) {
2630: $context = 'course';
2631: }
2632: if ($context) {
2633: if (ref($authhash->{$context}) eq 'HASH') {
2634: %can_assign = %{$authhash->{$context}};
2635: }
2636: }
2637: }
2638: }
2639: my $authnum = 0;
2640: foreach my $key (keys(%can_assign)) {
2641: if ($can_assign{$key}) {
2642: $authnum ++;
2643: }
2644: }
2645: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2646: $authnum --;
2647: }
2648: return ($authnum,%can_assign);
2649: }
2650:
1.80 albertel 2651: ###############################################################
2652: ## Get Kerberos Defaults for Domain ##
2653: ###############################################################
2654: ##
2655: ## Returns default kerberos version and an associated argument
2656: ## as listed in file domain.tab. If not listed, provides
2657: ## appropriate default domain and kerberos version.
2658: ##
2659: #-------------------------------------------
2660:
2661: =pod
2662:
1.648 raeburn 2663: =item * &get_kerberos_defaults()
1.80 albertel 2664:
2665: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2666: version and domain. If not found, it defaults to version 4 and the
2667: domain of the server.
1.80 albertel 2668:
1.648 raeburn 2669: =over 4
2670:
1.80 albertel 2671: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2672:
1.648 raeburn 2673: =back
2674:
2675: =back
2676:
1.80 albertel 2677: =cut
2678:
2679: #-------------------------------------------
2680: sub get_kerberos_defaults {
2681: my $domain=shift;
1.641 raeburn 2682: my ($krbdef,$krbdefdom);
2683: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2684: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2685: $krbdef = $domdefaults{'auth_def'};
2686: $krbdefdom = $domdefaults{'auth_arg_def'};
2687: } else {
1.80 albertel 2688: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2689: my $krbdefdom=$1;
2690: $krbdefdom=~tr/a-z/A-Z/;
2691: $krbdef = "krb4";
2692: }
2693: return ($krbdef,$krbdefdom);
2694: }
1.112 bowersj2 2695:
1.32 matthew 2696:
1.46 matthew 2697: ###############################################################
2698: ## Thesaurus Functions ##
2699: ###############################################################
1.20 www 2700:
1.46 matthew 2701: =pod
1.20 www 2702:
1.112 bowersj2 2703: =head1 Thesaurus Functions
2704:
2705: =over 4
2706:
1.648 raeburn 2707: =item * &initialize_keywords()
1.46 matthew 2708:
2709: Initializes the package variable %Keywords if it is empty. Uses the
2710: package variable $thesaurus_db_file.
2711:
2712: =cut
2713:
2714: ###################################################
2715:
2716: sub initialize_keywords {
2717: return 1 if (scalar keys(%Keywords));
2718: # If we are here, %Keywords is empty, so fill it up
2719: # Make sure the file we need exists...
2720: if (! -e $thesaurus_db_file) {
2721: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2722: " failed because it does not exist");
2723: return 0;
2724: }
2725: # Set up the hash as a database
2726: my %thesaurus_db;
2727: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2728: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2729: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2730: $thesaurus_db_file);
2731: return 0;
2732: }
2733: # Get the average number of appearances of a word.
2734: my $avecount = $thesaurus_db{'average.count'};
2735: # Put keywords (those that appear > average) into %Keywords
2736: while (my ($word,$data)=each (%thesaurus_db)) {
2737: my ($count,undef) = split /:/,$data;
2738: $Keywords{$word}++ if ($count > $avecount);
2739: }
2740: untie %thesaurus_db;
2741: # Remove special values from %Keywords.
1.356 albertel 2742: foreach my $value ('total.count','average.count') {
2743: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2744: }
1.46 matthew 2745: return 1;
2746: }
2747:
2748: ###################################################
2749:
2750: =pod
2751:
1.648 raeburn 2752: =item * &keyword($word)
1.46 matthew 2753:
2754: Returns true if $word is a keyword. A keyword is a word that appears more
2755: than the average number of times in the thesaurus database. Calls
2756: &initialize_keywords
2757:
2758: =cut
2759:
2760: ###################################################
1.20 www 2761:
2762: sub keyword {
1.46 matthew 2763: return if (!&initialize_keywords());
2764: my $word=lc(shift());
2765: $word=~s/\W//g;
2766: return exists($Keywords{$word});
1.20 www 2767: }
1.46 matthew 2768:
2769: ###############################################################
2770:
2771: =pod
1.20 www 2772:
1.648 raeburn 2773: =item * &get_related_words()
1.46 matthew 2774:
1.160 matthew 2775: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2776: an array of words. If the keyword is not in the thesaurus, an empty array
2777: will be returned. The order of the words returned is determined by the
2778: database which holds them.
2779:
2780: Uses global $thesaurus_db_file.
2781:
2782: =cut
2783:
2784: ###############################################################
2785: sub get_related_words {
2786: my $keyword = shift;
2787: my %thesaurus_db;
2788: if (! -e $thesaurus_db_file) {
2789: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2790: "failed because the file does not exist");
2791: return ();
2792: }
2793: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2794: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2795: return ();
2796: }
2797: my @Words=();
1.429 www 2798: my $count=0;
1.46 matthew 2799: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2800: # The first element is the number of times
2801: # the word appears. We do not need it now.
1.429 www 2802: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2803: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2804: my $threshold=$mostfrequentcount/10;
2805: foreach my $possibleword (@RelatedWords) {
2806: my ($word,$wordcount)=split(/\,/,$possibleword);
2807: if ($wordcount>$threshold) {
2808: push(@Words,$word);
2809: $count++;
2810: if ($count>10) { last; }
2811: }
1.20 www 2812: }
2813: }
1.46 matthew 2814: untie %thesaurus_db;
2815: return @Words;
1.14 harris41 2816: }
1.46 matthew 2817:
1.112 bowersj2 2818: =pod
2819:
2820: =back
2821:
2822: =cut
1.61 www 2823:
2824: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2825: =pod
2826:
1.112 bowersj2 2827: =head1 User Name Functions
2828:
2829: =over 4
2830:
1.648 raeburn 2831: =item * &plainname($uname,$udom,$first)
1.81 albertel 2832:
1.112 bowersj2 2833: Takes a users logon name and returns it as a string in
1.226 albertel 2834: "first middle last generation" form
2835: if $first is set to 'lastname' then it returns it as
2836: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2837:
2838: =cut
1.61 www 2839:
1.295 www 2840:
1.81 albertel 2841: ###############################################################
1.61 www 2842: sub plainname {
1.226 albertel 2843: my ($uname,$udom,$first)=@_;
1.537 albertel 2844: return if (!defined($uname) || !defined($udom));
1.295 www 2845: my %names=&getnames($uname,$udom);
1.226 albertel 2846: my $name=&Apache::lonnet::format_name($names{'firstname'},
2847: $names{'middlename'},
2848: $names{'lastname'},
2849: $names{'generation'},$first);
2850: $name=~s/^\s+//;
1.62 www 2851: $name=~s/\s+$//;
2852: $name=~s/\s+/ /g;
1.353 albertel 2853: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2854: return $name;
1.61 www 2855: }
1.66 www 2856:
2857: # -------------------------------------------------------------------- Nickname
1.81 albertel 2858: =pod
2859:
1.648 raeburn 2860: =item * &nickname($uname,$udom)
1.81 albertel 2861:
2862: Gets a users name and returns it as a string as
2863:
2864: ""nickname""
1.66 www 2865:
1.81 albertel 2866: if the user has a nickname or
2867:
2868: "first middle last generation"
2869:
2870: if the user does not
2871:
2872: =cut
1.66 www 2873:
2874: sub nickname {
2875: my ($uname,$udom)=@_;
1.537 albertel 2876: return if (!defined($uname) || !defined($udom));
1.295 www 2877: my %names=&getnames($uname,$udom);
1.68 albertel 2878: my $name=$names{'nickname'};
1.66 www 2879: if ($name) {
2880: $name='"'.$name.'"';
2881: } else {
2882: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2883: $names{'lastname'}.' '.$names{'generation'};
2884: $name=~s/\s+$//;
2885: $name=~s/\s+/ /g;
2886: }
2887: return $name;
2888: }
2889:
1.295 www 2890: sub getnames {
2891: my ($uname,$udom)=@_;
1.537 albertel 2892: return if (!defined($uname) || !defined($udom));
1.433 albertel 2893: if ($udom eq 'public' && $uname eq 'public') {
2894: return ('lastname' => &mt('Public'));
2895: }
1.295 www 2896: my $id=$uname.':'.$udom;
2897: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2898: if ($cached) {
2899: return %{$names};
2900: } else {
2901: my %loadnames=&Apache::lonnet::get('environment',
2902: ['firstname','middlename','lastname','generation','nickname'],
2903: $udom,$uname);
2904: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2905: return %loadnames;
2906: }
2907: }
1.61 www 2908:
1.542 raeburn 2909: # -------------------------------------------------------------------- getemails
1.648 raeburn 2910:
1.542 raeburn 2911: =pod
2912:
1.648 raeburn 2913: =item * &getemails($uname,$udom)
1.542 raeburn 2914:
2915: Gets a user's email information and returns it as a hash with keys:
2916: notification, critnotification, permanentemail
2917:
2918: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2919: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2920:
1.648 raeburn 2921:
1.542 raeburn 2922: =cut
2923:
1.648 raeburn 2924:
1.466 albertel 2925: sub getemails {
2926: my ($uname,$udom)=@_;
2927: if ($udom eq 'public' && $uname eq 'public') {
2928: return;
2929: }
1.467 www 2930: if (!$udom) { $udom=$env{'user.domain'}; }
2931: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2932: my $id=$uname.':'.$udom;
2933: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2934: if ($cached) {
2935: return %{$names};
2936: } else {
2937: my %loadnames=&Apache::lonnet::get('environment',
2938: ['notification','critnotification',
2939: 'permanentemail'],
2940: $udom,$uname);
2941: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2942: return %loadnames;
2943: }
2944: }
2945:
1.551 albertel 2946: sub flush_email_cache {
2947: my ($uname,$udom)=@_;
2948: if (!$udom) { $udom =$env{'user.domain'}; }
2949: if (!$uname) { $uname=$env{'user.name'}; }
2950: return if ($udom eq 'public' && $uname eq 'public');
2951: my $id=$uname.':'.$udom;
2952: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2953: }
2954:
1.728 raeburn 2955: # -------------------------------------------------------------------- getlangs
2956:
2957: =pod
2958:
2959: =item * &getlangs($uname,$udom)
2960:
2961: Gets a user's language preference and returns it as a hash with key:
2962: language.
2963:
2964: =cut
2965:
2966:
2967: sub getlangs {
2968: my ($uname,$udom) = @_;
2969: if (!$udom) { $udom =$env{'user.domain'}; }
2970: if (!$uname) { $uname=$env{'user.name'}; }
2971: my $id=$uname.':'.$udom;
2972: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2973: if ($cached) {
2974: return %{$langs};
2975: } else {
2976: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2977: $udom,$uname);
2978: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2979: return %loadlangs;
2980: }
2981: }
2982:
2983: sub flush_langs_cache {
2984: my ($uname,$udom)=@_;
2985: if (!$udom) { $udom =$env{'user.domain'}; }
2986: if (!$uname) { $uname=$env{'user.name'}; }
2987: return if ($udom eq 'public' && $uname eq 'public');
2988: my $id=$uname.':'.$udom;
2989: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2990: }
2991:
1.61 www 2992: # ------------------------------------------------------------------ Screenname
1.81 albertel 2993:
2994: =pod
2995:
1.648 raeburn 2996: =item * &screenname($uname,$udom)
1.81 albertel 2997:
2998: Gets a users screenname and returns it as a string
2999:
3000: =cut
1.61 www 3001:
3002: sub screenname {
3003: my ($uname,$udom)=@_;
1.258 albertel 3004: if ($uname eq $env{'user.name'} &&
3005: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3006: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3007: return $names{'screenname'};
1.62 www 3008: }
3009:
1.212 albertel 3010:
1.802 bisitz 3011: # ------------------------------------------------------------- Confirm Wrapper
3012: =pod
3013:
3014: =item confirmwrapper
3015:
3016: Wrap messages about completion of operation in box
3017:
3018: =cut
3019:
3020: sub confirmwrapper {
3021: my ($message)=@_;
3022: if ($message) {
3023: return "\n".'<div class="LC_confirm_box">'."\n"
3024: .$message."\n"
3025: .'</div>'."\n";
3026: } else {
3027: return $message;
3028: }
3029: }
3030:
1.62 www 3031: # ------------------------------------------------------------- Message Wrapper
3032:
3033: sub messagewrapper {
1.369 www 3034: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3035: return
1.441 albertel 3036: '<a href="/adm/email?compose=individual&'.
3037: 'recname='.$username.'&recdom='.$domain.
3038: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3039: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3040: }
1.802 bisitz 3041:
1.74 www 3042: # --------------------------------------------------------------- Notes Wrapper
3043:
3044: sub noteswrapper {
3045: my ($link,$un,$do)=@_;
3046: return
1.896 amueller 3047: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3048: }
1.802 bisitz 3049:
1.62 www 3050: # ------------------------------------------------------------- Aboutme Wrapper
3051:
3052: sub aboutmewrapper {
1.166 www 3053: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3054: if (!defined($username) && !defined($domain)) {
3055: return;
3056: }
1.892 amueller 3057: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3058: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3059: }
3060:
3061: # ------------------------------------------------------------ Syllabus Wrapper
3062:
3063: sub syllabuswrapper {
1.707 bisitz 3064: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3065: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3066: }
1.14 harris41 3067:
1.802 bisitz 3068: # -----------------------------------------------------------------------------
3069:
1.208 matthew 3070: sub track_student_link {
1.887 raeburn 3071: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3072: my $link ="/adm/trackstudent?";
1.208 matthew 3073: my $title = 'View recent activity';
3074: if (defined($sname) && $sname !~ /^\s*$/ &&
3075: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3076: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3077: $title .= ' of this student';
1.268 albertel 3078: }
1.208 matthew 3079: if (defined($target) && $target !~ /^\s*$/) {
3080: $target = qq{target="$target"};
3081: } else {
3082: $target = '';
3083: }
1.268 albertel 3084: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3085: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3086: $title = &mt($title);
3087: $linktext = &mt($linktext);
1.448 albertel 3088: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3089: &help_open_topic('View_recent_activity');
1.208 matthew 3090: }
3091:
1.781 raeburn 3092: sub slot_reservations_link {
3093: my ($linktext,$sname,$sdom,$target) = @_;
3094: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3095: my $title = 'View slot reservation history';
3096: if (defined($sname) && $sname !~ /^\s*$/ &&
3097: defined($sdom) && $sdom !~ /^\s*$/) {
3098: $link .= "&uname=$sname&udom=$sdom";
3099: $title .= ' of this student';
3100: }
3101: if (defined($target) && $target !~ /^\s*$/) {
3102: $target = qq{target="$target"};
3103: } else {
3104: $target = '';
3105: }
3106: $title = &mt($title);
3107: $linktext = &mt($linktext);
3108: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3109: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3110:
3111: }
3112:
1.508 www 3113: # ===================================================== Display a student photo
3114:
3115:
1.509 albertel 3116: sub student_image_tag {
1.508 www 3117: my ($domain,$user)=@_;
3118: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3119: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3120: return '<img src="'.$imgsrc.'" align="right" />';
3121: } else {
3122: return '';
3123: }
3124: }
3125:
1.112 bowersj2 3126: =pod
3127:
3128: =back
3129:
3130: =head1 Access .tab File Data
3131:
3132: =over 4
3133:
1.648 raeburn 3134: =item * &languageids()
1.112 bowersj2 3135:
3136: returns list of all language ids
3137:
3138: =cut
3139:
1.14 harris41 3140: sub languageids {
1.16 harris41 3141: return sort(keys(%language));
1.14 harris41 3142: }
3143:
1.112 bowersj2 3144: =pod
3145:
1.648 raeburn 3146: =item * &languagedescription()
1.112 bowersj2 3147:
3148: returns description of a specified language id
3149:
3150: =cut
3151:
1.14 harris41 3152: sub languagedescription {
1.125 www 3153: my $code=shift;
3154: return ($supported_language{$code}?'* ':'').
3155: $language{$code}.
1.126 www 3156: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3157: }
3158:
3159: sub plainlanguagedescription {
3160: my $code=shift;
3161: return $language{$code};
3162: }
3163:
3164: sub supportedlanguagecode {
3165: my $code=shift;
3166: return $supported_language{$code};
1.97 www 3167: }
3168:
1.112 bowersj2 3169: =pod
3170:
1.648 raeburn 3171: =item * ©rightids()
1.112 bowersj2 3172:
3173: returns list of all copyrights
3174:
3175: =cut
3176:
3177: sub copyrightids {
3178: return sort(keys(%cprtag));
3179: }
3180:
3181: =pod
3182:
1.648 raeburn 3183: =item * ©rightdescription()
1.112 bowersj2 3184:
3185: returns description of a specified copyright id
3186:
3187: =cut
3188:
3189: sub copyrightdescription {
1.166 www 3190: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3191: }
1.197 matthew 3192:
3193: =pod
3194:
1.648 raeburn 3195: =item * &source_copyrightids()
1.192 taceyjo1 3196:
3197: returns list of all source copyrights
3198:
3199: =cut
3200:
3201: sub source_copyrightids {
3202: return sort(keys(%scprtag));
3203: }
3204:
3205: =pod
3206:
1.648 raeburn 3207: =item * &source_copyrightdescription()
1.192 taceyjo1 3208:
3209: returns description of a specified source copyright id
3210:
3211: =cut
3212:
3213: sub source_copyrightdescription {
3214: return &mt($scprtag{shift(@_)});
3215: }
1.112 bowersj2 3216:
3217: =pod
3218:
1.648 raeburn 3219: =item * &filecategories()
1.112 bowersj2 3220:
3221: returns list of all file categories
3222:
3223: =cut
3224:
3225: sub filecategories {
3226: return sort(keys(%category_extensions));
3227: }
3228:
3229: =pod
3230:
1.648 raeburn 3231: =item * &filecategorytypes()
1.112 bowersj2 3232:
3233: returns list of file types belonging to a given file
3234: category
3235:
3236: =cut
3237:
3238: sub filecategorytypes {
1.356 albertel 3239: my ($cat) = @_;
3240: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3241: }
3242:
3243: =pod
3244:
1.648 raeburn 3245: =item * &fileembstyle()
1.112 bowersj2 3246:
3247: returns embedding style for a specified file type
3248:
3249: =cut
3250:
3251: sub fileembstyle {
3252: return $fe{lc(shift(@_))};
1.169 www 3253: }
3254:
1.351 www 3255: sub filemimetype {
3256: return $fm{lc(shift(@_))};
3257: }
3258:
1.169 www 3259:
3260: sub filecategoryselect {
3261: my ($name,$value)=@_;
1.189 matthew 3262: return &select_form($value,$name,
1.948.2.7 raeburn 3263: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3264: }
3265:
3266: =pod
3267:
1.648 raeburn 3268: =item * &filedescription()
1.112 bowersj2 3269:
3270: returns description for a specified file type
3271:
3272: =cut
3273:
3274: sub filedescription {
1.188 matthew 3275: my $file_description = $fd{lc(shift())};
3276: $file_description =~ s:([\[\]]):~$1:g;
3277: return &mt($file_description);
1.112 bowersj2 3278: }
3279:
3280: =pod
3281:
1.648 raeburn 3282: =item * &filedescriptionex()
1.112 bowersj2 3283:
3284: returns description for a specified file type with
3285: extra formatting
3286:
3287: =cut
3288:
3289: sub filedescriptionex {
3290: my $ex=shift;
1.188 matthew 3291: my $file_description = $fd{lc($ex)};
3292: $file_description =~ s:([\[\]]):~$1:g;
3293: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3294: }
3295:
3296: # End of .tab access
3297: =pod
3298:
3299: =back
3300:
3301: =cut
3302:
3303: # ------------------------------------------------------------------ File Types
3304: sub fileextensions {
3305: return sort(keys(%fe));
3306: }
3307:
1.97 www 3308: # ----------------------------------------------------------- Display Languages
3309: # returns a hash with all desired display languages
3310: #
3311:
3312: sub display_languages {
3313: my %languages=();
1.695 raeburn 3314: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3315: $languages{$lang}=1;
1.97 www 3316: }
3317: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3318: if ($env{'form.displaylanguage'}) {
1.356 albertel 3319: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3320: $languages{$lang}=1;
1.97 www 3321: }
3322: }
3323: return %languages;
1.14 harris41 3324: }
3325:
1.582 albertel 3326: sub languages {
3327: my ($possible_langs) = @_;
1.695 raeburn 3328: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3329: if (!ref($possible_langs)) {
3330: if( wantarray ) {
3331: return @preferred_langs;
3332: } else {
3333: return $preferred_langs[0];
3334: }
3335: }
3336: my %possibilities = map { $_ => 1 } (@$possible_langs);
3337: my @preferred_possibilities;
3338: foreach my $preferred_lang (@preferred_langs) {
3339: if (exists($possibilities{$preferred_lang})) {
3340: push(@preferred_possibilities, $preferred_lang);
3341: }
3342: }
3343: if( wantarray ) {
3344: return @preferred_possibilities;
3345: }
3346: return $preferred_possibilities[0];
3347: }
3348:
1.742 raeburn 3349: sub user_lang {
3350: my ($touname,$toudom,$fromcid) = @_;
3351: my @userlangs;
3352: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3353: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3354: $env{'course.'.$fromcid.'.languages'}));
3355: } else {
3356: my %langhash = &getlangs($touname,$toudom);
3357: if ($langhash{'languages'} ne '') {
3358: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3359: } else {
3360: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3361: if ($domdefs{'lang_def'} ne '') {
3362: @userlangs = ($domdefs{'lang_def'});
3363: }
3364: }
3365: }
3366: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3367: my $user_lh = Apache::localize->get_handle(@languages);
3368: return $user_lh;
3369: }
3370:
3371:
1.112 bowersj2 3372: ###############################################################
3373: ## Student Answer Attempts ##
3374: ###############################################################
3375:
3376: =pod
3377:
3378: =head1 Alternate Problem Views
3379:
3380: =over 4
3381:
1.648 raeburn 3382: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3383: $getattempt, $regexp, $gradesub)
3384:
3385: Return string with previous attempt on problem. Arguments:
3386:
3387: =over 4
3388:
3389: =item * $symb: Problem, including path
3390:
3391: =item * $username: username of the desired student
3392:
3393: =item * $domain: domain of the desired student
1.14 harris41 3394:
1.112 bowersj2 3395: =item * $course: Course ID
1.14 harris41 3396:
1.112 bowersj2 3397: =item * $getattempt: Leave blank for all attempts, otherwise put
3398: something
1.14 harris41 3399:
1.112 bowersj2 3400: =item * $regexp: if string matches this regexp, the string will be
3401: sent to $gradesub
1.14 harris41 3402:
1.112 bowersj2 3403: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3404:
1.112 bowersj2 3405: =back
1.14 harris41 3406:
1.112 bowersj2 3407: The output string is a table containing all desired attempts, if any.
1.16 harris41 3408:
1.112 bowersj2 3409: =cut
1.1 albertel 3410:
3411: sub get_previous_attempt {
1.43 ng 3412: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3413: my $prevattempts='';
1.43 ng 3414: no strict 'refs';
1.1 albertel 3415: if ($symb) {
1.3 albertel 3416: my (%returnhash)=
3417: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3418: if ($returnhash{'version'}) {
3419: my %lasthash=();
3420: my $version;
3421: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3422: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3423: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3424: }
1.1 albertel 3425: }
1.596 albertel 3426: $prevattempts=&start_data_table().&start_data_table_header_row();
3427: $prevattempts.='<th>'.&mt('History').'</th>';
1.948.2.8 raeburn 3428: my (%typeparts,%lasthidden);
1.945 raeburn 3429: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3430: foreach my $key (sort(keys(%lasthash))) {
3431: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3432: if ($#parts > 0) {
1.31 albertel 3433: my $data=$parts[-1];
1.948.2.15 raeburn 3434: next if ($data eq 'foilorder');
1.31 albertel 3435: pop(@parts);
1.945 raeburn 3436: if ($data eq 'type') {
3437: unless ($showsurv) {
3438: my $id = join(',',@parts);
3439: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.948.2.8 raeburn 3440: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3441: $lasthidden{$ign.'.'.$id} = 1;
3442: }
1.945 raeburn 3443: }
3444: delete($lasthash{$key});
3445: } else {
3446: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3447: }
1.31 albertel 3448: } else {
1.41 ng 3449: if ($#parts == 0) {
3450: $prevattempts.='<th>'.$parts[0].'</th>';
3451: } else {
3452: $prevattempts.='<th>'.$ign.'</th>';
3453: }
1.31 albertel 3454: }
1.16 harris41 3455: }
1.596 albertel 3456: $prevattempts.=&end_data_table_header_row();
1.40 ng 3457: if ($getattempt eq '') {
3458: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3459: my @hidden;
3460: if (%typeparts) {
3461: foreach my $id (keys(%typeparts)) {
3462: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3463: push(@hidden,$id);
3464: }
3465: }
3466: }
3467: $prevattempts.=&start_data_table_row().
3468: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3469: if (@hidden) {
3470: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3471: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3472: my $hide;
3473: foreach my $id (@hidden) {
3474: if ($key =~ /^\Q$id\E/) {
3475: $hide = 1;
3476: last;
3477: }
3478: }
3479: if ($hide) {
3480: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3481: if (($data eq 'award') || ($data eq 'awarddetail')) {
3482: my $value = &format_previous_attempt_value($key,
3483: $returnhash{$version.':'.$key});
3484: $prevattempts.='<td>'.$value.' </td>';
3485: } else {
3486: $prevattempts.='<td> </td>';
3487: }
3488: } else {
3489: if ($key =~ /\./) {
3490: my $value = &format_previous_attempt_value($key,
3491: $returnhash{$version.':'.$key});
3492: $prevattempts.='<td>'.$value.' </td>';
3493: } else {
3494: $prevattempts.='<td> </td>';
3495: }
3496: }
3497: }
3498: } else {
3499: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3500: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3501: my $value = &format_previous_attempt_value($key,
3502: $returnhash{$version.':'.$key});
3503: $prevattempts.='<td>'.$value.' </td>';
3504: }
3505: }
3506: $prevattempts.=&end_data_table_row();
1.40 ng 3507: }
1.1 albertel 3508: }
1.945 raeburn 3509: my @currhidden = keys(%lasthidden);
1.596 albertel 3510: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3511: foreach my $key (sort(keys(%lasthash))) {
1.948.2.15 raeburn 3512: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3513: if (%typeparts) {
3514: my $hidden;
3515: foreach my $id (@currhidden) {
3516: if ($key =~ /^\Q$id\E/) {
3517: $hidden = 1;
3518: last;
3519: }
3520: }
3521: if ($hidden) {
3522: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3523: if (($data eq 'award') || ($data eq 'awarddetail')) {
3524: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3525: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3526: $value = &$gradesub($value);
3527: }
3528: $prevattempts.='<td>'.$value.' </td>';
3529: } else {
3530: $prevattempts.='<td> </td>';
3531: }
3532: } else {
3533: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3534: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3535: $value = &$gradesub($value);
3536: }
3537: $prevattempts.='<td>'.$value.' </td>';
3538: }
3539: } else {
3540: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3541: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3542: $value = &$gradesub($value);
3543: }
3544: $prevattempts.='<td>'.$value.' </td>';
3545: }
1.16 harris41 3546: }
1.596 albertel 3547: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3548: } else {
1.596 albertel 3549: $prevattempts=
3550: &start_data_table().&start_data_table_row().
3551: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3552: &end_data_table_row().&end_data_table();
1.1 albertel 3553: }
3554: } else {
1.596 albertel 3555: $prevattempts=
3556: &start_data_table().&start_data_table_row().
3557: '<td>'.&mt('No data.').'</td>'.
3558: &end_data_table_row().&end_data_table();
1.1 albertel 3559: }
1.10 albertel 3560: }
3561:
1.581 albertel 3562: sub format_previous_attempt_value {
3563: my ($key,$value) = @_;
3564: if ($key =~ /timestamp/) {
3565: $value = &Apache::lonlocal::locallocaltime($value);
3566: } elsif (ref($value) eq 'ARRAY') {
3567: $value = '('.join(', ', @{ $value }).')';
1.948.2.14 raeburn 3568: } elsif ($key =~ /answerstring$/) {
3569: my %answers = &Apache::lonnet::str2hash($value);
3570: my @anskeys = sort(keys(%answers));
3571: if (@anskeys == 1) {
3572: my $answer = $answers{$anskeys[0]};
3573: if ($answer =~ m{\Q\0\E}) {
3574: $answer =~ s{\Q\0\E}{, }g;
3575: }
3576: my $tag_internal_answer_name = 'INTERNAL';
3577: if ($anskeys[0] eq $tag_internal_answer_name) {
3578: $value = $answer;
3579: } else {
3580: $value = $anskeys[0].'='.$answer;
3581: }
3582: } else {
3583: foreach my $ans (@anskeys) {
3584: my $answer = $answers{$ans};
3585: if ($answer =~ m{\Q\0\E}) {
3586: $answer =~ s{\Q\0\E}{, }g;
3587: }
3588: $value .= $ans.'='.$answer.'<br />';;
3589: }
3590: }
1.581 albertel 3591: } else {
3592: $value = &unescape($value);
3593: }
3594: return $value;
3595: }
3596:
3597:
1.107 albertel 3598: sub relative_to_absolute {
3599: my ($url,$output)=@_;
3600: my $parser=HTML::TokeParser->new(\$output);
3601: my $token;
3602: my $thisdir=$url;
3603: my @rlinks=();
3604: while ($token=$parser->get_token) {
3605: if ($token->[0] eq 'S') {
3606: if ($token->[1] eq 'a') {
3607: if ($token->[2]->{'href'}) {
3608: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3609: }
3610: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3611: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3612: } elsif ($token->[1] eq 'base') {
3613: $thisdir=$token->[2]->{'href'};
3614: }
3615: }
3616: }
3617: $thisdir=~s-/[^/]*$--;
1.356 albertel 3618: foreach my $link (@rlinks) {
1.726 raeburn 3619: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3620: ($link=~/^\//) ||
3621: ($link=~/^javascript:/i) ||
3622: ($link=~/^mailto:/i) ||
3623: ($link=~/^\#/)) {
3624: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3625: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3626: }
3627: }
3628: # -------------------------------------------------- Deal with Applet codebases
3629: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3630: return $output;
3631: }
3632:
1.112 bowersj2 3633: =pod
3634:
1.648 raeburn 3635: =item * &get_student_view()
1.112 bowersj2 3636:
3637: show a snapshot of what student was looking at
3638:
3639: =cut
3640:
1.10 albertel 3641: sub get_student_view {
1.186 albertel 3642: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3643: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3644: my (%form);
1.10 albertel 3645: my @elements=('symb','courseid','domain','username');
3646: foreach my $element (@elements) {
1.186 albertel 3647: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3648: }
1.186 albertel 3649: if (defined($moreenv)) {
3650: %form=(%form,%{$moreenv});
3651: }
1.236 albertel 3652: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3653: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3654: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3655: $userview=~s/\<body[^\>]*\>//gi;
3656: $userview=~s/\<\/body\>//gi;
3657: $userview=~s/\<html\>//gi;
3658: $userview=~s/\<\/html\>//gi;
3659: $userview=~s/\<head\>//gi;
3660: $userview=~s/\<\/head\>//gi;
3661: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3662: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3663: if (wantarray) {
3664: return ($userview,$response);
3665: } else {
3666: return $userview;
3667: }
3668: }
3669:
3670: sub get_student_view_with_retries {
3671: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3672:
3673: my $ok = 0; # True if we got a good response.
3674: my $content;
3675: my $response;
3676:
3677: # Try to get the student_view done. within the retries count:
3678:
3679: do {
3680: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3681: $ok = $response->is_success;
3682: if (!$ok) {
3683: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3684: }
3685: $retries--;
3686: } while (!$ok && ($retries > 0));
3687:
3688: if (!$ok) {
3689: $content = ''; # On error return an empty content.
3690: }
1.651 www 3691: if (wantarray) {
3692: return ($content, $response);
3693: } else {
3694: return $content;
3695: }
1.11 albertel 3696: }
3697:
1.112 bowersj2 3698: =pod
3699:
1.648 raeburn 3700: =item * &get_student_answers()
1.112 bowersj2 3701:
3702: show a snapshot of how student was answering problem
3703:
3704: =cut
3705:
1.11 albertel 3706: sub get_student_answers {
1.100 sakharuk 3707: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3708: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3709: my (%moreenv);
1.11 albertel 3710: my @elements=('symb','courseid','domain','username');
3711: foreach my $element (@elements) {
1.186 albertel 3712: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3713: }
1.186 albertel 3714: $moreenv{'grade_target'}='answer';
3715: %moreenv=(%form,%moreenv);
1.497 raeburn 3716: $feedurl = &Apache::lonnet::clutter($feedurl);
3717: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3718: return $userview;
1.1 albertel 3719: }
1.116 albertel 3720:
3721: =pod
3722:
3723: =item * &submlink()
3724:
1.242 albertel 3725: Inputs: $text $uname $udom $symb $target
1.116 albertel 3726:
3727: Returns: A link to grades.pm such as to see the SUBM view of a student
3728:
3729: =cut
3730:
3731: ###############################################
3732: sub submlink {
1.242 albertel 3733: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3734: if (!($uname && $udom)) {
3735: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3736: &Apache::lonnet::whichuser($symb);
1.116 albertel 3737: if (!$symb) { $symb=$cursymb; }
3738: }
1.254 matthew 3739: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3740: $symb=&escape($symb);
1.948.2.4 raeburn 3741: if ($target) { $target=" target=\"$target\""; }
3742: return
3743: '<a href="/adm/grades?command=submission'.
3744: '&symb='.$symb.
3745: '&student='.$uname.
3746: '&userdom='.$udom.'"'.
3747: $target.'>'.$text.'</a>';
1.242 albertel 3748: }
3749: ##############################################
3750:
3751: =pod
3752:
3753: =item * &pgrdlink()
3754:
3755: Inputs: $text $uname $udom $symb $target
3756:
3757: Returns: A link to grades.pm such as to see the PGRD view of a student
3758:
3759: =cut
3760:
3761: ###############################################
3762: sub pgrdlink {
3763: my $link=&submlink(@_);
3764: $link=~s/(&command=submission)/$1&showgrading=yes/;
3765: return $link;
3766: }
3767: ##############################################
3768:
3769: =pod
3770:
3771: =item * &pprmlink()
3772:
3773: Inputs: $text $uname $udom $symb $target
3774:
3775: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3776: student and a specific resource
1.242 albertel 3777:
3778: =cut
3779:
3780: ###############################################
3781: sub pprmlink {
3782: my ($text,$uname,$udom,$symb,$target)=@_;
3783: if (!($uname && $udom)) {
3784: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3785: &Apache::lonnet::whichuser($symb);
1.242 albertel 3786: if (!$symb) { $symb=$cursymb; }
3787: }
1.254 matthew 3788: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3789: $symb=&escape($symb);
1.242 albertel 3790: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3791: return '<a href="/adm/parmset?command=set&'.
3792: 'symb='.$symb.'&uname='.$uname.
3793: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3794: }
3795: ##############################################
1.37 matthew 3796:
1.112 bowersj2 3797: =pod
3798:
3799: =back
3800:
3801: =cut
3802:
1.37 matthew 3803: ###############################################
1.51 www 3804:
3805:
3806: sub timehash {
1.687 raeburn 3807: my ($thistime) = @_;
3808: my $timezone = &Apache::lonlocal::gettimezone();
3809: my $dt = DateTime->from_epoch(epoch => $thistime)
3810: ->set_time_zone($timezone);
3811: my $wday = $dt->day_of_week();
3812: if ($wday == 7) { $wday = 0; }
3813: return ( 'second' => $dt->second(),
3814: 'minute' => $dt->minute(),
3815: 'hour' => $dt->hour(),
3816: 'day' => $dt->day_of_month(),
3817: 'month' => $dt->month(),
3818: 'year' => $dt->year(),
3819: 'weekday' => $wday,
3820: 'dayyear' => $dt->day_of_year(),
3821: 'dlsav' => $dt->is_dst() );
1.51 www 3822: }
3823:
1.370 www 3824: sub utc_string {
3825: my ($date)=@_;
1.371 www 3826: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3827: }
3828:
1.51 www 3829: sub maketime {
3830: my %th=@_;
1.687 raeburn 3831: my ($epoch_time,$timezone,$dt);
3832: $timezone = &Apache::lonlocal::gettimezone();
3833: eval {
3834: $dt = DateTime->new( year => $th{'year'},
3835: month => $th{'month'},
3836: day => $th{'day'},
3837: hour => $th{'hour'},
3838: minute => $th{'minute'},
3839: second => $th{'second'},
3840: time_zone => $timezone,
3841: );
3842: };
3843: if (!$@) {
3844: $epoch_time = $dt->epoch;
3845: if ($epoch_time) {
3846: return $epoch_time;
3847: }
3848: }
1.51 www 3849: return POSIX::mktime(
3850: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3851: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3852: }
3853:
3854: #########################################
1.51 www 3855:
3856: sub findallcourses {
1.482 raeburn 3857: my ($roles,$uname,$udom) = @_;
1.355 albertel 3858: my %roles;
3859: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3860: my %courses;
1.51 www 3861: my $now=time;
1.482 raeburn 3862: if (!defined($uname)) {
3863: $uname = $env{'user.name'};
3864: }
3865: if (!defined($udom)) {
3866: $udom = $env{'user.domain'};
3867: }
3868: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.948.2.11 raeburn 3869: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3870: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3871: $extra);
1.482 raeburn 3872: if (!%roles) {
3873: %roles = (
3874: cc => 1,
1.907 raeburn 3875: co => 1,
1.482 raeburn 3876: in => 1,
3877: ep => 1,
3878: ta => 1,
3879: cr => 1,
3880: st => 1,
3881: );
3882: }
3883: foreach my $entry (keys(%roleshash)) {
3884: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3885: if ($trole =~ /^cr/) {
3886: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3887: } else {
3888: next if (!exists($roles{$trole}));
3889: }
3890: if ($tend) {
3891: next if ($tend < $now);
3892: }
3893: if ($tstart) {
3894: next if ($tstart > $now);
3895: }
3896: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3897: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3898: if ($secpart eq '') {
3899: ($cnum,$role) = split(/_/,$cnumpart);
3900: $sec = 'none';
3901: $realsec = '';
3902: } else {
3903: $cnum = $cnumpart;
3904: ($sec,$role) = split(/_/,$secpart);
3905: $realsec = $sec;
1.490 raeburn 3906: }
1.482 raeburn 3907: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3908: }
3909: } else {
3910: foreach my $key (keys(%env)) {
1.483 albertel 3911: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3912: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3913: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3914: next if ($role eq 'ca' || $role eq 'aa');
3915: next if (%roles && !exists($roles{$role}));
3916: my ($starttime,$endtime)=split(/\./,$env{$key});
3917: my $active=1;
3918: if ($starttime) {
3919: if ($now<$starttime) { $active=0; }
3920: }
3921: if ($endtime) {
3922: if ($now>$endtime) { $active=0; }
3923: }
3924: if ($active) {
3925: if ($sec eq '') {
3926: $sec = 'none';
3927: }
3928: $courses{$cdom.'_'.$cnum}{$sec} =
3929: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3930: }
3931: }
1.51 www 3932: }
3933: }
1.474 raeburn 3934: return %courses;
1.51 www 3935: }
1.37 matthew 3936:
1.54 www 3937: ###############################################
1.474 raeburn 3938:
3939: sub blockcheck {
1.482 raeburn 3940: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3941:
3942: if (!defined($udom)) {
3943: $udom = $env{'user.domain'};
3944: }
3945: if (!defined($uname)) {
3946: $uname = $env{'user.name'};
3947: }
3948:
3949: # If uname and udom are for a course, check for blocks in the course.
3950:
3951: if (&Apache::lonnet::is_course($udom,$uname)) {
3952: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3953: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3954: return ($startblock,$endblock);
3955: }
1.474 raeburn 3956:
1.502 raeburn 3957: my $startblock = 0;
3958: my $endblock = 0;
1.482 raeburn 3959: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3960:
1.490 raeburn 3961: # If uname is for a user, and activity is course-specific, i.e.,
3962: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3963:
1.490 raeburn 3964: if (($activity eq 'boards' || $activity eq 'chat' ||
3965: $activity eq 'groups') && ($env{'request.course.id'})) {
3966: foreach my $key (keys(%live_courses)) {
3967: if ($key ne $env{'request.course.id'}) {
3968: delete($live_courses{$key});
3969: }
3970: }
3971: }
3972:
3973: my $otheruser = 0;
3974: my %own_courses;
3975: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3976: # Resource belongs to user other than current user.
3977: $otheruser = 1;
3978: # Gather courses for current user
3979: %own_courses =
3980: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3981: }
3982:
3983: # Gather active course roles - course coordinator, instructor,
3984: # exam proctor, ta, student, or custom role.
1.474 raeburn 3985:
3986: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3987: my ($cdom,$cnum);
3988: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3989: $cdom = $env{'course.'.$course.'.domain'};
3990: $cnum = $env{'course.'.$course.'.num'};
3991: } else {
1.490 raeburn 3992: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3993: }
3994: my $no_ownblock = 0;
3995: my $no_userblock = 0;
1.533 raeburn 3996: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3997: # Check if current user has 'evb' priv for this
3998: if (defined($own_courses{$course})) {
3999: foreach my $sec (keys(%{$own_courses{$course}})) {
4000: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4001: if ($sec ne 'none') {
4002: $checkrole .= '/'.$sec;
4003: }
4004: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4005: $no_ownblock = 1;
4006: last;
4007: }
4008: }
4009: }
4010: # if they have 'evb' priv and are currently not playing student
4011: next if (($no_ownblock) &&
4012: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4013: }
1.474 raeburn 4014: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4015: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4016: if ($sec ne 'none') {
1.482 raeburn 4017: $checkrole .= '/'.$sec;
1.474 raeburn 4018: }
1.490 raeburn 4019: if ($otheruser) {
4020: # Resource belongs to user other than current user.
4021: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 4022: my ($trole,$tdom,$tnum,$tsec);
4023: my $entry = $live_courses{$course}{$sec};
4024: if ($entry =~ /^cr/) {
4025: ($trole,$tdom,$tnum,$tsec) =
4026: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4027: } else {
4028: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4029: }
4030: my ($spec,$area,$trest,%allroles,%userroles);
4031: $area = '/'.$tdom.'/'.$tnum;
4032: $trest = $tnum;
4033: if ($tsec ne '') {
4034: $area .= '/'.$tsec;
4035: $trest .= '/'.$tsec;
4036: }
4037: $spec = $trole.'.'.$area;
4038: if ($trole =~ /^cr/) {
4039: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4040: $tdom,$spec,$trest,$area);
4041: } else {
4042: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4043: $tdom,$spec,$trest,$area);
4044: }
4045: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4046: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4047: if ($1) {
4048: $no_userblock = 1;
4049: last;
4050: }
4051: }
1.490 raeburn 4052: } else {
4053: # Resource belongs to current user
4054: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4055: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4056: $no_ownblock = 1;
4057: last;
4058: }
1.474 raeburn 4059: }
4060: }
4061: # if they have the evb priv and are currently not playing student
1.482 raeburn 4062: next if (($no_ownblock) &&
1.491 albertel 4063: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4064: next if ($no_userblock);
1.474 raeburn 4065:
1.866 kalberla 4066: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4067: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4068:
4069: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4070: if (($start != 0) &&
4071: (($startblock == 0) || ($startblock > $start))) {
4072: $startblock = $start;
4073: }
4074: if (($end != 0) &&
4075: (($endblock == 0) || ($endblock < $end))) {
4076: $endblock = $end;
4077: }
1.490 raeburn 4078: }
4079: return ($startblock,$endblock);
4080: }
4081:
4082: sub get_blocks {
4083: my ($setters,$activity,$cdom,$cnum) = @_;
4084: my $startblock = 0;
4085: my $endblock = 0;
4086: my $course = $cdom.'_'.$cnum;
4087: $setters->{$course} = {};
4088: $setters->{$course}{'staff'} = [];
4089: $setters->{$course}{'times'} = [];
4090: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4091: foreach my $record (keys(%records)) {
4092: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4093: if ($start <= time && $end >= time) {
4094: my ($staff_name,$staff_dom,$title,$blocks) =
4095: &parse_block_record($records{$record});
4096: if ($blocks->{$activity} eq 'on') {
4097: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4098: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4099: if ( ($startblock == 0) || ($startblock > $start) ) {
4100: $startblock = $start;
1.490 raeburn 4101: }
1.491 albertel 4102: if ( ($endblock == 0) || ($endblock < $end) ) {
4103: $endblock = $end;
1.474 raeburn 4104: }
4105: }
4106: }
4107: }
4108: return ($startblock,$endblock);
4109: }
4110:
4111: sub parse_block_record {
4112: my ($record) = @_;
4113: my ($setuname,$setudom,$title,$blocks);
4114: if (ref($record) eq 'HASH') {
4115: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4116: $title = &unescape($record->{'event'});
4117: $blocks = $record->{'blocks'};
4118: } else {
4119: my @data = split(/:/,$record,3);
4120: if (scalar(@data) eq 2) {
4121: $title = $data[1];
4122: ($setuname,$setudom) = split(/@/,$data[0]);
4123: } else {
4124: ($setuname,$setudom,$title) = @data;
4125: }
4126: $blocks = { 'com' => 'on' };
4127: }
4128: return ($setuname,$setudom,$title,$blocks);
4129: }
4130:
1.854 kalberla 4131: sub blocking_status {
4132: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4133: my %setters;
1.890 droeschl 4134:
4135: # check for active blocking
1.867 kalberla 4136: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4137:
1.890 droeschl 4138: my $blocked = $startblock && $endblock ? 1 : 0;
4139:
4140: # caller just wants to know whether a block is active
4141: if (!wantarray) { return $blocked; }
4142:
4143: # build a link to a popup window containing the details
4144: my $querystring = "?activity=$activity";
4145: # $uname and $udom decide whose portfolio the user is trying to look at
4146: $querystring .= "&udom=$udom" if $udom;
4147: $querystring .= "&uname=$uname" if $uname;
4148:
4149: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4150: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4151: var options = "width=" + w + ",height=" + h + ",";
4152: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4153: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4154: var newWin = window.open(url, wdwName, options);
4155: newWin.focus();
4156: }
1.890 droeschl 4157: END_MYBLOCK
1.854 kalberla 4158:
1.890 droeschl 4159: $output = Apache::lonhtmlcommon::scripttag($output);
4160:
1.854 kalberla 4161: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4162: my $text = mt('Communication Blocked');
4163:
1.867 kalberla 4164: $output .= <<"END_BLOCK";
4165: <div class='LC_comblock'>
1.869 kalberla 4166: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4167: title='$text'>
4168: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4169: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4170: title='$text'>$text</a>
1.867 kalberla 4171: </div>
4172:
4173: END_BLOCK
1.474 raeburn 4174:
1.854 kalberla 4175: return ($blocked, $output);
4176: }
1.490 raeburn 4177:
1.60 matthew 4178: ###############################################
4179:
1.682 raeburn 4180: sub check_ip_acc {
4181: my ($acc)=@_;
4182: &Apache::lonxml::debug("acc is $acc");
4183: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4184: return 1;
4185: }
4186: my $allowed=0;
4187: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4188:
4189: my $name;
4190: foreach my $pattern (split(',',$acc)) {
4191: $pattern =~ s/^\s*//;
4192: $pattern =~ s/\s*$//;
4193: if ($pattern =~ /\*$/) {
4194: #35.8.*
4195: $pattern=~s/\*//;
4196: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4197: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4198: #35.8.3.[34-56]
4199: my $low=$2;
4200: my $high=$3;
4201: $pattern=$1;
4202: if ($ip =~ /^\Q$pattern\E/) {
4203: my $last=(split(/\./,$ip))[3];
4204: if ($last <=$high && $last >=$low) { $allowed=1; }
4205: }
4206: } elsif ($pattern =~ /^\*/) {
4207: #*.msu.edu
4208: $pattern=~s/\*//;
4209: if (!defined($name)) {
4210: use Socket;
4211: my $netaddr=inet_aton($ip);
4212: ($name)=gethostbyaddr($netaddr,AF_INET);
4213: }
4214: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4215: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4216: #127.0.0.1
4217: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4218: } else {
4219: #some.name.com
4220: if (!defined($name)) {
4221: use Socket;
4222: my $netaddr=inet_aton($ip);
4223: ($name)=gethostbyaddr($netaddr,AF_INET);
4224: }
4225: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4226: }
4227: if ($allowed) { last; }
4228: }
4229: return $allowed;
4230: }
4231:
4232: ###############################################
4233:
1.60 matthew 4234: =pod
4235:
1.112 bowersj2 4236: =head1 Domain Template Functions
4237:
4238: =over 4
4239:
4240: =item * &determinedomain()
1.60 matthew 4241:
4242: Inputs: $domain (usually will be undef)
4243:
1.63 www 4244: Returns: Determines which domain should be used for designs
1.60 matthew 4245:
4246: =cut
1.54 www 4247:
1.60 matthew 4248: ###############################################
1.63 www 4249: sub determinedomain {
4250: my $domain=shift;
1.531 albertel 4251: if (! $domain) {
1.60 matthew 4252: # Determine domain if we have not been given one
1.893 raeburn 4253: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4254: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4255: if ($env{'request.role.domain'}) {
4256: $domain=$env{'request.role.domain'};
1.60 matthew 4257: }
4258: }
1.63 www 4259: return $domain;
4260: }
4261: ###############################################
1.517 raeburn 4262:
1.518 albertel 4263: sub devalidate_domconfig_cache {
4264: my ($udom)=@_;
4265: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4266: }
4267:
4268: # ---------------------- Get domain configuration for a domain
4269: sub get_domainconf {
4270: my ($udom) = @_;
4271: my $cachetime=1800;
4272: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4273: if (defined($cached)) { return %{$result}; }
4274:
4275: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4276: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4277: my (%designhash,%legacy);
1.518 albertel 4278: if (keys(%domconfig) > 0) {
4279: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4280: if (keys(%{$domconfig{'login'}})) {
4281: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4282: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4283: if ($key eq 'loginvia') {
4284: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4285: my @ids = &Apache::lonnet::current_machine_ids();
4286: foreach my $hostname (@ids) {
1.948 raeburn 4287: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4288: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4289: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4290: $designhash{$udom.'.login.loginvia'} = $server;
4291: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4292:
4293: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4294: } else {
4295: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4296: }
4297: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4298: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4299: }
1.946 raeburn 4300: }
4301: }
4302: }
4303: }
4304: } else {
4305: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4306: $designhash{$udom.'.login.'.$key.'_'.$img} =
4307: $domconfig{'login'}{$key}{$img};
4308: }
1.699 raeburn 4309: }
4310: } else {
4311: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4312: }
1.632 raeburn 4313: }
4314: } else {
4315: $legacy{'login'} = 1;
1.518 albertel 4316: }
1.632 raeburn 4317: } else {
4318: $legacy{'login'} = 1;
1.518 albertel 4319: }
4320: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4321: if (keys(%{$domconfig{'rolecolors'}})) {
4322: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4323: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4324: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4325: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4326: }
1.518 albertel 4327: }
4328: }
1.632 raeburn 4329: } else {
4330: $legacy{'rolecolors'} = 1;
1.518 albertel 4331: }
1.632 raeburn 4332: } else {
4333: $legacy{'rolecolors'} = 1;
1.518 albertel 4334: }
1.948 raeburn 4335: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4336: if ($domconfig{'autoenroll'}{'co-owners'}) {
4337: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4338: }
4339: }
1.632 raeburn 4340: if (keys(%legacy) > 0) {
4341: my %legacyhash = &get_legacy_domconf($udom);
4342: foreach my $item (keys(%legacyhash)) {
4343: if ($item =~ /^\Q$udom\E\.login/) {
4344: if ($legacy{'login'}) {
4345: $designhash{$item} = $legacyhash{$item};
4346: }
4347: } else {
4348: if ($legacy{'rolecolors'}) {
4349: $designhash{$item} = $legacyhash{$item};
4350: }
1.518 albertel 4351: }
4352: }
4353: }
1.632 raeburn 4354: } else {
4355: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4356: }
4357: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4358: $cachetime);
4359: return %designhash;
4360: }
4361:
1.632 raeburn 4362: sub get_legacy_domconf {
4363: my ($udom) = @_;
4364: my %legacyhash;
4365: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4366: my $designfile = $designdir.'/'.$udom.'.tab';
4367: if (-e $designfile) {
4368: if ( open (my $fh,"<$designfile") ) {
4369: while (my $line = <$fh>) {
4370: next if ($line =~ /^\#/);
4371: chomp($line);
4372: my ($key,$val)=(split(/\=/,$line));
4373: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4374: }
4375: close($fh);
4376: }
4377: }
4378: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4379: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4380: }
4381: return %legacyhash;
4382: }
4383:
1.63 www 4384: =pod
4385:
1.112 bowersj2 4386: =item * &domainlogo()
1.63 www 4387:
4388: Inputs: $domain (usually will be undef)
4389:
4390: Returns: A link to a domain logo, if the domain logo exists.
4391: If the domain logo does not exist, a description of the domain.
4392:
4393: =cut
1.112 bowersj2 4394:
1.63 www 4395: ###############################################
4396: sub domainlogo {
1.517 raeburn 4397: my $domain = &determinedomain(shift);
1.518 albertel 4398: my %designhash = &get_domainconf($domain);
1.517 raeburn 4399: # See if there is a logo
4400: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4401: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4402: if ($imgsrc =~ m{^/(adm|res)/}) {
4403: if ($imgsrc =~ m{^/res/}) {
4404: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4405: &Apache::lonnet::repcopy($local_name);
4406: }
4407: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4408: }
4409: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4410: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4411: return &Apache::lonnet::domain($domain,'description');
1.59 www 4412: } else {
1.60 matthew 4413: return '';
1.59 www 4414: }
4415: }
1.63 www 4416: ##############################################
4417:
4418: =pod
4419:
1.112 bowersj2 4420: =item * &designparm()
1.63 www 4421:
4422: Inputs: $which parameter; $domain (usually will be undef)
4423:
4424: Returns: value of designparamter $which
4425:
4426: =cut
1.112 bowersj2 4427:
1.397 albertel 4428:
1.400 albertel 4429: ##############################################
1.397 albertel 4430: sub designparm {
4431: my ($which,$domain)=@_;
4432: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4433: return $env{'environment.color.'.$which};
1.96 www 4434: }
1.63 www 4435: $domain=&determinedomain($domain);
1.518 albertel 4436: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4437: my $output;
1.517 raeburn 4438: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4439: $output = $domdesign{$domain.'.'.$which};
1.63 www 4440: } else {
1.520 raeburn 4441: $output = $defaultdesign{$which};
4442: }
4443: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4444: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4445: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4446: if ($output =~ m{^/res/}) {
4447: my $local_name = &Apache::lonnet::filelocation('',$output);
4448: &Apache::lonnet::repcopy($local_name);
4449: }
1.520 raeburn 4450: $output = &lonhttpdurl($output);
4451: }
1.63 www 4452: }
1.520 raeburn 4453: return $output;
1.63 www 4454: }
1.59 www 4455:
1.822 bisitz 4456: ##############################################
4457: =pod
4458:
1.832 bisitz 4459: =item * &authorspace()
4460:
4461: Inputs: ./.
4462:
4463: Returns: Path to the Construction Space of the current user's
4464: accessed author space
4465: The author space will be that of the current user
4466: when accessing the own author space
4467: and that of the co-author/assistent co-author
4468: when accessing the co-author's/assistent co-author's
4469: space
4470:
4471: =cut
4472:
4473: sub authorspace {
4474: my $caname = '';
4475: if ($env{'request.role'} =~ /^ca|^aa/) {
4476: (undef,$caname) =
4477: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4478: } else {
4479: $caname = $env{'user.name'};
4480: }
4481: return '/priv/'.$caname.'/';
4482: }
4483:
4484: ##############################################
4485: =pod
4486:
1.822 bisitz 4487: =item * &head_subbox()
4488:
4489: Inputs: $content (contains HTML code with page functions, etc.)
4490:
4491: Returns: HTML div with $content
4492: To be included in page header
4493:
4494: =cut
4495:
4496: sub head_subbox {
4497: my ($content)=@_;
4498: my $output =
1.948.2.22 raeburn 4499: '<div class="LC_head_subbox">'
1.822 bisitz 4500: .$content
4501: .'</div>'
4502: }
4503:
4504: ##############################################
4505: =pod
4506:
4507: =item * &CSTR_pageheader()
4508:
4509: Inputs: ./.
4510:
4511: Returns: HTML div with CSTR path and recent box
4512: To be included on Construction Space pages
4513:
4514: =cut
4515:
4516: sub CSTR_pageheader {
4517: # this is for resources; directories have customtitle, and crumbs
4518: # and select recent are created in lonpubdir.pm
4519: my ($uname,$thisdisfn)=
4520: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4521: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4522: $formaction=~s/\/+/\//g;
4523:
4524: my $parentpath = '';
4525: my $lastitem = '';
4526: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4527: $parentpath = $1;
4528: $lastitem = $2;
4529: } else {
4530: $lastitem = $thisdisfn;
4531: }
1.921 bisitz 4532:
4533: my $output =
1.822 bisitz 4534: '<div>'
4535: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4536: .'<b>'.&mt('Construction Space:').'</b> '
4537: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4538: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4539: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4540:
4541: if ($lastitem) {
4542: $output .=
4543: '<span class="LC_filename">'
4544: .$lastitem
4545: .'</span>';
4546: }
4547: $output .=
4548: '<br />'
1.822 bisitz 4549: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4550: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4551: .'</form>'
4552: .&Apache::lonmenu::constspaceform()
4553: .'</div>';
1.921 bisitz 4554:
4555: return $output;
1.822 bisitz 4556: }
4557:
1.60 matthew 4558: ###############################################
4559: ###############################################
4560:
4561: =pod
4562:
1.112 bowersj2 4563: =back
4564:
1.549 albertel 4565: =head1 HTML Helpers
1.112 bowersj2 4566:
4567: =over 4
4568:
4569: =item * &bodytag()
1.60 matthew 4570:
4571: Returns a uniform header for LON-CAPA web pages.
4572:
4573: Inputs:
4574:
1.112 bowersj2 4575: =over 4
4576:
4577: =item * $title, A title to be displayed on the page.
4578:
4579: =item * $function, the current role (can be undef).
4580:
4581: =item * $addentries, extra parameters for the <body> tag.
4582:
4583: =item * $bodyonly, if defined, only return the <body> tag.
4584:
4585: =item * $domain, if defined, force a given domain.
4586:
4587: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4588: text interface only)
1.60 matthew 4589:
1.814 bisitz 4590: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4591: navigational links
1.317 albertel 4592:
1.338 albertel 4593: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4594:
1.361 albertel 4595: =item * $no_inline_link, if true and in remote mode, don't show the
4596: 'Switch To Inline Menu' link
4597:
1.460 albertel 4598: =item * $args, optional argument valid values are
4599: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4600: inherit_jsmath -> when creating popup window in a page,
4601: should it have jsmath forced on by the
4602: current page
1.460 albertel 4603:
1.112 bowersj2 4604: =back
4605:
1.60 matthew 4606: Returns: A uniform header for LON-CAPA web pages.
4607: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4608: If $bodyonly is undef or zero, an html string containing a <body> tag and
4609: other decorations will be returned.
4610:
4611: =cut
4612:
1.54 www 4613: sub bodytag {
1.831 bisitz 4614: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4615: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4616:
1.948.2.2 raeburn 4617: my $public;
4618: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4619: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4620: $public = 1;
4621: }
1.460 albertel 4622: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4623:
1.183 matthew 4624: $function = &get_users_function() if (!$function);
1.339 albertel 4625: my $img = &designparm($function.'.img',$domain);
4626: my $font = &designparm($function.'.font',$domain);
4627: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4628:
1.803 bisitz 4629: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4630: 'bgcolor' => $pgbg,
1.339 albertel 4631: 'text' => $font,
4632: 'alink' => &designparm($function.'.alink',$domain),
4633: 'vlink' => &designparm($function.'.vlink',$domain),
4634: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4635: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4636:
1.63 www 4637: # role and realm
1.378 raeburn 4638: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4639: if ($role eq 'ca') {
1.479 albertel 4640: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4641: $realm = &plainname($rname,$rdom);
1.378 raeburn 4642: }
1.55 www 4643: # realm
1.258 albertel 4644: if ($env{'request.course.id'}) {
1.378 raeburn 4645: if ($env{'request.role'} !~ /^cr/) {
4646: $role = &Apache::lonnet::plaintext($role,&course_type());
4647: }
1.898 raeburn 4648: if ($env{'request.course.sec'}) {
4649: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4650: }
1.359 albertel 4651: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4652: } else {
4653: $role = &Apache::lonnet::plaintext($role);
1.54 www 4654: }
1.433 albertel 4655:
1.359 albertel 4656: if (!$realm) { $realm=' '; }
1.55 www 4657: # Set messages
1.60 matthew 4658: my $messages=&domainlogo($domain);
1.330 albertel 4659:
1.438 albertel 4660: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4661:
1.101 www 4662: # construct main body tag
1.359 albertel 4663: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4664: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4665:
1.530 albertel 4666: if ($bodyonly) {
1.60 matthew 4667: return $bodytag;
1.798 tempelho 4668: }
1.359 albertel 4669:
1.410 albertel 4670: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.948.2.2 raeburn 4671: if ($public) {
1.433 albertel 4672: undef($role);
1.434 albertel 4673: } else {
4674: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4675: }
1.948.2.2 raeburn 4676:
1.762 bisitz 4677: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4678: #
4679: # Extra info if you are the DC
4680: my $dc_info = '';
4681: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4682: $env{'course.'.$env{'request.course.id'}.
4683: '.domain'}.'/'})) {
4684: my $cid = $env{'request.course.id'};
1.917 raeburn 4685: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4686: $dc_info =~ s/\s+$//;
1.359 albertel 4687: }
4688:
1.898 raeburn 4689: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4690: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4691:
1.948.2.19 raeburn 4692: if ($env{'environment.remote'} ne 'on') {
1.359 albertel 4693: # No Remote
1.916 droeschl 4694: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
1.948.2.19 raeburn 4695: return $bodytag;
4696: }
1.903 droeschl 4697:
4698: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4699:
4700: # if ($env{'request.state'} eq 'construct') {
4701: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4702: # }
4703:
1.359 albertel 4704:
4705:
1.916 droeschl 4706: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4707: if ($dc_info) {
4708: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4709: }
1.916 droeschl 4710: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4711: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4712: return $bodytag;
4713: }
1.948.2.19 raeburn 4714: if (($env{'request.noversionuri'} =~ m{^/adm/navmaps}) &&
4715: ($env{'environment.remotenavmap'} eq 'on')) {
4716: return $bodytag;
4717: }
1.894 droeschl 4718:
1.927 raeburn 4719: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4720: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4721: }
1.916 droeschl 4722:
1.903 droeschl 4723: $bodytag .= Apache::lonhtmlcommon::scripttag(
4724: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4725:
1.903 droeschl 4726: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4727:
1.917 raeburn 4728: if ($dc_info) {
4729: $dc_info = &dc_courseid_toggle($dc_info);
4730: }
4731: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4732:
1.903 droeschl 4733: #don't show menus for public users
1.948.2.2 raeburn 4734: if (!$public){
1.903 droeschl 4735: $bodytag .= Apache::lonmenu::secondary_menu();
4736: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4737: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4738: if ($env{'request.state'} eq 'construct') {
4739: $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
4740: $args->{'bread_crumbs'});
4741: } elsif ($forcereg) {
4742: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4743: }
1.903 droeschl 4744: }else{
4745: # this is to seperate menu from content when there's no secondary
4746: # menu. Especially needed for public accessible ressources.
4747: $bodytag .= '<hr style="clear:both" />';
4748: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4749: }
1.903 droeschl 4750:
1.235 raeburn 4751: return $bodytag;
1.94 www 4752: }
1.95 www 4753:
1.93 www 4754: #
1.95 www 4755: # Top frame rendering, Remote is up
1.93 www 4756: #
1.359 albertel 4757:
1.517 raeburn 4758: my $imgsrc = $img;
4759: if ($img =~ /^\/adm/) {
1.575 albertel 4760: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4761: }
4762: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4763:
1.305 www 4764: # Explicit link to get inline menu
1.361 albertel 4765: my $menu= ($no_inline_link?''
1.883 droeschl 4766: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917 raeburn 4767:
4768: if ($dc_info) {
4769: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
4770: }
4771:
1.916 droeschl 4772: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.897 wenzelju 4773: <ol class="LC_primary_menu LC_right">
1.853 droeschl 4774: <li>$menu</li>
1.917 raeburn 4775: </ol><div id="LC_realm"> $realm $dc_info</div>| unless $env{'form.inhibitmenu'};
1.94 www 4776: return(<<ENDBODY);
1.60 matthew 4777: $bodytag
1.359 albertel 4778: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4779: <tr><td>$upperleft</td>
4780: <td>$messages </td>
1.54 www 4781: </tr>
1.359 albertel 4782: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4783: </tr>
1.356 albertel 4784: </table>
1.54 www 4785: ENDBODY
1.182 matthew 4786: }
4787:
1.917 raeburn 4788: sub dc_courseid_toggle {
4789: my ($dc_info) = @_;
1.948.2.10 raeburn 4790: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4791: '<a href="javascript:showCourseID();">'.
4792: &mt('(More ...)').'</a></span>'.
4793: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4794: }
4795:
1.330 albertel 4796: sub make_attr_string {
4797: my ($register,$attr_ref) = @_;
4798:
4799: if ($attr_ref && !ref($attr_ref)) {
4800: die("addentries Must be a hash ref ".
4801: join(':',caller(1))." ".
4802: join(':',caller(0))." ");
4803: }
4804:
4805: if ($register) {
1.339 albertel 4806: my ($on_load,$on_unload);
4807: foreach my $key (keys(%{$attr_ref})) {
4808: if (lc($key) eq 'onload') {
4809: $on_load.=$attr_ref->{$key}.';';
4810: delete($attr_ref->{$key});
4811:
4812: } elsif (lc($key) eq 'onunload') {
4813: $on_unload.=$attr_ref->{$key}.';';
4814: delete($attr_ref->{$key});
4815: }
4816: }
4817: $attr_ref->{'onload'} =
4818: &Apache::lonmenu::loadevents(). $on_load;
4819: $attr_ref->{'onunload'}=
4820: &Apache::lonmenu::unloadevents().$on_unload;
4821: }
4822:
4823: # Accessibility font enhance
4824: if ($env{'browser.fontenhance'} eq 'on') {
4825: my $style;
4826: foreach my $key (keys(%{$attr_ref})) {
4827: if (lc($key) eq 'style') {
4828: $style.=$attr_ref->{$key}.';';
4829: delete($attr_ref->{$key});
4830: }
4831: }
4832: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4833: }
1.339 albertel 4834:
1.330 albertel 4835: my $attr_string;
4836: foreach my $attr (keys(%$attr_ref)) {
4837: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4838: }
4839: return $attr_string;
4840: }
4841:
4842:
1.182 matthew 4843: ###############################################
1.251 albertel 4844: ###############################################
4845:
4846: =pod
4847:
4848: =item * &endbodytag()
4849:
4850: Returns a uniform footer for LON-CAPA web pages.
4851:
1.635 raeburn 4852: Inputs: 1 - optional reference to an args hash
4853: If in the hash, key for noredirectlink has a value which evaluates to true,
4854: a 'Continue' link is not displayed if the page contains an
4855: internal redirect in the <head></head> section,
4856: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4857:
4858: =cut
4859:
4860: sub endbodytag {
1.635 raeburn 4861: my ($args) = @_;
1.251 albertel 4862: my $endbodytag='</body>';
1.269 albertel 4863: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4864: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4865: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4866: $endbodytag=
4867: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4868: &mt('Continue').'</a>'.
4869: $endbodytag;
4870: }
1.315 albertel 4871: }
1.251 albertel 4872: return $endbodytag;
4873: }
4874:
1.352 albertel 4875: =pod
4876:
4877: =item * &standard_css()
4878:
4879: Returns a style sheet
4880:
4881: Inputs: (all optional)
4882: domain -> force to color decorate a page for a specific
4883: domain
4884: function -> force usage of a specific rolish color scheme
4885: bgcolor -> override the default page bgcolor
4886:
4887: =cut
4888:
1.343 albertel 4889: sub standard_css {
1.345 albertel 4890: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4891: $function = &get_users_function() if (!$function);
4892: my $img = &designparm($function.'.img', $domain);
4893: my $tabbg = &designparm($function.'.tabbg', $domain);
4894: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4895: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4896: #second colour for later usage
1.345 albertel 4897: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4898: my $pgbg_or_bgcolor =
4899: $bgcolor ||
1.352 albertel 4900: &designparm($function.'.pgbg', $domain);
1.382 albertel 4901: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4902: my $alink = &designparm($function.'.alink', $domain);
4903: my $vlink = &designparm($function.'.vlink', $domain);
4904: my $link = &designparm($function.'.link', $domain);
4905:
1.602 albertel 4906: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4907: my $mono = 'monospace';
1.850 bisitz 4908: my $data_table_head = $sidebg;
4909: my $data_table_light = '#FAFAFA';
4910: my $data_table_dark = '#F0F0F0';
1.470 banghart 4911: my $data_table_darker = '#CCCCCC';
1.349 albertel 4912: my $data_table_highlight = '#FFFF00';
1.352 albertel 4913: my $mail_new = '#FFBB77';
4914: my $mail_new_hover = '#DD9955';
4915: my $mail_read = '#BBBB77';
4916: my $mail_read_hover = '#999944';
4917: my $mail_replied = '#AAAA88';
4918: my $mail_replied_hover = '#888855';
4919: my $mail_other = '#99BBBB';
4920: my $mail_other_hover = '#669999';
1.391 albertel 4921: my $table_header = '#DDDDDD';
1.489 raeburn 4922: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4923: my $lg_border_color = '#C8C8C8';
1.948.2.1 raeburn 4924: my $button_hover = '#BF2317';
1.392 albertel 4925:
1.608 albertel 4926: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4927: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4928: : '0 3px 0 4px';
1.448 albertel 4929:
1.343 albertel 4930: return <<END;
1.947 droeschl 4931:
4932: /* needed for iframe to allow 100% height in FF */
4933: body, html {
4934: margin: 0;
4935: padding: 0 0.5%;
4936: height: 99%; /* to avoid scrollbars */
4937: }
4938:
1.795 www 4939: body {
1.911 bisitz 4940: font-family: $sans;
4941: line-height:130%;
4942: font-size:0.83em;
4943: color:$font;
1.795 www 4944: }
4945:
1.948.2.9 raeburn 4946: a:focus,
4947: a:focus img {
1.795 www 4948: color: red;
1.911 bisitz 4949: background: yellow;
1.795 www 4950: }
1.698 harmsja 4951:
1.911 bisitz 4952: form, .inline {
4953: display: inline;
1.795 www 4954: }
1.721 harmsja 4955:
1.795 www 4956: .LC_right {
1.911 bisitz 4957: text-align:right;
1.795 www 4958: }
4959:
4960: .LC_middle {
1.911 bisitz 4961: vertical-align:middle;
1.795 www 4962: }
1.721 harmsja 4963:
1.911 bisitz 4964: .LC_400Box {
4965: width:400px;
4966: }
1.721 harmsja 4967:
1.947 droeschl 4968: .LC_iframecontainer {
4969: width: 98%;
4970: margin: 0;
4971: position: fixed;
4972: top: 8.5em;
4973: bottom: 0;
4974: }
4975:
4976: .LC_iframecontainer iframe{
4977: border: none;
4978: width: 100%;
4979: height: 100%;
4980: }
4981:
1.778 bisitz 4982: .LC_filename {
4983: font-family: $mono;
4984: white-space:pre;
1.921 bisitz 4985: font-size: 120%;
1.778 bisitz 4986: }
4987:
4988: .LC_fileicon {
4989: border: none;
4990: height: 1.3em;
4991: vertical-align: text-bottom;
4992: margin-right: 0.3em;
4993: text-decoration:none;
4994: }
4995:
1.350 albertel 4996: .LC_error {
4997: color: red;
4998: font-size: larger;
4999: }
1.795 www 5000:
1.457 albertel 5001: .LC_warning,
5002: .LC_diff_removed {
1.733 bisitz 5003: color: red;
1.394 albertel 5004: }
1.532 albertel 5005:
5006: .LC_info,
1.457 albertel 5007: .LC_success,
5008: .LC_diff_added {
1.350 albertel 5009: color: green;
5010: }
1.795 www 5011:
1.802 bisitz 5012: div.LC_confirm_box {
5013: background-color: #FAFAFA;
5014: border: 1px solid $lg_border_color;
5015: margin-right: 0;
5016: padding: 5px;
5017: }
5018:
5019: div.LC_confirm_box .LC_error img,
5020: div.LC_confirm_box .LC_success img {
5021: vertical-align: middle;
5022: }
5023:
1.440 albertel 5024: .LC_icon {
1.771 droeschl 5025: border: none;
1.790 droeschl 5026: vertical-align: middle;
1.771 droeschl 5027: }
5028:
1.543 albertel 5029: .LC_docs_spacer {
5030: width: 25px;
5031: height: 1px;
1.771 droeschl 5032: border: none;
1.543 albertel 5033: }
1.346 albertel 5034:
1.532 albertel 5035: .LC_internal_info {
1.735 bisitz 5036: color: #999999;
1.532 albertel 5037: }
5038:
1.794 www 5039: .LC_discussion {
1.911 bisitz 5040: background: $tabbg;
5041: border: 1px solid black;
5042: margin: 2px;
1.794 www 5043: }
5044:
5045: .LC_disc_action_links_bar {
1.911 bisitz 5046: background: $tabbg;
5047: border: none;
5048: margin: 4px;
1.794 www 5049: }
5050:
5051: .LC_disc_action_left {
1.911 bisitz 5052: text-align: left;
1.794 www 5053: }
5054:
5055: .LC_disc_action_right {
1.911 bisitz 5056: text-align: right;
1.794 www 5057: }
5058:
5059: .LC_disc_new_item {
1.911 bisitz 5060: background: white;
5061: border: 2px solid red;
5062: margin: 2px;
1.794 www 5063: }
5064:
5065: .LC_disc_old_item {
1.911 bisitz 5066: background: white;
5067: border: 1px solid black;
5068: margin: 2px;
1.794 www 5069: }
5070:
1.458 albertel 5071: table.LC_pastsubmission {
5072: border: 1px solid black;
5073: margin: 2px;
5074: }
5075:
1.924 bisitz 5076: table#LC_menubuttons {
1.345 albertel 5077: width: 100%;
5078: background: $pgbg;
1.392 albertel 5079: border: 2px;
1.402 albertel 5080: border-collapse: separate;
1.803 bisitz 5081: padding: 0;
1.345 albertel 5082: }
1.392 albertel 5083:
1.801 tempelho 5084: table#LC_title_bar a {
5085: color: $fontmenu;
5086: }
1.836 bisitz 5087:
1.807 droeschl 5088: table#LC_title_bar {
1.819 tempelho 5089: clear: both;
1.836 bisitz 5090: display: none;
1.807 droeschl 5091: }
5092:
1.795 www 5093: table#LC_title_bar,
1.933 droeschl 5094: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5095: table#LC_title_bar.LC_with_remote {
1.359 albertel 5096: width: 100%;
1.392 albertel 5097: border-color: $pgbg;
5098: border-style: solid;
5099: border-width: $border;
1.379 albertel 5100: background: $pgbg;
1.801 tempelho 5101: color: $fontmenu;
1.392 albertel 5102: border-collapse: collapse;
1.803 bisitz 5103: padding: 0;
1.819 tempelho 5104: margin: 0;
1.359 albertel 5105: }
1.795 www 5106:
1.933 droeschl 5107: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5108: margin: 0;
5109: padding: 0;
1.933 droeschl 5110: position: relative;
5111: list-style: none;
1.913 droeschl 5112: }
1.933 droeschl 5113: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5114: display: inline;
5115: }
1.933 droeschl 5116:
5117: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5118: padding: 0;
1.933 droeschl 5119: margin: 0;
5120: float: left;
1.913 droeschl 5121: }
1.933 droeschl 5122: .LC_breadcrumb_tools_tools {
5123: padding: 0;
5124: margin: 0;
1.913 droeschl 5125: float: right;
5126: }
5127:
1.359 albertel 5128: table#LC_title_bar td {
5129: background: $tabbg;
5130: }
1.795 www 5131:
1.911 bisitz 5132: table#LC_menubuttons img {
1.803 bisitz 5133: border: none;
1.346 albertel 5134: }
1.795 www 5135:
1.842 droeschl 5136: .LC_breadcrumbs_component {
1.911 bisitz 5137: float: right;
5138: margin: 0 1em;
1.357 albertel 5139: }
1.842 droeschl 5140: .LC_breadcrumbs_component img {
1.911 bisitz 5141: vertical-align: middle;
1.777 tempelho 5142: }
1.795 www 5143:
1.383 albertel 5144: td.LC_table_cell_checkbox {
5145: text-align: center;
5146: }
1.795 www 5147:
5148: .LC_fontsize_small {
1.911 bisitz 5149: font-size: 70%;
1.705 tempelho 5150: }
5151:
1.844 bisitz 5152: #LC_breadcrumbs {
1.911 bisitz 5153: clear:both;
5154: background: $sidebg;
5155: border-bottom: 1px solid $lg_border_color;
5156: line-height: 2.5em;
1.933 droeschl 5157: overflow: hidden;
1.911 bisitz 5158: margin: 0;
5159: padding: 0;
1.948.2.24! raeburn 5160: text-align: left;
1.819 tempelho 5161: }
1.862 bisitz 5162:
1.839 droeschl 5163: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 5164: #LC_remote #LC_breadcrumbs {
1.911 bisitz 5165: display:none;
1.839 droeschl 5166: }
1.819 tempelho 5167:
1.948.2.22 raeburn 5168: .LC_head_subbox {
1.911 bisitz 5169: clear:both;
5170: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5171: border: 1px solid $sidebg;
5172: margin: 0 0 10px 0;
1.948.2.6 raeburn 5173: padding: 3px;
1.948.2.24! raeburn 5174: text-align: left;
1.822 bisitz 5175: }
5176:
1.795 www 5177: .LC_fontsize_medium {
1.911 bisitz 5178: font-size: 85%;
1.705 tempelho 5179: }
5180:
1.795 www 5181: .LC_fontsize_large {
1.911 bisitz 5182: font-size: 120%;
1.705 tempelho 5183: }
5184:
1.346 albertel 5185: .LC_menubuttons_inline_text {
5186: color: $font;
1.698 harmsja 5187: font-size: 90%;
1.701 harmsja 5188: padding-left:3px;
1.346 albertel 5189: }
5190:
1.934 droeschl 5191: .LC_menubuttons_inline_text img{
5192: vertical-align: middle;
5193: }
5194:
1.948.2.1 raeburn 5195: li.LC_menubuttons_inline_text img,a {
5196: cursor:pointer;
5197: }
5198:
1.526 www 5199: .LC_menubuttons_link {
5200: text-decoration: none;
5201: }
1.795 www 5202:
1.522 albertel 5203: .LC_menubuttons_category {
1.521 www 5204: color: $font;
1.526 www 5205: background: $pgbg;
1.521 www 5206: font-size: larger;
5207: font-weight: bold;
5208: }
5209:
1.346 albertel 5210: td.LC_menubuttons_text {
1.911 bisitz 5211: color: $font;
1.346 albertel 5212: }
1.706 harmsja 5213:
1.346 albertel 5214: .LC_current_location {
5215: background: $tabbg;
5216: }
1.795 www 5217:
1.938 bisitz 5218: table.LC_data_table {
1.347 albertel 5219: border: 1px solid #000000;
1.402 albertel 5220: border-collapse: separate;
1.426 albertel 5221: border-spacing: 1px;
1.610 albertel 5222: background: $pgbg;
1.347 albertel 5223: }
1.795 www 5224:
1.422 albertel 5225: .LC_data_table_dense {
5226: font-size: small;
5227: }
1.795 www 5228:
1.507 raeburn 5229: table.LC_nested_outer {
5230: border: 1px solid #000000;
1.589 raeburn 5231: border-collapse: collapse;
1.803 bisitz 5232: border-spacing: 0;
1.507 raeburn 5233: width: 100%;
5234: }
1.795 www 5235:
1.879 raeburn 5236: table.LC_innerpickbox,
1.507 raeburn 5237: table.LC_nested {
1.803 bisitz 5238: border: none;
1.589 raeburn 5239: border-collapse: collapse;
1.803 bisitz 5240: border-spacing: 0;
1.507 raeburn 5241: width: 100%;
5242: }
1.795 www 5243:
1.930 faziophi 5244: .ui-accordion,
5245: .ui-accordion table.LC_data_table,
5246: .ui-accordion table.LC_nested_outer{
5247: border: 0px;
5248: border-spacing: 0px;
5249: margin: 3px;
5250: }
5251:
1.911 bisitz 5252: table.LC_data_table tr th,
5253: table.LC_calendar tr th,
1.879 raeburn 5254: table.LC_prior_tries tr th,
5255: table.LC_innerpickbox tr th {
1.349 albertel 5256: font-weight: bold;
5257: background-color: $data_table_head;
1.801 tempelho 5258: color:$fontmenu;
1.701 harmsja 5259: font-size:90%;
1.347 albertel 5260: }
1.795 www 5261:
1.879 raeburn 5262: table.LC_innerpickbox tr th,
5263: table.LC_innerpickbox tr td {
5264: vertical-align: top;
5265: }
5266:
1.711 raeburn 5267: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5268: background-color: #CCCCCC;
1.711 raeburn 5269: font-weight: bold;
5270: text-align: left;
5271: }
1.795 www 5272:
1.912 bisitz 5273: table.LC_data_table tr.LC_odd_row > td {
5274: background-color: $data_table_light;
5275: padding: 2px;
5276: vertical-align: top;
5277: }
5278:
1.809 bisitz 5279: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5280: background-color: $data_table_light;
1.912 bisitz 5281: vertical-align: top;
5282: }
5283:
5284: table.LC_data_table tr.LC_even_row > td {
5285: background-color: $data_table_dark;
1.425 albertel 5286: padding: 2px;
1.900 bisitz 5287: vertical-align: top;
1.347 albertel 5288: }
1.795 www 5289:
1.809 bisitz 5290: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5291: background-color: $data_table_dark;
1.900 bisitz 5292: vertical-align: top;
1.347 albertel 5293: }
1.795 www 5294:
1.425 albertel 5295: table.LC_data_table tr.LC_data_table_highlight td {
5296: background-color: $data_table_darker;
5297: }
1.795 www 5298:
1.639 raeburn 5299: table.LC_data_table tr td.LC_leftcol_header {
5300: background-color: $data_table_head;
5301: font-weight: bold;
5302: }
1.795 www 5303:
1.451 albertel 5304: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5305: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5306: font-weight: bold;
5307: font-style: italic;
5308: text-align: center;
5309: padding: 8px;
1.347 albertel 5310: }
1.795 www 5311:
1.940 bisitz 5312: table.LC_data_table tr.LC_empty_row td {
5313: background-color: $sidebg;
5314: }
5315:
5316: table.LC_nested tr.LC_empty_row td {
5317: background-color: #FFFFFF;
5318: }
5319:
1.890 droeschl 5320: table.LC_caption {
5321: }
5322:
1.507 raeburn 5323: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5324: padding: 4ex
5325: }
1.795 www 5326:
1.507 raeburn 5327: table.LC_nested_outer tr th {
5328: font-weight: bold;
1.801 tempelho 5329: color:$fontmenu;
1.507 raeburn 5330: background-color: $data_table_head;
1.701 harmsja 5331: font-size: small;
1.507 raeburn 5332: border-bottom: 1px solid #000000;
5333: }
1.795 www 5334:
1.507 raeburn 5335: table.LC_nested_outer tr td.LC_subheader {
5336: background-color: $data_table_head;
5337: font-weight: bold;
5338: font-size: small;
5339: border-bottom: 1px solid #000000;
5340: text-align: right;
1.451 albertel 5341: }
1.795 www 5342:
1.507 raeburn 5343: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5344: background-color: #CCCCCC;
1.451 albertel 5345: font-weight: bold;
5346: font-size: small;
1.507 raeburn 5347: text-align: center;
5348: }
1.795 www 5349:
1.589 raeburn 5350: table.LC_nested tr.LC_info_row td.LC_left_item,
5351: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5352: text-align: left;
1.451 albertel 5353: }
1.795 www 5354:
1.507 raeburn 5355: table.LC_nested td {
1.735 bisitz 5356: background-color: #FFFFFF;
1.451 albertel 5357: font-size: small;
1.507 raeburn 5358: }
1.795 www 5359:
1.507 raeburn 5360: table.LC_nested_outer tr th.LC_right_item,
5361: table.LC_nested tr.LC_info_row td.LC_right_item,
5362: table.LC_nested tr.LC_odd_row td.LC_right_item,
5363: table.LC_nested tr td.LC_right_item {
1.451 albertel 5364: text-align: right;
5365: }
5366:
1.930 faziophi 5367: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5368: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5369: text-align: right;
5370: width: 40%;
5371: padding-right:10px;
5372: vertical-align: top;
5373: padding: 5px;
5374: }
5375:
5376: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5377: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5378: text-align: left;
5379: width: 60%;
5380: padding: 2px 4px;
5381: }
5382:
1.507 raeburn 5383: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5384: background-color: #EEEEEE;
1.451 albertel 5385: }
5386:
1.473 raeburn 5387: table.LC_createuser {
5388: }
5389:
5390: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5391: font-size: small;
1.473 raeburn 5392: }
5393:
5394: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5395: background-color: #CCCCCC;
1.473 raeburn 5396: font-weight: bold;
5397: text-align: center;
5398: }
5399:
1.349 albertel 5400: table.LC_calendar {
5401: border: 1px solid #000000;
5402: border-collapse: collapse;
1.917 raeburn 5403: width: 98%;
1.349 albertel 5404: }
1.795 www 5405:
1.349 albertel 5406: table.LC_calendar_pickdate {
5407: font-size: xx-small;
5408: }
1.795 www 5409:
1.349 albertel 5410: table.LC_calendar tr td {
5411: border: 1px solid #000000;
5412: vertical-align: top;
1.917 raeburn 5413: width: 14%;
1.349 albertel 5414: }
1.795 www 5415:
1.349 albertel 5416: table.LC_calendar tr td.LC_calendar_day_empty {
5417: background-color: $data_table_dark;
5418: }
1.795 www 5419:
1.779 bisitz 5420: table.LC_calendar tr td.LC_calendar_day_current {
5421: background-color: $data_table_highlight;
1.777 tempelho 5422: }
1.795 www 5423:
1.938 bisitz 5424: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5425: background-color: $mail_new;
5426: }
1.795 www 5427:
1.938 bisitz 5428: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5429: background-color: $mail_new_hover;
5430: }
1.795 www 5431:
1.938 bisitz 5432: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5433: background-color: $mail_read;
5434: }
1.795 www 5435:
1.938 bisitz 5436: /*
5437: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5438: background-color: $mail_read_hover;
5439: }
1.938 bisitz 5440: */
1.795 www 5441:
1.938 bisitz 5442: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5443: background-color: $mail_replied;
5444: }
1.795 www 5445:
1.938 bisitz 5446: /*
5447: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5448: background-color: $mail_replied_hover;
5449: }
1.938 bisitz 5450: */
1.795 www 5451:
1.938 bisitz 5452: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5453: background-color: $mail_other;
5454: }
1.795 www 5455:
1.938 bisitz 5456: /*
5457: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5458: background-color: $mail_other_hover;
5459: }
1.938 bisitz 5460: */
1.494 raeburn 5461:
1.777 tempelho 5462: table.LC_data_table tr > td.LC_browser_file,
5463: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5464: background: #AAEE77;
1.389 albertel 5465: }
1.795 www 5466:
1.777 tempelho 5467: table.LC_data_table tr > td.LC_browser_file_locked,
5468: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5469: background: #FFAA99;
1.387 albertel 5470: }
1.795 www 5471:
1.777 tempelho 5472: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5473: background: #888888;
1.779 bisitz 5474: }
1.795 www 5475:
1.777 tempelho 5476: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5477: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5478: background: #F8F866;
1.777 tempelho 5479: }
1.795 www 5480:
1.696 bisitz 5481: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5482: background: #E0E8FF;
1.387 albertel 5483: }
1.696 bisitz 5484:
1.707 bisitz 5485: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5486: /* background: #77FF77; */
1.707 bisitz 5487: }
1.795 www 5488:
1.707 bisitz 5489: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5490: border-right: 8px solid #FFFF77;
1.707 bisitz 5491: }
1.795 www 5492:
1.707 bisitz 5493: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5494: border-right: 8px solid #FFAA77;
1.707 bisitz 5495: }
1.795 www 5496:
1.707 bisitz 5497: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5498: border-right: 8px solid #FF7777;
1.707 bisitz 5499: }
1.795 www 5500:
1.707 bisitz 5501: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5502: border-right: 8px solid #AAFF77;
1.707 bisitz 5503: }
1.795 www 5504:
1.707 bisitz 5505: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5506: border-right: 8px solid #11CC55;
1.707 bisitz 5507: }
5508:
1.388 albertel 5509: span.LC_current_location {
1.701 harmsja 5510: font-size:larger;
1.388 albertel 5511: background: $pgbg;
5512: }
1.387 albertel 5513:
1.395 albertel 5514: span.LC_parm_menu_item {
5515: font-size: larger;
5516: }
1.795 www 5517:
1.395 albertel 5518: span.LC_parm_scope_all {
5519: color: red;
5520: }
1.795 www 5521:
1.395 albertel 5522: span.LC_parm_scope_folder {
5523: color: green;
5524: }
1.795 www 5525:
1.395 albertel 5526: span.LC_parm_scope_resource {
5527: color: orange;
5528: }
1.795 www 5529:
1.395 albertel 5530: span.LC_parm_part {
5531: color: blue;
5532: }
1.795 www 5533:
1.911 bisitz 5534: span.LC_parm_folder,
5535: span.LC_parm_symb {
1.395 albertel 5536: font-size: x-small;
5537: font-family: $mono;
5538: color: #AAAAAA;
5539: }
5540:
1.948.2.8 raeburn 5541: ul.LC_parm_parmlist li {
5542: display: inline-block;
5543: padding: 0.3em 0.8em;
5544: vertical-align: top;
5545: width: 150px;
5546: border-top:1px solid $lg_border_color;
5547: }
5548:
1.795 www 5549: td.LC_parm_overview_level_menu,
5550: td.LC_parm_overview_map_menu,
5551: td.LC_parm_overview_parm_selectors,
5552: td.LC_parm_overview_restrictions {
1.396 albertel 5553: border: 1px solid black;
5554: border-collapse: collapse;
5555: }
1.795 www 5556:
1.396 albertel 5557: table.LC_parm_overview_restrictions td {
5558: border-width: 1px 4px 1px 4px;
5559: border-style: solid;
5560: border-color: $pgbg;
5561: text-align: center;
5562: }
1.795 www 5563:
1.396 albertel 5564: table.LC_parm_overview_restrictions th {
5565: background: $tabbg;
5566: border-width: 1px 4px 1px 4px;
5567: border-style: solid;
5568: border-color: $pgbg;
5569: }
1.795 www 5570:
1.398 albertel 5571: table#LC_helpmenu {
1.803 bisitz 5572: border: none;
1.398 albertel 5573: height: 55px;
1.803 bisitz 5574: border-spacing: 0;
1.398 albertel 5575: }
5576:
5577: table#LC_helpmenu fieldset legend {
5578: font-size: larger;
5579: }
1.795 www 5580:
1.397 albertel 5581: table#LC_helpmenu_links {
5582: width: 100%;
5583: border: 1px solid black;
5584: background: $pgbg;
1.803 bisitz 5585: padding: 0;
1.397 albertel 5586: border-spacing: 1px;
5587: }
1.795 www 5588:
1.397 albertel 5589: table#LC_helpmenu_links tr td {
5590: padding: 1px;
5591: background: $tabbg;
1.399 albertel 5592: text-align: center;
5593: font-weight: bold;
1.397 albertel 5594: }
1.396 albertel 5595:
1.795 www 5596: table#LC_helpmenu_links a:link,
5597: table#LC_helpmenu_links a:visited,
1.397 albertel 5598: table#LC_helpmenu_links a:active {
5599: text-decoration: none;
5600: color: $font;
5601: }
1.795 www 5602:
1.397 albertel 5603: table#LC_helpmenu_links a:hover {
5604: text-decoration: underline;
5605: color: $vlink;
5606: }
1.396 albertel 5607:
1.417 albertel 5608: .LC_chrt_popup_exists {
5609: border: 1px solid #339933;
5610: margin: -1px;
5611: }
1.795 www 5612:
1.417 albertel 5613: .LC_chrt_popup_up {
5614: border: 1px solid yellow;
5615: margin: -1px;
5616: }
1.795 www 5617:
1.417 albertel 5618: .LC_chrt_popup {
5619: border: 1px solid #8888FF;
5620: background: #CCCCFF;
5621: }
1.795 www 5622:
1.421 albertel 5623: table.LC_pick_box {
5624: border-collapse: separate;
5625: background: white;
5626: border: 1px solid black;
5627: border-spacing: 1px;
5628: }
1.795 www 5629:
1.421 albertel 5630: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5631: background: $sidebg;
1.421 albertel 5632: font-weight: bold;
1.900 bisitz 5633: text-align: left;
1.740 bisitz 5634: vertical-align: top;
1.421 albertel 5635: width: 184px;
5636: padding: 8px;
5637: }
1.795 www 5638:
1.579 raeburn 5639: table.LC_pick_box td.LC_pick_box_value {
5640: text-align: left;
5641: padding: 8px;
5642: }
1.795 www 5643:
1.579 raeburn 5644: table.LC_pick_box td.LC_pick_box_select {
5645: text-align: left;
5646: padding: 8px;
5647: }
1.795 www 5648:
1.424 albertel 5649: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5650: padding: 0;
1.421 albertel 5651: height: 1px;
5652: background: black;
5653: }
1.795 www 5654:
1.421 albertel 5655: table.LC_pick_box td.LC_pick_box_submit {
5656: text-align: right;
5657: }
1.795 www 5658:
1.579 raeburn 5659: table.LC_pick_box td.LC_evenrow_value {
5660: text-align: left;
5661: padding: 8px;
5662: background-color: $data_table_light;
5663: }
1.795 www 5664:
1.579 raeburn 5665: table.LC_pick_box td.LC_oddrow_value {
5666: text-align: left;
5667: padding: 8px;
5668: background-color: $data_table_light;
5669: }
1.795 www 5670:
1.579 raeburn 5671: span.LC_helpform_receipt_cat {
5672: font-weight: bold;
5673: }
1.795 www 5674:
1.424 albertel 5675: table.LC_group_priv_box {
5676: background: white;
5677: border: 1px solid black;
5678: border-spacing: 1px;
5679: }
1.795 www 5680:
1.424 albertel 5681: table.LC_group_priv_box td.LC_pick_box_title {
5682: background: $tabbg;
5683: font-weight: bold;
5684: text-align: right;
5685: width: 184px;
5686: }
1.795 www 5687:
1.424 albertel 5688: table.LC_group_priv_box td.LC_groups_fixed {
5689: background: $data_table_light;
5690: text-align: center;
5691: }
1.795 www 5692:
1.424 albertel 5693: table.LC_group_priv_box td.LC_groups_optional {
5694: background: $data_table_dark;
5695: text-align: center;
5696: }
1.795 www 5697:
1.424 albertel 5698: table.LC_group_priv_box td.LC_groups_functionality {
5699: background: $data_table_darker;
5700: text-align: center;
5701: font-weight: bold;
5702: }
1.795 www 5703:
1.424 albertel 5704: table.LC_group_priv td {
5705: text-align: left;
1.803 bisitz 5706: padding: 0;
1.424 albertel 5707: }
5708:
1.421 albertel 5709: table.LC_notify_front_page {
5710: background: white;
5711: border: 1px solid black;
5712: padding: 8px;
5713: }
1.795 www 5714:
1.421 albertel 5715: table.LC_notify_front_page td {
5716: padding: 8px;
5717: }
1.795 www 5718:
1.424 albertel 5719: .LC_navbuttons {
5720: margin: 2ex 0ex 2ex 0ex;
5721: }
1.795 www 5722:
1.423 albertel 5723: .LC_topic_bar {
5724: font-weight: bold;
5725: background: $tabbg;
1.918 wenzelju 5726: margin: 1em 0em 1em 2em;
1.805 bisitz 5727: padding: 3px;
1.918 wenzelju 5728: font-size: 1.2em;
1.423 albertel 5729: }
1.795 www 5730:
1.423 albertel 5731: .LC_topic_bar span {
1.918 wenzelju 5732: left: 0.5em;
5733: position: absolute;
1.423 albertel 5734: vertical-align: middle;
1.918 wenzelju 5735: font-size: 1.2em;
1.423 albertel 5736: }
1.795 www 5737:
1.423 albertel 5738: table.LC_course_group_status {
5739: margin: 20px;
5740: }
1.795 www 5741:
1.423 albertel 5742: table.LC_status_selector td {
5743: vertical-align: top;
5744: text-align: center;
1.424 albertel 5745: padding: 4px;
5746: }
1.795 www 5747:
1.599 albertel 5748: div.LC_feedback_link {
1.616 albertel 5749: clear: both;
1.829 kalberla 5750: background: $sidebg;
1.779 bisitz 5751: width: 100%;
1.829 kalberla 5752: padding-bottom: 10px;
5753: border: 1px $tabbg solid;
1.833 kalberla 5754: height: 22px;
5755: line-height: 22px;
5756: padding-top: 5px;
5757: }
5758:
5759: div.LC_feedback_link img {
5760: height: 22px;
1.867 kalberla 5761: vertical-align:middle;
1.829 kalberla 5762: }
5763:
1.911 bisitz 5764: div.LC_feedback_link a {
1.829 kalberla 5765: text-decoration: none;
1.489 raeburn 5766: }
1.795 www 5767:
1.867 kalberla 5768: div.LC_comblock {
1.911 bisitz 5769: display:inline;
1.867 kalberla 5770: color:$font;
5771: font-size:90%;
5772: }
5773:
5774: div.LC_feedback_link div.LC_comblock {
5775: padding-left:5px;
5776: }
5777:
5778: div.LC_feedback_link div.LC_comblock a {
5779: color:$font;
5780: }
5781:
1.489 raeburn 5782: span.LC_feedback_link {
1.858 bisitz 5783: /* background: $feedback_link_bg; */
1.599 albertel 5784: font-size: larger;
5785: }
1.795 www 5786:
1.599 albertel 5787: span.LC_message_link {
1.858 bisitz 5788: /* background: $feedback_link_bg; */
1.599 albertel 5789: font-size: larger;
5790: position: absolute;
5791: right: 1em;
1.489 raeburn 5792: }
1.421 albertel 5793:
1.515 albertel 5794: table.LC_prior_tries {
1.524 albertel 5795: border: 1px solid #000000;
5796: border-collapse: separate;
5797: border-spacing: 1px;
1.515 albertel 5798: }
1.523 albertel 5799:
1.515 albertel 5800: table.LC_prior_tries td {
1.524 albertel 5801: padding: 2px;
1.515 albertel 5802: }
1.523 albertel 5803:
5804: .LC_answer_correct {
1.795 www 5805: background: lightgreen;
5806: color: darkgreen;
5807: padding: 6px;
1.523 albertel 5808: }
1.795 www 5809:
1.523 albertel 5810: .LC_answer_charged_try {
1.797 www 5811: background: #FFAAAA;
1.795 www 5812: color: darkred;
5813: padding: 6px;
1.523 albertel 5814: }
1.795 www 5815:
1.779 bisitz 5816: .LC_answer_not_charged_try,
1.523 albertel 5817: .LC_answer_no_grade,
5818: .LC_answer_late {
1.795 www 5819: background: lightyellow;
1.523 albertel 5820: color: black;
1.795 www 5821: padding: 6px;
1.523 albertel 5822: }
1.795 www 5823:
1.523 albertel 5824: .LC_answer_previous {
1.795 www 5825: background: lightblue;
5826: color: darkblue;
5827: padding: 6px;
1.523 albertel 5828: }
1.795 www 5829:
1.779 bisitz 5830: .LC_answer_no_message {
1.777 tempelho 5831: background: #FFFFFF;
5832: color: black;
1.795 www 5833: padding: 6px;
1.779 bisitz 5834: }
1.795 www 5835:
1.779 bisitz 5836: .LC_answer_unknown {
5837: background: orange;
5838: color: black;
1.795 www 5839: padding: 6px;
1.777 tempelho 5840: }
1.795 www 5841:
1.529 albertel 5842: span.LC_prior_numerical,
5843: span.LC_prior_string,
5844: span.LC_prior_custom,
5845: span.LC_prior_reaction,
5846: span.LC_prior_math {
1.925 bisitz 5847: font-family: $mono;
1.523 albertel 5848: white-space: pre;
5849: }
5850:
1.525 albertel 5851: span.LC_prior_string {
1.925 bisitz 5852: font-family: $mono;
1.525 albertel 5853: white-space: pre;
5854: }
5855:
1.523 albertel 5856: table.LC_prior_option {
5857: width: 100%;
5858: border-collapse: collapse;
5859: }
1.795 www 5860:
1.911 bisitz 5861: table.LC_prior_rank,
1.795 www 5862: table.LC_prior_match {
1.528 albertel 5863: border-collapse: collapse;
5864: }
1.795 www 5865:
1.528 albertel 5866: table.LC_prior_option tr td,
5867: table.LC_prior_rank tr td,
5868: table.LC_prior_match tr td {
1.524 albertel 5869: border: 1px solid #000000;
1.515 albertel 5870: }
5871:
1.855 bisitz 5872: .LC_nobreak {
1.544 albertel 5873: white-space: nowrap;
1.519 raeburn 5874: }
5875:
1.576 raeburn 5876: span.LC_cusr_emph {
5877: font-style: italic;
5878: }
5879:
1.633 raeburn 5880: span.LC_cusr_subheading {
5881: font-weight: normal;
5882: font-size: 85%;
5883: }
5884:
1.861 bisitz 5885: div.LC_docs_entry_move {
1.859 bisitz 5886: border: 1px solid #BBBBBB;
1.545 albertel 5887: background: #DDDDDD;
1.861 bisitz 5888: width: 22px;
1.859 bisitz 5889: padding: 1px;
5890: margin: 0;
1.545 albertel 5891: }
5892:
1.861 bisitz 5893: table.LC_data_table tr > td.LC_docs_entry_commands,
5894: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5895: background: #DDDDDD;
5896: font-size: x-small;
5897: }
1.795 www 5898:
1.861 bisitz 5899: .LC_docs_entry_parameter {
5900: white-space: nowrap;
5901: }
5902:
1.544 albertel 5903: .LC_docs_copy {
1.545 albertel 5904: color: #000099;
1.544 albertel 5905: }
1.795 www 5906:
1.544 albertel 5907: .LC_docs_cut {
1.545 albertel 5908: color: #550044;
1.544 albertel 5909: }
1.795 www 5910:
1.544 albertel 5911: .LC_docs_rename {
1.545 albertel 5912: color: #009900;
1.544 albertel 5913: }
1.795 www 5914:
1.544 albertel 5915: .LC_docs_remove {
1.545 albertel 5916: color: #990000;
5917: }
5918:
1.547 albertel 5919: .LC_docs_reinit_warn,
5920: .LC_docs_ext_edit {
5921: font-size: x-small;
5922: }
5923:
1.545 albertel 5924: table.LC_docs_adddocs td,
5925: table.LC_docs_adddocs th {
5926: border: 1px solid #BBBBBB;
5927: padding: 4px;
5928: background: #DDDDDD;
1.543 albertel 5929: }
5930:
1.584 albertel 5931: table.LC_sty_begin {
5932: background: #BBFFBB;
5933: }
1.795 www 5934:
1.584 albertel 5935: table.LC_sty_end {
5936: background: #FFBBBB;
5937: }
5938:
1.589 raeburn 5939: table.LC_double_column {
1.803 bisitz 5940: border-width: 0;
1.589 raeburn 5941: border-collapse: collapse;
5942: width: 100%;
5943: padding: 2px;
5944: }
5945:
5946: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5947: top: 2px;
1.589 raeburn 5948: left: 2px;
5949: width: 47%;
5950: vertical-align: top;
5951: }
5952:
5953: table.LC_double_column tr td.LC_right_col {
5954: top: 2px;
1.779 bisitz 5955: right: 2px;
1.589 raeburn 5956: width: 47%;
5957: vertical-align: top;
5958: }
5959:
1.591 raeburn 5960: div.LC_left_float {
5961: float: left;
5962: padding-right: 5%;
1.597 albertel 5963: padding-bottom: 4px;
1.591 raeburn 5964: }
5965:
5966: div.LC_clear_float_header {
1.597 albertel 5967: padding-bottom: 2px;
1.591 raeburn 5968: }
5969:
5970: div.LC_clear_float_footer {
1.597 albertel 5971: padding-top: 10px;
1.591 raeburn 5972: clear: both;
5973: }
5974:
1.597 albertel 5975: div.LC_grade_show_user {
1.941 bisitz 5976: /* border-left: 5px solid $sidebg; */
5977: border-top: 5px solid #000000;
5978: margin: 50px 0 0 0;
1.936 bisitz 5979: padding: 15px 0 5px 10px;
1.597 albertel 5980: }
1.795 www 5981:
1.936 bisitz 5982: div.LC_grade_show_user_odd_row {
1.941 bisitz 5983: /* border-left: 5px solid #000000; */
5984: }
5985:
5986: div.LC_grade_show_user div.LC_Box {
5987: margin-right: 50px;
1.597 albertel 5988: }
5989:
5990: div.LC_grade_submissions,
5991: div.LC_grade_message_center,
1.936 bisitz 5992: div.LC_grade_info_links {
1.597 albertel 5993: margin: 5px;
5994: width: 99%;
5995: background: #FFFFFF;
5996: }
1.795 www 5997:
1.597 albertel 5998: div.LC_grade_submissions_header,
1.936 bisitz 5999: div.LC_grade_message_center_header {
1.705 tempelho 6000: font-weight: bold;
6001: font-size: large;
1.597 albertel 6002: }
1.795 www 6003:
1.597 albertel 6004: div.LC_grade_submissions_body,
1.936 bisitz 6005: div.LC_grade_message_center_body {
1.597 albertel 6006: border: 1px solid black;
6007: width: 99%;
6008: background: #FFFFFF;
6009: }
1.795 www 6010:
1.613 albertel 6011: table.LC_scantron_action {
6012: width: 100%;
6013: }
1.795 www 6014:
1.613 albertel 6015: table.LC_scantron_action tr th {
1.698 harmsja 6016: font-weight:bold;
6017: font-style:normal;
1.613 albertel 6018: }
1.795 www 6019:
1.779 bisitz 6020: .LC_edit_problem_header,
1.614 albertel 6021: div.LC_edit_problem_footer {
1.705 tempelho 6022: font-weight: normal;
6023: font-size: medium;
1.602 albertel 6024: margin: 2px;
1.600 albertel 6025: }
1.795 www 6026:
1.600 albertel 6027: div.LC_edit_problem_header,
1.602 albertel 6028: div.LC_edit_problem_header div,
1.614 albertel 6029: div.LC_edit_problem_footer,
6030: div.LC_edit_problem_footer div,
1.602 albertel 6031: div.LC_edit_problem_editxml_header,
6032: div.LC_edit_problem_editxml_header div {
1.600 albertel 6033: margin-top: 5px;
6034: }
1.795 www 6035:
1.600 albertel 6036: div.LC_edit_problem_header_title {
1.705 tempelho 6037: font-weight: bold;
6038: font-size: larger;
1.602 albertel 6039: background: $tabbg;
6040: padding: 3px;
6041: }
1.795 www 6042:
1.602 albertel 6043: table.LC_edit_problem_header_title {
6044: width: 100%;
1.600 albertel 6045: background: $tabbg;
1.602 albertel 6046: }
6047:
6048: div.LC_edit_problem_discards {
6049: float: left;
6050: padding-bottom: 5px;
6051: }
1.795 www 6052:
1.602 albertel 6053: div.LC_edit_problem_saves {
6054: float: right;
6055: padding-bottom: 5px;
1.600 albertel 6056: }
1.795 www 6057:
1.911 bisitz 6058: img.stift {
1.803 bisitz 6059: border-width: 0;
6060: vertical-align: middle;
1.677 riegler 6061: }
1.680 riegler 6062:
1.923 bisitz 6063: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6064: vertical-align: top;
1.777 tempelho 6065: }
1.795 www 6066:
1.716 raeburn 6067: div.LC_createcourse {
1.911 bisitz 6068: margin: 10px 10px 10px 10px;
1.716 raeburn 6069: }
6070:
1.917 raeburn 6071: .LC_dccid {
6072: margin: 0.2em 0 0 0;
6073: padding: 0;
6074: font-size: 90%;
6075: display:none;
6076: }
6077:
1.698 harmsja 6078: a:hover,
1.897 wenzelju 6079: ol.LC_primary_menu a:hover,
1.721 harmsja 6080: ol#LC_MenuBreadcrumbs a:hover,
6081: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6082: ul#LC_secondary_menu a:hover,
1.721 harmsja 6083: .LC_FormSectionClearButton input:hover
1.795 www 6084: ul.LC_TabContent li:hover a {
1.948.2.1 raeburn 6085: color:$button_hover;
1.911 bisitz 6086: text-decoration:none;
1.693 droeschl 6087: }
6088:
1.779 bisitz 6089: h1 {
1.911 bisitz 6090: padding: 0;
6091: line-height:130%;
1.693 droeschl 6092: }
1.698 harmsja 6093:
1.911 bisitz 6094: h2,
6095: h3,
6096: h4,
6097: h5,
6098: h6 {
6099: margin: 5px 0 5px 0;
6100: padding: 0;
6101: line-height:130%;
1.693 droeschl 6102: }
1.795 www 6103:
6104: .LC_hcell {
1.911 bisitz 6105: padding:3px 15px 3px 15px;
6106: margin: 0;
6107: background-color:$tabbg;
6108: color:$fontmenu;
6109: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6110: }
1.795 www 6111:
1.840 bisitz 6112: .LC_Box > .LC_hcell {
1.911 bisitz 6113: margin: 0 -10px 10px -10px;
1.835 bisitz 6114: }
6115:
1.721 harmsja 6116: .LC_noBorder {
1.911 bisitz 6117: border: 0;
1.698 harmsja 6118: }
1.693 droeschl 6119:
1.721 harmsja 6120: .LC_FormSectionClearButton input {
1.911 bisitz 6121: background-color:transparent;
6122: border: none;
6123: cursor:pointer;
6124: text-decoration:underline;
1.693 droeschl 6125: }
1.763 bisitz 6126:
6127: .LC_help_open_topic {
1.911 bisitz 6128: color: #FFFFFF;
6129: background-color: #EEEEFF;
6130: margin: 1px;
6131: padding: 4px;
6132: border: 1px solid #000033;
6133: white-space: nowrap;
6134: /* vertical-align: middle; */
1.759 neumanie 6135: }
1.693 droeschl 6136:
1.911 bisitz 6137: dl,
6138: ul,
6139: div,
6140: fieldset {
6141: margin: 10px 10px 10px 0;
6142: /* overflow: hidden; */
1.693 droeschl 6143: }
1.795 www 6144:
1.838 bisitz 6145: fieldset > legend {
1.911 bisitz 6146: font-weight: bold;
6147: padding: 0 5px 0 5px;
1.838 bisitz 6148: }
6149:
1.813 bisitz 6150: #LC_nav_bar {
1.911 bisitz 6151: float: left;
1.948.2.24! raeburn 6152: background-color: $pgbg_or_bgcolor;
1.948.2.6 raeburn 6153: margin: 0 0 2px 0;
1.807 droeschl 6154: }
6155:
1.916 droeschl 6156: #LC_realm {
6157: margin: 0.2em 0 0 0;
6158: padding: 0;
6159: font-weight: bold;
6160: text-align: center;
1.948.2.24! raeburn 6161: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6162: }
6163:
1.911 bisitz 6164: #LC_nav_bar em {
6165: font-weight: bold;
6166: font-style: normal;
1.807 droeschl 6167: }
6168:
1.948.2.6 raeburn 6169: /* Preliminary fix to hide nav_bar inside bookmarks window */
6170: #LC_bookmarks #LC_nav_bar {
6171: display:none;
6172: }
6173:
1.897 wenzelju 6174: ol.LC_primary_menu {
1.911 bisitz 6175: float: right;
1.934 droeschl 6176: margin: 0;
1.948.2.24! raeburn 6177: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6178: }
6179:
1.929 wenzelju 6180: span.LC_new_message{
6181: font-weight:bold;
6182: color: darkred;
6183: }
6184:
1.852 droeschl 6185: ol#LC_PathBreadcrumbs {
1.911 bisitz 6186: margin: 0;
1.693 droeschl 6187: }
6188:
1.897 wenzelju 6189: ol.LC_primary_menu li {
1.911 bisitz 6190: display: inline;
6191: padding: 5px 5px 0 10px;
6192: vertical-align: top;
1.693 droeschl 6193: }
6194:
1.897 wenzelju 6195: ol.LC_primary_menu li img {
1.911 bisitz 6196: vertical-align: bottom;
1.934 droeschl 6197: height: 1.1em;
1.693 droeschl 6198: }
6199:
1.897 wenzelju 6200: ol.LC_primary_menu a {
1.911 bisitz 6201: color: RGB(80, 80, 80);
6202: text-decoration: none;
1.693 droeschl 6203: }
1.795 www 6204:
1.948.2.7 raeburn 6205: ol.LC_docs_parameters {
6206: margin-left: 0;
6207: padding: 0;
6208: list-style: none;
6209: }
6210:
6211: ol.LC_docs_parameters li {
6212: margin: 0;
6213: padding-right: 20px;
6214: display: inline;
6215: }
6216:
6217: ol.LC_docs_parameters li:before {
6218: content: "\\002022 \\0020";
6219: }
6220:
6221: li.LC_docs_parameters_title {
6222: font-weight: bold;
6223: }
6224:
6225: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6226: content: "";
6227: }
6228:
1.897 wenzelju 6229: ul#LC_secondary_menu {
1.911 bisitz 6230: clear: both;
6231: color: $fontmenu;
6232: background: $tabbg;
6233: list-style: none;
6234: padding: 0;
6235: margin: 0;
6236: width: 100%;
1.948.2.24! raeburn 6237: text-align: left;
1.808 droeschl 6238: }
6239:
1.897 wenzelju 6240: ul#LC_secondary_menu li {
1.911 bisitz 6241: font-weight: bold;
6242: line-height: 1.8em;
6243: padding: 0 0.8em;
6244: border-right: 1px solid black;
6245: display: inline;
6246: vertical-align: middle;
1.807 droeschl 6247: }
6248:
1.847 tempelho 6249: ul.LC_TabContent {
1.911 bisitz 6250: display:block;
6251: background: $sidebg;
6252: border-bottom: solid 1px $lg_border_color;
6253: list-style:none;
6254: margin: 0 -10px;
6255: padding: 0;
1.693 droeschl 6256: }
6257:
1.795 www 6258: ul.LC_TabContent li,
6259: ul.LC_TabContentBigger li {
1.911 bisitz 6260: float:left;
1.741 harmsja 6261: }
1.795 www 6262:
1.897 wenzelju 6263: ul#LC_secondary_menu li a {
1.911 bisitz 6264: color: $fontmenu;
6265: text-decoration: none;
1.693 droeschl 6266: }
1.795 www 6267:
1.721 harmsja 6268: ul.LC_TabContent {
1.948.2.1 raeburn 6269: min-height:20px;
1.721 harmsja 6270: }
1.795 www 6271:
6272: ul.LC_TabContent li {
1.911 bisitz 6273: vertical-align:middle;
1.948.2.3 raeburn 6274: padding: 0 16px 0 10px;
1.911 bisitz 6275: background-color:$tabbg;
6276: border-bottom:solid 1px $lg_border_color;
1.948.2.1 raeburn 6277: border-right: solid 1px $font;
1.721 harmsja 6278: }
1.795 www 6279:
1.847 tempelho 6280: ul.LC_TabContent .right {
1.911 bisitz 6281: float:right;
1.847 tempelho 6282: }
6283:
1.911 bisitz 6284: ul.LC_TabContent li a,
6285: ul.LC_TabContent li {
6286: color:rgb(47,47,47);
6287: text-decoration:none;
6288: font-size:95%;
6289: font-weight:bold;
1.948.2.1 raeburn 6290: min-height:20px;
6291: }
6292:
1.948.2.3 raeburn 6293: ul.LC_TabContent li a:hover,
6294: ul.LC_TabContent li a:focus {
1.948.2.1 raeburn 6295: color: $button_hover;
1.948.2.3 raeburn 6296: background:none;
6297: outline:none;
1.948.2.1 raeburn 6298: }
6299:
6300: ul.LC_TabContent li:hover {
6301: color: $button_hover;
6302: cursor:pointer;
1.721 harmsja 6303: }
1.795 www 6304:
1.911 bisitz 6305: ul.LC_TabContent li.active {
1.948.2.1 raeburn 6306: color: $font;
1.911 bisitz 6307: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.948.2.1 raeburn 6308: border-bottom:solid 1px #FFFFFF;
6309: cursor: default;
1.744 ehlerst 6310: }
1.795 www 6311:
1.948.2.3 raeburn 6312: ul.LC_TabContent li.active a {
6313: color:$font;
6314: background:#FFFFFF;
6315: outline: none;
6316: }
1.870 tempelho 6317: #maincoursedoc {
1.911 bisitz 6318: clear:both;
1.870 tempelho 6319: }
6320:
6321: ul.LC_TabContentBigger {
1.911 bisitz 6322: display:block;
6323: list-style:none;
6324: padding: 0;
1.870 tempelho 6325: }
6326:
1.795 www 6327: ul.LC_TabContentBigger li {
1.911 bisitz 6328: vertical-align:bottom;
6329: height: 30px;
6330: font-size:110%;
6331: font-weight:bold;
6332: color: #737373;
1.841 tempelho 6333: }
6334:
1.948.2.3 raeburn 6335: ul.LC_TabContentBigger li.active {
6336: position: relative;
6337: top: 1px;
6338: }
1.870 tempelho 6339:
6340: ul.LC_TabContentBigger li a {
1.911 bisitz 6341: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6342: height: 30px;
6343: line-height: 30px;
6344: text-align: center;
6345: display: block;
6346: text-decoration: none;
1.948.2.3 raeburn 6347: outline: none;
1.741 harmsja 6348: }
1.795 www 6349:
1.870 tempelho 6350: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6351: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6352: color:$font;
1.744 ehlerst 6353: }
1.795 www 6354:
1.870 tempelho 6355: ul.LC_TabContentBigger li b {
1.911 bisitz 6356: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6357: display: block;
6358: float: left;
6359: padding: 0 30px;
1.948.2.3 raeburn 6360: border-bottom: 1px solid $lg_border_color;
6361: }
6362:
6363: ul.LC_TabContentBigger li:hover b {
6364: color:$button_hover;
1.870 tempelho 6365: }
6366:
6367: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6368: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6369: color:$font;
1.948.2.3 raeburn 6370: border: 0;
6371: cursor:default;
1.741 harmsja 6372: }
1.693 droeschl 6373:
1.862 bisitz 6374: ul.LC_CourseBreadcrumbs {
6375: background: $sidebg;
6376: line-height: 32px;
6377: padding-left: 10px;
6378: margin: 0 0 10px 0;
6379: list-style-position: inside;
6380:
6381: }
6382:
1.911 bisitz 6383: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6384: ol#LC_PathBreadcrumbs {
1.911 bisitz 6385: padding-left: 10px;
6386: margin: 0;
1.933 droeschl 6387: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6388: }
6389:
1.911 bisitz 6390: ol#LC_MenuBreadcrumbs li,
6391: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6392: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6393: display: inline;
1.933 droeschl 6394: white-space: normal;
1.693 droeschl 6395: }
6396:
1.823 bisitz 6397: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6398: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6399: text-decoration: none;
6400: font-size:90%;
1.693 droeschl 6401: }
1.795 www 6402:
1.948.2.7 raeburn 6403: ol#LC_MenuBreadcrumbs h1 {
6404: display: inline;
6405: font-size: 90%;
6406: line-height: 2.5em;
6407: margin: 0;
6408: padding: 0;
6409: }
6410:
1.795 www 6411: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6412: text-decoration:none;
6413: font-size:100%;
6414: font-weight:bold;
1.693 droeschl 6415: }
1.795 www 6416:
1.840 bisitz 6417: .LC_Box {
1.911 bisitz 6418: border: solid 1px $lg_border_color;
6419: padding: 0 10px 10px 10px;
1.746 neumanie 6420: }
1.795 www 6421:
6422: .LC_AboutMe_Image {
1.911 bisitz 6423: float:left;
6424: margin-right:10px;
1.747 neumanie 6425: }
1.795 www 6426:
6427: .LC_Clear_AboutMe_Image {
1.911 bisitz 6428: clear:left;
1.747 neumanie 6429: }
1.795 www 6430:
1.721 harmsja 6431: dl.LC_ListStyleClean dt {
1.911 bisitz 6432: padding-right: 5px;
6433: display: table-header-group;
1.693 droeschl 6434: }
6435:
1.721 harmsja 6436: dl.LC_ListStyleClean dd {
1.911 bisitz 6437: display: table-row;
1.693 droeschl 6438: }
6439:
1.721 harmsja 6440: .LC_ListStyleClean,
6441: .LC_ListStyleSimple,
6442: .LC_ListStyleNormal,
1.795 www 6443: .LC_ListStyleSpecial {
1.911 bisitz 6444: /* display:block; */
6445: list-style-position: inside;
6446: list-style-type: none;
6447: overflow: hidden;
6448: padding: 0;
1.693 droeschl 6449: }
6450:
1.721 harmsja 6451: .LC_ListStyleSimple li,
6452: .LC_ListStyleSimple dd,
6453: .LC_ListStyleNormal li,
6454: .LC_ListStyleNormal dd,
6455: .LC_ListStyleSpecial li,
1.795 www 6456: .LC_ListStyleSpecial dd {
1.911 bisitz 6457: margin: 0;
6458: padding: 5px 5px 5px 10px;
6459: clear: both;
1.693 droeschl 6460: }
6461:
1.721 harmsja 6462: .LC_ListStyleClean li,
6463: .LC_ListStyleClean dd {
1.911 bisitz 6464: padding-top: 0;
6465: padding-bottom: 0;
1.693 droeschl 6466: }
6467:
1.721 harmsja 6468: .LC_ListStyleSimple dd,
1.795 www 6469: .LC_ListStyleSimple li {
1.911 bisitz 6470: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6471: }
6472:
1.721 harmsja 6473: .LC_ListStyleSpecial li,
6474: .LC_ListStyleSpecial dd {
1.911 bisitz 6475: list-style-type: none;
6476: background-color: RGB(220, 220, 220);
6477: margin-bottom: 4px;
1.693 droeschl 6478: }
6479:
1.721 harmsja 6480: table.LC_SimpleTable {
1.911 bisitz 6481: margin:5px;
6482: border:solid 1px $lg_border_color;
1.795 www 6483: }
1.693 droeschl 6484:
1.721 harmsja 6485: table.LC_SimpleTable tr {
1.911 bisitz 6486: padding: 0;
6487: border:solid 1px $lg_border_color;
1.693 droeschl 6488: }
1.795 www 6489:
6490: table.LC_SimpleTable thead {
1.911 bisitz 6491: background:rgb(220,220,220);
1.693 droeschl 6492: }
6493:
1.721 harmsja 6494: div.LC_columnSection {
1.911 bisitz 6495: display: block;
6496: clear: both;
6497: overflow: hidden;
6498: margin: 0;
1.693 droeschl 6499: }
6500:
1.721 harmsja 6501: div.LC_columnSection>* {
1.911 bisitz 6502: float: left;
6503: margin: 10px 20px 10px 0;
6504: overflow:hidden;
1.693 droeschl 6505: }
1.721 harmsja 6506:
1.795 www 6507: table em {
1.911 bisitz 6508: font-weight: bold;
6509: font-style: normal;
1.748 schulted 6510: }
1.795 www 6511:
1.779 bisitz 6512: table.LC_tableBrowseRes,
1.795 www 6513: table.LC_tableOfContent {
1.911 bisitz 6514: border:none;
6515: border-spacing: 1px;
6516: padding: 3px;
6517: background-color: #FFFFFF;
6518: font-size: 90%;
1.753 droeschl 6519: }
1.789 droeschl 6520:
1.911 bisitz 6521: table.LC_tableOfContent {
6522: border-collapse: collapse;
1.789 droeschl 6523: }
6524:
1.771 droeschl 6525: table.LC_tableBrowseRes a,
1.768 schulted 6526: table.LC_tableOfContent a {
1.911 bisitz 6527: background-color: transparent;
6528: text-decoration: none;
1.753 droeschl 6529: }
6530:
1.795 www 6531: table.LC_tableOfContent img {
1.911 bisitz 6532: border: none;
6533: height: 1.3em;
6534: vertical-align: text-bottom;
6535: margin-right: 0.3em;
1.753 droeschl 6536: }
1.757 schulted 6537:
1.795 www 6538: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6539: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6540: }
6541:
1.795 www 6542: a#LC_content_toolbar_launchnav {
1.911 bisitz 6543: background-image:url(/res/adm/pages/start-navigation.gif);
1.774 ehlerst 6544: }
6545:
1.795 www 6546: a#LC_content_toolbar_closenav {
1.911 bisitz 6547: background-image:url(/res/adm/pages/close-navigation.gif);
1.774 ehlerst 6548: }
6549:
1.795 www 6550: a#LC_content_toolbar_everything {
1.911 bisitz 6551: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6552: }
6553:
1.795 www 6554: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6555: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6556: }
6557:
1.795 www 6558: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6559: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6560: }
6561:
1.795 www 6562: a#LC_content_toolbar_changefolder {
1.911 bisitz 6563: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6564: }
6565:
1.795 www 6566: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6567: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6568: }
6569:
1.795 www 6570: ul#LC_toolbar li a:hover {
1.911 bisitz 6571: background-position: bottom center;
1.757 schulted 6572: }
6573:
1.795 www 6574: ul#LC_toolbar {
1.911 bisitz 6575: padding: 0;
6576: margin: 2px;
6577: list-style:none;
6578: position:relative;
6579: background-color:white;
1.757 schulted 6580: }
6581:
1.795 www 6582: ul#LC_toolbar li {
1.911 bisitz 6583: border:1px solid white;
6584: padding: 0;
6585: margin: 0;
6586: float: left;
6587: display:inline;
6588: vertical-align:middle;
6589: }
1.757 schulted 6590:
1.783 amueller 6591:
1.795 www 6592: a.LC_toolbarItem {
1.911 bisitz 6593: display:block;
6594: padding: 0;
6595: margin: 0;
6596: height: 32px;
6597: width: 32px;
6598: color:white;
6599: border: none;
6600: background-repeat:no-repeat;
6601: background-color:transparent;
1.757 schulted 6602: }
6603:
1.915 droeschl 6604: ul.LC_funclist {
6605: margin: 0;
6606: padding: 0.5em 1em 0.5em 0;
6607: }
6608:
1.933 droeschl 6609: ul.LC_funclist > li:first-child {
6610: font-weight:bold;
6611: margin-left:0.8em;
6612: }
6613:
1.915 droeschl 6614: ul.LC_funclist + ul.LC_funclist {
6615: /*
6616: left border as a seperator if we have more than
6617: one list
6618: */
6619: border-left: 1px solid $sidebg;
6620: /*
6621: this hides the left border behind the border of the
6622: outer box if element is wrapped to the next 'line'
6623: */
6624: margin-left: -1px;
6625: }
6626:
1.843 bisitz 6627: ul.LC_funclist li {
1.915 droeschl 6628: display: inline;
1.782 bisitz 6629: white-space: nowrap;
1.915 droeschl 6630: margin: 0 0 0 25px;
6631: line-height: 150%;
1.782 bisitz 6632: }
6633:
1.930 faziophi 6634: .ui-accordion .LC_advanced_toggle {
6635: float: right;
6636: font-size: 90%;
6637: padding: 0px 4px
6638: }
1.757 schulted 6639:
1.343 albertel 6640: END
6641: }
6642:
1.306 albertel 6643: =pod
6644:
6645: =item * &headtag()
6646:
6647: Returns a uniform footer for LON-CAPA web pages.
6648:
1.307 albertel 6649: Inputs: $title - optional title for the head
6650: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6651: $args - optional arguments
1.319 albertel 6652: force_register - if is true call registerurl so the remote is
6653: informed
1.415 albertel 6654: redirect -> array ref of
6655: 1- seconds before redirect occurs
6656: 2- url to redirect to
6657: 3- whether the side effect should occur
1.315 albertel 6658: (side effect of setting
6659: $env{'internal.head.redirect'} to the url
6660: redirected too)
1.352 albertel 6661: domain -> force to color decorate a page for a specific
6662: domain
6663: function -> force usage of a specific rolish color scheme
6664: bgcolor -> override the default page bgcolor
1.460 albertel 6665: no_auto_mt_title
6666: -> prevent &mt()ing the title arg
1.464 albertel 6667:
1.306 albertel 6668: =cut
6669:
6670: sub headtag {
1.313 albertel 6671: my ($title,$head_extra,$args) = @_;
1.306 albertel 6672:
1.363 albertel 6673: my $function = $args->{'function'} || &get_users_function();
6674: my $domain = $args->{'domain'} || &determinedomain();
6675: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6676: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6677: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6678: #time(),
1.418 albertel 6679: $env{'environment.color.timestamp'},
1.363 albertel 6680: $function,$domain,$bgcolor);
6681:
1.369 www 6682: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6683:
1.308 albertel 6684: my $result =
6685: '<head>'.
1.461 albertel 6686: &font_settings();
1.319 albertel 6687:
1.461 albertel 6688: if (!$args->{'frameset'}) {
6689: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6690: }
1.319 albertel 6691: if ($args->{'force_register'}) {
6692: $result .= &Apache::lonmenu::registerurl(1);
6693: }
1.436 albertel 6694: if (!$args->{'no_nav_bar'}
6695: && !$args->{'only_body'}
6696: && !$args->{'frameset'}) {
6697: $result .= &help_menu_js();
6698: }
1.319 albertel 6699:
1.314 albertel 6700: if (ref($args->{'redirect'})) {
1.414 albertel 6701: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6702: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6703: if (!$inhibit_continue) {
6704: $env{'internal.head.redirect'} = $url;
6705: }
1.313 albertel 6706: $result.=<<ADDMETA
6707: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6708: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6709: ADDMETA
6710: }
1.306 albertel 6711: if (!defined($title)) {
6712: $title = 'The LearningOnline Network with CAPA';
6713: }
1.460 albertel 6714: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6715: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6716: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6717: .$head_extra;
1.306 albertel 6718: return $result;
6719: }
6720:
6721: =pod
6722:
1.340 albertel 6723: =item * &font_settings()
6724:
6725: Returns neccessary <meta> to set the proper encoding
6726:
6727: Inputs: none
6728:
6729: =cut
6730:
6731: sub font_settings {
6732: my $headerstring='';
1.647 www 6733: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6734: $headerstring.=
6735: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6736: }
6737: return $headerstring;
6738: }
6739:
1.341 albertel 6740: =pod
6741:
6742: =item * &xml_begin()
6743:
6744: Returns the needed doctype and <html>
6745:
6746: Inputs: none
6747:
6748: =cut
6749:
6750: sub xml_begin {
6751: my $output='';
6752:
6753: if ($env{'browser.mathml'}) {
6754: $output='<?xml version="1.0"?>'
6755: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6756: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6757:
6758: # .'<!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">] >'
6759: .'<!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">'
6760: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6761: .'xmlns="http://www.w3.org/1999/xhtml">';
6762: } else {
1.849 bisitz 6763: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6764: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6765: }
6766: return $output;
6767: }
1.340 albertel 6768:
6769: =pod
6770:
1.306 albertel 6771: =item * &endheadtag()
6772:
6773: Returns a uniform </head> for LON-CAPA web pages.
6774:
6775: Inputs: none
6776:
6777: =cut
6778:
6779: sub endheadtag {
6780: return '</head>';
6781: }
6782:
6783: =pod
6784:
6785: =item * &head()
6786:
6787: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6788:
1.648 raeburn 6789: Inputs:
6790:
6791: =over 4
6792:
6793: $title - optional title for the page
6794:
6795: $head_extra - optional extra HTML to put inside the <head>
6796:
6797: =back
1.405 albertel 6798:
1.306 albertel 6799: =cut
6800:
6801: sub head {
1.325 albertel 6802: my ($title,$head_extra,$args) = @_;
6803: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6804: }
6805:
6806: =pod
6807:
6808: =item * &start_page()
6809:
6810: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6811:
1.648 raeburn 6812: Inputs:
6813:
6814: =over 4
6815:
6816: $title - optional title for the page
6817:
6818: $head_extra - optional extra HTML to incude inside the <head>
6819:
6820: $args - additional optional args supported are:
6821:
6822: =over 8
6823:
6824: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6825: arg on
1.814 bisitz 6826: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6827: add_entries -> additional attributes to add to the <body>
6828: domain -> force to color decorate a page for a
1.317 albertel 6829: specific domain
1.648 raeburn 6830: function -> force usage of a specific rolish color
1.317 albertel 6831: scheme
1.648 raeburn 6832: redirect -> see &headtag()
6833: bgcolor -> override the default page bg color
6834: js_ready -> return a string ready for being used in
1.317 albertel 6835: a javascript writeln
1.648 raeburn 6836: html_encode -> return a string ready for being used in
1.320 albertel 6837: a html attribute
1.648 raeburn 6838: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6839: $forcereg arg
1.648 raeburn 6840: frameset -> if true will start with a <frameset>
1.330 albertel 6841: rather than <body>
1.648 raeburn 6842: skip_phases -> hash ref of
1.338 albertel 6843: head -> skip the <html><head> generation
6844: body -> skip all <body> generation
1.648 raeburn 6845: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6846: 'Switch To Inline Menu' link
1.648 raeburn 6847: no_auto_mt_title -> prevent &mt()ing the title arg
6848: inherit_jsmath -> when creating popup window in a page,
6849: should it have jsmath forced on by the
6850: current page
1.867 kalberla 6851: bread_crumbs -> Array containing breadcrumbs
1.948.2.12 raeburn 6852: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6853:
1.648 raeburn 6854: =back
1.460 albertel 6855:
1.648 raeburn 6856: =back
1.562 albertel 6857:
1.306 albertel 6858: =cut
6859:
6860: sub start_page {
1.309 albertel 6861: my ($title,$head_extra,$args) = @_;
1.318 albertel 6862: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6863: my %head_args;
1.352 albertel 6864: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6865: 'bgcolor','frameset','no_nav_bar','only_body',
6866: 'no_auto_mt_title') {
1.319 albertel 6867: if (defined($args->{$arg})) {
1.324 raeburn 6868: $head_args{$arg} = $args->{$arg};
1.319 albertel 6869: }
1.313 albertel 6870: }
1.319 albertel 6871:
1.315 albertel 6872: $env{'internal.start_page'}++;
1.338 albertel 6873: my $result;
6874: if (! exists($args->{'skip_phases'}{'head'}) ) {
6875: $result.=
1.341 albertel 6876: &xml_begin().
1.338 albertel 6877: &headtag($title,$head_extra,\%head_args).&endheadtag();
6878: }
6879:
6880: if (! exists($args->{'skip_phases'}{'body'}) ) {
6881: if ($args->{'frameset'}) {
6882: my $attr_string = &make_attr_string($args->{'force_register'},
6883: $args->{'add_entries'});
6884: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6885: } else {
6886: $result .=
6887: &bodytag($title,
6888: $args->{'function'}, $args->{'add_entries'},
6889: $args->{'only_body'}, $args->{'domain'},
6890: $args->{'force_register'}, $args->{'no_nav_bar'},
6891: $args->{'bgcolor'}, $args->{'no_inline_link'},
6892: $args);
6893: }
1.330 albertel 6894: }
1.338 albertel 6895:
1.315 albertel 6896: if ($args->{'js_ready'}) {
1.713 kaisler 6897: $result = &js_ready($result);
1.315 albertel 6898: }
1.320 albertel 6899: if ($args->{'html_encode'}) {
1.713 kaisler 6900: $result = &html_encode($result);
6901: }
6902:
1.813 bisitz 6903: # Preparation for new and consistent functionlist at top of screen
6904: # if ($args->{'functionlist'}) {
6905: # $result .= &build_functionlist();
6906: #}
6907:
6908: # Don't add anything more if only_body wanted
6909: return $result if $args->{'only_body'};
6910:
1.920 raeburn 6911: #Breadcrumbs for Construction Space provided by &bodytag.
6912: if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
6913: return $result;
6914: }
6915:
1.813 bisitz 6916: #Breadcrumbs
1.758 kaisler 6917: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6918: &Apache::lonhtmlcommon::clear_breadcrumbs();
6919: #if any br links exists, add them to the breadcrumbs
6920: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6921: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6922: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6923: }
6924: }
6925:
6926: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6927: if(exists($args->{'bread_crumbs_component'})){
6928: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6929: }else{
6930: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6931: }
1.320 albertel 6932: }
1.315 albertel 6933: return $result;
1.306 albertel 6934: }
6935:
1.330 albertel 6936:
1.306 albertel 6937: =pod
6938:
6939: =item * &head()
6940:
6941: Returns a complete </body></html> section for LON-CAPA web pages.
6942:
1.315 albertel 6943: Inputs: $args - additional optional args supported are:
6944: js_ready -> return a string ready for being used in
6945: a javascript writeln
1.320 albertel 6946: html_encode -> return a string ready for being used in
6947: a html attribute
1.330 albertel 6948: frameset -> if true will start with a <frameset>
6949: rather than <body>
1.493 albertel 6950: dicsussion -> if true will get discussion from
6951: lonxml::xmlend
6952: (you can pass the target and parser arguments
6953: through optional 'target' and 'parser' args
6954: to this routine)
1.306 albertel 6955:
6956: =cut
6957:
6958: sub end_page {
1.315 albertel 6959: my ($args) = @_;
6960: $env{'internal.end_page'}++;
1.330 albertel 6961: my $result;
1.335 albertel 6962: if ($args->{'discussion'}) {
6963: my ($target,$parser);
6964: if (ref($args->{'discussion'})) {
6965: ($target,$parser) =($args->{'discussion'}{'target'},
6966: $args->{'discussion'}{'parser'});
6967: }
6968: $result .= &Apache::lonxml::xmlend($target,$parser);
6969: }
6970:
1.330 albertel 6971: if ($args->{'frameset'}) {
6972: $result .= '</frameset>';
6973: } else {
1.635 raeburn 6974: $result .= &endbodytag($args);
1.330 albertel 6975: }
6976: $result .= "\n</html>";
6977:
1.315 albertel 6978: if ($args->{'js_ready'}) {
1.317 albertel 6979: $result = &js_ready($result);
1.315 albertel 6980: }
1.335 albertel 6981:
1.320 albertel 6982: if ($args->{'html_encode'}) {
6983: $result = &html_encode($result);
6984: }
1.335 albertel 6985:
1.315 albertel 6986: return $result;
6987: }
6988:
1.320 albertel 6989: sub html_encode {
6990: my ($result) = @_;
6991:
1.322 albertel 6992: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6993:
6994: return $result;
6995: }
1.317 albertel 6996: sub js_ready {
6997: my ($result) = @_;
6998:
1.323 albertel 6999: $result =~ s/[\n\r]/ /xmsg;
7000: $result =~ s/\\/\\\\/xmsg;
7001: $result =~ s/'/\\'/xmsg;
1.372 albertel 7002: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7003:
7004: return $result;
7005: }
7006:
1.315 albertel 7007: sub validate_page {
7008: if ( exists($env{'internal.start_page'})
1.316 albertel 7009: && $env{'internal.start_page'} > 1) {
7010: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7011: $env{'internal.start_page'}.' '.
1.316 albertel 7012: $ENV{'request.filename'});
1.315 albertel 7013: }
7014: if ( exists($env{'internal.end_page'})
1.316 albertel 7015: && $env{'internal.end_page'} > 1) {
7016: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7017: $env{'internal.end_page'}.' '.
1.316 albertel 7018: $env{'request.filename'});
1.315 albertel 7019: }
7020: if ( exists($env{'internal.start_page'})
7021: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7022: &Apache::lonnet::logthis('start_page called without end_page '.
7023: $env{'request.filename'});
1.315 albertel 7024: }
7025: if ( ! exists($env{'internal.start_page'})
7026: && exists($env{'internal.end_page'})) {
1.316 albertel 7027: &Apache::lonnet::logthis('end_page called without start_page'.
7028: $env{'request.filename'});
1.315 albertel 7029: }
1.306 albertel 7030: }
1.315 albertel 7031:
1.318 albertel 7032: sub simple_error_page {
7033: my ($r,$title,$msg) = @_;
7034: my $page =
7035: &Apache::loncommon::start_page($title).
7036: &mt($msg).
7037: &Apache::loncommon::end_page();
7038: if (ref($r)) {
7039: $r->print($page);
1.327 albertel 7040: return;
1.318 albertel 7041: }
7042: return $page;
7043: }
1.347 albertel 7044:
7045: {
1.610 albertel 7046: my @row_count;
1.948.2.5 raeburn 7047:
7048: sub start_data_table_count {
7049: unshift(@row_count, 0);
7050: return;
7051: }
7052:
7053: sub end_data_table_count {
7054: shift(@row_count);
7055: return;
7056: }
7057:
1.347 albertel 7058: sub start_data_table {
1.422 albertel 7059: my ($add_class) = @_;
7060: my $css_class = (join(' ','LC_data_table',$add_class));
1.948.2.5 raeburn 7061: &start_data_table_count();
1.422 albertel 7062: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 7063: }
7064:
7065: sub end_data_table {
1.948.2.5 raeburn 7066: &end_data_table_count();
1.389 albertel 7067: return '</table>'."\n";;
1.347 albertel 7068: }
7069:
7070: sub start_data_table_row {
1.422 albertel 7071: my ($add_class) = @_;
1.610 albertel 7072: $row_count[0]++;
7073: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7074: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 7075: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 7076: }
1.471 banghart 7077:
7078: sub continue_data_table_row {
7079: my ($add_class) = @_;
1.610 albertel 7080: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7081: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 7082: return '<tr class="'.$css_class.'">'."\n";;
7083: }
1.347 albertel 7084:
7085: sub end_data_table_row {
1.389 albertel 7086: return '</tr>'."\n";;
1.347 albertel 7087: }
1.367 www 7088:
1.421 albertel 7089: sub start_data_table_empty_row {
1.707 bisitz 7090: # $row_count[0]++;
1.421 albertel 7091: return '<tr class="LC_empty_row" >'."\n";;
7092: }
7093:
7094: sub end_data_table_empty_row {
7095: return '</tr>'."\n";;
7096: }
7097:
1.367 www 7098: sub start_data_table_header_row {
1.389 albertel 7099: return '<tr class="LC_header_row">'."\n";;
1.367 www 7100: }
7101:
7102: sub end_data_table_header_row {
1.389 albertel 7103: return '</tr>'."\n";;
1.367 www 7104: }
1.890 droeschl 7105:
7106: sub data_table_caption {
7107: my $caption = shift;
7108: return "<caption class=\"LC_caption\">$caption</caption>";
7109: }
1.347 albertel 7110: }
7111:
1.548 albertel 7112: =pod
7113:
7114: =item * &inhibit_menu_check($arg)
7115:
7116: Checks for a inhibitmenu state and generates output to preserve it
7117:
7118: Inputs: $arg - can be any of
7119: - undef - in which case the return value is a string
7120: to add into arguments list of a uri
7121: - 'input' - in which case the return value is a HTML
7122: <form> <input> field of type hidden to
7123: preserve the value
7124: - a url - in which case the return value is the url with
7125: the neccesary cgi args added to preserve the
7126: inhibitmenu state
7127: - a ref to a url - no return value, but the string is
7128: updated to include the neccessary cgi
7129: args to preserve the inhibitmenu state
7130:
7131: =cut
7132:
7133: sub inhibit_menu_check {
7134: my ($arg) = @_;
7135: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7136: if ($arg eq 'input') {
7137: if ($env{'form.inhibitmenu'}) {
7138: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7139: } else {
7140: return
7141: }
7142: }
7143: if ($env{'form.inhibitmenu'}) {
7144: if (ref($arg)) {
7145: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7146: } elsif ($arg eq '') {
7147: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7148: } else {
7149: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7150: }
7151: }
7152: if (!ref($arg)) {
7153: return $arg;
7154: }
7155: }
7156:
1.251 albertel 7157: ###############################################
1.182 matthew 7158:
7159: =pod
7160:
1.549 albertel 7161: =back
7162:
7163: =head1 User Information Routines
7164:
7165: =over 4
7166:
1.405 albertel 7167: =item * &get_users_function()
1.182 matthew 7168:
7169: Used by &bodytag to determine the current users primary role.
7170: Returns either 'student','coordinator','admin', or 'author'.
7171:
7172: =cut
7173:
7174: ###############################################
7175: sub get_users_function {
1.815 tempelho 7176: my $function = 'norole';
1.818 tempelho 7177: if ($env{'request.role'}=~/^(st)/) {
7178: $function='student';
7179: }
1.907 raeburn 7180: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7181: $function='coordinator';
7182: }
1.258 albertel 7183: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7184: $function='admin';
7185: }
1.826 bisitz 7186: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7187: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7188: $function='author';
7189: }
7190: return $function;
1.54 www 7191: }
1.99 www 7192:
7193: ###############################################
7194:
1.233 raeburn 7195: =pod
7196:
1.821 raeburn 7197: =item * &show_course()
7198:
7199: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7200: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7201:
7202: Inputs:
7203: None
7204:
7205: Outputs:
7206: Scalar: 1 if 'Course' to be used, 0 otherwise.
7207:
7208: =cut
7209:
7210: ###############################################
7211: sub show_course {
7212: my $course = !$env{'user.adv'};
7213: if (!$env{'user.adv'}) {
7214: foreach my $env (keys(%env)) {
7215: next if ($env !~ m/^user\.priv\./);
7216: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7217: $course = 0;
7218: last;
7219: }
7220: }
7221: }
7222: return $course;
7223: }
7224:
7225: ###############################################
7226:
7227: =pod
7228:
1.542 raeburn 7229: =item * &check_user_status()
1.274 raeburn 7230:
7231: Determines current status of supplied role for a
7232: specific user. Roles can be active, previous or future.
7233:
7234: Inputs:
7235: user's domain, user's username, course's domain,
1.375 raeburn 7236: course's number, optional section ID.
1.274 raeburn 7237:
7238: Outputs:
7239: role status: active, previous or future.
7240:
7241: =cut
7242:
7243: sub check_user_status {
1.412 raeburn 7244: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.948.2.11 raeburn 7245: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7246: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7247: my @uroles = keys %userinfo;
7248: my $srchstr;
7249: my $active_chk = 'none';
1.412 raeburn 7250: my $now = time;
1.274 raeburn 7251: if (@uroles > 0) {
1.908 raeburn 7252: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7253: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7254: } else {
1.412 raeburn 7255: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7256: }
7257: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7258: my $role_end = 0;
7259: my $role_start = 0;
7260: $active_chk = 'active';
1.412 raeburn 7261: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7262: $role_end = $1;
7263: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7264: $role_start = $1;
1.274 raeburn 7265: }
7266: }
7267: if ($role_start > 0) {
1.412 raeburn 7268: if ($now < $role_start) {
1.274 raeburn 7269: $active_chk = 'future';
7270: }
7271: }
7272: if ($role_end > 0) {
1.412 raeburn 7273: if ($now > $role_end) {
1.274 raeburn 7274: $active_chk = 'previous';
7275: }
7276: }
7277: }
7278: }
7279: return $active_chk;
7280: }
7281:
7282: ###############################################
7283:
7284: =pod
7285:
1.405 albertel 7286: =item * &get_sections()
1.233 raeburn 7287:
7288: Determines all the sections for a course including
7289: sections with students and sections containing other roles.
1.419 raeburn 7290: Incoming parameters:
7291:
7292: 1. domain
7293: 2. course number
7294: 3. reference to array containing roles for which sections should
7295: be gathered (optional).
7296: 4. reference to array containing status types for which sections
7297: should be gathered (optional).
7298:
7299: If the third argument is undefined, sections are gathered for any role.
7300: If the fourth argument is undefined, sections are gathered for any status.
7301: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7302:
1.374 raeburn 7303: Returns section hash (keys are section IDs, values are
7304: number of users in each section), subject to the
1.419 raeburn 7305: optional roles filter, optional status filter
1.233 raeburn 7306:
7307: =cut
7308:
7309: ###############################################
7310: sub get_sections {
1.419 raeburn 7311: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7312: if (!defined($cdom) || !defined($cnum)) {
7313: my $cid = $env{'request.course.id'};
7314:
7315: return if (!defined($cid));
7316:
7317: $cdom = $env{'course.'.$cid.'.domain'};
7318: $cnum = $env{'course.'.$cid.'.num'};
7319: }
7320:
7321: my %sectioncount;
1.419 raeburn 7322: my $now = time;
1.240 albertel 7323:
1.366 albertel 7324: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7325: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7326: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7327: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7328: my $start_index = &Apache::loncoursedata::CL_START();
7329: my $end_index = &Apache::loncoursedata::CL_END();
7330: my $status;
1.366 albertel 7331: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7332: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7333: $data->[$status_index],
7334: $data->[$start_index],
7335: $data->[$end_index]);
7336: if ($stu_status eq 'Active') {
7337: $status = 'active';
7338: } elsif ($end < $now) {
7339: $status = 'previous';
7340: } elsif ($start > $now) {
7341: $status = 'future';
7342: }
7343: if ($section ne '-1' && $section !~ /^\s*$/) {
7344: if ((!defined($possible_status)) || (($status ne '') &&
7345: (grep/^\Q$status\E$/,@{$possible_status}))) {
7346: $sectioncount{$section}++;
7347: }
1.240 albertel 7348: }
7349: }
7350: }
7351: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7352: foreach my $user (sort(keys(%courseroles))) {
7353: if ($user !~ /^(\w{2})/) { next; }
7354: my ($role) = ($user =~ /^(\w{2})/);
7355: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7356: my ($section,$status);
1.240 albertel 7357: if ($role eq 'cr' &&
7358: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7359: $section=$1;
7360: }
7361: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7362: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7363: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7364: if ($end == -1 && $start == -1) {
7365: next; #deleted role
7366: }
7367: if (!defined($possible_status)) {
7368: $sectioncount{$section}++;
7369: } else {
7370: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7371: $status = 'active';
7372: } elsif ($end < $now) {
7373: $status = 'future';
7374: } elsif ($start > $now) {
7375: $status = 'previous';
7376: }
7377: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7378: $sectioncount{$section}++;
7379: }
7380: }
1.233 raeburn 7381: }
1.366 albertel 7382: return %sectioncount;
1.233 raeburn 7383: }
7384:
1.274 raeburn 7385: ###############################################
1.294 raeburn 7386:
7387: =pod
1.405 albertel 7388:
7389: =item * &get_course_users()
7390:
1.275 raeburn 7391: Retrieves usernames:domains for users in the specified course
7392: with specific role(s), and access status.
7393:
7394: Incoming parameters:
1.277 albertel 7395: 1. course domain
7396: 2. course number
7397: 3. access status: users must have - either active,
1.275 raeburn 7398: previous, future, or all.
1.277 albertel 7399: 4. reference to array of permissible roles
1.288 raeburn 7400: 5. reference to array of section restrictions (optional)
7401: 6. reference to results object (hash of hashes).
7402: 7. reference to optional userdata hash
1.609 raeburn 7403: 8. reference to optional statushash
1.630 raeburn 7404: 9. flag if privileged users (except those set to unhide in
7405: course settings) should be excluded
1.609 raeburn 7406: Keys of top level results hash are roles.
1.275 raeburn 7407: Keys of inner hashes are username:domain, with
7408: values set to access type.
1.288 raeburn 7409: Optional userdata hash returns an array with arguments in the
7410: same order as loncoursedata::get_classlist() for student data.
7411:
1.609 raeburn 7412: Optional statushash returns
7413:
1.288 raeburn 7414: Entries for end, start, section and status are blank because
7415: of the possibility of multiple values for non-student roles.
7416:
1.275 raeburn 7417: =cut
1.405 albertel 7418:
1.275 raeburn 7419: ###############################################
1.405 albertel 7420:
1.275 raeburn 7421: sub get_course_users {
1.630 raeburn 7422: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7423: my %idx = ();
1.419 raeburn 7424: my %seclists;
1.288 raeburn 7425:
7426: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7427: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7428: $idx{end} = &Apache::loncoursedata::CL_END();
7429: $idx{start} = &Apache::loncoursedata::CL_START();
7430: $idx{id} = &Apache::loncoursedata::CL_ID();
7431: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7432: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7433: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7434:
1.290 albertel 7435: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7436: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7437: my $now = time;
1.277 albertel 7438: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7439: my $match = 0;
1.412 raeburn 7440: my $secmatch = 0;
1.419 raeburn 7441: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7442: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7443: if ($section eq '') {
7444: $section = 'none';
7445: }
1.291 albertel 7446: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7447: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7448: $secmatch = 1;
7449: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7450: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7451: $secmatch = 1;
7452: }
7453: } else {
1.419 raeburn 7454: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7455: $secmatch = 1;
7456: }
1.290 albertel 7457: }
1.412 raeburn 7458: if (!$secmatch) {
7459: next;
7460: }
1.419 raeburn 7461: }
1.275 raeburn 7462: if (defined($$types{'active'})) {
1.288 raeburn 7463: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7464: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7465: $match = 1;
1.275 raeburn 7466: }
7467: }
7468: if (defined($$types{'previous'})) {
1.609 raeburn 7469: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7470: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7471: $match = 1;
1.275 raeburn 7472: }
7473: }
7474: if (defined($$types{'future'})) {
1.609 raeburn 7475: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7476: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7477: $match = 1;
1.275 raeburn 7478: }
7479: }
1.609 raeburn 7480: if ($match) {
7481: push(@{$seclists{$student}},$section);
7482: if (ref($userdata) eq 'HASH') {
7483: $$userdata{$student} = $$classlist{$student};
7484: }
7485: if (ref($statushash) eq 'HASH') {
7486: $statushash->{$student}{'st'}{$section} = $status;
7487: }
1.288 raeburn 7488: }
1.275 raeburn 7489: }
7490: }
1.412 raeburn 7491: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7492: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7493: my $now = time;
1.609 raeburn 7494: my %displaystatus = ( previous => 'Expired',
7495: active => 'Active',
7496: future => 'Future',
7497: );
1.630 raeburn 7498: my %nothide;
7499: if ($hidepriv) {
7500: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7501: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7502: if ($user !~ /:/) {
7503: $nothide{join(':',split(/[\@]/,$user))}=1;
7504: } else {
7505: $nothide{$user} = 1;
7506: }
7507: }
7508: }
1.439 raeburn 7509: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7510: my $match = 0;
1.412 raeburn 7511: my $secmatch = 0;
1.439 raeburn 7512: my $status;
1.412 raeburn 7513: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7514: $user =~ s/:$//;
1.439 raeburn 7515: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7516: if ($end == -1 || $start == -1) {
7517: next;
7518: }
7519: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7520: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7521: my ($uname,$udom) = split(/:/,$user);
7522: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7523: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7524: $secmatch = 1;
7525: } elsif ($usec eq '') {
1.420 albertel 7526: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7527: $secmatch = 1;
7528: }
7529: } else {
7530: if (grep(/^\Q$usec\E$/,@{$sections})) {
7531: $secmatch = 1;
7532: }
7533: }
7534: if (!$secmatch) {
7535: next;
7536: }
1.288 raeburn 7537: }
1.419 raeburn 7538: if ($usec eq '') {
7539: $usec = 'none';
7540: }
1.275 raeburn 7541: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7542: if ($hidepriv) {
7543: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7544: (!$nothide{$uname.':'.$udom})) {
7545: next;
7546: }
7547: }
1.503 raeburn 7548: if ($end > 0 && $end < $now) {
1.439 raeburn 7549: $status = 'previous';
7550: } elsif ($start > $now) {
7551: $status = 'future';
7552: } else {
7553: $status = 'active';
7554: }
1.277 albertel 7555: foreach my $type (keys(%{$types})) {
1.275 raeburn 7556: if ($status eq $type) {
1.420 albertel 7557: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7558: push(@{$$users{$role}{$user}},$type);
7559: }
1.288 raeburn 7560: $match = 1;
7561: }
7562: }
1.419 raeburn 7563: if (($match) && (ref($userdata) eq 'HASH')) {
7564: if (!exists($$userdata{$uname.':'.$udom})) {
7565: &get_user_info($udom,$uname,\%idx,$userdata);
7566: }
1.420 albertel 7567: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7568: push(@{$seclists{$uname.':'.$udom}},$usec);
7569: }
1.609 raeburn 7570: if (ref($statushash) eq 'HASH') {
7571: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7572: }
1.275 raeburn 7573: }
7574: }
7575: }
7576: }
1.290 albertel 7577: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7578: if ((defined($cdom)) && (defined($cnum))) {
7579: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7580: if ( defined($csettings{'internal.courseowner'}) ) {
7581: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7582: next if ($owner eq '');
7583: my ($ownername,$ownerdom);
7584: if ($owner =~ /^([^:]+):([^:]+)$/) {
7585: $ownername = $1;
7586: $ownerdom = $2;
7587: } else {
7588: $ownername = $owner;
7589: $ownerdom = $cdom;
7590: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7591: }
7592: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7593: if (defined($userdata) &&
1.609 raeburn 7594: !exists($$userdata{$owner})) {
7595: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7596: if (!grep(/^none$/,@{$seclists{$owner}})) {
7597: push(@{$seclists{$owner}},'none');
7598: }
7599: if (ref($statushash) eq 'HASH') {
7600: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7601: }
1.290 albertel 7602: }
1.279 raeburn 7603: }
7604: }
7605: }
1.419 raeburn 7606: foreach my $user (keys(%seclists)) {
7607: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7608: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7609: }
1.275 raeburn 7610: }
7611: return;
7612: }
7613:
1.288 raeburn 7614: sub get_user_info {
7615: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7616: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7617: &plainname($uname,$udom,'lastname');
1.291 albertel 7618: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7619: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7620: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7621: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7622: return;
7623: }
1.275 raeburn 7624:
1.472 raeburn 7625: ###############################################
7626:
7627: =pod
7628:
7629: =item * &get_user_quota()
7630:
7631: Retrieves quota assigned for storage of portfolio files for a user
7632:
7633: Incoming parameters:
7634: 1. user's username
7635: 2. user's domain
7636:
7637: Returns:
1.536 raeburn 7638: 1. Disk quota (in Mb) assigned to student.
7639: 2. (Optional) Type of setting: custom or default
7640: (individually assigned or default for user's
7641: institutional status).
7642: 3. (Optional) - User's institutional status (e.g., faculty, staff
7643: or student - types as defined in localenroll::inst_usertypes
7644: for user's domain, which determines default quota for user.
7645: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7646:
7647: If a value has been stored in the user's environment,
1.536 raeburn 7648: it will return that, otherwise it returns the maximal default
7649: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7650:
7651: =cut
7652:
7653: ###############################################
7654:
7655:
7656: sub get_user_quota {
7657: my ($uname,$udom) = @_;
1.536 raeburn 7658: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7659: if (!defined($udom)) {
7660: $udom = $env{'user.domain'};
7661: }
7662: if (!defined($uname)) {
7663: $uname = $env{'user.name'};
7664: }
7665: if (($udom eq '' || $uname eq '') ||
7666: ($udom eq 'public') && ($uname eq 'public')) {
7667: $quota = 0;
1.536 raeburn 7668: $quotatype = 'default';
7669: $defquota = 0;
1.472 raeburn 7670: } else {
1.536 raeburn 7671: my $inststatus;
1.472 raeburn 7672: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7673: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7674: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7675: } else {
1.536 raeburn 7676: my %userenv =
7677: &Apache::lonnet::get('environment',['portfolioquota',
7678: 'inststatus'],$udom,$uname);
1.472 raeburn 7679: my ($tmp) = keys(%userenv);
7680: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7681: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7682: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7683: } else {
7684: undef(%userenv);
7685: }
7686: }
1.536 raeburn 7687: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7688: if ($quota eq '') {
1.536 raeburn 7689: $quota = $defquota;
7690: $quotatype = 'default';
7691: } else {
7692: $quotatype = 'custom';
1.472 raeburn 7693: }
7694: }
1.536 raeburn 7695: if (wantarray) {
7696: return ($quota,$quotatype,$settingstatus,$defquota);
7697: } else {
7698: return $quota;
7699: }
1.472 raeburn 7700: }
7701:
7702: ###############################################
7703:
7704: =pod
7705:
7706: =item * &default_quota()
7707:
1.536 raeburn 7708: Retrieves default quota assigned for storage of user portfolio files,
7709: given an (optional) user's institutional status.
1.472 raeburn 7710:
7711: Incoming parameters:
7712: 1. domain
1.536 raeburn 7713: 2. (Optional) institutional status(es). This is a : separated list of
7714: status types (e.g., faculty, staff, student etc.)
7715: which apply to the user for whom the default is being retrieved.
7716: If the institutional status string in undefined, the domain
7717: default quota will be returned.
1.472 raeburn 7718:
7719: Returns:
7720: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7721: 2. (Optional) institutional type which determined the value of the
7722: default quota.
1.472 raeburn 7723:
7724: If a value has been stored in the domain's configuration db,
7725: it will return that, otherwise it returns 20 (for backwards
7726: compatibility with domains which have not set up a configuration
7727: db file; the original statically defined portfolio quota was 20 Mb).
7728:
1.536 raeburn 7729: If the user's status includes multiple types (e.g., staff and student),
7730: the largest default quota which applies to the user determines the
7731: default quota returned.
7732:
1.780 raeburn 7733: =back
7734:
1.472 raeburn 7735: =cut
7736:
7737: ###############################################
7738:
7739:
7740: sub default_quota {
1.536 raeburn 7741: my ($udom,$inststatus) = @_;
7742: my ($defquota,$settingstatus);
7743: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7744: ['quotas'],$udom);
7745: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7746: if ($inststatus ne '') {
1.765 raeburn 7747: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7748: foreach my $item (@statuses) {
1.711 raeburn 7749: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7750: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7751: if ($defquota eq '') {
7752: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7753: $settingstatus = $item;
7754: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7755: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7756: $settingstatus = $item;
7757: }
7758: }
7759: } else {
7760: if ($quotahash{'quotas'}{$item} ne '') {
7761: if ($defquota eq '') {
7762: $defquota = $quotahash{'quotas'}{$item};
7763: $settingstatus = $item;
7764: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7765: $defquota = $quotahash{'quotas'}{$item};
7766: $settingstatus = $item;
7767: }
1.536 raeburn 7768: }
7769: }
7770: }
7771: }
7772: if ($defquota eq '') {
1.711 raeburn 7773: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7774: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7775: } else {
7776: $defquota = $quotahash{'quotas'}{'default'};
7777: }
1.536 raeburn 7778: $settingstatus = 'default';
7779: }
7780: } else {
7781: $settingstatus = 'default';
7782: $defquota = 20;
7783: }
7784: if (wantarray) {
7785: return ($defquota,$settingstatus);
1.472 raeburn 7786: } else {
1.536 raeburn 7787: return $defquota;
1.472 raeburn 7788: }
7789: }
7790:
1.384 raeburn 7791: sub get_secgrprole_info {
7792: my ($cdom,$cnum,$needroles,$type) = @_;
7793: my %sections_count = &get_sections($cdom,$cnum);
7794: my @sections = (sort {$a <=> $b} keys(%sections_count));
7795: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7796: my @groups = sort(keys(%curr_groups));
7797: my $allroles = [];
7798: my $rolehash;
7799: my $accesshash = {
7800: active => 'Currently has access',
7801: future => 'Will have future access',
7802: previous => 'Previously had access',
7803: };
7804: if ($needroles) {
7805: $rolehash = {'all' => 'all'};
1.385 albertel 7806: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7807: if (&Apache::lonnet::error(%user_roles)) {
7808: undef(%user_roles);
7809: }
7810: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7811: my ($role)=split(/\:/,$item,2);
7812: if ($role eq 'cr') { next; }
7813: if ($role =~ /^cr/) {
7814: $$rolehash{$role} = (split('/',$role))[3];
7815: } else {
7816: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7817: }
7818: }
7819: foreach my $key (sort(keys(%{$rolehash}))) {
7820: push(@{$allroles},$key);
7821: }
7822: push (@{$allroles},'st');
7823: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7824: }
7825: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7826: }
7827:
1.555 raeburn 7828: sub user_picker {
1.948.2.23 raeburn 7829: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 7830: my $currdom = $dom;
7831: my %curr_selected = (
7832: srchin => 'dom',
1.580 raeburn 7833: srchby => 'lastname',
1.555 raeburn 7834: );
7835: my $srchterm;
1.625 raeburn 7836: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7837: if ($srch->{'srchby'} ne '') {
7838: $curr_selected{'srchby'} = $srch->{'srchby'};
7839: }
7840: if ($srch->{'srchin'} ne '') {
7841: $curr_selected{'srchin'} = $srch->{'srchin'};
7842: }
7843: if ($srch->{'srchtype'} ne '') {
7844: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7845: }
7846: if ($srch->{'srchdomain'} ne '') {
7847: $currdom = $srch->{'srchdomain'};
7848: }
7849: $srchterm = $srch->{'srchterm'};
7850: }
7851: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7852: 'usr' => 'Search criteria',
1.563 raeburn 7853: 'doma' => 'Domain/institution to search',
1.558 albertel 7854: 'uname' => 'username',
7855: 'lastname' => 'last name',
1.555 raeburn 7856: 'lastfirst' => 'last name, first name',
1.558 albertel 7857: 'crs' => 'in this course',
1.576 raeburn 7858: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7859: 'alc' => 'all LON-CAPA',
1.573 raeburn 7860: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7861: 'exact' => 'is',
7862: 'contains' => 'contains',
1.569 raeburn 7863: 'begins' => 'begins with',
1.571 raeburn 7864: 'youm' => "You must include some text to search for.",
7865: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7866: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7867: 'yomc' => "You must choose a domain when using an institutional directory search.",
7868: 'ymcd' => "You must choose a domain when using a domain search.",
7869: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7870: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7871: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7872: );
1.563 raeburn 7873: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7874: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7875:
7876: my @srchins = ('crs','dom','alc','instd');
7877:
7878: foreach my $option (@srchins) {
7879: # FIXME 'alc' option unavailable until
7880: # loncreateuser::print_user_query_page()
7881: # has been completed.
7882: next if ($option eq 'alc');
1.880 raeburn 7883: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7884: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7885: if ($curr_selected{'srchin'} eq $option) {
7886: $srchinsel .= '
7887: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7888: } else {
7889: $srchinsel .= '
7890: <option value="'.$option.'">'.$lt{$option}.'</option>';
7891: }
1.555 raeburn 7892: }
1.563 raeburn 7893: $srchinsel .= "\n </select>\n";
1.555 raeburn 7894:
7895: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7896: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7897: if ($curr_selected{'srchby'} eq $option) {
7898: $srchbysel .= '
7899: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7900: } else {
7901: $srchbysel .= '
7902: <option value="'.$option.'">'.$lt{$option}.'</option>';
7903: }
7904: }
7905: $srchbysel .= "\n </select>\n";
7906:
7907: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7908: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7909: if ($curr_selected{'srchtype'} eq $option) {
7910: $srchtypesel .= '
7911: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7912: } else {
7913: $srchtypesel .= '
7914: <option value="'.$option.'">'.$lt{$option}.'</option>';
7915: }
7916: }
7917: $srchtypesel .= "\n </select>\n";
7918:
1.558 albertel 7919: my ($newuserscript,$new_user_create);
1.948.2.23 raeburn 7920: my $context_dom = $env{'request.role.domain'};
7921: if ($context eq 'requestcrs') {
7922: if ($env{'form.coursedom'} ne '') {
7923: $context_dom = $env{'form.coursedom'};
7924: }
7925: }
1.556 raeburn 7926: if ($forcenewuser) {
1.576 raeburn 7927: if (ref($srch) eq 'HASH') {
1.948.2.23 raeburn 7928: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 7929: if ($cancreate) {
7930: $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>';
7931: } else {
1.799 bisitz 7932: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7933: my %usertypetext = (
7934: official => 'institutional',
7935: unofficial => 'non-institutional',
7936: );
1.799 bisitz 7937: $new_user_create = '<p class="LC_warning">'
7938: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7939: .' '
7940: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7941: ,'<a href="'.$helplink.'">','</a>')
7942: .'</p><br />';
1.627 raeburn 7943: }
1.576 raeburn 7944: }
7945: }
7946:
1.556 raeburn 7947: $newuserscript = <<"ENDSCRIPT";
7948:
1.570 raeburn 7949: function setSearch(createnew,callingForm) {
1.556 raeburn 7950: if (createnew == 1) {
1.570 raeburn 7951: for (var i=0; i<callingForm.srchby.length; i++) {
7952: if (callingForm.srchby.options[i].value == 'uname') {
7953: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7954: }
7955: }
1.570 raeburn 7956: for (var i=0; i<callingForm.srchin.length; i++) {
7957: if ( callingForm.srchin.options[i].value == 'dom') {
7958: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7959: }
7960: }
1.570 raeburn 7961: for (var i=0; i<callingForm.srchtype.length; i++) {
7962: if (callingForm.srchtype.options[i].value == 'exact') {
7963: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7964: }
7965: }
1.570 raeburn 7966: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.948.2.23 raeburn 7967: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 7968: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7969: }
7970: }
7971: }
7972: }
7973: ENDSCRIPT
1.558 albertel 7974:
1.556 raeburn 7975: }
7976:
1.555 raeburn 7977: my $output = <<"END_BLOCK";
1.556 raeburn 7978: <script type="text/javascript">
1.824 bisitz 7979: // <![CDATA[
1.570 raeburn 7980: function validateEntry(callingForm) {
1.558 albertel 7981:
1.556 raeburn 7982: var checkok = 1;
1.558 albertel 7983: var srchin;
1.570 raeburn 7984: for (var i=0; i<callingForm.srchin.length; i++) {
7985: if ( callingForm.srchin[i].checked ) {
7986: srchin = callingForm.srchin[i].value;
1.558 albertel 7987: }
7988: }
7989:
1.570 raeburn 7990: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7991: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7992: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7993: var srchterm = callingForm.srchterm.value;
7994: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7995: var msg = "";
7996:
7997: if (srchterm == "") {
7998: checkok = 0;
1.571 raeburn 7999: msg += "$lt{'youm'}\\n";
1.556 raeburn 8000: }
8001:
1.569 raeburn 8002: if (srchtype== 'begins') {
8003: if (srchterm.length < 2) {
8004: checkok = 0;
1.571 raeburn 8005: msg += "$lt{'thte'}\\n";
1.569 raeburn 8006: }
8007: }
8008:
1.556 raeburn 8009: if (srchtype== 'contains') {
8010: if (srchterm.length < 3) {
8011: checkok = 0;
1.571 raeburn 8012: msg += "$lt{'thet'}\\n";
1.556 raeburn 8013: }
8014: }
8015: if (srchin == 'instd') {
8016: if (srchdomain == '') {
8017: checkok = 0;
1.571 raeburn 8018: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8019: }
8020: }
8021: if (srchin == 'dom') {
8022: if (srchdomain == '') {
8023: checkok = 0;
1.571 raeburn 8024: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8025: }
8026: }
8027: if (srchby == 'lastfirst') {
8028: if (srchterm.indexOf(",") == -1) {
8029: checkok = 0;
1.571 raeburn 8030: msg += "$lt{'whus'}\\n";
1.556 raeburn 8031: }
8032: if (srchterm.indexOf(",") == srchterm.length -1) {
8033: checkok = 0;
1.571 raeburn 8034: msg += "$lt{'whse'}\\n";
1.556 raeburn 8035: }
8036: }
8037: if (checkok == 0) {
1.571 raeburn 8038: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8039: return;
8040: }
8041: if (checkok == 1) {
1.570 raeburn 8042: callingForm.submit();
1.556 raeburn 8043: }
8044: }
8045:
8046: $newuserscript
8047:
1.824 bisitz 8048: // ]]>
1.556 raeburn 8049: </script>
1.558 albertel 8050:
8051: $new_user_create
8052:
1.555 raeburn 8053: END_BLOCK
1.558 albertel 8054:
1.876 raeburn 8055: $output .= &Apache::lonhtmlcommon::start_pick_box().
8056: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8057: $domform.
8058: &Apache::lonhtmlcommon::row_closure().
8059: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8060: $srchbysel.
8061: $srchtypesel.
8062: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8063: $srchinsel.
8064: &Apache::lonhtmlcommon::row_closure(1).
8065: &Apache::lonhtmlcommon::end_pick_box().
8066: '<br />';
1.555 raeburn 8067: return $output;
8068: }
8069:
1.612 raeburn 8070: sub user_rule_check {
1.615 raeburn 8071: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8072: my $response;
8073: if (ref($usershash) eq 'HASH') {
8074: foreach my $user (keys(%{$usershash})) {
8075: my ($uname,$udom) = split(/:/,$user);
8076: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8077: my ($id,$newuser);
1.612 raeburn 8078: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8079: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8080: $id = $usershash->{$user}->{'id'};
8081: }
8082: my $inst_response;
8083: if (ref($checks) eq 'HASH') {
8084: if (defined($checks->{'username'})) {
1.615 raeburn 8085: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8086: &Apache::lonnet::get_instuser($udom,$uname);
8087: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8088: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8089: &Apache::lonnet::get_instuser($udom,undef,$id);
8090: }
1.615 raeburn 8091: } else {
8092: ($inst_response,%{$inst_results->{$user}}) =
8093: &Apache::lonnet::get_instuser($udom,$uname);
8094: return;
1.612 raeburn 8095: }
1.615 raeburn 8096: if (!$got_rules->{$udom}) {
1.612 raeburn 8097: my %domconfig = &Apache::lonnet::get_dom('configuration',
8098: ['usercreation'],$udom);
8099: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8100: foreach my $item ('username','id') {
1.612 raeburn 8101: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8102: $$curr_rules{$udom}{$item} =
8103: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8104: }
8105: }
8106: }
1.615 raeburn 8107: $got_rules->{$udom} = 1;
1.585 raeburn 8108: }
1.612 raeburn 8109: foreach my $item (keys(%{$checks})) {
8110: if (ref($$curr_rules{$udom}) eq 'HASH') {
8111: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8112: if (@{$$curr_rules{$udom}{$item}} > 0) {
8113: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8114: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8115: if ($rule_check{$rule}) {
8116: $$rulematch{$user}{$item} = $rule;
8117: if ($inst_response eq 'ok') {
1.615 raeburn 8118: if (ref($inst_results) eq 'HASH') {
8119: if (ref($inst_results->{$user}) eq 'HASH') {
8120: if (keys(%{$inst_results->{$user}}) == 0) {
8121: $$alerts{$item}{$udom}{$uname} = 1;
8122: }
1.612 raeburn 8123: }
8124: }
1.615 raeburn 8125: }
8126: last;
1.585 raeburn 8127: }
8128: }
8129: }
8130: }
8131: }
8132: }
8133: }
8134: }
1.612 raeburn 8135: return;
8136: }
8137:
8138: sub user_rule_formats {
8139: my ($domain,$domdesc,$curr_rules,$check) = @_;
8140: my %text = (
8141: 'username' => 'Usernames',
8142: 'id' => 'IDs',
8143: );
8144: my $output;
8145: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8146: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8147: if (@{$ruleorder} > 0) {
8148: $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>';
8149: foreach my $rule (@{$ruleorder}) {
8150: if (ref($curr_rules) eq 'ARRAY') {
8151: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8152: if (ref($rules->{$rule}) eq 'HASH') {
8153: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8154: $rules->{$rule}{'desc'}.'</li>';
8155: }
8156: }
8157: }
8158: }
8159: $output .= '</ul>';
8160: }
8161: }
8162: return $output;
8163: }
8164:
8165: sub instrule_disallow_msg {
1.615 raeburn 8166: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8167: my $response;
8168: my %text = (
8169: item => 'username',
8170: items => 'usernames',
8171: match => 'matches',
8172: do => 'does',
8173: action => 'a username',
8174: one => 'one',
8175: );
8176: if ($count > 1) {
8177: $text{'item'} = 'usernames';
8178: $text{'match'} ='match';
8179: $text{'do'} = 'do';
8180: $text{'action'} = 'usernames',
8181: $text{'one'} = 'ones';
8182: }
8183: if ($checkitem eq 'id') {
8184: $text{'items'} = 'IDs';
8185: $text{'item'} = 'ID';
8186: $text{'action'} = 'an ID';
1.615 raeburn 8187: if ($count > 1) {
8188: $text{'item'} = 'IDs';
8189: $text{'action'} = 'IDs';
8190: }
1.612 raeburn 8191: }
1.674 bisitz 8192: $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 8193: if ($mode eq 'upload') {
8194: if ($checkitem eq 'username') {
8195: $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'}.");
8196: } elsif ($checkitem eq 'id') {
1.674 bisitz 8197: $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 8198: }
1.669 raeburn 8199: } elsif ($mode eq 'selfcreate') {
8200: if ($checkitem eq 'id') {
8201: $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.");
8202: }
1.615 raeburn 8203: } else {
8204: if ($checkitem eq 'username') {
8205: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8206: } elsif ($checkitem eq 'id') {
8207: $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.");
8208: }
1.612 raeburn 8209: }
8210: return $response;
1.585 raeburn 8211: }
8212:
1.624 raeburn 8213: sub personal_data_fieldtitles {
8214: my %fieldtitles = &Apache::lonlocal::texthash (
8215: id => 'Student/Employee ID',
8216: permanentemail => 'E-mail address',
8217: lastname => 'Last Name',
8218: firstname => 'First Name',
8219: middlename => 'Middle Name',
8220: generation => 'Generation',
8221: gen => 'Generation',
1.765 raeburn 8222: inststatus => 'Affiliation',
1.624 raeburn 8223: );
8224: return %fieldtitles;
8225: }
8226:
1.642 raeburn 8227: sub sorted_inst_types {
8228: my ($dom) = @_;
8229: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8230: my $othertitle = &mt('All users');
8231: if ($env{'request.course.id'}) {
1.668 raeburn 8232: $othertitle = &mt('Any users');
1.642 raeburn 8233: }
8234: my @types;
8235: if (ref($order) eq 'ARRAY') {
8236: @types = @{$order};
8237: }
8238: if (@types == 0) {
8239: if (ref($usertypes) eq 'HASH') {
8240: @types = sort(keys(%{$usertypes}));
8241: }
8242: }
8243: if (keys(%{$usertypes}) > 0) {
8244: $othertitle = &mt('Other users');
8245: }
8246: return ($othertitle,$usertypes,\@types);
8247: }
8248:
1.645 raeburn 8249: sub get_institutional_codes {
8250: my ($settings,$allcourses,$LC_code) = @_;
8251: # Get complete list of course sections to update
8252: my @currsections = ();
8253: my @currxlists = ();
8254: my $coursecode = $$settings{'internal.coursecode'};
8255:
8256: if ($$settings{'internal.sectionnums'} ne '') {
8257: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8258: }
8259:
8260: if ($$settings{'internal.crosslistings'} ne '') {
8261: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8262: }
8263:
8264: if (@currxlists > 0) {
8265: foreach (@currxlists) {
8266: if (m/^([^:]+):(\w*)$/) {
8267: unless (grep/^$1$/,@{$allcourses}) {
8268: push @{$allcourses},$1;
8269: $$LC_code{$1} = $2;
8270: }
8271: }
8272: }
8273: }
8274:
8275: if (@currsections > 0) {
8276: foreach (@currsections) {
8277: if (m/^(\w+):(\w*)$/) {
8278: my $sec = $coursecode.$1;
8279: my $lc_sec = $2;
8280: unless (grep/^$sec$/,@{$allcourses}) {
8281: push @{$allcourses},$sec;
8282: $$LC_code{$sec} = $lc_sec;
8283: }
8284: }
8285: }
8286: }
8287: return;
8288: }
8289:
1.948.2.7 raeburn 8290: sub get_standard_codeitems {
8291: return ('Year','Semester','Department','Number','Section');
8292: }
8293:
1.112 bowersj2 8294: =pod
8295:
1.780 raeburn 8296: =head1 Slot Helpers
8297:
8298: =over 4
8299:
8300: =item * sorted_slots()
8301:
8302: Sorts an array of slot names in order of slot start time (earliest first).
8303:
8304: Inputs:
8305:
8306: =over 4
8307:
8308: slotsarr - Reference to array of unsorted slot names.
8309:
8310: slots - Reference to hash of hash, where outer hash keys are slot names.
8311:
1.549 albertel 8312: =back
8313:
1.780 raeburn 8314: Returns:
8315:
8316: =over 4
8317:
8318: sorted - An array of slot names sorted by the start time of the slot.
8319:
8320: =back
8321:
8322: =back
8323:
8324: =cut
8325:
8326:
8327: sub sorted_slots {
8328: my ($slotsarr,$slots) = @_;
8329: my @sorted;
8330: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8331: @sorted =
8332: sort {
8333: if (ref($slots->{$a}) && ref($slots->{$b})) {
8334: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8335: }
8336: if (ref($slots->{$a})) { return -1;}
8337: if (ref($slots->{$b})) { return 1;}
8338: return 0;
8339: } @{$slotsarr};
8340: }
8341: return @sorted;
8342: }
8343:
8344:
8345: =pod
8346:
1.549 albertel 8347: =head1 HTTP Helpers
8348:
8349: =over 4
8350:
1.648 raeburn 8351: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8352:
1.258 albertel 8353: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8354: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8355: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8356:
8357: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8358: $possible_names is an ref to an array of form element names. As an example:
8359: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8360: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8361:
8362: =cut
1.1 albertel 8363:
1.6 albertel 8364: sub get_unprocessed_cgi {
1.25 albertel 8365: my ($query,$possible_names)= @_;
1.26 matthew 8366: # $Apache::lonxml::debug=1;
1.356 albertel 8367: foreach my $pair (split(/&/,$query)) {
8368: my ($name, $value) = split(/=/,$pair);
1.369 www 8369: $name = &unescape($name);
1.25 albertel 8370: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8371: $value =~ tr/+/ /;
8372: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8373: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8374: }
1.16 harris41 8375: }
1.6 albertel 8376: }
8377:
1.112 bowersj2 8378: =pod
8379:
1.648 raeburn 8380: =item * &cacheheader()
1.112 bowersj2 8381:
8382: returns cache-controlling header code
8383:
8384: =cut
8385:
1.7 albertel 8386: sub cacheheader {
1.258 albertel 8387: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8388: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8389: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8390: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8391: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8392: return $output;
1.7 albertel 8393: }
8394:
1.112 bowersj2 8395: =pod
8396:
1.648 raeburn 8397: =item * &no_cache($r)
1.112 bowersj2 8398:
8399: specifies header code to not have cache
8400:
8401: =cut
8402:
1.9 albertel 8403: sub no_cache {
1.216 albertel 8404: my ($r) = @_;
8405: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8406: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8407: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8408: $r->no_cache(1);
8409: $r->header_out("Expires" => $date);
8410: $r->header_out("Pragma" => "no-cache");
1.123 www 8411: }
8412:
8413: sub content_type {
1.181 albertel 8414: my ($r,$type,$charset) = @_;
1.299 foxr 8415: if ($r) {
8416: # Note that printout.pl calls this with undef for $r.
8417: &no_cache($r);
8418: }
1.258 albertel 8419: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8420: unless ($charset) {
8421: $charset=&Apache::lonlocal::current_encoding;
8422: }
8423: if ($charset) { $type.='; charset='.$charset; }
8424: if ($r) {
8425: $r->content_type($type);
8426: } else {
8427: print("Content-type: $type\n\n");
8428: }
1.9 albertel 8429: }
1.25 albertel 8430:
1.112 bowersj2 8431: =pod
8432:
1.648 raeburn 8433: =item * &add_to_env($name,$value)
1.112 bowersj2 8434:
1.258 albertel 8435: adds $name to the %env hash with value
1.112 bowersj2 8436: $value, if $name already exists, the entry is converted to an array
8437: reference and $value is added to the array.
8438:
8439: =cut
8440:
1.25 albertel 8441: sub add_to_env {
8442: my ($name,$value)=@_;
1.258 albertel 8443: if (defined($env{$name})) {
8444: if (ref($env{$name})) {
1.25 albertel 8445: #already have multiple values
1.258 albertel 8446: push(@{ $env{$name} },$value);
1.25 albertel 8447: } else {
8448: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8449: my $first=$env{$name};
8450: undef($env{$name});
8451: push(@{ $env{$name} },$first,$value);
1.25 albertel 8452: }
8453: } else {
1.258 albertel 8454: $env{$name}=$value;
1.25 albertel 8455: }
1.31 albertel 8456: }
1.149 albertel 8457:
8458: =pod
8459:
1.648 raeburn 8460: =item * &get_env_multiple($name)
1.149 albertel 8461:
1.258 albertel 8462: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8463: values may be defined and end up as an array ref.
8464:
8465: returns an array of values
8466:
8467: =cut
8468:
8469: sub get_env_multiple {
8470: my ($name) = @_;
8471: my @values;
1.258 albertel 8472: if (defined($env{$name})) {
1.149 albertel 8473: # exists is it an array
1.258 albertel 8474: if (ref($env{$name})) {
8475: @values=@{ $env{$name} };
1.149 albertel 8476: } else {
1.258 albertel 8477: $values[0]=$env{$name};
1.149 albertel 8478: }
8479: }
8480: return(@values);
8481: }
8482:
1.660 raeburn 8483: sub ask_for_embedded_content {
8484: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.948.2.17 raeburn 8485: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660 raeburn 8486: my $num = 0;
1.948.2.17 raeburn 8487: my $numremref = 0;
8488: my $numinvalid = 0;
8489: my $numpathchg = 0;
8490: my $numexisting = 0;
8491: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.948.2.12 raeburn 8492: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8493: my $current_path='/';
8494: if ($env{'form.currentpath'}) {
8495: $current_path = $env{'form.currentpath'};
8496: }
8497: if ($actionurl eq '/adm/coursegrp_portfolio') {
8498: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8499: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8500: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8501: } else {
8502: $udom = $env{'user.domain'};
8503: $uname = $env{'user.name'};
8504: $url = '/userfiles/portfolio';
8505: }
1.948.2.17 raeburn 8506: $toplevel = $url.'/';
1.948.2.12 raeburn 8507: $url .= $current_path;
8508: $getpropath = 1;
1.948.2.17 raeburn 8509: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8510: ($actionurl eq '/adm/imsimport')) {
1.948.2.12 raeburn 8511: ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
1.948.2.17 raeburn 8512: $url = '/home/'.$uname.'/public_html/';
8513: $toplevel = $url;
1.948.2.12 raeburn 8514: if ($rest ne '') {
1.948.2.17 raeburn 8515: $url .= $rest;
8516: }
8517: } elsif ($actionurl eq '/adm/coursedocs') {
8518: if (ref($args) eq 'HASH') {
8519: $url = $args->{'docs_url'};
8520: $toplevel = $url;
8521: }
8522: }
8523: my $now = time();
8524: foreach my $embed_file (keys(%{$allfiles})) {
8525: my $absolutepath;
8526: if ($embed_file =~ m{^\w+://}) {
8527: $newfiles{$embed_file} = 1;
8528: $mapping{$embed_file} = $embed_file;
8529: } else {
8530: if ($embed_file =~ m{^/}) {
8531: $absolutepath = $embed_file;
8532: $embed_file =~ s{^(/+)}{};
8533: }
8534: if ($embed_file =~ m{/}) {
8535: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8536: $path = &check_for_traversal($path,$url,$toplevel);
8537: my $item = $fname;
8538: if ($path ne '') {
8539: $item = $path.'/'.$fname;
8540: $subdependencies{$path}{$fname} = 1;
8541: } else {
8542: $dependencies{$item} = 1;
8543: }
8544: if ($absolutepath) {
8545: $mapping{$item} = $absolutepath;
8546: } else {
8547: $mapping{$item} = $embed_file;
8548: }
8549: } else {
8550: $dependencies{$embed_file} = 1;
8551: if ($absolutepath) {
8552: $mapping{$embed_file} = $absolutepath;
8553: } else {
8554: $mapping{$embed_file} = $embed_file;
8555: }
8556: }
1.948.2.12 raeburn 8557: }
8558: }
8559: foreach my $path (keys(%subdependencies)) {
8560: my %currsubfile;
8561: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8562: my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8563: foreach my $line (@subdir_list) {
8564: my ($file_name,$rest) = split(/\&/,$line,2);
8565: $currsubfile{$file_name} = 1;
8566: }
1.948.2.17 raeburn 8567: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.948.2.12 raeburn 8568: if (opendir(my $dir,$url.'/'.$path)) {
8569: my @subdir_list = grep(!/^\./,readdir($dir));
8570: map {$currsubfile{$_} = 1;} @subdir_list;
8571: }
8572: }
8573: foreach my $file (keys(%{$subdependencies{$path}})) {
1.948.2.17 raeburn 8574: if ($currsubfile{$file}) {
8575: my $item = $path.'/'.$file;
8576: unless ($mapping{$item} eq $item) {
8577: $pathchanges{$item} = 1;
8578: }
8579: $existing{$item} = 1;
8580: $numexisting ++;
8581: } else {
8582: $newfiles{$path.'/'.$file} = 1;
1.948.2.12 raeburn 8583: }
8584: }
8585: }
1.948.2.17 raeburn 8586: my %currfile;
1.948.2.12 raeburn 8587: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8588: my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8589: foreach my $line (@dir_list) {
8590: my ($file_name,$rest) = split(/\&/,$line,2);
8591: $currfile{$file_name} = 1;
8592: }
1.948.2.17 raeburn 8593: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.948.2.12 raeburn 8594: if (opendir(my $dir,$url)) {
1.948.2.17 raeburn 8595: my @dir_list = grep(!/^\./,readdir($dir));
1.948.2.12 raeburn 8596: map {$currfile{$_} = 1;} @dir_list;
8597: }
8598: }
8599: foreach my $file (keys(%dependencies)) {
1.948.2.17 raeburn 8600: if ($currfile{$file}) {
8601: unless ($mapping{$file} eq $file) {
8602: $pathchanges{$file} = 1;
8603: }
8604: $existing{$file} = 1;
8605: $numexisting ++;
8606: } else {
1.948.2.12 raeburn 8607: $newfiles{$file} = 1;
8608: }
8609: }
8610: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8611: $upload_output .= &start_data_table_row().
1.948.2.17 raeburn 8612: '<td><span class="LC_filename">'.$embed_file.'</span>';
8613: unless ($mapping{$embed_file} eq $embed_file) {
8614: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
8615: }
8616: $upload_output .= '</td><td>';
1.660 raeburn 8617: if ($args->{'ignore_remote_references'}
8618: && $embed_file =~ m{^\w+://}) {
8619: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.948.2.17 raeburn 8620: $numremref++;
1.660 raeburn 8621: } elsif ($args->{'error_on_invalid_names'}
8622: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8623:
1.948.2.17 raeburn 8624: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
8625: $numinvalid++;
1.660 raeburn 8626: } else {
1.948.2.17 raeburn 8627: $upload_output .= &embedded_file_element('upload_embedded',$num,
8628: $embed_file,\%mapping,
8629: $allfiles,$codebase);
8630: $num++;
1.660 raeburn 8631: }
1.948.2.12 raeburn 8632: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
1.660 raeburn 8633: }
1.948.2.17 raeburn 8634: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
8635: $upload_output .= &start_data_table_row().
8636: '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
8637: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
8638: &Apache::loncommon::end_data_table_row()."\n";
8639: }
8640: if ($upload_output) {
8641: $upload_output = &start_data_table().
1.948.2.12 raeburn 8642: $upload_output.
1.948.2.17 raeburn 8643: &end_data_table()."\n";
8644: }
8645: my $applies = 0;
8646: if ($numremref) {
8647: $applies ++;
8648: }
8649: if ($numinvalid) {
8650: $applies ++;
8651: }
8652: if ($numexisting) {
8653: $applies ++;
8654: }
8655: if ($num) {
8656: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8657: ' method="post" enctype="multipart/form-data">'."\n".
8658: $state.
8659: '<h3>'.&mt('Upload embedded files').
8660: ':</h3>'.$upload_output.'<br />'."\n".
8661: '<input type ="hidden" name="number_embedded_items" value="'.
8662: $num.'" />'."\n";
8663: if ($actionurl eq '') {
8664: $output .= '<input type="hidden" name="phase" value="three" />';
8665: }
8666: } elsif ($applies) {
8667: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
8668: if ($applies > 1) {
8669: $output .=
8670: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
8671: if ($numremref) {
8672: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
8673: }
8674: if ($numinvalid) {
8675: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
8676: }
8677: if ($numexisting) {
8678: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
8679: }
8680: $output .= '</ul><br />';
8681: } elsif ($numremref) {
8682: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
8683: } elsif ($numinvalid) {
8684: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
8685: } elsif ($numexisting) {
8686: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
8687: }
8688: $output .= $upload_output.'<br />';
8689: }
8690: my ($pathchange_output,$chgcount);
8691: $chgcount = $num;
8692: if (keys(%pathchanges) > 0) {
8693: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
8694: if ($num) {
8695: $output .= &embedded_file_element('pathchange',$chgcount,
8696: $embed_file,\%mapping,
8697: $allfiles,$codebase);
8698: } else {
8699: $pathchange_output .=
8700: &start_data_table_row().
8701: '<td><input type ="checkbox" name="namechange" value="'.
8702: $chgcount.'" checked="checked" /></td>'.
8703: '<td>'.$mapping{$embed_file}.'</td>'.
8704: '<td>'.$embed_file.
8705: &embedded_file_element('pathchange',$numpathchg,$embed_file,
8706: \%mapping,$allfiles,$codebase).
8707: '</td>'.&end_data_table_row();
8708: }
8709: $numpathchg ++;
8710: $chgcount ++;
8711: }
8712: }
8713: if ($num) {
8714: if ($numpathchg) {
8715: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
8716: $numpathchg.'" />'."\n";
8717: }
8718: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
8719: ($actionurl eq '/adm/imsimport')) {
8720: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
8721: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
8722: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
8723: }
8724: $output .= '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8725: &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
8726: } elsif ($numpathchg) {
8727: my %pathchange = ();
8728: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
8729: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8730: $output .= '<p>'.&mt('or').'</p>';
8731: }
8732: }
8733: return ($output,$num,$numpathchg);
8734: }
8735:
8736: sub embedded_file_element {
8737: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
8738: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
8739: (ref($codebase) eq 'HASH'));
8740: my $output;
8741: if ($context eq 'upload_embedded') {
8742: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
8743: }
8744: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
8745: &escape($embed_file).'" />';
8746: unless (($context eq 'upload_embedded') &&
8747: ($mapping->{$embed_file} eq $embed_file)) {
8748: $output .='
8749: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
8750: }
8751: my $attrib;
8752: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
8753: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
1.948.2.12 raeburn 8754: }
1.948.2.17 raeburn 8755: $output .=
8756: "\n\t\t".
8757: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8758: $attrib.'" />';
8759: if (exists($codebase->{$mapping->{$embed_file}})) {
8760: $output .=
8761: "\n\t\t".
8762: '<input name="codebase_'.$num.'" type="hidden" value="'.
8763: &escape($codebase->{$mapping->{$embed_file}}).'" />';
8764: }
8765: return $output;
1.660 raeburn 8766: }
8767:
1.661 raeburn 8768: sub upload_embedded {
8769: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.948.2.17 raeburn 8770: $current_disk_usage,$hiddenstate,$actionurl) = @_;
8771: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 8772: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8773: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8774: my $orig_uploaded_filename =
8775: $env{'form.embedded_item_'.$i.'.filename'};
1.948.2.17 raeburn 8776: foreach my $type ('orig','ref','attrib','codebase') {
8777: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
8778: $env{'form.embedded_'.$type.'_'.$i} =
8779: &unescape($env{'form.embedded_'.$type.'_'.$i});
8780: }
8781: }
1.661 raeburn 8782: my ($path,$fname) =
8783: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8784: # no path, whole string is fname
8785: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8786: $fname = &Apache::lonnet::clean_filename($fname);
8787: # See if there is anything left
8788: next if ($fname eq '');
8789:
8790: # Check if file already exists as a file or directory.
8791: my ($state,$msg);
8792: if ($context eq 'portfolio') {
8793: my $port_path = $dirpath;
8794: if ($group ne '') {
8795: $port_path = "groups/$group/$port_path";
8796: }
1.948.2.17 raeburn 8797: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
8798: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 8799: $dir_root,$port_path,$disk_quota,
8800: $current_disk_usage,$uname,$udom);
8801: if ($state eq 'will_exceed_quota'
1.948.2.12 raeburn 8802: || $state eq 'file_locked') {
1.661 raeburn 8803: $output .= $msg;
8804: next;
8805: }
8806: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8807: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8808: if ($state eq 'exists') {
8809: $output .= $msg;
8810: next;
8811: }
8812: }
8813: # Check if extension is valid
8814: if (($fname =~ /\.(\w+)$/) &&
8815: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.948.2.17 raeburn 8816: $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 8817: next;
8818: } elsif (($fname =~ /\.(\w+)$/) &&
8819: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.948.2.17 raeburn 8820: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 8821: next;
8822: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.948.2.17 raeburn 8823: $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 8824: next;
8825: }
8826:
8827: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8828: if ($context eq 'portfolio') {
1.948.2.12 raeburn 8829: my $result;
8830: if ($state eq 'existingfile') {
8831: $result=
8832: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.948.2.17 raeburn 8833: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 8834: } else {
1.948.2.12 raeburn 8835: $result=
8836: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.948.2.17 raeburn 8837: $dirpath.
8838: $env{'form.currentpath'}.$path);
1.948.2.12 raeburn 8839: if ($result !~ m|^/uploaded/|) {
8840: $output .= '<span class="LC_error">'
8841: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8842: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8843: .'</span><br />';
8844: next;
8845: } else {
1.948.2.17 raeburn 8846: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8847: $path.$fname.'</span>').'<br />';
1.948.2.12 raeburn 8848: }
1.661 raeburn 8849: }
1.948.2.17 raeburn 8850: } elsif ($context eq 'coursedoc') {
8851: my $result =
8852: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
8853: $dirpath.'/'.$path);
8854: if ($result !~ m|^/uploaded/|) {
8855: $output .= '<span class="LC_error">'
8856: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8857: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8858: .'</span><br />';
8859: next;
8860: } else {
8861: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8862: $path.$fname.'</span>').'<br />';
8863: }
1.661 raeburn 8864: } else {
8865: # Save the file
8866: my $target = $env{'form.embedded_item_'.$i};
8867: my $fullpath = $dir_root.$dirpath.'/'.$path;
8868: my $dest = $fullpath.$fname;
8869: my $url = $url_root.$dirpath.'/'.$path.$fname;
8870: my @parts=split(/\//,$fullpath);
8871: my $count;
8872: my $filepath = $dir_root;
8873: for ($count=4;$count<=$#parts;$count++) {
8874: $filepath .= "/$parts[$count]";
8875: if ((-e $filepath)!=1) {
8876: mkdir($filepath,0770);
8877: }
8878: }
8879: my $fh;
8880: if (!open($fh,'>'.$dest)) {
8881: &Apache::lonnet::logthis('Failed to create '.$dest);
8882: $output .= '<span class="LC_error">'.
8883: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8884: '</span><br />';
8885: } else {
8886: if (!print $fh $env{'form.embedded_item_'.$i}) {
8887: &Apache::lonnet::logthis('Failed to write to '.$dest);
8888: $output .= '<span class="LC_error">'.
8889: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8890: '</span><br />';
8891: } else {
1.948.2.17 raeburn 8892: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
8893: $url.'</span>').'<br />';
8894: unless ($context eq 'testbank') {
8895: $footer .= &mt('View embedded file: [_1]',
8896: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
1.661 raeburn 8897: }
8898: }
8899: close($fh);
8900: }
8901: }
1.948.2.17 raeburn 8902: if ($env{'form.embedded_ref_'.$i}) {
8903: $pathchange{$i} = 1;
8904: }
1.948.2.18 raeburn 8905: }
1.948.2.17 raeburn 8906: if ($output) {
8907: $output = '<p>'.$output.'</p>';
8908: }
8909: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
8910: $returnflag = 'ok';
8911: if (keys(%pathchange) > 0) {
8912: if ($context eq 'portfolio') {
8913: $output .= '<p>'.&mt('or').'</p>';
8914: } elsif ($context eq 'testbank') {
8915: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
8916: $returnflag = 'modify_orightml';
8917: }
8918: }
8919: return ($output.$footer,$returnflag);
8920: }
8921:
8922: sub modify_html_form {
8923: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
8924: my $end = 0;
8925: my $modifyform;
8926: if ($context eq 'upload_embedded') {
8927: return unless (ref($pathchange) eq 'HASH');
8928: if ($env{'form.number_embedded_items'}) {
8929: $end += $env{'form.number_embedded_items'};
8930: }
8931: if ($env{'form.number_pathchange_items'}) {
8932: $end += $env{'form.number_pathchange_items'};
8933: }
8934: if ($end) {
8935: for (my $i=0; $i<$end; $i++) {
8936: if ($i < $env{'form.number_embedded_items'}) {
8937: next unless($pathchange->{$i});
8938: }
8939: $modifyform .=
8940: &start_data_table_row().
8941: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
8942: 'checked="checked" /></td>'.
8943: '<td>'.$env{'form.embedded_ref_'.$i}.
8944: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
8945: &escape($env{'form.embedded_ref_'.$i}).'" />'.
8946: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
8947: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
8948: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
8949: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
8950: '<td>'.$env{'form.embedded_orig_'.$i}.
8951: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
8952: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
8953: &end_data_table_row();
8954: }
8955: }
8956: } else {
8957: $modifyform = $pathchgtable;
8958: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
8959: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
8960: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8961: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
8962: }
8963: }
8964: if ($modifyform) {
8965: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
8966: '<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".
8967: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
8968: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
8969: '</ol></p>'."\n".'<p>'.
8970: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
8971: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
8972: &start_data_table()."\n".
8973: &start_data_table_header_row().
8974: '<th>'.&mt('Change?').'</th>'.
8975: '<th>'.&mt('Current reference').'</th>'.
8976: '<th>'.&mt('Required reference').'</th>'.
8977: &end_data_table_header_row()."\n".
8978: $modifyform.
8979: &end_data_table().'<br />'."\n".$hiddenstate.
8980: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
8981: '</form>'."\n";
8982: }
8983: return;
8984: }
8985:
8986: sub modify_html_refs {
8987: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
8988: my $container;
8989: if ($context eq 'portfolio') {
8990: $container = $env{'form.container'};
8991: } elsif ($context eq 'coursedoc') {
8992: $container = $env{'form.primaryurl'};
8993: } else {
8994: $container = $env{'form.filename'};
8995: $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
8996: }
8997: my (%allfiles,%codebase,$output,$content);
8998: my @changes = &get_env_multiple('form.namechange');
8999: return unless (@changes > 0);
9000: if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
9001: return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
9002: $content = &Apache::lonnet::getfile($container);
9003: return if ($content eq '-1');
9004: } else {
9005: return unless ($container =~ /^\Q$dir_root\E/);
9006: if (open(my $fh,"<$container")) {
9007: $content = join('', <$fh>);
9008: close($fh);
9009: } else {
9010: return;
9011: }
9012: }
9013: my ($count,$codebasecount) = (0,0);
9014: my $mm = new File::MMagic;
9015: my $mime_type = $mm->checktype_contents($content);
9016: if ($mime_type eq 'text/html') {
9017: my $parse_result =
9018: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
9019: \%codebase,\$content);
9020: if ($parse_result eq 'ok') {
9021: foreach my $i (@changes) {
9022: my $orig = &unescape($env{'form.embedded_orig_'.$i});
9023: my $ref = &unescape($env{'form.embedded_ref_'.$i});
9024: if ($allfiles{$ref}) {
9025: my $newname = $orig;
9026: my ($attrib_regexp,$codebase);
9027: my $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
9028: if ($attrib_regexp =~ /:/) {
9029: $attrib_regexp =~ s/\:/|/g;
9030: }
9031: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
9032: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
9033: $count += $numchg;
9034: }
9035: if ($env{'form.embedded_codebase_'.$i} ne '') {
9036: my $codebase = &unescape($env{'form.embedded_codebase_'.$i});
9037: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
9038: $codebasecount ++;
9039: }
9040: }
9041: }
9042: if ($count || $codebasecount) {
9043: my $saveresult;
9044: if ($context eq 'portfolio' || $context eq 'coursedoc') {
9045: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
9046: if ($url eq $container) {
9047: my ($fname) = ($container =~ m{/([^/]+)$});
9048: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9049: $count,'<span class="LC_filename">'.
9050: $fname.'</span>').'</p>';
9051: } else {
9052: $output = '<p class="LC_error">'.
9053: &mt('Error: update failed for: [_1].',
9054: '<span class="LC_filename">'.
9055: $container.'</span>').'</p>';
9056: }
9057: } else {
9058: if (open(my $fh,">$container")) {
9059: print $fh $content;
9060: close($fh);
9061: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
9062: $count,'<span class="LC_filename">'.
9063: $container.'</span>').'</p>';
9064: } else {
9065: $output = '<p class="LC_error">'.
9066: &mt('Error: could not update [_1].',
9067: '<span class="LC_filename">'.
9068: $container.'</span>').'</p>';
9069: }
9070: }
9071: }
9072: } else {
9073: &logthis('Failed to parse '.$container.
9074: ' to modify references: '.$parse_result);
9075: }
1.661 raeburn 9076: }
9077: return $output;
9078: }
9079:
9080: sub check_for_existing {
9081: my ($path,$fname,$element) = @_;
9082: my ($state,$msg);
9083: if (-d $path.'/'.$fname) {
9084: $state = 'exists';
9085: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9086: } elsif (-e $path.'/'.$fname) {
9087: $state = 'exists';
9088: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
9089: }
9090: if ($state eq 'exists') {
9091: $msg = '<span class="LC_error">'.$msg.'</span><br />';
9092: }
9093: return ($state,$msg);
9094: }
9095:
9096: sub check_for_upload {
9097: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
9098: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.948.2.12 raeburn 9099: my $filesize = length($env{'form.'.$element});
9100: if (!$filesize) {
9101: my $msg = '<span class="LC_error">'.
9102: &mt('Unable to upload [_1]. (size = [_2] bytes)',
9103: '<span class="LC_filename">'.$fname.'</span>',
9104: $filesize).'<br />'.
1.948.2.21 raeburn 9105: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />';
1.948.2.12 raeburn 9106: '</span>';
9107: return ('zero_bytes',$msg);
9108: }
9109: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 9110: my $getpropath = 1;
9111: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
9112: $getpropath);
9113: my $found_file = 0;
9114: my $locked_file = 0;
1.948.2.20 raeburn 9115: my @lockers;
9116: my $navmap;
9117: if ($env{'request.course.id'}) {
9118: $navmap = Apache::lonnavmaps::navmap->new();
9119: }
1.661 raeburn 9120: foreach my $line (@dir_list) {
1.948.2.12 raeburn 9121: my ($file_name,$rest)=split(/\&/,$line,2);
1.661 raeburn 9122: if ($file_name eq $fname){
9123: $file_name = $path.$file_name;
9124: if ($group ne '') {
9125: $file_name = $group.$file_name;
9126: }
9127: $found_file = 1;
1.948.2.20 raeburn 9128: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
9129: foreach my $lock (@lockers) {
9130: if (ref($lock) eq 'ARRAY') {
9131: my ($symb,$crsid) = @{$lock};
9132: if ($crsid eq $env{'request.course.id'}) {
9133: if (ref($navmap)) {
9134: my $res = $navmap->getBySymb($symb);
9135: foreach my $part (@{$res->parts()}) {
9136: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
9137: unless (($slot_status == $res->RESERVED) ||
9138: ($slot_status == $res->RESERVED_LOCATION)) {
9139: $locked_file = 1;
9140: }
9141: }
9142: } else {
9143: $locked_file = 1;
9144: }
9145: } else {
9146: $locked_file = 1;
9147: }
9148: }
9149: }
1.948.2.12 raeburn 9150: } else {
9151: my @info = split(/\&/,$rest);
9152: my $currsize = $info[6]/1000;
9153: if ($currsize < $filesize) {
9154: my $extra = $filesize - $currsize;
9155: if (($current_disk_usage + $extra) > $disk_quota) {
9156: my $msg = '<span class="LC_error">'.
9157: &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.',
9158: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
9159: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
9160: $disk_quota,$current_disk_usage);
9161: return ('will_exceed_quota',$msg);
9162: }
9163: }
1.661 raeburn 9164: }
9165: }
9166: }
9167: if (($current_disk_usage + $filesize) > $disk_quota){
9168: my $msg = '<span class="LC_error">'.
9169: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
9170: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
9171: return ('will_exceed_quota',$msg);
9172: } elsif ($found_file) {
9173: if ($locked_file) {
9174: my $msg = '<span class="LC_error">';
9175: $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>');
9176: $msg .= '</span><br />';
9177: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
9178: return ('file_locked',$msg);
9179: } else {
9180: my $msg = '<span class="LC_error">';
1.948.2.12 raeburn 9181: $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 9182: $msg .= '</span>';
1.948.2.12 raeburn 9183: return ('existingfile',$msg);
1.661 raeburn 9184: }
9185: }
9186: }
9187:
1.948.2.17 raeburn 9188: sub check_for_traversal {
9189: my ($path,$url,$toplevel) = @_;
9190: my @parts=split(/\//,$path);
9191: my $cleanpath;
9192: my $fullpath = $url;
9193: for (my $i=0;$i<@parts;$i++) {
9194: next if ($parts[$i] eq '.');
9195: if ($parts[$i] eq '..') {
9196: $fullpath =~ s{([^/]+/)$}{};
9197: } else {
9198: $fullpath .= $parts[$i].'/';
9199: }
9200: }
9201: if ($fullpath =~ /^\Q$url\E(.*)$/) {
9202: $cleanpath = $1;
9203: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
9204: my $curr_toprel = $1;
9205: my @parts = split(/\//,$curr_toprel);
9206: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
9207: my @urlparts = split(/\//,$url_toprel);
9208: my $doubledots;
9209: my $startdiff = -1;
9210: for (my $i=0; $i<@urlparts; $i++) {
9211: if ($startdiff == -1) {
9212: unless ($urlparts[$i] eq $parts[$i]) {
9213: $startdiff = $i;
9214: $doubledots .= '../';
9215: }
9216: } else {
9217: $doubledots .= '../';
9218: }
9219: }
9220: if ($startdiff > -1) {
9221: $cleanpath = $doubledots;
9222: for (my $i=$startdiff; $i<@parts; $i++) {
9223: $cleanpath .= $parts[$i].'/';
9224: }
9225: }
9226: }
9227: $cleanpath =~ s{(/)$}{};
9228: return $cleanpath;
9229: }
1.31 albertel 9230:
1.41 ng 9231: =pod
1.45 matthew 9232:
1.464 albertel 9233: =back
1.41 ng 9234:
1.112 bowersj2 9235: =head1 CSV Upload/Handling functions
1.38 albertel 9236:
1.41 ng 9237: =over 4
9238:
1.648 raeburn 9239: =item * &upfile_store($r)
1.41 ng 9240:
9241: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 9242: needs $env{'form.upfile'}
1.41 ng 9243: returns $datatoken to be put into hidden field
9244:
9245: =cut
1.31 albertel 9246:
9247: sub upfile_store {
9248: my $r=shift;
1.258 albertel 9249: $env{'form.upfile'}=~s/\r/\n/gs;
9250: $env{'form.upfile'}=~s/\f/\n/gs;
9251: $env{'form.upfile'}=~s/\n+/\n/gs;
9252: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 9253:
1.258 albertel 9254: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
9255: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 9256: {
1.158 raeburn 9257: my $datafile = $r->dir_config('lonDaemons').
9258: '/tmp/'.$datatoken.'.tmp';
9259: if ( open(my $fh,">$datafile") ) {
1.258 albertel 9260: print $fh $env{'form.upfile'};
1.158 raeburn 9261: close($fh);
9262: }
1.31 albertel 9263: }
9264: return $datatoken;
9265: }
9266:
1.56 matthew 9267: =pod
9268:
1.648 raeburn 9269: =item * &load_tmp_file($r)
1.41 ng 9270:
9271: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 9272: needs $env{'form.datatoken'},
9273: sets $env{'form.upfile'} to the contents of the file
1.41 ng 9274:
9275: =cut
1.31 albertel 9276:
9277: sub load_tmp_file {
9278: my $r=shift;
9279: my @studentdata=();
9280: {
1.158 raeburn 9281: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 9282: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 9283: if ( open(my $fh,"<$studentfile") ) {
9284: @studentdata=<$fh>;
9285: close($fh);
9286: }
1.31 albertel 9287: }
1.258 albertel 9288: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 9289: }
9290:
1.56 matthew 9291: =pod
9292:
1.648 raeburn 9293: =item * &upfile_record_sep()
1.41 ng 9294:
9295: Separate uploaded file into records
9296: returns array of records,
1.258 albertel 9297: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 9298:
9299: =cut
1.31 albertel 9300:
9301: sub upfile_record_sep {
1.258 albertel 9302: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 9303: } else {
1.248 albertel 9304: my @records;
1.258 albertel 9305: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 9306: if ($line=~/^\s*$/) { next; }
9307: push(@records,$line);
9308: }
9309: return @records;
1.31 albertel 9310: }
9311: }
9312:
1.56 matthew 9313: =pod
9314:
1.648 raeburn 9315: =item * &record_sep($record)
1.41 ng 9316:
1.258 albertel 9317: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 9318:
9319: =cut
9320:
1.263 www 9321: sub takeleft {
9322: my $index=shift;
9323: return substr('0000'.$index,-4,4);
9324: }
9325:
1.31 albertel 9326: sub record_sep {
9327: my $record=shift;
9328: my %components=();
1.258 albertel 9329: if ($env{'form.upfiletype'} eq 'xml') {
9330: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 9331: my $i=0;
1.356 albertel 9332: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 9333: $field=~s/^(\"|\')//;
9334: $field=~s/(\"|\')$//;
1.263 www 9335: $components{&takeleft($i)}=$field;
1.31 albertel 9336: $i++;
9337: }
1.258 albertel 9338: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 9339: my $i=0;
1.356 albertel 9340: foreach my $field (split(/\t/,$record)) {
1.31 albertel 9341: $field=~s/^(\"|\')//;
9342: $field=~s/(\"|\')$//;
1.263 www 9343: $components{&takeleft($i)}=$field;
1.31 albertel 9344: $i++;
9345: }
9346: } else {
1.561 www 9347: my $separator=',';
1.480 banghart 9348: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 9349: $separator=';';
1.480 banghart 9350: }
1.31 albertel 9351: my $i=0;
1.561 www 9352: # the character we are looking for to indicate the end of a quote or a record
9353: my $looking_for=$separator;
9354: # do not add the characters to the fields
9355: my $ignore=0;
9356: # we just encountered a separator (or the beginning of the record)
9357: my $just_found_separator=1;
9358: # store the field we are working on here
9359: my $field='';
9360: # work our way through all characters in record
9361: foreach my $character ($record=~/(.)/g) {
9362: if ($character eq $looking_for) {
9363: if ($character ne $separator) {
9364: # Found the end of a quote, again looking for separator
9365: $looking_for=$separator;
9366: $ignore=1;
9367: } else {
9368: # Found a separator, store away what we got
9369: $components{&takeleft($i)}=$field;
9370: $i++;
9371: $just_found_separator=1;
9372: $ignore=0;
9373: $field='';
9374: }
9375: next;
9376: }
9377: # single or double quotation marks after a separator indicate beginning of a quote
9378: # we are now looking for the end of the quote and need to ignore separators
9379: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
9380: $looking_for=$character;
9381: next;
9382: }
9383: # ignore would be true after we reached the end of a quote
9384: if ($ignore) { next; }
9385: if (($just_found_separator) && ($character=~/\s/)) { next; }
9386: $field.=$character;
9387: $just_found_separator=0;
1.31 albertel 9388: }
1.561 www 9389: # catch the very last entry, since we never encountered the separator
9390: $components{&takeleft($i)}=$field;
1.31 albertel 9391: }
9392: return %components;
9393: }
9394:
1.144 matthew 9395: ######################################################
9396: ######################################################
9397:
1.56 matthew 9398: =pod
9399:
1.648 raeburn 9400: =item * &upfile_select_html()
1.41 ng 9401:
1.144 matthew 9402: Return HTML code to select a file from the users machine and specify
9403: the file type.
1.41 ng 9404:
9405: =cut
9406:
1.144 matthew 9407: ######################################################
9408: ######################################################
1.31 albertel 9409: sub upfile_select_html {
1.144 matthew 9410: my %Types = (
9411: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 9412: semisv => &mt('Semicolon separated values'),
1.144 matthew 9413: space => &mt('Space separated'),
9414: tab => &mt('Tabulator separated'),
9415: # xml => &mt('HTML/XML'),
9416: );
9417: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 9418: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 9419: foreach my $type (sort(keys(%Types))) {
9420: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
9421: }
9422: $Str .= "</select>\n";
9423: return $Str;
1.31 albertel 9424: }
9425:
1.301 albertel 9426: sub get_samples {
9427: my ($records,$toget) = @_;
9428: my @samples=({});
9429: my $got=0;
9430: foreach my $rec (@$records) {
9431: my %temp = &record_sep($rec);
9432: if (! grep(/\S/, values(%temp))) { next; }
9433: if (%temp) {
9434: $samples[$got]=\%temp;
9435: $got++;
9436: if ($got == $toget) { last; }
9437: }
9438: }
9439: return \@samples;
9440: }
9441:
1.144 matthew 9442: ######################################################
9443: ######################################################
9444:
1.56 matthew 9445: =pod
9446:
1.648 raeburn 9447: =item * &csv_print_samples($r,$records)
1.41 ng 9448:
9449: Prints a table of sample values from each column uploaded $r is an
9450: Apache Request ref, $records is an arrayref from
9451: &Apache::loncommon::upfile_record_sep
9452:
9453: =cut
9454:
1.144 matthew 9455: ######################################################
9456: ######################################################
1.31 albertel 9457: sub csv_print_samples {
9458: my ($r,$records) = @_;
1.662 bisitz 9459: my $samples = &get_samples($records,5);
1.301 albertel 9460:
1.594 raeburn 9461: $r->print(&mt('Samples').'<br />'.&start_data_table().
9462: &start_data_table_header_row());
1.356 albertel 9463: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 9464: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 9465: $r->print(&end_data_table_header_row());
1.301 albertel 9466: foreach my $hash (@$samples) {
1.594 raeburn 9467: $r->print(&start_data_table_row());
1.356 albertel 9468: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 9469: $r->print('<td>');
1.356 albertel 9470: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 9471: $r->print('</td>');
9472: }
1.594 raeburn 9473: $r->print(&end_data_table_row());
1.31 albertel 9474: }
1.594 raeburn 9475: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 9476: }
9477:
1.144 matthew 9478: ######################################################
9479: ######################################################
9480:
1.56 matthew 9481: =pod
9482:
1.648 raeburn 9483: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 9484:
9485: Prints a table to create associations between values and table columns.
1.144 matthew 9486:
1.41 ng 9487: $r is an Apache Request ref,
9488: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 9489: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 9490:
9491: =cut
9492:
1.144 matthew 9493: ######################################################
9494: ######################################################
1.31 albertel 9495: sub csv_print_select_table {
9496: my ($r,$records,$d) = @_;
1.301 albertel 9497: my $i=0;
9498: my $samples = &get_samples($records,1);
1.144 matthew 9499: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 9500: &start_data_table().&start_data_table_header_row().
1.144 matthew 9501: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 9502: '<th>'.&mt('Column').'</th>'.
9503: &end_data_table_header_row()."\n");
1.356 albertel 9504: foreach my $array_ref (@$d) {
9505: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 9506: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 9507:
1.875 bisitz 9508: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 9509: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 9510: $r->print('<option value="none"></option>');
1.356 albertel 9511: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
9512: $r->print('<option value="'.$sample.'"'.
9513: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 9514: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 9515: }
1.594 raeburn 9516: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 9517: $i++;
9518: }
1.594 raeburn 9519: $r->print(&end_data_table());
1.31 albertel 9520: $i--;
9521: return $i;
9522: }
1.56 matthew 9523:
1.144 matthew 9524: ######################################################
9525: ######################################################
9526:
1.56 matthew 9527: =pod
1.31 albertel 9528:
1.648 raeburn 9529: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 9530:
9531: Prints a table of sample values from the upload and can make associate samples to internal names.
9532:
9533: $r is an Apache Request ref,
9534: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
9535: $d is an array of 2 element arrays (internal name, displayed name)
9536:
9537: =cut
9538:
1.144 matthew 9539: ######################################################
9540: ######################################################
1.31 albertel 9541: sub csv_samples_select_table {
9542: my ($r,$records,$d) = @_;
9543: my $i=0;
1.144 matthew 9544: #
1.662 bisitz 9545: my $max_samples = 5;
9546: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 9547: $r->print(&start_data_table().
9548: &start_data_table_header_row().'<th>'.
9549: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
9550: &end_data_table_header_row());
1.301 albertel 9551:
9552: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 9553: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 9554: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 9555: foreach my $option (@$d) {
9556: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 9557: $r->print('<option value="'.$value.'"'.
1.253 albertel 9558: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 9559: $display.'</option>');
1.31 albertel 9560: }
9561: $r->print('</select></td><td>');
1.662 bisitz 9562: foreach my $line (0..($max_samples-1)) {
1.301 albertel 9563: if (defined($samples->[$line]{$key})) {
9564: $r->print($samples->[$line]{$key}."<br />\n");
9565: }
9566: }
1.594 raeburn 9567: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9568: $i++;
9569: }
1.594 raeburn 9570: $r->print(&end_data_table());
1.31 albertel 9571: $i--;
9572: return($i);
1.115 matthew 9573: }
9574:
1.144 matthew 9575: ######################################################
9576: ######################################################
9577:
1.115 matthew 9578: =pod
9579:
1.648 raeburn 9580: =item * &clean_excel_name($name)
1.115 matthew 9581:
9582: Returns a replacement for $name which does not contain any illegal characters.
9583:
9584: =cut
9585:
1.144 matthew 9586: ######################################################
9587: ######################################################
1.115 matthew 9588: sub clean_excel_name {
9589: my ($name) = @_;
9590: $name =~ s/[:\*\?\/\\]//g;
9591: if (length($name) > 31) {
9592: $name = substr($name,0,31);
9593: }
9594: return $name;
1.25 albertel 9595: }
1.84 albertel 9596:
1.85 albertel 9597: =pod
9598:
1.648 raeburn 9599: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9600:
9601: Returns either 1 or undef
9602:
9603: 1 if the part is to be hidden, undef if it is to be shown
9604:
9605: Arguments are:
9606:
9607: $id the id of the part to be checked
9608: $symb, optional the symb of the resource to check
9609: $udom, optional the domain of the user to check for
9610: $uname, optional the username of the user to check for
9611:
9612: =cut
1.84 albertel 9613:
9614: sub check_if_partid_hidden {
9615: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9616: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9617: $symb,$udom,$uname);
1.141 albertel 9618: my $truth=1;
9619: #if the string starts with !, then the list is the list to show not hide
9620: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9621: my @hiddenlist=split(/,/,$hiddenparts);
9622: foreach my $checkid (@hiddenlist) {
1.141 albertel 9623: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9624: }
1.141 albertel 9625: return !$truth;
1.84 albertel 9626: }
1.127 matthew 9627:
1.138 matthew 9628:
9629: ############################################################
9630: ############################################################
9631:
9632: =pod
9633:
1.157 matthew 9634: =back
9635:
1.138 matthew 9636: =head1 cgi-bin script and graphing routines
9637:
1.157 matthew 9638: =over 4
9639:
1.648 raeburn 9640: =item * &get_cgi_id()
1.138 matthew 9641:
9642: Inputs: none
9643:
9644: Returns an id which can be used to pass environment variables
9645: to various cgi-bin scripts. These environment variables will
9646: be removed from the users environment after a given time by
9647: the routine &Apache::lonnet::transfer_profile_to_env.
9648:
9649: =cut
9650:
9651: ############################################################
9652: ############################################################
1.152 albertel 9653: my $uniq=0;
1.136 matthew 9654: sub get_cgi_id {
1.154 albertel 9655: $uniq=($uniq+1)%100000;
1.280 albertel 9656: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9657: }
9658:
1.127 matthew 9659: ############################################################
9660: ############################################################
9661:
9662: =pod
9663:
1.648 raeburn 9664: =item * &DrawBarGraph()
1.127 matthew 9665:
1.138 matthew 9666: Facilitates the plotting of data in a (stacked) bar graph.
9667: Puts plot definition data into the users environment in order for
9668: graph.png to plot it. Returns an <img> tag for the plot.
9669: The bars on the plot are labeled '1','2',...,'n'.
9670:
9671: Inputs:
9672:
9673: =over 4
9674:
9675: =item $Title: string, the title of the plot
9676:
9677: =item $xlabel: string, text describing the X-axis of the plot
9678:
9679: =item $ylabel: string, text describing the Y-axis of the plot
9680:
9681: =item $Max: scalar, the maximum Y value to use in the plot
9682: If $Max is < any data point, the graph will not be rendered.
9683:
1.140 matthew 9684: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9685: they are plotted. If undefined, default values will be used.
9686:
1.178 matthew 9687: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9688:
1.138 matthew 9689: =item @Values: An array of array references. Each array reference holds data
9690: to be plotted in a stacked bar chart.
9691:
1.239 matthew 9692: =item If the final element of @Values is a hash reference the key/value
9693: pairs will be added to the graph definition.
9694:
1.138 matthew 9695: =back
9696:
9697: Returns:
9698:
9699: An <img> tag which references graph.png and the appropriate identifying
9700: information for the plot.
9701:
1.127 matthew 9702: =cut
9703:
9704: ############################################################
9705: ############################################################
1.134 matthew 9706: sub DrawBarGraph {
1.178 matthew 9707: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9708: #
9709: if (! defined($colors)) {
9710: $colors = ['#33ff00',
9711: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9712: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9713: ];
9714: }
1.228 matthew 9715: my $extra_settings = {};
9716: if (ref($Values[-1]) eq 'HASH') {
9717: $extra_settings = pop(@Values);
9718: }
1.127 matthew 9719: #
1.136 matthew 9720: my $identifier = &get_cgi_id();
9721: my $id = 'cgi.'.$identifier;
1.129 matthew 9722: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9723: return '';
9724: }
1.225 matthew 9725: #
9726: my @Labels;
9727: if (defined($labels)) {
9728: @Labels = @$labels;
9729: } else {
9730: for (my $i=0;$i<@{$Values[0]};$i++) {
9731: push (@Labels,$i+1);
9732: }
9733: }
9734: #
1.129 matthew 9735: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9736: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9737: my %ValuesHash;
9738: my $NumSets=1;
9739: foreach my $array (@Values) {
9740: next if (! ref($array));
1.136 matthew 9741: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9742: join(',',@$array);
1.129 matthew 9743: }
1.127 matthew 9744: #
1.136 matthew 9745: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9746: if ($NumBars < 3) {
9747: $width = 120+$NumBars*32;
1.220 matthew 9748: $xskip = 1;
1.225 matthew 9749: $bar_width = 30;
9750: } elsif ($NumBars < 5) {
9751: $width = 120+$NumBars*20;
9752: $xskip = 1;
9753: $bar_width = 20;
1.220 matthew 9754: } elsif ($NumBars < 10) {
1.136 matthew 9755: $width = 120+$NumBars*15;
9756: $xskip = 1;
9757: $bar_width = 15;
9758: } elsif ($NumBars <= 25) {
9759: $width = 120+$NumBars*11;
9760: $xskip = 5;
9761: $bar_width = 8;
9762: } elsif ($NumBars <= 50) {
9763: $width = 120+$NumBars*8;
9764: $xskip = 5;
9765: $bar_width = 4;
9766: } else {
9767: $width = 120+$NumBars*8;
9768: $xskip = 5;
9769: $bar_width = 4;
9770: }
9771: #
1.137 matthew 9772: $Max = 1 if ($Max < 1);
9773: if ( int($Max) < $Max ) {
9774: $Max++;
9775: $Max = int($Max);
9776: }
1.127 matthew 9777: $Title = '' if (! defined($Title));
9778: $xlabel = '' if (! defined($xlabel));
9779: $ylabel = '' if (! defined($ylabel));
1.369 www 9780: $ValuesHash{$id.'.title'} = &escape($Title);
9781: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9782: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9783: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9784: $ValuesHash{$id.'.NumBars'} = $NumBars;
9785: $ValuesHash{$id.'.NumSets'} = $NumSets;
9786: $ValuesHash{$id.'.PlotType'} = 'bar';
9787: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9788: $ValuesHash{$id.'.height'} = $height;
9789: $ValuesHash{$id.'.width'} = $width;
9790: $ValuesHash{$id.'.xskip'} = $xskip;
9791: $ValuesHash{$id.'.bar_width'} = $bar_width;
9792: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9793: #
1.228 matthew 9794: # Deal with other parameters
9795: while (my ($key,$value) = each(%$extra_settings)) {
9796: $ValuesHash{$id.'.'.$key} = $value;
9797: }
9798: #
1.646 raeburn 9799: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9800: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9801: }
9802:
9803: ############################################################
9804: ############################################################
9805:
9806: =pod
9807:
1.648 raeburn 9808: =item * &DrawXYGraph()
1.137 matthew 9809:
1.138 matthew 9810: Facilitates the plotting of data in an XY graph.
9811: Puts plot definition data into the users environment in order for
9812: graph.png to plot it. Returns an <img> tag for the plot.
9813:
9814: Inputs:
9815:
9816: =over 4
9817:
9818: =item $Title: string, the title of the plot
9819:
9820: =item $xlabel: string, text describing the X-axis of the plot
9821:
9822: =item $ylabel: string, text describing the Y-axis of the plot
9823:
9824: =item $Max: scalar, the maximum Y value to use in the plot
9825: If $Max is < any data point, the graph will not be rendered.
9826:
9827: =item $colors: Array ref containing the hex color codes for the data to be
9828: plotted in. If undefined, default values will be used.
9829:
9830: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9831:
9832: =item $Ydata: Array ref containing Array refs.
1.185 www 9833: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9834:
9835: =item %Values: hash indicating or overriding any default values which are
9836: passed to graph.png.
9837: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9838:
9839: =back
9840:
9841: Returns:
9842:
9843: An <img> tag which references graph.png and the appropriate identifying
9844: information for the plot.
9845:
1.137 matthew 9846: =cut
9847:
9848: ############################################################
9849: ############################################################
9850: sub DrawXYGraph {
9851: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9852: #
9853: # Create the identifier for the graph
9854: my $identifier = &get_cgi_id();
9855: my $id = 'cgi.'.$identifier;
9856: #
9857: $Title = '' if (! defined($Title));
9858: $xlabel = '' if (! defined($xlabel));
9859: $ylabel = '' if (! defined($ylabel));
9860: my %ValuesHash =
9861: (
1.369 www 9862: $id.'.title' => &escape($Title),
9863: $id.'.xlabel' => &escape($xlabel),
9864: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9865: $id.'.y_max_value'=> $Max,
9866: $id.'.labels' => join(',',@$Xlabels),
9867: $id.'.PlotType' => 'XY',
9868: );
9869: #
9870: if (defined($colors) && ref($colors) eq 'ARRAY') {
9871: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9872: }
9873: #
9874: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9875: return '';
9876: }
9877: my $NumSets=1;
1.138 matthew 9878: foreach my $array (@{$Ydata}){
1.137 matthew 9879: next if (! ref($array));
9880: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9881: }
1.138 matthew 9882: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9883: #
9884: # Deal with other parameters
9885: while (my ($key,$value) = each(%Values)) {
9886: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9887: }
9888: #
1.646 raeburn 9889: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9890: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9891: }
9892:
9893: ############################################################
9894: ############################################################
9895:
9896: =pod
9897:
1.648 raeburn 9898: =item * &DrawXYYGraph()
1.138 matthew 9899:
9900: Facilitates the plotting of data in an XY graph with two Y axes.
9901: Puts plot definition data into the users environment in order for
9902: graph.png to plot it. Returns an <img> tag for the plot.
9903:
9904: Inputs:
9905:
9906: =over 4
9907:
9908: =item $Title: string, the title of the plot
9909:
9910: =item $xlabel: string, text describing the X-axis of the plot
9911:
9912: =item $ylabel: string, text describing the Y-axis of the plot
9913:
9914: =item $colors: Array ref containing the hex color codes for the data to be
9915: plotted in. If undefined, default values will be used.
9916:
9917: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9918:
9919: =item $Ydata1: The first data set
9920:
9921: =item $Min1: The minimum value of the left Y-axis
9922:
9923: =item $Max1: The maximum value of the left Y-axis
9924:
9925: =item $Ydata2: The second data set
9926:
9927: =item $Min2: The minimum value of the right Y-axis
9928:
9929: =item $Max2: The maximum value of the left Y-axis
9930:
9931: =item %Values: hash indicating or overriding any default values which are
9932: passed to graph.png.
9933: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9934:
9935: =back
9936:
9937: Returns:
9938:
9939: An <img> tag which references graph.png and the appropriate identifying
9940: information for the plot.
1.136 matthew 9941:
9942: =cut
9943:
9944: ############################################################
9945: ############################################################
1.137 matthew 9946: sub DrawXYYGraph {
9947: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9948: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9949: #
9950: # Create the identifier for the graph
9951: my $identifier = &get_cgi_id();
9952: my $id = 'cgi.'.$identifier;
9953: #
9954: $Title = '' if (! defined($Title));
9955: $xlabel = '' if (! defined($xlabel));
9956: $ylabel = '' if (! defined($ylabel));
9957: my %ValuesHash =
9958: (
1.369 www 9959: $id.'.title' => &escape($Title),
9960: $id.'.xlabel' => &escape($xlabel),
9961: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9962: $id.'.labels' => join(',',@$Xlabels),
9963: $id.'.PlotType' => 'XY',
9964: $id.'.NumSets' => 2,
1.137 matthew 9965: $id.'.two_axes' => 1,
9966: $id.'.y1_max_value' => $Max1,
9967: $id.'.y1_min_value' => $Min1,
9968: $id.'.y2_max_value' => $Max2,
9969: $id.'.y2_min_value' => $Min2,
1.136 matthew 9970: );
9971: #
1.137 matthew 9972: if (defined($colors) && ref($colors) eq 'ARRAY') {
9973: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9974: }
9975: #
9976: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9977: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9978: return '';
9979: }
9980: my $NumSets=1;
1.137 matthew 9981: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9982: next if (! ref($array));
9983: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9984: }
9985: #
9986: # Deal with other parameters
9987: while (my ($key,$value) = each(%Values)) {
9988: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9989: }
9990: #
1.646 raeburn 9991: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9992: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9993: }
9994:
9995: ############################################################
9996: ############################################################
9997:
9998: =pod
9999:
1.157 matthew 10000: =back
10001:
1.139 matthew 10002: =head1 Statistics helper routines?
10003:
10004: Bad place for them but what the hell.
10005:
1.157 matthew 10006: =over 4
10007:
1.648 raeburn 10008: =item * &chartlink()
1.139 matthew 10009:
10010: Returns a link to the chart for a specific student.
10011:
10012: Inputs:
10013:
10014: =over 4
10015:
10016: =item $linktext: The text of the link
10017:
10018: =item $sname: The students username
10019:
10020: =item $sdomain: The students domain
10021:
10022: =back
10023:
1.157 matthew 10024: =back
10025:
1.139 matthew 10026: =cut
10027:
10028: ############################################################
10029: ############################################################
10030: sub chartlink {
10031: my ($linktext, $sname, $sdomain) = @_;
10032: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 10033: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 10034: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 10035: '">'.$linktext.'</a>';
1.153 matthew 10036: }
10037:
10038: #######################################################
10039: #######################################################
10040:
10041: =pod
10042:
10043: =head1 Course Environment Routines
1.157 matthew 10044:
10045: =over 4
1.153 matthew 10046:
1.648 raeburn 10047: =item * &restore_course_settings()
1.153 matthew 10048:
1.648 raeburn 10049: =item * &store_course_settings()
1.153 matthew 10050:
10051: Restores/Store indicated form parameters from the course environment.
10052: Will not overwrite existing values of the form parameters.
10053:
10054: Inputs:
10055: a scalar describing the data (e.g. 'chart', 'problem_analysis')
10056:
10057: a hash ref describing the data to be stored. For example:
10058:
10059: %Save_Parameters = ('Status' => 'scalar',
10060: 'chartoutputmode' => 'scalar',
10061: 'chartoutputdata' => 'scalar',
10062: 'Section' => 'array',
1.373 raeburn 10063: 'Group' => 'array',
1.153 matthew 10064: 'StudentData' => 'array',
10065: 'Maps' => 'array');
10066:
10067: Returns: both routines return nothing
10068:
1.631 raeburn 10069: =back
10070:
1.153 matthew 10071: =cut
10072:
10073: #######################################################
10074: #######################################################
10075: sub store_course_settings {
1.496 albertel 10076: return &store_settings($env{'request.course.id'},@_);
10077: }
10078:
10079: sub store_settings {
1.153 matthew 10080: # save to the environment
10081: # appenv the same items, just to be safe
1.300 albertel 10082: my $udom = $env{'user.domain'};
10083: my $uname = $env{'user.name'};
1.496 albertel 10084: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10085: my %SaveHash;
10086: my %AppHash;
10087: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 10088: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 10089: my $envname = 'environment.'.$basename;
1.258 albertel 10090: if (exists($env{'form.'.$setting})) {
1.153 matthew 10091: # Save this value away
10092: if ($type eq 'scalar' &&
1.258 albertel 10093: (! exists($env{$envname}) ||
10094: $env{$envname} ne $env{'form.'.$setting})) {
10095: $SaveHash{$basename} = $env{'form.'.$setting};
10096: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 10097: } elsif ($type eq 'array') {
10098: my $stored_form;
1.258 albertel 10099: if (ref($env{'form.'.$setting})) {
1.153 matthew 10100: $stored_form = join(',',
10101: map {
1.369 www 10102: &escape($_);
1.258 albertel 10103: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 10104: } else {
10105: $stored_form =
1.369 www 10106: &escape($env{'form.'.$setting});
1.153 matthew 10107: }
10108: # Determine if the array contents are the same.
1.258 albertel 10109: if ($stored_form ne $env{$envname}) {
1.153 matthew 10110: $SaveHash{$basename} = $stored_form;
10111: $AppHash{$envname} = $stored_form;
10112: }
10113: }
10114: }
10115: }
10116: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 10117: $udom,$uname);
1.153 matthew 10118: if ($put_result !~ /^(ok|delayed)/) {
10119: &Apache::lonnet::logthis('unable to save form parameters, '.
10120: 'got error:'.$put_result);
10121: }
10122: # Make sure these settings stick around in this session, too
1.646 raeburn 10123: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 10124: return;
10125: }
10126:
10127: sub restore_course_settings {
1.499 albertel 10128: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 10129: }
10130:
10131: sub restore_settings {
10132: my ($context,$prefix,$Settings) = @_;
1.153 matthew 10133: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 10134: next if (exists($env{'form.'.$setting}));
1.496 albertel 10135: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 10136: '.'.$setting;
1.258 albertel 10137: if (exists($env{$envname})) {
1.153 matthew 10138: if ($type eq 'scalar') {
1.258 albertel 10139: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 10140: } elsif ($type eq 'array') {
1.258 albertel 10141: $env{'form.'.$setting} = [
1.153 matthew 10142: map {
1.369 www 10143: &unescape($_);
1.258 albertel 10144: } split(',',$env{$envname})
1.153 matthew 10145: ];
10146: }
10147: }
10148: }
1.127 matthew 10149: }
10150:
1.618 raeburn 10151: #######################################################
10152: #######################################################
10153:
10154: =pod
10155:
10156: =head1 Domain E-mail Routines
10157:
10158: =over 4
10159:
1.648 raeburn 10160: =item * &build_recipient_list()
1.618 raeburn 10161:
1.884 raeburn 10162: Build recipient lists for five types of e-mail:
1.766 raeburn 10163: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 10164: (d) Help requests, (e) Course requests needing approval, generated by
10165: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
10166: loncoursequeueadmin.pm respectively.
1.618 raeburn 10167:
10168: Inputs:
1.619 raeburn 10169: defmail (scalar - email address of default recipient),
1.618 raeburn 10170: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 10171: defdom (domain for which to retrieve configuration settings),
10172: origmail (scalar - email address of recipient from loncapa.conf,
10173: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 10174:
1.655 raeburn 10175: Returns: comma separated list of addresses to which to send e-mail.
10176:
10177: =back
1.618 raeburn 10178:
10179: =cut
10180:
10181: ############################################################
10182: ############################################################
10183: sub build_recipient_list {
1.619 raeburn 10184: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 10185: my @recipients;
10186: my $otheremails;
10187: my %domconfig =
10188: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
10189: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 10190: if (exists($domconfig{'contacts'}{$mailing})) {
10191: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
10192: my @contacts = ('adminemail','supportemail');
10193: foreach my $item (@contacts) {
10194: if ($domconfig{'contacts'}{$mailing}{$item}) {
10195: my $addr = $domconfig{'contacts'}{$item};
10196: if (!grep(/^\Q$addr\E$/,@recipients)) {
10197: push(@recipients,$addr);
10198: }
1.619 raeburn 10199: }
1.766 raeburn 10200: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 10201: }
10202: }
1.766 raeburn 10203: } elsif ($origmail ne '') {
10204: push(@recipients,$origmail);
1.618 raeburn 10205: }
1.619 raeburn 10206: } elsif ($origmail ne '') {
10207: push(@recipients,$origmail);
1.618 raeburn 10208: }
1.688 raeburn 10209: if (defined($defmail)) {
10210: if ($defmail ne '') {
10211: push(@recipients,$defmail);
10212: }
1.618 raeburn 10213: }
10214: if ($otheremails) {
1.619 raeburn 10215: my @others;
10216: if ($otheremails =~ /,/) {
10217: @others = split(/,/,$otheremails);
1.618 raeburn 10218: } else {
1.619 raeburn 10219: push(@others,$otheremails);
10220: }
10221: foreach my $addr (@others) {
10222: if (!grep(/^\Q$addr\E$/,@recipients)) {
10223: push(@recipients,$addr);
10224: }
1.618 raeburn 10225: }
10226: }
1.619 raeburn 10227: my $recipientlist = join(',',@recipients);
1.618 raeburn 10228: return $recipientlist;
10229: }
10230:
1.127 matthew 10231: ############################################################
10232: ############################################################
1.154 albertel 10233:
1.655 raeburn 10234: =pod
10235:
10236: =head1 Course Catalog Routines
10237:
10238: =over 4
10239:
10240: =item * &gather_categories()
10241:
10242: Converts category definitions - keys of categories hash stored in
10243: coursecategories in configuration.db on the primary library server in a
10244: domain - to an array. Also generates javascript and idx hash used to
10245: generate Domain Coordinator interface for editing Course Categories.
10246:
10247: Inputs:
1.663 raeburn 10248:
1.655 raeburn 10249: categories (reference to hash of category definitions).
1.663 raeburn 10250:
1.655 raeburn 10251: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10252: categories and subcategories).
1.663 raeburn 10253:
1.655 raeburn 10254: idx (reference to hash of counters used in Domain Coordinator interface for
10255: editing Course Categories).
1.663 raeburn 10256:
1.655 raeburn 10257: jsarray (reference to array of categories used to create Javascript arrays for
10258: Domain Coordinator interface for editing Course Categories).
10259:
10260: Returns: nothing
10261:
10262: Side effects: populates cats, idx and jsarray.
10263:
10264: =cut
10265:
10266: sub gather_categories {
10267: my ($categories,$cats,$idx,$jsarray) = @_;
10268: my %counters;
10269: my $num = 0;
10270: foreach my $item (keys(%{$categories})) {
10271: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10272: if ($container eq '' && $depth == 0) {
10273: $cats->[$depth][$categories->{$item}] = $cat;
10274: } else {
10275: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
10276: }
10277: my ($escitem,$tail) = split(/:/,$item,2);
10278: if ($counters{$tail} eq '') {
10279: $counters{$tail} = $num;
10280: $num ++;
10281: }
10282: if (ref($idx) eq 'HASH') {
10283: $idx->{$item} = $counters{$tail};
10284: }
10285: if (ref($jsarray) eq 'ARRAY') {
10286: push(@{$jsarray->[$counters{$tail}]},$item);
10287: }
10288: }
10289: return;
10290: }
10291:
10292: =pod
10293:
10294: =item * &extract_categories()
10295:
10296: Used to generate breadcrumb trails for course categories.
10297:
10298: Inputs:
1.663 raeburn 10299:
1.655 raeburn 10300: categories (reference to hash of category definitions).
1.663 raeburn 10301:
1.655 raeburn 10302: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10303: categories and subcategories).
1.663 raeburn 10304:
1.655 raeburn 10305: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 10306:
1.655 raeburn 10307: allitems (reference to hash - key is category key
10308: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10309:
1.655 raeburn 10310: idx (reference to hash of counters used in Domain Coordinator interface for
10311: editing Course Categories).
1.663 raeburn 10312:
1.655 raeburn 10313: jsarray (reference to array of categories used to create Javascript arrays for
10314: Domain Coordinator interface for editing Course Categories).
10315:
1.665 raeburn 10316: subcats (reference to hash of arrays containing all subcategories within each
10317: category, -recursive)
10318:
1.655 raeburn 10319: Returns: nothing
10320:
10321: Side effects: populates trails and allitems hash references.
10322:
10323: =cut
10324:
10325: sub extract_categories {
1.665 raeburn 10326: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 10327: if (ref($categories) eq 'HASH') {
10328: &gather_categories($categories,$cats,$idx,$jsarray);
10329: if (ref($cats->[0]) eq 'ARRAY') {
10330: for (my $i=0; $i<@{$cats->[0]}; $i++) {
10331: my $name = $cats->[0][$i];
10332: my $item = &escape($name).'::0';
10333: my $trailstr;
10334: if ($name eq 'instcode') {
10335: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 10336: } elsif ($name eq 'communities') {
10337: $trailstr = &mt('Communities');
1.655 raeburn 10338: } else {
10339: $trailstr = $name;
10340: }
10341: if ($allitems->{$item} eq '') {
10342: push(@{$trails},$trailstr);
10343: $allitems->{$item} = scalar(@{$trails})-1;
10344: }
10345: my @parents = ($name);
10346: if (ref($cats->[1]{$name}) eq 'ARRAY') {
10347: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
10348: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 10349: if (ref($subcats) eq 'HASH') {
10350: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
10351: }
10352: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
10353: }
10354: } else {
10355: if (ref($subcats) eq 'HASH') {
10356: $subcats->{$item} = [];
1.655 raeburn 10357: }
10358: }
10359: }
10360: }
10361: }
10362: return;
10363: }
10364:
10365: =pod
10366:
10367: =item *&recurse_categories()
10368:
10369: Recursively used to generate breadcrumb trails for course categories.
10370:
10371: Inputs:
1.663 raeburn 10372:
1.655 raeburn 10373: cats (reference to array of arrays/hashes which encapsulates hierarchy of
10374: categories and subcategories).
1.663 raeburn 10375:
1.655 raeburn 10376: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 10377:
10378: category (current course category, for which breadcrumb trail is being generated).
10379:
10380: trails (reference to array of breadcrumb trails for each category).
10381:
1.655 raeburn 10382: allitems (reference to hash - key is category key
10383: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 10384:
1.655 raeburn 10385: parents (array containing containers directories for current category,
10386: back to top level).
10387:
10388: Returns: nothing
10389:
10390: Side effects: populates trails and allitems hash references
10391:
10392: =cut
10393:
10394: sub recurse_categories {
1.665 raeburn 10395: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 10396: my $shallower = $depth - 1;
10397: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
10398: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
10399: my $name = $cats->[$depth]{$category}[$k];
10400: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10401: my $trailstr = join(' -> ',(@{$parents},$category));
10402: if ($allitems->{$item} eq '') {
10403: push(@{$trails},$trailstr);
10404: $allitems->{$item} = scalar(@{$trails})-1;
10405: }
10406: my $deeper = $depth+1;
10407: push(@{$parents},$category);
1.665 raeburn 10408: if (ref($subcats) eq 'HASH') {
10409: my $subcat = &escape($name).':'.$category.':'.$depth;
10410: for (my $j=@{$parents}; $j>=0; $j--) {
10411: my $higher;
10412: if ($j > 0) {
10413: $higher = &escape($parents->[$j]).':'.
10414: &escape($parents->[$j-1]).':'.$j;
10415: } else {
10416: $higher = &escape($parents->[$j]).'::'.$j;
10417: }
10418: push(@{$subcats->{$higher}},$subcat);
10419: }
10420: }
10421: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
10422: $subcats);
1.655 raeburn 10423: pop(@{$parents});
10424: }
10425: } else {
10426: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
10427: my $trailstr = join(' -> ',(@{$parents},$category));
10428: if ($allitems->{$item} eq '') {
10429: push(@{$trails},$trailstr);
10430: $allitems->{$item} = scalar(@{$trails})-1;
10431: }
10432: }
10433: return;
10434: }
10435:
1.663 raeburn 10436: =pod
10437:
10438: =item *&assign_categories_table()
10439:
10440: Create a datatable for display of hierarchical categories in a domain,
10441: with checkboxes to allow a course to be categorized.
10442:
10443: Inputs:
10444:
10445: cathash - reference to hash of categories defined for the domain (from
10446: configuration.db)
10447:
10448: currcat - scalar with an & separated list of categories assigned to a course.
10449:
1.919 raeburn 10450: type - scalar contains course type (Course or Community).
10451:
1.663 raeburn 10452: Returns: $output (markup to be displayed)
10453:
10454: =cut
10455:
10456: sub assign_categories_table {
1.919 raeburn 10457: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 10458: my $output;
10459: if (ref($cathash) eq 'HASH') {
10460: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
10461: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
10462: $maxdepth = scalar(@cats);
10463: if (@cats > 0) {
10464: my $itemcount = 0;
10465: if (ref($cats[0]) eq 'ARRAY') {
10466: my @currcategories;
10467: if ($currcat ne '') {
10468: @currcategories = split('&',$currcat);
10469: }
1.919 raeburn 10470: my $table;
1.663 raeburn 10471: for (my $i=0; $i<@{$cats[0]}; $i++) {
10472: my $parent = $cats[0][$i];
1.919 raeburn 10473: next if ($parent eq 'instcode');
10474: if ($type eq 'Community') {
10475: next unless ($parent eq 'communities');
10476: } else {
10477: next if ($parent eq 'communities');
10478: }
1.663 raeburn 10479: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10480: my $item = &escape($parent).'::0';
10481: my $checked = '';
10482: if (@currcategories > 0) {
10483: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 10484: $checked = ' checked="checked"';
1.663 raeburn 10485: }
10486: }
1.919 raeburn 10487: my $parent_title = $parent;
10488: if ($parent eq 'communities') {
10489: $parent_title = &mt('Communities');
10490: }
10491: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
10492: '<input type="checkbox" name="usecategory" value="'.
10493: $item.'"'.$checked.' />'.$parent_title.'</span>'.
10494: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 10495: my $depth = 1;
10496: push(@path,$parent);
1.919 raeburn 10497: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 10498: pop(@path);
1.919 raeburn 10499: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 10500: $itemcount ++;
10501: }
1.919 raeburn 10502: if ($itemcount) {
10503: $output = &Apache::loncommon::start_data_table().
10504: $table.
10505: &Apache::loncommon::end_data_table();
10506: }
1.663 raeburn 10507: }
10508: }
10509: }
10510: return $output;
10511: }
10512:
10513: =pod
10514:
10515: =item *&assign_category_rows()
10516:
10517: Create a datatable row for display of nested categories in a domain,
10518: with checkboxes to allow a course to be categorized,called recursively.
10519:
10520: Inputs:
10521:
10522: itemcount - track row number for alternating colors
10523:
10524: cats - reference to array of arrays/hashes which encapsulates hierarchy of
10525: categories and subcategories.
10526:
10527: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
10528:
10529: parent - parent of current category item
10530:
10531: path - Array containing all categories back up through the hierarchy from the
10532: current category to the top level.
10533:
10534: currcategories - reference to array of current categories assigned to the course
10535:
10536: Returns: $output (markup to be displayed).
10537:
10538: =cut
10539:
10540: sub assign_category_rows {
10541: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
10542: my ($text,$name,$item,$chgstr);
10543: if (ref($cats) eq 'ARRAY') {
10544: my $maxdepth = scalar(@{$cats});
10545: if (ref($cats->[$depth]) eq 'HASH') {
10546: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10547: my $numchildren = @{$cats->[$depth]{$parent}};
10548: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10549: $text .= '<td><table class="LC_datatable">';
10550: for (my $j=0; $j<$numchildren; $j++) {
10551: $name = $cats->[$depth]{$parent}[$j];
10552: $item = &escape($name).':'.&escape($parent).':'.$depth;
10553: my $deeper = $depth+1;
10554: my $checked = '';
10555: if (ref($currcategories) eq 'ARRAY') {
10556: if (@{$currcategories} > 0) {
10557: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 10558: $checked = ' checked="checked"';
1.663 raeburn 10559: }
10560: }
10561: }
1.664 raeburn 10562: $text .= '<tr><td><span class="LC_nobreak"><label>'.
10563: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 10564: $item.'"'.$checked.' />'.$name.'</label></span>'.
10565: '<input type="hidden" name="catname" value="'.$name.'" />'.
10566: '</td><td>';
1.663 raeburn 10567: if (ref($path) eq 'ARRAY') {
10568: push(@{$path},$name);
10569: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10570: pop(@{$path});
10571: }
10572: $text .= '</td></tr>';
10573: }
10574: $text .= '</table></td>';
10575: }
10576: }
10577: }
10578: return $text;
10579: }
10580:
1.655 raeburn 10581: ############################################################
10582: ############################################################
10583:
10584:
1.443 albertel 10585: sub commit_customrole {
1.664 raeburn 10586: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10587: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10588: ($start?', '.&mt('starting').' '.localtime($start):'').
10589: ($end?', ending '.localtime($end):'').': <b>'.
10590: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10591: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10592: '</b><br />';
10593: return $output;
10594: }
10595:
10596: sub commit_standardrole {
1.541 raeburn 10597: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10598: my ($output,$logmsg,$linefeed);
10599: if ($context eq 'auto') {
10600: $linefeed = "\n";
10601: } else {
10602: $linefeed = "<br />\n";
10603: }
1.443 albertel 10604: if ($three eq 'st') {
1.541 raeburn 10605: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10606: $one,$two,$sec,$context);
10607: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10608: ($result eq 'unknown_course') || ($result eq 'refused')) {
10609: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10610: } else {
1.541 raeburn 10611: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10612: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10613: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10614: if ($context eq 'auto') {
10615: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10616: } else {
10617: $output .= '<b>'.$result.'</b>'.$linefeed.
10618: &mt('Add to classlist').': <b>ok</b>';
10619: }
10620: $output .= $linefeed;
1.443 albertel 10621: }
10622: } else {
10623: $output = &mt('Assigning').' '.$three.' in '.$url.
10624: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10625: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10626: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10627: if ($context eq 'auto') {
10628: $output .= $result.$linefeed;
10629: } else {
10630: $output .= '<b>'.$result.'</b>'.$linefeed;
10631: }
1.443 albertel 10632: }
10633: return $output;
10634: }
10635:
10636: sub commit_studentrole {
1.541 raeburn 10637: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10638: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10639: if ($context eq 'auto') {
10640: $linefeed = "\n";
10641: } else {
10642: $linefeed = '<br />'."\n";
10643: }
1.443 albertel 10644: if (defined($one) && defined($two)) {
10645: my $cid=$one.'_'.$two;
10646: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10647: my $secchange = 0;
10648: my $expire_role_result;
10649: my $modify_section_result;
1.628 raeburn 10650: if ($oldsec ne '-1') {
10651: if ($oldsec ne $sec) {
1.443 albertel 10652: $secchange = 1;
1.628 raeburn 10653: my $now = time;
1.443 albertel 10654: my $uurl='/'.$cid;
10655: $uurl=~s/\_/\//g;
10656: if ($oldsec) {
10657: $uurl.='/'.$oldsec;
10658: }
1.626 raeburn 10659: $oldsecurl = $uurl;
1.628 raeburn 10660: $expire_role_result =
1.652 raeburn 10661: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10662: if ($env{'request.course.sec'} ne '') {
10663: if ($expire_role_result eq 'refused') {
10664: my @roles = ('st');
10665: my @statuses = ('previous');
10666: my @roledoms = ($one);
10667: my $withsec = 1;
10668: my %roleshash =
10669: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10670: \@statuses,\@roles,\@roledoms,$withsec);
10671: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10672: my ($oldstart,$oldend) =
10673: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10674: if ($oldend > 0 && $oldend <= $now) {
10675: $expire_role_result = 'ok';
10676: }
10677: }
10678: }
10679: }
1.443 albertel 10680: $result = $expire_role_result;
10681: }
10682: }
10683: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10684: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10685: if ($modify_section_result =~ /^ok/) {
10686: if ($secchange == 1) {
1.628 raeburn 10687: if ($sec eq '') {
10688: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10689: } else {
10690: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10691: }
1.443 albertel 10692: } elsif ($oldsec eq '-1') {
1.628 raeburn 10693: if ($sec eq '') {
10694: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10695: } else {
10696: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10697: }
1.443 albertel 10698: } else {
1.628 raeburn 10699: if ($sec eq '') {
10700: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10701: } else {
10702: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10703: }
1.443 albertel 10704: }
10705: } else {
1.628 raeburn 10706: if ($secchange) {
10707: $$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;
10708: } else {
10709: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10710: }
1.443 albertel 10711: }
10712: $result = $modify_section_result;
10713: } elsif ($secchange == 1) {
1.628 raeburn 10714: if ($oldsec eq '') {
10715: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10716: } else {
10717: $$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;
10718: }
1.626 raeburn 10719: if ($expire_role_result eq 'refused') {
10720: my $newsecurl = '/'.$cid;
10721: $newsecurl =~ s/\_/\//g;
10722: if ($sec ne '') {
10723: $newsecurl.='/'.$sec;
10724: }
10725: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10726: if ($sec eq '') {
10727: $$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;
10728: } else {
10729: $$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;
10730: }
10731: }
10732: }
1.443 albertel 10733: }
10734: } else {
1.626 raeburn 10735: $$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 10736: $result = "error: incomplete course id\n";
10737: }
10738: return $result;
10739: }
10740:
10741: ############################################################
10742: ############################################################
10743:
1.566 albertel 10744: sub check_clone {
1.578 raeburn 10745: my ($args,$linefeed) = @_;
1.566 albertel 10746: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10747: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10748: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10749: my $clonemsg;
10750: my $can_clone = 0;
1.944 raeburn 10751: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10752: if ($lctype ne 'community') {
10753: $lctype = 'course';
10754: }
1.566 albertel 10755: if ($clonehome eq 'no_host') {
1.944 raeburn 10756: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10757: $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'});
10758: } else {
10759: $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'});
10760: }
1.566 albertel 10761: } else {
10762: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10763: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10764: if ($clonedesc{'type'} ne 'Community') {
10765: $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'});
10766: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10767: }
10768: }
1.882 raeburn 10769: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10770: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10771: $can_clone = 1;
10772: } else {
10773: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10774: $args->{'clonedomain'},$args->{'clonecourse'});
10775: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10776: if (grep(/^\*$/,@cloners)) {
10777: $can_clone = 1;
10778: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10779: $can_clone = 1;
10780: } else {
1.908 raeburn 10781: my $ccrole = 'cc';
1.944 raeburn 10782: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10783: $ccrole = 'co';
10784: }
1.578 raeburn 10785: my %roleshash =
10786: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10787: $args->{'ccdomain'},
1.908 raeburn 10788: 'userroles',['active'],[$ccrole],
1.578 raeburn 10789: [$args->{'clonedomain'}]);
1.908 raeburn 10790: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10791: $can_clone = 1;
10792: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10793: $can_clone = 1;
10794: } else {
1.944 raeburn 10795: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10796: $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'});
10797: } else {
10798: $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'});
10799: }
1.578 raeburn 10800: }
1.566 albertel 10801: }
1.578 raeburn 10802: }
1.566 albertel 10803: }
10804: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10805: }
10806:
1.444 albertel 10807: sub construct_course {
1.885 raeburn 10808: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10809: my $outcome;
1.541 raeburn 10810: my $linefeed = '<br />'."\n";
10811: if ($context eq 'auto') {
10812: $linefeed = "\n";
10813: }
1.566 albertel 10814:
10815: #
10816: # Are we cloning?
10817: #
10818: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10819: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10820: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10821: if ($context ne 'auto') {
1.578 raeburn 10822: if ($clonemsg ne '') {
10823: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10824: }
1.566 albertel 10825: }
10826: $outcome .= $clonemsg.$linefeed;
10827:
10828: if (!$can_clone) {
10829: return (0,$outcome);
10830: }
10831: }
10832:
1.444 albertel 10833: #
10834: # Open course
10835: #
10836: my $crstype = lc($args->{'crstype'});
10837: my %cenv=();
10838: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10839: $args->{'cdescr'},
10840: $args->{'curl'},
10841: $args->{'course_home'},
10842: $args->{'nonstandard'},
10843: $args->{'crscode'},
10844: $args->{'ccuname'}.':'.
10845: $args->{'ccdomain'},
1.882 raeburn 10846: $args->{'crstype'},
1.885 raeburn 10847: $cnum,$context,$category);
1.444 albertel 10848:
10849: # Note: The testing routines depend on this being output; see
10850: # Utils::Course. This needs to at least be output as a comment
10851: # if anyone ever decides to not show this, and Utils::Course::new
10852: # will need to be suitably modified.
1.541 raeburn 10853: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10854: if ($$courseid =~ /^error:/) {
10855: return (0,$outcome);
10856: }
10857:
1.444 albertel 10858: #
10859: # Check if created correctly
10860: #
1.479 albertel 10861: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10862: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10863: if ($crsuhome eq 'no_host') {
10864: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10865: return (0,$outcome);
10866: }
1.541 raeburn 10867: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10868:
1.444 albertel 10869: #
1.566 albertel 10870: # Do the cloning
10871: #
10872: if ($can_clone && $cloneid) {
10873: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10874: if ($context ne 'auto') {
10875: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10876: }
10877: $outcome .= $clonemsg.$linefeed;
10878: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10879: # Copy all files
1.637 www 10880: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10881: # Restore URL
1.566 albertel 10882: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10883: # Restore title
1.566 albertel 10884: $cenv{'description'}=$oldcenv{'description'};
1.948.2.2 raeburn 10885: # Restore creation date, creator and creation context.
10886: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10887: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10888: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10889: # Mark as cloned
1.566 albertel 10890: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10891: # Need to clone grading mode
10892: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10893: $cenv{'grading'}=$newenv{'grading'};
10894: # Do not clone these environment entries
10895: &Apache::lonnet::del('environment',
10896: ['default_enrollment_start_date',
10897: 'default_enrollment_end_date',
10898: 'question.email',
10899: 'policy.email',
10900: 'comment.email',
10901: 'pch.users.denied',
1.725 raeburn 10902: 'plc.users.denied',
10903: 'hidefromcat',
10904: 'categories'],
1.638 www 10905: $$crsudom,$$crsunum);
1.444 albertel 10906: }
1.566 albertel 10907:
1.444 albertel 10908: #
10909: # Set environment (will override cloned, if existing)
10910: #
10911: my @sections = ();
10912: my @xlists = ();
10913: if ($args->{'crstype'}) {
10914: $cenv{'type'}=$args->{'crstype'};
10915: }
10916: if ($args->{'crsid'}) {
10917: $cenv{'courseid'}=$args->{'crsid'};
10918: }
10919: if ($args->{'crscode'}) {
10920: $cenv{'internal.coursecode'}=$args->{'crscode'};
10921: }
10922: if ($args->{'crsquota'} ne '') {
10923: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10924: } else {
10925: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10926: }
10927: if ($args->{'ccuname'}) {
10928: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10929: ':'.$args->{'ccdomain'};
10930: } else {
10931: $cenv{'internal.courseowner'} = $args->{'curruser'};
10932: }
10933: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10934: if ($args->{'crssections'}) {
10935: $cenv{'internal.sectionnums'} = '';
10936: if ($args->{'crssections'} =~ m/,/) {
10937: @sections = split/,/,$args->{'crssections'};
10938: } else {
10939: $sections[0] = $args->{'crssections'};
10940: }
10941: if (@sections > 0) {
10942: foreach my $item (@sections) {
10943: my ($sec,$gp) = split/:/,$item;
10944: my $class = $args->{'crscode'}.$sec;
10945: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10946: $cenv{'internal.sectionnums'} .= $item.',';
10947: unless ($addcheck eq 'ok') {
10948: push @badclasses, $class;
10949: }
10950: }
10951: $cenv{'internal.sectionnums'} =~ s/,$//;
10952: }
10953: }
10954: # do not hide course coordinator from staff listing,
10955: # even if privileged
10956: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10957: # add crosslistings
10958: if ($args->{'crsxlist'}) {
10959: $cenv{'internal.crosslistings'}='';
10960: if ($args->{'crsxlist'} =~ m/,/) {
10961: @xlists = split/,/,$args->{'crsxlist'};
10962: } else {
10963: $xlists[0] = $args->{'crsxlist'};
10964: }
10965: if (@xlists > 0) {
10966: foreach my $item (@xlists) {
10967: my ($xl,$gp) = split/:/,$item;
10968: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10969: $cenv{'internal.crosslistings'} .= $item.',';
10970: unless ($addcheck eq 'ok') {
10971: push @badclasses, $xl;
10972: }
10973: }
10974: $cenv{'internal.crosslistings'} =~ s/,$//;
10975: }
10976: }
10977: if ($args->{'autoadds'}) {
10978: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10979: }
10980: if ($args->{'autodrops'}) {
10981: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10982: }
10983: # check for notification of enrollment changes
10984: my @notified = ();
10985: if ($args->{'notify_owner'}) {
10986: if ($args->{'ccuname'} ne '') {
10987: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10988: }
10989: }
10990: if ($args->{'notify_dc'}) {
10991: if ($uname ne '') {
1.630 raeburn 10992: push(@notified,$uname.':'.$udom);
1.444 albertel 10993: }
10994: }
10995: if (@notified > 0) {
10996: my $notifylist;
10997: if (@notified > 1) {
10998: $notifylist = join(',',@notified);
10999: } else {
11000: $notifylist = $notified[0];
11001: }
11002: $cenv{'internal.notifylist'} = $notifylist;
11003: }
11004: if (@badclasses > 0) {
11005: my %lt=&Apache::lonlocal::texthash(
11006: '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',
11007: 'dnhr' => 'does not have rights to access enrollment in these classes',
11008: 'adby' => 'as determined by the policies of your institution on access to official classlists'
11009: );
1.541 raeburn 11010: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
11011: ' ('.$lt{'adby'}.')';
11012: if ($context eq 'auto') {
11013: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 11014: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 11015: foreach my $item (@badclasses) {
11016: if ($context eq 'auto') {
11017: $outcome .= " - $item\n";
11018: } else {
11019: $outcome .= "<li>$item</li>\n";
11020: }
11021: }
11022: if ($context eq 'auto') {
11023: $outcome .= $linefeed;
11024: } else {
1.566 albertel 11025: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 11026: }
11027: }
1.444 albertel 11028: }
11029: if ($args->{'no_end_date'}) {
11030: $args->{'endaccess'} = 0;
11031: }
11032: $cenv{'internal.autostart'}=$args->{'enrollstart'};
11033: $cenv{'internal.autoend'}=$args->{'enrollend'};
11034: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
11035: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
11036: if ($args->{'showphotos'}) {
11037: $cenv{'internal.showphotos'}=$args->{'showphotos'};
11038: }
11039: $cenv{'internal.authtype'} = $args->{'authtype'};
11040: $cenv{'internal.autharg'} = $args->{'autharg'};
11041: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
11042: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 11043: 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');
11044: if ($context eq 'auto') {
11045: $outcome .= $krb_msg;
11046: } else {
1.566 albertel 11047: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 11048: }
11049: $outcome .= $linefeed;
1.444 albertel 11050: }
11051: }
11052: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
11053: if ($args->{'setpolicy'}) {
11054: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11055: }
11056: if ($args->{'setcontent'}) {
11057: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
11058: }
11059: }
11060: if ($args->{'reshome'}) {
11061: $cenv{'reshome'}=$args->{'reshome'}.'/';
11062: $cenv{'reshome'}=~s/\/+$/\//;
11063: }
11064: #
11065: # course has keyed access
11066: #
11067: if ($args->{'setkeys'}) {
11068: $cenv{'keyaccess'}='yes';
11069: }
11070: # if specified, key authority is not course, but user
11071: # only active if keyaccess is yes
11072: if ($args->{'keyauth'}) {
1.487 albertel 11073: my ($user,$domain) = split(':',$args->{'keyauth'});
11074: $user = &LONCAPA::clean_username($user);
11075: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 11076: if ($user ne '' && $domain ne '') {
1.487 albertel 11077: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 11078: }
11079: }
11080:
11081: if ($args->{'disresdis'}) {
11082: $cenv{'pch.roles.denied'}='st';
11083: }
11084: if ($args->{'disablechat'}) {
11085: $cenv{'plc.roles.denied'}='st';
11086: }
11087:
11088: # Record we've not yet viewed the Course Initialization Helper for this
11089: # course
11090: $cenv{'course.helper.not.run'} = 1;
11091: #
11092: # Use new Randomseed
11093: #
11094: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
11095: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
11096: #
11097: # The encryption code and receipt prefix for this course
11098: #
11099: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
11100: $cenv{'internal.encpref'}=100+int(9*rand(99));
11101: #
11102: # By default, use standard grading
11103: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
11104:
1.541 raeburn 11105: $outcome .= $linefeed.&mt('Setting environment').': '.
11106: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11107: #
11108: # Open all assignments
11109: #
11110: if ($args->{'openall'}) {
11111: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
11112: my %storecontent = ($storeunder => time,
11113: $storeunder.'.type' => 'date_start');
11114:
11115: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 11116: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 11117: }
11118: #
11119: # Set first page
11120: #
11121: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
11122: || ($cloneid)) {
1.445 albertel 11123: use LONCAPA::map;
1.444 albertel 11124: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 11125:
11126: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
11127: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
11128:
1.444 albertel 11129: $outcome .= ($fatal?$errtext:'read ok').' - ';
11130: my $title; my $url;
11131: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 11132: $title=&mt('Syllabus');
1.444 albertel 11133: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
11134: } else {
1.948.2.5 raeburn 11135: $title=&mt('Table of Contents');
1.444 albertel 11136: $url='/adm/navmaps';
11137: }
1.445 albertel 11138:
11139: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
11140: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
11141:
11142: if ($errtext) { $fatal=2; }
1.541 raeburn 11143: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 11144: }
1.566 albertel 11145:
11146: return (1,$outcome);
1.444 albertel 11147: }
11148:
11149: ############################################################
11150: ############################################################
11151:
1.378 raeburn 11152: sub course_type {
11153: my ($cid) = @_;
11154: if (!defined($cid)) {
11155: $cid = $env{'request.course.id'};
11156: }
1.404 albertel 11157: if (defined($env{'course.'.$cid.'.type'})) {
11158: return $env{'course.'.$cid.'.type'};
1.378 raeburn 11159: } else {
11160: return 'Course';
1.377 raeburn 11161: }
11162: }
1.156 albertel 11163:
1.406 raeburn 11164: sub group_term {
11165: my $crstype = &course_type();
11166: my %names = (
11167: 'Course' => 'group',
1.865 raeburn 11168: 'Community' => 'group',
1.406 raeburn 11169: );
11170: return $names{$crstype};
11171: }
11172:
1.902 raeburn 11173: sub course_types {
11174: my @types = ('official','unofficial','community');
11175: my %typename = (
11176: official => 'Official course',
11177: unofficial => 'Unofficial course',
11178: community => 'Community',
11179: );
11180: return (\@types,\%typename);
11181: }
11182:
1.156 albertel 11183: sub icon {
11184: my ($file)=@_;
1.505 albertel 11185: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 11186: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 11187: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 11188: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
11189: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
11190: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11191: $curfext.".gif") {
11192: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
11193: $curfext.".gif";
11194: }
11195: }
1.249 albertel 11196: return &lonhttpdurl($iconname);
1.154 albertel 11197: }
1.84 albertel 11198:
1.575 albertel 11199: sub lonhttpdurl {
1.692 www 11200: #
11201: # Had been used for "small fry" static images on separate port 8080.
11202: # Modify here if lightweight http functionality desired again.
11203: # Currently eliminated due to increasing firewall issues.
11204: #
1.575 albertel 11205: my ($url)=@_;
1.692 www 11206: return $url;
1.215 albertel 11207: }
11208:
1.213 albertel 11209: sub connection_aborted {
11210: my ($r)=@_;
11211: $r->print(" ");$r->rflush();
11212: my $c = $r->connection;
11213: return $c->aborted();
11214: }
11215:
1.221 foxr 11216: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 11217: # strings as 'strings'.
11218: sub escape_single {
1.221 foxr 11219: my ($input) = @_;
1.223 albertel 11220: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 11221: $input =~ s/\'/\\\'/g; # Esacpe the 's....
11222: return $input;
11223: }
1.223 albertel 11224:
1.222 foxr 11225: # Same as escape_single, but escape's "'s This
11226: # can be used for "strings"
11227: sub escape_double {
11228: my ($input) = @_;
11229: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
11230: $input =~ s/\"/\\\"/g; # Esacpe the "s....
11231: return $input;
11232: }
1.223 albertel 11233:
1.222 foxr 11234: # Escapes the last element of a full URL.
11235: sub escape_url {
11236: my ($url) = @_;
1.238 raeburn 11237: my @urlslices = split(/\//, $url,-1);
1.369 www 11238: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 11239: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 11240: }
1.462 albertel 11241:
1.820 raeburn 11242: sub compare_arrays {
11243: my ($arrayref1,$arrayref2) = @_;
11244: my (@difference,%count);
11245: @difference = ();
11246: %count = ();
11247: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
11248: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
11249: foreach my $element (keys(%count)) {
11250: if ($count{$element} == 1) {
11251: push(@difference,$element);
11252: }
11253: }
11254: }
11255: return @difference;
11256: }
11257:
1.817 bisitz 11258: # -------------------------------------------------------- Initialize user login
1.462 albertel 11259: sub init_user_environment {
1.463 albertel 11260: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 11261: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
11262:
11263: my $public=($username eq 'public' && $domain eq 'public');
11264:
11265: # See if old ID present, if so, remove
11266:
11267: my ($filename,$cookie,$userroles);
11268: my $now=time;
11269:
11270: if ($public) {
11271: my $max_public=100;
11272: my $oldest;
11273: my $oldest_time=0;
11274: for(my $next=1;$next<=$max_public;$next++) {
11275: if (-e $lonids."/publicuser_$next.id") {
11276: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
11277: if ($mtime<$oldest_time || !$oldest_time) {
11278: $oldest_time=$mtime;
11279: $oldest=$next;
11280: }
11281: } else {
11282: $cookie="publicuser_$next";
11283: last;
11284: }
11285: }
11286: if (!$cookie) { $cookie="publicuser_$oldest"; }
11287: } else {
1.463 albertel 11288: # if this isn't a robot, kill any existing non-robot sessions
11289: if (!$args->{'robot'}) {
11290: opendir(DIR,$lonids);
11291: while ($filename=readdir(DIR)) {
11292: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
11293: unlink($lonids.'/'.$filename);
11294: }
1.462 albertel 11295: }
1.463 albertel 11296: closedir(DIR);
1.462 albertel 11297: }
11298: # Give them a new cookie
1.463 albertel 11299: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 11300: : $now.$$.int(rand(10000)));
1.463 albertel 11301: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 11302:
11303: # Initialize roles
11304:
11305: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
11306: }
11307: # ------------------------------------ Check browser type and MathML capability
11308:
11309: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
11310: $clientunicode,$clientos) = &decode_user_agent($r);
11311:
11312: # ------------------------------------------------------------- Get environment
11313:
11314: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
11315: my ($tmp) = keys(%userenv);
11316: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
11317: # default remote control to off
11318: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
11319: } else {
11320: undef(%userenv);
11321: }
11322: if (($userenv{'interface'}) && (!$form->{'interface'})) {
11323: $form->{'interface'}=$userenv{'interface'};
11324: }
11325: $env{'environment.remote'}=$userenv{'remote'};
11326: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
11327:
11328: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 11329: foreach my $option ('interface','localpath','localres') {
11330: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 11331: }
11332: # --------------------------------------------------------- Write first profile
11333:
11334: {
11335: my %initial_env =
11336: ("user.name" => $username,
11337: "user.domain" => $domain,
11338: "user.home" => $authhost,
11339: "browser.type" => $clientbrowser,
11340: "browser.version" => $clientversion,
11341: "browser.mathml" => $clientmathml,
11342: "browser.unicode" => $clientunicode,
11343: "browser.os" => $clientos,
11344: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
11345: "request.course.fn" => '',
11346: "request.course.uri" => '',
11347: "request.course.sec" => '',
11348: "request.role" => 'cm',
11349: "request.role.adv" => $env{'user.adv'},
11350: "request.host" => $ENV{'REMOTE_ADDR'},);
11351:
11352: if ($form->{'localpath'}) {
11353: $initial_env{"browser.localpath"} = $form->{'localpath'};
11354: $initial_env{"browser.localres"} = $form->{'localres'};
11355: }
11356:
11357: if ($public) {
11358: $initial_env{"environment.remote"} = "off";
11359: }
11360: if ($form->{'interface'}) {
11361: $form->{'interface'}=~s/\W//gs;
11362: $initial_env{"browser.interface"} = $form->{'interface'};
11363: $env{'browser.interface'}=$form->{'interface'};
11364: }
1.948.2.11 raeburn 11365: my %is_adv = ( is_adv => $env{'user.adv'} );
1.948.2.10 raeburn 11366: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.462 albertel 11367:
1.724 raeburn 11368: foreach my $tool ('aboutme','blog','portfolio') {
11369: $userenv{'availabletools.'.$tool} =
1.948.2.10 raeburn 11370: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
11371: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 11372: }
11373:
1.864 raeburn 11374: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 11375: $userenv{'canrequest.'.$crstype} =
11376: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.948.2.10 raeburn 11377: 'reload','requestcourses',
11378: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 11379: }
11380:
1.462 albertel 11381: $env{'user.environment'} = "$lonids/$cookie.id";
11382:
11383: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
11384: &GDBM_WRCREAT(),0640)) {
11385: &_add_to_env(\%disk_env,\%initial_env);
11386: &_add_to_env(\%disk_env,\%userenv,'environment.');
11387: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 11388: if (ref($args->{'extra_env'})) {
11389: &_add_to_env(\%disk_env,$args->{'extra_env'});
11390: }
1.462 albertel 11391: untie(%disk_env);
11392: } else {
1.705 tempelho 11393: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
11394: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 11395: return 'error: '.$!;
11396: }
11397: }
11398: $env{'request.role'}='cm';
11399: $env{'request.role.adv'}=$env{'user.adv'};
11400: $env{'browser.type'}=$clientbrowser;
11401:
11402: return $cookie;
11403:
11404: }
11405:
11406: sub _add_to_env {
11407: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 11408: if (ref($env_data) eq 'HASH') {
11409: while (my ($key,$value) = each(%$env_data)) {
11410: $idf->{$prefix.$key} = $value;
11411: $env{$prefix.$key} = $value;
11412: }
1.462 albertel 11413: }
11414: }
11415:
1.685 tempelho 11416: # --- Get the symbolic name of a problem and the url
11417: sub get_symb {
11418: my ($request,$silent) = @_;
1.726 raeburn 11419: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 11420: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
11421: if ($symb eq '') {
11422: if (!$silent) {
11423: $request->print("Unable to handle ambiguous references:$url:.");
11424: return ();
11425: }
11426: }
11427: &Apache::lonenc::check_decrypt(\$symb);
11428: return ($symb);
11429: }
11430:
11431: # --------------------------------------------------------------Get annotation
11432:
11433: sub get_annotation {
11434: my ($symb,$enc) = @_;
11435:
11436: my $key = $symb;
11437: if (!$enc) {
11438: $key =
11439: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
11440: }
11441: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
11442: return $annotation{$key};
11443: }
11444:
11445: sub clean_symb {
1.731 raeburn 11446: my ($symb,$delete_enc) = @_;
1.685 tempelho 11447:
11448: &Apache::lonenc::check_decrypt(\$symb);
11449: my $enc = $env{'request.enc'};
1.731 raeburn 11450: if ($delete_enc) {
1.730 raeburn 11451: delete($env{'request.enc'});
11452: }
1.685 tempelho 11453:
11454: return ($symb,$enc);
11455: }
1.462 albertel 11456:
1.948.2.16 raeburn 11457: sub build_release_hashes {
11458: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
11459: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
11460: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
11461: (ref($randomizetry) eq 'HASH'));
11462: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
11463: my ($item,$name,$value) = split(/:/,$key);
11464: if ($item eq 'parameter') {
11465: if (ref($checkparms->{$name}) eq 'ARRAY') {
11466: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
11467: push(@{$checkparms->{$name}},$value);
11468: }
11469: } else {
11470: push(@{$checkparms->{$name}},$value);
11471: }
11472: } elsif ($item eq 'resourcetag') {
11473: if ($name eq 'responsetype') {
11474: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
11475: }
11476: } elsif ($item eq 'course') {
11477: if ($name eq 'crstype') {
11478: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
11479: }
11480: }
11481: }
11482: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
11483: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
11484: return;
11485: }
11486:
1.41 ng 11487: =pod
11488:
11489: =back
11490:
1.112 bowersj2 11491: =cut
1.41 ng 11492:
1.112 bowersj2 11493: 1;
11494: __END__;
1.41 ng 11495:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>