Annotation of loncom/interface/loncommon.pm, revision 1.909
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.909 ! raeburn 4: # $Id: loncommon.pm,v 1.908 2009/11/03 03:18:21 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.909 ! raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
! 486: my $wintitle = &mt('Course Browser');
! 487: if ($crstype ne '') {
! 488: $wintitle = &mt($crstype);
! 489: }
1.876 raeburn 490: my $id_functions = &javascript_index_functions();
491: my $output = '
1.776 bisitz 492: <script type="text/javascript" language="JavaScript">
1.824 bisitz 493: // <![CDATA[
1.468 raeburn 494: var stdeditbrowser;'."\n";
1.876 raeburn 495:
496: $output .= <<"ENDSTDBRW";
1.909 ! raeburn 497: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 498: var url = '/adm/pickcourse?';
1.895 raeburn 499: var formid = getFormIdByName(formname);
1.876 raeburn 500: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 501: if (domainfilter != null) {
502: if (domainfilter != '') {
503: url += 'domainfilter='+domainfilter+'&';
504: }
505: }
1.91 www 506: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 507: '&cdomelement='+udom+
508: '&cnameelement='+desc;
1.468 raeburn 509: if (extra_element !=null && extra_element != '') {
1.594 raeburn 510: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 511: url += '&roleelement='+extra_element;
512: if (domainfilter == null || domainfilter == '') {
513: url += '&domainfilter='+extra_element;
514: }
1.234 raeburn 515: }
1.468 raeburn 516: else {
517: if (formname == 'portform') {
518: url += '&setroles='+extra_element;
1.800 raeburn 519: } else {
520: if (formname == 'rules') {
521: url += '&fixeddom='+extra_element;
522: }
1.468 raeburn 523: }
524: }
1.230 raeburn 525: }
1.909 ! raeburn 526: if (type != null && type != '') {
! 527: url += '&type='+type;
! 528: }
! 529: if (type_elem != null && type_elem != '') {
! 530: url += '&typeelement='+type_elem;
! 531: }
1.872 raeburn 532: if (formname == 'ccrs') {
533: var ownername = document.forms[formid].ccuname.value;
534: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
535: url += '&cloner='+ownername+':'+ownerdom;
536: }
1.293 raeburn 537: if (multflag !=null && multflag != '') {
538: url += '&multiple='+multflag;
539: }
1.909 ! raeburn 540: var title = '$wintitle';
1.91 www 541: var options = 'scrollbars=1,resizable=1,menubar=0';
542: options += ',width=700,height=600';
543: stdeditbrowser = open(url,title,options,'1');
544: stdeditbrowser.focus();
545: }
1.876 raeburn 546: $id_functions
547: ENDSTDBRW
1.905 raeburn 548: if (($sec_element ne '') || ($role_element ne '')) {
549: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 550: }
551: $output .= '
552: // ]]>
553: </script>';
554: return $output;
555: }
556:
557: sub javascript_index_functions {
558: return <<"ENDJS";
559:
560: function getFormIdByName(formname) {
561: for (var i=0;i<document.forms.length;i++) {
562: if (document.forms[i].name == formname) {
563: return i;
564: }
565: }
566: return -1;
567: }
568:
569: function getIndexByName(formid,item) {
570: for (var i=0;i<document.forms[formid].elements.length;i++) {
571: if (document.forms[formid].elements[i].name == item) {
572: return i;
573: }
574: }
575: return -1;
576: }
1.468 raeburn 577:
1.876 raeburn 578: function getDomainFromSelectbox(formname,udom) {
579: var userdom;
580: var formid = getFormIdByName(formname);
581: if (formid > -1) {
582: var domid = getIndexByName(formid,udom);
583: if (domid > -1) {
584: if (document.forms[formid].elements[domid].type == 'select-one') {
585: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
586: }
587: if (document.forms[formid].elements[domid].type == 'hidden') {
588: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 589: }
590: }
591: }
1.876 raeburn 592: return userdom;
593: }
594:
595: ENDJS
1.468 raeburn 596:
1.876 raeburn 597: }
598:
599: sub userbrowser_javascript {
600: my $id_functions = &javascript_index_functions();
601: return <<"ENDUSERBRW";
602:
1.888 raeburn 603: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 604: var url = '/adm/pickuser?';
605: var userdom = getDomainFromSelectbox(formname,udom);
606: if (userdom != null) {
607: if (userdom != '') {
608: url += 'srchdom='+userdom+'&';
609: }
610: }
611: url += 'form=' + formname + '&unameelement='+uname+
612: '&udomelement='+udom+
613: '&ulastelement='+ulast+
614: '&ufirstelement='+ufirst+
615: '&uemailelement='+uemail+
1.881 raeburn 616: '&hideudomelement='+hideudom+
617: '&coursedom='+crsdom;
1.888 raeburn 618: if ((caller != null) && (caller != undefined)) {
619: url += '&caller='+caller;
620: }
1.876 raeburn 621: var title = 'User_Browser';
622: var options = 'scrollbars=1,resizable=1,menubar=0';
623: options += ',width=700,height=600';
624: var stdeditbrowser = open(url,title,options,'1');
625: stdeditbrowser.focus();
626: }
627:
1.888 raeburn 628: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 629: var formid = getFormIdByName(formname);
630: if (formid > -1) {
1.888 raeburn 631: var unameid = getIndexByName(formid,uname);
1.876 raeburn 632: var domid = getIndexByName(formid,udom);
633: var hidedomid = getIndexByName(formid,origdom);
634: if (hidedomid > -1) {
635: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 636: var unameval = document.forms[formid].elements[unameid].value;
637: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
638: if (domid > -1) {
639: var slct = document.forms[formid].elements[domid];
640: if (slct.type == 'select-one') {
641: var i;
642: for (i=0;i<slct.length;i++) {
643: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
644: }
645: }
646: if (slct.type == 'hidden') {
647: slct.value = fixeddom;
1.876 raeburn 648: }
649: }
1.468 raeburn 650: }
651: }
652: }
1.876 raeburn 653: return;
654: }
655:
656: $id_functions
657: ENDUSERBRW
1.468 raeburn 658: }
659:
660: sub setsec_javascript {
1.905 raeburn 661: my ($sec_element,$formname,$role_element) = @_;
662: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
663: $communityrolestr);
664: if ($role_element ne '') {
665: my @allroles = ('st','ta','ep','in','ad');
666: foreach my $crstype ('Course','Community') {
667: if ($crstype eq 'Community') {
668: foreach my $role (@allroles) {
669: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
670: }
671: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
672: } else {
673: foreach my $role (@allroles) {
674: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
675: }
676: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
677: }
678: }
679: $rolestr = '"'.join('","',@allroles).'"';
680: $courserolestr = '"'.join('","',@courserolenames).'"';
681: $communityrolestr = '"'.join('","',@communityrolenames).'"';
682: }
1.468 raeburn 683: my $setsections = qq|
684: function setSect(sectionlist) {
1.629 raeburn 685: var sectionsArray = new Array();
686: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
687: sectionsArray = sectionlist.split(",");
688: }
1.468 raeburn 689: var numSections = sectionsArray.length;
690: document.$formname.$sec_element.length = 0;
691: if (numSections == 0) {
692: document.$formname.$sec_element.multiple=false;
693: document.$formname.$sec_element.size=1;
694: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
695: } else {
696: if (numSections == 1) {
697: document.$formname.$sec_element.multiple=false;
698: document.$formname.$sec_element.size=1;
699: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
700: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
701: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
702: } else {
703: for (var i=0; i<numSections; i++) {
704: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
705: }
706: document.$formname.$sec_element.multiple=true
707: if (numSections < 3) {
708: document.$formname.$sec_element.size=numSections;
709: } else {
710: document.$formname.$sec_element.size=3;
711: }
712: document.$formname.$sec_element.options[0].selected = false
713: }
714: }
1.91 www 715: }
1.905 raeburn 716:
717: function setRole(crstype) {
1.468 raeburn 718: |;
1.905 raeburn 719: if ($role_element eq '') {
720: $setsections .= ' return;
721: }
722: ';
723: } else {
724: $setsections .= qq|
725: var elementLength = document.$formname.$role_element.length;
726: var allroles = Array($rolestr);
727: var courserolenames = Array($courserolestr);
728: var communityrolenames = Array($communityrolestr);
729: if (elementLength != undefined) {
730: if (document.$formname.$role_element.options[5].value == 'cc') {
731: if (crstype == 'Course') {
732: return;
733: } else {
734: allroles[5] = 'co';
735: for (var i=0; i<6; i++) {
736: document.$formname.$role_element.options[i].value = allroles[i];
737: document.$formname.$role_element.options[i].text = communityrolenames[i];
738: }
739: }
740: } else {
741: if (crstype == 'Community') {
742: return;
743: } else {
744: allroles[5] = 'cc';
745: for (var i=0; i<6; i++) {
746: document.$formname.$role_element.options[i].value = allroles[i];
747: document.$formname.$role_element.options[i].text = courserolenames[i];
748: }
749: }
750: }
751: }
752: return;
753: }
754: |;
755: }
1.468 raeburn 756: return $setsections;
757: }
758:
1.91 www 759: sub selectcourse_link {
1.909 ! raeburn 760: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
! 761: $typeelement) = @_;
! 762: my $type = $selecttype;
1.871 raeburn 763: my $linktext = &mt('Select Course');
764: if ($selecttype eq 'Community') {
1.909 ! raeburn 765: $linktext = &mt('Select Community');
1.906 raeburn 766: } elsif ($selecttype eq 'Course/Community') {
767: $linktext = &mt('Select Course/Community');
1.909 ! raeburn 768: $type = '';
1.871 raeburn 769: }
1.787 bisitz 770: return '<span class="LC_nobreak">'
771: ."<a href='"
772: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
773: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 ! raeburn 774: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 775: ."'>".$linktext.'</a>'
1.787 bisitz 776: .'</span>';
1.74 www 777: }
1.42 matthew 778:
1.653 raeburn 779: sub selectauthor_link {
780: my ($form,$udom)=@_;
781: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
782: &mt('Select Author').'</a>';
783: }
784:
1.876 raeburn 785: sub selectuser_link {
1.881 raeburn 786: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 787: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 788: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 789: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 790: ');">'.$linktext.'</a>';
1.876 raeburn 791: }
792:
1.273 raeburn 793: sub check_uncheck_jscript {
794: my $jscript = <<"ENDSCRT";
795: function checkAll(field) {
796: if (field.length > 0) {
797: for (i = 0; i < field.length; i++) {
798: field[i].checked = true ;
799: }
800: } else {
801: field.checked = true
802: }
803: }
804:
805: function uncheckAll(field) {
806: if (field.length > 0) {
807: for (i = 0; i < field.length; i++) {
808: field[i].checked = false ;
1.543 albertel 809: }
810: } else {
1.273 raeburn 811: field.checked = false ;
812: }
813: }
814: ENDSCRT
815: return $jscript;
816: }
817:
1.656 www 818: sub select_timezone {
1.659 raeburn 819: my ($name,$selected,$onchange,$includeempty)=@_;
820: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
821: if ($includeempty) {
822: $output .= '<option value=""';
823: if (($selected eq '') || ($selected eq 'local')) {
824: $output .= ' selected="selected" ';
825: }
826: $output .= '> </option>';
827: }
1.657 raeburn 828: my @timezones = DateTime::TimeZone->all_names;
829: foreach my $tzone (@timezones) {
830: $output.= '<option value="'.$tzone.'"';
831: if ($tzone eq $selected) {
832: $output.=' selected="selected"';
833: }
834: $output.=">$tzone</option>\n";
1.656 www 835: }
836: $output.="</select>";
837: return $output;
838: }
1.273 raeburn 839:
1.687 raeburn 840: sub select_datelocale {
841: my ($name,$selected,$onchange,$includeempty)=@_;
842: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
843: if ($includeempty) {
844: $output .= '<option value=""';
845: if ($selected eq '') {
846: $output .= ' selected="selected" ';
847: }
848: $output .= '> </option>';
849: }
850: my (@possibles,%locale_names);
851: my @locales = DateTime::Locale::Catalog::Locales;
852: foreach my $locale (@locales) {
853: if (ref($locale) eq 'HASH') {
854: my $id = $locale->{'id'};
855: if ($id ne '') {
856: my $en_terr = $locale->{'en_territory'};
857: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 858: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 859: if (grep(/^en$/,@languages) || !@languages) {
860: if ($en_terr ne '') {
861: $locale_names{$id} = '('.$en_terr.')';
862: } elsif ($native_terr ne '') {
863: $locale_names{$id} = $native_terr;
864: }
865: } else {
866: if ($native_terr ne '') {
867: $locale_names{$id} = $native_terr.' ';
868: } elsif ($en_terr ne '') {
869: $locale_names{$id} = '('.$en_terr.')';
870: }
871: }
872: push (@possibles,$id);
873: }
874: }
875: }
876: foreach my $item (sort(@possibles)) {
877: $output.= '<option value="'.$item.'"';
878: if ($item eq $selected) {
879: $output.=' selected="selected"';
880: }
881: $output.=">$item";
882: if ($locale_names{$item} ne '') {
883: $output.=" $locale_names{$item}</option>\n";
884: }
885: $output.="</option>\n";
886: }
887: $output.="</select>";
888: return $output;
889: }
890:
1.792 raeburn 891: sub select_language {
892: my ($name,$selected,$includeempty) = @_;
893: my %langchoices;
894: if ($includeempty) {
895: %langchoices = ('' => 'No language preference');
896: }
897: foreach my $id (&languageids()) {
898: my $code = &supportedlanguagecode($id);
899: if ($code) {
900: $langchoices{$code} = &plainlanguagedescription($id);
901: }
902: }
903: return &select_form($selected,$name,%langchoices);
904: }
905:
1.42 matthew 906: =pod
1.36 matthew 907:
1.648 raeburn 908: =item * &linked_select_forms(...)
1.36 matthew 909:
910: linked_select_forms returns a string containing a <script></script> block
911: and html for two <select> menus. The select menus will be linked in that
912: changing the value of the first menu will result in new values being placed
913: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 914: order unless a defined order is provided.
1.36 matthew 915:
916: linked_select_forms takes the following ordered inputs:
917:
918: =over 4
919:
1.112 bowersj2 920: =item * $formname, the name of the <form> tag
1.36 matthew 921:
1.112 bowersj2 922: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 923:
1.112 bowersj2 924: =item * $firstdefault, the default value for the first menu
1.36 matthew 925:
1.112 bowersj2 926: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 927:
1.112 bowersj2 928: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 929:
1.112 bowersj2 930: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 931:
1.609 raeburn 932: =item * $menuorder, the order of values in the first menu
933:
1.41 ng 934: =back
935:
1.36 matthew 936: Below is an example of such a hash. Only the 'text', 'default', and
937: 'select2' keys must appear as stated. keys(%menu) are the possible
938: values for the first select menu. The text that coincides with the
1.41 ng 939: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 940: and text for the second menu are given in the hash pointed to by
941: $menu{$choice1}->{'select2'}.
942:
1.112 bowersj2 943: my %menu = ( A1 => { text =>"Choice A1" ,
944: default => "B3",
945: select2 => {
946: B1 => "Choice B1",
947: B2 => "Choice B2",
948: B3 => "Choice B3",
949: B4 => "Choice B4"
1.609 raeburn 950: },
951: order => ['B4','B3','B1','B2'],
1.112 bowersj2 952: },
953: A2 => { text =>"Choice A2" ,
954: default => "C2",
955: select2 => {
956: C1 => "Choice C1",
957: C2 => "Choice C2",
958: C3 => "Choice C3"
1.609 raeburn 959: },
960: order => ['C2','C1','C3'],
1.112 bowersj2 961: },
962: A3 => { text =>"Choice A3" ,
963: default => "D6",
964: select2 => {
965: D1 => "Choice D1",
966: D2 => "Choice D2",
967: D3 => "Choice D3",
968: D4 => "Choice D4",
969: D5 => "Choice D5",
970: D6 => "Choice D6",
971: D7 => "Choice D7"
1.609 raeburn 972: },
973: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 974: }
975: );
1.36 matthew 976:
977: =cut
978:
979: sub linked_select_forms {
980: my ($formname,
981: $middletext,
982: $firstdefault,
983: $firstselectname,
984: $secondselectname,
1.609 raeburn 985: $hashref,
986: $menuorder,
1.36 matthew 987: ) = @_;
988: my $second = "document.$formname.$secondselectname";
989: my $first = "document.$formname.$firstselectname";
990: # output the javascript to do the changing
991: my $result = '';
1.776 bisitz 992: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 993: $result.="// <![CDATA[\n";
1.36 matthew 994: $result.="var select2data = new Object();\n";
995: $" = '","';
996: my $debug = '';
997: foreach my $s1 (sort(keys(%$hashref))) {
998: $result.="select2data.d_$s1 = new Object();\n";
999: $result.="select2data.d_$s1.def = new String('".
1000: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1001: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1002: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1003: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1004: @s2values = @{$hashref->{$s1}->{'order'}};
1005: }
1.36 matthew 1006: $result.="\"@s2values\");\n";
1007: $result.="select2data.d_$s1.texts = new Array(";
1008: my @s2texts;
1009: foreach my $value (@s2values) {
1010: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1011: }
1012: $result.="\"@s2texts\");\n";
1013: }
1014: $"=' ';
1015: $result.= <<"END";
1016:
1017: function select1_changed() {
1018: // Determine new choice
1019: var newvalue = "d_" + $first.value;
1020: // update select2
1021: var values = select2data[newvalue].values;
1022: var texts = select2data[newvalue].texts;
1023: var select2def = select2data[newvalue].def;
1024: var i;
1025: // out with the old
1026: for (i = 0; i < $second.options.length; i++) {
1027: $second.options[i] = null;
1028: }
1029: // in with the nuclear
1030: for (i=0;i<values.length; i++) {
1031: $second.options[i] = new Option(values[i]);
1.143 matthew 1032: $second.options[i].value = values[i];
1.36 matthew 1033: $second.options[i].text = texts[i];
1034: if (values[i] == select2def) {
1035: $second.options[i].selected = true;
1036: }
1037: }
1038: }
1.824 bisitz 1039: // ]]>
1.36 matthew 1040: </script>
1041: END
1042: # output the initial values for the selection lists
1043: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1044: my @order = sort(keys(%{$hashref}));
1045: if (ref($menuorder) eq 'ARRAY') {
1046: @order = @{$menuorder};
1047: }
1048: foreach my $value (@order) {
1.36 matthew 1049: $result.=" <option value=\"$value\" ";
1.253 albertel 1050: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1051: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1052: }
1053: $result .= "</select>\n";
1054: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1055: $result .= $middletext;
1056: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1057: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1058:
1059: my @secondorder = sort(keys(%select2));
1060: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1061: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1062: }
1063: foreach my $value (@secondorder) {
1.36 matthew 1064: $result.=" <option value=\"$value\" ";
1.253 albertel 1065: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1066: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1067: }
1068: $result .= "</select>\n";
1069: # return $debug;
1070: return $result;
1071: } # end of sub linked_select_forms {
1072:
1.45 matthew 1073: =pod
1.44 bowersj2 1074:
1.648 raeburn 1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 1076:
1.112 bowersj2 1077: Returns a string corresponding to an HTML link to the given help
1078: $topic, where $topic corresponds to the name of a .tex file in
1079: /home/httpd/html/adm/help/tex, with underscores replaced by
1080: spaces.
1081:
1082: $text will optionally be linked to the same topic, allowing you to
1083: link text in addition to the graphic. If you do not want to link
1084: text, but wish to specify one of the later parameters, pass an
1085: empty string.
1086:
1087: $stayOnPage is a value that will be interpreted as a boolean. If true,
1088: the link will not open a new window. If false, the link will open
1089: a new window using Javascript. (Default is false.)
1090:
1091: $width and $height are optional numerical parameters that will
1092: override the width and height of the popped up window, which may
1093: be useful for certain help topics with big pictures included.
1.44 bowersj2 1094:
1095: =cut
1096:
1097: sub help_open_topic {
1.48 bowersj2 1098: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1099: $text = "" if (not defined $text);
1.44 bowersj2 1100: $stayOnPage = 0 if (not defined $stayOnPage);
1101: $width = 350 if (not defined $width);
1102: $height = 400 if (not defined $height);
1103: my $filename = $topic;
1104: $filename =~ s/ /_/g;
1105:
1.48 bowersj2 1106: my $template = "";
1107: my $link;
1.572 banghart 1108:
1.159 www 1109: $topic=~s/\W/\_/g;
1.44 bowersj2 1110:
1.572 banghart 1111: if (!$stayOnPage) {
1.72 bowersj2 1112: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1113: } else {
1.48 bowersj2 1114: $link = "/adm/help/${filename}.hlp";
1115: }
1116:
1117: # Add the text
1.755 neumanie 1118: if ($text ne "") {
1.763 bisitz 1119: $template.='<span class="LC_help_open_topic">'
1120: .'<a target="_top" href="'.$link.'">'
1121: .$text.'</a>';
1.48 bowersj2 1122: }
1123:
1.763 bisitz 1124: # (Always) Add the graphic
1.179 matthew 1125: my $title = &mt('Online Help');
1.667 raeburn 1126: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763 bisitz 1127: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1128: .'<img src="'.$helpicon.'" border="0"'
1129: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783 amueller 1130: .' title="'.$title.'"'
1.763 bisitz 1131: .' /></a>';
1132: if ($text ne "") {
1133: $template.='</span>';
1134: }
1.44 bowersj2 1135: return $template;
1136:
1.106 bowersj2 1137: }
1138:
1139: # This is a quicky function for Latex cheatsheet editing, since it
1140: # appears in at least four places
1141: sub helpLatexCheatsheet {
1.732 raeburn 1142: my ($topic,$text,$not_author) = @_;
1143: my $out;
1.106 bowersj2 1144: my $addOther = '';
1.732 raeburn 1145: if ($topic) {
1.763 bisitz 1146: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1147: undef, undef, 600).
1148: '</span> ';
1149: }
1150: $out = '<span>' # Start cheatsheet
1151: .$addOther
1152: .'<span>'
1153: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1154: undef,undef,600)
1155: .'</span> <span>'
1156: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1157: undef,undef,600)
1158: .'</span>';
1.732 raeburn 1159: unless ($not_author) {
1.763 bisitz 1160: $out .= ' <span>'
1161: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1162: undef,undef,600)
1163: .'</span>';
1.732 raeburn 1164: }
1.763 bisitz 1165: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1166: return $out;
1.172 www 1167: }
1168:
1.430 albertel 1169: sub general_help {
1170: my $helptopic='Student_Intro';
1171: if ($env{'request.role'}=~/^(ca|au)/) {
1172: $helptopic='Authoring_Intro';
1.907 raeburn 1173: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1174: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1175: } elsif ($env{'request.role'}=~/^dc/) {
1176: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1177: }
1178: return $helptopic;
1179: }
1180:
1181: sub update_help_link {
1182: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1183: my $origurl = $ENV{'REQUEST_URI'};
1184: $origurl=~s|^/~|/priv/|;
1185: my $timestamp = time;
1186: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1187: $$datum = &escape($$datum);
1188: }
1189:
1190: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1191: my $output .= <<"ENDOUTPUT";
1192: <script type="text/javascript">
1.824 bisitz 1193: // <![CDATA[
1.430 albertel 1194: banner_link = '$banner_link';
1.824 bisitz 1195: // ]]>
1.430 albertel 1196: </script>
1197: ENDOUTPUT
1198: return $output;
1199: }
1200:
1201: # now just updates the help link and generates a blue icon
1.193 raeburn 1202: sub help_open_menu {
1.430 albertel 1203: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1204: = @_;
1.430 albertel 1205: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1206: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1207: # if environment.remote is on (using remote control UI)
1.798 tempelho 1208: if ($env{'environment.remote'} eq 'off' ) {
1.552 banghart 1209: $stayOnPage=1;
1.430 albertel 1210: }
1211: my $output;
1212: if ($component_help) {
1213: if (!$text) {
1214: $output=&help_open_topic($component_help,undef,$stayOnPage,
1215: $width,$height);
1216: } else {
1217: my $help_text;
1218: $help_text=&unescape($topic);
1219: $output='<table><tr><td>'.
1220: &help_open_topic($component_help,$help_text,$stayOnPage,
1221: $width,$height).'</td></tr></table>';
1222: }
1223: }
1224: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1225: return $output.$banner_link;
1226: }
1227:
1228: sub top_nav_help {
1229: my ($text) = @_;
1.436 albertel 1230: $text = &mt($text);
1.572 banghart 1231: my $stay_on_page =
1.798 tempelho 1232: ($env{'environment.remote'} eq 'off' );
1.572 banghart 1233: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1234: : "javascript:helpMenu('open')";
1.572 banghart 1235: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1236:
1.201 raeburn 1237: my $title = &mt('Get help');
1.436 albertel 1238:
1239: return <<"END";
1240: $banner_link
1241: <a href="$link" title="$title">$text</a>
1242: END
1243: }
1244:
1245: sub help_menu_js {
1246: my ($text) = @_;
1247:
1248: my $stayOnPage =
1.798 tempelho 1249: ($env{'environment.remote'} eq 'off' );
1.436 albertel 1250:
1251: my $width = 620;
1252: my $height = 600;
1.430 albertel 1253: my $helptopic=&general_help();
1254: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1255: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1256: my $start_page =
1257: &Apache::loncommon::start_page('Help Menu', undef,
1258: {'frameset' => 1,
1259: 'js_ready' => 1,
1260: 'add_entries' => {
1261: 'border' => '0',
1.579 raeburn 1262: 'rows' => "110,*",},});
1.331 albertel 1263: my $end_page =
1264: &Apache::loncommon::end_page({'frameset' => 1,
1265: 'js_ready' => 1,});
1266:
1.436 albertel 1267: my $template .= <<"ENDTEMPLATE";
1268: <script type="text/javascript">
1.877 bisitz 1269: // <![CDATA[
1.253 albertel 1270: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1271: var banner_link = '';
1.243 raeburn 1272: function helpMenu(target) {
1273: var caller = this;
1274: if (target == 'open') {
1275: var newWindow = null;
1276: try {
1.262 albertel 1277: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1278: }
1279: catch(error) {
1280: writeHelp(caller);
1281: return;
1282: }
1283: if (newWindow) {
1284: caller = newWindow;
1285: }
1.193 raeburn 1286: }
1.243 raeburn 1287: writeHelp(caller);
1288: return;
1289: }
1290: function writeHelp(caller) {
1.430 albertel 1291: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1292: caller.document.close()
1293: caller.focus()
1.193 raeburn 1294: }
1.877 bisitz 1295: // END LON-CAPA Internal -->
1.253 albertel 1296: // ]]>
1.436 albertel 1297: </script>
1.193 raeburn 1298: ENDTEMPLATE
1299: return $template;
1300: }
1301:
1.172 www 1302: sub help_open_bug {
1303: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1304: unless ($env{'user.adv'}) { return ''; }
1.172 www 1305: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1306: $text = "" if (not defined $text);
1307: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1308: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1309: $stayOnPage=1;
1310: }
1.184 albertel 1311: $width = 600 if (not defined $width);
1312: $height = 600 if (not defined $height);
1.172 www 1313:
1314: $topic=~s/\W+/\+/g;
1315: my $link='';
1316: my $template='';
1.379 albertel 1317: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1318: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1319: if (!$stayOnPage)
1320: {
1321: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1322: }
1323: else
1324: {
1325: $link = $url;
1326: }
1327: # Add the text
1328: if ($text ne "")
1329: {
1330: $template .=
1331: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1332: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1333: }
1334:
1335: # Add the graphic
1.179 matthew 1336: my $title = &mt('Report a Bug');
1.215 albertel 1337: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1338: $template .= <<"ENDTEMPLATE";
1.436 albertel 1339: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1340: ENDTEMPLATE
1341: if ($text ne '') { $template.='</td></tr></table>' };
1342: return $template;
1343:
1344: }
1345:
1346: sub help_open_faq {
1347: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1348: unless ($env{'user.adv'}) { return ''; }
1.172 www 1349: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1350: $text = "" if (not defined $text);
1351: $stayOnPage = 0 if (not defined $stayOnPage);
1.798 tempelho 1352: if ($env{'environment.remote'} eq 'off' ) {
1.172 www 1353: $stayOnPage=1;
1354: }
1355: $width = 350 if (not defined $width);
1356: $height = 400 if (not defined $height);
1357:
1358: $topic=~s/\W+/\+/g;
1359: my $link='';
1360: my $template='';
1361: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1362: if (!$stayOnPage)
1363: {
1364: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1365: }
1366: else
1367: {
1368: $link = $url;
1369: }
1370:
1371: # Add the text
1372: if ($text ne "")
1373: {
1374: $template .=
1.173 www 1375: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1376: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1377: }
1378:
1379: # Add the graphic
1.179 matthew 1380: my $title = &mt('View the FAQ');
1.215 albertel 1381: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1382: $template .= <<"ENDTEMPLATE";
1.436 albertel 1383: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1384: ENDTEMPLATE
1385: if ($text ne '') { $template.='</td></tr></table>' };
1386: return $template;
1387:
1.44 bowersj2 1388: }
1.37 matthew 1389:
1.180 matthew 1390: ###############################################################
1391: ###############################################################
1392:
1.45 matthew 1393: =pod
1394:
1.648 raeburn 1395: =item * &change_content_javascript():
1.256 matthew 1396:
1397: This and the next function allow you to create small sections of an
1398: otherwise static HTML page that you can update on the fly with
1399: Javascript, even in Netscape 4.
1400:
1401: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1402: must be written to the HTML page once. It will prove the Javascript
1403: function "change(name, content)". Calling the change function with the
1404: name of the section
1405: you want to update, matching the name passed to C<changable_area>, and
1406: the new content you want to put in there, will put the content into
1407: that area.
1408:
1409: B<Note>: Netscape 4 only reserves enough space for the changable area
1410: to contain room for the original contents. You need to "make space"
1411: for whatever changes you wish to make, and be B<sure> to check your
1412: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1413: it's adequate for updating a one-line status display, but little more.
1414: This script will set the space to 100% width, so you only need to
1415: worry about height in Netscape 4.
1416:
1417: Modern browsers are much less limiting, and if you can commit to the
1418: user not using Netscape 4, this feature may be used freely with
1419: pretty much any HTML.
1420:
1421: =cut
1422:
1423: sub change_content_javascript {
1424: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1425: if ($env{'browser.type'} eq 'netscape' &&
1426: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1427: return (<<NETSCAPE4);
1428: function change(name, content) {
1429: doc = document.layers[name+"___escape"].layers[0].document;
1430: doc.open();
1431: doc.write(content);
1432: doc.close();
1433: }
1434: NETSCAPE4
1435: } else {
1436: # Otherwise, we need to use semi-standards-compliant code
1437: # (technically, "innerHTML" isn't standard but the equivalent
1438: # is really scary, and every useful browser supports it
1439: return (<<DOMBASED);
1440: function change(name, content) {
1441: element = document.getElementById(name);
1442: element.innerHTML = content;
1443: }
1444: DOMBASED
1445: }
1446: }
1447:
1448: =pod
1449:
1.648 raeburn 1450: =item * &changable_area($name,$origContent):
1.256 matthew 1451:
1452: This provides a "changable area" that can be modified on the fly via
1453: the Javascript code provided in C<change_content_javascript>. $name is
1454: the name you will use to reference the area later; do not repeat the
1455: same name on a given HTML page more then once. $origContent is what
1456: the area will originally contain, which can be left blank.
1457:
1458: =cut
1459:
1460: sub changable_area {
1461: my ($name, $origContent) = @_;
1462:
1.258 albertel 1463: if ($env{'browser.type'} eq 'netscape' &&
1464: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1465: # If this is netscape 4, we need to use the Layer tag
1466: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1467: } else {
1468: return "<span id='$name'>$origContent</span>";
1469: }
1470: }
1471:
1472: =pod
1473:
1.648 raeburn 1474: =item * &viewport_geometry_js
1.590 raeburn 1475:
1476: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1477:
1478: =cut
1479:
1480:
1481: sub viewport_geometry_js {
1482: return <<"GEOMETRY";
1483: var Geometry = {};
1484: function init_geometry() {
1485: if (Geometry.init) { return };
1486: Geometry.init=1;
1487: if (window.innerHeight) {
1488: Geometry.getViewportHeight = function() { return window.innerHeight; };
1489: Geometry.getViewportWidth = function() { return window.innerWidth; };
1490: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1491: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1492: }
1493: else if (document.documentElement && document.documentElement.clientHeight) {
1494: Geometry.getViewportHeight =
1495: function() { return document.documentElement.clientHeight; };
1496: Geometry.getViewportWidth =
1497: function() { return document.documentElement.clientWidth; };
1498:
1499: Geometry.getHorizontalScroll =
1500: function() { return document.documentElement.scrollLeft; };
1501: Geometry.getVerticalScroll =
1502: function() { return document.documentElement.scrollTop; };
1503: }
1504: else if (document.body.clientHeight) {
1505: Geometry.getViewportHeight =
1506: function() { return document.body.clientHeight; };
1507: Geometry.getViewportWidth =
1508: function() { return document.body.clientWidth; };
1509: Geometry.getHorizontalScroll =
1510: function() { return document.body.scrollLeft; };
1511: Geometry.getVerticalScroll =
1512: function() { return document.body.scrollTop; };
1513: }
1514: }
1515:
1516: GEOMETRY
1517: }
1518:
1519: =pod
1520:
1.648 raeburn 1521: =item * &viewport_size_js()
1.590 raeburn 1522:
1523: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1524:
1525: =cut
1526:
1527: sub viewport_size_js {
1528: my $geometry = &viewport_geometry_js();
1529: return <<"DIMS";
1530:
1531: $geometry
1532:
1533: function getViewportDims(width,height) {
1534: init_geometry();
1535: width.value = Geometry.getViewportWidth();
1536: height.value = Geometry.getViewportHeight();
1537: return;
1538: }
1539:
1540: DIMS
1541: }
1542:
1543: =pod
1544:
1.648 raeburn 1545: =item * &resize_textarea_js()
1.565 albertel 1546:
1547: emits the needed javascript to resize a textarea to be as big as possible
1548:
1549: creates a function resize_textrea that takes two IDs first should be
1550: the id of the element to resize, second should be the id of a div that
1551: surrounds everything that comes after the textarea, this routine needs
1552: to be attached to the <body> for the onload and onresize events.
1553:
1.648 raeburn 1554: =back
1.565 albertel 1555:
1556: =cut
1557:
1558: sub resize_textarea_js {
1.590 raeburn 1559: my $geometry = &viewport_geometry_js();
1.565 albertel 1560: return <<"RESIZE";
1561: <script type="text/javascript">
1.824 bisitz 1562: // <![CDATA[
1.590 raeburn 1563: $geometry
1.565 albertel 1564:
1.588 albertel 1565: function getX(element) {
1566: var x = 0;
1567: while (element) {
1568: x += element.offsetLeft;
1569: element = element.offsetParent;
1570: }
1571: return x;
1572: }
1573: function getY(element) {
1574: var y = 0;
1575: while (element) {
1576: y += element.offsetTop;
1577: element = element.offsetParent;
1578: }
1579: return y;
1580: }
1581:
1582:
1.565 albertel 1583: function resize_textarea(textarea_id,bottom_id) {
1584: init_geometry();
1585: var textarea = document.getElementById(textarea_id);
1586: //alert(textarea);
1587:
1.588 albertel 1588: var textarea_top = getY(textarea);
1.565 albertel 1589: var textarea_height = textarea.offsetHeight;
1590: var bottom = document.getElementById(bottom_id);
1.588 albertel 1591: var bottom_top = getY(bottom);
1.565 albertel 1592: var bottom_height = bottom.offsetHeight;
1593: var window_height = Geometry.getViewportHeight();
1.588 albertel 1594: var fudge = 23;
1.565 albertel 1595: var new_height = window_height-fudge-textarea_top-bottom_height;
1596: if (new_height < 300) {
1597: new_height = 300;
1598: }
1599: textarea.style.height=new_height+'px';
1600: }
1.824 bisitz 1601: // ]]>
1.565 albertel 1602: </script>
1603: RESIZE
1604:
1605: }
1606:
1607: =pod
1608:
1.256 matthew 1609: =head1 Excel and CSV file utility routines
1610:
1611: =over 4
1612:
1613: =cut
1614:
1615: ###############################################################
1616: ###############################################################
1617:
1618: =pod
1619:
1.648 raeburn 1620: =item * &csv_translate($text)
1.37 matthew 1621:
1.185 www 1622: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1623: format.
1624:
1625: =cut
1626:
1.180 matthew 1627: ###############################################################
1628: ###############################################################
1.37 matthew 1629: sub csv_translate {
1630: my $text = shift;
1631: $text =~ s/\"/\"\"/g;
1.209 albertel 1632: $text =~ s/\n/ /g;
1.37 matthew 1633: return $text;
1634: }
1.180 matthew 1635:
1636: ###############################################################
1637: ###############################################################
1638:
1639: =pod
1640:
1.648 raeburn 1641: =item * &define_excel_formats()
1.180 matthew 1642:
1643: Define some commonly used Excel cell formats.
1644:
1645: Currently supported formats:
1646:
1647: =over 4
1648:
1649: =item header
1650:
1651: =item bold
1652:
1653: =item h1
1654:
1655: =item h2
1656:
1657: =item h3
1658:
1.256 matthew 1659: =item h4
1660:
1661: =item i
1662:
1.180 matthew 1663: =item date
1664:
1665: =back
1666:
1667: Inputs: $workbook
1668:
1669: Returns: $format, a hash reference.
1670:
1671: =cut
1672:
1673: ###############################################################
1674: ###############################################################
1675: sub define_excel_formats {
1676: my ($workbook) = @_;
1677: my $format;
1678: $format->{'header'} = $workbook->add_format(bold => 1,
1679: bottom => 1,
1680: align => 'center');
1681: $format->{'bold'} = $workbook->add_format(bold=>1);
1682: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1683: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1684: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1685: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1686: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1687: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1688: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1689: return $format;
1690: }
1691:
1692: ###############################################################
1693: ###############################################################
1.113 bowersj2 1694:
1695: =pod
1696:
1.648 raeburn 1697: =item * &create_workbook()
1.255 matthew 1698:
1699: Create an Excel worksheet. If it fails, output message on the
1700: request object and return undefs.
1701:
1702: Inputs: Apache request object
1703:
1704: Returns (undef) on failure,
1705: Excel worksheet object, scalar with filename, and formats
1706: from &Apache::loncommon::define_excel_formats on success
1707:
1708: =cut
1709:
1710: ###############################################################
1711: ###############################################################
1712: sub create_workbook {
1713: my ($r) = @_;
1714: #
1715: # Create the excel spreadsheet
1716: my $filename = '/prtspool/'.
1.258 albertel 1717: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1718: time.'_'.rand(1000000000).'.xls';
1719: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1720: if (! defined($workbook)) {
1721: $r->log_error("Error creating excel spreadsheet $filename: $!");
1722: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1723: "This error has been logged. ".
1724: "Please alert your LON-CAPA administrator").
1725: '</p>');
1726: return (undef);
1727: }
1728: #
1729: $workbook->set_tempdir('/home/httpd/perl/tmp');
1730: #
1731: my $format = &Apache::loncommon::define_excel_formats($workbook);
1732: return ($workbook,$filename,$format);
1733: }
1734:
1735: ###############################################################
1736: ###############################################################
1737:
1738: =pod
1739:
1.648 raeburn 1740: =item * &create_text_file()
1.113 bowersj2 1741:
1.542 raeburn 1742: Create a file to write to and eventually make available to the user.
1.256 matthew 1743: If file creation fails, outputs an error message on the request object and
1744: return undefs.
1.113 bowersj2 1745:
1.256 matthew 1746: Inputs: Apache request object, and file suffix
1.113 bowersj2 1747:
1.256 matthew 1748: Returns (undef) on failure,
1749: Filehandle and filename on success.
1.113 bowersj2 1750:
1751: =cut
1752:
1.256 matthew 1753: ###############################################################
1754: ###############################################################
1755: sub create_text_file {
1756: my ($r,$suffix) = @_;
1757: if (! defined($suffix)) { $suffix = 'txt'; };
1758: my $fh;
1759: my $filename = '/prtspool/'.
1.258 albertel 1760: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1761: time.'_'.rand(1000000000).'.'.$suffix;
1762: $fh = Apache::File->new('>/home/httpd'.$filename);
1763: if (! defined($fh)) {
1764: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1765: $r->print(&mt('Problems occurred in creating the output file. '
1766: .'This error has been logged. '
1767: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1768: }
1.256 matthew 1769: return ($fh,$filename)
1.113 bowersj2 1770: }
1771:
1772:
1.256 matthew 1773: =pod
1.113 bowersj2 1774:
1775: =back
1776:
1777: =cut
1.37 matthew 1778:
1779: ###############################################################
1.33 matthew 1780: ## Home server <option> list generating code ##
1781: ###############################################################
1.35 matthew 1782:
1.169 www 1783: # ------------------------------------------
1784:
1785: sub domain_select {
1786: my ($name,$value,$multiple)=@_;
1787: my %domains=map {
1.514 albertel 1788: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1789: } &Apache::lonnet::all_domains();
1.169 www 1790: if ($multiple) {
1791: $domains{''}=&mt('Any domain');
1.550 albertel 1792: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1793: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1794: } else {
1.550 albertel 1795: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1796: return &select_form($name,$value,%domains);
1797: }
1798: }
1799:
1.282 albertel 1800: #-------------------------------------------
1801:
1802: =pod
1803:
1.519 raeburn 1804: =head1 Routines for form select boxes
1805:
1806: =over 4
1807:
1.648 raeburn 1808: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1809:
1810: Returns a string containing a <select> element int multiple mode
1811:
1812:
1813: Args:
1814: $name - name of the <select> element
1.506 raeburn 1815: $value - scalar or array ref of values that should already be selected
1.282 albertel 1816: $size - number of rows long the select element is
1.283 albertel 1817: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1818: (shown text should already have been &mt())
1.506 raeburn 1819: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1820:
1.282 albertel 1821: =cut
1822:
1823: #-------------------------------------------
1.169 www 1824: sub multiple_select_form {
1.284 albertel 1825: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1826: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1827: my $output='';
1.191 matthew 1828: if (! defined($size)) {
1829: $size = 4;
1.283 albertel 1830: if (scalar(keys(%$hash))<4) {
1831: $size = scalar(keys(%$hash));
1.191 matthew 1832: }
1833: }
1.734 bisitz 1834: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1835: my @order;
1.506 raeburn 1836: if (ref($order) eq 'ARRAY') {
1837: @order = @{$order};
1838: } else {
1839: @order = sort(keys(%$hash));
1.501 banghart 1840: }
1841: if (exists($$hash{'select_form_order'})) {
1842: @order = @{$$hash{'select_form_order'}};
1843: }
1844:
1.284 albertel 1845: foreach my $key (@order) {
1.356 albertel 1846: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1847: $output.='selected="selected" ' if ($selected{$key});
1848: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1849: }
1850: $output.="</select>\n";
1851: return $output;
1852: }
1853:
1.88 www 1854: #-------------------------------------------
1855:
1856: =pod
1857:
1.648 raeburn 1858: =item * &select_form($defdom,$name,%hash)
1.88 www 1859:
1860: Returns a string containing a <select name='$name' size='1'> form to
1861: allow a user to select options from a hash option_name => displayed text.
1862: See lonrights.pm for an example invocation and use.
1863:
1864: =cut
1865:
1866: #-------------------------------------------
1867: sub select_form {
1868: my ($def,$name,%hash) = @_;
1869: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1870: my @keys;
1871: if (exists($hash{'select_form_order'})) {
1872: @keys=@{$hash{'select_form_order'}};
1873: } else {
1874: @keys=sort(keys(%hash));
1875: }
1.356 albertel 1876: foreach my $key (@keys) {
1877: $selectform.=
1878: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1879: ($key eq $def ? 'selected="selected" ' : '').
1880: ">".&mt($hash{$key})."</option>\n";
1.88 www 1881: }
1882: $selectform.="</select>";
1883: return $selectform;
1884: }
1885:
1.475 www 1886: # For display filters
1887:
1888: sub display_filter {
1889: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1890: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1891: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1892: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1893: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1894: '</label></span> <span class="LC_nobreak">'.
1.475 www 1895: &mt('Filter [_1]',
1.477 www 1896: &select_form($env{'form.displayfilter'},
1897: 'displayfilter',
1898: ('currentfolder' => 'Current folder/page',
1899: 'containing' => 'Containing phrase',
1900: 'none' => 'None'))).
1.714 bisitz 1901: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1902: }
1903:
1.167 www 1904: sub gradeleveldescription {
1905: my $gradelevel=shift;
1906: my %gradelevels=(0 => 'Not specified',
1907: 1 => 'Grade 1',
1908: 2 => 'Grade 2',
1909: 3 => 'Grade 3',
1910: 4 => 'Grade 4',
1911: 5 => 'Grade 5',
1912: 6 => 'Grade 6',
1913: 7 => 'Grade 7',
1914: 8 => 'Grade 8',
1915: 9 => 'Grade 9',
1916: 10 => 'Grade 10',
1917: 11 => 'Grade 11',
1918: 12 => 'Grade 12',
1919: 13 => 'Grade 13',
1920: 14 => '100 Level',
1921: 15 => '200 Level',
1922: 16 => '300 Level',
1923: 17 => '400 Level',
1924: 18 => 'Graduate Level');
1925: return &mt($gradelevels{$gradelevel});
1926: }
1927:
1.163 www 1928: sub select_level_form {
1929: my ($deflevel,$name)=@_;
1930: unless ($deflevel) { $deflevel=0; }
1.167 www 1931: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1932: for (my $i=0; $i<=18; $i++) {
1933: $selectform.="<option value=\"$i\" ".
1.253 albertel 1934: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1935: ">".&gradeleveldescription($i)."</option>\n";
1936: }
1937: $selectform.="</select>";
1938: return $selectform;
1.163 www 1939: }
1.167 www 1940:
1.35 matthew 1941: #-------------------------------------------
1942:
1.45 matthew 1943: =pod
1944:
1.873 raeburn 1945: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35 matthew 1946:
1947: Returns a string containing a <select name='$name' size='1'> form to
1948: allow a user to select the domain to preform an operation in.
1949: See loncreateuser.pm for an example invocation and use.
1950:
1.90 www 1951: If the $includeempty flag is set, it also includes an empty choice ("no domain
1952: selected");
1953:
1.743 raeburn 1954: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1955:
1.872 raeburn 1956: The optional $onchange argumnet specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
1.563 raeburn 1957:
1.35 matthew 1958: =cut
1959:
1960: #-------------------------------------------
1.34 matthew 1961: sub select_dom_form {
1.872 raeburn 1962: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
1963: if ($onchange) {
1.874 raeburn 1964: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1965: }
1.550 albertel 1966: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
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.356 albertel 3401: foreach my $key (sort(keys(%lasthash))) {
3402: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3403: if ($#parts > 0) {
1.31 albertel 3404: my $data=$parts[-1];
3405: pop(@parts);
1.596 albertel 3406: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3407: } else {
1.41 ng 3408: if ($#parts == 0) {
3409: $prevattempts.='<th>'.$parts[0].'</th>';
3410: } else {
3411: $prevattempts.='<th>'.$ign.'</th>';
3412: }
1.31 albertel 3413: }
1.16 harris41 3414: }
1.596 albertel 3415: $prevattempts.=&end_data_table_header_row();
1.40 ng 3416: if ($getattempt eq '') {
3417: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3418: $prevattempts.=&start_data_table_row().
3419: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3420: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3421: my $value = &format_previous_attempt_value($key,
3422: $returnhash{$version.':'.$key});
3423: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3424: }
1.596 albertel 3425: $prevattempts.=&end_data_table_row();
1.40 ng 3426: }
1.1 albertel 3427: }
1.596 albertel 3428: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3429: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3430: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3431: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3432: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3433: }
1.596 albertel 3434: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3435: } else {
1.596 albertel 3436: $prevattempts=
3437: &start_data_table().&start_data_table_row().
3438: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3439: &end_data_table_row().&end_data_table();
1.1 albertel 3440: }
3441: } else {
1.596 albertel 3442: $prevattempts=
3443: &start_data_table().&start_data_table_row().
3444: '<td>'.&mt('No data.').'</td>'.
3445: &end_data_table_row().&end_data_table();
1.1 albertel 3446: }
1.10 albertel 3447: }
3448:
1.581 albertel 3449: sub format_previous_attempt_value {
3450: my ($key,$value) = @_;
3451: if ($key =~ /timestamp/) {
3452: $value = &Apache::lonlocal::locallocaltime($value);
3453: } elsif (ref($value) eq 'ARRAY') {
3454: $value = '('.join(', ', @{ $value }).')';
3455: } else {
3456: $value = &unescape($value);
3457: }
3458: return $value;
3459: }
3460:
3461:
1.107 albertel 3462: sub relative_to_absolute {
3463: my ($url,$output)=@_;
3464: my $parser=HTML::TokeParser->new(\$output);
3465: my $token;
3466: my $thisdir=$url;
3467: my @rlinks=();
3468: while ($token=$parser->get_token) {
3469: if ($token->[0] eq 'S') {
3470: if ($token->[1] eq 'a') {
3471: if ($token->[2]->{'href'}) {
3472: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3473: }
3474: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3475: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3476: } elsif ($token->[1] eq 'base') {
3477: $thisdir=$token->[2]->{'href'};
3478: }
3479: }
3480: }
3481: $thisdir=~s-/[^/]*$--;
1.356 albertel 3482: foreach my $link (@rlinks) {
1.726 raeburn 3483: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3484: ($link=~/^\//) ||
3485: ($link=~/^javascript:/i) ||
3486: ($link=~/^mailto:/i) ||
3487: ($link=~/^\#/)) {
3488: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3489: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3490: }
3491: }
3492: # -------------------------------------------------- Deal with Applet codebases
3493: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3494: return $output;
3495: }
3496:
1.112 bowersj2 3497: =pod
3498:
1.648 raeburn 3499: =item * &get_student_view()
1.112 bowersj2 3500:
3501: show a snapshot of what student was looking at
3502:
3503: =cut
3504:
1.10 albertel 3505: sub get_student_view {
1.186 albertel 3506: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3507: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3508: my (%form);
1.10 albertel 3509: my @elements=('symb','courseid','domain','username');
3510: foreach my $element (@elements) {
1.186 albertel 3511: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3512: }
1.186 albertel 3513: if (defined($moreenv)) {
3514: %form=(%form,%{$moreenv});
3515: }
1.236 albertel 3516: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3517: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3518: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3519: $userview=~s/\<body[^\>]*\>//gi;
3520: $userview=~s/\<\/body\>//gi;
3521: $userview=~s/\<html\>//gi;
3522: $userview=~s/\<\/html\>//gi;
3523: $userview=~s/\<head\>//gi;
3524: $userview=~s/\<\/head\>//gi;
3525: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3526: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3527: if (wantarray) {
3528: return ($userview,$response);
3529: } else {
3530: return $userview;
3531: }
3532: }
3533:
3534: sub get_student_view_with_retries {
3535: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3536:
3537: my $ok = 0; # True if we got a good response.
3538: my $content;
3539: my $response;
3540:
3541: # Try to get the student_view done. within the retries count:
3542:
3543: do {
3544: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3545: $ok = $response->is_success;
3546: if (!$ok) {
3547: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3548: }
3549: $retries--;
3550: } while (!$ok && ($retries > 0));
3551:
3552: if (!$ok) {
3553: $content = ''; # On error return an empty content.
3554: }
1.651 www 3555: if (wantarray) {
3556: return ($content, $response);
3557: } else {
3558: return $content;
3559: }
1.11 albertel 3560: }
3561:
1.112 bowersj2 3562: =pod
3563:
1.648 raeburn 3564: =item * &get_student_answers()
1.112 bowersj2 3565:
3566: show a snapshot of how student was answering problem
3567:
3568: =cut
3569:
1.11 albertel 3570: sub get_student_answers {
1.100 sakharuk 3571: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3572: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3573: my (%moreenv);
1.11 albertel 3574: my @elements=('symb','courseid','domain','username');
3575: foreach my $element (@elements) {
1.186 albertel 3576: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3577: }
1.186 albertel 3578: $moreenv{'grade_target'}='answer';
3579: %moreenv=(%form,%moreenv);
1.497 raeburn 3580: $feedurl = &Apache::lonnet::clutter($feedurl);
3581: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3582: return $userview;
1.1 albertel 3583: }
1.116 albertel 3584:
3585: =pod
3586:
3587: =item * &submlink()
3588:
1.242 albertel 3589: Inputs: $text $uname $udom $symb $target
1.116 albertel 3590:
3591: Returns: A link to grades.pm such as to see the SUBM view of a student
3592:
3593: =cut
3594:
3595: ###############################################
3596: sub submlink {
1.242 albertel 3597: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3598: if (!($uname && $udom)) {
3599: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3600: &Apache::lonnet::whichuser($symb);
1.116 albertel 3601: if (!$symb) { $symb=$cursymb; }
3602: }
1.254 matthew 3603: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3604: $symb=&escape($symb);
1.242 albertel 3605: if ($target) { $target="target=\"$target\""; }
3606: return '<a href="/adm/grades?&command=submission&'.
3607: 'symb='.$symb.'&student='.$uname.
3608: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3609: }
3610: ##############################################
3611:
3612: =pod
3613:
3614: =item * &pgrdlink()
3615:
3616: Inputs: $text $uname $udom $symb $target
3617:
3618: Returns: A link to grades.pm such as to see the PGRD view of a student
3619:
3620: =cut
3621:
3622: ###############################################
3623: sub pgrdlink {
3624: my $link=&submlink(@_);
3625: $link=~s/(&command=submission)/$1&showgrading=yes/;
3626: return $link;
3627: }
3628: ##############################################
3629:
3630: =pod
3631:
3632: =item * &pprmlink()
3633:
3634: Inputs: $text $uname $udom $symb $target
3635:
3636: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3637: student and a specific resource
1.242 albertel 3638:
3639: =cut
3640:
3641: ###############################################
3642: sub pprmlink {
3643: my ($text,$uname,$udom,$symb,$target)=@_;
3644: if (!($uname && $udom)) {
3645: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3646: &Apache::lonnet::whichuser($symb);
1.242 albertel 3647: if (!$symb) { $symb=$cursymb; }
3648: }
1.254 matthew 3649: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3650: $symb=&escape($symb);
1.242 albertel 3651: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3652: return '<a href="/adm/parmset?command=set&'.
3653: 'symb='.$symb.'&uname='.$uname.
3654: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3655: }
3656: ##############################################
1.37 matthew 3657:
1.112 bowersj2 3658: =pod
3659:
3660: =back
3661:
3662: =cut
3663:
1.37 matthew 3664: ###############################################
1.51 www 3665:
3666:
3667: sub timehash {
1.687 raeburn 3668: my ($thistime) = @_;
3669: my $timezone = &Apache::lonlocal::gettimezone();
3670: my $dt = DateTime->from_epoch(epoch => $thistime)
3671: ->set_time_zone($timezone);
3672: my $wday = $dt->day_of_week();
3673: if ($wday == 7) { $wday = 0; }
3674: return ( 'second' => $dt->second(),
3675: 'minute' => $dt->minute(),
3676: 'hour' => $dt->hour(),
3677: 'day' => $dt->day_of_month(),
3678: 'month' => $dt->month(),
3679: 'year' => $dt->year(),
3680: 'weekday' => $wday,
3681: 'dayyear' => $dt->day_of_year(),
3682: 'dlsav' => $dt->is_dst() );
1.51 www 3683: }
3684:
1.370 www 3685: sub utc_string {
3686: my ($date)=@_;
1.371 www 3687: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3688: }
3689:
1.51 www 3690: sub maketime {
3691: my %th=@_;
1.687 raeburn 3692: my ($epoch_time,$timezone,$dt);
3693: $timezone = &Apache::lonlocal::gettimezone();
3694: eval {
3695: $dt = DateTime->new( year => $th{'year'},
3696: month => $th{'month'},
3697: day => $th{'day'},
3698: hour => $th{'hour'},
3699: minute => $th{'minute'},
3700: second => $th{'second'},
3701: time_zone => $timezone,
3702: );
3703: };
3704: if (!$@) {
3705: $epoch_time = $dt->epoch;
3706: if ($epoch_time) {
3707: return $epoch_time;
3708: }
3709: }
1.51 www 3710: return POSIX::mktime(
3711: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3712: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3713: }
3714:
3715: #########################################
1.51 www 3716:
3717: sub findallcourses {
1.482 raeburn 3718: my ($roles,$uname,$udom) = @_;
1.355 albertel 3719: my %roles;
3720: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3721: my %courses;
1.51 www 3722: my $now=time;
1.482 raeburn 3723: if (!defined($uname)) {
3724: $uname = $env{'user.name'};
3725: }
3726: if (!defined($udom)) {
3727: $udom = $env{'user.domain'};
3728: }
3729: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3730: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3731: if (!%roles) {
3732: %roles = (
3733: cc => 1,
1.907 raeburn 3734: co => 1,
1.482 raeburn 3735: in => 1,
3736: ep => 1,
3737: ta => 1,
3738: cr => 1,
3739: st => 1,
3740: );
3741: }
3742: foreach my $entry (keys(%roleshash)) {
3743: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3744: if ($trole =~ /^cr/) {
3745: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3746: } else {
3747: next if (!exists($roles{$trole}));
3748: }
3749: if ($tend) {
3750: next if ($tend < $now);
3751: }
3752: if ($tstart) {
3753: next if ($tstart > $now);
3754: }
3755: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3756: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3757: if ($secpart eq '') {
3758: ($cnum,$role) = split(/_/,$cnumpart);
3759: $sec = 'none';
3760: $realsec = '';
3761: } else {
3762: $cnum = $cnumpart;
3763: ($sec,$role) = split(/_/,$secpart);
3764: $realsec = $sec;
1.490 raeburn 3765: }
1.482 raeburn 3766: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3767: }
3768: } else {
3769: foreach my $key (keys(%env)) {
1.483 albertel 3770: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3771: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3772: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3773: next if ($role eq 'ca' || $role eq 'aa');
3774: next if (%roles && !exists($roles{$role}));
3775: my ($starttime,$endtime)=split(/\./,$env{$key});
3776: my $active=1;
3777: if ($starttime) {
3778: if ($now<$starttime) { $active=0; }
3779: }
3780: if ($endtime) {
3781: if ($now>$endtime) { $active=0; }
3782: }
3783: if ($active) {
3784: if ($sec eq '') {
3785: $sec = 'none';
3786: }
3787: $courses{$cdom.'_'.$cnum}{$sec} =
3788: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3789: }
3790: }
1.51 www 3791: }
3792: }
1.474 raeburn 3793: return %courses;
1.51 www 3794: }
1.37 matthew 3795:
1.54 www 3796: ###############################################
1.474 raeburn 3797:
3798: sub blockcheck {
1.482 raeburn 3799: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3800:
3801: if (!defined($udom)) {
3802: $udom = $env{'user.domain'};
3803: }
3804: if (!defined($uname)) {
3805: $uname = $env{'user.name'};
3806: }
3807:
3808: # If uname and udom are for a course, check for blocks in the course.
3809:
3810: if (&Apache::lonnet::is_course($udom,$uname)) {
3811: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3812: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3813: return ($startblock,$endblock);
3814: }
1.474 raeburn 3815:
1.502 raeburn 3816: my $startblock = 0;
3817: my $endblock = 0;
1.482 raeburn 3818: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3819:
1.490 raeburn 3820: # If uname is for a user, and activity is course-specific, i.e.,
3821: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3822:
1.490 raeburn 3823: if (($activity eq 'boards' || $activity eq 'chat' ||
3824: $activity eq 'groups') && ($env{'request.course.id'})) {
3825: foreach my $key (keys(%live_courses)) {
3826: if ($key ne $env{'request.course.id'}) {
3827: delete($live_courses{$key});
3828: }
3829: }
3830: }
3831:
3832: my $otheruser = 0;
3833: my %own_courses;
3834: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3835: # Resource belongs to user other than current user.
3836: $otheruser = 1;
3837: # Gather courses for current user
3838: %own_courses =
3839: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3840: }
3841:
3842: # Gather active course roles - course coordinator, instructor,
3843: # exam proctor, ta, student, or custom role.
1.474 raeburn 3844:
3845: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3846: my ($cdom,$cnum);
3847: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3848: $cdom = $env{'course.'.$course.'.domain'};
3849: $cnum = $env{'course.'.$course.'.num'};
3850: } else {
1.490 raeburn 3851: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3852: }
3853: my $no_ownblock = 0;
3854: my $no_userblock = 0;
1.533 raeburn 3855: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3856: # Check if current user has 'evb' priv for this
3857: if (defined($own_courses{$course})) {
3858: foreach my $sec (keys(%{$own_courses{$course}})) {
3859: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3860: if ($sec ne 'none') {
3861: $checkrole .= '/'.$sec;
3862: }
3863: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3864: $no_ownblock = 1;
3865: last;
3866: }
3867: }
3868: }
3869: # if they have 'evb' priv and are currently not playing student
3870: next if (($no_ownblock) &&
3871: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3872: }
1.474 raeburn 3873: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3874: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3875: if ($sec ne 'none') {
1.482 raeburn 3876: $checkrole .= '/'.$sec;
1.474 raeburn 3877: }
1.490 raeburn 3878: if ($otheruser) {
3879: # Resource belongs to user other than current user.
3880: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3881: my ($trole,$tdom,$tnum,$tsec);
3882: my $entry = $live_courses{$course}{$sec};
3883: if ($entry =~ /^cr/) {
3884: ($trole,$tdom,$tnum,$tsec) =
3885: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3886: } else {
3887: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3888: }
3889: my ($spec,$area,$trest,%allroles,%userroles);
3890: $area = '/'.$tdom.'/'.$tnum;
3891: $trest = $tnum;
3892: if ($tsec ne '') {
3893: $area .= '/'.$tsec;
3894: $trest .= '/'.$tsec;
3895: }
3896: $spec = $trole.'.'.$area;
3897: if ($trole =~ /^cr/) {
3898: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3899: $tdom,$spec,$trest,$area);
3900: } else {
3901: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3902: $tdom,$spec,$trest,$area);
3903: }
3904: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3905: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3906: if ($1) {
3907: $no_userblock = 1;
3908: last;
3909: }
3910: }
1.490 raeburn 3911: } else {
3912: # Resource belongs to current user
3913: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3914: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3915: $no_ownblock = 1;
3916: last;
3917: }
1.474 raeburn 3918: }
3919: }
3920: # if they have the evb priv and are currently not playing student
1.482 raeburn 3921: next if (($no_ownblock) &&
1.491 albertel 3922: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3923: next if ($no_userblock);
1.474 raeburn 3924:
1.866 kalberla 3925: # Retrieve blocking times and identity of locker for course
1.490 raeburn 3926: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3927:
3928: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3929: if (($start != 0) &&
3930: (($startblock == 0) || ($startblock > $start))) {
3931: $startblock = $start;
3932: }
3933: if (($end != 0) &&
3934: (($endblock == 0) || ($endblock < $end))) {
3935: $endblock = $end;
3936: }
1.490 raeburn 3937: }
3938: return ($startblock,$endblock);
3939: }
3940:
3941: sub get_blocks {
3942: my ($setters,$activity,$cdom,$cnum) = @_;
3943: my $startblock = 0;
3944: my $endblock = 0;
3945: my $course = $cdom.'_'.$cnum;
3946: $setters->{$course} = {};
3947: $setters->{$course}{'staff'} = [];
3948: $setters->{$course}{'times'} = [];
3949: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3950: foreach my $record (keys(%records)) {
3951: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3952: if ($start <= time && $end >= time) {
3953: my ($staff_name,$staff_dom,$title,$blocks) =
3954: &parse_block_record($records{$record});
3955: if ($blocks->{$activity} eq 'on') {
3956: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3957: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3958: if ( ($startblock == 0) || ($startblock > $start) ) {
3959: $startblock = $start;
1.490 raeburn 3960: }
1.491 albertel 3961: if ( ($endblock == 0) || ($endblock < $end) ) {
3962: $endblock = $end;
1.474 raeburn 3963: }
3964: }
3965: }
3966: }
3967: return ($startblock,$endblock);
3968: }
3969:
3970: sub parse_block_record {
3971: my ($record) = @_;
3972: my ($setuname,$setudom,$title,$blocks);
3973: if (ref($record) eq 'HASH') {
3974: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3975: $title = &unescape($record->{'event'});
3976: $blocks = $record->{'blocks'};
3977: } else {
3978: my @data = split(/:/,$record,3);
3979: if (scalar(@data) eq 2) {
3980: $title = $data[1];
3981: ($setuname,$setudom) = split(/@/,$data[0]);
3982: } else {
3983: ($setuname,$setudom,$title) = @data;
3984: }
3985: $blocks = { 'com' => 'on' };
3986: }
3987: return ($setuname,$setudom,$title,$blocks);
3988: }
3989:
1.854 kalberla 3990: sub blocking_status {
3991: my ($activity,$uname,$udom) = @_;
1.867 kalberla 3992: my %setters;
1.890 droeschl 3993:
3994: # check for active blocking
1.867 kalberla 3995: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 3996:
1.890 droeschl 3997: my $blocked = $startblock && $endblock ? 1 : 0;
3998:
3999: # caller just wants to know whether a block is active
4000: if (!wantarray) { return $blocked; }
4001:
4002: # build a link to a popup window containing the details
4003: my $querystring = "?activity=$activity";
4004: # $uname and $udom decide whose portfolio the user is trying to look at
4005: $querystring .= "&udom=$udom" if $udom;
4006: $querystring .= "&uname=$uname" if $uname;
4007:
4008: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4009: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4010: var options = "width=" + w + ",height=" + h + ",";
4011: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4012: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4013: var newWin = window.open(url, wdwName, options);
4014: newWin.focus();
4015: }
1.890 droeschl 4016: END_MYBLOCK
1.854 kalberla 4017:
1.890 droeschl 4018: $output = Apache::lonhtmlcommon::scripttag($output);
4019:
1.854 kalberla 4020: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4021: my $text = mt('Communication Blocked');
4022:
1.867 kalberla 4023: $output .= <<"END_BLOCK";
4024: <div class='LC_comblock'>
1.869 kalberla 4025: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4026: title='$text'>
4027: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4028: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4029: title='$text'>$text</a>
1.867 kalberla 4030: </div>
4031:
4032: END_BLOCK
1.474 raeburn 4033:
1.854 kalberla 4034: return ($blocked, $output);
4035: }
1.490 raeburn 4036:
1.60 matthew 4037: ###############################################
4038:
1.682 raeburn 4039: sub check_ip_acc {
4040: my ($acc)=@_;
4041: &Apache::lonxml::debug("acc is $acc");
4042: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4043: return 1;
4044: }
4045: my $allowed=0;
4046: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4047:
4048: my $name;
4049: foreach my $pattern (split(',',$acc)) {
4050: $pattern =~ s/^\s*//;
4051: $pattern =~ s/\s*$//;
4052: if ($pattern =~ /\*$/) {
4053: #35.8.*
4054: $pattern=~s/\*//;
4055: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4056: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4057: #35.8.3.[34-56]
4058: my $low=$2;
4059: my $high=$3;
4060: $pattern=$1;
4061: if ($ip =~ /^\Q$pattern\E/) {
4062: my $last=(split(/\./,$ip))[3];
4063: if ($last <=$high && $last >=$low) { $allowed=1; }
4064: }
4065: } elsif ($pattern =~ /^\*/) {
4066: #*.msu.edu
4067: $pattern=~s/\*//;
4068: if (!defined($name)) {
4069: use Socket;
4070: my $netaddr=inet_aton($ip);
4071: ($name)=gethostbyaddr($netaddr,AF_INET);
4072: }
4073: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4074: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4075: #127.0.0.1
4076: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4077: } else {
4078: #some.name.com
4079: if (!defined($name)) {
4080: use Socket;
4081: my $netaddr=inet_aton($ip);
4082: ($name)=gethostbyaddr($netaddr,AF_INET);
4083: }
4084: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4085: }
4086: if ($allowed) { last; }
4087: }
4088: return $allowed;
4089: }
4090:
4091: ###############################################
4092:
1.60 matthew 4093: =pod
4094:
1.112 bowersj2 4095: =head1 Domain Template Functions
4096:
4097: =over 4
4098:
4099: =item * &determinedomain()
1.60 matthew 4100:
4101: Inputs: $domain (usually will be undef)
4102:
1.63 www 4103: Returns: Determines which domain should be used for designs
1.60 matthew 4104:
4105: =cut
1.54 www 4106:
1.60 matthew 4107: ###############################################
1.63 www 4108: sub determinedomain {
4109: my $domain=shift;
1.531 albertel 4110: if (! $domain) {
1.60 matthew 4111: # Determine domain if we have not been given one
1.893 raeburn 4112: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4113: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4114: if ($env{'request.role.domain'}) {
4115: $domain=$env{'request.role.domain'};
1.60 matthew 4116: }
4117: }
1.63 www 4118: return $domain;
4119: }
4120: ###############################################
1.517 raeburn 4121:
1.518 albertel 4122: sub devalidate_domconfig_cache {
4123: my ($udom)=@_;
4124: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4125: }
4126:
4127: # ---------------------- Get domain configuration for a domain
4128: sub get_domainconf {
4129: my ($udom) = @_;
4130: my $cachetime=1800;
4131: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4132: if (defined($cached)) { return %{$result}; }
4133:
4134: my %domconfig = &Apache::lonnet::get_dom('configuration',
4135: ['login','rolecolors'],$udom);
1.632 raeburn 4136: my (%designhash,%legacy);
1.518 albertel 4137: if (keys(%domconfig) > 0) {
4138: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4139: if (keys(%{$domconfig{'login'}})) {
4140: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4141: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4142: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4143: $designhash{$udom.'.login.'.$key.'_'.$img} =
4144: $domconfig{'login'}{$key}{$img};
4145: }
4146: } else {
4147: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4148: }
1.632 raeburn 4149: }
4150: } else {
4151: $legacy{'login'} = 1;
1.518 albertel 4152: }
1.632 raeburn 4153: } else {
4154: $legacy{'login'} = 1;
1.518 albertel 4155: }
4156: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4157: if (keys(%{$domconfig{'rolecolors'}})) {
4158: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4159: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4160: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4161: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4162: }
1.518 albertel 4163: }
4164: }
1.632 raeburn 4165: } else {
4166: $legacy{'rolecolors'} = 1;
1.518 albertel 4167: }
1.632 raeburn 4168: } else {
4169: $legacy{'rolecolors'} = 1;
1.518 albertel 4170: }
1.632 raeburn 4171: if (keys(%legacy) > 0) {
4172: my %legacyhash = &get_legacy_domconf($udom);
4173: foreach my $item (keys(%legacyhash)) {
4174: if ($item =~ /^\Q$udom\E\.login/) {
4175: if ($legacy{'login'}) {
4176: $designhash{$item} = $legacyhash{$item};
4177: }
4178: } else {
4179: if ($legacy{'rolecolors'}) {
4180: $designhash{$item} = $legacyhash{$item};
4181: }
1.518 albertel 4182: }
4183: }
4184: }
1.632 raeburn 4185: } else {
4186: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4187: }
4188: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4189: $cachetime);
4190: return %designhash;
4191: }
4192:
1.632 raeburn 4193: sub get_legacy_domconf {
4194: my ($udom) = @_;
4195: my %legacyhash;
4196: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4197: my $designfile = $designdir.'/'.$udom.'.tab';
4198: if (-e $designfile) {
4199: if ( open (my $fh,"<$designfile") ) {
4200: while (my $line = <$fh>) {
4201: next if ($line =~ /^\#/);
4202: chomp($line);
4203: my ($key,$val)=(split(/\=/,$line));
4204: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4205: }
4206: close($fh);
4207: }
4208: }
4209: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4210: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4211: }
4212: return %legacyhash;
4213: }
4214:
1.63 www 4215: =pod
4216:
1.112 bowersj2 4217: =item * &domainlogo()
1.63 www 4218:
4219: Inputs: $domain (usually will be undef)
4220:
4221: Returns: A link to a domain logo, if the domain logo exists.
4222: If the domain logo does not exist, a description of the domain.
4223:
4224: =cut
1.112 bowersj2 4225:
1.63 www 4226: ###############################################
4227: sub domainlogo {
1.517 raeburn 4228: my $domain = &determinedomain(shift);
1.518 albertel 4229: my %designhash = &get_domainconf($domain);
1.517 raeburn 4230: # See if there is a logo
4231: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4232: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4233: if ($imgsrc =~ m{^/(adm|res)/}) {
4234: if ($imgsrc =~ m{^/res/}) {
4235: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4236: &Apache::lonnet::repcopy($local_name);
4237: }
4238: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4239: }
4240: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4241: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4242: return &Apache::lonnet::domain($domain,'description');
1.59 www 4243: } else {
1.60 matthew 4244: return '';
1.59 www 4245: }
4246: }
1.63 www 4247: ##############################################
4248:
4249: =pod
4250:
1.112 bowersj2 4251: =item * &designparm()
1.63 www 4252:
4253: Inputs: $which parameter; $domain (usually will be undef)
4254:
4255: Returns: value of designparamter $which
4256:
4257: =cut
1.112 bowersj2 4258:
1.397 albertel 4259:
1.400 albertel 4260: ##############################################
1.397 albertel 4261: sub designparm {
4262: my ($which,$domain)=@_;
4263: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4264: return $env{'environment.color.'.$which};
1.96 www 4265: }
1.63 www 4266: $domain=&determinedomain($domain);
1.518 albertel 4267: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4268: my $output;
1.517 raeburn 4269: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4270: $output = $domdesign{$domain.'.'.$which};
1.63 www 4271: } else {
1.520 raeburn 4272: $output = $defaultdesign{$which};
4273: }
4274: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4275: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4276: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4277: if ($output =~ m{^/res/}) {
4278: my $local_name = &Apache::lonnet::filelocation('',$output);
4279: &Apache::lonnet::repcopy($local_name);
4280: }
1.520 raeburn 4281: $output = &lonhttpdurl($output);
4282: }
1.63 www 4283: }
1.520 raeburn 4284: return $output;
1.63 www 4285: }
1.59 www 4286:
1.822 bisitz 4287: ##############################################
4288: =pod
4289:
1.832 bisitz 4290: =item * &authorspace()
4291:
4292: Inputs: ./.
4293:
4294: Returns: Path to the Construction Space of the current user's
4295: accessed author space
4296: The author space will be that of the current user
4297: when accessing the own author space
4298: and that of the co-author/assistent co-author
4299: when accessing the co-author's/assistent co-author's
4300: space
4301:
4302: =cut
4303:
4304: sub authorspace {
4305: my $caname = '';
4306: if ($env{'request.role'} =~ /^ca|^aa/) {
4307: (undef,$caname) =
4308: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4309: } else {
4310: $caname = $env{'user.name'};
4311: }
4312: return '/priv/'.$caname.'/';
4313: }
4314:
4315: ##############################################
4316: =pod
4317:
1.822 bisitz 4318: =item * &head_subbox()
4319:
4320: Inputs: $content (contains HTML code with page functions, etc.)
4321:
4322: Returns: HTML div with $content
4323: To be included in page header
4324:
4325: =cut
4326:
4327: sub head_subbox {
4328: my ($content)=@_;
4329: my $output =
1.844 bisitz 4330: '<div id="LC_head_subbox">'
1.822 bisitz 4331: .$content
4332: .'</div>'
4333: }
4334:
4335: ##############################################
4336: =pod
4337:
4338: =item * &CSTR_pageheader()
4339:
4340: Inputs: ./.
4341:
4342: Returns: HTML div with CSTR path and recent box
4343: To be included on Construction Space pages
4344:
4345: =cut
4346:
4347: sub CSTR_pageheader {
4348: # this is for resources; directories have customtitle, and crumbs
4349: # and select recent are created in lonpubdir.pm
4350: my ($uname,$thisdisfn)=
4351: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4352: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4353: $formaction=~s/\/+/\//g;
4354:
4355: my $parentpath = '';
4356: my $lastitem = '';
4357: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4358: $parentpath = $1;
4359: $lastitem = $2;
4360: } else {
4361: $lastitem = $thisdisfn;
4362: }
4363: return
4364: '<div>'
4365: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4366: .'<b>'.&mt('Construction Space:').'</b> '
4367: .'<form name="dirs" method="post" action="'.$formaction
4368: .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
4369: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
4370: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4371: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4372: .'</form>'
4373: .&Apache::lonmenu::constspaceform()
4374: .'</div>';
4375: }
4376:
1.60 matthew 4377: ###############################################
4378: ###############################################
4379:
4380: =pod
4381:
1.112 bowersj2 4382: =back
4383:
1.549 albertel 4384: =head1 HTML Helpers
1.112 bowersj2 4385:
4386: =over 4
4387:
4388: =item * &bodytag()
1.60 matthew 4389:
4390: Returns a uniform header for LON-CAPA web pages.
4391:
4392: Inputs:
4393:
1.112 bowersj2 4394: =over 4
4395:
4396: =item * $title, A title to be displayed on the page.
4397:
4398: =item * $function, the current role (can be undef).
4399:
4400: =item * $addentries, extra parameters for the <body> tag.
4401:
4402: =item * $bodyonly, if defined, only return the <body> tag.
4403:
4404: =item * $domain, if defined, force a given domain.
4405:
4406: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4407: text interface only)
1.60 matthew 4408:
1.814 bisitz 4409: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4410: navigational links
1.317 albertel 4411:
1.338 albertel 4412: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4413:
1.361 albertel 4414: =item * $no_inline_link, if true and in remote mode, don't show the
4415: 'Switch To Inline Menu' link
4416:
1.460 albertel 4417: =item * $args, optional argument valid values are
4418: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4419: inherit_jsmath -> when creating popup window in a page,
4420: should it have jsmath forced on by the
4421: current page
1.460 albertel 4422:
1.112 bowersj2 4423: =back
4424:
1.60 matthew 4425: Returns: A uniform header for LON-CAPA web pages.
4426: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4427: If $bodyonly is undef or zero, an html string containing a <body> tag and
4428: other decorations will be returned.
4429:
4430: =cut
4431:
1.54 www 4432: sub bodytag {
1.831 bisitz 4433: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816 bisitz 4434: $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339 albertel 4435:
1.460 albertel 4436: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4437:
1.183 matthew 4438: $function = &get_users_function() if (!$function);
1.339 albertel 4439: my $img = &designparm($function.'.img',$domain);
4440: my $font = &designparm($function.'.font',$domain);
4441: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4442:
1.803 bisitz 4443: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4444: 'bgcolor' => $pgbg,
1.339 albertel 4445: 'text' => $font,
4446: 'alink' => &designparm($function.'.alink',$domain),
4447: 'vlink' => &designparm($function.'.vlink',$domain),
4448: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4449: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4450:
1.63 www 4451: # role and realm
1.378 raeburn 4452: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4453: if ($role eq 'ca') {
1.479 albertel 4454: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4455: $realm = &plainname($rname,$rdom);
1.378 raeburn 4456: }
1.55 www 4457: # realm
1.258 albertel 4458: if ($env{'request.course.id'}) {
1.378 raeburn 4459: if ($env{'request.role'} !~ /^cr/) {
4460: $role = &Apache::lonnet::plaintext($role,&course_type());
4461: }
1.898 raeburn 4462: if ($env{'request.course.sec'}) {
4463: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4464: }
1.359 albertel 4465: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4466: } else {
4467: $role = &Apache::lonnet::plaintext($role);
1.54 www 4468: }
1.433 albertel 4469:
1.359 albertel 4470: if (!$realm) { $realm=' '; }
1.55 www 4471: # Set messages
1.60 matthew 4472: my $messages=&domainlogo($domain);
1.330 albertel 4473:
1.438 albertel 4474: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4475:
1.101 www 4476: # construct main body tag
1.359 albertel 4477: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4478: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4479:
1.530 albertel 4480: if ($bodyonly) {
1.60 matthew 4481: return $bodytag;
1.798 tempelho 4482: }
1.359 albertel 4483:
1.410 albertel 4484: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4485: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4486: undef($role);
1.434 albertel 4487: } else {
4488: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4489: }
1.359 albertel 4490:
1.762 bisitz 4491: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4492: #
4493: # Extra info if you are the DC
4494: my $dc_info = '';
4495: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4496: $env{'course.'.$env{'request.course.id'}.
4497: '.domain'}.'/'})) {
4498: my $cid = $env{'request.course.id'};
4499: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4500: $dc_info =~ s/\s+$//;
1.359 albertel 4501: $dc_info = '('.$dc_info.')';
4502: }
4503:
1.898 raeburn 4504: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4505: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4506:
1.837 bisitz 4507: if ($env{'environment.remote'} eq 'off') {
1.359 albertel 4508: # No Remote
1.903 droeschl 4509: if ($no_nav_bar) { return $bodytag; }
4510:
4511: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4512:
4513: # if ($env{'request.state'} eq 'construct') {
4514: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4515: # }
4516:
4517: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4518: <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
1.359 albertel 4519:
1.903 droeschl 4520: if ( $env{'form.inhibitmenu'} eq 'yes'
4521: || $ENV{'REQUEST_URI'} eq '/adm/logout'
4522: || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.359 albertel 4523:
1.903 droeschl 4524: return $bodytag;
4525: }
1.894 droeschl 4526:
1.903 droeschl 4527: $bodytag .= Apache::lonhtmlcommon::scripttag(
4528: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4529:
1.903 droeschl 4530: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4531:
1.903 droeschl 4532: #don't show menus for public users
4533: if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
4534: $bodytag .= Apache::lonmenu::secondary_menu();
4535: $bodytag .= Apache::lonmenu::serverform();
4536: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4537: $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
4538: }else{
4539: # this is to seperate menu from content when there's no secondary
4540: # menu. Especially needed for public accessible ressources.
4541: $bodytag .= '<hr style="clear:both" />';
4542: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4543: }
1.903 droeschl 4544:
4545: #SD testing
4546: #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
1.235 raeburn 4547: return $bodytag;
1.94 www 4548: }
1.95 www 4549:
1.93 www 4550: #
1.95 www 4551: # Top frame rendering, Remote is up
1.93 www 4552: #
1.359 albertel 4553:
1.517 raeburn 4554: my $imgsrc = $img;
4555: if ($img =~ /^\/adm/) {
1.575 albertel 4556: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4557: }
4558: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4559:
1.305 www 4560: # Explicit link to get inline menu
1.361 albertel 4561: my $menu= ($no_inline_link?''
1.883 droeschl 4562: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.853 droeschl 4563: $bodytag .= qq|<div id="LC_nav_bar">$name $role
4564: <em>$realm</em> $dc_info </div>
1.897 wenzelju 4565: <ol class="LC_primary_menu LC_right">
1.853 droeschl 4566: <li>$menu</li>
4567: </ol>| unless $env{'form.inhibitmenu'};
1.245 matthew 4568: #
1.94 www 4569: return(<<ENDBODY);
1.60 matthew 4570: $bodytag
1.359 albertel 4571: <table id="LC_title_bar" class="LC_with_remote">
1.791 tempelho 4572: <tr><td>$upperleft</td>
4573: <td>$messages </td>
1.54 www 4574: </tr>
1.359 albertel 4575: <tr><td>$titleinfo $dc_info $menu</td>
1.368 albertel 4576: </tr>
1.356 albertel 4577: </table>
1.54 www 4578: ENDBODY
1.182 matthew 4579: }
4580:
1.330 albertel 4581: sub make_attr_string {
4582: my ($register,$attr_ref) = @_;
4583:
4584: if ($attr_ref && !ref($attr_ref)) {
4585: die("addentries Must be a hash ref ".
4586: join(':',caller(1))." ".
4587: join(':',caller(0))." ");
4588: }
4589:
4590: if ($register) {
1.339 albertel 4591: my ($on_load,$on_unload);
4592: foreach my $key (keys(%{$attr_ref})) {
4593: if (lc($key) eq 'onload') {
4594: $on_load.=$attr_ref->{$key}.';';
4595: delete($attr_ref->{$key});
4596:
4597: } elsif (lc($key) eq 'onunload') {
4598: $on_unload.=$attr_ref->{$key}.';';
4599: delete($attr_ref->{$key});
4600: }
4601: }
4602: $attr_ref->{'onload'} =
4603: &Apache::lonmenu::loadevents(). $on_load;
4604: $attr_ref->{'onunload'}=
4605: &Apache::lonmenu::unloadevents().$on_unload;
4606: }
4607:
4608: # Accessibility font enhance
4609: if ($env{'browser.fontenhance'} eq 'on') {
4610: my $style;
4611: foreach my $key (keys(%{$attr_ref})) {
4612: if (lc($key) eq 'style') {
4613: $style.=$attr_ref->{$key}.';';
4614: delete($attr_ref->{$key});
4615: }
4616: }
4617: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4618: }
1.339 albertel 4619:
1.330 albertel 4620: my $attr_string;
4621: foreach my $attr (keys(%$attr_ref)) {
4622: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4623: }
4624: return $attr_string;
4625: }
4626:
4627:
1.182 matthew 4628: ###############################################
1.251 albertel 4629: ###############################################
4630:
4631: =pod
4632:
4633: =item * &endbodytag()
4634:
4635: Returns a uniform footer for LON-CAPA web pages.
4636:
1.635 raeburn 4637: Inputs: 1 - optional reference to an args hash
4638: If in the hash, key for noredirectlink has a value which evaluates to true,
4639: a 'Continue' link is not displayed if the page contains an
4640: internal redirect in the <head></head> section,
4641: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4642:
4643: =cut
4644:
4645: sub endbodytag {
1.635 raeburn 4646: my ($args) = @_;
1.251 albertel 4647: my $endbodytag='</body>';
1.269 albertel 4648: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4649: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4650: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4651: $endbodytag=
4652: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4653: &mt('Continue').'</a>'.
4654: $endbodytag;
4655: }
1.315 albertel 4656: }
1.251 albertel 4657: return $endbodytag;
4658: }
4659:
1.352 albertel 4660: =pod
4661:
4662: =item * &standard_css()
4663:
4664: Returns a style sheet
4665:
4666: Inputs: (all optional)
4667: domain -> force to color decorate a page for a specific
4668: domain
4669: function -> force usage of a specific rolish color scheme
4670: bgcolor -> override the default page bgcolor
4671:
4672: =cut
4673:
1.343 albertel 4674: sub standard_css {
1.345 albertel 4675: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4676: $function = &get_users_function() if (!$function);
4677: my $img = &designparm($function.'.img', $domain);
4678: my $tabbg = &designparm($function.'.tabbg', $domain);
4679: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4680: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4681: #second colour for later usage
1.345 albertel 4682: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4683: my $pgbg_or_bgcolor =
4684: $bgcolor ||
1.352 albertel 4685: &designparm($function.'.pgbg', $domain);
1.382 albertel 4686: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4687: my $alink = &designparm($function.'.alink', $domain);
4688: my $vlink = &designparm($function.'.vlink', $domain);
4689: my $link = &designparm($function.'.link', $domain);
4690:
1.704 muellerd 4691: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4692: my $bgcol = &designparm('login.bgcol',$domain);
4693: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4694:
1.602 albertel 4695: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4696: my $mono = 'monospace';
1.850 bisitz 4697: my $data_table_head = $sidebg;
4698: my $data_table_light = '#FAFAFA';
4699: my $data_table_dark = '#F0F0F0';
1.470 banghart 4700: my $data_table_darker = '#CCCCCC';
1.349 albertel 4701: my $data_table_highlight = '#FFFF00';
1.352 albertel 4702: my $mail_new = '#FFBB77';
4703: my $mail_new_hover = '#DD9955';
4704: my $mail_read = '#BBBB77';
4705: my $mail_read_hover = '#999944';
4706: my $mail_replied = '#AAAA88';
4707: my $mail_replied_hover = '#888855';
4708: my $mail_other = '#99BBBB';
4709: my $mail_other_hover = '#669999';
1.391 albertel 4710: my $table_header = '#DDDDDD';
1.489 raeburn 4711: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4712: my $lg_border_color = '#C8C8C8';
1.392 albertel 4713:
1.608 albertel 4714: my $border = ($env{'browser.type'} eq 'explorer' ||
1.803 bisitz 4715: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4716: : '0 3px 0 4px';
1.448 albertel 4717:
1.523 albertel 4718:
1.343 albertel 4719: return <<END;
1.795 www 4720: body {
4721: font-family: $sans;
4722: line-height:130%;
4723: font-size:0.83em;
4724: color:$font;
4725: }
4726:
4727: a:link, a:visited {
4728: font-size:100%;
4729: }
4730:
4731: a:focus {
4732: color: red;
4733: background: yellow
4734: }
1.698 harmsja 4735:
1.795 www 4736: form, .inline {
4737: display: inline;
4738: }
1.721 harmsja 4739:
1.795 www 4740: .LC_right {
4741: text-align:right;
4742: }
4743:
4744: .LC_middle {
4745: vertical-align:middle;
4746: }
1.721 harmsja 4747:
4748: /* just for tests */
1.754 droeschl 4749: .LC_400Box {width:400px; }
1.721 harmsja 4750: /* end */
4751:
1.778 bisitz 4752: .LC_filename {
4753: font-family: $mono;
4754: white-space:pre;
4755: }
4756:
4757: .LC_fileicon {
4758: border: none;
4759: height: 1.3em;
4760: vertical-align: text-bottom;
4761: margin-right: 0.3em;
4762: text-decoration:none;
4763: }
4764:
1.350 albertel 4765: .LC_error {
4766: color: red;
4767: font-size: larger;
4768: }
1.795 www 4769:
1.457 albertel 4770: .LC_warning,
4771: .LC_diff_removed {
1.733 bisitz 4772: color: red;
1.394 albertel 4773: }
1.532 albertel 4774:
4775: .LC_info,
1.457 albertel 4776: .LC_success,
4777: .LC_diff_added {
1.350 albertel 4778: color: green;
4779: }
1.795 www 4780:
1.802 bisitz 4781: div.LC_confirm_box {
4782: background-color: #FAFAFA;
4783: border: 1px solid $lg_border_color;
4784: margin-right: 0;
4785: padding: 5px;
4786: }
4787:
4788: div.LC_confirm_box .LC_error img,
4789: div.LC_confirm_box .LC_success img {
4790: vertical-align: middle;
4791: }
4792:
1.440 albertel 4793: .LC_icon {
1.771 droeschl 4794: border: none;
1.790 droeschl 4795: vertical-align: middle;
1.771 droeschl 4796: }
4797:
1.543 albertel 4798: .LC_docs_spacer {
4799: width: 25px;
4800: height: 1px;
1.771 droeschl 4801: border: none;
1.543 albertel 4802: }
1.346 albertel 4803:
1.532 albertel 4804: .LC_internal_info {
1.735 bisitz 4805: color: #999999;
1.532 albertel 4806: }
4807:
1.794 www 4808: .LC_discussion {
4809: background: $tabbg;
4810: border: 1px solid black;
4811: margin: 2px;
4812: }
4813:
4814: .LC_disc_action_links_bar {
4815: background: $tabbg;
1.803 bisitz 4816: border: none;
1.795 www 4817: margin: 4px;
1.794 www 4818: }
4819:
4820: .LC_disc_action_left {
4821: text-align: left;
4822: }
4823:
4824: .LC_disc_action_right {
4825: text-align: right;
4826: }
4827:
4828: .LC_disc_new_item {
4829: background: white;
4830: border: 2px solid red;
4831: margin: 2px;
4832: }
4833:
4834: .LC_disc_old_item {
4835: background: white;
4836: border: 1px solid black;
4837: margin: 2px;
4838: }
4839:
1.458 albertel 4840: table.LC_pastsubmission {
4841: border: 1px solid black;
4842: margin: 2px;
4843: }
4844:
1.795 www 4845: table#LC_top_nav,
4846: table#LC_menubuttons,
4847: table#LC_nav_location {
1.345 albertel 4848: width: 100%;
4849: background: $pgbg;
1.392 albertel 4850: border: 2px;
1.402 albertel 4851: border-collapse: separate;
1.803 bisitz 4852: padding: 0;
1.345 albertel 4853: }
1.392 albertel 4854:
1.801 tempelho 4855: table#LC_title_bar a {
4856: color: $fontmenu;
4857: }
1.836 bisitz 4858:
1.807 droeschl 4859: table#LC_title_bar {
1.819 tempelho 4860: clear: both;
1.836 bisitz 4861: display: none;
1.807 droeschl 4862: }
4863:
1.795 www 4864: table#LC_title_bar,
4865: table.LC_breadcrumbs,
1.393 albertel 4866: table#LC_title_bar.LC_with_remote {
1.359 albertel 4867: width: 100%;
1.392 albertel 4868: border-color: $pgbg;
4869: border-style: solid;
4870: border-width: $border;
1.379 albertel 4871: background: $pgbg;
1.801 tempelho 4872: color: $fontmenu;
1.392 albertel 4873: border-collapse: collapse;
1.803 bisitz 4874: padding: 0;
1.819 tempelho 4875: margin: 0;
1.359 albertel 4876: }
1.795 www 4877:
1.359 albertel 4878: table#LC_title_bar td {
4879: background: $tabbg;
4880: }
1.795 www 4881:
1.706 harmsja 4882: table#LC_menubuttons img{
1.803 bisitz 4883: border: none;
1.346 albertel 4884: }
1.795 www 4885:
1.345 albertel 4886: table#LC_top_nav td {
4887: background: $tabbg;
1.803 bisitz 4888: border: none;
1.407 albertel 4889: font-size: small;
1.706 harmsja 4890: vertical-align:top;
4891: padding:2px 5px 2px 5px;
1.345 albertel 4892: }
1.795 www 4893:
4894: table#LC_top_nav td a,
4895: div#LC_top_nav a {
1.345 albertel 4896: color: $font;
4897: }
1.795 www 4898:
1.364 albertel 4899: table#LC_top_nav td.LC_top_nav_logo {
4900: background: $tabbg;
1.432 albertel 4901: text-align: left;
1.408 albertel 4902: white-space: nowrap;
1.432 albertel 4903: width: 31px;
1.408 albertel 4904: }
1.795 www 4905:
1.408 albertel 4906: table#LC_top_nav td.LC_top_nav_logo img {
1.803 bisitz 4907: border: none;
1.408 albertel 4908: vertical-align: bottom;
1.364 albertel 4909: }
1.795 www 4910:
1.777 tempelho 4911: table#LC_top_nav td.LC_top_nav_exit,
1.779 bisitz 4912: table#LC_top_nav td.LC_top_nav_help {
1.777 tempelho 4913: width: 2.0em;
4914: }
1.795 www 4915:
1.442 albertel 4916: table#LC_top_nav td.LC_top_nav_login {
4917: width: 4.0em;
4918: text-align: center;
4919: }
1.795 www 4920:
1.842 droeschl 4921: .LC_breadcrumbs_component {
4922: float: right;
4923: margin: 0 1em;
1.357 albertel 4924: }
1.842 droeschl 4925: .LC_breadcrumbs_component img {
4926: vertical-align: middle;
1.777 tempelho 4927: }
1.795 www 4928:
1.383 albertel 4929: td.LC_table_cell_checkbox {
4930: text-align: center;
4931: }
1.795 www 4932:
1.779 bisitz 4933: table#LC_mainmenu td.LC_mainmenu_column {
4934: vertical-align: top;
1.777 tempelho 4935: }
1.522 albertel 4936:
1.795 www 4937: .LC_fontsize_small {
1.705 tempelho 4938: font-size: 70%;
4939: }
4940:
1.844 bisitz 4941: #LC_breadcrumbs {
1.819 tempelho 4942: clear:both;
4943: background: $sidebg;
1.822 bisitz 4944: border-bottom: 1px solid $lg_border_color;
1.904 droeschl 4945: line-height: 2.5em;
4946: /* SD working here
4947: height: 2.5em;
4948: overflow: hidden; */
1.822 bisitz 4949: margin: 0;
1.819 tempelho 4950: padding: 0;
4951: }
1.862 bisitz 4952:
1.839 droeschl 4953: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844 bisitz 4954: #LC_remote #LC_breadcrumbs {
1.839 droeschl 4955: display:none;
4956: }
1.819 tempelho 4957:
1.844 bisitz 4958: #LC_head_subbox {
1.822 bisitz 4959: clear:both;
4960: background: #F8F8F8; /* $sidebg; */
4961: border-bottom: 1px solid $lg_border_color;
4962: margin: 0 0 10px 0;
4963: padding: 5px;
4964: }
4965:
1.795 www 4966: .LC_fontsize_medium {
1.705 tempelho 4967: font-size: 85%;
4968: }
4969:
1.795 www 4970: .LC_fontsize_large {
1.705 tempelho 4971: font-size: 120%;
4972: }
4973:
1.346 albertel 4974: .LC_menubuttons_inline_text {
4975: color: $font;
1.698 harmsja 4976: font-size: 90%;
1.701 harmsja 4977: padding-left:3px;
1.346 albertel 4978: }
4979:
1.526 www 4980: .LC_menubuttons_link {
4981: text-decoration: none;
4982: }
1.795 www 4983:
1.522 albertel 4984: .LC_menubuttons_category {
1.521 www 4985: color: $font;
1.526 www 4986: background: $pgbg;
1.521 www 4987: font-size: larger;
4988: font-weight: bold;
4989: }
4990:
1.346 albertel 4991: td.LC_menubuttons_text {
1.779 bisitz 4992: color: $font;
1.346 albertel 4993: }
1.706 harmsja 4994:
1.346 albertel 4995: .LC_current_location {
4996: background: $tabbg;
4997: }
1.795 www 4998:
1.346 albertel 4999: .LC_new_mail {
1.634 www 5000: background: $tabbg;
1.346 albertel 5001: font-weight: bold;
5002: }
1.347 albertel 5003:
1.795 www 5004: table.LC_data_table,
5005: table.LC_mail_list {
1.347 albertel 5006: border: 1px solid #000000;
1.402 albertel 5007: border-collapse: separate;
1.426 albertel 5008: border-spacing: 1px;
1.610 albertel 5009: background: $pgbg;
1.347 albertel 5010: }
1.795 www 5011:
1.422 albertel 5012: .LC_data_table_dense {
5013: font-size: small;
5014: }
1.795 www 5015:
1.507 raeburn 5016: table.LC_nested_outer {
5017: border: 1px solid #000000;
1.589 raeburn 5018: border-collapse: collapse;
1.803 bisitz 5019: border-spacing: 0;
1.507 raeburn 5020: width: 100%;
5021: }
1.795 www 5022:
1.879 raeburn 5023: table.LC_innerpickbox,
1.507 raeburn 5024: table.LC_nested {
1.803 bisitz 5025: border: none;
1.589 raeburn 5026: border-collapse: collapse;
1.803 bisitz 5027: border-spacing: 0;
1.507 raeburn 5028: width: 100%;
5029: }
1.795 www 5030:
5031: table.LC_data_table tr th,
5032: table.LC_calendar tr th,
5033: table.LC_mail_list tr th,
1.879 raeburn 5034: table.LC_prior_tries tr th,
5035: table.LC_innerpickbox tr th {
1.349 albertel 5036: font-weight: bold;
5037: background-color: $data_table_head;
1.801 tempelho 5038: color:$fontmenu;
1.701 harmsja 5039: font-size:90%;
1.347 albertel 5040: }
1.795 www 5041:
1.879 raeburn 5042: table.LC_innerpickbox tr th,
5043: table.LC_innerpickbox tr td {
5044: vertical-align: top;
5045: }
5046:
1.711 raeburn 5047: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5048: background-color: #CCCCCC;
1.711 raeburn 5049: font-weight: bold;
5050: text-align: left;
5051: }
1.795 www 5052:
1.779 bisitz 5053: table.LC_data_table tr.LC_odd_row > td,
1.809 bisitz 5054: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5055: background-color: $data_table_light;
1.425 albertel 5056: padding: 2px;
1.900 bisitz 5057: vertical-align: top;
1.347 albertel 5058: }
1.795 www 5059:
1.610 albertel 5060: table.LC_data_table tr.LC_even_row > td,
1.809 bisitz 5061: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5062: background-color: $data_table_dark;
1.709 bisitz 5063: padding: 2px;
1.900 bisitz 5064: vertical-align: top;
1.347 albertel 5065: }
1.795 www 5066:
1.425 albertel 5067: table.LC_data_table tr.LC_data_table_highlight td {
5068: background-color: $data_table_darker;
5069: }
1.795 www 5070:
1.639 raeburn 5071: table.LC_data_table tr td.LC_leftcol_header {
5072: background-color: $data_table_head;
5073: font-weight: bold;
5074: }
1.795 www 5075:
1.451 albertel 5076: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5077: table.LC_nested tr.LC_empty_row td {
1.347 albertel 5078: background-color: #FFFFFF;
1.421 albertel 5079: font-weight: bold;
5080: font-style: italic;
5081: text-align: center;
5082: padding: 8px;
1.347 albertel 5083: }
1.795 www 5084:
1.890 droeschl 5085: table.LC_caption {
5086: }
5087:
1.507 raeburn 5088: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5089: padding: 4ex
5090: }
1.795 www 5091:
1.507 raeburn 5092: table.LC_nested_outer tr th {
5093: font-weight: bold;
1.801 tempelho 5094: color:$fontmenu;
1.507 raeburn 5095: background-color: $data_table_head;
1.701 harmsja 5096: font-size: small;
1.507 raeburn 5097: border-bottom: 1px solid #000000;
5098: }
1.795 www 5099:
1.507 raeburn 5100: table.LC_nested_outer tr td.LC_subheader {
5101: background-color: $data_table_head;
5102: font-weight: bold;
5103: font-size: small;
5104: border-bottom: 1px solid #000000;
5105: text-align: right;
1.451 albertel 5106: }
1.795 www 5107:
1.507 raeburn 5108: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5109: background-color: #CCCCCC;
1.451 albertel 5110: font-weight: bold;
5111: font-size: small;
1.507 raeburn 5112: text-align: center;
5113: }
1.795 www 5114:
1.589 raeburn 5115: table.LC_nested tr.LC_info_row td.LC_left_item,
5116: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5117: text-align: left;
1.451 albertel 5118: }
1.795 www 5119:
1.507 raeburn 5120: table.LC_nested td {
1.735 bisitz 5121: background-color: #FFFFFF;
1.451 albertel 5122: font-size: small;
1.507 raeburn 5123: }
1.795 www 5124:
1.507 raeburn 5125: table.LC_nested_outer tr th.LC_right_item,
5126: table.LC_nested tr.LC_info_row td.LC_right_item,
5127: table.LC_nested tr.LC_odd_row td.LC_right_item,
5128: table.LC_nested tr td.LC_right_item {
1.451 albertel 5129: text-align: right;
5130: }
5131:
1.507 raeburn 5132: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5133: background-color: #EEEEEE;
1.451 albertel 5134: }
5135:
1.473 raeburn 5136: table.LC_createuser {
5137: }
5138:
5139: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5140: font-size: small;
1.473 raeburn 5141: }
5142:
5143: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5144: background-color: #CCCCCC;
1.473 raeburn 5145: font-weight: bold;
5146: text-align: center;
5147: }
5148:
1.349 albertel 5149: table.LC_calendar {
5150: border: 1px solid #000000;
5151: border-collapse: collapse;
5152: }
1.795 www 5153:
1.349 albertel 5154: table.LC_calendar_pickdate {
5155: font-size: xx-small;
5156: }
1.795 www 5157:
1.349 albertel 5158: table.LC_calendar tr td {
5159: border: 1px solid #000000;
5160: vertical-align: top;
5161: }
1.795 www 5162:
1.349 albertel 5163: table.LC_calendar tr td.LC_calendar_day_empty {
5164: background-color: $data_table_dark;
5165: }
1.795 www 5166:
1.779 bisitz 5167: table.LC_calendar tr td.LC_calendar_day_current {
5168: background-color: $data_table_highlight;
1.777 tempelho 5169: }
1.795 www 5170:
1.349 albertel 5171: table.LC_mail_list tr.LC_mail_new {
5172: background-color: $mail_new;
5173: }
1.795 www 5174:
1.349 albertel 5175: table.LC_mail_list tr.LC_mail_new:hover {
5176: background-color: $mail_new_hover;
5177: }
1.795 www 5178:
5179: table.LC_mail_list tr.LC_mail_even {
1.777 tempelho 5180: }
1.795 www 5181:
5182: table.LC_mail_list tr.LC_mail_odd {
1.777 tempelho 5183: }
1.795 www 5184:
1.349 albertel 5185: table.LC_mail_list tr.LC_mail_read {
5186: background-color: $mail_read;
5187: }
1.795 www 5188:
1.349 albertel 5189: table.LC_mail_list tr.LC_mail_read:hover {
5190: background-color: $mail_read_hover;
5191: }
1.795 www 5192:
1.349 albertel 5193: table.LC_mail_list tr.LC_mail_replied {
5194: background-color: $mail_replied;
5195: }
1.795 www 5196:
1.349 albertel 5197: table.LC_mail_list tr.LC_mail_replied:hover {
5198: background-color: $mail_replied_hover;
5199: }
1.795 www 5200:
1.349 albertel 5201: table.LC_mail_list tr.LC_mail_other {
5202: background-color: $mail_other;
5203: }
1.795 www 5204:
1.349 albertel 5205: table.LC_mail_list tr.LC_mail_other:hover {
5206: background-color: $mail_other_hover;
5207: }
1.494 raeburn 5208:
1.777 tempelho 5209: table.LC_data_table tr > td.LC_browser_file,
5210: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5211: background: #AAEE77;
1.389 albertel 5212: }
1.795 www 5213:
1.777 tempelho 5214: table.LC_data_table tr > td.LC_browser_file_locked,
5215: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5216: background: #FFAA99;
1.387 albertel 5217: }
1.795 www 5218:
1.777 tempelho 5219: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5220: background: #888888;
1.779 bisitz 5221: }
1.795 www 5222:
1.777 tempelho 5223: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5224: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5225: background: #F8F866;
1.777 tempelho 5226: }
1.795 www 5227:
1.696 bisitz 5228: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5229: background: #E0E8FF;
1.387 albertel 5230: }
1.696 bisitz 5231:
1.707 bisitz 5232: table.LC_data_table tr > td.LC_roles_is {
5233: /* background: #77FF77; */
5234: }
1.795 www 5235:
1.707 bisitz 5236: table.LC_data_table tr > td.LC_roles_future {
5237: background: #FFFF77;
5238: }
1.795 www 5239:
1.707 bisitz 5240: table.LC_data_table tr > td.LC_roles_will {
5241: background: #FFAA77;
5242: }
1.795 www 5243:
1.707 bisitz 5244: table.LC_data_table tr > td.LC_roles_expired {
5245: background: #FF7777;
5246: }
1.795 www 5247:
1.707 bisitz 5248: table.LC_data_table tr > td.LC_roles_will_not {
5249: background: #AAFF77;
5250: }
1.795 www 5251:
1.707 bisitz 5252: table.LC_data_table tr > td.LC_roles_selected {
5253: background: #11CC55;
5254: }
5255:
1.388 albertel 5256: span.LC_current_location {
1.701 harmsja 5257: font-size:larger;
1.388 albertel 5258: background: $pgbg;
5259: }
1.387 albertel 5260:
1.395 albertel 5261: span.LC_parm_menu_item {
5262: font-size: larger;
5263: }
1.795 www 5264:
1.395 albertel 5265: span.LC_parm_scope_all {
5266: color: red;
5267: }
1.795 www 5268:
1.395 albertel 5269: span.LC_parm_scope_folder {
5270: color: green;
5271: }
1.795 www 5272:
1.395 albertel 5273: span.LC_parm_scope_resource {
5274: color: orange;
5275: }
1.795 www 5276:
1.395 albertel 5277: span.LC_parm_part {
5278: color: blue;
5279: }
1.795 www 5280:
1.395 albertel 5281: span.LC_parm_folder, span.LC_parm_symb {
5282: font-size: x-small;
5283: font-family: $mono;
5284: color: #AAAAAA;
5285: }
5286:
1.795 www 5287: td.LC_parm_overview_level_menu,
5288: td.LC_parm_overview_map_menu,
5289: td.LC_parm_overview_parm_selectors,
5290: td.LC_parm_overview_restrictions {
1.396 albertel 5291: border: 1px solid black;
5292: border-collapse: collapse;
5293: }
1.795 www 5294:
1.396 albertel 5295: table.LC_parm_overview_restrictions td {
5296: border-width: 1px 4px 1px 4px;
5297: border-style: solid;
5298: border-color: $pgbg;
5299: text-align: center;
5300: }
1.795 www 5301:
1.396 albertel 5302: table.LC_parm_overview_restrictions th {
5303: background: $tabbg;
5304: border-width: 1px 4px 1px 4px;
5305: border-style: solid;
5306: border-color: $pgbg;
5307: }
1.795 www 5308:
1.398 albertel 5309: table#LC_helpmenu {
1.803 bisitz 5310: border: none;
1.398 albertel 5311: height: 55px;
1.803 bisitz 5312: border-spacing: 0;
1.398 albertel 5313: }
5314:
5315: table#LC_helpmenu fieldset legend {
5316: font-size: larger;
5317: }
1.795 www 5318:
1.397 albertel 5319: table#LC_helpmenu_links {
5320: width: 100%;
5321: border: 1px solid black;
5322: background: $pgbg;
1.803 bisitz 5323: padding: 0;
1.397 albertel 5324: border-spacing: 1px;
5325: }
1.795 www 5326:
1.397 albertel 5327: table#LC_helpmenu_links tr td {
5328: padding: 1px;
5329: background: $tabbg;
1.399 albertel 5330: text-align: center;
5331: font-weight: bold;
1.397 albertel 5332: }
1.396 albertel 5333:
1.795 www 5334: table#LC_helpmenu_links a:link,
5335: table#LC_helpmenu_links a:visited,
1.397 albertel 5336: table#LC_helpmenu_links a:active {
5337: text-decoration: none;
5338: color: $font;
5339: }
1.795 www 5340:
1.397 albertel 5341: table#LC_helpmenu_links a:hover {
5342: text-decoration: underline;
5343: color: $vlink;
5344: }
1.396 albertel 5345:
1.417 albertel 5346: .LC_chrt_popup_exists {
5347: border: 1px solid #339933;
5348: margin: -1px;
5349: }
1.795 www 5350:
1.417 albertel 5351: .LC_chrt_popup_up {
5352: border: 1px solid yellow;
5353: margin: -1px;
5354: }
1.795 www 5355:
1.417 albertel 5356: .LC_chrt_popup {
5357: border: 1px solid #8888FF;
5358: background: #CCCCFF;
5359: }
1.795 www 5360:
1.421 albertel 5361: table.LC_pick_box {
5362: border-collapse: separate;
5363: background: white;
5364: border: 1px solid black;
5365: border-spacing: 1px;
5366: }
1.795 www 5367:
1.421 albertel 5368: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5369: background: $sidebg;
1.421 albertel 5370: font-weight: bold;
1.900 bisitz 5371: text-align: left;
1.740 bisitz 5372: vertical-align: top;
1.421 albertel 5373: width: 184px;
5374: padding: 8px;
5375: }
1.795 www 5376:
1.579 raeburn 5377: table.LC_pick_box td.LC_pick_box_value {
5378: text-align: left;
5379: padding: 8px;
5380: }
1.795 www 5381:
1.579 raeburn 5382: table.LC_pick_box td.LC_pick_box_select {
5383: text-align: left;
5384: padding: 8px;
5385: }
1.795 www 5386:
1.424 albertel 5387: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5388: padding: 0;
1.421 albertel 5389: height: 1px;
5390: background: black;
5391: }
1.795 www 5392:
1.421 albertel 5393: table.LC_pick_box td.LC_pick_box_submit {
5394: text-align: right;
5395: }
1.795 www 5396:
1.579 raeburn 5397: table.LC_pick_box td.LC_evenrow_value {
5398: text-align: left;
5399: padding: 8px;
5400: background-color: $data_table_light;
5401: }
1.795 www 5402:
1.579 raeburn 5403: table.LC_pick_box td.LC_oddrow_value {
5404: text-align: left;
5405: padding: 8px;
5406: background-color: $data_table_light;
5407: }
1.795 www 5408:
1.579 raeburn 5409: span.LC_helpform_receipt_cat {
5410: font-weight: bold;
5411: }
1.795 www 5412:
1.424 albertel 5413: table.LC_group_priv_box {
5414: background: white;
5415: border: 1px solid black;
5416: border-spacing: 1px;
5417: }
1.795 www 5418:
1.424 albertel 5419: table.LC_group_priv_box td.LC_pick_box_title {
5420: background: $tabbg;
5421: font-weight: bold;
5422: text-align: right;
5423: width: 184px;
5424: }
1.795 www 5425:
1.424 albertel 5426: table.LC_group_priv_box td.LC_groups_fixed {
5427: background: $data_table_light;
5428: text-align: center;
5429: }
1.795 www 5430:
1.424 albertel 5431: table.LC_group_priv_box td.LC_groups_optional {
5432: background: $data_table_dark;
5433: text-align: center;
5434: }
1.795 www 5435:
1.424 albertel 5436: table.LC_group_priv_box td.LC_groups_functionality {
5437: background: $data_table_darker;
5438: text-align: center;
5439: font-weight: bold;
5440: }
1.795 www 5441:
1.424 albertel 5442: table.LC_group_priv td {
5443: text-align: left;
1.803 bisitz 5444: padding: 0;
1.424 albertel 5445: }
5446:
1.421 albertel 5447: table.LC_notify_front_page {
5448: background: white;
5449: border: 1px solid black;
5450: padding: 8px;
5451: }
1.795 www 5452:
1.421 albertel 5453: table.LC_notify_front_page td {
5454: padding: 8px;
5455: }
1.795 www 5456:
1.424 albertel 5457: .LC_navbuttons {
5458: margin: 2ex 0ex 2ex 0ex;
5459: }
1.795 www 5460:
1.423 albertel 5461: .LC_topic_bar {
5462: font-weight: bold;
5463: width: 100%;
5464: background: $tabbg;
5465: vertical-align: middle;
5466: margin: 2ex 0ex 2ex 0ex;
1.805 bisitz 5467: padding: 3px;
1.423 albertel 5468: }
1.795 www 5469:
1.423 albertel 5470: .LC_topic_bar span {
5471: vertical-align: middle;
5472: }
1.795 www 5473:
1.423 albertel 5474: .LC_topic_bar img {
5475: vertical-align: bottom;
5476: }
1.795 www 5477:
1.423 albertel 5478: table.LC_course_group_status {
5479: margin: 20px;
5480: }
1.795 www 5481:
1.423 albertel 5482: table.LC_status_selector td {
5483: vertical-align: top;
5484: text-align: center;
1.424 albertel 5485: padding: 4px;
5486: }
1.795 www 5487:
1.599 albertel 5488: div.LC_feedback_link {
1.616 albertel 5489: clear: both;
1.829 kalberla 5490: background: $sidebg;
1.779 bisitz 5491: width: 100%;
1.829 kalberla 5492: padding-bottom: 10px;
5493: border: 1px $tabbg solid;
1.833 kalberla 5494: height: 22px;
5495: line-height: 22px;
5496: padding-top: 5px;
5497: }
5498:
5499: div.LC_feedback_link img {
5500: height: 22px;
1.867 kalberla 5501: vertical-align:middle;
1.829 kalberla 5502: }
5503:
5504: div.LC_feedback_link a{
5505: text-decoration: none;
1.489 raeburn 5506: }
1.795 www 5507:
1.867 kalberla 5508: div.LC_comblock {
5509: display:inline;
5510: color:$font;
5511: font-size:90%;
5512: }
5513:
5514: div.LC_feedback_link div.LC_comblock {
5515: padding-left:5px;
5516: }
5517:
5518: div.LC_feedback_link div.LC_comblock a {
5519: color:$font;
5520: }
5521:
1.489 raeburn 5522: span.LC_feedback_link {
1.858 bisitz 5523: /* background: $feedback_link_bg; */
1.599 albertel 5524: font-size: larger;
5525: }
1.795 www 5526:
1.599 albertel 5527: span.LC_message_link {
1.858 bisitz 5528: /* background: $feedback_link_bg; */
1.599 albertel 5529: font-size: larger;
5530: position: absolute;
5531: right: 1em;
1.489 raeburn 5532: }
1.421 albertel 5533:
1.515 albertel 5534: table.LC_prior_tries {
1.524 albertel 5535: border: 1px solid #000000;
5536: border-collapse: separate;
5537: border-spacing: 1px;
1.515 albertel 5538: }
1.523 albertel 5539:
1.515 albertel 5540: table.LC_prior_tries td {
1.524 albertel 5541: padding: 2px;
1.515 albertel 5542: }
1.523 albertel 5543:
5544: .LC_answer_correct {
1.795 www 5545: background: lightgreen;
5546: color: darkgreen;
5547: padding: 6px;
1.523 albertel 5548: }
1.795 www 5549:
1.523 albertel 5550: .LC_answer_charged_try {
1.797 www 5551: background: #FFAAAA;
1.795 www 5552: color: darkred;
5553: padding: 6px;
1.523 albertel 5554: }
1.795 www 5555:
1.779 bisitz 5556: .LC_answer_not_charged_try,
1.523 albertel 5557: .LC_answer_no_grade,
5558: .LC_answer_late {
1.795 www 5559: background: lightyellow;
1.523 albertel 5560: color: black;
1.795 www 5561: padding: 6px;
1.523 albertel 5562: }
1.795 www 5563:
1.523 albertel 5564: .LC_answer_previous {
1.795 www 5565: background: lightblue;
5566: color: darkblue;
5567: padding: 6px;
1.523 albertel 5568: }
1.795 www 5569:
1.779 bisitz 5570: .LC_answer_no_message {
1.777 tempelho 5571: background: #FFFFFF;
5572: color: black;
1.795 www 5573: padding: 6px;
1.779 bisitz 5574: }
1.795 www 5575:
1.779 bisitz 5576: .LC_answer_unknown {
5577: background: orange;
5578: color: black;
1.795 www 5579: padding: 6px;
1.777 tempelho 5580: }
1.795 www 5581:
1.529 albertel 5582: span.LC_prior_numerical,
5583: span.LC_prior_string,
5584: span.LC_prior_custom,
5585: span.LC_prior_reaction,
5586: span.LC_prior_math {
1.523 albertel 5587: font-family: monospace;
5588: white-space: pre;
5589: }
5590:
1.525 albertel 5591: span.LC_prior_string {
5592: font-family: monospace;
5593: white-space: pre;
5594: }
5595:
1.523 albertel 5596: table.LC_prior_option {
5597: width: 100%;
5598: border-collapse: collapse;
5599: }
1.795 www 5600:
5601: table.LC_prior_rank,
5602: table.LC_prior_match {
1.528 albertel 5603: border-collapse: collapse;
5604: }
1.795 www 5605:
1.528 albertel 5606: table.LC_prior_option tr td,
5607: table.LC_prior_rank tr td,
5608: table.LC_prior_match tr td {
1.524 albertel 5609: border: 1px solid #000000;
1.515 albertel 5610: }
5611:
1.855 bisitz 5612: .LC_nobreak {
1.544 albertel 5613: white-space: nowrap;
1.519 raeburn 5614: }
5615:
1.576 raeburn 5616: span.LC_cusr_emph {
5617: font-style: italic;
5618: }
5619:
1.633 raeburn 5620: span.LC_cusr_subheading {
5621: font-weight: normal;
5622: font-size: 85%;
5623: }
5624:
1.545 albertel 5625: table.LC_docs_documents {
5626: background: #BBBBBB;
1.803 bisitz 5627: border-width: 0;
1.545 albertel 5628: border-collapse: collapse;
5629: }
1.795 www 5630:
1.777 tempelho 5631: table.LC_docs_documents td.LC_docs_document {
1.779 bisitz 5632: border: 2px solid black;
5633: padding: 4px;
1.777 tempelho 5634: }
1.795 www 5635:
1.861 bisitz 5636: div.LC_docs_entry_move {
1.859 bisitz 5637: border: 1px solid #BBBBBB;
1.545 albertel 5638: background: #DDDDDD;
1.861 bisitz 5639: width: 22px;
1.859 bisitz 5640: padding: 1px;
5641: margin: 0;
1.545 albertel 5642: }
5643:
1.861 bisitz 5644: table.LC_data_table tr > td.LC_docs_entry_commands,
5645: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5646: background: #DDDDDD;
5647: font-size: x-small;
5648: }
1.795 www 5649:
1.861 bisitz 5650: .LC_docs_entry_parameter {
5651: white-space: nowrap;
5652: }
5653:
1.544 albertel 5654: .LC_docs_copy {
1.545 albertel 5655: color: #000099;
1.544 albertel 5656: }
1.795 www 5657:
1.544 albertel 5658: .LC_docs_cut {
1.545 albertel 5659: color: #550044;
1.544 albertel 5660: }
1.795 www 5661:
1.544 albertel 5662: .LC_docs_rename {
1.545 albertel 5663: color: #009900;
1.544 albertel 5664: }
1.795 www 5665:
1.544 albertel 5666: .LC_docs_remove {
1.545 albertel 5667: color: #990000;
5668: }
5669:
1.547 albertel 5670: .LC_docs_reinit_warn,
5671: .LC_docs_ext_edit {
5672: font-size: x-small;
5673: }
5674:
1.545 albertel 5675: table.LC_docs_adddocs td,
5676: table.LC_docs_adddocs th {
5677: border: 1px solid #BBBBBB;
5678: padding: 4px;
5679: background: #DDDDDD;
1.543 albertel 5680: }
5681:
1.584 albertel 5682: table.LC_sty_begin {
5683: background: #BBFFBB;
5684: }
1.795 www 5685:
1.584 albertel 5686: table.LC_sty_end {
5687: background: #FFBBBB;
5688: }
5689:
1.589 raeburn 5690: table.LC_double_column {
1.803 bisitz 5691: border-width: 0;
1.589 raeburn 5692: border-collapse: collapse;
5693: width: 100%;
5694: padding: 2px;
5695: }
5696:
5697: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5698: top: 2px;
1.589 raeburn 5699: left: 2px;
5700: width: 47%;
5701: vertical-align: top;
5702: }
5703:
5704: table.LC_double_column tr td.LC_right_col {
5705: top: 2px;
1.779 bisitz 5706: right: 2px;
1.589 raeburn 5707: width: 47%;
5708: vertical-align: top;
5709: }
5710:
1.591 raeburn 5711: div.LC_left_float {
5712: float: left;
5713: padding-right: 5%;
1.597 albertel 5714: padding-bottom: 4px;
1.591 raeburn 5715: }
5716:
5717: div.LC_clear_float_header {
1.597 albertel 5718: padding-bottom: 2px;
1.591 raeburn 5719: }
5720:
5721: div.LC_clear_float_footer {
1.597 albertel 5722: padding-top: 10px;
1.591 raeburn 5723: clear: both;
5724: }
5725:
1.597 albertel 5726: div.LC_grade_show_user {
5727: margin-top: 20px;
5728: border: 1px solid black;
5729: }
1.795 www 5730:
1.597 albertel 5731: div.LC_grade_user_name {
5732: background: #DDDDEE;
5733: border-bottom: 1px solid black;
1.705 tempelho 5734: font-weight: bold;
5735: font-size: large;
1.597 albertel 5736: }
1.795 www 5737:
1.597 albertel 5738: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5739: background: #DDEEDD;
5740: }
5741:
5742: div.LC_grade_show_problem,
5743: div.LC_grade_submissions,
5744: div.LC_grade_message_center,
5745: div.LC_grade_info_links,
5746: div.LC_grade_assign {
5747: margin: 5px;
5748: width: 99%;
5749: background: #FFFFFF;
5750: }
1.795 www 5751:
1.597 albertel 5752: div.LC_grade_show_problem_header,
5753: div.LC_grade_submissions_header,
5754: div.LC_grade_message_center_header,
5755: div.LC_grade_assign_header {
1.705 tempelho 5756: font-weight: bold;
5757: font-size: large;
1.597 albertel 5758: }
1.795 www 5759:
1.597 albertel 5760: div.LC_grade_show_problem_problem,
5761: div.LC_grade_submissions_body,
5762: div.LC_grade_message_center_body,
5763: div.LC_grade_assign_body {
5764: border: 1px solid black;
5765: width: 99%;
5766: background: #FFFFFF;
5767: }
1.795 www 5768:
1.598 albertel 5769: span.LC_grade_check_note {
1.705 tempelho 5770: font-weight: normal;
5771: font-size: medium;
1.598 albertel 5772: display: inline;
5773: position: absolute;
5774: right: 1em;
5775: }
1.597 albertel 5776:
1.613 albertel 5777: table.LC_scantron_action {
5778: width: 100%;
5779: }
1.795 www 5780:
1.613 albertel 5781: table.LC_scantron_action tr th {
1.698 harmsja 5782: font-weight:bold;
5783: font-style:normal;
1.613 albertel 5784: }
1.795 www 5785:
1.779 bisitz 5786: .LC_edit_problem_header,
1.614 albertel 5787: div.LC_edit_problem_footer {
1.705 tempelho 5788: font-weight: normal;
5789: font-size: medium;
1.602 albertel 5790: margin: 2px;
1.600 albertel 5791: }
1.795 www 5792:
1.600 albertel 5793: div.LC_edit_problem_header,
1.602 albertel 5794: div.LC_edit_problem_header div,
1.614 albertel 5795: div.LC_edit_problem_footer,
5796: div.LC_edit_problem_footer div,
1.602 albertel 5797: div.LC_edit_problem_editxml_header,
5798: div.LC_edit_problem_editxml_header div {
1.600 albertel 5799: margin-top: 5px;
5800: }
1.795 www 5801:
1.600 albertel 5802: div.LC_edit_problem_header_title {
1.705 tempelho 5803: font-weight: bold;
5804: font-size: larger;
1.602 albertel 5805: background: $tabbg;
5806: padding: 3px;
5807: }
1.795 www 5808:
1.602 albertel 5809: table.LC_edit_problem_header_title {
1.705 tempelho 5810: font-size: larger;
5811: font-weight: bold;
1.602 albertel 5812: width: 100%;
5813: border-color: $pgbg;
5814: border-style: solid;
5815: border-width: $border;
1.600 albertel 5816: background: $tabbg;
1.602 albertel 5817: border-collapse: collapse;
1.803 bisitz 5818: padding: 0;
1.602 albertel 5819: }
5820:
5821: div.LC_edit_problem_discards {
5822: float: left;
5823: padding-bottom: 5px;
5824: }
1.795 www 5825:
1.602 albertel 5826: div.LC_edit_problem_saves {
5827: float: right;
5828: padding-bottom: 5px;
1.600 albertel 5829: }
1.795 www 5830:
1.679 riegler 5831: img.stift{
1.803 bisitz 5832: border-width: 0;
5833: vertical-align: middle;
1.677 riegler 5834: }
1.680 riegler 5835:
1.681 riegler 5836: table#LC_mainmenu{
5837: margin-top:10px;
5838: width:80%;
5839: }
5840:
1.680 riegler 5841: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5842: vertical-align: top;
5843: width: 45%;
5844: }
1.795 www 5845:
1.779 bisitz 5846: .LC_mainmenu_fieldset_category {
5847: color: $font;
5848: background: $pgbg;
5849: font-size: small;
5850: font-weight: bold;
1.777 tempelho 5851: }
1.795 www 5852:
1.716 raeburn 5853: div.LC_createcourse {
5854: margin: 10px 10px 10px 10px;
5855: }
5856:
1.693 droeschl 5857: /* ---- Remove when done ----
5858: # The following styles is part of the redesign of LON-CAPA and are
5859: # subject to change during this project.
5860: # Don't rely on their current functionality as they might be
5861: # changed or removed.
5862: # --------------------------*/
5863:
1.698 harmsja 5864: a:hover,
1.897 wenzelju 5865: ol.LC_primary_menu a:hover,
1.721 harmsja 5866: ol#LC_MenuBreadcrumbs a:hover,
5867: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5868: ul#LC_secondary_menu a:hover,
1.721 harmsja 5869: .LC_FormSectionClearButton input:hover
1.795 www 5870: ul.LC_TabContent li:hover a {
1.698 harmsja 5871: color:#BF2317;
1.904 droeschl 5872: text-decoration:none;
1.693 droeschl 5873: }
5874:
1.779 bisitz 5875: h1 {
1.813 bisitz 5876: padding: 0;
1.693 droeschl 5877: line-height:130%;
5878: }
1.698 harmsja 5879:
1.795 www 5880: h2,h3,h4,h5,h6 {
1.803 bisitz 5881: margin: 5px 0 5px 0;
5882: padding: 0;
1.721 harmsja 5883: line-height:130%;
1.693 droeschl 5884: }
1.795 www 5885:
5886: .LC_hcell {
1.698 harmsja 5887: padding:3px 15px 3px 15px;
1.803 bisitz 5888: margin: 0;
1.703 harmsja 5889: background-color:$tabbg;
1.801 tempelho 5890: color:$fontmenu;
1.779 bisitz 5891: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5892: }
1.795 www 5893:
1.840 bisitz 5894: .LC_Box > .LC_hcell {
1.847 tempelho 5895: margin: 0 -10px 10px -10px;
1.835 bisitz 5896: }
5897:
1.721 harmsja 5898: .LC_noBorder {
1.803 bisitz 5899: border: 0;
1.698 harmsja 5900: }
1.693 droeschl 5901:
1.761 tempelho 5902: .LC_Right {
5903: float: right;
1.803 bisitz 5904: margin: 0;
5905: padding: 0;
1.761 tempelho 5906: }
5907:
1.721 harmsja 5908: .LC_FormSectionClearButton input {
1.779 bisitz 5909: background-color:transparent;
1.803 bisitz 5910: border: none;
1.698 harmsja 5911: cursor:pointer;
5912: text-decoration:underline;
1.693 droeschl 5913: }
1.763 bisitz 5914:
5915: .LC_help_open_topic {
5916: color: #FFFFFF;
5917: background-color: #EEEEFF;
5918: margin: 1px;
5919: padding: 4px;
5920: border: 1px solid #000033;
5921: white-space: nowrap;
1.783 amueller 5922: /* vertical-align: middle; */
1.759 neumanie 5923: }
1.693 droeschl 5924:
1.698 harmsja 5925: dl,ul,div,fieldset {
1.803 bisitz 5926: margin: 10px 10px 10px 0;
1.806 bisitz 5927: /* overflow: hidden; */
1.693 droeschl 5928: }
1.795 www 5929:
1.838 bisitz 5930: fieldset > legend {
5931: font-weight: bold;
5932: padding: 0 5px 0 5px;
5933: }
5934:
1.813 bisitz 5935: #LC_nav_bar {
1.807 droeschl 5936: float: left;
1.852 droeschl 5937: margin: 0.2em 0 0 0;
1.807 droeschl 5938: }
5939:
1.813 bisitz 5940: #LC_nav_bar em{
1.807 droeschl 5941: font-weight: bold;
5942: font-style: normal;
5943: }
5944:
1.897 wenzelju 5945: ol.LC_primary_menu {
1.807 droeschl 5946: float: right;
1.852 droeschl 5947: margin: 0.2em 0 0 0;
1.807 droeschl 5948: }
5949:
1.852 droeschl 5950: ol#LC_PathBreadcrumbs {
1.803 bisitz 5951: margin: 0;
1.693 droeschl 5952: }
5953:
1.897 wenzelju 5954: ol.LC_primary_menu li {
1.693 droeschl 5955: display: inline;
1.803 bisitz 5956: padding: 5px 5px 0 10px;
1.693 droeschl 5957: vertical-align: top;
5958: }
5959:
1.897 wenzelju 5960: ol.LC_primary_menu li img {
1.693 droeschl 5961: vertical-align: bottom;
5962: }
5963:
1.897 wenzelju 5964: ol.LC_primary_menu a {
1.693 droeschl 5965: font-size: 90%;
5966: color: RGB(80, 80, 80);
5967: text-decoration: none;
5968: }
1.795 www 5969:
1.897 wenzelju 5970: ul#LC_secondary_menu {
1.807 droeschl 5971: clear: both;
1.808 droeschl 5972: color: $fontmenu;
5973: background: $tabbg;
5974: list-style: none;
5975: padding: 0;
5976: margin: 0;
5977: width: 100%;
5978: }
5979:
1.897 wenzelju 5980: ul#LC_secondary_menu li {
1.808 droeschl 5981: font-weight: bold;
5982: line-height: 1.8em;
5983: padding: 0 0.8em;
5984: border-right: 1px solid black;
5985: display: inline;
5986: vertical-align: middle;
1.807 droeschl 5987: }
5988:
1.847 tempelho 5989: ul.LC_TabContent {
1.721 harmsja 5990: display:block;
1.847 tempelho 5991: background: $sidebg;
1.858 bisitz 5992: border-bottom: solid 1px $lg_border_color;
1.721 harmsja 5993: list-style:none;
1.870 tempelho 5994: margin: 0 -10px;
1.803 bisitz 5995: padding: 0;
1.693 droeschl 5996: }
5997:
1.795 www 5998: ul.LC_TabContent li,
5999: ul.LC_TabContentBigger li {
1.741 harmsja 6000: float:left;
6001: }
1.795 www 6002:
1.897 wenzelju 6003: ul#LC_secondary_menu li a {
1.808 droeschl 6004: color: $fontmenu;
1.693 droeschl 6005: text-decoration: none;
6006: }
1.795 www 6007:
1.721 harmsja 6008: ul.LC_TabContent {
1.847 tempelho 6009: min-height:1.5em;
1.721 harmsja 6010: }
1.795 www 6011:
6012: ul.LC_TabContent li {
1.741 harmsja 6013: vertical-align:middle;
1.803 bisitz 6014: padding: 0 10px 0 10px;
1.745 ehlerst 6015: background-color:$tabbg;
6016: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 6017: }
1.795 www 6018:
1.847 tempelho 6019: ul.LC_TabContent .right {
6020: float:right;
6021: }
6022:
1.795 www 6023: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721 harmsja 6024: color:rgb(47,47,47);
6025: text-decoration:none;
6026: font-size:95%;
6027: font-weight:bold;
1.761 tempelho 6028: padding-right: 16px;
1.721 harmsja 6029: }
1.795 www 6030:
6031: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761 tempelho 6032: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841 tempelho 6033: border-bottom:solid 2px #FFFFFF;
1.761 tempelho 6034: padding-right: 16px;
1.744 ehlerst 6035: }
1.795 www 6036:
1.870 tempelho 6037: #maincoursedoc {
6038: clear:both;
6039: }
6040:
6041: ul.LC_TabContentBigger {
6042: display:block;
6043: list-style:none;
6044: padding: 0;
6045: }
6046:
1.795 www 6047: ul.LC_TabContentBigger li {
1.870 tempelho 6048: vertical-align:bottom;
6049: height: 30px;
6050: font-size:110%;
6051: font-weight:bold;
6052: color: #737373;
1.841 tempelho 6053: }
6054:
1.870 tempelho 6055:
6056: ul.LC_TabContentBigger li a {
6057: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6058: height: 30px;
6059: line-height: 30px;
6060: text-align: center;
6061: display: block;
6062: text-decoration: none;
1.741 harmsja 6063: }
1.795 www 6064:
1.870 tempelho 6065: ul.LC_TabContentBigger li:hover a,
6066: ul.LC_TabContentBigger li.active a {
6067: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857 tempelho 6068: color:$font;
1.870 tempelho 6069: text-decoration: underline;
1.744 ehlerst 6070: }
1.795 www 6071:
1.870 tempelho 6072:
6073: ul.LC_TabContentBigger li b {
6074: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6075: display: block;
6076: float: left;
6077: padding: 0 30px;
6078: }
6079:
6080: ul.LC_TabContentBigger li:hover b,
6081: ul.LC_TabContentBigger li.active b {
6082: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6083: color:$font;
6084: border-bottom: 1px solid #FFFFFF;
1.741 harmsja 6085: }
1.693 droeschl 6086:
1.870 tempelho 6087:
1.862 bisitz 6088: ul.LC_CourseBreadcrumbs {
6089: background: $sidebg;
6090: line-height: 32px;
6091: padding-left: 10px;
6092: margin: 0 0 10px 0;
6093: list-style-position: inside;
6094:
6095: }
6096:
1.795 www 6097: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6098: ol#LC_PathBreadcrumbs {
1.693 droeschl 6099: padding-left: 10px;
1.819 tempelho 6100: margin: 0;
1.693 droeschl 6101: list-style-position: inside;
1.904 droeschl 6102: /* SD working here
6103: white-space: nowrap; */
1.693 droeschl 6104: }
6105:
1.795 www 6106: ol#LC_MenuBreadcrumbs li,
6107: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6108: ul.LC_CourseBreadcrumbs li {
1.842 droeschl 6109: display: inline;
6110: white-space: nowrap;
1.904 droeschl 6111: /* SD working here
6112: white-space: normal; */
1.693 droeschl 6113: }
6114:
1.823 bisitz 6115: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6116: ul.LC_CourseBreadcrumbs li a {
1.693 droeschl 6117: text-decoration: none;
6118: font-size:90%;
6119: }
1.795 www 6120:
6121: ol#LC_PathBreadcrumbs li a {
1.698 harmsja 6122: text-decoration:none;
6123: font-size:100%;
6124: font-weight:bold;
1.693 droeschl 6125: }
1.795 www 6126:
1.840 bisitz 6127: .LC_Box {
1.835 bisitz 6128: border: solid 1px $lg_border_color;
6129: padding: 0 10px 10px 10px;
1.746 neumanie 6130: }
1.795 www 6131:
6132: .LC_AboutMe_Image {
1.747 neumanie 6133: float:left;
6134: margin-right:10px;
6135: }
1.795 www 6136:
6137: .LC_Clear_AboutMe_Image {
1.747 neumanie 6138: clear:left;
6139: }
1.795 www 6140:
1.721 harmsja 6141: dl.LC_ListStyleClean dt {
1.693 droeschl 6142: padding-right: 5px;
6143: display: table-header-group;
6144: }
6145:
1.721 harmsja 6146: dl.LC_ListStyleClean dd {
1.693 droeschl 6147: display: table-row;
6148: }
6149:
1.721 harmsja 6150: .LC_ListStyleClean,
6151: .LC_ListStyleSimple,
6152: .LC_ListStyleNormal,
1.777 tempelho 6153: .LC_ListStyle_Border,
1.795 www 6154: .LC_ListStyleSpecial {
1.693 droeschl 6155: /*display:block; */
6156: list-style-position: inside;
6157: list-style-type: none;
6158: overflow: hidden;
1.803 bisitz 6159: padding: 0;
1.693 droeschl 6160: }
6161:
1.721 harmsja 6162: .LC_ListStyleSimple li,
6163: .LC_ListStyleSimple dd,
6164: .LC_ListStyleNormal li,
6165: .LC_ListStyleNormal dd,
6166: .LC_ListStyleSpecial li,
1.795 www 6167: .LC_ListStyleSpecial dd {
1.803 bisitz 6168: margin: 0;
1.693 droeschl 6169: padding: 5px 5px 5px 10px;
6170: clear: both;
6171: }
6172:
1.721 harmsja 6173: .LC_ListStyleClean li,
6174: .LC_ListStyleClean dd {
1.803 bisitz 6175: padding-top: 0;
6176: padding-bottom: 0;
1.693 droeschl 6177: }
6178:
1.721 harmsja 6179: .LC_ListStyleSimple dd,
1.795 www 6180: .LC_ListStyleSimple li {
1.698 harmsja 6181: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6182: }
6183:
1.721 harmsja 6184: .LC_ListStyleSpecial li,
6185: .LC_ListStyleSpecial dd {
1.693 droeschl 6186: list-style-type: none;
6187: background-color: RGB(220, 220, 220);
6188: margin-bottom: 4px;
6189: }
6190:
1.721 harmsja 6191: table.LC_SimpleTable {
1.698 harmsja 6192: margin:5px;
6193: border:solid 1px $lg_border_color;
1.795 www 6194: }
1.693 droeschl 6195:
1.721 harmsja 6196: table.LC_SimpleTable tr {
1.803 bisitz 6197: padding: 0;
1.698 harmsja 6198: border:solid 1px $lg_border_color;
1.693 droeschl 6199: }
1.795 www 6200:
6201: table.LC_SimpleTable thead {
1.698 harmsja 6202: background:rgb(220,220,220);
1.693 droeschl 6203: }
6204:
1.721 harmsja 6205: div.LC_columnSection {
1.693 droeschl 6206: display: block;
6207: clear: both;
6208: overflow: hidden;
1.803 bisitz 6209: margin: 0;
1.693 droeschl 6210: }
6211:
1.721 harmsja 6212: div.LC_columnSection>* {
1.693 droeschl 6213: float: left;
1.803 bisitz 6214: margin: 10px 20px 10px 0;
1.747 neumanie 6215: overflow:hidden;
1.693 droeschl 6216: }
1.721 harmsja 6217:
1.694 tempelho 6218: .LC_loginpage_container {
6219: text-align:left;
6220: margin : 0 auto;
1.785 tempelho 6221: width:90%;
1.694 tempelho 6222: padding: 10px;
6223: height: auto;
1.712 muellerd 6224: background-color:#FFFFFF;
1.694 tempelho 6225: border:1px solid #CCCCCC;
6226: }
6227:
6228:
6229: .LC_loginpage_loginContainer {
6230: float:left;
1.712 muellerd 6231: width: 182px;
1.785 tempelho 6232: padding: 2px;
1.712 muellerd 6233: border:1px solid #CCCCCC;
6234: background-color:$loginbg;
1.694 tempelho 6235: }
6236:
1.795 www 6237: .LC_loginpage_loginContainer h2 {
1.803 bisitz 6238: margin-top: 0;
1.712 muellerd 6239: display:block;
6240: background:$bgcol;
6241: color:$textcol;
6242: padding-left:5px;
6243: }
1.785 tempelho 6244:
1.694 tempelho 6245: .LC_loginpage_loginInfo {
6246: float:left;
1.785 tempelho 6247: width:182px;
1.694 tempelho 6248: border:1px solid #CCCCCC;
1.785 tempelho 6249: padding:2px;
1.712 muellerd 6250: }
6251:
1.694 tempelho 6252: .LC_loginpage_space {
1.754 droeschl 6253: clear: both;
6254: margin-bottom: 20px;
1.694 tempelho 6255: border-bottom: 1px solid #CCCCCC;
6256: }
6257:
1.785 tempelho 6258: .LC_loginpage_floatLeft {
6259: float: left;
6260: width: 200px;
6261: margin: 0;
6262: }
6263:
1.795 www 6264: table em {
1.754 droeschl 6265: font-weight: bold;
6266: font-style: normal;
1.748 schulted 6267: }
1.795 www 6268:
1.779 bisitz 6269: table.LC_tableBrowseRes,
1.795 www 6270: table.LC_tableOfContent {
1.769 schulted 6271: border:none;
1.858 bisitz 6272: border-spacing: 1px;
1.754 droeschl 6273: padding: 3px;
6274: background-color: #FFFFFF;
6275: font-size: 90%;
1.753 droeschl 6276: }
1.789 droeschl 6277:
6278: table.LC_tableOfContent{
6279: border-collapse: collapse;
6280: }
6281:
1.771 droeschl 6282: table.LC_tableBrowseRes a,
1.768 schulted 6283: table.LC_tableOfContent a {
1.771 droeschl 6284: background-color: transparent;
1.753 droeschl 6285: text-decoration: none;
6286: }
6287:
1.771 droeschl 6288: table.LC_tableBrowseRes tr.LC_trOdd,
1.768 schulted 6289: table.LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 6290: background-color: #EEEEEE;
1.753 droeschl 6291: }
6292:
1.795 www 6293: table.LC_tableOfContent img {
1.753 droeschl 6294: border: none;
6295: height: 1.3em;
6296: vertical-align: text-bottom;
6297: margin-right: 0.3em;
6298: }
1.757 schulted 6299:
1.795 www 6300: a#LC_content_toolbar_firsthomework {
1.774 ehlerst 6301: background-image:url(/res/adm/pages/open-first-problem.gif);
6302: }
6303:
1.795 www 6304: a#LC_content_toolbar_launchnav {
1.774 ehlerst 6305: background-image:url(/res/adm/pages/start-navigation.gif);
6306: }
6307:
1.795 www 6308: a#LC_content_toolbar_closenav {
1.774 ehlerst 6309: background-image:url(/res/adm/pages/close-navigation.gif);
6310: }
6311:
1.795 www 6312: a#LC_content_toolbar_everything {
1.774 ehlerst 6313: background-image:url(/res/adm/pages/show-all.gif);
6314: }
6315:
1.795 www 6316: a#LC_content_toolbar_uncompleted {
1.774 ehlerst 6317: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
6318: }
6319:
1.795 www 6320: #LC_content_toolbar_clearbubbles {
1.774 ehlerst 6321: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
6322: }
6323:
1.795 www 6324: a#LC_content_toolbar_changefolder {
1.757 schulted 6325: background : url(/res/adm/pages/close-all-folders.gif) top center ;
6326: }
6327:
1.795 www 6328: a#LC_content_toolbar_changefolder_toggled {
1.757 schulted 6329: background-image:url(/res/adm/pages/open-all-folders.gif);
6330: }
6331:
1.795 www 6332: ul#LC_toolbar li a:hover {
1.757 schulted 6333: background-position: bottom center;
6334: }
6335:
1.795 www 6336: ul#LC_toolbar {
1.803 bisitz 6337: padding: 0;
1.757 schulted 6338: margin: 2px;
6339: list-style:none;
6340: position:relative;
6341: background-color:white;
6342: }
6343:
1.795 www 6344: ul#LC_toolbar li {
1.757 schulted 6345: border:1px solid white;
1.803 bisitz 6346: padding: 0;
1.757 schulted 6347: margin: 0;
1.795 www 6348: float: left;
1.767 droeschl 6349: display:inline;
1.757 schulted 6350: vertical-align:middle;
1.795 www 6351: }
1.757 schulted 6352:
1.783 amueller 6353:
1.795 www 6354: a.LC_toolbarItem {
1.767 droeschl 6355: display:block;
1.803 bisitz 6356: padding: 0;
6357: margin: 0;
1.757 schulted 6358: height: 32px;
6359: width: 32px;
1.779 bisitz 6360: color:white;
1.803 bisitz 6361: border: none;
1.757 schulted 6362: background-repeat:no-repeat;
6363: background-color:transparent;
6364: }
6365:
1.843 bisitz 6366: ul.LC_funclist li {
1.782 bisitz 6367: float: left;
6368: white-space: nowrap;
6369: height: 35px; /* at least as high as heighest list item */
1.803 bisitz 6370: margin: 0 15px 15px 10px;
1.782 bisitz 6371: }
6372:
1.757 schulted 6373:
1.343 albertel 6374: END
6375: }
6376:
1.306 albertel 6377: =pod
6378:
6379: =item * &headtag()
6380:
6381: Returns a uniform footer for LON-CAPA web pages.
6382:
1.307 albertel 6383: Inputs: $title - optional title for the head
6384: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6385: $args - optional arguments
1.319 albertel 6386: force_register - if is true call registerurl so the remote is
6387: informed
1.415 albertel 6388: redirect -> array ref of
6389: 1- seconds before redirect occurs
6390: 2- url to redirect to
6391: 3- whether the side effect should occur
1.315 albertel 6392: (side effect of setting
6393: $env{'internal.head.redirect'} to the url
6394: redirected too)
1.352 albertel 6395: domain -> force to color decorate a page for a specific
6396: domain
6397: function -> force usage of a specific rolish color scheme
6398: bgcolor -> override the default page bgcolor
1.460 albertel 6399: no_auto_mt_title
6400: -> prevent &mt()ing the title arg
1.464 albertel 6401:
1.306 albertel 6402: =cut
6403:
6404: sub headtag {
1.313 albertel 6405: my ($title,$head_extra,$args) = @_;
1.306 albertel 6406:
1.363 albertel 6407: my $function = $args->{'function'} || &get_users_function();
6408: my $domain = $args->{'domain'} || &determinedomain();
6409: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6410: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6411: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6412: #time(),
1.418 albertel 6413: $env{'environment.color.timestamp'},
1.363 albertel 6414: $function,$domain,$bgcolor);
6415:
1.369 www 6416: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6417:
1.308 albertel 6418: my $result =
6419: '<head>'.
1.461 albertel 6420: &font_settings();
1.319 albertel 6421:
1.461 albertel 6422: if (!$args->{'frameset'}) {
6423: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6424: }
1.319 albertel 6425: if ($args->{'force_register'}) {
6426: $result .= &Apache::lonmenu::registerurl(1);
6427: }
1.436 albertel 6428: if (!$args->{'no_nav_bar'}
6429: && !$args->{'only_body'}
6430: && !$args->{'frameset'}) {
6431: $result .= &help_menu_js();
6432: }
1.319 albertel 6433:
1.314 albertel 6434: if (ref($args->{'redirect'})) {
1.414 albertel 6435: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6436: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6437: if (!$inhibit_continue) {
6438: $env{'internal.head.redirect'} = $url;
6439: }
1.313 albertel 6440: $result.=<<ADDMETA
6441: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6442: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6443: ADDMETA
6444: }
1.306 albertel 6445: if (!defined($title)) {
6446: $title = 'The LearningOnline Network with CAPA';
6447: }
1.460 albertel 6448: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6449: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6450: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6451: .$head_extra;
1.306 albertel 6452: return $result;
6453: }
6454:
6455: =pod
6456:
1.340 albertel 6457: =item * &font_settings()
6458:
6459: Returns neccessary <meta> to set the proper encoding
6460:
6461: Inputs: none
6462:
6463: =cut
6464:
6465: sub font_settings {
6466: my $headerstring='';
1.647 www 6467: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6468: $headerstring.=
6469: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6470: }
6471: return $headerstring;
6472: }
6473:
1.341 albertel 6474: =pod
6475:
6476: =item * &xml_begin()
6477:
6478: Returns the needed doctype and <html>
6479:
6480: Inputs: none
6481:
6482: =cut
6483:
6484: sub xml_begin {
6485: my $output='';
6486:
1.592 albertel 6487: if ($env{'internal.start_page'}==1) {
6488: &Apache::lonhtmlcommon::init_htmlareafields();
6489: }
1.342 albertel 6490:
1.341 albertel 6491: if ($env{'browser.mathml'}) {
6492: $output='<?xml version="1.0"?>'
6493: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6494: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6495:
6496: # .'<!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">] >'
6497: .'<!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">'
6498: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6499: .'xmlns="http://www.w3.org/1999/xhtml">';
6500: } else {
1.849 bisitz 6501: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6502: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6503: }
6504: return $output;
6505: }
1.340 albertel 6506:
6507: =pod
6508:
1.306 albertel 6509: =item * &endheadtag()
6510:
6511: Returns a uniform </head> for LON-CAPA web pages.
6512:
6513: Inputs: none
6514:
6515: =cut
6516:
6517: sub endheadtag {
6518: return '</head>';
6519: }
6520:
6521: =pod
6522:
6523: =item * &head()
6524:
6525: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6526:
1.648 raeburn 6527: Inputs:
6528:
6529: =over 4
6530:
6531: $title - optional title for the page
6532:
6533: $head_extra - optional extra HTML to put inside the <head>
6534:
6535: =back
1.405 albertel 6536:
1.306 albertel 6537: =cut
6538:
6539: sub head {
1.325 albertel 6540: my ($title,$head_extra,$args) = @_;
6541: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6542: }
6543:
6544: =pod
6545:
6546: =item * &start_page()
6547:
6548: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6549:
1.648 raeburn 6550: Inputs:
6551:
6552: =over 4
6553:
6554: $title - optional title for the page
6555:
6556: $head_extra - optional extra HTML to incude inside the <head>
6557:
6558: $args - additional optional args supported are:
6559:
6560: =over 8
6561:
6562: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6563: arg on
1.814 bisitz 6564: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6565: add_entries -> additional attributes to add to the <body>
6566: domain -> force to color decorate a page for a
1.317 albertel 6567: specific domain
1.648 raeburn 6568: function -> force usage of a specific rolish color
1.317 albertel 6569: scheme
1.648 raeburn 6570: redirect -> see &headtag()
6571: bgcolor -> override the default page bg color
6572: js_ready -> return a string ready for being used in
1.317 albertel 6573: a javascript writeln
1.648 raeburn 6574: html_encode -> return a string ready for being used in
1.320 albertel 6575: a html attribute
1.648 raeburn 6576: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6577: $forcereg arg
1.648 raeburn 6578: frameset -> if true will start with a <frameset>
1.330 albertel 6579: rather than <body>
1.648 raeburn 6580: skip_phases -> hash ref of
1.338 albertel 6581: head -> skip the <html><head> generation
6582: body -> skip all <body> generation
1.648 raeburn 6583: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6584: 'Switch To Inline Menu' link
1.648 raeburn 6585: no_auto_mt_title -> prevent &mt()ing the title arg
6586: inherit_jsmath -> when creating popup window in a page,
6587: should it have jsmath forced on by the
6588: current page
1.867 kalberla 6589: bread_crumbs -> Array containing breadcrumbs
6590: bread_crumbs_components -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6591:
1.648 raeburn 6592: =back
1.460 albertel 6593:
1.648 raeburn 6594: =back
1.562 albertel 6595:
1.306 albertel 6596: =cut
6597:
6598: sub start_page {
1.309 albertel 6599: my ($title,$head_extra,$args) = @_;
1.318 albertel 6600: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6601: my %head_args;
1.352 albertel 6602: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6603: 'bgcolor','frameset','no_nav_bar','only_body',
6604: 'no_auto_mt_title') {
1.319 albertel 6605: if (defined($args->{$arg})) {
1.324 raeburn 6606: $head_args{$arg} = $args->{$arg};
1.319 albertel 6607: }
1.313 albertel 6608: }
1.319 albertel 6609:
1.315 albertel 6610: $env{'internal.start_page'}++;
1.338 albertel 6611: my $result;
6612: if (! exists($args->{'skip_phases'}{'head'}) ) {
6613: $result.=
1.341 albertel 6614: &xml_begin().
1.338 albertel 6615: &headtag($title,$head_extra,\%head_args).&endheadtag();
6616: }
6617:
6618: if (! exists($args->{'skip_phases'}{'body'}) ) {
6619: if ($args->{'frameset'}) {
6620: my $attr_string = &make_attr_string($args->{'force_register'},
6621: $args->{'add_entries'});
6622: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6623: } else {
6624: $result .=
6625: &bodytag($title,
6626: $args->{'function'}, $args->{'add_entries'},
6627: $args->{'only_body'}, $args->{'domain'},
6628: $args->{'force_register'}, $args->{'no_nav_bar'},
6629: $args->{'bgcolor'}, $args->{'no_inline_link'},
6630: $args);
6631: }
1.330 albertel 6632: }
1.338 albertel 6633:
1.315 albertel 6634: if ($args->{'js_ready'}) {
1.713 kaisler 6635: $result = &js_ready($result);
1.315 albertel 6636: }
1.320 albertel 6637: if ($args->{'html_encode'}) {
1.713 kaisler 6638: $result = &html_encode($result);
6639: }
6640:
1.813 bisitz 6641: # Preparation for new and consistent functionlist at top of screen
6642: # if ($args->{'functionlist'}) {
6643: # $result .= &build_functionlist();
6644: #}
6645:
6646: # Don't add anything more if only_body wanted
6647: return $result if $args->{'only_body'};
6648:
6649: #Breadcrumbs
1.758 kaisler 6650: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6651: &Apache::lonhtmlcommon::clear_breadcrumbs();
6652: #if any br links exists, add them to the breadcrumbs
6653: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6654: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6655: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6656: }
6657: }
6658:
6659: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6660: if(exists($args->{'bread_crumbs_component'})){
6661: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6662: }else{
6663: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6664: }
1.320 albertel 6665: }
1.315 albertel 6666: return $result;
1.306 albertel 6667: }
6668:
1.330 albertel 6669:
1.306 albertel 6670: =pod
6671:
6672: =item * &head()
6673:
6674: Returns a complete </body></html> section for LON-CAPA web pages.
6675:
1.315 albertel 6676: Inputs: $args - additional optional args supported are:
6677: js_ready -> return a string ready for being used in
6678: a javascript writeln
1.320 albertel 6679: html_encode -> return a string ready for being used in
6680: a html attribute
1.330 albertel 6681: frameset -> if true will start with a <frameset>
6682: rather than <body>
1.493 albertel 6683: dicsussion -> if true will get discussion from
6684: lonxml::xmlend
6685: (you can pass the target and parser arguments
6686: through optional 'target' and 'parser' args
6687: to this routine)
1.306 albertel 6688:
6689: =cut
6690:
6691: sub end_page {
1.315 albertel 6692: my ($args) = @_;
6693: $env{'internal.end_page'}++;
1.330 albertel 6694: my $result;
1.335 albertel 6695: if ($args->{'discussion'}) {
6696: my ($target,$parser);
6697: if (ref($args->{'discussion'})) {
6698: ($target,$parser) =($args->{'discussion'}{'target'},
6699: $args->{'discussion'}{'parser'});
6700: }
6701: $result .= &Apache::lonxml::xmlend($target,$parser);
6702: }
6703:
1.330 albertel 6704: if ($args->{'frameset'}) {
6705: $result .= '</frameset>';
6706: } else {
1.635 raeburn 6707: $result .= &endbodytag($args);
1.330 albertel 6708: }
6709: $result .= "\n</html>";
6710:
1.315 albertel 6711: if ($args->{'js_ready'}) {
1.317 albertel 6712: $result = &js_ready($result);
1.315 albertel 6713: }
1.335 albertel 6714:
1.320 albertel 6715: if ($args->{'html_encode'}) {
6716: $result = &html_encode($result);
6717: }
1.335 albertel 6718:
1.315 albertel 6719: return $result;
6720: }
6721:
1.320 albertel 6722: sub html_encode {
6723: my ($result) = @_;
6724:
1.322 albertel 6725: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6726:
6727: return $result;
6728: }
1.317 albertel 6729: sub js_ready {
6730: my ($result) = @_;
6731:
1.323 albertel 6732: $result =~ s/[\n\r]/ /xmsg;
6733: $result =~ s/\\/\\\\/xmsg;
6734: $result =~ s/'/\\'/xmsg;
1.372 albertel 6735: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6736:
6737: return $result;
6738: }
6739:
1.315 albertel 6740: sub validate_page {
6741: if ( exists($env{'internal.start_page'})
1.316 albertel 6742: && $env{'internal.start_page'} > 1) {
6743: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6744: $env{'internal.start_page'}.' '.
1.316 albertel 6745: $ENV{'request.filename'});
1.315 albertel 6746: }
6747: if ( exists($env{'internal.end_page'})
1.316 albertel 6748: && $env{'internal.end_page'} > 1) {
6749: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6750: $env{'internal.end_page'}.' '.
1.316 albertel 6751: $env{'request.filename'});
1.315 albertel 6752: }
6753: if ( exists($env{'internal.start_page'})
6754: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6755: &Apache::lonnet::logthis('start_page called without end_page '.
6756: $env{'request.filename'});
1.315 albertel 6757: }
6758: if ( ! exists($env{'internal.start_page'})
6759: && exists($env{'internal.end_page'})) {
1.316 albertel 6760: &Apache::lonnet::logthis('end_page called without start_page'.
6761: $env{'request.filename'});
1.315 albertel 6762: }
1.306 albertel 6763: }
1.315 albertel 6764:
1.318 albertel 6765: sub simple_error_page {
6766: my ($r,$title,$msg) = @_;
6767: my $page =
6768: &Apache::loncommon::start_page($title).
6769: &mt($msg).
6770: &Apache::loncommon::end_page();
6771: if (ref($r)) {
6772: $r->print($page);
1.327 albertel 6773: return;
1.318 albertel 6774: }
6775: return $page;
6776: }
1.347 albertel 6777:
6778: {
1.610 albertel 6779: my @row_count;
1.347 albertel 6780: sub start_data_table {
1.422 albertel 6781: my ($add_class) = @_;
6782: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6783: unshift(@row_count,0);
1.422 albertel 6784: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6785: }
6786:
6787: sub end_data_table {
1.610 albertel 6788: shift(@row_count);
1.389 albertel 6789: return '</table>'."\n";;
1.347 albertel 6790: }
6791:
6792: sub start_data_table_row {
1.422 albertel 6793: my ($add_class) = @_;
1.610 albertel 6794: $row_count[0]++;
6795: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6796: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422 albertel 6797: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6798: }
1.471 banghart 6799:
6800: sub continue_data_table_row {
6801: my ($add_class) = @_;
1.610 albertel 6802: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6803: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471 banghart 6804: return '<tr class="'.$css_class.'">'."\n";;
6805: }
1.347 albertel 6806:
6807: sub end_data_table_row {
1.389 albertel 6808: return '</tr>'."\n";;
1.347 albertel 6809: }
1.367 www 6810:
1.421 albertel 6811: sub start_data_table_empty_row {
1.707 bisitz 6812: # $row_count[0]++;
1.421 albertel 6813: return '<tr class="LC_empty_row" >'."\n";;
6814: }
6815:
6816: sub end_data_table_empty_row {
6817: return '</tr>'."\n";;
6818: }
6819:
1.367 www 6820: sub start_data_table_header_row {
1.389 albertel 6821: return '<tr class="LC_header_row">'."\n";;
1.367 www 6822: }
6823:
6824: sub end_data_table_header_row {
1.389 albertel 6825: return '</tr>'."\n";;
1.367 www 6826: }
1.890 droeschl 6827:
6828: sub data_table_caption {
6829: my $caption = shift;
6830: return "<caption class=\"LC_caption\">$caption</caption>";
6831: }
1.347 albertel 6832: }
6833:
1.548 albertel 6834: =pod
6835:
6836: =item * &inhibit_menu_check($arg)
6837:
6838: Checks for a inhibitmenu state and generates output to preserve it
6839:
6840: Inputs: $arg - can be any of
6841: - undef - in which case the return value is a string
6842: to add into arguments list of a uri
6843: - 'input' - in which case the return value is a HTML
6844: <form> <input> field of type hidden to
6845: preserve the value
6846: - a url - in which case the return value is the url with
6847: the neccesary cgi args added to preserve the
6848: inhibitmenu state
6849: - a ref to a url - no return value, but the string is
6850: updated to include the neccessary cgi
6851: args to preserve the inhibitmenu state
6852:
6853: =cut
6854:
6855: sub inhibit_menu_check {
6856: my ($arg) = @_;
6857: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6858: if ($arg eq 'input') {
6859: if ($env{'form.inhibitmenu'}) {
6860: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6861: } else {
6862: return
6863: }
6864: }
6865: if ($env{'form.inhibitmenu'}) {
6866: if (ref($arg)) {
6867: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6868: } elsif ($arg eq '') {
6869: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6870: } else {
6871: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6872: }
6873: }
6874: if (!ref($arg)) {
6875: return $arg;
6876: }
6877: }
6878:
1.251 albertel 6879: ###############################################
1.182 matthew 6880:
6881: =pod
6882:
1.549 albertel 6883: =back
6884:
6885: =head1 User Information Routines
6886:
6887: =over 4
6888:
1.405 albertel 6889: =item * &get_users_function()
1.182 matthew 6890:
6891: Used by &bodytag to determine the current users primary role.
6892: Returns either 'student','coordinator','admin', or 'author'.
6893:
6894: =cut
6895:
6896: ###############################################
6897: sub get_users_function {
1.815 tempelho 6898: my $function = 'norole';
1.818 tempelho 6899: if ($env{'request.role'}=~/^(st)/) {
6900: $function='student';
6901: }
1.907 raeburn 6902: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 6903: $function='coordinator';
6904: }
1.258 albertel 6905: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6906: $function='admin';
6907: }
1.826 bisitz 6908: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6909: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6910: $function='author';
6911: }
6912: return $function;
1.54 www 6913: }
1.99 www 6914:
6915: ###############################################
6916:
1.233 raeburn 6917: =pod
6918:
1.821 raeburn 6919: =item * &show_course()
6920:
6921: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6922: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6923:
6924: Inputs:
6925: None
6926:
6927: Outputs:
6928: Scalar: 1 if 'Course' to be used, 0 otherwise.
6929:
6930: =cut
6931:
6932: ###############################################
6933: sub show_course {
6934: my $course = !$env{'user.adv'};
6935: if (!$env{'user.adv'}) {
6936: foreach my $env (keys(%env)) {
6937: next if ($env !~ m/^user\.priv\./);
6938: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6939: $course = 0;
6940: last;
6941: }
6942: }
6943: }
6944: return $course;
6945: }
6946:
6947: ###############################################
6948:
6949: =pod
6950:
1.542 raeburn 6951: =item * &check_user_status()
1.274 raeburn 6952:
6953: Determines current status of supplied role for a
6954: specific user. Roles can be active, previous or future.
6955:
6956: Inputs:
6957: user's domain, user's username, course's domain,
1.375 raeburn 6958: course's number, optional section ID.
1.274 raeburn 6959:
6960: Outputs:
6961: role status: active, previous or future.
6962:
6963: =cut
6964:
6965: sub check_user_status {
1.412 raeburn 6966: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6967: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6968: my @uroles = keys %userinfo;
6969: my $srchstr;
6970: my $active_chk = 'none';
1.412 raeburn 6971: my $now = time;
1.274 raeburn 6972: if (@uroles > 0) {
1.908 raeburn 6973: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6974: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6975: } else {
1.412 raeburn 6976: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6977: }
6978: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6979: my $role_end = 0;
6980: my $role_start = 0;
6981: $active_chk = 'active';
1.412 raeburn 6982: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6983: $role_end = $1;
6984: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6985: $role_start = $1;
1.274 raeburn 6986: }
6987: }
6988: if ($role_start > 0) {
1.412 raeburn 6989: if ($now < $role_start) {
1.274 raeburn 6990: $active_chk = 'future';
6991: }
6992: }
6993: if ($role_end > 0) {
1.412 raeburn 6994: if ($now > $role_end) {
1.274 raeburn 6995: $active_chk = 'previous';
6996: }
6997: }
6998: }
6999: }
7000: return $active_chk;
7001: }
7002:
7003: ###############################################
7004:
7005: =pod
7006:
1.405 albertel 7007: =item * &get_sections()
1.233 raeburn 7008:
7009: Determines all the sections for a course including
7010: sections with students and sections containing other roles.
1.419 raeburn 7011: Incoming parameters:
7012:
7013: 1. domain
7014: 2. course number
7015: 3. reference to array containing roles for which sections should
7016: be gathered (optional).
7017: 4. reference to array containing status types for which sections
7018: should be gathered (optional).
7019:
7020: If the third argument is undefined, sections are gathered for any role.
7021: If the fourth argument is undefined, sections are gathered for any status.
7022: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7023:
1.374 raeburn 7024: Returns section hash (keys are section IDs, values are
7025: number of users in each section), subject to the
1.419 raeburn 7026: optional roles filter, optional status filter
1.233 raeburn 7027:
7028: =cut
7029:
7030: ###############################################
7031: sub get_sections {
1.419 raeburn 7032: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7033: if (!defined($cdom) || !defined($cnum)) {
7034: my $cid = $env{'request.course.id'};
7035:
7036: return if (!defined($cid));
7037:
7038: $cdom = $env{'course.'.$cid.'.domain'};
7039: $cnum = $env{'course.'.$cid.'.num'};
7040: }
7041:
7042: my %sectioncount;
1.419 raeburn 7043: my $now = time;
1.240 albertel 7044:
1.366 albertel 7045: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7046: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7047: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7048: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7049: my $start_index = &Apache::loncoursedata::CL_START();
7050: my $end_index = &Apache::loncoursedata::CL_END();
7051: my $status;
1.366 albertel 7052: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7053: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7054: $data->[$status_index],
7055: $data->[$start_index],
7056: $data->[$end_index]);
7057: if ($stu_status eq 'Active') {
7058: $status = 'active';
7059: } elsif ($end < $now) {
7060: $status = 'previous';
7061: } elsif ($start > $now) {
7062: $status = 'future';
7063: }
7064: if ($section ne '-1' && $section !~ /^\s*$/) {
7065: if ((!defined($possible_status)) || (($status ne '') &&
7066: (grep/^\Q$status\E$/,@{$possible_status}))) {
7067: $sectioncount{$section}++;
7068: }
1.240 albertel 7069: }
7070: }
7071: }
7072: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7073: foreach my $user (sort(keys(%courseroles))) {
7074: if ($user !~ /^(\w{2})/) { next; }
7075: my ($role) = ($user =~ /^(\w{2})/);
7076: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7077: my ($section,$status);
1.240 albertel 7078: if ($role eq 'cr' &&
7079: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7080: $section=$1;
7081: }
7082: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7083: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7084: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7085: if ($end == -1 && $start == -1) {
7086: next; #deleted role
7087: }
7088: if (!defined($possible_status)) {
7089: $sectioncount{$section}++;
7090: } else {
7091: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7092: $status = 'active';
7093: } elsif ($end < $now) {
7094: $status = 'future';
7095: } elsif ($start > $now) {
7096: $status = 'previous';
7097: }
7098: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7099: $sectioncount{$section}++;
7100: }
7101: }
1.233 raeburn 7102: }
1.366 albertel 7103: return %sectioncount;
1.233 raeburn 7104: }
7105:
1.274 raeburn 7106: ###############################################
1.294 raeburn 7107:
7108: =pod
1.405 albertel 7109:
7110: =item * &get_course_users()
7111:
1.275 raeburn 7112: Retrieves usernames:domains for users in the specified course
7113: with specific role(s), and access status.
7114:
7115: Incoming parameters:
1.277 albertel 7116: 1. course domain
7117: 2. course number
7118: 3. access status: users must have - either active,
1.275 raeburn 7119: previous, future, or all.
1.277 albertel 7120: 4. reference to array of permissible roles
1.288 raeburn 7121: 5. reference to array of section restrictions (optional)
7122: 6. reference to results object (hash of hashes).
7123: 7. reference to optional userdata hash
1.609 raeburn 7124: 8. reference to optional statushash
1.630 raeburn 7125: 9. flag if privileged users (except those set to unhide in
7126: course settings) should be excluded
1.609 raeburn 7127: Keys of top level results hash are roles.
1.275 raeburn 7128: Keys of inner hashes are username:domain, with
7129: values set to access type.
1.288 raeburn 7130: Optional userdata hash returns an array with arguments in the
7131: same order as loncoursedata::get_classlist() for student data.
7132:
1.609 raeburn 7133: Optional statushash returns
7134:
1.288 raeburn 7135: Entries for end, start, section and status are blank because
7136: of the possibility of multiple values for non-student roles.
7137:
1.275 raeburn 7138: =cut
1.405 albertel 7139:
1.275 raeburn 7140: ###############################################
1.405 albertel 7141:
1.275 raeburn 7142: sub get_course_users {
1.630 raeburn 7143: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7144: my %idx = ();
1.419 raeburn 7145: my %seclists;
1.288 raeburn 7146:
7147: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7148: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7149: $idx{end} = &Apache::loncoursedata::CL_END();
7150: $idx{start} = &Apache::loncoursedata::CL_START();
7151: $idx{id} = &Apache::loncoursedata::CL_ID();
7152: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7153: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7154: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7155:
1.290 albertel 7156: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7157: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7158: my $now = time;
1.277 albertel 7159: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7160: my $match = 0;
1.412 raeburn 7161: my $secmatch = 0;
1.419 raeburn 7162: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7163: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7164: if ($section eq '') {
7165: $section = 'none';
7166: }
1.291 albertel 7167: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7168: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7169: $secmatch = 1;
7170: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7171: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7172: $secmatch = 1;
7173: }
7174: } else {
1.419 raeburn 7175: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7176: $secmatch = 1;
7177: }
1.290 albertel 7178: }
1.412 raeburn 7179: if (!$secmatch) {
7180: next;
7181: }
1.419 raeburn 7182: }
1.275 raeburn 7183: if (defined($$types{'active'})) {
1.288 raeburn 7184: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7185: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7186: $match = 1;
1.275 raeburn 7187: }
7188: }
7189: if (defined($$types{'previous'})) {
1.609 raeburn 7190: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7191: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7192: $match = 1;
1.275 raeburn 7193: }
7194: }
7195: if (defined($$types{'future'})) {
1.609 raeburn 7196: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7197: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7198: $match = 1;
1.275 raeburn 7199: }
7200: }
1.609 raeburn 7201: if ($match) {
7202: push(@{$seclists{$student}},$section);
7203: if (ref($userdata) eq 'HASH') {
7204: $$userdata{$student} = $$classlist{$student};
7205: }
7206: if (ref($statushash) eq 'HASH') {
7207: $statushash->{$student}{'st'}{$section} = $status;
7208: }
1.288 raeburn 7209: }
1.275 raeburn 7210: }
7211: }
1.412 raeburn 7212: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7213: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7214: my $now = time;
1.609 raeburn 7215: my %displaystatus = ( previous => 'Expired',
7216: active => 'Active',
7217: future => 'Future',
7218: );
1.630 raeburn 7219: my %nothide;
7220: if ($hidepriv) {
7221: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7222: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7223: if ($user !~ /:/) {
7224: $nothide{join(':',split(/[\@]/,$user))}=1;
7225: } else {
7226: $nothide{$user} = 1;
7227: }
7228: }
7229: }
1.439 raeburn 7230: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7231: my $match = 0;
1.412 raeburn 7232: my $secmatch = 0;
1.439 raeburn 7233: my $status;
1.412 raeburn 7234: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7235: $user =~ s/:$//;
1.439 raeburn 7236: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7237: if ($end == -1 || $start == -1) {
7238: next;
7239: }
7240: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7241: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7242: my ($uname,$udom) = split(/:/,$user);
7243: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7244: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7245: $secmatch = 1;
7246: } elsif ($usec eq '') {
1.420 albertel 7247: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7248: $secmatch = 1;
7249: }
7250: } else {
7251: if (grep(/^\Q$usec\E$/,@{$sections})) {
7252: $secmatch = 1;
7253: }
7254: }
7255: if (!$secmatch) {
7256: next;
7257: }
1.288 raeburn 7258: }
1.419 raeburn 7259: if ($usec eq '') {
7260: $usec = 'none';
7261: }
1.275 raeburn 7262: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7263: if ($hidepriv) {
7264: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7265: (!$nothide{$uname.':'.$udom})) {
7266: next;
7267: }
7268: }
1.503 raeburn 7269: if ($end > 0 && $end < $now) {
1.439 raeburn 7270: $status = 'previous';
7271: } elsif ($start > $now) {
7272: $status = 'future';
7273: } else {
7274: $status = 'active';
7275: }
1.277 albertel 7276: foreach my $type (keys(%{$types})) {
1.275 raeburn 7277: if ($status eq $type) {
1.420 albertel 7278: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7279: push(@{$$users{$role}{$user}},$type);
7280: }
1.288 raeburn 7281: $match = 1;
7282: }
7283: }
1.419 raeburn 7284: if (($match) && (ref($userdata) eq 'HASH')) {
7285: if (!exists($$userdata{$uname.':'.$udom})) {
7286: &get_user_info($udom,$uname,\%idx,$userdata);
7287: }
1.420 albertel 7288: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7289: push(@{$seclists{$uname.':'.$udom}},$usec);
7290: }
1.609 raeburn 7291: if (ref($statushash) eq 'HASH') {
7292: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7293: }
1.275 raeburn 7294: }
7295: }
7296: }
7297: }
1.290 albertel 7298: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7299: if ((defined($cdom)) && (defined($cnum))) {
7300: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7301: if ( defined($csettings{'internal.courseowner'}) ) {
7302: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7303: next if ($owner eq '');
7304: my ($ownername,$ownerdom);
7305: if ($owner =~ /^([^:]+):([^:]+)$/) {
7306: $ownername = $1;
7307: $ownerdom = $2;
7308: } else {
7309: $ownername = $owner;
7310: $ownerdom = $cdom;
7311: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7312: }
7313: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7314: if (defined($userdata) &&
1.609 raeburn 7315: !exists($$userdata{$owner})) {
7316: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7317: if (!grep(/^none$/,@{$seclists{$owner}})) {
7318: push(@{$seclists{$owner}},'none');
7319: }
7320: if (ref($statushash) eq 'HASH') {
7321: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7322: }
1.290 albertel 7323: }
1.279 raeburn 7324: }
7325: }
7326: }
1.419 raeburn 7327: foreach my $user (keys(%seclists)) {
7328: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7329: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7330: }
1.275 raeburn 7331: }
7332: return;
7333: }
7334:
1.288 raeburn 7335: sub get_user_info {
7336: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7337: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7338: &plainname($uname,$udom,'lastname');
1.291 albertel 7339: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7340: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7341: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7342: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7343: return;
7344: }
1.275 raeburn 7345:
1.472 raeburn 7346: ###############################################
7347:
7348: =pod
7349:
7350: =item * &get_user_quota()
7351:
7352: Retrieves quota assigned for storage of portfolio files for a user
7353:
7354: Incoming parameters:
7355: 1. user's username
7356: 2. user's domain
7357:
7358: Returns:
1.536 raeburn 7359: 1. Disk quota (in Mb) assigned to student.
7360: 2. (Optional) Type of setting: custom or default
7361: (individually assigned or default for user's
7362: institutional status).
7363: 3. (Optional) - User's institutional status (e.g., faculty, staff
7364: or student - types as defined in localenroll::inst_usertypes
7365: for user's domain, which determines default quota for user.
7366: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7367:
7368: If a value has been stored in the user's environment,
1.536 raeburn 7369: it will return that, otherwise it returns the maximal default
7370: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7371:
7372: =cut
7373:
7374: ###############################################
7375:
7376:
7377: sub get_user_quota {
7378: my ($uname,$udom) = @_;
1.536 raeburn 7379: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7380: if (!defined($udom)) {
7381: $udom = $env{'user.domain'};
7382: }
7383: if (!defined($uname)) {
7384: $uname = $env{'user.name'};
7385: }
7386: if (($udom eq '' || $uname eq '') ||
7387: ($udom eq 'public') && ($uname eq 'public')) {
7388: $quota = 0;
1.536 raeburn 7389: $quotatype = 'default';
7390: $defquota = 0;
1.472 raeburn 7391: } else {
1.536 raeburn 7392: my $inststatus;
1.472 raeburn 7393: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7394: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7395: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7396: } else {
1.536 raeburn 7397: my %userenv =
7398: &Apache::lonnet::get('environment',['portfolioquota',
7399: 'inststatus'],$udom,$uname);
1.472 raeburn 7400: my ($tmp) = keys(%userenv);
7401: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7402: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7403: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7404: } else {
7405: undef(%userenv);
7406: }
7407: }
1.536 raeburn 7408: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7409: if ($quota eq '') {
1.536 raeburn 7410: $quota = $defquota;
7411: $quotatype = 'default';
7412: } else {
7413: $quotatype = 'custom';
1.472 raeburn 7414: }
7415: }
1.536 raeburn 7416: if (wantarray) {
7417: return ($quota,$quotatype,$settingstatus,$defquota);
7418: } else {
7419: return $quota;
7420: }
1.472 raeburn 7421: }
7422:
7423: ###############################################
7424:
7425: =pod
7426:
7427: =item * &default_quota()
7428:
1.536 raeburn 7429: Retrieves default quota assigned for storage of user portfolio files,
7430: given an (optional) user's institutional status.
1.472 raeburn 7431:
7432: Incoming parameters:
7433: 1. domain
1.536 raeburn 7434: 2. (Optional) institutional status(es). This is a : separated list of
7435: status types (e.g., faculty, staff, student etc.)
7436: which apply to the user for whom the default is being retrieved.
7437: If the institutional status string in undefined, the domain
7438: default quota will be returned.
1.472 raeburn 7439:
7440: Returns:
7441: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7442: 2. (Optional) institutional type which determined the value of the
7443: default quota.
1.472 raeburn 7444:
7445: If a value has been stored in the domain's configuration db,
7446: it will return that, otherwise it returns 20 (for backwards
7447: compatibility with domains which have not set up a configuration
7448: db file; the original statically defined portfolio quota was 20 Mb).
7449:
1.536 raeburn 7450: If the user's status includes multiple types (e.g., staff and student),
7451: the largest default quota which applies to the user determines the
7452: default quota returned.
7453:
1.780 raeburn 7454: =back
7455:
1.472 raeburn 7456: =cut
7457:
7458: ###############################################
7459:
7460:
7461: sub default_quota {
1.536 raeburn 7462: my ($udom,$inststatus) = @_;
7463: my ($defquota,$settingstatus);
7464: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7465: ['quotas'],$udom);
7466: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7467: if ($inststatus ne '') {
1.765 raeburn 7468: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7469: foreach my $item (@statuses) {
1.711 raeburn 7470: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7471: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7472: if ($defquota eq '') {
7473: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7474: $settingstatus = $item;
7475: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7476: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7477: $settingstatus = $item;
7478: }
7479: }
7480: } else {
7481: if ($quotahash{'quotas'}{$item} ne '') {
7482: if ($defquota eq '') {
7483: $defquota = $quotahash{'quotas'}{$item};
7484: $settingstatus = $item;
7485: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7486: $defquota = $quotahash{'quotas'}{$item};
7487: $settingstatus = $item;
7488: }
1.536 raeburn 7489: }
7490: }
7491: }
7492: }
7493: if ($defquota eq '') {
1.711 raeburn 7494: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7495: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7496: } else {
7497: $defquota = $quotahash{'quotas'}{'default'};
7498: }
1.536 raeburn 7499: $settingstatus = 'default';
7500: }
7501: } else {
7502: $settingstatus = 'default';
7503: $defquota = 20;
7504: }
7505: if (wantarray) {
7506: return ($defquota,$settingstatus);
1.472 raeburn 7507: } else {
1.536 raeburn 7508: return $defquota;
1.472 raeburn 7509: }
7510: }
7511:
1.384 raeburn 7512: sub get_secgrprole_info {
7513: my ($cdom,$cnum,$needroles,$type) = @_;
7514: my %sections_count = &get_sections($cdom,$cnum);
7515: my @sections = (sort {$a <=> $b} keys(%sections_count));
7516: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7517: my @groups = sort(keys(%curr_groups));
7518: my $allroles = [];
7519: my $rolehash;
7520: my $accesshash = {
7521: active => 'Currently has access',
7522: future => 'Will have future access',
7523: previous => 'Previously had access',
7524: };
7525: if ($needroles) {
7526: $rolehash = {'all' => 'all'};
1.385 albertel 7527: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7528: if (&Apache::lonnet::error(%user_roles)) {
7529: undef(%user_roles);
7530: }
7531: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7532: my ($role)=split(/\:/,$item,2);
7533: if ($role eq 'cr') { next; }
7534: if ($role =~ /^cr/) {
7535: $$rolehash{$role} = (split('/',$role))[3];
7536: } else {
7537: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7538: }
7539: }
7540: foreach my $key (sort(keys(%{$rolehash}))) {
7541: push(@{$allroles},$key);
7542: }
7543: push (@{$allroles},'st');
7544: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7545: }
7546: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7547: }
7548:
1.555 raeburn 7549: sub user_picker {
1.627 raeburn 7550: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7551: my $currdom = $dom;
7552: my %curr_selected = (
7553: srchin => 'dom',
1.580 raeburn 7554: srchby => 'lastname',
1.555 raeburn 7555: );
7556: my $srchterm;
1.625 raeburn 7557: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7558: if ($srch->{'srchby'} ne '') {
7559: $curr_selected{'srchby'} = $srch->{'srchby'};
7560: }
7561: if ($srch->{'srchin'} ne '') {
7562: $curr_selected{'srchin'} = $srch->{'srchin'};
7563: }
7564: if ($srch->{'srchtype'} ne '') {
7565: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7566: }
7567: if ($srch->{'srchdomain'} ne '') {
7568: $currdom = $srch->{'srchdomain'};
7569: }
7570: $srchterm = $srch->{'srchterm'};
7571: }
7572: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7573: 'usr' => 'Search criteria',
1.563 raeburn 7574: 'doma' => 'Domain/institution to search',
1.558 albertel 7575: 'uname' => 'username',
7576: 'lastname' => 'last name',
1.555 raeburn 7577: 'lastfirst' => 'last name, first name',
1.558 albertel 7578: 'crs' => 'in this course',
1.576 raeburn 7579: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7580: 'alc' => 'all LON-CAPA',
1.573 raeburn 7581: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7582: 'exact' => 'is',
7583: 'contains' => 'contains',
1.569 raeburn 7584: 'begins' => 'begins with',
1.571 raeburn 7585: 'youm' => "You must include some text to search for.",
7586: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7587: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7588: 'yomc' => "You must choose a domain when using an institutional directory search.",
7589: 'ymcd' => "You must choose a domain when using a domain search.",
7590: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7591: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7592: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7593: );
1.563 raeburn 7594: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7595: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7596:
7597: my @srchins = ('crs','dom','alc','instd');
7598:
7599: foreach my $option (@srchins) {
7600: # FIXME 'alc' option unavailable until
7601: # loncreateuser::print_user_query_page()
7602: # has been completed.
7603: next if ($option eq 'alc');
1.880 raeburn 7604: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7605: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7606: if ($curr_selected{'srchin'} eq $option) {
7607: $srchinsel .= '
7608: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7609: } else {
7610: $srchinsel .= '
7611: <option value="'.$option.'">'.$lt{$option}.'</option>';
7612: }
1.555 raeburn 7613: }
1.563 raeburn 7614: $srchinsel .= "\n </select>\n";
1.555 raeburn 7615:
7616: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7617: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7618: if ($curr_selected{'srchby'} eq $option) {
7619: $srchbysel .= '
7620: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7621: } else {
7622: $srchbysel .= '
7623: <option value="'.$option.'">'.$lt{$option}.'</option>';
7624: }
7625: }
7626: $srchbysel .= "\n </select>\n";
7627:
7628: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7629: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7630: if ($curr_selected{'srchtype'} eq $option) {
7631: $srchtypesel .= '
7632: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7633: } else {
7634: $srchtypesel .= '
7635: <option value="'.$option.'">'.$lt{$option}.'</option>';
7636: }
7637: }
7638: $srchtypesel .= "\n </select>\n";
7639:
1.558 albertel 7640: my ($newuserscript,$new_user_create);
1.556 raeburn 7641:
7642: if ($forcenewuser) {
1.576 raeburn 7643: if (ref($srch) eq 'HASH') {
7644: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7645: if ($cancreate) {
7646: $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>';
7647: } else {
1.799 bisitz 7648: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7649: my %usertypetext = (
7650: official => 'institutional',
7651: unofficial => 'non-institutional',
7652: );
1.799 bisitz 7653: $new_user_create = '<p class="LC_warning">'
7654: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7655: .' '
7656: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7657: ,'<a href="'.$helplink.'">','</a>')
7658: .'</p><br />';
1.627 raeburn 7659: }
1.576 raeburn 7660: }
7661: }
7662:
1.556 raeburn 7663: $newuserscript = <<"ENDSCRIPT";
7664:
1.570 raeburn 7665: function setSearch(createnew,callingForm) {
1.556 raeburn 7666: if (createnew == 1) {
1.570 raeburn 7667: for (var i=0; i<callingForm.srchby.length; i++) {
7668: if (callingForm.srchby.options[i].value == 'uname') {
7669: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7670: }
7671: }
1.570 raeburn 7672: for (var i=0; i<callingForm.srchin.length; i++) {
7673: if ( callingForm.srchin.options[i].value == 'dom') {
7674: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7675: }
7676: }
1.570 raeburn 7677: for (var i=0; i<callingForm.srchtype.length; i++) {
7678: if (callingForm.srchtype.options[i].value == 'exact') {
7679: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7680: }
7681: }
1.570 raeburn 7682: for (var i=0; i<callingForm.srchdomain.length; i++) {
7683: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7684: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7685: }
7686: }
7687: }
7688: }
7689: ENDSCRIPT
1.558 albertel 7690:
1.556 raeburn 7691: }
7692:
1.555 raeburn 7693: my $output = <<"END_BLOCK";
1.556 raeburn 7694: <script type="text/javascript">
1.824 bisitz 7695: // <![CDATA[
1.570 raeburn 7696: function validateEntry(callingForm) {
1.558 albertel 7697:
1.556 raeburn 7698: var checkok = 1;
1.558 albertel 7699: var srchin;
1.570 raeburn 7700: for (var i=0; i<callingForm.srchin.length; i++) {
7701: if ( callingForm.srchin[i].checked ) {
7702: srchin = callingForm.srchin[i].value;
1.558 albertel 7703: }
7704: }
7705:
1.570 raeburn 7706: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7707: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7708: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7709: var srchterm = callingForm.srchterm.value;
7710: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7711: var msg = "";
7712:
7713: if (srchterm == "") {
7714: checkok = 0;
1.571 raeburn 7715: msg += "$lt{'youm'}\\n";
1.556 raeburn 7716: }
7717:
1.569 raeburn 7718: if (srchtype== 'begins') {
7719: if (srchterm.length < 2) {
7720: checkok = 0;
1.571 raeburn 7721: msg += "$lt{'thte'}\\n";
1.569 raeburn 7722: }
7723: }
7724:
1.556 raeburn 7725: if (srchtype== 'contains') {
7726: if (srchterm.length < 3) {
7727: checkok = 0;
1.571 raeburn 7728: msg += "$lt{'thet'}\\n";
1.556 raeburn 7729: }
7730: }
7731: if (srchin == 'instd') {
7732: if (srchdomain == '') {
7733: checkok = 0;
1.571 raeburn 7734: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7735: }
7736: }
7737: if (srchin == 'dom') {
7738: if (srchdomain == '') {
7739: checkok = 0;
1.571 raeburn 7740: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7741: }
7742: }
7743: if (srchby == 'lastfirst') {
7744: if (srchterm.indexOf(",") == -1) {
7745: checkok = 0;
1.571 raeburn 7746: msg += "$lt{'whus'}\\n";
1.556 raeburn 7747: }
7748: if (srchterm.indexOf(",") == srchterm.length -1) {
7749: checkok = 0;
1.571 raeburn 7750: msg += "$lt{'whse'}\\n";
1.556 raeburn 7751: }
7752: }
7753: if (checkok == 0) {
1.571 raeburn 7754: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7755: return;
7756: }
7757: if (checkok == 1) {
1.570 raeburn 7758: callingForm.submit();
1.556 raeburn 7759: }
7760: }
7761:
7762: $newuserscript
7763:
1.824 bisitz 7764: // ]]>
1.556 raeburn 7765: </script>
1.558 albertel 7766:
7767: $new_user_create
7768:
1.555 raeburn 7769: END_BLOCK
1.558 albertel 7770:
1.876 raeburn 7771: $output .= &Apache::lonhtmlcommon::start_pick_box().
7772: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7773: $domform.
7774: &Apache::lonhtmlcommon::row_closure().
7775: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7776: $srchbysel.
7777: $srchtypesel.
7778: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7779: $srchinsel.
7780: &Apache::lonhtmlcommon::row_closure(1).
7781: &Apache::lonhtmlcommon::end_pick_box().
7782: '<br />';
1.555 raeburn 7783: return $output;
7784: }
7785:
1.612 raeburn 7786: sub user_rule_check {
1.615 raeburn 7787: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7788: my $response;
7789: if (ref($usershash) eq 'HASH') {
7790: foreach my $user (keys(%{$usershash})) {
7791: my ($uname,$udom) = split(/:/,$user);
7792: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7793: my ($id,$newuser);
1.612 raeburn 7794: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7795: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7796: $id = $usershash->{$user}->{'id'};
7797: }
7798: my $inst_response;
7799: if (ref($checks) eq 'HASH') {
7800: if (defined($checks->{'username'})) {
1.615 raeburn 7801: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7802: &Apache::lonnet::get_instuser($udom,$uname);
7803: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7804: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7805: &Apache::lonnet::get_instuser($udom,undef,$id);
7806: }
1.615 raeburn 7807: } else {
7808: ($inst_response,%{$inst_results->{$user}}) =
7809: &Apache::lonnet::get_instuser($udom,$uname);
7810: return;
1.612 raeburn 7811: }
1.615 raeburn 7812: if (!$got_rules->{$udom}) {
1.612 raeburn 7813: my %domconfig = &Apache::lonnet::get_dom('configuration',
7814: ['usercreation'],$udom);
7815: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7816: foreach my $item ('username','id') {
1.612 raeburn 7817: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7818: $$curr_rules{$udom}{$item} =
7819: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7820: }
7821: }
7822: }
1.615 raeburn 7823: $got_rules->{$udom} = 1;
1.585 raeburn 7824: }
1.612 raeburn 7825: foreach my $item (keys(%{$checks})) {
7826: if (ref($$curr_rules{$udom}) eq 'HASH') {
7827: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7828: if (@{$$curr_rules{$udom}{$item}} > 0) {
7829: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7830: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7831: if ($rule_check{$rule}) {
7832: $$rulematch{$user}{$item} = $rule;
7833: if ($inst_response eq 'ok') {
1.615 raeburn 7834: if (ref($inst_results) eq 'HASH') {
7835: if (ref($inst_results->{$user}) eq 'HASH') {
7836: if (keys(%{$inst_results->{$user}}) == 0) {
7837: $$alerts{$item}{$udom}{$uname} = 1;
7838: }
1.612 raeburn 7839: }
7840: }
1.615 raeburn 7841: }
7842: last;
1.585 raeburn 7843: }
7844: }
7845: }
7846: }
7847: }
7848: }
7849: }
7850: }
1.612 raeburn 7851: return;
7852: }
7853:
7854: sub user_rule_formats {
7855: my ($domain,$domdesc,$curr_rules,$check) = @_;
7856: my %text = (
7857: 'username' => 'Usernames',
7858: 'id' => 'IDs',
7859: );
7860: my $output;
7861: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7862: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7863: if (@{$ruleorder} > 0) {
7864: $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>';
7865: foreach my $rule (@{$ruleorder}) {
7866: if (ref($curr_rules) eq 'ARRAY') {
7867: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7868: if (ref($rules->{$rule}) eq 'HASH') {
7869: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7870: $rules->{$rule}{'desc'}.'</li>';
7871: }
7872: }
7873: }
7874: }
7875: $output .= '</ul>';
7876: }
7877: }
7878: return $output;
7879: }
7880:
7881: sub instrule_disallow_msg {
1.615 raeburn 7882: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7883: my $response;
7884: my %text = (
7885: item => 'username',
7886: items => 'usernames',
7887: match => 'matches',
7888: do => 'does',
7889: action => 'a username',
7890: one => 'one',
7891: );
7892: if ($count > 1) {
7893: $text{'item'} = 'usernames';
7894: $text{'match'} ='match';
7895: $text{'do'} = 'do';
7896: $text{'action'} = 'usernames',
7897: $text{'one'} = 'ones';
7898: }
7899: if ($checkitem eq 'id') {
7900: $text{'items'} = 'IDs';
7901: $text{'item'} = 'ID';
7902: $text{'action'} = 'an ID';
1.615 raeburn 7903: if ($count > 1) {
7904: $text{'item'} = 'IDs';
7905: $text{'action'} = 'IDs';
7906: }
1.612 raeburn 7907: }
1.674 bisitz 7908: $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 7909: if ($mode eq 'upload') {
7910: if ($checkitem eq 'username') {
7911: $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'}.");
7912: } elsif ($checkitem eq 'id') {
1.674 bisitz 7913: $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 7914: }
1.669 raeburn 7915: } elsif ($mode eq 'selfcreate') {
7916: if ($checkitem eq 'id') {
7917: $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.");
7918: }
1.615 raeburn 7919: } else {
7920: if ($checkitem eq 'username') {
7921: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7922: } elsif ($checkitem eq 'id') {
7923: $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.");
7924: }
1.612 raeburn 7925: }
7926: return $response;
1.585 raeburn 7927: }
7928:
1.624 raeburn 7929: sub personal_data_fieldtitles {
7930: my %fieldtitles = &Apache::lonlocal::texthash (
7931: id => 'Student/Employee ID',
7932: permanentemail => 'E-mail address',
7933: lastname => 'Last Name',
7934: firstname => 'First Name',
7935: middlename => 'Middle Name',
7936: generation => 'Generation',
7937: gen => 'Generation',
1.765 raeburn 7938: inststatus => 'Affiliation',
1.624 raeburn 7939: );
7940: return %fieldtitles;
7941: }
7942:
1.642 raeburn 7943: sub sorted_inst_types {
7944: my ($dom) = @_;
7945: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7946: my $othertitle = &mt('All users');
7947: if ($env{'request.course.id'}) {
1.668 raeburn 7948: $othertitle = &mt('Any users');
1.642 raeburn 7949: }
7950: my @types;
7951: if (ref($order) eq 'ARRAY') {
7952: @types = @{$order};
7953: }
7954: if (@types == 0) {
7955: if (ref($usertypes) eq 'HASH') {
7956: @types = sort(keys(%{$usertypes}));
7957: }
7958: }
7959: if (keys(%{$usertypes}) > 0) {
7960: $othertitle = &mt('Other users');
7961: }
7962: return ($othertitle,$usertypes,\@types);
7963: }
7964:
1.645 raeburn 7965: sub get_institutional_codes {
7966: my ($settings,$allcourses,$LC_code) = @_;
7967: # Get complete list of course sections to update
7968: my @currsections = ();
7969: my @currxlists = ();
7970: my $coursecode = $$settings{'internal.coursecode'};
7971:
7972: if ($$settings{'internal.sectionnums'} ne '') {
7973: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7974: }
7975:
7976: if ($$settings{'internal.crosslistings'} ne '') {
7977: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7978: }
7979:
7980: if (@currxlists > 0) {
7981: foreach (@currxlists) {
7982: if (m/^([^:]+):(\w*)$/) {
7983: unless (grep/^$1$/,@{$allcourses}) {
7984: push @{$allcourses},$1;
7985: $$LC_code{$1} = $2;
7986: }
7987: }
7988: }
7989: }
7990:
7991: if (@currsections > 0) {
7992: foreach (@currsections) {
7993: if (m/^(\w+):(\w*)$/) {
7994: my $sec = $coursecode.$1;
7995: my $lc_sec = $2;
7996: unless (grep/^$sec$/,@{$allcourses}) {
7997: push @{$allcourses},$sec;
7998: $$LC_code{$sec} = $lc_sec;
7999: }
8000: }
8001: }
8002: }
8003: return;
8004: }
8005:
1.112 bowersj2 8006: =pod
8007:
1.780 raeburn 8008: =head1 Slot Helpers
8009:
8010: =over 4
8011:
8012: =item * sorted_slots()
8013:
8014: Sorts an array of slot names in order of slot start time (earliest first).
8015:
8016: Inputs:
8017:
8018: =over 4
8019:
8020: slotsarr - Reference to array of unsorted slot names.
8021:
8022: slots - Reference to hash of hash, where outer hash keys are slot names.
8023:
1.549 albertel 8024: =back
8025:
1.780 raeburn 8026: Returns:
8027:
8028: =over 4
8029:
8030: sorted - An array of slot names sorted by the start time of the slot.
8031:
8032: =back
8033:
8034: =back
8035:
8036: =cut
8037:
8038:
8039: sub sorted_slots {
8040: my ($slotsarr,$slots) = @_;
8041: my @sorted;
8042: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8043: @sorted =
8044: sort {
8045: if (ref($slots->{$a}) && ref($slots->{$b})) {
8046: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8047: }
8048: if (ref($slots->{$a})) { return -1;}
8049: if (ref($slots->{$b})) { return 1;}
8050: return 0;
8051: } @{$slotsarr};
8052: }
8053: return @sorted;
8054: }
8055:
8056:
8057: =pod
8058:
1.549 albertel 8059: =head1 HTTP Helpers
8060:
8061: =over 4
8062:
1.648 raeburn 8063: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8064:
1.258 albertel 8065: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8066: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8067: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8068:
8069: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8070: $possible_names is an ref to an array of form element names. As an example:
8071: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8072: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8073:
8074: =cut
1.1 albertel 8075:
1.6 albertel 8076: sub get_unprocessed_cgi {
1.25 albertel 8077: my ($query,$possible_names)= @_;
1.26 matthew 8078: # $Apache::lonxml::debug=1;
1.356 albertel 8079: foreach my $pair (split(/&/,$query)) {
8080: my ($name, $value) = split(/=/,$pair);
1.369 www 8081: $name = &unescape($name);
1.25 albertel 8082: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8083: $value =~ tr/+/ /;
8084: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8085: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8086: }
1.16 harris41 8087: }
1.6 albertel 8088: }
8089:
1.112 bowersj2 8090: =pod
8091:
1.648 raeburn 8092: =item * &cacheheader()
1.112 bowersj2 8093:
8094: returns cache-controlling header code
8095:
8096: =cut
8097:
1.7 albertel 8098: sub cacheheader {
1.258 albertel 8099: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8100: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8101: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8102: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8103: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8104: return $output;
1.7 albertel 8105: }
8106:
1.112 bowersj2 8107: =pod
8108:
1.648 raeburn 8109: =item * &no_cache($r)
1.112 bowersj2 8110:
8111: specifies header code to not have cache
8112:
8113: =cut
8114:
1.9 albertel 8115: sub no_cache {
1.216 albertel 8116: my ($r) = @_;
8117: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8118: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8119: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8120: $r->no_cache(1);
8121: $r->header_out("Expires" => $date);
8122: $r->header_out("Pragma" => "no-cache");
1.123 www 8123: }
8124:
8125: sub content_type {
1.181 albertel 8126: my ($r,$type,$charset) = @_;
1.299 foxr 8127: if ($r) {
8128: # Note that printout.pl calls this with undef for $r.
8129: &no_cache($r);
8130: }
1.258 albertel 8131: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8132: unless ($charset) {
8133: $charset=&Apache::lonlocal::current_encoding;
8134: }
8135: if ($charset) { $type.='; charset='.$charset; }
8136: if ($r) {
8137: $r->content_type($type);
8138: } else {
8139: print("Content-type: $type\n\n");
8140: }
1.9 albertel 8141: }
1.25 albertel 8142:
1.112 bowersj2 8143: =pod
8144:
1.648 raeburn 8145: =item * &add_to_env($name,$value)
1.112 bowersj2 8146:
1.258 albertel 8147: adds $name to the %env hash with value
1.112 bowersj2 8148: $value, if $name already exists, the entry is converted to an array
8149: reference and $value is added to the array.
8150:
8151: =cut
8152:
1.25 albertel 8153: sub add_to_env {
8154: my ($name,$value)=@_;
1.258 albertel 8155: if (defined($env{$name})) {
8156: if (ref($env{$name})) {
1.25 albertel 8157: #already have multiple values
1.258 albertel 8158: push(@{ $env{$name} },$value);
1.25 albertel 8159: } else {
8160: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8161: my $first=$env{$name};
8162: undef($env{$name});
8163: push(@{ $env{$name} },$first,$value);
1.25 albertel 8164: }
8165: } else {
1.258 albertel 8166: $env{$name}=$value;
1.25 albertel 8167: }
1.31 albertel 8168: }
1.149 albertel 8169:
8170: =pod
8171:
1.648 raeburn 8172: =item * &get_env_multiple($name)
1.149 albertel 8173:
1.258 albertel 8174: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8175: values may be defined and end up as an array ref.
8176:
8177: returns an array of values
8178:
8179: =cut
8180:
8181: sub get_env_multiple {
8182: my ($name) = @_;
8183: my @values;
1.258 albertel 8184: if (defined($env{$name})) {
1.149 albertel 8185: # exists is it an array
1.258 albertel 8186: if (ref($env{$name})) {
8187: @values=@{ $env{$name} };
1.149 albertel 8188: } else {
1.258 albertel 8189: $values[0]=$env{$name};
1.149 albertel 8190: }
8191: }
8192: return(@values);
8193: }
8194:
1.660 raeburn 8195: sub ask_for_embedded_content {
8196: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
8197: my $upload_output = '
8198: <form name="upload_embedded" action="'.$actionurl.'"
8199: method="post" enctype="multipart/form-data">';
8200: $upload_output .= $state;
1.661 raeburn 8201: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 8202:
8203: my $num = 0;
8204: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
8205: $upload_output .= &start_data_table_row().
8206: '<td>'.$embed_file.'</td><td>';
8207: if ($args->{'ignore_remote_references'}
8208: && $embed_file =~ m{^\w+://}) {
8209: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8210: } elsif ($args->{'error_on_invalid_names'}
8211: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8212:
8213: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8214:
8215: } else {
8216: $upload_output .='
1.661 raeburn 8217: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8218: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8219: my $attrib = join(':',@{$$allfiles{$embed_file}});
8220: $upload_output .=
8221: "\n\t\t".
8222: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8223: $attrib.'" />';
8224: if (exists($$codebase{$embed_file})) {
8225: $upload_output .=
8226: "\n\t\t".
8227: '<input name="codebase_'.$num.'" type="hidden" value="'.
8228: &escape($$codebase{$embed_file}).'" />';
8229: }
8230: }
8231: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
8232: $num++;
8233: }
8234: $upload_output .= &Apache::loncommon::end_data_table().'<br />
8235: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
8236: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
8237: '.&mt('(only files for which a location has been provided will be uploaded)').'
8238: </form>';
8239: return $upload_output;
8240: }
8241:
1.661 raeburn 8242: sub upload_embedded {
8243: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8244: $current_disk_usage) = @_;
8245: my $output;
8246: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8247: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8248: my $orig_uploaded_filename =
8249: $env{'form.embedded_item_'.$i.'.filename'};
8250:
8251: $env{'form.embedded_orig_'.$i} =
8252: &unescape($env{'form.embedded_orig_'.$i});
8253: my ($path,$fname) =
8254: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8255: # no path, whole string is fname
8256: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8257:
8258: $path = $env{'form.currentpath'}.$path;
8259: $fname = &Apache::lonnet::clean_filename($fname);
8260: # See if there is anything left
8261: next if ($fname eq '');
8262:
8263: # Check if file already exists as a file or directory.
8264: my ($state,$msg);
8265: if ($context eq 'portfolio') {
8266: my $port_path = $dirpath;
8267: if ($group ne '') {
8268: $port_path = "groups/$group/$port_path";
8269: }
8270: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8271: $dir_root,$port_path,$disk_quota,
8272: $current_disk_usage,$uname,$udom);
8273: if ($state eq 'will_exceed_quota'
8274: || $state eq 'file_locked'
8275: || $state eq 'file_exists' ) {
8276: $output .= $msg;
8277: next;
8278: }
8279: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8280: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8281: if ($state eq 'exists') {
8282: $output .= $msg;
8283: next;
8284: }
8285: }
8286: # Check if extension is valid
8287: if (($fname =~ /\.(\w+)$/) &&
8288: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8289: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8290: next;
8291: } elsif (($fname =~ /\.(\w+)$/) &&
8292: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8293: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8294: next;
8295: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8296: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8297: next;
8298: }
8299:
8300: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8301: if ($context eq 'portfolio') {
8302: my $result=
8303: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8304: $dirpath.$path);
8305: if ($result !~ m|^/uploaded/|) {
8306: $output .= '<span class="LC_error">'
8307: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8308: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8309: .'</span><br />';
8310: next;
8311: } else {
8312: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8313: $path.$fname.'</span>').'</p>';
8314: }
8315: } else {
8316: # Save the file
8317: my $target = $env{'form.embedded_item_'.$i};
8318: my $fullpath = $dir_root.$dirpath.'/'.$path;
8319: my $dest = $fullpath.$fname;
8320: my $url = $url_root.$dirpath.'/'.$path.$fname;
8321: my @parts=split(/\//,$fullpath);
8322: my $count;
8323: my $filepath = $dir_root;
8324: for ($count=4;$count<=$#parts;$count++) {
8325: $filepath .= "/$parts[$count]";
8326: if ((-e $filepath)!=1) {
8327: mkdir($filepath,0770);
8328: }
8329: }
8330: my $fh;
8331: if (!open($fh,'>'.$dest)) {
8332: &Apache::lonnet::logthis('Failed to create '.$dest);
8333: $output .= '<span class="LC_error">'.
8334: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8335: '</span><br />';
8336: } else {
8337: if (!print $fh $env{'form.embedded_item_'.$i}) {
8338: &Apache::lonnet::logthis('Failed to write to '.$dest);
8339: $output .= '<span class="LC_error">'.
8340: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8341: '</span><br />';
8342: } else {
8343: if ($context eq 'testbank') {
8344: $output .= &mt('Embedded file uploaded successfully:').
8345: ' <a href="'.$url.'">'.
8346: $orig_uploaded_filename.'</a><br />';
8347: } else {
1.705 tempelho 8348: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8349: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8350: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8351: }
8352: }
8353: close($fh);
8354: }
8355: }
8356: }
8357: return $output;
8358: }
8359:
8360: sub check_for_existing {
8361: my ($path,$fname,$element) = @_;
8362: my ($state,$msg);
8363: if (-d $path.'/'.$fname) {
8364: $state = 'exists';
8365: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8366: } elsif (-e $path.'/'.$fname) {
8367: $state = 'exists';
8368: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8369: }
8370: if ($state eq 'exists') {
8371: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8372: }
8373: return ($state,$msg);
8374: }
8375:
8376: sub check_for_upload {
8377: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8378: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
8379: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
8380: my $getpropath = 1;
8381: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8382: $getpropath);
8383: my $found_file = 0;
8384: my $locked_file = 0;
8385: foreach my $line (@dir_list) {
8386: my ($file_name)=split(/\&/,$line,2);
8387: if ($file_name eq $fname){
8388: $file_name = $path.$file_name;
8389: if ($group ne '') {
8390: $file_name = $group.$file_name;
8391: }
8392: $found_file = 1;
8393: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8394: $locked_file = 1;
8395: }
8396: }
8397: }
8398: if (($current_disk_usage + $filesize) > $disk_quota){
8399: my $msg = '<span class="LC_error">'.
8400: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8401: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8402: return ('will_exceed_quota',$msg);
8403: } elsif ($found_file) {
8404: if ($locked_file) {
8405: my $msg = '<span class="LC_error">';
8406: $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>');
8407: $msg .= '</span><br />';
8408: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8409: return ('file_locked',$msg);
8410: } else {
8411: my $msg = '<span class="LC_error">';
8412: $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'});
8413: $msg .= '</span>';
8414: $msg .= '<br />';
8415: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
8416: return ('file_exists',$msg);
8417: }
8418: }
8419: }
8420:
1.31 albertel 8421:
1.41 ng 8422: =pod
1.45 matthew 8423:
1.464 albertel 8424: =back
1.41 ng 8425:
1.112 bowersj2 8426: =head1 CSV Upload/Handling functions
1.38 albertel 8427:
1.41 ng 8428: =over 4
8429:
1.648 raeburn 8430: =item * &upfile_store($r)
1.41 ng 8431:
8432: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8433: needs $env{'form.upfile'}
1.41 ng 8434: returns $datatoken to be put into hidden field
8435:
8436: =cut
1.31 albertel 8437:
8438: sub upfile_store {
8439: my $r=shift;
1.258 albertel 8440: $env{'form.upfile'}=~s/\r/\n/gs;
8441: $env{'form.upfile'}=~s/\f/\n/gs;
8442: $env{'form.upfile'}=~s/\n+/\n/gs;
8443: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8444:
1.258 albertel 8445: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8446: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8447: {
1.158 raeburn 8448: my $datafile = $r->dir_config('lonDaemons').
8449: '/tmp/'.$datatoken.'.tmp';
8450: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8451: print $fh $env{'form.upfile'};
1.158 raeburn 8452: close($fh);
8453: }
1.31 albertel 8454: }
8455: return $datatoken;
8456: }
8457:
1.56 matthew 8458: =pod
8459:
1.648 raeburn 8460: =item * &load_tmp_file($r)
1.41 ng 8461:
8462: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8463: needs $env{'form.datatoken'},
8464: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8465:
8466: =cut
1.31 albertel 8467:
8468: sub load_tmp_file {
8469: my $r=shift;
8470: my @studentdata=();
8471: {
1.158 raeburn 8472: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8473: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8474: if ( open(my $fh,"<$studentfile") ) {
8475: @studentdata=<$fh>;
8476: close($fh);
8477: }
1.31 albertel 8478: }
1.258 albertel 8479: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8480: }
8481:
1.56 matthew 8482: =pod
8483:
1.648 raeburn 8484: =item * &upfile_record_sep()
1.41 ng 8485:
8486: Separate uploaded file into records
8487: returns array of records,
1.258 albertel 8488: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8489:
8490: =cut
1.31 albertel 8491:
8492: sub upfile_record_sep {
1.258 albertel 8493: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8494: } else {
1.248 albertel 8495: my @records;
1.258 albertel 8496: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8497: if ($line=~/^\s*$/) { next; }
8498: push(@records,$line);
8499: }
8500: return @records;
1.31 albertel 8501: }
8502: }
8503:
1.56 matthew 8504: =pod
8505:
1.648 raeburn 8506: =item * &record_sep($record)
1.41 ng 8507:
1.258 albertel 8508: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8509:
8510: =cut
8511:
1.263 www 8512: sub takeleft {
8513: my $index=shift;
8514: return substr('0000'.$index,-4,4);
8515: }
8516:
1.31 albertel 8517: sub record_sep {
8518: my $record=shift;
8519: my %components=();
1.258 albertel 8520: if ($env{'form.upfiletype'} eq 'xml') {
8521: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8522: my $i=0;
1.356 albertel 8523: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8524: $field=~s/^(\"|\')//;
8525: $field=~s/(\"|\')$//;
1.263 www 8526: $components{&takeleft($i)}=$field;
1.31 albertel 8527: $i++;
8528: }
1.258 albertel 8529: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8530: my $i=0;
1.356 albertel 8531: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8532: $field=~s/^(\"|\')//;
8533: $field=~s/(\"|\')$//;
1.263 www 8534: $components{&takeleft($i)}=$field;
1.31 albertel 8535: $i++;
8536: }
8537: } else {
1.561 www 8538: my $separator=',';
1.480 banghart 8539: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8540: $separator=';';
1.480 banghart 8541: }
1.31 albertel 8542: my $i=0;
1.561 www 8543: # the character we are looking for to indicate the end of a quote or a record
8544: my $looking_for=$separator;
8545: # do not add the characters to the fields
8546: my $ignore=0;
8547: # we just encountered a separator (or the beginning of the record)
8548: my $just_found_separator=1;
8549: # store the field we are working on here
8550: my $field='';
8551: # work our way through all characters in record
8552: foreach my $character ($record=~/(.)/g) {
8553: if ($character eq $looking_for) {
8554: if ($character ne $separator) {
8555: # Found the end of a quote, again looking for separator
8556: $looking_for=$separator;
8557: $ignore=1;
8558: } else {
8559: # Found a separator, store away what we got
8560: $components{&takeleft($i)}=$field;
8561: $i++;
8562: $just_found_separator=1;
8563: $ignore=0;
8564: $field='';
8565: }
8566: next;
8567: }
8568: # single or double quotation marks after a separator indicate beginning of a quote
8569: # we are now looking for the end of the quote and need to ignore separators
8570: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8571: $looking_for=$character;
8572: next;
8573: }
8574: # ignore would be true after we reached the end of a quote
8575: if ($ignore) { next; }
8576: if (($just_found_separator) && ($character=~/\s/)) { next; }
8577: $field.=$character;
8578: $just_found_separator=0;
1.31 albertel 8579: }
1.561 www 8580: # catch the very last entry, since we never encountered the separator
8581: $components{&takeleft($i)}=$field;
1.31 albertel 8582: }
8583: return %components;
8584: }
8585:
1.144 matthew 8586: ######################################################
8587: ######################################################
8588:
1.56 matthew 8589: =pod
8590:
1.648 raeburn 8591: =item * &upfile_select_html()
1.41 ng 8592:
1.144 matthew 8593: Return HTML code to select a file from the users machine and specify
8594: the file type.
1.41 ng 8595:
8596: =cut
8597:
1.144 matthew 8598: ######################################################
8599: ######################################################
1.31 albertel 8600: sub upfile_select_html {
1.144 matthew 8601: my %Types = (
8602: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8603: semisv => &mt('Semicolon separated values'),
1.144 matthew 8604: space => &mt('Space separated'),
8605: tab => &mt('Tabulator separated'),
8606: # xml => &mt('HTML/XML'),
8607: );
8608: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8609: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8610: foreach my $type (sort(keys(%Types))) {
8611: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8612: }
8613: $Str .= "</select>\n";
8614: return $Str;
1.31 albertel 8615: }
8616:
1.301 albertel 8617: sub get_samples {
8618: my ($records,$toget) = @_;
8619: my @samples=({});
8620: my $got=0;
8621: foreach my $rec (@$records) {
8622: my %temp = &record_sep($rec);
8623: if (! grep(/\S/, values(%temp))) { next; }
8624: if (%temp) {
8625: $samples[$got]=\%temp;
8626: $got++;
8627: if ($got == $toget) { last; }
8628: }
8629: }
8630: return \@samples;
8631: }
8632:
1.144 matthew 8633: ######################################################
8634: ######################################################
8635:
1.56 matthew 8636: =pod
8637:
1.648 raeburn 8638: =item * &csv_print_samples($r,$records)
1.41 ng 8639:
8640: Prints a table of sample values from each column uploaded $r is an
8641: Apache Request ref, $records is an arrayref from
8642: &Apache::loncommon::upfile_record_sep
8643:
8644: =cut
8645:
1.144 matthew 8646: ######################################################
8647: ######################################################
1.31 albertel 8648: sub csv_print_samples {
8649: my ($r,$records) = @_;
1.662 bisitz 8650: my $samples = &get_samples($records,5);
1.301 albertel 8651:
1.594 raeburn 8652: $r->print(&mt('Samples').'<br />'.&start_data_table().
8653: &start_data_table_header_row());
1.356 albertel 8654: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8655: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8656: $r->print(&end_data_table_header_row());
1.301 albertel 8657: foreach my $hash (@$samples) {
1.594 raeburn 8658: $r->print(&start_data_table_row());
1.356 albertel 8659: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8660: $r->print('<td>');
1.356 albertel 8661: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8662: $r->print('</td>');
8663: }
1.594 raeburn 8664: $r->print(&end_data_table_row());
1.31 albertel 8665: }
1.594 raeburn 8666: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8667: }
8668:
1.144 matthew 8669: ######################################################
8670: ######################################################
8671:
1.56 matthew 8672: =pod
8673:
1.648 raeburn 8674: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8675:
8676: Prints a table to create associations between values and table columns.
1.144 matthew 8677:
1.41 ng 8678: $r is an Apache Request ref,
8679: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8680: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8681:
8682: =cut
8683:
1.144 matthew 8684: ######################################################
8685: ######################################################
1.31 albertel 8686: sub csv_print_select_table {
8687: my ($r,$records,$d) = @_;
1.301 albertel 8688: my $i=0;
8689: my $samples = &get_samples($records,1);
1.144 matthew 8690: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8691: &start_data_table().&start_data_table_header_row().
1.144 matthew 8692: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8693: '<th>'.&mt('Column').'</th>'.
8694: &end_data_table_header_row()."\n");
1.356 albertel 8695: foreach my $array_ref (@$d) {
8696: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8697: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8698:
1.875 bisitz 8699: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8700: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8701: $r->print('<option value="none"></option>');
1.356 albertel 8702: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8703: $r->print('<option value="'.$sample.'"'.
8704: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8705: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8706: }
1.594 raeburn 8707: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8708: $i++;
8709: }
1.594 raeburn 8710: $r->print(&end_data_table());
1.31 albertel 8711: $i--;
8712: return $i;
8713: }
1.56 matthew 8714:
1.144 matthew 8715: ######################################################
8716: ######################################################
8717:
1.56 matthew 8718: =pod
1.31 albertel 8719:
1.648 raeburn 8720: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8721:
8722: Prints a table of sample values from the upload and can make associate samples to internal names.
8723:
8724: $r is an Apache Request ref,
8725: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8726: $d is an array of 2 element arrays (internal name, displayed name)
8727:
8728: =cut
8729:
1.144 matthew 8730: ######################################################
8731: ######################################################
1.31 albertel 8732: sub csv_samples_select_table {
8733: my ($r,$records,$d) = @_;
8734: my $i=0;
1.144 matthew 8735: #
1.662 bisitz 8736: my $max_samples = 5;
8737: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8738: $r->print(&start_data_table().
8739: &start_data_table_header_row().'<th>'.
8740: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8741: &end_data_table_header_row());
1.301 albertel 8742:
8743: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8744: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8745: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8746: foreach my $option (@$d) {
8747: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8748: $r->print('<option value="'.$value.'"'.
1.253 albertel 8749: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8750: $display.'</option>');
1.31 albertel 8751: }
8752: $r->print('</select></td><td>');
1.662 bisitz 8753: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8754: if (defined($samples->[$line]{$key})) {
8755: $r->print($samples->[$line]{$key}."<br />\n");
8756: }
8757: }
1.594 raeburn 8758: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8759: $i++;
8760: }
1.594 raeburn 8761: $r->print(&end_data_table());
1.31 albertel 8762: $i--;
8763: return($i);
1.115 matthew 8764: }
8765:
1.144 matthew 8766: ######################################################
8767: ######################################################
8768:
1.115 matthew 8769: =pod
8770:
1.648 raeburn 8771: =item * &clean_excel_name($name)
1.115 matthew 8772:
8773: Returns a replacement for $name which does not contain any illegal characters.
8774:
8775: =cut
8776:
1.144 matthew 8777: ######################################################
8778: ######################################################
1.115 matthew 8779: sub clean_excel_name {
8780: my ($name) = @_;
8781: $name =~ s/[:\*\?\/\\]//g;
8782: if (length($name) > 31) {
8783: $name = substr($name,0,31);
8784: }
8785: return $name;
1.25 albertel 8786: }
1.84 albertel 8787:
1.85 albertel 8788: =pod
8789:
1.648 raeburn 8790: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8791:
8792: Returns either 1 or undef
8793:
8794: 1 if the part is to be hidden, undef if it is to be shown
8795:
8796: Arguments are:
8797:
8798: $id the id of the part to be checked
8799: $symb, optional the symb of the resource to check
8800: $udom, optional the domain of the user to check for
8801: $uname, optional the username of the user to check for
8802:
8803: =cut
1.84 albertel 8804:
8805: sub check_if_partid_hidden {
8806: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8807: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8808: $symb,$udom,$uname);
1.141 albertel 8809: my $truth=1;
8810: #if the string starts with !, then the list is the list to show not hide
8811: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8812: my @hiddenlist=split(/,/,$hiddenparts);
8813: foreach my $checkid (@hiddenlist) {
1.141 albertel 8814: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8815: }
1.141 albertel 8816: return !$truth;
1.84 albertel 8817: }
1.127 matthew 8818:
1.138 matthew 8819:
8820: ############################################################
8821: ############################################################
8822:
8823: =pod
8824:
1.157 matthew 8825: =back
8826:
1.138 matthew 8827: =head1 cgi-bin script and graphing routines
8828:
1.157 matthew 8829: =over 4
8830:
1.648 raeburn 8831: =item * &get_cgi_id()
1.138 matthew 8832:
8833: Inputs: none
8834:
8835: Returns an id which can be used to pass environment variables
8836: to various cgi-bin scripts. These environment variables will
8837: be removed from the users environment after a given time by
8838: the routine &Apache::lonnet::transfer_profile_to_env.
8839:
8840: =cut
8841:
8842: ############################################################
8843: ############################################################
1.152 albertel 8844: my $uniq=0;
1.136 matthew 8845: sub get_cgi_id {
1.154 albertel 8846: $uniq=($uniq+1)%100000;
1.280 albertel 8847: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8848: }
8849:
1.127 matthew 8850: ############################################################
8851: ############################################################
8852:
8853: =pod
8854:
1.648 raeburn 8855: =item * &DrawBarGraph()
1.127 matthew 8856:
1.138 matthew 8857: Facilitates the plotting of data in a (stacked) bar graph.
8858: Puts plot definition data into the users environment in order for
8859: graph.png to plot it. Returns an <img> tag for the plot.
8860: The bars on the plot are labeled '1','2',...,'n'.
8861:
8862: Inputs:
8863:
8864: =over 4
8865:
8866: =item $Title: string, the title of the plot
8867:
8868: =item $xlabel: string, text describing the X-axis of the plot
8869:
8870: =item $ylabel: string, text describing the Y-axis of the plot
8871:
8872: =item $Max: scalar, the maximum Y value to use in the plot
8873: If $Max is < any data point, the graph will not be rendered.
8874:
1.140 matthew 8875: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8876: they are plotted. If undefined, default values will be used.
8877:
1.178 matthew 8878: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8879:
1.138 matthew 8880: =item @Values: An array of array references. Each array reference holds data
8881: to be plotted in a stacked bar chart.
8882:
1.239 matthew 8883: =item If the final element of @Values is a hash reference the key/value
8884: pairs will be added to the graph definition.
8885:
1.138 matthew 8886: =back
8887:
8888: Returns:
8889:
8890: An <img> tag which references graph.png and the appropriate identifying
8891: information for the plot.
8892:
1.127 matthew 8893: =cut
8894:
8895: ############################################################
8896: ############################################################
1.134 matthew 8897: sub DrawBarGraph {
1.178 matthew 8898: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8899: #
8900: if (! defined($colors)) {
8901: $colors = ['#33ff00',
8902: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8903: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8904: ];
8905: }
1.228 matthew 8906: my $extra_settings = {};
8907: if (ref($Values[-1]) eq 'HASH') {
8908: $extra_settings = pop(@Values);
8909: }
1.127 matthew 8910: #
1.136 matthew 8911: my $identifier = &get_cgi_id();
8912: my $id = 'cgi.'.$identifier;
1.129 matthew 8913: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8914: return '';
8915: }
1.225 matthew 8916: #
8917: my @Labels;
8918: if (defined($labels)) {
8919: @Labels = @$labels;
8920: } else {
8921: for (my $i=0;$i<@{$Values[0]};$i++) {
8922: push (@Labels,$i+1);
8923: }
8924: }
8925: #
1.129 matthew 8926: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8927: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8928: my %ValuesHash;
8929: my $NumSets=1;
8930: foreach my $array (@Values) {
8931: next if (! ref($array));
1.136 matthew 8932: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8933: join(',',@$array);
1.129 matthew 8934: }
1.127 matthew 8935: #
1.136 matthew 8936: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8937: if ($NumBars < 3) {
8938: $width = 120+$NumBars*32;
1.220 matthew 8939: $xskip = 1;
1.225 matthew 8940: $bar_width = 30;
8941: } elsif ($NumBars < 5) {
8942: $width = 120+$NumBars*20;
8943: $xskip = 1;
8944: $bar_width = 20;
1.220 matthew 8945: } elsif ($NumBars < 10) {
1.136 matthew 8946: $width = 120+$NumBars*15;
8947: $xskip = 1;
8948: $bar_width = 15;
8949: } elsif ($NumBars <= 25) {
8950: $width = 120+$NumBars*11;
8951: $xskip = 5;
8952: $bar_width = 8;
8953: } elsif ($NumBars <= 50) {
8954: $width = 120+$NumBars*8;
8955: $xskip = 5;
8956: $bar_width = 4;
8957: } else {
8958: $width = 120+$NumBars*8;
8959: $xskip = 5;
8960: $bar_width = 4;
8961: }
8962: #
1.137 matthew 8963: $Max = 1 if ($Max < 1);
8964: if ( int($Max) < $Max ) {
8965: $Max++;
8966: $Max = int($Max);
8967: }
1.127 matthew 8968: $Title = '' if (! defined($Title));
8969: $xlabel = '' if (! defined($xlabel));
8970: $ylabel = '' if (! defined($ylabel));
1.369 www 8971: $ValuesHash{$id.'.title'} = &escape($Title);
8972: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8973: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8974: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8975: $ValuesHash{$id.'.NumBars'} = $NumBars;
8976: $ValuesHash{$id.'.NumSets'} = $NumSets;
8977: $ValuesHash{$id.'.PlotType'} = 'bar';
8978: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8979: $ValuesHash{$id.'.height'} = $height;
8980: $ValuesHash{$id.'.width'} = $width;
8981: $ValuesHash{$id.'.xskip'} = $xskip;
8982: $ValuesHash{$id.'.bar_width'} = $bar_width;
8983: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8984: #
1.228 matthew 8985: # Deal with other parameters
8986: while (my ($key,$value) = each(%$extra_settings)) {
8987: $ValuesHash{$id.'.'.$key} = $value;
8988: }
8989: #
1.646 raeburn 8990: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8991: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8992: }
8993:
8994: ############################################################
8995: ############################################################
8996:
8997: =pod
8998:
1.648 raeburn 8999: =item * &DrawXYGraph()
1.137 matthew 9000:
1.138 matthew 9001: Facilitates the plotting of data in an XY graph.
9002: Puts plot definition data into the users environment in order for
9003: graph.png to plot it. Returns an <img> tag for the plot.
9004:
9005: Inputs:
9006:
9007: =over 4
9008:
9009: =item $Title: string, the title of the plot
9010:
9011: =item $xlabel: string, text describing the X-axis of the plot
9012:
9013: =item $ylabel: string, text describing the Y-axis of the plot
9014:
9015: =item $Max: scalar, the maximum Y value to use in the plot
9016: If $Max is < any data point, the graph will not be rendered.
9017:
9018: =item $colors: Array ref containing the hex color codes for the data to be
9019: plotted in. If undefined, default values will be used.
9020:
9021: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9022:
9023: =item $Ydata: Array ref containing Array refs.
1.185 www 9024: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9025:
9026: =item %Values: hash indicating or overriding any default values which are
9027: passed to graph.png.
9028: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9029:
9030: =back
9031:
9032: Returns:
9033:
9034: An <img> tag which references graph.png and the appropriate identifying
9035: information for the plot.
9036:
1.137 matthew 9037: =cut
9038:
9039: ############################################################
9040: ############################################################
9041: sub DrawXYGraph {
9042: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9043: #
9044: # Create the identifier for the graph
9045: my $identifier = &get_cgi_id();
9046: my $id = 'cgi.'.$identifier;
9047: #
9048: $Title = '' if (! defined($Title));
9049: $xlabel = '' if (! defined($xlabel));
9050: $ylabel = '' if (! defined($ylabel));
9051: my %ValuesHash =
9052: (
1.369 www 9053: $id.'.title' => &escape($Title),
9054: $id.'.xlabel' => &escape($xlabel),
9055: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9056: $id.'.y_max_value'=> $Max,
9057: $id.'.labels' => join(',',@$Xlabels),
9058: $id.'.PlotType' => 'XY',
9059: );
9060: #
9061: if (defined($colors) && ref($colors) eq 'ARRAY') {
9062: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9063: }
9064: #
9065: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9066: return '';
9067: }
9068: my $NumSets=1;
1.138 matthew 9069: foreach my $array (@{$Ydata}){
1.137 matthew 9070: next if (! ref($array));
9071: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9072: }
1.138 matthew 9073: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9074: #
9075: # Deal with other parameters
9076: while (my ($key,$value) = each(%Values)) {
9077: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9078: }
9079: #
1.646 raeburn 9080: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9081: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9082: }
9083:
9084: ############################################################
9085: ############################################################
9086:
9087: =pod
9088:
1.648 raeburn 9089: =item * &DrawXYYGraph()
1.138 matthew 9090:
9091: Facilitates the plotting of data in an XY graph with two Y axes.
9092: Puts plot definition data into the users environment in order for
9093: graph.png to plot it. Returns an <img> tag for the plot.
9094:
9095: Inputs:
9096:
9097: =over 4
9098:
9099: =item $Title: string, the title of the plot
9100:
9101: =item $xlabel: string, text describing the X-axis of the plot
9102:
9103: =item $ylabel: string, text describing the Y-axis of the plot
9104:
9105: =item $colors: Array ref containing the hex color codes for the data to be
9106: plotted in. If undefined, default values will be used.
9107:
9108: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9109:
9110: =item $Ydata1: The first data set
9111:
9112: =item $Min1: The minimum value of the left Y-axis
9113:
9114: =item $Max1: The maximum value of the left Y-axis
9115:
9116: =item $Ydata2: The second data set
9117:
9118: =item $Min2: The minimum value of the right Y-axis
9119:
9120: =item $Max2: The maximum value of the left Y-axis
9121:
9122: =item %Values: hash indicating or overriding any default values which are
9123: passed to graph.png.
9124: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9125:
9126: =back
9127:
9128: Returns:
9129:
9130: An <img> tag which references graph.png and the appropriate identifying
9131: information for the plot.
1.136 matthew 9132:
9133: =cut
9134:
9135: ############################################################
9136: ############################################################
1.137 matthew 9137: sub DrawXYYGraph {
9138: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9139: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9140: #
9141: # Create the identifier for the graph
9142: my $identifier = &get_cgi_id();
9143: my $id = 'cgi.'.$identifier;
9144: #
9145: $Title = '' if (! defined($Title));
9146: $xlabel = '' if (! defined($xlabel));
9147: $ylabel = '' if (! defined($ylabel));
9148: my %ValuesHash =
9149: (
1.369 www 9150: $id.'.title' => &escape($Title),
9151: $id.'.xlabel' => &escape($xlabel),
9152: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9153: $id.'.labels' => join(',',@$Xlabels),
9154: $id.'.PlotType' => 'XY',
9155: $id.'.NumSets' => 2,
1.137 matthew 9156: $id.'.two_axes' => 1,
9157: $id.'.y1_max_value' => $Max1,
9158: $id.'.y1_min_value' => $Min1,
9159: $id.'.y2_max_value' => $Max2,
9160: $id.'.y2_min_value' => $Min2,
1.136 matthew 9161: );
9162: #
1.137 matthew 9163: if (defined($colors) && ref($colors) eq 'ARRAY') {
9164: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9165: }
9166: #
9167: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9168: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9169: return '';
9170: }
9171: my $NumSets=1;
1.137 matthew 9172: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9173: next if (! ref($array));
9174: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9175: }
9176: #
9177: # Deal with other parameters
9178: while (my ($key,$value) = each(%Values)) {
9179: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9180: }
9181: #
1.646 raeburn 9182: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9183: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9184: }
9185:
9186: ############################################################
9187: ############################################################
9188:
9189: =pod
9190:
1.157 matthew 9191: =back
9192:
1.139 matthew 9193: =head1 Statistics helper routines?
9194:
9195: Bad place for them but what the hell.
9196:
1.157 matthew 9197: =over 4
9198:
1.648 raeburn 9199: =item * &chartlink()
1.139 matthew 9200:
9201: Returns a link to the chart for a specific student.
9202:
9203: Inputs:
9204:
9205: =over 4
9206:
9207: =item $linktext: The text of the link
9208:
9209: =item $sname: The students username
9210:
9211: =item $sdomain: The students domain
9212:
9213: =back
9214:
1.157 matthew 9215: =back
9216:
1.139 matthew 9217: =cut
9218:
9219: ############################################################
9220: ############################################################
9221: sub chartlink {
9222: my ($linktext, $sname, $sdomain) = @_;
9223: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9224: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9225: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9226: '">'.$linktext.'</a>';
1.153 matthew 9227: }
9228:
9229: #######################################################
9230: #######################################################
9231:
9232: =pod
9233:
9234: =head1 Course Environment Routines
1.157 matthew 9235:
9236: =over 4
1.153 matthew 9237:
1.648 raeburn 9238: =item * &restore_course_settings()
1.153 matthew 9239:
1.648 raeburn 9240: =item * &store_course_settings()
1.153 matthew 9241:
9242: Restores/Store indicated form parameters from the course environment.
9243: Will not overwrite existing values of the form parameters.
9244:
9245: Inputs:
9246: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9247:
9248: a hash ref describing the data to be stored. For example:
9249:
9250: %Save_Parameters = ('Status' => 'scalar',
9251: 'chartoutputmode' => 'scalar',
9252: 'chartoutputdata' => 'scalar',
9253: 'Section' => 'array',
1.373 raeburn 9254: 'Group' => 'array',
1.153 matthew 9255: 'StudentData' => 'array',
9256: 'Maps' => 'array');
9257:
9258: Returns: both routines return nothing
9259:
1.631 raeburn 9260: =back
9261:
1.153 matthew 9262: =cut
9263:
9264: #######################################################
9265: #######################################################
9266: sub store_course_settings {
1.496 albertel 9267: return &store_settings($env{'request.course.id'},@_);
9268: }
9269:
9270: sub store_settings {
1.153 matthew 9271: # save to the environment
9272: # appenv the same items, just to be safe
1.300 albertel 9273: my $udom = $env{'user.domain'};
9274: my $uname = $env{'user.name'};
1.496 albertel 9275: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9276: my %SaveHash;
9277: my %AppHash;
9278: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9279: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9280: my $envname = 'environment.'.$basename;
1.258 albertel 9281: if (exists($env{'form.'.$setting})) {
1.153 matthew 9282: # Save this value away
9283: if ($type eq 'scalar' &&
1.258 albertel 9284: (! exists($env{$envname}) ||
9285: $env{$envname} ne $env{'form.'.$setting})) {
9286: $SaveHash{$basename} = $env{'form.'.$setting};
9287: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9288: } elsif ($type eq 'array') {
9289: my $stored_form;
1.258 albertel 9290: if (ref($env{'form.'.$setting})) {
1.153 matthew 9291: $stored_form = join(',',
9292: map {
1.369 www 9293: &escape($_);
1.258 albertel 9294: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9295: } else {
9296: $stored_form =
1.369 www 9297: &escape($env{'form.'.$setting});
1.153 matthew 9298: }
9299: # Determine if the array contents are the same.
1.258 albertel 9300: if ($stored_form ne $env{$envname}) {
1.153 matthew 9301: $SaveHash{$basename} = $stored_form;
9302: $AppHash{$envname} = $stored_form;
9303: }
9304: }
9305: }
9306: }
9307: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9308: $udom,$uname);
1.153 matthew 9309: if ($put_result !~ /^(ok|delayed)/) {
9310: &Apache::lonnet::logthis('unable to save form parameters, '.
9311: 'got error:'.$put_result);
9312: }
9313: # Make sure these settings stick around in this session, too
1.646 raeburn 9314: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9315: return;
9316: }
9317:
9318: sub restore_course_settings {
1.499 albertel 9319: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9320: }
9321:
9322: sub restore_settings {
9323: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9324: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9325: next if (exists($env{'form.'.$setting}));
1.496 albertel 9326: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9327: '.'.$setting;
1.258 albertel 9328: if (exists($env{$envname})) {
1.153 matthew 9329: if ($type eq 'scalar') {
1.258 albertel 9330: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9331: } elsif ($type eq 'array') {
1.258 albertel 9332: $env{'form.'.$setting} = [
1.153 matthew 9333: map {
1.369 www 9334: &unescape($_);
1.258 albertel 9335: } split(',',$env{$envname})
1.153 matthew 9336: ];
9337: }
9338: }
9339: }
1.127 matthew 9340: }
9341:
1.618 raeburn 9342: #######################################################
9343: #######################################################
9344:
9345: =pod
9346:
9347: =head1 Domain E-mail Routines
9348:
9349: =over 4
9350:
1.648 raeburn 9351: =item * &build_recipient_list()
1.618 raeburn 9352:
1.884 raeburn 9353: Build recipient lists for five types of e-mail:
1.766 raeburn 9354: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9355: (d) Help requests, (e) Course requests needing approval, generated by
9356: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9357: loncoursequeueadmin.pm respectively.
1.618 raeburn 9358:
9359: Inputs:
1.619 raeburn 9360: defmail (scalar - email address of default recipient),
1.618 raeburn 9361: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9362: defdom (domain for which to retrieve configuration settings),
9363: origmail (scalar - email address of recipient from loncapa.conf,
9364: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9365:
1.655 raeburn 9366: Returns: comma separated list of addresses to which to send e-mail.
9367:
9368: =back
1.618 raeburn 9369:
9370: =cut
9371:
9372: ############################################################
9373: ############################################################
9374: sub build_recipient_list {
1.619 raeburn 9375: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9376: my @recipients;
9377: my $otheremails;
9378: my %domconfig =
9379: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9380: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9381: if (exists($domconfig{'contacts'}{$mailing})) {
9382: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9383: my @contacts = ('adminemail','supportemail');
9384: foreach my $item (@contacts) {
9385: if ($domconfig{'contacts'}{$mailing}{$item}) {
9386: my $addr = $domconfig{'contacts'}{$item};
9387: if (!grep(/^\Q$addr\E$/,@recipients)) {
9388: push(@recipients,$addr);
9389: }
1.619 raeburn 9390: }
1.766 raeburn 9391: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9392: }
9393: }
1.766 raeburn 9394: } elsif ($origmail ne '') {
9395: push(@recipients,$origmail);
1.618 raeburn 9396: }
1.619 raeburn 9397: } elsif ($origmail ne '') {
9398: push(@recipients,$origmail);
1.618 raeburn 9399: }
1.688 raeburn 9400: if (defined($defmail)) {
9401: if ($defmail ne '') {
9402: push(@recipients,$defmail);
9403: }
1.618 raeburn 9404: }
9405: if ($otheremails) {
1.619 raeburn 9406: my @others;
9407: if ($otheremails =~ /,/) {
9408: @others = split(/,/,$otheremails);
1.618 raeburn 9409: } else {
1.619 raeburn 9410: push(@others,$otheremails);
9411: }
9412: foreach my $addr (@others) {
9413: if (!grep(/^\Q$addr\E$/,@recipients)) {
9414: push(@recipients,$addr);
9415: }
1.618 raeburn 9416: }
9417: }
1.619 raeburn 9418: my $recipientlist = join(',',@recipients);
1.618 raeburn 9419: return $recipientlist;
9420: }
9421:
1.127 matthew 9422: ############################################################
9423: ############################################################
1.154 albertel 9424:
1.655 raeburn 9425: =pod
9426:
9427: =head1 Course Catalog Routines
9428:
9429: =over 4
9430:
9431: =item * &gather_categories()
9432:
9433: Converts category definitions - keys of categories hash stored in
9434: coursecategories in configuration.db on the primary library server in a
9435: domain - to an array. Also generates javascript and idx hash used to
9436: generate Domain Coordinator interface for editing Course Categories.
9437:
9438: Inputs:
1.663 raeburn 9439:
1.655 raeburn 9440: categories (reference to hash of category definitions).
1.663 raeburn 9441:
1.655 raeburn 9442: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9443: categories and subcategories).
1.663 raeburn 9444:
1.655 raeburn 9445: idx (reference to hash of counters used in Domain Coordinator interface for
9446: editing Course Categories).
1.663 raeburn 9447:
1.655 raeburn 9448: jsarray (reference to array of categories used to create Javascript arrays for
9449: Domain Coordinator interface for editing Course Categories).
9450:
9451: Returns: nothing
9452:
9453: Side effects: populates cats, idx and jsarray.
9454:
9455: =cut
9456:
9457: sub gather_categories {
9458: my ($categories,$cats,$idx,$jsarray) = @_;
9459: my %counters;
9460: my $num = 0;
9461: foreach my $item (keys(%{$categories})) {
9462: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9463: if ($container eq '' && $depth == 0) {
9464: $cats->[$depth][$categories->{$item}] = $cat;
9465: } else {
9466: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9467: }
9468: my ($escitem,$tail) = split(/:/,$item,2);
9469: if ($counters{$tail} eq '') {
9470: $counters{$tail} = $num;
9471: $num ++;
9472: }
9473: if (ref($idx) eq 'HASH') {
9474: $idx->{$item} = $counters{$tail};
9475: }
9476: if (ref($jsarray) eq 'ARRAY') {
9477: push(@{$jsarray->[$counters{$tail}]},$item);
9478: }
9479: }
9480: return;
9481: }
9482:
9483: =pod
9484:
9485: =item * &extract_categories()
9486:
9487: Used to generate breadcrumb trails for course categories.
9488:
9489: Inputs:
1.663 raeburn 9490:
1.655 raeburn 9491: categories (reference to hash of category definitions).
1.663 raeburn 9492:
1.655 raeburn 9493: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9494: categories and subcategories).
1.663 raeburn 9495:
1.655 raeburn 9496: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9497:
1.655 raeburn 9498: allitems (reference to hash - key is category key
9499: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9500:
1.655 raeburn 9501: idx (reference to hash of counters used in Domain Coordinator interface for
9502: editing Course Categories).
1.663 raeburn 9503:
1.655 raeburn 9504: jsarray (reference to array of categories used to create Javascript arrays for
9505: Domain Coordinator interface for editing Course Categories).
9506:
1.665 raeburn 9507: subcats (reference to hash of arrays containing all subcategories within each
9508: category, -recursive)
9509:
1.655 raeburn 9510: Returns: nothing
9511:
9512: Side effects: populates trails and allitems hash references.
9513:
9514: =cut
9515:
9516: sub extract_categories {
1.665 raeburn 9517: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9518: if (ref($categories) eq 'HASH') {
9519: &gather_categories($categories,$cats,$idx,$jsarray);
9520: if (ref($cats->[0]) eq 'ARRAY') {
9521: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9522: my $name = $cats->[0][$i];
9523: my $item = &escape($name).'::0';
9524: my $trailstr;
9525: if ($name eq 'instcode') {
9526: $trailstr = &mt('Official courses (with institutional codes)');
9527: } else {
9528: $trailstr = $name;
9529: }
9530: if ($allitems->{$item} eq '') {
9531: push(@{$trails},$trailstr);
9532: $allitems->{$item} = scalar(@{$trails})-1;
9533: }
9534: my @parents = ($name);
9535: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9536: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9537: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9538: if (ref($subcats) eq 'HASH') {
9539: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9540: }
9541: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9542: }
9543: } else {
9544: if (ref($subcats) eq 'HASH') {
9545: $subcats->{$item} = [];
1.655 raeburn 9546: }
9547: }
9548: }
9549: }
9550: }
9551: return;
9552: }
9553:
9554: =pod
9555:
9556: =item *&recurse_categories()
9557:
9558: Recursively used to generate breadcrumb trails for course categories.
9559:
9560: Inputs:
1.663 raeburn 9561:
1.655 raeburn 9562: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9563: categories and subcategories).
1.663 raeburn 9564:
1.655 raeburn 9565: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9566:
9567: category (current course category, for which breadcrumb trail is being generated).
9568:
9569: trails (reference to array of breadcrumb trails for each category).
9570:
1.655 raeburn 9571: allitems (reference to hash - key is category key
9572: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9573:
1.655 raeburn 9574: parents (array containing containers directories for current category,
9575: back to top level).
9576:
9577: Returns: nothing
9578:
9579: Side effects: populates trails and allitems hash references
9580:
9581: =cut
9582:
9583: sub recurse_categories {
1.665 raeburn 9584: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9585: my $shallower = $depth - 1;
9586: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9587: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9588: my $name = $cats->[$depth]{$category}[$k];
9589: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9590: my $trailstr = join(' -> ',(@{$parents},$category));
9591: if ($allitems->{$item} eq '') {
9592: push(@{$trails},$trailstr);
9593: $allitems->{$item} = scalar(@{$trails})-1;
9594: }
9595: my $deeper = $depth+1;
9596: push(@{$parents},$category);
1.665 raeburn 9597: if (ref($subcats) eq 'HASH') {
9598: my $subcat = &escape($name).':'.$category.':'.$depth;
9599: for (my $j=@{$parents}; $j>=0; $j--) {
9600: my $higher;
9601: if ($j > 0) {
9602: $higher = &escape($parents->[$j]).':'.
9603: &escape($parents->[$j-1]).':'.$j;
9604: } else {
9605: $higher = &escape($parents->[$j]).'::'.$j;
9606: }
9607: push(@{$subcats->{$higher}},$subcat);
9608: }
9609: }
9610: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9611: $subcats);
1.655 raeburn 9612: pop(@{$parents});
9613: }
9614: } else {
9615: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9616: my $trailstr = join(' -> ',(@{$parents},$category));
9617: if ($allitems->{$item} eq '') {
9618: push(@{$trails},$trailstr);
9619: $allitems->{$item} = scalar(@{$trails})-1;
9620: }
9621: }
9622: return;
9623: }
9624:
1.663 raeburn 9625: =pod
9626:
9627: =item *&assign_categories_table()
9628:
9629: Create a datatable for display of hierarchical categories in a domain,
9630: with checkboxes to allow a course to be categorized.
9631:
9632: Inputs:
9633:
9634: cathash - reference to hash of categories defined for the domain (from
9635: configuration.db)
9636:
9637: currcat - scalar with an & separated list of categories assigned to a course.
9638:
9639: Returns: $output (markup to be displayed)
9640:
9641: =cut
9642:
9643: sub assign_categories_table {
9644: my ($cathash,$currcat) = @_;
9645: my $output;
9646: if (ref($cathash) eq 'HASH') {
9647: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9648: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9649: $maxdepth = scalar(@cats);
9650: if (@cats > 0) {
9651: my $itemcount = 0;
9652: if (ref($cats[0]) eq 'ARRAY') {
9653: $output = &Apache::loncommon::start_data_table();
9654: my @currcategories;
9655: if ($currcat ne '') {
9656: @currcategories = split('&',$currcat);
9657: }
9658: for (my $i=0; $i<@{$cats[0]}; $i++) {
9659: my $parent = $cats[0][$i];
9660: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9661: next if ($parent eq 'instcode');
9662: my $item = &escape($parent).'::0';
9663: my $checked = '';
9664: if (@currcategories > 0) {
9665: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9666: $checked = ' checked="checked"';
1.663 raeburn 9667: }
9668: }
1.675 raeburn 9669: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9670: '<input type="checkbox" name="usecategory" value="'.
9671: $item.'"'.$checked.' />'.$parent.'</span>'.
9672: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9673: my $depth = 1;
9674: push(@path,$parent);
9675: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9676: pop(@path);
9677: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9678: $itemcount ++;
9679: }
9680: $output .= &Apache::loncommon::end_data_table();
9681: }
9682: }
9683: }
9684: return $output;
9685: }
9686:
9687: =pod
9688:
9689: =item *&assign_category_rows()
9690:
9691: Create a datatable row for display of nested categories in a domain,
9692: with checkboxes to allow a course to be categorized,called recursively.
9693:
9694: Inputs:
9695:
9696: itemcount - track row number for alternating colors
9697:
9698: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9699: categories and subcategories.
9700:
9701: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9702:
9703: parent - parent of current category item
9704:
9705: path - Array containing all categories back up through the hierarchy from the
9706: current category to the top level.
9707:
9708: currcategories - reference to array of current categories assigned to the course
9709:
9710: Returns: $output (markup to be displayed).
9711:
9712: =cut
9713:
9714: sub assign_category_rows {
9715: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9716: my ($text,$name,$item,$chgstr);
9717: if (ref($cats) eq 'ARRAY') {
9718: my $maxdepth = scalar(@{$cats});
9719: if (ref($cats->[$depth]) eq 'HASH') {
9720: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9721: my $numchildren = @{$cats->[$depth]{$parent}};
9722: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9723: $text .= '<td><table class="LC_datatable">';
9724: for (my $j=0; $j<$numchildren; $j++) {
9725: $name = $cats->[$depth]{$parent}[$j];
9726: $item = &escape($name).':'.&escape($parent).':'.$depth;
9727: my $deeper = $depth+1;
9728: my $checked = '';
9729: if (ref($currcategories) eq 'ARRAY') {
9730: if (@{$currcategories} > 0) {
9731: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9732: $checked = ' checked="checked"';
1.663 raeburn 9733: }
9734: }
9735: }
1.664 raeburn 9736: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9737: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9738: $item.'"'.$checked.' />'.$name.'</label></span>'.
9739: '<input type="hidden" name="catname" value="'.$name.'" />'.
9740: '</td><td>';
1.663 raeburn 9741: if (ref($path) eq 'ARRAY') {
9742: push(@{$path},$name);
9743: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9744: pop(@{$path});
9745: }
9746: $text .= '</td></tr>';
9747: }
9748: $text .= '</table></td>';
9749: }
9750: }
9751: }
9752: return $text;
9753: }
9754:
1.655 raeburn 9755: ############################################################
9756: ############################################################
9757:
9758:
1.443 albertel 9759: sub commit_customrole {
1.664 raeburn 9760: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9761: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9762: ($start?', '.&mt('starting').' '.localtime($start):'').
9763: ($end?', ending '.localtime($end):'').': <b>'.
9764: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9765: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9766: '</b><br />';
9767: return $output;
9768: }
9769:
9770: sub commit_standardrole {
1.541 raeburn 9771: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9772: my ($output,$logmsg,$linefeed);
9773: if ($context eq 'auto') {
9774: $linefeed = "\n";
9775: } else {
9776: $linefeed = "<br />\n";
9777: }
1.443 albertel 9778: if ($three eq 'st') {
1.541 raeburn 9779: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9780: $one,$two,$sec,$context);
9781: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9782: ($result eq 'unknown_course') || ($result eq 'refused')) {
9783: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9784: } else {
1.541 raeburn 9785: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9786: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9787: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9788: if ($context eq 'auto') {
9789: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9790: } else {
9791: $output .= '<b>'.$result.'</b>'.$linefeed.
9792: &mt('Add to classlist').': <b>ok</b>';
9793: }
9794: $output .= $linefeed;
1.443 albertel 9795: }
9796: } else {
9797: $output = &mt('Assigning').' '.$three.' in '.$url.
9798: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9799: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9800: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9801: if ($context eq 'auto') {
9802: $output .= $result.$linefeed;
9803: } else {
9804: $output .= '<b>'.$result.'</b>'.$linefeed;
9805: }
1.443 albertel 9806: }
9807: return $output;
9808: }
9809:
9810: sub commit_studentrole {
1.541 raeburn 9811: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9812: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9813: if ($context eq 'auto') {
9814: $linefeed = "\n";
9815: } else {
9816: $linefeed = '<br />'."\n";
9817: }
1.443 albertel 9818: if (defined($one) && defined($two)) {
9819: my $cid=$one.'_'.$two;
9820: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9821: my $secchange = 0;
9822: my $expire_role_result;
9823: my $modify_section_result;
1.628 raeburn 9824: if ($oldsec ne '-1') {
9825: if ($oldsec ne $sec) {
1.443 albertel 9826: $secchange = 1;
1.628 raeburn 9827: my $now = time;
1.443 albertel 9828: my $uurl='/'.$cid;
9829: $uurl=~s/\_/\//g;
9830: if ($oldsec) {
9831: $uurl.='/'.$oldsec;
9832: }
1.626 raeburn 9833: $oldsecurl = $uurl;
1.628 raeburn 9834: $expire_role_result =
1.652 raeburn 9835: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9836: if ($env{'request.course.sec'} ne '') {
9837: if ($expire_role_result eq 'refused') {
9838: my @roles = ('st');
9839: my @statuses = ('previous');
9840: my @roledoms = ($one);
9841: my $withsec = 1;
9842: my %roleshash =
9843: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9844: \@statuses,\@roles,\@roledoms,$withsec);
9845: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9846: my ($oldstart,$oldend) =
9847: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9848: if ($oldend > 0 && $oldend <= $now) {
9849: $expire_role_result = 'ok';
9850: }
9851: }
9852: }
9853: }
1.443 albertel 9854: $result = $expire_role_result;
9855: }
9856: }
9857: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9858: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9859: if ($modify_section_result =~ /^ok/) {
9860: if ($secchange == 1) {
1.628 raeburn 9861: if ($sec eq '') {
9862: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9863: } else {
9864: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9865: }
1.443 albertel 9866: } elsif ($oldsec eq '-1') {
1.628 raeburn 9867: if ($sec eq '') {
9868: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9869: } else {
9870: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9871: }
1.443 albertel 9872: } else {
1.628 raeburn 9873: if ($sec eq '') {
9874: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9875: } else {
9876: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9877: }
1.443 albertel 9878: }
9879: } else {
1.628 raeburn 9880: if ($secchange) {
9881: $$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;
9882: } else {
9883: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9884: }
1.443 albertel 9885: }
9886: $result = $modify_section_result;
9887: } elsif ($secchange == 1) {
1.628 raeburn 9888: if ($oldsec eq '') {
9889: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9890: } else {
9891: $$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;
9892: }
1.626 raeburn 9893: if ($expire_role_result eq 'refused') {
9894: my $newsecurl = '/'.$cid;
9895: $newsecurl =~ s/\_/\//g;
9896: if ($sec ne '') {
9897: $newsecurl.='/'.$sec;
9898: }
9899: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9900: if ($sec eq '') {
9901: $$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;
9902: } else {
9903: $$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;
9904: }
9905: }
9906: }
1.443 albertel 9907: }
9908: } else {
1.626 raeburn 9909: $$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 9910: $result = "error: incomplete course id\n";
9911: }
9912: return $result;
9913: }
9914:
9915: ############################################################
9916: ############################################################
9917:
1.566 albertel 9918: sub check_clone {
1.578 raeburn 9919: my ($args,$linefeed) = @_;
1.566 albertel 9920: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9921: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9922: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9923: my $clonemsg;
9924: my $can_clone = 0;
1.908 raeburn 9925: my $lctype = lc($args->{'type'});
9926: if ($lctype ne 'community') {
9927: $lctype = 'course';
9928: }
1.566 albertel 9929: if ($clonehome eq 'no_host') {
1.908 raeburn 9930: if ($args->{'type'} eq 'Community') {
9931: $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'});
9932: } else {
9933: $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'});
9934: }
1.566 albertel 9935: } else {
9936: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.908 raeburn 9937: if ($args->{'type'} eq 'Community') {
9938: if ($clonedesc{'type'} ne 'Community') {
9939: $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'});
9940: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9941: }
9942: }
1.882 raeburn 9943: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
9944: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 9945: $can_clone = 1;
9946: } else {
9947: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9948: $args->{'clonedomain'},$args->{'clonecourse'});
9949: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9950: if (grep(/^\*$/,@cloners)) {
9951: $can_clone = 1;
9952: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9953: $can_clone = 1;
9954: } else {
1.908 raeburn 9955: my $ccrole = 'cc';
9956: if ($args->{'type'} eq 'Community') {
9957: $ccrole = 'co';
9958: }
1.578 raeburn 9959: my %roleshash =
9960: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9961: $args->{'ccdomain'},
1.908 raeburn 9962: 'userroles',['active'],[$ccrole],
1.578 raeburn 9963: [$args->{'clonedomain'}]);
1.908 raeburn 9964: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.578 raeburn 9965: $can_clone = 1;
9966: } else {
1.908 raeburn 9967: if ($args->{'type'} eq 'Community') {
9968: $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'});
9969: } else {
9970: $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'});
9971: }
1.578 raeburn 9972: }
1.566 albertel 9973: }
1.578 raeburn 9974: }
1.566 albertel 9975: }
9976: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9977: }
9978:
1.444 albertel 9979: sub construct_course {
1.885 raeburn 9980: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 9981: my $outcome;
1.541 raeburn 9982: my $linefeed = '<br />'."\n";
9983: if ($context eq 'auto') {
9984: $linefeed = "\n";
9985: }
1.566 albertel 9986:
9987: #
9988: # Are we cloning?
9989: #
9990: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9991: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9992: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9993: if ($context ne 'auto') {
1.578 raeburn 9994: if ($clonemsg ne '') {
9995: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9996: }
1.566 albertel 9997: }
9998: $outcome .= $clonemsg.$linefeed;
9999:
10000: if (!$can_clone) {
10001: return (0,$outcome);
10002: }
10003: }
10004:
1.444 albertel 10005: #
10006: # Open course
10007: #
10008: my $crstype = lc($args->{'crstype'});
10009: my %cenv=();
10010: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10011: $args->{'cdescr'},
10012: $args->{'curl'},
10013: $args->{'course_home'},
10014: $args->{'nonstandard'},
10015: $args->{'crscode'},
10016: $args->{'ccuname'}.':'.
10017: $args->{'ccdomain'},
1.882 raeburn 10018: $args->{'crstype'},
1.885 raeburn 10019: $cnum,$context,$category);
1.444 albertel 10020:
10021: # Note: The testing routines depend on this being output; see
10022: # Utils::Course. This needs to at least be output as a comment
10023: # if anyone ever decides to not show this, and Utils::Course::new
10024: # will need to be suitably modified.
1.541 raeburn 10025: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 10026: #
10027: # Check if created correctly
10028: #
1.479 albertel 10029: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10030: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 10031: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10032:
1.444 albertel 10033: #
1.566 albertel 10034: # Do the cloning
10035: #
10036: if ($can_clone && $cloneid) {
10037: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10038: if ($context ne 'auto') {
10039: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10040: }
10041: $outcome .= $clonemsg.$linefeed;
10042: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10043: # Copy all files
1.637 www 10044: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10045: # Restore URL
1.566 albertel 10046: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10047: # Restore title
1.566 albertel 10048: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 10049: # Mark as cloned
1.566 albertel 10050: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10051: # Need to clone grading mode
10052: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10053: $cenv{'grading'}=$newenv{'grading'};
10054: # Do not clone these environment entries
10055: &Apache::lonnet::del('environment',
10056: ['default_enrollment_start_date',
10057: 'default_enrollment_end_date',
10058: 'question.email',
10059: 'policy.email',
10060: 'comment.email',
10061: 'pch.users.denied',
1.725 raeburn 10062: 'plc.users.denied',
10063: 'hidefromcat',
10064: 'categories'],
1.638 www 10065: $$crsudom,$$crsunum);
1.444 albertel 10066: }
1.566 albertel 10067:
1.444 albertel 10068: #
10069: # Set environment (will override cloned, if existing)
10070: #
10071: my @sections = ();
10072: my @xlists = ();
10073: if ($args->{'crstype'}) {
10074: $cenv{'type'}=$args->{'crstype'};
10075: }
10076: if ($args->{'crsid'}) {
10077: $cenv{'courseid'}=$args->{'crsid'};
10078: }
10079: if ($args->{'crscode'}) {
10080: $cenv{'internal.coursecode'}=$args->{'crscode'};
10081: }
10082: if ($args->{'crsquota'} ne '') {
10083: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10084: } else {
10085: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10086: }
10087: if ($args->{'ccuname'}) {
10088: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10089: ':'.$args->{'ccdomain'};
10090: } else {
10091: $cenv{'internal.courseowner'} = $args->{'curruser'};
10092: }
10093: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10094: if ($args->{'crssections'}) {
10095: $cenv{'internal.sectionnums'} = '';
10096: if ($args->{'crssections'} =~ m/,/) {
10097: @sections = split/,/,$args->{'crssections'};
10098: } else {
10099: $sections[0] = $args->{'crssections'};
10100: }
10101: if (@sections > 0) {
10102: foreach my $item (@sections) {
10103: my ($sec,$gp) = split/:/,$item;
10104: my $class = $args->{'crscode'}.$sec;
10105: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10106: $cenv{'internal.sectionnums'} .= $item.',';
10107: unless ($addcheck eq 'ok') {
10108: push @badclasses, $class;
10109: }
10110: }
10111: $cenv{'internal.sectionnums'} =~ s/,$//;
10112: }
10113: }
10114: # do not hide course coordinator from staff listing,
10115: # even if privileged
10116: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10117: # add crosslistings
10118: if ($args->{'crsxlist'}) {
10119: $cenv{'internal.crosslistings'}='';
10120: if ($args->{'crsxlist'} =~ m/,/) {
10121: @xlists = split/,/,$args->{'crsxlist'};
10122: } else {
10123: $xlists[0] = $args->{'crsxlist'};
10124: }
10125: if (@xlists > 0) {
10126: foreach my $item (@xlists) {
10127: my ($xl,$gp) = split/:/,$item;
10128: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10129: $cenv{'internal.crosslistings'} .= $item.',';
10130: unless ($addcheck eq 'ok') {
10131: push @badclasses, $xl;
10132: }
10133: }
10134: $cenv{'internal.crosslistings'} =~ s/,$//;
10135: }
10136: }
10137: if ($args->{'autoadds'}) {
10138: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10139: }
10140: if ($args->{'autodrops'}) {
10141: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10142: }
10143: # check for notification of enrollment changes
10144: my @notified = ();
10145: if ($args->{'notify_owner'}) {
10146: if ($args->{'ccuname'} ne '') {
10147: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10148: }
10149: }
10150: if ($args->{'notify_dc'}) {
10151: if ($uname ne '') {
1.630 raeburn 10152: push(@notified,$uname.':'.$udom);
1.444 albertel 10153: }
10154: }
10155: if (@notified > 0) {
10156: my $notifylist;
10157: if (@notified > 1) {
10158: $notifylist = join(',',@notified);
10159: } else {
10160: $notifylist = $notified[0];
10161: }
10162: $cenv{'internal.notifylist'} = $notifylist;
10163: }
10164: if (@badclasses > 0) {
10165: my %lt=&Apache::lonlocal::texthash(
10166: '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',
10167: 'dnhr' => 'does not have rights to access enrollment in these classes',
10168: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10169: );
1.541 raeburn 10170: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10171: ' ('.$lt{'adby'}.')';
10172: if ($context eq 'auto') {
10173: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10174: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10175: foreach my $item (@badclasses) {
10176: if ($context eq 'auto') {
10177: $outcome .= " - $item\n";
10178: } else {
10179: $outcome .= "<li>$item</li>\n";
10180: }
10181: }
10182: if ($context eq 'auto') {
10183: $outcome .= $linefeed;
10184: } else {
1.566 albertel 10185: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10186: }
10187: }
1.444 albertel 10188: }
10189: if ($args->{'no_end_date'}) {
10190: $args->{'endaccess'} = 0;
10191: }
10192: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10193: $cenv{'internal.autoend'}=$args->{'enrollend'};
10194: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10195: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10196: if ($args->{'showphotos'}) {
10197: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10198: }
10199: $cenv{'internal.authtype'} = $args->{'authtype'};
10200: $cenv{'internal.autharg'} = $args->{'autharg'};
10201: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10202: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10203: 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');
10204: if ($context eq 'auto') {
10205: $outcome .= $krb_msg;
10206: } else {
1.566 albertel 10207: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10208: }
10209: $outcome .= $linefeed;
1.444 albertel 10210: }
10211: }
10212: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10213: if ($args->{'setpolicy'}) {
10214: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10215: }
10216: if ($args->{'setcontent'}) {
10217: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10218: }
10219: }
10220: if ($args->{'reshome'}) {
10221: $cenv{'reshome'}=$args->{'reshome'}.'/';
10222: $cenv{'reshome'}=~s/\/+$/\//;
10223: }
10224: #
10225: # course has keyed access
10226: #
10227: if ($args->{'setkeys'}) {
10228: $cenv{'keyaccess'}='yes';
10229: }
10230: # if specified, key authority is not course, but user
10231: # only active if keyaccess is yes
10232: if ($args->{'keyauth'}) {
1.487 albertel 10233: my ($user,$domain) = split(':',$args->{'keyauth'});
10234: $user = &LONCAPA::clean_username($user);
10235: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10236: if ($user ne '' && $domain ne '') {
1.487 albertel 10237: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10238: }
10239: }
10240:
10241: if ($args->{'disresdis'}) {
10242: $cenv{'pch.roles.denied'}='st';
10243: }
10244: if ($args->{'disablechat'}) {
10245: $cenv{'plc.roles.denied'}='st';
10246: }
10247:
10248: # Record we've not yet viewed the Course Initialization Helper for this
10249: # course
10250: $cenv{'course.helper.not.run'} = 1;
10251: #
10252: # Use new Randomseed
10253: #
10254: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10255: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10256: #
10257: # The encryption code and receipt prefix for this course
10258: #
10259: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10260: $cenv{'internal.encpref'}=100+int(9*rand(99));
10261: #
10262: # By default, use standard grading
10263: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10264:
1.541 raeburn 10265: $outcome .= $linefeed.&mt('Setting environment').': '.
10266: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10267: #
10268: # Open all assignments
10269: #
10270: if ($args->{'openall'}) {
10271: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10272: my %storecontent = ($storeunder => time,
10273: $storeunder.'.type' => 'date_start');
10274:
10275: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10276: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10277: }
10278: #
10279: # Set first page
10280: #
10281: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10282: || ($cloneid)) {
1.445 albertel 10283: use LONCAPA::map;
1.444 albertel 10284: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10285:
10286: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10287: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10288:
1.444 albertel 10289: $outcome .= ($fatal?$errtext:'read ok').' - ';
10290: my $title; my $url;
10291: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10292: $title=&mt('Syllabus');
1.444 albertel 10293: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10294: } else {
1.690 bisitz 10295: $title=&mt('Navigate Contents');
1.444 albertel 10296: $url='/adm/navmaps';
10297: }
1.445 albertel 10298:
10299: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10300: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10301:
10302: if ($errtext) { $fatal=2; }
1.541 raeburn 10303: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10304: }
1.566 albertel 10305:
10306: return (1,$outcome);
1.444 albertel 10307: }
10308:
10309: ############################################################
10310: ############################################################
10311:
1.378 raeburn 10312: sub course_type {
10313: my ($cid) = @_;
10314: if (!defined($cid)) {
10315: $cid = $env{'request.course.id'};
10316: }
1.404 albertel 10317: if (defined($env{'course.'.$cid.'.type'})) {
10318: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10319: } else {
10320: return 'Course';
1.377 raeburn 10321: }
10322: }
1.156 albertel 10323:
1.406 raeburn 10324: sub group_term {
10325: my $crstype = &course_type();
10326: my %names = (
10327: 'Course' => 'group',
1.865 raeburn 10328: 'Community' => 'group',
1.406 raeburn 10329: );
10330: return $names{$crstype};
10331: }
10332:
1.902 raeburn 10333: sub course_types {
10334: my @types = ('official','unofficial','community');
10335: my %typename = (
10336: official => 'Official course',
10337: unofficial => 'Unofficial course',
10338: community => 'Community',
10339: );
10340: return (\@types,\%typename);
10341: }
10342:
1.156 albertel 10343: sub icon {
10344: my ($file)=@_;
1.505 albertel 10345: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10346: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10347: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10348: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10349: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10350: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10351: $curfext.".gif") {
10352: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10353: $curfext.".gif";
10354: }
10355: }
1.249 albertel 10356: return &lonhttpdurl($iconname);
1.154 albertel 10357: }
1.84 albertel 10358:
1.575 albertel 10359: sub lonhttpdurl {
1.692 www 10360: #
10361: # Had been used for "small fry" static images on separate port 8080.
10362: # Modify here if lightweight http functionality desired again.
10363: # Currently eliminated due to increasing firewall issues.
10364: #
1.575 albertel 10365: my ($url)=@_;
1.692 www 10366: return $url;
1.215 albertel 10367: }
10368:
1.213 albertel 10369: sub connection_aborted {
10370: my ($r)=@_;
10371: $r->print(" ");$r->rflush();
10372: my $c = $r->connection;
10373: return $c->aborted();
10374: }
10375:
1.221 foxr 10376: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10377: # strings as 'strings'.
10378: sub escape_single {
1.221 foxr 10379: my ($input) = @_;
1.223 albertel 10380: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10381: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10382: return $input;
10383: }
1.223 albertel 10384:
1.222 foxr 10385: # Same as escape_single, but escape's "'s This
10386: # can be used for "strings"
10387: sub escape_double {
10388: my ($input) = @_;
10389: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10390: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10391: return $input;
10392: }
1.223 albertel 10393:
1.222 foxr 10394: # Escapes the last element of a full URL.
10395: sub escape_url {
10396: my ($url) = @_;
1.238 raeburn 10397: my @urlslices = split(/\//, $url,-1);
1.369 www 10398: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10399: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10400: }
1.462 albertel 10401:
1.820 raeburn 10402: sub compare_arrays {
10403: my ($arrayref1,$arrayref2) = @_;
10404: my (@difference,%count);
10405: @difference = ();
10406: %count = ();
10407: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10408: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10409: foreach my $element (keys(%count)) {
10410: if ($count{$element} == 1) {
10411: push(@difference,$element);
10412: }
10413: }
10414: }
10415: return @difference;
10416: }
10417:
1.817 bisitz 10418: # -------------------------------------------------------- Initialize user login
1.462 albertel 10419: sub init_user_environment {
1.463 albertel 10420: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10421: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10422:
10423: my $public=($username eq 'public' && $domain eq 'public');
10424:
10425: # See if old ID present, if so, remove
10426:
10427: my ($filename,$cookie,$userroles);
10428: my $now=time;
10429:
10430: if ($public) {
10431: my $max_public=100;
10432: my $oldest;
10433: my $oldest_time=0;
10434: for(my $next=1;$next<=$max_public;$next++) {
10435: if (-e $lonids."/publicuser_$next.id") {
10436: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10437: if ($mtime<$oldest_time || !$oldest_time) {
10438: $oldest_time=$mtime;
10439: $oldest=$next;
10440: }
10441: } else {
10442: $cookie="publicuser_$next";
10443: last;
10444: }
10445: }
10446: if (!$cookie) { $cookie="publicuser_$oldest"; }
10447: } else {
1.463 albertel 10448: # if this isn't a robot, kill any existing non-robot sessions
10449: if (!$args->{'robot'}) {
10450: opendir(DIR,$lonids);
10451: while ($filename=readdir(DIR)) {
10452: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10453: unlink($lonids.'/'.$filename);
10454: }
1.462 albertel 10455: }
1.463 albertel 10456: closedir(DIR);
1.462 albertel 10457: }
10458: # Give them a new cookie
1.463 albertel 10459: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10460: : $now.$$.int(rand(10000)));
1.463 albertel 10461: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10462:
10463: # Initialize roles
10464:
10465: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10466: }
10467: # ------------------------------------ Check browser type and MathML capability
10468:
10469: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10470: $clientunicode,$clientos) = &decode_user_agent($r);
10471:
10472: # ------------------------------------------------------------- Get environment
10473:
10474: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10475: my ($tmp) = keys(%userenv);
10476: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10477: # default remote control to off
10478: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
10479: } else {
10480: undef(%userenv);
10481: }
10482: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10483: $form->{'interface'}=$userenv{'interface'};
10484: }
10485: $env{'environment.remote'}=$userenv{'remote'};
10486: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10487:
10488: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10489: foreach my $option ('interface','localpath','localres') {
10490: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10491: }
10492: # --------------------------------------------------------- Write first profile
10493:
10494: {
10495: my %initial_env =
10496: ("user.name" => $username,
10497: "user.domain" => $domain,
10498: "user.home" => $authhost,
10499: "browser.type" => $clientbrowser,
10500: "browser.version" => $clientversion,
10501: "browser.mathml" => $clientmathml,
10502: "browser.unicode" => $clientunicode,
10503: "browser.os" => $clientos,
10504: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10505: "request.course.fn" => '',
10506: "request.course.uri" => '',
10507: "request.course.sec" => '',
10508: "request.role" => 'cm',
10509: "request.role.adv" => $env{'user.adv'},
10510: "request.host" => $ENV{'REMOTE_ADDR'},);
10511:
10512: if ($form->{'localpath'}) {
10513: $initial_env{"browser.localpath"} = $form->{'localpath'};
10514: $initial_env{"browser.localres"} = $form->{'localres'};
10515: }
10516:
10517: if ($public) {
10518: $initial_env{"environment.remote"} = "off";
10519: }
10520: if ($form->{'interface'}) {
10521: $form->{'interface'}=~s/\W//gs;
10522: $initial_env{"browser.interface"} = $form->{'interface'};
10523: $env{'browser.interface'}=$form->{'interface'};
10524: }
10525:
1.724 raeburn 10526: foreach my $tool ('aboutme','blog','portfolio') {
10527: $userenv{'availabletools.'.$tool} =
10528: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10529: }
10530:
1.864 raeburn 10531: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10532: $userenv{'canrequest.'.$crstype} =
10533: &Apache::lonnet::usertools_access($username,$domain,$crstype,
10534: 'reload','requestcourses');
10535: }
10536:
1.462 albertel 10537: $env{'user.environment'} = "$lonids/$cookie.id";
10538:
10539: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10540: &GDBM_WRCREAT(),0640)) {
10541: &_add_to_env(\%disk_env,\%initial_env);
10542: &_add_to_env(\%disk_env,\%userenv,'environment.');
10543: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10544: if (ref($args->{'extra_env'})) {
10545: &_add_to_env(\%disk_env,$args->{'extra_env'});
10546: }
1.462 albertel 10547: untie(%disk_env);
10548: } else {
1.705 tempelho 10549: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10550: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10551: return 'error: '.$!;
10552: }
10553: }
10554: $env{'request.role'}='cm';
10555: $env{'request.role.adv'}=$env{'user.adv'};
10556: $env{'browser.type'}=$clientbrowser;
10557:
10558: return $cookie;
10559:
10560: }
10561:
10562: sub _add_to_env {
10563: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10564: if (ref($env_data) eq 'HASH') {
10565: while (my ($key,$value) = each(%$env_data)) {
10566: $idf->{$prefix.$key} = $value;
10567: $env{$prefix.$key} = $value;
10568: }
1.462 albertel 10569: }
10570: }
10571:
1.685 tempelho 10572: # --- Get the symbolic name of a problem and the url
10573: sub get_symb {
10574: my ($request,$silent) = @_;
1.726 raeburn 10575: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10576: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10577: if ($symb eq '') {
10578: if (!$silent) {
10579: $request->print("Unable to handle ambiguous references:$url:.");
10580: return ();
10581: }
10582: }
10583: &Apache::lonenc::check_decrypt(\$symb);
10584: return ($symb);
10585: }
10586:
10587: # --------------------------------------------------------------Get annotation
10588:
10589: sub get_annotation {
10590: my ($symb,$enc) = @_;
10591:
10592: my $key = $symb;
10593: if (!$enc) {
10594: $key =
10595: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10596: }
10597: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10598: return $annotation{$key};
10599: }
10600:
10601: sub clean_symb {
1.731 raeburn 10602: my ($symb,$delete_enc) = @_;
1.685 tempelho 10603:
10604: &Apache::lonenc::check_decrypt(\$symb);
10605: my $enc = $env{'request.enc'};
1.731 raeburn 10606: if ($delete_enc) {
1.730 raeburn 10607: delete($env{'request.enc'});
10608: }
1.685 tempelho 10609:
10610: return ($symb,$enc);
10611: }
1.462 albertel 10612:
1.41 ng 10613: =pod
10614:
10615: =back
10616:
1.112 bowersj2 10617: =cut
1.41 ng 10618:
1.112 bowersj2 10619: 1;
10620: __END__;
1.41 ng 10621:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>