Annotation of loncom/interface/loncommon.pm, revision 1.925.2.13
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.925.2.13! raeburn 4: # $Id: loncommon.pm,v 1.925.2.12 2010/02/26 22:48:43 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.909 raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
486: my $wintitle = &mt('Course Browser');
487: if ($crstype ne '') {
488: $wintitle = &mt($crstype);
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: }
903: return &select_form($selected,$name,%langchoices);
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.648 raeburn 1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 1076:
1.112 bowersj2 1077: Returns a string corresponding to an HTML link to the given help
1078: $topic, where $topic corresponds to the name of a .tex file in
1079: /home/httpd/html/adm/help/tex, with underscores replaced by
1080: spaces.
1081:
1082: $text will optionally be linked to the same topic, allowing you to
1083: link text in addition to the graphic. If you do not want to link
1084: text, but wish to specify one of the later parameters, pass an
1085: empty string.
1086:
1087: $stayOnPage is a value that will be interpreted as a boolean. If true,
1088: the link will not open a new window. If false, the link will open
1089: a new window using Javascript. (Default is false.)
1090:
1091: $width and $height are optional numerical parameters that will
1092: override the width and height of the popped up window, which may
1093: be useful for certain help topics with big pictures included.
1.44 bowersj2 1094:
1095: =cut
1096:
1097: sub help_open_topic {
1.48 bowersj2 1098: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1099: $text = "" if (not defined $text);
1.44 bowersj2 1100: $stayOnPage = 0 if (not defined $stayOnPage);
1101: $width = 350 if (not defined $width);
1102: $height = 400 if (not defined $height);
1103: my $filename = $topic;
1104: $filename =~ s/ /_/g;
1105:
1.48 bowersj2 1106: my $template = "";
1107: my $link;
1.572 banghart 1108:
1.159 www 1109: $topic=~s/\W/\_/g;
1.44 bowersj2 1110:
1.572 banghart 1111: if (!$stayOnPage) {
1.72 bowersj2 1112: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1113: } else {
1.48 bowersj2 1114: $link = "/adm/help/${filename}.hlp";
1115: }
1116:
1117: # Add the text
1.755 neumanie 1118: if ($text ne "") {
1.763 bisitz 1119: $template.='<span class="LC_help_open_topic">'
1120: .'<a target="_top" href="'.$link.'">'
1121: .$text.'</a>';
1.48 bowersj2 1122: }
1123:
1.763 bisitz 1124: # (Always) Add the graphic
1.179 matthew 1125: my $title = &mt('Online Help');
1.667 raeburn 1126: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 1127: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1128: .'<img src="'.$helpicon.'" border="0"'
1129: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 1130: .' title="'.$title.'"'
1.763 bisitz 1131: .' /></a>';
1132: if ($text ne "") {
1133: $template.='</span>';
1134: }
1.44 bowersj2 1135: return $template;
1136:
1.106 bowersj2 1137: }
1138:
1139: # This is a quicky function for Latex cheatsheet editing, since it
1140: # appears in at least four places
1141: sub helpLatexCheatsheet {
1.732 raeburn 1142: my ($topic,$text,$not_author) = @_;
1143: my $out;
1.106 bowersj2 1144: my $addOther = '';
1.732 raeburn 1145: if ($topic) {
1.763 bisitz 1146: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1147: undef, undef, 600).
1148: '</span> ';
1149: }
1150: $out = '<span>' # Start cheatsheet
1151: .$addOther
1152: .'<span>'
1153: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1154: undef,undef,600)
1155: .'</span> <span>'
1156: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1157: undef,undef,600)
1158: .'</span>';
1.732 raeburn 1159: unless ($not_author) {
1.763 bisitz 1160: $out .= ' <span>'
1161: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1162: undef,undef,600)
1163: .'</span>';
1.732 raeburn 1164: }
1.763 bisitz 1165: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1166: return $out;
1.172 www 1167: }
1168:
1.430 albertel 1169: sub general_help {
1170: my $helptopic='Student_Intro';
1171: if ($env{'request.role'}=~/^(ca|au)/) {
1172: $helptopic='Authoring_Intro';
1.907 raeburn 1173: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1174: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1175: } elsif ($env{'request.role'}=~/^dc/) {
1176: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1177: }
1178: return $helptopic;
1179: }
1180:
1181: sub update_help_link {
1182: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1183: my $origurl = $ENV{'REQUEST_URI'};
1184: $origurl=~s|^/~|/priv/|;
1185: my $timestamp = time;
1186: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1187: $$datum = &escape($$datum);
1188: }
1189:
1190: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1191: my $output .= <<"ENDOUTPUT";
1192: <script type="text/javascript">
1.824 bisitz 1193: // <![CDATA[
1.430 albertel 1194: banner_link = '$banner_link';
1.824 bisitz 1195: // ]]>
1.430 albertel 1196: </script>
1197: ENDOUTPUT
1198: return $output;
1199: }
1200:
1201: # now just updates the help link and generates a blue icon
1.193 raeburn 1202: sub help_open_menu {
1.430 albertel 1203: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1204: = @_;
1.430 albertel 1205: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1206: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1207: # if environment.remote is on (using remote control UI)
1.798 tempelho 1208: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1209: $stayOnPage=1;
1.430 albertel 1210: }
1211: my $output;
1212: if ($component_help) {
1213: if (!$text) {
1214: $output=&help_open_topic($component_help,undef,$stayOnPage,
1215: $width,$height);
1216: } else {
1217: my $help_text;
1218: $help_text=&unescape($topic);
1219: $output='<table><tr><td>'.
1220: &help_open_topic($component_help,$help_text,$stayOnPage,
1221: $width,$height).'</td></tr></table>';
1222: }
1223: }
1224: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1225: return $output.$banner_link;
1226: }
1227:
1228: sub top_nav_help {
1229: my ($text) = @_;
1.436 albertel 1230: $text = &mt($text);
1.572 banghart 1231: my $stay_on_page =
1.798 tempelho 1232: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1233: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1234: : "javascript:helpMenu('open')";
1.572 banghart 1235: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1236:
1.201 raeburn 1237: my $title = &mt('Get help');
1.436 albertel 1238:
1239: return <<"END";
1240: $banner_link
1241: <a href="$link" title="$title">$text</a>
1242: END
1243: }
1244:
1245: sub help_menu_js {
1246: my ($text) = @_;
1247:
1248: my $stayOnPage =
1.798 tempelho 1249: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1250:
1251: my $width = 620;
1252: my $height = 600;
1.430 albertel 1253: my $helptopic=&general_help();
1254: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1255: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1256: my $start_page =
1257: &Apache::loncommon::start_page('Help Menu', undef,
1258: {'frameset' => 1,
1259: 'js_ready' => 1,
1260: 'add_entries' => {
1261: 'border' => '0',
1.579 raeburn 1262: 'rows' => "110,*",},});
1.331 albertel 1263: my $end_page =
1264: &Apache::loncommon::end_page({'frameset' => 1,
1265: 'js_ready' => 1,});
1266:
1.436 albertel 1267: my $template .= <<"ENDTEMPLATE";
1268: <script type="text/javascript">
1.877 bisitz 1269: // <![CDATA[
1.253 albertel 1270: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1271: var banner_link = '';
1.243 raeburn 1272: function helpMenu(target) {
1273: var caller = this;
1274: if (target == 'open') {
1275: var newWindow = null;
1276: try {
1.262 albertel 1277: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1278: }
1279: catch(error) {
1280: writeHelp(caller);
1281: return;
1282: }
1283: if (newWindow) {
1284: caller = newWindow;
1285: }
1.193 raeburn 1286: }
1.243 raeburn 1287: writeHelp(caller);
1288: return;
1289: }
1290: function writeHelp(caller) {
1.430 albertel 1291: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1292: caller.document.close()
1293: caller.focus()
1.193 raeburn 1294: }
1.877 bisitz 1295: // END LON-CAPA Internal -->
1.253 albertel 1296: // ]]>
1.436 albertel 1297: </script>
1.193 raeburn 1298: ENDTEMPLATE
1299: return $template;
1300: }
1301:
1.172 www 1302: sub help_open_bug {
1303: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1304: unless ($env{'user.adv'}) { return ''; }
1.172 www 1305: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1306: $text = "" if (not defined $text);
1307: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1308: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1309: $stayOnPage=1;
1310: }
1.184 albertel 1311: $width = 600 if (not defined $width);
1312: $height = 600 if (not defined $height);
1.172 www 1313:
1314: $topic=~s/\W+/\+/g;
1315: my $link='';
1316: my $template='';
1.379 albertel 1317: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1318: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1319: if (!$stayOnPage)
1320: {
1321: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1322: }
1323: else
1324: {
1325: $link = $url;
1326: }
1327: # Add the text
1328: if ($text ne "")
1329: {
1330: $template .=
1331: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1332: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1333: }
1334:
1335: # Add the graphic
1.179 matthew 1336: my $title = &mt('Report a Bug');
1.215 albertel 1337: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1338: $template .= <<"ENDTEMPLATE";
1.436 albertel 1339: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1340: ENDTEMPLATE
1341: if ($text ne '') { $template.='</td></tr></table>' };
1342: return $template;
1343:
1344: }
1345:
1346: sub help_open_faq {
1347: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1348: unless ($env{'user.adv'}) { return ''; }
1.172 www 1349: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1350: $text = "" if (not defined $text);
1351: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1352: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1353: $stayOnPage=1;
1354: }
1355: $width = 350 if (not defined $width);
1356: $height = 400 if (not defined $height);
1357:
1358: $topic=~s/\W+/\+/g;
1359: my $link='';
1360: my $template='';
1361: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1362: if (!$stayOnPage)
1363: {
1364: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1365: }
1366: else
1367: {
1368: $link = $url;
1369: }
1370:
1371: # Add the text
1372: if ($text ne "")
1373: {
1374: $template .=
1.173 www 1375: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1376: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1377: }
1378:
1379: # Add the graphic
1.179 matthew 1380: my $title = &mt('View the FAQ');
1.215 albertel 1381: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1382: $template .= <<"ENDTEMPLATE";
1.436 albertel 1383: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1384: ENDTEMPLATE
1385: if ($text ne '') { $template.='</td></tr></table>' };
1386: return $template;
1387:
1.44 bowersj2 1388: }
1.37 matthew 1389:
1.180 matthew 1390: ###############################################################
1391: ###############################################################
1392:
1.45 matthew 1393: =pod
1394:
1.648 raeburn 1395: =item * &change_content_javascript():
1.256 matthew 1396:
1397: This and the next function allow you to create small sections of an
1398: otherwise static HTML page that you can update on the fly with
1399: Javascript, even in Netscape 4.
1400:
1401: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1402: must be written to the HTML page once. It will prove the Javascript
1403: function "change(name, content)". Calling the change function with the
1404: name of the section
1405: you want to update, matching the name passed to C<changable_area>, and
1406: the new content you want to put in there, will put the content into
1407: that area.
1408:
1409: B<Note>: Netscape 4 only reserves enough space for the changable area
1410: to contain room for the original contents. You need to "make space"
1411: for whatever changes you wish to make, and be B<sure> to check your
1412: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1413: it's adequate for updating a one-line status display, but little more.
1414: This script will set the space to 100% width, so you only need to
1415: worry about height in Netscape 4.
1416:
1417: Modern browsers are much less limiting, and if you can commit to the
1418: user not using Netscape 4, this feature may be used freely with
1419: pretty much any HTML.
1420:
1421: =cut
1422:
1423: sub change_content_javascript {
1424: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1425: if ($env{'browser.type'} eq 'netscape' &&
1426: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1427: return (<<NETSCAPE4);
1428: function change(name, content) {
1429: doc = document.layers[name+"___escape"].layers[0].document;
1430: doc.open();
1431: doc.write(content);
1432: doc.close();
1433: }
1434: NETSCAPE4
1435: } else {
1436: # Otherwise, we need to use semi-standards-compliant code
1437: # (technically, "innerHTML" isn't standard but the equivalent
1438: # is really scary, and every useful browser supports it
1439: return (<<DOMBASED);
1440: function change(name, content) {
1441: element = document.getElementById(name);
1442: element.innerHTML = content;
1443: }
1444: DOMBASED
1445: }
1446: }
1447:
1448: =pod
1449:
1.648 raeburn 1450: =item * &changable_area($name,$origContent):
1.256 matthew 1451:
1452: This provides a "changable area" that can be modified on the fly via
1453: the Javascript code provided in C<change_content_javascript>. $name is
1454: the name you will use to reference the area later; do not repeat the
1455: same name on a given HTML page more then once. $origContent is what
1456: the area will originally contain, which can be left blank.
1457:
1458: =cut
1459:
1460: sub changable_area {
1461: my ($name, $origContent) = @_;
1462:
1.258 albertel 1463: if ($env{'browser.type'} eq 'netscape' &&
1464: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1465: # If this is netscape 4, we need to use the Layer tag
1466: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1467: } else {
1468: return "<span id='$name'>$origContent</span>";
1469: }
1470: }
1471:
1472: =pod
1473:
1.648 raeburn 1474: =item * &viewport_geometry_js
1.590 raeburn 1475:
1476: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1477:
1478: =cut
1479:
1480:
1481: sub viewport_geometry_js {
1482: return <<"GEOMETRY";
1483: var Geometry = {};
1484: function init_geometry() {
1485: if (Geometry.init) { return };
1486: Geometry.init=1;
1487: if (window.innerHeight) {
1488: Geometry.getViewportHeight = function() { return window.innerHeight; };
1489: Geometry.getViewportWidth = function() { return window.innerWidth; };
1490: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1491: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1492: }
1493: else if (document.documentElement && document.documentElement.clientHeight) {
1494: Geometry.getViewportHeight =
1495: function() { return document.documentElement.clientHeight; };
1496: Geometry.getViewportWidth =
1497: function() { return document.documentElement.clientWidth; };
1498:
1499: Geometry.getHorizontalScroll =
1500: function() { return document.documentElement.scrollLeft; };
1501: Geometry.getVerticalScroll =
1502: function() { return document.documentElement.scrollTop; };
1503: }
1504: else if (document.body.clientHeight) {
1505: Geometry.getViewportHeight =
1506: function() { return document.body.clientHeight; };
1507: Geometry.getViewportWidth =
1508: function() { return document.body.clientWidth; };
1509: Geometry.getHorizontalScroll =
1510: function() { return document.body.scrollLeft; };
1511: Geometry.getVerticalScroll =
1512: function() { return document.body.scrollTop; };
1513: }
1514: }
1515:
1516: GEOMETRY
1517: }
1518:
1519: =pod
1520:
1.648 raeburn 1521: =item * &viewport_size_js()
1.590 raeburn 1522:
1523: 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.
1524:
1525: =cut
1526:
1527: sub viewport_size_js {
1528: my $geometry = &viewport_geometry_js();
1529: return <<"DIMS";
1530:
1531: $geometry
1532:
1533: function getViewportDims(width,height) {
1534: init_geometry();
1535: width.value = Geometry.getViewportWidth();
1536: height.value = Geometry.getViewportHeight();
1537: return;
1538: }
1539:
1540: DIMS
1541: }
1542:
1543: =pod
1544:
1.648 raeburn 1545: =item * &resize_textarea_js()
1.565 albertel 1546:
1547: emits the needed javascript to resize a textarea to be as big as possible
1548:
1549: creates a function resize_textrea that takes two IDs first should be
1550: the id of the element to resize, second should be the id of a div that
1551: surrounds everything that comes after the textarea, this routine needs
1552: to be attached to the <body> for the onload and onresize events.
1553:
1.648 raeburn 1554: =back
1.565 albertel 1555:
1556: =cut
1557:
1558: sub resize_textarea_js {
1.590 raeburn 1559: my $geometry = &viewport_geometry_js();
1.565 albertel 1560: return <<"RESIZE";
1561: <script type="text/javascript">
1.824 bisitz 1562: // <![CDATA[
1.590 raeburn 1563: $geometry
1.565 albertel 1564:
1.588 albertel 1565: function getX(element) {
1566: var x = 0;
1567: while (element) {
1568: x += element.offsetLeft;
1569: element = element.offsetParent;
1570: }
1571: return x;
1572: }
1573: function getY(element) {
1574: var y = 0;
1575: while (element) {
1576: y += element.offsetTop;
1577: element = element.offsetParent;
1578: }
1579: return y;
1580: }
1581:
1582:
1.565 albertel 1583: function resize_textarea(textarea_id,bottom_id) {
1584: init_geometry();
1585: var textarea = document.getElementById(textarea_id);
1586: //alert(textarea);
1587:
1.588 albertel 1588: var textarea_top = getY(textarea);
1.565 albertel 1589: var textarea_height = textarea.offsetHeight;
1590: var bottom = document.getElementById(bottom_id);
1.588 albertel 1591: var bottom_top = getY(bottom);
1.565 albertel 1592: var bottom_height = bottom.offsetHeight;
1593: var window_height = Geometry.getViewportHeight();
1.588 albertel 1594: var fudge = 23;
1.565 albertel 1595: var new_height = window_height-fudge-textarea_top-bottom_height;
1596: if (new_height < 300) {
1597: new_height = 300;
1598: }
1599: textarea.style.height=new_height+'px';
1600: }
1.824 bisitz 1601: // ]]>
1.565 albertel 1602: </script>
1603: RESIZE
1604:
1605: }
1606:
1607: =pod
1608:
1.256 matthew 1609: =head1 Excel and CSV file utility routines
1610:
1611: =over 4
1612:
1613: =cut
1614:
1615: ###############################################################
1616: ###############################################################
1617:
1618: =pod
1619:
1.648 raeburn 1620: =item * &csv_translate($text)
1.37 matthew 1621:
1.185 www 1622: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1623: format.
1624:
1625: =cut
1626:
1.180 matthew 1627: ###############################################################
1628: ###############################################################
1.37 matthew 1629: sub csv_translate {
1630: my $text = shift;
1631: $text =~ s/\"/\"\"/g;
1.209 albertel 1632: $text =~ s/\n/ /g;
1.37 matthew 1633: return $text;
1634: }
1.180 matthew 1635:
1636: ###############################################################
1637: ###############################################################
1638:
1639: =pod
1640:
1.648 raeburn 1641: =item * &define_excel_formats()
1.180 matthew 1642:
1643: Define some commonly used Excel cell formats.
1644:
1645: Currently supported formats:
1646:
1647: =over 4
1648:
1649: =item header
1650:
1651: =item bold
1652:
1653: =item h1
1654:
1655: =item h2
1656:
1657: =item h3
1658:
1.256 matthew 1659: =item h4
1660:
1661: =item i
1662:
1.180 matthew 1663: =item date
1664:
1665: =back
1666:
1667: Inputs: $workbook
1668:
1669: Returns: $format, a hash reference.
1670:
1671: =cut
1672:
1673: ###############################################################
1674: ###############################################################
1675: sub define_excel_formats {
1676: my ($workbook) = @_;
1677: my $format;
1678: $format->{'header'} = $workbook->add_format(bold => 1,
1679: bottom => 1,
1680: align => 'center');
1681: $format->{'bold'} = $workbook->add_format(bold=>1);
1682: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1683: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1684: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1685: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1686: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1687: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1688: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1689: return $format;
1690: }
1691:
1692: ###############################################################
1693: ###############################################################
1.113 bowersj2 1694:
1695: =pod
1696:
1.648 raeburn 1697: =item * &create_workbook()
1.255 matthew 1698:
1699: Create an Excel worksheet. If it fails, output message on the
1700: request object and return undefs.
1701:
1702: Inputs: Apache request object
1703:
1704: Returns (undef) on failure,
1705: Excel worksheet object, scalar with filename, and formats
1706: from &Apache::loncommon::define_excel_formats on success
1707:
1708: =cut
1709:
1710: ###############################################################
1711: ###############################################################
1712: sub create_workbook {
1713: my ($r) = @_;
1714: #
1715: # Create the excel spreadsheet
1716: my $filename = '/prtspool/'.
1.258 albertel 1717: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1718: time.'_'.rand(1000000000).'.xls';
1719: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1720: if (! defined($workbook)) {
1721: $r->log_error("Error creating excel spreadsheet $filename: $!");
1722: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1723: "This error has been logged. ".
1724: "Please alert your LON-CAPA administrator").
1725: '</p>');
1726: return (undef);
1727: }
1728: #
1729: $workbook->set_tempdir('/home/httpd/perl/tmp');
1730: #
1731: my $format = &Apache::loncommon::define_excel_formats($workbook);
1732: return ($workbook,$filename,$format);
1733: }
1734:
1735: ###############################################################
1736: ###############################################################
1737:
1738: =pod
1739:
1.648 raeburn 1740: =item * &create_text_file()
1.113 bowersj2 1741:
1.542 raeburn 1742: Create a file to write to and eventually make available to the user.
1.256 matthew 1743: If file creation fails, outputs an error message on the request object and
1744: return undefs.
1.113 bowersj2 1745:
1.256 matthew 1746: Inputs: Apache request object, and file suffix
1.113 bowersj2 1747:
1.256 matthew 1748: Returns (undef) on failure,
1749: Filehandle and filename on success.
1.113 bowersj2 1750:
1751: =cut
1752:
1.256 matthew 1753: ###############################################################
1754: ###############################################################
1755: sub create_text_file {
1756: my ($r,$suffix) = @_;
1757: if (! defined($suffix)) { $suffix = 'txt'; };
1758: my $fh;
1759: my $filename = '/prtspool/'.
1.258 albertel 1760: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1761: time.'_'.rand(1000000000).'.'.$suffix;
1762: $fh = Apache::File->new('>/home/httpd'.$filename);
1763: if (! defined($fh)) {
1764: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1765: $r->print(&mt('Problems occurred in creating the output file. '
1766: .'This error has been logged. '
1767: .'Please alert your LON-CAPA administrator.'));
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.169 www 1796: return &select_form($name,$value,%domains);
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.648 raeburn 1858: =item * &select_form($defdom,$name,%hash)
1.88 www 1859:
1860: Returns a string containing a <select name='$name' size='1'> form to
1861: allow a user to select options from a hash option_name => displayed text.
1862: See lonrights.pm for an example invocation and use.
1863:
1864: =cut
1865:
1866: #-------------------------------------------
1867: sub select_form {
1868: my ($def,$name,%hash) = @_;
1869: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1870: my @keys;
1871: if (exists($hash{'select_form_order'})) {
1872: @keys=@{$hash{'select_form_order'}};
1873: } else {
1874: @keys=sort(keys(%hash));
1875: }
1.356 albertel 1876: foreach my $key (@keys) {
1877: $selectform.=
1878: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1879: ($key eq $def ? 'selected="selected" ' : '').
1.922 bisitz 1880: ">".$hash{$key}."</option>\n";
1.88 www 1881: }
1882: $selectform.="</select>";
1883: return $selectform;
1884: }
1885:
1.475 www 1886: # For display filters
1887:
1888: sub display_filter {
1889: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1890: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1891: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1892: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1893: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1894: '</label></span> <span class="LC_nobreak">'.
1.475 www 1895: &mt('Filter [_1]',
1.477 www 1896: &select_form($env{'form.displayfilter'},
1897: 'displayfilter',
1898: ('currentfolder' => 'Current folder/page',
1899: 'containing' => 'Containing phrase',
1900: 'none' => 'None'))).
1.714 bisitz 1901: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1902: }
1903:
1.167 www 1904: sub gradeleveldescription {
1905: my $gradelevel=shift;
1906: my %gradelevels=(0 => 'Not specified',
1907: 1 => 'Grade 1',
1908: 2 => 'Grade 2',
1909: 3 => 'Grade 3',
1910: 4 => 'Grade 4',
1911: 5 => 'Grade 5',
1912: 6 => 'Grade 6',
1913: 7 => 'Grade 7',
1914: 8 => 'Grade 8',
1915: 9 => 'Grade 9',
1916: 10 => 'Grade 10',
1917: 11 => 'Grade 11',
1918: 12 => 'Grade 12',
1919: 13 => 'Grade 13',
1920: 14 => '100 Level',
1921: 15 => '200 Level',
1922: 16 => '300 Level',
1923: 17 => '400 Level',
1924: 18 => 'Graduate Level');
1925: return &mt($gradelevels{$gradelevel});
1926: }
1927:
1.163 www 1928: sub select_level_form {
1929: my ($deflevel,$name)=@_;
1930: unless ($deflevel) { $deflevel=0; }
1.167 www 1931: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1932: for (my $i=0; $i<=18; $i++) {
1933: $selectform.="<option value=\"$i\" ".
1.253 albertel 1934: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1935: ">".&gradeleveldescription($i)."</option>\n";
1936: }
1937: $selectform.="</select>";
1938: return $selectform;
1.163 www 1939: }
1.167 www 1940:
1.35 matthew 1941: #-------------------------------------------
1942:
1.45 matthew 1943: =pod
1944:
1.910 raeburn 1945: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1946:
1947: Returns a string containing a <select name='$name' size='1'> form to
1948: allow a user to select the domain to preform an operation in.
1949: See loncreateuser.pm for an example invocation and use.
1950:
1.90 www 1951: If the $includeempty flag is set, it also includes an empty choice ("no domain
1952: selected");
1953:
1.743 raeburn 1954: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1955:
1.910 raeburn 1956: 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.
1957:
1958: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 1959:
1.35 matthew 1960: =cut
1961:
1962: #-------------------------------------------
1.34 matthew 1963: sub select_dom_form {
1.910 raeburn 1964: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 1965: if ($onchange) {
1.874 raeburn 1966: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1967: }
1.910 raeburn 1968: my @domains;
1969: if (ref($incdoms) eq 'ARRAY') {
1970: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
1971: } else {
1972: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1973: }
1.90 www 1974: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1975: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1976: foreach my $dom (@domains) {
1977: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1978: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1979: if ($showdomdesc) {
1980: if ($dom ne '') {
1.925.2.13! raeburn 1981: my $domdesc;
! 1982: if ($name eq 'srchdomain') {
! 1983: if ($dom eq 'gci') {
! 1984: $domdesc = 'Faculty';
! 1985: } else {
! 1986: $domdesc = 'Students';
! 1987: }
! 1988: } else {
! 1989: $domdesc = &Apache::lonnet::domain($dom,'description');
! 1990: }
1.563 raeburn 1991: if ($domdesc ne '') {
1992: $selectdomain .= ' ('.$domdesc.')';
1993: }
1994: }
1995: }
1996: $selectdomain .= "</option>\n";
1.34 matthew 1997: }
1998: $selectdomain.="</select>";
1999: return $selectdomain;
2000: }
2001:
1.35 matthew 2002: #-------------------------------------------
2003:
1.45 matthew 2004: =pod
2005:
1.648 raeburn 2006: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2007:
1.586 raeburn 2008: input: 4 arguments (two required, two optional) -
2009: $domain - domain of new user
2010: $name - name of form element
2011: $default - Value of 'default' causes a default item to be first
2012: option, and selected by default.
2013: $hide - Value of 'hide' causes hiding of the name of the server,
2014: if 1 server found, or default, if 0 found.
1.594 raeburn 2015: output: returns 2 items:
1.586 raeburn 2016: (a) form element which contains either:
2017: (i) <select name="$name">
2018: <option value="$hostid1">$hostid $servers{$hostid}</option>
2019: <option value="$hostid2">$hostid $servers{$hostid}</option>
2020: </select>
2021: form item if there are multiple library servers in $domain, or
2022: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2023: if there is only one library server in $domain.
2024:
2025: (b) number of library servers found.
2026:
2027: See loncreateuser.pm for example of use.
1.35 matthew 2028:
2029: =cut
2030:
2031: #-------------------------------------------
1.586 raeburn 2032: sub home_server_form_item {
2033: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2034: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2035: my $result;
2036: my $numlib = keys(%servers);
2037: if ($numlib > 1) {
2038: $result .= '<select name="'.$name.'" />'."\n";
2039: if ($default) {
1.804 bisitz 2040: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2041: '</option>'."\n";
2042: }
2043: foreach my $hostid (sort(keys(%servers))) {
2044: $result.= '<option value="'.$hostid.'">'.
2045: $hostid.' '.$servers{$hostid}."</option>\n";
2046: }
2047: $result .= '</select>'."\n";
2048: } elsif ($numlib == 1) {
2049: my $hostid;
2050: foreach my $item (keys(%servers)) {
2051: $hostid = $item;
2052: }
2053: $result .= '<input type="hidden" name="'.$name.'" value="'.
2054: $hostid.'" />';
2055: if (!$hide) {
2056: $result .= $hostid.' '.$servers{$hostid};
2057: }
2058: $result .= "\n";
2059: } elsif ($default) {
2060: $result .= '<input type="hidden" name="'.$name.
2061: '" value="default" />';
2062: if (!$hide) {
2063: $result .= &mt('default');
2064: }
2065: $result .= "\n";
1.33 matthew 2066: }
1.586 raeburn 2067: return ($result,$numlib);
1.33 matthew 2068: }
1.112 bowersj2 2069:
2070: =pod
2071:
1.534 albertel 2072: =back
2073:
1.112 bowersj2 2074: =cut
1.87 matthew 2075:
2076: ###############################################################
1.112 bowersj2 2077: ## Decoding User Agent ##
1.87 matthew 2078: ###############################################################
2079:
2080: =pod
2081:
1.112 bowersj2 2082: =head1 Decoding the User Agent
2083:
2084: =over 4
2085:
2086: =item * &decode_user_agent()
1.87 matthew 2087:
2088: Inputs: $r
2089:
2090: Outputs:
2091:
2092: =over 4
2093:
1.112 bowersj2 2094: =item * $httpbrowser
1.87 matthew 2095:
1.112 bowersj2 2096: =item * $clientbrowser
1.87 matthew 2097:
1.112 bowersj2 2098: =item * $clientversion
1.87 matthew 2099:
1.112 bowersj2 2100: =item * $clientmathml
1.87 matthew 2101:
1.112 bowersj2 2102: =item * $clientunicode
1.87 matthew 2103:
1.112 bowersj2 2104: =item * $clientos
1.87 matthew 2105:
2106: =back
2107:
1.157 matthew 2108: =back
2109:
1.87 matthew 2110: =cut
2111:
2112: ###############################################################
2113: ###############################################################
2114: sub decode_user_agent {
1.247 albertel 2115: my ($r)=@_;
1.87 matthew 2116: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2117: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2118: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2119: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2120: my $clientbrowser='unknown';
2121: my $clientversion='0';
2122: my $clientmathml='';
2123: my $clientunicode='0';
2124: for (my $i=0;$i<=$#browsertype;$i++) {
2125: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2126: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2127: $clientbrowser=$bname;
2128: $httpbrowser=~/$vreg/i;
2129: $clientversion=$1;
2130: $clientmathml=($clientversion>=$minv);
2131: $clientunicode=($clientversion>=$univ);
2132: }
2133: }
2134: my $clientos='unknown';
2135: if (($httpbrowser=~/linux/i) ||
2136: ($httpbrowser=~/unix/i) ||
2137: ($httpbrowser=~/ux/i) ||
2138: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2139: if (($httpbrowser=~/vax/i) ||
2140: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2141: if ($httpbrowser=~/next/i) { $clientos='next'; }
2142: if (($httpbrowser=~/mac/i) ||
2143: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2144: if ($httpbrowser=~/win/i) { $clientos='win'; }
2145: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2146: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2147: $clientunicode,$clientos,);
2148: }
2149:
1.32 matthew 2150: ###############################################################
2151: ## Authentication changing form generation subroutines ##
2152: ###############################################################
2153: ##
2154: ## All of the authform_xxxxxxx subroutines take their inputs in a
2155: ## hash, and have reasonable default values.
2156: ##
2157: ## formname = the name given in the <form> tag.
1.35 matthew 2158: #-------------------------------------------
2159:
1.45 matthew 2160: =pod
2161:
1.112 bowersj2 2162: =head1 Authentication Routines
2163:
2164: =over 4
2165:
1.648 raeburn 2166: =item * &authform_xxxxxx()
1.35 matthew 2167:
2168: The authform_xxxxxx subroutines provide javascript and html forms which
2169: handle some of the conveniences required for authentication forms.
2170: This is not an optimal method, but it works.
2171:
2172: =over 4
2173:
1.112 bowersj2 2174: =item * authform_header
1.35 matthew 2175:
1.112 bowersj2 2176: =item * authform_authorwarning
1.35 matthew 2177:
1.112 bowersj2 2178: =item * authform_nochange
1.35 matthew 2179:
1.112 bowersj2 2180: =item * authform_kerberos
1.35 matthew 2181:
1.112 bowersj2 2182: =item * authform_internal
1.35 matthew 2183:
1.112 bowersj2 2184: =item * authform_filesystem
1.35 matthew 2185:
2186: =back
2187:
1.648 raeburn 2188: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2189:
1.35 matthew 2190: =cut
2191:
2192: #-------------------------------------------
1.32 matthew 2193: sub authform_header{
2194: my %in = (
2195: formname => 'cu',
1.80 albertel 2196: kerb_def_dom => '',
1.32 matthew 2197: @_,
2198: );
2199: $in{'formname'} = 'document.' . $in{'formname'};
2200: my $result='';
1.80 albertel 2201:
2202: #---------------------------------------------- Code for upper case translation
2203: my $Javascript_toUpperCase;
2204: unless ($in{kerb_def_dom}) {
2205: $Javascript_toUpperCase =<<"END";
2206: switch (choice) {
2207: case 'krb': currentform.elements[choicearg].value =
2208: currentform.elements[choicearg].value.toUpperCase();
2209: break;
2210: default:
2211: }
2212: END
2213: } else {
2214: $Javascript_toUpperCase = "";
2215: }
2216:
1.165 raeburn 2217: my $radioval = "'nochange'";
1.591 raeburn 2218: if (defined($in{'curr_authtype'})) {
2219: if ($in{'curr_authtype'} ne '') {
2220: $radioval = "'".$in{'curr_authtype'}."arg'";
2221: }
1.174 matthew 2222: }
1.165 raeburn 2223: my $argfield = 'null';
1.591 raeburn 2224: if (defined($in{'mode'})) {
1.165 raeburn 2225: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2226: if (defined($in{'curr_autharg'})) {
2227: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2228: $argfield = "'$in{'curr_autharg'}'";
2229: }
2230: }
2231: }
2232: }
2233:
1.32 matthew 2234: $result.=<<"END";
2235: var current = new Object();
1.165 raeburn 2236: current.radiovalue = $radioval;
2237: current.argfield = $argfield;
1.32 matthew 2238:
2239: function changed_radio(choice,currentform) {
2240: var choicearg = choice + 'arg';
2241: // If a radio button in changed, we need to change the argfield
2242: if (current.radiovalue != choice) {
2243: current.radiovalue = choice;
2244: if (current.argfield != null) {
2245: currentform.elements[current.argfield].value = '';
2246: }
2247: if (choice == 'nochange') {
2248: current.argfield = null;
2249: } else {
2250: current.argfield = choicearg;
2251: switch(choice) {
2252: case 'krb':
2253: currentform.elements[current.argfield].value =
2254: "$in{'kerb_def_dom'}";
2255: break;
2256: default:
2257: break;
2258: }
2259: }
2260: }
2261: return;
2262: }
1.22 www 2263:
1.32 matthew 2264: function changed_text(choice,currentform) {
2265: var choicearg = choice + 'arg';
2266: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2267: $Javascript_toUpperCase
1.32 matthew 2268: // clear old field
2269: if ((current.argfield != choicearg) && (current.argfield != null)) {
2270: currentform.elements[current.argfield].value = '';
2271: }
2272: current.argfield = choicearg;
2273: }
2274: set_auth_radio_buttons(choice,currentform);
2275: return;
1.20 www 2276: }
1.32 matthew 2277:
2278: function set_auth_radio_buttons(newvalue,currentform) {
2279: var i=0;
2280: while (i < currentform.login.length) {
2281: if (currentform.login[i].value == newvalue) { break; }
2282: i++;
2283: }
2284: if (i == currentform.login.length) {
2285: return;
2286: }
2287: current.radiovalue = newvalue;
2288: currentform.login[i].checked = true;
2289: return;
2290: }
2291: END
2292: return $result;
2293: }
2294:
2295: sub authform_authorwarning{
2296: my $result='';
1.144 matthew 2297: $result='<i>'.
2298: &mt('As a general rule, only authors or co-authors should be '.
2299: 'filesystem authenticated '.
2300: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2301: return $result;
2302: }
2303:
2304: sub authform_nochange{
2305: my %in = (
2306: formname => 'document.cu',
2307: kerb_def_dom => 'MSU.EDU',
2308: @_,
2309: );
1.586 raeburn 2310: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2311: my $result;
2312: if (keys(%can_assign) == 0) {
2313: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2314: } else {
2315: $result = '<label>'.&mt('[_1] Do not change login data',
2316: '<input type="radio" name="login" value="nochange" '.
2317: 'checked="checked" onclick="'.
1.281 albertel 2318: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2319: '</label>';
1.586 raeburn 2320: }
1.32 matthew 2321: return $result;
2322: }
2323:
1.591 raeburn 2324: sub authform_kerberos {
1.32 matthew 2325: my %in = (
2326: formname => 'document.cu',
2327: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2328: kerb_def_auth => 'krb4',
1.32 matthew 2329: @_,
2330: );
1.586 raeburn 2331: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2332: $autharg,$jscall);
2333: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2334: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2335: $check5 = ' checked="checked"';
1.80 albertel 2336: } else {
1.772 bisitz 2337: $check4 = ' checked="checked"';
1.80 albertel 2338: }
1.165 raeburn 2339: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2340: if (defined($in{'curr_authtype'})) {
2341: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2342: $krbcheck = ' checked="checked"';
1.623 raeburn 2343: if (defined($in{'mode'})) {
2344: if ($in{'mode'} eq 'modifyuser') {
2345: $krbcheck = '';
2346: }
2347: }
1.591 raeburn 2348: if (defined($in{'curr_kerb_ver'})) {
2349: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2350: $check5 = ' checked="checked"';
1.591 raeburn 2351: $check4 = '';
2352: } else {
1.772 bisitz 2353: $check4 = ' checked="checked"';
1.591 raeburn 2354: $check5 = '';
2355: }
1.586 raeburn 2356: }
1.591 raeburn 2357: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2358: $krbarg = $in{'curr_autharg'};
2359: }
1.586 raeburn 2360: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2361: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2362: $result =
2363: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2364: $in{'curr_autharg'},$krbver);
2365: } else {
2366: $result =
2367: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2368: }
2369: return $result;
2370: }
2371: }
2372: } else {
2373: if ($authnum == 1) {
1.784 bisitz 2374: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2375: }
2376: }
1.586 raeburn 2377: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2378: return;
1.587 raeburn 2379: } elsif ($authtype eq '') {
1.591 raeburn 2380: if (defined($in{'mode'})) {
1.587 raeburn 2381: if ($in{'mode'} eq 'modifycourse') {
2382: if ($authnum == 1) {
1.784 bisitz 2383: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2384: }
2385: }
2386: }
1.586 raeburn 2387: }
2388: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2389: if ($authtype eq '') {
2390: $authtype = '<input type="radio" name="login" value="krb" '.
2391: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2392: $krbcheck.' />';
2393: }
2394: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2395: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2396: $in{'curr_authtype'} eq 'krb5') ||
2397: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2398: $in{'curr_authtype'} eq 'krb4')) {
2399: $result .= &mt
1.144 matthew 2400: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2401: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2402: '<label>'.$authtype,
1.281 albertel 2403: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2404: 'value="'.$krbarg.'" '.
1.144 matthew 2405: 'onchange="'.$jscall.'" />',
1.281 albertel 2406: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2407: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2408: '</label>');
1.586 raeburn 2409: } elsif ($can_assign{'krb4'}) {
2410: $result .= &mt
2411: ('[_1] Kerberos authenticated with domain [_2] '.
2412: '[_3] Version 4 [_4]',
2413: '<label>'.$authtype,
2414: '</label><input type="text" size="10" name="krbarg" '.
2415: 'value="'.$krbarg.'" '.
2416: 'onchange="'.$jscall.'" />',
2417: '<label><input type="hidden" name="krbver" value="4" />',
2418: '</label>');
2419: } elsif ($can_assign{'krb5'}) {
2420: $result .= &mt
2421: ('[_1] Kerberos authenticated with domain [_2] '.
2422: '[_3] Version 5 [_4]',
2423: '<label>'.$authtype,
2424: '</label><input type="text" size="10" name="krbarg" '.
2425: 'value="'.$krbarg.'" '.
2426: 'onchange="'.$jscall.'" />',
2427: '<label><input type="hidden" name="krbver" value="5" />',
2428: '</label>');
2429: }
1.32 matthew 2430: return $result;
2431: }
2432:
2433: sub authform_internal{
1.586 raeburn 2434: my %in = (
1.32 matthew 2435: formname => 'document.cu',
2436: kerb_def_dom => 'MSU.EDU',
2437: @_,
2438: );
1.586 raeburn 2439: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2440: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2441: if (defined($in{'curr_authtype'})) {
2442: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2443: if ($can_assign{'int'}) {
1.772 bisitz 2444: $intcheck = 'checked="checked" ';
1.623 raeburn 2445: if (defined($in{'mode'})) {
2446: if ($in{'mode'} eq 'modifyuser') {
2447: $intcheck = '';
2448: }
2449: }
1.591 raeburn 2450: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2451: $intarg = $in{'curr_autharg'};
2452: }
2453: } else {
2454: $result = &mt('Currently internally authenticated.');
2455: return $result;
1.165 raeburn 2456: }
2457: }
1.586 raeburn 2458: } else {
2459: if ($authnum == 1) {
1.784 bisitz 2460: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2461: }
2462: }
2463: if (!$can_assign{'int'}) {
2464: return;
1.587 raeburn 2465: } elsif ($authtype eq '') {
1.591 raeburn 2466: if (defined($in{'mode'})) {
1.587 raeburn 2467: if ($in{'mode'} eq 'modifycourse') {
2468: if ($authnum == 1) {
1.784 bisitz 2469: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2470: }
2471: }
2472: }
1.165 raeburn 2473: }
1.586 raeburn 2474: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2475: if ($authtype eq '') {
2476: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2477: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2478: }
1.605 bisitz 2479: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2480: $intarg.'" onchange="'.$jscall.'" />';
1.925.2.13! raeburn 2481: my $authtext = '[_1] Internally authenticated (with initial password [_2])';
! 2482: if ($in{'caller'} eq 'requestcrs') {
! 2483: $authtext = "[_1] Students' password, if none in the uploaded file: [_2]";
! 2484: }
! 2485: $result = &mt($authtext,'<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2486: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2487: return $result;
2488: }
2489:
2490: sub authform_local{
2491: my %in = (
2492: formname => 'document.cu',
2493: kerb_def_dom => 'MSU.EDU',
2494: @_,
2495: );
1.586 raeburn 2496: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2497: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2498: if (defined($in{'curr_authtype'})) {
2499: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2500: if ($can_assign{'loc'}) {
1.772 bisitz 2501: $loccheck = 'checked="checked" ';
1.623 raeburn 2502: if (defined($in{'mode'})) {
2503: if ($in{'mode'} eq 'modifyuser') {
2504: $loccheck = '';
2505: }
2506: }
1.591 raeburn 2507: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2508: $locarg = $in{'curr_autharg'};
2509: }
2510: } else {
2511: $result = &mt('Currently using local (institutional) authentication.');
2512: return $result;
1.165 raeburn 2513: }
2514: }
1.586 raeburn 2515: } else {
2516: if ($authnum == 1) {
1.784 bisitz 2517: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2518: }
2519: }
2520: if (!$can_assign{'loc'}) {
2521: return;
1.587 raeburn 2522: } elsif ($authtype eq '') {
1.591 raeburn 2523: if (defined($in{'mode'})) {
1.587 raeburn 2524: if ($in{'mode'} eq 'modifycourse') {
2525: if ($authnum == 1) {
1.784 bisitz 2526: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2527: }
2528: }
2529: }
1.165 raeburn 2530: }
1.586 raeburn 2531: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2532: if ($authtype eq '') {
2533: $authtype = '<input type="radio" name="login" value="loc" '.
2534: $loccheck.' onchange="'.$jscall.'" onclick="'.
2535: $jscall.'" />';
2536: }
2537: $autharg = '<input type="text" size="10" name="locarg" value="'.
2538: $locarg.'" onchange="'.$jscall.'" />';
2539: $result = &mt('[_1] Local Authentication with argument [_2]',
2540: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2541: return $result;
2542: }
2543:
2544: sub authform_filesystem{
2545: my %in = (
2546: formname => 'document.cu',
2547: kerb_def_dom => 'MSU.EDU',
2548: @_,
2549: );
1.586 raeburn 2550: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2551: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2552: if (defined($in{'curr_authtype'})) {
2553: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2554: if ($can_assign{'fsys'}) {
1.772 bisitz 2555: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2556: if (defined($in{'mode'})) {
2557: if ($in{'mode'} eq 'modifyuser') {
2558: $fsyscheck = '';
2559: }
2560: }
1.586 raeburn 2561: } else {
2562: $result = &mt('Currently Filesystem Authenticated.');
2563: return $result;
2564: }
2565: }
2566: } else {
2567: if ($authnum == 1) {
1.784 bisitz 2568: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2569: }
2570: }
2571: if (!$can_assign{'fsys'}) {
2572: return;
1.587 raeburn 2573: } elsif ($authtype eq '') {
1.591 raeburn 2574: if (defined($in{'mode'})) {
1.587 raeburn 2575: if ($in{'mode'} eq 'modifycourse') {
2576: if ($authnum == 1) {
1.784 bisitz 2577: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2578: }
2579: }
2580: }
1.586 raeburn 2581: }
2582: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2583: if ($authtype eq '') {
2584: $authtype = '<input type="radio" name="login" value="fsys" '.
2585: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2586: $jscall.'" />';
2587: }
2588: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2589: ' onchange="'.$jscall.'" />';
2590: $result = &mt
1.144 matthew 2591: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2592: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2593: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2594: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2595: 'onchange="'.$jscall.'" />');
1.32 matthew 2596: return $result;
2597: }
2598:
1.586 raeburn 2599: sub get_assignable_auth {
2600: my ($dom) = @_;
2601: if ($dom eq '') {
2602: $dom = $env{'request.role.domain'};
2603: }
2604: my %can_assign = (
2605: krb4 => 1,
2606: krb5 => 1,
2607: int => 1,
2608: loc => 1,
2609: );
2610: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2611: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2612: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2613: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2614: my $context;
2615: if ($env{'request.role'} =~ /^au/) {
2616: $context = 'author';
2617: } elsif ($env{'request.role'} =~ /^dc/) {
2618: $context = 'domain';
2619: } elsif ($env{'request.course.id'}) {
2620: $context = 'course';
2621: }
2622: if ($context) {
2623: if (ref($authhash->{$context}) eq 'HASH') {
2624: %can_assign = %{$authhash->{$context}};
2625: }
2626: }
2627: }
2628: }
2629: my $authnum = 0;
2630: foreach my $key (keys(%can_assign)) {
2631: if ($can_assign{$key}) {
2632: $authnum ++;
2633: }
2634: }
2635: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2636: $authnum --;
2637: }
2638: return ($authnum,%can_assign);
2639: }
2640:
1.80 albertel 2641: ###############################################################
2642: ## Get Kerberos Defaults for Domain ##
2643: ###############################################################
2644: ##
2645: ## Returns default kerberos version and an associated argument
2646: ## as listed in file domain.tab. If not listed, provides
2647: ## appropriate default domain and kerberos version.
2648: ##
2649: #-------------------------------------------
2650:
2651: =pod
2652:
1.648 raeburn 2653: =item * &get_kerberos_defaults()
1.80 albertel 2654:
2655: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2656: version and domain. If not found, it defaults to version 4 and the
2657: domain of the server.
1.80 albertel 2658:
1.648 raeburn 2659: =over 4
2660:
1.80 albertel 2661: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2662:
1.648 raeburn 2663: =back
2664:
2665: =back
2666:
1.80 albertel 2667: =cut
2668:
2669: #-------------------------------------------
2670: sub get_kerberos_defaults {
2671: my $domain=shift;
1.641 raeburn 2672: my ($krbdef,$krbdefdom);
2673: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2674: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2675: $krbdef = $domdefaults{'auth_def'};
2676: $krbdefdom = $domdefaults{'auth_arg_def'};
2677: } else {
1.80 albertel 2678: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2679: my $krbdefdom=$1;
2680: $krbdefdom=~tr/a-z/A-Z/;
2681: $krbdef = "krb4";
2682: }
2683: return ($krbdef,$krbdefdom);
2684: }
1.112 bowersj2 2685:
1.32 matthew 2686:
1.46 matthew 2687: ###############################################################
2688: ## Thesaurus Functions ##
2689: ###############################################################
1.20 www 2690:
1.46 matthew 2691: =pod
1.20 www 2692:
1.112 bowersj2 2693: =head1 Thesaurus Functions
2694:
2695: =over 4
2696:
1.648 raeburn 2697: =item * &initialize_keywords()
1.46 matthew 2698:
2699: Initializes the package variable %Keywords if it is empty. Uses the
2700: package variable $thesaurus_db_file.
2701:
2702: =cut
2703:
2704: ###################################################
2705:
2706: sub initialize_keywords {
2707: return 1 if (scalar keys(%Keywords));
2708: # If we are here, %Keywords is empty, so fill it up
2709: # Make sure the file we need exists...
2710: if (! -e $thesaurus_db_file) {
2711: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2712: " failed because it does not exist");
2713: return 0;
2714: }
2715: # Set up the hash as a database
2716: my %thesaurus_db;
2717: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2718: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2719: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2720: $thesaurus_db_file);
2721: return 0;
2722: }
2723: # Get the average number of appearances of a word.
2724: my $avecount = $thesaurus_db{'average.count'};
2725: # Put keywords (those that appear > average) into %Keywords
2726: while (my ($word,$data)=each (%thesaurus_db)) {
2727: my ($count,undef) = split /:/,$data;
2728: $Keywords{$word}++ if ($count > $avecount);
2729: }
2730: untie %thesaurus_db;
2731: # Remove special values from %Keywords.
1.356 albertel 2732: foreach my $value ('total.count','average.count') {
2733: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2734: }
1.46 matthew 2735: return 1;
2736: }
2737:
2738: ###################################################
2739:
2740: =pod
2741:
1.648 raeburn 2742: =item * &keyword($word)
1.46 matthew 2743:
2744: Returns true if $word is a keyword. A keyword is a word that appears more
2745: than the average number of times in the thesaurus database. Calls
2746: &initialize_keywords
2747:
2748: =cut
2749:
2750: ###################################################
1.20 www 2751:
2752: sub keyword {
1.46 matthew 2753: return if (!&initialize_keywords());
2754: my $word=lc(shift());
2755: $word=~s/\W//g;
2756: return exists($Keywords{$word});
1.20 www 2757: }
1.46 matthew 2758:
2759: ###############################################################
2760:
2761: =pod
1.20 www 2762:
1.648 raeburn 2763: =item * &get_related_words()
1.46 matthew 2764:
1.160 matthew 2765: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2766: an array of words. If the keyword is not in the thesaurus, an empty array
2767: will be returned. The order of the words returned is determined by the
2768: database which holds them.
2769:
2770: Uses global $thesaurus_db_file.
2771:
2772: =cut
2773:
2774: ###############################################################
2775: sub get_related_words {
2776: my $keyword = shift;
2777: my %thesaurus_db;
2778: if (! -e $thesaurus_db_file) {
2779: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2780: "failed because the file does not exist");
2781: return ();
2782: }
2783: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2784: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2785: return ();
2786: }
2787: my @Words=();
1.429 www 2788: my $count=0;
1.46 matthew 2789: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2790: # The first element is the number of times
2791: # the word appears. We do not need it now.
1.429 www 2792: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2793: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2794: my $threshold=$mostfrequentcount/10;
2795: foreach my $possibleword (@RelatedWords) {
2796: my ($word,$wordcount)=split(/\,/,$possibleword);
2797: if ($wordcount>$threshold) {
2798: push(@Words,$word);
2799: $count++;
2800: if ($count>10) { last; }
2801: }
1.20 www 2802: }
2803: }
1.46 matthew 2804: untie %thesaurus_db;
2805: return @Words;
1.14 harris41 2806: }
1.46 matthew 2807:
1.112 bowersj2 2808: =pod
2809:
2810: =back
2811:
2812: =cut
1.61 www 2813:
2814: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2815: =pod
2816:
1.112 bowersj2 2817: =head1 User Name Functions
2818:
2819: =over 4
2820:
1.648 raeburn 2821: =item * &plainname($uname,$udom,$first)
1.81 albertel 2822:
1.112 bowersj2 2823: Takes a users logon name and returns it as a string in
1.226 albertel 2824: "first middle last generation" form
2825: if $first is set to 'lastname' then it returns it as
2826: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2827:
2828: =cut
1.61 www 2829:
1.295 www 2830:
1.81 albertel 2831: ###############################################################
1.61 www 2832: sub plainname {
1.226 albertel 2833: my ($uname,$udom,$first)=@_;
1.537 albertel 2834: return if (!defined($uname) || !defined($udom));
1.295 www 2835: my %names=&getnames($uname,$udom);
1.226 albertel 2836: my $name=&Apache::lonnet::format_name($names{'firstname'},
2837: $names{'middlename'},
2838: $names{'lastname'},
2839: $names{'generation'},$first);
2840: $name=~s/^\s+//;
1.62 www 2841: $name=~s/\s+$//;
2842: $name=~s/\s+/ /g;
1.353 albertel 2843: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2844: return $name;
1.61 www 2845: }
1.66 www 2846:
2847: # -------------------------------------------------------------------- Nickname
1.81 albertel 2848: =pod
2849:
1.648 raeburn 2850: =item * &nickname($uname,$udom)
1.81 albertel 2851:
2852: Gets a users name and returns it as a string as
2853:
2854: ""nickname""
1.66 www 2855:
1.81 albertel 2856: if the user has a nickname or
2857:
2858: "first middle last generation"
2859:
2860: if the user does not
2861:
2862: =cut
1.66 www 2863:
2864: sub nickname {
2865: my ($uname,$udom)=@_;
1.537 albertel 2866: return if (!defined($uname) || !defined($udom));
1.295 www 2867: my %names=&getnames($uname,$udom);
1.68 albertel 2868: my $name=$names{'nickname'};
1.66 www 2869: if ($name) {
2870: $name='"'.$name.'"';
2871: } else {
2872: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2873: $names{'lastname'}.' '.$names{'generation'};
2874: $name=~s/\s+$//;
2875: $name=~s/\s+/ /g;
2876: }
2877: return $name;
2878: }
2879:
1.295 www 2880: sub getnames {
2881: my ($uname,$udom)=@_;
1.537 albertel 2882: return if (!defined($uname) || !defined($udom));
1.433 albertel 2883: if ($udom eq 'public' && $uname eq 'public') {
2884: return ('lastname' => &mt('Public'));
2885: }
1.295 www 2886: my $id=$uname.':'.$udom;
2887: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2888: if ($cached) {
2889: return %{$names};
2890: } else {
2891: my %loadnames=&Apache::lonnet::get('environment',
2892: ['firstname','middlename','lastname','generation','nickname'],
2893: $udom,$uname);
2894: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2895: return %loadnames;
2896: }
2897: }
1.61 www 2898:
1.542 raeburn 2899: # -------------------------------------------------------------------- getemails
1.648 raeburn 2900:
1.542 raeburn 2901: =pod
2902:
1.648 raeburn 2903: =item * &getemails($uname,$udom)
1.542 raeburn 2904:
2905: Gets a user's email information and returns it as a hash with keys:
2906: notification, critnotification, permanentemail
2907:
2908: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2909: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2910:
1.648 raeburn 2911:
1.542 raeburn 2912: =cut
2913:
1.648 raeburn 2914:
1.466 albertel 2915: sub getemails {
2916: my ($uname,$udom)=@_;
2917: if ($udom eq 'public' && $uname eq 'public') {
2918: return;
2919: }
1.467 www 2920: if (!$udom) { $udom=$env{'user.domain'}; }
2921: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2922: my $id=$uname.':'.$udom;
2923: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2924: if ($cached) {
2925: return %{$names};
2926: } else {
2927: my %loadnames=&Apache::lonnet::get('environment',
2928: ['notification','critnotification',
2929: 'permanentemail'],
2930: $udom,$uname);
2931: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2932: return %loadnames;
2933: }
2934: }
2935:
1.551 albertel 2936: sub flush_email_cache {
2937: my ($uname,$udom)=@_;
2938: if (!$udom) { $udom =$env{'user.domain'}; }
2939: if (!$uname) { $uname=$env{'user.name'}; }
2940: return if ($udom eq 'public' && $uname eq 'public');
2941: my $id=$uname.':'.$udom;
2942: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2943: }
2944:
1.728 raeburn 2945: # -------------------------------------------------------------------- getlangs
2946:
2947: =pod
2948:
2949: =item * &getlangs($uname,$udom)
2950:
2951: Gets a user's language preference and returns it as a hash with key:
2952: language.
2953:
2954: =cut
2955:
2956:
2957: sub getlangs {
2958: my ($uname,$udom) = @_;
2959: if (!$udom) { $udom =$env{'user.domain'}; }
2960: if (!$uname) { $uname=$env{'user.name'}; }
2961: my $id=$uname.':'.$udom;
2962: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2963: if ($cached) {
2964: return %{$langs};
2965: } else {
2966: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2967: $udom,$uname);
2968: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2969: return %loadlangs;
2970: }
2971: }
2972:
2973: sub flush_langs_cache {
2974: my ($uname,$udom)=@_;
2975: if (!$udom) { $udom =$env{'user.domain'}; }
2976: if (!$uname) { $uname=$env{'user.name'}; }
2977: return if ($udom eq 'public' && $uname eq 'public');
2978: my $id=$uname.':'.$udom;
2979: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2980: }
2981:
1.61 www 2982: # ------------------------------------------------------------------ Screenname
1.81 albertel 2983:
2984: =pod
2985:
1.648 raeburn 2986: =item * &screenname($uname,$udom)
1.81 albertel 2987:
2988: Gets a users screenname and returns it as a string
2989:
2990: =cut
1.61 www 2991:
2992: sub screenname {
2993: my ($uname,$udom)=@_;
1.258 albertel 2994: if ($uname eq $env{'user.name'} &&
2995: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2996: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2997: return $names{'screenname'};
1.62 www 2998: }
2999:
1.212 albertel 3000:
1.802 bisitz 3001: # ------------------------------------------------------------- Confirm Wrapper
3002: =pod
3003:
3004: =item confirmwrapper
3005:
3006: Wrap messages about completion of operation in box
3007:
3008: =cut
3009:
3010: sub confirmwrapper {
3011: my ($message)=@_;
3012: if ($message) {
3013: return "\n".'<div class="LC_confirm_box">'."\n"
3014: .$message."\n"
3015: .'</div>'."\n";
3016: } else {
3017: return $message;
3018: }
3019: }
3020:
1.62 www 3021: # ------------------------------------------------------------- Message Wrapper
3022:
3023: sub messagewrapper {
1.369 www 3024: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3025: return
1.441 albertel 3026: '<a href="/adm/email?compose=individual&'.
3027: 'recname='.$username.'&recdom='.$domain.
3028: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3029: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3030: }
1.802 bisitz 3031:
1.74 www 3032: # --------------------------------------------------------------- Notes Wrapper
3033:
3034: sub noteswrapper {
3035: my ($link,$un,$do)=@_;
3036: return
1.896 amueller 3037: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3038: }
1.802 bisitz 3039:
1.62 www 3040: # ------------------------------------------------------------- Aboutme Wrapper
3041:
3042: sub aboutmewrapper {
1.166 www 3043: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3044: if (!defined($username) && !defined($domain)) {
3045: return;
3046: }
1.892 amueller 3047: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3048: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3049: }
3050:
3051: # ------------------------------------------------------------ Syllabus Wrapper
3052:
3053: sub syllabuswrapper {
1.707 bisitz 3054: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3055: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3056: }
1.14 harris41 3057:
1.802 bisitz 3058: # -----------------------------------------------------------------------------
3059:
1.208 matthew 3060: sub track_student_link {
1.887 raeburn 3061: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3062: my $link ="/adm/trackstudent?";
1.208 matthew 3063: my $title = 'View recent activity';
3064: if (defined($sname) && $sname !~ /^\s*$/ &&
3065: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3066: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3067: $title .= ' of this student';
1.268 albertel 3068: }
1.208 matthew 3069: if (defined($target) && $target !~ /^\s*$/) {
3070: $target = qq{target="$target"};
3071: } else {
3072: $target = '';
3073: }
1.268 albertel 3074: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3075: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3076: $title = &mt($title);
3077: $linktext = &mt($linktext);
1.448 albertel 3078: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3079: &help_open_topic('View_recent_activity');
1.208 matthew 3080: }
3081:
1.781 raeburn 3082: sub slot_reservations_link {
3083: my ($linktext,$sname,$sdom,$target) = @_;
3084: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3085: my $title = 'View slot reservation history';
3086: if (defined($sname) && $sname !~ /^\s*$/ &&
3087: defined($sdom) && $sdom !~ /^\s*$/) {
3088: $link .= "&uname=$sname&udom=$sdom";
3089: $title .= ' of this student';
3090: }
3091: if (defined($target) && $target !~ /^\s*$/) {
3092: $target = qq{target="$target"};
3093: } else {
3094: $target = '';
3095: }
3096: $title = &mt($title);
3097: $linktext = &mt($linktext);
3098: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3099: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3100:
3101: }
3102:
1.508 www 3103: # ===================================================== Display a student photo
3104:
3105:
1.509 albertel 3106: sub student_image_tag {
1.508 www 3107: my ($domain,$user)=@_;
3108: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3109: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3110: return '<img src="'.$imgsrc.'" align="right" />';
3111: } else {
3112: return '';
3113: }
3114: }
3115:
1.112 bowersj2 3116: =pod
3117:
3118: =back
3119:
3120: =head1 Access .tab File Data
3121:
3122: =over 4
3123:
1.648 raeburn 3124: =item * &languageids()
1.112 bowersj2 3125:
3126: returns list of all language ids
3127:
3128: =cut
3129:
1.14 harris41 3130: sub languageids {
1.16 harris41 3131: return sort(keys(%language));
1.14 harris41 3132: }
3133:
1.112 bowersj2 3134: =pod
3135:
1.648 raeburn 3136: =item * &languagedescription()
1.112 bowersj2 3137:
3138: returns description of a specified language id
3139:
3140: =cut
3141:
1.14 harris41 3142: sub languagedescription {
1.125 www 3143: my $code=shift;
3144: return ($supported_language{$code}?'* ':'').
3145: $language{$code}.
1.126 www 3146: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3147: }
3148:
3149: sub plainlanguagedescription {
3150: my $code=shift;
3151: return $language{$code};
3152: }
3153:
3154: sub supportedlanguagecode {
3155: my $code=shift;
3156: return $supported_language{$code};
1.97 www 3157: }
3158:
1.112 bowersj2 3159: =pod
3160:
1.648 raeburn 3161: =item * ©rightids()
1.112 bowersj2 3162:
3163: returns list of all copyrights
3164:
3165: =cut
3166:
3167: sub copyrightids {
3168: return sort(keys(%cprtag));
3169: }
3170:
3171: =pod
3172:
1.648 raeburn 3173: =item * ©rightdescription()
1.112 bowersj2 3174:
3175: returns description of a specified copyright id
3176:
3177: =cut
3178:
3179: sub copyrightdescription {
1.166 www 3180: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3181: }
1.197 matthew 3182:
3183: =pod
3184:
1.648 raeburn 3185: =item * &source_copyrightids()
1.192 taceyjo1 3186:
3187: returns list of all source copyrights
3188:
3189: =cut
3190:
3191: sub source_copyrightids {
3192: return sort(keys(%scprtag));
3193: }
3194:
3195: =pod
3196:
1.648 raeburn 3197: =item * &source_copyrightdescription()
1.192 taceyjo1 3198:
3199: returns description of a specified source copyright id
3200:
3201: =cut
3202:
3203: sub source_copyrightdescription {
3204: return &mt($scprtag{shift(@_)});
3205: }
1.112 bowersj2 3206:
3207: =pod
3208:
1.648 raeburn 3209: =item * &filecategories()
1.112 bowersj2 3210:
3211: returns list of all file categories
3212:
3213: =cut
3214:
3215: sub filecategories {
3216: return sort(keys(%category_extensions));
3217: }
3218:
3219: =pod
3220:
1.648 raeburn 3221: =item * &filecategorytypes()
1.112 bowersj2 3222:
3223: returns list of file types belonging to a given file
3224: category
3225:
3226: =cut
3227:
3228: sub filecategorytypes {
1.356 albertel 3229: my ($cat) = @_;
3230: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3231: }
3232:
3233: =pod
3234:
1.648 raeburn 3235: =item * &fileembstyle()
1.112 bowersj2 3236:
3237: returns embedding style for a specified file type
3238:
3239: =cut
3240:
3241: sub fileembstyle {
3242: return $fe{lc(shift(@_))};
1.169 www 3243: }
3244:
1.351 www 3245: sub filemimetype {
3246: return $fm{lc(shift(@_))};
3247: }
3248:
1.169 www 3249:
3250: sub filecategoryselect {
3251: my ($name,$value)=@_;
1.189 matthew 3252: return &select_form($value,$name,
1.169 www 3253: '' => &mt('Any category'),
3254: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3255: }
3256:
3257: =pod
3258:
1.648 raeburn 3259: =item * &filedescription()
1.112 bowersj2 3260:
3261: returns description for a specified file type
3262:
3263: =cut
3264:
3265: sub filedescription {
1.188 matthew 3266: my $file_description = $fd{lc(shift())};
3267: $file_description =~ s:([\[\]]):~$1:g;
3268: return &mt($file_description);
1.112 bowersj2 3269: }
3270:
3271: =pod
3272:
1.648 raeburn 3273: =item * &filedescriptionex()
1.112 bowersj2 3274:
3275: returns description for a specified file type with
3276: extra formatting
3277:
3278: =cut
3279:
3280: sub filedescriptionex {
3281: my $ex=shift;
1.188 matthew 3282: my $file_description = $fd{lc($ex)};
3283: $file_description =~ s:([\[\]]):~$1:g;
3284: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3285: }
3286:
3287: # End of .tab access
3288: =pod
3289:
3290: =back
3291:
3292: =cut
3293:
3294: # ------------------------------------------------------------------ File Types
3295: sub fileextensions {
3296: return sort(keys(%fe));
3297: }
3298:
1.97 www 3299: # ----------------------------------------------------------- Display Languages
3300: # returns a hash with all desired display languages
3301: #
3302:
3303: sub display_languages {
3304: my %languages=();
1.695 raeburn 3305: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3306: $languages{$lang}=1;
1.97 www 3307: }
3308: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3309: if ($env{'form.displaylanguage'}) {
1.356 albertel 3310: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3311: $languages{$lang}=1;
1.97 www 3312: }
3313: }
3314: return %languages;
1.14 harris41 3315: }
3316:
1.582 albertel 3317: sub languages {
3318: my ($possible_langs) = @_;
1.695 raeburn 3319: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3320: if (!ref($possible_langs)) {
3321: if( wantarray ) {
3322: return @preferred_langs;
3323: } else {
3324: return $preferred_langs[0];
3325: }
3326: }
3327: my %possibilities = map { $_ => 1 } (@$possible_langs);
3328: my @preferred_possibilities;
3329: foreach my $preferred_lang (@preferred_langs) {
3330: if (exists($possibilities{$preferred_lang})) {
3331: push(@preferred_possibilities, $preferred_lang);
3332: }
3333: }
3334: if( wantarray ) {
3335: return @preferred_possibilities;
3336: }
3337: return $preferred_possibilities[0];
3338: }
3339:
1.742 raeburn 3340: sub user_lang {
3341: my ($touname,$toudom,$fromcid) = @_;
3342: my @userlangs;
3343: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3344: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3345: $env{'course.'.$fromcid.'.languages'}));
3346: } else {
3347: my %langhash = &getlangs($touname,$toudom);
3348: if ($langhash{'languages'} ne '') {
3349: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3350: } else {
3351: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3352: if ($domdefs{'lang_def'} ne '') {
3353: @userlangs = ($domdefs{'lang_def'});
3354: }
3355: }
3356: }
3357: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3358: my $user_lh = Apache::localize->get_handle(@languages);
3359: return $user_lh;
3360: }
3361:
3362:
1.112 bowersj2 3363: ###############################################################
3364: ## Student Answer Attempts ##
3365: ###############################################################
3366:
3367: =pod
3368:
3369: =head1 Alternate Problem Views
3370:
3371: =over 4
3372:
1.648 raeburn 3373: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3374: $getattempt, $regexp, $gradesub)
3375:
3376: Return string with previous attempt on problem. Arguments:
3377:
3378: =over 4
3379:
3380: =item * $symb: Problem, including path
3381:
3382: =item * $username: username of the desired student
3383:
3384: =item * $domain: domain of the desired student
1.14 harris41 3385:
1.112 bowersj2 3386: =item * $course: Course ID
1.14 harris41 3387:
1.112 bowersj2 3388: =item * $getattempt: Leave blank for all attempts, otherwise put
3389: something
1.14 harris41 3390:
1.112 bowersj2 3391: =item * $regexp: if string matches this regexp, the string will be
3392: sent to $gradesub
1.14 harris41 3393:
1.112 bowersj2 3394: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3395:
1.112 bowersj2 3396: =back
1.14 harris41 3397:
1.112 bowersj2 3398: The output string is a table containing all desired attempts, if any.
1.16 harris41 3399:
1.112 bowersj2 3400: =cut
1.1 albertel 3401:
3402: sub get_previous_attempt {
1.43 ng 3403: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3404: my $prevattempts='';
1.43 ng 3405: no strict 'refs';
1.1 albertel 3406: if ($symb) {
1.3 albertel 3407: my (%returnhash)=
3408: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3409: if ($returnhash{'version'}) {
3410: my %lasthash=();
3411: my $version;
3412: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3413: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3414: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3415: }
1.1 albertel 3416: }
1.596 albertel 3417: $prevattempts=&start_data_table().&start_data_table_header_row();
3418: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3419: foreach my $key (sort(keys(%lasthash))) {
3420: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3421: if ($#parts > 0) {
1.31 albertel 3422: my $data=$parts[-1];
3423: pop(@parts);
1.596 albertel 3424: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3425: } else {
1.41 ng 3426: if ($#parts == 0) {
3427: $prevattempts.='<th>'.$parts[0].'</th>';
3428: } else {
3429: $prevattempts.='<th>'.$ign.'</th>';
3430: }
1.31 albertel 3431: }
1.16 harris41 3432: }
1.596 albertel 3433: $prevattempts.=&end_data_table_header_row();
1.40 ng 3434: if ($getattempt eq '') {
3435: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3436: $prevattempts.=&start_data_table_row().
3437: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3438: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3439: my $value = &format_previous_attempt_value($key,
3440: $returnhash{$version.':'.$key});
3441: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3442: }
1.596 albertel 3443: $prevattempts.=&end_data_table_row();
1.40 ng 3444: }
1.1 albertel 3445: }
1.596 albertel 3446: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3447: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3448: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3449: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3450: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3451: }
1.596 albertel 3452: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3453: } else {
1.596 albertel 3454: $prevattempts=
3455: &start_data_table().&start_data_table_row().
3456: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3457: &end_data_table_row().&end_data_table();
1.1 albertel 3458: }
3459: } else {
1.596 albertel 3460: $prevattempts=
3461: &start_data_table().&start_data_table_row().
3462: '<td>'.&mt('No data.').'</td>'.
3463: &end_data_table_row().&end_data_table();
1.1 albertel 3464: }
1.10 albertel 3465: }
3466:
1.581 albertel 3467: sub format_previous_attempt_value {
3468: my ($key,$value) = @_;
3469: if ($key =~ /timestamp/) {
3470: $value = &Apache::lonlocal::locallocaltime($value);
3471: } elsif (ref($value) eq 'ARRAY') {
3472: $value = '('.join(', ', @{ $value }).')';
3473: } else {
3474: $value = &unescape($value);
3475: }
3476: return $value;
3477: }
3478:
3479:
1.107 albertel 3480: sub relative_to_absolute {
3481: my ($url,$output)=@_;
3482: my $parser=HTML::TokeParser->new(\$output);
3483: my $token;
3484: my $thisdir=$url;
3485: my @rlinks=();
3486: while ($token=$parser->get_token) {
3487: if ($token->[0] eq 'S') {
3488: if ($token->[1] eq 'a') {
3489: if ($token->[2]->{'href'}) {
3490: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3491: }
3492: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3493: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3494: } elsif ($token->[1] eq 'base') {
3495: $thisdir=$token->[2]->{'href'};
3496: }
3497: }
3498: }
3499: $thisdir=~s-/[^/]*$--;
1.356 albertel 3500: foreach my $link (@rlinks) {
1.726 raeburn 3501: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3502: ($link=~/^\//) ||
3503: ($link=~/^javascript:/i) ||
3504: ($link=~/^mailto:/i) ||
3505: ($link=~/^\#/)) {
3506: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3507: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3508: }
3509: }
3510: # -------------------------------------------------- Deal with Applet codebases
3511: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3512: return $output;
3513: }
3514:
1.112 bowersj2 3515: =pod
3516:
1.648 raeburn 3517: =item * &get_student_view()
1.112 bowersj2 3518:
3519: show a snapshot of what student was looking at
3520:
3521: =cut
3522:
1.10 albertel 3523: sub get_student_view {
1.186 albertel 3524: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3525: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3526: my (%form);
1.10 albertel 3527: my @elements=('symb','courseid','domain','username');
3528: foreach my $element (@elements) {
1.186 albertel 3529: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3530: }
1.186 albertel 3531: if (defined($moreenv)) {
3532: %form=(%form,%{$moreenv});
3533: }
1.236 albertel 3534: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3535: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3536: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3537: $userview=~s/\<body[^\>]*\>//gi;
3538: $userview=~s/\<\/body\>//gi;
3539: $userview=~s/\<html\>//gi;
3540: $userview=~s/\<\/html\>//gi;
3541: $userview=~s/\<head\>//gi;
3542: $userview=~s/\<\/head\>//gi;
3543: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3544: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3545: if (wantarray) {
3546: return ($userview,$response);
3547: } else {
3548: return $userview;
3549: }
3550: }
3551:
3552: sub get_student_view_with_retries {
3553: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3554:
3555: my $ok = 0; # True if we got a good response.
3556: my $content;
3557: my $response;
3558:
3559: # Try to get the student_view done. within the retries count:
3560:
3561: do {
3562: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3563: $ok = $response->is_success;
3564: if (!$ok) {
3565: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3566: }
3567: $retries--;
3568: } while (!$ok && ($retries > 0));
3569:
3570: if (!$ok) {
3571: $content = ''; # On error return an empty content.
3572: }
1.651 www 3573: if (wantarray) {
3574: return ($content, $response);
3575: } else {
3576: return $content;
3577: }
1.11 albertel 3578: }
3579:
1.112 bowersj2 3580: =pod
3581:
1.648 raeburn 3582: =item * &get_student_answers()
1.112 bowersj2 3583:
3584: show a snapshot of how student was answering problem
3585:
3586: =cut
3587:
1.11 albertel 3588: sub get_student_answers {
1.100 sakharuk 3589: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3590: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3591: my (%moreenv);
1.11 albertel 3592: my @elements=('symb','courseid','domain','username');
3593: foreach my $element (@elements) {
1.186 albertel 3594: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3595: }
1.186 albertel 3596: $moreenv{'grade_target'}='answer';
3597: %moreenv=(%form,%moreenv);
1.497 raeburn 3598: $feedurl = &Apache::lonnet::clutter($feedurl);
3599: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3600: return $userview;
1.1 albertel 3601: }
1.116 albertel 3602:
3603: =pod
3604:
3605: =item * &submlink()
3606:
1.242 albertel 3607: Inputs: $text $uname $udom $symb $target
1.116 albertel 3608:
3609: Returns: A link to grades.pm such as to see the SUBM view of a student
3610:
3611: =cut
3612:
3613: ###############################################
3614: sub submlink {
1.242 albertel 3615: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3616: if (!($uname && $udom)) {
3617: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3618: &Apache::lonnet::whichuser($symb);
1.116 albertel 3619: if (!$symb) { $symb=$cursymb; }
3620: }
1.254 matthew 3621: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3622: $symb=&escape($symb);
1.242 albertel 3623: if ($target) { $target="target=\"$target\""; }
3624: return '<a href="/adm/grades?&command=submission&'.
3625: 'symb='.$symb.'&student='.$uname.
3626: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3627: }
3628: ##############################################
3629:
3630: =pod
3631:
3632: =item * &pgrdlink()
3633:
3634: Inputs: $text $uname $udom $symb $target
3635:
3636: Returns: A link to grades.pm such as to see the PGRD view of a student
3637:
3638: =cut
3639:
3640: ###############################################
3641: sub pgrdlink {
3642: my $link=&submlink(@_);
3643: $link=~s/(&command=submission)/$1&showgrading=yes/;
3644: return $link;
3645: }
3646: ##############################################
3647:
3648: =pod
3649:
3650: =item * &pprmlink()
3651:
3652: Inputs: $text $uname $udom $symb $target
3653:
3654: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3655: student and a specific resource
1.242 albertel 3656:
3657: =cut
3658:
3659: ###############################################
3660: sub pprmlink {
3661: my ($text,$uname,$udom,$symb,$target)=@_;
3662: if (!($uname && $udom)) {
3663: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3664: &Apache::lonnet::whichuser($symb);
1.242 albertel 3665: if (!$symb) { $symb=$cursymb; }
3666: }
1.254 matthew 3667: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3668: $symb=&escape($symb);
1.242 albertel 3669: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3670: return '<a href="/adm/parmset?command=set&'.
3671: 'symb='.$symb.'&uname='.$uname.
3672: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3673: }
3674: ##############################################
1.37 matthew 3675:
1.112 bowersj2 3676: =pod
3677:
3678: =back
3679:
3680: =cut
3681:
1.37 matthew 3682: ###############################################
1.51 www 3683:
3684:
3685: sub timehash {
1.687 raeburn 3686: my ($thistime) = @_;
3687: my $timezone = &Apache::lonlocal::gettimezone();
3688: my $dt = DateTime->from_epoch(epoch => $thistime)
3689: ->set_time_zone($timezone);
3690: my $wday = $dt->day_of_week();
3691: if ($wday == 7) { $wday = 0; }
3692: return ( 'second' => $dt->second(),
3693: 'minute' => $dt->minute(),
3694: 'hour' => $dt->hour(),
3695: 'day' => $dt->day_of_month(),
3696: 'month' => $dt->month(),
3697: 'year' => $dt->year(),
3698: 'weekday' => $wday,
3699: 'dayyear' => $dt->day_of_year(),
3700: 'dlsav' => $dt->is_dst() );
1.51 www 3701: }
3702:
1.370 www 3703: sub utc_string {
3704: my ($date)=@_;
1.371 www 3705: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3706: }
3707:
1.51 www 3708: sub maketime {
3709: my %th=@_;
1.687 raeburn 3710: my ($epoch_time,$timezone,$dt);
3711: $timezone = &Apache::lonlocal::gettimezone();
3712: eval {
3713: $dt = DateTime->new( year => $th{'year'},
3714: month => $th{'month'},
3715: day => $th{'day'},
3716: hour => $th{'hour'},
3717: minute => $th{'minute'},
3718: second => $th{'second'},
3719: time_zone => $timezone,
3720: );
3721: };
3722: if (!$@) {
3723: $epoch_time = $dt->epoch;
3724: if ($epoch_time) {
3725: return $epoch_time;
3726: }
3727: }
1.51 www 3728: return POSIX::mktime(
3729: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3730: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3731: }
3732:
3733: #########################################
1.51 www 3734:
3735: sub findallcourses {
1.482 raeburn 3736: my ($roles,$uname,$udom) = @_;
1.355 albertel 3737: my %roles;
3738: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3739: my %courses;
1.51 www 3740: my $now=time;
1.482 raeburn 3741: if (!defined($uname)) {
3742: $uname = $env{'user.name'};
3743: }
3744: if (!defined($udom)) {
3745: $udom = $env{'user.domain'};
3746: }
3747: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3748: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3749: if (!%roles) {
3750: %roles = (
3751: cc => 1,
1.907 raeburn 3752: co => 1,
1.482 raeburn 3753: in => 1,
3754: ep => 1,
3755: ta => 1,
3756: cr => 1,
3757: st => 1,
3758: );
3759: }
3760: foreach my $entry (keys(%roleshash)) {
3761: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3762: if ($trole =~ /^cr/) {
3763: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3764: } else {
3765: next if (!exists($roles{$trole}));
3766: }
3767: if ($tend) {
3768: next if ($tend < $now);
3769: }
3770: if ($tstart) {
3771: next if ($tstart > $now);
3772: }
3773: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3774: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3775: if ($secpart eq '') {
3776: ($cnum,$role) = split(/_/,$cnumpart);
3777: $sec = 'none';
3778: $realsec = '';
3779: } else {
3780: $cnum = $cnumpart;
3781: ($sec,$role) = split(/_/,$secpart);
3782: $realsec = $sec;
1.490 raeburn 3783: }
1.482 raeburn 3784: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3785: }
3786: } else {
3787: foreach my $key (keys(%env)) {
1.483 albertel 3788: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3789: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3790: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3791: next if ($role eq 'ca' || $role eq 'aa');
3792: next if (%roles && !exists($roles{$role}));
3793: my ($starttime,$endtime)=split(/\./,$env{$key});
3794: my $active=1;
3795: if ($starttime) {
3796: if ($now<$starttime) { $active=0; }
3797: }
3798: if ($endtime) {
3799: if ($now>$endtime) { $active=0; }
3800: }
3801: if ($active) {
3802: if ($sec eq '') {
3803: $sec = 'none';
3804: }
3805: $courses{$cdom.'_'.$cnum}{$sec} =
3806: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3807: }
3808: }
1.51 www 3809: }
3810: }
1.474 raeburn 3811: return %courses;
1.51 www 3812: }
1.37 matthew 3813:
1.54 www 3814: ###############################################
1.474 raeburn 3815:
3816: sub blockcheck {
1.482 raeburn 3817: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3818:
3819: if (!defined($udom)) {
3820: $udom = $env{'user.domain'};
3821: }
3822: if (!defined($uname)) {
3823: $uname = $env{'user.name'};
3824: }
3825:
3826: # If uname and udom are for a course, check for blocks in the course.
3827:
3828: if (&Apache::lonnet::is_course($udom,$uname)) {
3829: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3830: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3831: return ($startblock,$endblock);
3832: }
1.474 raeburn 3833:
1.502 raeburn 3834: my $startblock = 0;
3835: my $endblock = 0;
1.482 raeburn 3836: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3837:
1.490 raeburn 3838: # If uname is for a user, and activity is course-specific, i.e.,
3839: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3840:
1.490 raeburn 3841: if (($activity eq 'boards' || $activity eq 'chat' ||
3842: $activity eq 'groups') && ($env{'request.course.id'})) {
3843: foreach my $key (keys(%live_courses)) {
3844: if ($key ne $env{'request.course.id'}) {
3845: delete($live_courses{$key});
3846: }
3847: }
3848: }
3849:
3850: my $otheruser = 0;
3851: my %own_courses;
3852: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3853: # Resource belongs to user other than current user.
3854: $otheruser = 1;
3855: # Gather courses for current user
3856: %own_courses =
3857: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3858: }
3859:
3860: # Gather active course roles - course coordinator, instructor,
3861: # exam proctor, ta, student, or custom role.
1.474 raeburn 3862:
3863: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3864: my ($cdom,$cnum);
3865: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3866: $cdom = $env{'course.'.$course.'.domain'};
3867: $cnum = $env{'course.'.$course.'.num'};
3868: } else {
1.490 raeburn 3869: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3870: }
3871: my $no_ownblock = 0;
3872: my $no_userblock = 0;
1.533 raeburn 3873: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3874: # Check if current user has 'evb' priv for this
3875: if (defined($own_courses{$course})) {
3876: foreach my $sec (keys(%{$own_courses{$course}})) {
3877: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3878: if ($sec ne 'none') {
3879: $checkrole .= '/'.$sec;
3880: }
3881: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3882: $no_ownblock = 1;
3883: last;
3884: }
3885: }
3886: }
3887: # if they have 'evb' priv and are currently not playing student
3888: next if (($no_ownblock) &&
3889: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3890: }
1.474 raeburn 3891: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3892: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3893: if ($sec ne 'none') {
1.482 raeburn 3894: $checkrole .= '/'.$sec;
1.474 raeburn 3895: }
1.490 raeburn 3896: if ($otheruser) {
3897: # Resource belongs to user other than current user.
3898: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3899: my ($trole,$tdom,$tnum,$tsec);
3900: my $entry = $live_courses{$course}{$sec};
3901: if ($entry =~ /^cr/) {
3902: ($trole,$tdom,$tnum,$tsec) =
3903: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3904: } else {
3905: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3906: }
3907: my ($spec,$area,$trest,%allroles,%userroles);
3908: $area = '/'.$tdom.'/'.$tnum;
3909: $trest = $tnum;
3910: if ($tsec ne '') {
3911: $area .= '/'.$tsec;
3912: $trest .= '/'.$tsec;
3913: }
3914: $spec = $trole.'.'.$area;
3915: if ($trole =~ /^cr/) {
3916: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3917: $tdom,$spec,$trest,$area);
3918: } else {
3919: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3920: $tdom,$spec,$trest,$area);
3921: }
3922: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3923: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3924: if ($1) {
3925: $no_userblock = 1;
3926: last;
3927: }
3928: }
1.490 raeburn 3929: } else {
3930: # Resource belongs to current user
3931: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3932: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3933: $no_ownblock = 1;
3934: last;
3935: }
1.474 raeburn 3936: }
3937: }
3938: # if they have the evb priv and are currently not playing student
1.482 raeburn 3939: next if (($no_ownblock) &&
1.491 albertel 3940: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3941: next if ($no_userblock);
1.474 raeburn 3942:
1.866 kalberla 3943: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3944: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3945:
3946: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3947: if (($start != 0) &&
3948: (($startblock == 0) || ($startblock > $start))) {
3949: $startblock = $start;
3950: }
3951: if (($end != 0) &&
3952: (($endblock == 0) || ($endblock < $end))) {
3953: $endblock = $end;
3954: }
1.490 raeburn 3955: }
3956: return ($startblock,$endblock);
3957: }
3958:
3959: sub get_blocks {
3960: my ($setters,$activity,$cdom,$cnum) = @_;
3961: my $startblock = 0;
3962: my $endblock = 0;
3963: my $course = $cdom.'_'.$cnum;
3964: $setters->{$course} = {};
3965: $setters->{$course}{'staff'} = [];
3966: $setters->{$course}{'times'} = [];
3967: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3968: foreach my $record (keys(%records)) {
3969: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3970: if ($start <= time && $end >= time) {
3971: my ($staff_name,$staff_dom,$title,$blocks) =
3972: &parse_block_record($records{$record});
3973: if ($blocks->{$activity} eq 'on') {
3974: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3975: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3976: if ( ($startblock == 0) || ($startblock > $start) ) {
3977: $startblock = $start;
1.490 raeburn 3978: }
1.491 albertel 3979: if ( ($endblock == 0) || ($endblock < $end) ) {
3980: $endblock = $end;
1.474 raeburn 3981: }
3982: }
3983: }
3984: }
3985: return ($startblock,$endblock);
3986: }
3987:
3988: sub parse_block_record {
3989: my ($record) = @_;
3990: my ($setuname,$setudom,$title,$blocks);
3991: if (ref($record) eq 'HASH') {
3992: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3993: $title = &unescape($record->{'event'});
3994: $blocks = $record->{'blocks'};
3995: } else {
3996: my @data = split(/:/,$record,3);
3997: if (scalar(@data) eq 2) {
3998: $title = $data[1];
3999: ($setuname,$setudom) = split(/@/,$data[0]);
4000: } else {
4001: ($setuname,$setudom,$title) = @data;
4002: }
4003: $blocks = { 'com' => 'on' };
4004: }
4005: return ($setuname,$setudom,$title,$blocks);
4006: }
4007:
1.854 kalberla 4008: sub blocking_status {
4009: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4010: my %setters;
1.890 droeschl 4011:
4012: # check for active blocking
1.867 kalberla 4013: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4014:
1.890 droeschl 4015: my $blocked = $startblock && $endblock ? 1 : 0;
4016:
4017: # caller just wants to know whether a block is active
4018: if (!wantarray) { return $blocked; }
4019:
4020: # build a link to a popup window containing the details
4021: my $querystring = "?activity=$activity";
4022: # $uname and $udom decide whose portfolio the user is trying to look at
4023: $querystring .= "&udom=$udom" if $udom;
4024: $querystring .= "&uname=$uname" if $uname;
4025:
4026: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4027: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4028: var options = "width=" + w + ",height=" + h + ",";
4029: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4030: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4031: var newWin = window.open(url, wdwName, options);
4032: newWin.focus();
4033: }
1.890 droeschl 4034: END_MYBLOCK
1.854 kalberla 4035:
1.890 droeschl 4036: $output = Apache::lonhtmlcommon::scripttag($output);
4037:
1.854 kalberla 4038: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4039: my $text = mt('Communication Blocked');
4040:
1.867 kalberla 4041: $output .= <<"END_BLOCK";
4042: <div class='LC_comblock'>
1.869 kalberla 4043: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4044: title='$text'>
4045: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4046: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4047: title='$text'>$text</a>
1.867 kalberla 4048: </div>
4049:
4050: END_BLOCK
1.474 raeburn 4051:
1.854 kalberla 4052: return ($blocked, $output);
4053: }
1.490 raeburn 4054:
1.60 matthew 4055: ###############################################
4056:
1.682 raeburn 4057: sub check_ip_acc {
4058: my ($acc)=@_;
4059: &Apache::lonxml::debug("acc is $acc");
4060: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4061: return 1;
4062: }
4063: my $allowed=0;
4064: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4065:
4066: my $name;
4067: foreach my $pattern (split(',',$acc)) {
4068: $pattern =~ s/^\s*//;
4069: $pattern =~ s/\s*$//;
4070: if ($pattern =~ /\*$/) {
4071: #35.8.*
4072: $pattern=~s/\*//;
4073: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4074: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4075: #35.8.3.[34-56]
4076: my $low=$2;
4077: my $high=$3;
4078: $pattern=$1;
4079: if ($ip =~ /^\Q$pattern\E/) {
4080: my $last=(split(/\./,$ip))[3];
4081: if ($last <=$high && $last >=$low) { $allowed=1; }
4082: }
4083: } elsif ($pattern =~ /^\*/) {
4084: #*.msu.edu
4085: $pattern=~s/\*//;
4086: if (!defined($name)) {
4087: use Socket;
4088: my $netaddr=inet_aton($ip);
4089: ($name)=gethostbyaddr($netaddr,AF_INET);
4090: }
4091: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4092: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4093: #127.0.0.1
4094: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4095: } else {
4096: #some.name.com
4097: if (!defined($name)) {
4098: use Socket;
4099: my $netaddr=inet_aton($ip);
4100: ($name)=gethostbyaddr($netaddr,AF_INET);
4101: }
4102: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4103: }
4104: if ($allowed) { last; }
4105: }
4106: return $allowed;
4107: }
4108:
4109: ###############################################
4110:
1.60 matthew 4111: =pod
4112:
1.112 bowersj2 4113: =head1 Domain Template Functions
4114:
4115: =over 4
4116:
4117: =item * &determinedomain()
1.60 matthew 4118:
4119: Inputs: $domain (usually will be undef)
4120:
1.63 www 4121: Returns: Determines which domain should be used for designs
1.60 matthew 4122:
4123: =cut
1.54 www 4124:
1.60 matthew 4125: ###############################################
1.63 www 4126: sub determinedomain {
4127: my $domain=shift;
1.531 albertel 4128: if (! $domain) {
1.60 matthew 4129: # Determine domain if we have not been given one
1.893 raeburn 4130: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4131: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4132: if ($env{'request.role.domain'}) {
4133: $domain=$env{'request.role.domain'};
1.60 matthew 4134: }
4135: }
1.63 www 4136: return $domain;
4137: }
4138: ###############################################
1.517 raeburn 4139:
1.518 albertel 4140: sub devalidate_domconfig_cache {
4141: my ($udom)=@_;
4142: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4143: }
4144:
4145: # ---------------------- Get domain configuration for a domain
4146: sub get_domainconf {
4147: my ($udom) = @_;
4148: my $cachetime=1800;
4149: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4150: if (defined($cached)) { return %{$result}; }
4151:
4152: my %domconfig = &Apache::lonnet::get_dom('configuration',
4153: ['login','rolecolors'],$udom);
1.632 raeburn 4154: my (%designhash,%legacy);
1.518 albertel 4155: if (keys(%domconfig) > 0) {
4156: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4157: if (keys(%{$domconfig{'login'}})) {
4158: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4159: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4160: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4161: $designhash{$udom.'.login.'.$key.'_'.$img} =
4162: $domconfig{'login'}{$key}{$img};
4163: }
4164: } else {
4165: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4166: }
1.632 raeburn 4167: }
4168: } else {
4169: $legacy{'login'} = 1;
1.518 albertel 4170: }
1.632 raeburn 4171: } else {
4172: $legacy{'login'} = 1;
1.518 albertel 4173: }
4174: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4175: if (keys(%{$domconfig{'rolecolors'}})) {
4176: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4177: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4178: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4179: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4180: }
1.518 albertel 4181: }
4182: }
1.632 raeburn 4183: } else {
4184: $legacy{'rolecolors'} = 1;
1.518 albertel 4185: }
1.632 raeburn 4186: } else {
4187: $legacy{'rolecolors'} = 1;
1.518 albertel 4188: }
1.632 raeburn 4189: if (keys(%legacy) > 0) {
4190: my %legacyhash = &get_legacy_domconf($udom);
4191: foreach my $item (keys(%legacyhash)) {
4192: if ($item =~ /^\Q$udom\E\.login/) {
4193: if ($legacy{'login'}) {
4194: $designhash{$item} = $legacyhash{$item};
4195: }
4196: } else {
4197: if ($legacy{'rolecolors'}) {
4198: $designhash{$item} = $legacyhash{$item};
4199: }
1.518 albertel 4200: }
4201: }
4202: }
1.632 raeburn 4203: } else {
4204: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4205: }
4206: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4207: $cachetime);
4208: return %designhash;
4209: }
4210:
1.632 raeburn 4211: sub get_legacy_domconf {
4212: my ($udom) = @_;
4213: my %legacyhash;
4214: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4215: my $designfile = $designdir.'/'.$udom.'.tab';
4216: if (-e $designfile) {
4217: if ( open (my $fh,"<$designfile") ) {
4218: while (my $line = <$fh>) {
4219: next if ($line =~ /^\#/);
4220: chomp($line);
4221: my ($key,$val)=(split(/\=/,$line));
4222: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4223: }
4224: close($fh);
4225: }
4226: }
4227: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4228: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4229: }
4230: return %legacyhash;
4231: }
4232:
1.63 www 4233: =pod
4234:
1.112 bowersj2 4235: =item * &domainlogo()
1.63 www 4236:
4237: Inputs: $domain (usually will be undef)
4238:
4239: Returns: A link to a domain logo, if the domain logo exists.
4240: If the domain logo does not exist, a description of the domain.
4241:
4242: =cut
1.112 bowersj2 4243:
1.63 www 4244: ###############################################
4245: sub domainlogo {
1.517 raeburn 4246: my $domain = &determinedomain(shift);
1.518 albertel 4247: my %designhash = &get_domainconf($domain);
1.517 raeburn 4248: # See if there is a logo
4249: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4250: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4251: if ($imgsrc =~ m{^/(adm|res)/}) {
4252: if ($imgsrc =~ m{^/res/}) {
4253: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4254: &Apache::lonnet::repcopy($local_name);
4255: }
4256: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4257: }
4258: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4259: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4260: return &Apache::lonnet::domain($domain,'description');
1.59 www 4261: } else {
1.60 matthew 4262: return '';
1.59 www 4263: }
4264: }
1.63 www 4265: ##############################################
4266:
4267: =pod
4268:
1.112 bowersj2 4269: =item * &designparm()
1.63 www 4270:
4271: Inputs: $which parameter; $domain (usually will be undef)
4272:
4273: Returns: value of designparamter $which
4274:
4275: =cut
1.112 bowersj2 4276:
1.397 albertel 4277:
1.400 albertel 4278: ##############################################
1.397 albertel 4279: sub designparm {
4280: my ($which,$domain)=@_;
4281: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4282: return $env{'environment.color.'.$which};
1.96 www 4283: }
1.63 www 4284: $domain=&determinedomain($domain);
1.518 albertel 4285: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4286: my $output;
1.517 raeburn 4287: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4288: $output = $domdesign{$domain.'.'.$which};
1.63 www 4289: } else {
1.520 raeburn 4290: $output = $defaultdesign{$which};
4291: }
4292: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4293: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4294: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4295: if ($output =~ m{^/res/}) {
4296: my $local_name = &Apache::lonnet::filelocation('',$output);
4297: &Apache::lonnet::repcopy($local_name);
4298: }
1.520 raeburn 4299: $output = &lonhttpdurl($output);
4300: }
1.63 www 4301: }
1.520 raeburn 4302: return $output;
1.63 www 4303: }
1.59 www 4304:
1.822 bisitz 4305: ##############################################
4306: =pod
4307:
1.832 bisitz 4308: =item * &authorspace()
4309:
4310: Inputs: ./.
4311:
4312: Returns: Path to the Construction Space of the current user's
4313: accessed author space
4314: The author space will be that of the current user
4315: when accessing the own author space
4316: and that of the co-author/assistent co-author
4317: when accessing the co-author's/assistent co-author's
4318: space
4319:
4320: =cut
4321:
4322: sub authorspace {
4323: my $caname = '';
4324: if ($env{'request.role'} =~ /^ca|^aa/) {
4325: (undef,$caname) =
4326: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4327: } else {
4328: $caname = $env{'user.name'};
4329: }
4330: return '/priv/'.$caname.'/';
4331: }
4332:
4333: ##############################################
4334: =pod
4335:
1.822 bisitz 4336: =item * &head_subbox()
4337:
4338: Inputs: $content (contains HTML code with page functions, etc.)
4339:
4340: Returns: HTML div with $content
4341: To be included in page header
4342:
4343: =cut
4344:
4345: sub head_subbox {
4346: my ($content)=@_;
4347: my $output =
1.844 bisitz 4348: '<div id="LC_head_subbox">'
1.822 bisitz 4349: .$content
4350: .'</div>'
4351: }
4352:
4353: ##############################################
4354: =pod
4355:
4356: =item * &CSTR_pageheader()
4357:
4358: Inputs: ./.
4359:
4360: Returns: HTML div with CSTR path and recent box
4361: To be included on Construction Space pages
4362:
4363: =cut
4364:
4365: sub CSTR_pageheader {
4366: # this is for resources; directories have customtitle, and crumbs
4367: # and select recent are created in lonpubdir.pm
4368: my ($uname,$thisdisfn)=
4369: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4370: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4371: $formaction=~s/\/+/\//g;
4372:
4373: my $parentpath = '';
4374: my $lastitem = '';
4375: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4376: $parentpath = $1;
4377: $lastitem = $2;
4378: } else {
4379: $lastitem = $thisdisfn;
4380: }
1.921 bisitz 4381:
4382: my $output =
1.822 bisitz 4383: '<div>'
4384: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4385: .'<b>'.&mt('Construction Space:').'</b> '
4386: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4387: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4388: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4389:
4390: if ($lastitem) {
4391: $output .=
4392: '<span class="LC_filename">'
4393: .$lastitem
4394: .'</span>';
4395: }
4396: $output .=
4397: '<br />'
1.822 bisitz 4398: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4399: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4400: .'</form>'
4401: .&Apache::lonmenu::constspaceform()
4402: .'</div>';
1.921 bisitz 4403:
4404: return $output;
1.822 bisitz 4405: }
4406:
1.60 matthew 4407: ###############################################
4408: ###############################################
4409:
4410: =pod
4411:
1.112 bowersj2 4412: =back
4413:
1.549 albertel 4414: =head1 HTML Helpers
1.112 bowersj2 4415:
4416: =over 4
4417:
4418: =item * &bodytag()
1.60 matthew 4419:
4420: Returns a uniform header for LON-CAPA web pages.
4421:
4422: Inputs:
4423:
1.112 bowersj2 4424: =over 4
4425:
4426: =item * $title, A title to be displayed on the page.
4427:
4428: =item * $function, the current role (can be undef).
4429:
4430: =item * $addentries, extra parameters for the <body> tag.
4431:
4432: =item * $bodyonly, if defined, only return the <body> tag.
4433:
4434: =item * $domain, if defined, force a given domain.
4435:
4436: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4437: text interface only)
1.60 matthew 4438:
1.814 bisitz 4439: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4440: navigational links
1.317 albertel 4441:
1.338 albertel 4442: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4443:
1.361 albertel 4444: =item * $no_inline_link, if true and in remote mode, don't show the
4445: 'Switch To Inline Menu' link
4446:
1.460 albertel 4447: =item * $args, optional argument valid values are
4448: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4449: inherit_jsmath -> when creating popup window in a page,
4450: should it have jsmath forced on by the
4451: current page
1.460 albertel 4452:
1.112 bowersj2 4453: =back
4454:
1.60 matthew 4455: Returns: A uniform header for LON-CAPA web pages.
4456: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4457: If $bodyonly is undef or zero, an html string containing a <body> tag and
4458: other decorations will be returned.
4459:
4460: =cut
4461:
1.54 www 4462: sub bodytag {
1.831 bisitz 4463: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4464: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4465:
1.460 albertel 4466: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4467:
1.183 matthew 4468: $function = &get_users_function() if (!$function);
1.339 albertel 4469: my $img = &designparm($function.'.img',$domain);
4470: my $font = &designparm($function.'.font',$domain);
4471: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4472:
1.803 bisitz 4473: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4474: 'bgcolor' => $pgbg,
1.339 albertel 4475: 'text' => $font,
4476: 'alink' => &designparm($function.'.alink',$domain),
4477: 'vlink' => &designparm($function.'.vlink',$domain),
4478: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4479: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4480:
1.925.2.4 raeburn 4481: my $custommenu;
4482: if ($env{'environment.remote'} eq 'off') {
4483: $custommenu = &needs_gci_custom();
4484: }
1.63 www 4485: # role and realm
1.378 raeburn 4486: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4487: if ($role eq 'ca') {
1.479 albertel 4488: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4489: $realm = &plainname($rname,$rdom);
1.378 raeburn 4490: }
1.55 www 4491: # realm
1.258 albertel 4492: if ($env{'request.course.id'}) {
1.378 raeburn 4493: if ($env{'request.role'} !~ /^cr/) {
1.925.2.4 raeburn 4494: if (($custommenu) && ($role eq 'cm')) {
4495: undef($role);
4496: } else {
4497: $role = &Apache::lonnet::plaintext($role,&course_type());
4498: }
1.378 raeburn 4499: }
1.898 raeburn 4500: if ($env{'request.course.sec'}) {
4501: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4502: }
1.359 albertel 4503: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4504: } else {
1.925.2.4 raeburn 4505: if (($custommenu) && ($role eq 'cm')) {
4506: undef($role);
4507: } else {
4508: $role = &Apache::lonnet::plaintext($role);
4509: }
1.54 www 4510: }
1.433 albertel 4511:
1.359 albertel 4512: if (!$realm) { $realm=' '; }
1.55 www 4513: # Set messages
1.60 matthew 4514: my $messages=&domainlogo($domain);
1.330 albertel 4515:
1.438 albertel 4516: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4517:
1.101 www 4518: # construct main body tag
1.359 albertel 4519: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4520: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4521:
1.530 albertel 4522: if ($bodyonly) {
1.60 matthew 4523: return $bodytag;
1.798 tempelho 4524: }
1.359 albertel 4525:
1.410 albertel 4526: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4527: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4528: undef($role);
1.434 albertel 4529: } else {
4530: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4531: }
1.359 albertel 4532:
1.762 bisitz 4533: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4534: #
4535: # Extra info if you are the DC
4536: my $dc_info = '';
4537: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4538: $env{'course.'.$env{'request.course.id'}.
4539: '.domain'}.'/'})) {
4540: my $cid = $env{'request.course.id'};
1.917 raeburn 4541: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4542: $dc_info =~ s/\s+$//;
1.359 albertel 4543: }
4544:
1.898 raeburn 4545: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4546: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4547:
1.837 bisitz 4548: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4549: # No Remote
1.916 droeschl 4550: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4551: return $bodytag;
4552: }
1.903 droeschl 4553:
4554: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4555:
4556: # if ($env{'request.state'} eq 'construct') {
4557: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4558: # }
4559:
1.925.2.4 raeburn 4560: my $role_selector;
4561: if (($custommenu) && ($env{'request.course.id'}) &&
1.925.2.5 raeburn 4562: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gcitest') &&
4563: ($env{'request.role'} !~ m{^st\./gcitest/$match_courseid})) {
1.925.2.4 raeburn 4564: $role_selector = &Apache::lonmenu::roles_selector(
4565: $env{'course.' . $env{'request.course.id'} . '.domain'},
4566: $env{'course.' . $env{'request.course.id'} . '.num'} );
4567: if ($role_selector) {
4568: $role_selector = '<br />'.$role_selector;
4569: }
4570: }
1.359 albertel 4571:
1.916 droeschl 4572: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4573: if ($dc_info) {
4574: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4575: }
1.916 droeschl 4576: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4577: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4578: return $bodytag;
4579: }
1.894 droeschl 4580:
1.925.2.4 raeburn 4581: $bodytag .= qq|<div id="LC_nav_bar">$name $role $role_selector</div>|;
1.916 droeschl 4582:
1.903 droeschl 4583: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.925.2.2 raeburn 4584: Apache::lonmenu::utilityfunctions('',$custommenu), 'start');
1.816 bisitz 4585:
1.903 droeschl 4586: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4587:
1.917 raeburn 4588: if ($dc_info) {
4589: $dc_info = &dc_courseid_toggle($dc_info);
4590: }
4591: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4592:
1.903 droeschl 4593: #don't show menus for public users
4594: if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
1.925.2.5 raeburn 4595: if (($custommenu) &&
4596: ($env{'request.role'} !~ m{^st\./gcitest/$match_courseid})) {
1.925.2.2 raeburn 4597: $bodytag .= &Apache::lonmenu::gci_secondary_menu();
4598: } else {
4599: $bodytag .= Apache::lonmenu::secondary_menu();
4600: }
1.903 droeschl 4601: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4602: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4603: if ($env{'request.state'} eq 'construct') {
4604: $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
4605: $args->{'bread_crumbs'});
4606: } elsif ($forcereg) {
4607: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4608: }
1.903 droeschl 4609: }else{
4610: # this is to seperate menu from content when there's no secondary
4611: # menu. Especially needed for public accessible ressources.
4612: $bodytag .= '<hr style="clear:both" />';
4613: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4614: }
1.903 droeschl 4615:
4616: #SD testing
4617: #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
1.235 raeburn 4618: return $bodytag;
1.94 www 4619: }
1.95 www 4620:
1.93 www 4621: #
1.95 www 4622: # Top frame rendering, Remote is up
1.93 www 4623: #
1.359 albertel 4624:
1.517 raeburn 4625: my $imgsrc = $img;
4626: if ($img =~ /^\/adm/) {
1.575 albertel 4627: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4628: }
4629: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4630:
1.305 www 4631: # Explicit link to get inline menu
1.361 albertel 4632: my $menu= ($no_inline_link?''
1.883 droeschl 4633: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.917 raeburn 4634:
4635: if ($dc_info) {
4636: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
4637: }
4638:
1.916 droeschl 4639: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.897 wenzelju 4640: <ol class="LC_primary_menu LC_right">
1.853 droeschl 4641: <li>$menu</li>
1.917 raeburn 4642: </ol><div id="LC_realm"> $realm $dc_info</div>| unless $env{'form.inhibitmenu'};
1.94 www 4643: return(<<ENDBODY);
1.60 matthew 4644: $bodytag
1.359 albertel 4645: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4646: <tr><td>$upperleft</td>
4647: <td>$messages </td>
1.54 www 4648: </tr>
1.359 albertel 4649: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4650: </tr>
1.356 albertel 4651: </table>
1.54 www 4652: ENDBODY
1.182 matthew 4653: }
4654:
1.917 raeburn 4655: sub dc_courseid_toggle {
4656: my ($dc_info) = @_;
4657: return ' <span id="dccidtext" class="LC_cusr_subheading">'.
4658: '<a href="javascript:showCourseID();">'.
4659: &mt('(More ...)').'</a></span>'.
4660: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4661: }
4662:
1.330 albertel 4663: sub make_attr_string {
4664: my ($register,$attr_ref) = @_;
4665:
4666: if ($attr_ref && !ref($attr_ref)) {
4667: die("addentries Must be a hash ref ".
4668: join(':',caller(1))." ".
4669: join(':',caller(0))." ");
4670: }
4671:
4672: if ($register) {
1.339 albertel 4673: my ($on_load,$on_unload);
4674: foreach my $key (keys(%{$attr_ref})) {
4675: if (lc($key) eq 'onload') {
4676: $on_load.=$attr_ref->{$key}.';';
4677: delete($attr_ref->{$key});
4678:
4679: } elsif (lc($key) eq 'onunload') {
4680: $on_unload.=$attr_ref->{$key}.';';
4681: delete($attr_ref->{$key});
4682: }
4683: }
4684: $attr_ref->{'onload'} =
4685: &Apache::lonmenu::loadevents(). $on_load;
4686: $attr_ref->{'onunload'}=
4687: &Apache::lonmenu::unloadevents().$on_unload;
4688: }
4689:
4690: # Accessibility font enhance
4691: if ($env{'browser.fontenhance'} eq 'on') {
4692: my $style;
4693: foreach my $key (keys(%{$attr_ref})) {
4694: if (lc($key) eq 'style') {
4695: $style.=$attr_ref->{$key}.';';
4696: delete($attr_ref->{$key});
4697: }
4698: }
4699: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4700: }
1.339 albertel 4701:
1.330 albertel 4702: my $attr_string;
4703: foreach my $attr (keys(%$attr_ref)) {
4704: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4705: }
4706: return $attr_string;
4707: }
4708:
4709:
1.182 matthew 4710: ###############################################
1.251 albertel 4711: ###############################################
4712:
4713: =pod
4714:
4715: =item * &endbodytag()
4716:
4717: Returns a uniform footer for LON-CAPA web pages.
4718:
1.635 raeburn 4719: Inputs: 1 - optional reference to an args hash
4720: If in the hash, key for noredirectlink has a value which evaluates to true,
4721: a 'Continue' link is not displayed if the page contains an
4722: internal redirect in the <head></head> section,
4723: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4724:
4725: =cut
4726:
4727: sub endbodytag {
1.635 raeburn 4728: my ($args) = @_;
1.251 albertel 4729: my $endbodytag='</body>';
1.269 albertel 4730: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4731: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4732: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4733: $endbodytag=
4734: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4735: &mt('Continue').'</a>'.
4736: $endbodytag;
4737: }
1.315 albertel 4738: }
1.251 albertel 4739: return $endbodytag;
4740: }
4741:
1.352 albertel 4742: =pod
4743:
4744: =item * &standard_css()
4745:
4746: Returns a style sheet
4747:
4748: Inputs: (all optional)
4749: domain -> force to color decorate a page for a specific
4750: domain
4751: function -> force usage of a specific rolish color scheme
4752: bgcolor -> override the default page bgcolor
4753:
4754: =cut
4755:
1.343 albertel 4756: sub standard_css {
1.345 albertel 4757: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4758: $function = &get_users_function() if (!$function);
4759: my $img = &designparm($function.'.img', $domain);
4760: my $tabbg = &designparm($function.'.tabbg', $domain);
4761: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4762: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4763: #second colour for later usage
1.345 albertel 4764: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4765: my $pgbg_or_bgcolor =
4766: $bgcolor ||
1.352 albertel 4767: &designparm($function.'.pgbg', $domain);
1.382 albertel 4768: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4769: my $alink = &designparm($function.'.alink', $domain);
4770: my $vlink = &designparm($function.'.vlink', $domain);
4771: my $link = &designparm($function.'.link', $domain);
4772:
1.704 muellerd 4773: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4774: my $bgcol = &designparm('login.bgcol',$domain);
4775: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4776:
1.602 albertel 4777: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4778: my $mono = 'monospace';
1.850 bisitz 4779: my $data_table_head = $sidebg;
4780: my $data_table_light = '#FAFAFA';
4781: my $data_table_dark = '#F0F0F0';
1.470 banghart 4782: my $data_table_darker = '#CCCCCC';
1.349 albertel 4783: my $data_table_highlight = '#FFFF00';
1.352 albertel 4784: my $mail_new = '#FFBB77';
4785: my $mail_new_hover = '#DD9955';
4786: my $mail_read = '#BBBB77';
4787: my $mail_read_hover = '#999944';
4788: my $mail_replied = '#AAAA88';
4789: my $mail_replied_hover = '#888855';
4790: my $mail_other = '#99BBBB';
4791: my $mail_other_hover = '#669999';
1.391 albertel 4792: my $table_header = '#DDDDDD';
1.489 raeburn 4793: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4794: my $lg_border_color = '#C8C8C8';
1.392 albertel 4795:
1.608 albertel 4796: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4797: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4798: : '0 3px 0 4px';
1.448 albertel 4799:
1.523 albertel 4800:
1.343 albertel 4801: return <<END;
1.795 www 4802: body {
1.911 bisitz 4803: font-family: $sans;
4804: line-height:130%;
4805: font-size:0.83em;
4806: color:$font;
1.795 www 4807: }
4808:
1.911 bisitz 4809: a:focus {
1.795 www 4810: color: red;
1.911 bisitz 4811: background: yellow;
1.795 www 4812: }
1.698 harmsja 4813:
1.911 bisitz 4814: form, .inline {
4815: display: inline;
1.795 www 4816: }
1.721 harmsja 4817:
1.795 www 4818: .LC_right {
1.911 bisitz 4819: text-align:right;
1.795 www 4820: }
4821:
4822: .LC_middle {
1.911 bisitz 4823: vertical-align:middle;
1.795 www 4824: }
1.721 harmsja 4825:
4826: /* just for tests */
1.911 bisitz 4827: .LC_400Box {
4828: width:400px;
4829: }
1.721 harmsja 4830: /* end */
4831:
1.778 bisitz 4832: .LC_filename {
4833: font-family: $mono;
4834: white-space:pre;
1.921 bisitz 4835: font-size: 120%;
1.778 bisitz 4836: }
4837:
4838: .LC_fileicon {
4839: border: none;
4840: height: 1.3em;
4841: vertical-align: text-bottom;
4842: margin-right: 0.3em;
4843: text-decoration:none;
4844: }
4845:
1.350 albertel 4846: .LC_error {
4847: color: red;
4848: font-size: larger;
4849: }
1.795 www 4850:
1.457 albertel 4851: .LC_warning,
4852: .LC_diff_removed {
1.733 bisitz 4853: color: red;
1.394 albertel 4854: }
1.532 albertel 4855:
4856: .LC_info,
1.457 albertel 4857: .LC_success,
4858: .LC_diff_added {
1.350 albertel 4859: color: green;
4860: }
1.795 www 4861:
1.802 bisitz 4862: div.LC_confirm_box {
4863: background-color: #FAFAFA;
4864: border: 1px solid $lg_border_color;
4865: margin-right: 0;
4866: padding: 5px;
4867: }
4868:
4869: div.LC_confirm_box .LC_error img,
4870: div.LC_confirm_box .LC_success img {
4871: vertical-align: middle;
4872: }
4873:
1.440 albertel 4874: .LC_icon {
1.771 droeschl 4875: border: none;
1.790 droeschl 4876: vertical-align: middle;
1.771 droeschl 4877: }
4878:
1.543 albertel 4879: .LC_docs_spacer {
4880: width: 25px;
4881: height: 1px;
1.771 droeschl 4882: border: none;
1.543 albertel 4883: }
1.346 albertel 4884:
1.532 albertel 4885: .LC_internal_info {
1.735 bisitz 4886: color: #999999;
1.532 albertel 4887: }
4888:
1.794 www 4889: .LC_discussion {
1.911 bisitz 4890: background: $tabbg;
4891: border: 1px solid black;
4892: margin: 2px;
1.794 www 4893: }
4894:
4895: .LC_disc_action_links_bar {
1.911 bisitz 4896: background: $tabbg;
4897: border: none;
4898: margin: 4px;
1.794 www 4899: }
4900:
4901: .LC_disc_action_left {
1.911 bisitz 4902: text-align: left;
1.794 www 4903: }
4904:
4905: .LC_disc_action_right {
1.911 bisitz 4906: text-align: right;
1.794 www 4907: }
4908:
4909: .LC_disc_new_item {
1.911 bisitz 4910: background: white;
4911: border: 2px solid red;
4912: margin: 2px;
1.794 www 4913: }
4914:
4915: .LC_disc_old_item {
1.911 bisitz 4916: background: white;
4917: border: 1px solid black;
4918: margin: 2px;
1.794 www 4919: }
4920:
1.458 albertel 4921: table.LC_pastsubmission {
4922: border: 1px solid black;
4923: margin: 2px;
4924: }
4925:
1.924 bisitz 4926: table#LC_menubuttons {
1.345 albertel 4927: width: 100%;
4928: background: $pgbg;
1.392 albertel 4929: border: 2px;
1.402 albertel 4930: border-collapse: separate;
1.803 bisitz 4931: padding: 0;
1.345 albertel 4932: }
1.392 albertel 4933:
1.801 tempelho 4934: table#LC_title_bar a {
4935: color: $fontmenu;
4936: }
1.836 bisitz 4937:
1.807 droeschl 4938: table#LC_title_bar {
1.819 tempelho 4939: clear: both;
1.836 bisitz 4940: display: none;
1.807 droeschl 4941: }
4942:
1.795 www 4943: table#LC_title_bar,
4944: table.LC_breadcrumbs,
1.393 albertel 4945: table#LC_title_bar.LC_with_remote {
1.359 albertel 4946: width: 100%;
1.392 albertel 4947: border-color: $pgbg;
4948: border-style: solid;
4949: border-width: $border;
1.379 albertel 4950: background: $pgbg;
1.801 tempelho 4951: color: $fontmenu;
1.392 albertel 4952: border-collapse: collapse;
1.803 bisitz 4953: padding: 0;
1.819 tempelho 4954: margin: 0;
1.359 albertel 4955: }
1.795 www 4956:
1.925.2.13! raeburn 4957: dl.LC_GCI_Menu {
! 4958: width:300px;
! 4959: float:left;
! 4960: margin-right:2em;
! 4961: }
! 4962:
! 4963: dl.LC_GCI_Menu dt {
! 4964: font-weight: bold;
! 4965: font-size:0.9em;
! 4966: margin-bottom:0.7em;
! 4967: }
! 4968:
! 4969: dl.LC_GCI_Menu dd {
! 4970: font-size:0.8em;
! 4971: margin:0 0 2em 0;
! 4972: padding-left:4.5em;
! 4973: line-height:1.5em;
! 4974: background:none no-repeat left top;
! 4975: }
! 4976:
1.913 droeschl 4977: /* #SD START (work in progress)*/
4978:
4979: ul.LC_bct {
4980: margin: 0;
4981: padding: 0;
4982: }
4983: ul.LC_bct ol {
4984: display: inline;
4985: }
4986: ul.LC_bct ul {
4987: display: inline;
4988: padding: 0;
4989: }
4990: ul.LC_bct li {
4991: list-style-type: none;
4992: display: inline;
4993: }
4994:
4995:
4996: ul.LC_breadcrumb_tools {
4997: }
4998:
4999: li.LC_breadcrumb_tools {
5000: }
5001: li.LC_breadcrumb_tools img{
5002: vertical-align: middle;
5003: }
5004:
5005: .LC_breadcrumb_tools_A {
5006: margin: 0 0 0 1em;
5007: }
5008: .LC_breadcrumb_tools_B {
5009: float: right;
5010: margin-top: 0.4em;
5011: }
5012: .LC_breadcrumb_tools_C {
5013: margin: 0 1em 0 0;
5014: float: right;
5015: }
5016: /* #SD END */
5017:
1.359 albertel 5018: table#LC_title_bar td {
5019: background: $tabbg;
5020: }
1.795 www 5021:
1.911 bisitz 5022: table#LC_menubuttons img {
1.803 bisitz 5023: border: none;
1.346 albertel 5024: }
1.795 www 5025:
1.842 droeschl 5026: .LC_breadcrumbs_component {
1.911 bisitz 5027: float: right;
5028: margin: 0 1em;
1.357 albertel 5029: }
1.842 droeschl 5030: .LC_breadcrumbs_component img {
1.911 bisitz 5031: vertical-align: middle;
1.777 tempelho 5032: }
1.795 www 5033:
1.383 albertel 5034: td.LC_table_cell_checkbox {
5035: text-align: center;
5036: }
1.795 www 5037:
5038: .LC_fontsize_small {
1.911 bisitz 5039: font-size: 70%;
1.705 tempelho 5040: }
5041:
1.844 bisitz 5042: #LC_breadcrumbs {
1.911 bisitz 5043: clear:both;
5044: background: $sidebg;
5045: border-bottom: 1px solid $lg_border_color;
5046: line-height: 2.5em;
1.915 droeschl 5047: /* SD working here
5048: height: 2.5em;
5049: overflow: hidden; */
1.911 bisitz 5050: margin: 0;
5051: padding: 0;
1.819 tempelho 5052: }
1.862 bisitz 5053:
1.839 droeschl 5054: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 5055: #LC_remote #LC_breadcrumbs {
1.911 bisitz 5056: display:none;
1.839 droeschl 5057: }
1.819 tempelho 5058:
1.844 bisitz 5059: #LC_head_subbox {
1.911 bisitz 5060: clear:both;
5061: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5062: border: 1px solid $sidebg;
5063: margin: 0 0 10px 0;
1.822 bisitz 5064: }
5065:
1.795 www 5066: .LC_fontsize_medium {
1.911 bisitz 5067: font-size: 85%;
1.705 tempelho 5068: }
5069:
1.795 www 5070: .LC_fontsize_large {
1.911 bisitz 5071: font-size: 120%;
1.705 tempelho 5072: }
5073:
1.346 albertel 5074: .LC_menubuttons_inline_text {
5075: color: $font;
1.698 harmsja 5076: font-size: 90%;
1.701 harmsja 5077: padding-left:3px;
1.346 albertel 5078: }
5079:
1.526 www 5080: .LC_menubuttons_link {
5081: text-decoration: none;
5082: }
1.795 www 5083:
1.522 albertel 5084: .LC_menubuttons_category {
1.521 www 5085: color: $font;
1.526 www 5086: background: $pgbg;
1.521 www 5087: font-size: larger;
5088: font-weight: bold;
5089: }
5090:
1.346 albertel 5091: td.LC_menubuttons_text {
1.911 bisitz 5092: color: $font;
1.346 albertel 5093: }
1.706 harmsja 5094:
1.346 albertel 5095: .LC_current_location {
5096: background: $tabbg;
5097: }
1.795 www 5098:
5099: table.LC_data_table,
5100: table.LC_mail_list {
1.347 albertel 5101: border: 1px solid #000000;
1.402 albertel 5102: border-collapse: separate;
1.426 albertel 5103: border-spacing: 1px;
1.610 albertel 5104: background: $pgbg;
1.347 albertel 5105: }
1.795 www 5106:
1.422 albertel 5107: .LC_data_table_dense {
5108: font-size: small;
5109: }
1.795 www 5110:
1.507 raeburn 5111: table.LC_nested_outer {
5112: border: 1px solid #000000;
1.589 raeburn 5113: border-collapse: collapse;
1.803 bisitz 5114: border-spacing: 0;
1.507 raeburn 5115: width: 100%;
5116: }
1.795 www 5117:
1.879 raeburn 5118: table.LC_innerpickbox,
1.507 raeburn 5119: table.LC_nested {
1.803 bisitz 5120: border: none;
1.589 raeburn 5121: border-collapse: collapse;
1.803 bisitz 5122: border-spacing: 0;
1.507 raeburn 5123: width: 100%;
5124: }
1.795 www 5125:
1.911 bisitz 5126: table.LC_data_table tr th,
5127: table.LC_calendar tr th,
1.795 www 5128: table.LC_mail_list tr th,
1.879 raeburn 5129: table.LC_prior_tries tr th,
5130: table.LC_innerpickbox tr th {
1.349 albertel 5131: font-weight: bold;
5132: background-color: $data_table_head;
1.801 tempelho 5133: color:$fontmenu;
1.701 harmsja 5134: font-size:90%;
1.347 albertel 5135: }
1.795 www 5136:
1.879 raeburn 5137: table.LC_innerpickbox tr th,
5138: table.LC_innerpickbox tr td {
5139: vertical-align: top;
5140: }
5141:
1.711 raeburn 5142: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5143: background-color: #CCCCCC;
1.711 raeburn 5144: font-weight: bold;
5145: text-align: left;
5146: }
1.795 www 5147:
1.912 bisitz 5148: table.LC_data_table tr.LC_odd_row > td {
5149: background-color: $data_table_light;
5150: padding: 2px;
5151: vertical-align: top;
5152: }
5153:
1.809 bisitz 5154: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5155: background-color: $data_table_light;
1.912 bisitz 5156: vertical-align: top;
5157: }
5158:
5159: table.LC_data_table tr.LC_even_row > td {
5160: background-color: $data_table_dark;
1.425 albertel 5161: padding: 2px;
1.900 bisitz 5162: vertical-align: top;
1.347 albertel 5163: }
1.795 www 5164:
1.809 bisitz 5165: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5166: background-color: $data_table_dark;
1.900 bisitz 5167: vertical-align: top;
1.347 albertel 5168: }
1.795 www 5169:
1.425 albertel 5170: table.LC_data_table tr.LC_data_table_highlight td {
5171: background-color: $data_table_darker;
5172: }
1.795 www 5173:
1.639 raeburn 5174: table.LC_data_table tr td.LC_leftcol_header {
5175: background-color: $data_table_head;
5176: font-weight: bold;
5177: }
1.795 www 5178:
1.451 albertel 5179: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5180: table.LC_nested tr.LC_empty_row td {
1.347 albertel 5181: background-color: #FFFFFF;
1.421 albertel 5182: font-weight: bold;
5183: font-style: italic;
5184: text-align: center;
5185: padding: 8px;
1.347 albertel 5186: }
1.795 www 5187:
1.890 droeschl 5188: table.LC_caption {
5189: }
5190:
1.507 raeburn 5191: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5192: padding: 4ex
5193: }
1.795 www 5194:
1.507 raeburn 5195: table.LC_nested_outer tr th {
5196: font-weight: bold;
1.801 tempelho 5197: color:$fontmenu;
1.507 raeburn 5198: background-color: $data_table_head;
1.701 harmsja 5199: font-size: small;
1.507 raeburn 5200: border-bottom: 1px solid #000000;
5201: }
1.795 www 5202:
1.507 raeburn 5203: table.LC_nested_outer tr td.LC_subheader {
5204: background-color: $data_table_head;
5205: font-weight: bold;
5206: font-size: small;
5207: border-bottom: 1px solid #000000;
5208: text-align: right;
1.451 albertel 5209: }
1.795 www 5210:
1.507 raeburn 5211: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5212: background-color: #CCCCCC;
1.451 albertel 5213: font-weight: bold;
5214: font-size: small;
1.507 raeburn 5215: text-align: center;
5216: }
1.795 www 5217:
1.589 raeburn 5218: table.LC_nested tr.LC_info_row td.LC_left_item,
5219: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5220: text-align: left;
1.451 albertel 5221: }
1.795 www 5222:
1.507 raeburn 5223: table.LC_nested td {
1.735 bisitz 5224: background-color: #FFFFFF;
1.451 albertel 5225: font-size: small;
1.507 raeburn 5226: }
1.795 www 5227:
1.507 raeburn 5228: table.LC_nested_outer tr th.LC_right_item,
5229: table.LC_nested tr.LC_info_row td.LC_right_item,
5230: table.LC_nested tr.LC_odd_row td.LC_right_item,
5231: table.LC_nested tr td.LC_right_item {
1.451 albertel 5232: text-align: right;
5233: }
5234:
1.507 raeburn 5235: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5236: background-color: #EEEEEE;
1.451 albertel 5237: }
5238:
1.473 raeburn 5239: table.LC_createuser {
5240: }
5241:
5242: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5243: font-size: small;
1.473 raeburn 5244: }
5245:
5246: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5247: background-color: #CCCCCC;
1.473 raeburn 5248: font-weight: bold;
5249: text-align: center;
5250: }
5251:
1.349 albertel 5252: table.LC_calendar {
5253: border: 1px solid #000000;
5254: border-collapse: collapse;
1.917 raeburn 5255: width: 98%;
1.349 albertel 5256: }
1.795 www 5257:
1.349 albertel 5258: table.LC_calendar_pickdate {
5259: font-size: xx-small;
5260: }
1.795 www 5261:
1.349 albertel 5262: table.LC_calendar tr td {
5263: border: 1px solid #000000;
5264: vertical-align: top;
1.917 raeburn 5265: width: 14%;
1.349 albertel 5266: }
1.795 www 5267:
1.349 albertel 5268: table.LC_calendar tr td.LC_calendar_day_empty {
5269: background-color: $data_table_dark;
5270: }
1.795 www 5271:
1.779 bisitz 5272: table.LC_calendar tr td.LC_calendar_day_current {
5273: background-color: $data_table_highlight;
1.777 tempelho 5274: }
1.795 www 5275:
1.349 albertel 5276: table.LC_mail_list tr.LC_mail_new {
5277: background-color: $mail_new;
5278: }
1.795 www 5279:
1.349 albertel 5280: table.LC_mail_list tr.LC_mail_new:hover {
5281: background-color: $mail_new_hover;
5282: }
1.795 www 5283:
1.349 albertel 5284: table.LC_mail_list tr.LC_mail_read {
5285: background-color: $mail_read;
5286: }
1.795 www 5287:
1.349 albertel 5288: table.LC_mail_list tr.LC_mail_read:hover {
5289: background-color: $mail_read_hover;
5290: }
1.795 www 5291:
1.349 albertel 5292: table.LC_mail_list tr.LC_mail_replied {
5293: background-color: $mail_replied;
5294: }
1.795 www 5295:
1.349 albertel 5296: table.LC_mail_list tr.LC_mail_replied:hover {
5297: background-color: $mail_replied_hover;
5298: }
1.795 www 5299:
1.349 albertel 5300: table.LC_mail_list tr.LC_mail_other {
5301: background-color: $mail_other;
5302: }
1.795 www 5303:
1.349 albertel 5304: table.LC_mail_list tr.LC_mail_other:hover {
5305: background-color: $mail_other_hover;
5306: }
1.494 raeburn 5307:
1.777 tempelho 5308: table.LC_data_table tr > td.LC_browser_file,
5309: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5310: background: #AAEE77;
1.389 albertel 5311: }
1.795 www 5312:
1.777 tempelho 5313: table.LC_data_table tr > td.LC_browser_file_locked,
5314: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5315: background: #FFAA99;
1.387 albertel 5316: }
1.795 www 5317:
1.777 tempelho 5318: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5319: background: #888888;
1.779 bisitz 5320: }
1.795 www 5321:
1.777 tempelho 5322: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5323: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5324: background: #F8F866;
1.777 tempelho 5325: }
1.795 www 5326:
1.696 bisitz 5327: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5328: background: #E0E8FF;
1.387 albertel 5329: }
1.696 bisitz 5330:
1.707 bisitz 5331: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5332: /* background: #77FF77; */
1.707 bisitz 5333: }
1.795 www 5334:
1.707 bisitz 5335: table.LC_data_table tr > td.LC_roles_future {
5336: background: #FFFF77;
5337: }
1.795 www 5338:
1.707 bisitz 5339: table.LC_data_table tr > td.LC_roles_will {
5340: background: #FFAA77;
5341: }
1.795 www 5342:
1.707 bisitz 5343: table.LC_data_table tr > td.LC_roles_expired {
5344: background: #FF7777;
5345: }
1.795 www 5346:
1.707 bisitz 5347: table.LC_data_table tr > td.LC_roles_will_not {
5348: background: #AAFF77;
5349: }
1.795 www 5350:
1.707 bisitz 5351: table.LC_data_table tr > td.LC_roles_selected {
5352: background: #11CC55;
5353: }
5354:
1.388 albertel 5355: span.LC_current_location {
1.701 harmsja 5356: font-size:larger;
1.388 albertel 5357: background: $pgbg;
5358: }
1.387 albertel 5359:
1.395 albertel 5360: span.LC_parm_menu_item {
5361: font-size: larger;
5362: }
1.795 www 5363:
1.395 albertel 5364: span.LC_parm_scope_all {
5365: color: red;
5366: }
1.795 www 5367:
1.395 albertel 5368: span.LC_parm_scope_folder {
5369: color: green;
5370: }
1.795 www 5371:
1.395 albertel 5372: span.LC_parm_scope_resource {
5373: color: orange;
5374: }
1.795 www 5375:
1.395 albertel 5376: span.LC_parm_part {
5377: color: blue;
5378: }
1.795 www 5379:
1.911 bisitz 5380: span.LC_parm_folder,
5381: span.LC_parm_symb {
1.395 albertel 5382: font-size: x-small;
5383: font-family: $mono;
5384: color: #AAAAAA;
5385: }
5386:
1.795 www 5387: td.LC_parm_overview_level_menu,
5388: td.LC_parm_overview_map_menu,
5389: td.LC_parm_overview_parm_selectors,
5390: td.LC_parm_overview_restrictions {
1.396 albertel 5391: border: 1px solid black;
5392: border-collapse: collapse;
5393: }
1.795 www 5394:
1.396 albertel 5395: table.LC_parm_overview_restrictions td {
5396: border-width: 1px 4px 1px 4px;
5397: border-style: solid;
5398: border-color: $pgbg;
5399: text-align: center;
5400: }
1.795 www 5401:
1.396 albertel 5402: table.LC_parm_overview_restrictions th {
5403: background: $tabbg;
5404: border-width: 1px 4px 1px 4px;
5405: border-style: solid;
5406: border-color: $pgbg;
5407: }
1.795 www 5408:
1.398 albertel 5409: table#LC_helpmenu {
1.803 bisitz 5410: border: none;
1.398 albertel 5411: height: 55px;
1.803 bisitz 5412: border-spacing: 0;
1.398 albertel 5413: }
5414:
5415: table#LC_helpmenu fieldset legend {
5416: font-size: larger;
5417: }
1.795 www 5418:
1.397 albertel 5419: table#LC_helpmenu_links {
5420: width: 100%;
5421: border: 1px solid black;
5422: background: $pgbg;
1.803 bisitz 5423: padding: 0;
1.397 albertel 5424: border-spacing: 1px;
5425: }
1.795 www 5426:
1.397 albertel 5427: table#LC_helpmenu_links tr td {
5428: padding: 1px;
5429: background: $tabbg;
1.399 albertel 5430: text-align: center;
5431: font-weight: bold;
1.397 albertel 5432: }
1.396 albertel 5433:
1.795 www 5434: table#LC_helpmenu_links a:link,
5435: table#LC_helpmenu_links a:visited,
1.397 albertel 5436: table#LC_helpmenu_links a:active {
5437: text-decoration: none;
5438: color: $font;
5439: }
1.795 www 5440:
1.397 albertel 5441: table#LC_helpmenu_links a:hover {
5442: text-decoration: underline;
5443: color: $vlink;
5444: }
1.396 albertel 5445:
1.417 albertel 5446: .LC_chrt_popup_exists {
5447: border: 1px solid #339933;
5448: margin: -1px;
5449: }
1.795 www 5450:
1.417 albertel 5451: .LC_chrt_popup_up {
5452: border: 1px solid yellow;
5453: margin: -1px;
5454: }
1.795 www 5455:
1.417 albertel 5456: .LC_chrt_popup {
5457: border: 1px solid #8888FF;
5458: background: #CCCCFF;
5459: }
1.795 www 5460:
1.421 albertel 5461: table.LC_pick_box {
5462: border-collapse: separate;
5463: background: white;
5464: border: 1px solid black;
5465: border-spacing: 1px;
5466: }
1.795 www 5467:
1.421 albertel 5468: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5469: background: $sidebg;
1.421 albertel 5470: font-weight: bold;
1.900 bisitz 5471: text-align: left;
1.740 bisitz 5472: vertical-align: top;
1.421 albertel 5473: width: 184px;
5474: padding: 8px;
5475: }
1.795 www 5476:
1.579 raeburn 5477: table.LC_pick_box td.LC_pick_box_value {
5478: text-align: left;
5479: padding: 8px;
5480: }
1.795 www 5481:
1.579 raeburn 5482: table.LC_pick_box td.LC_pick_box_select {
5483: text-align: left;
5484: padding: 8px;
5485: }
1.795 www 5486:
1.424 albertel 5487: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5488: padding: 0;
1.421 albertel 5489: height: 1px;
5490: background: black;
5491: }
1.795 www 5492:
1.421 albertel 5493: table.LC_pick_box td.LC_pick_box_submit {
5494: text-align: right;
5495: }
1.795 www 5496:
1.579 raeburn 5497: table.LC_pick_box td.LC_evenrow_value {
5498: text-align: left;
5499: padding: 8px;
5500: background-color: $data_table_light;
5501: }
1.795 www 5502:
1.579 raeburn 5503: table.LC_pick_box td.LC_oddrow_value {
5504: text-align: left;
5505: padding: 8px;
5506: background-color: $data_table_light;
5507: }
1.795 www 5508:
1.579 raeburn 5509: span.LC_helpform_receipt_cat {
5510: font-weight: bold;
5511: }
1.795 www 5512:
1.424 albertel 5513: table.LC_group_priv_box {
5514: background: white;
5515: border: 1px solid black;
5516: border-spacing: 1px;
5517: }
1.795 www 5518:
1.424 albertel 5519: table.LC_group_priv_box td.LC_pick_box_title {
5520: background: $tabbg;
5521: font-weight: bold;
5522: text-align: right;
5523: width: 184px;
5524: }
1.795 www 5525:
1.424 albertel 5526: table.LC_group_priv_box td.LC_groups_fixed {
5527: background: $data_table_light;
5528: text-align: center;
5529: }
1.795 www 5530:
1.424 albertel 5531: table.LC_group_priv_box td.LC_groups_optional {
5532: background: $data_table_dark;
5533: text-align: center;
5534: }
1.795 www 5535:
1.424 albertel 5536: table.LC_group_priv_box td.LC_groups_functionality {
5537: background: $data_table_darker;
5538: text-align: center;
5539: font-weight: bold;
5540: }
1.795 www 5541:
1.424 albertel 5542: table.LC_group_priv td {
5543: text-align: left;
1.803 bisitz 5544: padding: 0;
1.424 albertel 5545: }
5546:
1.421 albertel 5547: table.LC_notify_front_page {
5548: background: white;
5549: border: 1px solid black;
5550: padding: 8px;
5551: }
1.795 www 5552:
1.421 albertel 5553: table.LC_notify_front_page td {
5554: padding: 8px;
5555: }
1.795 www 5556:
1.424 albertel 5557: .LC_navbuttons {
5558: margin: 2ex 0ex 2ex 0ex;
5559: }
1.795 www 5560:
1.423 albertel 5561: .LC_topic_bar {
5562: font-weight: bold;
5563: background: $tabbg;
1.918 wenzelju 5564: margin: 1em 0em 1em 2em;
1.805 bisitz 5565: padding: 3px;
1.918 wenzelju 5566: font-size: 1.2em;
1.423 albertel 5567: }
1.795 www 5568:
1.423 albertel 5569: .LC_topic_bar span {
1.918 wenzelju 5570: left: 0.5em;
5571: position: absolute;
1.423 albertel 5572: vertical-align: middle;
1.918 wenzelju 5573: font-size: 1.2em;
1.423 albertel 5574: }
1.795 www 5575:
1.423 albertel 5576: .LC_topic_bar img {
5577: vertical-align: bottom;
5578: }
1.795 www 5579:
1.423 albertel 5580: table.LC_course_group_status {
5581: margin: 20px;
5582: }
1.795 www 5583:
1.423 albertel 5584: table.LC_status_selector td {
5585: vertical-align: top;
5586: text-align: center;
1.424 albertel 5587: padding: 4px;
5588: }
1.795 www 5589:
1.599 albertel 5590: div.LC_feedback_link {
1.616 albertel 5591: clear: both;
1.829 kalberla 5592: background: $sidebg;
1.779 bisitz 5593: width: 100%;
1.829 kalberla 5594: padding-bottom: 10px;
5595: border: 1px $tabbg solid;
1.833 kalberla 5596: height: 22px;
5597: line-height: 22px;
5598: padding-top: 5px;
5599: }
5600:
5601: div.LC_feedback_link img {
5602: height: 22px;
1.867 kalberla 5603: vertical-align:middle;
1.829 kalberla 5604: }
5605:
1.911 bisitz 5606: div.LC_feedback_link a {
1.829 kalberla 5607: text-decoration: none;
1.489 raeburn 5608: }
1.795 www 5609:
1.867 kalberla 5610: div.LC_comblock {
1.911 bisitz 5611: display:inline;
1.867 kalberla 5612: color:$font;
5613: font-size:90%;
5614: }
5615:
5616: div.LC_feedback_link div.LC_comblock {
5617: padding-left:5px;
5618: }
5619:
5620: div.LC_feedback_link div.LC_comblock a {
5621: color:$font;
5622: }
5623:
1.489 raeburn 5624: span.LC_feedback_link {
1.858 bisitz 5625: /* background: $feedback_link_bg; */
1.599 albertel 5626: font-size: larger;
5627: }
1.795 www 5628:
1.599 albertel 5629: span.LC_message_link {
1.858 bisitz 5630: /* background: $feedback_link_bg; */
1.599 albertel 5631: font-size: larger;
5632: position: absolute;
5633: right: 1em;
1.489 raeburn 5634: }
1.421 albertel 5635:
1.515 albertel 5636: table.LC_prior_tries {
1.524 albertel 5637: border: 1px solid #000000;
5638: border-collapse: separate;
5639: border-spacing: 1px;
1.515 albertel 5640: }
1.523 albertel 5641:
1.515 albertel 5642: table.LC_prior_tries td {
1.524 albertel 5643: padding: 2px;
1.515 albertel 5644: }
1.523 albertel 5645:
5646: .LC_answer_correct {
1.795 www 5647: background: lightgreen;
5648: color: darkgreen;
5649: padding: 6px;
1.523 albertel 5650: }
1.795 www 5651:
1.523 albertel 5652: .LC_answer_charged_try {
1.797 www 5653: background: #FFAAAA;
1.795 www 5654: color: darkred;
5655: padding: 6px;
1.523 albertel 5656: }
1.795 www 5657:
1.779 bisitz 5658: .LC_answer_not_charged_try,
1.523 albertel 5659: .LC_answer_no_grade,
5660: .LC_answer_late {
1.795 www 5661: background: lightyellow;
1.523 albertel 5662: color: black;
1.795 www 5663: padding: 6px;
1.523 albertel 5664: }
1.795 www 5665:
1.523 albertel 5666: .LC_answer_previous {
1.795 www 5667: background: lightblue;
5668: color: darkblue;
5669: padding: 6px;
1.523 albertel 5670: }
1.795 www 5671:
1.779 bisitz 5672: .LC_answer_no_message {
1.777 tempelho 5673: background: #FFFFFF;
5674: color: black;
1.795 www 5675: padding: 6px;
1.779 bisitz 5676: }
1.795 www 5677:
1.779 bisitz 5678: .LC_answer_unknown {
5679: background: orange;
5680: color: black;
1.795 www 5681: padding: 6px;
1.777 tempelho 5682: }
1.795 www 5683:
1.529 albertel 5684: span.LC_prior_numerical,
5685: span.LC_prior_string,
5686: span.LC_prior_custom,
5687: span.LC_prior_reaction,
5688: span.LC_prior_math {
1.925 bisitz 5689: font-family: $mono;
1.523 albertel 5690: white-space: pre;
5691: }
5692:
1.525 albertel 5693: span.LC_prior_string {
1.925 bisitz 5694: font-family: $mono;
1.525 albertel 5695: white-space: pre;
5696: }
5697:
1.523 albertel 5698: table.LC_prior_option {
5699: width: 100%;
5700: border-collapse: collapse;
5701: }
1.795 www 5702:
1.911 bisitz 5703: table.LC_prior_rank,
1.795 www 5704: table.LC_prior_match {
1.528 albertel 5705: border-collapse: collapse;
5706: }
1.795 www 5707:
1.528 albertel 5708: table.LC_prior_option tr td,
5709: table.LC_prior_rank tr td,
5710: table.LC_prior_match tr td {
1.524 albertel 5711: border: 1px solid #000000;
1.515 albertel 5712: }
5713:
1.855 bisitz 5714: .LC_nobreak {
1.544 albertel 5715: white-space: nowrap;
1.519 raeburn 5716: }
5717:
1.576 raeburn 5718: span.LC_cusr_emph {
5719: font-style: italic;
5720: }
5721:
1.633 raeburn 5722: span.LC_cusr_subheading {
5723: font-weight: normal;
5724: font-size: 85%;
5725: }
5726:
1.861 bisitz 5727: div.LC_docs_entry_move {
1.859 bisitz 5728: border: 1px solid #BBBBBB;
1.545 albertel 5729: background: #DDDDDD;
1.861 bisitz 5730: width: 22px;
1.859 bisitz 5731: padding: 1px;
5732: margin: 0;
1.545 albertel 5733: }
5734:
1.861 bisitz 5735: table.LC_data_table tr > td.LC_docs_entry_commands,
5736: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5737: background: #DDDDDD;
5738: font-size: x-small;
5739: }
1.795 www 5740:
1.861 bisitz 5741: .LC_docs_entry_parameter {
5742: white-space: nowrap;
5743: }
5744:
1.544 albertel 5745: .LC_docs_copy {
1.545 albertel 5746: color: #000099;
1.544 albertel 5747: }
1.795 www 5748:
1.544 albertel 5749: .LC_docs_cut {
1.545 albertel 5750: color: #550044;
1.544 albertel 5751: }
1.795 www 5752:
1.544 albertel 5753: .LC_docs_rename {
1.545 albertel 5754: color: #009900;
1.544 albertel 5755: }
1.795 www 5756:
1.544 albertel 5757: .LC_docs_remove {
1.545 albertel 5758: color: #990000;
5759: }
5760:
1.547 albertel 5761: .LC_docs_reinit_warn,
5762: .LC_docs_ext_edit {
5763: font-size: x-small;
5764: }
5765:
1.545 albertel 5766: table.LC_docs_adddocs td,
5767: table.LC_docs_adddocs th {
5768: border: 1px solid #BBBBBB;
5769: padding: 4px;
5770: background: #DDDDDD;
1.543 albertel 5771: }
5772:
1.584 albertel 5773: table.LC_sty_begin {
5774: background: #BBFFBB;
5775: }
1.795 www 5776:
1.584 albertel 5777: table.LC_sty_end {
5778: background: #FFBBBB;
5779: }
5780:
1.589 raeburn 5781: table.LC_double_column {
1.803 bisitz 5782: border-width: 0;
1.589 raeburn 5783: border-collapse: collapse;
5784: width: 100%;
5785: padding: 2px;
5786: }
5787:
5788: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5789: top: 2px;
1.589 raeburn 5790: left: 2px;
5791: width: 47%;
5792: vertical-align: top;
5793: }
5794:
5795: table.LC_double_column tr td.LC_right_col {
5796: top: 2px;
1.779 bisitz 5797: right: 2px;
1.589 raeburn 5798: width: 47%;
5799: vertical-align: top;
5800: }
5801:
1.591 raeburn 5802: div.LC_left_float {
5803: float: left;
5804: padding-right: 5%;
1.597 albertel 5805: padding-bottom: 4px;
1.591 raeburn 5806: }
5807:
5808: div.LC_clear_float_header {
1.597 albertel 5809: padding-bottom: 2px;
1.591 raeburn 5810: }
5811:
5812: div.LC_clear_float_footer {
1.597 albertel 5813: padding-top: 10px;
1.591 raeburn 5814: clear: both;
5815: }
5816:
1.597 albertel 5817: div.LC_grade_show_user {
5818: margin-top: 20px;
5819: border: 1px solid black;
5820: }
1.795 www 5821:
1.597 albertel 5822: div.LC_grade_user_name {
5823: background: #DDDDEE;
5824: border-bottom: 1px solid black;
1.705 tempelho 5825: font-weight: bold;
5826: font-size: large;
1.597 albertel 5827: }
1.795 www 5828:
1.597 albertel 5829: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5830: background: #DDEEDD;
5831: }
5832:
5833: div.LC_grade_show_problem,
5834: div.LC_grade_submissions,
5835: div.LC_grade_message_center,
5836: div.LC_grade_info_links,
5837: div.LC_grade_assign {
5838: margin: 5px;
5839: width: 99%;
5840: background: #FFFFFF;
5841: }
1.795 www 5842:
1.597 albertel 5843: div.LC_grade_show_problem_header,
5844: div.LC_grade_submissions_header,
5845: div.LC_grade_message_center_header,
5846: div.LC_grade_assign_header {
1.705 tempelho 5847: font-weight: bold;
5848: font-size: large;
1.597 albertel 5849: }
1.795 www 5850:
1.597 albertel 5851: div.LC_grade_show_problem_problem,
5852: div.LC_grade_submissions_body,
5853: div.LC_grade_message_center_body,
5854: div.LC_grade_assign_body {
5855: border: 1px solid black;
5856: width: 99%;
5857: background: #FFFFFF;
5858: }
1.795 www 5859:
1.598 albertel 5860: span.LC_grade_check_note {
1.705 tempelho 5861: font-weight: normal;
5862: font-size: medium;
1.598 albertel 5863: display: inline;
5864: position: absolute;
5865: right: 1em;
5866: }
1.597 albertel 5867:
1.613 albertel 5868: table.LC_scantron_action {
5869: width: 100%;
5870: }
1.795 www 5871:
1.613 albertel 5872: table.LC_scantron_action tr th {
1.698 harmsja 5873: font-weight:bold;
5874: font-style:normal;
1.613 albertel 5875: }
1.795 www 5876:
1.779 bisitz 5877: .LC_edit_problem_header,
1.614 albertel 5878: div.LC_edit_problem_footer {
1.705 tempelho 5879: font-weight: normal;
5880: font-size: medium;
1.602 albertel 5881: margin: 2px;
1.600 albertel 5882: }
1.795 www 5883:
1.600 albertel 5884: div.LC_edit_problem_header,
1.602 albertel 5885: div.LC_edit_problem_header div,
1.614 albertel 5886: div.LC_edit_problem_footer,
5887: div.LC_edit_problem_footer div,
1.602 albertel 5888: div.LC_edit_problem_editxml_header,
5889: div.LC_edit_problem_editxml_header div {
1.600 albertel 5890: margin-top: 5px;
5891: }
1.795 www 5892:
1.600 albertel 5893: div.LC_edit_problem_header_title {
1.705 tempelho 5894: font-weight: bold;
5895: font-size: larger;
1.602 albertel 5896: background: $tabbg;
5897: padding: 3px;
5898: }
1.795 www 5899:
1.602 albertel 5900: table.LC_edit_problem_header_title {
1.705 tempelho 5901: font-size: larger;
5902: font-weight: bold;
1.602 albertel 5903: width: 100%;
5904: border-color: $pgbg;
5905: border-style: solid;
5906: border-width: $border;
1.600 albertel 5907: background: $tabbg;
1.602 albertel 5908: border-collapse: collapse;
1.803 bisitz 5909: padding: 0;
1.602 albertel 5910: }
5911:
5912: div.LC_edit_problem_discards {
5913: float: left;
5914: padding-bottom: 5px;
5915: }
1.795 www 5916:
1.602 albertel 5917: div.LC_edit_problem_saves {
5918: float: right;
5919: padding-bottom: 5px;
1.600 albertel 5920: }
1.795 www 5921:
1.911 bisitz 5922: img.stift {
1.803 bisitz 5923: border-width: 0;
5924: vertical-align: middle;
1.677 riegler 5925: }
1.680 riegler 5926:
1.923 bisitz 5927: table td.LC_mainmenu_col_fieldset {
1.680 riegler 5928: vertical-align: top;
1.777 tempelho 5929: }
1.795 www 5930:
1.716 raeburn 5931: div.LC_createcourse {
1.911 bisitz 5932: margin: 10px 10px 10px 10px;
1.716 raeburn 5933: }
5934:
1.917 raeburn 5935: .LC_dccid {
5936: margin: 0.2em 0 0 0;
5937: padding: 0;
5938: font-size: 90%;
5939: display:none;
5940: }
5941:
1.693 droeschl 5942: /* ---- Remove when done ----
5943: # The following styles is part of the redesign of LON-CAPA and are
5944: # subject to change during this project.
5945: # Don't rely on their current functionality as they might be
5946: # changed or removed.
5947: # --------------------------*/
5948:
1.698 harmsja 5949: a:hover,
1.897 wenzelju 5950: ol.LC_primary_menu a:hover,
1.721 harmsja 5951: ol#LC_MenuBreadcrumbs a:hover,
5952: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5953: ul#LC_secondary_menu a:hover,
1.721 harmsja 5954: .LC_FormSectionClearButton input:hover
1.795 www 5955: ul.LC_TabContent li:hover a {
1.911 bisitz 5956: color:#BF2317;
5957: text-decoration:none;
1.693 droeschl 5958: }
5959:
1.779 bisitz 5960: h1 {
1.911 bisitz 5961: padding: 0;
5962: line-height:130%;
1.693 droeschl 5963: }
1.698 harmsja 5964:
1.911 bisitz 5965: h2,
5966: h3,
5967: h4,
5968: h5,
5969: h6 {
5970: margin: 5px 0 5px 0;
5971: padding: 0;
5972: line-height:130%;
1.693 droeschl 5973: }
1.795 www 5974:
5975: .LC_hcell {
1.911 bisitz 5976: padding:3px 15px 3px 15px;
5977: margin: 0;
5978: background-color:$tabbg;
5979: color:$fontmenu;
5980: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5981: }
1.795 www 5982:
1.840 bisitz 5983: .LC_Box > .LC_hcell {
1.911 bisitz 5984: margin: 0 -10px 10px -10px;
1.835 bisitz 5985: }
5986:
1.721 harmsja 5987: .LC_noBorder {
1.911 bisitz 5988: border: 0;
1.698 harmsja 5989: }
1.693 droeschl 5990:
1.721 harmsja 5991: .LC_FormSectionClearButton input {
1.911 bisitz 5992: background-color:transparent;
5993: border: none;
5994: cursor:pointer;
5995: text-decoration:underline;
1.693 droeschl 5996: }
1.763 bisitz 5997:
5998: .LC_help_open_topic {
1.911 bisitz 5999: color: #FFFFFF;
6000: background-color: #EEEEFF;
6001: margin: 1px;
6002: padding: 4px;
6003: border: 1px solid #000033;
6004: white-space: nowrap;
6005: /* vertical-align: middle; */
1.759 neumanie 6006: }
1.693 droeschl 6007:
1.911 bisitz 6008: dl,
6009: ul,
6010: div,
6011: fieldset {
6012: margin: 10px 10px 10px 0;
6013: /* overflow: hidden; */
1.693 droeschl 6014: }
1.795 www 6015:
1.838 bisitz 6016: fieldset > legend {
1.911 bisitz 6017: font-weight: bold;
6018: padding: 0 5px 0 5px;
1.838 bisitz 6019: }
6020:
1.813 bisitz 6021: #LC_nav_bar {
1.911 bisitz 6022: float: left;
6023: margin: 0.2em 0 0 0;
1.807 droeschl 6024: }
6025:
1.916 droeschl 6026: #LC_realm {
6027: margin: 0.2em 0 0 0;
6028: padding: 0;
6029: font-weight: bold;
6030: text-align: center;
6031: }
6032:
1.911 bisitz 6033: #LC_nav_bar em {
6034: font-weight: bold;
6035: font-style: normal;
1.807 droeschl 6036: }
6037:
1.897 wenzelju 6038: ol.LC_primary_menu {
1.911 bisitz 6039: float: right;
6040: margin: 0.2em 0 0 0;
1.807 droeschl 6041: }
6042:
1.852 droeschl 6043: ol#LC_PathBreadcrumbs {
1.911 bisitz 6044: margin: 0;
1.693 droeschl 6045: }
6046:
1.897 wenzelju 6047: ol.LC_primary_menu li {
1.911 bisitz 6048: display: inline;
6049: padding: 5px 5px 0 10px;
6050: vertical-align: top;
1.693 droeschl 6051: }
6052:
1.897 wenzelju 6053: ol.LC_primary_menu li img {
1.911 bisitz 6054: vertical-align: bottom;
1.693 droeschl 6055: }
6056:
1.897 wenzelju 6057: ol.LC_primary_menu a {
1.911 bisitz 6058: font-size: 90%;
6059: color: RGB(80, 80, 80);
6060: text-decoration: none;
1.693 droeschl 6061: }
1.795 www 6062:
1.897 wenzelju 6063: ul#LC_secondary_menu {
1.911 bisitz 6064: clear: both;
6065: color: $fontmenu;
6066: background: $tabbg;
6067: list-style: none;
6068: padding: 0;
6069: margin: 0;
6070: width: 100%;
1.808 droeschl 6071: }
6072:
1.897 wenzelju 6073: ul#LC_secondary_menu li {
1.911 bisitz 6074: font-weight: bold;
6075: line-height: 1.8em;
6076: padding: 0 0.8em;
6077: border-right: 1px solid black;
6078: display: inline;
6079: vertical-align: middle;
1.807 droeschl 6080: }
6081:
1.847 tempelho 6082: ul.LC_TabContent {
1.911 bisitz 6083: display:block;
6084: background: $sidebg;
6085: border-bottom: solid 1px $lg_border_color;
6086: list-style:none;
6087: margin: 0 -10px;
6088: padding: 0;
1.693 droeschl 6089: }
6090:
1.795 www 6091: ul.LC_TabContent li,
6092: ul.LC_TabContentBigger li {
1.911 bisitz 6093: float:left;
1.741 harmsja 6094: }
1.795 www 6095:
1.897 wenzelju 6096: ul#LC_secondary_menu li a {
1.911 bisitz 6097: color: $fontmenu;
6098: text-decoration: none;
1.693 droeschl 6099: }
1.795 www 6100:
1.721 harmsja 6101: ul.LC_TabContent {
1.911 bisitz 6102: min-height:1.5em;
1.721 harmsja 6103: }
1.795 www 6104:
6105: ul.LC_TabContent li {
1.911 bisitz 6106: vertical-align:middle;
6107: padding: 0 10px 0 10px;
6108: background-color:$tabbg;
6109: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 6110: }
1.795 www 6111:
1.847 tempelho 6112: ul.LC_TabContent .right {
1.911 bisitz 6113: float:right;
1.847 tempelho 6114: }
6115:
1.911 bisitz 6116: ul.LC_TabContent li a,
6117: ul.LC_TabContent li {
6118: color:rgb(47,47,47);
6119: text-decoration:none;
6120: font-size:95%;
6121: font-weight:bold;
6122: padding-right: 16px;
1.721 harmsja 6123: }
1.795 www 6124:
1.911 bisitz 6125: ul.LC_TabContent li:hover,
6126: ul.LC_TabContent li.active {
6127: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
6128: border-bottom:solid 2px #FFFFFF;
6129: padding-right: 16px;
1.744 ehlerst 6130: }
1.795 www 6131:
1.870 tempelho 6132: #maincoursedoc {
1.911 bisitz 6133: clear:both;
1.870 tempelho 6134: }
6135:
6136: ul.LC_TabContentBigger {
1.911 bisitz 6137: display:block;
6138: list-style:none;
6139: padding: 0;
1.870 tempelho 6140: }
6141:
1.795 www 6142: ul.LC_TabContentBigger li {
1.911 bisitz 6143: vertical-align:bottom;
6144: height: 30px;
6145: font-size:110%;
6146: font-weight:bold;
6147: color: #737373;
1.841 tempelho 6148: }
6149:
1.870 tempelho 6150:
6151: ul.LC_TabContentBigger li a {
1.911 bisitz 6152: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6153: height: 30px;
6154: line-height: 30px;
6155: text-align: center;
6156: display: block;
6157: text-decoration: none;
1.741 harmsja 6158: }
1.795 www 6159:
1.911 bisitz 6160: ul.LC_TabContentBigger li:hover a,
1.870 tempelho 6161: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6162: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6163: color:$font;
6164: text-decoration: underline;
1.744 ehlerst 6165: }
1.795 www 6166:
1.870 tempelho 6167:
6168: ul.LC_TabContentBigger li b {
1.911 bisitz 6169: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6170: display: block;
6171: float: left;
6172: padding: 0 30px;
1.870 tempelho 6173: }
6174:
6175: ul.LC_TabContentBigger li:hover b,
6176: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6177: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6178: color:$font;
6179: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6180: }
1.693 droeschl 6181:
1.870 tempelho 6182:
1.862 bisitz 6183: ul.LC_CourseBreadcrumbs {
6184: background: $sidebg;
6185: line-height: 32px;
6186: padding-left: 10px;
6187: margin: 0 0 10px 0;
6188: list-style-position: inside;
6189:
6190: }
6191:
1.911 bisitz 6192: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6193: ol#LC_PathBreadcrumbs {
1.911 bisitz 6194: padding-left: 10px;
6195: margin: 0;
6196: list-style-position: inside;
1.915 droeschl 6197: /* SD working here
1.904 droeschl 6198: white-space: nowrap; */
1.693 droeschl 6199: }
6200:
1.911 bisitz 6201: ol#LC_MenuBreadcrumbs li,
6202: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6203: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6204: display: inline;
6205: white-space: nowrap;
1.915 droeschl 6206: /* SD working here
6207: white-space: normal; */
1.693 droeschl 6208: }
6209:
1.823 bisitz 6210: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6211: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6212: text-decoration: none;
6213: font-size:90%;
1.693 droeschl 6214: }
1.795 www 6215:
6216: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6217: text-decoration:none;
6218: font-size:100%;
6219: font-weight:bold;
1.693 droeschl 6220: }
1.795 www 6221:
1.840 bisitz 6222: .LC_Box {
1.911 bisitz 6223: border: solid 1px $lg_border_color;
6224: padding: 0 10px 10px 10px;
1.746 neumanie 6225: }
1.795 www 6226:
6227: .LC_AboutMe_Image {
1.911 bisitz 6228: float:left;
6229: margin-right:10px;
1.747 neumanie 6230: }
1.795 www 6231:
6232: .LC_Clear_AboutMe_Image {
1.911 bisitz 6233: clear:left;
1.747 neumanie 6234: }
1.795 www 6235:
1.721 harmsja 6236: dl.LC_ListStyleClean dt {
1.911 bisitz 6237: padding-right: 5px;
6238: display: table-header-group;
1.693 droeschl 6239: }
6240:
1.721 harmsja 6241: dl.LC_ListStyleClean dd {
1.911 bisitz 6242: display: table-row;
1.693 droeschl 6243: }
6244:
1.721 harmsja 6245: .LC_ListStyleClean,
6246: .LC_ListStyleSimple,
6247: .LC_ListStyleNormal,
1.795 www 6248: .LC_ListStyleSpecial {
1.911 bisitz 6249: /* display:block; */
6250: list-style-position: inside;
6251: list-style-type: none;
6252: overflow: hidden;
6253: padding: 0;
1.693 droeschl 6254: }
6255:
1.721 harmsja 6256: .LC_ListStyleSimple li,
6257: .LC_ListStyleSimple dd,
6258: .LC_ListStyleNormal li,
6259: .LC_ListStyleNormal dd,
6260: .LC_ListStyleSpecial li,
1.795 www 6261: .LC_ListStyleSpecial dd {
1.911 bisitz 6262: margin: 0;
6263: padding: 5px 5px 5px 10px;
6264: clear: both;
1.693 droeschl 6265: }
6266:
1.721 harmsja 6267: .LC_ListStyleClean li,
6268: .LC_ListStyleClean dd {
1.911 bisitz 6269: padding-top: 0;
6270: padding-bottom: 0;
1.693 droeschl 6271: }
6272:
1.721 harmsja 6273: .LC_ListStyleSimple dd,
1.795 www 6274: .LC_ListStyleSimple li {
1.911 bisitz 6275: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6276: }
6277:
1.721 harmsja 6278: .LC_ListStyleSpecial li,
6279: .LC_ListStyleSpecial dd {
1.911 bisitz 6280: list-style-type: none;
6281: background-color: RGB(220, 220, 220);
6282: margin-bottom: 4px;
1.693 droeschl 6283: }
6284:
1.721 harmsja 6285: table.LC_SimpleTable {
1.911 bisitz 6286: margin:5px;
6287: border:solid 1px $lg_border_color;
1.795 www 6288: }
1.693 droeschl 6289:
1.721 harmsja 6290: table.LC_SimpleTable tr {
1.911 bisitz 6291: padding: 0;
6292: border:solid 1px $lg_border_color;
1.693 droeschl 6293: }
1.795 www 6294:
6295: table.LC_SimpleTable thead {
1.911 bisitz 6296: background:rgb(220,220,220);
1.693 droeschl 6297: }
6298:
1.721 harmsja 6299: div.LC_columnSection {
1.911 bisitz 6300: display: block;
6301: clear: both;
6302: overflow: hidden;
6303: margin: 0;
1.693 droeschl 6304: }
6305:
1.721 harmsja 6306: div.LC_columnSection>* {
1.911 bisitz 6307: float: left;
6308: margin: 10px 20px 10px 0;
6309: overflow:hidden;
1.693 droeschl 6310: }
1.721 harmsja 6311:
1.694 tempelho 6312: .LC_loginpage_container {
1.911 bisitz 6313: text-align:left;
6314: margin : 0 auto;
6315: width:90%;
6316: padding: 10px;
6317: height: auto;
6318: background-color:#FFFFFF;
6319: border:1px solid #CCCCCC;
1.694 tempelho 6320: }
6321:
6322:
6323: .LC_loginpage_loginContainer {
1.911 bisitz 6324: float:left;
6325: width: 182px;
6326: padding: 2px;
6327: border:1px solid #CCCCCC;
6328: background-color:$loginbg;
1.694 tempelho 6329: }
6330:
1.795 www 6331: .LC_loginpage_loginContainer h2 {
1.911 bisitz 6332: margin-top: 0;
6333: display:block;
6334: background:$bgcol;
6335: color:$textcol;
6336: padding-left:5px;
1.712 muellerd 6337: }
1.785 tempelho 6338:
1.694 tempelho 6339: .LC_loginpage_loginInfo {
1.911 bisitz 6340: float:left;
6341: width:182px;
6342: border:1px solid #CCCCCC;
6343: padding:2px;
1.712 muellerd 6344: }
6345:
1.694 tempelho 6346: .LC_loginpage_space {
1.911 bisitz 6347: clear: both;
6348: margin-bottom: 20px;
6349: border-bottom: 1px solid #CCCCCC;
1.694 tempelho 6350: }
6351:
1.785 tempelho 6352: .LC_loginpage_floatLeft {
1.911 bisitz 6353: float: left;
6354: width: 200px;
6355: margin: 0;
1.785 tempelho 6356: }
6357:
1.795 www 6358: table em {
1.911 bisitz 6359: font-weight: bold;
6360: font-style: normal;
1.748 schulted 6361: }
1.795 www 6362:
1.779 bisitz 6363: table.LC_tableBrowseRes,
1.795 www 6364: table.LC_tableOfContent {
1.911 bisitz 6365: border:none;
6366: border-spacing: 1px;
6367: padding: 3px;
6368: background-color: #FFFFFF;
6369: font-size: 90%;
1.753 droeschl 6370: }
1.789 droeschl 6371:
1.911 bisitz 6372: table.LC_tableOfContent {
6373: border-collapse: collapse;
1.789 droeschl 6374: }
6375:
1.771 droeschl 6376: table.LC_tableBrowseRes a,
1.768 schulted 6377: table.LC_tableOfContent a {
1.911 bisitz 6378: background-color: transparent;
6379: text-decoration: none;
1.753 droeschl 6380: }
6381:
1.795 www 6382: table.LC_tableOfContent img {
1.911 bisitz 6383: border: none;
6384: height: 1.3em;
6385: vertical-align: text-bottom;
6386: margin-right: 0.3em;
1.753 droeschl 6387: }
1.757 schulted 6388:
1.795 www 6389: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6390: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6391: }
6392:
1.795 www 6393: a#LC_content_toolbar_launchnav {
1.911 bisitz 6394: background-image:url(/res/adm/pages/start-navigation.gif);
1.774 ehlerst 6395: }
6396:
1.795 www 6397: a#LC_content_toolbar_closenav {
1.911 bisitz 6398: background-image:url(/res/adm/pages/close-navigation.gif);
1.774 ehlerst 6399: }
6400:
1.795 www 6401: a#LC_content_toolbar_everything {
1.911 bisitz 6402: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6403: }
6404:
1.795 www 6405: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6406: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6407: }
6408:
1.795 www 6409: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6410: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6411: }
6412:
1.795 www 6413: a#LC_content_toolbar_changefolder {
1.911 bisitz 6414: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6415: }
6416:
1.795 www 6417: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6418: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6419: }
6420:
1.795 www 6421: ul#LC_toolbar li a:hover {
1.911 bisitz 6422: background-position: bottom center;
1.757 schulted 6423: }
6424:
1.795 www 6425: ul#LC_toolbar {
1.911 bisitz 6426: padding: 0;
6427: margin: 2px;
6428: list-style:none;
6429: position:relative;
6430: background-color:white;
1.757 schulted 6431: }
6432:
1.795 www 6433: ul#LC_toolbar li {
1.911 bisitz 6434: border:1px solid white;
6435: padding: 0;
6436: margin: 0;
6437: float: left;
6438: display:inline;
6439: vertical-align:middle;
6440: }
1.757 schulted 6441:
1.783 amueller 6442:
1.795 www 6443: a.LC_toolbarItem {
1.911 bisitz 6444: display:block;
6445: padding: 0;
6446: margin: 0;
6447: height: 32px;
6448: width: 32px;
6449: color:white;
6450: border: none;
6451: background-repeat:no-repeat;
6452: background-color:transparent;
1.757 schulted 6453: }
6454:
1.915 droeschl 6455: ul.LC_funclist {
6456: margin: 0;
6457: padding: 0.5em 1em 0.5em 0;
6458: }
6459:
6460: ul.LC_funclist + ul.LC_funclist {
6461: /*
6462: left border as a seperator if we have more than
6463: one list
6464: */
6465: border-left: 1px solid $sidebg;
6466: /*
6467: this hides the left border behind the border of the
6468: outer box if element is wrapped to the next 'line'
6469: */
6470: margin-left: -1px;
6471: }
6472:
1.843 bisitz 6473: ul.LC_funclist li {
1.915 droeschl 6474: display: inline;
1.782 bisitz 6475: white-space: nowrap;
1.915 droeschl 6476: margin: 0 0 0 25px;
6477: line-height: 150%;
1.782 bisitz 6478: }
6479:
1.925.2.1 raeburn 6480: #gciheader {
6481: float:left;
6482: width:100%;
6483: background:#DAE0D2 url("/gcimenu_bg.gif") repeat-x bottom;
6484: font-size:93%;
6485: line-height:normal;
6486: }
6487: #gciheader ul {
6488: margin:0;
6489: padding:10px 10px 0;
6490: list-style:none;
6491: }
6492: #gciheader li {
6493: float:left;
6494: background:url("/gcimenu_left.gif") no-repeat left top;
6495: margin:0;
6496: padding:0 0 0 9px;
6497: }
6498: #gciheader a {
6499: display:block;
6500: background:url("/gcimenu_right.gif") no-repeat right top;
6501: padding:5px 15px 4px 6px;
6502: }
6503: #gciheader #current {
6504: background-image:url("/gcimenu_left_on.gif");
6505: }
6506: #gciheader #current a {
6507: background-image:url("/gcimenu_right_on.gif");
6508: padding-bottom:5px;
6509: }
1.757 schulted 6510:
1.343 albertel 6511: END
6512: }
6513:
1.306 albertel 6514: =pod
6515:
6516: =item * &headtag()
6517:
6518: Returns a uniform footer for LON-CAPA web pages.
6519:
1.307 albertel 6520: Inputs: $title - optional title for the head
6521: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6522: $args - optional arguments
1.319 albertel 6523: force_register - if is true call registerurl so the remote is
6524: informed
1.415 albertel 6525: redirect -> array ref of
6526: 1- seconds before redirect occurs
6527: 2- url to redirect to
6528: 3- whether the side effect should occur
1.315 albertel 6529: (side effect of setting
6530: $env{'internal.head.redirect'} to the url
6531: redirected too)
1.352 albertel 6532: domain -> force to color decorate a page for a specific
6533: domain
6534: function -> force usage of a specific rolish color scheme
6535: bgcolor -> override the default page bgcolor
1.460 albertel 6536: no_auto_mt_title
6537: -> prevent &mt()ing the title arg
1.464 albertel 6538:
1.306 albertel 6539: =cut
6540:
6541: sub headtag {
1.313 albertel 6542: my ($title,$head_extra,$args) = @_;
1.306 albertel 6543:
1.363 albertel 6544: my $function = $args->{'function'} || &get_users_function();
6545: my $domain = $args->{'domain'} || &determinedomain();
6546: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6547: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6548: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6549: #time(),
1.418 albertel 6550: $env{'environment.color.timestamp'},
1.363 albertel 6551: $function,$domain,$bgcolor);
6552:
1.369 www 6553: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6554:
1.308 albertel 6555: my $result =
6556: '<head>'.
1.461 albertel 6557: &font_settings();
1.319 albertel 6558:
1.461 albertel 6559: if (!$args->{'frameset'}) {
6560: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6561: }
1.319 albertel 6562: if ($args->{'force_register'}) {
6563: $result .= &Apache::lonmenu::registerurl(1);
6564: }
1.436 albertel 6565: if (!$args->{'no_nav_bar'}
6566: && !$args->{'only_body'}
6567: && !$args->{'frameset'}) {
6568: $result .= &help_menu_js();
6569: }
1.319 albertel 6570:
1.314 albertel 6571: if (ref($args->{'redirect'})) {
1.414 albertel 6572: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6573: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6574: if (!$inhibit_continue) {
6575: $env{'internal.head.redirect'} = $url;
6576: }
1.313 albertel 6577: $result.=<<ADDMETA
6578: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6579: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6580: ADDMETA
6581: }
1.306 albertel 6582: if (!defined($title)) {
6583: $title = 'The LearningOnline Network with CAPA';
6584: }
1.460 albertel 6585: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6586: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6587: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6588: .$head_extra;
1.306 albertel 6589: return $result;
6590: }
6591:
6592: =pod
6593:
1.340 albertel 6594: =item * &font_settings()
6595:
6596: Returns neccessary <meta> to set the proper encoding
6597:
6598: Inputs: none
6599:
6600: =cut
6601:
6602: sub font_settings {
6603: my $headerstring='';
1.647 www 6604: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6605: $headerstring.=
6606: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6607: }
6608: return $headerstring;
6609: }
6610:
1.341 albertel 6611: =pod
6612:
6613: =item * &xml_begin()
6614:
6615: Returns the needed doctype and <html>
6616:
6617: Inputs: none
6618:
6619: =cut
6620:
6621: sub xml_begin {
6622: my $output='';
6623:
1.592 albertel 6624: if ($env{'internal.start_page'}==1) {
6625: &Apache::lonhtmlcommon::init_htmlareafields();
6626: }
1.342 albertel 6627:
1.341 albertel 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 * &endheadtag()
6647:
6648: Returns a uniform </head> for LON-CAPA web pages.
6649:
6650: Inputs: none
6651:
6652: =cut
6653:
6654: sub endheadtag {
6655: return '</head>';
6656: }
6657:
6658: =pod
6659:
6660: =item * &head()
6661:
6662: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6663:
1.648 raeburn 6664: Inputs:
6665:
6666: =over 4
6667:
6668: $title - optional title for the page
6669:
6670: $head_extra - optional extra HTML to put inside the <head>
6671:
6672: =back
1.405 albertel 6673:
1.306 albertel 6674: =cut
6675:
6676: sub head {
1.325 albertel 6677: my ($title,$head_extra,$args) = @_;
6678: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6679: }
6680:
6681: =pod
6682:
6683: =item * &start_page()
6684:
6685: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6686:
1.648 raeburn 6687: Inputs:
6688:
6689: =over 4
6690:
6691: $title - optional title for the page
6692:
6693: $head_extra - optional extra HTML to incude inside the <head>
6694:
6695: $args - additional optional args supported are:
6696:
6697: =over 8
6698:
6699: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6700: arg on
1.814 bisitz 6701: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6702: add_entries -> additional attributes to add to the <body>
6703: domain -> force to color decorate a page for a
1.317 albertel 6704: specific domain
1.648 raeburn 6705: function -> force usage of a specific rolish color
1.317 albertel 6706: scheme
1.648 raeburn 6707: redirect -> see &headtag()
6708: bgcolor -> override the default page bg color
6709: js_ready -> return a string ready for being used in
1.317 albertel 6710: a javascript writeln
1.648 raeburn 6711: html_encode -> return a string ready for being used in
1.320 albertel 6712: a html attribute
1.648 raeburn 6713: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6714: $forcereg arg
1.648 raeburn 6715: frameset -> if true will start with a <frameset>
1.330 albertel 6716: rather than <body>
1.648 raeburn 6717: skip_phases -> hash ref of
1.338 albertel 6718: head -> skip the <html><head> generation
6719: body -> skip all <body> generation
1.648 raeburn 6720: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6721: 'Switch To Inline Menu' link
1.648 raeburn 6722: no_auto_mt_title -> prevent &mt()ing the title arg
6723: inherit_jsmath -> when creating popup window in a page,
6724: should it have jsmath forced on by the
6725: current page
1.867 kalberla 6726: bread_crumbs -> Array containing breadcrumbs
6727: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6728:
1.648 raeburn 6729: =back
1.460 albertel 6730:
1.648 raeburn 6731: =back
1.562 albertel 6732:
1.306 albertel 6733: =cut
6734:
6735: sub start_page {
1.309 albertel 6736: my ($title,$head_extra,$args) = @_;
1.318 albertel 6737: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6738: my %head_args;
1.352 albertel 6739: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6740: 'bgcolor','frameset','no_nav_bar','only_body',
6741: 'no_auto_mt_title') {
1.319 albertel 6742: if (defined($args->{$arg})) {
1.324 raeburn 6743: $head_args{$arg} = $args->{$arg};
1.319 albertel 6744: }
1.313 albertel 6745: }
1.319 albertel 6746:
1.315 albertel 6747: $env{'internal.start_page'}++;
1.338 albertel 6748: my $result;
6749: if (! exists($args->{'skip_phases'}{'head'}) ) {
6750: $result.=
1.341 albertel 6751: &xml_begin().
1.338 albertel 6752: &headtag($title,$head_extra,\%head_args).&endheadtag();
6753: }
6754:
6755: if (! exists($args->{'skip_phases'}{'body'}) ) {
6756: if ($args->{'frameset'}) {
6757: my $attr_string = &make_attr_string($args->{'force_register'},
6758: $args->{'add_entries'});
6759: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6760: } else {
6761: $result .=
6762: &bodytag($title,
6763: $args->{'function'}, $args->{'add_entries'},
6764: $args->{'only_body'}, $args->{'domain'},
6765: $args->{'force_register'}, $args->{'no_nav_bar'},
6766: $args->{'bgcolor'}, $args->{'no_inline_link'},
6767: $args);
6768: }
1.330 albertel 6769: }
1.338 albertel 6770:
1.315 albertel 6771: if ($args->{'js_ready'}) {
1.713 kaisler 6772: $result = &js_ready($result);
1.315 albertel 6773: }
1.320 albertel 6774: if ($args->{'html_encode'}) {
1.713 kaisler 6775: $result = &html_encode($result);
6776: }
6777:
1.813 bisitz 6778: # Preparation for new and consistent functionlist at top of screen
6779: # if ($args->{'functionlist'}) {
6780: # $result .= &build_functionlist();
6781: #}
6782:
6783: # Don't add anything more if only_body wanted
6784: return $result if $args->{'only_body'};
6785:
1.920 raeburn 6786: #Breadcrumbs for Construction Space provided by &bodytag.
6787: if (($env{'environment.remote'} eq 'off') && ($env{'request.state'} eq 'construct')) {
6788: return $result;
6789: }
6790:
1.813 bisitz 6791: #Breadcrumbs
1.758 kaisler 6792: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6793: &Apache::lonhtmlcommon::clear_breadcrumbs();
6794: #if any br links exists, add them to the breadcrumbs
6795: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6796: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6797: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6798: }
6799: }
6800:
6801: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6802: if(exists($args->{'bread_crumbs_component'})){
6803: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6804: }else{
6805: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6806: }
1.320 albertel 6807: }
1.315 albertel 6808: return $result;
1.306 albertel 6809: }
6810:
1.330 albertel 6811:
1.306 albertel 6812: =pod
6813:
6814: =item * &head()
6815:
6816: Returns a complete </body></html> section for LON-CAPA web pages.
6817:
1.315 albertel 6818: Inputs: $args - additional optional args supported are:
6819: js_ready -> return a string ready for being used in
6820: a javascript writeln
1.320 albertel 6821: html_encode -> return a string ready for being used in
6822: a html attribute
1.330 albertel 6823: frameset -> if true will start with a <frameset>
6824: rather than <body>
1.493 albertel 6825: dicsussion -> if true will get discussion from
6826: lonxml::xmlend
6827: (you can pass the target and parser arguments
6828: through optional 'target' and 'parser' args
6829: to this routine)
1.306 albertel 6830:
6831: =cut
6832:
6833: sub end_page {
1.315 albertel 6834: my ($args) = @_;
6835: $env{'internal.end_page'}++;
1.330 albertel 6836: my $result;
1.335 albertel 6837: if ($args->{'discussion'}) {
6838: my ($target,$parser);
6839: if (ref($args->{'discussion'})) {
6840: ($target,$parser) =($args->{'discussion'}{'target'},
6841: $args->{'discussion'}{'parser'});
6842: }
6843: $result .= &Apache::lonxml::xmlend($target,$parser);
6844: }
6845:
1.330 albertel 6846: if ($args->{'frameset'}) {
6847: $result .= '</frameset>';
6848: } else {
1.635 raeburn 6849: $result .= &endbodytag($args);
1.330 albertel 6850: }
6851: $result .= "\n</html>";
6852:
1.315 albertel 6853: if ($args->{'js_ready'}) {
1.317 albertel 6854: $result = &js_ready($result);
1.315 albertel 6855: }
1.335 albertel 6856:
1.320 albertel 6857: if ($args->{'html_encode'}) {
6858: $result = &html_encode($result);
6859: }
1.335 albertel 6860:
1.315 albertel 6861: return $result;
6862: }
6863:
1.320 albertel 6864: sub html_encode {
6865: my ($result) = @_;
6866:
1.322 albertel 6867: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6868:
6869: return $result;
6870: }
1.317 albertel 6871: sub js_ready {
6872: my ($result) = @_;
6873:
1.323 albertel 6874: $result =~ s/[\n\r]/ /xmsg;
6875: $result =~ s/\\/\\\\/xmsg;
6876: $result =~ s/'/\\'/xmsg;
1.372 albertel 6877: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6878:
6879: return $result;
6880: }
6881:
1.315 albertel 6882: sub validate_page {
6883: if ( exists($env{'internal.start_page'})
1.316 albertel 6884: && $env{'internal.start_page'} > 1) {
6885: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6886: $env{'internal.start_page'}.' '.
1.316 albertel 6887: $ENV{'request.filename'});
1.315 albertel 6888: }
6889: if ( exists($env{'internal.end_page'})
1.316 albertel 6890: && $env{'internal.end_page'} > 1) {
6891: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6892: $env{'internal.end_page'}.' '.
1.316 albertel 6893: $env{'request.filename'});
1.315 albertel 6894: }
6895: if ( exists($env{'internal.start_page'})
6896: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6897: &Apache::lonnet::logthis('start_page called without end_page '.
6898: $env{'request.filename'});
1.315 albertel 6899: }
6900: if ( ! exists($env{'internal.start_page'})
6901: && exists($env{'internal.end_page'})) {
1.316 albertel 6902: &Apache::lonnet::logthis('end_page called without start_page'.
6903: $env{'request.filename'});
1.315 albertel 6904: }
1.306 albertel 6905: }
1.315 albertel 6906:
1.318 albertel 6907: sub simple_error_page {
6908: my ($r,$title,$msg) = @_;
6909: my $page =
6910: &Apache::loncommon::start_page($title).
6911: &mt($msg).
6912: &Apache::loncommon::end_page();
6913: if (ref($r)) {
6914: $r->print($page);
1.327 albertel 6915: return;
1.318 albertel 6916: }
6917: return $page;
6918: }
1.347 albertel 6919:
6920: {
1.610 albertel 6921: my @row_count;
1.347 albertel 6922: sub start_data_table {
1.422 albertel 6923: my ($add_class) = @_;
6924: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6925: unshift(@row_count,0);
1.422 albertel 6926: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6927: }
6928:
6929: sub end_data_table {
1.610 albertel 6930: shift(@row_count);
1.389 albertel 6931: return '</table>'."\n";;
1.347 albertel 6932: }
6933:
6934: sub start_data_table_row {
1.422 albertel 6935: my ($add_class) = @_;
1.610 albertel 6936: $row_count[0]++;
6937: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6938: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 6939: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6940: }
1.471 banghart 6941:
6942: sub continue_data_table_row {
6943: my ($add_class) = @_;
1.610 albertel 6944: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6945: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 6946: return '<tr class="'.$css_class.'">'."\n";;
6947: }
1.347 albertel 6948:
6949: sub end_data_table_row {
1.389 albertel 6950: return '</tr>'."\n";;
1.347 albertel 6951: }
1.367 www 6952:
1.421 albertel 6953: sub start_data_table_empty_row {
1.707 bisitz 6954: # $row_count[0]++;
1.421 albertel 6955: return '<tr class="LC_empty_row" >'."\n";;
6956: }
6957:
6958: sub end_data_table_empty_row {
6959: return '</tr>'."\n";;
6960: }
6961:
1.367 www 6962: sub start_data_table_header_row {
1.389 albertel 6963: return '<tr class="LC_header_row">'."\n";;
1.367 www 6964: }
6965:
6966: sub end_data_table_header_row {
1.389 albertel 6967: return '</tr>'."\n";;
1.367 www 6968: }
1.890 droeschl 6969:
6970: sub data_table_caption {
6971: my $caption = shift;
6972: return "<caption class=\"LC_caption\">$caption</caption>";
6973: }
1.347 albertel 6974: }
6975:
1.548 albertel 6976: =pod
6977:
6978: =item * &inhibit_menu_check($arg)
6979:
6980: Checks for a inhibitmenu state and generates output to preserve it
6981:
6982: Inputs: $arg - can be any of
6983: - undef - in which case the return value is a string
6984: to add into arguments list of a uri
6985: - 'input' - in which case the return value is a HTML
6986: <form> <input> field of type hidden to
6987: preserve the value
6988: - a url - in which case the return value is the url with
6989: the neccesary cgi args added to preserve the
6990: inhibitmenu state
6991: - a ref to a url - no return value, but the string is
6992: updated to include the neccessary cgi
6993: args to preserve the inhibitmenu state
6994:
6995: =cut
6996:
6997: sub inhibit_menu_check {
6998: my ($arg) = @_;
6999: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
7000: if ($arg eq 'input') {
7001: if ($env{'form.inhibitmenu'}) {
7002: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
7003: } else {
7004: return
7005: }
7006: }
7007: if ($env{'form.inhibitmenu'}) {
7008: if (ref($arg)) {
7009: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7010: } elsif ($arg eq '') {
7011: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7012: } else {
7013: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7014: }
7015: }
7016: if (!ref($arg)) {
7017: return $arg;
7018: }
7019: }
7020:
1.251 albertel 7021: ###############################################
1.182 matthew 7022:
7023: =pod
7024:
1.549 albertel 7025: =back
7026:
7027: =head1 User Information Routines
7028:
7029: =over 4
7030:
1.405 albertel 7031: =item * &get_users_function()
1.182 matthew 7032:
7033: Used by &bodytag to determine the current users primary role.
7034: Returns either 'student','coordinator','admin', or 'author'.
7035:
7036: =cut
7037:
7038: ###############################################
7039: sub get_users_function {
1.815 tempelho 7040: my $function = 'norole';
1.818 tempelho 7041: if ($env{'request.role'}=~/^(st)/) {
7042: $function='student';
7043: }
1.907 raeburn 7044: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7045: $function='coordinator';
7046: }
1.258 albertel 7047: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7048: $function='admin';
7049: }
1.826 bisitz 7050: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7051: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7052: $function='author';
7053: }
7054: return $function;
1.54 www 7055: }
1.99 www 7056:
7057: ###############################################
7058:
1.233 raeburn 7059: =pod
7060:
1.821 raeburn 7061: =item * &show_course()
7062:
7063: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7064: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7065:
7066: Inputs:
7067: None
7068:
7069: Outputs:
7070: Scalar: 1 if 'Course' to be used, 0 otherwise.
7071:
7072: =cut
7073:
7074: ###############################################
7075: sub show_course {
7076: my $course = !$env{'user.adv'};
7077: if (!$env{'user.adv'}) {
7078: foreach my $env (keys(%env)) {
7079: next if ($env !~ m/^user\.priv\./);
7080: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7081: $course = 0;
7082: last;
7083: }
7084: }
7085: }
7086: return $course;
7087: }
7088:
7089: ###############################################
7090:
7091: =pod
7092:
1.542 raeburn 7093: =item * &check_user_status()
1.274 raeburn 7094:
7095: Determines current status of supplied role for a
7096: specific user. Roles can be active, previous or future.
7097:
7098: Inputs:
7099: user's domain, user's username, course's domain,
1.375 raeburn 7100: course's number, optional section ID.
1.274 raeburn 7101:
7102: Outputs:
7103: role status: active, previous or future.
7104:
7105: =cut
7106:
7107: sub check_user_status {
1.412 raeburn 7108: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 7109: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
7110: my @uroles = keys %userinfo;
7111: my $srchstr;
7112: my $active_chk = 'none';
1.412 raeburn 7113: my $now = time;
1.274 raeburn 7114: if (@uroles > 0) {
1.908 raeburn 7115: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7116: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7117: } else {
1.412 raeburn 7118: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7119: }
7120: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7121: my $role_end = 0;
7122: my $role_start = 0;
7123: $active_chk = 'active';
1.412 raeburn 7124: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7125: $role_end = $1;
7126: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7127: $role_start = $1;
1.274 raeburn 7128: }
7129: }
7130: if ($role_start > 0) {
1.412 raeburn 7131: if ($now < $role_start) {
1.274 raeburn 7132: $active_chk = 'future';
7133: }
7134: }
7135: if ($role_end > 0) {
1.412 raeburn 7136: if ($now > $role_end) {
1.274 raeburn 7137: $active_chk = 'previous';
7138: }
7139: }
7140: }
7141: }
7142: return $active_chk;
7143: }
7144:
7145: ###############################################
7146:
7147: =pod
7148:
1.405 albertel 7149: =item * &get_sections()
1.233 raeburn 7150:
7151: Determines all the sections for a course including
7152: sections with students and sections containing other roles.
1.419 raeburn 7153: Incoming parameters:
7154:
7155: 1. domain
7156: 2. course number
7157: 3. reference to array containing roles for which sections should
7158: be gathered (optional).
7159: 4. reference to array containing status types for which sections
7160: should be gathered (optional).
7161:
7162: If the third argument is undefined, sections are gathered for any role.
7163: If the fourth argument is undefined, sections are gathered for any status.
7164: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7165:
1.374 raeburn 7166: Returns section hash (keys are section IDs, values are
7167: number of users in each section), subject to the
1.419 raeburn 7168: optional roles filter, optional status filter
1.233 raeburn 7169:
7170: =cut
7171:
7172: ###############################################
7173: sub get_sections {
1.419 raeburn 7174: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7175: if (!defined($cdom) || !defined($cnum)) {
7176: my $cid = $env{'request.course.id'};
7177:
7178: return if (!defined($cid));
7179:
7180: $cdom = $env{'course.'.$cid.'.domain'};
7181: $cnum = $env{'course.'.$cid.'.num'};
7182: }
7183:
7184: my %sectioncount;
1.419 raeburn 7185: my $now = time;
1.240 albertel 7186:
1.366 albertel 7187: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7188: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7189: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7190: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7191: my $start_index = &Apache::loncoursedata::CL_START();
7192: my $end_index = &Apache::loncoursedata::CL_END();
7193: my $status;
1.366 albertel 7194: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7195: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7196: $data->[$status_index],
7197: $data->[$start_index],
7198: $data->[$end_index]);
7199: if ($stu_status eq 'Active') {
7200: $status = 'active';
7201: } elsif ($end < $now) {
7202: $status = 'previous';
7203: } elsif ($start > $now) {
7204: $status = 'future';
7205: }
7206: if ($section ne '-1' && $section !~ /^\s*$/) {
7207: if ((!defined($possible_status)) || (($status ne '') &&
7208: (grep/^\Q$status\E$/,@{$possible_status}))) {
7209: $sectioncount{$section}++;
7210: }
1.240 albertel 7211: }
7212: }
7213: }
7214: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7215: foreach my $user (sort(keys(%courseroles))) {
7216: if ($user !~ /^(\w{2})/) { next; }
7217: my ($role) = ($user =~ /^(\w{2})/);
7218: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7219: my ($section,$status);
1.240 albertel 7220: if ($role eq 'cr' &&
7221: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7222: $section=$1;
7223: }
7224: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7225: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7226: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7227: if ($end == -1 && $start == -1) {
7228: next; #deleted role
7229: }
7230: if (!defined($possible_status)) {
7231: $sectioncount{$section}++;
7232: } else {
7233: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7234: $status = 'active';
7235: } elsif ($end < $now) {
7236: $status = 'future';
7237: } elsif ($start > $now) {
7238: $status = 'previous';
7239: }
7240: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7241: $sectioncount{$section}++;
7242: }
7243: }
1.233 raeburn 7244: }
1.366 albertel 7245: return %sectioncount;
1.233 raeburn 7246: }
7247:
1.274 raeburn 7248: ###############################################
1.294 raeburn 7249:
7250: =pod
1.405 albertel 7251:
7252: =item * &get_course_users()
7253:
1.275 raeburn 7254: Retrieves usernames:domains for users in the specified course
7255: with specific role(s), and access status.
7256:
7257: Incoming parameters:
1.277 albertel 7258: 1. course domain
7259: 2. course number
7260: 3. access status: users must have - either active,
1.275 raeburn 7261: previous, future, or all.
1.277 albertel 7262: 4. reference to array of permissible roles
1.288 raeburn 7263: 5. reference to array of section restrictions (optional)
7264: 6. reference to results object (hash of hashes).
7265: 7. reference to optional userdata hash
1.609 raeburn 7266: 8. reference to optional statushash
1.630 raeburn 7267: 9. flag if privileged users (except those set to unhide in
7268: course settings) should be excluded
1.609 raeburn 7269: Keys of top level results hash are roles.
1.275 raeburn 7270: Keys of inner hashes are username:domain, with
7271: values set to access type.
1.288 raeburn 7272: Optional userdata hash returns an array with arguments in the
7273: same order as loncoursedata::get_classlist() for student data.
7274:
1.609 raeburn 7275: Optional statushash returns
7276:
1.288 raeburn 7277: Entries for end, start, section and status are blank because
7278: of the possibility of multiple values for non-student roles.
7279:
1.275 raeburn 7280: =cut
1.405 albertel 7281:
1.275 raeburn 7282: ###############################################
1.405 albertel 7283:
1.275 raeburn 7284: sub get_course_users {
1.630 raeburn 7285: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7286: my %idx = ();
1.419 raeburn 7287: my %seclists;
1.288 raeburn 7288:
7289: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7290: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7291: $idx{end} = &Apache::loncoursedata::CL_END();
7292: $idx{start} = &Apache::loncoursedata::CL_START();
7293: $idx{id} = &Apache::loncoursedata::CL_ID();
7294: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7295: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7296: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7297:
1.290 albertel 7298: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7299: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7300: my $now = time;
1.277 albertel 7301: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7302: my $match = 0;
1.412 raeburn 7303: my $secmatch = 0;
1.419 raeburn 7304: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7305: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7306: if ($section eq '') {
7307: $section = 'none';
7308: }
1.291 albertel 7309: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7310: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7311: $secmatch = 1;
7312: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7313: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7314: $secmatch = 1;
7315: }
7316: } else {
1.419 raeburn 7317: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7318: $secmatch = 1;
7319: }
1.290 albertel 7320: }
1.412 raeburn 7321: if (!$secmatch) {
7322: next;
7323: }
1.419 raeburn 7324: }
1.275 raeburn 7325: if (defined($$types{'active'})) {
1.288 raeburn 7326: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7327: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7328: $match = 1;
1.275 raeburn 7329: }
7330: }
7331: if (defined($$types{'previous'})) {
1.609 raeburn 7332: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7333: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7334: $match = 1;
1.275 raeburn 7335: }
7336: }
7337: if (defined($$types{'future'})) {
1.609 raeburn 7338: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7339: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7340: $match = 1;
1.275 raeburn 7341: }
7342: }
1.609 raeburn 7343: if ($match) {
7344: push(@{$seclists{$student}},$section);
7345: if (ref($userdata) eq 'HASH') {
7346: $$userdata{$student} = $$classlist{$student};
7347: }
7348: if (ref($statushash) eq 'HASH') {
7349: $statushash->{$student}{'st'}{$section} = $status;
7350: }
1.288 raeburn 7351: }
1.275 raeburn 7352: }
7353: }
1.412 raeburn 7354: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7355: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7356: my $now = time;
1.609 raeburn 7357: my %displaystatus = ( previous => 'Expired',
7358: active => 'Active',
7359: future => 'Future',
7360: );
1.630 raeburn 7361: my %nothide;
7362: if ($hidepriv) {
7363: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7364: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7365: if ($user !~ /:/) {
7366: $nothide{join(':',split(/[\@]/,$user))}=1;
7367: } else {
7368: $nothide{$user} = 1;
7369: }
7370: }
7371: }
1.439 raeburn 7372: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7373: my $match = 0;
1.412 raeburn 7374: my $secmatch = 0;
1.439 raeburn 7375: my $status;
1.412 raeburn 7376: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7377: $user =~ s/:$//;
1.439 raeburn 7378: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7379: if ($end == -1 || $start == -1) {
7380: next;
7381: }
7382: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7383: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7384: my ($uname,$udom) = split(/:/,$user);
7385: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7386: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7387: $secmatch = 1;
7388: } elsif ($usec eq '') {
1.420 albertel 7389: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7390: $secmatch = 1;
7391: }
7392: } else {
7393: if (grep(/^\Q$usec\E$/,@{$sections})) {
7394: $secmatch = 1;
7395: }
7396: }
7397: if (!$secmatch) {
7398: next;
7399: }
1.288 raeburn 7400: }
1.419 raeburn 7401: if ($usec eq '') {
7402: $usec = 'none';
7403: }
1.275 raeburn 7404: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7405: if ($hidepriv) {
7406: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7407: (!$nothide{$uname.':'.$udom})) {
7408: next;
7409: }
7410: }
1.503 raeburn 7411: if ($end > 0 && $end < $now) {
1.439 raeburn 7412: $status = 'previous';
7413: } elsif ($start > $now) {
7414: $status = 'future';
7415: } else {
7416: $status = 'active';
7417: }
1.277 albertel 7418: foreach my $type (keys(%{$types})) {
1.275 raeburn 7419: if ($status eq $type) {
1.420 albertel 7420: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7421: push(@{$$users{$role}{$user}},$type);
7422: }
1.288 raeburn 7423: $match = 1;
7424: }
7425: }
1.419 raeburn 7426: if (($match) && (ref($userdata) eq 'HASH')) {
7427: if (!exists($$userdata{$uname.':'.$udom})) {
7428: &get_user_info($udom,$uname,\%idx,$userdata);
7429: }
1.420 albertel 7430: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7431: push(@{$seclists{$uname.':'.$udom}},$usec);
7432: }
1.609 raeburn 7433: if (ref($statushash) eq 'HASH') {
7434: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7435: }
1.275 raeburn 7436: }
7437: }
7438: }
7439: }
1.290 albertel 7440: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7441: if ((defined($cdom)) && (defined($cnum))) {
7442: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7443: if ( defined($csettings{'internal.courseowner'}) ) {
7444: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7445: next if ($owner eq '');
7446: my ($ownername,$ownerdom);
7447: if ($owner =~ /^([^:]+):([^:]+)$/) {
7448: $ownername = $1;
7449: $ownerdom = $2;
7450: } else {
7451: $ownername = $owner;
7452: $ownerdom = $cdom;
7453: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7454: }
7455: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7456: if (defined($userdata) &&
1.609 raeburn 7457: !exists($$userdata{$owner})) {
7458: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7459: if (!grep(/^none$/,@{$seclists{$owner}})) {
7460: push(@{$seclists{$owner}},'none');
7461: }
7462: if (ref($statushash) eq 'HASH') {
7463: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7464: }
1.290 albertel 7465: }
1.279 raeburn 7466: }
7467: }
7468: }
1.419 raeburn 7469: foreach my $user (keys(%seclists)) {
7470: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7471: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7472: }
1.275 raeburn 7473: }
7474: return;
7475: }
7476:
1.288 raeburn 7477: sub get_user_info {
7478: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7479: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7480: &plainname($uname,$udom,'lastname');
1.291 albertel 7481: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7482: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7483: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7484: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7485: return;
7486: }
1.275 raeburn 7487:
1.472 raeburn 7488: ###############################################
7489:
7490: =pod
7491:
7492: =item * &get_user_quota()
7493:
7494: Retrieves quota assigned for storage of portfolio files for a user
7495:
7496: Incoming parameters:
7497: 1. user's username
7498: 2. user's domain
7499:
7500: Returns:
1.536 raeburn 7501: 1. Disk quota (in Mb) assigned to student.
7502: 2. (Optional) Type of setting: custom or default
7503: (individually assigned or default for user's
7504: institutional status).
7505: 3. (Optional) - User's institutional status (e.g., faculty, staff
7506: or student - types as defined in localenroll::inst_usertypes
7507: for user's domain, which determines default quota for user.
7508: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7509:
7510: If a value has been stored in the user's environment,
1.536 raeburn 7511: it will return that, otherwise it returns the maximal default
7512: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7513:
7514: =cut
7515:
7516: ###############################################
7517:
7518:
7519: sub get_user_quota {
7520: my ($uname,$udom) = @_;
1.536 raeburn 7521: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7522: if (!defined($udom)) {
7523: $udom = $env{'user.domain'};
7524: }
7525: if (!defined($uname)) {
7526: $uname = $env{'user.name'};
7527: }
7528: if (($udom eq '' || $uname eq '') ||
7529: ($udom eq 'public') && ($uname eq 'public')) {
7530: $quota = 0;
1.536 raeburn 7531: $quotatype = 'default';
7532: $defquota = 0;
1.472 raeburn 7533: } else {
1.536 raeburn 7534: my $inststatus;
1.472 raeburn 7535: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7536: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7537: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7538: } else {
1.536 raeburn 7539: my %userenv =
7540: &Apache::lonnet::get('environment',['portfolioquota',
7541: 'inststatus'],$udom,$uname);
1.472 raeburn 7542: my ($tmp) = keys(%userenv);
7543: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7544: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7545: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7546: } else {
7547: undef(%userenv);
7548: }
7549: }
1.536 raeburn 7550: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7551: if ($quota eq '') {
1.536 raeburn 7552: $quota = $defquota;
7553: $quotatype = 'default';
7554: } else {
7555: $quotatype = 'custom';
1.472 raeburn 7556: }
7557: }
1.536 raeburn 7558: if (wantarray) {
7559: return ($quota,$quotatype,$settingstatus,$defquota);
7560: } else {
7561: return $quota;
7562: }
1.472 raeburn 7563: }
7564:
7565: ###############################################
7566:
7567: =pod
7568:
7569: =item * &default_quota()
7570:
1.536 raeburn 7571: Retrieves default quota assigned for storage of user portfolio files,
7572: given an (optional) user's institutional status.
1.472 raeburn 7573:
7574: Incoming parameters:
7575: 1. domain
1.536 raeburn 7576: 2. (Optional) institutional status(es). This is a : separated list of
7577: status types (e.g., faculty, staff, student etc.)
7578: which apply to the user for whom the default is being retrieved.
7579: If the institutional status string in undefined, the domain
7580: default quota will be returned.
1.472 raeburn 7581:
7582: Returns:
7583: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7584: 2. (Optional) institutional type which determined the value of the
7585: default quota.
1.472 raeburn 7586:
7587: If a value has been stored in the domain's configuration db,
7588: it will return that, otherwise it returns 20 (for backwards
7589: compatibility with domains which have not set up a configuration
7590: db file; the original statically defined portfolio quota was 20 Mb).
7591:
1.536 raeburn 7592: If the user's status includes multiple types (e.g., staff and student),
7593: the largest default quota which applies to the user determines the
7594: default quota returned.
7595:
1.780 raeburn 7596: =back
7597:
1.472 raeburn 7598: =cut
7599:
7600: ###############################################
7601:
7602:
7603: sub default_quota {
1.536 raeburn 7604: my ($udom,$inststatus) = @_;
7605: my ($defquota,$settingstatus);
7606: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7607: ['quotas'],$udom);
7608: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7609: if ($inststatus ne '') {
1.765 raeburn 7610: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7611: foreach my $item (@statuses) {
1.711 raeburn 7612: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7613: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7614: if ($defquota eq '') {
7615: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7616: $settingstatus = $item;
7617: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7618: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7619: $settingstatus = $item;
7620: }
7621: }
7622: } else {
7623: if ($quotahash{'quotas'}{$item} ne '') {
7624: if ($defquota eq '') {
7625: $defquota = $quotahash{'quotas'}{$item};
7626: $settingstatus = $item;
7627: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7628: $defquota = $quotahash{'quotas'}{$item};
7629: $settingstatus = $item;
7630: }
1.536 raeburn 7631: }
7632: }
7633: }
7634: }
7635: if ($defquota eq '') {
1.711 raeburn 7636: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7637: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7638: } else {
7639: $defquota = $quotahash{'quotas'}{'default'};
7640: }
1.536 raeburn 7641: $settingstatus = 'default';
7642: }
7643: } else {
7644: $settingstatus = 'default';
7645: $defquota = 20;
7646: }
7647: if (wantarray) {
7648: return ($defquota,$settingstatus);
1.472 raeburn 7649: } else {
1.536 raeburn 7650: return $defquota;
1.472 raeburn 7651: }
7652: }
7653:
1.384 raeburn 7654: sub get_secgrprole_info {
7655: my ($cdom,$cnum,$needroles,$type) = @_;
7656: my %sections_count = &get_sections($cdom,$cnum);
7657: my @sections = (sort {$a <=> $b} keys(%sections_count));
7658: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7659: my @groups = sort(keys(%curr_groups));
7660: my $allroles = [];
7661: my $rolehash;
7662: my $accesshash = {
7663: active => 'Currently has access',
7664: future => 'Will have future access',
7665: previous => 'Previously had access',
7666: };
7667: if ($needroles) {
7668: $rolehash = {'all' => 'all'};
1.385 albertel 7669: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7670: if (&Apache::lonnet::error(%user_roles)) {
7671: undef(%user_roles);
7672: }
7673: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7674: my ($role)=split(/\:/,$item,2);
7675: if ($role eq 'cr') { next; }
7676: if ($role =~ /^cr/) {
7677: $$rolehash{$role} = (split('/',$role))[3];
7678: } else {
7679: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7680: }
7681: }
7682: foreach my $key (sort(keys(%{$rolehash}))) {
7683: push(@{$allroles},$key);
7684: }
7685: push (@{$allroles},'st');
7686: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7687: }
7688: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7689: }
7690:
1.555 raeburn 7691: sub user_picker {
1.627 raeburn 7692: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7693: my $currdom = $dom;
7694: my %curr_selected = (
7695: srchin => 'dom',
1.580 raeburn 7696: srchby => 'lastname',
1.555 raeburn 7697: );
7698: my $srchterm;
1.625 raeburn 7699: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7700: if ($srch->{'srchby'} ne '') {
7701: $curr_selected{'srchby'} = $srch->{'srchby'};
7702: }
7703: if ($srch->{'srchin'} ne '') {
7704: $curr_selected{'srchin'} = $srch->{'srchin'};
7705: }
7706: if ($srch->{'srchtype'} ne '') {
7707: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7708: }
7709: if ($srch->{'srchdomain'} ne '') {
7710: $currdom = $srch->{'srchdomain'};
7711: }
7712: $srchterm = $srch->{'srchterm'};
7713: }
7714: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7715: 'usr' => 'Search criteria',
1.563 raeburn 7716: 'doma' => 'Domain/institution to search',
1.558 albertel 7717: 'uname' => 'username',
7718: 'lastname' => 'last name',
1.555 raeburn 7719: 'lastfirst' => 'last name, first name',
1.558 albertel 7720: 'crs' => 'in this course',
1.576 raeburn 7721: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7722: 'alc' => 'all LON-CAPA',
1.573 raeburn 7723: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7724: 'exact' => 'is',
7725: 'contains' => 'contains',
1.569 raeburn 7726: 'begins' => 'begins with',
1.571 raeburn 7727: 'youm' => "You must include some text to search for.",
7728: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7729: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7730: 'yomc' => "You must choose a domain when using an institutional directory search.",
7731: 'ymcd' => "You must choose a domain when using a domain search.",
7732: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7733: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7734: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7735: );
1.925.2.13! raeburn 7736: my $domform = &select_dom_form($currdom,'srchdomain',undef,1);
1.563 raeburn 7737: my $srchinsel = ' <select name="srchin">';
1.925.2.13! raeburn 7738:
1.555 raeburn 7739: my @srchins = ('crs','dom','alc','instd');
7740:
7741: foreach my $option (@srchins) {
7742: # FIXME 'alc' option unavailable until
7743: # loncreateuser::print_user_query_page()
7744: # has been completed.
7745: next if ($option eq 'alc');
1.880 raeburn 7746: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7747: next if ($option eq 'crs' && !$env{'request.course.id'});
1.925.2.13! raeburn 7748: next if ($option eq 'instd');
1.563 raeburn 7749: if ($curr_selected{'srchin'} eq $option) {
7750: $srchinsel .= '
1.925.2.13! raeburn 7751: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
1.563 raeburn 7752: } else {
7753: $srchinsel .= '
1.925.2.13! raeburn 7754: <option value="'.$option.'">'.$lt{$option}.'</option>';
1.563 raeburn 7755: }
1.555 raeburn 7756: }
1.563 raeburn 7757: $srchinsel .= "\n </select>\n";
1.555 raeburn 7758:
7759: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7760: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7761: if ($curr_selected{'srchby'} eq $option) {
7762: $srchbysel .= '
7763: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7764: } else {
7765: $srchbysel .= '
7766: <option value="'.$option.'">'.$lt{$option}.'</option>';
7767: }
7768: }
7769: $srchbysel .= "\n </select>\n";
7770:
7771: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7772: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7773: if ($curr_selected{'srchtype'} eq $option) {
7774: $srchtypesel .= '
7775: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7776: } else {
7777: $srchtypesel .= '
7778: <option value="'.$option.'">'.$lt{$option}.'</option>';
7779: }
7780: }
7781: $srchtypesel .= "\n </select>\n";
7782:
1.558 albertel 7783: my ($newuserscript,$new_user_create);
1.556 raeburn 7784:
7785: if ($forcenewuser) {
1.576 raeburn 7786: if (ref($srch) eq 'HASH') {
7787: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7788: if ($cancreate) {
7789: $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>';
7790: } else {
1.799 bisitz 7791: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7792: my %usertypetext = (
7793: official => 'institutional',
7794: unofficial => 'non-institutional',
7795: );
1.799 bisitz 7796: $new_user_create = '<p class="LC_warning">'
7797: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.925.2.13! raeburn 7798: .'<br />'
! 7799: .&mt('Enter a valid e-mail address as the username for the new user.').' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.'
! 7800: ,'<a href="'.$helplink.'">','</a>')
1.799 bisitz 7801: .'</p><br />';
1.627 raeburn 7802: }
1.576 raeburn 7803: }
7804: }
7805:
1.556 raeburn 7806: $newuserscript = <<"ENDSCRIPT";
7807:
1.570 raeburn 7808: function setSearch(createnew,callingForm) {
1.556 raeburn 7809: if (createnew == 1) {
1.570 raeburn 7810: for (var i=0; i<callingForm.srchby.length; i++) {
7811: if (callingForm.srchby.options[i].value == 'uname') {
7812: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7813: }
7814: }
1.570 raeburn 7815: for (var i=0; i<callingForm.srchin.length; i++) {
7816: if ( callingForm.srchin.options[i].value == 'dom') {
7817: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7818: }
7819: }
1.570 raeburn 7820: for (var i=0; i<callingForm.srchtype.length; i++) {
7821: if (callingForm.srchtype.options[i].value == 'exact') {
7822: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7823: }
7824: }
1.570 raeburn 7825: for (var i=0; i<callingForm.srchdomain.length; i++) {
7826: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7827: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7828: }
7829: }
7830: }
7831: }
7832: ENDSCRIPT
1.558 albertel 7833:
1.556 raeburn 7834: }
7835:
1.555 raeburn 7836: my $output = <<"END_BLOCK";
1.556 raeburn 7837: <script type="text/javascript">
1.824 bisitz 7838: // <![CDATA[
1.570 raeburn 7839: function validateEntry(callingForm) {
1.558 albertel 7840:
1.556 raeburn 7841: var checkok = 1;
1.558 albertel 7842: var srchin;
1.570 raeburn 7843: for (var i=0; i<callingForm.srchin.length; i++) {
7844: if ( callingForm.srchin[i].checked ) {
7845: srchin = callingForm.srchin[i].value;
1.558 albertel 7846: }
7847: }
7848:
1.570 raeburn 7849: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7850: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7851: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7852: var srchterm = callingForm.srchterm.value;
7853: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7854: var msg = "";
7855:
7856: if (srchterm == "") {
7857: checkok = 0;
1.571 raeburn 7858: msg += "$lt{'youm'}\\n";
1.556 raeburn 7859: }
7860:
1.569 raeburn 7861: if (srchtype== 'begins') {
7862: if (srchterm.length < 2) {
7863: checkok = 0;
1.571 raeburn 7864: msg += "$lt{'thte'}\\n";
1.569 raeburn 7865: }
7866: }
7867:
1.556 raeburn 7868: if (srchtype== 'contains') {
7869: if (srchterm.length < 3) {
7870: checkok = 0;
1.571 raeburn 7871: msg += "$lt{'thet'}\\n";
1.556 raeburn 7872: }
7873: }
7874: if (srchin == 'instd') {
7875: if (srchdomain == '') {
7876: checkok = 0;
1.571 raeburn 7877: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7878: }
7879: }
7880: if (srchin == 'dom') {
7881: if (srchdomain == '') {
7882: checkok = 0;
1.571 raeburn 7883: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7884: }
7885: }
7886: if (srchby == 'lastfirst') {
7887: if (srchterm.indexOf(",") == -1) {
7888: checkok = 0;
1.571 raeburn 7889: msg += "$lt{'whus'}\\n";
1.556 raeburn 7890: }
7891: if (srchterm.indexOf(",") == srchterm.length -1) {
7892: checkok = 0;
1.571 raeburn 7893: msg += "$lt{'whse'}\\n";
1.556 raeburn 7894: }
7895: }
7896: if (checkok == 0) {
1.571 raeburn 7897: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7898: return;
7899: }
7900: if (checkok == 1) {
1.570 raeburn 7901: callingForm.submit();
1.556 raeburn 7902: }
7903: }
7904:
7905: $newuserscript
7906:
1.824 bisitz 7907: // ]]>
1.556 raeburn 7908: </script>
1.558 albertel 7909:
7910: $new_user_create
7911:
1.555 raeburn 7912: END_BLOCK
1.558 albertel 7913:
1.876 raeburn 7914: $output .= &Apache::lonhtmlcommon::start_pick_box().
7915: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7916: $domform.
7917: &Apache::lonhtmlcommon::row_closure().
7918: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7919: $srchbysel.
7920: $srchtypesel.
7921: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7922: $srchinsel.
7923: &Apache::lonhtmlcommon::row_closure(1).
7924: &Apache::lonhtmlcommon::end_pick_box().
7925: '<br />';
1.555 raeburn 7926: return $output;
7927: }
7928:
1.612 raeburn 7929: sub user_rule_check {
1.615 raeburn 7930: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7931: my $response;
7932: if (ref($usershash) eq 'HASH') {
7933: foreach my $user (keys(%{$usershash})) {
7934: my ($uname,$udom) = split(/:/,$user);
7935: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7936: my ($id,$newuser);
1.612 raeburn 7937: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7938: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7939: $id = $usershash->{$user}->{'id'};
7940: }
7941: my $inst_response;
7942: if (ref($checks) eq 'HASH') {
7943: if (defined($checks->{'username'})) {
1.615 raeburn 7944: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7945: &Apache::lonnet::get_instuser($udom,$uname);
7946: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7947: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7948: &Apache::lonnet::get_instuser($udom,undef,$id);
7949: }
1.615 raeburn 7950: } else {
7951: ($inst_response,%{$inst_results->{$user}}) =
7952: &Apache::lonnet::get_instuser($udom,$uname);
7953: return;
1.612 raeburn 7954: }
1.615 raeburn 7955: if (!$got_rules->{$udom}) {
1.612 raeburn 7956: my %domconfig = &Apache::lonnet::get_dom('configuration',
7957: ['usercreation'],$udom);
7958: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7959: foreach my $item ('username','id') {
1.612 raeburn 7960: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7961: $$curr_rules{$udom}{$item} =
7962: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7963: }
7964: }
7965: }
1.615 raeburn 7966: $got_rules->{$udom} = 1;
1.585 raeburn 7967: }
1.612 raeburn 7968: foreach my $item (keys(%{$checks})) {
7969: if (ref($$curr_rules{$udom}) eq 'HASH') {
7970: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7971: if (@{$$curr_rules{$udom}{$item}} > 0) {
7972: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7973: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7974: if ($rule_check{$rule}) {
7975: $$rulematch{$user}{$item} = $rule;
7976: if ($inst_response eq 'ok') {
1.615 raeburn 7977: if (ref($inst_results) eq 'HASH') {
7978: if (ref($inst_results->{$user}) eq 'HASH') {
7979: if (keys(%{$inst_results->{$user}}) == 0) {
7980: $$alerts{$item}{$udom}{$uname} = 1;
7981: }
1.612 raeburn 7982: }
7983: }
1.615 raeburn 7984: }
7985: last;
1.585 raeburn 7986: }
7987: }
7988: }
7989: }
7990: }
7991: }
7992: }
7993: }
1.612 raeburn 7994: return;
7995: }
7996:
7997: sub user_rule_formats {
7998: my ($domain,$domdesc,$curr_rules,$check) = @_;
7999: my %text = (
8000: 'username' => 'Usernames',
8001: 'id' => 'IDs',
8002: );
8003: my $output;
8004: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
8005: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8006: if (@{$ruleorder} > 0) {
8007: $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>';
8008: foreach my $rule (@{$ruleorder}) {
8009: if (ref($curr_rules) eq 'ARRAY') {
8010: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8011: if (ref($rules->{$rule}) eq 'HASH') {
8012: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8013: $rules->{$rule}{'desc'}.'</li>';
8014: }
8015: }
8016: }
8017: }
8018: $output .= '</ul>';
8019: }
8020: }
8021: return $output;
8022: }
8023:
8024: sub instrule_disallow_msg {
1.615 raeburn 8025: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8026: my $response;
8027: my %text = (
8028: item => 'username',
8029: items => 'usernames',
8030: match => 'matches',
8031: do => 'does',
8032: action => 'a username',
8033: one => 'one',
8034: );
8035: if ($count > 1) {
8036: $text{'item'} = 'usernames';
8037: $text{'match'} ='match';
8038: $text{'do'} = 'do';
8039: $text{'action'} = 'usernames',
8040: $text{'one'} = 'ones';
8041: }
8042: if ($checkitem eq 'id') {
8043: $text{'items'} = 'IDs';
8044: $text{'item'} = 'ID';
8045: $text{'action'} = 'an ID';
1.615 raeburn 8046: if ($count > 1) {
8047: $text{'item'} = 'IDs';
8048: $text{'action'} = 'IDs';
8049: }
1.612 raeburn 8050: }
1.674 bisitz 8051: $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 8052: if ($mode eq 'upload') {
8053: if ($checkitem eq 'username') {
8054: $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'}.");
8055: } elsif ($checkitem eq 'id') {
1.674 bisitz 8056: $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 8057: }
1.669 raeburn 8058: } elsif ($mode eq 'selfcreate') {
8059: if ($checkitem eq 'id') {
8060: $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.");
8061: }
1.615 raeburn 8062: } else {
8063: if ($checkitem eq 'username') {
8064: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8065: } elsif ($checkitem eq 'id') {
8066: $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.");
8067: }
1.612 raeburn 8068: }
8069: return $response;
1.585 raeburn 8070: }
8071:
1.624 raeburn 8072: sub personal_data_fieldtitles {
8073: my %fieldtitles = &Apache::lonlocal::texthash (
8074: id => 'Student/Employee ID',
8075: permanentemail => 'E-mail address',
8076: lastname => 'Last Name',
8077: firstname => 'First Name',
8078: middlename => 'Middle Name',
8079: generation => 'Generation',
8080: gen => 'Generation',
1.765 raeburn 8081: inststatus => 'Affiliation',
1.624 raeburn 8082: );
8083: return %fieldtitles;
8084: }
8085:
1.642 raeburn 8086: sub sorted_inst_types {
8087: my ($dom) = @_;
8088: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8089: my $othertitle = &mt('All users');
8090: if ($env{'request.course.id'}) {
1.668 raeburn 8091: $othertitle = &mt('Any users');
1.642 raeburn 8092: }
8093: my @types;
8094: if (ref($order) eq 'ARRAY') {
8095: @types = @{$order};
8096: }
8097: if (@types == 0) {
8098: if (ref($usertypes) eq 'HASH') {
8099: @types = sort(keys(%{$usertypes}));
8100: }
8101: }
8102: if (keys(%{$usertypes}) > 0) {
8103: $othertitle = &mt('Other users');
8104: }
8105: return ($othertitle,$usertypes,\@types);
8106: }
8107:
1.645 raeburn 8108: sub get_institutional_codes {
8109: my ($settings,$allcourses,$LC_code) = @_;
8110: # Get complete list of course sections to update
8111: my @currsections = ();
8112: my @currxlists = ();
8113: my $coursecode = $$settings{'internal.coursecode'};
8114:
8115: if ($$settings{'internal.sectionnums'} ne '') {
8116: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8117: }
8118:
8119: if ($$settings{'internal.crosslistings'} ne '') {
8120: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8121: }
8122:
8123: if (@currxlists > 0) {
8124: foreach (@currxlists) {
8125: if (m/^([^:]+):(\w*)$/) {
8126: unless (grep/^$1$/,@{$allcourses}) {
8127: push @{$allcourses},$1;
8128: $$LC_code{$1} = $2;
8129: }
8130: }
8131: }
8132: }
8133:
8134: if (@currsections > 0) {
8135: foreach (@currsections) {
8136: if (m/^(\w+):(\w*)$/) {
8137: my $sec = $coursecode.$1;
8138: my $lc_sec = $2;
8139: unless (grep/^$sec$/,@{$allcourses}) {
8140: push @{$allcourses},$sec;
8141: $$LC_code{$sec} = $lc_sec;
8142: }
8143: }
8144: }
8145: }
8146: return;
8147: }
8148:
1.112 bowersj2 8149: =pod
8150:
1.780 raeburn 8151: =head1 Slot Helpers
8152:
8153: =over 4
8154:
8155: =item * sorted_slots()
8156:
8157: Sorts an array of slot names in order of slot start time (earliest first).
8158:
8159: Inputs:
8160:
8161: =over 4
8162:
8163: slotsarr - Reference to array of unsorted slot names.
8164:
8165: slots - Reference to hash of hash, where outer hash keys are slot names.
8166:
1.549 albertel 8167: =back
8168:
1.780 raeburn 8169: Returns:
8170:
8171: =over 4
8172:
8173: sorted - An array of slot names sorted by the start time of the slot.
8174:
8175: =back
8176:
8177: =back
8178:
8179: =cut
8180:
8181:
8182: sub sorted_slots {
8183: my ($slotsarr,$slots) = @_;
8184: my @sorted;
8185: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8186: @sorted =
8187: sort {
8188: if (ref($slots->{$a}) && ref($slots->{$b})) {
8189: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8190: }
8191: if (ref($slots->{$a})) { return -1;}
8192: if (ref($slots->{$b})) { return 1;}
8193: return 0;
8194: } @{$slotsarr};
8195: }
8196: return @sorted;
8197: }
8198:
8199:
8200: =pod
8201:
1.549 albertel 8202: =head1 HTTP Helpers
8203:
8204: =over 4
8205:
1.648 raeburn 8206: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8207:
1.258 albertel 8208: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8209: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8210: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8211:
8212: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8213: $possible_names is an ref to an array of form element names. As an example:
8214: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8215: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8216:
8217: =cut
1.1 albertel 8218:
1.6 albertel 8219: sub get_unprocessed_cgi {
1.25 albertel 8220: my ($query,$possible_names)= @_;
1.26 matthew 8221: # $Apache::lonxml::debug=1;
1.356 albertel 8222: foreach my $pair (split(/&/,$query)) {
8223: my ($name, $value) = split(/=/,$pair);
1.369 www 8224: $name = &unescape($name);
1.25 albertel 8225: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8226: $value =~ tr/+/ /;
8227: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8228: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8229: }
1.16 harris41 8230: }
1.6 albertel 8231: }
8232:
1.112 bowersj2 8233: =pod
8234:
1.648 raeburn 8235: =item * &cacheheader()
1.112 bowersj2 8236:
8237: returns cache-controlling header code
8238:
8239: =cut
8240:
1.7 albertel 8241: sub cacheheader {
1.258 albertel 8242: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8243: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8244: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8245: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8246: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8247: return $output;
1.7 albertel 8248: }
8249:
1.112 bowersj2 8250: =pod
8251:
1.648 raeburn 8252: =item * &no_cache($r)
1.112 bowersj2 8253:
8254: specifies header code to not have cache
8255:
8256: =cut
8257:
1.9 albertel 8258: sub no_cache {
1.216 albertel 8259: my ($r) = @_;
8260: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8261: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8262: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8263: $r->no_cache(1);
8264: $r->header_out("Expires" => $date);
8265: $r->header_out("Pragma" => "no-cache");
1.123 www 8266: }
8267:
8268: sub content_type {
1.181 albertel 8269: my ($r,$type,$charset) = @_;
1.299 foxr 8270: if ($r) {
8271: # Note that printout.pl calls this with undef for $r.
8272: &no_cache($r);
8273: }
1.258 albertel 8274: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8275: unless ($charset) {
8276: $charset=&Apache::lonlocal::current_encoding;
8277: }
8278: if ($charset) { $type.='; charset='.$charset; }
8279: if ($r) {
8280: $r->content_type($type);
8281: } else {
8282: print("Content-type: $type\n\n");
8283: }
1.9 albertel 8284: }
1.25 albertel 8285:
1.112 bowersj2 8286: =pod
8287:
1.648 raeburn 8288: =item * &add_to_env($name,$value)
1.112 bowersj2 8289:
1.258 albertel 8290: adds $name to the %env hash with value
1.112 bowersj2 8291: $value, if $name already exists, the entry is converted to an array
8292: reference and $value is added to the array.
8293:
8294: =cut
8295:
1.25 albertel 8296: sub add_to_env {
8297: my ($name,$value)=@_;
1.258 albertel 8298: if (defined($env{$name})) {
8299: if (ref($env{$name})) {
1.25 albertel 8300: #already have multiple values
1.258 albertel 8301: push(@{ $env{$name} },$value);
1.25 albertel 8302: } else {
8303: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8304: my $first=$env{$name};
8305: undef($env{$name});
8306: push(@{ $env{$name} },$first,$value);
1.25 albertel 8307: }
8308: } else {
1.258 albertel 8309: $env{$name}=$value;
1.25 albertel 8310: }
1.31 albertel 8311: }
1.149 albertel 8312:
8313: =pod
8314:
1.648 raeburn 8315: =item * &get_env_multiple($name)
1.149 albertel 8316:
1.258 albertel 8317: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8318: values may be defined and end up as an array ref.
8319:
8320: returns an array of values
8321:
8322: =cut
8323:
8324: sub get_env_multiple {
8325: my ($name) = @_;
8326: my @values;
1.258 albertel 8327: if (defined($env{$name})) {
1.149 albertel 8328: # exists is it an array
1.258 albertel 8329: if (ref($env{$name})) {
8330: @values=@{ $env{$name} };
1.149 albertel 8331: } else {
1.258 albertel 8332: $values[0]=$env{$name};
1.149 albertel 8333: }
8334: }
8335: return(@values);
8336: }
8337:
1.660 raeburn 8338: sub ask_for_embedded_content {
8339: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8340: my $upload_output = '
8341: <form name="upload_embedded" action="'.$actionurl.'"
8342: method="post" enctype="multipart/form-data">';
8343: $upload_output .= $state;
1.661 raeburn 8344: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8345:
8346: my $num = 0;
8347: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8348: $upload_output .= &start_data_table_row().
8349: '<td>'.$embed_file.'</td><td>';
8350: if ($args->{'ignore_remote_references'}
8351: && $embed_file =~ m{^\w+://}) {
8352: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8353: } elsif ($args->{'error_on_invalid_names'}
8354: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8355:
8356: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8357:
8358: } else {
8359: $upload_output .='
1.661 raeburn 8360: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8361: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8362: my $attrib = join(':',@{$$allfiles{$embed_file}});
8363: $upload_output .=
8364: "\n\t\t".
8365: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8366: $attrib.'" />';
8367: if (exists($$codebase{$embed_file})) {
8368: $upload_output .=
8369: "\n\t\t".
8370: '<input name="codebase_'.$num.'" type="hidden" value="'.
8371: &escape($$codebase{$embed_file}).'" />';
8372: }
8373: }
8374: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8375: $num++;
8376: }
8377: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8378: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8379: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8380: '.&mt('(only files for which a location has been provided will be uploaded)').'
8381: </form>';
8382: return $upload_output;
8383: }
8384:
1.661 raeburn 8385: sub upload_embedded {
8386: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8387: $current_disk_usage) = @_;
8388: my $output;
8389: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8390: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8391: my $orig_uploaded_filename =
8392: $env{'form.embedded_item_'.$i.'.filename'};
8393:
8394: $env{'form.embedded_orig_'.$i} =
8395: &unescape($env{'form.embedded_orig_'.$i});
8396: my ($path,$fname) =
8397: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8398: # no path, whole string is fname
8399: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8400:
8401: $path = $env{'form.currentpath'}.$path;
8402: $fname = &Apache::lonnet::clean_filename($fname);
8403: # See if there is anything left
8404: next if ($fname eq '');
8405:
8406: # Check if file already exists as a file or directory.
8407: my ($state,$msg);
8408: if ($context eq 'portfolio') {
8409: my $port_path = $dirpath;
8410: if ($group ne '') {
8411: $port_path = "groups/$group/$port_path";
8412: }
8413: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8414: $dir_root,$port_path,$disk_quota,
8415: $current_disk_usage,$uname,$udom);
8416: if ($state eq 'will_exceed_quota'
8417: || $state eq 'file_locked'
8418: || $state eq 'file_exists' ) {
8419: $output .= $msg;
8420: next;
8421: }
8422: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8423: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8424: if ($state eq 'exists') {
8425: $output .= $msg;
8426: next;
8427: }
8428: }
8429: # Check if extension is valid
8430: if (($fname =~ /\.(\w+)$/) &&
8431: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8432: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8433: next;
8434: } elsif (($fname =~ /\.(\w+)$/) &&
8435: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8436: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8437: next;
8438: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8439: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8440: next;
8441: }
8442:
8443: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8444: if ($context eq 'portfolio') {
8445: my $result=
8446: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8447: $dirpath.$path);
8448: if ($result !~ m|^/uploaded/|) {
8449: $output .= '<span class="LC_error">'
8450: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8451: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8452: .'</span><br />';
8453: next;
8454: } else {
8455: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8456: $path.$fname.'</span>').'</p>';
8457: }
8458: } else {
8459: # Save the file
8460: my $target = $env{'form.embedded_item_'.$i};
8461: my $fullpath = $dir_root.$dirpath.'/'.$path;
8462: my $dest = $fullpath.$fname;
8463: my $url = $url_root.$dirpath.'/'.$path.$fname;
8464: my @parts=split(/\//,$fullpath);
8465: my $count;
8466: my $filepath = $dir_root;
8467: for ($count=4;$count<=$#parts;$count++) {
8468: $filepath .= "/$parts[$count]";
8469: if ((-e $filepath)!=1) {
8470: mkdir($filepath,0770);
8471: }
8472: }
8473: my $fh;
8474: if (!open($fh,'>'.$dest)) {
8475: &Apache::lonnet::logthis('Failed to create '.$dest);
8476: $output .= '<span class="LC_error">'.
8477: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8478: '</span><br />';
8479: } else {
8480: if (!print $fh $env{'form.embedded_item_'.$i}) {
8481: &Apache::lonnet::logthis('Failed to write to '.$dest);
8482: $output .= '<span class="LC_error">'.
8483: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8484: '</span><br />';
8485: } else {
8486: if ($context eq 'testbank') {
8487: $output .= &mt('Embedded file uploaded successfully:').
8488: ' <a href="'.$url.'">'.
8489: $orig_uploaded_filename.'</a><br />';
8490: } else {
1.705 tempelho 8491: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8492: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8493: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8494: }
8495: }
8496: close($fh);
8497: }
8498: }
8499: }
8500: return $output;
8501: }
8502:
8503: sub check_for_existing {
8504: my ($path,$fname,$element) = @_;
8505: my ($state,$msg);
8506: if (-d $path.'/'.$fname) {
8507: $state = 'exists';
8508: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8509: } elsif (-e $path.'/'.$fname) {
8510: $state = 'exists';
8511: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8512: }
8513: if ($state eq 'exists') {
8514: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8515: }
8516: return ($state,$msg);
8517: }
8518:
8519: sub check_for_upload {
8520: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8521: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8522: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8523: my $getpropath = 1;
8524: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8525: $getpropath);
8526: my $found_file = 0;
8527: my $locked_file = 0;
8528: foreach my $line (@dir_list) {
8529: my ($file_name)=split(/\&/,$line,2);
8530: if ($file_name eq $fname){
8531: $file_name = $path.$file_name;
8532: if ($group ne '') {
8533: $file_name = $group.$file_name;
8534: }
8535: $found_file = 1;
8536: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8537: $locked_file = 1;
8538: }
8539: }
8540: }
8541: if (($current_disk_usage + $filesize) > $disk_quota){
8542: my $msg = '<span class="LC_error">'.
8543: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8544: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8545: return ('will_exceed_quota',$msg);
8546: } elsif ($found_file) {
8547: if ($locked_file) {
8548: my $msg = '<span class="LC_error">';
8549: $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>');
8550: $msg .= '</span><br />';
8551: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8552: return ('file_locked',$msg);
8553: } else {
8554: my $msg = '<span class="LC_error">';
8555: $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'});
8556: $msg .= '</span>';
8557: $msg .= '<br />';
8558: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8559: return ('file_exists',$msg);
8560: }
8561: }
8562: }
8563:
1.31 albertel 8564:
1.41 ng 8565: =pod
1.45 matthew 8566:
1.464 albertel 8567: =back
1.41 ng 8568:
1.112 bowersj2 8569: =head1 CSV Upload/Handling functions
1.38 albertel 8570:
1.41 ng 8571: =over 4
8572:
1.648 raeburn 8573: =item * &upfile_store($r)
1.41 ng 8574:
8575: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8576: needs $env{'form.upfile'}
1.41 ng 8577: returns $datatoken to be put into hidden field
8578:
8579: =cut
1.31 albertel 8580:
8581: sub upfile_store {
8582: my $r=shift;
1.258 albertel 8583: $env{'form.upfile'}=~s/\r/\n/gs;
8584: $env{'form.upfile'}=~s/\f/\n/gs;
8585: $env{'form.upfile'}=~s/\n+/\n/gs;
8586: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8587:
1.258 albertel 8588: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8589: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8590: {
1.158 raeburn 8591: my $datafile = $r->dir_config('lonDaemons').
8592: '/tmp/'.$datatoken.'.tmp';
8593: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8594: print $fh $env{'form.upfile'};
1.158 raeburn 8595: close($fh);
8596: }
1.31 albertel 8597: }
8598: return $datatoken;
8599: }
8600:
1.56 matthew 8601: =pod
8602:
1.648 raeburn 8603: =item * &load_tmp_file($r)
1.41 ng 8604:
8605: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8606: needs $env{'form.datatoken'},
8607: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8608:
8609: =cut
1.31 albertel 8610:
8611: sub load_tmp_file {
8612: my $r=shift;
8613: my @studentdata=();
8614: {
1.158 raeburn 8615: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8616: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8617: if ( open(my $fh,"<$studentfile") ) {
8618: @studentdata=<$fh>;
8619: close($fh);
8620: }
1.31 albertel 8621: }
1.258 albertel 8622: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8623: }
8624:
1.56 matthew 8625: =pod
8626:
1.648 raeburn 8627: =item * &upfile_record_sep()
1.41 ng 8628:
8629: Separate uploaded file into records
8630: returns array of records,
1.258 albertel 8631: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8632:
8633: =cut
1.31 albertel 8634:
8635: sub upfile_record_sep {
1.258 albertel 8636: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8637: } else {
1.248 albertel 8638: my @records;
1.258 albertel 8639: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8640: if ($line=~/^\s*$/) { next; }
8641: push(@records,$line);
8642: }
8643: return @records;
1.31 albertel 8644: }
8645: }
8646:
1.56 matthew 8647: =pod
8648:
1.648 raeburn 8649: =item * &record_sep($record)
1.41 ng 8650:
1.258 albertel 8651: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8652:
8653: =cut
8654:
1.263 www 8655: sub takeleft {
8656: my $index=shift;
8657: return substr('0000'.$index,-4,4);
8658: }
8659:
1.31 albertel 8660: sub record_sep {
8661: my $record=shift;
8662: my %components=();
1.258 albertel 8663: if ($env{'form.upfiletype'} eq 'xml') {
8664: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8665: my $i=0;
1.356 albertel 8666: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8667: $field=~s/^(\"|\')//;
8668: $field=~s/(\"|\')$//;
1.263 www 8669: $components{&takeleft($i)}=$field;
1.31 albertel 8670: $i++;
8671: }
1.258 albertel 8672: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8673: my $i=0;
1.356 albertel 8674: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8675: $field=~s/^(\"|\')//;
8676: $field=~s/(\"|\')$//;
1.263 www 8677: $components{&takeleft($i)}=$field;
1.31 albertel 8678: $i++;
8679: }
8680: } else {
1.561 www 8681: my $separator=',';
1.480 banghart 8682: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8683: $separator=';';
1.480 banghart 8684: }
1.31 albertel 8685: my $i=0;
1.561 www 8686: # the character we are looking for to indicate the end of a quote or a record
8687: my $looking_for=$separator;
8688: # do not add the characters to the fields
8689: my $ignore=0;
8690: # we just encountered a separator (or the beginning of the record)
8691: my $just_found_separator=1;
8692: # store the field we are working on here
8693: my $field='';
8694: # work our way through all characters in record
8695: foreach my $character ($record=~/(.)/g) {
8696: if ($character eq $looking_for) {
8697: if ($character ne $separator) {
8698: # Found the end of a quote, again looking for separator
8699: $looking_for=$separator;
8700: $ignore=1;
8701: } else {
8702: # Found a separator, store away what we got
8703: $components{&takeleft($i)}=$field;
8704: $i++;
8705: $just_found_separator=1;
8706: $ignore=0;
8707: $field='';
8708: }
8709: next;
8710: }
8711: # single or double quotation marks after a separator indicate beginning of a quote
8712: # we are now looking for the end of the quote and need to ignore separators
8713: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8714: $looking_for=$character;
8715: next;
8716: }
8717: # ignore would be true after we reached the end of a quote
8718: if ($ignore) { next; }
8719: if (($just_found_separator) && ($character=~/\s/)) { next; }
8720: $field.=$character;
8721: $just_found_separator=0;
1.31 albertel 8722: }
1.561 www 8723: # catch the very last entry, since we never encountered the separator
8724: $components{&takeleft($i)}=$field;
1.31 albertel 8725: }
8726: return %components;
8727: }
8728:
1.144 matthew 8729: ######################################################
8730: ######################################################
8731:
1.56 matthew 8732: =pod
8733:
1.648 raeburn 8734: =item * &upfile_select_html()
1.41 ng 8735:
1.144 matthew 8736: Return HTML code to select a file from the users machine and specify
8737: the file type.
1.41 ng 8738:
8739: =cut
8740:
1.144 matthew 8741: ######################################################
8742: ######################################################
1.31 albertel 8743: sub upfile_select_html {
1.144 matthew 8744: my %Types = (
8745: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8746: semisv => &mt('Semicolon separated values'),
1.144 matthew 8747: space => &mt('Space separated'),
8748: tab => &mt('Tabulator separated'),
8749: # xml => &mt('HTML/XML'),
8750: );
8751: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8752: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8753: foreach my $type (sort(keys(%Types))) {
8754: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8755: }
8756: $Str .= "</select>\n";
8757: return $Str;
1.31 albertel 8758: }
8759:
1.301 albertel 8760: sub get_samples {
8761: my ($records,$toget) = @_;
8762: my @samples=({});
8763: my $got=0;
8764: foreach my $rec (@$records) {
8765: my %temp = &record_sep($rec);
8766: if (! grep(/\S/, values(%temp))) { next; }
8767: if (%temp) {
8768: $samples[$got]=\%temp;
8769: $got++;
8770: if ($got == $toget) { last; }
8771: }
8772: }
8773: return \@samples;
8774: }
8775:
1.144 matthew 8776: ######################################################
8777: ######################################################
8778:
1.56 matthew 8779: =pod
8780:
1.648 raeburn 8781: =item * &csv_print_samples($r,$records)
1.41 ng 8782:
8783: Prints a table of sample values from each column uploaded $r is an
8784: Apache Request ref, $records is an arrayref from
8785: &Apache::loncommon::upfile_record_sep
8786:
8787: =cut
8788:
1.144 matthew 8789: ######################################################
8790: ######################################################
1.31 albertel 8791: sub csv_print_samples {
8792: my ($r,$records) = @_;
1.662 bisitz 8793: my $samples = &get_samples($records,5);
1.301 albertel 8794:
1.594 raeburn 8795: $r->print(&mt('Samples').'<br />'.&start_data_table().
8796: &start_data_table_header_row());
1.356 albertel 8797: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8798: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8799: $r->print(&end_data_table_header_row());
1.301 albertel 8800: foreach my $hash (@$samples) {
1.594 raeburn 8801: $r->print(&start_data_table_row());
1.356 albertel 8802: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8803: $r->print('<td>');
1.356 albertel 8804: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8805: $r->print('</td>');
8806: }
1.594 raeburn 8807: $r->print(&end_data_table_row());
1.31 albertel 8808: }
1.594 raeburn 8809: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8810: }
8811:
1.144 matthew 8812: ######################################################
8813: ######################################################
8814:
1.56 matthew 8815: =pod
8816:
1.648 raeburn 8817: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8818:
8819: Prints a table to create associations between values and table columns.
1.144 matthew 8820:
1.41 ng 8821: $r is an Apache Request ref,
8822: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8823: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8824:
8825: =cut
8826:
1.144 matthew 8827: ######################################################
8828: ######################################################
1.31 albertel 8829: sub csv_print_select_table {
8830: my ($r,$records,$d) = @_;
1.301 albertel 8831: my $i=0;
8832: my $samples = &get_samples($records,1);
1.144 matthew 8833: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8834: &start_data_table().&start_data_table_header_row().
1.144 matthew 8835: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8836: '<th>'.&mt('Column').'</th>'.
8837: &end_data_table_header_row()."\n");
1.356 albertel 8838: foreach my $array_ref (@$d) {
8839: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8840: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8841:
1.875 bisitz 8842: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8843: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8844: $r->print('<option value="none"></option>');
1.356 albertel 8845: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8846: $r->print('<option value="'.$sample.'"'.
8847: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8848: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8849: }
1.594 raeburn 8850: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8851: $i++;
8852: }
1.594 raeburn 8853: $r->print(&end_data_table());
1.31 albertel 8854: $i--;
8855: return $i;
8856: }
1.56 matthew 8857:
1.144 matthew 8858: ######################################################
8859: ######################################################
8860:
1.56 matthew 8861: =pod
1.31 albertel 8862:
1.648 raeburn 8863: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8864:
8865: Prints a table of sample values from the upload and can make associate samples to internal names.
8866:
8867: $r is an Apache Request ref,
8868: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8869: $d is an array of 2 element arrays (internal name, displayed name)
8870:
8871: =cut
8872:
1.144 matthew 8873: ######################################################
8874: ######################################################
1.31 albertel 8875: sub csv_samples_select_table {
8876: my ($r,$records,$d) = @_;
8877: my $i=0;
1.144 matthew 8878: #
1.662 bisitz 8879: my $max_samples = 5;
8880: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8881: $r->print(&start_data_table().
8882: &start_data_table_header_row().'<th>'.
8883: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8884: &end_data_table_header_row());
1.301 albertel 8885:
8886: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8887: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8888: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8889: foreach my $option (@$d) {
8890: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8891: $r->print('<option value="'.$value.'"'.
1.253 albertel 8892: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8893: $display.'</option>');
1.31 albertel 8894: }
8895: $r->print('</select></td><td>');
1.662 bisitz 8896: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8897: if (defined($samples->[$line]{$key})) {
8898: $r->print($samples->[$line]{$key}."<br />\n");
8899: }
8900: }
1.594 raeburn 8901: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8902: $i++;
8903: }
1.594 raeburn 8904: $r->print(&end_data_table());
1.31 albertel 8905: $i--;
8906: return($i);
1.115 matthew 8907: }
8908:
1.144 matthew 8909: ######################################################
8910: ######################################################
8911:
1.115 matthew 8912: =pod
8913:
1.648 raeburn 8914: =item * &clean_excel_name($name)
1.115 matthew 8915:
8916: Returns a replacement for $name which does not contain any illegal characters.
8917:
8918: =cut
8919:
1.144 matthew 8920: ######################################################
8921: ######################################################
1.115 matthew 8922: sub clean_excel_name {
8923: my ($name) = @_;
8924: $name =~ s/[:\*\?\/\\]//g;
8925: if (length($name) > 31) {
8926: $name = substr($name,0,31);
8927: }
8928: return $name;
1.25 albertel 8929: }
1.84 albertel 8930:
1.85 albertel 8931: =pod
8932:
1.648 raeburn 8933: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8934:
8935: Returns either 1 or undef
8936:
8937: 1 if the part is to be hidden, undef if it is to be shown
8938:
8939: Arguments are:
8940:
8941: $id the id of the part to be checked
8942: $symb, optional the symb of the resource to check
8943: $udom, optional the domain of the user to check for
8944: $uname, optional the username of the user to check for
8945:
8946: =cut
1.84 albertel 8947:
8948: sub check_if_partid_hidden {
8949: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8950: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8951: $symb,$udom,$uname);
1.141 albertel 8952: my $truth=1;
8953: #if the string starts with !, then the list is the list to show not hide
8954: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8955: my @hiddenlist=split(/,/,$hiddenparts);
8956: foreach my $checkid (@hiddenlist) {
1.141 albertel 8957: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8958: }
1.141 albertel 8959: return !$truth;
1.84 albertel 8960: }
1.127 matthew 8961:
1.138 matthew 8962:
8963: ############################################################
8964: ############################################################
8965:
8966: =pod
8967:
1.157 matthew 8968: =back
8969:
1.138 matthew 8970: =head1 cgi-bin script and graphing routines
8971:
1.157 matthew 8972: =over 4
8973:
1.648 raeburn 8974: =item * &get_cgi_id()
1.138 matthew 8975:
8976: Inputs: none
8977:
8978: Returns an id which can be used to pass environment variables
8979: to various cgi-bin scripts. These environment variables will
8980: be removed from the users environment after a given time by
8981: the routine &Apache::lonnet::transfer_profile_to_env.
8982:
8983: =cut
8984:
8985: ############################################################
8986: ############################################################
1.152 albertel 8987: my $uniq=0;
1.136 matthew 8988: sub get_cgi_id {
1.154 albertel 8989: $uniq=($uniq+1)%100000;
1.280 albertel 8990: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8991: }
8992:
1.127 matthew 8993: ############################################################
8994: ############################################################
8995:
8996: =pod
8997:
1.648 raeburn 8998: =item * &DrawBarGraph()
1.127 matthew 8999:
1.138 matthew 9000: Facilitates the plotting of data in a (stacked) bar graph.
9001: Puts plot definition data into the users environment in order for
9002: graph.png to plot it. Returns an <img> tag for the plot.
9003: The bars on the plot are labeled '1','2',...,'n'.
9004:
9005: Inputs:
9006:
9007: =over 4
9008:
9009: =item $Title: string, the title of the plot
9010:
9011: =item $xlabel: string, text describing the X-axis of the plot
9012:
9013: =item $ylabel: string, text describing the Y-axis of the plot
9014:
9015: =item $Max: scalar, the maximum Y value to use in the plot
9016: If $Max is < any data point, the graph will not be rendered.
9017:
1.140 matthew 9018: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9019: they are plotted. If undefined, default values will be used.
9020:
1.178 matthew 9021: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9022:
1.138 matthew 9023: =item @Values: An array of array references. Each array reference holds data
9024: to be plotted in a stacked bar chart.
9025:
1.239 matthew 9026: =item If the final element of @Values is a hash reference the key/value
9027: pairs will be added to the graph definition.
9028:
1.138 matthew 9029: =back
9030:
9031: Returns:
9032:
9033: An <img> tag which references graph.png and the appropriate identifying
9034: information for the plot.
9035:
1.127 matthew 9036: =cut
9037:
9038: ############################################################
9039: ############################################################
1.134 matthew 9040: sub DrawBarGraph {
1.178 matthew 9041: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9042: #
9043: if (! defined($colors)) {
9044: $colors = ['#33ff00',
9045: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9046: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9047: ];
9048: }
1.228 matthew 9049: my $extra_settings = {};
9050: if (ref($Values[-1]) eq 'HASH') {
9051: $extra_settings = pop(@Values);
9052: }
1.127 matthew 9053: #
1.136 matthew 9054: my $identifier = &get_cgi_id();
9055: my $id = 'cgi.'.$identifier;
1.129 matthew 9056: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9057: return '';
9058: }
1.225 matthew 9059: #
9060: my @Labels;
9061: if (defined($labels)) {
9062: @Labels = @$labels;
9063: } else {
9064: for (my $i=0;$i<@{$Values[0]};$i++) {
9065: push (@Labels,$i+1);
9066: }
9067: }
9068: #
1.129 matthew 9069: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9070: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9071: my %ValuesHash;
9072: my $NumSets=1;
9073: foreach my $array (@Values) {
9074: next if (! ref($array));
1.136 matthew 9075: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9076: join(',',@$array);
1.129 matthew 9077: }
1.127 matthew 9078: #
1.136 matthew 9079: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9080: if ($NumBars < 3) {
9081: $width = 120+$NumBars*32;
1.220 matthew 9082: $xskip = 1;
1.225 matthew 9083: $bar_width = 30;
9084: } elsif ($NumBars < 5) {
9085: $width = 120+$NumBars*20;
9086: $xskip = 1;
9087: $bar_width = 20;
1.220 matthew 9088: } elsif ($NumBars < 10) {
1.136 matthew 9089: $width = 120+$NumBars*15;
9090: $xskip = 1;
9091: $bar_width = 15;
9092: } elsif ($NumBars <= 25) {
9093: $width = 120+$NumBars*11;
9094: $xskip = 5;
9095: $bar_width = 8;
9096: } elsif ($NumBars <= 50) {
9097: $width = 120+$NumBars*8;
9098: $xskip = 5;
9099: $bar_width = 4;
9100: } else {
9101: $width = 120+$NumBars*8;
9102: $xskip = 5;
9103: $bar_width = 4;
9104: }
9105: #
1.137 matthew 9106: $Max = 1 if ($Max < 1);
9107: if ( int($Max) < $Max ) {
9108: $Max++;
9109: $Max = int($Max);
9110: }
1.127 matthew 9111: $Title = '' if (! defined($Title));
9112: $xlabel = '' if (! defined($xlabel));
9113: $ylabel = '' if (! defined($ylabel));
1.369 www 9114: $ValuesHash{$id.'.title'} = &escape($Title);
9115: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9116: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9117: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9118: $ValuesHash{$id.'.NumBars'} = $NumBars;
9119: $ValuesHash{$id.'.NumSets'} = $NumSets;
9120: $ValuesHash{$id.'.PlotType'} = 'bar';
9121: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9122: $ValuesHash{$id.'.height'} = $height;
9123: $ValuesHash{$id.'.width'} = $width;
9124: $ValuesHash{$id.'.xskip'} = $xskip;
9125: $ValuesHash{$id.'.bar_width'} = $bar_width;
9126: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9127: #
1.228 matthew 9128: # Deal with other parameters
9129: while (my ($key,$value) = each(%$extra_settings)) {
9130: $ValuesHash{$id.'.'.$key} = $value;
9131: }
9132: #
1.646 raeburn 9133: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9134: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9135: }
9136:
9137: ############################################################
9138: ############################################################
9139:
9140: =pod
9141:
1.648 raeburn 9142: =item * &DrawXYGraph()
1.137 matthew 9143:
1.138 matthew 9144: Facilitates the plotting of data in an XY graph.
9145: Puts plot definition data into the users environment in order for
9146: graph.png to plot it. Returns an <img> tag for the plot.
9147:
9148: Inputs:
9149:
9150: =over 4
9151:
9152: =item $Title: string, the title of the plot
9153:
9154: =item $xlabel: string, text describing the X-axis of the plot
9155:
9156: =item $ylabel: string, text describing the Y-axis of the plot
9157:
9158: =item $Max: scalar, the maximum Y value to use in the plot
9159: If $Max is < any data point, the graph will not be rendered.
9160:
9161: =item $colors: Array ref containing the hex color codes for the data to be
9162: plotted in. If undefined, default values will be used.
9163:
9164: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9165:
9166: =item $Ydata: Array ref containing Array refs.
1.185 www 9167: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9168:
9169: =item %Values: hash indicating or overriding any default values which are
9170: passed to graph.png.
9171: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9172:
9173: =back
9174:
9175: Returns:
9176:
9177: An <img> tag which references graph.png and the appropriate identifying
9178: information for the plot.
9179:
1.137 matthew 9180: =cut
9181:
9182: ############################################################
9183: ############################################################
9184: sub DrawXYGraph {
9185: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9186: #
9187: # Create the identifier for the graph
9188: my $identifier = &get_cgi_id();
9189: my $id = 'cgi.'.$identifier;
9190: #
9191: $Title = '' if (! defined($Title));
9192: $xlabel = '' if (! defined($xlabel));
9193: $ylabel = '' if (! defined($ylabel));
9194: my %ValuesHash =
9195: (
1.369 www 9196: $id.'.title' => &escape($Title),
9197: $id.'.xlabel' => &escape($xlabel),
9198: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9199: $id.'.y_max_value'=> $Max,
9200: $id.'.labels' => join(',',@$Xlabels),
9201: $id.'.PlotType' => 'XY',
9202: );
9203: #
9204: if (defined($colors) && ref($colors) eq 'ARRAY') {
9205: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9206: }
9207: #
9208: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9209: return '';
9210: }
9211: my $NumSets=1;
1.138 matthew 9212: foreach my $array (@{$Ydata}){
1.137 matthew 9213: next if (! ref($array));
9214: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9215: }
1.138 matthew 9216: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9217: #
9218: # Deal with other parameters
9219: while (my ($key,$value) = each(%Values)) {
9220: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9221: }
9222: #
1.646 raeburn 9223: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9224: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9225: }
9226:
9227: ############################################################
9228: ############################################################
9229:
9230: =pod
9231:
1.648 raeburn 9232: =item * &DrawXYYGraph()
1.138 matthew 9233:
9234: Facilitates the plotting of data in an XY graph with two Y axes.
9235: Puts plot definition data into the users environment in order for
9236: graph.png to plot it. Returns an <img> tag for the plot.
9237:
9238: Inputs:
9239:
9240: =over 4
9241:
9242: =item $Title: string, the title of the plot
9243:
9244: =item $xlabel: string, text describing the X-axis of the plot
9245:
9246: =item $ylabel: string, text describing the Y-axis of the plot
9247:
9248: =item $colors: Array ref containing the hex color codes for the data to be
9249: plotted in. If undefined, default values will be used.
9250:
9251: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9252:
9253: =item $Ydata1: The first data set
9254:
9255: =item $Min1: The minimum value of the left Y-axis
9256:
9257: =item $Max1: The maximum value of the left Y-axis
9258:
9259: =item $Ydata2: The second data set
9260:
9261: =item $Min2: The minimum value of the right Y-axis
9262:
9263: =item $Max2: The maximum value of the left Y-axis
9264:
9265: =item %Values: hash indicating or overriding any default values which are
9266: passed to graph.png.
9267: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9268:
9269: =back
9270:
9271: Returns:
9272:
9273: An <img> tag which references graph.png and the appropriate identifying
9274: information for the plot.
1.136 matthew 9275:
9276: =cut
9277:
9278: ############################################################
9279: ############################################################
1.137 matthew 9280: sub DrawXYYGraph {
9281: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9282: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9283: #
9284: # Create the identifier for the graph
9285: my $identifier = &get_cgi_id();
9286: my $id = 'cgi.'.$identifier;
9287: #
9288: $Title = '' if (! defined($Title));
9289: $xlabel = '' if (! defined($xlabel));
9290: $ylabel = '' if (! defined($ylabel));
9291: my %ValuesHash =
9292: (
1.369 www 9293: $id.'.title' => &escape($Title),
9294: $id.'.xlabel' => &escape($xlabel),
9295: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9296: $id.'.labels' => join(',',@$Xlabels),
9297: $id.'.PlotType' => 'XY',
9298: $id.'.NumSets' => 2,
1.137 matthew 9299: $id.'.two_axes' => 1,
9300: $id.'.y1_max_value' => $Max1,
9301: $id.'.y1_min_value' => $Min1,
9302: $id.'.y2_max_value' => $Max2,
9303: $id.'.y2_min_value' => $Min2,
1.136 matthew 9304: );
9305: #
1.137 matthew 9306: if (defined($colors) && ref($colors) eq 'ARRAY') {
9307: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9308: }
9309: #
9310: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9311: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9312: return '';
9313: }
9314: my $NumSets=1;
1.137 matthew 9315: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9316: next if (! ref($array));
9317: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9318: }
9319: #
9320: # Deal with other parameters
9321: while (my ($key,$value) = each(%Values)) {
9322: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9323: }
9324: #
1.646 raeburn 9325: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9326: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9327: }
9328:
9329: ############################################################
9330: ############################################################
9331:
9332: =pod
9333:
1.157 matthew 9334: =back
9335:
1.139 matthew 9336: =head1 Statistics helper routines?
9337:
9338: Bad place for them but what the hell.
9339:
1.157 matthew 9340: =over 4
9341:
1.648 raeburn 9342: =item * &chartlink()
1.139 matthew 9343:
9344: Returns a link to the chart for a specific student.
9345:
9346: Inputs:
9347:
9348: =over 4
9349:
9350: =item $linktext: The text of the link
9351:
9352: =item $sname: The students username
9353:
9354: =item $sdomain: The students domain
9355:
9356: =back
9357:
1.157 matthew 9358: =back
9359:
1.139 matthew 9360: =cut
9361:
9362: ############################################################
9363: ############################################################
9364: sub chartlink {
9365: my ($linktext, $sname, $sdomain) = @_;
9366: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9367: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9368: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9369: '">'.$linktext.'</a>';
1.153 matthew 9370: }
9371:
9372: #######################################################
9373: #######################################################
9374:
9375: =pod
9376:
9377: =head1 Course Environment Routines
1.157 matthew 9378:
9379: =over 4
1.153 matthew 9380:
1.648 raeburn 9381: =item * &restore_course_settings()
1.153 matthew 9382:
1.648 raeburn 9383: =item * &store_course_settings()
1.153 matthew 9384:
9385: Restores/Store indicated form parameters from the course environment.
9386: Will not overwrite existing values of the form parameters.
9387:
9388: Inputs:
9389: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9390:
9391: a hash ref describing the data to be stored. For example:
9392:
9393: %Save_Parameters = ('Status' => 'scalar',
9394: 'chartoutputmode' => 'scalar',
9395: 'chartoutputdata' => 'scalar',
9396: 'Section' => 'array',
1.373 raeburn 9397: 'Group' => 'array',
1.153 matthew 9398: 'StudentData' => 'array',
9399: 'Maps' => 'array');
9400:
9401: Returns: both routines return nothing
9402:
1.631 raeburn 9403: =back
9404:
1.153 matthew 9405: =cut
9406:
9407: #######################################################
9408: #######################################################
9409: sub store_course_settings {
1.496 albertel 9410: return &store_settings($env{'request.course.id'},@_);
9411: }
9412:
9413: sub store_settings {
1.153 matthew 9414: # save to the environment
9415: # appenv the same items, just to be safe
1.300 albertel 9416: my $udom = $env{'user.domain'};
9417: my $uname = $env{'user.name'};
1.496 albertel 9418: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9419: my %SaveHash;
9420: my %AppHash;
9421: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9422: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9423: my $envname = 'environment.'.$basename;
1.258 albertel 9424: if (exists($env{'form.'.$setting})) {
1.153 matthew 9425: # Save this value away
9426: if ($type eq 'scalar' &&
1.258 albertel 9427: (! exists($env{$envname}) ||
9428: $env{$envname} ne $env{'form.'.$setting})) {
9429: $SaveHash{$basename} = $env{'form.'.$setting};
9430: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9431: } elsif ($type eq 'array') {
9432: my $stored_form;
1.258 albertel 9433: if (ref($env{'form.'.$setting})) {
1.153 matthew 9434: $stored_form = join(',',
9435: map {
1.369 www 9436: &escape($_);
1.258 albertel 9437: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9438: } else {
9439: $stored_form =
1.369 www 9440: &escape($env{'form.'.$setting});
1.153 matthew 9441: }
9442: # Determine if the array contents are the same.
1.258 albertel 9443: if ($stored_form ne $env{$envname}) {
1.153 matthew 9444: $SaveHash{$basename} = $stored_form;
9445: $AppHash{$envname} = $stored_form;
9446: }
9447: }
9448: }
9449: }
9450: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9451: $udom,$uname);
1.153 matthew 9452: if ($put_result !~ /^(ok|delayed)/) {
9453: &Apache::lonnet::logthis('unable to save form parameters, '.
9454: 'got error:'.$put_result);
9455: }
9456: # Make sure these settings stick around in this session, too
1.646 raeburn 9457: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9458: return;
9459: }
9460:
9461: sub restore_course_settings {
1.499 albertel 9462: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9463: }
9464:
9465: sub restore_settings {
9466: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9467: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9468: next if (exists($env{'form.'.$setting}));
1.496 albertel 9469: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9470: '.'.$setting;
1.258 albertel 9471: if (exists($env{$envname})) {
1.153 matthew 9472: if ($type eq 'scalar') {
1.258 albertel 9473: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9474: } elsif ($type eq 'array') {
1.258 albertel 9475: $env{'form.'.$setting} = [
1.153 matthew 9476: map {
1.369 www 9477: &unescape($_);
1.258 albertel 9478: } split(',',$env{$envname})
1.153 matthew 9479: ];
9480: }
9481: }
9482: }
1.127 matthew 9483: }
9484:
1.618 raeburn 9485: #######################################################
9486: #######################################################
9487:
9488: =pod
9489:
9490: =head1 Domain E-mail Routines
9491:
9492: =over 4
9493:
1.648 raeburn 9494: =item * &build_recipient_list()
1.618 raeburn 9495:
1.884 raeburn 9496: Build recipient lists for five types of e-mail:
1.766 raeburn 9497: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9498: (d) Help requests, (e) Course requests needing approval, generated by
9499: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9500: loncoursequeueadmin.pm respectively.
1.618 raeburn 9501:
9502: Inputs:
1.619 raeburn 9503: defmail (scalar - email address of default recipient),
1.618 raeburn 9504: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9505: defdom (domain for which to retrieve configuration settings),
9506: origmail (scalar - email address of recipient from loncapa.conf,
9507: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9508:
1.655 raeburn 9509: Returns: comma separated list of addresses to which to send e-mail.
9510:
9511: =back
1.618 raeburn 9512:
9513: =cut
9514:
9515: ############################################################
9516: ############################################################
9517: sub build_recipient_list {
1.619 raeburn 9518: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9519: my @recipients;
9520: my $otheremails;
9521: my %domconfig =
9522: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9523: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9524: if (exists($domconfig{'contacts'}{$mailing})) {
9525: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9526: my @contacts = ('adminemail','supportemail');
9527: foreach my $item (@contacts) {
9528: if ($domconfig{'contacts'}{$mailing}{$item}) {
9529: my $addr = $domconfig{'contacts'}{$item};
9530: if (!grep(/^\Q$addr\E$/,@recipients)) {
9531: push(@recipients,$addr);
9532: }
1.619 raeburn 9533: }
1.766 raeburn 9534: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9535: }
9536: }
1.766 raeburn 9537: } elsif ($origmail ne '') {
9538: push(@recipients,$origmail);
1.618 raeburn 9539: }
1.619 raeburn 9540: } elsif ($origmail ne '') {
9541: push(@recipients,$origmail);
1.618 raeburn 9542: }
1.688 raeburn 9543: if (defined($defmail)) {
9544: if ($defmail ne '') {
9545: push(@recipients,$defmail);
9546: }
1.618 raeburn 9547: }
9548: if ($otheremails) {
1.619 raeburn 9549: my @others;
9550: if ($otheremails =~ /,/) {
9551: @others = split(/,/,$otheremails);
1.618 raeburn 9552: } else {
1.619 raeburn 9553: push(@others,$otheremails);
9554: }
9555: foreach my $addr (@others) {
9556: if (!grep(/^\Q$addr\E$/,@recipients)) {
9557: push(@recipients,$addr);
9558: }
1.618 raeburn 9559: }
9560: }
1.619 raeburn 9561: my $recipientlist = join(',',@recipients);
1.618 raeburn 9562: return $recipientlist;
9563: }
9564:
1.127 matthew 9565: ############################################################
9566: ############################################################
1.154 albertel 9567:
1.655 raeburn 9568: =pod
9569:
9570: =head1 Course Catalog Routines
9571:
9572: =over 4
9573:
9574: =item * &gather_categories()
9575:
9576: Converts category definitions - keys of categories hash stored in
9577: coursecategories in configuration.db on the primary library server in a
9578: domain - to an array. Also generates javascript and idx hash used to
9579: generate Domain Coordinator interface for editing Course Categories.
9580:
9581: Inputs:
1.663 raeburn 9582:
1.655 raeburn 9583: categories (reference to hash of category definitions).
1.663 raeburn 9584:
1.655 raeburn 9585: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9586: categories and subcategories).
1.663 raeburn 9587:
1.655 raeburn 9588: idx (reference to hash of counters used in Domain Coordinator interface for
9589: editing Course Categories).
1.663 raeburn 9590:
1.655 raeburn 9591: jsarray (reference to array of categories used to create Javascript arrays for
9592: Domain Coordinator interface for editing Course Categories).
9593:
9594: Returns: nothing
9595:
9596: Side effects: populates cats, idx and jsarray.
9597:
9598: =cut
9599:
9600: sub gather_categories {
9601: my ($categories,$cats,$idx,$jsarray) = @_;
9602: my %counters;
9603: my $num = 0;
9604: foreach my $item (keys(%{$categories})) {
9605: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9606: if ($container eq '' && $depth == 0) {
9607: $cats->[$depth][$categories->{$item}] = $cat;
9608: } else {
9609: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9610: }
9611: my ($escitem,$tail) = split(/:/,$item,2);
9612: if ($counters{$tail} eq '') {
9613: $counters{$tail} = $num;
9614: $num ++;
9615: }
9616: if (ref($idx) eq 'HASH') {
9617: $idx->{$item} = $counters{$tail};
9618: }
9619: if (ref($jsarray) eq 'ARRAY') {
9620: push(@{$jsarray->[$counters{$tail}]},$item);
9621: }
9622: }
9623: return;
9624: }
9625:
9626: =pod
9627:
9628: =item * &extract_categories()
9629:
9630: Used to generate breadcrumb trails for course categories.
9631:
9632: Inputs:
1.663 raeburn 9633:
1.655 raeburn 9634: categories (reference to hash of category definitions).
1.663 raeburn 9635:
1.655 raeburn 9636: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9637: categories and subcategories).
1.663 raeburn 9638:
1.655 raeburn 9639: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9640:
1.655 raeburn 9641: allitems (reference to hash - key is category key
9642: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9643:
1.655 raeburn 9644: idx (reference to hash of counters used in Domain Coordinator interface for
9645: editing Course Categories).
1.663 raeburn 9646:
1.655 raeburn 9647: jsarray (reference to array of categories used to create Javascript arrays for
9648: Domain Coordinator interface for editing Course Categories).
9649:
1.665 raeburn 9650: subcats (reference to hash of arrays containing all subcategories within each
9651: category, -recursive)
9652:
1.655 raeburn 9653: Returns: nothing
9654:
9655: Side effects: populates trails and allitems hash references.
9656:
9657: =cut
9658:
9659: sub extract_categories {
1.665 raeburn 9660: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9661: if (ref($categories) eq 'HASH') {
9662: &gather_categories($categories,$cats,$idx,$jsarray);
9663: if (ref($cats->[0]) eq 'ARRAY') {
9664: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9665: my $name = $cats->[0][$i];
9666: my $item = &escape($name).'::0';
9667: my $trailstr;
9668: if ($name eq 'instcode') {
9669: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 9670: } elsif ($name eq 'communities') {
9671: $trailstr = &mt('Communities');
1.655 raeburn 9672: } else {
9673: $trailstr = $name;
9674: }
9675: if ($allitems->{$item} eq '') {
9676: push(@{$trails},$trailstr);
9677: $allitems->{$item} = scalar(@{$trails})-1;
9678: }
9679: my @parents = ($name);
9680: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9681: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9682: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9683: if (ref($subcats) eq 'HASH') {
9684: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9685: }
9686: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9687: }
9688: } else {
9689: if (ref($subcats) eq 'HASH') {
9690: $subcats->{$item} = [];
1.655 raeburn 9691: }
9692: }
9693: }
9694: }
9695: }
9696: return;
9697: }
9698:
9699: =pod
9700:
9701: =item *&recurse_categories()
9702:
9703: Recursively used to generate breadcrumb trails for course categories.
9704:
9705: Inputs:
1.663 raeburn 9706:
1.655 raeburn 9707: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9708: categories and subcategories).
1.663 raeburn 9709:
1.655 raeburn 9710: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9711:
9712: category (current course category, for which breadcrumb trail is being generated).
9713:
9714: trails (reference to array of breadcrumb trails for each category).
9715:
1.655 raeburn 9716: allitems (reference to hash - key is category key
9717: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9718:
1.655 raeburn 9719: parents (array containing containers directories for current category,
9720: back to top level).
9721:
9722: Returns: nothing
9723:
9724: Side effects: populates trails and allitems hash references
9725:
9726: =cut
9727:
9728: sub recurse_categories {
1.665 raeburn 9729: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9730: my $shallower = $depth - 1;
9731: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9732: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9733: my $name = $cats->[$depth]{$category}[$k];
9734: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9735: my $trailstr = join(' -> ',(@{$parents},$category));
9736: if ($allitems->{$item} eq '') {
9737: push(@{$trails},$trailstr);
9738: $allitems->{$item} = scalar(@{$trails})-1;
9739: }
9740: my $deeper = $depth+1;
9741: push(@{$parents},$category);
1.665 raeburn 9742: if (ref($subcats) eq 'HASH') {
9743: my $subcat = &escape($name).':'.$category.':'.$depth;
9744: for (my $j=@{$parents}; $j>=0; $j--) {
9745: my $higher;
9746: if ($j > 0) {
9747: $higher = &escape($parents->[$j]).':'.
9748: &escape($parents->[$j-1]).':'.$j;
9749: } else {
9750: $higher = &escape($parents->[$j]).'::'.$j;
9751: }
9752: push(@{$subcats->{$higher}},$subcat);
9753: }
9754: }
9755: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9756: $subcats);
1.655 raeburn 9757: pop(@{$parents});
9758: }
9759: } else {
9760: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9761: my $trailstr = join(' -> ',(@{$parents},$category));
9762: if ($allitems->{$item} eq '') {
9763: push(@{$trails},$trailstr);
9764: $allitems->{$item} = scalar(@{$trails})-1;
9765: }
9766: }
9767: return;
9768: }
9769:
1.663 raeburn 9770: =pod
9771:
9772: =item *&assign_categories_table()
9773:
9774: Create a datatable for display of hierarchical categories in a domain,
9775: with checkboxes to allow a course to be categorized.
9776:
9777: Inputs:
9778:
9779: cathash - reference to hash of categories defined for the domain (from
9780: configuration.db)
9781:
9782: currcat - scalar with an & separated list of categories assigned to a course.
9783:
1.919 raeburn 9784: type - scalar contains course type (Course or Community).
9785:
1.663 raeburn 9786: Returns: $output (markup to be displayed)
9787:
9788: =cut
9789:
9790: sub assign_categories_table {
1.919 raeburn 9791: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 9792: my $output;
9793: if (ref($cathash) eq 'HASH') {
9794: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9795: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9796: $maxdepth = scalar(@cats);
9797: if (@cats > 0) {
9798: my $itemcount = 0;
9799: if (ref($cats[0]) eq 'ARRAY') {
9800: my @currcategories;
9801: if ($currcat ne '') {
9802: @currcategories = split('&',$currcat);
9803: }
1.919 raeburn 9804: my $table;
1.663 raeburn 9805: for (my $i=0; $i<@{$cats[0]}; $i++) {
9806: my $parent = $cats[0][$i];
1.919 raeburn 9807: next if ($parent eq 'instcode');
9808: if ($type eq 'Community') {
9809: next unless ($parent eq 'communities');
9810: } else {
9811: next if ($parent eq 'communities');
9812: }
1.663 raeburn 9813: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9814: my $item = &escape($parent).'::0';
9815: my $checked = '';
9816: if (@currcategories > 0) {
9817: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9818: $checked = ' checked="checked"';
1.663 raeburn 9819: }
9820: }
1.919 raeburn 9821: my $parent_title = $parent;
9822: if ($parent eq 'communities') {
9823: $parent_title = &mt('Communities');
9824: }
9825: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9826: '<input type="checkbox" name="usecategory" value="'.
9827: $item.'"'.$checked.' />'.$parent_title.'</span>'.
9828: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9829: my $depth = 1;
9830: push(@path,$parent);
1.919 raeburn 9831: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 9832: pop(@path);
1.919 raeburn 9833: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 9834: $itemcount ++;
9835: }
1.919 raeburn 9836: if ($itemcount) {
9837: $output = &Apache::loncommon::start_data_table().
9838: $table.
9839: &Apache::loncommon::end_data_table();
9840: }
1.663 raeburn 9841: }
9842: }
9843: }
9844: return $output;
9845: }
9846:
9847: =pod
9848:
9849: =item *&assign_category_rows()
9850:
9851: Create a datatable row for display of nested categories in a domain,
9852: with checkboxes to allow a course to be categorized,called recursively.
9853:
9854: Inputs:
9855:
9856: itemcount - track row number for alternating colors
9857:
9858: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9859: categories and subcategories.
9860:
9861: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9862:
9863: parent - parent of current category item
9864:
9865: path - Array containing all categories back up through the hierarchy from the
9866: current category to the top level.
9867:
9868: currcategories - reference to array of current categories assigned to the course
9869:
9870: Returns: $output (markup to be displayed).
9871:
9872: =cut
9873:
9874: sub assign_category_rows {
9875: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9876: my ($text,$name,$item,$chgstr);
9877: if (ref($cats) eq 'ARRAY') {
9878: my $maxdepth = scalar(@{$cats});
9879: if (ref($cats->[$depth]) eq 'HASH') {
9880: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9881: my $numchildren = @{$cats->[$depth]{$parent}};
9882: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9883: $text .= '<td><table class="LC_datatable">';
9884: for (my $j=0; $j<$numchildren; $j++) {
9885: $name = $cats->[$depth]{$parent}[$j];
9886: $item = &escape($name).':'.&escape($parent).':'.$depth;
9887: my $deeper = $depth+1;
9888: my $checked = '';
9889: if (ref($currcategories) eq 'ARRAY') {
9890: if (@{$currcategories} > 0) {
9891: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9892: $checked = ' checked="checked"';
1.663 raeburn 9893: }
9894: }
9895: }
1.664 raeburn 9896: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9897: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9898: $item.'"'.$checked.' />'.$name.'</label></span>'.
9899: '<input type="hidden" name="catname" value="'.$name.'" />'.
9900: '</td><td>';
1.663 raeburn 9901: if (ref($path) eq 'ARRAY') {
9902: push(@{$path},$name);
9903: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9904: pop(@{$path});
9905: }
9906: $text .= '</td></tr>';
9907: }
9908: $text .= '</table></td>';
9909: }
9910: }
9911: }
9912: return $text;
9913: }
9914:
1.655 raeburn 9915: ############################################################
9916: ############################################################
9917:
9918:
1.443 albertel 9919: sub commit_customrole {
1.664 raeburn 9920: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9921: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9922: ($start?', '.&mt('starting').' '.localtime($start):'').
9923: ($end?', ending '.localtime($end):'').': <b>'.
9924: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9925: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9926: '</b><br />';
9927: return $output;
9928: }
9929:
9930: sub commit_standardrole {
1.541 raeburn 9931: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9932: my ($output,$logmsg,$linefeed);
9933: if ($context eq 'auto') {
9934: $linefeed = "\n";
9935: } else {
9936: $linefeed = "<br />\n";
9937: }
1.443 albertel 9938: if ($three eq 'st') {
1.541 raeburn 9939: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9940: $one,$two,$sec,$context);
9941: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9942: ($result eq 'unknown_course') || ($result eq 'refused')) {
9943: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9944: } else {
1.541 raeburn 9945: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9946: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9947: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9948: if ($context eq 'auto') {
9949: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9950: } else {
9951: $output .= '<b>'.$result.'</b>'.$linefeed.
9952: &mt('Add to classlist').': <b>ok</b>';
9953: }
9954: $output .= $linefeed;
1.443 albertel 9955: }
9956: } else {
9957: $output = &mt('Assigning').' '.$three.' in '.$url.
9958: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9959: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9960: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9961: if ($context eq 'auto') {
9962: $output .= $result.$linefeed;
9963: } else {
9964: $output .= '<b>'.$result.'</b>'.$linefeed;
9965: }
1.443 albertel 9966: }
9967: return $output;
9968: }
9969:
9970: sub commit_studentrole {
1.541 raeburn 9971: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9972: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9973: if ($context eq 'auto') {
9974: $linefeed = "\n";
9975: } else {
9976: $linefeed = '<br />'."\n";
9977: }
1.443 albertel 9978: if (defined($one) && defined($two)) {
9979: my $cid=$one.'_'.$two;
9980: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9981: my $secchange = 0;
9982: my $expire_role_result;
9983: my $modify_section_result;
1.628 raeburn 9984: if ($oldsec ne '-1') {
9985: if ($oldsec ne $sec) {
1.443 albertel 9986: $secchange = 1;
1.628 raeburn 9987: my $now = time;
1.443 albertel 9988: my $uurl='/'.$cid;
9989: $uurl=~s/\_/\//g;
9990: if ($oldsec) {
9991: $uurl.='/'.$oldsec;
9992: }
1.626 raeburn 9993: $oldsecurl = $uurl;
1.628 raeburn 9994: $expire_role_result =
1.652 raeburn 9995: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9996: if ($env{'request.course.sec'} ne '') {
9997: if ($expire_role_result eq 'refused') {
9998: my @roles = ('st');
9999: my @statuses = ('previous');
10000: my @roledoms = ($one);
10001: my $withsec = 1;
10002: my %roleshash =
10003: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10004: \@statuses,\@roles,\@roledoms,$withsec);
10005: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10006: my ($oldstart,$oldend) =
10007: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10008: if ($oldend > 0 && $oldend <= $now) {
10009: $expire_role_result = 'ok';
10010: }
10011: }
10012: }
10013: }
1.443 albertel 10014: $result = $expire_role_result;
10015: }
10016: }
10017: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10018: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10019: if ($modify_section_result =~ /^ok/) {
10020: if ($secchange == 1) {
1.628 raeburn 10021: if ($sec eq '') {
10022: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10023: } else {
10024: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10025: }
1.443 albertel 10026: } elsif ($oldsec eq '-1') {
1.628 raeburn 10027: if ($sec eq '') {
10028: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10029: } else {
10030: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10031: }
1.443 albertel 10032: } else {
1.628 raeburn 10033: if ($sec eq '') {
10034: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10035: } else {
10036: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10037: }
1.443 albertel 10038: }
10039: } else {
1.628 raeburn 10040: if ($secchange) {
10041: $$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;
10042: } else {
10043: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10044: }
1.443 albertel 10045: }
10046: $result = $modify_section_result;
10047: } elsif ($secchange == 1) {
1.628 raeburn 10048: if ($oldsec eq '') {
10049: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10050: } else {
10051: $$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;
10052: }
1.626 raeburn 10053: if ($expire_role_result eq 'refused') {
10054: my $newsecurl = '/'.$cid;
10055: $newsecurl =~ s/\_/\//g;
10056: if ($sec ne '') {
10057: $newsecurl.='/'.$sec;
10058: }
10059: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10060: if ($sec eq '') {
10061: $$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;
10062: } else {
10063: $$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;
10064: }
10065: }
10066: }
1.443 albertel 10067: }
10068: } else {
1.626 raeburn 10069: $$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 10070: $result = "error: incomplete course id\n";
10071: }
10072: return $result;
10073: }
10074:
10075: ############################################################
10076: ############################################################
10077:
1.566 albertel 10078: sub check_clone {
1.578 raeburn 10079: my ($args,$linefeed) = @_;
1.566 albertel 10080: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10081: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10082: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10083: my $clonemsg;
10084: my $can_clone = 0;
1.925.2.11 raeburn 10085: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10086: if ($lctype ne 'community') {
10087: $lctype = 'course';
10088: }
1.566 albertel 10089: if ($clonehome eq 'no_host') {
1.925.2.11 raeburn 10090: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10091: $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'});
10092: } else {
10093: $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'});
10094: }
1.566 albertel 10095: } else {
10096: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.925.2.11 raeburn 10097: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10098: if ($clonedesc{'type'} ne 'Community') {
10099: $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'});
10100: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10101: }
10102: }
1.882 raeburn 10103: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10104: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10105: $can_clone = 1;
10106: } else {
10107: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10108: $args->{'clonedomain'},$args->{'clonecourse'});
10109: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10110: if (grep(/^\*$/,@cloners)) {
10111: $can_clone = 1;
10112: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10113: $can_clone = 1;
10114: } else {
1.908 raeburn 10115: my $ccrole = 'cc';
1.925.2.11 raeburn 10116: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10117: $ccrole = 'co';
10118: }
1.578 raeburn 10119: my %roleshash =
10120: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10121: $args->{'ccdomain'},
1.908 raeburn 10122: 'userroles',['active'],[$ccrole],
1.578 raeburn 10123: [$args->{'clonedomain'}]);
1.908 raeburn 10124: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.578 raeburn 10125: $can_clone = 1;
10126: } else {
1.925.2.11 raeburn 10127: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10128: $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'});
10129: } else {
10130: $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'});
10131: }
1.578 raeburn 10132: }
1.566 albertel 10133: }
1.578 raeburn 10134: }
1.566 albertel 10135: }
10136: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10137: }
10138:
1.444 albertel 10139: sub construct_course {
1.885 raeburn 10140: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10141: my $outcome;
1.541 raeburn 10142: my $linefeed = '<br />'."\n";
10143: if ($context eq 'auto') {
10144: $linefeed = "\n";
10145: }
1.566 albertel 10146:
10147: #
10148: # Are we cloning?
10149: #
10150: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10151: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10152: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10153: if ($context ne 'auto') {
1.578 raeburn 10154: if ($clonemsg ne '') {
10155: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10156: }
1.566 albertel 10157: }
10158: $outcome .= $clonemsg.$linefeed;
10159:
10160: if (!$can_clone) {
10161: return (0,$outcome);
10162: }
10163: }
10164:
1.444 albertel 10165: #
10166: # Open course
10167: #
10168: my $crstype = lc($args->{'crstype'});
10169: my %cenv=();
10170: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10171: $args->{'cdescr'},
10172: $args->{'curl'},
10173: $args->{'course_home'},
10174: $args->{'nonstandard'},
10175: $args->{'crscode'},
10176: $args->{'ccuname'}.':'.
10177: $args->{'ccdomain'},
1.882 raeburn 10178: $args->{'crstype'},
1.885 raeburn 10179: $cnum,$context,$category);
1.444 albertel 10180:
10181: # Note: The testing routines depend on this being output; see
10182: # Utils::Course. This needs to at least be output as a comment
10183: # if anyone ever decides to not show this, and Utils::Course::new
10184: # will need to be suitably modified.
1.541 raeburn 10185: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 10186: #
10187: # Check if created correctly
10188: #
1.479 albertel 10189: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10190: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 10191: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10192:
1.444 albertel 10193: #
1.566 albertel 10194: # Do the cloning
10195: #
10196: if ($can_clone && $cloneid) {
10197: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10198: if ($context ne 'auto') {
10199: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10200: }
10201: $outcome .= $clonemsg.$linefeed;
10202: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10203: # Copy all files
1.637 www 10204: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10205: # Restore URL
1.566 albertel 10206: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10207: # Restore title
1.566 albertel 10208: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 10209: # Mark as cloned
1.566 albertel 10210: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10211: # Need to clone grading mode
10212: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10213: $cenv{'grading'}=$newenv{'grading'};
10214: # Do not clone these environment entries
10215: &Apache::lonnet::del('environment',
10216: ['default_enrollment_start_date',
10217: 'default_enrollment_end_date',
10218: 'question.email',
10219: 'policy.email',
10220: 'comment.email',
10221: 'pch.users.denied',
1.725 raeburn 10222: 'plc.users.denied',
10223: 'hidefromcat',
10224: 'categories'],
1.638 www 10225: $$crsudom,$$crsunum);
1.444 albertel 10226: }
1.566 albertel 10227:
1.444 albertel 10228: #
10229: # Set environment (will override cloned, if existing)
10230: #
10231: my @sections = ();
10232: my @xlists = ();
10233: if ($args->{'crstype'}) {
10234: $cenv{'type'}=$args->{'crstype'};
10235: }
10236: if ($args->{'crsid'}) {
10237: $cenv{'courseid'}=$args->{'crsid'};
10238: }
10239: if ($args->{'crscode'}) {
10240: $cenv{'internal.coursecode'}=$args->{'crscode'};
10241: }
10242: if ($args->{'crsquota'} ne '') {
10243: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10244: } else {
10245: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10246: }
10247: if ($args->{'ccuname'}) {
10248: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10249: ':'.$args->{'ccdomain'};
10250: } else {
10251: $cenv{'internal.courseowner'} = $args->{'curruser'};
10252: }
10253: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10254: if ($args->{'crssections'}) {
10255: $cenv{'internal.sectionnums'} = '';
10256: if ($args->{'crssections'} =~ m/,/) {
10257: @sections = split/,/,$args->{'crssections'};
10258: } else {
10259: $sections[0] = $args->{'crssections'};
10260: }
10261: if (@sections > 0) {
10262: foreach my $item (@sections) {
10263: my ($sec,$gp) = split/:/,$item;
10264: my $class = $args->{'crscode'}.$sec;
10265: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10266: $cenv{'internal.sectionnums'} .= $item.',';
10267: unless ($addcheck eq 'ok') {
10268: push @badclasses, $class;
10269: }
10270: }
10271: $cenv{'internal.sectionnums'} =~ s/,$//;
10272: }
10273: }
10274: # do not hide course coordinator from staff listing,
10275: # even if privileged
10276: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10277: # add crosslistings
10278: if ($args->{'crsxlist'}) {
10279: $cenv{'internal.crosslistings'}='';
10280: if ($args->{'crsxlist'} =~ m/,/) {
10281: @xlists = split/,/,$args->{'crsxlist'};
10282: } else {
10283: $xlists[0] = $args->{'crsxlist'};
10284: }
10285: if (@xlists > 0) {
10286: foreach my $item (@xlists) {
10287: my ($xl,$gp) = split/:/,$item;
10288: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10289: $cenv{'internal.crosslistings'} .= $item.',';
10290: unless ($addcheck eq 'ok') {
10291: push @badclasses, $xl;
10292: }
10293: }
10294: $cenv{'internal.crosslistings'} =~ s/,$//;
10295: }
10296: }
10297: if ($args->{'autoadds'}) {
10298: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10299: }
10300: if ($args->{'autodrops'}) {
10301: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10302: }
10303: # check for notification of enrollment changes
10304: my @notified = ();
10305: if ($args->{'notify_owner'}) {
10306: if ($args->{'ccuname'} ne '') {
10307: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10308: }
10309: }
10310: if ($args->{'notify_dc'}) {
10311: if ($uname ne '') {
1.630 raeburn 10312: push(@notified,$uname.':'.$udom);
1.444 albertel 10313: }
10314: }
10315: if (@notified > 0) {
10316: my $notifylist;
10317: if (@notified > 1) {
10318: $notifylist = join(',',@notified);
10319: } else {
10320: $notifylist = $notified[0];
10321: }
10322: $cenv{'internal.notifylist'} = $notifylist;
10323: }
10324: if (@badclasses > 0) {
10325: my %lt=&Apache::lonlocal::texthash(
10326: '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',
10327: 'dnhr' => 'does not have rights to access enrollment in these classes',
10328: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10329: );
1.541 raeburn 10330: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10331: ' ('.$lt{'adby'}.')';
10332: if ($context eq 'auto') {
10333: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10334: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10335: foreach my $item (@badclasses) {
10336: if ($context eq 'auto') {
10337: $outcome .= " - $item\n";
10338: } else {
10339: $outcome .= "<li>$item</li>\n";
10340: }
10341: }
10342: if ($context eq 'auto') {
10343: $outcome .= $linefeed;
10344: } else {
1.566 albertel 10345: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10346: }
10347: }
1.444 albertel 10348: }
10349: if ($args->{'no_end_date'}) {
10350: $args->{'endaccess'} = 0;
10351: }
10352: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10353: $cenv{'internal.autoend'}=$args->{'enrollend'};
10354: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10355: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10356: if ($args->{'showphotos'}) {
10357: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10358: }
10359: $cenv{'internal.authtype'} = $args->{'authtype'};
10360: $cenv{'internal.autharg'} = $args->{'autharg'};
10361: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10362: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10363: 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');
10364: if ($context eq 'auto') {
10365: $outcome .= $krb_msg;
10366: } else {
1.566 albertel 10367: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10368: }
10369: $outcome .= $linefeed;
1.444 albertel 10370: }
10371: }
10372: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10373: if ($args->{'setpolicy'}) {
10374: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10375: }
10376: if ($args->{'setcontent'}) {
10377: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10378: }
10379: }
10380: if ($args->{'reshome'}) {
10381: $cenv{'reshome'}=$args->{'reshome'}.'/';
10382: $cenv{'reshome'}=~s/\/+$/\//;
10383: }
10384: #
10385: # course has keyed access
10386: #
10387: if ($args->{'setkeys'}) {
10388: $cenv{'keyaccess'}='yes';
10389: }
10390: # if specified, key authority is not course, but user
10391: # only active if keyaccess is yes
10392: if ($args->{'keyauth'}) {
1.487 albertel 10393: my ($user,$domain) = split(':',$args->{'keyauth'});
10394: $user = &LONCAPA::clean_username($user);
10395: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10396: if ($user ne '' && $domain ne '') {
1.487 albertel 10397: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10398: }
10399: }
10400:
10401: if ($args->{'disresdis'}) {
10402: $cenv{'pch.roles.denied'}='st';
10403: }
10404: if ($args->{'disablechat'}) {
10405: $cenv{'plc.roles.denied'}='st';
10406: }
10407:
10408: # Record we've not yet viewed the Course Initialization Helper for this
10409: # course
10410: $cenv{'course.helper.not.run'} = 1;
10411: #
10412: # Use new Randomseed
10413: #
10414: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10415: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10416: #
10417: # The encryption code and receipt prefix for this course
10418: #
10419: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10420: $cenv{'internal.encpref'}=100+int(9*rand(99));
10421: #
10422: # By default, use standard grading
10423: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10424:
1.541 raeburn 10425: $outcome .= $linefeed.&mt('Setting environment').': '.
10426: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10427: #
10428: # Open all assignments
10429: #
10430: if ($args->{'openall'}) {
10431: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10432: my %storecontent = ($storeunder => time,
10433: $storeunder.'.type' => 'date_start');
10434:
10435: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10436: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10437: }
10438: #
10439: # Set first page
10440: #
10441: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10442: || ($cloneid)) {
1.445 albertel 10443: use LONCAPA::map;
1.444 albertel 10444: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10445:
10446: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10447: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10448:
1.444 albertel 10449: $outcome .= ($fatal?$errtext:'read ok').' - ';
10450: my $title; my $url;
10451: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10452: $title=&mt('Syllabus');
1.444 albertel 10453: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10454: } else {
1.690 bisitz 10455: $title=&mt('Navigate Contents');
1.444 albertel 10456: $url='/adm/navmaps';
10457: }
1.445 albertel 10458:
10459: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10460: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10461:
10462: if ($errtext) { $fatal=2; }
1.541 raeburn 10463: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10464: }
1.566 albertel 10465:
1.925.2.12 raeburn 10466: if ($args->{'cloneroster'}) {
10467: my ($numadded,$clisterror) = &Apache::lonclonecourse::copyroster($cloneid,$$courseid,$args->{'startaccess'},$args->{'endaccess'});
10468: if ($clisterror) {
10469: $outcome .= "\0".&mt('An error occurred when copying the student roster from the old course to the new course; the error was: [_1].',$clisterror).$linefeed;
10470: if ($numadded) {
10471: $outcome .= &mt('Although [quant,_1,student] have received roles in the new course the roster does not report this. It is ').$linefeed;
10472: }
10473: } else {
10474: if ($numadded) {
10475: $outcome .= "\0".&mt('[quant,_1,student] copied from roster for old course to roster for new course.',$numadded).$linefeed;
10476: } else {
10477: $outcome .= "\0".&mt('No students have been enrolled in the new Concept Test.').' '.&mt('This is because either (a) an error occurred, or (b) there were no students with either current access or access which ended on/after the current default end date set for access to the old course.').$linefeed;
10478: }
10479: }
10480: }
1.566 albertel 10481: return (1,$outcome);
1.444 albertel 10482: }
10483:
10484: ############################################################
10485: ############################################################
10486:
1.378 raeburn 10487: sub course_type {
10488: my ($cid) = @_;
10489: if (!defined($cid)) {
10490: $cid = $env{'request.course.id'};
10491: }
1.404 albertel 10492: if (defined($env{'course.'.$cid.'.type'})) {
10493: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10494: } else {
10495: return 'Course';
1.377 raeburn 10496: }
10497: }
1.156 albertel 10498:
1.406 raeburn 10499: sub group_term {
10500: my $crstype = &course_type();
10501: my %names = (
10502: 'Course' => 'group',
1.865 raeburn 10503: 'Community' => 'group',
1.406 raeburn 10504: );
10505: return $names{$crstype};
10506: }
10507:
1.902 raeburn 10508: sub course_types {
10509: my @types = ('official','unofficial','community');
10510: my %typename = (
10511: official => 'Official course',
10512: unofficial => 'Unofficial course',
10513: community => 'Community',
10514: );
10515: return (\@types,\%typename);
10516: }
10517:
1.156 albertel 10518: sub icon {
10519: my ($file)=@_;
1.505 albertel 10520: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10521: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10522: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10523: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10524: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10525: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10526: $curfext.".gif") {
10527: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10528: $curfext.".gif";
10529: }
10530: }
1.249 albertel 10531: return &lonhttpdurl($iconname);
1.154 albertel 10532: }
1.84 albertel 10533:
1.575 albertel 10534: sub lonhttpdurl {
1.692 www 10535: #
10536: # Had been used for "small fry" static images on separate port 8080.
10537: # Modify here if lightweight http functionality desired again.
10538: # Currently eliminated due to increasing firewall issues.
10539: #
1.575 albertel 10540: my ($url)=@_;
1.692 www 10541: return $url;
1.215 albertel 10542: }
10543:
1.213 albertel 10544: sub connection_aborted {
10545: my ($r)=@_;
10546: $r->print(" ");$r->rflush();
10547: my $c = $r->connection;
10548: return $c->aborted();
10549: }
10550:
1.221 foxr 10551: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10552: # strings as 'strings'.
10553: sub escape_single {
1.221 foxr 10554: my ($input) = @_;
1.223 albertel 10555: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10556: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10557: return $input;
10558: }
1.223 albertel 10559:
1.222 foxr 10560: # Same as escape_single, but escape's "'s This
10561: # can be used for "strings"
10562: sub escape_double {
10563: my ($input) = @_;
10564: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10565: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10566: return $input;
10567: }
1.223 albertel 10568:
1.222 foxr 10569: # Escapes the last element of a full URL.
10570: sub escape_url {
10571: my ($url) = @_;
1.238 raeburn 10572: my @urlslices = split(/\//, $url,-1);
1.369 www 10573: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10574: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10575: }
1.462 albertel 10576:
1.820 raeburn 10577: sub compare_arrays {
10578: my ($arrayref1,$arrayref2) = @_;
10579: my (@difference,%count);
10580: @difference = ();
10581: %count = ();
10582: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10583: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10584: foreach my $element (keys(%count)) {
10585: if ($count{$element} == 1) {
10586: push(@difference,$element);
10587: }
10588: }
10589: }
10590: return @difference;
10591: }
10592:
1.817 bisitz 10593: # -------------------------------------------------------- Initialize user login
1.462 albertel 10594: sub init_user_environment {
1.463 albertel 10595: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10596: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10597:
10598: my $public=($username eq 'public' && $domain eq 'public');
10599:
10600: # See if old ID present, if so, remove
10601:
10602: my ($filename,$cookie,$userroles);
10603: my $now=time;
10604:
10605: if ($public) {
10606: my $max_public=100;
10607: my $oldest;
10608: my $oldest_time=0;
10609: for(my $next=1;$next<=$max_public;$next++) {
10610: if (-e $lonids."/publicuser_$next.id") {
10611: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10612: if ($mtime<$oldest_time || !$oldest_time) {
10613: $oldest_time=$mtime;
10614: $oldest=$next;
10615: }
10616: } else {
10617: $cookie="publicuser_$next";
10618: last;
10619: }
10620: }
10621: if (!$cookie) { $cookie="publicuser_$oldest"; }
10622: } else {
1.463 albertel 10623: # if this isn't a robot, kill any existing non-robot sessions
10624: if (!$args->{'robot'}) {
10625: opendir(DIR,$lonids);
10626: while ($filename=readdir(DIR)) {
10627: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10628: unlink($lonids.'/'.$filename);
10629: }
1.462 albertel 10630: }
1.463 albertel 10631: closedir(DIR);
1.462 albertel 10632: }
10633: # Give them a new cookie
1.463 albertel 10634: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10635: : $now.$$.int(rand(10000)));
1.463 albertel 10636: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10637:
10638: # Initialize roles
10639:
10640: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10641: }
10642: # ------------------------------------ Check browser type and MathML capability
10643:
10644: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10645: $clientunicode,$clientos) = &decode_user_agent($r);
10646:
10647: # ------------------------------------------------------------- Get environment
10648:
10649: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10650: my ($tmp) = keys(%userenv);
10651: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10652: # default remote control to off
10653: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10654: } else {
10655: undef(%userenv);
10656: }
10657: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10658: $form->{'interface'}=$userenv{'interface'};
10659: }
10660: $env{'environment.remote'}=$userenv{'remote'};
10661: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10662:
10663: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10664: foreach my $option ('interface','localpath','localres') {
10665: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10666: }
10667: # --------------------------------------------------------- Write first profile
10668:
10669: {
10670: my %initial_env =
10671: ("user.name" => $username,
10672: "user.domain" => $domain,
10673: "user.home" => $authhost,
10674: "browser.type" => $clientbrowser,
10675: "browser.version" => $clientversion,
10676: "browser.mathml" => $clientmathml,
10677: "browser.unicode" => $clientunicode,
10678: "browser.os" => $clientos,
10679: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10680: "request.course.fn" => '',
10681: "request.course.uri" => '',
10682: "request.course.sec" => '',
10683: "request.role" => 'cm',
10684: "request.role.adv" => $env{'user.adv'},
10685: "request.host" => $ENV{'REMOTE_ADDR'},);
10686:
10687: if ($form->{'localpath'}) {
10688: $initial_env{"browser.localpath"} = $form->{'localpath'};
10689: $initial_env{"browser.localres"} = $form->{'localres'};
10690: }
10691:
10692: if ($public) {
10693: $initial_env{"environment.remote"} = "off";
10694: }
10695: if ($form->{'interface'}) {
10696: $form->{'interface'}=~s/\W//gs;
10697: $initial_env{"browser.interface"} = $form->{'interface'};
10698: $env{'browser.interface'}=$form->{'interface'};
10699: }
10700:
1.724 raeburn 10701: foreach my $tool ('aboutme','blog','portfolio') {
10702: $userenv{'availabletools.'.$tool} =
10703: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10704: }
10705:
1.864 raeburn 10706: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10707: $userenv{'canrequest.'.$crstype} =
10708: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10709: 'reload','requestcourses');
10710: }
10711:
1.462 albertel 10712: $env{'user.environment'} = "$lonids/$cookie.id";
10713:
10714: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10715: &GDBM_WRCREAT(),0640)) {
10716: &_add_to_env(\%disk_env,\%initial_env);
10717: &_add_to_env(\%disk_env,\%userenv,'environment.');
10718: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10719: if (ref($args->{'extra_env'})) {
10720: &_add_to_env(\%disk_env,$args->{'extra_env'});
10721: }
1.462 albertel 10722: untie(%disk_env);
10723: } else {
1.705 tempelho 10724: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10725: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10726: return 'error: '.$!;
10727: }
10728: }
10729: $env{'request.role'}='cm';
10730: $env{'request.role.adv'}=$env{'user.adv'};
10731: $env{'browser.type'}=$clientbrowser;
10732:
10733: return $cookie;
10734:
10735: }
10736:
10737: sub _add_to_env {
10738: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10739: if (ref($env_data) eq 'HASH') {
10740: while (my ($key,$value) = each(%$env_data)) {
10741: $idf->{$prefix.$key} = $value;
10742: $env{$prefix.$key} = $value;
10743: }
1.462 albertel 10744: }
10745: }
10746:
1.925.2.8 raeburn 10747: sub new_roles_update {
10748: my $rolecount = 0;
10749: foreach my $envkey (keys(%env)) {
10750: next unless ($envkey =~ /^user\.role\./);
10751: $rolecount ++;
10752: }
1.925.2.9 raeburn 10753: my $newrolecount = 0;
1.925.2.8 raeburn 10754: if (!$rolecount) {
10755: my %userenv;
10756: foreach my $crstype ('official','unofficial','community') {
10757: $userenv{'canrequest.'.$crstype} =
10758: &Apache::lonnet::usertools_access($env{'user.name'},
10759: $env{'user.domain'},$crstype,'reload','requestcourses');
10760: }
10761: my $then=$env{'user.login.time'};
10762: my $refresh=time;
10763: my (%userroles,%allroles,%allgroups,@newroles);
10764: my %roleshash =
10765: &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',['active','future','previous'],undef,undef,1);
10766: foreach my $item (keys(%roleshash)) {
10767: my ($uname,$udom,$role,$section) = split(':',$item);
10768: my $where = '/'.$udom.'/'.$uname;
10769: my ($tstart,$tend) = split(':',$roleshash{$item});
10770: if ($section ne '') {
10771: $where .= '/'.$section;
10772: }
10773: my $spec = $role.'.'.$where;
10774: &Apache::lonnet::set_arearole($role,$where,$tstart,$tend,
10775: $env{'user.domain'},$env{'user.name'});
10776: $userroles{'user.role.'.$spec} = $tstart.'.'.$tend;
1.925.2.9 raeburn 10777: $newrolecount ++;
1.925.2.8 raeburn 10778: unless (grep(/^\Q$role\E$/,@newroles)) {
10779: push(@newroles,$role);
10780: }
10781: my $status =
10782: &Apache::lonnet::curr_role_status($tstart,$tend,$refresh,$then);
10783: if ($status eq 'active') {
10784: &Apache::lonnet::gather_roleprivs(\%allroles,\%allgroups,\%userroles,
10785: $where,$role,$tstart,$tend);
10786: }
10787: }
10788: if (@newroles) {
10789: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles,
10790: \%allgroups);
1.925.2.10 raeburn 10791: &Apache::lonnet::appenv(\%userroles,[@newroles,'cm']);
1.925.2.8 raeburn 10792: $userenv{'user.adv'} = $adv;
10793: $userenv{'user.author'} = $author;
10794: $userenv{'user.refresh.time'} = $refresh;
10795: }
10796: &Apache::lonnet::appenv(\%userenv);
10797: }
1.925.2.9 raeburn 10798: return $newrolecount;
1.925.2.8 raeburn 10799: }
10800:
1.685 tempelho 10801: # --- Get the symbolic name of a problem and the url
10802: sub get_symb {
10803: my ($request,$silent) = @_;
1.726 raeburn 10804: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10805: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10806: if ($symb eq '') {
10807: if (!$silent) {
10808: $request->print("Unable to handle ambiguous references:$url:.");
10809: return ();
10810: }
10811: }
10812: &Apache::lonenc::check_decrypt(\$symb);
10813: return ($symb);
10814: }
10815:
10816: # --------------------------------------------------------------Get annotation
10817:
10818: sub get_annotation {
10819: my ($symb,$enc) = @_;
10820:
10821: my $key = $symb;
10822: if (!$enc) {
10823: $key =
10824: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10825: }
10826: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10827: return $annotation{$key};
10828: }
10829:
10830: sub clean_symb {
1.731 raeburn 10831: my ($symb,$delete_enc) = @_;
1.685 tempelho 10832:
10833: &Apache::lonenc::check_decrypt(\$symb);
10834: my $enc = $env{'request.enc'};
1.731 raeburn 10835: if ($delete_enc) {
1.730 raeburn 10836: delete($env{'request.enc'});
10837: }
1.685 tempelho 10838:
10839: return ($symb,$enc);
10840: }
1.462 albertel 10841:
1.925.2.1 raeburn 10842: sub needs_gci_custom {
10843: my $custommenu;
10844: my $numdc = &check_for_gci_dc();
10845: unless ($numdc) {
10846: my $then=$env{'user.login.time'};
10847: my $now = time;
10848: my %cnums = (
10849: review => '9615072b469884921gcil1',
10850: submit => '1H96711d710194bfegcil1',
10851: );
10852: if ($env{'user.role.st./gci/'.$cnums{'review'}}) {
10853: my ($start,$end) =
10854: split('.',$env{'user.role.st./gci/'.$cnums{'review'}});
10855: if (((!$start) || ($start && $start <= $now)) &&
10856: ((!$end) || ($end > $now))) {
10857: $custommenu = 1;
10858: if ($env{'user.role.cc./gci/'.$cnums{'review'}}) {
10859: my ($ccstart,$ccend) =
10860: split('.',$env{'user.role.cc./gci/'.$cnums{'review'}});
10861: if (((!$start) || ($start && $start <= $now)) &&
10862: ((!$end) || ($end > $now))) {
10863: $custommenu = '';
10864: }
10865: }
10866: }
10867: }
10868: }
10869: return $custommenu;
10870: }
10871:
10872: sub check_for_gci_dc {
10873: my $then=$env{'user.login.time'};
10874: my $numdc = 0;
10875: foreach my $dom ('gci','gcitest') {
10876: if ($env{'user.role.dc./'.$dom.'/'}) {
10877: my $livedc = 1;
10878: my ($tstart,$tend)=split(/\./,$env{'user.role.dc./'.$dom.'/'});
10879: if ($tstart && $tstart>$then) { $livedc = 0; }
10880: if ($tend && $tend <$then) { $livedc = 0; }
10881: if ($livedc) {
10882: $numdc++;
10883: }
10884: }
10885: }
10886: return $numdc;
10887: }
10888:
10889: sub existing_gcitest_courses {
1.925.2.6 raeburn 10890: my ($role) = @_;
1.925.2.1 raeburn 10891: my %courses;
10892: my $cdom = 'gcitest';
10893: my $now = time;
10894: foreach my $envkey (keys(%env)) {
10895: my $cnum;
10896: if ($envkey =~ m{^user\.role\.\Q$role\E\./\Q$cdom\E/($match_courseid)$}) {
10897: $cnum = $1;
10898: } else {
10899: next;
10900: }
1.925.2.7 raeburn 10901: my ($tstart,$tend) = split('.',$env{$envkey});
1.925.2.1 raeburn 10902: if (((!$tstart) || ($tstart < $now)) && ((!$tend) || ($tend > $now))) {
1.925.2.3 raeburn 10903: my $descr = $env{'course.'.$cdom.'_'.$cnum.'.description'};
10904: if ($descr ne '') {
10905: $courses{$cdom.'_'.$cnum}{'description'} = $descr;
1.925.2.1 raeburn 10906: }
10907: }
10908: }
10909: return %courses;
10910: }
10911:
1.41 ng 10912: =pod
10913:
10914: =back
10915:
1.112 bowersj2 10916: =cut
1.41 ng 10917:
1.112 bowersj2 10918: 1;
10919: __END__;
1.41 ng 10920:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>