Annotation of loncom/interface/loncommon.pm, revision 1.692.2.11
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.11! raeburn 4: # $Id: loncommon.pm,v 1.692.2.10 2008/12/25 04:45:35 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 {
946: my $other = shift;
947: my $addOther = '';
948: if ($other) {
949: $addOther = Apache::loncommon::help_open_topic($other, shift,
950: undef, undef, 600) .
951: '</td><td>';
952: }
953: return '<table><tr><td>'.
954: $addOther .
1.636 raeburn 955: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
1.106 bowersj2 956: undef,undef,600)
957: .'</td><td>'.
1.636 raeburn 958: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
1.106 bowersj2 959: undef,undef,600)
1.673 felicia 960: .'</td><td>'.
961: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
962: undef,undef,600)
1.106 bowersj2 963: .'</td></tr></table>';
1.172 www 964: }
965:
1.430 albertel 966: sub general_help {
967: my $helptopic='Student_Intro';
968: if ($env{'request.role'}=~/^(ca|au)/) {
969: $helptopic='Authoring_Intro';
970: } elsif ($env{'request.role'}=~/^cc/) {
971: $helptopic='Course_Coordination_Intro';
1.672 raeburn 972: } elsif ($env{'request.role'}=~/^dc/) {
973: $helptopic='Domain_Coordination_Intro';
1.430 albertel 974: }
975: return $helptopic;
976: }
977:
978: sub update_help_link {
979: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
980: my $origurl = $ENV{'REQUEST_URI'};
981: $origurl=~s|^/~|/priv/|;
982: my $timestamp = time;
983: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
984: $$datum = &escape($$datum);
985: }
986:
987: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
988: my $output .= <<"ENDOUTPUT";
989: <script type="text/javascript">
990: banner_link = '$banner_link';
991: </script>
992: ENDOUTPUT
993: return $output;
994: }
995:
996: # now just updates the help link and generates a blue icon
1.193 raeburn 997: sub help_open_menu {
1.430 albertel 998: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 999: = @_;
1.430 albertel 1000: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1001: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1002: # if environment.remote is on (using remote control UI)
1.572 banghart 1003: if ($env{'browser.interface'} eq 'textual' ||
1004: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1005: $stayOnPage=1;
1.430 albertel 1006: }
1007: my $output;
1008: if ($component_help) {
1009: if (!$text) {
1010: $output=&help_open_topic($component_help,undef,$stayOnPage,
1011: $width,$height);
1012: } else {
1013: my $help_text;
1014: $help_text=&unescape($topic);
1015: $output='<table><tr><td>'.
1016: &help_open_topic($component_help,$help_text,$stayOnPage,
1017: $width,$height).'</td></tr></table>';
1018: }
1019: }
1020: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1021: return $output.$banner_link;
1022: }
1023:
1024: sub top_nav_help {
1025: my ($text) = @_;
1.436 albertel 1026: $text = &mt($text);
1.572 banghart 1027: my $stay_on_page =
1.436 albertel 1028: ($env{'browser.interface'} eq 'textual' ||
1029: $env{'environment.remote'} eq 'off' );
1.572 banghart 1030: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1031: : "javascript:helpMenu('open')";
1.572 banghart 1032: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1033:
1.201 raeburn 1034: my $title = &mt('Get help');
1.436 albertel 1035:
1036: return <<"END";
1037: $banner_link
1038: <a href="$link" title="$title">$text</a>
1039: END
1040: }
1041:
1042: sub help_menu_js {
1043: my ($text) = @_;
1044:
1045: my $stayOnPage =
1046: ($env{'browser.interface'} eq 'textual' ||
1047: $env{'environment.remote'} eq 'off' );
1048:
1049: my $width = 620;
1050: my $height = 600;
1.430 albertel 1051: my $helptopic=&general_help();
1052: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1053: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1054: my $start_page =
1055: &Apache::loncommon::start_page('Help Menu', undef,
1056: {'frameset' => 1,
1057: 'js_ready' => 1,
1058: 'add_entries' => {
1059: 'border' => '0',
1.579 raeburn 1060: 'rows' => "110,*",},});
1.331 albertel 1061: my $end_page =
1062: &Apache::loncommon::end_page({'frameset' => 1,
1063: 'js_ready' => 1,});
1064:
1.436 albertel 1065: my $template .= <<"ENDTEMPLATE";
1066: <script type="text/javascript">
1.253 albertel 1067: // <!-- BEGIN LON-CAPA Internal
1068: // <![CDATA[
1.430 albertel 1069: var banner_link = '';
1.243 raeburn 1070: function helpMenu(target) {
1071: var caller = this;
1072: if (target == 'open') {
1073: var newWindow = null;
1074: try {
1.262 albertel 1075: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1076: }
1077: catch(error) {
1078: writeHelp(caller);
1079: return;
1080: }
1081: if (newWindow) {
1082: caller = newWindow;
1083: }
1.193 raeburn 1084: }
1.243 raeburn 1085: writeHelp(caller);
1086: return;
1087: }
1088: function writeHelp(caller) {
1.430 albertel 1089: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1090: caller.document.close()
1091: caller.focus()
1.193 raeburn 1092: }
1.253 albertel 1093: // ]]>
1.219 albertel 1094: // END LON-CAPA Internal -->
1.436 albertel 1095: </script>
1.193 raeburn 1096: ENDTEMPLATE
1097: return $template;
1098: }
1099:
1.172 www 1100: sub help_open_bug {
1101: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1102: unless ($env{'user.adv'}) { return ''; }
1.172 www 1103: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1104: $text = "" if (not defined $text);
1105: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1106: if ($env{'browser.interface'} eq 'textual' ||
1107: $env{'environment.remote'} eq 'off' ) {
1.172 www 1108: $stayOnPage=1;
1109: }
1.184 albertel 1110: $width = 600 if (not defined $width);
1111: $height = 600 if (not defined $height);
1.172 www 1112:
1113: $topic=~s/\W+/\+/g;
1114: my $link='';
1115: my $template='';
1.379 albertel 1116: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1117: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1118: if (!$stayOnPage)
1119: {
1120: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1121: }
1122: else
1123: {
1124: $link = $url;
1125: }
1126: # Add the text
1127: if ($text ne "")
1128: {
1129: $template .=
1130: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1131: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1132: }
1133:
1134: # Add the graphic
1.179 matthew 1135: my $title = &mt('Report a Bug');
1.215 albertel 1136: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1137: $template .= <<"ENDTEMPLATE";
1.436 albertel 1138: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1139: ENDTEMPLATE
1140: if ($text ne '') { $template.='</td></tr></table>' };
1141: return $template;
1142:
1143: }
1144:
1145: sub help_open_faq {
1146: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1147: unless ($env{'user.adv'}) { return ''; }
1.172 www 1148: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1149: $text = "" if (not defined $text);
1150: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1151: if ($env{'browser.interface'} eq 'textual' ||
1152: $env{'environment.remote'} eq 'off' ) {
1.172 www 1153: $stayOnPage=1;
1154: }
1155: $width = 350 if (not defined $width);
1156: $height = 400 if (not defined $height);
1157:
1158: $topic=~s/\W+/\+/g;
1159: my $link='';
1160: my $template='';
1161: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1162: if (!$stayOnPage)
1163: {
1164: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1165: }
1166: else
1167: {
1168: $link = $url;
1169: }
1170:
1171: # Add the text
1172: if ($text ne "")
1173: {
1174: $template .=
1.173 www 1175: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1176: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1177: }
1178:
1179: # Add the graphic
1.179 matthew 1180: my $title = &mt('View the FAQ');
1.215 albertel 1181: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1182: $template .= <<"ENDTEMPLATE";
1.436 albertel 1183: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1184: ENDTEMPLATE
1185: if ($text ne '') { $template.='</td></tr></table>' };
1186: return $template;
1187:
1.44 bowersj2 1188: }
1.37 matthew 1189:
1.180 matthew 1190: ###############################################################
1191: ###############################################################
1192:
1.45 matthew 1193: =pod
1194:
1.648 raeburn 1195: =item * &change_content_javascript():
1.256 matthew 1196:
1197: This and the next function allow you to create small sections of an
1198: otherwise static HTML page that you can update on the fly with
1199: Javascript, even in Netscape 4.
1200:
1201: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1202: must be written to the HTML page once. It will prove the Javascript
1203: function "change(name, content)". Calling the change function with the
1204: name of the section
1205: you want to update, matching the name passed to C<changable_area>, and
1206: the new content you want to put in there, will put the content into
1207: that area.
1208:
1209: B<Note>: Netscape 4 only reserves enough space for the changable area
1210: to contain room for the original contents. You need to "make space"
1211: for whatever changes you wish to make, and be B<sure> to check your
1212: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1213: it's adequate for updating a one-line status display, but little more.
1214: This script will set the space to 100% width, so you only need to
1215: worry about height in Netscape 4.
1216:
1217: Modern browsers are much less limiting, and if you can commit to the
1218: user not using Netscape 4, this feature may be used freely with
1219: pretty much any HTML.
1220:
1221: =cut
1222:
1223: sub change_content_javascript {
1224: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1225: if ($env{'browser.type'} eq 'netscape' &&
1226: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1227: return (<<NETSCAPE4);
1228: function change(name, content) {
1229: doc = document.layers[name+"___escape"].layers[0].document;
1230: doc.open();
1231: doc.write(content);
1232: doc.close();
1233: }
1234: NETSCAPE4
1235: } else {
1236: # Otherwise, we need to use semi-standards-compliant code
1237: # (technically, "innerHTML" isn't standard but the equivalent
1238: # is really scary, and every useful browser supports it
1239: return (<<DOMBASED);
1240: function change(name, content) {
1241: element = document.getElementById(name);
1242: element.innerHTML = content;
1243: }
1244: DOMBASED
1245: }
1246: }
1247:
1248: =pod
1249:
1.648 raeburn 1250: =item * &changable_area($name,$origContent):
1.256 matthew 1251:
1252: This provides a "changable area" that can be modified on the fly via
1253: the Javascript code provided in C<change_content_javascript>. $name is
1254: the name you will use to reference the area later; do not repeat the
1255: same name on a given HTML page more then once. $origContent is what
1256: the area will originally contain, which can be left blank.
1257:
1258: =cut
1259:
1260: sub changable_area {
1261: my ($name, $origContent) = @_;
1262:
1.258 albertel 1263: if ($env{'browser.type'} eq 'netscape' &&
1264: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1265: # If this is netscape 4, we need to use the Layer tag
1266: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1267: } else {
1268: return "<span id='$name'>$origContent</span>";
1269: }
1270: }
1271:
1272: =pod
1273:
1.648 raeburn 1274: =item * &viewport_geometry_js
1.590 raeburn 1275:
1276: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1277:
1278: =cut
1279:
1280:
1281: sub viewport_geometry_js {
1282: return <<"GEOMETRY";
1283: var Geometry = {};
1284: function init_geometry() {
1285: if (Geometry.init) { return };
1286: Geometry.init=1;
1287: if (window.innerHeight) {
1288: Geometry.getViewportHeight = function() { return window.innerHeight; };
1289: Geometry.getViewportWidth = function() { return window.innerWidth; };
1290: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1291: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1292: }
1293: else if (document.documentElement && document.documentElement.clientHeight) {
1294: Geometry.getViewportHeight =
1295: function() { return document.documentElement.clientHeight; };
1296: Geometry.getViewportWidth =
1297: function() { return document.documentElement.clientWidth; };
1298:
1299: Geometry.getHorizontalScroll =
1300: function() { return document.documentElement.scrollLeft; };
1301: Geometry.getVerticalScroll =
1302: function() { return document.documentElement.scrollTop; };
1303: }
1304: else if (document.body.clientHeight) {
1305: Geometry.getViewportHeight =
1306: function() { return document.body.clientHeight; };
1307: Geometry.getViewportWidth =
1308: function() { return document.body.clientWidth; };
1309: Geometry.getHorizontalScroll =
1310: function() { return document.body.scrollLeft; };
1311: Geometry.getVerticalScroll =
1312: function() { return document.body.scrollTop; };
1313: }
1314: }
1315:
1316: GEOMETRY
1317: }
1318:
1319: =pod
1320:
1.648 raeburn 1321: =item * &viewport_size_js()
1.590 raeburn 1322:
1323: 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.
1324:
1325: =cut
1326:
1327: sub viewport_size_js {
1328: my $geometry = &viewport_geometry_js();
1329: return <<"DIMS";
1330:
1331: $geometry
1332:
1333: function getViewportDims(width,height) {
1334: init_geometry();
1335: width.value = Geometry.getViewportWidth();
1336: height.value = Geometry.getViewportHeight();
1337: return;
1338: }
1339:
1340: DIMS
1341: }
1342:
1343: =pod
1344:
1.648 raeburn 1345: =item * &resize_textarea_js()
1.565 albertel 1346:
1347: emits the needed javascript to resize a textarea to be as big as possible
1348:
1349: creates a function resize_textrea that takes two IDs first should be
1350: the id of the element to resize, second should be the id of a div that
1351: surrounds everything that comes after the textarea, this routine needs
1352: to be attached to the <body> for the onload and onresize events.
1353:
1.648 raeburn 1354: =back
1.565 albertel 1355:
1356: =cut
1357:
1358: sub resize_textarea_js {
1.590 raeburn 1359: my $geometry = &viewport_geometry_js();
1.565 albertel 1360: return <<"RESIZE";
1361: <script type="text/javascript">
1.590 raeburn 1362: $geometry
1.565 albertel 1363:
1.588 albertel 1364: function getX(element) {
1365: var x = 0;
1366: while (element) {
1367: x += element.offsetLeft;
1368: element = element.offsetParent;
1369: }
1370: return x;
1371: }
1372: function getY(element) {
1373: var y = 0;
1374: while (element) {
1375: y += element.offsetTop;
1376: element = element.offsetParent;
1377: }
1378: return y;
1379: }
1380:
1381:
1.565 albertel 1382: function resize_textarea(textarea_id,bottom_id) {
1383: init_geometry();
1384: var textarea = document.getElementById(textarea_id);
1385: //alert(textarea);
1386:
1.588 albertel 1387: var textarea_top = getY(textarea);
1.565 albertel 1388: var textarea_height = textarea.offsetHeight;
1389: var bottom = document.getElementById(bottom_id);
1.588 albertel 1390: var bottom_top = getY(bottom);
1.565 albertel 1391: var bottom_height = bottom.offsetHeight;
1392: var window_height = Geometry.getViewportHeight();
1.588 albertel 1393: var fudge = 23;
1.565 albertel 1394: var new_height = window_height-fudge-textarea_top-bottom_height;
1395: if (new_height < 300) {
1396: new_height = 300;
1397: }
1398: textarea.style.height=new_height+'px';
1399: }
1400: </script>
1401: RESIZE
1402:
1403: }
1404:
1405: =pod
1406:
1.256 matthew 1407: =head1 Excel and CSV file utility routines
1408:
1409: =over 4
1410:
1411: =cut
1412:
1413: ###############################################################
1414: ###############################################################
1415:
1416: =pod
1417:
1.648 raeburn 1418: =item * &csv_translate($text)
1.37 matthew 1419:
1.185 www 1420: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1421: format.
1422:
1423: =cut
1424:
1.180 matthew 1425: ###############################################################
1426: ###############################################################
1.37 matthew 1427: sub csv_translate {
1428: my $text = shift;
1429: $text =~ s/\"/\"\"/g;
1.209 albertel 1430: $text =~ s/\n/ /g;
1.37 matthew 1431: return $text;
1432: }
1.180 matthew 1433:
1434: ###############################################################
1435: ###############################################################
1436:
1437: =pod
1438:
1.648 raeburn 1439: =item * &define_excel_formats()
1.180 matthew 1440:
1441: Define some commonly used Excel cell formats.
1442:
1443: Currently supported formats:
1444:
1445: =over 4
1446:
1447: =item header
1448:
1449: =item bold
1450:
1451: =item h1
1452:
1453: =item h2
1454:
1455: =item h3
1456:
1.256 matthew 1457: =item h4
1458:
1459: =item i
1460:
1.180 matthew 1461: =item date
1462:
1463: =back
1464:
1465: Inputs: $workbook
1466:
1467: Returns: $format, a hash reference.
1468:
1469: =cut
1470:
1471: ###############################################################
1472: ###############################################################
1473: sub define_excel_formats {
1474: my ($workbook) = @_;
1475: my $format;
1476: $format->{'header'} = $workbook->add_format(bold => 1,
1477: bottom => 1,
1478: align => 'center');
1479: $format->{'bold'} = $workbook->add_format(bold=>1);
1480: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1481: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1482: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1483: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1484: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1485: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1486: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1487: return $format;
1488: }
1489:
1490: ###############################################################
1491: ###############################################################
1.113 bowersj2 1492:
1493: =pod
1494:
1.648 raeburn 1495: =item * &create_workbook()
1.255 matthew 1496:
1497: Create an Excel worksheet. If it fails, output message on the
1498: request object and return undefs.
1499:
1500: Inputs: Apache request object
1501:
1502: Returns (undef) on failure,
1503: Excel worksheet object, scalar with filename, and formats
1504: from &Apache::loncommon::define_excel_formats on success
1505:
1506: =cut
1507:
1508: ###############################################################
1509: ###############################################################
1510: sub create_workbook {
1511: my ($r) = @_;
1512: #
1513: # Create the excel spreadsheet
1514: my $filename = '/prtspool/'.
1.258 albertel 1515: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1516: time.'_'.rand(1000000000).'.xls';
1517: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1518: if (! defined($workbook)) {
1519: $r->log_error("Error creating excel spreadsheet $filename: $!");
1520: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1521: "This error has been logged. ".
1522: "Please alert your LON-CAPA administrator").
1523: '</p>');
1524: return (undef);
1525: }
1526: #
1527: $workbook->set_tempdir('/home/httpd/perl/tmp');
1528: #
1529: my $format = &Apache::loncommon::define_excel_formats($workbook);
1530: return ($workbook,$filename,$format);
1531: }
1532:
1533: ###############################################################
1534: ###############################################################
1535:
1536: =pod
1537:
1.648 raeburn 1538: =item * &create_text_file()
1.113 bowersj2 1539:
1.542 raeburn 1540: Create a file to write to and eventually make available to the user.
1.256 matthew 1541: If file creation fails, outputs an error message on the request object and
1542: return undefs.
1.113 bowersj2 1543:
1.256 matthew 1544: Inputs: Apache request object, and file suffix
1.113 bowersj2 1545:
1.256 matthew 1546: Returns (undef) on failure,
1547: Filehandle and filename on success.
1.113 bowersj2 1548:
1549: =cut
1550:
1.256 matthew 1551: ###############################################################
1552: ###############################################################
1553: sub create_text_file {
1554: my ($r,$suffix) = @_;
1555: if (! defined($suffix)) { $suffix = 'txt'; };
1556: my $fh;
1557: my $filename = '/prtspool/'.
1.258 albertel 1558: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1559: time.'_'.rand(1000000000).'.'.$suffix;
1560: $fh = Apache::File->new('>/home/httpd'.$filename);
1561: if (! defined($fh)) {
1562: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1563: $r->print(&mt('Problems occurred in creating the output file. '
1564: .'This error has been logged. '
1565: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1566: }
1.256 matthew 1567: return ($fh,$filename)
1.113 bowersj2 1568: }
1569:
1570:
1.256 matthew 1571: =pod
1.113 bowersj2 1572:
1573: =back
1574:
1575: =cut
1.37 matthew 1576:
1577: ###############################################################
1.33 matthew 1578: ## Home server <option> list generating code ##
1579: ###############################################################
1.35 matthew 1580:
1.169 www 1581: # ------------------------------------------
1582:
1583: sub domain_select {
1584: my ($name,$value,$multiple)=@_;
1585: my %domains=map {
1.514 albertel 1586: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1587: } &Apache::lonnet::all_domains();
1.169 www 1588: if ($multiple) {
1589: $domains{''}=&mt('Any domain');
1.550 albertel 1590: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1591: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1592: } else {
1.550 albertel 1593: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1594: return &select_form($name,$value,%domains);
1595: }
1596: }
1597:
1.282 albertel 1598: #-------------------------------------------
1599:
1600: =pod
1601:
1.519 raeburn 1602: =head1 Routines for form select boxes
1603:
1604: =over 4
1605:
1.648 raeburn 1606: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1607:
1608: Returns a string containing a <select> element int multiple mode
1609:
1610:
1611: Args:
1612: $name - name of the <select> element
1.506 raeburn 1613: $value - scalar or array ref of values that should already be selected
1.282 albertel 1614: $size - number of rows long the select element is
1.283 albertel 1615: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1616: (shown text should already have been &mt())
1.506 raeburn 1617: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1618:
1.282 albertel 1619: =cut
1620:
1621: #-------------------------------------------
1.169 www 1622: sub multiple_select_form {
1.284 albertel 1623: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1624: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1625: my $output='';
1.191 matthew 1626: if (! defined($size)) {
1627: $size = 4;
1.283 albertel 1628: if (scalar(keys(%$hash))<4) {
1629: $size = scalar(keys(%$hash));
1.191 matthew 1630: }
1631: }
1.169 www 1632: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501 banghart 1633: my @order;
1.506 raeburn 1634: if (ref($order) eq 'ARRAY') {
1635: @order = @{$order};
1636: } else {
1637: @order = sort(keys(%$hash));
1.501 banghart 1638: }
1639: if (exists($$hash{'select_form_order'})) {
1640: @order = @{$$hash{'select_form_order'}};
1641: }
1642:
1.284 albertel 1643: foreach my $key (@order) {
1.356 albertel 1644: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1645: $output.='selected="selected" ' if ($selected{$key});
1646: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1647: }
1648: $output.="</select>\n";
1649: return $output;
1650: }
1651:
1.88 www 1652: #-------------------------------------------
1653:
1654: =pod
1655:
1.648 raeburn 1656: =item * &select_form($defdom,$name,%hash)
1.88 www 1657:
1658: Returns a string containing a <select name='$name' size='1'> form to
1659: allow a user to select options from a hash option_name => displayed text.
1660: See lonrights.pm for an example invocation and use.
1661:
1662: =cut
1663:
1664: #-------------------------------------------
1665: sub select_form {
1666: my ($def,$name,%hash) = @_;
1667: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1668: my @keys;
1669: if (exists($hash{'select_form_order'})) {
1670: @keys=@{$hash{'select_form_order'}};
1671: } else {
1672: @keys=sort(keys(%hash));
1673: }
1.356 albertel 1674: foreach my $key (@keys) {
1675: $selectform.=
1676: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1677: ($key eq $def ? 'selected="selected" ' : '').
1678: ">".&mt($hash{$key})."</option>\n";
1.88 www 1679: }
1680: $selectform.="</select>";
1681: return $selectform;
1682: }
1683:
1.475 www 1684: # For display filters
1685:
1686: sub display_filter {
1687: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1688: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475 www 1689: return '<nobr><label>'.&mt('Records [_1]',
1690: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1691: (&mt('all'),10,20,50,100,1000,10000))).
1.478 www 1692: '</label></nobr> <nobr>'.
1.475 www 1693: &mt('Filter [_1]',
1.477 www 1694: &select_form($env{'form.displayfilter'},
1695: 'displayfilter',
1696: ('currentfolder' => 'Current folder/page',
1697: 'containing' => 'Containing phrase',
1698: 'none' => 'None'))).
1.478 www 1699: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475 www 1700: }
1701:
1.167 www 1702: sub gradeleveldescription {
1703: my $gradelevel=shift;
1704: my %gradelevels=(0 => 'Not specified',
1705: 1 => 'Grade 1',
1706: 2 => 'Grade 2',
1707: 3 => 'Grade 3',
1708: 4 => 'Grade 4',
1709: 5 => 'Grade 5',
1710: 6 => 'Grade 6',
1711: 7 => 'Grade 7',
1712: 8 => 'Grade 8',
1713: 9 => 'Grade 9',
1714: 10 => 'Grade 10',
1715: 11 => 'Grade 11',
1716: 12 => 'Grade 12',
1717: 13 => 'Grade 13',
1718: 14 => '100 Level',
1719: 15 => '200 Level',
1720: 16 => '300 Level',
1721: 17 => '400 Level',
1722: 18 => 'Graduate Level');
1723: return &mt($gradelevels{$gradelevel});
1724: }
1725:
1.163 www 1726: sub select_level_form {
1727: my ($deflevel,$name)=@_;
1728: unless ($deflevel) { $deflevel=0; }
1.167 www 1729: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1730: for (my $i=0; $i<=18; $i++) {
1731: $selectform.="<option value=\"$i\" ".
1.253 albertel 1732: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1733: ">".&gradeleveldescription($i)."</option>\n";
1734: }
1735: $selectform.="</select>";
1736: return $selectform;
1.163 www 1737: }
1.167 www 1738:
1.35 matthew 1739: #-------------------------------------------
1740:
1.45 matthew 1741: =pod
1742:
1.648 raeburn 1743: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35 matthew 1744:
1745: Returns a string containing a <select name='$name' size='1'> form to
1746: allow a user to select the domain to preform an operation in.
1747: See loncreateuser.pm for an example invocation and use.
1748:
1.90 www 1749: If the $includeempty flag is set, it also includes an empty choice ("no domain
1750: selected");
1751:
1.563 raeburn 1752: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1753:
1.35 matthew 1754: =cut
1755:
1756: #-------------------------------------------
1.34 matthew 1757: sub select_dom_form {
1.563 raeburn 1758: my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550 albertel 1759: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1760: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1761: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356 albertel 1762: foreach my $dom (@domains) {
1763: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1764: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1765: if ($showdomdesc) {
1766: if ($dom ne '') {
1767: my $domdesc = &Apache::lonnet::domain($dom,'description');
1768: if ($domdesc ne '') {
1769: $selectdomain .= ' ('.$domdesc.')';
1770: }
1771: }
1772: }
1773: $selectdomain .= "</option>\n";
1.34 matthew 1774: }
1775: $selectdomain.="</select>";
1776: return $selectdomain;
1777: }
1778:
1.35 matthew 1779: #-------------------------------------------
1780:
1.45 matthew 1781: =pod
1782:
1.648 raeburn 1783: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1784:
1.586 raeburn 1785: input: 4 arguments (two required, two optional) -
1786: $domain - domain of new user
1787: $name - name of form element
1788: $default - Value of 'default' causes a default item to be first
1789: option, and selected by default.
1790: $hide - Value of 'hide' causes hiding of the name of the server,
1791: if 1 server found, or default, if 0 found.
1.594 raeburn 1792: output: returns 2 items:
1.586 raeburn 1793: (a) form element which contains either:
1794: (i) <select name="$name">
1795: <option value="$hostid1">$hostid $servers{$hostid}</option>
1796: <option value="$hostid2">$hostid $servers{$hostid}</option>
1797: </select>
1798: form item if there are multiple library servers in $domain, or
1799: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1800: if there is only one library server in $domain.
1801:
1802: (b) number of library servers found.
1803:
1804: See loncreateuser.pm for example of use.
1.35 matthew 1805:
1806: =cut
1807:
1808: #-------------------------------------------
1.586 raeburn 1809: sub home_server_form_item {
1810: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1811: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1812: my $result;
1813: my $numlib = keys(%servers);
1814: if ($numlib > 1) {
1815: $result .= '<select name="'.$name.'" />'."\n";
1816: if ($default) {
1817: $result .= '<option value="default" selected>'.&mt('default').
1818: '</option>'."\n";
1819: }
1820: foreach my $hostid (sort(keys(%servers))) {
1821: $result.= '<option value="'.$hostid.'">'.
1822: $hostid.' '.$servers{$hostid}."</option>\n";
1823: }
1824: $result .= '</select>'."\n";
1825: } elsif ($numlib == 1) {
1826: my $hostid;
1827: foreach my $item (keys(%servers)) {
1828: $hostid = $item;
1829: }
1830: $result .= '<input type="hidden" name="'.$name.'" value="'.
1831: $hostid.'" />';
1832: if (!$hide) {
1833: $result .= $hostid.' '.$servers{$hostid};
1834: }
1835: $result .= "\n";
1836: } elsif ($default) {
1837: $result .= '<input type="hidden" name="'.$name.
1838: '" value="default" />';
1839: if (!$hide) {
1840: $result .= &mt('default');
1841: }
1842: $result .= "\n";
1.33 matthew 1843: }
1.586 raeburn 1844: return ($result,$numlib);
1.33 matthew 1845: }
1.112 bowersj2 1846:
1847: =pod
1848:
1.534 albertel 1849: =back
1850:
1.112 bowersj2 1851: =cut
1.87 matthew 1852:
1853: ###############################################################
1.112 bowersj2 1854: ## Decoding User Agent ##
1.87 matthew 1855: ###############################################################
1856:
1857: =pod
1858:
1.112 bowersj2 1859: =head1 Decoding the User Agent
1860:
1861: =over 4
1862:
1863: =item * &decode_user_agent()
1.87 matthew 1864:
1865: Inputs: $r
1866:
1867: Outputs:
1868:
1869: =over 4
1870:
1.112 bowersj2 1871: =item * $httpbrowser
1.87 matthew 1872:
1.112 bowersj2 1873: =item * $clientbrowser
1.87 matthew 1874:
1.112 bowersj2 1875: =item * $clientversion
1.87 matthew 1876:
1.112 bowersj2 1877: =item * $clientmathml
1.87 matthew 1878:
1.112 bowersj2 1879: =item * $clientunicode
1.87 matthew 1880:
1.112 bowersj2 1881: =item * $clientos
1.87 matthew 1882:
1883: =back
1884:
1.157 matthew 1885: =back
1886:
1.87 matthew 1887: =cut
1888:
1889: ###############################################################
1890: ###############################################################
1891: sub decode_user_agent {
1.247 albertel 1892: my ($r)=@_;
1.87 matthew 1893: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1894: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1895: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1896: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1897: my $clientbrowser='unknown';
1898: my $clientversion='0';
1899: my $clientmathml='';
1900: my $clientunicode='0';
1901: for (my $i=0;$i<=$#browsertype;$i++) {
1902: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1903: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1904: $clientbrowser=$bname;
1905: $httpbrowser=~/$vreg/i;
1906: $clientversion=$1;
1907: $clientmathml=($clientversion>=$minv);
1908: $clientunicode=($clientversion>=$univ);
1909: }
1910: }
1911: my $clientos='unknown';
1912: if (($httpbrowser=~/linux/i) ||
1913: ($httpbrowser=~/unix/i) ||
1914: ($httpbrowser=~/ux/i) ||
1915: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1916: if (($httpbrowser=~/vax/i) ||
1917: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1918: if ($httpbrowser=~/next/i) { $clientos='next'; }
1919: if (($httpbrowser=~/mac/i) ||
1920: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1921: if ($httpbrowser=~/win/i) { $clientos='win'; }
1922: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1923: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1924: $clientunicode,$clientos,);
1925: }
1926:
1.32 matthew 1927: ###############################################################
1928: ## Authentication changing form generation subroutines ##
1929: ###############################################################
1930: ##
1931: ## All of the authform_xxxxxxx subroutines take their inputs in a
1932: ## hash, and have reasonable default values.
1933: ##
1934: ## formname = the name given in the <form> tag.
1.35 matthew 1935: #-------------------------------------------
1936:
1.45 matthew 1937: =pod
1938:
1.112 bowersj2 1939: =head1 Authentication Routines
1940:
1941: =over 4
1942:
1.648 raeburn 1943: =item * &authform_xxxxxx()
1.35 matthew 1944:
1945: The authform_xxxxxx subroutines provide javascript and html forms which
1946: handle some of the conveniences required for authentication forms.
1947: This is not an optimal method, but it works.
1948:
1949: =over 4
1950:
1.112 bowersj2 1951: =item * authform_header
1.35 matthew 1952:
1.112 bowersj2 1953: =item * authform_authorwarning
1.35 matthew 1954:
1.112 bowersj2 1955: =item * authform_nochange
1.35 matthew 1956:
1.112 bowersj2 1957: =item * authform_kerberos
1.35 matthew 1958:
1.112 bowersj2 1959: =item * authform_internal
1.35 matthew 1960:
1.112 bowersj2 1961: =item * authform_filesystem
1.35 matthew 1962:
1963: =back
1964:
1.648 raeburn 1965: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1966:
1.35 matthew 1967: =cut
1968:
1969: #-------------------------------------------
1.32 matthew 1970: sub authform_header{
1971: my %in = (
1972: formname => 'cu',
1.80 albertel 1973: kerb_def_dom => '',
1.32 matthew 1974: @_,
1975: );
1976: $in{'formname'} = 'document.' . $in{'formname'};
1977: my $result='';
1.80 albertel 1978:
1979: #---------------------------------------------- Code for upper case translation
1980: my $Javascript_toUpperCase;
1981: unless ($in{kerb_def_dom}) {
1982: $Javascript_toUpperCase =<<"END";
1983: switch (choice) {
1984: case 'krb': currentform.elements[choicearg].value =
1985: currentform.elements[choicearg].value.toUpperCase();
1986: break;
1987: default:
1988: }
1989: END
1990: } else {
1991: $Javascript_toUpperCase = "";
1992: }
1993:
1.165 raeburn 1994: my $radioval = "'nochange'";
1.591 raeburn 1995: if (defined($in{'curr_authtype'})) {
1996: if ($in{'curr_authtype'} ne '') {
1997: $radioval = "'".$in{'curr_authtype'}."arg'";
1998: }
1.174 matthew 1999: }
1.165 raeburn 2000: my $argfield = 'null';
1.591 raeburn 2001: if (defined($in{'mode'})) {
1.165 raeburn 2002: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2003: if (defined($in{'curr_autharg'})) {
2004: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2005: $argfield = "'$in{'curr_autharg'}'";
2006: }
2007: }
2008: }
2009: }
2010:
1.32 matthew 2011: $result.=<<"END";
2012: var current = new Object();
1.165 raeburn 2013: current.radiovalue = $radioval;
2014: current.argfield = $argfield;
1.32 matthew 2015:
2016: function changed_radio(choice,currentform) {
2017: var choicearg = choice + 'arg';
2018: // If a radio button in changed, we need to change the argfield
2019: if (current.radiovalue != choice) {
2020: current.radiovalue = choice;
2021: if (current.argfield != null) {
2022: currentform.elements[current.argfield].value = '';
2023: }
2024: if (choice == 'nochange') {
2025: current.argfield = null;
2026: } else {
2027: current.argfield = choicearg;
2028: switch(choice) {
2029: case 'krb':
2030: currentform.elements[current.argfield].value =
2031: "$in{'kerb_def_dom'}";
2032: break;
2033: default:
2034: break;
2035: }
2036: }
2037: }
2038: return;
2039: }
1.22 www 2040:
1.32 matthew 2041: function changed_text(choice,currentform) {
2042: var choicearg = choice + 'arg';
2043: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2044: $Javascript_toUpperCase
1.32 matthew 2045: // clear old field
2046: if ((current.argfield != choicearg) && (current.argfield != null)) {
2047: currentform.elements[current.argfield].value = '';
2048: }
2049: current.argfield = choicearg;
2050: }
2051: set_auth_radio_buttons(choice,currentform);
2052: return;
1.20 www 2053: }
1.32 matthew 2054:
2055: function set_auth_radio_buttons(newvalue,currentform) {
2056: var i=0;
2057: while (i < currentform.login.length) {
2058: if (currentform.login[i].value == newvalue) { break; }
2059: i++;
2060: }
2061: if (i == currentform.login.length) {
2062: return;
2063: }
2064: current.radiovalue = newvalue;
2065: currentform.login[i].checked = true;
2066: return;
2067: }
2068: END
2069: return $result;
2070: }
2071:
2072: sub authform_authorwarning{
2073: my $result='';
1.144 matthew 2074: $result='<i>'.
2075: &mt('As a general rule, only authors or co-authors should be '.
2076: 'filesystem authenticated '.
2077: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2078: return $result;
2079: }
2080:
2081: sub authform_nochange{
2082: my %in = (
2083: formname => 'document.cu',
2084: kerb_def_dom => 'MSU.EDU',
2085: @_,
2086: );
1.586 raeburn 2087: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2088: my $result;
2089: if (keys(%can_assign) == 0) {
2090: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2091: } else {
2092: $result = '<label>'.&mt('[_1] Do not change login data',
2093: '<input type="radio" name="login" value="nochange" '.
2094: 'checked="checked" onclick="'.
1.281 albertel 2095: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2096: '</label>';
1.586 raeburn 2097: }
1.32 matthew 2098: return $result;
2099: }
2100:
1.591 raeburn 2101: sub authform_kerberos {
1.32 matthew 2102: my %in = (
2103: formname => 'document.cu',
2104: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2105: kerb_def_auth => 'krb4',
1.32 matthew 2106: @_,
2107: );
1.586 raeburn 2108: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2109: $autharg,$jscall);
2110: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2111: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2112: $check5 = ' checked="on"';
1.80 albertel 2113: } else {
1.586 raeburn 2114: $check4 = ' checked="on"';
1.80 albertel 2115: }
1.165 raeburn 2116: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2117: if (defined($in{'curr_authtype'})) {
2118: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2119: $krbcheck = ' checked="on"';
1.623 raeburn 2120: if (defined($in{'mode'})) {
2121: if ($in{'mode'} eq 'modifyuser') {
2122: $krbcheck = '';
2123: }
2124: }
1.591 raeburn 2125: if (defined($in{'curr_kerb_ver'})) {
2126: if ($in{'curr_krb_ver'} eq '5') {
2127: $check5 = ' checked="on"';
2128: $check4 = '';
2129: } else {
2130: $check4 = ' checked="on"';
2131: $check5 = '';
2132: }
1.586 raeburn 2133: }
1.591 raeburn 2134: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2135: $krbarg = $in{'curr_autharg'};
2136: }
1.586 raeburn 2137: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2138: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2139: $result =
2140: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2141: $in{'curr_autharg'},$krbver);
2142: } else {
2143: $result =
2144: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2145: }
2146: return $result;
2147: }
2148: }
2149: } else {
2150: if ($authnum == 1) {
2151: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2152: }
2153: }
1.586 raeburn 2154: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2155: return;
1.587 raeburn 2156: } elsif ($authtype eq '') {
1.591 raeburn 2157: if (defined($in{'mode'})) {
1.587 raeburn 2158: if ($in{'mode'} eq 'modifycourse') {
2159: if ($authnum == 1) {
2160: $authtype = '<input type="hidden" name="login" value="krb">';
2161: }
2162: }
2163: }
1.586 raeburn 2164: }
2165: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2166: if ($authtype eq '') {
2167: $authtype = '<input type="radio" name="login" value="krb" '.
2168: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2169: $krbcheck.' />';
2170: }
2171: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2172: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2173: $in{'curr_authtype'} eq 'krb5') ||
2174: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2175: $in{'curr_authtype'} eq 'krb4')) {
2176: $result .= &mt
1.144 matthew 2177: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2178: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2179: '<label>'.$authtype,
1.281 albertel 2180: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2181: 'value="'.$krbarg.'" '.
1.144 matthew 2182: 'onchange="'.$jscall.'" />',
1.281 albertel 2183: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2184: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2185: '</label>');
1.586 raeburn 2186: } elsif ($can_assign{'krb4'}) {
2187: $result .= &mt
2188: ('[_1] Kerberos authenticated with domain [_2] '.
2189: '[_3] Version 4 [_4]',
2190: '<label>'.$authtype,
2191: '</label><input type="text" size="10" name="krbarg" '.
2192: 'value="'.$krbarg.'" '.
2193: 'onchange="'.$jscall.'" />',
2194: '<label><input type="hidden" name="krbver" value="4" />',
2195: '</label>');
2196: } elsif ($can_assign{'krb5'}) {
2197: $result .= &mt
2198: ('[_1] Kerberos authenticated with domain [_2] '.
2199: '[_3] Version 5 [_4]',
2200: '<label>'.$authtype,
2201: '</label><input type="text" size="10" name="krbarg" '.
2202: 'value="'.$krbarg.'" '.
2203: 'onchange="'.$jscall.'" />',
2204: '<label><input type="hidden" name="krbver" value="5" />',
2205: '</label>');
2206: }
1.32 matthew 2207: return $result;
2208: }
2209:
2210: sub authform_internal{
1.586 raeburn 2211: my %in = (
1.32 matthew 2212: formname => 'document.cu',
2213: kerb_def_dom => 'MSU.EDU',
2214: @_,
2215: );
1.586 raeburn 2216: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2217: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2218: if (defined($in{'curr_authtype'})) {
2219: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2220: if ($can_assign{'int'}) {
2221: $intcheck = 'checked="on" ';
1.623 raeburn 2222: if (defined($in{'mode'})) {
2223: if ($in{'mode'} eq 'modifyuser') {
2224: $intcheck = '';
2225: }
2226: }
1.591 raeburn 2227: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2228: $intarg = $in{'curr_autharg'};
2229: }
2230: } else {
2231: $result = &mt('Currently internally authenticated.');
2232: return $result;
1.165 raeburn 2233: }
2234: }
1.586 raeburn 2235: } else {
2236: if ($authnum == 1) {
2237: $authtype = '<input type="hidden" name="login" value="int">';
2238: }
2239: }
2240: if (!$can_assign{'int'}) {
2241: return;
1.587 raeburn 2242: } elsif ($authtype eq '') {
1.591 raeburn 2243: if (defined($in{'mode'})) {
1.587 raeburn 2244: if ($in{'mode'} eq 'modifycourse') {
2245: if ($authnum == 1) {
2246: $authtype = '<input type="hidden" name="login" value="int">';
2247: }
2248: }
2249: }
1.165 raeburn 2250: }
1.586 raeburn 2251: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2252: if ($authtype eq '') {
2253: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2254: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2255: }
1.605 bisitz 2256: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2257: $intarg.'" onchange="'.$jscall.'" />';
2258: $result = &mt
1.144 matthew 2259: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2260: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2261: $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 2262: return $result;
2263: }
2264:
2265: sub authform_local{
2266: my %in = (
2267: formname => 'document.cu',
2268: kerb_def_dom => 'MSU.EDU',
2269: @_,
2270: );
1.586 raeburn 2271: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2272: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2273: if (defined($in{'curr_authtype'})) {
2274: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2275: if ($can_assign{'loc'}) {
2276: $loccheck = 'checked="on" ';
1.623 raeburn 2277: if (defined($in{'mode'})) {
2278: if ($in{'mode'} eq 'modifyuser') {
2279: $loccheck = '';
2280: }
2281: }
1.591 raeburn 2282: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2283: $locarg = $in{'curr_autharg'};
2284: }
2285: } else {
2286: $result = &mt('Currently using local (institutional) authentication.');
2287: return $result;
1.165 raeburn 2288: }
2289: }
1.586 raeburn 2290: } else {
2291: if ($authnum == 1) {
2292: $authtype = '<input type="hidden" name="login" value="loc">';
2293: }
2294: }
2295: if (!$can_assign{'loc'}) {
2296: return;
1.587 raeburn 2297: } elsif ($authtype eq '') {
1.591 raeburn 2298: if (defined($in{'mode'})) {
1.587 raeburn 2299: if ($in{'mode'} eq 'modifycourse') {
2300: if ($authnum == 1) {
2301: $authtype = '<input type="hidden" name="login" value="loc">';
2302: }
2303: }
2304: }
1.165 raeburn 2305: }
1.586 raeburn 2306: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2307: if ($authtype eq '') {
2308: $authtype = '<input type="radio" name="login" value="loc" '.
2309: $loccheck.' onchange="'.$jscall.'" onclick="'.
2310: $jscall.'" />';
2311: }
2312: $autharg = '<input type="text" size="10" name="locarg" value="'.
2313: $locarg.'" onchange="'.$jscall.'" />';
2314: $result = &mt('[_1] Local Authentication with argument [_2]',
2315: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2316: return $result;
2317: }
2318:
2319: sub authform_filesystem{
2320: my %in = (
2321: formname => 'document.cu',
2322: kerb_def_dom => 'MSU.EDU',
2323: @_,
2324: );
1.586 raeburn 2325: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2326: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2327: if (defined($in{'curr_authtype'})) {
2328: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2329: if ($can_assign{'fsys'}) {
2330: $fsyscheck = 'checked="on" ';
1.623 raeburn 2331: if (defined($in{'mode'})) {
2332: if ($in{'mode'} eq 'modifyuser') {
2333: $fsyscheck = '';
2334: }
2335: }
1.586 raeburn 2336: } else {
2337: $result = &mt('Currently Filesystem Authenticated.');
2338: return $result;
2339: }
2340: }
2341: } else {
2342: if ($authnum == 1) {
2343: $authtype = '<input type="hidden" name="login" value="fsys">';
2344: }
2345: }
2346: if (!$can_assign{'fsys'}) {
2347: return;
1.587 raeburn 2348: } elsif ($authtype eq '') {
1.591 raeburn 2349: if (defined($in{'mode'})) {
1.587 raeburn 2350: if ($in{'mode'} eq 'modifycourse') {
2351: if ($authnum == 1) {
2352: $authtype = '<input type="hidden" name="login" value="fsys">';
2353: }
2354: }
2355: }
1.586 raeburn 2356: }
2357: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2358: if ($authtype eq '') {
2359: $authtype = '<input type="radio" name="login" value="fsys" '.
2360: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2361: $jscall.'" />';
2362: }
2363: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2364: ' onchange="'.$jscall.'" />';
2365: $result = &mt
1.144 matthew 2366: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2367: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2368: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2369: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2370: 'onchange="'.$jscall.'" />');
1.32 matthew 2371: return $result;
2372: }
2373:
1.586 raeburn 2374: sub get_assignable_auth {
2375: my ($dom) = @_;
2376: if ($dom eq '') {
2377: $dom = $env{'request.role.domain'};
2378: }
2379: my %can_assign = (
2380: krb4 => 1,
2381: krb5 => 1,
2382: int => 1,
2383: loc => 1,
2384: );
2385: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2386: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2387: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2388: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2389: my $context;
2390: if ($env{'request.role'} =~ /^au/) {
2391: $context = 'author';
2392: } elsif ($env{'request.role'} =~ /^dc/) {
2393: $context = 'domain';
2394: } elsif ($env{'request.course.id'}) {
2395: $context = 'course';
2396: }
2397: if ($context) {
2398: if (ref($authhash->{$context}) eq 'HASH') {
2399: %can_assign = %{$authhash->{$context}};
2400: }
2401: }
2402: }
2403: }
2404: my $authnum = 0;
2405: foreach my $key (keys(%can_assign)) {
2406: if ($can_assign{$key}) {
2407: $authnum ++;
2408: }
2409: }
2410: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2411: $authnum --;
2412: }
2413: return ($authnum,%can_assign);
2414: }
2415:
1.80 albertel 2416: ###############################################################
2417: ## Get Kerberos Defaults for Domain ##
2418: ###############################################################
2419: ##
2420: ## Returns default kerberos version and an associated argument
2421: ## as listed in file domain.tab. If not listed, provides
2422: ## appropriate default domain and kerberos version.
2423: ##
2424: #-------------------------------------------
2425:
2426: =pod
2427:
1.648 raeburn 2428: =item * &get_kerberos_defaults()
1.80 albertel 2429:
2430: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2431: version and domain. If not found, it defaults to version 4 and the
2432: domain of the server.
1.80 albertel 2433:
1.648 raeburn 2434: =over 4
2435:
1.80 albertel 2436: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2437:
1.648 raeburn 2438: =back
2439:
2440: =back
2441:
1.80 albertel 2442: =cut
2443:
2444: #-------------------------------------------
2445: sub get_kerberos_defaults {
2446: my $domain=shift;
1.641 raeburn 2447: my ($krbdef,$krbdefdom);
2448: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2449: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2450: $krbdef = $domdefaults{'auth_def'};
2451: $krbdefdom = $domdefaults{'auth_arg_def'};
2452: } else {
1.80 albertel 2453: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2454: my $krbdefdom=$1;
2455: $krbdefdom=~tr/a-z/A-Z/;
2456: $krbdef = "krb4";
2457: }
2458: return ($krbdef,$krbdefdom);
2459: }
1.112 bowersj2 2460:
1.32 matthew 2461:
1.46 matthew 2462: ###############################################################
2463: ## Thesaurus Functions ##
2464: ###############################################################
1.20 www 2465:
1.46 matthew 2466: =pod
1.20 www 2467:
1.112 bowersj2 2468: =head1 Thesaurus Functions
2469:
2470: =over 4
2471:
1.648 raeburn 2472: =item * &initialize_keywords()
1.46 matthew 2473:
2474: Initializes the package variable %Keywords if it is empty. Uses the
2475: package variable $thesaurus_db_file.
2476:
2477: =cut
2478:
2479: ###################################################
2480:
2481: sub initialize_keywords {
2482: return 1 if (scalar keys(%Keywords));
2483: # If we are here, %Keywords is empty, so fill it up
2484: # Make sure the file we need exists...
2485: if (! -e $thesaurus_db_file) {
2486: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2487: " failed because it does not exist");
2488: return 0;
2489: }
2490: # Set up the hash as a database
2491: my %thesaurus_db;
2492: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2493: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2494: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2495: $thesaurus_db_file);
2496: return 0;
2497: }
2498: # Get the average number of appearances of a word.
2499: my $avecount = $thesaurus_db{'average.count'};
2500: # Put keywords (those that appear > average) into %Keywords
2501: while (my ($word,$data)=each (%thesaurus_db)) {
2502: my ($count,undef) = split /:/,$data;
2503: $Keywords{$word}++ if ($count > $avecount);
2504: }
2505: untie %thesaurus_db;
2506: # Remove special values from %Keywords.
1.356 albertel 2507: foreach my $value ('total.count','average.count') {
2508: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2509: }
1.46 matthew 2510: return 1;
2511: }
2512:
2513: ###################################################
2514:
2515: =pod
2516:
1.648 raeburn 2517: =item * &keyword($word)
1.46 matthew 2518:
2519: Returns true if $word is a keyword. A keyword is a word that appears more
2520: than the average number of times in the thesaurus database. Calls
2521: &initialize_keywords
2522:
2523: =cut
2524:
2525: ###################################################
1.20 www 2526:
2527: sub keyword {
1.46 matthew 2528: return if (!&initialize_keywords());
2529: my $word=lc(shift());
2530: $word=~s/\W//g;
2531: return exists($Keywords{$word});
1.20 www 2532: }
1.46 matthew 2533:
2534: ###############################################################
2535:
2536: =pod
1.20 www 2537:
1.648 raeburn 2538: =item * &get_related_words()
1.46 matthew 2539:
1.160 matthew 2540: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2541: an array of words. If the keyword is not in the thesaurus, an empty array
2542: will be returned. The order of the words returned is determined by the
2543: database which holds them.
2544:
2545: Uses global $thesaurus_db_file.
2546:
2547: =cut
2548:
2549: ###############################################################
2550: sub get_related_words {
2551: my $keyword = shift;
2552: my %thesaurus_db;
2553: if (! -e $thesaurus_db_file) {
2554: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2555: "failed because the file does not exist");
2556: return ();
2557: }
2558: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2559: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2560: return ();
2561: }
2562: my @Words=();
1.429 www 2563: my $count=0;
1.46 matthew 2564: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2565: # The first element is the number of times
2566: # the word appears. We do not need it now.
1.429 www 2567: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2568: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2569: my $threshold=$mostfrequentcount/10;
2570: foreach my $possibleword (@RelatedWords) {
2571: my ($word,$wordcount)=split(/\,/,$possibleword);
2572: if ($wordcount>$threshold) {
2573: push(@Words,$word);
2574: $count++;
2575: if ($count>10) { last; }
2576: }
1.20 www 2577: }
2578: }
1.46 matthew 2579: untie %thesaurus_db;
2580: return @Words;
1.14 harris41 2581: }
1.46 matthew 2582:
1.112 bowersj2 2583: =pod
2584:
2585: =back
2586:
2587: =cut
1.61 www 2588:
2589: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2590: =pod
2591:
1.112 bowersj2 2592: =head1 User Name Functions
2593:
2594: =over 4
2595:
1.648 raeburn 2596: =item * &plainname($uname,$udom,$first)
1.81 albertel 2597:
1.112 bowersj2 2598: Takes a users logon name and returns it as a string in
1.226 albertel 2599: "first middle last generation" form
2600: if $first is set to 'lastname' then it returns it as
2601: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2602:
2603: =cut
1.61 www 2604:
1.295 www 2605:
1.81 albertel 2606: ###############################################################
1.61 www 2607: sub plainname {
1.226 albertel 2608: my ($uname,$udom,$first)=@_;
1.537 albertel 2609: return if (!defined($uname) || !defined($udom));
1.295 www 2610: my %names=&getnames($uname,$udom);
1.226 albertel 2611: my $name=&Apache::lonnet::format_name($names{'firstname'},
2612: $names{'middlename'},
2613: $names{'lastname'},
2614: $names{'generation'},$first);
2615: $name=~s/^\s+//;
1.62 www 2616: $name=~s/\s+$//;
2617: $name=~s/\s+/ /g;
1.353 albertel 2618: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2619: return $name;
1.61 www 2620: }
1.66 www 2621:
2622: # -------------------------------------------------------------------- Nickname
1.81 albertel 2623: =pod
2624:
1.648 raeburn 2625: =item * &nickname($uname,$udom)
1.81 albertel 2626:
2627: Gets a users name and returns it as a string as
2628:
2629: ""nickname""
1.66 www 2630:
1.81 albertel 2631: if the user has a nickname or
2632:
2633: "first middle last generation"
2634:
2635: if the user does not
2636:
2637: =cut
1.66 www 2638:
2639: sub nickname {
2640: my ($uname,$udom)=@_;
1.537 albertel 2641: return if (!defined($uname) || !defined($udom));
1.295 www 2642: my %names=&getnames($uname,$udom);
1.68 albertel 2643: my $name=$names{'nickname'};
1.66 www 2644: if ($name) {
2645: $name='"'.$name.'"';
2646: } else {
2647: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2648: $names{'lastname'}.' '.$names{'generation'};
2649: $name=~s/\s+$//;
2650: $name=~s/\s+/ /g;
2651: }
2652: return $name;
2653: }
2654:
1.295 www 2655: sub getnames {
2656: my ($uname,$udom)=@_;
1.537 albertel 2657: return if (!defined($uname) || !defined($udom));
1.433 albertel 2658: if ($udom eq 'public' && $uname eq 'public') {
2659: return ('lastname' => &mt('Public'));
2660: }
1.295 www 2661: my $id=$uname.':'.$udom;
2662: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2663: if ($cached) {
2664: return %{$names};
2665: } else {
2666: my %loadnames=&Apache::lonnet::get('environment',
2667: ['firstname','middlename','lastname','generation','nickname'],
2668: $udom,$uname);
2669: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2670: return %loadnames;
2671: }
2672: }
1.61 www 2673:
1.542 raeburn 2674: # -------------------------------------------------------------------- getemails
1.648 raeburn 2675:
1.542 raeburn 2676: =pod
2677:
1.648 raeburn 2678: =item * &getemails($uname,$udom)
1.542 raeburn 2679:
2680: Gets a user's email information and returns it as a hash with keys:
2681: notification, critnotification, permanentemail
2682:
2683: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2684: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2685:
1.648 raeburn 2686:
1.542 raeburn 2687: =cut
2688:
1.648 raeburn 2689:
1.466 albertel 2690: sub getemails {
2691: my ($uname,$udom)=@_;
2692: if ($udom eq 'public' && $uname eq 'public') {
2693: return;
2694: }
1.467 www 2695: if (!$udom) { $udom=$env{'user.domain'}; }
2696: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2697: my $id=$uname.':'.$udom;
2698: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2699: if ($cached) {
2700: return %{$names};
2701: } else {
2702: my %loadnames=&Apache::lonnet::get('environment',
2703: ['notification','critnotification',
2704: 'permanentemail'],
2705: $udom,$uname);
2706: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2707: return %loadnames;
2708: }
2709: }
2710:
1.551 albertel 2711: sub flush_email_cache {
2712: my ($uname,$udom)=@_;
2713: if (!$udom) { $udom =$env{'user.domain'}; }
2714: if (!$uname) { $uname=$env{'user.name'}; }
2715: return if ($udom eq 'public' && $uname eq 'public');
2716: my $id=$uname.':'.$udom;
2717: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2718: }
2719:
1.692.2.9 raeburn 2720: # -------------------------------------------------------------------- getlangs
2721:
2722: =pod
2723:
2724: =item * &getlangs($uname,$udom)
2725:
2726: Gets a user's language preference and returns it as a hash with key:
2727: language.
2728:
2729: =cut
2730:
2731: sub getlangs {
2732: my ($uname,$udom) = @_;
2733: if (!$udom) { $udom =$env{'user.domain'}; }
2734: if (!$uname) { $uname=$env{'user.name'}; }
2735: my $id=$uname.':'.$udom;
2736: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2737: if ($cached) {
2738: return %{$langs};
2739: } else {
2740: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2741: $udom,$uname);
2742: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2743: return %loadlangs;
2744: }
2745: }
2746:
2747: sub flush_langs_cache {
2748: my ($uname,$udom)=@_;
2749: if (!$udom) { $udom =$env{'user.domain'}; }
2750: if (!$uname) { $uname=$env{'user.name'}; }
2751: return if ($udom eq 'public' && $uname eq 'public');
2752: my $id=$uname.':'.$udom;
2753: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2754: }
2755:
1.61 www 2756: # ------------------------------------------------------------------ Screenname
1.81 albertel 2757:
2758: =pod
2759:
1.648 raeburn 2760: =item * &screenname($uname,$udom)
1.81 albertel 2761:
2762: Gets a users screenname and returns it as a string
2763:
2764: =cut
1.61 www 2765:
2766: sub screenname {
2767: my ($uname,$udom)=@_;
1.258 albertel 2768: if ($uname eq $env{'user.name'} &&
2769: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2770: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2771: return $names{'screenname'};
1.62 www 2772: }
2773:
1.212 albertel 2774:
1.62 www 2775: # ------------------------------------------------------------- Message Wrapper
2776:
2777: sub messagewrapper {
1.369 www 2778: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2779: return
1.441 albertel 2780: '<a href="/adm/email?compose=individual&'.
2781: 'recname='.$username.'&recdom='.$domain.
2782: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2783: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2784: }
2785: # --------------------------------------------------------------- Notes Wrapper
2786:
2787: sub noteswrapper {
2788: my ($link,$un,$do)=@_;
2789: return
2790: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2791: }
2792: # ------------------------------------------------------------- Aboutme Wrapper
2793:
2794: sub aboutmewrapper {
1.166 www 2795: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2796: if (!defined($username) && !defined($domain)) {
2797: return;
2798: }
1.205 www 2799: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2800: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2801: }
2802:
2803: # ------------------------------------------------------------ Syllabus Wrapper
2804:
2805:
2806: sub syllabuswrapper {
1.109 matthew 2807: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2808: if ($fontcolor) {
2809: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2810: }
1.208 matthew 2811: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2812: }
1.14 harris41 2813:
1.208 matthew 2814: sub track_student_link {
1.268 albertel 2815: my ($linktext,$sname,$sdom,$target,$start) = @_;
2816: my $link ="/adm/trackstudent?";
1.208 matthew 2817: my $title = 'View recent activity';
2818: if (defined($sname) && $sname !~ /^\s*$/ &&
2819: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2820: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2821: $title .= ' of this student';
1.268 albertel 2822: }
1.208 matthew 2823: if (defined($target) && $target !~ /^\s*$/) {
2824: $target = qq{target="$target"};
2825: } else {
2826: $target = '';
2827: }
1.268 albertel 2828: if ($start) { $link.='&start='.$start; }
1.554 albertel 2829: $title = &mt($title);
2830: $linktext = &mt($linktext);
1.448 albertel 2831: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2832: &help_open_topic('View_recent_activity');
1.208 matthew 2833: }
2834:
1.508 www 2835: # ===================================================== Display a student photo
2836:
2837:
1.509 albertel 2838: sub student_image_tag {
1.508 www 2839: my ($domain,$user)=@_;
2840: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2841: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2842: return '<img src="'.$imgsrc.'" align="right" />';
2843: } else {
2844: return '';
2845: }
2846: }
2847:
1.112 bowersj2 2848: =pod
2849:
2850: =back
2851:
2852: =head1 Access .tab File Data
2853:
2854: =over 4
2855:
1.648 raeburn 2856: =item * &languageids()
1.112 bowersj2 2857:
2858: returns list of all language ids
2859:
2860: =cut
2861:
1.14 harris41 2862: sub languageids {
1.16 harris41 2863: return sort(keys(%language));
1.14 harris41 2864: }
2865:
1.112 bowersj2 2866: =pod
2867:
1.648 raeburn 2868: =item * &languagedescription()
1.112 bowersj2 2869:
2870: returns description of a specified language id
2871:
2872: =cut
2873:
1.14 harris41 2874: sub languagedescription {
1.125 www 2875: my $code=shift;
2876: return ($supported_language{$code}?'* ':'').
2877: $language{$code}.
1.126 www 2878: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2879: }
2880:
2881: sub plainlanguagedescription {
2882: my $code=shift;
2883: return $language{$code};
2884: }
2885:
2886: sub supportedlanguagecode {
2887: my $code=shift;
2888: return $supported_language{$code};
1.97 www 2889: }
2890:
1.112 bowersj2 2891: =pod
2892:
1.648 raeburn 2893: =item * ©rightids()
1.112 bowersj2 2894:
2895: returns list of all copyrights
2896:
2897: =cut
2898:
2899: sub copyrightids {
2900: return sort(keys(%cprtag));
2901: }
2902:
2903: =pod
2904:
1.648 raeburn 2905: =item * ©rightdescription()
1.112 bowersj2 2906:
2907: returns description of a specified copyright id
2908:
2909: =cut
2910:
2911: sub copyrightdescription {
1.166 www 2912: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2913: }
1.197 matthew 2914:
2915: =pod
2916:
1.648 raeburn 2917: =item * &source_copyrightids()
1.192 taceyjo1 2918:
2919: returns list of all source copyrights
2920:
2921: =cut
2922:
2923: sub source_copyrightids {
2924: return sort(keys(%scprtag));
2925: }
2926:
2927: =pod
2928:
1.648 raeburn 2929: =item * &source_copyrightdescription()
1.192 taceyjo1 2930:
2931: returns description of a specified source copyright id
2932:
2933: =cut
2934:
2935: sub source_copyrightdescription {
2936: return &mt($scprtag{shift(@_)});
2937: }
1.112 bowersj2 2938:
2939: =pod
2940:
1.648 raeburn 2941: =item * &filecategories()
1.112 bowersj2 2942:
2943: returns list of all file categories
2944:
2945: =cut
2946:
2947: sub filecategories {
2948: return sort(keys(%category_extensions));
2949: }
2950:
2951: =pod
2952:
1.648 raeburn 2953: =item * &filecategorytypes()
1.112 bowersj2 2954:
2955: returns list of file types belonging to a given file
2956: category
2957:
2958: =cut
2959:
2960: sub filecategorytypes {
1.356 albertel 2961: my ($cat) = @_;
2962: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2963: }
2964:
2965: =pod
2966:
1.648 raeburn 2967: =item * &fileembstyle()
1.112 bowersj2 2968:
2969: returns embedding style for a specified file type
2970:
2971: =cut
2972:
2973: sub fileembstyle {
2974: return $fe{lc(shift(@_))};
1.169 www 2975: }
2976:
1.351 www 2977: sub filemimetype {
2978: return $fm{lc(shift(@_))};
2979: }
2980:
1.169 www 2981:
2982: sub filecategoryselect {
2983: my ($name,$value)=@_;
1.189 matthew 2984: return &select_form($value,$name,
1.169 www 2985: '' => &mt('Any category'),
2986: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2987: }
2988:
2989: =pod
2990:
1.648 raeburn 2991: =item * &filedescription()
1.112 bowersj2 2992:
2993: returns description for a specified file type
2994:
2995: =cut
2996:
2997: sub filedescription {
1.188 matthew 2998: my $file_description = $fd{lc(shift())};
2999: $file_description =~ s:([\[\]]):~$1:g;
3000: return &mt($file_description);
1.112 bowersj2 3001: }
3002:
3003: =pod
3004:
1.648 raeburn 3005: =item * &filedescriptionex()
1.112 bowersj2 3006:
3007: returns description for a specified file type with
3008: extra formatting
3009:
3010: =cut
3011:
3012: sub filedescriptionex {
3013: my $ex=shift;
1.188 matthew 3014: my $file_description = $fd{lc($ex)};
3015: $file_description =~ s:([\[\]]):~$1:g;
3016: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3017: }
3018:
3019: # End of .tab access
3020: =pod
3021:
3022: =back
3023:
3024: =cut
3025:
3026: # ------------------------------------------------------------------ File Types
3027: sub fileextensions {
3028: return sort(keys(%fe));
3029: }
3030:
1.97 www 3031: # ----------------------------------------------------------- Display Languages
3032: # returns a hash with all desired display languages
3033: #
3034:
3035: sub display_languages {
3036: my %languages=();
1.692.2.1 raeburn 3037: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3038: $languages{$lang}=1;
1.97 www 3039: }
3040: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3041: if ($env{'form.displaylanguage'}) {
1.356 albertel 3042: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3043: $languages{$lang}=1;
1.97 www 3044: }
3045: }
3046: return %languages;
1.14 harris41 3047: }
3048:
1.582 albertel 3049: sub languages {
3050: my ($possible_langs) = @_;
1.692.2.1 raeburn 3051: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3052: if (!ref($possible_langs)) {
3053: if( wantarray ) {
3054: return @preferred_langs;
3055: } else {
3056: return $preferred_langs[0];
3057: }
3058: }
3059: my %possibilities = map { $_ => 1 } (@$possible_langs);
3060: my @preferred_possibilities;
3061: foreach my $preferred_lang (@preferred_langs) {
3062: if (exists($possibilities{$preferred_lang})) {
3063: push(@preferred_possibilities, $preferred_lang);
3064: }
3065: }
3066: if( wantarray ) {
3067: return @preferred_possibilities;
3068: }
3069: return $preferred_possibilities[0];
3070: }
3071:
1.112 bowersj2 3072: ###############################################################
3073: ## Student Answer Attempts ##
3074: ###############################################################
3075:
3076: =pod
3077:
3078: =head1 Alternate Problem Views
3079:
3080: =over 4
3081:
1.648 raeburn 3082: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3083: $getattempt, $regexp, $gradesub)
3084:
3085: Return string with previous attempt on problem. Arguments:
3086:
3087: =over 4
3088:
3089: =item * $symb: Problem, including path
3090:
3091: =item * $username: username of the desired student
3092:
3093: =item * $domain: domain of the desired student
1.14 harris41 3094:
1.112 bowersj2 3095: =item * $course: Course ID
1.14 harris41 3096:
1.112 bowersj2 3097: =item * $getattempt: Leave blank for all attempts, otherwise put
3098: something
1.14 harris41 3099:
1.112 bowersj2 3100: =item * $regexp: if string matches this regexp, the string will be
3101: sent to $gradesub
1.14 harris41 3102:
1.112 bowersj2 3103: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3104:
1.112 bowersj2 3105: =back
1.14 harris41 3106:
1.112 bowersj2 3107: The output string is a table containing all desired attempts, if any.
1.16 harris41 3108:
1.112 bowersj2 3109: =cut
1.1 albertel 3110:
3111: sub get_previous_attempt {
1.43 ng 3112: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3113: my $prevattempts='';
1.43 ng 3114: no strict 'refs';
1.1 albertel 3115: if ($symb) {
1.3 albertel 3116: my (%returnhash)=
3117: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3118: if ($returnhash{'version'}) {
3119: my %lasthash=();
3120: my $version;
3121: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3122: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3123: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3124: }
1.1 albertel 3125: }
1.596 albertel 3126: $prevattempts=&start_data_table().&start_data_table_header_row();
3127: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3128: foreach my $key (sort(keys(%lasthash))) {
3129: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3130: if ($#parts > 0) {
1.31 albertel 3131: my $data=$parts[-1];
3132: pop(@parts);
1.596 albertel 3133: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3134: } else {
1.41 ng 3135: if ($#parts == 0) {
3136: $prevattempts.='<th>'.$parts[0].'</th>';
3137: } else {
3138: $prevattempts.='<th>'.$ign.'</th>';
3139: }
1.31 albertel 3140: }
1.16 harris41 3141: }
1.596 albertel 3142: $prevattempts.=&end_data_table_header_row();
1.40 ng 3143: if ($getattempt eq '') {
3144: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3145: $prevattempts.=&start_data_table_row().
3146: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3147: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3148: my $value = &format_previous_attempt_value($key,
3149: $returnhash{$version.':'.$key});
3150: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3151: }
1.596 albertel 3152: $prevattempts.=&end_data_table_row();
1.40 ng 3153: }
1.1 albertel 3154: }
1.596 albertel 3155: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3156: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3157: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3158: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3159: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3160: }
1.596 albertel 3161: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3162: } else {
1.596 albertel 3163: $prevattempts=
3164: &start_data_table().&start_data_table_row().
3165: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3166: &end_data_table_row().&end_data_table();
1.1 albertel 3167: }
3168: } else {
1.596 albertel 3169: $prevattempts=
3170: &start_data_table().&start_data_table_row().
3171: '<td>'.&mt('No data.').'</td>'.
3172: &end_data_table_row().&end_data_table();
1.1 albertel 3173: }
1.10 albertel 3174: }
3175:
1.581 albertel 3176: sub format_previous_attempt_value {
3177: my ($key,$value) = @_;
3178: if ($key =~ /timestamp/) {
3179: $value = &Apache::lonlocal::locallocaltime($value);
3180: } elsif (ref($value) eq 'ARRAY') {
3181: $value = '('.join(', ', @{ $value }).')';
3182: } else {
3183: $value = &unescape($value);
3184: }
3185: return $value;
3186: }
3187:
3188:
1.107 albertel 3189: sub relative_to_absolute {
3190: my ($url,$output)=@_;
3191: my $parser=HTML::TokeParser->new(\$output);
3192: my $token;
3193: my $thisdir=$url;
3194: my @rlinks=();
3195: while ($token=$parser->get_token) {
3196: if ($token->[0] eq 'S') {
3197: if ($token->[1] eq 'a') {
3198: if ($token->[2]->{'href'}) {
3199: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3200: }
3201: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3202: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3203: } elsif ($token->[1] eq 'base') {
3204: $thisdir=$token->[2]->{'href'};
3205: }
3206: }
3207: }
3208: $thisdir=~s-/[^/]*$--;
1.356 albertel 3209: foreach my $link (@rlinks) {
1.692.2.8 raeburn 3210: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3211: ($link=~/^\//) ||
3212: ($link=~/^javascript:/i) ||
3213: ($link=~/^mailto:/i) ||
3214: ($link=~/^\#/)) {
3215: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3216: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3217: }
3218: }
3219: # -------------------------------------------------- Deal with Applet codebases
3220: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3221: return $output;
3222: }
3223:
1.112 bowersj2 3224: =pod
3225:
1.648 raeburn 3226: =item * &get_student_view()
1.112 bowersj2 3227:
3228: show a snapshot of what student was looking at
3229:
3230: =cut
3231:
1.10 albertel 3232: sub get_student_view {
1.186 albertel 3233: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3234: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3235: my (%form);
1.10 albertel 3236: my @elements=('symb','courseid','domain','username');
3237: foreach my $element (@elements) {
1.186 albertel 3238: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3239: }
1.186 albertel 3240: if (defined($moreenv)) {
3241: %form=(%form,%{$moreenv});
3242: }
1.236 albertel 3243: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3244: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3245: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3246: $userview=~s/\<body[^\>]*\>//gi;
3247: $userview=~s/\<\/body\>//gi;
3248: $userview=~s/\<html\>//gi;
3249: $userview=~s/\<\/html\>//gi;
3250: $userview=~s/\<head\>//gi;
3251: $userview=~s/\<\/head\>//gi;
3252: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3253: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3254: if (wantarray) {
3255: return ($userview,$response);
3256: } else {
3257: return $userview;
3258: }
3259: }
3260:
3261: sub get_student_view_with_retries {
3262: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3263:
3264: my $ok = 0; # True if we got a good response.
3265: my $content;
3266: my $response;
3267:
3268: # Try to get the student_view done. within the retries count:
3269:
3270: do {
3271: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3272: $ok = $response->is_success;
3273: if (!$ok) {
3274: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3275: }
3276: $retries--;
3277: } while (!$ok && ($retries > 0));
3278:
3279: if (!$ok) {
3280: $content = ''; # On error return an empty content.
3281: }
1.651 www 3282: if (wantarray) {
3283: return ($content, $response);
3284: } else {
3285: return $content;
3286: }
1.11 albertel 3287: }
3288:
1.112 bowersj2 3289: =pod
3290:
1.648 raeburn 3291: =item * &get_student_answers()
1.112 bowersj2 3292:
3293: show a snapshot of how student was answering problem
3294:
3295: =cut
3296:
1.11 albertel 3297: sub get_student_answers {
1.100 sakharuk 3298: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3299: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3300: my (%moreenv);
1.11 albertel 3301: my @elements=('symb','courseid','domain','username');
3302: foreach my $element (@elements) {
1.186 albertel 3303: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3304: }
1.186 albertel 3305: $moreenv{'grade_target'}='answer';
3306: %moreenv=(%form,%moreenv);
1.497 raeburn 3307: $feedurl = &Apache::lonnet::clutter($feedurl);
3308: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3309: return $userview;
1.1 albertel 3310: }
1.116 albertel 3311:
3312: =pod
3313:
3314: =item * &submlink()
3315:
1.242 albertel 3316: Inputs: $text $uname $udom $symb $target
1.116 albertel 3317:
3318: Returns: A link to grades.pm such as to see the SUBM view of a student
3319:
3320: =cut
3321:
3322: ###############################################
3323: sub submlink {
1.242 albertel 3324: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3325: if (!($uname && $udom)) {
3326: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3327: &Apache::lonnet::whichuser($symb);
1.116 albertel 3328: if (!$symb) { $symb=$cursymb; }
3329: }
1.254 matthew 3330: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3331: $symb=&escape($symb);
1.242 albertel 3332: if ($target) { $target="target=\"$target\""; }
3333: return '<a href="/adm/grades?&command=submission&'.
3334: 'symb='.$symb.'&student='.$uname.
3335: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3336: }
3337: ##############################################
3338:
3339: =pod
3340:
3341: =item * &pgrdlink()
3342:
3343: Inputs: $text $uname $udom $symb $target
3344:
3345: Returns: A link to grades.pm such as to see the PGRD view of a student
3346:
3347: =cut
3348:
3349: ###############################################
3350: sub pgrdlink {
3351: my $link=&submlink(@_);
3352: $link=~s/(&command=submission)/$1&showgrading=yes/;
3353: return $link;
3354: }
3355: ##############################################
3356:
3357: =pod
3358:
3359: =item * &pprmlink()
3360:
3361: Inputs: $text $uname $udom $symb $target
3362:
3363: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3364: student and a specific resource
1.242 albertel 3365:
3366: =cut
3367:
3368: ###############################################
3369: sub pprmlink {
3370: my ($text,$uname,$udom,$symb,$target)=@_;
3371: if (!($uname && $udom)) {
3372: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3373: &Apache::lonnet::whichuser($symb);
1.242 albertel 3374: if (!$symb) { $symb=$cursymb; }
3375: }
1.254 matthew 3376: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3377: $symb=&escape($symb);
1.242 albertel 3378: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3379: return '<a href="/adm/parmset?command=set&'.
3380: 'symb='.$symb.'&uname='.$uname.
3381: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3382: }
3383: ##############################################
1.37 matthew 3384:
1.112 bowersj2 3385: =pod
3386:
3387: =back
3388:
3389: =cut
3390:
1.37 matthew 3391: ###############################################
1.51 www 3392:
3393:
3394: sub timehash {
1.687 raeburn 3395: my ($thistime) = @_;
3396: my $timezone = &Apache::lonlocal::gettimezone();
3397: my $dt = DateTime->from_epoch(epoch => $thistime)
3398: ->set_time_zone($timezone);
3399: my $wday = $dt->day_of_week();
3400: if ($wday == 7) { $wday = 0; }
3401: return ( 'second' => $dt->second(),
3402: 'minute' => $dt->minute(),
3403: 'hour' => $dt->hour(),
3404: 'day' => $dt->day_of_month(),
3405: 'month' => $dt->month(),
3406: 'year' => $dt->year(),
3407: 'weekday' => $wday,
3408: 'dayyear' => $dt->day_of_year(),
3409: 'dlsav' => $dt->is_dst() );
1.51 www 3410: }
3411:
1.370 www 3412: sub utc_string {
3413: my ($date)=@_;
1.371 www 3414: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3415: }
3416:
1.51 www 3417: sub maketime {
3418: my %th=@_;
1.687 raeburn 3419: my ($epoch_time,$timezone,$dt);
3420: $timezone = &Apache::lonlocal::gettimezone();
3421: eval {
3422: $dt = DateTime->new( year => $th{'year'},
3423: month => $th{'month'},
3424: day => $th{'day'},
3425: hour => $th{'hour'},
3426: minute => $th{'minute'},
3427: second => $th{'second'},
3428: time_zone => $timezone,
3429: );
3430: };
3431: if (!$@) {
3432: $epoch_time = $dt->epoch;
3433: if ($epoch_time) {
3434: return $epoch_time;
3435: }
3436: }
1.51 www 3437: return POSIX::mktime(
3438: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3439: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3440: }
3441:
3442: #########################################
1.51 www 3443:
3444: sub findallcourses {
1.482 raeburn 3445: my ($roles,$uname,$udom) = @_;
1.355 albertel 3446: my %roles;
3447: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3448: my %courses;
1.51 www 3449: my $now=time;
1.482 raeburn 3450: if (!defined($uname)) {
3451: $uname = $env{'user.name'};
3452: }
3453: if (!defined($udom)) {
3454: $udom = $env{'user.domain'};
3455: }
3456: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3457: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3458: if (!%roles) {
3459: %roles = (
3460: cc => 1,
3461: in => 1,
3462: ep => 1,
3463: ta => 1,
3464: cr => 1,
3465: st => 1,
3466: );
3467: }
3468: foreach my $entry (keys(%roleshash)) {
3469: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3470: if ($trole =~ /^cr/) {
3471: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3472: } else {
3473: next if (!exists($roles{$trole}));
3474: }
3475: if ($tend) {
3476: next if ($tend < $now);
3477: }
3478: if ($tstart) {
3479: next if ($tstart > $now);
3480: }
3481: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3482: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3483: if ($secpart eq '') {
3484: ($cnum,$role) = split(/_/,$cnumpart);
3485: $sec = 'none';
3486: $realsec = '';
3487: } else {
3488: $cnum = $cnumpart;
3489: ($sec,$role) = split(/_/,$secpart);
3490: $realsec = $sec;
1.490 raeburn 3491: }
1.482 raeburn 3492: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3493: }
3494: } else {
3495: foreach my $key (keys(%env)) {
1.483 albertel 3496: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3497: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3498: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3499: next if ($role eq 'ca' || $role eq 'aa');
3500: next if (%roles && !exists($roles{$role}));
3501: my ($starttime,$endtime)=split(/\./,$env{$key});
3502: my $active=1;
3503: if ($starttime) {
3504: if ($now<$starttime) { $active=0; }
3505: }
3506: if ($endtime) {
3507: if ($now>$endtime) { $active=0; }
3508: }
3509: if ($active) {
3510: if ($sec eq '') {
3511: $sec = 'none';
3512: }
3513: $courses{$cdom.'_'.$cnum}{$sec} =
3514: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3515: }
3516: }
1.51 www 3517: }
3518: }
1.474 raeburn 3519: return %courses;
1.51 www 3520: }
1.37 matthew 3521:
1.54 www 3522: ###############################################
1.474 raeburn 3523:
3524: sub blockcheck {
1.482 raeburn 3525: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3526:
3527: if (!defined($udom)) {
3528: $udom = $env{'user.domain'};
3529: }
3530: if (!defined($uname)) {
3531: $uname = $env{'user.name'};
3532: }
3533:
3534: # If uname and udom are for a course, check for blocks in the course.
3535:
3536: if (&Apache::lonnet::is_course($udom,$uname)) {
3537: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3538: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3539: return ($startblock,$endblock);
3540: }
1.474 raeburn 3541:
1.502 raeburn 3542: my $startblock = 0;
3543: my $endblock = 0;
1.482 raeburn 3544: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3545:
1.490 raeburn 3546: # If uname is for a user, and activity is course-specific, i.e.,
3547: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3548:
1.490 raeburn 3549: if (($activity eq 'boards' || $activity eq 'chat' ||
3550: $activity eq 'groups') && ($env{'request.course.id'})) {
3551: foreach my $key (keys(%live_courses)) {
3552: if ($key ne $env{'request.course.id'}) {
3553: delete($live_courses{$key});
3554: }
3555: }
3556: }
3557:
3558: my $otheruser = 0;
3559: my %own_courses;
3560: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3561: # Resource belongs to user other than current user.
3562: $otheruser = 1;
3563: # Gather courses for current user
3564: %own_courses =
3565: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3566: }
3567:
3568: # Gather active course roles - course coordinator, instructor,
3569: # exam proctor, ta, student, or custom role.
1.474 raeburn 3570:
3571: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3572: my ($cdom,$cnum);
3573: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3574: $cdom = $env{'course.'.$course.'.domain'};
3575: $cnum = $env{'course.'.$course.'.num'};
3576: } else {
1.490 raeburn 3577: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3578: }
3579: my $no_ownblock = 0;
3580: my $no_userblock = 0;
1.533 raeburn 3581: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3582: # Check if current user has 'evb' priv for this
3583: if (defined($own_courses{$course})) {
3584: foreach my $sec (keys(%{$own_courses{$course}})) {
3585: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3586: if ($sec ne 'none') {
3587: $checkrole .= '/'.$sec;
3588: }
3589: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3590: $no_ownblock = 1;
3591: last;
3592: }
3593: }
3594: }
3595: # if they have 'evb' priv and are currently not playing student
3596: next if (($no_ownblock) &&
3597: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3598: }
1.474 raeburn 3599: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3600: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3601: if ($sec ne 'none') {
1.482 raeburn 3602: $checkrole .= '/'.$sec;
1.474 raeburn 3603: }
1.490 raeburn 3604: if ($otheruser) {
3605: # Resource belongs to user other than current user.
3606: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3607: my ($trole,$tdom,$tnum,$tsec);
3608: my $entry = $live_courses{$course}{$sec};
3609: if ($entry =~ /^cr/) {
3610: ($trole,$tdom,$tnum,$tsec) =
3611: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3612: } else {
3613: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3614: }
3615: my ($spec,$area,$trest,%allroles,%userroles);
3616: $area = '/'.$tdom.'/'.$tnum;
3617: $trest = $tnum;
3618: if ($tsec ne '') {
3619: $area .= '/'.$tsec;
3620: $trest .= '/'.$tsec;
3621: }
3622: $spec = $trole.'.'.$area;
3623: if ($trole =~ /^cr/) {
3624: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3625: $tdom,$spec,$trest,$area);
3626: } else {
3627: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3628: $tdom,$spec,$trest,$area);
3629: }
3630: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3631: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3632: if ($1) {
3633: $no_userblock = 1;
3634: last;
3635: }
3636: }
1.490 raeburn 3637: } else {
3638: # Resource belongs to current user
3639: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3640: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3641: $no_ownblock = 1;
3642: last;
3643: }
1.474 raeburn 3644: }
3645: }
3646: # if they have the evb priv and are currently not playing student
1.482 raeburn 3647: next if (($no_ownblock) &&
1.491 albertel 3648: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3649: next if ($no_userblock);
1.474 raeburn 3650:
1.490 raeburn 3651: # Retrieve blocking times and identity of blocker for course
3652: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3653:
3654: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3655: if (($start != 0) &&
3656: (($startblock == 0) || ($startblock > $start))) {
3657: $startblock = $start;
3658: }
3659: if (($end != 0) &&
3660: (($endblock == 0) || ($endblock < $end))) {
3661: $endblock = $end;
3662: }
1.490 raeburn 3663: }
3664: return ($startblock,$endblock);
3665: }
3666:
3667: sub get_blocks {
3668: my ($setters,$activity,$cdom,$cnum) = @_;
3669: my $startblock = 0;
3670: my $endblock = 0;
3671: my $course = $cdom.'_'.$cnum;
3672: $setters->{$course} = {};
3673: $setters->{$course}{'staff'} = [];
3674: $setters->{$course}{'times'} = [];
3675: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3676: foreach my $record (keys(%records)) {
3677: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3678: if ($start <= time && $end >= time) {
3679: my ($staff_name,$staff_dom,$title,$blocks) =
3680: &parse_block_record($records{$record});
3681: if ($blocks->{$activity} eq 'on') {
3682: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3683: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3684: if ( ($startblock == 0) || ($startblock > $start) ) {
3685: $startblock = $start;
1.490 raeburn 3686: }
1.491 albertel 3687: if ( ($endblock == 0) || ($endblock < $end) ) {
3688: $endblock = $end;
1.474 raeburn 3689: }
3690: }
3691: }
3692: }
3693: return ($startblock,$endblock);
3694: }
3695:
3696: sub parse_block_record {
3697: my ($record) = @_;
3698: my ($setuname,$setudom,$title,$blocks);
3699: if (ref($record) eq 'HASH') {
3700: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3701: $title = &unescape($record->{'event'});
3702: $blocks = $record->{'blocks'};
3703: } else {
3704: my @data = split(/:/,$record,3);
3705: if (scalar(@data) eq 2) {
3706: $title = $data[1];
3707: ($setuname,$setudom) = split(/@/,$data[0]);
3708: } else {
3709: ($setuname,$setudom,$title) = @data;
3710: }
3711: $blocks = { 'com' => 'on' };
3712: }
3713: return ($setuname,$setudom,$title,$blocks);
3714: }
3715:
3716: sub build_block_table {
3717: my ($startblock,$endblock,$setters) = @_;
3718: my %lt = &Apache::lonlocal::texthash(
3719: 'cacb' => 'Currently active communication blocks',
3720: 'cour' => 'Course',
3721: 'dura' => 'Duration',
3722: 'blse' => 'Block set by'
3723: );
3724: my $output;
1.476 raeburn 3725: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3726: $output .= &start_data_table();
3727: $output .= '
3728: <tr>
3729: <th>'.$lt{'cour'}.'</th>
3730: <th>'.$lt{'dura'}.'</th>
3731: <th>'.$lt{'blse'}.'</th>
3732: </tr>
3733: ';
3734: foreach my $course (keys(%{$setters})) {
3735: my %courseinfo=&Apache::lonnet::coursedescription($course);
3736: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3737: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3738: my $fullname = &plainname($uname,$udom);
3739: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3740: && $env{'user.name'} ne 'public'
3741: && $env{'user.domain'} ne 'public') {
3742: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3743: }
1.474 raeburn 3744: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3745: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3746: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3747: $output .= &Apache::loncommon::start_data_table_row().
3748: '<td>'.$courseinfo{'description'}.'</td>'.
3749: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3750: '<td>'.$fullname.'</td>'.
1.474 raeburn 3751: &Apache::loncommon::end_data_table_row();
3752: }
3753: }
3754: $output .= &end_data_table();
3755: }
3756:
1.490 raeburn 3757: sub blocking_status {
3758: my ($activity,$uname,$udom) = @_;
3759: my %setters;
3760: my ($blocked,$output,$ownitem,$is_course);
3761: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3762: if ($startblock && $endblock) {
3763: $blocked = 1;
3764: if (wantarray) {
3765: my $category;
3766: if ($activity eq 'boards') {
3767: $category = 'Discussion posts in this course';
3768: } elsif ($activity eq 'blogs') {
3769: $category = 'Blogs';
3770: } elsif ($activity eq 'port') {
3771: if (defined($uname) && defined($udom)) {
3772: if ($uname eq $env{'user.name'} &&
3773: $udom eq $env{'user.domain'}) {
3774: $ownitem = 1;
3775: }
3776: }
3777: $is_course = &Apache::lonnet::is_course($udom,$uname);
3778: if ($ownitem) {
3779: $category = 'Your portfolio files';
3780: } elsif ($is_course) {
3781: my $coursedesc;
3782: foreach my $course (keys(%setters)) {
3783: my %courseinfo =
3784: &Apache::lonnet::coursedescription($course);
3785: $coursedesc = $courseinfo{'description'};
3786: }
3787: $category = "Group files in the course '$coursedesc'";
3788: } else {
3789: $category = 'Portfolio files belonging to ';
3790: if ($env{'user.name'} eq 'public' &&
3791: $env{'user.domain'} eq 'public') {
3792: $category .= &plainname($uname,$udom);
3793: } else {
3794: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3795: }
3796: }
3797: } elsif ($activity eq 'groups') {
3798: $category = 'Groups in this course';
3799: }
3800: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3801: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3802: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3803: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3804: $output .= &build_block_table($startblock,$endblock,\%setters);
3805: }
3806: }
3807: }
3808: if (wantarray) {
3809: return ($blocked,$output);
3810: } else {
3811: return $blocked;
3812: }
3813: }
3814:
1.60 matthew 3815: ###############################################
3816:
1.682 raeburn 3817: sub check_ip_acc {
3818: my ($acc)=@_;
3819: &Apache::lonxml::debug("acc is $acc");
3820: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3821: return 1;
3822: }
3823: my $allowed=0;
3824: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3825:
3826: my $name;
3827: foreach my $pattern (split(',',$acc)) {
3828: $pattern =~ s/^\s*//;
3829: $pattern =~ s/\s*$//;
3830: if ($pattern =~ /\*$/) {
3831: #35.8.*
3832: $pattern=~s/\*//;
3833: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3834: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3835: #35.8.3.[34-56]
3836: my $low=$2;
3837: my $high=$3;
3838: $pattern=$1;
3839: if ($ip =~ /^\Q$pattern\E/) {
3840: my $last=(split(/\./,$ip))[3];
3841: if ($last <=$high && $last >=$low) { $allowed=1; }
3842: }
3843: } elsif ($pattern =~ /^\*/) {
3844: #*.msu.edu
3845: $pattern=~s/\*//;
3846: if (!defined($name)) {
3847: use Socket;
3848: my $netaddr=inet_aton($ip);
3849: ($name)=gethostbyaddr($netaddr,AF_INET);
3850: }
3851: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3852: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3853: #127.0.0.1
3854: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3855: } else {
3856: #some.name.com
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: }
3864: if ($allowed) { last; }
3865: }
3866: return $allowed;
3867: }
3868:
3869: ###############################################
3870:
1.60 matthew 3871: =pod
3872:
1.112 bowersj2 3873: =head1 Domain Template Functions
3874:
3875: =over 4
3876:
3877: =item * &determinedomain()
1.60 matthew 3878:
3879: Inputs: $domain (usually will be undef)
3880:
1.63 www 3881: Returns: Determines which domain should be used for designs
1.60 matthew 3882:
3883: =cut
1.54 www 3884:
1.60 matthew 3885: ###############################################
1.63 www 3886: sub determinedomain {
3887: my $domain=shift;
1.531 albertel 3888: if (! $domain) {
1.60 matthew 3889: # Determine domain if we have not been given one
3890: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3891: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3892: if ($env{'request.role.domain'}) {
3893: $domain=$env{'request.role.domain'};
1.60 matthew 3894: }
3895: }
1.63 www 3896: return $domain;
3897: }
3898: ###############################################
1.517 raeburn 3899:
1.518 albertel 3900: sub devalidate_domconfig_cache {
3901: my ($udom)=@_;
3902: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3903: }
3904:
3905: # ---------------------- Get domain configuration for a domain
3906: sub get_domainconf {
3907: my ($udom) = @_;
3908: my $cachetime=1800;
3909: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3910: if (defined($cached)) { return %{$result}; }
3911:
3912: my %domconfig = &Apache::lonnet::get_dom('configuration',
3913: ['login','rolecolors'],$udom);
1.632 raeburn 3914: my (%designhash,%legacy);
1.518 albertel 3915: if (keys(%domconfig) > 0) {
3916: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3917: if (keys(%{$domconfig{'login'}})) {
3918: foreach my $key (keys(%{$domconfig{'login'}})) {
1.692.2.2 raeburn 3919: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3920: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3921: $designhash{$udom.'.login.'.$key.'_'.$img} =
3922: $domconfig{'login'}{$key}{$img};
3923: }
3924: } else {
3925: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3926: }
1.632 raeburn 3927: }
3928: } else {
3929: $legacy{'login'} = 1;
1.518 albertel 3930: }
1.632 raeburn 3931: } else {
3932: $legacy{'login'} = 1;
1.518 albertel 3933: }
3934: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3935: if (keys(%{$domconfig{'rolecolors'}})) {
3936: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3937: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3938: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3939: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3940: }
1.518 albertel 3941: }
3942: }
1.632 raeburn 3943: } else {
3944: $legacy{'rolecolors'} = 1;
1.518 albertel 3945: }
1.632 raeburn 3946: } else {
3947: $legacy{'rolecolors'} = 1;
1.518 albertel 3948: }
1.632 raeburn 3949: if (keys(%legacy) > 0) {
3950: my %legacyhash = &get_legacy_domconf($udom);
3951: foreach my $item (keys(%legacyhash)) {
3952: if ($item =~ /^\Q$udom\E\.login/) {
3953: if ($legacy{'login'}) {
3954: $designhash{$item} = $legacyhash{$item};
3955: }
3956: } else {
3957: if ($legacy{'rolecolors'}) {
3958: $designhash{$item} = $legacyhash{$item};
3959: }
1.518 albertel 3960: }
3961: }
3962: }
1.632 raeburn 3963: } else {
3964: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3965: }
3966: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3967: $cachetime);
3968: return %designhash;
3969: }
3970:
1.632 raeburn 3971: sub get_legacy_domconf {
3972: my ($udom) = @_;
3973: my %legacyhash;
3974: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
3975: my $designfile = $designdir.'/'.$udom.'.tab';
3976: if (-e $designfile) {
3977: if ( open (my $fh,"<$designfile") ) {
3978: while (my $line = <$fh>) {
3979: next if ($line =~ /^\#/);
3980: chomp($line);
3981: my ($key,$val)=(split(/\=/,$line));
3982: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
3983: }
3984: close($fh);
3985: }
3986: }
3987: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
3988: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
3989: }
3990: return %legacyhash;
3991: }
3992:
1.63 www 3993: =pod
3994:
1.112 bowersj2 3995: =item * &domainlogo()
1.63 www 3996:
3997: Inputs: $domain (usually will be undef)
3998:
3999: Returns: A link to a domain logo, if the domain logo exists.
4000: If the domain logo does not exist, a description of the domain.
4001:
4002: =cut
1.112 bowersj2 4003:
1.63 www 4004: ###############################################
4005: sub domainlogo {
1.517 raeburn 4006: my $domain = &determinedomain(shift);
1.518 albertel 4007: my %designhash = &get_domainconf($domain);
1.517 raeburn 4008: # See if there is a logo
4009: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4010: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4011: if ($imgsrc =~ m{^/(adm|res)/}) {
4012: if ($imgsrc =~ m{^/res/}) {
4013: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4014: &Apache::lonnet::repcopy($local_name);
4015: }
4016: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4017: }
4018: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4019: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4020: return &Apache::lonnet::domain($domain,'description');
1.59 www 4021: } else {
1.60 matthew 4022: return '';
1.59 www 4023: }
4024: }
1.63 www 4025: ##############################################
4026:
4027: =pod
4028:
1.112 bowersj2 4029: =item * &designparm()
1.63 www 4030:
4031: Inputs: $which parameter; $domain (usually will be undef)
4032:
4033: Returns: value of designparamter $which
4034:
4035: =cut
1.112 bowersj2 4036:
1.397 albertel 4037:
1.400 albertel 4038: ##############################################
1.397 albertel 4039: sub designparm {
4040: my ($which,$domain)=@_;
1.258 albertel 4041: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4042: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4043: return '#000000';
4044: }
1.635 raeburn 4045: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4046: return '#FFFFFF';
4047: }
4048: if ($which=~/\.tabbg$/) {
4049: return '#CCCCCC';
4050: }
4051: }
1.397 albertel 4052: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4053: return $env{'environment.color.'.$which};
1.96 www 4054: }
1.63 www 4055: $domain=&determinedomain($domain);
1.518 albertel 4056: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4057: my $output;
1.517 raeburn 4058: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4059: $output = $domdesign{$domain.'.'.$which};
1.63 www 4060: } else {
1.520 raeburn 4061: $output = $defaultdesign{$which};
4062: }
4063: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4064: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4065: if ($output =~ m{^/(adm|res)/}) {
4066: if ($output =~ m{^/res/}) {
4067: my $local_name = &Apache::lonnet::filelocation('',$output);
4068: &Apache::lonnet::repcopy($local_name);
4069: }
1.520 raeburn 4070: $output = &lonhttpdurl($output);
4071: }
1.63 www 4072: }
1.520 raeburn 4073: return $output;
1.63 www 4074: }
1.59 www 4075:
1.60 matthew 4076: ###############################################
4077: ###############################################
4078:
4079: =pod
4080:
1.112 bowersj2 4081: =back
4082:
1.549 albertel 4083: =head1 HTML Helpers
1.112 bowersj2 4084:
4085: =over 4
4086:
4087: =item * &bodytag()
1.60 matthew 4088:
4089: Returns a uniform header for LON-CAPA web pages.
4090:
4091: Inputs:
4092:
1.112 bowersj2 4093: =over 4
4094:
4095: =item * $title, A title to be displayed on the page.
4096:
4097: =item * $function, the current role (can be undef).
4098:
4099: =item * $addentries, extra parameters for the <body> tag.
4100:
4101: =item * $bodyonly, if defined, only return the <body> tag.
4102:
4103: =item * $domain, if defined, force a given domain.
4104:
4105: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4106: text interface only)
1.60 matthew 4107:
1.326 albertel 4108: =item * $customtitle, alternate text to use instead of $title
4109: in the title box that appears, this text
4110: is not auto translated like the $title is
1.309 albertel 4111:
4112: =item * $notopbar, if true, keep the 'what is this' info but remove the
4113: navigational links
1.317 albertel 4114:
1.338 albertel 4115: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4116:
4117: =item * $notitle, if true keep the nav controls, but remove the title bar
4118:
1.361 albertel 4119: =item * $no_inline_link, if true and in remote mode, don't show the
4120: 'Switch To Inline Menu' link
4121:
1.460 albertel 4122: =item * $args, optional argument valid values are
4123: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4124: inherit_jsmath -> when creating popup window in a page,
4125: should it have jsmath forced on by the
4126: current page
1.460 albertel 4127:
1.112 bowersj2 4128: =back
4129:
1.60 matthew 4130: Returns: A uniform header for LON-CAPA web pages.
4131: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4132: If $bodyonly is undef or zero, an html string containing a <body> tag and
4133: other decorations will be returned.
4134:
4135: =cut
4136:
1.54 www 4137: sub bodytag {
1.309 albertel 4138: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4139: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4140:
1.460 albertel 4141: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4142:
1.183 matthew 4143: $function = &get_users_function() if (!$function);
1.339 albertel 4144: my $img = &designparm($function.'.img',$domain);
4145: my $font = &designparm($function.'.font',$domain);
4146: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4147:
4148: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4149: 'bgcolor' => $pgbg,
1.339 albertel 4150: 'text' => $font,
4151: 'alink' => &designparm($function.'.alink',$domain),
4152: 'vlink' => &designparm($function.'.vlink',$domain),
4153: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4154: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4155:
1.63 www 4156: # role and realm
1.378 raeburn 4157: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4158: if ($role eq 'ca') {
1.479 albertel 4159: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4160: $realm = &plainname($rname,$rdom);
1.378 raeburn 4161: }
1.55 www 4162: # realm
1.258 albertel 4163: if ($env{'request.course.id'}) {
1.378 raeburn 4164: if ($env{'request.role'} !~ /^cr/) {
4165: $role = &Apache::lonnet::plaintext($role,&course_type());
4166: }
1.359 albertel 4167: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4168: } else {
4169: $role = &Apache::lonnet::plaintext($role);
1.54 www 4170: }
1.433 albertel 4171:
1.359 albertel 4172: if (!$realm) { $realm=' '; }
1.55 www 4173: # Set messages
1.60 matthew 4174: my $messages=&domainlogo($domain);
1.330 albertel 4175:
1.438 albertel 4176: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4177:
1.101 www 4178: # construct main body tag
1.359 albertel 4179: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4180: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4181:
1.530 albertel 4182: if ($bodyonly) {
1.60 matthew 4183: return $bodytag;
1.258 albertel 4184: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4185: # Accessibility
1.224 raeburn 4186:
1.337 albertel 4187: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4188: if (!$notitle) {
1.337 albertel 4189: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4190: }
4191: return $bodytag;
1.359 albertel 4192: }
4193:
1.410 albertel 4194: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4195: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4196: undef($role);
1.434 albertel 4197: } else {
4198: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4199: }
1.359 albertel 4200:
4201: my $roleinfo=(<<ENDROLE);
4202: <td class="LC_title_bar_who">
4203: <div class="LC_title_bar_name">
1.410 albertel 4204: $name
1.361 albertel 4205:
1.359 albertel 4206: </div>
4207: <div class="LC_title_bar_role">
1.361 albertel 4208: $role
1.359 albertel 4209: </div>
4210: <div class="LC_title_bar_realm">
1.361 albertel 4211: $realm
1.359 albertel 4212: </div>
1.206 albertel 4213: </td>
4214: ENDROLE
1.235 raeburn 4215:
1.359 albertel 4216: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4217: if ($customtitle) {
4218: $titleinfo = $customtitle;
4219: }
4220: #
4221: # Extra info if you are the DC
4222: my $dc_info = '';
4223: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4224: $env{'course.'.$env{'request.course.id'}.
4225: '.domain'}.'/'})) {
4226: my $cid = $env{'request.course.id'};
4227: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4228: $dc_info =~ s/\s+$//;
1.359 albertel 4229: $dc_info = '('.$dc_info.')';
4230: }
4231:
1.644 www 4232: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4233: # No Remote
1.258 albertel 4234: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4235: $forcereg=1;
4236: }
4237:
4238: if (!$customtitle && $env{'request.state'} eq 'construct') {
4239: # this is for resources; directories have customtitle, and crumbs
4240: # and select recent are created in lonpubdir.pm
1.229 albertel 4241: my ($uname,$thisdisfn)=
1.258 albertel 4242: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4243: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4244: $formaction=~s/\/+/\//g;
4245:
1.359 albertel 4246: my $parentpath = '';
4247: my $lastitem = '';
4248: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4249: $parentpath = $1;
4250: $lastitem = $2;
4251: } else {
4252: $lastitem = $thisdisfn;
4253: }
4254: $titleinfo =
1.640 bisitz 4255: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4256: .'<b>'.&mt('Construction Space').'</b>: '
4257: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4258: .'" target="_top"><tt><b>'
4259: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
4260: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4261: .'</form>'
4262: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4263: }
1.359 albertel 4264:
1.337 albertel 4265: my $titletable;
1.338 albertel 4266: if (!$notitle) {
1.337 albertel 4267: $titletable =
1.359 albertel 4268: '<table id="LC_title_bar">'.
4269: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4270: '</tr></table>';
1.337 albertel 4271: }
1.359 albertel 4272: if ($notopbar) {
4273: $bodytag .= $titletable;
4274: } else {
4275: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4276: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4277: $titletable);
1.272 raeburn 4278: } else {
1.336 albertel 4279: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4280: $titletable;
1.272 raeburn 4281: }
1.235 raeburn 4282: }
4283: return $bodytag;
1.94 www 4284: }
1.95 www 4285:
1.93 www 4286: #
1.95 www 4287: # Top frame rendering, Remote is up
1.93 www 4288: #
1.359 albertel 4289:
1.517 raeburn 4290: my $imgsrc = $img;
4291: if ($img =~ /^\/adm/) {
1.575 albertel 4292: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4293: }
4294: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4295:
1.305 www 4296: # Explicit link to get inline menu
1.361 albertel 4297: my $menu= ($no_inline_link?''
4298: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4299: #
1.338 albertel 4300: if ($notitle) {
1.337 albertel 4301: return $bodytag;
4302: }
1.94 www 4303: return(<<ENDBODY);
1.60 matthew 4304: $bodytag
1.359 albertel 4305: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4306: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4307: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4308: </tr>
1.359 albertel 4309: <tr><td>$titleinfo $dc_info $menu</td>
4310: $roleinfo
1.368 albertel 4311: </tr>
1.356 albertel 4312: </table>
1.54 www 4313: ENDBODY
1.182 matthew 4314: }
4315:
1.330 albertel 4316: sub make_attr_string {
4317: my ($register,$attr_ref) = @_;
4318:
4319: if ($attr_ref && !ref($attr_ref)) {
4320: die("addentries Must be a hash ref ".
4321: join(':',caller(1))." ".
4322: join(':',caller(0))." ");
4323: }
4324:
4325: if ($register) {
1.339 albertel 4326: my ($on_load,$on_unload);
4327: foreach my $key (keys(%{$attr_ref})) {
4328: if (lc($key) eq 'onload') {
4329: $on_load.=$attr_ref->{$key}.';';
4330: delete($attr_ref->{$key});
4331:
4332: } elsif (lc($key) eq 'onunload') {
4333: $on_unload.=$attr_ref->{$key}.';';
4334: delete($attr_ref->{$key});
4335: }
4336: }
4337: $attr_ref->{'onload'} =
4338: &Apache::lonmenu::loadevents(). $on_load;
4339: $attr_ref->{'onunload'}=
4340: &Apache::lonmenu::unloadevents().$on_unload;
4341: }
4342:
4343: # Accessibility font enhance
4344: if ($env{'browser.fontenhance'} eq 'on') {
4345: my $style;
4346: foreach my $key (keys(%{$attr_ref})) {
4347: if (lc($key) eq 'style') {
4348: $style.=$attr_ref->{$key}.';';
4349: delete($attr_ref->{$key});
4350: }
4351: }
4352: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4353: }
1.339 albertel 4354:
4355: if ($env{'browser.blackwhite'} eq 'on') {
4356: delete($attr_ref->{'font'});
4357: delete($attr_ref->{'link'});
4358: delete($attr_ref->{'alink'});
4359: delete($attr_ref->{'vlink'});
4360: delete($attr_ref->{'bgcolor'});
4361: delete($attr_ref->{'background'});
4362: }
4363:
1.330 albertel 4364: my $attr_string;
4365: foreach my $attr (keys(%$attr_ref)) {
4366: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4367: }
4368: return $attr_string;
4369: }
4370:
4371:
1.182 matthew 4372: ###############################################
1.251 albertel 4373: ###############################################
4374:
4375: =pod
4376:
4377: =item * &endbodytag()
4378:
4379: Returns a uniform footer for LON-CAPA web pages.
4380:
1.635 raeburn 4381: Inputs: 1 - optional reference to an args hash
4382: If in the hash, key for noredirectlink has a value which evaluates to true,
4383: a 'Continue' link is not displayed if the page contains an
4384: internal redirect in the <head></head> section,
4385: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4386:
4387: =cut
4388:
4389: sub endbodytag {
1.635 raeburn 4390: my ($args) = @_;
1.251 albertel 4391: my $endbodytag='</body>';
1.269 albertel 4392: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4393: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4394: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4395: $endbodytag=
4396: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4397: &mt('Continue').'</a>'.
4398: $endbodytag;
4399: }
1.315 albertel 4400: }
1.251 albertel 4401: return $endbodytag;
4402: }
4403:
1.352 albertel 4404: =pod
4405:
4406: =item * &standard_css()
4407:
4408: Returns a style sheet
4409:
4410: Inputs: (all optional)
4411: domain -> force to color decorate a page for a specific
4412: domain
4413: function -> force usage of a specific rolish color scheme
4414: bgcolor -> override the default page bgcolor
4415:
4416: =cut
4417:
1.343 albertel 4418: sub standard_css {
1.345 albertel 4419: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4420: $function = &get_users_function() if (!$function);
4421: my $img = &designparm($function.'.img', $domain);
4422: my $tabbg = &designparm($function.'.tabbg', $domain);
4423: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4424: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4425: my $pgbg_or_bgcolor =
4426: $bgcolor ||
1.352 albertel 4427: &designparm($function.'.pgbg', $domain);
1.382 albertel 4428: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4429: my $alink = &designparm($function.'.alink', $domain);
4430: my $vlink = &designparm($function.'.vlink', $domain);
4431: my $link = &designparm($function.'.link', $domain);
4432:
1.602 albertel 4433: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4434: my $mono = 'monospace';
1.352 albertel 4435: my $data_table_head = $tabbg;
4436: my $data_table_light = '#EEEEEE';
1.470 banghart 4437: my $data_table_dark = '#DDDDDD';
4438: my $data_table_darker = '#CCCCCC';
1.349 albertel 4439: my $data_table_highlight = '#FFFF00';
1.352 albertel 4440: my $mail_new = '#FFBB77';
4441: my $mail_new_hover = '#DD9955';
4442: my $mail_read = '#BBBB77';
4443: my $mail_read_hover = '#999944';
4444: my $mail_replied = '#AAAA88';
4445: my $mail_replied_hover = '#888855';
4446: my $mail_other = '#99BBBB';
4447: my $mail_other_hover = '#669999';
1.391 albertel 4448: my $table_header = '#DDDDDD';
1.489 raeburn 4449: my $feedback_link_bg = '#BBBBBB';
1.392 albertel 4450:
1.608 albertel 4451: my $border = ($env{'browser.type'} eq 'explorer' ||
4452: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4453: : '0px 3px 0px 4px';
1.448 albertel 4454:
1.523 albertel 4455:
1.343 albertel 4456: return <<END;
1.345 albertel 4457: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4458: a:focus { color: red; background: yellow }
1.510 albertel 4459: table.thinborder,
1.523 albertel 4460:
1.510 albertel 4461: table.thinborder tr th {
4462: border-style: solid;
4463: border-width: 1px;
4464: background: $tabbg;
4465: }
1.523 albertel 4466: table.thinborder tr td {
1.510 albertel 4467: border-style: solid;
4468: border-width: 1px
4469: }
1.426 albertel 4470:
1.343 albertel 4471: form, .inline { display: inline; }
4472: .center { text-align: center; }
1.593 albertel 4473: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4474: .LC_error {
4475: color: red;
4476: font-size: larger;
4477: }
1.457 albertel 4478: .LC_warning,
4479: .LC_diff_removed {
1.394 albertel 4480: color: red;
4481: }
1.532 albertel 4482:
4483: .LC_info,
1.457 albertel 4484: .LC_success,
4485: .LC_diff_added {
1.350 albertel 4486: color: green;
4487: }
1.543 albertel 4488: .LC_unknown {
4489: color: yellow;
4490: }
4491:
1.440 albertel 4492: .LC_icon {
4493: border: 0px;
4494: }
1.539 albertel 4495: .LC_indexer_icon {
4496: border: 0px;
4497: height: 22px;
4498: }
1.543 albertel 4499: .LC_docs_spacer {
4500: width: 25px;
4501: height: 1px;
4502: border: 0px;
4503: }
1.346 albertel 4504:
1.532 albertel 4505: .LC_internal_info {
4506: color: #999;
4507: }
4508:
1.458 albertel 4509: table.LC_pastsubmission {
4510: border: 1px solid black;
4511: margin: 2px;
4512: }
4513:
1.606 albertel 4514: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4515: width: 100%;
4516: background: $pgbg;
1.392 albertel 4517: border: 2px;
1.402 albertel 4518: border-collapse: separate;
1.403 albertel 4519: padding: 0px;
1.345 albertel 4520: }
1.392 albertel 4521:
1.606 albertel 4522: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4523: table#LC_title_bar.LC_with_remote {
1.359 albertel 4524: width: 100%;
1.392 albertel 4525: border-color: $pgbg;
4526: border-style: solid;
4527: border-width: $border;
4528:
1.379 albertel 4529: background: $pgbg;
4530: font-family: $sans;
1.392 albertel 4531: border-collapse: collapse;
1.403 albertel 4532: padding: 0px;
1.359 albertel 4533: }
1.392 albertel 4534:
1.409 albertel 4535: table.LC_docs_path {
4536: width: 100%;
4537: border: 0;
4538: background: $pgbg;
4539: font-family: $sans;
4540: border-collapse: collapse;
4541: padding: 0px;
4542: }
4543:
1.359 albertel 4544: table#LC_title_bar td {
4545: background: $tabbg;
4546: }
4547: table#LC_title_bar td.LC_title_bar_who {
4548: background: $tabbg;
4549: color: $font;
1.427 albertel 4550: font: small $sans;
1.359 albertel 4551: text-align: right;
4552: }
1.469 banghart 4553: span.LC_metadata {
4554: font-family: $sans;
4555: }
1.359 albertel 4556: span.LC_title_bar_title {
1.416 albertel 4557: font: bold x-large $sans;
1.359 albertel 4558: }
4559: table#LC_title_bar td.LC_title_bar_domain_logo {
4560: background: $sidebg;
4561: text-align: right;
1.368 albertel 4562: padding: 0px;
4563: }
4564: table#LC_title_bar td.LC_title_bar_role_logo {
4565: background: $sidebg;
4566: padding: 0px;
1.359 albertel 4567: }
4568:
1.346 albertel 4569: table#LC_menubuttons_mainmenu {
1.526 www 4570: width: 100%;
1.346 albertel 4571: border: 0px;
4572: border-spacing: 1px;
1.372 albertel 4573: padding: 0px 1px;
1.346 albertel 4574: margin: 0px;
4575: border-collapse: separate;
4576: }
4577: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
4578: border: 0px;
4579: }
1.345 albertel 4580: table#LC_top_nav td {
4581: background: $tabbg;
1.392 albertel 4582: border: 0px;
1.407 albertel 4583: font-size: small;
1.345 albertel 4584: }
4585: table#LC_top_nav td a, div#LC_top_nav a {
4586: color: $font;
4587: font-family: $sans;
4588: }
1.364 albertel 4589: table#LC_top_nav td.LC_top_nav_logo {
4590: background: $tabbg;
1.432 albertel 4591: text-align: left;
1.408 albertel 4592: white-space: nowrap;
1.432 albertel 4593: width: 31px;
1.408 albertel 4594: }
4595: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4596: border: 0px;
1.408 albertel 4597: vertical-align: bottom;
1.364 albertel 4598: }
1.432 albertel 4599: table#LC_top_nav td.LC_top_nav_exit,
4600: table#LC_top_nav td.LC_top_nav_help {
4601: width: 2.0em;
4602: }
1.442 albertel 4603: table#LC_top_nav td.LC_top_nav_login {
4604: width: 4.0em;
4605: text-align: center;
4606: }
1.409 albertel 4607: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4608: background: $tabbg;
4609: color: $font;
4610: font-family: $sans;
1.358 albertel 4611: font-size: smaller;
1.357 albertel 4612: }
1.411 albertel 4613: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4614: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4615: background: $tabbg;
4616: color: $font;
4617: font-family: $sans;
4618: font-size: larger;
4619: text-align: right;
4620: }
1.383 albertel 4621: td.LC_table_cell_checkbox {
4622: text-align: center;
4623: }
1.522 albertel 4624: table#LC_mainmenu td.LC_mainmenu_column {
4625: vertical-align: top;
4626: }
4627:
1.346 albertel 4628: .LC_menubuttons_inline_text {
4629: color: $font;
4630: font-family: $sans;
4631: font-size: smaller;
4632: }
4633:
1.526 www 4634: .LC_menubuttons_link {
4635: text-decoration: none;
4636: }
1.692.2.10 raeburn 4637: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4638: .LC_menubuttons_category {
1.521 www 4639: color: $font;
1.526 www 4640: background: $pgbg;
1.521 www 4641: font-family: $sans;
4642: font-size: larger;
4643: font-weight: bold;
4644: }
4645:
1.346 albertel 4646: td.LC_menubuttons_text {
1.526 www 4647: width: 90%;
1.346 albertel 4648: color: $font;
4649: font-family: $sans;
4650: }
1.526 www 4651:
1.346 albertel 4652: td.LC_menubuttons_img {
4653: }
1.526 www 4654:
1.346 albertel 4655: .LC_current_location {
4656: font-family: $sans;
4657: background: $tabbg;
4658: }
4659: .LC_new_mail {
4660: font-family: $sans;
1.634 www 4661: background: $tabbg;
1.346 albertel 4662: font-weight: bold;
4663: }
1.347 albertel 4664:
1.526 www 4665: .LC_rolesmenu_is {
4666: font-family: $sans;
4667: }
4668:
4669: .LC_rolesmenu_selected {
4670: font-family: $sans;
4671: }
4672:
4673: .LC_rolesmenu_future {
4674: font-family: $sans;
4675: }
4676:
4677:
4678: .LC_rolesmenu_will {
4679: font-family: $sans;
4680: }
4681:
4682: .LC_rolesmenu_will_not {
4683: font-family: $sans;
4684: }
4685:
4686: .LC_rolesmenu_expired {
4687: font-family: $sans;
4688: }
4689:
4690: .LC_rolesinfo {
4691: font-family: $sans;
4692: }
4693:
1.527 www 4694: .LC_dropadd_labeltext {
4695: font-family: $sans;
4696: text-align: right;
4697: }
4698:
4699: .LC_preferences_labeltext {
4700: font-family: $sans;
4701: text-align: right;
4702: }
4703:
1.666 raeburn 4704: .LC_roleslog_note {
4705: font-size: smaller;
4706: }
4707:
1.692.2.4 raeburn 4708: .LC_mail_functions {
4709: font-weight: bold;
4710: }
4711:
1.440 albertel 4712: table.LC_aboutme_port {
4713: border: 0px;
4714: border-collapse: collapse;
4715: border-spacing: 0px;
4716: }
1.349 albertel 4717: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4718: border: 1px solid #000000;
1.402 albertel 4719: border-collapse: separate;
1.426 albertel 4720: border-spacing: 1px;
1.610 albertel 4721: background: $pgbg;
1.347 albertel 4722: }
1.422 albertel 4723: .LC_data_table_dense {
4724: font-size: small;
4725: }
1.507 raeburn 4726: table.LC_nested_outer {
4727: border: 1px solid #000000;
1.589 raeburn 4728: border-collapse: collapse;
1.507 raeburn 4729: border-spacing: 0px;
4730: width: 100%;
4731: }
4732: table.LC_nested {
4733: border: 0px;
1.589 raeburn 4734: border-collapse: collapse;
1.507 raeburn 4735: border-spacing: 0px;
4736: width: 100%;
4737: }
1.523 albertel 4738: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4739: table.LC_prior_tries tr th {
1.349 albertel 4740: font-weight: bold;
4741: background-color: $data_table_head;
1.421 albertel 4742: font-size: smaller;
1.347 albertel 4743: }
1.692.2.3 raeburn 4744: table.LC_data_table tr.LC_info_row > td {
4745: background-color: #CCC;
4746: font-weight: bold;
4747: text-align: left;
4748: }
1.610 albertel 4749: table.LC_data_table tr.LC_odd_row > td,
1.440 albertel 4750: table.LC_aboutme_port tr td {
1.349 albertel 4751: background-color: $data_table_light;
1.425 albertel 4752: padding: 2px;
1.347 albertel 4753: }
1.610 albertel 4754: table.LC_data_table tr.LC_even_row > td,
1.440 albertel 4755: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4756: background-color: $data_table_dark;
1.347 albertel 4757: }
1.425 albertel 4758: table.LC_data_table tr.LC_data_table_highlight td {
4759: background-color: $data_table_darker;
4760: }
1.639 raeburn 4761: table.LC_data_table tr td.LC_leftcol_header {
4762: background-color: $data_table_head;
4763: font-weight: bold;
4764: }
1.451 albertel 4765: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4766: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4767: background-color: #FFFFFF;
1.421 albertel 4768: font-weight: bold;
4769: font-style: italic;
4770: text-align: center;
4771: padding: 8px;
1.347 albertel 4772: }
1.507 raeburn 4773: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4774: padding: 4ex
4775: }
1.507 raeburn 4776: table.LC_nested_outer tr th {
4777: font-weight: bold;
4778: background-color: $data_table_head;
4779: font-size: smaller;
4780: border-bottom: 1px solid #000000;
4781: }
4782: table.LC_nested_outer tr td.LC_subheader {
4783: background-color: $data_table_head;
4784: font-weight: bold;
4785: font-size: small;
4786: border-bottom: 1px solid #000000;
4787: text-align: right;
1.451 albertel 4788: }
1.507 raeburn 4789: table.LC_nested tr.LC_info_row td {
1.451 albertel 4790: background-color: #CCC;
4791: font-weight: bold;
4792: font-size: small;
1.507 raeburn 4793: text-align: center;
4794: }
1.589 raeburn 4795: table.LC_nested tr.LC_info_row td.LC_left_item,
4796: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4797: text-align: left;
1.451 albertel 4798: }
1.507 raeburn 4799: table.LC_nested td {
1.451 albertel 4800: background-color: #FFF;
4801: font-size: small;
1.507 raeburn 4802: }
4803: table.LC_nested_outer tr th.LC_right_item,
4804: table.LC_nested tr.LC_info_row td.LC_right_item,
4805: table.LC_nested tr.LC_odd_row td.LC_right_item,
4806: table.LC_nested tr td.LC_right_item {
1.451 albertel 4807: text-align: right;
4808: }
4809:
1.507 raeburn 4810: table.LC_nested tr.LC_odd_row td {
1.451 albertel 4811: background-color: #EEE;
4812: }
4813:
1.473 raeburn 4814: table.LC_createuser {
4815: }
4816:
4817: table.LC_createuser tr.LC_section_row td {
4818: font-size: smaller;
4819: }
4820:
4821: table.LC_createuser tr.LC_info_row td {
4822: background-color: #CCC;
4823: font-weight: bold;
4824: text-align: center;
4825: }
4826:
1.349 albertel 4827: table.LC_calendar {
4828: border: 1px solid #000000;
4829: border-collapse: collapse;
4830: }
4831: table.LC_calendar_pickdate {
4832: font-size: xx-small;
4833: }
4834: table.LC_calendar tr td {
4835: border: 1px solid #000000;
4836: vertical-align: top;
4837: }
4838: table.LC_calendar tr td.LC_calendar_day_empty {
4839: background-color: $data_table_dark;
4840: }
4841: table.LC_calendar tr td.LC_calendar_day_current {
4842: background-color: $data_table_highlight;
4843: }
4844:
4845: table.LC_mail_list tr.LC_mail_new {
4846: background-color: $mail_new;
4847: }
4848: table.LC_mail_list tr.LC_mail_new:hover {
4849: background-color: $mail_new_hover;
4850: }
4851: table.LC_mail_list tr.LC_mail_read {
4852: background-color: $mail_read;
4853: }
4854: table.LC_mail_list tr.LC_mail_read:hover {
4855: background-color: $mail_read_hover;
4856: }
4857: table.LC_mail_list tr.LC_mail_replied {
4858: background-color: $mail_replied;
4859: }
4860: table.LC_mail_list tr.LC_mail_replied:hover {
4861: background-color: $mail_replied_hover;
4862: }
4863: table.LC_mail_list tr.LC_mail_other {
4864: background-color: $mail_other;
4865: }
4866: table.LC_mail_list tr.LC_mail_other:hover {
4867: background-color: $mail_other_hover;
4868: }
1.494 raeburn 4869: table.LC_mail_list tr.LC_mail_even {
4870: }
4871: table.LC_mail_list tr.LC_mail_odd {
4872: }
4873:
1.385 albertel 4874:
1.386 albertel 4875: table#LC_portfolio_actions {
4876: width: auto;
4877: background: $pgbg;
4878: border: 0px;
4879: border-spacing: 2px 2px;
4880: padding: 0px;
4881: margin: 0px;
4882: border-collapse: separate;
4883: }
4884: table#LC_portfolio_actions td.LC_label {
4885: background: $tabbg;
4886: text-align: right;
4887: }
4888: table#LC_portfolio_actions td.LC_value {
4889: background: $tabbg;
4890: }
1.385 albertel 4891:
1.391 albertel 4892: table#LC_cstr_controls {
4893: width: 100%;
4894: border-collapse: collapse;
4895: }
4896: table#LC_cstr_controls tr td {
4897: border: 4px solid $pgbg;
4898: padding: 4px;
4899: text-align: center;
4900: background: $tabbg;
4901: }
4902: table#LC_cstr_controls tr th {
4903: border: 4px solid $pgbg;
4904: background: $table_header;
4905: text-align: center;
4906: font-family: $sans;
4907: font-size: smaller;
4908: }
4909:
1.389 albertel 4910: table#LC_browser {
4911:
4912: }
4913: table#LC_browser tr th {
1.391 albertel 4914: background: $table_header;
1.389 albertel 4915: }
1.390 albertel 4916: table#LC_browser tr td {
4917: padding: 2px;
4918: }
1.389 albertel 4919: table#LC_browser tr.LC_browser_file,
4920: table#LC_browser tr.LC_browser_file_published {
4921: background: #CCFF88;
4922: }
4923: table#LC_browser tr.LC_browser_file_locked,
4924: table#LC_browser tr.LC_browser_file_unpublished {
4925: background: #FFAA99;
1.387 albertel 4926: }
1.389 albertel 4927: table#LC_browser tr.LC_browser_file_obsolete {
4928: background: #AAAAAA;
1.387 albertel 4929: }
1.455 albertel 4930: table#LC_browser tr.LC_browser_file_modified,
4931: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 4932: background: #FFFF77;
1.387 albertel 4933: }
1.389 albertel 4934: table#LC_browser tr.LC_browser_folder {
4935: background: #CCCCFF;
1.387 albertel 4936: }
1.388 albertel 4937: span.LC_current_location {
4938: font-size: x-large;
4939: background: $pgbg;
4940: }
1.387 albertel 4941:
1.395 albertel 4942: span.LC_parm_menu_item {
4943: font-size: larger;
4944: font-family: $sans;
4945: }
4946: span.LC_parm_scope_all {
4947: color: red;
4948: }
4949: span.LC_parm_scope_folder {
4950: color: green;
4951: }
4952: span.LC_parm_scope_resource {
4953: color: orange;
4954: }
4955: span.LC_parm_part {
4956: color: blue;
4957: }
4958: span.LC_parm_folder, span.LC_parm_symb {
4959: font-size: x-small;
4960: font-family: $mono;
4961: color: #AAAAAA;
4962: }
4963:
1.396 albertel 4964: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4965: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4966: border: 1px solid black;
4967: border-collapse: collapse;
4968: }
4969: table.LC_parm_overview_restrictions td {
4970: border-width: 1px 4px 1px 4px;
4971: border-style: solid;
4972: border-color: $pgbg;
4973: text-align: center;
4974: }
4975: table.LC_parm_overview_restrictions th {
4976: background: $tabbg;
4977: border-width: 1px 4px 1px 4px;
4978: border-style: solid;
4979: border-color: $pgbg;
4980: }
1.398 albertel 4981: table#LC_helpmenu {
4982: border: 0px;
4983: height: 55px;
4984: border-spacing: 0px;
4985: }
4986:
4987: table#LC_helpmenu fieldset legend {
4988: font-size: larger;
4989: font-weight: bold;
4990: }
1.397 albertel 4991: table#LC_helpmenu_links {
4992: width: 100%;
4993: border: 1px solid black;
4994: background: $pgbg;
4995: padding: 0px;
4996: border-spacing: 1px;
4997: }
4998: table#LC_helpmenu_links tr td {
4999: padding: 1px;
5000: background: $tabbg;
1.399 albertel 5001: text-align: center;
5002: font-weight: bold;
1.397 albertel 5003: }
1.396 albertel 5004:
1.397 albertel 5005: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5006: table#LC_helpmenu_links a:active {
5007: text-decoration: none;
5008: color: $font;
5009: }
5010: table#LC_helpmenu_links a:hover {
5011: text-decoration: underline;
5012: color: $vlink;
5013: }
1.396 albertel 5014:
1.417 albertel 5015: .LC_chrt_popup_exists {
5016: border: 1px solid #339933;
5017: margin: -1px;
5018: }
5019: .LC_chrt_popup_up {
5020: border: 1px solid yellow;
5021: margin: -1px;
5022: }
5023: .LC_chrt_popup {
5024: border: 1px solid #8888FF;
5025: background: #CCCCFF;
5026: }
1.421 albertel 5027: table.LC_pick_box {
5028: border-collapse: separate;
5029: background: white;
5030: border: 1px solid black;
5031: border-spacing: 1px;
5032: }
5033: table.LC_pick_box td.LC_pick_box_title {
5034: background: $tabbg;
5035: font-weight: bold;
5036: text-align: right;
5037: width: 184px;
5038: padding: 8px;
5039: }
1.645 raeburn 5040: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5041: background: $tabbg;
5042: font-weight: bold;
5043: text-align: right;
5044: width: 350px;
5045: padding: 8px;
5046: }
5047:
1.579 raeburn 5048: table.LC_pick_box td.LC_pick_box_value {
5049: text-align: left;
5050: padding: 8px;
5051: }
5052: table.LC_pick_box td.LC_pick_box_select {
5053: text-align: left;
5054: padding: 8px;
5055: }
1.424 albertel 5056: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5057: padding: 0px;
5058: height: 1px;
5059: background: black;
5060: }
5061: table.LC_pick_box td.LC_pick_box_submit {
5062: text-align: right;
5063: }
1.579 raeburn 5064: table.LC_pick_box td.LC_evenrow_value {
5065: text-align: left;
5066: padding: 8px;
5067: background-color: $data_table_light;
5068: }
5069: table.LC_pick_box td.LC_oddrow_value {
5070: text-align: left;
5071: padding: 8px;
5072: background-color: $data_table_light;
5073: }
5074: table.LC_helpform_receipt {
5075: width: 620px;
5076: border-collapse: separate;
5077: background: white;
5078: border: 1px solid black;
5079: border-spacing: 1px;
5080: }
5081: table.LC_helpform_receipt td.LC_pick_box_title {
5082: background: $tabbg;
5083: font-weight: bold;
5084: text-align: right;
5085: width: 184px;
5086: padding: 8px;
5087: }
5088: table.LC_helpform_receipt td.LC_evenrow_value {
5089: text-align: left;
5090: padding: 8px;
5091: background-color: $data_table_light;
5092: }
5093: table.LC_helpform_receipt td.LC_oddrow_value {
5094: text-align: left;
5095: padding: 8px;
5096: background-color: $data_table_light;
5097: }
5098: table.LC_helpform_receipt td.LC_pick_box_separator {
5099: padding: 0px;
5100: height: 1px;
5101: background: black;
5102: }
5103: span.LC_helpform_receipt_cat {
5104: font-weight: bold;
5105: }
1.424 albertel 5106: table.LC_group_priv_box {
5107: background: white;
5108: border: 1px solid black;
5109: border-spacing: 1px;
5110: }
5111: table.LC_group_priv_box td.LC_pick_box_title {
5112: background: $tabbg;
5113: font-weight: bold;
5114: text-align: right;
5115: width: 184px;
5116: }
5117: table.LC_group_priv_box td.LC_groups_fixed {
5118: background: $data_table_light;
5119: text-align: center;
5120: }
5121: table.LC_group_priv_box td.LC_groups_optional {
5122: background: $data_table_dark;
5123: text-align: center;
5124: }
5125: table.LC_group_priv_box td.LC_groups_functionality {
5126: background: $data_table_darker;
5127: text-align: center;
5128: font-weight: bold;
5129: }
5130: table.LC_group_priv td {
5131: text-align: left;
5132: padding: 0px;
5133: }
5134:
1.421 albertel 5135: table.LC_notify_front_page {
5136: background: white;
5137: border: 1px solid black;
5138: padding: 8px;
5139: }
5140: table.LC_notify_front_page td {
5141: padding: 8px;
5142: }
1.424 albertel 5143: .LC_navbuttons {
5144: margin: 2ex 0ex 2ex 0ex;
5145: }
1.423 albertel 5146: .LC_topic_bar {
5147: font-family: $sans;
5148: font-weight: bold;
5149: width: 100%;
5150: background: $tabbg;
5151: vertical-align: middle;
5152: margin: 2ex 0ex 2ex 0ex;
5153: }
5154: .LC_topic_bar span {
5155: vertical-align: middle;
5156: }
5157: .LC_topic_bar img {
5158: vertical-align: bottom;
5159: }
5160: table.LC_course_group_status {
5161: margin: 20px;
5162: }
5163: table.LC_status_selector td {
5164: vertical-align: top;
5165: text-align: center;
1.424 albertel 5166: padding: 4px;
5167: }
5168: table.LC_descriptive_input td.LC_description {
5169: vertical-align: top;
5170: text-align: right;
5171: font-weight: bold;
1.423 albertel 5172: }
1.599 albertel 5173: div.LC_feedback_link {
1.616 albertel 5174: clear: both;
1.599 albertel 5175: background: white;
5176: width: 100%;
1.489 raeburn 5177: }
5178: span.LC_feedback_link {
1.599 albertel 5179: background: $feedback_link_bg;
5180: font-size: larger;
5181: }
5182: span.LC_message_link {
5183: background: $feedback_link_bg;
5184: font-size: larger;
5185: position: absolute;
5186: right: 1em;
1.489 raeburn 5187: }
1.421 albertel 5188:
1.515 albertel 5189: table.LC_prior_tries {
1.524 albertel 5190: border: 1px solid #000000;
5191: border-collapse: separate;
5192: border-spacing: 1px;
1.515 albertel 5193: }
1.523 albertel 5194:
1.515 albertel 5195: table.LC_prior_tries td {
1.524 albertel 5196: padding: 2px;
1.515 albertel 5197: }
1.523 albertel 5198:
5199: .LC_answer_correct {
5200: background: #AAFFAA;
5201: color: black;
5202: }
5203: .LC_answer_charged_try {
5204: background: #FFAAAA ! important;
5205: color: black;
5206: }
5207: .LC_answer_not_charged_try,
5208: .LC_answer_no_grade,
5209: .LC_answer_late {
5210: background: #FFFFAA;
5211: color: black;
5212: }
5213: .LC_answer_previous {
5214: background: #AAAAFF;
5215: color: black;
5216: }
5217: .LC_answer_no_message {
5218: background: #FFFFFF;
5219: color: black;
5220: }
5221: .LC_answer_unknown {
5222: background: orange;
5223: color: black;
5224: }
5225:
5226:
1.529 albertel 5227: span.LC_prior_numerical,
5228: span.LC_prior_string,
5229: span.LC_prior_custom,
5230: span.LC_prior_reaction,
5231: span.LC_prior_math {
1.523 albertel 5232: font-family: monospace;
5233: white-space: pre;
5234: }
5235:
1.525 albertel 5236: span.LC_prior_string {
5237: font-family: monospace;
5238: white-space: pre;
5239: }
5240:
1.523 albertel 5241: table.LC_prior_option {
5242: width: 100%;
5243: border-collapse: collapse;
5244: }
1.528 albertel 5245: table.LC_prior_rank, table.LC_prior_match {
5246: border-collapse: collapse;
5247: }
5248: table.LC_prior_option tr td,
5249: table.LC_prior_rank tr td,
5250: table.LC_prior_match tr td {
1.524 albertel 5251: border: 1px solid #000000;
1.515 albertel 5252: }
5253:
1.519 raeburn 5254: span.LC_nobreak {
1.544 albertel 5255: white-space: nowrap;
1.519 raeburn 5256: }
5257:
1.576 raeburn 5258: span.LC_cusr_emph {
5259: font-style: italic;
5260: }
5261:
1.633 raeburn 5262: span.LC_cusr_subheading {
5263: font-weight: normal;
5264: font-size: 85%;
5265: }
5266:
1.545 albertel 5267: table.LC_docs_documents {
5268: background: #BBBBBB;
1.547 albertel 5269: border-width: 0px;
1.545 albertel 5270: border-collapse: collapse;
5271: }
5272:
5273: table.LC_docs_documents td.LC_docs_document {
5274: border: 2px solid black;
5275: padding: 4px;
5276: }
5277:
5278: .LC_docs_course_commands div {
5279: float: left;
5280: border: 4px solid #AAAAAA;
5281: padding: 4px;
5282: background: #DDDDCC;
5283: }
5284:
5285: .LC_docs_entry_move {
5286: border: 0px;
5287: border-collapse: collapse;
1.544 albertel 5288: }
5289:
1.545 albertel 5290: .LC_docs_entry_move td {
5291: border: 2px solid #BBBBBB;
5292: background: #DDDDDD;
5293: }
5294:
5295: .LC_docs_editor td.LC_docs_entry_commands {
5296: background: #DDDDDD;
5297: font-size: x-small;
5298: }
1.544 albertel 5299: .LC_docs_copy {
1.545 albertel 5300: color: #000099;
1.544 albertel 5301: }
5302: .LC_docs_cut {
1.545 albertel 5303: color: #550044;
1.544 albertel 5304: }
5305: .LC_docs_rename {
1.545 albertel 5306: color: #009900;
1.544 albertel 5307: }
5308: .LC_docs_remove {
1.545 albertel 5309: color: #990000;
5310: }
5311:
1.547 albertel 5312: .LC_docs_reinit_warn,
5313: .LC_docs_ext_edit {
5314: font-size: x-small;
5315: }
5316:
1.545 albertel 5317: .LC_docs_editor td.LC_docs_entry_title,
5318: .LC_docs_editor td.LC_docs_entry_icon {
5319: background: #FFFFBB;
5320: }
5321: .LC_docs_editor td.LC_docs_entry_parameter {
5322: background: #BBBBFF;
5323: font-size: x-small;
5324: white-space: nowrap;
5325: }
5326:
5327: table.LC_docs_adddocs td,
5328: table.LC_docs_adddocs th {
5329: border: 1px solid #BBBBBB;
5330: padding: 4px;
5331: background: #DDDDDD;
1.543 albertel 5332: }
5333:
1.584 albertel 5334: table.LC_sty_begin {
5335: background: #BBFFBB;
5336: }
5337: table.LC_sty_end {
5338: background: #FFBBBB;
5339: }
5340:
1.589 raeburn 5341: table.LC_double_column {
5342: border-width: 0px;
5343: border-collapse: collapse;
5344: width: 100%;
5345: padding: 2px;
5346: }
5347:
5348: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5349: top: 2px;
1.589 raeburn 5350: left: 2px;
5351: width: 47%;
5352: vertical-align: top;
5353: }
5354:
5355: table.LC_double_column tr td.LC_right_col {
5356: top: 2px;
5357: right: 2px;
5358: width: 47%;
5359: vertical-align: top;
5360: }
5361:
1.594 raeburn 5362: span.LC_role_level {
5363: font-weight: bold;
5364: }
5365:
1.591 raeburn 5366: div.LC_left_float {
5367: float: left;
5368: padding-right: 5%;
1.597 albertel 5369: padding-bottom: 4px;
1.591 raeburn 5370: }
5371:
5372: div.LC_clear_float_header {
1.597 albertel 5373: padding-bottom: 2px;
1.591 raeburn 5374: }
5375:
5376: div.LC_clear_float_footer {
1.597 albertel 5377: padding-top: 10px;
1.591 raeburn 5378: clear: both;
5379: }
5380:
1.597 albertel 5381:
1.601 albertel 5382: div.LC_grade_select_mode {
1.604 albertel 5383: font-family: $sans;
1.601 albertel 5384: }
5385: div.LC_grade_select_mode div div {
5386: margin: 5px;
5387: }
5388: div.LC_grade_select_mode_selector {
5389: margin: 5px;
5390: float: left;
5391: }
5392: div.LC_grade_select_mode_selector_header {
5393: font: bold medium $sans;
5394: }
5395: div.LC_grade_select_mode_type {
5396: clear: left;
5397: }
5398:
1.597 albertel 5399: div.LC_grade_show_user {
5400: margin-top: 20px;
5401: border: 1px solid black;
5402: }
5403: div.LC_grade_user_name {
5404: background: #DDDDEE;
5405: border-bottom: 1px solid black;
5406: font: bold large $sans;
5407: }
5408: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5409: background: #DDEEDD;
5410: }
5411:
5412: div.LC_grade_show_problem,
5413: div.LC_grade_submissions,
5414: div.LC_grade_message_center,
5415: div.LC_grade_info_links,
5416: div.LC_grade_assign {
5417: margin: 5px;
5418: width: 99%;
5419: background: #FFFFFF;
5420: }
5421: div.LC_grade_show_problem_header,
5422: div.LC_grade_submissions_header,
5423: div.LC_grade_message_center_header,
5424: div.LC_grade_assign_header {
5425: font: bold large $sans;
5426: }
5427: div.LC_grade_show_problem_problem,
5428: div.LC_grade_submissions_body,
5429: div.LC_grade_message_center_body,
5430: div.LC_grade_assign_body {
5431: border: 1px solid black;
5432: width: 99%;
5433: background: #FFFFFF;
5434: }
1.598 albertel 5435: span.LC_grade_check_note {
5436: font: normal medium $sans;
5437: display: inline;
5438: position: absolute;
5439: right: 1em;
5440: }
1.597 albertel 5441:
1.613 albertel 5442: table.LC_scantron_action {
5443: width: 100%;
5444: }
5445: table.LC_scantron_action tr th {
5446: font: normal bold $sans;
5447: }
1.600 albertel 5448:
1.614 albertel 5449: div.LC_edit_problem_header,
5450: div.LC_edit_problem_footer {
1.600 albertel 5451: font: normal medium $sans;
1.602 albertel 5452: margin: 2px;
1.600 albertel 5453: }
5454: div.LC_edit_problem_header,
1.602 albertel 5455: div.LC_edit_problem_header div,
1.614 albertel 5456: div.LC_edit_problem_footer,
5457: div.LC_edit_problem_footer div,
1.602 albertel 5458: div.LC_edit_problem_editxml_header,
5459: div.LC_edit_problem_editxml_header div {
1.600 albertel 5460: margin-top: 5px;
5461: }
1.602 albertel 5462: div.LC_edit_problem_header_edit_row {
5463: background: $tabbg;
5464: padding: 3px;
5465: margin-bottom: 5px;
5466: }
1.600 albertel 5467: div.LC_edit_problem_header_title {
1.602 albertel 5468: font: larger bold $sans;
5469: background: $tabbg;
5470: padding: 3px;
5471: }
5472: table.LC_edit_problem_header_title {
5473: font: larger bold $sans;
5474: width: 100%;
5475: border-color: $pgbg;
5476: border-style: solid;
5477: border-width: $border;
5478:
1.600 albertel 5479: background: $tabbg;
1.602 albertel 5480: border-collapse: collapse;
5481: padding: 0px
5482: }
5483:
5484: div.LC_edit_problem_discards {
5485: float: left;
5486: padding-bottom: 5px;
5487: }
5488: div.LC_edit_problem_saves {
5489: float: right;
5490: padding-bottom: 5px;
1.600 albertel 5491: }
5492: hr.LC_edit_problem_divide {
1.602 albertel 5493: clear: both;
1.600 albertel 5494: color: $tabbg;
5495: background-color: $tabbg;
5496: height: 3px;
5497: border: 0px;
5498: }
1.679 riegler 5499: img.stift{
1.678 riegler 5500: border-width:0;
1.679 riegler 5501: vertical-align:middle;
1.677 riegler 5502: }
1.680 riegler 5503:
1.681 riegler 5504: table#LC_mainmenu{
5505: margin-top:10px;
5506: width:80%;
5507:
5508: }
5509:
1.680 riegler 5510: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5511: vertical-align: top;
5512: width: 45%;
5513: }
5514: .LC_mainmenu_fieldset_category {
5515: color: $font;
5516: background: $pgbg;
5517: font-family: $sans;
5518: font-size: small;
5519: font-weight: bold;
5520: }
5521: fieldset#LC_mainmenu_fieldset {
1.681 riegler 5522: margin:0px 10px 10px 0px;
1.680 riegler 5523:
5524: }
1.692.2.5 raeburn 5525:
5526: div.LC_createcourse {
5527: margin: 10px 10px 10px 10px;
5528: }
5529:
1.343 albertel 5530: END
5531: }
5532:
1.306 albertel 5533: =pod
5534:
5535: =item * &headtag()
5536:
5537: Returns a uniform footer for LON-CAPA web pages.
5538:
1.307 albertel 5539: Inputs: $title - optional title for the head
5540: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5541: $args - optional arguments
1.319 albertel 5542: force_register - if is true call registerurl so the remote is
5543: informed
1.415 albertel 5544: redirect -> array ref of
5545: 1- seconds before redirect occurs
5546: 2- url to redirect to
5547: 3- whether the side effect should occur
1.315 albertel 5548: (side effect of setting
5549: $env{'internal.head.redirect'} to the url
5550: redirected too)
1.352 albertel 5551: domain -> force to color decorate a page for a specific
5552: domain
5553: function -> force usage of a specific rolish color scheme
5554: bgcolor -> override the default page bgcolor
1.460 albertel 5555: no_auto_mt_title
5556: -> prevent &mt()ing the title arg
1.464 albertel 5557:
1.306 albertel 5558: =cut
5559:
5560: sub headtag {
1.313 albertel 5561: my ($title,$head_extra,$args) = @_;
1.306 albertel 5562:
1.363 albertel 5563: my $function = $args->{'function'} || &get_users_function();
5564: my $domain = $args->{'domain'} || &determinedomain();
5565: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5566: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5567: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5568: #time(),
1.418 albertel 5569: $env{'environment.color.timestamp'},
1.363 albertel 5570: $function,$domain,$bgcolor);
5571:
1.369 www 5572: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5573:
1.308 albertel 5574: my $result =
5575: '<head>'.
1.461 albertel 5576: &font_settings();
1.319 albertel 5577:
1.461 albertel 5578: if (!$args->{'frameset'}) {
5579: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5580: }
1.319 albertel 5581: if ($args->{'force_register'}) {
5582: $result .= &Apache::lonmenu::registerurl(1);
5583: }
1.436 albertel 5584: if (!$args->{'no_nav_bar'}
5585: && !$args->{'only_body'}
5586: && !$args->{'frameset'}) {
5587: $result .= &help_menu_js();
5588: }
1.319 albertel 5589:
1.314 albertel 5590: if (ref($args->{'redirect'})) {
1.414 albertel 5591: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5592: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5593: if (!$inhibit_continue) {
5594: $env{'internal.head.redirect'} = $url;
5595: }
1.313 albertel 5596: $result.=<<ADDMETA
5597: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5598: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5599: ADDMETA
5600: }
1.306 albertel 5601: if (!defined($title)) {
5602: $title = 'The LearningOnline Network with CAPA';
5603: }
1.460 albertel 5604: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5605: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5606: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5607: .$head_extra;
1.306 albertel 5608: return $result;
5609: }
5610:
5611: =pod
5612:
1.340 albertel 5613: =item * &font_settings()
5614:
5615: Returns neccessary <meta> to set the proper encoding
5616:
5617: Inputs: none
5618:
5619: =cut
5620:
5621: sub font_settings {
5622: my $headerstring='';
1.647 www 5623: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5624: $headerstring.=
5625: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5626: }
5627: return $headerstring;
5628: }
5629:
1.341 albertel 5630: =pod
5631:
5632: =item * &xml_begin()
5633:
5634: Returns the needed doctype and <html>
5635:
5636: Inputs: none
5637:
5638: =cut
5639:
5640: sub xml_begin {
5641: my $output='';
5642:
1.592 albertel 5643: if ($env{'internal.start_page'}==1) {
5644: &Apache::lonhtmlcommon::init_htmlareafields();
5645: }
1.342 albertel 5646:
1.341 albertel 5647: if ($env{'browser.mathml'}) {
5648: $output='<?xml version="1.0"?>'
5649: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5650: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5651:
5652: # .'<!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">] >'
5653: .'<!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">'
5654: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5655: .'xmlns="http://www.w3.org/1999/xhtml">';
5656: } else {
5657: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5658: }
5659: return $output;
5660: }
1.340 albertel 5661:
5662: =pod
5663:
1.306 albertel 5664: =item * &endheadtag()
5665:
5666: Returns a uniform </head> for LON-CAPA web pages.
5667:
5668: Inputs: none
5669:
5670: =cut
5671:
5672: sub endheadtag {
5673: return '</head>';
5674: }
5675:
5676: =pod
5677:
5678: =item * &head()
5679:
5680: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5681:
1.648 raeburn 5682: Inputs:
5683:
5684: =over 4
5685:
5686: $title - optional title for the page
5687:
5688: $head_extra - optional extra HTML to put inside the <head>
5689:
5690: =back
1.405 albertel 5691:
1.306 albertel 5692: =cut
5693:
5694: sub head {
1.325 albertel 5695: my ($title,$head_extra,$args) = @_;
5696: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 5697: }
5698:
5699: =pod
5700:
5701: =item * &start_page()
5702:
5703: Returns a complete <html> .. <body> section for LON-CAPA web pages.
5704:
1.648 raeburn 5705: Inputs:
5706:
5707: =over 4
5708:
5709: $title - optional title for the page
5710:
5711: $head_extra - optional extra HTML to incude inside the <head>
5712:
5713: $args - additional optional args supported are:
5714:
5715: =over 8
5716:
5717: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 5718: arg on
1.648 raeburn 5719: no_nav_bar -> is true will set &bodytag() notopbar arg on
5720: add_entries -> additional attributes to add to the <body>
5721: domain -> force to color decorate a page for a
1.317 albertel 5722: specific domain
1.648 raeburn 5723: function -> force usage of a specific rolish color
1.317 albertel 5724: scheme
1.648 raeburn 5725: redirect -> see &headtag()
5726: bgcolor -> override the default page bg color
5727: js_ready -> return a string ready for being used in
1.317 albertel 5728: a javascript writeln
1.648 raeburn 5729: html_encode -> return a string ready for being used in
1.320 albertel 5730: a html attribute
1.648 raeburn 5731: force_register -> if is true will turn on the &bodytag()
1.317 albertel 5732: $forcereg arg
1.648 raeburn 5733: body_title -> alternate text to use instead of $title
1.326 albertel 5734: in the title box that appears, this text
5735: is not auto translated like the $title is
1.648 raeburn 5736: frameset -> if true will start with a <frameset>
1.330 albertel 5737: rather than <body>
1.648 raeburn 5738: no_title -> if true the title bar won't be shown
5739: skip_phases -> hash ref of
1.338 albertel 5740: head -> skip the <html><head> generation
5741: body -> skip all <body> generation
1.648 raeburn 5742: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 5743: 'Switch To Inline Menu' link
1.648 raeburn 5744: no_auto_mt_title -> prevent &mt()ing the title arg
5745: inherit_jsmath -> when creating popup window in a page,
5746: should it have jsmath forced on by the
5747: current page
1.361 albertel 5748:
1.648 raeburn 5749: =back
1.460 albertel 5750:
1.648 raeburn 5751: =back
1.562 albertel 5752:
1.306 albertel 5753: =cut
5754:
5755: sub start_page {
1.309 albertel 5756: my ($title,$head_extra,$args) = @_;
1.318 albertel 5757: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 5758: my %head_args;
1.352 albertel 5759: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 5760: 'bgcolor','frameset','no_nav_bar','only_body',
5761: 'no_auto_mt_title') {
1.319 albertel 5762: if (defined($args->{$arg})) {
1.324 raeburn 5763: $head_args{$arg} = $args->{$arg};
1.319 albertel 5764: }
1.313 albertel 5765: }
1.319 albertel 5766:
1.315 albertel 5767: $env{'internal.start_page'}++;
1.338 albertel 5768: my $result;
5769: if (! exists($args->{'skip_phases'}{'head'}) ) {
5770: $result.=
1.341 albertel 5771: &xml_begin().
1.338 albertel 5772: &headtag($title,$head_extra,\%head_args).&endheadtag();
5773: }
5774:
5775: if (! exists($args->{'skip_phases'}{'body'}) ) {
5776: if ($args->{'frameset'}) {
5777: my $attr_string = &make_attr_string($args->{'force_register'},
5778: $args->{'add_entries'});
5779: $result .= "\n<frameset $attr_string>\n";
5780: } else {
5781: $result .=
5782: &bodytag($title,
5783: $args->{'function'}, $args->{'add_entries'},
5784: $args->{'only_body'}, $args->{'domain'},
5785: $args->{'force_register'}, $args->{'body_title'},
5786: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 5787: $args->{'no_title'}, $args->{'no_inline_link'},
5788: $args);
1.338 albertel 5789: }
1.330 albertel 5790: }
1.338 albertel 5791:
1.315 albertel 5792: if ($args->{'js_ready'}) {
1.317 albertel 5793: $result = &js_ready($result);
1.315 albertel 5794: }
1.320 albertel 5795: if ($args->{'html_encode'}) {
5796: $result = &html_encode($result);
5797: }
1.315 albertel 5798: return $result;
1.306 albertel 5799: }
5800:
1.330 albertel 5801:
1.306 albertel 5802: =pod
5803:
5804: =item * &head()
5805:
5806: Returns a complete </body></html> section for LON-CAPA web pages.
5807:
1.315 albertel 5808: Inputs: $args - additional optional args supported are:
5809: js_ready -> return a string ready for being used in
5810: a javascript writeln
1.320 albertel 5811: html_encode -> return a string ready for being used in
5812: a html attribute
1.330 albertel 5813: frameset -> if true will start with a <frameset>
5814: rather than <body>
1.493 albertel 5815: dicsussion -> if true will get discussion from
5816: lonxml::xmlend
5817: (you can pass the target and parser arguments
5818: through optional 'target' and 'parser' args
5819: to this routine)
1.306 albertel 5820:
5821: =cut
5822:
5823: sub end_page {
1.315 albertel 5824: my ($args) = @_;
5825: $env{'internal.end_page'}++;
1.330 albertel 5826: my $result;
1.335 albertel 5827: if ($args->{'discussion'}) {
5828: my ($target,$parser);
5829: if (ref($args->{'discussion'})) {
5830: ($target,$parser) =($args->{'discussion'}{'target'},
5831: $args->{'discussion'}{'parser'});
5832: }
5833: $result .= &Apache::lonxml::xmlend($target,$parser);
5834: }
5835:
1.330 albertel 5836: if ($args->{'frameset'}) {
5837: $result .= '</frameset>';
5838: } else {
1.635 raeburn 5839: $result .= &endbodytag($args);
1.330 albertel 5840: }
5841: $result .= "\n</html>";
5842:
1.315 albertel 5843: if ($args->{'js_ready'}) {
1.317 albertel 5844: $result = &js_ready($result);
1.315 albertel 5845: }
1.335 albertel 5846:
1.320 albertel 5847: if ($args->{'html_encode'}) {
5848: $result = &html_encode($result);
5849: }
1.335 albertel 5850:
1.315 albertel 5851: return $result;
5852: }
5853:
1.320 albertel 5854: sub html_encode {
5855: my ($result) = @_;
5856:
1.322 albertel 5857: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 5858:
5859: return $result;
5860: }
1.317 albertel 5861: sub js_ready {
5862: my ($result) = @_;
5863:
1.323 albertel 5864: $result =~ s/[\n\r]/ /xmsg;
5865: $result =~ s/\\/\\\\/xmsg;
5866: $result =~ s/'/\\'/xmsg;
1.372 albertel 5867: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 5868:
5869: return $result;
5870: }
5871:
1.315 albertel 5872: sub validate_page {
5873: if ( exists($env{'internal.start_page'})
1.316 albertel 5874: && $env{'internal.start_page'} > 1) {
5875: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 5876: $env{'internal.start_page'}.' '.
1.316 albertel 5877: $ENV{'request.filename'});
1.315 albertel 5878: }
5879: if ( exists($env{'internal.end_page'})
1.316 albertel 5880: && $env{'internal.end_page'} > 1) {
5881: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 5882: $env{'internal.end_page'}.' '.
1.316 albertel 5883: $env{'request.filename'});
1.315 albertel 5884: }
5885: if ( exists($env{'internal.start_page'})
5886: && ! exists($env{'internal.end_page'})) {
1.316 albertel 5887: &Apache::lonnet::logthis('start_page called without end_page '.
5888: $env{'request.filename'});
1.315 albertel 5889: }
5890: if ( ! exists($env{'internal.start_page'})
5891: && exists($env{'internal.end_page'})) {
1.316 albertel 5892: &Apache::lonnet::logthis('end_page called without start_page'.
5893: $env{'request.filename'});
1.315 albertel 5894: }
1.306 albertel 5895: }
1.315 albertel 5896:
1.318 albertel 5897: sub simple_error_page {
5898: my ($r,$title,$msg) = @_;
5899: my $page =
5900: &Apache::loncommon::start_page($title).
5901: &mt($msg).
5902: &Apache::loncommon::end_page();
5903: if (ref($r)) {
5904: $r->print($page);
1.327 albertel 5905: return;
1.318 albertel 5906: }
5907: return $page;
5908: }
1.347 albertel 5909:
5910: {
1.610 albertel 5911: my @row_count;
1.347 albertel 5912: sub start_data_table {
1.422 albertel 5913: my ($add_class) = @_;
5914: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 5915: unshift(@row_count,0);
1.422 albertel 5916: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 5917: }
5918:
5919: sub end_data_table {
1.610 albertel 5920: shift(@row_count);
1.389 albertel 5921: return '</table>'."\n";;
1.347 albertel 5922: }
5923:
5924: sub start_data_table_row {
1.422 albertel 5925: my ($add_class) = @_;
1.610 albertel 5926: $row_count[0]++;
5927: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 5928: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 5929: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 5930: }
1.471 banghart 5931:
5932: sub continue_data_table_row {
5933: my ($add_class) = @_;
1.610 albertel 5934: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 5935: $css_class = (join(' ',$css_class,$add_class));
5936: return '<tr class="'.$css_class.'">'."\n";;
5937: }
1.347 albertel 5938:
5939: sub end_data_table_row {
1.389 albertel 5940: return '</tr>'."\n";;
1.347 albertel 5941: }
1.367 www 5942:
1.421 albertel 5943: sub start_data_table_empty_row {
1.610 albertel 5944: $row_count[0]++;
1.421 albertel 5945: return '<tr class="LC_empty_row" >'."\n";;
5946: }
5947:
5948: sub end_data_table_empty_row {
5949: return '</tr>'."\n";;
5950: }
5951:
1.367 www 5952: sub start_data_table_header_row {
1.389 albertel 5953: return '<tr class="LC_header_row">'."\n";;
1.367 www 5954: }
5955:
5956: sub end_data_table_header_row {
1.389 albertel 5957: return '</tr>'."\n";;
1.367 www 5958: }
1.347 albertel 5959: }
5960:
1.548 albertel 5961: =pod
5962:
5963: =item * &inhibit_menu_check($arg)
5964:
5965: Checks for a inhibitmenu state and generates output to preserve it
5966:
5967: Inputs: $arg - can be any of
5968: - undef - in which case the return value is a string
5969: to add into arguments list of a uri
5970: - 'input' - in which case the return value is a HTML
5971: <form> <input> field of type hidden to
5972: preserve the value
5973: - a url - in which case the return value is the url with
5974: the neccesary cgi args added to preserve the
5975: inhibitmenu state
5976: - a ref to a url - no return value, but the string is
5977: updated to include the neccessary cgi
5978: args to preserve the inhibitmenu state
5979:
5980: =cut
5981:
5982: sub inhibit_menu_check {
5983: my ($arg) = @_;
5984: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5985: if ($arg eq 'input') {
5986: if ($env{'form.inhibitmenu'}) {
5987: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
5988: } else {
5989: return
5990: }
5991: }
5992: if ($env{'form.inhibitmenu'}) {
5993: if (ref($arg)) {
5994: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5995: } elsif ($arg eq '') {
5996: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
5997: } else {
5998: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5999: }
6000: }
6001: if (!ref($arg)) {
6002: return $arg;
6003: }
6004: }
6005:
1.251 albertel 6006: ###############################################
1.182 matthew 6007:
6008: =pod
6009:
1.549 albertel 6010: =back
6011:
6012: =head1 User Information Routines
6013:
6014: =over 4
6015:
1.405 albertel 6016: =item * &get_users_function()
1.182 matthew 6017:
6018: Used by &bodytag to determine the current users primary role.
6019: Returns either 'student','coordinator','admin', or 'author'.
6020:
6021: =cut
6022:
6023: ###############################################
6024: sub get_users_function {
6025: my $function = 'student';
1.258 albertel 6026: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6027: $function='coordinator';
6028: }
1.258 albertel 6029: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6030: $function='admin';
6031: }
1.258 albertel 6032: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6033: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6034: $function='author';
6035: }
6036: return $function;
1.54 www 6037: }
1.99 www 6038:
6039: ###############################################
6040:
1.233 raeburn 6041: =pod
6042:
1.542 raeburn 6043: =item * &check_user_status()
1.274 raeburn 6044:
6045: Determines current status of supplied role for a
6046: specific user. Roles can be active, previous or future.
6047:
6048: Inputs:
6049: user's domain, user's username, course's domain,
1.375 raeburn 6050: course's number, optional section ID.
1.274 raeburn 6051:
6052: Outputs:
6053: role status: active, previous or future.
6054:
6055: =cut
6056:
6057: sub check_user_status {
1.412 raeburn 6058: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6059: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6060: my @uroles = keys %userinfo;
6061: my $srchstr;
6062: my $active_chk = 'none';
1.412 raeburn 6063: my $now = time;
1.274 raeburn 6064: if (@uroles > 0) {
1.412 raeburn 6065: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6066: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6067: } else {
1.412 raeburn 6068: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6069: }
6070: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6071: my $role_end = 0;
6072: my $role_start = 0;
6073: $active_chk = 'active';
1.412 raeburn 6074: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6075: $role_end = $1;
6076: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6077: $role_start = $1;
1.274 raeburn 6078: }
6079: }
6080: if ($role_start > 0) {
1.412 raeburn 6081: if ($now < $role_start) {
1.274 raeburn 6082: $active_chk = 'future';
6083: }
6084: }
6085: if ($role_end > 0) {
1.412 raeburn 6086: if ($now > $role_end) {
1.274 raeburn 6087: $active_chk = 'previous';
6088: }
6089: }
6090: }
6091: }
6092: return $active_chk;
6093: }
6094:
6095: ###############################################
6096:
6097: =pod
6098:
1.405 albertel 6099: =item * &get_sections()
1.233 raeburn 6100:
6101: Determines all the sections for a course including
6102: sections with students and sections containing other roles.
1.419 raeburn 6103: Incoming parameters:
6104:
6105: 1. domain
6106: 2. course number
6107: 3. reference to array containing roles for which sections should
6108: be gathered (optional).
6109: 4. reference to array containing status types for which sections
6110: should be gathered (optional).
6111:
6112: If the third argument is undefined, sections are gathered for any role.
6113: If the fourth argument is undefined, sections are gathered for any status.
6114: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6115:
1.374 raeburn 6116: Returns section hash (keys are section IDs, values are
6117: number of users in each section), subject to the
1.419 raeburn 6118: optional roles filter, optional status filter
1.233 raeburn 6119:
6120: =cut
6121:
6122: ###############################################
6123: sub get_sections {
1.419 raeburn 6124: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6125: if (!defined($cdom) || !defined($cnum)) {
6126: my $cid = $env{'request.course.id'};
6127:
6128: return if (!defined($cid));
6129:
6130: $cdom = $env{'course.'.$cid.'.domain'};
6131: $cnum = $env{'course.'.$cid.'.num'};
6132: }
6133:
6134: my %sectioncount;
1.419 raeburn 6135: my $now = time;
1.240 albertel 6136:
1.366 albertel 6137: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6138: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6139: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6140: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6141: my $start_index = &Apache::loncoursedata::CL_START();
6142: my $end_index = &Apache::loncoursedata::CL_END();
6143: my $status;
1.366 albertel 6144: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6145: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6146: $data->[$status_index],
6147: $data->[$start_index],
6148: $data->[$end_index]);
6149: if ($stu_status eq 'Active') {
6150: $status = 'active';
6151: } elsif ($end < $now) {
6152: $status = 'previous';
6153: } elsif ($start > $now) {
6154: $status = 'future';
6155: }
6156: if ($section ne '-1' && $section !~ /^\s*$/) {
6157: if ((!defined($possible_status)) || (($status ne '') &&
6158: (grep/^\Q$status\E$/,@{$possible_status}))) {
6159: $sectioncount{$section}++;
6160: }
1.240 albertel 6161: }
6162: }
6163: }
6164: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6165: foreach my $user (sort(keys(%courseroles))) {
6166: if ($user !~ /^(\w{2})/) { next; }
6167: my ($role) = ($user =~ /^(\w{2})/);
6168: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6169: my ($section,$status);
1.240 albertel 6170: if ($role eq 'cr' &&
6171: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6172: $section=$1;
6173: }
6174: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6175: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6176: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6177: if ($end == -1 && $start == -1) {
6178: next; #deleted role
6179: }
6180: if (!defined($possible_status)) {
6181: $sectioncount{$section}++;
6182: } else {
6183: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6184: $status = 'active';
6185: } elsif ($end < $now) {
6186: $status = 'future';
6187: } elsif ($start > $now) {
6188: $status = 'previous';
6189: }
6190: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6191: $sectioncount{$section}++;
6192: }
6193: }
1.233 raeburn 6194: }
1.366 albertel 6195: return %sectioncount;
1.233 raeburn 6196: }
6197:
1.274 raeburn 6198: ###############################################
1.294 raeburn 6199:
6200: =pod
1.405 albertel 6201:
6202: =item * &get_course_users()
6203:
1.275 raeburn 6204: Retrieves usernames:domains for users in the specified course
6205: with specific role(s), and access status.
6206:
6207: Incoming parameters:
1.277 albertel 6208: 1. course domain
6209: 2. course number
6210: 3. access status: users must have - either active,
1.275 raeburn 6211: previous, future, or all.
1.277 albertel 6212: 4. reference to array of permissible roles
1.288 raeburn 6213: 5. reference to array of section restrictions (optional)
6214: 6. reference to results object (hash of hashes).
6215: 7. reference to optional userdata hash
1.609 raeburn 6216: 8. reference to optional statushash
1.630 raeburn 6217: 9. flag if privileged users (except those set to unhide in
6218: course settings) should be excluded
1.609 raeburn 6219: Keys of top level results hash are roles.
1.275 raeburn 6220: Keys of inner hashes are username:domain, with
6221: values set to access type.
1.288 raeburn 6222: Optional userdata hash returns an array with arguments in the
6223: same order as loncoursedata::get_classlist() for student data.
6224:
1.609 raeburn 6225: Optional statushash returns
6226:
1.288 raeburn 6227: Entries for end, start, section and status are blank because
6228: of the possibility of multiple values for non-student roles.
6229:
1.275 raeburn 6230: =cut
1.405 albertel 6231:
1.275 raeburn 6232: ###############################################
1.405 albertel 6233:
1.275 raeburn 6234: sub get_course_users {
1.630 raeburn 6235: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6236: my %idx = ();
1.419 raeburn 6237: my %seclists;
1.288 raeburn 6238:
6239: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6240: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6241: $idx{end} = &Apache::loncoursedata::CL_END();
6242: $idx{start} = &Apache::loncoursedata::CL_START();
6243: $idx{id} = &Apache::loncoursedata::CL_ID();
6244: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6245: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6246: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6247:
1.290 albertel 6248: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6249: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6250: my $now = time;
1.277 albertel 6251: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6252: my $match = 0;
1.412 raeburn 6253: my $secmatch = 0;
1.419 raeburn 6254: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6255: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6256: if ($section eq '') {
6257: $section = 'none';
6258: }
1.291 albertel 6259: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6260: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6261: $secmatch = 1;
6262: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6263: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6264: $secmatch = 1;
6265: }
6266: } else {
1.419 raeburn 6267: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6268: $secmatch = 1;
6269: }
1.290 albertel 6270: }
1.412 raeburn 6271: if (!$secmatch) {
6272: next;
6273: }
1.419 raeburn 6274: }
1.275 raeburn 6275: if (defined($$types{'active'})) {
1.288 raeburn 6276: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6277: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6278: $match = 1;
1.275 raeburn 6279: }
6280: }
6281: if (defined($$types{'previous'})) {
1.609 raeburn 6282: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6283: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6284: $match = 1;
1.275 raeburn 6285: }
6286: }
6287: if (defined($$types{'future'})) {
1.609 raeburn 6288: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6289: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6290: $match = 1;
1.275 raeburn 6291: }
6292: }
1.609 raeburn 6293: if ($match) {
6294: push(@{$seclists{$student}},$section);
6295: if (ref($userdata) eq 'HASH') {
6296: $$userdata{$student} = $$classlist{$student};
6297: }
6298: if (ref($statushash) eq 'HASH') {
6299: $statushash->{$student}{'st'}{$section} = $status;
6300: }
1.288 raeburn 6301: }
1.275 raeburn 6302: }
6303: }
1.412 raeburn 6304: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6305: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6306: my $now = time;
1.609 raeburn 6307: my %displaystatus = ( previous => 'Expired',
6308: active => 'Active',
6309: future => 'Future',
6310: );
1.630 raeburn 6311: my %nothide;
6312: if ($hidepriv) {
6313: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6314: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6315: if ($user !~ /:/) {
6316: $nothide{join(':',split(/[\@]/,$user))}=1;
6317: } else {
6318: $nothide{$user} = 1;
6319: }
6320: }
6321: }
1.439 raeburn 6322: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6323: my $match = 0;
1.412 raeburn 6324: my $secmatch = 0;
1.439 raeburn 6325: my $status;
1.412 raeburn 6326: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6327: $user =~ s/:$//;
1.439 raeburn 6328: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6329: if ($end == -1 || $start == -1) {
6330: next;
6331: }
6332: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6333: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6334: my ($uname,$udom) = split(/:/,$user);
6335: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6336: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6337: $secmatch = 1;
6338: } elsif ($usec eq '') {
1.420 albertel 6339: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6340: $secmatch = 1;
6341: }
6342: } else {
6343: if (grep(/^\Q$usec\E$/,@{$sections})) {
6344: $secmatch = 1;
6345: }
6346: }
6347: if (!$secmatch) {
6348: next;
6349: }
1.288 raeburn 6350: }
1.419 raeburn 6351: if ($usec eq '') {
6352: $usec = 'none';
6353: }
1.275 raeburn 6354: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6355: if ($hidepriv) {
6356: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6357: (!$nothide{$uname.':'.$udom})) {
6358: next;
6359: }
6360: }
1.503 raeburn 6361: if ($end > 0 && $end < $now) {
1.439 raeburn 6362: $status = 'previous';
6363: } elsif ($start > $now) {
6364: $status = 'future';
6365: } else {
6366: $status = 'active';
6367: }
1.277 albertel 6368: foreach my $type (keys(%{$types})) {
1.275 raeburn 6369: if ($status eq $type) {
1.420 albertel 6370: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6371: push(@{$$users{$role}{$user}},$type);
6372: }
1.288 raeburn 6373: $match = 1;
6374: }
6375: }
1.419 raeburn 6376: if (($match) && (ref($userdata) eq 'HASH')) {
6377: if (!exists($$userdata{$uname.':'.$udom})) {
6378: &get_user_info($udom,$uname,\%idx,$userdata);
6379: }
1.420 albertel 6380: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6381: push(@{$seclists{$uname.':'.$udom}},$usec);
6382: }
1.609 raeburn 6383: if (ref($statushash) eq 'HASH') {
6384: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6385: }
1.275 raeburn 6386: }
6387: }
6388: }
6389: }
1.290 albertel 6390: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6391: if ((defined($cdom)) && (defined($cnum))) {
6392: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6393: if ( defined($csettings{'internal.courseowner'}) ) {
6394: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6395: next if ($owner eq '');
6396: my ($ownername,$ownerdom);
6397: if ($owner =~ /^([^:]+):([^:]+)$/) {
6398: $ownername = $1;
6399: $ownerdom = $2;
6400: } else {
6401: $ownername = $owner;
6402: $ownerdom = $cdom;
6403: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6404: }
6405: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6406: if (defined($userdata) &&
1.609 raeburn 6407: !exists($$userdata{$owner})) {
6408: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6409: if (!grep(/^none$/,@{$seclists{$owner}})) {
6410: push(@{$seclists{$owner}},'none');
6411: }
6412: if (ref($statushash) eq 'HASH') {
6413: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6414: }
1.290 albertel 6415: }
1.279 raeburn 6416: }
6417: }
6418: }
1.419 raeburn 6419: foreach my $user (keys(%seclists)) {
6420: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6421: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6422: }
1.275 raeburn 6423: }
6424: return;
6425: }
6426:
1.288 raeburn 6427: sub get_user_info {
6428: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6429: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6430: &plainname($uname,$udom,'lastname');
1.291 albertel 6431: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6432: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6433: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6434: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6435: return;
6436: }
1.275 raeburn 6437:
1.472 raeburn 6438: ###############################################
6439:
6440: =pod
6441:
6442: =item * &get_user_quota()
6443:
6444: Retrieves quota assigned for storage of portfolio files for a user
6445:
6446: Incoming parameters:
6447: 1. user's username
6448: 2. user's domain
6449:
6450: Returns:
1.536 raeburn 6451: 1. Disk quota (in Mb) assigned to student.
6452: 2. (Optional) Type of setting: custom or default
6453: (individually assigned or default for user's
6454: institutional status).
6455: 3. (Optional) - User's institutional status (e.g., faculty, staff
6456: or student - types as defined in localenroll::inst_usertypes
6457: for user's domain, which determines default quota for user.
6458: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6459:
6460: If a value has been stored in the user's environment,
1.536 raeburn 6461: it will return that, otherwise it returns the maximal default
6462: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6463:
6464: =cut
6465:
6466: ###############################################
6467:
6468:
6469: sub get_user_quota {
6470: my ($uname,$udom) = @_;
1.536 raeburn 6471: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6472: if (!defined($udom)) {
6473: $udom = $env{'user.domain'};
6474: }
6475: if (!defined($uname)) {
6476: $uname = $env{'user.name'};
6477: }
6478: if (($udom eq '' || $uname eq '') ||
6479: ($udom eq 'public') && ($uname eq 'public')) {
6480: $quota = 0;
1.536 raeburn 6481: $quotatype = 'default';
6482: $defquota = 0;
1.472 raeburn 6483: } else {
1.536 raeburn 6484: my $inststatus;
1.472 raeburn 6485: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6486: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6487: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6488: } else {
1.536 raeburn 6489: my %userenv =
6490: &Apache::lonnet::get('environment',['portfolioquota',
6491: 'inststatus'],$udom,$uname);
1.472 raeburn 6492: my ($tmp) = keys(%userenv);
6493: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6494: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6495: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6496: } else {
6497: undef(%userenv);
6498: }
6499: }
1.536 raeburn 6500: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6501: if ($quota eq '') {
1.536 raeburn 6502: $quota = $defquota;
6503: $quotatype = 'default';
6504: } else {
6505: $quotatype = 'custom';
1.472 raeburn 6506: }
6507: }
1.536 raeburn 6508: if (wantarray) {
6509: return ($quota,$quotatype,$settingstatus,$defquota);
6510: } else {
6511: return $quota;
6512: }
1.472 raeburn 6513: }
6514:
6515: ###############################################
6516:
6517: =pod
6518:
6519: =item * &default_quota()
6520:
1.536 raeburn 6521: Retrieves default quota assigned for storage of user portfolio files,
6522: given an (optional) user's institutional status.
1.472 raeburn 6523:
6524: Incoming parameters:
6525: 1. domain
1.536 raeburn 6526: 2. (Optional) institutional status(es). This is a : separated list of
6527: status types (e.g., faculty, staff, student etc.)
6528: which apply to the user for whom the default is being retrieved.
6529: If the institutional status string in undefined, the domain
6530: default quota will be returned.
1.472 raeburn 6531:
6532: Returns:
6533: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6534: 2. (Optional) institutional type which determined the value of the
6535: default quota.
1.472 raeburn 6536:
6537: If a value has been stored in the domain's configuration db,
6538: it will return that, otherwise it returns 20 (for backwards
6539: compatibility with domains which have not set up a configuration
6540: db file; the original statically defined portfolio quota was 20 Mb).
6541:
1.536 raeburn 6542: If the user's status includes multiple types (e.g., staff and student),
6543: the largest default quota which applies to the user determines the
6544: default quota returned.
6545:
1.472 raeburn 6546: =cut
6547:
6548: ###############################################
6549:
6550:
6551: sub default_quota {
1.536 raeburn 6552: my ($udom,$inststatus) = @_;
6553: my ($defquota,$settingstatus);
6554: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6555: ['quotas'],$udom);
6556: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6557: if ($inststatus ne '') {
6558: my @statuses = split(/:/,$inststatus);
6559: foreach my $item (@statuses) {
1.692.2.3 raeburn 6560: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6561: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6562: if ($defquota eq '') {
6563: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6564: $settingstatus = $item;
6565: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6566: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6567: $settingstatus = $item;
6568: }
6569: }
6570: } else {
6571: if ($quotahash{'quotas'}{$item} ne '') {
6572: if ($defquota eq '') {
6573: $defquota = $quotahash{'quotas'}{$item};
6574: $settingstatus = $item;
6575: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6576: $defquota = $quotahash{'quotas'}{$item};
6577: $settingstatus = $item;
6578: }
1.536 raeburn 6579: }
6580: }
6581: }
6582: }
6583: if ($defquota eq '') {
1.692.2.3 raeburn 6584: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6585: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6586: } else {
6587: $defquota = $quotahash{'quotas'}{'default'};
6588: }
1.536 raeburn 6589: $settingstatus = 'default';
6590: }
6591: } else {
6592: $settingstatus = 'default';
6593: $defquota = 20;
6594: }
6595: if (wantarray) {
6596: return ($defquota,$settingstatus);
1.472 raeburn 6597: } else {
1.536 raeburn 6598: return $defquota;
1.472 raeburn 6599: }
6600: }
6601:
1.384 raeburn 6602: sub get_secgrprole_info {
6603: my ($cdom,$cnum,$needroles,$type) = @_;
6604: my %sections_count = &get_sections($cdom,$cnum);
6605: my @sections = (sort {$a <=> $b} keys(%sections_count));
6606: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6607: my @groups = sort(keys(%curr_groups));
6608: my $allroles = [];
6609: my $rolehash;
6610: my $accesshash = {
6611: active => 'Currently has access',
6612: future => 'Will have future access',
6613: previous => 'Previously had access',
6614: };
6615: if ($needroles) {
6616: $rolehash = {'all' => 'all'};
1.385 albertel 6617: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6618: if (&Apache::lonnet::error(%user_roles)) {
6619: undef(%user_roles);
6620: }
6621: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6622: my ($role)=split(/\:/,$item,2);
6623: if ($role eq 'cr') { next; }
6624: if ($role =~ /^cr/) {
6625: $$rolehash{$role} = (split('/',$role))[3];
6626: } else {
6627: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6628: }
6629: }
6630: foreach my $key (sort(keys(%{$rolehash}))) {
6631: push(@{$allroles},$key);
6632: }
6633: push (@{$allroles},'st');
6634: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6635: }
6636: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6637: }
6638:
1.555 raeburn 6639: sub user_picker {
1.627 raeburn 6640: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6641: my $currdom = $dom;
6642: my %curr_selected = (
6643: srchin => 'dom',
1.580 raeburn 6644: srchby => 'lastname',
1.555 raeburn 6645: );
6646: my $srchterm;
1.625 raeburn 6647: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6648: if ($srch->{'srchby'} ne '') {
6649: $curr_selected{'srchby'} = $srch->{'srchby'};
6650: }
6651: if ($srch->{'srchin'} ne '') {
6652: $curr_selected{'srchin'} = $srch->{'srchin'};
6653: }
6654: if ($srch->{'srchtype'} ne '') {
6655: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6656: }
6657: if ($srch->{'srchdomain'} ne '') {
6658: $currdom = $srch->{'srchdomain'};
6659: }
6660: $srchterm = $srch->{'srchterm'};
6661: }
6662: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6663: 'usr' => 'Search criteria',
1.563 raeburn 6664: 'doma' => 'Domain/institution to search',
1.558 albertel 6665: 'uname' => 'username',
6666: 'lastname' => 'last name',
1.555 raeburn 6667: 'lastfirst' => 'last name, first name',
1.558 albertel 6668: 'crs' => 'in this course',
1.576 raeburn 6669: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6670: 'alc' => 'all LON-CAPA',
1.573 raeburn 6671: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6672: 'exact' => 'is',
6673: 'contains' => 'contains',
1.569 raeburn 6674: 'begins' => 'begins with',
1.571 raeburn 6675: 'youm' => "You must include some text to search for.",
6676: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6677: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6678: 'yomc' => "You must choose a domain when using an institutional directory search.",
6679: 'ymcd' => "You must choose a domain when using a domain search.",
6680: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6681: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6682: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6683: );
1.563 raeburn 6684: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6685: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6686:
6687: my @srchins = ('crs','dom','alc','instd');
6688:
6689: foreach my $option (@srchins) {
6690: # FIXME 'alc' option unavailable until
6691: # loncreateuser::print_user_query_page()
6692: # has been completed.
6693: next if ($option eq 'alc');
6694: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6695: if ($curr_selected{'srchin'} eq $option) {
6696: $srchinsel .= '
6697: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6698: } else {
6699: $srchinsel .= '
6700: <option value="'.$option.'">'.$lt{$option}.'</option>';
6701: }
1.555 raeburn 6702: }
1.563 raeburn 6703: $srchinsel .= "\n </select>\n";
1.555 raeburn 6704:
6705: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 6706: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 6707: if ($curr_selected{'srchby'} eq $option) {
6708: $srchbysel .= '
6709: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6710: } else {
6711: $srchbysel .= '
6712: <option value="'.$option.'">'.$lt{$option}.'</option>';
6713: }
6714: }
6715: $srchbysel .= "\n </select>\n";
6716:
6717: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 6718: foreach my $option ('begins','contains','exact') {
1.555 raeburn 6719: if ($curr_selected{'srchtype'} eq $option) {
6720: $srchtypesel .= '
6721: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6722: } else {
6723: $srchtypesel .= '
6724: <option value="'.$option.'">'.$lt{$option}.'</option>';
6725: }
6726: }
6727: $srchtypesel .= "\n </select>\n";
6728:
1.558 albertel 6729: my ($newuserscript,$new_user_create);
1.556 raeburn 6730:
6731: if ($forcenewuser) {
1.576 raeburn 6732: if (ref($srch) eq 'HASH') {
6733: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 6734: if ($cancreate) {
6735: $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>';
6736: } else {
6737: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
6738: my %usertypetext = (
6739: official => 'institutional',
6740: unofficial => 'non-institutional',
6741: );
6742: $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 />';
6743: }
1.576 raeburn 6744: }
6745: }
6746:
1.556 raeburn 6747: $newuserscript = <<"ENDSCRIPT";
6748:
1.570 raeburn 6749: function setSearch(createnew,callingForm) {
1.556 raeburn 6750: if (createnew == 1) {
1.570 raeburn 6751: for (var i=0; i<callingForm.srchby.length; i++) {
6752: if (callingForm.srchby.options[i].value == 'uname') {
6753: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6754: }
6755: }
1.570 raeburn 6756: for (var i=0; i<callingForm.srchin.length; i++) {
6757: if ( callingForm.srchin.options[i].value == 'dom') {
6758: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6759: }
6760: }
1.570 raeburn 6761: for (var i=0; i<callingForm.srchtype.length; i++) {
6762: if (callingForm.srchtype.options[i].value == 'exact') {
6763: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6764: }
6765: }
1.570 raeburn 6766: for (var i=0; i<callingForm.srchdomain.length; i++) {
6767: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6768: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6769: }
6770: }
6771: }
6772: }
6773: ENDSCRIPT
1.558 albertel 6774:
1.556 raeburn 6775: }
6776:
1.555 raeburn 6777: my $output = <<"END_BLOCK";
1.556 raeburn 6778: <script type="text/javascript">
1.570 raeburn 6779: function validateEntry(callingForm) {
1.558 albertel 6780:
1.556 raeburn 6781: var checkok = 1;
1.558 albertel 6782: var srchin;
1.570 raeburn 6783: for (var i=0; i<callingForm.srchin.length; i++) {
6784: if ( callingForm.srchin[i].checked ) {
6785: srchin = callingForm.srchin[i].value;
1.558 albertel 6786: }
6787: }
6788:
1.570 raeburn 6789: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6790: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6791: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6792: var srchterm = callingForm.srchterm.value;
6793: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6794: var msg = "";
6795:
6796: if (srchterm == "") {
6797: checkok = 0;
1.571 raeburn 6798: msg += "$lt{'youm'}\\n";
1.556 raeburn 6799: }
6800:
1.569 raeburn 6801: if (srchtype== 'begins') {
6802: if (srchterm.length < 2) {
6803: checkok = 0;
1.571 raeburn 6804: msg += "$lt{'thte'}\\n";
1.569 raeburn 6805: }
6806: }
6807:
1.556 raeburn 6808: if (srchtype== 'contains') {
6809: if (srchterm.length < 3) {
6810: checkok = 0;
1.571 raeburn 6811: msg += "$lt{'thet'}\\n";
1.556 raeburn 6812: }
6813: }
6814: if (srchin == 'instd') {
6815: if (srchdomain == '') {
6816: checkok = 0;
1.571 raeburn 6817: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6818: }
6819: }
6820: if (srchin == 'dom') {
6821: if (srchdomain == '') {
6822: checkok = 0;
1.571 raeburn 6823: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6824: }
6825: }
6826: if (srchby == 'lastfirst') {
6827: if (srchterm.indexOf(",") == -1) {
6828: checkok = 0;
1.571 raeburn 6829: msg += "$lt{'whus'}\\n";
1.556 raeburn 6830: }
6831: if (srchterm.indexOf(",") == srchterm.length -1) {
6832: checkok = 0;
1.571 raeburn 6833: msg += "$lt{'whse'}\\n";
1.556 raeburn 6834: }
6835: }
6836: if (checkok == 0) {
1.571 raeburn 6837: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6838: return;
6839: }
6840: if (checkok == 1) {
1.570 raeburn 6841: callingForm.submit();
1.556 raeburn 6842: }
6843: }
6844:
6845: $newuserscript
6846:
6847: </script>
1.558 albertel 6848:
6849: $new_user_create
6850:
1.555 raeburn 6851: <table>
1.558 albertel 6852: <tr>
1.573 raeburn 6853: <td>$lt{'doma'}:</td>
6854: <td>$domform</td>
6855: </td>
6856: </tr>
6857: <tr>
6858: <td>$lt{'usr'}:</td>
1.563 raeburn 6859: <td>$srchbysel
6860: $srchtypesel
6861: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 6862: $srchinsel
1.563 raeburn 6863: </td>
6864: </tr>
1.555 raeburn 6865: </table>
6866: <br />
6867: END_BLOCK
1.558 albertel 6868:
1.555 raeburn 6869: return $output;
6870: }
6871:
1.612 raeburn 6872: sub user_rule_check {
1.615 raeburn 6873: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 6874: my $response;
6875: if (ref($usershash) eq 'HASH') {
6876: foreach my $user (keys(%{$usershash})) {
6877: my ($uname,$udom) = split(/:/,$user);
6878: next if ($udom eq '' || $uname eq '');
1.615 raeburn 6879: my ($id,$newuser);
1.612 raeburn 6880: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 6881: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 6882: $id = $usershash->{$user}->{'id'};
6883: }
6884: my $inst_response;
6885: if (ref($checks) eq 'HASH') {
6886: if (defined($checks->{'username'})) {
1.615 raeburn 6887: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6888: &Apache::lonnet::get_instuser($udom,$uname);
6889: } elsif (defined($checks->{'id'})) {
1.615 raeburn 6890: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6891: &Apache::lonnet::get_instuser($udom,undef,$id);
6892: }
1.615 raeburn 6893: } else {
6894: ($inst_response,%{$inst_results->{$user}}) =
6895: &Apache::lonnet::get_instuser($udom,$uname);
6896: return;
1.612 raeburn 6897: }
1.615 raeburn 6898: if (!$got_rules->{$udom}) {
1.612 raeburn 6899: my %domconfig = &Apache::lonnet::get_dom('configuration',
6900: ['usercreation'],$udom);
6901: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 6902: foreach my $item ('username','id') {
1.612 raeburn 6903: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6904: $$curr_rules{$udom}{$item} =
6905: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 6906: }
6907: }
6908: }
1.615 raeburn 6909: $got_rules->{$udom} = 1;
1.585 raeburn 6910: }
1.612 raeburn 6911: foreach my $item (keys(%{$checks})) {
6912: if (ref($$curr_rules{$udom}) eq 'HASH') {
6913: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
6914: if (@{$$curr_rules{$udom}{$item}} > 0) {
6915: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
6916: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
6917: if ($rule_check{$rule}) {
6918: $$rulematch{$user}{$item} = $rule;
6919: if ($inst_response eq 'ok') {
1.615 raeburn 6920: if (ref($inst_results) eq 'HASH') {
6921: if (ref($inst_results->{$user}) eq 'HASH') {
6922: if (keys(%{$inst_results->{$user}}) == 0) {
6923: $$alerts{$item}{$udom}{$uname} = 1;
6924: }
1.612 raeburn 6925: }
6926: }
1.615 raeburn 6927: }
6928: last;
1.585 raeburn 6929: }
6930: }
6931: }
6932: }
6933: }
6934: }
6935: }
6936: }
1.612 raeburn 6937: return;
6938: }
6939:
6940: sub user_rule_formats {
6941: my ($domain,$domdesc,$curr_rules,$check) = @_;
6942: my %text = (
6943: 'username' => 'Usernames',
6944: 'id' => 'IDs',
6945: );
6946: my $output;
6947: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
6948: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
6949: if (@{$ruleorder} > 0) {
6950: $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>';
6951: foreach my $rule (@{$ruleorder}) {
6952: if (ref($curr_rules) eq 'ARRAY') {
6953: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
6954: if (ref($rules->{$rule}) eq 'HASH') {
6955: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
6956: $rules->{$rule}{'desc'}.'</li>';
6957: }
6958: }
6959: }
6960: }
6961: $output .= '</ul>';
6962: }
6963: }
6964: return $output;
6965: }
6966:
6967: sub instrule_disallow_msg {
1.615 raeburn 6968: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 6969: my $response;
6970: my %text = (
6971: item => 'username',
6972: items => 'usernames',
6973: match => 'matches',
6974: do => 'does',
6975: action => 'a username',
6976: one => 'one',
6977: );
6978: if ($count > 1) {
6979: $text{'item'} = 'usernames';
6980: $text{'match'} ='match';
6981: $text{'do'} = 'do';
6982: $text{'action'} = 'usernames',
6983: $text{'one'} = 'ones';
6984: }
6985: if ($checkitem eq 'id') {
6986: $text{'items'} = 'IDs';
6987: $text{'item'} = 'ID';
6988: $text{'action'} = 'an ID';
1.615 raeburn 6989: if ($count > 1) {
6990: $text{'item'} = 'IDs';
6991: $text{'action'} = 'IDs';
6992: }
1.612 raeburn 6993: }
1.674 bisitz 6994: $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 6995: if ($mode eq 'upload') {
6996: if ($checkitem eq 'username') {
6997: $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'}.");
6998: } elsif ($checkitem eq 'id') {
1.674 bisitz 6999: $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 7000: }
1.669 raeburn 7001: } elsif ($mode eq 'selfcreate') {
7002: if ($checkitem eq 'id') {
7003: $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.");
7004: }
1.615 raeburn 7005: } else {
7006: if ($checkitem eq 'username') {
7007: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7008: } elsif ($checkitem eq 'id') {
7009: $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.");
7010: }
1.612 raeburn 7011: }
7012: return $response;
1.585 raeburn 7013: }
7014:
1.624 raeburn 7015: sub personal_data_fieldtitles {
7016: my %fieldtitles = &Apache::lonlocal::texthash (
7017: id => 'Student/Employee ID',
7018: permanentemail => 'E-mail address',
7019: lastname => 'Last Name',
7020: firstname => 'First Name',
7021: middlename => 'Middle Name',
7022: generation => 'Generation',
7023: gen => 'Generation',
7024: );
7025: return %fieldtitles;
7026: }
7027:
1.642 raeburn 7028: sub sorted_inst_types {
7029: my ($dom) = @_;
7030: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7031: my $othertitle = &mt('All users');
7032: if ($env{'request.course.id'}) {
1.668 raeburn 7033: $othertitle = &mt('Any users');
1.642 raeburn 7034: }
7035: my @types;
7036: if (ref($order) eq 'ARRAY') {
7037: @types = @{$order};
7038: }
7039: if (@types == 0) {
7040: if (ref($usertypes) eq 'HASH') {
7041: @types = sort(keys(%{$usertypes}));
7042: }
7043: }
7044: if (keys(%{$usertypes}) > 0) {
7045: $othertitle = &mt('Other users');
7046: }
7047: return ($othertitle,$usertypes,\@types);
7048: }
7049:
1.645 raeburn 7050: sub get_institutional_codes {
7051: my ($settings,$allcourses,$LC_code) = @_;
7052: # Get complete list of course sections to update
7053: my @currsections = ();
7054: my @currxlists = ();
7055: my $coursecode = $$settings{'internal.coursecode'};
7056:
7057: if ($$settings{'internal.sectionnums'} ne '') {
7058: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7059: }
7060:
7061: if ($$settings{'internal.crosslistings'} ne '') {
7062: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7063: }
7064:
7065: if (@currxlists > 0) {
7066: foreach (@currxlists) {
7067: if (m/^([^:]+):(\w*)$/) {
7068: unless (grep/^$1$/,@{$allcourses}) {
7069: push @{$allcourses},$1;
7070: $$LC_code{$1} = $2;
7071: }
7072: }
7073: }
7074: }
7075:
7076: if (@currsections > 0) {
7077: foreach (@currsections) {
7078: if (m/^(\w+):(\w*)$/) {
7079: my $sec = $coursecode.$1;
7080: my $lc_sec = $2;
7081: unless (grep/^$sec$/,@{$allcourses}) {
7082: push @{$allcourses},$sec;
7083: $$LC_code{$sec} = $lc_sec;
7084: }
7085: }
7086: }
7087: }
7088: return;
7089: }
7090:
1.112 bowersj2 7091: =pod
7092:
1.549 albertel 7093: =back
7094:
7095: =head1 HTTP Helpers
7096:
7097: =over 4
7098:
1.648 raeburn 7099: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7100:
1.258 albertel 7101: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7102: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7103: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7104:
7105: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7106: $possible_names is an ref to an array of form element names. As an example:
7107: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7108: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7109:
7110: =cut
1.1 albertel 7111:
1.6 albertel 7112: sub get_unprocessed_cgi {
1.25 albertel 7113: my ($query,$possible_names)= @_;
1.26 matthew 7114: # $Apache::lonxml::debug=1;
1.356 albertel 7115: foreach my $pair (split(/&/,$query)) {
7116: my ($name, $value) = split(/=/,$pair);
1.369 www 7117: $name = &unescape($name);
1.25 albertel 7118: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7119: $value =~ tr/+/ /;
7120: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7121: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7122: }
1.16 harris41 7123: }
1.6 albertel 7124: }
7125:
1.112 bowersj2 7126: =pod
7127:
1.648 raeburn 7128: =item * &cacheheader()
1.112 bowersj2 7129:
7130: returns cache-controlling header code
7131:
7132: =cut
7133:
1.7 albertel 7134: sub cacheheader {
1.258 albertel 7135: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7136: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7137: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7138: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7139: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7140: return $output;
1.7 albertel 7141: }
7142:
1.112 bowersj2 7143: =pod
7144:
1.648 raeburn 7145: =item * &no_cache($r)
1.112 bowersj2 7146:
7147: specifies header code to not have cache
7148:
7149: =cut
7150:
1.9 albertel 7151: sub no_cache {
1.216 albertel 7152: my ($r) = @_;
7153: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7154: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7155: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7156: $r->no_cache(1);
7157: $r->header_out("Expires" => $date);
7158: $r->header_out("Pragma" => "no-cache");
1.123 www 7159: }
7160:
7161: sub content_type {
1.181 albertel 7162: my ($r,$type,$charset) = @_;
1.299 foxr 7163: if ($r) {
7164: # Note that printout.pl calls this with undef for $r.
7165: &no_cache($r);
7166: }
1.258 albertel 7167: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7168: unless ($charset) {
7169: $charset=&Apache::lonlocal::current_encoding;
7170: }
7171: if ($charset) { $type.='; charset='.$charset; }
7172: if ($r) {
7173: $r->content_type($type);
7174: } else {
7175: print("Content-type: $type\n\n");
7176: }
1.9 albertel 7177: }
1.25 albertel 7178:
1.112 bowersj2 7179: =pod
7180:
1.648 raeburn 7181: =item * &add_to_env($name,$value)
1.112 bowersj2 7182:
1.258 albertel 7183: adds $name to the %env hash with value
1.112 bowersj2 7184: $value, if $name already exists, the entry is converted to an array
7185: reference and $value is added to the array.
7186:
7187: =cut
7188:
1.25 albertel 7189: sub add_to_env {
7190: my ($name,$value)=@_;
1.258 albertel 7191: if (defined($env{$name})) {
7192: if (ref($env{$name})) {
1.25 albertel 7193: #already have multiple values
1.258 albertel 7194: push(@{ $env{$name} },$value);
1.25 albertel 7195: } else {
7196: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7197: my $first=$env{$name};
7198: undef($env{$name});
7199: push(@{ $env{$name} },$first,$value);
1.25 albertel 7200: }
7201: } else {
1.258 albertel 7202: $env{$name}=$value;
1.25 albertel 7203: }
1.31 albertel 7204: }
1.149 albertel 7205:
7206: =pod
7207:
1.648 raeburn 7208: =item * &get_env_multiple($name)
1.149 albertel 7209:
1.258 albertel 7210: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7211: values may be defined and end up as an array ref.
7212:
7213: returns an array of values
7214:
7215: =cut
7216:
7217: sub get_env_multiple {
7218: my ($name) = @_;
7219: my @values;
1.258 albertel 7220: if (defined($env{$name})) {
1.149 albertel 7221: # exists is it an array
1.258 albertel 7222: if (ref($env{$name})) {
7223: @values=@{ $env{$name} };
1.149 albertel 7224: } else {
1.258 albertel 7225: $values[0]=$env{$name};
1.149 albertel 7226: }
7227: }
7228: return(@values);
7229: }
7230:
1.660 raeburn 7231: sub ask_for_embedded_content {
7232: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7233: my $upload_output = '
7234: <form name="upload_embedded" action="'.$actionurl.'"
7235: method="post" enctype="multipart/form-data">';
7236: $upload_output .= $state;
1.661 raeburn 7237: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7238:
7239: my $num = 0;
7240: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7241: $upload_output .= &start_data_table_row().
7242: '<td>'.$embed_file.'</td><td>';
7243: if ($args->{'ignore_remote_references'}
7244: && $embed_file =~ m{^\w+://}) {
7245: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7246: } elsif ($args->{'error_on_invalid_names'}
7247: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7248:
7249: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7250:
7251: } else {
7252: $upload_output .='
1.661 raeburn 7253: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7254: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7255: my $attrib = join(':',@{$$allfiles{$embed_file}});
7256: $upload_output .=
7257: "\n\t\t".
7258: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7259: $attrib.'" />';
7260: if (exists($$codebase{$embed_file})) {
7261: $upload_output .=
7262: "\n\t\t".
7263: '<input name="codebase_'.$num.'" type="hidden" value="'.
7264: &escape($$codebase{$embed_file}).'" />';
7265: }
7266: }
7267: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7268: $num++;
7269: }
7270: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7271: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7272: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7273: '.&mt('(only files for which a location has been provided will be uploaded)').'
7274: </form>';
7275: return $upload_output;
7276: }
7277:
1.661 raeburn 7278: sub upload_embedded {
7279: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7280: $current_disk_usage) = @_;
7281: my $output;
7282: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7283: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7284: my $orig_uploaded_filename =
7285: $env{'form.embedded_item_'.$i.'.filename'};
7286:
7287: $env{'form.embedded_orig_'.$i} =
7288: &unescape($env{'form.embedded_orig_'.$i});
7289: my ($path,$fname) =
7290: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7291: # no path, whole string is fname
7292: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7293:
7294: $path = $env{'form.currentpath'}.$path;
7295: $fname = &Apache::lonnet::clean_filename($fname);
7296: # See if there is anything left
7297: next if ($fname eq '');
7298:
7299: # Check if file already exists as a file or directory.
7300: my ($state,$msg);
7301: if ($context eq 'portfolio') {
7302: my $port_path = $dirpath;
7303: if ($group ne '') {
7304: $port_path = "groups/$group/$port_path";
7305: }
7306: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7307: $dir_root,$port_path,$disk_quota,
7308: $current_disk_usage,$uname,$udom);
7309: if ($state eq 'will_exceed_quota'
7310: || $state eq 'file_locked'
7311: || $state eq 'file_exists' ) {
7312: $output .= $msg;
7313: next;
7314: }
7315: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7316: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7317: if ($state eq 'exists') {
7318: $output .= $msg;
7319: next;
7320: }
7321: }
7322: # Check if extension is valid
7323: if (($fname =~ /\.(\w+)$/) &&
7324: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7325: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7326: next;
7327: } elsif (($fname =~ /\.(\w+)$/) &&
7328: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7329: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7330: next;
7331: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7332: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7333: next;
7334: }
7335:
7336: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7337: if ($context eq 'portfolio') {
7338: my $result=
7339: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7340: $dirpath.$path);
7341: if ($result !~ m|^/uploaded/|) {
7342: $output .= '<span class="LC_error">'
7343: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7344: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7345: .'</span><br />';
7346: next;
7347: } else {
7348: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7349: $path.$fname.'</span>').'</p>';
7350: }
7351: } else {
7352: # Save the file
7353: my $target = $env{'form.embedded_item_'.$i};
7354: my $fullpath = $dir_root.$dirpath.'/'.$path;
7355: my $dest = $fullpath.$fname;
7356: my $url = $url_root.$dirpath.'/'.$path.$fname;
7357: my @parts=split(/\//,$fullpath);
7358: my $count;
7359: my $filepath = $dir_root;
7360: for ($count=4;$count<=$#parts;$count++) {
7361: $filepath .= "/$parts[$count]";
7362: if ((-e $filepath)!=1) {
7363: mkdir($filepath,0770);
7364: }
7365: }
7366: my $fh;
7367: if (!open($fh,'>'.$dest)) {
7368: &Apache::lonnet::logthis('Failed to create '.$dest);
7369: $output .= '<span class="LC_error">'.
7370: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7371: '</span><br />';
7372: } else {
7373: if (!print $fh $env{'form.embedded_item_'.$i}) {
7374: &Apache::lonnet::logthis('Failed to write to '.$dest);
7375: $output .= '<span class="LC_error">'.
7376: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7377: '</span><br />';
7378: } else {
7379: if ($context eq 'testbank') {
7380: $output .= &mt('Embedded file uploaded successfully:').
7381: ' <a href="'.$url.'">'.
7382: $orig_uploaded_filename.'</a><br />';
7383: } else {
7384: $output .= '<font size="+2">'.
7385: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7386: $orig_uploaded_filename.'</a>').'</font><br />';
7387: }
7388: }
7389: close($fh);
7390: }
7391: }
7392: }
7393: return $output;
7394: }
7395:
7396: sub check_for_existing {
7397: my ($path,$fname,$element) = @_;
7398: my ($state,$msg);
7399: if (-d $path.'/'.$fname) {
7400: $state = 'exists';
7401: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7402: } elsif (-e $path.'/'.$fname) {
7403: $state = 'exists';
7404: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7405: }
7406: if ($state eq 'exists') {
7407: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7408: }
7409: return ($state,$msg);
7410: }
7411:
7412: sub check_for_upload {
7413: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7414: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7415: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7416: my $getpropath = 1;
7417: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7418: $getpropath);
7419: my $found_file = 0;
7420: my $locked_file = 0;
7421: foreach my $line (@dir_list) {
7422: my ($file_name)=split(/\&/,$line,2);
7423: if ($file_name eq $fname){
7424: $file_name = $path.$file_name;
7425: if ($group ne '') {
7426: $file_name = $group.$file_name;
7427: }
7428: $found_file = 1;
7429: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7430: $locked_file = 1;
7431: }
7432: }
7433: }
7434: if (($current_disk_usage + $filesize) > $disk_quota){
7435: my $msg = '<span class="LC_error">'.
7436: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7437: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7438: return ('will_exceed_quota',$msg);
7439: } elsif ($found_file) {
7440: if ($locked_file) {
7441: my $msg = '<span class="LC_error">';
7442: $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>');
7443: $msg .= '</span><br />';
7444: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7445: return ('file_locked',$msg);
7446: } else {
7447: my $msg = '<span class="LC_error">';
7448: $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'});
7449: $msg .= '</span>';
7450: $msg .= '<br />';
7451: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7452: return ('file_exists',$msg);
7453: }
7454: }
7455: }
7456:
1.31 albertel 7457:
1.41 ng 7458: =pod
1.45 matthew 7459:
1.464 albertel 7460: =back
1.41 ng 7461:
1.112 bowersj2 7462: =head1 CSV Upload/Handling functions
1.38 albertel 7463:
1.41 ng 7464: =over 4
7465:
1.648 raeburn 7466: =item * &upfile_store($r)
1.41 ng 7467:
7468: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7469: needs $env{'form.upfile'}
1.41 ng 7470: returns $datatoken to be put into hidden field
7471:
7472: =cut
1.31 albertel 7473:
7474: sub upfile_store {
7475: my $r=shift;
1.258 albertel 7476: $env{'form.upfile'}=~s/\r/\n/gs;
7477: $env{'form.upfile'}=~s/\f/\n/gs;
7478: $env{'form.upfile'}=~s/\n+/\n/gs;
7479: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7480:
1.258 albertel 7481: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7482: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7483: {
1.158 raeburn 7484: my $datafile = $r->dir_config('lonDaemons').
7485: '/tmp/'.$datatoken.'.tmp';
7486: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7487: print $fh $env{'form.upfile'};
1.158 raeburn 7488: close($fh);
7489: }
1.31 albertel 7490: }
7491: return $datatoken;
7492: }
7493:
1.56 matthew 7494: =pod
7495:
1.648 raeburn 7496: =item * &load_tmp_file($r)
1.41 ng 7497:
7498: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7499: needs $env{'form.datatoken'},
7500: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7501:
7502: =cut
1.31 albertel 7503:
7504: sub load_tmp_file {
7505: my $r=shift;
7506: my @studentdata=();
7507: {
1.158 raeburn 7508: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7509: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7510: if ( open(my $fh,"<$studentfile") ) {
7511: @studentdata=<$fh>;
7512: close($fh);
7513: }
1.31 albertel 7514: }
1.258 albertel 7515: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7516: }
7517:
1.56 matthew 7518: =pod
7519:
1.648 raeburn 7520: =item * &upfile_record_sep()
1.41 ng 7521:
7522: Separate uploaded file into records
7523: returns array of records,
1.258 albertel 7524: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7525:
7526: =cut
1.31 albertel 7527:
7528: sub upfile_record_sep {
1.258 albertel 7529: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7530: } else {
1.248 albertel 7531: my @records;
1.258 albertel 7532: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7533: if ($line=~/^\s*$/) { next; }
7534: push(@records,$line);
7535: }
7536: return @records;
1.31 albertel 7537: }
7538: }
7539:
1.56 matthew 7540: =pod
7541:
1.648 raeburn 7542: =item * &record_sep($record)
1.41 ng 7543:
1.258 albertel 7544: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7545:
7546: =cut
7547:
1.263 www 7548: sub takeleft {
7549: my $index=shift;
7550: return substr('0000'.$index,-4,4);
7551: }
7552:
1.31 albertel 7553: sub record_sep {
7554: my $record=shift;
7555: my %components=();
1.258 albertel 7556: if ($env{'form.upfiletype'} eq 'xml') {
7557: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7558: my $i=0;
1.356 albertel 7559: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7560: $field=~s/^(\"|\')//;
7561: $field=~s/(\"|\')$//;
1.263 www 7562: $components{&takeleft($i)}=$field;
1.31 albertel 7563: $i++;
7564: }
1.258 albertel 7565: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7566: my $i=0;
1.356 albertel 7567: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7568: $field=~s/^(\"|\')//;
7569: $field=~s/(\"|\')$//;
1.263 www 7570: $components{&takeleft($i)}=$field;
1.31 albertel 7571: $i++;
7572: }
7573: } else {
1.561 www 7574: my $separator=',';
1.480 banghart 7575: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7576: $separator=';';
1.480 banghart 7577: }
1.31 albertel 7578: my $i=0;
1.561 www 7579: # the character we are looking for to indicate the end of a quote or a record
7580: my $looking_for=$separator;
7581: # do not add the characters to the fields
7582: my $ignore=0;
7583: # we just encountered a separator (or the beginning of the record)
7584: my $just_found_separator=1;
7585: # store the field we are working on here
7586: my $field='';
7587: # work our way through all characters in record
7588: foreach my $character ($record=~/(.)/g) {
7589: if ($character eq $looking_for) {
7590: if ($character ne $separator) {
7591: # Found the end of a quote, again looking for separator
7592: $looking_for=$separator;
7593: $ignore=1;
7594: } else {
7595: # Found a separator, store away what we got
7596: $components{&takeleft($i)}=$field;
7597: $i++;
7598: $just_found_separator=1;
7599: $ignore=0;
7600: $field='';
7601: }
7602: next;
7603: }
7604: # single or double quotation marks after a separator indicate beginning of a quote
7605: # we are now looking for the end of the quote and need to ignore separators
7606: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7607: $looking_for=$character;
7608: next;
7609: }
7610: # ignore would be true after we reached the end of a quote
7611: if ($ignore) { next; }
7612: if (($just_found_separator) && ($character=~/\s/)) { next; }
7613: $field.=$character;
7614: $just_found_separator=0;
1.31 albertel 7615: }
1.561 www 7616: # catch the very last entry, since we never encountered the separator
7617: $components{&takeleft($i)}=$field;
1.31 albertel 7618: }
7619: return %components;
7620: }
7621:
1.144 matthew 7622: ######################################################
7623: ######################################################
7624:
1.56 matthew 7625: =pod
7626:
1.648 raeburn 7627: =item * &upfile_select_html()
1.41 ng 7628:
1.144 matthew 7629: Return HTML code to select a file from the users machine and specify
7630: the file type.
1.41 ng 7631:
7632: =cut
7633:
1.144 matthew 7634: ######################################################
7635: ######################################################
1.31 albertel 7636: sub upfile_select_html {
1.144 matthew 7637: my %Types = (
7638: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7639: semisv => &mt('Semicolon separated values'),
1.144 matthew 7640: space => &mt('Space separated'),
7641: tab => &mt('Tabulator separated'),
7642: # xml => &mt('HTML/XML'),
7643: );
7644: my $Str = '<input type="file" name="upfile" size="50" />'.
7645: '<br />Type: <select name="upfiletype">';
7646: foreach my $type (sort(keys(%Types))) {
7647: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7648: }
7649: $Str .= "</select>\n";
7650: return $Str;
1.31 albertel 7651: }
7652:
1.301 albertel 7653: sub get_samples {
7654: my ($records,$toget) = @_;
7655: my @samples=({});
7656: my $got=0;
7657: foreach my $rec (@$records) {
7658: my %temp = &record_sep($rec);
7659: if (! grep(/\S/, values(%temp))) { next; }
7660: if (%temp) {
7661: $samples[$got]=\%temp;
7662: $got++;
7663: if ($got == $toget) { last; }
7664: }
7665: }
7666: return \@samples;
7667: }
7668:
1.144 matthew 7669: ######################################################
7670: ######################################################
7671:
1.56 matthew 7672: =pod
7673:
1.648 raeburn 7674: =item * &csv_print_samples($r,$records)
1.41 ng 7675:
7676: Prints a table of sample values from each column uploaded $r is an
7677: Apache Request ref, $records is an arrayref from
7678: &Apache::loncommon::upfile_record_sep
7679:
7680: =cut
7681:
1.144 matthew 7682: ######################################################
7683: ######################################################
1.31 albertel 7684: sub csv_print_samples {
7685: my ($r,$records) = @_;
1.662 bisitz 7686: my $samples = &get_samples($records,5);
1.301 albertel 7687:
1.594 raeburn 7688: $r->print(&mt('Samples').'<br />'.&start_data_table().
7689: &start_data_table_header_row());
1.356 albertel 7690: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7691: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 7692: $r->print(&end_data_table_header_row());
1.301 albertel 7693: foreach my $hash (@$samples) {
1.594 raeburn 7694: $r->print(&start_data_table_row());
1.356 albertel 7695: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7696: $r->print('<td>');
1.356 albertel 7697: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 7698: $r->print('</td>');
7699: }
1.594 raeburn 7700: $r->print(&end_data_table_row());
1.31 albertel 7701: }
1.594 raeburn 7702: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 7703: }
7704:
1.144 matthew 7705: ######################################################
7706: ######################################################
7707:
1.56 matthew 7708: =pod
7709:
1.648 raeburn 7710: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 7711:
7712: Prints a table to create associations between values and table columns.
1.144 matthew 7713:
1.41 ng 7714: $r is an Apache Request ref,
7715: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7716: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7717:
7718: =cut
7719:
1.144 matthew 7720: ######################################################
7721: ######################################################
1.31 albertel 7722: sub csv_print_select_table {
7723: my ($r,$records,$d) = @_;
1.301 albertel 7724: my $i=0;
7725: my $samples = &get_samples($records,1);
1.144 matthew 7726: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7727: &start_data_table().&start_data_table_header_row().
1.144 matthew 7728: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7729: '<th>'.&mt('Column').'</th>'.
7730: &end_data_table_header_row()."\n");
1.356 albertel 7731: foreach my $array_ref (@$d) {
7732: my ($value,$display,$defaultcol)=@{ $array_ref };
1.689 bisitz 7733: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 7734:
7735: $r->print('<td><select name=f'.$i.
1.32 matthew 7736: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7737: $r->print('<option value="none"></option>');
1.356 albertel 7738: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7739: $r->print('<option value="'.$sample.'"'.
7740: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 7741: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 7742: }
1.594 raeburn 7743: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7744: $i++;
7745: }
1.594 raeburn 7746: $r->print(&end_data_table());
1.31 albertel 7747: $i--;
7748: return $i;
7749: }
1.56 matthew 7750:
1.144 matthew 7751: ######################################################
7752: ######################################################
7753:
1.56 matthew 7754: =pod
1.31 albertel 7755:
1.648 raeburn 7756: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 7757:
7758: Prints a table of sample values from the upload and can make associate samples to internal names.
7759:
7760: $r is an Apache Request ref,
7761: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7762: $d is an array of 2 element arrays (internal name, displayed name)
7763:
7764: =cut
7765:
1.144 matthew 7766: ######################################################
7767: ######################################################
1.31 albertel 7768: sub csv_samples_select_table {
7769: my ($r,$records,$d) = @_;
7770: my $i=0;
1.144 matthew 7771: #
1.662 bisitz 7772: my $max_samples = 5;
7773: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 7774: $r->print(&start_data_table().
7775: &start_data_table_header_row().'<th>'.
7776: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7777: &end_data_table_header_row());
1.301 albertel 7778:
7779: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7780: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7781: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7782: foreach my $option (@$d) {
7783: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7784: $r->print('<option value="'.$value.'"'.
1.253 albertel 7785: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7786: $display.'</option>');
1.31 albertel 7787: }
7788: $r->print('</select></td><td>');
1.662 bisitz 7789: foreach my $line (0..($max_samples-1)) {
1.301 albertel 7790: if (defined($samples->[$line]{$key})) {
7791: $r->print($samples->[$line]{$key}."<br />\n");
7792: }
7793: }
1.594 raeburn 7794: $r->print('</td>'.&end_data_table_row());
1.31 albertel 7795: $i++;
7796: }
1.594 raeburn 7797: $r->print(&end_data_table());
1.31 albertel 7798: $i--;
7799: return($i);
1.115 matthew 7800: }
7801:
1.144 matthew 7802: ######################################################
7803: ######################################################
7804:
1.115 matthew 7805: =pod
7806:
1.648 raeburn 7807: =item * &clean_excel_name($name)
1.115 matthew 7808:
7809: Returns a replacement for $name which does not contain any illegal characters.
7810:
7811: =cut
7812:
1.144 matthew 7813: ######################################################
7814: ######################################################
1.115 matthew 7815: sub clean_excel_name {
7816: my ($name) = @_;
7817: $name =~ s/[:\*\?\/\\]//g;
7818: if (length($name) > 31) {
7819: $name = substr($name,0,31);
7820: }
7821: return $name;
1.25 albertel 7822: }
1.84 albertel 7823:
1.85 albertel 7824: =pod
7825:
1.648 raeburn 7826: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 7827:
7828: Returns either 1 or undef
7829:
7830: 1 if the part is to be hidden, undef if it is to be shown
7831:
7832: Arguments are:
7833:
7834: $id the id of the part to be checked
7835: $symb, optional the symb of the resource to check
7836: $udom, optional the domain of the user to check for
7837: $uname, optional the username of the user to check for
7838:
7839: =cut
1.84 albertel 7840:
7841: sub check_if_partid_hidden {
7842: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 7843: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 7844: $symb,$udom,$uname);
1.141 albertel 7845: my $truth=1;
7846: #if the string starts with !, then the list is the list to show not hide
7847: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 7848: my @hiddenlist=split(/,/,$hiddenparts);
7849: foreach my $checkid (@hiddenlist) {
1.141 albertel 7850: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 7851: }
1.141 albertel 7852: return !$truth;
1.84 albertel 7853: }
1.127 matthew 7854:
1.138 matthew 7855:
7856: ############################################################
7857: ############################################################
7858:
7859: =pod
7860:
1.157 matthew 7861: =back
7862:
1.138 matthew 7863: =head1 cgi-bin script and graphing routines
7864:
1.157 matthew 7865: =over 4
7866:
1.648 raeburn 7867: =item * &get_cgi_id()
1.138 matthew 7868:
7869: Inputs: none
7870:
7871: Returns an id which can be used to pass environment variables
7872: to various cgi-bin scripts. These environment variables will
7873: be removed from the users environment after a given time by
7874: the routine &Apache::lonnet::transfer_profile_to_env.
7875:
7876: =cut
7877:
7878: ############################################################
7879: ############################################################
1.152 albertel 7880: my $uniq=0;
1.136 matthew 7881: sub get_cgi_id {
1.154 albertel 7882: $uniq=($uniq+1)%100000;
1.280 albertel 7883: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 7884: }
7885:
1.127 matthew 7886: ############################################################
7887: ############################################################
7888:
7889: =pod
7890:
1.648 raeburn 7891: =item * &DrawBarGraph()
1.127 matthew 7892:
1.138 matthew 7893: Facilitates the plotting of data in a (stacked) bar graph.
7894: Puts plot definition data into the users environment in order for
7895: graph.png to plot it. Returns an <img> tag for the plot.
7896: The bars on the plot are labeled '1','2',...,'n'.
7897:
7898: Inputs:
7899:
7900: =over 4
7901:
7902: =item $Title: string, the title of the plot
7903:
7904: =item $xlabel: string, text describing the X-axis of the plot
7905:
7906: =item $ylabel: string, text describing the Y-axis of the plot
7907:
7908: =item $Max: scalar, the maximum Y value to use in the plot
7909: If $Max is < any data point, the graph will not be rendered.
7910:
1.140 matthew 7911: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 7912: they are plotted. If undefined, default values will be used.
7913:
1.178 matthew 7914: =item $labels: array ref holding the labels to use on the x-axis for the bars.
7915:
1.138 matthew 7916: =item @Values: An array of array references. Each array reference holds data
7917: to be plotted in a stacked bar chart.
7918:
1.239 matthew 7919: =item If the final element of @Values is a hash reference the key/value
7920: pairs will be added to the graph definition.
7921:
1.138 matthew 7922: =back
7923:
7924: Returns:
7925:
7926: An <img> tag which references graph.png and the appropriate identifying
7927: information for the plot.
7928:
1.127 matthew 7929: =cut
7930:
7931: ############################################################
7932: ############################################################
1.134 matthew 7933: sub DrawBarGraph {
1.178 matthew 7934: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 7935: #
7936: if (! defined($colors)) {
7937: $colors = ['#33ff00',
7938: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
7939: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
7940: ];
7941: }
1.228 matthew 7942: my $extra_settings = {};
7943: if (ref($Values[-1]) eq 'HASH') {
7944: $extra_settings = pop(@Values);
7945: }
1.127 matthew 7946: #
1.136 matthew 7947: my $identifier = &get_cgi_id();
7948: my $id = 'cgi.'.$identifier;
1.129 matthew 7949: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 7950: return '';
7951: }
1.225 matthew 7952: #
7953: my @Labels;
7954: if (defined($labels)) {
7955: @Labels = @$labels;
7956: } else {
7957: for (my $i=0;$i<@{$Values[0]};$i++) {
7958: push (@Labels,$i+1);
7959: }
7960: }
7961: #
1.129 matthew 7962: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 7963: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 7964: my %ValuesHash;
7965: my $NumSets=1;
7966: foreach my $array (@Values) {
7967: next if (! ref($array));
1.136 matthew 7968: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 7969: join(',',@$array);
1.129 matthew 7970: }
1.127 matthew 7971: #
1.136 matthew 7972: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 7973: if ($NumBars < 3) {
7974: $width = 120+$NumBars*32;
1.220 matthew 7975: $xskip = 1;
1.225 matthew 7976: $bar_width = 30;
7977: } elsif ($NumBars < 5) {
7978: $width = 120+$NumBars*20;
7979: $xskip = 1;
7980: $bar_width = 20;
1.220 matthew 7981: } elsif ($NumBars < 10) {
1.136 matthew 7982: $width = 120+$NumBars*15;
7983: $xskip = 1;
7984: $bar_width = 15;
7985: } elsif ($NumBars <= 25) {
7986: $width = 120+$NumBars*11;
7987: $xskip = 5;
7988: $bar_width = 8;
7989: } elsif ($NumBars <= 50) {
7990: $width = 120+$NumBars*8;
7991: $xskip = 5;
7992: $bar_width = 4;
7993: } else {
7994: $width = 120+$NumBars*8;
7995: $xskip = 5;
7996: $bar_width = 4;
7997: }
7998: #
1.137 matthew 7999: $Max = 1 if ($Max < 1);
8000: if ( int($Max) < $Max ) {
8001: $Max++;
8002: $Max = int($Max);
8003: }
1.127 matthew 8004: $Title = '' if (! defined($Title));
8005: $xlabel = '' if (! defined($xlabel));
8006: $ylabel = '' if (! defined($ylabel));
1.369 www 8007: $ValuesHash{$id.'.title'} = &escape($Title);
8008: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8009: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8010: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8011: $ValuesHash{$id.'.NumBars'} = $NumBars;
8012: $ValuesHash{$id.'.NumSets'} = $NumSets;
8013: $ValuesHash{$id.'.PlotType'} = 'bar';
8014: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8015: $ValuesHash{$id.'.height'} = $height;
8016: $ValuesHash{$id.'.width'} = $width;
8017: $ValuesHash{$id.'.xskip'} = $xskip;
8018: $ValuesHash{$id.'.bar_width'} = $bar_width;
8019: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8020: #
1.228 matthew 8021: # Deal with other parameters
8022: while (my ($key,$value) = each(%$extra_settings)) {
8023: $ValuesHash{$id.'.'.$key} = $value;
8024: }
8025: #
1.646 raeburn 8026: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8027: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8028: }
8029:
8030: ############################################################
8031: ############################################################
8032:
8033: =pod
8034:
1.648 raeburn 8035: =item * &DrawXYGraph()
1.137 matthew 8036:
1.138 matthew 8037: Facilitates the plotting of data in an XY graph.
8038: Puts plot definition data into the users environment in order for
8039: graph.png to plot it. Returns an <img> tag for the plot.
8040:
8041: Inputs:
8042:
8043: =over 4
8044:
8045: =item $Title: string, the title of the plot
8046:
8047: =item $xlabel: string, text describing the X-axis of the plot
8048:
8049: =item $ylabel: string, text describing the Y-axis of the plot
8050:
8051: =item $Max: scalar, the maximum Y value to use in the plot
8052: If $Max is < any data point, the graph will not be rendered.
8053:
8054: =item $colors: Array ref containing the hex color codes for the data to be
8055: plotted in. If undefined, default values will be used.
8056:
8057: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8058:
8059: =item $Ydata: Array ref containing Array refs.
1.185 www 8060: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8061:
8062: =item %Values: hash indicating or overriding any default values which are
8063: passed to graph.png.
8064: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8065:
8066: =back
8067:
8068: Returns:
8069:
8070: An <img> tag which references graph.png and the appropriate identifying
8071: information for the plot.
8072:
1.137 matthew 8073: =cut
8074:
8075: ############################################################
8076: ############################################################
8077: sub DrawXYGraph {
8078: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8079: #
8080: # Create the identifier for the graph
8081: my $identifier = &get_cgi_id();
8082: my $id = 'cgi.'.$identifier;
8083: #
8084: $Title = '' if (! defined($Title));
8085: $xlabel = '' if (! defined($xlabel));
8086: $ylabel = '' if (! defined($ylabel));
8087: my %ValuesHash =
8088: (
1.369 www 8089: $id.'.title' => &escape($Title),
8090: $id.'.xlabel' => &escape($xlabel),
8091: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8092: $id.'.y_max_value'=> $Max,
8093: $id.'.labels' => join(',',@$Xlabels),
8094: $id.'.PlotType' => 'XY',
8095: );
8096: #
8097: if (defined($colors) && ref($colors) eq 'ARRAY') {
8098: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8099: }
8100: #
8101: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8102: return '';
8103: }
8104: my $NumSets=1;
1.138 matthew 8105: foreach my $array (@{$Ydata}){
1.137 matthew 8106: next if (! ref($array));
8107: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8108: }
1.138 matthew 8109: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8110: #
8111: # Deal with other parameters
8112: while (my ($key,$value) = each(%Values)) {
8113: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8114: }
8115: #
1.646 raeburn 8116: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8117: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8118: }
8119:
8120: ############################################################
8121: ############################################################
8122:
8123: =pod
8124:
1.648 raeburn 8125: =item * &DrawXYYGraph()
1.138 matthew 8126:
8127: Facilitates the plotting of data in an XY graph with two Y axes.
8128: Puts plot definition data into the users environment in order for
8129: graph.png to plot it. Returns an <img> tag for the plot.
8130:
8131: Inputs:
8132:
8133: =over 4
8134:
8135: =item $Title: string, the title of the plot
8136:
8137: =item $xlabel: string, text describing the X-axis of the plot
8138:
8139: =item $ylabel: string, text describing the Y-axis of the plot
8140:
8141: =item $colors: Array ref containing the hex color codes for the data to be
8142: plotted in. If undefined, default values will be used.
8143:
8144: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8145:
8146: =item $Ydata1: The first data set
8147:
8148: =item $Min1: The minimum value of the left Y-axis
8149:
8150: =item $Max1: The maximum value of the left Y-axis
8151:
8152: =item $Ydata2: The second data set
8153:
8154: =item $Min2: The minimum value of the right Y-axis
8155:
8156: =item $Max2: The maximum value of the left Y-axis
8157:
8158: =item %Values: hash indicating or overriding any default values which are
8159: passed to graph.png.
8160: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8161:
8162: =back
8163:
8164: Returns:
8165:
8166: An <img> tag which references graph.png and the appropriate identifying
8167: information for the plot.
1.136 matthew 8168:
8169: =cut
8170:
8171: ############################################################
8172: ############################################################
1.137 matthew 8173: sub DrawXYYGraph {
8174: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8175: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8176: #
8177: # Create the identifier for the graph
8178: my $identifier = &get_cgi_id();
8179: my $id = 'cgi.'.$identifier;
8180: #
8181: $Title = '' if (! defined($Title));
8182: $xlabel = '' if (! defined($xlabel));
8183: $ylabel = '' if (! defined($ylabel));
8184: my %ValuesHash =
8185: (
1.369 www 8186: $id.'.title' => &escape($Title),
8187: $id.'.xlabel' => &escape($xlabel),
8188: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8189: $id.'.labels' => join(',',@$Xlabels),
8190: $id.'.PlotType' => 'XY',
8191: $id.'.NumSets' => 2,
1.137 matthew 8192: $id.'.two_axes' => 1,
8193: $id.'.y1_max_value' => $Max1,
8194: $id.'.y1_min_value' => $Min1,
8195: $id.'.y2_max_value' => $Max2,
8196: $id.'.y2_min_value' => $Min2,
1.136 matthew 8197: );
8198: #
1.137 matthew 8199: if (defined($colors) && ref($colors) eq 'ARRAY') {
8200: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8201: }
8202: #
8203: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8204: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8205: return '';
8206: }
8207: my $NumSets=1;
1.137 matthew 8208: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8209: next if (! ref($array));
8210: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8211: }
8212: #
8213: # Deal with other parameters
8214: while (my ($key,$value) = each(%Values)) {
8215: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8216: }
8217: #
1.646 raeburn 8218: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8219: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8220: }
8221:
8222: ############################################################
8223: ############################################################
8224:
8225: =pod
8226:
1.157 matthew 8227: =back
8228:
1.139 matthew 8229: =head1 Statistics helper routines?
8230:
8231: Bad place for them but what the hell.
8232:
1.157 matthew 8233: =over 4
8234:
1.648 raeburn 8235: =item * &chartlink()
1.139 matthew 8236:
8237: Returns a link to the chart for a specific student.
8238:
8239: Inputs:
8240:
8241: =over 4
8242:
8243: =item $linktext: The text of the link
8244:
8245: =item $sname: The students username
8246:
8247: =item $sdomain: The students domain
8248:
8249: =back
8250:
1.157 matthew 8251: =back
8252:
1.139 matthew 8253: =cut
8254:
8255: ############################################################
8256: ############################################################
8257: sub chartlink {
8258: my ($linktext, $sname, $sdomain) = @_;
8259: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8260: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8261: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8262: '">'.$linktext.'</a>';
1.153 matthew 8263: }
8264:
8265: #######################################################
8266: #######################################################
8267:
8268: =pod
8269:
8270: =head1 Course Environment Routines
1.157 matthew 8271:
8272: =over 4
1.153 matthew 8273:
1.648 raeburn 8274: =item * &restore_course_settings()
1.153 matthew 8275:
1.648 raeburn 8276: =item * &store_course_settings()
1.153 matthew 8277:
8278: Restores/Store indicated form parameters from the course environment.
8279: Will not overwrite existing values of the form parameters.
8280:
8281: Inputs:
8282: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8283:
8284: a hash ref describing the data to be stored. For example:
8285:
8286: %Save_Parameters = ('Status' => 'scalar',
8287: 'chartoutputmode' => 'scalar',
8288: 'chartoutputdata' => 'scalar',
8289: 'Section' => 'array',
1.373 raeburn 8290: 'Group' => 'array',
1.153 matthew 8291: 'StudentData' => 'array',
8292: 'Maps' => 'array');
8293:
8294: Returns: both routines return nothing
8295:
1.631 raeburn 8296: =back
8297:
1.153 matthew 8298: =cut
8299:
8300: #######################################################
8301: #######################################################
8302: sub store_course_settings {
1.496 albertel 8303: return &store_settings($env{'request.course.id'},@_);
8304: }
8305:
8306: sub store_settings {
1.153 matthew 8307: # save to the environment
8308: # appenv the same items, just to be safe
1.300 albertel 8309: my $udom = $env{'user.domain'};
8310: my $uname = $env{'user.name'};
1.496 albertel 8311: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8312: my %SaveHash;
8313: my %AppHash;
8314: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8315: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8316: my $envname = 'environment.'.$basename;
1.258 albertel 8317: if (exists($env{'form.'.$setting})) {
1.153 matthew 8318: # Save this value away
8319: if ($type eq 'scalar' &&
1.258 albertel 8320: (! exists($env{$envname}) ||
8321: $env{$envname} ne $env{'form.'.$setting})) {
8322: $SaveHash{$basename} = $env{'form.'.$setting};
8323: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8324: } elsif ($type eq 'array') {
8325: my $stored_form;
1.258 albertel 8326: if (ref($env{'form.'.$setting})) {
1.153 matthew 8327: $stored_form = join(',',
8328: map {
1.369 www 8329: &escape($_);
1.258 albertel 8330: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8331: } else {
8332: $stored_form =
1.369 www 8333: &escape($env{'form.'.$setting});
1.153 matthew 8334: }
8335: # Determine if the array contents are the same.
1.258 albertel 8336: if ($stored_form ne $env{$envname}) {
1.153 matthew 8337: $SaveHash{$basename} = $stored_form;
8338: $AppHash{$envname} = $stored_form;
8339: }
8340: }
8341: }
8342: }
8343: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8344: $udom,$uname);
1.153 matthew 8345: if ($put_result !~ /^(ok|delayed)/) {
8346: &Apache::lonnet::logthis('unable to save form parameters, '.
8347: 'got error:'.$put_result);
8348: }
8349: # Make sure these settings stick around in this session, too
1.646 raeburn 8350: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8351: return;
8352: }
8353:
8354: sub restore_course_settings {
1.499 albertel 8355: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8356: }
8357:
8358: sub restore_settings {
8359: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8360: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8361: next if (exists($env{'form.'.$setting}));
1.496 albertel 8362: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8363: '.'.$setting;
1.258 albertel 8364: if (exists($env{$envname})) {
1.153 matthew 8365: if ($type eq 'scalar') {
1.258 albertel 8366: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8367: } elsif ($type eq 'array') {
1.258 albertel 8368: $env{'form.'.$setting} = [
1.153 matthew 8369: map {
1.369 www 8370: &unescape($_);
1.258 albertel 8371: } split(',',$env{$envname})
1.153 matthew 8372: ];
8373: }
8374: }
8375: }
1.127 matthew 8376: }
8377:
1.618 raeburn 8378: #######################################################
8379: #######################################################
8380:
8381: =pod
8382:
8383: =head1 Domain E-mail Routines
8384:
8385: =over 4
8386:
1.648 raeburn 8387: =item * &build_recipient_list()
1.618 raeburn 8388:
8389: Build recipient lists for three types of e-mail:
8390: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8391: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8392:
8393: Inputs:
1.619 raeburn 8394: defmail (scalar - email address of default recipient),
1.618 raeburn 8395: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8396: defdom (domain for which to retrieve configuration settings),
8397: origmail (scalar - email address of recipient from loncapa.conf,
8398: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8399:
1.655 raeburn 8400: Returns: comma separated list of addresses to which to send e-mail.
8401:
8402: =back
1.618 raeburn 8403:
8404: =cut
8405:
8406: ############################################################
8407: ############################################################
8408: sub build_recipient_list {
1.619 raeburn 8409: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8410: my @recipients;
8411: my $otheremails;
8412: my %domconfig =
8413: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8414: if (ref($domconfig{'contacts'}) eq 'HASH') {
8415: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8416: my @contacts = ('adminemail','supportemail');
8417: foreach my $item (@contacts) {
8418: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8419: my $addr = $domconfig{'contacts'}{$item};
8420: if (!grep(/^\Q$addr\E$/,@recipients)) {
8421: push(@recipients,$addr);
8422: }
1.618 raeburn 8423: }
8424: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8425: }
8426: }
1.619 raeburn 8427: } elsif ($origmail ne '') {
8428: push(@recipients,$origmail);
1.618 raeburn 8429: }
1.688 raeburn 8430: if (defined($defmail)) {
8431: if ($defmail ne '') {
8432: push(@recipients,$defmail);
8433: }
1.618 raeburn 8434: }
8435: if ($otheremails) {
1.619 raeburn 8436: my @others;
8437: if ($otheremails =~ /,/) {
8438: @others = split(/,/,$otheremails);
1.618 raeburn 8439: } else {
1.619 raeburn 8440: push(@others,$otheremails);
8441: }
8442: foreach my $addr (@others) {
8443: if (!grep(/^\Q$addr\E$/,@recipients)) {
8444: push(@recipients,$addr);
8445: }
1.618 raeburn 8446: }
8447: }
1.619 raeburn 8448: my $recipientlist = join(',',@recipients);
1.618 raeburn 8449: return $recipientlist;
8450: }
8451:
1.127 matthew 8452: ############################################################
8453: ############################################################
1.154 albertel 8454:
1.655 raeburn 8455: =pod
8456:
8457: =head1 Course Catalog Routines
8458:
8459: =over 4
8460:
8461: =item * &gather_categories()
8462:
8463: Converts category definitions - keys of categories hash stored in
8464: coursecategories in configuration.db on the primary library server in a
8465: domain - to an array. Also generates javascript and idx hash used to
8466: generate Domain Coordinator interface for editing Course Categories.
8467:
8468: Inputs:
1.663 raeburn 8469:
1.655 raeburn 8470: categories (reference to hash of category definitions).
1.663 raeburn 8471:
1.655 raeburn 8472: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8473: categories and subcategories).
1.663 raeburn 8474:
1.655 raeburn 8475: idx (reference to hash of counters used in Domain Coordinator interface for
8476: editing Course Categories).
1.663 raeburn 8477:
1.655 raeburn 8478: jsarray (reference to array of categories used to create Javascript arrays for
8479: Domain Coordinator interface for editing Course Categories).
8480:
8481: Returns: nothing
8482:
8483: Side effects: populates cats, idx and jsarray.
8484:
8485: =cut
8486:
8487: sub gather_categories {
8488: my ($categories,$cats,$idx,$jsarray) = @_;
8489: my %counters;
8490: my $num = 0;
8491: foreach my $item (keys(%{$categories})) {
8492: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8493: if ($container eq '' && $depth == 0) {
8494: $cats->[$depth][$categories->{$item}] = $cat;
8495: } else {
8496: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8497: }
8498: my ($escitem,$tail) = split(/:/,$item,2);
8499: if ($counters{$tail} eq '') {
8500: $counters{$tail} = $num;
8501: $num ++;
8502: }
8503: if (ref($idx) eq 'HASH') {
8504: $idx->{$item} = $counters{$tail};
8505: }
8506: if (ref($jsarray) eq 'ARRAY') {
8507: push(@{$jsarray->[$counters{$tail}]},$item);
8508: }
8509: }
8510: return;
8511: }
8512:
8513: =pod
8514:
8515: =item * &extract_categories()
8516:
8517: Used to generate breadcrumb trails for course categories.
8518:
8519: Inputs:
1.663 raeburn 8520:
1.655 raeburn 8521: categories (reference to hash of category definitions).
1.663 raeburn 8522:
1.655 raeburn 8523: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8524: categories and subcategories).
1.663 raeburn 8525:
1.655 raeburn 8526: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8527:
1.655 raeburn 8528: allitems (reference to hash - key is category key
8529: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8530:
1.655 raeburn 8531: idx (reference to hash of counters used in Domain Coordinator interface for
8532: editing Course Categories).
1.663 raeburn 8533:
1.655 raeburn 8534: jsarray (reference to array of categories used to create Javascript arrays for
8535: Domain Coordinator interface for editing Course Categories).
8536:
1.665 raeburn 8537: subcats (reference to hash of arrays containing all subcategories within each
8538: category, -recursive)
8539:
1.655 raeburn 8540: Returns: nothing
8541:
8542: Side effects: populates trails and allitems hash references.
8543:
8544: =cut
8545:
8546: sub extract_categories {
1.665 raeburn 8547: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8548: if (ref($categories) eq 'HASH') {
8549: &gather_categories($categories,$cats,$idx,$jsarray);
8550: if (ref($cats->[0]) eq 'ARRAY') {
8551: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8552: my $name = $cats->[0][$i];
8553: my $item = &escape($name).'::0';
8554: my $trailstr;
8555: if ($name eq 'instcode') {
8556: $trailstr = &mt('Official courses (with institutional codes)');
8557: } else {
8558: $trailstr = $name;
8559: }
8560: if ($allitems->{$item} eq '') {
8561: push(@{$trails},$trailstr);
8562: $allitems->{$item} = scalar(@{$trails})-1;
8563: }
8564: my @parents = ($name);
8565: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8566: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8567: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8568: if (ref($subcats) eq 'HASH') {
8569: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8570: }
8571: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8572: }
8573: } else {
8574: if (ref($subcats) eq 'HASH') {
8575: $subcats->{$item} = [];
1.655 raeburn 8576: }
8577: }
8578: }
8579: }
8580: }
8581: return;
8582: }
8583:
8584: =pod
8585:
8586: =item *&recurse_categories()
8587:
8588: Recursively used to generate breadcrumb trails for course categories.
8589:
8590: Inputs:
1.663 raeburn 8591:
1.655 raeburn 8592: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8593: categories and subcategories).
1.663 raeburn 8594:
1.655 raeburn 8595: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8596:
8597: category (current course category, for which breadcrumb trail is being generated).
8598:
8599: trails (reference to array of breadcrumb trails for each category).
8600:
1.655 raeburn 8601: allitems (reference to hash - key is category key
8602: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8603:
1.655 raeburn 8604: parents (array containing containers directories for current category,
8605: back to top level).
8606:
8607: Returns: nothing
8608:
8609: Side effects: populates trails and allitems hash references
8610:
8611: =cut
8612:
8613: sub recurse_categories {
1.665 raeburn 8614: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8615: my $shallower = $depth - 1;
8616: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8617: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8618: my $name = $cats->[$depth]{$category}[$k];
8619: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8620: my $trailstr = join(' -> ',(@{$parents},$category));
8621: if ($allitems->{$item} eq '') {
8622: push(@{$trails},$trailstr);
8623: $allitems->{$item} = scalar(@{$trails})-1;
8624: }
8625: my $deeper = $depth+1;
8626: push(@{$parents},$category);
1.665 raeburn 8627: if (ref($subcats) eq 'HASH') {
8628: my $subcat = &escape($name).':'.$category.':'.$depth;
8629: for (my $j=@{$parents}; $j>=0; $j--) {
8630: my $higher;
8631: if ($j > 0) {
8632: $higher = &escape($parents->[$j]).':'.
8633: &escape($parents->[$j-1]).':'.$j;
8634: } else {
8635: $higher = &escape($parents->[$j]).'::'.$j;
8636: }
8637: push(@{$subcats->{$higher}},$subcat);
8638: }
8639: }
8640: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8641: $subcats);
1.655 raeburn 8642: pop(@{$parents});
8643: }
8644: } else {
8645: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8646: my $trailstr = join(' -> ',(@{$parents},$category));
8647: if ($allitems->{$item} eq '') {
8648: push(@{$trails},$trailstr);
8649: $allitems->{$item} = scalar(@{$trails})-1;
8650: }
8651: }
8652: return;
8653: }
8654:
1.663 raeburn 8655: =pod
8656:
8657: =item *&assign_categories_table()
8658:
8659: Create a datatable for display of hierarchical categories in a domain,
8660: with checkboxes to allow a course to be categorized.
8661:
8662: Inputs:
8663:
8664: cathash - reference to hash of categories defined for the domain (from
8665: configuration.db)
8666:
8667: currcat - scalar with an & separated list of categories assigned to a course.
8668:
8669: Returns: $output (markup to be displayed)
8670:
8671: =cut
8672:
8673: sub assign_categories_table {
8674: my ($cathash,$currcat) = @_;
8675: my $output;
8676: if (ref($cathash) eq 'HASH') {
8677: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
8678: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
8679: $maxdepth = scalar(@cats);
8680: if (@cats > 0) {
8681: my $itemcount = 0;
8682: if (ref($cats[0]) eq 'ARRAY') {
8683: $output = &Apache::loncommon::start_data_table();
8684: my @currcategories;
8685: if ($currcat ne '') {
8686: @currcategories = split('&',$currcat);
8687: }
8688: for (my $i=0; $i<@{$cats[0]}; $i++) {
8689: my $parent = $cats[0][$i];
8690: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8691: next if ($parent eq 'instcode');
8692: my $item = &escape($parent).'::0';
8693: my $checked = '';
8694: if (@currcategories > 0) {
8695: if (grep(/^\Q$item\E$/,@currcategories)) {
8696: $checked = ' checked="checked" ';
8697: }
8698: }
1.675 raeburn 8699: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
8700: '<input type="checkbox" name="usecategory" value="'.
8701: $item.'"'.$checked.' />'.$parent.'</span>'.
8702: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 8703: my $depth = 1;
8704: push(@path,$parent);
8705: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
8706: pop(@path);
8707: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8708: $itemcount ++;
8709: }
8710: $output .= &Apache::loncommon::end_data_table();
8711: }
8712: }
8713: }
8714: return $output;
8715: }
8716:
8717: =pod
8718:
8719: =item *&assign_category_rows()
8720:
8721: Create a datatable row for display of nested categories in a domain,
8722: with checkboxes to allow a course to be categorized,called recursively.
8723:
8724: Inputs:
8725:
8726: itemcount - track row number for alternating colors
8727:
8728: cats - reference to array of arrays/hashes which encapsulates hierarchy of
8729: categories and subcategories.
8730:
8731: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
8732:
8733: parent - parent of current category item
8734:
8735: path - Array containing all categories back up through the hierarchy from the
8736: current category to the top level.
8737:
8738: currcategories - reference to array of current categories assigned to the course
8739:
8740: Returns: $output (markup to be displayed).
8741:
8742: =cut
8743:
8744: sub assign_category_rows {
8745: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
8746: my ($text,$name,$item,$chgstr);
8747: if (ref($cats) eq 'ARRAY') {
8748: my $maxdepth = scalar(@{$cats});
8749: if (ref($cats->[$depth]) eq 'HASH') {
8750: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8751: my $numchildren = @{$cats->[$depth]{$parent}};
8752: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8753: $text .= '<td><table class="LC_datatable">';
8754: for (my $j=0; $j<$numchildren; $j++) {
8755: $name = $cats->[$depth]{$parent}[$j];
8756: $item = &escape($name).':'.&escape($parent).':'.$depth;
8757: my $deeper = $depth+1;
8758: my $checked = '';
8759: if (ref($currcategories) eq 'ARRAY') {
8760: if (@{$currcategories} > 0) {
8761: if (grep(/^\Q$item\E$/,@{$currcategories})) {
8762: $checked = ' checked="checked" ';
8763: }
8764: }
8765: }
1.664 raeburn 8766: $text .= '<tr><td><span class="LC_nobreak"><label>'.
8767: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 8768: $item.'"'.$checked.' />'.$name.'</label></span>'.
8769: '<input type="hidden" name="catname" value="'.$name.'" />'.
8770: '</td><td>';
1.663 raeburn 8771: if (ref($path) eq 'ARRAY') {
8772: push(@{$path},$name);
8773: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
8774: pop(@{$path});
8775: }
8776: $text .= '</td></tr>';
8777: }
8778: $text .= '</table></td>';
8779: }
8780: }
8781: }
8782: return $text;
8783: }
8784:
1.655 raeburn 8785: ############################################################
8786: ############################################################
8787:
8788:
1.443 albertel 8789: sub commit_customrole {
1.664 raeburn 8790: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 8791: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 8792: ($start?', '.&mt('starting').' '.localtime($start):'').
8793: ($end?', ending '.localtime($end):'').': <b>'.
8794: &Apache::lonnet::assigncustomrole(
1.664 raeburn 8795: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 8796: '</b><br />';
8797: return $output;
8798: }
8799:
8800: sub commit_standardrole {
1.541 raeburn 8801: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
8802: my ($output,$logmsg,$linefeed);
8803: if ($context eq 'auto') {
8804: $linefeed = "\n";
8805: } else {
8806: $linefeed = "<br />\n";
8807: }
1.443 albertel 8808: if ($three eq 'st') {
1.541 raeburn 8809: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
8810: $one,$two,$sec,$context);
8811: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 8812: ($result eq 'unknown_course') || ($result eq 'refused')) {
8813: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 8814: } else {
1.541 raeburn 8815: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 8816: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 8817: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
8818: if ($context eq 'auto') {
8819: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
8820: } else {
8821: $output .= '<b>'.$result.'</b>'.$linefeed.
8822: &mt('Add to classlist').': <b>ok</b>';
8823: }
8824: $output .= $linefeed;
1.443 albertel 8825: }
8826: } else {
8827: $output = &mt('Assigning').' '.$three.' in '.$url.
8828: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 8829: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 8830: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 8831: if ($context eq 'auto') {
8832: $output .= $result.$linefeed;
8833: } else {
8834: $output .= '<b>'.$result.'</b>'.$linefeed;
8835: }
1.443 albertel 8836: }
8837: return $output;
8838: }
8839:
8840: sub commit_studentrole {
1.541 raeburn 8841: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 8842: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 8843: if ($context eq 'auto') {
8844: $linefeed = "\n";
8845: } else {
8846: $linefeed = '<br />'."\n";
8847: }
1.443 albertel 8848: if (defined($one) && defined($two)) {
8849: my $cid=$one.'_'.$two;
8850: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
8851: my $secchange = 0;
8852: my $expire_role_result;
8853: my $modify_section_result;
1.628 raeburn 8854: if ($oldsec ne '-1') {
8855: if ($oldsec ne $sec) {
1.443 albertel 8856: $secchange = 1;
1.628 raeburn 8857: my $now = time;
1.443 albertel 8858: my $uurl='/'.$cid;
8859: $uurl=~s/\_/\//g;
8860: if ($oldsec) {
8861: $uurl.='/'.$oldsec;
8862: }
1.626 raeburn 8863: $oldsecurl = $uurl;
1.628 raeburn 8864: $expire_role_result =
1.652 raeburn 8865: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 8866: if ($env{'request.course.sec'} ne '') {
8867: if ($expire_role_result eq 'refused') {
8868: my @roles = ('st');
8869: my @statuses = ('previous');
8870: my @roledoms = ($one);
8871: my $withsec = 1;
8872: my %roleshash =
8873: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
8874: \@statuses,\@roles,\@roledoms,$withsec);
8875: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
8876: my ($oldstart,$oldend) =
8877: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
8878: if ($oldend > 0 && $oldend <= $now) {
8879: $expire_role_result = 'ok';
8880: }
8881: }
8882: }
8883: }
1.443 albertel 8884: $result = $expire_role_result;
8885: }
8886: }
8887: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 8888: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 8889: if ($modify_section_result =~ /^ok/) {
8890: if ($secchange == 1) {
1.628 raeburn 8891: if ($sec eq '') {
8892: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
8893: } else {
8894: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
8895: }
1.443 albertel 8896: } elsif ($oldsec eq '-1') {
1.628 raeburn 8897: if ($sec eq '') {
8898: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
8899: } else {
8900: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8901: }
1.443 albertel 8902: } else {
1.628 raeburn 8903: if ($sec eq '') {
8904: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
8905: } else {
8906: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8907: }
1.443 albertel 8908: }
8909: } else {
1.628 raeburn 8910: if ($secchange) {
8911: $$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;
8912: } else {
8913: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
8914: }
1.443 albertel 8915: }
8916: $result = $modify_section_result;
8917: } elsif ($secchange == 1) {
1.628 raeburn 8918: if ($oldsec eq '') {
8919: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
8920: } else {
8921: $$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;
8922: }
1.626 raeburn 8923: if ($expire_role_result eq 'refused') {
8924: my $newsecurl = '/'.$cid;
8925: $newsecurl =~ s/\_/\//g;
8926: if ($sec ne '') {
8927: $newsecurl.='/'.$sec;
8928: }
8929: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
8930: if ($sec eq '') {
8931: $$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;
8932: } else {
8933: $$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;
8934: }
8935: }
8936: }
1.443 albertel 8937: }
8938: } else {
1.626 raeburn 8939: $$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 8940: $result = "error: incomplete course id\n";
8941: }
8942: return $result;
8943: }
8944:
8945: ############################################################
8946: ############################################################
8947:
1.566 albertel 8948: sub check_clone {
1.578 raeburn 8949: my ($args,$linefeed) = @_;
1.566 albertel 8950: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
8951: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
8952: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
8953: my $clonemsg;
8954: my $can_clone = 0;
8955:
8956: if ($clonehome eq 'no_host') {
1.578 raeburn 8957: $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 8958: } else {
8959: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 8960: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 8961: $can_clone = 1;
8962: } else {
8963: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
8964: $args->{'clonedomain'},$args->{'clonecourse'});
8965: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 8966: if (grep(/^\*$/,@cloners)) {
8967: $can_clone = 1;
8968: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
8969: $can_clone = 1;
8970: } else {
8971: my %roleshash =
8972: &Apache::lonnet::get_my_roles($args->{'ccuname'},
8973: $args->{'ccdomain'},
8974: 'userroles',['active'],['cc'],
8975: [$args->{'clonedomain'}]);
8976: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
8977: $can_clone = 1;
8978: } else {
8979: $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'});
8980: }
1.566 albertel 8981: }
1.578 raeburn 8982: }
1.566 albertel 8983: }
8984: return ($can_clone, $clonemsg, $cloneid, $clonehome);
8985: }
8986:
1.444 albertel 8987: sub construct_course {
1.541 raeburn 8988: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 8989: my $outcome;
1.541 raeburn 8990: my $linefeed = '<br />'."\n";
8991: if ($context eq 'auto') {
8992: $linefeed = "\n";
8993: }
1.566 albertel 8994:
8995: #
8996: # Are we cloning?
8997: #
8998: my ($can_clone, $clonemsg, $cloneid, $clonehome);
8999: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9000: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9001: if ($context ne 'auto') {
1.578 raeburn 9002: if ($clonemsg ne '') {
9003: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9004: }
1.566 albertel 9005: }
9006: $outcome .= $clonemsg.$linefeed;
9007:
9008: if (!$can_clone) {
9009: return (0,$outcome);
9010: }
9011: }
9012:
1.444 albertel 9013: #
9014: # Open course
9015: #
9016: my $crstype = lc($args->{'crstype'});
9017: my %cenv=();
9018: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9019: $args->{'cdescr'},
9020: $args->{'curl'},
9021: $args->{'course_home'},
9022: $args->{'nonstandard'},
9023: $args->{'crscode'},
9024: $args->{'ccuname'}.':'.
9025: $args->{'ccdomain'},
9026: $args->{'crstype'});
9027:
9028: # Note: The testing routines depend on this being output; see
9029: # Utils::Course. This needs to at least be output as a comment
9030: # if anyone ever decides to not show this, and Utils::Course::new
9031: # will need to be suitably modified.
1.541 raeburn 9032: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9033: #
9034: # Check if created correctly
9035: #
1.479 albertel 9036: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9037: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9038: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9039:
1.444 albertel 9040: #
1.566 albertel 9041: # Do the cloning
9042: #
9043: if ($can_clone && $cloneid) {
9044: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9045: if ($context ne 'auto') {
9046: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9047: }
9048: $outcome .= $clonemsg.$linefeed;
9049: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9050: # Copy all files
1.637 www 9051: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9052: # Restore URL
1.566 albertel 9053: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9054: # Restore title
1.566 albertel 9055: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9056: # Mark as cloned
1.566 albertel 9057: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9058: # Need to clone grading mode
9059: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9060: $cenv{'grading'}=$newenv{'grading'};
9061: # Do not clone these environment entries
9062: &Apache::lonnet::del('environment',
9063: ['default_enrollment_start_date',
9064: 'default_enrollment_end_date',
9065: 'question.email',
9066: 'policy.email',
9067: 'comment.email',
9068: 'pch.users.denied',
1.692.2.7 raeburn 9069: 'plc.users.denied',
9070: 'hidefromcat',
9071: 'categories'],
1.638 www 9072: $$crsudom,$$crsunum);
1.444 albertel 9073: }
1.566 albertel 9074:
1.444 albertel 9075: #
9076: # Set environment (will override cloned, if existing)
9077: #
9078: my @sections = ();
9079: my @xlists = ();
9080: if ($args->{'crstype'}) {
9081: $cenv{'type'}=$args->{'crstype'};
9082: }
9083: if ($args->{'crsid'}) {
9084: $cenv{'courseid'}=$args->{'crsid'};
9085: }
9086: if ($args->{'crscode'}) {
9087: $cenv{'internal.coursecode'}=$args->{'crscode'};
9088: }
9089: if ($args->{'crsquota'} ne '') {
9090: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9091: } else {
9092: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9093: }
9094: if ($args->{'ccuname'}) {
9095: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9096: ':'.$args->{'ccdomain'};
9097: } else {
9098: $cenv{'internal.courseowner'} = $args->{'curruser'};
9099: }
9100: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9101: if ($args->{'crssections'}) {
9102: $cenv{'internal.sectionnums'} = '';
9103: if ($args->{'crssections'} =~ m/,/) {
9104: @sections = split/,/,$args->{'crssections'};
9105: } else {
9106: $sections[0] = $args->{'crssections'};
9107: }
9108: if (@sections > 0) {
9109: foreach my $item (@sections) {
9110: my ($sec,$gp) = split/:/,$item;
9111: my $class = $args->{'crscode'}.$sec;
9112: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9113: $cenv{'internal.sectionnums'} .= $item.',';
9114: unless ($addcheck eq 'ok') {
9115: push @badclasses, $class;
9116: }
9117: }
9118: $cenv{'internal.sectionnums'} =~ s/,$//;
9119: }
9120: }
9121: # do not hide course coordinator from staff listing,
9122: # even if privileged
9123: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9124: # add crosslistings
9125: if ($args->{'crsxlist'}) {
9126: $cenv{'internal.crosslistings'}='';
9127: if ($args->{'crsxlist'} =~ m/,/) {
9128: @xlists = split/,/,$args->{'crsxlist'};
9129: } else {
9130: $xlists[0] = $args->{'crsxlist'};
9131: }
9132: if (@xlists > 0) {
9133: foreach my $item (@xlists) {
9134: my ($xl,$gp) = split/:/,$item;
9135: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9136: $cenv{'internal.crosslistings'} .= $item.',';
9137: unless ($addcheck eq 'ok') {
9138: push @badclasses, $xl;
9139: }
9140: }
9141: $cenv{'internal.crosslistings'} =~ s/,$//;
9142: }
9143: }
9144: if ($args->{'autoadds'}) {
9145: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9146: }
9147: if ($args->{'autodrops'}) {
9148: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9149: }
9150: # check for notification of enrollment changes
9151: my @notified = ();
9152: if ($args->{'notify_owner'}) {
9153: if ($args->{'ccuname'} ne '') {
9154: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9155: }
9156: }
9157: if ($args->{'notify_dc'}) {
9158: if ($uname ne '') {
1.630 raeburn 9159: push(@notified,$uname.':'.$udom);
1.444 albertel 9160: }
9161: }
9162: if (@notified > 0) {
9163: my $notifylist;
9164: if (@notified > 1) {
9165: $notifylist = join(',',@notified);
9166: } else {
9167: $notifylist = $notified[0];
9168: }
9169: $cenv{'internal.notifylist'} = $notifylist;
9170: }
9171: if (@badclasses > 0) {
9172: my %lt=&Apache::lonlocal::texthash(
9173: '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',
9174: 'dnhr' => 'does not have rights to access enrollment in these classes',
9175: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9176: );
1.541 raeburn 9177: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9178: ' ('.$lt{'adby'}.')';
9179: if ($context eq 'auto') {
9180: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9181: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9182: foreach my $item (@badclasses) {
9183: if ($context eq 'auto') {
9184: $outcome .= " - $item\n";
9185: } else {
9186: $outcome .= "<li>$item</li>\n";
9187: }
9188: }
9189: if ($context eq 'auto') {
9190: $outcome .= $linefeed;
9191: } else {
1.566 albertel 9192: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9193: }
9194: }
1.444 albertel 9195: }
9196: if ($args->{'no_end_date'}) {
9197: $args->{'endaccess'} = 0;
9198: }
9199: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9200: $cenv{'internal.autoend'}=$args->{'enrollend'};
9201: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9202: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9203: if ($args->{'showphotos'}) {
9204: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9205: }
9206: $cenv{'internal.authtype'} = $args->{'authtype'};
9207: $cenv{'internal.autharg'} = $args->{'autharg'};
9208: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9209: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9210: 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');
9211: if ($context eq 'auto') {
9212: $outcome .= $krb_msg;
9213: } else {
1.566 albertel 9214: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9215: }
9216: $outcome .= $linefeed;
1.444 albertel 9217: }
9218: }
9219: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9220: if ($args->{'setpolicy'}) {
9221: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9222: }
9223: if ($args->{'setcontent'}) {
9224: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9225: }
9226: }
9227: if ($args->{'reshome'}) {
9228: $cenv{'reshome'}=$args->{'reshome'}.'/';
9229: $cenv{'reshome'}=~s/\/+$/\//;
9230: }
9231: #
9232: # course has keyed access
9233: #
9234: if ($args->{'setkeys'}) {
9235: $cenv{'keyaccess'}='yes';
9236: }
9237: # if specified, key authority is not course, but user
9238: # only active if keyaccess is yes
9239: if ($args->{'keyauth'}) {
1.487 albertel 9240: my ($user,$domain) = split(':',$args->{'keyauth'});
9241: $user = &LONCAPA::clean_username($user);
9242: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9243: if ($user ne '' && $domain ne '') {
1.487 albertel 9244: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9245: }
9246: }
9247:
9248: if ($args->{'disresdis'}) {
9249: $cenv{'pch.roles.denied'}='st';
9250: }
9251: if ($args->{'disablechat'}) {
9252: $cenv{'plc.roles.denied'}='st';
9253: }
9254:
9255: # Record we've not yet viewed the Course Initialization Helper for this
9256: # course
9257: $cenv{'course.helper.not.run'} = 1;
9258: #
9259: # Use new Randomseed
9260: #
9261: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9262: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9263: #
9264: # The encryption code and receipt prefix for this course
9265: #
9266: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9267: $cenv{'internal.encpref'}=100+int(9*rand(99));
9268: #
9269: # By default, use standard grading
9270: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9271:
1.541 raeburn 9272: $outcome .= $linefeed.&mt('Setting environment').': '.
9273: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9274: #
9275: # Open all assignments
9276: #
9277: if ($args->{'openall'}) {
9278: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9279: my %storecontent = ($storeunder => time,
9280: $storeunder.'.type' => 'date_start');
9281:
9282: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9283: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9284: }
9285: #
9286: # Set first page
9287: #
9288: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9289: || ($cloneid)) {
1.445 albertel 9290: use LONCAPA::map;
1.444 albertel 9291: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9292:
9293: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9294: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9295:
1.444 albertel 9296: $outcome .= ($fatal?$errtext:'read ok').' - ';
9297: my $title; my $url;
9298: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9299: $title=&mt('Syllabus');
1.444 albertel 9300: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9301: } else {
1.690 bisitz 9302: $title=&mt('Navigate Contents');
1.444 albertel 9303: $url='/adm/navmaps';
9304: }
1.445 albertel 9305:
9306: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9307: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9308:
9309: if ($errtext) { $fatal=2; }
1.541 raeburn 9310: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9311: }
1.566 albertel 9312:
9313: return (1,$outcome);
1.444 albertel 9314: }
9315:
9316: ############################################################
9317: ############################################################
9318:
1.378 raeburn 9319: sub course_type {
9320: my ($cid) = @_;
9321: if (!defined($cid)) {
9322: $cid = $env{'request.course.id'};
9323: }
1.404 albertel 9324: if (defined($env{'course.'.$cid.'.type'})) {
9325: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9326: } else {
9327: return 'Course';
1.377 raeburn 9328: }
9329: }
1.156 albertel 9330:
1.406 raeburn 9331: sub group_term {
9332: my $crstype = &course_type();
9333: my %names = (
9334: 'Course' => 'group',
9335: 'Group' => 'team',
9336: );
9337: return $names{$crstype};
9338: }
9339:
1.156 albertel 9340: sub icon {
9341: my ($file)=@_;
1.505 albertel 9342: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9343: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9344: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9345: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9346: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9347: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9348: $curfext.".gif") {
9349: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9350: $curfext.".gif";
9351: }
9352: }
1.249 albertel 9353: return &lonhttpdurl($iconname);
1.154 albertel 9354: }
1.84 albertel 9355:
1.575 albertel 9356: sub lonhttpdurl {
1.692 www 9357: #
9358: # Had been used for "small fry" static images on separate port 8080.
9359: # Modify here if lightweight http functionality desired again.
9360: # Currently eliminated due to increasing firewall issues.
9361: #
1.575 albertel 9362: my ($url)=@_;
1.692 www 9363: return $url;
1.215 albertel 9364: }
9365:
1.213 albertel 9366: sub connection_aborted {
9367: my ($r)=@_;
9368: $r->print(" ");$r->rflush();
9369: my $c = $r->connection;
9370: return $c->aborted();
9371: }
9372:
1.221 foxr 9373: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9374: # strings as 'strings'.
9375: sub escape_single {
1.221 foxr 9376: my ($input) = @_;
1.223 albertel 9377: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9378: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9379: return $input;
9380: }
1.223 albertel 9381:
1.222 foxr 9382: # Same as escape_single, but escape's "'s This
9383: # can be used for "strings"
9384: sub escape_double {
9385: my ($input) = @_;
9386: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9387: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9388: return $input;
9389: }
1.223 albertel 9390:
1.222 foxr 9391: # Escapes the last element of a full URL.
9392: sub escape_url {
9393: my ($url) = @_;
1.238 raeburn 9394: my @urlslices = split(/\//, $url,-1);
1.369 www 9395: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9396: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9397: }
1.462 albertel 9398:
9399: # -------------------------------------------------------- Initliaze user login
9400: sub init_user_environment {
1.463 albertel 9401: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9402: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9403:
9404: my $public=($username eq 'public' && $domain eq 'public');
9405:
9406: # See if old ID present, if so, remove
9407:
9408: my ($filename,$cookie,$userroles);
9409: my $now=time;
9410:
9411: if ($public) {
9412: my $max_public=100;
9413: my $oldest;
9414: my $oldest_time=0;
9415: for(my $next=1;$next<=$max_public;$next++) {
9416: if (-e $lonids."/publicuser_$next.id") {
9417: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9418: if ($mtime<$oldest_time || !$oldest_time) {
9419: $oldest_time=$mtime;
9420: $oldest=$next;
9421: }
9422: } else {
9423: $cookie="publicuser_$next";
9424: last;
9425: }
9426: }
9427: if (!$cookie) { $cookie="publicuser_$oldest"; }
9428: } else {
1.463 albertel 9429: # if this isn't a robot, kill any existing non-robot sessions
9430: if (!$args->{'robot'}) {
9431: opendir(DIR,$lonids);
9432: while ($filename=readdir(DIR)) {
9433: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9434: unlink($lonids.'/'.$filename);
9435: }
1.462 albertel 9436: }
1.463 albertel 9437: closedir(DIR);
1.462 albertel 9438: }
9439: # Give them a new cookie
1.463 albertel 9440: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9441: : $now.$$.int(rand(10000)));
1.463 albertel 9442: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9443:
9444: # Initialize roles
9445:
9446: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9447: }
9448: # ------------------------------------ Check browser type and MathML capability
9449:
9450: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9451: $clientunicode,$clientos) = &decode_user_agent($r);
9452:
9453: # -------------------------------------- Any accessibility options to remember?
9454: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9455: foreach my $option ('imagesuppress','appletsuppress',
9456: 'embedsuppress','fontenhance','blackwhite') {
9457: if ($form->{$option} eq 'true') {
9458: &Apache::lonnet::put('environment',{$option => 'on'},
9459: $domain,$username);
9460: } else {
9461: &Apache::lonnet::del('environment',[$option],
9462: $domain,$username);
9463: }
9464: }
9465: }
9466: # ------------------------------------------------------------- Get environment
9467:
9468: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9469: my ($tmp) = keys(%userenv);
9470: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9471: # default remote control to off
9472: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9473: } else {
9474: undef(%userenv);
9475: }
9476: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9477: $form->{'interface'}=$userenv{'interface'};
9478: }
9479: $env{'environment.remote'}=$userenv{'remote'};
9480: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9481:
9482: # --------------- Do not trust query string to be put directly into environment
9483: foreach my $option ('imagesuppress','appletsuppress',
9484: 'embedsuppress','fontenhance','blackwhite',
9485: 'interface','localpath','localres') {
9486: $form->{$option}=~s/[\n\r\=]//gs;
9487: }
9488: # --------------------------------------------------------- Write first profile
9489:
9490: {
9491: my %initial_env =
9492: ("user.name" => $username,
9493: "user.domain" => $domain,
9494: "user.home" => $authhost,
9495: "browser.type" => $clientbrowser,
9496: "browser.version" => $clientversion,
9497: "browser.mathml" => $clientmathml,
9498: "browser.unicode" => $clientunicode,
9499: "browser.os" => $clientos,
9500: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9501: "request.course.fn" => '',
9502: "request.course.uri" => '',
9503: "request.course.sec" => '',
9504: "request.role" => 'cm',
9505: "request.role.adv" => $env{'user.adv'},
9506: "request.host" => $ENV{'REMOTE_ADDR'},);
9507:
9508: if ($form->{'localpath'}) {
9509: $initial_env{"browser.localpath"} = $form->{'localpath'};
9510: $initial_env{"browser.localres"} = $form->{'localres'};
9511: }
9512:
9513: if ($public) {
9514: $initial_env{"environment.remote"} = "off";
9515: }
9516: if ($form->{'interface'}) {
9517: $form->{'interface'}=~s/\W//gs;
9518: $initial_env{"browser.interface"} = $form->{'interface'};
9519: $env{'browser.interface'}=$form->{'interface'};
9520: foreach my $option ('imagesuppress','appletsuppress',
9521: 'embedsuppress','fontenhance','blackwhite') {
9522: if (($form->{$option} eq 'true') ||
9523: ($userenv{$option} eq 'on')) {
9524: $initial_env{"browser.$option"} = "on";
9525: }
9526: }
9527: }
9528:
1.692.2.6 raeburn 9529: foreach my $tool ('aboutme','blog','portfolio') {
9530: $userenv{'availabletools.'.$tool} =
9531: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9532: }
9533:
1.462 albertel 9534: $env{'user.environment'} = "$lonids/$cookie.id";
9535:
9536: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9537: &GDBM_WRCREAT(),0640)) {
9538: &_add_to_env(\%disk_env,\%initial_env);
9539: &_add_to_env(\%disk_env,\%userenv,'environment.');
9540: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9541: if (ref($args->{'extra_env'})) {
9542: &_add_to_env(\%disk_env,$args->{'extra_env'});
9543: }
1.462 albertel 9544: untie(%disk_env);
9545: } else {
9546: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
9547: 'Could not create environment storage in lonauth: '.$!.'</font>');
9548: return 'error: '.$!;
9549: }
9550: }
9551: $env{'request.role'}='cm';
9552: $env{'request.role.adv'}=$env{'user.adv'};
9553: $env{'browser.type'}=$clientbrowser;
9554:
9555: return $cookie;
9556:
9557: }
9558:
9559: sub _add_to_env {
9560: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9561: if (ref($env_data) eq 'HASH') {
9562: while (my ($key,$value) = each(%$env_data)) {
9563: $idf->{$prefix.$key} = $value;
9564: $env{$prefix.$key} = $value;
9565: }
1.462 albertel 9566: }
9567: }
9568:
1.685 tempelho 9569: # --- Get the symbolic name of a problem and the url
9570: sub get_symb {
9571: my ($request,$silent) = @_;
1.692.2.8 raeburn 9572: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 9573: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9574: if ($symb eq '') {
9575: if (!$silent) {
9576: $request->print("Unable to handle ambiguous references:$url:.");
9577: return ();
9578: }
9579: }
9580: &Apache::lonenc::check_decrypt(\$symb);
9581: return ($symb);
9582: }
9583:
9584: # --------------------------------------------------------------Get annotation
9585:
9586: sub get_annotation {
9587: my ($symb,$enc) = @_;
9588:
9589: my $key = $symb;
9590: if (!$enc) {
9591: $key =
9592: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9593: }
9594: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9595: return $annotation{$key};
9596: }
9597:
9598: sub clean_symb {
1.692.2.11! raeburn 9599: my ($symb,$delete_enc) = @_;
1.685 tempelho 9600:
9601: &Apache::lonenc::check_decrypt(\$symb);
9602: my $enc = $env{'request.enc'};
1.692.2.11! raeburn 9603: if ($delete_enc) {
! 9604: delete($env{'request.enc'});
! 9605: }
1.685 tempelho 9606:
9607: return ($symb,$enc);
9608: }
1.462 albertel 9609:
1.41 ng 9610: =pod
9611:
9612: =back
9613:
1.112 bowersj2 9614: =cut
1.41 ng 9615:
1.112 bowersj2 9616: 1;
9617: __END__;
1.41 ng 9618:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>