Annotation of loncom/interface/loncommon.pm, revision 1.948.2.14
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.14! raeburn 4: # $Id: loncommon.pm,v 1.948.2.13 2010/11/17 20:41:53 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.13 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.169 www 3263: '' => &mt('Any category'),
1.948.2.7 raeburn 3264: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3265: }
3266:
3267: =pod
3268:
1.648 raeburn 3269: =item * &filedescription()
1.112 bowersj2 3270:
3271: returns description for a specified file type
3272:
3273: =cut
3274:
3275: sub filedescription {
1.188 matthew 3276: my $file_description = $fd{lc(shift())};
3277: $file_description =~ s:([\[\]]):~$1:g;
3278: return &mt($file_description);
1.112 bowersj2 3279: }
3280:
3281: =pod
3282:
1.648 raeburn 3283: =item * &filedescriptionex()
1.112 bowersj2 3284:
3285: returns description for a specified file type with
3286: extra formatting
3287:
3288: =cut
3289:
3290: sub filedescriptionex {
3291: my $ex=shift;
1.188 matthew 3292: my $file_description = $fd{lc($ex)};
3293: $file_description =~ s:([\[\]]):~$1:g;
3294: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3295: }
3296:
3297: # End of .tab access
3298: =pod
3299:
3300: =back
3301:
3302: =cut
3303:
3304: # ------------------------------------------------------------------ File Types
3305: sub fileextensions {
3306: return sort(keys(%fe));
3307: }
3308:
1.97 www 3309: # ----------------------------------------------------------- Display Languages
3310: # returns a hash with all desired display languages
3311: #
3312:
3313: sub display_languages {
3314: my %languages=();
1.695 raeburn 3315: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3316: $languages{$lang}=1;
1.97 www 3317: }
3318: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3319: if ($env{'form.displaylanguage'}) {
1.356 albertel 3320: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3321: $languages{$lang}=1;
1.97 www 3322: }
3323: }
3324: return %languages;
1.14 harris41 3325: }
3326:
1.582 albertel 3327: sub languages {
3328: my ($possible_langs) = @_;
1.695 raeburn 3329: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3330: if (!ref($possible_langs)) {
3331: if( wantarray ) {
3332: return @preferred_langs;
3333: } else {
3334: return $preferred_langs[0];
3335: }
3336: }
3337: my %possibilities = map { $_ => 1 } (@$possible_langs);
3338: my @preferred_possibilities;
3339: foreach my $preferred_lang (@preferred_langs) {
3340: if (exists($possibilities{$preferred_lang})) {
3341: push(@preferred_possibilities, $preferred_lang);
3342: }
3343: }
3344: if( wantarray ) {
3345: return @preferred_possibilities;
3346: }
3347: return $preferred_possibilities[0];
3348: }
3349:
1.742 raeburn 3350: sub user_lang {
3351: my ($touname,$toudom,$fromcid) = @_;
3352: my @userlangs;
3353: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3354: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3355: $env{'course.'.$fromcid.'.languages'}));
3356: } else {
3357: my %langhash = &getlangs($touname,$toudom);
3358: if ($langhash{'languages'} ne '') {
3359: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3360: } else {
3361: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3362: if ($domdefs{'lang_def'} ne '') {
3363: @userlangs = ($domdefs{'lang_def'});
3364: }
3365: }
3366: }
3367: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3368: my $user_lh = Apache::localize->get_handle(@languages);
3369: return $user_lh;
3370: }
3371:
3372:
1.112 bowersj2 3373: ###############################################################
3374: ## Student Answer Attempts ##
3375: ###############################################################
3376:
3377: =pod
3378:
3379: =head1 Alternate Problem Views
3380:
3381: =over 4
3382:
1.648 raeburn 3383: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3384: $getattempt, $regexp, $gradesub)
3385:
3386: Return string with previous attempt on problem. Arguments:
3387:
3388: =over 4
3389:
3390: =item * $symb: Problem, including path
3391:
3392: =item * $username: username of the desired student
3393:
3394: =item * $domain: domain of the desired student
1.14 harris41 3395:
1.112 bowersj2 3396: =item * $course: Course ID
1.14 harris41 3397:
1.112 bowersj2 3398: =item * $getattempt: Leave blank for all attempts, otherwise put
3399: something
1.14 harris41 3400:
1.112 bowersj2 3401: =item * $regexp: if string matches this regexp, the string will be
3402: sent to $gradesub
1.14 harris41 3403:
1.112 bowersj2 3404: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3405:
1.112 bowersj2 3406: =back
1.14 harris41 3407:
1.112 bowersj2 3408: The output string is a table containing all desired attempts, if any.
1.16 harris41 3409:
1.112 bowersj2 3410: =cut
1.1 albertel 3411:
3412: sub get_previous_attempt {
1.43 ng 3413: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3414: my $prevattempts='';
1.43 ng 3415: no strict 'refs';
1.1 albertel 3416: if ($symb) {
1.3 albertel 3417: my (%returnhash)=
3418: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3419: if ($returnhash{'version'}) {
3420: my %lasthash=();
3421: my $version;
3422: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3423: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3424: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3425: }
1.1 albertel 3426: }
1.596 albertel 3427: $prevattempts=&start_data_table().&start_data_table_header_row();
3428: $prevattempts.='<th>'.&mt('History').'</th>';
1.948.2.8 raeburn 3429: my (%typeparts,%lasthidden);
1.945 raeburn 3430: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3431: foreach my $key (sort(keys(%lasthash))) {
3432: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3433: if ($#parts > 0) {
1.31 albertel 3434: my $data=$parts[-1];
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))) {
3471: my $hide;
3472: foreach my $id (@hidden) {
3473: if ($key =~ /^\Q$id\E/) {
3474: $hide = 1;
3475: last;
3476: }
3477: }
3478: if ($hide) {
3479: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3480: if (($data eq 'award') || ($data eq 'awarddetail')) {
3481: my $value = &format_previous_attempt_value($key,
3482: $returnhash{$version.':'.$key});
3483: $prevattempts.='<td>'.$value.' </td>';
3484: } else {
3485: $prevattempts.='<td> </td>';
3486: }
3487: } else {
3488: if ($key =~ /\./) {
3489: my $value = &format_previous_attempt_value($key,
3490: $returnhash{$version.':'.$key});
3491: $prevattempts.='<td>'.$value.' </td>';
3492: } else {
3493: $prevattempts.='<td> </td>';
3494: }
3495: }
3496: }
3497: } else {
3498: foreach my $key (sort(keys(%lasthash))) {
3499: my $value = &format_previous_attempt_value($key,
3500: $returnhash{$version.':'.$key});
3501: $prevattempts.='<td>'.$value.' </td>';
3502: }
3503: }
3504: $prevattempts.=&end_data_table_row();
1.40 ng 3505: }
1.1 albertel 3506: }
1.945 raeburn 3507: my @currhidden = keys(%lasthidden);
1.596 albertel 3508: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3509: foreach my $key (sort(keys(%lasthash))) {
1.945 raeburn 3510: if (%typeparts) {
3511: my $hidden;
3512: foreach my $id (@currhidden) {
3513: if ($key =~ /^\Q$id\E/) {
3514: $hidden = 1;
3515: last;
3516: }
3517: }
3518: if ($hidden) {
3519: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3520: if (($data eq 'award') || ($data eq 'awarddetail')) {
3521: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3522: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3523: $value = &$gradesub($value);
3524: }
3525: $prevattempts.='<td>'.$value.' </td>';
3526: } else {
3527: $prevattempts.='<td> </td>';
3528: }
3529: } else {
3530: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3531: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3532: $value = &$gradesub($value);
3533: }
3534: $prevattempts.='<td>'.$value.' </td>';
3535: }
3536: } else {
3537: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3538: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3539: $value = &$gradesub($value);
3540: }
3541: $prevattempts.='<td>'.$value.' </td>';
3542: }
1.16 harris41 3543: }
1.596 albertel 3544: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3545: } else {
1.596 albertel 3546: $prevattempts=
3547: &start_data_table().&start_data_table_row().
3548: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3549: &end_data_table_row().&end_data_table();
1.1 albertel 3550: }
3551: } else {
1.596 albertel 3552: $prevattempts=
3553: &start_data_table().&start_data_table_row().
3554: '<td>'.&mt('No data.').'</td>'.
3555: &end_data_table_row().&end_data_table();
1.1 albertel 3556: }
1.10 albertel 3557: }
3558:
1.581 albertel 3559: sub format_previous_attempt_value {
3560: my ($key,$value) = @_;
3561: if ($key =~ /timestamp/) {
3562: $value = &Apache::lonlocal::locallocaltime($value);
3563: } elsif (ref($value) eq 'ARRAY') {
3564: $value = '('.join(', ', @{ $value }).')';
1.948.2.14! raeburn 3565: } elsif ($key =~ /answerstring$/) {
! 3566: my %answers = &Apache::lonnet::str2hash($value);
! 3567: my @anskeys = sort(keys(%answers));
! 3568: if (@anskeys == 1) {
! 3569: my $answer = $answers{$anskeys[0]};
! 3570: if ($answer =~ m{\Q\0\E}) {
! 3571: $answer =~ s{\Q\0\E}{, }g;
! 3572: }
! 3573: my $tag_internal_answer_name = 'INTERNAL';
! 3574: if ($anskeys[0] eq $tag_internal_answer_name) {
! 3575: $value = $answer;
! 3576: } else {
! 3577: $value = $anskeys[0].'='.$answer;
! 3578: }
! 3579: } else {
! 3580: foreach my $ans (@anskeys) {
! 3581: my $answer = $answers{$ans};
! 3582: if ($answer =~ m{\Q\0\E}) {
! 3583: $answer =~ s{\Q\0\E}{, }g;
! 3584: }
! 3585: $value .= $ans.'='.$answer.'<br />';;
! 3586: }
! 3587: }
1.581 albertel 3588: } else {
3589: $value = &unescape($value);
3590: }
3591: return $value;
3592: }
3593:
3594:
1.107 albertel 3595: sub relative_to_absolute {
3596: my ($url,$output)=@_;
3597: my $parser=HTML::TokeParser->new(\$output);
3598: my $token;
3599: my $thisdir=$url;
3600: my @rlinks=();
3601: while ($token=$parser->get_token) {
3602: if ($token->[0] eq 'S') {
3603: if ($token->[1] eq 'a') {
3604: if ($token->[2]->{'href'}) {
3605: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3606: }
3607: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3608: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3609: } elsif ($token->[1] eq 'base') {
3610: $thisdir=$token->[2]->{'href'};
3611: }
3612: }
3613: }
3614: $thisdir=~s-/[^/]*$--;
1.356 albertel 3615: foreach my $link (@rlinks) {
1.726 raeburn 3616: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3617: ($link=~/^\//) ||
3618: ($link=~/^javascript:/i) ||
3619: ($link=~/^mailto:/i) ||
3620: ($link=~/^\#/)) {
3621: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3622: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3623: }
3624: }
3625: # -------------------------------------------------- Deal with Applet codebases
3626: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3627: return $output;
3628: }
3629:
1.112 bowersj2 3630: =pod
3631:
1.648 raeburn 3632: =item * &get_student_view()
1.112 bowersj2 3633:
3634: show a snapshot of what student was looking at
3635:
3636: =cut
3637:
1.10 albertel 3638: sub get_student_view {
1.186 albertel 3639: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3640: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3641: my (%form);
1.10 albertel 3642: my @elements=('symb','courseid','domain','username');
3643: foreach my $element (@elements) {
1.186 albertel 3644: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3645: }
1.186 albertel 3646: if (defined($moreenv)) {
3647: %form=(%form,%{$moreenv});
3648: }
1.236 albertel 3649: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3650: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3651: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3652: $userview=~s/\<body[^\>]*\>//gi;
3653: $userview=~s/\<\/body\>//gi;
3654: $userview=~s/\<html\>//gi;
3655: $userview=~s/\<\/html\>//gi;
3656: $userview=~s/\<head\>//gi;
3657: $userview=~s/\<\/head\>//gi;
3658: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3659: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3660: if (wantarray) {
3661: return ($userview,$response);
3662: } else {
3663: return $userview;
3664: }
3665: }
3666:
3667: sub get_student_view_with_retries {
3668: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3669:
3670: my $ok = 0; # True if we got a good response.
3671: my $content;
3672: my $response;
3673:
3674: # Try to get the student_view done. within the retries count:
3675:
3676: do {
3677: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3678: $ok = $response->is_success;
3679: if (!$ok) {
3680: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3681: }
3682: $retries--;
3683: } while (!$ok && ($retries > 0));
3684:
3685: if (!$ok) {
3686: $content = ''; # On error return an empty content.
3687: }
1.651 www 3688: if (wantarray) {
3689: return ($content, $response);
3690: } else {
3691: return $content;
3692: }
1.11 albertel 3693: }
3694:
1.112 bowersj2 3695: =pod
3696:
1.648 raeburn 3697: =item * &get_student_answers()
1.112 bowersj2 3698:
3699: show a snapshot of how student was answering problem
3700:
3701: =cut
3702:
1.11 albertel 3703: sub get_student_answers {
1.100 sakharuk 3704: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3705: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3706: my (%moreenv);
1.11 albertel 3707: my @elements=('symb','courseid','domain','username');
3708: foreach my $element (@elements) {
1.186 albertel 3709: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3710: }
1.186 albertel 3711: $moreenv{'grade_target'}='answer';
3712: %moreenv=(%form,%moreenv);
1.497 raeburn 3713: $feedurl = &Apache::lonnet::clutter($feedurl);
3714: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3715: return $userview;
1.1 albertel 3716: }
1.116 albertel 3717:
3718: =pod
3719:
3720: =item * &submlink()
3721:
1.242 albertel 3722: Inputs: $text $uname $udom $symb $target
1.116 albertel 3723:
3724: Returns: A link to grades.pm such as to see the SUBM view of a student
3725:
3726: =cut
3727:
3728: ###############################################
3729: sub submlink {
1.242 albertel 3730: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3731: if (!($uname && $udom)) {
3732: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3733: &Apache::lonnet::whichuser($symb);
1.116 albertel 3734: if (!$symb) { $symb=$cursymb; }
3735: }
1.254 matthew 3736: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3737: $symb=&escape($symb);
1.948.2.4 raeburn 3738: if ($target) { $target=" target=\"$target\""; }
3739: return
3740: '<a href="/adm/grades?command=submission'.
3741: '&symb='.$symb.
3742: '&student='.$uname.
3743: '&userdom='.$udom.'"'.
3744: $target.'>'.$text.'</a>';
1.242 albertel 3745: }
3746: ##############################################
3747:
3748: =pod
3749:
3750: =item * &pgrdlink()
3751:
3752: Inputs: $text $uname $udom $symb $target
3753:
3754: Returns: A link to grades.pm such as to see the PGRD view of a student
3755:
3756: =cut
3757:
3758: ###############################################
3759: sub pgrdlink {
3760: my $link=&submlink(@_);
3761: $link=~s/(&command=submission)/$1&showgrading=yes/;
3762: return $link;
3763: }
3764: ##############################################
3765:
3766: =pod
3767:
3768: =item * &pprmlink()
3769:
3770: Inputs: $text $uname $udom $symb $target
3771:
3772: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3773: student and a specific resource
1.242 albertel 3774:
3775: =cut
3776:
3777: ###############################################
3778: sub pprmlink {
3779: my ($text,$uname,$udom,$symb,$target)=@_;
3780: if (!($uname && $udom)) {
3781: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3782: &Apache::lonnet::whichuser($symb);
1.242 albertel 3783: if (!$symb) { $symb=$cursymb; }
3784: }
1.254 matthew 3785: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3786: $symb=&escape($symb);
1.242 albertel 3787: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3788: return '<a href="/adm/parmset?command=set&'.
3789: 'symb='.$symb.'&uname='.$uname.
3790: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3791: }
3792: ##############################################
1.37 matthew 3793:
1.112 bowersj2 3794: =pod
3795:
3796: =back
3797:
3798: =cut
3799:
1.37 matthew 3800: ###############################################
1.51 www 3801:
3802:
3803: sub timehash {
1.687 raeburn 3804: my ($thistime) = @_;
3805: my $timezone = &Apache::lonlocal::gettimezone();
3806: my $dt = DateTime->from_epoch(epoch => $thistime)
3807: ->set_time_zone($timezone);
3808: my $wday = $dt->day_of_week();
3809: if ($wday == 7) { $wday = 0; }
3810: return ( 'second' => $dt->second(),
3811: 'minute' => $dt->minute(),
3812: 'hour' => $dt->hour(),
3813: 'day' => $dt->day_of_month(),
3814: 'month' => $dt->month(),
3815: 'year' => $dt->year(),
3816: 'weekday' => $wday,
3817: 'dayyear' => $dt->day_of_year(),
3818: 'dlsav' => $dt->is_dst() );
1.51 www 3819: }
3820:
1.370 www 3821: sub utc_string {
3822: my ($date)=@_;
1.371 www 3823: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3824: }
3825:
1.51 www 3826: sub maketime {
3827: my %th=@_;
1.687 raeburn 3828: my ($epoch_time,$timezone,$dt);
3829: $timezone = &Apache::lonlocal::gettimezone();
3830: eval {
3831: $dt = DateTime->new( year => $th{'year'},
3832: month => $th{'month'},
3833: day => $th{'day'},
3834: hour => $th{'hour'},
3835: minute => $th{'minute'},
3836: second => $th{'second'},
3837: time_zone => $timezone,
3838: );
3839: };
3840: if (!$@) {
3841: $epoch_time = $dt->epoch;
3842: if ($epoch_time) {
3843: return $epoch_time;
3844: }
3845: }
1.51 www 3846: return POSIX::mktime(
3847: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3848: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3849: }
3850:
3851: #########################################
1.51 www 3852:
3853: sub findallcourses {
1.482 raeburn 3854: my ($roles,$uname,$udom) = @_;
1.355 albertel 3855: my %roles;
3856: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3857: my %courses;
1.51 www 3858: my $now=time;
1.482 raeburn 3859: if (!defined($uname)) {
3860: $uname = $env{'user.name'};
3861: }
3862: if (!defined($udom)) {
3863: $udom = $env{'user.domain'};
3864: }
3865: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.948.2.11 raeburn 3866: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3867: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3868: $extra);
1.482 raeburn 3869: if (!%roles) {
3870: %roles = (
3871: cc => 1,
1.907 raeburn 3872: co => 1,
1.482 raeburn 3873: in => 1,
3874: ep => 1,
3875: ta => 1,
3876: cr => 1,
3877: st => 1,
3878: );
3879: }
3880: foreach my $entry (keys(%roleshash)) {
3881: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3882: if ($trole =~ /^cr/) {
3883: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3884: } else {
3885: next if (!exists($roles{$trole}));
3886: }
3887: if ($tend) {
3888: next if ($tend < $now);
3889: }
3890: if ($tstart) {
3891: next if ($tstart > $now);
3892: }
3893: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3894: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3895: if ($secpart eq '') {
3896: ($cnum,$role) = split(/_/,$cnumpart);
3897: $sec = 'none';
3898: $realsec = '';
3899: } else {
3900: $cnum = $cnumpart;
3901: ($sec,$role) = split(/_/,$secpart);
3902: $realsec = $sec;
1.490 raeburn 3903: }
1.482 raeburn 3904: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3905: }
3906: } else {
3907: foreach my $key (keys(%env)) {
1.483 albertel 3908: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3909: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3910: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3911: next if ($role eq 'ca' || $role eq 'aa');
3912: next if (%roles && !exists($roles{$role}));
3913: my ($starttime,$endtime)=split(/\./,$env{$key});
3914: my $active=1;
3915: if ($starttime) {
3916: if ($now<$starttime) { $active=0; }
3917: }
3918: if ($endtime) {
3919: if ($now>$endtime) { $active=0; }
3920: }
3921: if ($active) {
3922: if ($sec eq '') {
3923: $sec = 'none';
3924: }
3925: $courses{$cdom.'_'.$cnum}{$sec} =
3926: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3927: }
3928: }
1.51 www 3929: }
3930: }
1.474 raeburn 3931: return %courses;
1.51 www 3932: }
1.37 matthew 3933:
1.54 www 3934: ###############################################
1.474 raeburn 3935:
3936: sub blockcheck {
1.482 raeburn 3937: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3938:
3939: if (!defined($udom)) {
3940: $udom = $env{'user.domain'};
3941: }
3942: if (!defined($uname)) {
3943: $uname = $env{'user.name'};
3944: }
3945:
3946: # If uname and udom are for a course, check for blocks in the course.
3947:
3948: if (&Apache::lonnet::is_course($udom,$uname)) {
3949: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3950: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3951: return ($startblock,$endblock);
3952: }
1.474 raeburn 3953:
1.502 raeburn 3954: my $startblock = 0;
3955: my $endblock = 0;
1.482 raeburn 3956: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3957:
1.490 raeburn 3958: # If uname is for a user, and activity is course-specific, i.e.,
3959: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3960:
1.490 raeburn 3961: if (($activity eq 'boards' || $activity eq 'chat' ||
3962: $activity eq 'groups') && ($env{'request.course.id'})) {
3963: foreach my $key (keys(%live_courses)) {
3964: if ($key ne $env{'request.course.id'}) {
3965: delete($live_courses{$key});
3966: }
3967: }
3968: }
3969:
3970: my $otheruser = 0;
3971: my %own_courses;
3972: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3973: # Resource belongs to user other than current user.
3974: $otheruser = 1;
3975: # Gather courses for current user
3976: %own_courses =
3977: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3978: }
3979:
3980: # Gather active course roles - course coordinator, instructor,
3981: # exam proctor, ta, student, or custom role.
1.474 raeburn 3982:
3983: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3984: my ($cdom,$cnum);
3985: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3986: $cdom = $env{'course.'.$course.'.domain'};
3987: $cnum = $env{'course.'.$course.'.num'};
3988: } else {
1.490 raeburn 3989: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3990: }
3991: my $no_ownblock = 0;
3992: my $no_userblock = 0;
1.533 raeburn 3993: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3994: # Check if current user has 'evb' priv for this
3995: if (defined($own_courses{$course})) {
3996: foreach my $sec (keys(%{$own_courses{$course}})) {
3997: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3998: if ($sec ne 'none') {
3999: $checkrole .= '/'.$sec;
4000: }
4001: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4002: $no_ownblock = 1;
4003: last;
4004: }
4005: }
4006: }
4007: # if they have 'evb' priv and are currently not playing student
4008: next if (($no_ownblock) &&
4009: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4010: }
1.474 raeburn 4011: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4012: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4013: if ($sec ne 'none') {
1.482 raeburn 4014: $checkrole .= '/'.$sec;
1.474 raeburn 4015: }
1.490 raeburn 4016: if ($otheruser) {
4017: # Resource belongs to user other than current user.
4018: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 4019: my ($trole,$tdom,$tnum,$tsec);
4020: my $entry = $live_courses{$course}{$sec};
4021: if ($entry =~ /^cr/) {
4022: ($trole,$tdom,$tnum,$tsec) =
4023: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4024: } else {
4025: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4026: }
4027: my ($spec,$area,$trest,%allroles,%userroles);
4028: $area = '/'.$tdom.'/'.$tnum;
4029: $trest = $tnum;
4030: if ($tsec ne '') {
4031: $area .= '/'.$tsec;
4032: $trest .= '/'.$tsec;
4033: }
4034: $spec = $trole.'.'.$area;
4035: if ($trole =~ /^cr/) {
4036: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4037: $tdom,$spec,$trest,$area);
4038: } else {
4039: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4040: $tdom,$spec,$trest,$area);
4041: }
4042: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4043: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4044: if ($1) {
4045: $no_userblock = 1;
4046: last;
4047: }
4048: }
1.490 raeburn 4049: } else {
4050: # Resource belongs to current user
4051: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4052: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4053: $no_ownblock = 1;
4054: last;
4055: }
1.474 raeburn 4056: }
4057: }
4058: # if they have the evb priv and are currently not playing student
1.482 raeburn 4059: next if (($no_ownblock) &&
1.491 albertel 4060: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4061: next if ($no_userblock);
1.474 raeburn 4062:
1.866 kalberla 4063: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4064: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4065:
4066: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4067: if (($start != 0) &&
4068: (($startblock == 0) || ($startblock > $start))) {
4069: $startblock = $start;
4070: }
4071: if (($end != 0) &&
4072: (($endblock == 0) || ($endblock < $end))) {
4073: $endblock = $end;
4074: }
1.490 raeburn 4075: }
4076: return ($startblock,$endblock);
4077: }
4078:
4079: sub get_blocks {
4080: my ($setters,$activity,$cdom,$cnum) = @_;
4081: my $startblock = 0;
4082: my $endblock = 0;
4083: my $course = $cdom.'_'.$cnum;
4084: $setters->{$course} = {};
4085: $setters->{$course}{'staff'} = [];
4086: $setters->{$course}{'times'} = [];
4087: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4088: foreach my $record (keys(%records)) {
4089: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4090: if ($start <= time && $end >= time) {
4091: my ($staff_name,$staff_dom,$title,$blocks) =
4092: &parse_block_record($records{$record});
4093: if ($blocks->{$activity} eq 'on') {
4094: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4095: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4096: if ( ($startblock == 0) || ($startblock > $start) ) {
4097: $startblock = $start;
1.490 raeburn 4098: }
1.491 albertel 4099: if ( ($endblock == 0) || ($endblock < $end) ) {
4100: $endblock = $end;
1.474 raeburn 4101: }
4102: }
4103: }
4104: }
4105: return ($startblock,$endblock);
4106: }
4107:
4108: sub parse_block_record {
4109: my ($record) = @_;
4110: my ($setuname,$setudom,$title,$blocks);
4111: if (ref($record) eq 'HASH') {
4112: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4113: $title = &unescape($record->{'event'});
4114: $blocks = $record->{'blocks'};
4115: } else {
4116: my @data = split(/:/,$record,3);
4117: if (scalar(@data) eq 2) {
4118: $title = $data[1];
4119: ($setuname,$setudom) = split(/@/,$data[0]);
4120: } else {
4121: ($setuname,$setudom,$title) = @data;
4122: }
4123: $blocks = { 'com' => 'on' };
4124: }
4125: return ($setuname,$setudom,$title,$blocks);
4126: }
4127:
1.854 kalberla 4128: sub blocking_status {
4129: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4130: my %setters;
1.890 droeschl 4131:
4132: # check for active blocking
1.867 kalberla 4133: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4134:
1.890 droeschl 4135: my $blocked = $startblock && $endblock ? 1 : 0;
4136:
4137: # caller just wants to know whether a block is active
4138: if (!wantarray) { return $blocked; }
4139:
4140: # build a link to a popup window containing the details
4141: my $querystring = "?activity=$activity";
4142: # $uname and $udom decide whose portfolio the user is trying to look at
4143: $querystring .= "&udom=$udom" if $udom;
4144: $querystring .= "&uname=$uname" if $uname;
4145:
4146: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4147: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4148: var options = "width=" + w + ",height=" + h + ",";
4149: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4150: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4151: var newWin = window.open(url, wdwName, options);
4152: newWin.focus();
4153: }
1.890 droeschl 4154: END_MYBLOCK
1.854 kalberla 4155:
1.890 droeschl 4156: $output = Apache::lonhtmlcommon::scripttag($output);
4157:
1.854 kalberla 4158: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4159: my $text = mt('Communication Blocked');
4160:
1.867 kalberla 4161: $output .= <<"END_BLOCK";
4162: <div class='LC_comblock'>
1.869 kalberla 4163: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4164: title='$text'>
4165: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
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'>$text</a>
1.867 kalberla 4168: </div>
4169:
4170: END_BLOCK
1.474 raeburn 4171:
1.854 kalberla 4172: return ($blocked, $output);
4173: }
1.490 raeburn 4174:
1.60 matthew 4175: ###############################################
4176:
1.682 raeburn 4177: sub check_ip_acc {
4178: my ($acc)=@_;
4179: &Apache::lonxml::debug("acc is $acc");
4180: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4181: return 1;
4182: }
4183: my $allowed=0;
4184: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4185:
4186: my $name;
4187: foreach my $pattern (split(',',$acc)) {
4188: $pattern =~ s/^\s*//;
4189: $pattern =~ s/\s*$//;
4190: if ($pattern =~ /\*$/) {
4191: #35.8.*
4192: $pattern=~s/\*//;
4193: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4194: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4195: #35.8.3.[34-56]
4196: my $low=$2;
4197: my $high=$3;
4198: $pattern=$1;
4199: if ($ip =~ /^\Q$pattern\E/) {
4200: my $last=(split(/\./,$ip))[3];
4201: if ($last <=$high && $last >=$low) { $allowed=1; }
4202: }
4203: } elsif ($pattern =~ /^\*/) {
4204: #*.msu.edu
4205: $pattern=~s/\*//;
4206: if (!defined($name)) {
4207: use Socket;
4208: my $netaddr=inet_aton($ip);
4209: ($name)=gethostbyaddr($netaddr,AF_INET);
4210: }
4211: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4212: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4213: #127.0.0.1
4214: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4215: } else {
4216: #some.name.com
4217: if (!defined($name)) {
4218: use Socket;
4219: my $netaddr=inet_aton($ip);
4220: ($name)=gethostbyaddr($netaddr,AF_INET);
4221: }
4222: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4223: }
4224: if ($allowed) { last; }
4225: }
4226: return $allowed;
4227: }
4228:
4229: ###############################################
4230:
1.60 matthew 4231: =pod
4232:
1.112 bowersj2 4233: =head1 Domain Template Functions
4234:
4235: =over 4
4236:
4237: =item * &determinedomain()
1.60 matthew 4238:
4239: Inputs: $domain (usually will be undef)
4240:
1.63 www 4241: Returns: Determines which domain should be used for designs
1.60 matthew 4242:
4243: =cut
1.54 www 4244:
1.60 matthew 4245: ###############################################
1.63 www 4246: sub determinedomain {
4247: my $domain=shift;
1.531 albertel 4248: if (! $domain) {
1.60 matthew 4249: # Determine domain if we have not been given one
1.893 raeburn 4250: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4251: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4252: if ($env{'request.role.domain'}) {
4253: $domain=$env{'request.role.domain'};
1.60 matthew 4254: }
4255: }
1.63 www 4256: return $domain;
4257: }
4258: ###############################################
1.517 raeburn 4259:
1.518 albertel 4260: sub devalidate_domconfig_cache {
4261: my ($udom)=@_;
4262: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4263: }
4264:
4265: # ---------------------- Get domain configuration for a domain
4266: sub get_domainconf {
4267: my ($udom) = @_;
4268: my $cachetime=1800;
4269: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4270: if (defined($cached)) { return %{$result}; }
4271:
4272: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4273: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4274: my (%designhash,%legacy);
1.518 albertel 4275: if (keys(%domconfig) > 0) {
4276: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4277: if (keys(%{$domconfig{'login'}})) {
4278: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4279: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4280: if ($key eq 'loginvia') {
4281: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4282: my @ids = &Apache::lonnet::current_machine_ids();
4283: foreach my $hostname (@ids) {
1.948 raeburn 4284: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4285: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4286: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4287: $designhash{$udom.'.login.loginvia'} = $server;
4288: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4289:
4290: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4291: } else {
4292: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4293: }
4294: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4295: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4296: }
1.946 raeburn 4297: }
4298: }
4299: }
4300: }
4301: } else {
4302: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4303: $designhash{$udom.'.login.'.$key.'_'.$img} =
4304: $domconfig{'login'}{$key}{$img};
4305: }
1.699 raeburn 4306: }
4307: } else {
4308: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4309: }
1.632 raeburn 4310: }
4311: } else {
4312: $legacy{'login'} = 1;
1.518 albertel 4313: }
1.632 raeburn 4314: } else {
4315: $legacy{'login'} = 1;
1.518 albertel 4316: }
4317: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4318: if (keys(%{$domconfig{'rolecolors'}})) {
4319: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4320: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4321: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4322: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4323: }
1.518 albertel 4324: }
4325: }
1.632 raeburn 4326: } else {
4327: $legacy{'rolecolors'} = 1;
1.518 albertel 4328: }
1.632 raeburn 4329: } else {
4330: $legacy{'rolecolors'} = 1;
1.518 albertel 4331: }
1.948 raeburn 4332: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4333: if ($domconfig{'autoenroll'}{'co-owners'}) {
4334: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4335: }
4336: }
1.632 raeburn 4337: if (keys(%legacy) > 0) {
4338: my %legacyhash = &get_legacy_domconf($udom);
4339: foreach my $item (keys(%legacyhash)) {
4340: if ($item =~ /^\Q$udom\E\.login/) {
4341: if ($legacy{'login'}) {
4342: $designhash{$item} = $legacyhash{$item};
4343: }
4344: } else {
4345: if ($legacy{'rolecolors'}) {
4346: $designhash{$item} = $legacyhash{$item};
4347: }
1.518 albertel 4348: }
4349: }
4350: }
1.632 raeburn 4351: } else {
4352: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4353: }
4354: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4355: $cachetime);
4356: return %designhash;
4357: }
4358:
1.632 raeburn 4359: sub get_legacy_domconf {
4360: my ($udom) = @_;
4361: my %legacyhash;
4362: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4363: my $designfile = $designdir.'/'.$udom.'.tab';
4364: if (-e $designfile) {
4365: if ( open (my $fh,"<$designfile") ) {
4366: while (my $line = <$fh>) {
4367: next if ($line =~ /^\#/);
4368: chomp($line);
4369: my ($key,$val)=(split(/\=/,$line));
4370: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4371: }
4372: close($fh);
4373: }
4374: }
4375: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4376: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4377: }
4378: return %legacyhash;
4379: }
4380:
1.63 www 4381: =pod
4382:
1.112 bowersj2 4383: =item * &domainlogo()
1.63 www 4384:
4385: Inputs: $domain (usually will be undef)
4386:
4387: Returns: A link to a domain logo, if the domain logo exists.
4388: If the domain logo does not exist, a description of the domain.
4389:
4390: =cut
1.112 bowersj2 4391:
1.63 www 4392: ###############################################
4393: sub domainlogo {
1.517 raeburn 4394: my $domain = &determinedomain(shift);
1.518 albertel 4395: my %designhash = &get_domainconf($domain);
1.517 raeburn 4396: # See if there is a logo
4397: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4398: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4399: if ($imgsrc =~ m{^/(adm|res)/}) {
4400: if ($imgsrc =~ m{^/res/}) {
4401: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4402: &Apache::lonnet::repcopy($local_name);
4403: }
4404: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4405: }
4406: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4407: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4408: return &Apache::lonnet::domain($domain,'description');
1.59 www 4409: } else {
1.60 matthew 4410: return '';
1.59 www 4411: }
4412: }
1.63 www 4413: ##############################################
4414:
4415: =pod
4416:
1.112 bowersj2 4417: =item * &designparm()
1.63 www 4418:
4419: Inputs: $which parameter; $domain (usually will be undef)
4420:
4421: Returns: value of designparamter $which
4422:
4423: =cut
1.112 bowersj2 4424:
1.397 albertel 4425:
1.400 albertel 4426: ##############################################
1.397 albertel 4427: sub designparm {
4428: my ($which,$domain)=@_;
4429: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4430: return $env{'environment.color.'.$which};
1.96 www 4431: }
1.63 www 4432: $domain=&determinedomain($domain);
1.518 albertel 4433: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4434: my $output;
1.517 raeburn 4435: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4436: $output = $domdesign{$domain.'.'.$which};
1.63 www 4437: } else {
1.520 raeburn 4438: $output = $defaultdesign{$which};
4439: }
4440: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4441: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4442: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4443: if ($output =~ m{^/res/}) {
4444: my $local_name = &Apache::lonnet::filelocation('',$output);
4445: &Apache::lonnet::repcopy($local_name);
4446: }
1.520 raeburn 4447: $output = &lonhttpdurl($output);
4448: }
1.63 www 4449: }
1.520 raeburn 4450: return $output;
1.63 www 4451: }
1.59 www 4452:
1.822 bisitz 4453: ##############################################
4454: =pod
4455:
1.832 bisitz 4456: =item * &authorspace()
4457:
4458: Inputs: ./.
4459:
4460: Returns: Path to the Construction Space of the current user's
4461: accessed author space
4462: The author space will be that of the current user
4463: when accessing the own author space
4464: and that of the co-author/assistent co-author
4465: when accessing the co-author's/assistent co-author's
4466: space
4467:
4468: =cut
4469:
4470: sub authorspace {
4471: my $caname = '';
4472: if ($env{'request.role'} =~ /^ca|^aa/) {
4473: (undef,$caname) =
4474: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4475: } else {
4476: $caname = $env{'user.name'};
4477: }
4478: return '/priv/'.$caname.'/';
4479: }
4480:
4481: ##############################################
4482: =pod
4483:
1.822 bisitz 4484: =item * &head_subbox()
4485:
4486: Inputs: $content (contains HTML code with page functions, etc.)
4487:
4488: Returns: HTML div with $content
4489: To be included in page header
4490:
4491: =cut
4492:
4493: sub head_subbox {
4494: my ($content)=@_;
4495: my $output =
1.844 bisitz 4496: '<div id="LC_head_subbox">'
1.822 bisitz 4497: .$content
4498: .'</div>'
4499: }
4500:
4501: ##############################################
4502: =pod
4503:
4504: =item * &CSTR_pageheader()
4505:
4506: Inputs: ./.
4507:
4508: Returns: HTML div with CSTR path and recent box
4509: To be included on Construction Space pages
4510:
4511: =cut
4512:
4513: sub CSTR_pageheader {
4514: # this is for resources; directories have customtitle, and crumbs
4515: # and select recent are created in lonpubdir.pm
4516: my ($uname,$thisdisfn)=
4517: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4518: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4519: $formaction=~s/\/+/\//g;
4520:
4521: my $parentpath = '';
4522: my $lastitem = '';
4523: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4524: $parentpath = $1;
4525: $lastitem = $2;
4526: } else {
4527: $lastitem = $thisdisfn;
4528: }
1.921 bisitz 4529:
4530: my $output =
1.822 bisitz 4531: '<div>'
4532: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4533: .'<b>'.&mt('Construction Space:').'</b> '
4534: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4535: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4536: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4537:
4538: if ($lastitem) {
4539: $output .=
4540: '<span class="LC_filename">'
4541: .$lastitem
4542: .'</span>';
4543: }
4544: $output .=
4545: '<br />'
1.822 bisitz 4546: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4547: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4548: .'</form>'
4549: .&Apache::lonmenu::constspaceform()
4550: .'</div>';
1.921 bisitz 4551:
4552: return $output;
1.822 bisitz 4553: }
4554:
1.60 matthew 4555: ###############################################
4556: ###############################################
4557:
4558: =pod
4559:
1.112 bowersj2 4560: =back
4561:
1.549 albertel 4562: =head1 HTML Helpers
1.112 bowersj2 4563:
4564: =over 4
4565:
4566: =item * &bodytag()
1.60 matthew 4567:
4568: Returns a uniform header for LON-CAPA web pages.
4569:
4570: Inputs:
4571:
1.112 bowersj2 4572: =over 4
4573:
4574: =item * $title, A title to be displayed on the page.
4575:
4576: =item * $function, the current role (can be undef).
4577:
4578: =item * $addentries, extra parameters for the <body> tag.
4579:
4580: =item * $bodyonly, if defined, only return the <body> tag.
4581:
4582: =item * $domain, if defined, force a given domain.
4583:
4584: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4585: text interface only)
1.60 matthew 4586:
1.814 bisitz 4587: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4588: navigational links
1.317 albertel 4589:
1.338 albertel 4590: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4591:
1.361 albertel 4592: =item * $no_inline_link, if true and in remote mode, don't show the
4593: 'Switch To Inline Menu' link
4594:
1.460 albertel 4595: =item * $args, optional argument valid values are
4596: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4597: inherit_jsmath -> when creating popup window in a page,
4598: should it have jsmath forced on by the
4599: current page
1.460 albertel 4600:
1.112 bowersj2 4601: =back
4602:
1.60 matthew 4603: Returns: A uniform header for LON-CAPA web pages.
4604: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4605: If $bodyonly is undef or zero, an html string containing a <body> tag and
4606: other decorations will be returned.
4607:
4608: =cut
4609:
1.54 www 4610: sub bodytag {
1.831 bisitz 4611: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4612: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4613:
1.948.2.2 raeburn 4614: my $public;
4615: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4616: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4617: $public = 1;
4618: }
1.460 albertel 4619: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4620:
1.183 matthew 4621: $function = &get_users_function() if (!$function);
1.339 albertel 4622: my $img = &designparm($function.'.img',$domain);
4623: my $font = &designparm($function.'.font',$domain);
4624: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4625:
1.803 bisitz 4626: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4627: 'bgcolor' => $pgbg,
1.339 albertel 4628: 'text' => $font,
4629: 'alink' => &designparm($function.'.alink',$domain),
4630: 'vlink' => &designparm($function.'.vlink',$domain),
4631: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4632: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4633:
1.63 www 4634: # role and realm
1.378 raeburn 4635: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4636: if ($role eq 'ca') {
1.479 albertel 4637: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4638: $realm = &plainname($rname,$rdom);
1.378 raeburn 4639: }
1.55 www 4640: # realm
1.258 albertel 4641: if ($env{'request.course.id'}) {
1.378 raeburn 4642: if ($env{'request.role'} !~ /^cr/) {
4643: $role = &Apache::lonnet::plaintext($role,&course_type());
4644: }
1.898 raeburn 4645: if ($env{'request.course.sec'}) {
4646: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4647: }
1.359 albertel 4648: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4649: } else {
4650: $role = &Apache::lonnet::plaintext($role);
1.54 www 4651: }
1.433 albertel 4652:
1.359 albertel 4653: if (!$realm) { $realm=' '; }
1.55 www 4654: # Set messages
1.60 matthew 4655: my $messages=&domainlogo($domain);
1.330 albertel 4656:
1.438 albertel 4657: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4658:
1.101 www 4659: # construct main body tag
1.359 albertel 4660: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4661: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4662:
1.530 albertel 4663: if ($bodyonly) {
1.60 matthew 4664: return $bodytag;
1.798 tempelho 4665: }
1.359 albertel 4666:
1.410 albertel 4667: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.948.2.2 raeburn 4668: if ($public) {
1.433 albertel 4669: undef($role);
1.434 albertel 4670: } else {
4671: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4672: }
1.948.2.2 raeburn 4673:
1.762 bisitz 4674: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4675: #
4676: # Extra info if you are the DC
4677: my $dc_info = '';
4678: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4679: $env{'course.'.$env{'request.course.id'}.
4680: '.domain'}.'/'})) {
4681: my $cid = $env{'request.course.id'};
1.917 raeburn 4682: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4683: $dc_info =~ s/\s+$//;
1.359 albertel 4684: }
4685:
1.898 raeburn 4686: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4687: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4688:
1.837 bisitz 4689: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4690: # No Remote
1.916 droeschl 4691: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4692: return $bodytag;
4693: }
1.903 droeschl 4694:
4695: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4696:
4697: # if ($env{'request.state'} eq 'construct') {
4698: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4699: # }
4700:
1.359 albertel 4701:
4702:
1.916 droeschl 4703: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4704: if ($dc_info) {
4705: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4706: }
1.916 droeschl 4707: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4708: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4709: return $bodytag;
4710: }
1.894 droeschl 4711:
1.927 raeburn 4712: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4713: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4714: }
1.916 droeschl 4715:
1.903 droeschl 4716: $bodytag .= Apache::lonhtmlcommon::scripttag(
4717: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4718:
1.903 droeschl 4719: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4720:
1.917 raeburn 4721: if ($dc_info) {
4722: $dc_info = &dc_courseid_toggle($dc_info);
4723: }
4724: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4725:
1.903 droeschl 4726: #don't show menus for public users
1.948.2.2 raeburn 4727: if (!$public){
1.903 droeschl 4728: $bodytag .= Apache::lonmenu::secondary_menu();
4729: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4730: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4731: if ($env{'request.state'} eq 'construct') {
4732: $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
4733: $args->{'bread_crumbs'});
4734: } elsif ($forcereg) {
4735: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4736: }
1.903 droeschl 4737: }else{
4738: # this is to seperate menu from content when there's no secondary
4739: # menu. Especially needed for public accessible ressources.
4740: $bodytag .= '<hr style="clear:both" />';
4741: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4742: }
1.903 droeschl 4743:
1.235 raeburn 4744: return $bodytag;
1.94 www 4745: }
1.95 www 4746:
1.93 www 4747: #
1.95 www 4748: # Top frame rendering, Remote is up
1.93 www 4749: #
1.359 albertel 4750:
1.517 raeburn 4751: my $imgsrc = $img;
4752: if ($img =~ /^\/adm/) {
1.575 albertel 4753: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4754: }
4755: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4756:
1.305 www 4757: # Explicit link to get inline menu
1.361 albertel 4758: my $menu= ($no_inline_link?''
1.883 droeschl 4759: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917 raeburn 4760:
4761: if ($dc_info) {
4762: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
4763: }
4764:
1.916 droeschl 4765: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.897 wenzelju 4766: <ol class="LC_primary_menu LC_right">
1.853 droeschl 4767: <li>$menu</li>
1.917 raeburn 4768: </ol><div id="LC_realm"> $realm $dc_info</div>| unless $env{'form.inhibitmenu'};
1.94 www 4769: return(<<ENDBODY);
1.60 matthew 4770: $bodytag
1.359 albertel 4771: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4772: <tr><td>$upperleft</td>
4773: <td>$messages </td>
1.54 www 4774: </tr>
1.359 albertel 4775: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4776: </tr>
1.356 albertel 4777: </table>
1.54 www 4778: ENDBODY
1.182 matthew 4779: }
4780:
1.917 raeburn 4781: sub dc_courseid_toggle {
4782: my ($dc_info) = @_;
1.948.2.10 raeburn 4783: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4784: '<a href="javascript:showCourseID();">'.
4785: &mt('(More ...)').'</a></span>'.
4786: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4787: }
4788:
1.330 albertel 4789: sub make_attr_string {
4790: my ($register,$attr_ref) = @_;
4791:
4792: if ($attr_ref && !ref($attr_ref)) {
4793: die("addentries Must be a hash ref ".
4794: join(':',caller(1))." ".
4795: join(':',caller(0))." ");
4796: }
4797:
4798: if ($register) {
1.339 albertel 4799: my ($on_load,$on_unload);
4800: foreach my $key (keys(%{$attr_ref})) {
4801: if (lc($key) eq 'onload') {
4802: $on_load.=$attr_ref->{$key}.';';
4803: delete($attr_ref->{$key});
4804:
4805: } elsif (lc($key) eq 'onunload') {
4806: $on_unload.=$attr_ref->{$key}.';';
4807: delete($attr_ref->{$key});
4808: }
4809: }
4810: $attr_ref->{'onload'} =
4811: &Apache::lonmenu::loadevents(). $on_load;
4812: $attr_ref->{'onunload'}=
4813: &Apache::lonmenu::unloadevents().$on_unload;
4814: }
4815:
4816: # Accessibility font enhance
4817: if ($env{'browser.fontenhance'} eq 'on') {
4818: my $style;
4819: foreach my $key (keys(%{$attr_ref})) {
4820: if (lc($key) eq 'style') {
4821: $style.=$attr_ref->{$key}.';';
4822: delete($attr_ref->{$key});
4823: }
4824: }
4825: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4826: }
1.339 albertel 4827:
1.330 albertel 4828: my $attr_string;
4829: foreach my $attr (keys(%$attr_ref)) {
4830: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4831: }
4832: return $attr_string;
4833: }
4834:
4835:
1.182 matthew 4836: ###############################################
1.251 albertel 4837: ###############################################
4838:
4839: =pod
4840:
4841: =item * &endbodytag()
4842:
4843: Returns a uniform footer for LON-CAPA web pages.
4844:
1.635 raeburn 4845: Inputs: 1 - optional reference to an args hash
4846: If in the hash, key for noredirectlink has a value which evaluates to true,
4847: a 'Continue' link is not displayed if the page contains an
4848: internal redirect in the <head></head> section,
4849: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4850:
4851: =cut
4852:
4853: sub endbodytag {
1.635 raeburn 4854: my ($args) = @_;
1.251 albertel 4855: my $endbodytag='</body>';
1.269 albertel 4856: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4857: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4858: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4859: $endbodytag=
4860: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4861: &mt('Continue').'</a>'.
4862: $endbodytag;
4863: }
1.315 albertel 4864: }
1.251 albertel 4865: return $endbodytag;
4866: }
4867:
1.352 albertel 4868: =pod
4869:
4870: =item * &standard_css()
4871:
4872: Returns a style sheet
4873:
4874: Inputs: (all optional)
4875: domain -> force to color decorate a page for a specific
4876: domain
4877: function -> force usage of a specific rolish color scheme
4878: bgcolor -> override the default page bgcolor
4879:
4880: =cut
4881:
1.343 albertel 4882: sub standard_css {
1.345 albertel 4883: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4884: $function = &get_users_function() if (!$function);
4885: my $img = &designparm($function.'.img', $domain);
4886: my $tabbg = &designparm($function.'.tabbg', $domain);
4887: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4888: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4889: #second colour for later usage
1.345 albertel 4890: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4891: my $pgbg_or_bgcolor =
4892: $bgcolor ||
1.352 albertel 4893: &designparm($function.'.pgbg', $domain);
1.382 albertel 4894: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4895: my $alink = &designparm($function.'.alink', $domain);
4896: my $vlink = &designparm($function.'.vlink', $domain);
4897: my $link = &designparm($function.'.link', $domain);
4898:
1.602 albertel 4899: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4900: my $mono = 'monospace';
1.850 bisitz 4901: my $data_table_head = $sidebg;
4902: my $data_table_light = '#FAFAFA';
4903: my $data_table_dark = '#F0F0F0';
1.470 banghart 4904: my $data_table_darker = '#CCCCCC';
1.349 albertel 4905: my $data_table_highlight = '#FFFF00';
1.352 albertel 4906: my $mail_new = '#FFBB77';
4907: my $mail_new_hover = '#DD9955';
4908: my $mail_read = '#BBBB77';
4909: my $mail_read_hover = '#999944';
4910: my $mail_replied = '#AAAA88';
4911: my $mail_replied_hover = '#888855';
4912: my $mail_other = '#99BBBB';
4913: my $mail_other_hover = '#669999';
1.391 albertel 4914: my $table_header = '#DDDDDD';
1.489 raeburn 4915: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4916: my $lg_border_color = '#C8C8C8';
1.948.2.1 raeburn 4917: my $button_hover = '#BF2317';
1.392 albertel 4918:
1.608 albertel 4919: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4920: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4921: : '0 3px 0 4px';
1.448 albertel 4922:
1.343 albertel 4923: return <<END;
1.947 droeschl 4924:
4925: /* needed for iframe to allow 100% height in FF */
4926: body, html {
4927: margin: 0;
4928: padding: 0 0.5%;
4929: height: 99%; /* to avoid scrollbars */
4930: }
4931:
1.795 www 4932: body {
1.911 bisitz 4933: font-family: $sans;
4934: line-height:130%;
4935: font-size:0.83em;
4936: color:$font;
1.795 www 4937: }
4938:
1.948.2.9 raeburn 4939: a:focus,
4940: a:focus img {
1.795 www 4941: color: red;
1.911 bisitz 4942: background: yellow;
1.795 www 4943: }
1.698 harmsja 4944:
1.911 bisitz 4945: form, .inline {
4946: display: inline;
1.795 www 4947: }
1.721 harmsja 4948:
1.795 www 4949: .LC_right {
1.911 bisitz 4950: text-align:right;
1.795 www 4951: }
4952:
4953: .LC_middle {
1.911 bisitz 4954: vertical-align:middle;
1.795 www 4955: }
1.721 harmsja 4956:
1.911 bisitz 4957: .LC_400Box {
4958: width:400px;
4959: }
1.721 harmsja 4960:
1.947 droeschl 4961: .LC_iframecontainer {
4962: width: 98%;
4963: margin: 0;
4964: position: fixed;
4965: top: 8.5em;
4966: bottom: 0;
4967: }
4968:
4969: .LC_iframecontainer iframe{
4970: border: none;
4971: width: 100%;
4972: height: 100%;
4973: }
4974:
1.778 bisitz 4975: .LC_filename {
4976: font-family: $mono;
4977: white-space:pre;
1.921 bisitz 4978: font-size: 120%;
1.778 bisitz 4979: }
4980:
4981: .LC_fileicon {
4982: border: none;
4983: height: 1.3em;
4984: vertical-align: text-bottom;
4985: margin-right: 0.3em;
4986: text-decoration:none;
4987: }
4988:
1.350 albertel 4989: .LC_error {
4990: color: red;
4991: font-size: larger;
4992: }
1.795 www 4993:
1.457 albertel 4994: .LC_warning,
4995: .LC_diff_removed {
1.733 bisitz 4996: color: red;
1.394 albertel 4997: }
1.532 albertel 4998:
4999: .LC_info,
1.457 albertel 5000: .LC_success,
5001: .LC_diff_added {
1.350 albertel 5002: color: green;
5003: }
1.795 www 5004:
1.802 bisitz 5005: div.LC_confirm_box {
5006: background-color: #FAFAFA;
5007: border: 1px solid $lg_border_color;
5008: margin-right: 0;
5009: padding: 5px;
5010: }
5011:
5012: div.LC_confirm_box .LC_error img,
5013: div.LC_confirm_box .LC_success img {
5014: vertical-align: middle;
5015: }
5016:
1.440 albertel 5017: .LC_icon {
1.771 droeschl 5018: border: none;
1.790 droeschl 5019: vertical-align: middle;
1.771 droeschl 5020: }
5021:
1.543 albertel 5022: .LC_docs_spacer {
5023: width: 25px;
5024: height: 1px;
1.771 droeschl 5025: border: none;
1.543 albertel 5026: }
1.346 albertel 5027:
1.532 albertel 5028: .LC_internal_info {
1.735 bisitz 5029: color: #999999;
1.532 albertel 5030: }
5031:
1.794 www 5032: .LC_discussion {
1.911 bisitz 5033: background: $tabbg;
5034: border: 1px solid black;
5035: margin: 2px;
1.794 www 5036: }
5037:
5038: .LC_disc_action_links_bar {
1.911 bisitz 5039: background: $tabbg;
5040: border: none;
5041: margin: 4px;
1.794 www 5042: }
5043:
5044: .LC_disc_action_left {
1.911 bisitz 5045: text-align: left;
1.794 www 5046: }
5047:
5048: .LC_disc_action_right {
1.911 bisitz 5049: text-align: right;
1.794 www 5050: }
5051:
5052: .LC_disc_new_item {
1.911 bisitz 5053: background: white;
5054: border: 2px solid red;
5055: margin: 2px;
1.794 www 5056: }
5057:
5058: .LC_disc_old_item {
1.911 bisitz 5059: background: white;
5060: border: 1px solid black;
5061: margin: 2px;
1.794 www 5062: }
5063:
1.458 albertel 5064: table.LC_pastsubmission {
5065: border: 1px solid black;
5066: margin: 2px;
5067: }
5068:
1.924 bisitz 5069: table#LC_menubuttons {
1.345 albertel 5070: width: 100%;
5071: background: $pgbg;
1.392 albertel 5072: border: 2px;
1.402 albertel 5073: border-collapse: separate;
1.803 bisitz 5074: padding: 0;
1.345 albertel 5075: }
1.392 albertel 5076:
1.801 tempelho 5077: table#LC_title_bar a {
5078: color: $fontmenu;
5079: }
1.836 bisitz 5080:
1.807 droeschl 5081: table#LC_title_bar {
1.819 tempelho 5082: clear: both;
1.836 bisitz 5083: display: none;
1.807 droeschl 5084: }
5085:
1.795 www 5086: table#LC_title_bar,
1.933 droeschl 5087: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5088: table#LC_title_bar.LC_with_remote {
1.359 albertel 5089: width: 100%;
1.392 albertel 5090: border-color: $pgbg;
5091: border-style: solid;
5092: border-width: $border;
1.379 albertel 5093: background: $pgbg;
1.801 tempelho 5094: color: $fontmenu;
1.392 albertel 5095: border-collapse: collapse;
1.803 bisitz 5096: padding: 0;
1.819 tempelho 5097: margin: 0;
1.359 albertel 5098: }
1.795 www 5099:
1.933 droeschl 5100: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5101: margin: 0;
5102: padding: 0;
1.933 droeschl 5103: position: relative;
5104: list-style: none;
1.913 droeschl 5105: }
1.933 droeschl 5106: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5107: display: inline;
5108: }
1.933 droeschl 5109:
5110: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5111: padding: 0;
1.933 droeschl 5112: margin: 0;
5113: float: left;
1.913 droeschl 5114: }
1.933 droeschl 5115: .LC_breadcrumb_tools_tools {
5116: padding: 0;
5117: margin: 0;
1.913 droeschl 5118: float: right;
5119: }
5120:
1.359 albertel 5121: table#LC_title_bar td {
5122: background: $tabbg;
5123: }
1.795 www 5124:
1.911 bisitz 5125: table#LC_menubuttons img {
1.803 bisitz 5126: border: none;
1.346 albertel 5127: }
1.795 www 5128:
1.842 droeschl 5129: .LC_breadcrumbs_component {
1.911 bisitz 5130: float: right;
5131: margin: 0 1em;
1.357 albertel 5132: }
1.842 droeschl 5133: .LC_breadcrumbs_component img {
1.911 bisitz 5134: vertical-align: middle;
1.777 tempelho 5135: }
1.795 www 5136:
1.383 albertel 5137: td.LC_table_cell_checkbox {
5138: text-align: center;
5139: }
1.795 www 5140:
5141: .LC_fontsize_small {
1.911 bisitz 5142: font-size: 70%;
1.705 tempelho 5143: }
5144:
1.844 bisitz 5145: #LC_breadcrumbs {
1.911 bisitz 5146: clear:both;
5147: background: $sidebg;
5148: border-bottom: 1px solid $lg_border_color;
5149: line-height: 2.5em;
1.933 droeschl 5150: overflow: hidden;
1.911 bisitz 5151: margin: 0;
5152: padding: 0;
1.819 tempelho 5153: }
1.862 bisitz 5154:
1.839 droeschl 5155: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 5156: #LC_remote #LC_breadcrumbs {
1.911 bisitz 5157: display:none;
1.839 droeschl 5158: }
1.819 tempelho 5159:
1.844 bisitz 5160: #LC_head_subbox {
1.911 bisitz 5161: clear:both;
5162: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5163: border: 1px solid $sidebg;
5164: margin: 0 0 10px 0;
1.948.2.6 raeburn 5165: padding: 3px;
1.822 bisitz 5166: }
5167:
1.795 www 5168: .LC_fontsize_medium {
1.911 bisitz 5169: font-size: 85%;
1.705 tempelho 5170: }
5171:
1.795 www 5172: .LC_fontsize_large {
1.911 bisitz 5173: font-size: 120%;
1.705 tempelho 5174: }
5175:
1.346 albertel 5176: .LC_menubuttons_inline_text {
5177: color: $font;
1.698 harmsja 5178: font-size: 90%;
1.701 harmsja 5179: padding-left:3px;
1.346 albertel 5180: }
5181:
1.934 droeschl 5182: .LC_menubuttons_inline_text img{
5183: vertical-align: middle;
5184: }
5185:
1.948.2.1 raeburn 5186: li.LC_menubuttons_inline_text img,a {
5187: cursor:pointer;
5188: }
5189:
1.526 www 5190: .LC_menubuttons_link {
5191: text-decoration: none;
5192: }
1.795 www 5193:
1.522 albertel 5194: .LC_menubuttons_category {
1.521 www 5195: color: $font;
1.526 www 5196: background: $pgbg;
1.521 www 5197: font-size: larger;
5198: font-weight: bold;
5199: }
5200:
1.346 albertel 5201: td.LC_menubuttons_text {
1.911 bisitz 5202: color: $font;
1.346 albertel 5203: }
1.706 harmsja 5204:
1.346 albertel 5205: .LC_current_location {
5206: background: $tabbg;
5207: }
1.795 www 5208:
1.938 bisitz 5209: table.LC_data_table {
1.347 albertel 5210: border: 1px solid #000000;
1.402 albertel 5211: border-collapse: separate;
1.426 albertel 5212: border-spacing: 1px;
1.610 albertel 5213: background: $pgbg;
1.347 albertel 5214: }
1.795 www 5215:
1.422 albertel 5216: .LC_data_table_dense {
5217: font-size: small;
5218: }
1.795 www 5219:
1.507 raeburn 5220: table.LC_nested_outer {
5221: border: 1px solid #000000;
1.589 raeburn 5222: border-collapse: collapse;
1.803 bisitz 5223: border-spacing: 0;
1.507 raeburn 5224: width: 100%;
5225: }
1.795 www 5226:
1.879 raeburn 5227: table.LC_innerpickbox,
1.507 raeburn 5228: table.LC_nested {
1.803 bisitz 5229: border: none;
1.589 raeburn 5230: border-collapse: collapse;
1.803 bisitz 5231: border-spacing: 0;
1.507 raeburn 5232: width: 100%;
5233: }
1.795 www 5234:
1.930 faziophi 5235: .ui-accordion,
5236: .ui-accordion table.LC_data_table,
5237: .ui-accordion table.LC_nested_outer{
5238: border: 0px;
5239: border-spacing: 0px;
5240: margin: 3px;
5241: }
5242:
1.911 bisitz 5243: table.LC_data_table tr th,
5244: table.LC_calendar tr th,
1.879 raeburn 5245: table.LC_prior_tries tr th,
5246: table.LC_innerpickbox tr th {
1.349 albertel 5247: font-weight: bold;
5248: background-color: $data_table_head;
1.801 tempelho 5249: color:$fontmenu;
1.701 harmsja 5250: font-size:90%;
1.347 albertel 5251: }
1.795 www 5252:
1.879 raeburn 5253: table.LC_innerpickbox tr th,
5254: table.LC_innerpickbox tr td {
5255: vertical-align: top;
5256: }
5257:
1.711 raeburn 5258: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5259: background-color: #CCCCCC;
1.711 raeburn 5260: font-weight: bold;
5261: text-align: left;
5262: }
1.795 www 5263:
1.912 bisitz 5264: table.LC_data_table tr.LC_odd_row > td {
5265: background-color: $data_table_light;
5266: padding: 2px;
5267: vertical-align: top;
5268: }
5269:
1.809 bisitz 5270: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5271: background-color: $data_table_light;
1.912 bisitz 5272: vertical-align: top;
5273: }
5274:
5275: table.LC_data_table tr.LC_even_row > td {
5276: background-color: $data_table_dark;
1.425 albertel 5277: padding: 2px;
1.900 bisitz 5278: vertical-align: top;
1.347 albertel 5279: }
1.795 www 5280:
1.809 bisitz 5281: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5282: background-color: $data_table_dark;
1.900 bisitz 5283: vertical-align: top;
1.347 albertel 5284: }
1.795 www 5285:
1.425 albertel 5286: table.LC_data_table tr.LC_data_table_highlight td {
5287: background-color: $data_table_darker;
5288: }
1.795 www 5289:
1.639 raeburn 5290: table.LC_data_table tr td.LC_leftcol_header {
5291: background-color: $data_table_head;
5292: font-weight: bold;
5293: }
1.795 www 5294:
1.451 albertel 5295: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5296: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5297: font-weight: bold;
5298: font-style: italic;
5299: text-align: center;
5300: padding: 8px;
1.347 albertel 5301: }
1.795 www 5302:
1.940 bisitz 5303: table.LC_data_table tr.LC_empty_row td {
5304: background-color: $sidebg;
5305: }
5306:
5307: table.LC_nested tr.LC_empty_row td {
5308: background-color: #FFFFFF;
5309: }
5310:
1.890 droeschl 5311: table.LC_caption {
5312: }
5313:
1.507 raeburn 5314: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5315: padding: 4ex
5316: }
1.795 www 5317:
1.507 raeburn 5318: table.LC_nested_outer tr th {
5319: font-weight: bold;
1.801 tempelho 5320: color:$fontmenu;
1.507 raeburn 5321: background-color: $data_table_head;
1.701 harmsja 5322: font-size: small;
1.507 raeburn 5323: border-bottom: 1px solid #000000;
5324: }
1.795 www 5325:
1.507 raeburn 5326: table.LC_nested_outer tr td.LC_subheader {
5327: background-color: $data_table_head;
5328: font-weight: bold;
5329: font-size: small;
5330: border-bottom: 1px solid #000000;
5331: text-align: right;
1.451 albertel 5332: }
1.795 www 5333:
1.507 raeburn 5334: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5335: background-color: #CCCCCC;
1.451 albertel 5336: font-weight: bold;
5337: font-size: small;
1.507 raeburn 5338: text-align: center;
5339: }
1.795 www 5340:
1.589 raeburn 5341: table.LC_nested tr.LC_info_row td.LC_left_item,
5342: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5343: text-align: left;
1.451 albertel 5344: }
1.795 www 5345:
1.507 raeburn 5346: table.LC_nested td {
1.735 bisitz 5347: background-color: #FFFFFF;
1.451 albertel 5348: font-size: small;
1.507 raeburn 5349: }
1.795 www 5350:
1.507 raeburn 5351: table.LC_nested_outer tr th.LC_right_item,
5352: table.LC_nested tr.LC_info_row td.LC_right_item,
5353: table.LC_nested tr.LC_odd_row td.LC_right_item,
5354: table.LC_nested tr td.LC_right_item {
1.451 albertel 5355: text-align: right;
5356: }
5357:
1.930 faziophi 5358: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5359: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5360: text-align: right;
5361: width: 40%;
5362: padding-right:10px;
5363: vertical-align: top;
5364: padding: 5px;
5365: }
5366:
5367: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5368: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5369: text-align: left;
5370: width: 60%;
5371: padding: 2px 4px;
5372: }
5373:
1.507 raeburn 5374: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5375: background-color: #EEEEEE;
1.451 albertel 5376: }
5377:
1.473 raeburn 5378: table.LC_createuser {
5379: }
5380:
5381: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5382: font-size: small;
1.473 raeburn 5383: }
5384:
5385: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5386: background-color: #CCCCCC;
1.473 raeburn 5387: font-weight: bold;
5388: text-align: center;
5389: }
5390:
1.349 albertel 5391: table.LC_calendar {
5392: border: 1px solid #000000;
5393: border-collapse: collapse;
1.917 raeburn 5394: width: 98%;
1.349 albertel 5395: }
1.795 www 5396:
1.349 albertel 5397: table.LC_calendar_pickdate {
5398: font-size: xx-small;
5399: }
1.795 www 5400:
1.349 albertel 5401: table.LC_calendar tr td {
5402: border: 1px solid #000000;
5403: vertical-align: top;
1.917 raeburn 5404: width: 14%;
1.349 albertel 5405: }
1.795 www 5406:
1.349 albertel 5407: table.LC_calendar tr td.LC_calendar_day_empty {
5408: background-color: $data_table_dark;
5409: }
1.795 www 5410:
1.779 bisitz 5411: table.LC_calendar tr td.LC_calendar_day_current {
5412: background-color: $data_table_highlight;
1.777 tempelho 5413: }
1.795 www 5414:
1.938 bisitz 5415: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5416: background-color: $mail_new;
5417: }
1.795 www 5418:
1.938 bisitz 5419: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5420: background-color: $mail_new_hover;
5421: }
1.795 www 5422:
1.938 bisitz 5423: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5424: background-color: $mail_read;
5425: }
1.795 www 5426:
1.938 bisitz 5427: /*
5428: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5429: background-color: $mail_read_hover;
5430: }
1.938 bisitz 5431: */
1.795 www 5432:
1.938 bisitz 5433: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5434: background-color: $mail_replied;
5435: }
1.795 www 5436:
1.938 bisitz 5437: /*
5438: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5439: background-color: $mail_replied_hover;
5440: }
1.938 bisitz 5441: */
1.795 www 5442:
1.938 bisitz 5443: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5444: background-color: $mail_other;
5445: }
1.795 www 5446:
1.938 bisitz 5447: /*
5448: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5449: background-color: $mail_other_hover;
5450: }
1.938 bisitz 5451: */
1.494 raeburn 5452:
1.777 tempelho 5453: table.LC_data_table tr > td.LC_browser_file,
5454: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5455: background: #AAEE77;
1.389 albertel 5456: }
1.795 www 5457:
1.777 tempelho 5458: table.LC_data_table tr > td.LC_browser_file_locked,
5459: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5460: background: #FFAA99;
1.387 albertel 5461: }
1.795 www 5462:
1.777 tempelho 5463: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5464: background: #888888;
1.779 bisitz 5465: }
1.795 www 5466:
1.777 tempelho 5467: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5468: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5469: background: #F8F866;
1.777 tempelho 5470: }
1.795 www 5471:
1.696 bisitz 5472: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5473: background: #E0E8FF;
1.387 albertel 5474: }
1.696 bisitz 5475:
1.707 bisitz 5476: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5477: /* background: #77FF77; */
1.707 bisitz 5478: }
1.795 www 5479:
1.707 bisitz 5480: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5481: border-right: 8px solid #FFFF77;
1.707 bisitz 5482: }
1.795 www 5483:
1.707 bisitz 5484: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5485: border-right: 8px solid #FFAA77;
1.707 bisitz 5486: }
1.795 www 5487:
1.707 bisitz 5488: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5489: border-right: 8px solid #FF7777;
1.707 bisitz 5490: }
1.795 www 5491:
1.707 bisitz 5492: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5493: border-right: 8px solid #AAFF77;
1.707 bisitz 5494: }
1.795 www 5495:
1.707 bisitz 5496: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5497: border-right: 8px solid #11CC55;
1.707 bisitz 5498: }
5499:
1.388 albertel 5500: span.LC_current_location {
1.701 harmsja 5501: font-size:larger;
1.388 albertel 5502: background: $pgbg;
5503: }
1.387 albertel 5504:
1.395 albertel 5505: span.LC_parm_menu_item {
5506: font-size: larger;
5507: }
1.795 www 5508:
1.395 albertel 5509: span.LC_parm_scope_all {
5510: color: red;
5511: }
1.795 www 5512:
1.395 albertel 5513: span.LC_parm_scope_folder {
5514: color: green;
5515: }
1.795 www 5516:
1.395 albertel 5517: span.LC_parm_scope_resource {
5518: color: orange;
5519: }
1.795 www 5520:
1.395 albertel 5521: span.LC_parm_part {
5522: color: blue;
5523: }
1.795 www 5524:
1.911 bisitz 5525: span.LC_parm_folder,
5526: span.LC_parm_symb {
1.395 albertel 5527: font-size: x-small;
5528: font-family: $mono;
5529: color: #AAAAAA;
5530: }
5531:
1.948.2.8 raeburn 5532: ul.LC_parm_parmlist li {
5533: display: inline-block;
5534: padding: 0.3em 0.8em;
5535: vertical-align: top;
5536: width: 150px;
5537: border-top:1px solid $lg_border_color;
5538: }
5539:
1.795 www 5540: td.LC_parm_overview_level_menu,
5541: td.LC_parm_overview_map_menu,
5542: td.LC_parm_overview_parm_selectors,
5543: td.LC_parm_overview_restrictions {
1.396 albertel 5544: border: 1px solid black;
5545: border-collapse: collapse;
5546: }
1.795 www 5547:
1.396 albertel 5548: table.LC_parm_overview_restrictions td {
5549: border-width: 1px 4px 1px 4px;
5550: border-style: solid;
5551: border-color: $pgbg;
5552: text-align: center;
5553: }
1.795 www 5554:
1.396 albertel 5555: table.LC_parm_overview_restrictions th {
5556: background: $tabbg;
5557: border-width: 1px 4px 1px 4px;
5558: border-style: solid;
5559: border-color: $pgbg;
5560: }
1.795 www 5561:
1.398 albertel 5562: table#LC_helpmenu {
1.803 bisitz 5563: border: none;
1.398 albertel 5564: height: 55px;
1.803 bisitz 5565: border-spacing: 0;
1.398 albertel 5566: }
5567:
5568: table#LC_helpmenu fieldset legend {
5569: font-size: larger;
5570: }
1.795 www 5571:
1.397 albertel 5572: table#LC_helpmenu_links {
5573: width: 100%;
5574: border: 1px solid black;
5575: background: $pgbg;
1.803 bisitz 5576: padding: 0;
1.397 albertel 5577: border-spacing: 1px;
5578: }
1.795 www 5579:
1.397 albertel 5580: table#LC_helpmenu_links tr td {
5581: padding: 1px;
5582: background: $tabbg;
1.399 albertel 5583: text-align: center;
5584: font-weight: bold;
1.397 albertel 5585: }
1.396 albertel 5586:
1.795 www 5587: table#LC_helpmenu_links a:link,
5588: table#LC_helpmenu_links a:visited,
1.397 albertel 5589: table#LC_helpmenu_links a:active {
5590: text-decoration: none;
5591: color: $font;
5592: }
1.795 www 5593:
1.397 albertel 5594: table#LC_helpmenu_links a:hover {
5595: text-decoration: underline;
5596: color: $vlink;
5597: }
1.396 albertel 5598:
1.417 albertel 5599: .LC_chrt_popup_exists {
5600: border: 1px solid #339933;
5601: margin: -1px;
5602: }
1.795 www 5603:
1.417 albertel 5604: .LC_chrt_popup_up {
5605: border: 1px solid yellow;
5606: margin: -1px;
5607: }
1.795 www 5608:
1.417 albertel 5609: .LC_chrt_popup {
5610: border: 1px solid #8888FF;
5611: background: #CCCCFF;
5612: }
1.795 www 5613:
1.421 albertel 5614: table.LC_pick_box {
5615: border-collapse: separate;
5616: background: white;
5617: border: 1px solid black;
5618: border-spacing: 1px;
5619: }
1.795 www 5620:
1.421 albertel 5621: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5622: background: $sidebg;
1.421 albertel 5623: font-weight: bold;
1.900 bisitz 5624: text-align: left;
1.740 bisitz 5625: vertical-align: top;
1.421 albertel 5626: width: 184px;
5627: padding: 8px;
5628: }
1.795 www 5629:
1.579 raeburn 5630: table.LC_pick_box td.LC_pick_box_value {
5631: text-align: left;
5632: padding: 8px;
5633: }
1.795 www 5634:
1.579 raeburn 5635: table.LC_pick_box td.LC_pick_box_select {
5636: text-align: left;
5637: padding: 8px;
5638: }
1.795 www 5639:
1.424 albertel 5640: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5641: padding: 0;
1.421 albertel 5642: height: 1px;
5643: background: black;
5644: }
1.795 www 5645:
1.421 albertel 5646: table.LC_pick_box td.LC_pick_box_submit {
5647: text-align: right;
5648: }
1.795 www 5649:
1.579 raeburn 5650: table.LC_pick_box td.LC_evenrow_value {
5651: text-align: left;
5652: padding: 8px;
5653: background-color: $data_table_light;
5654: }
1.795 www 5655:
1.579 raeburn 5656: table.LC_pick_box td.LC_oddrow_value {
5657: text-align: left;
5658: padding: 8px;
5659: background-color: $data_table_light;
5660: }
1.795 www 5661:
1.579 raeburn 5662: span.LC_helpform_receipt_cat {
5663: font-weight: bold;
5664: }
1.795 www 5665:
1.424 albertel 5666: table.LC_group_priv_box {
5667: background: white;
5668: border: 1px solid black;
5669: border-spacing: 1px;
5670: }
1.795 www 5671:
1.424 albertel 5672: table.LC_group_priv_box td.LC_pick_box_title {
5673: background: $tabbg;
5674: font-weight: bold;
5675: text-align: right;
5676: width: 184px;
5677: }
1.795 www 5678:
1.424 albertel 5679: table.LC_group_priv_box td.LC_groups_fixed {
5680: background: $data_table_light;
5681: text-align: center;
5682: }
1.795 www 5683:
1.424 albertel 5684: table.LC_group_priv_box td.LC_groups_optional {
5685: background: $data_table_dark;
5686: text-align: center;
5687: }
1.795 www 5688:
1.424 albertel 5689: table.LC_group_priv_box td.LC_groups_functionality {
5690: background: $data_table_darker;
5691: text-align: center;
5692: font-weight: bold;
5693: }
1.795 www 5694:
1.424 albertel 5695: table.LC_group_priv td {
5696: text-align: left;
1.803 bisitz 5697: padding: 0;
1.424 albertel 5698: }
5699:
1.421 albertel 5700: table.LC_notify_front_page {
5701: background: white;
5702: border: 1px solid black;
5703: padding: 8px;
5704: }
1.795 www 5705:
1.421 albertel 5706: table.LC_notify_front_page td {
5707: padding: 8px;
5708: }
1.795 www 5709:
1.424 albertel 5710: .LC_navbuttons {
5711: margin: 2ex 0ex 2ex 0ex;
5712: }
1.795 www 5713:
1.423 albertel 5714: .LC_topic_bar {
5715: font-weight: bold;
5716: background: $tabbg;
1.918 wenzelju 5717: margin: 1em 0em 1em 2em;
1.805 bisitz 5718: padding: 3px;
1.918 wenzelju 5719: font-size: 1.2em;
1.423 albertel 5720: }
1.795 www 5721:
1.423 albertel 5722: .LC_topic_bar span {
1.918 wenzelju 5723: left: 0.5em;
5724: position: absolute;
1.423 albertel 5725: vertical-align: middle;
1.918 wenzelju 5726: font-size: 1.2em;
1.423 albertel 5727: }
1.795 www 5728:
1.423 albertel 5729: table.LC_course_group_status {
5730: margin: 20px;
5731: }
1.795 www 5732:
1.423 albertel 5733: table.LC_status_selector td {
5734: vertical-align: top;
5735: text-align: center;
1.424 albertel 5736: padding: 4px;
5737: }
1.795 www 5738:
1.599 albertel 5739: div.LC_feedback_link {
1.616 albertel 5740: clear: both;
1.829 kalberla 5741: background: $sidebg;
1.779 bisitz 5742: width: 100%;
1.829 kalberla 5743: padding-bottom: 10px;
5744: border: 1px $tabbg solid;
1.833 kalberla 5745: height: 22px;
5746: line-height: 22px;
5747: padding-top: 5px;
5748: }
5749:
5750: div.LC_feedback_link img {
5751: height: 22px;
1.867 kalberla 5752: vertical-align:middle;
1.829 kalberla 5753: }
5754:
1.911 bisitz 5755: div.LC_feedback_link a {
1.829 kalberla 5756: text-decoration: none;
1.489 raeburn 5757: }
1.795 www 5758:
1.867 kalberla 5759: div.LC_comblock {
1.911 bisitz 5760: display:inline;
1.867 kalberla 5761: color:$font;
5762: font-size:90%;
5763: }
5764:
5765: div.LC_feedback_link div.LC_comblock {
5766: padding-left:5px;
5767: }
5768:
5769: div.LC_feedback_link div.LC_comblock a {
5770: color:$font;
5771: }
5772:
1.489 raeburn 5773: span.LC_feedback_link {
1.858 bisitz 5774: /* background: $feedback_link_bg; */
1.599 albertel 5775: font-size: larger;
5776: }
1.795 www 5777:
1.599 albertel 5778: span.LC_message_link {
1.858 bisitz 5779: /* background: $feedback_link_bg; */
1.599 albertel 5780: font-size: larger;
5781: position: absolute;
5782: right: 1em;
1.489 raeburn 5783: }
1.421 albertel 5784:
1.515 albertel 5785: table.LC_prior_tries {
1.524 albertel 5786: border: 1px solid #000000;
5787: border-collapse: separate;
5788: border-spacing: 1px;
1.515 albertel 5789: }
1.523 albertel 5790:
1.515 albertel 5791: table.LC_prior_tries td {
1.524 albertel 5792: padding: 2px;
1.515 albertel 5793: }
1.523 albertel 5794:
5795: .LC_answer_correct {
1.795 www 5796: background: lightgreen;
5797: color: darkgreen;
5798: padding: 6px;
1.523 albertel 5799: }
1.795 www 5800:
1.523 albertel 5801: .LC_answer_charged_try {
1.797 www 5802: background: #FFAAAA;
1.795 www 5803: color: darkred;
5804: padding: 6px;
1.523 albertel 5805: }
1.795 www 5806:
1.779 bisitz 5807: .LC_answer_not_charged_try,
1.523 albertel 5808: .LC_answer_no_grade,
5809: .LC_answer_late {
1.795 www 5810: background: lightyellow;
1.523 albertel 5811: color: black;
1.795 www 5812: padding: 6px;
1.523 albertel 5813: }
1.795 www 5814:
1.523 albertel 5815: .LC_answer_previous {
1.795 www 5816: background: lightblue;
5817: color: darkblue;
5818: padding: 6px;
1.523 albertel 5819: }
1.795 www 5820:
1.779 bisitz 5821: .LC_answer_no_message {
1.777 tempelho 5822: background: #FFFFFF;
5823: color: black;
1.795 www 5824: padding: 6px;
1.779 bisitz 5825: }
1.795 www 5826:
1.779 bisitz 5827: .LC_answer_unknown {
5828: background: orange;
5829: color: black;
1.795 www 5830: padding: 6px;
1.777 tempelho 5831: }
1.795 www 5832:
1.529 albertel 5833: span.LC_prior_numerical,
5834: span.LC_prior_string,
5835: span.LC_prior_custom,
5836: span.LC_prior_reaction,
5837: span.LC_prior_math {
1.925 bisitz 5838: font-family: $mono;
1.523 albertel 5839: white-space: pre;
5840: }
5841:
1.525 albertel 5842: span.LC_prior_string {
1.925 bisitz 5843: font-family: $mono;
1.525 albertel 5844: white-space: pre;
5845: }
5846:
1.523 albertel 5847: table.LC_prior_option {
5848: width: 100%;
5849: border-collapse: collapse;
5850: }
1.795 www 5851:
1.911 bisitz 5852: table.LC_prior_rank,
1.795 www 5853: table.LC_prior_match {
1.528 albertel 5854: border-collapse: collapse;
5855: }
1.795 www 5856:
1.528 albertel 5857: table.LC_prior_option tr td,
5858: table.LC_prior_rank tr td,
5859: table.LC_prior_match tr td {
1.524 albertel 5860: border: 1px solid #000000;
1.515 albertel 5861: }
5862:
1.855 bisitz 5863: .LC_nobreak {
1.544 albertel 5864: white-space: nowrap;
1.519 raeburn 5865: }
5866:
1.576 raeburn 5867: span.LC_cusr_emph {
5868: font-style: italic;
5869: }
5870:
1.633 raeburn 5871: span.LC_cusr_subheading {
5872: font-weight: normal;
5873: font-size: 85%;
5874: }
5875:
1.861 bisitz 5876: div.LC_docs_entry_move {
1.859 bisitz 5877: border: 1px solid #BBBBBB;
1.545 albertel 5878: background: #DDDDDD;
1.861 bisitz 5879: width: 22px;
1.859 bisitz 5880: padding: 1px;
5881: margin: 0;
1.545 albertel 5882: }
5883:
1.861 bisitz 5884: table.LC_data_table tr > td.LC_docs_entry_commands,
5885: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5886: background: #DDDDDD;
5887: font-size: x-small;
5888: }
1.795 www 5889:
1.861 bisitz 5890: .LC_docs_entry_parameter {
5891: white-space: nowrap;
5892: }
5893:
1.544 albertel 5894: .LC_docs_copy {
1.545 albertel 5895: color: #000099;
1.544 albertel 5896: }
1.795 www 5897:
1.544 albertel 5898: .LC_docs_cut {
1.545 albertel 5899: color: #550044;
1.544 albertel 5900: }
1.795 www 5901:
1.544 albertel 5902: .LC_docs_rename {
1.545 albertel 5903: color: #009900;
1.544 albertel 5904: }
1.795 www 5905:
1.544 albertel 5906: .LC_docs_remove {
1.545 albertel 5907: color: #990000;
5908: }
5909:
1.547 albertel 5910: .LC_docs_reinit_warn,
5911: .LC_docs_ext_edit {
5912: font-size: x-small;
5913: }
5914:
1.545 albertel 5915: table.LC_docs_adddocs td,
5916: table.LC_docs_adddocs th {
5917: border: 1px solid #BBBBBB;
5918: padding: 4px;
5919: background: #DDDDDD;
1.543 albertel 5920: }
5921:
1.584 albertel 5922: table.LC_sty_begin {
5923: background: #BBFFBB;
5924: }
1.795 www 5925:
1.584 albertel 5926: table.LC_sty_end {
5927: background: #FFBBBB;
5928: }
5929:
1.589 raeburn 5930: table.LC_double_column {
1.803 bisitz 5931: border-width: 0;
1.589 raeburn 5932: border-collapse: collapse;
5933: width: 100%;
5934: padding: 2px;
5935: }
5936:
5937: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5938: top: 2px;
1.589 raeburn 5939: left: 2px;
5940: width: 47%;
5941: vertical-align: top;
5942: }
5943:
5944: table.LC_double_column tr td.LC_right_col {
5945: top: 2px;
1.779 bisitz 5946: right: 2px;
1.589 raeburn 5947: width: 47%;
5948: vertical-align: top;
5949: }
5950:
1.591 raeburn 5951: div.LC_left_float {
5952: float: left;
5953: padding-right: 5%;
1.597 albertel 5954: padding-bottom: 4px;
1.591 raeburn 5955: }
5956:
5957: div.LC_clear_float_header {
1.597 albertel 5958: padding-bottom: 2px;
1.591 raeburn 5959: }
5960:
5961: div.LC_clear_float_footer {
1.597 albertel 5962: padding-top: 10px;
1.591 raeburn 5963: clear: both;
5964: }
5965:
1.597 albertel 5966: div.LC_grade_show_user {
1.941 bisitz 5967: /* border-left: 5px solid $sidebg; */
5968: border-top: 5px solid #000000;
5969: margin: 50px 0 0 0;
1.936 bisitz 5970: padding: 15px 0 5px 10px;
1.597 albertel 5971: }
1.795 www 5972:
1.936 bisitz 5973: div.LC_grade_show_user_odd_row {
1.941 bisitz 5974: /* border-left: 5px solid #000000; */
5975: }
5976:
5977: div.LC_grade_show_user div.LC_Box {
5978: margin-right: 50px;
1.597 albertel 5979: }
5980:
5981: div.LC_grade_submissions,
5982: div.LC_grade_message_center,
1.936 bisitz 5983: div.LC_grade_info_links {
1.597 albertel 5984: margin: 5px;
5985: width: 99%;
5986: background: #FFFFFF;
5987: }
1.795 www 5988:
1.597 albertel 5989: div.LC_grade_submissions_header,
1.936 bisitz 5990: div.LC_grade_message_center_header {
1.705 tempelho 5991: font-weight: bold;
5992: font-size: large;
1.597 albertel 5993: }
1.795 www 5994:
1.597 albertel 5995: div.LC_grade_submissions_body,
1.936 bisitz 5996: div.LC_grade_message_center_body {
1.597 albertel 5997: border: 1px solid black;
5998: width: 99%;
5999: background: #FFFFFF;
6000: }
1.795 www 6001:
1.613 albertel 6002: table.LC_scantron_action {
6003: width: 100%;
6004: }
1.795 www 6005:
1.613 albertel 6006: table.LC_scantron_action tr th {
1.698 harmsja 6007: font-weight:bold;
6008: font-style:normal;
1.613 albertel 6009: }
1.795 www 6010:
1.779 bisitz 6011: .LC_edit_problem_header,
1.614 albertel 6012: div.LC_edit_problem_footer {
1.705 tempelho 6013: font-weight: normal;
6014: font-size: medium;
1.602 albertel 6015: margin: 2px;
1.600 albertel 6016: }
1.795 www 6017:
1.600 albertel 6018: div.LC_edit_problem_header,
1.602 albertel 6019: div.LC_edit_problem_header div,
1.614 albertel 6020: div.LC_edit_problem_footer,
6021: div.LC_edit_problem_footer div,
1.602 albertel 6022: div.LC_edit_problem_editxml_header,
6023: div.LC_edit_problem_editxml_header div {
1.600 albertel 6024: margin-top: 5px;
6025: }
1.795 www 6026:
1.600 albertel 6027: div.LC_edit_problem_header_title {
1.705 tempelho 6028: font-weight: bold;
6029: font-size: larger;
1.602 albertel 6030: background: $tabbg;
6031: padding: 3px;
6032: }
1.795 www 6033:
1.602 albertel 6034: table.LC_edit_problem_header_title {
6035: width: 100%;
1.600 albertel 6036: background: $tabbg;
1.602 albertel 6037: }
6038:
6039: div.LC_edit_problem_discards {
6040: float: left;
6041: padding-bottom: 5px;
6042: }
1.795 www 6043:
1.602 albertel 6044: div.LC_edit_problem_saves {
6045: float: right;
6046: padding-bottom: 5px;
1.600 albertel 6047: }
1.795 www 6048:
1.911 bisitz 6049: img.stift {
1.803 bisitz 6050: border-width: 0;
6051: vertical-align: middle;
1.677 riegler 6052: }
1.680 riegler 6053:
1.923 bisitz 6054: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6055: vertical-align: top;
1.777 tempelho 6056: }
1.795 www 6057:
1.716 raeburn 6058: div.LC_createcourse {
1.911 bisitz 6059: margin: 10px 10px 10px 10px;
1.716 raeburn 6060: }
6061:
1.917 raeburn 6062: .LC_dccid {
6063: margin: 0.2em 0 0 0;
6064: padding: 0;
6065: font-size: 90%;
6066: display:none;
6067: }
6068:
1.698 harmsja 6069: a:hover,
1.897 wenzelju 6070: ol.LC_primary_menu a:hover,
1.721 harmsja 6071: ol#LC_MenuBreadcrumbs a:hover,
6072: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6073: ul#LC_secondary_menu a:hover,
1.721 harmsja 6074: .LC_FormSectionClearButton input:hover
1.795 www 6075: ul.LC_TabContent li:hover a {
1.948.2.1 raeburn 6076: color:$button_hover;
1.911 bisitz 6077: text-decoration:none;
1.693 droeschl 6078: }
6079:
1.779 bisitz 6080: h1 {
1.911 bisitz 6081: padding: 0;
6082: line-height:130%;
1.693 droeschl 6083: }
1.698 harmsja 6084:
1.911 bisitz 6085: h2,
6086: h3,
6087: h4,
6088: h5,
6089: h6 {
6090: margin: 5px 0 5px 0;
6091: padding: 0;
6092: line-height:130%;
1.693 droeschl 6093: }
1.795 www 6094:
6095: .LC_hcell {
1.911 bisitz 6096: padding:3px 15px 3px 15px;
6097: margin: 0;
6098: background-color:$tabbg;
6099: color:$fontmenu;
6100: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6101: }
1.795 www 6102:
1.840 bisitz 6103: .LC_Box > .LC_hcell {
1.911 bisitz 6104: margin: 0 -10px 10px -10px;
1.835 bisitz 6105: }
6106:
1.721 harmsja 6107: .LC_noBorder {
1.911 bisitz 6108: border: 0;
1.698 harmsja 6109: }
1.693 droeschl 6110:
1.721 harmsja 6111: .LC_FormSectionClearButton input {
1.911 bisitz 6112: background-color:transparent;
6113: border: none;
6114: cursor:pointer;
6115: text-decoration:underline;
1.693 droeschl 6116: }
1.763 bisitz 6117:
6118: .LC_help_open_topic {
1.911 bisitz 6119: color: #FFFFFF;
6120: background-color: #EEEEFF;
6121: margin: 1px;
6122: padding: 4px;
6123: border: 1px solid #000033;
6124: white-space: nowrap;
6125: /* vertical-align: middle; */
1.759 neumanie 6126: }
1.693 droeschl 6127:
1.911 bisitz 6128: dl,
6129: ul,
6130: div,
6131: fieldset {
6132: margin: 10px 10px 10px 0;
6133: /* overflow: hidden; */
1.693 droeschl 6134: }
1.795 www 6135:
1.838 bisitz 6136: fieldset > legend {
1.911 bisitz 6137: font-weight: bold;
6138: padding: 0 5px 0 5px;
1.838 bisitz 6139: }
6140:
1.813 bisitz 6141: #LC_nav_bar {
1.911 bisitz 6142: float: left;
1.948.2.6 raeburn 6143: margin: 0 0 2px 0;
1.807 droeschl 6144: }
6145:
1.916 droeschl 6146: #LC_realm {
6147: margin: 0.2em 0 0 0;
6148: padding: 0;
6149: font-weight: bold;
6150: text-align: center;
6151: }
6152:
1.911 bisitz 6153: #LC_nav_bar em {
6154: font-weight: bold;
6155: font-style: normal;
1.807 droeschl 6156: }
6157:
1.948.2.6 raeburn 6158: /* Preliminary fix to hide nav_bar inside bookmarks window */
6159: #LC_bookmarks #LC_nav_bar {
6160: display:none;
6161: }
6162:
1.897 wenzelju 6163: ol.LC_primary_menu {
1.911 bisitz 6164: float: right;
1.934 droeschl 6165: margin: 0;
1.807 droeschl 6166: }
6167:
1.929 wenzelju 6168: span.LC_new_message{
6169: font-weight:bold;
6170: color: darkred;
6171: }
6172:
1.852 droeschl 6173: ol#LC_PathBreadcrumbs {
1.911 bisitz 6174: margin: 0;
1.693 droeschl 6175: }
6176:
1.897 wenzelju 6177: ol.LC_primary_menu li {
1.911 bisitz 6178: display: inline;
6179: padding: 5px 5px 0 10px;
6180: vertical-align: top;
1.693 droeschl 6181: }
6182:
1.897 wenzelju 6183: ol.LC_primary_menu li img {
1.911 bisitz 6184: vertical-align: bottom;
1.934 droeschl 6185: height: 1.1em;
1.693 droeschl 6186: }
6187:
1.897 wenzelju 6188: ol.LC_primary_menu a {
1.911 bisitz 6189: color: RGB(80, 80, 80);
6190: text-decoration: none;
1.693 droeschl 6191: }
1.795 www 6192:
1.948.2.7 raeburn 6193: ol.LC_docs_parameters {
6194: margin-left: 0;
6195: padding: 0;
6196: list-style: none;
6197: }
6198:
6199: ol.LC_docs_parameters li {
6200: margin: 0;
6201: padding-right: 20px;
6202: display: inline;
6203: }
6204:
6205: ol.LC_docs_parameters li:before {
6206: content: "\\002022 \\0020";
6207: }
6208:
6209: li.LC_docs_parameters_title {
6210: font-weight: bold;
6211: }
6212:
6213: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6214: content: "";
6215: }
6216:
1.897 wenzelju 6217: ul#LC_secondary_menu {
1.911 bisitz 6218: clear: both;
6219: color: $fontmenu;
6220: background: $tabbg;
6221: list-style: none;
6222: padding: 0;
6223: margin: 0;
6224: width: 100%;
1.808 droeschl 6225: }
6226:
1.897 wenzelju 6227: ul#LC_secondary_menu li {
1.911 bisitz 6228: font-weight: bold;
6229: line-height: 1.8em;
6230: padding: 0 0.8em;
6231: border-right: 1px solid black;
6232: display: inline;
6233: vertical-align: middle;
1.807 droeschl 6234: }
6235:
1.847 tempelho 6236: ul.LC_TabContent {
1.911 bisitz 6237: display:block;
6238: background: $sidebg;
6239: border-bottom: solid 1px $lg_border_color;
6240: list-style:none;
6241: margin: 0 -10px;
6242: padding: 0;
1.693 droeschl 6243: }
6244:
1.795 www 6245: ul.LC_TabContent li,
6246: ul.LC_TabContentBigger li {
1.911 bisitz 6247: float:left;
1.741 harmsja 6248: }
1.795 www 6249:
1.897 wenzelju 6250: ul#LC_secondary_menu li a {
1.911 bisitz 6251: color: $fontmenu;
6252: text-decoration: none;
1.693 droeschl 6253: }
1.795 www 6254:
1.721 harmsja 6255: ul.LC_TabContent {
1.948.2.1 raeburn 6256: min-height:20px;
1.721 harmsja 6257: }
1.795 www 6258:
6259: ul.LC_TabContent li {
1.911 bisitz 6260: vertical-align:middle;
1.948.2.3 raeburn 6261: padding: 0 16px 0 10px;
1.911 bisitz 6262: background-color:$tabbg;
6263: border-bottom:solid 1px $lg_border_color;
1.948.2.1 raeburn 6264: border-right: solid 1px $font;
1.721 harmsja 6265: }
1.795 www 6266:
1.847 tempelho 6267: ul.LC_TabContent .right {
1.911 bisitz 6268: float:right;
1.847 tempelho 6269: }
6270:
1.911 bisitz 6271: ul.LC_TabContent li a,
6272: ul.LC_TabContent li {
6273: color:rgb(47,47,47);
6274: text-decoration:none;
6275: font-size:95%;
6276: font-weight:bold;
1.948.2.1 raeburn 6277: min-height:20px;
6278: }
6279:
1.948.2.3 raeburn 6280: ul.LC_TabContent li a:hover,
6281: ul.LC_TabContent li a:focus {
1.948.2.1 raeburn 6282: color: $button_hover;
1.948.2.3 raeburn 6283: background:none;
6284: outline:none;
1.948.2.1 raeburn 6285: }
6286:
6287: ul.LC_TabContent li:hover {
6288: color: $button_hover;
6289: cursor:pointer;
1.721 harmsja 6290: }
1.795 www 6291:
1.911 bisitz 6292: ul.LC_TabContent li.active {
1.948.2.1 raeburn 6293: color: $font;
1.911 bisitz 6294: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.948.2.1 raeburn 6295: border-bottom:solid 1px #FFFFFF;
6296: cursor: default;
1.744 ehlerst 6297: }
1.795 www 6298:
1.948.2.3 raeburn 6299: ul.LC_TabContent li.active a {
6300: color:$font;
6301: background:#FFFFFF;
6302: outline: none;
6303: }
1.870 tempelho 6304: #maincoursedoc {
1.911 bisitz 6305: clear:both;
1.870 tempelho 6306: }
6307:
6308: ul.LC_TabContentBigger {
1.911 bisitz 6309: display:block;
6310: list-style:none;
6311: padding: 0;
1.870 tempelho 6312: }
6313:
1.795 www 6314: ul.LC_TabContentBigger li {
1.911 bisitz 6315: vertical-align:bottom;
6316: height: 30px;
6317: font-size:110%;
6318: font-weight:bold;
6319: color: #737373;
1.841 tempelho 6320: }
6321:
1.948.2.3 raeburn 6322: ul.LC_TabContentBigger li.active {
6323: position: relative;
6324: top: 1px;
6325: }
1.870 tempelho 6326:
6327: ul.LC_TabContentBigger li a {
1.911 bisitz 6328: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6329: height: 30px;
6330: line-height: 30px;
6331: text-align: center;
6332: display: block;
6333: text-decoration: none;
1.948.2.3 raeburn 6334: outline: none;
1.741 harmsja 6335: }
1.795 www 6336:
1.870 tempelho 6337: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6338: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6339: color:$font;
1.744 ehlerst 6340: }
1.795 www 6341:
1.870 tempelho 6342: ul.LC_TabContentBigger li b {
1.911 bisitz 6343: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6344: display: block;
6345: float: left;
6346: padding: 0 30px;
1.948.2.3 raeburn 6347: border-bottom: 1px solid $lg_border_color;
6348: }
6349:
6350: ul.LC_TabContentBigger li:hover b {
6351: color:$button_hover;
1.870 tempelho 6352: }
6353:
6354: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6355: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6356: color:$font;
1.948.2.3 raeburn 6357: border: 0;
6358: cursor:default;
1.741 harmsja 6359: }
1.693 droeschl 6360:
1.862 bisitz 6361: ul.LC_CourseBreadcrumbs {
6362: background: $sidebg;
6363: line-height: 32px;
6364: padding-left: 10px;
6365: margin: 0 0 10px 0;
6366: list-style-position: inside;
6367:
6368: }
6369:
1.911 bisitz 6370: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6371: ol#LC_PathBreadcrumbs {
1.911 bisitz 6372: padding-left: 10px;
6373: margin: 0;
1.933 droeschl 6374: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6375: }
6376:
1.911 bisitz 6377: ol#LC_MenuBreadcrumbs li,
6378: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6379: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6380: display: inline;
1.933 droeschl 6381: white-space: normal;
1.693 droeschl 6382: }
6383:
1.823 bisitz 6384: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6385: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6386: text-decoration: none;
6387: font-size:90%;
1.693 droeschl 6388: }
1.795 www 6389:
1.948.2.7 raeburn 6390: ol#LC_MenuBreadcrumbs h1 {
6391: display: inline;
6392: font-size: 90%;
6393: line-height: 2.5em;
6394: margin: 0;
6395: padding: 0;
6396: }
6397:
1.795 www 6398: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6399: text-decoration:none;
6400: font-size:100%;
6401: font-weight:bold;
1.693 droeschl 6402: }
1.795 www 6403:
1.840 bisitz 6404: .LC_Box {
1.911 bisitz 6405: border: solid 1px $lg_border_color;
6406: padding: 0 10px 10px 10px;
1.746 neumanie 6407: }
1.795 www 6408:
6409: .LC_AboutMe_Image {
1.911 bisitz 6410: float:left;
6411: margin-right:10px;
1.747 neumanie 6412: }
1.795 www 6413:
6414: .LC_Clear_AboutMe_Image {
1.911 bisitz 6415: clear:left;
1.747 neumanie 6416: }
1.795 www 6417:
1.721 harmsja 6418: dl.LC_ListStyleClean dt {
1.911 bisitz 6419: padding-right: 5px;
6420: display: table-header-group;
1.693 droeschl 6421: }
6422:
1.721 harmsja 6423: dl.LC_ListStyleClean dd {
1.911 bisitz 6424: display: table-row;
1.693 droeschl 6425: }
6426:
1.721 harmsja 6427: .LC_ListStyleClean,
6428: .LC_ListStyleSimple,
6429: .LC_ListStyleNormal,
1.795 www 6430: .LC_ListStyleSpecial {
1.911 bisitz 6431: /* display:block; */
6432: list-style-position: inside;
6433: list-style-type: none;
6434: overflow: hidden;
6435: padding: 0;
1.693 droeschl 6436: }
6437:
1.721 harmsja 6438: .LC_ListStyleSimple li,
6439: .LC_ListStyleSimple dd,
6440: .LC_ListStyleNormal li,
6441: .LC_ListStyleNormal dd,
6442: .LC_ListStyleSpecial li,
1.795 www 6443: .LC_ListStyleSpecial dd {
1.911 bisitz 6444: margin: 0;
6445: padding: 5px 5px 5px 10px;
6446: clear: both;
1.693 droeschl 6447: }
6448:
1.721 harmsja 6449: .LC_ListStyleClean li,
6450: .LC_ListStyleClean dd {
1.911 bisitz 6451: padding-top: 0;
6452: padding-bottom: 0;
1.693 droeschl 6453: }
6454:
1.721 harmsja 6455: .LC_ListStyleSimple dd,
1.795 www 6456: .LC_ListStyleSimple li {
1.911 bisitz 6457: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6458: }
6459:
1.721 harmsja 6460: .LC_ListStyleSpecial li,
6461: .LC_ListStyleSpecial dd {
1.911 bisitz 6462: list-style-type: none;
6463: background-color: RGB(220, 220, 220);
6464: margin-bottom: 4px;
1.693 droeschl 6465: }
6466:
1.721 harmsja 6467: table.LC_SimpleTable {
1.911 bisitz 6468: margin:5px;
6469: border:solid 1px $lg_border_color;
1.795 www 6470: }
1.693 droeschl 6471:
1.721 harmsja 6472: table.LC_SimpleTable tr {
1.911 bisitz 6473: padding: 0;
6474: border:solid 1px $lg_border_color;
1.693 droeschl 6475: }
1.795 www 6476:
6477: table.LC_SimpleTable thead {
1.911 bisitz 6478: background:rgb(220,220,220);
1.693 droeschl 6479: }
6480:
1.721 harmsja 6481: div.LC_columnSection {
1.911 bisitz 6482: display: block;
6483: clear: both;
6484: overflow: hidden;
6485: margin: 0;
1.693 droeschl 6486: }
6487:
1.721 harmsja 6488: div.LC_columnSection>* {
1.911 bisitz 6489: float: left;
6490: margin: 10px 20px 10px 0;
6491: overflow:hidden;
1.693 droeschl 6492: }
1.721 harmsja 6493:
1.795 www 6494: table em {
1.911 bisitz 6495: font-weight: bold;
6496: font-style: normal;
1.748 schulted 6497: }
1.795 www 6498:
1.779 bisitz 6499: table.LC_tableBrowseRes,
1.795 www 6500: table.LC_tableOfContent {
1.911 bisitz 6501: border:none;
6502: border-spacing: 1px;
6503: padding: 3px;
6504: background-color: #FFFFFF;
6505: font-size: 90%;
1.753 droeschl 6506: }
1.789 droeschl 6507:
1.911 bisitz 6508: table.LC_tableOfContent {
6509: border-collapse: collapse;
1.789 droeschl 6510: }
6511:
1.771 droeschl 6512: table.LC_tableBrowseRes a,
1.768 schulted 6513: table.LC_tableOfContent a {
1.911 bisitz 6514: background-color: transparent;
6515: text-decoration: none;
1.753 droeschl 6516: }
6517:
1.795 www 6518: table.LC_tableOfContent img {
1.911 bisitz 6519: border: none;
6520: height: 1.3em;
6521: vertical-align: text-bottom;
6522: margin-right: 0.3em;
1.753 droeschl 6523: }
1.757 schulted 6524:
1.795 www 6525: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6526: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6527: }
6528:
1.795 www 6529: a#LC_content_toolbar_launchnav {
1.911 bisitz 6530: background-image:url(/res/adm/pages/start-navigation.gif);
1.774 ehlerst 6531: }
6532:
1.795 www 6533: a#LC_content_toolbar_closenav {
1.911 bisitz 6534: background-image:url(/res/adm/pages/close-navigation.gif);
1.774 ehlerst 6535: }
6536:
1.795 www 6537: a#LC_content_toolbar_everything {
1.911 bisitz 6538: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6539: }
6540:
1.795 www 6541: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6542: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6543: }
6544:
1.795 www 6545: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6546: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6547: }
6548:
1.795 www 6549: a#LC_content_toolbar_changefolder {
1.911 bisitz 6550: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6551: }
6552:
1.795 www 6553: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6554: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6555: }
6556:
1.795 www 6557: ul#LC_toolbar li a:hover {
1.911 bisitz 6558: background-position: bottom center;
1.757 schulted 6559: }
6560:
1.795 www 6561: ul#LC_toolbar {
1.911 bisitz 6562: padding: 0;
6563: margin: 2px;
6564: list-style:none;
6565: position:relative;
6566: background-color:white;
1.757 schulted 6567: }
6568:
1.795 www 6569: ul#LC_toolbar li {
1.911 bisitz 6570: border:1px solid white;
6571: padding: 0;
6572: margin: 0;
6573: float: left;
6574: display:inline;
6575: vertical-align:middle;
6576: }
1.757 schulted 6577:
1.783 amueller 6578:
1.795 www 6579: a.LC_toolbarItem {
1.911 bisitz 6580: display:block;
6581: padding: 0;
6582: margin: 0;
6583: height: 32px;
6584: width: 32px;
6585: color:white;
6586: border: none;
6587: background-repeat:no-repeat;
6588: background-color:transparent;
1.757 schulted 6589: }
6590:
1.915 droeschl 6591: ul.LC_funclist {
6592: margin: 0;
6593: padding: 0.5em 1em 0.5em 0;
6594: }
6595:
1.933 droeschl 6596: ul.LC_funclist > li:first-child {
6597: font-weight:bold;
6598: margin-left:0.8em;
6599: }
6600:
1.915 droeschl 6601: ul.LC_funclist + ul.LC_funclist {
6602: /*
6603: left border as a seperator if we have more than
6604: one list
6605: */
6606: border-left: 1px solid $sidebg;
6607: /*
6608: this hides the left border behind the border of the
6609: outer box if element is wrapped to the next 'line'
6610: */
6611: margin-left: -1px;
6612: }
6613:
1.843 bisitz 6614: ul.LC_funclist li {
1.915 droeschl 6615: display: inline;
1.782 bisitz 6616: white-space: nowrap;
1.915 droeschl 6617: margin: 0 0 0 25px;
6618: line-height: 150%;
1.782 bisitz 6619: }
6620:
1.930 faziophi 6621: .ui-accordion .LC_advanced_toggle {
6622: float: right;
6623: font-size: 90%;
6624: padding: 0px 4px
6625: }
1.757 schulted 6626:
1.343 albertel 6627: END
6628: }
6629:
1.306 albertel 6630: =pod
6631:
6632: =item * &headtag()
6633:
6634: Returns a uniform footer for LON-CAPA web pages.
6635:
1.307 albertel 6636: Inputs: $title - optional title for the head
6637: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6638: $args - optional arguments
1.319 albertel 6639: force_register - if is true call registerurl so the remote is
6640: informed
1.415 albertel 6641: redirect -> array ref of
6642: 1- seconds before redirect occurs
6643: 2- url to redirect to
6644: 3- whether the side effect should occur
1.315 albertel 6645: (side effect of setting
6646: $env{'internal.head.redirect'} to the url
6647: redirected too)
1.352 albertel 6648: domain -> force to color decorate a page for a specific
6649: domain
6650: function -> force usage of a specific rolish color scheme
6651: bgcolor -> override the default page bgcolor
1.460 albertel 6652: no_auto_mt_title
6653: -> prevent &mt()ing the title arg
1.464 albertel 6654:
1.306 albertel 6655: =cut
6656:
6657: sub headtag {
1.313 albertel 6658: my ($title,$head_extra,$args) = @_;
1.306 albertel 6659:
1.363 albertel 6660: my $function = $args->{'function'} || &get_users_function();
6661: my $domain = $args->{'domain'} || &determinedomain();
6662: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6663: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6664: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6665: #time(),
1.418 albertel 6666: $env{'environment.color.timestamp'},
1.363 albertel 6667: $function,$domain,$bgcolor);
6668:
1.369 www 6669: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6670:
1.308 albertel 6671: my $result =
6672: '<head>'.
1.461 albertel 6673: &font_settings();
1.319 albertel 6674:
1.461 albertel 6675: if (!$args->{'frameset'}) {
6676: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6677: }
1.319 albertel 6678: if ($args->{'force_register'}) {
6679: $result .= &Apache::lonmenu::registerurl(1);
6680: }
1.436 albertel 6681: if (!$args->{'no_nav_bar'}
6682: && !$args->{'only_body'}
6683: && !$args->{'frameset'}) {
6684: $result .= &help_menu_js();
6685: }
1.319 albertel 6686:
1.314 albertel 6687: if (ref($args->{'redirect'})) {
1.414 albertel 6688: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6689: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6690: if (!$inhibit_continue) {
6691: $env{'internal.head.redirect'} = $url;
6692: }
1.313 albertel 6693: $result.=<<ADDMETA
6694: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6695: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6696: ADDMETA
6697: }
1.306 albertel 6698: if (!defined($title)) {
6699: $title = 'The LearningOnline Network with CAPA';
6700: }
1.460 albertel 6701: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6702: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6703: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6704: .$head_extra;
1.306 albertel 6705: return $result;
6706: }
6707:
6708: =pod
6709:
1.340 albertel 6710: =item * &font_settings()
6711:
6712: Returns neccessary <meta> to set the proper encoding
6713:
6714: Inputs: none
6715:
6716: =cut
6717:
6718: sub font_settings {
6719: my $headerstring='';
1.647 www 6720: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6721: $headerstring.=
6722: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6723: }
6724: return $headerstring;
6725: }
6726:
1.341 albertel 6727: =pod
6728:
6729: =item * &xml_begin()
6730:
6731: Returns the needed doctype and <html>
6732:
6733: Inputs: none
6734:
6735: =cut
6736:
6737: sub xml_begin {
6738: my $output='';
6739:
6740: if ($env{'browser.mathml'}) {
6741: $output='<?xml version="1.0"?>'
6742: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6743: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6744:
6745: # .'<!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">] >'
6746: .'<!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">'
6747: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6748: .'xmlns="http://www.w3.org/1999/xhtml">';
6749: } else {
1.849 bisitz 6750: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6751: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6752: }
6753: return $output;
6754: }
1.340 albertel 6755:
6756: =pod
6757:
1.306 albertel 6758: =item * &endheadtag()
6759:
6760: Returns a uniform </head> for LON-CAPA web pages.
6761:
6762: Inputs: none
6763:
6764: =cut
6765:
6766: sub endheadtag {
6767: return '</head>';
6768: }
6769:
6770: =pod
6771:
6772: =item * &head()
6773:
6774: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6775:
1.648 raeburn 6776: Inputs:
6777:
6778: =over 4
6779:
6780: $title - optional title for the page
6781:
6782: $head_extra - optional extra HTML to put inside the <head>
6783:
6784: =back
1.405 albertel 6785:
1.306 albertel 6786: =cut
6787:
6788: sub head {
1.325 albertel 6789: my ($title,$head_extra,$args) = @_;
6790: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6791: }
6792:
6793: =pod
6794:
6795: =item * &start_page()
6796:
6797: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6798:
1.648 raeburn 6799: Inputs:
6800:
6801: =over 4
6802:
6803: $title - optional title for the page
6804:
6805: $head_extra - optional extra HTML to incude inside the <head>
6806:
6807: $args - additional optional args supported are:
6808:
6809: =over 8
6810:
6811: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6812: arg on
1.814 bisitz 6813: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6814: add_entries -> additional attributes to add to the <body>
6815: domain -> force to color decorate a page for a
1.317 albertel 6816: specific domain
1.648 raeburn 6817: function -> force usage of a specific rolish color
1.317 albertel 6818: scheme
1.648 raeburn 6819: redirect -> see &headtag()
6820: bgcolor -> override the default page bg color
6821: js_ready -> return a string ready for being used in
1.317 albertel 6822: a javascript writeln
1.648 raeburn 6823: html_encode -> return a string ready for being used in
1.320 albertel 6824: a html attribute
1.648 raeburn 6825: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6826: $forcereg arg
1.648 raeburn 6827: frameset -> if true will start with a <frameset>
1.330 albertel 6828: rather than <body>
1.648 raeburn 6829: skip_phases -> hash ref of
1.338 albertel 6830: head -> skip the <html><head> generation
6831: body -> skip all <body> generation
1.648 raeburn 6832: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6833: 'Switch To Inline Menu' link
1.648 raeburn 6834: no_auto_mt_title -> prevent &mt()ing the title arg
6835: inherit_jsmath -> when creating popup window in a page,
6836: should it have jsmath forced on by the
6837: current page
1.867 kalberla 6838: bread_crumbs -> Array containing breadcrumbs
1.948.2.12 raeburn 6839: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6840:
1.648 raeburn 6841: =back
1.460 albertel 6842:
1.648 raeburn 6843: =back
1.562 albertel 6844:
1.306 albertel 6845: =cut
6846:
6847: sub start_page {
1.309 albertel 6848: my ($title,$head_extra,$args) = @_;
1.318 albertel 6849: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6850: my %head_args;
1.352 albertel 6851: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6852: 'bgcolor','frameset','no_nav_bar','only_body',
6853: 'no_auto_mt_title') {
1.319 albertel 6854: if (defined($args->{$arg})) {
1.324 raeburn 6855: $head_args{$arg} = $args->{$arg};
1.319 albertel 6856: }
1.313 albertel 6857: }
1.319 albertel 6858:
1.315 albertel 6859: $env{'internal.start_page'}++;
1.338 albertel 6860: my $result;
6861: if (! exists($args->{'skip_phases'}{'head'}) ) {
6862: $result.=
1.341 albertel 6863: &xml_begin().
1.338 albertel 6864: &headtag($title,$head_extra,\%head_args).&endheadtag();
6865: }
6866:
6867: if (! exists($args->{'skip_phases'}{'body'}) ) {
6868: if ($args->{'frameset'}) {
6869: my $attr_string = &make_attr_string($args->{'force_register'},
6870: $args->{'add_entries'});
6871: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6872: } else {
6873: $result .=
6874: &bodytag($title,
6875: $args->{'function'}, $args->{'add_entries'},
6876: $args->{'only_body'}, $args->{'domain'},
6877: $args->{'force_register'}, $args->{'no_nav_bar'},
6878: $args->{'bgcolor'}, $args->{'no_inline_link'},
6879: $args);
6880: }
1.330 albertel 6881: }
1.338 albertel 6882:
1.315 albertel 6883: if ($args->{'js_ready'}) {
1.713 kaisler 6884: $result = &js_ready($result);
1.315 albertel 6885: }
1.320 albertel 6886: if ($args->{'html_encode'}) {
1.713 kaisler 6887: $result = &html_encode($result);
6888: }
6889:
1.813 bisitz 6890: # Preparation for new and consistent functionlist at top of screen
6891: # if ($args->{'functionlist'}) {
6892: # $result .= &build_functionlist();
6893: #}
6894:
6895: # Don't add anything more if only_body wanted
6896: return $result if $args->{'only_body'};
6897:
1.920 raeburn 6898: #Breadcrumbs for Construction Space provided by &bodytag.
6899: if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
6900: return $result;
6901: }
6902:
1.813 bisitz 6903: #Breadcrumbs
1.758 kaisler 6904: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6905: &Apache::lonhtmlcommon::clear_breadcrumbs();
6906: #if any br links exists, add them to the breadcrumbs
6907: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6908: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6909: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6910: }
6911: }
6912:
6913: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6914: if(exists($args->{'bread_crumbs_component'})){
6915: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6916: }else{
6917: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6918: }
1.320 albertel 6919: }
1.315 albertel 6920: return $result;
1.306 albertel 6921: }
6922:
1.330 albertel 6923:
1.306 albertel 6924: =pod
6925:
6926: =item * &head()
6927:
6928: Returns a complete </body></html> section for LON-CAPA web pages.
6929:
1.315 albertel 6930: Inputs: $args - additional optional args supported are:
6931: js_ready -> return a string ready for being used in
6932: a javascript writeln
1.320 albertel 6933: html_encode -> return a string ready for being used in
6934: a html attribute
1.330 albertel 6935: frameset -> if true will start with a <frameset>
6936: rather than <body>
1.493 albertel 6937: dicsussion -> if true will get discussion from
6938: lonxml::xmlend
6939: (you can pass the target and parser arguments
6940: through optional 'target' and 'parser' args
6941: to this routine)
1.306 albertel 6942:
6943: =cut
6944:
6945: sub end_page {
1.315 albertel 6946: my ($args) = @_;
6947: $env{'internal.end_page'}++;
1.330 albertel 6948: my $result;
1.335 albertel 6949: if ($args->{'discussion'}) {
6950: my ($target,$parser);
6951: if (ref($args->{'discussion'})) {
6952: ($target,$parser) =($args->{'discussion'}{'target'},
6953: $args->{'discussion'}{'parser'});
6954: }
6955: $result .= &Apache::lonxml::xmlend($target,$parser);
6956: }
6957:
1.330 albertel 6958: if ($args->{'frameset'}) {
6959: $result .= '</frameset>';
6960: } else {
1.635 raeburn 6961: $result .= &endbodytag($args);
1.330 albertel 6962: }
6963: $result .= "\n</html>";
6964:
1.315 albertel 6965: if ($args->{'js_ready'}) {
1.317 albertel 6966: $result = &js_ready($result);
1.315 albertel 6967: }
1.335 albertel 6968:
1.320 albertel 6969: if ($args->{'html_encode'}) {
6970: $result = &html_encode($result);
6971: }
1.335 albertel 6972:
1.315 albertel 6973: return $result;
6974: }
6975:
1.320 albertel 6976: sub html_encode {
6977: my ($result) = @_;
6978:
1.322 albertel 6979: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6980:
6981: return $result;
6982: }
1.317 albertel 6983: sub js_ready {
6984: my ($result) = @_;
6985:
1.323 albertel 6986: $result =~ s/[\n\r]/ /xmsg;
6987: $result =~ s/\\/\\\\/xmsg;
6988: $result =~ s/'/\\'/xmsg;
1.372 albertel 6989: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6990:
6991: return $result;
6992: }
6993:
1.315 albertel 6994: sub validate_page {
6995: if ( exists($env{'internal.start_page'})
1.316 albertel 6996: && $env{'internal.start_page'} > 1) {
6997: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6998: $env{'internal.start_page'}.' '.
1.316 albertel 6999: $ENV{'request.filename'});
1.315 albertel 7000: }
7001: if ( exists($env{'internal.end_page'})
1.316 albertel 7002: && $env{'internal.end_page'} > 1) {
7003: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7004: $env{'internal.end_page'}.' '.
1.316 albertel 7005: $env{'request.filename'});
1.315 albertel 7006: }
7007: if ( exists($env{'internal.start_page'})
7008: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7009: &Apache::lonnet::logthis('start_page called without end_page '.
7010: $env{'request.filename'});
1.315 albertel 7011: }
7012: if ( ! exists($env{'internal.start_page'})
7013: && exists($env{'internal.end_page'})) {
1.316 albertel 7014: &Apache::lonnet::logthis('end_page called without start_page'.
7015: $env{'request.filename'});
1.315 albertel 7016: }
1.306 albertel 7017: }
1.315 albertel 7018:
1.318 albertel 7019: sub simple_error_page {
7020: my ($r,$title,$msg) = @_;
7021: my $page =
7022: &Apache::loncommon::start_page($title).
7023: &mt($msg).
7024: &Apache::loncommon::end_page();
7025: if (ref($r)) {
7026: $r->print($page);
1.327 albertel 7027: return;
1.318 albertel 7028: }
7029: return $page;
7030: }
1.347 albertel 7031:
7032: {
1.610 albertel 7033: my @row_count;
1.948.2.5 raeburn 7034:
7035: sub start_data_table_count {
7036: unshift(@row_count, 0);
7037: return;
7038: }
7039:
7040: sub end_data_table_count {
7041: shift(@row_count);
7042: return;
7043: }
7044:
1.347 albertel 7045: sub start_data_table {
1.422 albertel 7046: my ($add_class) = @_;
7047: my $css_class = (join(' ','LC_data_table',$add_class));
1.948.2.5 raeburn 7048: &start_data_table_count();
1.422 albertel 7049: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 7050: }
7051:
7052: sub end_data_table {
1.948.2.5 raeburn 7053: &end_data_table_count();
1.389 albertel 7054: return '</table>'."\n";;
1.347 albertel 7055: }
7056:
7057: sub start_data_table_row {
1.422 albertel 7058: my ($add_class) = @_;
1.610 albertel 7059: $row_count[0]++;
7060: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7061: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 7062: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 7063: }
1.471 banghart 7064:
7065: sub continue_data_table_row {
7066: my ($add_class) = @_;
1.610 albertel 7067: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7068: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 7069: return '<tr class="'.$css_class.'">'."\n";;
7070: }
1.347 albertel 7071:
7072: sub end_data_table_row {
1.389 albertel 7073: return '</tr>'."\n";;
1.347 albertel 7074: }
1.367 www 7075:
1.421 albertel 7076: sub start_data_table_empty_row {
1.707 bisitz 7077: # $row_count[0]++;
1.421 albertel 7078: return '<tr class="LC_empty_row" >'."\n";;
7079: }
7080:
7081: sub end_data_table_empty_row {
7082: return '</tr>'."\n";;
7083: }
7084:
1.367 www 7085: sub start_data_table_header_row {
1.389 albertel 7086: return '<tr class="LC_header_row">'."\n";;
1.367 www 7087: }
7088:
7089: sub end_data_table_header_row {
1.389 albertel 7090: return '</tr>'."\n";;
1.367 www 7091: }
1.890 droeschl 7092:
7093: sub data_table_caption {
7094: my $caption = shift;
7095: return "<caption class=\"LC_caption\">$caption</caption>";
7096: }
1.347 albertel 7097: }
7098:
1.548 albertel 7099: =pod
7100:
7101: =item * &inhibit_menu_check($arg)
7102:
7103: Checks for a inhibitmenu state and generates output to preserve it
7104:
7105: Inputs: $arg - can be any of
7106: - undef - in which case the return value is a string
7107: to add into arguments list of a uri
7108: - 'input' - in which case the return value is a HTML
7109: <form> <input> field of type hidden to
7110: preserve the value
7111: - a url - in which case the return value is the url with
7112: the neccesary cgi args added to preserve the
7113: inhibitmenu state
7114: - a ref to a url - no return value, but the string is
7115: updated to include the neccessary cgi
7116: args to preserve the inhibitmenu state
7117:
7118: =cut
7119:
7120: sub inhibit_menu_check {
7121: my ($arg) = @_;
7122: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7123: if ($arg eq 'input') {
7124: if ($env{'form.inhibitmenu'}) {
7125: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7126: } else {
7127: return
7128: }
7129: }
7130: if ($env{'form.inhibitmenu'}) {
7131: if (ref($arg)) {
7132: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7133: } elsif ($arg eq '') {
7134: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7135: } else {
7136: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7137: }
7138: }
7139: if (!ref($arg)) {
7140: return $arg;
7141: }
7142: }
7143:
1.251 albertel 7144: ###############################################
1.182 matthew 7145:
7146: =pod
7147:
1.549 albertel 7148: =back
7149:
7150: =head1 User Information Routines
7151:
7152: =over 4
7153:
1.405 albertel 7154: =item * &get_users_function()
1.182 matthew 7155:
7156: Used by &bodytag to determine the current users primary role.
7157: Returns either 'student','coordinator','admin', or 'author'.
7158:
7159: =cut
7160:
7161: ###############################################
7162: sub get_users_function {
1.815 tempelho 7163: my $function = 'norole';
1.818 tempelho 7164: if ($env{'request.role'}=~/^(st)/) {
7165: $function='student';
7166: }
1.907 raeburn 7167: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7168: $function='coordinator';
7169: }
1.258 albertel 7170: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7171: $function='admin';
7172: }
1.826 bisitz 7173: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7174: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7175: $function='author';
7176: }
7177: return $function;
1.54 www 7178: }
1.99 www 7179:
7180: ###############################################
7181:
1.233 raeburn 7182: =pod
7183:
1.821 raeburn 7184: =item * &show_course()
7185:
7186: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7187: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7188:
7189: Inputs:
7190: None
7191:
7192: Outputs:
7193: Scalar: 1 if 'Course' to be used, 0 otherwise.
7194:
7195: =cut
7196:
7197: ###############################################
7198: sub show_course {
7199: my $course = !$env{'user.adv'};
7200: if (!$env{'user.adv'}) {
7201: foreach my $env (keys(%env)) {
7202: next if ($env !~ m/^user\.priv\./);
7203: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7204: $course = 0;
7205: last;
7206: }
7207: }
7208: }
7209: return $course;
7210: }
7211:
7212: ###############################################
7213:
7214: =pod
7215:
1.542 raeburn 7216: =item * &check_user_status()
1.274 raeburn 7217:
7218: Determines current status of supplied role for a
7219: specific user. Roles can be active, previous or future.
7220:
7221: Inputs:
7222: user's domain, user's username, course's domain,
1.375 raeburn 7223: course's number, optional section ID.
1.274 raeburn 7224:
7225: Outputs:
7226: role status: active, previous or future.
7227:
7228: =cut
7229:
7230: sub check_user_status {
1.412 raeburn 7231: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.948.2.11 raeburn 7232: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7233: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7234: my @uroles = keys %userinfo;
7235: my $srchstr;
7236: my $active_chk = 'none';
1.412 raeburn 7237: my $now = time;
1.274 raeburn 7238: if (@uroles > 0) {
1.908 raeburn 7239: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7240: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7241: } else {
1.412 raeburn 7242: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7243: }
7244: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7245: my $role_end = 0;
7246: my $role_start = 0;
7247: $active_chk = 'active';
1.412 raeburn 7248: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7249: $role_end = $1;
7250: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7251: $role_start = $1;
1.274 raeburn 7252: }
7253: }
7254: if ($role_start > 0) {
1.412 raeburn 7255: if ($now < $role_start) {
1.274 raeburn 7256: $active_chk = 'future';
7257: }
7258: }
7259: if ($role_end > 0) {
1.412 raeburn 7260: if ($now > $role_end) {
1.274 raeburn 7261: $active_chk = 'previous';
7262: }
7263: }
7264: }
7265: }
7266: return $active_chk;
7267: }
7268:
7269: ###############################################
7270:
7271: =pod
7272:
1.405 albertel 7273: =item * &get_sections()
1.233 raeburn 7274:
7275: Determines all the sections for a course including
7276: sections with students and sections containing other roles.
1.419 raeburn 7277: Incoming parameters:
7278:
7279: 1. domain
7280: 2. course number
7281: 3. reference to array containing roles for which sections should
7282: be gathered (optional).
7283: 4. reference to array containing status types for which sections
7284: should be gathered (optional).
7285:
7286: If the third argument is undefined, sections are gathered for any role.
7287: If the fourth argument is undefined, sections are gathered for any status.
7288: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7289:
1.374 raeburn 7290: Returns section hash (keys are section IDs, values are
7291: number of users in each section), subject to the
1.419 raeburn 7292: optional roles filter, optional status filter
1.233 raeburn 7293:
7294: =cut
7295:
7296: ###############################################
7297: sub get_sections {
1.419 raeburn 7298: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7299: if (!defined($cdom) || !defined($cnum)) {
7300: my $cid = $env{'request.course.id'};
7301:
7302: return if (!defined($cid));
7303:
7304: $cdom = $env{'course.'.$cid.'.domain'};
7305: $cnum = $env{'course.'.$cid.'.num'};
7306: }
7307:
7308: my %sectioncount;
1.419 raeburn 7309: my $now = time;
1.240 albertel 7310:
1.366 albertel 7311: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7312: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7313: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7314: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7315: my $start_index = &Apache::loncoursedata::CL_START();
7316: my $end_index = &Apache::loncoursedata::CL_END();
7317: my $status;
1.366 albertel 7318: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7319: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7320: $data->[$status_index],
7321: $data->[$start_index],
7322: $data->[$end_index]);
7323: if ($stu_status eq 'Active') {
7324: $status = 'active';
7325: } elsif ($end < $now) {
7326: $status = 'previous';
7327: } elsif ($start > $now) {
7328: $status = 'future';
7329: }
7330: if ($section ne '-1' && $section !~ /^\s*$/) {
7331: if ((!defined($possible_status)) || (($status ne '') &&
7332: (grep/^\Q$status\E$/,@{$possible_status}))) {
7333: $sectioncount{$section}++;
7334: }
1.240 albertel 7335: }
7336: }
7337: }
7338: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7339: foreach my $user (sort(keys(%courseroles))) {
7340: if ($user !~ /^(\w{2})/) { next; }
7341: my ($role) = ($user =~ /^(\w{2})/);
7342: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7343: my ($section,$status);
1.240 albertel 7344: if ($role eq 'cr' &&
7345: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7346: $section=$1;
7347: }
7348: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7349: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7350: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7351: if ($end == -1 && $start == -1) {
7352: next; #deleted role
7353: }
7354: if (!defined($possible_status)) {
7355: $sectioncount{$section}++;
7356: } else {
7357: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7358: $status = 'active';
7359: } elsif ($end < $now) {
7360: $status = 'future';
7361: } elsif ($start > $now) {
7362: $status = 'previous';
7363: }
7364: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7365: $sectioncount{$section}++;
7366: }
7367: }
1.233 raeburn 7368: }
1.366 albertel 7369: return %sectioncount;
1.233 raeburn 7370: }
7371:
1.274 raeburn 7372: ###############################################
1.294 raeburn 7373:
7374: =pod
1.405 albertel 7375:
7376: =item * &get_course_users()
7377:
1.275 raeburn 7378: Retrieves usernames:domains for users in the specified course
7379: with specific role(s), and access status.
7380:
7381: Incoming parameters:
1.277 albertel 7382: 1. course domain
7383: 2. course number
7384: 3. access status: users must have - either active,
1.275 raeburn 7385: previous, future, or all.
1.277 albertel 7386: 4. reference to array of permissible roles
1.288 raeburn 7387: 5. reference to array of section restrictions (optional)
7388: 6. reference to results object (hash of hashes).
7389: 7. reference to optional userdata hash
1.609 raeburn 7390: 8. reference to optional statushash
1.630 raeburn 7391: 9. flag if privileged users (except those set to unhide in
7392: course settings) should be excluded
1.609 raeburn 7393: Keys of top level results hash are roles.
1.275 raeburn 7394: Keys of inner hashes are username:domain, with
7395: values set to access type.
1.288 raeburn 7396: Optional userdata hash returns an array with arguments in the
7397: same order as loncoursedata::get_classlist() for student data.
7398:
1.609 raeburn 7399: Optional statushash returns
7400:
1.288 raeburn 7401: Entries for end, start, section and status are blank because
7402: of the possibility of multiple values for non-student roles.
7403:
1.275 raeburn 7404: =cut
1.405 albertel 7405:
1.275 raeburn 7406: ###############################################
1.405 albertel 7407:
1.275 raeburn 7408: sub get_course_users {
1.630 raeburn 7409: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7410: my %idx = ();
1.419 raeburn 7411: my %seclists;
1.288 raeburn 7412:
7413: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7414: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7415: $idx{end} = &Apache::loncoursedata::CL_END();
7416: $idx{start} = &Apache::loncoursedata::CL_START();
7417: $idx{id} = &Apache::loncoursedata::CL_ID();
7418: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7419: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7420: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7421:
1.290 albertel 7422: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7423: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7424: my $now = time;
1.277 albertel 7425: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7426: my $match = 0;
1.412 raeburn 7427: my $secmatch = 0;
1.419 raeburn 7428: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7429: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7430: if ($section eq '') {
7431: $section = 'none';
7432: }
1.291 albertel 7433: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7434: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7435: $secmatch = 1;
7436: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7437: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7438: $secmatch = 1;
7439: }
7440: } else {
1.419 raeburn 7441: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7442: $secmatch = 1;
7443: }
1.290 albertel 7444: }
1.412 raeburn 7445: if (!$secmatch) {
7446: next;
7447: }
1.419 raeburn 7448: }
1.275 raeburn 7449: if (defined($$types{'active'})) {
1.288 raeburn 7450: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7451: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7452: $match = 1;
1.275 raeburn 7453: }
7454: }
7455: if (defined($$types{'previous'})) {
1.609 raeburn 7456: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7457: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7458: $match = 1;
1.275 raeburn 7459: }
7460: }
7461: if (defined($$types{'future'})) {
1.609 raeburn 7462: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7463: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7464: $match = 1;
1.275 raeburn 7465: }
7466: }
1.609 raeburn 7467: if ($match) {
7468: push(@{$seclists{$student}},$section);
7469: if (ref($userdata) eq 'HASH') {
7470: $$userdata{$student} = $$classlist{$student};
7471: }
7472: if (ref($statushash) eq 'HASH') {
7473: $statushash->{$student}{'st'}{$section} = $status;
7474: }
1.288 raeburn 7475: }
1.275 raeburn 7476: }
7477: }
1.412 raeburn 7478: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7479: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7480: my $now = time;
1.609 raeburn 7481: my %displaystatus = ( previous => 'Expired',
7482: active => 'Active',
7483: future => 'Future',
7484: );
1.630 raeburn 7485: my %nothide;
7486: if ($hidepriv) {
7487: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7488: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7489: if ($user !~ /:/) {
7490: $nothide{join(':',split(/[\@]/,$user))}=1;
7491: } else {
7492: $nothide{$user} = 1;
7493: }
7494: }
7495: }
1.439 raeburn 7496: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7497: my $match = 0;
1.412 raeburn 7498: my $secmatch = 0;
1.439 raeburn 7499: my $status;
1.412 raeburn 7500: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7501: $user =~ s/:$//;
1.439 raeburn 7502: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7503: if ($end == -1 || $start == -1) {
7504: next;
7505: }
7506: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7507: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7508: my ($uname,$udom) = split(/:/,$user);
7509: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7510: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7511: $secmatch = 1;
7512: } elsif ($usec eq '') {
1.420 albertel 7513: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7514: $secmatch = 1;
7515: }
7516: } else {
7517: if (grep(/^\Q$usec\E$/,@{$sections})) {
7518: $secmatch = 1;
7519: }
7520: }
7521: if (!$secmatch) {
7522: next;
7523: }
1.288 raeburn 7524: }
1.419 raeburn 7525: if ($usec eq '') {
7526: $usec = 'none';
7527: }
1.275 raeburn 7528: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7529: if ($hidepriv) {
7530: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7531: (!$nothide{$uname.':'.$udom})) {
7532: next;
7533: }
7534: }
1.503 raeburn 7535: if ($end > 0 && $end < $now) {
1.439 raeburn 7536: $status = 'previous';
7537: } elsif ($start > $now) {
7538: $status = 'future';
7539: } else {
7540: $status = 'active';
7541: }
1.277 albertel 7542: foreach my $type (keys(%{$types})) {
1.275 raeburn 7543: if ($status eq $type) {
1.420 albertel 7544: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7545: push(@{$$users{$role}{$user}},$type);
7546: }
1.288 raeburn 7547: $match = 1;
7548: }
7549: }
1.419 raeburn 7550: if (($match) && (ref($userdata) eq 'HASH')) {
7551: if (!exists($$userdata{$uname.':'.$udom})) {
7552: &get_user_info($udom,$uname,\%idx,$userdata);
7553: }
1.420 albertel 7554: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7555: push(@{$seclists{$uname.':'.$udom}},$usec);
7556: }
1.609 raeburn 7557: if (ref($statushash) eq 'HASH') {
7558: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7559: }
1.275 raeburn 7560: }
7561: }
7562: }
7563: }
1.290 albertel 7564: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7565: if ((defined($cdom)) && (defined($cnum))) {
7566: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7567: if ( defined($csettings{'internal.courseowner'}) ) {
7568: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7569: next if ($owner eq '');
7570: my ($ownername,$ownerdom);
7571: if ($owner =~ /^([^:]+):([^:]+)$/) {
7572: $ownername = $1;
7573: $ownerdom = $2;
7574: } else {
7575: $ownername = $owner;
7576: $ownerdom = $cdom;
7577: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7578: }
7579: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7580: if (defined($userdata) &&
1.609 raeburn 7581: !exists($$userdata{$owner})) {
7582: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7583: if (!grep(/^none$/,@{$seclists{$owner}})) {
7584: push(@{$seclists{$owner}},'none');
7585: }
7586: if (ref($statushash) eq 'HASH') {
7587: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7588: }
1.290 albertel 7589: }
1.279 raeburn 7590: }
7591: }
7592: }
1.419 raeburn 7593: foreach my $user (keys(%seclists)) {
7594: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7595: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7596: }
1.275 raeburn 7597: }
7598: return;
7599: }
7600:
1.288 raeburn 7601: sub get_user_info {
7602: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7603: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7604: &plainname($uname,$udom,'lastname');
1.291 albertel 7605: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7606: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7607: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7608: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7609: return;
7610: }
1.275 raeburn 7611:
1.472 raeburn 7612: ###############################################
7613:
7614: =pod
7615:
7616: =item * &get_user_quota()
7617:
7618: Retrieves quota assigned for storage of portfolio files for a user
7619:
7620: Incoming parameters:
7621: 1. user's username
7622: 2. user's domain
7623:
7624: Returns:
1.536 raeburn 7625: 1. Disk quota (in Mb) assigned to student.
7626: 2. (Optional) Type of setting: custom or default
7627: (individually assigned or default for user's
7628: institutional status).
7629: 3. (Optional) - User's institutional status (e.g., faculty, staff
7630: or student - types as defined in localenroll::inst_usertypes
7631: for user's domain, which determines default quota for user.
7632: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7633:
7634: If a value has been stored in the user's environment,
1.536 raeburn 7635: it will return that, otherwise it returns the maximal default
7636: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7637:
7638: =cut
7639:
7640: ###############################################
7641:
7642:
7643: sub get_user_quota {
7644: my ($uname,$udom) = @_;
1.536 raeburn 7645: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7646: if (!defined($udom)) {
7647: $udom = $env{'user.domain'};
7648: }
7649: if (!defined($uname)) {
7650: $uname = $env{'user.name'};
7651: }
7652: if (($udom eq '' || $uname eq '') ||
7653: ($udom eq 'public') && ($uname eq 'public')) {
7654: $quota = 0;
1.536 raeburn 7655: $quotatype = 'default';
7656: $defquota = 0;
1.472 raeburn 7657: } else {
1.536 raeburn 7658: my $inststatus;
1.472 raeburn 7659: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7660: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7661: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7662: } else {
1.536 raeburn 7663: my %userenv =
7664: &Apache::lonnet::get('environment',['portfolioquota',
7665: 'inststatus'],$udom,$uname);
1.472 raeburn 7666: my ($tmp) = keys(%userenv);
7667: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7668: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7669: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7670: } else {
7671: undef(%userenv);
7672: }
7673: }
1.536 raeburn 7674: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7675: if ($quota eq '') {
1.536 raeburn 7676: $quota = $defquota;
7677: $quotatype = 'default';
7678: } else {
7679: $quotatype = 'custom';
1.472 raeburn 7680: }
7681: }
1.536 raeburn 7682: if (wantarray) {
7683: return ($quota,$quotatype,$settingstatus,$defquota);
7684: } else {
7685: return $quota;
7686: }
1.472 raeburn 7687: }
7688:
7689: ###############################################
7690:
7691: =pod
7692:
7693: =item * &default_quota()
7694:
1.536 raeburn 7695: Retrieves default quota assigned for storage of user portfolio files,
7696: given an (optional) user's institutional status.
1.472 raeburn 7697:
7698: Incoming parameters:
7699: 1. domain
1.536 raeburn 7700: 2. (Optional) institutional status(es). This is a : separated list of
7701: status types (e.g., faculty, staff, student etc.)
7702: which apply to the user for whom the default is being retrieved.
7703: If the institutional status string in undefined, the domain
7704: default quota will be returned.
1.472 raeburn 7705:
7706: Returns:
7707: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7708: 2. (Optional) institutional type which determined the value of the
7709: default quota.
1.472 raeburn 7710:
7711: If a value has been stored in the domain's configuration db,
7712: it will return that, otherwise it returns 20 (for backwards
7713: compatibility with domains which have not set up a configuration
7714: db file; the original statically defined portfolio quota was 20 Mb).
7715:
1.536 raeburn 7716: If the user's status includes multiple types (e.g., staff and student),
7717: the largest default quota which applies to the user determines the
7718: default quota returned.
7719:
1.780 raeburn 7720: =back
7721:
1.472 raeburn 7722: =cut
7723:
7724: ###############################################
7725:
7726:
7727: sub default_quota {
1.536 raeburn 7728: my ($udom,$inststatus) = @_;
7729: my ($defquota,$settingstatus);
7730: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7731: ['quotas'],$udom);
7732: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7733: if ($inststatus ne '') {
1.765 raeburn 7734: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7735: foreach my $item (@statuses) {
1.711 raeburn 7736: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7737: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7738: if ($defquota eq '') {
7739: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7740: $settingstatus = $item;
7741: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7742: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7743: $settingstatus = $item;
7744: }
7745: }
7746: } else {
7747: if ($quotahash{'quotas'}{$item} ne '') {
7748: if ($defquota eq '') {
7749: $defquota = $quotahash{'quotas'}{$item};
7750: $settingstatus = $item;
7751: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7752: $defquota = $quotahash{'quotas'}{$item};
7753: $settingstatus = $item;
7754: }
1.536 raeburn 7755: }
7756: }
7757: }
7758: }
7759: if ($defquota eq '') {
1.711 raeburn 7760: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7761: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7762: } else {
7763: $defquota = $quotahash{'quotas'}{'default'};
7764: }
1.536 raeburn 7765: $settingstatus = 'default';
7766: }
7767: } else {
7768: $settingstatus = 'default';
7769: $defquota = 20;
7770: }
7771: if (wantarray) {
7772: return ($defquota,$settingstatus);
1.472 raeburn 7773: } else {
1.536 raeburn 7774: return $defquota;
1.472 raeburn 7775: }
7776: }
7777:
1.384 raeburn 7778: sub get_secgrprole_info {
7779: my ($cdom,$cnum,$needroles,$type) = @_;
7780: my %sections_count = &get_sections($cdom,$cnum);
7781: my @sections = (sort {$a <=> $b} keys(%sections_count));
7782: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7783: my @groups = sort(keys(%curr_groups));
7784: my $allroles = [];
7785: my $rolehash;
7786: my $accesshash = {
7787: active => 'Currently has access',
7788: future => 'Will have future access',
7789: previous => 'Previously had access',
7790: };
7791: if ($needroles) {
7792: $rolehash = {'all' => 'all'};
1.385 albertel 7793: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7794: if (&Apache::lonnet::error(%user_roles)) {
7795: undef(%user_roles);
7796: }
7797: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7798: my ($role)=split(/\:/,$item,2);
7799: if ($role eq 'cr') { next; }
7800: if ($role =~ /^cr/) {
7801: $$rolehash{$role} = (split('/',$role))[3];
7802: } else {
7803: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7804: }
7805: }
7806: foreach my $key (sort(keys(%{$rolehash}))) {
7807: push(@{$allroles},$key);
7808: }
7809: push (@{$allroles},'st');
7810: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7811: }
7812: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7813: }
7814:
1.555 raeburn 7815: sub user_picker {
1.627 raeburn 7816: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7817: my $currdom = $dom;
7818: my %curr_selected = (
7819: srchin => 'dom',
1.580 raeburn 7820: srchby => 'lastname',
1.555 raeburn 7821: );
7822: my $srchterm;
1.625 raeburn 7823: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7824: if ($srch->{'srchby'} ne '') {
7825: $curr_selected{'srchby'} = $srch->{'srchby'};
7826: }
7827: if ($srch->{'srchin'} ne '') {
7828: $curr_selected{'srchin'} = $srch->{'srchin'};
7829: }
7830: if ($srch->{'srchtype'} ne '') {
7831: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7832: }
7833: if ($srch->{'srchdomain'} ne '') {
7834: $currdom = $srch->{'srchdomain'};
7835: }
7836: $srchterm = $srch->{'srchterm'};
7837: }
7838: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7839: 'usr' => 'Search criteria',
1.563 raeburn 7840: 'doma' => 'Domain/institution to search',
1.558 albertel 7841: 'uname' => 'username',
7842: 'lastname' => 'last name',
1.555 raeburn 7843: 'lastfirst' => 'last name, first name',
1.558 albertel 7844: 'crs' => 'in this course',
1.576 raeburn 7845: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7846: 'alc' => 'all LON-CAPA',
1.573 raeburn 7847: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7848: 'exact' => 'is',
7849: 'contains' => 'contains',
1.569 raeburn 7850: 'begins' => 'begins with',
1.571 raeburn 7851: 'youm' => "You must include some text to search for.",
7852: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7853: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7854: 'yomc' => "You must choose a domain when using an institutional directory search.",
7855: 'ymcd' => "You must choose a domain when using a domain search.",
7856: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7857: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7858: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7859: );
1.563 raeburn 7860: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7861: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7862:
7863: my @srchins = ('crs','dom','alc','instd');
7864:
7865: foreach my $option (@srchins) {
7866: # FIXME 'alc' option unavailable until
7867: # loncreateuser::print_user_query_page()
7868: # has been completed.
7869: next if ($option eq 'alc');
1.880 raeburn 7870: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7871: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7872: if ($curr_selected{'srchin'} eq $option) {
7873: $srchinsel .= '
7874: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7875: } else {
7876: $srchinsel .= '
7877: <option value="'.$option.'">'.$lt{$option}.'</option>';
7878: }
1.555 raeburn 7879: }
1.563 raeburn 7880: $srchinsel .= "\n </select>\n";
1.555 raeburn 7881:
7882: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7883: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7884: if ($curr_selected{'srchby'} eq $option) {
7885: $srchbysel .= '
7886: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7887: } else {
7888: $srchbysel .= '
7889: <option value="'.$option.'">'.$lt{$option}.'</option>';
7890: }
7891: }
7892: $srchbysel .= "\n </select>\n";
7893:
7894: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7895: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7896: if ($curr_selected{'srchtype'} eq $option) {
7897: $srchtypesel .= '
7898: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7899: } else {
7900: $srchtypesel .= '
7901: <option value="'.$option.'">'.$lt{$option}.'</option>';
7902: }
7903: }
7904: $srchtypesel .= "\n </select>\n";
7905:
1.558 albertel 7906: my ($newuserscript,$new_user_create);
1.556 raeburn 7907:
7908: if ($forcenewuser) {
1.576 raeburn 7909: if (ref($srch) eq 'HASH') {
7910: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7911: if ($cancreate) {
7912: $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>';
7913: } else {
1.799 bisitz 7914: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7915: my %usertypetext = (
7916: official => 'institutional',
7917: unofficial => 'non-institutional',
7918: );
1.799 bisitz 7919: $new_user_create = '<p class="LC_warning">'
7920: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7921: .' '
7922: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7923: ,'<a href="'.$helplink.'">','</a>')
7924: .'</p><br />';
1.627 raeburn 7925: }
1.576 raeburn 7926: }
7927: }
7928:
1.556 raeburn 7929: $newuserscript = <<"ENDSCRIPT";
7930:
1.570 raeburn 7931: function setSearch(createnew,callingForm) {
1.556 raeburn 7932: if (createnew == 1) {
1.570 raeburn 7933: for (var i=0; i<callingForm.srchby.length; i++) {
7934: if (callingForm.srchby.options[i].value == 'uname') {
7935: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7936: }
7937: }
1.570 raeburn 7938: for (var i=0; i<callingForm.srchin.length; i++) {
7939: if ( callingForm.srchin.options[i].value == 'dom') {
7940: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7941: }
7942: }
1.570 raeburn 7943: for (var i=0; i<callingForm.srchtype.length; i++) {
7944: if (callingForm.srchtype.options[i].value == 'exact') {
7945: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7946: }
7947: }
1.570 raeburn 7948: for (var i=0; i<callingForm.srchdomain.length; i++) {
7949: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7950: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7951: }
7952: }
7953: }
7954: }
7955: ENDSCRIPT
1.558 albertel 7956:
1.556 raeburn 7957: }
7958:
1.555 raeburn 7959: my $output = <<"END_BLOCK";
1.556 raeburn 7960: <script type="text/javascript">
1.824 bisitz 7961: // <![CDATA[
1.570 raeburn 7962: function validateEntry(callingForm) {
1.558 albertel 7963:
1.556 raeburn 7964: var checkok = 1;
1.558 albertel 7965: var srchin;
1.570 raeburn 7966: for (var i=0; i<callingForm.srchin.length; i++) {
7967: if ( callingForm.srchin[i].checked ) {
7968: srchin = callingForm.srchin[i].value;
1.558 albertel 7969: }
7970: }
7971:
1.570 raeburn 7972: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7973: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7974: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7975: var srchterm = callingForm.srchterm.value;
7976: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7977: var msg = "";
7978:
7979: if (srchterm == "") {
7980: checkok = 0;
1.571 raeburn 7981: msg += "$lt{'youm'}\\n";
1.556 raeburn 7982: }
7983:
1.569 raeburn 7984: if (srchtype== 'begins') {
7985: if (srchterm.length < 2) {
7986: checkok = 0;
1.571 raeburn 7987: msg += "$lt{'thte'}\\n";
1.569 raeburn 7988: }
7989: }
7990:
1.556 raeburn 7991: if (srchtype== 'contains') {
7992: if (srchterm.length < 3) {
7993: checkok = 0;
1.571 raeburn 7994: msg += "$lt{'thet'}\\n";
1.556 raeburn 7995: }
7996: }
7997: if (srchin == 'instd') {
7998: if (srchdomain == '') {
7999: checkok = 0;
1.571 raeburn 8000: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8001: }
8002: }
8003: if (srchin == 'dom') {
8004: if (srchdomain == '') {
8005: checkok = 0;
1.571 raeburn 8006: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8007: }
8008: }
8009: if (srchby == 'lastfirst') {
8010: if (srchterm.indexOf(",") == -1) {
8011: checkok = 0;
1.571 raeburn 8012: msg += "$lt{'whus'}\\n";
1.556 raeburn 8013: }
8014: if (srchterm.indexOf(",") == srchterm.length -1) {
8015: checkok = 0;
1.571 raeburn 8016: msg += "$lt{'whse'}\\n";
1.556 raeburn 8017: }
8018: }
8019: if (checkok == 0) {
1.571 raeburn 8020: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8021: return;
8022: }
8023: if (checkok == 1) {
1.570 raeburn 8024: callingForm.submit();
1.556 raeburn 8025: }
8026: }
8027:
8028: $newuserscript
8029:
1.824 bisitz 8030: // ]]>
1.556 raeburn 8031: </script>
1.558 albertel 8032:
8033: $new_user_create
8034:
1.555 raeburn 8035: END_BLOCK
1.558 albertel 8036:
1.876 raeburn 8037: $output .= &Apache::lonhtmlcommon::start_pick_box().
8038: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8039: $domform.
8040: &Apache::lonhtmlcommon::row_closure().
8041: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8042: $srchbysel.
8043: $srchtypesel.
8044: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8045: $srchinsel.
8046: &Apache::lonhtmlcommon::row_closure(1).
8047: &Apache::lonhtmlcommon::end_pick_box().
8048: '<br />';
1.555 raeburn 8049: return $output;
8050: }
8051:
1.612 raeburn 8052: sub user_rule_check {
1.615 raeburn 8053: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8054: my $response;
8055: if (ref($usershash) eq 'HASH') {
8056: foreach my $user (keys(%{$usershash})) {
8057: my ($uname,$udom) = split(/:/,$user);
8058: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8059: my ($id,$newuser);
1.612 raeburn 8060: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8061: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8062: $id = $usershash->{$user}->{'id'};
8063: }
8064: my $inst_response;
8065: if (ref($checks) eq 'HASH') {
8066: if (defined($checks->{'username'})) {
1.615 raeburn 8067: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8068: &Apache::lonnet::get_instuser($udom,$uname);
8069: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8070: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8071: &Apache::lonnet::get_instuser($udom,undef,$id);
8072: }
1.615 raeburn 8073: } else {
8074: ($inst_response,%{$inst_results->{$user}}) =
8075: &Apache::lonnet::get_instuser($udom,$uname);
8076: return;
1.612 raeburn 8077: }
1.615 raeburn 8078: if (!$got_rules->{$udom}) {
1.612 raeburn 8079: my %domconfig = &Apache::lonnet::get_dom('configuration',
8080: ['usercreation'],$udom);
8081: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 8082: foreach my $item ('username','id') {
1.612 raeburn 8083: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
8084: $$curr_rules{$udom}{$item} =
8085: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 8086: }
8087: }
8088: }
1.615 raeburn 8089: $got_rules->{$udom} = 1;
1.585 raeburn 8090: }
1.612 raeburn 8091: foreach my $item (keys(%{$checks})) {
8092: if (ref($$curr_rules{$udom}) eq 'HASH') {
8093: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
8094: if (@{$$curr_rules{$udom}{$item}} > 0) {
8095: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
8096: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
8097: if ($rule_check{$rule}) {
8098: $$rulematch{$user}{$item} = $rule;
8099: if ($inst_response eq 'ok') {
1.615 raeburn 8100: if (ref($inst_results) eq 'HASH') {
8101: if (ref($inst_results->{$user}) eq 'HASH') {
8102: if (keys(%{$inst_results->{$user}}) == 0) {
8103: $$alerts{$item}{$udom}{$uname} = 1;
8104: }
1.612 raeburn 8105: }
8106: }
1.615 raeburn 8107: }
8108: last;
1.585 raeburn 8109: }
8110: }
8111: }
8112: }
8113: }
8114: }
8115: }
8116: }
1.612 raeburn 8117: return;
8118: }
8119:
8120: sub user_rule_formats {
8121: my ($domain,$domdesc,$curr_rules,$check) = @_;
8122: my %text = (
8123: 'username' => 'Usernames',
8124: 'id' => 'IDs',
8125: );
8126: my $output;
8127: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8128: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8129: if (@{$ruleorder} > 0) {
8130: $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>';
8131: foreach my $rule (@{$ruleorder}) {
8132: if (ref($curr_rules) eq 'ARRAY') {
8133: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8134: if (ref($rules->{$rule}) eq 'HASH') {
8135: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8136: $rules->{$rule}{'desc'}.'</li>';
8137: }
8138: }
8139: }
8140: }
8141: $output .= '</ul>';
8142: }
8143: }
8144: return $output;
8145: }
8146:
8147: sub instrule_disallow_msg {
1.615 raeburn 8148: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8149: my $response;
8150: my %text = (
8151: item => 'username',
8152: items => 'usernames',
8153: match => 'matches',
8154: do => 'does',
8155: action => 'a username',
8156: one => 'one',
8157: );
8158: if ($count > 1) {
8159: $text{'item'} = 'usernames';
8160: $text{'match'} ='match';
8161: $text{'do'} = 'do';
8162: $text{'action'} = 'usernames',
8163: $text{'one'} = 'ones';
8164: }
8165: if ($checkitem eq 'id') {
8166: $text{'items'} = 'IDs';
8167: $text{'item'} = 'ID';
8168: $text{'action'} = 'an ID';
1.615 raeburn 8169: if ($count > 1) {
8170: $text{'item'} = 'IDs';
8171: $text{'action'} = 'IDs';
8172: }
1.612 raeburn 8173: }
1.674 bisitz 8174: $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 8175: if ($mode eq 'upload') {
8176: if ($checkitem eq 'username') {
8177: $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'}.");
8178: } elsif ($checkitem eq 'id') {
1.674 bisitz 8179: $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 8180: }
1.669 raeburn 8181: } elsif ($mode eq 'selfcreate') {
8182: if ($checkitem eq 'id') {
8183: $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.");
8184: }
1.615 raeburn 8185: } else {
8186: if ($checkitem eq 'username') {
8187: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8188: } elsif ($checkitem eq 'id') {
8189: $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.");
8190: }
1.612 raeburn 8191: }
8192: return $response;
1.585 raeburn 8193: }
8194:
1.624 raeburn 8195: sub personal_data_fieldtitles {
8196: my %fieldtitles = &Apache::lonlocal::texthash (
8197: id => 'Student/Employee ID',
8198: permanentemail => 'E-mail address',
8199: lastname => 'Last Name',
8200: firstname => 'First Name',
8201: middlename => 'Middle Name',
8202: generation => 'Generation',
8203: gen => 'Generation',
1.765 raeburn 8204: inststatus => 'Affiliation',
1.624 raeburn 8205: );
8206: return %fieldtitles;
8207: }
8208:
1.642 raeburn 8209: sub sorted_inst_types {
8210: my ($dom) = @_;
8211: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8212: my $othertitle = &mt('All users');
8213: if ($env{'request.course.id'}) {
1.668 raeburn 8214: $othertitle = &mt('Any users');
1.642 raeburn 8215: }
8216: my @types;
8217: if (ref($order) eq 'ARRAY') {
8218: @types = @{$order};
8219: }
8220: if (@types == 0) {
8221: if (ref($usertypes) eq 'HASH') {
8222: @types = sort(keys(%{$usertypes}));
8223: }
8224: }
8225: if (keys(%{$usertypes}) > 0) {
8226: $othertitle = &mt('Other users');
8227: }
8228: return ($othertitle,$usertypes,\@types);
8229: }
8230:
1.645 raeburn 8231: sub get_institutional_codes {
8232: my ($settings,$allcourses,$LC_code) = @_;
8233: # Get complete list of course sections to update
8234: my @currsections = ();
8235: my @currxlists = ();
8236: my $coursecode = $$settings{'internal.coursecode'};
8237:
8238: if ($$settings{'internal.sectionnums'} ne '') {
8239: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8240: }
8241:
8242: if ($$settings{'internal.crosslistings'} ne '') {
8243: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8244: }
8245:
8246: if (@currxlists > 0) {
8247: foreach (@currxlists) {
8248: if (m/^([^:]+):(\w*)$/) {
8249: unless (grep/^$1$/,@{$allcourses}) {
8250: push @{$allcourses},$1;
8251: $$LC_code{$1} = $2;
8252: }
8253: }
8254: }
8255: }
8256:
8257: if (@currsections > 0) {
8258: foreach (@currsections) {
8259: if (m/^(\w+):(\w*)$/) {
8260: my $sec = $coursecode.$1;
8261: my $lc_sec = $2;
8262: unless (grep/^$sec$/,@{$allcourses}) {
8263: push @{$allcourses},$sec;
8264: $$LC_code{$sec} = $lc_sec;
8265: }
8266: }
8267: }
8268: }
8269: return;
8270: }
8271:
1.948.2.7 raeburn 8272: sub get_standard_codeitems {
8273: return ('Year','Semester','Department','Number','Section');
8274: }
8275:
1.112 bowersj2 8276: =pod
8277:
1.780 raeburn 8278: =head1 Slot Helpers
8279:
8280: =over 4
8281:
8282: =item * sorted_slots()
8283:
8284: Sorts an array of slot names in order of slot start time (earliest first).
8285:
8286: Inputs:
8287:
8288: =over 4
8289:
8290: slotsarr - Reference to array of unsorted slot names.
8291:
8292: slots - Reference to hash of hash, where outer hash keys are slot names.
8293:
1.549 albertel 8294: =back
8295:
1.780 raeburn 8296: Returns:
8297:
8298: =over 4
8299:
8300: sorted - An array of slot names sorted by the start time of the slot.
8301:
8302: =back
8303:
8304: =back
8305:
8306: =cut
8307:
8308:
8309: sub sorted_slots {
8310: my ($slotsarr,$slots) = @_;
8311: my @sorted;
8312: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8313: @sorted =
8314: sort {
8315: if (ref($slots->{$a}) && ref($slots->{$b})) {
8316: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8317: }
8318: if (ref($slots->{$a})) { return -1;}
8319: if (ref($slots->{$b})) { return 1;}
8320: return 0;
8321: } @{$slotsarr};
8322: }
8323: return @sorted;
8324: }
8325:
8326:
8327: =pod
8328:
1.549 albertel 8329: =head1 HTTP Helpers
8330:
8331: =over 4
8332:
1.648 raeburn 8333: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8334:
1.258 albertel 8335: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8336: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8337: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8338:
8339: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8340: $possible_names is an ref to an array of form element names. As an example:
8341: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8342: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8343:
8344: =cut
1.1 albertel 8345:
1.6 albertel 8346: sub get_unprocessed_cgi {
1.25 albertel 8347: my ($query,$possible_names)= @_;
1.26 matthew 8348: # $Apache::lonxml::debug=1;
1.356 albertel 8349: foreach my $pair (split(/&/,$query)) {
8350: my ($name, $value) = split(/=/,$pair);
1.369 www 8351: $name = &unescape($name);
1.25 albertel 8352: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8353: $value =~ tr/+/ /;
8354: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8355: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8356: }
1.16 harris41 8357: }
1.6 albertel 8358: }
8359:
1.112 bowersj2 8360: =pod
8361:
1.648 raeburn 8362: =item * &cacheheader()
1.112 bowersj2 8363:
8364: returns cache-controlling header code
8365:
8366: =cut
8367:
1.7 albertel 8368: sub cacheheader {
1.258 albertel 8369: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8370: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8371: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8372: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8373: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8374: return $output;
1.7 albertel 8375: }
8376:
1.112 bowersj2 8377: =pod
8378:
1.648 raeburn 8379: =item * &no_cache($r)
1.112 bowersj2 8380:
8381: specifies header code to not have cache
8382:
8383: =cut
8384:
1.9 albertel 8385: sub no_cache {
1.216 albertel 8386: my ($r) = @_;
8387: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8388: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8389: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8390: $r->no_cache(1);
8391: $r->header_out("Expires" => $date);
8392: $r->header_out("Pragma" => "no-cache");
1.123 www 8393: }
8394:
8395: sub content_type {
1.181 albertel 8396: my ($r,$type,$charset) = @_;
1.299 foxr 8397: if ($r) {
8398: # Note that printout.pl calls this with undef for $r.
8399: &no_cache($r);
8400: }
1.258 albertel 8401: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8402: unless ($charset) {
8403: $charset=&Apache::lonlocal::current_encoding;
8404: }
8405: if ($charset) { $type.='; charset='.$charset; }
8406: if ($r) {
8407: $r->content_type($type);
8408: } else {
8409: print("Content-type: $type\n\n");
8410: }
1.9 albertel 8411: }
1.25 albertel 8412:
1.112 bowersj2 8413: =pod
8414:
1.648 raeburn 8415: =item * &add_to_env($name,$value)
1.112 bowersj2 8416:
1.258 albertel 8417: adds $name to the %env hash with value
1.112 bowersj2 8418: $value, if $name already exists, the entry is converted to an array
8419: reference and $value is added to the array.
8420:
8421: =cut
8422:
1.25 albertel 8423: sub add_to_env {
8424: my ($name,$value)=@_;
1.258 albertel 8425: if (defined($env{$name})) {
8426: if (ref($env{$name})) {
1.25 albertel 8427: #already have multiple values
1.258 albertel 8428: push(@{ $env{$name} },$value);
1.25 albertel 8429: } else {
8430: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8431: my $first=$env{$name};
8432: undef($env{$name});
8433: push(@{ $env{$name} },$first,$value);
1.25 albertel 8434: }
8435: } else {
1.258 albertel 8436: $env{$name}=$value;
1.25 albertel 8437: }
1.31 albertel 8438: }
1.149 albertel 8439:
8440: =pod
8441:
1.648 raeburn 8442: =item * &get_env_multiple($name)
1.149 albertel 8443:
1.258 albertel 8444: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8445: values may be defined and end up as an array ref.
8446:
8447: returns an array of values
8448:
8449: =cut
8450:
8451: sub get_env_multiple {
8452: my ($name) = @_;
8453: my @values;
1.258 albertel 8454: if (defined($env{$name})) {
1.149 albertel 8455: # exists is it an array
1.258 albertel 8456: if (ref($env{$name})) {
8457: @values=@{ $env{$name} };
1.149 albertel 8458: } else {
1.258 albertel 8459: $values[0]=$env{$name};
1.149 albertel 8460: }
8461: }
8462: return(@values);
8463: }
8464:
1.660 raeburn 8465: sub ask_for_embedded_content {
8466: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.948.2.12 raeburn 8467: my (%subdependencies,%dependencies,%newfiles);
1.660 raeburn 8468: my $num = 0;
1.948.2.12 raeburn 8469: my $upload_output;
8470: foreach my $embed_file (keys(%{$allfiles})) {
8471: unless ($embed_file =~ m{^\w+://} || $embed_file =~ m{^/}) {
8472: my ($relpath,$fname);
8473: if ($embed_file =~ m{/}) {
8474: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8475: $subdependencies{$path}{$fname} = 1;
8476: } else {
8477: $dependencies{$embed_file} = 1;
8478: }
8479: }
8480: }
8481: my ($url,$udom,$uname,$getpropath);
8482: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8483: my $current_path='/';
8484: if ($env{'form.currentpath'}) {
8485: $current_path = $env{'form.currentpath'};
8486: }
8487: if ($actionurl eq '/adm/coursegrp_portfolio') {
8488: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8489: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8490: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8491: } else {
8492: $udom = $env{'user.domain'};
8493: $uname = $env{'user.name'};
8494: $url = '/userfiles/portfolio';
8495: }
8496: $url .= $current_path;
8497: $getpropath = 1;
8498: } elsif ($actionurl eq '/adm/upload') {
8499: ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
8500: $url = '/home/'.$uname.'/public_html';
8501: if ($rest ne '') {
8502: $url .= '/'.$rest;
8503: }
8504: }
8505: foreach my $path (keys(%subdependencies)) {
8506: my %currsubfile;
8507: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8508: my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8509: foreach my $line (@subdir_list) {
8510: my ($file_name,$rest) = split(/\&/,$line,2);
8511: $currsubfile{$file_name} = 1;
8512: }
8513: } elsif ($actionurl eq '/adm/upload') {
8514: if (opendir(my $dir,$url.'/'.$path)) {
8515: my @subdir_list = grep(!/^\./,readdir($dir));
8516: map {$currsubfile{$_} = 1;} @subdir_list;
8517: }
8518: }
8519: foreach my $file (keys(%{$subdependencies{$path}})) {
8520: unless ($currsubfile{$file}) {
8521: $newfiles{$path.'/'.$file} = 1;
8522: }
8523: }
8524: }
8525: my (@dir_list,%currfile);
8526: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8527: my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8528: foreach my $line (@dir_list) {
8529: my ($file_name,$rest) = split(/\&/,$line,2);
8530: $currfile{$file_name} = 1;
8531: }
8532: } elsif ($actionurl eq '/adm/upload') {
8533: if (opendir(my $dir,$url)) {
8534: @dir_list = grep(!/^\./,readdir($dir));
8535: map {$currfile{$_} = 1;} @dir_list;
8536: }
8537: }
8538: foreach my $file (keys(%dependencies)) {
8539: unless ($currfile{$file}) {
8540: $newfiles{$file} = 1;
8541: }
8542: }
8543: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8544: $upload_output .= &start_data_table_row().
8545: '<td>'.$embed_file.'</td><td>';
8546: if ($args->{'ignore_remote_references'}
8547: && $embed_file =~ m{^\w+://}) {
8548: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8549: } elsif ($args->{'error_on_invalid_names'}
8550: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8551:
8552: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8553:
8554: } else {
8555: $upload_output .='
1.661 raeburn 8556: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8557: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8558: my $attrib = join(':',@{$$allfiles{$embed_file}});
8559: $upload_output .=
8560: "\n\t\t".
8561: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8562: $attrib.'" />';
8563: if (exists($$codebase{$embed_file})) {
8564: $upload_output .=
8565: "\n\t\t".
8566: '<input name="codebase_'.$num.'" type="hidden" value="'.
8567: &escape($$codebase{$embed_file}).'" />';
8568: }
8569: }
1.948.2.12 raeburn 8570: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
1.660 raeburn 8571: $num++;
8572: }
1.948.2.12 raeburn 8573: if ($num) {
8574: $upload_output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8575: ' method="post" enctype="multipart/form-data">'."\n".
8576: $state.
8577: '<b>Upload embedded files</b>:<br />'.&start_data_table().
8578: $upload_output.
8579: &Apache::loncommon::end_data_table().'<br />'."\n".
8580: '<input type ="hidden" name="number_embedded_items" value="'.$num.'" />'."\n".
8581: '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8582: &mt('(only files for which a location has been provided will be uploaded)')."\n".
8583: '</form>';
8584: }
1.660 raeburn 8585: return $upload_output;
8586: }
8587:
1.661 raeburn 8588: sub upload_embedded {
8589: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8590: $current_disk_usage) = @_;
8591: my $output;
8592: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8593: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8594: my $orig_uploaded_filename =
8595: $env{'form.embedded_item_'.$i.'.filename'};
8596:
8597: $env{'form.embedded_orig_'.$i} =
8598: &unescape($env{'form.embedded_orig_'.$i});
8599: my ($path,$fname) =
8600: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8601: # no path, whole string is fname
8602: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8603:
8604: $path = $env{'form.currentpath'}.$path;
8605: $fname = &Apache::lonnet::clean_filename($fname);
8606: # See if there is anything left
8607: next if ($fname eq '');
8608:
8609: # Check if file already exists as a file or directory.
8610: my ($state,$msg);
8611: if ($context eq 'portfolio') {
8612: my $port_path = $dirpath;
8613: if ($group ne '') {
8614: $port_path = "groups/$group/$port_path";
8615: }
8616: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8617: $dir_root,$port_path,$disk_quota,
8618: $current_disk_usage,$uname,$udom);
8619: if ($state eq 'will_exceed_quota'
1.948.2.12 raeburn 8620: || $state eq 'file_locked') {
1.661 raeburn 8621: $output .= $msg;
8622: next;
8623: }
8624: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8625: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8626: if ($state eq 'exists') {
8627: $output .= $msg;
8628: next;
8629: }
8630: }
8631: # Check if extension is valid
8632: if (($fname =~ /\.(\w+)$/) &&
8633: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8634: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8635: next;
8636: } elsif (($fname =~ /\.(\w+)$/) &&
8637: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8638: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8639: next;
8640: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8641: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8642: next;
8643: }
8644:
8645: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8646: if ($context eq 'portfolio') {
1.948.2.12 raeburn 8647: my $result;
8648: if ($state eq 'existingfile') {
8649: $result=
8650: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
8651: $dirpath.$path,);
1.661 raeburn 8652: } else {
1.948.2.12 raeburn 8653: $result=
8654: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8655: $dirpath.$path);
8656: if ($result !~ m|^/uploaded/|) {
8657: $output .= '<span class="LC_error">'
8658: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8659: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8660: .'</span><br />';
8661: next;
8662: } else {
8663: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8664: $path.$fname.'</span>').'</p>';
8665: }
1.661 raeburn 8666: }
8667: } else {
8668: # Save the file
8669: my $target = $env{'form.embedded_item_'.$i};
8670: my $fullpath = $dir_root.$dirpath.'/'.$path;
8671: my $dest = $fullpath.$fname;
8672: my $url = $url_root.$dirpath.'/'.$path.$fname;
8673: my @parts=split(/\//,$fullpath);
8674: my $count;
8675: my $filepath = $dir_root;
8676: for ($count=4;$count<=$#parts;$count++) {
8677: $filepath .= "/$parts[$count]";
8678: if ((-e $filepath)!=1) {
8679: mkdir($filepath,0770);
8680: }
8681: }
8682: my $fh;
8683: if (!open($fh,'>'.$dest)) {
8684: &Apache::lonnet::logthis('Failed to create '.$dest);
8685: $output .= '<span class="LC_error">'.
8686: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8687: '</span><br />';
8688: } else {
8689: if (!print $fh $env{'form.embedded_item_'.$i}) {
8690: &Apache::lonnet::logthis('Failed to write to '.$dest);
8691: $output .= '<span class="LC_error">'.
8692: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8693: '</span><br />';
8694: } else {
8695: if ($context eq 'testbank') {
8696: $output .= &mt('Embedded file uploaded successfully:').
8697: ' <a href="'.$url.'">'.
8698: $orig_uploaded_filename.'</a><br />';
8699: } else {
1.705 tempelho 8700: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8701: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8702: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8703: }
8704: }
8705: close($fh);
8706: }
8707: }
8708: }
8709: return $output;
8710: }
8711:
8712: sub check_for_existing {
8713: my ($path,$fname,$element) = @_;
8714: my ($state,$msg);
8715: if (-d $path.'/'.$fname) {
8716: $state = 'exists';
8717: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8718: } elsif (-e $path.'/'.$fname) {
8719: $state = 'exists';
8720: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8721: }
8722: if ($state eq 'exists') {
8723: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8724: }
8725: return ($state,$msg);
8726: }
8727:
8728: sub check_for_upload {
8729: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8730: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.948.2.12 raeburn 8731: my $filesize = length($env{'form.'.$element});
8732: if (!$filesize) {
8733: my $msg = '<span class="LC_error">'.
8734: &mt('Unable to upload [_1]. (size = [_2] bytes)',
8735: '<span class="LC_filename">'.$fname.'</span>',
8736: $filesize).'<br />'.
8737: &mt('Either the file you uploaded was empty, or your web browser was unable to read its contents.').'<br />';
8738: '</span>';
8739: return ('zero_bytes',$msg);
8740: }
8741: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 8742: my $getpropath = 1;
8743: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8744: $getpropath);
8745: my $found_file = 0;
8746: my $locked_file = 0;
8747: foreach my $line (@dir_list) {
1.948.2.12 raeburn 8748: my ($file_name,$rest)=split(/\&/,$line,2);
1.661 raeburn 8749: if ($file_name eq $fname){
8750: $file_name = $path.$file_name;
8751: if ($group ne '') {
8752: $file_name = $group.$file_name;
8753: }
8754: $found_file = 1;
8755: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8756: $locked_file = 1;
1.948.2.12 raeburn 8757: } else {
8758: my @info = split(/\&/,$rest);
8759: my $currsize = $info[6]/1000;
8760: if ($currsize < $filesize) {
8761: my $extra = $filesize - $currsize;
8762: if (($current_disk_usage + $extra) > $disk_quota) {
8763: my $msg = '<span class="LC_error">'.
8764: &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.',
8765: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
8766: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8767: $disk_quota,$current_disk_usage);
8768: return ('will_exceed_quota',$msg);
8769: }
8770: }
1.661 raeburn 8771: }
8772: }
8773: }
8774: if (($current_disk_usage + $filesize) > $disk_quota){
8775: my $msg = '<span class="LC_error">'.
8776: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8777: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8778: return ('will_exceed_quota',$msg);
8779: } elsif ($found_file) {
8780: if ($locked_file) {
8781: my $msg = '<span class="LC_error">';
8782: $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>');
8783: $msg .= '</span><br />';
8784: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8785: return ('file_locked',$msg);
8786: } else {
8787: my $msg = '<span class="LC_error">';
1.948.2.12 raeburn 8788: $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 8789: $msg .= '</span>';
1.948.2.12 raeburn 8790: return ('existingfile',$msg);
1.661 raeburn 8791: }
8792: }
8793: }
8794:
1.31 albertel 8795:
1.41 ng 8796: =pod
1.45 matthew 8797:
1.464 albertel 8798: =back
1.41 ng 8799:
1.112 bowersj2 8800: =head1 CSV Upload/Handling functions
1.38 albertel 8801:
1.41 ng 8802: =over 4
8803:
1.648 raeburn 8804: =item * &upfile_store($r)
1.41 ng 8805:
8806: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8807: needs $env{'form.upfile'}
1.41 ng 8808: returns $datatoken to be put into hidden field
8809:
8810: =cut
1.31 albertel 8811:
8812: sub upfile_store {
8813: my $r=shift;
1.258 albertel 8814: $env{'form.upfile'}=~s/\r/\n/gs;
8815: $env{'form.upfile'}=~s/\f/\n/gs;
8816: $env{'form.upfile'}=~s/\n+/\n/gs;
8817: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8818:
1.258 albertel 8819: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8820: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8821: {
1.158 raeburn 8822: my $datafile = $r->dir_config('lonDaemons').
8823: '/tmp/'.$datatoken.'.tmp';
8824: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8825: print $fh $env{'form.upfile'};
1.158 raeburn 8826: close($fh);
8827: }
1.31 albertel 8828: }
8829: return $datatoken;
8830: }
8831:
1.56 matthew 8832: =pod
8833:
1.648 raeburn 8834: =item * &load_tmp_file($r)
1.41 ng 8835:
8836: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8837: needs $env{'form.datatoken'},
8838: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8839:
8840: =cut
1.31 albertel 8841:
8842: sub load_tmp_file {
8843: my $r=shift;
8844: my @studentdata=();
8845: {
1.158 raeburn 8846: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8847: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8848: if ( open(my $fh,"<$studentfile") ) {
8849: @studentdata=<$fh>;
8850: close($fh);
8851: }
1.31 albertel 8852: }
1.258 albertel 8853: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8854: }
8855:
1.56 matthew 8856: =pod
8857:
1.648 raeburn 8858: =item * &upfile_record_sep()
1.41 ng 8859:
8860: Separate uploaded file into records
8861: returns array of records,
1.258 albertel 8862: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8863:
8864: =cut
1.31 albertel 8865:
8866: sub upfile_record_sep {
1.258 albertel 8867: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8868: } else {
1.248 albertel 8869: my @records;
1.258 albertel 8870: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8871: if ($line=~/^\s*$/) { next; }
8872: push(@records,$line);
8873: }
8874: return @records;
1.31 albertel 8875: }
8876: }
8877:
1.56 matthew 8878: =pod
8879:
1.648 raeburn 8880: =item * &record_sep($record)
1.41 ng 8881:
1.258 albertel 8882: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8883:
8884: =cut
8885:
1.263 www 8886: sub takeleft {
8887: my $index=shift;
8888: return substr('0000'.$index,-4,4);
8889: }
8890:
1.31 albertel 8891: sub record_sep {
8892: my $record=shift;
8893: my %components=();
1.258 albertel 8894: if ($env{'form.upfiletype'} eq 'xml') {
8895: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8896: my $i=0;
1.356 albertel 8897: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8898: $field=~s/^(\"|\')//;
8899: $field=~s/(\"|\')$//;
1.263 www 8900: $components{&takeleft($i)}=$field;
1.31 albertel 8901: $i++;
8902: }
1.258 albertel 8903: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8904: my $i=0;
1.356 albertel 8905: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8906: $field=~s/^(\"|\')//;
8907: $field=~s/(\"|\')$//;
1.263 www 8908: $components{&takeleft($i)}=$field;
1.31 albertel 8909: $i++;
8910: }
8911: } else {
1.561 www 8912: my $separator=',';
1.480 banghart 8913: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8914: $separator=';';
1.480 banghart 8915: }
1.31 albertel 8916: my $i=0;
1.561 www 8917: # the character we are looking for to indicate the end of a quote or a record
8918: my $looking_for=$separator;
8919: # do not add the characters to the fields
8920: my $ignore=0;
8921: # we just encountered a separator (or the beginning of the record)
8922: my $just_found_separator=1;
8923: # store the field we are working on here
8924: my $field='';
8925: # work our way through all characters in record
8926: foreach my $character ($record=~/(.)/g) {
8927: if ($character eq $looking_for) {
8928: if ($character ne $separator) {
8929: # Found the end of a quote, again looking for separator
8930: $looking_for=$separator;
8931: $ignore=1;
8932: } else {
8933: # Found a separator, store away what we got
8934: $components{&takeleft($i)}=$field;
8935: $i++;
8936: $just_found_separator=1;
8937: $ignore=0;
8938: $field='';
8939: }
8940: next;
8941: }
8942: # single or double quotation marks after a separator indicate beginning of a quote
8943: # we are now looking for the end of the quote and need to ignore separators
8944: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8945: $looking_for=$character;
8946: next;
8947: }
8948: # ignore would be true after we reached the end of a quote
8949: if ($ignore) { next; }
8950: if (($just_found_separator) && ($character=~/\s/)) { next; }
8951: $field.=$character;
8952: $just_found_separator=0;
1.31 albertel 8953: }
1.561 www 8954: # catch the very last entry, since we never encountered the separator
8955: $components{&takeleft($i)}=$field;
1.31 albertel 8956: }
8957: return %components;
8958: }
8959:
1.144 matthew 8960: ######################################################
8961: ######################################################
8962:
1.56 matthew 8963: =pod
8964:
1.648 raeburn 8965: =item * &upfile_select_html()
1.41 ng 8966:
1.144 matthew 8967: Return HTML code to select a file from the users machine and specify
8968: the file type.
1.41 ng 8969:
8970: =cut
8971:
1.144 matthew 8972: ######################################################
8973: ######################################################
1.31 albertel 8974: sub upfile_select_html {
1.144 matthew 8975: my %Types = (
8976: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8977: semisv => &mt('Semicolon separated values'),
1.144 matthew 8978: space => &mt('Space separated'),
8979: tab => &mt('Tabulator separated'),
8980: # xml => &mt('HTML/XML'),
8981: );
8982: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8983: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8984: foreach my $type (sort(keys(%Types))) {
8985: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8986: }
8987: $Str .= "</select>\n";
8988: return $Str;
1.31 albertel 8989: }
8990:
1.301 albertel 8991: sub get_samples {
8992: my ($records,$toget) = @_;
8993: my @samples=({});
8994: my $got=0;
8995: foreach my $rec (@$records) {
8996: my %temp = &record_sep($rec);
8997: if (! grep(/\S/, values(%temp))) { next; }
8998: if (%temp) {
8999: $samples[$got]=\%temp;
9000: $got++;
9001: if ($got == $toget) { last; }
9002: }
9003: }
9004: return \@samples;
9005: }
9006:
1.144 matthew 9007: ######################################################
9008: ######################################################
9009:
1.56 matthew 9010: =pod
9011:
1.648 raeburn 9012: =item * &csv_print_samples($r,$records)
1.41 ng 9013:
9014: Prints a table of sample values from each column uploaded $r is an
9015: Apache Request ref, $records is an arrayref from
9016: &Apache::loncommon::upfile_record_sep
9017:
9018: =cut
9019:
1.144 matthew 9020: ######################################################
9021: ######################################################
1.31 albertel 9022: sub csv_print_samples {
9023: my ($r,$records) = @_;
1.662 bisitz 9024: my $samples = &get_samples($records,5);
1.301 albertel 9025:
1.594 raeburn 9026: $r->print(&mt('Samples').'<br />'.&start_data_table().
9027: &start_data_table_header_row());
1.356 albertel 9028: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 9029: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 9030: $r->print(&end_data_table_header_row());
1.301 albertel 9031: foreach my $hash (@$samples) {
1.594 raeburn 9032: $r->print(&start_data_table_row());
1.356 albertel 9033: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 9034: $r->print('<td>');
1.356 albertel 9035: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 9036: $r->print('</td>');
9037: }
1.594 raeburn 9038: $r->print(&end_data_table_row());
1.31 albertel 9039: }
1.594 raeburn 9040: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 9041: }
9042:
1.144 matthew 9043: ######################################################
9044: ######################################################
9045:
1.56 matthew 9046: =pod
9047:
1.648 raeburn 9048: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 9049:
9050: Prints a table to create associations between values and table columns.
1.144 matthew 9051:
1.41 ng 9052: $r is an Apache Request ref,
9053: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 9054: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 9055:
9056: =cut
9057:
1.144 matthew 9058: ######################################################
9059: ######################################################
1.31 albertel 9060: sub csv_print_select_table {
9061: my ($r,$records,$d) = @_;
1.301 albertel 9062: my $i=0;
9063: my $samples = &get_samples($records,1);
1.144 matthew 9064: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 9065: &start_data_table().&start_data_table_header_row().
1.144 matthew 9066: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 9067: '<th>'.&mt('Column').'</th>'.
9068: &end_data_table_header_row()."\n");
1.356 albertel 9069: foreach my $array_ref (@$d) {
9070: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 9071: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 9072:
1.875 bisitz 9073: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 9074: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 9075: $r->print('<option value="none"></option>');
1.356 albertel 9076: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
9077: $r->print('<option value="'.$sample.'"'.
9078: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 9079: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 9080: }
1.594 raeburn 9081: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 9082: $i++;
9083: }
1.594 raeburn 9084: $r->print(&end_data_table());
1.31 albertel 9085: $i--;
9086: return $i;
9087: }
1.56 matthew 9088:
1.144 matthew 9089: ######################################################
9090: ######################################################
9091:
1.56 matthew 9092: =pod
1.31 albertel 9093:
1.648 raeburn 9094: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 9095:
9096: Prints a table of sample values from the upload and can make associate samples to internal names.
9097:
9098: $r is an Apache Request ref,
9099: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
9100: $d is an array of 2 element arrays (internal name, displayed name)
9101:
9102: =cut
9103:
1.144 matthew 9104: ######################################################
9105: ######################################################
1.31 albertel 9106: sub csv_samples_select_table {
9107: my ($r,$records,$d) = @_;
9108: my $i=0;
1.144 matthew 9109: #
1.662 bisitz 9110: my $max_samples = 5;
9111: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 9112: $r->print(&start_data_table().
9113: &start_data_table_header_row().'<th>'.
9114: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
9115: &end_data_table_header_row());
1.301 albertel 9116:
9117: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 9118: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 9119: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 9120: foreach my $option (@$d) {
9121: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 9122: $r->print('<option value="'.$value.'"'.
1.253 albertel 9123: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 9124: $display.'</option>');
1.31 albertel 9125: }
9126: $r->print('</select></td><td>');
1.662 bisitz 9127: foreach my $line (0..($max_samples-1)) {
1.301 albertel 9128: if (defined($samples->[$line]{$key})) {
9129: $r->print($samples->[$line]{$key}."<br />\n");
9130: }
9131: }
1.594 raeburn 9132: $r->print('</td>'.&end_data_table_row());
1.31 albertel 9133: $i++;
9134: }
1.594 raeburn 9135: $r->print(&end_data_table());
1.31 albertel 9136: $i--;
9137: return($i);
1.115 matthew 9138: }
9139:
1.144 matthew 9140: ######################################################
9141: ######################################################
9142:
1.115 matthew 9143: =pod
9144:
1.648 raeburn 9145: =item * &clean_excel_name($name)
1.115 matthew 9146:
9147: Returns a replacement for $name which does not contain any illegal characters.
9148:
9149: =cut
9150:
1.144 matthew 9151: ######################################################
9152: ######################################################
1.115 matthew 9153: sub clean_excel_name {
9154: my ($name) = @_;
9155: $name =~ s/[:\*\?\/\\]//g;
9156: if (length($name) > 31) {
9157: $name = substr($name,0,31);
9158: }
9159: return $name;
1.25 albertel 9160: }
1.84 albertel 9161:
1.85 albertel 9162: =pod
9163:
1.648 raeburn 9164: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 9165:
9166: Returns either 1 or undef
9167:
9168: 1 if the part is to be hidden, undef if it is to be shown
9169:
9170: Arguments are:
9171:
9172: $id the id of the part to be checked
9173: $symb, optional the symb of the resource to check
9174: $udom, optional the domain of the user to check for
9175: $uname, optional the username of the user to check for
9176:
9177: =cut
1.84 albertel 9178:
9179: sub check_if_partid_hidden {
9180: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9181: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9182: $symb,$udom,$uname);
1.141 albertel 9183: my $truth=1;
9184: #if the string starts with !, then the list is the list to show not hide
9185: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9186: my @hiddenlist=split(/,/,$hiddenparts);
9187: foreach my $checkid (@hiddenlist) {
1.141 albertel 9188: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9189: }
1.141 albertel 9190: return !$truth;
1.84 albertel 9191: }
1.127 matthew 9192:
1.138 matthew 9193:
9194: ############################################################
9195: ############################################################
9196:
9197: =pod
9198:
1.157 matthew 9199: =back
9200:
1.138 matthew 9201: =head1 cgi-bin script and graphing routines
9202:
1.157 matthew 9203: =over 4
9204:
1.648 raeburn 9205: =item * &get_cgi_id()
1.138 matthew 9206:
9207: Inputs: none
9208:
9209: Returns an id which can be used to pass environment variables
9210: to various cgi-bin scripts. These environment variables will
9211: be removed from the users environment after a given time by
9212: the routine &Apache::lonnet::transfer_profile_to_env.
9213:
9214: =cut
9215:
9216: ############################################################
9217: ############################################################
1.152 albertel 9218: my $uniq=0;
1.136 matthew 9219: sub get_cgi_id {
1.154 albertel 9220: $uniq=($uniq+1)%100000;
1.280 albertel 9221: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9222: }
9223:
1.127 matthew 9224: ############################################################
9225: ############################################################
9226:
9227: =pod
9228:
1.648 raeburn 9229: =item * &DrawBarGraph()
1.127 matthew 9230:
1.138 matthew 9231: Facilitates the plotting of data in a (stacked) bar graph.
9232: Puts plot definition data into the users environment in order for
9233: graph.png to plot it. Returns an <img> tag for the plot.
9234: The bars on the plot are labeled '1','2',...,'n'.
9235:
9236: Inputs:
9237:
9238: =over 4
9239:
9240: =item $Title: string, the title of the plot
9241:
9242: =item $xlabel: string, text describing the X-axis of the plot
9243:
9244: =item $ylabel: string, text describing the Y-axis of the plot
9245:
9246: =item $Max: scalar, the maximum Y value to use in the plot
9247: If $Max is < any data point, the graph will not be rendered.
9248:
1.140 matthew 9249: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9250: they are plotted. If undefined, default values will be used.
9251:
1.178 matthew 9252: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9253:
1.138 matthew 9254: =item @Values: An array of array references. Each array reference holds data
9255: to be plotted in a stacked bar chart.
9256:
1.239 matthew 9257: =item If the final element of @Values is a hash reference the key/value
9258: pairs will be added to the graph definition.
9259:
1.138 matthew 9260: =back
9261:
9262: Returns:
9263:
9264: An <img> tag which references graph.png and the appropriate identifying
9265: information for the plot.
9266:
1.127 matthew 9267: =cut
9268:
9269: ############################################################
9270: ############################################################
1.134 matthew 9271: sub DrawBarGraph {
1.178 matthew 9272: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9273: #
9274: if (! defined($colors)) {
9275: $colors = ['#33ff00',
9276: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9277: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9278: ];
9279: }
1.228 matthew 9280: my $extra_settings = {};
9281: if (ref($Values[-1]) eq 'HASH') {
9282: $extra_settings = pop(@Values);
9283: }
1.127 matthew 9284: #
1.136 matthew 9285: my $identifier = &get_cgi_id();
9286: my $id = 'cgi.'.$identifier;
1.129 matthew 9287: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9288: return '';
9289: }
1.225 matthew 9290: #
9291: my @Labels;
9292: if (defined($labels)) {
9293: @Labels = @$labels;
9294: } else {
9295: for (my $i=0;$i<@{$Values[0]};$i++) {
9296: push (@Labels,$i+1);
9297: }
9298: }
9299: #
1.129 matthew 9300: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9301: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9302: my %ValuesHash;
9303: my $NumSets=1;
9304: foreach my $array (@Values) {
9305: next if (! ref($array));
1.136 matthew 9306: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9307: join(',',@$array);
1.129 matthew 9308: }
1.127 matthew 9309: #
1.136 matthew 9310: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9311: if ($NumBars < 3) {
9312: $width = 120+$NumBars*32;
1.220 matthew 9313: $xskip = 1;
1.225 matthew 9314: $bar_width = 30;
9315: } elsif ($NumBars < 5) {
9316: $width = 120+$NumBars*20;
9317: $xskip = 1;
9318: $bar_width = 20;
1.220 matthew 9319: } elsif ($NumBars < 10) {
1.136 matthew 9320: $width = 120+$NumBars*15;
9321: $xskip = 1;
9322: $bar_width = 15;
9323: } elsif ($NumBars <= 25) {
9324: $width = 120+$NumBars*11;
9325: $xskip = 5;
9326: $bar_width = 8;
9327: } elsif ($NumBars <= 50) {
9328: $width = 120+$NumBars*8;
9329: $xskip = 5;
9330: $bar_width = 4;
9331: } else {
9332: $width = 120+$NumBars*8;
9333: $xskip = 5;
9334: $bar_width = 4;
9335: }
9336: #
1.137 matthew 9337: $Max = 1 if ($Max < 1);
9338: if ( int($Max) < $Max ) {
9339: $Max++;
9340: $Max = int($Max);
9341: }
1.127 matthew 9342: $Title = '' if (! defined($Title));
9343: $xlabel = '' if (! defined($xlabel));
9344: $ylabel = '' if (! defined($ylabel));
1.369 www 9345: $ValuesHash{$id.'.title'} = &escape($Title);
9346: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9347: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9348: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9349: $ValuesHash{$id.'.NumBars'} = $NumBars;
9350: $ValuesHash{$id.'.NumSets'} = $NumSets;
9351: $ValuesHash{$id.'.PlotType'} = 'bar';
9352: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9353: $ValuesHash{$id.'.height'} = $height;
9354: $ValuesHash{$id.'.width'} = $width;
9355: $ValuesHash{$id.'.xskip'} = $xskip;
9356: $ValuesHash{$id.'.bar_width'} = $bar_width;
9357: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9358: #
1.228 matthew 9359: # Deal with other parameters
9360: while (my ($key,$value) = each(%$extra_settings)) {
9361: $ValuesHash{$id.'.'.$key} = $value;
9362: }
9363: #
1.646 raeburn 9364: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9365: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9366: }
9367:
9368: ############################################################
9369: ############################################################
9370:
9371: =pod
9372:
1.648 raeburn 9373: =item * &DrawXYGraph()
1.137 matthew 9374:
1.138 matthew 9375: Facilitates the plotting of data in an XY graph.
9376: Puts plot definition data into the users environment in order for
9377: graph.png to plot it. Returns an <img> tag for the plot.
9378:
9379: Inputs:
9380:
9381: =over 4
9382:
9383: =item $Title: string, the title of the plot
9384:
9385: =item $xlabel: string, text describing the X-axis of the plot
9386:
9387: =item $ylabel: string, text describing the Y-axis of the plot
9388:
9389: =item $Max: scalar, the maximum Y value to use in the plot
9390: If $Max is < any data point, the graph will not be rendered.
9391:
9392: =item $colors: Array ref containing the hex color codes for the data to be
9393: plotted in. If undefined, default values will be used.
9394:
9395: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9396:
9397: =item $Ydata: Array ref containing Array refs.
1.185 www 9398: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9399:
9400: =item %Values: hash indicating or overriding any default values which are
9401: passed to graph.png.
9402: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9403:
9404: =back
9405:
9406: Returns:
9407:
9408: An <img> tag which references graph.png and the appropriate identifying
9409: information for the plot.
9410:
1.137 matthew 9411: =cut
9412:
9413: ############################################################
9414: ############################################################
9415: sub DrawXYGraph {
9416: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9417: #
9418: # Create the identifier for the graph
9419: my $identifier = &get_cgi_id();
9420: my $id = 'cgi.'.$identifier;
9421: #
9422: $Title = '' if (! defined($Title));
9423: $xlabel = '' if (! defined($xlabel));
9424: $ylabel = '' if (! defined($ylabel));
9425: my %ValuesHash =
9426: (
1.369 www 9427: $id.'.title' => &escape($Title),
9428: $id.'.xlabel' => &escape($xlabel),
9429: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9430: $id.'.y_max_value'=> $Max,
9431: $id.'.labels' => join(',',@$Xlabels),
9432: $id.'.PlotType' => 'XY',
9433: );
9434: #
9435: if (defined($colors) && ref($colors) eq 'ARRAY') {
9436: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9437: }
9438: #
9439: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9440: return '';
9441: }
9442: my $NumSets=1;
1.138 matthew 9443: foreach my $array (@{$Ydata}){
1.137 matthew 9444: next if (! ref($array));
9445: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9446: }
1.138 matthew 9447: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9448: #
9449: # Deal with other parameters
9450: while (my ($key,$value) = each(%Values)) {
9451: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9452: }
9453: #
1.646 raeburn 9454: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9455: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9456: }
9457:
9458: ############################################################
9459: ############################################################
9460:
9461: =pod
9462:
1.648 raeburn 9463: =item * &DrawXYYGraph()
1.138 matthew 9464:
9465: Facilitates the plotting of data in an XY graph with two Y axes.
9466: Puts plot definition data into the users environment in order for
9467: graph.png to plot it. Returns an <img> tag for the plot.
9468:
9469: Inputs:
9470:
9471: =over 4
9472:
9473: =item $Title: string, the title of the plot
9474:
9475: =item $xlabel: string, text describing the X-axis of the plot
9476:
9477: =item $ylabel: string, text describing the Y-axis of the plot
9478:
9479: =item $colors: Array ref containing the hex color codes for the data to be
9480: plotted in. If undefined, default values will be used.
9481:
9482: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9483:
9484: =item $Ydata1: The first data set
9485:
9486: =item $Min1: The minimum value of the left Y-axis
9487:
9488: =item $Max1: The maximum value of the left Y-axis
9489:
9490: =item $Ydata2: The second data set
9491:
9492: =item $Min2: The minimum value of the right Y-axis
9493:
9494: =item $Max2: The maximum value of the left Y-axis
9495:
9496: =item %Values: hash indicating or overriding any default values which are
9497: passed to graph.png.
9498: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9499:
9500: =back
9501:
9502: Returns:
9503:
9504: An <img> tag which references graph.png and the appropriate identifying
9505: information for the plot.
1.136 matthew 9506:
9507: =cut
9508:
9509: ############################################################
9510: ############################################################
1.137 matthew 9511: sub DrawXYYGraph {
9512: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9513: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9514: #
9515: # Create the identifier for the graph
9516: my $identifier = &get_cgi_id();
9517: my $id = 'cgi.'.$identifier;
9518: #
9519: $Title = '' if (! defined($Title));
9520: $xlabel = '' if (! defined($xlabel));
9521: $ylabel = '' if (! defined($ylabel));
9522: my %ValuesHash =
9523: (
1.369 www 9524: $id.'.title' => &escape($Title),
9525: $id.'.xlabel' => &escape($xlabel),
9526: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9527: $id.'.labels' => join(',',@$Xlabels),
9528: $id.'.PlotType' => 'XY',
9529: $id.'.NumSets' => 2,
1.137 matthew 9530: $id.'.two_axes' => 1,
9531: $id.'.y1_max_value' => $Max1,
9532: $id.'.y1_min_value' => $Min1,
9533: $id.'.y2_max_value' => $Max2,
9534: $id.'.y2_min_value' => $Min2,
1.136 matthew 9535: );
9536: #
1.137 matthew 9537: if (defined($colors) && ref($colors) eq 'ARRAY') {
9538: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9539: }
9540: #
9541: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9542: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9543: return '';
9544: }
9545: my $NumSets=1;
1.137 matthew 9546: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9547: next if (! ref($array));
9548: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9549: }
9550: #
9551: # Deal with other parameters
9552: while (my ($key,$value) = each(%Values)) {
9553: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9554: }
9555: #
1.646 raeburn 9556: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9557: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9558: }
9559:
9560: ############################################################
9561: ############################################################
9562:
9563: =pod
9564:
1.157 matthew 9565: =back
9566:
1.139 matthew 9567: =head1 Statistics helper routines?
9568:
9569: Bad place for them but what the hell.
9570:
1.157 matthew 9571: =over 4
9572:
1.648 raeburn 9573: =item * &chartlink()
1.139 matthew 9574:
9575: Returns a link to the chart for a specific student.
9576:
9577: Inputs:
9578:
9579: =over 4
9580:
9581: =item $linktext: The text of the link
9582:
9583: =item $sname: The students username
9584:
9585: =item $sdomain: The students domain
9586:
9587: =back
9588:
1.157 matthew 9589: =back
9590:
1.139 matthew 9591: =cut
9592:
9593: ############################################################
9594: ############################################################
9595: sub chartlink {
9596: my ($linktext, $sname, $sdomain) = @_;
9597: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9598: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9599: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9600: '">'.$linktext.'</a>';
1.153 matthew 9601: }
9602:
9603: #######################################################
9604: #######################################################
9605:
9606: =pod
9607:
9608: =head1 Course Environment Routines
1.157 matthew 9609:
9610: =over 4
1.153 matthew 9611:
1.648 raeburn 9612: =item * &restore_course_settings()
1.153 matthew 9613:
1.648 raeburn 9614: =item * &store_course_settings()
1.153 matthew 9615:
9616: Restores/Store indicated form parameters from the course environment.
9617: Will not overwrite existing values of the form parameters.
9618:
9619: Inputs:
9620: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9621:
9622: a hash ref describing the data to be stored. For example:
9623:
9624: %Save_Parameters = ('Status' => 'scalar',
9625: 'chartoutputmode' => 'scalar',
9626: 'chartoutputdata' => 'scalar',
9627: 'Section' => 'array',
1.373 raeburn 9628: 'Group' => 'array',
1.153 matthew 9629: 'StudentData' => 'array',
9630: 'Maps' => 'array');
9631:
9632: Returns: both routines return nothing
9633:
1.631 raeburn 9634: =back
9635:
1.153 matthew 9636: =cut
9637:
9638: #######################################################
9639: #######################################################
9640: sub store_course_settings {
1.496 albertel 9641: return &store_settings($env{'request.course.id'},@_);
9642: }
9643:
9644: sub store_settings {
1.153 matthew 9645: # save to the environment
9646: # appenv the same items, just to be safe
1.300 albertel 9647: my $udom = $env{'user.domain'};
9648: my $uname = $env{'user.name'};
1.496 albertel 9649: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9650: my %SaveHash;
9651: my %AppHash;
9652: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9653: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9654: my $envname = 'environment.'.$basename;
1.258 albertel 9655: if (exists($env{'form.'.$setting})) {
1.153 matthew 9656: # Save this value away
9657: if ($type eq 'scalar' &&
1.258 albertel 9658: (! exists($env{$envname}) ||
9659: $env{$envname} ne $env{'form.'.$setting})) {
9660: $SaveHash{$basename} = $env{'form.'.$setting};
9661: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9662: } elsif ($type eq 'array') {
9663: my $stored_form;
1.258 albertel 9664: if (ref($env{'form.'.$setting})) {
1.153 matthew 9665: $stored_form = join(',',
9666: map {
1.369 www 9667: &escape($_);
1.258 albertel 9668: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9669: } else {
9670: $stored_form =
1.369 www 9671: &escape($env{'form.'.$setting});
1.153 matthew 9672: }
9673: # Determine if the array contents are the same.
1.258 albertel 9674: if ($stored_form ne $env{$envname}) {
1.153 matthew 9675: $SaveHash{$basename} = $stored_form;
9676: $AppHash{$envname} = $stored_form;
9677: }
9678: }
9679: }
9680: }
9681: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9682: $udom,$uname);
1.153 matthew 9683: if ($put_result !~ /^(ok|delayed)/) {
9684: &Apache::lonnet::logthis('unable to save form parameters, '.
9685: 'got error:'.$put_result);
9686: }
9687: # Make sure these settings stick around in this session, too
1.646 raeburn 9688: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9689: return;
9690: }
9691:
9692: sub restore_course_settings {
1.499 albertel 9693: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9694: }
9695:
9696: sub restore_settings {
9697: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9698: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9699: next if (exists($env{'form.'.$setting}));
1.496 albertel 9700: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9701: '.'.$setting;
1.258 albertel 9702: if (exists($env{$envname})) {
1.153 matthew 9703: if ($type eq 'scalar') {
1.258 albertel 9704: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9705: } elsif ($type eq 'array') {
1.258 albertel 9706: $env{'form.'.$setting} = [
1.153 matthew 9707: map {
1.369 www 9708: &unescape($_);
1.258 albertel 9709: } split(',',$env{$envname})
1.153 matthew 9710: ];
9711: }
9712: }
9713: }
1.127 matthew 9714: }
9715:
1.618 raeburn 9716: #######################################################
9717: #######################################################
9718:
9719: =pod
9720:
9721: =head1 Domain E-mail Routines
9722:
9723: =over 4
9724:
1.648 raeburn 9725: =item * &build_recipient_list()
1.618 raeburn 9726:
1.884 raeburn 9727: Build recipient lists for five types of e-mail:
1.766 raeburn 9728: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9729: (d) Help requests, (e) Course requests needing approval, generated by
9730: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9731: loncoursequeueadmin.pm respectively.
1.618 raeburn 9732:
9733: Inputs:
1.619 raeburn 9734: defmail (scalar - email address of default recipient),
1.618 raeburn 9735: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9736: defdom (domain for which to retrieve configuration settings),
9737: origmail (scalar - email address of recipient from loncapa.conf,
9738: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9739:
1.655 raeburn 9740: Returns: comma separated list of addresses to which to send e-mail.
9741:
9742: =back
1.618 raeburn 9743:
9744: =cut
9745:
9746: ############################################################
9747: ############################################################
9748: sub build_recipient_list {
1.619 raeburn 9749: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9750: my @recipients;
9751: my $otheremails;
9752: my %domconfig =
9753: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9754: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9755: if (exists($domconfig{'contacts'}{$mailing})) {
9756: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9757: my @contacts = ('adminemail','supportemail');
9758: foreach my $item (@contacts) {
9759: if ($domconfig{'contacts'}{$mailing}{$item}) {
9760: my $addr = $domconfig{'contacts'}{$item};
9761: if (!grep(/^\Q$addr\E$/,@recipients)) {
9762: push(@recipients,$addr);
9763: }
1.619 raeburn 9764: }
1.766 raeburn 9765: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9766: }
9767: }
1.766 raeburn 9768: } elsif ($origmail ne '') {
9769: push(@recipients,$origmail);
1.618 raeburn 9770: }
1.619 raeburn 9771: } elsif ($origmail ne '') {
9772: push(@recipients,$origmail);
1.618 raeburn 9773: }
1.688 raeburn 9774: if (defined($defmail)) {
9775: if ($defmail ne '') {
9776: push(@recipients,$defmail);
9777: }
1.618 raeburn 9778: }
9779: if ($otheremails) {
1.619 raeburn 9780: my @others;
9781: if ($otheremails =~ /,/) {
9782: @others = split(/,/,$otheremails);
1.618 raeburn 9783: } else {
1.619 raeburn 9784: push(@others,$otheremails);
9785: }
9786: foreach my $addr (@others) {
9787: if (!grep(/^\Q$addr\E$/,@recipients)) {
9788: push(@recipients,$addr);
9789: }
1.618 raeburn 9790: }
9791: }
1.619 raeburn 9792: my $recipientlist = join(',',@recipients);
1.618 raeburn 9793: return $recipientlist;
9794: }
9795:
1.127 matthew 9796: ############################################################
9797: ############################################################
1.154 albertel 9798:
1.655 raeburn 9799: =pod
9800:
9801: =head1 Course Catalog Routines
9802:
9803: =over 4
9804:
9805: =item * &gather_categories()
9806:
9807: Converts category definitions - keys of categories hash stored in
9808: coursecategories in configuration.db on the primary library server in a
9809: domain - to an array. Also generates javascript and idx hash used to
9810: generate Domain Coordinator interface for editing Course Categories.
9811:
9812: Inputs:
1.663 raeburn 9813:
1.655 raeburn 9814: categories (reference to hash of category definitions).
1.663 raeburn 9815:
1.655 raeburn 9816: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9817: categories and subcategories).
1.663 raeburn 9818:
1.655 raeburn 9819: idx (reference to hash of counters used in Domain Coordinator interface for
9820: editing Course Categories).
1.663 raeburn 9821:
1.655 raeburn 9822: jsarray (reference to array of categories used to create Javascript arrays for
9823: Domain Coordinator interface for editing Course Categories).
9824:
9825: Returns: nothing
9826:
9827: Side effects: populates cats, idx and jsarray.
9828:
9829: =cut
9830:
9831: sub gather_categories {
9832: my ($categories,$cats,$idx,$jsarray) = @_;
9833: my %counters;
9834: my $num = 0;
9835: foreach my $item (keys(%{$categories})) {
9836: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9837: if ($container eq '' && $depth == 0) {
9838: $cats->[$depth][$categories->{$item}] = $cat;
9839: } else {
9840: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9841: }
9842: my ($escitem,$tail) = split(/:/,$item,2);
9843: if ($counters{$tail} eq '') {
9844: $counters{$tail} = $num;
9845: $num ++;
9846: }
9847: if (ref($idx) eq 'HASH') {
9848: $idx->{$item} = $counters{$tail};
9849: }
9850: if (ref($jsarray) eq 'ARRAY') {
9851: push(@{$jsarray->[$counters{$tail}]},$item);
9852: }
9853: }
9854: return;
9855: }
9856:
9857: =pod
9858:
9859: =item * &extract_categories()
9860:
9861: Used to generate breadcrumb trails for course categories.
9862:
9863: Inputs:
1.663 raeburn 9864:
1.655 raeburn 9865: categories (reference to hash of category definitions).
1.663 raeburn 9866:
1.655 raeburn 9867: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9868: categories and subcategories).
1.663 raeburn 9869:
1.655 raeburn 9870: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9871:
1.655 raeburn 9872: allitems (reference to hash - key is category key
9873: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9874:
1.655 raeburn 9875: idx (reference to hash of counters used in Domain Coordinator interface for
9876: editing Course Categories).
1.663 raeburn 9877:
1.655 raeburn 9878: jsarray (reference to array of categories used to create Javascript arrays for
9879: Domain Coordinator interface for editing Course Categories).
9880:
1.665 raeburn 9881: subcats (reference to hash of arrays containing all subcategories within each
9882: category, -recursive)
9883:
1.655 raeburn 9884: Returns: nothing
9885:
9886: Side effects: populates trails and allitems hash references.
9887:
9888: =cut
9889:
9890: sub extract_categories {
1.665 raeburn 9891: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9892: if (ref($categories) eq 'HASH') {
9893: &gather_categories($categories,$cats,$idx,$jsarray);
9894: if (ref($cats->[0]) eq 'ARRAY') {
9895: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9896: my $name = $cats->[0][$i];
9897: my $item = &escape($name).'::0';
9898: my $trailstr;
9899: if ($name eq 'instcode') {
9900: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 9901: } elsif ($name eq 'communities') {
9902: $trailstr = &mt('Communities');
1.655 raeburn 9903: } else {
9904: $trailstr = $name;
9905: }
9906: if ($allitems->{$item} eq '') {
9907: push(@{$trails},$trailstr);
9908: $allitems->{$item} = scalar(@{$trails})-1;
9909: }
9910: my @parents = ($name);
9911: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9912: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9913: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9914: if (ref($subcats) eq 'HASH') {
9915: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9916: }
9917: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9918: }
9919: } else {
9920: if (ref($subcats) eq 'HASH') {
9921: $subcats->{$item} = [];
1.655 raeburn 9922: }
9923: }
9924: }
9925: }
9926: }
9927: return;
9928: }
9929:
9930: =pod
9931:
9932: =item *&recurse_categories()
9933:
9934: Recursively used to generate breadcrumb trails for course categories.
9935:
9936: Inputs:
1.663 raeburn 9937:
1.655 raeburn 9938: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9939: categories and subcategories).
1.663 raeburn 9940:
1.655 raeburn 9941: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9942:
9943: category (current course category, for which breadcrumb trail is being generated).
9944:
9945: trails (reference to array of breadcrumb trails for each category).
9946:
1.655 raeburn 9947: allitems (reference to hash - key is category key
9948: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9949:
1.655 raeburn 9950: parents (array containing containers directories for current category,
9951: back to top level).
9952:
9953: Returns: nothing
9954:
9955: Side effects: populates trails and allitems hash references
9956:
9957: =cut
9958:
9959: sub recurse_categories {
1.665 raeburn 9960: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9961: my $shallower = $depth - 1;
9962: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9963: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9964: my $name = $cats->[$depth]{$category}[$k];
9965: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9966: my $trailstr = join(' -> ',(@{$parents},$category));
9967: if ($allitems->{$item} eq '') {
9968: push(@{$trails},$trailstr);
9969: $allitems->{$item} = scalar(@{$trails})-1;
9970: }
9971: my $deeper = $depth+1;
9972: push(@{$parents},$category);
1.665 raeburn 9973: if (ref($subcats) eq 'HASH') {
9974: my $subcat = &escape($name).':'.$category.':'.$depth;
9975: for (my $j=@{$parents}; $j>=0; $j--) {
9976: my $higher;
9977: if ($j > 0) {
9978: $higher = &escape($parents->[$j]).':'.
9979: &escape($parents->[$j-1]).':'.$j;
9980: } else {
9981: $higher = &escape($parents->[$j]).'::'.$j;
9982: }
9983: push(@{$subcats->{$higher}},$subcat);
9984: }
9985: }
9986: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9987: $subcats);
1.655 raeburn 9988: pop(@{$parents});
9989: }
9990: } else {
9991: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9992: my $trailstr = join(' -> ',(@{$parents},$category));
9993: if ($allitems->{$item} eq '') {
9994: push(@{$trails},$trailstr);
9995: $allitems->{$item} = scalar(@{$trails})-1;
9996: }
9997: }
9998: return;
9999: }
10000:
1.663 raeburn 10001: =pod
10002:
10003: =item *&assign_categories_table()
10004:
10005: Create a datatable for display of hierarchical categories in a domain,
10006: with checkboxes to allow a course to be categorized.
10007:
10008: Inputs:
10009:
10010: cathash - reference to hash of categories defined for the domain (from
10011: configuration.db)
10012:
10013: currcat - scalar with an & separated list of categories assigned to a course.
10014:
1.919 raeburn 10015: type - scalar contains course type (Course or Community).
10016:
1.663 raeburn 10017: Returns: $output (markup to be displayed)
10018:
10019: =cut
10020:
10021: sub assign_categories_table {
1.919 raeburn 10022: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 10023: my $output;
10024: if (ref($cathash) eq 'HASH') {
10025: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
10026: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
10027: $maxdepth = scalar(@cats);
10028: if (@cats > 0) {
10029: my $itemcount = 0;
10030: if (ref($cats[0]) eq 'ARRAY') {
10031: my @currcategories;
10032: if ($currcat ne '') {
10033: @currcategories = split('&',$currcat);
10034: }
1.919 raeburn 10035: my $table;
1.663 raeburn 10036: for (my $i=0; $i<@{$cats[0]}; $i++) {
10037: my $parent = $cats[0][$i];
1.919 raeburn 10038: next if ($parent eq 'instcode');
10039: if ($type eq 'Community') {
10040: next unless ($parent eq 'communities');
10041: } else {
10042: next if ($parent eq 'communities');
10043: }
1.663 raeburn 10044: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10045: my $item = &escape($parent).'::0';
10046: my $checked = '';
10047: if (@currcategories > 0) {
10048: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 10049: $checked = ' checked="checked"';
1.663 raeburn 10050: }
10051: }
1.919 raeburn 10052: my $parent_title = $parent;
10053: if ($parent eq 'communities') {
10054: $parent_title = &mt('Communities');
10055: }
10056: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
10057: '<input type="checkbox" name="usecategory" value="'.
10058: $item.'"'.$checked.' />'.$parent_title.'</span>'.
10059: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 10060: my $depth = 1;
10061: push(@path,$parent);
1.919 raeburn 10062: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 10063: pop(@path);
1.919 raeburn 10064: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 10065: $itemcount ++;
10066: }
1.919 raeburn 10067: if ($itemcount) {
10068: $output = &Apache::loncommon::start_data_table().
10069: $table.
10070: &Apache::loncommon::end_data_table();
10071: }
1.663 raeburn 10072: }
10073: }
10074: }
10075: return $output;
10076: }
10077:
10078: =pod
10079:
10080: =item *&assign_category_rows()
10081:
10082: Create a datatable row for display of nested categories in a domain,
10083: with checkboxes to allow a course to be categorized,called recursively.
10084:
10085: Inputs:
10086:
10087: itemcount - track row number for alternating colors
10088:
10089: cats - reference to array of arrays/hashes which encapsulates hierarchy of
10090: categories and subcategories.
10091:
10092: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
10093:
10094: parent - parent of current category item
10095:
10096: path - Array containing all categories back up through the hierarchy from the
10097: current category to the top level.
10098:
10099: currcategories - reference to array of current categories assigned to the course
10100:
10101: Returns: $output (markup to be displayed).
10102:
10103: =cut
10104:
10105: sub assign_category_rows {
10106: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
10107: my ($text,$name,$item,$chgstr);
10108: if (ref($cats) eq 'ARRAY') {
10109: my $maxdepth = scalar(@{$cats});
10110: if (ref($cats->[$depth]) eq 'HASH') {
10111: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10112: my $numchildren = @{$cats->[$depth]{$parent}};
10113: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
10114: $text .= '<td><table class="LC_datatable">';
10115: for (my $j=0; $j<$numchildren; $j++) {
10116: $name = $cats->[$depth]{$parent}[$j];
10117: $item = &escape($name).':'.&escape($parent).':'.$depth;
10118: my $deeper = $depth+1;
10119: my $checked = '';
10120: if (ref($currcategories) eq 'ARRAY') {
10121: if (@{$currcategories} > 0) {
10122: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 10123: $checked = ' checked="checked"';
1.663 raeburn 10124: }
10125: }
10126: }
1.664 raeburn 10127: $text .= '<tr><td><span class="LC_nobreak"><label>'.
10128: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 10129: $item.'"'.$checked.' />'.$name.'</label></span>'.
10130: '<input type="hidden" name="catname" value="'.$name.'" />'.
10131: '</td><td>';
1.663 raeburn 10132: if (ref($path) eq 'ARRAY') {
10133: push(@{$path},$name);
10134: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
10135: pop(@{$path});
10136: }
10137: $text .= '</td></tr>';
10138: }
10139: $text .= '</table></td>';
10140: }
10141: }
10142: }
10143: return $text;
10144: }
10145:
1.655 raeburn 10146: ############################################################
10147: ############################################################
10148:
10149:
1.443 albertel 10150: sub commit_customrole {
1.664 raeburn 10151: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 10152: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 10153: ($start?', '.&mt('starting').' '.localtime($start):'').
10154: ($end?', ending '.localtime($end):'').': <b>'.
10155: &Apache::lonnet::assigncustomrole(
1.664 raeburn 10156: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 10157: '</b><br />';
10158: return $output;
10159: }
10160:
10161: sub commit_standardrole {
1.541 raeburn 10162: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
10163: my ($output,$logmsg,$linefeed);
10164: if ($context eq 'auto') {
10165: $linefeed = "\n";
10166: } else {
10167: $linefeed = "<br />\n";
10168: }
1.443 albertel 10169: if ($three eq 'st') {
1.541 raeburn 10170: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10171: $one,$two,$sec,$context);
10172: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10173: ($result eq 'unknown_course') || ($result eq 'refused')) {
10174: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10175: } else {
1.541 raeburn 10176: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10177: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10178: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10179: if ($context eq 'auto') {
10180: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10181: } else {
10182: $output .= '<b>'.$result.'</b>'.$linefeed.
10183: &mt('Add to classlist').': <b>ok</b>';
10184: }
10185: $output .= $linefeed;
1.443 albertel 10186: }
10187: } else {
10188: $output = &mt('Assigning').' '.$three.' in '.$url.
10189: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10190: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10191: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10192: if ($context eq 'auto') {
10193: $output .= $result.$linefeed;
10194: } else {
10195: $output .= '<b>'.$result.'</b>'.$linefeed;
10196: }
1.443 albertel 10197: }
10198: return $output;
10199: }
10200:
10201: sub commit_studentrole {
1.541 raeburn 10202: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10203: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10204: if ($context eq 'auto') {
10205: $linefeed = "\n";
10206: } else {
10207: $linefeed = '<br />'."\n";
10208: }
1.443 albertel 10209: if (defined($one) && defined($two)) {
10210: my $cid=$one.'_'.$two;
10211: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10212: my $secchange = 0;
10213: my $expire_role_result;
10214: my $modify_section_result;
1.628 raeburn 10215: if ($oldsec ne '-1') {
10216: if ($oldsec ne $sec) {
1.443 albertel 10217: $secchange = 1;
1.628 raeburn 10218: my $now = time;
1.443 albertel 10219: my $uurl='/'.$cid;
10220: $uurl=~s/\_/\//g;
10221: if ($oldsec) {
10222: $uurl.='/'.$oldsec;
10223: }
1.626 raeburn 10224: $oldsecurl = $uurl;
1.628 raeburn 10225: $expire_role_result =
1.652 raeburn 10226: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10227: if ($env{'request.course.sec'} ne '') {
10228: if ($expire_role_result eq 'refused') {
10229: my @roles = ('st');
10230: my @statuses = ('previous');
10231: my @roledoms = ($one);
10232: my $withsec = 1;
10233: my %roleshash =
10234: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10235: \@statuses,\@roles,\@roledoms,$withsec);
10236: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10237: my ($oldstart,$oldend) =
10238: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10239: if ($oldend > 0 && $oldend <= $now) {
10240: $expire_role_result = 'ok';
10241: }
10242: }
10243: }
10244: }
1.443 albertel 10245: $result = $expire_role_result;
10246: }
10247: }
10248: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10249: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10250: if ($modify_section_result =~ /^ok/) {
10251: if ($secchange == 1) {
1.628 raeburn 10252: if ($sec eq '') {
10253: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10254: } else {
10255: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10256: }
1.443 albertel 10257: } elsif ($oldsec eq '-1') {
1.628 raeburn 10258: if ($sec eq '') {
10259: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10260: } else {
10261: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10262: }
1.443 albertel 10263: } else {
1.628 raeburn 10264: if ($sec eq '') {
10265: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10266: } else {
10267: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10268: }
1.443 albertel 10269: }
10270: } else {
1.628 raeburn 10271: if ($secchange) {
10272: $$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;
10273: } else {
10274: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10275: }
1.443 albertel 10276: }
10277: $result = $modify_section_result;
10278: } elsif ($secchange == 1) {
1.628 raeburn 10279: if ($oldsec eq '') {
10280: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10281: } else {
10282: $$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;
10283: }
1.626 raeburn 10284: if ($expire_role_result eq 'refused') {
10285: my $newsecurl = '/'.$cid;
10286: $newsecurl =~ s/\_/\//g;
10287: if ($sec ne '') {
10288: $newsecurl.='/'.$sec;
10289: }
10290: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10291: if ($sec eq '') {
10292: $$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;
10293: } else {
10294: $$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;
10295: }
10296: }
10297: }
1.443 albertel 10298: }
10299: } else {
1.626 raeburn 10300: $$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 10301: $result = "error: incomplete course id\n";
10302: }
10303: return $result;
10304: }
10305:
10306: ############################################################
10307: ############################################################
10308:
1.566 albertel 10309: sub check_clone {
1.578 raeburn 10310: my ($args,$linefeed) = @_;
1.566 albertel 10311: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10312: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10313: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10314: my $clonemsg;
10315: my $can_clone = 0;
1.944 raeburn 10316: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10317: if ($lctype ne 'community') {
10318: $lctype = 'course';
10319: }
1.566 albertel 10320: if ($clonehome eq 'no_host') {
1.944 raeburn 10321: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10322: $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'});
10323: } else {
10324: $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'});
10325: }
1.566 albertel 10326: } else {
10327: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10328: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10329: if ($clonedesc{'type'} ne 'Community') {
10330: $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'});
10331: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10332: }
10333: }
1.882 raeburn 10334: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10335: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10336: $can_clone = 1;
10337: } else {
10338: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10339: $args->{'clonedomain'},$args->{'clonecourse'});
10340: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10341: if (grep(/^\*$/,@cloners)) {
10342: $can_clone = 1;
10343: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10344: $can_clone = 1;
10345: } else {
1.908 raeburn 10346: my $ccrole = 'cc';
1.944 raeburn 10347: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10348: $ccrole = 'co';
10349: }
1.578 raeburn 10350: my %roleshash =
10351: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10352: $args->{'ccdomain'},
1.908 raeburn 10353: 'userroles',['active'],[$ccrole],
1.578 raeburn 10354: [$args->{'clonedomain'}]);
1.908 raeburn 10355: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10356: $can_clone = 1;
10357: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10358: $can_clone = 1;
10359: } else {
1.944 raeburn 10360: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10361: $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'});
10362: } else {
10363: $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'});
10364: }
1.578 raeburn 10365: }
1.566 albertel 10366: }
1.578 raeburn 10367: }
1.566 albertel 10368: }
10369: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10370: }
10371:
1.444 albertel 10372: sub construct_course {
1.885 raeburn 10373: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10374: my $outcome;
1.541 raeburn 10375: my $linefeed = '<br />'."\n";
10376: if ($context eq 'auto') {
10377: $linefeed = "\n";
10378: }
1.566 albertel 10379:
10380: #
10381: # Are we cloning?
10382: #
10383: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10384: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10385: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10386: if ($context ne 'auto') {
1.578 raeburn 10387: if ($clonemsg ne '') {
10388: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10389: }
1.566 albertel 10390: }
10391: $outcome .= $clonemsg.$linefeed;
10392:
10393: if (!$can_clone) {
10394: return (0,$outcome);
10395: }
10396: }
10397:
1.444 albertel 10398: #
10399: # Open course
10400: #
10401: my $crstype = lc($args->{'crstype'});
10402: my %cenv=();
10403: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10404: $args->{'cdescr'},
10405: $args->{'curl'},
10406: $args->{'course_home'},
10407: $args->{'nonstandard'},
10408: $args->{'crscode'},
10409: $args->{'ccuname'}.':'.
10410: $args->{'ccdomain'},
1.882 raeburn 10411: $args->{'crstype'},
1.885 raeburn 10412: $cnum,$context,$category);
1.444 albertel 10413:
10414: # Note: The testing routines depend on this being output; see
10415: # Utils::Course. This needs to at least be output as a comment
10416: # if anyone ever decides to not show this, and Utils::Course::new
10417: # will need to be suitably modified.
1.541 raeburn 10418: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10419: if ($$courseid =~ /^error:/) {
10420: return (0,$outcome);
10421: }
10422:
1.444 albertel 10423: #
10424: # Check if created correctly
10425: #
1.479 albertel 10426: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10427: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10428: if ($crsuhome eq 'no_host') {
10429: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10430: return (0,$outcome);
10431: }
1.541 raeburn 10432: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10433:
1.444 albertel 10434: #
1.566 albertel 10435: # Do the cloning
10436: #
10437: if ($can_clone && $cloneid) {
10438: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10439: if ($context ne 'auto') {
10440: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10441: }
10442: $outcome .= $clonemsg.$linefeed;
10443: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10444: # Copy all files
1.637 www 10445: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10446: # Restore URL
1.566 albertel 10447: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10448: # Restore title
1.566 albertel 10449: $cenv{'description'}=$oldcenv{'description'};
1.948.2.2 raeburn 10450: # Restore creation date, creator and creation context.
10451: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10452: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10453: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10454: # Mark as cloned
1.566 albertel 10455: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10456: # Need to clone grading mode
10457: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10458: $cenv{'grading'}=$newenv{'grading'};
10459: # Do not clone these environment entries
10460: &Apache::lonnet::del('environment',
10461: ['default_enrollment_start_date',
10462: 'default_enrollment_end_date',
10463: 'question.email',
10464: 'policy.email',
10465: 'comment.email',
10466: 'pch.users.denied',
1.725 raeburn 10467: 'plc.users.denied',
10468: 'hidefromcat',
10469: 'categories'],
1.638 www 10470: $$crsudom,$$crsunum);
1.444 albertel 10471: }
1.566 albertel 10472:
1.444 albertel 10473: #
10474: # Set environment (will override cloned, if existing)
10475: #
10476: my @sections = ();
10477: my @xlists = ();
10478: if ($args->{'crstype'}) {
10479: $cenv{'type'}=$args->{'crstype'};
10480: }
10481: if ($args->{'crsid'}) {
10482: $cenv{'courseid'}=$args->{'crsid'};
10483: }
10484: if ($args->{'crscode'}) {
10485: $cenv{'internal.coursecode'}=$args->{'crscode'};
10486: }
10487: if ($args->{'crsquota'} ne '') {
10488: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10489: } else {
10490: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10491: }
10492: if ($args->{'ccuname'}) {
10493: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10494: ':'.$args->{'ccdomain'};
10495: } else {
10496: $cenv{'internal.courseowner'} = $args->{'curruser'};
10497: }
10498: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10499: if ($args->{'crssections'}) {
10500: $cenv{'internal.sectionnums'} = '';
10501: if ($args->{'crssections'} =~ m/,/) {
10502: @sections = split/,/,$args->{'crssections'};
10503: } else {
10504: $sections[0] = $args->{'crssections'};
10505: }
10506: if (@sections > 0) {
10507: foreach my $item (@sections) {
10508: my ($sec,$gp) = split/:/,$item;
10509: my $class = $args->{'crscode'}.$sec;
10510: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10511: $cenv{'internal.sectionnums'} .= $item.',';
10512: unless ($addcheck eq 'ok') {
10513: push @badclasses, $class;
10514: }
10515: }
10516: $cenv{'internal.sectionnums'} =~ s/,$//;
10517: }
10518: }
10519: # do not hide course coordinator from staff listing,
10520: # even if privileged
10521: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10522: # add crosslistings
10523: if ($args->{'crsxlist'}) {
10524: $cenv{'internal.crosslistings'}='';
10525: if ($args->{'crsxlist'} =~ m/,/) {
10526: @xlists = split/,/,$args->{'crsxlist'};
10527: } else {
10528: $xlists[0] = $args->{'crsxlist'};
10529: }
10530: if (@xlists > 0) {
10531: foreach my $item (@xlists) {
10532: my ($xl,$gp) = split/:/,$item;
10533: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10534: $cenv{'internal.crosslistings'} .= $item.',';
10535: unless ($addcheck eq 'ok') {
10536: push @badclasses, $xl;
10537: }
10538: }
10539: $cenv{'internal.crosslistings'} =~ s/,$//;
10540: }
10541: }
10542: if ($args->{'autoadds'}) {
10543: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10544: }
10545: if ($args->{'autodrops'}) {
10546: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10547: }
10548: # check for notification of enrollment changes
10549: my @notified = ();
10550: if ($args->{'notify_owner'}) {
10551: if ($args->{'ccuname'} ne '') {
10552: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10553: }
10554: }
10555: if ($args->{'notify_dc'}) {
10556: if ($uname ne '') {
1.630 raeburn 10557: push(@notified,$uname.':'.$udom);
1.444 albertel 10558: }
10559: }
10560: if (@notified > 0) {
10561: my $notifylist;
10562: if (@notified > 1) {
10563: $notifylist = join(',',@notified);
10564: } else {
10565: $notifylist = $notified[0];
10566: }
10567: $cenv{'internal.notifylist'} = $notifylist;
10568: }
10569: if (@badclasses > 0) {
10570: my %lt=&Apache::lonlocal::texthash(
10571: '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',
10572: 'dnhr' => 'does not have rights to access enrollment in these classes',
10573: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10574: );
1.541 raeburn 10575: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10576: ' ('.$lt{'adby'}.')';
10577: if ($context eq 'auto') {
10578: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10579: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10580: foreach my $item (@badclasses) {
10581: if ($context eq 'auto') {
10582: $outcome .= " - $item\n";
10583: } else {
10584: $outcome .= "<li>$item</li>\n";
10585: }
10586: }
10587: if ($context eq 'auto') {
10588: $outcome .= $linefeed;
10589: } else {
1.566 albertel 10590: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10591: }
10592: }
1.444 albertel 10593: }
10594: if ($args->{'no_end_date'}) {
10595: $args->{'endaccess'} = 0;
10596: }
10597: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10598: $cenv{'internal.autoend'}=$args->{'enrollend'};
10599: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10600: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10601: if ($args->{'showphotos'}) {
10602: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10603: }
10604: $cenv{'internal.authtype'} = $args->{'authtype'};
10605: $cenv{'internal.autharg'} = $args->{'autharg'};
10606: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10607: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10608: 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');
10609: if ($context eq 'auto') {
10610: $outcome .= $krb_msg;
10611: } else {
1.566 albertel 10612: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10613: }
10614: $outcome .= $linefeed;
1.444 albertel 10615: }
10616: }
10617: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10618: if ($args->{'setpolicy'}) {
10619: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10620: }
10621: if ($args->{'setcontent'}) {
10622: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10623: }
10624: }
10625: if ($args->{'reshome'}) {
10626: $cenv{'reshome'}=$args->{'reshome'}.'/';
10627: $cenv{'reshome'}=~s/\/+$/\//;
10628: }
10629: #
10630: # course has keyed access
10631: #
10632: if ($args->{'setkeys'}) {
10633: $cenv{'keyaccess'}='yes';
10634: }
10635: # if specified, key authority is not course, but user
10636: # only active if keyaccess is yes
10637: if ($args->{'keyauth'}) {
1.487 albertel 10638: my ($user,$domain) = split(':',$args->{'keyauth'});
10639: $user = &LONCAPA::clean_username($user);
10640: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10641: if ($user ne '' && $domain ne '') {
1.487 albertel 10642: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10643: }
10644: }
10645:
10646: if ($args->{'disresdis'}) {
10647: $cenv{'pch.roles.denied'}='st';
10648: }
10649: if ($args->{'disablechat'}) {
10650: $cenv{'plc.roles.denied'}='st';
10651: }
10652:
10653: # Record we've not yet viewed the Course Initialization Helper for this
10654: # course
10655: $cenv{'course.helper.not.run'} = 1;
10656: #
10657: # Use new Randomseed
10658: #
10659: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10660: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10661: #
10662: # The encryption code and receipt prefix for this course
10663: #
10664: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10665: $cenv{'internal.encpref'}=100+int(9*rand(99));
10666: #
10667: # By default, use standard grading
10668: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10669:
1.541 raeburn 10670: $outcome .= $linefeed.&mt('Setting environment').': '.
10671: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10672: #
10673: # Open all assignments
10674: #
10675: if ($args->{'openall'}) {
10676: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10677: my %storecontent = ($storeunder => time,
10678: $storeunder.'.type' => 'date_start');
10679:
10680: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10681: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10682: }
10683: #
10684: # Set first page
10685: #
10686: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10687: || ($cloneid)) {
1.445 albertel 10688: use LONCAPA::map;
1.444 albertel 10689: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10690:
10691: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10692: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10693:
1.444 albertel 10694: $outcome .= ($fatal?$errtext:'read ok').' - ';
10695: my $title; my $url;
10696: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10697: $title=&mt('Syllabus');
1.444 albertel 10698: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10699: } else {
1.948.2.5 raeburn 10700: $title=&mt('Table of Contents');
1.444 albertel 10701: $url='/adm/navmaps';
10702: }
1.445 albertel 10703:
10704: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10705: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10706:
10707: if ($errtext) { $fatal=2; }
1.541 raeburn 10708: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10709: }
1.566 albertel 10710:
10711: return (1,$outcome);
1.444 albertel 10712: }
10713:
10714: ############################################################
10715: ############################################################
10716:
1.378 raeburn 10717: sub course_type {
10718: my ($cid) = @_;
10719: if (!defined($cid)) {
10720: $cid = $env{'request.course.id'};
10721: }
1.404 albertel 10722: if (defined($env{'course.'.$cid.'.type'})) {
10723: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10724: } else {
10725: return 'Course';
1.377 raeburn 10726: }
10727: }
1.156 albertel 10728:
1.406 raeburn 10729: sub group_term {
10730: my $crstype = &course_type();
10731: my %names = (
10732: 'Course' => 'group',
1.865 raeburn 10733: 'Community' => 'group',
1.406 raeburn 10734: );
10735: return $names{$crstype};
10736: }
10737:
1.902 raeburn 10738: sub course_types {
10739: my @types = ('official','unofficial','community');
10740: my %typename = (
10741: official => 'Official course',
10742: unofficial => 'Unofficial course',
10743: community => 'Community',
10744: );
10745: return (\@types,\%typename);
10746: }
10747:
1.156 albertel 10748: sub icon {
10749: my ($file)=@_;
1.505 albertel 10750: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10751: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10752: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10753: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10754: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10755: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10756: $curfext.".gif") {
10757: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10758: $curfext.".gif";
10759: }
10760: }
1.249 albertel 10761: return &lonhttpdurl($iconname);
1.154 albertel 10762: }
1.84 albertel 10763:
1.575 albertel 10764: sub lonhttpdurl {
1.692 www 10765: #
10766: # Had been used for "small fry" static images on separate port 8080.
10767: # Modify here if lightweight http functionality desired again.
10768: # Currently eliminated due to increasing firewall issues.
10769: #
1.575 albertel 10770: my ($url)=@_;
1.692 www 10771: return $url;
1.215 albertel 10772: }
10773:
1.213 albertel 10774: sub connection_aborted {
10775: my ($r)=@_;
10776: $r->print(" ");$r->rflush();
10777: my $c = $r->connection;
10778: return $c->aborted();
10779: }
10780:
1.221 foxr 10781: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10782: # strings as 'strings'.
10783: sub escape_single {
1.221 foxr 10784: my ($input) = @_;
1.223 albertel 10785: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10786: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10787: return $input;
10788: }
1.223 albertel 10789:
1.222 foxr 10790: # Same as escape_single, but escape's "'s This
10791: # can be used for "strings"
10792: sub escape_double {
10793: my ($input) = @_;
10794: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10795: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10796: return $input;
10797: }
1.223 albertel 10798:
1.222 foxr 10799: # Escapes the last element of a full URL.
10800: sub escape_url {
10801: my ($url) = @_;
1.238 raeburn 10802: my @urlslices = split(/\//, $url,-1);
1.369 www 10803: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10804: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10805: }
1.462 albertel 10806:
1.820 raeburn 10807: sub compare_arrays {
10808: my ($arrayref1,$arrayref2) = @_;
10809: my (@difference,%count);
10810: @difference = ();
10811: %count = ();
10812: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10813: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10814: foreach my $element (keys(%count)) {
10815: if ($count{$element} == 1) {
10816: push(@difference,$element);
10817: }
10818: }
10819: }
10820: return @difference;
10821: }
10822:
1.817 bisitz 10823: # -------------------------------------------------------- Initialize user login
1.462 albertel 10824: sub init_user_environment {
1.463 albertel 10825: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10826: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10827:
10828: my $public=($username eq 'public' && $domain eq 'public');
10829:
10830: # See if old ID present, if so, remove
10831:
10832: my ($filename,$cookie,$userroles);
10833: my $now=time;
10834:
10835: if ($public) {
10836: my $max_public=100;
10837: my $oldest;
10838: my $oldest_time=0;
10839: for(my $next=1;$next<=$max_public;$next++) {
10840: if (-e $lonids."/publicuser_$next.id") {
10841: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10842: if ($mtime<$oldest_time || !$oldest_time) {
10843: $oldest_time=$mtime;
10844: $oldest=$next;
10845: }
10846: } else {
10847: $cookie="publicuser_$next";
10848: last;
10849: }
10850: }
10851: if (!$cookie) { $cookie="publicuser_$oldest"; }
10852: } else {
1.463 albertel 10853: # if this isn't a robot, kill any existing non-robot sessions
10854: if (!$args->{'robot'}) {
10855: opendir(DIR,$lonids);
10856: while ($filename=readdir(DIR)) {
10857: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10858: unlink($lonids.'/'.$filename);
10859: }
1.462 albertel 10860: }
1.463 albertel 10861: closedir(DIR);
1.462 albertel 10862: }
10863: # Give them a new cookie
1.463 albertel 10864: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10865: : $now.$$.int(rand(10000)));
1.463 albertel 10866: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10867:
10868: # Initialize roles
10869:
10870: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10871: }
10872: # ------------------------------------ Check browser type and MathML capability
10873:
10874: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10875: $clientunicode,$clientos) = &decode_user_agent($r);
10876:
10877: # ------------------------------------------------------------- Get environment
10878:
10879: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10880: my ($tmp) = keys(%userenv);
10881: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10882: # default remote control to off
10883: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10884: } else {
10885: undef(%userenv);
10886: }
10887: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10888: $form->{'interface'}=$userenv{'interface'};
10889: }
10890: $env{'environment.remote'}=$userenv{'remote'};
10891: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10892:
10893: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10894: foreach my $option ('interface','localpath','localres') {
10895: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10896: }
10897: # --------------------------------------------------------- Write first profile
10898:
10899: {
10900: my %initial_env =
10901: ("user.name" => $username,
10902: "user.domain" => $domain,
10903: "user.home" => $authhost,
10904: "browser.type" => $clientbrowser,
10905: "browser.version" => $clientversion,
10906: "browser.mathml" => $clientmathml,
10907: "browser.unicode" => $clientunicode,
10908: "browser.os" => $clientos,
10909: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10910: "request.course.fn" => '',
10911: "request.course.uri" => '',
10912: "request.course.sec" => '',
10913: "request.role" => 'cm',
10914: "request.role.adv" => $env{'user.adv'},
10915: "request.host" => $ENV{'REMOTE_ADDR'},);
10916:
10917: if ($form->{'localpath'}) {
10918: $initial_env{"browser.localpath"} = $form->{'localpath'};
10919: $initial_env{"browser.localres"} = $form->{'localres'};
10920: }
10921:
10922: if ($public) {
10923: $initial_env{"environment.remote"} = "off";
10924: }
10925: if ($form->{'interface'}) {
10926: $form->{'interface'}=~s/\W//gs;
10927: $initial_env{"browser.interface"} = $form->{'interface'};
10928: $env{'browser.interface'}=$form->{'interface'};
10929: }
1.948.2.11 raeburn 10930: my %is_adv = ( is_adv => $env{'user.adv'} );
1.948.2.10 raeburn 10931: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.462 albertel 10932:
1.724 raeburn 10933: foreach my $tool ('aboutme','blog','portfolio') {
10934: $userenv{'availabletools.'.$tool} =
1.948.2.10 raeburn 10935: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
10936: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 10937: }
10938:
1.864 raeburn 10939: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10940: $userenv{'canrequest.'.$crstype} =
10941: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.948.2.10 raeburn 10942: 'reload','requestcourses',
10943: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 10944: }
10945:
1.462 albertel 10946: $env{'user.environment'} = "$lonids/$cookie.id";
10947:
10948: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10949: &GDBM_WRCREAT(),0640)) {
10950: &_add_to_env(\%disk_env,\%initial_env);
10951: &_add_to_env(\%disk_env,\%userenv,'environment.');
10952: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10953: if (ref($args->{'extra_env'})) {
10954: &_add_to_env(\%disk_env,$args->{'extra_env'});
10955: }
1.462 albertel 10956: untie(%disk_env);
10957: } else {
1.705 tempelho 10958: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10959: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10960: return 'error: '.$!;
10961: }
10962: }
10963: $env{'request.role'}='cm';
10964: $env{'request.role.adv'}=$env{'user.adv'};
10965: $env{'browser.type'}=$clientbrowser;
10966:
10967: return $cookie;
10968:
10969: }
10970:
10971: sub _add_to_env {
10972: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10973: if (ref($env_data) eq 'HASH') {
10974: while (my ($key,$value) = each(%$env_data)) {
10975: $idf->{$prefix.$key} = $value;
10976: $env{$prefix.$key} = $value;
10977: }
1.462 albertel 10978: }
10979: }
10980:
1.685 tempelho 10981: # --- Get the symbolic name of a problem and the url
10982: sub get_symb {
10983: my ($request,$silent) = @_;
1.726 raeburn 10984: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10985: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10986: if ($symb eq '') {
10987: if (!$silent) {
10988: $request->print("Unable to handle ambiguous references:$url:.");
10989: return ();
10990: }
10991: }
10992: &Apache::lonenc::check_decrypt(\$symb);
10993: return ($symb);
10994: }
10995:
10996: # --------------------------------------------------------------Get annotation
10997:
10998: sub get_annotation {
10999: my ($symb,$enc) = @_;
11000:
11001: my $key = $symb;
11002: if (!$enc) {
11003: $key =
11004: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
11005: }
11006: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
11007: return $annotation{$key};
11008: }
11009:
11010: sub clean_symb {
1.731 raeburn 11011: my ($symb,$delete_enc) = @_;
1.685 tempelho 11012:
11013: &Apache::lonenc::check_decrypt(\$symb);
11014: my $enc = $env{'request.enc'};
1.731 raeburn 11015: if ($delete_enc) {
1.730 raeburn 11016: delete($env{'request.enc'});
11017: }
1.685 tempelho 11018:
11019: return ($symb,$enc);
11020: }
1.462 albertel 11021:
1.41 ng 11022: =pod
11023:
11024: =back
11025:
1.112 bowersj2 11026: =cut
1.41 ng 11027:
1.112 bowersj2 11028: 1;
11029: __END__;
1.41 ng 11030:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>