Annotation of loncom/interface/loncommon.pm, revision 1.985
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.985 ! raeburn 4: # $Id: loncommon.pm,v 1.984 2010/10/27 01:04:10 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.776 bisitz 409: <script type="text/javascript" language="Javascript">
1.824 bisitz 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.793 raeburn 412: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74 www 413: var url = '/adm/pickstudent?';
414: var filter;
1.558 albertel 415: if (!ignorefilter) {
416: eval('filter=document.'+formname+'.'+uname+'.value;');
417: }
1.74 www 418: if (filter != null) {
419: if (filter != '') {
420: url += 'filter='+filter+'&';
421: }
422: }
423: url += 'form=' + formname + '&unameelement='+uname+
424: '&udomelement='+udom;
1.111 www 425: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 426: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 427: var title = 'Student_Browser';
1.74 www 428: var options = 'scrollbars=1,resizable=1,menubar=0';
429: options += ',width=700,height=600';
430: stdeditbrowser = open(url,title,options,'1');
431: stdeditbrowser.focus();
432: }
1.824 bisitz 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.793 raeburn 439: my ($form,$unameele,$udomele,$courseadvonly)=@_;
440: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 441: if ($env{'request.course.id'}) {
1.302 albertel 442: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
443: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
444: '/'.$env{'request.course.sec'})) {
1.111 www 445: return '';
446: }
1.793 raeburn 447: if ($courseadvonly) {
448: $callargs .= ",'',1,1";
449: }
450: return '<span class="LC_nobreak">'.
451: '<a href="javascript:openstdbrowser('.$callargs.');">'.
452: &mt('Select User').'</a></span>';
1.74 www 453: }
1.258 albertel 454: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793 raeburn 455: $callargs .= ",1";
456: return '<span class="LC_nobreak">'.
457: '<a href="javascript:openstdbrowser('.$callargs.');">'.
458: &mt('Select User').'</a></span>';
1.111 www 459: }
460: return '';
1.91 www 461: }
462:
1.653 raeburn 463: sub authorbrowser_javascript {
464: return <<"ENDAUTHORBRW";
1.776 bisitz 465: <script type="text/javascript" language="JavaScript">
1.824 bisitz 466: // <![CDATA[
1.653 raeburn 467: var stdeditbrowser;
468:
469: function openauthorbrowser(formname,udom) {
470: var url = '/adm/pickauthor?';
471: url += 'form='+formname+'&roledom='+udom;
472: var title = 'Author_Browser';
473: var options = 'scrollbars=1,resizable=1,menubar=0';
474: options += ',width=700,height=600';
475: stdeditbrowser = open(url,title,options,'1');
476: stdeditbrowser.focus();
477: }
478:
1.824 bisitz 479: // ]]>
1.653 raeburn 480: </script>
481: ENDAUTHORBRW
482: }
483:
1.91 www 484: sub coursebrowser_javascript {
1.909 raeburn 485: my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932 raeburn 486: my $wintitle = 'Course_Browser';
1.931 raeburn 487: if ($crstype eq 'Community') {
1.932 raeburn 488: $wintitle = 'Community_Browser';
1.909 raeburn 489: }
1.876 raeburn 490: my $id_functions = &javascript_index_functions();
491: my $output = '
1.776 bisitz 492: <script type="text/javascript" language="JavaScript">
1.824 bisitz 493: // <![CDATA[
1.468 raeburn 494: var stdeditbrowser;'."\n";
1.876 raeburn 495:
496: $output .= <<"ENDSTDBRW";
1.909 raeburn 497: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 498: var url = '/adm/pickcourse?';
1.895 raeburn 499: var formid = getFormIdByName(formname);
1.876 raeburn 500: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 501: if (domainfilter != null) {
502: if (domainfilter != '') {
503: url += 'domainfilter='+domainfilter+'&';
504: }
505: }
1.91 www 506: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 507: '&cdomelement='+udom+
508: '&cnameelement='+desc;
1.468 raeburn 509: if (extra_element !=null && extra_element != '') {
1.594 raeburn 510: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 511: url += '&roleelement='+extra_element;
512: if (domainfilter == null || domainfilter == '') {
513: url += '&domainfilter='+extra_element;
514: }
1.234 raeburn 515: }
1.468 raeburn 516: else {
517: if (formname == 'portform') {
518: url += '&setroles='+extra_element;
1.800 raeburn 519: } else {
520: if (formname == 'rules') {
521: url += '&fixeddom='+extra_element;
522: }
1.468 raeburn 523: }
524: }
1.230 raeburn 525: }
1.909 raeburn 526: if (type != null && type != '') {
527: url += '&type='+type;
528: }
529: if (type_elem != null && type_elem != '') {
530: url += '&typeelement='+type_elem;
531: }
1.872 raeburn 532: if (formname == 'ccrs') {
533: var ownername = document.forms[formid].ccuname.value;
534: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
535: url += '&cloner='+ownername+':'+ownerdom;
536: }
1.293 raeburn 537: if (multflag !=null && multflag != '') {
538: url += '&multiple='+multflag;
539: }
1.909 raeburn 540: var title = '$wintitle';
1.91 www 541: var options = 'scrollbars=1,resizable=1,menubar=0';
542: options += ',width=700,height=600';
543: stdeditbrowser = open(url,title,options,'1');
544: stdeditbrowser.focus();
545: }
1.876 raeburn 546: $id_functions
547: ENDSTDBRW
1.905 raeburn 548: if (($sec_element ne '') || ($role_element ne '')) {
549: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876 raeburn 550: }
551: $output .= '
552: // ]]>
553: </script>';
554: return $output;
555: }
556:
557: sub javascript_index_functions {
558: return <<"ENDJS";
559:
560: function getFormIdByName(formname) {
561: for (var i=0;i<document.forms.length;i++) {
562: if (document.forms[i].name == formname) {
563: return i;
564: }
565: }
566: return -1;
567: }
568:
569: function getIndexByName(formid,item) {
570: for (var i=0;i<document.forms[formid].elements.length;i++) {
571: if (document.forms[formid].elements[i].name == item) {
572: return i;
573: }
574: }
575: return -1;
576: }
1.468 raeburn 577:
1.876 raeburn 578: function getDomainFromSelectbox(formname,udom) {
579: var userdom;
580: var formid = getFormIdByName(formname);
581: if (formid > -1) {
582: var domid = getIndexByName(formid,udom);
583: if (domid > -1) {
584: if (document.forms[formid].elements[domid].type == 'select-one') {
585: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
586: }
587: if (document.forms[formid].elements[domid].type == 'hidden') {
588: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 589: }
590: }
591: }
1.876 raeburn 592: return userdom;
593: }
594:
595: ENDJS
1.468 raeburn 596:
1.876 raeburn 597: }
598:
599: sub userbrowser_javascript {
600: my $id_functions = &javascript_index_functions();
601: return <<"ENDUSERBRW";
602:
1.888 raeburn 603: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 604: var url = '/adm/pickuser?';
605: var userdom = getDomainFromSelectbox(formname,udom);
606: if (userdom != null) {
607: if (userdom != '') {
608: url += 'srchdom='+userdom+'&';
609: }
610: }
611: url += 'form=' + formname + '&unameelement='+uname+
612: '&udomelement='+udom+
613: '&ulastelement='+ulast+
614: '&ufirstelement='+ufirst+
615: '&uemailelement='+uemail+
1.881 raeburn 616: '&hideudomelement='+hideudom+
617: '&coursedom='+crsdom;
1.888 raeburn 618: if ((caller != null) && (caller != undefined)) {
619: url += '&caller='+caller;
620: }
1.876 raeburn 621: var title = 'User_Browser';
622: var options = 'scrollbars=1,resizable=1,menubar=0';
623: options += ',width=700,height=600';
624: var stdeditbrowser = open(url,title,options,'1');
625: stdeditbrowser.focus();
626: }
627:
1.888 raeburn 628: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 629: var formid = getFormIdByName(formname);
630: if (formid > -1) {
1.888 raeburn 631: var unameid = getIndexByName(formid,uname);
1.876 raeburn 632: var domid = getIndexByName(formid,udom);
633: var hidedomid = getIndexByName(formid,origdom);
634: if (hidedomid > -1) {
635: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 636: var unameval = document.forms[formid].elements[unameid].value;
637: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
638: if (domid > -1) {
639: var slct = document.forms[formid].elements[domid];
640: if (slct.type == 'select-one') {
641: var i;
642: for (i=0;i<slct.length;i++) {
643: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
644: }
645: }
646: if (slct.type == 'hidden') {
647: slct.value = fixeddom;
1.876 raeburn 648: }
649: }
1.468 raeburn 650: }
651: }
652: }
1.876 raeburn 653: return;
654: }
655:
656: $id_functions
657: ENDUSERBRW
1.468 raeburn 658: }
659:
660: sub setsec_javascript {
1.905 raeburn 661: my ($sec_element,$formname,$role_element) = @_;
662: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
663: $communityrolestr);
664: if ($role_element ne '') {
665: my @allroles = ('st','ta','ep','in','ad');
666: foreach my $crstype ('Course','Community') {
667: if ($crstype eq 'Community') {
668: foreach my $role (@allroles) {
669: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
670: }
671: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
672: } else {
673: foreach my $role (@allroles) {
674: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
675: }
676: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
677: }
678: }
679: $rolestr = '"'.join('","',@allroles).'"';
680: $courserolestr = '"'.join('","',@courserolenames).'"';
681: $communityrolestr = '"'.join('","',@communityrolenames).'"';
682: }
1.468 raeburn 683: my $setsections = qq|
684: function setSect(sectionlist) {
1.629 raeburn 685: var sectionsArray = new Array();
686: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
687: sectionsArray = sectionlist.split(",");
688: }
1.468 raeburn 689: var numSections = sectionsArray.length;
690: document.$formname.$sec_element.length = 0;
691: if (numSections == 0) {
692: document.$formname.$sec_element.multiple=false;
693: document.$formname.$sec_element.size=1;
694: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
695: } else {
696: if (numSections == 1) {
697: document.$formname.$sec_element.multiple=false;
698: document.$formname.$sec_element.size=1;
699: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
700: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
701: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
702: } else {
703: for (var i=0; i<numSections; i++) {
704: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
705: }
706: document.$formname.$sec_element.multiple=true
707: if (numSections < 3) {
708: document.$formname.$sec_element.size=numSections;
709: } else {
710: document.$formname.$sec_element.size=3;
711: }
712: document.$formname.$sec_element.options[0].selected = false
713: }
714: }
1.91 www 715: }
1.905 raeburn 716:
717: function setRole(crstype) {
1.468 raeburn 718: |;
1.905 raeburn 719: if ($role_element eq '') {
720: $setsections .= ' return;
721: }
722: ';
723: } else {
724: $setsections .= qq|
725: var elementLength = document.$formname.$role_element.length;
726: var allroles = Array($rolestr);
727: var courserolenames = Array($courserolestr);
728: var communityrolenames = Array($communityrolestr);
729: if (elementLength != undefined) {
730: if (document.$formname.$role_element.options[5].value == 'cc') {
731: if (crstype == 'Course') {
732: return;
733: } else {
734: allroles[5] = 'co';
735: for (var i=0; i<6; i++) {
736: document.$formname.$role_element.options[i].value = allroles[i];
737: document.$formname.$role_element.options[i].text = communityrolenames[i];
738: }
739: }
740: } else {
741: if (crstype == 'Community') {
742: return;
743: } else {
744: allroles[5] = 'cc';
745: for (var i=0; i<6; i++) {
746: document.$formname.$role_element.options[i].value = allroles[i];
747: document.$formname.$role_element.options[i].text = courserolenames[i];
748: }
749: }
750: }
751: }
752: return;
753: }
754: |;
755: }
1.468 raeburn 756: return $setsections;
757: }
758:
1.91 www 759: sub selectcourse_link {
1.909 raeburn 760: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
761: $typeelement) = @_;
762: my $type = $selecttype;
1.871 raeburn 763: my $linktext = &mt('Select Course');
764: if ($selecttype eq 'Community') {
1.909 raeburn 765: $linktext = &mt('Select Community');
1.906 raeburn 766: } elsif ($selecttype eq 'Course/Community') {
767: $linktext = &mt('Select Course/Community');
1.909 raeburn 768: $type = '';
1.871 raeburn 769: }
1.787 bisitz 770: return '<span class="LC_nobreak">'
771: ."<a href='"
772: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
773: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 774: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 775: ."'>".$linktext.'</a>'
1.787 bisitz 776: .'</span>';
1.74 www 777: }
1.42 matthew 778:
1.653 raeburn 779: sub selectauthor_link {
780: my ($form,$udom)=@_;
781: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
782: &mt('Select Author').'</a>';
783: }
784:
1.876 raeburn 785: sub selectuser_link {
1.881 raeburn 786: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 787: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 788: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 789: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 790: ');">'.$linktext.'</a>';
1.876 raeburn 791: }
792:
1.273 raeburn 793: sub check_uncheck_jscript {
794: my $jscript = <<"ENDSCRT";
795: function checkAll(field) {
796: if (field.length > 0) {
797: for (i = 0; i < field.length; i++) {
798: field[i].checked = true ;
799: }
800: } else {
801: field.checked = true
802: }
803: }
804:
805: function uncheckAll(field) {
806: if (field.length > 0) {
807: for (i = 0; i < field.length; i++) {
808: field[i].checked = false ;
1.543 albertel 809: }
810: } else {
1.273 raeburn 811: field.checked = false ;
812: }
813: }
814: ENDSCRT
815: return $jscript;
816: }
817:
1.656 www 818: sub select_timezone {
1.659 raeburn 819: my ($name,$selected,$onchange,$includeempty)=@_;
820: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
821: if ($includeempty) {
822: $output .= '<option value=""';
823: if (($selected eq '') || ($selected eq 'local')) {
824: $output .= ' selected="selected" ';
825: }
826: $output .= '> </option>';
827: }
1.657 raeburn 828: my @timezones = DateTime::TimeZone->all_names;
829: foreach my $tzone (@timezones) {
830: $output.= '<option value="'.$tzone.'"';
831: if ($tzone eq $selected) {
832: $output.=' selected="selected"';
833: }
834: $output.=">$tzone</option>\n";
1.656 www 835: }
836: $output.="</select>";
837: return $output;
838: }
1.273 raeburn 839:
1.687 raeburn 840: sub select_datelocale {
841: my ($name,$selected,$onchange,$includeempty)=@_;
842: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
843: if ($includeempty) {
844: $output .= '<option value=""';
845: if ($selected eq '') {
846: $output .= ' selected="selected" ';
847: }
848: $output .= '> </option>';
849: }
850: my (@possibles,%locale_names);
851: my @locales = DateTime::Locale::Catalog::Locales;
852: foreach my $locale (@locales) {
853: if (ref($locale) eq 'HASH') {
854: my $id = $locale->{'id'};
855: if ($id ne '') {
856: my $en_terr = $locale->{'en_territory'};
857: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 858: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 859: if (grep(/^en$/,@languages) || !@languages) {
860: if ($en_terr ne '') {
861: $locale_names{$id} = '('.$en_terr.')';
862: } elsif ($native_terr ne '') {
863: $locale_names{$id} = $native_terr;
864: }
865: } else {
866: if ($native_terr ne '') {
867: $locale_names{$id} = $native_terr.' ';
868: } elsif ($en_terr ne '') {
869: $locale_names{$id} = '('.$en_terr.')';
870: }
871: }
872: push (@possibles,$id);
873: }
874: }
875: }
876: foreach my $item (sort(@possibles)) {
877: $output.= '<option value="'.$item.'"';
878: if ($item eq $selected) {
879: $output.=' selected="selected"';
880: }
881: $output.=">$item";
882: if ($locale_names{$item} ne '') {
883: $output.=" $locale_names{$item}</option>\n";
884: }
885: $output.="</option>\n";
886: }
887: $output.="</select>";
888: return $output;
889: }
890:
1.792 raeburn 891: sub select_language {
892: my ($name,$selected,$includeempty) = @_;
893: my %langchoices;
894: if ($includeempty) {
895: %langchoices = ('' => 'No language preference');
896: }
897: foreach my $id (&languageids()) {
898: my $code = &supportedlanguagecode($id);
899: if ($code) {
900: $langchoices{$code} = &plainlanguagedescription($id);
901: }
902: }
1.970 raeburn 903: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 904: }
905:
1.42 matthew 906: =pod
1.36 matthew 907:
1.648 raeburn 908: =item * &linked_select_forms(...)
1.36 matthew 909:
910: linked_select_forms returns a string containing a <script></script> block
911: and html for two <select> menus. The select menus will be linked in that
912: changing the value of the first menu will result in new values being placed
913: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 914: order unless a defined order is provided.
1.36 matthew 915:
916: linked_select_forms takes the following ordered inputs:
917:
918: =over 4
919:
1.112 bowersj2 920: =item * $formname, the name of the <form> tag
1.36 matthew 921:
1.112 bowersj2 922: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 923:
1.112 bowersj2 924: =item * $firstdefault, the default value for the first menu
1.36 matthew 925:
1.112 bowersj2 926: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 927:
1.112 bowersj2 928: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 929:
1.112 bowersj2 930: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 931:
1.609 raeburn 932: =item * $menuorder, the order of values in the first menu
933:
1.41 ng 934: =back
935:
1.36 matthew 936: Below is an example of such a hash. Only the 'text', 'default', and
937: 'select2' keys must appear as stated. keys(%menu) are the possible
938: values for the first select menu. The text that coincides with the
1.41 ng 939: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 940: and text for the second menu are given in the hash pointed to by
941: $menu{$choice1}->{'select2'}.
942:
1.112 bowersj2 943: my %menu = ( A1 => { text =>"Choice A1" ,
944: default => "B3",
945: select2 => {
946: B1 => "Choice B1",
947: B2 => "Choice B2",
948: B3 => "Choice B3",
949: B4 => "Choice B4"
1.609 raeburn 950: },
951: order => ['B4','B3','B1','B2'],
1.112 bowersj2 952: },
953: A2 => { text =>"Choice A2" ,
954: default => "C2",
955: select2 => {
956: C1 => "Choice C1",
957: C2 => "Choice C2",
958: C3 => "Choice C3"
1.609 raeburn 959: },
960: order => ['C2','C1','C3'],
1.112 bowersj2 961: },
962: A3 => { text =>"Choice A3" ,
963: default => "D6",
964: select2 => {
965: D1 => "Choice D1",
966: D2 => "Choice D2",
967: D3 => "Choice D3",
968: D4 => "Choice D4",
969: D5 => "Choice D5",
970: D6 => "Choice D6",
971: D7 => "Choice D7"
1.609 raeburn 972: },
973: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 974: }
975: );
1.36 matthew 976:
977: =cut
978:
979: sub linked_select_forms {
980: my ($formname,
981: $middletext,
982: $firstdefault,
983: $firstselectname,
984: $secondselectname,
1.609 raeburn 985: $hashref,
986: $menuorder,
1.36 matthew 987: ) = @_;
988: my $second = "document.$formname.$secondselectname";
989: my $first = "document.$formname.$firstselectname";
990: # output the javascript to do the changing
991: my $result = '';
1.776 bisitz 992: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 993: $result.="// <![CDATA[\n";
1.36 matthew 994: $result.="var select2data = new Object();\n";
995: $" = '","';
996: my $debug = '';
997: foreach my $s1 (sort(keys(%$hashref))) {
998: $result.="select2data.d_$s1 = new Object();\n";
999: $result.="select2data.d_$s1.def = new String('".
1000: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1001: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1002: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1003: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1004: @s2values = @{$hashref->{$s1}->{'order'}};
1005: }
1.36 matthew 1006: $result.="\"@s2values\");\n";
1007: $result.="select2data.d_$s1.texts = new Array(";
1008: my @s2texts;
1009: foreach my $value (@s2values) {
1010: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1011: }
1012: $result.="\"@s2texts\");\n";
1013: }
1014: $"=' ';
1015: $result.= <<"END";
1016:
1017: function select1_changed() {
1018: // Determine new choice
1019: var newvalue = "d_" + $first.value;
1020: // update select2
1021: var values = select2data[newvalue].values;
1022: var texts = select2data[newvalue].texts;
1023: var select2def = select2data[newvalue].def;
1024: var i;
1025: // out with the old
1026: for (i = 0; i < $second.options.length; i++) {
1027: $second.options[i] = null;
1028: }
1029: // in with the nuclear
1030: for (i=0;i<values.length; i++) {
1031: $second.options[i] = new Option(values[i]);
1.143 matthew 1032: $second.options[i].value = values[i];
1.36 matthew 1033: $second.options[i].text = texts[i];
1034: if (values[i] == select2def) {
1035: $second.options[i].selected = true;
1036: }
1037: }
1038: }
1.824 bisitz 1039: // ]]>
1.36 matthew 1040: </script>
1041: END
1042: # output the initial values for the selection lists
1043: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1044: my @order = sort(keys(%{$hashref}));
1045: if (ref($menuorder) eq 'ARRAY') {
1046: @order = @{$menuorder};
1047: }
1048: foreach my $value (@order) {
1.36 matthew 1049: $result.=" <option value=\"$value\" ";
1.253 albertel 1050: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1051: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1052: }
1053: $result .= "</select>\n";
1054: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1055: $result .= $middletext;
1056: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1057: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1058:
1059: my @secondorder = sort(keys(%select2));
1060: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1061: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1062: }
1063: foreach my $value (@secondorder) {
1.36 matthew 1064: $result.=" <option value=\"$value\" ";
1.253 albertel 1065: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1066: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1067: }
1068: $result .= "</select>\n";
1069: # return $debug;
1070: return $result;
1071: } # end of sub linked_select_forms {
1072:
1.45 matthew 1073: =pod
1.44 bowersj2 1074:
1.973 raeburn 1075: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1076:
1.112 bowersj2 1077: Returns a string corresponding to an HTML link to the given help
1078: $topic, where $topic corresponds to the name of a .tex file in
1079: /home/httpd/html/adm/help/tex, with underscores replaced by
1080: spaces.
1081:
1082: $text will optionally be linked to the same topic, allowing you to
1083: link text in addition to the graphic. If you do not want to link
1084: text, but wish to specify one of the later parameters, pass an
1085: empty string.
1086:
1087: $stayOnPage is a value that will be interpreted as a boolean. If true,
1088: the link will not open a new window. If false, the link will open
1089: a new window using Javascript. (Default is false.)
1090:
1091: $width and $height are optional numerical parameters that will
1092: override the width and height of the popped up window, which may
1.973 raeburn 1093: be useful for certain help topics with big pictures included.
1094:
1095: $imgid is the id of the img tag used for the help icon. This may be
1096: used in a javascript call to switch the image src. See
1097: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1098:
1099: =cut
1100:
1101: sub help_open_topic {
1.973 raeburn 1102: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1103: $text = "" if (not defined $text);
1.44 bowersj2 1104: $stayOnPage = 0 if (not defined $stayOnPage);
1105: $width = 350 if (not defined $width);
1106: $height = 400 if (not defined $height);
1107: my $filename = $topic;
1108: $filename =~ s/ /_/g;
1109:
1.48 bowersj2 1110: my $template = "";
1111: my $link;
1.572 banghart 1112:
1.159 www 1113: $topic=~s/\W/\_/g;
1.44 bowersj2 1114:
1.572 banghart 1115: if (!$stayOnPage) {
1.72 bowersj2 1116: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1117: } else {
1.48 bowersj2 1118: $link = "/adm/help/${filename}.hlp";
1119: }
1120:
1121: # Add the text
1.755 neumanie 1122: if ($text ne "") {
1.763 bisitz 1123: $template.='<span class="LC_help_open_topic">'
1124: .'<a target="_top" href="'.$link.'">'
1125: .$text.'</a>';
1.48 bowersj2 1126: }
1127:
1.763 bisitz 1128: # (Always) Add the graphic
1.179 matthew 1129: my $title = &mt('Online Help');
1.667 raeburn 1130: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1131: if ($imgid ne '') {
1132: $imgid = ' id="'.$imgid.'"';
1133: }
1.763 bisitz 1134: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1135: .'<img src="'.$helpicon.'" border="0"'
1136: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1137: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1138: .' /></a>';
1139: if ($text ne "") {
1140: $template.='</span>';
1141: }
1.44 bowersj2 1142: return $template;
1143:
1.106 bowersj2 1144: }
1145:
1146: # This is a quicky function for Latex cheatsheet editing, since it
1147: # appears in at least four places
1148: sub helpLatexCheatsheet {
1.732 raeburn 1149: my ($topic,$text,$not_author) = @_;
1150: my $out;
1.106 bowersj2 1151: my $addOther = '';
1.732 raeburn 1152: if ($topic) {
1.763 bisitz 1153: $addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
1154: undef, undef, 600).
1155: '</span> ';
1156: }
1157: $out = '<span>' # Start cheatsheet
1158: .$addOther
1159: .'<span>'
1160: .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
1161: undef,undef,600)
1162: .'</span> <span>'
1163: .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
1164: undef,undef,600)
1165: .'</span>';
1.732 raeburn 1166: unless ($not_author) {
1.763 bisitz 1167: $out .= ' <span>'
1168: .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
1169: undef,undef,600)
1170: .'</span>';
1.732 raeburn 1171: }
1.763 bisitz 1172: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1173: return $out;
1.172 www 1174: }
1175:
1.430 albertel 1176: sub general_help {
1177: my $helptopic='Student_Intro';
1178: if ($env{'request.role'}=~/^(ca|au)/) {
1179: $helptopic='Authoring_Intro';
1.907 raeburn 1180: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1181: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1182: } elsif ($env{'request.role'}=~/^dc/) {
1183: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1184: }
1185: return $helptopic;
1186: }
1187:
1188: sub update_help_link {
1189: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1190: my $origurl = $ENV{'REQUEST_URI'};
1191: $origurl=~s|^/~|/priv/|;
1192: my $timestamp = time;
1193: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1194: $$datum = &escape($$datum);
1195: }
1196:
1197: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1198: my $output .= <<"ENDOUTPUT";
1199: <script type="text/javascript">
1.824 bisitz 1200: // <![CDATA[
1.430 albertel 1201: banner_link = '$banner_link';
1.824 bisitz 1202: // ]]>
1.430 albertel 1203: </script>
1204: ENDOUTPUT
1205: return $output;
1206: }
1207:
1208: # now just updates the help link and generates a blue icon
1.193 raeburn 1209: sub help_open_menu {
1.430 albertel 1210: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1211: = @_;
1.949 droeschl 1212: $stayOnPage = 1;
1.430 albertel 1213: my $output;
1214: if ($component_help) {
1215: if (!$text) {
1216: $output=&help_open_topic($component_help,undef,$stayOnPage,
1217: $width,$height);
1218: } else {
1219: my $help_text;
1220: $help_text=&unescape($topic);
1221: $output='<table><tr><td>'.
1222: &help_open_topic($component_help,$help_text,$stayOnPage,
1223: $width,$height).'</td></tr></table>';
1224: }
1225: }
1226: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1227: return $output.$banner_link;
1228: }
1229:
1230: sub top_nav_help {
1231: my ($text) = @_;
1.436 albertel 1232: $text = &mt($text);
1.949 droeschl 1233: my $stay_on_page = 1;
1234:
1.572 banghart 1235: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1236: : "javascript:helpMenu('open')";
1.572 banghart 1237: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1238:
1.201 raeburn 1239: my $title = &mt('Get help');
1.436 albertel 1240:
1241: return <<"END";
1242: $banner_link
1243: <a href="$link" title="$title">$text</a>
1244: END
1245: }
1246:
1247: sub help_menu_js {
1248: my ($text) = @_;
1.949 droeschl 1249: my $stayOnPage = 1;
1.436 albertel 1250: my $width = 620;
1251: my $height = 600;
1.430 albertel 1252: my $helptopic=&general_help();
1253: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1254: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1255: my $start_page =
1256: &Apache::loncommon::start_page('Help Menu', undef,
1257: {'frameset' => 1,
1258: 'js_ready' => 1,
1259: 'add_entries' => {
1260: 'border' => '0',
1.579 raeburn 1261: 'rows' => "110,*",},});
1.331 albertel 1262: my $end_page =
1263: &Apache::loncommon::end_page({'frameset' => 1,
1264: 'js_ready' => 1,});
1265:
1.436 albertel 1266: my $template .= <<"ENDTEMPLATE";
1267: <script type="text/javascript">
1.877 bisitz 1268: // <![CDATA[
1.253 albertel 1269: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1270: var banner_link = '';
1.243 raeburn 1271: function helpMenu(target) {
1272: var caller = this;
1273: if (target == 'open') {
1274: var newWindow = null;
1275: try {
1.262 albertel 1276: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1277: }
1278: catch(error) {
1279: writeHelp(caller);
1280: return;
1281: }
1282: if (newWindow) {
1283: caller = newWindow;
1284: }
1.193 raeburn 1285: }
1.243 raeburn 1286: writeHelp(caller);
1287: return;
1288: }
1289: function writeHelp(caller) {
1.430 albertel 1290: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1291: caller.document.close()
1292: caller.focus()
1.193 raeburn 1293: }
1.877 bisitz 1294: // END LON-CAPA Internal -->
1.253 albertel 1295: // ]]>
1.436 albertel 1296: </script>
1.193 raeburn 1297: ENDTEMPLATE
1298: return $template;
1299: }
1300:
1.172 www 1301: sub help_open_bug {
1302: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1303: unless ($env{'user.adv'}) { return ''; }
1.172 www 1304: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1305: $text = "" if (not defined $text);
1306: $stayOnPage=1;
1.184 albertel 1307: $width = 600 if (not defined $width);
1308: $height = 600 if (not defined $height);
1.172 www 1309:
1310: $topic=~s/\W+/\+/g;
1311: my $link='';
1312: my $template='';
1.379 albertel 1313: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1314: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1315: if (!$stayOnPage)
1316: {
1317: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1318: }
1319: else
1320: {
1321: $link = $url;
1322: }
1323: # Add the text
1324: if ($text ne "")
1325: {
1326: $template .=
1327: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1328: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1329: }
1330:
1331: # Add the graphic
1.179 matthew 1332: my $title = &mt('Report a Bug');
1.215 albertel 1333: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1334: $template .= <<"ENDTEMPLATE";
1.436 albertel 1335: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1336: ENDTEMPLATE
1337: if ($text ne '') { $template.='</td></tr></table>' };
1338: return $template;
1339:
1340: }
1341:
1342: sub help_open_faq {
1343: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1344: unless ($env{'user.adv'}) { return ''; }
1.172 www 1345: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1346: $text = "" if (not defined $text);
1347: $stayOnPage=1;
1348: $width = 350 if (not defined $width);
1349: $height = 400 if (not defined $height);
1350:
1351: $topic=~s/\W+/\+/g;
1352: my $link='';
1353: my $template='';
1354: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1355: if (!$stayOnPage)
1356: {
1357: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1358: }
1359: else
1360: {
1361: $link = $url;
1362: }
1363:
1364: # Add the text
1365: if ($text ne "")
1366: {
1367: $template .=
1.173 www 1368: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1369: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1370: }
1371:
1372: # Add the graphic
1.179 matthew 1373: my $title = &mt('View the FAQ');
1.215 albertel 1374: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1375: $template .= <<"ENDTEMPLATE";
1.436 albertel 1376: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1377: ENDTEMPLATE
1378: if ($text ne '') { $template.='</td></tr></table>' };
1379: return $template;
1380:
1.44 bowersj2 1381: }
1.37 matthew 1382:
1.180 matthew 1383: ###############################################################
1384: ###############################################################
1385:
1.45 matthew 1386: =pod
1387:
1.648 raeburn 1388: =item * &change_content_javascript():
1.256 matthew 1389:
1390: This and the next function allow you to create small sections of an
1391: otherwise static HTML page that you can update on the fly with
1392: Javascript, even in Netscape 4.
1393:
1394: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1395: must be written to the HTML page once. It will prove the Javascript
1396: function "change(name, content)". Calling the change function with the
1397: name of the section
1398: you want to update, matching the name passed to C<changable_area>, and
1399: the new content you want to put in there, will put the content into
1400: that area.
1401:
1402: B<Note>: Netscape 4 only reserves enough space for the changable area
1403: to contain room for the original contents. You need to "make space"
1404: for whatever changes you wish to make, and be B<sure> to check your
1405: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1406: it's adequate for updating a one-line status display, but little more.
1407: This script will set the space to 100% width, so you only need to
1408: worry about height in Netscape 4.
1409:
1410: Modern browsers are much less limiting, and if you can commit to the
1411: user not using Netscape 4, this feature may be used freely with
1412: pretty much any HTML.
1413:
1414: =cut
1415:
1416: sub change_content_javascript {
1417: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1418: if ($env{'browser.type'} eq 'netscape' &&
1419: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1420: return (<<NETSCAPE4);
1421: function change(name, content) {
1422: doc = document.layers[name+"___escape"].layers[0].document;
1423: doc.open();
1424: doc.write(content);
1425: doc.close();
1426: }
1427: NETSCAPE4
1428: } else {
1429: # Otherwise, we need to use semi-standards-compliant code
1430: # (technically, "innerHTML" isn't standard but the equivalent
1431: # is really scary, and every useful browser supports it
1432: return (<<DOMBASED);
1433: function change(name, content) {
1434: element = document.getElementById(name);
1435: element.innerHTML = content;
1436: }
1437: DOMBASED
1438: }
1439: }
1440:
1441: =pod
1442:
1.648 raeburn 1443: =item * &changable_area($name,$origContent):
1.256 matthew 1444:
1445: This provides a "changable area" that can be modified on the fly via
1446: the Javascript code provided in C<change_content_javascript>. $name is
1447: the name you will use to reference the area later; do not repeat the
1448: same name on a given HTML page more then once. $origContent is what
1449: the area will originally contain, which can be left blank.
1450:
1451: =cut
1452:
1453: sub changable_area {
1454: my ($name, $origContent) = @_;
1455:
1.258 albertel 1456: if ($env{'browser.type'} eq 'netscape' &&
1457: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1458: # If this is netscape 4, we need to use the Layer tag
1459: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1460: } else {
1461: return "<span id='$name'>$origContent</span>";
1462: }
1463: }
1464:
1465: =pod
1466:
1.648 raeburn 1467: =item * &viewport_geometry_js
1.590 raeburn 1468:
1469: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1470:
1471: =cut
1472:
1473:
1474: sub viewport_geometry_js {
1475: return <<"GEOMETRY";
1476: var Geometry = {};
1477: function init_geometry() {
1478: if (Geometry.init) { return };
1479: Geometry.init=1;
1480: if (window.innerHeight) {
1481: Geometry.getViewportHeight = function() { return window.innerHeight; };
1482: Geometry.getViewportWidth = function() { return window.innerWidth; };
1483: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1484: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1485: }
1486: else if (document.documentElement && document.documentElement.clientHeight) {
1487: Geometry.getViewportHeight =
1488: function() { return document.documentElement.clientHeight; };
1489: Geometry.getViewportWidth =
1490: function() { return document.documentElement.clientWidth; };
1491:
1492: Geometry.getHorizontalScroll =
1493: function() { return document.documentElement.scrollLeft; };
1494: Geometry.getVerticalScroll =
1495: function() { return document.documentElement.scrollTop; };
1496: }
1497: else if (document.body.clientHeight) {
1498: Geometry.getViewportHeight =
1499: function() { return document.body.clientHeight; };
1500: Geometry.getViewportWidth =
1501: function() { return document.body.clientWidth; };
1502: Geometry.getHorizontalScroll =
1503: function() { return document.body.scrollLeft; };
1504: Geometry.getVerticalScroll =
1505: function() { return document.body.scrollTop; };
1506: }
1507: }
1508:
1509: GEOMETRY
1510: }
1511:
1512: =pod
1513:
1.648 raeburn 1514: =item * &viewport_size_js()
1.590 raeburn 1515:
1516: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1517:
1518: =cut
1519:
1520: sub viewport_size_js {
1521: my $geometry = &viewport_geometry_js();
1522: return <<"DIMS";
1523:
1524: $geometry
1525:
1526: function getViewportDims(width,height) {
1527: init_geometry();
1528: width.value = Geometry.getViewportWidth();
1529: height.value = Geometry.getViewportHeight();
1530: return;
1531: }
1532:
1533: DIMS
1534: }
1535:
1536: =pod
1537:
1.648 raeburn 1538: =item * &resize_textarea_js()
1.565 albertel 1539:
1540: emits the needed javascript to resize a textarea to be as big as possible
1541:
1542: creates a function resize_textrea that takes two IDs first should be
1543: the id of the element to resize, second should be the id of a div that
1544: surrounds everything that comes after the textarea, this routine needs
1545: to be attached to the <body> for the onload and onresize events.
1546:
1.648 raeburn 1547: =back
1.565 albertel 1548:
1549: =cut
1550:
1551: sub resize_textarea_js {
1.590 raeburn 1552: my $geometry = &viewport_geometry_js();
1.565 albertel 1553: return <<"RESIZE";
1554: <script type="text/javascript">
1.824 bisitz 1555: // <![CDATA[
1.590 raeburn 1556: $geometry
1.565 albertel 1557:
1.588 albertel 1558: function getX(element) {
1559: var x = 0;
1560: while (element) {
1561: x += element.offsetLeft;
1562: element = element.offsetParent;
1563: }
1564: return x;
1565: }
1566: function getY(element) {
1567: var y = 0;
1568: while (element) {
1569: y += element.offsetTop;
1570: element = element.offsetParent;
1571: }
1572: return y;
1573: }
1574:
1575:
1.565 albertel 1576: function resize_textarea(textarea_id,bottom_id) {
1577: init_geometry();
1578: var textarea = document.getElementById(textarea_id);
1579: //alert(textarea);
1580:
1.588 albertel 1581: var textarea_top = getY(textarea);
1.565 albertel 1582: var textarea_height = textarea.offsetHeight;
1583: var bottom = document.getElementById(bottom_id);
1.588 albertel 1584: var bottom_top = getY(bottom);
1.565 albertel 1585: var bottom_height = bottom.offsetHeight;
1586: var window_height = Geometry.getViewportHeight();
1.588 albertel 1587: var fudge = 23;
1.565 albertel 1588: var new_height = window_height-fudge-textarea_top-bottom_height;
1589: if (new_height < 300) {
1590: new_height = 300;
1591: }
1592: textarea.style.height=new_height+'px';
1593: }
1.824 bisitz 1594: // ]]>
1.565 albertel 1595: </script>
1596: RESIZE
1597:
1598: }
1599:
1600: =pod
1601:
1.256 matthew 1602: =head1 Excel and CSV file utility routines
1603:
1604: =over 4
1605:
1606: =cut
1607:
1608: ###############################################################
1609: ###############################################################
1610:
1611: =pod
1612:
1.648 raeburn 1613: =item * &csv_translate($text)
1.37 matthew 1614:
1.185 www 1615: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1616: format.
1617:
1618: =cut
1619:
1.180 matthew 1620: ###############################################################
1621: ###############################################################
1.37 matthew 1622: sub csv_translate {
1623: my $text = shift;
1624: $text =~ s/\"/\"\"/g;
1.209 albertel 1625: $text =~ s/\n/ /g;
1.37 matthew 1626: return $text;
1627: }
1.180 matthew 1628:
1629: ###############################################################
1630: ###############################################################
1631:
1632: =pod
1633:
1.648 raeburn 1634: =item * &define_excel_formats()
1.180 matthew 1635:
1636: Define some commonly used Excel cell formats.
1637:
1638: Currently supported formats:
1639:
1640: =over 4
1641:
1642: =item header
1643:
1644: =item bold
1645:
1646: =item h1
1647:
1648: =item h2
1649:
1650: =item h3
1651:
1.256 matthew 1652: =item h4
1653:
1654: =item i
1655:
1.180 matthew 1656: =item date
1657:
1658: =back
1659:
1660: Inputs: $workbook
1661:
1662: Returns: $format, a hash reference.
1663:
1664: =cut
1665:
1666: ###############################################################
1667: ###############################################################
1668: sub define_excel_formats {
1669: my ($workbook) = @_;
1670: my $format;
1671: $format->{'header'} = $workbook->add_format(bold => 1,
1672: bottom => 1,
1673: align => 'center');
1674: $format->{'bold'} = $workbook->add_format(bold=>1);
1675: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1676: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1677: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1678: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1679: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1680: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1681: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1682: return $format;
1683: }
1684:
1685: ###############################################################
1686: ###############################################################
1.113 bowersj2 1687:
1688: =pod
1689:
1.648 raeburn 1690: =item * &create_workbook()
1.255 matthew 1691:
1692: Create an Excel worksheet. If it fails, output message on the
1693: request object and return undefs.
1694:
1695: Inputs: Apache request object
1696:
1697: Returns (undef) on failure,
1698: Excel worksheet object, scalar with filename, and formats
1699: from &Apache::loncommon::define_excel_formats on success
1700:
1701: =cut
1702:
1703: ###############################################################
1704: ###############################################################
1705: sub create_workbook {
1706: my ($r) = @_;
1707: #
1708: # Create the excel spreadsheet
1709: my $filename = '/prtspool/'.
1.258 albertel 1710: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1711: time.'_'.rand(1000000000).'.xls';
1712: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1713: if (! defined($workbook)) {
1714: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1715: $r->print(
1716: '<p class="LC_error">'
1717: .&mt('Problems occurred in creating the new Excel file.')
1718: .' '.&mt('This error has been logged.')
1719: .' '.&mt('Please alert your LON-CAPA administrator.')
1720: .'</p>'
1721: );
1.255 matthew 1722: return (undef);
1723: }
1724: #
1725: $workbook->set_tempdir('/home/httpd/perl/tmp');
1726: #
1727: my $format = &Apache::loncommon::define_excel_formats($workbook);
1728: return ($workbook,$filename,$format);
1729: }
1730:
1731: ###############################################################
1732: ###############################################################
1733:
1734: =pod
1735:
1.648 raeburn 1736: =item * &create_text_file()
1.113 bowersj2 1737:
1.542 raeburn 1738: Create a file to write to and eventually make available to the user.
1.256 matthew 1739: If file creation fails, outputs an error message on the request object and
1740: return undefs.
1.113 bowersj2 1741:
1.256 matthew 1742: Inputs: Apache request object, and file suffix
1.113 bowersj2 1743:
1.256 matthew 1744: Returns (undef) on failure,
1745: Filehandle and filename on success.
1.113 bowersj2 1746:
1747: =cut
1748:
1.256 matthew 1749: ###############################################################
1750: ###############################################################
1751: sub create_text_file {
1752: my ($r,$suffix) = @_;
1753: if (! defined($suffix)) { $suffix = 'txt'; };
1754: my $fh;
1755: my $filename = '/prtspool/'.
1.258 albertel 1756: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1757: time.'_'.rand(1000000000).'.'.$suffix;
1758: $fh = Apache::File->new('>/home/httpd'.$filename);
1759: if (! defined($fh)) {
1760: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1761: $r->print(
1762: '<p class="LC_error">'
1763: .&mt('Problems occurred in creating the output file.')
1764: .' '.&mt('This error has been logged.')
1765: .' '.&mt('Please alert your LON-CAPA administrator.')
1766: .'</p>'
1767: );
1.113 bowersj2 1768: }
1.256 matthew 1769: return ($fh,$filename)
1.113 bowersj2 1770: }
1771:
1772:
1.256 matthew 1773: =pod
1.113 bowersj2 1774:
1775: =back
1776:
1777: =cut
1.37 matthew 1778:
1779: ###############################################################
1.33 matthew 1780: ## Home server <option> list generating code ##
1781: ###############################################################
1.35 matthew 1782:
1.169 www 1783: # ------------------------------------------
1784:
1785: sub domain_select {
1786: my ($name,$value,$multiple)=@_;
1787: my %domains=map {
1.514 albertel 1788: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1789: } &Apache::lonnet::all_domains();
1.169 www 1790: if ($multiple) {
1791: $domains{''}=&mt('Any domain');
1.550 albertel 1792: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1793: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1794: } else {
1.550 albertel 1795: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1796: return &select_form($name,$value,\%domains);
1.169 www 1797: }
1798: }
1799:
1.282 albertel 1800: #-------------------------------------------
1801:
1802: =pod
1803:
1.519 raeburn 1804: =head1 Routines for form select boxes
1805:
1806: =over 4
1807:
1.648 raeburn 1808: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1809:
1810: Returns a string containing a <select> element int multiple mode
1811:
1812:
1813: Args:
1814: $name - name of the <select> element
1.506 raeburn 1815: $value - scalar or array ref of values that should already be selected
1.282 albertel 1816: $size - number of rows long the select element is
1.283 albertel 1817: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1818: (shown text should already have been &mt())
1.506 raeburn 1819: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1820:
1.282 albertel 1821: =cut
1822:
1823: #-------------------------------------------
1.169 www 1824: sub multiple_select_form {
1.284 albertel 1825: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1826: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1827: my $output='';
1.191 matthew 1828: if (! defined($size)) {
1829: $size = 4;
1.283 albertel 1830: if (scalar(keys(%$hash))<4) {
1831: $size = scalar(keys(%$hash));
1.191 matthew 1832: }
1833: }
1.734 bisitz 1834: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1835: my @order;
1.506 raeburn 1836: if (ref($order) eq 'ARRAY') {
1837: @order = @{$order};
1838: } else {
1839: @order = sort(keys(%$hash));
1.501 banghart 1840: }
1841: if (exists($$hash{'select_form_order'})) {
1842: @order = @{$$hash{'select_form_order'}};
1843: }
1844:
1.284 albertel 1845: foreach my $key (@order) {
1.356 albertel 1846: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1847: $output.='selected="selected" ' if ($selected{$key});
1848: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1849: }
1850: $output.="</select>\n";
1851: return $output;
1852: }
1853:
1.88 www 1854: #-------------------------------------------
1855:
1856: =pod
1857:
1.970 raeburn 1858: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 1859:
1860: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 1861: allow a user to select options from a ref to a hash containing:
1862: option_name => displayed text. An optional $onchange can include
1863: a javascript onchange item, e.g., onchange="this.form.submit();"
1864:
1.88 www 1865: See lonrights.pm for an example invocation and use.
1866:
1867: =cut
1868:
1869: #-------------------------------------------
1870: sub select_form {
1.970 raeburn 1871: my ($def,$name,$hashref,$onchange) = @_;
1872: return unless (ref($hashref) eq 'HASH');
1873: if ($onchange) {
1874: $onchange = ' onchange="'.$onchange.'"';
1875: }
1876: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 1877: my @keys;
1.970 raeburn 1878: if (exists($hashref->{'select_form_order'})) {
1879: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 1880: } else {
1.970 raeburn 1881: @keys=sort(keys(%{$hashref}));
1.128 albertel 1882: }
1.356 albertel 1883: foreach my $key (@keys) {
1884: $selectform.=
1885: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1886: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 1887: ">".$hashref->{$key}."</option>\n";
1.88 www 1888: }
1889: $selectform.="</select>";
1890: return $selectform;
1891: }
1892:
1.475 www 1893: # For display filters
1894:
1895: sub display_filter {
1896: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1897: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1898: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1899: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1900: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1901: '</label></span> <span class="LC_nobreak">'.
1.475 www 1902: &mt('Filter [_1]',
1.477 www 1903: &select_form($env{'form.displayfilter'},
1904: 'displayfilter',
1.970 raeburn 1905: {'currentfolder' => 'Current folder/page',
1.477 www 1906: 'containing' => 'Containing phrase',
1.970 raeburn 1907: 'none' => 'None'})).
1.714 bisitz 1908: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1909: }
1910:
1.167 www 1911: sub gradeleveldescription {
1912: my $gradelevel=shift;
1913: my %gradelevels=(0 => 'Not specified',
1914: 1 => 'Grade 1',
1915: 2 => 'Grade 2',
1916: 3 => 'Grade 3',
1917: 4 => 'Grade 4',
1918: 5 => 'Grade 5',
1919: 6 => 'Grade 6',
1920: 7 => 'Grade 7',
1921: 8 => 'Grade 8',
1922: 9 => 'Grade 9',
1923: 10 => 'Grade 10',
1924: 11 => 'Grade 11',
1925: 12 => 'Grade 12',
1926: 13 => 'Grade 13',
1927: 14 => '100 Level',
1928: 15 => '200 Level',
1929: 16 => '300 Level',
1930: 17 => '400 Level',
1931: 18 => 'Graduate Level');
1932: return &mt($gradelevels{$gradelevel});
1933: }
1934:
1.163 www 1935: sub select_level_form {
1936: my ($deflevel,$name)=@_;
1937: unless ($deflevel) { $deflevel=0; }
1.167 www 1938: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1939: for (my $i=0; $i<=18; $i++) {
1940: $selectform.="<option value=\"$i\" ".
1.253 albertel 1941: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1942: ">".&gradeleveldescription($i)."</option>\n";
1943: }
1944: $selectform.="</select>";
1945: return $selectform;
1.163 www 1946: }
1.167 www 1947:
1.35 matthew 1948: #-------------------------------------------
1949:
1.45 matthew 1950: =pod
1951:
1.910 raeburn 1952: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 1953:
1954: Returns a string containing a <select name='$name' size='1'> form to
1955: allow a user to select the domain to preform an operation in.
1956: See loncreateuser.pm for an example invocation and use.
1957:
1.90 www 1958: If the $includeempty flag is set, it also includes an empty choice ("no domain
1959: selected");
1960:
1.743 raeburn 1961: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1962:
1.910 raeburn 1963: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
1964:
1965: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 1966:
1.35 matthew 1967: =cut
1968:
1969: #-------------------------------------------
1.34 matthew 1970: sub select_dom_form {
1.910 raeburn 1971: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 1972: if ($onchange) {
1.874 raeburn 1973: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 1974: }
1.910 raeburn 1975: my @domains;
1976: if (ref($incdoms) eq 'ARRAY') {
1977: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
1978: } else {
1979: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1980: }
1.90 www 1981: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1982: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1983: foreach my $dom (@domains) {
1984: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1985: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1986: if ($showdomdesc) {
1987: if ($dom ne '') {
1988: my $domdesc = &Apache::lonnet::domain($dom,'description');
1989: if ($domdesc ne '') {
1990: $selectdomain .= ' ('.$domdesc.')';
1991: }
1992: }
1993: }
1994: $selectdomain .= "</option>\n";
1.34 matthew 1995: }
1996: $selectdomain.="</select>";
1997: return $selectdomain;
1998: }
1999:
1.35 matthew 2000: #-------------------------------------------
2001:
1.45 matthew 2002: =pod
2003:
1.648 raeburn 2004: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2005:
1.586 raeburn 2006: input: 4 arguments (two required, two optional) -
2007: $domain - domain of new user
2008: $name - name of form element
2009: $default - Value of 'default' causes a default item to be first
2010: option, and selected by default.
2011: $hide - Value of 'hide' causes hiding of the name of the server,
2012: if 1 server found, or default, if 0 found.
1.594 raeburn 2013: output: returns 2 items:
1.586 raeburn 2014: (a) form element which contains either:
2015: (i) <select name="$name">
2016: <option value="$hostid1">$hostid $servers{$hostid}</option>
2017: <option value="$hostid2">$hostid $servers{$hostid}</option>
2018: </select>
2019: form item if there are multiple library servers in $domain, or
2020: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2021: if there is only one library server in $domain.
2022:
2023: (b) number of library servers found.
2024:
2025: See loncreateuser.pm for example of use.
1.35 matthew 2026:
2027: =cut
2028:
2029: #-------------------------------------------
1.586 raeburn 2030: sub home_server_form_item {
2031: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2032: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2033: my $result;
2034: my $numlib = keys(%servers);
2035: if ($numlib > 1) {
2036: $result .= '<select name="'.$name.'" />'."\n";
2037: if ($default) {
1.804 bisitz 2038: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2039: '</option>'."\n";
2040: }
2041: foreach my $hostid (sort(keys(%servers))) {
2042: $result.= '<option value="'.$hostid.'">'.
2043: $hostid.' '.$servers{$hostid}."</option>\n";
2044: }
2045: $result .= '</select>'."\n";
2046: } elsif ($numlib == 1) {
2047: my $hostid;
2048: foreach my $item (keys(%servers)) {
2049: $hostid = $item;
2050: }
2051: $result .= '<input type="hidden" name="'.$name.'" value="'.
2052: $hostid.'" />';
2053: if (!$hide) {
2054: $result .= $hostid.' '.$servers{$hostid};
2055: }
2056: $result .= "\n";
2057: } elsif ($default) {
2058: $result .= '<input type="hidden" name="'.$name.
2059: '" value="default" />';
2060: if (!$hide) {
2061: $result .= &mt('default');
2062: }
2063: $result .= "\n";
1.33 matthew 2064: }
1.586 raeburn 2065: return ($result,$numlib);
1.33 matthew 2066: }
1.112 bowersj2 2067:
2068: =pod
2069:
1.534 albertel 2070: =back
2071:
1.112 bowersj2 2072: =cut
1.87 matthew 2073:
2074: ###############################################################
1.112 bowersj2 2075: ## Decoding User Agent ##
1.87 matthew 2076: ###############################################################
2077:
2078: =pod
2079:
1.112 bowersj2 2080: =head1 Decoding the User Agent
2081:
2082: =over 4
2083:
2084: =item * &decode_user_agent()
1.87 matthew 2085:
2086: Inputs: $r
2087:
2088: Outputs:
2089:
2090: =over 4
2091:
1.112 bowersj2 2092: =item * $httpbrowser
1.87 matthew 2093:
1.112 bowersj2 2094: =item * $clientbrowser
1.87 matthew 2095:
1.112 bowersj2 2096: =item * $clientversion
1.87 matthew 2097:
1.112 bowersj2 2098: =item * $clientmathml
1.87 matthew 2099:
1.112 bowersj2 2100: =item * $clientunicode
1.87 matthew 2101:
1.112 bowersj2 2102: =item * $clientos
1.87 matthew 2103:
2104: =back
2105:
1.157 matthew 2106: =back
2107:
1.87 matthew 2108: =cut
2109:
2110: ###############################################################
2111: ###############################################################
2112: sub decode_user_agent {
1.247 albertel 2113: my ($r)=@_;
1.87 matthew 2114: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2115: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2116: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2117: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2118: my $clientbrowser='unknown';
2119: my $clientversion='0';
2120: my $clientmathml='';
2121: my $clientunicode='0';
2122: for (my $i=0;$i<=$#browsertype;$i++) {
2123: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2124: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2125: $clientbrowser=$bname;
2126: $httpbrowser=~/$vreg/i;
2127: $clientversion=$1;
2128: $clientmathml=($clientversion>=$minv);
2129: $clientunicode=($clientversion>=$univ);
2130: }
2131: }
2132: my $clientos='unknown';
2133: if (($httpbrowser=~/linux/i) ||
2134: ($httpbrowser=~/unix/i) ||
2135: ($httpbrowser=~/ux/i) ||
2136: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2137: if (($httpbrowser=~/vax/i) ||
2138: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2139: if ($httpbrowser=~/next/i) { $clientos='next'; }
2140: if (($httpbrowser=~/mac/i) ||
2141: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2142: if ($httpbrowser=~/win/i) { $clientos='win'; }
2143: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2144: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2145: $clientunicode,$clientos,);
2146: }
2147:
1.32 matthew 2148: ###############################################################
2149: ## Authentication changing form generation subroutines ##
2150: ###############################################################
2151: ##
2152: ## All of the authform_xxxxxxx subroutines take their inputs in a
2153: ## hash, and have reasonable default values.
2154: ##
2155: ## formname = the name given in the <form> tag.
1.35 matthew 2156: #-------------------------------------------
2157:
1.45 matthew 2158: =pod
2159:
1.112 bowersj2 2160: =head1 Authentication Routines
2161:
2162: =over 4
2163:
1.648 raeburn 2164: =item * &authform_xxxxxx()
1.35 matthew 2165:
2166: The authform_xxxxxx subroutines provide javascript and html forms which
2167: handle some of the conveniences required for authentication forms.
2168: This is not an optimal method, but it works.
2169:
2170: =over 4
2171:
1.112 bowersj2 2172: =item * authform_header
1.35 matthew 2173:
1.112 bowersj2 2174: =item * authform_authorwarning
1.35 matthew 2175:
1.112 bowersj2 2176: =item * authform_nochange
1.35 matthew 2177:
1.112 bowersj2 2178: =item * authform_kerberos
1.35 matthew 2179:
1.112 bowersj2 2180: =item * authform_internal
1.35 matthew 2181:
1.112 bowersj2 2182: =item * authform_filesystem
1.35 matthew 2183:
2184: =back
2185:
1.648 raeburn 2186: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2187:
1.35 matthew 2188: =cut
2189:
2190: #-------------------------------------------
1.32 matthew 2191: sub authform_header{
2192: my %in = (
2193: formname => 'cu',
1.80 albertel 2194: kerb_def_dom => '',
1.32 matthew 2195: @_,
2196: );
2197: $in{'formname'} = 'document.' . $in{'formname'};
2198: my $result='';
1.80 albertel 2199:
2200: #---------------------------------------------- Code for upper case translation
2201: my $Javascript_toUpperCase;
2202: unless ($in{kerb_def_dom}) {
2203: $Javascript_toUpperCase =<<"END";
2204: switch (choice) {
2205: case 'krb': currentform.elements[choicearg].value =
2206: currentform.elements[choicearg].value.toUpperCase();
2207: break;
2208: default:
2209: }
2210: END
2211: } else {
2212: $Javascript_toUpperCase = "";
2213: }
2214:
1.165 raeburn 2215: my $radioval = "'nochange'";
1.591 raeburn 2216: if (defined($in{'curr_authtype'})) {
2217: if ($in{'curr_authtype'} ne '') {
2218: $radioval = "'".$in{'curr_authtype'}."arg'";
2219: }
1.174 matthew 2220: }
1.165 raeburn 2221: my $argfield = 'null';
1.591 raeburn 2222: if (defined($in{'mode'})) {
1.165 raeburn 2223: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2224: if (defined($in{'curr_autharg'})) {
2225: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2226: $argfield = "'$in{'curr_autharg'}'";
2227: }
2228: }
2229: }
2230: }
2231:
1.32 matthew 2232: $result.=<<"END";
2233: var current = new Object();
1.165 raeburn 2234: current.radiovalue = $radioval;
2235: current.argfield = $argfield;
1.32 matthew 2236:
2237: function changed_radio(choice,currentform) {
2238: var choicearg = choice + 'arg';
2239: // If a radio button in changed, we need to change the argfield
2240: if (current.radiovalue != choice) {
2241: current.radiovalue = choice;
2242: if (current.argfield != null) {
2243: currentform.elements[current.argfield].value = '';
2244: }
2245: if (choice == 'nochange') {
2246: current.argfield = null;
2247: } else {
2248: current.argfield = choicearg;
2249: switch(choice) {
2250: case 'krb':
2251: currentform.elements[current.argfield].value =
2252: "$in{'kerb_def_dom'}";
2253: break;
2254: default:
2255: break;
2256: }
2257: }
2258: }
2259: return;
2260: }
1.22 www 2261:
1.32 matthew 2262: function changed_text(choice,currentform) {
2263: var choicearg = choice + 'arg';
2264: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2265: $Javascript_toUpperCase
1.32 matthew 2266: // clear old field
2267: if ((current.argfield != choicearg) && (current.argfield != null)) {
2268: currentform.elements[current.argfield].value = '';
2269: }
2270: current.argfield = choicearg;
2271: }
2272: set_auth_radio_buttons(choice,currentform);
2273: return;
1.20 www 2274: }
1.32 matthew 2275:
2276: function set_auth_radio_buttons(newvalue,currentform) {
2277: var i=0;
2278: while (i < currentform.login.length) {
2279: if (currentform.login[i].value == newvalue) { break; }
2280: i++;
2281: }
2282: if (i == currentform.login.length) {
2283: return;
2284: }
2285: current.radiovalue = newvalue;
2286: currentform.login[i].checked = true;
2287: return;
2288: }
2289: END
2290: return $result;
2291: }
2292:
2293: sub authform_authorwarning{
2294: my $result='';
1.144 matthew 2295: $result='<i>'.
2296: &mt('As a general rule, only authors or co-authors should be '.
2297: 'filesystem authenticated '.
2298: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2299: return $result;
2300: }
2301:
2302: sub authform_nochange{
2303: my %in = (
2304: formname => 'document.cu',
2305: kerb_def_dom => 'MSU.EDU',
2306: @_,
2307: );
1.586 raeburn 2308: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2309: my $result;
2310: if (keys(%can_assign) == 0) {
2311: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2312: } else {
2313: $result = '<label>'.&mt('[_1] Do not change login data',
2314: '<input type="radio" name="login" value="nochange" '.
2315: 'checked="checked" onclick="'.
1.281 albertel 2316: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2317: '</label>';
1.586 raeburn 2318: }
1.32 matthew 2319: return $result;
2320: }
2321:
1.591 raeburn 2322: sub authform_kerberos {
1.32 matthew 2323: my %in = (
2324: formname => 'document.cu',
2325: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2326: kerb_def_auth => 'krb4',
1.32 matthew 2327: @_,
2328: );
1.586 raeburn 2329: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2330: $autharg,$jscall);
2331: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2332: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2333: $check5 = ' checked="checked"';
1.80 albertel 2334: } else {
1.772 bisitz 2335: $check4 = ' checked="checked"';
1.80 albertel 2336: }
1.165 raeburn 2337: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2338: if (defined($in{'curr_authtype'})) {
2339: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2340: $krbcheck = ' checked="checked"';
1.623 raeburn 2341: if (defined($in{'mode'})) {
2342: if ($in{'mode'} eq 'modifyuser') {
2343: $krbcheck = '';
2344: }
2345: }
1.591 raeburn 2346: if (defined($in{'curr_kerb_ver'})) {
2347: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2348: $check5 = ' checked="checked"';
1.591 raeburn 2349: $check4 = '';
2350: } else {
1.772 bisitz 2351: $check4 = ' checked="checked"';
1.591 raeburn 2352: $check5 = '';
2353: }
1.586 raeburn 2354: }
1.591 raeburn 2355: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2356: $krbarg = $in{'curr_autharg'};
2357: }
1.586 raeburn 2358: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2359: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2360: $result =
2361: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2362: $in{'curr_autharg'},$krbver);
2363: } else {
2364: $result =
2365: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2366: }
2367: return $result;
2368: }
2369: }
2370: } else {
2371: if ($authnum == 1) {
1.784 bisitz 2372: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2373: }
2374: }
1.586 raeburn 2375: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2376: return;
1.587 raeburn 2377: } elsif ($authtype eq '') {
1.591 raeburn 2378: if (defined($in{'mode'})) {
1.587 raeburn 2379: if ($in{'mode'} eq 'modifycourse') {
2380: if ($authnum == 1) {
1.784 bisitz 2381: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2382: }
2383: }
2384: }
1.586 raeburn 2385: }
2386: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2387: if ($authtype eq '') {
2388: $authtype = '<input type="radio" name="login" value="krb" '.
2389: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2390: $krbcheck.' />';
2391: }
2392: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2393: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2394: $in{'curr_authtype'} eq 'krb5') ||
2395: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2396: $in{'curr_authtype'} eq 'krb4')) {
2397: $result .= &mt
1.144 matthew 2398: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2399: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2400: '<label>'.$authtype,
1.281 albertel 2401: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2402: 'value="'.$krbarg.'" '.
1.144 matthew 2403: 'onchange="'.$jscall.'" />',
1.281 albertel 2404: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2405: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2406: '</label>');
1.586 raeburn 2407: } elsif ($can_assign{'krb4'}) {
2408: $result .= &mt
2409: ('[_1] Kerberos authenticated with domain [_2] '.
2410: '[_3] Version 4 [_4]',
2411: '<label>'.$authtype,
2412: '</label><input type="text" size="10" name="krbarg" '.
2413: 'value="'.$krbarg.'" '.
2414: 'onchange="'.$jscall.'" />',
2415: '<label><input type="hidden" name="krbver" value="4" />',
2416: '</label>');
2417: } elsif ($can_assign{'krb5'}) {
2418: $result .= &mt
2419: ('[_1] Kerberos authenticated with domain [_2] '.
2420: '[_3] Version 5 [_4]',
2421: '<label>'.$authtype,
2422: '</label><input type="text" size="10" name="krbarg" '.
2423: 'value="'.$krbarg.'" '.
2424: 'onchange="'.$jscall.'" />',
2425: '<label><input type="hidden" name="krbver" value="5" />',
2426: '</label>');
2427: }
1.32 matthew 2428: return $result;
2429: }
2430:
2431: sub authform_internal{
1.586 raeburn 2432: my %in = (
1.32 matthew 2433: formname => 'document.cu',
2434: kerb_def_dom => 'MSU.EDU',
2435: @_,
2436: );
1.586 raeburn 2437: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2438: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2439: if (defined($in{'curr_authtype'})) {
2440: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2441: if ($can_assign{'int'}) {
1.772 bisitz 2442: $intcheck = 'checked="checked" ';
1.623 raeburn 2443: if (defined($in{'mode'})) {
2444: if ($in{'mode'} eq 'modifyuser') {
2445: $intcheck = '';
2446: }
2447: }
1.591 raeburn 2448: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2449: $intarg = $in{'curr_autharg'};
2450: }
2451: } else {
2452: $result = &mt('Currently internally authenticated.');
2453: return $result;
1.165 raeburn 2454: }
2455: }
1.586 raeburn 2456: } else {
2457: if ($authnum == 1) {
1.784 bisitz 2458: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2459: }
2460: }
2461: if (!$can_assign{'int'}) {
2462: return;
1.587 raeburn 2463: } elsif ($authtype eq '') {
1.591 raeburn 2464: if (defined($in{'mode'})) {
1.587 raeburn 2465: if ($in{'mode'} eq 'modifycourse') {
2466: if ($authnum == 1) {
1.784 bisitz 2467: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2468: }
2469: }
2470: }
1.165 raeburn 2471: }
1.586 raeburn 2472: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2473: if ($authtype eq '') {
2474: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2475: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2476: }
1.605 bisitz 2477: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2478: $intarg.'" onchange="'.$jscall.'" />';
2479: $result = &mt
1.144 matthew 2480: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2481: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2482: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2483: return $result;
2484: }
2485:
2486: sub authform_local{
2487: my %in = (
2488: formname => 'document.cu',
2489: kerb_def_dom => 'MSU.EDU',
2490: @_,
2491: );
1.586 raeburn 2492: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2493: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2494: if (defined($in{'curr_authtype'})) {
2495: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2496: if ($can_assign{'loc'}) {
1.772 bisitz 2497: $loccheck = 'checked="checked" ';
1.623 raeburn 2498: if (defined($in{'mode'})) {
2499: if ($in{'mode'} eq 'modifyuser') {
2500: $loccheck = '';
2501: }
2502: }
1.591 raeburn 2503: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2504: $locarg = $in{'curr_autharg'};
2505: }
2506: } else {
2507: $result = &mt('Currently using local (institutional) authentication.');
2508: return $result;
1.165 raeburn 2509: }
2510: }
1.586 raeburn 2511: } else {
2512: if ($authnum == 1) {
1.784 bisitz 2513: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2514: }
2515: }
2516: if (!$can_assign{'loc'}) {
2517: return;
1.587 raeburn 2518: } elsif ($authtype eq '') {
1.591 raeburn 2519: if (defined($in{'mode'})) {
1.587 raeburn 2520: if ($in{'mode'} eq 'modifycourse') {
2521: if ($authnum == 1) {
1.784 bisitz 2522: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2523: }
2524: }
2525: }
1.165 raeburn 2526: }
1.586 raeburn 2527: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2528: if ($authtype eq '') {
2529: $authtype = '<input type="radio" name="login" value="loc" '.
2530: $loccheck.' onchange="'.$jscall.'" onclick="'.
2531: $jscall.'" />';
2532: }
2533: $autharg = '<input type="text" size="10" name="locarg" value="'.
2534: $locarg.'" onchange="'.$jscall.'" />';
2535: $result = &mt('[_1] Local Authentication with argument [_2]',
2536: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2537: return $result;
2538: }
2539:
2540: sub authform_filesystem{
2541: my %in = (
2542: formname => 'document.cu',
2543: kerb_def_dom => 'MSU.EDU',
2544: @_,
2545: );
1.586 raeburn 2546: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2547: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2548: if (defined($in{'curr_authtype'})) {
2549: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2550: if ($can_assign{'fsys'}) {
1.772 bisitz 2551: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2552: if (defined($in{'mode'})) {
2553: if ($in{'mode'} eq 'modifyuser') {
2554: $fsyscheck = '';
2555: }
2556: }
1.586 raeburn 2557: } else {
2558: $result = &mt('Currently Filesystem Authenticated.');
2559: return $result;
2560: }
2561: }
2562: } else {
2563: if ($authnum == 1) {
1.784 bisitz 2564: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2565: }
2566: }
2567: if (!$can_assign{'fsys'}) {
2568: return;
1.587 raeburn 2569: } elsif ($authtype eq '') {
1.591 raeburn 2570: if (defined($in{'mode'})) {
1.587 raeburn 2571: if ($in{'mode'} eq 'modifycourse') {
2572: if ($authnum == 1) {
1.784 bisitz 2573: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2574: }
2575: }
2576: }
1.586 raeburn 2577: }
2578: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2579: if ($authtype eq '') {
2580: $authtype = '<input type="radio" name="login" value="fsys" '.
2581: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2582: $jscall.'" />';
2583: }
2584: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2585: ' onchange="'.$jscall.'" />';
2586: $result = &mt
1.144 matthew 2587: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2588: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2589: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2590: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2591: 'onchange="'.$jscall.'" />');
1.32 matthew 2592: return $result;
2593: }
2594:
1.586 raeburn 2595: sub get_assignable_auth {
2596: my ($dom) = @_;
2597: if ($dom eq '') {
2598: $dom = $env{'request.role.domain'};
2599: }
2600: my %can_assign = (
2601: krb4 => 1,
2602: krb5 => 1,
2603: int => 1,
2604: loc => 1,
2605: );
2606: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2607: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2608: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2609: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2610: my $context;
2611: if ($env{'request.role'} =~ /^au/) {
2612: $context = 'author';
2613: } elsif ($env{'request.role'} =~ /^dc/) {
2614: $context = 'domain';
2615: } elsif ($env{'request.course.id'}) {
2616: $context = 'course';
2617: }
2618: if ($context) {
2619: if (ref($authhash->{$context}) eq 'HASH') {
2620: %can_assign = %{$authhash->{$context}};
2621: }
2622: }
2623: }
2624: }
2625: my $authnum = 0;
2626: foreach my $key (keys(%can_assign)) {
2627: if ($can_assign{$key}) {
2628: $authnum ++;
2629: }
2630: }
2631: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2632: $authnum --;
2633: }
2634: return ($authnum,%can_assign);
2635: }
2636:
1.80 albertel 2637: ###############################################################
2638: ## Get Kerberos Defaults for Domain ##
2639: ###############################################################
2640: ##
2641: ## Returns default kerberos version and an associated argument
2642: ## as listed in file domain.tab. If not listed, provides
2643: ## appropriate default domain and kerberos version.
2644: ##
2645: #-------------------------------------------
2646:
2647: =pod
2648:
1.648 raeburn 2649: =item * &get_kerberos_defaults()
1.80 albertel 2650:
2651: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2652: version and domain. If not found, it defaults to version 4 and the
2653: domain of the server.
1.80 albertel 2654:
1.648 raeburn 2655: =over 4
2656:
1.80 albertel 2657: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2658:
1.648 raeburn 2659: =back
2660:
2661: =back
2662:
1.80 albertel 2663: =cut
2664:
2665: #-------------------------------------------
2666: sub get_kerberos_defaults {
2667: my $domain=shift;
1.641 raeburn 2668: my ($krbdef,$krbdefdom);
2669: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2670: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2671: $krbdef = $domdefaults{'auth_def'};
2672: $krbdefdom = $domdefaults{'auth_arg_def'};
2673: } else {
1.80 albertel 2674: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2675: my $krbdefdom=$1;
2676: $krbdefdom=~tr/a-z/A-Z/;
2677: $krbdef = "krb4";
2678: }
2679: return ($krbdef,$krbdefdom);
2680: }
1.112 bowersj2 2681:
1.32 matthew 2682:
1.46 matthew 2683: ###############################################################
2684: ## Thesaurus Functions ##
2685: ###############################################################
1.20 www 2686:
1.46 matthew 2687: =pod
1.20 www 2688:
1.112 bowersj2 2689: =head1 Thesaurus Functions
2690:
2691: =over 4
2692:
1.648 raeburn 2693: =item * &initialize_keywords()
1.46 matthew 2694:
2695: Initializes the package variable %Keywords if it is empty. Uses the
2696: package variable $thesaurus_db_file.
2697:
2698: =cut
2699:
2700: ###################################################
2701:
2702: sub initialize_keywords {
2703: return 1 if (scalar keys(%Keywords));
2704: # If we are here, %Keywords is empty, so fill it up
2705: # Make sure the file we need exists...
2706: if (! -e $thesaurus_db_file) {
2707: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2708: " failed because it does not exist");
2709: return 0;
2710: }
2711: # Set up the hash as a database
2712: my %thesaurus_db;
2713: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2714: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2715: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2716: $thesaurus_db_file);
2717: return 0;
2718: }
2719: # Get the average number of appearances of a word.
2720: my $avecount = $thesaurus_db{'average.count'};
2721: # Put keywords (those that appear > average) into %Keywords
2722: while (my ($word,$data)=each (%thesaurus_db)) {
2723: my ($count,undef) = split /:/,$data;
2724: $Keywords{$word}++ if ($count > $avecount);
2725: }
2726: untie %thesaurus_db;
2727: # Remove special values from %Keywords.
1.356 albertel 2728: foreach my $value ('total.count','average.count') {
2729: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2730: }
1.46 matthew 2731: return 1;
2732: }
2733:
2734: ###################################################
2735:
2736: =pod
2737:
1.648 raeburn 2738: =item * &keyword($word)
1.46 matthew 2739:
2740: Returns true if $word is a keyword. A keyword is a word that appears more
2741: than the average number of times in the thesaurus database. Calls
2742: &initialize_keywords
2743:
2744: =cut
2745:
2746: ###################################################
1.20 www 2747:
2748: sub keyword {
1.46 matthew 2749: return if (!&initialize_keywords());
2750: my $word=lc(shift());
2751: $word=~s/\W//g;
2752: return exists($Keywords{$word});
1.20 www 2753: }
1.46 matthew 2754:
2755: ###############################################################
2756:
2757: =pod
1.20 www 2758:
1.648 raeburn 2759: =item * &get_related_words()
1.46 matthew 2760:
1.160 matthew 2761: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2762: an array of words. If the keyword is not in the thesaurus, an empty array
2763: will be returned. The order of the words returned is determined by the
2764: database which holds them.
2765:
2766: Uses global $thesaurus_db_file.
2767:
2768: =cut
2769:
2770: ###############################################################
2771: sub get_related_words {
2772: my $keyword = shift;
2773: my %thesaurus_db;
2774: if (! -e $thesaurus_db_file) {
2775: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2776: "failed because the file does not exist");
2777: return ();
2778: }
2779: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2780: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2781: return ();
2782: }
2783: my @Words=();
1.429 www 2784: my $count=0;
1.46 matthew 2785: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2786: # The first element is the number of times
2787: # the word appears. We do not need it now.
1.429 www 2788: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2789: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2790: my $threshold=$mostfrequentcount/10;
2791: foreach my $possibleword (@RelatedWords) {
2792: my ($word,$wordcount)=split(/\,/,$possibleword);
2793: if ($wordcount>$threshold) {
2794: push(@Words,$word);
2795: $count++;
2796: if ($count>10) { last; }
2797: }
1.20 www 2798: }
2799: }
1.46 matthew 2800: untie %thesaurus_db;
2801: return @Words;
1.14 harris41 2802: }
1.46 matthew 2803:
1.112 bowersj2 2804: =pod
2805:
2806: =back
2807:
2808: =cut
1.61 www 2809:
2810: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2811: =pod
2812:
1.112 bowersj2 2813: =head1 User Name Functions
2814:
2815: =over 4
2816:
1.648 raeburn 2817: =item * &plainname($uname,$udom,$first)
1.81 albertel 2818:
1.112 bowersj2 2819: Takes a users logon name and returns it as a string in
1.226 albertel 2820: "first middle last generation" form
2821: if $first is set to 'lastname' then it returns it as
2822: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2823:
2824: =cut
1.61 www 2825:
1.295 www 2826:
1.81 albertel 2827: ###############################################################
1.61 www 2828: sub plainname {
1.226 albertel 2829: my ($uname,$udom,$first)=@_;
1.537 albertel 2830: return if (!defined($uname) || !defined($udom));
1.295 www 2831: my %names=&getnames($uname,$udom);
1.226 albertel 2832: my $name=&Apache::lonnet::format_name($names{'firstname'},
2833: $names{'middlename'},
2834: $names{'lastname'},
2835: $names{'generation'},$first);
2836: $name=~s/^\s+//;
1.62 www 2837: $name=~s/\s+$//;
2838: $name=~s/\s+/ /g;
1.353 albertel 2839: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2840: return $name;
1.61 www 2841: }
1.66 www 2842:
2843: # -------------------------------------------------------------------- Nickname
1.81 albertel 2844: =pod
2845:
1.648 raeburn 2846: =item * &nickname($uname,$udom)
1.81 albertel 2847:
2848: Gets a users name and returns it as a string as
2849:
2850: ""nickname""
1.66 www 2851:
1.81 albertel 2852: if the user has a nickname or
2853:
2854: "first middle last generation"
2855:
2856: if the user does not
2857:
2858: =cut
1.66 www 2859:
2860: sub nickname {
2861: my ($uname,$udom)=@_;
1.537 albertel 2862: return if (!defined($uname) || !defined($udom));
1.295 www 2863: my %names=&getnames($uname,$udom);
1.68 albertel 2864: my $name=$names{'nickname'};
1.66 www 2865: if ($name) {
2866: $name='"'.$name.'"';
2867: } else {
2868: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2869: $names{'lastname'}.' '.$names{'generation'};
2870: $name=~s/\s+$//;
2871: $name=~s/\s+/ /g;
2872: }
2873: return $name;
2874: }
2875:
1.295 www 2876: sub getnames {
2877: my ($uname,$udom)=@_;
1.537 albertel 2878: return if (!defined($uname) || !defined($udom));
1.433 albertel 2879: if ($udom eq 'public' && $uname eq 'public') {
2880: return ('lastname' => &mt('Public'));
2881: }
1.295 www 2882: my $id=$uname.':'.$udom;
2883: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2884: if ($cached) {
2885: return %{$names};
2886: } else {
2887: my %loadnames=&Apache::lonnet::get('environment',
2888: ['firstname','middlename','lastname','generation','nickname'],
2889: $udom,$uname);
2890: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2891: return %loadnames;
2892: }
2893: }
1.61 www 2894:
1.542 raeburn 2895: # -------------------------------------------------------------------- getemails
1.648 raeburn 2896:
1.542 raeburn 2897: =pod
2898:
1.648 raeburn 2899: =item * &getemails($uname,$udom)
1.542 raeburn 2900:
2901: Gets a user's email information and returns it as a hash with keys:
2902: notification, critnotification, permanentemail
2903:
2904: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2905: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2906:
1.648 raeburn 2907:
1.542 raeburn 2908: =cut
2909:
1.648 raeburn 2910:
1.466 albertel 2911: sub getemails {
2912: my ($uname,$udom)=@_;
2913: if ($udom eq 'public' && $uname eq 'public') {
2914: return;
2915: }
1.467 www 2916: if (!$udom) { $udom=$env{'user.domain'}; }
2917: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2918: my $id=$uname.':'.$udom;
2919: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2920: if ($cached) {
2921: return %{$names};
2922: } else {
2923: my %loadnames=&Apache::lonnet::get('environment',
2924: ['notification','critnotification',
2925: 'permanentemail'],
2926: $udom,$uname);
2927: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2928: return %loadnames;
2929: }
2930: }
2931:
1.551 albertel 2932: sub flush_email_cache {
2933: my ($uname,$udom)=@_;
2934: if (!$udom) { $udom =$env{'user.domain'}; }
2935: if (!$uname) { $uname=$env{'user.name'}; }
2936: return if ($udom eq 'public' && $uname eq 'public');
2937: my $id=$uname.':'.$udom;
2938: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2939: }
2940:
1.728 raeburn 2941: # -------------------------------------------------------------------- getlangs
2942:
2943: =pod
2944:
2945: =item * &getlangs($uname,$udom)
2946:
2947: Gets a user's language preference and returns it as a hash with key:
2948: language.
2949:
2950: =cut
2951:
2952:
2953: sub getlangs {
2954: my ($uname,$udom) = @_;
2955: if (!$udom) { $udom =$env{'user.domain'}; }
2956: if (!$uname) { $uname=$env{'user.name'}; }
2957: my $id=$uname.':'.$udom;
2958: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2959: if ($cached) {
2960: return %{$langs};
2961: } else {
2962: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2963: $udom,$uname);
2964: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2965: return %loadlangs;
2966: }
2967: }
2968:
2969: sub flush_langs_cache {
2970: my ($uname,$udom)=@_;
2971: if (!$udom) { $udom =$env{'user.domain'}; }
2972: if (!$uname) { $uname=$env{'user.name'}; }
2973: return if ($udom eq 'public' && $uname eq 'public');
2974: my $id=$uname.':'.$udom;
2975: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2976: }
2977:
1.61 www 2978: # ------------------------------------------------------------------ Screenname
1.81 albertel 2979:
2980: =pod
2981:
1.648 raeburn 2982: =item * &screenname($uname,$udom)
1.81 albertel 2983:
2984: Gets a users screenname and returns it as a string
2985:
2986: =cut
1.61 www 2987:
2988: sub screenname {
2989: my ($uname,$udom)=@_;
1.258 albertel 2990: if ($uname eq $env{'user.name'} &&
2991: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2992: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2993: return $names{'screenname'};
1.62 www 2994: }
2995:
1.212 albertel 2996:
1.802 bisitz 2997: # ------------------------------------------------------------- Confirm Wrapper
2998: =pod
2999:
3000: =item confirmwrapper
3001:
3002: Wrap messages about completion of operation in box
3003:
3004: =cut
3005:
3006: sub confirmwrapper {
3007: my ($message)=@_;
3008: if ($message) {
3009: return "\n".'<div class="LC_confirm_box">'."\n"
3010: .$message."\n"
3011: .'</div>'."\n";
3012: } else {
3013: return $message;
3014: }
3015: }
3016:
1.62 www 3017: # ------------------------------------------------------------- Message Wrapper
3018:
3019: sub messagewrapper {
1.369 www 3020: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3021: return
1.441 albertel 3022: '<a href="/adm/email?compose=individual&'.
3023: 'recname='.$username.'&recdom='.$domain.
3024: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3025: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3026: }
1.802 bisitz 3027:
1.74 www 3028: # --------------------------------------------------------------- Notes Wrapper
3029:
3030: sub noteswrapper {
3031: my ($link,$un,$do)=@_;
3032: return
1.896 amueller 3033: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3034: }
1.802 bisitz 3035:
1.62 www 3036: # ------------------------------------------------------------- Aboutme Wrapper
3037:
3038: sub aboutmewrapper {
1.166 www 3039: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3040: if (!defined($username) && !defined($domain)) {
3041: return;
3042: }
1.892 amueller 3043: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756 weissno 3044: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3045: }
3046:
3047: # ------------------------------------------------------------ Syllabus Wrapper
3048:
3049: sub syllabuswrapper {
1.707 bisitz 3050: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3051: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3052: }
1.14 harris41 3053:
1.802 bisitz 3054: # -----------------------------------------------------------------------------
3055:
1.208 matthew 3056: sub track_student_link {
1.887 raeburn 3057: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3058: my $link ="/adm/trackstudent?";
1.208 matthew 3059: my $title = 'View recent activity';
3060: if (defined($sname) && $sname !~ /^\s*$/ &&
3061: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3062: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3063: $title .= ' of this student';
1.268 albertel 3064: }
1.208 matthew 3065: if (defined($target) && $target !~ /^\s*$/) {
3066: $target = qq{target="$target"};
3067: } else {
3068: $target = '';
3069: }
1.268 albertel 3070: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3071: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3072: $title = &mt($title);
3073: $linktext = &mt($linktext);
1.448 albertel 3074: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3075: &help_open_topic('View_recent_activity');
1.208 matthew 3076: }
3077:
1.781 raeburn 3078: sub slot_reservations_link {
3079: my ($linktext,$sname,$sdom,$target) = @_;
3080: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3081: my $title = 'View slot reservation history';
3082: if (defined($sname) && $sname !~ /^\s*$/ &&
3083: defined($sdom) && $sdom !~ /^\s*$/) {
3084: $link .= "&uname=$sname&udom=$sdom";
3085: $title .= ' of this student';
3086: }
3087: if (defined($target) && $target !~ /^\s*$/) {
3088: $target = qq{target="$target"};
3089: } else {
3090: $target = '';
3091: }
3092: $title = &mt($title);
3093: $linktext = &mt($linktext);
3094: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3095: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3096:
3097: }
3098:
1.508 www 3099: # ===================================================== Display a student photo
3100:
3101:
1.509 albertel 3102: sub student_image_tag {
1.508 www 3103: my ($domain,$user)=@_;
3104: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3105: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3106: return '<img src="'.$imgsrc.'" align="right" />';
3107: } else {
3108: return '';
3109: }
3110: }
3111:
1.112 bowersj2 3112: =pod
3113:
3114: =back
3115:
3116: =head1 Access .tab File Data
3117:
3118: =over 4
3119:
1.648 raeburn 3120: =item * &languageids()
1.112 bowersj2 3121:
3122: returns list of all language ids
3123:
3124: =cut
3125:
1.14 harris41 3126: sub languageids {
1.16 harris41 3127: return sort(keys(%language));
1.14 harris41 3128: }
3129:
1.112 bowersj2 3130: =pod
3131:
1.648 raeburn 3132: =item * &languagedescription()
1.112 bowersj2 3133:
3134: returns description of a specified language id
3135:
3136: =cut
3137:
1.14 harris41 3138: sub languagedescription {
1.125 www 3139: my $code=shift;
3140: return ($supported_language{$code}?'* ':'').
3141: $language{$code}.
1.126 www 3142: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3143: }
3144:
3145: sub plainlanguagedescription {
3146: my $code=shift;
3147: return $language{$code};
3148: }
3149:
3150: sub supportedlanguagecode {
3151: my $code=shift;
3152: return $supported_language{$code};
1.97 www 3153: }
3154:
1.112 bowersj2 3155: =pod
3156:
1.648 raeburn 3157: =item * ©rightids()
1.112 bowersj2 3158:
3159: returns list of all copyrights
3160:
3161: =cut
3162:
3163: sub copyrightids {
3164: return sort(keys(%cprtag));
3165: }
3166:
3167: =pod
3168:
1.648 raeburn 3169: =item * ©rightdescription()
1.112 bowersj2 3170:
3171: returns description of a specified copyright id
3172:
3173: =cut
3174:
3175: sub copyrightdescription {
1.166 www 3176: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3177: }
1.197 matthew 3178:
3179: =pod
3180:
1.648 raeburn 3181: =item * &source_copyrightids()
1.192 taceyjo1 3182:
3183: returns list of all source copyrights
3184:
3185: =cut
3186:
3187: sub source_copyrightids {
3188: return sort(keys(%scprtag));
3189: }
3190:
3191: =pod
3192:
1.648 raeburn 3193: =item * &source_copyrightdescription()
1.192 taceyjo1 3194:
3195: returns description of a specified source copyright id
3196:
3197: =cut
3198:
3199: sub source_copyrightdescription {
3200: return &mt($scprtag{shift(@_)});
3201: }
1.112 bowersj2 3202:
3203: =pod
3204:
1.648 raeburn 3205: =item * &filecategories()
1.112 bowersj2 3206:
3207: returns list of all file categories
3208:
3209: =cut
3210:
3211: sub filecategories {
3212: return sort(keys(%category_extensions));
3213: }
3214:
3215: =pod
3216:
1.648 raeburn 3217: =item * &filecategorytypes()
1.112 bowersj2 3218:
3219: returns list of file types belonging to a given file
3220: category
3221:
3222: =cut
3223:
3224: sub filecategorytypes {
1.356 albertel 3225: my ($cat) = @_;
3226: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3227: }
3228:
3229: =pod
3230:
1.648 raeburn 3231: =item * &fileembstyle()
1.112 bowersj2 3232:
3233: returns embedding style for a specified file type
3234:
3235: =cut
3236:
3237: sub fileembstyle {
3238: return $fe{lc(shift(@_))};
1.169 www 3239: }
3240:
1.351 www 3241: sub filemimetype {
3242: return $fm{lc(shift(@_))};
3243: }
3244:
1.169 www 3245:
3246: sub filecategoryselect {
3247: my ($name,$value)=@_;
1.189 matthew 3248: return &select_form($value,$name,
1.970 raeburn 3249: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3250: }
3251:
3252: =pod
3253:
1.648 raeburn 3254: =item * &filedescription()
1.112 bowersj2 3255:
3256: returns description for a specified file type
3257:
3258: =cut
3259:
3260: sub filedescription {
1.188 matthew 3261: my $file_description = $fd{lc(shift())};
3262: $file_description =~ s:([\[\]]):~$1:g;
3263: return &mt($file_description);
1.112 bowersj2 3264: }
3265:
3266: =pod
3267:
1.648 raeburn 3268: =item * &filedescriptionex()
1.112 bowersj2 3269:
3270: returns description for a specified file type with
3271: extra formatting
3272:
3273: =cut
3274:
3275: sub filedescriptionex {
3276: my $ex=shift;
1.188 matthew 3277: my $file_description = $fd{lc($ex)};
3278: $file_description =~ s:([\[\]]):~$1:g;
3279: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3280: }
3281:
3282: # End of .tab access
3283: =pod
3284:
3285: =back
3286:
3287: =cut
3288:
3289: # ------------------------------------------------------------------ File Types
3290: sub fileextensions {
3291: return sort(keys(%fe));
3292: }
3293:
1.97 www 3294: # ----------------------------------------------------------- Display Languages
3295: # returns a hash with all desired display languages
3296: #
3297:
3298: sub display_languages {
3299: my %languages=();
1.695 raeburn 3300: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3301: $languages{$lang}=1;
1.97 www 3302: }
3303: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3304: if ($env{'form.displaylanguage'}) {
1.356 albertel 3305: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3306: $languages{$lang}=1;
1.97 www 3307: }
3308: }
3309: return %languages;
1.14 harris41 3310: }
3311:
1.582 albertel 3312: sub languages {
3313: my ($possible_langs) = @_;
1.695 raeburn 3314: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3315: if (!ref($possible_langs)) {
3316: if( wantarray ) {
3317: return @preferred_langs;
3318: } else {
3319: return $preferred_langs[0];
3320: }
3321: }
3322: my %possibilities = map { $_ => 1 } (@$possible_langs);
3323: my @preferred_possibilities;
3324: foreach my $preferred_lang (@preferred_langs) {
3325: if (exists($possibilities{$preferred_lang})) {
3326: push(@preferred_possibilities, $preferred_lang);
3327: }
3328: }
3329: if( wantarray ) {
3330: return @preferred_possibilities;
3331: }
3332: return $preferred_possibilities[0];
3333: }
3334:
1.742 raeburn 3335: sub user_lang {
3336: my ($touname,$toudom,$fromcid) = @_;
3337: my @userlangs;
3338: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3339: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3340: $env{'course.'.$fromcid.'.languages'}));
3341: } else {
3342: my %langhash = &getlangs($touname,$toudom);
3343: if ($langhash{'languages'} ne '') {
3344: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3345: } else {
3346: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3347: if ($domdefs{'lang_def'} ne '') {
3348: @userlangs = ($domdefs{'lang_def'});
3349: }
3350: }
3351: }
3352: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3353: my $user_lh = Apache::localize->get_handle(@languages);
3354: return $user_lh;
3355: }
3356:
3357:
1.112 bowersj2 3358: ###############################################################
3359: ## Student Answer Attempts ##
3360: ###############################################################
3361:
3362: =pod
3363:
3364: =head1 Alternate Problem Views
3365:
3366: =over 4
3367:
1.648 raeburn 3368: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3369: $getattempt, $regexp, $gradesub)
3370:
3371: Return string with previous attempt on problem. Arguments:
3372:
3373: =over 4
3374:
3375: =item * $symb: Problem, including path
3376:
3377: =item * $username: username of the desired student
3378:
3379: =item * $domain: domain of the desired student
1.14 harris41 3380:
1.112 bowersj2 3381: =item * $course: Course ID
1.14 harris41 3382:
1.112 bowersj2 3383: =item * $getattempt: Leave blank for all attempts, otherwise put
3384: something
1.14 harris41 3385:
1.112 bowersj2 3386: =item * $regexp: if string matches this regexp, the string will be
3387: sent to $gradesub
1.14 harris41 3388:
1.112 bowersj2 3389: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3390:
1.112 bowersj2 3391: =back
1.14 harris41 3392:
1.112 bowersj2 3393: The output string is a table containing all desired attempts, if any.
1.16 harris41 3394:
1.112 bowersj2 3395: =cut
1.1 albertel 3396:
3397: sub get_previous_attempt {
1.43 ng 3398: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3399: my $prevattempts='';
1.43 ng 3400: no strict 'refs';
1.1 albertel 3401: if ($symb) {
1.3 albertel 3402: my (%returnhash)=
3403: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3404: if ($returnhash{'version'}) {
3405: my %lasthash=();
3406: my $version;
3407: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3408: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3409: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3410: }
1.1 albertel 3411: }
1.596 albertel 3412: $prevattempts=&start_data_table().&start_data_table_header_row();
3413: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3414: my (%typeparts,%lasthidden);
1.945 raeburn 3415: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3416: foreach my $key (sort(keys(%lasthash))) {
3417: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3418: if ($#parts > 0) {
1.31 albertel 3419: my $data=$parts[-1];
3420: pop(@parts);
1.945 raeburn 3421: if ($data eq 'type') {
3422: unless ($showsurv) {
3423: my $id = join(',',@parts);
3424: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3425: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3426: $lasthidden{$ign.'.'.$id} = 1;
3427: }
1.945 raeburn 3428: }
3429: delete($lasthash{$key});
3430: } else {
3431: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
3432: }
1.31 albertel 3433: } else {
1.41 ng 3434: if ($#parts == 0) {
3435: $prevattempts.='<th>'.$parts[0].'</th>';
3436: } else {
3437: $prevattempts.='<th>'.$ign.'</th>';
3438: }
1.31 albertel 3439: }
1.16 harris41 3440: }
1.596 albertel 3441: $prevattempts.=&end_data_table_header_row();
1.40 ng 3442: if ($getattempt eq '') {
3443: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3444: my @hidden;
3445: if (%typeparts) {
3446: foreach my $id (keys(%typeparts)) {
3447: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3448: push(@hidden,$id);
3449: }
3450: }
3451: }
3452: $prevattempts.=&start_data_table_row().
3453: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3454: if (@hidden) {
3455: foreach my $key (sort(keys(%lasthash))) {
3456: my $hide;
3457: foreach my $id (@hidden) {
3458: if ($key =~ /^\Q$id\E/) {
3459: $hide = 1;
3460: last;
3461: }
3462: }
3463: if ($hide) {
3464: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3465: if (($data eq 'award') || ($data eq 'awarddetail')) {
3466: my $value = &format_previous_attempt_value($key,
3467: $returnhash{$version.':'.$key});
3468: $prevattempts.='<td>'.$value.' </td>';
3469: } else {
3470: $prevattempts.='<td> </td>';
3471: }
3472: } else {
3473: if ($key =~ /\./) {
3474: my $value = &format_previous_attempt_value($key,
3475: $returnhash{$version.':'.$key});
3476: $prevattempts.='<td>'.$value.' </td>';
3477: } else {
3478: $prevattempts.='<td> </td>';
3479: }
3480: }
3481: }
3482: } else {
3483: foreach my $key (sort(keys(%lasthash))) {
3484: my $value = &format_previous_attempt_value($key,
3485: $returnhash{$version.':'.$key});
3486: $prevattempts.='<td>'.$value.' </td>';
3487: }
3488: }
3489: $prevattempts.=&end_data_table_row();
1.40 ng 3490: }
1.1 albertel 3491: }
1.945 raeburn 3492: my @currhidden = keys(%lasthidden);
1.596 albertel 3493: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3494: foreach my $key (sort(keys(%lasthash))) {
1.945 raeburn 3495: if (%typeparts) {
3496: my $hidden;
3497: foreach my $id (@currhidden) {
3498: if ($key =~ /^\Q$id\E/) {
3499: $hidden = 1;
3500: last;
3501: }
3502: }
3503: if ($hidden) {
3504: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3505: if (($data eq 'award') || ($data eq 'awarddetail')) {
3506: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3507: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3508: $value = &$gradesub($value);
3509: }
3510: $prevattempts.='<td>'.$value.' </td>';
3511: } else {
3512: $prevattempts.='<td> </td>';
3513: }
3514: } else {
3515: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3516: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3517: $value = &$gradesub($value);
3518: }
3519: $prevattempts.='<td>'.$value.' </td>';
3520: }
3521: } else {
3522: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3523: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3524: $value = &$gradesub($value);
3525: }
3526: $prevattempts.='<td>'.$value.' </td>';
3527: }
1.16 harris41 3528: }
1.596 albertel 3529: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3530: } else {
1.596 albertel 3531: $prevattempts=
3532: &start_data_table().&start_data_table_row().
3533: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3534: &end_data_table_row().&end_data_table();
1.1 albertel 3535: }
3536: } else {
1.596 albertel 3537: $prevattempts=
3538: &start_data_table().&start_data_table_row().
3539: '<td>'.&mt('No data.').'</td>'.
3540: &end_data_table_row().&end_data_table();
1.1 albertel 3541: }
1.10 albertel 3542: }
3543:
1.581 albertel 3544: sub format_previous_attempt_value {
3545: my ($key,$value) = @_;
3546: if ($key =~ /timestamp/) {
3547: $value = &Apache::lonlocal::locallocaltime($value);
3548: } elsif (ref($value) eq 'ARRAY') {
3549: $value = '('.join(', ', @{ $value }).')';
3550: } else {
3551: $value = &unescape($value);
3552: }
3553: return $value;
3554: }
3555:
3556:
1.107 albertel 3557: sub relative_to_absolute {
3558: my ($url,$output)=@_;
3559: my $parser=HTML::TokeParser->new(\$output);
3560: my $token;
3561: my $thisdir=$url;
3562: my @rlinks=();
3563: while ($token=$parser->get_token) {
3564: if ($token->[0] eq 'S') {
3565: if ($token->[1] eq 'a') {
3566: if ($token->[2]->{'href'}) {
3567: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3568: }
3569: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3570: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3571: } elsif ($token->[1] eq 'base') {
3572: $thisdir=$token->[2]->{'href'};
3573: }
3574: }
3575: }
3576: $thisdir=~s-/[^/]*$--;
1.356 albertel 3577: foreach my $link (@rlinks) {
1.726 raeburn 3578: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3579: ($link=~/^\//) ||
3580: ($link=~/^javascript:/i) ||
3581: ($link=~/^mailto:/i) ||
3582: ($link=~/^\#/)) {
3583: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3584: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3585: }
3586: }
3587: # -------------------------------------------------- Deal with Applet codebases
3588: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3589: return $output;
3590: }
3591:
1.112 bowersj2 3592: =pod
3593:
1.648 raeburn 3594: =item * &get_student_view()
1.112 bowersj2 3595:
3596: show a snapshot of what student was looking at
3597:
3598: =cut
3599:
1.10 albertel 3600: sub get_student_view {
1.186 albertel 3601: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3602: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3603: my (%form);
1.10 albertel 3604: my @elements=('symb','courseid','domain','username');
3605: foreach my $element (@elements) {
1.186 albertel 3606: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3607: }
1.186 albertel 3608: if (defined($moreenv)) {
3609: %form=(%form,%{$moreenv});
3610: }
1.236 albertel 3611: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3612: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3613: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3614: $userview=~s/\<body[^\>]*\>//gi;
3615: $userview=~s/\<\/body\>//gi;
3616: $userview=~s/\<html\>//gi;
3617: $userview=~s/\<\/html\>//gi;
3618: $userview=~s/\<head\>//gi;
3619: $userview=~s/\<\/head\>//gi;
3620: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3621: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3622: if (wantarray) {
3623: return ($userview,$response);
3624: } else {
3625: return $userview;
3626: }
3627: }
3628:
3629: sub get_student_view_with_retries {
3630: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3631:
3632: my $ok = 0; # True if we got a good response.
3633: my $content;
3634: my $response;
3635:
3636: # Try to get the student_view done. within the retries count:
3637:
3638: do {
3639: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3640: $ok = $response->is_success;
3641: if (!$ok) {
3642: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3643: }
3644: $retries--;
3645: } while (!$ok && ($retries > 0));
3646:
3647: if (!$ok) {
3648: $content = ''; # On error return an empty content.
3649: }
1.651 www 3650: if (wantarray) {
3651: return ($content, $response);
3652: } else {
3653: return $content;
3654: }
1.11 albertel 3655: }
3656:
1.112 bowersj2 3657: =pod
3658:
1.648 raeburn 3659: =item * &get_student_answers()
1.112 bowersj2 3660:
3661: show a snapshot of how student was answering problem
3662:
3663: =cut
3664:
1.11 albertel 3665: sub get_student_answers {
1.100 sakharuk 3666: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3667: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3668: my (%moreenv);
1.11 albertel 3669: my @elements=('symb','courseid','domain','username');
3670: foreach my $element (@elements) {
1.186 albertel 3671: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3672: }
1.186 albertel 3673: $moreenv{'grade_target'}='answer';
3674: %moreenv=(%form,%moreenv);
1.497 raeburn 3675: $feedurl = &Apache::lonnet::clutter($feedurl);
3676: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3677: return $userview;
1.1 albertel 3678: }
1.116 albertel 3679:
3680: =pod
3681:
3682: =item * &submlink()
3683:
1.242 albertel 3684: Inputs: $text $uname $udom $symb $target
1.116 albertel 3685:
3686: Returns: A link to grades.pm such as to see the SUBM view of a student
3687:
3688: =cut
3689:
3690: ###############################################
3691: sub submlink {
1.242 albertel 3692: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3693: if (!($uname && $udom)) {
3694: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3695: &Apache::lonnet::whichuser($symb);
1.116 albertel 3696: if (!$symb) { $symb=$cursymb; }
3697: }
1.254 matthew 3698: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3699: $symb=&escape($symb);
1.960 bisitz 3700: if ($target) { $target=" target=\"$target\""; }
3701: return
3702: '<a href="/adm/grades?command=submission'.
3703: '&symb='.$symb.
3704: '&student='.$uname.
3705: '&userdom='.$udom.'"'.
3706: $target.'>'.$text.'</a>';
1.242 albertel 3707: }
3708: ##############################################
3709:
3710: =pod
3711:
3712: =item * &pgrdlink()
3713:
3714: Inputs: $text $uname $udom $symb $target
3715:
3716: Returns: A link to grades.pm such as to see the PGRD view of a student
3717:
3718: =cut
3719:
3720: ###############################################
3721: sub pgrdlink {
3722: my $link=&submlink(@_);
3723: $link=~s/(&command=submission)/$1&showgrading=yes/;
3724: return $link;
3725: }
3726: ##############################################
3727:
3728: =pod
3729:
3730: =item * &pprmlink()
3731:
3732: Inputs: $text $uname $udom $symb $target
3733:
3734: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3735: student and a specific resource
1.242 albertel 3736:
3737: =cut
3738:
3739: ###############################################
3740: sub pprmlink {
3741: my ($text,$uname,$udom,$symb,$target)=@_;
3742: if (!($uname && $udom)) {
3743: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3744: &Apache::lonnet::whichuser($symb);
1.242 albertel 3745: if (!$symb) { $symb=$cursymb; }
3746: }
1.254 matthew 3747: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3748: $symb=&escape($symb);
1.242 albertel 3749: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3750: return '<a href="/adm/parmset?command=set&'.
3751: 'symb='.$symb.'&uname='.$uname.
3752: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3753: }
3754: ##############################################
1.37 matthew 3755:
1.112 bowersj2 3756: =pod
3757:
3758: =back
3759:
3760: =cut
3761:
1.37 matthew 3762: ###############################################
1.51 www 3763:
3764:
3765: sub timehash {
1.687 raeburn 3766: my ($thistime) = @_;
3767: my $timezone = &Apache::lonlocal::gettimezone();
3768: my $dt = DateTime->from_epoch(epoch => $thistime)
3769: ->set_time_zone($timezone);
3770: my $wday = $dt->day_of_week();
3771: if ($wday == 7) { $wday = 0; }
3772: return ( 'second' => $dt->second(),
3773: 'minute' => $dt->minute(),
3774: 'hour' => $dt->hour(),
3775: 'day' => $dt->day_of_month(),
3776: 'month' => $dt->month(),
3777: 'year' => $dt->year(),
3778: 'weekday' => $wday,
3779: 'dayyear' => $dt->day_of_year(),
3780: 'dlsav' => $dt->is_dst() );
1.51 www 3781: }
3782:
1.370 www 3783: sub utc_string {
3784: my ($date)=@_;
1.371 www 3785: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3786: }
3787:
1.51 www 3788: sub maketime {
3789: my %th=@_;
1.687 raeburn 3790: my ($epoch_time,$timezone,$dt);
3791: $timezone = &Apache::lonlocal::gettimezone();
3792: eval {
3793: $dt = DateTime->new( year => $th{'year'},
3794: month => $th{'month'},
3795: day => $th{'day'},
3796: hour => $th{'hour'},
3797: minute => $th{'minute'},
3798: second => $th{'second'},
3799: time_zone => $timezone,
3800: );
3801: };
3802: if (!$@) {
3803: $epoch_time = $dt->epoch;
3804: if ($epoch_time) {
3805: return $epoch_time;
3806: }
3807: }
1.51 www 3808: return POSIX::mktime(
3809: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3810: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3811: }
3812:
3813: #########################################
1.51 www 3814:
3815: sub findallcourses {
1.482 raeburn 3816: my ($roles,$uname,$udom) = @_;
1.355 albertel 3817: my %roles;
3818: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3819: my %courses;
1.51 www 3820: my $now=time;
1.482 raeburn 3821: if (!defined($uname)) {
3822: $uname = $env{'user.name'};
3823: }
3824: if (!defined($udom)) {
3825: $udom = $env{'user.domain'};
3826: }
3827: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.982 raeburn 3828: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
3829: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
3830: $extra);
1.482 raeburn 3831: if (!%roles) {
3832: %roles = (
3833: cc => 1,
1.907 raeburn 3834: co => 1,
1.482 raeburn 3835: in => 1,
3836: ep => 1,
3837: ta => 1,
3838: cr => 1,
3839: st => 1,
3840: );
3841: }
3842: foreach my $entry (keys(%roleshash)) {
3843: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3844: if ($trole =~ /^cr/) {
3845: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3846: } else {
3847: next if (!exists($roles{$trole}));
3848: }
3849: if ($tend) {
3850: next if ($tend < $now);
3851: }
3852: if ($tstart) {
3853: next if ($tstart > $now);
3854: }
3855: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3856: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3857: if ($secpart eq '') {
3858: ($cnum,$role) = split(/_/,$cnumpart);
3859: $sec = 'none';
3860: $realsec = '';
3861: } else {
3862: $cnum = $cnumpart;
3863: ($sec,$role) = split(/_/,$secpart);
3864: $realsec = $sec;
1.490 raeburn 3865: }
1.482 raeburn 3866: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3867: }
3868: } else {
3869: foreach my $key (keys(%env)) {
1.483 albertel 3870: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3871: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3872: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3873: next if ($role eq 'ca' || $role eq 'aa');
3874: next if (%roles && !exists($roles{$role}));
3875: my ($starttime,$endtime)=split(/\./,$env{$key});
3876: my $active=1;
3877: if ($starttime) {
3878: if ($now<$starttime) { $active=0; }
3879: }
3880: if ($endtime) {
3881: if ($now>$endtime) { $active=0; }
3882: }
3883: if ($active) {
3884: if ($sec eq '') {
3885: $sec = 'none';
3886: }
3887: $courses{$cdom.'_'.$cnum}{$sec} =
3888: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3889: }
3890: }
1.51 www 3891: }
3892: }
1.474 raeburn 3893: return %courses;
1.51 www 3894: }
1.37 matthew 3895:
1.54 www 3896: ###############################################
1.474 raeburn 3897:
3898: sub blockcheck {
1.482 raeburn 3899: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3900:
3901: if (!defined($udom)) {
3902: $udom = $env{'user.domain'};
3903: }
3904: if (!defined($uname)) {
3905: $uname = $env{'user.name'};
3906: }
3907:
3908: # If uname and udom are for a course, check for blocks in the course.
3909:
3910: if (&Apache::lonnet::is_course($udom,$uname)) {
3911: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3912: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3913: return ($startblock,$endblock);
3914: }
1.474 raeburn 3915:
1.502 raeburn 3916: my $startblock = 0;
3917: my $endblock = 0;
1.482 raeburn 3918: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3919:
1.490 raeburn 3920: # If uname is for a user, and activity is course-specific, i.e.,
3921: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3922:
1.490 raeburn 3923: if (($activity eq 'boards' || $activity eq 'chat' ||
3924: $activity eq 'groups') && ($env{'request.course.id'})) {
3925: foreach my $key (keys(%live_courses)) {
3926: if ($key ne $env{'request.course.id'}) {
3927: delete($live_courses{$key});
3928: }
3929: }
3930: }
3931:
3932: my $otheruser = 0;
3933: my %own_courses;
3934: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3935: # Resource belongs to user other than current user.
3936: $otheruser = 1;
3937: # Gather courses for current user
3938: %own_courses =
3939: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3940: }
3941:
3942: # Gather active course roles - course coordinator, instructor,
3943: # exam proctor, ta, student, or custom role.
1.474 raeburn 3944:
3945: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3946: my ($cdom,$cnum);
3947: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3948: $cdom = $env{'course.'.$course.'.domain'};
3949: $cnum = $env{'course.'.$course.'.num'};
3950: } else {
1.490 raeburn 3951: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3952: }
3953: my $no_ownblock = 0;
3954: my $no_userblock = 0;
1.533 raeburn 3955: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3956: # Check if current user has 'evb' priv for this
3957: if (defined($own_courses{$course})) {
3958: foreach my $sec (keys(%{$own_courses{$course}})) {
3959: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3960: if ($sec ne 'none') {
3961: $checkrole .= '/'.$sec;
3962: }
3963: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3964: $no_ownblock = 1;
3965: last;
3966: }
3967: }
3968: }
3969: # if they have 'evb' priv and are currently not playing student
3970: next if (($no_ownblock) &&
3971: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3972: }
1.474 raeburn 3973: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3974: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3975: if ($sec ne 'none') {
1.482 raeburn 3976: $checkrole .= '/'.$sec;
1.474 raeburn 3977: }
1.490 raeburn 3978: if ($otheruser) {
3979: # Resource belongs to user other than current user.
3980: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3981: my ($trole,$tdom,$tnum,$tsec);
3982: my $entry = $live_courses{$course}{$sec};
3983: if ($entry =~ /^cr/) {
3984: ($trole,$tdom,$tnum,$tsec) =
3985: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3986: } else {
3987: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3988: }
3989: my ($spec,$area,$trest,%allroles,%userroles);
3990: $area = '/'.$tdom.'/'.$tnum;
3991: $trest = $tnum;
3992: if ($tsec ne '') {
3993: $area .= '/'.$tsec;
3994: $trest .= '/'.$tsec;
3995: }
3996: $spec = $trole.'.'.$area;
3997: if ($trole =~ /^cr/) {
3998: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3999: $tdom,$spec,$trest,$area);
4000: } else {
4001: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4002: $tdom,$spec,$trest,$area);
4003: }
4004: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 4005: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4006: if ($1) {
4007: $no_userblock = 1;
4008: last;
4009: }
4010: }
1.490 raeburn 4011: } else {
4012: # Resource belongs to current user
4013: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4014: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4015: $no_ownblock = 1;
4016: last;
4017: }
1.474 raeburn 4018: }
4019: }
4020: # if they have the evb priv and are currently not playing student
1.482 raeburn 4021: next if (($no_ownblock) &&
1.491 albertel 4022: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4023: next if ($no_userblock);
1.474 raeburn 4024:
1.866 kalberla 4025: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4026: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4027:
4028: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
4029: if (($start != 0) &&
4030: (($startblock == 0) || ($startblock > $start))) {
4031: $startblock = $start;
4032: }
4033: if (($end != 0) &&
4034: (($endblock == 0) || ($endblock < $end))) {
4035: $endblock = $end;
4036: }
1.490 raeburn 4037: }
4038: return ($startblock,$endblock);
4039: }
4040:
4041: sub get_blocks {
4042: my ($setters,$activity,$cdom,$cnum) = @_;
4043: my $startblock = 0;
4044: my $endblock = 0;
4045: my $course = $cdom.'_'.$cnum;
4046: $setters->{$course} = {};
4047: $setters->{$course}{'staff'} = [];
4048: $setters->{$course}{'times'} = [];
4049: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
4050: foreach my $record (keys(%records)) {
4051: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
4052: if ($start <= time && $end >= time) {
4053: my ($staff_name,$staff_dom,$title,$blocks) =
4054: &parse_block_record($records{$record});
4055: if ($blocks->{$activity} eq 'on') {
4056: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4057: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 4058: if ( ($startblock == 0) || ($startblock > $start) ) {
4059: $startblock = $start;
1.490 raeburn 4060: }
1.491 albertel 4061: if ( ($endblock == 0) || ($endblock < $end) ) {
4062: $endblock = $end;
1.474 raeburn 4063: }
4064: }
4065: }
4066: }
4067: return ($startblock,$endblock);
4068: }
4069:
4070: sub parse_block_record {
4071: my ($record) = @_;
4072: my ($setuname,$setudom,$title,$blocks);
4073: if (ref($record) eq 'HASH') {
4074: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4075: $title = &unescape($record->{'event'});
4076: $blocks = $record->{'blocks'};
4077: } else {
4078: my @data = split(/:/,$record,3);
4079: if (scalar(@data) eq 2) {
4080: $title = $data[1];
4081: ($setuname,$setudom) = split(/@/,$data[0]);
4082: } else {
4083: ($setuname,$setudom,$title) = @data;
4084: }
4085: $blocks = { 'com' => 'on' };
4086: }
4087: return ($setuname,$setudom,$title,$blocks);
4088: }
4089:
1.854 kalberla 4090: sub blocking_status {
4091: my ($activity,$uname,$udom) = @_;
1.867 kalberla 4092: my %setters;
1.890 droeschl 4093:
4094: # check for active blocking
1.867 kalberla 4095: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854 kalberla 4096:
1.890 droeschl 4097: my $blocked = $startblock && $endblock ? 1 : 0;
4098:
4099: # caller just wants to know whether a block is active
4100: if (!wantarray) { return $blocked; }
4101:
4102: # build a link to a popup window containing the details
4103: my $querystring = "?activity=$activity";
4104: # $uname and $udom decide whose portfolio the user is trying to look at
4105: $querystring .= "&udom=$udom" if $udom;
4106: $querystring .= "&uname=$uname" if $uname;
4107:
4108: my $output .= <<'END_MYBLOCK';
1.854 kalberla 4109: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4110: var options = "width=" + w + ",height=" + h + ",";
4111: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4112: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4113: var newWin = window.open(url, wdwName, options);
4114: newWin.focus();
4115: }
1.890 droeschl 4116: END_MYBLOCK
1.854 kalberla 4117:
1.890 droeschl 4118: $output = Apache::lonhtmlcommon::scripttag($output);
4119:
1.854 kalberla 4120: my $popupUrl = "/adm/blockingstatus/$querystring";
1.890 droeschl 4121: my $text = mt('Communication Blocked');
4122:
1.867 kalberla 4123: $output .= <<"END_BLOCK";
4124: <div class='LC_comblock'>
1.869 kalberla 4125: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4126: title='$text'>
4127: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4128: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4129: title='$text'>$text</a>
1.867 kalberla 4130: </div>
4131:
4132: END_BLOCK
1.474 raeburn 4133:
1.854 kalberla 4134: return ($blocked, $output);
4135: }
1.490 raeburn 4136:
1.60 matthew 4137: ###############################################
4138:
1.682 raeburn 4139: sub check_ip_acc {
4140: my ($acc)=@_;
4141: &Apache::lonxml::debug("acc is $acc");
4142: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4143: return 1;
4144: }
4145: my $allowed=0;
4146: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4147:
4148: my $name;
4149: foreach my $pattern (split(',',$acc)) {
4150: $pattern =~ s/^\s*//;
4151: $pattern =~ s/\s*$//;
4152: if ($pattern =~ /\*$/) {
4153: #35.8.*
4154: $pattern=~s/\*//;
4155: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4156: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4157: #35.8.3.[34-56]
4158: my $low=$2;
4159: my $high=$3;
4160: $pattern=$1;
4161: if ($ip =~ /^\Q$pattern\E/) {
4162: my $last=(split(/\./,$ip))[3];
4163: if ($last <=$high && $last >=$low) { $allowed=1; }
4164: }
4165: } elsif ($pattern =~ /^\*/) {
4166: #*.msu.edu
4167: $pattern=~s/\*//;
4168: if (!defined($name)) {
4169: use Socket;
4170: my $netaddr=inet_aton($ip);
4171: ($name)=gethostbyaddr($netaddr,AF_INET);
4172: }
4173: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4174: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4175: #127.0.0.1
4176: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4177: } else {
4178: #some.name.com
4179: if (!defined($name)) {
4180: use Socket;
4181: my $netaddr=inet_aton($ip);
4182: ($name)=gethostbyaddr($netaddr,AF_INET);
4183: }
4184: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4185: }
4186: if ($allowed) { last; }
4187: }
4188: return $allowed;
4189: }
4190:
4191: ###############################################
4192:
1.60 matthew 4193: =pod
4194:
1.112 bowersj2 4195: =head1 Domain Template Functions
4196:
4197: =over 4
4198:
4199: =item * &determinedomain()
1.60 matthew 4200:
4201: Inputs: $domain (usually will be undef)
4202:
1.63 www 4203: Returns: Determines which domain should be used for designs
1.60 matthew 4204:
4205: =cut
1.54 www 4206:
1.60 matthew 4207: ###############################################
1.63 www 4208: sub determinedomain {
4209: my $domain=shift;
1.531 albertel 4210: if (! $domain) {
1.60 matthew 4211: # Determine domain if we have not been given one
1.893 raeburn 4212: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4213: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4214: if ($env{'request.role.domain'}) {
4215: $domain=$env{'request.role.domain'};
1.60 matthew 4216: }
4217: }
1.63 www 4218: return $domain;
4219: }
4220: ###############################################
1.517 raeburn 4221:
1.518 albertel 4222: sub devalidate_domconfig_cache {
4223: my ($udom)=@_;
4224: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4225: }
4226:
4227: # ---------------------- Get domain configuration for a domain
4228: sub get_domainconf {
4229: my ($udom) = @_;
4230: my $cachetime=1800;
4231: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4232: if (defined($cached)) { return %{$result}; }
4233:
4234: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4235: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4236: my (%designhash,%legacy);
1.518 albertel 4237: if (keys(%domconfig) > 0) {
4238: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4239: if (keys(%{$domconfig{'login'}})) {
4240: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4241: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4242: if ($key eq 'loginvia') {
4243: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
4244: my @ids = &Apache::lonnet::current_machine_ids();
4245: foreach my $hostname (@ids) {
1.948 raeburn 4246: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4247: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4248: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4249: $designhash{$udom.'.login.loginvia'} = $server;
4250: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4251:
4252: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4253: } else {
4254: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4255: }
4256: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4257: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4258: }
1.946 raeburn 4259: }
4260: }
4261: }
4262: }
4263: } else {
4264: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4265: $designhash{$udom.'.login.'.$key.'_'.$img} =
4266: $domconfig{'login'}{$key}{$img};
4267: }
1.699 raeburn 4268: }
4269: } else {
4270: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4271: }
1.632 raeburn 4272: }
4273: } else {
4274: $legacy{'login'} = 1;
1.518 albertel 4275: }
1.632 raeburn 4276: } else {
4277: $legacy{'login'} = 1;
1.518 albertel 4278: }
4279: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4280: if (keys(%{$domconfig{'rolecolors'}})) {
4281: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4282: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4283: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4284: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4285: }
1.518 albertel 4286: }
4287: }
1.632 raeburn 4288: } else {
4289: $legacy{'rolecolors'} = 1;
1.518 albertel 4290: }
1.632 raeburn 4291: } else {
4292: $legacy{'rolecolors'} = 1;
1.518 albertel 4293: }
1.948 raeburn 4294: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4295: if ($domconfig{'autoenroll'}{'co-owners'}) {
4296: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4297: }
4298: }
1.632 raeburn 4299: if (keys(%legacy) > 0) {
4300: my %legacyhash = &get_legacy_domconf($udom);
4301: foreach my $item (keys(%legacyhash)) {
4302: if ($item =~ /^\Q$udom\E\.login/) {
4303: if ($legacy{'login'}) {
4304: $designhash{$item} = $legacyhash{$item};
4305: }
4306: } else {
4307: if ($legacy{'rolecolors'}) {
4308: $designhash{$item} = $legacyhash{$item};
4309: }
1.518 albertel 4310: }
4311: }
4312: }
1.632 raeburn 4313: } else {
4314: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4315: }
4316: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4317: $cachetime);
4318: return %designhash;
4319: }
4320:
1.632 raeburn 4321: sub get_legacy_domconf {
4322: my ($udom) = @_;
4323: my %legacyhash;
4324: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4325: my $designfile = $designdir.'/'.$udom.'.tab';
4326: if (-e $designfile) {
4327: if ( open (my $fh,"<$designfile") ) {
4328: while (my $line = <$fh>) {
4329: next if ($line =~ /^\#/);
4330: chomp($line);
4331: my ($key,$val)=(split(/\=/,$line));
4332: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4333: }
4334: close($fh);
4335: }
4336: }
4337: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4338: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4339: }
4340: return %legacyhash;
4341: }
4342:
1.63 www 4343: =pod
4344:
1.112 bowersj2 4345: =item * &domainlogo()
1.63 www 4346:
4347: Inputs: $domain (usually will be undef)
4348:
4349: Returns: A link to a domain logo, if the domain logo exists.
4350: If the domain logo does not exist, a description of the domain.
4351:
4352: =cut
1.112 bowersj2 4353:
1.63 www 4354: ###############################################
4355: sub domainlogo {
1.517 raeburn 4356: my $domain = &determinedomain(shift);
1.518 albertel 4357: my %designhash = &get_domainconf($domain);
1.517 raeburn 4358: # See if there is a logo
4359: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4360: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4361: if ($imgsrc =~ m{^/(adm|res)/}) {
4362: if ($imgsrc =~ m{^/res/}) {
4363: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4364: &Apache::lonnet::repcopy($local_name);
4365: }
4366: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4367: }
4368: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4369: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4370: return &Apache::lonnet::domain($domain,'description');
1.59 www 4371: } else {
1.60 matthew 4372: return '';
1.59 www 4373: }
4374: }
1.63 www 4375: ##############################################
4376:
4377: =pod
4378:
1.112 bowersj2 4379: =item * &designparm()
1.63 www 4380:
4381: Inputs: $which parameter; $domain (usually will be undef)
4382:
4383: Returns: value of designparamter $which
4384:
4385: =cut
1.112 bowersj2 4386:
1.397 albertel 4387:
1.400 albertel 4388: ##############################################
1.397 albertel 4389: sub designparm {
4390: my ($which,$domain)=@_;
4391: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4392: return $env{'environment.color.'.$which};
1.96 www 4393: }
1.63 www 4394: $domain=&determinedomain($domain);
1.518 albertel 4395: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4396: my $output;
1.517 raeburn 4397: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4398: $output = $domdesign{$domain.'.'.$which};
1.63 www 4399: } else {
1.520 raeburn 4400: $output = $defaultdesign{$which};
4401: }
4402: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4403: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4404: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4405: if ($output =~ m{^/res/}) {
4406: my $local_name = &Apache::lonnet::filelocation('',$output);
4407: &Apache::lonnet::repcopy($local_name);
4408: }
1.520 raeburn 4409: $output = &lonhttpdurl($output);
4410: }
1.63 www 4411: }
1.520 raeburn 4412: return $output;
1.63 www 4413: }
1.59 www 4414:
1.822 bisitz 4415: ##############################################
4416: =pod
4417:
1.832 bisitz 4418: =item * &authorspace()
4419:
4420: Inputs: ./.
4421:
4422: Returns: Path to the Construction Space of the current user's
4423: accessed author space
4424: The author space will be that of the current user
4425: when accessing the own author space
4426: and that of the co-author/assistent co-author
4427: when accessing the co-author's/assistent co-author's
4428: space
4429:
4430: =cut
4431:
4432: sub authorspace {
4433: my $caname = '';
4434: if ($env{'request.role'} =~ /^ca|^aa/) {
4435: (undef,$caname) =
4436: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
4437: } else {
4438: $caname = $env{'user.name'};
4439: }
4440: return '/priv/'.$caname.'/';
4441: }
4442:
4443: ##############################################
4444: =pod
4445:
1.822 bisitz 4446: =item * &head_subbox()
4447:
4448: Inputs: $content (contains HTML code with page functions, etc.)
4449:
4450: Returns: HTML div with $content
4451: To be included in page header
4452:
4453: =cut
4454:
4455: sub head_subbox {
4456: my ($content)=@_;
4457: my $output =
1.844 bisitz 4458: '<div id="LC_head_subbox">'
1.822 bisitz 4459: .$content
4460: .'</div>'
4461: }
4462:
4463: ##############################################
4464: =pod
4465:
4466: =item * &CSTR_pageheader()
4467:
4468: Inputs: ./.
4469:
4470: Returns: HTML div with CSTR path and recent box
4471: To be included on Construction Space pages
4472:
4473: =cut
4474:
4475: sub CSTR_pageheader {
4476: # this is for resources; directories have customtitle, and crumbs
4477: # and select recent are created in lonpubdir.pm
4478: my ($uname,$thisdisfn)=
4479: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
4480: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4481: $formaction=~s/\/+/\//g;
4482:
4483: my $parentpath = '';
4484: my $lastitem = '';
4485: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4486: $parentpath = $1;
4487: $lastitem = $2;
4488: } else {
4489: $lastitem = $thisdisfn;
4490: }
1.921 bisitz 4491:
4492: my $output =
1.822 bisitz 4493: '<div>'
4494: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
4495: .'<b>'.&mt('Construction Space:').'</b> '
4496: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 4497: .'" target="_top">' #FIXME lonpubdir: target="_parent"
4498: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
4499:
4500: if ($lastitem) {
4501: $output .=
4502: '<span class="LC_filename">'
4503: .$lastitem
4504: .'</span>';
4505: }
4506: $output .=
4507: '<br />'
1.822 bisitz 4508: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
4509: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4510: .'</form>'
4511: .&Apache::lonmenu::constspaceform()
4512: .'</div>';
1.921 bisitz 4513:
4514: return $output;
1.822 bisitz 4515: }
4516:
1.60 matthew 4517: ###############################################
4518: ###############################################
4519:
4520: =pod
4521:
1.112 bowersj2 4522: =back
4523:
1.549 albertel 4524: =head1 HTML Helpers
1.112 bowersj2 4525:
4526: =over 4
4527:
4528: =item * &bodytag()
1.60 matthew 4529:
4530: Returns a uniform header for LON-CAPA web pages.
4531:
4532: Inputs:
4533:
1.112 bowersj2 4534: =over 4
4535:
4536: =item * $title, A title to be displayed on the page.
4537:
4538: =item * $function, the current role (can be undef).
4539:
4540: =item * $addentries, extra parameters for the <body> tag.
4541:
4542: =item * $bodyonly, if defined, only return the <body> tag.
4543:
4544: =item * $domain, if defined, force a given domain.
4545:
4546: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4547: text interface only)
1.60 matthew 4548:
1.814 bisitz 4549: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
4550: navigational links
1.317 albertel 4551:
1.338 albertel 4552: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4553:
1.460 albertel 4554: =item * $args, optional argument valid values are
4555: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4556: inherit_jsmath -> when creating popup window in a page,
4557: should it have jsmath forced on by the
4558: current page
1.460 albertel 4559:
1.112 bowersj2 4560: =back
4561:
1.60 matthew 4562: Returns: A uniform header for LON-CAPA web pages.
4563: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4564: If $bodyonly is undef or zero, an html string containing a <body> tag and
4565: other decorations will be returned.
4566:
4567: =cut
4568:
1.54 www 4569: sub bodytag {
1.831 bisitz 4570: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962 droeschl 4571: $no_nav_bar,$bgcolor,$args)=@_;
1.339 albertel 4572:
1.954 raeburn 4573: my $public;
4574: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
4575: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
4576: $public = 1;
4577: }
1.460 albertel 4578: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4579:
1.183 matthew 4580: $function = &get_users_function() if (!$function);
1.339 albertel 4581: my $img = &designparm($function.'.img',$domain);
4582: my $font = &designparm($function.'.font',$domain);
4583: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4584:
1.803 bisitz 4585: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4586: 'bgcolor' => $pgbg,
1.339 albertel 4587: 'text' => $font,
4588: 'alink' => &designparm($function.'.alink',$domain),
4589: 'vlink' => &designparm($function.'.vlink',$domain),
4590: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4591: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4592:
1.63 www 4593: # role and realm
1.378 raeburn 4594: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4595: if ($role eq 'ca') {
1.479 albertel 4596: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4597: $realm = &plainname($rname,$rdom);
1.378 raeburn 4598: }
1.55 www 4599: # realm
1.258 albertel 4600: if ($env{'request.course.id'}) {
1.378 raeburn 4601: if ($env{'request.role'} !~ /^cr/) {
4602: $role = &Apache::lonnet::plaintext($role,&course_type());
4603: }
1.898 raeburn 4604: if ($env{'request.course.sec'}) {
4605: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
4606: }
1.359 albertel 4607: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4608: } else {
4609: $role = &Apache::lonnet::plaintext($role);
1.54 www 4610: }
1.433 albertel 4611:
1.359 albertel 4612: if (!$realm) { $realm=' '; }
1.330 albertel 4613:
1.438 albertel 4614: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4615:
1.101 www 4616: # construct main body tag
1.359 albertel 4617: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4618: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4619:
1.530 albertel 4620: if ($bodyonly) {
1.60 matthew 4621: return $bodytag;
1.798 tempelho 4622: }
1.359 albertel 4623:
1.410 albertel 4624: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 4625: if ($public) {
1.433 albertel 4626: undef($role);
1.434 albertel 4627: } else {
4628: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4629: }
1.359 albertel 4630:
1.762 bisitz 4631: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 4632: #
4633: # Extra info if you are the DC
4634: my $dc_info = '';
4635: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4636: $env{'course.'.$env{'request.course.id'}.
4637: '.domain'}.'/'})) {
4638: my $cid = $env{'request.course.id'};
1.917 raeburn 4639: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4640: $dc_info =~ s/\s+$//;
1.359 albertel 4641: }
4642:
1.898 raeburn 4643: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 4644: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
4645:
1.916 droeschl 4646: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
4647: return $bodytag;
4648: }
1.903 droeschl 4649:
4650: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
4651:
4652: # if ($env{'request.state'} eq 'construct') {
4653: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
4654: # }
4655:
1.359 albertel 4656:
4657:
1.916 droeschl 4658: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 4659: if ($dc_info) {
4660: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
4661: }
1.916 droeschl 4662: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
4663: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 4664: return $bodytag;
4665: }
1.894 droeschl 4666:
1.927 raeburn 4667: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
4668: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
4669: }
1.916 droeschl 4670:
1.903 droeschl 4671: $bodytag .= Apache::lonhtmlcommon::scripttag(
4672: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 4673:
1.903 droeschl 4674: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 4675:
1.917 raeburn 4676: if ($dc_info) {
4677: $dc_info = &dc_courseid_toggle($dc_info);
4678: }
4679: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 4680:
1.903 droeschl 4681: #don't show menus for public users
1.954 raeburn 4682: if (!$public){
1.903 droeschl 4683: $bodytag .= Apache::lonmenu::secondary_menu();
4684: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 4685: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
4686: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 4687: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 4688: $args->{'bread_crumbs'});
4689: } elsif ($forcereg) {
4690: $bodytag .= &Apache::lonmenu::innerregister($forcereg);
4691: }
1.903 droeschl 4692: }else{
4693: # this is to seperate menu from content when there's no secondary
4694: # menu. Especially needed for public accessible ressources.
4695: $bodytag .= '<hr style="clear:both" />';
4696: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 4697: }
1.903 droeschl 4698:
1.235 raeburn 4699: return $bodytag;
1.182 matthew 4700: }
4701:
1.917 raeburn 4702: sub dc_courseid_toggle {
4703: my ($dc_info) = @_;
1.980 raeburn 4704: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917 raeburn 4705: '<a href="javascript:showCourseID();">'.
4706: &mt('(More ...)').'</a></span>'.
4707: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
4708: }
4709:
1.330 albertel 4710: sub make_attr_string {
4711: my ($register,$attr_ref) = @_;
4712:
4713: if ($attr_ref && !ref($attr_ref)) {
4714: die("addentries Must be a hash ref ".
4715: join(':',caller(1))." ".
4716: join(':',caller(0))." ");
4717: }
4718:
4719: if ($register) {
1.339 albertel 4720: my ($on_load,$on_unload);
4721: foreach my $key (keys(%{$attr_ref})) {
4722: if (lc($key) eq 'onload') {
4723: $on_load.=$attr_ref->{$key}.';';
4724: delete($attr_ref->{$key});
4725:
4726: } elsif (lc($key) eq 'onunload') {
4727: $on_unload.=$attr_ref->{$key}.';';
4728: delete($attr_ref->{$key});
4729: }
4730: }
1.953 droeschl 4731: $attr_ref->{'onload'} = $on_load;
4732: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 4733: }
1.339 albertel 4734:
1.330 albertel 4735: my $attr_string;
4736: foreach my $attr (keys(%$attr_ref)) {
4737: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4738: }
4739: return $attr_string;
4740: }
4741:
4742:
1.182 matthew 4743: ###############################################
1.251 albertel 4744: ###############################################
4745:
4746: =pod
4747:
4748: =item * &endbodytag()
4749:
4750: Returns a uniform footer for LON-CAPA web pages.
4751:
1.635 raeburn 4752: Inputs: 1 - optional reference to an args hash
4753: If in the hash, key for noredirectlink has a value which evaluates to true,
4754: a 'Continue' link is not displayed if the page contains an
4755: internal redirect in the <head></head> section,
4756: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4757:
4758: =cut
4759:
4760: sub endbodytag {
1.635 raeburn 4761: my ($args) = @_;
1.251 albertel 4762: my $endbodytag='</body>';
1.269 albertel 4763: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4764: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4765: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4766: $endbodytag=
4767: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4768: &mt('Continue').'</a>'.
4769: $endbodytag;
4770: }
1.315 albertel 4771: }
1.251 albertel 4772: return $endbodytag;
4773: }
4774:
1.352 albertel 4775: =pod
4776:
4777: =item * &standard_css()
4778:
4779: Returns a style sheet
4780:
4781: Inputs: (all optional)
4782: domain -> force to color decorate a page for a specific
4783: domain
4784: function -> force usage of a specific rolish color scheme
4785: bgcolor -> override the default page bgcolor
4786:
4787: =cut
4788:
1.343 albertel 4789: sub standard_css {
1.345 albertel 4790: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4791: $function = &get_users_function() if (!$function);
4792: my $img = &designparm($function.'.img', $domain);
4793: my $tabbg = &designparm($function.'.tabbg', $domain);
4794: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 4795: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 4796: #second colour for later usage
1.345 albertel 4797: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4798: my $pgbg_or_bgcolor =
4799: $bgcolor ||
1.352 albertel 4800: &designparm($function.'.pgbg', $domain);
1.382 albertel 4801: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4802: my $alink = &designparm($function.'.alink', $domain);
4803: my $vlink = &designparm($function.'.vlink', $domain);
4804: my $link = &designparm($function.'.link', $domain);
4805:
1.602 albertel 4806: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4807: my $mono = 'monospace';
1.850 bisitz 4808: my $data_table_head = $sidebg;
4809: my $data_table_light = '#FAFAFA';
4810: my $data_table_dark = '#F0F0F0';
1.470 banghart 4811: my $data_table_darker = '#CCCCCC';
1.349 albertel 4812: my $data_table_highlight = '#FFFF00';
1.352 albertel 4813: my $mail_new = '#FFBB77';
4814: my $mail_new_hover = '#DD9955';
4815: my $mail_read = '#BBBB77';
4816: my $mail_read_hover = '#999944';
4817: my $mail_replied = '#AAAA88';
4818: my $mail_replied_hover = '#888855';
4819: my $mail_other = '#99BBBB';
4820: my $mail_other_hover = '#669999';
1.391 albertel 4821: my $table_header = '#DDDDDD';
1.489 raeburn 4822: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 4823: my $lg_border_color = '#C8C8C8';
1.952 onken 4824: my $button_hover = '#BF2317';
1.392 albertel 4825:
1.608 albertel 4826: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 4827: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4828: : '0 3px 0 4px';
1.448 albertel 4829:
1.523 albertel 4830:
1.343 albertel 4831: return <<END;
1.947 droeschl 4832:
4833: /* needed for iframe to allow 100% height in FF */
4834: body, html {
4835: margin: 0;
4836: padding: 0 0.5%;
4837: height: 99%; /* to avoid scrollbars */
4838: }
4839:
1.795 www 4840: body {
1.911 bisitz 4841: font-family: $sans;
4842: line-height:130%;
4843: font-size:0.83em;
4844: color:$font;
1.795 www 4845: }
4846:
1.959 onken 4847: a:focus,
4848: a:focus img {
1.795 www 4849: color: red;
1.911 bisitz 4850: background: yellow;
1.795 www 4851: }
1.698 harmsja 4852:
1.911 bisitz 4853: form, .inline {
4854: display: inline;
1.795 www 4855: }
1.721 harmsja 4856:
1.795 www 4857: .LC_right {
1.911 bisitz 4858: text-align:right;
1.795 www 4859: }
4860:
4861: .LC_middle {
1.911 bisitz 4862: vertical-align:middle;
1.795 www 4863: }
1.721 harmsja 4864:
1.911 bisitz 4865: .LC_400Box {
4866: width:400px;
4867: }
1.721 harmsja 4868:
1.947 droeschl 4869: .LC_iframecontainer {
4870: width: 98%;
4871: margin: 0;
4872: position: fixed;
4873: top: 8.5em;
4874: bottom: 0;
4875: }
4876:
4877: .LC_iframecontainer iframe{
4878: border: none;
4879: width: 100%;
4880: height: 100%;
4881: }
4882:
1.778 bisitz 4883: .LC_filename {
4884: font-family: $mono;
4885: white-space:pre;
1.921 bisitz 4886: font-size: 120%;
1.778 bisitz 4887: }
4888:
4889: .LC_fileicon {
4890: border: none;
4891: height: 1.3em;
4892: vertical-align: text-bottom;
4893: margin-right: 0.3em;
4894: text-decoration:none;
4895: }
4896:
1.350 albertel 4897: .LC_error {
4898: color: red;
4899: font-size: larger;
4900: }
1.795 www 4901:
1.457 albertel 4902: .LC_warning,
4903: .LC_diff_removed {
1.733 bisitz 4904: color: red;
1.394 albertel 4905: }
1.532 albertel 4906:
4907: .LC_info,
1.457 albertel 4908: .LC_success,
4909: .LC_diff_added {
1.350 albertel 4910: color: green;
4911: }
1.795 www 4912:
1.802 bisitz 4913: div.LC_confirm_box {
4914: background-color: #FAFAFA;
4915: border: 1px solid $lg_border_color;
4916: margin-right: 0;
4917: padding: 5px;
4918: }
4919:
4920: div.LC_confirm_box .LC_error img,
4921: div.LC_confirm_box .LC_success img {
4922: vertical-align: middle;
4923: }
4924:
1.440 albertel 4925: .LC_icon {
1.771 droeschl 4926: border: none;
1.790 droeschl 4927: vertical-align: middle;
1.771 droeschl 4928: }
4929:
1.543 albertel 4930: .LC_docs_spacer {
4931: width: 25px;
4932: height: 1px;
1.771 droeschl 4933: border: none;
1.543 albertel 4934: }
1.346 albertel 4935:
1.532 albertel 4936: .LC_internal_info {
1.735 bisitz 4937: color: #999999;
1.532 albertel 4938: }
4939:
1.794 www 4940: .LC_discussion {
1.911 bisitz 4941: background: $tabbg;
4942: border: 1px solid black;
4943: margin: 2px;
1.794 www 4944: }
4945:
4946: .LC_disc_action_links_bar {
1.911 bisitz 4947: background: $tabbg;
4948: border: none;
4949: margin: 4px;
1.794 www 4950: }
4951:
4952: .LC_disc_action_left {
1.911 bisitz 4953: text-align: left;
1.794 www 4954: }
4955:
4956: .LC_disc_action_right {
1.911 bisitz 4957: text-align: right;
1.794 www 4958: }
4959:
4960: .LC_disc_new_item {
1.911 bisitz 4961: background: white;
4962: border: 2px solid red;
4963: margin: 2px;
1.794 www 4964: }
4965:
4966: .LC_disc_old_item {
1.911 bisitz 4967: background: white;
4968: border: 1px solid black;
4969: margin: 2px;
1.794 www 4970: }
4971:
1.458 albertel 4972: table.LC_pastsubmission {
4973: border: 1px solid black;
4974: margin: 2px;
4975: }
4976:
1.924 bisitz 4977: table#LC_menubuttons {
1.345 albertel 4978: width: 100%;
4979: background: $pgbg;
1.392 albertel 4980: border: 2px;
1.402 albertel 4981: border-collapse: separate;
1.803 bisitz 4982: padding: 0;
1.345 albertel 4983: }
1.392 albertel 4984:
1.801 tempelho 4985: table#LC_title_bar a {
4986: color: $fontmenu;
4987: }
1.836 bisitz 4988:
1.807 droeschl 4989: table#LC_title_bar {
1.819 tempelho 4990: clear: both;
1.836 bisitz 4991: display: none;
1.807 droeschl 4992: }
4993:
1.795 www 4994: table#LC_title_bar,
1.933 droeschl 4995: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 4996: table#LC_title_bar.LC_with_remote {
1.359 albertel 4997: width: 100%;
1.392 albertel 4998: border-color: $pgbg;
4999: border-style: solid;
5000: border-width: $border;
1.379 albertel 5001: background: $pgbg;
1.801 tempelho 5002: color: $fontmenu;
1.392 albertel 5003: border-collapse: collapse;
1.803 bisitz 5004: padding: 0;
1.819 tempelho 5005: margin: 0;
1.359 albertel 5006: }
1.795 www 5007:
1.933 droeschl 5008: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5009: margin: 0;
5010: padding: 0;
1.933 droeschl 5011: position: relative;
5012: list-style: none;
1.913 droeschl 5013: }
1.933 droeschl 5014: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5015: display: inline;
5016: }
1.933 droeschl 5017:
5018: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5019: padding: 0;
1.933 droeschl 5020: margin: 0;
5021: float: left;
1.913 droeschl 5022: }
1.933 droeschl 5023: .LC_breadcrumb_tools_tools {
5024: padding: 0;
5025: margin: 0;
1.913 droeschl 5026: float: right;
5027: }
5028:
1.359 albertel 5029: table#LC_title_bar td {
5030: background: $tabbg;
5031: }
1.795 www 5032:
1.911 bisitz 5033: table#LC_menubuttons img {
1.803 bisitz 5034: border: none;
1.346 albertel 5035: }
1.795 www 5036:
1.842 droeschl 5037: .LC_breadcrumbs_component {
1.911 bisitz 5038: float: right;
5039: margin: 0 1em;
1.357 albertel 5040: }
1.842 droeschl 5041: .LC_breadcrumbs_component img {
1.911 bisitz 5042: vertical-align: middle;
1.777 tempelho 5043: }
1.795 www 5044:
1.383 albertel 5045: td.LC_table_cell_checkbox {
5046: text-align: center;
5047: }
1.795 www 5048:
5049: .LC_fontsize_small {
1.911 bisitz 5050: font-size: 70%;
1.705 tempelho 5051: }
5052:
1.844 bisitz 5053: #LC_breadcrumbs {
1.911 bisitz 5054: clear:both;
5055: background: $sidebg;
5056: border-bottom: 1px solid $lg_border_color;
5057: line-height: 2.5em;
1.933 droeschl 5058: overflow: hidden;
1.911 bisitz 5059: margin: 0;
5060: padding: 0;
1.819 tempelho 5061: }
1.862 bisitz 5062:
1.844 bisitz 5063: #LC_head_subbox {
1.911 bisitz 5064: clear:both;
5065: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5066: border: 1px solid $sidebg;
5067: margin: 0 0 10px 0;
1.966 bisitz 5068: padding: 3px;
1.822 bisitz 5069: }
5070:
1.795 www 5071: .LC_fontsize_medium {
1.911 bisitz 5072: font-size: 85%;
1.705 tempelho 5073: }
5074:
1.795 www 5075: .LC_fontsize_large {
1.911 bisitz 5076: font-size: 120%;
1.705 tempelho 5077: }
5078:
1.346 albertel 5079: .LC_menubuttons_inline_text {
5080: color: $font;
1.698 harmsja 5081: font-size: 90%;
1.701 harmsja 5082: padding-left:3px;
1.346 albertel 5083: }
5084:
1.934 droeschl 5085: .LC_menubuttons_inline_text img{
5086: vertical-align: middle;
5087: }
5088:
1.951 onken 5089: li.LC_menubuttons_inline_text img,a {
5090: cursor:pointer;
5091: }
5092:
1.526 www 5093: .LC_menubuttons_link {
5094: text-decoration: none;
5095: }
1.795 www 5096:
1.522 albertel 5097: .LC_menubuttons_category {
1.521 www 5098: color: $font;
1.526 www 5099: background: $pgbg;
1.521 www 5100: font-size: larger;
5101: font-weight: bold;
5102: }
5103:
1.346 albertel 5104: td.LC_menubuttons_text {
1.911 bisitz 5105: color: $font;
1.346 albertel 5106: }
1.706 harmsja 5107:
1.346 albertel 5108: .LC_current_location {
5109: background: $tabbg;
5110: }
1.795 www 5111:
1.938 bisitz 5112: table.LC_data_table {
1.347 albertel 5113: border: 1px solid #000000;
1.402 albertel 5114: border-collapse: separate;
1.426 albertel 5115: border-spacing: 1px;
1.610 albertel 5116: background: $pgbg;
1.347 albertel 5117: }
1.795 www 5118:
1.422 albertel 5119: .LC_data_table_dense {
5120: font-size: small;
5121: }
1.795 www 5122:
1.507 raeburn 5123: table.LC_nested_outer {
5124: border: 1px solid #000000;
1.589 raeburn 5125: border-collapse: collapse;
1.803 bisitz 5126: border-spacing: 0;
1.507 raeburn 5127: width: 100%;
5128: }
1.795 www 5129:
1.879 raeburn 5130: table.LC_innerpickbox,
1.507 raeburn 5131: table.LC_nested {
1.803 bisitz 5132: border: none;
1.589 raeburn 5133: border-collapse: collapse;
1.803 bisitz 5134: border-spacing: 0;
1.507 raeburn 5135: width: 100%;
5136: }
1.795 www 5137:
1.930 faziophi 5138: .ui-accordion,
5139: .ui-accordion table.LC_data_table,
5140: .ui-accordion table.LC_nested_outer{
5141: border: 0px;
5142: border-spacing: 0px;
5143: margin: 3px;
5144: }
5145:
1.911 bisitz 5146: table.LC_data_table tr th,
5147: table.LC_calendar tr th,
1.879 raeburn 5148: table.LC_prior_tries tr th,
5149: table.LC_innerpickbox tr th {
1.349 albertel 5150: font-weight: bold;
5151: background-color: $data_table_head;
1.801 tempelho 5152: color:$fontmenu;
1.701 harmsja 5153: font-size:90%;
1.347 albertel 5154: }
1.795 www 5155:
1.879 raeburn 5156: table.LC_innerpickbox tr th,
5157: table.LC_innerpickbox tr td {
5158: vertical-align: top;
5159: }
5160:
1.711 raeburn 5161: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5162: background-color: #CCCCCC;
1.711 raeburn 5163: font-weight: bold;
5164: text-align: left;
5165: }
1.795 www 5166:
1.912 bisitz 5167: table.LC_data_table tr.LC_odd_row > td {
5168: background-color: $data_table_light;
5169: padding: 2px;
5170: vertical-align: top;
5171: }
5172:
1.809 bisitz 5173: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5174: background-color: $data_table_light;
1.912 bisitz 5175: vertical-align: top;
5176: }
5177:
5178: table.LC_data_table tr.LC_even_row > td {
5179: background-color: $data_table_dark;
1.425 albertel 5180: padding: 2px;
1.900 bisitz 5181: vertical-align: top;
1.347 albertel 5182: }
1.795 www 5183:
1.809 bisitz 5184: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5185: background-color: $data_table_dark;
1.900 bisitz 5186: vertical-align: top;
1.347 albertel 5187: }
1.795 www 5188:
1.425 albertel 5189: table.LC_data_table tr.LC_data_table_highlight td {
5190: background-color: $data_table_darker;
5191: }
1.795 www 5192:
1.639 raeburn 5193: table.LC_data_table tr td.LC_leftcol_header {
5194: background-color: $data_table_head;
5195: font-weight: bold;
5196: }
1.795 www 5197:
1.451 albertel 5198: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5199: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5200: font-weight: bold;
5201: font-style: italic;
5202: text-align: center;
5203: padding: 8px;
1.347 albertel 5204: }
1.795 www 5205:
1.940 bisitz 5206: table.LC_data_table tr.LC_empty_row td {
5207: background-color: $sidebg;
5208: }
5209:
5210: table.LC_nested tr.LC_empty_row td {
5211: background-color: #FFFFFF;
5212: }
5213:
1.890 droeschl 5214: table.LC_caption {
5215: }
5216:
1.507 raeburn 5217: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5218: padding: 4ex
5219: }
1.795 www 5220:
1.507 raeburn 5221: table.LC_nested_outer tr th {
5222: font-weight: bold;
1.801 tempelho 5223: color:$fontmenu;
1.507 raeburn 5224: background-color: $data_table_head;
1.701 harmsja 5225: font-size: small;
1.507 raeburn 5226: border-bottom: 1px solid #000000;
5227: }
1.795 www 5228:
1.507 raeburn 5229: table.LC_nested_outer tr td.LC_subheader {
5230: background-color: $data_table_head;
5231: font-weight: bold;
5232: font-size: small;
5233: border-bottom: 1px solid #000000;
5234: text-align: right;
1.451 albertel 5235: }
1.795 www 5236:
1.507 raeburn 5237: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5238: background-color: #CCCCCC;
1.451 albertel 5239: font-weight: bold;
5240: font-size: small;
1.507 raeburn 5241: text-align: center;
5242: }
1.795 www 5243:
1.589 raeburn 5244: table.LC_nested tr.LC_info_row td.LC_left_item,
5245: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5246: text-align: left;
1.451 albertel 5247: }
1.795 www 5248:
1.507 raeburn 5249: table.LC_nested td {
1.735 bisitz 5250: background-color: #FFFFFF;
1.451 albertel 5251: font-size: small;
1.507 raeburn 5252: }
1.795 www 5253:
1.507 raeburn 5254: table.LC_nested_outer tr th.LC_right_item,
5255: table.LC_nested tr.LC_info_row td.LC_right_item,
5256: table.LC_nested tr.LC_odd_row td.LC_right_item,
5257: table.LC_nested tr td.LC_right_item {
1.451 albertel 5258: text-align: right;
5259: }
5260:
1.930 faziophi 5261: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
5262: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
5263: text-align: right;
5264: width: 40%;
5265: padding-right:10px;
5266: vertical-align: top;
5267: padding: 5px;
5268: }
5269:
5270: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
5271: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
5272: text-align: left;
5273: width: 60%;
5274: padding: 2px 4px;
5275: }
5276:
1.507 raeburn 5277: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5278: background-color: #EEEEEE;
1.451 albertel 5279: }
5280:
1.473 raeburn 5281: table.LC_createuser {
5282: }
5283:
5284: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5285: font-size: small;
1.473 raeburn 5286: }
5287:
5288: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5289: background-color: #CCCCCC;
1.473 raeburn 5290: font-weight: bold;
5291: text-align: center;
5292: }
5293:
1.349 albertel 5294: table.LC_calendar {
5295: border: 1px solid #000000;
5296: border-collapse: collapse;
1.917 raeburn 5297: width: 98%;
1.349 albertel 5298: }
1.795 www 5299:
1.349 albertel 5300: table.LC_calendar_pickdate {
5301: font-size: xx-small;
5302: }
1.795 www 5303:
1.349 albertel 5304: table.LC_calendar tr td {
5305: border: 1px solid #000000;
5306: vertical-align: top;
1.917 raeburn 5307: width: 14%;
1.349 albertel 5308: }
1.795 www 5309:
1.349 albertel 5310: table.LC_calendar tr td.LC_calendar_day_empty {
5311: background-color: $data_table_dark;
5312: }
1.795 www 5313:
1.779 bisitz 5314: table.LC_calendar tr td.LC_calendar_day_current {
5315: background-color: $data_table_highlight;
1.777 tempelho 5316: }
1.795 www 5317:
1.938 bisitz 5318: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5319: background-color: $mail_new;
5320: }
1.795 www 5321:
1.938 bisitz 5322: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5323: background-color: $mail_new_hover;
5324: }
1.795 www 5325:
1.938 bisitz 5326: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5327: background-color: $mail_read;
5328: }
1.795 www 5329:
1.938 bisitz 5330: /*
5331: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5332: background-color: $mail_read_hover;
5333: }
1.938 bisitz 5334: */
1.795 www 5335:
1.938 bisitz 5336: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5337: background-color: $mail_replied;
5338: }
1.795 www 5339:
1.938 bisitz 5340: /*
5341: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5342: background-color: $mail_replied_hover;
5343: }
1.938 bisitz 5344: */
1.795 www 5345:
1.938 bisitz 5346: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5347: background-color: $mail_other;
5348: }
1.795 www 5349:
1.938 bisitz 5350: /*
5351: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5352: background-color: $mail_other_hover;
5353: }
1.938 bisitz 5354: */
1.494 raeburn 5355:
1.777 tempelho 5356: table.LC_data_table tr > td.LC_browser_file,
5357: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5358: background: #AAEE77;
1.389 albertel 5359: }
1.795 www 5360:
1.777 tempelho 5361: table.LC_data_table tr > td.LC_browser_file_locked,
5362: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5363: background: #FFAA99;
1.387 albertel 5364: }
1.795 www 5365:
1.777 tempelho 5366: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5367: background: #888888;
1.779 bisitz 5368: }
1.795 www 5369:
1.777 tempelho 5370: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5371: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5372: background: #F8F866;
1.777 tempelho 5373: }
1.795 www 5374:
1.696 bisitz 5375: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5376: background: #E0E8FF;
1.387 albertel 5377: }
1.696 bisitz 5378:
1.707 bisitz 5379: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5380: /* background: #77FF77; */
1.707 bisitz 5381: }
1.795 www 5382:
1.707 bisitz 5383: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5384: border-right: 8px solid #FFFF77;
1.707 bisitz 5385: }
1.795 www 5386:
1.707 bisitz 5387: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5388: border-right: 8px solid #FFAA77;
1.707 bisitz 5389: }
1.795 www 5390:
1.707 bisitz 5391: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5392: border-right: 8px solid #FF7777;
1.707 bisitz 5393: }
1.795 www 5394:
1.707 bisitz 5395: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5396: border-right: 8px solid #AAFF77;
1.707 bisitz 5397: }
1.795 www 5398:
1.707 bisitz 5399: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5400: border-right: 8px solid #11CC55;
1.707 bisitz 5401: }
5402:
1.388 albertel 5403: span.LC_current_location {
1.701 harmsja 5404: font-size:larger;
1.388 albertel 5405: background: $pgbg;
5406: }
1.387 albertel 5407:
1.395 albertel 5408: span.LC_parm_menu_item {
5409: font-size: larger;
5410: }
1.795 www 5411:
1.395 albertel 5412: span.LC_parm_scope_all {
5413: color: red;
5414: }
1.795 www 5415:
1.395 albertel 5416: span.LC_parm_scope_folder {
5417: color: green;
5418: }
1.795 www 5419:
1.395 albertel 5420: span.LC_parm_scope_resource {
5421: color: orange;
5422: }
1.795 www 5423:
1.395 albertel 5424: span.LC_parm_part {
5425: color: blue;
5426: }
1.795 www 5427:
1.911 bisitz 5428: span.LC_parm_folder,
5429: span.LC_parm_symb {
1.395 albertel 5430: font-size: x-small;
5431: font-family: $mono;
5432: color: #AAAAAA;
5433: }
5434:
1.977 bisitz 5435: ul.LC_parm_parmlist li {
5436: display: inline-block;
5437: padding: 0.3em 0.8em;
5438: vertical-align: top;
5439: width: 150px;
5440: border-top:1px solid $lg_border_color;
5441: }
5442:
1.795 www 5443: td.LC_parm_overview_level_menu,
5444: td.LC_parm_overview_map_menu,
5445: td.LC_parm_overview_parm_selectors,
5446: td.LC_parm_overview_restrictions {
1.396 albertel 5447: border: 1px solid black;
5448: border-collapse: collapse;
5449: }
1.795 www 5450:
1.396 albertel 5451: table.LC_parm_overview_restrictions td {
5452: border-width: 1px 4px 1px 4px;
5453: border-style: solid;
5454: border-color: $pgbg;
5455: text-align: center;
5456: }
1.795 www 5457:
1.396 albertel 5458: table.LC_parm_overview_restrictions th {
5459: background: $tabbg;
5460: border-width: 1px 4px 1px 4px;
5461: border-style: solid;
5462: border-color: $pgbg;
5463: }
1.795 www 5464:
1.398 albertel 5465: table#LC_helpmenu {
1.803 bisitz 5466: border: none;
1.398 albertel 5467: height: 55px;
1.803 bisitz 5468: border-spacing: 0;
1.398 albertel 5469: }
5470:
5471: table#LC_helpmenu fieldset legend {
5472: font-size: larger;
5473: }
1.795 www 5474:
1.397 albertel 5475: table#LC_helpmenu_links {
5476: width: 100%;
5477: border: 1px solid black;
5478: background: $pgbg;
1.803 bisitz 5479: padding: 0;
1.397 albertel 5480: border-spacing: 1px;
5481: }
1.795 www 5482:
1.397 albertel 5483: table#LC_helpmenu_links tr td {
5484: padding: 1px;
5485: background: $tabbg;
1.399 albertel 5486: text-align: center;
5487: font-weight: bold;
1.397 albertel 5488: }
1.396 albertel 5489:
1.795 www 5490: table#LC_helpmenu_links a:link,
5491: table#LC_helpmenu_links a:visited,
1.397 albertel 5492: table#LC_helpmenu_links a:active {
5493: text-decoration: none;
5494: color: $font;
5495: }
1.795 www 5496:
1.397 albertel 5497: table#LC_helpmenu_links a:hover {
5498: text-decoration: underline;
5499: color: $vlink;
5500: }
1.396 albertel 5501:
1.417 albertel 5502: .LC_chrt_popup_exists {
5503: border: 1px solid #339933;
5504: margin: -1px;
5505: }
1.795 www 5506:
1.417 albertel 5507: .LC_chrt_popup_up {
5508: border: 1px solid yellow;
5509: margin: -1px;
5510: }
1.795 www 5511:
1.417 albertel 5512: .LC_chrt_popup {
5513: border: 1px solid #8888FF;
5514: background: #CCCCFF;
5515: }
1.795 www 5516:
1.421 albertel 5517: table.LC_pick_box {
5518: border-collapse: separate;
5519: background: white;
5520: border: 1px solid black;
5521: border-spacing: 1px;
5522: }
1.795 www 5523:
1.421 albertel 5524: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 5525: background: $sidebg;
1.421 albertel 5526: font-weight: bold;
1.900 bisitz 5527: text-align: left;
1.740 bisitz 5528: vertical-align: top;
1.421 albertel 5529: width: 184px;
5530: padding: 8px;
5531: }
1.795 www 5532:
1.579 raeburn 5533: table.LC_pick_box td.LC_pick_box_value {
5534: text-align: left;
5535: padding: 8px;
5536: }
1.795 www 5537:
1.579 raeburn 5538: table.LC_pick_box td.LC_pick_box_select {
5539: text-align: left;
5540: padding: 8px;
5541: }
1.795 www 5542:
1.424 albertel 5543: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 5544: padding: 0;
1.421 albertel 5545: height: 1px;
5546: background: black;
5547: }
1.795 www 5548:
1.421 albertel 5549: table.LC_pick_box td.LC_pick_box_submit {
5550: text-align: right;
5551: }
1.795 www 5552:
1.579 raeburn 5553: table.LC_pick_box td.LC_evenrow_value {
5554: text-align: left;
5555: padding: 8px;
5556: background-color: $data_table_light;
5557: }
1.795 www 5558:
1.579 raeburn 5559: table.LC_pick_box td.LC_oddrow_value {
5560: text-align: left;
5561: padding: 8px;
5562: background-color: $data_table_light;
5563: }
1.795 www 5564:
1.579 raeburn 5565: span.LC_helpform_receipt_cat {
5566: font-weight: bold;
5567: }
1.795 www 5568:
1.424 albertel 5569: table.LC_group_priv_box {
5570: background: white;
5571: border: 1px solid black;
5572: border-spacing: 1px;
5573: }
1.795 www 5574:
1.424 albertel 5575: table.LC_group_priv_box td.LC_pick_box_title {
5576: background: $tabbg;
5577: font-weight: bold;
5578: text-align: right;
5579: width: 184px;
5580: }
1.795 www 5581:
1.424 albertel 5582: table.LC_group_priv_box td.LC_groups_fixed {
5583: background: $data_table_light;
5584: text-align: center;
5585: }
1.795 www 5586:
1.424 albertel 5587: table.LC_group_priv_box td.LC_groups_optional {
5588: background: $data_table_dark;
5589: text-align: center;
5590: }
1.795 www 5591:
1.424 albertel 5592: table.LC_group_priv_box td.LC_groups_functionality {
5593: background: $data_table_darker;
5594: text-align: center;
5595: font-weight: bold;
5596: }
1.795 www 5597:
1.424 albertel 5598: table.LC_group_priv td {
5599: text-align: left;
1.803 bisitz 5600: padding: 0;
1.424 albertel 5601: }
5602:
5603: .LC_navbuttons {
5604: margin: 2ex 0ex 2ex 0ex;
5605: }
1.795 www 5606:
1.423 albertel 5607: .LC_topic_bar {
5608: font-weight: bold;
5609: background: $tabbg;
1.918 wenzelju 5610: margin: 1em 0em 1em 2em;
1.805 bisitz 5611: padding: 3px;
1.918 wenzelju 5612: font-size: 1.2em;
1.423 albertel 5613: }
1.795 www 5614:
1.423 albertel 5615: .LC_topic_bar span {
1.918 wenzelju 5616: left: 0.5em;
5617: position: absolute;
1.423 albertel 5618: vertical-align: middle;
1.918 wenzelju 5619: font-size: 1.2em;
1.423 albertel 5620: }
1.795 www 5621:
1.423 albertel 5622: table.LC_course_group_status {
5623: margin: 20px;
5624: }
1.795 www 5625:
1.423 albertel 5626: table.LC_status_selector td {
5627: vertical-align: top;
5628: text-align: center;
1.424 albertel 5629: padding: 4px;
5630: }
1.795 www 5631:
1.599 albertel 5632: div.LC_feedback_link {
1.616 albertel 5633: clear: both;
1.829 kalberla 5634: background: $sidebg;
1.779 bisitz 5635: width: 100%;
1.829 kalberla 5636: padding-bottom: 10px;
5637: border: 1px $tabbg solid;
1.833 kalberla 5638: height: 22px;
5639: line-height: 22px;
5640: padding-top: 5px;
5641: }
5642:
5643: div.LC_feedback_link img {
5644: height: 22px;
1.867 kalberla 5645: vertical-align:middle;
1.829 kalberla 5646: }
5647:
1.911 bisitz 5648: div.LC_feedback_link a {
1.829 kalberla 5649: text-decoration: none;
1.489 raeburn 5650: }
1.795 www 5651:
1.867 kalberla 5652: div.LC_comblock {
1.911 bisitz 5653: display:inline;
1.867 kalberla 5654: color:$font;
5655: font-size:90%;
5656: }
5657:
5658: div.LC_feedback_link div.LC_comblock {
5659: padding-left:5px;
5660: }
5661:
5662: div.LC_feedback_link div.LC_comblock a {
5663: color:$font;
5664: }
5665:
1.489 raeburn 5666: span.LC_feedback_link {
1.858 bisitz 5667: /* background: $feedback_link_bg; */
1.599 albertel 5668: font-size: larger;
5669: }
1.795 www 5670:
1.599 albertel 5671: span.LC_message_link {
1.858 bisitz 5672: /* background: $feedback_link_bg; */
1.599 albertel 5673: font-size: larger;
5674: position: absolute;
5675: right: 1em;
1.489 raeburn 5676: }
1.421 albertel 5677:
1.515 albertel 5678: table.LC_prior_tries {
1.524 albertel 5679: border: 1px solid #000000;
5680: border-collapse: separate;
5681: border-spacing: 1px;
1.515 albertel 5682: }
1.523 albertel 5683:
1.515 albertel 5684: table.LC_prior_tries td {
1.524 albertel 5685: padding: 2px;
1.515 albertel 5686: }
1.523 albertel 5687:
5688: .LC_answer_correct {
1.795 www 5689: background: lightgreen;
5690: color: darkgreen;
5691: padding: 6px;
1.523 albertel 5692: }
1.795 www 5693:
1.523 albertel 5694: .LC_answer_charged_try {
1.797 www 5695: background: #FFAAAA;
1.795 www 5696: color: darkred;
5697: padding: 6px;
1.523 albertel 5698: }
1.795 www 5699:
1.779 bisitz 5700: .LC_answer_not_charged_try,
1.523 albertel 5701: .LC_answer_no_grade,
5702: .LC_answer_late {
1.795 www 5703: background: lightyellow;
1.523 albertel 5704: color: black;
1.795 www 5705: padding: 6px;
1.523 albertel 5706: }
1.795 www 5707:
1.523 albertel 5708: .LC_answer_previous {
1.795 www 5709: background: lightblue;
5710: color: darkblue;
5711: padding: 6px;
1.523 albertel 5712: }
1.795 www 5713:
1.779 bisitz 5714: .LC_answer_no_message {
1.777 tempelho 5715: background: #FFFFFF;
5716: color: black;
1.795 www 5717: padding: 6px;
1.779 bisitz 5718: }
1.795 www 5719:
1.779 bisitz 5720: .LC_answer_unknown {
5721: background: orange;
5722: color: black;
1.795 www 5723: padding: 6px;
1.777 tempelho 5724: }
1.795 www 5725:
1.529 albertel 5726: span.LC_prior_numerical,
5727: span.LC_prior_string,
5728: span.LC_prior_custom,
5729: span.LC_prior_reaction,
5730: span.LC_prior_math {
1.925 bisitz 5731: font-family: $mono;
1.523 albertel 5732: white-space: pre;
5733: }
5734:
1.525 albertel 5735: span.LC_prior_string {
1.925 bisitz 5736: font-family: $mono;
1.525 albertel 5737: white-space: pre;
5738: }
5739:
1.523 albertel 5740: table.LC_prior_option {
5741: width: 100%;
5742: border-collapse: collapse;
5743: }
1.795 www 5744:
1.911 bisitz 5745: table.LC_prior_rank,
1.795 www 5746: table.LC_prior_match {
1.528 albertel 5747: border-collapse: collapse;
5748: }
1.795 www 5749:
1.528 albertel 5750: table.LC_prior_option tr td,
5751: table.LC_prior_rank tr td,
5752: table.LC_prior_match tr td {
1.524 albertel 5753: border: 1px solid #000000;
1.515 albertel 5754: }
5755:
1.855 bisitz 5756: .LC_nobreak {
1.544 albertel 5757: white-space: nowrap;
1.519 raeburn 5758: }
5759:
1.576 raeburn 5760: span.LC_cusr_emph {
5761: font-style: italic;
5762: }
5763:
1.633 raeburn 5764: span.LC_cusr_subheading {
5765: font-weight: normal;
5766: font-size: 85%;
5767: }
5768:
1.861 bisitz 5769: div.LC_docs_entry_move {
1.859 bisitz 5770: border: 1px solid #BBBBBB;
1.545 albertel 5771: background: #DDDDDD;
1.861 bisitz 5772: width: 22px;
1.859 bisitz 5773: padding: 1px;
5774: margin: 0;
1.545 albertel 5775: }
5776:
1.861 bisitz 5777: table.LC_data_table tr > td.LC_docs_entry_commands,
5778: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 5779: background: #DDDDDD;
5780: font-size: x-small;
5781: }
1.795 www 5782:
1.861 bisitz 5783: .LC_docs_entry_parameter {
5784: white-space: nowrap;
5785: }
5786:
1.544 albertel 5787: .LC_docs_copy {
1.545 albertel 5788: color: #000099;
1.544 albertel 5789: }
1.795 www 5790:
1.544 albertel 5791: .LC_docs_cut {
1.545 albertel 5792: color: #550044;
1.544 albertel 5793: }
1.795 www 5794:
1.544 albertel 5795: .LC_docs_rename {
1.545 albertel 5796: color: #009900;
1.544 albertel 5797: }
1.795 www 5798:
1.544 albertel 5799: .LC_docs_remove {
1.545 albertel 5800: color: #990000;
5801: }
5802:
1.547 albertel 5803: .LC_docs_reinit_warn,
5804: .LC_docs_ext_edit {
5805: font-size: x-small;
5806: }
5807:
1.545 albertel 5808: table.LC_docs_adddocs td,
5809: table.LC_docs_adddocs th {
5810: border: 1px solid #BBBBBB;
5811: padding: 4px;
5812: background: #DDDDDD;
1.543 albertel 5813: }
5814:
1.584 albertel 5815: table.LC_sty_begin {
5816: background: #BBFFBB;
5817: }
1.795 www 5818:
1.584 albertel 5819: table.LC_sty_end {
5820: background: #FFBBBB;
5821: }
5822:
1.589 raeburn 5823: table.LC_double_column {
1.803 bisitz 5824: border-width: 0;
1.589 raeburn 5825: border-collapse: collapse;
5826: width: 100%;
5827: padding: 2px;
5828: }
5829:
5830: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5831: top: 2px;
1.589 raeburn 5832: left: 2px;
5833: width: 47%;
5834: vertical-align: top;
5835: }
5836:
5837: table.LC_double_column tr td.LC_right_col {
5838: top: 2px;
1.779 bisitz 5839: right: 2px;
1.589 raeburn 5840: width: 47%;
5841: vertical-align: top;
5842: }
5843:
1.591 raeburn 5844: div.LC_left_float {
5845: float: left;
5846: padding-right: 5%;
1.597 albertel 5847: padding-bottom: 4px;
1.591 raeburn 5848: }
5849:
5850: div.LC_clear_float_header {
1.597 albertel 5851: padding-bottom: 2px;
1.591 raeburn 5852: }
5853:
5854: div.LC_clear_float_footer {
1.597 albertel 5855: padding-top: 10px;
1.591 raeburn 5856: clear: both;
5857: }
5858:
1.597 albertel 5859: div.LC_grade_show_user {
1.941 bisitz 5860: /* border-left: 5px solid $sidebg; */
5861: border-top: 5px solid #000000;
5862: margin: 50px 0 0 0;
1.936 bisitz 5863: padding: 15px 0 5px 10px;
1.597 albertel 5864: }
1.795 www 5865:
1.936 bisitz 5866: div.LC_grade_show_user_odd_row {
1.941 bisitz 5867: /* border-left: 5px solid #000000; */
5868: }
5869:
5870: div.LC_grade_show_user div.LC_Box {
5871: margin-right: 50px;
1.597 albertel 5872: }
5873:
5874: div.LC_grade_submissions,
5875: div.LC_grade_message_center,
1.936 bisitz 5876: div.LC_grade_info_links {
1.597 albertel 5877: margin: 5px;
5878: width: 99%;
5879: background: #FFFFFF;
5880: }
1.795 www 5881:
1.597 albertel 5882: div.LC_grade_submissions_header,
1.936 bisitz 5883: div.LC_grade_message_center_header {
1.705 tempelho 5884: font-weight: bold;
5885: font-size: large;
1.597 albertel 5886: }
1.795 www 5887:
1.597 albertel 5888: div.LC_grade_submissions_body,
1.936 bisitz 5889: div.LC_grade_message_center_body {
1.597 albertel 5890: border: 1px solid black;
5891: width: 99%;
5892: background: #FFFFFF;
5893: }
1.795 www 5894:
1.613 albertel 5895: table.LC_scantron_action {
5896: width: 100%;
5897: }
1.795 www 5898:
1.613 albertel 5899: table.LC_scantron_action tr th {
1.698 harmsja 5900: font-weight:bold;
5901: font-style:normal;
1.613 albertel 5902: }
1.795 www 5903:
1.779 bisitz 5904: .LC_edit_problem_header,
1.614 albertel 5905: div.LC_edit_problem_footer {
1.705 tempelho 5906: font-weight: normal;
5907: font-size: medium;
1.602 albertel 5908: margin: 2px;
1.600 albertel 5909: }
1.795 www 5910:
1.600 albertel 5911: div.LC_edit_problem_header,
1.602 albertel 5912: div.LC_edit_problem_header div,
1.614 albertel 5913: div.LC_edit_problem_footer,
5914: div.LC_edit_problem_footer div,
1.602 albertel 5915: div.LC_edit_problem_editxml_header,
5916: div.LC_edit_problem_editxml_header div {
1.600 albertel 5917: margin-top: 5px;
5918: }
1.795 www 5919:
1.600 albertel 5920: div.LC_edit_problem_header_title {
1.705 tempelho 5921: font-weight: bold;
5922: font-size: larger;
1.602 albertel 5923: background: $tabbg;
5924: padding: 3px;
5925: }
1.795 www 5926:
1.602 albertel 5927: table.LC_edit_problem_header_title {
5928: width: 100%;
1.600 albertel 5929: background: $tabbg;
1.602 albertel 5930: }
5931:
5932: div.LC_edit_problem_discards {
5933: float: left;
5934: padding-bottom: 5px;
5935: }
1.795 www 5936:
1.602 albertel 5937: div.LC_edit_problem_saves {
5938: float: right;
5939: padding-bottom: 5px;
1.600 albertel 5940: }
1.795 www 5941:
1.911 bisitz 5942: img.stift {
1.803 bisitz 5943: border-width: 0;
5944: vertical-align: middle;
1.677 riegler 5945: }
1.680 riegler 5946:
1.923 bisitz 5947: table td.LC_mainmenu_col_fieldset {
1.680 riegler 5948: vertical-align: top;
1.777 tempelho 5949: }
1.795 www 5950:
1.716 raeburn 5951: div.LC_createcourse {
1.911 bisitz 5952: margin: 10px 10px 10px 10px;
1.716 raeburn 5953: }
5954:
1.917 raeburn 5955: .LC_dccid {
5956: margin: 0.2em 0 0 0;
5957: padding: 0;
5958: font-size: 90%;
5959: display:none;
5960: }
5961:
1.698 harmsja 5962: a:hover,
1.897 wenzelju 5963: ol.LC_primary_menu a:hover,
1.721 harmsja 5964: ol#LC_MenuBreadcrumbs a:hover,
5965: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 5966: ul#LC_secondary_menu a:hover,
1.721 harmsja 5967: .LC_FormSectionClearButton input:hover
1.795 www 5968: ul.LC_TabContent li:hover a {
1.952 onken 5969: color:$button_hover;
1.911 bisitz 5970: text-decoration:none;
1.693 droeschl 5971: }
5972:
1.779 bisitz 5973: h1 {
1.911 bisitz 5974: padding: 0;
5975: line-height:130%;
1.693 droeschl 5976: }
1.698 harmsja 5977:
1.911 bisitz 5978: h2,
5979: h3,
5980: h4,
5981: h5,
5982: h6 {
5983: margin: 5px 0 5px 0;
5984: padding: 0;
5985: line-height:130%;
1.693 droeschl 5986: }
1.795 www 5987:
5988: .LC_hcell {
1.911 bisitz 5989: padding:3px 15px 3px 15px;
5990: margin: 0;
5991: background-color:$tabbg;
5992: color:$fontmenu;
5993: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5994: }
1.795 www 5995:
1.840 bisitz 5996: .LC_Box > .LC_hcell {
1.911 bisitz 5997: margin: 0 -10px 10px -10px;
1.835 bisitz 5998: }
5999:
1.721 harmsja 6000: .LC_noBorder {
1.911 bisitz 6001: border: 0;
1.698 harmsja 6002: }
1.693 droeschl 6003:
1.721 harmsja 6004: .LC_FormSectionClearButton input {
1.911 bisitz 6005: background-color:transparent;
6006: border: none;
6007: cursor:pointer;
6008: text-decoration:underline;
1.693 droeschl 6009: }
1.763 bisitz 6010:
6011: .LC_help_open_topic {
1.911 bisitz 6012: color: #FFFFFF;
6013: background-color: #EEEEFF;
6014: margin: 1px;
6015: padding: 4px;
6016: border: 1px solid #000033;
6017: white-space: nowrap;
6018: /* vertical-align: middle; */
1.759 neumanie 6019: }
1.693 droeschl 6020:
1.911 bisitz 6021: dl,
6022: ul,
6023: div,
6024: fieldset {
6025: margin: 10px 10px 10px 0;
6026: /* overflow: hidden; */
1.693 droeschl 6027: }
1.795 www 6028:
1.838 bisitz 6029: fieldset > legend {
1.911 bisitz 6030: font-weight: bold;
6031: padding: 0 5px 0 5px;
1.838 bisitz 6032: }
6033:
1.813 bisitz 6034: #LC_nav_bar {
1.911 bisitz 6035: float: left;
1.966 bisitz 6036: margin: 0 0 2px 0;
1.807 droeschl 6037: }
6038:
1.916 droeschl 6039: #LC_realm {
6040: margin: 0.2em 0 0 0;
6041: padding: 0;
6042: font-weight: bold;
6043: text-align: center;
6044: }
6045:
1.911 bisitz 6046: #LC_nav_bar em {
6047: font-weight: bold;
6048: font-style: normal;
1.807 droeschl 6049: }
6050:
1.897 wenzelju 6051: ol.LC_primary_menu {
1.911 bisitz 6052: float: right;
1.934 droeschl 6053: margin: 0;
1.807 droeschl 6054: }
6055:
1.852 droeschl 6056: ol#LC_PathBreadcrumbs {
1.911 bisitz 6057: margin: 0;
1.693 droeschl 6058: }
6059:
1.897 wenzelju 6060: ol.LC_primary_menu li {
1.911 bisitz 6061: display: inline;
6062: padding: 5px 5px 0 10px;
6063: vertical-align: top;
1.693 droeschl 6064: }
6065:
1.897 wenzelju 6066: ol.LC_primary_menu li img {
1.911 bisitz 6067: vertical-align: bottom;
1.934 droeschl 6068: height: 1.1em;
1.693 droeschl 6069: }
6070:
1.897 wenzelju 6071: ol.LC_primary_menu a {
1.911 bisitz 6072: color: RGB(80, 80, 80);
6073: text-decoration: none;
1.693 droeschl 6074: }
1.795 www 6075:
1.949 droeschl 6076: ol.LC_primary_menu a.LC_new_message {
6077: font-weight:bold;
6078: color: darkred;
6079: }
6080:
1.975 raeburn 6081: ol.LC_docs_parameters {
6082: margin-left: 0;
6083: padding: 0;
6084: list-style: none;
6085: }
6086:
6087: ol.LC_docs_parameters li {
6088: margin: 0;
6089: padding-right: 20px;
6090: display: inline;
6091: }
6092:
1.976 raeburn 6093: ol.LC_docs_parameters li:before {
6094: content: "\\002022 \\0020";
6095: }
6096:
6097: li.LC_docs_parameters_title {
6098: font-weight: bold;
6099: }
6100:
6101: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6102: content: "";
6103: }
6104:
1.897 wenzelju 6105: ul#LC_secondary_menu {
1.911 bisitz 6106: clear: both;
6107: color: $fontmenu;
6108: background: $tabbg;
6109: list-style: none;
6110: padding: 0;
6111: margin: 0;
6112: width: 100%;
1.808 droeschl 6113: }
6114:
1.897 wenzelju 6115: ul#LC_secondary_menu li {
1.911 bisitz 6116: font-weight: bold;
6117: line-height: 1.8em;
6118: padding: 0 0.8em;
6119: border-right: 1px solid black;
6120: display: inline;
6121: vertical-align: middle;
1.807 droeschl 6122: }
6123:
1.847 tempelho 6124: ul.LC_TabContent {
1.911 bisitz 6125: display:block;
6126: background: $sidebg;
6127: border-bottom: solid 1px $lg_border_color;
6128: list-style:none;
6129: margin: 0 -10px;
6130: padding: 0;
1.693 droeschl 6131: }
6132:
1.795 www 6133: ul.LC_TabContent li,
6134: ul.LC_TabContentBigger li {
1.911 bisitz 6135: float:left;
1.741 harmsja 6136: }
1.795 www 6137:
1.897 wenzelju 6138: ul#LC_secondary_menu li a {
1.911 bisitz 6139: color: $fontmenu;
6140: text-decoration: none;
1.693 droeschl 6141: }
1.795 www 6142:
1.721 harmsja 6143: ul.LC_TabContent {
1.952 onken 6144: min-height:20px;
1.721 harmsja 6145: }
1.795 www 6146:
6147: ul.LC_TabContent li {
1.911 bisitz 6148: vertical-align:middle;
1.959 onken 6149: padding: 0 16px 0 10px;
1.911 bisitz 6150: background-color:$tabbg;
6151: border-bottom:solid 1px $lg_border_color;
1.952 onken 6152: border-right: solid 1px $font;
1.721 harmsja 6153: }
1.795 www 6154:
1.847 tempelho 6155: ul.LC_TabContent .right {
1.911 bisitz 6156: float:right;
1.847 tempelho 6157: }
6158:
1.911 bisitz 6159: ul.LC_TabContent li a,
6160: ul.LC_TabContent li {
6161: color:rgb(47,47,47);
6162: text-decoration:none;
6163: font-size:95%;
6164: font-weight:bold;
1.952 onken 6165: min-height:20px;
6166: }
6167:
1.959 onken 6168: ul.LC_TabContent li a:hover,
6169: ul.LC_TabContent li a:focus {
1.952 onken 6170: color: $button_hover;
1.959 onken 6171: background:none;
6172: outline:none;
1.952 onken 6173: }
6174:
6175: ul.LC_TabContent li:hover {
6176: color: $button_hover;
6177: cursor:pointer;
1.721 harmsja 6178: }
1.795 www 6179:
1.911 bisitz 6180: ul.LC_TabContent li.active {
1.952 onken 6181: color: $font;
1.911 bisitz 6182: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6183: border-bottom:solid 1px #FFFFFF;
6184: cursor: default;
1.744 ehlerst 6185: }
1.795 www 6186:
1.959 onken 6187: ul.LC_TabContent li.active a {
6188: color:$font;
6189: background:#FFFFFF;
6190: outline: none;
6191: }
1.870 tempelho 6192: #maincoursedoc {
1.911 bisitz 6193: clear:both;
1.870 tempelho 6194: }
6195:
6196: ul.LC_TabContentBigger {
1.911 bisitz 6197: display:block;
6198: list-style:none;
6199: padding: 0;
1.870 tempelho 6200: }
6201:
1.795 www 6202: ul.LC_TabContentBigger li {
1.911 bisitz 6203: vertical-align:bottom;
6204: height: 30px;
6205: font-size:110%;
6206: font-weight:bold;
6207: color: #737373;
1.841 tempelho 6208: }
6209:
1.957 onken 6210: ul.LC_TabContentBigger li.active {
6211: position: relative;
6212: top: 1px;
6213: }
6214:
1.870 tempelho 6215: ul.LC_TabContentBigger li a {
1.911 bisitz 6216: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6217: height: 30px;
6218: line-height: 30px;
6219: text-align: center;
6220: display: block;
6221: text-decoration: none;
1.958 onken 6222: outline: none;
1.741 harmsja 6223: }
1.795 www 6224:
1.870 tempelho 6225: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6226: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6227: color:$font;
1.744 ehlerst 6228: }
1.795 www 6229:
1.870 tempelho 6230: ul.LC_TabContentBigger li b {
1.911 bisitz 6231: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6232: display: block;
6233: float: left;
6234: padding: 0 30px;
1.957 onken 6235: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6236: }
6237:
1.956 onken 6238: ul.LC_TabContentBigger li:hover b {
6239: color:$button_hover;
6240: }
6241:
1.870 tempelho 6242: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6243: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6244: color:$font;
1.957 onken 6245: border: 0;
1.956 onken 6246: cursor:default;
1.741 harmsja 6247: }
1.693 droeschl 6248:
1.870 tempelho 6249:
1.862 bisitz 6250: ul.LC_CourseBreadcrumbs {
6251: background: $sidebg;
6252: line-height: 32px;
6253: padding-left: 10px;
6254: margin: 0 0 10px 0;
6255: list-style-position: inside;
6256:
6257: }
6258:
1.911 bisitz 6259: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6260: ol#LC_PathBreadcrumbs {
1.911 bisitz 6261: padding-left: 10px;
6262: margin: 0;
1.933 droeschl 6263: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6264: }
6265:
1.911 bisitz 6266: ol#LC_MenuBreadcrumbs li,
6267: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6268: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6269: display: inline;
1.933 droeschl 6270: white-space: normal;
1.693 droeschl 6271: }
6272:
1.823 bisitz 6273: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6274: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6275: text-decoration: none;
6276: font-size:90%;
1.693 droeschl 6277: }
1.795 www 6278:
1.969 droeschl 6279: ol#LC_MenuBreadcrumbs h1 {
6280: display: inline;
6281: font-size: 90%;
6282: line-height: 2.5em;
6283: margin: 0;
6284: padding: 0;
6285: }
6286:
1.795 www 6287: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6288: text-decoration:none;
6289: font-size:100%;
6290: font-weight:bold;
1.693 droeschl 6291: }
1.795 www 6292:
1.840 bisitz 6293: .LC_Box {
1.911 bisitz 6294: border: solid 1px $lg_border_color;
6295: padding: 0 10px 10px 10px;
1.746 neumanie 6296: }
1.795 www 6297:
6298: .LC_AboutMe_Image {
1.911 bisitz 6299: float:left;
6300: margin-right:10px;
1.747 neumanie 6301: }
1.795 www 6302:
6303: .LC_Clear_AboutMe_Image {
1.911 bisitz 6304: clear:left;
1.747 neumanie 6305: }
1.795 www 6306:
1.721 harmsja 6307: dl.LC_ListStyleClean dt {
1.911 bisitz 6308: padding-right: 5px;
6309: display: table-header-group;
1.693 droeschl 6310: }
6311:
1.721 harmsja 6312: dl.LC_ListStyleClean dd {
1.911 bisitz 6313: display: table-row;
1.693 droeschl 6314: }
6315:
1.721 harmsja 6316: .LC_ListStyleClean,
6317: .LC_ListStyleSimple,
6318: .LC_ListStyleNormal,
1.795 www 6319: .LC_ListStyleSpecial {
1.911 bisitz 6320: /* display:block; */
6321: list-style-position: inside;
6322: list-style-type: none;
6323: overflow: hidden;
6324: padding: 0;
1.693 droeschl 6325: }
6326:
1.721 harmsja 6327: .LC_ListStyleSimple li,
6328: .LC_ListStyleSimple dd,
6329: .LC_ListStyleNormal li,
6330: .LC_ListStyleNormal dd,
6331: .LC_ListStyleSpecial li,
1.795 www 6332: .LC_ListStyleSpecial dd {
1.911 bisitz 6333: margin: 0;
6334: padding: 5px 5px 5px 10px;
6335: clear: both;
1.693 droeschl 6336: }
6337:
1.721 harmsja 6338: .LC_ListStyleClean li,
6339: .LC_ListStyleClean dd {
1.911 bisitz 6340: padding-top: 0;
6341: padding-bottom: 0;
1.693 droeschl 6342: }
6343:
1.721 harmsja 6344: .LC_ListStyleSimple dd,
1.795 www 6345: .LC_ListStyleSimple li {
1.911 bisitz 6346: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6347: }
6348:
1.721 harmsja 6349: .LC_ListStyleSpecial li,
6350: .LC_ListStyleSpecial dd {
1.911 bisitz 6351: list-style-type: none;
6352: background-color: RGB(220, 220, 220);
6353: margin-bottom: 4px;
1.693 droeschl 6354: }
6355:
1.721 harmsja 6356: table.LC_SimpleTable {
1.911 bisitz 6357: margin:5px;
6358: border:solid 1px $lg_border_color;
1.795 www 6359: }
1.693 droeschl 6360:
1.721 harmsja 6361: table.LC_SimpleTable tr {
1.911 bisitz 6362: padding: 0;
6363: border:solid 1px $lg_border_color;
1.693 droeschl 6364: }
1.795 www 6365:
6366: table.LC_SimpleTable thead {
1.911 bisitz 6367: background:rgb(220,220,220);
1.693 droeschl 6368: }
6369:
1.721 harmsja 6370: div.LC_columnSection {
1.911 bisitz 6371: display: block;
6372: clear: both;
6373: overflow: hidden;
6374: margin: 0;
1.693 droeschl 6375: }
6376:
1.721 harmsja 6377: div.LC_columnSection>* {
1.911 bisitz 6378: float: left;
6379: margin: 10px 20px 10px 0;
6380: overflow:hidden;
1.693 droeschl 6381: }
1.721 harmsja 6382:
1.795 www 6383: table em {
1.911 bisitz 6384: font-weight: bold;
6385: font-style: normal;
1.748 schulted 6386: }
1.795 www 6387:
1.779 bisitz 6388: table.LC_tableBrowseRes,
1.795 www 6389: table.LC_tableOfContent {
1.911 bisitz 6390: border:none;
6391: border-spacing: 1px;
6392: padding: 3px;
6393: background-color: #FFFFFF;
6394: font-size: 90%;
1.753 droeschl 6395: }
1.789 droeschl 6396:
1.911 bisitz 6397: table.LC_tableOfContent {
6398: border-collapse: collapse;
1.789 droeschl 6399: }
6400:
1.771 droeschl 6401: table.LC_tableBrowseRes a,
1.768 schulted 6402: table.LC_tableOfContent a {
1.911 bisitz 6403: background-color: transparent;
6404: text-decoration: none;
1.753 droeschl 6405: }
6406:
1.795 www 6407: table.LC_tableOfContent img {
1.911 bisitz 6408: border: none;
6409: height: 1.3em;
6410: vertical-align: text-bottom;
6411: margin-right: 0.3em;
1.753 droeschl 6412: }
1.757 schulted 6413:
1.795 www 6414: a#LC_content_toolbar_firsthomework {
1.911 bisitz 6415: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 6416: }
6417:
1.795 www 6418: a#LC_content_toolbar_everything {
1.911 bisitz 6419: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 6420: }
6421:
1.795 www 6422: a#LC_content_toolbar_uncompleted {
1.911 bisitz 6423: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 6424: }
6425:
1.795 www 6426: #LC_content_toolbar_clearbubbles {
1.911 bisitz 6427: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 6428: }
6429:
1.795 www 6430: a#LC_content_toolbar_changefolder {
1.911 bisitz 6431: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 6432: }
6433:
1.795 www 6434: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 6435: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 6436: }
6437:
1.795 www 6438: ul#LC_toolbar li a:hover {
1.911 bisitz 6439: background-position: bottom center;
1.757 schulted 6440: }
6441:
1.795 www 6442: ul#LC_toolbar {
1.911 bisitz 6443: padding: 0;
6444: margin: 2px;
6445: list-style:none;
6446: position:relative;
6447: background-color:white;
1.757 schulted 6448: }
6449:
1.795 www 6450: ul#LC_toolbar li {
1.911 bisitz 6451: border:1px solid white;
6452: padding: 0;
6453: margin: 0;
6454: float: left;
6455: display:inline;
6456: vertical-align:middle;
6457: }
1.757 schulted 6458:
1.783 amueller 6459:
1.795 www 6460: a.LC_toolbarItem {
1.911 bisitz 6461: display:block;
6462: padding: 0;
6463: margin: 0;
6464: height: 32px;
6465: width: 32px;
6466: color:white;
6467: border: none;
6468: background-repeat:no-repeat;
6469: background-color:transparent;
1.757 schulted 6470: }
6471:
1.915 droeschl 6472: ul.LC_funclist {
6473: margin: 0;
6474: padding: 0.5em 1em 0.5em 0;
6475: }
6476:
1.933 droeschl 6477: ul.LC_funclist > li:first-child {
6478: font-weight:bold;
6479: margin-left:0.8em;
6480: }
6481:
1.915 droeschl 6482: ul.LC_funclist + ul.LC_funclist {
6483: /*
6484: left border as a seperator if we have more than
6485: one list
6486: */
6487: border-left: 1px solid $sidebg;
6488: /*
6489: this hides the left border behind the border of the
6490: outer box if element is wrapped to the next 'line'
6491: */
6492: margin-left: -1px;
6493: }
6494:
1.843 bisitz 6495: ul.LC_funclist li {
1.915 droeschl 6496: display: inline;
1.782 bisitz 6497: white-space: nowrap;
1.915 droeschl 6498: margin: 0 0 0 25px;
6499: line-height: 150%;
1.782 bisitz 6500: }
6501:
1.930 faziophi 6502: .ui-accordion .LC_advanced_toggle {
6503: float: right;
6504: font-size: 90%;
6505: padding: 0px 4px
6506: }
1.757 schulted 6507:
1.974 wenzelju 6508: .LC_hidden {
6509: display: none;
6510: }
6511:
1.343 albertel 6512: END
6513: }
6514:
1.306 albertel 6515: =pod
6516:
6517: =item * &headtag()
6518:
6519: Returns a uniform footer for LON-CAPA web pages.
6520:
1.307 albertel 6521: Inputs: $title - optional title for the head
6522: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 6523: $args - optional arguments
1.319 albertel 6524: force_register - if is true call registerurl so the remote is
6525: informed
1.415 albertel 6526: redirect -> array ref of
6527: 1- seconds before redirect occurs
6528: 2- url to redirect to
6529: 3- whether the side effect should occur
1.315 albertel 6530: (side effect of setting
6531: $env{'internal.head.redirect'} to the url
6532: redirected too)
1.352 albertel 6533: domain -> force to color decorate a page for a specific
6534: domain
6535: function -> force usage of a specific rolish color scheme
6536: bgcolor -> override the default page bgcolor
1.460 albertel 6537: no_auto_mt_title
6538: -> prevent &mt()ing the title arg
1.464 albertel 6539:
1.306 albertel 6540: =cut
6541:
6542: sub headtag {
1.313 albertel 6543: my ($title,$head_extra,$args) = @_;
1.306 albertel 6544:
1.363 albertel 6545: my $function = $args->{'function'} || &get_users_function();
6546: my $domain = $args->{'domain'} || &determinedomain();
6547: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6548: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6549: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6550: #time(),
1.418 albertel 6551: $env{'environment.color.timestamp'},
1.363 albertel 6552: $function,$domain,$bgcolor);
6553:
1.369 www 6554: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6555:
1.308 albertel 6556: my $result =
6557: '<head>'.
1.461 albertel 6558: &font_settings();
1.319 albertel 6559:
1.461 albertel 6560: if (!$args->{'frameset'}) {
6561: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6562: }
1.962 droeschl 6563: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
6564: $result .= Apache::lonxml::display_title();
1.319 albertel 6565: }
1.436 albertel 6566: if (!$args->{'no_nav_bar'}
6567: && !$args->{'only_body'}
6568: && !$args->{'frameset'}) {
6569: $result .= &help_menu_js();
6570: }
1.319 albertel 6571:
1.314 albertel 6572: if (ref($args->{'redirect'})) {
1.414 albertel 6573: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6574: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6575: if (!$inhibit_continue) {
6576: $env{'internal.head.redirect'} = $url;
6577: }
1.313 albertel 6578: $result.=<<ADDMETA
6579: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6580: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6581: ADDMETA
6582: }
1.306 albertel 6583: if (!defined($title)) {
6584: $title = 'The LearningOnline Network with CAPA';
6585: }
1.460 albertel 6586: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6587: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6588: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6589: .$head_extra;
1.962 droeschl 6590: return $result.'</head>';
1.306 albertel 6591: }
6592:
6593: =pod
6594:
1.340 albertel 6595: =item * &font_settings()
6596:
6597: Returns neccessary <meta> to set the proper encoding
6598:
6599: Inputs: none
6600:
6601: =cut
6602:
6603: sub font_settings {
6604: my $headerstring='';
1.647 www 6605: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6606: $headerstring.=
6607: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6608: }
6609: return $headerstring;
6610: }
6611:
1.341 albertel 6612: =pod
6613:
6614: =item * &xml_begin()
6615:
6616: Returns the needed doctype and <html>
6617:
6618: Inputs: none
6619:
6620: =cut
6621:
6622: sub xml_begin {
6623: my $output='';
6624:
6625: if ($env{'browser.mathml'}) {
6626: $output='<?xml version="1.0"?>'
6627: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6628: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6629:
6630: # .'<!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">] >'
6631: .'<!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">'
6632: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6633: .'xmlns="http://www.w3.org/1999/xhtml">';
6634: } else {
1.849 bisitz 6635: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
6636: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 6637: }
6638: return $output;
6639: }
1.340 albertel 6640:
6641: =pod
6642:
1.306 albertel 6643: =item * &start_page()
6644:
6645: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6646:
1.648 raeburn 6647: Inputs:
6648:
6649: =over 4
6650:
6651: $title - optional title for the page
6652:
6653: $head_extra - optional extra HTML to incude inside the <head>
6654:
6655: $args - additional optional args supported are:
6656:
6657: =over 8
6658:
6659: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6660: arg on
1.814 bisitz 6661: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 6662: add_entries -> additional attributes to add to the <body>
6663: domain -> force to color decorate a page for a
1.317 albertel 6664: specific domain
1.648 raeburn 6665: function -> force usage of a specific rolish color
1.317 albertel 6666: scheme
1.648 raeburn 6667: redirect -> see &headtag()
6668: bgcolor -> override the default page bg color
6669: js_ready -> return a string ready for being used in
1.317 albertel 6670: a javascript writeln
1.648 raeburn 6671: html_encode -> return a string ready for being used in
1.320 albertel 6672: a html attribute
1.648 raeburn 6673: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6674: $forcereg arg
1.648 raeburn 6675: frameset -> if true will start with a <frameset>
1.330 albertel 6676: rather than <body>
1.648 raeburn 6677: skip_phases -> hash ref of
1.338 albertel 6678: head -> skip the <html><head> generation
6679: body -> skip all <body> generation
1.648 raeburn 6680: no_auto_mt_title -> prevent &mt()ing the title arg
6681: inherit_jsmath -> when creating popup window in a page,
6682: should it have jsmath forced on by the
6683: current page
1.867 kalberla 6684: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 6685: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.361 albertel 6686:
1.648 raeburn 6687: =back
1.460 albertel 6688:
1.648 raeburn 6689: =back
1.562 albertel 6690:
1.306 albertel 6691: =cut
6692:
6693: sub start_page {
1.309 albertel 6694: my ($title,$head_extra,$args) = @_;
1.318 albertel 6695: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.964 droeschl 6696: #SD
6697: #I don't see why we copy certain elements of %$args to %head_args
6698: #head args is passed to headtag() and this routine only reads those
6699: #keys that are needed. There doesn't happen any writes or any processing
6700: #of other keys.
6701: #proposal: just pass $args to headtag instead of \%head_args and delete
6702: #marked lines
6703: #<- MARK
1.313 albertel 6704: my %head_args;
1.352 albertel 6705: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6706: 'bgcolor','frameset','no_nav_bar','only_body',
6707: 'no_auto_mt_title') {
1.319 albertel 6708: if (defined($args->{$arg})) {
1.324 raeburn 6709: $head_args{$arg} = $args->{$arg};
1.319 albertel 6710: }
1.313 albertel 6711: }
1.964 droeschl 6712: #MARK ->
1.319 albertel 6713:
1.315 albertel 6714: $env{'internal.start_page'}++;
1.338 albertel 6715: my $result;
1.964 droeschl 6716:
1.338 albertel 6717: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.964 droeschl 6718: $result .=
6719: &xml_begin() . &headtag($title,$head_extra,\%head_args);
6720: #replace prev line by
6721: # &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 6722: }
6723:
6724: if (! exists($args->{'skip_phases'}{'body'}) ) {
6725: if ($args->{'frameset'}) {
6726: my $attr_string = &make_attr_string($args->{'force_register'},
6727: $args->{'add_entries'});
6728: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 6729: } else {
6730: $result .=
6731: &bodytag($title,
6732: $args->{'function'}, $args->{'add_entries'},
6733: $args->{'only_body'}, $args->{'domain'},
6734: $args->{'force_register'}, $args->{'no_nav_bar'},
1.962 droeschl 6735: $args->{'bgcolor'}, $args);
1.831 bisitz 6736: }
1.330 albertel 6737: }
1.338 albertel 6738:
1.315 albertel 6739: if ($args->{'js_ready'}) {
1.713 kaisler 6740: $result = &js_ready($result);
1.315 albertel 6741: }
1.320 albertel 6742: if ($args->{'html_encode'}) {
1.713 kaisler 6743: $result = &html_encode($result);
6744: }
6745:
1.813 bisitz 6746: # Preparation for new and consistent functionlist at top of screen
6747: # if ($args->{'functionlist'}) {
6748: # $result .= &build_functionlist();
6749: #}
6750:
1.964 droeschl 6751: # Don't add anything more if only_body wanted or in const space
6752: return $result if $args->{'only_body'}
6753: || $env{'request.state'} eq 'construct';
1.813 bisitz 6754:
6755: #Breadcrumbs
1.758 kaisler 6756: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6757: &Apache::lonhtmlcommon::clear_breadcrumbs();
6758: #if any br links exists, add them to the breadcrumbs
6759: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6760: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6761: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6762: }
6763: }
6764:
6765: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6766: if(exists($args->{'bread_crumbs_component'})){
6767: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6768: }else{
6769: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6770: }
1.320 albertel 6771: }
1.315 albertel 6772: return $result;
1.306 albertel 6773: }
6774:
6775: sub end_page {
1.315 albertel 6776: my ($args) = @_;
6777: $env{'internal.end_page'}++;
1.330 albertel 6778: my $result;
1.335 albertel 6779: if ($args->{'discussion'}) {
6780: my ($target,$parser);
6781: if (ref($args->{'discussion'})) {
6782: ($target,$parser) =($args->{'discussion'}{'target'},
6783: $args->{'discussion'}{'parser'});
6784: }
6785: $result .= &Apache::lonxml::xmlend($target,$parser);
6786: }
6787:
1.330 albertel 6788: if ($args->{'frameset'}) {
6789: $result .= '</frameset>';
6790: } else {
1.635 raeburn 6791: $result .= &endbodytag($args);
1.330 albertel 6792: }
6793: $result .= "\n</html>";
6794:
1.315 albertel 6795: if ($args->{'js_ready'}) {
1.317 albertel 6796: $result = &js_ready($result);
1.315 albertel 6797: }
1.335 albertel 6798:
1.320 albertel 6799: if ($args->{'html_encode'}) {
6800: $result = &html_encode($result);
6801: }
1.335 albertel 6802:
1.315 albertel 6803: return $result;
6804: }
6805:
1.320 albertel 6806: sub html_encode {
6807: my ($result) = @_;
6808:
1.322 albertel 6809: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6810:
6811: return $result;
6812: }
1.317 albertel 6813: sub js_ready {
6814: my ($result) = @_;
6815:
1.323 albertel 6816: $result =~ s/[\n\r]/ /xmsg;
6817: $result =~ s/\\/\\\\/xmsg;
6818: $result =~ s/'/\\'/xmsg;
1.372 albertel 6819: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6820:
6821: return $result;
6822: }
6823:
1.315 albertel 6824: sub validate_page {
6825: if ( exists($env{'internal.start_page'})
1.316 albertel 6826: && $env{'internal.start_page'} > 1) {
6827: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6828: $env{'internal.start_page'}.' '.
1.316 albertel 6829: $ENV{'request.filename'});
1.315 albertel 6830: }
6831: if ( exists($env{'internal.end_page'})
1.316 albertel 6832: && $env{'internal.end_page'} > 1) {
6833: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6834: $env{'internal.end_page'}.' '.
1.316 albertel 6835: $env{'request.filename'});
1.315 albertel 6836: }
6837: if ( exists($env{'internal.start_page'})
6838: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6839: &Apache::lonnet::logthis('start_page called without end_page '.
6840: $env{'request.filename'});
1.315 albertel 6841: }
6842: if ( ! exists($env{'internal.start_page'})
6843: && exists($env{'internal.end_page'})) {
1.316 albertel 6844: &Apache::lonnet::logthis('end_page called without start_page'.
6845: $env{'request.filename'});
1.315 albertel 6846: }
1.306 albertel 6847: }
1.315 albertel 6848:
1.318 albertel 6849: sub simple_error_page {
6850: my ($r,$title,$msg) = @_;
6851: my $page =
6852: &Apache::loncommon::start_page($title).
6853: &mt($msg).
6854: &Apache::loncommon::end_page();
6855: if (ref($r)) {
6856: $r->print($page);
1.327 albertel 6857: return;
1.318 albertel 6858: }
6859: return $page;
6860: }
1.347 albertel 6861:
6862: {
1.610 albertel 6863: my @row_count;
1.961 onken 6864:
6865: sub start_data_table_count {
6866: unshift(@row_count, 0);
6867: return;
6868: }
6869:
6870: sub end_data_table_count {
6871: shift(@row_count);
6872: return;
6873: }
6874:
1.347 albertel 6875: sub start_data_table {
1.422 albertel 6876: my ($add_class) = @_;
6877: my $css_class = (join(' ','LC_data_table',$add_class));
1.961 onken 6878: &start_data_table_count();
1.422 albertel 6879: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6880: }
6881:
6882: sub end_data_table {
1.961 onken 6883: &end_data_table_count();
1.389 albertel 6884: return '</table>'."\n";;
1.347 albertel 6885: }
6886:
6887: sub start_data_table_row {
1.974 wenzelju 6888: my ($add_class, $id) = @_;
1.610 albertel 6889: $row_count[0]++;
6890: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 6891: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 6892: $id = (' id="'.$id.'"') unless ($id eq '');
6893: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 6894: }
1.471 banghart 6895:
6896: sub continue_data_table_row {
1.974 wenzelju 6897: my ($add_class, $id) = @_;
1.610 albertel 6898: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 6899: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
6900: $id = (' id="'.$id.'"') unless ($id eq '');
6901: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 6902: }
1.347 albertel 6903:
6904: sub end_data_table_row {
1.389 albertel 6905: return '</tr>'."\n";;
1.347 albertel 6906: }
1.367 www 6907:
1.421 albertel 6908: sub start_data_table_empty_row {
1.707 bisitz 6909: # $row_count[0]++;
1.421 albertel 6910: return '<tr class="LC_empty_row" >'."\n";;
6911: }
6912:
6913: sub end_data_table_empty_row {
6914: return '</tr>'."\n";;
6915: }
6916:
1.367 www 6917: sub start_data_table_header_row {
1.389 albertel 6918: return '<tr class="LC_header_row">'."\n";;
1.367 www 6919: }
6920:
6921: sub end_data_table_header_row {
1.389 albertel 6922: return '</tr>'."\n";;
1.367 www 6923: }
1.890 droeschl 6924:
6925: sub data_table_caption {
6926: my $caption = shift;
6927: return "<caption class=\"LC_caption\">$caption</caption>";
6928: }
1.347 albertel 6929: }
6930:
1.548 albertel 6931: =pod
6932:
6933: =item * &inhibit_menu_check($arg)
6934:
6935: Checks for a inhibitmenu state and generates output to preserve it
6936:
6937: Inputs: $arg - can be any of
6938: - undef - in which case the return value is a string
6939: to add into arguments list of a uri
6940: - 'input' - in which case the return value is a HTML
6941: <form> <input> field of type hidden to
6942: preserve the value
6943: - a url - in which case the return value is the url with
6944: the neccesary cgi args added to preserve the
6945: inhibitmenu state
6946: - a ref to a url - no return value, but the string is
6947: updated to include the neccessary cgi
6948: args to preserve the inhibitmenu state
6949:
6950: =cut
6951:
6952: sub inhibit_menu_check {
6953: my ($arg) = @_;
6954: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6955: if ($arg eq 'input') {
6956: if ($env{'form.inhibitmenu'}) {
6957: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6958: } else {
6959: return
6960: }
6961: }
6962: if ($env{'form.inhibitmenu'}) {
6963: if (ref($arg)) {
6964: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6965: } elsif ($arg eq '') {
6966: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6967: } else {
6968: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6969: }
6970: }
6971: if (!ref($arg)) {
6972: return $arg;
6973: }
6974: }
6975:
1.251 albertel 6976: ###############################################
1.182 matthew 6977:
6978: =pod
6979:
1.549 albertel 6980: =back
6981:
6982: =head1 User Information Routines
6983:
6984: =over 4
6985:
1.405 albertel 6986: =item * &get_users_function()
1.182 matthew 6987:
6988: Used by &bodytag to determine the current users primary role.
6989: Returns either 'student','coordinator','admin', or 'author'.
6990:
6991: =cut
6992:
6993: ###############################################
6994: sub get_users_function {
1.815 tempelho 6995: my $function = 'norole';
1.818 tempelho 6996: if ($env{'request.role'}=~/^(st)/) {
6997: $function='student';
6998: }
1.907 raeburn 6999: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 7000: $function='coordinator';
7001: }
1.258 albertel 7002: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 7003: $function='admin';
7004: }
1.826 bisitz 7005: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 7006: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
7007: $function='author';
7008: }
7009: return $function;
1.54 www 7010: }
1.99 www 7011:
7012: ###############################################
7013:
1.233 raeburn 7014: =pod
7015:
1.821 raeburn 7016: =item * &show_course()
7017:
7018: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
7019: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
7020:
7021: Inputs:
7022: None
7023:
7024: Outputs:
7025: Scalar: 1 if 'Course' to be used, 0 otherwise.
7026:
7027: =cut
7028:
7029: ###############################################
7030: sub show_course {
7031: my $course = !$env{'user.adv'};
7032: if (!$env{'user.adv'}) {
7033: foreach my $env (keys(%env)) {
7034: next if ($env !~ m/^user\.priv\./);
7035: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
7036: $course = 0;
7037: last;
7038: }
7039: }
7040: }
7041: return $course;
7042: }
7043:
7044: ###############################################
7045:
7046: =pod
7047:
1.542 raeburn 7048: =item * &check_user_status()
1.274 raeburn 7049:
7050: Determines current status of supplied role for a
7051: specific user. Roles can be active, previous or future.
7052:
7053: Inputs:
7054: user's domain, user's username, course's domain,
1.375 raeburn 7055: course's number, optional section ID.
1.274 raeburn 7056:
7057: Outputs:
7058: role status: active, previous or future.
7059:
7060: =cut
7061:
7062: sub check_user_status {
1.412 raeburn 7063: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.982 raeburn 7064: my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
7065: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274 raeburn 7066: my @uroles = keys %userinfo;
7067: my $srchstr;
7068: my $active_chk = 'none';
1.412 raeburn 7069: my $now = time;
1.274 raeburn 7070: if (@uroles > 0) {
1.908 raeburn 7071: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 7072: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
7073: } else {
1.412 raeburn 7074: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
7075: }
7076: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 7077: my $role_end = 0;
7078: my $role_start = 0;
7079: $active_chk = 'active';
1.412 raeburn 7080: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
7081: $role_end = $1;
7082: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
7083: $role_start = $1;
1.274 raeburn 7084: }
7085: }
7086: if ($role_start > 0) {
1.412 raeburn 7087: if ($now < $role_start) {
1.274 raeburn 7088: $active_chk = 'future';
7089: }
7090: }
7091: if ($role_end > 0) {
1.412 raeburn 7092: if ($now > $role_end) {
1.274 raeburn 7093: $active_chk = 'previous';
7094: }
7095: }
7096: }
7097: }
7098: return $active_chk;
7099: }
7100:
7101: ###############################################
7102:
7103: =pod
7104:
1.405 albertel 7105: =item * &get_sections()
1.233 raeburn 7106:
7107: Determines all the sections for a course including
7108: sections with students and sections containing other roles.
1.419 raeburn 7109: Incoming parameters:
7110:
7111: 1. domain
7112: 2. course number
7113: 3. reference to array containing roles for which sections should
7114: be gathered (optional).
7115: 4. reference to array containing status types for which sections
7116: should be gathered (optional).
7117:
7118: If the third argument is undefined, sections are gathered for any role.
7119: If the fourth argument is undefined, sections are gathered for any status.
7120: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 7121:
1.374 raeburn 7122: Returns section hash (keys are section IDs, values are
7123: number of users in each section), subject to the
1.419 raeburn 7124: optional roles filter, optional status filter
1.233 raeburn 7125:
7126: =cut
7127:
7128: ###############################################
7129: sub get_sections {
1.419 raeburn 7130: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 7131: if (!defined($cdom) || !defined($cnum)) {
7132: my $cid = $env{'request.course.id'};
7133:
7134: return if (!defined($cid));
7135:
7136: $cdom = $env{'course.'.$cid.'.domain'};
7137: $cnum = $env{'course.'.$cid.'.num'};
7138: }
7139:
7140: my %sectioncount;
1.419 raeburn 7141: my $now = time;
1.240 albertel 7142:
1.366 albertel 7143: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 7144: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 7145: my $sec_index = &Apache::loncoursedata::CL_SECTION();
7146: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 7147: my $start_index = &Apache::loncoursedata::CL_START();
7148: my $end_index = &Apache::loncoursedata::CL_END();
7149: my $status;
1.366 albertel 7150: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 7151: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
7152: $data->[$status_index],
7153: $data->[$start_index],
7154: $data->[$end_index]);
7155: if ($stu_status eq 'Active') {
7156: $status = 'active';
7157: } elsif ($end < $now) {
7158: $status = 'previous';
7159: } elsif ($start > $now) {
7160: $status = 'future';
7161: }
7162: if ($section ne '-1' && $section !~ /^\s*$/) {
7163: if ((!defined($possible_status)) || (($status ne '') &&
7164: (grep/^\Q$status\E$/,@{$possible_status}))) {
7165: $sectioncount{$section}++;
7166: }
1.240 albertel 7167: }
7168: }
7169: }
7170: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7171: foreach my $user (sort(keys(%courseroles))) {
7172: if ($user !~ /^(\w{2})/) { next; }
7173: my ($role) = ($user =~ /^(\w{2})/);
7174: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 7175: my ($section,$status);
1.240 albertel 7176: if ($role eq 'cr' &&
7177: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
7178: $section=$1;
7179: }
7180: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
7181: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 7182: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
7183: if ($end == -1 && $start == -1) {
7184: next; #deleted role
7185: }
7186: if (!defined($possible_status)) {
7187: $sectioncount{$section}++;
7188: } else {
7189: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
7190: $status = 'active';
7191: } elsif ($end < $now) {
7192: $status = 'future';
7193: } elsif ($start > $now) {
7194: $status = 'previous';
7195: }
7196: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
7197: $sectioncount{$section}++;
7198: }
7199: }
1.233 raeburn 7200: }
1.366 albertel 7201: return %sectioncount;
1.233 raeburn 7202: }
7203:
1.274 raeburn 7204: ###############################################
1.294 raeburn 7205:
7206: =pod
1.405 albertel 7207:
7208: =item * &get_course_users()
7209:
1.275 raeburn 7210: Retrieves usernames:domains for users in the specified course
7211: with specific role(s), and access status.
7212:
7213: Incoming parameters:
1.277 albertel 7214: 1. course domain
7215: 2. course number
7216: 3. access status: users must have - either active,
1.275 raeburn 7217: previous, future, or all.
1.277 albertel 7218: 4. reference to array of permissible roles
1.288 raeburn 7219: 5. reference to array of section restrictions (optional)
7220: 6. reference to results object (hash of hashes).
7221: 7. reference to optional userdata hash
1.609 raeburn 7222: 8. reference to optional statushash
1.630 raeburn 7223: 9. flag if privileged users (except those set to unhide in
7224: course settings) should be excluded
1.609 raeburn 7225: Keys of top level results hash are roles.
1.275 raeburn 7226: Keys of inner hashes are username:domain, with
7227: values set to access type.
1.288 raeburn 7228: Optional userdata hash returns an array with arguments in the
7229: same order as loncoursedata::get_classlist() for student data.
7230:
1.609 raeburn 7231: Optional statushash returns
7232:
1.288 raeburn 7233: Entries for end, start, section and status are blank because
7234: of the possibility of multiple values for non-student roles.
7235:
1.275 raeburn 7236: =cut
1.405 albertel 7237:
1.275 raeburn 7238: ###############################################
1.405 albertel 7239:
1.275 raeburn 7240: sub get_course_users {
1.630 raeburn 7241: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 7242: my %idx = ();
1.419 raeburn 7243: my %seclists;
1.288 raeburn 7244:
7245: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
7246: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
7247: $idx{end} = &Apache::loncoursedata::CL_END();
7248: $idx{start} = &Apache::loncoursedata::CL_START();
7249: $idx{id} = &Apache::loncoursedata::CL_ID();
7250: $idx{section} = &Apache::loncoursedata::CL_SECTION();
7251: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
7252: $idx{status} = &Apache::loncoursedata::CL_STATUS();
7253:
1.290 albertel 7254: if (grep(/^st$/,@{$roles})) {
1.276 albertel 7255: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 7256: my $now = time;
1.277 albertel 7257: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 7258: my $match = 0;
1.412 raeburn 7259: my $secmatch = 0;
1.419 raeburn 7260: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 7261: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 7262: if ($section eq '') {
7263: $section = 'none';
7264: }
1.291 albertel 7265: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7266: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7267: $secmatch = 1;
7268: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 7269: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7270: $secmatch = 1;
7271: }
7272: } else {
1.419 raeburn 7273: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 7274: $secmatch = 1;
7275: }
1.290 albertel 7276: }
1.412 raeburn 7277: if (!$secmatch) {
7278: next;
7279: }
1.419 raeburn 7280: }
1.275 raeburn 7281: if (defined($$types{'active'})) {
1.288 raeburn 7282: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 7283: push(@{$$users{st}{$student}},'active');
1.288 raeburn 7284: $match = 1;
1.275 raeburn 7285: }
7286: }
7287: if (defined($$types{'previous'})) {
1.609 raeburn 7288: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 7289: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 7290: $match = 1;
1.275 raeburn 7291: }
7292: }
7293: if (defined($$types{'future'})) {
1.609 raeburn 7294: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 7295: push(@{$$users{st}{$student}},'future');
1.288 raeburn 7296: $match = 1;
1.275 raeburn 7297: }
7298: }
1.609 raeburn 7299: if ($match) {
7300: push(@{$seclists{$student}},$section);
7301: if (ref($userdata) eq 'HASH') {
7302: $$userdata{$student} = $$classlist{$student};
7303: }
7304: if (ref($statushash) eq 'HASH') {
7305: $statushash->{$student}{'st'}{$section} = $status;
7306: }
1.288 raeburn 7307: }
1.275 raeburn 7308: }
7309: }
1.412 raeburn 7310: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 7311: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7312: my $now = time;
1.609 raeburn 7313: my %displaystatus = ( previous => 'Expired',
7314: active => 'Active',
7315: future => 'Future',
7316: );
1.630 raeburn 7317: my %nothide;
7318: if ($hidepriv) {
7319: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
7320: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
7321: if ($user !~ /:/) {
7322: $nothide{join(':',split(/[\@]/,$user))}=1;
7323: } else {
7324: $nothide{$user} = 1;
7325: }
7326: }
7327: }
1.439 raeburn 7328: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 7329: my $match = 0;
1.412 raeburn 7330: my $secmatch = 0;
1.439 raeburn 7331: my $status;
1.412 raeburn 7332: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 7333: $user =~ s/:$//;
1.439 raeburn 7334: my ($end,$start) = split(/:/,$coursepersonnel{$person});
7335: if ($end == -1 || $start == -1) {
7336: next;
7337: }
7338: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
7339: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 7340: my ($uname,$udom) = split(/:/,$user);
7341: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 7342: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 7343: $secmatch = 1;
7344: } elsif ($usec eq '') {
1.420 albertel 7345: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 7346: $secmatch = 1;
7347: }
7348: } else {
7349: if (grep(/^\Q$usec\E$/,@{$sections})) {
7350: $secmatch = 1;
7351: }
7352: }
7353: if (!$secmatch) {
7354: next;
7355: }
1.288 raeburn 7356: }
1.419 raeburn 7357: if ($usec eq '') {
7358: $usec = 'none';
7359: }
1.275 raeburn 7360: if ($uname ne '' && $udom ne '') {
1.630 raeburn 7361: if ($hidepriv) {
7362: if ((&Apache::lonnet::privileged($uname,$udom)) &&
7363: (!$nothide{$uname.':'.$udom})) {
7364: next;
7365: }
7366: }
1.503 raeburn 7367: if ($end > 0 && $end < $now) {
1.439 raeburn 7368: $status = 'previous';
7369: } elsif ($start > $now) {
7370: $status = 'future';
7371: } else {
7372: $status = 'active';
7373: }
1.277 albertel 7374: foreach my $type (keys(%{$types})) {
1.275 raeburn 7375: if ($status eq $type) {
1.420 albertel 7376: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 7377: push(@{$$users{$role}{$user}},$type);
7378: }
1.288 raeburn 7379: $match = 1;
7380: }
7381: }
1.419 raeburn 7382: if (($match) && (ref($userdata) eq 'HASH')) {
7383: if (!exists($$userdata{$uname.':'.$udom})) {
7384: &get_user_info($udom,$uname,\%idx,$userdata);
7385: }
1.420 albertel 7386: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 7387: push(@{$seclists{$uname.':'.$udom}},$usec);
7388: }
1.609 raeburn 7389: if (ref($statushash) eq 'HASH') {
7390: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
7391: }
1.275 raeburn 7392: }
7393: }
7394: }
7395: }
1.290 albertel 7396: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 7397: if ((defined($cdom)) && (defined($cnum))) {
7398: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
7399: if ( defined($csettings{'internal.courseowner'}) ) {
7400: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 7401: next if ($owner eq '');
7402: my ($ownername,$ownerdom);
7403: if ($owner =~ /^([^:]+):([^:]+)$/) {
7404: $ownername = $1;
7405: $ownerdom = $2;
7406: } else {
7407: $ownername = $owner;
7408: $ownerdom = $cdom;
7409: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 7410: }
7411: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 7412: if (defined($userdata) &&
1.609 raeburn 7413: !exists($$userdata{$owner})) {
7414: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
7415: if (!grep(/^none$/,@{$seclists{$owner}})) {
7416: push(@{$seclists{$owner}},'none');
7417: }
7418: if (ref($statushash) eq 'HASH') {
7419: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 7420: }
1.290 albertel 7421: }
1.279 raeburn 7422: }
7423: }
7424: }
1.419 raeburn 7425: foreach my $user (keys(%seclists)) {
7426: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
7427: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
7428: }
1.275 raeburn 7429: }
7430: return;
7431: }
7432:
1.288 raeburn 7433: sub get_user_info {
7434: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 7435: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
7436: &plainname($uname,$udom,'lastname');
1.291 albertel 7437: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 7438: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 7439: my %idhash = &Apache::lonnet::idrget($udom,($uname));
7440: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 7441: return;
7442: }
1.275 raeburn 7443:
1.472 raeburn 7444: ###############################################
7445:
7446: =pod
7447:
7448: =item * &get_user_quota()
7449:
7450: Retrieves quota assigned for storage of portfolio files for a user
7451:
7452: Incoming parameters:
7453: 1. user's username
7454: 2. user's domain
7455:
7456: Returns:
1.536 raeburn 7457: 1. Disk quota (in Mb) assigned to student.
7458: 2. (Optional) Type of setting: custom or default
7459: (individually assigned or default for user's
7460: institutional status).
7461: 3. (Optional) - User's institutional status (e.g., faculty, staff
7462: or student - types as defined in localenroll::inst_usertypes
7463: for user's domain, which determines default quota for user.
7464: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 7465:
7466: If a value has been stored in the user's environment,
1.536 raeburn 7467: it will return that, otherwise it returns the maximal default
7468: defined for the user's instituional status(es) in the domain.
1.472 raeburn 7469:
7470: =cut
7471:
7472: ###############################################
7473:
7474:
7475: sub get_user_quota {
7476: my ($uname,$udom) = @_;
1.536 raeburn 7477: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 7478: if (!defined($udom)) {
7479: $udom = $env{'user.domain'};
7480: }
7481: if (!defined($uname)) {
7482: $uname = $env{'user.name'};
7483: }
7484: if (($udom eq '' || $uname eq '') ||
7485: ($udom eq 'public') && ($uname eq 'public')) {
7486: $quota = 0;
1.536 raeburn 7487: $quotatype = 'default';
7488: $defquota = 0;
1.472 raeburn 7489: } else {
1.536 raeburn 7490: my $inststatus;
1.472 raeburn 7491: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
7492: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 7493: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 7494: } else {
1.536 raeburn 7495: my %userenv =
7496: &Apache::lonnet::get('environment',['portfolioquota',
7497: 'inststatus'],$udom,$uname);
1.472 raeburn 7498: my ($tmp) = keys(%userenv);
7499: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
7500: $quota = $userenv{'portfolioquota'};
1.536 raeburn 7501: $inststatus = $userenv{'inststatus'};
1.472 raeburn 7502: } else {
7503: undef(%userenv);
7504: }
7505: }
1.536 raeburn 7506: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 7507: if ($quota eq '') {
1.536 raeburn 7508: $quota = $defquota;
7509: $quotatype = 'default';
7510: } else {
7511: $quotatype = 'custom';
1.472 raeburn 7512: }
7513: }
1.536 raeburn 7514: if (wantarray) {
7515: return ($quota,$quotatype,$settingstatus,$defquota);
7516: } else {
7517: return $quota;
7518: }
1.472 raeburn 7519: }
7520:
7521: ###############################################
7522:
7523: =pod
7524:
7525: =item * &default_quota()
7526:
1.536 raeburn 7527: Retrieves default quota assigned for storage of user portfolio files,
7528: given an (optional) user's institutional status.
1.472 raeburn 7529:
7530: Incoming parameters:
7531: 1. domain
1.536 raeburn 7532: 2. (Optional) institutional status(es). This is a : separated list of
7533: status types (e.g., faculty, staff, student etc.)
7534: which apply to the user for whom the default is being retrieved.
7535: If the institutional status string in undefined, the domain
7536: default quota will be returned.
1.472 raeburn 7537:
7538: Returns:
7539: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7540: 2. (Optional) institutional type which determined the value of the
7541: default quota.
1.472 raeburn 7542:
7543: If a value has been stored in the domain's configuration db,
7544: it will return that, otherwise it returns 20 (for backwards
7545: compatibility with domains which have not set up a configuration
7546: db file; the original statically defined portfolio quota was 20 Mb).
7547:
1.536 raeburn 7548: If the user's status includes multiple types (e.g., staff and student),
7549: the largest default quota which applies to the user determines the
7550: default quota returned.
7551:
1.780 raeburn 7552: =back
7553:
1.472 raeburn 7554: =cut
7555:
7556: ###############################################
7557:
7558:
7559: sub default_quota {
1.536 raeburn 7560: my ($udom,$inststatus) = @_;
7561: my ($defquota,$settingstatus);
7562: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7563: ['quotas'],$udom);
7564: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7565: if ($inststatus ne '') {
1.765 raeburn 7566: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 7567: foreach my $item (@statuses) {
1.711 raeburn 7568: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7569: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7570: if ($defquota eq '') {
7571: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7572: $settingstatus = $item;
7573: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7574: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7575: $settingstatus = $item;
7576: }
7577: }
7578: } else {
7579: if ($quotahash{'quotas'}{$item} ne '') {
7580: if ($defquota eq '') {
7581: $defquota = $quotahash{'quotas'}{$item};
7582: $settingstatus = $item;
7583: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7584: $defquota = $quotahash{'quotas'}{$item};
7585: $settingstatus = $item;
7586: }
1.536 raeburn 7587: }
7588: }
7589: }
7590: }
7591: if ($defquota eq '') {
1.711 raeburn 7592: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7593: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7594: } else {
7595: $defquota = $quotahash{'quotas'}{'default'};
7596: }
1.536 raeburn 7597: $settingstatus = 'default';
7598: }
7599: } else {
7600: $settingstatus = 'default';
7601: $defquota = 20;
7602: }
7603: if (wantarray) {
7604: return ($defquota,$settingstatus);
1.472 raeburn 7605: } else {
1.536 raeburn 7606: return $defquota;
1.472 raeburn 7607: }
7608: }
7609:
1.384 raeburn 7610: sub get_secgrprole_info {
7611: my ($cdom,$cnum,$needroles,$type) = @_;
7612: my %sections_count = &get_sections($cdom,$cnum);
7613: my @sections = (sort {$a <=> $b} keys(%sections_count));
7614: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7615: my @groups = sort(keys(%curr_groups));
7616: my $allroles = [];
7617: my $rolehash;
7618: my $accesshash = {
7619: active => 'Currently has access',
7620: future => 'Will have future access',
7621: previous => 'Previously had access',
7622: };
7623: if ($needroles) {
7624: $rolehash = {'all' => 'all'};
1.385 albertel 7625: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7626: if (&Apache::lonnet::error(%user_roles)) {
7627: undef(%user_roles);
7628: }
7629: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7630: my ($role)=split(/\:/,$item,2);
7631: if ($role eq 'cr') { next; }
7632: if ($role =~ /^cr/) {
7633: $$rolehash{$role} = (split('/',$role))[3];
7634: } else {
7635: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7636: }
7637: }
7638: foreach my $key (sort(keys(%{$rolehash}))) {
7639: push(@{$allroles},$key);
7640: }
7641: push (@{$allroles},'st');
7642: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7643: }
7644: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7645: }
7646:
1.555 raeburn 7647: sub user_picker {
1.627 raeburn 7648: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7649: my $currdom = $dom;
7650: my %curr_selected = (
7651: srchin => 'dom',
1.580 raeburn 7652: srchby => 'lastname',
1.555 raeburn 7653: );
7654: my $srchterm;
1.625 raeburn 7655: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7656: if ($srch->{'srchby'} ne '') {
7657: $curr_selected{'srchby'} = $srch->{'srchby'};
7658: }
7659: if ($srch->{'srchin'} ne '') {
7660: $curr_selected{'srchin'} = $srch->{'srchin'};
7661: }
7662: if ($srch->{'srchtype'} ne '') {
7663: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7664: }
7665: if ($srch->{'srchdomain'} ne '') {
7666: $currdom = $srch->{'srchdomain'};
7667: }
7668: $srchterm = $srch->{'srchterm'};
7669: }
7670: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7671: 'usr' => 'Search criteria',
1.563 raeburn 7672: 'doma' => 'Domain/institution to search',
1.558 albertel 7673: 'uname' => 'username',
7674: 'lastname' => 'last name',
1.555 raeburn 7675: 'lastfirst' => 'last name, first name',
1.558 albertel 7676: 'crs' => 'in this course',
1.576 raeburn 7677: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7678: 'alc' => 'all LON-CAPA',
1.573 raeburn 7679: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7680: 'exact' => 'is',
7681: 'contains' => 'contains',
1.569 raeburn 7682: 'begins' => 'begins with',
1.571 raeburn 7683: 'youm' => "You must include some text to search for.",
7684: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7685: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7686: 'yomc' => "You must choose a domain when using an institutional directory search.",
7687: 'ymcd' => "You must choose a domain when using a domain search.",
7688: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7689: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7690: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7691: );
1.563 raeburn 7692: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7693: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7694:
7695: my @srchins = ('crs','dom','alc','instd');
7696:
7697: foreach my $option (@srchins) {
7698: # FIXME 'alc' option unavailable until
7699: # loncreateuser::print_user_query_page()
7700: # has been completed.
7701: next if ($option eq 'alc');
1.880 raeburn 7702: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7703: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7704: if ($curr_selected{'srchin'} eq $option) {
7705: $srchinsel .= '
7706: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7707: } else {
7708: $srchinsel .= '
7709: <option value="'.$option.'">'.$lt{$option}.'</option>';
7710: }
1.555 raeburn 7711: }
1.563 raeburn 7712: $srchinsel .= "\n </select>\n";
1.555 raeburn 7713:
7714: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7715: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7716: if ($curr_selected{'srchby'} eq $option) {
7717: $srchbysel .= '
7718: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7719: } else {
7720: $srchbysel .= '
7721: <option value="'.$option.'">'.$lt{$option}.'</option>';
7722: }
7723: }
7724: $srchbysel .= "\n </select>\n";
7725:
7726: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7727: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7728: if ($curr_selected{'srchtype'} eq $option) {
7729: $srchtypesel .= '
7730: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7731: } else {
7732: $srchtypesel .= '
7733: <option value="'.$option.'">'.$lt{$option}.'</option>';
7734: }
7735: }
7736: $srchtypesel .= "\n </select>\n";
7737:
1.558 albertel 7738: my ($newuserscript,$new_user_create);
1.556 raeburn 7739:
7740: if ($forcenewuser) {
1.576 raeburn 7741: if (ref($srch) eq 'HASH') {
7742: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7743: if ($cancreate) {
7744: $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>';
7745: } else {
1.799 bisitz 7746: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7747: my %usertypetext = (
7748: official => 'institutional',
7749: unofficial => 'non-institutional',
7750: );
1.799 bisitz 7751: $new_user_create = '<p class="LC_warning">'
7752: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
7753: .' '
7754: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
7755: ,'<a href="'.$helplink.'">','</a>')
7756: .'</p><br />';
1.627 raeburn 7757: }
1.576 raeburn 7758: }
7759: }
7760:
1.556 raeburn 7761: $newuserscript = <<"ENDSCRIPT";
7762:
1.570 raeburn 7763: function setSearch(createnew,callingForm) {
1.556 raeburn 7764: if (createnew == 1) {
1.570 raeburn 7765: for (var i=0; i<callingForm.srchby.length; i++) {
7766: if (callingForm.srchby.options[i].value == 'uname') {
7767: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7768: }
7769: }
1.570 raeburn 7770: for (var i=0; i<callingForm.srchin.length; i++) {
7771: if ( callingForm.srchin.options[i].value == 'dom') {
7772: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7773: }
7774: }
1.570 raeburn 7775: for (var i=0; i<callingForm.srchtype.length; i++) {
7776: if (callingForm.srchtype.options[i].value == 'exact') {
7777: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7778: }
7779: }
1.570 raeburn 7780: for (var i=0; i<callingForm.srchdomain.length; i++) {
7781: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7782: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7783: }
7784: }
7785: }
7786: }
7787: ENDSCRIPT
1.558 albertel 7788:
1.556 raeburn 7789: }
7790:
1.555 raeburn 7791: my $output = <<"END_BLOCK";
1.556 raeburn 7792: <script type="text/javascript">
1.824 bisitz 7793: // <![CDATA[
1.570 raeburn 7794: function validateEntry(callingForm) {
1.558 albertel 7795:
1.556 raeburn 7796: var checkok = 1;
1.558 albertel 7797: var srchin;
1.570 raeburn 7798: for (var i=0; i<callingForm.srchin.length; i++) {
7799: if ( callingForm.srchin[i].checked ) {
7800: srchin = callingForm.srchin[i].value;
1.558 albertel 7801: }
7802: }
7803:
1.570 raeburn 7804: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7805: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7806: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7807: var srchterm = callingForm.srchterm.value;
7808: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7809: var msg = "";
7810:
7811: if (srchterm == "") {
7812: checkok = 0;
1.571 raeburn 7813: msg += "$lt{'youm'}\\n";
1.556 raeburn 7814: }
7815:
1.569 raeburn 7816: if (srchtype== 'begins') {
7817: if (srchterm.length < 2) {
7818: checkok = 0;
1.571 raeburn 7819: msg += "$lt{'thte'}\\n";
1.569 raeburn 7820: }
7821: }
7822:
1.556 raeburn 7823: if (srchtype== 'contains') {
7824: if (srchterm.length < 3) {
7825: checkok = 0;
1.571 raeburn 7826: msg += "$lt{'thet'}\\n";
1.556 raeburn 7827: }
7828: }
7829: if (srchin == 'instd') {
7830: if (srchdomain == '') {
7831: checkok = 0;
1.571 raeburn 7832: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7833: }
7834: }
7835: if (srchin == 'dom') {
7836: if (srchdomain == '') {
7837: checkok = 0;
1.571 raeburn 7838: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7839: }
7840: }
7841: if (srchby == 'lastfirst') {
7842: if (srchterm.indexOf(",") == -1) {
7843: checkok = 0;
1.571 raeburn 7844: msg += "$lt{'whus'}\\n";
1.556 raeburn 7845: }
7846: if (srchterm.indexOf(",") == srchterm.length -1) {
7847: checkok = 0;
1.571 raeburn 7848: msg += "$lt{'whse'}\\n";
1.556 raeburn 7849: }
7850: }
7851: if (checkok == 0) {
1.571 raeburn 7852: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7853: return;
7854: }
7855: if (checkok == 1) {
1.570 raeburn 7856: callingForm.submit();
1.556 raeburn 7857: }
7858: }
7859:
7860: $newuserscript
7861:
1.824 bisitz 7862: // ]]>
1.556 raeburn 7863: </script>
1.558 albertel 7864:
7865: $new_user_create
7866:
1.555 raeburn 7867: END_BLOCK
1.558 albertel 7868:
1.876 raeburn 7869: $output .= &Apache::lonhtmlcommon::start_pick_box().
7870: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7871: $domform.
7872: &Apache::lonhtmlcommon::row_closure().
7873: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7874: $srchbysel.
7875: $srchtypesel.
7876: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7877: $srchinsel.
7878: &Apache::lonhtmlcommon::row_closure(1).
7879: &Apache::lonhtmlcommon::end_pick_box().
7880: '<br />';
1.555 raeburn 7881: return $output;
7882: }
7883:
1.612 raeburn 7884: sub user_rule_check {
1.615 raeburn 7885: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7886: my $response;
7887: if (ref($usershash) eq 'HASH') {
7888: foreach my $user (keys(%{$usershash})) {
7889: my ($uname,$udom) = split(/:/,$user);
7890: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7891: my ($id,$newuser);
1.612 raeburn 7892: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7893: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7894: $id = $usershash->{$user}->{'id'};
7895: }
7896: my $inst_response;
7897: if (ref($checks) eq 'HASH') {
7898: if (defined($checks->{'username'})) {
1.615 raeburn 7899: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7900: &Apache::lonnet::get_instuser($udom,$uname);
7901: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7902: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7903: &Apache::lonnet::get_instuser($udom,undef,$id);
7904: }
1.615 raeburn 7905: } else {
7906: ($inst_response,%{$inst_results->{$user}}) =
7907: &Apache::lonnet::get_instuser($udom,$uname);
7908: return;
1.612 raeburn 7909: }
1.615 raeburn 7910: if (!$got_rules->{$udom}) {
1.612 raeburn 7911: my %domconfig = &Apache::lonnet::get_dom('configuration',
7912: ['usercreation'],$udom);
7913: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7914: foreach my $item ('username','id') {
1.612 raeburn 7915: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7916: $$curr_rules{$udom}{$item} =
7917: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7918: }
7919: }
7920: }
1.615 raeburn 7921: $got_rules->{$udom} = 1;
1.585 raeburn 7922: }
1.612 raeburn 7923: foreach my $item (keys(%{$checks})) {
7924: if (ref($$curr_rules{$udom}) eq 'HASH') {
7925: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7926: if (@{$$curr_rules{$udom}{$item}} > 0) {
7927: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7928: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7929: if ($rule_check{$rule}) {
7930: $$rulematch{$user}{$item} = $rule;
7931: if ($inst_response eq 'ok') {
1.615 raeburn 7932: if (ref($inst_results) eq 'HASH') {
7933: if (ref($inst_results->{$user}) eq 'HASH') {
7934: if (keys(%{$inst_results->{$user}}) == 0) {
7935: $$alerts{$item}{$udom}{$uname} = 1;
7936: }
1.612 raeburn 7937: }
7938: }
1.615 raeburn 7939: }
7940: last;
1.585 raeburn 7941: }
7942: }
7943: }
7944: }
7945: }
7946: }
7947: }
7948: }
1.612 raeburn 7949: return;
7950: }
7951:
7952: sub user_rule_formats {
7953: my ($domain,$domdesc,$curr_rules,$check) = @_;
7954: my %text = (
7955: 'username' => 'Usernames',
7956: 'id' => 'IDs',
7957: );
7958: my $output;
7959: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7960: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7961: if (@{$ruleorder} > 0) {
7962: $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>';
7963: foreach my $rule (@{$ruleorder}) {
7964: if (ref($curr_rules) eq 'ARRAY') {
7965: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7966: if (ref($rules->{$rule}) eq 'HASH') {
7967: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7968: $rules->{$rule}{'desc'}.'</li>';
7969: }
7970: }
7971: }
7972: }
7973: $output .= '</ul>';
7974: }
7975: }
7976: return $output;
7977: }
7978:
7979: sub instrule_disallow_msg {
1.615 raeburn 7980: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7981: my $response;
7982: my %text = (
7983: item => 'username',
7984: items => 'usernames',
7985: match => 'matches',
7986: do => 'does',
7987: action => 'a username',
7988: one => 'one',
7989: );
7990: if ($count > 1) {
7991: $text{'item'} = 'usernames';
7992: $text{'match'} ='match';
7993: $text{'do'} = 'do';
7994: $text{'action'} = 'usernames',
7995: $text{'one'} = 'ones';
7996: }
7997: if ($checkitem eq 'id') {
7998: $text{'items'} = 'IDs';
7999: $text{'item'} = 'ID';
8000: $text{'action'} = 'an ID';
1.615 raeburn 8001: if ($count > 1) {
8002: $text{'item'} = 'IDs';
8003: $text{'action'} = 'IDs';
8004: }
1.612 raeburn 8005: }
1.674 bisitz 8006: $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 8007: if ($mode eq 'upload') {
8008: if ($checkitem eq 'username') {
8009: $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'}.");
8010: } elsif ($checkitem eq 'id') {
1.674 bisitz 8011: $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 8012: }
1.669 raeburn 8013: } elsif ($mode eq 'selfcreate') {
8014: if ($checkitem eq 'id') {
8015: $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.");
8016: }
1.615 raeburn 8017: } else {
8018: if ($checkitem eq 'username') {
8019: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
8020: } elsif ($checkitem eq 'id') {
8021: $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.");
8022: }
1.612 raeburn 8023: }
8024: return $response;
1.585 raeburn 8025: }
8026:
1.624 raeburn 8027: sub personal_data_fieldtitles {
8028: my %fieldtitles = &Apache::lonlocal::texthash (
8029: id => 'Student/Employee ID',
8030: permanentemail => 'E-mail address',
8031: lastname => 'Last Name',
8032: firstname => 'First Name',
8033: middlename => 'Middle Name',
8034: generation => 'Generation',
8035: gen => 'Generation',
1.765 raeburn 8036: inststatus => 'Affiliation',
1.624 raeburn 8037: );
8038: return %fieldtitles;
8039: }
8040:
1.642 raeburn 8041: sub sorted_inst_types {
8042: my ($dom) = @_;
8043: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
8044: my $othertitle = &mt('All users');
8045: if ($env{'request.course.id'}) {
1.668 raeburn 8046: $othertitle = &mt('Any users');
1.642 raeburn 8047: }
8048: my @types;
8049: if (ref($order) eq 'ARRAY') {
8050: @types = @{$order};
8051: }
8052: if (@types == 0) {
8053: if (ref($usertypes) eq 'HASH') {
8054: @types = sort(keys(%{$usertypes}));
8055: }
8056: }
8057: if (keys(%{$usertypes}) > 0) {
8058: $othertitle = &mt('Other users');
8059: }
8060: return ($othertitle,$usertypes,\@types);
8061: }
8062:
1.645 raeburn 8063: sub get_institutional_codes {
8064: my ($settings,$allcourses,$LC_code) = @_;
8065: # Get complete list of course sections to update
8066: my @currsections = ();
8067: my @currxlists = ();
8068: my $coursecode = $$settings{'internal.coursecode'};
8069:
8070: if ($$settings{'internal.sectionnums'} ne '') {
8071: @currsections = split(/,/,$$settings{'internal.sectionnums'});
8072: }
8073:
8074: if ($$settings{'internal.crosslistings'} ne '') {
8075: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
8076: }
8077:
8078: if (@currxlists > 0) {
8079: foreach (@currxlists) {
8080: if (m/^([^:]+):(\w*)$/) {
8081: unless (grep/^$1$/,@{$allcourses}) {
8082: push @{$allcourses},$1;
8083: $$LC_code{$1} = $2;
8084: }
8085: }
8086: }
8087: }
8088:
8089: if (@currsections > 0) {
8090: foreach (@currsections) {
8091: if (m/^(\w+):(\w*)$/) {
8092: my $sec = $coursecode.$1;
8093: my $lc_sec = $2;
8094: unless (grep/^$sec$/,@{$allcourses}) {
8095: push @{$allcourses},$sec;
8096: $$LC_code{$sec} = $lc_sec;
8097: }
8098: }
8099: }
8100: }
8101: return;
8102: }
8103:
1.971 raeburn 8104: sub get_standard_codeitems {
8105: return ('Year','Semester','Department','Number','Section');
8106: }
8107:
1.112 bowersj2 8108: =pod
8109:
1.780 raeburn 8110: =head1 Slot Helpers
8111:
8112: =over 4
8113:
8114: =item * sorted_slots()
8115:
8116: Sorts an array of slot names in order of slot start time (earliest first).
8117:
8118: Inputs:
8119:
8120: =over 4
8121:
8122: slotsarr - Reference to array of unsorted slot names.
8123:
8124: slots - Reference to hash of hash, where outer hash keys are slot names.
8125:
1.549 albertel 8126: =back
8127:
1.780 raeburn 8128: Returns:
8129:
8130: =over 4
8131:
8132: sorted - An array of slot names sorted by the start time of the slot.
8133:
8134: =back
8135:
8136: =back
8137:
8138: =cut
8139:
8140:
8141: sub sorted_slots {
8142: my ($slotsarr,$slots) = @_;
8143: my @sorted;
8144: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
8145: @sorted =
8146: sort {
8147: if (ref($slots->{$a}) && ref($slots->{$b})) {
8148: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
8149: }
8150: if (ref($slots->{$a})) { return -1;}
8151: if (ref($slots->{$b})) { return 1;}
8152: return 0;
8153: } @{$slotsarr};
8154: }
8155: return @sorted;
8156: }
8157:
8158:
8159: =pod
8160:
1.549 albertel 8161: =head1 HTTP Helpers
8162:
8163: =over 4
8164:
1.648 raeburn 8165: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 8166:
1.258 albertel 8167: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 8168: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 8169: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 8170:
8171: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
8172: $possible_names is an ref to an array of form element names. As an example:
8173: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 8174: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 8175:
8176: =cut
1.1 albertel 8177:
1.6 albertel 8178: sub get_unprocessed_cgi {
1.25 albertel 8179: my ($query,$possible_names)= @_;
1.26 matthew 8180: # $Apache::lonxml::debug=1;
1.356 albertel 8181: foreach my $pair (split(/&/,$query)) {
8182: my ($name, $value) = split(/=/,$pair);
1.369 www 8183: $name = &unescape($name);
1.25 albertel 8184: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
8185: $value =~ tr/+/ /;
8186: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 8187: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 8188: }
1.16 harris41 8189: }
1.6 albertel 8190: }
8191:
1.112 bowersj2 8192: =pod
8193:
1.648 raeburn 8194: =item * &cacheheader()
1.112 bowersj2 8195:
8196: returns cache-controlling header code
8197:
8198: =cut
8199:
1.7 albertel 8200: sub cacheheader {
1.258 albertel 8201: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 8202: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
8203: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 8204: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
8205: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 8206: return $output;
1.7 albertel 8207: }
8208:
1.112 bowersj2 8209: =pod
8210:
1.648 raeburn 8211: =item * &no_cache($r)
1.112 bowersj2 8212:
8213: specifies header code to not have cache
8214:
8215: =cut
8216:
1.9 albertel 8217: sub no_cache {
1.216 albertel 8218: my ($r) = @_;
8219: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 8220: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 8221: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
8222: $r->no_cache(1);
8223: $r->header_out("Expires" => $date);
8224: $r->header_out("Pragma" => "no-cache");
1.123 www 8225: }
8226:
8227: sub content_type {
1.181 albertel 8228: my ($r,$type,$charset) = @_;
1.299 foxr 8229: if ($r) {
8230: # Note that printout.pl calls this with undef for $r.
8231: &no_cache($r);
8232: }
1.258 albertel 8233: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 8234: unless ($charset) {
8235: $charset=&Apache::lonlocal::current_encoding;
8236: }
8237: if ($charset) { $type.='; charset='.$charset; }
8238: if ($r) {
8239: $r->content_type($type);
8240: } else {
8241: print("Content-type: $type\n\n");
8242: }
1.9 albertel 8243: }
1.25 albertel 8244:
1.112 bowersj2 8245: =pod
8246:
1.648 raeburn 8247: =item * &add_to_env($name,$value)
1.112 bowersj2 8248:
1.258 albertel 8249: adds $name to the %env hash with value
1.112 bowersj2 8250: $value, if $name already exists, the entry is converted to an array
8251: reference and $value is added to the array.
8252:
8253: =cut
8254:
1.25 albertel 8255: sub add_to_env {
8256: my ($name,$value)=@_;
1.258 albertel 8257: if (defined($env{$name})) {
8258: if (ref($env{$name})) {
1.25 albertel 8259: #already have multiple values
1.258 albertel 8260: push(@{ $env{$name} },$value);
1.25 albertel 8261: } else {
8262: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 8263: my $first=$env{$name};
8264: undef($env{$name});
8265: push(@{ $env{$name} },$first,$value);
1.25 albertel 8266: }
8267: } else {
1.258 albertel 8268: $env{$name}=$value;
1.25 albertel 8269: }
1.31 albertel 8270: }
1.149 albertel 8271:
8272: =pod
8273:
1.648 raeburn 8274: =item * &get_env_multiple($name)
1.149 albertel 8275:
1.258 albertel 8276: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 8277: values may be defined and end up as an array ref.
8278:
8279: returns an array of values
8280:
8281: =cut
8282:
8283: sub get_env_multiple {
8284: my ($name) = @_;
8285: my @values;
1.258 albertel 8286: if (defined($env{$name})) {
1.149 albertel 8287: # exists is it an array
1.258 albertel 8288: if (ref($env{$name})) {
8289: @values=@{ $env{$name} };
1.149 albertel 8290: } else {
1.258 albertel 8291: $values[0]=$env{$name};
1.149 albertel 8292: }
8293: }
8294: return(@values);
8295: }
8296:
1.660 raeburn 8297: sub ask_for_embedded_content {
8298: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.984 raeburn 8299: my (%subdependencies,%dependencies,%newfiles);
1.660 raeburn 8300: my $num = 0;
1.984 raeburn 8301: my $upload_output;
8302: foreach my $embed_file (keys(%{$allfiles})) {
8303: unless ($embed_file =~ m{^\w+://} || $embed_file =~ m{^/}) {
8304: my ($relpath,$fname);
8305: if ($embed_file =~ m{/}) {
8306: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
8307: $subdependencies{$path}{$fname} = 1;
8308: } else {
8309: $dependencies{$embed_file} = 1;
8310: }
8311: }
8312: }
8313: my ($url,$udom,$uname,$getpropath);
8314: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8315: my $current_path='/';
8316: if ($env{'form.currentpath'}) {
8317: $current_path = $env{'form.currentpath'};
8318: }
8319: if ($actionurl eq '/adm/coursegrp_portfolio') {
8320: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8321: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
8322: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
8323: } else {
8324: $udom = $env{'user.domain'};
8325: $uname = $env{'user.name'};
8326: $url = '/userfiles/portfolio';
8327: }
8328: $url .= $current_path;
8329: $getpropath = 1;
8330: } elsif ($actionurl eq '/adm/upload') {
8331: ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
8332: $url = '/home/'.$uname.'/public_html';
8333: if ($rest ne '') {
8334: $url .= '/'.$rest;
8335: }
8336: }
8337: foreach my $path (keys(%subdependencies)) {
8338: my %currsubfile;
8339: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8340: my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
8341: foreach my $line (@subdir_list) {
8342: my ($file_name,$rest) = split(/\&/,$line,2);
8343: $currsubfile{$file_name} = 1;
8344: }
8345: } elsif ($actionurl eq '/adm/upload') {
8346: if (opendir(my $dir,$url.'/'.$path)) {
8347: my @subdir_list = grep(!/^\./,readdir($dir));
8348: map {$currsubfile{$_} = 1;} @subdir_list;
8349: }
8350: }
8351: foreach my $file (keys(%{$subdependencies{$path}})) {
8352: unless ($currsubfile{$file}) {
8353: $newfiles{$path.'/'.$file} = 1;
8354: }
8355: }
8356: }
8357: my (@dir_list,%currfile);
8358: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
8359: my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
8360: foreach my $line (@dir_list) {
8361: my ($file_name,$rest) = split(/\&/,$line,2);
8362: $currfile{$file_name} = 1;
8363: }
8364: } elsif ($actionurl eq '/adm/upload') {
8365: if (opendir(my $dir,$url)) {
8366: @dir_list = grep(!/^\./,readdir($dir));
8367: map {$currfile{$_} = 1;} @dir_list;
8368: }
8369: }
8370: foreach my $file (keys(%dependencies)) {
8371: unless ($currfile{$file}) {
8372: $newfiles{$file} = 1;
8373: }
8374: }
8375: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660 raeburn 8376: $upload_output .= &start_data_table_row().
8377: '<td>'.$embed_file.'</td><td>';
8378: if ($args->{'ignore_remote_references'}
8379: && $embed_file =~ m{^\w+://}) {
8380: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
8381: } elsif ($args->{'error_on_invalid_names'}
8382: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
8383:
8384: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
8385:
8386: } else {
8387: $upload_output .='
1.661 raeburn 8388: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 8389: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
8390: my $attrib = join(':',@{$$allfiles{$embed_file}});
8391: $upload_output .=
8392: "\n\t\t".
8393: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
8394: $attrib.'" />';
8395: if (exists($$codebase{$embed_file})) {
8396: $upload_output .=
8397: "\n\t\t".
8398: '<input name="codebase_'.$num.'" type="hidden" value="'.
8399: &escape($$codebase{$embed_file}).'" />';
8400: }
8401: }
1.984 raeburn 8402: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
1.660 raeburn 8403: $num++;
8404: }
1.984 raeburn 8405: if ($num) {
8406: $upload_output = '<form name="upload_embedded" action="'.$actionurl.'"'.
8407: ' method="post" enctype="multipart/form-data">'."\n".
8408: $state.
8409: '<b>Upload embedded files</b>:<br />'.&start_data_table().
8410: $upload_output.
8411: &Apache::loncommon::end_data_table().'<br />'."\n".
8412: '<input type ="hidden" name="number_embedded_items" value="'.$num.'" />'."\n".
8413: '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
8414: &mt('(only files for which a location has been provided will be uploaded)')."\n".
8415: '</form>';
8416: }
1.660 raeburn 8417: return $upload_output;
8418: }
8419:
1.661 raeburn 8420: sub upload_embedded {
8421: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
8422: $current_disk_usage) = @_;
8423: my $output;
8424: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
8425: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
8426: my $orig_uploaded_filename =
8427: $env{'form.embedded_item_'.$i.'.filename'};
8428:
8429: $env{'form.embedded_orig_'.$i} =
8430: &unescape($env{'form.embedded_orig_'.$i});
8431: my ($path,$fname) =
8432: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
8433: # no path, whole string is fname
8434: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
8435:
8436: $path = $env{'form.currentpath'}.$path;
8437: $fname = &Apache::lonnet::clean_filename($fname);
8438: # See if there is anything left
8439: next if ($fname eq '');
8440:
8441: # Check if file already exists as a file or directory.
8442: my ($state,$msg);
8443: if ($context eq 'portfolio') {
8444: my $port_path = $dirpath;
8445: if ($group ne '') {
8446: $port_path = "groups/$group/$port_path";
8447: }
8448: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
8449: $dir_root,$port_path,$disk_quota,
8450: $current_disk_usage,$uname,$udom);
8451: if ($state eq 'will_exceed_quota'
1.984 raeburn 8452: || $state eq 'file_locked') {
1.661 raeburn 8453: $output .= $msg;
8454: next;
8455: }
8456: } elsif (($context eq 'author') || ($context eq 'testbank')) {
8457: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
8458: if ($state eq 'exists') {
8459: $output .= $msg;
8460: next;
8461: }
8462: }
8463: # Check if extension is valid
8464: if (($fname =~ /\.(\w+)$/) &&
8465: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8466: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
8467: next;
8468: } elsif (($fname =~ /\.(\w+)$/) &&
8469: (!defined(&Apache::loncommon::fileembstyle($1)))) {
8470: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8471: next;
8472: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
8473: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
8474: next;
8475: }
8476:
8477: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
8478: if ($context eq 'portfolio') {
1.984 raeburn 8479: my $result;
8480: if ($state eq 'existingfile') {
8481: $result=
8482: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
8483: $dirpath.$path,);
1.661 raeburn 8484: } else {
1.984 raeburn 8485: $result=
8486: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
8487: $dirpath.$path);
8488: if ($result !~ m|^/uploaded/|) {
8489: $output .= '<span class="LC_error">'
8490: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
8491: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
8492: .'</span><br />';
8493: next;
8494: } else {
8495: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
8496: $path.$fname.'</span>').'</p>';
8497: }
1.661 raeburn 8498: }
8499: } else {
8500: # Save the file
8501: my $target = $env{'form.embedded_item_'.$i};
8502: my $fullpath = $dir_root.$dirpath.'/'.$path;
8503: my $dest = $fullpath.$fname;
8504: my $url = $url_root.$dirpath.'/'.$path.$fname;
8505: my @parts=split(/\//,$fullpath);
8506: my $count;
8507: my $filepath = $dir_root;
8508: for ($count=4;$count<=$#parts;$count++) {
8509: $filepath .= "/$parts[$count]";
8510: if ((-e $filepath)!=1) {
8511: mkdir($filepath,0770);
8512: }
8513: }
8514: my $fh;
8515: if (!open($fh,'>'.$dest)) {
8516: &Apache::lonnet::logthis('Failed to create '.$dest);
8517: $output .= '<span class="LC_error">'.
8518: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8519: '</span><br />';
8520: } else {
8521: if (!print $fh $env{'form.embedded_item_'.$i}) {
8522: &Apache::lonnet::logthis('Failed to write to '.$dest);
8523: $output .= '<span class="LC_error">'.
8524: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
8525: '</span><br />';
8526: } else {
8527: if ($context eq 'testbank') {
8528: $output .= &mt('Embedded file uploaded successfully:').
8529: ' <a href="'.$url.'">'.
8530: $orig_uploaded_filename.'</a><br />';
8531: } else {
1.705 tempelho 8532: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 8533: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 8534: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 8535: }
8536: }
8537: close($fh);
8538: }
8539: }
8540: }
8541: return $output;
8542: }
8543:
8544: sub check_for_existing {
8545: my ($path,$fname,$element) = @_;
8546: my ($state,$msg);
8547: if (-d $path.'/'.$fname) {
8548: $state = 'exists';
8549: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8550: } elsif (-e $path.'/'.$fname) {
8551: $state = 'exists';
8552: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
8553: }
8554: if ($state eq 'exists') {
8555: $msg = '<span class="LC_error">'.$msg.'</span><br />';
8556: }
8557: return ($state,$msg);
8558: }
8559:
8560: sub check_for_upload {
8561: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
8562: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 ! raeburn 8563: my $filesize = length($env{'form.'.$element});
! 8564: if (!$filesize) {
! 8565: my $msg = '<span class="LC_error">'.
! 8566: &mt('Unable to upload [_1]. (size = [_2] bytes)',
! 8567: '<span class="LC_filename">'.$fname.'</span>',
! 8568: $filesize).'<br />'.
! 8569: &mt('Either the file you uploaded was empty, or your web browser was unable to read its contents.').'<br />';
! 8570: '</span>';
! 8571: return ('zero_bytes',$msg);
! 8572: }
! 8573: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 8574: my $getpropath = 1;
8575: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
8576: $getpropath);
8577: my $found_file = 0;
8578: my $locked_file = 0;
8579: foreach my $line (@dir_list) {
1.984 raeburn 8580: my ($file_name,$rest)=split(/\&/,$line,2);
1.661 raeburn 8581: if ($file_name eq $fname){
8582: $file_name = $path.$file_name;
8583: if ($group ne '') {
8584: $file_name = $group.$file_name;
8585: }
8586: $found_file = 1;
8587: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
8588: $locked_file = 1;
1.984 raeburn 8589: } else {
8590: my @info = split(/\&/,$rest);
8591: my $currsize = $info[6]/1000;
8592: if ($currsize < $filesize) {
8593: my $extra = $filesize - $currsize;
8594: if (($current_disk_usage + $extra) > $disk_quota) {
8595: my $msg = '<span class="LC_error">'.
8596: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
8597: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
8598: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
8599: $disk_quota,$current_disk_usage);
8600: return ('will_exceed_quota',$msg);
8601: }
8602: }
1.661 raeburn 8603: }
8604: }
8605: }
8606: if (($current_disk_usage + $filesize) > $disk_quota){
8607: my $msg = '<span class="LC_error">'.
8608: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
8609: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
8610: return ('will_exceed_quota',$msg);
8611: } elsif ($found_file) {
8612: if ($locked_file) {
8613: my $msg = '<span class="LC_error">';
8614: $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>');
8615: $msg .= '</span><br />';
8616: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
8617: return ('file_locked',$msg);
8618: } else {
8619: my $msg = '<span class="LC_error">';
1.984 raeburn 8620: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661 raeburn 8621: $msg .= '</span>';
1.984 raeburn 8622: return ('existingfile',$msg);
1.661 raeburn 8623: }
8624: }
8625: }
8626:
1.31 albertel 8627:
1.41 ng 8628: =pod
1.45 matthew 8629:
1.464 albertel 8630: =back
1.41 ng 8631:
1.112 bowersj2 8632: =head1 CSV Upload/Handling functions
1.38 albertel 8633:
1.41 ng 8634: =over 4
8635:
1.648 raeburn 8636: =item * &upfile_store($r)
1.41 ng 8637:
8638: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 8639: needs $env{'form.upfile'}
1.41 ng 8640: returns $datatoken to be put into hidden field
8641:
8642: =cut
1.31 albertel 8643:
8644: sub upfile_store {
8645: my $r=shift;
1.258 albertel 8646: $env{'form.upfile'}=~s/\r/\n/gs;
8647: $env{'form.upfile'}=~s/\f/\n/gs;
8648: $env{'form.upfile'}=~s/\n+/\n/gs;
8649: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 8650:
1.258 albertel 8651: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
8652: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 8653: {
1.158 raeburn 8654: my $datafile = $r->dir_config('lonDaemons').
8655: '/tmp/'.$datatoken.'.tmp';
8656: if ( open(my $fh,">$datafile") ) {
1.258 albertel 8657: print $fh $env{'form.upfile'};
1.158 raeburn 8658: close($fh);
8659: }
1.31 albertel 8660: }
8661: return $datatoken;
8662: }
8663:
1.56 matthew 8664: =pod
8665:
1.648 raeburn 8666: =item * &load_tmp_file($r)
1.41 ng 8667:
8668: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 8669: needs $env{'form.datatoken'},
8670: sets $env{'form.upfile'} to the contents of the file
1.41 ng 8671:
8672: =cut
1.31 albertel 8673:
8674: sub load_tmp_file {
8675: my $r=shift;
8676: my @studentdata=();
8677: {
1.158 raeburn 8678: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 8679: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 8680: if ( open(my $fh,"<$studentfile") ) {
8681: @studentdata=<$fh>;
8682: close($fh);
8683: }
1.31 albertel 8684: }
1.258 albertel 8685: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 8686: }
8687:
1.56 matthew 8688: =pod
8689:
1.648 raeburn 8690: =item * &upfile_record_sep()
1.41 ng 8691:
8692: Separate uploaded file into records
8693: returns array of records,
1.258 albertel 8694: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 8695:
8696: =cut
1.31 albertel 8697:
8698: sub upfile_record_sep {
1.258 albertel 8699: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 8700: } else {
1.248 albertel 8701: my @records;
1.258 albertel 8702: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8703: if ($line=~/^\s*$/) { next; }
8704: push(@records,$line);
8705: }
8706: return @records;
1.31 albertel 8707: }
8708: }
8709:
1.56 matthew 8710: =pod
8711:
1.648 raeburn 8712: =item * &record_sep($record)
1.41 ng 8713:
1.258 albertel 8714: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8715:
8716: =cut
8717:
1.263 www 8718: sub takeleft {
8719: my $index=shift;
8720: return substr('0000'.$index,-4,4);
8721: }
8722:
1.31 albertel 8723: sub record_sep {
8724: my $record=shift;
8725: my %components=();
1.258 albertel 8726: if ($env{'form.upfiletype'} eq 'xml') {
8727: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8728: my $i=0;
1.356 albertel 8729: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8730: $field=~s/^(\"|\')//;
8731: $field=~s/(\"|\')$//;
1.263 www 8732: $components{&takeleft($i)}=$field;
1.31 albertel 8733: $i++;
8734: }
1.258 albertel 8735: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8736: my $i=0;
1.356 albertel 8737: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8738: $field=~s/^(\"|\')//;
8739: $field=~s/(\"|\')$//;
1.263 www 8740: $components{&takeleft($i)}=$field;
1.31 albertel 8741: $i++;
8742: }
8743: } else {
1.561 www 8744: my $separator=',';
1.480 banghart 8745: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8746: $separator=';';
1.480 banghart 8747: }
1.31 albertel 8748: my $i=0;
1.561 www 8749: # the character we are looking for to indicate the end of a quote or a record
8750: my $looking_for=$separator;
8751: # do not add the characters to the fields
8752: my $ignore=0;
8753: # we just encountered a separator (or the beginning of the record)
8754: my $just_found_separator=1;
8755: # store the field we are working on here
8756: my $field='';
8757: # work our way through all characters in record
8758: foreach my $character ($record=~/(.)/g) {
8759: if ($character eq $looking_for) {
8760: if ($character ne $separator) {
8761: # Found the end of a quote, again looking for separator
8762: $looking_for=$separator;
8763: $ignore=1;
8764: } else {
8765: # Found a separator, store away what we got
8766: $components{&takeleft($i)}=$field;
8767: $i++;
8768: $just_found_separator=1;
8769: $ignore=0;
8770: $field='';
8771: }
8772: next;
8773: }
8774: # single or double quotation marks after a separator indicate beginning of a quote
8775: # we are now looking for the end of the quote and need to ignore separators
8776: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8777: $looking_for=$character;
8778: next;
8779: }
8780: # ignore would be true after we reached the end of a quote
8781: if ($ignore) { next; }
8782: if (($just_found_separator) && ($character=~/\s/)) { next; }
8783: $field.=$character;
8784: $just_found_separator=0;
1.31 albertel 8785: }
1.561 www 8786: # catch the very last entry, since we never encountered the separator
8787: $components{&takeleft($i)}=$field;
1.31 albertel 8788: }
8789: return %components;
8790: }
8791:
1.144 matthew 8792: ######################################################
8793: ######################################################
8794:
1.56 matthew 8795: =pod
8796:
1.648 raeburn 8797: =item * &upfile_select_html()
1.41 ng 8798:
1.144 matthew 8799: Return HTML code to select a file from the users machine and specify
8800: the file type.
1.41 ng 8801:
8802: =cut
8803:
1.144 matthew 8804: ######################################################
8805: ######################################################
1.31 albertel 8806: sub upfile_select_html {
1.144 matthew 8807: my %Types = (
8808: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8809: semisv => &mt('Semicolon separated values'),
1.144 matthew 8810: space => &mt('Space separated'),
8811: tab => &mt('Tabulator separated'),
8812: # xml => &mt('HTML/XML'),
8813: );
8814: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8815: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8816: foreach my $type (sort(keys(%Types))) {
8817: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8818: }
8819: $Str .= "</select>\n";
8820: return $Str;
1.31 albertel 8821: }
8822:
1.301 albertel 8823: sub get_samples {
8824: my ($records,$toget) = @_;
8825: my @samples=({});
8826: my $got=0;
8827: foreach my $rec (@$records) {
8828: my %temp = &record_sep($rec);
8829: if (! grep(/\S/, values(%temp))) { next; }
8830: if (%temp) {
8831: $samples[$got]=\%temp;
8832: $got++;
8833: if ($got == $toget) { last; }
8834: }
8835: }
8836: return \@samples;
8837: }
8838:
1.144 matthew 8839: ######################################################
8840: ######################################################
8841:
1.56 matthew 8842: =pod
8843:
1.648 raeburn 8844: =item * &csv_print_samples($r,$records)
1.41 ng 8845:
8846: Prints a table of sample values from each column uploaded $r is an
8847: Apache Request ref, $records is an arrayref from
8848: &Apache::loncommon::upfile_record_sep
8849:
8850: =cut
8851:
1.144 matthew 8852: ######################################################
8853: ######################################################
1.31 albertel 8854: sub csv_print_samples {
8855: my ($r,$records) = @_;
1.662 bisitz 8856: my $samples = &get_samples($records,5);
1.301 albertel 8857:
1.594 raeburn 8858: $r->print(&mt('Samples').'<br />'.&start_data_table().
8859: &start_data_table_header_row());
1.356 albertel 8860: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 8861: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8862: $r->print(&end_data_table_header_row());
1.301 albertel 8863: foreach my $hash (@$samples) {
1.594 raeburn 8864: $r->print(&start_data_table_row());
1.356 albertel 8865: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8866: $r->print('<td>');
1.356 albertel 8867: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8868: $r->print('</td>');
8869: }
1.594 raeburn 8870: $r->print(&end_data_table_row());
1.31 albertel 8871: }
1.594 raeburn 8872: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8873: }
8874:
1.144 matthew 8875: ######################################################
8876: ######################################################
8877:
1.56 matthew 8878: =pod
8879:
1.648 raeburn 8880: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8881:
8882: Prints a table to create associations between values and table columns.
1.144 matthew 8883:
1.41 ng 8884: $r is an Apache Request ref,
8885: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8886: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8887:
8888: =cut
8889:
1.144 matthew 8890: ######################################################
8891: ######################################################
1.31 albertel 8892: sub csv_print_select_table {
8893: my ($r,$records,$d) = @_;
1.301 albertel 8894: my $i=0;
8895: my $samples = &get_samples($records,1);
1.144 matthew 8896: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8897: &start_data_table().&start_data_table_header_row().
1.144 matthew 8898: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8899: '<th>'.&mt('Column').'</th>'.
8900: &end_data_table_header_row()."\n");
1.356 albertel 8901: foreach my $array_ref (@$d) {
8902: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8903: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8904:
1.875 bisitz 8905: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 8906: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8907: $r->print('<option value="none"></option>');
1.356 albertel 8908: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8909: $r->print('<option value="'.$sample.'"'.
8910: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8911: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8912: }
1.594 raeburn 8913: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8914: $i++;
8915: }
1.594 raeburn 8916: $r->print(&end_data_table());
1.31 albertel 8917: $i--;
8918: return $i;
8919: }
1.56 matthew 8920:
1.144 matthew 8921: ######################################################
8922: ######################################################
8923:
1.56 matthew 8924: =pod
1.31 albertel 8925:
1.648 raeburn 8926: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8927:
8928: Prints a table of sample values from the upload and can make associate samples to internal names.
8929:
8930: $r is an Apache Request ref,
8931: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8932: $d is an array of 2 element arrays (internal name, displayed name)
8933:
8934: =cut
8935:
1.144 matthew 8936: ######################################################
8937: ######################################################
1.31 albertel 8938: sub csv_samples_select_table {
8939: my ($r,$records,$d) = @_;
8940: my $i=0;
1.144 matthew 8941: #
1.662 bisitz 8942: my $max_samples = 5;
8943: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8944: $r->print(&start_data_table().
8945: &start_data_table_header_row().'<th>'.
8946: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8947: &end_data_table_header_row());
1.301 albertel 8948:
8949: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8950: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8951: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8952: foreach my $option (@$d) {
8953: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8954: $r->print('<option value="'.$value.'"'.
1.253 albertel 8955: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8956: $display.'</option>');
1.31 albertel 8957: }
8958: $r->print('</select></td><td>');
1.662 bisitz 8959: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8960: if (defined($samples->[$line]{$key})) {
8961: $r->print($samples->[$line]{$key}."<br />\n");
8962: }
8963: }
1.594 raeburn 8964: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8965: $i++;
8966: }
1.594 raeburn 8967: $r->print(&end_data_table());
1.31 albertel 8968: $i--;
8969: return($i);
1.115 matthew 8970: }
8971:
1.144 matthew 8972: ######################################################
8973: ######################################################
8974:
1.115 matthew 8975: =pod
8976:
1.648 raeburn 8977: =item * &clean_excel_name($name)
1.115 matthew 8978:
8979: Returns a replacement for $name which does not contain any illegal characters.
8980:
8981: =cut
8982:
1.144 matthew 8983: ######################################################
8984: ######################################################
1.115 matthew 8985: sub clean_excel_name {
8986: my ($name) = @_;
8987: $name =~ s/[:\*\?\/\\]//g;
8988: if (length($name) > 31) {
8989: $name = substr($name,0,31);
8990: }
8991: return $name;
1.25 albertel 8992: }
1.84 albertel 8993:
1.85 albertel 8994: =pod
8995:
1.648 raeburn 8996: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8997:
8998: Returns either 1 or undef
8999:
9000: 1 if the part is to be hidden, undef if it is to be shown
9001:
9002: Arguments are:
9003:
9004: $id the id of the part to be checked
9005: $symb, optional the symb of the resource to check
9006: $udom, optional the domain of the user to check for
9007: $uname, optional the username of the user to check for
9008:
9009: =cut
1.84 albertel 9010:
9011: sub check_if_partid_hidden {
9012: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 9013: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 9014: $symb,$udom,$uname);
1.141 albertel 9015: my $truth=1;
9016: #if the string starts with !, then the list is the list to show not hide
9017: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 9018: my @hiddenlist=split(/,/,$hiddenparts);
9019: foreach my $checkid (@hiddenlist) {
1.141 albertel 9020: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 9021: }
1.141 albertel 9022: return !$truth;
1.84 albertel 9023: }
1.127 matthew 9024:
1.138 matthew 9025:
9026: ############################################################
9027: ############################################################
9028:
9029: =pod
9030:
1.157 matthew 9031: =back
9032:
1.138 matthew 9033: =head1 cgi-bin script and graphing routines
9034:
1.157 matthew 9035: =over 4
9036:
1.648 raeburn 9037: =item * &get_cgi_id()
1.138 matthew 9038:
9039: Inputs: none
9040:
9041: Returns an id which can be used to pass environment variables
9042: to various cgi-bin scripts. These environment variables will
9043: be removed from the users environment after a given time by
9044: the routine &Apache::lonnet::transfer_profile_to_env.
9045:
9046: =cut
9047:
9048: ############################################################
9049: ############################################################
1.152 albertel 9050: my $uniq=0;
1.136 matthew 9051: sub get_cgi_id {
1.154 albertel 9052: $uniq=($uniq+1)%100000;
1.280 albertel 9053: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 9054: }
9055:
1.127 matthew 9056: ############################################################
9057: ############################################################
9058:
9059: =pod
9060:
1.648 raeburn 9061: =item * &DrawBarGraph()
1.127 matthew 9062:
1.138 matthew 9063: Facilitates the plotting of data in a (stacked) bar graph.
9064: Puts plot definition data into the users environment in order for
9065: graph.png to plot it. Returns an <img> tag for the plot.
9066: The bars on the plot are labeled '1','2',...,'n'.
9067:
9068: Inputs:
9069:
9070: =over 4
9071:
9072: =item $Title: string, the title of the plot
9073:
9074: =item $xlabel: string, text describing the X-axis of the plot
9075:
9076: =item $ylabel: string, text describing the Y-axis of the plot
9077:
9078: =item $Max: scalar, the maximum Y value to use in the plot
9079: If $Max is < any data point, the graph will not be rendered.
9080:
1.140 matthew 9081: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 9082: they are plotted. If undefined, default values will be used.
9083:
1.178 matthew 9084: =item $labels: array ref holding the labels to use on the x-axis for the bars.
9085:
1.138 matthew 9086: =item @Values: An array of array references. Each array reference holds data
9087: to be plotted in a stacked bar chart.
9088:
1.239 matthew 9089: =item If the final element of @Values is a hash reference the key/value
9090: pairs will be added to the graph definition.
9091:
1.138 matthew 9092: =back
9093:
9094: Returns:
9095:
9096: An <img> tag which references graph.png and the appropriate identifying
9097: information for the plot.
9098:
1.127 matthew 9099: =cut
9100:
9101: ############################################################
9102: ############################################################
1.134 matthew 9103: sub DrawBarGraph {
1.178 matthew 9104: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 9105: #
9106: if (! defined($colors)) {
9107: $colors = ['#33ff00',
9108: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
9109: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
9110: ];
9111: }
1.228 matthew 9112: my $extra_settings = {};
9113: if (ref($Values[-1]) eq 'HASH') {
9114: $extra_settings = pop(@Values);
9115: }
1.127 matthew 9116: #
1.136 matthew 9117: my $identifier = &get_cgi_id();
9118: my $id = 'cgi.'.$identifier;
1.129 matthew 9119: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 9120: return '';
9121: }
1.225 matthew 9122: #
9123: my @Labels;
9124: if (defined($labels)) {
9125: @Labels = @$labels;
9126: } else {
9127: for (my $i=0;$i<@{$Values[0]};$i++) {
9128: push (@Labels,$i+1);
9129: }
9130: }
9131: #
1.129 matthew 9132: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 9133: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 9134: my %ValuesHash;
9135: my $NumSets=1;
9136: foreach my $array (@Values) {
9137: next if (! ref($array));
1.136 matthew 9138: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 9139: join(',',@$array);
1.129 matthew 9140: }
1.127 matthew 9141: #
1.136 matthew 9142: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 9143: if ($NumBars < 3) {
9144: $width = 120+$NumBars*32;
1.220 matthew 9145: $xskip = 1;
1.225 matthew 9146: $bar_width = 30;
9147: } elsif ($NumBars < 5) {
9148: $width = 120+$NumBars*20;
9149: $xskip = 1;
9150: $bar_width = 20;
1.220 matthew 9151: } elsif ($NumBars < 10) {
1.136 matthew 9152: $width = 120+$NumBars*15;
9153: $xskip = 1;
9154: $bar_width = 15;
9155: } elsif ($NumBars <= 25) {
9156: $width = 120+$NumBars*11;
9157: $xskip = 5;
9158: $bar_width = 8;
9159: } elsif ($NumBars <= 50) {
9160: $width = 120+$NumBars*8;
9161: $xskip = 5;
9162: $bar_width = 4;
9163: } else {
9164: $width = 120+$NumBars*8;
9165: $xskip = 5;
9166: $bar_width = 4;
9167: }
9168: #
1.137 matthew 9169: $Max = 1 if ($Max < 1);
9170: if ( int($Max) < $Max ) {
9171: $Max++;
9172: $Max = int($Max);
9173: }
1.127 matthew 9174: $Title = '' if (! defined($Title));
9175: $xlabel = '' if (! defined($xlabel));
9176: $ylabel = '' if (! defined($ylabel));
1.369 www 9177: $ValuesHash{$id.'.title'} = &escape($Title);
9178: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
9179: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 9180: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 9181: $ValuesHash{$id.'.NumBars'} = $NumBars;
9182: $ValuesHash{$id.'.NumSets'} = $NumSets;
9183: $ValuesHash{$id.'.PlotType'} = 'bar';
9184: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9185: $ValuesHash{$id.'.height'} = $height;
9186: $ValuesHash{$id.'.width'} = $width;
9187: $ValuesHash{$id.'.xskip'} = $xskip;
9188: $ValuesHash{$id.'.bar_width'} = $bar_width;
9189: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 9190: #
1.228 matthew 9191: # Deal with other parameters
9192: while (my ($key,$value) = each(%$extra_settings)) {
9193: $ValuesHash{$id.'.'.$key} = $value;
9194: }
9195: #
1.646 raeburn 9196: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 9197: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9198: }
9199:
9200: ############################################################
9201: ############################################################
9202:
9203: =pod
9204:
1.648 raeburn 9205: =item * &DrawXYGraph()
1.137 matthew 9206:
1.138 matthew 9207: Facilitates the plotting of data in an XY graph.
9208: Puts plot definition data into the users environment in order for
9209: graph.png to plot it. Returns an <img> tag for the plot.
9210:
9211: Inputs:
9212:
9213: =over 4
9214:
9215: =item $Title: string, the title of the plot
9216:
9217: =item $xlabel: string, text describing the X-axis of the plot
9218:
9219: =item $ylabel: string, text describing the Y-axis of the plot
9220:
9221: =item $Max: scalar, the maximum Y value to use in the plot
9222: If $Max is < any data point, the graph will not be rendered.
9223:
9224: =item $colors: Array ref containing the hex color codes for the data to be
9225: plotted in. If undefined, default values will be used.
9226:
9227: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9228:
9229: =item $Ydata: Array ref containing Array refs.
1.185 www 9230: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 9231:
9232: =item %Values: hash indicating or overriding any default values which are
9233: passed to graph.png.
9234: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9235:
9236: =back
9237:
9238: Returns:
9239:
9240: An <img> tag which references graph.png and the appropriate identifying
9241: information for the plot.
9242:
1.137 matthew 9243: =cut
9244:
9245: ############################################################
9246: ############################################################
9247: sub DrawXYGraph {
9248: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
9249: #
9250: # Create the identifier for the graph
9251: my $identifier = &get_cgi_id();
9252: my $id = 'cgi.'.$identifier;
9253: #
9254: $Title = '' if (! defined($Title));
9255: $xlabel = '' if (! defined($xlabel));
9256: $ylabel = '' if (! defined($ylabel));
9257: my %ValuesHash =
9258: (
1.369 www 9259: $id.'.title' => &escape($Title),
9260: $id.'.xlabel' => &escape($xlabel),
9261: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 9262: $id.'.y_max_value'=> $Max,
9263: $id.'.labels' => join(',',@$Xlabels),
9264: $id.'.PlotType' => 'XY',
9265: );
9266: #
9267: if (defined($colors) && ref($colors) eq 'ARRAY') {
9268: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9269: }
9270: #
9271: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
9272: return '';
9273: }
9274: my $NumSets=1;
1.138 matthew 9275: foreach my $array (@{$Ydata}){
1.137 matthew 9276: next if (! ref($array));
9277: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
9278: }
1.138 matthew 9279: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 9280: #
9281: # Deal with other parameters
9282: while (my ($key,$value) = each(%Values)) {
9283: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 9284: }
9285: #
1.646 raeburn 9286: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 9287: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
9288: }
9289:
9290: ############################################################
9291: ############################################################
9292:
9293: =pod
9294:
1.648 raeburn 9295: =item * &DrawXYYGraph()
1.138 matthew 9296:
9297: Facilitates the plotting of data in an XY graph with two Y axes.
9298: Puts plot definition data into the users environment in order for
9299: graph.png to plot it. Returns an <img> tag for the plot.
9300:
9301: Inputs:
9302:
9303: =over 4
9304:
9305: =item $Title: string, the title of the plot
9306:
9307: =item $xlabel: string, text describing the X-axis of the plot
9308:
9309: =item $ylabel: string, text describing the Y-axis of the plot
9310:
9311: =item $colors: Array ref containing the hex color codes for the data to be
9312: plotted in. If undefined, default values will be used.
9313:
9314: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
9315:
9316: =item $Ydata1: The first data set
9317:
9318: =item $Min1: The minimum value of the left Y-axis
9319:
9320: =item $Max1: The maximum value of the left Y-axis
9321:
9322: =item $Ydata2: The second data set
9323:
9324: =item $Min2: The minimum value of the right Y-axis
9325:
9326: =item $Max2: The maximum value of the left Y-axis
9327:
9328: =item %Values: hash indicating or overriding any default values which are
9329: passed to graph.png.
9330: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
9331:
9332: =back
9333:
9334: Returns:
9335:
9336: An <img> tag which references graph.png and the appropriate identifying
9337: information for the plot.
1.136 matthew 9338:
9339: =cut
9340:
9341: ############################################################
9342: ############################################################
1.137 matthew 9343: sub DrawXYYGraph {
9344: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
9345: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 9346: #
9347: # Create the identifier for the graph
9348: my $identifier = &get_cgi_id();
9349: my $id = 'cgi.'.$identifier;
9350: #
9351: $Title = '' if (! defined($Title));
9352: $xlabel = '' if (! defined($xlabel));
9353: $ylabel = '' if (! defined($ylabel));
9354: my %ValuesHash =
9355: (
1.369 www 9356: $id.'.title' => &escape($Title),
9357: $id.'.xlabel' => &escape($xlabel),
9358: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 9359: $id.'.labels' => join(',',@$Xlabels),
9360: $id.'.PlotType' => 'XY',
9361: $id.'.NumSets' => 2,
1.137 matthew 9362: $id.'.two_axes' => 1,
9363: $id.'.y1_max_value' => $Max1,
9364: $id.'.y1_min_value' => $Min1,
9365: $id.'.y2_max_value' => $Max2,
9366: $id.'.y2_min_value' => $Min2,
1.136 matthew 9367: );
9368: #
1.137 matthew 9369: if (defined($colors) && ref($colors) eq 'ARRAY') {
9370: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
9371: }
9372: #
9373: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
9374: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 9375: return '';
9376: }
9377: my $NumSets=1;
1.137 matthew 9378: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 9379: next if (! ref($array));
9380: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 9381: }
9382: #
9383: # Deal with other parameters
9384: while (my ($key,$value) = each(%Values)) {
9385: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 9386: }
9387: #
1.646 raeburn 9388: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 9389: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 9390: }
9391:
9392: ############################################################
9393: ############################################################
9394:
9395: =pod
9396:
1.157 matthew 9397: =back
9398:
1.139 matthew 9399: =head1 Statistics helper routines?
9400:
9401: Bad place for them but what the hell.
9402:
1.157 matthew 9403: =over 4
9404:
1.648 raeburn 9405: =item * &chartlink()
1.139 matthew 9406:
9407: Returns a link to the chart for a specific student.
9408:
9409: Inputs:
9410:
9411: =over 4
9412:
9413: =item $linktext: The text of the link
9414:
9415: =item $sname: The students username
9416:
9417: =item $sdomain: The students domain
9418:
9419: =back
9420:
1.157 matthew 9421: =back
9422:
1.139 matthew 9423: =cut
9424:
9425: ############################################################
9426: ############################################################
9427: sub chartlink {
9428: my ($linktext, $sname, $sdomain) = @_;
9429: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 9430: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 9431: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 9432: '">'.$linktext.'</a>';
1.153 matthew 9433: }
9434:
9435: #######################################################
9436: #######################################################
9437:
9438: =pod
9439:
9440: =head1 Course Environment Routines
1.157 matthew 9441:
9442: =over 4
1.153 matthew 9443:
1.648 raeburn 9444: =item * &restore_course_settings()
1.153 matthew 9445:
1.648 raeburn 9446: =item * &store_course_settings()
1.153 matthew 9447:
9448: Restores/Store indicated form parameters from the course environment.
9449: Will not overwrite existing values of the form parameters.
9450:
9451: Inputs:
9452: a scalar describing the data (e.g. 'chart', 'problem_analysis')
9453:
9454: a hash ref describing the data to be stored. For example:
9455:
9456: %Save_Parameters = ('Status' => 'scalar',
9457: 'chartoutputmode' => 'scalar',
9458: 'chartoutputdata' => 'scalar',
9459: 'Section' => 'array',
1.373 raeburn 9460: 'Group' => 'array',
1.153 matthew 9461: 'StudentData' => 'array',
9462: 'Maps' => 'array');
9463:
9464: Returns: both routines return nothing
9465:
1.631 raeburn 9466: =back
9467:
1.153 matthew 9468: =cut
9469:
9470: #######################################################
9471: #######################################################
9472: sub store_course_settings {
1.496 albertel 9473: return &store_settings($env{'request.course.id'},@_);
9474: }
9475:
9476: sub store_settings {
1.153 matthew 9477: # save to the environment
9478: # appenv the same items, just to be safe
1.300 albertel 9479: my $udom = $env{'user.domain'};
9480: my $uname = $env{'user.name'};
1.496 albertel 9481: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9482: my %SaveHash;
9483: my %AppHash;
9484: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 9485: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 9486: my $envname = 'environment.'.$basename;
1.258 albertel 9487: if (exists($env{'form.'.$setting})) {
1.153 matthew 9488: # Save this value away
9489: if ($type eq 'scalar' &&
1.258 albertel 9490: (! exists($env{$envname}) ||
9491: $env{$envname} ne $env{'form.'.$setting})) {
9492: $SaveHash{$basename} = $env{'form.'.$setting};
9493: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 9494: } elsif ($type eq 'array') {
9495: my $stored_form;
1.258 albertel 9496: if (ref($env{'form.'.$setting})) {
1.153 matthew 9497: $stored_form = join(',',
9498: map {
1.369 www 9499: &escape($_);
1.258 albertel 9500: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 9501: } else {
9502: $stored_form =
1.369 www 9503: &escape($env{'form.'.$setting});
1.153 matthew 9504: }
9505: # Determine if the array contents are the same.
1.258 albertel 9506: if ($stored_form ne $env{$envname}) {
1.153 matthew 9507: $SaveHash{$basename} = $stored_form;
9508: $AppHash{$envname} = $stored_form;
9509: }
9510: }
9511: }
9512: }
9513: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 9514: $udom,$uname);
1.153 matthew 9515: if ($put_result !~ /^(ok|delayed)/) {
9516: &Apache::lonnet::logthis('unable to save form parameters, '.
9517: 'got error:'.$put_result);
9518: }
9519: # Make sure these settings stick around in this session, too
1.646 raeburn 9520: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 9521: return;
9522: }
9523:
9524: sub restore_course_settings {
1.499 albertel 9525: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 9526: }
9527:
9528: sub restore_settings {
9529: my ($context,$prefix,$Settings) = @_;
1.153 matthew 9530: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 9531: next if (exists($env{'form.'.$setting}));
1.496 albertel 9532: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 9533: '.'.$setting;
1.258 albertel 9534: if (exists($env{$envname})) {
1.153 matthew 9535: if ($type eq 'scalar') {
1.258 albertel 9536: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 9537: } elsif ($type eq 'array') {
1.258 albertel 9538: $env{'form.'.$setting} = [
1.153 matthew 9539: map {
1.369 www 9540: &unescape($_);
1.258 albertel 9541: } split(',',$env{$envname})
1.153 matthew 9542: ];
9543: }
9544: }
9545: }
1.127 matthew 9546: }
9547:
1.618 raeburn 9548: #######################################################
9549: #######################################################
9550:
9551: =pod
9552:
9553: =head1 Domain E-mail Routines
9554:
9555: =over 4
9556:
1.648 raeburn 9557: =item * &build_recipient_list()
1.618 raeburn 9558:
1.884 raeburn 9559: Build recipient lists for five types of e-mail:
1.766 raeburn 9560: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 9561: (d) Help requests, (e) Course requests needing approval, generated by
9562: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
9563: loncoursequeueadmin.pm respectively.
1.618 raeburn 9564:
9565: Inputs:
1.619 raeburn 9566: defmail (scalar - email address of default recipient),
1.618 raeburn 9567: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 9568: defdom (domain for which to retrieve configuration settings),
9569: origmail (scalar - email address of recipient from loncapa.conf,
9570: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 9571:
1.655 raeburn 9572: Returns: comma separated list of addresses to which to send e-mail.
9573:
9574: =back
1.618 raeburn 9575:
9576: =cut
9577:
9578: ############################################################
9579: ############################################################
9580: sub build_recipient_list {
1.619 raeburn 9581: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 9582: my @recipients;
9583: my $otheremails;
9584: my %domconfig =
9585: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
9586: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 9587: if (exists($domconfig{'contacts'}{$mailing})) {
9588: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
9589: my @contacts = ('adminemail','supportemail');
9590: foreach my $item (@contacts) {
9591: if ($domconfig{'contacts'}{$mailing}{$item}) {
9592: my $addr = $domconfig{'contacts'}{$item};
9593: if (!grep(/^\Q$addr\E$/,@recipients)) {
9594: push(@recipients,$addr);
9595: }
1.619 raeburn 9596: }
1.766 raeburn 9597: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 9598: }
9599: }
1.766 raeburn 9600: } elsif ($origmail ne '') {
9601: push(@recipients,$origmail);
1.618 raeburn 9602: }
1.619 raeburn 9603: } elsif ($origmail ne '') {
9604: push(@recipients,$origmail);
1.618 raeburn 9605: }
1.688 raeburn 9606: if (defined($defmail)) {
9607: if ($defmail ne '') {
9608: push(@recipients,$defmail);
9609: }
1.618 raeburn 9610: }
9611: if ($otheremails) {
1.619 raeburn 9612: my @others;
9613: if ($otheremails =~ /,/) {
9614: @others = split(/,/,$otheremails);
1.618 raeburn 9615: } else {
1.619 raeburn 9616: push(@others,$otheremails);
9617: }
9618: foreach my $addr (@others) {
9619: if (!grep(/^\Q$addr\E$/,@recipients)) {
9620: push(@recipients,$addr);
9621: }
1.618 raeburn 9622: }
9623: }
1.619 raeburn 9624: my $recipientlist = join(',',@recipients);
1.618 raeburn 9625: return $recipientlist;
9626: }
9627:
1.127 matthew 9628: ############################################################
9629: ############################################################
1.154 albertel 9630:
1.655 raeburn 9631: =pod
9632:
9633: =head1 Course Catalog Routines
9634:
9635: =over 4
9636:
9637: =item * &gather_categories()
9638:
9639: Converts category definitions - keys of categories hash stored in
9640: coursecategories in configuration.db on the primary library server in a
9641: domain - to an array. Also generates javascript and idx hash used to
9642: generate Domain Coordinator interface for editing Course Categories.
9643:
9644: Inputs:
1.663 raeburn 9645:
1.655 raeburn 9646: categories (reference to hash of category definitions).
1.663 raeburn 9647:
1.655 raeburn 9648: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9649: categories and subcategories).
1.663 raeburn 9650:
1.655 raeburn 9651: idx (reference to hash of counters used in Domain Coordinator interface for
9652: editing Course Categories).
1.663 raeburn 9653:
1.655 raeburn 9654: jsarray (reference to array of categories used to create Javascript arrays for
9655: Domain Coordinator interface for editing Course Categories).
9656:
9657: Returns: nothing
9658:
9659: Side effects: populates cats, idx and jsarray.
9660:
9661: =cut
9662:
9663: sub gather_categories {
9664: my ($categories,$cats,$idx,$jsarray) = @_;
9665: my %counters;
9666: my $num = 0;
9667: foreach my $item (keys(%{$categories})) {
9668: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
9669: if ($container eq '' && $depth == 0) {
9670: $cats->[$depth][$categories->{$item}] = $cat;
9671: } else {
9672: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
9673: }
9674: my ($escitem,$tail) = split(/:/,$item,2);
9675: if ($counters{$tail} eq '') {
9676: $counters{$tail} = $num;
9677: $num ++;
9678: }
9679: if (ref($idx) eq 'HASH') {
9680: $idx->{$item} = $counters{$tail};
9681: }
9682: if (ref($jsarray) eq 'ARRAY') {
9683: push(@{$jsarray->[$counters{$tail}]},$item);
9684: }
9685: }
9686: return;
9687: }
9688:
9689: =pod
9690:
9691: =item * &extract_categories()
9692:
9693: Used to generate breadcrumb trails for course categories.
9694:
9695: Inputs:
1.663 raeburn 9696:
1.655 raeburn 9697: categories (reference to hash of category definitions).
1.663 raeburn 9698:
1.655 raeburn 9699: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9700: categories and subcategories).
1.663 raeburn 9701:
1.655 raeburn 9702: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 9703:
1.655 raeburn 9704: allitems (reference to hash - key is category key
9705: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9706:
1.655 raeburn 9707: idx (reference to hash of counters used in Domain Coordinator interface for
9708: editing Course Categories).
1.663 raeburn 9709:
1.655 raeburn 9710: jsarray (reference to array of categories used to create Javascript arrays for
9711: Domain Coordinator interface for editing Course Categories).
9712:
1.665 raeburn 9713: subcats (reference to hash of arrays containing all subcategories within each
9714: category, -recursive)
9715:
1.655 raeburn 9716: Returns: nothing
9717:
9718: Side effects: populates trails and allitems hash references.
9719:
9720: =cut
9721:
9722: sub extract_categories {
1.665 raeburn 9723: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9724: if (ref($categories) eq 'HASH') {
9725: &gather_categories($categories,$cats,$idx,$jsarray);
9726: if (ref($cats->[0]) eq 'ARRAY') {
9727: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9728: my $name = $cats->[0][$i];
9729: my $item = &escape($name).'::0';
9730: my $trailstr;
9731: if ($name eq 'instcode') {
9732: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 9733: } elsif ($name eq 'communities') {
9734: $trailstr = &mt('Communities');
1.655 raeburn 9735: } else {
9736: $trailstr = $name;
9737: }
9738: if ($allitems->{$item} eq '') {
9739: push(@{$trails},$trailstr);
9740: $allitems->{$item} = scalar(@{$trails})-1;
9741: }
9742: my @parents = ($name);
9743: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9744: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9745: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9746: if (ref($subcats) eq 'HASH') {
9747: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9748: }
9749: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9750: }
9751: } else {
9752: if (ref($subcats) eq 'HASH') {
9753: $subcats->{$item} = [];
1.655 raeburn 9754: }
9755: }
9756: }
9757: }
9758: }
9759: return;
9760: }
9761:
9762: =pod
9763:
9764: =item *&recurse_categories()
9765:
9766: Recursively used to generate breadcrumb trails for course categories.
9767:
9768: Inputs:
1.663 raeburn 9769:
1.655 raeburn 9770: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9771: categories and subcategories).
1.663 raeburn 9772:
1.655 raeburn 9773: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9774:
9775: category (current course category, for which breadcrumb trail is being generated).
9776:
9777: trails (reference to array of breadcrumb trails for each category).
9778:
1.655 raeburn 9779: allitems (reference to hash - key is category key
9780: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9781:
1.655 raeburn 9782: parents (array containing containers directories for current category,
9783: back to top level).
9784:
9785: Returns: nothing
9786:
9787: Side effects: populates trails and allitems hash references
9788:
9789: =cut
9790:
9791: sub recurse_categories {
1.665 raeburn 9792: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9793: my $shallower = $depth - 1;
9794: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9795: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9796: my $name = $cats->[$depth]{$category}[$k];
9797: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9798: my $trailstr = join(' -> ',(@{$parents},$category));
9799: if ($allitems->{$item} eq '') {
9800: push(@{$trails},$trailstr);
9801: $allitems->{$item} = scalar(@{$trails})-1;
9802: }
9803: my $deeper = $depth+1;
9804: push(@{$parents},$category);
1.665 raeburn 9805: if (ref($subcats) eq 'HASH') {
9806: my $subcat = &escape($name).':'.$category.':'.$depth;
9807: for (my $j=@{$parents}; $j>=0; $j--) {
9808: my $higher;
9809: if ($j > 0) {
9810: $higher = &escape($parents->[$j]).':'.
9811: &escape($parents->[$j-1]).':'.$j;
9812: } else {
9813: $higher = &escape($parents->[$j]).'::'.$j;
9814: }
9815: push(@{$subcats->{$higher}},$subcat);
9816: }
9817: }
9818: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9819: $subcats);
1.655 raeburn 9820: pop(@{$parents});
9821: }
9822: } else {
9823: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9824: my $trailstr = join(' -> ',(@{$parents},$category));
9825: if ($allitems->{$item} eq '') {
9826: push(@{$trails},$trailstr);
9827: $allitems->{$item} = scalar(@{$trails})-1;
9828: }
9829: }
9830: return;
9831: }
9832:
1.663 raeburn 9833: =pod
9834:
9835: =item *&assign_categories_table()
9836:
9837: Create a datatable for display of hierarchical categories in a domain,
9838: with checkboxes to allow a course to be categorized.
9839:
9840: Inputs:
9841:
9842: cathash - reference to hash of categories defined for the domain (from
9843: configuration.db)
9844:
9845: currcat - scalar with an & separated list of categories assigned to a course.
9846:
1.919 raeburn 9847: type - scalar contains course type (Course or Community).
9848:
1.663 raeburn 9849: Returns: $output (markup to be displayed)
9850:
9851: =cut
9852:
9853: sub assign_categories_table {
1.919 raeburn 9854: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 9855: my $output;
9856: if (ref($cathash) eq 'HASH') {
9857: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9858: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9859: $maxdepth = scalar(@cats);
9860: if (@cats > 0) {
9861: my $itemcount = 0;
9862: if (ref($cats[0]) eq 'ARRAY') {
9863: my @currcategories;
9864: if ($currcat ne '') {
9865: @currcategories = split('&',$currcat);
9866: }
1.919 raeburn 9867: my $table;
1.663 raeburn 9868: for (my $i=0; $i<@{$cats[0]}; $i++) {
9869: my $parent = $cats[0][$i];
1.919 raeburn 9870: next if ($parent eq 'instcode');
9871: if ($type eq 'Community') {
9872: next unless ($parent eq 'communities');
9873: } else {
9874: next if ($parent eq 'communities');
9875: }
1.663 raeburn 9876: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9877: my $item = &escape($parent).'::0';
9878: my $checked = '';
9879: if (@currcategories > 0) {
9880: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 9881: $checked = ' checked="checked"';
1.663 raeburn 9882: }
9883: }
1.919 raeburn 9884: my $parent_title = $parent;
9885: if ($parent eq 'communities') {
9886: $parent_title = &mt('Communities');
9887: }
9888: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9889: '<input type="checkbox" name="usecategory" value="'.
9890: $item.'"'.$checked.' />'.$parent_title.'</span>'.
9891: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9892: my $depth = 1;
9893: push(@path,$parent);
1.919 raeburn 9894: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 9895: pop(@path);
1.919 raeburn 9896: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 9897: $itemcount ++;
9898: }
1.919 raeburn 9899: if ($itemcount) {
9900: $output = &Apache::loncommon::start_data_table().
9901: $table.
9902: &Apache::loncommon::end_data_table();
9903: }
1.663 raeburn 9904: }
9905: }
9906: }
9907: return $output;
9908: }
9909:
9910: =pod
9911:
9912: =item *&assign_category_rows()
9913:
9914: Create a datatable row for display of nested categories in a domain,
9915: with checkboxes to allow a course to be categorized,called recursively.
9916:
9917: Inputs:
9918:
9919: itemcount - track row number for alternating colors
9920:
9921: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9922: categories and subcategories.
9923:
9924: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9925:
9926: parent - parent of current category item
9927:
9928: path - Array containing all categories back up through the hierarchy from the
9929: current category to the top level.
9930:
9931: currcategories - reference to array of current categories assigned to the course
9932:
9933: Returns: $output (markup to be displayed).
9934:
9935: =cut
9936:
9937: sub assign_category_rows {
9938: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9939: my ($text,$name,$item,$chgstr);
9940: if (ref($cats) eq 'ARRAY') {
9941: my $maxdepth = scalar(@{$cats});
9942: if (ref($cats->[$depth]) eq 'HASH') {
9943: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9944: my $numchildren = @{$cats->[$depth]{$parent}};
9945: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9946: $text .= '<td><table class="LC_datatable">';
9947: for (my $j=0; $j<$numchildren; $j++) {
9948: $name = $cats->[$depth]{$parent}[$j];
9949: $item = &escape($name).':'.&escape($parent).':'.$depth;
9950: my $deeper = $depth+1;
9951: my $checked = '';
9952: if (ref($currcategories) eq 'ARRAY') {
9953: if (@{$currcategories} > 0) {
9954: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 9955: $checked = ' checked="checked"';
1.663 raeburn 9956: }
9957: }
9958: }
1.664 raeburn 9959: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9960: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9961: $item.'"'.$checked.' />'.$name.'</label></span>'.
9962: '<input type="hidden" name="catname" value="'.$name.'" />'.
9963: '</td><td>';
1.663 raeburn 9964: if (ref($path) eq 'ARRAY') {
9965: push(@{$path},$name);
9966: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9967: pop(@{$path});
9968: }
9969: $text .= '</td></tr>';
9970: }
9971: $text .= '</table></td>';
9972: }
9973: }
9974: }
9975: return $text;
9976: }
9977:
1.655 raeburn 9978: ############################################################
9979: ############################################################
9980:
9981:
1.443 albertel 9982: sub commit_customrole {
1.664 raeburn 9983: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9984: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9985: ($start?', '.&mt('starting').' '.localtime($start):'').
9986: ($end?', ending '.localtime($end):'').': <b>'.
9987: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9988: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9989: '</b><br />';
9990: return $output;
9991: }
9992:
9993: sub commit_standardrole {
1.541 raeburn 9994: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9995: my ($output,$logmsg,$linefeed);
9996: if ($context eq 'auto') {
9997: $linefeed = "\n";
9998: } else {
9999: $linefeed = "<br />\n";
10000: }
1.443 albertel 10001: if ($three eq 'st') {
1.541 raeburn 10002: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
10003: $one,$two,$sec,$context);
10004: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 10005: ($result eq 'unknown_course') || ($result eq 'refused')) {
10006: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 10007: } else {
1.541 raeburn 10008: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 10009: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10010: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
10011: if ($context eq 'auto') {
10012: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
10013: } else {
10014: $output .= '<b>'.$result.'</b>'.$linefeed.
10015: &mt('Add to classlist').': <b>ok</b>';
10016: }
10017: $output .= $linefeed;
1.443 albertel 10018: }
10019: } else {
10020: $output = &mt('Assigning').' '.$three.' in '.$url.
10021: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 10022: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 10023: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 10024: if ($context eq 'auto') {
10025: $output .= $result.$linefeed;
10026: } else {
10027: $output .= '<b>'.$result.'</b>'.$linefeed;
10028: }
1.443 albertel 10029: }
10030: return $output;
10031: }
10032:
10033: sub commit_studentrole {
1.541 raeburn 10034: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 10035: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 10036: if ($context eq 'auto') {
10037: $linefeed = "\n";
10038: } else {
10039: $linefeed = '<br />'."\n";
10040: }
1.443 albertel 10041: if (defined($one) && defined($two)) {
10042: my $cid=$one.'_'.$two;
10043: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
10044: my $secchange = 0;
10045: my $expire_role_result;
10046: my $modify_section_result;
1.628 raeburn 10047: if ($oldsec ne '-1') {
10048: if ($oldsec ne $sec) {
1.443 albertel 10049: $secchange = 1;
1.628 raeburn 10050: my $now = time;
1.443 albertel 10051: my $uurl='/'.$cid;
10052: $uurl=~s/\_/\//g;
10053: if ($oldsec) {
10054: $uurl.='/'.$oldsec;
10055: }
1.626 raeburn 10056: $oldsecurl = $uurl;
1.628 raeburn 10057: $expire_role_result =
1.652 raeburn 10058: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 10059: if ($env{'request.course.sec'} ne '') {
10060: if ($expire_role_result eq 'refused') {
10061: my @roles = ('st');
10062: my @statuses = ('previous');
10063: my @roledoms = ($one);
10064: my $withsec = 1;
10065: my %roleshash =
10066: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
10067: \@statuses,\@roles,\@roledoms,$withsec);
10068: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
10069: my ($oldstart,$oldend) =
10070: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
10071: if ($oldend > 0 && $oldend <= $now) {
10072: $expire_role_result = 'ok';
10073: }
10074: }
10075: }
10076: }
1.443 albertel 10077: $result = $expire_role_result;
10078: }
10079: }
10080: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 10081: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 10082: if ($modify_section_result =~ /^ok/) {
10083: if ($secchange == 1) {
1.628 raeburn 10084: if ($sec eq '') {
10085: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
10086: } else {
10087: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
10088: }
1.443 albertel 10089: } elsif ($oldsec eq '-1') {
1.628 raeburn 10090: if ($sec eq '') {
10091: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
10092: } else {
10093: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10094: }
1.443 albertel 10095: } else {
1.628 raeburn 10096: if ($sec eq '') {
10097: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
10098: } else {
10099: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
10100: }
1.443 albertel 10101: }
10102: } else {
1.628 raeburn 10103: if ($secchange) {
10104: $$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;
10105: } else {
10106: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
10107: }
1.443 albertel 10108: }
10109: $result = $modify_section_result;
10110: } elsif ($secchange == 1) {
1.628 raeburn 10111: if ($oldsec eq '') {
10112: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
10113: } else {
10114: $$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;
10115: }
1.626 raeburn 10116: if ($expire_role_result eq 'refused') {
10117: my $newsecurl = '/'.$cid;
10118: $newsecurl =~ s/\_/\//g;
10119: if ($sec ne '') {
10120: $newsecurl.='/'.$sec;
10121: }
10122: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
10123: if ($sec eq '') {
10124: $$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;
10125: } else {
10126: $$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;
10127: }
10128: }
10129: }
1.443 albertel 10130: }
10131: } else {
1.626 raeburn 10132: $$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 10133: $result = "error: incomplete course id\n";
10134: }
10135: return $result;
10136: }
10137:
10138: ############################################################
10139: ############################################################
10140:
1.566 albertel 10141: sub check_clone {
1.578 raeburn 10142: my ($args,$linefeed) = @_;
1.566 albertel 10143: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
10144: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
10145: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
10146: my $clonemsg;
10147: my $can_clone = 0;
1.944 raeburn 10148: my $lctype = lc($args->{'crstype'});
1.908 raeburn 10149: if ($lctype ne 'community') {
10150: $lctype = 'course';
10151: }
1.566 albertel 10152: if ($clonehome eq 'no_host') {
1.944 raeburn 10153: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10154: $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'});
10155: } else {
10156: $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'});
10157: }
1.566 albertel 10158: } else {
10159: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 10160: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10161: if ($clonedesc{'type'} ne 'Community') {
10162: $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'});
10163: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10164: }
10165: }
1.882 raeburn 10166: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
10167: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 10168: $can_clone = 1;
10169: } else {
10170: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
10171: $args->{'clonedomain'},$args->{'clonecourse'});
10172: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 10173: if (grep(/^\*$/,@cloners)) {
10174: $can_clone = 1;
10175: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
10176: $can_clone = 1;
10177: } else {
1.908 raeburn 10178: my $ccrole = 'cc';
1.944 raeburn 10179: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10180: $ccrole = 'co';
10181: }
1.578 raeburn 10182: my %roleshash =
10183: &Apache::lonnet::get_my_roles($args->{'ccuname'},
10184: $args->{'ccdomain'},
1.908 raeburn 10185: 'userroles',['active'],[$ccrole],
1.578 raeburn 10186: [$args->{'clonedomain'}]);
1.908 raeburn 10187: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 10188: $can_clone = 1;
10189: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
10190: $can_clone = 1;
10191: } else {
1.944 raeburn 10192: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 10193: $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'});
10194: } else {
10195: $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'});
10196: }
1.578 raeburn 10197: }
1.566 albertel 10198: }
1.578 raeburn 10199: }
1.566 albertel 10200: }
10201: return ($can_clone, $clonemsg, $cloneid, $clonehome);
10202: }
10203:
1.444 albertel 10204: sub construct_course {
1.885 raeburn 10205: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 10206: my $outcome;
1.541 raeburn 10207: my $linefeed = '<br />'."\n";
10208: if ($context eq 'auto') {
10209: $linefeed = "\n";
10210: }
1.566 albertel 10211:
10212: #
10213: # Are we cloning?
10214: #
10215: my ($can_clone, $clonemsg, $cloneid, $clonehome);
10216: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 10217: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 10218: if ($context ne 'auto') {
1.578 raeburn 10219: if ($clonemsg ne '') {
10220: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
10221: }
1.566 albertel 10222: }
10223: $outcome .= $clonemsg.$linefeed;
10224:
10225: if (!$can_clone) {
10226: return (0,$outcome);
10227: }
10228: }
10229:
1.444 albertel 10230: #
10231: # Open course
10232: #
10233: my $crstype = lc($args->{'crstype'});
10234: my %cenv=();
10235: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
10236: $args->{'cdescr'},
10237: $args->{'curl'},
10238: $args->{'course_home'},
10239: $args->{'nonstandard'},
10240: $args->{'crscode'},
10241: $args->{'ccuname'}.':'.
10242: $args->{'ccdomain'},
1.882 raeburn 10243: $args->{'crstype'},
1.885 raeburn 10244: $cnum,$context,$category);
1.444 albertel 10245:
10246: # Note: The testing routines depend on this being output; see
10247: # Utils::Course. This needs to at least be output as a comment
10248: # if anyone ever decides to not show this, and Utils::Course::new
10249: # will need to be suitably modified.
1.541 raeburn 10250: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 10251: if ($$courseid =~ /^error:/) {
10252: return (0,$outcome);
10253: }
10254:
1.444 albertel 10255: #
10256: # Check if created correctly
10257: #
1.479 albertel 10258: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 10259: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 10260: if ($crsuhome eq 'no_host') {
10261: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
10262: return (0,$outcome);
10263: }
1.541 raeburn 10264: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 10265:
1.444 albertel 10266: #
1.566 albertel 10267: # Do the cloning
10268: #
10269: if ($can_clone && $cloneid) {
10270: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
10271: if ($context ne 'auto') {
10272: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
10273: }
10274: $outcome .= $clonemsg.$linefeed;
10275: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 10276: # Copy all files
1.637 www 10277: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 10278: # Restore URL
1.566 albertel 10279: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 10280: # Restore title
1.566 albertel 10281: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 10282: # Restore creation date, creator and creation context.
10283: $cenv{'internal.created'}=$oldcenv{'internal.created'};
10284: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
10285: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 10286: # Mark as cloned
1.566 albertel 10287: $cenv{'clonedfrom'}=$cloneid;
1.638 www 10288: # Need to clone grading mode
10289: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
10290: $cenv{'grading'}=$newenv{'grading'};
10291: # Do not clone these environment entries
10292: &Apache::lonnet::del('environment',
10293: ['default_enrollment_start_date',
10294: 'default_enrollment_end_date',
10295: 'question.email',
10296: 'policy.email',
10297: 'comment.email',
10298: 'pch.users.denied',
1.725 raeburn 10299: 'plc.users.denied',
10300: 'hidefromcat',
10301: 'categories'],
1.638 www 10302: $$crsudom,$$crsunum);
1.444 albertel 10303: }
1.566 albertel 10304:
1.444 albertel 10305: #
10306: # Set environment (will override cloned, if existing)
10307: #
10308: my @sections = ();
10309: my @xlists = ();
10310: if ($args->{'crstype'}) {
10311: $cenv{'type'}=$args->{'crstype'};
10312: }
10313: if ($args->{'crsid'}) {
10314: $cenv{'courseid'}=$args->{'crsid'};
10315: }
10316: if ($args->{'crscode'}) {
10317: $cenv{'internal.coursecode'}=$args->{'crscode'};
10318: }
10319: if ($args->{'crsquota'} ne '') {
10320: $cenv{'internal.coursequota'}=$args->{'crsquota'};
10321: } else {
10322: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
10323: }
10324: if ($args->{'ccuname'}) {
10325: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
10326: ':'.$args->{'ccdomain'};
10327: } else {
10328: $cenv{'internal.courseowner'} = $args->{'curruser'};
10329: }
10330: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
10331: if ($args->{'crssections'}) {
10332: $cenv{'internal.sectionnums'} = '';
10333: if ($args->{'crssections'} =~ m/,/) {
10334: @sections = split/,/,$args->{'crssections'};
10335: } else {
10336: $sections[0] = $args->{'crssections'};
10337: }
10338: if (@sections > 0) {
10339: foreach my $item (@sections) {
10340: my ($sec,$gp) = split/:/,$item;
10341: my $class = $args->{'crscode'}.$sec;
10342: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
10343: $cenv{'internal.sectionnums'} .= $item.',';
10344: unless ($addcheck eq 'ok') {
10345: push @badclasses, $class;
10346: }
10347: }
10348: $cenv{'internal.sectionnums'} =~ s/,$//;
10349: }
10350: }
10351: # do not hide course coordinator from staff listing,
10352: # even if privileged
10353: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10354: # add crosslistings
10355: if ($args->{'crsxlist'}) {
10356: $cenv{'internal.crosslistings'}='';
10357: if ($args->{'crsxlist'} =~ m/,/) {
10358: @xlists = split/,/,$args->{'crsxlist'};
10359: } else {
10360: $xlists[0] = $args->{'crsxlist'};
10361: }
10362: if (@xlists > 0) {
10363: foreach my $item (@xlists) {
10364: my ($xl,$gp) = split/:/,$item;
10365: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
10366: $cenv{'internal.crosslistings'} .= $item.',';
10367: unless ($addcheck eq 'ok') {
10368: push @badclasses, $xl;
10369: }
10370: }
10371: $cenv{'internal.crosslistings'} =~ s/,$//;
10372: }
10373: }
10374: if ($args->{'autoadds'}) {
10375: $cenv{'internal.autoadds'}=$args->{'autoadds'};
10376: }
10377: if ($args->{'autodrops'}) {
10378: $cenv{'internal.autodrops'}=$args->{'autodrops'};
10379: }
10380: # check for notification of enrollment changes
10381: my @notified = ();
10382: if ($args->{'notify_owner'}) {
10383: if ($args->{'ccuname'} ne '') {
10384: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
10385: }
10386: }
10387: if ($args->{'notify_dc'}) {
10388: if ($uname ne '') {
1.630 raeburn 10389: push(@notified,$uname.':'.$udom);
1.444 albertel 10390: }
10391: }
10392: if (@notified > 0) {
10393: my $notifylist;
10394: if (@notified > 1) {
10395: $notifylist = join(',',@notified);
10396: } else {
10397: $notifylist = $notified[0];
10398: }
10399: $cenv{'internal.notifylist'} = $notifylist;
10400: }
10401: if (@badclasses > 0) {
10402: my %lt=&Apache::lonlocal::texthash(
10403: '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',
10404: 'dnhr' => 'does not have rights to access enrollment in these classes',
10405: 'adby' => 'as determined by the policies of your institution on access to official classlists'
10406: );
1.541 raeburn 10407: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
10408: ' ('.$lt{'adby'}.')';
10409: if ($context eq 'auto') {
10410: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 10411: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 10412: foreach my $item (@badclasses) {
10413: if ($context eq 'auto') {
10414: $outcome .= " - $item\n";
10415: } else {
10416: $outcome .= "<li>$item</li>\n";
10417: }
10418: }
10419: if ($context eq 'auto') {
10420: $outcome .= $linefeed;
10421: } else {
1.566 albertel 10422: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 10423: }
10424: }
1.444 albertel 10425: }
10426: if ($args->{'no_end_date'}) {
10427: $args->{'endaccess'} = 0;
10428: }
10429: $cenv{'internal.autostart'}=$args->{'enrollstart'};
10430: $cenv{'internal.autoend'}=$args->{'enrollend'};
10431: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
10432: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
10433: if ($args->{'showphotos'}) {
10434: $cenv{'internal.showphotos'}=$args->{'showphotos'};
10435: }
10436: $cenv{'internal.authtype'} = $args->{'authtype'};
10437: $cenv{'internal.autharg'} = $args->{'autharg'};
10438: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
10439: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 10440: 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');
10441: if ($context eq 'auto') {
10442: $outcome .= $krb_msg;
10443: } else {
1.566 albertel 10444: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 10445: }
10446: $outcome .= $linefeed;
1.444 albertel 10447: }
10448: }
10449: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
10450: if ($args->{'setpolicy'}) {
10451: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10452: }
10453: if ($args->{'setcontent'}) {
10454: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
10455: }
10456: }
10457: if ($args->{'reshome'}) {
10458: $cenv{'reshome'}=$args->{'reshome'}.'/';
10459: $cenv{'reshome'}=~s/\/+$/\//;
10460: }
10461: #
10462: # course has keyed access
10463: #
10464: if ($args->{'setkeys'}) {
10465: $cenv{'keyaccess'}='yes';
10466: }
10467: # if specified, key authority is not course, but user
10468: # only active if keyaccess is yes
10469: if ($args->{'keyauth'}) {
1.487 albertel 10470: my ($user,$domain) = split(':',$args->{'keyauth'});
10471: $user = &LONCAPA::clean_username($user);
10472: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 10473: if ($user ne '' && $domain ne '') {
1.487 albertel 10474: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 10475: }
10476: }
10477:
10478: if ($args->{'disresdis'}) {
10479: $cenv{'pch.roles.denied'}='st';
10480: }
10481: if ($args->{'disablechat'}) {
10482: $cenv{'plc.roles.denied'}='st';
10483: }
10484:
10485: # Record we've not yet viewed the Course Initialization Helper for this
10486: # course
10487: $cenv{'course.helper.not.run'} = 1;
10488: #
10489: # Use new Randomseed
10490: #
10491: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
10492: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
10493: #
10494: # The encryption code and receipt prefix for this course
10495: #
10496: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
10497: $cenv{'internal.encpref'}=100+int(9*rand(99));
10498: #
10499: # By default, use standard grading
10500: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
10501:
1.541 raeburn 10502: $outcome .= $linefeed.&mt('Setting environment').': '.
10503: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10504: #
10505: # Open all assignments
10506: #
10507: if ($args->{'openall'}) {
10508: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
10509: my %storecontent = ($storeunder => time,
10510: $storeunder.'.type' => 'date_start');
10511:
10512: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 10513: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 10514: }
10515: #
10516: # Set first page
10517: #
10518: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
10519: || ($cloneid)) {
1.445 albertel 10520: use LONCAPA::map;
1.444 albertel 10521: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 10522:
10523: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
10524: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
10525:
1.444 albertel 10526: $outcome .= ($fatal?$errtext:'read ok').' - ';
10527: my $title; my $url;
10528: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 10529: $title=&mt('Syllabus');
1.444 albertel 10530: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
10531: } else {
1.963 raeburn 10532: $title=&mt('Table of Contents');
1.444 albertel 10533: $url='/adm/navmaps';
10534: }
1.445 albertel 10535:
10536: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
10537: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
10538:
10539: if ($errtext) { $fatal=2; }
1.541 raeburn 10540: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 10541: }
1.566 albertel 10542:
10543: return (1,$outcome);
1.444 albertel 10544: }
10545:
10546: ############################################################
10547: ############################################################
10548:
1.953 droeschl 10549: #SD
10550: # only Community and Course, or anything else?
1.378 raeburn 10551: sub course_type {
10552: my ($cid) = @_;
10553: if (!defined($cid)) {
10554: $cid = $env{'request.course.id'};
10555: }
1.404 albertel 10556: if (defined($env{'course.'.$cid.'.type'})) {
10557: return $env{'course.'.$cid.'.type'};
1.378 raeburn 10558: } else {
10559: return 'Course';
1.377 raeburn 10560: }
10561: }
1.156 albertel 10562:
1.406 raeburn 10563: sub group_term {
10564: my $crstype = &course_type();
10565: my %names = (
10566: 'Course' => 'group',
1.865 raeburn 10567: 'Community' => 'group',
1.406 raeburn 10568: );
10569: return $names{$crstype};
10570: }
10571:
1.902 raeburn 10572: sub course_types {
10573: my @types = ('official','unofficial','community');
10574: my %typename = (
10575: official => 'Official course',
10576: unofficial => 'Unofficial course',
10577: community => 'Community',
10578: );
10579: return (\@types,\%typename);
10580: }
10581:
1.156 albertel 10582: sub icon {
10583: my ($file)=@_;
1.505 albertel 10584: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 10585: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 10586: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 10587: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
10588: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
10589: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10590: $curfext.".gif") {
10591: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
10592: $curfext.".gif";
10593: }
10594: }
1.249 albertel 10595: return &lonhttpdurl($iconname);
1.154 albertel 10596: }
1.84 albertel 10597:
1.575 albertel 10598: sub lonhttpdurl {
1.692 www 10599: #
10600: # Had been used for "small fry" static images on separate port 8080.
10601: # Modify here if lightweight http functionality desired again.
10602: # Currently eliminated due to increasing firewall issues.
10603: #
1.575 albertel 10604: my ($url)=@_;
1.692 www 10605: return $url;
1.215 albertel 10606: }
10607:
1.213 albertel 10608: sub connection_aborted {
10609: my ($r)=@_;
10610: $r->print(" ");$r->rflush();
10611: my $c = $r->connection;
10612: return $c->aborted();
10613: }
10614:
1.221 foxr 10615: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 10616: # strings as 'strings'.
10617: sub escape_single {
1.221 foxr 10618: my ($input) = @_;
1.223 albertel 10619: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 10620: $input =~ s/\'/\\\'/g; # Esacpe the 's....
10621: return $input;
10622: }
1.223 albertel 10623:
1.222 foxr 10624: # Same as escape_single, but escape's "'s This
10625: # can be used for "strings"
10626: sub escape_double {
10627: my ($input) = @_;
10628: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
10629: $input =~ s/\"/\\\"/g; # Esacpe the "s....
10630: return $input;
10631: }
1.223 albertel 10632:
1.222 foxr 10633: # Escapes the last element of a full URL.
10634: sub escape_url {
10635: my ($url) = @_;
1.238 raeburn 10636: my @urlslices = split(/\//, $url,-1);
1.369 www 10637: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 10638: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 10639: }
1.462 albertel 10640:
1.820 raeburn 10641: sub compare_arrays {
10642: my ($arrayref1,$arrayref2) = @_;
10643: my (@difference,%count);
10644: @difference = ();
10645: %count = ();
10646: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
10647: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
10648: foreach my $element (keys(%count)) {
10649: if ($count{$element} == 1) {
10650: push(@difference,$element);
10651: }
10652: }
10653: }
10654: return @difference;
10655: }
10656:
1.817 bisitz 10657: # -------------------------------------------------------- Initialize user login
1.462 albertel 10658: sub init_user_environment {
1.463 albertel 10659: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 10660: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
10661:
10662: my $public=($username eq 'public' && $domain eq 'public');
10663:
10664: # See if old ID present, if so, remove
10665:
10666: my ($filename,$cookie,$userroles);
10667: my $now=time;
10668:
10669: if ($public) {
10670: my $max_public=100;
10671: my $oldest;
10672: my $oldest_time=0;
10673: for(my $next=1;$next<=$max_public;$next++) {
10674: if (-e $lonids."/publicuser_$next.id") {
10675: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
10676: if ($mtime<$oldest_time || !$oldest_time) {
10677: $oldest_time=$mtime;
10678: $oldest=$next;
10679: }
10680: } else {
10681: $cookie="publicuser_$next";
10682: last;
10683: }
10684: }
10685: if (!$cookie) { $cookie="publicuser_$oldest"; }
10686: } else {
1.463 albertel 10687: # if this isn't a robot, kill any existing non-robot sessions
10688: if (!$args->{'robot'}) {
10689: opendir(DIR,$lonids);
10690: while ($filename=readdir(DIR)) {
10691: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
10692: unlink($lonids.'/'.$filename);
10693: }
1.462 albertel 10694: }
1.463 albertel 10695: closedir(DIR);
1.462 albertel 10696: }
10697: # Give them a new cookie
1.463 albertel 10698: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 10699: : $now.$$.int(rand(10000)));
1.463 albertel 10700: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 10701:
10702: # Initialize roles
10703:
10704: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
10705: }
10706: # ------------------------------------ Check browser type and MathML capability
10707:
10708: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
10709: $clientunicode,$clientos) = &decode_user_agent($r);
10710:
10711: # ------------------------------------------------------------- Get environment
10712:
10713: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
10714: my ($tmp) = keys(%userenv);
10715: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10716: } else {
10717: undef(%userenv);
10718: }
10719: if (($userenv{'interface'}) && (!$form->{'interface'})) {
10720: $form->{'interface'}=$userenv{'interface'};
10721: }
10722: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
10723:
10724: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 10725: foreach my $option ('interface','localpath','localres') {
10726: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 10727: }
10728: # --------------------------------------------------------- Write first profile
10729:
10730: {
10731: my %initial_env =
10732: ("user.name" => $username,
10733: "user.domain" => $domain,
10734: "user.home" => $authhost,
10735: "browser.type" => $clientbrowser,
10736: "browser.version" => $clientversion,
10737: "browser.mathml" => $clientmathml,
10738: "browser.unicode" => $clientunicode,
10739: "browser.os" => $clientos,
10740: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
10741: "request.course.fn" => '',
10742: "request.course.uri" => '',
10743: "request.course.sec" => '',
10744: "request.role" => 'cm',
10745: "request.role.adv" => $env{'user.adv'},
10746: "request.host" => $ENV{'REMOTE_ADDR'},);
10747:
10748: if ($form->{'localpath'}) {
10749: $initial_env{"browser.localpath"} = $form->{'localpath'};
10750: $initial_env{"browser.localres"} = $form->{'localres'};
10751: }
10752:
10753: if ($form->{'interface'}) {
10754: $form->{'interface'}=~s/\W//gs;
10755: $initial_env{"browser.interface"} = $form->{'interface'};
10756: $env{'browser.interface'}=$form->{'interface'};
10757: }
10758:
1.981 raeburn 10759: my %is_adv = ( is_adv => $env{'user.adv'} );
1.980 raeburn 10760: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
10761:
1.724 raeburn 10762: foreach my $tool ('aboutme','blog','portfolio') {
10763: $userenv{'availabletools.'.$tool} =
1.980 raeburn 10764: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
10765: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 10766: }
10767:
1.864 raeburn 10768: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 10769: $userenv{'canrequest.'.$crstype} =
10770: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 10771: 'reload','requestcourses',
10772: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 10773: }
10774:
1.462 albertel 10775: $env{'user.environment'} = "$lonids/$cookie.id";
10776:
10777: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10778: &GDBM_WRCREAT(),0640)) {
10779: &_add_to_env(\%disk_env,\%initial_env);
10780: &_add_to_env(\%disk_env,\%userenv,'environment.');
10781: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10782: if (ref($args->{'extra_env'})) {
10783: &_add_to_env(\%disk_env,$args->{'extra_env'});
10784: }
1.462 albertel 10785: untie(%disk_env);
10786: } else {
1.705 tempelho 10787: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10788: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10789: return 'error: '.$!;
10790: }
10791: }
10792: $env{'request.role'}='cm';
10793: $env{'request.role.adv'}=$env{'user.adv'};
10794: $env{'browser.type'}=$clientbrowser;
10795:
10796: return $cookie;
10797:
10798: }
10799:
10800: sub _add_to_env {
10801: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10802: if (ref($env_data) eq 'HASH') {
10803: while (my ($key,$value) = each(%$env_data)) {
10804: $idf->{$prefix.$key} = $value;
10805: $env{$prefix.$key} = $value;
10806: }
1.462 albertel 10807: }
10808: }
10809:
1.685 tempelho 10810: # --- Get the symbolic name of a problem and the url
10811: sub get_symb {
10812: my ($request,$silent) = @_;
1.726 raeburn 10813: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10814: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10815: if ($symb eq '') {
10816: if (!$silent) {
10817: $request->print("Unable to handle ambiguous references:$url:.");
10818: return ();
10819: }
10820: }
10821: &Apache::lonenc::check_decrypt(\$symb);
10822: return ($symb);
10823: }
10824:
10825: # --------------------------------------------------------------Get annotation
10826:
10827: sub get_annotation {
10828: my ($symb,$enc) = @_;
10829:
10830: my $key = $symb;
10831: if (!$enc) {
10832: $key =
10833: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10834: }
10835: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10836: return $annotation{$key};
10837: }
10838:
10839: sub clean_symb {
1.731 raeburn 10840: my ($symb,$delete_enc) = @_;
1.685 tempelho 10841:
10842: &Apache::lonenc::check_decrypt(\$symb);
10843: my $enc = $env{'request.enc'};
1.731 raeburn 10844: if ($delete_enc) {
1.730 raeburn 10845: delete($env{'request.enc'});
10846: }
1.685 tempelho 10847:
10848: return ($symb,$enc);
10849: }
1.462 albertel 10850:
1.41 ng 10851: =pod
10852:
10853: =back
10854:
1.112 bowersj2 10855: =cut
1.41 ng 10856:
1.112 bowersj2 10857: 1;
10858: __END__;
1.41 ng 10859:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>