Annotation of loncom/interface/loncommon.pm, revision 1.692.4.21
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.692.4.21! raeburn 4: # $Id: loncommon.pm,v 1.692.4.20 2009/10/24 03:32:49 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.46 matthew 274: "<font color=yellow>INFO: Read file types</font>");
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.692.4.2 raeburn 409: <script type="text/javascript" language="Javascript">
1.692.4.4 raeburn 410: // <![CDATA[
1.74 www 411: var stdeditbrowser;
1.692.4.2 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.692.4.2 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.692.4.4 raeburn 433: // ]]>
1.74 www 434: </script>
435: ENDSTDBRW
436: }
1.42 matthew 437:
1.74 www 438: sub selectstudent_link {
1.692.4.2 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.692.4.2 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.692.4.2 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";
465: <script type="text/javascript">
1.692.4.4 raeburn 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: }
1.692.4.4 raeburn 478: // ]]>
1.653 raeburn 479: </script>
480: ENDAUTHORBRW
481: }
482:
1.91 www 483: sub coursebrowser_javascript {
1.692.4.21! raeburn 484: my ($domainfilter,$sec_element,$formname,$role_element)=@_;
1.692.4.17 raeburn 485: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role.');
1.692.4.9 raeburn 486: my $id_functions = &javascript_index_functions();
487: my $output = '
1.692.4.2 raeburn 488: <script type="text/javascript" language="JavaScript">
1.692.4.4 raeburn 489: // <![CDATA[
1.468 raeburn 490: var stdeditbrowser;'."\n";
1.692.4.9 raeburn 491:
492: $output .= <<"ENDSTDBRW";
1.377 raeburn 493: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 494: var url = '/adm/pickcourse?';
1.692.4.18 raeburn 495: var formid = getFormIdByName(formname);
1.692.4.9 raeburn 496: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 497: if (domainfilter != null) {
498: if (domainfilter != '') {
499: url += 'domainfilter='+domainfilter+'&';
500: }
501: }
1.91 www 502: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 503: '&cdomelement='+udom+
504: '&cnameelement='+desc;
1.468 raeburn 505: if (extra_element !=null && extra_element != '') {
1.594 raeburn 506: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 507: url += '&roleelement='+extra_element;
508: if (domainfilter == null || domainfilter == '') {
509: url += '&domainfilter='+extra_element;
510: }
1.234 raeburn 511: }
1.468 raeburn 512: else {
513: if (formname == 'portform') {
514: url += '&setroles='+extra_element;
515: }
516: }
1.230 raeburn 517: }
1.692.4.7 raeburn 518: if (formname == 'ccrs') {
519: var ownername = document.forms[formid].ccuname.value;
520: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
521: url += '&cloner='+ownername+':'+ownerdom;
522: }
1.293 raeburn 523: if (multflag !=null && multflag != '') {
524: url += '&multiple='+multflag;
525: }
1.692.4.6 raeburn 526: if (crstype == 'Course/Community') {
1.377 raeburn 527: if (formname == 'cu') {
528: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
529: if (crstype == "") {
530: alert("$crs_or_grp_alert");
531: return;
532: }
533: }
534: }
535: if (crstype !=null && crstype != '') {
536: url += '&type='+crstype;
537: }
1.102 www 538: var title = 'Course_Browser';
1.91 www 539: var options = 'scrollbars=1,resizable=1,menubar=0';
540: options += ',width=700,height=600';
541: stdeditbrowser = open(url,title,options,'1');
542: stdeditbrowser.focus();
543: }
1.692.4.9 raeburn 544: $id_functions
1.91 www 545: ENDSTDBRW
1.692.4.21! raeburn 546: if (($sec_element ne '') || ($role_element ne '')) {
! 547: $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.468 raeburn 548: }
549: $output .= '
1.692.4.4 raeburn 550: // ]]>
1.468 raeburn 551: </script>';
552: return $output;
553: }
554:
1.692.4.9 raeburn 555: sub javascript_index_functions {
556: return <<"ENDJS";
557:
558: function getFormIdByName(formname) {
559: for (var i=0;i<document.forms.length;i++) {
560: if (document.forms[i].name == formname) {
561: return i;
562: }
563: }
564: return -1;
565: }
566:
567: function getIndexByName(formid,item) {
568: for (var i=0;i<document.forms[formid].elements.length;i++) {
569: if (document.forms[formid].elements[i].name == item) {
570: return i;
571: }
572: }
573: return -1;
574: }
575:
576: function getDomainFromSelectbox(formname,udom) {
577: var userdom;
578: var formid = getFormIdByName(formname);
579: if (formid > -1) {
580: var domid = getIndexByName(formid,udom);
581: if (domid > -1) {
582: if (document.forms[formid].elements[domid].type == 'select-one') {
583: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
584: }
585: if (document.forms[formid].elements[domid].type == 'hidden') {
586: userdom=document.forms[formid].elements[domid].value;
587: }
588: }
589: }
590: return userdom;
591: }
592:
593: ENDJS
594:
595: }
596:
597: sub userbrowser_javascript {
598: my $id_functions = &javascript_index_functions();
599: return <<"ENDUSERBRW";
600:
1.692.4.17 raeburn 601: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.692.4.9 raeburn 602: var url = '/adm/pickuser?';
603: var userdom = getDomainFromSelectbox(formname,udom);
604: if (userdom != null) {
605: if (userdom != '') {
606: url += 'srchdom='+userdom+'&';
607: }
608: }
609: url += 'form=' + formname + '&unameelement='+uname+
610: '&udomelement='+udom+
611: '&ulastelement='+ulast+
612: '&ufirstelement='+ufirst+
613: '&uemailelement='+uemail+
614: '&hideudomelement='+hideudom+
615: '&coursedom='+crsdom;
1.692.4.17 raeburn 616: if ((caller != null) && (caller != undefined)) {
617: url += '&caller='+caller;
618: }
1.692.4.9 raeburn 619: var title = 'User_Browser';
620: var options = 'scrollbars=1,resizable=1,menubar=0';
621: options += ',width=700,height=600';
622: var stdeditbrowser = open(url,title,options,'1');
623: stdeditbrowser.focus();
624: }
625:
1.692.4.17 raeburn 626: function fix_domain (formname,udom,origdom,uname) {
1.692.4.9 raeburn 627: var formid = getFormIdByName(formname);
628: if (formid > -1) {
1.692.4.17 raeburn 629: var unameid = getIndexByName(formid,uname);
1.692.4.9 raeburn 630: var domid = getIndexByName(formid,udom);
631: var hidedomid = getIndexByName(formid,origdom);
632: if (hidedomid > -1) {
633: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.692.4.17 raeburn 634: var unameval = document.forms[formid].elements[unameid].value;
635: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
636: if (domid > -1) {
637: var slct = document.forms[formid].elements[domid];
638: if (slct.type == 'select-one') {
639: var i;
640: for (i=0;i<slct.length;i++) {
641: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
642: }
643: }
644: if (slct.type == 'hidden') {
645: slct.value = fixeddom;
1.692.4.9 raeburn 646: }
647: }
648: }
649: }
650: }
651: return;
652: }
653:
654: $id_functions
655: ENDUSERBRW
656: }
657:
658:
1.468 raeburn 659: sub setsec_javascript {
1.692.4.21! raeburn 660: my ($sec_element,$formname,$role_element) = @_;
! 661: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
! 662: $communityrolestr);
! 663: if ($role_element ne '') {
! 664: my @allroles = ('st','ta','ep','in','ad');
! 665: foreach my $crstype ('Course','Community') {
! 666: if ($crstype eq 'Community') {
! 667: foreach my $role (@allroles) {
! 668: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
! 669: }
! 670: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
! 671: } else {
! 672: foreach my $role (@allroles) {
! 673: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
! 674: }
! 675: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
! 676: }
! 677: }
! 678: $rolestr = '"'.join('","',@allroles).'"';
! 679: $courserolestr = '"'.join('","',@courserolenames).'"';
! 680: $communityrolestr = '"'.join('","',@communityrolenames).'"';
! 681: }
1.468 raeburn 682: my $setsections = qq|
683: function setSect(sectionlist) {
1.629 raeburn 684: var sectionsArray = new Array();
685: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
686: sectionsArray = sectionlist.split(",");
687: }
1.468 raeburn 688: var numSections = sectionsArray.length;
689: document.$formname.$sec_element.length = 0;
690: if (numSections == 0) {
691: document.$formname.$sec_element.multiple=false;
692: document.$formname.$sec_element.size=1;
693: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
694: } else {
695: if (numSections == 1) {
696: document.$formname.$sec_element.multiple=false;
697: document.$formname.$sec_element.size=1;
698: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
699: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
700: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
701: } else {
702: for (var i=0; i<numSections; i++) {
703: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
704: }
705: document.$formname.$sec_element.multiple=true
706: if (numSections < 3) {
707: document.$formname.$sec_element.size=numSections;
708: } else {
709: document.$formname.$sec_element.size=3;
710: }
711: document.$formname.$sec_element.options[0].selected = false
712: }
713: }
1.91 www 714: }
1.692.4.21! raeburn 715:
! 716: function setRole(crstype) {
! 717: |;
! 718: if ($role_element eq '') {
! 719: $setsections .= ' return;
! 720: }
! 721: ';
! 722: } else {
! 723: $setsections .= qq|
! 724: var elementLength = document.$formname.$role_element.length;
! 725: var allroles = Array($rolestr);
! 726: var courserolenames = Array($courserolestr);
! 727: var communityrolenames = Array($communityrolestr);
! 728: if (elementLength != undefined) {
! 729: if (document.$formname.$role_element.options[5].value == 'cc') {
! 730: if (crstype == 'Course') {
! 731: return;
! 732: } else {
! 733: allroles[5] = 'co';
! 734: for (var i=0; i<6; i++) {
! 735: document.$formname.$role_element.options[i].value = allroles[i];
! 736: document.$formname.$role_element.options[i].text = communityrolenames[i];
! 737: }
! 738: }
! 739: } else {
! 740: if (crstype == 'Community') {
! 741: return;
! 742: } else {
! 743: allroles[5] = 'cc';
! 744: for (var i=0; i<6; i++) {
! 745: document.$formname.$role_element.options[i].value = allroles[i];
! 746: document.$formname.$role_element.options[i].text = courserolenames[i];
! 747: }
! 748: }
! 749: }
! 750: }
! 751: return;
! 752: }
1.468 raeburn 753: |;
1.692.4.21! raeburn 754: }
1.468 raeburn 755: return $setsections;
756: }
757:
1.91 www 758: sub selectcourse_link {
1.377 raeburn 759: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.692.4.6 raeburn 760: my $linktext = &mt('Select Course');
761: if ($selecttype eq 'Community') {
762: $linktext = &mt('Select Community');
763: }
1.692.4.2 raeburn 764: return '<span class="LC_nobreak">'
765: ."<a href='"
766: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
767: .'","'.$udomele.'","'.$desc.'","'.$extra_element
768: .'","'.$multflag.'","'.$selecttype.'");'
1.692.4.6 raeburn 769: ."'>".$linktext.'</a>'
1.692.4.2 raeburn 770: .'</span>';
1.74 www 771: }
1.42 matthew 772:
1.653 raeburn 773: sub selectauthor_link {
774: my ($form,$udom)=@_;
775: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
776: &mt('Select Author').'</a>';
777: }
778:
1.692.4.9 raeburn 779: sub selectuser_link {
780: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.692.4.17 raeburn 781: $coursedom,$linktext,$caller) = @_;
1.692.4.9 raeburn 782: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.692.4.17 raeburn 783: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.692.4.9 raeburn 784: ');">'.$linktext.'</a>';
785: }
786:
1.273 raeburn 787: sub check_uncheck_jscript {
788: my $jscript = <<"ENDSCRT";
789: function checkAll(field) {
790: if (field.length > 0) {
791: for (i = 0; i < field.length; i++) {
792: field[i].checked = true ;
793: }
794: } else {
795: field.checked = true
796: }
797: }
798:
799: function uncheckAll(field) {
800: if (field.length > 0) {
801: for (i = 0; i < field.length; i++) {
802: field[i].checked = false ;
1.543 albertel 803: }
804: } else {
1.273 raeburn 805: field.checked = false ;
806: }
807: }
808: ENDSCRT
809: return $jscript;
810: }
811:
1.656 www 812: sub select_timezone {
1.659 raeburn 813: my ($name,$selected,$onchange,$includeempty)=@_;
814: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
815: if ($includeempty) {
816: $output .= '<option value=""';
817: if (($selected eq '') || ($selected eq 'local')) {
818: $output .= ' selected="selected" ';
819: }
820: $output .= '> </option>';
821: }
1.657 raeburn 822: my @timezones = DateTime::TimeZone->all_names;
823: foreach my $tzone (@timezones) {
824: $output.= '<option value="'.$tzone.'"';
825: if ($tzone eq $selected) {
826: $output.=' selected="selected"';
827: }
828: $output.=">$tzone</option>\n";
1.656 www 829: }
830: $output.="</select>";
831: return $output;
832: }
1.273 raeburn 833:
1.687 raeburn 834: sub select_datelocale {
835: my ($name,$selected,$onchange,$includeempty)=@_;
836: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
837: if ($includeempty) {
838: $output .= '<option value=""';
839: if ($selected eq '') {
840: $output .= ' selected="selected" ';
841: }
842: $output .= '> </option>';
843: }
844: my (@possibles,%locale_names);
845: my @locales = DateTime::Locale::Catalog::Locales;
846: foreach my $locale (@locales) {
847: if (ref($locale) eq 'HASH') {
848: my $id = $locale->{'id'};
849: if ($id ne '') {
850: my $en_terr = $locale->{'en_territory'};
851: my $native_terr = $locale->{'native_territory'};
1.692.4.1 raeburn 852: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 853: if (grep(/^en$/,@languages) || !@languages) {
854: if ($en_terr ne '') {
855: $locale_names{$id} = '('.$en_terr.')';
856: } elsif ($native_terr ne '') {
857: $locale_names{$id} = $native_terr;
858: }
859: } else {
860: if ($native_terr ne '') {
861: $locale_names{$id} = $native_terr.' ';
862: } elsif ($en_terr ne '') {
863: $locale_names{$id} = '('.$en_terr.')';
864: }
865: }
866: push (@possibles,$id);
867: }
868: }
869: }
870: foreach my $item (sort(@possibles)) {
871: $output.= '<option value="'.$item.'"';
872: if ($item eq $selected) {
873: $output.=' selected="selected"';
874: }
875: $output.=">$item";
876: if ($locale_names{$item} ne '') {
877: $output.=" $locale_names{$item}</option>\n";
878: }
879: $output.="</option>\n";
880: }
881: $output.="</select>";
882: return $output;
883: }
884:
1.692.4.2 raeburn 885: sub select_language {
886: my ($name,$selected,$includeempty) = @_;
887: my %langchoices;
888: if ($includeempty) {
889: %langchoices = ('' => 'No language preference');
890: }
891: foreach my $id (&languageids()) {
892: my $code = &supportedlanguagecode($id);
893: if ($code) {
894: $langchoices{$code} = &plainlanguagedescription($id);
895: }
896: }
897: return &select_form($selected,$name,%langchoices);
898: }
899:
1.42 matthew 900: =pod
1.36 matthew 901:
1.648 raeburn 902: =item * &linked_select_forms(...)
1.36 matthew 903:
904: linked_select_forms returns a string containing a <script></script> block
905: and html for two <select> menus. The select menus will be linked in that
906: changing the value of the first menu will result in new values being placed
907: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 908: order unless a defined order is provided.
1.36 matthew 909:
910: linked_select_forms takes the following ordered inputs:
911:
912: =over 4
913:
1.112 bowersj2 914: =item * $formname, the name of the <form> tag
1.36 matthew 915:
1.112 bowersj2 916: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 917:
1.112 bowersj2 918: =item * $firstdefault, the default value for the first menu
1.36 matthew 919:
1.112 bowersj2 920: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 921:
1.112 bowersj2 922: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 923:
1.112 bowersj2 924: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 925:
1.609 raeburn 926: =item * $menuorder, the order of values in the first menu
927:
1.41 ng 928: =back
929:
1.36 matthew 930: Below is an example of such a hash. Only the 'text', 'default', and
931: 'select2' keys must appear as stated. keys(%menu) are the possible
932: values for the first select menu. The text that coincides with the
1.41 ng 933: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 934: and text for the second menu are given in the hash pointed to by
935: $menu{$choice1}->{'select2'}.
936:
1.112 bowersj2 937: my %menu = ( A1 => { text =>"Choice A1" ,
938: default => "B3",
939: select2 => {
940: B1 => "Choice B1",
941: B2 => "Choice B2",
942: B3 => "Choice B3",
943: B4 => "Choice B4"
1.609 raeburn 944: },
945: order => ['B4','B3','B1','B2'],
1.112 bowersj2 946: },
947: A2 => { text =>"Choice A2" ,
948: default => "C2",
949: select2 => {
950: C1 => "Choice C1",
951: C2 => "Choice C2",
952: C3 => "Choice C3"
1.609 raeburn 953: },
954: order => ['C2','C1','C3'],
1.112 bowersj2 955: },
956: A3 => { text =>"Choice A3" ,
957: default => "D6",
958: select2 => {
959: D1 => "Choice D1",
960: D2 => "Choice D2",
961: D3 => "Choice D3",
962: D4 => "Choice D4",
963: D5 => "Choice D5",
964: D6 => "Choice D6",
965: D7 => "Choice D7"
1.609 raeburn 966: },
967: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 968: }
969: );
1.36 matthew 970:
971: =cut
972:
973: sub linked_select_forms {
974: my ($formname,
975: $middletext,
976: $firstdefault,
977: $firstselectname,
978: $secondselectname,
1.609 raeburn 979: $hashref,
980: $menuorder,
1.36 matthew 981: ) = @_;
982: my $second = "document.$formname.$secondselectname";
983: my $first = "document.$formname.$firstselectname";
984: # output the javascript to do the changing
985: my $result = '';
1.692.4.2 raeburn 986: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.692.4.4 raeburn 987: $result.="// <![CDATA[\n";
1.36 matthew 988: $result.="var select2data = new Object();\n";
989: $" = '","';
990: my $debug = '';
991: foreach my $s1 (sort(keys(%$hashref))) {
992: $result.="select2data.d_$s1 = new Object();\n";
993: $result.="select2data.d_$s1.def = new String('".
994: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 995: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 996: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 997: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
998: @s2values = @{$hashref->{$s1}->{'order'}};
999: }
1.36 matthew 1000: $result.="\"@s2values\");\n";
1001: $result.="select2data.d_$s1.texts = new Array(";
1002: my @s2texts;
1003: foreach my $value (@s2values) {
1004: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1005: }
1006: $result.="\"@s2texts\");\n";
1007: }
1008: $"=' ';
1009: $result.= <<"END";
1010:
1011: function select1_changed() {
1012: // Determine new choice
1013: var newvalue = "d_" + $first.value;
1014: // update select2
1015: var values = select2data[newvalue].values;
1016: var texts = select2data[newvalue].texts;
1017: var select2def = select2data[newvalue].def;
1018: var i;
1019: // out with the old
1020: for (i = 0; i < $second.options.length; i++) {
1021: $second.options[i] = null;
1022: }
1023: // in with the nuclear
1024: for (i=0;i<values.length; i++) {
1025: $second.options[i] = new Option(values[i]);
1.143 matthew 1026: $second.options[i].value = values[i];
1.36 matthew 1027: $second.options[i].text = texts[i];
1028: if (values[i] == select2def) {
1029: $second.options[i].selected = true;
1030: }
1031: }
1032: }
1.692.4.4 raeburn 1033: // ]]>
1.36 matthew 1034: </script>
1035: END
1036: # output the initial values for the selection lists
1037: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 1038: my @order = sort(keys(%{$hashref}));
1039: if (ref($menuorder) eq 'ARRAY') {
1040: @order = @{$menuorder};
1041: }
1042: foreach my $value (@order) {
1.36 matthew 1043: $result.=" <option value=\"$value\" ";
1.253 albertel 1044: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1045: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1046: }
1047: $result .= "</select>\n";
1048: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1049: $result .= $middletext;
1050: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
1051: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1052:
1053: my @secondorder = sort(keys(%select2));
1054: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1055: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1056: }
1057: foreach my $value (@secondorder) {
1.36 matthew 1058: $result.=" <option value=\"$value\" ";
1.253 albertel 1059: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1060: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1061: }
1062: $result .= "</select>\n";
1063: # return $debug;
1064: return $result;
1065: } # end of sub linked_select_forms {
1066:
1.45 matthew 1067: =pod
1.44 bowersj2 1068:
1.648 raeburn 1069: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 1070:
1.112 bowersj2 1071: Returns a string corresponding to an HTML link to the given help
1072: $topic, where $topic corresponds to the name of a .tex file in
1073: /home/httpd/html/adm/help/tex, with underscores replaced by
1074: spaces.
1075:
1076: $text will optionally be linked to the same topic, allowing you to
1077: link text in addition to the graphic. If you do not want to link
1078: text, but wish to specify one of the later parameters, pass an
1079: empty string.
1080:
1081: $stayOnPage is a value that will be interpreted as a boolean. If true,
1082: the link will not open a new window. If false, the link will open
1083: a new window using Javascript. (Default is false.)
1084:
1085: $width and $height are optional numerical parameters that will
1086: override the width and height of the popped up window, which may
1087: be useful for certain help topics with big pictures included.
1.44 bowersj2 1088:
1089: =cut
1090:
1091: sub help_open_topic {
1.48 bowersj2 1092: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1093: $text = "" if (not defined $text);
1.44 bowersj2 1094: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 1095: if ($env{'browser.interface'} eq 'textual') {
1.79 www 1096: $stayOnPage=1;
1097: }
1.44 bowersj2 1098: $width = 350 if (not defined $width);
1099: $height = 400 if (not defined $height);
1100: my $filename = $topic;
1101: $filename =~ s/ /_/g;
1102:
1.48 bowersj2 1103: my $template = "";
1104: my $link;
1.572 banghart 1105:
1.159 www 1106: $topic=~s/\W/\_/g;
1.44 bowersj2 1107:
1.572 banghart 1108: if (!$stayOnPage) {
1.72 bowersj2 1109: $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 1110: } else {
1.48 bowersj2 1111: $link = "/adm/help/${filename}.hlp";
1112: }
1113:
1114: # Add the text
1.572 banghart 1115: if ($text ne "") {
1.77 www 1116: $template .=
1.572 banghart 1117: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.691 bisitz 1118: "<td bgcolor='#5555FF'><span class=\"LC_nobreak\"><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 1119: }
1120:
1121: # Add the graphic
1.179 matthew 1122: my $title = &mt('Online Help');
1.667 raeburn 1123: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.692.4.2 raeburn 1124: $template .= '<a target="_top" href="'.$link.'" title="'.$title.'">'.
1125: '<img src="'.$helpicon.'" border="0" alt="'.&mt('Help: [_1]',$topic).
1126: '" title="'.$title.'" /></a>';
1127: if ($text ne '') {
1128: $template.='</span></td></tr></table>';
1129: }
1.44 bowersj2 1130: return $template;
1131:
1.106 bowersj2 1132: }
1133:
1134: # This is a quicky function for Latex cheatsheet editing, since it
1135: # appears in at least four places
1136: sub helpLatexCheatsheet {
1.692.4.2 raeburn 1137: my ($topic,$text,$not_author) = @_;
1138: my $out;
1.106 bowersj2 1139: my $addOther = '';
1.692.4.3 raeburn 1140: if ($topic) {
1.692.4.2 raeburn 1141: $addOther = &Apache::loncommon::help_open_topic($topic,$text,
1.106 bowersj2 1142: undef, undef, 600) .
1143: '</td><td>';
1144: }
1.692.4.2 raeburn 1145: $out = '<table><tr><td>'.
1146: $addOther .
1147: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
1148: undef,undef,600).
1149: '</td><td>'.
1150: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
1151: undef,undef,600).
1152: '</td>';
1153: unless ($not_author) {
1154: $out .= '<td>'.
1155: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
1156: undef,undef,600).
1157: '</td>';
1158: }
1159: $out .= '</tr></table>';
1160: return $out;
1.172 www 1161: }
1162:
1.430 albertel 1163: sub general_help {
1164: my $helptopic='Student_Intro';
1165: if ($env{'request.role'}=~/^(ca|au)/) {
1166: $helptopic='Authoring_Intro';
1167: } elsif ($env{'request.role'}=~/^cc/) {
1168: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1169: } elsif ($env{'request.role'}=~/^dc/) {
1170: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1171: }
1172: return $helptopic;
1173: }
1174:
1175: sub update_help_link {
1176: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1177: my $origurl = $ENV{'REQUEST_URI'};
1178: $origurl=~s|^/~|/priv/|;
1179: my $timestamp = time;
1180: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1181: $$datum = &escape($$datum);
1182: }
1183:
1184: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1185: my $output .= <<"ENDOUTPUT";
1186: <script type="text/javascript">
1.692.4.4 raeburn 1187: // <![CDATA[
1.430 albertel 1188: banner_link = '$banner_link';
1.692.4.4 raeburn 1189: // ]]>
1.430 albertel 1190: </script>
1191: ENDOUTPUT
1192: return $output;
1193: }
1194:
1195: # now just updates the help link and generates a blue icon
1.193 raeburn 1196: sub help_open_menu {
1.430 albertel 1197: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1198: = @_;
1.430 albertel 1199: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1200: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1201: # if environment.remote is on (using remote control UI)
1.572 banghart 1202: if ($env{'browser.interface'} eq 'textual' ||
1203: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1204: $stayOnPage=1;
1.430 albertel 1205: }
1206: my $output;
1207: if ($component_help) {
1208: if (!$text) {
1209: $output=&help_open_topic($component_help,undef,$stayOnPage,
1210: $width,$height);
1211: } else {
1212: my $help_text;
1213: $help_text=&unescape($topic);
1214: $output='<table><tr><td>'.
1215: &help_open_topic($component_help,$help_text,$stayOnPage,
1216: $width,$height).'</td></tr></table>';
1217: }
1218: }
1219: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1220: return $output.$banner_link;
1221: }
1222:
1223: sub top_nav_help {
1224: my ($text) = @_;
1.436 albertel 1225: $text = &mt($text);
1.572 banghart 1226: my $stay_on_page =
1.436 albertel 1227: ($env{'browser.interface'} eq 'textual' ||
1228: $env{'environment.remote'} eq 'off' );
1.572 banghart 1229: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1230: : "javascript:helpMenu('open')";
1.572 banghart 1231: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1232:
1.201 raeburn 1233: my $title = &mt('Get help');
1.436 albertel 1234:
1235: return <<"END";
1236: $banner_link
1237: <a href="$link" title="$title">$text</a>
1238: END
1239: }
1240:
1241: sub help_menu_js {
1242: my ($text) = @_;
1243:
1244: my $stayOnPage =
1245: ($env{'browser.interface'} eq 'textual' ||
1246: $env{'environment.remote'} eq 'off' );
1247:
1248: my $width = 620;
1249: my $height = 600;
1.430 albertel 1250: my $helptopic=&general_help();
1251: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1252: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1253: my $start_page =
1254: &Apache::loncommon::start_page('Help Menu', undef,
1255: {'frameset' => 1,
1256: 'js_ready' => 1,
1257: 'add_entries' => {
1258: 'border' => '0',
1.579 raeburn 1259: 'rows' => "110,*",},});
1.331 albertel 1260: my $end_page =
1261: &Apache::loncommon::end_page({'frameset' => 1,
1262: 'js_ready' => 1,});
1263:
1.436 albertel 1264: my $template .= <<"ENDTEMPLATE";
1265: <script type="text/javascript">
1.253 albertel 1266: // <![CDATA[
1.692.4.10 raeburn 1267: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1268: var banner_link = '';
1.243 raeburn 1269: function helpMenu(target) {
1270: var caller = this;
1271: if (target == 'open') {
1272: var newWindow = null;
1273: try {
1.262 albertel 1274: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1275: }
1276: catch(error) {
1277: writeHelp(caller);
1278: return;
1279: }
1280: if (newWindow) {
1281: caller = newWindow;
1282: }
1.193 raeburn 1283: }
1.243 raeburn 1284: writeHelp(caller);
1285: return;
1286: }
1287: function writeHelp(caller) {
1.430 albertel 1288: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1289: caller.document.close()
1290: caller.focus()
1.193 raeburn 1291: }
1.219 albertel 1292: // END LON-CAPA Internal -->
1.692.4.10 raeburn 1293: // ]]>
1.436 albertel 1294: </script>
1.193 raeburn 1295: ENDTEMPLATE
1296: return $template;
1297: }
1298:
1.172 www 1299: sub help_open_bug {
1300: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1301: unless ($env{'user.adv'}) { return ''; }
1.172 www 1302: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1303: $text = "" if (not defined $text);
1304: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1305: if ($env{'browser.interface'} eq 'textual' ||
1306: $env{'environment.remote'} eq 'off' ) {
1.172 www 1307: $stayOnPage=1;
1308: }
1.184 albertel 1309: $width = 600 if (not defined $width);
1310: $height = 600 if (not defined $height);
1.172 www 1311:
1312: $topic=~s/\W+/\+/g;
1313: my $link='';
1314: my $template='';
1.379 albertel 1315: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1316: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1317: if (!$stayOnPage)
1318: {
1319: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1320: }
1321: else
1322: {
1323: $link = $url;
1324: }
1325: # Add the text
1326: if ($text ne "")
1327: {
1328: $template .=
1329: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1330: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1331: }
1332:
1333: # Add the graphic
1.179 matthew 1334: my $title = &mt('Report a Bug');
1.215 albertel 1335: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1336: $template .= <<"ENDTEMPLATE";
1.436 albertel 1337: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1338: ENDTEMPLATE
1339: if ($text ne '') { $template.='</td></tr></table>' };
1340: return $template;
1341:
1342: }
1343:
1344: sub help_open_faq {
1345: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1346: unless ($env{'user.adv'}) { return ''; }
1.172 www 1347: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1348: $text = "" if (not defined $text);
1349: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1350: if ($env{'browser.interface'} eq 'textual' ||
1351: $env{'environment.remote'} eq 'off' ) {
1.172 www 1352: $stayOnPage=1;
1353: }
1354: $width = 350 if (not defined $width);
1355: $height = 400 if (not defined $height);
1356:
1357: $topic=~s/\W+/\+/g;
1358: my $link='';
1359: my $template='';
1360: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1361: if (!$stayOnPage)
1362: {
1363: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1364: }
1365: else
1366: {
1367: $link = $url;
1368: }
1369:
1370: # Add the text
1371: if ($text ne "")
1372: {
1373: $template .=
1.173 www 1374: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1375: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1376: }
1377:
1378: # Add the graphic
1.179 matthew 1379: my $title = &mt('View the FAQ');
1.215 albertel 1380: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1381: $template .= <<"ENDTEMPLATE";
1.436 albertel 1382: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1383: ENDTEMPLATE
1384: if ($text ne '') { $template.='</td></tr></table>' };
1385: return $template;
1386:
1.44 bowersj2 1387: }
1.37 matthew 1388:
1.180 matthew 1389: ###############################################################
1390: ###############################################################
1391:
1.45 matthew 1392: =pod
1393:
1.648 raeburn 1394: =item * &change_content_javascript():
1.256 matthew 1395:
1396: This and the next function allow you to create small sections of an
1397: otherwise static HTML page that you can update on the fly with
1398: Javascript, even in Netscape 4.
1399:
1400: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1401: must be written to the HTML page once. It will prove the Javascript
1402: function "change(name, content)". Calling the change function with the
1403: name of the section
1404: you want to update, matching the name passed to C<changable_area>, and
1405: the new content you want to put in there, will put the content into
1406: that area.
1407:
1408: B<Note>: Netscape 4 only reserves enough space for the changable area
1409: to contain room for the original contents. You need to "make space"
1410: for whatever changes you wish to make, and be B<sure> to check your
1411: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1412: it's adequate for updating a one-line status display, but little more.
1413: This script will set the space to 100% width, so you only need to
1414: worry about height in Netscape 4.
1415:
1416: Modern browsers are much less limiting, and if you can commit to the
1417: user not using Netscape 4, this feature may be used freely with
1418: pretty much any HTML.
1419:
1420: =cut
1421:
1422: sub change_content_javascript {
1423: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1424: if ($env{'browser.type'} eq 'netscape' &&
1425: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1426: return (<<NETSCAPE4);
1427: function change(name, content) {
1428: doc = document.layers[name+"___escape"].layers[0].document;
1429: doc.open();
1430: doc.write(content);
1431: doc.close();
1432: }
1433: NETSCAPE4
1434: } else {
1435: # Otherwise, we need to use semi-standards-compliant code
1436: # (technically, "innerHTML" isn't standard but the equivalent
1437: # is really scary, and every useful browser supports it
1438: return (<<DOMBASED);
1439: function change(name, content) {
1440: element = document.getElementById(name);
1441: element.innerHTML = content;
1442: }
1443: DOMBASED
1444: }
1445: }
1446:
1447: =pod
1448:
1.648 raeburn 1449: =item * &changable_area($name,$origContent):
1.256 matthew 1450:
1451: This provides a "changable area" that can be modified on the fly via
1452: the Javascript code provided in C<change_content_javascript>. $name is
1453: the name you will use to reference the area later; do not repeat the
1454: same name on a given HTML page more then once. $origContent is what
1455: the area will originally contain, which can be left blank.
1456:
1457: =cut
1458:
1459: sub changable_area {
1460: my ($name, $origContent) = @_;
1461:
1.258 albertel 1462: if ($env{'browser.type'} eq 'netscape' &&
1463: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1464: # If this is netscape 4, we need to use the Layer tag
1465: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1466: } else {
1467: return "<span id='$name'>$origContent</span>";
1468: }
1469: }
1470:
1471: =pod
1472:
1.648 raeburn 1473: =item * &viewport_geometry_js
1.590 raeburn 1474:
1475: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1476:
1477: =cut
1478:
1479:
1480: sub viewport_geometry_js {
1481: return <<"GEOMETRY";
1482: var Geometry = {};
1483: function init_geometry() {
1484: if (Geometry.init) { return };
1485: Geometry.init=1;
1486: if (window.innerHeight) {
1487: Geometry.getViewportHeight = function() { return window.innerHeight; };
1488: Geometry.getViewportWidth = function() { return window.innerWidth; };
1489: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1490: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1491: }
1492: else if (document.documentElement && document.documentElement.clientHeight) {
1493: Geometry.getViewportHeight =
1494: function() { return document.documentElement.clientHeight; };
1495: Geometry.getViewportWidth =
1496: function() { return document.documentElement.clientWidth; };
1497:
1498: Geometry.getHorizontalScroll =
1499: function() { return document.documentElement.scrollLeft; };
1500: Geometry.getVerticalScroll =
1501: function() { return document.documentElement.scrollTop; };
1502: }
1503: else if (document.body.clientHeight) {
1504: Geometry.getViewportHeight =
1505: function() { return document.body.clientHeight; };
1506: Geometry.getViewportWidth =
1507: function() { return document.body.clientWidth; };
1508: Geometry.getHorizontalScroll =
1509: function() { return document.body.scrollLeft; };
1510: Geometry.getVerticalScroll =
1511: function() { return document.body.scrollTop; };
1512: }
1513: }
1514:
1515: GEOMETRY
1516: }
1517:
1518: =pod
1519:
1.648 raeburn 1520: =item * &viewport_size_js()
1.590 raeburn 1521:
1522: 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.
1523:
1524: =cut
1525:
1526: sub viewport_size_js {
1527: my $geometry = &viewport_geometry_js();
1528: return <<"DIMS";
1529:
1530: $geometry
1531:
1532: function getViewportDims(width,height) {
1533: init_geometry();
1534: width.value = Geometry.getViewportWidth();
1535: height.value = Geometry.getViewportHeight();
1536: return;
1537: }
1538:
1539: DIMS
1540: }
1541:
1542: =pod
1543:
1.648 raeburn 1544: =item * &resize_textarea_js()
1.565 albertel 1545:
1546: emits the needed javascript to resize a textarea to be as big as possible
1547:
1548: creates a function resize_textrea that takes two IDs first should be
1549: the id of the element to resize, second should be the id of a div that
1550: surrounds everything that comes after the textarea, this routine needs
1551: to be attached to the <body> for the onload and onresize events.
1552:
1.648 raeburn 1553: =back
1.565 albertel 1554:
1555: =cut
1556:
1557: sub resize_textarea_js {
1.590 raeburn 1558: my $geometry = &viewport_geometry_js();
1.565 albertel 1559: return <<"RESIZE";
1560: <script type="text/javascript">
1.692.4.4 raeburn 1561: // <![CDATA[
1.590 raeburn 1562: $geometry
1.565 albertel 1563:
1.588 albertel 1564: function getX(element) {
1565: var x = 0;
1566: while (element) {
1567: x += element.offsetLeft;
1568: element = element.offsetParent;
1569: }
1570: return x;
1571: }
1572: function getY(element) {
1573: var y = 0;
1574: while (element) {
1575: y += element.offsetTop;
1576: element = element.offsetParent;
1577: }
1578: return y;
1579: }
1580:
1581:
1.565 albertel 1582: function resize_textarea(textarea_id,bottom_id) {
1583: init_geometry();
1584: var textarea = document.getElementById(textarea_id);
1585: //alert(textarea);
1586:
1.588 albertel 1587: var textarea_top = getY(textarea);
1.565 albertel 1588: var textarea_height = textarea.offsetHeight;
1589: var bottom = document.getElementById(bottom_id);
1.588 albertel 1590: var bottom_top = getY(bottom);
1.565 albertel 1591: var bottom_height = bottom.offsetHeight;
1592: var window_height = Geometry.getViewportHeight();
1.588 albertel 1593: var fudge = 23;
1.565 albertel 1594: var new_height = window_height-fudge-textarea_top-bottom_height;
1595: if (new_height < 300) {
1596: new_height = 300;
1597: }
1598: textarea.style.height=new_height+'px';
1599: }
1.692.4.4 raeburn 1600: // ]]>
1.565 albertel 1601: </script>
1602: RESIZE
1603:
1604: }
1605:
1606: =pod
1607:
1.256 matthew 1608: =head1 Excel and CSV file utility routines
1609:
1610: =over 4
1611:
1612: =cut
1613:
1614: ###############################################################
1615: ###############################################################
1616:
1617: =pod
1618:
1.648 raeburn 1619: =item * &csv_translate($text)
1.37 matthew 1620:
1.185 www 1621: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1622: format.
1623:
1624: =cut
1625:
1.180 matthew 1626: ###############################################################
1627: ###############################################################
1.37 matthew 1628: sub csv_translate {
1629: my $text = shift;
1630: $text =~ s/\"/\"\"/g;
1.209 albertel 1631: $text =~ s/\n/ /g;
1.37 matthew 1632: return $text;
1633: }
1.180 matthew 1634:
1635: ###############################################################
1636: ###############################################################
1637:
1638: =pod
1639:
1.648 raeburn 1640: =item * &define_excel_formats()
1.180 matthew 1641:
1642: Define some commonly used Excel cell formats.
1643:
1644: Currently supported formats:
1645:
1646: =over 4
1647:
1648: =item header
1649:
1650: =item bold
1651:
1652: =item h1
1653:
1654: =item h2
1655:
1656: =item h3
1657:
1.256 matthew 1658: =item h4
1659:
1660: =item i
1661:
1.180 matthew 1662: =item date
1663:
1664: =back
1665:
1666: Inputs: $workbook
1667:
1668: Returns: $format, a hash reference.
1669:
1670: =cut
1671:
1672: ###############################################################
1673: ###############################################################
1674: sub define_excel_formats {
1675: my ($workbook) = @_;
1676: my $format;
1677: $format->{'header'} = $workbook->add_format(bold => 1,
1678: bottom => 1,
1679: align => 'center');
1680: $format->{'bold'} = $workbook->add_format(bold=>1);
1681: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1682: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1683: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1684: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1685: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1686: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1687: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1688: return $format;
1689: }
1690:
1691: ###############################################################
1692: ###############################################################
1.113 bowersj2 1693:
1694: =pod
1695:
1.648 raeburn 1696: =item * &create_workbook()
1.255 matthew 1697:
1698: Create an Excel worksheet. If it fails, output message on the
1699: request object and return undefs.
1700:
1701: Inputs: Apache request object
1702:
1703: Returns (undef) on failure,
1704: Excel worksheet object, scalar with filename, and formats
1705: from &Apache::loncommon::define_excel_formats on success
1706:
1707: =cut
1708:
1709: ###############################################################
1710: ###############################################################
1711: sub create_workbook {
1712: my ($r) = @_;
1713: #
1714: # Create the excel spreadsheet
1715: my $filename = '/prtspool/'.
1.258 albertel 1716: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1717: time.'_'.rand(1000000000).'.xls';
1718: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1719: if (! defined($workbook)) {
1720: $r->log_error("Error creating excel spreadsheet $filename: $!");
1721: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1722: "This error has been logged. ".
1723: "Please alert your LON-CAPA administrator").
1724: '</p>');
1725: return (undef);
1726: }
1727: #
1728: $workbook->set_tempdir('/home/httpd/perl/tmp');
1729: #
1730: my $format = &Apache::loncommon::define_excel_formats($workbook);
1731: return ($workbook,$filename,$format);
1732: }
1733:
1734: ###############################################################
1735: ###############################################################
1736:
1737: =pod
1738:
1.648 raeburn 1739: =item * &create_text_file()
1.113 bowersj2 1740:
1.542 raeburn 1741: Create a file to write to and eventually make available to the user.
1.256 matthew 1742: If file creation fails, outputs an error message on the request object and
1743: return undefs.
1.113 bowersj2 1744:
1.256 matthew 1745: Inputs: Apache request object, and file suffix
1.113 bowersj2 1746:
1.256 matthew 1747: Returns (undef) on failure,
1748: Filehandle and filename on success.
1.113 bowersj2 1749:
1750: =cut
1751:
1.256 matthew 1752: ###############################################################
1753: ###############################################################
1754: sub create_text_file {
1755: my ($r,$suffix) = @_;
1756: if (! defined($suffix)) { $suffix = 'txt'; };
1757: my $fh;
1758: my $filename = '/prtspool/'.
1.258 albertel 1759: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1760: time.'_'.rand(1000000000).'.'.$suffix;
1761: $fh = Apache::File->new('>/home/httpd'.$filename);
1762: if (! defined($fh)) {
1763: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1764: $r->print(&mt('Problems occurred in creating the output file. '
1765: .'This error has been logged. '
1766: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1767: }
1.256 matthew 1768: return ($fh,$filename)
1.113 bowersj2 1769: }
1770:
1771:
1.256 matthew 1772: =pod
1.113 bowersj2 1773:
1774: =back
1775:
1776: =cut
1.37 matthew 1777:
1778: ###############################################################
1.33 matthew 1779: ## Home server <option> list generating code ##
1780: ###############################################################
1.35 matthew 1781:
1.169 www 1782: # ------------------------------------------
1783:
1784: sub domain_select {
1785: my ($name,$value,$multiple)=@_;
1786: my %domains=map {
1.514 albertel 1787: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1788: } &Apache::lonnet::all_domains();
1.169 www 1789: if ($multiple) {
1790: $domains{''}=&mt('Any domain');
1.550 albertel 1791: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1792: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1793: } else {
1.550 albertel 1794: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1795: return &select_form($name,$value,%domains);
1796: }
1797: }
1798:
1.282 albertel 1799: #-------------------------------------------
1800:
1801: =pod
1802:
1.519 raeburn 1803: =head1 Routines for form select boxes
1804:
1805: =over 4
1806:
1.648 raeburn 1807: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1808:
1809: Returns a string containing a <select> element int multiple mode
1810:
1811:
1812: Args:
1813: $name - name of the <select> element
1.506 raeburn 1814: $value - scalar or array ref of values that should already be selected
1.282 albertel 1815: $size - number of rows long the select element is
1.283 albertel 1816: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1817: (shown text should already have been &mt())
1.506 raeburn 1818: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1819:
1.282 albertel 1820: =cut
1821:
1822: #-------------------------------------------
1.169 www 1823: sub multiple_select_form {
1.284 albertel 1824: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1825: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1826: my $output='';
1.191 matthew 1827: if (! defined($size)) {
1828: $size = 4;
1.283 albertel 1829: if (scalar(keys(%$hash))<4) {
1830: $size = scalar(keys(%$hash));
1.191 matthew 1831: }
1832: }
1.692.4.2 raeburn 1833: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1834: my @order;
1.506 raeburn 1835: if (ref($order) eq 'ARRAY') {
1836: @order = @{$order};
1837: } else {
1838: @order = sort(keys(%$hash));
1.501 banghart 1839: }
1840: if (exists($$hash{'select_form_order'})) {
1841: @order = @{$$hash{'select_form_order'}};
1842: }
1843:
1.284 albertel 1844: foreach my $key (@order) {
1.356 albertel 1845: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1846: $output.='selected="selected" ' if ($selected{$key});
1847: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1848: }
1849: $output.="</select>\n";
1850: return $output;
1851: }
1852:
1.88 www 1853: #-------------------------------------------
1854:
1855: =pod
1856:
1.648 raeburn 1857: =item * &select_form($defdom,$name,%hash)
1.88 www 1858:
1859: Returns a string containing a <select name='$name' size='1'> form to
1860: allow a user to select options from a hash option_name => displayed text.
1861: See lonrights.pm for an example invocation and use.
1862:
1863: =cut
1864:
1865: #-------------------------------------------
1866: sub select_form {
1867: my ($def,$name,%hash) = @_;
1868: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1869: my @keys;
1870: if (exists($hash{'select_form_order'})) {
1871: @keys=@{$hash{'select_form_order'}};
1872: } else {
1873: @keys=sort(keys(%hash));
1874: }
1.356 albertel 1875: foreach my $key (@keys) {
1876: $selectform.=
1877: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1878: ($key eq $def ? 'selected="selected" ' : '').
1879: ">".&mt($hash{$key})."</option>\n";
1.88 www 1880: }
1881: $selectform.="</select>";
1882: return $selectform;
1883: }
1884:
1.475 www 1885: # For display filters
1886:
1887: sub display_filter {
1888: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1889: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.692.4.2 raeburn 1890: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1891: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1892: (&mt('all'),10,20,50,100,1000,10000))).
1.692.4.2 raeburn 1893: '</label></span> <span class="LC_nobreak">'.
1.475 www 1894: &mt('Filter [_1]',
1.477 www 1895: &select_form($env{'form.displayfilter'},
1896: 'displayfilter',
1897: ('currentfolder' => 'Current folder/page',
1898: 'containing' => 'Containing phrase',
1899: 'none' => 'None'))).
1.692.4.2 raeburn 1900: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1901: }
1902:
1.167 www 1903: sub gradeleveldescription {
1904: my $gradelevel=shift;
1905: my %gradelevels=(0 => 'Not specified',
1906: 1 => 'Grade 1',
1907: 2 => 'Grade 2',
1908: 3 => 'Grade 3',
1909: 4 => 'Grade 4',
1910: 5 => 'Grade 5',
1911: 6 => 'Grade 6',
1912: 7 => 'Grade 7',
1913: 8 => 'Grade 8',
1914: 9 => 'Grade 9',
1915: 10 => 'Grade 10',
1916: 11 => 'Grade 11',
1917: 12 => 'Grade 12',
1918: 13 => 'Grade 13',
1919: 14 => '100 Level',
1920: 15 => '200 Level',
1921: 16 => '300 Level',
1922: 17 => '400 Level',
1923: 18 => 'Graduate Level');
1924: return &mt($gradelevels{$gradelevel});
1925: }
1926:
1.163 www 1927: sub select_level_form {
1928: my ($deflevel,$name)=@_;
1929: unless ($deflevel) { $deflevel=0; }
1.167 www 1930: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1931: for (my $i=0; $i<=18; $i++) {
1932: $selectform.="<option value=\"$i\" ".
1.253 albertel 1933: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1934: ">".&gradeleveldescription($i)."</option>\n";
1935: }
1936: $selectform.="</select>";
1937: return $selectform;
1.163 www 1938: }
1.167 www 1939:
1.35 matthew 1940: #-------------------------------------------
1941:
1.45 matthew 1942: =pod
1943:
1.692.4.7 raeburn 1944: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35 matthew 1945:
1946: Returns a string containing a <select name='$name' size='1'> form to
1947: allow a user to select the domain to preform an operation in.
1948: See loncreateuser.pm for an example invocation and use.
1949:
1.90 www 1950: If the $includeempty flag is set, it also includes an empty choice ("no domain
1951: selected");
1952:
1.692.4.2 raeburn 1953: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1954:
1.692.4.7 raeburn 1955: 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.
1.563 raeburn 1956:
1.35 matthew 1957: =cut
1958:
1959: #-------------------------------------------
1.34 matthew 1960: sub select_dom_form {
1.692.4.7 raeburn 1961: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
1962: if ($onchange) {
1963: $onchange = ' onchange="'.$onchange.'"';
1.692.4.2 raeburn 1964: }
1.550 albertel 1965: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1966: if ($includeempty) { @domains=('',@domains); }
1.692.4.2 raeburn 1967: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1968: foreach my $dom (@domains) {
1969: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1970: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1971: if ($showdomdesc) {
1972: if ($dom ne '') {
1973: my $domdesc = &Apache::lonnet::domain($dom,'description');
1974: if ($domdesc ne '') {
1975: $selectdomain .= ' ('.$domdesc.')';
1976: }
1977: }
1978: }
1979: $selectdomain .= "</option>\n";
1.34 matthew 1980: }
1981: $selectdomain.="</select>";
1982: return $selectdomain;
1983: }
1984:
1.35 matthew 1985: #-------------------------------------------
1986:
1.45 matthew 1987: =pod
1988:
1.648 raeburn 1989: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1990:
1.586 raeburn 1991: input: 4 arguments (two required, two optional) -
1992: $domain - domain of new user
1993: $name - name of form element
1994: $default - Value of 'default' causes a default item to be first
1995: option, and selected by default.
1996: $hide - Value of 'hide' causes hiding of the name of the server,
1997: if 1 server found, or default, if 0 found.
1.594 raeburn 1998: output: returns 2 items:
1.586 raeburn 1999: (a) form element which contains either:
2000: (i) <select name="$name">
2001: <option value="$hostid1">$hostid $servers{$hostid}</option>
2002: <option value="$hostid2">$hostid $servers{$hostid}</option>
2003: </select>
2004: form item if there are multiple library servers in $domain, or
2005: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2006: if there is only one library server in $domain.
2007:
2008: (b) number of library servers found.
2009:
2010: See loncreateuser.pm for example of use.
1.35 matthew 2011:
2012: =cut
2013:
2014: #-------------------------------------------
1.586 raeburn 2015: sub home_server_form_item {
2016: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2017: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2018: my $result;
2019: my $numlib = keys(%servers);
2020: if ($numlib > 1) {
2021: $result .= '<select name="'.$name.'" />'."\n";
2022: if ($default) {
1.692.4.2 raeburn 2023: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2024: '</option>'."\n";
2025: }
2026: foreach my $hostid (sort(keys(%servers))) {
2027: $result.= '<option value="'.$hostid.'">'.
2028: $hostid.' '.$servers{$hostid}."</option>\n";
2029: }
2030: $result .= '</select>'."\n";
2031: } elsif ($numlib == 1) {
2032: my $hostid;
2033: foreach my $item (keys(%servers)) {
2034: $hostid = $item;
2035: }
2036: $result .= '<input type="hidden" name="'.$name.'" value="'.
2037: $hostid.'" />';
2038: if (!$hide) {
2039: $result .= $hostid.' '.$servers{$hostid};
2040: }
2041: $result .= "\n";
2042: } elsif ($default) {
2043: $result .= '<input type="hidden" name="'.$name.
2044: '" value="default" />';
2045: if (!$hide) {
2046: $result .= &mt('default');
2047: }
2048: $result .= "\n";
1.33 matthew 2049: }
1.586 raeburn 2050: return ($result,$numlib);
1.33 matthew 2051: }
1.112 bowersj2 2052:
2053: =pod
2054:
1.534 albertel 2055: =back
2056:
1.112 bowersj2 2057: =cut
1.87 matthew 2058:
2059: ###############################################################
1.112 bowersj2 2060: ## Decoding User Agent ##
1.87 matthew 2061: ###############################################################
2062:
2063: =pod
2064:
1.112 bowersj2 2065: =head1 Decoding the User Agent
2066:
2067: =over 4
2068:
2069: =item * &decode_user_agent()
1.87 matthew 2070:
2071: Inputs: $r
2072:
2073: Outputs:
2074:
2075: =over 4
2076:
1.112 bowersj2 2077: =item * $httpbrowser
1.87 matthew 2078:
1.112 bowersj2 2079: =item * $clientbrowser
1.87 matthew 2080:
1.112 bowersj2 2081: =item * $clientversion
1.87 matthew 2082:
1.112 bowersj2 2083: =item * $clientmathml
1.87 matthew 2084:
1.112 bowersj2 2085: =item * $clientunicode
1.87 matthew 2086:
1.112 bowersj2 2087: =item * $clientos
1.87 matthew 2088:
2089: =back
2090:
1.157 matthew 2091: =back
2092:
1.87 matthew 2093: =cut
2094:
2095: ###############################################################
2096: ###############################################################
2097: sub decode_user_agent {
1.247 albertel 2098: my ($r)=@_;
1.87 matthew 2099: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2100: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2101: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2102: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2103: my $clientbrowser='unknown';
2104: my $clientversion='0';
2105: my $clientmathml='';
2106: my $clientunicode='0';
2107: for (my $i=0;$i<=$#browsertype;$i++) {
2108: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2109: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2110: $clientbrowser=$bname;
2111: $httpbrowser=~/$vreg/i;
2112: $clientversion=$1;
2113: $clientmathml=($clientversion>=$minv);
2114: $clientunicode=($clientversion>=$univ);
2115: }
2116: }
2117: my $clientos='unknown';
2118: if (($httpbrowser=~/linux/i) ||
2119: ($httpbrowser=~/unix/i) ||
2120: ($httpbrowser=~/ux/i) ||
2121: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2122: if (($httpbrowser=~/vax/i) ||
2123: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2124: if ($httpbrowser=~/next/i) { $clientos='next'; }
2125: if (($httpbrowser=~/mac/i) ||
2126: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2127: if ($httpbrowser=~/win/i) { $clientos='win'; }
2128: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2129: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2130: $clientunicode,$clientos,);
2131: }
2132:
1.32 matthew 2133: ###############################################################
2134: ## Authentication changing form generation subroutines ##
2135: ###############################################################
2136: ##
2137: ## All of the authform_xxxxxxx subroutines take their inputs in a
2138: ## hash, and have reasonable default values.
2139: ##
2140: ## formname = the name given in the <form> tag.
1.35 matthew 2141: #-------------------------------------------
2142:
1.45 matthew 2143: =pod
2144:
1.112 bowersj2 2145: =head1 Authentication Routines
2146:
2147: =over 4
2148:
1.648 raeburn 2149: =item * &authform_xxxxxx()
1.35 matthew 2150:
2151: The authform_xxxxxx subroutines provide javascript and html forms which
2152: handle some of the conveniences required for authentication forms.
2153: This is not an optimal method, but it works.
2154:
2155: =over 4
2156:
1.112 bowersj2 2157: =item * authform_header
1.35 matthew 2158:
1.112 bowersj2 2159: =item * authform_authorwarning
1.35 matthew 2160:
1.112 bowersj2 2161: =item * authform_nochange
1.35 matthew 2162:
1.112 bowersj2 2163: =item * authform_kerberos
1.35 matthew 2164:
1.112 bowersj2 2165: =item * authform_internal
1.35 matthew 2166:
1.112 bowersj2 2167: =item * authform_filesystem
1.35 matthew 2168:
2169: =back
2170:
1.648 raeburn 2171: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2172:
1.35 matthew 2173: =cut
2174:
2175: #-------------------------------------------
1.32 matthew 2176: sub authform_header{
2177: my %in = (
2178: formname => 'cu',
1.80 albertel 2179: kerb_def_dom => '',
1.32 matthew 2180: @_,
2181: );
2182: $in{'formname'} = 'document.' . $in{'formname'};
2183: my $result='';
1.80 albertel 2184:
2185: #---------------------------------------------- Code for upper case translation
2186: my $Javascript_toUpperCase;
2187: unless ($in{kerb_def_dom}) {
2188: $Javascript_toUpperCase =<<"END";
2189: switch (choice) {
2190: case 'krb': currentform.elements[choicearg].value =
2191: currentform.elements[choicearg].value.toUpperCase();
2192: break;
2193: default:
2194: }
2195: END
2196: } else {
2197: $Javascript_toUpperCase = "";
2198: }
2199:
1.165 raeburn 2200: my $radioval = "'nochange'";
1.591 raeburn 2201: if (defined($in{'curr_authtype'})) {
2202: if ($in{'curr_authtype'} ne '') {
2203: $radioval = "'".$in{'curr_authtype'}."arg'";
2204: }
1.174 matthew 2205: }
1.165 raeburn 2206: my $argfield = 'null';
1.591 raeburn 2207: if (defined($in{'mode'})) {
1.165 raeburn 2208: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2209: if (defined($in{'curr_autharg'})) {
2210: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2211: $argfield = "'$in{'curr_autharg'}'";
2212: }
2213: }
2214: }
2215: }
2216:
1.32 matthew 2217: $result.=<<"END";
2218: var current = new Object();
1.165 raeburn 2219: current.radiovalue = $radioval;
2220: current.argfield = $argfield;
1.32 matthew 2221:
2222: function changed_radio(choice,currentform) {
2223: var choicearg = choice + 'arg';
2224: // If a radio button in changed, we need to change the argfield
2225: if (current.radiovalue != choice) {
2226: current.radiovalue = choice;
2227: if (current.argfield != null) {
2228: currentform.elements[current.argfield].value = '';
2229: }
2230: if (choice == 'nochange') {
2231: current.argfield = null;
2232: } else {
2233: current.argfield = choicearg;
2234: switch(choice) {
2235: case 'krb':
2236: currentform.elements[current.argfield].value =
2237: "$in{'kerb_def_dom'}";
2238: break;
2239: default:
2240: break;
2241: }
2242: }
2243: }
2244: return;
2245: }
1.22 www 2246:
1.32 matthew 2247: function changed_text(choice,currentform) {
2248: var choicearg = choice + 'arg';
2249: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2250: $Javascript_toUpperCase
1.32 matthew 2251: // clear old field
2252: if ((current.argfield != choicearg) && (current.argfield != null)) {
2253: currentform.elements[current.argfield].value = '';
2254: }
2255: current.argfield = choicearg;
2256: }
2257: set_auth_radio_buttons(choice,currentform);
2258: return;
1.20 www 2259: }
1.32 matthew 2260:
2261: function set_auth_radio_buttons(newvalue,currentform) {
2262: var i=0;
2263: while (i < currentform.login.length) {
2264: if (currentform.login[i].value == newvalue) { break; }
2265: i++;
2266: }
2267: if (i == currentform.login.length) {
2268: return;
2269: }
2270: current.radiovalue = newvalue;
2271: currentform.login[i].checked = true;
2272: return;
2273: }
2274: END
2275: return $result;
2276: }
2277:
2278: sub authform_authorwarning{
2279: my $result='';
1.144 matthew 2280: $result='<i>'.
2281: &mt('As a general rule, only authors or co-authors should be '.
2282: 'filesystem authenticated '.
2283: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2284: return $result;
2285: }
2286:
2287: sub authform_nochange{
2288: my %in = (
2289: formname => 'document.cu',
2290: kerb_def_dom => 'MSU.EDU',
2291: @_,
2292: );
1.586 raeburn 2293: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2294: my $result;
2295: if (keys(%can_assign) == 0) {
2296: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2297: } else {
2298: $result = '<label>'.&mt('[_1] Do not change login data',
2299: '<input type="radio" name="login" value="nochange" '.
2300: 'checked="checked" onclick="'.
1.281 albertel 2301: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2302: '</label>';
1.586 raeburn 2303: }
1.32 matthew 2304: return $result;
2305: }
2306:
1.591 raeburn 2307: sub authform_kerberos {
1.32 matthew 2308: my %in = (
2309: formname => 'document.cu',
2310: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2311: kerb_def_auth => 'krb4',
1.32 matthew 2312: @_,
2313: );
1.586 raeburn 2314: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2315: $autharg,$jscall);
2316: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2317: if ($in{'kerb_def_auth'} eq 'krb5') {
1.692.4.2 raeburn 2318: $check5 = ' checked="checked"';
1.80 albertel 2319: } else {
1.692.4.2 raeburn 2320: $check4 = ' checked="checked"';
1.80 albertel 2321: }
1.165 raeburn 2322: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2323: if (defined($in{'curr_authtype'})) {
2324: if ($in{'curr_authtype'} eq 'krb') {
1.692.4.2 raeburn 2325: $krbcheck = ' checked="checked"';
1.623 raeburn 2326: if (defined($in{'mode'})) {
2327: if ($in{'mode'} eq 'modifyuser') {
2328: $krbcheck = '';
2329: }
2330: }
1.591 raeburn 2331: if (defined($in{'curr_kerb_ver'})) {
2332: if ($in{'curr_krb_ver'} eq '5') {
1.692.4.2 raeburn 2333: $check5 = ' checked="checked"';
1.591 raeburn 2334: $check4 = '';
2335: } else {
1.692.4.2 raeburn 2336: $check4 = ' checked="checked"';
1.591 raeburn 2337: $check5 = '';
2338: }
1.586 raeburn 2339: }
1.591 raeburn 2340: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2341: $krbarg = $in{'curr_autharg'};
2342: }
1.586 raeburn 2343: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2344: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2345: $result =
2346: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2347: $in{'curr_autharg'},$krbver);
2348: } else {
2349: $result =
2350: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2351: }
2352: return $result;
2353: }
2354: }
2355: } else {
2356: if ($authnum == 1) {
1.692.4.2 raeburn 2357: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2358: }
2359: }
1.586 raeburn 2360: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2361: return;
1.587 raeburn 2362: } elsif ($authtype eq '') {
1.591 raeburn 2363: if (defined($in{'mode'})) {
1.587 raeburn 2364: if ($in{'mode'} eq 'modifycourse') {
2365: if ($authnum == 1) {
1.692.4.2 raeburn 2366: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2367: }
2368: }
2369: }
1.586 raeburn 2370: }
2371: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2372: if ($authtype eq '') {
2373: $authtype = '<input type="radio" name="login" value="krb" '.
2374: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2375: $krbcheck.' />';
2376: }
2377: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2378: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2379: $in{'curr_authtype'} eq 'krb5') ||
2380: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2381: $in{'curr_authtype'} eq 'krb4')) {
2382: $result .= &mt
1.144 matthew 2383: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2384: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2385: '<label>'.$authtype,
1.281 albertel 2386: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2387: 'value="'.$krbarg.'" '.
1.144 matthew 2388: 'onchange="'.$jscall.'" />',
1.281 albertel 2389: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2390: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2391: '</label>');
1.586 raeburn 2392: } elsif ($can_assign{'krb4'}) {
2393: $result .= &mt
2394: ('[_1] Kerberos authenticated with domain [_2] '.
2395: '[_3] Version 4 [_4]',
2396: '<label>'.$authtype,
2397: '</label><input type="text" size="10" name="krbarg" '.
2398: 'value="'.$krbarg.'" '.
2399: 'onchange="'.$jscall.'" />',
2400: '<label><input type="hidden" name="krbver" value="4" />',
2401: '</label>');
2402: } elsif ($can_assign{'krb5'}) {
2403: $result .= &mt
2404: ('[_1] Kerberos authenticated with domain [_2] '.
2405: '[_3] Version 5 [_4]',
2406: '<label>'.$authtype,
2407: '</label><input type="text" size="10" name="krbarg" '.
2408: 'value="'.$krbarg.'" '.
2409: 'onchange="'.$jscall.'" />',
2410: '<label><input type="hidden" name="krbver" value="5" />',
2411: '</label>');
2412: }
1.32 matthew 2413: return $result;
2414: }
2415:
2416: sub authform_internal{
1.586 raeburn 2417: my %in = (
1.32 matthew 2418: formname => 'document.cu',
2419: kerb_def_dom => 'MSU.EDU',
2420: @_,
2421: );
1.586 raeburn 2422: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2423: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2424: if (defined($in{'curr_authtype'})) {
2425: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2426: if ($can_assign{'int'}) {
1.692.4.2 raeburn 2427: $intcheck = 'checked="checked" ';
1.623 raeburn 2428: if (defined($in{'mode'})) {
2429: if ($in{'mode'} eq 'modifyuser') {
2430: $intcheck = '';
2431: }
2432: }
1.591 raeburn 2433: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2434: $intarg = $in{'curr_autharg'};
2435: }
2436: } else {
2437: $result = &mt('Currently internally authenticated.');
2438: return $result;
1.165 raeburn 2439: }
2440: }
1.586 raeburn 2441: } else {
2442: if ($authnum == 1) {
1.692.4.2 raeburn 2443: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2444: }
2445: }
2446: if (!$can_assign{'int'}) {
2447: return;
1.587 raeburn 2448: } elsif ($authtype eq '') {
1.591 raeburn 2449: if (defined($in{'mode'})) {
1.587 raeburn 2450: if ($in{'mode'} eq 'modifycourse') {
2451: if ($authnum == 1) {
1.692.4.2 raeburn 2452: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2453: }
2454: }
2455: }
1.165 raeburn 2456: }
1.586 raeburn 2457: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2458: if ($authtype eq '') {
2459: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2460: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2461: }
1.605 bisitz 2462: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2463: $intarg.'" onchange="'.$jscall.'" />';
2464: $result = &mt
1.144 matthew 2465: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2466: '<label>'.$authtype,'</label>'.$autharg);
1.692.4.4 raeburn 2467: $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 2468: return $result;
2469: }
2470:
2471: sub authform_local{
2472: my %in = (
2473: formname => 'document.cu',
2474: kerb_def_dom => 'MSU.EDU',
2475: @_,
2476: );
1.586 raeburn 2477: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2478: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2479: if (defined($in{'curr_authtype'})) {
2480: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2481: if ($can_assign{'loc'}) {
1.692.4.2 raeburn 2482: $loccheck = 'checked="checked" ';
1.623 raeburn 2483: if (defined($in{'mode'})) {
2484: if ($in{'mode'} eq 'modifyuser') {
2485: $loccheck = '';
2486: }
2487: }
1.591 raeburn 2488: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2489: $locarg = $in{'curr_autharg'};
2490: }
2491: } else {
2492: $result = &mt('Currently using local (institutional) authentication.');
2493: return $result;
1.165 raeburn 2494: }
2495: }
1.586 raeburn 2496: } else {
2497: if ($authnum == 1) {
1.692.4.2 raeburn 2498: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2499: }
2500: }
2501: if (!$can_assign{'loc'}) {
2502: return;
1.587 raeburn 2503: } elsif ($authtype eq '') {
1.591 raeburn 2504: if (defined($in{'mode'})) {
1.587 raeburn 2505: if ($in{'mode'} eq 'modifycourse') {
2506: if ($authnum == 1) {
1.692.4.2 raeburn 2507: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2508: }
2509: }
2510: }
1.165 raeburn 2511: }
1.586 raeburn 2512: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2513: if ($authtype eq '') {
2514: $authtype = '<input type="radio" name="login" value="loc" '.
2515: $loccheck.' onchange="'.$jscall.'" onclick="'.
2516: $jscall.'" />';
2517: }
2518: $autharg = '<input type="text" size="10" name="locarg" value="'.
2519: $locarg.'" onchange="'.$jscall.'" />';
2520: $result = &mt('[_1] Local Authentication with argument [_2]',
2521: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2522: return $result;
2523: }
2524:
2525: sub authform_filesystem{
2526: my %in = (
2527: formname => 'document.cu',
2528: kerb_def_dom => 'MSU.EDU',
2529: @_,
2530: );
1.586 raeburn 2531: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2532: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2533: if (defined($in{'curr_authtype'})) {
2534: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2535: if ($can_assign{'fsys'}) {
1.692.4.2 raeburn 2536: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2537: if (defined($in{'mode'})) {
2538: if ($in{'mode'} eq 'modifyuser') {
2539: $fsyscheck = '';
2540: }
2541: }
1.586 raeburn 2542: } else {
2543: $result = &mt('Currently Filesystem Authenticated.');
2544: return $result;
2545: }
2546: }
2547: } else {
2548: if ($authnum == 1) {
1.692.4.2 raeburn 2549: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2550: }
2551: }
2552: if (!$can_assign{'fsys'}) {
2553: return;
1.587 raeburn 2554: } elsif ($authtype eq '') {
1.591 raeburn 2555: if (defined($in{'mode'})) {
1.587 raeburn 2556: if ($in{'mode'} eq 'modifycourse') {
2557: if ($authnum == 1) {
1.692.4.2 raeburn 2558: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2559: }
2560: }
2561: }
1.586 raeburn 2562: }
2563: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2564: if ($authtype eq '') {
2565: $authtype = '<input type="radio" name="login" value="fsys" '.
2566: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2567: $jscall.'" />';
2568: }
2569: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2570: ' onchange="'.$jscall.'" />';
2571: $result = &mt
1.144 matthew 2572: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2573: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2574: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2575: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2576: 'onchange="'.$jscall.'" />');
1.32 matthew 2577: return $result;
2578: }
2579:
1.586 raeburn 2580: sub get_assignable_auth {
2581: my ($dom) = @_;
2582: if ($dom eq '') {
2583: $dom = $env{'request.role.domain'};
2584: }
2585: my %can_assign = (
2586: krb4 => 1,
2587: krb5 => 1,
2588: int => 1,
2589: loc => 1,
2590: );
2591: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2592: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2593: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2594: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2595: my $context;
2596: if ($env{'request.role'} =~ /^au/) {
2597: $context = 'author';
2598: } elsif ($env{'request.role'} =~ /^dc/) {
2599: $context = 'domain';
2600: } elsif ($env{'request.course.id'}) {
2601: $context = 'course';
2602: }
2603: if ($context) {
2604: if (ref($authhash->{$context}) eq 'HASH') {
2605: %can_assign = %{$authhash->{$context}};
2606: }
2607: }
2608: }
2609: }
2610: my $authnum = 0;
2611: foreach my $key (keys(%can_assign)) {
2612: if ($can_assign{$key}) {
2613: $authnum ++;
2614: }
2615: }
2616: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2617: $authnum --;
2618: }
2619: return ($authnum,%can_assign);
2620: }
2621:
1.80 albertel 2622: ###############################################################
2623: ## Get Kerberos Defaults for Domain ##
2624: ###############################################################
2625: ##
2626: ## Returns default kerberos version and an associated argument
2627: ## as listed in file domain.tab. If not listed, provides
2628: ## appropriate default domain and kerberos version.
2629: ##
2630: #-------------------------------------------
2631:
2632: =pod
2633:
1.648 raeburn 2634: =item * &get_kerberos_defaults()
1.80 albertel 2635:
2636: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2637: version and domain. If not found, it defaults to version 4 and the
2638: domain of the server.
1.80 albertel 2639:
1.648 raeburn 2640: =over 4
2641:
1.80 albertel 2642: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2643:
1.648 raeburn 2644: =back
2645:
2646: =back
2647:
1.80 albertel 2648: =cut
2649:
2650: #-------------------------------------------
2651: sub get_kerberos_defaults {
2652: my $domain=shift;
1.641 raeburn 2653: my ($krbdef,$krbdefdom);
2654: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2655: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2656: $krbdef = $domdefaults{'auth_def'};
2657: $krbdefdom = $domdefaults{'auth_arg_def'};
2658: } else {
1.80 albertel 2659: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2660: my $krbdefdom=$1;
2661: $krbdefdom=~tr/a-z/A-Z/;
2662: $krbdef = "krb4";
2663: }
2664: return ($krbdef,$krbdefdom);
2665: }
1.112 bowersj2 2666:
1.32 matthew 2667:
1.46 matthew 2668: ###############################################################
2669: ## Thesaurus Functions ##
2670: ###############################################################
1.20 www 2671:
1.46 matthew 2672: =pod
1.20 www 2673:
1.112 bowersj2 2674: =head1 Thesaurus Functions
2675:
2676: =over 4
2677:
1.648 raeburn 2678: =item * &initialize_keywords()
1.46 matthew 2679:
2680: Initializes the package variable %Keywords if it is empty. Uses the
2681: package variable $thesaurus_db_file.
2682:
2683: =cut
2684:
2685: ###################################################
2686:
2687: sub initialize_keywords {
2688: return 1 if (scalar keys(%Keywords));
2689: # If we are here, %Keywords is empty, so fill it up
2690: # Make sure the file we need exists...
2691: if (! -e $thesaurus_db_file) {
2692: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2693: " failed because it does not exist");
2694: return 0;
2695: }
2696: # Set up the hash as a database
2697: my %thesaurus_db;
2698: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2699: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2700: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2701: $thesaurus_db_file);
2702: return 0;
2703: }
2704: # Get the average number of appearances of a word.
2705: my $avecount = $thesaurus_db{'average.count'};
2706: # Put keywords (those that appear > average) into %Keywords
2707: while (my ($word,$data)=each (%thesaurus_db)) {
2708: my ($count,undef) = split /:/,$data;
2709: $Keywords{$word}++ if ($count > $avecount);
2710: }
2711: untie %thesaurus_db;
2712: # Remove special values from %Keywords.
1.356 albertel 2713: foreach my $value ('total.count','average.count') {
2714: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2715: }
1.46 matthew 2716: return 1;
2717: }
2718:
2719: ###################################################
2720:
2721: =pod
2722:
1.648 raeburn 2723: =item * &keyword($word)
1.46 matthew 2724:
2725: Returns true if $word is a keyword. A keyword is a word that appears more
2726: than the average number of times in the thesaurus database. Calls
2727: &initialize_keywords
2728:
2729: =cut
2730:
2731: ###################################################
1.20 www 2732:
2733: sub keyword {
1.46 matthew 2734: return if (!&initialize_keywords());
2735: my $word=lc(shift());
2736: $word=~s/\W//g;
2737: return exists($Keywords{$word});
1.20 www 2738: }
1.46 matthew 2739:
2740: ###############################################################
2741:
2742: =pod
1.20 www 2743:
1.648 raeburn 2744: =item * &get_related_words()
1.46 matthew 2745:
1.160 matthew 2746: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2747: an array of words. If the keyword is not in the thesaurus, an empty array
2748: will be returned. The order of the words returned is determined by the
2749: database which holds them.
2750:
2751: Uses global $thesaurus_db_file.
2752:
2753: =cut
2754:
2755: ###############################################################
2756: sub get_related_words {
2757: my $keyword = shift;
2758: my %thesaurus_db;
2759: if (! -e $thesaurus_db_file) {
2760: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2761: "failed because the file does not exist");
2762: return ();
2763: }
2764: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2765: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2766: return ();
2767: }
2768: my @Words=();
1.429 www 2769: my $count=0;
1.46 matthew 2770: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2771: # The first element is the number of times
2772: # the word appears. We do not need it now.
1.429 www 2773: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2774: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2775: my $threshold=$mostfrequentcount/10;
2776: foreach my $possibleword (@RelatedWords) {
2777: my ($word,$wordcount)=split(/\,/,$possibleword);
2778: if ($wordcount>$threshold) {
2779: push(@Words,$word);
2780: $count++;
2781: if ($count>10) { last; }
2782: }
1.20 www 2783: }
2784: }
1.46 matthew 2785: untie %thesaurus_db;
2786: return @Words;
1.14 harris41 2787: }
1.46 matthew 2788:
1.112 bowersj2 2789: =pod
2790:
2791: =back
2792:
2793: =cut
1.61 www 2794:
2795: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2796: =pod
2797:
1.112 bowersj2 2798: =head1 User Name Functions
2799:
2800: =over 4
2801:
1.648 raeburn 2802: =item * &plainname($uname,$udom,$first)
1.81 albertel 2803:
1.112 bowersj2 2804: Takes a users logon name and returns it as a string in
1.226 albertel 2805: "first middle last generation" form
2806: if $first is set to 'lastname' then it returns it as
2807: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2808:
2809: =cut
1.61 www 2810:
1.295 www 2811:
1.81 albertel 2812: ###############################################################
1.61 www 2813: sub plainname {
1.226 albertel 2814: my ($uname,$udom,$first)=@_;
1.537 albertel 2815: return if (!defined($uname) || !defined($udom));
1.295 www 2816: my %names=&getnames($uname,$udom);
1.226 albertel 2817: my $name=&Apache::lonnet::format_name($names{'firstname'},
2818: $names{'middlename'},
2819: $names{'lastname'},
2820: $names{'generation'},$first);
2821: $name=~s/^\s+//;
1.62 www 2822: $name=~s/\s+$//;
2823: $name=~s/\s+/ /g;
1.353 albertel 2824: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2825: return $name;
1.61 www 2826: }
1.66 www 2827:
2828: # -------------------------------------------------------------------- Nickname
1.81 albertel 2829: =pod
2830:
1.648 raeburn 2831: =item * &nickname($uname,$udom)
1.81 albertel 2832:
2833: Gets a users name and returns it as a string as
2834:
2835: ""nickname""
1.66 www 2836:
1.81 albertel 2837: if the user has a nickname or
2838:
2839: "first middle last generation"
2840:
2841: if the user does not
2842:
2843: =cut
1.66 www 2844:
2845: sub nickname {
2846: my ($uname,$udom)=@_;
1.537 albertel 2847: return if (!defined($uname) || !defined($udom));
1.295 www 2848: my %names=&getnames($uname,$udom);
1.68 albertel 2849: my $name=$names{'nickname'};
1.66 www 2850: if ($name) {
2851: $name='"'.$name.'"';
2852: } else {
2853: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2854: $names{'lastname'}.' '.$names{'generation'};
2855: $name=~s/\s+$//;
2856: $name=~s/\s+/ /g;
2857: }
2858: return $name;
2859: }
2860:
1.295 www 2861: sub getnames {
2862: my ($uname,$udom)=@_;
1.537 albertel 2863: return if (!defined($uname) || !defined($udom));
1.433 albertel 2864: if ($udom eq 'public' && $uname eq 'public') {
2865: return ('lastname' => &mt('Public'));
2866: }
1.295 www 2867: my $id=$uname.':'.$udom;
2868: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2869: if ($cached) {
2870: return %{$names};
2871: } else {
2872: my %loadnames=&Apache::lonnet::get('environment',
2873: ['firstname','middlename','lastname','generation','nickname'],
2874: $udom,$uname);
2875: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2876: return %loadnames;
2877: }
2878: }
1.61 www 2879:
1.542 raeburn 2880: # -------------------------------------------------------------------- getemails
1.648 raeburn 2881:
1.542 raeburn 2882: =pod
2883:
1.648 raeburn 2884: =item * &getemails($uname,$udom)
1.542 raeburn 2885:
2886: Gets a user's email information and returns it as a hash with keys:
2887: notification, critnotification, permanentemail
2888:
2889: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2890: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2891:
1.648 raeburn 2892:
1.542 raeburn 2893: =cut
2894:
1.648 raeburn 2895:
1.466 albertel 2896: sub getemails {
2897: my ($uname,$udom)=@_;
2898: if ($udom eq 'public' && $uname eq 'public') {
2899: return;
2900: }
1.467 www 2901: if (!$udom) { $udom=$env{'user.domain'}; }
2902: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2903: my $id=$uname.':'.$udom;
2904: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2905: if ($cached) {
2906: return %{$names};
2907: } else {
2908: my %loadnames=&Apache::lonnet::get('environment',
2909: ['notification','critnotification',
2910: 'permanentemail'],
2911: $udom,$uname);
2912: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2913: return %loadnames;
2914: }
2915: }
2916:
1.551 albertel 2917: sub flush_email_cache {
2918: my ($uname,$udom)=@_;
2919: if (!$udom) { $udom =$env{'user.domain'}; }
2920: if (!$uname) { $uname=$env{'user.name'}; }
2921: return if ($udom eq 'public' && $uname eq 'public');
2922: my $id=$uname.':'.$udom;
2923: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2924: }
2925:
1.692.4.2 raeburn 2926: # -------------------------------------------------------------------- getlangs
2927:
2928: =pod
2929:
2930: =item * &getlangs($uname,$udom)
2931:
2932: Gets a user's language preference and returns it as a hash with key:
2933: language.
2934:
2935: =cut
2936:
2937:
2938: sub getlangs {
2939: my ($uname,$udom) = @_;
2940: if (!$udom) { $udom =$env{'user.domain'}; }
2941: if (!$uname) { $uname=$env{'user.name'}; }
2942: my $id=$uname.':'.$udom;
2943: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2944: if ($cached) {
2945: return %{$langs};
2946: } else {
2947: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2948: $udom,$uname);
2949: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2950: return %loadlangs;
2951: }
2952: }
2953:
2954: sub flush_langs_cache {
2955: my ($uname,$udom)=@_;
2956: if (!$udom) { $udom =$env{'user.domain'}; }
2957: if (!$uname) { $uname=$env{'user.name'}; }
2958: return if ($udom eq 'public' && $uname eq 'public');
2959: my $id=$uname.':'.$udom;
2960: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2961: }
2962:
1.61 www 2963: # ------------------------------------------------------------------ Screenname
1.81 albertel 2964:
2965: =pod
2966:
1.648 raeburn 2967: =item * &screenname($uname,$udom)
1.81 albertel 2968:
2969: Gets a users screenname and returns it as a string
2970:
2971: =cut
1.61 www 2972:
2973: sub screenname {
2974: my ($uname,$udom)=@_;
1.258 albertel 2975: if ($uname eq $env{'user.name'} &&
2976: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2977: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2978: return $names{'screenname'};
1.62 www 2979: }
2980:
1.692.4.2 raeburn 2981: # ------------------------------------------------------------- Confirm Wrapper
2982: =pod
2983:
2984: =item confirmwrapper
2985:
2986: Wrap messages about completion of operation in box
2987:
2988: =cut
2989:
2990: sub confirmwrapper {
2991: my ($message)=@_;
2992: if ($message) {
2993: return "\n".'<div class="LC_confirm_box">'."\n"
2994: .$message."\n"
2995: .'</div>'."\n";
2996: } else {
2997: return $message;
2998: }
2999: }
1.212 albertel 3000:
1.62 www 3001: # ------------------------------------------------------------- Message Wrapper
3002:
3003: sub messagewrapper {
1.369 www 3004: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3005: return
1.441 albertel 3006: '<a href="/adm/email?compose=individual&'.
3007: 'recname='.$username.'&recdom='.$domain.
3008: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3009: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3010: }
3011: # --------------------------------------------------------------- Notes Wrapper
3012:
3013: sub noteswrapper {
3014: my ($link,$un,$do)=@_;
3015: return
3016: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3017: }
3018: # ------------------------------------------------------------- Aboutme Wrapper
3019:
3020: sub aboutmewrapper {
1.166 www 3021: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 3022: if (!defined($username) && !defined($domain)) {
3023: return;
3024: }
1.205 www 3025: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.692.4.2 raeburn 3026: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3027: }
3028:
3029: # ------------------------------------------------------------ Syllabus Wrapper
3030:
3031:
3032: sub syllabuswrapper {
1.109 matthew 3033: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
3034: if ($fontcolor) {
3035: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
3036: }
1.208 matthew 3037: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3038: }
1.14 harris41 3039:
1.208 matthew 3040: sub track_student_link {
1.692.4.17 raeburn 3041: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3042: my $link ="/adm/trackstudent?";
1.208 matthew 3043: my $title = 'View recent activity';
3044: if (defined($sname) && $sname !~ /^\s*$/ &&
3045: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3046: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3047: $title .= ' of this student';
1.268 albertel 3048: }
1.208 matthew 3049: if (defined($target) && $target !~ /^\s*$/) {
3050: $target = qq{target="$target"};
3051: } else {
3052: $target = '';
3053: }
1.268 albertel 3054: if ($start) { $link.='&start='.$start; }
1.692.4.17 raeburn 3055: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3056: $title = &mt($title);
3057: $linktext = &mt($linktext);
1.448 albertel 3058: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3059: &help_open_topic('View_recent_activity');
1.208 matthew 3060: }
3061:
1.692.4.2 raeburn 3062: sub slot_reservations_link {
3063: my ($linktext,$sname,$sdom,$target) = @_;
3064: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3065: my $title = 'View slot reservation history';
3066: if (defined($sname) && $sname !~ /^\s*$/ &&
3067: defined($sdom) && $sdom !~ /^\s*$/) {
3068: $link .= "&uname=$sname&udom=$sdom";
3069: $title .= ' of this student';
3070: }
3071: if (defined($target) && $target !~ /^\s*$/) {
3072: $target = qq{target="$target"};
3073: } else {
3074: $target = '';
3075: }
3076: $title = &mt($title);
3077: $linktext = &mt($linktext);
3078: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3079: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3080:
3081: }
3082:
1.508 www 3083: # ===================================================== Display a student photo
3084:
3085:
1.509 albertel 3086: sub student_image_tag {
1.508 www 3087: my ($domain,$user)=@_;
3088: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3089: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3090: return '<img src="'.$imgsrc.'" align="right" />';
3091: } else {
3092: return '';
3093: }
3094: }
3095:
1.112 bowersj2 3096: =pod
3097:
3098: =back
3099:
3100: =head1 Access .tab File Data
3101:
3102: =over 4
3103:
1.648 raeburn 3104: =item * &languageids()
1.112 bowersj2 3105:
3106: returns list of all language ids
3107:
3108: =cut
3109:
1.14 harris41 3110: sub languageids {
1.16 harris41 3111: return sort(keys(%language));
1.14 harris41 3112: }
3113:
1.112 bowersj2 3114: =pod
3115:
1.648 raeburn 3116: =item * &languagedescription()
1.112 bowersj2 3117:
3118: returns description of a specified language id
3119:
3120: =cut
3121:
1.14 harris41 3122: sub languagedescription {
1.125 www 3123: my $code=shift;
3124: return ($supported_language{$code}?'* ':'').
3125: $language{$code}.
1.126 www 3126: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3127: }
3128:
3129: sub plainlanguagedescription {
3130: my $code=shift;
3131: return $language{$code};
3132: }
3133:
3134: sub supportedlanguagecode {
3135: my $code=shift;
3136: return $supported_language{$code};
1.97 www 3137: }
3138:
1.112 bowersj2 3139: =pod
3140:
1.648 raeburn 3141: =item * ©rightids()
1.112 bowersj2 3142:
3143: returns list of all copyrights
3144:
3145: =cut
3146:
3147: sub copyrightids {
3148: return sort(keys(%cprtag));
3149: }
3150:
3151: =pod
3152:
1.648 raeburn 3153: =item * ©rightdescription()
1.112 bowersj2 3154:
3155: returns description of a specified copyright id
3156:
3157: =cut
3158:
3159: sub copyrightdescription {
1.166 www 3160: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3161: }
1.197 matthew 3162:
3163: =pod
3164:
1.648 raeburn 3165: =item * &source_copyrightids()
1.192 taceyjo1 3166:
3167: returns list of all source copyrights
3168:
3169: =cut
3170:
3171: sub source_copyrightids {
3172: return sort(keys(%scprtag));
3173: }
3174:
3175: =pod
3176:
1.648 raeburn 3177: =item * &source_copyrightdescription()
1.192 taceyjo1 3178:
3179: returns description of a specified source copyright id
3180:
3181: =cut
3182:
3183: sub source_copyrightdescription {
3184: return &mt($scprtag{shift(@_)});
3185: }
1.112 bowersj2 3186:
3187: =pod
3188:
1.648 raeburn 3189: =item * &filecategories()
1.112 bowersj2 3190:
3191: returns list of all file categories
3192:
3193: =cut
3194:
3195: sub filecategories {
3196: return sort(keys(%category_extensions));
3197: }
3198:
3199: =pod
3200:
1.648 raeburn 3201: =item * &filecategorytypes()
1.112 bowersj2 3202:
3203: returns list of file types belonging to a given file
3204: category
3205:
3206: =cut
3207:
3208: sub filecategorytypes {
1.356 albertel 3209: my ($cat) = @_;
3210: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3211: }
3212:
3213: =pod
3214:
1.648 raeburn 3215: =item * &fileembstyle()
1.112 bowersj2 3216:
3217: returns embedding style for a specified file type
3218:
3219: =cut
3220:
3221: sub fileembstyle {
3222: return $fe{lc(shift(@_))};
1.169 www 3223: }
3224:
1.351 www 3225: sub filemimetype {
3226: return $fm{lc(shift(@_))};
3227: }
3228:
1.169 www 3229:
3230: sub filecategoryselect {
3231: my ($name,$value)=@_;
1.189 matthew 3232: return &select_form($value,$name,
1.169 www 3233: '' => &mt('Any category'),
3234: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3235: }
3236:
3237: =pod
3238:
1.648 raeburn 3239: =item * &filedescription()
1.112 bowersj2 3240:
3241: returns description for a specified file type
3242:
3243: =cut
3244:
3245: sub filedescription {
1.188 matthew 3246: my $file_description = $fd{lc(shift())};
3247: $file_description =~ s:([\[\]]):~$1:g;
3248: return &mt($file_description);
1.112 bowersj2 3249: }
3250:
3251: =pod
3252:
1.648 raeburn 3253: =item * &filedescriptionex()
1.112 bowersj2 3254:
3255: returns description for a specified file type with
3256: extra formatting
3257:
3258: =cut
3259:
3260: sub filedescriptionex {
3261: my $ex=shift;
1.188 matthew 3262: my $file_description = $fd{lc($ex)};
3263: $file_description =~ s:([\[\]]):~$1:g;
3264: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3265: }
3266:
3267: # End of .tab access
3268: =pod
3269:
3270: =back
3271:
3272: =cut
3273:
3274: # ------------------------------------------------------------------ File Types
3275: sub fileextensions {
3276: return sort(keys(%fe));
3277: }
3278:
1.97 www 3279: # ----------------------------------------------------------- Display Languages
3280: # returns a hash with all desired display languages
3281: #
3282:
3283: sub display_languages {
3284: my %languages=();
1.692.4.1 raeburn 3285: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3286: $languages{$lang}=1;
1.97 www 3287: }
3288: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3289: if ($env{'form.displaylanguage'}) {
1.356 albertel 3290: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3291: $languages{$lang}=1;
1.97 www 3292: }
3293: }
3294: return %languages;
1.14 harris41 3295: }
3296:
1.582 albertel 3297: sub languages {
3298: my ($possible_langs) = @_;
1.692.4.1 raeburn 3299: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3300: if (!ref($possible_langs)) {
3301: if( wantarray ) {
3302: return @preferred_langs;
3303: } else {
3304: return $preferred_langs[0];
3305: }
3306: }
3307: my %possibilities = map { $_ => 1 } (@$possible_langs);
3308: my @preferred_possibilities;
3309: foreach my $preferred_lang (@preferred_langs) {
3310: if (exists($possibilities{$preferred_lang})) {
3311: push(@preferred_possibilities, $preferred_lang);
3312: }
3313: }
3314: if( wantarray ) {
3315: return @preferred_possibilities;
3316: }
3317: return $preferred_possibilities[0];
3318: }
3319:
1.692.4.2 raeburn 3320: sub user_lang {
3321: my ($touname,$toudom,$fromcid) = @_;
3322: my @userlangs;
3323: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3324: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3325: $env{'course.'.$fromcid.'.languages'}));
3326: } else {
3327: my %langhash = &getlangs($touname,$toudom);
3328: if ($langhash{'languages'} ne '') {
3329: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3330: } else {
3331: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3332: if ($domdefs{'lang_def'} ne '') {
3333: @userlangs = ($domdefs{'lang_def'});
3334: }
3335: }
3336: }
3337: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3338: my $user_lh = Apache::localize->get_handle(@languages);
3339: return $user_lh;
3340: }
3341:
1.112 bowersj2 3342: ###############################################################
3343: ## Student Answer Attempts ##
3344: ###############################################################
3345:
3346: =pod
3347:
3348: =head1 Alternate Problem Views
3349:
3350: =over 4
3351:
1.648 raeburn 3352: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3353: $getattempt, $regexp, $gradesub)
3354:
3355: Return string with previous attempt on problem. Arguments:
3356:
3357: =over 4
3358:
3359: =item * $symb: Problem, including path
3360:
3361: =item * $username: username of the desired student
3362:
3363: =item * $domain: domain of the desired student
1.14 harris41 3364:
1.112 bowersj2 3365: =item * $course: Course ID
1.14 harris41 3366:
1.112 bowersj2 3367: =item * $getattempt: Leave blank for all attempts, otherwise put
3368: something
1.14 harris41 3369:
1.112 bowersj2 3370: =item * $regexp: if string matches this regexp, the string will be
3371: sent to $gradesub
1.14 harris41 3372:
1.112 bowersj2 3373: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3374:
1.112 bowersj2 3375: =back
1.14 harris41 3376:
1.112 bowersj2 3377: The output string is a table containing all desired attempts, if any.
1.16 harris41 3378:
1.112 bowersj2 3379: =cut
1.1 albertel 3380:
3381: sub get_previous_attempt {
1.43 ng 3382: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3383: my $prevattempts='';
1.43 ng 3384: no strict 'refs';
1.1 albertel 3385: if ($symb) {
1.3 albertel 3386: my (%returnhash)=
3387: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3388: if ($returnhash{'version'}) {
3389: my %lasthash=();
3390: my $version;
3391: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3392: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3393: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3394: }
1.1 albertel 3395: }
1.596 albertel 3396: $prevattempts=&start_data_table().&start_data_table_header_row();
3397: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3398: foreach my $key (sort(keys(%lasthash))) {
3399: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3400: if ($#parts > 0) {
1.31 albertel 3401: my $data=$parts[-1];
3402: pop(@parts);
1.596 albertel 3403: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3404: } else {
1.41 ng 3405: if ($#parts == 0) {
3406: $prevattempts.='<th>'.$parts[0].'</th>';
3407: } else {
3408: $prevattempts.='<th>'.$ign.'</th>';
3409: }
1.31 albertel 3410: }
1.16 harris41 3411: }
1.596 albertel 3412: $prevattempts.=&end_data_table_header_row();
1.40 ng 3413: if ($getattempt eq '') {
3414: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3415: $prevattempts.=&start_data_table_row().
3416: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3417: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3418: my $value = &format_previous_attempt_value($key,
3419: $returnhash{$version.':'.$key});
3420: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3421: }
1.596 albertel 3422: $prevattempts.=&end_data_table_row();
1.40 ng 3423: }
1.1 albertel 3424: }
1.596 albertel 3425: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3426: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3427: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3428: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3429: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3430: }
1.596 albertel 3431: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3432: } else {
1.596 albertel 3433: $prevattempts=
3434: &start_data_table().&start_data_table_row().
3435: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3436: &end_data_table_row().&end_data_table();
1.1 albertel 3437: }
3438: } else {
1.596 albertel 3439: $prevattempts=
3440: &start_data_table().&start_data_table_row().
3441: '<td>'.&mt('No data.').'</td>'.
3442: &end_data_table_row().&end_data_table();
1.1 albertel 3443: }
1.10 albertel 3444: }
3445:
1.581 albertel 3446: sub format_previous_attempt_value {
3447: my ($key,$value) = @_;
3448: if ($key =~ /timestamp/) {
3449: $value = &Apache::lonlocal::locallocaltime($value);
3450: } elsif (ref($value) eq 'ARRAY') {
3451: $value = '('.join(', ', @{ $value }).')';
3452: } else {
3453: $value = &unescape($value);
3454: }
3455: return $value;
3456: }
3457:
3458:
1.107 albertel 3459: sub relative_to_absolute {
3460: my ($url,$output)=@_;
3461: my $parser=HTML::TokeParser->new(\$output);
3462: my $token;
3463: my $thisdir=$url;
3464: my @rlinks=();
3465: while ($token=$parser->get_token) {
3466: if ($token->[0] eq 'S') {
3467: if ($token->[1] eq 'a') {
3468: if ($token->[2]->{'href'}) {
3469: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3470: }
3471: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3472: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3473: } elsif ($token->[1] eq 'base') {
3474: $thisdir=$token->[2]->{'href'};
3475: }
3476: }
3477: }
3478: $thisdir=~s-/[^/]*$--;
1.356 albertel 3479: foreach my $link (@rlinks) {
1.692.4.2 raeburn 3480: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3481: ($link=~/^\//) ||
3482: ($link=~/^javascript:/i) ||
3483: ($link=~/^mailto:/i) ||
3484: ($link=~/^\#/)) {
3485: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3486: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3487: }
3488: }
3489: # -------------------------------------------------- Deal with Applet codebases
3490: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3491: return $output;
3492: }
3493:
1.112 bowersj2 3494: =pod
3495:
1.648 raeburn 3496: =item * &get_student_view()
1.112 bowersj2 3497:
3498: show a snapshot of what student was looking at
3499:
3500: =cut
3501:
1.10 albertel 3502: sub get_student_view {
1.186 albertel 3503: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3504: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3505: my (%form);
1.10 albertel 3506: my @elements=('symb','courseid','domain','username');
3507: foreach my $element (@elements) {
1.186 albertel 3508: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3509: }
1.186 albertel 3510: if (defined($moreenv)) {
3511: %form=(%form,%{$moreenv});
3512: }
1.236 albertel 3513: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3514: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3515: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3516: $userview=~s/\<body[^\>]*\>//gi;
3517: $userview=~s/\<\/body\>//gi;
3518: $userview=~s/\<html\>//gi;
3519: $userview=~s/\<\/html\>//gi;
3520: $userview=~s/\<head\>//gi;
3521: $userview=~s/\<\/head\>//gi;
3522: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3523: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3524: if (wantarray) {
3525: return ($userview,$response);
3526: } else {
3527: return $userview;
3528: }
3529: }
3530:
3531: sub get_student_view_with_retries {
3532: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3533:
3534: my $ok = 0; # True if we got a good response.
3535: my $content;
3536: my $response;
3537:
3538: # Try to get the student_view done. within the retries count:
3539:
3540: do {
3541: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3542: $ok = $response->is_success;
3543: if (!$ok) {
3544: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3545: }
3546: $retries--;
3547: } while (!$ok && ($retries > 0));
3548:
3549: if (!$ok) {
3550: $content = ''; # On error return an empty content.
3551: }
1.651 www 3552: if (wantarray) {
3553: return ($content, $response);
3554: } else {
3555: return $content;
3556: }
1.11 albertel 3557: }
3558:
1.112 bowersj2 3559: =pod
3560:
1.648 raeburn 3561: =item * &get_student_answers()
1.112 bowersj2 3562:
3563: show a snapshot of how student was answering problem
3564:
3565: =cut
3566:
1.11 albertel 3567: sub get_student_answers {
1.100 sakharuk 3568: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3569: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3570: my (%moreenv);
1.11 albertel 3571: my @elements=('symb','courseid','domain','username');
3572: foreach my $element (@elements) {
1.186 albertel 3573: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3574: }
1.186 albertel 3575: $moreenv{'grade_target'}='answer';
3576: %moreenv=(%form,%moreenv);
1.497 raeburn 3577: $feedurl = &Apache::lonnet::clutter($feedurl);
3578: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3579: return $userview;
1.1 albertel 3580: }
1.116 albertel 3581:
3582: =pod
3583:
3584: =item * &submlink()
3585:
1.242 albertel 3586: Inputs: $text $uname $udom $symb $target
1.116 albertel 3587:
3588: Returns: A link to grades.pm such as to see the SUBM view of a student
3589:
3590: =cut
3591:
3592: ###############################################
3593: sub submlink {
1.242 albertel 3594: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3595: if (!($uname && $udom)) {
3596: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3597: &Apache::lonnet::whichuser($symb);
1.116 albertel 3598: if (!$symb) { $symb=$cursymb; }
3599: }
1.254 matthew 3600: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3601: $symb=&escape($symb);
1.242 albertel 3602: if ($target) { $target="target=\"$target\""; }
3603: return '<a href="/adm/grades?&command=submission&'.
3604: 'symb='.$symb.'&student='.$uname.
3605: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3606: }
3607: ##############################################
3608:
3609: =pod
3610:
3611: =item * &pgrdlink()
3612:
3613: Inputs: $text $uname $udom $symb $target
3614:
3615: Returns: A link to grades.pm such as to see the PGRD view of a student
3616:
3617: =cut
3618:
3619: ###############################################
3620: sub pgrdlink {
3621: my $link=&submlink(@_);
3622: $link=~s/(&command=submission)/$1&showgrading=yes/;
3623: return $link;
3624: }
3625: ##############################################
3626:
3627: =pod
3628:
3629: =item * &pprmlink()
3630:
3631: Inputs: $text $uname $udom $symb $target
3632:
3633: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3634: student and a specific resource
1.242 albertel 3635:
3636: =cut
3637:
3638: ###############################################
3639: sub pprmlink {
3640: my ($text,$uname,$udom,$symb,$target)=@_;
3641: if (!($uname && $udom)) {
3642: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3643: &Apache::lonnet::whichuser($symb);
1.242 albertel 3644: if (!$symb) { $symb=$cursymb; }
3645: }
1.254 matthew 3646: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3647: $symb=&escape($symb);
1.242 albertel 3648: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3649: return '<a href="/adm/parmset?command=set&'.
3650: 'symb='.$symb.'&uname='.$uname.
3651: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3652: }
3653: ##############################################
1.37 matthew 3654:
1.112 bowersj2 3655: =pod
3656:
3657: =back
3658:
3659: =cut
3660:
1.37 matthew 3661: ###############################################
1.51 www 3662:
3663:
3664: sub timehash {
1.687 raeburn 3665: my ($thistime) = @_;
3666: my $timezone = &Apache::lonlocal::gettimezone();
3667: my $dt = DateTime->from_epoch(epoch => $thistime)
3668: ->set_time_zone($timezone);
3669: my $wday = $dt->day_of_week();
3670: if ($wday == 7) { $wday = 0; }
3671: return ( 'second' => $dt->second(),
3672: 'minute' => $dt->minute(),
3673: 'hour' => $dt->hour(),
3674: 'day' => $dt->day_of_month(),
3675: 'month' => $dt->month(),
3676: 'year' => $dt->year(),
3677: 'weekday' => $wday,
3678: 'dayyear' => $dt->day_of_year(),
3679: 'dlsav' => $dt->is_dst() );
1.51 www 3680: }
3681:
1.370 www 3682: sub utc_string {
3683: my ($date)=@_;
1.371 www 3684: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3685: }
3686:
1.51 www 3687: sub maketime {
3688: my %th=@_;
1.687 raeburn 3689: my ($epoch_time,$timezone,$dt);
3690: $timezone = &Apache::lonlocal::gettimezone();
3691: eval {
3692: $dt = DateTime->new( year => $th{'year'},
3693: month => $th{'month'},
3694: day => $th{'day'},
3695: hour => $th{'hour'},
3696: minute => $th{'minute'},
3697: second => $th{'second'},
3698: time_zone => $timezone,
3699: );
3700: };
3701: if (!$@) {
3702: $epoch_time = $dt->epoch;
3703: if ($epoch_time) {
3704: return $epoch_time;
3705: }
3706: }
1.51 www 3707: return POSIX::mktime(
3708: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3709: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3710: }
3711:
3712: #########################################
1.51 www 3713:
3714: sub findallcourses {
1.482 raeburn 3715: my ($roles,$uname,$udom) = @_;
1.355 albertel 3716: my %roles;
3717: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3718: my %courses;
1.51 www 3719: my $now=time;
1.482 raeburn 3720: if (!defined($uname)) {
3721: $uname = $env{'user.name'};
3722: }
3723: if (!defined($udom)) {
3724: $udom = $env{'user.domain'};
3725: }
3726: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3727: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3728: if (!%roles) {
3729: %roles = (
3730: cc => 1,
3731: in => 1,
3732: ep => 1,
3733: ta => 1,
3734: cr => 1,
3735: st => 1,
3736: );
3737: }
3738: foreach my $entry (keys(%roleshash)) {
3739: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3740: if ($trole =~ /^cr/) {
3741: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3742: } else {
3743: next if (!exists($roles{$trole}));
3744: }
3745: if ($tend) {
3746: next if ($tend < $now);
3747: }
3748: if ($tstart) {
3749: next if ($tstart > $now);
3750: }
3751: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3752: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3753: if ($secpart eq '') {
3754: ($cnum,$role) = split(/_/,$cnumpart);
3755: $sec = 'none';
3756: $realsec = '';
3757: } else {
3758: $cnum = $cnumpart;
3759: ($sec,$role) = split(/_/,$secpart);
3760: $realsec = $sec;
1.490 raeburn 3761: }
1.482 raeburn 3762: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3763: }
3764: } else {
3765: foreach my $key (keys(%env)) {
1.483 albertel 3766: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3767: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3768: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3769: next if ($role eq 'ca' || $role eq 'aa');
3770: next if (%roles && !exists($roles{$role}));
3771: my ($starttime,$endtime)=split(/\./,$env{$key});
3772: my $active=1;
3773: if ($starttime) {
3774: if ($now<$starttime) { $active=0; }
3775: }
3776: if ($endtime) {
3777: if ($now>$endtime) { $active=0; }
3778: }
3779: if ($active) {
3780: if ($sec eq '') {
3781: $sec = 'none';
3782: }
3783: $courses{$cdom.'_'.$cnum}{$sec} =
3784: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3785: }
3786: }
1.51 www 3787: }
3788: }
1.474 raeburn 3789: return %courses;
1.51 www 3790: }
1.37 matthew 3791:
1.54 www 3792: ###############################################
1.474 raeburn 3793:
3794: sub blockcheck {
1.482 raeburn 3795: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3796:
3797: if (!defined($udom)) {
3798: $udom = $env{'user.domain'};
3799: }
3800: if (!defined($uname)) {
3801: $uname = $env{'user.name'};
3802: }
3803:
3804: # If uname and udom are for a course, check for blocks in the course.
3805:
3806: if (&Apache::lonnet::is_course($udom,$uname)) {
3807: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3808: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3809: return ($startblock,$endblock);
3810: }
1.474 raeburn 3811:
1.502 raeburn 3812: my $startblock = 0;
3813: my $endblock = 0;
1.482 raeburn 3814: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3815:
1.490 raeburn 3816: # If uname is for a user, and activity is course-specific, i.e.,
3817: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3818:
1.490 raeburn 3819: if (($activity eq 'boards' || $activity eq 'chat' ||
3820: $activity eq 'groups') && ($env{'request.course.id'})) {
3821: foreach my $key (keys(%live_courses)) {
3822: if ($key ne $env{'request.course.id'}) {
3823: delete($live_courses{$key});
3824: }
3825: }
3826: }
3827:
3828: my $otheruser = 0;
3829: my %own_courses;
3830: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3831: # Resource belongs to user other than current user.
3832: $otheruser = 1;
3833: # Gather courses for current user
3834: %own_courses =
3835: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3836: }
3837:
3838: # Gather active course roles - course coordinator, instructor,
3839: # exam proctor, ta, student, or custom role.
1.474 raeburn 3840:
3841: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3842: my ($cdom,$cnum);
3843: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3844: $cdom = $env{'course.'.$course.'.domain'};
3845: $cnum = $env{'course.'.$course.'.num'};
3846: } else {
1.490 raeburn 3847: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3848: }
3849: my $no_ownblock = 0;
3850: my $no_userblock = 0;
1.533 raeburn 3851: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3852: # Check if current user has 'evb' priv for this
3853: if (defined($own_courses{$course})) {
3854: foreach my $sec (keys(%{$own_courses{$course}})) {
3855: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3856: if ($sec ne 'none') {
3857: $checkrole .= '/'.$sec;
3858: }
3859: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3860: $no_ownblock = 1;
3861: last;
3862: }
3863: }
3864: }
3865: # if they have 'evb' priv and are currently not playing student
3866: next if (($no_ownblock) &&
3867: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3868: }
1.474 raeburn 3869: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3870: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3871: if ($sec ne 'none') {
1.482 raeburn 3872: $checkrole .= '/'.$sec;
1.474 raeburn 3873: }
1.490 raeburn 3874: if ($otheruser) {
3875: # Resource belongs to user other than current user.
3876: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3877: my ($trole,$tdom,$tnum,$tsec);
3878: my $entry = $live_courses{$course}{$sec};
3879: if ($entry =~ /^cr/) {
3880: ($trole,$tdom,$tnum,$tsec) =
3881: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3882: } else {
3883: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3884: }
3885: my ($spec,$area,$trest,%allroles,%userroles);
3886: $area = '/'.$tdom.'/'.$tnum;
3887: $trest = $tnum;
3888: if ($tsec ne '') {
3889: $area .= '/'.$tsec;
3890: $trest .= '/'.$tsec;
3891: }
3892: $spec = $trole.'.'.$area;
3893: if ($trole =~ /^cr/) {
3894: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3895: $tdom,$spec,$trest,$area);
3896: } else {
3897: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3898: $tdom,$spec,$trest,$area);
3899: }
3900: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3901: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3902: if ($1) {
3903: $no_userblock = 1;
3904: last;
3905: }
3906: }
1.490 raeburn 3907: } else {
3908: # Resource belongs to current user
3909: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3910: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3911: $no_ownblock = 1;
3912: last;
3913: }
1.474 raeburn 3914: }
3915: }
3916: # if they have the evb priv and are currently not playing student
1.482 raeburn 3917: next if (($no_ownblock) &&
1.491 albertel 3918: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3919: next if ($no_userblock);
1.474 raeburn 3920:
1.490 raeburn 3921: # Retrieve blocking times and identity of blocker for course
3922: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3923:
3924: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3925: if (($start != 0) &&
3926: (($startblock == 0) || ($startblock > $start))) {
3927: $startblock = $start;
3928: }
3929: if (($end != 0) &&
3930: (($endblock == 0) || ($endblock < $end))) {
3931: $endblock = $end;
3932: }
1.490 raeburn 3933: }
3934: return ($startblock,$endblock);
3935: }
3936:
3937: sub get_blocks {
3938: my ($setters,$activity,$cdom,$cnum) = @_;
3939: my $startblock = 0;
3940: my $endblock = 0;
3941: my $course = $cdom.'_'.$cnum;
3942: $setters->{$course} = {};
3943: $setters->{$course}{'staff'} = [];
3944: $setters->{$course}{'times'} = [];
3945: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3946: foreach my $record (keys(%records)) {
3947: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3948: if ($start <= time && $end >= time) {
3949: my ($staff_name,$staff_dom,$title,$blocks) =
3950: &parse_block_record($records{$record});
3951: if ($blocks->{$activity} eq 'on') {
3952: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3953: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3954: if ( ($startblock == 0) || ($startblock > $start) ) {
3955: $startblock = $start;
1.490 raeburn 3956: }
1.491 albertel 3957: if ( ($endblock == 0) || ($endblock < $end) ) {
3958: $endblock = $end;
1.474 raeburn 3959: }
3960: }
3961: }
3962: }
3963: return ($startblock,$endblock);
3964: }
3965:
3966: sub parse_block_record {
3967: my ($record) = @_;
3968: my ($setuname,$setudom,$title,$blocks);
3969: if (ref($record) eq 'HASH') {
3970: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3971: $title = &unescape($record->{'event'});
3972: $blocks = $record->{'blocks'};
3973: } else {
3974: my @data = split(/:/,$record,3);
3975: if (scalar(@data) eq 2) {
3976: $title = $data[1];
3977: ($setuname,$setudom) = split(/@/,$data[0]);
3978: } else {
3979: ($setuname,$setudom,$title) = @data;
3980: }
3981: $blocks = { 'com' => 'on' };
3982: }
3983: return ($setuname,$setudom,$title,$blocks);
3984: }
3985:
3986: sub build_block_table {
3987: my ($startblock,$endblock,$setters) = @_;
3988: my %lt = &Apache::lonlocal::texthash(
3989: 'cacb' => 'Currently active communication blocks',
3990: 'cour' => 'Course',
3991: 'dura' => 'Duration',
3992: 'blse' => 'Block set by'
3993: );
3994: my $output;
1.476 raeburn 3995: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3996: $output .= &start_data_table();
3997: $output .= '
3998: <tr>
3999: <th>'.$lt{'cour'}.'</th>
4000: <th>'.$lt{'dura'}.'</th>
4001: <th>'.$lt{'blse'}.'</th>
4002: </tr>
4003: ';
4004: foreach my $course (keys(%{$setters})) {
4005: my %courseinfo=&Apache::lonnet::coursedescription($course);
4006: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
4007: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 4008: my $fullname = &plainname($uname,$udom);
4009: if (defined($env{'user.name'}) && defined($env{'user.domain'})
4010: && $env{'user.name'} ne 'public'
4011: && $env{'user.domain'} ne 'public') {
4012: $fullname = &aboutmewrapper($fullname,$uname,$udom);
4013: }
1.474 raeburn 4014: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
4015: $openblock = &Apache::lonlocal::locallocaltime($openblock);
4016: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
4017: $output .= &Apache::loncommon::start_data_table_row().
4018: '<td>'.$courseinfo{'description'}.'</td>'.
4019: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 4020: '<td>'.$fullname.'</td>'.
1.474 raeburn 4021: &Apache::loncommon::end_data_table_row();
4022: }
4023: }
4024: $output .= &end_data_table();
4025: }
4026:
1.490 raeburn 4027: sub blocking_status {
4028: my ($activity,$uname,$udom) = @_;
4029: my %setters;
4030: my ($blocked,$output,$ownitem,$is_course);
4031: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
4032: if ($startblock && $endblock) {
4033: $blocked = 1;
4034: if (wantarray) {
4035: my $category;
4036: if ($activity eq 'boards') {
4037: $category = 'Discussion posts in this course';
4038: } elsif ($activity eq 'blogs') {
4039: $category = 'Blogs';
4040: } elsif ($activity eq 'port') {
4041: if (defined($uname) && defined($udom)) {
4042: if ($uname eq $env{'user.name'} &&
4043: $udom eq $env{'user.domain'}) {
4044: $ownitem = 1;
4045: }
4046: }
4047: $is_course = &Apache::lonnet::is_course($udom,$uname);
4048: if ($ownitem) {
4049: $category = 'Your portfolio files';
4050: } elsif ($is_course) {
4051: my $coursedesc;
4052: foreach my $course (keys(%setters)) {
4053: my %courseinfo =
4054: &Apache::lonnet::coursedescription($course);
4055: $coursedesc = $courseinfo{'description'};
4056: }
1.692.4.2 raeburn 4057: $category = "Group portfolio files in the course '$coursedesc'";
1.490 raeburn 4058: } else {
4059: $category = 'Portfolio files belonging to ';
4060: if ($env{'user.name'} eq 'public' &&
4061: $env{'user.domain'} eq 'public') {
4062: $category .= &plainname($uname,$udom);
4063: } else {
4064: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
4065: }
4066: }
4067: } elsif ($activity eq 'groups') {
4068: $category = 'Groups in this course';
4069: }
4070: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
4071: my $showend = &Apache::lonlocal::locallocaltime($endblock);
4072: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
4073: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
4074: $output .= &build_block_table($startblock,$endblock,\%setters);
4075: }
4076: }
4077: }
4078: if (wantarray) {
4079: return ($blocked,$output);
4080: } else {
4081: return $blocked;
4082: }
4083: }
4084:
1.60 matthew 4085: ###############################################
4086:
1.682 raeburn 4087: sub check_ip_acc {
4088: my ($acc)=@_;
4089: &Apache::lonxml::debug("acc is $acc");
4090: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4091: return 1;
4092: }
4093: my $allowed=0;
4094: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4095:
4096: my $name;
4097: foreach my $pattern (split(',',$acc)) {
4098: $pattern =~ s/^\s*//;
4099: $pattern =~ s/\s*$//;
4100: if ($pattern =~ /\*$/) {
4101: #35.8.*
4102: $pattern=~s/\*//;
4103: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4104: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4105: #35.8.3.[34-56]
4106: my $low=$2;
4107: my $high=$3;
4108: $pattern=$1;
4109: if ($ip =~ /^\Q$pattern\E/) {
4110: my $last=(split(/\./,$ip))[3];
4111: if ($last <=$high && $last >=$low) { $allowed=1; }
4112: }
4113: } elsif ($pattern =~ /^\*/) {
4114: #*.msu.edu
4115: $pattern=~s/\*//;
4116: if (!defined($name)) {
4117: use Socket;
4118: my $netaddr=inet_aton($ip);
4119: ($name)=gethostbyaddr($netaddr,AF_INET);
4120: }
4121: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4122: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4123: #127.0.0.1
4124: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4125: } else {
4126: #some.name.com
4127: if (!defined($name)) {
4128: use Socket;
4129: my $netaddr=inet_aton($ip);
4130: ($name)=gethostbyaddr($netaddr,AF_INET);
4131: }
4132: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4133: }
4134: if ($allowed) { last; }
4135: }
4136: return $allowed;
4137: }
4138:
4139: ###############################################
4140:
1.60 matthew 4141: =pod
4142:
1.112 bowersj2 4143: =head1 Domain Template Functions
4144:
4145: =over 4
4146:
4147: =item * &determinedomain()
1.60 matthew 4148:
4149: Inputs: $domain (usually will be undef)
4150:
1.63 www 4151: Returns: Determines which domain should be used for designs
1.60 matthew 4152:
4153: =cut
1.54 www 4154:
1.60 matthew 4155: ###############################################
1.63 www 4156: sub determinedomain {
4157: my $domain=shift;
1.531 albertel 4158: if (! $domain) {
1.60 matthew 4159: # Determine domain if we have not been given one
1.692.4.18 raeburn 4160: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4161: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4162: if ($env{'request.role.domain'}) {
4163: $domain=$env{'request.role.domain'};
1.60 matthew 4164: }
4165: }
1.63 www 4166: return $domain;
4167: }
4168: ###############################################
1.517 raeburn 4169:
1.518 albertel 4170: sub devalidate_domconfig_cache {
4171: my ($udom)=@_;
4172: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4173: }
4174:
4175: # ---------------------- Get domain configuration for a domain
4176: sub get_domainconf {
4177: my ($udom) = @_;
4178: my $cachetime=1800;
4179: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4180: if (defined($cached)) { return %{$result}; }
4181:
4182: my %domconfig = &Apache::lonnet::get_dom('configuration',
4183: ['login','rolecolors'],$udom);
1.632 raeburn 4184: my (%designhash,%legacy);
1.518 albertel 4185: if (keys(%domconfig) > 0) {
4186: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4187: if (keys(%{$domconfig{'login'}})) {
4188: foreach my $key (keys(%{$domconfig{'login'}})) {
1.692.4.2 raeburn 4189: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4190: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4191: $designhash{$udom.'.login.'.$key.'_'.$img} =
4192: $domconfig{'login'}{$key}{$img};
4193: }
4194: } else {
4195: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4196: }
1.632 raeburn 4197: }
4198: } else {
4199: $legacy{'login'} = 1;
1.518 albertel 4200: }
1.632 raeburn 4201: } else {
4202: $legacy{'login'} = 1;
1.518 albertel 4203: }
4204: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4205: if (keys(%{$domconfig{'rolecolors'}})) {
4206: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4207: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4208: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4209: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4210: }
1.518 albertel 4211: }
4212: }
1.632 raeburn 4213: } else {
4214: $legacy{'rolecolors'} = 1;
1.518 albertel 4215: }
1.632 raeburn 4216: } else {
4217: $legacy{'rolecolors'} = 1;
1.518 albertel 4218: }
1.632 raeburn 4219: if (keys(%legacy) > 0) {
4220: my %legacyhash = &get_legacy_domconf($udom);
4221: foreach my $item (keys(%legacyhash)) {
4222: if ($item =~ /^\Q$udom\E\.login/) {
4223: if ($legacy{'login'}) {
4224: $designhash{$item} = $legacyhash{$item};
4225: }
4226: } else {
4227: if ($legacy{'rolecolors'}) {
4228: $designhash{$item} = $legacyhash{$item};
4229: }
1.518 albertel 4230: }
4231: }
4232: }
1.632 raeburn 4233: } else {
4234: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4235: }
4236: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4237: $cachetime);
4238: return %designhash;
4239: }
4240:
1.632 raeburn 4241: sub get_legacy_domconf {
4242: my ($udom) = @_;
4243: my %legacyhash;
4244: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4245: my $designfile = $designdir.'/'.$udom.'.tab';
4246: if (-e $designfile) {
4247: if ( open (my $fh,"<$designfile") ) {
4248: while (my $line = <$fh>) {
4249: next if ($line =~ /^\#/);
4250: chomp($line);
4251: my ($key,$val)=(split(/\=/,$line));
4252: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4253: }
4254: close($fh);
4255: }
4256: }
4257: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4258: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4259: }
4260: return %legacyhash;
4261: }
4262:
1.63 www 4263: =pod
4264:
1.112 bowersj2 4265: =item * &domainlogo()
1.63 www 4266:
4267: Inputs: $domain (usually will be undef)
4268:
4269: Returns: A link to a domain logo, if the domain logo exists.
4270: If the domain logo does not exist, a description of the domain.
4271:
4272: =cut
1.112 bowersj2 4273:
1.63 www 4274: ###############################################
4275: sub domainlogo {
1.517 raeburn 4276: my $domain = &determinedomain(shift);
1.518 albertel 4277: my %designhash = &get_domainconf($domain);
1.517 raeburn 4278: # See if there is a logo
4279: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4280: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4281: if ($imgsrc =~ m{^/(adm|res)/}) {
4282: if ($imgsrc =~ m{^/res/}) {
4283: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4284: &Apache::lonnet::repcopy($local_name);
4285: }
4286: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4287: }
4288: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4289: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4290: return &Apache::lonnet::domain($domain,'description');
1.59 www 4291: } else {
1.60 matthew 4292: return '';
1.59 www 4293: }
4294: }
1.63 www 4295: ##############################################
4296:
4297: =pod
4298:
1.112 bowersj2 4299: =item * &designparm()
1.63 www 4300:
4301: Inputs: $which parameter; $domain (usually will be undef)
4302:
4303: Returns: value of designparamter $which
4304:
4305: =cut
1.112 bowersj2 4306:
1.397 albertel 4307:
1.400 albertel 4308: ##############################################
1.397 albertel 4309: sub designparm {
4310: my ($which,$domain)=@_;
1.258 albertel 4311: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4312: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4313: return '#000000';
4314: }
1.635 raeburn 4315: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4316: return '#FFFFFF';
4317: }
4318: if ($which=~/\.tabbg$/) {
4319: return '#CCCCCC';
4320: }
4321: }
1.397 albertel 4322: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4323: return $env{'environment.color.'.$which};
1.96 www 4324: }
1.63 www 4325: $domain=&determinedomain($domain);
1.518 albertel 4326: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4327: my $output;
1.517 raeburn 4328: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4329: $output = $domdesign{$domain.'.'.$which};
1.63 www 4330: } else {
1.520 raeburn 4331: $output = $defaultdesign{$which};
4332: }
4333: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4334: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4335: if ($output =~ m{^/(adm|res)/}) {
4336: if ($output =~ m{^/res/}) {
4337: my $local_name = &Apache::lonnet::filelocation('',$output);
4338: &Apache::lonnet::repcopy($local_name);
4339: }
1.520 raeburn 4340: $output = &lonhttpdurl($output);
4341: }
1.63 www 4342: }
1.520 raeburn 4343: return $output;
1.63 www 4344: }
1.59 www 4345:
1.60 matthew 4346: ###############################################
4347: ###############################################
4348:
4349: =pod
4350:
1.112 bowersj2 4351: =back
4352:
1.549 albertel 4353: =head1 HTML Helpers
1.112 bowersj2 4354:
4355: =over 4
4356:
4357: =item * &bodytag()
1.60 matthew 4358:
4359: Returns a uniform header for LON-CAPA web pages.
4360:
4361: Inputs:
4362:
1.112 bowersj2 4363: =over 4
4364:
4365: =item * $title, A title to be displayed on the page.
4366:
4367: =item * $function, the current role (can be undef).
4368:
4369: =item * $addentries, extra parameters for the <body> tag.
4370:
4371: =item * $bodyonly, if defined, only return the <body> tag.
4372:
4373: =item * $domain, if defined, force a given domain.
4374:
4375: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4376: text interface only)
1.60 matthew 4377:
1.326 albertel 4378: =item * $customtitle, alternate text to use instead of $title
4379: in the title box that appears, this text
4380: is not auto translated like the $title is
1.309 albertel 4381:
4382: =item * $notopbar, if true, keep the 'what is this' info but remove the
4383: navigational links
1.317 albertel 4384:
1.338 albertel 4385: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4386:
4387: =item * $notitle, if true keep the nav controls, but remove the title bar
4388:
1.361 albertel 4389: =item * $no_inline_link, if true and in remote mode, don't show the
4390: 'Switch To Inline Menu' link
4391:
1.460 albertel 4392: =item * $args, optional argument valid values are
4393: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4394: inherit_jsmath -> when creating popup window in a page,
4395: should it have jsmath forced on by the
4396: current page
1.460 albertel 4397:
1.112 bowersj2 4398: =back
4399:
1.60 matthew 4400: Returns: A uniform header for LON-CAPA web pages.
4401: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4402: If $bodyonly is undef or zero, an html string containing a <body> tag and
4403: other decorations will be returned.
4404:
4405: =cut
4406:
1.54 www 4407: sub bodytag {
1.309 albertel 4408: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4409: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4410:
1.460 albertel 4411: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4412:
1.183 matthew 4413: $function = &get_users_function() if (!$function);
1.339 albertel 4414: my $img = &designparm($function.'.img',$domain);
4415: my $font = &designparm($function.'.font',$domain);
4416: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4417:
1.692.4.2 raeburn 4418: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4419: 'bgcolor' => $pgbg,
1.339 albertel 4420: 'text' => $font,
4421: 'alink' => &designparm($function.'.alink',$domain),
4422: 'vlink' => &designparm($function.'.vlink',$domain),
4423: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4424: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4425:
1.63 www 4426: # role and realm
1.378 raeburn 4427: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4428: if ($role eq 'ca') {
1.479 albertel 4429: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4430: $realm = &plainname($rname,$rdom);
1.378 raeburn 4431: }
1.55 www 4432: # realm
1.258 albertel 4433: if ($env{'request.course.id'}) {
1.378 raeburn 4434: if ($env{'request.role'} !~ /^cr/) {
4435: $role = &Apache::lonnet::plaintext($role,&course_type());
4436: }
1.359 albertel 4437: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4438: } else {
4439: $role = &Apache::lonnet::plaintext($role);
1.54 www 4440: }
1.433 albertel 4441:
1.359 albertel 4442: if (!$realm) { $realm=' '; }
1.55 www 4443: # Set messages
1.60 matthew 4444: my $messages=&domainlogo($domain);
1.330 albertel 4445:
1.438 albertel 4446: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4447:
1.101 www 4448: # construct main body tag
1.359 albertel 4449: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4450: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4451:
1.530 albertel 4452: if ($bodyonly) {
1.60 matthew 4453: return $bodytag;
1.258 albertel 4454: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4455: # Accessibility
1.224 raeburn 4456:
1.337 albertel 4457: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4458: if (!$notitle) {
1.337 albertel 4459: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4460: }
4461: return $bodytag;
1.359 albertel 4462: }
4463:
1.410 albertel 4464: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4465: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4466: undef($role);
1.434 albertel 4467: } else {
4468: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4469: }
1.359 albertel 4470:
4471: my $roleinfo=(<<ENDROLE);
4472: <td class="LC_title_bar_who">
4473: <div class="LC_title_bar_name">
1.410 albertel 4474: $name
1.361 albertel 4475:
1.359 albertel 4476: </div>
4477: <div class="LC_title_bar_role">
1.361 albertel 4478: $role
1.359 albertel 4479: </div>
4480: <div class="LC_title_bar_realm">
1.361 albertel 4481: $realm
1.359 albertel 4482: </div>
1.206 albertel 4483: </td>
4484: ENDROLE
1.235 raeburn 4485:
1.359 albertel 4486: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4487: if ($customtitle) {
4488: $titleinfo = $customtitle;
4489: }
4490: #
4491: # Extra info if you are the DC
4492: my $dc_info = '';
4493: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4494: $env{'course.'.$env{'request.course.id'}.
4495: '.domain'}.'/'})) {
4496: my $cid = $env{'request.course.id'};
4497: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4498: $dc_info =~ s/\s+$//;
1.359 albertel 4499: $dc_info = '('.$dc_info.')';
4500: }
4501:
1.644 www 4502: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4503: # No Remote
1.258 albertel 4504: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4505: $forcereg=1;
4506: }
4507:
4508: if (!$customtitle && $env{'request.state'} eq 'construct') {
4509: # this is for resources; directories have customtitle, and crumbs
4510: # and select recent are created in lonpubdir.pm
1.229 albertel 4511: my ($uname,$thisdisfn)=
1.258 albertel 4512: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4513: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4514: $formaction=~s/\/+/\//g;
4515:
1.359 albertel 4516: my $parentpath = '';
4517: my $lastitem = '';
4518: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4519: $parentpath = $1;
4520: $lastitem = $2;
4521: } else {
4522: $lastitem = $thisdisfn;
4523: }
4524: $titleinfo =
1.640 bisitz 4525: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4526: .'<b>'.&mt('Construction Space').'</b>: '
4527: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4528: .'" target="_top"><tt><b>'
4529: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
4530: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4531: .'</form>'
4532: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4533: }
1.359 albertel 4534:
1.337 albertel 4535: my $titletable;
1.338 albertel 4536: if (!$notitle) {
1.337 albertel 4537: $titletable =
1.359 albertel 4538: '<table id="LC_title_bar">'.
4539: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4540: '</tr></table>';
1.337 albertel 4541: }
1.359 albertel 4542: if ($notopbar) {
4543: $bodytag .= $titletable;
4544: } else {
4545: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4546: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4547: $titletable);
1.272 raeburn 4548: } else {
1.336 albertel 4549: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4550: $titletable;
1.272 raeburn 4551: }
1.235 raeburn 4552: }
4553: return $bodytag;
1.94 www 4554: }
1.95 www 4555:
1.93 www 4556: #
1.95 www 4557: # Top frame rendering, Remote is up
1.93 www 4558: #
1.359 albertel 4559:
1.517 raeburn 4560: my $imgsrc = $img;
4561: if ($img =~ /^\/adm/) {
1.575 albertel 4562: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4563: }
4564: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4565:
1.305 www 4566: # Explicit link to get inline menu
1.361 albertel 4567: my $menu= ($no_inline_link?''
4568: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4569: #
1.338 albertel 4570: if ($notitle) {
1.337 albertel 4571: return $bodytag;
4572: }
1.94 www 4573: return(<<ENDBODY);
1.60 matthew 4574: $bodytag
1.359 albertel 4575: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4576: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4577: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4578: </tr>
1.359 albertel 4579: <tr><td>$titleinfo $dc_info $menu</td>
4580: $roleinfo
1.368 albertel 4581: </tr>
1.356 albertel 4582: </table>
1.54 www 4583: ENDBODY
1.182 matthew 4584: }
4585:
1.330 albertel 4586: sub make_attr_string {
4587: my ($register,$attr_ref) = @_;
4588:
4589: if ($attr_ref && !ref($attr_ref)) {
4590: die("addentries Must be a hash ref ".
4591: join(':',caller(1))." ".
4592: join(':',caller(0))." ");
4593: }
4594:
4595: if ($register) {
1.339 albertel 4596: my ($on_load,$on_unload);
4597: foreach my $key (keys(%{$attr_ref})) {
4598: if (lc($key) eq 'onload') {
4599: $on_load.=$attr_ref->{$key}.';';
4600: delete($attr_ref->{$key});
4601:
4602: } elsif (lc($key) eq 'onunload') {
4603: $on_unload.=$attr_ref->{$key}.';';
4604: delete($attr_ref->{$key});
4605: }
4606: }
4607: $attr_ref->{'onload'} =
4608: &Apache::lonmenu::loadevents(). $on_load;
4609: $attr_ref->{'onunload'}=
4610: &Apache::lonmenu::unloadevents().$on_unload;
4611: }
4612:
4613: # Accessibility font enhance
4614: if ($env{'browser.fontenhance'} eq 'on') {
4615: my $style;
4616: foreach my $key (keys(%{$attr_ref})) {
4617: if (lc($key) eq 'style') {
4618: $style.=$attr_ref->{$key}.';';
4619: delete($attr_ref->{$key});
4620: }
4621: }
4622: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4623: }
1.339 albertel 4624:
4625: if ($env{'browser.blackwhite'} eq 'on') {
4626: delete($attr_ref->{'font'});
4627: delete($attr_ref->{'link'});
4628: delete($attr_ref->{'alink'});
4629: delete($attr_ref->{'vlink'});
4630: delete($attr_ref->{'bgcolor'});
4631: delete($attr_ref->{'background'});
4632: }
4633:
1.330 albertel 4634: my $attr_string;
4635: foreach my $attr (keys(%$attr_ref)) {
4636: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4637: }
4638: return $attr_string;
4639: }
4640:
4641:
1.182 matthew 4642: ###############################################
1.251 albertel 4643: ###############################################
4644:
4645: =pod
4646:
4647: =item * &endbodytag()
4648:
4649: Returns a uniform footer for LON-CAPA web pages.
4650:
1.635 raeburn 4651: Inputs: 1 - optional reference to an args hash
4652: If in the hash, key for noredirectlink has a value which evaluates to true,
4653: a 'Continue' link is not displayed if the page contains an
4654: internal redirect in the <head></head> section,
4655: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4656:
4657: =cut
4658:
4659: sub endbodytag {
1.635 raeburn 4660: my ($args) = @_;
1.251 albertel 4661: my $endbodytag='</body>';
1.269 albertel 4662: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4663: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4664: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4665: $endbodytag=
4666: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4667: &mt('Continue').'</a>'.
4668: $endbodytag;
4669: }
1.315 albertel 4670: }
1.251 albertel 4671: return $endbodytag;
4672: }
4673:
1.352 albertel 4674: =pod
4675:
4676: =item * &standard_css()
4677:
4678: Returns a style sheet
4679:
4680: Inputs: (all optional)
4681: domain -> force to color decorate a page for a specific
4682: domain
4683: function -> force usage of a specific rolish color scheme
4684: bgcolor -> override the default page bgcolor
4685:
4686: =cut
4687:
1.343 albertel 4688: sub standard_css {
1.345 albertel 4689: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4690: $function = &get_users_function() if (!$function);
4691: my $img = &designparm($function.'.img', $domain);
4692: my $tabbg = &designparm($function.'.tabbg', $domain);
4693: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4694: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4695: my $pgbg_or_bgcolor =
4696: $bgcolor ||
1.352 albertel 4697: &designparm($function.'.pgbg', $domain);
1.382 albertel 4698: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4699: my $alink = &designparm($function.'.alink', $domain);
4700: my $vlink = &designparm($function.'.vlink', $domain);
4701: my $link = &designparm($function.'.link', $domain);
4702:
1.602 albertel 4703: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4704: my $mono = 'monospace';
1.692.4.13 raeburn 4705: my $data_table_head = $tabbg;
1.692.4.6 raeburn 4706: my $data_table_light = '#FAFAFA';
4707: my $data_table_dark = '#F0F0F0';
1.470 banghart 4708: my $data_table_darker = '#CCCCCC';
1.349 albertel 4709: my $data_table_highlight = '#FFFF00';
1.352 albertel 4710: my $mail_new = '#FFBB77';
4711: my $mail_new_hover = '#DD9955';
4712: my $mail_read = '#BBBB77';
4713: my $mail_read_hover = '#999944';
4714: my $mail_replied = '#AAAA88';
4715: my $mail_replied_hover = '#888855';
4716: my $mail_other = '#99BBBB';
4717: my $mail_other_hover = '#669999';
1.391 albertel 4718: my $table_header = '#DDDDDD';
1.489 raeburn 4719: my $feedback_link_bg = '#BBBBBB';
1.692.4.3 raeburn 4720: my $lg_border_color = '#C8C8C8';
1.392 albertel 4721:
1.608 albertel 4722: my $border = ($env{'browser.type'} eq 'explorer' ||
1.692.4.2 raeburn 4723: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4724: : '0 3px 0 4px';
1.448 albertel 4725:
1.523 albertel 4726:
1.343 albertel 4727: return <<END;
1.345 albertel 4728: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4729: a:focus { color: red; background: yellow }
1.692.4.6 raeburn 4730:
4731: hr {
4732: clear: both;
4733: color: $tabbg;
4734: background-color: $tabbg;
4735: height: 3px;
4736: border: none;
4737: }
4738:
1.510 albertel 4739: table.thinborder,
1.523 albertel 4740:
1.510 albertel 4741: table.thinborder tr th {
4742: border-style: solid;
4743: border-width: 1px;
4744: background: $tabbg;
4745: }
1.523 albertel 4746: table.thinborder tr td {
1.510 albertel 4747: border-style: solid;
4748: border-width: 1px
4749: }
1.426 albertel 4750:
1.343 albertel 4751: form, .inline { display: inline; }
4752: .center { text-align: center; }
1.593 albertel 4753: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4754: .LC_error {
4755: color: red;
4756: font-size: larger;
4757: }
1.457 albertel 4758: .LC_warning,
4759: .LC_diff_removed {
1.394 albertel 4760: color: red;
4761: }
1.532 albertel 4762:
4763: .LC_info,
1.457 albertel 4764: .LC_success,
4765: .LC_diff_added {
1.350 albertel 4766: color: green;
4767: }
1.692.4.2 raeburn 4768:
4769: div.LC_confirm_box {
4770: background-color: #FAFAFA;
4771: border: 1px solid $lg_border_color;
4772: margin-right: 0;
4773: padding: 5px;
4774: }
4775:
4776: div.LC_confirm_box .LC_error img,
4777: div.LC_confirm_box .LC_success img {
4778: vertical-align: middle;
1.543 albertel 4779: }
4780:
1.440 albertel 4781: .LC_icon {
1.692.4.2 raeburn 4782: border: none;
1.440 albertel 4783: }
1.539 albertel 4784: .LC_indexer_icon {
1.692.4.2 raeburn 4785: border: 0;
1.539 albertel 4786: height: 22px;
4787: }
1.543 albertel 4788: .LC_docs_spacer {
4789: width: 25px;
4790: height: 1px;
1.692.4.2 raeburn 4791: border: none;
1.543 albertel 4792: }
1.346 albertel 4793:
1.532 albertel 4794: .LC_internal_info {
1.692.4.2 raeburn 4795: color: #999999;
1.532 albertel 4796: }
4797:
1.692.4.19 raeburn 4798: .LC_discussion {
4799: background: $tabbg;
4800: border: 1px solid black;
4801: margin: 2px;
4802: }
4803:
4804: .LC_disc_action_links_bar {
4805: background: $tabbg;
4806: border: none;
4807: margin: 4px;
4808: }
4809:
4810: .LC_disc_action_left {
4811: text-align: left;
4812: }
4813:
4814: .LC_disc_action_right {
4815: text-align: right;
4816: }
4817:
4818: .LC_disc_new_item {
4819: background: white;
4820: border: 2px solid red;
4821: margin: 2px;
4822: }
4823:
4824: .LC_disc_old_item {
4825: background: white;
4826: border: 1px solid black;
4827: margin: 2px;
4828: }
4829:
1.458 albertel 4830: table.LC_pastsubmission {
4831: border: 1px solid black;
4832: margin: 2px;
4833: }
4834:
1.606 albertel 4835: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4836: width: 100%;
4837: background: $pgbg;
1.392 albertel 4838: border: 2px;
1.402 albertel 4839: border-collapse: separate;
1.692.4.2 raeburn 4840: padding: 0;
1.345 albertel 4841: }
1.392 albertel 4842:
1.606 albertel 4843: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4844: table#LC_title_bar.LC_with_remote {
1.359 albertel 4845: width: 100%;
1.392 albertel 4846: border-color: $pgbg;
4847: border-style: solid;
4848: border-width: $border;
4849:
1.379 albertel 4850: background: $pgbg;
4851: font-family: $sans;
1.392 albertel 4852: border-collapse: collapse;
1.692.4.2 raeburn 4853: padding: 0;
1.359 albertel 4854: }
1.392 albertel 4855:
1.409 albertel 4856: table.LC_docs_path {
4857: width: 100%;
4858: border: 0;
4859: background: $pgbg;
4860: font-family: $sans;
4861: border-collapse: collapse;
1.692.4.2 raeburn 4862: padding: 0;
1.409 albertel 4863: }
4864:
1.359 albertel 4865: table#LC_title_bar td {
4866: background: $tabbg;
4867: }
4868: table#LC_title_bar td.LC_title_bar_who {
4869: background: $tabbg;
4870: color: $font;
1.427 albertel 4871: font: small $sans;
1.359 albertel 4872: text-align: right;
4873: }
1.469 banghart 4874: span.LC_metadata {
4875: font-family: $sans;
4876: }
1.359 albertel 4877: span.LC_title_bar_title {
1.416 albertel 4878: font: bold x-large $sans;
1.359 albertel 4879: }
4880: table#LC_title_bar td.LC_title_bar_domain_logo {
4881: background: $sidebg;
4882: text-align: right;
1.692.4.2 raeburn 4883: padding: 0;
1.368 albertel 4884: }
4885: table#LC_title_bar td.LC_title_bar_role_logo {
4886: background: $sidebg;
1.692.4.2 raeburn 4887: padding: 0;
1.359 albertel 4888: }
4889:
1.346 albertel 4890: table#LC_menubuttons_mainmenu {
1.526 www 4891: width: 100%;
1.692.4.2 raeburn 4892: border: 0;
1.346 albertel 4893: border-spacing: 1px;
1.692.4.2 raeburn 4894: padding: 0 1px;
4895: margin: 0;
1.346 albertel 4896: border-collapse: separate;
4897: }
4898: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
1.692.4.2 raeburn 4899: border: none;
1.346 albertel 4900: }
1.345 albertel 4901: table#LC_top_nav td {
4902: background: $tabbg;
1.692.4.2 raeburn 4903: border: none;
1.407 albertel 4904: font-size: small;
1.345 albertel 4905: }
4906: table#LC_top_nav td a, div#LC_top_nav a {
4907: color: $font;
4908: font-family: $sans;
4909: }
1.364 albertel 4910: table#LC_top_nav td.LC_top_nav_logo {
4911: background: $tabbg;
1.432 albertel 4912: text-align: left;
1.408 albertel 4913: white-space: nowrap;
1.432 albertel 4914: width: 31px;
1.408 albertel 4915: }
4916: table#LC_top_nav td.LC_top_nav_logo img {
1.692.4.2 raeburn 4917: border: none;
1.408 albertel 4918: vertical-align: bottom;
1.364 albertel 4919: }
1.432 albertel 4920: table#LC_top_nav td.LC_top_nav_exit,
4921: table#LC_top_nav td.LC_top_nav_help {
4922: width: 2.0em;
4923: }
1.442 albertel 4924: table#LC_top_nav td.LC_top_nav_login {
4925: width: 4.0em;
4926: text-align: center;
4927: }
1.409 albertel 4928: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4929: background: $tabbg;
4930: color: $font;
4931: font-family: $sans;
1.358 albertel 4932: font-size: smaller;
1.357 albertel 4933: }
1.411 albertel 4934: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4935: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4936: background: $tabbg;
4937: color: $font;
4938: font-family: $sans;
4939: font-size: larger;
4940: text-align: right;
4941: }
1.383 albertel 4942: td.LC_table_cell_checkbox {
4943: text-align: center;
4944: }
1.522 albertel 4945: table#LC_mainmenu td.LC_mainmenu_column {
4946: vertical-align: top;
4947: }
4948:
1.346 albertel 4949: .LC_menubuttons_inline_text {
4950: color: $font;
4951: font-family: $sans;
4952: font-size: smaller;
4953: }
4954:
1.526 www 4955: .LC_menubuttons_link {
4956: text-decoration: none;
4957: }
1.692.4.2 raeburn 4958: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4959: .LC_menubuttons_category {
1.521 www 4960: color: $font;
1.526 www 4961: background: $pgbg;
1.521 www 4962: font-family: $sans;
4963: font-size: larger;
4964: font-weight: bold;
4965: }
4966:
1.346 albertel 4967: td.LC_menubuttons_text {
1.526 www 4968: width: 90%;
1.346 albertel 4969: color: $font;
4970: font-family: $sans;
4971: }
1.526 www 4972:
1.346 albertel 4973: td.LC_menubuttons_img {
4974: }
1.526 www 4975:
1.346 albertel 4976: .LC_current_location {
4977: font-family: $sans;
4978: background: $tabbg;
4979: }
4980: .LC_new_mail {
4981: font-family: $sans;
1.634 www 4982: background: $tabbg;
1.346 albertel 4983: font-weight: bold;
4984: }
1.347 albertel 4985:
1.527 www 4986: .LC_dropadd_labeltext {
4987: font-family: $sans;
4988: text-align: right;
4989: }
4990:
4991: .LC_preferences_labeltext {
4992: font-family: $sans;
4993: text-align: right;
4994: }
4995:
1.666 raeburn 4996: .LC_roleslog_note {
4997: font-size: smaller;
4998: }
4999:
1.692.4.2 raeburn 5000: .LC_mail_functions {
5001: font-weight: bold;
5002: }
5003:
1.440 albertel 5004: table.LC_aboutme_port {
1.692.4.2 raeburn 5005: border: none;
1.440 albertel 5006: border-collapse: collapse;
1.692.4.2 raeburn 5007: border-spacing: 0;
1.440 albertel 5008: }
1.349 albertel 5009: table.LC_data_table, table.LC_mail_list {
1.347 albertel 5010: border: 1px solid #000000;
1.402 albertel 5011: border-collapse: separate;
1.426 albertel 5012: border-spacing: 1px;
1.610 albertel 5013: background: $pgbg;
1.347 albertel 5014: }
1.422 albertel 5015: .LC_data_table_dense {
5016: font-size: small;
5017: }
1.507 raeburn 5018: table.LC_nested_outer {
5019: border: 1px solid #000000;
1.589 raeburn 5020: border-collapse: collapse;
1.692.4.2 raeburn 5021: border-spacing: 0;
1.507 raeburn 5022: width: 100%;
5023: }
1.692.4.11 raeburn 5024: table.LC_innerpickbox,
1.507 raeburn 5025: table.LC_nested {
1.692.4.2 raeburn 5026: border: none;
1.589 raeburn 5027: border-collapse: collapse;
1.692.4.2 raeburn 5028: border-spacing: 0;
1.507 raeburn 5029: width: 100%;
5030: }
1.523 albertel 5031: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
1.692.4.11 raeburn 5032: table.LC_prior_tries tr th,
5033: table.LC_innerpickbox tr th {
1.349 albertel 5034: font-weight: bold;
5035: background-color: $data_table_head;
1.421 albertel 5036: font-size: smaller;
1.347 albertel 5037: }
1.692.4.11 raeburn 5038: table.LC_innerpickbox tr th,
5039: table.LC_innerpickbox tr td {
5040: vertical-align: top;
5041: }
1.692.4.2 raeburn 5042: table.LC_data_table tr.LC_info_row > td {
5043: background-color: #CCCCCC;
5044: font-weight: bold;
5045: text-align: left;
5046: }
1.610 albertel 5047: table.LC_data_table tr.LC_odd_row > td,
1.692.4.2 raeburn 5048: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 5049: table.LC_aboutme_port tr td {
1.349 albertel 5050: background-color: $data_table_light;
1.425 albertel 5051: padding: 2px;
1.347 albertel 5052: }
1.610 albertel 5053: table.LC_data_table tr.LC_even_row > td,
1.692.4.2 raeburn 5054: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 5055: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 5056: background-color: $data_table_dark;
1.692.4.2 raeburn 5057: padding: 2px;
1.347 albertel 5058: }
1.425 albertel 5059: table.LC_data_table tr.LC_data_table_highlight td {
5060: background-color: $data_table_darker;
5061: }
1.639 raeburn 5062: table.LC_data_table tr td.LC_leftcol_header {
5063: background-color: $data_table_head;
5064: font-weight: bold;
5065: }
1.451 albertel 5066: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5067: table.LC_nested tr.LC_empty_row td {
1.347 albertel 5068: background-color: #FFFFFF;
1.421 albertel 5069: font-weight: bold;
5070: font-style: italic;
5071: text-align: center;
5072: padding: 8px;
1.347 albertel 5073: }
1.507 raeburn 5074: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5075: padding: 4ex
5076: }
1.507 raeburn 5077: table.LC_nested_outer tr th {
5078: font-weight: bold;
5079: background-color: $data_table_head;
5080: font-size: smaller;
5081: border-bottom: 1px solid #000000;
5082: }
5083: table.LC_nested_outer tr td.LC_subheader {
5084: background-color: $data_table_head;
5085: font-weight: bold;
5086: font-size: small;
5087: border-bottom: 1px solid #000000;
5088: text-align: right;
1.451 albertel 5089: }
1.507 raeburn 5090: table.LC_nested tr.LC_info_row td {
1.692.4.2 raeburn 5091: background-color: #CCCCCC;
1.451 albertel 5092: font-weight: bold;
5093: font-size: small;
1.507 raeburn 5094: text-align: center;
5095: }
1.589 raeburn 5096: table.LC_nested tr.LC_info_row td.LC_left_item,
5097: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5098: text-align: left;
1.451 albertel 5099: }
1.507 raeburn 5100: table.LC_nested td {
1.692.4.2 raeburn 5101: background-color: #FFFFFF;
1.451 albertel 5102: font-size: small;
1.507 raeburn 5103: }
5104: table.LC_nested_outer tr th.LC_right_item,
5105: table.LC_nested tr.LC_info_row td.LC_right_item,
5106: table.LC_nested tr.LC_odd_row td.LC_right_item,
5107: table.LC_nested tr td.LC_right_item {
1.451 albertel 5108: text-align: right;
5109: }
5110:
1.507 raeburn 5111: table.LC_nested tr.LC_odd_row td {
1.692.4.2 raeburn 5112: background-color: #EEEEEE;
1.451 albertel 5113: }
5114:
1.473 raeburn 5115: table.LC_createuser {
5116: }
5117:
5118: table.LC_createuser tr.LC_section_row td {
5119: font-size: smaller;
5120: }
5121:
5122: table.LC_createuser tr.LC_info_row td {
1.692.4.2 raeburn 5123: background-color: #CCCCCC;
1.473 raeburn 5124: font-weight: bold;
5125: text-align: center;
5126: }
5127:
1.349 albertel 5128: table.LC_calendar {
5129: border: 1px solid #000000;
5130: border-collapse: collapse;
5131: }
5132: table.LC_calendar_pickdate {
5133: font-size: xx-small;
5134: }
5135: table.LC_calendar tr td {
5136: border: 1px solid #000000;
5137: vertical-align: top;
5138: }
5139: table.LC_calendar tr td.LC_calendar_day_empty {
5140: background-color: $data_table_dark;
5141: }
5142: table.LC_calendar tr td.LC_calendar_day_current {
5143: background-color: $data_table_highlight;
5144: }
5145:
5146: table.LC_mail_list tr.LC_mail_new {
5147: background-color: $mail_new;
5148: }
5149: table.LC_mail_list tr.LC_mail_new:hover {
5150: background-color: $mail_new_hover;
5151: }
5152: table.LC_mail_list tr.LC_mail_read {
5153: background-color: $mail_read;
5154: }
5155: table.LC_mail_list tr.LC_mail_read:hover {
5156: background-color: $mail_read_hover;
5157: }
5158: table.LC_mail_list tr.LC_mail_replied {
5159: background-color: $mail_replied;
5160: }
5161: table.LC_mail_list tr.LC_mail_replied:hover {
5162: background-color: $mail_replied_hover;
5163: }
5164: table.LC_mail_list tr.LC_mail_other {
5165: background-color: $mail_other;
5166: }
5167: table.LC_mail_list tr.LC_mail_other:hover {
5168: background-color: $mail_other_hover;
5169: }
1.494 raeburn 5170: table.LC_mail_list tr.LC_mail_even {
5171: }
5172: table.LC_mail_list tr.LC_mail_odd {
5173: }
5174:
1.385 albertel 5175:
1.386 albertel 5176: table#LC_portfolio_actions {
5177: width: auto;
5178: background: $pgbg;
1.692.4.2 raeburn 5179: border: none;
1.386 albertel 5180: border-spacing: 2px 2px;
1.692.4.2 raeburn 5181: padding: 0;
5182: margin: 0;
1.386 albertel 5183: border-collapse: separate;
5184: }
5185: table#LC_portfolio_actions td.LC_label {
5186: background: $tabbg;
5187: text-align: right;
5188: }
5189: table#LC_portfolio_actions td.LC_value {
5190: background: $tabbg;
5191: }
1.385 albertel 5192:
1.391 albertel 5193: table#LC_cstr_controls {
5194: width: 100%;
5195: border-collapse: collapse;
5196: }
5197: table#LC_cstr_controls tr td {
5198: border: 4px solid $pgbg;
5199: padding: 4px;
5200: text-align: center;
5201: background: $tabbg;
5202: }
5203: table#LC_cstr_controls tr th {
5204: border: 4px solid $pgbg;
5205: background: $table_header;
5206: text-align: center;
5207: font-family: $sans;
5208: font-size: smaller;
5209: }
5210:
1.389 albertel 5211: table#LC_browser {
5212:
5213: }
5214: table#LC_browser tr th {
1.391 albertel 5215: background: $table_header;
1.389 albertel 5216: }
1.390 albertel 5217: table#LC_browser tr td {
5218: padding: 2px;
5219: }
1.389 albertel 5220: table#LC_browser tr.LC_browser_file,
5221: table#LC_browser tr.LC_browser_file_published {
5222: background: #CCFF88;
5223: }
5224: table#LC_browser tr.LC_browser_file_locked,
5225: table#LC_browser tr.LC_browser_file_unpublished {
5226: background: #FFAA99;
1.387 albertel 5227: }
1.389 albertel 5228: table#LC_browser tr.LC_browser_file_obsolete {
5229: background: #AAAAAA;
1.387 albertel 5230: }
1.455 albertel 5231: table#LC_browser tr.LC_browser_file_modified,
5232: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 5233: background: #FFFF77;
1.387 albertel 5234: }
1.389 albertel 5235: table#LC_browser tr.LC_browser_folder {
5236: background: #CCCCFF;
1.387 albertel 5237: }
1.692.4.2 raeburn 5238:
5239: table.LC_data_table tr > td.LC_roles_is {
5240: /* background: #77FF77; */
5241: }
5242: table.LC_data_table tr > td.LC_roles_future {
5243: background: #FFFF77;
5244: }
5245: table.LC_data_table tr > td.LC_roles_will {
5246: background: #FFAA77;
5247: }
5248: table.LC_data_table tr > td.LC_roles_expired {
5249: background: #FF7777;
5250: }
5251: table.LC_data_table tr > td.LC_roles_will_not {
5252: background: #AAFF77;
5253: }
5254: table.LC_data_table tr > td.LC_roles_selected {
5255: background: #11CC55;
5256: }
5257:
1.388 albertel 5258: span.LC_current_location {
5259: font-size: x-large;
5260: background: $pgbg;
5261: }
1.387 albertel 5262:
1.395 albertel 5263: span.LC_parm_menu_item {
5264: font-size: larger;
5265: font-family: $sans;
5266: }
5267: span.LC_parm_scope_all {
5268: color: red;
5269: }
5270: span.LC_parm_scope_folder {
5271: color: green;
5272: }
5273: span.LC_parm_scope_resource {
5274: color: orange;
5275: }
5276: span.LC_parm_part {
5277: color: blue;
5278: }
5279: span.LC_parm_folder, span.LC_parm_symb {
5280: font-size: x-small;
5281: font-family: $mono;
5282: color: #AAAAAA;
5283: }
5284:
1.396 albertel 5285: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
5286: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
5287: border: 1px solid black;
5288: border-collapse: collapse;
5289: }
5290: table.LC_parm_overview_restrictions td {
5291: border-width: 1px 4px 1px 4px;
5292: border-style: solid;
5293: border-color: $pgbg;
5294: text-align: center;
5295: }
5296: table.LC_parm_overview_restrictions th {
5297: background: $tabbg;
5298: border-width: 1px 4px 1px 4px;
5299: border-style: solid;
5300: border-color: $pgbg;
5301: }
1.398 albertel 5302: table#LC_helpmenu {
1.692.4.2 raeburn 5303: border: none;
1.398 albertel 5304: height: 55px;
1.692.4.2 raeburn 5305: border-spacing: 0;
1.398 albertel 5306: }
5307:
5308: table#LC_helpmenu fieldset legend {
5309: font-size: larger;
5310: font-weight: bold;
5311: }
1.397 albertel 5312: table#LC_helpmenu_links {
5313: width: 100%;
5314: border: 1px solid black;
5315: background: $pgbg;
1.692.4.2 raeburn 5316: padding: 0;
1.397 albertel 5317: border-spacing: 1px;
5318: }
5319: table#LC_helpmenu_links tr td {
5320: padding: 1px;
5321: background: $tabbg;
1.399 albertel 5322: text-align: center;
5323: font-weight: bold;
1.397 albertel 5324: }
1.396 albertel 5325:
1.397 albertel 5326: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5327: table#LC_helpmenu_links a:active {
5328: text-decoration: none;
5329: color: $font;
5330: }
5331: table#LC_helpmenu_links a:hover {
5332: text-decoration: underline;
5333: color: $vlink;
5334: }
1.396 albertel 5335:
1.417 albertel 5336: .LC_chrt_popup_exists {
5337: border: 1px solid #339933;
5338: margin: -1px;
5339: }
5340: .LC_chrt_popup_up {
5341: border: 1px solid yellow;
5342: margin: -1px;
5343: }
5344: .LC_chrt_popup {
5345: border: 1px solid #8888FF;
5346: background: #CCCCFF;
5347: }
1.421 albertel 5348: table.LC_pick_box {
5349: border-collapse: separate;
5350: background: white;
5351: border: 1px solid black;
5352: border-spacing: 1px;
5353: }
5354: table.LC_pick_box td.LC_pick_box_title {
1.692.4.16 raeburn 5355: background: $tabbg;
1.421 albertel 5356: font-weight: bold;
5357: text-align: right;
1.692.4.2 raeburn 5358: vertical-align: top;
1.421 albertel 5359: width: 184px;
5360: padding: 8px;
5361: }
1.645 raeburn 5362: table.LC_pick_box td.LC_selfenroll_pick_box_title {
1.692.4.16 raeburn 5363: background: $tabbg;
1.645 raeburn 5364: font-weight: bold;
5365: text-align: right;
5366: width: 350px;
5367: padding: 8px;
5368: }
5369:
1.579 raeburn 5370: table.LC_pick_box td.LC_pick_box_value {
5371: text-align: left;
5372: padding: 8px;
5373: }
5374: table.LC_pick_box td.LC_pick_box_select {
5375: text-align: left;
5376: padding: 8px;
5377: }
1.424 albertel 5378: table.LC_pick_box td.LC_pick_box_separator {
1.692.4.2 raeburn 5379: padding: 0;
1.421 albertel 5380: height: 1px;
5381: background: black;
5382: }
5383: table.LC_pick_box td.LC_pick_box_submit {
5384: text-align: right;
5385: }
1.579 raeburn 5386: table.LC_pick_box td.LC_evenrow_value {
5387: text-align: left;
5388: padding: 8px;
5389: background-color: $data_table_light;
5390: }
5391: table.LC_pick_box td.LC_oddrow_value {
5392: text-align: left;
5393: padding: 8px;
5394: background-color: $data_table_light;
5395: }
5396: table.LC_helpform_receipt {
5397: width: 620px;
5398: border-collapse: separate;
5399: background: white;
5400: border: 1px solid black;
5401: border-spacing: 1px;
5402: }
5403: table.LC_helpform_receipt td.LC_pick_box_title {
5404: background: $tabbg;
5405: font-weight: bold;
5406: text-align: right;
5407: width: 184px;
5408: padding: 8px;
5409: }
5410: table.LC_helpform_receipt td.LC_evenrow_value {
5411: text-align: left;
5412: padding: 8px;
5413: background-color: $data_table_light;
5414: }
5415: table.LC_helpform_receipt td.LC_oddrow_value {
5416: text-align: left;
5417: padding: 8px;
5418: background-color: $data_table_light;
5419: }
5420: table.LC_helpform_receipt td.LC_pick_box_separator {
1.692.4.2 raeburn 5421: padding: 0;
1.579 raeburn 5422: height: 1px;
5423: background: black;
5424: }
5425: span.LC_helpform_receipt_cat {
5426: font-weight: bold;
5427: }
1.424 albertel 5428: table.LC_group_priv_box {
5429: background: white;
5430: border: 1px solid black;
5431: border-spacing: 1px;
5432: }
5433: table.LC_group_priv_box td.LC_pick_box_title {
5434: background: $tabbg;
5435: font-weight: bold;
5436: text-align: right;
5437: width: 184px;
5438: }
5439: table.LC_group_priv_box td.LC_groups_fixed {
5440: background: $data_table_light;
5441: text-align: center;
5442: }
5443: table.LC_group_priv_box td.LC_groups_optional {
5444: background: $data_table_dark;
5445: text-align: center;
5446: }
5447: table.LC_group_priv_box td.LC_groups_functionality {
5448: background: $data_table_darker;
5449: text-align: center;
5450: font-weight: bold;
5451: }
5452: table.LC_group_priv td {
5453: text-align: left;
1.692.4.2 raeburn 5454: padding: 0;
1.424 albertel 5455: }
5456:
1.421 albertel 5457: table.LC_notify_front_page {
5458: background: white;
5459: border: 1px solid black;
5460: padding: 8px;
5461: }
5462: table.LC_notify_front_page td {
5463: padding: 8px;
5464: }
1.424 albertel 5465: .LC_navbuttons {
5466: margin: 2ex 0ex 2ex 0ex;
5467: }
1.423 albertel 5468: .LC_topic_bar {
5469: font-family: $sans;
5470: font-weight: bold;
5471: width: 100%;
5472: background: $tabbg;
5473: vertical-align: middle;
5474: margin: 2ex 0ex 2ex 0ex;
1.692.4.2 raeburn 5475: padding: 3px;
1.423 albertel 5476: }
5477: .LC_topic_bar span {
5478: vertical-align: middle;
5479: }
5480: .LC_topic_bar img {
5481: vertical-align: bottom;
5482: }
5483: table.LC_course_group_status {
5484: margin: 20px;
5485: }
5486: table.LC_status_selector td {
5487: vertical-align: top;
5488: text-align: center;
1.424 albertel 5489: padding: 4px;
5490: }
5491: table.LC_descriptive_input td.LC_description {
5492: vertical-align: top;
5493: text-align: right;
5494: font-weight: bold;
1.423 albertel 5495: }
1.599 albertel 5496: div.LC_feedback_link {
1.616 albertel 5497: clear: both;
1.599 albertel 5498: background: white;
5499: width: 100%;
1.489 raeburn 5500: }
5501: span.LC_feedback_link {
1.599 albertel 5502: background: $feedback_link_bg;
5503: font-size: larger;
5504: }
5505: span.LC_message_link {
5506: background: $feedback_link_bg;
5507: font-size: larger;
5508: position: absolute;
5509: right: 1em;
1.489 raeburn 5510: }
1.421 albertel 5511:
1.515 albertel 5512: table.LC_prior_tries {
1.524 albertel 5513: border: 1px solid #000000;
5514: border-collapse: separate;
5515: border-spacing: 1px;
1.515 albertel 5516: }
1.523 albertel 5517:
1.515 albertel 5518: table.LC_prior_tries td {
1.524 albertel 5519: padding: 2px;
1.515 albertel 5520: }
1.523 albertel 5521:
5522: .LC_answer_correct {
5523: background: #AAFFAA;
5524: color: black;
5525: }
5526: .LC_answer_charged_try {
5527: background: #FFAAAA ! important;
5528: color: black;
5529: }
5530: .LC_answer_not_charged_try,
5531: .LC_answer_no_grade,
5532: .LC_answer_late {
5533: background: #FFFFAA;
5534: color: black;
5535: }
5536: .LC_answer_previous {
5537: background: #AAAAFF;
5538: color: black;
5539: }
5540: .LC_answer_no_message {
5541: background: #FFFFFF;
5542: color: black;
5543: }
5544: .LC_answer_unknown {
5545: background: orange;
5546: color: black;
5547: }
5548:
5549:
1.529 albertel 5550: span.LC_prior_numerical,
5551: span.LC_prior_string,
5552: span.LC_prior_custom,
5553: span.LC_prior_reaction,
5554: span.LC_prior_math {
1.523 albertel 5555: font-family: monospace;
5556: white-space: pre;
5557: }
5558:
1.525 albertel 5559: span.LC_prior_string {
5560: font-family: monospace;
5561: white-space: pre;
5562: }
5563:
1.523 albertel 5564: table.LC_prior_option {
5565: width: 100%;
5566: border-collapse: collapse;
5567: }
1.528 albertel 5568: table.LC_prior_rank, table.LC_prior_match {
5569: border-collapse: collapse;
5570: }
5571: table.LC_prior_option tr td,
5572: table.LC_prior_rank tr td,
5573: table.LC_prior_match tr td {
1.524 albertel 5574: border: 1px solid #000000;
1.515 albertel 5575: }
5576:
1.519 raeburn 5577: span.LC_nobreak {
1.544 albertel 5578: white-space: nowrap;
1.519 raeburn 5579: }
5580:
1.576 raeburn 5581: span.LC_cusr_emph {
5582: font-style: italic;
5583: }
5584:
1.633 raeburn 5585: span.LC_cusr_subheading {
5586: font-weight: normal;
5587: font-size: 85%;
5588: }
5589:
1.545 albertel 5590: table.LC_docs_documents {
5591: background: #BBBBBB;
1.692.4.2 raeburn 5592: border-width: 0;
1.545 albertel 5593: border-collapse: collapse;
5594: }
5595:
5596: table.LC_docs_documents td.LC_docs_document {
5597: border: 2px solid black;
5598: padding: 4px;
5599: }
5600:
5601: .LC_docs_course_commands div {
5602: float: left;
5603: border: 4px solid #AAAAAA;
5604: padding: 4px;
5605: background: #DDDDCC;
5606: }
5607:
5608: .LC_docs_entry_move {
1.692.4.2 raeburn 5609: border: none;
1.545 albertel 5610: border-collapse: collapse;
1.544 albertel 5611: }
5612:
1.545 albertel 5613: .LC_docs_entry_move td {
5614: border: 2px solid #BBBBBB;
5615: background: #DDDDDD;
5616: }
5617:
5618: .LC_docs_editor td.LC_docs_entry_commands {
5619: background: #DDDDDD;
5620: font-size: x-small;
5621: }
1.544 albertel 5622: .LC_docs_copy {
1.545 albertel 5623: color: #000099;
1.544 albertel 5624: }
5625: .LC_docs_cut {
1.545 albertel 5626: color: #550044;
1.544 albertel 5627: }
5628: .LC_docs_rename {
1.545 albertel 5629: color: #009900;
1.544 albertel 5630: }
5631: .LC_docs_remove {
1.545 albertel 5632: color: #990000;
5633: }
5634:
1.547 albertel 5635: .LC_docs_reinit_warn,
5636: .LC_docs_ext_edit {
5637: font-size: x-small;
5638: }
5639:
1.545 albertel 5640: .LC_docs_editor td.LC_docs_entry_title,
5641: .LC_docs_editor td.LC_docs_entry_icon {
5642: background: #FFFFBB;
5643: }
5644: .LC_docs_editor td.LC_docs_entry_parameter {
5645: background: #BBBBFF;
5646: font-size: x-small;
5647: white-space: nowrap;
5648: }
5649:
5650: table.LC_docs_adddocs td,
5651: table.LC_docs_adddocs th {
5652: border: 1px solid #BBBBBB;
5653: padding: 4px;
5654: background: #DDDDDD;
1.543 albertel 5655: }
5656:
1.584 albertel 5657: table.LC_sty_begin {
5658: background: #BBFFBB;
5659: }
5660: table.LC_sty_end {
5661: background: #FFBBBB;
5662: }
5663:
1.589 raeburn 5664: table.LC_double_column {
1.692.4.2 raeburn 5665: border-width: 0;
1.589 raeburn 5666: border-collapse: collapse;
5667: width: 100%;
5668: padding: 2px;
5669: }
5670:
5671: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5672: top: 2px;
1.589 raeburn 5673: left: 2px;
5674: width: 47%;
5675: vertical-align: top;
5676: }
5677:
5678: table.LC_double_column tr td.LC_right_col {
5679: top: 2px;
5680: right: 2px;
5681: width: 47%;
5682: vertical-align: top;
5683: }
5684:
1.594 raeburn 5685: span.LC_role_level {
5686: font-weight: bold;
5687: }
5688:
1.591 raeburn 5689: div.LC_left_float {
5690: float: left;
5691: padding-right: 5%;
1.597 albertel 5692: padding-bottom: 4px;
1.591 raeburn 5693: }
5694:
5695: div.LC_clear_float_header {
1.597 albertel 5696: padding-bottom: 2px;
1.591 raeburn 5697: }
5698:
5699: div.LC_clear_float_footer {
1.597 albertel 5700: padding-top: 10px;
1.591 raeburn 5701: clear: both;
5702: }
5703:
1.597 albertel 5704:
1.601 albertel 5705: div.LC_grade_select_mode {
1.604 albertel 5706: font-family: $sans;
1.601 albertel 5707: }
5708: div.LC_grade_select_mode div div {
5709: margin: 5px;
5710: }
5711: div.LC_grade_select_mode_selector {
5712: margin: 5px;
5713: float: left;
5714: }
5715: div.LC_grade_select_mode_selector_header {
5716: font: bold medium $sans;
5717: }
5718: div.LC_grade_select_mode_type {
5719: clear: left;
5720: }
5721:
1.597 albertel 5722: div.LC_grade_show_user {
5723: margin-top: 20px;
5724: border: 1px solid black;
5725: }
5726: div.LC_grade_user_name {
5727: background: #DDDDEE;
5728: border-bottom: 1px solid black;
5729: font: bold large $sans;
5730: }
5731: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5732: background: #DDEEDD;
5733: }
5734:
5735: div.LC_grade_show_problem,
5736: div.LC_grade_submissions,
5737: div.LC_grade_message_center,
5738: div.LC_grade_info_links,
5739: div.LC_grade_assign {
5740: margin: 5px;
5741: width: 99%;
5742: background: #FFFFFF;
5743: }
5744: div.LC_grade_show_problem_header,
5745: div.LC_grade_submissions_header,
5746: div.LC_grade_message_center_header,
5747: div.LC_grade_assign_header {
5748: font: bold large $sans;
5749: }
5750: div.LC_grade_show_problem_problem,
5751: div.LC_grade_submissions_body,
5752: div.LC_grade_message_center_body,
5753: div.LC_grade_assign_body {
5754: border: 1px solid black;
5755: width: 99%;
5756: background: #FFFFFF;
5757: }
1.598 albertel 5758: span.LC_grade_check_note {
5759: font: normal medium $sans;
5760: display: inline;
5761: position: absolute;
5762: right: 1em;
5763: }
1.597 albertel 5764:
1.613 albertel 5765: table.LC_scantron_action {
5766: width: 100%;
5767: }
5768: table.LC_scantron_action tr th {
5769: font: normal bold $sans;
5770: }
1.600 albertel 5771:
1.614 albertel 5772: div.LC_edit_problem_header,
5773: div.LC_edit_problem_footer {
1.600 albertel 5774: font: normal medium $sans;
1.602 albertel 5775: margin: 2px;
1.600 albertel 5776: }
5777: div.LC_edit_problem_header,
1.602 albertel 5778: div.LC_edit_problem_header div,
1.614 albertel 5779: div.LC_edit_problem_footer,
5780: div.LC_edit_problem_footer div,
1.602 albertel 5781: div.LC_edit_problem_editxml_header,
5782: div.LC_edit_problem_editxml_header div {
1.600 albertel 5783: margin-top: 5px;
5784: }
1.602 albertel 5785: div.LC_edit_problem_header_edit_row {
5786: background: $tabbg;
5787: padding: 3px;
5788: margin-bottom: 5px;
5789: }
1.600 albertel 5790: div.LC_edit_problem_header_title {
1.602 albertel 5791: font: larger bold $sans;
5792: background: $tabbg;
5793: padding: 3px;
5794: }
5795: table.LC_edit_problem_header_title {
5796: font: larger bold $sans;
5797: width: 100%;
5798: border-color: $pgbg;
5799: border-style: solid;
5800: border-width: $border;
5801:
1.600 albertel 5802: background: $tabbg;
1.602 albertel 5803: border-collapse: collapse;
1.692.4.2 raeburn 5804: padding: 0;
1.602 albertel 5805: }
5806:
5807: div.LC_edit_problem_discards {
5808: float: left;
5809: padding-bottom: 5px;
5810: }
5811: div.LC_edit_problem_saves {
5812: float: right;
5813: padding-bottom: 5px;
1.600 albertel 5814: }
5815: hr.LC_edit_problem_divide {
1.602 albertel 5816: clear: both;
1.600 albertel 5817: color: $tabbg;
5818: background-color: $tabbg;
5819: height: 3px;
1.692.4.2 raeburn 5820: border: none;
1.600 albertel 5821: }
1.679 riegler 5822: img.stift{
1.678 riegler 5823: border-width:0;
1.679 riegler 5824: vertical-align:middle;
1.677 riegler 5825: }
1.680 riegler 5826:
1.681 riegler 5827: table#LC_mainmenu{
5828: margin-top:10px;
5829: width:80%;
5830:
5831: }
5832:
1.680 riegler 5833: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5834: vertical-align: top;
5835: width: 45%;
5836: }
5837: .LC_mainmenu_fieldset_category {
5838: color: $font;
5839: background: $pgbg;
5840: font-family: $sans;
5841: font-size: small;
5842: font-weight: bold;
5843: }
5844: fieldset#LC_mainmenu_fieldset {
1.692.4.2 raeburn 5845: margin:0 10px 10px 0;
5846:
5847: }
1.680 riegler 5848:
1.692.4.2 raeburn 5849: div.LC_createcourse {
5850: margin: 10px 10px 10px 10px;
1.680 riegler 5851: }
1.692.4.2 raeburn 5852:
1.343 albertel 5853: END
5854: }
5855:
1.306 albertel 5856: =pod
5857:
5858: =item * &headtag()
5859:
5860: Returns a uniform footer for LON-CAPA web pages.
5861:
1.307 albertel 5862: Inputs: $title - optional title for the head
5863: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5864: $args - optional arguments
1.319 albertel 5865: force_register - if is true call registerurl so the remote is
5866: informed
1.415 albertel 5867: redirect -> array ref of
5868: 1- seconds before redirect occurs
5869: 2- url to redirect to
5870: 3- whether the side effect should occur
1.315 albertel 5871: (side effect of setting
5872: $env{'internal.head.redirect'} to the url
5873: redirected too)
1.352 albertel 5874: domain -> force to color decorate a page for a specific
5875: domain
5876: function -> force usage of a specific rolish color scheme
5877: bgcolor -> override the default page bgcolor
1.460 albertel 5878: no_auto_mt_title
5879: -> prevent &mt()ing the title arg
1.464 albertel 5880:
1.306 albertel 5881: =cut
5882:
5883: sub headtag {
1.313 albertel 5884: my ($title,$head_extra,$args) = @_;
1.306 albertel 5885:
1.363 albertel 5886: my $function = $args->{'function'} || &get_users_function();
5887: my $domain = $args->{'domain'} || &determinedomain();
5888: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5889: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5890: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5891: #time(),
1.418 albertel 5892: $env{'environment.color.timestamp'},
1.363 albertel 5893: $function,$domain,$bgcolor);
5894:
1.369 www 5895: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5896:
1.308 albertel 5897: my $result =
5898: '<head>'.
1.461 albertel 5899: &font_settings();
1.319 albertel 5900:
1.461 albertel 5901: if (!$args->{'frameset'}) {
5902: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5903: }
1.319 albertel 5904: if ($args->{'force_register'}) {
5905: $result .= &Apache::lonmenu::registerurl(1);
5906: }
1.436 albertel 5907: if (!$args->{'no_nav_bar'}
5908: && !$args->{'only_body'}
5909: && !$args->{'frameset'}) {
5910: $result .= &help_menu_js();
5911: }
1.319 albertel 5912:
1.314 albertel 5913: if (ref($args->{'redirect'})) {
1.414 albertel 5914: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5915: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5916: if (!$inhibit_continue) {
5917: $env{'internal.head.redirect'} = $url;
5918: }
1.313 albertel 5919: $result.=<<ADDMETA
5920: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5921: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5922: ADDMETA
5923: }
1.306 albertel 5924: if (!defined($title)) {
5925: $title = 'The LearningOnline Network with CAPA';
5926: }
1.460 albertel 5927: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5928: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5929: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5930: .$head_extra;
1.306 albertel 5931: return $result;
5932: }
5933:
5934: =pod
5935:
1.340 albertel 5936: =item * &font_settings()
5937:
5938: Returns neccessary <meta> to set the proper encoding
5939:
5940: Inputs: none
5941:
5942: =cut
5943:
5944: sub font_settings {
5945: my $headerstring='';
1.647 www 5946: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5947: $headerstring.=
5948: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5949: }
5950: return $headerstring;
5951: }
5952:
1.341 albertel 5953: =pod
5954:
5955: =item * &xml_begin()
5956:
5957: Returns the needed doctype and <html>
5958:
5959: Inputs: none
5960:
5961: =cut
5962:
5963: sub xml_begin {
5964: my $output='';
5965:
1.592 albertel 5966: if ($env{'internal.start_page'}==1) {
5967: &Apache::lonhtmlcommon::init_htmlareafields();
5968: }
1.342 albertel 5969:
1.341 albertel 5970: if ($env{'browser.mathml'}) {
5971: $output='<?xml version="1.0"?>'
5972: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5973: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5974:
5975: # .'<!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">] >'
5976: .'<!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">'
5977: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5978: .'xmlns="http://www.w3.org/1999/xhtml">';
5979: } else {
1.692.4.6 raeburn 5980: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.
5981: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 5982: }
5983: return $output;
5984: }
1.340 albertel 5985:
5986: =pod
5987:
1.306 albertel 5988: =item * &endheadtag()
5989:
5990: Returns a uniform </head> for LON-CAPA web pages.
5991:
5992: Inputs: none
5993:
5994: =cut
5995:
5996: sub endheadtag {
5997: return '</head>';
5998: }
5999:
6000: =pod
6001:
6002: =item * &head()
6003:
6004: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6005:
1.648 raeburn 6006: Inputs:
6007:
6008: =over 4
6009:
6010: $title - optional title for the page
6011:
6012: $head_extra - optional extra HTML to put inside the <head>
6013:
6014: =back
1.405 albertel 6015:
1.306 albertel 6016: =cut
6017:
6018: sub head {
1.325 albertel 6019: my ($title,$head_extra,$args) = @_;
6020: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6021: }
6022:
6023: =pod
6024:
6025: =item * &start_page()
6026:
6027: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6028:
1.648 raeburn 6029: Inputs:
6030:
6031: =over 4
6032:
6033: $title - optional title for the page
6034:
6035: $head_extra - optional extra HTML to incude inside the <head>
6036:
6037: $args - additional optional args supported are:
6038:
6039: =over 8
6040:
6041: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6042: arg on
1.648 raeburn 6043: no_nav_bar -> is true will set &bodytag() notopbar arg on
6044: add_entries -> additional attributes to add to the <body>
6045: domain -> force to color decorate a page for a
1.317 albertel 6046: specific domain
1.648 raeburn 6047: function -> force usage of a specific rolish color
1.317 albertel 6048: scheme
1.648 raeburn 6049: redirect -> see &headtag()
6050: bgcolor -> override the default page bg color
6051: js_ready -> return a string ready for being used in
1.317 albertel 6052: a javascript writeln
1.648 raeburn 6053: html_encode -> return a string ready for being used in
1.320 albertel 6054: a html attribute
1.648 raeburn 6055: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6056: $forcereg arg
1.648 raeburn 6057: body_title -> alternate text to use instead of $title
1.326 albertel 6058: in the title box that appears, this text
6059: is not auto translated like the $title is
1.648 raeburn 6060: frameset -> if true will start with a <frameset>
1.330 albertel 6061: rather than <body>
1.648 raeburn 6062: no_title -> if true the title bar won't be shown
6063: skip_phases -> hash ref of
1.338 albertel 6064: head -> skip the <html><head> generation
6065: body -> skip all <body> generation
1.648 raeburn 6066: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6067: 'Switch To Inline Menu' link
1.648 raeburn 6068: no_auto_mt_title -> prevent &mt()ing the title arg
6069: inherit_jsmath -> when creating popup window in a page,
6070: should it have jsmath forced on by the
6071: current page
1.361 albertel 6072:
1.648 raeburn 6073: =back
1.460 albertel 6074:
1.648 raeburn 6075: =back
1.562 albertel 6076:
1.306 albertel 6077: =cut
6078:
6079: sub start_page {
1.309 albertel 6080: my ($title,$head_extra,$args) = @_;
1.318 albertel 6081: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6082: my %head_args;
1.352 albertel 6083: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6084: 'bgcolor','frameset','no_nav_bar','only_body',
6085: 'no_auto_mt_title') {
1.319 albertel 6086: if (defined($args->{$arg})) {
1.324 raeburn 6087: $head_args{$arg} = $args->{$arg};
1.319 albertel 6088: }
1.313 albertel 6089: }
1.319 albertel 6090:
1.315 albertel 6091: $env{'internal.start_page'}++;
1.338 albertel 6092: my $result;
6093: if (! exists($args->{'skip_phases'}{'head'}) ) {
6094: $result.=
1.341 albertel 6095: &xml_begin().
1.338 albertel 6096: &headtag($title,$head_extra,\%head_args).&endheadtag();
6097: }
6098:
6099: if (! exists($args->{'skip_phases'}{'body'}) ) {
6100: if ($args->{'frameset'}) {
6101: my $attr_string = &make_attr_string($args->{'force_register'},
6102: $args->{'add_entries'});
6103: $result .= "\n<frameset $attr_string>\n";
6104: } else {
6105: $result .=
6106: &bodytag($title,
6107: $args->{'function'}, $args->{'add_entries'},
6108: $args->{'only_body'}, $args->{'domain'},
6109: $args->{'force_register'}, $args->{'body_title'},
6110: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6111: $args->{'no_title'}, $args->{'no_inline_link'},
6112: $args);
1.338 albertel 6113: }
1.330 albertel 6114: }
1.338 albertel 6115:
1.315 albertel 6116: if ($args->{'js_ready'}) {
1.317 albertel 6117: $result = &js_ready($result);
1.315 albertel 6118: }
1.320 albertel 6119: if ($args->{'html_encode'}) {
6120: $result = &html_encode($result);
6121: }
1.692.4.2 raeburn 6122: #Breadcrumbs
6123: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
6124: &Apache::lonhtmlcommon::clear_breadcrumbs();
6125: #if any br links exists, add them to the breadcrumbs
6126: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6127: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6128: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6129: }
6130: }
1.306 albertel 6131:
1.692.4.2 raeburn 6132: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
6133: if (exists($args->{'bread_crumbs_component'})){
6134: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
6135: } else {
6136: $result .= &Apache::lonhtmlcommon::breadcrumbs();
6137: }
6138: }
6139: return $result;
1.692.4.3 raeburn 6140: }
1.330 albertel 6141:
1.306 albertel 6142: =pod
6143:
6144: =item * &head()
6145:
6146: Returns a complete </body></html> section for LON-CAPA web pages.
6147:
1.315 albertel 6148: Inputs: $args - additional optional args supported are:
6149: js_ready -> return a string ready for being used in
6150: a javascript writeln
1.320 albertel 6151: html_encode -> return a string ready for being used in
6152: a html attribute
1.330 albertel 6153: frameset -> if true will start with a <frameset>
6154: rather than <body>
1.493 albertel 6155: dicsussion -> if true will get discussion from
6156: lonxml::xmlend
6157: (you can pass the target and parser arguments
6158: through optional 'target' and 'parser' args
6159: to this routine)
1.306 albertel 6160:
6161: =cut
6162:
6163: sub end_page {
1.315 albertel 6164: my ($args) = @_;
6165: $env{'internal.end_page'}++;
1.330 albertel 6166: my $result;
1.335 albertel 6167: if ($args->{'discussion'}) {
6168: my ($target,$parser);
6169: if (ref($args->{'discussion'})) {
6170: ($target,$parser) =($args->{'discussion'}{'target'},
6171: $args->{'discussion'}{'parser'});
6172: }
6173: $result .= &Apache::lonxml::xmlend($target,$parser);
6174: }
6175:
1.330 albertel 6176: if ($args->{'frameset'}) {
6177: $result .= '</frameset>';
6178: } else {
1.635 raeburn 6179: $result .= &endbodytag($args);
1.330 albertel 6180: }
6181: $result .= "\n</html>";
6182:
1.315 albertel 6183: if ($args->{'js_ready'}) {
1.317 albertel 6184: $result = &js_ready($result);
1.315 albertel 6185: }
1.335 albertel 6186:
1.320 albertel 6187: if ($args->{'html_encode'}) {
6188: $result = &html_encode($result);
6189: }
1.335 albertel 6190:
1.315 albertel 6191: return $result;
6192: }
6193:
1.320 albertel 6194: sub html_encode {
6195: my ($result) = @_;
6196:
1.322 albertel 6197: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6198:
6199: return $result;
6200: }
1.317 albertel 6201: sub js_ready {
6202: my ($result) = @_;
6203:
1.323 albertel 6204: $result =~ s/[\n\r]/ /xmsg;
6205: $result =~ s/\\/\\\\/xmsg;
6206: $result =~ s/'/\\'/xmsg;
1.372 albertel 6207: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6208:
6209: return $result;
6210: }
6211:
1.315 albertel 6212: sub validate_page {
6213: if ( exists($env{'internal.start_page'})
1.316 albertel 6214: && $env{'internal.start_page'} > 1) {
6215: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6216: $env{'internal.start_page'}.' '.
1.316 albertel 6217: $ENV{'request.filename'});
1.315 albertel 6218: }
6219: if ( exists($env{'internal.end_page'})
1.316 albertel 6220: && $env{'internal.end_page'} > 1) {
6221: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6222: $env{'internal.end_page'}.' '.
1.316 albertel 6223: $env{'request.filename'});
1.315 albertel 6224: }
6225: if ( exists($env{'internal.start_page'})
6226: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6227: &Apache::lonnet::logthis('start_page called without end_page '.
6228: $env{'request.filename'});
1.315 albertel 6229: }
6230: if ( ! exists($env{'internal.start_page'})
6231: && exists($env{'internal.end_page'})) {
1.316 albertel 6232: &Apache::lonnet::logthis('end_page called without start_page'.
6233: $env{'request.filename'});
1.315 albertel 6234: }
1.306 albertel 6235: }
1.315 albertel 6236:
1.318 albertel 6237: sub simple_error_page {
6238: my ($r,$title,$msg) = @_;
6239: my $page =
6240: &Apache::loncommon::start_page($title).
6241: &mt($msg).
6242: &Apache::loncommon::end_page();
6243: if (ref($r)) {
6244: $r->print($page);
1.327 albertel 6245: return;
1.318 albertel 6246: }
6247: return $page;
6248: }
1.347 albertel 6249:
6250: {
1.610 albertel 6251: my @row_count;
1.347 albertel 6252: sub start_data_table {
1.422 albertel 6253: my ($add_class) = @_;
6254: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6255: unshift(@row_count,0);
1.422 albertel 6256: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6257: }
6258:
6259: sub end_data_table {
1.610 albertel 6260: shift(@row_count);
1.389 albertel 6261: return '</table>'."\n";;
1.347 albertel 6262: }
6263:
6264: sub start_data_table_row {
1.422 albertel 6265: my ($add_class) = @_;
1.610 albertel 6266: $row_count[0]++;
6267: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6268: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6269: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6270: }
1.471 banghart 6271:
6272: sub continue_data_table_row {
6273: my ($add_class) = @_;
1.610 albertel 6274: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6275: $css_class = (join(' ',$css_class,$add_class));
6276: return '<tr class="'.$css_class.'">'."\n";;
6277: }
1.347 albertel 6278:
6279: sub end_data_table_row {
1.389 albertel 6280: return '</tr>'."\n";;
1.347 albertel 6281: }
1.367 www 6282:
1.421 albertel 6283: sub start_data_table_empty_row {
1.610 albertel 6284: $row_count[0]++;
1.421 albertel 6285: return '<tr class="LC_empty_row" >'."\n";;
6286: }
6287:
6288: sub end_data_table_empty_row {
6289: return '</tr>'."\n";;
6290: }
6291:
1.367 www 6292: sub start_data_table_header_row {
1.389 albertel 6293: return '<tr class="LC_header_row">'."\n";;
1.367 www 6294: }
6295:
6296: sub end_data_table_header_row {
1.389 albertel 6297: return '</tr>'."\n";;
1.367 www 6298: }
1.347 albertel 6299: }
6300:
1.548 albertel 6301: =pod
6302:
6303: =item * &inhibit_menu_check($arg)
6304:
6305: Checks for a inhibitmenu state and generates output to preserve it
6306:
6307: Inputs: $arg - can be any of
6308: - undef - in which case the return value is a string
6309: to add into arguments list of a uri
6310: - 'input' - in which case the return value is a HTML
6311: <form> <input> field of type hidden to
6312: preserve the value
6313: - a url - in which case the return value is the url with
6314: the neccesary cgi args added to preserve the
6315: inhibitmenu state
6316: - a ref to a url - no return value, but the string is
6317: updated to include the neccessary cgi
6318: args to preserve the inhibitmenu state
6319:
6320: =cut
6321:
6322: sub inhibit_menu_check {
6323: my ($arg) = @_;
6324: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6325: if ($arg eq 'input') {
6326: if ($env{'form.inhibitmenu'}) {
6327: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6328: } else {
6329: return
6330: }
6331: }
6332: if ($env{'form.inhibitmenu'}) {
6333: if (ref($arg)) {
6334: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6335: } elsif ($arg eq '') {
6336: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6337: } else {
6338: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6339: }
6340: }
6341: if (!ref($arg)) {
6342: return $arg;
6343: }
6344: }
6345:
1.251 albertel 6346: ###############################################
1.182 matthew 6347:
6348: =pod
6349:
1.549 albertel 6350: =back
6351:
6352: =head1 User Information Routines
6353:
6354: =over 4
6355:
1.405 albertel 6356: =item * &get_users_function()
1.182 matthew 6357:
6358: Used by &bodytag to determine the current users primary role.
6359: Returns either 'student','coordinator','admin', or 'author'.
6360:
6361: =cut
6362:
6363: ###############################################
6364: sub get_users_function {
6365: my $function = 'student';
1.258 albertel 6366: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6367: $function='coordinator';
6368: }
1.258 albertel 6369: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6370: $function='admin';
6371: }
1.692.4.5 raeburn 6372: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182 matthew 6373: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6374: $function='author';
6375: }
6376: return $function;
1.54 www 6377: }
1.99 www 6378:
6379: ###############################################
6380:
1.233 raeburn 6381: =pod
6382:
1.692.4.2 raeburn 6383: =item * &show_course()
6384:
6385: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6386: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6387: Inputs:
6388: None
6389:
6390: Outputs:
6391: Scalar: 1 if 'Course' to be used, 0 otherwise.
6392:
6393: =cut
6394:
6395: ###############################################
6396: sub show_course {
6397: my $course = !$env{'user.adv'};
6398: if (!$env{'user.adv'}) {
6399: foreach my $env (keys(%env)) {
6400: next if ($env !~ m/^user\.priv\./);
6401: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6402: $course = 0;
6403: last;
6404: }
6405: }
6406: }
6407: return $course;
6408: }
6409:
6410: ###############################################
6411:
6412: =pod
6413:
1.542 raeburn 6414: =item * &check_user_status()
1.274 raeburn 6415:
6416: Determines current status of supplied role for a
6417: specific user. Roles can be active, previous or future.
6418:
6419: Inputs:
6420: user's domain, user's username, course's domain,
1.375 raeburn 6421: course's number, optional section ID.
1.274 raeburn 6422:
6423: Outputs:
6424: role status: active, previous or future.
6425:
6426: =cut
6427:
6428: sub check_user_status {
1.412 raeburn 6429: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6430: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6431: my @uroles = keys %userinfo;
6432: my $srchstr;
6433: my $active_chk = 'none';
1.412 raeburn 6434: my $now = time;
1.274 raeburn 6435: if (@uroles > 0) {
1.412 raeburn 6436: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6437: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6438: } else {
1.412 raeburn 6439: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6440: }
6441: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6442: my $role_end = 0;
6443: my $role_start = 0;
6444: $active_chk = 'active';
1.412 raeburn 6445: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6446: $role_end = $1;
6447: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6448: $role_start = $1;
1.274 raeburn 6449: }
6450: }
6451: if ($role_start > 0) {
1.412 raeburn 6452: if ($now < $role_start) {
1.274 raeburn 6453: $active_chk = 'future';
6454: }
6455: }
6456: if ($role_end > 0) {
1.412 raeburn 6457: if ($now > $role_end) {
1.274 raeburn 6458: $active_chk = 'previous';
6459: }
6460: }
6461: }
6462: }
6463: return $active_chk;
6464: }
6465:
6466: ###############################################
6467:
6468: =pod
6469:
1.405 albertel 6470: =item * &get_sections()
1.233 raeburn 6471:
6472: Determines all the sections for a course including
6473: sections with students and sections containing other roles.
1.419 raeburn 6474: Incoming parameters:
6475:
6476: 1. domain
6477: 2. course number
6478: 3. reference to array containing roles for which sections should
6479: be gathered (optional).
6480: 4. reference to array containing status types for which sections
6481: should be gathered (optional).
6482:
6483: If the third argument is undefined, sections are gathered for any role.
6484: If the fourth argument is undefined, sections are gathered for any status.
6485: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6486:
1.374 raeburn 6487: Returns section hash (keys are section IDs, values are
6488: number of users in each section), subject to the
1.419 raeburn 6489: optional roles filter, optional status filter
1.233 raeburn 6490:
6491: =cut
6492:
6493: ###############################################
6494: sub get_sections {
1.419 raeburn 6495: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6496: if (!defined($cdom) || !defined($cnum)) {
6497: my $cid = $env{'request.course.id'};
6498:
6499: return if (!defined($cid));
6500:
6501: $cdom = $env{'course.'.$cid.'.domain'};
6502: $cnum = $env{'course.'.$cid.'.num'};
6503: }
6504:
6505: my %sectioncount;
1.419 raeburn 6506: my $now = time;
1.240 albertel 6507:
1.366 albertel 6508: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6509: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6510: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6511: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6512: my $start_index = &Apache::loncoursedata::CL_START();
6513: my $end_index = &Apache::loncoursedata::CL_END();
6514: my $status;
1.366 albertel 6515: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6516: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6517: $data->[$status_index],
6518: $data->[$start_index],
6519: $data->[$end_index]);
6520: if ($stu_status eq 'Active') {
6521: $status = 'active';
6522: } elsif ($end < $now) {
6523: $status = 'previous';
6524: } elsif ($start > $now) {
6525: $status = 'future';
6526: }
6527: if ($section ne '-1' && $section !~ /^\s*$/) {
6528: if ((!defined($possible_status)) || (($status ne '') &&
6529: (grep/^\Q$status\E$/,@{$possible_status}))) {
6530: $sectioncount{$section}++;
6531: }
1.240 albertel 6532: }
6533: }
6534: }
6535: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6536: foreach my $user (sort(keys(%courseroles))) {
6537: if ($user !~ /^(\w{2})/) { next; }
6538: my ($role) = ($user =~ /^(\w{2})/);
6539: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6540: my ($section,$status);
1.240 albertel 6541: if ($role eq 'cr' &&
6542: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6543: $section=$1;
6544: }
6545: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6546: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6547: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6548: if ($end == -1 && $start == -1) {
6549: next; #deleted role
6550: }
6551: if (!defined($possible_status)) {
6552: $sectioncount{$section}++;
6553: } else {
6554: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6555: $status = 'active';
6556: } elsif ($end < $now) {
6557: $status = 'future';
6558: } elsif ($start > $now) {
6559: $status = 'previous';
6560: }
6561: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6562: $sectioncount{$section}++;
6563: }
6564: }
1.233 raeburn 6565: }
1.366 albertel 6566: return %sectioncount;
1.233 raeburn 6567: }
6568:
1.274 raeburn 6569: ###############################################
1.294 raeburn 6570:
6571: =pod
1.405 albertel 6572:
6573: =item * &get_course_users()
6574:
1.275 raeburn 6575: Retrieves usernames:domains for users in the specified course
6576: with specific role(s), and access status.
6577:
6578: Incoming parameters:
1.277 albertel 6579: 1. course domain
6580: 2. course number
6581: 3. access status: users must have - either active,
1.275 raeburn 6582: previous, future, or all.
1.277 albertel 6583: 4. reference to array of permissible roles
1.288 raeburn 6584: 5. reference to array of section restrictions (optional)
6585: 6. reference to results object (hash of hashes).
6586: 7. reference to optional userdata hash
1.609 raeburn 6587: 8. reference to optional statushash
1.630 raeburn 6588: 9. flag if privileged users (except those set to unhide in
6589: course settings) should be excluded
1.609 raeburn 6590: Keys of top level results hash are roles.
1.275 raeburn 6591: Keys of inner hashes are username:domain, with
6592: values set to access type.
1.288 raeburn 6593: Optional userdata hash returns an array with arguments in the
6594: same order as loncoursedata::get_classlist() for student data.
6595:
1.609 raeburn 6596: Optional statushash returns
6597:
1.288 raeburn 6598: Entries for end, start, section and status are blank because
6599: of the possibility of multiple values for non-student roles.
6600:
1.275 raeburn 6601: =cut
1.405 albertel 6602:
1.275 raeburn 6603: ###############################################
1.405 albertel 6604:
1.275 raeburn 6605: sub get_course_users {
1.630 raeburn 6606: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6607: my %idx = ();
1.419 raeburn 6608: my %seclists;
1.288 raeburn 6609:
6610: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6611: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6612: $idx{end} = &Apache::loncoursedata::CL_END();
6613: $idx{start} = &Apache::loncoursedata::CL_START();
6614: $idx{id} = &Apache::loncoursedata::CL_ID();
6615: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6616: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6617: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6618:
1.290 albertel 6619: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6620: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6621: my $now = time;
1.277 albertel 6622: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6623: my $match = 0;
1.412 raeburn 6624: my $secmatch = 0;
1.419 raeburn 6625: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6626: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6627: if ($section eq '') {
6628: $section = 'none';
6629: }
1.291 albertel 6630: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6631: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6632: $secmatch = 1;
6633: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6634: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6635: $secmatch = 1;
6636: }
6637: } else {
1.419 raeburn 6638: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6639: $secmatch = 1;
6640: }
1.290 albertel 6641: }
1.412 raeburn 6642: if (!$secmatch) {
6643: next;
6644: }
1.419 raeburn 6645: }
1.275 raeburn 6646: if (defined($$types{'active'})) {
1.288 raeburn 6647: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6648: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6649: $match = 1;
1.275 raeburn 6650: }
6651: }
6652: if (defined($$types{'previous'})) {
1.609 raeburn 6653: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6654: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6655: $match = 1;
1.275 raeburn 6656: }
6657: }
6658: if (defined($$types{'future'})) {
1.609 raeburn 6659: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6660: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6661: $match = 1;
1.275 raeburn 6662: }
6663: }
1.609 raeburn 6664: if ($match) {
6665: push(@{$seclists{$student}},$section);
6666: if (ref($userdata) eq 'HASH') {
6667: $$userdata{$student} = $$classlist{$student};
6668: }
6669: if (ref($statushash) eq 'HASH') {
6670: $statushash->{$student}{'st'}{$section} = $status;
6671: }
1.288 raeburn 6672: }
1.275 raeburn 6673: }
6674: }
1.412 raeburn 6675: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6676: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6677: my $now = time;
1.609 raeburn 6678: my %displaystatus = ( previous => 'Expired',
6679: active => 'Active',
6680: future => 'Future',
6681: );
1.630 raeburn 6682: my %nothide;
6683: if ($hidepriv) {
6684: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6685: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6686: if ($user !~ /:/) {
6687: $nothide{join(':',split(/[\@]/,$user))}=1;
6688: } else {
6689: $nothide{$user} = 1;
6690: }
6691: }
6692: }
1.439 raeburn 6693: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6694: my $match = 0;
1.412 raeburn 6695: my $secmatch = 0;
1.439 raeburn 6696: my $status;
1.412 raeburn 6697: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6698: $user =~ s/:$//;
1.439 raeburn 6699: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6700: if ($end == -1 || $start == -1) {
6701: next;
6702: }
6703: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6704: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6705: my ($uname,$udom) = split(/:/,$user);
6706: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6707: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6708: $secmatch = 1;
6709: } elsif ($usec eq '') {
1.420 albertel 6710: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6711: $secmatch = 1;
6712: }
6713: } else {
6714: if (grep(/^\Q$usec\E$/,@{$sections})) {
6715: $secmatch = 1;
6716: }
6717: }
6718: if (!$secmatch) {
6719: next;
6720: }
1.288 raeburn 6721: }
1.419 raeburn 6722: if ($usec eq '') {
6723: $usec = 'none';
6724: }
1.275 raeburn 6725: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6726: if ($hidepriv) {
6727: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6728: (!$nothide{$uname.':'.$udom})) {
6729: next;
6730: }
6731: }
1.503 raeburn 6732: if ($end > 0 && $end < $now) {
1.439 raeburn 6733: $status = 'previous';
6734: } elsif ($start > $now) {
6735: $status = 'future';
6736: } else {
6737: $status = 'active';
6738: }
1.277 albertel 6739: foreach my $type (keys(%{$types})) {
1.275 raeburn 6740: if ($status eq $type) {
1.420 albertel 6741: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6742: push(@{$$users{$role}{$user}},$type);
6743: }
1.288 raeburn 6744: $match = 1;
6745: }
6746: }
1.419 raeburn 6747: if (($match) && (ref($userdata) eq 'HASH')) {
6748: if (!exists($$userdata{$uname.':'.$udom})) {
6749: &get_user_info($udom,$uname,\%idx,$userdata);
6750: }
1.420 albertel 6751: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6752: push(@{$seclists{$uname.':'.$udom}},$usec);
6753: }
1.609 raeburn 6754: if (ref($statushash) eq 'HASH') {
6755: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6756: }
1.275 raeburn 6757: }
6758: }
6759: }
6760: }
1.290 albertel 6761: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6762: if ((defined($cdom)) && (defined($cnum))) {
6763: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6764: if ( defined($csettings{'internal.courseowner'}) ) {
6765: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6766: next if ($owner eq '');
6767: my ($ownername,$ownerdom);
6768: if ($owner =~ /^([^:]+):([^:]+)$/) {
6769: $ownername = $1;
6770: $ownerdom = $2;
6771: } else {
6772: $ownername = $owner;
6773: $ownerdom = $cdom;
6774: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6775: }
6776: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6777: if (defined($userdata) &&
1.609 raeburn 6778: !exists($$userdata{$owner})) {
6779: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6780: if (!grep(/^none$/,@{$seclists{$owner}})) {
6781: push(@{$seclists{$owner}},'none');
6782: }
6783: if (ref($statushash) eq 'HASH') {
6784: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6785: }
1.290 albertel 6786: }
1.279 raeburn 6787: }
6788: }
6789: }
1.419 raeburn 6790: foreach my $user (keys(%seclists)) {
6791: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6792: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6793: }
1.275 raeburn 6794: }
6795: return;
6796: }
6797:
1.288 raeburn 6798: sub get_user_info {
6799: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6800: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6801: &plainname($uname,$udom,'lastname');
1.291 albertel 6802: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6803: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6804: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6805: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6806: return;
6807: }
1.275 raeburn 6808:
1.472 raeburn 6809: ###############################################
6810:
6811: =pod
6812:
6813: =item * &get_user_quota()
6814:
6815: Retrieves quota assigned for storage of portfolio files for a user
6816:
6817: Incoming parameters:
6818: 1. user's username
6819: 2. user's domain
6820:
6821: Returns:
1.536 raeburn 6822: 1. Disk quota (in Mb) assigned to student.
6823: 2. (Optional) Type of setting: custom or default
6824: (individually assigned or default for user's
6825: institutional status).
6826: 3. (Optional) - User's institutional status (e.g., faculty, staff
6827: or student - types as defined in localenroll::inst_usertypes
6828: for user's domain, which determines default quota for user.
6829: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6830:
6831: If a value has been stored in the user's environment,
1.536 raeburn 6832: it will return that, otherwise it returns the maximal default
6833: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6834:
6835: =cut
6836:
6837: ###############################################
6838:
6839:
6840: sub get_user_quota {
6841: my ($uname,$udom) = @_;
1.536 raeburn 6842: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6843: if (!defined($udom)) {
6844: $udom = $env{'user.domain'};
6845: }
6846: if (!defined($uname)) {
6847: $uname = $env{'user.name'};
6848: }
6849: if (($udom eq '' || $uname eq '') ||
6850: ($udom eq 'public') && ($uname eq 'public')) {
6851: $quota = 0;
1.536 raeburn 6852: $quotatype = 'default';
6853: $defquota = 0;
1.472 raeburn 6854: } else {
1.536 raeburn 6855: my $inststatus;
1.472 raeburn 6856: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6857: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6858: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6859: } else {
1.536 raeburn 6860: my %userenv =
6861: &Apache::lonnet::get('environment',['portfolioquota',
6862: 'inststatus'],$udom,$uname);
1.472 raeburn 6863: my ($tmp) = keys(%userenv);
6864: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6865: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6866: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6867: } else {
6868: undef(%userenv);
6869: }
6870: }
1.536 raeburn 6871: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6872: if ($quota eq '') {
1.536 raeburn 6873: $quota = $defquota;
6874: $quotatype = 'default';
6875: } else {
6876: $quotatype = 'custom';
1.472 raeburn 6877: }
6878: }
1.536 raeburn 6879: if (wantarray) {
6880: return ($quota,$quotatype,$settingstatus,$defquota);
6881: } else {
6882: return $quota;
6883: }
1.472 raeburn 6884: }
6885:
6886: ###############################################
6887:
6888: =pod
6889:
6890: =item * &default_quota()
6891:
1.536 raeburn 6892: Retrieves default quota assigned for storage of user portfolio files,
6893: given an (optional) user's institutional status.
1.472 raeburn 6894:
6895: Incoming parameters:
6896: 1. domain
1.536 raeburn 6897: 2. (Optional) institutional status(es). This is a : separated list of
6898: status types (e.g., faculty, staff, student etc.)
6899: which apply to the user for whom the default is being retrieved.
6900: If the institutional status string in undefined, the domain
6901: default quota will be returned.
1.472 raeburn 6902:
6903: Returns:
6904: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6905: 2. (Optional) institutional type which determined the value of the
6906: default quota.
1.472 raeburn 6907:
6908: If a value has been stored in the domain's configuration db,
6909: it will return that, otherwise it returns 20 (for backwards
6910: compatibility with domains which have not set up a configuration
6911: db file; the original statically defined portfolio quota was 20 Mb).
6912:
1.536 raeburn 6913: If the user's status includes multiple types (e.g., staff and student),
6914: the largest default quota which applies to the user determines the
6915: default quota returned.
6916:
1.692.4.15 raeburn 6917: =back
6918:
1.472 raeburn 6919: =cut
6920:
6921: ###############################################
6922:
6923:
6924: sub default_quota {
1.536 raeburn 6925: my ($udom,$inststatus) = @_;
6926: my ($defquota,$settingstatus);
6927: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6928: ['quotas'],$udom);
6929: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6930: if ($inststatus ne '') {
1.692.4.2 raeburn 6931: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 6932: foreach my $item (@statuses) {
1.692.4.2 raeburn 6933: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6934: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6935: if ($defquota eq '') {
6936: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6937: $settingstatus = $item;
6938: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6939: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6940: $settingstatus = $item;
6941: }
6942: }
6943: } else {
6944: if ($quotahash{'quotas'}{$item} ne '') {
6945: if ($defquota eq '') {
6946: $defquota = $quotahash{'quotas'}{$item};
6947: $settingstatus = $item;
6948: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6949: $defquota = $quotahash{'quotas'}{$item};
6950: $settingstatus = $item;
6951: }
1.536 raeburn 6952: }
6953: }
6954: }
6955: }
6956: if ($defquota eq '') {
1.692.4.2 raeburn 6957: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6958: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6959: } else {
6960: $defquota = $quotahash{'quotas'}{'default'};
6961: }
1.536 raeburn 6962: $settingstatus = 'default';
6963: }
6964: } else {
6965: $settingstatus = 'default';
6966: $defquota = 20;
6967: }
6968: if (wantarray) {
6969: return ($defquota,$settingstatus);
1.472 raeburn 6970: } else {
1.536 raeburn 6971: return $defquota;
1.472 raeburn 6972: }
6973: }
6974:
1.384 raeburn 6975: sub get_secgrprole_info {
6976: my ($cdom,$cnum,$needroles,$type) = @_;
6977: my %sections_count = &get_sections($cdom,$cnum);
6978: my @sections = (sort {$a <=> $b} keys(%sections_count));
6979: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6980: my @groups = sort(keys(%curr_groups));
6981: my $allroles = [];
6982: my $rolehash;
6983: my $accesshash = {
6984: active => 'Currently has access',
6985: future => 'Will have future access',
6986: previous => 'Previously had access',
6987: };
6988: if ($needroles) {
6989: $rolehash = {'all' => 'all'};
1.385 albertel 6990: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6991: if (&Apache::lonnet::error(%user_roles)) {
6992: undef(%user_roles);
6993: }
6994: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6995: my ($role)=split(/\:/,$item,2);
6996: if ($role eq 'cr') { next; }
6997: if ($role =~ /^cr/) {
6998: $$rolehash{$role} = (split('/',$role))[3];
6999: } else {
7000: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7001: }
7002: }
7003: foreach my $key (sort(keys(%{$rolehash}))) {
7004: push(@{$allroles},$key);
7005: }
7006: push (@{$allroles},'st');
7007: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7008: }
7009: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7010: }
7011:
1.555 raeburn 7012: sub user_picker {
1.627 raeburn 7013: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7014: my $currdom = $dom;
7015: my %curr_selected = (
7016: srchin => 'dom',
1.580 raeburn 7017: srchby => 'lastname',
1.555 raeburn 7018: );
7019: my $srchterm;
1.625 raeburn 7020: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7021: if ($srch->{'srchby'} ne '') {
7022: $curr_selected{'srchby'} = $srch->{'srchby'};
7023: }
7024: if ($srch->{'srchin'} ne '') {
7025: $curr_selected{'srchin'} = $srch->{'srchin'};
7026: }
7027: if ($srch->{'srchtype'} ne '') {
7028: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7029: }
7030: if ($srch->{'srchdomain'} ne '') {
7031: $currdom = $srch->{'srchdomain'};
7032: }
7033: $srchterm = $srch->{'srchterm'};
7034: }
7035: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7036: 'usr' => 'Search criteria',
1.563 raeburn 7037: 'doma' => 'Domain/institution to search',
1.558 albertel 7038: 'uname' => 'username',
7039: 'lastname' => 'last name',
1.555 raeburn 7040: 'lastfirst' => 'last name, first name',
1.558 albertel 7041: 'crs' => 'in this course',
1.576 raeburn 7042: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7043: 'alc' => 'all LON-CAPA',
1.573 raeburn 7044: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7045: 'exact' => 'is',
7046: 'contains' => 'contains',
1.569 raeburn 7047: 'begins' => 'begins with',
1.571 raeburn 7048: 'youm' => "You must include some text to search for.",
7049: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7050: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7051: 'yomc' => "You must choose a domain when using an institutional directory search.",
7052: 'ymcd' => "You must choose a domain when using a domain search.",
7053: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7054: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7055: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7056: );
1.563 raeburn 7057: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7058: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7059:
7060: my @srchins = ('crs','dom','alc','instd');
7061:
7062: foreach my $option (@srchins) {
7063: # FIXME 'alc' option unavailable until
7064: # loncreateuser::print_user_query_page()
7065: # has been completed.
7066: next if ($option eq 'alc');
1.692.4.11 raeburn 7067: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 7068: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7069: if ($curr_selected{'srchin'} eq $option) {
7070: $srchinsel .= '
7071: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7072: } else {
7073: $srchinsel .= '
7074: <option value="'.$option.'">'.$lt{$option}.'</option>';
7075: }
1.555 raeburn 7076: }
1.563 raeburn 7077: $srchinsel .= "\n </select>\n";
1.555 raeburn 7078:
7079: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7080: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7081: if ($curr_selected{'srchby'} eq $option) {
7082: $srchbysel .= '
7083: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7084: } else {
7085: $srchbysel .= '
7086: <option value="'.$option.'">'.$lt{$option}.'</option>';
7087: }
7088: }
7089: $srchbysel .= "\n </select>\n";
7090:
7091: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7092: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7093: if ($curr_selected{'srchtype'} eq $option) {
7094: $srchtypesel .= '
7095: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7096: } else {
7097: $srchtypesel .= '
7098: <option value="'.$option.'">'.$lt{$option}.'</option>';
7099: }
7100: }
7101: $srchtypesel .= "\n </select>\n";
7102:
1.558 albertel 7103: my ($newuserscript,$new_user_create);
1.556 raeburn 7104:
7105: if ($forcenewuser) {
1.576 raeburn 7106: if (ref($srch) eq 'HASH') {
7107: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7108: if ($cancreate) {
7109: $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>';
7110: } else {
1.692.4.2 raeburn 7111: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 7112: my %usertypetext = (
7113: official => 'institutional',
7114: unofficial => 'non-institutional',
7115: );
1.692.4.2 raeburn 7116: $new_user_create = '<p class="LC_warning">'.
7117: &mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.
7118: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="'.$helplink.'">','</a>').'</p><br />';
1.627 raeburn 7119: }
1.576 raeburn 7120: }
7121: }
7122:
1.556 raeburn 7123: $newuserscript = <<"ENDSCRIPT";
7124:
1.570 raeburn 7125: function setSearch(createnew,callingForm) {
1.556 raeburn 7126: if (createnew == 1) {
1.570 raeburn 7127: for (var i=0; i<callingForm.srchby.length; i++) {
7128: if (callingForm.srchby.options[i].value == 'uname') {
7129: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7130: }
7131: }
1.570 raeburn 7132: for (var i=0; i<callingForm.srchin.length; i++) {
7133: if ( callingForm.srchin.options[i].value == 'dom') {
7134: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7135: }
7136: }
1.570 raeburn 7137: for (var i=0; i<callingForm.srchtype.length; i++) {
7138: if (callingForm.srchtype.options[i].value == 'exact') {
7139: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7140: }
7141: }
1.570 raeburn 7142: for (var i=0; i<callingForm.srchdomain.length; i++) {
7143: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7144: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7145: }
7146: }
7147: }
7148: }
7149: ENDSCRIPT
1.558 albertel 7150:
1.556 raeburn 7151: }
7152:
1.555 raeburn 7153: my $output = <<"END_BLOCK";
1.556 raeburn 7154: <script type="text/javascript">
1.692.4.4 raeburn 7155: // <![CDATA[
1.570 raeburn 7156: function validateEntry(callingForm) {
1.558 albertel 7157:
1.556 raeburn 7158: var checkok = 1;
1.558 albertel 7159: var srchin;
1.570 raeburn 7160: for (var i=0; i<callingForm.srchin.length; i++) {
7161: if ( callingForm.srchin[i].checked ) {
7162: srchin = callingForm.srchin[i].value;
1.558 albertel 7163: }
7164: }
7165:
1.570 raeburn 7166: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7167: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7168: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7169: var srchterm = callingForm.srchterm.value;
7170: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7171: var msg = "";
7172:
7173: if (srchterm == "") {
7174: checkok = 0;
1.571 raeburn 7175: msg += "$lt{'youm'}\\n";
1.556 raeburn 7176: }
7177:
1.569 raeburn 7178: if (srchtype== 'begins') {
7179: if (srchterm.length < 2) {
7180: checkok = 0;
1.571 raeburn 7181: msg += "$lt{'thte'}\\n";
1.569 raeburn 7182: }
7183: }
7184:
1.556 raeburn 7185: if (srchtype== 'contains') {
7186: if (srchterm.length < 3) {
7187: checkok = 0;
1.571 raeburn 7188: msg += "$lt{'thet'}\\n";
1.556 raeburn 7189: }
7190: }
7191: if (srchin == 'instd') {
7192: if (srchdomain == '') {
7193: checkok = 0;
1.571 raeburn 7194: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7195: }
7196: }
7197: if (srchin == 'dom') {
7198: if (srchdomain == '') {
7199: checkok = 0;
1.571 raeburn 7200: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7201: }
7202: }
7203: if (srchby == 'lastfirst') {
7204: if (srchterm.indexOf(",") == -1) {
7205: checkok = 0;
1.571 raeburn 7206: msg += "$lt{'whus'}\\n";
1.556 raeburn 7207: }
7208: if (srchterm.indexOf(",") == srchterm.length -1) {
7209: checkok = 0;
1.571 raeburn 7210: msg += "$lt{'whse'}\\n";
1.556 raeburn 7211: }
7212: }
7213: if (checkok == 0) {
1.571 raeburn 7214: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7215: return;
7216: }
7217: if (checkok == 1) {
1.570 raeburn 7218: callingForm.submit();
1.556 raeburn 7219: }
7220: }
7221:
7222: $newuserscript
7223:
1.692.4.4 raeburn 7224: // ]]>
1.556 raeburn 7225: </script>
1.558 albertel 7226:
7227: $new_user_create
7228:
1.555 raeburn 7229: END_BLOCK
1.558 albertel 7230:
1.692.4.9 raeburn 7231: $output .= &Apache::lonhtmlcommon::start_pick_box().
7232: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
7233: $domform.
7234: &Apache::lonhtmlcommon::row_closure().
7235: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
7236: $srchbysel.
7237: $srchtypesel.
7238: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
7239: $srchinsel.
7240: &Apache::lonhtmlcommon::row_closure(1).
7241: &Apache::lonhtmlcommon::end_pick_box().
7242: '<br />';
1.555 raeburn 7243: return $output;
7244: }
7245:
1.612 raeburn 7246: sub user_rule_check {
1.615 raeburn 7247: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7248: my $response;
7249: if (ref($usershash) eq 'HASH') {
7250: foreach my $user (keys(%{$usershash})) {
7251: my ($uname,$udom) = split(/:/,$user);
7252: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7253: my ($id,$newuser);
1.612 raeburn 7254: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7255: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7256: $id = $usershash->{$user}->{'id'};
7257: }
7258: my $inst_response;
7259: if (ref($checks) eq 'HASH') {
7260: if (defined($checks->{'username'})) {
1.615 raeburn 7261: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7262: &Apache::lonnet::get_instuser($udom,$uname);
7263: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7264: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7265: &Apache::lonnet::get_instuser($udom,undef,$id);
7266: }
1.615 raeburn 7267: } else {
7268: ($inst_response,%{$inst_results->{$user}}) =
7269: &Apache::lonnet::get_instuser($udom,$uname);
7270: return;
1.612 raeburn 7271: }
1.615 raeburn 7272: if (!$got_rules->{$udom}) {
1.612 raeburn 7273: my %domconfig = &Apache::lonnet::get_dom('configuration',
7274: ['usercreation'],$udom);
7275: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7276: foreach my $item ('username','id') {
1.612 raeburn 7277: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7278: $$curr_rules{$udom}{$item} =
7279: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7280: }
7281: }
7282: }
1.615 raeburn 7283: $got_rules->{$udom} = 1;
1.585 raeburn 7284: }
1.612 raeburn 7285: foreach my $item (keys(%{$checks})) {
7286: if (ref($$curr_rules{$udom}) eq 'HASH') {
7287: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7288: if (@{$$curr_rules{$udom}{$item}} > 0) {
7289: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7290: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7291: if ($rule_check{$rule}) {
7292: $$rulematch{$user}{$item} = $rule;
7293: if ($inst_response eq 'ok') {
1.615 raeburn 7294: if (ref($inst_results) eq 'HASH') {
7295: if (ref($inst_results->{$user}) eq 'HASH') {
7296: if (keys(%{$inst_results->{$user}}) == 0) {
7297: $$alerts{$item}{$udom}{$uname} = 1;
7298: }
1.612 raeburn 7299: }
7300: }
1.615 raeburn 7301: }
7302: last;
1.585 raeburn 7303: }
7304: }
7305: }
7306: }
7307: }
7308: }
7309: }
7310: }
1.612 raeburn 7311: return;
7312: }
7313:
7314: sub user_rule_formats {
7315: my ($domain,$domdesc,$curr_rules,$check) = @_;
7316: my %text = (
7317: 'username' => 'Usernames',
7318: 'id' => 'IDs',
7319: );
7320: my $output;
7321: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7322: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7323: if (@{$ruleorder} > 0) {
7324: $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>';
7325: foreach my $rule (@{$ruleorder}) {
7326: if (ref($curr_rules) eq 'ARRAY') {
7327: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7328: if (ref($rules->{$rule}) eq 'HASH') {
7329: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7330: $rules->{$rule}{'desc'}.'</li>';
7331: }
7332: }
7333: }
7334: }
7335: $output .= '</ul>';
7336: }
7337: }
7338: return $output;
7339: }
7340:
7341: sub instrule_disallow_msg {
1.615 raeburn 7342: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7343: my $response;
7344: my %text = (
7345: item => 'username',
7346: items => 'usernames',
7347: match => 'matches',
7348: do => 'does',
7349: action => 'a username',
7350: one => 'one',
7351: );
7352: if ($count > 1) {
7353: $text{'item'} = 'usernames';
7354: $text{'match'} ='match';
7355: $text{'do'} = 'do';
7356: $text{'action'} = 'usernames',
7357: $text{'one'} = 'ones';
7358: }
7359: if ($checkitem eq 'id') {
7360: $text{'items'} = 'IDs';
7361: $text{'item'} = 'ID';
7362: $text{'action'} = 'an ID';
1.615 raeburn 7363: if ($count > 1) {
7364: $text{'item'} = 'IDs';
7365: $text{'action'} = 'IDs';
7366: }
1.612 raeburn 7367: }
1.674 bisitz 7368: $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 7369: if ($mode eq 'upload') {
7370: if ($checkitem eq 'username') {
7371: $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'}.");
7372: } elsif ($checkitem eq 'id') {
1.674 bisitz 7373: $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 7374: }
1.669 raeburn 7375: } elsif ($mode eq 'selfcreate') {
7376: if ($checkitem eq 'id') {
7377: $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.");
7378: }
1.615 raeburn 7379: } else {
7380: if ($checkitem eq 'username') {
7381: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7382: } elsif ($checkitem eq 'id') {
7383: $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.");
7384: }
1.612 raeburn 7385: }
7386: return $response;
1.585 raeburn 7387: }
7388:
1.624 raeburn 7389: sub personal_data_fieldtitles {
7390: my %fieldtitles = &Apache::lonlocal::texthash (
7391: id => 'Student/Employee ID',
7392: permanentemail => 'E-mail address',
7393: lastname => 'Last Name',
7394: firstname => 'First Name',
7395: middlename => 'Middle Name',
7396: generation => 'Generation',
7397: gen => 'Generation',
1.692.4.2 raeburn 7398: inststatus => 'Affiliation',
1.624 raeburn 7399: );
7400: return %fieldtitles;
7401: }
7402:
1.642 raeburn 7403: sub sorted_inst_types {
7404: my ($dom) = @_;
7405: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7406: my $othertitle = &mt('All users');
7407: if ($env{'request.course.id'}) {
1.668 raeburn 7408: $othertitle = &mt('Any users');
1.642 raeburn 7409: }
7410: my @types;
7411: if (ref($order) eq 'ARRAY') {
7412: @types = @{$order};
7413: }
7414: if (@types == 0) {
7415: if (ref($usertypes) eq 'HASH') {
7416: @types = sort(keys(%{$usertypes}));
7417: }
7418: }
7419: if (keys(%{$usertypes}) > 0) {
7420: $othertitle = &mt('Other users');
7421: }
7422: return ($othertitle,$usertypes,\@types);
7423: }
7424:
1.645 raeburn 7425: sub get_institutional_codes {
7426: my ($settings,$allcourses,$LC_code) = @_;
7427: # Get complete list of course sections to update
7428: my @currsections = ();
7429: my @currxlists = ();
7430: my $coursecode = $$settings{'internal.coursecode'};
7431:
7432: if ($$settings{'internal.sectionnums'} ne '') {
7433: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7434: }
7435:
7436: if ($$settings{'internal.crosslistings'} ne '') {
7437: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7438: }
7439:
7440: if (@currxlists > 0) {
7441: foreach (@currxlists) {
7442: if (m/^([^:]+):(\w*)$/) {
7443: unless (grep/^$1$/,@{$allcourses}) {
7444: push @{$allcourses},$1;
7445: $$LC_code{$1} = $2;
7446: }
7447: }
7448: }
7449: }
7450:
7451: if (@currsections > 0) {
7452: foreach (@currsections) {
7453: if (m/^(\w+):(\w*)$/) {
7454: my $sec = $coursecode.$1;
7455: my $lc_sec = $2;
7456: unless (grep/^$sec$/,@{$allcourses}) {
7457: push @{$allcourses},$sec;
7458: $$LC_code{$sec} = $lc_sec;
7459: }
7460: }
7461: }
7462: }
7463: return;
7464: }
7465:
1.112 bowersj2 7466: =pod
7467:
1.692.4.2 raeburn 7468: =head1 Slot Helpers
7469:
7470: =over 4
7471:
7472: =item * sorted_slots()
7473:
7474: Sorts an array of slot names in order of slot start time (earliest first).
7475:
7476: Inputs:
7477:
7478: =over 4
7479:
7480: slotsarr - Reference to array of unsorted slot names.
7481:
7482: slots - Reference to hash of hash, where outer hash keys are slot names.
7483:
7484: =back
7485:
7486: Returns:
7487:
7488: =over 4
7489:
7490: sorted - An array of slot names sorted by the start time of the slot.
7491:
7492: =back
7493:
7494: =back
7495:
7496: =cut
7497:
7498:
7499: sub sorted_slots {
7500: my ($slotsarr,$slots) = @_;
7501: my @sorted;
7502: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7503: @sorted =
7504: sort {
7505: if (ref($slots->{$a}) && ref($slots->{$b})) {
7506: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7507: }
7508: if (ref($slots->{$a})) { return -1;}
7509: if (ref($slots->{$b})) { return 1;}
7510: return 0;
7511: } @{$slotsarr};
7512: }
7513: return @sorted;
7514: }
7515:
7516: =pod
7517:
1.549 albertel 7518: =head1 HTTP Helpers
7519:
7520: =over 4
7521:
1.648 raeburn 7522: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7523:
1.258 albertel 7524: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7525: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7526: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7527:
7528: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7529: $possible_names is an ref to an array of form element names. As an example:
7530: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7531: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7532:
7533: =cut
1.1 albertel 7534:
1.6 albertel 7535: sub get_unprocessed_cgi {
1.25 albertel 7536: my ($query,$possible_names)= @_;
1.26 matthew 7537: # $Apache::lonxml::debug=1;
1.356 albertel 7538: foreach my $pair (split(/&/,$query)) {
7539: my ($name, $value) = split(/=/,$pair);
1.369 www 7540: $name = &unescape($name);
1.25 albertel 7541: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7542: $value =~ tr/+/ /;
7543: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7544: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7545: }
1.16 harris41 7546: }
1.6 albertel 7547: }
7548:
1.112 bowersj2 7549: =pod
7550:
1.648 raeburn 7551: =item * &cacheheader()
1.112 bowersj2 7552:
7553: returns cache-controlling header code
7554:
7555: =cut
7556:
1.7 albertel 7557: sub cacheheader {
1.258 albertel 7558: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7559: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7560: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7561: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7562: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7563: return $output;
1.7 albertel 7564: }
7565:
1.112 bowersj2 7566: =pod
7567:
1.648 raeburn 7568: =item * &no_cache($r)
1.112 bowersj2 7569:
7570: specifies header code to not have cache
7571:
7572: =cut
7573:
1.9 albertel 7574: sub no_cache {
1.216 albertel 7575: my ($r) = @_;
7576: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7577: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7578: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7579: $r->no_cache(1);
7580: $r->header_out("Expires" => $date);
7581: $r->header_out("Pragma" => "no-cache");
1.123 www 7582: }
7583:
7584: sub content_type {
1.181 albertel 7585: my ($r,$type,$charset) = @_;
1.299 foxr 7586: if ($r) {
7587: # Note that printout.pl calls this with undef for $r.
7588: &no_cache($r);
7589: }
1.258 albertel 7590: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7591: unless ($charset) {
7592: $charset=&Apache::lonlocal::current_encoding;
7593: }
7594: if ($charset) { $type.='; charset='.$charset; }
7595: if ($r) {
7596: $r->content_type($type);
7597: } else {
7598: print("Content-type: $type\n\n");
7599: }
1.9 albertel 7600: }
1.25 albertel 7601:
1.112 bowersj2 7602: =pod
7603:
1.648 raeburn 7604: =item * &add_to_env($name,$value)
1.112 bowersj2 7605:
1.258 albertel 7606: adds $name to the %env hash with value
1.112 bowersj2 7607: $value, if $name already exists, the entry is converted to an array
7608: reference and $value is added to the array.
7609:
7610: =cut
7611:
1.25 albertel 7612: sub add_to_env {
7613: my ($name,$value)=@_;
1.258 albertel 7614: if (defined($env{$name})) {
7615: if (ref($env{$name})) {
1.25 albertel 7616: #already have multiple values
1.258 albertel 7617: push(@{ $env{$name} },$value);
1.25 albertel 7618: } else {
7619: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7620: my $first=$env{$name};
7621: undef($env{$name});
7622: push(@{ $env{$name} },$first,$value);
1.25 albertel 7623: }
7624: } else {
1.258 albertel 7625: $env{$name}=$value;
1.25 albertel 7626: }
1.31 albertel 7627: }
1.149 albertel 7628:
7629: =pod
7630:
1.648 raeburn 7631: =item * &get_env_multiple($name)
1.149 albertel 7632:
1.258 albertel 7633: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7634: values may be defined and end up as an array ref.
7635:
7636: returns an array of values
7637:
7638: =cut
7639:
7640: sub get_env_multiple {
7641: my ($name) = @_;
7642: my @values;
1.258 albertel 7643: if (defined($env{$name})) {
1.149 albertel 7644: # exists is it an array
1.258 albertel 7645: if (ref($env{$name})) {
7646: @values=@{ $env{$name} };
1.149 albertel 7647: } else {
1.258 albertel 7648: $values[0]=$env{$name};
1.149 albertel 7649: }
7650: }
7651: return(@values);
7652: }
7653:
1.660 raeburn 7654: sub ask_for_embedded_content {
7655: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7656: my $upload_output = '
7657: <form name="upload_embedded" action="'.$actionurl.'"
7658: method="post" enctype="multipart/form-data">';
7659: $upload_output .= $state;
1.661 raeburn 7660: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7661:
7662: my $num = 0;
7663: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7664: $upload_output .= &start_data_table_row().
7665: '<td>'.$embed_file.'</td><td>';
7666: if ($args->{'ignore_remote_references'}
7667: && $embed_file =~ m{^\w+://}) {
7668: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7669: } elsif ($args->{'error_on_invalid_names'}
7670: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7671:
7672: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7673:
7674: } else {
7675: $upload_output .='
1.661 raeburn 7676: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7677: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7678: my $attrib = join(':',@{$$allfiles{$embed_file}});
7679: $upload_output .=
7680: "\n\t\t".
7681: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7682: $attrib.'" />';
7683: if (exists($$codebase{$embed_file})) {
7684: $upload_output .=
7685: "\n\t\t".
7686: '<input name="codebase_'.$num.'" type="hidden" value="'.
7687: &escape($$codebase{$embed_file}).'" />';
7688: }
7689: }
7690: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7691: $num++;
7692: }
7693: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7694: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7695: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7696: '.&mt('(only files for which a location has been provided will be uploaded)').'
7697: </form>';
7698: return $upload_output;
7699: }
7700:
1.661 raeburn 7701: sub upload_embedded {
7702: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7703: $current_disk_usage) = @_;
7704: my $output;
7705: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7706: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7707: my $orig_uploaded_filename =
7708: $env{'form.embedded_item_'.$i.'.filename'};
7709:
7710: $env{'form.embedded_orig_'.$i} =
7711: &unescape($env{'form.embedded_orig_'.$i});
7712: my ($path,$fname) =
7713: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7714: # no path, whole string is fname
7715: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7716:
7717: $path = $env{'form.currentpath'}.$path;
7718: $fname = &Apache::lonnet::clean_filename($fname);
7719: # See if there is anything left
7720: next if ($fname eq '');
7721:
7722: # Check if file already exists as a file or directory.
7723: my ($state,$msg);
7724: if ($context eq 'portfolio') {
7725: my $port_path = $dirpath;
7726: if ($group ne '') {
7727: $port_path = "groups/$group/$port_path";
7728: }
7729: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7730: $dir_root,$port_path,$disk_quota,
7731: $current_disk_usage,$uname,$udom);
7732: if ($state eq 'will_exceed_quota'
7733: || $state eq 'file_locked'
7734: || $state eq 'file_exists' ) {
7735: $output .= $msg;
7736: next;
7737: }
7738: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7739: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7740: if ($state eq 'exists') {
7741: $output .= $msg;
7742: next;
7743: }
7744: }
7745: # Check if extension is valid
7746: if (($fname =~ /\.(\w+)$/) &&
7747: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7748: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7749: next;
7750: } elsif (($fname =~ /\.(\w+)$/) &&
7751: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7752: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7753: next;
7754: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7755: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7756: next;
7757: }
7758:
7759: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7760: if ($context eq 'portfolio') {
7761: my $result=
7762: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7763: $dirpath.$path);
7764: if ($result !~ m|^/uploaded/|) {
7765: $output .= '<span class="LC_error">'
7766: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7767: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7768: .'</span><br />';
7769: next;
7770: } else {
7771: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7772: $path.$fname.'</span>').'</p>';
7773: }
7774: } else {
7775: # Save the file
7776: my $target = $env{'form.embedded_item_'.$i};
7777: my $fullpath = $dir_root.$dirpath.'/'.$path;
7778: my $dest = $fullpath.$fname;
7779: my $url = $url_root.$dirpath.'/'.$path.$fname;
7780: my @parts=split(/\//,$fullpath);
7781: my $count;
7782: my $filepath = $dir_root;
7783: for ($count=4;$count<=$#parts;$count++) {
7784: $filepath .= "/$parts[$count]";
7785: if ((-e $filepath)!=1) {
7786: mkdir($filepath,0770);
7787: }
7788: }
7789: my $fh;
7790: if (!open($fh,'>'.$dest)) {
7791: &Apache::lonnet::logthis('Failed to create '.$dest);
7792: $output .= '<span class="LC_error">'.
7793: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7794: '</span><br />';
7795: } else {
7796: if (!print $fh $env{'form.embedded_item_'.$i}) {
7797: &Apache::lonnet::logthis('Failed to write to '.$dest);
7798: $output .= '<span class="LC_error">'.
7799: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7800: '</span><br />';
7801: } else {
7802: if ($context eq 'testbank') {
7803: $output .= &mt('Embedded file uploaded successfully:').
7804: ' <a href="'.$url.'">'.
7805: $orig_uploaded_filename.'</a><br />';
7806: } else {
7807: $output .= '<font size="+2">'.
7808: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7809: $orig_uploaded_filename.'</a>').'</font><br />';
7810: }
7811: }
7812: close($fh);
7813: }
7814: }
7815: }
7816: return $output;
7817: }
7818:
7819: sub check_for_existing {
7820: my ($path,$fname,$element) = @_;
7821: my ($state,$msg);
7822: if (-d $path.'/'.$fname) {
7823: $state = 'exists';
7824: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7825: } elsif (-e $path.'/'.$fname) {
7826: $state = 'exists';
7827: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7828: }
7829: if ($state eq 'exists') {
7830: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7831: }
7832: return ($state,$msg);
7833: }
7834:
7835: sub check_for_upload {
7836: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7837: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7838: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7839: my $getpropath = 1;
7840: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7841: $getpropath);
7842: my $found_file = 0;
7843: my $locked_file = 0;
7844: foreach my $line (@dir_list) {
7845: my ($file_name)=split(/\&/,$line,2);
7846: if ($file_name eq $fname){
7847: $file_name = $path.$file_name;
7848: if ($group ne '') {
7849: $file_name = $group.$file_name;
7850: }
7851: $found_file = 1;
7852: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7853: $locked_file = 1;
7854: }
7855: }
7856: }
7857: if (($current_disk_usage + $filesize) > $disk_quota){
7858: my $msg = '<span class="LC_error">'.
7859: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7860: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7861: return ('will_exceed_quota',$msg);
7862: } elsif ($found_file) {
7863: if ($locked_file) {
7864: my $msg = '<span class="LC_error">';
7865: $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>');
7866: $msg .= '</span><br />';
7867: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7868: return ('file_locked',$msg);
7869: } else {
7870: my $msg = '<span class="LC_error">';
7871: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
7872: $msg .= '</span>';
7873: $msg .= '<br />';
7874: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7875: return ('file_exists',$msg);
7876: }
7877: }
7878: }
7879:
1.31 albertel 7880:
1.41 ng 7881: =pod
1.45 matthew 7882:
1.464 albertel 7883: =back
1.41 ng 7884:
1.112 bowersj2 7885: =head1 CSV Upload/Handling functions
1.38 albertel 7886:
1.41 ng 7887: =over 4
7888:
1.648 raeburn 7889: =item * &upfile_store($r)
1.41 ng 7890:
7891: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7892: needs $env{'form.upfile'}
1.41 ng 7893: returns $datatoken to be put into hidden field
7894:
7895: =cut
1.31 albertel 7896:
7897: sub upfile_store {
7898: my $r=shift;
1.258 albertel 7899: $env{'form.upfile'}=~s/\r/\n/gs;
7900: $env{'form.upfile'}=~s/\f/\n/gs;
7901: $env{'form.upfile'}=~s/\n+/\n/gs;
7902: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7903:
1.258 albertel 7904: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7905: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7906: {
1.158 raeburn 7907: my $datafile = $r->dir_config('lonDaemons').
7908: '/tmp/'.$datatoken.'.tmp';
7909: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7910: print $fh $env{'form.upfile'};
1.158 raeburn 7911: close($fh);
7912: }
1.31 albertel 7913: }
7914: return $datatoken;
7915: }
7916:
1.56 matthew 7917: =pod
7918:
1.648 raeburn 7919: =item * &load_tmp_file($r)
1.41 ng 7920:
7921: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7922: needs $env{'form.datatoken'},
7923: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7924:
7925: =cut
1.31 albertel 7926:
7927: sub load_tmp_file {
7928: my $r=shift;
7929: my @studentdata=();
7930: {
1.158 raeburn 7931: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7932: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7933: if ( open(my $fh,"<$studentfile") ) {
7934: @studentdata=<$fh>;
7935: close($fh);
7936: }
1.31 albertel 7937: }
1.258 albertel 7938: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7939: }
7940:
1.56 matthew 7941: =pod
7942:
1.648 raeburn 7943: =item * &upfile_record_sep()
1.41 ng 7944:
7945: Separate uploaded file into records
7946: returns array of records,
1.258 albertel 7947: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7948:
7949: =cut
1.31 albertel 7950:
7951: sub upfile_record_sep {
1.258 albertel 7952: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7953: } else {
1.248 albertel 7954: my @records;
1.258 albertel 7955: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7956: if ($line=~/^\s*$/) { next; }
7957: push(@records,$line);
7958: }
7959: return @records;
1.31 albertel 7960: }
7961: }
7962:
1.56 matthew 7963: =pod
7964:
1.648 raeburn 7965: =item * &record_sep($record)
1.41 ng 7966:
1.258 albertel 7967: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7968:
7969: =cut
7970:
1.263 www 7971: sub takeleft {
7972: my $index=shift;
7973: return substr('0000'.$index,-4,4);
7974: }
7975:
1.31 albertel 7976: sub record_sep {
7977: my $record=shift;
7978: my %components=();
1.258 albertel 7979: if ($env{'form.upfiletype'} eq 'xml') {
7980: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7981: my $i=0;
1.356 albertel 7982: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7983: $field=~s/^(\"|\')//;
7984: $field=~s/(\"|\')$//;
1.263 www 7985: $components{&takeleft($i)}=$field;
1.31 albertel 7986: $i++;
7987: }
1.258 albertel 7988: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7989: my $i=0;
1.356 albertel 7990: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7991: $field=~s/^(\"|\')//;
7992: $field=~s/(\"|\')$//;
1.263 www 7993: $components{&takeleft($i)}=$field;
1.31 albertel 7994: $i++;
7995: }
7996: } else {
1.561 www 7997: my $separator=',';
1.480 banghart 7998: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7999: $separator=';';
1.480 banghart 8000: }
1.31 albertel 8001: my $i=0;
1.561 www 8002: # the character we are looking for to indicate the end of a quote or a record
8003: my $looking_for=$separator;
8004: # do not add the characters to the fields
8005: my $ignore=0;
8006: # we just encountered a separator (or the beginning of the record)
8007: my $just_found_separator=1;
8008: # store the field we are working on here
8009: my $field='';
8010: # work our way through all characters in record
8011: foreach my $character ($record=~/(.)/g) {
8012: if ($character eq $looking_for) {
8013: if ($character ne $separator) {
8014: # Found the end of a quote, again looking for separator
8015: $looking_for=$separator;
8016: $ignore=1;
8017: } else {
8018: # Found a separator, store away what we got
8019: $components{&takeleft($i)}=$field;
8020: $i++;
8021: $just_found_separator=1;
8022: $ignore=0;
8023: $field='';
8024: }
8025: next;
8026: }
8027: # single or double quotation marks after a separator indicate beginning of a quote
8028: # we are now looking for the end of the quote and need to ignore separators
8029: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8030: $looking_for=$character;
8031: next;
8032: }
8033: # ignore would be true after we reached the end of a quote
8034: if ($ignore) { next; }
8035: if (($just_found_separator) && ($character=~/\s/)) { next; }
8036: $field.=$character;
8037: $just_found_separator=0;
1.31 albertel 8038: }
1.561 www 8039: # catch the very last entry, since we never encountered the separator
8040: $components{&takeleft($i)}=$field;
1.31 albertel 8041: }
8042: return %components;
8043: }
8044:
1.144 matthew 8045: ######################################################
8046: ######################################################
8047:
1.56 matthew 8048: =pod
8049:
1.648 raeburn 8050: =item * &upfile_select_html()
1.41 ng 8051:
1.144 matthew 8052: Return HTML code to select a file from the users machine and specify
8053: the file type.
1.41 ng 8054:
8055: =cut
8056:
1.144 matthew 8057: ######################################################
8058: ######################################################
1.31 albertel 8059: sub upfile_select_html {
1.144 matthew 8060: my %Types = (
8061: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8062: semisv => &mt('Semicolon separated values'),
1.144 matthew 8063: space => &mt('Space separated'),
8064: tab => &mt('Tabulator separated'),
8065: # xml => &mt('HTML/XML'),
8066: );
8067: my $Str = '<input type="file" name="upfile" size="50" />'.
1.692.4.2 raeburn 8068: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8069: foreach my $type (sort(keys(%Types))) {
8070: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8071: }
8072: $Str .= "</select>\n";
8073: return $Str;
1.31 albertel 8074: }
8075:
1.301 albertel 8076: sub get_samples {
8077: my ($records,$toget) = @_;
8078: my @samples=({});
8079: my $got=0;
8080: foreach my $rec (@$records) {
8081: my %temp = &record_sep($rec);
8082: if (! grep(/\S/, values(%temp))) { next; }
8083: if (%temp) {
8084: $samples[$got]=\%temp;
8085: $got++;
8086: if ($got == $toget) { last; }
8087: }
8088: }
8089: return \@samples;
8090: }
8091:
1.144 matthew 8092: ######################################################
8093: ######################################################
8094:
1.56 matthew 8095: =pod
8096:
1.648 raeburn 8097: =item * &csv_print_samples($r,$records)
1.41 ng 8098:
8099: Prints a table of sample values from each column uploaded $r is an
8100: Apache Request ref, $records is an arrayref from
8101: &Apache::loncommon::upfile_record_sep
8102:
8103: =cut
8104:
1.144 matthew 8105: ######################################################
8106: ######################################################
1.31 albertel 8107: sub csv_print_samples {
8108: my ($r,$records) = @_;
1.662 bisitz 8109: my $samples = &get_samples($records,5);
1.301 albertel 8110:
1.594 raeburn 8111: $r->print(&mt('Samples').'<br />'.&start_data_table().
8112: &start_data_table_header_row());
1.356 albertel 8113: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.692.4.6 raeburn 8114: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>');
8115: }
1.594 raeburn 8116: $r->print(&end_data_table_header_row());
1.301 albertel 8117: foreach my $hash (@$samples) {
1.594 raeburn 8118: $r->print(&start_data_table_row());
1.356 albertel 8119: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8120: $r->print('<td>');
1.356 albertel 8121: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8122: $r->print('</td>');
8123: }
1.594 raeburn 8124: $r->print(&end_data_table_row());
1.31 albertel 8125: }
1.594 raeburn 8126: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8127: }
8128:
1.144 matthew 8129: ######################################################
8130: ######################################################
8131:
1.56 matthew 8132: =pod
8133:
1.648 raeburn 8134: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8135:
8136: Prints a table to create associations between values and table columns.
1.144 matthew 8137:
1.41 ng 8138: $r is an Apache Request ref,
8139: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8140: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8141:
8142: =cut
8143:
1.144 matthew 8144: ######################################################
8145: ######################################################
1.31 albertel 8146: sub csv_print_select_table {
8147: my ($r,$records,$d) = @_;
1.301 albertel 8148: my $i=0;
8149: my $samples = &get_samples($records,1);
1.144 matthew 8150: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8151: &start_data_table().&start_data_table_header_row().
1.144 matthew 8152: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8153: '<th>'.&mt('Column').'</th>'.
8154: &end_data_table_header_row()."\n");
1.356 albertel 8155: foreach my $array_ref (@$d) {
8156: my ($value,$display,$defaultcol)=@{ $array_ref };
1.689 bisitz 8157: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8158:
1.692.4.8 raeburn 8159: $r->print('<td><select name"f'.$i.'"'.
1.32 matthew 8160: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8161: $r->print('<option value="none"></option>');
1.356 albertel 8162: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8163: $r->print('<option value="'.$sample.'"'.
8164: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8165: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8166: }
1.594 raeburn 8167: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8168: $i++;
8169: }
1.594 raeburn 8170: $r->print(&end_data_table());
1.31 albertel 8171: $i--;
8172: return $i;
8173: }
1.56 matthew 8174:
1.144 matthew 8175: ######################################################
8176: ######################################################
8177:
1.56 matthew 8178: =pod
1.31 albertel 8179:
1.648 raeburn 8180: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8181:
8182: Prints a table of sample values from the upload and can make associate samples to internal names.
8183:
8184: $r is an Apache Request ref,
8185: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8186: $d is an array of 2 element arrays (internal name, displayed name)
8187:
8188: =cut
8189:
1.144 matthew 8190: ######################################################
8191: ######################################################
1.31 albertel 8192: sub csv_samples_select_table {
8193: my ($r,$records,$d) = @_;
8194: my $i=0;
1.144 matthew 8195: #
1.662 bisitz 8196: my $max_samples = 5;
8197: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8198: $r->print(&start_data_table().
8199: &start_data_table_header_row().'<th>'.
8200: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8201: &end_data_table_header_row());
1.301 albertel 8202:
8203: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8204: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8205: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8206: foreach my $option (@$d) {
8207: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8208: $r->print('<option value="'.$value.'"'.
1.253 albertel 8209: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8210: $display.'</option>');
1.31 albertel 8211: }
8212: $r->print('</select></td><td>');
1.662 bisitz 8213: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8214: if (defined($samples->[$line]{$key})) {
8215: $r->print($samples->[$line]{$key}."<br />\n");
8216: }
8217: }
1.594 raeburn 8218: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8219: $i++;
8220: }
1.594 raeburn 8221: $r->print(&end_data_table());
1.31 albertel 8222: $i--;
8223: return($i);
1.115 matthew 8224: }
8225:
1.144 matthew 8226: ######################################################
8227: ######################################################
8228:
1.115 matthew 8229: =pod
8230:
1.648 raeburn 8231: =item * &clean_excel_name($name)
1.115 matthew 8232:
8233: Returns a replacement for $name which does not contain any illegal characters.
8234:
8235: =cut
8236:
1.144 matthew 8237: ######################################################
8238: ######################################################
1.115 matthew 8239: sub clean_excel_name {
8240: my ($name) = @_;
8241: $name =~ s/[:\*\?\/\\]//g;
8242: if (length($name) > 31) {
8243: $name = substr($name,0,31);
8244: }
8245: return $name;
1.25 albertel 8246: }
1.84 albertel 8247:
1.85 albertel 8248: =pod
8249:
1.648 raeburn 8250: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8251:
8252: Returns either 1 or undef
8253:
8254: 1 if the part is to be hidden, undef if it is to be shown
8255:
8256: Arguments are:
8257:
8258: $id the id of the part to be checked
8259: $symb, optional the symb of the resource to check
8260: $udom, optional the domain of the user to check for
8261: $uname, optional the username of the user to check for
8262:
8263: =cut
1.84 albertel 8264:
8265: sub check_if_partid_hidden {
8266: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8267: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8268: $symb,$udom,$uname);
1.141 albertel 8269: my $truth=1;
8270: #if the string starts with !, then the list is the list to show not hide
8271: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8272: my @hiddenlist=split(/,/,$hiddenparts);
8273: foreach my $checkid (@hiddenlist) {
1.141 albertel 8274: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8275: }
1.141 albertel 8276: return !$truth;
1.84 albertel 8277: }
1.127 matthew 8278:
1.138 matthew 8279:
8280: ############################################################
8281: ############################################################
8282:
8283: =pod
8284:
1.157 matthew 8285: =back
8286:
1.138 matthew 8287: =head1 cgi-bin script and graphing routines
8288:
1.157 matthew 8289: =over 4
8290:
1.648 raeburn 8291: =item * &get_cgi_id()
1.138 matthew 8292:
8293: Inputs: none
8294:
8295: Returns an id which can be used to pass environment variables
8296: to various cgi-bin scripts. These environment variables will
8297: be removed from the users environment after a given time by
8298: the routine &Apache::lonnet::transfer_profile_to_env.
8299:
8300: =cut
8301:
8302: ############################################################
8303: ############################################################
1.152 albertel 8304: my $uniq=0;
1.136 matthew 8305: sub get_cgi_id {
1.154 albertel 8306: $uniq=($uniq+1)%100000;
1.280 albertel 8307: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8308: }
8309:
1.127 matthew 8310: ############################################################
8311: ############################################################
8312:
8313: =pod
8314:
1.648 raeburn 8315: =item * &DrawBarGraph()
1.127 matthew 8316:
1.138 matthew 8317: Facilitates the plotting of data in a (stacked) bar graph.
8318: Puts plot definition data into the users environment in order for
8319: graph.png to plot it. Returns an <img> tag for the plot.
8320: The bars on the plot are labeled '1','2',...,'n'.
8321:
8322: Inputs:
8323:
8324: =over 4
8325:
8326: =item $Title: string, the title of the plot
8327:
8328: =item $xlabel: string, text describing the X-axis of the plot
8329:
8330: =item $ylabel: string, text describing the Y-axis of the plot
8331:
8332: =item $Max: scalar, the maximum Y value to use in the plot
8333: If $Max is < any data point, the graph will not be rendered.
8334:
1.140 matthew 8335: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8336: they are plotted. If undefined, default values will be used.
8337:
1.178 matthew 8338: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8339:
1.138 matthew 8340: =item @Values: An array of array references. Each array reference holds data
8341: to be plotted in a stacked bar chart.
8342:
1.239 matthew 8343: =item If the final element of @Values is a hash reference the key/value
8344: pairs will be added to the graph definition.
8345:
1.138 matthew 8346: =back
8347:
8348: Returns:
8349:
8350: An <img> tag which references graph.png and the appropriate identifying
8351: information for the plot.
8352:
1.127 matthew 8353: =cut
8354:
8355: ############################################################
8356: ############################################################
1.134 matthew 8357: sub DrawBarGraph {
1.178 matthew 8358: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8359: #
8360: if (! defined($colors)) {
8361: $colors = ['#33ff00',
8362: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8363: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8364: ];
8365: }
1.228 matthew 8366: my $extra_settings = {};
8367: if (ref($Values[-1]) eq 'HASH') {
8368: $extra_settings = pop(@Values);
8369: }
1.127 matthew 8370: #
1.136 matthew 8371: my $identifier = &get_cgi_id();
8372: my $id = 'cgi.'.$identifier;
1.129 matthew 8373: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8374: return '';
8375: }
1.225 matthew 8376: #
8377: my @Labels;
8378: if (defined($labels)) {
8379: @Labels = @$labels;
8380: } else {
8381: for (my $i=0;$i<@{$Values[0]};$i++) {
8382: push (@Labels,$i+1);
8383: }
8384: }
8385: #
1.129 matthew 8386: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8387: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8388: my %ValuesHash;
8389: my $NumSets=1;
8390: foreach my $array (@Values) {
8391: next if (! ref($array));
1.136 matthew 8392: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8393: join(',',@$array);
1.129 matthew 8394: }
1.127 matthew 8395: #
1.136 matthew 8396: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8397: if ($NumBars < 3) {
8398: $width = 120+$NumBars*32;
1.220 matthew 8399: $xskip = 1;
1.225 matthew 8400: $bar_width = 30;
8401: } elsif ($NumBars < 5) {
8402: $width = 120+$NumBars*20;
8403: $xskip = 1;
8404: $bar_width = 20;
1.220 matthew 8405: } elsif ($NumBars < 10) {
1.136 matthew 8406: $width = 120+$NumBars*15;
8407: $xskip = 1;
8408: $bar_width = 15;
8409: } elsif ($NumBars <= 25) {
8410: $width = 120+$NumBars*11;
8411: $xskip = 5;
8412: $bar_width = 8;
8413: } elsif ($NumBars <= 50) {
8414: $width = 120+$NumBars*8;
8415: $xskip = 5;
8416: $bar_width = 4;
8417: } else {
8418: $width = 120+$NumBars*8;
8419: $xskip = 5;
8420: $bar_width = 4;
8421: }
8422: #
1.137 matthew 8423: $Max = 1 if ($Max < 1);
8424: if ( int($Max) < $Max ) {
8425: $Max++;
8426: $Max = int($Max);
8427: }
1.127 matthew 8428: $Title = '' if (! defined($Title));
8429: $xlabel = '' if (! defined($xlabel));
8430: $ylabel = '' if (! defined($ylabel));
1.369 www 8431: $ValuesHash{$id.'.title'} = &escape($Title);
8432: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8433: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8434: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8435: $ValuesHash{$id.'.NumBars'} = $NumBars;
8436: $ValuesHash{$id.'.NumSets'} = $NumSets;
8437: $ValuesHash{$id.'.PlotType'} = 'bar';
8438: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8439: $ValuesHash{$id.'.height'} = $height;
8440: $ValuesHash{$id.'.width'} = $width;
8441: $ValuesHash{$id.'.xskip'} = $xskip;
8442: $ValuesHash{$id.'.bar_width'} = $bar_width;
8443: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8444: #
1.228 matthew 8445: # Deal with other parameters
8446: while (my ($key,$value) = each(%$extra_settings)) {
8447: $ValuesHash{$id.'.'.$key} = $value;
8448: }
8449: #
1.646 raeburn 8450: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8451: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8452: }
8453:
8454: ############################################################
8455: ############################################################
8456:
8457: =pod
8458:
1.648 raeburn 8459: =item * &DrawXYGraph()
1.137 matthew 8460:
1.138 matthew 8461: Facilitates the plotting of data in an XY graph.
8462: Puts plot definition data into the users environment in order for
8463: graph.png to plot it. Returns an <img> tag for the plot.
8464:
8465: Inputs:
8466:
8467: =over 4
8468:
8469: =item $Title: string, the title of the plot
8470:
8471: =item $xlabel: string, text describing the X-axis of the plot
8472:
8473: =item $ylabel: string, text describing the Y-axis of the plot
8474:
8475: =item $Max: scalar, the maximum Y value to use in the plot
8476: If $Max is < any data point, the graph will not be rendered.
8477:
8478: =item $colors: Array ref containing the hex color codes for the data to be
8479: plotted in. If undefined, default values will be used.
8480:
8481: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8482:
8483: =item $Ydata: Array ref containing Array refs.
1.185 www 8484: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8485:
8486: =item %Values: hash indicating or overriding any default values which are
8487: passed to graph.png.
8488: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8489:
8490: =back
8491:
8492: Returns:
8493:
8494: An <img> tag which references graph.png and the appropriate identifying
8495: information for the plot.
8496:
1.137 matthew 8497: =cut
8498:
8499: ############################################################
8500: ############################################################
8501: sub DrawXYGraph {
8502: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8503: #
8504: # Create the identifier for the graph
8505: my $identifier = &get_cgi_id();
8506: my $id = 'cgi.'.$identifier;
8507: #
8508: $Title = '' if (! defined($Title));
8509: $xlabel = '' if (! defined($xlabel));
8510: $ylabel = '' if (! defined($ylabel));
8511: my %ValuesHash =
8512: (
1.369 www 8513: $id.'.title' => &escape($Title),
8514: $id.'.xlabel' => &escape($xlabel),
8515: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8516: $id.'.y_max_value'=> $Max,
8517: $id.'.labels' => join(',',@$Xlabels),
8518: $id.'.PlotType' => 'XY',
8519: );
8520: #
8521: if (defined($colors) && ref($colors) eq 'ARRAY') {
8522: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8523: }
8524: #
8525: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8526: return '';
8527: }
8528: my $NumSets=1;
1.138 matthew 8529: foreach my $array (@{$Ydata}){
1.137 matthew 8530: next if (! ref($array));
8531: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8532: }
1.138 matthew 8533: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8534: #
8535: # Deal with other parameters
8536: while (my ($key,$value) = each(%Values)) {
8537: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8538: }
8539: #
1.646 raeburn 8540: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8541: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8542: }
8543:
8544: ############################################################
8545: ############################################################
8546:
8547: =pod
8548:
1.648 raeburn 8549: =item * &DrawXYYGraph()
1.138 matthew 8550:
8551: Facilitates the plotting of data in an XY graph with two Y axes.
8552: Puts plot definition data into the users environment in order for
8553: graph.png to plot it. Returns an <img> tag for the plot.
8554:
8555: Inputs:
8556:
8557: =over 4
8558:
8559: =item $Title: string, the title of the plot
8560:
8561: =item $xlabel: string, text describing the X-axis of the plot
8562:
8563: =item $ylabel: string, text describing the Y-axis of the plot
8564:
8565: =item $colors: Array ref containing the hex color codes for the data to be
8566: plotted in. If undefined, default values will be used.
8567:
8568: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8569:
8570: =item $Ydata1: The first data set
8571:
8572: =item $Min1: The minimum value of the left Y-axis
8573:
8574: =item $Max1: The maximum value of the left Y-axis
8575:
8576: =item $Ydata2: The second data set
8577:
8578: =item $Min2: The minimum value of the right Y-axis
8579:
8580: =item $Max2: The maximum value of the left Y-axis
8581:
8582: =item %Values: hash indicating or overriding any default values which are
8583: passed to graph.png.
8584: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8585:
8586: =back
8587:
8588: Returns:
8589:
8590: An <img> tag which references graph.png and the appropriate identifying
8591: information for the plot.
1.136 matthew 8592:
8593: =cut
8594:
8595: ############################################################
8596: ############################################################
1.137 matthew 8597: sub DrawXYYGraph {
8598: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8599: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8600: #
8601: # Create the identifier for the graph
8602: my $identifier = &get_cgi_id();
8603: my $id = 'cgi.'.$identifier;
8604: #
8605: $Title = '' if (! defined($Title));
8606: $xlabel = '' if (! defined($xlabel));
8607: $ylabel = '' if (! defined($ylabel));
8608: my %ValuesHash =
8609: (
1.369 www 8610: $id.'.title' => &escape($Title),
8611: $id.'.xlabel' => &escape($xlabel),
8612: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8613: $id.'.labels' => join(',',@$Xlabels),
8614: $id.'.PlotType' => 'XY',
8615: $id.'.NumSets' => 2,
1.137 matthew 8616: $id.'.two_axes' => 1,
8617: $id.'.y1_max_value' => $Max1,
8618: $id.'.y1_min_value' => $Min1,
8619: $id.'.y2_max_value' => $Max2,
8620: $id.'.y2_min_value' => $Min2,
1.136 matthew 8621: );
8622: #
1.137 matthew 8623: if (defined($colors) && ref($colors) eq 'ARRAY') {
8624: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8625: }
8626: #
8627: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8628: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8629: return '';
8630: }
8631: my $NumSets=1;
1.137 matthew 8632: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8633: next if (! ref($array));
8634: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8635: }
8636: #
8637: # Deal with other parameters
8638: while (my ($key,$value) = each(%Values)) {
8639: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8640: }
8641: #
1.646 raeburn 8642: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8643: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8644: }
8645:
8646: ############################################################
8647: ############################################################
8648:
8649: =pod
8650:
1.157 matthew 8651: =back
8652:
1.139 matthew 8653: =head1 Statistics helper routines?
8654:
8655: Bad place for them but what the hell.
8656:
1.157 matthew 8657: =over 4
8658:
1.648 raeburn 8659: =item * &chartlink()
1.139 matthew 8660:
8661: Returns a link to the chart for a specific student.
8662:
8663: Inputs:
8664:
8665: =over 4
8666:
8667: =item $linktext: The text of the link
8668:
8669: =item $sname: The students username
8670:
8671: =item $sdomain: The students domain
8672:
8673: =back
8674:
1.157 matthew 8675: =back
8676:
1.139 matthew 8677: =cut
8678:
8679: ############################################################
8680: ############################################################
8681: sub chartlink {
8682: my ($linktext, $sname, $sdomain) = @_;
8683: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8684: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8685: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8686: '">'.$linktext.'</a>';
1.153 matthew 8687: }
8688:
8689: #######################################################
8690: #######################################################
8691:
8692: =pod
8693:
8694: =head1 Course Environment Routines
1.157 matthew 8695:
8696: =over 4
1.153 matthew 8697:
1.648 raeburn 8698: =item * &restore_course_settings()
1.153 matthew 8699:
1.648 raeburn 8700: =item * &store_course_settings()
1.153 matthew 8701:
8702: Restores/Store indicated form parameters from the course environment.
8703: Will not overwrite existing values of the form parameters.
8704:
8705: Inputs:
8706: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8707:
8708: a hash ref describing the data to be stored. For example:
8709:
8710: %Save_Parameters = ('Status' => 'scalar',
8711: 'chartoutputmode' => 'scalar',
8712: 'chartoutputdata' => 'scalar',
8713: 'Section' => 'array',
1.373 raeburn 8714: 'Group' => 'array',
1.153 matthew 8715: 'StudentData' => 'array',
8716: 'Maps' => 'array');
8717:
8718: Returns: both routines return nothing
8719:
1.631 raeburn 8720: =back
8721:
1.153 matthew 8722: =cut
8723:
8724: #######################################################
8725: #######################################################
8726: sub store_course_settings {
1.496 albertel 8727: return &store_settings($env{'request.course.id'},@_);
8728: }
8729:
8730: sub store_settings {
1.153 matthew 8731: # save to the environment
8732: # appenv the same items, just to be safe
1.300 albertel 8733: my $udom = $env{'user.domain'};
8734: my $uname = $env{'user.name'};
1.496 albertel 8735: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8736: my %SaveHash;
8737: my %AppHash;
8738: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8739: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8740: my $envname = 'environment.'.$basename;
1.258 albertel 8741: if (exists($env{'form.'.$setting})) {
1.153 matthew 8742: # Save this value away
8743: if ($type eq 'scalar' &&
1.258 albertel 8744: (! exists($env{$envname}) ||
8745: $env{$envname} ne $env{'form.'.$setting})) {
8746: $SaveHash{$basename} = $env{'form.'.$setting};
8747: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8748: } elsif ($type eq 'array') {
8749: my $stored_form;
1.258 albertel 8750: if (ref($env{'form.'.$setting})) {
1.153 matthew 8751: $stored_form = join(',',
8752: map {
1.369 www 8753: &escape($_);
1.258 albertel 8754: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8755: } else {
8756: $stored_form =
1.369 www 8757: &escape($env{'form.'.$setting});
1.153 matthew 8758: }
8759: # Determine if the array contents are the same.
1.258 albertel 8760: if ($stored_form ne $env{$envname}) {
1.153 matthew 8761: $SaveHash{$basename} = $stored_form;
8762: $AppHash{$envname} = $stored_form;
8763: }
8764: }
8765: }
8766: }
8767: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8768: $udom,$uname);
1.153 matthew 8769: if ($put_result !~ /^(ok|delayed)/) {
8770: &Apache::lonnet::logthis('unable to save form parameters, '.
8771: 'got error:'.$put_result);
8772: }
8773: # Make sure these settings stick around in this session, too
1.646 raeburn 8774: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8775: return;
8776: }
8777:
8778: sub restore_course_settings {
1.499 albertel 8779: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8780: }
8781:
8782: sub restore_settings {
8783: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8784: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8785: next if (exists($env{'form.'.$setting}));
1.496 albertel 8786: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8787: '.'.$setting;
1.258 albertel 8788: if (exists($env{$envname})) {
1.153 matthew 8789: if ($type eq 'scalar') {
1.258 albertel 8790: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8791: } elsif ($type eq 'array') {
1.258 albertel 8792: $env{'form.'.$setting} = [
1.153 matthew 8793: map {
1.369 www 8794: &unescape($_);
1.258 albertel 8795: } split(',',$env{$envname})
1.153 matthew 8796: ];
8797: }
8798: }
8799: }
1.127 matthew 8800: }
8801:
1.618 raeburn 8802: #######################################################
8803: #######################################################
8804:
8805: =pod
8806:
8807: =head1 Domain E-mail Routines
8808:
8809: =over 4
8810:
1.648 raeburn 8811: =item * &build_recipient_list()
1.618 raeburn 8812:
1.692.4.14 raeburn 8813: Build recipient lists for five types of e-mail:
1.692.4.2 raeburn 8814: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.692.4.14 raeburn 8815: (d) Help requests, (e) Course requests needing approval, generated by
8816: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
8817: loncoursequeueadmin.pm respectively.
1.618 raeburn 8818:
8819: Inputs:
1.619 raeburn 8820: defmail (scalar - email address of default recipient),
1.618 raeburn 8821: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8822: defdom (domain for which to retrieve configuration settings),
8823: origmail (scalar - email address of recipient from loncapa.conf,
8824: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8825:
1.655 raeburn 8826: Returns: comma separated list of addresses to which to send e-mail.
8827:
8828: =back
1.618 raeburn 8829:
8830: =cut
8831:
8832: ############################################################
8833: ############################################################
8834: sub build_recipient_list {
1.619 raeburn 8835: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8836: my @recipients;
8837: my $otheremails;
8838: my %domconfig =
8839: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8840: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.692.4.2 raeburn 8841: if (exists($domconfig{'contacts'}{$mailing})) {
8842: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8843: my @contacts = ('adminemail','supportemail');
8844: foreach my $item (@contacts) {
8845: if ($domconfig{'contacts'}{$mailing}{$item}) {
8846: my $addr = $domconfig{'contacts'}{$item};
8847: if (!grep(/^\Q$addr\E$/,@recipients)) {
8848: push(@recipients,$addr);
8849: }
1.619 raeburn 8850: }
1.692.4.2 raeburn 8851: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 8852: }
8853: }
1.692.4.2 raeburn 8854: } elsif ($origmail ne '') {
8855: push(@recipients,$origmail);
1.618 raeburn 8856: }
1.619 raeburn 8857: } elsif ($origmail ne '') {
8858: push(@recipients,$origmail);
1.618 raeburn 8859: }
1.688 raeburn 8860: if (defined($defmail)) {
8861: if ($defmail ne '') {
8862: push(@recipients,$defmail);
8863: }
1.618 raeburn 8864: }
8865: if ($otheremails) {
1.619 raeburn 8866: my @others;
8867: if ($otheremails =~ /,/) {
8868: @others = split(/,/,$otheremails);
1.618 raeburn 8869: } else {
1.619 raeburn 8870: push(@others,$otheremails);
8871: }
8872: foreach my $addr (@others) {
8873: if (!grep(/^\Q$addr\E$/,@recipients)) {
8874: push(@recipients,$addr);
8875: }
1.618 raeburn 8876: }
8877: }
1.619 raeburn 8878: my $recipientlist = join(',',@recipients);
1.618 raeburn 8879: return $recipientlist;
8880: }
8881:
1.127 matthew 8882: ############################################################
8883: ############################################################
1.154 albertel 8884:
1.655 raeburn 8885: =pod
8886:
8887: =head1 Course Catalog Routines
8888:
8889: =over 4
8890:
8891: =item * &gather_categories()
8892:
8893: Converts category definitions - keys of categories hash stored in
8894: coursecategories in configuration.db on the primary library server in a
8895: domain - to an array. Also generates javascript and idx hash used to
8896: generate Domain Coordinator interface for editing Course Categories.
8897:
8898: Inputs:
1.663 raeburn 8899:
1.655 raeburn 8900: categories (reference to hash of category definitions).
1.663 raeburn 8901:
1.655 raeburn 8902: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8903: categories and subcategories).
1.663 raeburn 8904:
1.655 raeburn 8905: idx (reference to hash of counters used in Domain Coordinator interface for
8906: editing Course Categories).
1.663 raeburn 8907:
1.655 raeburn 8908: jsarray (reference to array of categories used to create Javascript arrays for
8909: Domain Coordinator interface for editing Course Categories).
8910:
8911: Returns: nothing
8912:
8913: Side effects: populates cats, idx and jsarray.
8914:
8915: =cut
8916:
8917: sub gather_categories {
8918: my ($categories,$cats,$idx,$jsarray) = @_;
8919: my %counters;
8920: my $num = 0;
8921: foreach my $item (keys(%{$categories})) {
8922: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8923: if ($container eq '' && $depth == 0) {
8924: $cats->[$depth][$categories->{$item}] = $cat;
8925: } else {
8926: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8927: }
8928: my ($escitem,$tail) = split(/:/,$item,2);
8929: if ($counters{$tail} eq '') {
8930: $counters{$tail} = $num;
8931: $num ++;
8932: }
8933: if (ref($idx) eq 'HASH') {
8934: $idx->{$item} = $counters{$tail};
8935: }
8936: if (ref($jsarray) eq 'ARRAY') {
8937: push(@{$jsarray->[$counters{$tail}]},$item);
8938: }
8939: }
8940: return;
8941: }
8942:
8943: =pod
8944:
8945: =item * &extract_categories()
8946:
8947: Used to generate breadcrumb trails for course categories.
8948:
8949: Inputs:
1.663 raeburn 8950:
1.655 raeburn 8951: categories (reference to hash of category definitions).
1.663 raeburn 8952:
1.655 raeburn 8953: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8954: categories and subcategories).
1.663 raeburn 8955:
1.655 raeburn 8956: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8957:
1.655 raeburn 8958: allitems (reference to hash - key is category key
8959: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8960:
1.655 raeburn 8961: idx (reference to hash of counters used in Domain Coordinator interface for
8962: editing Course Categories).
1.663 raeburn 8963:
1.655 raeburn 8964: jsarray (reference to array of categories used to create Javascript arrays for
8965: Domain Coordinator interface for editing Course Categories).
8966:
1.665 raeburn 8967: subcats (reference to hash of arrays containing all subcategories within each
8968: category, -recursive)
8969:
1.655 raeburn 8970: Returns: nothing
8971:
8972: Side effects: populates trails and allitems hash references.
8973:
8974: =cut
8975:
8976: sub extract_categories {
1.665 raeburn 8977: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8978: if (ref($categories) eq 'HASH') {
8979: &gather_categories($categories,$cats,$idx,$jsarray);
8980: if (ref($cats->[0]) eq 'ARRAY') {
8981: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8982: my $name = $cats->[0][$i];
8983: my $item = &escape($name).'::0';
8984: my $trailstr;
8985: if ($name eq 'instcode') {
8986: $trailstr = &mt('Official courses (with institutional codes)');
8987: } else {
8988: $trailstr = $name;
8989: }
8990: if ($allitems->{$item} eq '') {
8991: push(@{$trails},$trailstr);
8992: $allitems->{$item} = scalar(@{$trails})-1;
8993: }
8994: my @parents = ($name);
8995: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8996: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8997: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8998: if (ref($subcats) eq 'HASH') {
8999: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9000: }
9001: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9002: }
9003: } else {
9004: if (ref($subcats) eq 'HASH') {
9005: $subcats->{$item} = [];
1.655 raeburn 9006: }
9007: }
9008: }
9009: }
9010: }
9011: return;
9012: }
9013:
9014: =pod
9015:
9016: =item *&recurse_categories()
9017:
9018: Recursively used to generate breadcrumb trails for course categories.
9019:
9020: Inputs:
1.663 raeburn 9021:
1.655 raeburn 9022: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9023: categories and subcategories).
1.663 raeburn 9024:
1.655 raeburn 9025: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9026:
9027: category (current course category, for which breadcrumb trail is being generated).
9028:
9029: trails (reference to array of breadcrumb trails for each category).
9030:
1.655 raeburn 9031: allitems (reference to hash - key is category key
9032: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9033:
1.655 raeburn 9034: parents (array containing containers directories for current category,
9035: back to top level).
9036:
9037: Returns: nothing
9038:
9039: Side effects: populates trails and allitems hash references
9040:
9041: =cut
9042:
9043: sub recurse_categories {
1.665 raeburn 9044: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9045: my $shallower = $depth - 1;
9046: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9047: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9048: my $name = $cats->[$depth]{$category}[$k];
9049: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9050: my $trailstr = join(' -> ',(@{$parents},$category));
9051: if ($allitems->{$item} eq '') {
9052: push(@{$trails},$trailstr);
9053: $allitems->{$item} = scalar(@{$trails})-1;
9054: }
9055: my $deeper = $depth+1;
9056: push(@{$parents},$category);
1.665 raeburn 9057: if (ref($subcats) eq 'HASH') {
9058: my $subcat = &escape($name).':'.$category.':'.$depth;
9059: for (my $j=@{$parents}; $j>=0; $j--) {
9060: my $higher;
9061: if ($j > 0) {
9062: $higher = &escape($parents->[$j]).':'.
9063: &escape($parents->[$j-1]).':'.$j;
9064: } else {
9065: $higher = &escape($parents->[$j]).'::'.$j;
9066: }
9067: push(@{$subcats->{$higher}},$subcat);
9068: }
9069: }
9070: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9071: $subcats);
1.655 raeburn 9072: pop(@{$parents});
9073: }
9074: } else {
9075: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9076: my $trailstr = join(' -> ',(@{$parents},$category));
9077: if ($allitems->{$item} eq '') {
9078: push(@{$trails},$trailstr);
9079: $allitems->{$item} = scalar(@{$trails})-1;
9080: }
9081: }
9082: return;
9083: }
9084:
1.663 raeburn 9085: =pod
9086:
9087: =item *&assign_categories_table()
9088:
9089: Create a datatable for display of hierarchical categories in a domain,
9090: with checkboxes to allow a course to be categorized.
9091:
9092: Inputs:
9093:
9094: cathash - reference to hash of categories defined for the domain (from
9095: configuration.db)
9096:
9097: currcat - scalar with an & separated list of categories assigned to a course.
9098:
9099: Returns: $output (markup to be displayed)
9100:
9101: =cut
9102:
9103: sub assign_categories_table {
9104: my ($cathash,$currcat) = @_;
9105: my $output;
9106: if (ref($cathash) eq 'HASH') {
9107: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9108: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9109: $maxdepth = scalar(@cats);
9110: if (@cats > 0) {
9111: my $itemcount = 0;
9112: if (ref($cats[0]) eq 'ARRAY') {
9113: $output = &Apache::loncommon::start_data_table();
9114: my @currcategories;
9115: if ($currcat ne '') {
9116: @currcategories = split('&',$currcat);
9117: }
9118: for (my $i=0; $i<@{$cats[0]}; $i++) {
9119: my $parent = $cats[0][$i];
9120: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9121: next if ($parent eq 'instcode');
9122: my $item = &escape($parent).'::0';
9123: my $checked = '';
9124: if (@currcategories > 0) {
9125: if (grep(/^\Q$item\E$/,@currcategories)) {
9126: $checked = ' checked="checked" ';
9127: }
9128: }
1.675 raeburn 9129: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9130: '<input type="checkbox" name="usecategory" value="'.
9131: $item.'"'.$checked.' />'.$parent.'</span>'.
9132: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9133: my $depth = 1;
9134: push(@path,$parent);
9135: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9136: pop(@path);
9137: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9138: $itemcount ++;
9139: }
9140: $output .= &Apache::loncommon::end_data_table();
9141: }
9142: }
9143: }
9144: return $output;
9145: }
9146:
9147: =pod
9148:
9149: =item *&assign_category_rows()
9150:
9151: Create a datatable row for display of nested categories in a domain,
9152: with checkboxes to allow a course to be categorized,called recursively.
9153:
9154: Inputs:
9155:
9156: itemcount - track row number for alternating colors
9157:
9158: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9159: categories and subcategories.
9160:
9161: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9162:
9163: parent - parent of current category item
9164:
9165: path - Array containing all categories back up through the hierarchy from the
9166: current category to the top level.
9167:
9168: currcategories - reference to array of current categories assigned to the course
9169:
9170: Returns: $output (markup to be displayed).
9171:
9172: =cut
9173:
9174: sub assign_category_rows {
9175: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9176: my ($text,$name,$item,$chgstr);
9177: if (ref($cats) eq 'ARRAY') {
9178: my $maxdepth = scalar(@{$cats});
9179: if (ref($cats->[$depth]) eq 'HASH') {
9180: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9181: my $numchildren = @{$cats->[$depth]{$parent}};
9182: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9183: $text .= '<td><table class="LC_datatable">';
9184: for (my $j=0; $j<$numchildren; $j++) {
9185: $name = $cats->[$depth]{$parent}[$j];
9186: $item = &escape($name).':'.&escape($parent).':'.$depth;
9187: my $deeper = $depth+1;
9188: my $checked = '';
9189: if (ref($currcategories) eq 'ARRAY') {
9190: if (@{$currcategories} > 0) {
9191: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9192: $checked = ' checked="checked" ';
9193: }
9194: }
9195: }
1.664 raeburn 9196: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9197: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9198: $item.'"'.$checked.' />'.$name.'</label></span>'.
9199: '<input type="hidden" name="catname" value="'.$name.'" />'.
9200: '</td><td>';
1.663 raeburn 9201: if (ref($path) eq 'ARRAY') {
9202: push(@{$path},$name);
9203: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9204: pop(@{$path});
9205: }
9206: $text .= '</td></tr>';
9207: }
9208: $text .= '</table></td>';
9209: }
9210: }
9211: }
9212: return $text;
9213: }
9214:
1.655 raeburn 9215: ############################################################
9216: ############################################################
9217:
9218:
1.443 albertel 9219: sub commit_customrole {
1.664 raeburn 9220: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9221: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9222: ($start?', '.&mt('starting').' '.localtime($start):'').
9223: ($end?', ending '.localtime($end):'').': <b>'.
9224: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9225: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9226: '</b><br />';
9227: return $output;
9228: }
9229:
9230: sub commit_standardrole {
1.541 raeburn 9231: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9232: my ($output,$logmsg,$linefeed);
9233: if ($context eq 'auto') {
9234: $linefeed = "\n";
9235: } else {
9236: $linefeed = "<br />\n";
9237: }
1.443 albertel 9238: if ($three eq 'st') {
1.541 raeburn 9239: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9240: $one,$two,$sec,$context);
9241: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9242: ($result eq 'unknown_course') || ($result eq 'refused')) {
9243: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9244: } else {
1.541 raeburn 9245: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9246: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9247: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9248: if ($context eq 'auto') {
9249: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9250: } else {
9251: $output .= '<b>'.$result.'</b>'.$linefeed.
9252: &mt('Add to classlist').': <b>ok</b>';
9253: }
9254: $output .= $linefeed;
1.443 albertel 9255: }
9256: } else {
9257: $output = &mt('Assigning').' '.$three.' in '.$url.
9258: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9259: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9260: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9261: if ($context eq 'auto') {
9262: $output .= $result.$linefeed;
9263: } else {
9264: $output .= '<b>'.$result.'</b>'.$linefeed;
9265: }
1.443 albertel 9266: }
9267: return $output;
9268: }
9269:
9270: sub commit_studentrole {
1.541 raeburn 9271: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9272: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9273: if ($context eq 'auto') {
9274: $linefeed = "\n";
9275: } else {
9276: $linefeed = '<br />'."\n";
9277: }
1.443 albertel 9278: if (defined($one) && defined($two)) {
9279: my $cid=$one.'_'.$two;
9280: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9281: my $secchange = 0;
9282: my $expire_role_result;
9283: my $modify_section_result;
1.628 raeburn 9284: if ($oldsec ne '-1') {
9285: if ($oldsec ne $sec) {
1.443 albertel 9286: $secchange = 1;
1.628 raeburn 9287: my $now = time;
1.443 albertel 9288: my $uurl='/'.$cid;
9289: $uurl=~s/\_/\//g;
9290: if ($oldsec) {
9291: $uurl.='/'.$oldsec;
9292: }
1.626 raeburn 9293: $oldsecurl = $uurl;
1.628 raeburn 9294: $expire_role_result =
1.652 raeburn 9295: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9296: if ($env{'request.course.sec'} ne '') {
9297: if ($expire_role_result eq 'refused') {
9298: my @roles = ('st');
9299: my @statuses = ('previous');
9300: my @roledoms = ($one);
9301: my $withsec = 1;
9302: my %roleshash =
9303: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9304: \@statuses,\@roles,\@roledoms,$withsec);
9305: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9306: my ($oldstart,$oldend) =
9307: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9308: if ($oldend > 0 && $oldend <= $now) {
9309: $expire_role_result = 'ok';
9310: }
9311: }
9312: }
9313: }
1.443 albertel 9314: $result = $expire_role_result;
9315: }
9316: }
9317: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9318: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9319: if ($modify_section_result =~ /^ok/) {
9320: if ($secchange == 1) {
1.628 raeburn 9321: if ($sec eq '') {
9322: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9323: } else {
9324: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9325: }
1.443 albertel 9326: } elsif ($oldsec eq '-1') {
1.628 raeburn 9327: if ($sec eq '') {
9328: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9329: } else {
9330: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9331: }
1.443 albertel 9332: } else {
1.628 raeburn 9333: if ($sec eq '') {
9334: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9335: } else {
9336: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9337: }
1.443 albertel 9338: }
9339: } else {
1.628 raeburn 9340: if ($secchange) {
9341: $$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;
9342: } else {
9343: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9344: }
1.443 albertel 9345: }
9346: $result = $modify_section_result;
9347: } elsif ($secchange == 1) {
1.628 raeburn 9348: if ($oldsec eq '') {
9349: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9350: } else {
9351: $$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;
9352: }
1.626 raeburn 9353: if ($expire_role_result eq 'refused') {
9354: my $newsecurl = '/'.$cid;
9355: $newsecurl =~ s/\_/\//g;
9356: if ($sec ne '') {
9357: $newsecurl.='/'.$sec;
9358: }
9359: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9360: if ($sec eq '') {
9361: $$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;
9362: } else {
9363: $$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;
9364: }
9365: }
9366: }
1.443 albertel 9367: }
9368: } else {
1.626 raeburn 9369: $$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 9370: $result = "error: incomplete course id\n";
9371: }
9372: return $result;
9373: }
9374:
9375: ############################################################
9376: ############################################################
9377:
1.566 albertel 9378: sub check_clone {
1.578 raeburn 9379: my ($args,$linefeed) = @_;
1.566 albertel 9380: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9381: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9382: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9383: my $clonemsg;
9384: my $can_clone = 0;
9385:
9386: if ($clonehome eq 'no_host') {
1.578 raeburn 9387: $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'});
1.566 albertel 9388: } else {
9389: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.692.4.12 raeburn 9390: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
9391: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
9392: $can_clone = 1;
1.566 albertel 9393: } else {
9394: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9395: $args->{'clonedomain'},$args->{'clonecourse'});
9396: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9397: if (grep(/^\*$/,@cloners)) {
9398: $can_clone = 1;
9399: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9400: $can_clone = 1;
9401: } else {
9402: my %roleshash =
9403: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9404: $args->{'ccdomain'},
9405: 'userroles',['active'],['cc'],
9406: [$args->{'clonedomain'}]);
9407: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9408: $can_clone = 1;
9409: } else {
9410: $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'});
9411: }
1.566 albertel 9412: }
1.578 raeburn 9413: }
1.566 albertel 9414: }
9415: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9416: }
9417:
1.444 albertel 9418: sub construct_course {
1.692.4.14 raeburn 9419: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 9420: my $outcome;
1.541 raeburn 9421: my $linefeed = '<br />'."\n";
9422: if ($context eq 'auto') {
9423: $linefeed = "\n";
9424: }
1.566 albertel 9425:
9426: #
9427: # Are we cloning?
9428: #
9429: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9430: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9431: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9432: if ($context ne 'auto') {
1.578 raeburn 9433: if ($clonemsg ne '') {
9434: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9435: }
1.566 albertel 9436: }
9437: $outcome .= $clonemsg.$linefeed;
9438:
9439: if (!$can_clone) {
9440: return (0,$outcome);
9441: }
9442: }
9443:
1.444 albertel 9444: #
9445: # Open course
9446: #
9447: my $crstype = lc($args->{'crstype'});
9448: my %cenv=();
9449: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9450: $args->{'cdescr'},
9451: $args->{'curl'},
9452: $args->{'course_home'},
9453: $args->{'nonstandard'},
9454: $args->{'crscode'},
9455: $args->{'ccuname'}.':'.
9456: $args->{'ccdomain'},
1.692.4.12 raeburn 9457: $args->{'crstype'},
1.692.4.14 raeburn 9458: $cnum,$context,$category);
1.692.4.12 raeburn 9459:
1.444 albertel 9460:
9461: # Note: The testing routines depend on this being output; see
9462: # Utils::Course. This needs to at least be output as a comment
9463: # if anyone ever decides to not show this, and Utils::Course::new
9464: # will need to be suitably modified.
1.541 raeburn 9465: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9466: #
9467: # Check if created correctly
9468: #
1.479 albertel 9469: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9470: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9471: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9472:
1.444 albertel 9473: #
1.566 albertel 9474: # Do the cloning
9475: #
9476: if ($can_clone && $cloneid) {
9477: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9478: if ($context ne 'auto') {
9479: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9480: }
9481: $outcome .= $clonemsg.$linefeed;
9482: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9483: # Copy all files
1.637 www 9484: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9485: # Restore URL
1.566 albertel 9486: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9487: # Restore title
1.566 albertel 9488: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9489: # Mark as cloned
1.566 albertel 9490: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9491: # Need to clone grading mode
9492: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9493: $cenv{'grading'}=$newenv{'grading'};
9494: # Do not clone these environment entries
9495: &Apache::lonnet::del('environment',
9496: ['default_enrollment_start_date',
9497: 'default_enrollment_end_date',
9498: 'question.email',
9499: 'policy.email',
9500: 'comment.email',
9501: 'pch.users.denied',
1.692.4.2 raeburn 9502: 'plc.users.denied',
9503: 'hidefromcat',
9504: 'categories'],
1.638 www 9505: $$crsudom,$$crsunum);
1.444 albertel 9506: }
1.566 albertel 9507:
1.444 albertel 9508: #
9509: # Set environment (will override cloned, if existing)
9510: #
9511: my @sections = ();
9512: my @xlists = ();
9513: if ($args->{'crstype'}) {
9514: $cenv{'type'}=$args->{'crstype'};
9515: }
9516: if ($args->{'crsid'}) {
9517: $cenv{'courseid'}=$args->{'crsid'};
9518: }
9519: if ($args->{'crscode'}) {
9520: $cenv{'internal.coursecode'}=$args->{'crscode'};
9521: }
9522: if ($args->{'crsquota'} ne '') {
9523: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9524: } else {
9525: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9526: }
9527: if ($args->{'ccuname'}) {
9528: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9529: ':'.$args->{'ccdomain'};
9530: } else {
9531: $cenv{'internal.courseowner'} = $args->{'curruser'};
9532: }
9533: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9534: if ($args->{'crssections'}) {
9535: $cenv{'internal.sectionnums'} = '';
9536: if ($args->{'crssections'} =~ m/,/) {
9537: @sections = split/,/,$args->{'crssections'};
9538: } else {
9539: $sections[0] = $args->{'crssections'};
9540: }
9541: if (@sections > 0) {
9542: foreach my $item (@sections) {
9543: my ($sec,$gp) = split/:/,$item;
9544: my $class = $args->{'crscode'}.$sec;
9545: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9546: $cenv{'internal.sectionnums'} .= $item.',';
9547: unless ($addcheck eq 'ok') {
9548: push @badclasses, $class;
9549: }
9550: }
9551: $cenv{'internal.sectionnums'} =~ s/,$//;
9552: }
9553: }
9554: # do not hide course coordinator from staff listing,
9555: # even if privileged
9556: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9557: # add crosslistings
9558: if ($args->{'crsxlist'}) {
9559: $cenv{'internal.crosslistings'}='';
9560: if ($args->{'crsxlist'} =~ m/,/) {
9561: @xlists = split/,/,$args->{'crsxlist'};
9562: } else {
9563: $xlists[0] = $args->{'crsxlist'};
9564: }
9565: if (@xlists > 0) {
9566: foreach my $item (@xlists) {
9567: my ($xl,$gp) = split/:/,$item;
9568: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9569: $cenv{'internal.crosslistings'} .= $item.',';
9570: unless ($addcheck eq 'ok') {
9571: push @badclasses, $xl;
9572: }
9573: }
9574: $cenv{'internal.crosslistings'} =~ s/,$//;
9575: }
9576: }
9577: if ($args->{'autoadds'}) {
9578: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9579: }
9580: if ($args->{'autodrops'}) {
9581: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9582: }
9583: # check for notification of enrollment changes
9584: my @notified = ();
9585: if ($args->{'notify_owner'}) {
9586: if ($args->{'ccuname'} ne '') {
9587: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9588: }
9589: }
9590: if ($args->{'notify_dc'}) {
9591: if ($uname ne '') {
1.630 raeburn 9592: push(@notified,$uname.':'.$udom);
1.444 albertel 9593: }
9594: }
9595: if (@notified > 0) {
9596: my $notifylist;
9597: if (@notified > 1) {
9598: $notifylist = join(',',@notified);
9599: } else {
9600: $notifylist = $notified[0];
9601: }
9602: $cenv{'internal.notifylist'} = $notifylist;
9603: }
9604: if (@badclasses > 0) {
9605: my %lt=&Apache::lonlocal::texthash(
9606: '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',
9607: 'dnhr' => 'does not have rights to access enrollment in these classes',
9608: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9609: );
1.541 raeburn 9610: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9611: ' ('.$lt{'adby'}.')';
9612: if ($context eq 'auto') {
9613: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9614: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9615: foreach my $item (@badclasses) {
9616: if ($context eq 'auto') {
9617: $outcome .= " - $item\n";
9618: } else {
9619: $outcome .= "<li>$item</li>\n";
9620: }
9621: }
9622: if ($context eq 'auto') {
9623: $outcome .= $linefeed;
9624: } else {
1.566 albertel 9625: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9626: }
9627: }
1.444 albertel 9628: }
9629: if ($args->{'no_end_date'}) {
9630: $args->{'endaccess'} = 0;
9631: }
9632: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9633: $cenv{'internal.autoend'}=$args->{'enrollend'};
9634: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9635: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9636: if ($args->{'showphotos'}) {
9637: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9638: }
9639: $cenv{'internal.authtype'} = $args->{'authtype'};
9640: $cenv{'internal.autharg'} = $args->{'autharg'};
9641: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9642: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9643: 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');
9644: if ($context eq 'auto') {
9645: $outcome .= $krb_msg;
9646: } else {
1.566 albertel 9647: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9648: }
9649: $outcome .= $linefeed;
1.444 albertel 9650: }
9651: }
9652: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9653: if ($args->{'setpolicy'}) {
9654: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9655: }
9656: if ($args->{'setcontent'}) {
9657: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9658: }
9659: }
9660: if ($args->{'reshome'}) {
9661: $cenv{'reshome'}=$args->{'reshome'}.'/';
9662: $cenv{'reshome'}=~s/\/+$/\//;
9663: }
9664: #
9665: # course has keyed access
9666: #
9667: if ($args->{'setkeys'}) {
9668: $cenv{'keyaccess'}='yes';
9669: }
9670: # if specified, key authority is not course, but user
9671: # only active if keyaccess is yes
9672: if ($args->{'keyauth'}) {
1.487 albertel 9673: my ($user,$domain) = split(':',$args->{'keyauth'});
9674: $user = &LONCAPA::clean_username($user);
9675: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9676: if ($user ne '' && $domain ne '') {
1.487 albertel 9677: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9678: }
9679: }
9680:
9681: if ($args->{'disresdis'}) {
9682: $cenv{'pch.roles.denied'}='st';
9683: }
9684: if ($args->{'disablechat'}) {
9685: $cenv{'plc.roles.denied'}='st';
9686: }
9687:
9688: # Record we've not yet viewed the Course Initialization Helper for this
9689: # course
9690: $cenv{'course.helper.not.run'} = 1;
9691: #
9692: # Use new Randomseed
9693: #
9694: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9695: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9696: #
9697: # The encryption code and receipt prefix for this course
9698: #
9699: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9700: $cenv{'internal.encpref'}=100+int(9*rand(99));
9701: #
9702: # By default, use standard grading
9703: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9704:
1.541 raeburn 9705: $outcome .= $linefeed.&mt('Setting environment').': '.
9706: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9707: #
9708: # Open all assignments
9709: #
9710: if ($args->{'openall'}) {
9711: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9712: my %storecontent = ($storeunder => time,
9713: $storeunder.'.type' => 'date_start');
9714:
9715: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9716: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9717: }
9718: #
9719: # Set first page
9720: #
9721: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9722: || ($cloneid)) {
1.445 albertel 9723: use LONCAPA::map;
1.444 albertel 9724: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9725:
9726: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9727: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9728:
1.444 albertel 9729: $outcome .= ($fatal?$errtext:'read ok').' - ';
9730: my $title; my $url;
9731: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9732: $title=&mt('Syllabus');
1.444 albertel 9733: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9734: } else {
1.690 bisitz 9735: $title=&mt('Navigate Contents');
1.444 albertel 9736: $url='/adm/navmaps';
9737: }
1.445 albertel 9738:
9739: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9740: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9741:
9742: if ($errtext) { $fatal=2; }
1.541 raeburn 9743: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9744: }
1.566 albertel 9745:
9746: return (1,$outcome);
1.444 albertel 9747: }
9748:
9749: ############################################################
9750: ############################################################
9751:
1.378 raeburn 9752: sub course_type {
9753: my ($cid) = @_;
9754: if (!defined($cid)) {
9755: $cid = $env{'request.course.id'};
9756: }
1.404 albertel 9757: if (defined($env{'course.'.$cid.'.type'})) {
9758: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9759: } else {
9760: return 'Course';
1.377 raeburn 9761: }
9762: }
1.156 albertel 9763:
1.406 raeburn 9764: sub group_term {
9765: my $crstype = &course_type();
9766: my %names = (
1.692.4.6 raeburn 9767: 'Course' => 'group',
9768: 'Community' => 'group',
1.406 raeburn 9769: );
9770: return $names{$crstype};
9771: }
9772:
1.692.4.20 raeburn 9773: sub course_types {
9774: my @types = ('official','unofficial','community');
9775: my %typename = (
9776: official => 'Official course',
9777: unofficial => 'Unofficial course',
9778: community => 'Community',
9779: );
9780: return (\@types,\%typename);
9781: }
9782:
1.156 albertel 9783: sub icon {
9784: my ($file)=@_;
1.505 albertel 9785: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9786: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9787: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9788: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9789: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9790: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9791: $curfext.".gif") {
9792: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9793: $curfext.".gif";
9794: }
9795: }
1.249 albertel 9796: return &lonhttpdurl($iconname);
1.154 albertel 9797: }
1.84 albertel 9798:
1.575 albertel 9799: sub lonhttpdurl {
1.692 www 9800: #
9801: # Had been used for "small fry" static images on separate port 8080.
9802: # Modify here if lightweight http functionality desired again.
9803: # Currently eliminated due to increasing firewall issues.
9804: #
1.575 albertel 9805: my ($url)=@_;
1.692 www 9806: return $url;
1.215 albertel 9807: }
9808:
1.213 albertel 9809: sub connection_aborted {
9810: my ($r)=@_;
9811: $r->print(" ");$r->rflush();
9812: my $c = $r->connection;
9813: return $c->aborted();
9814: }
9815:
1.221 foxr 9816: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9817: # strings as 'strings'.
9818: sub escape_single {
1.221 foxr 9819: my ($input) = @_;
1.223 albertel 9820: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9821: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9822: return $input;
9823: }
1.223 albertel 9824:
1.222 foxr 9825: # Same as escape_single, but escape's "'s This
9826: # can be used for "strings"
9827: sub escape_double {
9828: my ($input) = @_;
9829: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9830: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9831: return $input;
9832: }
1.223 albertel 9833:
1.222 foxr 9834: # Escapes the last element of a full URL.
9835: sub escape_url {
9836: my ($url) = @_;
1.238 raeburn 9837: my @urlslices = split(/\//, $url,-1);
1.369 www 9838: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9839: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9840: }
1.462 albertel 9841:
1.692.4.2 raeburn 9842: sub compare_arrays {
9843: my ($arrayref1,$arrayref2) = @_;
9844: my (@difference,%count);
9845: @difference = ();
9846: %count = ();
9847: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
9848: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
9849: foreach my $element (keys(%count)) {
9850: if ($count{$element} == 1) {
9851: push(@difference,$element);
9852: }
9853: }
9854: }
9855: return @difference;
9856: }
9857:
1.462 albertel 9858: # -------------------------------------------------------- Initliaze user login
9859: sub init_user_environment {
1.463 albertel 9860: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9861: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9862:
9863: my $public=($username eq 'public' && $domain eq 'public');
9864:
9865: # See if old ID present, if so, remove
9866:
9867: my ($filename,$cookie,$userroles);
9868: my $now=time;
9869:
9870: if ($public) {
9871: my $max_public=100;
9872: my $oldest;
9873: my $oldest_time=0;
9874: for(my $next=1;$next<=$max_public;$next++) {
9875: if (-e $lonids."/publicuser_$next.id") {
9876: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9877: if ($mtime<$oldest_time || !$oldest_time) {
9878: $oldest_time=$mtime;
9879: $oldest=$next;
9880: }
9881: } else {
9882: $cookie="publicuser_$next";
9883: last;
9884: }
9885: }
9886: if (!$cookie) { $cookie="publicuser_$oldest"; }
9887: } else {
1.463 albertel 9888: # if this isn't a robot, kill any existing non-robot sessions
9889: if (!$args->{'robot'}) {
9890: opendir(DIR,$lonids);
9891: while ($filename=readdir(DIR)) {
9892: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9893: unlink($lonids.'/'.$filename);
9894: }
1.462 albertel 9895: }
1.463 albertel 9896: closedir(DIR);
1.462 albertel 9897: }
9898: # Give them a new cookie
1.463 albertel 9899: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9900: : $now.$$.int(rand(10000)));
1.463 albertel 9901: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9902:
9903: # Initialize roles
9904:
9905: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9906: }
9907: # ------------------------------------ Check browser type and MathML capability
9908:
9909: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9910: $clientunicode,$clientos) = &decode_user_agent($r);
9911:
9912: # -------------------------------------- Any accessibility options to remember?
9913: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9914: foreach my $option ('imagesuppress','appletsuppress',
9915: 'embedsuppress','fontenhance','blackwhite') {
9916: if ($form->{$option} eq 'true') {
9917: &Apache::lonnet::put('environment',{$option => 'on'},
9918: $domain,$username);
9919: } else {
9920: &Apache::lonnet::del('environment',[$option],
9921: $domain,$username);
9922: }
9923: }
9924: }
9925: # ------------------------------------------------------------- Get environment
9926:
9927: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9928: my ($tmp) = keys(%userenv);
9929: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9930: # default remote control to off
9931: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9932: } else {
9933: undef(%userenv);
9934: }
9935: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9936: $form->{'interface'}=$userenv{'interface'};
9937: }
9938: $env{'environment.remote'}=$userenv{'remote'};
9939: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9940:
9941: # --------------- Do not trust query string to be put directly into environment
9942: foreach my $option ('imagesuppress','appletsuppress',
9943: 'embedsuppress','fontenhance','blackwhite',
9944: 'interface','localpath','localres') {
9945: $form->{$option}=~s/[\n\r\=]//gs;
9946: }
9947: # --------------------------------------------------------- Write first profile
9948:
9949: {
9950: my %initial_env =
9951: ("user.name" => $username,
9952: "user.domain" => $domain,
9953: "user.home" => $authhost,
9954: "browser.type" => $clientbrowser,
9955: "browser.version" => $clientversion,
9956: "browser.mathml" => $clientmathml,
9957: "browser.unicode" => $clientunicode,
9958: "browser.os" => $clientos,
9959: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9960: "request.course.fn" => '',
9961: "request.course.uri" => '',
9962: "request.course.sec" => '',
9963: "request.role" => 'cm',
9964: "request.role.adv" => $env{'user.adv'},
9965: "request.host" => $ENV{'REMOTE_ADDR'},);
9966:
9967: if ($form->{'localpath'}) {
9968: $initial_env{"browser.localpath"} = $form->{'localpath'};
9969: $initial_env{"browser.localres"} = $form->{'localres'};
9970: }
9971:
9972: if ($public) {
9973: $initial_env{"environment.remote"} = "off";
9974: }
9975: if ($form->{'interface'}) {
9976: $form->{'interface'}=~s/\W//gs;
9977: $initial_env{"browser.interface"} = $form->{'interface'};
9978: $env{'browser.interface'}=$form->{'interface'};
9979: foreach my $option ('imagesuppress','appletsuppress',
9980: 'embedsuppress','fontenhance','blackwhite') {
9981: if (($form->{$option} eq 'true') ||
9982: ($userenv{$option} eq 'on')) {
9983: $initial_env{"browser.$option"} = "on";
9984: }
9985: }
9986: }
9987:
1.692.4.2 raeburn 9988: foreach my $tool ('aboutme','blog','portfolio') {
9989: $userenv{'availabletools.'.$tool} =
9990: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9991: }
9992:
1.692.4.6 raeburn 9993: foreach my $crstype ('official','unofficial','community') {
1.692.4.2 raeburn 9994: $userenv{'canrequest.'.$crstype} =
9995: &Apache::lonnet::usertools_access($username,$domain,$crstype,
9996: 'reload','requestcourses');
9997: }
9998:
1.462 albertel 9999: $env{'user.environment'} = "$lonids/$cookie.id";
10000:
10001: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10002: &GDBM_WRCREAT(),0640)) {
10003: &_add_to_env(\%disk_env,\%initial_env);
10004: &_add_to_env(\%disk_env,\%userenv,'environment.');
10005: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10006: if (ref($args->{'extra_env'})) {
10007: &_add_to_env(\%disk_env,$args->{'extra_env'});
10008: }
1.462 albertel 10009: untie(%disk_env);
10010: } else {
10011: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
10012: 'Could not create environment storage in lonauth: '.$!.'</font>');
10013: return 'error: '.$!;
10014: }
10015: }
10016: $env{'request.role'}='cm';
10017: $env{'request.role.adv'}=$env{'user.adv'};
10018: $env{'browser.type'}=$clientbrowser;
10019:
10020: return $cookie;
10021:
10022: }
10023:
10024: sub _add_to_env {
10025: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10026: if (ref($env_data) eq 'HASH') {
10027: while (my ($key,$value) = each(%$env_data)) {
10028: $idf->{$prefix.$key} = $value;
10029: $env{$prefix.$key} = $value;
10030: }
1.462 albertel 10031: }
10032: }
10033:
1.685 tempelho 10034: # --- Get the symbolic name of a problem and the url
10035: sub get_symb {
10036: my ($request,$silent) = @_;
1.692.4.2 raeburn 10037: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10038: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10039: if ($symb eq '') {
10040: if (!$silent) {
10041: $request->print("Unable to handle ambiguous references:$url:.");
10042: return ();
10043: }
10044: }
10045: &Apache::lonenc::check_decrypt(\$symb);
10046: return ($symb);
10047: }
10048:
10049: # --------------------------------------------------------------Get annotation
10050:
10051: sub get_annotation {
10052: my ($symb,$enc) = @_;
10053:
10054: my $key = $symb;
10055: if (!$enc) {
10056: $key =
10057: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10058: }
10059: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10060: return $annotation{$key};
10061: }
10062:
10063: sub clean_symb {
1.692.4.2 raeburn 10064: my ($symb,$delete_enc) = @_;
1.685 tempelho 10065:
10066: &Apache::lonenc::check_decrypt(\$symb);
10067: my $enc = $env{'request.enc'};
1.692.4.2 raeburn 10068: if ($delete_enc) {
10069: delete($env{'request.enc'});
10070: }
1.685 tempelho 10071:
10072: return ($symb,$enc);
10073: }
1.462 albertel 10074:
1.41 ng 10075: =pod
10076:
10077: =back
10078:
1.112 bowersj2 10079: =cut
1.41 ng 10080:
1.112 bowersj2 10081: 1;
10082: __END__;
1.41 ng 10083:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>