Annotation of loncom/interface/loncommon.pm, revision 1.978
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.978 ! raeburn 4: # $Id: loncommon.pm,v 1.977 2010/08/16 16:02:08 bisitz Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.909 raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 486: my $wintitle = 'Course_Browser';
1.931 raeburn 487: if ($crstype eq 'Community') {
1.932 raeburn 488: $wintitle = 'Community_Browser';
1.909 raeburn 489: }
1.876 raeburn 490: my $id_functions = &javascript_index_functions();
491: my $output = '
1.776 bisitz 492: <script type="text/javascript" language="JavaScript">
1.824 bisitz 493: // <![CDATA[
1.468 raeburn 494: var stdeditbrowser;'."\n";
1.876 raeburn 495:
496: $output .= <<"ENDSTDBRW";
1.909 raeburn 497: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 498: var url = '/adm/pickcourse?';
1.895 raeburn 499: var formid = getFormIdByName(formname);
1.876 raeburn 500: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 501: if (domainfilter != null) {
502: if (domainfilter != '') {
503: url += 'domainfilter='+domainfilter+'&';
504: }
505: }
1.91 www 506: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 507: '&cdomelement='+udom+
508: '&cnameelement='+desc;
1.468 raeburn 509: if (extra_element !=null && extra_element != '') {
1.594 raeburn 510: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 511: url += '&roleelement='+extra_element;
512: if (domainfilter == null || domainfilter == '') {
513: url += '&domainfilter='+extra_element;
514: }
1.234 raeburn 515: }
1.468 raeburn 516: else {
517: if (formname == 'portform') {
518: url += '&setroles='+extra_element;
1.800 raeburn 519: } else {
520: if (formname == 'rules') {
521: url += '&fixeddom='+extra_element;
522: }
1.468 raeburn 523: }
524: }
1.230 raeburn 525: }
1.909 raeburn 526: if (type != null && type != '') {
527: url += '&type='+type;
528: }
529: if (type_elem != null && type_elem != '') {
530: url += '&typeelement='+type_elem;
531: }
1.872 raeburn 532: if (formname == 'ccrs') {
533: var ownername = document.forms[formid].ccuname.value;
534: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
535: url += '&cloner='+ownername+':'+ownerdom;
536: }
1.293 raeburn 537: if (multflag !=null && multflag != '') {
538: url += '&multiple='+multflag;
539: }
1.909 raeburn 540: var title = '$wintitle';
1.91 www 541: var options = 'scrollbars=1,resizable=1,menubar=0';
542: options += ',width=700,height=600';
543: stdeditbrowser = open(url,title,options,'1');
544: stdeditbrowser.focus();
545: }
1.876 raeburn 546: $id_functions
547: ENDSTDBRW
1.905 raeburn 548: if (($sec_element ne '') || ($role_element ne '')) {
549: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 550: }
551: $output .= '
552: // ]]>
553: </script>';
554: return $output;
555: }
556:
557: sub javascript_index_functions {
558: return <<"ENDJS";
559:
560: function getFormIdByName(formname) {
561: for (var i=0;i<document.forms.length;i++) {
562: if (document.forms[i].name == formname) {
563: return i;
564: }
565: }
566: return -1;
567: }
568:
569: function getIndexByName(formid,item) {
570: for (var i=0;i<document.forms[formid].elements.length;i++) {
571: if (document.forms[formid].elements[i].name == item) {
572: return i;
573: }
574: }
575: return -1;
576: }
1.468 raeburn 577:
1.876 raeburn 578: function getDomainFromSelectbox(formname,udom) {
579: var userdom;
580: var formid = getFormIdByName(formname);
581: if (formid > -1) {
582: var domid = getIndexByName(formid,udom);
583: if (domid > -1) {
584: if (document.forms[formid].elements[domid].type == 'select-one') {
585: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
586: }
587: if (document.forms[formid].elements[domid].type == 'hidden') {
588: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 589: }
590: }
591: }
1.876 raeburn 592: return userdom;
593: }
594:
595: ENDJS
1.468 raeburn 596:
1.876 raeburn 597: }
598:
599: sub userbrowser_javascript {
600: my $id_functions = &javascript_index_functions();
601: return <<"ENDUSERBRW";
602:
1.888 raeburn 603: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 604: var url = '/adm/pickuser?';
605: var userdom = getDomainFromSelectbox(formname,udom);
606: if (userdom != null) {
607: if (userdom != '') {
608: url += 'srchdom='+userdom+'&';
609: }
610: }
611: url += 'form=' + formname + '&unameelement='+uname+
612: '&udomelement='+udom+
613: '&ulastelement='+ulast+
614: '&ufirstelement='+ufirst+
615: '&uemailelement='+uemail+
1.881 raeburn 616: '&hideudomelement='+hideudom+
617: '&coursedom='+crsdom;
1.888 raeburn 618: if ((caller != null) && (caller != undefined)) {
619: url += '&caller='+caller;
620: }
1.876 raeburn 621: var title = 'User_Browser';
622: var options = 'scrollbars=1,resizable=1,menubar=0';
623: options += ',width=700,height=600';
624: var stdeditbrowser = open(url,title,options,'1');
625: stdeditbrowser.focus();
626: }
627:
1.888 raeburn 628: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 629: var formid = getFormIdByName(formname);
630: if (formid > -1) {
1.888 raeburn 631: var unameid = getIndexByName(formid,uname);
1.876 raeburn 632: var domid = getIndexByName(formid,udom);
633: var hidedomid = getIndexByName(formid,origdom);
634: if (hidedomid > -1) {
635: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 636: var unameval = document.forms[formid].elements[unameid].value;
637: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
638: if (domid > -1) {
639: var slct = document.forms[formid].elements[domid];
640: if (slct.type == 'select-one') {
641: var i;
642: for (i=0;i<slct.length;i++) {
643: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
644: }
645: }
646: if (slct.type == 'hidden') {
647: slct.value = fixeddom;
1.876 raeburn 648: }
649: }
1.468 raeburn 650: }
651: }
652: }
1.876 raeburn 653: return;
654: }
655:
656: $id_functions
657: ENDUSERBRW
1.468 raeburn 658: }
659:
660: sub setsec_javascript {
1.905 raeburn 661: my ($sec_element,$formname,$role_element) = @_;
662: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
663: $communityrolestr);
664: if ($role_element ne '') {
665: my @allroles = ('st','ta','ep','in','ad');
666: foreach my $crstype ('Course','Community') {
667: if ($crstype eq 'Community') {
668: foreach my $role (@allroles) {
669: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
670: }
671: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
672: } else {
673: foreach my $role (@allroles) {
674: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
675: }
676: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
677: }
678: }
679: $rolestr = '"'.join('","',@allroles).'"';
680: $courserolestr = '"'.join('","',@courserolenames).'"';
681: $communityrolestr = '"'.join('","',@communityrolenames).'"';
682: }
1.468 raeburn 683: my $setsections = qq|
684: function setSect(sectionlist) {
1.629 raeburn 685: var sectionsArray = new Array();
686: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
687: sectionsArray = sectionlist.split(",");
688: }
1.468 raeburn 689: var numSections = sectionsArray.length;
690: document.$formname.$sec_element.length = 0;
691: if (numSections == 0) {
692: document.$formname.$sec_element.multiple=false;
693: document.$formname.$sec_element.size=1;
694: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
695: } else {
696: if (numSections == 1) {
697: document.$formname.$sec_element.multiple=false;
698: document.$formname.$sec_element.size=1;
699: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
700: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
701: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
702: } else {
703: for (var i=0; i<numSections; i++) {
704: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
705: }
706: document.$formname.$sec_element.multiple=true
707: if (numSections < 3) {
708: document.$formname.$sec_element.size=numSections;
709: } else {
710: document.$formname.$sec_element.size=3;
711: }
712: document.$formname.$sec_element.options[0].selected = false
713: }
714: }
1.91 www 715: }
1.905 raeburn 716:
717: function setRole(crstype) {
1.468 raeburn 718: |;
1.905 raeburn 719: if ($role_element eq '') {
720: $setsections .= ' return;
721: }
722: ';
723: } else {
724: $setsections .= qq|
725: var elementLength = document.$formname.$role_element.length;
726: var allroles = Array($rolestr);
727: var courserolenames = Array($courserolestr);
728: var communityrolenames = Array($communityrolestr);
729: if (elementLength != undefined) {
730: if (document.$formname.$role_element.options[5].value == 'cc') {
731: if (crstype == 'Course') {
732: return;
733: } else {
734: allroles[5] = 'co';
735: for (var i=0; i<6; i++) {
736: document.$formname.$role_element.options[i].value = allroles[i];
737: document.$formname.$role_element.options[i].text = communityrolenames[i];
738: }
739: }
740: } else {
741: if (crstype == 'Community') {
742: return;
743: } else {
744: allroles[5] = 'cc';
745: for (var i=0; i<6; i++) {
746: document.$formname.$role_element.options[i].value = allroles[i];
747: document.$formname.$role_element.options[i].text = courserolenames[i];
748: }
749: }
750: }
751: }
752: return;
753: }
754: |;
755: }
1.468 raeburn 756: return $setsections;
757: }
758:
1.91 www 759: sub selectcourse_link {
1.909 raeburn 760: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
761: $typeelement) = @_;
762: my $type = $selecttype;
1.871 raeburn 763: my $linktext = &mt('Select Course');
764: if ($selecttype eq 'Community') {
1.909 raeburn 765: $linktext = &mt('Select Community');
1.906 raeburn 766: } elsif ($selecttype eq 'Course/Community') {
767: $linktext = &mt('Select Course/Community');
1.909 raeburn 768: $type = '';
1.871 raeburn 769: }
1.787 bisitz 770: return '<span class="LC_nobreak">'
771: ."<a href='"
772: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
773: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 774: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 775: ."'>".$linktext.'</a>'
1.787 bisitz 776: .'</span>';
1.74 www 777: }
1.42 matthew 778:
1.653 raeburn 779: sub selectauthor_link {
780: my ($form,$udom)=@_;
781: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
782: &mt('Select Author').'</a>';
783: }
784:
1.876 raeburn 785: sub selectuser_link {
1.881 raeburn 786: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 787: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 788: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 789: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 790: ');">'.$linktext.'</a>';
1.876 raeburn 791: }
792:
1.273 raeburn 793: sub check_uncheck_jscript {
794: my $jscript = <<"ENDSCRT";
795: function checkAll(field) {
796: if (field.length > 0) {
797: for (i = 0; i < field.length; i++) {
798: field[i].checked = true ;
799: }
800: } else {
801: field.checked = true
802: }
803: }
804:
805: function uncheckAll(field) {
806: if (field.length > 0) {
807: for (i = 0; i < field.length; i++) {
808: field[i].checked = false ;
1.543 albertel 809: }
810: } else {
1.273 raeburn 811: field.checked = false ;
812: }
813: }
814: ENDSCRT
815: return $jscript;
816: }
817:
1.656 www 818: sub select_timezone {
1.659 raeburn 819: my ($name,$selected,$onchange,$includeempty)=@_;
820: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
821: if ($includeempty) {
822: $output .= '<option value=""';
823: if (($selected eq '') || ($selected eq 'local')) {
824: $output .= ' selected="selected" ';
825: }
826: $output .= '> </option>';
827: }
1.657 raeburn 828: my @timezones = DateTime::TimeZone->all_names;
829: foreach my $tzone (@timezones) {
830: $output.= '<option value="'.$tzone.'"';
831: if ($tzone eq $selected) {
832: $output.=' selected="selected"';
833: }
834: $output.=">$tzone</option>\n";
1.656 www 835: }
836: $output.="</select>";
837: return $output;
838: }
1.273 raeburn 839:
1.687 raeburn 840: sub select_datelocale {
841: my ($name,$selected,$onchange,$includeempty)=@_;
842: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
843: if ($includeempty) {
844: $output .= '<option value=""';
845: if ($selected eq '') {
846: $output .= ' selected="selected" ';
847: }
848: $output .= '> </option>';
849: }
850: my (@possibles,%locale_names);
851: my @locales = DateTime::Locale::Catalog::Locales;
852: foreach my $locale (@locales) {
853: if (ref($locale) eq 'HASH') {
854: my $id = $locale->{'id'};
855: if ($id ne '') {
856: my $en_terr = $locale->{'en_territory'};
857: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 858: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 859: if (grep(/^en$/,@languages) || !@languages) {
860: if ($en_terr ne '') {
861: $locale_names{$id} = '('.$en_terr.')';
862: } elsif ($native_terr ne '') {
863: $locale_names{$id} = $native_terr;
864: }
865: } else {
866: if ($native_terr ne '') {
867: $locale_names{$id} = $native_terr.' ';
868: } elsif ($en_terr ne '') {
869: $locale_names{$id} = '('.$en_terr.')';
870: }
871: }
872: push (@possibles,$id);
873: }
874: }
875: }
876: foreach my $item (sort(@possibles)) {
877: $output.= '<option value="'.$item.'"';
878: if ($item eq $selected) {
879: $output.=' selected="selected"';
880: }
881: $output.=">$item";
882: if ($locale_names{$item} ne '') {
883: $output.=" $locale_names{$item}</option>\n";
884: }
885: $output.="</option>\n";
886: }
887: $output.="</select>";
888: return $output;
889: }
890:
1.792 raeburn 891: sub select_language {
892: my ($name,$selected,$includeempty) = @_;
893: my %langchoices;
894: if ($includeempty) {
895: %langchoices = ('' => 'No language preference');
896: }
897: foreach my $id (&languageids()) {
898: my $code = &supportedlanguagecode($id);
899: if ($code) {
900: $langchoices{$code} = &plainlanguagedescription($id);
901: }
902: }
1.970 raeburn 903: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 904: }
905:
1.42 matthew 906: =pod
1.36 matthew 907:
1.648 raeburn 908: =item * &linked_select_forms(...)
1.36 matthew 909:
910: linked_select_forms returns a string containing a <script></script> block
911: and html for two <select> menus. The select menus will be linked in that
912: changing the value of the first menu will result in new values being placed
913: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 914: order unless a defined order is provided.
1.36 matthew 915:
916: linked_select_forms takes the following ordered inputs:
917:
918: =over 4
919:
1.112 bowersj2 920: =item * $formname, the name of the <form> tag
1.36 matthew 921:
1.112 bowersj2 922: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 923:
1.112 bowersj2 924: =item * $firstdefault, the default value for the first menu
1.36 matthew 925:
1.112 bowersj2 926: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 927:
1.112 bowersj2 928: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 929:
1.112 bowersj2 930: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 931:
1.609 raeburn 932: =item * $menuorder, the order of values in the first menu
933:
1.41 ng 934: =back
935:
1.36 matthew 936: Below is an example of such a hash. Only the 'text', 'default', and
937: 'select2' keys must appear as stated. keys(%menu) are the possible
938: values for the first select menu. The text that coincides with the
1.41 ng 939: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 940: and text for the second menu are given in the hash pointed to by
941: $menu{$choice1}->{'select2'}.
942:
1.112 bowersj2 943: my %menu = ( A1 => { text =>"Choice A1" ,
944: default => "B3",
945: select2 => {
946: B1 => "Choice B1",
947: B2 => "Choice B2",
948: B3 => "Choice B3",
949: B4 => "Choice B4"
1.609 raeburn 950: },
951: order => ['B4','B3','B1','B2'],
1.112 bowersj2 952: },
953: A2 => { text =>"Choice A2" ,
954: default => "C2",
955: select2 => {
956: C1 => "Choice C1",
957: C2 => "Choice C2",
958: C3 => "Choice C3"
1.609 raeburn 959: },
960: order => ['C2','C1','C3'],
1.112 bowersj2 961: },
962: A3 => { text =>"Choice A3" ,
963: default => "D6",
964: select2 => {
965: D1 => "Choice D1",
966: D2 => "Choice D2",
967: D3 => "Choice D3",
968: D4 => "Choice D4",
969: D5 => "Choice D5",
970: D6 => "Choice D6",
971: D7 => "Choice D7"
1.609 raeburn 972: },
973: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 974: }
975: );
1.36 matthew 976:
977: =cut
978:
979: sub linked_select_forms {
980: my ($formname,
981: $middletext,
982: $firstdefault,
983: $firstselectname,
984: $secondselectname,
1.609 raeburn 985: $hashref,
986: $menuorder,
1.36 matthew 987: ) = @_;
988: my $second = "document.$formname.$secondselectname";
989: my $first = "document.$formname.$firstselectname";
990: # output the javascript to do the changing
991: my $result = '';
1.776 bisitz 992: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 993: $result.="// <![CDATA[\n";
1.36 matthew 994: $result.="var select2data = new Object();\n";
995: $" = '","';
996: my $debug = '';
997: foreach my $s1 (sort(keys(%$hashref))) {
998: $result.="select2data.d_$s1 = new Object();\n";
999: $result.="select2data.d_$s1.def = new String('".
1000: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1001: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1002: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1003: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1004: @s2values = @{$hashref->{$s1}->{'order'}};
1005: }
1.36 matthew 1006: $result.="\"@s2values\");\n";
1007: $result.="select2data.d_$s1.texts = new Array(";
1008: my @s2texts;
1009: foreach my $value (@s2values) {
1010: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1011: }
1012: $result.="\"@s2texts\");\n";
1013: }
1014: $"=' ';
1015: $result.= <<"END";
1016:
1017: function select1_changed() {
1018: // Determine new choice
1019: var newvalue = "d_" + $first.value;
1020: // update select2
1021: var values = select2data[newvalue].values;
1022: var texts = select2data[newvalue].texts;
1023: var select2def = select2data[newvalue].def;
1024: var i;
1025: // out with the old
1026: for (i = 0; i < $second.options.length; i++) {
1027: $second.options[i] = null;
1028: }
1029: // in with the nuclear
1030: for (i=0;i<values.length; i++) {
1031: $second.options[i] = new Option(values[i]);
1.143 matthew 1032: $second.options[i].value = values[i];
1.36 matthew 1033: $second.options[i].text = texts[i];
1034: if (values[i] == select2def) {
1035: $second.options[i].selected = true;
1036: }
1037: }
1038: }
1.824 bisitz 1039: // ]]>
1.36 matthew 1040: </script>
1041: END
1042: # output the initial values for the selection lists
1043: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1044: my @order = sort(keys(%{$hashref}));
1045: if (ref($menuorder) eq 'ARRAY') {
1046: @order = @{$menuorder};
1047: }
1048: foreach my $value (@order) {
1.36 matthew 1049: $result.=" <option value=\"$value\" ";
1.253 albertel 1050: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1051: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1052: }
1053: $result .= "</select>\n";
1054: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1055: $result .= $middletext;
1056: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1057: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1058:
1059: my @secondorder = sort(keys(%select2));
1060: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1061: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1062: }
1063: foreach my $value (@secondorder) {
1.36 matthew 1064: $result.=" <option value=\"$value\" ";
1.253 albertel 1065: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1066: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1067: }
1068: $result .= "</select>\n";
1069: # return $debug;
1070: return $result;
1071: } # end of sub linked_select_forms {
1072:
1.45 matthew 1073: =pod
1.44 bowersj2 1074:
1.973 raeburn 1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1076:
1.112 bowersj2 1077: Returns a string corresponding to an HTML link to the given help
1078: $topic, where $topic corresponds to the name of a .tex file in
1079: /home/httpd/html/adm/help/tex, with underscores replaced by
1080: spaces.
1081:
1082: $text will optionally be linked to the same topic, allowing you to
1083: link text in addition to the graphic. If you do not want to link
1084: text, but wish to specify one of the later parameters, pass an
1085: empty string.
1086:
1087: $stayOnPage is a value that will be interpreted as a boolean. If true,
1088: the link will not open a new window. If false, the link will open
1089: a new window using Javascript. (Default is false.)
1090:
1091: $width and $height are optional numerical parameters that will
1092: override the width and height of the popped up window, which may
1.973 raeburn 1093: be useful for certain help topics with big pictures included.
1094:
1095: $imgid is the id of the img tag used for the help icon. This may be
1096: used in a javascript call to switch the image src. See
1097: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1098:
1099: =cut
1100:
1101: sub help_open_topic {
1.973 raeburn 1102: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1103: $text = "" if (not defined $text);
1.44 bowersj2 1104: $stayOnPage = 0 if (not defined $stayOnPage);
1105: $width = 350 if (not defined $width);
1106: $height = 400 if (not defined $height);
1107: my $filename = $topic;
1108: $filename =~ s/ /_/g;
1109:
1.48 bowersj2 1110: my $template = "";
1111: my $link;
1.572 banghart 1112:
1.159 www 1113: $topic=~s/\W/\_/g;
1.44 bowersj2 1114:
1.572 banghart 1115: if (!$stayOnPage) {
1.72 bowersj2 1116: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1117: } else {
1.48 bowersj2 1118: $link = "/adm/help/${filename}.hlp";
1119: }
1120:
1121: # Add the text
1.755 neumanie 1122: if ($text ne "") {
1.763 bisitz 1123: $template.='<span class="LC_help_open_topic">'
1124: .'<a target="_top" href="'.$link.'">'
1125: .$text.'</a>';
1.48 bowersj2 1126: }
1127:
1.763 bisitz 1128: # (Always) Add the graphic
1.179 matthew 1129: my $title = &mt('Online Help');
1.667 raeburn 1130: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1131: if ($imgid ne '') {
1132: $imgid = ' id="'.$imgid.'"';
1133: }
1.763 bisitz 1134: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1135: .'<img src="'.$helpicon.'" border="0"'
1136: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1137: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1138: .' /></a>';
1139: if ($text ne "") {
1140: $template.='</span>';
1141: }
1.44 bowersj2 1142: return $template;
1143:
1.106 bowersj2 1144: }
1145:
1146: # This is a quicky function for Latex cheatsheet editing, since it
1147: # appears in at least four places
1148: sub helpLatexCheatsheet {
1.732 raeburn 1149: my ($topic,$text,$not_author) = @_;
1150: my $out;
1.106 bowersj2 1151: my $addOther = '';
1.732 raeburn 1152: if ($topic) {
1.763 bisitz 1153: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1154: undef, undef, 600).
1155: '</span> ';
1156: }
1157: $out = '<span>' # Start cheatsheet
1158: .$addOther
1159: .'<span>'
1160: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1161: undef,undef,600)
1162: .'</span> <span>'
1163: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1164: undef,undef,600)
1165: .'</span>';
1.732 raeburn 1166: unless ($not_author) {
1.763 bisitz 1167: $out .= ' <span>'
1168: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1169: undef,undef,600)
1170: .'</span>';
1.732 raeburn 1171: }
1.763 bisitz 1172: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1173: return $out;
1.172 www 1174: }
1175:
1.430 albertel 1176: sub general_help {
1177: my $helptopic='Student_Intro';
1178: if ($env{'request.role'}=~/^(ca|au)/) {
1179: $helptopic='Authoring_Intro';
1.907 raeburn 1180: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1181: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1182: } elsif ($env{'request.role'}=~/^dc/) {
1183: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1184: }
1185: return $helptopic;
1186: }
1187:
1188: sub update_help_link {
1189: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1190: my $origurl = $ENV{'REQUEST_URI'};
1191: $origurl=~s|^/~|/priv/|;
1192: my $timestamp = time;
1193: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1194: $$datum = &escape($$datum);
1195: }
1196:
1197: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1198: my $output .= <<"ENDOUTPUT";
1199: <script type="text/javascript">
1.824 bisitz 1200: // <![CDATA[
1.430 albertel 1201: banner_link = '$banner_link';
1.824 bisitz 1202: // ]]>
1.430 albertel 1203: </script>
1204: ENDOUTPUT
1205: return $output;
1206: }
1207:
1208: # now just updates the help link and generates a blue icon
1.193 raeburn 1209: sub help_open_menu {
1.430 albertel 1210: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1211: = @_;
1.949 droeschl 1212: $stayOnPage = 1;
1.430 albertel 1213: my $output;
1214: if ($component_help) {
1215: if (!$text) {
1216: $output=&help_open_topic($component_help,undef,$stayOnPage,
1217: $width,$height);
1218: } else {
1219: my $help_text;
1220: $help_text=&unescape($topic);
1221: $output='<table><tr><td>'.
1222: &help_open_topic($component_help,$help_text,$stayOnPage,
1223: $width,$height).'</td></tr></table>';
1224: }
1225: }
1226: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1227: return $output.$banner_link;
1228: }
1229:
1230: sub top_nav_help {
1231: my ($text) = @_;
1.436 albertel 1232: $text = &mt($text);
1.949 droeschl 1233: my $stay_on_page = 1;
1234:
1.572 banghart 1235: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1236: : "javascript:helpMenu('open')";
1.572 banghart 1237: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1238:
1.201 raeburn 1239: my $title = &mt('Get help');
1.436 albertel 1240:
1241: return <<"END";
1242: $banner_link
1243: <a href="$link" title="$title">$text</a>
1244: END
1245: }
1246:
1247: sub help_menu_js {
1248: my ($text) = @_;
1.949 droeschl 1249: my $stayOnPage = 1;
1.436 albertel 1250: my $width = 620;
1251: my $height = 600;
1.430 albertel 1252: my $helptopic=&general_help();
1253: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1254: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1255: my $start_page =
1256: &Apache::loncommon::start_page('Help Menu', undef,
1257: {'frameset' => 1,
1258: 'js_ready' => 1,
1259: 'add_entries' => {
1260: 'border' => '0',
1.579 raeburn 1261: 'rows' => "110,*",},});
1.331 albertel 1262: my $end_page =
1263: &Apache::loncommon::end_page({'frameset' => 1,
1264: 'js_ready' => 1,});
1265:
1.436 albertel 1266: my $template .= <<"ENDTEMPLATE";
1267: <script type="text/javascript">
1.877 bisitz 1268: // <![CDATA[
1.253 albertel 1269: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1270: var banner_link = '';
1.243 raeburn 1271: function helpMenu(target) {
1272: var caller = this;
1273: if (target == 'open') {
1274: var newWindow = null;
1275: try {
1.262 albertel 1276: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1277: }
1278: catch(error) {
1279: writeHelp(caller);
1280: return;
1281: }
1282: if (newWindow) {
1283: caller = newWindow;
1284: }
1.193 raeburn 1285: }
1.243 raeburn 1286: writeHelp(caller);
1287: return;
1288: }
1289: function writeHelp(caller) {
1.430 albertel 1290: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1291: caller.document.close()
1292: caller.focus()
1.193 raeburn 1293: }
1.877 bisitz 1294: // END LON-CAPA Internal -->
1.253 albertel 1295: // ]]>
1.436 albertel 1296: </script>
1.193 raeburn 1297: ENDTEMPLATE
1298: return $template;
1299: }
1300:
1.172 www 1301: sub help_open_bug {
1302: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1303: unless ($env{'user.adv'}) { return ''; }
1.172 www 1304: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1305: $text = "" if (not defined $text);
1306: $stayOnPage=1;
1.184 albertel 1307: $width = 600 if (not defined $width);
1308: $height = 600 if (not defined $height);
1.172 www 1309:
1310: $topic=~s/\W+/\+/g;
1311: my $link='';
1312: my $template='';
1.379 albertel 1313: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1314: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1315: if (!$stayOnPage)
1316: {
1317: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1318: }
1319: else
1320: {
1321: $link = $url;
1322: }
1323: # Add the text
1324: if ($text ne "")
1325: {
1326: $template .=
1327: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1328: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1329: }
1330:
1331: # Add the graphic
1.179 matthew 1332: my $title = &mt('Report a Bug');
1.215 albertel 1333: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1334: $template .= <<"ENDTEMPLATE";
1.436 albertel 1335: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1336: ENDTEMPLATE
1337: if ($text ne '') { $template.='</td></tr></table>' };
1338: return $template;
1339:
1340: }
1341:
1342: sub help_open_faq {
1343: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1344: unless ($env{'user.adv'}) { return ''; }
1.172 www 1345: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1346: $text = "" if (not defined $text);
1347: $stayOnPage=1;
1348: $width = 350 if (not defined $width);
1349: $height = 400 if (not defined $height);
1350:
1351: $topic=~s/\W+/\+/g;
1352: my $link='';
1353: my $template='';
1354: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1355: if (!$stayOnPage)
1356: {
1357: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1358: }
1359: else
1360: {
1361: $link = $url;
1362: }
1363:
1364: # Add the text
1365: if ($text ne "")
1366: {
1367: $template .=
1.173 www 1368: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1369: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1370: }
1371:
1372: # Add the graphic
1.179 matthew 1373: my $title = &mt('View the FAQ');
1.215 albertel 1374: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1375: $template .= <<"ENDTEMPLATE";
1.436 albertel 1376: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1377: ENDTEMPLATE
1378: if ($text ne '') { $template.='</td></tr></table>' };
1379: return $template;
1380:
1.44 bowersj2 1381: }
1.37 matthew 1382:
1.180 matthew 1383: ###############################################################
1384: ###############################################################
1385:
1.45 matthew 1386: =pod
1387:
1.648 raeburn 1388: =item * &change_content_javascript():
1.256 matthew 1389:
1390: This and the next function allow you to create small sections of an
1391: otherwise static HTML page that you can update on the fly with
1392: Javascript, even in Netscape 4.
1393:
1394: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1395: must be written to the HTML page once. It will prove the Javascript
1396: function "change(name, content)". Calling the change function with the
1397: name of the section
1398: you want to update, matching the name passed to C<changable_area>, and
1399: the new content you want to put in there, will put the content into
1400: that area.
1401:
1402: B<Note>: Netscape 4 only reserves enough space for the changable area
1403: to contain room for the original contents. You need to "make space"
1404: for whatever changes you wish to make, and be B<sure> to check your
1405: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1406: it's adequate for updating a one-line status display, but little more.
1407: This script will set the space to 100% width, so you only need to
1408: worry about height in Netscape 4.
1409:
1410: Modern browsers are much less limiting, and if you can commit to the
1411: user not using Netscape 4, this feature may be used freely with
1412: pretty much any HTML.
1413:
1414: =cut
1415:
1416: sub change_content_javascript {
1417: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1418: if ($env{'browser.type'} eq 'netscape' &&
1419: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1420: return (<<NETSCAPE4);
1421: function change(name, content) {
1422: doc = document.layers[name+"___escape"].layers[0].document;
1423: doc.open();
1424: doc.write(content);
1425: doc.close();
1426: }
1427: NETSCAPE4
1428: } else {
1429: # Otherwise, we need to use semi-standards-compliant code
1430: # (technically, "innerHTML" isn't standard but the equivalent
1431: # is really scary, and every useful browser supports it
1432: return (<<DOMBASED);
1433: function change(name, content) {
1434: element = document.getElementById(name);
1435: element.innerHTML = content;
1436: }
1437: DOMBASED
1438: }
1439: }
1440:
1441: =pod
1442:
1.648 raeburn 1443: =item * &changable_area($name,$origContent):
1.256 matthew 1444:
1445: This provides a "changable area" that can be modified on the fly via
1446: the Javascript code provided in C<change_content_javascript>. $name is
1447: the name you will use to reference the area later; do not repeat the
1448: same name on a given HTML page more then once. $origContent is what
1449: the area will originally contain, which can be left blank.
1450:
1451: =cut
1452:
1453: sub changable_area {
1454: my ($name, $origContent) = @_;
1455:
1.258 albertel 1456: if ($env{'browser.type'} eq 'netscape' &&
1457: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1458: # If this is netscape 4, we need to use the Layer tag
1459: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1460: } else {
1461: return "<span id='$name'>$origContent</span>";
1462: }
1463: }
1464:
1465: =pod
1466:
1.648 raeburn 1467: =item * &viewport_geometry_js
1.590 raeburn 1468:
1469: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1470:
1471: =cut
1472:
1473:
1474: sub viewport_geometry_js {
1475: return <<"GEOMETRY";
1476: var Geometry = {};
1477: function init_geometry() {
1478: if (Geometry.init) { return };
1479: Geometry.init=1;
1480: if (window.innerHeight) {
1481: Geometry.getViewportHeight = function() { return window.innerHeight; };
1482: Geometry.getViewportWidth = function() { return window.innerWidth; };
1483: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1484: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1485: }
1486: else if (document.documentElement && document.documentElement.clientHeight) {
1487: Geometry.getViewportHeight =
1488: function() { return document.documentElement.clientHeight; };
1489: Geometry.getViewportWidth =
1490: function() { return document.documentElement.clientWidth; };
1491:
1492: Geometry.getHorizontalScroll =
1493: function() { return document.documentElement.scrollLeft; };
1494: Geometry.getVerticalScroll =
1495: function() { return document.documentElement.scrollTop; };
1496: }
1497: else if (document.body.clientHeight) {
1498: Geometry.getViewportHeight =
1499: function() { return document.body.clientHeight; };
1500: Geometry.getViewportWidth =
1501: function() { return document.body.clientWidth; };
1502: Geometry.getHorizontalScroll =
1503: function() { return document.body.scrollLeft; };
1504: Geometry.getVerticalScroll =
1505: function() { return document.body.scrollTop; };
1506: }
1507: }
1508:
1509: GEOMETRY
1510: }
1511:
1512: =pod
1513:
1.648 raeburn 1514: =item * &viewport_size_js()
1.590 raeburn 1515:
1516: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1517:
1518: =cut
1519:
1520: sub viewport_size_js {
1521: my $geometry = &viewport_geometry_js();
1522: return <<"DIMS";
1523:
1524: $geometry
1525:
1526: function getViewportDims(width,height) {
1527: init_geometry();
1528: width.value = Geometry.getViewportWidth();
1529: height.value = Geometry.getViewportHeight();
1530: return;
1531: }
1532:
1533: DIMS
1534: }
1535:
1536: =pod
1537:
1.648 raeburn 1538: =item * &resize_textarea_js()
1.565 albertel 1539:
1540: emits the needed javascript to resize a textarea to be as big as possible
1541:
1542: creates a function resize_textrea that takes two IDs first should be
1543: the id of the element to resize, second should be the id of a div that
1544: surrounds everything that comes after the textarea, this routine needs
1545: to be attached to the <body> for the onload and onresize events.
1546:
1.648 raeburn 1547: =back
1.565 albertel 1548:
1549: =cut
1550:
1551: sub resize_textarea_js {
1.590 raeburn 1552: my $geometry = &viewport_geometry_js();
1.565 albertel 1553: return <<"RESIZE";
1554: <script type="text/javascript">
1.824 bisitz 1555: // <![CDATA[
1.590 raeburn 1556: $geometry
1.565 albertel 1557:
1.588 albertel 1558: function getX(element) {
1559: var x = 0;
1560: while (element) {
1561: x += element.offsetLeft;
1562: element = element.offsetParent;
1563: }
1564: return x;
1565: }
1566: function getY(element) {
1567: var y = 0;
1568: while (element) {
1569: y += element.offsetTop;
1570: element = element.offsetParent;
1571: }
1572: return y;
1573: }
1574:
1575:
1.565 albertel 1576: function resize_textarea(textarea_id,bottom_id) {
1577: init_geometry();
1578: var textarea = document.getElementById(textarea_id);
1579: //alert(textarea);
1580:
1.588 albertel 1581: var textarea_top = getY(textarea);
1.565 albertel 1582: var textarea_height = textarea.offsetHeight;
1583: var bottom = document.getElementById(bottom_id);
1.588 albertel 1584: var bottom_top = getY(bottom);
1.565 albertel 1585: var bottom_height = bottom.offsetHeight;
1586: var window_height = Geometry.getViewportHeight();
1.588 albertel 1587: var fudge = 23;
1.565 albertel 1588: var new_height = window_height-fudge-textarea_top-bottom_height;
1589: if (new_height < 300) {
1590: new_height = 300;
1591: }
1592: textarea.style.height=new_height+'px';
1593: }
1.824 bisitz 1594: // ]]>
1.565 albertel 1595: </script>
1596: RESIZE
1597:
1598: }
1599:
1600: =pod
1601:
1.256 matthew 1602: =head1 Excel and CSV file utility routines
1603:
1604: =over 4
1605:
1606: =cut
1607:
1608: ###############################################################
1609: ###############################################################
1610:
1611: =pod
1612:
1.648 raeburn 1613: =item * &csv_translate($text)
1.37 matthew 1614:
1.185 www 1615: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1616: format.
1617:
1618: =cut
1619:
1.180 matthew 1620: ###############################################################
1621: ###############################################################
1.37 matthew 1622: sub csv_translate {
1623: my $text = shift;
1624: $text =~ s/\"/\"\"/g;
1.209 albertel 1625: $text =~ s/\n/ /g;
1.37 matthew 1626: return $text;
1627: }
1.180 matthew 1628:
1629: ###############################################################
1630: ###############################################################
1631:
1632: =pod
1633:
1.648 raeburn 1634: =item * &define_excel_formats()
1.180 matthew 1635:
1636: Define some commonly used Excel cell formats.
1637:
1638: Currently supported formats:
1639:
1640: =over 4
1641:
1642: =item header
1643:
1644: =item bold
1645:
1646: =item h1
1647:
1648: =item h2
1649:
1650: =item h3
1651:
1.256 matthew 1652: =item h4
1653:
1654: =item i
1655:
1.180 matthew 1656: =item date
1657:
1658: =back
1659:
1660: Inputs: $workbook
1661:
1662: Returns: $format, a hash reference.
1663:
1664: =cut
1665:
1666: ###############################################################
1667: ###############################################################
1668: sub define_excel_formats {
1669: my ($workbook) = @_;
1670: my $format;
1671: $format->{'header'} = $workbook->add_format(bold => 1,
1672: bottom => 1,
1673: align => 'center');
1674: $format->{'bold'} = $workbook->add_format(bold=>1);
1675: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1676: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1677: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1678: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1679: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1680: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1681: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1682: return $format;
1683: }
1684:
1685: ###############################################################
1686: ###############################################################
1.113 bowersj2 1687:
1688: =pod
1689:
1.648 raeburn 1690: =item * &create_workbook()
1.255 matthew 1691:
1692: Create an Excel worksheet. If it fails, output message on the
1693: request object and return undefs.
1694:
1695: Inputs: Apache request object
1696:
1697: Returns (undef) on failure,
1698: Excel worksheet object, scalar with filename, and formats
1699: from &Apache::loncommon::define_excel_formats on success
1700:
1701: =cut
1702:
1703: ###############################################################
1704: ###############################################################
1705: sub create_workbook {
1706: my ($r) = @_;
1707: #
1708: # Create the excel spreadsheet
1709: my $filename = '/prtspool/'.
1.258 albertel 1710: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1711: time.'_'.rand(1000000000).'.xls';
1712: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1713: if (! defined($workbook)) {
1714: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1715: $r->print(
1716: '<p class="LC_error">'
1717: .&mt('Problems occurred in creating the new Excel file.')
1718: .' '.&mt('This error has been logged.')
1719: .' '.&mt('Please alert your LON-CAPA administrator.')
1720: .'</p>'
1721: );
1.255 matthew 1722: return (undef);
1723: }
1724: #
1725: $workbook->set_tempdir('/home/httpd/perl/tmp');
1726: #
1727: my $format = &Apache::loncommon::define_excel_formats($workbook);
1728: return ($workbook,$filename,$format);
1729: }
1730:
1731: ###############################################################
1732: ###############################################################
1733:
1734: =pod
1735:
1.648 raeburn 1736: =item * &create_text_file()
1.113 bowersj2 1737:
1.542 raeburn 1738: Create a file to write to and eventually make available to the user.
1.256 matthew 1739: If file creation fails, outputs an error message on the request object and
1740: return undefs.
1.113 bowersj2 1741:
1.256 matthew 1742: Inputs: Apache request object, and file suffix
1.113 bowersj2 1743:
1.256 matthew 1744: Returns (undef) on failure,
1745: Filehandle and filename on success.
1.113 bowersj2 1746:
1747: =cut
1748:
1.256 matthew 1749: ###############################################################
1750: ###############################################################
1751: sub create_text_file {
1752: my ($r,$suffix) = @_;
1753: if (! defined($suffix)) { $suffix = 'txt'; };
1754: my $fh;
1755: my $filename = '/prtspool/'.
1.258 albertel 1756: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1757: time.'_'.rand(1000000000).'.'.$suffix;
1758: $fh = Apache::File->new('>/home/httpd'.$filename);
1759: if (! defined($fh)) {
1760: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1761: $r->print(
1762: '<p class="LC_error">'
1763: .&mt('Problems occurred in creating the output file.')
1764: .' '.&mt('This error has been logged.')
1765: .' '.&mt('Please alert your LON-CAPA administrator.')
1766: .'</p>'
1767: );
1.113 bowersj2 1768: }
1.256 matthew 1769: return ($fh,$filename)
1.113 bowersj2 1770: }
1771:
1772:
1.256 matthew 1773: =pod
1.113 bowersj2 1774:
1775: =back
1776:
1777: =cut
1.37 matthew 1778:
1779: ###############################################################
1.33 matthew 1780: ## Home server <option> list generating code ##
1781: ###############################################################
1.35 matthew 1782:
1.169 www 1783: # ------------------------------------------
1784:
1785: sub domain_select {
1786: my ($name,$value,$multiple)=@_;
1787: my %domains=map {
1.514 albertel 1788: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1789: } &Apache::lonnet::all_domains();
1.169 www 1790: if ($multiple) {
1791: $domains{''}=&mt('Any domain');
1.550 albertel 1792: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1793: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1794: } else {
1.550 albertel 1795: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1796: return &select_form($name,$value,\%domains);
1.169 www 1797: }
1798: }
1799:
1.282 albertel 1800: #-------------------------------------------
1801:
1802: =pod
1803:
1.519 raeburn 1804: =head1 Routines for form select boxes
1805:
1806: =over 4
1807:
1.648 raeburn 1808: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1809:
1810: Returns a string containing a <select> element int multiple mode
1811:
1812:
1813: Args:
1814: $name - name of the <select> element
1.506 raeburn 1815: $value - scalar or array ref of values that should already be selected
1.282 albertel 1816: $size - number of rows long the select element is
1.283 albertel 1817: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1818: (shown text should already have been &mt())
1.506 raeburn 1819: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1820:
1.282 albertel 1821: =cut
1822:
1823: #-------------------------------------------
1.169 www 1824: sub multiple_select_form {
1.284 albertel 1825: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1826: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1827: my $output='';
1.191 matthew 1828: if (! defined($size)) {
1829: $size = 4;
1.283 albertel 1830: if (scalar(keys(%$hash))<4) {
1831: $size = scalar(keys(%$hash));
1.191 matthew 1832: }
1833: }
1.734 bisitz 1834: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1835: my @order;
1.506 raeburn 1836: if (ref($order) eq 'ARRAY') {
1837: @order = @{$order};
1838: } else {
1839: @order = sort(keys(%$hash));
1.501 banghart 1840: }
1841: if (exists($$hash{'select_form_order'})) {
1842: @order = @{$$hash{'select_form_order'}};
1843: }
1844:
1.284 albertel 1845: foreach my $key (@order) {
1.356 albertel 1846: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1847: $output.='selected="selected" ' if ($selected{$key});
1848: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1849: }
1850: $output.="</select>\n";
1851: return $output;
1852: }
1853:
1.88 www 1854: #-------------------------------------------
1855:
1856: =pod
1857:
1.970 raeburn 1858: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1859:
1860: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1861: allow a user to select options from a ref to a hash containing:
1862: option_name => displayed text. An optional $onchange can include
1863: a javascript onchange item, e.g., onchange="this.form.submit();"
1864:
1.88 www 1865: See lonrights.pm for an example invocation and use.
1866:
1867: =cut
1868:
1869: #-------------------------------------------
1870: sub select_form {
1.970 raeburn 1871: my ($def,$name,$hashref,$onchange) = @_;
1872: return unless (ref($hashref) eq 'HASH');
1873: if ($onchange) {
1874: $onchange = ' onchange="'.$onchange.'"';
1875: }
1876: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1877: my @keys;
1.970 raeburn 1878: if (exists($hashref->{'select_form_order'})) {
1879: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1880: } else {
1.970 raeburn 1881: @keys=sort(keys(%{$hashref}));
1.128 albertel 1882: }
1.356 albertel 1883: foreach my $key (@keys) {
1884: $selectform.=
1885: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1886: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 1887: ">".$hashref->{$key}."</option>\n";
1.88 www 1888: }
1889: $selectform.="</select>";
1890: return $selectform;
1891: }
1892:
1.475 www 1893: # For display filters
1894:
1895: sub display_filter {
1896: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1897: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1898: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1899: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1900: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1901: '</label></span> <span class="LC_nobreak">'.
1.475 www 1902: &mt('Filter [_1]',
1.477 www 1903: &select_form($env{'form.displayfilter'},
1904: 'displayfilter',
1.970 raeburn 1905: {'currentfolder' => 'Current folder/page',
1.477 www 1906: 'containing' => 'Containing phrase',
1.970 raeburn 1907: 'none' => 'None'})).
1.714 bisitz 1908: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1909: }
1910:
1.167 www 1911: sub gradeleveldescription {
1912: my $gradelevel=shift;
1913: my %gradelevels=(0 => 'Not specified',
1914: 1 => 'Grade 1',
1915: 2 => 'Grade 2',
1916: 3 => 'Grade 3',
1917: 4 => 'Grade 4',
1918: 5 => 'Grade 5',
1919: 6 => 'Grade 6',
1920: 7 => 'Grade 7',
1921: 8 => 'Grade 8',
1922: 9 => 'Grade 9',
1923: 10 => 'Grade 10',
1924: 11 => 'Grade 11',
1925: 12 => 'Grade 12',
1926: 13 => 'Grade 13',
1927: 14 => '100 Level',
1928: 15 => '200 Level',
1929: 16 => '300 Level',
1930: 17 => '400 Level',
1931: 18 => 'Graduate Level');
1932: return &mt($gradelevels{$gradelevel});
1933: }
1934:
1.163 www 1935: sub select_level_form {
1936: my ($deflevel,$name)=@_;
1937: unless ($deflevel) { $deflevel=0; }
1.167 www 1938: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1939: for (my $i=0; $i<=18; $i++) {
1940: $selectform.="<option value=\"$i\" ".
1.253 albertel 1941: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1942: ">".&gradeleveldescription($i)."</option>\n";
1943: }
1944: $selectform.="</select>";
1945: return $selectform;
1.163 www 1946: }
1.167 www 1947:
1.35 matthew 1948: #-------------------------------------------
1949:
1.45 matthew 1950: =pod
1951:
1.910 raeburn 1952: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1953:
1954: Returns a string containing a <select name='$name' size='1'> form to
1955: allow a user to select the domain to preform an operation in.
1956: See loncreateuser.pm for an example invocation and use.
1957:
1.90 www 1958: If the $includeempty flag is set, it also includes an empty choice ("no domain
1959: selected");
1960:
1.743 raeburn 1961: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1962:
1.910 raeburn 1963: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
1964:
1965: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 1966:
1.35 matthew 1967: =cut
1968:
1969: #-------------------------------------------
1.34 matthew 1970: sub select_dom_form {
1.910 raeburn 1971: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 1972: if ($onchange) {
1.874 raeburn 1973: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1974: }
1.910 raeburn 1975: my @domains;
1976: if (ref($incdoms) eq 'ARRAY') {
1977: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
1978: } else {
1979: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1980: }
1.90 www 1981: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1982: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1983: foreach my $dom (@domains) {
1984: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1985: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1986: if ($showdomdesc) {
1987: if ($dom ne '') {
1988: my $domdesc = &Apache::lonnet::domain($dom,'description');
1989: if ($domdesc ne '') {
1990: $selectdomain .= ' ('.$domdesc.')';
1991: }
1992: }
1993: }
1994: $selectdomain .= "</option>\n";
1.34 matthew 1995: }
1996: $selectdomain.="</select>";
1997: return $selectdomain;
1998: }
1999:
1.35 matthew 2000: #-------------------------------------------
2001:
1.45 matthew 2002: =pod
2003:
1.648 raeburn 2004: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2005:
1.586 raeburn 2006: input: 4 arguments (two required, two optional) -
2007: $domain - domain of new user
2008: $name - name of form element
2009: $default - Value of 'default' causes a default item to be first
2010: option, and selected by default.
2011: $hide - Value of 'hide' causes hiding of the name of the server,
2012: if 1 server found, or default, if 0 found.
1.594 raeburn 2013: output: returns 2 items:
1.586 raeburn 2014: (a) form element which contains either:
2015: (i) <select name="$name">
2016: <option value="$hostid1">$hostid $servers{$hostid}</option>
2017: <option value="$hostid2">$hostid $servers{$hostid}</option>
2018: </select>
2019: form item if there are multiple library servers in $domain, or
2020: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2021: if there is only one library server in $domain.
2022:
2023: (b) number of library servers found.
2024:
2025: See loncreateuser.pm for example of use.
1.35 matthew 2026:
2027: =cut
2028:
2029: #-------------------------------------------
1.586 raeburn 2030: sub home_server_form_item {
2031: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2032: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2033: my $result;
2034: my $numlib = keys(%servers);
2035: if ($numlib > 1) {
2036: $result .= '<select name="'.$name.'" />'."\n";
2037: if ($default) {
1.804 bisitz 2038: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2039: '</option>'."\n";
2040: }
2041: foreach my $hostid (sort(keys(%servers))) {
2042: $result.= '<option value="'.$hostid.'">'.
2043: $hostid.' '.$servers{$hostid}."</option>\n";
2044: }
2045: $result .= '</select>'."\n";
2046: } elsif ($numlib == 1) {
2047: my $hostid;
2048: foreach my $item (keys(%servers)) {
2049: $hostid = $item;
2050: }
2051: $result .= '<input type="hidden" name="'.$name.'" value="'.
2052: $hostid.'" />';
2053: if (!$hide) {
2054: $result .= $hostid.' '.$servers{$hostid};
2055: }
2056: $result .= "\n";
2057: } elsif ($default) {
2058: $result .= '<input type="hidden" name="'.$name.
2059: '" value="default" />';
2060: if (!$hide) {
2061: $result .= &mt('default');
2062: }
2063: $result .= "\n";
1.33 matthew 2064: }
1.586 raeburn 2065: return ($result,$numlib);
1.33 matthew 2066: }
1.112 bowersj2 2067:
2068: =pod
2069:
1.534 albertel 2070: =back
2071:
1.112 bowersj2 2072: =cut
1.87 matthew 2073:
2074: ###############################################################
1.112 bowersj2 2075: ## Decoding User Agent ##
1.87 matthew 2076: ###############################################################
2077:
2078: =pod
2079:
1.112 bowersj2 2080: =head1 Decoding the User Agent
2081:
2082: =over 4
2083:
2084: =item * &decode_user_agent()
1.87 matthew 2085:
2086: Inputs: $r
2087:
2088: Outputs:
2089:
2090: =over 4
2091:
1.112 bowersj2 2092: =item * $httpbrowser
1.87 matthew 2093:
1.112 bowersj2 2094: =item * $clientbrowser
1.87 matthew 2095:
1.112 bowersj2 2096: =item * $clientversion
1.87 matthew 2097:
1.112 bowersj2 2098: =item * $clientmathml
1.87 matthew 2099:
1.112 bowersj2 2100: =item * $clientunicode
1.87 matthew 2101:
1.112 bowersj2 2102: =item * $clientos
1.87 matthew 2103:
2104: =back
2105:
1.157 matthew 2106: =back
2107:
1.87 matthew 2108: =cut
2109:
2110: ###############################################################
2111: ###############################################################
2112: sub decode_user_agent {
1.247 albertel 2113: my ($r)=@_;
1.87 matthew 2114: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2115: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2116: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2117: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2118: my $clientbrowser='unknown';
2119: my $clientversion='0';
2120: my $clientmathml='';
2121: my $clientunicode='0';
2122: for (my $i=0;$i<=$#browsertype;$i++) {
2123: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2124: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2125: $clientbrowser=$bname;
2126: $httpbrowser=~/$vreg/i;
2127: $clientversion=$1;
2128: $clientmathml=($clientversion>=$minv);
2129: $clientunicode=($clientversion>=$univ);
2130: }
2131: }
2132: my $clientos='unknown';
2133: if (($httpbrowser=~/linux/i) ||
2134: ($httpbrowser=~/unix/i) ||
2135: ($httpbrowser=~/ux/i) ||
2136: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2137: if (($httpbrowser=~/vax/i) ||
2138: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2139: if ($httpbrowser=~/next/i) { $clientos='next'; }
2140: if (($httpbrowser=~/mac/i) ||
2141: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2142: if ($httpbrowser=~/win/i) { $clientos='win'; }
2143: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2144: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2145: $clientunicode,$clientos,);
2146: }
2147:
1.32 matthew 2148: ###############################################################
2149: ## Authentication changing form generation subroutines ##
2150: ###############################################################
2151: ##
2152: ## All of the authform_xxxxxxx subroutines take their inputs in a
2153: ## hash, and have reasonable default values.
2154: ##
2155: ## formname = the name given in the <form> tag.
1.35 matthew 2156: #-------------------------------------------
2157:
1.45 matthew 2158: =pod
2159:
1.112 bowersj2 2160: =head1 Authentication Routines
2161:
2162: =over 4
2163:
1.648 raeburn 2164: =item * &authform_xxxxxx()
1.35 matthew 2165:
2166: The authform_xxxxxx subroutines provide javascript and html forms which
2167: handle some of the conveniences required for authentication forms.
2168: This is not an optimal method, but it works.
2169:
2170: =over 4
2171:
1.112 bowersj2 2172: =item * authform_header
1.35 matthew 2173:
1.112 bowersj2 2174: =item * authform_authorwarning
1.35 matthew 2175:
1.112 bowersj2 2176: =item * authform_nochange
1.35 matthew 2177:
1.112 bowersj2 2178: =item * authform_kerberos
1.35 matthew 2179:
1.112 bowersj2 2180: =item * authform_internal
1.35 matthew 2181:
1.112 bowersj2 2182: =item * authform_filesystem
1.35 matthew 2183:
2184: =back
2185:
1.648 raeburn 2186: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2187:
1.35 matthew 2188: =cut
2189:
2190: #-------------------------------------------
1.32 matthew 2191: sub authform_header{
2192: my %in = (
2193: formname => 'cu',
1.80 albertel 2194: kerb_def_dom => '',
1.32 matthew 2195: @_,
2196: );
2197: $in{'formname'} = 'document.' . $in{'formname'};
2198: my $result='';
1.80 albertel 2199:
2200: #---------------------------------------------- Code for upper case translation
2201: my $Javascript_toUpperCase;
2202: unless ($in{kerb_def_dom}) {
2203: $Javascript_toUpperCase =<<"END";
2204: switch (choice) {
2205: case 'krb': currentform.elements[choicearg].value =
2206: currentform.elements[choicearg].value.toUpperCase();
2207: break;
2208: default:
2209: }
2210: END
2211: } else {
2212: $Javascript_toUpperCase = "";
2213: }
2214:
1.165 raeburn 2215: my $radioval = "'nochange'";
1.591 raeburn 2216: if (defined($in{'curr_authtype'})) {
2217: if ($in{'curr_authtype'} ne '') {
2218: $radioval = "'".$in{'curr_authtype'}."arg'";
2219: }
1.174 matthew 2220: }
1.165 raeburn 2221: my $argfield = 'null';
1.591 raeburn 2222: if (defined($in{'mode'})) {
1.165 raeburn 2223: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2224: if (defined($in{'curr_autharg'})) {
2225: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2226: $argfield = "'$in{'curr_autharg'}'";
2227: }
2228: }
2229: }
2230: }
2231:
1.32 matthew 2232: $result.=<<"END";
2233: var current = new Object();
1.165 raeburn 2234: current.radiovalue = $radioval;
2235: current.argfield = $argfield;
1.32 matthew 2236:
2237: function changed_radio(choice,currentform) {
2238: var choicearg = choice + 'arg';
2239: // If a radio button in changed, we need to change the argfield
2240: if (current.radiovalue != choice) {
2241: current.radiovalue = choice;
2242: if (current.argfield != null) {
2243: currentform.elements[current.argfield].value = '';
2244: }
2245: if (choice == 'nochange') {
2246: current.argfield = null;
2247: } else {
2248: current.argfield = choicearg;
2249: switch(choice) {
2250: case 'krb':
2251: currentform.elements[current.argfield].value =
2252: "$in{'kerb_def_dom'}";
2253: break;
2254: default:
2255: break;
2256: }
2257: }
2258: }
2259: return;
2260: }
1.22 www 2261:
1.32 matthew 2262: function changed_text(choice,currentform) {
2263: var choicearg = choice + 'arg';
2264: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2265: $Javascript_toUpperCase
1.32 matthew 2266: // clear old field
2267: if ((current.argfield != choicearg) && (current.argfield != null)) {
2268: currentform.elements[current.argfield].value = '';
2269: }
2270: current.argfield = choicearg;
2271: }
2272: set_auth_radio_buttons(choice,currentform);
2273: return;
1.20 www 2274: }
1.32 matthew 2275:
2276: function set_auth_radio_buttons(newvalue,currentform) {
2277: var i=0;
2278: while (i < currentform.login.length) {
2279: if (currentform.login[i].value == newvalue) { break; }
2280: i++;
2281: }
2282: if (i == currentform.login.length) {
2283: return;
2284: }
2285: current.radiovalue = newvalue;
2286: currentform.login[i].checked = true;
2287: return;
2288: }
2289: END
2290: return $result;
2291: }
2292:
2293: sub authform_authorwarning{
2294: my $result='';
1.144 matthew 2295: $result='<i>'.
2296: &mt('As a general rule, only authors or co-authors should be '.
2297: 'filesystem authenticated '.
2298: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2299: return $result;
2300: }
2301:
2302: sub authform_nochange{
2303: my %in = (
2304: formname => 'document.cu',
2305: kerb_def_dom => 'MSU.EDU',
2306: @_,
2307: );
1.586 raeburn 2308: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2309: my $result;
2310: if (keys(%can_assign) == 0) {
2311: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2312: } else {
2313: $result = '<label>'.&mt('[_1] Do not change login data',
2314: '<input type="radio" name="login" value="nochange" '.
2315: 'checked="checked" onclick="'.
1.281 albertel 2316: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2317: '</label>';
1.586 raeburn 2318: }
1.32 matthew 2319: return $result;
2320: }
2321:
1.591 raeburn 2322: sub authform_kerberos {
1.32 matthew 2323: my %in = (
2324: formname => 'document.cu',
2325: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2326: kerb_def_auth => 'krb4',
1.32 matthew 2327: @_,
2328: );
1.586 raeburn 2329: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2330: $autharg,$jscall);
2331: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2332: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2333: $check5 = ' checked="checked"';
1.80 albertel 2334: } else {
1.772 bisitz 2335: $check4 = ' checked="checked"';
1.80 albertel 2336: }
1.165 raeburn 2337: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2338: if (defined($in{'curr_authtype'})) {
2339: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2340: $krbcheck = ' checked="checked"';
1.623 raeburn 2341: if (defined($in{'mode'})) {
2342: if ($in{'mode'} eq 'modifyuser') {
2343: $krbcheck = '';
2344: }
2345: }
1.591 raeburn 2346: if (defined($in{'curr_kerb_ver'})) {
2347: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2348: $check5 = ' checked="checked"';
1.591 raeburn 2349: $check4 = '';
2350: } else {
1.772 bisitz 2351: $check4 = ' checked="checked"';
1.591 raeburn 2352: $check5 = '';
2353: }
1.586 raeburn 2354: }
1.591 raeburn 2355: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2356: $krbarg = $in{'curr_autharg'};
2357: }
1.586 raeburn 2358: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2359: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2360: $result =
2361: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2362: $in{'curr_autharg'},$krbver);
2363: } else {
2364: $result =
2365: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2366: }
2367: return $result;
2368: }
2369: }
2370: } else {
2371: if ($authnum == 1) {
1.784 bisitz 2372: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2373: }
2374: }
1.586 raeburn 2375: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2376: return;
1.587 raeburn 2377: } elsif ($authtype eq '') {
1.591 raeburn 2378: if (defined($in{'mode'})) {
1.587 raeburn 2379: if ($in{'mode'} eq 'modifycourse') {
2380: if ($authnum == 1) {
1.784 bisitz 2381: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2382: }
2383: }
2384: }
1.586 raeburn 2385: }
2386: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2387: if ($authtype eq '') {
2388: $authtype = '<input type="radio" name="login" value="krb" '.
2389: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2390: $krbcheck.' />';
2391: }
2392: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2393: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2394: $in{'curr_authtype'} eq 'krb5') ||
2395: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2396: $in{'curr_authtype'} eq 'krb4')) {
2397: $result .= &mt
1.144 matthew 2398: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2399: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2400: '<label>'.$authtype,
1.281 albertel 2401: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2402: 'value="'.$krbarg.'" '.
1.144 matthew 2403: 'onchange="'.$jscall.'" />',
1.281 albertel 2404: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2405: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2406: '</label>');
1.586 raeburn 2407: } elsif ($can_assign{'krb4'}) {
2408: $result .= &mt
2409: ('[_1] Kerberos authenticated with domain [_2] '.
2410: '[_3] Version 4 [_4]',
2411: '<label>'.$authtype,
2412: '</label><input type="text" size="10" name="krbarg" '.
2413: 'value="'.$krbarg.'" '.
2414: 'onchange="'.$jscall.'" />',
2415: '<label><input type="hidden" name="krbver" value="4" />',
2416: '</label>');
2417: } elsif ($can_assign{'krb5'}) {
2418: $result .= &mt
2419: ('[_1] Kerberos authenticated with domain [_2] '.
2420: '[_3] Version 5 [_4]',
2421: '<label>'.$authtype,
2422: '</label><input type="text" size="10" name="krbarg" '.
2423: 'value="'.$krbarg.'" '.
2424: 'onchange="'.$jscall.'" />',
2425: '<label><input type="hidden" name="krbver" value="5" />',
2426: '</label>');
2427: }
1.32 matthew 2428: return $result;
2429: }
2430:
2431: sub authform_internal{
1.586 raeburn 2432: my %in = (
1.32 matthew 2433: formname => 'document.cu',
2434: kerb_def_dom => 'MSU.EDU',
2435: @_,
2436: );
1.586 raeburn 2437: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2438: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2439: if (defined($in{'curr_authtype'})) {
2440: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2441: if ($can_assign{'int'}) {
1.772 bisitz 2442: $intcheck = 'checked="checked" ';
1.623 raeburn 2443: if (defined($in{'mode'})) {
2444: if ($in{'mode'} eq 'modifyuser') {
2445: $intcheck = '';
2446: }
2447: }
1.591 raeburn 2448: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2449: $intarg = $in{'curr_autharg'};
2450: }
2451: } else {
2452: $result = &mt('Currently internally authenticated.');
2453: return $result;
1.165 raeburn 2454: }
2455: }
1.586 raeburn 2456: } else {
2457: if ($authnum == 1) {
1.784 bisitz 2458: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2459: }
2460: }
2461: if (!$can_assign{'int'}) {
2462: return;
1.587 raeburn 2463: } elsif ($authtype eq '') {
1.591 raeburn 2464: if (defined($in{'mode'})) {
1.587 raeburn 2465: if ($in{'mode'} eq 'modifycourse') {
2466: if ($authnum == 1) {
1.784 bisitz 2467: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2468: }
2469: }
2470: }
1.165 raeburn 2471: }
1.586 raeburn 2472: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2473: if ($authtype eq '') {
2474: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2475: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2476: }
1.605 bisitz 2477: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2478: $intarg.'" onchange="'.$jscall.'" />';
2479: $result = &mt
1.144 matthew 2480: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2481: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2482: $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 2483: return $result;
2484: }
2485:
2486: sub authform_local{
2487: my %in = (
2488: formname => 'document.cu',
2489: kerb_def_dom => 'MSU.EDU',
2490: @_,
2491: );
1.586 raeburn 2492: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2493: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2494: if (defined($in{'curr_authtype'})) {
2495: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2496: if ($can_assign{'loc'}) {
1.772 bisitz 2497: $loccheck = 'checked="checked" ';
1.623 raeburn 2498: if (defined($in{'mode'})) {
2499: if ($in{'mode'} eq 'modifyuser') {
2500: $loccheck = '';
2501: }
2502: }
1.591 raeburn 2503: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2504: $locarg = $in{'curr_autharg'};
2505: }
2506: } else {
2507: $result = &mt('Currently using local (institutional) authentication.');
2508: return $result;
1.165 raeburn 2509: }
2510: }
1.586 raeburn 2511: } else {
2512: if ($authnum == 1) {
1.784 bisitz 2513: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2514: }
2515: }
2516: if (!$can_assign{'loc'}) {
2517: return;
1.587 raeburn 2518: } elsif ($authtype eq '') {
1.591 raeburn 2519: if (defined($in{'mode'})) {
1.587 raeburn 2520: if ($in{'mode'} eq 'modifycourse') {
2521: if ($authnum == 1) {
1.784 bisitz 2522: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2523: }
2524: }
2525: }
1.165 raeburn 2526: }
1.586 raeburn 2527: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2528: if ($authtype eq '') {
2529: $authtype = '<input type="radio" name="login" value="loc" '.
2530: $loccheck.' onchange="'.$jscall.'" onclick="'.
2531: $jscall.'" />';
2532: }
2533: $autharg = '<input type="text" size="10" name="locarg" value="'.
2534: $locarg.'" onchange="'.$jscall.'" />';
2535: $result = &mt('[_1] Local Authentication with argument [_2]',
2536: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2537: return $result;
2538: }
2539:
2540: sub authform_filesystem{
2541: my %in = (
2542: formname => 'document.cu',
2543: kerb_def_dom => 'MSU.EDU',
2544: @_,
2545: );
1.586 raeburn 2546: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2547: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2548: if (defined($in{'curr_authtype'})) {
2549: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2550: if ($can_assign{'fsys'}) {
1.772 bisitz 2551: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2552: if (defined($in{'mode'})) {
2553: if ($in{'mode'} eq 'modifyuser') {
2554: $fsyscheck = '';
2555: }
2556: }
1.586 raeburn 2557: } else {
2558: $result = &mt('Currently Filesystem Authenticated.');
2559: return $result;
2560: }
2561: }
2562: } else {
2563: if ($authnum == 1) {
1.784 bisitz 2564: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2565: }
2566: }
2567: if (!$can_assign{'fsys'}) {
2568: return;
1.587 raeburn 2569: } elsif ($authtype eq '') {
1.591 raeburn 2570: if (defined($in{'mode'})) {
1.587 raeburn 2571: if ($in{'mode'} eq 'modifycourse') {
2572: if ($authnum == 1) {
1.784 bisitz 2573: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2574: }
2575: }
2576: }
1.586 raeburn 2577: }
2578: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2579: if ($authtype eq '') {
2580: $authtype = '<input type="radio" name="login" value="fsys" '.
2581: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2582: $jscall.'" />';
2583: }
2584: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2585: ' onchange="'.$jscall.'" />';
2586: $result = &mt
1.144 matthew 2587: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2588: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2589: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2590: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2591: 'onchange="'.$jscall.'" />');
1.32 matthew 2592: return $result;
2593: }
2594:
1.586 raeburn 2595: sub get_assignable_auth {
2596: my ($dom) = @_;
2597: if ($dom eq '') {
2598: $dom = $env{'request.role.domain'};
2599: }
2600: my %can_assign = (
2601: krb4 => 1,
2602: krb5 => 1,
2603: int => 1,
2604: loc => 1,
2605: );
2606: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2607: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2608: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2609: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2610: my $context;
2611: if ($env{'request.role'} =~ /^au/) {
2612: $context = 'author';
2613: } elsif ($env{'request.role'} =~ /^dc/) {
2614: $context = 'domain';
2615: } elsif ($env{'request.course.id'}) {
2616: $context = 'course';
2617: }
2618: if ($context) {
2619: if (ref($authhash->{$context}) eq 'HASH') {
2620: %can_assign = %{$authhash->{$context}};
2621: }
2622: }
2623: }
2624: }
2625: my $authnum = 0;
2626: foreach my $key (keys(%can_assign)) {
2627: if ($can_assign{$key}) {
2628: $authnum ++;
2629: }
2630: }
2631: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2632: $authnum --;
2633: }
2634: return ($authnum,%can_assign);
2635: }
2636:
1.80 albertel 2637: ###############################################################
2638: ## Get Kerberos Defaults for Domain ##
2639: ###############################################################
2640: ##
2641: ## Returns default kerberos version and an associated argument
2642: ## as listed in file domain.tab. If not listed, provides
2643: ## appropriate default domain and kerberos version.
2644: ##
2645: #-------------------------------------------
2646:
2647: =pod
2648:
1.648 raeburn 2649: =item * &get_kerberos_defaults()
1.80 albertel 2650:
2651: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2652: version and domain. If not found, it defaults to version 4 and the
2653: domain of the server.
1.80 albertel 2654:
1.648 raeburn 2655: =over 4
2656:
1.80 albertel 2657: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2658:
1.648 raeburn 2659: =back
2660:
2661: =back
2662:
1.80 albertel 2663: =cut
2664:
2665: #-------------------------------------------
2666: sub get_kerberos_defaults {
2667: my $domain=shift;
1.641 raeburn 2668: my ($krbdef,$krbdefdom);
2669: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2670: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2671: $krbdef = $domdefaults{'auth_def'};
2672: $krbdefdom = $domdefaults{'auth_arg_def'};
2673: } else {
1.80 albertel 2674: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2675: my $krbdefdom=$1;
2676: $krbdefdom=~tr/a-z/A-Z/;
2677: $krbdef = "krb4";
2678: }
2679: return ($krbdef,$krbdefdom);
2680: }
1.112 bowersj2 2681:
1.32 matthew 2682:
1.46 matthew 2683: ###############################################################
2684: ## Thesaurus Functions ##
2685: ###############################################################
1.20 www 2686:
1.46 matthew 2687: =pod
1.20 www 2688:
1.112 bowersj2 2689: =head1 Thesaurus Functions
2690:
2691: =over 4
2692:
1.648 raeburn 2693: =item * &initialize_keywords()
1.46 matthew 2694:
2695: Initializes the package variable %Keywords if it is empty. Uses the
2696: package variable $thesaurus_db_file.
2697:
2698: =cut
2699:
2700: ###################################################
2701:
2702: sub initialize_keywords {
2703: return 1 if (scalar keys(%Keywords));
2704: # If we are here, %Keywords is empty, so fill it up
2705: # Make sure the file we need exists...
2706: if (! -e $thesaurus_db_file) {
2707: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2708: " failed because it does not exist");
2709: return 0;
2710: }
2711: # Set up the hash as a database
2712: my %thesaurus_db;
2713: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2714: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2715: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2716: $thesaurus_db_file);
2717: return 0;
2718: }
2719: # Get the average number of appearances of a word.
2720: my $avecount = $thesaurus_db{'average.count'};
2721: # Put keywords (those that appear > average) into %Keywords
2722: while (my ($word,$data)=each (%thesaurus_db)) {
2723: my ($count,undef) = split /:/,$data;
2724: $Keywords{$word}++ if ($count > $avecount);
2725: }
2726: untie %thesaurus_db;
2727: # Remove special values from %Keywords.
1.356 albertel 2728: foreach my $value ('total.count','average.count') {
2729: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2730: }
1.46 matthew 2731: return 1;
2732: }
2733:
2734: ###################################################
2735:
2736: =pod
2737:
1.648 raeburn 2738: =item * &keyword($word)
1.46 matthew 2739:
2740: Returns true if $word is a keyword. A keyword is a word that appears more
2741: than the average number of times in the thesaurus database. Calls
2742: &initialize_keywords
2743:
2744: =cut
2745:
2746: ###################################################
1.20 www 2747:
2748: sub keyword {
1.46 matthew 2749: return if (!&initialize_keywords());
2750: my $word=lc(shift());
2751: $word=~s/\W//g;
2752: return exists($Keywords{$word});
1.20 www 2753: }
1.46 matthew 2754:
2755: ###############################################################
2756:
2757: =pod
1.20 www 2758:
1.648 raeburn 2759: =item * &get_related_words()
1.46 matthew 2760:
1.160 matthew 2761: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2762: an array of words. If the keyword is not in the thesaurus, an empty array
2763: will be returned. The order of the words returned is determined by the
2764: database which holds them.
2765:
2766: Uses global $thesaurus_db_file.
2767:
2768: =cut
2769:
2770: ###############################################################
2771: sub get_related_words {
2772: my $keyword = shift;
2773: my %thesaurus_db;
2774: if (! -e $thesaurus_db_file) {
2775: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2776: "failed because the file does not exist");
2777: return ();
2778: }
2779: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2780: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2781: return ();
2782: }
2783: my @Words=();
1.429 www 2784: my $count=0;
1.46 matthew 2785: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2786: # The first element is the number of times
2787: # the word appears. We do not need it now.
1.429 www 2788: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2789: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2790: my $threshold=$mostfrequentcount/10;
2791: foreach my $possibleword (@RelatedWords) {
2792: my ($word,$wordcount)=split(/\,/,$possibleword);
2793: if ($wordcount>$threshold) {
2794: push(@Words,$word);
2795: $count++;
2796: if ($count>10) { last; }
2797: }
1.20 www 2798: }
2799: }
1.46 matthew 2800: untie %thesaurus_db;
2801: return @Words;
1.14 harris41 2802: }
1.46 matthew 2803:
1.112 bowersj2 2804: =pod
2805:
2806: =back
2807:
2808: =cut
1.61 www 2809:
2810: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2811: =pod
2812:
1.112 bowersj2 2813: =head1 User Name Functions
2814:
2815: =over 4
2816:
1.648 raeburn 2817: =item * &plainname($uname,$udom,$first)
1.81 albertel 2818:
1.112 bowersj2 2819: Takes a users logon name and returns it as a string in
1.226 albertel 2820: "first middle last generation" form
2821: if $first is set to 'lastname' then it returns it as
2822: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2823:
2824: =cut
1.61 www 2825:
1.295 www 2826:
1.81 albertel 2827: ###############################################################
1.61 www 2828: sub plainname {
1.226 albertel 2829: my ($uname,$udom,$first)=@_;
1.537 albertel 2830: return if (!defined($uname) || !defined($udom));
1.295 www 2831: my %names=&getnames($uname,$udom);
1.226 albertel 2832: my $name=&Apache::lonnet::format_name($names{'firstname'},
2833: $names{'middlename'},
2834: $names{'lastname'},
2835: $names{'generation'},$first);
2836: $name=~s/^\s+//;
1.62 www 2837: $name=~s/\s+$//;
2838: $name=~s/\s+/ /g;
1.353 albertel 2839: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2840: return $name;
1.61 www 2841: }
1.66 www 2842:
2843: # -------------------------------------------------------------------- Nickname
1.81 albertel 2844: =pod
2845:
1.648 raeburn 2846: =item * &nickname($uname,$udom)
1.81 albertel 2847:
2848: Gets a users name and returns it as a string as
2849:
2850: ""nickname""
1.66 www 2851:
1.81 albertel 2852: if the user has a nickname or
2853:
2854: "first middle last generation"
2855:
2856: if the user does not
2857:
2858: =cut
1.66 www 2859:
2860: sub nickname {
2861: my ($uname,$udom)=@_;
1.537 albertel 2862: return if (!defined($uname) || !defined($udom));
1.295 www 2863: my %names=&getnames($uname,$udom);
1.68 albertel 2864: my $name=$names{'nickname'};
1.66 www 2865: if ($name) {
2866: $name='"'.$name.'"';
2867: } else {
2868: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2869: $names{'lastname'}.' '.$names{'generation'};
2870: $name=~s/\s+$//;
2871: $name=~s/\s+/ /g;
2872: }
2873: return $name;
2874: }
2875:
1.295 www 2876: sub getnames {
2877: my ($uname,$udom)=@_;
1.537 albertel 2878: return if (!defined($uname) || !defined($udom));
1.433 albertel 2879: if ($udom eq 'public' && $uname eq 'public') {
2880: return ('lastname' => &mt('Public'));
2881: }
1.295 www 2882: my $id=$uname.':'.$udom;
2883: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2884: if ($cached) {
2885: return %{$names};
2886: } else {
2887: my %loadnames=&Apache::lonnet::get('environment',
2888: ['firstname','middlename','lastname','generation','nickname'],
2889: $udom,$uname);
2890: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2891: return %loadnames;
2892: }
2893: }
1.61 www 2894:
1.542 raeburn 2895: # -------------------------------------------------------------------- getemails
1.648 raeburn 2896:
1.542 raeburn 2897: =pod
2898:
1.648 raeburn 2899: =item * &getemails($uname,$udom)
1.542 raeburn 2900:
2901: Gets a user's email information and returns it as a hash with keys:
2902: notification, critnotification, permanentemail
2903:
2904: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2905: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2906:
1.648 raeburn 2907:
1.542 raeburn 2908: =cut
2909:
1.648 raeburn 2910:
1.466 albertel 2911: sub getemails {
2912: my ($uname,$udom)=@_;
2913: if ($udom eq 'public' && $uname eq 'public') {
2914: return;
2915: }
1.467 www 2916: if (!$udom) { $udom=$env{'user.domain'}; }
2917: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2918: my $id=$uname.':'.$udom;
2919: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2920: if ($cached) {
2921: return %{$names};
2922: } else {
2923: my %loadnames=&Apache::lonnet::get('environment',
2924: ['notification','critnotification',
2925: 'permanentemail'],
2926: $udom,$uname);
2927: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2928: return %loadnames;
2929: }
2930: }
2931:
1.551 albertel 2932: sub flush_email_cache {
2933: my ($uname,$udom)=@_;
2934: if (!$udom) { $udom =$env{'user.domain'}; }
2935: if (!$uname) { $uname=$env{'user.name'}; }
2936: return if ($udom eq 'public' && $uname eq 'public');
2937: my $id=$uname.':'.$udom;
2938: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2939: }
2940:
1.728 raeburn 2941: # -------------------------------------------------------------------- getlangs
2942:
2943: =pod
2944:
2945: =item * &getlangs($uname,$udom)
2946:
2947: Gets a user's language preference and returns it as a hash with key:
2948: language.
2949:
2950: =cut
2951:
2952:
2953: sub getlangs {
2954: my ($uname,$udom) = @_;
2955: if (!$udom) { $udom =$env{'user.domain'}; }
2956: if (!$uname) { $uname=$env{'user.name'}; }
2957: my $id=$uname.':'.$udom;
2958: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2959: if ($cached) {
2960: return %{$langs};
2961: } else {
2962: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2963: $udom,$uname);
2964: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2965: return %loadlangs;
2966: }
2967: }
2968:
2969: sub flush_langs_cache {
2970: my ($uname,$udom)=@_;
2971: if (!$udom) { $udom =$env{'user.domain'}; }
2972: if (!$uname) { $uname=$env{'user.name'}; }
2973: return if ($udom eq 'public' && $uname eq 'public');
2974: my $id=$uname.':'.$udom;
2975: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2976: }
2977:
1.61 www 2978: # ------------------------------------------------------------------ Screenname
1.81 albertel 2979:
2980: =pod
2981:
1.648 raeburn 2982: =item * &screenname($uname,$udom)
1.81 albertel 2983:
2984: Gets a users screenname and returns it as a string
2985:
2986: =cut
1.61 www 2987:
2988: sub screenname {
2989: my ($uname,$udom)=@_;
1.258 albertel 2990: if ($uname eq $env{'user.name'} &&
2991: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2992: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2993: return $names{'screenname'};
1.62 www 2994: }
2995:
1.212 albertel 2996:
1.802 bisitz 2997: # ------------------------------------------------------------- Confirm Wrapper
2998: =pod
2999:
3000: =item confirmwrapper
3001:
3002: Wrap messages about completion of operation in box
3003:
3004: =cut
3005:
3006: sub confirmwrapper {
3007: my ($message)=@_;
3008: if ($message) {
3009: return "\n".'<div class="LC_confirm_box">'."\n"
3010: .$message."\n"
3011: .'</div>'."\n";
3012: } else {
3013: return $message;
3014: }
3015: }
3016:
1.62 www 3017: # ------------------------------------------------------------- Message Wrapper
3018:
3019: sub messagewrapper {
1.369 www 3020: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3021: return
1.441 albertel 3022: '<a href="/adm/email?compose=individual&'.
3023: 'recname='.$username.'&recdom='.$domain.
3024: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3025: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3026: }
1.802 bisitz 3027:
1.74 www 3028: # --------------------------------------------------------------- Notes Wrapper
3029:
3030: sub noteswrapper {
3031: my ($link,$un,$do)=@_;
3032: return
1.896 amueller 3033: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3034: }
1.802 bisitz 3035:
1.62 www 3036: # ------------------------------------------------------------- Aboutme Wrapper
3037:
3038: sub aboutmewrapper {
1.166 www 3039: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3040: if (!defined($username) && !defined($domain)) {
3041: return;
3042: }
1.892 amueller 3043: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3044: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3045: }
3046:
3047: # ------------------------------------------------------------ Syllabus Wrapper
3048:
3049: sub syllabuswrapper {
1.707 bisitz 3050: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3051: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3052: }
1.14 harris41 3053:
1.802 bisitz 3054: # -----------------------------------------------------------------------------
3055:
1.208 matthew 3056: sub track_student_link {
1.887 raeburn 3057: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3058: my $link ="/adm/trackstudent?";
1.208 matthew 3059: my $title = 'View recent activity';
3060: if (defined($sname) && $sname !~ /^\s*$/ &&
3061: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3062: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3063: $title .= ' of this student';
1.268 albertel 3064: }
1.208 matthew 3065: if (defined($target) && $target !~ /^\s*$/) {
3066: $target = qq{target="$target"};
3067: } else {
3068: $target = '';
3069: }
1.268 albertel 3070: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3071: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3072: $title = &mt($title);
3073: $linktext = &mt($linktext);
1.448 albertel 3074: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3075: &help_open_topic('View_recent_activity');
1.208 matthew 3076: }
3077:
1.781 raeburn 3078: sub slot_reservations_link {
3079: my ($linktext,$sname,$sdom,$target) = @_;
3080: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3081: my $title = 'View slot reservation history';
3082: if (defined($sname) && $sname !~ /^\s*$/ &&
3083: defined($sdom) && $sdom !~ /^\s*$/) {
3084: $link .= "&uname=$sname&udom=$sdom";
3085: $title .= ' of this student';
3086: }
3087: if (defined($target) && $target !~ /^\s*$/) {
3088: $target = qq{target="$target"};
3089: } else {
3090: $target = '';
3091: }
3092: $title = &mt($title);
3093: $linktext = &mt($linktext);
3094: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3095: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3096:
3097: }
3098:
1.508 www 3099: # ===================================================== Display a student photo
3100:
3101:
1.509 albertel 3102: sub student_image_tag {
1.508 www 3103: my ($domain,$user)=@_;
3104: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3105: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3106: return '<img src="'.$imgsrc.'" align="right" />';
3107: } else {
3108: return '';
3109: }
3110: }
3111:
1.112 bowersj2 3112: =pod
3113:
3114: =back
3115:
3116: =head1 Access .tab File Data
3117:
3118: =over 4
3119:
1.648 raeburn 3120: =item * &languageids()
1.112 bowersj2 3121:
3122: returns list of all language ids
3123:
3124: =cut
3125:
1.14 harris41 3126: sub languageids {
1.16 harris41 3127: return sort(keys(%language));
1.14 harris41 3128: }
3129:
1.112 bowersj2 3130: =pod
3131:
1.648 raeburn 3132: =item * &languagedescription()
1.112 bowersj2 3133:
3134: returns description of a specified language id
3135:
3136: =cut
3137:
1.14 harris41 3138: sub languagedescription {
1.125 www 3139: my $code=shift;
3140: return ($supported_language{$code}?'* ':'').
3141: $language{$code}.
1.126 www 3142: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3143: }
3144:
3145: sub plainlanguagedescription {
3146: my $code=shift;
3147: return $language{$code};
3148: }
3149:
3150: sub supportedlanguagecode {
3151: my $code=shift;
3152: return $supported_language{$code};
1.97 www 3153: }
3154:
1.112 bowersj2 3155: =pod
3156:
1.648 raeburn 3157: =item * ©rightids()
1.112 bowersj2 3158:
3159: returns list of all copyrights
3160:
3161: =cut
3162:
3163: sub copyrightids {
3164: return sort(keys(%cprtag));
3165: }
3166:
3167: =pod
3168:
1.648 raeburn 3169: =item * ©rightdescription()
1.112 bowersj2 3170:
3171: returns description of a specified copyright id
3172:
3173: =cut
3174:
3175: sub copyrightdescription {
1.166 www 3176: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3177: }
1.197 matthew 3178:
3179: =pod
3180:
1.648 raeburn 3181: =item * &source_copyrightids()
1.192 taceyjo1 3182:
3183: returns list of all source copyrights
3184:
3185: =cut
3186:
3187: sub source_copyrightids {
3188: return sort(keys(%scprtag));
3189: }
3190:
3191: =pod
3192:
1.648 raeburn 3193: =item * &source_copyrightdescription()
1.192 taceyjo1 3194:
3195: returns description of a specified source copyright id
3196:
3197: =cut
3198:
3199: sub source_copyrightdescription {
3200: return &mt($scprtag{shift(@_)});
3201: }
1.112 bowersj2 3202:
3203: =pod
3204:
1.648 raeburn 3205: =item * &filecategories()
1.112 bowersj2 3206:
3207: returns list of all file categories
3208:
3209: =cut
3210:
3211: sub filecategories {
3212: return sort(keys(%category_extensions));
3213: }
3214:
3215: =pod
3216:
1.648 raeburn 3217: =item * &filecategorytypes()
1.112 bowersj2 3218:
3219: returns list of file types belonging to a given file
3220: category
3221:
3222: =cut
3223:
3224: sub filecategorytypes {
1.356 albertel 3225: my ($cat) = @_;
3226: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3227: }
3228:
3229: =pod
3230:
1.648 raeburn 3231: =item * &fileembstyle()
1.112 bowersj2 3232:
3233: returns embedding style for a specified file type
3234:
3235: =cut
3236:
3237: sub fileembstyle {
3238: return $fe{lc(shift(@_))};
1.169 www 3239: }
3240:
1.351 www 3241: sub filemimetype {
3242: return $fm{lc(shift(@_))};
3243: }
3244:
1.169 www 3245:
3246: sub filecategoryselect {
3247: my ($name,$value)=@_;
1.189 matthew 3248: return &select_form($value,$name,
1.970 raeburn 3249: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3250: }
3251:
3252: =pod
3253:
1.648 raeburn 3254: =item * &filedescription()
1.112 bowersj2 3255:
3256: returns description for a specified file type
3257:
3258: =cut
3259:
3260: sub filedescription {
1.188 matthew 3261: my $file_description = $fd{lc(shift())};
3262: $file_description =~ s:([\[\]]):~$1:g;
3263: return &mt($file_description);
1.112 bowersj2 3264: }
3265:
3266: =pod
3267:
1.648 raeburn 3268: =item * &filedescriptionex()
1.112 bowersj2 3269:
3270: returns description for a specified file type with
3271: extra formatting
3272:
3273: =cut
3274:
3275: sub filedescriptionex {
3276: my $ex=shift;
1.188 matthew 3277: my $file_description = $fd{lc($ex)};
3278: $file_description =~ s:([\[\]]):~$1:g;
3279: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3280: }
3281:
3282: # End of .tab access
3283: =pod
3284:
3285: =back
3286:
3287: =cut
3288:
3289: # ------------------------------------------------------------------ File Types
3290: sub fileextensions {
3291: return sort(keys(%fe));
3292: }
3293:
1.97 www 3294: # ----------------------------------------------------------- Display Languages
3295: # returns a hash with all desired display languages
3296: #
3297:
3298: sub display_languages {
3299: my %languages=();
1.695 raeburn 3300: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3301: $languages{$lang}=1;
1.97 www 3302: }
3303: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3304: if ($env{'form.displaylanguage'}) {
1.356 albertel 3305: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3306: $languages{$lang}=1;
1.97 www 3307: }
3308: }
3309: return %languages;
1.14 harris41 3310: }
3311:
1.582 albertel 3312: sub languages {
3313: my ($possible_langs) = @_;
1.695 raeburn 3314: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3315: if (!ref($possible_langs)) {
3316: if( wantarray ) {
3317: return @preferred_langs;
3318: } else {
3319: return $preferred_langs[0];
3320: }
3321: }
3322: my %possibilities = map { $_ => 1 } (@$possible_langs);
3323: my @preferred_possibilities;
3324: foreach my $preferred_lang (@preferred_langs) {
3325: if (exists($possibilities{$preferred_lang})) {
3326: push(@preferred_possibilities, $preferred_lang);
3327: }
3328: }
3329: if( wantarray ) {
3330: return @preferred_possibilities;
3331: }
3332: return $preferred_possibilities[0];
3333: }
3334:
1.742 raeburn 3335: sub user_lang {
3336: my ($touname,$toudom,$fromcid) = @_;
3337: my @userlangs;
3338: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3339: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3340: $env{'course.'.$fromcid.'.languages'}));
3341: } else {
3342: my %langhash = &getlangs($touname,$toudom);
3343: if ($langhash{'languages'} ne '') {
3344: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3345: } else {
3346: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3347: if ($domdefs{'lang_def'} ne '') {
3348: @userlangs = ($domdefs{'lang_def'});
3349: }
3350: }
3351: }
3352: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3353: my $user_lh = Apache::localize->get_handle(@languages);
3354: return $user_lh;
3355: }
3356:
3357:
1.112 bowersj2 3358: ###############################################################
3359: ## Student Answer Attempts ##
3360: ###############################################################
3361:
3362: =pod
3363:
3364: =head1 Alternate Problem Views
3365:
3366: =over 4
3367:
1.648 raeburn 3368: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3369: $getattempt, $regexp, $gradesub)
3370:
3371: Return string with previous attempt on problem. Arguments:
3372:
3373: =over 4
3374:
3375: =item * $symb: Problem, including path
3376:
3377: =item * $username: username of the desired student
3378:
3379: =item * $domain: domain of the desired student
1.14 harris41 3380:
1.112 bowersj2 3381: =item * $course: Course ID
1.14 harris41 3382:
1.112 bowersj2 3383: =item * $getattempt: Leave blank for all attempts, otherwise put
3384: something
1.14 harris41 3385:
1.112 bowersj2 3386: =item * $regexp: if string matches this regexp, the string will be
3387: sent to $gradesub
1.14 harris41 3388:
1.112 bowersj2 3389: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3390:
1.112 bowersj2 3391: =back
1.14 harris41 3392:
1.112 bowersj2 3393: The output string is a table containing all desired attempts, if any.
1.16 harris41 3394:
1.112 bowersj2 3395: =cut
1.1 albertel 3396:
3397: sub get_previous_attempt {
1.43 ng 3398: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3399: my $prevattempts='';
1.43 ng 3400: no strict 'refs';
1.1 albertel 3401: if ($symb) {
1.3 albertel 3402: my (%returnhash)=
3403: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3404: if ($returnhash{'version'}) {
3405: my %lasthash=();
3406: my $version;
3407: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3408: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3409: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3410: }
1.1 albertel 3411: }
1.596 albertel 3412: $prevattempts=&start_data_table().&start_data_table_header_row();
3413: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 ! raeburn 3414: my (%typeparts,%lasthidden);
1.945 raeburn 3415: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3416: foreach my $key (sort(keys(%lasthash))) {
3417: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3418: if ($#parts > 0) {
1.31 albertel 3419: my $data=$parts[-1];
3420: pop(@parts);
1.945 raeburn 3421: if ($data eq 'type') {
3422: unless ($showsurv) {
3423: my $id = join(',',@parts);
3424: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 ! raeburn 3425: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
! 3426: $lasthidden{$ign.'.'.$id} = 1;
! 3427: }
1.945 raeburn 3428: }
3429: delete($lasthash{$key});
3430: } else {
3431: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3432: }
1.31 albertel 3433: } else {
1.41 ng 3434: if ($#parts == 0) {
3435: $prevattempts.='<th>'.$parts[0].'</th>';
3436: } else {
3437: $prevattempts.='<th>'.$ign.'</th>';
3438: }
1.31 albertel 3439: }
1.16 harris41 3440: }
1.596 albertel 3441: $prevattempts.=&end_data_table_header_row();
1.40 ng 3442: if ($getattempt eq '') {
3443: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3444: my @hidden;
3445: if (%typeparts) {
3446: foreach my $id (keys(%typeparts)) {
3447: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3448: push(@hidden,$id);
3449: }
3450: }
3451: }
3452: $prevattempts.=&start_data_table_row().
3453: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3454: if (@hidden) {
3455: foreach my $key (sort(keys(%lasthash))) {
3456: my $hide;
3457: foreach my $id (@hidden) {
3458: if ($key =~ /^\Q$id\E/) {
3459: $hide = 1;
3460: last;
3461: }
3462: }
3463: if ($hide) {
3464: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3465: if (($data eq 'award') || ($data eq 'awarddetail')) {
3466: my $value = &format_previous_attempt_value($key,
3467: $returnhash{$version.':'.$key});
3468: $prevattempts.='<td>'.$value.' </td>';
3469: } else {
3470: $prevattempts.='<td> </td>';
3471: }
3472: } else {
3473: if ($key =~ /\./) {
3474: my $value = &format_previous_attempt_value($key,
3475: $returnhash{$version.':'.$key});
3476: $prevattempts.='<td>'.$value.' </td>';
3477: } else {
3478: $prevattempts.='<td> </td>';
3479: }
3480: }
3481: }
3482: } else {
3483: foreach my $key (sort(keys(%lasthash))) {
3484: my $value = &format_previous_attempt_value($key,
3485: $returnhash{$version.':'.$key});
3486: $prevattempts.='<td>'.$value.' </td>';
3487: }
3488: }
3489: $prevattempts.=&end_data_table_row();
1.40 ng 3490: }
1.1 albertel 3491: }
1.945 raeburn 3492: my @currhidden = keys(%lasthidden);
1.596 albertel 3493: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3494: foreach my $key (sort(keys(%lasthash))) {
1.945 raeburn 3495: if (%typeparts) {
3496: my $hidden;
3497: foreach my $id (@currhidden) {
3498: if ($key =~ /^\Q$id\E/) {
3499: $hidden = 1;
3500: last;
3501: }
3502: }
3503: if ($hidden) {
3504: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3505: if (($data eq 'award') || ($data eq 'awarddetail')) {
3506: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3507: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3508: $value = &$gradesub($value);
3509: }
3510: $prevattempts.='<td>'.$value.' </td>';
3511: } else {
3512: $prevattempts.='<td> </td>';
3513: }
3514: } else {
3515: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3516: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3517: $value = &$gradesub($value);
3518: }
3519: $prevattempts.='<td>'.$value.' </td>';
3520: }
3521: } else {
3522: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3523: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3524: $value = &$gradesub($value);
3525: }
3526: $prevattempts.='<td>'.$value.' </td>';
3527: }
1.16 harris41 3528: }
1.596 albertel 3529: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3530: } else {
1.596 albertel 3531: $prevattempts=
3532: &start_data_table().&start_data_table_row().
3533: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3534: &end_data_table_row().&end_data_table();
1.1 albertel 3535: }
3536: } else {
1.596 albertel 3537: $prevattempts=
3538: &start_data_table().&start_data_table_row().
3539: '<td>'.&mt('No data.').'</td>'.
3540: &end_data_table_row().&end_data_table();
1.1 albertel 3541: }
1.10 albertel 3542: }
3543:
1.581 albertel 3544: sub format_previous_attempt_value {
3545: my ($key,$value) = @_;
3546: if ($key =~ /timestamp/) {
3547: $value = &Apache::lonlocal::locallocaltime($value);
3548: } elsif (ref($value) eq 'ARRAY') {
3549: $value = '('.join(', ', @{ $value }).')';
3550: } else {
3551: $value = &unescape($value);
3552: }
3553: return $value;
3554: }
3555:
3556:
1.107 albertel 3557: sub relative_to_absolute {
3558: my ($url,$output)=@_;
3559: my $parser=HTML::TokeParser->new(\$output);
3560: my $token;
3561: my $thisdir=$url;
3562: my @rlinks=();
3563: while ($token=$parser->get_token) {
3564: if ($token->[0] eq 'S') {
3565: if ($token->[1] eq 'a') {
3566: if ($token->[2]->{'href'}) {
3567: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3568: }
3569: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3570: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3571: } elsif ($token->[1] eq 'base') {
3572: $thisdir=$token->[2]->{'href'};
3573: }
3574: }
3575: }
3576: $thisdir=~s-/[^/]*$--;
1.356 albertel 3577: foreach my $link (@rlinks) {
1.726 raeburn 3578: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3579: ($link=~/^\//) ||
3580: ($link=~/^javascript:/i) ||
3581: ($link=~/^mailto:/i) ||
3582: ($link=~/^\#/)) {
3583: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3584: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3585: }
3586: }
3587: # -------------------------------------------------- Deal with Applet codebases
3588: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3589: return $output;
3590: }
3591:
1.112 bowersj2 3592: =pod
3593:
1.648 raeburn 3594: =item * &get_student_view()
1.112 bowersj2 3595:
3596: show a snapshot of what student was looking at
3597:
3598: =cut
3599:
1.10 albertel 3600: sub get_student_view {
1.186 albertel 3601: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3602: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3603: my (%form);
1.10 albertel 3604: my @elements=('symb','courseid','domain','username');
3605: foreach my $element (@elements) {
1.186 albertel 3606: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3607: }
1.186 albertel 3608: if (defined($moreenv)) {
3609: %form=(%form,%{$moreenv});
3610: }
1.236 albertel 3611: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3612: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3613: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3614: $userview=~s/\<body[^\>]*\>//gi;
3615: $userview=~s/\<\/body\>//gi;
3616: $userview=~s/\<html\>//gi;
3617: $userview=~s/\<\/html\>//gi;
3618: $userview=~s/\<head\>//gi;
3619: $userview=~s/\<\/head\>//gi;
3620: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3621: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3622: if (wantarray) {
3623: return ($userview,$response);
3624: } else {
3625: return $userview;
3626: }
3627: }
3628:
3629: sub get_student_view_with_retries {
3630: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3631:
3632: my $ok = 0; # True if we got a good response.
3633: my $content;
3634: my $response;
3635:
3636: # Try to get the student_view done. within the retries count:
3637:
3638: do {
3639: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3640: $ok = $response->is_success;
3641: if (!$ok) {
3642: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3643: }
3644: $retries--;
3645: } while (!$ok && ($retries > 0));
3646:
3647: if (!$ok) {
3648: $content = ''; # On error return an empty content.
3649: }
1.651 www 3650: if (wantarray) {
3651: return ($content, $response);
3652: } else {
3653: return $content;
3654: }
1.11 albertel 3655: }
3656:
1.112 bowersj2 3657: =pod
3658:
1.648 raeburn 3659: =item * &get_student_answers()
1.112 bowersj2 3660:
3661: show a snapshot of how student was answering problem
3662:
3663: =cut
3664:
1.11 albertel 3665: sub get_student_answers {
1.100 sakharuk 3666: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3667: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3668: my (%moreenv);
1.11 albertel 3669: my @elements=('symb','courseid','domain','username');
3670: foreach my $element (@elements) {
1.186 albertel 3671: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3672: }
1.186 albertel 3673: $moreenv{'grade_target'}='answer';
3674: %moreenv=(%form,%moreenv);
1.497 raeburn 3675: $feedurl = &Apache::lonnet::clutter($feedurl);
3676: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3677: return $userview;
1.1 albertel 3678: }
1.116 albertel 3679:
3680: =pod
3681:
3682: =item * &submlink()
3683:
1.242 albertel 3684: Inputs: $text $uname $udom $symb $target
1.116 albertel 3685:
3686: Returns: A link to grades.pm such as to see the SUBM view of a student
3687:
3688: =cut
3689:
3690: ###############################################
3691: sub submlink {
1.242 albertel 3692: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3693: if (!($uname && $udom)) {
3694: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3695: &Apache::lonnet::whichuser($symb);
1.116 albertel 3696: if (!$symb) { $symb=$cursymb; }
3697: }
1.254 matthew 3698: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3699: $symb=&escape($symb);
1.960 bisitz 3700: if ($target) { $target=" target=\"$target\""; }
3701: return
3702: '<a href="/adm/grades?command=submission'.
3703: '&symb='.$symb.
3704: '&student='.$uname.
3705: '&userdom='.$udom.'"'.
3706: $target.'>'.$text.'</a>';
1.242 albertel 3707: }
3708: ##############################################
3709:
3710: =pod
3711:
3712: =item * &pgrdlink()
3713:
3714: Inputs: $text $uname $udom $symb $target
3715:
3716: Returns: A link to grades.pm such as to see the PGRD view of a student
3717:
3718: =cut
3719:
3720: ###############################################
3721: sub pgrdlink {
3722: my $link=&submlink(@_);
3723: $link=~s/(&command=submission)/$1&showgrading=yes/;
3724: return $link;
3725: }
3726: ##############################################
3727:
3728: =pod
3729:
3730: =item * &pprmlink()
3731:
3732: Inputs: $text $uname $udom $symb $target
3733:
3734: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3735: student and a specific resource
1.242 albertel 3736:
3737: =cut
3738:
3739: ###############################################
3740: sub pprmlink {
3741: my ($text,$uname,$udom,$symb,$target)=@_;
3742: if (!($uname && $udom)) {
3743: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3744: &Apache::lonnet::whichuser($symb);
1.242 albertel 3745: if (!$symb) { $symb=$cursymb; }
3746: }
1.254 matthew 3747: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3748: $symb=&escape($symb);
1.242 albertel 3749: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3750: return '<a href="/adm/parmset?command=set&'.
3751: 'symb='.$symb.'&uname='.$uname.
3752: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3753: }
3754: ##############################################
1.37 matthew 3755:
1.112 bowersj2 3756: =pod
3757:
3758: =back
3759:
3760: =cut
3761:
1.37 matthew 3762: ###############################################
1.51 www 3763:
3764:
3765: sub timehash {
1.687 raeburn 3766: my ($thistime) = @_;
3767: my $timezone = &Apache::lonlocal::gettimezone();
3768: my $dt = DateTime->from_epoch(epoch => $thistime)
3769: ->set_time_zone($timezone);
3770: my $wday = $dt->day_of_week();
3771: if ($wday == 7) { $wday = 0; }
3772: return ( 'second' => $dt->second(),
3773: 'minute' => $dt->minute(),
3774: 'hour' => $dt->hour(),
3775: 'day' => $dt->day_of_month(),
3776: 'month' => $dt->month(),
3777: 'year' => $dt->year(),
3778: 'weekday' => $wday,
3779: 'dayyear' => $dt->day_of_year(),
3780: 'dlsav' => $dt->is_dst() );
1.51 www 3781: }
3782:
1.370 www 3783: sub utc_string {
3784: my ($date)=@_;
1.371 www 3785: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3786: }
3787:
1.51 www 3788: sub maketime {
3789: my %th=@_;
1.687 raeburn 3790: my ($epoch_time,$timezone,$dt);
3791: $timezone = &Apache::lonlocal::gettimezone();
3792: eval {
3793: $dt = DateTime->new( year => $th{'year'},
3794: month => $th{'month'},
3795: day => $th{'day'},
3796: hour => $th{'hour'},
3797: minute => $th{'minute'},
3798: second => $th{'second'},
3799: time_zone => $timezone,
3800: );
3801: };
3802: if (!$@) {
3803: $epoch_time = $dt->epoch;
3804: if ($epoch_time) {
3805: return $epoch_time;
3806: }
3807: }
1.51 www 3808: return POSIX::mktime(
3809: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3810: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3811: }
3812:
3813: #########################################
1.51 www 3814:
3815: sub findallcourses {
1.482 raeburn 3816: my ($roles,$uname,$udom) = @_;
1.355 albertel 3817: my %roles;
3818: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3819: my %courses;
1.51 www 3820: my $now=time;
1.482 raeburn 3821: if (!defined($uname)) {
3822: $uname = $env{'user.name'};
3823: }
3824: if (!defined($udom)) {
3825: $udom = $env{'user.domain'};
3826: }
3827: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3828: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3829: if (!%roles) {
3830: %roles = (
3831: cc => 1,
1.907 raeburn 3832: co => 1,
1.482 raeburn 3833: in => 1,
3834: ep => 1,
3835: ta => 1,
3836: cr => 1,
3837: st => 1,
3838: );
3839: }
3840: foreach my $entry (keys(%roleshash)) {
3841: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3842: if ($trole =~ /^cr/) {
3843: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3844: } else {
3845: next if (!exists($roles{$trole}));
3846: }
3847: if ($tend) {
3848: next if ($tend < $now);
3849: }
3850: if ($tstart) {
3851: next if ($tstart > $now);
3852: }
3853: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3854: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3855: if ($secpart eq '') {
3856: ($cnum,$role) = split(/_/,$cnumpart);
3857: $sec = 'none';
3858: $realsec = '';
3859: } else {
3860: $cnum = $cnumpart;
3861: ($sec,$role) = split(/_/,$secpart);
3862: $realsec = $sec;
1.490 raeburn 3863: }
1.482 raeburn 3864: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3865: }
3866: } else {
3867: foreach my $key (keys(%env)) {
1.483 albertel 3868: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3869: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3870: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3871: next if ($role eq 'ca' || $role eq 'aa');
3872: next if (%roles && !exists($roles{$role}));
3873: my ($starttime,$endtime)=split(/\./,$env{$key});
3874: my $active=1;
3875: if ($starttime) {
3876: if ($now<$starttime) { $active=0; }
3877: }
3878: if ($endtime) {
3879: if ($now>$endtime) { $active=0; }
3880: }
3881: if ($active) {
3882: if ($sec eq '') {
3883: $sec = 'none';
3884: }
3885: $courses{$cdom.'_'.$cnum}{$sec} =
3886: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3887: }
3888: }
1.51 www 3889: }
3890: }
1.474 raeburn 3891: return %courses;
1.51 www 3892: }
1.37 matthew 3893:
1.54 www 3894: ###############################################
1.474 raeburn 3895:
3896: sub blockcheck {
1.482 raeburn 3897: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3898:
3899: if (!defined($udom)) {
3900: $udom = $env{'user.domain'};
3901: }
3902: if (!defined($uname)) {
3903: $uname = $env{'user.name'};
3904: }
3905:
3906: # If uname and udom are for a course, check for blocks in the course.
3907:
3908: if (&Apache::lonnet::is_course($udom,$uname)) {
3909: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3910: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3911: return ($startblock,$endblock);
3912: }
1.474 raeburn 3913:
1.502 raeburn 3914: my $startblock = 0;
3915: my $endblock = 0;
1.482 raeburn 3916: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3917:
1.490 raeburn 3918: # If uname is for a user, and activity is course-specific, i.e.,
3919: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3920:
1.490 raeburn 3921: if (($activity eq 'boards' || $activity eq 'chat' ||
3922: $activity eq 'groups') && ($env{'request.course.id'})) {
3923: foreach my $key (keys(%live_courses)) {
3924: if ($key ne $env{'request.course.id'}) {
3925: delete($live_courses{$key});
3926: }
3927: }
3928: }
3929:
3930: my $otheruser = 0;
3931: my %own_courses;
3932: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3933: # Resource belongs to user other than current user.
3934: $otheruser = 1;
3935: # Gather courses for current user
3936: %own_courses =
3937: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3938: }
3939:
3940: # Gather active course roles - course coordinator, instructor,
3941: # exam proctor, ta, student, or custom role.
1.474 raeburn 3942:
3943: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3944: my ($cdom,$cnum);
3945: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3946: $cdom = $env{'course.'.$course.'.domain'};
3947: $cnum = $env{'course.'.$course.'.num'};
3948: } else {
1.490 raeburn 3949: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3950: }
3951: my $no_ownblock = 0;
3952: my $no_userblock = 0;
1.533 raeburn 3953: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3954: # Check if current user has 'evb' priv for this
3955: if (defined($own_courses{$course})) {
3956: foreach my $sec (keys(%{$own_courses{$course}})) {
3957: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3958: if ($sec ne 'none') {
3959: $checkrole .= '/'.$sec;
3960: }
3961: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3962: $no_ownblock = 1;
3963: last;
3964: }
3965: }
3966: }
3967: # if they have 'evb' priv and are currently not playing student
3968: next if (($no_ownblock) &&
3969: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3970: }
1.474 raeburn 3971: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3972: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3973: if ($sec ne 'none') {
1.482 raeburn 3974: $checkrole .= '/'.$sec;
1.474 raeburn 3975: }
1.490 raeburn 3976: if ($otheruser) {
3977: # Resource belongs to user other than current user.
3978: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3979: my ($trole,$tdom,$tnum,$tsec);
3980: my $entry = $live_courses{$course}{$sec};
3981: if ($entry =~ /^cr/) {
3982: ($trole,$tdom,$tnum,$tsec) =
3983: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3984: } else {
3985: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3986: }
3987: my ($spec,$area,$trest,%allroles,%userroles);
3988: $area = '/'.$tdom.'/'.$tnum;
3989: $trest = $tnum;
3990: if ($tsec ne '') {
3991: $area .= '/'.$tsec;
3992: $trest .= '/'.$tsec;
3993: }
3994: $spec = $trole.'.'.$area;
3995: if ($trole =~ /^cr/) {
3996: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3997: $tdom,$spec,$trest,$area);
3998: } else {
3999: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4000: $tdom,$spec,$trest,$area);
4001: }
4002: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4003: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4004: if ($1) {
4005: $no_userblock = 1;
4006: last;
4007: }
4008: }
1.490 raeburn 4009: } else {
4010: # Resource belongs to current user
4011: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4012: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4013: $no_ownblock = 1;
4014: last;
4015: }
1.474 raeburn 4016: }
4017: }
4018: # if they have the evb priv and are currently not playing student
1.482 raeburn 4019: next if (($no_ownblock) &&
1.491 albertel 4020: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4021: next if ($no_userblock);
1.474 raeburn 4022:
1.866 kalberla 4023: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4024: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4025:
4026: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4027: if (($start != 0) &&
4028: (($startblock == 0) || ($startblock > $start))) {
4029: $startblock = $start;
4030: }
4031: if (($end != 0) &&
4032: (($endblock == 0) || ($endblock < $end))) {
4033: $endblock = $end;
4034: }
1.490 raeburn 4035: }
4036: return ($startblock,$endblock);
4037: }
4038:
4039: sub get_blocks {
4040: my ($setters,$activity,$cdom,$cnum) = @_;
4041: my $startblock = 0;
4042: my $endblock = 0;
4043: my $course = $cdom.'_'.$cnum;
4044: $setters->{$course} = {};
4045: $setters->{$course}{'staff'} = [];
4046: $setters->{$course}{'times'} = [];
4047: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4048: foreach my $record (keys(%records)) {
4049: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4050: if ($start <= time && $end >= time) {
4051: my ($staff_name,$staff_dom,$title,$blocks) =
4052: &parse_block_record($records{$record});
4053: if ($blocks->{$activity} eq 'on') {
4054: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4055: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4056: if ( ($startblock == 0) || ($startblock > $start) ) {
4057: $startblock = $start;
1.490 raeburn 4058: }
1.491 albertel 4059: if ( ($endblock == 0) || ($endblock < $end) ) {
4060: $endblock = $end;
1.474 raeburn 4061: }
4062: }
4063: }
4064: }
4065: return ($startblock,$endblock);
4066: }
4067:
4068: sub parse_block_record {
4069: my ($record) = @_;
4070: my ($setuname,$setudom,$title,$blocks);
4071: if (ref($record) eq 'HASH') {
4072: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4073: $title = &unescape($record->{'event'});
4074: $blocks = $record->{'blocks'};
4075: } else {
4076: my @data = split(/:/,$record,3);
4077: if (scalar(@data) eq 2) {
4078: $title = $data[1];
4079: ($setuname,$setudom) = split(/@/,$data[0]);
4080: } else {
4081: ($setuname,$setudom,$title) = @data;
4082: }
4083: $blocks = { 'com' => 'on' };
4084: }
4085: return ($setuname,$setudom,$title,$blocks);
4086: }
4087:
1.854 kalberla 4088: sub blocking_status {
4089: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4090: my %setters;
1.890 droeschl 4091:
4092: # check for active blocking
1.867 kalberla 4093: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4094:
1.890 droeschl 4095: my $blocked = $startblock && $endblock ? 1 : 0;
4096:
4097: # caller just wants to know whether a block is active
4098: if (!wantarray) { return $blocked; }
4099:
4100: # build a link to a popup window containing the details
4101: my $querystring = "?activity=$activity";
4102: # $uname and $udom decide whose portfolio the user is trying to look at
4103: $querystring .= "&udom=$udom" if $udom;
4104: $querystring .= "&uname=$uname" if $uname;
4105:
4106: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4107: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4108: var options = "width=" + w + ",height=" + h + ",";
4109: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4110: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4111: var newWin = window.open(url, wdwName, options);
4112: newWin.focus();
4113: }
1.890 droeschl 4114: END_MYBLOCK
1.854 kalberla 4115:
1.890 droeschl 4116: $output = Apache::lonhtmlcommon::scripttag($output);
4117:
1.854 kalberla 4118: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4119: my $text = mt('Communication Blocked');
4120:
1.867 kalberla 4121: $output .= <<"END_BLOCK";
4122: <div class='LC_comblock'>
1.869 kalberla 4123: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4124: title='$text'>
4125: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4126: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4127: title='$text'>$text</a>
1.867 kalberla 4128: </div>
4129:
4130: END_BLOCK
1.474 raeburn 4131:
1.854 kalberla 4132: return ($blocked, $output);
4133: }
1.490 raeburn 4134:
1.60 matthew 4135: ###############################################
4136:
1.682 raeburn 4137: sub check_ip_acc {
4138: my ($acc)=@_;
4139: &Apache::lonxml::debug("acc is $acc");
4140: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4141: return 1;
4142: }
4143: my $allowed=0;
4144: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4145:
4146: my $name;
4147: foreach my $pattern (split(',',$acc)) {
4148: $pattern =~ s/^\s*//;
4149: $pattern =~ s/\s*$//;
4150: if ($pattern =~ /\*$/) {
4151: #35.8.*
4152: $pattern=~s/\*//;
4153: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4154: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4155: #35.8.3.[34-56]
4156: my $low=$2;
4157: my $high=$3;
4158: $pattern=$1;
4159: if ($ip =~ /^\Q$pattern\E/) {
4160: my $last=(split(/\./,$ip))[3];
4161: if ($last <=$high && $last >=$low) { $allowed=1; }
4162: }
4163: } elsif ($pattern =~ /^\*/) {
4164: #*.msu.edu
4165: $pattern=~s/\*//;
4166: if (!defined($name)) {
4167: use Socket;
4168: my $netaddr=inet_aton($ip);
4169: ($name)=gethostbyaddr($netaddr,AF_INET);
4170: }
4171: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4172: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4173: #127.0.0.1
4174: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4175: } else {
4176: #some.name.com
4177: if (!defined($name)) {
4178: use Socket;
4179: my $netaddr=inet_aton($ip);
4180: ($name)=gethostbyaddr($netaddr,AF_INET);
4181: }
4182: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4183: }
4184: if ($allowed) { last; }
4185: }
4186: return $allowed;
4187: }
4188:
4189: ###############################################
4190:
1.60 matthew 4191: =pod
4192:
1.112 bowersj2 4193: =head1 Domain Template Functions
4194:
4195: =over 4
4196:
4197: =item * &determinedomain()
1.60 matthew 4198:
4199: Inputs: $domain (usually will be undef)
4200:
1.63 www 4201: Returns: Determines which domain should be used for designs
1.60 matthew 4202:
4203: =cut
1.54 www 4204:
1.60 matthew 4205: ###############################################
1.63 www 4206: sub determinedomain {
4207: my $domain=shift;
1.531 albertel 4208: if (! $domain) {
1.60 matthew 4209: # Determine domain if we have not been given one
1.893 raeburn 4210: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4211: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4212: if ($env{'request.role.domain'}) {
4213: $domain=$env{'request.role.domain'};
1.60 matthew 4214: }
4215: }
1.63 www 4216: return $domain;
4217: }
4218: ###############################################
1.517 raeburn 4219:
1.518 albertel 4220: sub devalidate_domconfig_cache {
4221: my ($udom)=@_;
4222: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4223: }
4224:
4225: # ---------------------- Get domain configuration for a domain
4226: sub get_domainconf {
4227: my ($udom) = @_;
4228: my $cachetime=1800;
4229: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4230: if (defined($cached)) { return %{$result}; }
4231:
4232: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4233: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4234: my (%designhash,%legacy);
1.518 albertel 4235: if (keys(%domconfig) > 0) {
4236: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4237: if (keys(%{$domconfig{'login'}})) {
4238: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4239: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4240: if ($key eq 'loginvia') {
4241: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4242: my @ids = &Apache::lonnet::current_machine_ids();
4243: foreach my $hostname (@ids) {
1.948 raeburn 4244: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4245: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4246: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4247: $designhash{$udom.'.login.loginvia'} = $server;
4248: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4249:
4250: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4251: } else {
4252: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4253: }
4254: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4255: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4256: }
1.946 raeburn 4257: }
4258: }
4259: }
4260: }
4261: } else {
4262: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4263: $designhash{$udom.'.login.'.$key.'_'.$img} =
4264: $domconfig{'login'}{$key}{$img};
4265: }
1.699 raeburn 4266: }
4267: } else {
4268: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4269: }
1.632 raeburn 4270: }
4271: } else {
4272: $legacy{'login'} = 1;
1.518 albertel 4273: }
1.632 raeburn 4274: } else {
4275: $legacy{'login'} = 1;
1.518 albertel 4276: }
4277: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4278: if (keys(%{$domconfig{'rolecolors'}})) {
4279: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4280: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4281: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4282: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4283: }
1.518 albertel 4284: }
4285: }
1.632 raeburn 4286: } else {
4287: $legacy{'rolecolors'} = 1;
1.518 albertel 4288: }
1.632 raeburn 4289: } else {
4290: $legacy{'rolecolors'} = 1;
1.518 albertel 4291: }
1.948 raeburn 4292: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4293: if ($domconfig{'autoenroll'}{'co-owners'}) {
4294: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4295: }
4296: }
1.632 raeburn 4297: if (keys(%legacy) > 0) {
4298: my %legacyhash = &get_legacy_domconf($udom);
4299: foreach my $item (keys(%legacyhash)) {
4300: if ($item =~ /^\Q$udom\E\.login/) {
4301: if ($legacy{'login'}) {
4302: $designhash{$item} = $legacyhash{$item};
4303: }
4304: } else {
4305: if ($legacy{'rolecolors'}) {
4306: $designhash{$item} = $legacyhash{$item};
4307: }
1.518 albertel 4308: }
4309: }
4310: }
1.632 raeburn 4311: } else {
4312: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4313: }
4314: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4315: $cachetime);
4316: return %designhash;
4317: }
4318:
1.632 raeburn 4319: sub get_legacy_domconf {
4320: my ($udom) = @_;
4321: my %legacyhash;
4322: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4323: my $designfile = $designdir.'/'.$udom.'.tab';
4324: if (-e $designfile) {
4325: if ( open (my $fh,"<$designfile") ) {
4326: while (my $line = <$fh>) {
4327: next if ($line =~ /^\#/);
4328: chomp($line);
4329: my ($key,$val)=(split(/\=/,$line));
4330: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4331: }
4332: close($fh);
4333: }
4334: }
4335: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4336: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4337: }
4338: return %legacyhash;
4339: }
4340:
1.63 www 4341: =pod
4342:
1.112 bowersj2 4343: =item * &domainlogo()
1.63 www 4344:
4345: Inputs: $domain (usually will be undef)
4346:
4347: Returns: A link to a domain logo, if the domain logo exists.
4348: If the domain logo does not exist, a description of the domain.
4349:
4350: =cut
1.112 bowersj2 4351:
1.63 www 4352: ###############################################
4353: sub domainlogo {
1.517 raeburn 4354: my $domain = &determinedomain(shift);
1.518 albertel 4355: my %designhash = &get_domainconf($domain);
1.517 raeburn 4356: # See if there is a logo
4357: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4358: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4359: if ($imgsrc =~ m{^/(adm|res)/}) {
4360: if ($imgsrc =~ m{^/res/}) {
4361: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4362: &Apache::lonnet::repcopy($local_name);
4363: }
4364: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4365: }
4366: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4367: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4368: return &Apache::lonnet::domain($domain,'description');
1.59 www 4369: } else {
1.60 matthew 4370: return '';
1.59 www 4371: }
4372: }
1.63 www 4373: ##############################################
4374:
4375: =pod
4376:
1.112 bowersj2 4377: =item * &designparm()
1.63 www 4378:
4379: Inputs: $which parameter; $domain (usually will be undef)
4380:
4381: Returns: value of designparamter $which
4382:
4383: =cut
1.112 bowersj2 4384:
1.397 albertel 4385:
1.400 albertel 4386: ##############################################
1.397 albertel 4387: sub designparm {
4388: my ($which,$domain)=@_;
4389: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4390: return $env{'environment.color.'.$which};
1.96 www 4391: }
1.63 www 4392: $domain=&determinedomain($domain);
1.518 albertel 4393: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4394: my $output;
1.517 raeburn 4395: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4396: $output = $domdesign{$domain.'.'.$which};
1.63 www 4397: } else {
1.520 raeburn 4398: $output = $defaultdesign{$which};
4399: }
4400: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4401: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4402: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4403: if ($output =~ m{^/res/}) {
4404: my $local_name = &Apache::lonnet::filelocation('',$output);
4405: &Apache::lonnet::repcopy($local_name);
4406: }
1.520 raeburn 4407: $output = &lonhttpdurl($output);
4408: }
1.63 www 4409: }
1.520 raeburn 4410: return $output;
1.63 www 4411: }
1.59 www 4412:
1.822 bisitz 4413: ##############################################
4414: =pod
4415:
1.832 bisitz 4416: =item * &authorspace()
4417:
4418: Inputs: ./.
4419:
4420: Returns: Path to the Construction Space of the current user's
4421: accessed author space
4422: The author space will be that of the current user
4423: when accessing the own author space
4424: and that of the co-author/assistent co-author
4425: when accessing the co-author's/assistent co-author's
4426: space
4427:
4428: =cut
4429:
4430: sub authorspace {
4431: my $caname = '';
4432: if ($env{'request.role'} =~ /^ca|^aa/) {
4433: (undef,$caname) =
4434: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4435: } else {
4436: $caname = $env{'user.name'};
4437: }
4438: return '/priv/'.$caname.'/';
4439: }
4440:
4441: ##############################################
4442: =pod
4443:
1.822 bisitz 4444: =item * &head_subbox()
4445:
4446: Inputs: $content (contains HTML code with page functions, etc.)
4447:
4448: Returns: HTML div with $content
4449: To be included in page header
4450:
4451: =cut
4452:
4453: sub head_subbox {
4454: my ($content)=@_;
4455: my $output =
1.844 bisitz 4456: '<div id="LC_head_subbox">'
1.822 bisitz 4457: .$content
4458: .'</div>'
4459: }
4460:
4461: ##############################################
4462: =pod
4463:
4464: =item * &CSTR_pageheader()
4465:
4466: Inputs: ./.
4467:
4468: Returns: HTML div with CSTR path and recent box
4469: To be included on Construction Space pages
4470:
4471: =cut
4472:
4473: sub CSTR_pageheader {
4474: # this is for resources; directories have customtitle, and crumbs
4475: # and select recent are created in lonpubdir.pm
4476: my ($uname,$thisdisfn)=
4477: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4478: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4479: $formaction=~s/\/+/\//g;
4480:
4481: my $parentpath = '';
4482: my $lastitem = '';
4483: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4484: $parentpath = $1;
4485: $lastitem = $2;
4486: } else {
4487: $lastitem = $thisdisfn;
4488: }
1.921 bisitz 4489:
4490: my $output =
1.822 bisitz 4491: '<div>'
4492: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4493: .'<b>'.&mt('Construction Space:').'</b> '
4494: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4495: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4496: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4497:
4498: if ($lastitem) {
4499: $output .=
4500: '<span class="LC_filename">'
4501: .$lastitem
4502: .'</span>';
4503: }
4504: $output .=
4505: '<br />'
1.822 bisitz 4506: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4507: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4508: .'</form>'
4509: .&Apache::lonmenu::constspaceform()
4510: .'</div>';
1.921 bisitz 4511:
4512: return $output;
1.822 bisitz 4513: }
4514:
1.60 matthew 4515: ###############################################
4516: ###############################################
4517:
4518: =pod
4519:
1.112 bowersj2 4520: =back
4521:
1.549 albertel 4522: =head1 HTML Helpers
1.112 bowersj2 4523:
4524: =over 4
4525:
4526: =item * &bodytag()
1.60 matthew 4527:
4528: Returns a uniform header for LON-CAPA web pages.
4529:
4530: Inputs:
4531:
1.112 bowersj2 4532: =over 4
4533:
4534: =item * $title, A title to be displayed on the page.
4535:
4536: =item * $function, the current role (can be undef).
4537:
4538: =item * $addentries, extra parameters for the <body> tag.
4539:
4540: =item * $bodyonly, if defined, only return the <body> tag.
4541:
4542: =item * $domain, if defined, force a given domain.
4543:
4544: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4545: text interface only)
1.60 matthew 4546:
1.814 bisitz 4547: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4548: navigational links
1.317 albertel 4549:
1.338 albertel 4550: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4551:
1.460 albertel 4552: =item * $args, optional argument valid values are
4553: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4554: inherit_jsmath -> when creating popup window in a page,
4555: should it have jsmath forced on by the
4556: current page
1.460 albertel 4557:
1.112 bowersj2 4558: =back
4559:
1.60 matthew 4560: Returns: A uniform header for LON-CAPA web pages.
4561: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4562: If $bodyonly is undef or zero, an html string containing a <body> tag and
4563: other decorations will be returned.
4564:
4565: =cut
4566:
1.54 www 4567: sub bodytag {
1.831 bisitz 4568: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962 droeschl 4569: $no_nav_bar,$bgcolor,$args)=@_;
1.339 albertel 4570:
1.954 raeburn 4571: my $public;
4572: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4573: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4574: $public = 1;
4575: }
1.460 albertel 4576: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4577:
1.183 matthew 4578: $function = &get_users_function() if (!$function);
1.339 albertel 4579: my $img = &designparm($function.'.img',$domain);
4580: my $font = &designparm($function.'.font',$domain);
4581: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4582:
1.803 bisitz 4583: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4584: 'bgcolor' => $pgbg,
1.339 albertel 4585: 'text' => $font,
4586: 'alink' => &designparm($function.'.alink',$domain),
4587: 'vlink' => &designparm($function.'.vlink',$domain),
4588: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4589: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4590:
1.63 www 4591: # role and realm
1.378 raeburn 4592: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4593: if ($role eq 'ca') {
1.479 albertel 4594: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4595: $realm = &plainname($rname,$rdom);
1.378 raeburn 4596: }
1.55 www 4597: # realm
1.258 albertel 4598: if ($env{'request.course.id'}) {
1.378 raeburn 4599: if ($env{'request.role'} !~ /^cr/) {
4600: $role = &Apache::lonnet::plaintext($role,&course_type());
4601: }
1.898 raeburn 4602: if ($env{'request.course.sec'}) {
4603: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4604: }
1.359 albertel 4605: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4606: } else {
4607: $role = &Apache::lonnet::plaintext($role);
1.54 www 4608: }
1.433 albertel 4609:
1.359 albertel 4610: if (!$realm) { $realm=' '; }
1.330 albertel 4611:
1.438 albertel 4612: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4613:
1.101 www 4614: # construct main body tag
1.359 albertel 4615: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4616: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4617:
1.530 albertel 4618: if ($bodyonly) {
1.60 matthew 4619: return $bodytag;
1.798 tempelho 4620: }
1.359 albertel 4621:
1.410 albertel 4622: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 4623: if ($public) {
1.433 albertel 4624: undef($role);
1.434 albertel 4625: } else {
4626: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4627: }
1.359 albertel 4628:
1.762 bisitz 4629: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4630: #
4631: # Extra info if you are the DC
4632: my $dc_info = '';
4633: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4634: $env{'course.'.$env{'request.course.id'}.
4635: '.domain'}.'/'})) {
4636: my $cid = $env{'request.course.id'};
1.917 raeburn 4637: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4638: $dc_info =~ s/\s+$//;
1.359 albertel 4639: }
4640:
1.898 raeburn 4641: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4642: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4643:
1.916 droeschl 4644: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4645: return $bodytag;
4646: }
1.903 droeschl 4647:
4648: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4649:
4650: # if ($env{'request.state'} eq 'construct') {
4651: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4652: # }
4653:
1.359 albertel 4654:
4655:
1.916 droeschl 4656: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4657: if ($dc_info) {
4658: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4659: }
1.916 droeschl 4660: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4661: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4662: return $bodytag;
4663: }
1.894 droeschl 4664:
1.927 raeburn 4665: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4666: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4667: }
1.916 droeschl 4668:
1.903 droeschl 4669: $bodytag .= Apache::lonhtmlcommon::scripttag(
4670: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4671:
1.903 droeschl 4672: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4673:
1.917 raeburn 4674: if ($dc_info) {
4675: $dc_info = &dc_courseid_toggle($dc_info);
4676: }
4677: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4678:
1.903 droeschl 4679: #don't show menus for public users
1.954 raeburn 4680: if (!$public){
1.903 droeschl 4681: $bodytag .= Apache::lonmenu::secondary_menu();
4682: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4683: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4684: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 4685: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 4686: $args->{'bread_crumbs'});
4687: } elsif ($forcereg) {
4688: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4689: }
1.903 droeschl 4690: }else{
4691: # this is to seperate menu from content when there's no secondary
4692: # menu. Especially needed for public accessible ressources.
4693: $bodytag .= '<hr style="clear:both" />';
4694: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4695: }
1.903 droeschl 4696:
1.235 raeburn 4697: return $bodytag;
1.182 matthew 4698: }
4699:
1.917 raeburn 4700: sub dc_courseid_toggle {
4701: my ($dc_info) = @_;
4702: return ' <span id="dccidtext" class="LC_cusr_subheading">'.
4703: '<a href="javascript:showCourseID();">'.
4704: &mt('(More ...)').'</a></span>'.
4705: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4706: }
4707:
1.330 albertel 4708: sub make_attr_string {
4709: my ($register,$attr_ref) = @_;
4710:
4711: if ($attr_ref && !ref($attr_ref)) {
4712: die("addentries Must be a hash ref ".
4713: join(':',caller(1))." ".
4714: join(':',caller(0))." ");
4715: }
4716:
4717: if ($register) {
1.339 albertel 4718: my ($on_load,$on_unload);
4719: foreach my $key (keys(%{$attr_ref})) {
4720: if (lc($key) eq 'onload') {
4721: $on_load.=$attr_ref->{$key}.';';
4722: delete($attr_ref->{$key});
4723:
4724: } elsif (lc($key) eq 'onunload') {
4725: $on_unload.=$attr_ref->{$key}.';';
4726: delete($attr_ref->{$key});
4727: }
4728: }
1.953 droeschl 4729: $attr_ref->{'onload'} = $on_load;
4730: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 4731: }
1.339 albertel 4732:
1.330 albertel 4733: my $attr_string;
4734: foreach my $attr (keys(%$attr_ref)) {
4735: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4736: }
4737: return $attr_string;
4738: }
4739:
4740:
1.182 matthew 4741: ###############################################
1.251 albertel 4742: ###############################################
4743:
4744: =pod
4745:
4746: =item * &endbodytag()
4747:
4748: Returns a uniform footer for LON-CAPA web pages.
4749:
1.635 raeburn 4750: Inputs: 1 - optional reference to an args hash
4751: If in the hash, key for noredirectlink has a value which evaluates to true,
4752: a 'Continue' link is not displayed if the page contains an
4753: internal redirect in the <head></head> section,
4754: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4755:
4756: =cut
4757:
4758: sub endbodytag {
1.635 raeburn 4759: my ($args) = @_;
1.251 albertel 4760: my $endbodytag='</body>';
1.269 albertel 4761: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4762: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4763: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4764: $endbodytag=
4765: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4766: &mt('Continue').'</a>'.
4767: $endbodytag;
4768: }
1.315 albertel 4769: }
1.251 albertel 4770: return $endbodytag;
4771: }
4772:
1.352 albertel 4773: =pod
4774:
4775: =item * &standard_css()
4776:
4777: Returns a style sheet
4778:
4779: Inputs: (all optional)
4780: domain -> force to color decorate a page for a specific
4781: domain
4782: function -> force usage of a specific rolish color scheme
4783: bgcolor -> override the default page bgcolor
4784:
4785: =cut
4786:
1.343 albertel 4787: sub standard_css {
1.345 albertel 4788: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4789: $function = &get_users_function() if (!$function);
4790: my $img = &designparm($function.'.img', $domain);
4791: my $tabbg = &designparm($function.'.tabbg', $domain);
4792: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4793: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4794: #second colour for later usage
1.345 albertel 4795: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4796: my $pgbg_or_bgcolor =
4797: $bgcolor ||
1.352 albertel 4798: &designparm($function.'.pgbg', $domain);
1.382 albertel 4799: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4800: my $alink = &designparm($function.'.alink', $domain);
4801: my $vlink = &designparm($function.'.vlink', $domain);
4802: my $link = &designparm($function.'.link', $domain);
4803:
1.602 albertel 4804: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4805: my $mono = 'monospace';
1.850 bisitz 4806: my $data_table_head = $sidebg;
4807: my $data_table_light = '#FAFAFA';
4808: my $data_table_dark = '#F0F0F0';
1.470 banghart 4809: my $data_table_darker = '#CCCCCC';
1.349 albertel 4810: my $data_table_highlight = '#FFFF00';
1.352 albertel 4811: my $mail_new = '#FFBB77';
4812: my $mail_new_hover = '#DD9955';
4813: my $mail_read = '#BBBB77';
4814: my $mail_read_hover = '#999944';
4815: my $mail_replied = '#AAAA88';
4816: my $mail_replied_hover = '#888855';
4817: my $mail_other = '#99BBBB';
4818: my $mail_other_hover = '#669999';
1.391 albertel 4819: my $table_header = '#DDDDDD';
1.489 raeburn 4820: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4821: my $lg_border_color = '#C8C8C8';
1.952 onken 4822: my $button_hover = '#BF2317';
1.392 albertel 4823:
1.608 albertel 4824: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4825: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4826: : '0 3px 0 4px';
1.448 albertel 4827:
1.523 albertel 4828:
1.343 albertel 4829: return <<END;
1.947 droeschl 4830:
4831: /* needed for iframe to allow 100% height in FF */
4832: body, html {
4833: margin: 0;
4834: padding: 0 0.5%;
4835: height: 99%; /* to avoid scrollbars */
4836: }
4837:
1.795 www 4838: body {
1.911 bisitz 4839: font-family: $sans;
4840: line-height:130%;
4841: font-size:0.83em;
4842: color:$font;
1.795 www 4843: }
4844:
1.959 onken 4845: a:focus,
4846: a:focus img {
1.795 www 4847: color: red;
1.911 bisitz 4848: background: yellow;
1.795 www 4849: }
1.698 harmsja 4850:
1.911 bisitz 4851: form, .inline {
4852: display: inline;
1.795 www 4853: }
1.721 harmsja 4854:
1.795 www 4855: .LC_right {
1.911 bisitz 4856: text-align:right;
1.795 www 4857: }
4858:
4859: .LC_middle {
1.911 bisitz 4860: vertical-align:middle;
1.795 www 4861: }
1.721 harmsja 4862:
1.911 bisitz 4863: .LC_400Box {
4864: width:400px;
4865: }
1.721 harmsja 4866:
1.947 droeschl 4867: .LC_iframecontainer {
4868: width: 98%;
4869: margin: 0;
4870: position: fixed;
4871: top: 8.5em;
4872: bottom: 0;
4873: }
4874:
4875: .LC_iframecontainer iframe{
4876: border: none;
4877: width: 100%;
4878: height: 100%;
4879: }
4880:
1.778 bisitz 4881: .LC_filename {
4882: font-family: $mono;
4883: white-space:pre;
1.921 bisitz 4884: font-size: 120%;
1.778 bisitz 4885: }
4886:
4887: .LC_fileicon {
4888: border: none;
4889: height: 1.3em;
4890: vertical-align: text-bottom;
4891: margin-right: 0.3em;
4892: text-decoration:none;
4893: }
4894:
1.350 albertel 4895: .LC_error {
4896: color: red;
4897: font-size: larger;
4898: }
1.795 www 4899:
1.457 albertel 4900: .LC_warning,
4901: .LC_diff_removed {
1.733 bisitz 4902: color: red;
1.394 albertel 4903: }
1.532 albertel 4904:
4905: .LC_info,
1.457 albertel 4906: .LC_success,
4907: .LC_diff_added {
1.350 albertel 4908: color: green;
4909: }
1.795 www 4910:
1.802 bisitz 4911: div.LC_confirm_box {
4912: background-color: #FAFAFA;
4913: border: 1px solid $lg_border_color;
4914: margin-right: 0;
4915: padding: 5px;
4916: }
4917:
4918: div.LC_confirm_box .LC_error img,
4919: div.LC_confirm_box .LC_success img {
4920: vertical-align: middle;
4921: }
4922:
1.440 albertel 4923: .LC_icon {
1.771 droeschl 4924: border: none;
1.790 droeschl 4925: vertical-align: middle;
1.771 droeschl 4926: }
4927:
1.543 albertel 4928: .LC_docs_spacer {
4929: width: 25px;
4930: height: 1px;
1.771 droeschl 4931: border: none;
1.543 albertel 4932: }
1.346 albertel 4933:
1.532 albertel 4934: .LC_internal_info {
1.735 bisitz 4935: color: #999999;
1.532 albertel 4936: }
4937:
1.794 www 4938: .LC_discussion {
1.911 bisitz 4939: background: $tabbg;
4940: border: 1px solid black;
4941: margin: 2px;
1.794 www 4942: }
4943:
4944: .LC_disc_action_links_bar {
1.911 bisitz 4945: background: $tabbg;
4946: border: none;
4947: margin: 4px;
1.794 www 4948: }
4949:
4950: .LC_disc_action_left {
1.911 bisitz 4951: text-align: left;
1.794 www 4952: }
4953:
4954: .LC_disc_action_right {
1.911 bisitz 4955: text-align: right;
1.794 www 4956: }
4957:
4958: .LC_disc_new_item {
1.911 bisitz 4959: background: white;
4960: border: 2px solid red;
4961: margin: 2px;
1.794 www 4962: }
4963:
4964: .LC_disc_old_item {
1.911 bisitz 4965: background: white;
4966: border: 1px solid black;
4967: margin: 2px;
1.794 www 4968: }
4969:
1.458 albertel 4970: table.LC_pastsubmission {
4971: border: 1px solid black;
4972: margin: 2px;
4973: }
4974:
1.924 bisitz 4975: table#LC_menubuttons {
1.345 albertel 4976: width: 100%;
4977: background: $pgbg;
1.392 albertel 4978: border: 2px;
1.402 albertel 4979: border-collapse: separate;
1.803 bisitz 4980: padding: 0;
1.345 albertel 4981: }
1.392 albertel 4982:
1.801 tempelho 4983: table#LC_title_bar a {
4984: color: $fontmenu;
4985: }
1.836 bisitz 4986:
1.807 droeschl 4987: table#LC_title_bar {
1.819 tempelho 4988: clear: both;
1.836 bisitz 4989: display: none;
1.807 droeschl 4990: }
4991:
1.795 www 4992: table#LC_title_bar,
1.933 droeschl 4993: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 4994: table#LC_title_bar.LC_with_remote {
1.359 albertel 4995: width: 100%;
1.392 albertel 4996: border-color: $pgbg;
4997: border-style: solid;
4998: border-width: $border;
1.379 albertel 4999: background: $pgbg;
1.801 tempelho 5000: color: $fontmenu;
1.392 albertel 5001: border-collapse: collapse;
1.803 bisitz 5002: padding: 0;
1.819 tempelho 5003: margin: 0;
1.359 albertel 5004: }
1.795 www 5005:
1.933 droeschl 5006: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5007: margin: 0;
5008: padding: 0;
1.933 droeschl 5009: position: relative;
5010: list-style: none;
1.913 droeschl 5011: }
1.933 droeschl 5012: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5013: display: inline;
5014: }
1.933 droeschl 5015:
5016: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5017: padding: 0;
1.933 droeschl 5018: margin: 0;
5019: float: left;
1.913 droeschl 5020: }
1.933 droeschl 5021: .LC_breadcrumb_tools_tools {
5022: padding: 0;
5023: margin: 0;
1.913 droeschl 5024: float: right;
5025: }
5026:
1.359 albertel 5027: table#LC_title_bar td {
5028: background: $tabbg;
5029: }
1.795 www 5030:
1.911 bisitz 5031: table#LC_menubuttons img {
1.803 bisitz 5032: border: none;
1.346 albertel 5033: }
1.795 www 5034:
1.842 droeschl 5035: .LC_breadcrumbs_component {
1.911 bisitz 5036: float: right;
5037: margin: 0 1em;
1.357 albertel 5038: }
1.842 droeschl 5039: .LC_breadcrumbs_component img {
1.911 bisitz 5040: vertical-align: middle;
1.777 tempelho 5041: }
1.795 www 5042:
1.383 albertel 5043: td.LC_table_cell_checkbox {
5044: text-align: center;
5045: }
1.795 www 5046:
5047: .LC_fontsize_small {
1.911 bisitz 5048: font-size: 70%;
1.705 tempelho 5049: }
5050:
1.844 bisitz 5051: #LC_breadcrumbs {
1.911 bisitz 5052: clear:both;
5053: background: $sidebg;
5054: border-bottom: 1px solid $lg_border_color;
5055: line-height: 2.5em;
1.933 droeschl 5056: overflow: hidden;
1.911 bisitz 5057: margin: 0;
5058: padding: 0;
1.819 tempelho 5059: }
1.862 bisitz 5060:
1.844 bisitz 5061: #LC_head_subbox {
1.911 bisitz 5062: clear:both;
5063: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5064: border: 1px solid $sidebg;
5065: margin: 0 0 10px 0;
1.966 bisitz 5066: padding: 3px;
1.822 bisitz 5067: }
5068:
1.795 www 5069: .LC_fontsize_medium {
1.911 bisitz 5070: font-size: 85%;
1.705 tempelho 5071: }
5072:
1.795 www 5073: .LC_fontsize_large {
1.911 bisitz 5074: font-size: 120%;
1.705 tempelho 5075: }
5076:
1.346 albertel 5077: .LC_menubuttons_inline_text {
5078: color: $font;
1.698 harmsja 5079: font-size: 90%;
1.701 harmsja 5080: padding-left:3px;
1.346 albertel 5081: }
5082:
1.934 droeschl 5083: .LC_menubuttons_inline_text img{
5084: vertical-align: middle;
5085: }
5086:
1.951 onken 5087: li.LC_menubuttons_inline_text img,a {
5088: cursor:pointer;
5089: }
5090:
1.526 www 5091: .LC_menubuttons_link {
5092: text-decoration: none;
5093: }
1.795 www 5094:
1.522 albertel 5095: .LC_menubuttons_category {
1.521 www 5096: color: $font;
1.526 www 5097: background: $pgbg;
1.521 www 5098: font-size: larger;
5099: font-weight: bold;
5100: }
5101:
1.346 albertel 5102: td.LC_menubuttons_text {
1.911 bisitz 5103: color: $font;
1.346 albertel 5104: }
1.706 harmsja 5105:
1.346 albertel 5106: .LC_current_location {
5107: background: $tabbg;
5108: }
1.795 www 5109:
1.938 bisitz 5110: table.LC_data_table {
1.347 albertel 5111: border: 1px solid #000000;
1.402 albertel 5112: border-collapse: separate;
1.426 albertel 5113: border-spacing: 1px;
1.610 albertel 5114: background: $pgbg;
1.347 albertel 5115: }
1.795 www 5116:
1.422 albertel 5117: .LC_data_table_dense {
5118: font-size: small;
5119: }
1.795 www 5120:
1.507 raeburn 5121: table.LC_nested_outer {
5122: border: 1px solid #000000;
1.589 raeburn 5123: border-collapse: collapse;
1.803 bisitz 5124: border-spacing: 0;
1.507 raeburn 5125: width: 100%;
5126: }
1.795 www 5127:
1.879 raeburn 5128: table.LC_innerpickbox,
1.507 raeburn 5129: table.LC_nested {
1.803 bisitz 5130: border: none;
1.589 raeburn 5131: border-collapse: collapse;
1.803 bisitz 5132: border-spacing: 0;
1.507 raeburn 5133: width: 100%;
5134: }
1.795 www 5135:
1.930 faziophi 5136: .ui-accordion,
5137: .ui-accordion table.LC_data_table,
5138: .ui-accordion table.LC_nested_outer{
5139: border: 0px;
5140: border-spacing: 0px;
5141: margin: 3px;
5142: }
5143:
1.911 bisitz 5144: table.LC_data_table tr th,
5145: table.LC_calendar tr th,
1.879 raeburn 5146: table.LC_prior_tries tr th,
5147: table.LC_innerpickbox tr th {
1.349 albertel 5148: font-weight: bold;
5149: background-color: $data_table_head;
1.801 tempelho 5150: color:$fontmenu;
1.701 harmsja 5151: font-size:90%;
1.347 albertel 5152: }
1.795 www 5153:
1.879 raeburn 5154: table.LC_innerpickbox tr th,
5155: table.LC_innerpickbox tr td {
5156: vertical-align: top;
5157: }
5158:
1.711 raeburn 5159: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5160: background-color: #CCCCCC;
1.711 raeburn 5161: font-weight: bold;
5162: text-align: left;
5163: }
1.795 www 5164:
1.912 bisitz 5165: table.LC_data_table tr.LC_odd_row > td {
5166: background-color: $data_table_light;
5167: padding: 2px;
5168: vertical-align: top;
5169: }
5170:
1.809 bisitz 5171: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5172: background-color: $data_table_light;
1.912 bisitz 5173: vertical-align: top;
5174: }
5175:
5176: table.LC_data_table tr.LC_even_row > td {
5177: background-color: $data_table_dark;
1.425 albertel 5178: padding: 2px;
1.900 bisitz 5179: vertical-align: top;
1.347 albertel 5180: }
1.795 www 5181:
1.809 bisitz 5182: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5183: background-color: $data_table_dark;
1.900 bisitz 5184: vertical-align: top;
1.347 albertel 5185: }
1.795 www 5186:
1.425 albertel 5187: table.LC_data_table tr.LC_data_table_highlight td {
5188: background-color: $data_table_darker;
5189: }
1.795 www 5190:
1.639 raeburn 5191: table.LC_data_table tr td.LC_leftcol_header {
5192: background-color: $data_table_head;
5193: font-weight: bold;
5194: }
1.795 www 5195:
1.451 albertel 5196: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5197: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5198: font-weight: bold;
5199: font-style: italic;
5200: text-align: center;
5201: padding: 8px;
1.347 albertel 5202: }
1.795 www 5203:
1.940 bisitz 5204: table.LC_data_table tr.LC_empty_row td {
5205: background-color: $sidebg;
5206: }
5207:
5208: table.LC_nested tr.LC_empty_row td {
5209: background-color: #FFFFFF;
5210: }
5211:
1.890 droeschl 5212: table.LC_caption {
5213: }
5214:
1.507 raeburn 5215: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5216: padding: 4ex
5217: }
1.795 www 5218:
1.507 raeburn 5219: table.LC_nested_outer tr th {
5220: font-weight: bold;
1.801 tempelho 5221: color:$fontmenu;
1.507 raeburn 5222: background-color: $data_table_head;
1.701 harmsja 5223: font-size: small;
1.507 raeburn 5224: border-bottom: 1px solid #000000;
5225: }
1.795 www 5226:
1.507 raeburn 5227: table.LC_nested_outer tr td.LC_subheader {
5228: background-color: $data_table_head;
5229: font-weight: bold;
5230: font-size: small;
5231: border-bottom: 1px solid #000000;
5232: text-align: right;
1.451 albertel 5233: }
1.795 www 5234:
1.507 raeburn 5235: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5236: background-color: #CCCCCC;
1.451 albertel 5237: font-weight: bold;
5238: font-size: small;
1.507 raeburn 5239: text-align: center;
5240: }
1.795 www 5241:
1.589 raeburn 5242: table.LC_nested tr.LC_info_row td.LC_left_item,
5243: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5244: text-align: left;
1.451 albertel 5245: }
1.795 www 5246:
1.507 raeburn 5247: table.LC_nested td {
1.735 bisitz 5248: background-color: #FFFFFF;
1.451 albertel 5249: font-size: small;
1.507 raeburn 5250: }
1.795 www 5251:
1.507 raeburn 5252: table.LC_nested_outer tr th.LC_right_item,
5253: table.LC_nested tr.LC_info_row td.LC_right_item,
5254: table.LC_nested tr.LC_odd_row td.LC_right_item,
5255: table.LC_nested tr td.LC_right_item {
1.451 albertel 5256: text-align: right;
5257: }
5258:
1.930 faziophi 5259: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5260: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5261: text-align: right;
5262: width: 40%;
5263: padding-right:10px;
5264: vertical-align: top;
5265: padding: 5px;
5266: }
5267:
5268: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5269: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5270: text-align: left;
5271: width: 60%;
5272: padding: 2px 4px;
5273: }
5274:
1.507 raeburn 5275: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5276: background-color: #EEEEEE;
1.451 albertel 5277: }
5278:
1.473 raeburn 5279: table.LC_createuser {
5280: }
5281:
5282: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5283: font-size: small;
1.473 raeburn 5284: }
5285:
5286: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5287: background-color: #CCCCCC;
1.473 raeburn 5288: font-weight: bold;
5289: text-align: center;
5290: }
5291:
1.349 albertel 5292: table.LC_calendar {
5293: border: 1px solid #000000;
5294: border-collapse: collapse;
1.917 raeburn 5295: width: 98%;
1.349 albertel 5296: }
1.795 www 5297:
1.349 albertel 5298: table.LC_calendar_pickdate {
5299: font-size: xx-small;
5300: }
1.795 www 5301:
1.349 albertel 5302: table.LC_calendar tr td {
5303: border: 1px solid #000000;
5304: vertical-align: top;
1.917 raeburn 5305: width: 14%;
1.349 albertel 5306: }
1.795 www 5307:
1.349 albertel 5308: table.LC_calendar tr td.LC_calendar_day_empty {
5309: background-color: $data_table_dark;
5310: }
1.795 www 5311:
1.779 bisitz 5312: table.LC_calendar tr td.LC_calendar_day_current {
5313: background-color: $data_table_highlight;
1.777 tempelho 5314: }
1.795 www 5315:
1.938 bisitz 5316: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5317: background-color: $mail_new;
5318: }
1.795 www 5319:
1.938 bisitz 5320: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5321: background-color: $mail_new_hover;
5322: }
1.795 www 5323:
1.938 bisitz 5324: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5325: background-color: $mail_read;
5326: }
1.795 www 5327:
1.938 bisitz 5328: /*
5329: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5330: background-color: $mail_read_hover;
5331: }
1.938 bisitz 5332: */
1.795 www 5333:
1.938 bisitz 5334: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5335: background-color: $mail_replied;
5336: }
1.795 www 5337:
1.938 bisitz 5338: /*
5339: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5340: background-color: $mail_replied_hover;
5341: }
1.938 bisitz 5342: */
1.795 www 5343:
1.938 bisitz 5344: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5345: background-color: $mail_other;
5346: }
1.795 www 5347:
1.938 bisitz 5348: /*
5349: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5350: background-color: $mail_other_hover;
5351: }
1.938 bisitz 5352: */
1.494 raeburn 5353:
1.777 tempelho 5354: table.LC_data_table tr > td.LC_browser_file,
5355: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5356: background: #AAEE77;
1.389 albertel 5357: }
1.795 www 5358:
1.777 tempelho 5359: table.LC_data_table tr > td.LC_browser_file_locked,
5360: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5361: background: #FFAA99;
1.387 albertel 5362: }
1.795 www 5363:
1.777 tempelho 5364: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5365: background: #888888;
1.779 bisitz 5366: }
1.795 www 5367:
1.777 tempelho 5368: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5369: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5370: background: #F8F866;
1.777 tempelho 5371: }
1.795 www 5372:
1.696 bisitz 5373: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5374: background: #E0E8FF;
1.387 albertel 5375: }
1.696 bisitz 5376:
1.707 bisitz 5377: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5378: /* background: #77FF77; */
1.707 bisitz 5379: }
1.795 www 5380:
1.707 bisitz 5381: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5382: border-right: 8px solid #FFFF77;
1.707 bisitz 5383: }
1.795 www 5384:
1.707 bisitz 5385: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5386: border-right: 8px solid #FFAA77;
1.707 bisitz 5387: }
1.795 www 5388:
1.707 bisitz 5389: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5390: border-right: 8px solid #FF7777;
1.707 bisitz 5391: }
1.795 www 5392:
1.707 bisitz 5393: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5394: border-right: 8px solid #AAFF77;
1.707 bisitz 5395: }
1.795 www 5396:
1.707 bisitz 5397: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5398: border-right: 8px solid #11CC55;
1.707 bisitz 5399: }
5400:
1.388 albertel 5401: span.LC_current_location {
1.701 harmsja 5402: font-size:larger;
1.388 albertel 5403: background: $pgbg;
5404: }
1.387 albertel 5405:
1.395 albertel 5406: span.LC_parm_menu_item {
5407: font-size: larger;
5408: }
1.795 www 5409:
1.395 albertel 5410: span.LC_parm_scope_all {
5411: color: red;
5412: }
1.795 www 5413:
1.395 albertel 5414: span.LC_parm_scope_folder {
5415: color: green;
5416: }
1.795 www 5417:
1.395 albertel 5418: span.LC_parm_scope_resource {
5419: color: orange;
5420: }
1.795 www 5421:
1.395 albertel 5422: span.LC_parm_part {
5423: color: blue;
5424: }
1.795 www 5425:
1.911 bisitz 5426: span.LC_parm_folder,
5427: span.LC_parm_symb {
1.395 albertel 5428: font-size: x-small;
5429: font-family: $mono;
5430: color: #AAAAAA;
5431: }
5432:
1.977 bisitz 5433: ul.LC_parm_parmlist li {
5434: display: inline-block;
5435: padding: 0.3em 0.8em;
5436: vertical-align: top;
5437: width: 150px;
5438: border-top:1px solid $lg_border_color;
5439: }
5440:
1.795 www 5441: td.LC_parm_overview_level_menu,
5442: td.LC_parm_overview_map_menu,
5443: td.LC_parm_overview_parm_selectors,
5444: td.LC_parm_overview_restrictions {
1.396 albertel 5445: border: 1px solid black;
5446: border-collapse: collapse;
5447: }
1.795 www 5448:
1.396 albertel 5449: table.LC_parm_overview_restrictions td {
5450: border-width: 1px 4px 1px 4px;
5451: border-style: solid;
5452: border-color: $pgbg;
5453: text-align: center;
5454: }
1.795 www 5455:
1.396 albertel 5456: table.LC_parm_overview_restrictions th {
5457: background: $tabbg;
5458: border-width: 1px 4px 1px 4px;
5459: border-style: solid;
5460: border-color: $pgbg;
5461: }
1.795 www 5462:
1.398 albertel 5463: table#LC_helpmenu {
1.803 bisitz 5464: border: none;
1.398 albertel 5465: height: 55px;
1.803 bisitz 5466: border-spacing: 0;
1.398 albertel 5467: }
5468:
5469: table#LC_helpmenu fieldset legend {
5470: font-size: larger;
5471: }
1.795 www 5472:
1.397 albertel 5473: table#LC_helpmenu_links {
5474: width: 100%;
5475: border: 1px solid black;
5476: background: $pgbg;
1.803 bisitz 5477: padding: 0;
1.397 albertel 5478: border-spacing: 1px;
5479: }
1.795 www 5480:
1.397 albertel 5481: table#LC_helpmenu_links tr td {
5482: padding: 1px;
5483: background: $tabbg;
1.399 albertel 5484: text-align: center;
5485: font-weight: bold;
1.397 albertel 5486: }
1.396 albertel 5487:
1.795 www 5488: table#LC_helpmenu_links a:link,
5489: table#LC_helpmenu_links a:visited,
1.397 albertel 5490: table#LC_helpmenu_links a:active {
5491: text-decoration: none;
5492: color: $font;
5493: }
1.795 www 5494:
1.397 albertel 5495: table#LC_helpmenu_links a:hover {
5496: text-decoration: underline;
5497: color: $vlink;
5498: }
1.396 albertel 5499:
1.417 albertel 5500: .LC_chrt_popup_exists {
5501: border: 1px solid #339933;
5502: margin: -1px;
5503: }
1.795 www 5504:
1.417 albertel 5505: .LC_chrt_popup_up {
5506: border: 1px solid yellow;
5507: margin: -1px;
5508: }
1.795 www 5509:
1.417 albertel 5510: .LC_chrt_popup {
5511: border: 1px solid #8888FF;
5512: background: #CCCCFF;
5513: }
1.795 www 5514:
1.421 albertel 5515: table.LC_pick_box {
5516: border-collapse: separate;
5517: background: white;
5518: border: 1px solid black;
5519: border-spacing: 1px;
5520: }
1.795 www 5521:
1.421 albertel 5522: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5523: background: $sidebg;
1.421 albertel 5524: font-weight: bold;
1.900 bisitz 5525: text-align: left;
1.740 bisitz 5526: vertical-align: top;
1.421 albertel 5527: width: 184px;
5528: padding: 8px;
5529: }
1.795 www 5530:
1.579 raeburn 5531: table.LC_pick_box td.LC_pick_box_value {
5532: text-align: left;
5533: padding: 8px;
5534: }
1.795 www 5535:
1.579 raeburn 5536: table.LC_pick_box td.LC_pick_box_select {
5537: text-align: left;
5538: padding: 8px;
5539: }
1.795 www 5540:
1.424 albertel 5541: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5542: padding: 0;
1.421 albertel 5543: height: 1px;
5544: background: black;
5545: }
1.795 www 5546:
1.421 albertel 5547: table.LC_pick_box td.LC_pick_box_submit {
5548: text-align: right;
5549: }
1.795 www 5550:
1.579 raeburn 5551: table.LC_pick_box td.LC_evenrow_value {
5552: text-align: left;
5553: padding: 8px;
5554: background-color: $data_table_light;
5555: }
1.795 www 5556:
1.579 raeburn 5557: table.LC_pick_box td.LC_oddrow_value {
5558: text-align: left;
5559: padding: 8px;
5560: background-color: $data_table_light;
5561: }
1.795 www 5562:
1.579 raeburn 5563: span.LC_helpform_receipt_cat {
5564: font-weight: bold;
5565: }
1.795 www 5566:
1.424 albertel 5567: table.LC_group_priv_box {
5568: background: white;
5569: border: 1px solid black;
5570: border-spacing: 1px;
5571: }
1.795 www 5572:
1.424 albertel 5573: table.LC_group_priv_box td.LC_pick_box_title {
5574: background: $tabbg;
5575: font-weight: bold;
5576: text-align: right;
5577: width: 184px;
5578: }
1.795 www 5579:
1.424 albertel 5580: table.LC_group_priv_box td.LC_groups_fixed {
5581: background: $data_table_light;
5582: text-align: center;
5583: }
1.795 www 5584:
1.424 albertel 5585: table.LC_group_priv_box td.LC_groups_optional {
5586: background: $data_table_dark;
5587: text-align: center;
5588: }
1.795 www 5589:
1.424 albertel 5590: table.LC_group_priv_box td.LC_groups_functionality {
5591: background: $data_table_darker;
5592: text-align: center;
5593: font-weight: bold;
5594: }
1.795 www 5595:
1.424 albertel 5596: table.LC_group_priv td {
5597: text-align: left;
1.803 bisitz 5598: padding: 0;
1.424 albertel 5599: }
5600:
5601: .LC_navbuttons {
5602: margin: 2ex 0ex 2ex 0ex;
5603: }
1.795 www 5604:
1.423 albertel 5605: .LC_topic_bar {
5606: font-weight: bold;
5607: background: $tabbg;
1.918 wenzelju 5608: margin: 1em 0em 1em 2em;
1.805 bisitz 5609: padding: 3px;
1.918 wenzelju 5610: font-size: 1.2em;
1.423 albertel 5611: }
1.795 www 5612:
1.423 albertel 5613: .LC_topic_bar span {
1.918 wenzelju 5614: left: 0.5em;
5615: position: absolute;
1.423 albertel 5616: vertical-align: middle;
1.918 wenzelju 5617: font-size: 1.2em;
1.423 albertel 5618: }
1.795 www 5619:
1.423 albertel 5620: table.LC_course_group_status {
5621: margin: 20px;
5622: }
1.795 www 5623:
1.423 albertel 5624: table.LC_status_selector td {
5625: vertical-align: top;
5626: text-align: center;
1.424 albertel 5627: padding: 4px;
5628: }
1.795 www 5629:
1.599 albertel 5630: div.LC_feedback_link {
1.616 albertel 5631: clear: both;
1.829 kalberla 5632: background: $sidebg;
1.779 bisitz 5633: width: 100%;
1.829 kalberla 5634: padding-bottom: 10px;
5635: border: 1px $tabbg solid;
1.833 kalberla 5636: height: 22px;
5637: line-height: 22px;
5638: padding-top: 5px;
5639: }
5640:
5641: div.LC_feedback_link img {
5642: height: 22px;
1.867 kalberla 5643: vertical-align:middle;
1.829 kalberla 5644: }
5645:
1.911 bisitz 5646: div.LC_feedback_link a {
1.829 kalberla 5647: text-decoration: none;
1.489 raeburn 5648: }
1.795 www 5649:
1.867 kalberla 5650: div.LC_comblock {
1.911 bisitz 5651: display:inline;
1.867 kalberla 5652: color:$font;
5653: font-size:90%;
5654: }
5655:
5656: div.LC_feedback_link div.LC_comblock {
5657: padding-left:5px;
5658: }
5659:
5660: div.LC_feedback_link div.LC_comblock a {
5661: color:$font;
5662: }
5663:
1.489 raeburn 5664: span.LC_feedback_link {
1.858 bisitz 5665: /* background: $feedback_link_bg; */
1.599 albertel 5666: font-size: larger;
5667: }
1.795 www 5668:
1.599 albertel 5669: span.LC_message_link {
1.858 bisitz 5670: /* background: $feedback_link_bg; */
1.599 albertel 5671: font-size: larger;
5672: position: absolute;
5673: right: 1em;
1.489 raeburn 5674: }
1.421 albertel 5675:
1.515 albertel 5676: table.LC_prior_tries {
1.524 albertel 5677: border: 1px solid #000000;
5678: border-collapse: separate;
5679: border-spacing: 1px;
1.515 albertel 5680: }
1.523 albertel 5681:
1.515 albertel 5682: table.LC_prior_tries td {
1.524 albertel 5683: padding: 2px;
1.515 albertel 5684: }
1.523 albertel 5685:
5686: .LC_answer_correct {
1.795 www 5687: background: lightgreen;
5688: color: darkgreen;
5689: padding: 6px;
1.523 albertel 5690: }
1.795 www 5691:
1.523 albertel 5692: .LC_answer_charged_try {
1.797 www 5693: background: #FFAAAA;
1.795 www 5694: color: darkred;
5695: padding: 6px;
1.523 albertel 5696: }
1.795 www 5697:
1.779 bisitz 5698: .LC_answer_not_charged_try,
1.523 albertel 5699: .LC_answer_no_grade,
5700: .LC_answer_late {
1.795 www 5701: background: lightyellow;
1.523 albertel 5702: color: black;
1.795 www 5703: padding: 6px;
1.523 albertel 5704: }
1.795 www 5705:
1.523 albertel 5706: .LC_answer_previous {
1.795 www 5707: background: lightblue;
5708: color: darkblue;
5709: padding: 6px;
1.523 albertel 5710: }
1.795 www 5711:
1.779 bisitz 5712: .LC_answer_no_message {
1.777 tempelho 5713: background: #FFFFFF;
5714: color: black;
1.795 www 5715: padding: 6px;
1.779 bisitz 5716: }
1.795 www 5717:
1.779 bisitz 5718: .LC_answer_unknown {
5719: background: orange;
5720: color: black;
1.795 www 5721: padding: 6px;
1.777 tempelho 5722: }
1.795 www 5723:
1.529 albertel 5724: span.LC_prior_numerical,
5725: span.LC_prior_string,
5726: span.LC_prior_custom,
5727: span.LC_prior_reaction,
5728: span.LC_prior_math {
1.925 bisitz 5729: font-family: $mono;
1.523 albertel 5730: white-space: pre;
5731: }
5732:
1.525 albertel 5733: span.LC_prior_string {
1.925 bisitz 5734: font-family: $mono;
1.525 albertel 5735: white-space: pre;
5736: }
5737:
1.523 albertel 5738: table.LC_prior_option {
5739: width: 100%;
5740: border-collapse: collapse;
5741: }
1.795 www 5742:
1.911 bisitz 5743: table.LC_prior_rank,
1.795 www 5744: table.LC_prior_match {
1.528 albertel 5745: border-collapse: collapse;
5746: }
1.795 www 5747:
1.528 albertel 5748: table.LC_prior_option tr td,
5749: table.LC_prior_rank tr td,
5750: table.LC_prior_match tr td {
1.524 albertel 5751: border: 1px solid #000000;
1.515 albertel 5752: }
5753:
1.855 bisitz 5754: .LC_nobreak {
1.544 albertel 5755: white-space: nowrap;
1.519 raeburn 5756: }
5757:
1.576 raeburn 5758: span.LC_cusr_emph {
5759: font-style: italic;
5760: }
5761:
1.633 raeburn 5762: span.LC_cusr_subheading {
5763: font-weight: normal;
5764: font-size: 85%;
5765: }
5766:
1.861 bisitz 5767: div.LC_docs_entry_move {
1.859 bisitz 5768: border: 1px solid #BBBBBB;
1.545 albertel 5769: background: #DDDDDD;
1.861 bisitz 5770: width: 22px;
1.859 bisitz 5771: padding: 1px;
5772: margin: 0;
1.545 albertel 5773: }
5774:
1.861 bisitz 5775: table.LC_data_table tr > td.LC_docs_entry_commands,
5776: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5777: background: #DDDDDD;
5778: font-size: x-small;
5779: }
1.795 www 5780:
1.861 bisitz 5781: .LC_docs_entry_parameter {
5782: white-space: nowrap;
5783: }
5784:
1.544 albertel 5785: .LC_docs_copy {
1.545 albertel 5786: color: #000099;
1.544 albertel 5787: }
1.795 www 5788:
1.544 albertel 5789: .LC_docs_cut {
1.545 albertel 5790: color: #550044;
1.544 albertel 5791: }
1.795 www 5792:
1.544 albertel 5793: .LC_docs_rename {
1.545 albertel 5794: color: #009900;
1.544 albertel 5795: }
1.795 www 5796:
1.544 albertel 5797: .LC_docs_remove {
1.545 albertel 5798: color: #990000;
5799: }
5800:
1.547 albertel 5801: .LC_docs_reinit_warn,
5802: .LC_docs_ext_edit {
5803: font-size: x-small;
5804: }
5805:
1.545 albertel 5806: table.LC_docs_adddocs td,
5807: table.LC_docs_adddocs th {
5808: border: 1px solid #BBBBBB;
5809: padding: 4px;
5810: background: #DDDDDD;
1.543 albertel 5811: }
5812:
1.584 albertel 5813: table.LC_sty_begin {
5814: background: #BBFFBB;
5815: }
1.795 www 5816:
1.584 albertel 5817: table.LC_sty_end {
5818: background: #FFBBBB;
5819: }
5820:
1.589 raeburn 5821: table.LC_double_column {
1.803 bisitz 5822: border-width: 0;
1.589 raeburn 5823: border-collapse: collapse;
5824: width: 100%;
5825: padding: 2px;
5826: }
5827:
5828: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5829: top: 2px;
1.589 raeburn 5830: left: 2px;
5831: width: 47%;
5832: vertical-align: top;
5833: }
5834:
5835: table.LC_double_column tr td.LC_right_col {
5836: top: 2px;
1.779 bisitz 5837: right: 2px;
1.589 raeburn 5838: width: 47%;
5839: vertical-align: top;
5840: }
5841:
1.591 raeburn 5842: div.LC_left_float {
5843: float: left;
5844: padding-right: 5%;
1.597 albertel 5845: padding-bottom: 4px;
1.591 raeburn 5846: }
5847:
5848: div.LC_clear_float_header {
1.597 albertel 5849: padding-bottom: 2px;
1.591 raeburn 5850: }
5851:
5852: div.LC_clear_float_footer {
1.597 albertel 5853: padding-top: 10px;
1.591 raeburn 5854: clear: both;
5855: }
5856:
1.597 albertel 5857: div.LC_grade_show_user {
1.941 bisitz 5858: /* border-left: 5px solid $sidebg; */
5859: border-top: 5px solid #000000;
5860: margin: 50px 0 0 0;
1.936 bisitz 5861: padding: 15px 0 5px 10px;
1.597 albertel 5862: }
1.795 www 5863:
1.936 bisitz 5864: div.LC_grade_show_user_odd_row {
1.941 bisitz 5865: /* border-left: 5px solid #000000; */
5866: }
5867:
5868: div.LC_grade_show_user div.LC_Box {
5869: margin-right: 50px;
1.597 albertel 5870: }
5871:
5872: div.LC_grade_submissions,
5873: div.LC_grade_message_center,
1.936 bisitz 5874: div.LC_grade_info_links {
1.597 albertel 5875: margin: 5px;
5876: width: 99%;
5877: background: #FFFFFF;
5878: }
1.795 www 5879:
1.597 albertel 5880: div.LC_grade_submissions_header,
1.936 bisitz 5881: div.LC_grade_message_center_header {
1.705 tempelho 5882: font-weight: bold;
5883: font-size: large;
1.597 albertel 5884: }
1.795 www 5885:
1.597 albertel 5886: div.LC_grade_submissions_body,
1.936 bisitz 5887: div.LC_grade_message_center_body {
1.597 albertel 5888: border: 1px solid black;
5889: width: 99%;
5890: background: #FFFFFF;
5891: }
1.795 www 5892:
1.613 albertel 5893: table.LC_scantron_action {
5894: width: 100%;
5895: }
1.795 www 5896:
1.613 albertel 5897: table.LC_scantron_action tr th {
1.698 harmsja 5898: font-weight:bold;
5899: font-style:normal;
1.613 albertel 5900: }
1.795 www 5901:
1.779 bisitz 5902: .LC_edit_problem_header,
1.614 albertel 5903: div.LC_edit_problem_footer {
1.705 tempelho 5904: font-weight: normal;
5905: font-size: medium;
1.602 albertel 5906: margin: 2px;
1.600 albertel 5907: }
1.795 www 5908:
1.600 albertel 5909: div.LC_edit_problem_header,
1.602 albertel 5910: div.LC_edit_problem_header div,
1.614 albertel 5911: div.LC_edit_problem_footer,
5912: div.LC_edit_problem_footer div,
1.602 albertel 5913: div.LC_edit_problem_editxml_header,
5914: div.LC_edit_problem_editxml_header div {
1.600 albertel 5915: margin-top: 5px;
5916: }
1.795 www 5917:
1.600 albertel 5918: div.LC_edit_problem_header_title {
1.705 tempelho 5919: font-weight: bold;
5920: font-size: larger;
1.602 albertel 5921: background: $tabbg;
5922: padding: 3px;
5923: }
1.795 www 5924:
1.602 albertel 5925: table.LC_edit_problem_header_title {
5926: width: 100%;
1.600 albertel 5927: background: $tabbg;
1.602 albertel 5928: }
5929:
5930: div.LC_edit_problem_discards {
5931: float: left;
5932: padding-bottom: 5px;
5933: }
1.795 www 5934:
1.602 albertel 5935: div.LC_edit_problem_saves {
5936: float: right;
5937: padding-bottom: 5px;
1.600 albertel 5938: }
1.795 www 5939:
1.911 bisitz 5940: img.stift {
1.803 bisitz 5941: border-width: 0;
5942: vertical-align: middle;
1.677 riegler 5943: }
1.680 riegler 5944:
1.923 bisitz 5945: table td.LC_mainmenu_col_fieldset {
1.680 riegler 5946: vertical-align: top;
1.777 tempelho 5947: }
1.795 www 5948:
1.716 raeburn 5949: div.LC_createcourse {
1.911 bisitz 5950: margin: 10px 10px 10px 10px;
1.716 raeburn 5951: }
5952:
1.917 raeburn 5953: .LC_dccid {
5954: margin: 0.2em 0 0 0;
5955: padding: 0;
5956: font-size: 90%;
5957: display:none;
5958: }
5959:
1.698 harmsja 5960: a:hover,
1.897 wenzelju 5961: ol.LC_primary_menu a:hover,
1.721 harmsja 5962: ol#LC_MenuBreadcrumbs a:hover,
5963: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5964: ul#LC_secondary_menu a:hover,
1.721 harmsja 5965: .LC_FormSectionClearButton input:hover
1.795 www 5966: ul.LC_TabContent li:hover a {
1.952 onken 5967: color:$button_hover;
1.911 bisitz 5968: text-decoration:none;
1.693 droeschl 5969: }
5970:
1.779 bisitz 5971: h1 {
1.911 bisitz 5972: padding: 0;
5973: line-height:130%;
1.693 droeschl 5974: }
1.698 harmsja 5975:
1.911 bisitz 5976: h2,
5977: h3,
5978: h4,
5979: h5,
5980: h6 {
5981: margin: 5px 0 5px 0;
5982: padding: 0;
5983: line-height:130%;
1.693 droeschl 5984: }
1.795 www 5985:
5986: .LC_hcell {
1.911 bisitz 5987: padding:3px 15px 3px 15px;
5988: margin: 0;
5989: background-color:$tabbg;
5990: color:$fontmenu;
5991: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5992: }
1.795 www 5993:
1.840 bisitz 5994: .LC_Box > .LC_hcell {
1.911 bisitz 5995: margin: 0 -10px 10px -10px;
1.835 bisitz 5996: }
5997:
1.721 harmsja 5998: .LC_noBorder {
1.911 bisitz 5999: border: 0;
1.698 harmsja 6000: }
1.693 droeschl 6001:
1.721 harmsja 6002: .LC_FormSectionClearButton input {
1.911 bisitz 6003: background-color:transparent;
6004: border: none;
6005: cursor:pointer;
6006: text-decoration:underline;
1.693 droeschl 6007: }
1.763 bisitz 6008:
6009: .LC_help_open_topic {
1.911 bisitz 6010: color: #FFFFFF;
6011: background-color: #EEEEFF;
6012: margin: 1px;
6013: padding: 4px;
6014: border: 1px solid #000033;
6015: white-space: nowrap;
6016: /* vertical-align: middle; */
1.759 neumanie 6017: }
1.693 droeschl 6018:
1.911 bisitz 6019: dl,
6020: ul,
6021: div,
6022: fieldset {
6023: margin: 10px 10px 10px 0;
6024: /* overflow: hidden; */
1.693 droeschl 6025: }
1.795 www 6026:
1.838 bisitz 6027: fieldset > legend {
1.911 bisitz 6028: font-weight: bold;
6029: padding: 0 5px 0 5px;
1.838 bisitz 6030: }
6031:
1.813 bisitz 6032: #LC_nav_bar {
1.911 bisitz 6033: float: left;
1.966 bisitz 6034: margin: 0 0 2px 0;
1.807 droeschl 6035: }
6036:
1.916 droeschl 6037: #LC_realm {
6038: margin: 0.2em 0 0 0;
6039: padding: 0;
6040: font-weight: bold;
6041: text-align: center;
6042: }
6043:
1.911 bisitz 6044: #LC_nav_bar em {
6045: font-weight: bold;
6046: font-style: normal;
1.807 droeschl 6047: }
6048:
1.965 bisitz 6049: /* Preliminary fix to hide nav_bar inside bookmarks window */
6050: #LC_bookmarks #LC_nav_bar {
6051: display:none;
6052: }
6053:
1.897 wenzelju 6054: ol.LC_primary_menu {
1.911 bisitz 6055: float: right;
1.934 droeschl 6056: margin: 0;
1.807 droeschl 6057: }
6058:
1.852 droeschl 6059: ol#LC_PathBreadcrumbs {
1.911 bisitz 6060: margin: 0;
1.693 droeschl 6061: }
6062:
1.897 wenzelju 6063: ol.LC_primary_menu li {
1.911 bisitz 6064: display: inline;
6065: padding: 5px 5px 0 10px;
6066: vertical-align: top;
1.693 droeschl 6067: }
6068:
1.897 wenzelju 6069: ol.LC_primary_menu li img {
1.911 bisitz 6070: vertical-align: bottom;
1.934 droeschl 6071: height: 1.1em;
1.693 droeschl 6072: }
6073:
1.897 wenzelju 6074: ol.LC_primary_menu a {
1.911 bisitz 6075: color: RGB(80, 80, 80);
6076: text-decoration: none;
1.693 droeschl 6077: }
1.795 www 6078:
1.949 droeschl 6079: ol.LC_primary_menu a.LC_new_message {
6080: font-weight:bold;
6081: color: darkred;
6082: }
6083:
1.975 raeburn 6084: ol.LC_docs_parameters {
6085: margin-left: 0;
6086: padding: 0;
6087: list-style: none;
6088: }
6089:
6090: ol.LC_docs_parameters li {
6091: margin: 0;
6092: padding-right: 20px;
6093: display: inline;
6094: }
6095:
1.976 raeburn 6096: ol.LC_docs_parameters li:before {
6097: content: "\\002022 \\0020";
6098: }
6099:
6100: li.LC_docs_parameters_title {
6101: font-weight: bold;
6102: }
6103:
6104: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6105: content: "";
6106: }
6107:
1.897 wenzelju 6108: ul#LC_secondary_menu {
1.911 bisitz 6109: clear: both;
6110: color: $fontmenu;
6111: background: $tabbg;
6112: list-style: none;
6113: padding: 0;
6114: margin: 0;
6115: width: 100%;
1.808 droeschl 6116: }
6117:
1.897 wenzelju 6118: ul#LC_secondary_menu li {
1.911 bisitz 6119: font-weight: bold;
6120: line-height: 1.8em;
6121: padding: 0 0.8em;
6122: border-right: 1px solid black;
6123: display: inline;
6124: vertical-align: middle;
1.807 droeschl 6125: }
6126:
1.847 tempelho 6127: ul.LC_TabContent {
1.911 bisitz 6128: display:block;
6129: background: $sidebg;
6130: border-bottom: solid 1px $lg_border_color;
6131: list-style:none;
6132: margin: 0 -10px;
6133: padding: 0;
1.693 droeschl 6134: }
6135:
1.795 www 6136: ul.LC_TabContent li,
6137: ul.LC_TabContentBigger li {
1.911 bisitz 6138: float:left;
1.741 harmsja 6139: }
1.795 www 6140:
1.897 wenzelju 6141: ul#LC_secondary_menu li a {
1.911 bisitz 6142: color: $fontmenu;
6143: text-decoration: none;
1.693 droeschl 6144: }
1.795 www 6145:
1.721 harmsja 6146: ul.LC_TabContent {
1.952 onken 6147: min-height:20px;
1.721 harmsja 6148: }
1.795 www 6149:
6150: ul.LC_TabContent li {
1.911 bisitz 6151: vertical-align:middle;
1.959 onken 6152: padding: 0 16px 0 10px;
1.911 bisitz 6153: background-color:$tabbg;
6154: border-bottom:solid 1px $lg_border_color;
1.952 onken 6155: border-right: solid 1px $font;
1.721 harmsja 6156: }
1.795 www 6157:
1.847 tempelho 6158: ul.LC_TabContent .right {
1.911 bisitz 6159: float:right;
1.847 tempelho 6160: }
6161:
1.911 bisitz 6162: ul.LC_TabContent li a,
6163: ul.LC_TabContent li {
6164: color:rgb(47,47,47);
6165: text-decoration:none;
6166: font-size:95%;
6167: font-weight:bold;
1.952 onken 6168: min-height:20px;
6169: }
6170:
1.959 onken 6171: ul.LC_TabContent li a:hover,
6172: ul.LC_TabContent li a:focus {
1.952 onken 6173: color: $button_hover;
1.959 onken 6174: background:none;
6175: outline:none;
1.952 onken 6176: }
6177:
6178: ul.LC_TabContent li:hover {
6179: color: $button_hover;
6180: cursor:pointer;
1.721 harmsja 6181: }
1.795 www 6182:
1.911 bisitz 6183: ul.LC_TabContent li.active {
1.952 onken 6184: color: $font;
1.911 bisitz 6185: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6186: border-bottom:solid 1px #FFFFFF;
6187: cursor: default;
1.744 ehlerst 6188: }
1.795 www 6189:
1.959 onken 6190: ul.LC_TabContent li.active a {
6191: color:$font;
6192: background:#FFFFFF;
6193: outline: none;
6194: }
1.870 tempelho 6195: #maincoursedoc {
1.911 bisitz 6196: clear:both;
1.870 tempelho 6197: }
6198:
6199: ul.LC_TabContentBigger {
1.911 bisitz 6200: display:block;
6201: list-style:none;
6202: padding: 0;
1.870 tempelho 6203: }
6204:
1.795 www 6205: ul.LC_TabContentBigger li {
1.911 bisitz 6206: vertical-align:bottom;
6207: height: 30px;
6208: font-size:110%;
6209: font-weight:bold;
6210: color: #737373;
1.841 tempelho 6211: }
6212:
1.957 onken 6213: ul.LC_TabContentBigger li.active {
6214: position: relative;
6215: top: 1px;
6216: }
6217:
1.870 tempelho 6218: ul.LC_TabContentBigger li a {
1.911 bisitz 6219: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6220: height: 30px;
6221: line-height: 30px;
6222: text-align: center;
6223: display: block;
6224: text-decoration: none;
1.958 onken 6225: outline: none;
1.741 harmsja 6226: }
1.795 www 6227:
1.870 tempelho 6228: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6229: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6230: color:$font;
1.744 ehlerst 6231: }
1.795 www 6232:
1.870 tempelho 6233: ul.LC_TabContentBigger li b {
1.911 bisitz 6234: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6235: display: block;
6236: float: left;
6237: padding: 0 30px;
1.957 onken 6238: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6239: }
6240:
1.956 onken 6241: ul.LC_TabContentBigger li:hover b {
6242: color:$button_hover;
6243: }
6244:
1.870 tempelho 6245: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6246: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6247: color:$font;
1.957 onken 6248: border: 0;
1.956 onken 6249: cursor:default;
1.741 harmsja 6250: }
1.693 droeschl 6251:
1.870 tempelho 6252:
1.862 bisitz 6253: ul.LC_CourseBreadcrumbs {
6254: background: $sidebg;
6255: line-height: 32px;
6256: padding-left: 10px;
6257: margin: 0 0 10px 0;
6258: list-style-position: inside;
6259:
6260: }
6261:
1.911 bisitz 6262: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6263: ol#LC_PathBreadcrumbs {
1.911 bisitz 6264: padding-left: 10px;
6265: margin: 0;
1.933 droeschl 6266: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6267: }
6268:
1.911 bisitz 6269: ol#LC_MenuBreadcrumbs li,
6270: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6271: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6272: display: inline;
1.933 droeschl 6273: white-space: normal;
1.693 droeschl 6274: }
6275:
1.823 bisitz 6276: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6277: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6278: text-decoration: none;
6279: font-size:90%;
1.693 droeschl 6280: }
1.795 www 6281:
1.969 droeschl 6282: ol#LC_MenuBreadcrumbs h1 {
6283: display: inline;
6284: font-size: 90%;
6285: line-height: 2.5em;
6286: margin: 0;
6287: padding: 0;
6288: }
6289:
1.795 www 6290: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6291: text-decoration:none;
6292: font-size:100%;
6293: font-weight:bold;
1.693 droeschl 6294: }
1.795 www 6295:
1.840 bisitz 6296: .LC_Box {
1.911 bisitz 6297: border: solid 1px $lg_border_color;
6298: padding: 0 10px 10px 10px;
1.746 neumanie 6299: }
1.795 www 6300:
6301: .LC_AboutMe_Image {
1.911 bisitz 6302: float:left;
6303: margin-right:10px;
1.747 neumanie 6304: }
1.795 www 6305:
6306: .LC_Clear_AboutMe_Image {
1.911 bisitz 6307: clear:left;
1.747 neumanie 6308: }
1.795 www 6309:
1.721 harmsja 6310: dl.LC_ListStyleClean dt {
1.911 bisitz 6311: padding-right: 5px;
6312: display: table-header-group;
1.693 droeschl 6313: }
6314:
1.721 harmsja 6315: dl.LC_ListStyleClean dd {
1.911 bisitz 6316: display: table-row;
1.693 droeschl 6317: }
6318:
1.721 harmsja 6319: .LC_ListStyleClean,
6320: .LC_ListStyleSimple,
6321: .LC_ListStyleNormal,
1.795 www 6322: .LC_ListStyleSpecial {
1.911 bisitz 6323: /* display:block; */
6324: list-style-position: inside;
6325: list-style-type: none;
6326: overflow: hidden;
6327: padding: 0;
1.693 droeschl 6328: }
6329:
1.721 harmsja 6330: .LC_ListStyleSimple li,
6331: .LC_ListStyleSimple dd,
6332: .LC_ListStyleNormal li,
6333: .LC_ListStyleNormal dd,
6334: .LC_ListStyleSpecial li,
1.795 www 6335: .LC_ListStyleSpecial dd {
1.911 bisitz 6336: margin: 0;
6337: padding: 5px 5px 5px 10px;
6338: clear: both;
1.693 droeschl 6339: }
6340:
1.721 harmsja 6341: .LC_ListStyleClean li,
6342: .LC_ListStyleClean dd {
1.911 bisitz 6343: padding-top: 0;
6344: padding-bottom: 0;
1.693 droeschl 6345: }
6346:
1.721 harmsja 6347: .LC_ListStyleSimple dd,
1.795 www 6348: .LC_ListStyleSimple li {
1.911 bisitz 6349: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6350: }
6351:
1.721 harmsja 6352: .LC_ListStyleSpecial li,
6353: .LC_ListStyleSpecial dd {
1.911 bisitz 6354: list-style-type: none;
6355: background-color: RGB(220, 220, 220);
6356: margin-bottom: 4px;
1.693 droeschl 6357: }
6358:
1.721 harmsja 6359: table.LC_SimpleTable {
1.911 bisitz 6360: margin:5px;
6361: border:solid 1px $lg_border_color;
1.795 www 6362: }
1.693 droeschl 6363:
1.721 harmsja 6364: table.LC_SimpleTable tr {
1.911 bisitz 6365: padding: 0;
6366: border:solid 1px $lg_border_color;
1.693 droeschl 6367: }
1.795 www 6368:
6369: table.LC_SimpleTable thead {
1.911 bisitz 6370: background:rgb(220,220,220);
1.693 droeschl 6371: }
6372:
1.721 harmsja 6373: div.LC_columnSection {
1.911 bisitz 6374: display: block;
6375: clear: both;
6376: overflow: hidden;
6377: margin: 0;
1.693 droeschl 6378: }
6379:
1.721 harmsja 6380: div.LC_columnSection>* {
1.911 bisitz 6381: float: left;
6382: margin: 10px 20px 10px 0;
6383: overflow:hidden;
1.693 droeschl 6384: }
1.721 harmsja 6385:
1.795 www 6386: table em {
1.911 bisitz 6387: font-weight: bold;
6388: font-style: normal;
1.748 schulted 6389: }
1.795 www 6390:
1.779 bisitz 6391: table.LC_tableBrowseRes,
1.795 www 6392: table.LC_tableOfContent {
1.911 bisitz 6393: border:none;
6394: border-spacing: 1px;
6395: padding: 3px;
6396: background-color: #FFFFFF;
6397: font-size: 90%;
1.753 droeschl 6398: }
1.789 droeschl 6399:
1.911 bisitz 6400: table.LC_tableOfContent {
6401: border-collapse: collapse;
1.789 droeschl 6402: }
6403:
1.771 droeschl 6404: table.LC_tableBrowseRes a,
1.768 schulted 6405: table.LC_tableOfContent a {
1.911 bisitz 6406: background-color: transparent;
6407: text-decoration: none;
1.753 droeschl 6408: }
6409:
1.795 www 6410: table.LC_tableOfContent img {
1.911 bisitz 6411: border: none;
6412: height: 1.3em;
6413: vertical-align: text-bottom;
6414: margin-right: 0.3em;
1.753 droeschl 6415: }
1.757 schulted 6416:
1.795 www 6417: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6418: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6419: }
6420:
1.795 www 6421: a#LC_content_toolbar_everything {
1.911 bisitz 6422: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6423: }
6424:
1.795 www 6425: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6426: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6427: }
6428:
1.795 www 6429: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6430: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6431: }
6432:
1.795 www 6433: a#LC_content_toolbar_changefolder {
1.911 bisitz 6434: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6435: }
6436:
1.795 www 6437: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6438: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6439: }
6440:
1.795 www 6441: ul#LC_toolbar li a:hover {
1.911 bisitz 6442: background-position: bottom center;
1.757 schulted 6443: }
6444:
1.795 www 6445: ul#LC_toolbar {
1.911 bisitz 6446: padding: 0;
6447: margin: 2px;
6448: list-style:none;
6449: position:relative;
6450: background-color:white;
1.757 schulted 6451: }
6452:
1.795 www 6453: ul#LC_toolbar li {
1.911 bisitz 6454: border:1px solid white;
6455: padding: 0;
6456: margin: 0;
6457: float: left;
6458: display:inline;
6459: vertical-align:middle;
6460: }
1.757 schulted 6461:
1.783 amueller 6462:
1.795 www 6463: a.LC_toolbarItem {
1.911 bisitz 6464: display:block;
6465: padding: 0;
6466: margin: 0;
6467: height: 32px;
6468: width: 32px;
6469: color:white;
6470: border: none;
6471: background-repeat:no-repeat;
6472: background-color:transparent;
1.757 schulted 6473: }
6474:
1.915 droeschl 6475: ul.LC_funclist {
6476: margin: 0;
6477: padding: 0.5em 1em 0.5em 0;
6478: }
6479:
1.933 droeschl 6480: ul.LC_funclist > li:first-child {
6481: font-weight:bold;
6482: margin-left:0.8em;
6483: }
6484:
1.915 droeschl 6485: ul.LC_funclist + ul.LC_funclist {
6486: /*
6487: left border as a seperator if we have more than
6488: one list
6489: */
6490: border-left: 1px solid $sidebg;
6491: /*
6492: this hides the left border behind the border of the
6493: outer box if element is wrapped to the next 'line'
6494: */
6495: margin-left: -1px;
6496: }
6497:
1.843 bisitz 6498: ul.LC_funclist li {
1.915 droeschl 6499: display: inline;
1.782 bisitz 6500: white-space: nowrap;
1.915 droeschl 6501: margin: 0 0 0 25px;
6502: line-height: 150%;
1.782 bisitz 6503: }
6504:
1.930 faziophi 6505: .ui-accordion .LC_advanced_toggle {
6506: float: right;
6507: font-size: 90%;
6508: padding: 0px 4px
6509: }
1.757 schulted 6510:
1.974 wenzelju 6511: .LC_hidden {
6512: display: none;
6513: }
6514:
1.343 albertel 6515: END
6516: }
6517:
1.306 albertel 6518: =pod
6519:
6520: =item * &headtag()
6521:
6522: Returns a uniform footer for LON-CAPA web pages.
6523:
1.307 albertel 6524: Inputs: $title - optional title for the head
6525: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6526: $args - optional arguments
1.319 albertel 6527: force_register - if is true call registerurl so the remote is
6528: informed
1.415 albertel 6529: redirect -> array ref of
6530: 1- seconds before redirect occurs
6531: 2- url to redirect to
6532: 3- whether the side effect should occur
1.315 albertel 6533: (side effect of setting
6534: $env{'internal.head.redirect'} to the url
6535: redirected too)
1.352 albertel 6536: domain -> force to color decorate a page for a specific
6537: domain
6538: function -> force usage of a specific rolish color scheme
6539: bgcolor -> override the default page bgcolor
1.460 albertel 6540: no_auto_mt_title
6541: -> prevent &mt()ing the title arg
1.464 albertel 6542:
1.306 albertel 6543: =cut
6544:
6545: sub headtag {
1.313 albertel 6546: my ($title,$head_extra,$args) = @_;
1.306 albertel 6547:
1.363 albertel 6548: my $function = $args->{'function'} || &get_users_function();
6549: my $domain = $args->{'domain'} || &determinedomain();
6550: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6551: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6552: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6553: #time(),
1.418 albertel 6554: $env{'environment.color.timestamp'},
1.363 albertel 6555: $function,$domain,$bgcolor);
6556:
1.369 www 6557: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6558:
1.308 albertel 6559: my $result =
6560: '<head>'.
1.461 albertel 6561: &font_settings();
1.319 albertel 6562:
1.461 albertel 6563: if (!$args->{'frameset'}) {
6564: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6565: }
1.962 droeschl 6566: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
6567: $result .= Apache::lonxml::display_title();
1.319 albertel 6568: }
1.436 albertel 6569: if (!$args->{'no_nav_bar'}
6570: && !$args->{'only_body'}
6571: && !$args->{'frameset'}) {
6572: $result .= &help_menu_js();
6573: }
1.319 albertel 6574:
1.314 albertel 6575: if (ref($args->{'redirect'})) {
1.414 albertel 6576: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6577: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6578: if (!$inhibit_continue) {
6579: $env{'internal.head.redirect'} = $url;
6580: }
1.313 albertel 6581: $result.=<<ADDMETA
6582: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6583: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6584: ADDMETA
6585: }
1.306 albertel 6586: if (!defined($title)) {
6587: $title = 'The LearningOnline Network with CAPA';
6588: }
1.460 albertel 6589: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6590: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6591: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6592: .$head_extra;
1.962 droeschl 6593: return $result.'</head>';
1.306 albertel 6594: }
6595:
6596: =pod
6597:
1.340 albertel 6598: =item * &font_settings()
6599:
6600: Returns neccessary <meta> to set the proper encoding
6601:
6602: Inputs: none
6603:
6604: =cut
6605:
6606: sub font_settings {
6607: my $headerstring='';
1.647 www 6608: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6609: $headerstring.=
6610: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6611: }
6612: return $headerstring;
6613: }
6614:
1.341 albertel 6615: =pod
6616:
6617: =item * &xml_begin()
6618:
6619: Returns the needed doctype and <html>
6620:
6621: Inputs: none
6622:
6623: =cut
6624:
6625: sub xml_begin {
6626: my $output='';
6627:
6628: if ($env{'browser.mathml'}) {
6629: $output='<?xml version="1.0"?>'
6630: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6631: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6632:
6633: # .'<!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">] >'
6634: .'<!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">'
6635: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6636: .'xmlns="http://www.w3.org/1999/xhtml">';
6637: } else {
1.849 bisitz 6638: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6639: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6640: }
6641: return $output;
6642: }
1.340 albertel 6643:
6644: =pod
6645:
1.306 albertel 6646: =item * &start_page()
6647:
6648: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6649:
1.648 raeburn 6650: Inputs:
6651:
6652: =over 4
6653:
6654: $title - optional title for the page
6655:
6656: $head_extra - optional extra HTML to incude inside the <head>
6657:
6658: $args - additional optional args supported are:
6659:
6660: =over 8
6661:
6662: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6663: arg on
1.814 bisitz 6664: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6665: add_entries -> additional attributes to add to the <body>
6666: domain -> force to color decorate a page for a
1.317 albertel 6667: specific domain
1.648 raeburn 6668: function -> force usage of a specific rolish color
1.317 albertel 6669: scheme
1.648 raeburn 6670: redirect -> see &headtag()
6671: bgcolor -> override the default page bg color
6672: js_ready -> return a string ready for being used in
1.317 albertel 6673: a javascript writeln
1.648 raeburn 6674: html_encode -> return a string ready for being used in
1.320 albertel 6675: a html attribute
1.648 raeburn 6676: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6677: $forcereg arg
1.648 raeburn 6678: frameset -> if true will start with a <frameset>
1.330 albertel 6679: rather than <body>
1.648 raeburn 6680: skip_phases -> hash ref of
1.338 albertel 6681: head -> skip the <html><head> generation
6682: body -> skip all <body> generation
1.648 raeburn 6683: no_auto_mt_title -> prevent &mt()ing the title arg
6684: inherit_jsmath -> when creating popup window in a page,
6685: should it have jsmath forced on by the
6686: current page
1.867 kalberla 6687: bread_crumbs -> Array containing breadcrumbs
6688: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6689:
1.648 raeburn 6690: =back
1.460 albertel 6691:
1.648 raeburn 6692: =back
1.562 albertel 6693:
1.306 albertel 6694: =cut
6695:
6696: sub start_page {
1.309 albertel 6697: my ($title,$head_extra,$args) = @_;
1.318 albertel 6698: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.964 droeschl 6699: #SD
6700: #I don't see why we copy certain elements of %$args to %head_args
6701: #head args is passed to headtag() and this routine only reads those
6702: #keys that are needed. There doesn't happen any writes or any processing
6703: #of other keys.
6704: #proposal: just pass $args to headtag instead of \%head_args and delete
6705: #marked lines
6706: #<- MARK
1.313 albertel 6707: my %head_args;
1.352 albertel 6708: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6709: 'bgcolor','frameset','no_nav_bar','only_body',
6710: 'no_auto_mt_title') {
1.319 albertel 6711: if (defined($args->{$arg})) {
1.324 raeburn 6712: $head_args{$arg} = $args->{$arg};
1.319 albertel 6713: }
1.313 albertel 6714: }
1.964 droeschl 6715: #MARK ->
1.319 albertel 6716:
1.315 albertel 6717: $env{'internal.start_page'}++;
1.338 albertel 6718: my $result;
1.964 droeschl 6719:
1.338 albertel 6720: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.964 droeschl 6721: $result .=
6722: &xml_begin() . &headtag($title,$head_extra,\%head_args);
6723: #replace prev line by
6724: # &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 6725: }
6726:
6727: if (! exists($args->{'skip_phases'}{'body'}) ) {
6728: if ($args->{'frameset'}) {
6729: my $attr_string = &make_attr_string($args->{'force_register'},
6730: $args->{'add_entries'});
6731: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6732: } else {
6733: $result .=
6734: &bodytag($title,
6735: $args->{'function'}, $args->{'add_entries'},
6736: $args->{'only_body'}, $args->{'domain'},
6737: $args->{'force_register'}, $args->{'no_nav_bar'},
1.962 droeschl 6738: $args->{'bgcolor'}, $args);
1.831 bisitz 6739: }
1.330 albertel 6740: }
1.338 albertel 6741:
1.315 albertel 6742: if ($args->{'js_ready'}) {
1.713 kaisler 6743: $result = &js_ready($result);
1.315 albertel 6744: }
1.320 albertel 6745: if ($args->{'html_encode'}) {
1.713 kaisler 6746: $result = &html_encode($result);
6747: }
6748:
1.813 bisitz 6749: # Preparation for new and consistent functionlist at top of screen
6750: # if ($args->{'functionlist'}) {
6751: # $result .= &build_functionlist();
6752: #}
6753:
1.964 droeschl 6754: # Don't add anything more if only_body wanted or in const space
6755: return $result if $args->{'only_body'}
6756: || $env{'request.state'} eq 'construct';
1.813 bisitz 6757:
6758: #Breadcrumbs
1.758 kaisler 6759: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6760: &Apache::lonhtmlcommon::clear_breadcrumbs();
6761: #if any br links exists, add them to the breadcrumbs
6762: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6763: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6764: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6765: }
6766: }
6767:
6768: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6769: if(exists($args->{'bread_crumbs_component'})){
6770: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6771: }else{
6772: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6773: }
1.320 albertel 6774: }
1.315 albertel 6775: return $result;
1.306 albertel 6776: }
6777:
6778: sub end_page {
1.315 albertel 6779: my ($args) = @_;
6780: $env{'internal.end_page'}++;
1.330 albertel 6781: my $result;
1.335 albertel 6782: if ($args->{'discussion'}) {
6783: my ($target,$parser);
6784: if (ref($args->{'discussion'})) {
6785: ($target,$parser) =($args->{'discussion'}{'target'},
6786: $args->{'discussion'}{'parser'});
6787: }
6788: $result .= &Apache::lonxml::xmlend($target,$parser);
6789: }
6790:
1.330 albertel 6791: if ($args->{'frameset'}) {
6792: $result .= '</frameset>';
6793: } else {
1.635 raeburn 6794: $result .= &endbodytag($args);
1.330 albertel 6795: }
6796: $result .= "\n</html>";
6797:
1.315 albertel 6798: if ($args->{'js_ready'}) {
1.317 albertel 6799: $result = &js_ready($result);
1.315 albertel 6800: }
1.335 albertel 6801:
1.320 albertel 6802: if ($args->{'html_encode'}) {
6803: $result = &html_encode($result);
6804: }
1.335 albertel 6805:
1.315 albertel 6806: return $result;
6807: }
6808:
1.320 albertel 6809: sub html_encode {
6810: my ($result) = @_;
6811:
1.322 albertel 6812: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6813:
6814: return $result;
6815: }
1.317 albertel 6816: sub js_ready {
6817: my ($result) = @_;
6818:
1.323 albertel 6819: $result =~ s/[\n\r]/ /xmsg;
6820: $result =~ s/\\/\\\\/xmsg;
6821: $result =~ s/'/\\'/xmsg;
1.372 albertel 6822: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6823:
6824: return $result;
6825: }
6826:
1.315 albertel 6827: sub validate_page {
6828: if ( exists($env{'internal.start_page'})
1.316 albertel 6829: && $env{'internal.start_page'} > 1) {
6830: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6831: $env{'internal.start_page'}.' '.
1.316 albertel 6832: $ENV{'request.filename'});
1.315 albertel 6833: }
6834: if ( exists($env{'internal.end_page'})
1.316 albertel 6835: && $env{'internal.end_page'} > 1) {
6836: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6837: $env{'internal.end_page'}.' '.
1.316 albertel 6838: $env{'request.filename'});
1.315 albertel 6839: }
6840: if ( exists($env{'internal.start_page'})
6841: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6842: &Apache::lonnet::logthis('start_page called without end_page '.
6843: $env{'request.filename'});
1.315 albertel 6844: }
6845: if ( ! exists($env{'internal.start_page'})
6846: && exists($env{'internal.end_page'})) {
1.316 albertel 6847: &Apache::lonnet::logthis('end_page called without start_page'.
6848: $env{'request.filename'});
1.315 albertel 6849: }
1.306 albertel 6850: }
1.315 albertel 6851:
1.318 albertel 6852: sub simple_error_page {
6853: my ($r,$title,$msg) = @_;
6854: my $page =
6855: &Apache::loncommon::start_page($title).
6856: &mt($msg).
6857: &Apache::loncommon::end_page();
6858: if (ref($r)) {
6859: $r->print($page);
1.327 albertel 6860: return;
1.318 albertel 6861: }
6862: return $page;
6863: }
1.347 albertel 6864:
6865: {
1.610 albertel 6866: my @row_count;
1.961 onken 6867:
6868: sub start_data_table_count {
6869: unshift(@row_count, 0);
6870: return;
6871: }
6872:
6873: sub end_data_table_count {
6874: shift(@row_count);
6875: return;
6876: }
6877:
1.347 albertel 6878: sub start_data_table {
1.422 albertel 6879: my ($add_class) = @_;
6880: my $css_class = (join(' ','LC_data_table',$add_class));
1.961 onken 6881: &start_data_table_count();
1.422 albertel 6882: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6883: }
6884:
6885: sub end_data_table {
1.961 onken 6886: &end_data_table_count();
1.389 albertel 6887: return '</table>'."\n";;
1.347 albertel 6888: }
6889:
6890: sub start_data_table_row {
1.974 wenzelju 6891: my ($add_class, $id) = @_;
1.610 albertel 6892: $row_count[0]++;
6893: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6894: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 6895: $id = (' id="'.$id.'"') unless ($id eq '');
6896: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 6897: }
1.471 banghart 6898:
6899: sub continue_data_table_row {
1.974 wenzelju 6900: my ($add_class, $id) = @_;
1.610 albertel 6901: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 6902: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
6903: $id = (' id="'.$id.'"') unless ($id eq '');
6904: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 6905: }
1.347 albertel 6906:
6907: sub end_data_table_row {
1.389 albertel 6908: return '</tr>'."\n";;
1.347 albertel 6909: }
1.367 www 6910:
1.421 albertel 6911: sub start_data_table_empty_row {
1.707 bisitz 6912: # $row_count[0]++;
1.421 albertel 6913: return '<tr class="LC_empty_row" >'."\n";;
6914: }
6915:
6916: sub end_data_table_empty_row {
6917: return '</tr>'."\n";;
6918: }
6919:
1.367 www 6920: sub start_data_table_header_row {
1.389 albertel 6921: return '<tr class="LC_header_row">'."\n";;
1.367 www 6922: }
6923:
6924: sub end_data_table_header_row {
1.389 albertel 6925: return '</tr>'."\n";;
1.367 www 6926: }
1.890 droeschl 6927:
6928: sub data_table_caption {
6929: my $caption = shift;
6930: return "<caption class=\"LC_caption\">$caption</caption>";
6931: }
1.347 albertel 6932: }
6933:
1.548 albertel 6934: =pod
6935:
6936: =item * &inhibit_menu_check($arg)
6937:
6938: Checks for a inhibitmenu state and generates output to preserve it
6939:
6940: Inputs: $arg - can be any of
6941: - undef - in which case the return value is a string
6942: to add into arguments list of a uri
6943: - 'input' - in which case the return value is a HTML
6944: <form> <input> field of type hidden to
6945: preserve the value
6946: - a url - in which case the return value is the url with
6947: the neccesary cgi args added to preserve the
6948: inhibitmenu state
6949: - a ref to a url - no return value, but the string is
6950: updated to include the neccessary cgi
6951: args to preserve the inhibitmenu state
6952:
6953: =cut
6954:
6955: sub inhibit_menu_check {
6956: my ($arg) = @_;
6957: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6958: if ($arg eq 'input') {
6959: if ($env{'form.inhibitmenu'}) {
6960: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6961: } else {
6962: return
6963: }
6964: }
6965: if ($env{'form.inhibitmenu'}) {
6966: if (ref($arg)) {
6967: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6968: } elsif ($arg eq '') {
6969: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6970: } else {
6971: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6972: }
6973: }
6974: if (!ref($arg)) {
6975: return $arg;
6976: }
6977: }
6978:
1.251 albertel 6979: ###############################################
1.182 matthew 6980:
6981: =pod
6982:
1.549 albertel 6983: =back
6984:
6985: =head1 User Information Routines
6986:
6987: =over 4
6988:
1.405 albertel 6989: =item * &get_users_function()
1.182 matthew 6990:
6991: Used by &bodytag to determine the current users primary role.
6992: Returns either 'student','coordinator','admin', or 'author'.
6993:
6994: =cut
6995:
6996: ###############################################
6997: sub get_users_function {
1.815 tempelho 6998: my $function = 'norole';
1.818 tempelho 6999: if ($env{'request.role'}=~/^(st)/) {
7000: $function='student';
7001: }
1.907 raeburn 7002: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7003: $function='coordinator';
7004: }
1.258 albertel 7005: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7006: $function='admin';
7007: }
1.826 bisitz 7008: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7009: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7010: $function='author';
7011: }
7012: return $function;
1.54 www 7013: }
1.99 www 7014:
7015: ###############################################
7016:
1.233 raeburn 7017: =pod
7018:
1.821 raeburn 7019: =item * &show_course()
7020:
7021: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7022: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7023:
7024: Inputs:
7025: None
7026:
7027: Outputs:
7028: Scalar: 1 if 'Course' to be used, 0 otherwise.
7029:
7030: =cut
7031:
7032: ###############################################
7033: sub show_course {
7034: my $course = !$env{'user.adv'};
7035: if (!$env{'user.adv'}) {
7036: foreach my $env (keys(%env)) {
7037: next if ($env !~ m/^user\.priv\./);
7038: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7039: $course = 0;
7040: last;
7041: }
7042: }
7043: }
7044: return $course;
7045: }
7046:
7047: ###############################################
7048:
7049: =pod
7050:
1.542 raeburn 7051: =item * &check_user_status()
1.274 raeburn 7052:
7053: Determines current status of supplied role for a
7054: specific user. Roles can be active, previous or future.
7055:
7056: Inputs:
7057: user's domain, user's username, course's domain,
1.375 raeburn 7058: course's number, optional section ID.
1.274 raeburn 7059:
7060: Outputs:
7061: role status: active, previous or future.
7062:
7063: =cut
7064:
7065: sub check_user_status {
1.412 raeburn 7066: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 7067: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
7068: my @uroles = keys %userinfo;
7069: my $srchstr;
7070: my $active_chk = 'none';
1.412 raeburn 7071: my $now = time;
1.274 raeburn 7072: if (@uroles > 0) {
1.908 raeburn 7073: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7074: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7075: } else {
1.412 raeburn 7076: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7077: }
7078: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7079: my $role_end = 0;
7080: my $role_start = 0;
7081: $active_chk = 'active';
1.412 raeburn 7082: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7083: $role_end = $1;
7084: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7085: $role_start = $1;
1.274 raeburn 7086: }
7087: }
7088: if ($role_start > 0) {
1.412 raeburn 7089: if ($now < $role_start) {
1.274 raeburn 7090: $active_chk = 'future';
7091: }
7092: }
7093: if ($role_end > 0) {
1.412 raeburn 7094: if ($now > $role_end) {
1.274 raeburn 7095: $active_chk = 'previous';
7096: }
7097: }
7098: }
7099: }
7100: return $active_chk;
7101: }
7102:
7103: ###############################################
7104:
7105: =pod
7106:
1.405 albertel 7107: =item * &get_sections()
1.233 raeburn 7108:
7109: Determines all the sections for a course including
7110: sections with students and sections containing other roles.
1.419 raeburn 7111: Incoming parameters:
7112:
7113: 1. domain
7114: 2. course number
7115: 3. reference to array containing roles for which sections should
7116: be gathered (optional).
7117: 4. reference to array containing status types for which sections
7118: should be gathered (optional).
7119:
7120: If the third argument is undefined, sections are gathered for any role.
7121: If the fourth argument is undefined, sections are gathered for any status.
7122: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7123:
1.374 raeburn 7124: Returns section hash (keys are section IDs, values are
7125: number of users in each section), subject to the
1.419 raeburn 7126: optional roles filter, optional status filter
1.233 raeburn 7127:
7128: =cut
7129:
7130: ###############################################
7131: sub get_sections {
1.419 raeburn 7132: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7133: if (!defined($cdom) || !defined($cnum)) {
7134: my $cid = $env{'request.course.id'};
7135:
7136: return if (!defined($cid));
7137:
7138: $cdom = $env{'course.'.$cid.'.domain'};
7139: $cnum = $env{'course.'.$cid.'.num'};
7140: }
7141:
7142: my %sectioncount;
1.419 raeburn 7143: my $now = time;
1.240 albertel 7144:
1.366 albertel 7145: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7146: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7147: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7148: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7149: my $start_index = &Apache::loncoursedata::CL_START();
7150: my $end_index = &Apache::loncoursedata::CL_END();
7151: my $status;
1.366 albertel 7152: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7153: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7154: $data->[$status_index],
7155: $data->[$start_index],
7156: $data->[$end_index]);
7157: if ($stu_status eq 'Active') {
7158: $status = 'active';
7159: } elsif ($end < $now) {
7160: $status = 'previous';
7161: } elsif ($start > $now) {
7162: $status = 'future';
7163: }
7164: if ($section ne '-1' && $section !~ /^\s*$/) {
7165: if ((!defined($possible_status)) || (($status ne '') &&
7166: (grep/^\Q$status\E$/,@{$possible_status}))) {
7167: $sectioncount{$section}++;
7168: }
1.240 albertel 7169: }
7170: }
7171: }
7172: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7173: foreach my $user (sort(keys(%courseroles))) {
7174: if ($user !~ /^(\w{2})/) { next; }
7175: my ($role) = ($user =~ /^(\w{2})/);
7176: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7177: my ($section,$status);
1.240 albertel 7178: if ($role eq 'cr' &&
7179: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7180: $section=$1;
7181: }
7182: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7183: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7184: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7185: if ($end == -1 && $start == -1) {
7186: next; #deleted role
7187: }
7188: if (!defined($possible_status)) {
7189: $sectioncount{$section}++;
7190: } else {
7191: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7192: $status = 'active';
7193: } elsif ($end < $now) {
7194: $status = 'future';
7195: } elsif ($start > $now) {
7196: $status = 'previous';
7197: }
7198: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7199: $sectioncount{$section}++;
7200: }
7201: }
1.233 raeburn 7202: }
1.366 albertel 7203: return %sectioncount;
1.233 raeburn 7204: }
7205:
1.274 raeburn 7206: ###############################################
1.294 raeburn 7207:
7208: =pod
1.405 albertel 7209:
7210: =item * &get_course_users()
7211:
1.275 raeburn 7212: Retrieves usernames:domains for users in the specified course
7213: with specific role(s), and access status.
7214:
7215: Incoming parameters:
1.277 albertel 7216: 1. course domain
7217: 2. course number
7218: 3. access status: users must have - either active,
1.275 raeburn 7219: previous, future, or all.
1.277 albertel 7220: 4. reference to array of permissible roles
1.288 raeburn 7221: 5. reference to array of section restrictions (optional)
7222: 6. reference to results object (hash of hashes).
7223: 7. reference to optional userdata hash
1.609 raeburn 7224: 8. reference to optional statushash
1.630 raeburn 7225: 9. flag if privileged users (except those set to unhide in
7226: course settings) should be excluded
1.609 raeburn 7227: Keys of top level results hash are roles.
1.275 raeburn 7228: Keys of inner hashes are username:domain, with
7229: values set to access type.
1.288 raeburn 7230: Optional userdata hash returns an array with arguments in the
7231: same order as loncoursedata::get_classlist() for student data.
7232:
1.609 raeburn 7233: Optional statushash returns
7234:
1.288 raeburn 7235: Entries for end, start, section and status are blank because
7236: of the possibility of multiple values for non-student roles.
7237:
1.275 raeburn 7238: =cut
1.405 albertel 7239:
1.275 raeburn 7240: ###############################################
1.405 albertel 7241:
1.275 raeburn 7242: sub get_course_users {
1.630 raeburn 7243: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7244: my %idx = ();
1.419 raeburn 7245: my %seclists;
1.288 raeburn 7246:
7247: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7248: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7249: $idx{end} = &Apache::loncoursedata::CL_END();
7250: $idx{start} = &Apache::loncoursedata::CL_START();
7251: $idx{id} = &Apache::loncoursedata::CL_ID();
7252: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7253: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7254: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7255:
1.290 albertel 7256: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7257: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7258: my $now = time;
1.277 albertel 7259: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7260: my $match = 0;
1.412 raeburn 7261: my $secmatch = 0;
1.419 raeburn 7262: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7263: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7264: if ($section eq '') {
7265: $section = 'none';
7266: }
1.291 albertel 7267: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7268: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7269: $secmatch = 1;
7270: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7271: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7272: $secmatch = 1;
7273: }
7274: } else {
1.419 raeburn 7275: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7276: $secmatch = 1;
7277: }
1.290 albertel 7278: }
1.412 raeburn 7279: if (!$secmatch) {
7280: next;
7281: }
1.419 raeburn 7282: }
1.275 raeburn 7283: if (defined($$types{'active'})) {
1.288 raeburn 7284: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7285: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7286: $match = 1;
1.275 raeburn 7287: }
7288: }
7289: if (defined($$types{'previous'})) {
1.609 raeburn 7290: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7291: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7292: $match = 1;
1.275 raeburn 7293: }
7294: }
7295: if (defined($$types{'future'})) {
1.609 raeburn 7296: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7297: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7298: $match = 1;
1.275 raeburn 7299: }
7300: }
1.609 raeburn 7301: if ($match) {
7302: push(@{$seclists{$student}},$section);
7303: if (ref($userdata) eq 'HASH') {
7304: $$userdata{$student} = $$classlist{$student};
7305: }
7306: if (ref($statushash) eq 'HASH') {
7307: $statushash->{$student}{'st'}{$section} = $status;
7308: }
1.288 raeburn 7309: }
1.275 raeburn 7310: }
7311: }
1.412 raeburn 7312: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7313: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7314: my $now = time;
1.609 raeburn 7315: my %displaystatus = ( previous => 'Expired',
7316: active => 'Active',
7317: future => 'Future',
7318: );
1.630 raeburn 7319: my %nothide;
7320: if ($hidepriv) {
7321: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7322: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7323: if ($user !~ /:/) {
7324: $nothide{join(':',split(/[\@]/,$user))}=1;
7325: } else {
7326: $nothide{$user} = 1;
7327: }
7328: }
7329: }
1.439 raeburn 7330: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7331: my $match = 0;
1.412 raeburn 7332: my $secmatch = 0;
1.439 raeburn 7333: my $status;
1.412 raeburn 7334: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7335: $user =~ s/:$//;
1.439 raeburn 7336: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7337: if ($end == -1 || $start == -1) {
7338: next;
7339: }
7340: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7341: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7342: my ($uname,$udom) = split(/:/,$user);
7343: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7344: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7345: $secmatch = 1;
7346: } elsif ($usec eq '') {
1.420 albertel 7347: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7348: $secmatch = 1;
7349: }
7350: } else {
7351: if (grep(/^\Q$usec\E$/,@{$sections})) {
7352: $secmatch = 1;
7353: }
7354: }
7355: if (!$secmatch) {
7356: next;
7357: }
1.288 raeburn 7358: }
1.419 raeburn 7359: if ($usec eq '') {
7360: $usec = 'none';
7361: }
1.275 raeburn 7362: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7363: if ($hidepriv) {
7364: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7365: (!$nothide{$uname.':'.$udom})) {
7366: next;
7367: }
7368: }
1.503 raeburn 7369: if ($end > 0 && $end < $now) {
1.439 raeburn 7370: $status = 'previous';
7371: } elsif ($start > $now) {
7372: $status = 'future';
7373: } else {
7374: $status = 'active';
7375: }
1.277 albertel 7376: foreach my $type (keys(%{$types})) {
1.275 raeburn 7377: if ($status eq $type) {
1.420 albertel 7378: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7379: push(@{$$users{$role}{$user}},$type);
7380: }
1.288 raeburn 7381: $match = 1;
7382: }
7383: }
1.419 raeburn 7384: if (($match) && (ref($userdata) eq 'HASH')) {
7385: if (!exists($$userdata{$uname.':'.$udom})) {
7386: &get_user_info($udom,$uname,\%idx,$userdata);
7387: }
1.420 albertel 7388: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7389: push(@{$seclists{$uname.':'.$udom}},$usec);
7390: }
1.609 raeburn 7391: if (ref($statushash) eq 'HASH') {
7392: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7393: }
1.275 raeburn 7394: }
7395: }
7396: }
7397: }
1.290 albertel 7398: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7399: if ((defined($cdom)) && (defined($cnum))) {
7400: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7401: if ( defined($csettings{'internal.courseowner'}) ) {
7402: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7403: next if ($owner eq '');
7404: my ($ownername,$ownerdom);
7405: if ($owner =~ /^([^:]+):([^:]+)$/) {
7406: $ownername = $1;
7407: $ownerdom = $2;
7408: } else {
7409: $ownername = $owner;
7410: $ownerdom = $cdom;
7411: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7412: }
7413: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7414: if (defined($userdata) &&
1.609 raeburn 7415: !exists($$userdata{$owner})) {
7416: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7417: if (!grep(/^none$/,@{$seclists{$owner}})) {
7418: push(@{$seclists{$owner}},'none');
7419: }
7420: if (ref($statushash) eq 'HASH') {
7421: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7422: }
1.290 albertel 7423: }
1.279 raeburn 7424: }
7425: }
7426: }
1.419 raeburn 7427: foreach my $user (keys(%seclists)) {
7428: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7429: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7430: }
1.275 raeburn 7431: }
7432: return;
7433: }
7434:
1.288 raeburn 7435: sub get_user_info {
7436: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7437: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7438: &plainname($uname,$udom,'lastname');
1.291 albertel 7439: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7440: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7441: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7442: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7443: return;
7444: }
1.275 raeburn 7445:
1.472 raeburn 7446: ###############################################
7447:
7448: =pod
7449:
7450: =item * &get_user_quota()
7451:
7452: Retrieves quota assigned for storage of portfolio files for a user
7453:
7454: Incoming parameters:
7455: 1. user's username
7456: 2. user's domain
7457:
7458: Returns:
1.536 raeburn 7459: 1. Disk quota (in Mb) assigned to student.
7460: 2. (Optional) Type of setting: custom or default
7461: (individually assigned or default for user's
7462: institutional status).
7463: 3. (Optional) - User's institutional status (e.g., faculty, staff
7464: or student - types as defined in localenroll::inst_usertypes
7465: for user's domain, which determines default quota for user.
7466: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7467:
7468: If a value has been stored in the user's environment,
1.536 raeburn 7469: it will return that, otherwise it returns the maximal default
7470: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7471:
7472: =cut
7473:
7474: ###############################################
7475:
7476:
7477: sub get_user_quota {
7478: my ($uname,$udom) = @_;
1.536 raeburn 7479: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7480: if (!defined($udom)) {
7481: $udom = $env{'user.domain'};
7482: }
7483: if (!defined($uname)) {
7484: $uname = $env{'user.name'};
7485: }
7486: if (($udom eq '' || $uname eq '') ||
7487: ($udom eq 'public') && ($uname eq 'public')) {
7488: $quota = 0;
1.536 raeburn 7489: $quotatype = 'default';
7490: $defquota = 0;
1.472 raeburn 7491: } else {
1.536 raeburn 7492: my $inststatus;
1.472 raeburn 7493: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7494: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7495: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7496: } else {
1.536 raeburn 7497: my %userenv =
7498: &Apache::lonnet::get('environment',['portfolioquota',
7499: 'inststatus'],$udom,$uname);
1.472 raeburn 7500: my ($tmp) = keys(%userenv);
7501: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7502: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7503: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7504: } else {
7505: undef(%userenv);
7506: }
7507: }
1.536 raeburn 7508: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7509: if ($quota eq '') {
1.536 raeburn 7510: $quota = $defquota;
7511: $quotatype = 'default';
7512: } else {
7513: $quotatype = 'custom';
1.472 raeburn 7514: }
7515: }
1.536 raeburn 7516: if (wantarray) {
7517: return ($quota,$quotatype,$settingstatus,$defquota);
7518: } else {
7519: return $quota;
7520: }
1.472 raeburn 7521: }
7522:
7523: ###############################################
7524:
7525: =pod
7526:
7527: =item * &default_quota()
7528:
1.536 raeburn 7529: Retrieves default quota assigned for storage of user portfolio files,
7530: given an (optional) user's institutional status.
1.472 raeburn 7531:
7532: Incoming parameters:
7533: 1. domain
1.536 raeburn 7534: 2. (Optional) institutional status(es). This is a : separated list of
7535: status types (e.g., faculty, staff, student etc.)
7536: which apply to the user for whom the default is being retrieved.
7537: If the institutional status string in undefined, the domain
7538: default quota will be returned.
1.472 raeburn 7539:
7540: Returns:
7541: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7542: 2. (Optional) institutional type which determined the value of the
7543: default quota.
1.472 raeburn 7544:
7545: If a value has been stored in the domain's configuration db,
7546: it will return that, otherwise it returns 20 (for backwards
7547: compatibility with domains which have not set up a configuration
7548: db file; the original statically defined portfolio quota was 20 Mb).
7549:
1.536 raeburn 7550: If the user's status includes multiple types (e.g., staff and student),
7551: the largest default quota which applies to the user determines the
7552: default quota returned.
7553:
1.780 raeburn 7554: =back
7555:
1.472 raeburn 7556: =cut
7557:
7558: ###############################################
7559:
7560:
7561: sub default_quota {
1.536 raeburn 7562: my ($udom,$inststatus) = @_;
7563: my ($defquota,$settingstatus);
7564: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7565: ['quotas'],$udom);
7566: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7567: if ($inststatus ne '') {
1.765 raeburn 7568: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7569: foreach my $item (@statuses) {
1.711 raeburn 7570: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7571: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7572: if ($defquota eq '') {
7573: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7574: $settingstatus = $item;
7575: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7576: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7577: $settingstatus = $item;
7578: }
7579: }
7580: } else {
7581: if ($quotahash{'quotas'}{$item} ne '') {
7582: if ($defquota eq '') {
7583: $defquota = $quotahash{'quotas'}{$item};
7584: $settingstatus = $item;
7585: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7586: $defquota = $quotahash{'quotas'}{$item};
7587: $settingstatus = $item;
7588: }
1.536 raeburn 7589: }
7590: }
7591: }
7592: }
7593: if ($defquota eq '') {
1.711 raeburn 7594: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7595: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7596: } else {
7597: $defquota = $quotahash{'quotas'}{'default'};
7598: }
1.536 raeburn 7599: $settingstatus = 'default';
7600: }
7601: } else {
7602: $settingstatus = 'default';
7603: $defquota = 20;
7604: }
7605: if (wantarray) {
7606: return ($defquota,$settingstatus);
1.472 raeburn 7607: } else {
1.536 raeburn 7608: return $defquota;
1.472 raeburn 7609: }
7610: }
7611:
1.384 raeburn 7612: sub get_secgrprole_info {
7613: my ($cdom,$cnum,$needroles,$type) = @_;
7614: my %sections_count = &get_sections($cdom,$cnum);
7615: my @sections = (sort {$a <=> $b} keys(%sections_count));
7616: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7617: my @groups = sort(keys(%curr_groups));
7618: my $allroles = [];
7619: my $rolehash;
7620: my $accesshash = {
7621: active => 'Currently has access',
7622: future => 'Will have future access',
7623: previous => 'Previously had access',
7624: };
7625: if ($needroles) {
7626: $rolehash = {'all' => 'all'};
1.385 albertel 7627: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7628: if (&Apache::lonnet::error(%user_roles)) {
7629: undef(%user_roles);
7630: }
7631: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7632: my ($role)=split(/\:/,$item,2);
7633: if ($role eq 'cr') { next; }
7634: if ($role =~ /^cr/) {
7635: $$rolehash{$role} = (split('/',$role))[3];
7636: } else {
7637: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7638: }
7639: }
7640: foreach my $key (sort(keys(%{$rolehash}))) {
7641: push(@{$allroles},$key);
7642: }
7643: push (@{$allroles},'st');
7644: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7645: }
7646: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7647: }
7648:
1.555 raeburn 7649: sub user_picker {
1.627 raeburn 7650: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7651: my $currdom = $dom;
7652: my %curr_selected = (
7653: srchin => 'dom',
1.580 raeburn 7654: srchby => 'lastname',
1.555 raeburn 7655: );
7656: my $srchterm;
1.625 raeburn 7657: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7658: if ($srch->{'srchby'} ne '') {
7659: $curr_selected{'srchby'} = $srch->{'srchby'};
7660: }
7661: if ($srch->{'srchin'} ne '') {
7662: $curr_selected{'srchin'} = $srch->{'srchin'};
7663: }
7664: if ($srch->{'srchtype'} ne '') {
7665: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7666: }
7667: if ($srch->{'srchdomain'} ne '') {
7668: $currdom = $srch->{'srchdomain'};
7669: }
7670: $srchterm = $srch->{'srchterm'};
7671: }
7672: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7673: 'usr' => 'Search criteria',
1.563 raeburn 7674: 'doma' => 'Domain/institution to search',
1.558 albertel 7675: 'uname' => 'username',
7676: 'lastname' => 'last name',
1.555 raeburn 7677: 'lastfirst' => 'last name, first name',
1.558 albertel 7678: 'crs' => 'in this course',
1.576 raeburn 7679: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7680: 'alc' => 'all LON-CAPA',
1.573 raeburn 7681: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7682: 'exact' => 'is',
7683: 'contains' => 'contains',
1.569 raeburn 7684: 'begins' => 'begins with',
1.571 raeburn 7685: 'youm' => "You must include some text to search for.",
7686: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7687: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7688: 'yomc' => "You must choose a domain when using an institutional directory search.",
7689: 'ymcd' => "You must choose a domain when using a domain search.",
7690: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7691: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7692: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7693: );
1.563 raeburn 7694: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7695: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7696:
7697: my @srchins = ('crs','dom','alc','instd');
7698:
7699: foreach my $option (@srchins) {
7700: # FIXME 'alc' option unavailable until
7701: # loncreateuser::print_user_query_page()
7702: # has been completed.
7703: next if ($option eq 'alc');
1.880 raeburn 7704: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7705: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7706: if ($curr_selected{'srchin'} eq $option) {
7707: $srchinsel .= '
7708: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7709: } else {
7710: $srchinsel .= '
7711: <option value="'.$option.'">'.$lt{$option}.'</option>';
7712: }
1.555 raeburn 7713: }
1.563 raeburn 7714: $srchinsel .= "\n </select>\n";
1.555 raeburn 7715:
7716: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7717: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7718: if ($curr_selected{'srchby'} eq $option) {
7719: $srchbysel .= '
7720: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7721: } else {
7722: $srchbysel .= '
7723: <option value="'.$option.'">'.$lt{$option}.'</option>';
7724: }
7725: }
7726: $srchbysel .= "\n </select>\n";
7727:
7728: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7729: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7730: if ($curr_selected{'srchtype'} eq $option) {
7731: $srchtypesel .= '
7732: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7733: } else {
7734: $srchtypesel .= '
7735: <option value="'.$option.'">'.$lt{$option}.'</option>';
7736: }
7737: }
7738: $srchtypesel .= "\n </select>\n";
7739:
1.558 albertel 7740: my ($newuserscript,$new_user_create);
1.556 raeburn 7741:
7742: if ($forcenewuser) {
1.576 raeburn 7743: if (ref($srch) eq 'HASH') {
7744: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7745: if ($cancreate) {
7746: $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>';
7747: } else {
1.799 bisitz 7748: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7749: my %usertypetext = (
7750: official => 'institutional',
7751: unofficial => 'non-institutional',
7752: );
1.799 bisitz 7753: $new_user_create = '<p class="LC_warning">'
7754: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7755: .' '
7756: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7757: ,'<a href="'.$helplink.'">','</a>')
7758: .'</p><br />';
1.627 raeburn 7759: }
1.576 raeburn 7760: }
7761: }
7762:
1.556 raeburn 7763: $newuserscript = <<"ENDSCRIPT";
7764:
1.570 raeburn 7765: function setSearch(createnew,callingForm) {
1.556 raeburn 7766: if (createnew == 1) {
1.570 raeburn 7767: for (var i=0; i<callingForm.srchby.length; i++) {
7768: if (callingForm.srchby.options[i].value == 'uname') {
7769: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7770: }
7771: }
1.570 raeburn 7772: for (var i=0; i<callingForm.srchin.length; i++) {
7773: if ( callingForm.srchin.options[i].value == 'dom') {
7774: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7775: }
7776: }
1.570 raeburn 7777: for (var i=0; i<callingForm.srchtype.length; i++) {
7778: if (callingForm.srchtype.options[i].value == 'exact') {
7779: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7780: }
7781: }
1.570 raeburn 7782: for (var i=0; i<callingForm.srchdomain.length; i++) {
7783: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7784: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7785: }
7786: }
7787: }
7788: }
7789: ENDSCRIPT
1.558 albertel 7790:
1.556 raeburn 7791: }
7792:
1.555 raeburn 7793: my $output = <<"END_BLOCK";
1.556 raeburn 7794: <script type="text/javascript">
1.824 bisitz 7795: // <![CDATA[
1.570 raeburn 7796: function validateEntry(callingForm) {
1.558 albertel 7797:
1.556 raeburn 7798: var checkok = 1;
1.558 albertel 7799: var srchin;
1.570 raeburn 7800: for (var i=0; i<callingForm.srchin.length; i++) {
7801: if ( callingForm.srchin[i].checked ) {
7802: srchin = callingForm.srchin[i].value;
1.558 albertel 7803: }
7804: }
7805:
1.570 raeburn 7806: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7807: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7808: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7809: var srchterm = callingForm.srchterm.value;
7810: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7811: var msg = "";
7812:
7813: if (srchterm == "") {
7814: checkok = 0;
1.571 raeburn 7815: msg += "$lt{'youm'}\\n";
1.556 raeburn 7816: }
7817:
1.569 raeburn 7818: if (srchtype== 'begins') {
7819: if (srchterm.length < 2) {
7820: checkok = 0;
1.571 raeburn 7821: msg += "$lt{'thte'}\\n";
1.569 raeburn 7822: }
7823: }
7824:
1.556 raeburn 7825: if (srchtype== 'contains') {
7826: if (srchterm.length < 3) {
7827: checkok = 0;
1.571 raeburn 7828: msg += "$lt{'thet'}\\n";
1.556 raeburn 7829: }
7830: }
7831: if (srchin == 'instd') {
7832: if (srchdomain == '') {
7833: checkok = 0;
1.571 raeburn 7834: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7835: }
7836: }
7837: if (srchin == 'dom') {
7838: if (srchdomain == '') {
7839: checkok = 0;
1.571 raeburn 7840: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7841: }
7842: }
7843: if (srchby == 'lastfirst') {
7844: if (srchterm.indexOf(",") == -1) {
7845: checkok = 0;
1.571 raeburn 7846: msg += "$lt{'whus'}\\n";
1.556 raeburn 7847: }
7848: if (srchterm.indexOf(",") == srchterm.length -1) {
7849: checkok = 0;
1.571 raeburn 7850: msg += "$lt{'whse'}\\n";
1.556 raeburn 7851: }
7852: }
7853: if (checkok == 0) {
1.571 raeburn 7854: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7855: return;
7856: }
7857: if (checkok == 1) {
1.570 raeburn 7858: callingForm.submit();
1.556 raeburn 7859: }
7860: }
7861:
7862: $newuserscript
7863:
1.824 bisitz 7864: // ]]>
1.556 raeburn 7865: </script>
1.558 albertel 7866:
7867: $new_user_create
7868:
1.555 raeburn 7869: END_BLOCK
1.558 albertel 7870:
1.876 raeburn 7871: $output .= &Apache::lonhtmlcommon::start_pick_box().
7872: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7873: $domform.
7874: &Apache::lonhtmlcommon::row_closure().
7875: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7876: $srchbysel.
7877: $srchtypesel.
7878: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7879: $srchinsel.
7880: &Apache::lonhtmlcommon::row_closure(1).
7881: &Apache::lonhtmlcommon::end_pick_box().
7882: '<br />';
1.555 raeburn 7883: return $output;
7884: }
7885:
1.612 raeburn 7886: sub user_rule_check {
1.615 raeburn 7887: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7888: my $response;
7889: if (ref($usershash) eq 'HASH') {
7890: foreach my $user (keys(%{$usershash})) {
7891: my ($uname,$udom) = split(/:/,$user);
7892: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7893: my ($id,$newuser);
1.612 raeburn 7894: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7895: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7896: $id = $usershash->{$user}->{'id'};
7897: }
7898: my $inst_response;
7899: if (ref($checks) eq 'HASH') {
7900: if (defined($checks->{'username'})) {
1.615 raeburn 7901: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7902: &Apache::lonnet::get_instuser($udom,$uname);
7903: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7904: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7905: &Apache::lonnet::get_instuser($udom,undef,$id);
7906: }
1.615 raeburn 7907: } else {
7908: ($inst_response,%{$inst_results->{$user}}) =
7909: &Apache::lonnet::get_instuser($udom,$uname);
7910: return;
1.612 raeburn 7911: }
1.615 raeburn 7912: if (!$got_rules->{$udom}) {
1.612 raeburn 7913: my %domconfig = &Apache::lonnet::get_dom('configuration',
7914: ['usercreation'],$udom);
7915: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7916: foreach my $item ('username','id') {
1.612 raeburn 7917: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7918: $$curr_rules{$udom}{$item} =
7919: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7920: }
7921: }
7922: }
1.615 raeburn 7923: $got_rules->{$udom} = 1;
1.585 raeburn 7924: }
1.612 raeburn 7925: foreach my $item (keys(%{$checks})) {
7926: if (ref($$curr_rules{$udom}) eq 'HASH') {
7927: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7928: if (@{$$curr_rules{$udom}{$item}} > 0) {
7929: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7930: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7931: if ($rule_check{$rule}) {
7932: $$rulematch{$user}{$item} = $rule;
7933: if ($inst_response eq 'ok') {
1.615 raeburn 7934: if (ref($inst_results) eq 'HASH') {
7935: if (ref($inst_results->{$user}) eq 'HASH') {
7936: if (keys(%{$inst_results->{$user}}) == 0) {
7937: $$alerts{$item}{$udom}{$uname} = 1;
7938: }
1.612 raeburn 7939: }
7940: }
1.615 raeburn 7941: }
7942: last;
1.585 raeburn 7943: }
7944: }
7945: }
7946: }
7947: }
7948: }
7949: }
7950: }
1.612 raeburn 7951: return;
7952: }
7953:
7954: sub user_rule_formats {
7955: my ($domain,$domdesc,$curr_rules,$check) = @_;
7956: my %text = (
7957: 'username' => 'Usernames',
7958: 'id' => 'IDs',
7959: );
7960: my $output;
7961: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7962: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7963: if (@{$ruleorder} > 0) {
7964: $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>';
7965: foreach my $rule (@{$ruleorder}) {
7966: if (ref($curr_rules) eq 'ARRAY') {
7967: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7968: if (ref($rules->{$rule}) eq 'HASH') {
7969: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7970: $rules->{$rule}{'desc'}.'</li>';
7971: }
7972: }
7973: }
7974: }
7975: $output .= '</ul>';
7976: }
7977: }
7978: return $output;
7979: }
7980:
7981: sub instrule_disallow_msg {
1.615 raeburn 7982: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7983: my $response;
7984: my %text = (
7985: item => 'username',
7986: items => 'usernames',
7987: match => 'matches',
7988: do => 'does',
7989: action => 'a username',
7990: one => 'one',
7991: );
7992: if ($count > 1) {
7993: $text{'item'} = 'usernames';
7994: $text{'match'} ='match';
7995: $text{'do'} = 'do';
7996: $text{'action'} = 'usernames',
7997: $text{'one'} = 'ones';
7998: }
7999: if ($checkitem eq 'id') {
8000: $text{'items'} = 'IDs';
8001: $text{'item'} = 'ID';
8002: $text{'action'} = 'an ID';
1.615 raeburn 8003: if ($count > 1) {
8004: $text{'item'} = 'IDs';
8005: $text{'action'} = 'IDs';
8006: }
1.612 raeburn 8007: }
1.674 bisitz 8008: $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 8009: if ($mode eq 'upload') {
8010: if ($checkitem eq 'username') {
8011: $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'}.");
8012: } elsif ($checkitem eq 'id') {
1.674 bisitz 8013: $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 8014: }
1.669 raeburn 8015: } elsif ($mode eq 'selfcreate') {
8016: if ($checkitem eq 'id') {
8017: $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.");
8018: }
1.615 raeburn 8019: } else {
8020: if ($checkitem eq 'username') {
8021: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8022: } elsif ($checkitem eq 'id') {
8023: $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.");
8024: }
1.612 raeburn 8025: }
8026: return $response;
1.585 raeburn 8027: }
8028:
1.624 raeburn 8029: sub personal_data_fieldtitles {
8030: my %fieldtitles = &Apache::lonlocal::texthash (
8031: id => 'Student/Employee ID',
8032: permanentemail => 'E-mail address',
8033: lastname => 'Last Name',
8034: firstname => 'First Name',
8035: middlename => 'Middle Name',
8036: generation => 'Generation',
8037: gen => 'Generation',
1.765 raeburn 8038: inststatus => 'Affiliation',
1.624 raeburn 8039: );
8040: return %fieldtitles;
8041: }
8042:
1.642 raeburn 8043: sub sorted_inst_types {
8044: my ($dom) = @_;
8045: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8046: my $othertitle = &mt('All users');
8047: if ($env{'request.course.id'}) {
1.668 raeburn 8048: $othertitle = &mt('Any users');
1.642 raeburn 8049: }
8050: my @types;
8051: if (ref($order) eq 'ARRAY') {
8052: @types = @{$order};
8053: }
8054: if (@types == 0) {
8055: if (ref($usertypes) eq 'HASH') {
8056: @types = sort(keys(%{$usertypes}));
8057: }
8058: }
8059: if (keys(%{$usertypes}) > 0) {
8060: $othertitle = &mt('Other users');
8061: }
8062: return ($othertitle,$usertypes,\@types);
8063: }
8064:
1.645 raeburn 8065: sub get_institutional_codes {
8066: my ($settings,$allcourses,$LC_code) = @_;
8067: # Get complete list of course sections to update
8068: my @currsections = ();
8069: my @currxlists = ();
8070: my $coursecode = $$settings{'internal.coursecode'};
8071:
8072: if ($$settings{'internal.sectionnums'} ne '') {
8073: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8074: }
8075:
8076: if ($$settings{'internal.crosslistings'} ne '') {
8077: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8078: }
8079:
8080: if (@currxlists > 0) {
8081: foreach (@currxlists) {
8082: if (m/^([^:]+):(\w*)$/) {
8083: unless (grep/^$1$/,@{$allcourses}) {
8084: push @{$allcourses},$1;
8085: $$LC_code{$1} = $2;
8086: }
8087: }
8088: }
8089: }
8090:
8091: if (@currsections > 0) {
8092: foreach (@currsections) {
8093: if (m/^(\w+):(\w*)$/) {
8094: my $sec = $coursecode.$1;
8095: my $lc_sec = $2;
8096: unless (grep/^$sec$/,@{$allcourses}) {
8097: push @{$allcourses},$sec;
8098: $$LC_code{$sec} = $lc_sec;
8099: }
8100: }
8101: }
8102: }
8103: return;
8104: }
8105:
1.971 raeburn 8106: sub get_standard_codeitems {
8107: return ('Year','Semester','Department','Number','Section');
8108: }
8109:
1.112 bowersj2 8110: =pod
8111:
1.780 raeburn 8112: =head1 Slot Helpers
8113:
8114: =over 4
8115:
8116: =item * sorted_slots()
8117:
8118: Sorts an array of slot names in order of slot start time (earliest first).
8119:
8120: Inputs:
8121:
8122: =over 4
8123:
8124: slotsarr - Reference to array of unsorted slot names.
8125:
8126: slots - Reference to hash of hash, where outer hash keys are slot names.
8127:
1.549 albertel 8128: =back
8129:
1.780 raeburn 8130: Returns:
8131:
8132: =over 4
8133:
8134: sorted - An array of slot names sorted by the start time of the slot.
8135:
8136: =back
8137:
8138: =back
8139:
8140: =cut
8141:
8142:
8143: sub sorted_slots {
8144: my ($slotsarr,$slots) = @_;
8145: my @sorted;
8146: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8147: @sorted =
8148: sort {
8149: if (ref($slots->{$a}) && ref($slots->{$b})) {
8150: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8151: }
8152: if (ref($slots->{$a})) { return -1;}
8153: if (ref($slots->{$b})) { return 1;}
8154: return 0;
8155: } @{$slotsarr};
8156: }
8157: return @sorted;
8158: }
8159:
8160:
8161: =pod
8162:
1.549 albertel 8163: =head1 HTTP Helpers
8164:
8165: =over 4
8166:
1.648 raeburn 8167: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8168:
1.258 albertel 8169: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8170: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8171: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8172:
8173: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8174: $possible_names is an ref to an array of form element names. As an example:
8175: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8176: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8177:
8178: =cut
1.1 albertel 8179:
1.6 albertel 8180: sub get_unprocessed_cgi {
1.25 albertel 8181: my ($query,$possible_names)= @_;
1.26 matthew 8182: # $Apache::lonxml::debug=1;
1.356 albertel 8183: foreach my $pair (split(/&/,$query)) {
8184: my ($name, $value) = split(/=/,$pair);
1.369 www 8185: $name = &unescape($name);
1.25 albertel 8186: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8187: $value =~ tr/+/ /;
8188: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8189: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8190: }
1.16 harris41 8191: }
1.6 albertel 8192: }
8193:
1.112 bowersj2 8194: =pod
8195:
1.648 raeburn 8196: =item * &cacheheader()
1.112 bowersj2 8197:
8198: returns cache-controlling header code
8199:
8200: =cut
8201:
1.7 albertel 8202: sub cacheheader {
1.258 albertel 8203: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8204: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8205: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8206: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8207: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8208: return $output;
1.7 albertel 8209: }
8210:
1.112 bowersj2 8211: =pod
8212:
1.648 raeburn 8213: =item * &no_cache($r)
1.112 bowersj2 8214:
8215: specifies header code to not have cache
8216:
8217: =cut
8218:
1.9 albertel 8219: sub no_cache {
1.216 albertel 8220: my ($r) = @_;
8221: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8222: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8223: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8224: $r->no_cache(1);
8225: $r->header_out("Expires" => $date);
8226: $r->header_out("Pragma" => "no-cache");
1.123 www 8227: }
8228:
8229: sub content_type {
1.181 albertel 8230: my ($r,$type,$charset) = @_;
1.299 foxr 8231: if ($r) {
8232: # Note that printout.pl calls this with undef for $r.
8233: &no_cache($r);
8234: }
1.258 albertel 8235: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8236: unless ($charset) {
8237: $charset=&Apache::lonlocal::current_encoding;
8238: }
8239: if ($charset) { $type.='; charset='.$charset; }
8240: if ($r) {
8241: $r->content_type($type);
8242: } else {
8243: print("Content-type: $type\n\n");
8244: }
1.9 albertel 8245: }
1.25 albertel 8246:
1.112 bowersj2 8247: =pod
8248:
1.648 raeburn 8249: =item * &add_to_env($name,$value)
1.112 bowersj2 8250:
1.258 albertel 8251: adds $name to the %env hash with value
1.112 bowersj2 8252: $value, if $name already exists, the entry is converted to an array
8253: reference and $value is added to the array.
8254:
8255: =cut
8256:
1.25 albertel 8257: sub add_to_env {
8258: my ($name,$value)=@_;
1.258 albertel 8259: if (defined($env{$name})) {
8260: if (ref($env{$name})) {
1.25 albertel 8261: #already have multiple values
1.258 albertel 8262: push(@{ $env{$name} },$value);
1.25 albertel 8263: } else {
8264: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8265: my $first=$env{$name};
8266: undef($env{$name});
8267: push(@{ $env{$name} },$first,$value);
1.25 albertel 8268: }
8269: } else {
1.258 albertel 8270: $env{$name}=$value;
1.25 albertel 8271: }
1.31 albertel 8272: }
1.149 albertel 8273:
8274: =pod
8275:
1.648 raeburn 8276: =item * &get_env_multiple($name)
1.149 albertel 8277:
1.258 albertel 8278: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8279: values may be defined and end up as an array ref.
8280:
8281: returns an array of values
8282:
8283: =cut
8284:
8285: sub get_env_multiple {
8286: my ($name) = @_;
8287: my @values;
1.258 albertel 8288: if (defined($env{$name})) {
1.149 albertel 8289: # exists is it an array
1.258 albertel 8290: if (ref($env{$name})) {
8291: @values=@{ $env{$name} };
1.149 albertel 8292: } else {
1.258 albertel 8293: $values[0]=$env{$name};
1.149 albertel 8294: }
8295: }
8296: return(@values);
8297: }
8298:
1.660 raeburn 8299: sub ask_for_embedded_content {
8300: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8301: my $upload_output = '
8302: <form name="upload_embedded" action="'.$actionurl.'"
8303: method="post" enctype="multipart/form-data">';
8304: $upload_output .= $state;
1.661 raeburn 8305: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8306:
8307: my $num = 0;
8308: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8309: $upload_output .= &start_data_table_row().
8310: '<td>'.$embed_file.'</td><td>';
8311: if ($args->{'ignore_remote_references'}
8312: && $embed_file =~ m{^\w+://}) {
8313: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8314: } elsif ($args->{'error_on_invalid_names'}
8315: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8316:
8317: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8318:
8319: } else {
8320: $upload_output .='
1.661 raeburn 8321: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8322: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8323: my $attrib = join(':',@{$$allfiles{$embed_file}});
8324: $upload_output .=
8325: "\n\t\t".
8326: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8327: $attrib.'" />';
8328: if (exists($$codebase{$embed_file})) {
8329: $upload_output .=
8330: "\n\t\t".
8331: '<input name="codebase_'.$num.'" type="hidden" value="'.
8332: &escape($$codebase{$embed_file}).'" />';
8333: }
8334: }
8335: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8336: $num++;
8337: }
8338: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8339: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8340: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8341: '.&mt('(only files for which a location has been provided will be uploaded)').'
8342: </form>';
8343: return $upload_output;
8344: }
8345:
1.661 raeburn 8346: sub upload_embedded {
8347: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8348: $current_disk_usage) = @_;
8349: my $output;
8350: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8351: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8352: my $orig_uploaded_filename =
8353: $env{'form.embedded_item_'.$i.'.filename'};
8354:
8355: $env{'form.embedded_orig_'.$i} =
8356: &unescape($env{'form.embedded_orig_'.$i});
8357: my ($path,$fname) =
8358: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8359: # no path, whole string is fname
8360: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8361:
8362: $path = $env{'form.currentpath'}.$path;
8363: $fname = &Apache::lonnet::clean_filename($fname);
8364: # See if there is anything left
8365: next if ($fname eq '');
8366:
8367: # Check if file already exists as a file or directory.
8368: my ($state,$msg);
8369: if ($context eq 'portfolio') {
8370: my $port_path = $dirpath;
8371: if ($group ne '') {
8372: $port_path = "groups/$group/$port_path";
8373: }
8374: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8375: $dir_root,$port_path,$disk_quota,
8376: $current_disk_usage,$uname,$udom);
8377: if ($state eq 'will_exceed_quota'
8378: || $state eq 'file_locked'
8379: || $state eq 'file_exists' ) {
8380: $output .= $msg;
8381: next;
8382: }
8383: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8384: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8385: if ($state eq 'exists') {
8386: $output .= $msg;
8387: next;
8388: }
8389: }
8390: # Check if extension is valid
8391: if (($fname =~ /\.(\w+)$/) &&
8392: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8393: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8394: next;
8395: } elsif (($fname =~ /\.(\w+)$/) &&
8396: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8397: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8398: next;
8399: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8400: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8401: next;
8402: }
8403:
8404: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8405: if ($context eq 'portfolio') {
8406: my $result=
8407: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8408: $dirpath.$path);
8409: if ($result !~ m|^/uploaded/|) {
8410: $output .= '<span class="LC_error">'
8411: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8412: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8413: .'</span><br />';
8414: next;
8415: } else {
8416: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8417: $path.$fname.'</span>').'</p>';
8418: }
8419: } else {
8420: # Save the file
8421: my $target = $env{'form.embedded_item_'.$i};
8422: my $fullpath = $dir_root.$dirpath.'/'.$path;
8423: my $dest = $fullpath.$fname;
8424: my $url = $url_root.$dirpath.'/'.$path.$fname;
8425: my @parts=split(/\//,$fullpath);
8426: my $count;
8427: my $filepath = $dir_root;
8428: for ($count=4;$count<=$#parts;$count++) {
8429: $filepath .= "/$parts[$count]";
8430: if ((-e $filepath)!=1) {
8431: mkdir($filepath,0770);
8432: }
8433: }
8434: my $fh;
8435: if (!open($fh,'>'.$dest)) {
8436: &Apache::lonnet::logthis('Failed to create '.$dest);
8437: $output .= '<span class="LC_error">'.
8438: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8439: '</span><br />';
8440: } else {
8441: if (!print $fh $env{'form.embedded_item_'.$i}) {
8442: &Apache::lonnet::logthis('Failed to write to '.$dest);
8443: $output .= '<span class="LC_error">'.
8444: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8445: '</span><br />';
8446: } else {
8447: if ($context eq 'testbank') {
8448: $output .= &mt('Embedded file uploaded successfully:').
8449: ' <a href="'.$url.'">'.
8450: $orig_uploaded_filename.'</a><br />';
8451: } else {
1.705 tempelho 8452: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8453: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8454: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8455: }
8456: }
8457: close($fh);
8458: }
8459: }
8460: }
8461: return $output;
8462: }
8463:
8464: sub check_for_existing {
8465: my ($path,$fname,$element) = @_;
8466: my ($state,$msg);
8467: if (-d $path.'/'.$fname) {
8468: $state = 'exists';
8469: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8470: } elsif (-e $path.'/'.$fname) {
8471: $state = 'exists';
8472: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8473: }
8474: if ($state eq 'exists') {
8475: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8476: }
8477: return ($state,$msg);
8478: }
8479:
8480: sub check_for_upload {
8481: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8482: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8483: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8484: my $getpropath = 1;
8485: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8486: $getpropath);
8487: my $found_file = 0;
8488: my $locked_file = 0;
8489: foreach my $line (@dir_list) {
8490: my ($file_name)=split(/\&/,$line,2);
8491: if ($file_name eq $fname){
8492: $file_name = $path.$file_name;
8493: if ($group ne '') {
8494: $file_name = $group.$file_name;
8495: }
8496: $found_file = 1;
8497: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8498: $locked_file = 1;
8499: }
8500: }
8501: }
8502: if (($current_disk_usage + $filesize) > $disk_quota){
8503: my $msg = '<span class="LC_error">'.
8504: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8505: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8506: return ('will_exceed_quota',$msg);
8507: } elsif ($found_file) {
8508: if ($locked_file) {
8509: my $msg = '<span class="LC_error">';
8510: $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>');
8511: $msg .= '</span><br />';
8512: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8513: return ('file_locked',$msg);
8514: } else {
8515: my $msg = '<span class="LC_error">';
8516: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
8517: $msg .= '</span>';
8518: $msg .= '<br />';
8519: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8520: return ('file_exists',$msg);
8521: }
8522: }
8523: }
8524:
1.31 albertel 8525:
1.41 ng 8526: =pod
1.45 matthew 8527:
1.464 albertel 8528: =back
1.41 ng 8529:
1.112 bowersj2 8530: =head1 CSV Upload/Handling functions
1.38 albertel 8531:
1.41 ng 8532: =over 4
8533:
1.648 raeburn 8534: =item * &upfile_store($r)
1.41 ng 8535:
8536: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8537: needs $env{'form.upfile'}
1.41 ng 8538: returns $datatoken to be put into hidden field
8539:
8540: =cut
1.31 albertel 8541:
8542: sub upfile_store {
8543: my $r=shift;
1.258 albertel 8544: $env{'form.upfile'}=~s/\r/\n/gs;
8545: $env{'form.upfile'}=~s/\f/\n/gs;
8546: $env{'form.upfile'}=~s/\n+/\n/gs;
8547: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8548:
1.258 albertel 8549: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8550: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8551: {
1.158 raeburn 8552: my $datafile = $r->dir_config('lonDaemons').
8553: '/tmp/'.$datatoken.'.tmp';
8554: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8555: print $fh $env{'form.upfile'};
1.158 raeburn 8556: close($fh);
8557: }
1.31 albertel 8558: }
8559: return $datatoken;
8560: }
8561:
1.56 matthew 8562: =pod
8563:
1.648 raeburn 8564: =item * &load_tmp_file($r)
1.41 ng 8565:
8566: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8567: needs $env{'form.datatoken'},
8568: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8569:
8570: =cut
1.31 albertel 8571:
8572: sub load_tmp_file {
8573: my $r=shift;
8574: my @studentdata=();
8575: {
1.158 raeburn 8576: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8577: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8578: if ( open(my $fh,"<$studentfile") ) {
8579: @studentdata=<$fh>;
8580: close($fh);
8581: }
1.31 albertel 8582: }
1.258 albertel 8583: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8584: }
8585:
1.56 matthew 8586: =pod
8587:
1.648 raeburn 8588: =item * &upfile_record_sep()
1.41 ng 8589:
8590: Separate uploaded file into records
8591: returns array of records,
1.258 albertel 8592: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8593:
8594: =cut
1.31 albertel 8595:
8596: sub upfile_record_sep {
1.258 albertel 8597: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8598: } else {
1.248 albertel 8599: my @records;
1.258 albertel 8600: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8601: if ($line=~/^\s*$/) { next; }
8602: push(@records,$line);
8603: }
8604: return @records;
1.31 albertel 8605: }
8606: }
8607:
1.56 matthew 8608: =pod
8609:
1.648 raeburn 8610: =item * &record_sep($record)
1.41 ng 8611:
1.258 albertel 8612: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8613:
8614: =cut
8615:
1.263 www 8616: sub takeleft {
8617: my $index=shift;
8618: return substr('0000'.$index,-4,4);
8619: }
8620:
1.31 albertel 8621: sub record_sep {
8622: my $record=shift;
8623: my %components=();
1.258 albertel 8624: if ($env{'form.upfiletype'} eq 'xml') {
8625: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8626: my $i=0;
1.356 albertel 8627: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8628: $field=~s/^(\"|\')//;
8629: $field=~s/(\"|\')$//;
1.263 www 8630: $components{&takeleft($i)}=$field;
1.31 albertel 8631: $i++;
8632: }
1.258 albertel 8633: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8634: my $i=0;
1.356 albertel 8635: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8636: $field=~s/^(\"|\')//;
8637: $field=~s/(\"|\')$//;
1.263 www 8638: $components{&takeleft($i)}=$field;
1.31 albertel 8639: $i++;
8640: }
8641: } else {
1.561 www 8642: my $separator=',';
1.480 banghart 8643: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8644: $separator=';';
1.480 banghart 8645: }
1.31 albertel 8646: my $i=0;
1.561 www 8647: # the character we are looking for to indicate the end of a quote or a record
8648: my $looking_for=$separator;
8649: # do not add the characters to the fields
8650: my $ignore=0;
8651: # we just encountered a separator (or the beginning of the record)
8652: my $just_found_separator=1;
8653: # store the field we are working on here
8654: my $field='';
8655: # work our way through all characters in record
8656: foreach my $character ($record=~/(.)/g) {
8657: if ($character eq $looking_for) {
8658: if ($character ne $separator) {
8659: # Found the end of a quote, again looking for separator
8660: $looking_for=$separator;
8661: $ignore=1;
8662: } else {
8663: # Found a separator, store away what we got
8664: $components{&takeleft($i)}=$field;
8665: $i++;
8666: $just_found_separator=1;
8667: $ignore=0;
8668: $field='';
8669: }
8670: next;
8671: }
8672: # single or double quotation marks after a separator indicate beginning of a quote
8673: # we are now looking for the end of the quote and need to ignore separators
8674: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8675: $looking_for=$character;
8676: next;
8677: }
8678: # ignore would be true after we reached the end of a quote
8679: if ($ignore) { next; }
8680: if (($just_found_separator) && ($character=~/\s/)) { next; }
8681: $field.=$character;
8682: $just_found_separator=0;
1.31 albertel 8683: }
1.561 www 8684: # catch the very last entry, since we never encountered the separator
8685: $components{&takeleft($i)}=$field;
1.31 albertel 8686: }
8687: return %components;
8688: }
8689:
1.144 matthew 8690: ######################################################
8691: ######################################################
8692:
1.56 matthew 8693: =pod
8694:
1.648 raeburn 8695: =item * &upfile_select_html()
1.41 ng 8696:
1.144 matthew 8697: Return HTML code to select a file from the users machine and specify
8698: the file type.
1.41 ng 8699:
8700: =cut
8701:
1.144 matthew 8702: ######################################################
8703: ######################################################
1.31 albertel 8704: sub upfile_select_html {
1.144 matthew 8705: my %Types = (
8706: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8707: semisv => &mt('Semicolon separated values'),
1.144 matthew 8708: space => &mt('Space separated'),
8709: tab => &mt('Tabulator separated'),
8710: # xml => &mt('HTML/XML'),
8711: );
8712: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8713: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8714: foreach my $type (sort(keys(%Types))) {
8715: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8716: }
8717: $Str .= "</select>\n";
8718: return $Str;
1.31 albertel 8719: }
8720:
1.301 albertel 8721: sub get_samples {
8722: my ($records,$toget) = @_;
8723: my @samples=({});
8724: my $got=0;
8725: foreach my $rec (@$records) {
8726: my %temp = &record_sep($rec);
8727: if (! grep(/\S/, values(%temp))) { next; }
8728: if (%temp) {
8729: $samples[$got]=\%temp;
8730: $got++;
8731: if ($got == $toget) { last; }
8732: }
8733: }
8734: return \@samples;
8735: }
8736:
1.144 matthew 8737: ######################################################
8738: ######################################################
8739:
1.56 matthew 8740: =pod
8741:
1.648 raeburn 8742: =item * &csv_print_samples($r,$records)
1.41 ng 8743:
8744: Prints a table of sample values from each column uploaded $r is an
8745: Apache Request ref, $records is an arrayref from
8746: &Apache::loncommon::upfile_record_sep
8747:
8748: =cut
8749:
1.144 matthew 8750: ######################################################
8751: ######################################################
1.31 albertel 8752: sub csv_print_samples {
8753: my ($r,$records) = @_;
1.662 bisitz 8754: my $samples = &get_samples($records,5);
1.301 albertel 8755:
1.594 raeburn 8756: $r->print(&mt('Samples').'<br />'.&start_data_table().
8757: &start_data_table_header_row());
1.356 albertel 8758: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8759: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8760: $r->print(&end_data_table_header_row());
1.301 albertel 8761: foreach my $hash (@$samples) {
1.594 raeburn 8762: $r->print(&start_data_table_row());
1.356 albertel 8763: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8764: $r->print('<td>');
1.356 albertel 8765: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8766: $r->print('</td>');
8767: }
1.594 raeburn 8768: $r->print(&end_data_table_row());
1.31 albertel 8769: }
1.594 raeburn 8770: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8771: }
8772:
1.144 matthew 8773: ######################################################
8774: ######################################################
8775:
1.56 matthew 8776: =pod
8777:
1.648 raeburn 8778: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8779:
8780: Prints a table to create associations between values and table columns.
1.144 matthew 8781:
1.41 ng 8782: $r is an Apache Request ref,
8783: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8784: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8785:
8786: =cut
8787:
1.144 matthew 8788: ######################################################
8789: ######################################################
1.31 albertel 8790: sub csv_print_select_table {
8791: my ($r,$records,$d) = @_;
1.301 albertel 8792: my $i=0;
8793: my $samples = &get_samples($records,1);
1.144 matthew 8794: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8795: &start_data_table().&start_data_table_header_row().
1.144 matthew 8796: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8797: '<th>'.&mt('Column').'</th>'.
8798: &end_data_table_header_row()."\n");
1.356 albertel 8799: foreach my $array_ref (@$d) {
8800: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8801: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8802:
1.875 bisitz 8803: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8804: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8805: $r->print('<option value="none"></option>');
1.356 albertel 8806: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8807: $r->print('<option value="'.$sample.'"'.
8808: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8809: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8810: }
1.594 raeburn 8811: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8812: $i++;
8813: }
1.594 raeburn 8814: $r->print(&end_data_table());
1.31 albertel 8815: $i--;
8816: return $i;
8817: }
1.56 matthew 8818:
1.144 matthew 8819: ######################################################
8820: ######################################################
8821:
1.56 matthew 8822: =pod
1.31 albertel 8823:
1.648 raeburn 8824: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8825:
8826: Prints a table of sample values from the upload and can make associate samples to internal names.
8827:
8828: $r is an Apache Request ref,
8829: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8830: $d is an array of 2 element arrays (internal name, displayed name)
8831:
8832: =cut
8833:
1.144 matthew 8834: ######################################################
8835: ######################################################
1.31 albertel 8836: sub csv_samples_select_table {
8837: my ($r,$records,$d) = @_;
8838: my $i=0;
1.144 matthew 8839: #
1.662 bisitz 8840: my $max_samples = 5;
8841: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8842: $r->print(&start_data_table().
8843: &start_data_table_header_row().'<th>'.
8844: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8845: &end_data_table_header_row());
1.301 albertel 8846:
8847: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8848: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8849: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8850: foreach my $option (@$d) {
8851: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8852: $r->print('<option value="'.$value.'"'.
1.253 albertel 8853: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8854: $display.'</option>');
1.31 albertel 8855: }
8856: $r->print('</select></td><td>');
1.662 bisitz 8857: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8858: if (defined($samples->[$line]{$key})) {
8859: $r->print($samples->[$line]{$key}."<br />\n");
8860: }
8861: }
1.594 raeburn 8862: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8863: $i++;
8864: }
1.594 raeburn 8865: $r->print(&end_data_table());
1.31 albertel 8866: $i--;
8867: return($i);
1.115 matthew 8868: }
8869:
1.144 matthew 8870: ######################################################
8871: ######################################################
8872:
1.115 matthew 8873: =pod
8874:
1.648 raeburn 8875: =item * &clean_excel_name($name)
1.115 matthew 8876:
8877: Returns a replacement for $name which does not contain any illegal characters.
8878:
8879: =cut
8880:
1.144 matthew 8881: ######################################################
8882: ######################################################
1.115 matthew 8883: sub clean_excel_name {
8884: my ($name) = @_;
8885: $name =~ s/[:\*\?\/\\]//g;
8886: if (length($name) > 31) {
8887: $name = substr($name,0,31);
8888: }
8889: return $name;
1.25 albertel 8890: }
1.84 albertel 8891:
1.85 albertel 8892: =pod
8893:
1.648 raeburn 8894: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8895:
8896: Returns either 1 or undef
8897:
8898: 1 if the part is to be hidden, undef if it is to be shown
8899:
8900: Arguments are:
8901:
8902: $id the id of the part to be checked
8903: $symb, optional the symb of the resource to check
8904: $udom, optional the domain of the user to check for
8905: $uname, optional the username of the user to check for
8906:
8907: =cut
1.84 albertel 8908:
8909: sub check_if_partid_hidden {
8910: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8911: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8912: $symb,$udom,$uname);
1.141 albertel 8913: my $truth=1;
8914: #if the string starts with !, then the list is the list to show not hide
8915: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8916: my @hiddenlist=split(/,/,$hiddenparts);
8917: foreach my $checkid (@hiddenlist) {
1.141 albertel 8918: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8919: }
1.141 albertel 8920: return !$truth;
1.84 albertel 8921: }
1.127 matthew 8922:
1.138 matthew 8923:
8924: ############################################################
8925: ############################################################
8926:
8927: =pod
8928:
1.157 matthew 8929: =back
8930:
1.138 matthew 8931: =head1 cgi-bin script and graphing routines
8932:
1.157 matthew 8933: =over 4
8934:
1.648 raeburn 8935: =item * &get_cgi_id()
1.138 matthew 8936:
8937: Inputs: none
8938:
8939: Returns an id which can be used to pass environment variables
8940: to various cgi-bin scripts. These environment variables will
8941: be removed from the users environment after a given time by
8942: the routine &Apache::lonnet::transfer_profile_to_env.
8943:
8944: =cut
8945:
8946: ############################################################
8947: ############################################################
1.152 albertel 8948: my $uniq=0;
1.136 matthew 8949: sub get_cgi_id {
1.154 albertel 8950: $uniq=($uniq+1)%100000;
1.280 albertel 8951: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8952: }
8953:
1.127 matthew 8954: ############################################################
8955: ############################################################
8956:
8957: =pod
8958:
1.648 raeburn 8959: =item * &DrawBarGraph()
1.127 matthew 8960:
1.138 matthew 8961: Facilitates the plotting of data in a (stacked) bar graph.
8962: Puts plot definition data into the users environment in order for
8963: graph.png to plot it. Returns an <img> tag for the plot.
8964: The bars on the plot are labeled '1','2',...,'n'.
8965:
8966: Inputs:
8967:
8968: =over 4
8969:
8970: =item $Title: string, the title of the plot
8971:
8972: =item $xlabel: string, text describing the X-axis of the plot
8973:
8974: =item $ylabel: string, text describing the Y-axis of the plot
8975:
8976: =item $Max: scalar, the maximum Y value to use in the plot
8977: If $Max is < any data point, the graph will not be rendered.
8978:
1.140 matthew 8979: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8980: they are plotted. If undefined, default values will be used.
8981:
1.178 matthew 8982: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8983:
1.138 matthew 8984: =item @Values: An array of array references. Each array reference holds data
8985: to be plotted in a stacked bar chart.
8986:
1.239 matthew 8987: =item If the final element of @Values is a hash reference the key/value
8988: pairs will be added to the graph definition.
8989:
1.138 matthew 8990: =back
8991:
8992: Returns:
8993:
8994: An <img> tag which references graph.png and the appropriate identifying
8995: information for the plot.
8996:
1.127 matthew 8997: =cut
8998:
8999: ############################################################
9000: ############################################################
1.134 matthew 9001: sub DrawBarGraph {
1.178 matthew 9002: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9003: #
9004: if (! defined($colors)) {
9005: $colors = ['#33ff00',
9006: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9007: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9008: ];
9009: }
1.228 matthew 9010: my $extra_settings = {};
9011: if (ref($Values[-1]) eq 'HASH') {
9012: $extra_settings = pop(@Values);
9013: }
1.127 matthew 9014: #
1.136 matthew 9015: my $identifier = &get_cgi_id();
9016: my $id = 'cgi.'.$identifier;
1.129 matthew 9017: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9018: return '';
9019: }
1.225 matthew 9020: #
9021: my @Labels;
9022: if (defined($labels)) {
9023: @Labels = @$labels;
9024: } else {
9025: for (my $i=0;$i<@{$Values[0]};$i++) {
9026: push (@Labels,$i+1);
9027: }
9028: }
9029: #
1.129 matthew 9030: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9031: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9032: my %ValuesHash;
9033: my $NumSets=1;
9034: foreach my $array (@Values) {
9035: next if (! ref($array));
1.136 matthew 9036: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9037: join(',',@$array);
1.129 matthew 9038: }
1.127 matthew 9039: #
1.136 matthew 9040: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9041: if ($NumBars < 3) {
9042: $width = 120+$NumBars*32;
1.220 matthew 9043: $xskip = 1;
1.225 matthew 9044: $bar_width = 30;
9045: } elsif ($NumBars < 5) {
9046: $width = 120+$NumBars*20;
9047: $xskip = 1;
9048: $bar_width = 20;
1.220 matthew 9049: } elsif ($NumBars < 10) {
1.136 matthew 9050: $width = 120+$NumBars*15;
9051: $xskip = 1;
9052: $bar_width = 15;
9053: } elsif ($NumBars <= 25) {
9054: $width = 120+$NumBars*11;
9055: $xskip = 5;
9056: $bar_width = 8;
9057: } elsif ($NumBars <= 50) {
9058: $width = 120+$NumBars*8;
9059: $xskip = 5;
9060: $bar_width = 4;
9061: } else {
9062: $width = 120+$NumBars*8;
9063: $xskip = 5;
9064: $bar_width = 4;
9065: }
9066: #
1.137 matthew 9067: $Max = 1 if ($Max < 1);
9068: if ( int($Max) < $Max ) {
9069: $Max++;
9070: $Max = int($Max);
9071: }
1.127 matthew 9072: $Title = '' if (! defined($Title));
9073: $xlabel = '' if (! defined($xlabel));
9074: $ylabel = '' if (! defined($ylabel));
1.369 www 9075: $ValuesHash{$id.'.title'} = &escape($Title);
9076: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9077: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9078: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9079: $ValuesHash{$id.'.NumBars'} = $NumBars;
9080: $ValuesHash{$id.'.NumSets'} = $NumSets;
9081: $ValuesHash{$id.'.PlotType'} = 'bar';
9082: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9083: $ValuesHash{$id.'.height'} = $height;
9084: $ValuesHash{$id.'.width'} = $width;
9085: $ValuesHash{$id.'.xskip'} = $xskip;
9086: $ValuesHash{$id.'.bar_width'} = $bar_width;
9087: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9088: #
1.228 matthew 9089: # Deal with other parameters
9090: while (my ($key,$value) = each(%$extra_settings)) {
9091: $ValuesHash{$id.'.'.$key} = $value;
9092: }
9093: #
1.646 raeburn 9094: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9095: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9096: }
9097:
9098: ############################################################
9099: ############################################################
9100:
9101: =pod
9102:
1.648 raeburn 9103: =item * &DrawXYGraph()
1.137 matthew 9104:
1.138 matthew 9105: Facilitates the plotting of data in an XY graph.
9106: Puts plot definition data into the users environment in order for
9107: graph.png to plot it. Returns an <img> tag for the plot.
9108:
9109: Inputs:
9110:
9111: =over 4
9112:
9113: =item $Title: string, the title of the plot
9114:
9115: =item $xlabel: string, text describing the X-axis of the plot
9116:
9117: =item $ylabel: string, text describing the Y-axis of the plot
9118:
9119: =item $Max: scalar, the maximum Y value to use in the plot
9120: If $Max is < any data point, the graph will not be rendered.
9121:
9122: =item $colors: Array ref containing the hex color codes for the data to be
9123: plotted in. If undefined, default values will be used.
9124:
9125: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9126:
9127: =item $Ydata: Array ref containing Array refs.
1.185 www 9128: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9129:
9130: =item %Values: hash indicating or overriding any default values which are
9131: passed to graph.png.
9132: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9133:
9134: =back
9135:
9136: Returns:
9137:
9138: An <img> tag which references graph.png and the appropriate identifying
9139: information for the plot.
9140:
1.137 matthew 9141: =cut
9142:
9143: ############################################################
9144: ############################################################
9145: sub DrawXYGraph {
9146: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9147: #
9148: # Create the identifier for the graph
9149: my $identifier = &get_cgi_id();
9150: my $id = 'cgi.'.$identifier;
9151: #
9152: $Title = '' if (! defined($Title));
9153: $xlabel = '' if (! defined($xlabel));
9154: $ylabel = '' if (! defined($ylabel));
9155: my %ValuesHash =
9156: (
1.369 www 9157: $id.'.title' => &escape($Title),
9158: $id.'.xlabel' => &escape($xlabel),
9159: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9160: $id.'.y_max_value'=> $Max,
9161: $id.'.labels' => join(',',@$Xlabels),
9162: $id.'.PlotType' => 'XY',
9163: );
9164: #
9165: if (defined($colors) && ref($colors) eq 'ARRAY') {
9166: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9167: }
9168: #
9169: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9170: return '';
9171: }
9172: my $NumSets=1;
1.138 matthew 9173: foreach my $array (@{$Ydata}){
1.137 matthew 9174: next if (! ref($array));
9175: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9176: }
1.138 matthew 9177: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9178: #
9179: # Deal with other parameters
9180: while (my ($key,$value) = each(%Values)) {
9181: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9182: }
9183: #
1.646 raeburn 9184: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9185: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9186: }
9187:
9188: ############################################################
9189: ############################################################
9190:
9191: =pod
9192:
1.648 raeburn 9193: =item * &DrawXYYGraph()
1.138 matthew 9194:
9195: Facilitates the plotting of data in an XY graph with two Y axes.
9196: Puts plot definition data into the users environment in order for
9197: graph.png to plot it. Returns an <img> tag for the plot.
9198:
9199: Inputs:
9200:
9201: =over 4
9202:
9203: =item $Title: string, the title of the plot
9204:
9205: =item $xlabel: string, text describing the X-axis of the plot
9206:
9207: =item $ylabel: string, text describing the Y-axis of the plot
9208:
9209: =item $colors: Array ref containing the hex color codes for the data to be
9210: plotted in. If undefined, default values will be used.
9211:
9212: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9213:
9214: =item $Ydata1: The first data set
9215:
9216: =item $Min1: The minimum value of the left Y-axis
9217:
9218: =item $Max1: The maximum value of the left Y-axis
9219:
9220: =item $Ydata2: The second data set
9221:
9222: =item $Min2: The minimum value of the right Y-axis
9223:
9224: =item $Max2: The maximum value of the left Y-axis
9225:
9226: =item %Values: hash indicating or overriding any default values which are
9227: passed to graph.png.
9228: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9229:
9230: =back
9231:
9232: Returns:
9233:
9234: An <img> tag which references graph.png and the appropriate identifying
9235: information for the plot.
1.136 matthew 9236:
9237: =cut
9238:
9239: ############################################################
9240: ############################################################
1.137 matthew 9241: sub DrawXYYGraph {
9242: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9243: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9244: #
9245: # Create the identifier for the graph
9246: my $identifier = &get_cgi_id();
9247: my $id = 'cgi.'.$identifier;
9248: #
9249: $Title = '' if (! defined($Title));
9250: $xlabel = '' if (! defined($xlabel));
9251: $ylabel = '' if (! defined($ylabel));
9252: my %ValuesHash =
9253: (
1.369 www 9254: $id.'.title' => &escape($Title),
9255: $id.'.xlabel' => &escape($xlabel),
9256: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9257: $id.'.labels' => join(',',@$Xlabels),
9258: $id.'.PlotType' => 'XY',
9259: $id.'.NumSets' => 2,
1.137 matthew 9260: $id.'.two_axes' => 1,
9261: $id.'.y1_max_value' => $Max1,
9262: $id.'.y1_min_value' => $Min1,
9263: $id.'.y2_max_value' => $Max2,
9264: $id.'.y2_min_value' => $Min2,
1.136 matthew 9265: );
9266: #
1.137 matthew 9267: if (defined($colors) && ref($colors) eq 'ARRAY') {
9268: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9269: }
9270: #
9271: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9272: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9273: return '';
9274: }
9275: my $NumSets=1;
1.137 matthew 9276: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9277: next if (! ref($array));
9278: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9279: }
9280: #
9281: # Deal with other parameters
9282: while (my ($key,$value) = each(%Values)) {
9283: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9284: }
9285: #
1.646 raeburn 9286: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9287: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9288: }
9289:
9290: ############################################################
9291: ############################################################
9292:
9293: =pod
9294:
1.157 matthew 9295: =back
9296:
1.139 matthew 9297: =head1 Statistics helper routines?
9298:
9299: Bad place for them but what the hell.
9300:
1.157 matthew 9301: =over 4
9302:
1.648 raeburn 9303: =item * &chartlink()
1.139 matthew 9304:
9305: Returns a link to the chart for a specific student.
9306:
9307: Inputs:
9308:
9309: =over 4
9310:
9311: =item $linktext: The text of the link
9312:
9313: =item $sname: The students username
9314:
9315: =item $sdomain: The students domain
9316:
9317: =back
9318:
1.157 matthew 9319: =back
9320:
1.139 matthew 9321: =cut
9322:
9323: ############################################################
9324: ############################################################
9325: sub chartlink {
9326: my ($linktext, $sname, $sdomain) = @_;
9327: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9328: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9329: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9330: '">'.$linktext.'</a>';
1.153 matthew 9331: }
9332:
9333: #######################################################
9334: #######################################################
9335:
9336: =pod
9337:
9338: =head1 Course Environment Routines
1.157 matthew 9339:
9340: =over 4
1.153 matthew 9341:
1.648 raeburn 9342: =item * &restore_course_settings()
1.153 matthew 9343:
1.648 raeburn 9344: =item * &store_course_settings()
1.153 matthew 9345:
9346: Restores/Store indicated form parameters from the course environment.
9347: Will not overwrite existing values of the form parameters.
9348:
9349: Inputs:
9350: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9351:
9352: a hash ref describing the data to be stored. For example:
9353:
9354: %Save_Parameters = ('Status' => 'scalar',
9355: 'chartoutputmode' => 'scalar',
9356: 'chartoutputdata' => 'scalar',
9357: 'Section' => 'array',
1.373 raeburn 9358: 'Group' => 'array',
1.153 matthew 9359: 'StudentData' => 'array',
9360: 'Maps' => 'array');
9361:
9362: Returns: both routines return nothing
9363:
1.631 raeburn 9364: =back
9365:
1.153 matthew 9366: =cut
9367:
9368: #######################################################
9369: #######################################################
9370: sub store_course_settings {
1.496 albertel 9371: return &store_settings($env{'request.course.id'},@_);
9372: }
9373:
9374: sub store_settings {
1.153 matthew 9375: # save to the environment
9376: # appenv the same items, just to be safe
1.300 albertel 9377: my $udom = $env{'user.domain'};
9378: my $uname = $env{'user.name'};
1.496 albertel 9379: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9380: my %SaveHash;
9381: my %AppHash;
9382: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9383: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9384: my $envname = 'environment.'.$basename;
1.258 albertel 9385: if (exists($env{'form.'.$setting})) {
1.153 matthew 9386: # Save this value away
9387: if ($type eq 'scalar' &&
1.258 albertel 9388: (! exists($env{$envname}) ||
9389: $env{$envname} ne $env{'form.'.$setting})) {
9390: $SaveHash{$basename} = $env{'form.'.$setting};
9391: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9392: } elsif ($type eq 'array') {
9393: my $stored_form;
1.258 albertel 9394: if (ref($env{'form.'.$setting})) {
1.153 matthew 9395: $stored_form = join(',',
9396: map {
1.369 www 9397: &escape($_);
1.258 albertel 9398: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9399: } else {
9400: $stored_form =
1.369 www 9401: &escape($env{'form.'.$setting});
1.153 matthew 9402: }
9403: # Determine if the array contents are the same.
1.258 albertel 9404: if ($stored_form ne $env{$envname}) {
1.153 matthew 9405: $SaveHash{$basename} = $stored_form;
9406: $AppHash{$envname} = $stored_form;
9407: }
9408: }
9409: }
9410: }
9411: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9412: $udom,$uname);
1.153 matthew 9413: if ($put_result !~ /^(ok|delayed)/) {
9414: &Apache::lonnet::logthis('unable to save form parameters, '.
9415: 'got error:'.$put_result);
9416: }
9417: # Make sure these settings stick around in this session, too
1.646 raeburn 9418: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9419: return;
9420: }
9421:
9422: sub restore_course_settings {
1.499 albertel 9423: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9424: }
9425:
9426: sub restore_settings {
9427: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9428: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9429: next if (exists($env{'form.'.$setting}));
1.496 albertel 9430: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9431: '.'.$setting;
1.258 albertel 9432: if (exists($env{$envname})) {
1.153 matthew 9433: if ($type eq 'scalar') {
1.258 albertel 9434: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9435: } elsif ($type eq 'array') {
1.258 albertel 9436: $env{'form.'.$setting} = [
1.153 matthew 9437: map {
1.369 www 9438: &unescape($_);
1.258 albertel 9439: } split(',',$env{$envname})
1.153 matthew 9440: ];
9441: }
9442: }
9443: }
1.127 matthew 9444: }
9445:
1.618 raeburn 9446: #######################################################
9447: #######################################################
9448:
9449: =pod
9450:
9451: =head1 Domain E-mail Routines
9452:
9453: =over 4
9454:
1.648 raeburn 9455: =item * &build_recipient_list()
1.618 raeburn 9456:
1.884 raeburn 9457: Build recipient lists for five types of e-mail:
1.766 raeburn 9458: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9459: (d) Help requests, (e) Course requests needing approval, generated by
9460: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9461: loncoursequeueadmin.pm respectively.
1.618 raeburn 9462:
9463: Inputs:
1.619 raeburn 9464: defmail (scalar - email address of default recipient),
1.618 raeburn 9465: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9466: defdom (domain for which to retrieve configuration settings),
9467: origmail (scalar - email address of recipient from loncapa.conf,
9468: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9469:
1.655 raeburn 9470: Returns: comma separated list of addresses to which to send e-mail.
9471:
9472: =back
1.618 raeburn 9473:
9474: =cut
9475:
9476: ############################################################
9477: ############################################################
9478: sub build_recipient_list {
1.619 raeburn 9479: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9480: my @recipients;
9481: my $otheremails;
9482: my %domconfig =
9483: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9484: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9485: if (exists($domconfig{'contacts'}{$mailing})) {
9486: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9487: my @contacts = ('adminemail','supportemail');
9488: foreach my $item (@contacts) {
9489: if ($domconfig{'contacts'}{$mailing}{$item}) {
9490: my $addr = $domconfig{'contacts'}{$item};
9491: if (!grep(/^\Q$addr\E$/,@recipients)) {
9492: push(@recipients,$addr);
9493: }
1.619 raeburn 9494: }
1.766 raeburn 9495: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9496: }
9497: }
1.766 raeburn 9498: } elsif ($origmail ne '') {
9499: push(@recipients,$origmail);
1.618 raeburn 9500: }
1.619 raeburn 9501: } elsif ($origmail ne '') {
9502: push(@recipients,$origmail);
1.618 raeburn 9503: }
1.688 raeburn 9504: if (defined($defmail)) {
9505: if ($defmail ne '') {
9506: push(@recipients,$defmail);
9507: }
1.618 raeburn 9508: }
9509: if ($otheremails) {
1.619 raeburn 9510: my @others;
9511: if ($otheremails =~ /,/) {
9512: @others = split(/,/,$otheremails);
1.618 raeburn 9513: } else {
1.619 raeburn 9514: push(@others,$otheremails);
9515: }
9516: foreach my $addr (@others) {
9517: if (!grep(/^\Q$addr\E$/,@recipients)) {
9518: push(@recipients,$addr);
9519: }
1.618 raeburn 9520: }
9521: }
1.619 raeburn 9522: my $recipientlist = join(',',@recipients);
1.618 raeburn 9523: return $recipientlist;
9524: }
9525:
1.127 matthew 9526: ############################################################
9527: ############################################################
1.154 albertel 9528:
1.655 raeburn 9529: =pod
9530:
9531: =head1 Course Catalog Routines
9532:
9533: =over 4
9534:
9535: =item * &gather_categories()
9536:
9537: Converts category definitions - keys of categories hash stored in
9538: coursecategories in configuration.db on the primary library server in a
9539: domain - to an array. Also generates javascript and idx hash used to
9540: generate Domain Coordinator interface for editing Course Categories.
9541:
9542: Inputs:
1.663 raeburn 9543:
1.655 raeburn 9544: categories (reference to hash of category definitions).
1.663 raeburn 9545:
1.655 raeburn 9546: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9547: categories and subcategories).
1.663 raeburn 9548:
1.655 raeburn 9549: idx (reference to hash of counters used in Domain Coordinator interface for
9550: editing Course Categories).
1.663 raeburn 9551:
1.655 raeburn 9552: jsarray (reference to array of categories used to create Javascript arrays for
9553: Domain Coordinator interface for editing Course Categories).
9554:
9555: Returns: nothing
9556:
9557: Side effects: populates cats, idx and jsarray.
9558:
9559: =cut
9560:
9561: sub gather_categories {
9562: my ($categories,$cats,$idx,$jsarray) = @_;
9563: my %counters;
9564: my $num = 0;
9565: foreach my $item (keys(%{$categories})) {
9566: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9567: if ($container eq '' && $depth == 0) {
9568: $cats->[$depth][$categories->{$item}] = $cat;
9569: } else {
9570: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9571: }
9572: my ($escitem,$tail) = split(/:/,$item,2);
9573: if ($counters{$tail} eq '') {
9574: $counters{$tail} = $num;
9575: $num ++;
9576: }
9577: if (ref($idx) eq 'HASH') {
9578: $idx->{$item} = $counters{$tail};
9579: }
9580: if (ref($jsarray) eq 'ARRAY') {
9581: push(@{$jsarray->[$counters{$tail}]},$item);
9582: }
9583: }
9584: return;
9585: }
9586:
9587: =pod
9588:
9589: =item * &extract_categories()
9590:
9591: Used to generate breadcrumb trails for course categories.
9592:
9593: Inputs:
1.663 raeburn 9594:
1.655 raeburn 9595: categories (reference to hash of category definitions).
1.663 raeburn 9596:
1.655 raeburn 9597: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9598: categories and subcategories).
1.663 raeburn 9599:
1.655 raeburn 9600: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9601:
1.655 raeburn 9602: allitems (reference to hash - key is category key
9603: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9604:
1.655 raeburn 9605: idx (reference to hash of counters used in Domain Coordinator interface for
9606: editing Course Categories).
1.663 raeburn 9607:
1.655 raeburn 9608: jsarray (reference to array of categories used to create Javascript arrays for
9609: Domain Coordinator interface for editing Course Categories).
9610:
1.665 raeburn 9611: subcats (reference to hash of arrays containing all subcategories within each
9612: category, -recursive)
9613:
1.655 raeburn 9614: Returns: nothing
9615:
9616: Side effects: populates trails and allitems hash references.
9617:
9618: =cut
9619:
9620: sub extract_categories {
1.665 raeburn 9621: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9622: if (ref($categories) eq 'HASH') {
9623: &gather_categories($categories,$cats,$idx,$jsarray);
9624: if (ref($cats->[0]) eq 'ARRAY') {
9625: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9626: my $name = $cats->[0][$i];
9627: my $item = &escape($name).'::0';
9628: my $trailstr;
9629: if ($name eq 'instcode') {
9630: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 9631: } elsif ($name eq 'communities') {
9632: $trailstr = &mt('Communities');
1.655 raeburn 9633: } else {
9634: $trailstr = $name;
9635: }
9636: if ($allitems->{$item} eq '') {
9637: push(@{$trails},$trailstr);
9638: $allitems->{$item} = scalar(@{$trails})-1;
9639: }
9640: my @parents = ($name);
9641: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9642: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9643: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9644: if (ref($subcats) eq 'HASH') {
9645: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9646: }
9647: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9648: }
9649: } else {
9650: if (ref($subcats) eq 'HASH') {
9651: $subcats->{$item} = [];
1.655 raeburn 9652: }
9653: }
9654: }
9655: }
9656: }
9657: return;
9658: }
9659:
9660: =pod
9661:
9662: =item *&recurse_categories()
9663:
9664: Recursively used to generate breadcrumb trails for course categories.
9665:
9666: Inputs:
1.663 raeburn 9667:
1.655 raeburn 9668: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9669: categories and subcategories).
1.663 raeburn 9670:
1.655 raeburn 9671: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9672:
9673: category (current course category, for which breadcrumb trail is being generated).
9674:
9675: trails (reference to array of breadcrumb trails for each category).
9676:
1.655 raeburn 9677: allitems (reference to hash - key is category key
9678: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9679:
1.655 raeburn 9680: parents (array containing containers directories for current category,
9681: back to top level).
9682:
9683: Returns: nothing
9684:
9685: Side effects: populates trails and allitems hash references
9686:
9687: =cut
9688:
9689: sub recurse_categories {
1.665 raeburn 9690: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9691: my $shallower = $depth - 1;
9692: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9693: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9694: my $name = $cats->[$depth]{$category}[$k];
9695: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9696: my $trailstr = join(' -> ',(@{$parents},$category));
9697: if ($allitems->{$item} eq '') {
9698: push(@{$trails},$trailstr);
9699: $allitems->{$item} = scalar(@{$trails})-1;
9700: }
9701: my $deeper = $depth+1;
9702: push(@{$parents},$category);
1.665 raeburn 9703: if (ref($subcats) eq 'HASH') {
9704: my $subcat = &escape($name).':'.$category.':'.$depth;
9705: for (my $j=@{$parents}; $j>=0; $j--) {
9706: my $higher;
9707: if ($j > 0) {
9708: $higher = &escape($parents->[$j]).':'.
9709: &escape($parents->[$j-1]).':'.$j;
9710: } else {
9711: $higher = &escape($parents->[$j]).'::'.$j;
9712: }
9713: push(@{$subcats->{$higher}},$subcat);
9714: }
9715: }
9716: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9717: $subcats);
1.655 raeburn 9718: pop(@{$parents});
9719: }
9720: } else {
9721: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9722: my $trailstr = join(' -> ',(@{$parents},$category));
9723: if ($allitems->{$item} eq '') {
9724: push(@{$trails},$trailstr);
9725: $allitems->{$item} = scalar(@{$trails})-1;
9726: }
9727: }
9728: return;
9729: }
9730:
1.663 raeburn 9731: =pod
9732:
9733: =item *&assign_categories_table()
9734:
9735: Create a datatable for display of hierarchical categories in a domain,
9736: with checkboxes to allow a course to be categorized.
9737:
9738: Inputs:
9739:
9740: cathash - reference to hash of categories defined for the domain (from
9741: configuration.db)
9742:
9743: currcat - scalar with an & separated list of categories assigned to a course.
9744:
1.919 raeburn 9745: type - scalar contains course type (Course or Community).
9746:
1.663 raeburn 9747: Returns: $output (markup to be displayed)
9748:
9749: =cut
9750:
9751: sub assign_categories_table {
1.919 raeburn 9752: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 9753: my $output;
9754: if (ref($cathash) eq 'HASH') {
9755: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9756: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9757: $maxdepth = scalar(@cats);
9758: if (@cats > 0) {
9759: my $itemcount = 0;
9760: if (ref($cats[0]) eq 'ARRAY') {
9761: my @currcategories;
9762: if ($currcat ne '') {
9763: @currcategories = split('&',$currcat);
9764: }
1.919 raeburn 9765: my $table;
1.663 raeburn 9766: for (my $i=0; $i<@{$cats[0]}; $i++) {
9767: my $parent = $cats[0][$i];
1.919 raeburn 9768: next if ($parent eq 'instcode');
9769: if ($type eq 'Community') {
9770: next unless ($parent eq 'communities');
9771: } else {
9772: next if ($parent eq 'communities');
9773: }
1.663 raeburn 9774: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9775: my $item = &escape($parent).'::0';
9776: my $checked = '';
9777: if (@currcategories > 0) {
9778: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9779: $checked = ' checked="checked"';
1.663 raeburn 9780: }
9781: }
1.919 raeburn 9782: my $parent_title = $parent;
9783: if ($parent eq 'communities') {
9784: $parent_title = &mt('Communities');
9785: }
9786: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9787: '<input type="checkbox" name="usecategory" value="'.
9788: $item.'"'.$checked.' />'.$parent_title.'</span>'.
9789: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9790: my $depth = 1;
9791: push(@path,$parent);
1.919 raeburn 9792: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 9793: pop(@path);
1.919 raeburn 9794: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 9795: $itemcount ++;
9796: }
1.919 raeburn 9797: if ($itemcount) {
9798: $output = &Apache::loncommon::start_data_table().
9799: $table.
9800: &Apache::loncommon::end_data_table();
9801: }
1.663 raeburn 9802: }
9803: }
9804: }
9805: return $output;
9806: }
9807:
9808: =pod
9809:
9810: =item *&assign_category_rows()
9811:
9812: Create a datatable row for display of nested categories in a domain,
9813: with checkboxes to allow a course to be categorized,called recursively.
9814:
9815: Inputs:
9816:
9817: itemcount - track row number for alternating colors
9818:
9819: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9820: categories and subcategories.
9821:
9822: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9823:
9824: parent - parent of current category item
9825:
9826: path - Array containing all categories back up through the hierarchy from the
9827: current category to the top level.
9828:
9829: currcategories - reference to array of current categories assigned to the course
9830:
9831: Returns: $output (markup to be displayed).
9832:
9833: =cut
9834:
9835: sub assign_category_rows {
9836: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9837: my ($text,$name,$item,$chgstr);
9838: if (ref($cats) eq 'ARRAY') {
9839: my $maxdepth = scalar(@{$cats});
9840: if (ref($cats->[$depth]) eq 'HASH') {
9841: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9842: my $numchildren = @{$cats->[$depth]{$parent}};
9843: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9844: $text .= '<td><table class="LC_datatable">';
9845: for (my $j=0; $j<$numchildren; $j++) {
9846: $name = $cats->[$depth]{$parent}[$j];
9847: $item = &escape($name).':'.&escape($parent).':'.$depth;
9848: my $deeper = $depth+1;
9849: my $checked = '';
9850: if (ref($currcategories) eq 'ARRAY') {
9851: if (@{$currcategories} > 0) {
9852: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9853: $checked = ' checked="checked"';
1.663 raeburn 9854: }
9855: }
9856: }
1.664 raeburn 9857: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9858: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9859: $item.'"'.$checked.' />'.$name.'</label></span>'.
9860: '<input type="hidden" name="catname" value="'.$name.'" />'.
9861: '</td><td>';
1.663 raeburn 9862: if (ref($path) eq 'ARRAY') {
9863: push(@{$path},$name);
9864: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9865: pop(@{$path});
9866: }
9867: $text .= '</td></tr>';
9868: }
9869: $text .= '</table></td>';
9870: }
9871: }
9872: }
9873: return $text;
9874: }
9875:
1.655 raeburn 9876: ############################################################
9877: ############################################################
9878:
9879:
1.443 albertel 9880: sub commit_customrole {
1.664 raeburn 9881: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9882: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9883: ($start?', '.&mt('starting').' '.localtime($start):'').
9884: ($end?', ending '.localtime($end):'').': <b>'.
9885: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9886: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9887: '</b><br />';
9888: return $output;
9889: }
9890:
9891: sub commit_standardrole {
1.541 raeburn 9892: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9893: my ($output,$logmsg,$linefeed);
9894: if ($context eq 'auto') {
9895: $linefeed = "\n";
9896: } else {
9897: $linefeed = "<br />\n";
9898: }
1.443 albertel 9899: if ($three eq 'st') {
1.541 raeburn 9900: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9901: $one,$two,$sec,$context);
9902: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9903: ($result eq 'unknown_course') || ($result eq 'refused')) {
9904: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9905: } else {
1.541 raeburn 9906: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9907: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9908: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9909: if ($context eq 'auto') {
9910: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9911: } else {
9912: $output .= '<b>'.$result.'</b>'.$linefeed.
9913: &mt('Add to classlist').': <b>ok</b>';
9914: }
9915: $output .= $linefeed;
1.443 albertel 9916: }
9917: } else {
9918: $output = &mt('Assigning').' '.$three.' in '.$url.
9919: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9920: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9921: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9922: if ($context eq 'auto') {
9923: $output .= $result.$linefeed;
9924: } else {
9925: $output .= '<b>'.$result.'</b>'.$linefeed;
9926: }
1.443 albertel 9927: }
9928: return $output;
9929: }
9930:
9931: sub commit_studentrole {
1.541 raeburn 9932: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9933: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9934: if ($context eq 'auto') {
9935: $linefeed = "\n";
9936: } else {
9937: $linefeed = '<br />'."\n";
9938: }
1.443 albertel 9939: if (defined($one) && defined($two)) {
9940: my $cid=$one.'_'.$two;
9941: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9942: my $secchange = 0;
9943: my $expire_role_result;
9944: my $modify_section_result;
1.628 raeburn 9945: if ($oldsec ne '-1') {
9946: if ($oldsec ne $sec) {
1.443 albertel 9947: $secchange = 1;
1.628 raeburn 9948: my $now = time;
1.443 albertel 9949: my $uurl='/'.$cid;
9950: $uurl=~s/\_/\//g;
9951: if ($oldsec) {
9952: $uurl.='/'.$oldsec;
9953: }
1.626 raeburn 9954: $oldsecurl = $uurl;
1.628 raeburn 9955: $expire_role_result =
1.652 raeburn 9956: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9957: if ($env{'request.course.sec'} ne '') {
9958: if ($expire_role_result eq 'refused') {
9959: my @roles = ('st');
9960: my @statuses = ('previous');
9961: my @roledoms = ($one);
9962: my $withsec = 1;
9963: my %roleshash =
9964: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9965: \@statuses,\@roles,\@roledoms,$withsec);
9966: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9967: my ($oldstart,$oldend) =
9968: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9969: if ($oldend > 0 && $oldend <= $now) {
9970: $expire_role_result = 'ok';
9971: }
9972: }
9973: }
9974: }
1.443 albertel 9975: $result = $expire_role_result;
9976: }
9977: }
9978: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9979: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9980: if ($modify_section_result =~ /^ok/) {
9981: if ($secchange == 1) {
1.628 raeburn 9982: if ($sec eq '') {
9983: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9984: } else {
9985: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9986: }
1.443 albertel 9987: } elsif ($oldsec eq '-1') {
1.628 raeburn 9988: if ($sec eq '') {
9989: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9990: } else {
9991: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9992: }
1.443 albertel 9993: } else {
1.628 raeburn 9994: if ($sec eq '') {
9995: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9996: } else {
9997: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9998: }
1.443 albertel 9999: }
10000: } else {
1.628 raeburn 10001: if ($secchange) {
10002: $$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;
10003: } else {
10004: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10005: }
1.443 albertel 10006: }
10007: $result = $modify_section_result;
10008: } elsif ($secchange == 1) {
1.628 raeburn 10009: if ($oldsec eq '') {
10010: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10011: } else {
10012: $$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;
10013: }
1.626 raeburn 10014: if ($expire_role_result eq 'refused') {
10015: my $newsecurl = '/'.$cid;
10016: $newsecurl =~ s/\_/\//g;
10017: if ($sec ne '') {
10018: $newsecurl.='/'.$sec;
10019: }
10020: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10021: if ($sec eq '') {
10022: $$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;
10023: } else {
10024: $$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;
10025: }
10026: }
10027: }
1.443 albertel 10028: }
10029: } else {
1.626 raeburn 10030: $$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 10031: $result = "error: incomplete course id\n";
10032: }
10033: return $result;
10034: }
10035:
10036: ############################################################
10037: ############################################################
10038:
1.566 albertel 10039: sub check_clone {
1.578 raeburn 10040: my ($args,$linefeed) = @_;
1.566 albertel 10041: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10042: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10043: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10044: my $clonemsg;
10045: my $can_clone = 0;
1.944 raeburn 10046: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10047: if ($lctype ne 'community') {
10048: $lctype = 'course';
10049: }
1.566 albertel 10050: if ($clonehome eq 'no_host') {
1.944 raeburn 10051: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10052: $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'});
10053: } else {
10054: $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'});
10055: }
1.566 albertel 10056: } else {
10057: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10058: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10059: if ($clonedesc{'type'} ne 'Community') {
10060: $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'});
10061: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10062: }
10063: }
1.882 raeburn 10064: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10065: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10066: $can_clone = 1;
10067: } else {
10068: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10069: $args->{'clonedomain'},$args->{'clonecourse'});
10070: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10071: if (grep(/^\*$/,@cloners)) {
10072: $can_clone = 1;
10073: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10074: $can_clone = 1;
10075: } else {
1.908 raeburn 10076: my $ccrole = 'cc';
1.944 raeburn 10077: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10078: $ccrole = 'co';
10079: }
1.578 raeburn 10080: my %roleshash =
10081: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10082: $args->{'ccdomain'},
1.908 raeburn 10083: 'userroles',['active'],[$ccrole],
1.578 raeburn 10084: [$args->{'clonedomain'}]);
1.908 raeburn 10085: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10086: $can_clone = 1;
10087: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10088: $can_clone = 1;
10089: } else {
1.944 raeburn 10090: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10091: $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'});
10092: } else {
10093: $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'});
10094: }
1.578 raeburn 10095: }
1.566 albertel 10096: }
1.578 raeburn 10097: }
1.566 albertel 10098: }
10099: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10100: }
10101:
1.444 albertel 10102: sub construct_course {
1.885 raeburn 10103: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10104: my $outcome;
1.541 raeburn 10105: my $linefeed = '<br />'."\n";
10106: if ($context eq 'auto') {
10107: $linefeed = "\n";
10108: }
1.566 albertel 10109:
10110: #
10111: # Are we cloning?
10112: #
10113: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10114: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10115: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10116: if ($context ne 'auto') {
1.578 raeburn 10117: if ($clonemsg ne '') {
10118: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10119: }
1.566 albertel 10120: }
10121: $outcome .= $clonemsg.$linefeed;
10122:
10123: if (!$can_clone) {
10124: return (0,$outcome);
10125: }
10126: }
10127:
1.444 albertel 10128: #
10129: # Open course
10130: #
10131: my $crstype = lc($args->{'crstype'});
10132: my %cenv=();
10133: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10134: $args->{'cdescr'},
10135: $args->{'curl'},
10136: $args->{'course_home'},
10137: $args->{'nonstandard'},
10138: $args->{'crscode'},
10139: $args->{'ccuname'}.':'.
10140: $args->{'ccdomain'},
1.882 raeburn 10141: $args->{'crstype'},
1.885 raeburn 10142: $cnum,$context,$category);
1.444 albertel 10143:
10144: # Note: The testing routines depend on this being output; see
10145: # Utils::Course. This needs to at least be output as a comment
10146: # if anyone ever decides to not show this, and Utils::Course::new
10147: # will need to be suitably modified.
1.541 raeburn 10148: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10149: if ($$courseid =~ /^error:/) {
10150: return (0,$outcome);
10151: }
10152:
1.444 albertel 10153: #
10154: # Check if created correctly
10155: #
1.479 albertel 10156: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10157: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10158: if ($crsuhome eq 'no_host') {
10159: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10160: return (0,$outcome);
10161: }
1.541 raeburn 10162: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10163:
1.444 albertel 10164: #
1.566 albertel 10165: # Do the cloning
10166: #
10167: if ($can_clone && $cloneid) {
10168: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10169: if ($context ne 'auto') {
10170: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10171: }
10172: $outcome .= $clonemsg.$linefeed;
10173: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10174: # Copy all files
1.637 www 10175: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10176: # Restore URL
1.566 albertel 10177: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10178: # Restore title
1.566 albertel 10179: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 10180: # Restore creation date, creator and creation context.
10181: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10182: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10183: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10184: # Mark as cloned
1.566 albertel 10185: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10186: # Need to clone grading mode
10187: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10188: $cenv{'grading'}=$newenv{'grading'};
10189: # Do not clone these environment entries
10190: &Apache::lonnet::del('environment',
10191: ['default_enrollment_start_date',
10192: 'default_enrollment_end_date',
10193: 'question.email',
10194: 'policy.email',
10195: 'comment.email',
10196: 'pch.users.denied',
1.725 raeburn 10197: 'plc.users.denied',
10198: 'hidefromcat',
10199: 'categories'],
1.638 www 10200: $$crsudom,$$crsunum);
1.444 albertel 10201: }
1.566 albertel 10202:
1.444 albertel 10203: #
10204: # Set environment (will override cloned, if existing)
10205: #
10206: my @sections = ();
10207: my @xlists = ();
10208: if ($args->{'crstype'}) {
10209: $cenv{'type'}=$args->{'crstype'};
10210: }
10211: if ($args->{'crsid'}) {
10212: $cenv{'courseid'}=$args->{'crsid'};
10213: }
10214: if ($args->{'crscode'}) {
10215: $cenv{'internal.coursecode'}=$args->{'crscode'};
10216: }
10217: if ($args->{'crsquota'} ne '') {
10218: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10219: } else {
10220: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10221: }
10222: if ($args->{'ccuname'}) {
10223: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10224: ':'.$args->{'ccdomain'};
10225: } else {
10226: $cenv{'internal.courseowner'} = $args->{'curruser'};
10227: }
10228: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10229: if ($args->{'crssections'}) {
10230: $cenv{'internal.sectionnums'} = '';
10231: if ($args->{'crssections'} =~ m/,/) {
10232: @sections = split/,/,$args->{'crssections'};
10233: } else {
10234: $sections[0] = $args->{'crssections'};
10235: }
10236: if (@sections > 0) {
10237: foreach my $item (@sections) {
10238: my ($sec,$gp) = split/:/,$item;
10239: my $class = $args->{'crscode'}.$sec;
10240: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10241: $cenv{'internal.sectionnums'} .= $item.',';
10242: unless ($addcheck eq 'ok') {
10243: push @badclasses, $class;
10244: }
10245: }
10246: $cenv{'internal.sectionnums'} =~ s/,$//;
10247: }
10248: }
10249: # do not hide course coordinator from staff listing,
10250: # even if privileged
10251: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10252: # add crosslistings
10253: if ($args->{'crsxlist'}) {
10254: $cenv{'internal.crosslistings'}='';
10255: if ($args->{'crsxlist'} =~ m/,/) {
10256: @xlists = split/,/,$args->{'crsxlist'};
10257: } else {
10258: $xlists[0] = $args->{'crsxlist'};
10259: }
10260: if (@xlists > 0) {
10261: foreach my $item (@xlists) {
10262: my ($xl,$gp) = split/:/,$item;
10263: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10264: $cenv{'internal.crosslistings'} .= $item.',';
10265: unless ($addcheck eq 'ok') {
10266: push @badclasses, $xl;
10267: }
10268: }
10269: $cenv{'internal.crosslistings'} =~ s/,$//;
10270: }
10271: }
10272: if ($args->{'autoadds'}) {
10273: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10274: }
10275: if ($args->{'autodrops'}) {
10276: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10277: }
10278: # check for notification of enrollment changes
10279: my @notified = ();
10280: if ($args->{'notify_owner'}) {
10281: if ($args->{'ccuname'} ne '') {
10282: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10283: }
10284: }
10285: if ($args->{'notify_dc'}) {
10286: if ($uname ne '') {
1.630 raeburn 10287: push(@notified,$uname.':'.$udom);
1.444 albertel 10288: }
10289: }
10290: if (@notified > 0) {
10291: my $notifylist;
10292: if (@notified > 1) {
10293: $notifylist = join(',',@notified);
10294: } else {
10295: $notifylist = $notified[0];
10296: }
10297: $cenv{'internal.notifylist'} = $notifylist;
10298: }
10299: if (@badclasses > 0) {
10300: my %lt=&Apache::lonlocal::texthash(
10301: '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',
10302: 'dnhr' => 'does not have rights to access enrollment in these classes',
10303: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10304: );
1.541 raeburn 10305: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10306: ' ('.$lt{'adby'}.')';
10307: if ($context eq 'auto') {
10308: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10309: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10310: foreach my $item (@badclasses) {
10311: if ($context eq 'auto') {
10312: $outcome .= " - $item\n";
10313: } else {
10314: $outcome .= "<li>$item</li>\n";
10315: }
10316: }
10317: if ($context eq 'auto') {
10318: $outcome .= $linefeed;
10319: } else {
1.566 albertel 10320: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10321: }
10322: }
1.444 albertel 10323: }
10324: if ($args->{'no_end_date'}) {
10325: $args->{'endaccess'} = 0;
10326: }
10327: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10328: $cenv{'internal.autoend'}=$args->{'enrollend'};
10329: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10330: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10331: if ($args->{'showphotos'}) {
10332: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10333: }
10334: $cenv{'internal.authtype'} = $args->{'authtype'};
10335: $cenv{'internal.autharg'} = $args->{'autharg'};
10336: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10337: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10338: 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');
10339: if ($context eq 'auto') {
10340: $outcome .= $krb_msg;
10341: } else {
1.566 albertel 10342: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10343: }
10344: $outcome .= $linefeed;
1.444 albertel 10345: }
10346: }
10347: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10348: if ($args->{'setpolicy'}) {
10349: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10350: }
10351: if ($args->{'setcontent'}) {
10352: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10353: }
10354: }
10355: if ($args->{'reshome'}) {
10356: $cenv{'reshome'}=$args->{'reshome'}.'/';
10357: $cenv{'reshome'}=~s/\/+$/\//;
10358: }
10359: #
10360: # course has keyed access
10361: #
10362: if ($args->{'setkeys'}) {
10363: $cenv{'keyaccess'}='yes';
10364: }
10365: # if specified, key authority is not course, but user
10366: # only active if keyaccess is yes
10367: if ($args->{'keyauth'}) {
1.487 albertel 10368: my ($user,$domain) = split(':',$args->{'keyauth'});
10369: $user = &LONCAPA::clean_username($user);
10370: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10371: if ($user ne '' && $domain ne '') {
1.487 albertel 10372: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10373: }
10374: }
10375:
10376: if ($args->{'disresdis'}) {
10377: $cenv{'pch.roles.denied'}='st';
10378: }
10379: if ($args->{'disablechat'}) {
10380: $cenv{'plc.roles.denied'}='st';
10381: }
10382:
10383: # Record we've not yet viewed the Course Initialization Helper for this
10384: # course
10385: $cenv{'course.helper.not.run'} = 1;
10386: #
10387: # Use new Randomseed
10388: #
10389: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10390: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10391: #
10392: # The encryption code and receipt prefix for this course
10393: #
10394: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10395: $cenv{'internal.encpref'}=100+int(9*rand(99));
10396: #
10397: # By default, use standard grading
10398: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10399:
1.541 raeburn 10400: $outcome .= $linefeed.&mt('Setting environment').': '.
10401: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10402: #
10403: # Open all assignments
10404: #
10405: if ($args->{'openall'}) {
10406: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10407: my %storecontent = ($storeunder => time,
10408: $storeunder.'.type' => 'date_start');
10409:
10410: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10411: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10412: }
10413: #
10414: # Set first page
10415: #
10416: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10417: || ($cloneid)) {
1.445 albertel 10418: use LONCAPA::map;
1.444 albertel 10419: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10420:
10421: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10422: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10423:
1.444 albertel 10424: $outcome .= ($fatal?$errtext:'read ok').' - ';
10425: my $title; my $url;
10426: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10427: $title=&mt('Syllabus');
1.444 albertel 10428: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10429: } else {
1.963 raeburn 10430: $title=&mt('Table of Contents');
1.444 albertel 10431: $url='/adm/navmaps';
10432: }
1.445 albertel 10433:
10434: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10435: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10436:
10437: if ($errtext) { $fatal=2; }
1.541 raeburn 10438: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10439: }
1.566 albertel 10440:
10441: return (1,$outcome);
1.444 albertel 10442: }
10443:
10444: ############################################################
10445: ############################################################
10446:
1.953 droeschl 10447: #SD
10448: # only Community and Course, or anything else?
1.378 raeburn 10449: sub course_type {
10450: my ($cid) = @_;
10451: if (!defined($cid)) {
10452: $cid = $env{'request.course.id'};
10453: }
1.404 albertel 10454: if (defined($env{'course.'.$cid.'.type'})) {
10455: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10456: } else {
10457: return 'Course';
1.377 raeburn 10458: }
10459: }
1.156 albertel 10460:
1.406 raeburn 10461: sub group_term {
10462: my $crstype = &course_type();
10463: my %names = (
10464: 'Course' => 'group',
1.865 raeburn 10465: 'Community' => 'group',
1.406 raeburn 10466: );
10467: return $names{$crstype};
10468: }
10469:
1.902 raeburn 10470: sub course_types {
10471: my @types = ('official','unofficial','community');
10472: my %typename = (
10473: official => 'Official course',
10474: unofficial => 'Unofficial course',
10475: community => 'Community',
10476: );
10477: return (\@types,\%typename);
10478: }
10479:
1.156 albertel 10480: sub icon {
10481: my ($file)=@_;
1.505 albertel 10482: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10483: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10484: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10485: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10486: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10487: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10488: $curfext.".gif") {
10489: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10490: $curfext.".gif";
10491: }
10492: }
1.249 albertel 10493: return &lonhttpdurl($iconname);
1.154 albertel 10494: }
1.84 albertel 10495:
1.575 albertel 10496: sub lonhttpdurl {
1.692 www 10497: #
10498: # Had been used for "small fry" static images on separate port 8080.
10499: # Modify here if lightweight http functionality desired again.
10500: # Currently eliminated due to increasing firewall issues.
10501: #
1.575 albertel 10502: my ($url)=@_;
1.692 www 10503: return $url;
1.215 albertel 10504: }
10505:
1.213 albertel 10506: sub connection_aborted {
10507: my ($r)=@_;
10508: $r->print(" ");$r->rflush();
10509: my $c = $r->connection;
10510: return $c->aborted();
10511: }
10512:
1.221 foxr 10513: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10514: # strings as 'strings'.
10515: sub escape_single {
1.221 foxr 10516: my ($input) = @_;
1.223 albertel 10517: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10518: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10519: return $input;
10520: }
1.223 albertel 10521:
1.222 foxr 10522: # Same as escape_single, but escape's "'s This
10523: # can be used for "strings"
10524: sub escape_double {
10525: my ($input) = @_;
10526: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10527: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10528: return $input;
10529: }
1.223 albertel 10530:
1.222 foxr 10531: # Escapes the last element of a full URL.
10532: sub escape_url {
10533: my ($url) = @_;
1.238 raeburn 10534: my @urlslices = split(/\//, $url,-1);
1.369 www 10535: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10536: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10537: }
1.462 albertel 10538:
1.820 raeburn 10539: sub compare_arrays {
10540: my ($arrayref1,$arrayref2) = @_;
10541: my (@difference,%count);
10542: @difference = ();
10543: %count = ();
10544: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10545: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10546: foreach my $element (keys(%count)) {
10547: if ($count{$element} == 1) {
10548: push(@difference,$element);
10549: }
10550: }
10551: }
10552: return @difference;
10553: }
10554:
1.817 bisitz 10555: # -------------------------------------------------------- Initialize user login
1.462 albertel 10556: sub init_user_environment {
1.463 albertel 10557: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10558: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10559:
10560: my $public=($username eq 'public' && $domain eq 'public');
10561:
10562: # See if old ID present, if so, remove
10563:
10564: my ($filename,$cookie,$userroles);
10565: my $now=time;
10566:
10567: if ($public) {
10568: my $max_public=100;
10569: my $oldest;
10570: my $oldest_time=0;
10571: for(my $next=1;$next<=$max_public;$next++) {
10572: if (-e $lonids."/publicuser_$next.id") {
10573: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10574: if ($mtime<$oldest_time || !$oldest_time) {
10575: $oldest_time=$mtime;
10576: $oldest=$next;
10577: }
10578: } else {
10579: $cookie="publicuser_$next";
10580: last;
10581: }
10582: }
10583: if (!$cookie) { $cookie="publicuser_$oldest"; }
10584: } else {
1.463 albertel 10585: # if this isn't a robot, kill any existing non-robot sessions
10586: if (!$args->{'robot'}) {
10587: opendir(DIR,$lonids);
10588: while ($filename=readdir(DIR)) {
10589: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10590: unlink($lonids.'/'.$filename);
10591: }
1.462 albertel 10592: }
1.463 albertel 10593: closedir(DIR);
1.462 albertel 10594: }
10595: # Give them a new cookie
1.463 albertel 10596: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10597: : $now.$$.int(rand(10000)));
1.463 albertel 10598: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10599:
10600: # Initialize roles
10601:
10602: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10603: }
10604: # ------------------------------------ Check browser type and MathML capability
10605:
10606: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10607: $clientunicode,$clientos) = &decode_user_agent($r);
10608:
10609: # ------------------------------------------------------------- Get environment
10610:
10611: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10612: my ($tmp) = keys(%userenv);
10613: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10614: } else {
10615: undef(%userenv);
10616: }
10617: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10618: $form->{'interface'}=$userenv{'interface'};
10619: }
10620: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10621:
10622: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10623: foreach my $option ('interface','localpath','localres') {
10624: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10625: }
10626: # --------------------------------------------------------- Write first profile
10627:
10628: {
10629: my %initial_env =
10630: ("user.name" => $username,
10631: "user.domain" => $domain,
10632: "user.home" => $authhost,
10633: "browser.type" => $clientbrowser,
10634: "browser.version" => $clientversion,
10635: "browser.mathml" => $clientmathml,
10636: "browser.unicode" => $clientunicode,
10637: "browser.os" => $clientos,
10638: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10639: "request.course.fn" => '',
10640: "request.course.uri" => '',
10641: "request.course.sec" => '',
10642: "request.role" => 'cm',
10643: "request.role.adv" => $env{'user.adv'},
10644: "request.host" => $ENV{'REMOTE_ADDR'},);
10645:
10646: if ($form->{'localpath'}) {
10647: $initial_env{"browser.localpath"} = $form->{'localpath'};
10648: $initial_env{"browser.localres"} = $form->{'localres'};
10649: }
10650:
10651: if ($form->{'interface'}) {
10652: $form->{'interface'}=~s/\W//gs;
10653: $initial_env{"browser.interface"} = $form->{'interface'};
10654: $env{'browser.interface'}=$form->{'interface'};
10655: }
10656:
1.724 raeburn 10657: foreach my $tool ('aboutme','blog','portfolio') {
10658: $userenv{'availabletools.'.$tool} =
10659: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10660: }
10661:
1.864 raeburn 10662: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10663: $userenv{'canrequest.'.$crstype} =
10664: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10665: 'reload','requestcourses');
10666: }
10667:
1.462 albertel 10668: $env{'user.environment'} = "$lonids/$cookie.id";
10669:
10670: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10671: &GDBM_WRCREAT(),0640)) {
10672: &_add_to_env(\%disk_env,\%initial_env);
10673: &_add_to_env(\%disk_env,\%userenv,'environment.');
10674: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10675: if (ref($args->{'extra_env'})) {
10676: &_add_to_env(\%disk_env,$args->{'extra_env'});
10677: }
1.462 albertel 10678: untie(%disk_env);
10679: } else {
1.705 tempelho 10680: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10681: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10682: return 'error: '.$!;
10683: }
10684: }
10685: $env{'request.role'}='cm';
10686: $env{'request.role.adv'}=$env{'user.adv'};
10687: $env{'browser.type'}=$clientbrowser;
10688:
10689: return $cookie;
10690:
10691: }
10692:
10693: sub _add_to_env {
10694: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10695: if (ref($env_data) eq 'HASH') {
10696: while (my ($key,$value) = each(%$env_data)) {
10697: $idf->{$prefix.$key} = $value;
10698: $env{$prefix.$key} = $value;
10699: }
1.462 albertel 10700: }
10701: }
10702:
1.685 tempelho 10703: # --- Get the symbolic name of a problem and the url
10704: sub get_symb {
10705: my ($request,$silent) = @_;
1.726 raeburn 10706: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10707: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10708: if ($symb eq '') {
10709: if (!$silent) {
10710: $request->print("Unable to handle ambiguous references:$url:.");
10711: return ();
10712: }
10713: }
10714: &Apache::lonenc::check_decrypt(\$symb);
10715: return ($symb);
10716: }
10717:
10718: # --------------------------------------------------------------Get annotation
10719:
10720: sub get_annotation {
10721: my ($symb,$enc) = @_;
10722:
10723: my $key = $symb;
10724: if (!$enc) {
10725: $key =
10726: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10727: }
10728: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10729: return $annotation{$key};
10730: }
10731:
10732: sub clean_symb {
1.731 raeburn 10733: my ($symb,$delete_enc) = @_;
1.685 tempelho 10734:
10735: &Apache::lonenc::check_decrypt(\$symb);
10736: my $enc = $env{'request.enc'};
1.731 raeburn 10737: if ($delete_enc) {
1.730 raeburn 10738: delete($env{'request.enc'});
10739: }
1.685 tempelho 10740:
10741: return ($symb,$enc);
10742: }
1.462 albertel 10743:
1.41 ng 10744: =pod
10745:
10746: =back
10747:
1.112 bowersj2 10748: =cut
1.41 ng 10749:
1.112 bowersj2 10750: 1;
10751: __END__;
1.41 ng 10752:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>