Annotation of loncom/interface/loncommon.pm, revision 1.950
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.950 ! onken 4: # $Id: loncommon.pm,v 1.949 2010/03/10 21:25:49 droeschl Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.909 raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 486: my $wintitle = 'Course_Browser';
1.931 raeburn 487: if ($crstype eq 'Community') {
1.932 raeburn 488: $wintitle = 'Community_Browser';
1.909 raeburn 489: }
1.876 raeburn 490: my $id_functions = &javascript_index_functions();
491: my $output = '
1.776 bisitz 492: <script type="text/javascript" language="JavaScript">
1.824 bisitz 493: // <![CDATA[
1.468 raeburn 494: var stdeditbrowser;'."\n";
1.876 raeburn 495:
496: $output .= <<"ENDSTDBRW";
1.909 raeburn 497: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 498: var url = '/adm/pickcourse?';
1.895 raeburn 499: var formid = getFormIdByName(formname);
1.876 raeburn 500: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 501: if (domainfilter != null) {
502: if (domainfilter != '') {
503: url += 'domainfilter='+domainfilter+'&';
504: }
505: }
1.91 www 506: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 507: '&cdomelement='+udom+
508: '&cnameelement='+desc;
1.468 raeburn 509: if (extra_element !=null && extra_element != '') {
1.594 raeburn 510: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 511: url += '&roleelement='+extra_element;
512: if (domainfilter == null || domainfilter == '') {
513: url += '&domainfilter='+extra_element;
514: }
1.234 raeburn 515: }
1.468 raeburn 516: else {
517: if (formname == 'portform') {
518: url += '&setroles='+extra_element;
1.800 raeburn 519: } else {
520: if (formname == 'rules') {
521: url += '&fixeddom='+extra_element;
522: }
1.468 raeburn 523: }
524: }
1.230 raeburn 525: }
1.909 raeburn 526: if (type != null && type != '') {
527: url += '&type='+type;
528: }
529: if (type_elem != null && type_elem != '') {
530: url += '&typeelement='+type_elem;
531: }
1.872 raeburn 532: if (formname == 'ccrs') {
533: var ownername = document.forms[formid].ccuname.value;
534: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
535: url += '&cloner='+ownername+':'+ownerdom;
536: }
1.293 raeburn 537: if (multflag !=null && multflag != '') {
538: url += '&multiple='+multflag;
539: }
1.909 raeburn 540: var title = '$wintitle';
1.91 www 541: var options = 'scrollbars=1,resizable=1,menubar=0';
542: options += ',width=700,height=600';
543: stdeditbrowser = open(url,title,options,'1');
544: stdeditbrowser.focus();
545: }
1.876 raeburn 546: $id_functions
547: ENDSTDBRW
1.905 raeburn 548: if (($sec_element ne '') || ($role_element ne '')) {
549: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 550: }
551: $output .= '
552: // ]]>
553: </script>';
554: return $output;
555: }
556:
557: sub javascript_index_functions {
558: return <<"ENDJS";
559:
560: function getFormIdByName(formname) {
561: for (var i=0;i<document.forms.length;i++) {
562: if (document.forms[i].name == formname) {
563: return i;
564: }
565: }
566: return -1;
567: }
568:
569: function getIndexByName(formid,item) {
570: for (var i=0;i<document.forms[formid].elements.length;i++) {
571: if (document.forms[formid].elements[i].name == item) {
572: return i;
573: }
574: }
575: return -1;
576: }
1.468 raeburn 577:
1.876 raeburn 578: function getDomainFromSelectbox(formname,udom) {
579: var userdom;
580: var formid = getFormIdByName(formname);
581: if (formid > -1) {
582: var domid = getIndexByName(formid,udom);
583: if (domid > -1) {
584: if (document.forms[formid].elements[domid].type == 'select-one') {
585: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
586: }
587: if (document.forms[formid].elements[domid].type == 'hidden') {
588: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 589: }
590: }
591: }
1.876 raeburn 592: return userdom;
593: }
594:
595: ENDJS
1.468 raeburn 596:
1.876 raeburn 597: }
598:
599: sub userbrowser_javascript {
600: my $id_functions = &javascript_index_functions();
601: return <<"ENDUSERBRW";
602:
1.888 raeburn 603: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 604: var url = '/adm/pickuser?';
605: var userdom = getDomainFromSelectbox(formname,udom);
606: if (userdom != null) {
607: if (userdom != '') {
608: url += 'srchdom='+userdom+'&';
609: }
610: }
611: url += 'form=' + formname + '&unameelement='+uname+
612: '&udomelement='+udom+
613: '&ulastelement='+ulast+
614: '&ufirstelement='+ufirst+
615: '&uemailelement='+uemail+
1.881 raeburn 616: '&hideudomelement='+hideudom+
617: '&coursedom='+crsdom;
1.888 raeburn 618: if ((caller != null) && (caller != undefined)) {
619: url += '&caller='+caller;
620: }
1.876 raeburn 621: var title = 'User_Browser';
622: var options = 'scrollbars=1,resizable=1,menubar=0';
623: options += ',width=700,height=600';
624: var stdeditbrowser = open(url,title,options,'1');
625: stdeditbrowser.focus();
626: }
627:
1.888 raeburn 628: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 629: var formid = getFormIdByName(formname);
630: if (formid > -1) {
1.888 raeburn 631: var unameid = getIndexByName(formid,uname);
1.876 raeburn 632: var domid = getIndexByName(formid,udom);
633: var hidedomid = getIndexByName(formid,origdom);
634: if (hidedomid > -1) {
635: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 636: var unameval = document.forms[formid].elements[unameid].value;
637: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
638: if (domid > -1) {
639: var slct = document.forms[formid].elements[domid];
640: if (slct.type == 'select-one') {
641: var i;
642: for (i=0;i<slct.length;i++) {
643: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
644: }
645: }
646: if (slct.type == 'hidden') {
647: slct.value = fixeddom;
1.876 raeburn 648: }
649: }
1.468 raeburn 650: }
651: }
652: }
1.876 raeburn 653: return;
654: }
655:
656: $id_functions
657: ENDUSERBRW
1.468 raeburn 658: }
659:
660: sub setsec_javascript {
1.905 raeburn 661: my ($sec_element,$formname,$role_element) = @_;
662: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
663: $communityrolestr);
664: if ($role_element ne '') {
665: my @allroles = ('st','ta','ep','in','ad');
666: foreach my $crstype ('Course','Community') {
667: if ($crstype eq 'Community') {
668: foreach my $role (@allroles) {
669: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
670: }
671: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
672: } else {
673: foreach my $role (@allroles) {
674: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
675: }
676: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
677: }
678: }
679: $rolestr = '"'.join('","',@allroles).'"';
680: $courserolestr = '"'.join('","',@courserolenames).'"';
681: $communityrolestr = '"'.join('","',@communityrolenames).'"';
682: }
1.468 raeburn 683: my $setsections = qq|
684: function setSect(sectionlist) {
1.629 raeburn 685: var sectionsArray = new Array();
686: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
687: sectionsArray = sectionlist.split(",");
688: }
1.468 raeburn 689: var numSections = sectionsArray.length;
690: document.$formname.$sec_element.length = 0;
691: if (numSections == 0) {
692: document.$formname.$sec_element.multiple=false;
693: document.$formname.$sec_element.size=1;
694: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
695: } else {
696: if (numSections == 1) {
697: document.$formname.$sec_element.multiple=false;
698: document.$formname.$sec_element.size=1;
699: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
700: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
701: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
702: } else {
703: for (var i=0; i<numSections; i++) {
704: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
705: }
706: document.$formname.$sec_element.multiple=true
707: if (numSections < 3) {
708: document.$formname.$sec_element.size=numSections;
709: } else {
710: document.$formname.$sec_element.size=3;
711: }
712: document.$formname.$sec_element.options[0].selected = false
713: }
714: }
1.91 www 715: }
1.905 raeburn 716:
717: function setRole(crstype) {
1.468 raeburn 718: |;
1.905 raeburn 719: if ($role_element eq '') {
720: $setsections .= ' return;
721: }
722: ';
723: } else {
724: $setsections .= qq|
725: var elementLength = document.$formname.$role_element.length;
726: var allroles = Array($rolestr);
727: var courserolenames = Array($courserolestr);
728: var communityrolenames = Array($communityrolestr);
729: if (elementLength != undefined) {
730: if (document.$formname.$role_element.options[5].value == 'cc') {
731: if (crstype == 'Course') {
732: return;
733: } else {
734: allroles[5] = 'co';
735: for (var i=0; i<6; i++) {
736: document.$formname.$role_element.options[i].value = allroles[i];
737: document.$formname.$role_element.options[i].text = communityrolenames[i];
738: }
739: }
740: } else {
741: if (crstype == 'Community') {
742: return;
743: } else {
744: allroles[5] = 'cc';
745: for (var i=0; i<6; i++) {
746: document.$formname.$role_element.options[i].value = allroles[i];
747: document.$formname.$role_element.options[i].text = courserolenames[i];
748: }
749: }
750: }
751: }
752: return;
753: }
754: |;
755: }
1.468 raeburn 756: return $setsections;
757: }
758:
1.91 www 759: sub selectcourse_link {
1.909 raeburn 760: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
761: $typeelement) = @_;
762: my $type = $selecttype;
1.871 raeburn 763: my $linktext = &mt('Select Course');
764: if ($selecttype eq 'Community') {
1.909 raeburn 765: $linktext = &mt('Select Community');
1.906 raeburn 766: } elsif ($selecttype eq 'Course/Community') {
767: $linktext = &mt('Select Course/Community');
1.909 raeburn 768: $type = '';
1.871 raeburn 769: }
1.787 bisitz 770: return '<span class="LC_nobreak">'
771: ."<a href='"
772: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
773: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 774: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 775: ."'>".$linktext.'</a>'
1.787 bisitz 776: .'</span>';
1.74 www 777: }
1.42 matthew 778:
1.653 raeburn 779: sub selectauthor_link {
780: my ($form,$udom)=@_;
781: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
782: &mt('Select Author').'</a>';
783: }
784:
1.876 raeburn 785: sub selectuser_link {
1.881 raeburn 786: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 787: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 788: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 789: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 790: ');">'.$linktext.'</a>';
1.876 raeburn 791: }
792:
1.273 raeburn 793: sub check_uncheck_jscript {
794: my $jscript = <<"ENDSCRT";
795: function checkAll(field) {
796: if (field.length > 0) {
797: for (i = 0; i < field.length; i++) {
798: field[i].checked = true ;
799: }
800: } else {
801: field.checked = true
802: }
803: }
804:
805: function uncheckAll(field) {
806: if (field.length > 0) {
807: for (i = 0; i < field.length; i++) {
808: field[i].checked = false ;
1.543 albertel 809: }
810: } else {
1.273 raeburn 811: field.checked = false ;
812: }
813: }
814: ENDSCRT
815: return $jscript;
816: }
817:
1.656 www 818: sub select_timezone {
1.659 raeburn 819: my ($name,$selected,$onchange,$includeempty)=@_;
820: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
821: if ($includeempty) {
822: $output .= '<option value=""';
823: if (($selected eq '') || ($selected eq 'local')) {
824: $output .= ' selected="selected" ';
825: }
826: $output .= '> </option>';
827: }
1.657 raeburn 828: my @timezones = DateTime::TimeZone->all_names;
829: foreach my $tzone (@timezones) {
830: $output.= '<option value="'.$tzone.'"';
831: if ($tzone eq $selected) {
832: $output.=' selected="selected"';
833: }
834: $output.=">$tzone</option>\n";
1.656 www 835: }
836: $output.="</select>";
837: return $output;
838: }
1.273 raeburn 839:
1.687 raeburn 840: sub select_datelocale {
841: my ($name,$selected,$onchange,$includeempty)=@_;
842: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
843: if ($includeempty) {
844: $output .= '<option value=""';
845: if ($selected eq '') {
846: $output .= ' selected="selected" ';
847: }
848: $output .= '> </option>';
849: }
850: my (@possibles,%locale_names);
851: my @locales = DateTime::Locale::Catalog::Locales;
852: foreach my $locale (@locales) {
853: if (ref($locale) eq 'HASH') {
854: my $id = $locale->{'id'};
855: if ($id ne '') {
856: my $en_terr = $locale->{'en_territory'};
857: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 858: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 859: if (grep(/^en$/,@languages) || !@languages) {
860: if ($en_terr ne '') {
861: $locale_names{$id} = '('.$en_terr.')';
862: } elsif ($native_terr ne '') {
863: $locale_names{$id} = $native_terr;
864: }
865: } else {
866: if ($native_terr ne '') {
867: $locale_names{$id} = $native_terr.' ';
868: } elsif ($en_terr ne '') {
869: $locale_names{$id} = '('.$en_terr.')';
870: }
871: }
872: push (@possibles,$id);
873: }
874: }
875: }
876: foreach my $item (sort(@possibles)) {
877: $output.= '<option value="'.$item.'"';
878: if ($item eq $selected) {
879: $output.=' selected="selected"';
880: }
881: $output.=">$item";
882: if ($locale_names{$item} ne '') {
883: $output.=" $locale_names{$item}</option>\n";
884: }
885: $output.="</option>\n";
886: }
887: $output.="</select>";
888: return $output;
889: }
890:
1.792 raeburn 891: sub select_language {
892: my ($name,$selected,$includeempty) = @_;
893: my %langchoices;
894: if ($includeempty) {
895: %langchoices = ('' => 'No language preference');
896: }
897: foreach my $id (&languageids()) {
898: my $code = &supportedlanguagecode($id);
899: if ($code) {
900: $langchoices{$code} = &plainlanguagedescription($id);
901: }
902: }
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.934 droeschl 1130: .' title="'.$title.'" style="vertical-align:middle;"'
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.949 droeschl 1205: $stayOnPage = 1;
1.430 albertel 1206: my $output;
1207: if ($component_help) {
1208: if (!$text) {
1209: $output=&help_open_topic($component_help,undef,$stayOnPage,
1210: $width,$height);
1211: } else {
1212: my $help_text;
1213: $help_text=&unescape($topic);
1214: $output='<table><tr><td>'.
1215: &help_open_topic($component_help,$help_text,$stayOnPage,
1216: $width,$height).'</td></tr></table>';
1217: }
1218: }
1219: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1220: return $output.$banner_link;
1221: }
1222:
1223: sub top_nav_help {
1224: my ($text) = @_;
1.436 albertel 1225: $text = &mt($text);
1.949 droeschl 1226: my $stay_on_page = 1;
1227:
1.572 banghart 1228: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1229: : "javascript:helpMenu('open')";
1.572 banghart 1230: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1231:
1.201 raeburn 1232: my $title = &mt('Get help');
1.436 albertel 1233:
1234: return <<"END";
1235: $banner_link
1236: <a href="$link" title="$title">$text</a>
1237: END
1238: }
1239:
1240: sub help_menu_js {
1241: my ($text) = @_;
1.949 droeschl 1242: my $stayOnPage = 1;
1.436 albertel 1243: my $width = 620;
1244: my $height = 600;
1.430 albertel 1245: my $helptopic=&general_help();
1246: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1247: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1248: my $start_page =
1249: &Apache::loncommon::start_page('Help Menu', undef,
1250: {'frameset' => 1,
1251: 'js_ready' => 1,
1252: 'add_entries' => {
1253: 'border' => '0',
1.579 raeburn 1254: 'rows' => "110,*",},});
1.331 albertel 1255: my $end_page =
1256: &Apache::loncommon::end_page({'frameset' => 1,
1257: 'js_ready' => 1,});
1258:
1.436 albertel 1259: my $template .= <<"ENDTEMPLATE";
1260: <script type="text/javascript">
1.877 bisitz 1261: // <![CDATA[
1.253 albertel 1262: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1263: var banner_link = '';
1.243 raeburn 1264: function helpMenu(target) {
1265: var caller = this;
1266: if (target == 'open') {
1267: var newWindow = null;
1268: try {
1.262 albertel 1269: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1270: }
1271: catch(error) {
1272: writeHelp(caller);
1273: return;
1274: }
1275: if (newWindow) {
1276: caller = newWindow;
1277: }
1.193 raeburn 1278: }
1.243 raeburn 1279: writeHelp(caller);
1280: return;
1281: }
1282: function writeHelp(caller) {
1.430 albertel 1283: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1284: caller.document.close()
1285: caller.focus()
1.193 raeburn 1286: }
1.877 bisitz 1287: // END LON-CAPA Internal -->
1.253 albertel 1288: // ]]>
1.436 albertel 1289: </script>
1.193 raeburn 1290: ENDTEMPLATE
1291: return $template;
1292: }
1293:
1.172 www 1294: sub help_open_bug {
1295: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1296: unless ($env{'user.adv'}) { return ''; }
1.172 www 1297: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1298: $text = "" if (not defined $text);
1299: $stayOnPage=1;
1.184 albertel 1300: $width = 600 if (not defined $width);
1301: $height = 600 if (not defined $height);
1.172 www 1302:
1303: $topic=~s/\W+/\+/g;
1304: my $link='';
1305: my $template='';
1.379 albertel 1306: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1307: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1308: if (!$stayOnPage)
1309: {
1310: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1311: }
1312: else
1313: {
1314: $link = $url;
1315: }
1316: # Add the text
1317: if ($text ne "")
1318: {
1319: $template .=
1320: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1321: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1322: }
1323:
1324: # Add the graphic
1.179 matthew 1325: my $title = &mt('Report a Bug');
1.215 albertel 1326: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1327: $template .= <<"ENDTEMPLATE";
1.436 albertel 1328: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1329: ENDTEMPLATE
1330: if ($text ne '') { $template.='</td></tr></table>' };
1331: return $template;
1332:
1333: }
1334:
1335: sub help_open_faq {
1336: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1337: unless ($env{'user.adv'}) { return ''; }
1.172 www 1338: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1339: $text = "" if (not defined $text);
1340: $stayOnPage=1;
1341: $width = 350 if (not defined $width);
1342: $height = 400 if (not defined $height);
1343:
1344: $topic=~s/\W+/\+/g;
1345: my $link='';
1346: my $template='';
1347: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1348: if (!$stayOnPage)
1349: {
1350: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1351: }
1352: else
1353: {
1354: $link = $url;
1355: }
1356:
1357: # Add the text
1358: if ($text ne "")
1359: {
1360: $template .=
1.173 www 1361: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1362: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1363: }
1364:
1365: # Add the graphic
1.179 matthew 1366: my $title = &mt('View the FAQ');
1.215 albertel 1367: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1368: $template .= <<"ENDTEMPLATE";
1.436 albertel 1369: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1370: ENDTEMPLATE
1371: if ($text ne '') { $template.='</td></tr></table>' };
1372: return $template;
1373:
1.44 bowersj2 1374: }
1.37 matthew 1375:
1.180 matthew 1376: ###############################################################
1377: ###############################################################
1378:
1.45 matthew 1379: =pod
1380:
1.648 raeburn 1381: =item * &change_content_javascript():
1.256 matthew 1382:
1383: This and the next function allow you to create small sections of an
1384: otherwise static HTML page that you can update on the fly with
1385: Javascript, even in Netscape 4.
1386:
1387: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1388: must be written to the HTML page once. It will prove the Javascript
1389: function "change(name, content)". Calling the change function with the
1390: name of the section
1391: you want to update, matching the name passed to C<changable_area>, and
1392: the new content you want to put in there, will put the content into
1393: that area.
1394:
1395: B<Note>: Netscape 4 only reserves enough space for the changable area
1396: to contain room for the original contents. You need to "make space"
1397: for whatever changes you wish to make, and be B<sure> to check your
1398: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1399: it's adequate for updating a one-line status display, but little more.
1400: This script will set the space to 100% width, so you only need to
1401: worry about height in Netscape 4.
1402:
1403: Modern browsers are much less limiting, and if you can commit to the
1404: user not using Netscape 4, this feature may be used freely with
1405: pretty much any HTML.
1406:
1407: =cut
1408:
1409: sub change_content_javascript {
1410: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1411: if ($env{'browser.type'} eq 'netscape' &&
1412: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1413: return (<<NETSCAPE4);
1414: function change(name, content) {
1415: doc = document.layers[name+"___escape"].layers[0].document;
1416: doc.open();
1417: doc.write(content);
1418: doc.close();
1419: }
1420: NETSCAPE4
1421: } else {
1422: # Otherwise, we need to use semi-standards-compliant code
1423: # (technically, "innerHTML" isn't standard but the equivalent
1424: # is really scary, and every useful browser supports it
1425: return (<<DOMBASED);
1426: function change(name, content) {
1427: element = document.getElementById(name);
1428: element.innerHTML = content;
1429: }
1430: DOMBASED
1431: }
1432: }
1433:
1434: =pod
1435:
1.648 raeburn 1436: =item * &changable_area($name,$origContent):
1.256 matthew 1437:
1438: This provides a "changable area" that can be modified on the fly via
1439: the Javascript code provided in C<change_content_javascript>. $name is
1440: the name you will use to reference the area later; do not repeat the
1441: same name on a given HTML page more then once. $origContent is what
1442: the area will originally contain, which can be left blank.
1443:
1444: =cut
1445:
1446: sub changable_area {
1447: my ($name, $origContent) = @_;
1448:
1.258 albertel 1449: if ($env{'browser.type'} eq 'netscape' &&
1450: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1451: # If this is netscape 4, we need to use the Layer tag
1452: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1453: } else {
1454: return "<span id='$name'>$origContent</span>";
1455: }
1456: }
1457:
1458: =pod
1459:
1.648 raeburn 1460: =item * &viewport_geometry_js
1.590 raeburn 1461:
1462: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1463:
1464: =cut
1465:
1466:
1467: sub viewport_geometry_js {
1468: return <<"GEOMETRY";
1469: var Geometry = {};
1470: function init_geometry() {
1471: if (Geometry.init) { return };
1472: Geometry.init=1;
1473: if (window.innerHeight) {
1474: Geometry.getViewportHeight = function() { return window.innerHeight; };
1475: Geometry.getViewportWidth = function() { return window.innerWidth; };
1476: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1477: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1478: }
1479: else if (document.documentElement && document.documentElement.clientHeight) {
1480: Geometry.getViewportHeight =
1481: function() { return document.documentElement.clientHeight; };
1482: Geometry.getViewportWidth =
1483: function() { return document.documentElement.clientWidth; };
1484:
1485: Geometry.getHorizontalScroll =
1486: function() { return document.documentElement.scrollLeft; };
1487: Geometry.getVerticalScroll =
1488: function() { return document.documentElement.scrollTop; };
1489: }
1490: else if (document.body.clientHeight) {
1491: Geometry.getViewportHeight =
1492: function() { return document.body.clientHeight; };
1493: Geometry.getViewportWidth =
1494: function() { return document.body.clientWidth; };
1495: Geometry.getHorizontalScroll =
1496: function() { return document.body.scrollLeft; };
1497: Geometry.getVerticalScroll =
1498: function() { return document.body.scrollTop; };
1499: }
1500: }
1501:
1502: GEOMETRY
1503: }
1504:
1505: =pod
1506:
1.648 raeburn 1507: =item * &viewport_size_js()
1.590 raeburn 1508:
1509: 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.
1510:
1511: =cut
1512:
1513: sub viewport_size_js {
1514: my $geometry = &viewport_geometry_js();
1515: return <<"DIMS";
1516:
1517: $geometry
1518:
1519: function getViewportDims(width,height) {
1520: init_geometry();
1521: width.value = Geometry.getViewportWidth();
1522: height.value = Geometry.getViewportHeight();
1523: return;
1524: }
1525:
1526: DIMS
1527: }
1528:
1529: =pod
1530:
1.648 raeburn 1531: =item * &resize_textarea_js()
1.565 albertel 1532:
1533: emits the needed javascript to resize a textarea to be as big as possible
1534:
1535: creates a function resize_textrea that takes two IDs first should be
1536: the id of the element to resize, second should be the id of a div that
1537: surrounds everything that comes after the textarea, this routine needs
1538: to be attached to the <body> for the onload and onresize events.
1539:
1.648 raeburn 1540: =back
1.565 albertel 1541:
1542: =cut
1543:
1544: sub resize_textarea_js {
1.590 raeburn 1545: my $geometry = &viewport_geometry_js();
1.565 albertel 1546: return <<"RESIZE";
1547: <script type="text/javascript">
1.824 bisitz 1548: // <![CDATA[
1.590 raeburn 1549: $geometry
1.565 albertel 1550:
1.588 albertel 1551: function getX(element) {
1552: var x = 0;
1553: while (element) {
1554: x += element.offsetLeft;
1555: element = element.offsetParent;
1556: }
1557: return x;
1558: }
1559: function getY(element) {
1560: var y = 0;
1561: while (element) {
1562: y += element.offsetTop;
1563: element = element.offsetParent;
1564: }
1565: return y;
1566: }
1567:
1568:
1.565 albertel 1569: function resize_textarea(textarea_id,bottom_id) {
1570: init_geometry();
1571: var textarea = document.getElementById(textarea_id);
1572: //alert(textarea);
1573:
1.588 albertel 1574: var textarea_top = getY(textarea);
1.565 albertel 1575: var textarea_height = textarea.offsetHeight;
1576: var bottom = document.getElementById(bottom_id);
1.588 albertel 1577: var bottom_top = getY(bottom);
1.565 albertel 1578: var bottom_height = bottom.offsetHeight;
1579: var window_height = Geometry.getViewportHeight();
1.588 albertel 1580: var fudge = 23;
1.565 albertel 1581: var new_height = window_height-fudge-textarea_top-bottom_height;
1582: if (new_height < 300) {
1583: new_height = 300;
1584: }
1585: textarea.style.height=new_height+'px';
1586: }
1.824 bisitz 1587: // ]]>
1.565 albertel 1588: </script>
1589: RESIZE
1590:
1591: }
1592:
1593: =pod
1594:
1.256 matthew 1595: =head1 Excel and CSV file utility routines
1596:
1597: =over 4
1598:
1599: =cut
1600:
1601: ###############################################################
1602: ###############################################################
1603:
1604: =pod
1605:
1.648 raeburn 1606: =item * &csv_translate($text)
1.37 matthew 1607:
1.185 www 1608: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1609: format.
1610:
1611: =cut
1612:
1.180 matthew 1613: ###############################################################
1614: ###############################################################
1.37 matthew 1615: sub csv_translate {
1616: my $text = shift;
1617: $text =~ s/\"/\"\"/g;
1.209 albertel 1618: $text =~ s/\n/ /g;
1.37 matthew 1619: return $text;
1620: }
1.180 matthew 1621:
1622: ###############################################################
1623: ###############################################################
1624:
1625: =pod
1626:
1.648 raeburn 1627: =item * &define_excel_formats()
1.180 matthew 1628:
1629: Define some commonly used Excel cell formats.
1630:
1631: Currently supported formats:
1632:
1633: =over 4
1634:
1635: =item header
1636:
1637: =item bold
1638:
1639: =item h1
1640:
1641: =item h2
1642:
1643: =item h3
1644:
1.256 matthew 1645: =item h4
1646:
1647: =item i
1648:
1.180 matthew 1649: =item date
1650:
1651: =back
1652:
1653: Inputs: $workbook
1654:
1655: Returns: $format, a hash reference.
1656:
1657: =cut
1658:
1659: ###############################################################
1660: ###############################################################
1661: sub define_excel_formats {
1662: my ($workbook) = @_;
1663: my $format;
1664: $format->{'header'} = $workbook->add_format(bold => 1,
1665: bottom => 1,
1666: align => 'center');
1667: $format->{'bold'} = $workbook->add_format(bold=>1);
1668: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1669: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1670: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1671: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1672: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1673: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1674: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1675: return $format;
1676: }
1677:
1678: ###############################################################
1679: ###############################################################
1.113 bowersj2 1680:
1681: =pod
1682:
1.648 raeburn 1683: =item * &create_workbook()
1.255 matthew 1684:
1685: Create an Excel worksheet. If it fails, output message on the
1686: request object and return undefs.
1687:
1688: Inputs: Apache request object
1689:
1690: Returns (undef) on failure,
1691: Excel worksheet object, scalar with filename, and formats
1692: from &Apache::loncommon::define_excel_formats on success
1693:
1694: =cut
1695:
1696: ###############################################################
1697: ###############################################################
1698: sub create_workbook {
1699: my ($r) = @_;
1700: #
1701: # Create the excel spreadsheet
1702: my $filename = '/prtspool/'.
1.258 albertel 1703: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1704: time.'_'.rand(1000000000).'.xls';
1705: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1706: if (! defined($workbook)) {
1707: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1708: $r->print(
1709: '<p class="LC_error">'
1710: .&mt('Problems occurred in creating the new Excel file.')
1711: .' '.&mt('This error has been logged.')
1712: .' '.&mt('Please alert your LON-CAPA administrator.')
1713: .'</p>'
1714: );
1.255 matthew 1715: return (undef);
1716: }
1717: #
1718: $workbook->set_tempdir('/home/httpd/perl/tmp');
1719: #
1720: my $format = &Apache::loncommon::define_excel_formats($workbook);
1721: return ($workbook,$filename,$format);
1722: }
1723:
1724: ###############################################################
1725: ###############################################################
1726:
1727: =pod
1728:
1.648 raeburn 1729: =item * &create_text_file()
1.113 bowersj2 1730:
1.542 raeburn 1731: Create a file to write to and eventually make available to the user.
1.256 matthew 1732: If file creation fails, outputs an error message on the request object and
1733: return undefs.
1.113 bowersj2 1734:
1.256 matthew 1735: Inputs: Apache request object, and file suffix
1.113 bowersj2 1736:
1.256 matthew 1737: Returns (undef) on failure,
1738: Filehandle and filename on success.
1.113 bowersj2 1739:
1740: =cut
1741:
1.256 matthew 1742: ###############################################################
1743: ###############################################################
1744: sub create_text_file {
1745: my ($r,$suffix) = @_;
1746: if (! defined($suffix)) { $suffix = 'txt'; };
1747: my $fh;
1748: my $filename = '/prtspool/'.
1.258 albertel 1749: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1750: time.'_'.rand(1000000000).'.'.$suffix;
1751: $fh = Apache::File->new('>/home/httpd'.$filename);
1752: if (! defined($fh)) {
1753: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1754: $r->print(
1755: '<p class="LC_error">'
1756: .&mt('Problems occurred in creating the output file.')
1757: .' '.&mt('This error has been logged.')
1758: .' '.&mt('Please alert your LON-CAPA administrator.')
1759: .'</p>'
1760: );
1.113 bowersj2 1761: }
1.256 matthew 1762: return ($fh,$filename)
1.113 bowersj2 1763: }
1764:
1765:
1.256 matthew 1766: =pod
1.113 bowersj2 1767:
1768: =back
1769:
1770: =cut
1.37 matthew 1771:
1772: ###############################################################
1.33 matthew 1773: ## Home server <option> list generating code ##
1774: ###############################################################
1.35 matthew 1775:
1.169 www 1776: # ------------------------------------------
1777:
1778: sub domain_select {
1779: my ($name,$value,$multiple)=@_;
1780: my %domains=map {
1.514 albertel 1781: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1782: } &Apache::lonnet::all_domains();
1.169 www 1783: if ($multiple) {
1784: $domains{''}=&mt('Any domain');
1.550 albertel 1785: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1786: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1787: } else {
1.550 albertel 1788: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1789: return &select_form($name,$value,%domains);
1790: }
1791: }
1792:
1.282 albertel 1793: #-------------------------------------------
1794:
1795: =pod
1796:
1.519 raeburn 1797: =head1 Routines for form select boxes
1798:
1799: =over 4
1800:
1.648 raeburn 1801: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1802:
1803: Returns a string containing a <select> element int multiple mode
1804:
1805:
1806: Args:
1807: $name - name of the <select> element
1.506 raeburn 1808: $value - scalar or array ref of values that should already be selected
1.282 albertel 1809: $size - number of rows long the select element is
1.283 albertel 1810: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1811: (shown text should already have been &mt())
1.506 raeburn 1812: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1813:
1.282 albertel 1814: =cut
1815:
1816: #-------------------------------------------
1.169 www 1817: sub multiple_select_form {
1.284 albertel 1818: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1819: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1820: my $output='';
1.191 matthew 1821: if (! defined($size)) {
1822: $size = 4;
1.283 albertel 1823: if (scalar(keys(%$hash))<4) {
1824: $size = scalar(keys(%$hash));
1.191 matthew 1825: }
1826: }
1.734 bisitz 1827: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1828: my @order;
1.506 raeburn 1829: if (ref($order) eq 'ARRAY') {
1830: @order = @{$order};
1831: } else {
1832: @order = sort(keys(%$hash));
1.501 banghart 1833: }
1834: if (exists($$hash{'select_form_order'})) {
1835: @order = @{$$hash{'select_form_order'}};
1836: }
1837:
1.284 albertel 1838: foreach my $key (@order) {
1.356 albertel 1839: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1840: $output.='selected="selected" ' if ($selected{$key});
1841: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1842: }
1843: $output.="</select>\n";
1844: return $output;
1845: }
1846:
1.88 www 1847: #-------------------------------------------
1848:
1849: =pod
1850:
1.648 raeburn 1851: =item * &select_form($defdom,$name,%hash)
1.88 www 1852:
1853: Returns a string containing a <select name='$name' size='1'> form to
1854: allow a user to select options from a hash option_name => displayed text.
1855: See lonrights.pm for an example invocation and use.
1856:
1857: =cut
1858:
1859: #-------------------------------------------
1860: sub select_form {
1861: my ($def,$name,%hash) = @_;
1862: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1863: my @keys;
1864: if (exists($hash{'select_form_order'})) {
1865: @keys=@{$hash{'select_form_order'}};
1866: } else {
1867: @keys=sort(keys(%hash));
1868: }
1.356 albertel 1869: foreach my $key (@keys) {
1870: $selectform.=
1871: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1872: ($key eq $def ? 'selected="selected" ' : '').
1.922 bisitz 1873: ">".$hash{$key}."</option>\n";
1.88 www 1874: }
1875: $selectform.="</select>";
1876: return $selectform;
1877: }
1878:
1.475 www 1879: # For display filters
1880:
1881: sub display_filter {
1882: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1883: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1884: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1885: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1886: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1887: '</label></span> <span class="LC_nobreak">'.
1.475 www 1888: &mt('Filter [_1]',
1.477 www 1889: &select_form($env{'form.displayfilter'},
1890: 'displayfilter',
1891: ('currentfolder' => 'Current folder/page',
1892: 'containing' => 'Containing phrase',
1893: 'none' => 'None'))).
1.714 bisitz 1894: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1895: }
1896:
1.167 www 1897: sub gradeleveldescription {
1898: my $gradelevel=shift;
1899: my %gradelevels=(0 => 'Not specified',
1900: 1 => 'Grade 1',
1901: 2 => 'Grade 2',
1902: 3 => 'Grade 3',
1903: 4 => 'Grade 4',
1904: 5 => 'Grade 5',
1905: 6 => 'Grade 6',
1906: 7 => 'Grade 7',
1907: 8 => 'Grade 8',
1908: 9 => 'Grade 9',
1909: 10 => 'Grade 10',
1910: 11 => 'Grade 11',
1911: 12 => 'Grade 12',
1912: 13 => 'Grade 13',
1913: 14 => '100 Level',
1914: 15 => '200 Level',
1915: 16 => '300 Level',
1916: 17 => '400 Level',
1917: 18 => 'Graduate Level');
1918: return &mt($gradelevels{$gradelevel});
1919: }
1920:
1.163 www 1921: sub select_level_form {
1922: my ($deflevel,$name)=@_;
1923: unless ($deflevel) { $deflevel=0; }
1.167 www 1924: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1925: for (my $i=0; $i<=18; $i++) {
1926: $selectform.="<option value=\"$i\" ".
1.253 albertel 1927: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1928: ">".&gradeleveldescription($i)."</option>\n";
1929: }
1930: $selectform.="</select>";
1931: return $selectform;
1.163 www 1932: }
1.167 www 1933:
1.35 matthew 1934: #-------------------------------------------
1935:
1.45 matthew 1936: =pod
1937:
1.910 raeburn 1938: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1939:
1940: Returns a string containing a <select name='$name' size='1'> form to
1941: allow a user to select the domain to preform an operation in.
1942: See loncreateuser.pm for an example invocation and use.
1943:
1.90 www 1944: If the $includeempty flag is set, it also includes an empty choice ("no domain
1945: selected");
1946:
1.743 raeburn 1947: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1948:
1.910 raeburn 1949: 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.
1950:
1951: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 1952:
1.35 matthew 1953: =cut
1954:
1955: #-------------------------------------------
1.34 matthew 1956: sub select_dom_form {
1.910 raeburn 1957: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 1958: if ($onchange) {
1.874 raeburn 1959: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1960: }
1.910 raeburn 1961: my @domains;
1962: if (ref($incdoms) eq 'ARRAY') {
1963: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
1964: } else {
1965: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1966: }
1.90 www 1967: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1968: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1969: foreach my $dom (@domains) {
1970: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1971: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1972: if ($showdomdesc) {
1973: if ($dom ne '') {
1974: my $domdesc = &Apache::lonnet::domain($dom,'description');
1975: if ($domdesc ne '') {
1976: $selectdomain .= ' ('.$domdesc.')';
1977: }
1978: }
1979: }
1980: $selectdomain .= "</option>\n";
1.34 matthew 1981: }
1982: $selectdomain.="</select>";
1983: return $selectdomain;
1984: }
1985:
1.35 matthew 1986: #-------------------------------------------
1987:
1.45 matthew 1988: =pod
1989:
1.648 raeburn 1990: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1991:
1.586 raeburn 1992: input: 4 arguments (two required, two optional) -
1993: $domain - domain of new user
1994: $name - name of form element
1995: $default - Value of 'default' causes a default item to be first
1996: option, and selected by default.
1997: $hide - Value of 'hide' causes hiding of the name of the server,
1998: if 1 server found, or default, if 0 found.
1.594 raeburn 1999: output: returns 2 items:
1.586 raeburn 2000: (a) form element which contains either:
2001: (i) <select name="$name">
2002: <option value="$hostid1">$hostid $servers{$hostid}</option>
2003: <option value="$hostid2">$hostid $servers{$hostid}</option>
2004: </select>
2005: form item if there are multiple library servers in $domain, or
2006: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2007: if there is only one library server in $domain.
2008:
2009: (b) number of library servers found.
2010:
2011: See loncreateuser.pm for example of use.
1.35 matthew 2012:
2013: =cut
2014:
2015: #-------------------------------------------
1.586 raeburn 2016: sub home_server_form_item {
2017: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2018: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2019: my $result;
2020: my $numlib = keys(%servers);
2021: if ($numlib > 1) {
2022: $result .= '<select name="'.$name.'" />'."\n";
2023: if ($default) {
1.804 bisitz 2024: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2025: '</option>'."\n";
2026: }
2027: foreach my $hostid (sort(keys(%servers))) {
2028: $result.= '<option value="'.$hostid.'">'.
2029: $hostid.' '.$servers{$hostid}."</option>\n";
2030: }
2031: $result .= '</select>'."\n";
2032: } elsif ($numlib == 1) {
2033: my $hostid;
2034: foreach my $item (keys(%servers)) {
2035: $hostid = $item;
2036: }
2037: $result .= '<input type="hidden" name="'.$name.'" value="'.
2038: $hostid.'" />';
2039: if (!$hide) {
2040: $result .= $hostid.' '.$servers{$hostid};
2041: }
2042: $result .= "\n";
2043: } elsif ($default) {
2044: $result .= '<input type="hidden" name="'.$name.
2045: '" value="default" />';
2046: if (!$hide) {
2047: $result .= &mt('default');
2048: }
2049: $result .= "\n";
1.33 matthew 2050: }
1.586 raeburn 2051: return ($result,$numlib);
1.33 matthew 2052: }
1.112 bowersj2 2053:
2054: =pod
2055:
1.534 albertel 2056: =back
2057:
1.112 bowersj2 2058: =cut
1.87 matthew 2059:
2060: ###############################################################
1.112 bowersj2 2061: ## Decoding User Agent ##
1.87 matthew 2062: ###############################################################
2063:
2064: =pod
2065:
1.112 bowersj2 2066: =head1 Decoding the User Agent
2067:
2068: =over 4
2069:
2070: =item * &decode_user_agent()
1.87 matthew 2071:
2072: Inputs: $r
2073:
2074: Outputs:
2075:
2076: =over 4
2077:
1.112 bowersj2 2078: =item * $httpbrowser
1.87 matthew 2079:
1.112 bowersj2 2080: =item * $clientbrowser
1.87 matthew 2081:
1.112 bowersj2 2082: =item * $clientversion
1.87 matthew 2083:
1.112 bowersj2 2084: =item * $clientmathml
1.87 matthew 2085:
1.112 bowersj2 2086: =item * $clientunicode
1.87 matthew 2087:
1.112 bowersj2 2088: =item * $clientos
1.87 matthew 2089:
2090: =back
2091:
1.157 matthew 2092: =back
2093:
1.87 matthew 2094: =cut
2095:
2096: ###############################################################
2097: ###############################################################
2098: sub decode_user_agent {
1.247 albertel 2099: my ($r)=@_;
1.87 matthew 2100: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2101: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2102: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2103: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2104: my $clientbrowser='unknown';
2105: my $clientversion='0';
2106: my $clientmathml='';
2107: my $clientunicode='0';
2108: for (my $i=0;$i<=$#browsertype;$i++) {
2109: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2110: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2111: $clientbrowser=$bname;
2112: $httpbrowser=~/$vreg/i;
2113: $clientversion=$1;
2114: $clientmathml=($clientversion>=$minv);
2115: $clientunicode=($clientversion>=$univ);
2116: }
2117: }
2118: my $clientos='unknown';
2119: if (($httpbrowser=~/linux/i) ||
2120: ($httpbrowser=~/unix/i) ||
2121: ($httpbrowser=~/ux/i) ||
2122: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2123: if (($httpbrowser=~/vax/i) ||
2124: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2125: if ($httpbrowser=~/next/i) { $clientos='next'; }
2126: if (($httpbrowser=~/mac/i) ||
2127: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2128: if ($httpbrowser=~/win/i) { $clientos='win'; }
2129: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2130: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2131: $clientunicode,$clientos,);
2132: }
2133:
1.32 matthew 2134: ###############################################################
2135: ## Authentication changing form generation subroutines ##
2136: ###############################################################
2137: ##
2138: ## All of the authform_xxxxxxx subroutines take their inputs in a
2139: ## hash, and have reasonable default values.
2140: ##
2141: ## formname = the name given in the <form> tag.
1.35 matthew 2142: #-------------------------------------------
2143:
1.45 matthew 2144: =pod
2145:
1.112 bowersj2 2146: =head1 Authentication Routines
2147:
2148: =over 4
2149:
1.648 raeburn 2150: =item * &authform_xxxxxx()
1.35 matthew 2151:
2152: The authform_xxxxxx subroutines provide javascript and html forms which
2153: handle some of the conveniences required for authentication forms.
2154: This is not an optimal method, but it works.
2155:
2156: =over 4
2157:
1.112 bowersj2 2158: =item * authform_header
1.35 matthew 2159:
1.112 bowersj2 2160: =item * authform_authorwarning
1.35 matthew 2161:
1.112 bowersj2 2162: =item * authform_nochange
1.35 matthew 2163:
1.112 bowersj2 2164: =item * authform_kerberos
1.35 matthew 2165:
1.112 bowersj2 2166: =item * authform_internal
1.35 matthew 2167:
1.112 bowersj2 2168: =item * authform_filesystem
1.35 matthew 2169:
2170: =back
2171:
1.648 raeburn 2172: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2173:
1.35 matthew 2174: =cut
2175:
2176: #-------------------------------------------
1.32 matthew 2177: sub authform_header{
2178: my %in = (
2179: formname => 'cu',
1.80 albertel 2180: kerb_def_dom => '',
1.32 matthew 2181: @_,
2182: );
2183: $in{'formname'} = 'document.' . $in{'formname'};
2184: my $result='';
1.80 albertel 2185:
2186: #---------------------------------------------- Code for upper case translation
2187: my $Javascript_toUpperCase;
2188: unless ($in{kerb_def_dom}) {
2189: $Javascript_toUpperCase =<<"END";
2190: switch (choice) {
2191: case 'krb': currentform.elements[choicearg].value =
2192: currentform.elements[choicearg].value.toUpperCase();
2193: break;
2194: default:
2195: }
2196: END
2197: } else {
2198: $Javascript_toUpperCase = "";
2199: }
2200:
1.165 raeburn 2201: my $radioval = "'nochange'";
1.591 raeburn 2202: if (defined($in{'curr_authtype'})) {
2203: if ($in{'curr_authtype'} ne '') {
2204: $radioval = "'".$in{'curr_authtype'}."arg'";
2205: }
1.174 matthew 2206: }
1.165 raeburn 2207: my $argfield = 'null';
1.591 raeburn 2208: if (defined($in{'mode'})) {
1.165 raeburn 2209: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2210: if (defined($in{'curr_autharg'})) {
2211: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2212: $argfield = "'$in{'curr_autharg'}'";
2213: }
2214: }
2215: }
2216: }
2217:
1.32 matthew 2218: $result.=<<"END";
2219: var current = new Object();
1.165 raeburn 2220: current.radiovalue = $radioval;
2221: current.argfield = $argfield;
1.32 matthew 2222:
2223: function changed_radio(choice,currentform) {
2224: var choicearg = choice + 'arg';
2225: // If a radio button in changed, we need to change the argfield
2226: if (current.radiovalue != choice) {
2227: current.radiovalue = choice;
2228: if (current.argfield != null) {
2229: currentform.elements[current.argfield].value = '';
2230: }
2231: if (choice == 'nochange') {
2232: current.argfield = null;
2233: } else {
2234: current.argfield = choicearg;
2235: switch(choice) {
2236: case 'krb':
2237: currentform.elements[current.argfield].value =
2238: "$in{'kerb_def_dom'}";
2239: break;
2240: default:
2241: break;
2242: }
2243: }
2244: }
2245: return;
2246: }
1.22 www 2247:
1.32 matthew 2248: function changed_text(choice,currentform) {
2249: var choicearg = choice + 'arg';
2250: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2251: $Javascript_toUpperCase
1.32 matthew 2252: // clear old field
2253: if ((current.argfield != choicearg) && (current.argfield != null)) {
2254: currentform.elements[current.argfield].value = '';
2255: }
2256: current.argfield = choicearg;
2257: }
2258: set_auth_radio_buttons(choice,currentform);
2259: return;
1.20 www 2260: }
1.32 matthew 2261:
2262: function set_auth_radio_buttons(newvalue,currentform) {
2263: var i=0;
2264: while (i < currentform.login.length) {
2265: if (currentform.login[i].value == newvalue) { break; }
2266: i++;
2267: }
2268: if (i == currentform.login.length) {
2269: return;
2270: }
2271: current.radiovalue = newvalue;
2272: currentform.login[i].checked = true;
2273: return;
2274: }
2275: END
2276: return $result;
2277: }
2278:
2279: sub authform_authorwarning{
2280: my $result='';
1.144 matthew 2281: $result='<i>'.
2282: &mt('As a general rule, only authors or co-authors should be '.
2283: 'filesystem authenticated '.
2284: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2285: return $result;
2286: }
2287:
2288: sub authform_nochange{
2289: my %in = (
2290: formname => 'document.cu',
2291: kerb_def_dom => 'MSU.EDU',
2292: @_,
2293: );
1.586 raeburn 2294: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2295: my $result;
2296: if (keys(%can_assign) == 0) {
2297: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2298: } else {
2299: $result = '<label>'.&mt('[_1] Do not change login data',
2300: '<input type="radio" name="login" value="nochange" '.
2301: 'checked="checked" onclick="'.
1.281 albertel 2302: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2303: '</label>';
1.586 raeburn 2304: }
1.32 matthew 2305: return $result;
2306: }
2307:
1.591 raeburn 2308: sub authform_kerberos {
1.32 matthew 2309: my %in = (
2310: formname => 'document.cu',
2311: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2312: kerb_def_auth => 'krb4',
1.32 matthew 2313: @_,
2314: );
1.586 raeburn 2315: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2316: $autharg,$jscall);
2317: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2318: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2319: $check5 = ' checked="checked"';
1.80 albertel 2320: } else {
1.772 bisitz 2321: $check4 = ' checked="checked"';
1.80 albertel 2322: }
1.165 raeburn 2323: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2324: if (defined($in{'curr_authtype'})) {
2325: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2326: $krbcheck = ' checked="checked"';
1.623 raeburn 2327: if (defined($in{'mode'})) {
2328: if ($in{'mode'} eq 'modifyuser') {
2329: $krbcheck = '';
2330: }
2331: }
1.591 raeburn 2332: if (defined($in{'curr_kerb_ver'})) {
2333: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2334: $check5 = ' checked="checked"';
1.591 raeburn 2335: $check4 = '';
2336: } else {
1.772 bisitz 2337: $check4 = ' checked="checked"';
1.591 raeburn 2338: $check5 = '';
2339: }
1.586 raeburn 2340: }
1.591 raeburn 2341: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2342: $krbarg = $in{'curr_autharg'};
2343: }
1.586 raeburn 2344: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2345: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2346: $result =
2347: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2348: $in{'curr_autharg'},$krbver);
2349: } else {
2350: $result =
2351: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2352: }
2353: return $result;
2354: }
2355: }
2356: } else {
2357: if ($authnum == 1) {
1.784 bisitz 2358: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2359: }
2360: }
1.586 raeburn 2361: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2362: return;
1.587 raeburn 2363: } elsif ($authtype eq '') {
1.591 raeburn 2364: if (defined($in{'mode'})) {
1.587 raeburn 2365: if ($in{'mode'} eq 'modifycourse') {
2366: if ($authnum == 1) {
1.784 bisitz 2367: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2368: }
2369: }
2370: }
1.586 raeburn 2371: }
2372: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2373: if ($authtype eq '') {
2374: $authtype = '<input type="radio" name="login" value="krb" '.
2375: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2376: $krbcheck.' />';
2377: }
2378: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2379: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2380: $in{'curr_authtype'} eq 'krb5') ||
2381: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2382: $in{'curr_authtype'} eq 'krb4')) {
2383: $result .= &mt
1.144 matthew 2384: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2385: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2386: '<label>'.$authtype,
1.281 albertel 2387: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2388: 'value="'.$krbarg.'" '.
1.144 matthew 2389: 'onchange="'.$jscall.'" />',
1.281 albertel 2390: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2391: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2392: '</label>');
1.586 raeburn 2393: } elsif ($can_assign{'krb4'}) {
2394: $result .= &mt
2395: ('[_1] Kerberos authenticated with domain [_2] '.
2396: '[_3] Version 4 [_4]',
2397: '<label>'.$authtype,
2398: '</label><input type="text" size="10" name="krbarg" '.
2399: 'value="'.$krbarg.'" '.
2400: 'onchange="'.$jscall.'" />',
2401: '<label><input type="hidden" name="krbver" value="4" />',
2402: '</label>');
2403: } elsif ($can_assign{'krb5'}) {
2404: $result .= &mt
2405: ('[_1] Kerberos authenticated with domain [_2] '.
2406: '[_3] Version 5 [_4]',
2407: '<label>'.$authtype,
2408: '</label><input type="text" size="10" name="krbarg" '.
2409: 'value="'.$krbarg.'" '.
2410: 'onchange="'.$jscall.'" />',
2411: '<label><input type="hidden" name="krbver" value="5" />',
2412: '</label>');
2413: }
1.32 matthew 2414: return $result;
2415: }
2416:
2417: sub authform_internal{
1.586 raeburn 2418: my %in = (
1.32 matthew 2419: formname => 'document.cu',
2420: kerb_def_dom => 'MSU.EDU',
2421: @_,
2422: );
1.586 raeburn 2423: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2424: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2425: if (defined($in{'curr_authtype'})) {
2426: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2427: if ($can_assign{'int'}) {
1.772 bisitz 2428: $intcheck = 'checked="checked" ';
1.623 raeburn 2429: if (defined($in{'mode'})) {
2430: if ($in{'mode'} eq 'modifyuser') {
2431: $intcheck = '';
2432: }
2433: }
1.591 raeburn 2434: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2435: $intarg = $in{'curr_autharg'};
2436: }
2437: } else {
2438: $result = &mt('Currently internally authenticated.');
2439: return $result;
1.165 raeburn 2440: }
2441: }
1.586 raeburn 2442: } else {
2443: if ($authnum == 1) {
1.784 bisitz 2444: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2445: }
2446: }
2447: if (!$can_assign{'int'}) {
2448: return;
1.587 raeburn 2449: } elsif ($authtype eq '') {
1.591 raeburn 2450: if (defined($in{'mode'})) {
1.587 raeburn 2451: if ($in{'mode'} eq 'modifycourse') {
2452: if ($authnum == 1) {
1.784 bisitz 2453: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2454: }
2455: }
2456: }
1.165 raeburn 2457: }
1.586 raeburn 2458: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2459: if ($authtype eq '') {
2460: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2461: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2462: }
1.605 bisitz 2463: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2464: $intarg.'" onchange="'.$jscall.'" />';
2465: $result = &mt
1.144 matthew 2466: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2467: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2468: $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 2469: return $result;
2470: }
2471:
2472: sub authform_local{
2473: my %in = (
2474: formname => 'document.cu',
2475: kerb_def_dom => 'MSU.EDU',
2476: @_,
2477: );
1.586 raeburn 2478: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2479: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2480: if (defined($in{'curr_authtype'})) {
2481: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2482: if ($can_assign{'loc'}) {
1.772 bisitz 2483: $loccheck = 'checked="checked" ';
1.623 raeburn 2484: if (defined($in{'mode'})) {
2485: if ($in{'mode'} eq 'modifyuser') {
2486: $loccheck = '';
2487: }
2488: }
1.591 raeburn 2489: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2490: $locarg = $in{'curr_autharg'};
2491: }
2492: } else {
2493: $result = &mt('Currently using local (institutional) authentication.');
2494: return $result;
1.165 raeburn 2495: }
2496: }
1.586 raeburn 2497: } else {
2498: if ($authnum == 1) {
1.784 bisitz 2499: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2500: }
2501: }
2502: if (!$can_assign{'loc'}) {
2503: return;
1.587 raeburn 2504: } elsif ($authtype eq '') {
1.591 raeburn 2505: if (defined($in{'mode'})) {
1.587 raeburn 2506: if ($in{'mode'} eq 'modifycourse') {
2507: if ($authnum == 1) {
1.784 bisitz 2508: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2509: }
2510: }
2511: }
1.165 raeburn 2512: }
1.586 raeburn 2513: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2514: if ($authtype eq '') {
2515: $authtype = '<input type="radio" name="login" value="loc" '.
2516: $loccheck.' onchange="'.$jscall.'" onclick="'.
2517: $jscall.'" />';
2518: }
2519: $autharg = '<input type="text" size="10" name="locarg" value="'.
2520: $locarg.'" onchange="'.$jscall.'" />';
2521: $result = &mt('[_1] Local Authentication with argument [_2]',
2522: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2523: return $result;
2524: }
2525:
2526: sub authform_filesystem{
2527: my %in = (
2528: formname => 'document.cu',
2529: kerb_def_dom => 'MSU.EDU',
2530: @_,
2531: );
1.586 raeburn 2532: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2533: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2534: if (defined($in{'curr_authtype'})) {
2535: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2536: if ($can_assign{'fsys'}) {
1.772 bisitz 2537: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2538: if (defined($in{'mode'})) {
2539: if ($in{'mode'} eq 'modifyuser') {
2540: $fsyscheck = '';
2541: }
2542: }
1.586 raeburn 2543: } else {
2544: $result = &mt('Currently Filesystem Authenticated.');
2545: return $result;
2546: }
2547: }
2548: } else {
2549: if ($authnum == 1) {
1.784 bisitz 2550: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2551: }
2552: }
2553: if (!$can_assign{'fsys'}) {
2554: return;
1.587 raeburn 2555: } elsif ($authtype eq '') {
1.591 raeburn 2556: if (defined($in{'mode'})) {
1.587 raeburn 2557: if ($in{'mode'} eq 'modifycourse') {
2558: if ($authnum == 1) {
1.784 bisitz 2559: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2560: }
2561: }
2562: }
1.586 raeburn 2563: }
2564: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2565: if ($authtype eq '') {
2566: $authtype = '<input type="radio" name="login" value="fsys" '.
2567: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2568: $jscall.'" />';
2569: }
2570: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2571: ' onchange="'.$jscall.'" />';
2572: $result = &mt
1.144 matthew 2573: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2574: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2575: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2576: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2577: 'onchange="'.$jscall.'" />');
1.32 matthew 2578: return $result;
2579: }
2580:
1.586 raeburn 2581: sub get_assignable_auth {
2582: my ($dom) = @_;
2583: if ($dom eq '') {
2584: $dom = $env{'request.role.domain'};
2585: }
2586: my %can_assign = (
2587: krb4 => 1,
2588: krb5 => 1,
2589: int => 1,
2590: loc => 1,
2591: );
2592: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2593: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2594: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2595: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2596: my $context;
2597: if ($env{'request.role'} =~ /^au/) {
2598: $context = 'author';
2599: } elsif ($env{'request.role'} =~ /^dc/) {
2600: $context = 'domain';
2601: } elsif ($env{'request.course.id'}) {
2602: $context = 'course';
2603: }
2604: if ($context) {
2605: if (ref($authhash->{$context}) eq 'HASH') {
2606: %can_assign = %{$authhash->{$context}};
2607: }
2608: }
2609: }
2610: }
2611: my $authnum = 0;
2612: foreach my $key (keys(%can_assign)) {
2613: if ($can_assign{$key}) {
2614: $authnum ++;
2615: }
2616: }
2617: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2618: $authnum --;
2619: }
2620: return ($authnum,%can_assign);
2621: }
2622:
1.80 albertel 2623: ###############################################################
2624: ## Get Kerberos Defaults for Domain ##
2625: ###############################################################
2626: ##
2627: ## Returns default kerberos version and an associated argument
2628: ## as listed in file domain.tab. If not listed, provides
2629: ## appropriate default domain and kerberos version.
2630: ##
2631: #-------------------------------------------
2632:
2633: =pod
2634:
1.648 raeburn 2635: =item * &get_kerberos_defaults()
1.80 albertel 2636:
2637: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2638: version and domain. If not found, it defaults to version 4 and the
2639: domain of the server.
1.80 albertel 2640:
1.648 raeburn 2641: =over 4
2642:
1.80 albertel 2643: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2644:
1.648 raeburn 2645: =back
2646:
2647: =back
2648:
1.80 albertel 2649: =cut
2650:
2651: #-------------------------------------------
2652: sub get_kerberos_defaults {
2653: my $domain=shift;
1.641 raeburn 2654: my ($krbdef,$krbdefdom);
2655: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2656: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2657: $krbdef = $domdefaults{'auth_def'};
2658: $krbdefdom = $domdefaults{'auth_arg_def'};
2659: } else {
1.80 albertel 2660: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2661: my $krbdefdom=$1;
2662: $krbdefdom=~tr/a-z/A-Z/;
2663: $krbdef = "krb4";
2664: }
2665: return ($krbdef,$krbdefdom);
2666: }
1.112 bowersj2 2667:
1.32 matthew 2668:
1.46 matthew 2669: ###############################################################
2670: ## Thesaurus Functions ##
2671: ###############################################################
1.20 www 2672:
1.46 matthew 2673: =pod
1.20 www 2674:
1.112 bowersj2 2675: =head1 Thesaurus Functions
2676:
2677: =over 4
2678:
1.648 raeburn 2679: =item * &initialize_keywords()
1.46 matthew 2680:
2681: Initializes the package variable %Keywords if it is empty. Uses the
2682: package variable $thesaurus_db_file.
2683:
2684: =cut
2685:
2686: ###################################################
2687:
2688: sub initialize_keywords {
2689: return 1 if (scalar keys(%Keywords));
2690: # If we are here, %Keywords is empty, so fill it up
2691: # Make sure the file we need exists...
2692: if (! -e $thesaurus_db_file) {
2693: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2694: " failed because it does not exist");
2695: return 0;
2696: }
2697: # Set up the hash as a database
2698: my %thesaurus_db;
2699: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2700: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2701: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2702: $thesaurus_db_file);
2703: return 0;
2704: }
2705: # Get the average number of appearances of a word.
2706: my $avecount = $thesaurus_db{'average.count'};
2707: # Put keywords (those that appear > average) into %Keywords
2708: while (my ($word,$data)=each (%thesaurus_db)) {
2709: my ($count,undef) = split /:/,$data;
2710: $Keywords{$word}++ if ($count > $avecount);
2711: }
2712: untie %thesaurus_db;
2713: # Remove special values from %Keywords.
1.356 albertel 2714: foreach my $value ('total.count','average.count') {
2715: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2716: }
1.46 matthew 2717: return 1;
2718: }
2719:
2720: ###################################################
2721:
2722: =pod
2723:
1.648 raeburn 2724: =item * &keyword($word)
1.46 matthew 2725:
2726: Returns true if $word is a keyword. A keyword is a word that appears more
2727: than the average number of times in the thesaurus database. Calls
2728: &initialize_keywords
2729:
2730: =cut
2731:
2732: ###################################################
1.20 www 2733:
2734: sub keyword {
1.46 matthew 2735: return if (!&initialize_keywords());
2736: my $word=lc(shift());
2737: $word=~s/\W//g;
2738: return exists($Keywords{$word});
1.20 www 2739: }
1.46 matthew 2740:
2741: ###############################################################
2742:
2743: =pod
1.20 www 2744:
1.648 raeburn 2745: =item * &get_related_words()
1.46 matthew 2746:
1.160 matthew 2747: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2748: an array of words. If the keyword is not in the thesaurus, an empty array
2749: will be returned. The order of the words returned is determined by the
2750: database which holds them.
2751:
2752: Uses global $thesaurus_db_file.
2753:
2754: =cut
2755:
2756: ###############################################################
2757: sub get_related_words {
2758: my $keyword = shift;
2759: my %thesaurus_db;
2760: if (! -e $thesaurus_db_file) {
2761: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2762: "failed because the file does not exist");
2763: return ();
2764: }
2765: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2766: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2767: return ();
2768: }
2769: my @Words=();
1.429 www 2770: my $count=0;
1.46 matthew 2771: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2772: # The first element is the number of times
2773: # the word appears. We do not need it now.
1.429 www 2774: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2775: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2776: my $threshold=$mostfrequentcount/10;
2777: foreach my $possibleword (@RelatedWords) {
2778: my ($word,$wordcount)=split(/\,/,$possibleword);
2779: if ($wordcount>$threshold) {
2780: push(@Words,$word);
2781: $count++;
2782: if ($count>10) { last; }
2783: }
1.20 www 2784: }
2785: }
1.46 matthew 2786: untie %thesaurus_db;
2787: return @Words;
1.14 harris41 2788: }
1.46 matthew 2789:
1.112 bowersj2 2790: =pod
2791:
2792: =back
2793:
2794: =cut
1.61 www 2795:
2796: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2797: =pod
2798:
1.112 bowersj2 2799: =head1 User Name Functions
2800:
2801: =over 4
2802:
1.648 raeburn 2803: =item * &plainname($uname,$udom,$first)
1.81 albertel 2804:
1.112 bowersj2 2805: Takes a users logon name and returns it as a string in
1.226 albertel 2806: "first middle last generation" form
2807: if $first is set to 'lastname' then it returns it as
2808: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2809:
2810: =cut
1.61 www 2811:
1.295 www 2812:
1.81 albertel 2813: ###############################################################
1.61 www 2814: sub plainname {
1.226 albertel 2815: my ($uname,$udom,$first)=@_;
1.537 albertel 2816: return if (!defined($uname) || !defined($udom));
1.295 www 2817: my %names=&getnames($uname,$udom);
1.226 albertel 2818: my $name=&Apache::lonnet::format_name($names{'firstname'},
2819: $names{'middlename'},
2820: $names{'lastname'},
2821: $names{'generation'},$first);
2822: $name=~s/^\s+//;
1.62 www 2823: $name=~s/\s+$//;
2824: $name=~s/\s+/ /g;
1.353 albertel 2825: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2826: return $name;
1.61 www 2827: }
1.66 www 2828:
2829: # -------------------------------------------------------------------- Nickname
1.81 albertel 2830: =pod
2831:
1.648 raeburn 2832: =item * &nickname($uname,$udom)
1.81 albertel 2833:
2834: Gets a users name and returns it as a string as
2835:
2836: ""nickname""
1.66 www 2837:
1.81 albertel 2838: if the user has a nickname or
2839:
2840: "first middle last generation"
2841:
2842: if the user does not
2843:
2844: =cut
1.66 www 2845:
2846: sub nickname {
2847: my ($uname,$udom)=@_;
1.537 albertel 2848: return if (!defined($uname) || !defined($udom));
1.295 www 2849: my %names=&getnames($uname,$udom);
1.68 albertel 2850: my $name=$names{'nickname'};
1.66 www 2851: if ($name) {
2852: $name='"'.$name.'"';
2853: } else {
2854: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2855: $names{'lastname'}.' '.$names{'generation'};
2856: $name=~s/\s+$//;
2857: $name=~s/\s+/ /g;
2858: }
2859: return $name;
2860: }
2861:
1.295 www 2862: sub getnames {
2863: my ($uname,$udom)=@_;
1.537 albertel 2864: return if (!defined($uname) || !defined($udom));
1.433 albertel 2865: if ($udom eq 'public' && $uname eq 'public') {
2866: return ('lastname' => &mt('Public'));
2867: }
1.295 www 2868: my $id=$uname.':'.$udom;
2869: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2870: if ($cached) {
2871: return %{$names};
2872: } else {
2873: my %loadnames=&Apache::lonnet::get('environment',
2874: ['firstname','middlename','lastname','generation','nickname'],
2875: $udom,$uname);
2876: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2877: return %loadnames;
2878: }
2879: }
1.61 www 2880:
1.542 raeburn 2881: # -------------------------------------------------------------------- getemails
1.648 raeburn 2882:
1.542 raeburn 2883: =pod
2884:
1.648 raeburn 2885: =item * &getemails($uname,$udom)
1.542 raeburn 2886:
2887: Gets a user's email information and returns it as a hash with keys:
2888: notification, critnotification, permanentemail
2889:
2890: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2891: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2892:
1.648 raeburn 2893:
1.542 raeburn 2894: =cut
2895:
1.648 raeburn 2896:
1.466 albertel 2897: sub getemails {
2898: my ($uname,$udom)=@_;
2899: if ($udom eq 'public' && $uname eq 'public') {
2900: return;
2901: }
1.467 www 2902: if (!$udom) { $udom=$env{'user.domain'}; }
2903: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2904: my $id=$uname.':'.$udom;
2905: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2906: if ($cached) {
2907: return %{$names};
2908: } else {
2909: my %loadnames=&Apache::lonnet::get('environment',
2910: ['notification','critnotification',
2911: 'permanentemail'],
2912: $udom,$uname);
2913: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2914: return %loadnames;
2915: }
2916: }
2917:
1.551 albertel 2918: sub flush_email_cache {
2919: my ($uname,$udom)=@_;
2920: if (!$udom) { $udom =$env{'user.domain'}; }
2921: if (!$uname) { $uname=$env{'user.name'}; }
2922: return if ($udom eq 'public' && $uname eq 'public');
2923: my $id=$uname.':'.$udom;
2924: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2925: }
2926:
1.728 raeburn 2927: # -------------------------------------------------------------------- getlangs
2928:
2929: =pod
2930:
2931: =item * &getlangs($uname,$udom)
2932:
2933: Gets a user's language preference and returns it as a hash with key:
2934: language.
2935:
2936: =cut
2937:
2938:
2939: sub getlangs {
2940: my ($uname,$udom) = @_;
2941: if (!$udom) { $udom =$env{'user.domain'}; }
2942: if (!$uname) { $uname=$env{'user.name'}; }
2943: my $id=$uname.':'.$udom;
2944: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2945: if ($cached) {
2946: return %{$langs};
2947: } else {
2948: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2949: $udom,$uname);
2950: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2951: return %loadlangs;
2952: }
2953: }
2954:
2955: sub flush_langs_cache {
2956: my ($uname,$udom)=@_;
2957: if (!$udom) { $udom =$env{'user.domain'}; }
2958: if (!$uname) { $uname=$env{'user.name'}; }
2959: return if ($udom eq 'public' && $uname eq 'public');
2960: my $id=$uname.':'.$udom;
2961: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2962: }
2963:
1.61 www 2964: # ------------------------------------------------------------------ Screenname
1.81 albertel 2965:
2966: =pod
2967:
1.648 raeburn 2968: =item * &screenname($uname,$udom)
1.81 albertel 2969:
2970: Gets a users screenname and returns it as a string
2971:
2972: =cut
1.61 www 2973:
2974: sub screenname {
2975: my ($uname,$udom)=@_;
1.258 albertel 2976: if ($uname eq $env{'user.name'} &&
2977: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2978: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2979: return $names{'screenname'};
1.62 www 2980: }
2981:
1.212 albertel 2982:
1.802 bisitz 2983: # ------------------------------------------------------------- Confirm Wrapper
2984: =pod
2985:
2986: =item confirmwrapper
2987:
2988: Wrap messages about completion of operation in box
2989:
2990: =cut
2991:
2992: sub confirmwrapper {
2993: my ($message)=@_;
2994: if ($message) {
2995: return "\n".'<div class="LC_confirm_box">'."\n"
2996: .$message."\n"
2997: .'</div>'."\n";
2998: } else {
2999: return $message;
3000: }
3001: }
3002:
1.62 www 3003: # ------------------------------------------------------------- Message Wrapper
3004:
3005: sub messagewrapper {
1.369 www 3006: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3007: return
1.441 albertel 3008: '<a href="/adm/email?compose=individual&'.
3009: 'recname='.$username.'&recdom='.$domain.
3010: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3011: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3012: }
1.802 bisitz 3013:
1.74 www 3014: # --------------------------------------------------------------- Notes Wrapper
3015:
3016: sub noteswrapper {
3017: my ($link,$un,$do)=@_;
3018: return
1.896 amueller 3019: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3020: }
1.802 bisitz 3021:
1.62 www 3022: # ------------------------------------------------------------- Aboutme Wrapper
3023:
3024: sub aboutmewrapper {
1.166 www 3025: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3026: if (!defined($username) && !defined($domain)) {
3027: return;
3028: }
1.892 amueller 3029: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3030: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3031: }
3032:
3033: # ------------------------------------------------------------ Syllabus Wrapper
3034:
3035: sub syllabuswrapper {
1.707 bisitz 3036: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3037: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3038: }
1.14 harris41 3039:
1.802 bisitz 3040: # -----------------------------------------------------------------------------
3041:
1.208 matthew 3042: sub track_student_link {
1.887 raeburn 3043: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3044: my $link ="/adm/trackstudent?";
1.208 matthew 3045: my $title = 'View recent activity';
3046: if (defined($sname) && $sname !~ /^\s*$/ &&
3047: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3048: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3049: $title .= ' of this student';
1.268 albertel 3050: }
1.208 matthew 3051: if (defined($target) && $target !~ /^\s*$/) {
3052: $target = qq{target="$target"};
3053: } else {
3054: $target = '';
3055: }
1.268 albertel 3056: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3057: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3058: $title = &mt($title);
3059: $linktext = &mt($linktext);
1.448 albertel 3060: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3061: &help_open_topic('View_recent_activity');
1.208 matthew 3062: }
3063:
1.781 raeburn 3064: sub slot_reservations_link {
3065: my ($linktext,$sname,$sdom,$target) = @_;
3066: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3067: my $title = 'View slot reservation history';
3068: if (defined($sname) && $sname !~ /^\s*$/ &&
3069: defined($sdom) && $sdom !~ /^\s*$/) {
3070: $link .= "&uname=$sname&udom=$sdom";
3071: $title .= ' of this student';
3072: }
3073: if (defined($target) && $target !~ /^\s*$/) {
3074: $target = qq{target="$target"};
3075: } else {
3076: $target = '';
3077: }
3078: $title = &mt($title);
3079: $linktext = &mt($linktext);
3080: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3081: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3082:
3083: }
3084:
1.508 www 3085: # ===================================================== Display a student photo
3086:
3087:
1.509 albertel 3088: sub student_image_tag {
1.508 www 3089: my ($domain,$user)=@_;
3090: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3091: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3092: return '<img src="'.$imgsrc.'" align="right" />';
3093: } else {
3094: return '';
3095: }
3096: }
3097:
1.112 bowersj2 3098: =pod
3099:
3100: =back
3101:
3102: =head1 Access .tab File Data
3103:
3104: =over 4
3105:
1.648 raeburn 3106: =item * &languageids()
1.112 bowersj2 3107:
3108: returns list of all language ids
3109:
3110: =cut
3111:
1.14 harris41 3112: sub languageids {
1.16 harris41 3113: return sort(keys(%language));
1.14 harris41 3114: }
3115:
1.112 bowersj2 3116: =pod
3117:
1.648 raeburn 3118: =item * &languagedescription()
1.112 bowersj2 3119:
3120: returns description of a specified language id
3121:
3122: =cut
3123:
1.14 harris41 3124: sub languagedescription {
1.125 www 3125: my $code=shift;
3126: return ($supported_language{$code}?'* ':'').
3127: $language{$code}.
1.126 www 3128: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3129: }
3130:
3131: sub plainlanguagedescription {
3132: my $code=shift;
3133: return $language{$code};
3134: }
3135:
3136: sub supportedlanguagecode {
3137: my $code=shift;
3138: return $supported_language{$code};
1.97 www 3139: }
3140:
1.112 bowersj2 3141: =pod
3142:
1.648 raeburn 3143: =item * ©rightids()
1.112 bowersj2 3144:
3145: returns list of all copyrights
3146:
3147: =cut
3148:
3149: sub copyrightids {
3150: return sort(keys(%cprtag));
3151: }
3152:
3153: =pod
3154:
1.648 raeburn 3155: =item * ©rightdescription()
1.112 bowersj2 3156:
3157: returns description of a specified copyright id
3158:
3159: =cut
3160:
3161: sub copyrightdescription {
1.166 www 3162: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3163: }
1.197 matthew 3164:
3165: =pod
3166:
1.648 raeburn 3167: =item * &source_copyrightids()
1.192 taceyjo1 3168:
3169: returns list of all source copyrights
3170:
3171: =cut
3172:
3173: sub source_copyrightids {
3174: return sort(keys(%scprtag));
3175: }
3176:
3177: =pod
3178:
1.648 raeburn 3179: =item * &source_copyrightdescription()
1.192 taceyjo1 3180:
3181: returns description of a specified source copyright id
3182:
3183: =cut
3184:
3185: sub source_copyrightdescription {
3186: return &mt($scprtag{shift(@_)});
3187: }
1.112 bowersj2 3188:
3189: =pod
3190:
1.648 raeburn 3191: =item * &filecategories()
1.112 bowersj2 3192:
3193: returns list of all file categories
3194:
3195: =cut
3196:
3197: sub filecategories {
3198: return sort(keys(%category_extensions));
3199: }
3200:
3201: =pod
3202:
1.648 raeburn 3203: =item * &filecategorytypes()
1.112 bowersj2 3204:
3205: returns list of file types belonging to a given file
3206: category
3207:
3208: =cut
3209:
3210: sub filecategorytypes {
1.356 albertel 3211: my ($cat) = @_;
3212: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3213: }
3214:
3215: =pod
3216:
1.648 raeburn 3217: =item * &fileembstyle()
1.112 bowersj2 3218:
3219: returns embedding style for a specified file type
3220:
3221: =cut
3222:
3223: sub fileembstyle {
3224: return $fe{lc(shift(@_))};
1.169 www 3225: }
3226:
1.351 www 3227: sub filemimetype {
3228: return $fm{lc(shift(@_))};
3229: }
3230:
1.169 www 3231:
3232: sub filecategoryselect {
3233: my ($name,$value)=@_;
1.189 matthew 3234: return &select_form($value,$name,
1.169 www 3235: '' => &mt('Any category'),
3236: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3237: }
3238:
3239: =pod
3240:
1.648 raeburn 3241: =item * &filedescription()
1.112 bowersj2 3242:
3243: returns description for a specified file type
3244:
3245: =cut
3246:
3247: sub filedescription {
1.188 matthew 3248: my $file_description = $fd{lc(shift())};
3249: $file_description =~ s:([\[\]]):~$1:g;
3250: return &mt($file_description);
1.112 bowersj2 3251: }
3252:
3253: =pod
3254:
1.648 raeburn 3255: =item * &filedescriptionex()
1.112 bowersj2 3256:
3257: returns description for a specified file type with
3258: extra formatting
3259:
3260: =cut
3261:
3262: sub filedescriptionex {
3263: my $ex=shift;
1.188 matthew 3264: my $file_description = $fd{lc($ex)};
3265: $file_description =~ s:([\[\]]):~$1:g;
3266: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3267: }
3268:
3269: # End of .tab access
3270: =pod
3271:
3272: =back
3273:
3274: =cut
3275:
3276: # ------------------------------------------------------------------ File Types
3277: sub fileextensions {
3278: return sort(keys(%fe));
3279: }
3280:
1.97 www 3281: # ----------------------------------------------------------- Display Languages
3282: # returns a hash with all desired display languages
3283: #
3284:
3285: sub display_languages {
3286: my %languages=();
1.695 raeburn 3287: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3288: $languages{$lang}=1;
1.97 www 3289: }
3290: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3291: if ($env{'form.displaylanguage'}) {
1.356 albertel 3292: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3293: $languages{$lang}=1;
1.97 www 3294: }
3295: }
3296: return %languages;
1.14 harris41 3297: }
3298:
1.582 albertel 3299: sub languages {
3300: my ($possible_langs) = @_;
1.695 raeburn 3301: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3302: if (!ref($possible_langs)) {
3303: if( wantarray ) {
3304: return @preferred_langs;
3305: } else {
3306: return $preferred_langs[0];
3307: }
3308: }
3309: my %possibilities = map { $_ => 1 } (@$possible_langs);
3310: my @preferred_possibilities;
3311: foreach my $preferred_lang (@preferred_langs) {
3312: if (exists($possibilities{$preferred_lang})) {
3313: push(@preferred_possibilities, $preferred_lang);
3314: }
3315: }
3316: if( wantarray ) {
3317: return @preferred_possibilities;
3318: }
3319: return $preferred_possibilities[0];
3320: }
3321:
1.742 raeburn 3322: sub user_lang {
3323: my ($touname,$toudom,$fromcid) = @_;
3324: my @userlangs;
3325: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3326: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3327: $env{'course.'.$fromcid.'.languages'}));
3328: } else {
3329: my %langhash = &getlangs($touname,$toudom);
3330: if ($langhash{'languages'} ne '') {
3331: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3332: } else {
3333: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3334: if ($domdefs{'lang_def'} ne '') {
3335: @userlangs = ($domdefs{'lang_def'});
3336: }
3337: }
3338: }
3339: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3340: my $user_lh = Apache::localize->get_handle(@languages);
3341: return $user_lh;
3342: }
3343:
3344:
1.112 bowersj2 3345: ###############################################################
3346: ## Student Answer Attempts ##
3347: ###############################################################
3348:
3349: =pod
3350:
3351: =head1 Alternate Problem Views
3352:
3353: =over 4
3354:
1.648 raeburn 3355: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3356: $getattempt, $regexp, $gradesub)
3357:
3358: Return string with previous attempt on problem. Arguments:
3359:
3360: =over 4
3361:
3362: =item * $symb: Problem, including path
3363:
3364: =item * $username: username of the desired student
3365:
3366: =item * $domain: domain of the desired student
1.14 harris41 3367:
1.112 bowersj2 3368: =item * $course: Course ID
1.14 harris41 3369:
1.112 bowersj2 3370: =item * $getattempt: Leave blank for all attempts, otherwise put
3371: something
1.14 harris41 3372:
1.112 bowersj2 3373: =item * $regexp: if string matches this regexp, the string will be
3374: sent to $gradesub
1.14 harris41 3375:
1.112 bowersj2 3376: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3377:
1.112 bowersj2 3378: =back
1.14 harris41 3379:
1.112 bowersj2 3380: The output string is a table containing all desired attempts, if any.
1.16 harris41 3381:
1.112 bowersj2 3382: =cut
1.1 albertel 3383:
3384: sub get_previous_attempt {
1.43 ng 3385: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3386: my $prevattempts='';
1.43 ng 3387: no strict 'refs';
1.1 albertel 3388: if ($symb) {
1.3 albertel 3389: my (%returnhash)=
3390: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3391: if ($returnhash{'version'}) {
3392: my %lasthash=();
3393: my $version;
3394: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3395: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3396: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3397: }
1.1 albertel 3398: }
1.596 albertel 3399: $prevattempts=&start_data_table().&start_data_table_header_row();
3400: $prevattempts.='<th>'.&mt('History').'</th>';
1.945 raeburn 3401: my %typeparts;
3402: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3403: foreach my $key (sort(keys(%lasthash))) {
3404: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3405: if ($#parts > 0) {
1.31 albertel 3406: my $data=$parts[-1];
3407: pop(@parts);
1.945 raeburn 3408: if ($data eq 'type') {
3409: unless ($showsurv) {
3410: my $id = join(',',@parts);
3411: $typeparts{$ign.'.'.$id} = $lasthash{$key};
3412: }
3413: delete($lasthash{$key});
3414: } else {
3415: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3416: }
1.31 albertel 3417: } else {
1.41 ng 3418: if ($#parts == 0) {
3419: $prevattempts.='<th>'.$parts[0].'</th>';
3420: } else {
3421: $prevattempts.='<th>'.$ign.'</th>';
3422: }
1.31 albertel 3423: }
1.16 harris41 3424: }
1.596 albertel 3425: $prevattempts.=&end_data_table_header_row();
1.945 raeburn 3426: my %lasthidden;
1.40 ng 3427: if ($getattempt eq '') {
3428: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3429: my @hidden;
3430: if (%typeparts) {
3431: foreach my $id (keys(%typeparts)) {
3432: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3433: push(@hidden,$id);
3434: $lasthidden{$id} = 1;
3435: } elsif ($lasthidden{$id}) {
3436: if (exists($returnhash{$version.':'.$id.'.award'})) {
3437: delete($lasthidden{$id});
3438: }
3439: }
3440: }
3441: }
3442: $prevattempts.=&start_data_table_row().
3443: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3444: if (@hidden) {
3445: foreach my $key (sort(keys(%lasthash))) {
3446: my $hide;
3447: foreach my $id (@hidden) {
3448: if ($key =~ /^\Q$id\E/) {
3449: $hide = 1;
3450: last;
3451: }
3452: }
3453: if ($hide) {
3454: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3455: if (($data eq 'award') || ($data eq 'awarddetail')) {
3456: my $value = &format_previous_attempt_value($key,
3457: $returnhash{$version.':'.$key});
3458: $prevattempts.='<td>'.$value.' </td>';
3459: } else {
3460: $prevattempts.='<td> </td>';
3461: }
3462: } else {
3463: if ($key =~ /\./) {
3464: my $value = &format_previous_attempt_value($key,
3465: $returnhash{$version.':'.$key});
3466: $prevattempts.='<td>'.$value.' </td>';
3467: } else {
3468: $prevattempts.='<td> </td>';
3469: }
3470: }
3471: }
3472: } else {
3473: foreach my $key (sort(keys(%lasthash))) {
3474: my $value = &format_previous_attempt_value($key,
3475: $returnhash{$version.':'.$key});
3476: $prevattempts.='<td>'.$value.' </td>';
3477: }
3478: }
3479: $prevattempts.=&end_data_table_row();
1.40 ng 3480: }
1.1 albertel 3481: }
1.945 raeburn 3482: my @currhidden = keys(%lasthidden);
1.596 albertel 3483: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3484: foreach my $key (sort(keys(%lasthash))) {
1.945 raeburn 3485: if (%typeparts) {
3486: my $hidden;
3487: foreach my $id (@currhidden) {
3488: if ($key =~ /^\Q$id\E/) {
3489: $hidden = 1;
3490: last;
3491: }
3492: }
3493: if ($hidden) {
3494: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3495: if (($data eq 'award') || ($data eq 'awarddetail')) {
3496: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3497: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3498: $value = &$gradesub($value);
3499: }
3500: $prevattempts.='<td>'.$value.' </td>';
3501: } else {
3502: $prevattempts.='<td> </td>';
3503: }
3504: } else {
3505: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3506: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3507: $value = &$gradesub($value);
3508: }
3509: $prevattempts.='<td>'.$value.' </td>';
3510: }
3511: } else {
3512: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3513: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3514: $value = &$gradesub($value);
3515: }
3516: $prevattempts.='<td>'.$value.' </td>';
3517: }
1.16 harris41 3518: }
1.596 albertel 3519: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3520: } else {
1.596 albertel 3521: $prevattempts=
3522: &start_data_table().&start_data_table_row().
3523: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3524: &end_data_table_row().&end_data_table();
1.1 albertel 3525: }
3526: } else {
1.596 albertel 3527: $prevattempts=
3528: &start_data_table().&start_data_table_row().
3529: '<td>'.&mt('No data.').'</td>'.
3530: &end_data_table_row().&end_data_table();
1.1 albertel 3531: }
1.10 albertel 3532: }
3533:
1.581 albertel 3534: sub format_previous_attempt_value {
3535: my ($key,$value) = @_;
3536: if ($key =~ /timestamp/) {
3537: $value = &Apache::lonlocal::locallocaltime($value);
3538: } elsif (ref($value) eq 'ARRAY') {
3539: $value = '('.join(', ', @{ $value }).')';
3540: } else {
3541: $value = &unescape($value);
3542: }
3543: return $value;
3544: }
3545:
3546:
1.107 albertel 3547: sub relative_to_absolute {
3548: my ($url,$output)=@_;
3549: my $parser=HTML::TokeParser->new(\$output);
3550: my $token;
3551: my $thisdir=$url;
3552: my @rlinks=();
3553: while ($token=$parser->get_token) {
3554: if ($token->[0] eq 'S') {
3555: if ($token->[1] eq 'a') {
3556: if ($token->[2]->{'href'}) {
3557: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3558: }
3559: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3560: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3561: } elsif ($token->[1] eq 'base') {
3562: $thisdir=$token->[2]->{'href'};
3563: }
3564: }
3565: }
3566: $thisdir=~s-/[^/]*$--;
1.356 albertel 3567: foreach my $link (@rlinks) {
1.726 raeburn 3568: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3569: ($link=~/^\//) ||
3570: ($link=~/^javascript:/i) ||
3571: ($link=~/^mailto:/i) ||
3572: ($link=~/^\#/)) {
3573: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3574: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3575: }
3576: }
3577: # -------------------------------------------------- Deal with Applet codebases
3578: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3579: return $output;
3580: }
3581:
1.112 bowersj2 3582: =pod
3583:
1.648 raeburn 3584: =item * &get_student_view()
1.112 bowersj2 3585:
3586: show a snapshot of what student was looking at
3587:
3588: =cut
3589:
1.10 albertel 3590: sub get_student_view {
1.186 albertel 3591: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3592: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3593: my (%form);
1.10 albertel 3594: my @elements=('symb','courseid','domain','username');
3595: foreach my $element (@elements) {
1.186 albertel 3596: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3597: }
1.186 albertel 3598: if (defined($moreenv)) {
3599: %form=(%form,%{$moreenv});
3600: }
1.236 albertel 3601: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3602: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3603: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3604: $userview=~s/\<body[^\>]*\>//gi;
3605: $userview=~s/\<\/body\>//gi;
3606: $userview=~s/\<html\>//gi;
3607: $userview=~s/\<\/html\>//gi;
3608: $userview=~s/\<head\>//gi;
3609: $userview=~s/\<\/head\>//gi;
3610: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3611: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3612: if (wantarray) {
3613: return ($userview,$response);
3614: } else {
3615: return $userview;
3616: }
3617: }
3618:
3619: sub get_student_view_with_retries {
3620: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3621:
3622: my $ok = 0; # True if we got a good response.
3623: my $content;
3624: my $response;
3625:
3626: # Try to get the student_view done. within the retries count:
3627:
3628: do {
3629: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3630: $ok = $response->is_success;
3631: if (!$ok) {
3632: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3633: }
3634: $retries--;
3635: } while (!$ok && ($retries > 0));
3636:
3637: if (!$ok) {
3638: $content = ''; # On error return an empty content.
3639: }
1.651 www 3640: if (wantarray) {
3641: return ($content, $response);
3642: } else {
3643: return $content;
3644: }
1.11 albertel 3645: }
3646:
1.112 bowersj2 3647: =pod
3648:
1.648 raeburn 3649: =item * &get_student_answers()
1.112 bowersj2 3650:
3651: show a snapshot of how student was answering problem
3652:
3653: =cut
3654:
1.11 albertel 3655: sub get_student_answers {
1.100 sakharuk 3656: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3657: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3658: my (%moreenv);
1.11 albertel 3659: my @elements=('symb','courseid','domain','username');
3660: foreach my $element (@elements) {
1.186 albertel 3661: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3662: }
1.186 albertel 3663: $moreenv{'grade_target'}='answer';
3664: %moreenv=(%form,%moreenv);
1.497 raeburn 3665: $feedurl = &Apache::lonnet::clutter($feedurl);
3666: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3667: return $userview;
1.1 albertel 3668: }
1.116 albertel 3669:
3670: =pod
3671:
3672: =item * &submlink()
3673:
1.242 albertel 3674: Inputs: $text $uname $udom $symb $target
1.116 albertel 3675:
3676: Returns: A link to grades.pm such as to see the SUBM view of a student
3677:
3678: =cut
3679:
3680: ###############################################
3681: sub submlink {
1.242 albertel 3682: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3683: if (!($uname && $udom)) {
3684: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3685: &Apache::lonnet::whichuser($symb);
1.116 albertel 3686: if (!$symb) { $symb=$cursymb; }
3687: }
1.254 matthew 3688: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3689: $symb=&escape($symb);
1.242 albertel 3690: if ($target) { $target="target=\"$target\""; }
3691: return '<a href="/adm/grades?&command=submission&'.
3692: 'symb='.$symb.'&student='.$uname.
3693: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3694: }
3695: ##############################################
3696:
3697: =pod
3698:
3699: =item * &pgrdlink()
3700:
3701: Inputs: $text $uname $udom $symb $target
3702:
3703: Returns: A link to grades.pm such as to see the PGRD view of a student
3704:
3705: =cut
3706:
3707: ###############################################
3708: sub pgrdlink {
3709: my $link=&submlink(@_);
3710: $link=~s/(&command=submission)/$1&showgrading=yes/;
3711: return $link;
3712: }
3713: ##############################################
3714:
3715: =pod
3716:
3717: =item * &pprmlink()
3718:
3719: Inputs: $text $uname $udom $symb $target
3720:
3721: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3722: student and a specific resource
1.242 albertel 3723:
3724: =cut
3725:
3726: ###############################################
3727: sub pprmlink {
3728: my ($text,$uname,$udom,$symb,$target)=@_;
3729: if (!($uname && $udom)) {
3730: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3731: &Apache::lonnet::whichuser($symb);
1.242 albertel 3732: if (!$symb) { $symb=$cursymb; }
3733: }
1.254 matthew 3734: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3735: $symb=&escape($symb);
1.242 albertel 3736: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3737: return '<a href="/adm/parmset?command=set&'.
3738: 'symb='.$symb.'&uname='.$uname.
3739: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3740: }
3741: ##############################################
1.37 matthew 3742:
1.112 bowersj2 3743: =pod
3744:
3745: =back
3746:
3747: =cut
3748:
1.37 matthew 3749: ###############################################
1.51 www 3750:
3751:
3752: sub timehash {
1.687 raeburn 3753: my ($thistime) = @_;
3754: my $timezone = &Apache::lonlocal::gettimezone();
3755: my $dt = DateTime->from_epoch(epoch => $thistime)
3756: ->set_time_zone($timezone);
3757: my $wday = $dt->day_of_week();
3758: if ($wday == 7) { $wday = 0; }
3759: return ( 'second' => $dt->second(),
3760: 'minute' => $dt->minute(),
3761: 'hour' => $dt->hour(),
3762: 'day' => $dt->day_of_month(),
3763: 'month' => $dt->month(),
3764: 'year' => $dt->year(),
3765: 'weekday' => $wday,
3766: 'dayyear' => $dt->day_of_year(),
3767: 'dlsav' => $dt->is_dst() );
1.51 www 3768: }
3769:
1.370 www 3770: sub utc_string {
3771: my ($date)=@_;
1.371 www 3772: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3773: }
3774:
1.51 www 3775: sub maketime {
3776: my %th=@_;
1.687 raeburn 3777: my ($epoch_time,$timezone,$dt);
3778: $timezone = &Apache::lonlocal::gettimezone();
3779: eval {
3780: $dt = DateTime->new( year => $th{'year'},
3781: month => $th{'month'},
3782: day => $th{'day'},
3783: hour => $th{'hour'},
3784: minute => $th{'minute'},
3785: second => $th{'second'},
3786: time_zone => $timezone,
3787: );
3788: };
3789: if (!$@) {
3790: $epoch_time = $dt->epoch;
3791: if ($epoch_time) {
3792: return $epoch_time;
3793: }
3794: }
1.51 www 3795: return POSIX::mktime(
3796: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3797: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3798: }
3799:
3800: #########################################
1.51 www 3801:
3802: sub findallcourses {
1.482 raeburn 3803: my ($roles,$uname,$udom) = @_;
1.355 albertel 3804: my %roles;
3805: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3806: my %courses;
1.51 www 3807: my $now=time;
1.482 raeburn 3808: if (!defined($uname)) {
3809: $uname = $env{'user.name'};
3810: }
3811: if (!defined($udom)) {
3812: $udom = $env{'user.domain'};
3813: }
3814: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3815: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3816: if (!%roles) {
3817: %roles = (
3818: cc => 1,
1.907 raeburn 3819: co => 1,
1.482 raeburn 3820: in => 1,
3821: ep => 1,
3822: ta => 1,
3823: cr => 1,
3824: st => 1,
3825: );
3826: }
3827: foreach my $entry (keys(%roleshash)) {
3828: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3829: if ($trole =~ /^cr/) {
3830: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3831: } else {
3832: next if (!exists($roles{$trole}));
3833: }
3834: if ($tend) {
3835: next if ($tend < $now);
3836: }
3837: if ($tstart) {
3838: next if ($tstart > $now);
3839: }
3840: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3841: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3842: if ($secpart eq '') {
3843: ($cnum,$role) = split(/_/,$cnumpart);
3844: $sec = 'none';
3845: $realsec = '';
3846: } else {
3847: $cnum = $cnumpart;
3848: ($sec,$role) = split(/_/,$secpart);
3849: $realsec = $sec;
1.490 raeburn 3850: }
1.482 raeburn 3851: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3852: }
3853: } else {
3854: foreach my $key (keys(%env)) {
1.483 albertel 3855: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3856: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3857: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3858: next if ($role eq 'ca' || $role eq 'aa');
3859: next if (%roles && !exists($roles{$role}));
3860: my ($starttime,$endtime)=split(/\./,$env{$key});
3861: my $active=1;
3862: if ($starttime) {
3863: if ($now<$starttime) { $active=0; }
3864: }
3865: if ($endtime) {
3866: if ($now>$endtime) { $active=0; }
3867: }
3868: if ($active) {
3869: if ($sec eq '') {
3870: $sec = 'none';
3871: }
3872: $courses{$cdom.'_'.$cnum}{$sec} =
3873: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3874: }
3875: }
1.51 www 3876: }
3877: }
1.474 raeburn 3878: return %courses;
1.51 www 3879: }
1.37 matthew 3880:
1.54 www 3881: ###############################################
1.474 raeburn 3882:
3883: sub blockcheck {
1.482 raeburn 3884: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3885:
3886: if (!defined($udom)) {
3887: $udom = $env{'user.domain'};
3888: }
3889: if (!defined($uname)) {
3890: $uname = $env{'user.name'};
3891: }
3892:
3893: # If uname and udom are for a course, check for blocks in the course.
3894:
3895: if (&Apache::lonnet::is_course($udom,$uname)) {
3896: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3897: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3898: return ($startblock,$endblock);
3899: }
1.474 raeburn 3900:
1.502 raeburn 3901: my $startblock = 0;
3902: my $endblock = 0;
1.482 raeburn 3903: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3904:
1.490 raeburn 3905: # If uname is for a user, and activity is course-specific, i.e.,
3906: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3907:
1.490 raeburn 3908: if (($activity eq 'boards' || $activity eq 'chat' ||
3909: $activity eq 'groups') && ($env{'request.course.id'})) {
3910: foreach my $key (keys(%live_courses)) {
3911: if ($key ne $env{'request.course.id'}) {
3912: delete($live_courses{$key});
3913: }
3914: }
3915: }
3916:
3917: my $otheruser = 0;
3918: my %own_courses;
3919: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3920: # Resource belongs to user other than current user.
3921: $otheruser = 1;
3922: # Gather courses for current user
3923: %own_courses =
3924: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3925: }
3926:
3927: # Gather active course roles - course coordinator, instructor,
3928: # exam proctor, ta, student, or custom role.
1.474 raeburn 3929:
3930: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3931: my ($cdom,$cnum);
3932: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3933: $cdom = $env{'course.'.$course.'.domain'};
3934: $cnum = $env{'course.'.$course.'.num'};
3935: } else {
1.490 raeburn 3936: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3937: }
3938: my $no_ownblock = 0;
3939: my $no_userblock = 0;
1.533 raeburn 3940: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3941: # Check if current user has 'evb' priv for this
3942: if (defined($own_courses{$course})) {
3943: foreach my $sec (keys(%{$own_courses{$course}})) {
3944: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3945: if ($sec ne 'none') {
3946: $checkrole .= '/'.$sec;
3947: }
3948: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3949: $no_ownblock = 1;
3950: last;
3951: }
3952: }
3953: }
3954: # if they have 'evb' priv and are currently not playing student
3955: next if (($no_ownblock) &&
3956: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3957: }
1.474 raeburn 3958: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3959: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3960: if ($sec ne 'none') {
1.482 raeburn 3961: $checkrole .= '/'.$sec;
1.474 raeburn 3962: }
1.490 raeburn 3963: if ($otheruser) {
3964: # Resource belongs to user other than current user.
3965: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3966: my ($trole,$tdom,$tnum,$tsec);
3967: my $entry = $live_courses{$course}{$sec};
3968: if ($entry =~ /^cr/) {
3969: ($trole,$tdom,$tnum,$tsec) =
3970: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3971: } else {
3972: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3973: }
3974: my ($spec,$area,$trest,%allroles,%userroles);
3975: $area = '/'.$tdom.'/'.$tnum;
3976: $trest = $tnum;
3977: if ($tsec ne '') {
3978: $area .= '/'.$tsec;
3979: $trest .= '/'.$tsec;
3980: }
3981: $spec = $trole.'.'.$area;
3982: if ($trole =~ /^cr/) {
3983: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3984: $tdom,$spec,$trest,$area);
3985: } else {
3986: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3987: $tdom,$spec,$trest,$area);
3988: }
3989: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3990: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3991: if ($1) {
3992: $no_userblock = 1;
3993: last;
3994: }
3995: }
1.490 raeburn 3996: } else {
3997: # Resource belongs to current user
3998: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3999: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4000: $no_ownblock = 1;
4001: last;
4002: }
1.474 raeburn 4003: }
4004: }
4005: # if they have the evb priv and are currently not playing student
1.482 raeburn 4006: next if (($no_ownblock) &&
1.491 albertel 4007: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4008: next if ($no_userblock);
1.474 raeburn 4009:
1.866 kalberla 4010: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4011: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4012:
4013: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4014: if (($start != 0) &&
4015: (($startblock == 0) || ($startblock > $start))) {
4016: $startblock = $start;
4017: }
4018: if (($end != 0) &&
4019: (($endblock == 0) || ($endblock < $end))) {
4020: $endblock = $end;
4021: }
1.490 raeburn 4022: }
4023: return ($startblock,$endblock);
4024: }
4025:
4026: sub get_blocks {
4027: my ($setters,$activity,$cdom,$cnum) = @_;
4028: my $startblock = 0;
4029: my $endblock = 0;
4030: my $course = $cdom.'_'.$cnum;
4031: $setters->{$course} = {};
4032: $setters->{$course}{'staff'} = [];
4033: $setters->{$course}{'times'} = [];
4034: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4035: foreach my $record (keys(%records)) {
4036: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4037: if ($start <= time && $end >= time) {
4038: my ($staff_name,$staff_dom,$title,$blocks) =
4039: &parse_block_record($records{$record});
4040: if ($blocks->{$activity} eq 'on') {
4041: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4042: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4043: if ( ($startblock == 0) || ($startblock > $start) ) {
4044: $startblock = $start;
1.490 raeburn 4045: }
1.491 albertel 4046: if ( ($endblock == 0) || ($endblock < $end) ) {
4047: $endblock = $end;
1.474 raeburn 4048: }
4049: }
4050: }
4051: }
4052: return ($startblock,$endblock);
4053: }
4054:
4055: sub parse_block_record {
4056: my ($record) = @_;
4057: my ($setuname,$setudom,$title,$blocks);
4058: if (ref($record) eq 'HASH') {
4059: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4060: $title = &unescape($record->{'event'});
4061: $blocks = $record->{'blocks'};
4062: } else {
4063: my @data = split(/:/,$record,3);
4064: if (scalar(@data) eq 2) {
4065: $title = $data[1];
4066: ($setuname,$setudom) = split(/@/,$data[0]);
4067: } else {
4068: ($setuname,$setudom,$title) = @data;
4069: }
4070: $blocks = { 'com' => 'on' };
4071: }
4072: return ($setuname,$setudom,$title,$blocks);
4073: }
4074:
1.854 kalberla 4075: sub blocking_status {
4076: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4077: my %setters;
1.890 droeschl 4078:
4079: # check for active blocking
1.867 kalberla 4080: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4081:
1.890 droeschl 4082: my $blocked = $startblock && $endblock ? 1 : 0;
4083:
4084: # caller just wants to know whether a block is active
4085: if (!wantarray) { return $blocked; }
4086:
4087: # build a link to a popup window containing the details
4088: my $querystring = "?activity=$activity";
4089: # $uname and $udom decide whose portfolio the user is trying to look at
4090: $querystring .= "&udom=$udom" if $udom;
4091: $querystring .= "&uname=$uname" if $uname;
4092:
4093: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4094: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4095: var options = "width=" + w + ",height=" + h + ",";
4096: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4097: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4098: var newWin = window.open(url, wdwName, options);
4099: newWin.focus();
4100: }
1.890 droeschl 4101: END_MYBLOCK
1.854 kalberla 4102:
1.890 droeschl 4103: $output = Apache::lonhtmlcommon::scripttag($output);
4104:
1.854 kalberla 4105: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4106: my $text = mt('Communication Blocked');
4107:
1.867 kalberla 4108: $output .= <<"END_BLOCK";
4109: <div class='LC_comblock'>
1.869 kalberla 4110: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4111: title='$text'>
4112: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4113: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4114: title='$text'>$text</a>
1.867 kalberla 4115: </div>
4116:
4117: END_BLOCK
1.474 raeburn 4118:
1.854 kalberla 4119: return ($blocked, $output);
4120: }
1.490 raeburn 4121:
1.60 matthew 4122: ###############################################
4123:
1.682 raeburn 4124: sub check_ip_acc {
4125: my ($acc)=@_;
4126: &Apache::lonxml::debug("acc is $acc");
4127: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4128: return 1;
4129: }
4130: my $allowed=0;
4131: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4132:
4133: my $name;
4134: foreach my $pattern (split(',',$acc)) {
4135: $pattern =~ s/^\s*//;
4136: $pattern =~ s/\s*$//;
4137: if ($pattern =~ /\*$/) {
4138: #35.8.*
4139: $pattern=~s/\*//;
4140: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4141: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4142: #35.8.3.[34-56]
4143: my $low=$2;
4144: my $high=$3;
4145: $pattern=$1;
4146: if ($ip =~ /^\Q$pattern\E/) {
4147: my $last=(split(/\./,$ip))[3];
4148: if ($last <=$high && $last >=$low) { $allowed=1; }
4149: }
4150: } elsif ($pattern =~ /^\*/) {
4151: #*.msu.edu
4152: $pattern=~s/\*//;
4153: if (!defined($name)) {
4154: use Socket;
4155: my $netaddr=inet_aton($ip);
4156: ($name)=gethostbyaddr($netaddr,AF_INET);
4157: }
4158: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4159: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4160: #127.0.0.1
4161: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4162: } else {
4163: #some.name.com
4164: if (!defined($name)) {
4165: use Socket;
4166: my $netaddr=inet_aton($ip);
4167: ($name)=gethostbyaddr($netaddr,AF_INET);
4168: }
4169: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4170: }
4171: if ($allowed) { last; }
4172: }
4173: return $allowed;
4174: }
4175:
4176: ###############################################
4177:
1.60 matthew 4178: =pod
4179:
1.112 bowersj2 4180: =head1 Domain Template Functions
4181:
4182: =over 4
4183:
4184: =item * &determinedomain()
1.60 matthew 4185:
4186: Inputs: $domain (usually will be undef)
4187:
1.63 www 4188: Returns: Determines which domain should be used for designs
1.60 matthew 4189:
4190: =cut
1.54 www 4191:
1.60 matthew 4192: ###############################################
1.63 www 4193: sub determinedomain {
4194: my $domain=shift;
1.531 albertel 4195: if (! $domain) {
1.60 matthew 4196: # Determine domain if we have not been given one
1.893 raeburn 4197: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4198: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4199: if ($env{'request.role.domain'}) {
4200: $domain=$env{'request.role.domain'};
1.60 matthew 4201: }
4202: }
1.63 www 4203: return $domain;
4204: }
4205: ###############################################
1.517 raeburn 4206:
1.518 albertel 4207: sub devalidate_domconfig_cache {
4208: my ($udom)=@_;
4209: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4210: }
4211:
4212: # ---------------------- Get domain configuration for a domain
4213: sub get_domainconf {
4214: my ($udom) = @_;
4215: my $cachetime=1800;
4216: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4217: if (defined($cached)) { return %{$result}; }
4218:
4219: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4220: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4221: my (%designhash,%legacy);
1.518 albertel 4222: if (keys(%domconfig) > 0) {
4223: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4224: if (keys(%{$domconfig{'login'}})) {
4225: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4226: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4227: if ($key eq 'loginvia') {
4228: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4229: my @ids = &Apache::lonnet::current_machine_ids();
4230: foreach my $hostname (@ids) {
1.948 raeburn 4231: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4232: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4233: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4234: $designhash{$udom.'.login.loginvia'} = $server;
4235: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4236:
4237: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4238: } else {
4239: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4240: }
4241: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4242: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4243: }
1.946 raeburn 4244: }
4245: }
4246: }
4247: }
4248: } else {
4249: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4250: $designhash{$udom.'.login.'.$key.'_'.$img} =
4251: $domconfig{'login'}{$key}{$img};
4252: }
1.699 raeburn 4253: }
4254: } else {
4255: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4256: }
1.632 raeburn 4257: }
4258: } else {
4259: $legacy{'login'} = 1;
1.518 albertel 4260: }
1.632 raeburn 4261: } else {
4262: $legacy{'login'} = 1;
1.518 albertel 4263: }
4264: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4265: if (keys(%{$domconfig{'rolecolors'}})) {
4266: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4267: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4268: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4269: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4270: }
1.518 albertel 4271: }
4272: }
1.632 raeburn 4273: } else {
4274: $legacy{'rolecolors'} = 1;
1.518 albertel 4275: }
1.632 raeburn 4276: } else {
4277: $legacy{'rolecolors'} = 1;
1.518 albertel 4278: }
1.948 raeburn 4279: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4280: if ($domconfig{'autoenroll'}{'co-owners'}) {
4281: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4282: }
4283: }
1.632 raeburn 4284: if (keys(%legacy) > 0) {
4285: my %legacyhash = &get_legacy_domconf($udom);
4286: foreach my $item (keys(%legacyhash)) {
4287: if ($item =~ /^\Q$udom\E\.login/) {
4288: if ($legacy{'login'}) {
4289: $designhash{$item} = $legacyhash{$item};
4290: }
4291: } else {
4292: if ($legacy{'rolecolors'}) {
4293: $designhash{$item} = $legacyhash{$item};
4294: }
1.518 albertel 4295: }
4296: }
4297: }
1.632 raeburn 4298: } else {
4299: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4300: }
4301: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4302: $cachetime);
4303: return %designhash;
4304: }
4305:
1.632 raeburn 4306: sub get_legacy_domconf {
4307: my ($udom) = @_;
4308: my %legacyhash;
4309: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4310: my $designfile = $designdir.'/'.$udom.'.tab';
4311: if (-e $designfile) {
4312: if ( open (my $fh,"<$designfile") ) {
4313: while (my $line = <$fh>) {
4314: next if ($line =~ /^\#/);
4315: chomp($line);
4316: my ($key,$val)=(split(/\=/,$line));
4317: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4318: }
4319: close($fh);
4320: }
4321: }
4322: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4323: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4324: }
4325: return %legacyhash;
4326: }
4327:
1.63 www 4328: =pod
4329:
1.112 bowersj2 4330: =item * &domainlogo()
1.63 www 4331:
4332: Inputs: $domain (usually will be undef)
4333:
4334: Returns: A link to a domain logo, if the domain logo exists.
4335: If the domain logo does not exist, a description of the domain.
4336:
4337: =cut
1.112 bowersj2 4338:
1.63 www 4339: ###############################################
4340: sub domainlogo {
1.517 raeburn 4341: my $domain = &determinedomain(shift);
1.518 albertel 4342: my %designhash = &get_domainconf($domain);
1.517 raeburn 4343: # See if there is a logo
4344: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4345: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4346: if ($imgsrc =~ m{^/(adm|res)/}) {
4347: if ($imgsrc =~ m{^/res/}) {
4348: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4349: &Apache::lonnet::repcopy($local_name);
4350: }
4351: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4352: }
4353: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4354: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4355: return &Apache::lonnet::domain($domain,'description');
1.59 www 4356: } else {
1.60 matthew 4357: return '';
1.59 www 4358: }
4359: }
1.63 www 4360: ##############################################
4361:
4362: =pod
4363:
1.112 bowersj2 4364: =item * &designparm()
1.63 www 4365:
4366: Inputs: $which parameter; $domain (usually will be undef)
4367:
4368: Returns: value of designparamter $which
4369:
4370: =cut
1.112 bowersj2 4371:
1.397 albertel 4372:
1.400 albertel 4373: ##############################################
1.397 albertel 4374: sub designparm {
4375: my ($which,$domain)=@_;
4376: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4377: return $env{'environment.color.'.$which};
1.96 www 4378: }
1.63 www 4379: $domain=&determinedomain($domain);
1.518 albertel 4380: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4381: my $output;
1.517 raeburn 4382: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4383: $output = $domdesign{$domain.'.'.$which};
1.63 www 4384: } else {
1.520 raeburn 4385: $output = $defaultdesign{$which};
4386: }
4387: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4388: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4389: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4390: if ($output =~ m{^/res/}) {
4391: my $local_name = &Apache::lonnet::filelocation('',$output);
4392: &Apache::lonnet::repcopy($local_name);
4393: }
1.520 raeburn 4394: $output = &lonhttpdurl($output);
4395: }
1.63 www 4396: }
1.520 raeburn 4397: return $output;
1.63 www 4398: }
1.59 www 4399:
1.822 bisitz 4400: ##############################################
4401: =pod
4402:
1.832 bisitz 4403: =item * &authorspace()
4404:
4405: Inputs: ./.
4406:
4407: Returns: Path to the Construction Space of the current user's
4408: accessed author space
4409: The author space will be that of the current user
4410: when accessing the own author space
4411: and that of the co-author/assistent co-author
4412: when accessing the co-author's/assistent co-author's
4413: space
4414:
4415: =cut
4416:
4417: sub authorspace {
4418: my $caname = '';
4419: if ($env{'request.role'} =~ /^ca|^aa/) {
4420: (undef,$caname) =
4421: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4422: } else {
4423: $caname = $env{'user.name'};
4424: }
4425: return '/priv/'.$caname.'/';
4426: }
4427:
4428: ##############################################
4429: =pod
4430:
1.822 bisitz 4431: =item * &head_subbox()
4432:
4433: Inputs: $content (contains HTML code with page functions, etc.)
4434:
4435: Returns: HTML div with $content
4436: To be included in page header
4437:
4438: =cut
4439:
4440: sub head_subbox {
4441: my ($content)=@_;
4442: my $output =
1.844 bisitz 4443: '<div id="LC_head_subbox">'
1.822 bisitz 4444: .$content
4445: .'</div>'
4446: }
4447:
4448: ##############################################
4449: =pod
4450:
4451: =item * &CSTR_pageheader()
4452:
4453: Inputs: ./.
4454:
4455: Returns: HTML div with CSTR path and recent box
4456: To be included on Construction Space pages
4457:
4458: =cut
4459:
4460: sub CSTR_pageheader {
4461: # this is for resources; directories have customtitle, and crumbs
4462: # and select recent are created in lonpubdir.pm
4463: my ($uname,$thisdisfn)=
4464: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4465: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4466: $formaction=~s/\/+/\//g;
4467:
4468: my $parentpath = '';
4469: my $lastitem = '';
4470: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4471: $parentpath = $1;
4472: $lastitem = $2;
4473: } else {
4474: $lastitem = $thisdisfn;
4475: }
1.921 bisitz 4476:
4477: my $output =
1.822 bisitz 4478: '<div>'
4479: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4480: .'<b>'.&mt('Construction Space:').'</b> '
4481: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4482: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4483: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4484:
4485: if ($lastitem) {
4486: $output .=
4487: '<span class="LC_filename">'
4488: .$lastitem
4489: .'</span>';
4490: }
4491: $output .=
4492: '<br />'
1.822 bisitz 4493: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4494: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4495: .'</form>'
4496: .&Apache::lonmenu::constspaceform()
4497: .'</div>';
1.921 bisitz 4498:
4499: return $output;
1.822 bisitz 4500: }
4501:
1.60 matthew 4502: ###############################################
4503: ###############################################
4504:
4505: =pod
4506:
1.112 bowersj2 4507: =back
4508:
1.549 albertel 4509: =head1 HTML Helpers
1.112 bowersj2 4510:
4511: =over 4
4512:
4513: =item * &bodytag()
1.60 matthew 4514:
4515: Returns a uniform header for LON-CAPA web pages.
4516:
4517: Inputs:
4518:
1.112 bowersj2 4519: =over 4
4520:
4521: =item * $title, A title to be displayed on the page.
4522:
4523: =item * $function, the current role (can be undef).
4524:
4525: =item * $addentries, extra parameters for the <body> tag.
4526:
4527: =item * $bodyonly, if defined, only return the <body> tag.
4528:
4529: =item * $domain, if defined, force a given domain.
4530:
4531: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4532: text interface only)
1.60 matthew 4533:
1.814 bisitz 4534: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4535: navigational links
1.317 albertel 4536:
1.338 albertel 4537: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4538:
1.949 droeschl 4539: #RC =item * $no_inline_link, if true and in remote mode, don't show the
4540: #RC 'Switch To Inline Menu' link
4541: #RC
1.460 albertel 4542: =item * $args, optional argument valid values are
4543: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4544: inherit_jsmath -> when creating popup window in a page,
4545: should it have jsmath forced on by the
4546: current page
1.460 albertel 4547:
1.112 bowersj2 4548: =back
4549:
1.60 matthew 4550: Returns: A uniform header for LON-CAPA web pages.
4551: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4552: If $bodyonly is undef or zero, an html string containing a <body> tag and
4553: other decorations will be returned.
4554:
4555: =cut
4556:
1.54 www 4557: sub bodytag {
1.831 bisitz 4558: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4559: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4560:
1.460 albertel 4561: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4562:
1.183 matthew 4563: $function = &get_users_function() if (!$function);
1.339 albertel 4564: my $img = &designparm($function.'.img',$domain);
4565: my $font = &designparm($function.'.font',$domain);
4566: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4567:
1.803 bisitz 4568: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4569: 'bgcolor' => $pgbg,
1.339 albertel 4570: 'text' => $font,
4571: 'alink' => &designparm($function.'.alink',$domain),
4572: 'vlink' => &designparm($function.'.vlink',$domain),
4573: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4574: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4575:
1.63 www 4576: # role and realm
1.378 raeburn 4577: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4578: if ($role eq 'ca') {
1.479 albertel 4579: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4580: $realm = &plainname($rname,$rdom);
1.378 raeburn 4581: }
1.55 www 4582: # realm
1.258 albertel 4583: if ($env{'request.course.id'}) {
1.378 raeburn 4584: if ($env{'request.role'} !~ /^cr/) {
4585: $role = &Apache::lonnet::plaintext($role,&course_type());
4586: }
1.898 raeburn 4587: if ($env{'request.course.sec'}) {
4588: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4589: }
1.359 albertel 4590: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4591: } else {
4592: $role = &Apache::lonnet::plaintext($role);
1.54 www 4593: }
1.433 albertel 4594:
1.359 albertel 4595: if (!$realm) { $realm=' '; }
1.55 www 4596: # Set messages
1.60 matthew 4597: my $messages=&domainlogo($domain);
1.330 albertel 4598:
1.438 albertel 4599: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4600:
1.101 www 4601: # construct main body tag
1.359 albertel 4602: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4603: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4604:
1.530 albertel 4605: if ($bodyonly) {
1.60 matthew 4606: return $bodytag;
1.798 tempelho 4607: }
1.359 albertel 4608:
1.410 albertel 4609: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4610: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4611: undef($role);
1.434 albertel 4612: } else {
4613: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4614: }
1.359 albertel 4615:
1.762 bisitz 4616: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4617: #
4618: # Extra info if you are the DC
4619: my $dc_info = '';
4620: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4621: $env{'course.'.$env{'request.course.id'}.
4622: '.domain'}.'/'})) {
4623: my $cid = $env{'request.course.id'};
1.917 raeburn 4624: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4625: $dc_info =~ s/\s+$//;
1.359 albertel 4626: }
4627:
1.898 raeburn 4628: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4629: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4630:
1.359 albertel 4631: # No Remote
1.916 droeschl 4632: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4633: return $bodytag;
4634: }
1.903 droeschl 4635:
4636: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4637:
4638: # if ($env{'request.state'} eq 'construct') {
4639: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4640: # }
4641:
1.359 albertel 4642:
4643:
1.916 droeschl 4644: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4645: if ($dc_info) {
4646: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4647: }
1.916 droeschl 4648: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4649: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4650: return $bodytag;
4651: }
1.894 droeschl 4652:
1.927 raeburn 4653: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4654: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4655: }
1.916 droeschl 4656:
1.903 droeschl 4657: $bodytag .= Apache::lonhtmlcommon::scripttag(
4658: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4659:
1.903 droeschl 4660: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4661:
1.917 raeburn 4662: if ($dc_info) {
4663: $dc_info = &dc_courseid_toggle($dc_info);
4664: }
4665: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4666:
1.903 droeschl 4667: #don't show menus for public users
4668: if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
4669: $bodytag .= Apache::lonmenu::secondary_menu();
4670: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4671: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4672: if ($env{'request.state'} eq 'construct') {
4673: $bodytag .= &Apache::lonmenu::innerregister($forcereg,'',
4674: $args->{'bread_crumbs'});
4675: } elsif ($forcereg) {
4676: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4677: }
1.903 droeschl 4678: }else{
4679: # this is to seperate menu from content when there's no secondary
4680: # menu. Especially needed for public accessible ressources.
4681: $bodytag .= '<hr style="clear:both" />';
4682: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4683: }
1.903 droeschl 4684:
1.235 raeburn 4685: return $bodytag;
1.182 matthew 4686: }
4687:
1.917 raeburn 4688: sub dc_courseid_toggle {
4689: my ($dc_info) = @_;
4690: return ' <span id="dccidtext" class="LC_cusr_subheading">'.
4691: '<a href="javascript:showCourseID();">'.
4692: &mt('(More ...)').'</a></span>'.
4693: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4694: }
4695:
1.330 albertel 4696: sub make_attr_string {
4697: my ($register,$attr_ref) = @_;
4698:
4699: if ($attr_ref && !ref($attr_ref)) {
4700: die("addentries Must be a hash ref ".
4701: join(':',caller(1))." ".
4702: join(':',caller(0))." ");
4703: }
4704:
4705: if ($register) {
1.339 albertel 4706: my ($on_load,$on_unload);
4707: foreach my $key (keys(%{$attr_ref})) {
4708: if (lc($key) eq 'onload') {
4709: $on_load.=$attr_ref->{$key}.';';
4710: delete($attr_ref->{$key});
4711:
4712: } elsif (lc($key) eq 'onunload') {
4713: $on_unload.=$attr_ref->{$key}.';';
4714: delete($attr_ref->{$key});
4715: }
4716: }
4717: $attr_ref->{'onload'} =
4718: &Apache::lonmenu::loadevents(). $on_load;
4719: $attr_ref->{'onunload'}=
4720: &Apache::lonmenu::unloadevents().$on_unload;
4721: }
4722:
4723: # Accessibility font enhance
4724: if ($env{'browser.fontenhance'} eq 'on') {
4725: my $style;
4726: foreach my $key (keys(%{$attr_ref})) {
4727: if (lc($key) eq 'style') {
4728: $style.=$attr_ref->{$key}.';';
4729: delete($attr_ref->{$key});
4730: }
4731: }
4732: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4733: }
1.339 albertel 4734:
1.330 albertel 4735: my $attr_string;
4736: foreach my $attr (keys(%$attr_ref)) {
4737: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4738: }
4739: return $attr_string;
4740: }
4741:
4742:
1.182 matthew 4743: ###############################################
1.251 albertel 4744: ###############################################
4745:
4746: =pod
4747:
4748: =item * &endbodytag()
4749:
4750: Returns a uniform footer for LON-CAPA web pages.
4751:
1.635 raeburn 4752: Inputs: 1 - optional reference to an args hash
4753: If in the hash, key for noredirectlink has a value which evaluates to true,
4754: a 'Continue' link is not displayed if the page contains an
4755: internal redirect in the <head></head> section,
4756: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4757:
4758: =cut
4759:
4760: sub endbodytag {
1.635 raeburn 4761: my ($args) = @_;
1.251 albertel 4762: my $endbodytag='</body>';
1.269 albertel 4763: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4764: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4765: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4766: $endbodytag=
4767: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4768: &mt('Continue').'</a>'.
4769: $endbodytag;
4770: }
1.315 albertel 4771: }
1.251 albertel 4772: return $endbodytag;
4773: }
4774:
1.352 albertel 4775: =pod
4776:
4777: =item * &standard_css()
4778:
4779: Returns a style sheet
4780:
4781: Inputs: (all optional)
4782: domain -> force to color decorate a page for a specific
4783: domain
4784: function -> force usage of a specific rolish color scheme
4785: bgcolor -> override the default page bgcolor
4786:
4787: =cut
4788:
1.343 albertel 4789: sub standard_css {
1.345 albertel 4790: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4791: $function = &get_users_function() if (!$function);
4792: my $img = &designparm($function.'.img', $domain);
4793: my $tabbg = &designparm($function.'.tabbg', $domain);
4794: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4795: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4796: #second colour for later usage
1.345 albertel 4797: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4798: my $pgbg_or_bgcolor =
4799: $bgcolor ||
1.352 albertel 4800: &designparm($function.'.pgbg', $domain);
1.382 albertel 4801: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4802: my $alink = &designparm($function.'.alink', $domain);
4803: my $vlink = &designparm($function.'.vlink', $domain);
4804: my $link = &designparm($function.'.link', $domain);
4805:
1.704 muellerd 4806: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4807: my $bgcol = &designparm('login.bgcol',$domain);
4808: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4809:
1.602 albertel 4810: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4811: my $mono = 'monospace';
1.850 bisitz 4812: my $data_table_head = $sidebg;
4813: my $data_table_light = '#FAFAFA';
4814: my $data_table_dark = '#F0F0F0';
1.470 banghart 4815: my $data_table_darker = '#CCCCCC';
1.349 albertel 4816: my $data_table_highlight = '#FFFF00';
1.352 albertel 4817: my $mail_new = '#FFBB77';
4818: my $mail_new_hover = '#DD9955';
4819: my $mail_read = '#BBBB77';
4820: my $mail_read_hover = '#999944';
4821: my $mail_replied = '#AAAA88';
4822: my $mail_replied_hover = '#888855';
4823: my $mail_other = '#99BBBB';
4824: my $mail_other_hover = '#669999';
1.391 albertel 4825: my $table_header = '#DDDDDD';
1.489 raeburn 4826: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4827: my $lg_border_color = '#C8C8C8';
1.392 albertel 4828:
1.608 albertel 4829: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4830: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4831: : '0 3px 0 4px';
1.448 albertel 4832:
1.523 albertel 4833:
1.343 albertel 4834: return <<END;
1.947 droeschl 4835:
4836: /* needed for iframe to allow 100% height in FF */
4837: body, html {
4838: margin: 0;
4839: padding: 0 0.5%;
4840: height: 99%; /* to avoid scrollbars */
4841: }
4842:
1.795 www 4843: body {
1.911 bisitz 4844: font-family: $sans;
4845: line-height:130%;
4846: font-size:0.83em;
4847: color:$font;
1.795 www 4848: }
4849:
1.911 bisitz 4850: a:focus {
1.795 www 4851: color: red;
1.911 bisitz 4852: background: yellow;
1.795 www 4853: }
1.698 harmsja 4854:
1.911 bisitz 4855: form, .inline {
4856: display: inline;
1.795 www 4857: }
1.721 harmsja 4858:
1.795 www 4859: .LC_right {
1.911 bisitz 4860: text-align:right;
1.795 www 4861: }
4862:
4863: .LC_middle {
1.911 bisitz 4864: vertical-align:middle;
1.795 www 4865: }
1.721 harmsja 4866:
1.911 bisitz 4867: .LC_400Box {
4868: width:400px;
4869: }
1.721 harmsja 4870:
1.947 droeschl 4871: .LC_iframecontainer {
4872: width: 98%;
4873: margin: 0;
4874: position: fixed;
4875: top: 8.5em;
4876: bottom: 0;
4877: }
4878:
4879: .LC_iframecontainer iframe{
4880: border: none;
4881: width: 100%;
4882: height: 100%;
4883: }
4884:
1.778 bisitz 4885: .LC_filename {
4886: font-family: $mono;
4887: white-space:pre;
1.921 bisitz 4888: font-size: 120%;
1.778 bisitz 4889: }
4890:
4891: .LC_fileicon {
4892: border: none;
4893: height: 1.3em;
4894: vertical-align: text-bottom;
4895: margin-right: 0.3em;
4896: text-decoration:none;
4897: }
4898:
1.350 albertel 4899: .LC_error {
4900: color: red;
4901: font-size: larger;
4902: }
1.795 www 4903:
1.457 albertel 4904: .LC_warning,
4905: .LC_diff_removed {
1.733 bisitz 4906: color: red;
1.394 albertel 4907: }
1.532 albertel 4908:
4909: .LC_info,
1.457 albertel 4910: .LC_success,
4911: .LC_diff_added {
1.350 albertel 4912: color: green;
4913: }
1.795 www 4914:
1.802 bisitz 4915: div.LC_confirm_box {
4916: background-color: #FAFAFA;
4917: border: 1px solid $lg_border_color;
4918: margin-right: 0;
4919: padding: 5px;
4920: }
4921:
4922: div.LC_confirm_box .LC_error img,
4923: div.LC_confirm_box .LC_success img {
4924: vertical-align: middle;
4925: }
4926:
1.440 albertel 4927: .LC_icon {
1.771 droeschl 4928: border: none;
1.790 droeschl 4929: vertical-align: middle;
1.771 droeschl 4930: }
4931:
1.543 albertel 4932: .LC_docs_spacer {
4933: width: 25px;
4934: height: 1px;
1.771 droeschl 4935: border: none;
1.543 albertel 4936: }
1.346 albertel 4937:
1.532 albertel 4938: .LC_internal_info {
1.735 bisitz 4939: color: #999999;
1.532 albertel 4940: }
4941:
1.794 www 4942: .LC_discussion {
1.911 bisitz 4943: background: $tabbg;
4944: border: 1px solid black;
4945: margin: 2px;
1.794 www 4946: }
4947:
4948: .LC_disc_action_links_bar {
1.911 bisitz 4949: background: $tabbg;
4950: border: none;
4951: margin: 4px;
1.794 www 4952: }
4953:
4954: .LC_disc_action_left {
1.911 bisitz 4955: text-align: left;
1.794 www 4956: }
4957:
4958: .LC_disc_action_right {
1.911 bisitz 4959: text-align: right;
1.794 www 4960: }
4961:
4962: .LC_disc_new_item {
1.911 bisitz 4963: background: white;
4964: border: 2px solid red;
4965: margin: 2px;
1.794 www 4966: }
4967:
4968: .LC_disc_old_item {
1.911 bisitz 4969: background: white;
4970: border: 1px solid black;
4971: margin: 2px;
1.794 www 4972: }
4973:
1.458 albertel 4974: table.LC_pastsubmission {
4975: border: 1px solid black;
4976: margin: 2px;
4977: }
4978:
1.924 bisitz 4979: table#LC_menubuttons {
1.345 albertel 4980: width: 100%;
4981: background: $pgbg;
1.392 albertel 4982: border: 2px;
1.402 albertel 4983: border-collapse: separate;
1.803 bisitz 4984: padding: 0;
1.345 albertel 4985: }
1.392 albertel 4986:
1.801 tempelho 4987: table#LC_title_bar a {
4988: color: $fontmenu;
4989: }
1.836 bisitz 4990:
1.807 droeschl 4991: table#LC_title_bar {
1.819 tempelho 4992: clear: both;
1.836 bisitz 4993: display: none;
1.807 droeschl 4994: }
4995:
1.795 www 4996: table#LC_title_bar,
1.933 droeschl 4997: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 4998: table#LC_title_bar.LC_with_remote {
1.359 albertel 4999: width: 100%;
1.392 albertel 5000: border-color: $pgbg;
5001: border-style: solid;
5002: border-width: $border;
1.379 albertel 5003: background: $pgbg;
1.801 tempelho 5004: color: $fontmenu;
1.392 albertel 5005: border-collapse: collapse;
1.803 bisitz 5006: padding: 0;
1.819 tempelho 5007: margin: 0;
1.359 albertel 5008: }
1.795 www 5009:
1.933 droeschl 5010: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5011: margin: 0;
5012: padding: 0;
1.933 droeschl 5013: position: relative;
5014: list-style: none;
1.913 droeschl 5015: }
1.933 droeschl 5016: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5017: display: inline;
5018: }
1.933 droeschl 5019:
5020: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5021: padding: 0;
1.933 droeschl 5022: margin: 0;
5023: float: left;
1.913 droeschl 5024: }
1.933 droeschl 5025: .LC_breadcrumb_tools_tools {
5026: padding: 0;
5027: margin: 0;
1.913 droeschl 5028: float: right;
5029: }
5030:
1.359 albertel 5031: table#LC_title_bar td {
5032: background: $tabbg;
5033: }
1.795 www 5034:
1.911 bisitz 5035: table#LC_menubuttons img {
1.803 bisitz 5036: border: none;
1.346 albertel 5037: }
1.795 www 5038:
1.842 droeschl 5039: .LC_breadcrumbs_component {
1.911 bisitz 5040: float: right;
5041: margin: 0 1em;
1.357 albertel 5042: }
1.842 droeschl 5043: .LC_breadcrumbs_component img {
1.911 bisitz 5044: vertical-align: middle;
1.777 tempelho 5045: }
1.795 www 5046:
1.383 albertel 5047: td.LC_table_cell_checkbox {
5048: text-align: center;
5049: }
1.795 www 5050:
5051: .LC_fontsize_small {
1.911 bisitz 5052: font-size: 70%;
1.705 tempelho 5053: }
5054:
1.844 bisitz 5055: #LC_breadcrumbs {
1.911 bisitz 5056: clear:both;
5057: background: $sidebg;
5058: border-bottom: 1px solid $lg_border_color;
5059: line-height: 2.5em;
1.933 droeschl 5060: overflow: hidden;
1.911 bisitz 5061: margin: 0;
5062: padding: 0;
1.819 tempelho 5063: }
1.862 bisitz 5064:
1.844 bisitz 5065: #LC_head_subbox {
1.911 bisitz 5066: clear:both;
5067: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5068: border: 1px solid $sidebg;
5069: margin: 0 0 10px 0;
1.822 bisitz 5070: }
5071:
1.795 www 5072: .LC_fontsize_medium {
1.911 bisitz 5073: font-size: 85%;
1.705 tempelho 5074: }
5075:
1.795 www 5076: .LC_fontsize_large {
1.911 bisitz 5077: font-size: 120%;
1.705 tempelho 5078: }
5079:
1.346 albertel 5080: .LC_menubuttons_inline_text {
5081: color: $font;
1.698 harmsja 5082: font-size: 90%;
1.701 harmsja 5083: padding-left:3px;
1.346 albertel 5084: }
5085:
1.934 droeschl 5086: .LC_menubuttons_inline_text img{
5087: vertical-align: middle;
5088: }
5089:
1.526 www 5090: .LC_menubuttons_link {
5091: text-decoration: none;
5092: }
1.795 www 5093:
1.522 albertel 5094: .LC_menubuttons_category {
1.521 www 5095: color: $font;
1.526 www 5096: background: $pgbg;
1.521 www 5097: font-size: larger;
5098: font-weight: bold;
5099: }
5100:
1.346 albertel 5101: td.LC_menubuttons_text {
1.911 bisitz 5102: color: $font;
1.346 albertel 5103: }
1.706 harmsja 5104:
1.346 albertel 5105: .LC_current_location {
5106: background: $tabbg;
5107: }
1.795 www 5108:
1.938 bisitz 5109: table.LC_data_table {
1.347 albertel 5110: border: 1px solid #000000;
1.402 albertel 5111: border-collapse: separate;
1.426 albertel 5112: border-spacing: 1px;
1.610 albertel 5113: background: $pgbg;
1.347 albertel 5114: }
1.795 www 5115:
1.422 albertel 5116: .LC_data_table_dense {
5117: font-size: small;
5118: }
1.795 www 5119:
1.507 raeburn 5120: table.LC_nested_outer {
5121: border: 1px solid #000000;
1.589 raeburn 5122: border-collapse: collapse;
1.803 bisitz 5123: border-spacing: 0;
1.507 raeburn 5124: width: 100%;
5125: }
1.795 www 5126:
1.879 raeburn 5127: table.LC_innerpickbox,
1.507 raeburn 5128: table.LC_nested {
1.803 bisitz 5129: border: none;
1.589 raeburn 5130: border-collapse: collapse;
1.803 bisitz 5131: border-spacing: 0;
1.507 raeburn 5132: width: 100%;
5133: }
1.795 www 5134:
1.930 faziophi 5135: .ui-accordion,
5136: .ui-accordion table.LC_data_table,
5137: .ui-accordion table.LC_nested_outer{
5138: border: 0px;
5139: border-spacing: 0px;
5140: margin: 3px;
5141: }
5142:
1.911 bisitz 5143: table.LC_data_table tr th,
5144: table.LC_calendar tr th,
1.879 raeburn 5145: table.LC_prior_tries tr th,
5146: table.LC_innerpickbox tr th {
1.349 albertel 5147: font-weight: bold;
5148: background-color: $data_table_head;
1.801 tempelho 5149: color:$fontmenu;
1.701 harmsja 5150: font-size:90%;
1.347 albertel 5151: }
1.795 www 5152:
1.879 raeburn 5153: table.LC_innerpickbox tr th,
5154: table.LC_innerpickbox tr td {
5155: vertical-align: top;
5156: }
5157:
1.711 raeburn 5158: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5159: background-color: #CCCCCC;
1.711 raeburn 5160: font-weight: bold;
5161: text-align: left;
5162: }
1.795 www 5163:
1.912 bisitz 5164: table.LC_data_table tr.LC_odd_row > td {
5165: background-color: $data_table_light;
5166: padding: 2px;
5167: vertical-align: top;
5168: }
5169:
1.809 bisitz 5170: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5171: background-color: $data_table_light;
1.912 bisitz 5172: vertical-align: top;
5173: }
5174:
5175: table.LC_data_table tr.LC_even_row > td {
5176: background-color: $data_table_dark;
1.425 albertel 5177: padding: 2px;
1.900 bisitz 5178: vertical-align: top;
1.347 albertel 5179: }
1.795 www 5180:
1.809 bisitz 5181: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5182: background-color: $data_table_dark;
1.900 bisitz 5183: vertical-align: top;
1.347 albertel 5184: }
1.795 www 5185:
1.425 albertel 5186: table.LC_data_table tr.LC_data_table_highlight td {
5187: background-color: $data_table_darker;
5188: }
1.795 www 5189:
1.639 raeburn 5190: table.LC_data_table tr td.LC_leftcol_header {
5191: background-color: $data_table_head;
5192: font-weight: bold;
5193: }
1.795 www 5194:
1.451 albertel 5195: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5196: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5197: font-weight: bold;
5198: font-style: italic;
5199: text-align: center;
5200: padding: 8px;
1.347 albertel 5201: }
1.795 www 5202:
1.940 bisitz 5203: table.LC_data_table tr.LC_empty_row td {
5204: background-color: $sidebg;
5205: }
5206:
5207: table.LC_nested tr.LC_empty_row td {
5208: background-color: #FFFFFF;
5209: }
5210:
1.890 droeschl 5211: table.LC_caption {
5212: }
5213:
1.507 raeburn 5214: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5215: padding: 4ex
5216: }
1.795 www 5217:
1.507 raeburn 5218: table.LC_nested_outer tr th {
5219: font-weight: bold;
1.801 tempelho 5220: color:$fontmenu;
1.507 raeburn 5221: background-color: $data_table_head;
1.701 harmsja 5222: font-size: small;
1.507 raeburn 5223: border-bottom: 1px solid #000000;
5224: }
1.795 www 5225:
1.507 raeburn 5226: table.LC_nested_outer tr td.LC_subheader {
5227: background-color: $data_table_head;
5228: font-weight: bold;
5229: font-size: small;
5230: border-bottom: 1px solid #000000;
5231: text-align: right;
1.451 albertel 5232: }
1.795 www 5233:
1.507 raeburn 5234: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5235: background-color: #CCCCCC;
1.451 albertel 5236: font-weight: bold;
5237: font-size: small;
1.507 raeburn 5238: text-align: center;
5239: }
1.795 www 5240:
1.589 raeburn 5241: table.LC_nested tr.LC_info_row td.LC_left_item,
5242: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5243: text-align: left;
1.451 albertel 5244: }
1.795 www 5245:
1.507 raeburn 5246: table.LC_nested td {
1.735 bisitz 5247: background-color: #FFFFFF;
1.451 albertel 5248: font-size: small;
1.507 raeburn 5249: }
1.795 www 5250:
1.507 raeburn 5251: table.LC_nested_outer tr th.LC_right_item,
5252: table.LC_nested tr.LC_info_row td.LC_right_item,
5253: table.LC_nested tr.LC_odd_row td.LC_right_item,
5254: table.LC_nested tr td.LC_right_item {
1.451 albertel 5255: text-align: right;
5256: }
5257:
1.930 faziophi 5258: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5259: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5260: text-align: right;
5261: width: 40%;
5262: padding-right:10px;
5263: vertical-align: top;
5264: padding: 5px;
5265: }
5266:
5267: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5268: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5269: text-align: left;
5270: width: 60%;
5271: padding: 2px 4px;
5272: }
5273:
1.507 raeburn 5274: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5275: background-color: #EEEEEE;
1.451 albertel 5276: }
5277:
1.473 raeburn 5278: table.LC_createuser {
5279: }
5280:
5281: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5282: font-size: small;
1.473 raeburn 5283: }
5284:
5285: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5286: background-color: #CCCCCC;
1.473 raeburn 5287: font-weight: bold;
5288: text-align: center;
5289: }
5290:
1.349 albertel 5291: table.LC_calendar {
5292: border: 1px solid #000000;
5293: border-collapse: collapse;
1.917 raeburn 5294: width: 98%;
1.349 albertel 5295: }
1.795 www 5296:
1.349 albertel 5297: table.LC_calendar_pickdate {
5298: font-size: xx-small;
5299: }
1.795 www 5300:
1.349 albertel 5301: table.LC_calendar tr td {
5302: border: 1px solid #000000;
5303: vertical-align: top;
1.917 raeburn 5304: width: 14%;
1.349 albertel 5305: }
1.795 www 5306:
1.349 albertel 5307: table.LC_calendar tr td.LC_calendar_day_empty {
5308: background-color: $data_table_dark;
5309: }
1.795 www 5310:
1.779 bisitz 5311: table.LC_calendar tr td.LC_calendar_day_current {
5312: background-color: $data_table_highlight;
1.777 tempelho 5313: }
1.795 www 5314:
1.938 bisitz 5315: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5316: background-color: $mail_new;
5317: }
1.795 www 5318:
1.938 bisitz 5319: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5320: background-color: $mail_new_hover;
5321: }
1.795 www 5322:
1.938 bisitz 5323: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5324: background-color: $mail_read;
5325: }
1.795 www 5326:
1.938 bisitz 5327: /*
5328: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5329: background-color: $mail_read_hover;
5330: }
1.938 bisitz 5331: */
1.795 www 5332:
1.938 bisitz 5333: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5334: background-color: $mail_replied;
5335: }
1.795 www 5336:
1.938 bisitz 5337: /*
5338: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5339: background-color: $mail_replied_hover;
5340: }
1.938 bisitz 5341: */
1.795 www 5342:
1.938 bisitz 5343: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5344: background-color: $mail_other;
5345: }
1.795 www 5346:
1.938 bisitz 5347: /*
5348: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5349: background-color: $mail_other_hover;
5350: }
1.938 bisitz 5351: */
1.494 raeburn 5352:
1.777 tempelho 5353: table.LC_data_table tr > td.LC_browser_file,
5354: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5355: background: #AAEE77;
1.389 albertel 5356: }
1.795 www 5357:
1.777 tempelho 5358: table.LC_data_table tr > td.LC_browser_file_locked,
5359: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5360: background: #FFAA99;
1.387 albertel 5361: }
1.795 www 5362:
1.777 tempelho 5363: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5364: background: #888888;
1.779 bisitz 5365: }
1.795 www 5366:
1.777 tempelho 5367: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5368: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5369: background: #F8F866;
1.777 tempelho 5370: }
1.795 www 5371:
1.696 bisitz 5372: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5373: background: #E0E8FF;
1.387 albertel 5374: }
1.696 bisitz 5375:
1.707 bisitz 5376: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5377: /* background: #77FF77; */
1.707 bisitz 5378: }
1.795 www 5379:
1.707 bisitz 5380: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5381: border-right: 8px solid #FFFF77;
1.707 bisitz 5382: }
1.795 www 5383:
1.707 bisitz 5384: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5385: border-right: 8px solid #FFAA77;
1.707 bisitz 5386: }
1.795 www 5387:
1.707 bisitz 5388: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5389: border-right: 8px solid #FF7777;
1.707 bisitz 5390: }
1.795 www 5391:
1.707 bisitz 5392: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5393: border-right: 8px solid #AAFF77;
1.707 bisitz 5394: }
1.795 www 5395:
1.707 bisitz 5396: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5397: border-right: 8px solid #11CC55;
1.707 bisitz 5398: }
5399:
1.388 albertel 5400: span.LC_current_location {
1.701 harmsja 5401: font-size:larger;
1.388 albertel 5402: background: $pgbg;
5403: }
1.387 albertel 5404:
1.395 albertel 5405: span.LC_parm_menu_item {
5406: font-size: larger;
5407: }
1.795 www 5408:
1.395 albertel 5409: span.LC_parm_scope_all {
5410: color: red;
5411: }
1.795 www 5412:
1.395 albertel 5413: span.LC_parm_scope_folder {
5414: color: green;
5415: }
1.795 www 5416:
1.395 albertel 5417: span.LC_parm_scope_resource {
5418: color: orange;
5419: }
1.795 www 5420:
1.395 albertel 5421: span.LC_parm_part {
5422: color: blue;
5423: }
1.795 www 5424:
1.911 bisitz 5425: span.LC_parm_folder,
5426: span.LC_parm_symb {
1.395 albertel 5427: font-size: x-small;
5428: font-family: $mono;
5429: color: #AAAAAA;
5430: }
5431:
1.795 www 5432: td.LC_parm_overview_level_menu,
5433: td.LC_parm_overview_map_menu,
5434: td.LC_parm_overview_parm_selectors,
5435: td.LC_parm_overview_restrictions {
1.396 albertel 5436: border: 1px solid black;
5437: border-collapse: collapse;
5438: }
1.795 www 5439:
1.396 albertel 5440: table.LC_parm_overview_restrictions td {
5441: border-width: 1px 4px 1px 4px;
5442: border-style: solid;
5443: border-color: $pgbg;
5444: text-align: center;
5445: }
1.795 www 5446:
1.396 albertel 5447: table.LC_parm_overview_restrictions th {
5448: background: $tabbg;
5449: border-width: 1px 4px 1px 4px;
5450: border-style: solid;
5451: border-color: $pgbg;
5452: }
1.795 www 5453:
1.398 albertel 5454: table#LC_helpmenu {
1.803 bisitz 5455: border: none;
1.398 albertel 5456: height: 55px;
1.803 bisitz 5457: border-spacing: 0;
1.398 albertel 5458: }
5459:
5460: table#LC_helpmenu fieldset legend {
5461: font-size: larger;
5462: }
1.795 www 5463:
1.397 albertel 5464: table#LC_helpmenu_links {
5465: width: 100%;
5466: border: 1px solid black;
5467: background: $pgbg;
1.803 bisitz 5468: padding: 0;
1.397 albertel 5469: border-spacing: 1px;
5470: }
1.795 www 5471:
1.397 albertel 5472: table#LC_helpmenu_links tr td {
5473: padding: 1px;
5474: background: $tabbg;
1.399 albertel 5475: text-align: center;
5476: font-weight: bold;
1.397 albertel 5477: }
1.396 albertel 5478:
1.795 www 5479: table#LC_helpmenu_links a:link,
5480: table#LC_helpmenu_links a:visited,
1.397 albertel 5481: table#LC_helpmenu_links a:active {
5482: text-decoration: none;
5483: color: $font;
5484: }
1.795 www 5485:
1.397 albertel 5486: table#LC_helpmenu_links a:hover {
5487: text-decoration: underline;
5488: color: $vlink;
5489: }
1.396 albertel 5490:
1.417 albertel 5491: .LC_chrt_popup_exists {
5492: border: 1px solid #339933;
5493: margin: -1px;
5494: }
1.795 www 5495:
1.417 albertel 5496: .LC_chrt_popup_up {
5497: border: 1px solid yellow;
5498: margin: -1px;
5499: }
1.795 www 5500:
1.417 albertel 5501: .LC_chrt_popup {
5502: border: 1px solid #8888FF;
5503: background: #CCCCFF;
5504: }
1.795 www 5505:
1.421 albertel 5506: table.LC_pick_box {
5507: border-collapse: separate;
5508: background: white;
5509: border: 1px solid black;
5510: border-spacing: 1px;
5511: }
1.795 www 5512:
1.421 albertel 5513: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5514: background: $sidebg;
1.421 albertel 5515: font-weight: bold;
1.900 bisitz 5516: text-align: left;
1.740 bisitz 5517: vertical-align: top;
1.421 albertel 5518: width: 184px;
5519: padding: 8px;
5520: }
1.795 www 5521:
1.579 raeburn 5522: table.LC_pick_box td.LC_pick_box_value {
5523: text-align: left;
5524: padding: 8px;
5525: }
1.795 www 5526:
1.579 raeburn 5527: table.LC_pick_box td.LC_pick_box_select {
5528: text-align: left;
5529: padding: 8px;
5530: }
1.795 www 5531:
1.424 albertel 5532: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5533: padding: 0;
1.421 albertel 5534: height: 1px;
5535: background: black;
5536: }
1.795 www 5537:
1.421 albertel 5538: table.LC_pick_box td.LC_pick_box_submit {
5539: text-align: right;
5540: }
1.795 www 5541:
1.579 raeburn 5542: table.LC_pick_box td.LC_evenrow_value {
5543: text-align: left;
5544: padding: 8px;
5545: background-color: $data_table_light;
5546: }
1.795 www 5547:
1.579 raeburn 5548: table.LC_pick_box td.LC_oddrow_value {
5549: text-align: left;
5550: padding: 8px;
5551: background-color: $data_table_light;
5552: }
1.795 www 5553:
1.579 raeburn 5554: span.LC_helpform_receipt_cat {
5555: font-weight: bold;
5556: }
1.795 www 5557:
1.424 albertel 5558: table.LC_group_priv_box {
5559: background: white;
5560: border: 1px solid black;
5561: border-spacing: 1px;
5562: }
1.795 www 5563:
1.424 albertel 5564: table.LC_group_priv_box td.LC_pick_box_title {
5565: background: $tabbg;
5566: font-weight: bold;
5567: text-align: right;
5568: width: 184px;
5569: }
1.795 www 5570:
1.424 albertel 5571: table.LC_group_priv_box td.LC_groups_fixed {
5572: background: $data_table_light;
5573: text-align: center;
5574: }
1.795 www 5575:
1.424 albertel 5576: table.LC_group_priv_box td.LC_groups_optional {
5577: background: $data_table_dark;
5578: text-align: center;
5579: }
1.795 www 5580:
1.424 albertel 5581: table.LC_group_priv_box td.LC_groups_functionality {
5582: background: $data_table_darker;
5583: text-align: center;
5584: font-weight: bold;
5585: }
1.795 www 5586:
1.424 albertel 5587: table.LC_group_priv td {
5588: text-align: left;
1.803 bisitz 5589: padding: 0;
1.424 albertel 5590: }
5591:
1.421 albertel 5592: table.LC_notify_front_page {
5593: background: white;
5594: border: 1px solid black;
5595: padding: 8px;
5596: }
1.795 www 5597:
1.421 albertel 5598: table.LC_notify_front_page td {
5599: padding: 8px;
5600: }
1.795 www 5601:
1.424 albertel 5602: .LC_navbuttons {
5603: margin: 2ex 0ex 2ex 0ex;
5604: }
1.795 www 5605:
1.423 albertel 5606: .LC_topic_bar {
5607: font-weight: bold;
5608: background: $tabbg;
1.918 wenzelju 5609: margin: 1em 0em 1em 2em;
1.805 bisitz 5610: padding: 3px;
1.918 wenzelju 5611: font-size: 1.2em;
1.423 albertel 5612: }
1.795 www 5613:
1.423 albertel 5614: .LC_topic_bar span {
1.918 wenzelju 5615: left: 0.5em;
5616: position: absolute;
1.423 albertel 5617: vertical-align: middle;
1.918 wenzelju 5618: font-size: 1.2em;
1.423 albertel 5619: }
1.795 www 5620:
1.423 albertel 5621: table.LC_course_group_status {
5622: margin: 20px;
5623: }
1.795 www 5624:
1.423 albertel 5625: table.LC_status_selector td {
5626: vertical-align: top;
5627: text-align: center;
1.424 albertel 5628: padding: 4px;
5629: }
1.795 www 5630:
1.599 albertel 5631: div.LC_feedback_link {
1.616 albertel 5632: clear: both;
1.829 kalberla 5633: background: $sidebg;
1.779 bisitz 5634: width: 100%;
1.829 kalberla 5635: padding-bottom: 10px;
5636: border: 1px $tabbg solid;
1.833 kalberla 5637: height: 22px;
5638: line-height: 22px;
5639: padding-top: 5px;
5640: }
5641:
5642: div.LC_feedback_link img {
5643: height: 22px;
1.867 kalberla 5644: vertical-align:middle;
1.829 kalberla 5645: }
5646:
1.911 bisitz 5647: div.LC_feedback_link a {
1.829 kalberla 5648: text-decoration: none;
1.489 raeburn 5649: }
1.795 www 5650:
1.867 kalberla 5651: div.LC_comblock {
1.911 bisitz 5652: display:inline;
1.867 kalberla 5653: color:$font;
5654: font-size:90%;
5655: }
5656:
5657: div.LC_feedback_link div.LC_comblock {
5658: padding-left:5px;
5659: }
5660:
5661: div.LC_feedback_link div.LC_comblock a {
5662: color:$font;
5663: }
5664:
1.489 raeburn 5665: span.LC_feedback_link {
1.858 bisitz 5666: /* background: $feedback_link_bg; */
1.599 albertel 5667: font-size: larger;
5668: }
1.795 www 5669:
1.599 albertel 5670: span.LC_message_link {
1.858 bisitz 5671: /* background: $feedback_link_bg; */
1.599 albertel 5672: font-size: larger;
5673: position: absolute;
5674: right: 1em;
1.489 raeburn 5675: }
1.421 albertel 5676:
1.515 albertel 5677: table.LC_prior_tries {
1.524 albertel 5678: border: 1px solid #000000;
5679: border-collapse: separate;
5680: border-spacing: 1px;
1.515 albertel 5681: }
1.523 albertel 5682:
1.515 albertel 5683: table.LC_prior_tries td {
1.524 albertel 5684: padding: 2px;
1.515 albertel 5685: }
1.523 albertel 5686:
5687: .LC_answer_correct {
1.795 www 5688: background: lightgreen;
5689: color: darkgreen;
5690: padding: 6px;
1.523 albertel 5691: }
1.795 www 5692:
1.523 albertel 5693: .LC_answer_charged_try {
1.797 www 5694: background: #FFAAAA;
1.795 www 5695: color: darkred;
5696: padding: 6px;
1.523 albertel 5697: }
1.795 www 5698:
1.779 bisitz 5699: .LC_answer_not_charged_try,
1.523 albertel 5700: .LC_answer_no_grade,
5701: .LC_answer_late {
1.795 www 5702: background: lightyellow;
1.523 albertel 5703: color: black;
1.795 www 5704: padding: 6px;
1.523 albertel 5705: }
1.795 www 5706:
1.523 albertel 5707: .LC_answer_previous {
1.795 www 5708: background: lightblue;
5709: color: darkblue;
5710: padding: 6px;
1.523 albertel 5711: }
1.795 www 5712:
1.779 bisitz 5713: .LC_answer_no_message {
1.777 tempelho 5714: background: #FFFFFF;
5715: color: black;
1.795 www 5716: padding: 6px;
1.779 bisitz 5717: }
1.795 www 5718:
1.779 bisitz 5719: .LC_answer_unknown {
5720: background: orange;
5721: color: black;
1.795 www 5722: padding: 6px;
1.777 tempelho 5723: }
1.795 www 5724:
1.529 albertel 5725: span.LC_prior_numerical,
5726: span.LC_prior_string,
5727: span.LC_prior_custom,
5728: span.LC_prior_reaction,
5729: span.LC_prior_math {
1.925 bisitz 5730: font-family: $mono;
1.523 albertel 5731: white-space: pre;
5732: }
5733:
1.525 albertel 5734: span.LC_prior_string {
1.925 bisitz 5735: font-family: $mono;
1.525 albertel 5736: white-space: pre;
5737: }
5738:
1.523 albertel 5739: table.LC_prior_option {
5740: width: 100%;
5741: border-collapse: collapse;
5742: }
1.795 www 5743:
1.911 bisitz 5744: table.LC_prior_rank,
1.795 www 5745: table.LC_prior_match {
1.528 albertel 5746: border-collapse: collapse;
5747: }
1.795 www 5748:
1.528 albertel 5749: table.LC_prior_option tr td,
5750: table.LC_prior_rank tr td,
5751: table.LC_prior_match tr td {
1.524 albertel 5752: border: 1px solid #000000;
1.515 albertel 5753: }
5754:
1.855 bisitz 5755: .LC_nobreak {
1.544 albertel 5756: white-space: nowrap;
1.519 raeburn 5757: }
5758:
1.576 raeburn 5759: span.LC_cusr_emph {
5760: font-style: italic;
5761: }
5762:
1.633 raeburn 5763: span.LC_cusr_subheading {
5764: font-weight: normal;
5765: font-size: 85%;
5766: }
5767:
1.861 bisitz 5768: div.LC_docs_entry_move {
1.859 bisitz 5769: border: 1px solid #BBBBBB;
1.545 albertel 5770: background: #DDDDDD;
1.861 bisitz 5771: width: 22px;
1.859 bisitz 5772: padding: 1px;
5773: margin: 0;
1.545 albertel 5774: }
5775:
1.861 bisitz 5776: table.LC_data_table tr > td.LC_docs_entry_commands,
5777: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5778: background: #DDDDDD;
5779: font-size: x-small;
5780: }
1.795 www 5781:
1.861 bisitz 5782: .LC_docs_entry_parameter {
5783: white-space: nowrap;
5784: }
5785:
1.544 albertel 5786: .LC_docs_copy {
1.545 albertel 5787: color: #000099;
1.544 albertel 5788: }
1.795 www 5789:
1.544 albertel 5790: .LC_docs_cut {
1.545 albertel 5791: color: #550044;
1.544 albertel 5792: }
1.795 www 5793:
1.544 albertel 5794: .LC_docs_rename {
1.545 albertel 5795: color: #009900;
1.544 albertel 5796: }
1.795 www 5797:
1.544 albertel 5798: .LC_docs_remove {
1.545 albertel 5799: color: #990000;
5800: }
5801:
1.547 albertel 5802: .LC_docs_reinit_warn,
5803: .LC_docs_ext_edit {
5804: font-size: x-small;
5805: }
5806:
1.545 albertel 5807: table.LC_docs_adddocs td,
5808: table.LC_docs_adddocs th {
5809: border: 1px solid #BBBBBB;
5810: padding: 4px;
5811: background: #DDDDDD;
1.543 albertel 5812: }
5813:
1.584 albertel 5814: table.LC_sty_begin {
5815: background: #BBFFBB;
5816: }
1.795 www 5817:
1.584 albertel 5818: table.LC_sty_end {
5819: background: #FFBBBB;
5820: }
5821:
1.589 raeburn 5822: table.LC_double_column {
1.803 bisitz 5823: border-width: 0;
1.589 raeburn 5824: border-collapse: collapse;
5825: width: 100%;
5826: padding: 2px;
5827: }
5828:
5829: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5830: top: 2px;
1.589 raeburn 5831: left: 2px;
5832: width: 47%;
5833: vertical-align: top;
5834: }
5835:
5836: table.LC_double_column tr td.LC_right_col {
5837: top: 2px;
1.779 bisitz 5838: right: 2px;
1.589 raeburn 5839: width: 47%;
5840: vertical-align: top;
5841: }
5842:
1.591 raeburn 5843: div.LC_left_float {
5844: float: left;
5845: padding-right: 5%;
1.597 albertel 5846: padding-bottom: 4px;
1.591 raeburn 5847: }
5848:
5849: div.LC_clear_float_header {
1.597 albertel 5850: padding-bottom: 2px;
1.591 raeburn 5851: }
5852:
5853: div.LC_clear_float_footer {
1.597 albertel 5854: padding-top: 10px;
1.591 raeburn 5855: clear: both;
5856: }
5857:
1.597 albertel 5858: div.LC_grade_show_user {
1.941 bisitz 5859: /* border-left: 5px solid $sidebg; */
5860: border-top: 5px solid #000000;
5861: margin: 50px 0 0 0;
1.936 bisitz 5862: padding: 15px 0 5px 10px;
1.597 albertel 5863: }
1.795 www 5864:
1.936 bisitz 5865: div.LC_grade_show_user_odd_row {
1.941 bisitz 5866: /* border-left: 5px solid #000000; */
5867: }
5868:
5869: div.LC_grade_show_user div.LC_Box {
5870: margin-right: 50px;
1.597 albertel 5871: }
5872:
5873: div.LC_grade_submissions,
5874: div.LC_grade_message_center,
1.936 bisitz 5875: div.LC_grade_info_links {
1.597 albertel 5876: margin: 5px;
5877: width: 99%;
5878: background: #FFFFFF;
5879: }
1.795 www 5880:
1.597 albertel 5881: div.LC_grade_submissions_header,
1.936 bisitz 5882: div.LC_grade_message_center_header {
1.705 tempelho 5883: font-weight: bold;
5884: font-size: large;
1.597 albertel 5885: }
1.795 www 5886:
1.597 albertel 5887: div.LC_grade_submissions_body,
1.936 bisitz 5888: div.LC_grade_message_center_body {
1.597 albertel 5889: border: 1px solid black;
5890: width: 99%;
5891: background: #FFFFFF;
5892: }
1.795 www 5893:
1.613 albertel 5894: table.LC_scantron_action {
5895: width: 100%;
5896: }
1.795 www 5897:
1.613 albertel 5898: table.LC_scantron_action tr th {
1.698 harmsja 5899: font-weight:bold;
5900: font-style:normal;
1.613 albertel 5901: }
1.795 www 5902:
1.779 bisitz 5903: .LC_edit_problem_header,
1.614 albertel 5904: div.LC_edit_problem_footer {
1.705 tempelho 5905: font-weight: normal;
5906: font-size: medium;
1.602 albertel 5907: margin: 2px;
1.600 albertel 5908: }
1.795 www 5909:
1.600 albertel 5910: div.LC_edit_problem_header,
1.602 albertel 5911: div.LC_edit_problem_header div,
1.614 albertel 5912: div.LC_edit_problem_footer,
5913: div.LC_edit_problem_footer div,
1.602 albertel 5914: div.LC_edit_problem_editxml_header,
5915: div.LC_edit_problem_editxml_header div {
1.600 albertel 5916: margin-top: 5px;
5917: }
1.795 www 5918:
1.600 albertel 5919: div.LC_edit_problem_header_title {
1.705 tempelho 5920: font-weight: bold;
5921: font-size: larger;
1.602 albertel 5922: background: $tabbg;
5923: padding: 3px;
5924: }
1.795 www 5925:
1.602 albertel 5926: table.LC_edit_problem_header_title {
5927: width: 100%;
1.600 albertel 5928: background: $tabbg;
1.602 albertel 5929: }
5930:
5931: div.LC_edit_problem_discards {
5932: float: left;
5933: padding-bottom: 5px;
5934: }
1.795 www 5935:
1.602 albertel 5936: div.LC_edit_problem_saves {
5937: float: right;
5938: padding-bottom: 5px;
1.600 albertel 5939: }
1.795 www 5940:
1.911 bisitz 5941: img.stift {
1.803 bisitz 5942: border-width: 0;
5943: vertical-align: middle;
1.677 riegler 5944: }
1.680 riegler 5945:
1.923 bisitz 5946: table td.LC_mainmenu_col_fieldset {
1.680 riegler 5947: vertical-align: top;
1.777 tempelho 5948: }
1.795 www 5949:
1.716 raeburn 5950: div.LC_createcourse {
1.911 bisitz 5951: margin: 10px 10px 10px 10px;
1.716 raeburn 5952: }
5953:
1.917 raeburn 5954: .LC_dccid {
5955: margin: 0.2em 0 0 0;
5956: padding: 0;
5957: font-size: 90%;
5958: display:none;
5959: }
5960:
1.698 harmsja 5961: a:hover,
1.897 wenzelju 5962: ol.LC_primary_menu a:hover,
1.721 harmsja 5963: ol#LC_MenuBreadcrumbs a:hover,
5964: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5965: ul#LC_secondary_menu a:hover,
1.721 harmsja 5966: .LC_FormSectionClearButton input:hover
1.795 www 5967: ul.LC_TabContent li:hover a {
1.911 bisitz 5968: color:#BF2317;
5969: text-decoration:none;
1.693 droeschl 5970: }
5971:
1.779 bisitz 5972: h1 {
1.911 bisitz 5973: padding: 0;
5974: line-height:130%;
1.693 droeschl 5975: }
1.698 harmsja 5976:
1.911 bisitz 5977: h2,
5978: h3,
5979: h4,
5980: h5,
5981: h6 {
5982: margin: 5px 0 5px 0;
5983: padding: 0;
5984: line-height:130%;
1.693 droeschl 5985: }
1.795 www 5986:
5987: .LC_hcell {
1.911 bisitz 5988: padding:3px 15px 3px 15px;
5989: margin: 0;
5990: background-color:$tabbg;
5991: color:$fontmenu;
5992: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5993: }
1.795 www 5994:
1.840 bisitz 5995: .LC_Box > .LC_hcell {
1.911 bisitz 5996: margin: 0 -10px 10px -10px;
1.835 bisitz 5997: }
5998:
1.721 harmsja 5999: .LC_noBorder {
1.911 bisitz 6000: border: 0;
1.698 harmsja 6001: }
1.693 droeschl 6002:
1.721 harmsja 6003: .LC_FormSectionClearButton input {
1.911 bisitz 6004: background-color:transparent;
6005: border: none;
6006: cursor:pointer;
6007: text-decoration:underline;
1.693 droeschl 6008: }
1.763 bisitz 6009:
6010: .LC_help_open_topic {
1.911 bisitz 6011: color: #FFFFFF;
6012: background-color: #EEEEFF;
6013: margin: 1px;
6014: padding: 4px;
6015: border: 1px solid #000033;
6016: white-space: nowrap;
6017: /* vertical-align: middle; */
1.759 neumanie 6018: }
1.693 droeschl 6019:
1.911 bisitz 6020: dl,
6021: ul,
6022: div,
6023: fieldset {
6024: margin: 10px 10px 10px 0;
6025: /* overflow: hidden; */
1.693 droeschl 6026: }
1.795 www 6027:
1.838 bisitz 6028: fieldset > legend {
1.911 bisitz 6029: font-weight: bold;
6030: padding: 0 5px 0 5px;
1.838 bisitz 6031: }
6032:
1.813 bisitz 6033: #LC_nav_bar {
1.911 bisitz 6034: float: left;
1.934 droeschl 6035: margin: 0;
1.807 droeschl 6036: }
6037:
1.916 droeschl 6038: #LC_realm {
6039: margin: 0.2em 0 0 0;
6040: padding: 0;
6041: font-weight: bold;
6042: text-align: center;
6043: }
6044:
1.911 bisitz 6045: #LC_nav_bar em {
6046: font-weight: bold;
6047: font-style: normal;
1.807 droeschl 6048: }
6049:
1.897 wenzelju 6050: ol.LC_primary_menu {
1.911 bisitz 6051: float: right;
1.934 droeschl 6052: margin: 0;
1.807 droeschl 6053: }
6054:
1.852 droeschl 6055: ol#LC_PathBreadcrumbs {
1.911 bisitz 6056: margin: 0;
1.693 droeschl 6057: }
6058:
1.897 wenzelju 6059: ol.LC_primary_menu li {
1.911 bisitz 6060: display: inline;
6061: padding: 5px 5px 0 10px;
6062: vertical-align: top;
1.693 droeschl 6063: }
6064:
1.897 wenzelju 6065: ol.LC_primary_menu li img {
1.911 bisitz 6066: vertical-align: bottom;
1.934 droeschl 6067: height: 1.1em;
1.693 droeschl 6068: }
6069:
1.897 wenzelju 6070: ol.LC_primary_menu a {
1.911 bisitz 6071: color: RGB(80, 80, 80);
6072: text-decoration: none;
1.693 droeschl 6073: }
1.795 www 6074:
1.949 droeschl 6075: ol.LC_primary_menu a.LC_new_message {
6076: font-weight:bold;
6077: color: darkred;
6078: }
6079:
1.897 wenzelju 6080: ul#LC_secondary_menu {
1.911 bisitz 6081: clear: both;
6082: color: $fontmenu;
6083: background: $tabbg;
6084: list-style: none;
6085: padding: 0;
6086: margin: 0;
6087: width: 100%;
1.808 droeschl 6088: }
6089:
1.897 wenzelju 6090: ul#LC_secondary_menu li {
1.911 bisitz 6091: font-weight: bold;
6092: line-height: 1.8em;
6093: padding: 0 0.8em;
6094: border-right: 1px solid black;
6095: display: inline;
6096: vertical-align: middle;
1.807 droeschl 6097: }
6098:
1.847 tempelho 6099: ul.LC_TabContent {
1.911 bisitz 6100: display:block;
6101: background: $sidebg;
6102: border-bottom: solid 1px $lg_border_color;
6103: list-style:none;
6104: margin: 0 -10px;
6105: padding: 0;
1.693 droeschl 6106: }
6107:
1.795 www 6108: ul.LC_TabContent li,
6109: ul.LC_TabContentBigger li {
1.911 bisitz 6110: float:left;
1.741 harmsja 6111: }
1.795 www 6112:
1.897 wenzelju 6113: ul#LC_secondary_menu li a {
1.911 bisitz 6114: color: $fontmenu;
6115: text-decoration: none;
1.693 droeschl 6116: }
1.795 www 6117:
1.721 harmsja 6118: ul.LC_TabContent {
1.911 bisitz 6119: min-height:1.5em;
1.721 harmsja 6120: }
1.795 www 6121:
6122: ul.LC_TabContent li {
1.911 bisitz 6123: vertical-align:middle;
6124: padding: 0 10px 0 10px;
6125: background-color:$tabbg;
6126: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 6127: }
1.795 www 6128:
1.847 tempelho 6129: ul.LC_TabContent .right {
1.911 bisitz 6130: float:right;
1.847 tempelho 6131: }
6132:
1.911 bisitz 6133: ul.LC_TabContent li a,
6134: ul.LC_TabContent li {
6135: color:rgb(47,47,47);
6136: text-decoration:none;
6137: font-size:95%;
6138: font-weight:bold;
6139: padding-right: 16px;
1.721 harmsja 6140: }
1.795 www 6141:
1.911 bisitz 6142: ul.LC_TabContent li:hover,
6143: ul.LC_TabContent li.active {
6144: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
6145: border-bottom:solid 2px #FFFFFF;
6146: padding-right: 16px;
1.950 ! onken 6147: cursor:pointer;
1.744 ehlerst 6148: }
1.795 www 6149:
1.870 tempelho 6150: #maincoursedoc {
1.911 bisitz 6151: clear:both;
1.870 tempelho 6152: }
6153:
6154: ul.LC_TabContentBigger {
1.911 bisitz 6155: display:block;
6156: list-style:none;
6157: padding: 0;
1.870 tempelho 6158: }
6159:
1.795 www 6160: ul.LC_TabContentBigger li {
1.911 bisitz 6161: vertical-align:bottom;
6162: height: 30px;
6163: font-size:110%;
6164: font-weight:bold;
6165: color: #737373;
1.841 tempelho 6166: }
6167:
1.870 tempelho 6168:
6169: ul.LC_TabContentBigger li a {
1.911 bisitz 6170: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6171: height: 30px;
6172: line-height: 30px;
6173: text-align: center;
6174: display: block;
6175: text-decoration: none;
1.741 harmsja 6176: }
1.795 www 6177:
1.911 bisitz 6178: ul.LC_TabContentBigger li:hover a,
1.870 tempelho 6179: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6180: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6181: color:$font;
6182: text-decoration: underline;
1.744 ehlerst 6183: }
1.795 www 6184:
1.870 tempelho 6185:
6186: ul.LC_TabContentBigger li b {
1.911 bisitz 6187: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6188: display: block;
6189: float: left;
6190: padding: 0 30px;
1.870 tempelho 6191: }
6192:
6193: ul.LC_TabContentBigger li:hover b,
6194: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6195: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6196: color:$font;
6197: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6198: }
1.693 droeschl 6199:
1.870 tempelho 6200:
1.862 bisitz 6201: ul.LC_CourseBreadcrumbs {
6202: background: $sidebg;
6203: line-height: 32px;
6204: padding-left: 10px;
6205: margin: 0 0 10px 0;
6206: list-style-position: inside;
6207:
6208: }
6209:
1.911 bisitz 6210: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6211: ol#LC_PathBreadcrumbs {
1.911 bisitz 6212: padding-left: 10px;
6213: margin: 0;
1.933 droeschl 6214: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6215: }
6216:
1.911 bisitz 6217: ol#LC_MenuBreadcrumbs li,
6218: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6219: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6220: display: inline;
1.933 droeschl 6221: white-space: normal;
1.693 droeschl 6222: }
6223:
1.823 bisitz 6224: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6225: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6226: text-decoration: none;
6227: font-size:90%;
1.693 droeschl 6228: }
1.795 www 6229:
6230: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6231: text-decoration:none;
6232: font-size:100%;
6233: font-weight:bold;
1.693 droeschl 6234: }
1.795 www 6235:
1.840 bisitz 6236: .LC_Box {
1.911 bisitz 6237: border: solid 1px $lg_border_color;
6238: padding: 0 10px 10px 10px;
1.746 neumanie 6239: }
1.795 www 6240:
6241: .LC_AboutMe_Image {
1.911 bisitz 6242: float:left;
6243: margin-right:10px;
1.747 neumanie 6244: }
1.795 www 6245:
6246: .LC_Clear_AboutMe_Image {
1.911 bisitz 6247: clear:left;
1.747 neumanie 6248: }
1.795 www 6249:
1.721 harmsja 6250: dl.LC_ListStyleClean dt {
1.911 bisitz 6251: padding-right: 5px;
6252: display: table-header-group;
1.693 droeschl 6253: }
6254:
1.721 harmsja 6255: dl.LC_ListStyleClean dd {
1.911 bisitz 6256: display: table-row;
1.693 droeschl 6257: }
6258:
1.721 harmsja 6259: .LC_ListStyleClean,
6260: .LC_ListStyleSimple,
6261: .LC_ListStyleNormal,
1.795 www 6262: .LC_ListStyleSpecial {
1.911 bisitz 6263: /* display:block; */
6264: list-style-position: inside;
6265: list-style-type: none;
6266: overflow: hidden;
6267: padding: 0;
1.693 droeschl 6268: }
6269:
1.721 harmsja 6270: .LC_ListStyleSimple li,
6271: .LC_ListStyleSimple dd,
6272: .LC_ListStyleNormal li,
6273: .LC_ListStyleNormal dd,
6274: .LC_ListStyleSpecial li,
1.795 www 6275: .LC_ListStyleSpecial dd {
1.911 bisitz 6276: margin: 0;
6277: padding: 5px 5px 5px 10px;
6278: clear: both;
1.693 droeschl 6279: }
6280:
1.721 harmsja 6281: .LC_ListStyleClean li,
6282: .LC_ListStyleClean dd {
1.911 bisitz 6283: padding-top: 0;
6284: padding-bottom: 0;
1.693 droeschl 6285: }
6286:
1.721 harmsja 6287: .LC_ListStyleSimple dd,
1.795 www 6288: .LC_ListStyleSimple li {
1.911 bisitz 6289: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6290: }
6291:
1.721 harmsja 6292: .LC_ListStyleSpecial li,
6293: .LC_ListStyleSpecial dd {
1.911 bisitz 6294: list-style-type: none;
6295: background-color: RGB(220, 220, 220);
6296: margin-bottom: 4px;
1.693 droeschl 6297: }
6298:
1.721 harmsja 6299: table.LC_SimpleTable {
1.911 bisitz 6300: margin:5px;
6301: border:solid 1px $lg_border_color;
1.795 www 6302: }
1.693 droeschl 6303:
1.721 harmsja 6304: table.LC_SimpleTable tr {
1.911 bisitz 6305: padding: 0;
6306: border:solid 1px $lg_border_color;
1.693 droeschl 6307: }
1.795 www 6308:
6309: table.LC_SimpleTable thead {
1.911 bisitz 6310: background:rgb(220,220,220);
1.693 droeschl 6311: }
6312:
1.721 harmsja 6313: div.LC_columnSection {
1.911 bisitz 6314: display: block;
6315: clear: both;
6316: overflow: hidden;
6317: margin: 0;
1.693 droeschl 6318: }
6319:
1.721 harmsja 6320: div.LC_columnSection>* {
1.911 bisitz 6321: float: left;
6322: margin: 10px 20px 10px 0;
6323: overflow:hidden;
1.693 droeschl 6324: }
1.721 harmsja 6325:
1.694 tempelho 6326: .LC_loginpage_container {
1.911 bisitz 6327: text-align:left;
6328: margin : 0 auto;
6329: width:90%;
6330: padding: 10px;
6331: height: auto;
6332: background-color:#FFFFFF;
6333: border:1px solid #CCCCCC;
1.694 tempelho 6334: }
6335:
6336:
6337: .LC_loginpage_loginContainer {
1.911 bisitz 6338: float:left;
6339: width: 182px;
6340: padding: 2px;
6341: border:1px solid #CCCCCC;
6342: background-color:$loginbg;
1.694 tempelho 6343: }
6344:
1.795 www 6345: .LC_loginpage_loginContainer h2 {
1.911 bisitz 6346: margin-top: 0;
6347: display:block;
6348: background:$bgcol;
6349: color:$textcol;
6350: padding-left:5px;
1.712 muellerd 6351: }
1.785 tempelho 6352:
1.694 tempelho 6353: .LC_loginpage_loginInfo {
1.911 bisitz 6354: float:left;
6355: width:182px;
6356: border:1px solid #CCCCCC;
6357: padding:2px;
1.712 muellerd 6358: }
6359:
1.694 tempelho 6360: .LC_loginpage_space {
1.911 bisitz 6361: clear: both;
6362: margin-bottom: 20px;
6363: border-bottom: 1px solid #CCCCCC;
1.694 tempelho 6364: }
6365:
1.785 tempelho 6366: .LC_loginpage_floatLeft {
1.911 bisitz 6367: float: left;
6368: width: 200px;
6369: margin: 0;
1.785 tempelho 6370: }
6371:
1.795 www 6372: table em {
1.911 bisitz 6373: font-weight: bold;
6374: font-style: normal;
1.748 schulted 6375: }
1.795 www 6376:
1.779 bisitz 6377: table.LC_tableBrowseRes,
1.795 www 6378: table.LC_tableOfContent {
1.911 bisitz 6379: border:none;
6380: border-spacing: 1px;
6381: padding: 3px;
6382: background-color: #FFFFFF;
6383: font-size: 90%;
1.753 droeschl 6384: }
1.789 droeschl 6385:
1.911 bisitz 6386: table.LC_tableOfContent {
6387: border-collapse: collapse;
1.789 droeschl 6388: }
6389:
1.771 droeschl 6390: table.LC_tableBrowseRes a,
1.768 schulted 6391: table.LC_tableOfContent a {
1.911 bisitz 6392: background-color: transparent;
6393: text-decoration: none;
1.753 droeschl 6394: }
6395:
1.795 www 6396: table.LC_tableOfContent img {
1.911 bisitz 6397: border: none;
6398: height: 1.3em;
6399: vertical-align: text-bottom;
6400: margin-right: 0.3em;
1.753 droeschl 6401: }
1.757 schulted 6402:
1.795 www 6403: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6404: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6405: }
6406:
1.795 www 6407: a#LC_content_toolbar_launchnav {
1.911 bisitz 6408: background-image:url(/res/adm/pages/start-navigation.gif);
1.774 ehlerst 6409: }
6410:
1.795 www 6411: a#LC_content_toolbar_closenav {
1.911 bisitz 6412: background-image:url(/res/adm/pages/close-navigation.gif);
1.774 ehlerst 6413: }
6414:
1.795 www 6415: a#LC_content_toolbar_everything {
1.911 bisitz 6416: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6417: }
6418:
1.795 www 6419: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6420: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6421: }
6422:
1.795 www 6423: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6424: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6425: }
6426:
1.795 www 6427: a#LC_content_toolbar_changefolder {
1.911 bisitz 6428: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6429: }
6430:
1.795 www 6431: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6432: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6433: }
6434:
1.795 www 6435: ul#LC_toolbar li a:hover {
1.911 bisitz 6436: background-position: bottom center;
1.757 schulted 6437: }
6438:
1.795 www 6439: ul#LC_toolbar {
1.911 bisitz 6440: padding: 0;
6441: margin: 2px;
6442: list-style:none;
6443: position:relative;
6444: background-color:white;
1.757 schulted 6445: }
6446:
1.795 www 6447: ul#LC_toolbar li {
1.911 bisitz 6448: border:1px solid white;
6449: padding: 0;
6450: margin: 0;
6451: float: left;
6452: display:inline;
6453: vertical-align:middle;
6454: }
1.757 schulted 6455:
1.783 amueller 6456:
1.795 www 6457: a.LC_toolbarItem {
1.911 bisitz 6458: display:block;
6459: padding: 0;
6460: margin: 0;
6461: height: 32px;
6462: width: 32px;
6463: color:white;
6464: border: none;
6465: background-repeat:no-repeat;
6466: background-color:transparent;
1.757 schulted 6467: }
6468:
1.915 droeschl 6469: ul.LC_funclist {
6470: margin: 0;
6471: padding: 0.5em 1em 0.5em 0;
6472: }
6473:
1.933 droeschl 6474: ul.LC_funclist > li:first-child {
6475: font-weight:bold;
6476: margin-left:0.8em;
6477: }
6478:
1.915 droeschl 6479: ul.LC_funclist + ul.LC_funclist {
6480: /*
6481: left border as a seperator if we have more than
6482: one list
6483: */
6484: border-left: 1px solid $sidebg;
6485: /*
6486: this hides the left border behind the border of the
6487: outer box if element is wrapped to the next 'line'
6488: */
6489: margin-left: -1px;
6490: }
6491:
1.843 bisitz 6492: ul.LC_funclist li {
1.915 droeschl 6493: display: inline;
1.782 bisitz 6494: white-space: nowrap;
1.915 droeschl 6495: margin: 0 0 0 25px;
6496: line-height: 150%;
1.782 bisitz 6497: }
6498:
1.930 faziophi 6499: .ui-accordion .LC_advanced_toggle {
6500: float: right;
6501: font-size: 90%;
6502: padding: 0px 4px
6503: }
1.757 schulted 6504:
1.343 albertel 6505: END
6506: }
6507:
1.306 albertel 6508: =pod
6509:
6510: =item * &headtag()
6511:
6512: Returns a uniform footer for LON-CAPA web pages.
6513:
1.307 albertel 6514: Inputs: $title - optional title for the head
6515: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6516: $args - optional arguments
1.319 albertel 6517: force_register - if is true call registerurl so the remote is
6518: informed
1.415 albertel 6519: redirect -> array ref of
6520: 1- seconds before redirect occurs
6521: 2- url to redirect to
6522: 3- whether the side effect should occur
1.315 albertel 6523: (side effect of setting
6524: $env{'internal.head.redirect'} to the url
6525: redirected too)
1.352 albertel 6526: domain -> force to color decorate a page for a specific
6527: domain
6528: function -> force usage of a specific rolish color scheme
6529: bgcolor -> override the default page bgcolor
1.460 albertel 6530: no_auto_mt_title
6531: -> prevent &mt()ing the title arg
1.464 albertel 6532:
1.306 albertel 6533: =cut
6534:
6535: sub headtag {
1.313 albertel 6536: my ($title,$head_extra,$args) = @_;
1.306 albertel 6537:
1.363 albertel 6538: my $function = $args->{'function'} || &get_users_function();
6539: my $domain = $args->{'domain'} || &determinedomain();
6540: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6541: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6542: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6543: #time(),
1.418 albertel 6544: $env{'environment.color.timestamp'},
1.363 albertel 6545: $function,$domain,$bgcolor);
6546:
1.369 www 6547: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6548:
1.308 albertel 6549: my $result =
6550: '<head>'.
1.461 albertel 6551: &font_settings();
1.319 albertel 6552:
1.461 albertel 6553: if (!$args->{'frameset'}) {
6554: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6555: }
1.319 albertel 6556: if ($args->{'force_register'}) {
6557: $result .= &Apache::lonmenu::registerurl(1);
6558: }
1.436 albertel 6559: if (!$args->{'no_nav_bar'}
6560: && !$args->{'only_body'}
6561: && !$args->{'frameset'}) {
6562: $result .= &help_menu_js();
6563: }
1.319 albertel 6564:
1.314 albertel 6565: if (ref($args->{'redirect'})) {
1.414 albertel 6566: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6567: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6568: if (!$inhibit_continue) {
6569: $env{'internal.head.redirect'} = $url;
6570: }
1.313 albertel 6571: $result.=<<ADDMETA
6572: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6573: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6574: ADDMETA
6575: }
1.306 albertel 6576: if (!defined($title)) {
6577: $title = 'The LearningOnline Network with CAPA';
6578: }
1.460 albertel 6579: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6580: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6581: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6582: .$head_extra;
1.306 albertel 6583: return $result;
6584: }
6585:
6586: =pod
6587:
1.340 albertel 6588: =item * &font_settings()
6589:
6590: Returns neccessary <meta> to set the proper encoding
6591:
6592: Inputs: none
6593:
6594: =cut
6595:
6596: sub font_settings {
6597: my $headerstring='';
1.647 www 6598: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6599: $headerstring.=
6600: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6601: }
6602: return $headerstring;
6603: }
6604:
1.341 albertel 6605: =pod
6606:
6607: =item * &xml_begin()
6608:
6609: Returns the needed doctype and <html>
6610:
6611: Inputs: none
6612:
6613: =cut
6614:
6615: sub xml_begin {
6616: my $output='';
6617:
1.592 albertel 6618: if ($env{'internal.start_page'}==1) {
6619: &Apache::lonhtmlcommon::init_htmlareafields();
6620: }
1.342 albertel 6621:
1.341 albertel 6622: if ($env{'browser.mathml'}) {
6623: $output='<?xml version="1.0"?>'
6624: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6625: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6626:
6627: # .'<!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">] >'
6628: .'<!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">'
6629: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6630: .'xmlns="http://www.w3.org/1999/xhtml">';
6631: } else {
1.849 bisitz 6632: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6633: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6634: }
6635: return $output;
6636: }
1.340 albertel 6637:
6638: =pod
6639:
1.306 albertel 6640: =item * &endheadtag()
6641:
6642: Returns a uniform </head> for LON-CAPA web pages.
6643:
6644: Inputs: none
6645:
6646: =cut
6647:
6648: sub endheadtag {
6649: return '</head>';
6650: }
6651:
6652: =pod
6653:
6654: =item * &head()
6655:
6656: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6657:
1.648 raeburn 6658: Inputs:
6659:
6660: =over 4
6661:
6662: $title - optional title for the page
6663:
6664: $head_extra - optional extra HTML to put inside the <head>
6665:
6666: =back
1.405 albertel 6667:
1.306 albertel 6668: =cut
6669:
6670: sub head {
1.325 albertel 6671: my ($title,$head_extra,$args) = @_;
6672: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6673: }
6674:
6675: =pod
6676:
6677: =item * &start_page()
6678:
6679: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6680:
1.648 raeburn 6681: Inputs:
6682:
6683: =over 4
6684:
6685: $title - optional title for the page
6686:
6687: $head_extra - optional extra HTML to incude inside the <head>
6688:
6689: $args - additional optional args supported are:
6690:
6691: =over 8
6692:
6693: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6694: arg on
1.814 bisitz 6695: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6696: add_entries -> additional attributes to add to the <body>
6697: domain -> force to color decorate a page for a
1.317 albertel 6698: specific domain
1.648 raeburn 6699: function -> force usage of a specific rolish color
1.317 albertel 6700: scheme
1.648 raeburn 6701: redirect -> see &headtag()
6702: bgcolor -> override the default page bg color
6703: js_ready -> return a string ready for being used in
1.317 albertel 6704: a javascript writeln
1.648 raeburn 6705: html_encode -> return a string ready for being used in
1.320 albertel 6706: a html attribute
1.648 raeburn 6707: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6708: $forcereg arg
1.648 raeburn 6709: frameset -> if true will start with a <frameset>
1.330 albertel 6710: rather than <body>
1.648 raeburn 6711: skip_phases -> hash ref of
1.338 albertel 6712: head -> skip the <html><head> generation
6713: body -> skip all <body> generation
1.949 droeschl 6714: #RC no_inline_link -> if true and in remote mode, don't show the
6715: #RC 'Switch To Inline Menu' link
1.648 raeburn 6716: no_auto_mt_title -> prevent &mt()ing the title arg
6717: inherit_jsmath -> when creating popup window in a page,
6718: should it have jsmath forced on by the
6719: current page
1.867 kalberla 6720: bread_crumbs -> Array containing breadcrumbs
6721: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6722:
1.648 raeburn 6723: =back
1.460 albertel 6724:
1.648 raeburn 6725: =back
1.562 albertel 6726:
1.306 albertel 6727: =cut
6728:
6729: sub start_page {
1.309 albertel 6730: my ($title,$head_extra,$args) = @_;
1.318 albertel 6731: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6732: my %head_args;
1.352 albertel 6733: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6734: 'bgcolor','frameset','no_nav_bar','only_body',
6735: 'no_auto_mt_title') {
1.319 albertel 6736: if (defined($args->{$arg})) {
1.324 raeburn 6737: $head_args{$arg} = $args->{$arg};
1.319 albertel 6738: }
1.313 albertel 6739: }
1.319 albertel 6740:
1.315 albertel 6741: $env{'internal.start_page'}++;
1.338 albertel 6742: my $result;
6743: if (! exists($args->{'skip_phases'}{'head'}) ) {
6744: $result.=
1.341 albertel 6745: &xml_begin().
1.338 albertel 6746: &headtag($title,$head_extra,\%head_args).&endheadtag();
6747: }
6748:
6749: if (! exists($args->{'skip_phases'}{'body'}) ) {
6750: if ($args->{'frameset'}) {
6751: my $attr_string = &make_attr_string($args->{'force_register'},
6752: $args->{'add_entries'});
6753: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6754: } else {
6755: $result .=
6756: &bodytag($title,
6757: $args->{'function'}, $args->{'add_entries'},
6758: $args->{'only_body'}, $args->{'domain'},
6759: $args->{'force_register'}, $args->{'no_nav_bar'},
6760: $args->{'bgcolor'}, $args->{'no_inline_link'},
6761: $args);
6762: }
1.330 albertel 6763: }
1.338 albertel 6764:
1.315 albertel 6765: if ($args->{'js_ready'}) {
1.713 kaisler 6766: $result = &js_ready($result);
1.315 albertel 6767: }
1.320 albertel 6768: if ($args->{'html_encode'}) {
1.713 kaisler 6769: $result = &html_encode($result);
6770: }
6771:
1.813 bisitz 6772: # Preparation for new and consistent functionlist at top of screen
6773: # if ($args->{'functionlist'}) {
6774: # $result .= &build_functionlist();
6775: #}
6776:
6777: # Don't add anything more if only_body wanted
6778: return $result if $args->{'only_body'};
6779:
1.920 raeburn 6780: #Breadcrumbs for Construction Space provided by &bodytag.
1.949 droeschl 6781: if (
6782: $env{'request.state'} eq 'construct') {
1.920 raeburn 6783: return $result;
6784: }
6785:
1.813 bisitz 6786: #Breadcrumbs
1.758 kaisler 6787: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6788: &Apache::lonhtmlcommon::clear_breadcrumbs();
6789: #if any br links exists, add them to the breadcrumbs
6790: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6791: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6792: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6793: }
6794: }
6795:
6796: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6797: if(exists($args->{'bread_crumbs_component'})){
6798: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6799: }else{
6800: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6801: }
1.320 albertel 6802: }
1.315 albertel 6803: return $result;
1.306 albertel 6804: }
6805:
1.330 albertel 6806:
1.306 albertel 6807: =pod
6808:
6809: =item * &head()
6810:
6811: Returns a complete </body></html> section for LON-CAPA web pages.
6812:
1.315 albertel 6813: Inputs: $args - additional optional args supported are:
6814: js_ready -> return a string ready for being used in
6815: a javascript writeln
1.320 albertel 6816: html_encode -> return a string ready for being used in
6817: a html attribute
1.330 albertel 6818: frameset -> if true will start with a <frameset>
6819: rather than <body>
1.493 albertel 6820: dicsussion -> if true will get discussion from
6821: lonxml::xmlend
6822: (you can pass the target and parser arguments
6823: through optional 'target' and 'parser' args
6824: to this routine)
1.306 albertel 6825:
6826: =cut
6827:
6828: sub end_page {
1.315 albertel 6829: my ($args) = @_;
6830: $env{'internal.end_page'}++;
1.330 albertel 6831: my $result;
1.335 albertel 6832: if ($args->{'discussion'}) {
6833: my ($target,$parser);
6834: if (ref($args->{'discussion'})) {
6835: ($target,$parser) =($args->{'discussion'}{'target'},
6836: $args->{'discussion'}{'parser'});
6837: }
6838: $result .= &Apache::lonxml::xmlend($target,$parser);
6839: }
6840:
1.330 albertel 6841: if ($args->{'frameset'}) {
6842: $result .= '</frameset>';
6843: } else {
1.635 raeburn 6844: $result .= &endbodytag($args);
1.330 albertel 6845: }
6846: $result .= "\n</html>";
6847:
1.315 albertel 6848: if ($args->{'js_ready'}) {
1.317 albertel 6849: $result = &js_ready($result);
1.315 albertel 6850: }
1.335 albertel 6851:
1.320 albertel 6852: if ($args->{'html_encode'}) {
6853: $result = &html_encode($result);
6854: }
1.335 albertel 6855:
1.315 albertel 6856: return $result;
6857: }
6858:
1.320 albertel 6859: sub html_encode {
6860: my ($result) = @_;
6861:
1.322 albertel 6862: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6863:
6864: return $result;
6865: }
1.317 albertel 6866: sub js_ready {
6867: my ($result) = @_;
6868:
1.323 albertel 6869: $result =~ s/[\n\r]/ /xmsg;
6870: $result =~ s/\\/\\\\/xmsg;
6871: $result =~ s/'/\\'/xmsg;
1.372 albertel 6872: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6873:
6874: return $result;
6875: }
6876:
1.315 albertel 6877: sub validate_page {
6878: if ( exists($env{'internal.start_page'})
1.316 albertel 6879: && $env{'internal.start_page'} > 1) {
6880: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6881: $env{'internal.start_page'}.' '.
1.316 albertel 6882: $ENV{'request.filename'});
1.315 albertel 6883: }
6884: if ( exists($env{'internal.end_page'})
1.316 albertel 6885: && $env{'internal.end_page'} > 1) {
6886: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6887: $env{'internal.end_page'}.' '.
1.316 albertel 6888: $env{'request.filename'});
1.315 albertel 6889: }
6890: if ( exists($env{'internal.start_page'})
6891: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6892: &Apache::lonnet::logthis('start_page called without end_page '.
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('end_page called without start_page'.
6898: $env{'request.filename'});
1.315 albertel 6899: }
1.306 albertel 6900: }
1.315 albertel 6901:
1.318 albertel 6902: sub simple_error_page {
6903: my ($r,$title,$msg) = @_;
6904: my $page =
6905: &Apache::loncommon::start_page($title).
6906: &mt($msg).
6907: &Apache::loncommon::end_page();
6908: if (ref($r)) {
6909: $r->print($page);
1.327 albertel 6910: return;
1.318 albertel 6911: }
6912: return $page;
6913: }
1.347 albertel 6914:
6915: {
1.610 albertel 6916: my @row_count;
1.347 albertel 6917: sub start_data_table {
1.422 albertel 6918: my ($add_class) = @_;
6919: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6920: unshift(@row_count,0);
1.422 albertel 6921: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6922: }
6923:
6924: sub end_data_table {
1.610 albertel 6925: shift(@row_count);
1.389 albertel 6926: return '</table>'."\n";;
1.347 albertel 6927: }
6928:
6929: sub start_data_table_row {
1.422 albertel 6930: my ($add_class) = @_;
1.610 albertel 6931: $row_count[0]++;
6932: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6933: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 6934: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6935: }
1.471 banghart 6936:
6937: sub continue_data_table_row {
6938: my ($add_class) = @_;
1.610 albertel 6939: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6940: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 6941: return '<tr class="'.$css_class.'">'."\n";;
6942: }
1.347 albertel 6943:
6944: sub end_data_table_row {
1.389 albertel 6945: return '</tr>'."\n";;
1.347 albertel 6946: }
1.367 www 6947:
1.421 albertel 6948: sub start_data_table_empty_row {
1.707 bisitz 6949: # $row_count[0]++;
1.421 albertel 6950: return '<tr class="LC_empty_row" >'."\n";;
6951: }
6952:
6953: sub end_data_table_empty_row {
6954: return '</tr>'."\n";;
6955: }
6956:
1.367 www 6957: sub start_data_table_header_row {
1.389 albertel 6958: return '<tr class="LC_header_row">'."\n";;
1.367 www 6959: }
6960:
6961: sub end_data_table_header_row {
1.389 albertel 6962: return '</tr>'."\n";;
1.367 www 6963: }
1.890 droeschl 6964:
6965: sub data_table_caption {
6966: my $caption = shift;
6967: return "<caption class=\"LC_caption\">$caption</caption>";
6968: }
1.347 albertel 6969: }
6970:
1.548 albertel 6971: =pod
6972:
6973: =item * &inhibit_menu_check($arg)
6974:
6975: Checks for a inhibitmenu state and generates output to preserve it
6976:
6977: Inputs: $arg - can be any of
6978: - undef - in which case the return value is a string
6979: to add into arguments list of a uri
6980: - 'input' - in which case the return value is a HTML
6981: <form> <input> field of type hidden to
6982: preserve the value
6983: - a url - in which case the return value is the url with
6984: the neccesary cgi args added to preserve the
6985: inhibitmenu state
6986: - a ref to a url - no return value, but the string is
6987: updated to include the neccessary cgi
6988: args to preserve the inhibitmenu state
6989:
6990: =cut
6991:
6992: sub inhibit_menu_check {
6993: my ($arg) = @_;
6994: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6995: if ($arg eq 'input') {
6996: if ($env{'form.inhibitmenu'}) {
6997: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6998: } else {
6999: return
7000: }
7001: }
7002: if ($env{'form.inhibitmenu'}) {
7003: if (ref($arg)) {
7004: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7005: } elsif ($arg eq '') {
7006: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
7007: } else {
7008: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
7009: }
7010: }
7011: if (!ref($arg)) {
7012: return $arg;
7013: }
7014: }
7015:
1.251 albertel 7016: ###############################################
1.182 matthew 7017:
7018: =pod
7019:
1.549 albertel 7020: =back
7021:
7022: =head1 User Information Routines
7023:
7024: =over 4
7025:
1.405 albertel 7026: =item * &get_users_function()
1.182 matthew 7027:
7028: Used by &bodytag to determine the current users primary role.
7029: Returns either 'student','coordinator','admin', or 'author'.
7030:
7031: =cut
7032:
7033: ###############################################
7034: sub get_users_function {
1.815 tempelho 7035: my $function = 'norole';
1.818 tempelho 7036: if ($env{'request.role'}=~/^(st)/) {
7037: $function='student';
7038: }
1.907 raeburn 7039: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7040: $function='coordinator';
7041: }
1.258 albertel 7042: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7043: $function='admin';
7044: }
1.826 bisitz 7045: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7046: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7047: $function='author';
7048: }
7049: return $function;
1.54 www 7050: }
1.99 www 7051:
7052: ###############################################
7053:
1.233 raeburn 7054: =pod
7055:
1.821 raeburn 7056: =item * &show_course()
7057:
7058: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7059: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7060:
7061: Inputs:
7062: None
7063:
7064: Outputs:
7065: Scalar: 1 if 'Course' to be used, 0 otherwise.
7066:
7067: =cut
7068:
7069: ###############################################
7070: sub show_course {
7071: my $course = !$env{'user.adv'};
7072: if (!$env{'user.adv'}) {
7073: foreach my $env (keys(%env)) {
7074: next if ($env !~ m/^user\.priv\./);
7075: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7076: $course = 0;
7077: last;
7078: }
7079: }
7080: }
7081: return $course;
7082: }
7083:
7084: ###############################################
7085:
7086: =pod
7087:
1.542 raeburn 7088: =item * &check_user_status()
1.274 raeburn 7089:
7090: Determines current status of supplied role for a
7091: specific user. Roles can be active, previous or future.
7092:
7093: Inputs:
7094: user's domain, user's username, course's domain,
1.375 raeburn 7095: course's number, optional section ID.
1.274 raeburn 7096:
7097: Outputs:
7098: role status: active, previous or future.
7099:
7100: =cut
7101:
7102: sub check_user_status {
1.412 raeburn 7103: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 7104: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
7105: my @uroles = keys %userinfo;
7106: my $srchstr;
7107: my $active_chk = 'none';
1.412 raeburn 7108: my $now = time;
1.274 raeburn 7109: if (@uroles > 0) {
1.908 raeburn 7110: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7111: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7112: } else {
1.412 raeburn 7113: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7114: }
7115: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7116: my $role_end = 0;
7117: my $role_start = 0;
7118: $active_chk = 'active';
1.412 raeburn 7119: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7120: $role_end = $1;
7121: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7122: $role_start = $1;
1.274 raeburn 7123: }
7124: }
7125: if ($role_start > 0) {
1.412 raeburn 7126: if ($now < $role_start) {
1.274 raeburn 7127: $active_chk = 'future';
7128: }
7129: }
7130: if ($role_end > 0) {
1.412 raeburn 7131: if ($now > $role_end) {
1.274 raeburn 7132: $active_chk = 'previous';
7133: }
7134: }
7135: }
7136: }
7137: return $active_chk;
7138: }
7139:
7140: ###############################################
7141:
7142: =pod
7143:
1.405 albertel 7144: =item * &get_sections()
1.233 raeburn 7145:
7146: Determines all the sections for a course including
7147: sections with students and sections containing other roles.
1.419 raeburn 7148: Incoming parameters:
7149:
7150: 1. domain
7151: 2. course number
7152: 3. reference to array containing roles for which sections should
7153: be gathered (optional).
7154: 4. reference to array containing status types for which sections
7155: should be gathered (optional).
7156:
7157: If the third argument is undefined, sections are gathered for any role.
7158: If the fourth argument is undefined, sections are gathered for any status.
7159: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7160:
1.374 raeburn 7161: Returns section hash (keys are section IDs, values are
7162: number of users in each section), subject to the
1.419 raeburn 7163: optional roles filter, optional status filter
1.233 raeburn 7164:
7165: =cut
7166:
7167: ###############################################
7168: sub get_sections {
1.419 raeburn 7169: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7170: if (!defined($cdom) || !defined($cnum)) {
7171: my $cid = $env{'request.course.id'};
7172:
7173: return if (!defined($cid));
7174:
7175: $cdom = $env{'course.'.$cid.'.domain'};
7176: $cnum = $env{'course.'.$cid.'.num'};
7177: }
7178:
7179: my %sectioncount;
1.419 raeburn 7180: my $now = time;
1.240 albertel 7181:
1.366 albertel 7182: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7183: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7184: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7185: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7186: my $start_index = &Apache::loncoursedata::CL_START();
7187: my $end_index = &Apache::loncoursedata::CL_END();
7188: my $status;
1.366 albertel 7189: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7190: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7191: $data->[$status_index],
7192: $data->[$start_index],
7193: $data->[$end_index]);
7194: if ($stu_status eq 'Active') {
7195: $status = 'active';
7196: } elsif ($end < $now) {
7197: $status = 'previous';
7198: } elsif ($start > $now) {
7199: $status = 'future';
7200: }
7201: if ($section ne '-1' && $section !~ /^\s*$/) {
7202: if ((!defined($possible_status)) || (($status ne '') &&
7203: (grep/^\Q$status\E$/,@{$possible_status}))) {
7204: $sectioncount{$section}++;
7205: }
1.240 albertel 7206: }
7207: }
7208: }
7209: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7210: foreach my $user (sort(keys(%courseroles))) {
7211: if ($user !~ /^(\w{2})/) { next; }
7212: my ($role) = ($user =~ /^(\w{2})/);
7213: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7214: my ($section,$status);
1.240 albertel 7215: if ($role eq 'cr' &&
7216: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7217: $section=$1;
7218: }
7219: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7220: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7221: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7222: if ($end == -1 && $start == -1) {
7223: next; #deleted role
7224: }
7225: if (!defined($possible_status)) {
7226: $sectioncount{$section}++;
7227: } else {
7228: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7229: $status = 'active';
7230: } elsif ($end < $now) {
7231: $status = 'future';
7232: } elsif ($start > $now) {
7233: $status = 'previous';
7234: }
7235: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7236: $sectioncount{$section}++;
7237: }
7238: }
1.233 raeburn 7239: }
1.366 albertel 7240: return %sectioncount;
1.233 raeburn 7241: }
7242:
1.274 raeburn 7243: ###############################################
1.294 raeburn 7244:
7245: =pod
1.405 albertel 7246:
7247: =item * &get_course_users()
7248:
1.275 raeburn 7249: Retrieves usernames:domains for users in the specified course
7250: with specific role(s), and access status.
7251:
7252: Incoming parameters:
1.277 albertel 7253: 1. course domain
7254: 2. course number
7255: 3. access status: users must have - either active,
1.275 raeburn 7256: previous, future, or all.
1.277 albertel 7257: 4. reference to array of permissible roles
1.288 raeburn 7258: 5. reference to array of section restrictions (optional)
7259: 6. reference to results object (hash of hashes).
7260: 7. reference to optional userdata hash
1.609 raeburn 7261: 8. reference to optional statushash
1.630 raeburn 7262: 9. flag if privileged users (except those set to unhide in
7263: course settings) should be excluded
1.609 raeburn 7264: Keys of top level results hash are roles.
1.275 raeburn 7265: Keys of inner hashes are username:domain, with
7266: values set to access type.
1.288 raeburn 7267: Optional userdata hash returns an array with arguments in the
7268: same order as loncoursedata::get_classlist() for student data.
7269:
1.609 raeburn 7270: Optional statushash returns
7271:
1.288 raeburn 7272: Entries for end, start, section and status are blank because
7273: of the possibility of multiple values for non-student roles.
7274:
1.275 raeburn 7275: =cut
1.405 albertel 7276:
1.275 raeburn 7277: ###############################################
1.405 albertel 7278:
1.275 raeburn 7279: sub get_course_users {
1.630 raeburn 7280: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7281: my %idx = ();
1.419 raeburn 7282: my %seclists;
1.288 raeburn 7283:
7284: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7285: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7286: $idx{end} = &Apache::loncoursedata::CL_END();
7287: $idx{start} = &Apache::loncoursedata::CL_START();
7288: $idx{id} = &Apache::loncoursedata::CL_ID();
7289: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7290: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7291: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7292:
1.290 albertel 7293: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7294: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7295: my $now = time;
1.277 albertel 7296: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7297: my $match = 0;
1.412 raeburn 7298: my $secmatch = 0;
1.419 raeburn 7299: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7300: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7301: if ($section eq '') {
7302: $section = 'none';
7303: }
1.291 albertel 7304: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7305: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7306: $secmatch = 1;
7307: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7308: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7309: $secmatch = 1;
7310: }
7311: } else {
1.419 raeburn 7312: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7313: $secmatch = 1;
7314: }
1.290 albertel 7315: }
1.412 raeburn 7316: if (!$secmatch) {
7317: next;
7318: }
1.419 raeburn 7319: }
1.275 raeburn 7320: if (defined($$types{'active'})) {
1.288 raeburn 7321: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7322: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7323: $match = 1;
1.275 raeburn 7324: }
7325: }
7326: if (defined($$types{'previous'})) {
1.609 raeburn 7327: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7328: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7329: $match = 1;
1.275 raeburn 7330: }
7331: }
7332: if (defined($$types{'future'})) {
1.609 raeburn 7333: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7334: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7335: $match = 1;
1.275 raeburn 7336: }
7337: }
1.609 raeburn 7338: if ($match) {
7339: push(@{$seclists{$student}},$section);
7340: if (ref($userdata) eq 'HASH') {
7341: $$userdata{$student} = $$classlist{$student};
7342: }
7343: if (ref($statushash) eq 'HASH') {
7344: $statushash->{$student}{'st'}{$section} = $status;
7345: }
1.288 raeburn 7346: }
1.275 raeburn 7347: }
7348: }
1.412 raeburn 7349: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7350: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7351: my $now = time;
1.609 raeburn 7352: my %displaystatus = ( previous => 'Expired',
7353: active => 'Active',
7354: future => 'Future',
7355: );
1.630 raeburn 7356: my %nothide;
7357: if ($hidepriv) {
7358: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7359: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7360: if ($user !~ /:/) {
7361: $nothide{join(':',split(/[\@]/,$user))}=1;
7362: } else {
7363: $nothide{$user} = 1;
7364: }
7365: }
7366: }
1.439 raeburn 7367: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7368: my $match = 0;
1.412 raeburn 7369: my $secmatch = 0;
1.439 raeburn 7370: my $status;
1.412 raeburn 7371: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7372: $user =~ s/:$//;
1.439 raeburn 7373: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7374: if ($end == -1 || $start == -1) {
7375: next;
7376: }
7377: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7378: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7379: my ($uname,$udom) = split(/:/,$user);
7380: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7381: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7382: $secmatch = 1;
7383: } elsif ($usec eq '') {
1.420 albertel 7384: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7385: $secmatch = 1;
7386: }
7387: } else {
7388: if (grep(/^\Q$usec\E$/,@{$sections})) {
7389: $secmatch = 1;
7390: }
7391: }
7392: if (!$secmatch) {
7393: next;
7394: }
1.288 raeburn 7395: }
1.419 raeburn 7396: if ($usec eq '') {
7397: $usec = 'none';
7398: }
1.275 raeburn 7399: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7400: if ($hidepriv) {
7401: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7402: (!$nothide{$uname.':'.$udom})) {
7403: next;
7404: }
7405: }
1.503 raeburn 7406: if ($end > 0 && $end < $now) {
1.439 raeburn 7407: $status = 'previous';
7408: } elsif ($start > $now) {
7409: $status = 'future';
7410: } else {
7411: $status = 'active';
7412: }
1.277 albertel 7413: foreach my $type (keys(%{$types})) {
1.275 raeburn 7414: if ($status eq $type) {
1.420 albertel 7415: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7416: push(@{$$users{$role}{$user}},$type);
7417: }
1.288 raeburn 7418: $match = 1;
7419: }
7420: }
1.419 raeburn 7421: if (($match) && (ref($userdata) eq 'HASH')) {
7422: if (!exists($$userdata{$uname.':'.$udom})) {
7423: &get_user_info($udom,$uname,\%idx,$userdata);
7424: }
1.420 albertel 7425: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7426: push(@{$seclists{$uname.':'.$udom}},$usec);
7427: }
1.609 raeburn 7428: if (ref($statushash) eq 'HASH') {
7429: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7430: }
1.275 raeburn 7431: }
7432: }
7433: }
7434: }
1.290 albertel 7435: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7436: if ((defined($cdom)) && (defined($cnum))) {
7437: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7438: if ( defined($csettings{'internal.courseowner'}) ) {
7439: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7440: next if ($owner eq '');
7441: my ($ownername,$ownerdom);
7442: if ($owner =~ /^([^:]+):([^:]+)$/) {
7443: $ownername = $1;
7444: $ownerdom = $2;
7445: } else {
7446: $ownername = $owner;
7447: $ownerdom = $cdom;
7448: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7449: }
7450: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7451: if (defined($userdata) &&
1.609 raeburn 7452: !exists($$userdata{$owner})) {
7453: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7454: if (!grep(/^none$/,@{$seclists{$owner}})) {
7455: push(@{$seclists{$owner}},'none');
7456: }
7457: if (ref($statushash) eq 'HASH') {
7458: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7459: }
1.290 albertel 7460: }
1.279 raeburn 7461: }
7462: }
7463: }
1.419 raeburn 7464: foreach my $user (keys(%seclists)) {
7465: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7466: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7467: }
1.275 raeburn 7468: }
7469: return;
7470: }
7471:
1.288 raeburn 7472: sub get_user_info {
7473: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7474: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7475: &plainname($uname,$udom,'lastname');
1.291 albertel 7476: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7477: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7478: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7479: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7480: return;
7481: }
1.275 raeburn 7482:
1.472 raeburn 7483: ###############################################
7484:
7485: =pod
7486:
7487: =item * &get_user_quota()
7488:
7489: Retrieves quota assigned for storage of portfolio files for a user
7490:
7491: Incoming parameters:
7492: 1. user's username
7493: 2. user's domain
7494:
7495: Returns:
1.536 raeburn 7496: 1. Disk quota (in Mb) assigned to student.
7497: 2. (Optional) Type of setting: custom or default
7498: (individually assigned or default for user's
7499: institutional status).
7500: 3. (Optional) - User's institutional status (e.g., faculty, staff
7501: or student - types as defined in localenroll::inst_usertypes
7502: for user's domain, which determines default quota for user.
7503: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7504:
7505: If a value has been stored in the user's environment,
1.536 raeburn 7506: it will return that, otherwise it returns the maximal default
7507: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7508:
7509: =cut
7510:
7511: ###############################################
7512:
7513:
7514: sub get_user_quota {
7515: my ($uname,$udom) = @_;
1.536 raeburn 7516: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7517: if (!defined($udom)) {
7518: $udom = $env{'user.domain'};
7519: }
7520: if (!defined($uname)) {
7521: $uname = $env{'user.name'};
7522: }
7523: if (($udom eq '' || $uname eq '') ||
7524: ($udom eq 'public') && ($uname eq 'public')) {
7525: $quota = 0;
1.536 raeburn 7526: $quotatype = 'default';
7527: $defquota = 0;
1.472 raeburn 7528: } else {
1.536 raeburn 7529: my $inststatus;
1.472 raeburn 7530: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7531: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7532: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7533: } else {
1.536 raeburn 7534: my %userenv =
7535: &Apache::lonnet::get('environment',['portfolioquota',
7536: 'inststatus'],$udom,$uname);
1.472 raeburn 7537: my ($tmp) = keys(%userenv);
7538: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7539: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7540: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7541: } else {
7542: undef(%userenv);
7543: }
7544: }
1.536 raeburn 7545: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7546: if ($quota eq '') {
1.536 raeburn 7547: $quota = $defquota;
7548: $quotatype = 'default';
7549: } else {
7550: $quotatype = 'custom';
1.472 raeburn 7551: }
7552: }
1.536 raeburn 7553: if (wantarray) {
7554: return ($quota,$quotatype,$settingstatus,$defquota);
7555: } else {
7556: return $quota;
7557: }
1.472 raeburn 7558: }
7559:
7560: ###############################################
7561:
7562: =pod
7563:
7564: =item * &default_quota()
7565:
1.536 raeburn 7566: Retrieves default quota assigned for storage of user portfolio files,
7567: given an (optional) user's institutional status.
1.472 raeburn 7568:
7569: Incoming parameters:
7570: 1. domain
1.536 raeburn 7571: 2. (Optional) institutional status(es). This is a : separated list of
7572: status types (e.g., faculty, staff, student etc.)
7573: which apply to the user for whom the default is being retrieved.
7574: If the institutional status string in undefined, the domain
7575: default quota will be returned.
1.472 raeburn 7576:
7577: Returns:
7578: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7579: 2. (Optional) institutional type which determined the value of the
7580: default quota.
1.472 raeburn 7581:
7582: If a value has been stored in the domain's configuration db,
7583: it will return that, otherwise it returns 20 (for backwards
7584: compatibility with domains which have not set up a configuration
7585: db file; the original statically defined portfolio quota was 20 Mb).
7586:
1.536 raeburn 7587: If the user's status includes multiple types (e.g., staff and student),
7588: the largest default quota which applies to the user determines the
7589: default quota returned.
7590:
1.780 raeburn 7591: =back
7592:
1.472 raeburn 7593: =cut
7594:
7595: ###############################################
7596:
7597:
7598: sub default_quota {
1.536 raeburn 7599: my ($udom,$inststatus) = @_;
7600: my ($defquota,$settingstatus);
7601: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7602: ['quotas'],$udom);
7603: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7604: if ($inststatus ne '') {
1.765 raeburn 7605: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7606: foreach my $item (@statuses) {
1.711 raeburn 7607: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7608: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7609: if ($defquota eq '') {
7610: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7611: $settingstatus = $item;
7612: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7613: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7614: $settingstatus = $item;
7615: }
7616: }
7617: } else {
7618: if ($quotahash{'quotas'}{$item} ne '') {
7619: if ($defquota eq '') {
7620: $defquota = $quotahash{'quotas'}{$item};
7621: $settingstatus = $item;
7622: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7623: $defquota = $quotahash{'quotas'}{$item};
7624: $settingstatus = $item;
7625: }
1.536 raeburn 7626: }
7627: }
7628: }
7629: }
7630: if ($defquota eq '') {
1.711 raeburn 7631: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7632: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7633: } else {
7634: $defquota = $quotahash{'quotas'}{'default'};
7635: }
1.536 raeburn 7636: $settingstatus = 'default';
7637: }
7638: } else {
7639: $settingstatus = 'default';
7640: $defquota = 20;
7641: }
7642: if (wantarray) {
7643: return ($defquota,$settingstatus);
1.472 raeburn 7644: } else {
1.536 raeburn 7645: return $defquota;
1.472 raeburn 7646: }
7647: }
7648:
1.384 raeburn 7649: sub get_secgrprole_info {
7650: my ($cdom,$cnum,$needroles,$type) = @_;
7651: my %sections_count = &get_sections($cdom,$cnum);
7652: my @sections = (sort {$a <=> $b} keys(%sections_count));
7653: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7654: my @groups = sort(keys(%curr_groups));
7655: my $allroles = [];
7656: my $rolehash;
7657: my $accesshash = {
7658: active => 'Currently has access',
7659: future => 'Will have future access',
7660: previous => 'Previously had access',
7661: };
7662: if ($needroles) {
7663: $rolehash = {'all' => 'all'};
1.385 albertel 7664: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7665: if (&Apache::lonnet::error(%user_roles)) {
7666: undef(%user_roles);
7667: }
7668: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7669: my ($role)=split(/\:/,$item,2);
7670: if ($role eq 'cr') { next; }
7671: if ($role =~ /^cr/) {
7672: $$rolehash{$role} = (split('/',$role))[3];
7673: } else {
7674: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7675: }
7676: }
7677: foreach my $key (sort(keys(%{$rolehash}))) {
7678: push(@{$allroles},$key);
7679: }
7680: push (@{$allroles},'st');
7681: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7682: }
7683: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7684: }
7685:
1.555 raeburn 7686: sub user_picker {
1.627 raeburn 7687: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7688: my $currdom = $dom;
7689: my %curr_selected = (
7690: srchin => 'dom',
1.580 raeburn 7691: srchby => 'lastname',
1.555 raeburn 7692: );
7693: my $srchterm;
1.625 raeburn 7694: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7695: if ($srch->{'srchby'} ne '') {
7696: $curr_selected{'srchby'} = $srch->{'srchby'};
7697: }
7698: if ($srch->{'srchin'} ne '') {
7699: $curr_selected{'srchin'} = $srch->{'srchin'};
7700: }
7701: if ($srch->{'srchtype'} ne '') {
7702: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7703: }
7704: if ($srch->{'srchdomain'} ne '') {
7705: $currdom = $srch->{'srchdomain'};
7706: }
7707: $srchterm = $srch->{'srchterm'};
7708: }
7709: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7710: 'usr' => 'Search criteria',
1.563 raeburn 7711: 'doma' => 'Domain/institution to search',
1.558 albertel 7712: 'uname' => 'username',
7713: 'lastname' => 'last name',
1.555 raeburn 7714: 'lastfirst' => 'last name, first name',
1.558 albertel 7715: 'crs' => 'in this course',
1.576 raeburn 7716: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7717: 'alc' => 'all LON-CAPA',
1.573 raeburn 7718: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7719: 'exact' => 'is',
7720: 'contains' => 'contains',
1.569 raeburn 7721: 'begins' => 'begins with',
1.571 raeburn 7722: 'youm' => "You must include some text to search for.",
7723: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7724: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7725: 'yomc' => "You must choose a domain when using an institutional directory search.",
7726: 'ymcd' => "You must choose a domain when using a domain search.",
7727: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7728: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7729: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7730: );
1.563 raeburn 7731: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7732: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7733:
7734: my @srchins = ('crs','dom','alc','instd');
7735:
7736: foreach my $option (@srchins) {
7737: # FIXME 'alc' option unavailable until
7738: # loncreateuser::print_user_query_page()
7739: # has been completed.
7740: next if ($option eq 'alc');
1.880 raeburn 7741: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7742: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7743: if ($curr_selected{'srchin'} eq $option) {
7744: $srchinsel .= '
7745: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7746: } else {
7747: $srchinsel .= '
7748: <option value="'.$option.'">'.$lt{$option}.'</option>';
7749: }
1.555 raeburn 7750: }
1.563 raeburn 7751: $srchinsel .= "\n </select>\n";
1.555 raeburn 7752:
7753: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7754: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7755: if ($curr_selected{'srchby'} eq $option) {
7756: $srchbysel .= '
7757: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7758: } else {
7759: $srchbysel .= '
7760: <option value="'.$option.'">'.$lt{$option}.'</option>';
7761: }
7762: }
7763: $srchbysel .= "\n </select>\n";
7764:
7765: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7766: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7767: if ($curr_selected{'srchtype'} eq $option) {
7768: $srchtypesel .= '
7769: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7770: } else {
7771: $srchtypesel .= '
7772: <option value="'.$option.'">'.$lt{$option}.'</option>';
7773: }
7774: }
7775: $srchtypesel .= "\n </select>\n";
7776:
1.558 albertel 7777: my ($newuserscript,$new_user_create);
1.556 raeburn 7778:
7779: if ($forcenewuser) {
1.576 raeburn 7780: if (ref($srch) eq 'HASH') {
7781: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7782: if ($cancreate) {
7783: $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>';
7784: } else {
1.799 bisitz 7785: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7786: my %usertypetext = (
7787: official => 'institutional',
7788: unofficial => 'non-institutional',
7789: );
1.799 bisitz 7790: $new_user_create = '<p class="LC_warning">'
7791: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7792: .' '
7793: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7794: ,'<a href="'.$helplink.'">','</a>')
7795: .'</p><br />';
1.627 raeburn 7796: }
1.576 raeburn 7797: }
7798: }
7799:
1.556 raeburn 7800: $newuserscript = <<"ENDSCRIPT";
7801:
1.570 raeburn 7802: function setSearch(createnew,callingForm) {
1.556 raeburn 7803: if (createnew == 1) {
1.570 raeburn 7804: for (var i=0; i<callingForm.srchby.length; i++) {
7805: if (callingForm.srchby.options[i].value == 'uname') {
7806: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7807: }
7808: }
1.570 raeburn 7809: for (var i=0; i<callingForm.srchin.length; i++) {
7810: if ( callingForm.srchin.options[i].value == 'dom') {
7811: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7812: }
7813: }
1.570 raeburn 7814: for (var i=0; i<callingForm.srchtype.length; i++) {
7815: if (callingForm.srchtype.options[i].value == 'exact') {
7816: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7817: }
7818: }
1.570 raeburn 7819: for (var i=0; i<callingForm.srchdomain.length; i++) {
7820: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7821: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7822: }
7823: }
7824: }
7825: }
7826: ENDSCRIPT
1.558 albertel 7827:
1.556 raeburn 7828: }
7829:
1.555 raeburn 7830: my $output = <<"END_BLOCK";
1.556 raeburn 7831: <script type="text/javascript">
1.824 bisitz 7832: // <![CDATA[
1.570 raeburn 7833: function validateEntry(callingForm) {
1.558 albertel 7834:
1.556 raeburn 7835: var checkok = 1;
1.558 albertel 7836: var srchin;
1.570 raeburn 7837: for (var i=0; i<callingForm.srchin.length; i++) {
7838: if ( callingForm.srchin[i].checked ) {
7839: srchin = callingForm.srchin[i].value;
1.558 albertel 7840: }
7841: }
7842:
1.570 raeburn 7843: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7844: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7845: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7846: var srchterm = callingForm.srchterm.value;
7847: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7848: var msg = "";
7849:
7850: if (srchterm == "") {
7851: checkok = 0;
1.571 raeburn 7852: msg += "$lt{'youm'}\\n";
1.556 raeburn 7853: }
7854:
1.569 raeburn 7855: if (srchtype== 'begins') {
7856: if (srchterm.length < 2) {
7857: checkok = 0;
1.571 raeburn 7858: msg += "$lt{'thte'}\\n";
1.569 raeburn 7859: }
7860: }
7861:
1.556 raeburn 7862: if (srchtype== 'contains') {
7863: if (srchterm.length < 3) {
7864: checkok = 0;
1.571 raeburn 7865: msg += "$lt{'thet'}\\n";
1.556 raeburn 7866: }
7867: }
7868: if (srchin == 'instd') {
7869: if (srchdomain == '') {
7870: checkok = 0;
1.571 raeburn 7871: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7872: }
7873: }
7874: if (srchin == 'dom') {
7875: if (srchdomain == '') {
7876: checkok = 0;
1.571 raeburn 7877: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7878: }
7879: }
7880: if (srchby == 'lastfirst') {
7881: if (srchterm.indexOf(",") == -1) {
7882: checkok = 0;
1.571 raeburn 7883: msg += "$lt{'whus'}\\n";
1.556 raeburn 7884: }
7885: if (srchterm.indexOf(",") == srchterm.length -1) {
7886: checkok = 0;
1.571 raeburn 7887: msg += "$lt{'whse'}\\n";
1.556 raeburn 7888: }
7889: }
7890: if (checkok == 0) {
1.571 raeburn 7891: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7892: return;
7893: }
7894: if (checkok == 1) {
1.570 raeburn 7895: callingForm.submit();
1.556 raeburn 7896: }
7897: }
7898:
7899: $newuserscript
7900:
1.824 bisitz 7901: // ]]>
1.556 raeburn 7902: </script>
1.558 albertel 7903:
7904: $new_user_create
7905:
1.555 raeburn 7906: END_BLOCK
1.558 albertel 7907:
1.876 raeburn 7908: $output .= &Apache::lonhtmlcommon::start_pick_box().
7909: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7910: $domform.
7911: &Apache::lonhtmlcommon::row_closure().
7912: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7913: $srchbysel.
7914: $srchtypesel.
7915: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7916: $srchinsel.
7917: &Apache::lonhtmlcommon::row_closure(1).
7918: &Apache::lonhtmlcommon::end_pick_box().
7919: '<br />';
1.555 raeburn 7920: return $output;
7921: }
7922:
1.612 raeburn 7923: sub user_rule_check {
1.615 raeburn 7924: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7925: my $response;
7926: if (ref($usershash) eq 'HASH') {
7927: foreach my $user (keys(%{$usershash})) {
7928: my ($uname,$udom) = split(/:/,$user);
7929: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7930: my ($id,$newuser);
1.612 raeburn 7931: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7932: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7933: $id = $usershash->{$user}->{'id'};
7934: }
7935: my $inst_response;
7936: if (ref($checks) eq 'HASH') {
7937: if (defined($checks->{'username'})) {
1.615 raeburn 7938: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7939: &Apache::lonnet::get_instuser($udom,$uname);
7940: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7941: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7942: &Apache::lonnet::get_instuser($udom,undef,$id);
7943: }
1.615 raeburn 7944: } else {
7945: ($inst_response,%{$inst_results->{$user}}) =
7946: &Apache::lonnet::get_instuser($udom,$uname);
7947: return;
1.612 raeburn 7948: }
1.615 raeburn 7949: if (!$got_rules->{$udom}) {
1.612 raeburn 7950: my %domconfig = &Apache::lonnet::get_dom('configuration',
7951: ['usercreation'],$udom);
7952: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7953: foreach my $item ('username','id') {
1.612 raeburn 7954: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7955: $$curr_rules{$udom}{$item} =
7956: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7957: }
7958: }
7959: }
1.615 raeburn 7960: $got_rules->{$udom} = 1;
1.585 raeburn 7961: }
1.612 raeburn 7962: foreach my $item (keys(%{$checks})) {
7963: if (ref($$curr_rules{$udom}) eq 'HASH') {
7964: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7965: if (@{$$curr_rules{$udom}{$item}} > 0) {
7966: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7967: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7968: if ($rule_check{$rule}) {
7969: $$rulematch{$user}{$item} = $rule;
7970: if ($inst_response eq 'ok') {
1.615 raeburn 7971: if (ref($inst_results) eq 'HASH') {
7972: if (ref($inst_results->{$user}) eq 'HASH') {
7973: if (keys(%{$inst_results->{$user}}) == 0) {
7974: $$alerts{$item}{$udom}{$uname} = 1;
7975: }
1.612 raeburn 7976: }
7977: }
1.615 raeburn 7978: }
7979: last;
1.585 raeburn 7980: }
7981: }
7982: }
7983: }
7984: }
7985: }
7986: }
7987: }
1.612 raeburn 7988: return;
7989: }
7990:
7991: sub user_rule_formats {
7992: my ($domain,$domdesc,$curr_rules,$check) = @_;
7993: my %text = (
7994: 'username' => 'Usernames',
7995: 'id' => 'IDs',
7996: );
7997: my $output;
7998: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7999: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8000: if (@{$ruleorder} > 0) {
8001: $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>';
8002: foreach my $rule (@{$ruleorder}) {
8003: if (ref($curr_rules) eq 'ARRAY') {
8004: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
8005: if (ref($rules->{$rule}) eq 'HASH') {
8006: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
8007: $rules->{$rule}{'desc'}.'</li>';
8008: }
8009: }
8010: }
8011: }
8012: $output .= '</ul>';
8013: }
8014: }
8015: return $output;
8016: }
8017:
8018: sub instrule_disallow_msg {
1.615 raeburn 8019: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 8020: my $response;
8021: my %text = (
8022: item => 'username',
8023: items => 'usernames',
8024: match => 'matches',
8025: do => 'does',
8026: action => 'a username',
8027: one => 'one',
8028: );
8029: if ($count > 1) {
8030: $text{'item'} = 'usernames';
8031: $text{'match'} ='match';
8032: $text{'do'} = 'do';
8033: $text{'action'} = 'usernames',
8034: $text{'one'} = 'ones';
8035: }
8036: if ($checkitem eq 'id') {
8037: $text{'items'} = 'IDs';
8038: $text{'item'} = 'ID';
8039: $text{'action'} = 'an ID';
1.615 raeburn 8040: if ($count > 1) {
8041: $text{'item'} = 'IDs';
8042: $text{'action'} = 'IDs';
8043: }
1.612 raeburn 8044: }
1.674 bisitz 8045: $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 8046: if ($mode eq 'upload') {
8047: if ($checkitem eq 'username') {
8048: $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'}.");
8049: } elsif ($checkitem eq 'id') {
1.674 bisitz 8050: $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 8051: }
1.669 raeburn 8052: } elsif ($mode eq 'selfcreate') {
8053: if ($checkitem eq 'id') {
8054: $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.");
8055: }
1.615 raeburn 8056: } else {
8057: if ($checkitem eq 'username') {
8058: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8059: } elsif ($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.612 raeburn 8062: }
8063: return $response;
1.585 raeburn 8064: }
8065:
1.624 raeburn 8066: sub personal_data_fieldtitles {
8067: my %fieldtitles = &Apache::lonlocal::texthash (
8068: id => 'Student/Employee ID',
8069: permanentemail => 'E-mail address',
8070: lastname => 'Last Name',
8071: firstname => 'First Name',
8072: middlename => 'Middle Name',
8073: generation => 'Generation',
8074: gen => 'Generation',
1.765 raeburn 8075: inststatus => 'Affiliation',
1.624 raeburn 8076: );
8077: return %fieldtitles;
8078: }
8079:
1.642 raeburn 8080: sub sorted_inst_types {
8081: my ($dom) = @_;
8082: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8083: my $othertitle = &mt('All users');
8084: if ($env{'request.course.id'}) {
1.668 raeburn 8085: $othertitle = &mt('Any users');
1.642 raeburn 8086: }
8087: my @types;
8088: if (ref($order) eq 'ARRAY') {
8089: @types = @{$order};
8090: }
8091: if (@types == 0) {
8092: if (ref($usertypes) eq 'HASH') {
8093: @types = sort(keys(%{$usertypes}));
8094: }
8095: }
8096: if (keys(%{$usertypes}) > 0) {
8097: $othertitle = &mt('Other users');
8098: }
8099: return ($othertitle,$usertypes,\@types);
8100: }
8101:
1.645 raeburn 8102: sub get_institutional_codes {
8103: my ($settings,$allcourses,$LC_code) = @_;
8104: # Get complete list of course sections to update
8105: my @currsections = ();
8106: my @currxlists = ();
8107: my $coursecode = $$settings{'internal.coursecode'};
8108:
8109: if ($$settings{'internal.sectionnums'} ne '') {
8110: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8111: }
8112:
8113: if ($$settings{'internal.crosslistings'} ne '') {
8114: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8115: }
8116:
8117: if (@currxlists > 0) {
8118: foreach (@currxlists) {
8119: if (m/^([^:]+):(\w*)$/) {
8120: unless (grep/^$1$/,@{$allcourses}) {
8121: push @{$allcourses},$1;
8122: $$LC_code{$1} = $2;
8123: }
8124: }
8125: }
8126: }
8127:
8128: if (@currsections > 0) {
8129: foreach (@currsections) {
8130: if (m/^(\w+):(\w*)$/) {
8131: my $sec = $coursecode.$1;
8132: my $lc_sec = $2;
8133: unless (grep/^$sec$/,@{$allcourses}) {
8134: push @{$allcourses},$sec;
8135: $$LC_code{$sec} = $lc_sec;
8136: }
8137: }
8138: }
8139: }
8140: return;
8141: }
8142:
1.112 bowersj2 8143: =pod
8144:
1.780 raeburn 8145: =head1 Slot Helpers
8146:
8147: =over 4
8148:
8149: =item * sorted_slots()
8150:
8151: Sorts an array of slot names in order of slot start time (earliest first).
8152:
8153: Inputs:
8154:
8155: =over 4
8156:
8157: slotsarr - Reference to array of unsorted slot names.
8158:
8159: slots - Reference to hash of hash, where outer hash keys are slot names.
8160:
1.549 albertel 8161: =back
8162:
1.780 raeburn 8163: Returns:
8164:
8165: =over 4
8166:
8167: sorted - An array of slot names sorted by the start time of the slot.
8168:
8169: =back
8170:
8171: =back
8172:
8173: =cut
8174:
8175:
8176: sub sorted_slots {
8177: my ($slotsarr,$slots) = @_;
8178: my @sorted;
8179: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8180: @sorted =
8181: sort {
8182: if (ref($slots->{$a}) && ref($slots->{$b})) {
8183: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8184: }
8185: if (ref($slots->{$a})) { return -1;}
8186: if (ref($slots->{$b})) { return 1;}
8187: return 0;
8188: } @{$slotsarr};
8189: }
8190: return @sorted;
8191: }
8192:
8193:
8194: =pod
8195:
1.549 albertel 8196: =head1 HTTP Helpers
8197:
8198: =over 4
8199:
1.648 raeburn 8200: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8201:
1.258 albertel 8202: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8203: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8204: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8205:
8206: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8207: $possible_names is an ref to an array of form element names. As an example:
8208: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8209: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8210:
8211: =cut
1.1 albertel 8212:
1.6 albertel 8213: sub get_unprocessed_cgi {
1.25 albertel 8214: my ($query,$possible_names)= @_;
1.26 matthew 8215: # $Apache::lonxml::debug=1;
1.356 albertel 8216: foreach my $pair (split(/&/,$query)) {
8217: my ($name, $value) = split(/=/,$pair);
1.369 www 8218: $name = &unescape($name);
1.25 albertel 8219: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8220: $value =~ tr/+/ /;
8221: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8222: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8223: }
1.16 harris41 8224: }
1.6 albertel 8225: }
8226:
1.112 bowersj2 8227: =pod
8228:
1.648 raeburn 8229: =item * &cacheheader()
1.112 bowersj2 8230:
8231: returns cache-controlling header code
8232:
8233: =cut
8234:
1.7 albertel 8235: sub cacheheader {
1.258 albertel 8236: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8237: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8238: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8239: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8240: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8241: return $output;
1.7 albertel 8242: }
8243:
1.112 bowersj2 8244: =pod
8245:
1.648 raeburn 8246: =item * &no_cache($r)
1.112 bowersj2 8247:
8248: specifies header code to not have cache
8249:
8250: =cut
8251:
1.9 albertel 8252: sub no_cache {
1.216 albertel 8253: my ($r) = @_;
8254: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8255: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8256: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8257: $r->no_cache(1);
8258: $r->header_out("Expires" => $date);
8259: $r->header_out("Pragma" => "no-cache");
1.123 www 8260: }
8261:
8262: sub content_type {
1.181 albertel 8263: my ($r,$type,$charset) = @_;
1.299 foxr 8264: if ($r) {
8265: # Note that printout.pl calls this with undef for $r.
8266: &no_cache($r);
8267: }
1.258 albertel 8268: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8269: unless ($charset) {
8270: $charset=&Apache::lonlocal::current_encoding;
8271: }
8272: if ($charset) { $type.='; charset='.$charset; }
8273: if ($r) {
8274: $r->content_type($type);
8275: } else {
8276: print("Content-type: $type\n\n");
8277: }
1.9 albertel 8278: }
1.25 albertel 8279:
1.112 bowersj2 8280: =pod
8281:
1.648 raeburn 8282: =item * &add_to_env($name,$value)
1.112 bowersj2 8283:
1.258 albertel 8284: adds $name to the %env hash with value
1.112 bowersj2 8285: $value, if $name already exists, the entry is converted to an array
8286: reference and $value is added to the array.
8287:
8288: =cut
8289:
1.25 albertel 8290: sub add_to_env {
8291: my ($name,$value)=@_;
1.258 albertel 8292: if (defined($env{$name})) {
8293: if (ref($env{$name})) {
1.25 albertel 8294: #already have multiple values
1.258 albertel 8295: push(@{ $env{$name} },$value);
1.25 albertel 8296: } else {
8297: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8298: my $first=$env{$name};
8299: undef($env{$name});
8300: push(@{ $env{$name} },$first,$value);
1.25 albertel 8301: }
8302: } else {
1.258 albertel 8303: $env{$name}=$value;
1.25 albertel 8304: }
1.31 albertel 8305: }
1.149 albertel 8306:
8307: =pod
8308:
1.648 raeburn 8309: =item * &get_env_multiple($name)
1.149 albertel 8310:
1.258 albertel 8311: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8312: values may be defined and end up as an array ref.
8313:
8314: returns an array of values
8315:
8316: =cut
8317:
8318: sub get_env_multiple {
8319: my ($name) = @_;
8320: my @values;
1.258 albertel 8321: if (defined($env{$name})) {
1.149 albertel 8322: # exists is it an array
1.258 albertel 8323: if (ref($env{$name})) {
8324: @values=@{ $env{$name} };
1.149 albertel 8325: } else {
1.258 albertel 8326: $values[0]=$env{$name};
1.149 albertel 8327: }
8328: }
8329: return(@values);
8330: }
8331:
1.660 raeburn 8332: sub ask_for_embedded_content {
8333: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8334: my $upload_output = '
8335: <form name="upload_embedded" action="'.$actionurl.'"
8336: method="post" enctype="multipart/form-data">';
8337: $upload_output .= $state;
1.661 raeburn 8338: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8339:
8340: my $num = 0;
8341: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8342: $upload_output .= &start_data_table_row().
8343: '<td>'.$embed_file.'</td><td>';
8344: if ($args->{'ignore_remote_references'}
8345: && $embed_file =~ m{^\w+://}) {
8346: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8347: } elsif ($args->{'error_on_invalid_names'}
8348: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8349:
8350: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8351:
8352: } else {
8353: $upload_output .='
1.661 raeburn 8354: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8355: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8356: my $attrib = join(':',@{$$allfiles{$embed_file}});
8357: $upload_output .=
8358: "\n\t\t".
8359: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8360: $attrib.'" />';
8361: if (exists($$codebase{$embed_file})) {
8362: $upload_output .=
8363: "\n\t\t".
8364: '<input name="codebase_'.$num.'" type="hidden" value="'.
8365: &escape($$codebase{$embed_file}).'" />';
8366: }
8367: }
8368: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8369: $num++;
8370: }
8371: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8372: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8373: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8374: '.&mt('(only files for which a location has been provided will be uploaded)').'
8375: </form>';
8376: return $upload_output;
8377: }
8378:
1.661 raeburn 8379: sub upload_embedded {
8380: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8381: $current_disk_usage) = @_;
8382: my $output;
8383: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8384: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8385: my $orig_uploaded_filename =
8386: $env{'form.embedded_item_'.$i.'.filename'};
8387:
8388: $env{'form.embedded_orig_'.$i} =
8389: &unescape($env{'form.embedded_orig_'.$i});
8390: my ($path,$fname) =
8391: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8392: # no path, whole string is fname
8393: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8394:
8395: $path = $env{'form.currentpath'}.$path;
8396: $fname = &Apache::lonnet::clean_filename($fname);
8397: # See if there is anything left
8398: next if ($fname eq '');
8399:
8400: # Check if file already exists as a file or directory.
8401: my ($state,$msg);
8402: if ($context eq 'portfolio') {
8403: my $port_path = $dirpath;
8404: if ($group ne '') {
8405: $port_path = "groups/$group/$port_path";
8406: }
8407: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8408: $dir_root,$port_path,$disk_quota,
8409: $current_disk_usage,$uname,$udom);
8410: if ($state eq 'will_exceed_quota'
8411: || $state eq 'file_locked'
8412: || $state eq 'file_exists' ) {
8413: $output .= $msg;
8414: next;
8415: }
8416: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8417: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8418: if ($state eq 'exists') {
8419: $output .= $msg;
8420: next;
8421: }
8422: }
8423: # Check if extension is valid
8424: if (($fname =~ /\.(\w+)$/) &&
8425: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8426: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8427: next;
8428: } elsif (($fname =~ /\.(\w+)$/) &&
8429: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8430: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8431: next;
8432: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8433: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8434: next;
8435: }
8436:
8437: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8438: if ($context eq 'portfolio') {
8439: my $result=
8440: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8441: $dirpath.$path);
8442: if ($result !~ m|^/uploaded/|) {
8443: $output .= '<span class="LC_error">'
8444: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8445: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8446: .'</span><br />';
8447: next;
8448: } else {
8449: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8450: $path.$fname.'</span>').'</p>';
8451: }
8452: } else {
8453: # Save the file
8454: my $target = $env{'form.embedded_item_'.$i};
8455: my $fullpath = $dir_root.$dirpath.'/'.$path;
8456: my $dest = $fullpath.$fname;
8457: my $url = $url_root.$dirpath.'/'.$path.$fname;
8458: my @parts=split(/\//,$fullpath);
8459: my $count;
8460: my $filepath = $dir_root;
8461: for ($count=4;$count<=$#parts;$count++) {
8462: $filepath .= "/$parts[$count]";
8463: if ((-e $filepath)!=1) {
8464: mkdir($filepath,0770);
8465: }
8466: }
8467: my $fh;
8468: if (!open($fh,'>'.$dest)) {
8469: &Apache::lonnet::logthis('Failed to create '.$dest);
8470: $output .= '<span class="LC_error">'.
8471: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8472: '</span><br />';
8473: } else {
8474: if (!print $fh $env{'form.embedded_item_'.$i}) {
8475: &Apache::lonnet::logthis('Failed to write to '.$dest);
8476: $output .= '<span class="LC_error">'.
8477: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8478: '</span><br />';
8479: } else {
8480: if ($context eq 'testbank') {
8481: $output .= &mt('Embedded file uploaded successfully:').
8482: ' <a href="'.$url.'">'.
8483: $orig_uploaded_filename.'</a><br />';
8484: } else {
1.705 tempelho 8485: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8486: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8487: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8488: }
8489: }
8490: close($fh);
8491: }
8492: }
8493: }
8494: return $output;
8495: }
8496:
8497: sub check_for_existing {
8498: my ($path,$fname,$element) = @_;
8499: my ($state,$msg);
8500: if (-d $path.'/'.$fname) {
8501: $state = 'exists';
8502: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8503: } elsif (-e $path.'/'.$fname) {
8504: $state = 'exists';
8505: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8506: }
8507: if ($state eq 'exists') {
8508: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8509: }
8510: return ($state,$msg);
8511: }
8512:
8513: sub check_for_upload {
8514: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8515: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8516: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8517: my $getpropath = 1;
8518: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8519: $getpropath);
8520: my $found_file = 0;
8521: my $locked_file = 0;
8522: foreach my $line (@dir_list) {
8523: my ($file_name)=split(/\&/,$line,2);
8524: if ($file_name eq $fname){
8525: $file_name = $path.$file_name;
8526: if ($group ne '') {
8527: $file_name = $group.$file_name;
8528: }
8529: $found_file = 1;
8530: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8531: $locked_file = 1;
8532: }
8533: }
8534: }
8535: if (($current_disk_usage + $filesize) > $disk_quota){
8536: my $msg = '<span class="LC_error">'.
8537: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8538: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8539: return ('will_exceed_quota',$msg);
8540: } elsif ($found_file) {
8541: if ($locked_file) {
8542: my $msg = '<span class="LC_error">';
8543: $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>');
8544: $msg .= '</span><br />';
8545: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8546: return ('file_locked',$msg);
8547: } else {
8548: my $msg = '<span class="LC_error">';
8549: $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'});
8550: $msg .= '</span>';
8551: $msg .= '<br />';
8552: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8553: return ('file_exists',$msg);
8554: }
8555: }
8556: }
8557:
1.31 albertel 8558:
1.41 ng 8559: =pod
1.45 matthew 8560:
1.464 albertel 8561: =back
1.41 ng 8562:
1.112 bowersj2 8563: =head1 CSV Upload/Handling functions
1.38 albertel 8564:
1.41 ng 8565: =over 4
8566:
1.648 raeburn 8567: =item * &upfile_store($r)
1.41 ng 8568:
8569: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8570: needs $env{'form.upfile'}
1.41 ng 8571: returns $datatoken to be put into hidden field
8572:
8573: =cut
1.31 albertel 8574:
8575: sub upfile_store {
8576: my $r=shift;
1.258 albertel 8577: $env{'form.upfile'}=~s/\r/\n/gs;
8578: $env{'form.upfile'}=~s/\f/\n/gs;
8579: $env{'form.upfile'}=~s/\n+/\n/gs;
8580: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8581:
1.258 albertel 8582: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8583: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8584: {
1.158 raeburn 8585: my $datafile = $r->dir_config('lonDaemons').
8586: '/tmp/'.$datatoken.'.tmp';
8587: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8588: print $fh $env{'form.upfile'};
1.158 raeburn 8589: close($fh);
8590: }
1.31 albertel 8591: }
8592: return $datatoken;
8593: }
8594:
1.56 matthew 8595: =pod
8596:
1.648 raeburn 8597: =item * &load_tmp_file($r)
1.41 ng 8598:
8599: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8600: needs $env{'form.datatoken'},
8601: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8602:
8603: =cut
1.31 albertel 8604:
8605: sub load_tmp_file {
8606: my $r=shift;
8607: my @studentdata=();
8608: {
1.158 raeburn 8609: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8610: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8611: if ( open(my $fh,"<$studentfile") ) {
8612: @studentdata=<$fh>;
8613: close($fh);
8614: }
1.31 albertel 8615: }
1.258 albertel 8616: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8617: }
8618:
1.56 matthew 8619: =pod
8620:
1.648 raeburn 8621: =item * &upfile_record_sep()
1.41 ng 8622:
8623: Separate uploaded file into records
8624: returns array of records,
1.258 albertel 8625: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8626:
8627: =cut
1.31 albertel 8628:
8629: sub upfile_record_sep {
1.258 albertel 8630: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8631: } else {
1.248 albertel 8632: my @records;
1.258 albertel 8633: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8634: if ($line=~/^\s*$/) { next; }
8635: push(@records,$line);
8636: }
8637: return @records;
1.31 albertel 8638: }
8639: }
8640:
1.56 matthew 8641: =pod
8642:
1.648 raeburn 8643: =item * &record_sep($record)
1.41 ng 8644:
1.258 albertel 8645: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8646:
8647: =cut
8648:
1.263 www 8649: sub takeleft {
8650: my $index=shift;
8651: return substr('0000'.$index,-4,4);
8652: }
8653:
1.31 albertel 8654: sub record_sep {
8655: my $record=shift;
8656: my %components=();
1.258 albertel 8657: if ($env{'form.upfiletype'} eq 'xml') {
8658: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8659: my $i=0;
1.356 albertel 8660: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8661: $field=~s/^(\"|\')//;
8662: $field=~s/(\"|\')$//;
1.263 www 8663: $components{&takeleft($i)}=$field;
1.31 albertel 8664: $i++;
8665: }
1.258 albertel 8666: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8667: my $i=0;
1.356 albertel 8668: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8669: $field=~s/^(\"|\')//;
8670: $field=~s/(\"|\')$//;
1.263 www 8671: $components{&takeleft($i)}=$field;
1.31 albertel 8672: $i++;
8673: }
8674: } else {
1.561 www 8675: my $separator=',';
1.480 banghart 8676: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8677: $separator=';';
1.480 banghart 8678: }
1.31 albertel 8679: my $i=0;
1.561 www 8680: # the character we are looking for to indicate the end of a quote or a record
8681: my $looking_for=$separator;
8682: # do not add the characters to the fields
8683: my $ignore=0;
8684: # we just encountered a separator (or the beginning of the record)
8685: my $just_found_separator=1;
8686: # store the field we are working on here
8687: my $field='';
8688: # work our way through all characters in record
8689: foreach my $character ($record=~/(.)/g) {
8690: if ($character eq $looking_for) {
8691: if ($character ne $separator) {
8692: # Found the end of a quote, again looking for separator
8693: $looking_for=$separator;
8694: $ignore=1;
8695: } else {
8696: # Found a separator, store away what we got
8697: $components{&takeleft($i)}=$field;
8698: $i++;
8699: $just_found_separator=1;
8700: $ignore=0;
8701: $field='';
8702: }
8703: next;
8704: }
8705: # single or double quotation marks after a separator indicate beginning of a quote
8706: # we are now looking for the end of the quote and need to ignore separators
8707: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8708: $looking_for=$character;
8709: next;
8710: }
8711: # ignore would be true after we reached the end of a quote
8712: if ($ignore) { next; }
8713: if (($just_found_separator) && ($character=~/\s/)) { next; }
8714: $field.=$character;
8715: $just_found_separator=0;
1.31 albertel 8716: }
1.561 www 8717: # catch the very last entry, since we never encountered the separator
8718: $components{&takeleft($i)}=$field;
1.31 albertel 8719: }
8720: return %components;
8721: }
8722:
1.144 matthew 8723: ######################################################
8724: ######################################################
8725:
1.56 matthew 8726: =pod
8727:
1.648 raeburn 8728: =item * &upfile_select_html()
1.41 ng 8729:
1.144 matthew 8730: Return HTML code to select a file from the users machine and specify
8731: the file type.
1.41 ng 8732:
8733: =cut
8734:
1.144 matthew 8735: ######################################################
8736: ######################################################
1.31 albertel 8737: sub upfile_select_html {
1.144 matthew 8738: my %Types = (
8739: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8740: semisv => &mt('Semicolon separated values'),
1.144 matthew 8741: space => &mt('Space separated'),
8742: tab => &mt('Tabulator separated'),
8743: # xml => &mt('HTML/XML'),
8744: );
8745: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8746: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8747: foreach my $type (sort(keys(%Types))) {
8748: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8749: }
8750: $Str .= "</select>\n";
8751: return $Str;
1.31 albertel 8752: }
8753:
1.301 albertel 8754: sub get_samples {
8755: my ($records,$toget) = @_;
8756: my @samples=({});
8757: my $got=0;
8758: foreach my $rec (@$records) {
8759: my %temp = &record_sep($rec);
8760: if (! grep(/\S/, values(%temp))) { next; }
8761: if (%temp) {
8762: $samples[$got]=\%temp;
8763: $got++;
8764: if ($got == $toget) { last; }
8765: }
8766: }
8767: return \@samples;
8768: }
8769:
1.144 matthew 8770: ######################################################
8771: ######################################################
8772:
1.56 matthew 8773: =pod
8774:
1.648 raeburn 8775: =item * &csv_print_samples($r,$records)
1.41 ng 8776:
8777: Prints a table of sample values from each column uploaded $r is an
8778: Apache Request ref, $records is an arrayref from
8779: &Apache::loncommon::upfile_record_sep
8780:
8781: =cut
8782:
1.144 matthew 8783: ######################################################
8784: ######################################################
1.31 albertel 8785: sub csv_print_samples {
8786: my ($r,$records) = @_;
1.662 bisitz 8787: my $samples = &get_samples($records,5);
1.301 albertel 8788:
1.594 raeburn 8789: $r->print(&mt('Samples').'<br />'.&start_data_table().
8790: &start_data_table_header_row());
1.356 albertel 8791: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8792: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8793: $r->print(&end_data_table_header_row());
1.301 albertel 8794: foreach my $hash (@$samples) {
1.594 raeburn 8795: $r->print(&start_data_table_row());
1.356 albertel 8796: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8797: $r->print('<td>');
1.356 albertel 8798: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8799: $r->print('</td>');
8800: }
1.594 raeburn 8801: $r->print(&end_data_table_row());
1.31 albertel 8802: }
1.594 raeburn 8803: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8804: }
8805:
1.144 matthew 8806: ######################################################
8807: ######################################################
8808:
1.56 matthew 8809: =pod
8810:
1.648 raeburn 8811: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8812:
8813: Prints a table to create associations between values and table columns.
1.144 matthew 8814:
1.41 ng 8815: $r is an Apache Request ref,
8816: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8817: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8818:
8819: =cut
8820:
1.144 matthew 8821: ######################################################
8822: ######################################################
1.31 albertel 8823: sub csv_print_select_table {
8824: my ($r,$records,$d) = @_;
1.301 albertel 8825: my $i=0;
8826: my $samples = &get_samples($records,1);
1.144 matthew 8827: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8828: &start_data_table().&start_data_table_header_row().
1.144 matthew 8829: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8830: '<th>'.&mt('Column').'</th>'.
8831: &end_data_table_header_row()."\n");
1.356 albertel 8832: foreach my $array_ref (@$d) {
8833: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8834: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8835:
1.875 bisitz 8836: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8837: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8838: $r->print('<option value="none"></option>');
1.356 albertel 8839: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8840: $r->print('<option value="'.$sample.'"'.
8841: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8842: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8843: }
1.594 raeburn 8844: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8845: $i++;
8846: }
1.594 raeburn 8847: $r->print(&end_data_table());
1.31 albertel 8848: $i--;
8849: return $i;
8850: }
1.56 matthew 8851:
1.144 matthew 8852: ######################################################
8853: ######################################################
8854:
1.56 matthew 8855: =pod
1.31 albertel 8856:
1.648 raeburn 8857: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8858:
8859: Prints a table of sample values from the upload and can make associate samples to internal names.
8860:
8861: $r is an Apache Request ref,
8862: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8863: $d is an array of 2 element arrays (internal name, displayed name)
8864:
8865: =cut
8866:
1.144 matthew 8867: ######################################################
8868: ######################################################
1.31 albertel 8869: sub csv_samples_select_table {
8870: my ($r,$records,$d) = @_;
8871: my $i=0;
1.144 matthew 8872: #
1.662 bisitz 8873: my $max_samples = 5;
8874: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8875: $r->print(&start_data_table().
8876: &start_data_table_header_row().'<th>'.
8877: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8878: &end_data_table_header_row());
1.301 albertel 8879:
8880: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8881: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8882: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8883: foreach my $option (@$d) {
8884: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8885: $r->print('<option value="'.$value.'"'.
1.253 albertel 8886: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8887: $display.'</option>');
1.31 albertel 8888: }
8889: $r->print('</select></td><td>');
1.662 bisitz 8890: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8891: if (defined($samples->[$line]{$key})) {
8892: $r->print($samples->[$line]{$key}."<br />\n");
8893: }
8894: }
1.594 raeburn 8895: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8896: $i++;
8897: }
1.594 raeburn 8898: $r->print(&end_data_table());
1.31 albertel 8899: $i--;
8900: return($i);
1.115 matthew 8901: }
8902:
1.144 matthew 8903: ######################################################
8904: ######################################################
8905:
1.115 matthew 8906: =pod
8907:
1.648 raeburn 8908: =item * &clean_excel_name($name)
1.115 matthew 8909:
8910: Returns a replacement for $name which does not contain any illegal characters.
8911:
8912: =cut
8913:
1.144 matthew 8914: ######################################################
8915: ######################################################
1.115 matthew 8916: sub clean_excel_name {
8917: my ($name) = @_;
8918: $name =~ s/[:\*\?\/\\]//g;
8919: if (length($name) > 31) {
8920: $name = substr($name,0,31);
8921: }
8922: return $name;
1.25 albertel 8923: }
1.84 albertel 8924:
1.85 albertel 8925: =pod
8926:
1.648 raeburn 8927: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8928:
8929: Returns either 1 or undef
8930:
8931: 1 if the part is to be hidden, undef if it is to be shown
8932:
8933: Arguments are:
8934:
8935: $id the id of the part to be checked
8936: $symb, optional the symb of the resource to check
8937: $udom, optional the domain of the user to check for
8938: $uname, optional the username of the user to check for
8939:
8940: =cut
1.84 albertel 8941:
8942: sub check_if_partid_hidden {
8943: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8944: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8945: $symb,$udom,$uname);
1.141 albertel 8946: my $truth=1;
8947: #if the string starts with !, then the list is the list to show not hide
8948: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8949: my @hiddenlist=split(/,/,$hiddenparts);
8950: foreach my $checkid (@hiddenlist) {
1.141 albertel 8951: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8952: }
1.141 albertel 8953: return !$truth;
1.84 albertel 8954: }
1.127 matthew 8955:
1.138 matthew 8956:
8957: ############################################################
8958: ############################################################
8959:
8960: =pod
8961:
1.157 matthew 8962: =back
8963:
1.138 matthew 8964: =head1 cgi-bin script and graphing routines
8965:
1.157 matthew 8966: =over 4
8967:
1.648 raeburn 8968: =item * &get_cgi_id()
1.138 matthew 8969:
8970: Inputs: none
8971:
8972: Returns an id which can be used to pass environment variables
8973: to various cgi-bin scripts. These environment variables will
8974: be removed from the users environment after a given time by
8975: the routine &Apache::lonnet::transfer_profile_to_env.
8976:
8977: =cut
8978:
8979: ############################################################
8980: ############################################################
1.152 albertel 8981: my $uniq=0;
1.136 matthew 8982: sub get_cgi_id {
1.154 albertel 8983: $uniq=($uniq+1)%100000;
1.280 albertel 8984: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8985: }
8986:
1.127 matthew 8987: ############################################################
8988: ############################################################
8989:
8990: =pod
8991:
1.648 raeburn 8992: =item * &DrawBarGraph()
1.127 matthew 8993:
1.138 matthew 8994: Facilitates the plotting of data in a (stacked) bar graph.
8995: Puts plot definition data into the users environment in order for
8996: graph.png to plot it. Returns an <img> tag for the plot.
8997: The bars on the plot are labeled '1','2',...,'n'.
8998:
8999: Inputs:
9000:
9001: =over 4
9002:
9003: =item $Title: string, the title of the plot
9004:
9005: =item $xlabel: string, text describing the X-axis of the plot
9006:
9007: =item $ylabel: string, text describing the Y-axis of the plot
9008:
9009: =item $Max: scalar, the maximum Y value to use in the plot
9010: If $Max is < any data point, the graph will not be rendered.
9011:
1.140 matthew 9012: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9013: they are plotted. If undefined, default values will be used.
9014:
1.178 matthew 9015: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9016:
1.138 matthew 9017: =item @Values: An array of array references. Each array reference holds data
9018: to be plotted in a stacked bar chart.
9019:
1.239 matthew 9020: =item If the final element of @Values is a hash reference the key/value
9021: pairs will be added to the graph definition.
9022:
1.138 matthew 9023: =back
9024:
9025: Returns:
9026:
9027: An <img> tag which references graph.png and the appropriate identifying
9028: information for the plot.
9029:
1.127 matthew 9030: =cut
9031:
9032: ############################################################
9033: ############################################################
1.134 matthew 9034: sub DrawBarGraph {
1.178 matthew 9035: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9036: #
9037: if (! defined($colors)) {
9038: $colors = ['#33ff00',
9039: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9040: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9041: ];
9042: }
1.228 matthew 9043: my $extra_settings = {};
9044: if (ref($Values[-1]) eq 'HASH') {
9045: $extra_settings = pop(@Values);
9046: }
1.127 matthew 9047: #
1.136 matthew 9048: my $identifier = &get_cgi_id();
9049: my $id = 'cgi.'.$identifier;
1.129 matthew 9050: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9051: return '';
9052: }
1.225 matthew 9053: #
9054: my @Labels;
9055: if (defined($labels)) {
9056: @Labels = @$labels;
9057: } else {
9058: for (my $i=0;$i<@{$Values[0]};$i++) {
9059: push (@Labels,$i+1);
9060: }
9061: }
9062: #
1.129 matthew 9063: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9064: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9065: my %ValuesHash;
9066: my $NumSets=1;
9067: foreach my $array (@Values) {
9068: next if (! ref($array));
1.136 matthew 9069: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9070: join(',',@$array);
1.129 matthew 9071: }
1.127 matthew 9072: #
1.136 matthew 9073: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9074: if ($NumBars < 3) {
9075: $width = 120+$NumBars*32;
1.220 matthew 9076: $xskip = 1;
1.225 matthew 9077: $bar_width = 30;
9078: } elsif ($NumBars < 5) {
9079: $width = 120+$NumBars*20;
9080: $xskip = 1;
9081: $bar_width = 20;
1.220 matthew 9082: } elsif ($NumBars < 10) {
1.136 matthew 9083: $width = 120+$NumBars*15;
9084: $xskip = 1;
9085: $bar_width = 15;
9086: } elsif ($NumBars <= 25) {
9087: $width = 120+$NumBars*11;
9088: $xskip = 5;
9089: $bar_width = 8;
9090: } elsif ($NumBars <= 50) {
9091: $width = 120+$NumBars*8;
9092: $xskip = 5;
9093: $bar_width = 4;
9094: } else {
9095: $width = 120+$NumBars*8;
9096: $xskip = 5;
9097: $bar_width = 4;
9098: }
9099: #
1.137 matthew 9100: $Max = 1 if ($Max < 1);
9101: if ( int($Max) < $Max ) {
9102: $Max++;
9103: $Max = int($Max);
9104: }
1.127 matthew 9105: $Title = '' if (! defined($Title));
9106: $xlabel = '' if (! defined($xlabel));
9107: $ylabel = '' if (! defined($ylabel));
1.369 www 9108: $ValuesHash{$id.'.title'} = &escape($Title);
9109: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9110: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9111: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9112: $ValuesHash{$id.'.NumBars'} = $NumBars;
9113: $ValuesHash{$id.'.NumSets'} = $NumSets;
9114: $ValuesHash{$id.'.PlotType'} = 'bar';
9115: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9116: $ValuesHash{$id.'.height'} = $height;
9117: $ValuesHash{$id.'.width'} = $width;
9118: $ValuesHash{$id.'.xskip'} = $xskip;
9119: $ValuesHash{$id.'.bar_width'} = $bar_width;
9120: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9121: #
1.228 matthew 9122: # Deal with other parameters
9123: while (my ($key,$value) = each(%$extra_settings)) {
9124: $ValuesHash{$id.'.'.$key} = $value;
9125: }
9126: #
1.646 raeburn 9127: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9128: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9129: }
9130:
9131: ############################################################
9132: ############################################################
9133:
9134: =pod
9135:
1.648 raeburn 9136: =item * &DrawXYGraph()
1.137 matthew 9137:
1.138 matthew 9138: Facilitates the plotting of data in an XY graph.
9139: Puts plot definition data into the users environment in order for
9140: graph.png to plot it. Returns an <img> tag for the plot.
9141:
9142: Inputs:
9143:
9144: =over 4
9145:
9146: =item $Title: string, the title of the plot
9147:
9148: =item $xlabel: string, text describing the X-axis of the plot
9149:
9150: =item $ylabel: string, text describing the Y-axis of the plot
9151:
9152: =item $Max: scalar, the maximum Y value to use in the plot
9153: If $Max is < any data point, the graph will not be rendered.
9154:
9155: =item $colors: Array ref containing the hex color codes for the data to be
9156: plotted in. If undefined, default values will be used.
9157:
9158: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9159:
9160: =item $Ydata: Array ref containing Array refs.
1.185 www 9161: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9162:
9163: =item %Values: hash indicating or overriding any default values which are
9164: passed to graph.png.
9165: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9166:
9167: =back
9168:
9169: Returns:
9170:
9171: An <img> tag which references graph.png and the appropriate identifying
9172: information for the plot.
9173:
1.137 matthew 9174: =cut
9175:
9176: ############################################################
9177: ############################################################
9178: sub DrawXYGraph {
9179: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9180: #
9181: # Create the identifier for the graph
9182: my $identifier = &get_cgi_id();
9183: my $id = 'cgi.'.$identifier;
9184: #
9185: $Title = '' if (! defined($Title));
9186: $xlabel = '' if (! defined($xlabel));
9187: $ylabel = '' if (! defined($ylabel));
9188: my %ValuesHash =
9189: (
1.369 www 9190: $id.'.title' => &escape($Title),
9191: $id.'.xlabel' => &escape($xlabel),
9192: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9193: $id.'.y_max_value'=> $Max,
9194: $id.'.labels' => join(',',@$Xlabels),
9195: $id.'.PlotType' => 'XY',
9196: );
9197: #
9198: if (defined($colors) && ref($colors) eq 'ARRAY') {
9199: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9200: }
9201: #
9202: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9203: return '';
9204: }
9205: my $NumSets=1;
1.138 matthew 9206: foreach my $array (@{$Ydata}){
1.137 matthew 9207: next if (! ref($array));
9208: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9209: }
1.138 matthew 9210: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9211: #
9212: # Deal with other parameters
9213: while (my ($key,$value) = each(%Values)) {
9214: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9215: }
9216: #
1.646 raeburn 9217: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9218: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9219: }
9220:
9221: ############################################################
9222: ############################################################
9223:
9224: =pod
9225:
1.648 raeburn 9226: =item * &DrawXYYGraph()
1.138 matthew 9227:
9228: Facilitates the plotting of data in an XY graph with two Y axes.
9229: Puts plot definition data into the users environment in order for
9230: graph.png to plot it. Returns an <img> tag for the plot.
9231:
9232: Inputs:
9233:
9234: =over 4
9235:
9236: =item $Title: string, the title of the plot
9237:
9238: =item $xlabel: string, text describing the X-axis of the plot
9239:
9240: =item $ylabel: string, text describing the Y-axis of the plot
9241:
9242: =item $colors: Array ref containing the hex color codes for the data to be
9243: plotted in. If undefined, default values will be used.
9244:
9245: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9246:
9247: =item $Ydata1: The first data set
9248:
9249: =item $Min1: The minimum value of the left Y-axis
9250:
9251: =item $Max1: The maximum value of the left Y-axis
9252:
9253: =item $Ydata2: The second data set
9254:
9255: =item $Min2: The minimum value of the right Y-axis
9256:
9257: =item $Max2: The maximum value of the left Y-axis
9258:
9259: =item %Values: hash indicating or overriding any default values which are
9260: passed to graph.png.
9261: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9262:
9263: =back
9264:
9265: Returns:
9266:
9267: An <img> tag which references graph.png and the appropriate identifying
9268: information for the plot.
1.136 matthew 9269:
9270: =cut
9271:
9272: ############################################################
9273: ############################################################
1.137 matthew 9274: sub DrawXYYGraph {
9275: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9276: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9277: #
9278: # Create the identifier for the graph
9279: my $identifier = &get_cgi_id();
9280: my $id = 'cgi.'.$identifier;
9281: #
9282: $Title = '' if (! defined($Title));
9283: $xlabel = '' if (! defined($xlabel));
9284: $ylabel = '' if (! defined($ylabel));
9285: my %ValuesHash =
9286: (
1.369 www 9287: $id.'.title' => &escape($Title),
9288: $id.'.xlabel' => &escape($xlabel),
9289: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9290: $id.'.labels' => join(',',@$Xlabels),
9291: $id.'.PlotType' => 'XY',
9292: $id.'.NumSets' => 2,
1.137 matthew 9293: $id.'.two_axes' => 1,
9294: $id.'.y1_max_value' => $Max1,
9295: $id.'.y1_min_value' => $Min1,
9296: $id.'.y2_max_value' => $Max2,
9297: $id.'.y2_min_value' => $Min2,
1.136 matthew 9298: );
9299: #
1.137 matthew 9300: if (defined($colors) && ref($colors) eq 'ARRAY') {
9301: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9302: }
9303: #
9304: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9305: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9306: return '';
9307: }
9308: my $NumSets=1;
1.137 matthew 9309: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9310: next if (! ref($array));
9311: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9312: }
9313: #
9314: # Deal with other parameters
9315: while (my ($key,$value) = each(%Values)) {
9316: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9317: }
9318: #
1.646 raeburn 9319: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9320: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9321: }
9322:
9323: ############################################################
9324: ############################################################
9325:
9326: =pod
9327:
1.157 matthew 9328: =back
9329:
1.139 matthew 9330: =head1 Statistics helper routines?
9331:
9332: Bad place for them but what the hell.
9333:
1.157 matthew 9334: =over 4
9335:
1.648 raeburn 9336: =item * &chartlink()
1.139 matthew 9337:
9338: Returns a link to the chart for a specific student.
9339:
9340: Inputs:
9341:
9342: =over 4
9343:
9344: =item $linktext: The text of the link
9345:
9346: =item $sname: The students username
9347:
9348: =item $sdomain: The students domain
9349:
9350: =back
9351:
1.157 matthew 9352: =back
9353:
1.139 matthew 9354: =cut
9355:
9356: ############################################################
9357: ############################################################
9358: sub chartlink {
9359: my ($linktext, $sname, $sdomain) = @_;
9360: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9361: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9362: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9363: '">'.$linktext.'</a>';
1.153 matthew 9364: }
9365:
9366: #######################################################
9367: #######################################################
9368:
9369: =pod
9370:
9371: =head1 Course Environment Routines
1.157 matthew 9372:
9373: =over 4
1.153 matthew 9374:
1.648 raeburn 9375: =item * &restore_course_settings()
1.153 matthew 9376:
1.648 raeburn 9377: =item * &store_course_settings()
1.153 matthew 9378:
9379: Restores/Store indicated form parameters from the course environment.
9380: Will not overwrite existing values of the form parameters.
9381:
9382: Inputs:
9383: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9384:
9385: a hash ref describing the data to be stored. For example:
9386:
9387: %Save_Parameters = ('Status' => 'scalar',
9388: 'chartoutputmode' => 'scalar',
9389: 'chartoutputdata' => 'scalar',
9390: 'Section' => 'array',
1.373 raeburn 9391: 'Group' => 'array',
1.153 matthew 9392: 'StudentData' => 'array',
9393: 'Maps' => 'array');
9394:
9395: Returns: both routines return nothing
9396:
1.631 raeburn 9397: =back
9398:
1.153 matthew 9399: =cut
9400:
9401: #######################################################
9402: #######################################################
9403: sub store_course_settings {
1.496 albertel 9404: return &store_settings($env{'request.course.id'},@_);
9405: }
9406:
9407: sub store_settings {
1.153 matthew 9408: # save to the environment
9409: # appenv the same items, just to be safe
1.300 albertel 9410: my $udom = $env{'user.domain'};
9411: my $uname = $env{'user.name'};
1.496 albertel 9412: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9413: my %SaveHash;
9414: my %AppHash;
9415: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9416: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9417: my $envname = 'environment.'.$basename;
1.258 albertel 9418: if (exists($env{'form.'.$setting})) {
1.153 matthew 9419: # Save this value away
9420: if ($type eq 'scalar' &&
1.258 albertel 9421: (! exists($env{$envname}) ||
9422: $env{$envname} ne $env{'form.'.$setting})) {
9423: $SaveHash{$basename} = $env{'form.'.$setting};
9424: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9425: } elsif ($type eq 'array') {
9426: my $stored_form;
1.258 albertel 9427: if (ref($env{'form.'.$setting})) {
1.153 matthew 9428: $stored_form = join(',',
9429: map {
1.369 www 9430: &escape($_);
1.258 albertel 9431: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9432: } else {
9433: $stored_form =
1.369 www 9434: &escape($env{'form.'.$setting});
1.153 matthew 9435: }
9436: # Determine if the array contents are the same.
1.258 albertel 9437: if ($stored_form ne $env{$envname}) {
1.153 matthew 9438: $SaveHash{$basename} = $stored_form;
9439: $AppHash{$envname} = $stored_form;
9440: }
9441: }
9442: }
9443: }
9444: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9445: $udom,$uname);
1.153 matthew 9446: if ($put_result !~ /^(ok|delayed)/) {
9447: &Apache::lonnet::logthis('unable to save form parameters, '.
9448: 'got error:'.$put_result);
9449: }
9450: # Make sure these settings stick around in this session, too
1.646 raeburn 9451: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9452: return;
9453: }
9454:
9455: sub restore_course_settings {
1.499 albertel 9456: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9457: }
9458:
9459: sub restore_settings {
9460: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9461: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9462: next if (exists($env{'form.'.$setting}));
1.496 albertel 9463: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9464: '.'.$setting;
1.258 albertel 9465: if (exists($env{$envname})) {
1.153 matthew 9466: if ($type eq 'scalar') {
1.258 albertel 9467: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9468: } elsif ($type eq 'array') {
1.258 albertel 9469: $env{'form.'.$setting} = [
1.153 matthew 9470: map {
1.369 www 9471: &unescape($_);
1.258 albertel 9472: } split(',',$env{$envname})
1.153 matthew 9473: ];
9474: }
9475: }
9476: }
1.127 matthew 9477: }
9478:
1.618 raeburn 9479: #######################################################
9480: #######################################################
9481:
9482: =pod
9483:
9484: =head1 Domain E-mail Routines
9485:
9486: =over 4
9487:
1.648 raeburn 9488: =item * &build_recipient_list()
1.618 raeburn 9489:
1.884 raeburn 9490: Build recipient lists for five types of e-mail:
1.766 raeburn 9491: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9492: (d) Help requests, (e) Course requests needing approval, generated by
9493: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9494: loncoursequeueadmin.pm respectively.
1.618 raeburn 9495:
9496: Inputs:
1.619 raeburn 9497: defmail (scalar - email address of default recipient),
1.618 raeburn 9498: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9499: defdom (domain for which to retrieve configuration settings),
9500: origmail (scalar - email address of recipient from loncapa.conf,
9501: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9502:
1.655 raeburn 9503: Returns: comma separated list of addresses to which to send e-mail.
9504:
9505: =back
1.618 raeburn 9506:
9507: =cut
9508:
9509: ############################################################
9510: ############################################################
9511: sub build_recipient_list {
1.619 raeburn 9512: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9513: my @recipients;
9514: my $otheremails;
9515: my %domconfig =
9516: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9517: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9518: if (exists($domconfig{'contacts'}{$mailing})) {
9519: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9520: my @contacts = ('adminemail','supportemail');
9521: foreach my $item (@contacts) {
9522: if ($domconfig{'contacts'}{$mailing}{$item}) {
9523: my $addr = $domconfig{'contacts'}{$item};
9524: if (!grep(/^\Q$addr\E$/,@recipients)) {
9525: push(@recipients,$addr);
9526: }
1.619 raeburn 9527: }
1.766 raeburn 9528: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9529: }
9530: }
1.766 raeburn 9531: } elsif ($origmail ne '') {
9532: push(@recipients,$origmail);
1.618 raeburn 9533: }
1.619 raeburn 9534: } elsif ($origmail ne '') {
9535: push(@recipients,$origmail);
1.618 raeburn 9536: }
1.688 raeburn 9537: if (defined($defmail)) {
9538: if ($defmail ne '') {
9539: push(@recipients,$defmail);
9540: }
1.618 raeburn 9541: }
9542: if ($otheremails) {
1.619 raeburn 9543: my @others;
9544: if ($otheremails =~ /,/) {
9545: @others = split(/,/,$otheremails);
1.618 raeburn 9546: } else {
1.619 raeburn 9547: push(@others,$otheremails);
9548: }
9549: foreach my $addr (@others) {
9550: if (!grep(/^\Q$addr\E$/,@recipients)) {
9551: push(@recipients,$addr);
9552: }
1.618 raeburn 9553: }
9554: }
1.619 raeburn 9555: my $recipientlist = join(',',@recipients);
1.618 raeburn 9556: return $recipientlist;
9557: }
9558:
1.127 matthew 9559: ############################################################
9560: ############################################################
1.154 albertel 9561:
1.655 raeburn 9562: =pod
9563:
9564: =head1 Course Catalog Routines
9565:
9566: =over 4
9567:
9568: =item * &gather_categories()
9569:
9570: Converts category definitions - keys of categories hash stored in
9571: coursecategories in configuration.db on the primary library server in a
9572: domain - to an array. Also generates javascript and idx hash used to
9573: generate Domain Coordinator interface for editing Course Categories.
9574:
9575: Inputs:
1.663 raeburn 9576:
1.655 raeburn 9577: categories (reference to hash of category definitions).
1.663 raeburn 9578:
1.655 raeburn 9579: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9580: categories and subcategories).
1.663 raeburn 9581:
1.655 raeburn 9582: idx (reference to hash of counters used in Domain Coordinator interface for
9583: editing Course Categories).
1.663 raeburn 9584:
1.655 raeburn 9585: jsarray (reference to array of categories used to create Javascript arrays for
9586: Domain Coordinator interface for editing Course Categories).
9587:
9588: Returns: nothing
9589:
9590: Side effects: populates cats, idx and jsarray.
9591:
9592: =cut
9593:
9594: sub gather_categories {
9595: my ($categories,$cats,$idx,$jsarray) = @_;
9596: my %counters;
9597: my $num = 0;
9598: foreach my $item (keys(%{$categories})) {
9599: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9600: if ($container eq '' && $depth == 0) {
9601: $cats->[$depth][$categories->{$item}] = $cat;
9602: } else {
9603: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9604: }
9605: my ($escitem,$tail) = split(/:/,$item,2);
9606: if ($counters{$tail} eq '') {
9607: $counters{$tail} = $num;
9608: $num ++;
9609: }
9610: if (ref($idx) eq 'HASH') {
9611: $idx->{$item} = $counters{$tail};
9612: }
9613: if (ref($jsarray) eq 'ARRAY') {
9614: push(@{$jsarray->[$counters{$tail}]},$item);
9615: }
9616: }
9617: return;
9618: }
9619:
9620: =pod
9621:
9622: =item * &extract_categories()
9623:
9624: Used to generate breadcrumb trails for course categories.
9625:
9626: Inputs:
1.663 raeburn 9627:
1.655 raeburn 9628: categories (reference to hash of category definitions).
1.663 raeburn 9629:
1.655 raeburn 9630: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9631: categories and subcategories).
1.663 raeburn 9632:
1.655 raeburn 9633: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9634:
1.655 raeburn 9635: allitems (reference to hash - key is category key
9636: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9637:
1.655 raeburn 9638: idx (reference to hash of counters used in Domain Coordinator interface for
9639: editing Course Categories).
1.663 raeburn 9640:
1.655 raeburn 9641: jsarray (reference to array of categories used to create Javascript arrays for
9642: Domain Coordinator interface for editing Course Categories).
9643:
1.665 raeburn 9644: subcats (reference to hash of arrays containing all subcategories within each
9645: category, -recursive)
9646:
1.655 raeburn 9647: Returns: nothing
9648:
9649: Side effects: populates trails and allitems hash references.
9650:
9651: =cut
9652:
9653: sub extract_categories {
1.665 raeburn 9654: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9655: if (ref($categories) eq 'HASH') {
9656: &gather_categories($categories,$cats,$idx,$jsarray);
9657: if (ref($cats->[0]) eq 'ARRAY') {
9658: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9659: my $name = $cats->[0][$i];
9660: my $item = &escape($name).'::0';
9661: my $trailstr;
9662: if ($name eq 'instcode') {
9663: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 9664: } elsif ($name eq 'communities') {
9665: $trailstr = &mt('Communities');
1.655 raeburn 9666: } else {
9667: $trailstr = $name;
9668: }
9669: if ($allitems->{$item} eq '') {
9670: push(@{$trails},$trailstr);
9671: $allitems->{$item} = scalar(@{$trails})-1;
9672: }
9673: my @parents = ($name);
9674: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9675: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9676: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9677: if (ref($subcats) eq 'HASH') {
9678: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9679: }
9680: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9681: }
9682: } else {
9683: if (ref($subcats) eq 'HASH') {
9684: $subcats->{$item} = [];
1.655 raeburn 9685: }
9686: }
9687: }
9688: }
9689: }
9690: return;
9691: }
9692:
9693: =pod
9694:
9695: =item *&recurse_categories()
9696:
9697: Recursively used to generate breadcrumb trails for course categories.
9698:
9699: Inputs:
1.663 raeburn 9700:
1.655 raeburn 9701: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9702: categories and subcategories).
1.663 raeburn 9703:
1.655 raeburn 9704: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9705:
9706: category (current course category, for which breadcrumb trail is being generated).
9707:
9708: trails (reference to array of breadcrumb trails for each category).
9709:
1.655 raeburn 9710: allitems (reference to hash - key is category key
9711: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9712:
1.655 raeburn 9713: parents (array containing containers directories for current category,
9714: back to top level).
9715:
9716: Returns: nothing
9717:
9718: Side effects: populates trails and allitems hash references
9719:
9720: =cut
9721:
9722: sub recurse_categories {
1.665 raeburn 9723: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9724: my $shallower = $depth - 1;
9725: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9726: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9727: my $name = $cats->[$depth]{$category}[$k];
9728: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9729: my $trailstr = join(' -> ',(@{$parents},$category));
9730: if ($allitems->{$item} eq '') {
9731: push(@{$trails},$trailstr);
9732: $allitems->{$item} = scalar(@{$trails})-1;
9733: }
9734: my $deeper = $depth+1;
9735: push(@{$parents},$category);
1.665 raeburn 9736: if (ref($subcats) eq 'HASH') {
9737: my $subcat = &escape($name).':'.$category.':'.$depth;
9738: for (my $j=@{$parents}; $j>=0; $j--) {
9739: my $higher;
9740: if ($j > 0) {
9741: $higher = &escape($parents->[$j]).':'.
9742: &escape($parents->[$j-1]).':'.$j;
9743: } else {
9744: $higher = &escape($parents->[$j]).'::'.$j;
9745: }
9746: push(@{$subcats->{$higher}},$subcat);
9747: }
9748: }
9749: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9750: $subcats);
1.655 raeburn 9751: pop(@{$parents});
9752: }
9753: } else {
9754: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9755: my $trailstr = join(' -> ',(@{$parents},$category));
9756: if ($allitems->{$item} eq '') {
9757: push(@{$trails},$trailstr);
9758: $allitems->{$item} = scalar(@{$trails})-1;
9759: }
9760: }
9761: return;
9762: }
9763:
1.663 raeburn 9764: =pod
9765:
9766: =item *&assign_categories_table()
9767:
9768: Create a datatable for display of hierarchical categories in a domain,
9769: with checkboxes to allow a course to be categorized.
9770:
9771: Inputs:
9772:
9773: cathash - reference to hash of categories defined for the domain (from
9774: configuration.db)
9775:
9776: currcat - scalar with an & separated list of categories assigned to a course.
9777:
1.919 raeburn 9778: type - scalar contains course type (Course or Community).
9779:
1.663 raeburn 9780: Returns: $output (markup to be displayed)
9781:
9782: =cut
9783:
9784: sub assign_categories_table {
1.919 raeburn 9785: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 9786: my $output;
9787: if (ref($cathash) eq 'HASH') {
9788: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9789: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9790: $maxdepth = scalar(@cats);
9791: if (@cats > 0) {
9792: my $itemcount = 0;
9793: if (ref($cats[0]) eq 'ARRAY') {
9794: my @currcategories;
9795: if ($currcat ne '') {
9796: @currcategories = split('&',$currcat);
9797: }
1.919 raeburn 9798: my $table;
1.663 raeburn 9799: for (my $i=0; $i<@{$cats[0]}; $i++) {
9800: my $parent = $cats[0][$i];
1.919 raeburn 9801: next if ($parent eq 'instcode');
9802: if ($type eq 'Community') {
9803: next unless ($parent eq 'communities');
9804: } else {
9805: next if ($parent eq 'communities');
9806: }
1.663 raeburn 9807: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9808: my $item = &escape($parent).'::0';
9809: my $checked = '';
9810: if (@currcategories > 0) {
9811: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9812: $checked = ' checked="checked"';
1.663 raeburn 9813: }
9814: }
1.919 raeburn 9815: my $parent_title = $parent;
9816: if ($parent eq 'communities') {
9817: $parent_title = &mt('Communities');
9818: }
9819: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9820: '<input type="checkbox" name="usecategory" value="'.
9821: $item.'"'.$checked.' />'.$parent_title.'</span>'.
9822: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9823: my $depth = 1;
9824: push(@path,$parent);
1.919 raeburn 9825: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 9826: pop(@path);
1.919 raeburn 9827: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 9828: $itemcount ++;
9829: }
1.919 raeburn 9830: if ($itemcount) {
9831: $output = &Apache::loncommon::start_data_table().
9832: $table.
9833: &Apache::loncommon::end_data_table();
9834: }
1.663 raeburn 9835: }
9836: }
9837: }
9838: return $output;
9839: }
9840:
9841: =pod
9842:
9843: =item *&assign_category_rows()
9844:
9845: Create a datatable row for display of nested categories in a domain,
9846: with checkboxes to allow a course to be categorized,called recursively.
9847:
9848: Inputs:
9849:
9850: itemcount - track row number for alternating colors
9851:
9852: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9853: categories and subcategories.
9854:
9855: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9856:
9857: parent - parent of current category item
9858:
9859: path - Array containing all categories back up through the hierarchy from the
9860: current category to the top level.
9861:
9862: currcategories - reference to array of current categories assigned to the course
9863:
9864: Returns: $output (markup to be displayed).
9865:
9866: =cut
9867:
9868: sub assign_category_rows {
9869: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9870: my ($text,$name,$item,$chgstr);
9871: if (ref($cats) eq 'ARRAY') {
9872: my $maxdepth = scalar(@{$cats});
9873: if (ref($cats->[$depth]) eq 'HASH') {
9874: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9875: my $numchildren = @{$cats->[$depth]{$parent}};
9876: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9877: $text .= '<td><table class="LC_datatable">';
9878: for (my $j=0; $j<$numchildren; $j++) {
9879: $name = $cats->[$depth]{$parent}[$j];
9880: $item = &escape($name).':'.&escape($parent).':'.$depth;
9881: my $deeper = $depth+1;
9882: my $checked = '';
9883: if (ref($currcategories) eq 'ARRAY') {
9884: if (@{$currcategories} > 0) {
9885: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9886: $checked = ' checked="checked"';
1.663 raeburn 9887: }
9888: }
9889: }
1.664 raeburn 9890: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9891: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9892: $item.'"'.$checked.' />'.$name.'</label></span>'.
9893: '<input type="hidden" name="catname" value="'.$name.'" />'.
9894: '</td><td>';
1.663 raeburn 9895: if (ref($path) eq 'ARRAY') {
9896: push(@{$path},$name);
9897: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9898: pop(@{$path});
9899: }
9900: $text .= '</td></tr>';
9901: }
9902: $text .= '</table></td>';
9903: }
9904: }
9905: }
9906: return $text;
9907: }
9908:
1.655 raeburn 9909: ############################################################
9910: ############################################################
9911:
9912:
1.443 albertel 9913: sub commit_customrole {
1.664 raeburn 9914: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9915: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9916: ($start?', '.&mt('starting').' '.localtime($start):'').
9917: ($end?', ending '.localtime($end):'').': <b>'.
9918: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9919: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9920: '</b><br />';
9921: return $output;
9922: }
9923:
9924: sub commit_standardrole {
1.541 raeburn 9925: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9926: my ($output,$logmsg,$linefeed);
9927: if ($context eq 'auto') {
9928: $linefeed = "\n";
9929: } else {
9930: $linefeed = "<br />\n";
9931: }
1.443 albertel 9932: if ($three eq 'st') {
1.541 raeburn 9933: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9934: $one,$two,$sec,$context);
9935: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9936: ($result eq 'unknown_course') || ($result eq 'refused')) {
9937: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9938: } else {
1.541 raeburn 9939: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9940: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9941: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9942: if ($context eq 'auto') {
9943: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9944: } else {
9945: $output .= '<b>'.$result.'</b>'.$linefeed.
9946: &mt('Add to classlist').': <b>ok</b>';
9947: }
9948: $output .= $linefeed;
1.443 albertel 9949: }
9950: } else {
9951: $output = &mt('Assigning').' '.$three.' in '.$url.
9952: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9953: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9954: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9955: if ($context eq 'auto') {
9956: $output .= $result.$linefeed;
9957: } else {
9958: $output .= '<b>'.$result.'</b>'.$linefeed;
9959: }
1.443 albertel 9960: }
9961: return $output;
9962: }
9963:
9964: sub commit_studentrole {
1.541 raeburn 9965: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9966: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9967: if ($context eq 'auto') {
9968: $linefeed = "\n";
9969: } else {
9970: $linefeed = '<br />'."\n";
9971: }
1.443 albertel 9972: if (defined($one) && defined($two)) {
9973: my $cid=$one.'_'.$two;
9974: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9975: my $secchange = 0;
9976: my $expire_role_result;
9977: my $modify_section_result;
1.628 raeburn 9978: if ($oldsec ne '-1') {
9979: if ($oldsec ne $sec) {
1.443 albertel 9980: $secchange = 1;
1.628 raeburn 9981: my $now = time;
1.443 albertel 9982: my $uurl='/'.$cid;
9983: $uurl=~s/\_/\//g;
9984: if ($oldsec) {
9985: $uurl.='/'.$oldsec;
9986: }
1.626 raeburn 9987: $oldsecurl = $uurl;
1.628 raeburn 9988: $expire_role_result =
1.652 raeburn 9989: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9990: if ($env{'request.course.sec'} ne '') {
9991: if ($expire_role_result eq 'refused') {
9992: my @roles = ('st');
9993: my @statuses = ('previous');
9994: my @roledoms = ($one);
9995: my $withsec = 1;
9996: my %roleshash =
9997: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9998: \@statuses,\@roles,\@roledoms,$withsec);
9999: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10000: my ($oldstart,$oldend) =
10001: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10002: if ($oldend > 0 && $oldend <= $now) {
10003: $expire_role_result = 'ok';
10004: }
10005: }
10006: }
10007: }
1.443 albertel 10008: $result = $expire_role_result;
10009: }
10010: }
10011: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10012: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10013: if ($modify_section_result =~ /^ok/) {
10014: if ($secchange == 1) {
1.628 raeburn 10015: if ($sec eq '') {
10016: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10017: } else {
10018: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10019: }
1.443 albertel 10020: } elsif ($oldsec eq '-1') {
1.628 raeburn 10021: if ($sec eq '') {
10022: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10023: } else {
10024: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10025: }
1.443 albertel 10026: } else {
1.628 raeburn 10027: if ($sec eq '') {
10028: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10029: } else {
10030: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10031: }
1.443 albertel 10032: }
10033: } else {
1.628 raeburn 10034: if ($secchange) {
10035: $$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;
10036: } else {
10037: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10038: }
1.443 albertel 10039: }
10040: $result = $modify_section_result;
10041: } elsif ($secchange == 1) {
1.628 raeburn 10042: if ($oldsec eq '') {
10043: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10044: } else {
10045: $$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;
10046: }
1.626 raeburn 10047: if ($expire_role_result eq 'refused') {
10048: my $newsecurl = '/'.$cid;
10049: $newsecurl =~ s/\_/\//g;
10050: if ($sec ne '') {
10051: $newsecurl.='/'.$sec;
10052: }
10053: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10054: if ($sec eq '') {
10055: $$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;
10056: } else {
10057: $$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;
10058: }
10059: }
10060: }
1.443 albertel 10061: }
10062: } else {
1.626 raeburn 10063: $$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 10064: $result = "error: incomplete course id\n";
10065: }
10066: return $result;
10067: }
10068:
10069: ############################################################
10070: ############################################################
10071:
1.566 albertel 10072: sub check_clone {
1.578 raeburn 10073: my ($args,$linefeed) = @_;
1.566 albertel 10074: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10075: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10076: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10077: my $clonemsg;
10078: my $can_clone = 0;
1.944 raeburn 10079: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10080: if ($lctype ne 'community') {
10081: $lctype = 'course';
10082: }
1.566 albertel 10083: if ($clonehome eq 'no_host') {
1.944 raeburn 10084: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10085: $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'});
10086: } else {
10087: $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'});
10088: }
1.566 albertel 10089: } else {
10090: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10091: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10092: if ($clonedesc{'type'} ne 'Community') {
10093: $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'});
10094: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10095: }
10096: }
1.882 raeburn 10097: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10098: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10099: $can_clone = 1;
10100: } else {
10101: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10102: $args->{'clonedomain'},$args->{'clonecourse'});
10103: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10104: if (grep(/^\*$/,@cloners)) {
10105: $can_clone = 1;
10106: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10107: $can_clone = 1;
10108: } else {
1.908 raeburn 10109: my $ccrole = 'cc';
1.944 raeburn 10110: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10111: $ccrole = 'co';
10112: }
1.578 raeburn 10113: my %roleshash =
10114: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10115: $args->{'ccdomain'},
1.908 raeburn 10116: 'userroles',['active'],[$ccrole],
1.578 raeburn 10117: [$args->{'clonedomain'}]);
1.908 raeburn 10118: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10119: $can_clone = 1;
10120: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10121: $can_clone = 1;
10122: } else {
1.944 raeburn 10123: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10124: $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'});
10125: } else {
10126: $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'});
10127: }
1.578 raeburn 10128: }
1.566 albertel 10129: }
1.578 raeburn 10130: }
1.566 albertel 10131: }
10132: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10133: }
10134:
1.444 albertel 10135: sub construct_course {
1.885 raeburn 10136: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10137: my $outcome;
1.541 raeburn 10138: my $linefeed = '<br />'."\n";
10139: if ($context eq 'auto') {
10140: $linefeed = "\n";
10141: }
1.566 albertel 10142:
10143: #
10144: # Are we cloning?
10145: #
10146: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10147: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10148: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10149: if ($context ne 'auto') {
1.578 raeburn 10150: if ($clonemsg ne '') {
10151: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10152: }
1.566 albertel 10153: }
10154: $outcome .= $clonemsg.$linefeed;
10155:
10156: if (!$can_clone) {
10157: return (0,$outcome);
10158: }
10159: }
10160:
1.444 albertel 10161: #
10162: # Open course
10163: #
10164: my $crstype = lc($args->{'crstype'});
10165: my %cenv=();
10166: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10167: $args->{'cdescr'},
10168: $args->{'curl'},
10169: $args->{'course_home'},
10170: $args->{'nonstandard'},
10171: $args->{'crscode'},
10172: $args->{'ccuname'}.':'.
10173: $args->{'ccdomain'},
1.882 raeburn 10174: $args->{'crstype'},
1.885 raeburn 10175: $cnum,$context,$category);
1.444 albertel 10176:
10177: # Note: The testing routines depend on this being output; see
10178: # Utils::Course. This needs to at least be output as a comment
10179: # if anyone ever decides to not show this, and Utils::Course::new
10180: # will need to be suitably modified.
1.541 raeburn 10181: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10182: if ($$courseid =~ /^error:/) {
10183: return (0,$outcome);
10184: }
10185:
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.943 raeburn 10191: if ($crsuhome eq 'no_host') {
10192: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10193: return (0,$outcome);
10194: }
1.541 raeburn 10195: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10196:
1.444 albertel 10197: #
1.566 albertel 10198: # Do the cloning
10199: #
10200: if ($can_clone && $cloneid) {
10201: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10202: if ($context ne 'auto') {
10203: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10204: }
10205: $outcome .= $clonemsg.$linefeed;
10206: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10207: # Copy all files
1.637 www 10208: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10209: # Restore URL
1.566 albertel 10210: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10211: # Restore title
1.566 albertel 10212: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 10213: # Mark as cloned
1.566 albertel 10214: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10215: # Need to clone grading mode
10216: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10217: $cenv{'grading'}=$newenv{'grading'};
10218: # Do not clone these environment entries
10219: &Apache::lonnet::del('environment',
10220: ['default_enrollment_start_date',
10221: 'default_enrollment_end_date',
10222: 'question.email',
10223: 'policy.email',
10224: 'comment.email',
10225: 'pch.users.denied',
1.725 raeburn 10226: 'plc.users.denied',
10227: 'hidefromcat',
10228: 'categories'],
1.638 www 10229: $$crsudom,$$crsunum);
1.444 albertel 10230: }
1.566 albertel 10231:
1.444 albertel 10232: #
10233: # Set environment (will override cloned, if existing)
10234: #
10235: my @sections = ();
10236: my @xlists = ();
10237: if ($args->{'crstype'}) {
10238: $cenv{'type'}=$args->{'crstype'};
10239: }
10240: if ($args->{'crsid'}) {
10241: $cenv{'courseid'}=$args->{'crsid'};
10242: }
10243: if ($args->{'crscode'}) {
10244: $cenv{'internal.coursecode'}=$args->{'crscode'};
10245: }
10246: if ($args->{'crsquota'} ne '') {
10247: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10248: } else {
10249: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10250: }
10251: if ($args->{'ccuname'}) {
10252: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10253: ':'.$args->{'ccdomain'};
10254: } else {
10255: $cenv{'internal.courseowner'} = $args->{'curruser'};
10256: }
10257: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10258: if ($args->{'crssections'}) {
10259: $cenv{'internal.sectionnums'} = '';
10260: if ($args->{'crssections'} =~ m/,/) {
10261: @sections = split/,/,$args->{'crssections'};
10262: } else {
10263: $sections[0] = $args->{'crssections'};
10264: }
10265: if (@sections > 0) {
10266: foreach my $item (@sections) {
10267: my ($sec,$gp) = split/:/,$item;
10268: my $class = $args->{'crscode'}.$sec;
10269: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10270: $cenv{'internal.sectionnums'} .= $item.',';
10271: unless ($addcheck eq 'ok') {
10272: push @badclasses, $class;
10273: }
10274: }
10275: $cenv{'internal.sectionnums'} =~ s/,$//;
10276: }
10277: }
10278: # do not hide course coordinator from staff listing,
10279: # even if privileged
10280: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10281: # add crosslistings
10282: if ($args->{'crsxlist'}) {
10283: $cenv{'internal.crosslistings'}='';
10284: if ($args->{'crsxlist'} =~ m/,/) {
10285: @xlists = split/,/,$args->{'crsxlist'};
10286: } else {
10287: $xlists[0] = $args->{'crsxlist'};
10288: }
10289: if (@xlists > 0) {
10290: foreach my $item (@xlists) {
10291: my ($xl,$gp) = split/:/,$item;
10292: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10293: $cenv{'internal.crosslistings'} .= $item.',';
10294: unless ($addcheck eq 'ok') {
10295: push @badclasses, $xl;
10296: }
10297: }
10298: $cenv{'internal.crosslistings'} =~ s/,$//;
10299: }
10300: }
10301: if ($args->{'autoadds'}) {
10302: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10303: }
10304: if ($args->{'autodrops'}) {
10305: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10306: }
10307: # check for notification of enrollment changes
10308: my @notified = ();
10309: if ($args->{'notify_owner'}) {
10310: if ($args->{'ccuname'} ne '') {
10311: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10312: }
10313: }
10314: if ($args->{'notify_dc'}) {
10315: if ($uname ne '') {
1.630 raeburn 10316: push(@notified,$uname.':'.$udom);
1.444 albertel 10317: }
10318: }
10319: if (@notified > 0) {
10320: my $notifylist;
10321: if (@notified > 1) {
10322: $notifylist = join(',',@notified);
10323: } else {
10324: $notifylist = $notified[0];
10325: }
10326: $cenv{'internal.notifylist'} = $notifylist;
10327: }
10328: if (@badclasses > 0) {
10329: my %lt=&Apache::lonlocal::texthash(
10330: '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',
10331: 'dnhr' => 'does not have rights to access enrollment in these classes',
10332: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10333: );
1.541 raeburn 10334: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10335: ' ('.$lt{'adby'}.')';
10336: if ($context eq 'auto') {
10337: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10338: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10339: foreach my $item (@badclasses) {
10340: if ($context eq 'auto') {
10341: $outcome .= " - $item\n";
10342: } else {
10343: $outcome .= "<li>$item</li>\n";
10344: }
10345: }
10346: if ($context eq 'auto') {
10347: $outcome .= $linefeed;
10348: } else {
1.566 albertel 10349: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10350: }
10351: }
1.444 albertel 10352: }
10353: if ($args->{'no_end_date'}) {
10354: $args->{'endaccess'} = 0;
10355: }
10356: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10357: $cenv{'internal.autoend'}=$args->{'enrollend'};
10358: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10359: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10360: if ($args->{'showphotos'}) {
10361: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10362: }
10363: $cenv{'internal.authtype'} = $args->{'authtype'};
10364: $cenv{'internal.autharg'} = $args->{'autharg'};
10365: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10366: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10367: 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');
10368: if ($context eq 'auto') {
10369: $outcome .= $krb_msg;
10370: } else {
1.566 albertel 10371: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10372: }
10373: $outcome .= $linefeed;
1.444 albertel 10374: }
10375: }
10376: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10377: if ($args->{'setpolicy'}) {
10378: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10379: }
10380: if ($args->{'setcontent'}) {
10381: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10382: }
10383: }
10384: if ($args->{'reshome'}) {
10385: $cenv{'reshome'}=$args->{'reshome'}.'/';
10386: $cenv{'reshome'}=~s/\/+$/\//;
10387: }
10388: #
10389: # course has keyed access
10390: #
10391: if ($args->{'setkeys'}) {
10392: $cenv{'keyaccess'}='yes';
10393: }
10394: # if specified, key authority is not course, but user
10395: # only active if keyaccess is yes
10396: if ($args->{'keyauth'}) {
1.487 albertel 10397: my ($user,$domain) = split(':',$args->{'keyauth'});
10398: $user = &LONCAPA::clean_username($user);
10399: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10400: if ($user ne '' && $domain ne '') {
1.487 albertel 10401: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10402: }
10403: }
10404:
10405: if ($args->{'disresdis'}) {
10406: $cenv{'pch.roles.denied'}='st';
10407: }
10408: if ($args->{'disablechat'}) {
10409: $cenv{'plc.roles.denied'}='st';
10410: }
10411:
10412: # Record we've not yet viewed the Course Initialization Helper for this
10413: # course
10414: $cenv{'course.helper.not.run'} = 1;
10415: #
10416: # Use new Randomseed
10417: #
10418: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10419: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10420: #
10421: # The encryption code and receipt prefix for this course
10422: #
10423: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10424: $cenv{'internal.encpref'}=100+int(9*rand(99));
10425: #
10426: # By default, use standard grading
10427: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10428:
1.541 raeburn 10429: $outcome .= $linefeed.&mt('Setting environment').': '.
10430: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10431: #
10432: # Open all assignments
10433: #
10434: if ($args->{'openall'}) {
10435: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10436: my %storecontent = ($storeunder => time,
10437: $storeunder.'.type' => 'date_start');
10438:
10439: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10440: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10441: }
10442: #
10443: # Set first page
10444: #
10445: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10446: || ($cloneid)) {
1.445 albertel 10447: use LONCAPA::map;
1.444 albertel 10448: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10449:
10450: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10451: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10452:
1.444 albertel 10453: $outcome .= ($fatal?$errtext:'read ok').' - ';
10454: my $title; my $url;
10455: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10456: $title=&mt('Syllabus');
1.444 albertel 10457: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10458: } else {
1.690 bisitz 10459: $title=&mt('Navigate Contents');
1.444 albertel 10460: $url='/adm/navmaps';
10461: }
1.445 albertel 10462:
10463: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10464: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10465:
10466: if ($errtext) { $fatal=2; }
1.541 raeburn 10467: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10468: }
1.566 albertel 10469:
10470: return (1,$outcome);
1.444 albertel 10471: }
10472:
10473: ############################################################
10474: ############################################################
10475:
1.378 raeburn 10476: sub course_type {
10477: my ($cid) = @_;
10478: if (!defined($cid)) {
10479: $cid = $env{'request.course.id'};
10480: }
1.404 albertel 10481: if (defined($env{'course.'.$cid.'.type'})) {
10482: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10483: } else {
10484: return 'Course';
1.377 raeburn 10485: }
10486: }
1.156 albertel 10487:
1.406 raeburn 10488: sub group_term {
10489: my $crstype = &course_type();
10490: my %names = (
10491: 'Course' => 'group',
1.865 raeburn 10492: 'Community' => 'group',
1.406 raeburn 10493: );
10494: return $names{$crstype};
10495: }
10496:
1.902 raeburn 10497: sub course_types {
10498: my @types = ('official','unofficial','community');
10499: my %typename = (
10500: official => 'Official course',
10501: unofficial => 'Unofficial course',
10502: community => 'Community',
10503: );
10504: return (\@types,\%typename);
10505: }
10506:
1.156 albertel 10507: sub icon {
10508: my ($file)=@_;
1.505 albertel 10509: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10510: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10511: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10512: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10513: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10514: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10515: $curfext.".gif") {
10516: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10517: $curfext.".gif";
10518: }
10519: }
1.249 albertel 10520: return &lonhttpdurl($iconname);
1.154 albertel 10521: }
1.84 albertel 10522:
1.575 albertel 10523: sub lonhttpdurl {
1.692 www 10524: #
10525: # Had been used for "small fry" static images on separate port 8080.
10526: # Modify here if lightweight http functionality desired again.
10527: # Currently eliminated due to increasing firewall issues.
10528: #
1.575 albertel 10529: my ($url)=@_;
1.692 www 10530: return $url;
1.215 albertel 10531: }
10532:
1.213 albertel 10533: sub connection_aborted {
10534: my ($r)=@_;
10535: $r->print(" ");$r->rflush();
10536: my $c = $r->connection;
10537: return $c->aborted();
10538: }
10539:
1.221 foxr 10540: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10541: # strings as 'strings'.
10542: sub escape_single {
1.221 foxr 10543: my ($input) = @_;
1.223 albertel 10544: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10545: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10546: return $input;
10547: }
1.223 albertel 10548:
1.222 foxr 10549: # Same as escape_single, but escape's "'s This
10550: # can be used for "strings"
10551: sub escape_double {
10552: my ($input) = @_;
10553: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10554: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10555: return $input;
10556: }
1.223 albertel 10557:
1.222 foxr 10558: # Escapes the last element of a full URL.
10559: sub escape_url {
10560: my ($url) = @_;
1.238 raeburn 10561: my @urlslices = split(/\//, $url,-1);
1.369 www 10562: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10563: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10564: }
1.462 albertel 10565:
1.820 raeburn 10566: sub compare_arrays {
10567: my ($arrayref1,$arrayref2) = @_;
10568: my (@difference,%count);
10569: @difference = ();
10570: %count = ();
10571: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10572: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10573: foreach my $element (keys(%count)) {
10574: if ($count{$element} == 1) {
10575: push(@difference,$element);
10576: }
10577: }
10578: }
10579: return @difference;
10580: }
10581:
1.817 bisitz 10582: # -------------------------------------------------------- Initialize user login
1.462 albertel 10583: sub init_user_environment {
1.463 albertel 10584: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10585: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10586:
10587: my $public=($username eq 'public' && $domain eq 'public');
10588:
10589: # See if old ID present, if so, remove
10590:
10591: my ($filename,$cookie,$userroles);
10592: my $now=time;
10593:
10594: if ($public) {
10595: my $max_public=100;
10596: my $oldest;
10597: my $oldest_time=0;
10598: for(my $next=1;$next<=$max_public;$next++) {
10599: if (-e $lonids."/publicuser_$next.id") {
10600: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10601: if ($mtime<$oldest_time || !$oldest_time) {
10602: $oldest_time=$mtime;
10603: $oldest=$next;
10604: }
10605: } else {
10606: $cookie="publicuser_$next";
10607: last;
10608: }
10609: }
10610: if (!$cookie) { $cookie="publicuser_$oldest"; }
10611: } else {
1.463 albertel 10612: # if this isn't a robot, kill any existing non-robot sessions
10613: if (!$args->{'robot'}) {
10614: opendir(DIR,$lonids);
10615: while ($filename=readdir(DIR)) {
10616: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10617: unlink($lonids.'/'.$filename);
10618: }
1.462 albertel 10619: }
1.463 albertel 10620: closedir(DIR);
1.462 albertel 10621: }
10622: # Give them a new cookie
1.463 albertel 10623: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10624: : $now.$$.int(rand(10000)));
1.463 albertel 10625: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10626:
10627: # Initialize roles
10628:
10629: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10630: }
10631: # ------------------------------------ Check browser type and MathML capability
10632:
10633: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10634: $clientunicode,$clientos) = &decode_user_agent($r);
10635:
10636: # ------------------------------------------------------------- Get environment
10637:
10638: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10639: my ($tmp) = keys(%userenv);
10640: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10641: } else {
10642: undef(%userenv);
10643: }
10644: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10645: $form->{'interface'}=$userenv{'interface'};
10646: }
10647: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10648:
10649: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10650: foreach my $option ('interface','localpath','localres') {
10651: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10652: }
10653: # --------------------------------------------------------- Write first profile
10654:
10655: {
10656: my %initial_env =
10657: ("user.name" => $username,
10658: "user.domain" => $domain,
10659: "user.home" => $authhost,
10660: "browser.type" => $clientbrowser,
10661: "browser.version" => $clientversion,
10662: "browser.mathml" => $clientmathml,
10663: "browser.unicode" => $clientunicode,
10664: "browser.os" => $clientos,
10665: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10666: "request.course.fn" => '',
10667: "request.course.uri" => '',
10668: "request.course.sec" => '',
10669: "request.role" => 'cm',
10670: "request.role.adv" => $env{'user.adv'},
10671: "request.host" => $ENV{'REMOTE_ADDR'},);
10672:
10673: if ($form->{'localpath'}) {
10674: $initial_env{"browser.localpath"} = $form->{'localpath'};
10675: $initial_env{"browser.localres"} = $form->{'localres'};
10676: }
10677:
10678: if ($form->{'interface'}) {
10679: $form->{'interface'}=~s/\W//gs;
10680: $initial_env{"browser.interface"} = $form->{'interface'};
10681: $env{'browser.interface'}=$form->{'interface'};
10682: }
10683:
1.724 raeburn 10684: foreach my $tool ('aboutme','blog','portfolio') {
10685: $userenv{'availabletools.'.$tool} =
10686: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10687: }
10688:
1.864 raeburn 10689: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10690: $userenv{'canrequest.'.$crstype} =
10691: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10692: 'reload','requestcourses');
10693: }
10694:
1.462 albertel 10695: $env{'user.environment'} = "$lonids/$cookie.id";
10696:
10697: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10698: &GDBM_WRCREAT(),0640)) {
10699: &_add_to_env(\%disk_env,\%initial_env);
10700: &_add_to_env(\%disk_env,\%userenv,'environment.');
10701: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10702: if (ref($args->{'extra_env'})) {
10703: &_add_to_env(\%disk_env,$args->{'extra_env'});
10704: }
1.462 albertel 10705: untie(%disk_env);
10706: } else {
1.705 tempelho 10707: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10708: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10709: return 'error: '.$!;
10710: }
10711: }
10712: $env{'request.role'}='cm';
10713: $env{'request.role.adv'}=$env{'user.adv'};
10714: $env{'browser.type'}=$clientbrowser;
10715:
10716: return $cookie;
10717:
10718: }
10719:
10720: sub _add_to_env {
10721: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10722: if (ref($env_data) eq 'HASH') {
10723: while (my ($key,$value) = each(%$env_data)) {
10724: $idf->{$prefix.$key} = $value;
10725: $env{$prefix.$key} = $value;
10726: }
1.462 albertel 10727: }
10728: }
10729:
1.685 tempelho 10730: # --- Get the symbolic name of a problem and the url
10731: sub get_symb {
10732: my ($request,$silent) = @_;
1.726 raeburn 10733: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10734: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10735: if ($symb eq '') {
10736: if (!$silent) {
10737: $request->print("Unable to handle ambiguous references:$url:.");
10738: return ();
10739: }
10740: }
10741: &Apache::lonenc::check_decrypt(\$symb);
10742: return ($symb);
10743: }
10744:
10745: # --------------------------------------------------------------Get annotation
10746:
10747: sub get_annotation {
10748: my ($symb,$enc) = @_;
10749:
10750: my $key = $symb;
10751: if (!$enc) {
10752: $key =
10753: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10754: }
10755: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10756: return $annotation{$key};
10757: }
10758:
10759: sub clean_symb {
1.731 raeburn 10760: my ($symb,$delete_enc) = @_;
1.685 tempelho 10761:
10762: &Apache::lonenc::check_decrypt(\$symb);
10763: my $enc = $env{'request.enc'};
1.731 raeburn 10764: if ($delete_enc) {
1.730 raeburn 10765: delete($env{'request.enc'});
10766: }
1.685 tempelho 10767:
10768: return ($symb,$enc);
10769: }
1.462 albertel 10770:
1.41 ng 10771: =pod
10772:
10773: =back
10774:
1.112 bowersj2 10775: =cut
1.41 ng 10776:
1.112 bowersj2 10777: 1;
10778: __END__;
1.41 ng 10779:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>