Annotation of loncom/interface/loncommon.pm, revision 1.692.2.13
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.692.2.13! raeburn 4: # $Id: loncommon.pm,v 1.692.2.12 2009/01/12 04:39:30 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');
409: <script type="text/javascript" language="Javascript" >
410: var stdeditbrowser;
1.558 albertel 411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74 www 412: var url = '/adm/pickstudent?';
413: var filter;
1.558 albertel 414: if (!ignorefilter) {
415: eval('filter=document.'+formname+'.'+uname+'.value;');
416: }
1.74 www 417: if (filter != null) {
418: if (filter != '') {
419: url += 'filter='+filter+'&';
420: }
421: }
422: url += 'form=' + formname + '&unameelement='+uname+
423: '&udomelement='+udom;
1.111 www 424: if (roleflag) { url+="&roles=1"; }
1.102 www 425: var title = 'Student_Browser';
1.74 www 426: var options = 'scrollbars=1,resizable=1,menubar=0';
427: options += ',width=700,height=600';
428: stdeditbrowser = open(url,title,options,'1');
429: stdeditbrowser.focus();
430: }
431: </script>
432: ENDSTDBRW
433: }
1.42 matthew 434:
1.74 www 435: sub selectstudent_link {
1.111 www 436: my ($form,$unameele,$udomele)=@_;
1.258 albertel 437: if ($env{'request.course.id'}) {
1.302 albertel 438: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
439: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
440: '/'.$env{'request.course.sec'})) {
1.111 www 441: return '';
442: }
443: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607 albertel 444: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 445: }
1.258 albertel 446: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 447: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 448: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 449: }
450: return '';
1.91 www 451: }
452:
1.653 raeburn 453: sub authorbrowser_javascript {
454: return <<"ENDAUTHORBRW";
455: <script type="text/javascript">
456: var stdeditbrowser;
457:
458: function openauthorbrowser(formname,udom) {
459: var url = '/adm/pickauthor?';
460: url += 'form='+formname+'&roledom='+udom;
461: var title = 'Author_Browser';
462: var options = 'scrollbars=1,resizable=1,menubar=0';
463: options += ',width=700,height=600';
464: stdeditbrowser = open(url,title,options,'1');
465: stdeditbrowser.focus();
466: }
467:
468: </script>
469: ENDAUTHORBRW
470: }
471:
1.91 www 472: sub coursebrowser_javascript {
1.468 raeburn 473: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 474: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468 raeburn 475: my $output = '
1.538 albertel 476: <script type="text/javascript">
1.468 raeburn 477: var stdeditbrowser;'."\n";
478: $output .= <<"ENDSTDBRW";
1.377 raeburn 479: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 480: var url = '/adm/pickcourse?';
1.468 raeburn 481: var domainfilter = '';
482: var formid = getFormIdByName(formname);
483: if (formid > -1) {
484: var domid = getIndexByName(formid,udom);
485: if (domid > -1) {
486: if (document.forms[formid].elements[domid].type == 'select-one') {
487: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
488: }
489: if (document.forms[formid].elements[domid].type == 'hidden') {
490: domainfilter=document.forms[formid].elements[domid].value;
491: }
492: }
1.91 www 493: }
1.128 albertel 494: if (domainfilter != null) {
495: if (domainfilter != '') {
496: url += 'domainfilter='+domainfilter+'&';
497: }
498: }
1.91 www 499: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 500: '&cdomelement='+udom+
501: '&cnameelement='+desc;
1.468 raeburn 502: if (extra_element !=null && extra_element != '') {
1.594 raeburn 503: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 504: url += '&roleelement='+extra_element;
505: if (domainfilter == null || domainfilter == '') {
506: url += '&domainfilter='+extra_element;
507: }
1.234 raeburn 508: }
1.468 raeburn 509: else {
510: if (formname == 'portform') {
511: url += '&setroles='+extra_element;
512: }
513: }
1.230 raeburn 514: }
1.293 raeburn 515: if (multflag !=null && multflag != '') {
516: url += '&multiple='+multflag;
517: }
1.377 raeburn 518: if (crstype == 'Course/Group') {
519: if (formname == 'cu') {
520: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
521: if (crstype == "") {
522: alert("$crs_or_grp_alert");
523: return;
524: }
525: }
526: }
527: if (crstype !=null && crstype != '') {
528: url += '&type='+crstype;
529: }
1.102 www 530: var title = 'Course_Browser';
1.91 www 531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
1.468 raeburn 536:
537: function getFormIdByName(formname) {
538: for (var i=0;i<document.forms.length;i++) {
539: if (document.forms[i].name == formname) {
540: return i;
541: }
542: }
543: return -1;
544: }
545:
546: function getIndexByName(formid,item) {
547: for (var i=0;i<document.forms[formid].elements.length;i++) {
548: if (document.forms[formid].elements[i].name == item) {
549: return i;
550: }
551: }
552: return -1;
553: }
1.91 www 554: ENDSTDBRW
1.468 raeburn 555: if ($sec_element ne '') {
556: $output .= &setsec_javascript($sec_element,$formname);
557: }
558: $output .= '
559: </script>';
560: return $output;
561: }
562:
563: sub setsec_javascript {
564: my ($sec_element,$formname) = @_;
565: my $setsections = qq|
566: function setSect(sectionlist) {
1.629 raeburn 567: var sectionsArray = new Array();
568: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
569: sectionsArray = sectionlist.split(",");
570: }
1.468 raeburn 571: var numSections = sectionsArray.length;
572: document.$formname.$sec_element.length = 0;
573: if (numSections == 0) {
574: document.$formname.$sec_element.multiple=false;
575: document.$formname.$sec_element.size=1;
576: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
577: } else {
578: if (numSections == 1) {
579: document.$formname.$sec_element.multiple=false;
580: document.$formname.$sec_element.size=1;
581: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
582: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
583: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
584: } else {
585: for (var i=0; i<numSections; i++) {
586: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
587: }
588: document.$formname.$sec_element.multiple=true
589: if (numSections < 3) {
590: document.$formname.$sec_element.size=numSections;
591: } else {
592: document.$formname.$sec_element.size=3;
593: }
594: document.$formname.$sec_element.options[0].selected = false
595: }
596: }
1.91 www 597: }
1.468 raeburn 598: |;
599: return $setsections;
600: }
601:
1.91 www 602:
603: sub selectcourse_link {
1.377 raeburn 604: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 605: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
606: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 607: }
1.42 matthew 608:
1.653 raeburn 609: sub selectauthor_link {
610: my ($form,$udom)=@_;
611: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
612: &mt('Select Author').'</a>';
613: }
614:
1.273 raeburn 615: sub check_uncheck_jscript {
616: my $jscript = <<"ENDSCRT";
617: function checkAll(field) {
618: if (field.length > 0) {
619: for (i = 0; i < field.length; i++) {
620: field[i].checked = true ;
621: }
622: } else {
623: field.checked = true
624: }
625: }
626:
627: function uncheckAll(field) {
628: if (field.length > 0) {
629: for (i = 0; i < field.length; i++) {
630: field[i].checked = false ;
1.543 albertel 631: }
632: } else {
1.273 raeburn 633: field.checked = false ;
634: }
635: }
636: ENDSCRT
637: return $jscript;
638: }
639:
1.656 www 640: sub select_timezone {
1.659 raeburn 641: my ($name,$selected,$onchange,$includeempty)=@_;
642: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
643: if ($includeempty) {
644: $output .= '<option value=""';
645: if (($selected eq '') || ($selected eq 'local')) {
646: $output .= ' selected="selected" ';
647: }
648: $output .= '> </option>';
649: }
1.657 raeburn 650: my @timezones = DateTime::TimeZone->all_names;
651: foreach my $tzone (@timezones) {
652: $output.= '<option value="'.$tzone.'"';
653: if ($tzone eq $selected) {
654: $output.=' selected="selected"';
655: }
656: $output.=">$tzone</option>\n";
1.656 www 657: }
658: $output.="</select>";
659: return $output;
660: }
1.273 raeburn 661:
1.687 raeburn 662: sub select_datelocale {
663: my ($name,$selected,$onchange,$includeempty)=@_;
664: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
665: if ($includeempty) {
666: $output .= '<option value=""';
667: if ($selected eq '') {
668: $output .= ' selected="selected" ';
669: }
670: $output .= '> </option>';
671: }
672: my (@possibles,%locale_names);
673: my @locales = DateTime::Locale::Catalog::Locales;
674: foreach my $locale (@locales) {
675: if (ref($locale) eq 'HASH') {
676: my $id = $locale->{'id'};
677: if ($id ne '') {
678: my $en_terr = $locale->{'en_territory'};
679: my $native_terr = $locale->{'native_territory'};
1.692.2.1 raeburn 680: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 681: if (grep(/^en$/,@languages) || !@languages) {
682: if ($en_terr ne '') {
683: $locale_names{$id} = '('.$en_terr.')';
684: } elsif ($native_terr ne '') {
685: $locale_names{$id} = $native_terr;
686: }
687: } else {
688: if ($native_terr ne '') {
689: $locale_names{$id} = $native_terr.' ';
690: } elsif ($en_terr ne '') {
691: $locale_names{$id} = '('.$en_terr.')';
692: }
693: }
694: push (@possibles,$id);
695: }
696: }
697: }
698: foreach my $item (sort(@possibles)) {
699: $output.= '<option value="'.$item.'"';
700: if ($item eq $selected) {
701: $output.=' selected="selected"';
702: }
703: $output.=">$item";
704: if ($locale_names{$item} ne '') {
705: $output.=" $locale_names{$item}</option>\n";
706: }
707: $output.="</option>\n";
708: }
709: $output.="</select>";
710: return $output;
711: }
712:
1.42 matthew 713: =pod
1.36 matthew 714:
1.648 raeburn 715: =item * &linked_select_forms(...)
1.36 matthew 716:
717: linked_select_forms returns a string containing a <script></script> block
718: and html for two <select> menus. The select menus will be linked in that
719: changing the value of the first menu will result in new values being placed
720: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 721: order unless a defined order is provided.
1.36 matthew 722:
723: linked_select_forms takes the following ordered inputs:
724:
725: =over 4
726:
1.112 bowersj2 727: =item * $formname, the name of the <form> tag
1.36 matthew 728:
1.112 bowersj2 729: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 730:
1.112 bowersj2 731: =item * $firstdefault, the default value for the first menu
1.36 matthew 732:
1.112 bowersj2 733: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 734:
1.112 bowersj2 735: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 736:
1.112 bowersj2 737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 738:
1.609 raeburn 739: =item * $menuorder, the order of values in the first menu
740:
1.41 ng 741: =back
742:
1.36 matthew 743: Below is an example of such a hash. Only the 'text', 'default', and
744: 'select2' keys must appear as stated. keys(%menu) are the possible
745: values for the first select menu. The text that coincides with the
1.41 ng 746: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 747: and text for the second menu are given in the hash pointed to by
748: $menu{$choice1}->{'select2'}.
749:
1.112 bowersj2 750: my %menu = ( A1 => { text =>"Choice A1" ,
751: default => "B3",
752: select2 => {
753: B1 => "Choice B1",
754: B2 => "Choice B2",
755: B3 => "Choice B3",
756: B4 => "Choice B4"
1.609 raeburn 757: },
758: order => ['B4','B3','B1','B2'],
1.112 bowersj2 759: },
760: A2 => { text =>"Choice A2" ,
761: default => "C2",
762: select2 => {
763: C1 => "Choice C1",
764: C2 => "Choice C2",
765: C3 => "Choice C3"
1.609 raeburn 766: },
767: order => ['C2','C1','C3'],
1.112 bowersj2 768: },
769: A3 => { text =>"Choice A3" ,
770: default => "D6",
771: select2 => {
772: D1 => "Choice D1",
773: D2 => "Choice D2",
774: D3 => "Choice D3",
775: D4 => "Choice D4",
776: D5 => "Choice D5",
777: D6 => "Choice D6",
778: D7 => "Choice D7"
1.609 raeburn 779: },
780: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 781: }
782: );
1.36 matthew 783:
784: =cut
785:
786: sub linked_select_forms {
787: my ($formname,
788: $middletext,
789: $firstdefault,
790: $firstselectname,
791: $secondselectname,
1.609 raeburn 792: $hashref,
793: $menuorder,
1.36 matthew 794: ) = @_;
795: my $second = "document.$formname.$secondselectname";
796: my $first = "document.$formname.$firstselectname";
797: # output the javascript to do the changing
798: my $result = '';
1.219 albertel 799: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 800: $result.="var select2data = new Object();\n";
801: $" = '","';
802: my $debug = '';
803: foreach my $s1 (sort(keys(%$hashref))) {
804: $result.="select2data.d_$s1 = new Object();\n";
805: $result.="select2data.d_$s1.def = new String('".
806: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 807: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 808: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 809: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
810: @s2values = @{$hashref->{$s1}->{'order'}};
811: }
1.36 matthew 812: $result.="\"@s2values\");\n";
813: $result.="select2data.d_$s1.texts = new Array(";
814: my @s2texts;
815: foreach my $value (@s2values) {
816: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
817: }
818: $result.="\"@s2texts\");\n";
819: }
820: $"=' ';
821: $result.= <<"END";
822:
823: function select1_changed() {
824: // Determine new choice
825: var newvalue = "d_" + $first.value;
826: // update select2
827: var values = select2data[newvalue].values;
828: var texts = select2data[newvalue].texts;
829: var select2def = select2data[newvalue].def;
830: var i;
831: // out with the old
832: for (i = 0; i < $second.options.length; i++) {
833: $second.options[i] = null;
834: }
835: // in with the nuclear
836: for (i=0;i<values.length; i++) {
837: $second.options[i] = new Option(values[i]);
1.143 matthew 838: $second.options[i].value = values[i];
1.36 matthew 839: $second.options[i].text = texts[i];
840: if (values[i] == select2def) {
841: $second.options[i].selected = true;
842: }
843: }
844: }
845: </script>
846: END
847: # output the initial values for the selection lists
848: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 849: my @order = sort(keys(%{$hashref}));
850: if (ref($menuorder) eq 'ARRAY') {
851: @order = @{$menuorder};
852: }
853: foreach my $value (@order) {
1.36 matthew 854: $result.=" <option value=\"$value\" ";
1.253 albertel 855: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 856: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 857: }
858: $result .= "</select>\n";
859: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
860: $result .= $middletext;
861: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
862: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 863:
864: my @secondorder = sort(keys(%select2));
865: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
866: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
867: }
868: foreach my $value (@secondorder) {
1.36 matthew 869: $result.=" <option value=\"$value\" ";
1.253 albertel 870: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 871: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 872: }
873: $result .= "</select>\n";
874: # return $debug;
875: return $result;
876: } # end of sub linked_select_forms {
877:
1.45 matthew 878: =pod
1.44 bowersj2 879:
1.648 raeburn 880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 881:
1.112 bowersj2 882: Returns a string corresponding to an HTML link to the given help
883: $topic, where $topic corresponds to the name of a .tex file in
884: /home/httpd/html/adm/help/tex, with underscores replaced by
885: spaces.
886:
887: $text will optionally be linked to the same topic, allowing you to
888: link text in addition to the graphic. If you do not want to link
889: text, but wish to specify one of the later parameters, pass an
890: empty string.
891:
892: $stayOnPage is a value that will be interpreted as a boolean. If true,
893: the link will not open a new window. If false, the link will open
894: a new window using Javascript. (Default is false.)
895:
896: $width and $height are optional numerical parameters that will
897: override the width and height of the popped up window, which may
898: be useful for certain help topics with big pictures included.
1.44 bowersj2 899:
900: =cut
901:
902: sub help_open_topic {
1.48 bowersj2 903: my ($topic, $text, $stayOnPage, $width, $height) = @_;
904: $text = "" if (not defined $text);
1.44 bowersj2 905: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 906: if ($env{'browser.interface'} eq 'textual') {
1.79 www 907: $stayOnPage=1;
908: }
1.44 bowersj2 909: $width = 350 if (not defined $width);
910: $height = 400 if (not defined $height);
911: my $filename = $topic;
912: $filename =~ s/ /_/g;
913:
1.48 bowersj2 914: my $template = "";
915: my $link;
1.572 banghart 916:
1.159 www 917: $topic=~s/\W/\_/g;
1.44 bowersj2 918:
1.572 banghart 919: if (!$stayOnPage) {
1.72 bowersj2 920: $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 921: } else {
1.48 bowersj2 922: $link = "/adm/help/${filename}.hlp";
923: }
924:
925: # Add the text
1.572 banghart 926: if ($text ne "") {
1.77 www 927: $template .=
1.572 banghart 928: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.691 bisitz 929: "<td bgcolor='#5555FF'><span class=\"LC_nobreak\"><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 930: }
931:
932: # Add the graphic
1.179 matthew 933: my $title = &mt('Online Help');
1.667 raeburn 934: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48 bowersj2 935: $template .= <<"ENDTEMPLATE";
1.436 albertel 936: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 937: ENDTEMPLATE
1.691 bisitz 938: if ($text ne '') { $template.='</span></td></tr></table>' };
1.44 bowersj2 939: return $template;
940:
1.106 bowersj2 941: }
942:
943: # This is a quicky function for Latex cheatsheet editing, since it
944: # appears in at least four places
945: sub helpLatexCheatsheet {
1.692.2.12 raeburn 946: my ($topic,$text,$not_author) = @_;
947: my $out;
1.106 bowersj2 948: my $addOther = '';
1.692.2.12 raeburn 949: if ($topic) {
950: $addOther = Apache::loncommon::help_open_topic($topic,$text,
951: undef, undef, 600).
952: '</td><td>';
953: }
954: $out = '<table><tr><td>'.
955: $addOther.
956: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
957: undef,undef,600).
958: '</td><td>'.
959: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
960: undef,undef,600).
961: '</td>';
962: unless ($not_author) {
963: $out .= '<td>'.
964: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
965: undef,undef,600).
966: '</td>';
967: }
968: $out .= '</tr></table>';
969: return $out;
1.172 www 970: }
971:
1.430 albertel 972: sub general_help {
973: my $helptopic='Student_Intro';
974: if ($env{'request.role'}=~/^(ca|au)/) {
975: $helptopic='Authoring_Intro';
976: } elsif ($env{'request.role'}=~/^cc/) {
977: $helptopic='Course_Coordination_Intro';
1.672 raeburn 978: } elsif ($env{'request.role'}=~/^dc/) {
979: $helptopic='Domain_Coordination_Intro';
1.430 albertel 980: }
981: return $helptopic;
982: }
983:
984: sub update_help_link {
985: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
986: my $origurl = $ENV{'REQUEST_URI'};
987: $origurl=~s|^/~|/priv/|;
988: my $timestamp = time;
989: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
990: $$datum = &escape($$datum);
991: }
992:
993: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
994: my $output .= <<"ENDOUTPUT";
995: <script type="text/javascript">
996: banner_link = '$banner_link';
997: </script>
998: ENDOUTPUT
999: return $output;
1000: }
1001:
1002: # now just updates the help link and generates a blue icon
1.193 raeburn 1003: sub help_open_menu {
1.430 albertel 1004: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1005: = @_;
1.430 albertel 1006: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1007: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1008: # if environment.remote is on (using remote control UI)
1.572 banghart 1009: if ($env{'browser.interface'} eq 'textual' ||
1010: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1011: $stayOnPage=1;
1.430 albertel 1012: }
1013: my $output;
1014: if ($component_help) {
1015: if (!$text) {
1016: $output=&help_open_topic($component_help,undef,$stayOnPage,
1017: $width,$height);
1018: } else {
1019: my $help_text;
1020: $help_text=&unescape($topic);
1021: $output='<table><tr><td>'.
1022: &help_open_topic($component_help,$help_text,$stayOnPage,
1023: $width,$height).'</td></tr></table>';
1024: }
1025: }
1026: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1027: return $output.$banner_link;
1028: }
1029:
1030: sub top_nav_help {
1031: my ($text) = @_;
1.436 albertel 1032: $text = &mt($text);
1.572 banghart 1033: my $stay_on_page =
1.436 albertel 1034: ($env{'browser.interface'} eq 'textual' ||
1035: $env{'environment.remote'} eq 'off' );
1.572 banghart 1036: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1037: : "javascript:helpMenu('open')";
1.572 banghart 1038: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1039:
1.201 raeburn 1040: my $title = &mt('Get help');
1.436 albertel 1041:
1042: return <<"END";
1043: $banner_link
1044: <a href="$link" title="$title">$text</a>
1045: END
1046: }
1047:
1048: sub help_menu_js {
1049: my ($text) = @_;
1050:
1051: my $stayOnPage =
1052: ($env{'browser.interface'} eq 'textual' ||
1053: $env{'environment.remote'} eq 'off' );
1054:
1055: my $width = 620;
1056: my $height = 600;
1.430 albertel 1057: my $helptopic=&general_help();
1058: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1059: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1060: my $start_page =
1061: &Apache::loncommon::start_page('Help Menu', undef,
1062: {'frameset' => 1,
1063: 'js_ready' => 1,
1064: 'add_entries' => {
1065: 'border' => '0',
1.579 raeburn 1066: 'rows' => "110,*",},});
1.331 albertel 1067: my $end_page =
1068: &Apache::loncommon::end_page({'frameset' => 1,
1069: 'js_ready' => 1,});
1070:
1.436 albertel 1071: my $template .= <<"ENDTEMPLATE";
1072: <script type="text/javascript">
1.253 albertel 1073: // <!-- BEGIN LON-CAPA Internal
1074: // <![CDATA[
1.430 albertel 1075: var banner_link = '';
1.243 raeburn 1076: function helpMenu(target) {
1077: var caller = this;
1078: if (target == 'open') {
1079: var newWindow = null;
1080: try {
1.262 albertel 1081: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1082: }
1083: catch(error) {
1084: writeHelp(caller);
1085: return;
1086: }
1087: if (newWindow) {
1088: caller = newWindow;
1089: }
1.193 raeburn 1090: }
1.243 raeburn 1091: writeHelp(caller);
1092: return;
1093: }
1094: function writeHelp(caller) {
1.430 albertel 1095: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1096: caller.document.close()
1097: caller.focus()
1.193 raeburn 1098: }
1.253 albertel 1099: // ]]>
1.219 albertel 1100: // END LON-CAPA Internal -->
1.436 albertel 1101: </script>
1.193 raeburn 1102: ENDTEMPLATE
1103: return $template;
1104: }
1105:
1.172 www 1106: sub help_open_bug {
1107: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1108: unless ($env{'user.adv'}) { return ''; }
1.172 www 1109: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1110: $text = "" if (not defined $text);
1111: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1112: if ($env{'browser.interface'} eq 'textual' ||
1113: $env{'environment.remote'} eq 'off' ) {
1.172 www 1114: $stayOnPage=1;
1115: }
1.184 albertel 1116: $width = 600 if (not defined $width);
1117: $height = 600 if (not defined $height);
1.172 www 1118:
1119: $topic=~s/\W+/\+/g;
1120: my $link='';
1121: my $template='';
1.379 albertel 1122: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1123: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1124: if (!$stayOnPage)
1125: {
1126: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1127: }
1128: else
1129: {
1130: $link = $url;
1131: }
1132: # Add the text
1133: if ($text ne "")
1134: {
1135: $template .=
1136: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1137: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1138: }
1139:
1140: # Add the graphic
1.179 matthew 1141: my $title = &mt('Report a Bug');
1.215 albertel 1142: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1143: $template .= <<"ENDTEMPLATE";
1.436 albertel 1144: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1145: ENDTEMPLATE
1146: if ($text ne '') { $template.='</td></tr></table>' };
1147: return $template;
1148:
1149: }
1150:
1151: sub help_open_faq {
1152: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1153: unless ($env{'user.adv'}) { return ''; }
1.172 www 1154: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1155: $text = "" if (not defined $text);
1156: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1157: if ($env{'browser.interface'} eq 'textual' ||
1158: $env{'environment.remote'} eq 'off' ) {
1.172 www 1159: $stayOnPage=1;
1160: }
1161: $width = 350 if (not defined $width);
1162: $height = 400 if (not defined $height);
1163:
1164: $topic=~s/\W+/\+/g;
1165: my $link='';
1166: my $template='';
1167: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1168: if (!$stayOnPage)
1169: {
1170: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1171: }
1172: else
1173: {
1174: $link = $url;
1175: }
1176:
1177: # Add the text
1178: if ($text ne "")
1179: {
1180: $template .=
1.173 www 1181: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1182: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1183: }
1184:
1185: # Add the graphic
1.179 matthew 1186: my $title = &mt('View the FAQ');
1.215 albertel 1187: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1188: $template .= <<"ENDTEMPLATE";
1.436 albertel 1189: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1190: ENDTEMPLATE
1191: if ($text ne '') { $template.='</td></tr></table>' };
1192: return $template;
1193:
1.44 bowersj2 1194: }
1.37 matthew 1195:
1.180 matthew 1196: ###############################################################
1197: ###############################################################
1198:
1.45 matthew 1199: =pod
1200:
1.648 raeburn 1201: =item * &change_content_javascript():
1.256 matthew 1202:
1203: This and the next function allow you to create small sections of an
1204: otherwise static HTML page that you can update on the fly with
1205: Javascript, even in Netscape 4.
1206:
1207: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1208: must be written to the HTML page once. It will prove the Javascript
1209: function "change(name, content)". Calling the change function with the
1210: name of the section
1211: you want to update, matching the name passed to C<changable_area>, and
1212: the new content you want to put in there, will put the content into
1213: that area.
1214:
1215: B<Note>: Netscape 4 only reserves enough space for the changable area
1216: to contain room for the original contents. You need to "make space"
1217: for whatever changes you wish to make, and be B<sure> to check your
1218: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1219: it's adequate for updating a one-line status display, but little more.
1220: This script will set the space to 100% width, so you only need to
1221: worry about height in Netscape 4.
1222:
1223: Modern browsers are much less limiting, and if you can commit to the
1224: user not using Netscape 4, this feature may be used freely with
1225: pretty much any HTML.
1226:
1227: =cut
1228:
1229: sub change_content_javascript {
1230: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1231: if ($env{'browser.type'} eq 'netscape' &&
1232: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1233: return (<<NETSCAPE4);
1234: function change(name, content) {
1235: doc = document.layers[name+"___escape"].layers[0].document;
1236: doc.open();
1237: doc.write(content);
1238: doc.close();
1239: }
1240: NETSCAPE4
1241: } else {
1242: # Otherwise, we need to use semi-standards-compliant code
1243: # (technically, "innerHTML" isn't standard but the equivalent
1244: # is really scary, and every useful browser supports it
1245: return (<<DOMBASED);
1246: function change(name, content) {
1247: element = document.getElementById(name);
1248: element.innerHTML = content;
1249: }
1250: DOMBASED
1251: }
1252: }
1253:
1254: =pod
1255:
1.648 raeburn 1256: =item * &changable_area($name,$origContent):
1.256 matthew 1257:
1258: This provides a "changable area" that can be modified on the fly via
1259: the Javascript code provided in C<change_content_javascript>. $name is
1260: the name you will use to reference the area later; do not repeat the
1261: same name on a given HTML page more then once. $origContent is what
1262: the area will originally contain, which can be left blank.
1263:
1264: =cut
1265:
1266: sub changable_area {
1267: my ($name, $origContent) = @_;
1268:
1.258 albertel 1269: if ($env{'browser.type'} eq 'netscape' &&
1270: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1271: # If this is netscape 4, we need to use the Layer tag
1272: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1273: } else {
1274: return "<span id='$name'>$origContent</span>";
1275: }
1276: }
1277:
1278: =pod
1279:
1.648 raeburn 1280: =item * &viewport_geometry_js
1.590 raeburn 1281:
1282: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1283:
1284: =cut
1285:
1286:
1287: sub viewport_geometry_js {
1288: return <<"GEOMETRY";
1289: var Geometry = {};
1290: function init_geometry() {
1291: if (Geometry.init) { return };
1292: Geometry.init=1;
1293: if (window.innerHeight) {
1294: Geometry.getViewportHeight = function() { return window.innerHeight; };
1295: Geometry.getViewportWidth = function() { return window.innerWidth; };
1296: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1297: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1298: }
1299: else if (document.documentElement && document.documentElement.clientHeight) {
1300: Geometry.getViewportHeight =
1301: function() { return document.documentElement.clientHeight; };
1302: Geometry.getViewportWidth =
1303: function() { return document.documentElement.clientWidth; };
1304:
1305: Geometry.getHorizontalScroll =
1306: function() { return document.documentElement.scrollLeft; };
1307: Geometry.getVerticalScroll =
1308: function() { return document.documentElement.scrollTop; };
1309: }
1310: else if (document.body.clientHeight) {
1311: Geometry.getViewportHeight =
1312: function() { return document.body.clientHeight; };
1313: Geometry.getViewportWidth =
1314: function() { return document.body.clientWidth; };
1315: Geometry.getHorizontalScroll =
1316: function() { return document.body.scrollLeft; };
1317: Geometry.getVerticalScroll =
1318: function() { return document.body.scrollTop; };
1319: }
1320: }
1321:
1322: GEOMETRY
1323: }
1324:
1325: =pod
1326:
1.648 raeburn 1327: =item * &viewport_size_js()
1.590 raeburn 1328:
1329: 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.
1330:
1331: =cut
1332:
1333: sub viewport_size_js {
1334: my $geometry = &viewport_geometry_js();
1335: return <<"DIMS";
1336:
1337: $geometry
1338:
1339: function getViewportDims(width,height) {
1340: init_geometry();
1341: width.value = Geometry.getViewportWidth();
1342: height.value = Geometry.getViewportHeight();
1343: return;
1344: }
1345:
1346: DIMS
1347: }
1348:
1349: =pod
1350:
1.648 raeburn 1351: =item * &resize_textarea_js()
1.565 albertel 1352:
1353: emits the needed javascript to resize a textarea to be as big as possible
1354:
1355: creates a function resize_textrea that takes two IDs first should be
1356: the id of the element to resize, second should be the id of a div that
1357: surrounds everything that comes after the textarea, this routine needs
1358: to be attached to the <body> for the onload and onresize events.
1359:
1.648 raeburn 1360: =back
1.565 albertel 1361:
1362: =cut
1363:
1364: sub resize_textarea_js {
1.590 raeburn 1365: my $geometry = &viewport_geometry_js();
1.565 albertel 1366: return <<"RESIZE";
1367: <script type="text/javascript">
1.590 raeburn 1368: $geometry
1.565 albertel 1369:
1.588 albertel 1370: function getX(element) {
1371: var x = 0;
1372: while (element) {
1373: x += element.offsetLeft;
1374: element = element.offsetParent;
1375: }
1376: return x;
1377: }
1378: function getY(element) {
1379: var y = 0;
1380: while (element) {
1381: y += element.offsetTop;
1382: element = element.offsetParent;
1383: }
1384: return y;
1385: }
1386:
1387:
1.565 albertel 1388: function resize_textarea(textarea_id,bottom_id) {
1389: init_geometry();
1390: var textarea = document.getElementById(textarea_id);
1391: //alert(textarea);
1392:
1.588 albertel 1393: var textarea_top = getY(textarea);
1.565 albertel 1394: var textarea_height = textarea.offsetHeight;
1395: var bottom = document.getElementById(bottom_id);
1.588 albertel 1396: var bottom_top = getY(bottom);
1.565 albertel 1397: var bottom_height = bottom.offsetHeight;
1398: var window_height = Geometry.getViewportHeight();
1.588 albertel 1399: var fudge = 23;
1.565 albertel 1400: var new_height = window_height-fudge-textarea_top-bottom_height;
1401: if (new_height < 300) {
1402: new_height = 300;
1403: }
1404: textarea.style.height=new_height+'px';
1405: }
1406: </script>
1407: RESIZE
1408:
1409: }
1410:
1411: =pod
1412:
1.256 matthew 1413: =head1 Excel and CSV file utility routines
1414:
1415: =over 4
1416:
1417: =cut
1418:
1419: ###############################################################
1420: ###############################################################
1421:
1422: =pod
1423:
1.648 raeburn 1424: =item * &csv_translate($text)
1.37 matthew 1425:
1.185 www 1426: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1427: format.
1428:
1429: =cut
1430:
1.180 matthew 1431: ###############################################################
1432: ###############################################################
1.37 matthew 1433: sub csv_translate {
1434: my $text = shift;
1435: $text =~ s/\"/\"\"/g;
1.209 albertel 1436: $text =~ s/\n/ /g;
1.37 matthew 1437: return $text;
1438: }
1.180 matthew 1439:
1440: ###############################################################
1441: ###############################################################
1442:
1443: =pod
1444:
1.648 raeburn 1445: =item * &define_excel_formats()
1.180 matthew 1446:
1447: Define some commonly used Excel cell formats.
1448:
1449: Currently supported formats:
1450:
1451: =over 4
1452:
1453: =item header
1454:
1455: =item bold
1456:
1457: =item h1
1458:
1459: =item h2
1460:
1461: =item h3
1462:
1.256 matthew 1463: =item h4
1464:
1465: =item i
1466:
1.180 matthew 1467: =item date
1468:
1469: =back
1470:
1471: Inputs: $workbook
1472:
1473: Returns: $format, a hash reference.
1474:
1475: =cut
1476:
1477: ###############################################################
1478: ###############################################################
1479: sub define_excel_formats {
1480: my ($workbook) = @_;
1481: my $format;
1482: $format->{'header'} = $workbook->add_format(bold => 1,
1483: bottom => 1,
1484: align => 'center');
1485: $format->{'bold'} = $workbook->add_format(bold=>1);
1486: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1487: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1488: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1489: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1490: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1491: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1492: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1493: return $format;
1494: }
1495:
1496: ###############################################################
1497: ###############################################################
1.113 bowersj2 1498:
1499: =pod
1500:
1.648 raeburn 1501: =item * &create_workbook()
1.255 matthew 1502:
1503: Create an Excel worksheet. If it fails, output message on the
1504: request object and return undefs.
1505:
1506: Inputs: Apache request object
1507:
1508: Returns (undef) on failure,
1509: Excel worksheet object, scalar with filename, and formats
1510: from &Apache::loncommon::define_excel_formats on success
1511:
1512: =cut
1513:
1514: ###############################################################
1515: ###############################################################
1516: sub create_workbook {
1517: my ($r) = @_;
1518: #
1519: # Create the excel spreadsheet
1520: my $filename = '/prtspool/'.
1.258 albertel 1521: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1522: time.'_'.rand(1000000000).'.xls';
1523: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1524: if (! defined($workbook)) {
1525: $r->log_error("Error creating excel spreadsheet $filename: $!");
1526: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1527: "This error has been logged. ".
1528: "Please alert your LON-CAPA administrator").
1529: '</p>');
1530: return (undef);
1531: }
1532: #
1533: $workbook->set_tempdir('/home/httpd/perl/tmp');
1534: #
1535: my $format = &Apache::loncommon::define_excel_formats($workbook);
1536: return ($workbook,$filename,$format);
1537: }
1538:
1539: ###############################################################
1540: ###############################################################
1541:
1542: =pod
1543:
1.648 raeburn 1544: =item * &create_text_file()
1.113 bowersj2 1545:
1.542 raeburn 1546: Create a file to write to and eventually make available to the user.
1.256 matthew 1547: If file creation fails, outputs an error message on the request object and
1548: return undefs.
1.113 bowersj2 1549:
1.256 matthew 1550: Inputs: Apache request object, and file suffix
1.113 bowersj2 1551:
1.256 matthew 1552: Returns (undef) on failure,
1553: Filehandle and filename on success.
1.113 bowersj2 1554:
1555: =cut
1556:
1.256 matthew 1557: ###############################################################
1558: ###############################################################
1559: sub create_text_file {
1560: my ($r,$suffix) = @_;
1561: if (! defined($suffix)) { $suffix = 'txt'; };
1562: my $fh;
1563: my $filename = '/prtspool/'.
1.258 albertel 1564: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1565: time.'_'.rand(1000000000).'.'.$suffix;
1566: $fh = Apache::File->new('>/home/httpd'.$filename);
1567: if (! defined($fh)) {
1568: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1569: $r->print(&mt('Problems occurred in creating the output file. '
1570: .'This error has been logged. '
1571: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1572: }
1.256 matthew 1573: return ($fh,$filename)
1.113 bowersj2 1574: }
1575:
1576:
1.256 matthew 1577: =pod
1.113 bowersj2 1578:
1579: =back
1580:
1581: =cut
1.37 matthew 1582:
1583: ###############################################################
1.33 matthew 1584: ## Home server <option> list generating code ##
1585: ###############################################################
1.35 matthew 1586:
1.169 www 1587: # ------------------------------------------
1588:
1589: sub domain_select {
1590: my ($name,$value,$multiple)=@_;
1591: my %domains=map {
1.514 albertel 1592: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1593: } &Apache::lonnet::all_domains();
1.169 www 1594: if ($multiple) {
1595: $domains{''}=&mt('Any domain');
1.550 albertel 1596: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1597: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1598: } else {
1.550 albertel 1599: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1600: return &select_form($name,$value,%domains);
1601: }
1602: }
1603:
1.282 albertel 1604: #-------------------------------------------
1605:
1606: =pod
1607:
1.519 raeburn 1608: =head1 Routines for form select boxes
1609:
1610: =over 4
1611:
1.648 raeburn 1612: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1613:
1614: Returns a string containing a <select> element int multiple mode
1615:
1616:
1617: Args:
1618: $name - name of the <select> element
1.506 raeburn 1619: $value - scalar or array ref of values that should already be selected
1.282 albertel 1620: $size - number of rows long the select element is
1.283 albertel 1621: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1622: (shown text should already have been &mt())
1.506 raeburn 1623: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1624:
1.282 albertel 1625: =cut
1626:
1627: #-------------------------------------------
1.169 www 1628: sub multiple_select_form {
1.284 albertel 1629: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1630: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1631: my $output='';
1.191 matthew 1632: if (! defined($size)) {
1633: $size = 4;
1.283 albertel 1634: if (scalar(keys(%$hash))<4) {
1635: $size = scalar(keys(%$hash));
1.191 matthew 1636: }
1637: }
1.169 www 1638: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501 banghart 1639: my @order;
1.506 raeburn 1640: if (ref($order) eq 'ARRAY') {
1641: @order = @{$order};
1642: } else {
1643: @order = sort(keys(%$hash));
1.501 banghart 1644: }
1645: if (exists($$hash{'select_form_order'})) {
1646: @order = @{$$hash{'select_form_order'}};
1647: }
1648:
1.284 albertel 1649: foreach my $key (@order) {
1.356 albertel 1650: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1651: $output.='selected="selected" ' if ($selected{$key});
1652: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1653: }
1654: $output.="</select>\n";
1655: return $output;
1656: }
1657:
1.88 www 1658: #-------------------------------------------
1659:
1660: =pod
1661:
1.648 raeburn 1662: =item * &select_form($defdom,$name,%hash)
1.88 www 1663:
1664: Returns a string containing a <select name='$name' size='1'> form to
1665: allow a user to select options from a hash option_name => displayed text.
1666: See lonrights.pm for an example invocation and use.
1667:
1668: =cut
1669:
1670: #-------------------------------------------
1671: sub select_form {
1672: my ($def,$name,%hash) = @_;
1673: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1674: my @keys;
1675: if (exists($hash{'select_form_order'})) {
1676: @keys=@{$hash{'select_form_order'}};
1677: } else {
1678: @keys=sort(keys(%hash));
1679: }
1.356 albertel 1680: foreach my $key (@keys) {
1681: $selectform.=
1682: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1683: ($key eq $def ? 'selected="selected" ' : '').
1684: ">".&mt($hash{$key})."</option>\n";
1.88 www 1685: }
1686: $selectform.="</select>";
1687: return $selectform;
1688: }
1689:
1.475 www 1690: # For display filters
1691:
1692: sub display_filter {
1693: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1694: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475 www 1695: return '<nobr><label>'.&mt('Records [_1]',
1696: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1697: (&mt('all'),10,20,50,100,1000,10000))).
1.478 www 1698: '</label></nobr> <nobr>'.
1.475 www 1699: &mt('Filter [_1]',
1.477 www 1700: &select_form($env{'form.displayfilter'},
1701: 'displayfilter',
1702: ('currentfolder' => 'Current folder/page',
1703: 'containing' => 'Containing phrase',
1704: 'none' => 'None'))).
1.478 www 1705: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475 www 1706: }
1707:
1.167 www 1708: sub gradeleveldescription {
1709: my $gradelevel=shift;
1710: my %gradelevels=(0 => 'Not specified',
1711: 1 => 'Grade 1',
1712: 2 => 'Grade 2',
1713: 3 => 'Grade 3',
1714: 4 => 'Grade 4',
1715: 5 => 'Grade 5',
1716: 6 => 'Grade 6',
1717: 7 => 'Grade 7',
1718: 8 => 'Grade 8',
1719: 9 => 'Grade 9',
1720: 10 => 'Grade 10',
1721: 11 => 'Grade 11',
1722: 12 => 'Grade 12',
1723: 13 => 'Grade 13',
1724: 14 => '100 Level',
1725: 15 => '200 Level',
1726: 16 => '300 Level',
1727: 17 => '400 Level',
1728: 18 => 'Graduate Level');
1729: return &mt($gradelevels{$gradelevel});
1730: }
1731:
1.163 www 1732: sub select_level_form {
1733: my ($deflevel,$name)=@_;
1734: unless ($deflevel) { $deflevel=0; }
1.167 www 1735: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1736: for (my $i=0; $i<=18; $i++) {
1737: $selectform.="<option value=\"$i\" ".
1.253 albertel 1738: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1739: ">".&gradeleveldescription($i)."</option>\n";
1740: }
1741: $selectform.="</select>";
1742: return $selectform;
1.163 www 1743: }
1.167 www 1744:
1.35 matthew 1745: #-------------------------------------------
1746:
1.45 matthew 1747: =pod
1748:
1.692.2.13! raeburn 1749: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$change)
1.35 matthew 1750:
1751: Returns a string containing a <select name='$name' size='1'> form to
1752: allow a user to select the domain to preform an operation in.
1753: See loncreateuser.pm for an example invocation and use.
1754:
1.90 www 1755: If the $includeempty flag is set, it also includes an empty choice ("no domain
1756: selected");
1757:
1.692.2.13! raeburn 1758: If the $showdomdesc flag is set, the domain name is followed by the domain description.
! 1759:
! 1760: 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 1761:
1.35 matthew 1762: =cut
1763:
1764: #-------------------------------------------
1.34 matthew 1765: sub select_dom_form {
1.692.2.13! raeburn 1766: my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
! 1767: if ($onchange) {
! 1768: $onchange = ' onchange="'.$onchange.'"';
! 1769: }
1.550 albertel 1770: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1771: if ($includeempty) { @domains=('',@domains); }
1.692.2.13! raeburn 1772: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1773: foreach my $dom (@domains) {
1774: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1775: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1776: if ($showdomdesc) {
1777: if ($dom ne '') {
1778: my $domdesc = &Apache::lonnet::domain($dom,'description');
1779: if ($domdesc ne '') {
1780: $selectdomain .= ' ('.$domdesc.')';
1781: }
1782: }
1783: }
1784: $selectdomain .= "</option>\n";
1.34 matthew 1785: }
1786: $selectdomain.="</select>";
1787: return $selectdomain;
1788: }
1789:
1.35 matthew 1790: #-------------------------------------------
1791:
1.45 matthew 1792: =pod
1793:
1.648 raeburn 1794: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1795:
1.586 raeburn 1796: input: 4 arguments (two required, two optional) -
1797: $domain - domain of new user
1798: $name - name of form element
1799: $default - Value of 'default' causes a default item to be first
1800: option, and selected by default.
1801: $hide - Value of 'hide' causes hiding of the name of the server,
1802: if 1 server found, or default, if 0 found.
1.594 raeburn 1803: output: returns 2 items:
1.586 raeburn 1804: (a) form element which contains either:
1805: (i) <select name="$name">
1806: <option value="$hostid1">$hostid $servers{$hostid}</option>
1807: <option value="$hostid2">$hostid $servers{$hostid}</option>
1808: </select>
1809: form item if there are multiple library servers in $domain, or
1810: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1811: if there is only one library server in $domain.
1812:
1813: (b) number of library servers found.
1814:
1815: See loncreateuser.pm for example of use.
1.35 matthew 1816:
1817: =cut
1818:
1819: #-------------------------------------------
1.586 raeburn 1820: sub home_server_form_item {
1821: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1822: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1823: my $result;
1824: my $numlib = keys(%servers);
1825: if ($numlib > 1) {
1826: $result .= '<select name="'.$name.'" />'."\n";
1827: if ($default) {
1828: $result .= '<option value="default" selected>'.&mt('default').
1829: '</option>'."\n";
1830: }
1831: foreach my $hostid (sort(keys(%servers))) {
1832: $result.= '<option value="'.$hostid.'">'.
1833: $hostid.' '.$servers{$hostid}."</option>\n";
1834: }
1835: $result .= '</select>'."\n";
1836: } elsif ($numlib == 1) {
1837: my $hostid;
1838: foreach my $item (keys(%servers)) {
1839: $hostid = $item;
1840: }
1841: $result .= '<input type="hidden" name="'.$name.'" value="'.
1842: $hostid.'" />';
1843: if (!$hide) {
1844: $result .= $hostid.' '.$servers{$hostid};
1845: }
1846: $result .= "\n";
1847: } elsif ($default) {
1848: $result .= '<input type="hidden" name="'.$name.
1849: '" value="default" />';
1850: if (!$hide) {
1851: $result .= &mt('default');
1852: }
1853: $result .= "\n";
1.33 matthew 1854: }
1.586 raeburn 1855: return ($result,$numlib);
1.33 matthew 1856: }
1.112 bowersj2 1857:
1858: =pod
1859:
1.534 albertel 1860: =back
1861:
1.112 bowersj2 1862: =cut
1.87 matthew 1863:
1864: ###############################################################
1.112 bowersj2 1865: ## Decoding User Agent ##
1.87 matthew 1866: ###############################################################
1867:
1868: =pod
1869:
1.112 bowersj2 1870: =head1 Decoding the User Agent
1871:
1872: =over 4
1873:
1874: =item * &decode_user_agent()
1.87 matthew 1875:
1876: Inputs: $r
1877:
1878: Outputs:
1879:
1880: =over 4
1881:
1.112 bowersj2 1882: =item * $httpbrowser
1.87 matthew 1883:
1.112 bowersj2 1884: =item * $clientbrowser
1.87 matthew 1885:
1.112 bowersj2 1886: =item * $clientversion
1.87 matthew 1887:
1.112 bowersj2 1888: =item * $clientmathml
1.87 matthew 1889:
1.112 bowersj2 1890: =item * $clientunicode
1.87 matthew 1891:
1.112 bowersj2 1892: =item * $clientos
1.87 matthew 1893:
1894: =back
1895:
1.157 matthew 1896: =back
1897:
1.87 matthew 1898: =cut
1899:
1900: ###############################################################
1901: ###############################################################
1902: sub decode_user_agent {
1.247 albertel 1903: my ($r)=@_;
1.87 matthew 1904: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1905: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1906: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1907: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1908: my $clientbrowser='unknown';
1909: my $clientversion='0';
1910: my $clientmathml='';
1911: my $clientunicode='0';
1912: for (my $i=0;$i<=$#browsertype;$i++) {
1913: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1914: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1915: $clientbrowser=$bname;
1916: $httpbrowser=~/$vreg/i;
1917: $clientversion=$1;
1918: $clientmathml=($clientversion>=$minv);
1919: $clientunicode=($clientversion>=$univ);
1920: }
1921: }
1922: my $clientos='unknown';
1923: if (($httpbrowser=~/linux/i) ||
1924: ($httpbrowser=~/unix/i) ||
1925: ($httpbrowser=~/ux/i) ||
1926: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1927: if (($httpbrowser=~/vax/i) ||
1928: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1929: if ($httpbrowser=~/next/i) { $clientos='next'; }
1930: if (($httpbrowser=~/mac/i) ||
1931: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1932: if ($httpbrowser=~/win/i) { $clientos='win'; }
1933: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1934: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1935: $clientunicode,$clientos,);
1936: }
1937:
1.32 matthew 1938: ###############################################################
1939: ## Authentication changing form generation subroutines ##
1940: ###############################################################
1941: ##
1942: ## All of the authform_xxxxxxx subroutines take their inputs in a
1943: ## hash, and have reasonable default values.
1944: ##
1945: ## formname = the name given in the <form> tag.
1.35 matthew 1946: #-------------------------------------------
1947:
1.45 matthew 1948: =pod
1949:
1.112 bowersj2 1950: =head1 Authentication Routines
1951:
1952: =over 4
1953:
1.648 raeburn 1954: =item * &authform_xxxxxx()
1.35 matthew 1955:
1956: The authform_xxxxxx subroutines provide javascript and html forms which
1957: handle some of the conveniences required for authentication forms.
1958: This is not an optimal method, but it works.
1959:
1960: =over 4
1961:
1.112 bowersj2 1962: =item * authform_header
1.35 matthew 1963:
1.112 bowersj2 1964: =item * authform_authorwarning
1.35 matthew 1965:
1.112 bowersj2 1966: =item * authform_nochange
1.35 matthew 1967:
1.112 bowersj2 1968: =item * authform_kerberos
1.35 matthew 1969:
1.112 bowersj2 1970: =item * authform_internal
1.35 matthew 1971:
1.112 bowersj2 1972: =item * authform_filesystem
1.35 matthew 1973:
1974: =back
1975:
1.648 raeburn 1976: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1977:
1.35 matthew 1978: =cut
1979:
1980: #-------------------------------------------
1.32 matthew 1981: sub authform_header{
1982: my %in = (
1983: formname => 'cu',
1.80 albertel 1984: kerb_def_dom => '',
1.32 matthew 1985: @_,
1986: );
1987: $in{'formname'} = 'document.' . $in{'formname'};
1988: my $result='';
1.80 albertel 1989:
1990: #---------------------------------------------- Code for upper case translation
1991: my $Javascript_toUpperCase;
1992: unless ($in{kerb_def_dom}) {
1993: $Javascript_toUpperCase =<<"END";
1994: switch (choice) {
1995: case 'krb': currentform.elements[choicearg].value =
1996: currentform.elements[choicearg].value.toUpperCase();
1997: break;
1998: default:
1999: }
2000: END
2001: } else {
2002: $Javascript_toUpperCase = "";
2003: }
2004:
1.165 raeburn 2005: my $radioval = "'nochange'";
1.591 raeburn 2006: if (defined($in{'curr_authtype'})) {
2007: if ($in{'curr_authtype'} ne '') {
2008: $radioval = "'".$in{'curr_authtype'}."arg'";
2009: }
1.174 matthew 2010: }
1.165 raeburn 2011: my $argfield = 'null';
1.591 raeburn 2012: if (defined($in{'mode'})) {
1.165 raeburn 2013: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2014: if (defined($in{'curr_autharg'})) {
2015: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2016: $argfield = "'$in{'curr_autharg'}'";
2017: }
2018: }
2019: }
2020: }
2021:
1.32 matthew 2022: $result.=<<"END";
2023: var current = new Object();
1.165 raeburn 2024: current.radiovalue = $radioval;
2025: current.argfield = $argfield;
1.32 matthew 2026:
2027: function changed_radio(choice,currentform) {
2028: var choicearg = choice + 'arg';
2029: // If a radio button in changed, we need to change the argfield
2030: if (current.radiovalue != choice) {
2031: current.radiovalue = choice;
2032: if (current.argfield != null) {
2033: currentform.elements[current.argfield].value = '';
2034: }
2035: if (choice == 'nochange') {
2036: current.argfield = null;
2037: } else {
2038: current.argfield = choicearg;
2039: switch(choice) {
2040: case 'krb':
2041: currentform.elements[current.argfield].value =
2042: "$in{'kerb_def_dom'}";
2043: break;
2044: default:
2045: break;
2046: }
2047: }
2048: }
2049: return;
2050: }
1.22 www 2051:
1.32 matthew 2052: function changed_text(choice,currentform) {
2053: var choicearg = choice + 'arg';
2054: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2055: $Javascript_toUpperCase
1.32 matthew 2056: // clear old field
2057: if ((current.argfield != choicearg) && (current.argfield != null)) {
2058: currentform.elements[current.argfield].value = '';
2059: }
2060: current.argfield = choicearg;
2061: }
2062: set_auth_radio_buttons(choice,currentform);
2063: return;
1.20 www 2064: }
1.32 matthew 2065:
2066: function set_auth_radio_buttons(newvalue,currentform) {
2067: var i=0;
2068: while (i < currentform.login.length) {
2069: if (currentform.login[i].value == newvalue) { break; }
2070: i++;
2071: }
2072: if (i == currentform.login.length) {
2073: return;
2074: }
2075: current.radiovalue = newvalue;
2076: currentform.login[i].checked = true;
2077: return;
2078: }
2079: END
2080: return $result;
2081: }
2082:
2083: sub authform_authorwarning{
2084: my $result='';
1.144 matthew 2085: $result='<i>'.
2086: &mt('As a general rule, only authors or co-authors should be '.
2087: 'filesystem authenticated '.
2088: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2089: return $result;
2090: }
2091:
2092: sub authform_nochange{
2093: my %in = (
2094: formname => 'document.cu',
2095: kerb_def_dom => 'MSU.EDU',
2096: @_,
2097: );
1.586 raeburn 2098: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2099: my $result;
2100: if (keys(%can_assign) == 0) {
2101: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2102: } else {
2103: $result = '<label>'.&mt('[_1] Do not change login data',
2104: '<input type="radio" name="login" value="nochange" '.
2105: 'checked="checked" onclick="'.
1.281 albertel 2106: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2107: '</label>';
1.586 raeburn 2108: }
1.32 matthew 2109: return $result;
2110: }
2111:
1.591 raeburn 2112: sub authform_kerberos {
1.32 matthew 2113: my %in = (
2114: formname => 'document.cu',
2115: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2116: kerb_def_auth => 'krb4',
1.32 matthew 2117: @_,
2118: );
1.586 raeburn 2119: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2120: $autharg,$jscall);
2121: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2122: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2123: $check5 = ' checked="on"';
1.80 albertel 2124: } else {
1.586 raeburn 2125: $check4 = ' checked="on"';
1.80 albertel 2126: }
1.165 raeburn 2127: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2128: if (defined($in{'curr_authtype'})) {
2129: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2130: $krbcheck = ' checked="on"';
1.623 raeburn 2131: if (defined($in{'mode'})) {
2132: if ($in{'mode'} eq 'modifyuser') {
2133: $krbcheck = '';
2134: }
2135: }
1.591 raeburn 2136: if (defined($in{'curr_kerb_ver'})) {
2137: if ($in{'curr_krb_ver'} eq '5') {
2138: $check5 = ' checked="on"';
2139: $check4 = '';
2140: } else {
2141: $check4 = ' checked="on"';
2142: $check5 = '';
2143: }
1.586 raeburn 2144: }
1.591 raeburn 2145: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2146: $krbarg = $in{'curr_autharg'};
2147: }
1.586 raeburn 2148: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2149: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2150: $result =
2151: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2152: $in{'curr_autharg'},$krbver);
2153: } else {
2154: $result =
2155: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2156: }
2157: return $result;
2158: }
2159: }
2160: } else {
2161: if ($authnum == 1) {
2162: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2163: }
2164: }
1.586 raeburn 2165: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2166: return;
1.587 raeburn 2167: } elsif ($authtype eq '') {
1.591 raeburn 2168: if (defined($in{'mode'})) {
1.587 raeburn 2169: if ($in{'mode'} eq 'modifycourse') {
2170: if ($authnum == 1) {
2171: $authtype = '<input type="hidden" name="login" value="krb">';
2172: }
2173: }
2174: }
1.586 raeburn 2175: }
2176: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2177: if ($authtype eq '') {
2178: $authtype = '<input type="radio" name="login" value="krb" '.
2179: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2180: $krbcheck.' />';
2181: }
2182: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2183: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2184: $in{'curr_authtype'} eq 'krb5') ||
2185: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2186: $in{'curr_authtype'} eq 'krb4')) {
2187: $result .= &mt
1.144 matthew 2188: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2189: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2190: '<label>'.$authtype,
1.281 albertel 2191: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2192: 'value="'.$krbarg.'" '.
1.144 matthew 2193: 'onchange="'.$jscall.'" />',
1.281 albertel 2194: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2195: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2196: '</label>');
1.586 raeburn 2197: } elsif ($can_assign{'krb4'}) {
2198: $result .= &mt
2199: ('[_1] Kerberos authenticated with domain [_2] '.
2200: '[_3] Version 4 [_4]',
2201: '<label>'.$authtype,
2202: '</label><input type="text" size="10" name="krbarg" '.
2203: 'value="'.$krbarg.'" '.
2204: 'onchange="'.$jscall.'" />',
2205: '<label><input type="hidden" name="krbver" value="4" />',
2206: '</label>');
2207: } elsif ($can_assign{'krb5'}) {
2208: $result .= &mt
2209: ('[_1] Kerberos authenticated with domain [_2] '.
2210: '[_3] Version 5 [_4]',
2211: '<label>'.$authtype,
2212: '</label><input type="text" size="10" name="krbarg" '.
2213: 'value="'.$krbarg.'" '.
2214: 'onchange="'.$jscall.'" />',
2215: '<label><input type="hidden" name="krbver" value="5" />',
2216: '</label>');
2217: }
1.32 matthew 2218: return $result;
2219: }
2220:
2221: sub authform_internal{
1.586 raeburn 2222: my %in = (
1.32 matthew 2223: formname => 'document.cu',
2224: kerb_def_dom => 'MSU.EDU',
2225: @_,
2226: );
1.586 raeburn 2227: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2228: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2229: if (defined($in{'curr_authtype'})) {
2230: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2231: if ($can_assign{'int'}) {
2232: $intcheck = 'checked="on" ';
1.623 raeburn 2233: if (defined($in{'mode'})) {
2234: if ($in{'mode'} eq 'modifyuser') {
2235: $intcheck = '';
2236: }
2237: }
1.591 raeburn 2238: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2239: $intarg = $in{'curr_autharg'};
2240: }
2241: } else {
2242: $result = &mt('Currently internally authenticated.');
2243: return $result;
1.165 raeburn 2244: }
2245: }
1.586 raeburn 2246: } else {
2247: if ($authnum == 1) {
2248: $authtype = '<input type="hidden" name="login" value="int">';
2249: }
2250: }
2251: if (!$can_assign{'int'}) {
2252: return;
1.587 raeburn 2253: } elsif ($authtype eq '') {
1.591 raeburn 2254: if (defined($in{'mode'})) {
1.587 raeburn 2255: if ($in{'mode'} eq 'modifycourse') {
2256: if ($authnum == 1) {
2257: $authtype = '<input type="hidden" name="login" value="int">';
2258: }
2259: }
2260: }
1.165 raeburn 2261: }
1.586 raeburn 2262: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2263: if ($authtype eq '') {
2264: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2265: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2266: }
1.605 bisitz 2267: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2268: $intarg.'" onchange="'.$jscall.'" />';
2269: $result = &mt
1.144 matthew 2270: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2271: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2272: $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 2273: return $result;
2274: }
2275:
2276: sub authform_local{
2277: my %in = (
2278: formname => 'document.cu',
2279: kerb_def_dom => 'MSU.EDU',
2280: @_,
2281: );
1.586 raeburn 2282: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2283: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2284: if (defined($in{'curr_authtype'})) {
2285: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2286: if ($can_assign{'loc'}) {
2287: $loccheck = 'checked="on" ';
1.623 raeburn 2288: if (defined($in{'mode'})) {
2289: if ($in{'mode'} eq 'modifyuser') {
2290: $loccheck = '';
2291: }
2292: }
1.591 raeburn 2293: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2294: $locarg = $in{'curr_autharg'};
2295: }
2296: } else {
2297: $result = &mt('Currently using local (institutional) authentication.');
2298: return $result;
1.165 raeburn 2299: }
2300: }
1.586 raeburn 2301: } else {
2302: if ($authnum == 1) {
2303: $authtype = '<input type="hidden" name="login" value="loc">';
2304: }
2305: }
2306: if (!$can_assign{'loc'}) {
2307: return;
1.587 raeburn 2308: } elsif ($authtype eq '') {
1.591 raeburn 2309: if (defined($in{'mode'})) {
1.587 raeburn 2310: if ($in{'mode'} eq 'modifycourse') {
2311: if ($authnum == 1) {
2312: $authtype = '<input type="hidden" name="login" value="loc">';
2313: }
2314: }
2315: }
1.165 raeburn 2316: }
1.586 raeburn 2317: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2318: if ($authtype eq '') {
2319: $authtype = '<input type="radio" name="login" value="loc" '.
2320: $loccheck.' onchange="'.$jscall.'" onclick="'.
2321: $jscall.'" />';
2322: }
2323: $autharg = '<input type="text" size="10" name="locarg" value="'.
2324: $locarg.'" onchange="'.$jscall.'" />';
2325: $result = &mt('[_1] Local Authentication with argument [_2]',
2326: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2327: return $result;
2328: }
2329:
2330: sub authform_filesystem{
2331: my %in = (
2332: formname => 'document.cu',
2333: kerb_def_dom => 'MSU.EDU',
2334: @_,
2335: );
1.586 raeburn 2336: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2337: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2338: if (defined($in{'curr_authtype'})) {
2339: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2340: if ($can_assign{'fsys'}) {
2341: $fsyscheck = 'checked="on" ';
1.623 raeburn 2342: if (defined($in{'mode'})) {
2343: if ($in{'mode'} eq 'modifyuser') {
2344: $fsyscheck = '';
2345: }
2346: }
1.586 raeburn 2347: } else {
2348: $result = &mt('Currently Filesystem Authenticated.');
2349: return $result;
2350: }
2351: }
2352: } else {
2353: if ($authnum == 1) {
2354: $authtype = '<input type="hidden" name="login" value="fsys">';
2355: }
2356: }
2357: if (!$can_assign{'fsys'}) {
2358: return;
1.587 raeburn 2359: } elsif ($authtype eq '') {
1.591 raeburn 2360: if (defined($in{'mode'})) {
1.587 raeburn 2361: if ($in{'mode'} eq 'modifycourse') {
2362: if ($authnum == 1) {
2363: $authtype = '<input type="hidden" name="login" value="fsys">';
2364: }
2365: }
2366: }
1.586 raeburn 2367: }
2368: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2369: if ($authtype eq '') {
2370: $authtype = '<input type="radio" name="login" value="fsys" '.
2371: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2372: $jscall.'" />';
2373: }
2374: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2375: ' onchange="'.$jscall.'" />';
2376: $result = &mt
1.144 matthew 2377: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2378: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2379: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2380: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2381: 'onchange="'.$jscall.'" />');
1.32 matthew 2382: return $result;
2383: }
2384:
1.586 raeburn 2385: sub get_assignable_auth {
2386: my ($dom) = @_;
2387: if ($dom eq '') {
2388: $dom = $env{'request.role.domain'};
2389: }
2390: my %can_assign = (
2391: krb4 => 1,
2392: krb5 => 1,
2393: int => 1,
2394: loc => 1,
2395: );
2396: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2397: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2398: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2399: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2400: my $context;
2401: if ($env{'request.role'} =~ /^au/) {
2402: $context = 'author';
2403: } elsif ($env{'request.role'} =~ /^dc/) {
2404: $context = 'domain';
2405: } elsif ($env{'request.course.id'}) {
2406: $context = 'course';
2407: }
2408: if ($context) {
2409: if (ref($authhash->{$context}) eq 'HASH') {
2410: %can_assign = %{$authhash->{$context}};
2411: }
2412: }
2413: }
2414: }
2415: my $authnum = 0;
2416: foreach my $key (keys(%can_assign)) {
2417: if ($can_assign{$key}) {
2418: $authnum ++;
2419: }
2420: }
2421: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2422: $authnum --;
2423: }
2424: return ($authnum,%can_assign);
2425: }
2426:
1.80 albertel 2427: ###############################################################
2428: ## Get Kerberos Defaults for Domain ##
2429: ###############################################################
2430: ##
2431: ## Returns default kerberos version and an associated argument
2432: ## as listed in file domain.tab. If not listed, provides
2433: ## appropriate default domain and kerberos version.
2434: ##
2435: #-------------------------------------------
2436:
2437: =pod
2438:
1.648 raeburn 2439: =item * &get_kerberos_defaults()
1.80 albertel 2440:
2441: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2442: version and domain. If not found, it defaults to version 4 and the
2443: domain of the server.
1.80 albertel 2444:
1.648 raeburn 2445: =over 4
2446:
1.80 albertel 2447: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2448:
1.648 raeburn 2449: =back
2450:
2451: =back
2452:
1.80 albertel 2453: =cut
2454:
2455: #-------------------------------------------
2456: sub get_kerberos_defaults {
2457: my $domain=shift;
1.641 raeburn 2458: my ($krbdef,$krbdefdom);
2459: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2460: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2461: $krbdef = $domdefaults{'auth_def'};
2462: $krbdefdom = $domdefaults{'auth_arg_def'};
2463: } else {
1.80 albertel 2464: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2465: my $krbdefdom=$1;
2466: $krbdefdom=~tr/a-z/A-Z/;
2467: $krbdef = "krb4";
2468: }
2469: return ($krbdef,$krbdefdom);
2470: }
1.112 bowersj2 2471:
1.32 matthew 2472:
1.46 matthew 2473: ###############################################################
2474: ## Thesaurus Functions ##
2475: ###############################################################
1.20 www 2476:
1.46 matthew 2477: =pod
1.20 www 2478:
1.112 bowersj2 2479: =head1 Thesaurus Functions
2480:
2481: =over 4
2482:
1.648 raeburn 2483: =item * &initialize_keywords()
1.46 matthew 2484:
2485: Initializes the package variable %Keywords if it is empty. Uses the
2486: package variable $thesaurus_db_file.
2487:
2488: =cut
2489:
2490: ###################################################
2491:
2492: sub initialize_keywords {
2493: return 1 if (scalar keys(%Keywords));
2494: # If we are here, %Keywords is empty, so fill it up
2495: # Make sure the file we need exists...
2496: if (! -e $thesaurus_db_file) {
2497: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2498: " failed because it does not exist");
2499: return 0;
2500: }
2501: # Set up the hash as a database
2502: my %thesaurus_db;
2503: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2504: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2505: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2506: $thesaurus_db_file);
2507: return 0;
2508: }
2509: # Get the average number of appearances of a word.
2510: my $avecount = $thesaurus_db{'average.count'};
2511: # Put keywords (those that appear > average) into %Keywords
2512: while (my ($word,$data)=each (%thesaurus_db)) {
2513: my ($count,undef) = split /:/,$data;
2514: $Keywords{$word}++ if ($count > $avecount);
2515: }
2516: untie %thesaurus_db;
2517: # Remove special values from %Keywords.
1.356 albertel 2518: foreach my $value ('total.count','average.count') {
2519: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2520: }
1.46 matthew 2521: return 1;
2522: }
2523:
2524: ###################################################
2525:
2526: =pod
2527:
1.648 raeburn 2528: =item * &keyword($word)
1.46 matthew 2529:
2530: Returns true if $word is a keyword. A keyword is a word that appears more
2531: than the average number of times in the thesaurus database. Calls
2532: &initialize_keywords
2533:
2534: =cut
2535:
2536: ###################################################
1.20 www 2537:
2538: sub keyword {
1.46 matthew 2539: return if (!&initialize_keywords());
2540: my $word=lc(shift());
2541: $word=~s/\W//g;
2542: return exists($Keywords{$word});
1.20 www 2543: }
1.46 matthew 2544:
2545: ###############################################################
2546:
2547: =pod
1.20 www 2548:
1.648 raeburn 2549: =item * &get_related_words()
1.46 matthew 2550:
1.160 matthew 2551: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2552: an array of words. If the keyword is not in the thesaurus, an empty array
2553: will be returned. The order of the words returned is determined by the
2554: database which holds them.
2555:
2556: Uses global $thesaurus_db_file.
2557:
2558: =cut
2559:
2560: ###############################################################
2561: sub get_related_words {
2562: my $keyword = shift;
2563: my %thesaurus_db;
2564: if (! -e $thesaurus_db_file) {
2565: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2566: "failed because the file does not exist");
2567: return ();
2568: }
2569: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2570: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2571: return ();
2572: }
2573: my @Words=();
1.429 www 2574: my $count=0;
1.46 matthew 2575: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2576: # The first element is the number of times
2577: # the word appears. We do not need it now.
1.429 www 2578: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2579: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2580: my $threshold=$mostfrequentcount/10;
2581: foreach my $possibleword (@RelatedWords) {
2582: my ($word,$wordcount)=split(/\,/,$possibleword);
2583: if ($wordcount>$threshold) {
2584: push(@Words,$word);
2585: $count++;
2586: if ($count>10) { last; }
2587: }
1.20 www 2588: }
2589: }
1.46 matthew 2590: untie %thesaurus_db;
2591: return @Words;
1.14 harris41 2592: }
1.46 matthew 2593:
1.112 bowersj2 2594: =pod
2595:
2596: =back
2597:
2598: =cut
1.61 www 2599:
2600: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2601: =pod
2602:
1.112 bowersj2 2603: =head1 User Name Functions
2604:
2605: =over 4
2606:
1.648 raeburn 2607: =item * &plainname($uname,$udom,$first)
1.81 albertel 2608:
1.112 bowersj2 2609: Takes a users logon name and returns it as a string in
1.226 albertel 2610: "first middle last generation" form
2611: if $first is set to 'lastname' then it returns it as
2612: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2613:
2614: =cut
1.61 www 2615:
1.295 www 2616:
1.81 albertel 2617: ###############################################################
1.61 www 2618: sub plainname {
1.226 albertel 2619: my ($uname,$udom,$first)=@_;
1.537 albertel 2620: return if (!defined($uname) || !defined($udom));
1.295 www 2621: my %names=&getnames($uname,$udom);
1.226 albertel 2622: my $name=&Apache::lonnet::format_name($names{'firstname'},
2623: $names{'middlename'},
2624: $names{'lastname'},
2625: $names{'generation'},$first);
2626: $name=~s/^\s+//;
1.62 www 2627: $name=~s/\s+$//;
2628: $name=~s/\s+/ /g;
1.353 albertel 2629: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2630: return $name;
1.61 www 2631: }
1.66 www 2632:
2633: # -------------------------------------------------------------------- Nickname
1.81 albertel 2634: =pod
2635:
1.648 raeburn 2636: =item * &nickname($uname,$udom)
1.81 albertel 2637:
2638: Gets a users name and returns it as a string as
2639:
2640: ""nickname""
1.66 www 2641:
1.81 albertel 2642: if the user has a nickname or
2643:
2644: "first middle last generation"
2645:
2646: if the user does not
2647:
2648: =cut
1.66 www 2649:
2650: sub nickname {
2651: my ($uname,$udom)=@_;
1.537 albertel 2652: return if (!defined($uname) || !defined($udom));
1.295 www 2653: my %names=&getnames($uname,$udom);
1.68 albertel 2654: my $name=$names{'nickname'};
1.66 www 2655: if ($name) {
2656: $name='"'.$name.'"';
2657: } else {
2658: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2659: $names{'lastname'}.' '.$names{'generation'};
2660: $name=~s/\s+$//;
2661: $name=~s/\s+/ /g;
2662: }
2663: return $name;
2664: }
2665:
1.295 www 2666: sub getnames {
2667: my ($uname,$udom)=@_;
1.537 albertel 2668: return if (!defined($uname) || !defined($udom));
1.433 albertel 2669: if ($udom eq 'public' && $uname eq 'public') {
2670: return ('lastname' => &mt('Public'));
2671: }
1.295 www 2672: my $id=$uname.':'.$udom;
2673: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2674: if ($cached) {
2675: return %{$names};
2676: } else {
2677: my %loadnames=&Apache::lonnet::get('environment',
2678: ['firstname','middlename','lastname','generation','nickname'],
2679: $udom,$uname);
2680: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2681: return %loadnames;
2682: }
2683: }
1.61 www 2684:
1.542 raeburn 2685: # -------------------------------------------------------------------- getemails
1.648 raeburn 2686:
1.542 raeburn 2687: =pod
2688:
1.648 raeburn 2689: =item * &getemails($uname,$udom)
1.542 raeburn 2690:
2691: Gets a user's email information and returns it as a hash with keys:
2692: notification, critnotification, permanentemail
2693:
2694: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2695: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2696:
1.648 raeburn 2697:
1.542 raeburn 2698: =cut
2699:
1.648 raeburn 2700:
1.466 albertel 2701: sub getemails {
2702: my ($uname,$udom)=@_;
2703: if ($udom eq 'public' && $uname eq 'public') {
2704: return;
2705: }
1.467 www 2706: if (!$udom) { $udom=$env{'user.domain'}; }
2707: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2708: my $id=$uname.':'.$udom;
2709: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2710: if ($cached) {
2711: return %{$names};
2712: } else {
2713: my %loadnames=&Apache::lonnet::get('environment',
2714: ['notification','critnotification',
2715: 'permanentemail'],
2716: $udom,$uname);
2717: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2718: return %loadnames;
2719: }
2720: }
2721:
1.551 albertel 2722: sub flush_email_cache {
2723: my ($uname,$udom)=@_;
2724: if (!$udom) { $udom =$env{'user.domain'}; }
2725: if (!$uname) { $uname=$env{'user.name'}; }
2726: return if ($udom eq 'public' && $uname eq 'public');
2727: my $id=$uname.':'.$udom;
2728: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2729: }
2730:
1.692.2.9 raeburn 2731: # -------------------------------------------------------------------- getlangs
2732:
2733: =pod
2734:
2735: =item * &getlangs($uname,$udom)
2736:
2737: Gets a user's language preference and returns it as a hash with key:
2738: language.
2739:
2740: =cut
2741:
2742: sub getlangs {
2743: my ($uname,$udom) = @_;
2744: if (!$udom) { $udom =$env{'user.domain'}; }
2745: if (!$uname) { $uname=$env{'user.name'}; }
2746: my $id=$uname.':'.$udom;
2747: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2748: if ($cached) {
2749: return %{$langs};
2750: } else {
2751: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2752: $udom,$uname);
2753: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2754: return %loadlangs;
2755: }
2756: }
2757:
2758: sub flush_langs_cache {
2759: my ($uname,$udom)=@_;
2760: if (!$udom) { $udom =$env{'user.domain'}; }
2761: if (!$uname) { $uname=$env{'user.name'}; }
2762: return if ($udom eq 'public' && $uname eq 'public');
2763: my $id=$uname.':'.$udom;
2764: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2765: }
2766:
1.61 www 2767: # ------------------------------------------------------------------ Screenname
1.81 albertel 2768:
2769: =pod
2770:
1.648 raeburn 2771: =item * &screenname($uname,$udom)
1.81 albertel 2772:
2773: Gets a users screenname and returns it as a string
2774:
2775: =cut
1.61 www 2776:
2777: sub screenname {
2778: my ($uname,$udom)=@_;
1.258 albertel 2779: if ($uname eq $env{'user.name'} &&
2780: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2781: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2782: return $names{'screenname'};
1.62 www 2783: }
2784:
1.212 albertel 2785:
1.62 www 2786: # ------------------------------------------------------------- Message Wrapper
2787:
2788: sub messagewrapper {
1.369 www 2789: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2790: return
1.441 albertel 2791: '<a href="/adm/email?compose=individual&'.
2792: 'recname='.$username.'&recdom='.$domain.
2793: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2794: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2795: }
2796: # --------------------------------------------------------------- Notes Wrapper
2797:
2798: sub noteswrapper {
2799: my ($link,$un,$do)=@_;
2800: return
2801: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2802: }
2803: # ------------------------------------------------------------- Aboutme Wrapper
2804:
2805: sub aboutmewrapper {
1.166 www 2806: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2807: if (!defined($username) && !defined($domain)) {
2808: return;
2809: }
1.205 www 2810: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2811: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2812: }
2813:
2814: # ------------------------------------------------------------ Syllabus Wrapper
2815:
2816:
2817: sub syllabuswrapper {
1.109 matthew 2818: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2819: if ($fontcolor) {
2820: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2821: }
1.208 matthew 2822: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2823: }
1.14 harris41 2824:
1.208 matthew 2825: sub track_student_link {
1.268 albertel 2826: my ($linktext,$sname,$sdom,$target,$start) = @_;
2827: my $link ="/adm/trackstudent?";
1.208 matthew 2828: my $title = 'View recent activity';
2829: if (defined($sname) && $sname !~ /^\s*$/ &&
2830: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2831: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2832: $title .= ' of this student';
1.268 albertel 2833: }
1.208 matthew 2834: if (defined($target) && $target !~ /^\s*$/) {
2835: $target = qq{target="$target"};
2836: } else {
2837: $target = '';
2838: }
1.268 albertel 2839: if ($start) { $link.='&start='.$start; }
1.554 albertel 2840: $title = &mt($title);
2841: $linktext = &mt($linktext);
1.448 albertel 2842: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2843: &help_open_topic('View_recent_activity');
1.208 matthew 2844: }
2845:
1.508 www 2846: # ===================================================== Display a student photo
2847:
2848:
1.509 albertel 2849: sub student_image_tag {
1.508 www 2850: my ($domain,$user)=@_;
2851: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2852: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2853: return '<img src="'.$imgsrc.'" align="right" />';
2854: } else {
2855: return '';
2856: }
2857: }
2858:
1.112 bowersj2 2859: =pod
2860:
2861: =back
2862:
2863: =head1 Access .tab File Data
2864:
2865: =over 4
2866:
1.648 raeburn 2867: =item * &languageids()
1.112 bowersj2 2868:
2869: returns list of all language ids
2870:
2871: =cut
2872:
1.14 harris41 2873: sub languageids {
1.16 harris41 2874: return sort(keys(%language));
1.14 harris41 2875: }
2876:
1.112 bowersj2 2877: =pod
2878:
1.648 raeburn 2879: =item * &languagedescription()
1.112 bowersj2 2880:
2881: returns description of a specified language id
2882:
2883: =cut
2884:
1.14 harris41 2885: sub languagedescription {
1.125 www 2886: my $code=shift;
2887: return ($supported_language{$code}?'* ':'').
2888: $language{$code}.
1.126 www 2889: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2890: }
2891:
2892: sub plainlanguagedescription {
2893: my $code=shift;
2894: return $language{$code};
2895: }
2896:
2897: sub supportedlanguagecode {
2898: my $code=shift;
2899: return $supported_language{$code};
1.97 www 2900: }
2901:
1.112 bowersj2 2902: =pod
2903:
1.648 raeburn 2904: =item * ©rightids()
1.112 bowersj2 2905:
2906: returns list of all copyrights
2907:
2908: =cut
2909:
2910: sub copyrightids {
2911: return sort(keys(%cprtag));
2912: }
2913:
2914: =pod
2915:
1.648 raeburn 2916: =item * ©rightdescription()
1.112 bowersj2 2917:
2918: returns description of a specified copyright id
2919:
2920: =cut
2921:
2922: sub copyrightdescription {
1.166 www 2923: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2924: }
1.197 matthew 2925:
2926: =pod
2927:
1.648 raeburn 2928: =item * &source_copyrightids()
1.192 taceyjo1 2929:
2930: returns list of all source copyrights
2931:
2932: =cut
2933:
2934: sub source_copyrightids {
2935: return sort(keys(%scprtag));
2936: }
2937:
2938: =pod
2939:
1.648 raeburn 2940: =item * &source_copyrightdescription()
1.192 taceyjo1 2941:
2942: returns description of a specified source copyright id
2943:
2944: =cut
2945:
2946: sub source_copyrightdescription {
2947: return &mt($scprtag{shift(@_)});
2948: }
1.112 bowersj2 2949:
2950: =pod
2951:
1.648 raeburn 2952: =item * &filecategories()
1.112 bowersj2 2953:
2954: returns list of all file categories
2955:
2956: =cut
2957:
2958: sub filecategories {
2959: return sort(keys(%category_extensions));
2960: }
2961:
2962: =pod
2963:
1.648 raeburn 2964: =item * &filecategorytypes()
1.112 bowersj2 2965:
2966: returns list of file types belonging to a given file
2967: category
2968:
2969: =cut
2970:
2971: sub filecategorytypes {
1.356 albertel 2972: my ($cat) = @_;
2973: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2974: }
2975:
2976: =pod
2977:
1.648 raeburn 2978: =item * &fileembstyle()
1.112 bowersj2 2979:
2980: returns embedding style for a specified file type
2981:
2982: =cut
2983:
2984: sub fileembstyle {
2985: return $fe{lc(shift(@_))};
1.169 www 2986: }
2987:
1.351 www 2988: sub filemimetype {
2989: return $fm{lc(shift(@_))};
2990: }
2991:
1.169 www 2992:
2993: sub filecategoryselect {
2994: my ($name,$value)=@_;
1.189 matthew 2995: return &select_form($value,$name,
1.169 www 2996: '' => &mt('Any category'),
2997: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2998: }
2999:
3000: =pod
3001:
1.648 raeburn 3002: =item * &filedescription()
1.112 bowersj2 3003:
3004: returns description for a specified file type
3005:
3006: =cut
3007:
3008: sub filedescription {
1.188 matthew 3009: my $file_description = $fd{lc(shift())};
3010: $file_description =~ s:([\[\]]):~$1:g;
3011: return &mt($file_description);
1.112 bowersj2 3012: }
3013:
3014: =pod
3015:
1.648 raeburn 3016: =item * &filedescriptionex()
1.112 bowersj2 3017:
3018: returns description for a specified file type with
3019: extra formatting
3020:
3021: =cut
3022:
3023: sub filedescriptionex {
3024: my $ex=shift;
1.188 matthew 3025: my $file_description = $fd{lc($ex)};
3026: $file_description =~ s:([\[\]]):~$1:g;
3027: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3028: }
3029:
3030: # End of .tab access
3031: =pod
3032:
3033: =back
3034:
3035: =cut
3036:
3037: # ------------------------------------------------------------------ File Types
3038: sub fileextensions {
3039: return sort(keys(%fe));
3040: }
3041:
1.97 www 3042: # ----------------------------------------------------------- Display Languages
3043: # returns a hash with all desired display languages
3044: #
3045:
3046: sub display_languages {
3047: my %languages=();
1.692.2.1 raeburn 3048: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3049: $languages{$lang}=1;
1.97 www 3050: }
3051: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3052: if ($env{'form.displaylanguage'}) {
1.356 albertel 3053: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3054: $languages{$lang}=1;
1.97 www 3055: }
3056: }
3057: return %languages;
1.14 harris41 3058: }
3059:
1.582 albertel 3060: sub languages {
3061: my ($possible_langs) = @_;
1.692.2.1 raeburn 3062: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3063: if (!ref($possible_langs)) {
3064: if( wantarray ) {
3065: return @preferred_langs;
3066: } else {
3067: return $preferred_langs[0];
3068: }
3069: }
3070: my %possibilities = map { $_ => 1 } (@$possible_langs);
3071: my @preferred_possibilities;
3072: foreach my $preferred_lang (@preferred_langs) {
3073: if (exists($possibilities{$preferred_lang})) {
3074: push(@preferred_possibilities, $preferred_lang);
3075: }
3076: }
3077: if( wantarray ) {
3078: return @preferred_possibilities;
3079: }
3080: return $preferred_possibilities[0];
3081: }
3082:
1.112 bowersj2 3083: ###############################################################
3084: ## Student Answer Attempts ##
3085: ###############################################################
3086:
3087: =pod
3088:
3089: =head1 Alternate Problem Views
3090:
3091: =over 4
3092:
1.648 raeburn 3093: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3094: $getattempt, $regexp, $gradesub)
3095:
3096: Return string with previous attempt on problem. Arguments:
3097:
3098: =over 4
3099:
3100: =item * $symb: Problem, including path
3101:
3102: =item * $username: username of the desired student
3103:
3104: =item * $domain: domain of the desired student
1.14 harris41 3105:
1.112 bowersj2 3106: =item * $course: Course ID
1.14 harris41 3107:
1.112 bowersj2 3108: =item * $getattempt: Leave blank for all attempts, otherwise put
3109: something
1.14 harris41 3110:
1.112 bowersj2 3111: =item * $regexp: if string matches this regexp, the string will be
3112: sent to $gradesub
1.14 harris41 3113:
1.112 bowersj2 3114: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3115:
1.112 bowersj2 3116: =back
1.14 harris41 3117:
1.112 bowersj2 3118: The output string is a table containing all desired attempts, if any.
1.16 harris41 3119:
1.112 bowersj2 3120: =cut
1.1 albertel 3121:
3122: sub get_previous_attempt {
1.43 ng 3123: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3124: my $prevattempts='';
1.43 ng 3125: no strict 'refs';
1.1 albertel 3126: if ($symb) {
1.3 albertel 3127: my (%returnhash)=
3128: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3129: if ($returnhash{'version'}) {
3130: my %lasthash=();
3131: my $version;
3132: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3133: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3134: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3135: }
1.1 albertel 3136: }
1.596 albertel 3137: $prevattempts=&start_data_table().&start_data_table_header_row();
3138: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3139: foreach my $key (sort(keys(%lasthash))) {
3140: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3141: if ($#parts > 0) {
1.31 albertel 3142: my $data=$parts[-1];
3143: pop(@parts);
1.596 albertel 3144: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3145: } else {
1.41 ng 3146: if ($#parts == 0) {
3147: $prevattempts.='<th>'.$parts[0].'</th>';
3148: } else {
3149: $prevattempts.='<th>'.$ign.'</th>';
3150: }
1.31 albertel 3151: }
1.16 harris41 3152: }
1.596 albertel 3153: $prevattempts.=&end_data_table_header_row();
1.40 ng 3154: if ($getattempt eq '') {
3155: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3156: $prevattempts.=&start_data_table_row().
3157: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3158: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3159: my $value = &format_previous_attempt_value($key,
3160: $returnhash{$version.':'.$key});
3161: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3162: }
1.596 albertel 3163: $prevattempts.=&end_data_table_row();
1.40 ng 3164: }
1.1 albertel 3165: }
1.596 albertel 3166: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3167: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3168: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3169: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3170: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3171: }
1.596 albertel 3172: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3173: } else {
1.596 albertel 3174: $prevattempts=
3175: &start_data_table().&start_data_table_row().
3176: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3177: &end_data_table_row().&end_data_table();
1.1 albertel 3178: }
3179: } else {
1.596 albertel 3180: $prevattempts=
3181: &start_data_table().&start_data_table_row().
3182: '<td>'.&mt('No data.').'</td>'.
3183: &end_data_table_row().&end_data_table();
1.1 albertel 3184: }
1.10 albertel 3185: }
3186:
1.581 albertel 3187: sub format_previous_attempt_value {
3188: my ($key,$value) = @_;
3189: if ($key =~ /timestamp/) {
3190: $value = &Apache::lonlocal::locallocaltime($value);
3191: } elsif (ref($value) eq 'ARRAY') {
3192: $value = '('.join(', ', @{ $value }).')';
3193: } else {
3194: $value = &unescape($value);
3195: }
3196: return $value;
3197: }
3198:
3199:
1.107 albertel 3200: sub relative_to_absolute {
3201: my ($url,$output)=@_;
3202: my $parser=HTML::TokeParser->new(\$output);
3203: my $token;
3204: my $thisdir=$url;
3205: my @rlinks=();
3206: while ($token=$parser->get_token) {
3207: if ($token->[0] eq 'S') {
3208: if ($token->[1] eq 'a') {
3209: if ($token->[2]->{'href'}) {
3210: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3211: }
3212: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3213: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3214: } elsif ($token->[1] eq 'base') {
3215: $thisdir=$token->[2]->{'href'};
3216: }
3217: }
3218: }
3219: $thisdir=~s-/[^/]*$--;
1.356 albertel 3220: foreach my $link (@rlinks) {
1.692.2.8 raeburn 3221: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3222: ($link=~/^\//) ||
3223: ($link=~/^javascript:/i) ||
3224: ($link=~/^mailto:/i) ||
3225: ($link=~/^\#/)) {
3226: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3227: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3228: }
3229: }
3230: # -------------------------------------------------- Deal with Applet codebases
3231: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3232: return $output;
3233: }
3234:
1.112 bowersj2 3235: =pod
3236:
1.648 raeburn 3237: =item * &get_student_view()
1.112 bowersj2 3238:
3239: show a snapshot of what student was looking at
3240:
3241: =cut
3242:
1.10 albertel 3243: sub get_student_view {
1.186 albertel 3244: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3245: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3246: my (%form);
1.10 albertel 3247: my @elements=('symb','courseid','domain','username');
3248: foreach my $element (@elements) {
1.186 albertel 3249: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3250: }
1.186 albertel 3251: if (defined($moreenv)) {
3252: %form=(%form,%{$moreenv});
3253: }
1.236 albertel 3254: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3255: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3256: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3257: $userview=~s/\<body[^\>]*\>//gi;
3258: $userview=~s/\<\/body\>//gi;
3259: $userview=~s/\<html\>//gi;
3260: $userview=~s/\<\/html\>//gi;
3261: $userview=~s/\<head\>//gi;
3262: $userview=~s/\<\/head\>//gi;
3263: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3264: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3265: if (wantarray) {
3266: return ($userview,$response);
3267: } else {
3268: return $userview;
3269: }
3270: }
3271:
3272: sub get_student_view_with_retries {
3273: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3274:
3275: my $ok = 0; # True if we got a good response.
3276: my $content;
3277: my $response;
3278:
3279: # Try to get the student_view done. within the retries count:
3280:
3281: do {
3282: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3283: $ok = $response->is_success;
3284: if (!$ok) {
3285: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3286: }
3287: $retries--;
3288: } while (!$ok && ($retries > 0));
3289:
3290: if (!$ok) {
3291: $content = ''; # On error return an empty content.
3292: }
1.651 www 3293: if (wantarray) {
3294: return ($content, $response);
3295: } else {
3296: return $content;
3297: }
1.11 albertel 3298: }
3299:
1.112 bowersj2 3300: =pod
3301:
1.648 raeburn 3302: =item * &get_student_answers()
1.112 bowersj2 3303:
3304: show a snapshot of how student was answering problem
3305:
3306: =cut
3307:
1.11 albertel 3308: sub get_student_answers {
1.100 sakharuk 3309: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3310: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3311: my (%moreenv);
1.11 albertel 3312: my @elements=('symb','courseid','domain','username');
3313: foreach my $element (@elements) {
1.186 albertel 3314: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3315: }
1.186 albertel 3316: $moreenv{'grade_target'}='answer';
3317: %moreenv=(%form,%moreenv);
1.497 raeburn 3318: $feedurl = &Apache::lonnet::clutter($feedurl);
3319: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3320: return $userview;
1.1 albertel 3321: }
1.116 albertel 3322:
3323: =pod
3324:
3325: =item * &submlink()
3326:
1.242 albertel 3327: Inputs: $text $uname $udom $symb $target
1.116 albertel 3328:
3329: Returns: A link to grades.pm such as to see the SUBM view of a student
3330:
3331: =cut
3332:
3333: ###############################################
3334: sub submlink {
1.242 albertel 3335: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3336: if (!($uname && $udom)) {
3337: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3338: &Apache::lonnet::whichuser($symb);
1.116 albertel 3339: if (!$symb) { $symb=$cursymb; }
3340: }
1.254 matthew 3341: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3342: $symb=&escape($symb);
1.242 albertel 3343: if ($target) { $target="target=\"$target\""; }
3344: return '<a href="/adm/grades?&command=submission&'.
3345: 'symb='.$symb.'&student='.$uname.
3346: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3347: }
3348: ##############################################
3349:
3350: =pod
3351:
3352: =item * &pgrdlink()
3353:
3354: Inputs: $text $uname $udom $symb $target
3355:
3356: Returns: A link to grades.pm such as to see the PGRD view of a student
3357:
3358: =cut
3359:
3360: ###############################################
3361: sub pgrdlink {
3362: my $link=&submlink(@_);
3363: $link=~s/(&command=submission)/$1&showgrading=yes/;
3364: return $link;
3365: }
3366: ##############################################
3367:
3368: =pod
3369:
3370: =item * &pprmlink()
3371:
3372: Inputs: $text $uname $udom $symb $target
3373:
3374: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3375: student and a specific resource
1.242 albertel 3376:
3377: =cut
3378:
3379: ###############################################
3380: sub pprmlink {
3381: my ($text,$uname,$udom,$symb,$target)=@_;
3382: if (!($uname && $udom)) {
3383: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3384: &Apache::lonnet::whichuser($symb);
1.242 albertel 3385: if (!$symb) { $symb=$cursymb; }
3386: }
1.254 matthew 3387: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3388: $symb=&escape($symb);
1.242 albertel 3389: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3390: return '<a href="/adm/parmset?command=set&'.
3391: 'symb='.$symb.'&uname='.$uname.
3392: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3393: }
3394: ##############################################
1.37 matthew 3395:
1.112 bowersj2 3396: =pod
3397:
3398: =back
3399:
3400: =cut
3401:
1.37 matthew 3402: ###############################################
1.51 www 3403:
3404:
3405: sub timehash {
1.687 raeburn 3406: my ($thistime) = @_;
3407: my $timezone = &Apache::lonlocal::gettimezone();
3408: my $dt = DateTime->from_epoch(epoch => $thistime)
3409: ->set_time_zone($timezone);
3410: my $wday = $dt->day_of_week();
3411: if ($wday == 7) { $wday = 0; }
3412: return ( 'second' => $dt->second(),
3413: 'minute' => $dt->minute(),
3414: 'hour' => $dt->hour(),
3415: 'day' => $dt->day_of_month(),
3416: 'month' => $dt->month(),
3417: 'year' => $dt->year(),
3418: 'weekday' => $wday,
3419: 'dayyear' => $dt->day_of_year(),
3420: 'dlsav' => $dt->is_dst() );
1.51 www 3421: }
3422:
1.370 www 3423: sub utc_string {
3424: my ($date)=@_;
1.371 www 3425: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3426: }
3427:
1.51 www 3428: sub maketime {
3429: my %th=@_;
1.687 raeburn 3430: my ($epoch_time,$timezone,$dt);
3431: $timezone = &Apache::lonlocal::gettimezone();
3432: eval {
3433: $dt = DateTime->new( year => $th{'year'},
3434: month => $th{'month'},
3435: day => $th{'day'},
3436: hour => $th{'hour'},
3437: minute => $th{'minute'},
3438: second => $th{'second'},
3439: time_zone => $timezone,
3440: );
3441: };
3442: if (!$@) {
3443: $epoch_time = $dt->epoch;
3444: if ($epoch_time) {
3445: return $epoch_time;
3446: }
3447: }
1.51 www 3448: return POSIX::mktime(
3449: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3450: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3451: }
3452:
3453: #########################################
1.51 www 3454:
3455: sub findallcourses {
1.482 raeburn 3456: my ($roles,$uname,$udom) = @_;
1.355 albertel 3457: my %roles;
3458: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3459: my %courses;
1.51 www 3460: my $now=time;
1.482 raeburn 3461: if (!defined($uname)) {
3462: $uname = $env{'user.name'};
3463: }
3464: if (!defined($udom)) {
3465: $udom = $env{'user.domain'};
3466: }
3467: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3468: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3469: if (!%roles) {
3470: %roles = (
3471: cc => 1,
3472: in => 1,
3473: ep => 1,
3474: ta => 1,
3475: cr => 1,
3476: st => 1,
3477: );
3478: }
3479: foreach my $entry (keys(%roleshash)) {
3480: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3481: if ($trole =~ /^cr/) {
3482: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3483: } else {
3484: next if (!exists($roles{$trole}));
3485: }
3486: if ($tend) {
3487: next if ($tend < $now);
3488: }
3489: if ($tstart) {
3490: next if ($tstart > $now);
3491: }
3492: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3493: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3494: if ($secpart eq '') {
3495: ($cnum,$role) = split(/_/,$cnumpart);
3496: $sec = 'none';
3497: $realsec = '';
3498: } else {
3499: $cnum = $cnumpart;
3500: ($sec,$role) = split(/_/,$secpart);
3501: $realsec = $sec;
1.490 raeburn 3502: }
1.482 raeburn 3503: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3504: }
3505: } else {
3506: foreach my $key (keys(%env)) {
1.483 albertel 3507: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3508: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3509: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3510: next if ($role eq 'ca' || $role eq 'aa');
3511: next if (%roles && !exists($roles{$role}));
3512: my ($starttime,$endtime)=split(/\./,$env{$key});
3513: my $active=1;
3514: if ($starttime) {
3515: if ($now<$starttime) { $active=0; }
3516: }
3517: if ($endtime) {
3518: if ($now>$endtime) { $active=0; }
3519: }
3520: if ($active) {
3521: if ($sec eq '') {
3522: $sec = 'none';
3523: }
3524: $courses{$cdom.'_'.$cnum}{$sec} =
3525: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3526: }
3527: }
1.51 www 3528: }
3529: }
1.474 raeburn 3530: return %courses;
1.51 www 3531: }
1.37 matthew 3532:
1.54 www 3533: ###############################################
1.474 raeburn 3534:
3535: sub blockcheck {
1.482 raeburn 3536: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3537:
3538: if (!defined($udom)) {
3539: $udom = $env{'user.domain'};
3540: }
3541: if (!defined($uname)) {
3542: $uname = $env{'user.name'};
3543: }
3544:
3545: # If uname and udom are for a course, check for blocks in the course.
3546:
3547: if (&Apache::lonnet::is_course($udom,$uname)) {
3548: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3549: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3550: return ($startblock,$endblock);
3551: }
1.474 raeburn 3552:
1.502 raeburn 3553: my $startblock = 0;
3554: my $endblock = 0;
1.482 raeburn 3555: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3556:
1.490 raeburn 3557: # If uname is for a user, and activity is course-specific, i.e.,
3558: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3559:
1.490 raeburn 3560: if (($activity eq 'boards' || $activity eq 'chat' ||
3561: $activity eq 'groups') && ($env{'request.course.id'})) {
3562: foreach my $key (keys(%live_courses)) {
3563: if ($key ne $env{'request.course.id'}) {
3564: delete($live_courses{$key});
3565: }
3566: }
3567: }
3568:
3569: my $otheruser = 0;
3570: my %own_courses;
3571: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3572: # Resource belongs to user other than current user.
3573: $otheruser = 1;
3574: # Gather courses for current user
3575: %own_courses =
3576: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3577: }
3578:
3579: # Gather active course roles - course coordinator, instructor,
3580: # exam proctor, ta, student, or custom role.
1.474 raeburn 3581:
3582: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3583: my ($cdom,$cnum);
3584: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3585: $cdom = $env{'course.'.$course.'.domain'};
3586: $cnum = $env{'course.'.$course.'.num'};
3587: } else {
1.490 raeburn 3588: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3589: }
3590: my $no_ownblock = 0;
3591: my $no_userblock = 0;
1.533 raeburn 3592: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3593: # Check if current user has 'evb' priv for this
3594: if (defined($own_courses{$course})) {
3595: foreach my $sec (keys(%{$own_courses{$course}})) {
3596: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3597: if ($sec ne 'none') {
3598: $checkrole .= '/'.$sec;
3599: }
3600: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3601: $no_ownblock = 1;
3602: last;
3603: }
3604: }
3605: }
3606: # if they have 'evb' priv and are currently not playing student
3607: next if (($no_ownblock) &&
3608: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3609: }
1.474 raeburn 3610: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3611: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3612: if ($sec ne 'none') {
1.482 raeburn 3613: $checkrole .= '/'.$sec;
1.474 raeburn 3614: }
1.490 raeburn 3615: if ($otheruser) {
3616: # Resource belongs to user other than current user.
3617: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3618: my ($trole,$tdom,$tnum,$tsec);
3619: my $entry = $live_courses{$course}{$sec};
3620: if ($entry =~ /^cr/) {
3621: ($trole,$tdom,$tnum,$tsec) =
3622: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3623: } else {
3624: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3625: }
3626: my ($spec,$area,$trest,%allroles,%userroles);
3627: $area = '/'.$tdom.'/'.$tnum;
3628: $trest = $tnum;
3629: if ($tsec ne '') {
3630: $area .= '/'.$tsec;
3631: $trest .= '/'.$tsec;
3632: }
3633: $spec = $trole.'.'.$area;
3634: if ($trole =~ /^cr/) {
3635: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3636: $tdom,$spec,$trest,$area);
3637: } else {
3638: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3639: $tdom,$spec,$trest,$area);
3640: }
3641: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3642: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3643: if ($1) {
3644: $no_userblock = 1;
3645: last;
3646: }
3647: }
1.490 raeburn 3648: } else {
3649: # Resource belongs to current user
3650: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3651: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3652: $no_ownblock = 1;
3653: last;
3654: }
1.474 raeburn 3655: }
3656: }
3657: # if they have the evb priv and are currently not playing student
1.482 raeburn 3658: next if (($no_ownblock) &&
1.491 albertel 3659: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3660: next if ($no_userblock);
1.474 raeburn 3661:
1.490 raeburn 3662: # Retrieve blocking times and identity of blocker for course
3663: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3664:
3665: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3666: if (($start != 0) &&
3667: (($startblock == 0) || ($startblock > $start))) {
3668: $startblock = $start;
3669: }
3670: if (($end != 0) &&
3671: (($endblock == 0) || ($endblock < $end))) {
3672: $endblock = $end;
3673: }
1.490 raeburn 3674: }
3675: return ($startblock,$endblock);
3676: }
3677:
3678: sub get_blocks {
3679: my ($setters,$activity,$cdom,$cnum) = @_;
3680: my $startblock = 0;
3681: my $endblock = 0;
3682: my $course = $cdom.'_'.$cnum;
3683: $setters->{$course} = {};
3684: $setters->{$course}{'staff'} = [];
3685: $setters->{$course}{'times'} = [];
3686: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3687: foreach my $record (keys(%records)) {
3688: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3689: if ($start <= time && $end >= time) {
3690: my ($staff_name,$staff_dom,$title,$blocks) =
3691: &parse_block_record($records{$record});
3692: if ($blocks->{$activity} eq 'on') {
3693: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3694: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3695: if ( ($startblock == 0) || ($startblock > $start) ) {
3696: $startblock = $start;
1.490 raeburn 3697: }
1.491 albertel 3698: if ( ($endblock == 0) || ($endblock < $end) ) {
3699: $endblock = $end;
1.474 raeburn 3700: }
3701: }
3702: }
3703: }
3704: return ($startblock,$endblock);
3705: }
3706:
3707: sub parse_block_record {
3708: my ($record) = @_;
3709: my ($setuname,$setudom,$title,$blocks);
3710: if (ref($record) eq 'HASH') {
3711: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3712: $title = &unescape($record->{'event'});
3713: $blocks = $record->{'blocks'};
3714: } else {
3715: my @data = split(/:/,$record,3);
3716: if (scalar(@data) eq 2) {
3717: $title = $data[1];
3718: ($setuname,$setudom) = split(/@/,$data[0]);
3719: } else {
3720: ($setuname,$setudom,$title) = @data;
3721: }
3722: $blocks = { 'com' => 'on' };
3723: }
3724: return ($setuname,$setudom,$title,$blocks);
3725: }
3726:
3727: sub build_block_table {
3728: my ($startblock,$endblock,$setters) = @_;
3729: my %lt = &Apache::lonlocal::texthash(
3730: 'cacb' => 'Currently active communication blocks',
3731: 'cour' => 'Course',
3732: 'dura' => 'Duration',
3733: 'blse' => 'Block set by'
3734: );
3735: my $output;
1.476 raeburn 3736: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3737: $output .= &start_data_table();
3738: $output .= '
3739: <tr>
3740: <th>'.$lt{'cour'}.'</th>
3741: <th>'.$lt{'dura'}.'</th>
3742: <th>'.$lt{'blse'}.'</th>
3743: </tr>
3744: ';
3745: foreach my $course (keys(%{$setters})) {
3746: my %courseinfo=&Apache::lonnet::coursedescription($course);
3747: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3748: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3749: my $fullname = &plainname($uname,$udom);
3750: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3751: && $env{'user.name'} ne 'public'
3752: && $env{'user.domain'} ne 'public') {
3753: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3754: }
1.474 raeburn 3755: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3756: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3757: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3758: $output .= &Apache::loncommon::start_data_table_row().
3759: '<td>'.$courseinfo{'description'}.'</td>'.
3760: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3761: '<td>'.$fullname.'</td>'.
1.474 raeburn 3762: &Apache::loncommon::end_data_table_row();
3763: }
3764: }
3765: $output .= &end_data_table();
3766: }
3767:
1.490 raeburn 3768: sub blocking_status {
3769: my ($activity,$uname,$udom) = @_;
3770: my %setters;
3771: my ($blocked,$output,$ownitem,$is_course);
3772: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3773: if ($startblock && $endblock) {
3774: $blocked = 1;
3775: if (wantarray) {
3776: my $category;
3777: if ($activity eq 'boards') {
3778: $category = 'Discussion posts in this course';
3779: } elsif ($activity eq 'blogs') {
3780: $category = 'Blogs';
3781: } elsif ($activity eq 'port') {
3782: if (defined($uname) && defined($udom)) {
3783: if ($uname eq $env{'user.name'} &&
3784: $udom eq $env{'user.domain'}) {
3785: $ownitem = 1;
3786: }
3787: }
3788: $is_course = &Apache::lonnet::is_course($udom,$uname);
3789: if ($ownitem) {
3790: $category = 'Your portfolio files';
3791: } elsif ($is_course) {
3792: my $coursedesc;
3793: foreach my $course (keys(%setters)) {
3794: my %courseinfo =
3795: &Apache::lonnet::coursedescription($course);
3796: $coursedesc = $courseinfo{'description'};
3797: }
3798: $category = "Group files in the course '$coursedesc'";
3799: } else {
3800: $category = 'Portfolio files belonging to ';
3801: if ($env{'user.name'} eq 'public' &&
3802: $env{'user.domain'} eq 'public') {
3803: $category .= &plainname($uname,$udom);
3804: } else {
3805: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3806: }
3807: }
3808: } elsif ($activity eq 'groups') {
3809: $category = 'Groups in this course';
3810: }
3811: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3812: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3813: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3814: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3815: $output .= &build_block_table($startblock,$endblock,\%setters);
3816: }
3817: }
3818: }
3819: if (wantarray) {
3820: return ($blocked,$output);
3821: } else {
3822: return $blocked;
3823: }
3824: }
3825:
1.60 matthew 3826: ###############################################
3827:
1.682 raeburn 3828: sub check_ip_acc {
3829: my ($acc)=@_;
3830: &Apache::lonxml::debug("acc is $acc");
3831: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3832: return 1;
3833: }
3834: my $allowed=0;
3835: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3836:
3837: my $name;
3838: foreach my $pattern (split(',',$acc)) {
3839: $pattern =~ s/^\s*//;
3840: $pattern =~ s/\s*$//;
3841: if ($pattern =~ /\*$/) {
3842: #35.8.*
3843: $pattern=~s/\*//;
3844: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3845: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3846: #35.8.3.[34-56]
3847: my $low=$2;
3848: my $high=$3;
3849: $pattern=$1;
3850: if ($ip =~ /^\Q$pattern\E/) {
3851: my $last=(split(/\./,$ip))[3];
3852: if ($last <=$high && $last >=$low) { $allowed=1; }
3853: }
3854: } elsif ($pattern =~ /^\*/) {
3855: #*.msu.edu
3856: $pattern=~s/\*//;
3857: if (!defined($name)) {
3858: use Socket;
3859: my $netaddr=inet_aton($ip);
3860: ($name)=gethostbyaddr($netaddr,AF_INET);
3861: }
3862: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3863: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3864: #127.0.0.1
3865: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3866: } else {
3867: #some.name.com
3868: if (!defined($name)) {
3869: use Socket;
3870: my $netaddr=inet_aton($ip);
3871: ($name)=gethostbyaddr($netaddr,AF_INET);
3872: }
3873: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3874: }
3875: if ($allowed) { last; }
3876: }
3877: return $allowed;
3878: }
3879:
3880: ###############################################
3881:
1.60 matthew 3882: =pod
3883:
1.112 bowersj2 3884: =head1 Domain Template Functions
3885:
3886: =over 4
3887:
3888: =item * &determinedomain()
1.60 matthew 3889:
3890: Inputs: $domain (usually will be undef)
3891:
1.63 www 3892: Returns: Determines which domain should be used for designs
1.60 matthew 3893:
3894: =cut
1.54 www 3895:
1.60 matthew 3896: ###############################################
1.63 www 3897: sub determinedomain {
3898: my $domain=shift;
1.531 albertel 3899: if (! $domain) {
1.60 matthew 3900: # Determine domain if we have not been given one
3901: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3902: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3903: if ($env{'request.role.domain'}) {
3904: $domain=$env{'request.role.domain'};
1.60 matthew 3905: }
3906: }
1.63 www 3907: return $domain;
3908: }
3909: ###############################################
1.517 raeburn 3910:
1.518 albertel 3911: sub devalidate_domconfig_cache {
3912: my ($udom)=@_;
3913: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3914: }
3915:
3916: # ---------------------- Get domain configuration for a domain
3917: sub get_domainconf {
3918: my ($udom) = @_;
3919: my $cachetime=1800;
3920: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3921: if (defined($cached)) { return %{$result}; }
3922:
3923: my %domconfig = &Apache::lonnet::get_dom('configuration',
3924: ['login','rolecolors'],$udom);
1.632 raeburn 3925: my (%designhash,%legacy);
1.518 albertel 3926: if (keys(%domconfig) > 0) {
3927: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3928: if (keys(%{$domconfig{'login'}})) {
3929: foreach my $key (keys(%{$domconfig{'login'}})) {
1.692.2.2 raeburn 3930: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3931: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3932: $designhash{$udom.'.login.'.$key.'_'.$img} =
3933: $domconfig{'login'}{$key}{$img};
3934: }
3935: } else {
3936: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3937: }
1.632 raeburn 3938: }
3939: } else {
3940: $legacy{'login'} = 1;
1.518 albertel 3941: }
1.632 raeburn 3942: } else {
3943: $legacy{'login'} = 1;
1.518 albertel 3944: }
3945: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3946: if (keys(%{$domconfig{'rolecolors'}})) {
3947: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3948: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3949: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3950: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3951: }
1.518 albertel 3952: }
3953: }
1.632 raeburn 3954: } else {
3955: $legacy{'rolecolors'} = 1;
1.518 albertel 3956: }
1.632 raeburn 3957: } else {
3958: $legacy{'rolecolors'} = 1;
1.518 albertel 3959: }
1.632 raeburn 3960: if (keys(%legacy) > 0) {
3961: my %legacyhash = &get_legacy_domconf($udom);
3962: foreach my $item (keys(%legacyhash)) {
3963: if ($item =~ /^\Q$udom\E\.login/) {
3964: if ($legacy{'login'}) {
3965: $designhash{$item} = $legacyhash{$item};
3966: }
3967: } else {
3968: if ($legacy{'rolecolors'}) {
3969: $designhash{$item} = $legacyhash{$item};
3970: }
1.518 albertel 3971: }
3972: }
3973: }
1.632 raeburn 3974: } else {
3975: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3976: }
3977: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3978: $cachetime);
3979: return %designhash;
3980: }
3981:
1.632 raeburn 3982: sub get_legacy_domconf {
3983: my ($udom) = @_;
3984: my %legacyhash;
3985: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
3986: my $designfile = $designdir.'/'.$udom.'.tab';
3987: if (-e $designfile) {
3988: if ( open (my $fh,"<$designfile") ) {
3989: while (my $line = <$fh>) {
3990: next if ($line =~ /^\#/);
3991: chomp($line);
3992: my ($key,$val)=(split(/\=/,$line));
3993: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
3994: }
3995: close($fh);
3996: }
3997: }
3998: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
3999: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4000: }
4001: return %legacyhash;
4002: }
4003:
1.63 www 4004: =pod
4005:
1.112 bowersj2 4006: =item * &domainlogo()
1.63 www 4007:
4008: Inputs: $domain (usually will be undef)
4009:
4010: Returns: A link to a domain logo, if the domain logo exists.
4011: If the domain logo does not exist, a description of the domain.
4012:
4013: =cut
1.112 bowersj2 4014:
1.63 www 4015: ###############################################
4016: sub domainlogo {
1.517 raeburn 4017: my $domain = &determinedomain(shift);
1.518 albertel 4018: my %designhash = &get_domainconf($domain);
1.517 raeburn 4019: # See if there is a logo
4020: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4021: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4022: if ($imgsrc =~ m{^/(adm|res)/}) {
4023: if ($imgsrc =~ m{^/res/}) {
4024: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4025: &Apache::lonnet::repcopy($local_name);
4026: }
4027: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4028: }
4029: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4030: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4031: return &Apache::lonnet::domain($domain,'description');
1.59 www 4032: } else {
1.60 matthew 4033: return '';
1.59 www 4034: }
4035: }
1.63 www 4036: ##############################################
4037:
4038: =pod
4039:
1.112 bowersj2 4040: =item * &designparm()
1.63 www 4041:
4042: Inputs: $which parameter; $domain (usually will be undef)
4043:
4044: Returns: value of designparamter $which
4045:
4046: =cut
1.112 bowersj2 4047:
1.397 albertel 4048:
1.400 albertel 4049: ##############################################
1.397 albertel 4050: sub designparm {
4051: my ($which,$domain)=@_;
1.258 albertel 4052: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4053: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4054: return '#000000';
4055: }
1.635 raeburn 4056: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4057: return '#FFFFFF';
4058: }
4059: if ($which=~/\.tabbg$/) {
4060: return '#CCCCCC';
4061: }
4062: }
1.397 albertel 4063: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4064: return $env{'environment.color.'.$which};
1.96 www 4065: }
1.63 www 4066: $domain=&determinedomain($domain);
1.518 albertel 4067: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4068: my $output;
1.517 raeburn 4069: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4070: $output = $domdesign{$domain.'.'.$which};
1.63 www 4071: } else {
1.520 raeburn 4072: $output = $defaultdesign{$which};
4073: }
4074: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4075: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4076: if ($output =~ m{^/(adm|res)/}) {
4077: if ($output =~ m{^/res/}) {
4078: my $local_name = &Apache::lonnet::filelocation('',$output);
4079: &Apache::lonnet::repcopy($local_name);
4080: }
1.520 raeburn 4081: $output = &lonhttpdurl($output);
4082: }
1.63 www 4083: }
1.520 raeburn 4084: return $output;
1.63 www 4085: }
1.59 www 4086:
1.60 matthew 4087: ###############################################
4088: ###############################################
4089:
4090: =pod
4091:
1.112 bowersj2 4092: =back
4093:
1.549 albertel 4094: =head1 HTML Helpers
1.112 bowersj2 4095:
4096: =over 4
4097:
4098: =item * &bodytag()
1.60 matthew 4099:
4100: Returns a uniform header for LON-CAPA web pages.
4101:
4102: Inputs:
4103:
1.112 bowersj2 4104: =over 4
4105:
4106: =item * $title, A title to be displayed on the page.
4107:
4108: =item * $function, the current role (can be undef).
4109:
4110: =item * $addentries, extra parameters for the <body> tag.
4111:
4112: =item * $bodyonly, if defined, only return the <body> tag.
4113:
4114: =item * $domain, if defined, force a given domain.
4115:
4116: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4117: text interface only)
1.60 matthew 4118:
1.326 albertel 4119: =item * $customtitle, alternate text to use instead of $title
4120: in the title box that appears, this text
4121: is not auto translated like the $title is
1.309 albertel 4122:
4123: =item * $notopbar, if true, keep the 'what is this' info but remove the
4124: navigational links
1.317 albertel 4125:
1.338 albertel 4126: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4127:
4128: =item * $notitle, if true keep the nav controls, but remove the title bar
4129:
1.361 albertel 4130: =item * $no_inline_link, if true and in remote mode, don't show the
4131: 'Switch To Inline Menu' link
4132:
1.460 albertel 4133: =item * $args, optional argument valid values are
4134: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4135: inherit_jsmath -> when creating popup window in a page,
4136: should it have jsmath forced on by the
4137: current page
1.460 albertel 4138:
1.112 bowersj2 4139: =back
4140:
1.60 matthew 4141: Returns: A uniform header for LON-CAPA web pages.
4142: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4143: If $bodyonly is undef or zero, an html string containing a <body> tag and
4144: other decorations will be returned.
4145:
4146: =cut
4147:
1.54 www 4148: sub bodytag {
1.309 albertel 4149: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4150: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4151:
1.460 albertel 4152: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4153:
1.183 matthew 4154: $function = &get_users_function() if (!$function);
1.339 albertel 4155: my $img = &designparm($function.'.img',$domain);
4156: my $font = &designparm($function.'.font',$domain);
4157: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4158:
4159: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4160: 'bgcolor' => $pgbg,
1.339 albertel 4161: 'text' => $font,
4162: 'alink' => &designparm($function.'.alink',$domain),
4163: 'vlink' => &designparm($function.'.vlink',$domain),
4164: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4165: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4166:
1.63 www 4167: # role and realm
1.378 raeburn 4168: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4169: if ($role eq 'ca') {
1.479 albertel 4170: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4171: $realm = &plainname($rname,$rdom);
1.378 raeburn 4172: }
1.55 www 4173: # realm
1.258 albertel 4174: if ($env{'request.course.id'}) {
1.378 raeburn 4175: if ($env{'request.role'} !~ /^cr/) {
4176: $role = &Apache::lonnet::plaintext($role,&course_type());
4177: }
1.359 albertel 4178: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4179: } else {
4180: $role = &Apache::lonnet::plaintext($role);
1.54 www 4181: }
1.433 albertel 4182:
1.359 albertel 4183: if (!$realm) { $realm=' '; }
1.55 www 4184: # Set messages
1.60 matthew 4185: my $messages=&domainlogo($domain);
1.330 albertel 4186:
1.438 albertel 4187: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4188:
1.101 www 4189: # construct main body tag
1.359 albertel 4190: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4191: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4192:
1.530 albertel 4193: if ($bodyonly) {
1.60 matthew 4194: return $bodytag;
1.258 albertel 4195: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4196: # Accessibility
1.224 raeburn 4197:
1.337 albertel 4198: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4199: if (!$notitle) {
1.337 albertel 4200: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4201: }
4202: return $bodytag;
1.359 albertel 4203: }
4204:
1.410 albertel 4205: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4206: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4207: undef($role);
1.434 albertel 4208: } else {
4209: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4210: }
1.359 albertel 4211:
4212: my $roleinfo=(<<ENDROLE);
4213: <td class="LC_title_bar_who">
4214: <div class="LC_title_bar_name">
1.410 albertel 4215: $name
1.361 albertel 4216:
1.359 albertel 4217: </div>
4218: <div class="LC_title_bar_role">
1.361 albertel 4219: $role
1.359 albertel 4220: </div>
4221: <div class="LC_title_bar_realm">
1.361 albertel 4222: $realm
1.359 albertel 4223: </div>
1.206 albertel 4224: </td>
4225: ENDROLE
1.235 raeburn 4226:
1.359 albertel 4227: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4228: if ($customtitle) {
4229: $titleinfo = $customtitle;
4230: }
4231: #
4232: # Extra info if you are the DC
4233: my $dc_info = '';
4234: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4235: $env{'course.'.$env{'request.course.id'}.
4236: '.domain'}.'/'})) {
4237: my $cid = $env{'request.course.id'};
4238: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4239: $dc_info =~ s/\s+$//;
1.359 albertel 4240: $dc_info = '('.$dc_info.')';
4241: }
4242:
1.644 www 4243: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4244: # No Remote
1.258 albertel 4245: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4246: $forcereg=1;
4247: }
4248:
4249: if (!$customtitle && $env{'request.state'} eq 'construct') {
4250: # this is for resources; directories have customtitle, and crumbs
4251: # and select recent are created in lonpubdir.pm
1.229 albertel 4252: my ($uname,$thisdisfn)=
1.258 albertel 4253: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4254: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4255: $formaction=~s/\/+/\//g;
4256:
1.359 albertel 4257: my $parentpath = '';
4258: my $lastitem = '';
4259: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4260: $parentpath = $1;
4261: $lastitem = $2;
4262: } else {
4263: $lastitem = $thisdisfn;
4264: }
4265: $titleinfo =
1.640 bisitz 4266: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4267: .'<b>'.&mt('Construction Space').'</b>: '
4268: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4269: .'" target="_top"><tt><b>'
4270: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
4271: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4272: .'</form>'
4273: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4274: }
1.359 albertel 4275:
1.337 albertel 4276: my $titletable;
1.338 albertel 4277: if (!$notitle) {
1.337 albertel 4278: $titletable =
1.359 albertel 4279: '<table id="LC_title_bar">'.
4280: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4281: '</tr></table>';
1.337 albertel 4282: }
1.359 albertel 4283: if ($notopbar) {
4284: $bodytag .= $titletable;
4285: } else {
4286: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4287: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4288: $titletable);
1.272 raeburn 4289: } else {
1.336 albertel 4290: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4291: $titletable;
1.272 raeburn 4292: }
1.235 raeburn 4293: }
4294: return $bodytag;
1.94 www 4295: }
1.95 www 4296:
1.93 www 4297: #
1.95 www 4298: # Top frame rendering, Remote is up
1.93 www 4299: #
1.359 albertel 4300:
1.517 raeburn 4301: my $imgsrc = $img;
4302: if ($img =~ /^\/adm/) {
1.575 albertel 4303: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4304: }
4305: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4306:
1.305 www 4307: # Explicit link to get inline menu
1.361 albertel 4308: my $menu= ($no_inline_link?''
4309: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4310: #
1.338 albertel 4311: if ($notitle) {
1.337 albertel 4312: return $bodytag;
4313: }
1.94 www 4314: return(<<ENDBODY);
1.60 matthew 4315: $bodytag
1.359 albertel 4316: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4317: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4318: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4319: </tr>
1.359 albertel 4320: <tr><td>$titleinfo $dc_info $menu</td>
4321: $roleinfo
1.368 albertel 4322: </tr>
1.356 albertel 4323: </table>
1.54 www 4324: ENDBODY
1.182 matthew 4325: }
4326:
1.330 albertel 4327: sub make_attr_string {
4328: my ($register,$attr_ref) = @_;
4329:
4330: if ($attr_ref && !ref($attr_ref)) {
4331: die("addentries Must be a hash ref ".
4332: join(':',caller(1))." ".
4333: join(':',caller(0))." ");
4334: }
4335:
4336: if ($register) {
1.339 albertel 4337: my ($on_load,$on_unload);
4338: foreach my $key (keys(%{$attr_ref})) {
4339: if (lc($key) eq 'onload') {
4340: $on_load.=$attr_ref->{$key}.';';
4341: delete($attr_ref->{$key});
4342:
4343: } elsif (lc($key) eq 'onunload') {
4344: $on_unload.=$attr_ref->{$key}.';';
4345: delete($attr_ref->{$key});
4346: }
4347: }
4348: $attr_ref->{'onload'} =
4349: &Apache::lonmenu::loadevents(). $on_load;
4350: $attr_ref->{'onunload'}=
4351: &Apache::lonmenu::unloadevents().$on_unload;
4352: }
4353:
4354: # Accessibility font enhance
4355: if ($env{'browser.fontenhance'} eq 'on') {
4356: my $style;
4357: foreach my $key (keys(%{$attr_ref})) {
4358: if (lc($key) eq 'style') {
4359: $style.=$attr_ref->{$key}.';';
4360: delete($attr_ref->{$key});
4361: }
4362: }
4363: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4364: }
1.339 albertel 4365:
4366: if ($env{'browser.blackwhite'} eq 'on') {
4367: delete($attr_ref->{'font'});
4368: delete($attr_ref->{'link'});
4369: delete($attr_ref->{'alink'});
4370: delete($attr_ref->{'vlink'});
4371: delete($attr_ref->{'bgcolor'});
4372: delete($attr_ref->{'background'});
4373: }
4374:
1.330 albertel 4375: my $attr_string;
4376: foreach my $attr (keys(%$attr_ref)) {
4377: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4378: }
4379: return $attr_string;
4380: }
4381:
4382:
1.182 matthew 4383: ###############################################
1.251 albertel 4384: ###############################################
4385:
4386: =pod
4387:
4388: =item * &endbodytag()
4389:
4390: Returns a uniform footer for LON-CAPA web pages.
4391:
1.635 raeburn 4392: Inputs: 1 - optional reference to an args hash
4393: If in the hash, key for noredirectlink has a value which evaluates to true,
4394: a 'Continue' link is not displayed if the page contains an
4395: internal redirect in the <head></head> section,
4396: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4397:
4398: =cut
4399:
4400: sub endbodytag {
1.635 raeburn 4401: my ($args) = @_;
1.251 albertel 4402: my $endbodytag='</body>';
1.269 albertel 4403: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4404: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4405: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4406: $endbodytag=
4407: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4408: &mt('Continue').'</a>'.
4409: $endbodytag;
4410: }
1.315 albertel 4411: }
1.251 albertel 4412: return $endbodytag;
4413: }
4414:
1.352 albertel 4415: =pod
4416:
4417: =item * &standard_css()
4418:
4419: Returns a style sheet
4420:
4421: Inputs: (all optional)
4422: domain -> force to color decorate a page for a specific
4423: domain
4424: function -> force usage of a specific rolish color scheme
4425: bgcolor -> override the default page bgcolor
4426:
4427: =cut
4428:
1.343 albertel 4429: sub standard_css {
1.345 albertel 4430: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4431: $function = &get_users_function() if (!$function);
4432: my $img = &designparm($function.'.img', $domain);
4433: my $tabbg = &designparm($function.'.tabbg', $domain);
4434: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4435: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4436: my $pgbg_or_bgcolor =
4437: $bgcolor ||
1.352 albertel 4438: &designparm($function.'.pgbg', $domain);
1.382 albertel 4439: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4440: my $alink = &designparm($function.'.alink', $domain);
4441: my $vlink = &designparm($function.'.vlink', $domain);
4442: my $link = &designparm($function.'.link', $domain);
4443:
1.602 albertel 4444: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4445: my $mono = 'monospace';
1.352 albertel 4446: my $data_table_head = $tabbg;
4447: my $data_table_light = '#EEEEEE';
1.470 banghart 4448: my $data_table_dark = '#DDDDDD';
4449: my $data_table_darker = '#CCCCCC';
1.349 albertel 4450: my $data_table_highlight = '#FFFF00';
1.352 albertel 4451: my $mail_new = '#FFBB77';
4452: my $mail_new_hover = '#DD9955';
4453: my $mail_read = '#BBBB77';
4454: my $mail_read_hover = '#999944';
4455: my $mail_replied = '#AAAA88';
4456: my $mail_replied_hover = '#888855';
4457: my $mail_other = '#99BBBB';
4458: my $mail_other_hover = '#669999';
1.391 albertel 4459: my $table_header = '#DDDDDD';
1.489 raeburn 4460: my $feedback_link_bg = '#BBBBBB';
1.392 albertel 4461:
1.608 albertel 4462: my $border = ($env{'browser.type'} eq 'explorer' ||
4463: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4464: : '0px 3px 0px 4px';
1.448 albertel 4465:
1.523 albertel 4466:
1.343 albertel 4467: return <<END;
1.345 albertel 4468: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4469: a:focus { color: red; background: yellow }
1.510 albertel 4470: table.thinborder,
1.523 albertel 4471:
1.510 albertel 4472: table.thinborder tr th {
4473: border-style: solid;
4474: border-width: 1px;
4475: background: $tabbg;
4476: }
1.523 albertel 4477: table.thinborder tr td {
1.510 albertel 4478: border-style: solid;
4479: border-width: 1px
4480: }
1.426 albertel 4481:
1.343 albertel 4482: form, .inline { display: inline; }
4483: .center { text-align: center; }
1.593 albertel 4484: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4485: .LC_error {
4486: color: red;
4487: font-size: larger;
4488: }
1.457 albertel 4489: .LC_warning,
4490: .LC_diff_removed {
1.394 albertel 4491: color: red;
4492: }
1.532 albertel 4493:
4494: .LC_info,
1.457 albertel 4495: .LC_success,
4496: .LC_diff_added {
1.350 albertel 4497: color: green;
4498: }
1.543 albertel 4499: .LC_unknown {
4500: color: yellow;
4501: }
4502:
1.440 albertel 4503: .LC_icon {
4504: border: 0px;
4505: }
1.539 albertel 4506: .LC_indexer_icon {
4507: border: 0px;
4508: height: 22px;
4509: }
1.543 albertel 4510: .LC_docs_spacer {
4511: width: 25px;
4512: height: 1px;
4513: border: 0px;
4514: }
1.346 albertel 4515:
1.532 albertel 4516: .LC_internal_info {
4517: color: #999;
4518: }
4519:
1.458 albertel 4520: table.LC_pastsubmission {
4521: border: 1px solid black;
4522: margin: 2px;
4523: }
4524:
1.606 albertel 4525: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4526: width: 100%;
4527: background: $pgbg;
1.392 albertel 4528: border: 2px;
1.402 albertel 4529: border-collapse: separate;
1.403 albertel 4530: padding: 0px;
1.345 albertel 4531: }
1.392 albertel 4532:
1.606 albertel 4533: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4534: table#LC_title_bar.LC_with_remote {
1.359 albertel 4535: width: 100%;
1.392 albertel 4536: border-color: $pgbg;
4537: border-style: solid;
4538: border-width: $border;
4539:
1.379 albertel 4540: background: $pgbg;
4541: font-family: $sans;
1.392 albertel 4542: border-collapse: collapse;
1.403 albertel 4543: padding: 0px;
1.359 albertel 4544: }
1.392 albertel 4545:
1.409 albertel 4546: table.LC_docs_path {
4547: width: 100%;
4548: border: 0;
4549: background: $pgbg;
4550: font-family: $sans;
4551: border-collapse: collapse;
4552: padding: 0px;
4553: }
4554:
1.359 albertel 4555: table#LC_title_bar td {
4556: background: $tabbg;
4557: }
4558: table#LC_title_bar td.LC_title_bar_who {
4559: background: $tabbg;
4560: color: $font;
1.427 albertel 4561: font: small $sans;
1.359 albertel 4562: text-align: right;
4563: }
1.469 banghart 4564: span.LC_metadata {
4565: font-family: $sans;
4566: }
1.359 albertel 4567: span.LC_title_bar_title {
1.416 albertel 4568: font: bold x-large $sans;
1.359 albertel 4569: }
4570: table#LC_title_bar td.LC_title_bar_domain_logo {
4571: background: $sidebg;
4572: text-align: right;
1.368 albertel 4573: padding: 0px;
4574: }
4575: table#LC_title_bar td.LC_title_bar_role_logo {
4576: background: $sidebg;
4577: padding: 0px;
1.359 albertel 4578: }
4579:
1.346 albertel 4580: table#LC_menubuttons_mainmenu {
1.526 www 4581: width: 100%;
1.346 albertel 4582: border: 0px;
4583: border-spacing: 1px;
1.372 albertel 4584: padding: 0px 1px;
1.346 albertel 4585: margin: 0px;
4586: border-collapse: separate;
4587: }
4588: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
4589: border: 0px;
4590: }
1.345 albertel 4591: table#LC_top_nav td {
4592: background: $tabbg;
1.392 albertel 4593: border: 0px;
1.407 albertel 4594: font-size: small;
1.345 albertel 4595: }
4596: table#LC_top_nav td a, div#LC_top_nav a {
4597: color: $font;
4598: font-family: $sans;
4599: }
1.364 albertel 4600: table#LC_top_nav td.LC_top_nav_logo {
4601: background: $tabbg;
1.432 albertel 4602: text-align: left;
1.408 albertel 4603: white-space: nowrap;
1.432 albertel 4604: width: 31px;
1.408 albertel 4605: }
4606: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4607: border: 0px;
1.408 albertel 4608: vertical-align: bottom;
1.364 albertel 4609: }
1.432 albertel 4610: table#LC_top_nav td.LC_top_nav_exit,
4611: table#LC_top_nav td.LC_top_nav_help {
4612: width: 2.0em;
4613: }
1.442 albertel 4614: table#LC_top_nav td.LC_top_nav_login {
4615: width: 4.0em;
4616: text-align: center;
4617: }
1.409 albertel 4618: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4619: background: $tabbg;
4620: color: $font;
4621: font-family: $sans;
1.358 albertel 4622: font-size: smaller;
1.357 albertel 4623: }
1.411 albertel 4624: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4625: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4626: background: $tabbg;
4627: color: $font;
4628: font-family: $sans;
4629: font-size: larger;
4630: text-align: right;
4631: }
1.383 albertel 4632: td.LC_table_cell_checkbox {
4633: text-align: center;
4634: }
1.522 albertel 4635: table#LC_mainmenu td.LC_mainmenu_column {
4636: vertical-align: top;
4637: }
4638:
1.346 albertel 4639: .LC_menubuttons_inline_text {
4640: color: $font;
4641: font-family: $sans;
4642: font-size: smaller;
4643: }
4644:
1.526 www 4645: .LC_menubuttons_link {
4646: text-decoration: none;
4647: }
1.692.2.10 raeburn 4648: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4649: .LC_menubuttons_category {
1.521 www 4650: color: $font;
1.526 www 4651: background: $pgbg;
1.521 www 4652: font-family: $sans;
4653: font-size: larger;
4654: font-weight: bold;
4655: }
4656:
1.346 albertel 4657: td.LC_menubuttons_text {
1.526 www 4658: width: 90%;
1.346 albertel 4659: color: $font;
4660: font-family: $sans;
4661: }
1.526 www 4662:
1.346 albertel 4663: td.LC_menubuttons_img {
4664: }
1.526 www 4665:
1.346 albertel 4666: .LC_current_location {
4667: font-family: $sans;
4668: background: $tabbg;
4669: }
4670: .LC_new_mail {
4671: font-family: $sans;
1.634 www 4672: background: $tabbg;
1.346 albertel 4673: font-weight: bold;
4674: }
1.347 albertel 4675:
1.526 www 4676: .LC_rolesmenu_is {
4677: font-family: $sans;
4678: }
4679:
4680: .LC_rolesmenu_selected {
4681: font-family: $sans;
4682: }
4683:
4684: .LC_rolesmenu_future {
4685: font-family: $sans;
4686: }
4687:
4688:
4689: .LC_rolesmenu_will {
4690: font-family: $sans;
4691: }
4692:
4693: .LC_rolesmenu_will_not {
4694: font-family: $sans;
4695: }
4696:
4697: .LC_rolesmenu_expired {
4698: font-family: $sans;
4699: }
4700:
4701: .LC_rolesinfo {
4702: font-family: $sans;
4703: }
4704:
1.527 www 4705: .LC_dropadd_labeltext {
4706: font-family: $sans;
4707: text-align: right;
4708: }
4709:
4710: .LC_preferences_labeltext {
4711: font-family: $sans;
4712: text-align: right;
4713: }
4714:
1.666 raeburn 4715: .LC_roleslog_note {
4716: font-size: smaller;
4717: }
4718:
1.692.2.4 raeburn 4719: .LC_mail_functions {
4720: font-weight: bold;
4721: }
4722:
1.440 albertel 4723: table.LC_aboutme_port {
4724: border: 0px;
4725: border-collapse: collapse;
4726: border-spacing: 0px;
4727: }
1.349 albertel 4728: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4729: border: 1px solid #000000;
1.402 albertel 4730: border-collapse: separate;
1.426 albertel 4731: border-spacing: 1px;
1.610 albertel 4732: background: $pgbg;
1.347 albertel 4733: }
1.422 albertel 4734: .LC_data_table_dense {
4735: font-size: small;
4736: }
1.507 raeburn 4737: table.LC_nested_outer {
4738: border: 1px solid #000000;
1.589 raeburn 4739: border-collapse: collapse;
1.507 raeburn 4740: border-spacing: 0px;
4741: width: 100%;
4742: }
4743: table.LC_nested {
4744: border: 0px;
1.589 raeburn 4745: border-collapse: collapse;
1.507 raeburn 4746: border-spacing: 0px;
4747: width: 100%;
4748: }
1.523 albertel 4749: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4750: table.LC_prior_tries tr th {
1.349 albertel 4751: font-weight: bold;
4752: background-color: $data_table_head;
1.421 albertel 4753: font-size: smaller;
1.347 albertel 4754: }
1.692.2.3 raeburn 4755: table.LC_data_table tr.LC_info_row > td {
4756: background-color: #CCC;
4757: font-weight: bold;
4758: text-align: left;
4759: }
1.610 albertel 4760: table.LC_data_table tr.LC_odd_row > td,
1.440 albertel 4761: table.LC_aboutme_port tr td {
1.349 albertel 4762: background-color: $data_table_light;
1.425 albertel 4763: padding: 2px;
1.347 albertel 4764: }
1.610 albertel 4765: table.LC_data_table tr.LC_even_row > td,
1.440 albertel 4766: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4767: background-color: $data_table_dark;
1.347 albertel 4768: }
1.425 albertel 4769: table.LC_data_table tr.LC_data_table_highlight td {
4770: background-color: $data_table_darker;
4771: }
1.639 raeburn 4772: table.LC_data_table tr td.LC_leftcol_header {
4773: background-color: $data_table_head;
4774: font-weight: bold;
4775: }
1.451 albertel 4776: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4777: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4778: background-color: #FFFFFF;
1.421 albertel 4779: font-weight: bold;
4780: font-style: italic;
4781: text-align: center;
4782: padding: 8px;
1.347 albertel 4783: }
1.507 raeburn 4784: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4785: padding: 4ex
4786: }
1.507 raeburn 4787: table.LC_nested_outer tr th {
4788: font-weight: bold;
4789: background-color: $data_table_head;
4790: font-size: smaller;
4791: border-bottom: 1px solid #000000;
4792: }
4793: table.LC_nested_outer tr td.LC_subheader {
4794: background-color: $data_table_head;
4795: font-weight: bold;
4796: font-size: small;
4797: border-bottom: 1px solid #000000;
4798: text-align: right;
1.451 albertel 4799: }
1.507 raeburn 4800: table.LC_nested tr.LC_info_row td {
1.451 albertel 4801: background-color: #CCC;
4802: font-weight: bold;
4803: font-size: small;
1.507 raeburn 4804: text-align: center;
4805: }
1.589 raeburn 4806: table.LC_nested tr.LC_info_row td.LC_left_item,
4807: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4808: text-align: left;
1.451 albertel 4809: }
1.507 raeburn 4810: table.LC_nested td {
1.451 albertel 4811: background-color: #FFF;
4812: font-size: small;
1.507 raeburn 4813: }
4814: table.LC_nested_outer tr th.LC_right_item,
4815: table.LC_nested tr.LC_info_row td.LC_right_item,
4816: table.LC_nested tr.LC_odd_row td.LC_right_item,
4817: table.LC_nested tr td.LC_right_item {
1.451 albertel 4818: text-align: right;
4819: }
4820:
1.507 raeburn 4821: table.LC_nested tr.LC_odd_row td {
1.451 albertel 4822: background-color: #EEE;
4823: }
4824:
1.473 raeburn 4825: table.LC_createuser {
4826: }
4827:
4828: table.LC_createuser tr.LC_section_row td {
4829: font-size: smaller;
4830: }
4831:
4832: table.LC_createuser tr.LC_info_row td {
4833: background-color: #CCC;
4834: font-weight: bold;
4835: text-align: center;
4836: }
4837:
1.349 albertel 4838: table.LC_calendar {
4839: border: 1px solid #000000;
4840: border-collapse: collapse;
4841: }
4842: table.LC_calendar_pickdate {
4843: font-size: xx-small;
4844: }
4845: table.LC_calendar tr td {
4846: border: 1px solid #000000;
4847: vertical-align: top;
4848: }
4849: table.LC_calendar tr td.LC_calendar_day_empty {
4850: background-color: $data_table_dark;
4851: }
4852: table.LC_calendar tr td.LC_calendar_day_current {
4853: background-color: $data_table_highlight;
4854: }
4855:
4856: table.LC_mail_list tr.LC_mail_new {
4857: background-color: $mail_new;
4858: }
4859: table.LC_mail_list tr.LC_mail_new:hover {
4860: background-color: $mail_new_hover;
4861: }
4862: table.LC_mail_list tr.LC_mail_read {
4863: background-color: $mail_read;
4864: }
4865: table.LC_mail_list tr.LC_mail_read:hover {
4866: background-color: $mail_read_hover;
4867: }
4868: table.LC_mail_list tr.LC_mail_replied {
4869: background-color: $mail_replied;
4870: }
4871: table.LC_mail_list tr.LC_mail_replied:hover {
4872: background-color: $mail_replied_hover;
4873: }
4874: table.LC_mail_list tr.LC_mail_other {
4875: background-color: $mail_other;
4876: }
4877: table.LC_mail_list tr.LC_mail_other:hover {
4878: background-color: $mail_other_hover;
4879: }
1.494 raeburn 4880: table.LC_mail_list tr.LC_mail_even {
4881: }
4882: table.LC_mail_list tr.LC_mail_odd {
4883: }
4884:
1.385 albertel 4885:
1.386 albertel 4886: table#LC_portfolio_actions {
4887: width: auto;
4888: background: $pgbg;
4889: border: 0px;
4890: border-spacing: 2px 2px;
4891: padding: 0px;
4892: margin: 0px;
4893: border-collapse: separate;
4894: }
4895: table#LC_portfolio_actions td.LC_label {
4896: background: $tabbg;
4897: text-align: right;
4898: }
4899: table#LC_portfolio_actions td.LC_value {
4900: background: $tabbg;
4901: }
1.385 albertel 4902:
1.391 albertel 4903: table#LC_cstr_controls {
4904: width: 100%;
4905: border-collapse: collapse;
4906: }
4907: table#LC_cstr_controls tr td {
4908: border: 4px solid $pgbg;
4909: padding: 4px;
4910: text-align: center;
4911: background: $tabbg;
4912: }
4913: table#LC_cstr_controls tr th {
4914: border: 4px solid $pgbg;
4915: background: $table_header;
4916: text-align: center;
4917: font-family: $sans;
4918: font-size: smaller;
4919: }
4920:
1.389 albertel 4921: table#LC_browser {
4922:
4923: }
4924: table#LC_browser tr th {
1.391 albertel 4925: background: $table_header;
1.389 albertel 4926: }
1.390 albertel 4927: table#LC_browser tr td {
4928: padding: 2px;
4929: }
1.389 albertel 4930: table#LC_browser tr.LC_browser_file,
4931: table#LC_browser tr.LC_browser_file_published {
4932: background: #CCFF88;
4933: }
4934: table#LC_browser tr.LC_browser_file_locked,
4935: table#LC_browser tr.LC_browser_file_unpublished {
4936: background: #FFAA99;
1.387 albertel 4937: }
1.389 albertel 4938: table#LC_browser tr.LC_browser_file_obsolete {
4939: background: #AAAAAA;
1.387 albertel 4940: }
1.455 albertel 4941: table#LC_browser tr.LC_browser_file_modified,
4942: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 4943: background: #FFFF77;
1.387 albertel 4944: }
1.389 albertel 4945: table#LC_browser tr.LC_browser_folder {
4946: background: #CCCCFF;
1.387 albertel 4947: }
1.388 albertel 4948: span.LC_current_location {
4949: font-size: x-large;
4950: background: $pgbg;
4951: }
1.387 albertel 4952:
1.395 albertel 4953: span.LC_parm_menu_item {
4954: font-size: larger;
4955: font-family: $sans;
4956: }
4957: span.LC_parm_scope_all {
4958: color: red;
4959: }
4960: span.LC_parm_scope_folder {
4961: color: green;
4962: }
4963: span.LC_parm_scope_resource {
4964: color: orange;
4965: }
4966: span.LC_parm_part {
4967: color: blue;
4968: }
4969: span.LC_parm_folder, span.LC_parm_symb {
4970: font-size: x-small;
4971: font-family: $mono;
4972: color: #AAAAAA;
4973: }
4974:
1.396 albertel 4975: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4976: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4977: border: 1px solid black;
4978: border-collapse: collapse;
4979: }
4980: table.LC_parm_overview_restrictions td {
4981: border-width: 1px 4px 1px 4px;
4982: border-style: solid;
4983: border-color: $pgbg;
4984: text-align: center;
4985: }
4986: table.LC_parm_overview_restrictions th {
4987: background: $tabbg;
4988: border-width: 1px 4px 1px 4px;
4989: border-style: solid;
4990: border-color: $pgbg;
4991: }
1.398 albertel 4992: table#LC_helpmenu {
4993: border: 0px;
4994: height: 55px;
4995: border-spacing: 0px;
4996: }
4997:
4998: table#LC_helpmenu fieldset legend {
4999: font-size: larger;
5000: font-weight: bold;
5001: }
1.397 albertel 5002: table#LC_helpmenu_links {
5003: width: 100%;
5004: border: 1px solid black;
5005: background: $pgbg;
5006: padding: 0px;
5007: border-spacing: 1px;
5008: }
5009: table#LC_helpmenu_links tr td {
5010: padding: 1px;
5011: background: $tabbg;
1.399 albertel 5012: text-align: center;
5013: font-weight: bold;
1.397 albertel 5014: }
1.396 albertel 5015:
1.397 albertel 5016: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5017: table#LC_helpmenu_links a:active {
5018: text-decoration: none;
5019: color: $font;
5020: }
5021: table#LC_helpmenu_links a:hover {
5022: text-decoration: underline;
5023: color: $vlink;
5024: }
1.396 albertel 5025:
1.417 albertel 5026: .LC_chrt_popup_exists {
5027: border: 1px solid #339933;
5028: margin: -1px;
5029: }
5030: .LC_chrt_popup_up {
5031: border: 1px solid yellow;
5032: margin: -1px;
5033: }
5034: .LC_chrt_popup {
5035: border: 1px solid #8888FF;
5036: background: #CCCCFF;
5037: }
1.421 albertel 5038: table.LC_pick_box {
5039: border-collapse: separate;
5040: background: white;
5041: border: 1px solid black;
5042: border-spacing: 1px;
5043: }
5044: table.LC_pick_box td.LC_pick_box_title {
5045: background: $tabbg;
5046: font-weight: bold;
5047: text-align: right;
5048: width: 184px;
5049: padding: 8px;
5050: }
1.645 raeburn 5051: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5052: background: $tabbg;
5053: font-weight: bold;
5054: text-align: right;
5055: width: 350px;
5056: padding: 8px;
5057: }
5058:
1.579 raeburn 5059: table.LC_pick_box td.LC_pick_box_value {
5060: text-align: left;
5061: padding: 8px;
5062: }
5063: table.LC_pick_box td.LC_pick_box_select {
5064: text-align: left;
5065: padding: 8px;
5066: }
1.424 albertel 5067: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5068: padding: 0px;
5069: height: 1px;
5070: background: black;
5071: }
5072: table.LC_pick_box td.LC_pick_box_submit {
5073: text-align: right;
5074: }
1.579 raeburn 5075: table.LC_pick_box td.LC_evenrow_value {
5076: text-align: left;
5077: padding: 8px;
5078: background-color: $data_table_light;
5079: }
5080: table.LC_pick_box td.LC_oddrow_value {
5081: text-align: left;
5082: padding: 8px;
5083: background-color: $data_table_light;
5084: }
5085: table.LC_helpform_receipt {
5086: width: 620px;
5087: border-collapse: separate;
5088: background: white;
5089: border: 1px solid black;
5090: border-spacing: 1px;
5091: }
5092: table.LC_helpform_receipt td.LC_pick_box_title {
5093: background: $tabbg;
5094: font-weight: bold;
5095: text-align: right;
5096: width: 184px;
5097: padding: 8px;
5098: }
5099: table.LC_helpform_receipt td.LC_evenrow_value {
5100: text-align: left;
5101: padding: 8px;
5102: background-color: $data_table_light;
5103: }
5104: table.LC_helpform_receipt td.LC_oddrow_value {
5105: text-align: left;
5106: padding: 8px;
5107: background-color: $data_table_light;
5108: }
5109: table.LC_helpform_receipt td.LC_pick_box_separator {
5110: padding: 0px;
5111: height: 1px;
5112: background: black;
5113: }
5114: span.LC_helpform_receipt_cat {
5115: font-weight: bold;
5116: }
1.424 albertel 5117: table.LC_group_priv_box {
5118: background: white;
5119: border: 1px solid black;
5120: border-spacing: 1px;
5121: }
5122: table.LC_group_priv_box td.LC_pick_box_title {
5123: background: $tabbg;
5124: font-weight: bold;
5125: text-align: right;
5126: width: 184px;
5127: }
5128: table.LC_group_priv_box td.LC_groups_fixed {
5129: background: $data_table_light;
5130: text-align: center;
5131: }
5132: table.LC_group_priv_box td.LC_groups_optional {
5133: background: $data_table_dark;
5134: text-align: center;
5135: }
5136: table.LC_group_priv_box td.LC_groups_functionality {
5137: background: $data_table_darker;
5138: text-align: center;
5139: font-weight: bold;
5140: }
5141: table.LC_group_priv td {
5142: text-align: left;
5143: padding: 0px;
5144: }
5145:
1.421 albertel 5146: table.LC_notify_front_page {
5147: background: white;
5148: border: 1px solid black;
5149: padding: 8px;
5150: }
5151: table.LC_notify_front_page td {
5152: padding: 8px;
5153: }
1.424 albertel 5154: .LC_navbuttons {
5155: margin: 2ex 0ex 2ex 0ex;
5156: }
1.423 albertel 5157: .LC_topic_bar {
5158: font-family: $sans;
5159: font-weight: bold;
5160: width: 100%;
5161: background: $tabbg;
5162: vertical-align: middle;
5163: margin: 2ex 0ex 2ex 0ex;
5164: }
5165: .LC_topic_bar span {
5166: vertical-align: middle;
5167: }
5168: .LC_topic_bar img {
5169: vertical-align: bottom;
5170: }
5171: table.LC_course_group_status {
5172: margin: 20px;
5173: }
5174: table.LC_status_selector td {
5175: vertical-align: top;
5176: text-align: center;
1.424 albertel 5177: padding: 4px;
5178: }
5179: table.LC_descriptive_input td.LC_description {
5180: vertical-align: top;
5181: text-align: right;
5182: font-weight: bold;
1.423 albertel 5183: }
1.599 albertel 5184: div.LC_feedback_link {
1.616 albertel 5185: clear: both;
1.599 albertel 5186: background: white;
5187: width: 100%;
1.489 raeburn 5188: }
5189: span.LC_feedback_link {
1.599 albertel 5190: background: $feedback_link_bg;
5191: font-size: larger;
5192: }
5193: span.LC_message_link {
5194: background: $feedback_link_bg;
5195: font-size: larger;
5196: position: absolute;
5197: right: 1em;
1.489 raeburn 5198: }
1.421 albertel 5199:
1.515 albertel 5200: table.LC_prior_tries {
1.524 albertel 5201: border: 1px solid #000000;
5202: border-collapse: separate;
5203: border-spacing: 1px;
1.515 albertel 5204: }
1.523 albertel 5205:
1.515 albertel 5206: table.LC_prior_tries td {
1.524 albertel 5207: padding: 2px;
1.515 albertel 5208: }
1.523 albertel 5209:
5210: .LC_answer_correct {
5211: background: #AAFFAA;
5212: color: black;
5213: }
5214: .LC_answer_charged_try {
5215: background: #FFAAAA ! important;
5216: color: black;
5217: }
5218: .LC_answer_not_charged_try,
5219: .LC_answer_no_grade,
5220: .LC_answer_late {
5221: background: #FFFFAA;
5222: color: black;
5223: }
5224: .LC_answer_previous {
5225: background: #AAAAFF;
5226: color: black;
5227: }
5228: .LC_answer_no_message {
5229: background: #FFFFFF;
5230: color: black;
5231: }
5232: .LC_answer_unknown {
5233: background: orange;
5234: color: black;
5235: }
5236:
5237:
1.529 albertel 5238: span.LC_prior_numerical,
5239: span.LC_prior_string,
5240: span.LC_prior_custom,
5241: span.LC_prior_reaction,
5242: span.LC_prior_math {
1.523 albertel 5243: font-family: monospace;
5244: white-space: pre;
5245: }
5246:
1.525 albertel 5247: span.LC_prior_string {
5248: font-family: monospace;
5249: white-space: pre;
5250: }
5251:
1.523 albertel 5252: table.LC_prior_option {
5253: width: 100%;
5254: border-collapse: collapse;
5255: }
1.528 albertel 5256: table.LC_prior_rank, table.LC_prior_match {
5257: border-collapse: collapse;
5258: }
5259: table.LC_prior_option tr td,
5260: table.LC_prior_rank tr td,
5261: table.LC_prior_match tr td {
1.524 albertel 5262: border: 1px solid #000000;
1.515 albertel 5263: }
5264:
1.519 raeburn 5265: span.LC_nobreak {
1.544 albertel 5266: white-space: nowrap;
1.519 raeburn 5267: }
5268:
1.576 raeburn 5269: span.LC_cusr_emph {
5270: font-style: italic;
5271: }
5272:
1.633 raeburn 5273: span.LC_cusr_subheading {
5274: font-weight: normal;
5275: font-size: 85%;
5276: }
5277:
1.545 albertel 5278: table.LC_docs_documents {
5279: background: #BBBBBB;
1.547 albertel 5280: border-width: 0px;
1.545 albertel 5281: border-collapse: collapse;
5282: }
5283:
5284: table.LC_docs_documents td.LC_docs_document {
5285: border: 2px solid black;
5286: padding: 4px;
5287: }
5288:
5289: .LC_docs_course_commands div {
5290: float: left;
5291: border: 4px solid #AAAAAA;
5292: padding: 4px;
5293: background: #DDDDCC;
5294: }
5295:
5296: .LC_docs_entry_move {
5297: border: 0px;
5298: border-collapse: collapse;
1.544 albertel 5299: }
5300:
1.545 albertel 5301: .LC_docs_entry_move td {
5302: border: 2px solid #BBBBBB;
5303: background: #DDDDDD;
5304: }
5305:
5306: .LC_docs_editor td.LC_docs_entry_commands {
5307: background: #DDDDDD;
5308: font-size: x-small;
5309: }
1.544 albertel 5310: .LC_docs_copy {
1.545 albertel 5311: color: #000099;
1.544 albertel 5312: }
5313: .LC_docs_cut {
1.545 albertel 5314: color: #550044;
1.544 albertel 5315: }
5316: .LC_docs_rename {
1.545 albertel 5317: color: #009900;
1.544 albertel 5318: }
5319: .LC_docs_remove {
1.545 albertel 5320: color: #990000;
5321: }
5322:
1.547 albertel 5323: .LC_docs_reinit_warn,
5324: .LC_docs_ext_edit {
5325: font-size: x-small;
5326: }
5327:
1.545 albertel 5328: .LC_docs_editor td.LC_docs_entry_title,
5329: .LC_docs_editor td.LC_docs_entry_icon {
5330: background: #FFFFBB;
5331: }
5332: .LC_docs_editor td.LC_docs_entry_parameter {
5333: background: #BBBBFF;
5334: font-size: x-small;
5335: white-space: nowrap;
5336: }
5337:
5338: table.LC_docs_adddocs td,
5339: table.LC_docs_adddocs th {
5340: border: 1px solid #BBBBBB;
5341: padding: 4px;
5342: background: #DDDDDD;
1.543 albertel 5343: }
5344:
1.584 albertel 5345: table.LC_sty_begin {
5346: background: #BBFFBB;
5347: }
5348: table.LC_sty_end {
5349: background: #FFBBBB;
5350: }
5351:
1.589 raeburn 5352: table.LC_double_column {
5353: border-width: 0px;
5354: border-collapse: collapse;
5355: width: 100%;
5356: padding: 2px;
5357: }
5358:
5359: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5360: top: 2px;
1.589 raeburn 5361: left: 2px;
5362: width: 47%;
5363: vertical-align: top;
5364: }
5365:
5366: table.LC_double_column tr td.LC_right_col {
5367: top: 2px;
5368: right: 2px;
5369: width: 47%;
5370: vertical-align: top;
5371: }
5372:
1.594 raeburn 5373: span.LC_role_level {
5374: font-weight: bold;
5375: }
5376:
1.591 raeburn 5377: div.LC_left_float {
5378: float: left;
5379: padding-right: 5%;
1.597 albertel 5380: padding-bottom: 4px;
1.591 raeburn 5381: }
5382:
5383: div.LC_clear_float_header {
1.597 albertel 5384: padding-bottom: 2px;
1.591 raeburn 5385: }
5386:
5387: div.LC_clear_float_footer {
1.597 albertel 5388: padding-top: 10px;
1.591 raeburn 5389: clear: both;
5390: }
5391:
1.597 albertel 5392:
1.601 albertel 5393: div.LC_grade_select_mode {
1.604 albertel 5394: font-family: $sans;
1.601 albertel 5395: }
5396: div.LC_grade_select_mode div div {
5397: margin: 5px;
5398: }
5399: div.LC_grade_select_mode_selector {
5400: margin: 5px;
5401: float: left;
5402: }
5403: div.LC_grade_select_mode_selector_header {
5404: font: bold medium $sans;
5405: }
5406: div.LC_grade_select_mode_type {
5407: clear: left;
5408: }
5409:
1.597 albertel 5410: div.LC_grade_show_user {
5411: margin-top: 20px;
5412: border: 1px solid black;
5413: }
5414: div.LC_grade_user_name {
5415: background: #DDDDEE;
5416: border-bottom: 1px solid black;
5417: font: bold large $sans;
5418: }
5419: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5420: background: #DDEEDD;
5421: }
5422:
5423: div.LC_grade_show_problem,
5424: div.LC_grade_submissions,
5425: div.LC_grade_message_center,
5426: div.LC_grade_info_links,
5427: div.LC_grade_assign {
5428: margin: 5px;
5429: width: 99%;
5430: background: #FFFFFF;
5431: }
5432: div.LC_grade_show_problem_header,
5433: div.LC_grade_submissions_header,
5434: div.LC_grade_message_center_header,
5435: div.LC_grade_assign_header {
5436: font: bold large $sans;
5437: }
5438: div.LC_grade_show_problem_problem,
5439: div.LC_grade_submissions_body,
5440: div.LC_grade_message_center_body,
5441: div.LC_grade_assign_body {
5442: border: 1px solid black;
5443: width: 99%;
5444: background: #FFFFFF;
5445: }
1.598 albertel 5446: span.LC_grade_check_note {
5447: font: normal medium $sans;
5448: display: inline;
5449: position: absolute;
5450: right: 1em;
5451: }
1.597 albertel 5452:
1.613 albertel 5453: table.LC_scantron_action {
5454: width: 100%;
5455: }
5456: table.LC_scantron_action tr th {
5457: font: normal bold $sans;
5458: }
1.600 albertel 5459:
1.614 albertel 5460: div.LC_edit_problem_header,
5461: div.LC_edit_problem_footer {
1.600 albertel 5462: font: normal medium $sans;
1.602 albertel 5463: margin: 2px;
1.600 albertel 5464: }
5465: div.LC_edit_problem_header,
1.602 albertel 5466: div.LC_edit_problem_header div,
1.614 albertel 5467: div.LC_edit_problem_footer,
5468: div.LC_edit_problem_footer div,
1.602 albertel 5469: div.LC_edit_problem_editxml_header,
5470: div.LC_edit_problem_editxml_header div {
1.600 albertel 5471: margin-top: 5px;
5472: }
1.602 albertel 5473: div.LC_edit_problem_header_edit_row {
5474: background: $tabbg;
5475: padding: 3px;
5476: margin-bottom: 5px;
5477: }
1.600 albertel 5478: div.LC_edit_problem_header_title {
1.602 albertel 5479: font: larger bold $sans;
5480: background: $tabbg;
5481: padding: 3px;
5482: }
5483: table.LC_edit_problem_header_title {
5484: font: larger bold $sans;
5485: width: 100%;
5486: border-color: $pgbg;
5487: border-style: solid;
5488: border-width: $border;
5489:
1.600 albertel 5490: background: $tabbg;
1.602 albertel 5491: border-collapse: collapse;
5492: padding: 0px
5493: }
5494:
5495: div.LC_edit_problem_discards {
5496: float: left;
5497: padding-bottom: 5px;
5498: }
5499: div.LC_edit_problem_saves {
5500: float: right;
5501: padding-bottom: 5px;
1.600 albertel 5502: }
5503: hr.LC_edit_problem_divide {
1.602 albertel 5504: clear: both;
1.600 albertel 5505: color: $tabbg;
5506: background-color: $tabbg;
5507: height: 3px;
5508: border: 0px;
5509: }
1.679 riegler 5510: img.stift{
1.678 riegler 5511: border-width:0;
1.679 riegler 5512: vertical-align:middle;
1.677 riegler 5513: }
1.680 riegler 5514:
1.681 riegler 5515: table#LC_mainmenu{
5516: margin-top:10px;
5517: width:80%;
5518:
5519: }
5520:
1.680 riegler 5521: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5522: vertical-align: top;
5523: width: 45%;
5524: }
5525: .LC_mainmenu_fieldset_category {
5526: color: $font;
5527: background: $pgbg;
5528: font-family: $sans;
5529: font-size: small;
5530: font-weight: bold;
5531: }
5532: fieldset#LC_mainmenu_fieldset {
1.681 riegler 5533: margin:0px 10px 10px 0px;
1.680 riegler 5534:
5535: }
1.692.2.5 raeburn 5536:
5537: div.LC_createcourse {
5538: margin: 10px 10px 10px 10px;
5539: }
5540:
1.343 albertel 5541: END
5542: }
5543:
1.306 albertel 5544: =pod
5545:
5546: =item * &headtag()
5547:
5548: Returns a uniform footer for LON-CAPA web pages.
5549:
1.307 albertel 5550: Inputs: $title - optional title for the head
5551: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5552: $args - optional arguments
1.319 albertel 5553: force_register - if is true call registerurl so the remote is
5554: informed
1.415 albertel 5555: redirect -> array ref of
5556: 1- seconds before redirect occurs
5557: 2- url to redirect to
5558: 3- whether the side effect should occur
1.315 albertel 5559: (side effect of setting
5560: $env{'internal.head.redirect'} to the url
5561: redirected too)
1.352 albertel 5562: domain -> force to color decorate a page for a specific
5563: domain
5564: function -> force usage of a specific rolish color scheme
5565: bgcolor -> override the default page bgcolor
1.460 albertel 5566: no_auto_mt_title
5567: -> prevent &mt()ing the title arg
1.464 albertel 5568:
1.306 albertel 5569: =cut
5570:
5571: sub headtag {
1.313 albertel 5572: my ($title,$head_extra,$args) = @_;
1.306 albertel 5573:
1.363 albertel 5574: my $function = $args->{'function'} || &get_users_function();
5575: my $domain = $args->{'domain'} || &determinedomain();
5576: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5577: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5578: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5579: #time(),
1.418 albertel 5580: $env{'environment.color.timestamp'},
1.363 albertel 5581: $function,$domain,$bgcolor);
5582:
1.369 www 5583: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5584:
1.308 albertel 5585: my $result =
5586: '<head>'.
1.461 albertel 5587: &font_settings();
1.319 albertel 5588:
1.461 albertel 5589: if (!$args->{'frameset'}) {
5590: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5591: }
1.319 albertel 5592: if ($args->{'force_register'}) {
5593: $result .= &Apache::lonmenu::registerurl(1);
5594: }
1.436 albertel 5595: if (!$args->{'no_nav_bar'}
5596: && !$args->{'only_body'}
5597: && !$args->{'frameset'}) {
5598: $result .= &help_menu_js();
5599: }
1.319 albertel 5600:
1.314 albertel 5601: if (ref($args->{'redirect'})) {
1.414 albertel 5602: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5603: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5604: if (!$inhibit_continue) {
5605: $env{'internal.head.redirect'} = $url;
5606: }
1.313 albertel 5607: $result.=<<ADDMETA
5608: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5609: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5610: ADDMETA
5611: }
1.306 albertel 5612: if (!defined($title)) {
5613: $title = 'The LearningOnline Network with CAPA';
5614: }
1.460 albertel 5615: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5616: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5617: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5618: .$head_extra;
1.306 albertel 5619: return $result;
5620: }
5621:
5622: =pod
5623:
1.340 albertel 5624: =item * &font_settings()
5625:
5626: Returns neccessary <meta> to set the proper encoding
5627:
5628: Inputs: none
5629:
5630: =cut
5631:
5632: sub font_settings {
5633: my $headerstring='';
1.647 www 5634: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5635: $headerstring.=
5636: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5637: }
5638: return $headerstring;
5639: }
5640:
1.341 albertel 5641: =pod
5642:
5643: =item * &xml_begin()
5644:
5645: Returns the needed doctype and <html>
5646:
5647: Inputs: none
5648:
5649: =cut
5650:
5651: sub xml_begin {
5652: my $output='';
5653:
1.592 albertel 5654: if ($env{'internal.start_page'}==1) {
5655: &Apache::lonhtmlcommon::init_htmlareafields();
5656: }
1.342 albertel 5657:
1.341 albertel 5658: if ($env{'browser.mathml'}) {
5659: $output='<?xml version="1.0"?>'
5660: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5661: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5662:
5663: # .'<!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">] >'
5664: .'<!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">'
5665: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5666: .'xmlns="http://www.w3.org/1999/xhtml">';
5667: } else {
5668: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5669: }
5670: return $output;
5671: }
1.340 albertel 5672:
5673: =pod
5674:
1.306 albertel 5675: =item * &endheadtag()
5676:
5677: Returns a uniform </head> for LON-CAPA web pages.
5678:
5679: Inputs: none
5680:
5681: =cut
5682:
5683: sub endheadtag {
5684: return '</head>';
5685: }
5686:
5687: =pod
5688:
5689: =item * &head()
5690:
5691: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5692:
1.648 raeburn 5693: Inputs:
5694:
5695: =over 4
5696:
5697: $title - optional title for the page
5698:
5699: $head_extra - optional extra HTML to put inside the <head>
5700:
5701: =back
1.405 albertel 5702:
1.306 albertel 5703: =cut
5704:
5705: sub head {
1.325 albertel 5706: my ($title,$head_extra,$args) = @_;
5707: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 5708: }
5709:
5710: =pod
5711:
5712: =item * &start_page()
5713:
5714: Returns a complete <html> .. <body> section for LON-CAPA web pages.
5715:
1.648 raeburn 5716: Inputs:
5717:
5718: =over 4
5719:
5720: $title - optional title for the page
5721:
5722: $head_extra - optional extra HTML to incude inside the <head>
5723:
5724: $args - additional optional args supported are:
5725:
5726: =over 8
5727:
5728: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 5729: arg on
1.648 raeburn 5730: no_nav_bar -> is true will set &bodytag() notopbar arg on
5731: add_entries -> additional attributes to add to the <body>
5732: domain -> force to color decorate a page for a
1.317 albertel 5733: specific domain
1.648 raeburn 5734: function -> force usage of a specific rolish color
1.317 albertel 5735: scheme
1.648 raeburn 5736: redirect -> see &headtag()
5737: bgcolor -> override the default page bg color
5738: js_ready -> return a string ready for being used in
1.317 albertel 5739: a javascript writeln
1.648 raeburn 5740: html_encode -> return a string ready for being used in
1.320 albertel 5741: a html attribute
1.648 raeburn 5742: force_register -> if is true will turn on the &bodytag()
1.317 albertel 5743: $forcereg arg
1.648 raeburn 5744: body_title -> alternate text to use instead of $title
1.326 albertel 5745: in the title box that appears, this text
5746: is not auto translated like the $title is
1.648 raeburn 5747: frameset -> if true will start with a <frameset>
1.330 albertel 5748: rather than <body>
1.648 raeburn 5749: no_title -> if true the title bar won't be shown
5750: skip_phases -> hash ref of
1.338 albertel 5751: head -> skip the <html><head> generation
5752: body -> skip all <body> generation
1.648 raeburn 5753: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 5754: 'Switch To Inline Menu' link
1.648 raeburn 5755: no_auto_mt_title -> prevent &mt()ing the title arg
5756: inherit_jsmath -> when creating popup window in a page,
5757: should it have jsmath forced on by the
5758: current page
1.361 albertel 5759:
1.648 raeburn 5760: =back
1.460 albertel 5761:
1.648 raeburn 5762: =back
1.562 albertel 5763:
1.306 albertel 5764: =cut
5765:
5766: sub start_page {
1.309 albertel 5767: my ($title,$head_extra,$args) = @_;
1.318 albertel 5768: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 5769: my %head_args;
1.352 albertel 5770: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 5771: 'bgcolor','frameset','no_nav_bar','only_body',
5772: 'no_auto_mt_title') {
1.319 albertel 5773: if (defined($args->{$arg})) {
1.324 raeburn 5774: $head_args{$arg} = $args->{$arg};
1.319 albertel 5775: }
1.313 albertel 5776: }
1.319 albertel 5777:
1.315 albertel 5778: $env{'internal.start_page'}++;
1.338 albertel 5779: my $result;
5780: if (! exists($args->{'skip_phases'}{'head'}) ) {
5781: $result.=
1.341 albertel 5782: &xml_begin().
1.338 albertel 5783: &headtag($title,$head_extra,\%head_args).&endheadtag();
5784: }
5785:
5786: if (! exists($args->{'skip_phases'}{'body'}) ) {
5787: if ($args->{'frameset'}) {
5788: my $attr_string = &make_attr_string($args->{'force_register'},
5789: $args->{'add_entries'});
5790: $result .= "\n<frameset $attr_string>\n";
5791: } else {
5792: $result .=
5793: &bodytag($title,
5794: $args->{'function'}, $args->{'add_entries'},
5795: $args->{'only_body'}, $args->{'domain'},
5796: $args->{'force_register'}, $args->{'body_title'},
5797: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 5798: $args->{'no_title'}, $args->{'no_inline_link'},
5799: $args);
1.338 albertel 5800: }
1.330 albertel 5801: }
1.338 albertel 5802:
1.315 albertel 5803: if ($args->{'js_ready'}) {
1.317 albertel 5804: $result = &js_ready($result);
1.315 albertel 5805: }
1.320 albertel 5806: if ($args->{'html_encode'}) {
5807: $result = &html_encode($result);
5808: }
1.315 albertel 5809: return $result;
1.306 albertel 5810: }
5811:
1.330 albertel 5812:
1.306 albertel 5813: =pod
5814:
5815: =item * &head()
5816:
5817: Returns a complete </body></html> section for LON-CAPA web pages.
5818:
1.315 albertel 5819: Inputs: $args - additional optional args supported are:
5820: js_ready -> return a string ready for being used in
5821: a javascript writeln
1.320 albertel 5822: html_encode -> return a string ready for being used in
5823: a html attribute
1.330 albertel 5824: frameset -> if true will start with a <frameset>
5825: rather than <body>
1.493 albertel 5826: dicsussion -> if true will get discussion from
5827: lonxml::xmlend
5828: (you can pass the target and parser arguments
5829: through optional 'target' and 'parser' args
5830: to this routine)
1.306 albertel 5831:
5832: =cut
5833:
5834: sub end_page {
1.315 albertel 5835: my ($args) = @_;
5836: $env{'internal.end_page'}++;
1.330 albertel 5837: my $result;
1.335 albertel 5838: if ($args->{'discussion'}) {
5839: my ($target,$parser);
5840: if (ref($args->{'discussion'})) {
5841: ($target,$parser) =($args->{'discussion'}{'target'},
5842: $args->{'discussion'}{'parser'});
5843: }
5844: $result .= &Apache::lonxml::xmlend($target,$parser);
5845: }
5846:
1.330 albertel 5847: if ($args->{'frameset'}) {
5848: $result .= '</frameset>';
5849: } else {
1.635 raeburn 5850: $result .= &endbodytag($args);
1.330 albertel 5851: }
5852: $result .= "\n</html>";
5853:
1.315 albertel 5854: if ($args->{'js_ready'}) {
1.317 albertel 5855: $result = &js_ready($result);
1.315 albertel 5856: }
1.335 albertel 5857:
1.320 albertel 5858: if ($args->{'html_encode'}) {
5859: $result = &html_encode($result);
5860: }
1.335 albertel 5861:
1.315 albertel 5862: return $result;
5863: }
5864:
1.320 albertel 5865: sub html_encode {
5866: my ($result) = @_;
5867:
1.322 albertel 5868: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 5869:
5870: return $result;
5871: }
1.317 albertel 5872: sub js_ready {
5873: my ($result) = @_;
5874:
1.323 albertel 5875: $result =~ s/[\n\r]/ /xmsg;
5876: $result =~ s/\\/\\\\/xmsg;
5877: $result =~ s/'/\\'/xmsg;
1.372 albertel 5878: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 5879:
5880: return $result;
5881: }
5882:
1.315 albertel 5883: sub validate_page {
5884: if ( exists($env{'internal.start_page'})
1.316 albertel 5885: && $env{'internal.start_page'} > 1) {
5886: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 5887: $env{'internal.start_page'}.' '.
1.316 albertel 5888: $ENV{'request.filename'});
1.315 albertel 5889: }
5890: if ( exists($env{'internal.end_page'})
1.316 albertel 5891: && $env{'internal.end_page'} > 1) {
5892: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 5893: $env{'internal.end_page'}.' '.
1.316 albertel 5894: $env{'request.filename'});
1.315 albertel 5895: }
5896: if ( exists($env{'internal.start_page'})
5897: && ! exists($env{'internal.end_page'})) {
1.316 albertel 5898: &Apache::lonnet::logthis('start_page called without end_page '.
5899: $env{'request.filename'});
1.315 albertel 5900: }
5901: if ( ! exists($env{'internal.start_page'})
5902: && exists($env{'internal.end_page'})) {
1.316 albertel 5903: &Apache::lonnet::logthis('end_page called without start_page'.
5904: $env{'request.filename'});
1.315 albertel 5905: }
1.306 albertel 5906: }
1.315 albertel 5907:
1.318 albertel 5908: sub simple_error_page {
5909: my ($r,$title,$msg) = @_;
5910: my $page =
5911: &Apache::loncommon::start_page($title).
5912: &mt($msg).
5913: &Apache::loncommon::end_page();
5914: if (ref($r)) {
5915: $r->print($page);
1.327 albertel 5916: return;
1.318 albertel 5917: }
5918: return $page;
5919: }
1.347 albertel 5920:
5921: {
1.610 albertel 5922: my @row_count;
1.347 albertel 5923: sub start_data_table {
1.422 albertel 5924: my ($add_class) = @_;
5925: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 5926: unshift(@row_count,0);
1.422 albertel 5927: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 5928: }
5929:
5930: sub end_data_table {
1.610 albertel 5931: shift(@row_count);
1.389 albertel 5932: return '</table>'."\n";;
1.347 albertel 5933: }
5934:
5935: sub start_data_table_row {
1.422 albertel 5936: my ($add_class) = @_;
1.610 albertel 5937: $row_count[0]++;
5938: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 5939: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 5940: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 5941: }
1.471 banghart 5942:
5943: sub continue_data_table_row {
5944: my ($add_class) = @_;
1.610 albertel 5945: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 5946: $css_class = (join(' ',$css_class,$add_class));
5947: return '<tr class="'.$css_class.'">'."\n";;
5948: }
1.347 albertel 5949:
5950: sub end_data_table_row {
1.389 albertel 5951: return '</tr>'."\n";;
1.347 albertel 5952: }
1.367 www 5953:
1.421 albertel 5954: sub start_data_table_empty_row {
1.610 albertel 5955: $row_count[0]++;
1.421 albertel 5956: return '<tr class="LC_empty_row" >'."\n";;
5957: }
5958:
5959: sub end_data_table_empty_row {
5960: return '</tr>'."\n";;
5961: }
5962:
1.367 www 5963: sub start_data_table_header_row {
1.389 albertel 5964: return '<tr class="LC_header_row">'."\n";;
1.367 www 5965: }
5966:
5967: sub end_data_table_header_row {
1.389 albertel 5968: return '</tr>'."\n";;
1.367 www 5969: }
1.347 albertel 5970: }
5971:
1.548 albertel 5972: =pod
5973:
5974: =item * &inhibit_menu_check($arg)
5975:
5976: Checks for a inhibitmenu state and generates output to preserve it
5977:
5978: Inputs: $arg - can be any of
5979: - undef - in which case the return value is a string
5980: to add into arguments list of a uri
5981: - 'input' - in which case the return value is a HTML
5982: <form> <input> field of type hidden to
5983: preserve the value
5984: - a url - in which case the return value is the url with
5985: the neccesary cgi args added to preserve the
5986: inhibitmenu state
5987: - a ref to a url - no return value, but the string is
5988: updated to include the neccessary cgi
5989: args to preserve the inhibitmenu state
5990:
5991: =cut
5992:
5993: sub inhibit_menu_check {
5994: my ($arg) = @_;
5995: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5996: if ($arg eq 'input') {
5997: if ($env{'form.inhibitmenu'}) {
5998: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
5999: } else {
6000: return
6001: }
6002: }
6003: if ($env{'form.inhibitmenu'}) {
6004: if (ref($arg)) {
6005: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6006: } elsif ($arg eq '') {
6007: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6008: } else {
6009: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6010: }
6011: }
6012: if (!ref($arg)) {
6013: return $arg;
6014: }
6015: }
6016:
1.251 albertel 6017: ###############################################
1.182 matthew 6018:
6019: =pod
6020:
1.549 albertel 6021: =back
6022:
6023: =head1 User Information Routines
6024:
6025: =over 4
6026:
1.405 albertel 6027: =item * &get_users_function()
1.182 matthew 6028:
6029: Used by &bodytag to determine the current users primary role.
6030: Returns either 'student','coordinator','admin', or 'author'.
6031:
6032: =cut
6033:
6034: ###############################################
6035: sub get_users_function {
6036: my $function = 'student';
1.258 albertel 6037: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6038: $function='coordinator';
6039: }
1.258 albertel 6040: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6041: $function='admin';
6042: }
1.258 albertel 6043: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6044: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6045: $function='author';
6046: }
6047: return $function;
1.54 www 6048: }
1.99 www 6049:
6050: ###############################################
6051:
1.233 raeburn 6052: =pod
6053:
1.542 raeburn 6054: =item * &check_user_status()
1.274 raeburn 6055:
6056: Determines current status of supplied role for a
6057: specific user. Roles can be active, previous or future.
6058:
6059: Inputs:
6060: user's domain, user's username, course's domain,
1.375 raeburn 6061: course's number, optional section ID.
1.274 raeburn 6062:
6063: Outputs:
6064: role status: active, previous or future.
6065:
6066: =cut
6067:
6068: sub check_user_status {
1.412 raeburn 6069: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6070: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6071: my @uroles = keys %userinfo;
6072: my $srchstr;
6073: my $active_chk = 'none';
1.412 raeburn 6074: my $now = time;
1.274 raeburn 6075: if (@uroles > 0) {
1.412 raeburn 6076: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6077: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6078: } else {
1.412 raeburn 6079: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6080: }
6081: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6082: my $role_end = 0;
6083: my $role_start = 0;
6084: $active_chk = 'active';
1.412 raeburn 6085: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6086: $role_end = $1;
6087: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6088: $role_start = $1;
1.274 raeburn 6089: }
6090: }
6091: if ($role_start > 0) {
1.412 raeburn 6092: if ($now < $role_start) {
1.274 raeburn 6093: $active_chk = 'future';
6094: }
6095: }
6096: if ($role_end > 0) {
1.412 raeburn 6097: if ($now > $role_end) {
1.274 raeburn 6098: $active_chk = 'previous';
6099: }
6100: }
6101: }
6102: }
6103: return $active_chk;
6104: }
6105:
6106: ###############################################
6107:
6108: =pod
6109:
1.405 albertel 6110: =item * &get_sections()
1.233 raeburn 6111:
6112: Determines all the sections for a course including
6113: sections with students and sections containing other roles.
1.419 raeburn 6114: Incoming parameters:
6115:
6116: 1. domain
6117: 2. course number
6118: 3. reference to array containing roles for which sections should
6119: be gathered (optional).
6120: 4. reference to array containing status types for which sections
6121: should be gathered (optional).
6122:
6123: If the third argument is undefined, sections are gathered for any role.
6124: If the fourth argument is undefined, sections are gathered for any status.
6125: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6126:
1.374 raeburn 6127: Returns section hash (keys are section IDs, values are
6128: number of users in each section), subject to the
1.419 raeburn 6129: optional roles filter, optional status filter
1.233 raeburn 6130:
6131: =cut
6132:
6133: ###############################################
6134: sub get_sections {
1.419 raeburn 6135: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6136: if (!defined($cdom) || !defined($cnum)) {
6137: my $cid = $env{'request.course.id'};
6138:
6139: return if (!defined($cid));
6140:
6141: $cdom = $env{'course.'.$cid.'.domain'};
6142: $cnum = $env{'course.'.$cid.'.num'};
6143: }
6144:
6145: my %sectioncount;
1.419 raeburn 6146: my $now = time;
1.240 albertel 6147:
1.366 albertel 6148: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6149: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6150: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6151: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6152: my $start_index = &Apache::loncoursedata::CL_START();
6153: my $end_index = &Apache::loncoursedata::CL_END();
6154: my $status;
1.366 albertel 6155: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6156: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6157: $data->[$status_index],
6158: $data->[$start_index],
6159: $data->[$end_index]);
6160: if ($stu_status eq 'Active') {
6161: $status = 'active';
6162: } elsif ($end < $now) {
6163: $status = 'previous';
6164: } elsif ($start > $now) {
6165: $status = 'future';
6166: }
6167: if ($section ne '-1' && $section !~ /^\s*$/) {
6168: if ((!defined($possible_status)) || (($status ne '') &&
6169: (grep/^\Q$status\E$/,@{$possible_status}))) {
6170: $sectioncount{$section}++;
6171: }
1.240 albertel 6172: }
6173: }
6174: }
6175: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6176: foreach my $user (sort(keys(%courseroles))) {
6177: if ($user !~ /^(\w{2})/) { next; }
6178: my ($role) = ($user =~ /^(\w{2})/);
6179: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6180: my ($section,$status);
1.240 albertel 6181: if ($role eq 'cr' &&
6182: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6183: $section=$1;
6184: }
6185: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6186: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6187: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6188: if ($end == -1 && $start == -1) {
6189: next; #deleted role
6190: }
6191: if (!defined($possible_status)) {
6192: $sectioncount{$section}++;
6193: } else {
6194: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6195: $status = 'active';
6196: } elsif ($end < $now) {
6197: $status = 'future';
6198: } elsif ($start > $now) {
6199: $status = 'previous';
6200: }
6201: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6202: $sectioncount{$section}++;
6203: }
6204: }
1.233 raeburn 6205: }
1.366 albertel 6206: return %sectioncount;
1.233 raeburn 6207: }
6208:
1.274 raeburn 6209: ###############################################
1.294 raeburn 6210:
6211: =pod
1.405 albertel 6212:
6213: =item * &get_course_users()
6214:
1.275 raeburn 6215: Retrieves usernames:domains for users in the specified course
6216: with specific role(s), and access status.
6217:
6218: Incoming parameters:
1.277 albertel 6219: 1. course domain
6220: 2. course number
6221: 3. access status: users must have - either active,
1.275 raeburn 6222: previous, future, or all.
1.277 albertel 6223: 4. reference to array of permissible roles
1.288 raeburn 6224: 5. reference to array of section restrictions (optional)
6225: 6. reference to results object (hash of hashes).
6226: 7. reference to optional userdata hash
1.609 raeburn 6227: 8. reference to optional statushash
1.630 raeburn 6228: 9. flag if privileged users (except those set to unhide in
6229: course settings) should be excluded
1.609 raeburn 6230: Keys of top level results hash are roles.
1.275 raeburn 6231: Keys of inner hashes are username:domain, with
6232: values set to access type.
1.288 raeburn 6233: Optional userdata hash returns an array with arguments in the
6234: same order as loncoursedata::get_classlist() for student data.
6235:
1.609 raeburn 6236: Optional statushash returns
6237:
1.288 raeburn 6238: Entries for end, start, section and status are blank because
6239: of the possibility of multiple values for non-student roles.
6240:
1.275 raeburn 6241: =cut
1.405 albertel 6242:
1.275 raeburn 6243: ###############################################
1.405 albertel 6244:
1.275 raeburn 6245: sub get_course_users {
1.630 raeburn 6246: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6247: my %idx = ();
1.419 raeburn 6248: my %seclists;
1.288 raeburn 6249:
6250: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6251: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6252: $idx{end} = &Apache::loncoursedata::CL_END();
6253: $idx{start} = &Apache::loncoursedata::CL_START();
6254: $idx{id} = &Apache::loncoursedata::CL_ID();
6255: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6256: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6257: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6258:
1.290 albertel 6259: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6260: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6261: my $now = time;
1.277 albertel 6262: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6263: my $match = 0;
1.412 raeburn 6264: my $secmatch = 0;
1.419 raeburn 6265: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6266: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6267: if ($section eq '') {
6268: $section = 'none';
6269: }
1.291 albertel 6270: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6271: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6272: $secmatch = 1;
6273: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6274: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6275: $secmatch = 1;
6276: }
6277: } else {
1.419 raeburn 6278: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6279: $secmatch = 1;
6280: }
1.290 albertel 6281: }
1.412 raeburn 6282: if (!$secmatch) {
6283: next;
6284: }
1.419 raeburn 6285: }
1.275 raeburn 6286: if (defined($$types{'active'})) {
1.288 raeburn 6287: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6288: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6289: $match = 1;
1.275 raeburn 6290: }
6291: }
6292: if (defined($$types{'previous'})) {
1.609 raeburn 6293: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6294: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6295: $match = 1;
1.275 raeburn 6296: }
6297: }
6298: if (defined($$types{'future'})) {
1.609 raeburn 6299: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6300: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6301: $match = 1;
1.275 raeburn 6302: }
6303: }
1.609 raeburn 6304: if ($match) {
6305: push(@{$seclists{$student}},$section);
6306: if (ref($userdata) eq 'HASH') {
6307: $$userdata{$student} = $$classlist{$student};
6308: }
6309: if (ref($statushash) eq 'HASH') {
6310: $statushash->{$student}{'st'}{$section} = $status;
6311: }
1.288 raeburn 6312: }
1.275 raeburn 6313: }
6314: }
1.412 raeburn 6315: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6316: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6317: my $now = time;
1.609 raeburn 6318: my %displaystatus = ( previous => 'Expired',
6319: active => 'Active',
6320: future => 'Future',
6321: );
1.630 raeburn 6322: my %nothide;
6323: if ($hidepriv) {
6324: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6325: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6326: if ($user !~ /:/) {
6327: $nothide{join(':',split(/[\@]/,$user))}=1;
6328: } else {
6329: $nothide{$user} = 1;
6330: }
6331: }
6332: }
1.439 raeburn 6333: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6334: my $match = 0;
1.412 raeburn 6335: my $secmatch = 0;
1.439 raeburn 6336: my $status;
1.412 raeburn 6337: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6338: $user =~ s/:$//;
1.439 raeburn 6339: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6340: if ($end == -1 || $start == -1) {
6341: next;
6342: }
6343: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6344: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6345: my ($uname,$udom) = split(/:/,$user);
6346: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6347: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6348: $secmatch = 1;
6349: } elsif ($usec eq '') {
1.420 albertel 6350: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6351: $secmatch = 1;
6352: }
6353: } else {
6354: if (grep(/^\Q$usec\E$/,@{$sections})) {
6355: $secmatch = 1;
6356: }
6357: }
6358: if (!$secmatch) {
6359: next;
6360: }
1.288 raeburn 6361: }
1.419 raeburn 6362: if ($usec eq '') {
6363: $usec = 'none';
6364: }
1.275 raeburn 6365: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6366: if ($hidepriv) {
6367: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6368: (!$nothide{$uname.':'.$udom})) {
6369: next;
6370: }
6371: }
1.503 raeburn 6372: if ($end > 0 && $end < $now) {
1.439 raeburn 6373: $status = 'previous';
6374: } elsif ($start > $now) {
6375: $status = 'future';
6376: } else {
6377: $status = 'active';
6378: }
1.277 albertel 6379: foreach my $type (keys(%{$types})) {
1.275 raeburn 6380: if ($status eq $type) {
1.420 albertel 6381: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6382: push(@{$$users{$role}{$user}},$type);
6383: }
1.288 raeburn 6384: $match = 1;
6385: }
6386: }
1.419 raeburn 6387: if (($match) && (ref($userdata) eq 'HASH')) {
6388: if (!exists($$userdata{$uname.':'.$udom})) {
6389: &get_user_info($udom,$uname,\%idx,$userdata);
6390: }
1.420 albertel 6391: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6392: push(@{$seclists{$uname.':'.$udom}},$usec);
6393: }
1.609 raeburn 6394: if (ref($statushash) eq 'HASH') {
6395: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6396: }
1.275 raeburn 6397: }
6398: }
6399: }
6400: }
1.290 albertel 6401: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6402: if ((defined($cdom)) && (defined($cnum))) {
6403: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6404: if ( defined($csettings{'internal.courseowner'}) ) {
6405: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6406: next if ($owner eq '');
6407: my ($ownername,$ownerdom);
6408: if ($owner =~ /^([^:]+):([^:]+)$/) {
6409: $ownername = $1;
6410: $ownerdom = $2;
6411: } else {
6412: $ownername = $owner;
6413: $ownerdom = $cdom;
6414: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6415: }
6416: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6417: if (defined($userdata) &&
1.609 raeburn 6418: !exists($$userdata{$owner})) {
6419: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6420: if (!grep(/^none$/,@{$seclists{$owner}})) {
6421: push(@{$seclists{$owner}},'none');
6422: }
6423: if (ref($statushash) eq 'HASH') {
6424: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6425: }
1.290 albertel 6426: }
1.279 raeburn 6427: }
6428: }
6429: }
1.419 raeburn 6430: foreach my $user (keys(%seclists)) {
6431: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6432: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6433: }
1.275 raeburn 6434: }
6435: return;
6436: }
6437:
1.288 raeburn 6438: sub get_user_info {
6439: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6440: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6441: &plainname($uname,$udom,'lastname');
1.291 albertel 6442: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6443: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6444: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6445: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6446: return;
6447: }
1.275 raeburn 6448:
1.472 raeburn 6449: ###############################################
6450:
6451: =pod
6452:
6453: =item * &get_user_quota()
6454:
6455: Retrieves quota assigned for storage of portfolio files for a user
6456:
6457: Incoming parameters:
6458: 1. user's username
6459: 2. user's domain
6460:
6461: Returns:
1.536 raeburn 6462: 1. Disk quota (in Mb) assigned to student.
6463: 2. (Optional) Type of setting: custom or default
6464: (individually assigned or default for user's
6465: institutional status).
6466: 3. (Optional) - User's institutional status (e.g., faculty, staff
6467: or student - types as defined in localenroll::inst_usertypes
6468: for user's domain, which determines default quota for user.
6469: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6470:
6471: If a value has been stored in the user's environment,
1.536 raeburn 6472: it will return that, otherwise it returns the maximal default
6473: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6474:
6475: =cut
6476:
6477: ###############################################
6478:
6479:
6480: sub get_user_quota {
6481: my ($uname,$udom) = @_;
1.536 raeburn 6482: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6483: if (!defined($udom)) {
6484: $udom = $env{'user.domain'};
6485: }
6486: if (!defined($uname)) {
6487: $uname = $env{'user.name'};
6488: }
6489: if (($udom eq '' || $uname eq '') ||
6490: ($udom eq 'public') && ($uname eq 'public')) {
6491: $quota = 0;
1.536 raeburn 6492: $quotatype = 'default';
6493: $defquota = 0;
1.472 raeburn 6494: } else {
1.536 raeburn 6495: my $inststatus;
1.472 raeburn 6496: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6497: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6498: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6499: } else {
1.536 raeburn 6500: my %userenv =
6501: &Apache::lonnet::get('environment',['portfolioquota',
6502: 'inststatus'],$udom,$uname);
1.472 raeburn 6503: my ($tmp) = keys(%userenv);
6504: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6505: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6506: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6507: } else {
6508: undef(%userenv);
6509: }
6510: }
1.536 raeburn 6511: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6512: if ($quota eq '') {
1.536 raeburn 6513: $quota = $defquota;
6514: $quotatype = 'default';
6515: } else {
6516: $quotatype = 'custom';
1.472 raeburn 6517: }
6518: }
1.536 raeburn 6519: if (wantarray) {
6520: return ($quota,$quotatype,$settingstatus,$defquota);
6521: } else {
6522: return $quota;
6523: }
1.472 raeburn 6524: }
6525:
6526: ###############################################
6527:
6528: =pod
6529:
6530: =item * &default_quota()
6531:
1.536 raeburn 6532: Retrieves default quota assigned for storage of user portfolio files,
6533: given an (optional) user's institutional status.
1.472 raeburn 6534:
6535: Incoming parameters:
6536: 1. domain
1.536 raeburn 6537: 2. (Optional) institutional status(es). This is a : separated list of
6538: status types (e.g., faculty, staff, student etc.)
6539: which apply to the user for whom the default is being retrieved.
6540: If the institutional status string in undefined, the domain
6541: default quota will be returned.
1.472 raeburn 6542:
6543: Returns:
6544: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6545: 2. (Optional) institutional type which determined the value of the
6546: default quota.
1.472 raeburn 6547:
6548: If a value has been stored in the domain's configuration db,
6549: it will return that, otherwise it returns 20 (for backwards
6550: compatibility with domains which have not set up a configuration
6551: db file; the original statically defined portfolio quota was 20 Mb).
6552:
1.536 raeburn 6553: If the user's status includes multiple types (e.g., staff and student),
6554: the largest default quota which applies to the user determines the
6555: default quota returned.
6556:
1.472 raeburn 6557: =cut
6558:
6559: ###############################################
6560:
6561:
6562: sub default_quota {
1.536 raeburn 6563: my ($udom,$inststatus) = @_;
6564: my ($defquota,$settingstatus);
6565: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6566: ['quotas'],$udom);
6567: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6568: if ($inststatus ne '') {
6569: my @statuses = split(/:/,$inststatus);
6570: foreach my $item (@statuses) {
1.692.2.3 raeburn 6571: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6572: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6573: if ($defquota eq '') {
6574: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6575: $settingstatus = $item;
6576: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6577: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6578: $settingstatus = $item;
6579: }
6580: }
6581: } else {
6582: if ($quotahash{'quotas'}{$item} ne '') {
6583: if ($defquota eq '') {
6584: $defquota = $quotahash{'quotas'}{$item};
6585: $settingstatus = $item;
6586: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6587: $defquota = $quotahash{'quotas'}{$item};
6588: $settingstatus = $item;
6589: }
1.536 raeburn 6590: }
6591: }
6592: }
6593: }
6594: if ($defquota eq '') {
1.692.2.3 raeburn 6595: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6596: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6597: } else {
6598: $defquota = $quotahash{'quotas'}{'default'};
6599: }
1.536 raeburn 6600: $settingstatus = 'default';
6601: }
6602: } else {
6603: $settingstatus = 'default';
6604: $defquota = 20;
6605: }
6606: if (wantarray) {
6607: return ($defquota,$settingstatus);
1.472 raeburn 6608: } else {
1.536 raeburn 6609: return $defquota;
1.472 raeburn 6610: }
6611: }
6612:
1.384 raeburn 6613: sub get_secgrprole_info {
6614: my ($cdom,$cnum,$needroles,$type) = @_;
6615: my %sections_count = &get_sections($cdom,$cnum);
6616: my @sections = (sort {$a <=> $b} keys(%sections_count));
6617: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6618: my @groups = sort(keys(%curr_groups));
6619: my $allroles = [];
6620: my $rolehash;
6621: my $accesshash = {
6622: active => 'Currently has access',
6623: future => 'Will have future access',
6624: previous => 'Previously had access',
6625: };
6626: if ($needroles) {
6627: $rolehash = {'all' => 'all'};
1.385 albertel 6628: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6629: if (&Apache::lonnet::error(%user_roles)) {
6630: undef(%user_roles);
6631: }
6632: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6633: my ($role)=split(/\:/,$item,2);
6634: if ($role eq 'cr') { next; }
6635: if ($role =~ /^cr/) {
6636: $$rolehash{$role} = (split('/',$role))[3];
6637: } else {
6638: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6639: }
6640: }
6641: foreach my $key (sort(keys(%{$rolehash}))) {
6642: push(@{$allroles},$key);
6643: }
6644: push (@{$allroles},'st');
6645: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6646: }
6647: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6648: }
6649:
1.555 raeburn 6650: sub user_picker {
1.627 raeburn 6651: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6652: my $currdom = $dom;
6653: my %curr_selected = (
6654: srchin => 'dom',
1.580 raeburn 6655: srchby => 'lastname',
1.555 raeburn 6656: );
6657: my $srchterm;
1.625 raeburn 6658: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6659: if ($srch->{'srchby'} ne '') {
6660: $curr_selected{'srchby'} = $srch->{'srchby'};
6661: }
6662: if ($srch->{'srchin'} ne '') {
6663: $curr_selected{'srchin'} = $srch->{'srchin'};
6664: }
6665: if ($srch->{'srchtype'} ne '') {
6666: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6667: }
6668: if ($srch->{'srchdomain'} ne '') {
6669: $currdom = $srch->{'srchdomain'};
6670: }
6671: $srchterm = $srch->{'srchterm'};
6672: }
6673: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6674: 'usr' => 'Search criteria',
1.563 raeburn 6675: 'doma' => 'Domain/institution to search',
1.558 albertel 6676: 'uname' => 'username',
6677: 'lastname' => 'last name',
1.555 raeburn 6678: 'lastfirst' => 'last name, first name',
1.558 albertel 6679: 'crs' => 'in this course',
1.576 raeburn 6680: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6681: 'alc' => 'all LON-CAPA',
1.573 raeburn 6682: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6683: 'exact' => 'is',
6684: 'contains' => 'contains',
1.569 raeburn 6685: 'begins' => 'begins with',
1.571 raeburn 6686: 'youm' => "You must include some text to search for.",
6687: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6688: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6689: 'yomc' => "You must choose a domain when using an institutional directory search.",
6690: 'ymcd' => "You must choose a domain when using a domain search.",
6691: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6692: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6693: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6694: );
1.563 raeburn 6695: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6696: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6697:
6698: my @srchins = ('crs','dom','alc','instd');
6699:
6700: foreach my $option (@srchins) {
6701: # FIXME 'alc' option unavailable until
6702: # loncreateuser::print_user_query_page()
6703: # has been completed.
6704: next if ($option eq 'alc');
6705: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6706: if ($curr_selected{'srchin'} eq $option) {
6707: $srchinsel .= '
6708: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6709: } else {
6710: $srchinsel .= '
6711: <option value="'.$option.'">'.$lt{$option}.'</option>';
6712: }
1.555 raeburn 6713: }
1.563 raeburn 6714: $srchinsel .= "\n </select>\n";
1.555 raeburn 6715:
6716: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 6717: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 6718: if ($curr_selected{'srchby'} eq $option) {
6719: $srchbysel .= '
6720: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6721: } else {
6722: $srchbysel .= '
6723: <option value="'.$option.'">'.$lt{$option}.'</option>';
6724: }
6725: }
6726: $srchbysel .= "\n </select>\n";
6727:
6728: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 6729: foreach my $option ('begins','contains','exact') {
1.555 raeburn 6730: if ($curr_selected{'srchtype'} eq $option) {
6731: $srchtypesel .= '
6732: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6733: } else {
6734: $srchtypesel .= '
6735: <option value="'.$option.'">'.$lt{$option}.'</option>';
6736: }
6737: }
6738: $srchtypesel .= "\n </select>\n";
6739:
1.558 albertel 6740: my ($newuserscript,$new_user_create);
1.556 raeburn 6741:
6742: if ($forcenewuser) {
1.576 raeburn 6743: if (ref($srch) eq 'HASH') {
6744: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 6745: if ($cancreate) {
6746: $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>';
6747: } else {
6748: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
6749: my %usertypetext = (
6750: official => 'institutional',
6751: unofficial => 'non-institutional',
6752: );
6753: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
6754: }
1.576 raeburn 6755: }
6756: }
6757:
1.556 raeburn 6758: $newuserscript = <<"ENDSCRIPT";
6759:
1.570 raeburn 6760: function setSearch(createnew,callingForm) {
1.556 raeburn 6761: if (createnew == 1) {
1.570 raeburn 6762: for (var i=0; i<callingForm.srchby.length; i++) {
6763: if (callingForm.srchby.options[i].value == 'uname') {
6764: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6765: }
6766: }
1.570 raeburn 6767: for (var i=0; i<callingForm.srchin.length; i++) {
6768: if ( callingForm.srchin.options[i].value == 'dom') {
6769: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6770: }
6771: }
1.570 raeburn 6772: for (var i=0; i<callingForm.srchtype.length; i++) {
6773: if (callingForm.srchtype.options[i].value == 'exact') {
6774: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6775: }
6776: }
1.570 raeburn 6777: for (var i=0; i<callingForm.srchdomain.length; i++) {
6778: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6779: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6780: }
6781: }
6782: }
6783: }
6784: ENDSCRIPT
1.558 albertel 6785:
1.556 raeburn 6786: }
6787:
1.555 raeburn 6788: my $output = <<"END_BLOCK";
1.556 raeburn 6789: <script type="text/javascript">
1.570 raeburn 6790: function validateEntry(callingForm) {
1.558 albertel 6791:
1.556 raeburn 6792: var checkok = 1;
1.558 albertel 6793: var srchin;
1.570 raeburn 6794: for (var i=0; i<callingForm.srchin.length; i++) {
6795: if ( callingForm.srchin[i].checked ) {
6796: srchin = callingForm.srchin[i].value;
1.558 albertel 6797: }
6798: }
6799:
1.570 raeburn 6800: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6801: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6802: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6803: var srchterm = callingForm.srchterm.value;
6804: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6805: var msg = "";
6806:
6807: if (srchterm == "") {
6808: checkok = 0;
1.571 raeburn 6809: msg += "$lt{'youm'}\\n";
1.556 raeburn 6810: }
6811:
1.569 raeburn 6812: if (srchtype== 'begins') {
6813: if (srchterm.length < 2) {
6814: checkok = 0;
1.571 raeburn 6815: msg += "$lt{'thte'}\\n";
1.569 raeburn 6816: }
6817: }
6818:
1.556 raeburn 6819: if (srchtype== 'contains') {
6820: if (srchterm.length < 3) {
6821: checkok = 0;
1.571 raeburn 6822: msg += "$lt{'thet'}\\n";
1.556 raeburn 6823: }
6824: }
6825: if (srchin == 'instd') {
6826: if (srchdomain == '') {
6827: checkok = 0;
1.571 raeburn 6828: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6829: }
6830: }
6831: if (srchin == 'dom') {
6832: if (srchdomain == '') {
6833: checkok = 0;
1.571 raeburn 6834: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6835: }
6836: }
6837: if (srchby == 'lastfirst') {
6838: if (srchterm.indexOf(",") == -1) {
6839: checkok = 0;
1.571 raeburn 6840: msg += "$lt{'whus'}\\n";
1.556 raeburn 6841: }
6842: if (srchterm.indexOf(",") == srchterm.length -1) {
6843: checkok = 0;
1.571 raeburn 6844: msg += "$lt{'whse'}\\n";
1.556 raeburn 6845: }
6846: }
6847: if (checkok == 0) {
1.571 raeburn 6848: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6849: return;
6850: }
6851: if (checkok == 1) {
1.570 raeburn 6852: callingForm.submit();
1.556 raeburn 6853: }
6854: }
6855:
6856: $newuserscript
6857:
6858: </script>
1.558 albertel 6859:
6860: $new_user_create
6861:
1.555 raeburn 6862: <table>
1.558 albertel 6863: <tr>
1.573 raeburn 6864: <td>$lt{'doma'}:</td>
6865: <td>$domform</td>
6866: </td>
6867: </tr>
6868: <tr>
6869: <td>$lt{'usr'}:</td>
1.563 raeburn 6870: <td>$srchbysel
6871: $srchtypesel
6872: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 6873: $srchinsel
1.563 raeburn 6874: </td>
6875: </tr>
1.555 raeburn 6876: </table>
6877: <br />
6878: END_BLOCK
1.558 albertel 6879:
1.555 raeburn 6880: return $output;
6881: }
6882:
1.612 raeburn 6883: sub user_rule_check {
1.615 raeburn 6884: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 6885: my $response;
6886: if (ref($usershash) eq 'HASH') {
6887: foreach my $user (keys(%{$usershash})) {
6888: my ($uname,$udom) = split(/:/,$user);
6889: next if ($udom eq '' || $uname eq '');
1.615 raeburn 6890: my ($id,$newuser);
1.612 raeburn 6891: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 6892: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 6893: $id = $usershash->{$user}->{'id'};
6894: }
6895: my $inst_response;
6896: if (ref($checks) eq 'HASH') {
6897: if (defined($checks->{'username'})) {
1.615 raeburn 6898: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6899: &Apache::lonnet::get_instuser($udom,$uname);
6900: } elsif (defined($checks->{'id'})) {
1.615 raeburn 6901: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6902: &Apache::lonnet::get_instuser($udom,undef,$id);
6903: }
1.615 raeburn 6904: } else {
6905: ($inst_response,%{$inst_results->{$user}}) =
6906: &Apache::lonnet::get_instuser($udom,$uname);
6907: return;
1.612 raeburn 6908: }
1.615 raeburn 6909: if (!$got_rules->{$udom}) {
1.612 raeburn 6910: my %domconfig = &Apache::lonnet::get_dom('configuration',
6911: ['usercreation'],$udom);
6912: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 6913: foreach my $item ('username','id') {
1.612 raeburn 6914: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6915: $$curr_rules{$udom}{$item} =
6916: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 6917: }
6918: }
6919: }
1.615 raeburn 6920: $got_rules->{$udom} = 1;
1.585 raeburn 6921: }
1.612 raeburn 6922: foreach my $item (keys(%{$checks})) {
6923: if (ref($$curr_rules{$udom}) eq 'HASH') {
6924: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
6925: if (@{$$curr_rules{$udom}{$item}} > 0) {
6926: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
6927: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
6928: if ($rule_check{$rule}) {
6929: $$rulematch{$user}{$item} = $rule;
6930: if ($inst_response eq 'ok') {
1.615 raeburn 6931: if (ref($inst_results) eq 'HASH') {
6932: if (ref($inst_results->{$user}) eq 'HASH') {
6933: if (keys(%{$inst_results->{$user}}) == 0) {
6934: $$alerts{$item}{$udom}{$uname} = 1;
6935: }
1.612 raeburn 6936: }
6937: }
1.615 raeburn 6938: }
6939: last;
1.585 raeburn 6940: }
6941: }
6942: }
6943: }
6944: }
6945: }
6946: }
6947: }
1.612 raeburn 6948: return;
6949: }
6950:
6951: sub user_rule_formats {
6952: my ($domain,$domdesc,$curr_rules,$check) = @_;
6953: my %text = (
6954: 'username' => 'Usernames',
6955: 'id' => 'IDs',
6956: );
6957: my $output;
6958: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
6959: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
6960: if (@{$ruleorder} > 0) {
6961: $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>';
6962: foreach my $rule (@{$ruleorder}) {
6963: if (ref($curr_rules) eq 'ARRAY') {
6964: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
6965: if (ref($rules->{$rule}) eq 'HASH') {
6966: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
6967: $rules->{$rule}{'desc'}.'</li>';
6968: }
6969: }
6970: }
6971: }
6972: $output .= '</ul>';
6973: }
6974: }
6975: return $output;
6976: }
6977:
6978: sub instrule_disallow_msg {
1.615 raeburn 6979: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 6980: my $response;
6981: my %text = (
6982: item => 'username',
6983: items => 'usernames',
6984: match => 'matches',
6985: do => 'does',
6986: action => 'a username',
6987: one => 'one',
6988: );
6989: if ($count > 1) {
6990: $text{'item'} = 'usernames';
6991: $text{'match'} ='match';
6992: $text{'do'} = 'do';
6993: $text{'action'} = 'usernames',
6994: $text{'one'} = 'ones';
6995: }
6996: if ($checkitem eq 'id') {
6997: $text{'items'} = 'IDs';
6998: $text{'item'} = 'ID';
6999: $text{'action'} = 'an ID';
1.615 raeburn 7000: if ($count > 1) {
7001: $text{'item'} = 'IDs';
7002: $text{'action'} = 'IDs';
7003: }
1.612 raeburn 7004: }
1.674 bisitz 7005: $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 7006: if ($mode eq 'upload') {
7007: if ($checkitem eq 'username') {
7008: $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'}.");
7009: } elsif ($checkitem eq 'id') {
1.674 bisitz 7010: $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 7011: }
1.669 raeburn 7012: } elsif ($mode eq 'selfcreate') {
7013: if ($checkitem eq 'id') {
7014: $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.");
7015: }
1.615 raeburn 7016: } else {
7017: if ($checkitem eq 'username') {
7018: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7019: } elsif ($checkitem eq 'id') {
7020: $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.");
7021: }
1.612 raeburn 7022: }
7023: return $response;
1.585 raeburn 7024: }
7025:
1.624 raeburn 7026: sub personal_data_fieldtitles {
7027: my %fieldtitles = &Apache::lonlocal::texthash (
7028: id => 'Student/Employee ID',
7029: permanentemail => 'E-mail address',
7030: lastname => 'Last Name',
7031: firstname => 'First Name',
7032: middlename => 'Middle Name',
7033: generation => 'Generation',
7034: gen => 'Generation',
7035: );
7036: return %fieldtitles;
7037: }
7038:
1.642 raeburn 7039: sub sorted_inst_types {
7040: my ($dom) = @_;
7041: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7042: my $othertitle = &mt('All users');
7043: if ($env{'request.course.id'}) {
1.668 raeburn 7044: $othertitle = &mt('Any users');
1.642 raeburn 7045: }
7046: my @types;
7047: if (ref($order) eq 'ARRAY') {
7048: @types = @{$order};
7049: }
7050: if (@types == 0) {
7051: if (ref($usertypes) eq 'HASH') {
7052: @types = sort(keys(%{$usertypes}));
7053: }
7054: }
7055: if (keys(%{$usertypes}) > 0) {
7056: $othertitle = &mt('Other users');
7057: }
7058: return ($othertitle,$usertypes,\@types);
7059: }
7060:
1.645 raeburn 7061: sub get_institutional_codes {
7062: my ($settings,$allcourses,$LC_code) = @_;
7063: # Get complete list of course sections to update
7064: my @currsections = ();
7065: my @currxlists = ();
7066: my $coursecode = $$settings{'internal.coursecode'};
7067:
7068: if ($$settings{'internal.sectionnums'} ne '') {
7069: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7070: }
7071:
7072: if ($$settings{'internal.crosslistings'} ne '') {
7073: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7074: }
7075:
7076: if (@currxlists > 0) {
7077: foreach (@currxlists) {
7078: if (m/^([^:]+):(\w*)$/) {
7079: unless (grep/^$1$/,@{$allcourses}) {
7080: push @{$allcourses},$1;
7081: $$LC_code{$1} = $2;
7082: }
7083: }
7084: }
7085: }
7086:
7087: if (@currsections > 0) {
7088: foreach (@currsections) {
7089: if (m/^(\w+):(\w*)$/) {
7090: my $sec = $coursecode.$1;
7091: my $lc_sec = $2;
7092: unless (grep/^$sec$/,@{$allcourses}) {
7093: push @{$allcourses},$sec;
7094: $$LC_code{$sec} = $lc_sec;
7095: }
7096: }
7097: }
7098: }
7099: return;
7100: }
7101:
1.112 bowersj2 7102: =pod
7103:
1.549 albertel 7104: =back
7105:
7106: =head1 HTTP Helpers
7107:
7108: =over 4
7109:
1.648 raeburn 7110: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7111:
1.258 albertel 7112: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7113: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7114: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7115:
7116: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7117: $possible_names is an ref to an array of form element names. As an example:
7118: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7119: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7120:
7121: =cut
1.1 albertel 7122:
1.6 albertel 7123: sub get_unprocessed_cgi {
1.25 albertel 7124: my ($query,$possible_names)= @_;
1.26 matthew 7125: # $Apache::lonxml::debug=1;
1.356 albertel 7126: foreach my $pair (split(/&/,$query)) {
7127: my ($name, $value) = split(/=/,$pair);
1.369 www 7128: $name = &unescape($name);
1.25 albertel 7129: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7130: $value =~ tr/+/ /;
7131: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7132: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7133: }
1.16 harris41 7134: }
1.6 albertel 7135: }
7136:
1.112 bowersj2 7137: =pod
7138:
1.648 raeburn 7139: =item * &cacheheader()
1.112 bowersj2 7140:
7141: returns cache-controlling header code
7142:
7143: =cut
7144:
1.7 albertel 7145: sub cacheheader {
1.258 albertel 7146: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7147: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7148: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7149: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7150: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7151: return $output;
1.7 albertel 7152: }
7153:
1.112 bowersj2 7154: =pod
7155:
1.648 raeburn 7156: =item * &no_cache($r)
1.112 bowersj2 7157:
7158: specifies header code to not have cache
7159:
7160: =cut
7161:
1.9 albertel 7162: sub no_cache {
1.216 albertel 7163: my ($r) = @_;
7164: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7165: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7166: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7167: $r->no_cache(1);
7168: $r->header_out("Expires" => $date);
7169: $r->header_out("Pragma" => "no-cache");
1.123 www 7170: }
7171:
7172: sub content_type {
1.181 albertel 7173: my ($r,$type,$charset) = @_;
1.299 foxr 7174: if ($r) {
7175: # Note that printout.pl calls this with undef for $r.
7176: &no_cache($r);
7177: }
1.258 albertel 7178: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7179: unless ($charset) {
7180: $charset=&Apache::lonlocal::current_encoding;
7181: }
7182: if ($charset) { $type.='; charset='.$charset; }
7183: if ($r) {
7184: $r->content_type($type);
7185: } else {
7186: print("Content-type: $type\n\n");
7187: }
1.9 albertel 7188: }
1.25 albertel 7189:
1.112 bowersj2 7190: =pod
7191:
1.648 raeburn 7192: =item * &add_to_env($name,$value)
1.112 bowersj2 7193:
1.258 albertel 7194: adds $name to the %env hash with value
1.112 bowersj2 7195: $value, if $name already exists, the entry is converted to an array
7196: reference and $value is added to the array.
7197:
7198: =cut
7199:
1.25 albertel 7200: sub add_to_env {
7201: my ($name,$value)=@_;
1.258 albertel 7202: if (defined($env{$name})) {
7203: if (ref($env{$name})) {
1.25 albertel 7204: #already have multiple values
1.258 albertel 7205: push(@{ $env{$name} },$value);
1.25 albertel 7206: } else {
7207: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7208: my $first=$env{$name};
7209: undef($env{$name});
7210: push(@{ $env{$name} },$first,$value);
1.25 albertel 7211: }
7212: } else {
1.258 albertel 7213: $env{$name}=$value;
1.25 albertel 7214: }
1.31 albertel 7215: }
1.149 albertel 7216:
7217: =pod
7218:
1.648 raeburn 7219: =item * &get_env_multiple($name)
1.149 albertel 7220:
1.258 albertel 7221: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7222: values may be defined and end up as an array ref.
7223:
7224: returns an array of values
7225:
7226: =cut
7227:
7228: sub get_env_multiple {
7229: my ($name) = @_;
7230: my @values;
1.258 albertel 7231: if (defined($env{$name})) {
1.149 albertel 7232: # exists is it an array
1.258 albertel 7233: if (ref($env{$name})) {
7234: @values=@{ $env{$name} };
1.149 albertel 7235: } else {
1.258 albertel 7236: $values[0]=$env{$name};
1.149 albertel 7237: }
7238: }
7239: return(@values);
7240: }
7241:
1.660 raeburn 7242: sub ask_for_embedded_content {
7243: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7244: my $upload_output = '
7245: <form name="upload_embedded" action="'.$actionurl.'"
7246: method="post" enctype="multipart/form-data">';
7247: $upload_output .= $state;
1.661 raeburn 7248: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7249:
7250: my $num = 0;
7251: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7252: $upload_output .= &start_data_table_row().
7253: '<td>'.$embed_file.'</td><td>';
7254: if ($args->{'ignore_remote_references'}
7255: && $embed_file =~ m{^\w+://}) {
7256: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7257: } elsif ($args->{'error_on_invalid_names'}
7258: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7259:
7260: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7261:
7262: } else {
7263: $upload_output .='
1.661 raeburn 7264: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7265: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7266: my $attrib = join(':',@{$$allfiles{$embed_file}});
7267: $upload_output .=
7268: "\n\t\t".
7269: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7270: $attrib.'" />';
7271: if (exists($$codebase{$embed_file})) {
7272: $upload_output .=
7273: "\n\t\t".
7274: '<input name="codebase_'.$num.'" type="hidden" value="'.
7275: &escape($$codebase{$embed_file}).'" />';
7276: }
7277: }
7278: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7279: $num++;
7280: }
7281: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7282: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7283: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7284: '.&mt('(only files for which a location has been provided will be uploaded)').'
7285: </form>';
7286: return $upload_output;
7287: }
7288:
1.661 raeburn 7289: sub upload_embedded {
7290: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7291: $current_disk_usage) = @_;
7292: my $output;
7293: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7294: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7295: my $orig_uploaded_filename =
7296: $env{'form.embedded_item_'.$i.'.filename'};
7297:
7298: $env{'form.embedded_orig_'.$i} =
7299: &unescape($env{'form.embedded_orig_'.$i});
7300: my ($path,$fname) =
7301: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7302: # no path, whole string is fname
7303: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7304:
7305: $path = $env{'form.currentpath'}.$path;
7306: $fname = &Apache::lonnet::clean_filename($fname);
7307: # See if there is anything left
7308: next if ($fname eq '');
7309:
7310: # Check if file already exists as a file or directory.
7311: my ($state,$msg);
7312: if ($context eq 'portfolio') {
7313: my $port_path = $dirpath;
7314: if ($group ne '') {
7315: $port_path = "groups/$group/$port_path";
7316: }
7317: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7318: $dir_root,$port_path,$disk_quota,
7319: $current_disk_usage,$uname,$udom);
7320: if ($state eq 'will_exceed_quota'
7321: || $state eq 'file_locked'
7322: || $state eq 'file_exists' ) {
7323: $output .= $msg;
7324: next;
7325: }
7326: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7327: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7328: if ($state eq 'exists') {
7329: $output .= $msg;
7330: next;
7331: }
7332: }
7333: # Check if extension is valid
7334: if (($fname =~ /\.(\w+)$/) &&
7335: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7336: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7337: next;
7338: } elsif (($fname =~ /\.(\w+)$/) &&
7339: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7340: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7341: next;
7342: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7343: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7344: next;
7345: }
7346:
7347: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7348: if ($context eq 'portfolio') {
7349: my $result=
7350: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7351: $dirpath.$path);
7352: if ($result !~ m|^/uploaded/|) {
7353: $output .= '<span class="LC_error">'
7354: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7355: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7356: .'</span><br />';
7357: next;
7358: } else {
7359: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7360: $path.$fname.'</span>').'</p>';
7361: }
7362: } else {
7363: # Save the file
7364: my $target = $env{'form.embedded_item_'.$i};
7365: my $fullpath = $dir_root.$dirpath.'/'.$path;
7366: my $dest = $fullpath.$fname;
7367: my $url = $url_root.$dirpath.'/'.$path.$fname;
7368: my @parts=split(/\//,$fullpath);
7369: my $count;
7370: my $filepath = $dir_root;
7371: for ($count=4;$count<=$#parts;$count++) {
7372: $filepath .= "/$parts[$count]";
7373: if ((-e $filepath)!=1) {
7374: mkdir($filepath,0770);
7375: }
7376: }
7377: my $fh;
7378: if (!open($fh,'>'.$dest)) {
7379: &Apache::lonnet::logthis('Failed to create '.$dest);
7380: $output .= '<span class="LC_error">'.
7381: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7382: '</span><br />';
7383: } else {
7384: if (!print $fh $env{'form.embedded_item_'.$i}) {
7385: &Apache::lonnet::logthis('Failed to write to '.$dest);
7386: $output .= '<span class="LC_error">'.
7387: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7388: '</span><br />';
7389: } else {
7390: if ($context eq 'testbank') {
7391: $output .= &mt('Embedded file uploaded successfully:').
7392: ' <a href="'.$url.'">'.
7393: $orig_uploaded_filename.'</a><br />';
7394: } else {
7395: $output .= '<font size="+2">'.
7396: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7397: $orig_uploaded_filename.'</a>').'</font><br />';
7398: }
7399: }
7400: close($fh);
7401: }
7402: }
7403: }
7404: return $output;
7405: }
7406:
7407: sub check_for_existing {
7408: my ($path,$fname,$element) = @_;
7409: my ($state,$msg);
7410: if (-d $path.'/'.$fname) {
7411: $state = 'exists';
7412: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7413: } elsif (-e $path.'/'.$fname) {
7414: $state = 'exists';
7415: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7416: }
7417: if ($state eq 'exists') {
7418: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7419: }
7420: return ($state,$msg);
7421: }
7422:
7423: sub check_for_upload {
7424: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7425: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7426: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7427: my $getpropath = 1;
7428: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7429: $getpropath);
7430: my $found_file = 0;
7431: my $locked_file = 0;
7432: foreach my $line (@dir_list) {
7433: my ($file_name)=split(/\&/,$line,2);
7434: if ($file_name eq $fname){
7435: $file_name = $path.$file_name;
7436: if ($group ne '') {
7437: $file_name = $group.$file_name;
7438: }
7439: $found_file = 1;
7440: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7441: $locked_file = 1;
7442: }
7443: }
7444: }
7445: if (($current_disk_usage + $filesize) > $disk_quota){
7446: my $msg = '<span class="LC_error">'.
7447: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7448: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7449: return ('will_exceed_quota',$msg);
7450: } elsif ($found_file) {
7451: if ($locked_file) {
7452: my $msg = '<span class="LC_error">';
7453: $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>');
7454: $msg .= '</span><br />';
7455: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7456: return ('file_locked',$msg);
7457: } else {
7458: my $msg = '<span class="LC_error">';
7459: $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'});
7460: $msg .= '</span>';
7461: $msg .= '<br />';
7462: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7463: return ('file_exists',$msg);
7464: }
7465: }
7466: }
7467:
1.31 albertel 7468:
1.41 ng 7469: =pod
1.45 matthew 7470:
1.464 albertel 7471: =back
1.41 ng 7472:
1.112 bowersj2 7473: =head1 CSV Upload/Handling functions
1.38 albertel 7474:
1.41 ng 7475: =over 4
7476:
1.648 raeburn 7477: =item * &upfile_store($r)
1.41 ng 7478:
7479: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7480: needs $env{'form.upfile'}
1.41 ng 7481: returns $datatoken to be put into hidden field
7482:
7483: =cut
1.31 albertel 7484:
7485: sub upfile_store {
7486: my $r=shift;
1.258 albertel 7487: $env{'form.upfile'}=~s/\r/\n/gs;
7488: $env{'form.upfile'}=~s/\f/\n/gs;
7489: $env{'form.upfile'}=~s/\n+/\n/gs;
7490: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7491:
1.258 albertel 7492: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7493: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7494: {
1.158 raeburn 7495: my $datafile = $r->dir_config('lonDaemons').
7496: '/tmp/'.$datatoken.'.tmp';
7497: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7498: print $fh $env{'form.upfile'};
1.158 raeburn 7499: close($fh);
7500: }
1.31 albertel 7501: }
7502: return $datatoken;
7503: }
7504:
1.56 matthew 7505: =pod
7506:
1.648 raeburn 7507: =item * &load_tmp_file($r)
1.41 ng 7508:
7509: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7510: needs $env{'form.datatoken'},
7511: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7512:
7513: =cut
1.31 albertel 7514:
7515: sub load_tmp_file {
7516: my $r=shift;
7517: my @studentdata=();
7518: {
1.158 raeburn 7519: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7520: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7521: if ( open(my $fh,"<$studentfile") ) {
7522: @studentdata=<$fh>;
7523: close($fh);
7524: }
1.31 albertel 7525: }
1.258 albertel 7526: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7527: }
7528:
1.56 matthew 7529: =pod
7530:
1.648 raeburn 7531: =item * &upfile_record_sep()
1.41 ng 7532:
7533: Separate uploaded file into records
7534: returns array of records,
1.258 albertel 7535: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7536:
7537: =cut
1.31 albertel 7538:
7539: sub upfile_record_sep {
1.258 albertel 7540: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7541: } else {
1.248 albertel 7542: my @records;
1.258 albertel 7543: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7544: if ($line=~/^\s*$/) { next; }
7545: push(@records,$line);
7546: }
7547: return @records;
1.31 albertel 7548: }
7549: }
7550:
1.56 matthew 7551: =pod
7552:
1.648 raeburn 7553: =item * &record_sep($record)
1.41 ng 7554:
1.258 albertel 7555: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7556:
7557: =cut
7558:
1.263 www 7559: sub takeleft {
7560: my $index=shift;
7561: return substr('0000'.$index,-4,4);
7562: }
7563:
1.31 albertel 7564: sub record_sep {
7565: my $record=shift;
7566: my %components=();
1.258 albertel 7567: if ($env{'form.upfiletype'} eq 'xml') {
7568: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7569: my $i=0;
1.356 albertel 7570: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7571: $field=~s/^(\"|\')//;
7572: $field=~s/(\"|\')$//;
1.263 www 7573: $components{&takeleft($i)}=$field;
1.31 albertel 7574: $i++;
7575: }
1.258 albertel 7576: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7577: my $i=0;
1.356 albertel 7578: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7579: $field=~s/^(\"|\')//;
7580: $field=~s/(\"|\')$//;
1.263 www 7581: $components{&takeleft($i)}=$field;
1.31 albertel 7582: $i++;
7583: }
7584: } else {
1.561 www 7585: my $separator=',';
1.480 banghart 7586: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7587: $separator=';';
1.480 banghart 7588: }
1.31 albertel 7589: my $i=0;
1.561 www 7590: # the character we are looking for to indicate the end of a quote or a record
7591: my $looking_for=$separator;
7592: # do not add the characters to the fields
7593: my $ignore=0;
7594: # we just encountered a separator (or the beginning of the record)
7595: my $just_found_separator=1;
7596: # store the field we are working on here
7597: my $field='';
7598: # work our way through all characters in record
7599: foreach my $character ($record=~/(.)/g) {
7600: if ($character eq $looking_for) {
7601: if ($character ne $separator) {
7602: # Found the end of a quote, again looking for separator
7603: $looking_for=$separator;
7604: $ignore=1;
7605: } else {
7606: # Found a separator, store away what we got
7607: $components{&takeleft($i)}=$field;
7608: $i++;
7609: $just_found_separator=1;
7610: $ignore=0;
7611: $field='';
7612: }
7613: next;
7614: }
7615: # single or double quotation marks after a separator indicate beginning of a quote
7616: # we are now looking for the end of the quote and need to ignore separators
7617: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7618: $looking_for=$character;
7619: next;
7620: }
7621: # ignore would be true after we reached the end of a quote
7622: if ($ignore) { next; }
7623: if (($just_found_separator) && ($character=~/\s/)) { next; }
7624: $field.=$character;
7625: $just_found_separator=0;
1.31 albertel 7626: }
1.561 www 7627: # catch the very last entry, since we never encountered the separator
7628: $components{&takeleft($i)}=$field;
1.31 albertel 7629: }
7630: return %components;
7631: }
7632:
1.144 matthew 7633: ######################################################
7634: ######################################################
7635:
1.56 matthew 7636: =pod
7637:
1.648 raeburn 7638: =item * &upfile_select_html()
1.41 ng 7639:
1.144 matthew 7640: Return HTML code to select a file from the users machine and specify
7641: the file type.
1.41 ng 7642:
7643: =cut
7644:
1.144 matthew 7645: ######################################################
7646: ######################################################
1.31 albertel 7647: sub upfile_select_html {
1.144 matthew 7648: my %Types = (
7649: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7650: semisv => &mt('Semicolon separated values'),
1.144 matthew 7651: space => &mt('Space separated'),
7652: tab => &mt('Tabulator separated'),
7653: # xml => &mt('HTML/XML'),
7654: );
7655: my $Str = '<input type="file" name="upfile" size="50" />'.
7656: '<br />Type: <select name="upfiletype">';
7657: foreach my $type (sort(keys(%Types))) {
7658: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7659: }
7660: $Str .= "</select>\n";
7661: return $Str;
1.31 albertel 7662: }
7663:
1.301 albertel 7664: sub get_samples {
7665: my ($records,$toget) = @_;
7666: my @samples=({});
7667: my $got=0;
7668: foreach my $rec (@$records) {
7669: my %temp = &record_sep($rec);
7670: if (! grep(/\S/, values(%temp))) { next; }
7671: if (%temp) {
7672: $samples[$got]=\%temp;
7673: $got++;
7674: if ($got == $toget) { last; }
7675: }
7676: }
7677: return \@samples;
7678: }
7679:
1.144 matthew 7680: ######################################################
7681: ######################################################
7682:
1.56 matthew 7683: =pod
7684:
1.648 raeburn 7685: =item * &csv_print_samples($r,$records)
1.41 ng 7686:
7687: Prints a table of sample values from each column uploaded $r is an
7688: Apache Request ref, $records is an arrayref from
7689: &Apache::loncommon::upfile_record_sep
7690:
7691: =cut
7692:
1.144 matthew 7693: ######################################################
7694: ######################################################
1.31 albertel 7695: sub csv_print_samples {
7696: my ($r,$records) = @_;
1.662 bisitz 7697: my $samples = &get_samples($records,5);
1.301 albertel 7698:
1.594 raeburn 7699: $r->print(&mt('Samples').'<br />'.&start_data_table().
7700: &start_data_table_header_row());
1.356 albertel 7701: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7702: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 7703: $r->print(&end_data_table_header_row());
1.301 albertel 7704: foreach my $hash (@$samples) {
1.594 raeburn 7705: $r->print(&start_data_table_row());
1.356 albertel 7706: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7707: $r->print('<td>');
1.356 albertel 7708: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 7709: $r->print('</td>');
7710: }
1.594 raeburn 7711: $r->print(&end_data_table_row());
1.31 albertel 7712: }
1.594 raeburn 7713: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 7714: }
7715:
1.144 matthew 7716: ######################################################
7717: ######################################################
7718:
1.56 matthew 7719: =pod
7720:
1.648 raeburn 7721: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 7722:
7723: Prints a table to create associations between values and table columns.
1.144 matthew 7724:
1.41 ng 7725: $r is an Apache Request ref,
7726: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7727: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7728:
7729: =cut
7730:
1.144 matthew 7731: ######################################################
7732: ######################################################
1.31 albertel 7733: sub csv_print_select_table {
7734: my ($r,$records,$d) = @_;
1.301 albertel 7735: my $i=0;
7736: my $samples = &get_samples($records,1);
1.144 matthew 7737: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7738: &start_data_table().&start_data_table_header_row().
1.144 matthew 7739: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7740: '<th>'.&mt('Column').'</th>'.
7741: &end_data_table_header_row()."\n");
1.356 albertel 7742: foreach my $array_ref (@$d) {
7743: my ($value,$display,$defaultcol)=@{ $array_ref };
1.689 bisitz 7744: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 7745:
7746: $r->print('<td><select name=f'.$i.
1.32 matthew 7747: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7748: $r->print('<option value="none"></option>');
1.356 albertel 7749: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7750: $r->print('<option value="'.$sample.'"'.
7751: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 7752: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 7753: }
1.594 raeburn 7754: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7755: $i++;
7756: }
1.594 raeburn 7757: $r->print(&end_data_table());
1.31 albertel 7758: $i--;
7759: return $i;
7760: }
1.56 matthew 7761:
1.144 matthew 7762: ######################################################
7763: ######################################################
7764:
1.56 matthew 7765: =pod
1.31 albertel 7766:
1.648 raeburn 7767: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 7768:
7769: Prints a table of sample values from the upload and can make associate samples to internal names.
7770:
7771: $r is an Apache Request ref,
7772: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7773: $d is an array of 2 element arrays (internal name, displayed name)
7774:
7775: =cut
7776:
1.144 matthew 7777: ######################################################
7778: ######################################################
1.31 albertel 7779: sub csv_samples_select_table {
7780: my ($r,$records,$d) = @_;
7781: my $i=0;
1.144 matthew 7782: #
1.662 bisitz 7783: my $max_samples = 5;
7784: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 7785: $r->print(&start_data_table().
7786: &start_data_table_header_row().'<th>'.
7787: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7788: &end_data_table_header_row());
1.301 albertel 7789:
7790: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7791: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7792: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7793: foreach my $option (@$d) {
7794: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7795: $r->print('<option value="'.$value.'"'.
1.253 albertel 7796: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7797: $display.'</option>');
1.31 albertel 7798: }
7799: $r->print('</select></td><td>');
1.662 bisitz 7800: foreach my $line (0..($max_samples-1)) {
1.301 albertel 7801: if (defined($samples->[$line]{$key})) {
7802: $r->print($samples->[$line]{$key}."<br />\n");
7803: }
7804: }
1.594 raeburn 7805: $r->print('</td>'.&end_data_table_row());
1.31 albertel 7806: $i++;
7807: }
1.594 raeburn 7808: $r->print(&end_data_table());
1.31 albertel 7809: $i--;
7810: return($i);
1.115 matthew 7811: }
7812:
1.144 matthew 7813: ######################################################
7814: ######################################################
7815:
1.115 matthew 7816: =pod
7817:
1.648 raeburn 7818: =item * &clean_excel_name($name)
1.115 matthew 7819:
7820: Returns a replacement for $name which does not contain any illegal characters.
7821:
7822: =cut
7823:
1.144 matthew 7824: ######################################################
7825: ######################################################
1.115 matthew 7826: sub clean_excel_name {
7827: my ($name) = @_;
7828: $name =~ s/[:\*\?\/\\]//g;
7829: if (length($name) > 31) {
7830: $name = substr($name,0,31);
7831: }
7832: return $name;
1.25 albertel 7833: }
1.84 albertel 7834:
1.85 albertel 7835: =pod
7836:
1.648 raeburn 7837: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 7838:
7839: Returns either 1 or undef
7840:
7841: 1 if the part is to be hidden, undef if it is to be shown
7842:
7843: Arguments are:
7844:
7845: $id the id of the part to be checked
7846: $symb, optional the symb of the resource to check
7847: $udom, optional the domain of the user to check for
7848: $uname, optional the username of the user to check for
7849:
7850: =cut
1.84 albertel 7851:
7852: sub check_if_partid_hidden {
7853: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 7854: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 7855: $symb,$udom,$uname);
1.141 albertel 7856: my $truth=1;
7857: #if the string starts with !, then the list is the list to show not hide
7858: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 7859: my @hiddenlist=split(/,/,$hiddenparts);
7860: foreach my $checkid (@hiddenlist) {
1.141 albertel 7861: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 7862: }
1.141 albertel 7863: return !$truth;
1.84 albertel 7864: }
1.127 matthew 7865:
1.138 matthew 7866:
7867: ############################################################
7868: ############################################################
7869:
7870: =pod
7871:
1.157 matthew 7872: =back
7873:
1.138 matthew 7874: =head1 cgi-bin script and graphing routines
7875:
1.157 matthew 7876: =over 4
7877:
1.648 raeburn 7878: =item * &get_cgi_id()
1.138 matthew 7879:
7880: Inputs: none
7881:
7882: Returns an id which can be used to pass environment variables
7883: to various cgi-bin scripts. These environment variables will
7884: be removed from the users environment after a given time by
7885: the routine &Apache::lonnet::transfer_profile_to_env.
7886:
7887: =cut
7888:
7889: ############################################################
7890: ############################################################
1.152 albertel 7891: my $uniq=0;
1.136 matthew 7892: sub get_cgi_id {
1.154 albertel 7893: $uniq=($uniq+1)%100000;
1.280 albertel 7894: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 7895: }
7896:
1.127 matthew 7897: ############################################################
7898: ############################################################
7899:
7900: =pod
7901:
1.648 raeburn 7902: =item * &DrawBarGraph()
1.127 matthew 7903:
1.138 matthew 7904: Facilitates the plotting of data in a (stacked) bar graph.
7905: Puts plot definition data into the users environment in order for
7906: graph.png to plot it. Returns an <img> tag for the plot.
7907: The bars on the plot are labeled '1','2',...,'n'.
7908:
7909: Inputs:
7910:
7911: =over 4
7912:
7913: =item $Title: string, the title of the plot
7914:
7915: =item $xlabel: string, text describing the X-axis of the plot
7916:
7917: =item $ylabel: string, text describing the Y-axis of the plot
7918:
7919: =item $Max: scalar, the maximum Y value to use in the plot
7920: If $Max is < any data point, the graph will not be rendered.
7921:
1.140 matthew 7922: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 7923: they are plotted. If undefined, default values will be used.
7924:
1.178 matthew 7925: =item $labels: array ref holding the labels to use on the x-axis for the bars.
7926:
1.138 matthew 7927: =item @Values: An array of array references. Each array reference holds data
7928: to be plotted in a stacked bar chart.
7929:
1.239 matthew 7930: =item If the final element of @Values is a hash reference the key/value
7931: pairs will be added to the graph definition.
7932:
1.138 matthew 7933: =back
7934:
7935: Returns:
7936:
7937: An <img> tag which references graph.png and the appropriate identifying
7938: information for the plot.
7939:
1.127 matthew 7940: =cut
7941:
7942: ############################################################
7943: ############################################################
1.134 matthew 7944: sub DrawBarGraph {
1.178 matthew 7945: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 7946: #
7947: if (! defined($colors)) {
7948: $colors = ['#33ff00',
7949: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
7950: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
7951: ];
7952: }
1.228 matthew 7953: my $extra_settings = {};
7954: if (ref($Values[-1]) eq 'HASH') {
7955: $extra_settings = pop(@Values);
7956: }
1.127 matthew 7957: #
1.136 matthew 7958: my $identifier = &get_cgi_id();
7959: my $id = 'cgi.'.$identifier;
1.129 matthew 7960: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 7961: return '';
7962: }
1.225 matthew 7963: #
7964: my @Labels;
7965: if (defined($labels)) {
7966: @Labels = @$labels;
7967: } else {
7968: for (my $i=0;$i<@{$Values[0]};$i++) {
7969: push (@Labels,$i+1);
7970: }
7971: }
7972: #
1.129 matthew 7973: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 7974: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 7975: my %ValuesHash;
7976: my $NumSets=1;
7977: foreach my $array (@Values) {
7978: next if (! ref($array));
1.136 matthew 7979: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 7980: join(',',@$array);
1.129 matthew 7981: }
1.127 matthew 7982: #
1.136 matthew 7983: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 7984: if ($NumBars < 3) {
7985: $width = 120+$NumBars*32;
1.220 matthew 7986: $xskip = 1;
1.225 matthew 7987: $bar_width = 30;
7988: } elsif ($NumBars < 5) {
7989: $width = 120+$NumBars*20;
7990: $xskip = 1;
7991: $bar_width = 20;
1.220 matthew 7992: } elsif ($NumBars < 10) {
1.136 matthew 7993: $width = 120+$NumBars*15;
7994: $xskip = 1;
7995: $bar_width = 15;
7996: } elsif ($NumBars <= 25) {
7997: $width = 120+$NumBars*11;
7998: $xskip = 5;
7999: $bar_width = 8;
8000: } elsif ($NumBars <= 50) {
8001: $width = 120+$NumBars*8;
8002: $xskip = 5;
8003: $bar_width = 4;
8004: } else {
8005: $width = 120+$NumBars*8;
8006: $xskip = 5;
8007: $bar_width = 4;
8008: }
8009: #
1.137 matthew 8010: $Max = 1 if ($Max < 1);
8011: if ( int($Max) < $Max ) {
8012: $Max++;
8013: $Max = int($Max);
8014: }
1.127 matthew 8015: $Title = '' if (! defined($Title));
8016: $xlabel = '' if (! defined($xlabel));
8017: $ylabel = '' if (! defined($ylabel));
1.369 www 8018: $ValuesHash{$id.'.title'} = &escape($Title);
8019: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8020: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8021: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8022: $ValuesHash{$id.'.NumBars'} = $NumBars;
8023: $ValuesHash{$id.'.NumSets'} = $NumSets;
8024: $ValuesHash{$id.'.PlotType'} = 'bar';
8025: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8026: $ValuesHash{$id.'.height'} = $height;
8027: $ValuesHash{$id.'.width'} = $width;
8028: $ValuesHash{$id.'.xskip'} = $xskip;
8029: $ValuesHash{$id.'.bar_width'} = $bar_width;
8030: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8031: #
1.228 matthew 8032: # Deal with other parameters
8033: while (my ($key,$value) = each(%$extra_settings)) {
8034: $ValuesHash{$id.'.'.$key} = $value;
8035: }
8036: #
1.646 raeburn 8037: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8038: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8039: }
8040:
8041: ############################################################
8042: ############################################################
8043:
8044: =pod
8045:
1.648 raeburn 8046: =item * &DrawXYGraph()
1.137 matthew 8047:
1.138 matthew 8048: Facilitates the plotting of data in an XY graph.
8049: Puts plot definition data into the users environment in order for
8050: graph.png to plot it. Returns an <img> tag for the plot.
8051:
8052: Inputs:
8053:
8054: =over 4
8055:
8056: =item $Title: string, the title of the plot
8057:
8058: =item $xlabel: string, text describing the X-axis of the plot
8059:
8060: =item $ylabel: string, text describing the Y-axis of the plot
8061:
8062: =item $Max: scalar, the maximum Y value to use in the plot
8063: If $Max is < any data point, the graph will not be rendered.
8064:
8065: =item $colors: Array ref containing the hex color codes for the data to be
8066: plotted in. If undefined, default values will be used.
8067:
8068: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8069:
8070: =item $Ydata: Array ref containing Array refs.
1.185 www 8071: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8072:
8073: =item %Values: hash indicating or overriding any default values which are
8074: passed to graph.png.
8075: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8076:
8077: =back
8078:
8079: Returns:
8080:
8081: An <img> tag which references graph.png and the appropriate identifying
8082: information for the plot.
8083:
1.137 matthew 8084: =cut
8085:
8086: ############################################################
8087: ############################################################
8088: sub DrawXYGraph {
8089: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8090: #
8091: # Create the identifier for the graph
8092: my $identifier = &get_cgi_id();
8093: my $id = 'cgi.'.$identifier;
8094: #
8095: $Title = '' if (! defined($Title));
8096: $xlabel = '' if (! defined($xlabel));
8097: $ylabel = '' if (! defined($ylabel));
8098: my %ValuesHash =
8099: (
1.369 www 8100: $id.'.title' => &escape($Title),
8101: $id.'.xlabel' => &escape($xlabel),
8102: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8103: $id.'.y_max_value'=> $Max,
8104: $id.'.labels' => join(',',@$Xlabels),
8105: $id.'.PlotType' => 'XY',
8106: );
8107: #
8108: if (defined($colors) && ref($colors) eq 'ARRAY') {
8109: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8110: }
8111: #
8112: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8113: return '';
8114: }
8115: my $NumSets=1;
1.138 matthew 8116: foreach my $array (@{$Ydata}){
1.137 matthew 8117: next if (! ref($array));
8118: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8119: }
1.138 matthew 8120: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8121: #
8122: # Deal with other parameters
8123: while (my ($key,$value) = each(%Values)) {
8124: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8125: }
8126: #
1.646 raeburn 8127: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8128: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8129: }
8130:
8131: ############################################################
8132: ############################################################
8133:
8134: =pod
8135:
1.648 raeburn 8136: =item * &DrawXYYGraph()
1.138 matthew 8137:
8138: Facilitates the plotting of data in an XY graph with two Y axes.
8139: Puts plot definition data into the users environment in order for
8140: graph.png to plot it. Returns an <img> tag for the plot.
8141:
8142: Inputs:
8143:
8144: =over 4
8145:
8146: =item $Title: string, the title of the plot
8147:
8148: =item $xlabel: string, text describing the X-axis of the plot
8149:
8150: =item $ylabel: string, text describing the Y-axis of the plot
8151:
8152: =item $colors: Array ref containing the hex color codes for the data to be
8153: plotted in. If undefined, default values will be used.
8154:
8155: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8156:
8157: =item $Ydata1: The first data set
8158:
8159: =item $Min1: The minimum value of the left Y-axis
8160:
8161: =item $Max1: The maximum value of the left Y-axis
8162:
8163: =item $Ydata2: The second data set
8164:
8165: =item $Min2: The minimum value of the right Y-axis
8166:
8167: =item $Max2: The maximum value of the left Y-axis
8168:
8169: =item %Values: hash indicating or overriding any default values which are
8170: passed to graph.png.
8171: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8172:
8173: =back
8174:
8175: Returns:
8176:
8177: An <img> tag which references graph.png and the appropriate identifying
8178: information for the plot.
1.136 matthew 8179:
8180: =cut
8181:
8182: ############################################################
8183: ############################################################
1.137 matthew 8184: sub DrawXYYGraph {
8185: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8186: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8187: #
8188: # Create the identifier for the graph
8189: my $identifier = &get_cgi_id();
8190: my $id = 'cgi.'.$identifier;
8191: #
8192: $Title = '' if (! defined($Title));
8193: $xlabel = '' if (! defined($xlabel));
8194: $ylabel = '' if (! defined($ylabel));
8195: my %ValuesHash =
8196: (
1.369 www 8197: $id.'.title' => &escape($Title),
8198: $id.'.xlabel' => &escape($xlabel),
8199: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8200: $id.'.labels' => join(',',@$Xlabels),
8201: $id.'.PlotType' => 'XY',
8202: $id.'.NumSets' => 2,
1.137 matthew 8203: $id.'.two_axes' => 1,
8204: $id.'.y1_max_value' => $Max1,
8205: $id.'.y1_min_value' => $Min1,
8206: $id.'.y2_max_value' => $Max2,
8207: $id.'.y2_min_value' => $Min2,
1.136 matthew 8208: );
8209: #
1.137 matthew 8210: if (defined($colors) && ref($colors) eq 'ARRAY') {
8211: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8212: }
8213: #
8214: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8215: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8216: return '';
8217: }
8218: my $NumSets=1;
1.137 matthew 8219: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8220: next if (! ref($array));
8221: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8222: }
8223: #
8224: # Deal with other parameters
8225: while (my ($key,$value) = each(%Values)) {
8226: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8227: }
8228: #
1.646 raeburn 8229: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8230: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8231: }
8232:
8233: ############################################################
8234: ############################################################
8235:
8236: =pod
8237:
1.157 matthew 8238: =back
8239:
1.139 matthew 8240: =head1 Statistics helper routines?
8241:
8242: Bad place for them but what the hell.
8243:
1.157 matthew 8244: =over 4
8245:
1.648 raeburn 8246: =item * &chartlink()
1.139 matthew 8247:
8248: Returns a link to the chart for a specific student.
8249:
8250: Inputs:
8251:
8252: =over 4
8253:
8254: =item $linktext: The text of the link
8255:
8256: =item $sname: The students username
8257:
8258: =item $sdomain: The students domain
8259:
8260: =back
8261:
1.157 matthew 8262: =back
8263:
1.139 matthew 8264: =cut
8265:
8266: ############################################################
8267: ############################################################
8268: sub chartlink {
8269: my ($linktext, $sname, $sdomain) = @_;
8270: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8271: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8272: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8273: '">'.$linktext.'</a>';
1.153 matthew 8274: }
8275:
8276: #######################################################
8277: #######################################################
8278:
8279: =pod
8280:
8281: =head1 Course Environment Routines
1.157 matthew 8282:
8283: =over 4
1.153 matthew 8284:
1.648 raeburn 8285: =item * &restore_course_settings()
1.153 matthew 8286:
1.648 raeburn 8287: =item * &store_course_settings()
1.153 matthew 8288:
8289: Restores/Store indicated form parameters from the course environment.
8290: Will not overwrite existing values of the form parameters.
8291:
8292: Inputs:
8293: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8294:
8295: a hash ref describing the data to be stored. For example:
8296:
8297: %Save_Parameters = ('Status' => 'scalar',
8298: 'chartoutputmode' => 'scalar',
8299: 'chartoutputdata' => 'scalar',
8300: 'Section' => 'array',
1.373 raeburn 8301: 'Group' => 'array',
1.153 matthew 8302: 'StudentData' => 'array',
8303: 'Maps' => 'array');
8304:
8305: Returns: both routines return nothing
8306:
1.631 raeburn 8307: =back
8308:
1.153 matthew 8309: =cut
8310:
8311: #######################################################
8312: #######################################################
8313: sub store_course_settings {
1.496 albertel 8314: return &store_settings($env{'request.course.id'},@_);
8315: }
8316:
8317: sub store_settings {
1.153 matthew 8318: # save to the environment
8319: # appenv the same items, just to be safe
1.300 albertel 8320: my $udom = $env{'user.domain'};
8321: my $uname = $env{'user.name'};
1.496 albertel 8322: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8323: my %SaveHash;
8324: my %AppHash;
8325: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8326: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8327: my $envname = 'environment.'.$basename;
1.258 albertel 8328: if (exists($env{'form.'.$setting})) {
1.153 matthew 8329: # Save this value away
8330: if ($type eq 'scalar' &&
1.258 albertel 8331: (! exists($env{$envname}) ||
8332: $env{$envname} ne $env{'form.'.$setting})) {
8333: $SaveHash{$basename} = $env{'form.'.$setting};
8334: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8335: } elsif ($type eq 'array') {
8336: my $stored_form;
1.258 albertel 8337: if (ref($env{'form.'.$setting})) {
1.153 matthew 8338: $stored_form = join(',',
8339: map {
1.369 www 8340: &escape($_);
1.258 albertel 8341: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8342: } else {
8343: $stored_form =
1.369 www 8344: &escape($env{'form.'.$setting});
1.153 matthew 8345: }
8346: # Determine if the array contents are the same.
1.258 albertel 8347: if ($stored_form ne $env{$envname}) {
1.153 matthew 8348: $SaveHash{$basename} = $stored_form;
8349: $AppHash{$envname} = $stored_form;
8350: }
8351: }
8352: }
8353: }
8354: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8355: $udom,$uname);
1.153 matthew 8356: if ($put_result !~ /^(ok|delayed)/) {
8357: &Apache::lonnet::logthis('unable to save form parameters, '.
8358: 'got error:'.$put_result);
8359: }
8360: # Make sure these settings stick around in this session, too
1.646 raeburn 8361: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8362: return;
8363: }
8364:
8365: sub restore_course_settings {
1.499 albertel 8366: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8367: }
8368:
8369: sub restore_settings {
8370: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8371: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8372: next if (exists($env{'form.'.$setting}));
1.496 albertel 8373: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8374: '.'.$setting;
1.258 albertel 8375: if (exists($env{$envname})) {
1.153 matthew 8376: if ($type eq 'scalar') {
1.258 albertel 8377: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8378: } elsif ($type eq 'array') {
1.258 albertel 8379: $env{'form.'.$setting} = [
1.153 matthew 8380: map {
1.369 www 8381: &unescape($_);
1.258 albertel 8382: } split(',',$env{$envname})
1.153 matthew 8383: ];
8384: }
8385: }
8386: }
1.127 matthew 8387: }
8388:
1.618 raeburn 8389: #######################################################
8390: #######################################################
8391:
8392: =pod
8393:
8394: =head1 Domain E-mail Routines
8395:
8396: =over 4
8397:
1.648 raeburn 8398: =item * &build_recipient_list()
1.618 raeburn 8399:
8400: Build recipient lists for three types of e-mail:
8401: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8402: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8403:
8404: Inputs:
1.619 raeburn 8405: defmail (scalar - email address of default recipient),
1.618 raeburn 8406: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8407: defdom (domain for which to retrieve configuration settings),
8408: origmail (scalar - email address of recipient from loncapa.conf,
8409: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8410:
1.655 raeburn 8411: Returns: comma separated list of addresses to which to send e-mail.
8412:
8413: =back
1.618 raeburn 8414:
8415: =cut
8416:
8417: ############################################################
8418: ############################################################
8419: sub build_recipient_list {
1.619 raeburn 8420: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8421: my @recipients;
8422: my $otheremails;
8423: my %domconfig =
8424: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8425: if (ref($domconfig{'contacts'}) eq 'HASH') {
8426: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8427: my @contacts = ('adminemail','supportemail');
8428: foreach my $item (@contacts) {
8429: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8430: my $addr = $domconfig{'contacts'}{$item};
8431: if (!grep(/^\Q$addr\E$/,@recipients)) {
8432: push(@recipients,$addr);
8433: }
1.618 raeburn 8434: }
8435: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8436: }
8437: }
1.619 raeburn 8438: } elsif ($origmail ne '') {
8439: push(@recipients,$origmail);
1.618 raeburn 8440: }
1.688 raeburn 8441: if (defined($defmail)) {
8442: if ($defmail ne '') {
8443: push(@recipients,$defmail);
8444: }
1.618 raeburn 8445: }
8446: if ($otheremails) {
1.619 raeburn 8447: my @others;
8448: if ($otheremails =~ /,/) {
8449: @others = split(/,/,$otheremails);
1.618 raeburn 8450: } else {
1.619 raeburn 8451: push(@others,$otheremails);
8452: }
8453: foreach my $addr (@others) {
8454: if (!grep(/^\Q$addr\E$/,@recipients)) {
8455: push(@recipients,$addr);
8456: }
1.618 raeburn 8457: }
8458: }
1.619 raeburn 8459: my $recipientlist = join(',',@recipients);
1.618 raeburn 8460: return $recipientlist;
8461: }
8462:
1.127 matthew 8463: ############################################################
8464: ############################################################
1.154 albertel 8465:
1.655 raeburn 8466: =pod
8467:
8468: =head1 Course Catalog Routines
8469:
8470: =over 4
8471:
8472: =item * &gather_categories()
8473:
8474: Converts category definitions - keys of categories hash stored in
8475: coursecategories in configuration.db on the primary library server in a
8476: domain - to an array. Also generates javascript and idx hash used to
8477: generate Domain Coordinator interface for editing Course Categories.
8478:
8479: Inputs:
1.663 raeburn 8480:
1.655 raeburn 8481: categories (reference to hash of category definitions).
1.663 raeburn 8482:
1.655 raeburn 8483: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8484: categories and subcategories).
1.663 raeburn 8485:
1.655 raeburn 8486: idx (reference to hash of counters used in Domain Coordinator interface for
8487: editing Course Categories).
1.663 raeburn 8488:
1.655 raeburn 8489: jsarray (reference to array of categories used to create Javascript arrays for
8490: Domain Coordinator interface for editing Course Categories).
8491:
8492: Returns: nothing
8493:
8494: Side effects: populates cats, idx and jsarray.
8495:
8496: =cut
8497:
8498: sub gather_categories {
8499: my ($categories,$cats,$idx,$jsarray) = @_;
8500: my %counters;
8501: my $num = 0;
8502: foreach my $item (keys(%{$categories})) {
8503: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8504: if ($container eq '' && $depth == 0) {
8505: $cats->[$depth][$categories->{$item}] = $cat;
8506: } else {
8507: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8508: }
8509: my ($escitem,$tail) = split(/:/,$item,2);
8510: if ($counters{$tail} eq '') {
8511: $counters{$tail} = $num;
8512: $num ++;
8513: }
8514: if (ref($idx) eq 'HASH') {
8515: $idx->{$item} = $counters{$tail};
8516: }
8517: if (ref($jsarray) eq 'ARRAY') {
8518: push(@{$jsarray->[$counters{$tail}]},$item);
8519: }
8520: }
8521: return;
8522: }
8523:
8524: =pod
8525:
8526: =item * &extract_categories()
8527:
8528: Used to generate breadcrumb trails for course categories.
8529:
8530: Inputs:
1.663 raeburn 8531:
1.655 raeburn 8532: categories (reference to hash of category definitions).
1.663 raeburn 8533:
1.655 raeburn 8534: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8535: categories and subcategories).
1.663 raeburn 8536:
1.655 raeburn 8537: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8538:
1.655 raeburn 8539: allitems (reference to hash - key is category key
8540: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8541:
1.655 raeburn 8542: idx (reference to hash of counters used in Domain Coordinator interface for
8543: editing Course Categories).
1.663 raeburn 8544:
1.655 raeburn 8545: jsarray (reference to array of categories used to create Javascript arrays for
8546: Domain Coordinator interface for editing Course Categories).
8547:
1.665 raeburn 8548: subcats (reference to hash of arrays containing all subcategories within each
8549: category, -recursive)
8550:
1.655 raeburn 8551: Returns: nothing
8552:
8553: Side effects: populates trails and allitems hash references.
8554:
8555: =cut
8556:
8557: sub extract_categories {
1.665 raeburn 8558: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8559: if (ref($categories) eq 'HASH') {
8560: &gather_categories($categories,$cats,$idx,$jsarray);
8561: if (ref($cats->[0]) eq 'ARRAY') {
8562: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8563: my $name = $cats->[0][$i];
8564: my $item = &escape($name).'::0';
8565: my $trailstr;
8566: if ($name eq 'instcode') {
8567: $trailstr = &mt('Official courses (with institutional codes)');
8568: } else {
8569: $trailstr = $name;
8570: }
8571: if ($allitems->{$item} eq '') {
8572: push(@{$trails},$trailstr);
8573: $allitems->{$item} = scalar(@{$trails})-1;
8574: }
8575: my @parents = ($name);
8576: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8577: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8578: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8579: if (ref($subcats) eq 'HASH') {
8580: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8581: }
8582: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8583: }
8584: } else {
8585: if (ref($subcats) eq 'HASH') {
8586: $subcats->{$item} = [];
1.655 raeburn 8587: }
8588: }
8589: }
8590: }
8591: }
8592: return;
8593: }
8594:
8595: =pod
8596:
8597: =item *&recurse_categories()
8598:
8599: Recursively used to generate breadcrumb trails for course categories.
8600:
8601: Inputs:
1.663 raeburn 8602:
1.655 raeburn 8603: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8604: categories and subcategories).
1.663 raeburn 8605:
1.655 raeburn 8606: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8607:
8608: category (current course category, for which breadcrumb trail is being generated).
8609:
8610: trails (reference to array of breadcrumb trails for each category).
8611:
1.655 raeburn 8612: allitems (reference to hash - key is category key
8613: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8614:
1.655 raeburn 8615: parents (array containing containers directories for current category,
8616: back to top level).
8617:
8618: Returns: nothing
8619:
8620: Side effects: populates trails and allitems hash references
8621:
8622: =cut
8623:
8624: sub recurse_categories {
1.665 raeburn 8625: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8626: my $shallower = $depth - 1;
8627: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8628: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8629: my $name = $cats->[$depth]{$category}[$k];
8630: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8631: my $trailstr = join(' -> ',(@{$parents},$category));
8632: if ($allitems->{$item} eq '') {
8633: push(@{$trails},$trailstr);
8634: $allitems->{$item} = scalar(@{$trails})-1;
8635: }
8636: my $deeper = $depth+1;
8637: push(@{$parents},$category);
1.665 raeburn 8638: if (ref($subcats) eq 'HASH') {
8639: my $subcat = &escape($name).':'.$category.':'.$depth;
8640: for (my $j=@{$parents}; $j>=0; $j--) {
8641: my $higher;
8642: if ($j > 0) {
8643: $higher = &escape($parents->[$j]).':'.
8644: &escape($parents->[$j-1]).':'.$j;
8645: } else {
8646: $higher = &escape($parents->[$j]).'::'.$j;
8647: }
8648: push(@{$subcats->{$higher}},$subcat);
8649: }
8650: }
8651: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8652: $subcats);
1.655 raeburn 8653: pop(@{$parents});
8654: }
8655: } else {
8656: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8657: my $trailstr = join(' -> ',(@{$parents},$category));
8658: if ($allitems->{$item} eq '') {
8659: push(@{$trails},$trailstr);
8660: $allitems->{$item} = scalar(@{$trails})-1;
8661: }
8662: }
8663: return;
8664: }
8665:
1.663 raeburn 8666: =pod
8667:
8668: =item *&assign_categories_table()
8669:
8670: Create a datatable for display of hierarchical categories in a domain,
8671: with checkboxes to allow a course to be categorized.
8672:
8673: Inputs:
8674:
8675: cathash - reference to hash of categories defined for the domain (from
8676: configuration.db)
8677:
8678: currcat - scalar with an & separated list of categories assigned to a course.
8679:
8680: Returns: $output (markup to be displayed)
8681:
8682: =cut
8683:
8684: sub assign_categories_table {
8685: my ($cathash,$currcat) = @_;
8686: my $output;
8687: if (ref($cathash) eq 'HASH') {
8688: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
8689: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
8690: $maxdepth = scalar(@cats);
8691: if (@cats > 0) {
8692: my $itemcount = 0;
8693: if (ref($cats[0]) eq 'ARRAY') {
8694: $output = &Apache::loncommon::start_data_table();
8695: my @currcategories;
8696: if ($currcat ne '') {
8697: @currcategories = split('&',$currcat);
8698: }
8699: for (my $i=0; $i<@{$cats[0]}; $i++) {
8700: my $parent = $cats[0][$i];
8701: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8702: next if ($parent eq 'instcode');
8703: my $item = &escape($parent).'::0';
8704: my $checked = '';
8705: if (@currcategories > 0) {
8706: if (grep(/^\Q$item\E$/,@currcategories)) {
8707: $checked = ' checked="checked" ';
8708: }
8709: }
1.675 raeburn 8710: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
8711: '<input type="checkbox" name="usecategory" value="'.
8712: $item.'"'.$checked.' />'.$parent.'</span>'.
8713: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 8714: my $depth = 1;
8715: push(@path,$parent);
8716: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
8717: pop(@path);
8718: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8719: $itemcount ++;
8720: }
8721: $output .= &Apache::loncommon::end_data_table();
8722: }
8723: }
8724: }
8725: return $output;
8726: }
8727:
8728: =pod
8729:
8730: =item *&assign_category_rows()
8731:
8732: Create a datatable row for display of nested categories in a domain,
8733: with checkboxes to allow a course to be categorized,called recursively.
8734:
8735: Inputs:
8736:
8737: itemcount - track row number for alternating colors
8738:
8739: cats - reference to array of arrays/hashes which encapsulates hierarchy of
8740: categories and subcategories.
8741:
8742: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
8743:
8744: parent - parent of current category item
8745:
8746: path - Array containing all categories back up through the hierarchy from the
8747: current category to the top level.
8748:
8749: currcategories - reference to array of current categories assigned to the course
8750:
8751: Returns: $output (markup to be displayed).
8752:
8753: =cut
8754:
8755: sub assign_category_rows {
8756: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
8757: my ($text,$name,$item,$chgstr);
8758: if (ref($cats) eq 'ARRAY') {
8759: my $maxdepth = scalar(@{$cats});
8760: if (ref($cats->[$depth]) eq 'HASH') {
8761: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8762: my $numchildren = @{$cats->[$depth]{$parent}};
8763: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8764: $text .= '<td><table class="LC_datatable">';
8765: for (my $j=0; $j<$numchildren; $j++) {
8766: $name = $cats->[$depth]{$parent}[$j];
8767: $item = &escape($name).':'.&escape($parent).':'.$depth;
8768: my $deeper = $depth+1;
8769: my $checked = '';
8770: if (ref($currcategories) eq 'ARRAY') {
8771: if (@{$currcategories} > 0) {
8772: if (grep(/^\Q$item\E$/,@{$currcategories})) {
8773: $checked = ' checked="checked" ';
8774: }
8775: }
8776: }
1.664 raeburn 8777: $text .= '<tr><td><span class="LC_nobreak"><label>'.
8778: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 8779: $item.'"'.$checked.' />'.$name.'</label></span>'.
8780: '<input type="hidden" name="catname" value="'.$name.'" />'.
8781: '</td><td>';
1.663 raeburn 8782: if (ref($path) eq 'ARRAY') {
8783: push(@{$path},$name);
8784: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
8785: pop(@{$path});
8786: }
8787: $text .= '</td></tr>';
8788: }
8789: $text .= '</table></td>';
8790: }
8791: }
8792: }
8793: return $text;
8794: }
8795:
1.655 raeburn 8796: ############################################################
8797: ############################################################
8798:
8799:
1.443 albertel 8800: sub commit_customrole {
1.664 raeburn 8801: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 8802: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 8803: ($start?', '.&mt('starting').' '.localtime($start):'').
8804: ($end?', ending '.localtime($end):'').': <b>'.
8805: &Apache::lonnet::assigncustomrole(
1.664 raeburn 8806: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 8807: '</b><br />';
8808: return $output;
8809: }
8810:
8811: sub commit_standardrole {
1.541 raeburn 8812: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
8813: my ($output,$logmsg,$linefeed);
8814: if ($context eq 'auto') {
8815: $linefeed = "\n";
8816: } else {
8817: $linefeed = "<br />\n";
8818: }
1.443 albertel 8819: if ($three eq 'st') {
1.541 raeburn 8820: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
8821: $one,$two,$sec,$context);
8822: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 8823: ($result eq 'unknown_course') || ($result eq 'refused')) {
8824: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 8825: } else {
1.541 raeburn 8826: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 8827: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 8828: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
8829: if ($context eq 'auto') {
8830: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
8831: } else {
8832: $output .= '<b>'.$result.'</b>'.$linefeed.
8833: &mt('Add to classlist').': <b>ok</b>';
8834: }
8835: $output .= $linefeed;
1.443 albertel 8836: }
8837: } else {
8838: $output = &mt('Assigning').' '.$three.' in '.$url.
8839: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 8840: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 8841: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 8842: if ($context eq 'auto') {
8843: $output .= $result.$linefeed;
8844: } else {
8845: $output .= '<b>'.$result.'</b>'.$linefeed;
8846: }
1.443 albertel 8847: }
8848: return $output;
8849: }
8850:
8851: sub commit_studentrole {
1.541 raeburn 8852: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 8853: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 8854: if ($context eq 'auto') {
8855: $linefeed = "\n";
8856: } else {
8857: $linefeed = '<br />'."\n";
8858: }
1.443 albertel 8859: if (defined($one) && defined($two)) {
8860: my $cid=$one.'_'.$two;
8861: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
8862: my $secchange = 0;
8863: my $expire_role_result;
8864: my $modify_section_result;
1.628 raeburn 8865: if ($oldsec ne '-1') {
8866: if ($oldsec ne $sec) {
1.443 albertel 8867: $secchange = 1;
1.628 raeburn 8868: my $now = time;
1.443 albertel 8869: my $uurl='/'.$cid;
8870: $uurl=~s/\_/\//g;
8871: if ($oldsec) {
8872: $uurl.='/'.$oldsec;
8873: }
1.626 raeburn 8874: $oldsecurl = $uurl;
1.628 raeburn 8875: $expire_role_result =
1.652 raeburn 8876: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 8877: if ($env{'request.course.sec'} ne '') {
8878: if ($expire_role_result eq 'refused') {
8879: my @roles = ('st');
8880: my @statuses = ('previous');
8881: my @roledoms = ($one);
8882: my $withsec = 1;
8883: my %roleshash =
8884: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
8885: \@statuses,\@roles,\@roledoms,$withsec);
8886: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
8887: my ($oldstart,$oldend) =
8888: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
8889: if ($oldend > 0 && $oldend <= $now) {
8890: $expire_role_result = 'ok';
8891: }
8892: }
8893: }
8894: }
1.443 albertel 8895: $result = $expire_role_result;
8896: }
8897: }
8898: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 8899: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 8900: if ($modify_section_result =~ /^ok/) {
8901: if ($secchange == 1) {
1.628 raeburn 8902: if ($sec eq '') {
8903: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
8904: } else {
8905: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
8906: }
1.443 albertel 8907: } elsif ($oldsec eq '-1') {
1.628 raeburn 8908: if ($sec eq '') {
8909: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
8910: } else {
8911: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8912: }
1.443 albertel 8913: } else {
1.628 raeburn 8914: if ($sec eq '') {
8915: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
8916: } else {
8917: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8918: }
1.443 albertel 8919: }
8920: } else {
1.628 raeburn 8921: if ($secchange) {
8922: $$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;
8923: } else {
8924: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
8925: }
1.443 albertel 8926: }
8927: $result = $modify_section_result;
8928: } elsif ($secchange == 1) {
1.628 raeburn 8929: if ($oldsec eq '') {
8930: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
8931: } else {
8932: $$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;
8933: }
1.626 raeburn 8934: if ($expire_role_result eq 'refused') {
8935: my $newsecurl = '/'.$cid;
8936: $newsecurl =~ s/\_/\//g;
8937: if ($sec ne '') {
8938: $newsecurl.='/'.$sec;
8939: }
8940: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
8941: if ($sec eq '') {
8942: $$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;
8943: } else {
8944: $$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;
8945: }
8946: }
8947: }
1.443 albertel 8948: }
8949: } else {
1.626 raeburn 8950: $$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 8951: $result = "error: incomplete course id\n";
8952: }
8953: return $result;
8954: }
8955:
8956: ############################################################
8957: ############################################################
8958:
1.566 albertel 8959: sub check_clone {
1.578 raeburn 8960: my ($args,$linefeed) = @_;
1.566 albertel 8961: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
8962: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
8963: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
8964: my $clonemsg;
8965: my $can_clone = 0;
8966:
8967: if ($clonehome eq 'no_host') {
1.578 raeburn 8968: $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 8969: } else {
8970: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 8971: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 8972: $can_clone = 1;
8973: } else {
8974: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
8975: $args->{'clonedomain'},$args->{'clonecourse'});
8976: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 8977: if (grep(/^\*$/,@cloners)) {
8978: $can_clone = 1;
8979: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
8980: $can_clone = 1;
8981: } else {
8982: my %roleshash =
8983: &Apache::lonnet::get_my_roles($args->{'ccuname'},
8984: $args->{'ccdomain'},
8985: 'userroles',['active'],['cc'],
8986: [$args->{'clonedomain'}]);
8987: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
8988: $can_clone = 1;
8989: } else {
8990: $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'});
8991: }
1.566 albertel 8992: }
1.578 raeburn 8993: }
1.566 albertel 8994: }
8995: return ($can_clone, $clonemsg, $cloneid, $clonehome);
8996: }
8997:
1.444 albertel 8998: sub construct_course {
1.541 raeburn 8999: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9000: my $outcome;
1.541 raeburn 9001: my $linefeed = '<br />'."\n";
9002: if ($context eq 'auto') {
9003: $linefeed = "\n";
9004: }
1.566 albertel 9005:
9006: #
9007: # Are we cloning?
9008: #
9009: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9010: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9011: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9012: if ($context ne 'auto') {
1.578 raeburn 9013: if ($clonemsg ne '') {
9014: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9015: }
1.566 albertel 9016: }
9017: $outcome .= $clonemsg.$linefeed;
9018:
9019: if (!$can_clone) {
9020: return (0,$outcome);
9021: }
9022: }
9023:
1.444 albertel 9024: #
9025: # Open course
9026: #
9027: my $crstype = lc($args->{'crstype'});
9028: my %cenv=();
9029: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9030: $args->{'cdescr'},
9031: $args->{'curl'},
9032: $args->{'course_home'},
9033: $args->{'nonstandard'},
9034: $args->{'crscode'},
9035: $args->{'ccuname'}.':'.
9036: $args->{'ccdomain'},
9037: $args->{'crstype'});
9038:
9039: # Note: The testing routines depend on this being output; see
9040: # Utils::Course. This needs to at least be output as a comment
9041: # if anyone ever decides to not show this, and Utils::Course::new
9042: # will need to be suitably modified.
1.541 raeburn 9043: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9044: #
9045: # Check if created correctly
9046: #
1.479 albertel 9047: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9048: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9049: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9050:
1.444 albertel 9051: #
1.566 albertel 9052: # Do the cloning
9053: #
9054: if ($can_clone && $cloneid) {
9055: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9056: if ($context ne 'auto') {
9057: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9058: }
9059: $outcome .= $clonemsg.$linefeed;
9060: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9061: # Copy all files
1.637 www 9062: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9063: # Restore URL
1.566 albertel 9064: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9065: # Restore title
1.566 albertel 9066: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9067: # Mark as cloned
1.566 albertel 9068: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9069: # Need to clone grading mode
9070: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9071: $cenv{'grading'}=$newenv{'grading'};
9072: # Do not clone these environment entries
9073: &Apache::lonnet::del('environment',
9074: ['default_enrollment_start_date',
9075: 'default_enrollment_end_date',
9076: 'question.email',
9077: 'policy.email',
9078: 'comment.email',
9079: 'pch.users.denied',
1.692.2.7 raeburn 9080: 'plc.users.denied',
9081: 'hidefromcat',
9082: 'categories'],
1.638 www 9083: $$crsudom,$$crsunum);
1.444 albertel 9084: }
1.566 albertel 9085:
1.444 albertel 9086: #
9087: # Set environment (will override cloned, if existing)
9088: #
9089: my @sections = ();
9090: my @xlists = ();
9091: if ($args->{'crstype'}) {
9092: $cenv{'type'}=$args->{'crstype'};
9093: }
9094: if ($args->{'crsid'}) {
9095: $cenv{'courseid'}=$args->{'crsid'};
9096: }
9097: if ($args->{'crscode'}) {
9098: $cenv{'internal.coursecode'}=$args->{'crscode'};
9099: }
9100: if ($args->{'crsquota'} ne '') {
9101: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9102: } else {
9103: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9104: }
9105: if ($args->{'ccuname'}) {
9106: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9107: ':'.$args->{'ccdomain'};
9108: } else {
9109: $cenv{'internal.courseowner'} = $args->{'curruser'};
9110: }
9111: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9112: if ($args->{'crssections'}) {
9113: $cenv{'internal.sectionnums'} = '';
9114: if ($args->{'crssections'} =~ m/,/) {
9115: @sections = split/,/,$args->{'crssections'};
9116: } else {
9117: $sections[0] = $args->{'crssections'};
9118: }
9119: if (@sections > 0) {
9120: foreach my $item (@sections) {
9121: my ($sec,$gp) = split/:/,$item;
9122: my $class = $args->{'crscode'}.$sec;
9123: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9124: $cenv{'internal.sectionnums'} .= $item.',';
9125: unless ($addcheck eq 'ok') {
9126: push @badclasses, $class;
9127: }
9128: }
9129: $cenv{'internal.sectionnums'} =~ s/,$//;
9130: }
9131: }
9132: # do not hide course coordinator from staff listing,
9133: # even if privileged
9134: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9135: # add crosslistings
9136: if ($args->{'crsxlist'}) {
9137: $cenv{'internal.crosslistings'}='';
9138: if ($args->{'crsxlist'} =~ m/,/) {
9139: @xlists = split/,/,$args->{'crsxlist'};
9140: } else {
9141: $xlists[0] = $args->{'crsxlist'};
9142: }
9143: if (@xlists > 0) {
9144: foreach my $item (@xlists) {
9145: my ($xl,$gp) = split/:/,$item;
9146: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9147: $cenv{'internal.crosslistings'} .= $item.',';
9148: unless ($addcheck eq 'ok') {
9149: push @badclasses, $xl;
9150: }
9151: }
9152: $cenv{'internal.crosslistings'} =~ s/,$//;
9153: }
9154: }
9155: if ($args->{'autoadds'}) {
9156: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9157: }
9158: if ($args->{'autodrops'}) {
9159: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9160: }
9161: # check for notification of enrollment changes
9162: my @notified = ();
9163: if ($args->{'notify_owner'}) {
9164: if ($args->{'ccuname'} ne '') {
9165: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9166: }
9167: }
9168: if ($args->{'notify_dc'}) {
9169: if ($uname ne '') {
1.630 raeburn 9170: push(@notified,$uname.':'.$udom);
1.444 albertel 9171: }
9172: }
9173: if (@notified > 0) {
9174: my $notifylist;
9175: if (@notified > 1) {
9176: $notifylist = join(',',@notified);
9177: } else {
9178: $notifylist = $notified[0];
9179: }
9180: $cenv{'internal.notifylist'} = $notifylist;
9181: }
9182: if (@badclasses > 0) {
9183: my %lt=&Apache::lonlocal::texthash(
9184: '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',
9185: 'dnhr' => 'does not have rights to access enrollment in these classes',
9186: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9187: );
1.541 raeburn 9188: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9189: ' ('.$lt{'adby'}.')';
9190: if ($context eq 'auto') {
9191: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9192: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9193: foreach my $item (@badclasses) {
9194: if ($context eq 'auto') {
9195: $outcome .= " - $item\n";
9196: } else {
9197: $outcome .= "<li>$item</li>\n";
9198: }
9199: }
9200: if ($context eq 'auto') {
9201: $outcome .= $linefeed;
9202: } else {
1.566 albertel 9203: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9204: }
9205: }
1.444 albertel 9206: }
9207: if ($args->{'no_end_date'}) {
9208: $args->{'endaccess'} = 0;
9209: }
9210: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9211: $cenv{'internal.autoend'}=$args->{'enrollend'};
9212: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9213: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9214: if ($args->{'showphotos'}) {
9215: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9216: }
9217: $cenv{'internal.authtype'} = $args->{'authtype'};
9218: $cenv{'internal.autharg'} = $args->{'autharg'};
9219: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9220: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9221: 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');
9222: if ($context eq 'auto') {
9223: $outcome .= $krb_msg;
9224: } else {
1.566 albertel 9225: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9226: }
9227: $outcome .= $linefeed;
1.444 albertel 9228: }
9229: }
9230: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9231: if ($args->{'setpolicy'}) {
9232: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9233: }
9234: if ($args->{'setcontent'}) {
9235: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9236: }
9237: }
9238: if ($args->{'reshome'}) {
9239: $cenv{'reshome'}=$args->{'reshome'}.'/';
9240: $cenv{'reshome'}=~s/\/+$/\//;
9241: }
9242: #
9243: # course has keyed access
9244: #
9245: if ($args->{'setkeys'}) {
9246: $cenv{'keyaccess'}='yes';
9247: }
9248: # if specified, key authority is not course, but user
9249: # only active if keyaccess is yes
9250: if ($args->{'keyauth'}) {
1.487 albertel 9251: my ($user,$domain) = split(':',$args->{'keyauth'});
9252: $user = &LONCAPA::clean_username($user);
9253: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9254: if ($user ne '' && $domain ne '') {
1.487 albertel 9255: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9256: }
9257: }
9258:
9259: if ($args->{'disresdis'}) {
9260: $cenv{'pch.roles.denied'}='st';
9261: }
9262: if ($args->{'disablechat'}) {
9263: $cenv{'plc.roles.denied'}='st';
9264: }
9265:
9266: # Record we've not yet viewed the Course Initialization Helper for this
9267: # course
9268: $cenv{'course.helper.not.run'} = 1;
9269: #
9270: # Use new Randomseed
9271: #
9272: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9273: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9274: #
9275: # The encryption code and receipt prefix for this course
9276: #
9277: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9278: $cenv{'internal.encpref'}=100+int(9*rand(99));
9279: #
9280: # By default, use standard grading
9281: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9282:
1.541 raeburn 9283: $outcome .= $linefeed.&mt('Setting environment').': '.
9284: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9285: #
9286: # Open all assignments
9287: #
9288: if ($args->{'openall'}) {
9289: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9290: my %storecontent = ($storeunder => time,
9291: $storeunder.'.type' => 'date_start');
9292:
9293: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9294: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9295: }
9296: #
9297: # Set first page
9298: #
9299: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9300: || ($cloneid)) {
1.445 albertel 9301: use LONCAPA::map;
1.444 albertel 9302: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9303:
9304: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9305: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9306:
1.444 albertel 9307: $outcome .= ($fatal?$errtext:'read ok').' - ';
9308: my $title; my $url;
9309: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9310: $title=&mt('Syllabus');
1.444 albertel 9311: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9312: } else {
1.690 bisitz 9313: $title=&mt('Navigate Contents');
1.444 albertel 9314: $url='/adm/navmaps';
9315: }
1.445 albertel 9316:
9317: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9318: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9319:
9320: if ($errtext) { $fatal=2; }
1.541 raeburn 9321: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9322: }
1.566 albertel 9323:
9324: return (1,$outcome);
1.444 albertel 9325: }
9326:
9327: ############################################################
9328: ############################################################
9329:
1.378 raeburn 9330: sub course_type {
9331: my ($cid) = @_;
9332: if (!defined($cid)) {
9333: $cid = $env{'request.course.id'};
9334: }
1.404 albertel 9335: if (defined($env{'course.'.$cid.'.type'})) {
9336: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9337: } else {
9338: return 'Course';
1.377 raeburn 9339: }
9340: }
1.156 albertel 9341:
1.406 raeburn 9342: sub group_term {
9343: my $crstype = &course_type();
9344: my %names = (
9345: 'Course' => 'group',
9346: 'Group' => 'team',
9347: );
9348: return $names{$crstype};
9349: }
9350:
1.156 albertel 9351: sub icon {
9352: my ($file)=@_;
1.505 albertel 9353: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9354: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9355: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9356: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9357: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9358: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9359: $curfext.".gif") {
9360: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9361: $curfext.".gif";
9362: }
9363: }
1.249 albertel 9364: return &lonhttpdurl($iconname);
1.154 albertel 9365: }
1.84 albertel 9366:
1.575 albertel 9367: sub lonhttpdurl {
1.692 www 9368: #
9369: # Had been used for "small fry" static images on separate port 8080.
9370: # Modify here if lightweight http functionality desired again.
9371: # Currently eliminated due to increasing firewall issues.
9372: #
1.575 albertel 9373: my ($url)=@_;
1.692 www 9374: return $url;
1.215 albertel 9375: }
9376:
1.213 albertel 9377: sub connection_aborted {
9378: my ($r)=@_;
9379: $r->print(" ");$r->rflush();
9380: my $c = $r->connection;
9381: return $c->aborted();
9382: }
9383:
1.221 foxr 9384: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9385: # strings as 'strings'.
9386: sub escape_single {
1.221 foxr 9387: my ($input) = @_;
1.223 albertel 9388: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9389: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9390: return $input;
9391: }
1.223 albertel 9392:
1.222 foxr 9393: # Same as escape_single, but escape's "'s This
9394: # can be used for "strings"
9395: sub escape_double {
9396: my ($input) = @_;
9397: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9398: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9399: return $input;
9400: }
1.223 albertel 9401:
1.222 foxr 9402: # Escapes the last element of a full URL.
9403: sub escape_url {
9404: my ($url) = @_;
1.238 raeburn 9405: my @urlslices = split(/\//, $url,-1);
1.369 www 9406: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9407: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9408: }
1.462 albertel 9409:
9410: # -------------------------------------------------------- Initliaze user login
9411: sub init_user_environment {
1.463 albertel 9412: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9413: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9414:
9415: my $public=($username eq 'public' && $domain eq 'public');
9416:
9417: # See if old ID present, if so, remove
9418:
9419: my ($filename,$cookie,$userroles);
9420: my $now=time;
9421:
9422: if ($public) {
9423: my $max_public=100;
9424: my $oldest;
9425: my $oldest_time=0;
9426: for(my $next=1;$next<=$max_public;$next++) {
9427: if (-e $lonids."/publicuser_$next.id") {
9428: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9429: if ($mtime<$oldest_time || !$oldest_time) {
9430: $oldest_time=$mtime;
9431: $oldest=$next;
9432: }
9433: } else {
9434: $cookie="publicuser_$next";
9435: last;
9436: }
9437: }
9438: if (!$cookie) { $cookie="publicuser_$oldest"; }
9439: } else {
1.463 albertel 9440: # if this isn't a robot, kill any existing non-robot sessions
9441: if (!$args->{'robot'}) {
9442: opendir(DIR,$lonids);
9443: while ($filename=readdir(DIR)) {
9444: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9445: unlink($lonids.'/'.$filename);
9446: }
1.462 albertel 9447: }
1.463 albertel 9448: closedir(DIR);
1.462 albertel 9449: }
9450: # Give them a new cookie
1.463 albertel 9451: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9452: : $now.$$.int(rand(10000)));
1.463 albertel 9453: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9454:
9455: # Initialize roles
9456:
9457: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9458: }
9459: # ------------------------------------ Check browser type and MathML capability
9460:
9461: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9462: $clientunicode,$clientos) = &decode_user_agent($r);
9463:
9464: # -------------------------------------- Any accessibility options to remember?
9465: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9466: foreach my $option ('imagesuppress','appletsuppress',
9467: 'embedsuppress','fontenhance','blackwhite') {
9468: if ($form->{$option} eq 'true') {
9469: &Apache::lonnet::put('environment',{$option => 'on'},
9470: $domain,$username);
9471: } else {
9472: &Apache::lonnet::del('environment',[$option],
9473: $domain,$username);
9474: }
9475: }
9476: }
9477: # ------------------------------------------------------------- Get environment
9478:
9479: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9480: my ($tmp) = keys(%userenv);
9481: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9482: # default remote control to off
9483: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9484: } else {
9485: undef(%userenv);
9486: }
9487: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9488: $form->{'interface'}=$userenv{'interface'};
9489: }
9490: $env{'environment.remote'}=$userenv{'remote'};
9491: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9492:
9493: # --------------- Do not trust query string to be put directly into environment
9494: foreach my $option ('imagesuppress','appletsuppress',
9495: 'embedsuppress','fontenhance','blackwhite',
9496: 'interface','localpath','localres') {
9497: $form->{$option}=~s/[\n\r\=]//gs;
9498: }
9499: # --------------------------------------------------------- Write first profile
9500:
9501: {
9502: my %initial_env =
9503: ("user.name" => $username,
9504: "user.domain" => $domain,
9505: "user.home" => $authhost,
9506: "browser.type" => $clientbrowser,
9507: "browser.version" => $clientversion,
9508: "browser.mathml" => $clientmathml,
9509: "browser.unicode" => $clientunicode,
9510: "browser.os" => $clientos,
9511: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9512: "request.course.fn" => '',
9513: "request.course.uri" => '',
9514: "request.course.sec" => '',
9515: "request.role" => 'cm',
9516: "request.role.adv" => $env{'user.adv'},
9517: "request.host" => $ENV{'REMOTE_ADDR'},);
9518:
9519: if ($form->{'localpath'}) {
9520: $initial_env{"browser.localpath"} = $form->{'localpath'};
9521: $initial_env{"browser.localres"} = $form->{'localres'};
9522: }
9523:
9524: if ($public) {
9525: $initial_env{"environment.remote"} = "off";
9526: }
9527: if ($form->{'interface'}) {
9528: $form->{'interface'}=~s/\W//gs;
9529: $initial_env{"browser.interface"} = $form->{'interface'};
9530: $env{'browser.interface'}=$form->{'interface'};
9531: foreach my $option ('imagesuppress','appletsuppress',
9532: 'embedsuppress','fontenhance','blackwhite') {
9533: if (($form->{$option} eq 'true') ||
9534: ($userenv{$option} eq 'on')) {
9535: $initial_env{"browser.$option"} = "on";
9536: }
9537: }
9538: }
9539:
1.692.2.6 raeburn 9540: foreach my $tool ('aboutme','blog','portfolio') {
9541: $userenv{'availabletools.'.$tool} =
9542: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9543: }
9544:
1.462 albertel 9545: $env{'user.environment'} = "$lonids/$cookie.id";
9546:
9547: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9548: &GDBM_WRCREAT(),0640)) {
9549: &_add_to_env(\%disk_env,\%initial_env);
9550: &_add_to_env(\%disk_env,\%userenv,'environment.');
9551: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9552: if (ref($args->{'extra_env'})) {
9553: &_add_to_env(\%disk_env,$args->{'extra_env'});
9554: }
1.462 albertel 9555: untie(%disk_env);
9556: } else {
9557: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
9558: 'Could not create environment storage in lonauth: '.$!.'</font>');
9559: return 'error: '.$!;
9560: }
9561: }
9562: $env{'request.role'}='cm';
9563: $env{'request.role.adv'}=$env{'user.adv'};
9564: $env{'browser.type'}=$clientbrowser;
9565:
9566: return $cookie;
9567:
9568: }
9569:
9570: sub _add_to_env {
9571: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9572: if (ref($env_data) eq 'HASH') {
9573: while (my ($key,$value) = each(%$env_data)) {
9574: $idf->{$prefix.$key} = $value;
9575: $env{$prefix.$key} = $value;
9576: }
1.462 albertel 9577: }
9578: }
9579:
1.685 tempelho 9580: # --- Get the symbolic name of a problem and the url
9581: sub get_symb {
9582: my ($request,$silent) = @_;
1.692.2.8 raeburn 9583: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 9584: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9585: if ($symb eq '') {
9586: if (!$silent) {
9587: $request->print("Unable to handle ambiguous references:$url:.");
9588: return ();
9589: }
9590: }
9591: &Apache::lonenc::check_decrypt(\$symb);
9592: return ($symb);
9593: }
9594:
9595: # --------------------------------------------------------------Get annotation
9596:
9597: sub get_annotation {
9598: my ($symb,$enc) = @_;
9599:
9600: my $key = $symb;
9601: if (!$enc) {
9602: $key =
9603: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9604: }
9605: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9606: return $annotation{$key};
9607: }
9608:
9609: sub clean_symb {
1.692.2.11 raeburn 9610: my ($symb,$delete_enc) = @_;
1.685 tempelho 9611:
9612: &Apache::lonenc::check_decrypt(\$symb);
9613: my $enc = $env{'request.enc'};
1.692.2.11 raeburn 9614: if ($delete_enc) {
9615: delete($env{'request.enc'});
9616: }
1.685 tempelho 9617:
9618: return ($symb,$enc);
9619: }
1.462 albertel 9620:
1.41 ng 9621: =pod
9622:
9623: =back
9624:
1.112 bowersj2 9625: =cut
1.41 ng 9626:
1.112 bowersj2 9627: 1;
9628: __END__;
1.41 ng 9629:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>