Annotation of loncom/interface/loncommon.pm, revision 1.692.4.3
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.692.4.3! raeburn 4: # $Id: loncommon.pm,v 1.692.4.2 2009/05/21 05:27:10 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.46 matthew 274: "<font color=yellow>INFO: Read file types</font>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
1.692.4.2 raeburn 409: <script type="text/javascript" language="Javascript">
1.74 www 410: var stdeditbrowser;
1.692.4.2 raeburn 411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
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.692.4.2 raeburn 425: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 426: var title = 'Student_Browser';
1.74 www 427: var options = 'scrollbars=1,resizable=1,menubar=0';
428: options += ',width=700,height=600';
429: stdeditbrowser = open(url,title,options,'1');
430: stdeditbrowser.focus();
431: }
432: </script>
433: ENDSTDBRW
434: }
1.42 matthew 435:
1.74 www 436: sub selectstudent_link {
1.692.4.2 raeburn 437: my ($form,$unameele,$udomele,$courseadvonly)=@_;
438: my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258 albertel 439: if ($env{'request.course.id'}) {
1.302 albertel 440: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
441: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
442: '/'.$env{'request.course.sec'})) {
1.111 www 443: return '';
444: }
1.692.4.2 raeburn 445: if ($courseadvonly) {
446: $callargs .= ",'',1,1";
447: }
448: return '<span class="LC_nobreak">'.
449: '<a href="javascript:openstdbrowser('.$callargs.');">'.
450: &mt('Select User').'</a></span>';
1.74 www 451: }
1.258 albertel 452: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.692.4.2 raeburn 453: $callargs .= ",1";
454: return '<span class="LC_nobreak">'.
455: '<a href="javascript:openstdbrowser('.$callargs.');">'.
456: &mt('Select User').'</a></span>';
1.111 www 457: }
458: return '';
1.91 www 459: }
460:
1.653 raeburn 461: sub authorbrowser_javascript {
462: return <<"ENDAUTHORBRW";
463: <script type="text/javascript">
464: var stdeditbrowser;
465:
466: function openauthorbrowser(formname,udom) {
467: var url = '/adm/pickauthor?';
468: url += 'form='+formname+'&roledom='+udom;
469: var title = 'Author_Browser';
470: var options = 'scrollbars=1,resizable=1,menubar=0';
471: options += ',width=700,height=600';
472: stdeditbrowser = open(url,title,options,'1');
473: stdeditbrowser.focus();
474: }
475:
476: </script>
477: ENDAUTHORBRW
478: }
479:
1.91 www 480: sub coursebrowser_javascript {
1.468 raeburn 481: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 482: 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 483: my $output = '
1.692.4.2 raeburn 484: <script type="text/javascript" language="JavaScript">
1.468 raeburn 485: var stdeditbrowser;'."\n";
486: $output .= <<"ENDSTDBRW";
1.377 raeburn 487: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 488: var url = '/adm/pickcourse?';
1.468 raeburn 489: var domainfilter = '';
490: var formid = getFormIdByName(formname);
491: if (formid > -1) {
492: var domid = getIndexByName(formid,udom);
493: if (domid > -1) {
494: if (document.forms[formid].elements[domid].type == 'select-one') {
495: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
496: }
497: if (document.forms[formid].elements[domid].type == 'hidden') {
498: domainfilter=document.forms[formid].elements[domid].value;
499: }
500: }
1.91 www 501: }
1.128 albertel 502: if (domainfilter != null) {
503: if (domainfilter != '') {
504: url += 'domainfilter='+domainfilter+'&';
505: }
506: }
1.91 www 507: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 508: '&cdomelement='+udom+
509: '&cnameelement='+desc;
1.468 raeburn 510: if (extra_element !=null && extra_element != '') {
1.594 raeburn 511: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 512: url += '&roleelement='+extra_element;
513: if (domainfilter == null || domainfilter == '') {
514: url += '&domainfilter='+extra_element;
515: }
1.234 raeburn 516: }
1.468 raeburn 517: else {
518: if (formname == 'portform') {
519: url += '&setroles='+extra_element;
520: }
521: }
1.230 raeburn 522: }
1.293 raeburn 523: if (multflag !=null && multflag != '') {
524: url += '&multiple='+multflag;
525: }
1.377 raeburn 526: if (crstype == 'Course/Group') {
527: if (formname == 'cu') {
528: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
529: if (crstype == "") {
530: alert("$crs_or_grp_alert");
531: return;
532: }
533: }
534: }
535: if (crstype !=null && crstype != '') {
536: url += '&type='+crstype;
537: }
1.102 www 538: var title = 'Course_Browser';
1.91 www 539: var options = 'scrollbars=1,resizable=1,menubar=0';
540: options += ',width=700,height=600';
541: stdeditbrowser = open(url,title,options,'1');
542: stdeditbrowser.focus();
543: }
1.468 raeburn 544:
545: function getFormIdByName(formname) {
546: for (var i=0;i<document.forms.length;i++) {
547: if (document.forms[i].name == formname) {
548: return i;
549: }
550: }
551: return -1;
552: }
553:
554: function getIndexByName(formid,item) {
555: for (var i=0;i<document.forms[formid].elements.length;i++) {
556: if (document.forms[formid].elements[i].name == item) {
557: return i;
558: }
559: }
560: return -1;
561: }
1.91 www 562: ENDSTDBRW
1.468 raeburn 563: if ($sec_element ne '') {
564: $output .= &setsec_javascript($sec_element,$formname);
565: }
566: $output .= '
567: </script>';
568: return $output;
569: }
570:
571: sub setsec_javascript {
572: my ($sec_element,$formname) = @_;
573: my $setsections = qq|
574: function setSect(sectionlist) {
1.629 raeburn 575: var sectionsArray = new Array();
576: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
577: sectionsArray = sectionlist.split(",");
578: }
1.468 raeburn 579: var numSections = sectionsArray.length;
580: document.$formname.$sec_element.length = 0;
581: if (numSections == 0) {
582: document.$formname.$sec_element.multiple=false;
583: document.$formname.$sec_element.size=1;
584: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
585: } else {
586: if (numSections == 1) {
587: document.$formname.$sec_element.multiple=false;
588: document.$formname.$sec_element.size=1;
589: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
590: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
591: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
592: } else {
593: for (var i=0; i<numSections; i++) {
594: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
595: }
596: document.$formname.$sec_element.multiple=true
597: if (numSections < 3) {
598: document.$formname.$sec_element.size=numSections;
599: } else {
600: document.$formname.$sec_element.size=3;
601: }
602: document.$formname.$sec_element.options[0].selected = false
603: }
604: }
1.91 www 605: }
1.468 raeburn 606: |;
607: return $setsections;
608: }
609:
1.91 www 610:
611: sub selectcourse_link {
1.377 raeburn 612: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.692.4.2 raeburn 613: return '<span class="LC_nobreak">'
614: ."<a href='"
615: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
616: .'","'.$udomele.'","'.$desc.'","'.$extra_element
617: .'","'.$multflag.'","'.$selecttype.'");'
618: ."'>".&mt('Select Course').'</a>'
619: .'</span>';
1.74 www 620: }
1.42 matthew 621:
1.653 raeburn 622: sub selectauthor_link {
623: my ($form,$udom)=@_;
624: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
625: &mt('Select Author').'</a>';
626: }
627:
1.273 raeburn 628: sub check_uncheck_jscript {
629: my $jscript = <<"ENDSCRT";
630: function checkAll(field) {
631: if (field.length > 0) {
632: for (i = 0; i < field.length; i++) {
633: field[i].checked = true ;
634: }
635: } else {
636: field.checked = true
637: }
638: }
639:
640: function uncheckAll(field) {
641: if (field.length > 0) {
642: for (i = 0; i < field.length; i++) {
643: field[i].checked = false ;
1.543 albertel 644: }
645: } else {
1.273 raeburn 646: field.checked = false ;
647: }
648: }
649: ENDSCRT
650: return $jscript;
651: }
652:
1.656 www 653: sub select_timezone {
1.659 raeburn 654: my ($name,$selected,$onchange,$includeempty)=@_;
655: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
656: if ($includeempty) {
657: $output .= '<option value=""';
658: if (($selected eq '') || ($selected eq 'local')) {
659: $output .= ' selected="selected" ';
660: }
661: $output .= '> </option>';
662: }
1.657 raeburn 663: my @timezones = DateTime::TimeZone->all_names;
664: foreach my $tzone (@timezones) {
665: $output.= '<option value="'.$tzone.'"';
666: if ($tzone eq $selected) {
667: $output.=' selected="selected"';
668: }
669: $output.=">$tzone</option>\n";
1.656 www 670: }
671: $output.="</select>";
672: return $output;
673: }
1.273 raeburn 674:
1.687 raeburn 675: sub select_datelocale {
676: my ($name,$selected,$onchange,$includeempty)=@_;
677: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
678: if ($includeempty) {
679: $output .= '<option value=""';
680: if ($selected eq '') {
681: $output .= ' selected="selected" ';
682: }
683: $output .= '> </option>';
684: }
685: my (@possibles,%locale_names);
686: my @locales = DateTime::Locale::Catalog::Locales;
687: foreach my $locale (@locales) {
688: if (ref($locale) eq 'HASH') {
689: my $id = $locale->{'id'};
690: if ($id ne '') {
691: my $en_terr = $locale->{'en_territory'};
692: my $native_terr = $locale->{'native_territory'};
1.692.4.1 raeburn 693: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 694: if (grep(/^en$/,@languages) || !@languages) {
695: if ($en_terr ne '') {
696: $locale_names{$id} = '('.$en_terr.')';
697: } elsif ($native_terr ne '') {
698: $locale_names{$id} = $native_terr;
699: }
700: } else {
701: if ($native_terr ne '') {
702: $locale_names{$id} = $native_terr.' ';
703: } elsif ($en_terr ne '') {
704: $locale_names{$id} = '('.$en_terr.')';
705: }
706: }
707: push (@possibles,$id);
708: }
709: }
710: }
711: foreach my $item (sort(@possibles)) {
712: $output.= '<option value="'.$item.'"';
713: if ($item eq $selected) {
714: $output.=' selected="selected"';
715: }
716: $output.=">$item";
717: if ($locale_names{$item} ne '') {
718: $output.=" $locale_names{$item}</option>\n";
719: }
720: $output.="</option>\n";
721: }
722: $output.="</select>";
723: return $output;
724: }
725:
1.692.4.2 raeburn 726: sub select_language {
727: my ($name,$selected,$includeempty) = @_;
728: my %langchoices;
729: if ($includeempty) {
730: %langchoices = ('' => 'No language preference');
731: }
732: foreach my $id (&languageids()) {
733: my $code = &supportedlanguagecode($id);
734: if ($code) {
735: $langchoices{$code} = &plainlanguagedescription($id);
736: }
737: }
738: return &select_form($selected,$name,%langchoices);
739: }
740:
1.42 matthew 741: =pod
1.36 matthew 742:
1.648 raeburn 743: =item * &linked_select_forms(...)
1.36 matthew 744:
745: linked_select_forms returns a string containing a <script></script> block
746: and html for two <select> menus. The select menus will be linked in that
747: changing the value of the first menu will result in new values being placed
748: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 749: order unless a defined order is provided.
1.36 matthew 750:
751: linked_select_forms takes the following ordered inputs:
752:
753: =over 4
754:
1.112 bowersj2 755: =item * $formname, the name of the <form> tag
1.36 matthew 756:
1.112 bowersj2 757: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 758:
1.112 bowersj2 759: =item * $firstdefault, the default value for the first menu
1.36 matthew 760:
1.112 bowersj2 761: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 762:
1.112 bowersj2 763: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 764:
1.112 bowersj2 765: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 766:
1.609 raeburn 767: =item * $menuorder, the order of values in the first menu
768:
1.41 ng 769: =back
770:
1.36 matthew 771: Below is an example of such a hash. Only the 'text', 'default', and
772: 'select2' keys must appear as stated. keys(%menu) are the possible
773: values for the first select menu. The text that coincides with the
1.41 ng 774: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 775: and text for the second menu are given in the hash pointed to by
776: $menu{$choice1}->{'select2'}.
777:
1.112 bowersj2 778: my %menu = ( A1 => { text =>"Choice A1" ,
779: default => "B3",
780: select2 => {
781: B1 => "Choice B1",
782: B2 => "Choice B2",
783: B3 => "Choice B3",
784: B4 => "Choice B4"
1.609 raeburn 785: },
786: order => ['B4','B3','B1','B2'],
1.112 bowersj2 787: },
788: A2 => { text =>"Choice A2" ,
789: default => "C2",
790: select2 => {
791: C1 => "Choice C1",
792: C2 => "Choice C2",
793: C3 => "Choice C3"
1.609 raeburn 794: },
795: order => ['C2','C1','C3'],
1.112 bowersj2 796: },
797: A3 => { text =>"Choice A3" ,
798: default => "D6",
799: select2 => {
800: D1 => "Choice D1",
801: D2 => "Choice D2",
802: D3 => "Choice D3",
803: D4 => "Choice D4",
804: D5 => "Choice D5",
805: D6 => "Choice D6",
806: D7 => "Choice D7"
1.609 raeburn 807: },
808: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 809: }
810: );
1.36 matthew 811:
812: =cut
813:
814: sub linked_select_forms {
815: my ($formname,
816: $middletext,
817: $firstdefault,
818: $firstselectname,
819: $secondselectname,
1.609 raeburn 820: $hashref,
821: $menuorder,
1.36 matthew 822: ) = @_;
823: my $second = "document.$formname.$secondselectname";
824: my $first = "document.$formname.$firstselectname";
825: # output the javascript to do the changing
826: my $result = '';
1.692.4.2 raeburn 827: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36 matthew 828: $result.="var select2data = new Object();\n";
829: $" = '","';
830: my $debug = '';
831: foreach my $s1 (sort(keys(%$hashref))) {
832: $result.="select2data.d_$s1 = new Object();\n";
833: $result.="select2data.d_$s1.def = new String('".
834: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 835: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 836: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 837: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
838: @s2values = @{$hashref->{$s1}->{'order'}};
839: }
1.36 matthew 840: $result.="\"@s2values\");\n";
841: $result.="select2data.d_$s1.texts = new Array(";
842: my @s2texts;
843: foreach my $value (@s2values) {
844: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
845: }
846: $result.="\"@s2texts\");\n";
847: }
848: $"=' ';
849: $result.= <<"END";
850:
851: function select1_changed() {
852: // Determine new choice
853: var newvalue = "d_" + $first.value;
854: // update select2
855: var values = select2data[newvalue].values;
856: var texts = select2data[newvalue].texts;
857: var select2def = select2data[newvalue].def;
858: var i;
859: // out with the old
860: for (i = 0; i < $second.options.length; i++) {
861: $second.options[i] = null;
862: }
863: // in with the nuclear
864: for (i=0;i<values.length; i++) {
865: $second.options[i] = new Option(values[i]);
1.143 matthew 866: $second.options[i].value = values[i];
1.36 matthew 867: $second.options[i].text = texts[i];
868: if (values[i] == select2def) {
869: $second.options[i].selected = true;
870: }
871: }
872: }
873: </script>
874: END
875: # output the initial values for the selection lists
876: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 877: my @order = sort(keys(%{$hashref}));
878: if (ref($menuorder) eq 'ARRAY') {
879: @order = @{$menuorder};
880: }
881: foreach my $value (@order) {
1.36 matthew 882: $result.=" <option value=\"$value\" ";
1.253 albertel 883: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 884: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 885: }
886: $result .= "</select>\n";
887: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
888: $result .= $middletext;
889: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
890: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 891:
892: my @secondorder = sort(keys(%select2));
893: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
894: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
895: }
896: foreach my $value (@secondorder) {
1.36 matthew 897: $result.=" <option value=\"$value\" ";
1.253 albertel 898: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 899: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 900: }
901: $result .= "</select>\n";
902: # return $debug;
903: return $result;
904: } # end of sub linked_select_forms {
905:
1.45 matthew 906: =pod
1.44 bowersj2 907:
1.648 raeburn 908: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 909:
1.112 bowersj2 910: Returns a string corresponding to an HTML link to the given help
911: $topic, where $topic corresponds to the name of a .tex file in
912: /home/httpd/html/adm/help/tex, with underscores replaced by
913: spaces.
914:
915: $text will optionally be linked to the same topic, allowing you to
916: link text in addition to the graphic. If you do not want to link
917: text, but wish to specify one of the later parameters, pass an
918: empty string.
919:
920: $stayOnPage is a value that will be interpreted as a boolean. If true,
921: the link will not open a new window. If false, the link will open
922: a new window using Javascript. (Default is false.)
923:
924: $width and $height are optional numerical parameters that will
925: override the width and height of the popped up window, which may
926: be useful for certain help topics with big pictures included.
1.44 bowersj2 927:
928: =cut
929:
930: sub help_open_topic {
1.48 bowersj2 931: my ($topic, $text, $stayOnPage, $width, $height) = @_;
932: $text = "" if (not defined $text);
1.44 bowersj2 933: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 934: if ($env{'browser.interface'} eq 'textual') {
1.79 www 935: $stayOnPage=1;
936: }
1.44 bowersj2 937: $width = 350 if (not defined $width);
938: $height = 400 if (not defined $height);
939: my $filename = $topic;
940: $filename =~ s/ /_/g;
941:
1.48 bowersj2 942: my $template = "";
943: my $link;
1.572 banghart 944:
1.159 www 945: $topic=~s/\W/\_/g;
1.44 bowersj2 946:
1.572 banghart 947: if (!$stayOnPage) {
1.72 bowersj2 948: $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 949: } else {
1.48 bowersj2 950: $link = "/adm/help/${filename}.hlp";
951: }
952:
953: # Add the text
1.572 banghart 954: if ($text ne "") {
1.77 www 955: $template .=
1.572 banghart 956: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.691 bisitz 957: "<td bgcolor='#5555FF'><span class=\"LC_nobreak\"><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 958: }
959:
960: # Add the graphic
1.179 matthew 961: my $title = &mt('Online Help');
1.667 raeburn 962: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.692.4.2 raeburn 963: $template .= '<a target="_top" href="'.$link.'" title="'.$title.'">'.
964: '<img src="'.$helpicon.'" border="0" alt="'.&mt('Help: [_1]',$topic).
965: '" title="'.$title.'" /></a>';
966: if ($text ne '') {
967: $template.='</span></td></tr></table>';
968: }
1.44 bowersj2 969: return $template;
970:
1.106 bowersj2 971: }
972:
973: # This is a quicky function for Latex cheatsheet editing, since it
974: # appears in at least four places
975: sub helpLatexCheatsheet {
1.692.4.2 raeburn 976: my ($topic,$text,$not_author) = @_;
977: my $out;
1.106 bowersj2 978: my $addOther = '';
1.692.4.3! raeburn 979: if ($topic) {
1.692.4.2 raeburn 980: $addOther = &Apache::loncommon::help_open_topic($topic,$text,
1.106 bowersj2 981: undef, undef, 600) .
982: '</td><td>';
983: }
1.692.4.2 raeburn 984: $out = '<table><tr><td>'.
985: $addOther .
986: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
987: undef,undef,600).
988: '</td><td>'.
989: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
990: undef,undef,600).
991: '</td>';
992: unless ($not_author) {
993: $out .= '<td>'.
994: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
995: undef,undef,600).
996: '</td>';
997: }
998: $out .= '</tr></table>';
999: return $out;
1.172 www 1000: }
1001:
1.430 albertel 1002: sub general_help {
1003: my $helptopic='Student_Intro';
1004: if ($env{'request.role'}=~/^(ca|au)/) {
1005: $helptopic='Authoring_Intro';
1006: } elsif ($env{'request.role'}=~/^cc/) {
1007: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1008: } elsif ($env{'request.role'}=~/^dc/) {
1009: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1010: }
1011: return $helptopic;
1012: }
1013:
1014: sub update_help_link {
1015: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1016: my $origurl = $ENV{'REQUEST_URI'};
1017: $origurl=~s|^/~|/priv/|;
1018: my $timestamp = time;
1019: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1020: $$datum = &escape($$datum);
1021: }
1022:
1023: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1024: my $output .= <<"ENDOUTPUT";
1025: <script type="text/javascript">
1026: banner_link = '$banner_link';
1027: </script>
1028: ENDOUTPUT
1029: return $output;
1030: }
1031:
1032: # now just updates the help link and generates a blue icon
1.193 raeburn 1033: sub help_open_menu {
1.430 albertel 1034: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1035: = @_;
1.430 albertel 1036: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1037: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1038: # if environment.remote is on (using remote control UI)
1.572 banghart 1039: if ($env{'browser.interface'} eq 'textual' ||
1040: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1041: $stayOnPage=1;
1.430 albertel 1042: }
1043: my $output;
1044: if ($component_help) {
1045: if (!$text) {
1046: $output=&help_open_topic($component_help,undef,$stayOnPage,
1047: $width,$height);
1048: } else {
1049: my $help_text;
1050: $help_text=&unescape($topic);
1051: $output='<table><tr><td>'.
1052: &help_open_topic($component_help,$help_text,$stayOnPage,
1053: $width,$height).'</td></tr></table>';
1054: }
1055: }
1056: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1057: return $output.$banner_link;
1058: }
1059:
1060: sub top_nav_help {
1061: my ($text) = @_;
1.436 albertel 1062: $text = &mt($text);
1.572 banghart 1063: my $stay_on_page =
1.436 albertel 1064: ($env{'browser.interface'} eq 'textual' ||
1065: $env{'environment.remote'} eq 'off' );
1.572 banghart 1066: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1067: : "javascript:helpMenu('open')";
1.572 banghart 1068: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1069:
1.201 raeburn 1070: my $title = &mt('Get help');
1.436 albertel 1071:
1072: return <<"END";
1073: $banner_link
1074: <a href="$link" title="$title">$text</a>
1075: END
1076: }
1077:
1078: sub help_menu_js {
1079: my ($text) = @_;
1080:
1081: my $stayOnPage =
1082: ($env{'browser.interface'} eq 'textual' ||
1083: $env{'environment.remote'} eq 'off' );
1084:
1085: my $width = 620;
1086: my $height = 600;
1.430 albertel 1087: my $helptopic=&general_help();
1088: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1089: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1090: my $start_page =
1091: &Apache::loncommon::start_page('Help Menu', undef,
1092: {'frameset' => 1,
1093: 'js_ready' => 1,
1094: 'add_entries' => {
1095: 'border' => '0',
1.579 raeburn 1096: 'rows' => "110,*",},});
1.331 albertel 1097: my $end_page =
1098: &Apache::loncommon::end_page({'frameset' => 1,
1099: 'js_ready' => 1,});
1100:
1.436 albertel 1101: my $template .= <<"ENDTEMPLATE";
1102: <script type="text/javascript">
1.253 albertel 1103: // <!-- BEGIN LON-CAPA Internal
1104: // <![CDATA[
1.430 albertel 1105: var banner_link = '';
1.243 raeburn 1106: function helpMenu(target) {
1107: var caller = this;
1108: if (target == 'open') {
1109: var newWindow = null;
1110: try {
1.262 albertel 1111: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1112: }
1113: catch(error) {
1114: writeHelp(caller);
1115: return;
1116: }
1117: if (newWindow) {
1118: caller = newWindow;
1119: }
1.193 raeburn 1120: }
1.243 raeburn 1121: writeHelp(caller);
1122: return;
1123: }
1124: function writeHelp(caller) {
1.430 albertel 1125: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1126: caller.document.close()
1127: caller.focus()
1.193 raeburn 1128: }
1.253 albertel 1129: // ]]>
1.219 albertel 1130: // END LON-CAPA Internal -->
1.436 albertel 1131: </script>
1.193 raeburn 1132: ENDTEMPLATE
1133: return $template;
1134: }
1135:
1.172 www 1136: sub help_open_bug {
1137: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1138: unless ($env{'user.adv'}) { return ''; }
1.172 www 1139: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1140: $text = "" if (not defined $text);
1141: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1142: if ($env{'browser.interface'} eq 'textual' ||
1143: $env{'environment.remote'} eq 'off' ) {
1.172 www 1144: $stayOnPage=1;
1145: }
1.184 albertel 1146: $width = 600 if (not defined $width);
1147: $height = 600 if (not defined $height);
1.172 www 1148:
1149: $topic=~s/\W+/\+/g;
1150: my $link='';
1151: my $template='';
1.379 albertel 1152: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1153: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1154: if (!$stayOnPage)
1155: {
1156: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1157: }
1158: else
1159: {
1160: $link = $url;
1161: }
1162: # Add the text
1163: if ($text ne "")
1164: {
1165: $template .=
1166: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1167: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1168: }
1169:
1170: # Add the graphic
1.179 matthew 1171: my $title = &mt('Report a Bug');
1.215 albertel 1172: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1173: $template .= <<"ENDTEMPLATE";
1.436 albertel 1174: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1175: ENDTEMPLATE
1176: if ($text ne '') { $template.='</td></tr></table>' };
1177: return $template;
1178:
1179: }
1180:
1181: sub help_open_faq {
1182: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1183: unless ($env{'user.adv'}) { return ''; }
1.172 www 1184: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1185: $text = "" if (not defined $text);
1186: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1187: if ($env{'browser.interface'} eq 'textual' ||
1188: $env{'environment.remote'} eq 'off' ) {
1.172 www 1189: $stayOnPage=1;
1190: }
1191: $width = 350 if (not defined $width);
1192: $height = 400 if (not defined $height);
1193:
1194: $topic=~s/\W+/\+/g;
1195: my $link='';
1196: my $template='';
1197: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1198: if (!$stayOnPage)
1199: {
1200: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1201: }
1202: else
1203: {
1204: $link = $url;
1205: }
1206:
1207: # Add the text
1208: if ($text ne "")
1209: {
1210: $template .=
1.173 www 1211: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1212: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1213: }
1214:
1215: # Add the graphic
1.179 matthew 1216: my $title = &mt('View the FAQ');
1.215 albertel 1217: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1218: $template .= <<"ENDTEMPLATE";
1.436 albertel 1219: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1220: ENDTEMPLATE
1221: if ($text ne '') { $template.='</td></tr></table>' };
1222: return $template;
1223:
1.44 bowersj2 1224: }
1.37 matthew 1225:
1.180 matthew 1226: ###############################################################
1227: ###############################################################
1228:
1.45 matthew 1229: =pod
1230:
1.648 raeburn 1231: =item * &change_content_javascript():
1.256 matthew 1232:
1233: This and the next function allow you to create small sections of an
1234: otherwise static HTML page that you can update on the fly with
1235: Javascript, even in Netscape 4.
1236:
1237: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1238: must be written to the HTML page once. It will prove the Javascript
1239: function "change(name, content)". Calling the change function with the
1240: name of the section
1241: you want to update, matching the name passed to C<changable_area>, and
1242: the new content you want to put in there, will put the content into
1243: that area.
1244:
1245: B<Note>: Netscape 4 only reserves enough space for the changable area
1246: to contain room for the original contents. You need to "make space"
1247: for whatever changes you wish to make, and be B<sure> to check your
1248: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1249: it's adequate for updating a one-line status display, but little more.
1250: This script will set the space to 100% width, so you only need to
1251: worry about height in Netscape 4.
1252:
1253: Modern browsers are much less limiting, and if you can commit to the
1254: user not using Netscape 4, this feature may be used freely with
1255: pretty much any HTML.
1256:
1257: =cut
1258:
1259: sub change_content_javascript {
1260: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1261: if ($env{'browser.type'} eq 'netscape' &&
1262: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1263: return (<<NETSCAPE4);
1264: function change(name, content) {
1265: doc = document.layers[name+"___escape"].layers[0].document;
1266: doc.open();
1267: doc.write(content);
1268: doc.close();
1269: }
1270: NETSCAPE4
1271: } else {
1272: # Otherwise, we need to use semi-standards-compliant code
1273: # (technically, "innerHTML" isn't standard but the equivalent
1274: # is really scary, and every useful browser supports it
1275: return (<<DOMBASED);
1276: function change(name, content) {
1277: element = document.getElementById(name);
1278: element.innerHTML = content;
1279: }
1280: DOMBASED
1281: }
1282: }
1283:
1284: =pod
1285:
1.648 raeburn 1286: =item * &changable_area($name,$origContent):
1.256 matthew 1287:
1288: This provides a "changable area" that can be modified on the fly via
1289: the Javascript code provided in C<change_content_javascript>. $name is
1290: the name you will use to reference the area later; do not repeat the
1291: same name on a given HTML page more then once. $origContent is what
1292: the area will originally contain, which can be left blank.
1293:
1294: =cut
1295:
1296: sub changable_area {
1297: my ($name, $origContent) = @_;
1298:
1.258 albertel 1299: if ($env{'browser.type'} eq 'netscape' &&
1300: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1301: # If this is netscape 4, we need to use the Layer tag
1302: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1303: } else {
1304: return "<span id='$name'>$origContent</span>";
1305: }
1306: }
1307:
1308: =pod
1309:
1.648 raeburn 1310: =item * &viewport_geometry_js
1.590 raeburn 1311:
1312: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1313:
1314: =cut
1315:
1316:
1317: sub viewport_geometry_js {
1318: return <<"GEOMETRY";
1319: var Geometry = {};
1320: function init_geometry() {
1321: if (Geometry.init) { return };
1322: Geometry.init=1;
1323: if (window.innerHeight) {
1324: Geometry.getViewportHeight = function() { return window.innerHeight; };
1325: Geometry.getViewportWidth = function() { return window.innerWidth; };
1326: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1327: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1328: }
1329: else if (document.documentElement && document.documentElement.clientHeight) {
1330: Geometry.getViewportHeight =
1331: function() { return document.documentElement.clientHeight; };
1332: Geometry.getViewportWidth =
1333: function() { return document.documentElement.clientWidth; };
1334:
1335: Geometry.getHorizontalScroll =
1336: function() { return document.documentElement.scrollLeft; };
1337: Geometry.getVerticalScroll =
1338: function() { return document.documentElement.scrollTop; };
1339: }
1340: else if (document.body.clientHeight) {
1341: Geometry.getViewportHeight =
1342: function() { return document.body.clientHeight; };
1343: Geometry.getViewportWidth =
1344: function() { return document.body.clientWidth; };
1345: Geometry.getHorizontalScroll =
1346: function() { return document.body.scrollLeft; };
1347: Geometry.getVerticalScroll =
1348: function() { return document.body.scrollTop; };
1349: }
1350: }
1351:
1352: GEOMETRY
1353: }
1354:
1355: =pod
1356:
1.648 raeburn 1357: =item * &viewport_size_js()
1.590 raeburn 1358:
1359: 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.
1360:
1361: =cut
1362:
1363: sub viewport_size_js {
1364: my $geometry = &viewport_geometry_js();
1365: return <<"DIMS";
1366:
1367: $geometry
1368:
1369: function getViewportDims(width,height) {
1370: init_geometry();
1371: width.value = Geometry.getViewportWidth();
1372: height.value = Geometry.getViewportHeight();
1373: return;
1374: }
1375:
1376: DIMS
1377: }
1378:
1379: =pod
1380:
1.648 raeburn 1381: =item * &resize_textarea_js()
1.565 albertel 1382:
1383: emits the needed javascript to resize a textarea to be as big as possible
1384:
1385: creates a function resize_textrea that takes two IDs first should be
1386: the id of the element to resize, second should be the id of a div that
1387: surrounds everything that comes after the textarea, this routine needs
1388: to be attached to the <body> for the onload and onresize events.
1389:
1.648 raeburn 1390: =back
1.565 albertel 1391:
1392: =cut
1393:
1394: sub resize_textarea_js {
1.590 raeburn 1395: my $geometry = &viewport_geometry_js();
1.565 albertel 1396: return <<"RESIZE";
1397: <script type="text/javascript">
1.590 raeburn 1398: $geometry
1.565 albertel 1399:
1.588 albertel 1400: function getX(element) {
1401: var x = 0;
1402: while (element) {
1403: x += element.offsetLeft;
1404: element = element.offsetParent;
1405: }
1406: return x;
1407: }
1408: function getY(element) {
1409: var y = 0;
1410: while (element) {
1411: y += element.offsetTop;
1412: element = element.offsetParent;
1413: }
1414: return y;
1415: }
1416:
1417:
1.565 albertel 1418: function resize_textarea(textarea_id,bottom_id) {
1419: init_geometry();
1420: var textarea = document.getElementById(textarea_id);
1421: //alert(textarea);
1422:
1.588 albertel 1423: var textarea_top = getY(textarea);
1.565 albertel 1424: var textarea_height = textarea.offsetHeight;
1425: var bottom = document.getElementById(bottom_id);
1.588 albertel 1426: var bottom_top = getY(bottom);
1.565 albertel 1427: var bottom_height = bottom.offsetHeight;
1428: var window_height = Geometry.getViewportHeight();
1.588 albertel 1429: var fudge = 23;
1.565 albertel 1430: var new_height = window_height-fudge-textarea_top-bottom_height;
1431: if (new_height < 300) {
1432: new_height = 300;
1433: }
1434: textarea.style.height=new_height+'px';
1435: }
1436: </script>
1437: RESIZE
1438:
1439: }
1440:
1441: =pod
1442:
1.256 matthew 1443: =head1 Excel and CSV file utility routines
1444:
1445: =over 4
1446:
1447: =cut
1448:
1449: ###############################################################
1450: ###############################################################
1451:
1452: =pod
1453:
1.648 raeburn 1454: =item * &csv_translate($text)
1.37 matthew 1455:
1.185 www 1456: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1457: format.
1458:
1459: =cut
1460:
1.180 matthew 1461: ###############################################################
1462: ###############################################################
1.37 matthew 1463: sub csv_translate {
1464: my $text = shift;
1465: $text =~ s/\"/\"\"/g;
1.209 albertel 1466: $text =~ s/\n/ /g;
1.37 matthew 1467: return $text;
1468: }
1.180 matthew 1469:
1470: ###############################################################
1471: ###############################################################
1472:
1473: =pod
1474:
1.648 raeburn 1475: =item * &define_excel_formats()
1.180 matthew 1476:
1477: Define some commonly used Excel cell formats.
1478:
1479: Currently supported formats:
1480:
1481: =over 4
1482:
1483: =item header
1484:
1485: =item bold
1486:
1487: =item h1
1488:
1489: =item h2
1490:
1491: =item h3
1492:
1.256 matthew 1493: =item h4
1494:
1495: =item i
1496:
1.180 matthew 1497: =item date
1498:
1499: =back
1500:
1501: Inputs: $workbook
1502:
1503: Returns: $format, a hash reference.
1504:
1505: =cut
1506:
1507: ###############################################################
1508: ###############################################################
1509: sub define_excel_formats {
1510: my ($workbook) = @_;
1511: my $format;
1512: $format->{'header'} = $workbook->add_format(bold => 1,
1513: bottom => 1,
1514: align => 'center');
1515: $format->{'bold'} = $workbook->add_format(bold=>1);
1516: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1517: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1518: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1519: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1520: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1521: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1522: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1523: return $format;
1524: }
1525:
1526: ###############################################################
1527: ###############################################################
1.113 bowersj2 1528:
1529: =pod
1530:
1.648 raeburn 1531: =item * &create_workbook()
1.255 matthew 1532:
1533: Create an Excel worksheet. If it fails, output message on the
1534: request object and return undefs.
1535:
1536: Inputs: Apache request object
1537:
1538: Returns (undef) on failure,
1539: Excel worksheet object, scalar with filename, and formats
1540: from &Apache::loncommon::define_excel_formats on success
1541:
1542: =cut
1543:
1544: ###############################################################
1545: ###############################################################
1546: sub create_workbook {
1547: my ($r) = @_;
1548: #
1549: # Create the excel spreadsheet
1550: my $filename = '/prtspool/'.
1.258 albertel 1551: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1552: time.'_'.rand(1000000000).'.xls';
1553: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1554: if (! defined($workbook)) {
1555: $r->log_error("Error creating excel spreadsheet $filename: $!");
1556: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1557: "This error has been logged. ".
1558: "Please alert your LON-CAPA administrator").
1559: '</p>');
1560: return (undef);
1561: }
1562: #
1563: $workbook->set_tempdir('/home/httpd/perl/tmp');
1564: #
1565: my $format = &Apache::loncommon::define_excel_formats($workbook);
1566: return ($workbook,$filename,$format);
1567: }
1568:
1569: ###############################################################
1570: ###############################################################
1571:
1572: =pod
1573:
1.648 raeburn 1574: =item * &create_text_file()
1.113 bowersj2 1575:
1.542 raeburn 1576: Create a file to write to and eventually make available to the user.
1.256 matthew 1577: If file creation fails, outputs an error message on the request object and
1578: return undefs.
1.113 bowersj2 1579:
1.256 matthew 1580: Inputs: Apache request object, and file suffix
1.113 bowersj2 1581:
1.256 matthew 1582: Returns (undef) on failure,
1583: Filehandle and filename on success.
1.113 bowersj2 1584:
1585: =cut
1586:
1.256 matthew 1587: ###############################################################
1588: ###############################################################
1589: sub create_text_file {
1590: my ($r,$suffix) = @_;
1591: if (! defined($suffix)) { $suffix = 'txt'; };
1592: my $fh;
1593: my $filename = '/prtspool/'.
1.258 albertel 1594: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1595: time.'_'.rand(1000000000).'.'.$suffix;
1596: $fh = Apache::File->new('>/home/httpd'.$filename);
1597: if (! defined($fh)) {
1598: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1599: $r->print(&mt('Problems occurred in creating the output file. '
1600: .'This error has been logged. '
1601: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1602: }
1.256 matthew 1603: return ($fh,$filename)
1.113 bowersj2 1604: }
1605:
1606:
1.256 matthew 1607: =pod
1.113 bowersj2 1608:
1609: =back
1610:
1611: =cut
1.37 matthew 1612:
1613: ###############################################################
1.33 matthew 1614: ## Home server <option> list generating code ##
1615: ###############################################################
1.35 matthew 1616:
1.169 www 1617: # ------------------------------------------
1618:
1619: sub domain_select {
1620: my ($name,$value,$multiple)=@_;
1621: my %domains=map {
1.514 albertel 1622: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1623: } &Apache::lonnet::all_domains();
1.169 www 1624: if ($multiple) {
1625: $domains{''}=&mt('Any domain');
1.550 albertel 1626: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1627: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1628: } else {
1.550 albertel 1629: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1630: return &select_form($name,$value,%domains);
1631: }
1632: }
1633:
1.282 albertel 1634: #-------------------------------------------
1635:
1636: =pod
1637:
1.519 raeburn 1638: =head1 Routines for form select boxes
1639:
1640: =over 4
1641:
1.648 raeburn 1642: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1643:
1644: Returns a string containing a <select> element int multiple mode
1645:
1646:
1647: Args:
1648: $name - name of the <select> element
1.506 raeburn 1649: $value - scalar or array ref of values that should already be selected
1.282 albertel 1650: $size - number of rows long the select element is
1.283 albertel 1651: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1652: (shown text should already have been &mt())
1.506 raeburn 1653: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1654:
1.282 albertel 1655: =cut
1656:
1657: #-------------------------------------------
1.169 www 1658: sub multiple_select_form {
1.284 albertel 1659: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1660: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1661: my $output='';
1.191 matthew 1662: if (! defined($size)) {
1663: $size = 4;
1.283 albertel 1664: if (scalar(keys(%$hash))<4) {
1665: $size = scalar(keys(%$hash));
1.191 matthew 1666: }
1667: }
1.692.4.2 raeburn 1668: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1669: my @order;
1.506 raeburn 1670: if (ref($order) eq 'ARRAY') {
1671: @order = @{$order};
1672: } else {
1673: @order = sort(keys(%$hash));
1.501 banghart 1674: }
1675: if (exists($$hash{'select_form_order'})) {
1676: @order = @{$$hash{'select_form_order'}};
1677: }
1678:
1.284 albertel 1679: foreach my $key (@order) {
1.356 albertel 1680: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1681: $output.='selected="selected" ' if ($selected{$key});
1682: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1683: }
1684: $output.="</select>\n";
1685: return $output;
1686: }
1687:
1.88 www 1688: #-------------------------------------------
1689:
1690: =pod
1691:
1.648 raeburn 1692: =item * &select_form($defdom,$name,%hash)
1.88 www 1693:
1694: Returns a string containing a <select name='$name' size='1'> form to
1695: allow a user to select options from a hash option_name => displayed text.
1696: See lonrights.pm for an example invocation and use.
1697:
1698: =cut
1699:
1700: #-------------------------------------------
1701: sub select_form {
1702: my ($def,$name,%hash) = @_;
1703: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1704: my @keys;
1705: if (exists($hash{'select_form_order'})) {
1706: @keys=@{$hash{'select_form_order'}};
1707: } else {
1708: @keys=sort(keys(%hash));
1709: }
1.356 albertel 1710: foreach my $key (@keys) {
1711: $selectform.=
1712: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1713: ($key eq $def ? 'selected="selected" ' : '').
1714: ">".&mt($hash{$key})."</option>\n";
1.88 www 1715: }
1716: $selectform.="</select>";
1717: return $selectform;
1718: }
1719:
1.475 www 1720: # For display filters
1721:
1722: sub display_filter {
1723: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1724: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.692.4.2 raeburn 1725: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1726: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1727: (&mt('all'),10,20,50,100,1000,10000))).
1.692.4.2 raeburn 1728: '</label></span> <span class="LC_nobreak">'.
1.475 www 1729: &mt('Filter [_1]',
1.477 www 1730: &select_form($env{'form.displayfilter'},
1731: 'displayfilter',
1732: ('currentfolder' => 'Current folder/page',
1733: 'containing' => 'Containing phrase',
1734: 'none' => 'None'))).
1.692.4.2 raeburn 1735: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1736: }
1737:
1.167 www 1738: sub gradeleveldescription {
1739: my $gradelevel=shift;
1740: my %gradelevels=(0 => 'Not specified',
1741: 1 => 'Grade 1',
1742: 2 => 'Grade 2',
1743: 3 => 'Grade 3',
1744: 4 => 'Grade 4',
1745: 5 => 'Grade 5',
1746: 6 => 'Grade 6',
1747: 7 => 'Grade 7',
1748: 8 => 'Grade 8',
1749: 9 => 'Grade 9',
1750: 10 => 'Grade 10',
1751: 11 => 'Grade 11',
1752: 12 => 'Grade 12',
1753: 13 => 'Grade 13',
1754: 14 => '100 Level',
1755: 15 => '200 Level',
1756: 16 => '300 Level',
1757: 17 => '400 Level',
1758: 18 => 'Graduate Level');
1759: return &mt($gradelevels{$gradelevel});
1760: }
1761:
1.163 www 1762: sub select_level_form {
1763: my ($deflevel,$name)=@_;
1764: unless ($deflevel) { $deflevel=0; }
1.167 www 1765: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1766: for (my $i=0; $i<=18; $i++) {
1767: $selectform.="<option value=\"$i\" ".
1.253 albertel 1768: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1769: ">".&gradeleveldescription($i)."</option>\n";
1770: }
1771: $selectform.="</select>";
1772: return $selectform;
1.163 www 1773: }
1.167 www 1774:
1.35 matthew 1775: #-------------------------------------------
1776:
1.45 matthew 1777: =pod
1778:
1.692.4.2 raeburn 1779: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1780:
1781: Returns a string containing a <select name='$name' size='1'> form to
1782: allow a user to select the domain to preform an operation in.
1783: See loncreateuser.pm for an example invocation and use.
1784:
1.90 www 1785: If the $includeempty flag is set, it also includes an empty choice ("no domain
1786: selected");
1787:
1.692.4.2 raeburn 1788: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1789:
1790: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1791:
1.35 matthew 1792: =cut
1793:
1794: #-------------------------------------------
1.34 matthew 1795: sub select_dom_form {
1.692.4.2 raeburn 1796: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1797: my $onchange;
1798: if ($autosubmit) {
1799: $onchange = ' onchange="this.form.submit()"';
1800: }
1.550 albertel 1801: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1802: if ($includeempty) { @domains=('',@domains); }
1.692.4.2 raeburn 1803: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1804: foreach my $dom (@domains) {
1805: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1806: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1807: if ($showdomdesc) {
1808: if ($dom ne '') {
1809: my $domdesc = &Apache::lonnet::domain($dom,'description');
1810: if ($domdesc ne '') {
1811: $selectdomain .= ' ('.$domdesc.')';
1812: }
1813: }
1814: }
1815: $selectdomain .= "</option>\n";
1.34 matthew 1816: }
1817: $selectdomain.="</select>";
1818: return $selectdomain;
1819: }
1820:
1.35 matthew 1821: #-------------------------------------------
1822:
1.45 matthew 1823: =pod
1824:
1.648 raeburn 1825: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1826:
1.586 raeburn 1827: input: 4 arguments (two required, two optional) -
1828: $domain - domain of new user
1829: $name - name of form element
1830: $default - Value of 'default' causes a default item to be first
1831: option, and selected by default.
1832: $hide - Value of 'hide' causes hiding of the name of the server,
1833: if 1 server found, or default, if 0 found.
1.594 raeburn 1834: output: returns 2 items:
1.586 raeburn 1835: (a) form element which contains either:
1836: (i) <select name="$name">
1837: <option value="$hostid1">$hostid $servers{$hostid}</option>
1838: <option value="$hostid2">$hostid $servers{$hostid}</option>
1839: </select>
1840: form item if there are multiple library servers in $domain, or
1841: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1842: if there is only one library server in $domain.
1843:
1844: (b) number of library servers found.
1845:
1846: See loncreateuser.pm for example of use.
1.35 matthew 1847:
1848: =cut
1849:
1850: #-------------------------------------------
1.586 raeburn 1851: sub home_server_form_item {
1852: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1853: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1854: my $result;
1855: my $numlib = keys(%servers);
1856: if ($numlib > 1) {
1857: $result .= '<select name="'.$name.'" />'."\n";
1858: if ($default) {
1.692.4.2 raeburn 1859: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 1860: '</option>'."\n";
1861: }
1862: foreach my $hostid (sort(keys(%servers))) {
1863: $result.= '<option value="'.$hostid.'">'.
1864: $hostid.' '.$servers{$hostid}."</option>\n";
1865: }
1866: $result .= '</select>'."\n";
1867: } elsif ($numlib == 1) {
1868: my $hostid;
1869: foreach my $item (keys(%servers)) {
1870: $hostid = $item;
1871: }
1872: $result .= '<input type="hidden" name="'.$name.'" value="'.
1873: $hostid.'" />';
1874: if (!$hide) {
1875: $result .= $hostid.' '.$servers{$hostid};
1876: }
1877: $result .= "\n";
1878: } elsif ($default) {
1879: $result .= '<input type="hidden" name="'.$name.
1880: '" value="default" />';
1881: if (!$hide) {
1882: $result .= &mt('default');
1883: }
1884: $result .= "\n";
1.33 matthew 1885: }
1.586 raeburn 1886: return ($result,$numlib);
1.33 matthew 1887: }
1.112 bowersj2 1888:
1889: =pod
1890:
1.534 albertel 1891: =back
1892:
1.112 bowersj2 1893: =cut
1.87 matthew 1894:
1895: ###############################################################
1.112 bowersj2 1896: ## Decoding User Agent ##
1.87 matthew 1897: ###############################################################
1898:
1899: =pod
1900:
1.112 bowersj2 1901: =head1 Decoding the User Agent
1902:
1903: =over 4
1904:
1905: =item * &decode_user_agent()
1.87 matthew 1906:
1907: Inputs: $r
1908:
1909: Outputs:
1910:
1911: =over 4
1912:
1.112 bowersj2 1913: =item * $httpbrowser
1.87 matthew 1914:
1.112 bowersj2 1915: =item * $clientbrowser
1.87 matthew 1916:
1.112 bowersj2 1917: =item * $clientversion
1.87 matthew 1918:
1.112 bowersj2 1919: =item * $clientmathml
1.87 matthew 1920:
1.112 bowersj2 1921: =item * $clientunicode
1.87 matthew 1922:
1.112 bowersj2 1923: =item * $clientos
1.87 matthew 1924:
1925: =back
1926:
1.157 matthew 1927: =back
1928:
1.87 matthew 1929: =cut
1930:
1931: ###############################################################
1932: ###############################################################
1933: sub decode_user_agent {
1.247 albertel 1934: my ($r)=@_;
1.87 matthew 1935: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1936: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1937: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1938: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1939: my $clientbrowser='unknown';
1940: my $clientversion='0';
1941: my $clientmathml='';
1942: my $clientunicode='0';
1943: for (my $i=0;$i<=$#browsertype;$i++) {
1944: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1945: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1946: $clientbrowser=$bname;
1947: $httpbrowser=~/$vreg/i;
1948: $clientversion=$1;
1949: $clientmathml=($clientversion>=$minv);
1950: $clientunicode=($clientversion>=$univ);
1951: }
1952: }
1953: my $clientos='unknown';
1954: if (($httpbrowser=~/linux/i) ||
1955: ($httpbrowser=~/unix/i) ||
1956: ($httpbrowser=~/ux/i) ||
1957: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1958: if (($httpbrowser=~/vax/i) ||
1959: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1960: if ($httpbrowser=~/next/i) { $clientos='next'; }
1961: if (($httpbrowser=~/mac/i) ||
1962: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1963: if ($httpbrowser=~/win/i) { $clientos='win'; }
1964: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1965: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1966: $clientunicode,$clientos,);
1967: }
1968:
1.32 matthew 1969: ###############################################################
1970: ## Authentication changing form generation subroutines ##
1971: ###############################################################
1972: ##
1973: ## All of the authform_xxxxxxx subroutines take their inputs in a
1974: ## hash, and have reasonable default values.
1975: ##
1976: ## formname = the name given in the <form> tag.
1.35 matthew 1977: #-------------------------------------------
1978:
1.45 matthew 1979: =pod
1980:
1.112 bowersj2 1981: =head1 Authentication Routines
1982:
1983: =over 4
1984:
1.648 raeburn 1985: =item * &authform_xxxxxx()
1.35 matthew 1986:
1987: The authform_xxxxxx subroutines provide javascript and html forms which
1988: handle some of the conveniences required for authentication forms.
1989: This is not an optimal method, but it works.
1990:
1991: =over 4
1992:
1.112 bowersj2 1993: =item * authform_header
1.35 matthew 1994:
1.112 bowersj2 1995: =item * authform_authorwarning
1.35 matthew 1996:
1.112 bowersj2 1997: =item * authform_nochange
1.35 matthew 1998:
1.112 bowersj2 1999: =item * authform_kerberos
1.35 matthew 2000:
1.112 bowersj2 2001: =item * authform_internal
1.35 matthew 2002:
1.112 bowersj2 2003: =item * authform_filesystem
1.35 matthew 2004:
2005: =back
2006:
1.648 raeburn 2007: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2008:
1.35 matthew 2009: =cut
2010:
2011: #-------------------------------------------
1.32 matthew 2012: sub authform_header{
2013: my %in = (
2014: formname => 'cu',
1.80 albertel 2015: kerb_def_dom => '',
1.32 matthew 2016: @_,
2017: );
2018: $in{'formname'} = 'document.' . $in{'formname'};
2019: my $result='';
1.80 albertel 2020:
2021: #---------------------------------------------- Code for upper case translation
2022: my $Javascript_toUpperCase;
2023: unless ($in{kerb_def_dom}) {
2024: $Javascript_toUpperCase =<<"END";
2025: switch (choice) {
2026: case 'krb': currentform.elements[choicearg].value =
2027: currentform.elements[choicearg].value.toUpperCase();
2028: break;
2029: default:
2030: }
2031: END
2032: } else {
2033: $Javascript_toUpperCase = "";
2034: }
2035:
1.165 raeburn 2036: my $radioval = "'nochange'";
1.591 raeburn 2037: if (defined($in{'curr_authtype'})) {
2038: if ($in{'curr_authtype'} ne '') {
2039: $radioval = "'".$in{'curr_authtype'}."arg'";
2040: }
1.174 matthew 2041: }
1.165 raeburn 2042: my $argfield = 'null';
1.591 raeburn 2043: if (defined($in{'mode'})) {
1.165 raeburn 2044: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2045: if (defined($in{'curr_autharg'})) {
2046: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2047: $argfield = "'$in{'curr_autharg'}'";
2048: }
2049: }
2050: }
2051: }
2052:
1.32 matthew 2053: $result.=<<"END";
2054: var current = new Object();
1.165 raeburn 2055: current.radiovalue = $radioval;
2056: current.argfield = $argfield;
1.32 matthew 2057:
2058: function changed_radio(choice,currentform) {
2059: var choicearg = choice + 'arg';
2060: // If a radio button in changed, we need to change the argfield
2061: if (current.radiovalue != choice) {
2062: current.radiovalue = choice;
2063: if (current.argfield != null) {
2064: currentform.elements[current.argfield].value = '';
2065: }
2066: if (choice == 'nochange') {
2067: current.argfield = null;
2068: } else {
2069: current.argfield = choicearg;
2070: switch(choice) {
2071: case 'krb':
2072: currentform.elements[current.argfield].value =
2073: "$in{'kerb_def_dom'}";
2074: break;
2075: default:
2076: break;
2077: }
2078: }
2079: }
2080: return;
2081: }
1.22 www 2082:
1.32 matthew 2083: function changed_text(choice,currentform) {
2084: var choicearg = choice + 'arg';
2085: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2086: $Javascript_toUpperCase
1.32 matthew 2087: // clear old field
2088: if ((current.argfield != choicearg) && (current.argfield != null)) {
2089: currentform.elements[current.argfield].value = '';
2090: }
2091: current.argfield = choicearg;
2092: }
2093: set_auth_radio_buttons(choice,currentform);
2094: return;
1.20 www 2095: }
1.32 matthew 2096:
2097: function set_auth_radio_buttons(newvalue,currentform) {
2098: var i=0;
2099: while (i < currentform.login.length) {
2100: if (currentform.login[i].value == newvalue) { break; }
2101: i++;
2102: }
2103: if (i == currentform.login.length) {
2104: return;
2105: }
2106: current.radiovalue = newvalue;
2107: currentform.login[i].checked = true;
2108: return;
2109: }
2110: END
2111: return $result;
2112: }
2113:
2114: sub authform_authorwarning{
2115: my $result='';
1.144 matthew 2116: $result='<i>'.
2117: &mt('As a general rule, only authors or co-authors should be '.
2118: 'filesystem authenticated '.
2119: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2120: return $result;
2121: }
2122:
2123: sub authform_nochange{
2124: my %in = (
2125: formname => 'document.cu',
2126: kerb_def_dom => 'MSU.EDU',
2127: @_,
2128: );
1.586 raeburn 2129: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2130: my $result;
2131: if (keys(%can_assign) == 0) {
2132: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2133: } else {
2134: $result = '<label>'.&mt('[_1] Do not change login data',
2135: '<input type="radio" name="login" value="nochange" '.
2136: 'checked="checked" onclick="'.
1.281 albertel 2137: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2138: '</label>';
1.586 raeburn 2139: }
1.32 matthew 2140: return $result;
2141: }
2142:
1.591 raeburn 2143: sub authform_kerberos {
1.32 matthew 2144: my %in = (
2145: formname => 'document.cu',
2146: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2147: kerb_def_auth => 'krb4',
1.32 matthew 2148: @_,
2149: );
1.586 raeburn 2150: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2151: $autharg,$jscall);
2152: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2153: if ($in{'kerb_def_auth'} eq 'krb5') {
1.692.4.2 raeburn 2154: $check5 = ' checked="checked"';
1.80 albertel 2155: } else {
1.692.4.2 raeburn 2156: $check4 = ' checked="checked"';
1.80 albertel 2157: }
1.165 raeburn 2158: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2159: if (defined($in{'curr_authtype'})) {
2160: if ($in{'curr_authtype'} eq 'krb') {
1.692.4.2 raeburn 2161: $krbcheck = ' checked="checked"';
1.623 raeburn 2162: if (defined($in{'mode'})) {
2163: if ($in{'mode'} eq 'modifyuser') {
2164: $krbcheck = '';
2165: }
2166: }
1.591 raeburn 2167: if (defined($in{'curr_kerb_ver'})) {
2168: if ($in{'curr_krb_ver'} eq '5') {
1.692.4.2 raeburn 2169: $check5 = ' checked="checked"';
1.591 raeburn 2170: $check4 = '';
2171: } else {
1.692.4.2 raeburn 2172: $check4 = ' checked="checked"';
1.591 raeburn 2173: $check5 = '';
2174: }
1.586 raeburn 2175: }
1.591 raeburn 2176: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2177: $krbarg = $in{'curr_autharg'};
2178: }
1.586 raeburn 2179: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2180: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2181: $result =
2182: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2183: $in{'curr_autharg'},$krbver);
2184: } else {
2185: $result =
2186: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2187: }
2188: return $result;
2189: }
2190: }
2191: } else {
2192: if ($authnum == 1) {
1.692.4.2 raeburn 2193: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2194: }
2195: }
1.586 raeburn 2196: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2197: return;
1.587 raeburn 2198: } elsif ($authtype eq '') {
1.591 raeburn 2199: if (defined($in{'mode'})) {
1.587 raeburn 2200: if ($in{'mode'} eq 'modifycourse') {
2201: if ($authnum == 1) {
1.692.4.2 raeburn 2202: $authtype = '<input type="hidden" name="login" value="krb" />';
1.587 raeburn 2203: }
2204: }
2205: }
1.586 raeburn 2206: }
2207: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2208: if ($authtype eq '') {
2209: $authtype = '<input type="radio" name="login" value="krb" '.
2210: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2211: $krbcheck.' />';
2212: }
2213: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2214: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2215: $in{'curr_authtype'} eq 'krb5') ||
2216: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2217: $in{'curr_authtype'} eq 'krb4')) {
2218: $result .= &mt
1.144 matthew 2219: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2220: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2221: '<label>'.$authtype,
1.281 albertel 2222: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2223: 'value="'.$krbarg.'" '.
1.144 matthew 2224: 'onchange="'.$jscall.'" />',
1.281 albertel 2225: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2226: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2227: '</label>');
1.586 raeburn 2228: } elsif ($can_assign{'krb4'}) {
2229: $result .= &mt
2230: ('[_1] Kerberos authenticated with domain [_2] '.
2231: '[_3] Version 4 [_4]',
2232: '<label>'.$authtype,
2233: '</label><input type="text" size="10" name="krbarg" '.
2234: 'value="'.$krbarg.'" '.
2235: 'onchange="'.$jscall.'" />',
2236: '<label><input type="hidden" name="krbver" value="4" />',
2237: '</label>');
2238: } elsif ($can_assign{'krb5'}) {
2239: $result .= &mt
2240: ('[_1] Kerberos authenticated with domain [_2] '.
2241: '[_3] Version 5 [_4]',
2242: '<label>'.$authtype,
2243: '</label><input type="text" size="10" name="krbarg" '.
2244: 'value="'.$krbarg.'" '.
2245: 'onchange="'.$jscall.'" />',
2246: '<label><input type="hidden" name="krbver" value="5" />',
2247: '</label>');
2248: }
1.32 matthew 2249: return $result;
2250: }
2251:
2252: sub authform_internal{
1.586 raeburn 2253: my %in = (
1.32 matthew 2254: formname => 'document.cu',
2255: kerb_def_dom => 'MSU.EDU',
2256: @_,
2257: );
1.586 raeburn 2258: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2259: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2260: if (defined($in{'curr_authtype'})) {
2261: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2262: if ($can_assign{'int'}) {
1.692.4.2 raeburn 2263: $intcheck = 'checked="checked" ';
1.623 raeburn 2264: if (defined($in{'mode'})) {
2265: if ($in{'mode'} eq 'modifyuser') {
2266: $intcheck = '';
2267: }
2268: }
1.591 raeburn 2269: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2270: $intarg = $in{'curr_autharg'};
2271: }
2272: } else {
2273: $result = &mt('Currently internally authenticated.');
2274: return $result;
1.165 raeburn 2275: }
2276: }
1.586 raeburn 2277: } else {
2278: if ($authnum == 1) {
1.692.4.2 raeburn 2279: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2280: }
2281: }
2282: if (!$can_assign{'int'}) {
2283: return;
1.587 raeburn 2284: } elsif ($authtype eq '') {
1.591 raeburn 2285: if (defined($in{'mode'})) {
1.587 raeburn 2286: if ($in{'mode'} eq 'modifycourse') {
2287: if ($authnum == 1) {
1.692.4.2 raeburn 2288: $authtype = '<input type="hidden" name="login" value="int" />';
1.587 raeburn 2289: }
2290: }
2291: }
1.165 raeburn 2292: }
1.586 raeburn 2293: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2294: if ($authtype eq '') {
2295: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2296: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2297: }
1.605 bisitz 2298: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2299: $intarg.'" onchange="'.$jscall.'" />';
2300: $result = &mt
1.144 matthew 2301: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2302: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2303: $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 2304: return $result;
2305: }
2306:
2307: sub authform_local{
2308: my %in = (
2309: formname => 'document.cu',
2310: kerb_def_dom => 'MSU.EDU',
2311: @_,
2312: );
1.586 raeburn 2313: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2314: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2315: if (defined($in{'curr_authtype'})) {
2316: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2317: if ($can_assign{'loc'}) {
1.692.4.2 raeburn 2318: $loccheck = 'checked="checked" ';
1.623 raeburn 2319: if (defined($in{'mode'})) {
2320: if ($in{'mode'} eq 'modifyuser') {
2321: $loccheck = '';
2322: }
2323: }
1.591 raeburn 2324: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2325: $locarg = $in{'curr_autharg'};
2326: }
2327: } else {
2328: $result = &mt('Currently using local (institutional) authentication.');
2329: return $result;
1.165 raeburn 2330: }
2331: }
1.586 raeburn 2332: } else {
2333: if ($authnum == 1) {
1.692.4.2 raeburn 2334: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2335: }
2336: }
2337: if (!$can_assign{'loc'}) {
2338: return;
1.587 raeburn 2339: } elsif ($authtype eq '') {
1.591 raeburn 2340: if (defined($in{'mode'})) {
1.587 raeburn 2341: if ($in{'mode'} eq 'modifycourse') {
2342: if ($authnum == 1) {
1.692.4.2 raeburn 2343: $authtype = '<input type="hidden" name="login" value="loc" />';
1.587 raeburn 2344: }
2345: }
2346: }
1.165 raeburn 2347: }
1.586 raeburn 2348: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2349: if ($authtype eq '') {
2350: $authtype = '<input type="radio" name="login" value="loc" '.
2351: $loccheck.' onchange="'.$jscall.'" onclick="'.
2352: $jscall.'" />';
2353: }
2354: $autharg = '<input type="text" size="10" name="locarg" value="'.
2355: $locarg.'" onchange="'.$jscall.'" />';
2356: $result = &mt('[_1] Local Authentication with argument [_2]',
2357: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2358: return $result;
2359: }
2360:
2361: sub authform_filesystem{
2362: my %in = (
2363: formname => 'document.cu',
2364: kerb_def_dom => 'MSU.EDU',
2365: @_,
2366: );
1.586 raeburn 2367: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2368: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2369: if (defined($in{'curr_authtype'})) {
2370: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2371: if ($can_assign{'fsys'}) {
1.692.4.2 raeburn 2372: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2373: if (defined($in{'mode'})) {
2374: if ($in{'mode'} eq 'modifyuser') {
2375: $fsyscheck = '';
2376: }
2377: }
1.586 raeburn 2378: } else {
2379: $result = &mt('Currently Filesystem Authenticated.');
2380: return $result;
2381: }
2382: }
2383: } else {
2384: if ($authnum == 1) {
1.692.4.2 raeburn 2385: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2386: }
2387: }
2388: if (!$can_assign{'fsys'}) {
2389: return;
1.587 raeburn 2390: } elsif ($authtype eq '') {
1.591 raeburn 2391: if (defined($in{'mode'})) {
1.587 raeburn 2392: if ($in{'mode'} eq 'modifycourse') {
2393: if ($authnum == 1) {
1.692.4.2 raeburn 2394: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587 raeburn 2395: }
2396: }
2397: }
1.586 raeburn 2398: }
2399: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2400: if ($authtype eq '') {
2401: $authtype = '<input type="radio" name="login" value="fsys" '.
2402: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2403: $jscall.'" />';
2404: }
2405: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2406: ' onchange="'.$jscall.'" />';
2407: $result = &mt
1.144 matthew 2408: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2409: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2410: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2411: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2412: 'onchange="'.$jscall.'" />');
1.32 matthew 2413: return $result;
2414: }
2415:
1.586 raeburn 2416: sub get_assignable_auth {
2417: my ($dom) = @_;
2418: if ($dom eq '') {
2419: $dom = $env{'request.role.domain'};
2420: }
2421: my %can_assign = (
2422: krb4 => 1,
2423: krb5 => 1,
2424: int => 1,
2425: loc => 1,
2426: );
2427: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2428: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2429: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2430: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2431: my $context;
2432: if ($env{'request.role'} =~ /^au/) {
2433: $context = 'author';
2434: } elsif ($env{'request.role'} =~ /^dc/) {
2435: $context = 'domain';
2436: } elsif ($env{'request.course.id'}) {
2437: $context = 'course';
2438: }
2439: if ($context) {
2440: if (ref($authhash->{$context}) eq 'HASH') {
2441: %can_assign = %{$authhash->{$context}};
2442: }
2443: }
2444: }
2445: }
2446: my $authnum = 0;
2447: foreach my $key (keys(%can_assign)) {
2448: if ($can_assign{$key}) {
2449: $authnum ++;
2450: }
2451: }
2452: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2453: $authnum --;
2454: }
2455: return ($authnum,%can_assign);
2456: }
2457:
1.80 albertel 2458: ###############################################################
2459: ## Get Kerberos Defaults for Domain ##
2460: ###############################################################
2461: ##
2462: ## Returns default kerberos version and an associated argument
2463: ## as listed in file domain.tab. If not listed, provides
2464: ## appropriate default domain and kerberos version.
2465: ##
2466: #-------------------------------------------
2467:
2468: =pod
2469:
1.648 raeburn 2470: =item * &get_kerberos_defaults()
1.80 albertel 2471:
2472: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2473: version and domain. If not found, it defaults to version 4 and the
2474: domain of the server.
1.80 albertel 2475:
1.648 raeburn 2476: =over 4
2477:
1.80 albertel 2478: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2479:
1.648 raeburn 2480: =back
2481:
2482: =back
2483:
1.80 albertel 2484: =cut
2485:
2486: #-------------------------------------------
2487: sub get_kerberos_defaults {
2488: my $domain=shift;
1.641 raeburn 2489: my ($krbdef,$krbdefdom);
2490: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2491: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2492: $krbdef = $domdefaults{'auth_def'};
2493: $krbdefdom = $domdefaults{'auth_arg_def'};
2494: } else {
1.80 albertel 2495: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2496: my $krbdefdom=$1;
2497: $krbdefdom=~tr/a-z/A-Z/;
2498: $krbdef = "krb4";
2499: }
2500: return ($krbdef,$krbdefdom);
2501: }
1.112 bowersj2 2502:
1.32 matthew 2503:
1.46 matthew 2504: ###############################################################
2505: ## Thesaurus Functions ##
2506: ###############################################################
1.20 www 2507:
1.46 matthew 2508: =pod
1.20 www 2509:
1.112 bowersj2 2510: =head1 Thesaurus Functions
2511:
2512: =over 4
2513:
1.648 raeburn 2514: =item * &initialize_keywords()
1.46 matthew 2515:
2516: Initializes the package variable %Keywords if it is empty. Uses the
2517: package variable $thesaurus_db_file.
2518:
2519: =cut
2520:
2521: ###################################################
2522:
2523: sub initialize_keywords {
2524: return 1 if (scalar keys(%Keywords));
2525: # If we are here, %Keywords is empty, so fill it up
2526: # Make sure the file we need exists...
2527: if (! -e $thesaurus_db_file) {
2528: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2529: " failed because it does not exist");
2530: return 0;
2531: }
2532: # Set up the hash as a database
2533: my %thesaurus_db;
2534: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2535: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2536: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2537: $thesaurus_db_file);
2538: return 0;
2539: }
2540: # Get the average number of appearances of a word.
2541: my $avecount = $thesaurus_db{'average.count'};
2542: # Put keywords (those that appear > average) into %Keywords
2543: while (my ($word,$data)=each (%thesaurus_db)) {
2544: my ($count,undef) = split /:/,$data;
2545: $Keywords{$word}++ if ($count > $avecount);
2546: }
2547: untie %thesaurus_db;
2548: # Remove special values from %Keywords.
1.356 albertel 2549: foreach my $value ('total.count','average.count') {
2550: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2551: }
1.46 matthew 2552: return 1;
2553: }
2554:
2555: ###################################################
2556:
2557: =pod
2558:
1.648 raeburn 2559: =item * &keyword($word)
1.46 matthew 2560:
2561: Returns true if $word is a keyword. A keyword is a word that appears more
2562: than the average number of times in the thesaurus database. Calls
2563: &initialize_keywords
2564:
2565: =cut
2566:
2567: ###################################################
1.20 www 2568:
2569: sub keyword {
1.46 matthew 2570: return if (!&initialize_keywords());
2571: my $word=lc(shift());
2572: $word=~s/\W//g;
2573: return exists($Keywords{$word});
1.20 www 2574: }
1.46 matthew 2575:
2576: ###############################################################
2577:
2578: =pod
1.20 www 2579:
1.648 raeburn 2580: =item * &get_related_words()
1.46 matthew 2581:
1.160 matthew 2582: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2583: an array of words. If the keyword is not in the thesaurus, an empty array
2584: will be returned. The order of the words returned is determined by the
2585: database which holds them.
2586:
2587: Uses global $thesaurus_db_file.
2588:
2589: =cut
2590:
2591: ###############################################################
2592: sub get_related_words {
2593: my $keyword = shift;
2594: my %thesaurus_db;
2595: if (! -e $thesaurus_db_file) {
2596: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2597: "failed because the file does not exist");
2598: return ();
2599: }
2600: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2601: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2602: return ();
2603: }
2604: my @Words=();
1.429 www 2605: my $count=0;
1.46 matthew 2606: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2607: # The first element is the number of times
2608: # the word appears. We do not need it now.
1.429 www 2609: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2610: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2611: my $threshold=$mostfrequentcount/10;
2612: foreach my $possibleword (@RelatedWords) {
2613: my ($word,$wordcount)=split(/\,/,$possibleword);
2614: if ($wordcount>$threshold) {
2615: push(@Words,$word);
2616: $count++;
2617: if ($count>10) { last; }
2618: }
1.20 www 2619: }
2620: }
1.46 matthew 2621: untie %thesaurus_db;
2622: return @Words;
1.14 harris41 2623: }
1.46 matthew 2624:
1.112 bowersj2 2625: =pod
2626:
2627: =back
2628:
2629: =cut
1.61 www 2630:
2631: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2632: =pod
2633:
1.112 bowersj2 2634: =head1 User Name Functions
2635:
2636: =over 4
2637:
1.648 raeburn 2638: =item * &plainname($uname,$udom,$first)
1.81 albertel 2639:
1.112 bowersj2 2640: Takes a users logon name and returns it as a string in
1.226 albertel 2641: "first middle last generation" form
2642: if $first is set to 'lastname' then it returns it as
2643: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2644:
2645: =cut
1.61 www 2646:
1.295 www 2647:
1.81 albertel 2648: ###############################################################
1.61 www 2649: sub plainname {
1.226 albertel 2650: my ($uname,$udom,$first)=@_;
1.537 albertel 2651: return if (!defined($uname) || !defined($udom));
1.295 www 2652: my %names=&getnames($uname,$udom);
1.226 albertel 2653: my $name=&Apache::lonnet::format_name($names{'firstname'},
2654: $names{'middlename'},
2655: $names{'lastname'},
2656: $names{'generation'},$first);
2657: $name=~s/^\s+//;
1.62 www 2658: $name=~s/\s+$//;
2659: $name=~s/\s+/ /g;
1.353 albertel 2660: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2661: return $name;
1.61 www 2662: }
1.66 www 2663:
2664: # -------------------------------------------------------------------- Nickname
1.81 albertel 2665: =pod
2666:
1.648 raeburn 2667: =item * &nickname($uname,$udom)
1.81 albertel 2668:
2669: Gets a users name and returns it as a string as
2670:
2671: ""nickname""
1.66 www 2672:
1.81 albertel 2673: if the user has a nickname or
2674:
2675: "first middle last generation"
2676:
2677: if the user does not
2678:
2679: =cut
1.66 www 2680:
2681: sub nickname {
2682: my ($uname,$udom)=@_;
1.537 albertel 2683: return if (!defined($uname) || !defined($udom));
1.295 www 2684: my %names=&getnames($uname,$udom);
1.68 albertel 2685: my $name=$names{'nickname'};
1.66 www 2686: if ($name) {
2687: $name='"'.$name.'"';
2688: } else {
2689: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2690: $names{'lastname'}.' '.$names{'generation'};
2691: $name=~s/\s+$//;
2692: $name=~s/\s+/ /g;
2693: }
2694: return $name;
2695: }
2696:
1.295 www 2697: sub getnames {
2698: my ($uname,$udom)=@_;
1.537 albertel 2699: return if (!defined($uname) || !defined($udom));
1.433 albertel 2700: if ($udom eq 'public' && $uname eq 'public') {
2701: return ('lastname' => &mt('Public'));
2702: }
1.295 www 2703: my $id=$uname.':'.$udom;
2704: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2705: if ($cached) {
2706: return %{$names};
2707: } else {
2708: my %loadnames=&Apache::lonnet::get('environment',
2709: ['firstname','middlename','lastname','generation','nickname'],
2710: $udom,$uname);
2711: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2712: return %loadnames;
2713: }
2714: }
1.61 www 2715:
1.542 raeburn 2716: # -------------------------------------------------------------------- getemails
1.648 raeburn 2717:
1.542 raeburn 2718: =pod
2719:
1.648 raeburn 2720: =item * &getemails($uname,$udom)
1.542 raeburn 2721:
2722: Gets a user's email information and returns it as a hash with keys:
2723: notification, critnotification, permanentemail
2724:
2725: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2726: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2727:
1.648 raeburn 2728:
1.542 raeburn 2729: =cut
2730:
1.648 raeburn 2731:
1.466 albertel 2732: sub getemails {
2733: my ($uname,$udom)=@_;
2734: if ($udom eq 'public' && $uname eq 'public') {
2735: return;
2736: }
1.467 www 2737: if (!$udom) { $udom=$env{'user.domain'}; }
2738: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2739: my $id=$uname.':'.$udom;
2740: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2741: if ($cached) {
2742: return %{$names};
2743: } else {
2744: my %loadnames=&Apache::lonnet::get('environment',
2745: ['notification','critnotification',
2746: 'permanentemail'],
2747: $udom,$uname);
2748: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2749: return %loadnames;
2750: }
2751: }
2752:
1.551 albertel 2753: sub flush_email_cache {
2754: my ($uname,$udom)=@_;
2755: if (!$udom) { $udom =$env{'user.domain'}; }
2756: if (!$uname) { $uname=$env{'user.name'}; }
2757: return if ($udom eq 'public' && $uname eq 'public');
2758: my $id=$uname.':'.$udom;
2759: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2760: }
2761:
1.692.4.2 raeburn 2762: # -------------------------------------------------------------------- getlangs
2763:
2764: =pod
2765:
2766: =item * &getlangs($uname,$udom)
2767:
2768: Gets a user's language preference and returns it as a hash with key:
2769: language.
2770:
2771: =cut
2772:
2773:
2774: sub getlangs {
2775: my ($uname,$udom) = @_;
2776: if (!$udom) { $udom =$env{'user.domain'}; }
2777: if (!$uname) { $uname=$env{'user.name'}; }
2778: my $id=$uname.':'.$udom;
2779: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2780: if ($cached) {
2781: return %{$langs};
2782: } else {
2783: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2784: $udom,$uname);
2785: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2786: return %loadlangs;
2787: }
2788: }
2789:
2790: sub flush_langs_cache {
2791: my ($uname,$udom)=@_;
2792: if (!$udom) { $udom =$env{'user.domain'}; }
2793: if (!$uname) { $uname=$env{'user.name'}; }
2794: return if ($udom eq 'public' && $uname eq 'public');
2795: my $id=$uname.':'.$udom;
2796: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2797: }
2798:
1.61 www 2799: # ------------------------------------------------------------------ Screenname
1.81 albertel 2800:
2801: =pod
2802:
1.648 raeburn 2803: =item * &screenname($uname,$udom)
1.81 albertel 2804:
2805: Gets a users screenname and returns it as a string
2806:
2807: =cut
1.61 www 2808:
2809: sub screenname {
2810: my ($uname,$udom)=@_;
1.258 albertel 2811: if ($uname eq $env{'user.name'} &&
2812: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2813: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2814: return $names{'screenname'};
1.62 www 2815: }
2816:
1.692.4.2 raeburn 2817: # ------------------------------------------------------------- Confirm Wrapper
2818: =pod
2819:
2820: =item confirmwrapper
2821:
2822: Wrap messages about completion of operation in box
2823:
2824: =cut
2825:
2826: sub confirmwrapper {
2827: my ($message)=@_;
2828: if ($message) {
2829: return "\n".'<div class="LC_confirm_box">'."\n"
2830: .$message."\n"
2831: .'</div>'."\n";
2832: } else {
2833: return $message;
2834: }
2835: }
1.212 albertel 2836:
1.62 www 2837: # ------------------------------------------------------------- Message Wrapper
2838:
2839: sub messagewrapper {
1.369 www 2840: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2841: return
1.441 albertel 2842: '<a href="/adm/email?compose=individual&'.
2843: 'recname='.$username.'&recdom='.$domain.
2844: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2845: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2846: }
2847: # --------------------------------------------------------------- Notes Wrapper
2848:
2849: sub noteswrapper {
2850: my ($link,$un,$do)=@_;
2851: return
2852: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2853: }
2854: # ------------------------------------------------------------- Aboutme Wrapper
2855:
2856: sub aboutmewrapper {
1.166 www 2857: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2858: if (!defined($username) && !defined($domain)) {
2859: return;
2860: }
1.205 www 2861: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.692.4.2 raeburn 2862: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2863: }
2864:
2865: # ------------------------------------------------------------ Syllabus Wrapper
2866:
2867:
2868: sub syllabuswrapper {
1.109 matthew 2869: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2870: if ($fontcolor) {
2871: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2872: }
1.208 matthew 2873: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2874: }
1.14 harris41 2875:
1.208 matthew 2876: sub track_student_link {
1.268 albertel 2877: my ($linktext,$sname,$sdom,$target,$start) = @_;
2878: my $link ="/adm/trackstudent?";
1.208 matthew 2879: my $title = 'View recent activity';
2880: if (defined($sname) && $sname !~ /^\s*$/ &&
2881: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2882: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2883: $title .= ' of this student';
1.268 albertel 2884: }
1.208 matthew 2885: if (defined($target) && $target !~ /^\s*$/) {
2886: $target = qq{target="$target"};
2887: } else {
2888: $target = '';
2889: }
1.268 albertel 2890: if ($start) { $link.='&start='.$start; }
1.554 albertel 2891: $title = &mt($title);
2892: $linktext = &mt($linktext);
1.448 albertel 2893: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2894: &help_open_topic('View_recent_activity');
1.208 matthew 2895: }
2896:
1.692.4.2 raeburn 2897: sub slot_reservations_link {
2898: my ($linktext,$sname,$sdom,$target) = @_;
2899: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
2900: my $title = 'View slot reservation history';
2901: if (defined($sname) && $sname !~ /^\s*$/ &&
2902: defined($sdom) && $sdom !~ /^\s*$/) {
2903: $link .= "&uname=$sname&udom=$sdom";
2904: $title .= ' of this student';
2905: }
2906: if (defined($target) && $target !~ /^\s*$/) {
2907: $target = qq{target="$target"};
2908: } else {
2909: $target = '';
2910: }
2911: $title = &mt($title);
2912: $linktext = &mt($linktext);
2913: return qq{<a href="$link" title="$title" $target>$linktext</a>};
2914: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
2915:
2916: }
2917:
1.508 www 2918: # ===================================================== Display a student photo
2919:
2920:
1.509 albertel 2921: sub student_image_tag {
1.508 www 2922: my ($domain,$user)=@_;
2923: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2924: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2925: return '<img src="'.$imgsrc.'" align="right" />';
2926: } else {
2927: return '';
2928: }
2929: }
2930:
1.112 bowersj2 2931: =pod
2932:
2933: =back
2934:
2935: =head1 Access .tab File Data
2936:
2937: =over 4
2938:
1.648 raeburn 2939: =item * &languageids()
1.112 bowersj2 2940:
2941: returns list of all language ids
2942:
2943: =cut
2944:
1.14 harris41 2945: sub languageids {
1.16 harris41 2946: return sort(keys(%language));
1.14 harris41 2947: }
2948:
1.112 bowersj2 2949: =pod
2950:
1.648 raeburn 2951: =item * &languagedescription()
1.112 bowersj2 2952:
2953: returns description of a specified language id
2954:
2955: =cut
2956:
1.14 harris41 2957: sub languagedescription {
1.125 www 2958: my $code=shift;
2959: return ($supported_language{$code}?'* ':'').
2960: $language{$code}.
1.126 www 2961: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2962: }
2963:
2964: sub plainlanguagedescription {
2965: my $code=shift;
2966: return $language{$code};
2967: }
2968:
2969: sub supportedlanguagecode {
2970: my $code=shift;
2971: return $supported_language{$code};
1.97 www 2972: }
2973:
1.112 bowersj2 2974: =pod
2975:
1.648 raeburn 2976: =item * ©rightids()
1.112 bowersj2 2977:
2978: returns list of all copyrights
2979:
2980: =cut
2981:
2982: sub copyrightids {
2983: return sort(keys(%cprtag));
2984: }
2985:
2986: =pod
2987:
1.648 raeburn 2988: =item * ©rightdescription()
1.112 bowersj2 2989:
2990: returns description of a specified copyright id
2991:
2992: =cut
2993:
2994: sub copyrightdescription {
1.166 www 2995: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2996: }
1.197 matthew 2997:
2998: =pod
2999:
1.648 raeburn 3000: =item * &source_copyrightids()
1.192 taceyjo1 3001:
3002: returns list of all source copyrights
3003:
3004: =cut
3005:
3006: sub source_copyrightids {
3007: return sort(keys(%scprtag));
3008: }
3009:
3010: =pod
3011:
1.648 raeburn 3012: =item * &source_copyrightdescription()
1.192 taceyjo1 3013:
3014: returns description of a specified source copyright id
3015:
3016: =cut
3017:
3018: sub source_copyrightdescription {
3019: return &mt($scprtag{shift(@_)});
3020: }
1.112 bowersj2 3021:
3022: =pod
3023:
1.648 raeburn 3024: =item * &filecategories()
1.112 bowersj2 3025:
3026: returns list of all file categories
3027:
3028: =cut
3029:
3030: sub filecategories {
3031: return sort(keys(%category_extensions));
3032: }
3033:
3034: =pod
3035:
1.648 raeburn 3036: =item * &filecategorytypes()
1.112 bowersj2 3037:
3038: returns list of file types belonging to a given file
3039: category
3040:
3041: =cut
3042:
3043: sub filecategorytypes {
1.356 albertel 3044: my ($cat) = @_;
3045: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3046: }
3047:
3048: =pod
3049:
1.648 raeburn 3050: =item * &fileembstyle()
1.112 bowersj2 3051:
3052: returns embedding style for a specified file type
3053:
3054: =cut
3055:
3056: sub fileembstyle {
3057: return $fe{lc(shift(@_))};
1.169 www 3058: }
3059:
1.351 www 3060: sub filemimetype {
3061: return $fm{lc(shift(@_))};
3062: }
3063:
1.169 www 3064:
3065: sub filecategoryselect {
3066: my ($name,$value)=@_;
1.189 matthew 3067: return &select_form($value,$name,
1.169 www 3068: '' => &mt('Any category'),
3069: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 3070: }
3071:
3072: =pod
3073:
1.648 raeburn 3074: =item * &filedescription()
1.112 bowersj2 3075:
3076: returns description for a specified file type
3077:
3078: =cut
3079:
3080: sub filedescription {
1.188 matthew 3081: my $file_description = $fd{lc(shift())};
3082: $file_description =~ s:([\[\]]):~$1:g;
3083: return &mt($file_description);
1.112 bowersj2 3084: }
3085:
3086: =pod
3087:
1.648 raeburn 3088: =item * &filedescriptionex()
1.112 bowersj2 3089:
3090: returns description for a specified file type with
3091: extra formatting
3092:
3093: =cut
3094:
3095: sub filedescriptionex {
3096: my $ex=shift;
1.188 matthew 3097: my $file_description = $fd{lc($ex)};
3098: $file_description =~ s:([\[\]]):~$1:g;
3099: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3100: }
3101:
3102: # End of .tab access
3103: =pod
3104:
3105: =back
3106:
3107: =cut
3108:
3109: # ------------------------------------------------------------------ File Types
3110: sub fileextensions {
3111: return sort(keys(%fe));
3112: }
3113:
1.97 www 3114: # ----------------------------------------------------------- Display Languages
3115: # returns a hash with all desired display languages
3116: #
3117:
3118: sub display_languages {
3119: my %languages=();
1.692.4.1 raeburn 3120: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3121: $languages{$lang}=1;
1.97 www 3122: }
3123: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3124: if ($env{'form.displaylanguage'}) {
1.356 albertel 3125: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3126: $languages{$lang}=1;
1.97 www 3127: }
3128: }
3129: return %languages;
1.14 harris41 3130: }
3131:
1.582 albertel 3132: sub languages {
3133: my ($possible_langs) = @_;
1.692.4.1 raeburn 3134: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3135: if (!ref($possible_langs)) {
3136: if( wantarray ) {
3137: return @preferred_langs;
3138: } else {
3139: return $preferred_langs[0];
3140: }
3141: }
3142: my %possibilities = map { $_ => 1 } (@$possible_langs);
3143: my @preferred_possibilities;
3144: foreach my $preferred_lang (@preferred_langs) {
3145: if (exists($possibilities{$preferred_lang})) {
3146: push(@preferred_possibilities, $preferred_lang);
3147: }
3148: }
3149: if( wantarray ) {
3150: return @preferred_possibilities;
3151: }
3152: return $preferred_possibilities[0];
3153: }
3154:
1.692.4.2 raeburn 3155: sub user_lang {
3156: my ($touname,$toudom,$fromcid) = @_;
3157: my @userlangs;
3158: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3159: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3160: $env{'course.'.$fromcid.'.languages'}));
3161: } else {
3162: my %langhash = &getlangs($touname,$toudom);
3163: if ($langhash{'languages'} ne '') {
3164: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3165: } else {
3166: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3167: if ($domdefs{'lang_def'} ne '') {
3168: @userlangs = ($domdefs{'lang_def'});
3169: }
3170: }
3171: }
3172: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3173: my $user_lh = Apache::localize->get_handle(@languages);
3174: return $user_lh;
3175: }
3176:
1.112 bowersj2 3177: ###############################################################
3178: ## Student Answer Attempts ##
3179: ###############################################################
3180:
3181: =pod
3182:
3183: =head1 Alternate Problem Views
3184:
3185: =over 4
3186:
1.648 raeburn 3187: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3188: $getattempt, $regexp, $gradesub)
3189:
3190: Return string with previous attempt on problem. Arguments:
3191:
3192: =over 4
3193:
3194: =item * $symb: Problem, including path
3195:
3196: =item * $username: username of the desired student
3197:
3198: =item * $domain: domain of the desired student
1.14 harris41 3199:
1.112 bowersj2 3200: =item * $course: Course ID
1.14 harris41 3201:
1.112 bowersj2 3202: =item * $getattempt: Leave blank for all attempts, otherwise put
3203: something
1.14 harris41 3204:
1.112 bowersj2 3205: =item * $regexp: if string matches this regexp, the string will be
3206: sent to $gradesub
1.14 harris41 3207:
1.112 bowersj2 3208: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3209:
1.112 bowersj2 3210: =back
1.14 harris41 3211:
1.112 bowersj2 3212: The output string is a table containing all desired attempts, if any.
1.16 harris41 3213:
1.112 bowersj2 3214: =cut
1.1 albertel 3215:
3216: sub get_previous_attempt {
1.43 ng 3217: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3218: my $prevattempts='';
1.43 ng 3219: no strict 'refs';
1.1 albertel 3220: if ($symb) {
1.3 albertel 3221: my (%returnhash)=
3222: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3223: if ($returnhash{'version'}) {
3224: my %lasthash=();
3225: my $version;
3226: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3227: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3228: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3229: }
1.1 albertel 3230: }
1.596 albertel 3231: $prevattempts=&start_data_table().&start_data_table_header_row();
3232: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3233: foreach my $key (sort(keys(%lasthash))) {
3234: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3235: if ($#parts > 0) {
1.31 albertel 3236: my $data=$parts[-1];
3237: pop(@parts);
1.596 albertel 3238: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3239: } else {
1.41 ng 3240: if ($#parts == 0) {
3241: $prevattempts.='<th>'.$parts[0].'</th>';
3242: } else {
3243: $prevattempts.='<th>'.$ign.'</th>';
3244: }
1.31 albertel 3245: }
1.16 harris41 3246: }
1.596 albertel 3247: $prevattempts.=&end_data_table_header_row();
1.40 ng 3248: if ($getattempt eq '') {
3249: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3250: $prevattempts.=&start_data_table_row().
3251: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3252: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3253: my $value = &format_previous_attempt_value($key,
3254: $returnhash{$version.':'.$key});
3255: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3256: }
1.596 albertel 3257: $prevattempts.=&end_data_table_row();
1.40 ng 3258: }
1.1 albertel 3259: }
1.596 albertel 3260: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3261: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3262: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3263: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3264: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3265: }
1.596 albertel 3266: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3267: } else {
1.596 albertel 3268: $prevattempts=
3269: &start_data_table().&start_data_table_row().
3270: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3271: &end_data_table_row().&end_data_table();
1.1 albertel 3272: }
3273: } else {
1.596 albertel 3274: $prevattempts=
3275: &start_data_table().&start_data_table_row().
3276: '<td>'.&mt('No data.').'</td>'.
3277: &end_data_table_row().&end_data_table();
1.1 albertel 3278: }
1.10 albertel 3279: }
3280:
1.581 albertel 3281: sub format_previous_attempt_value {
3282: my ($key,$value) = @_;
3283: if ($key =~ /timestamp/) {
3284: $value = &Apache::lonlocal::locallocaltime($value);
3285: } elsif (ref($value) eq 'ARRAY') {
3286: $value = '('.join(', ', @{ $value }).')';
3287: } else {
3288: $value = &unescape($value);
3289: }
3290: return $value;
3291: }
3292:
3293:
1.107 albertel 3294: sub relative_to_absolute {
3295: my ($url,$output)=@_;
3296: my $parser=HTML::TokeParser->new(\$output);
3297: my $token;
3298: my $thisdir=$url;
3299: my @rlinks=();
3300: while ($token=$parser->get_token) {
3301: if ($token->[0] eq 'S') {
3302: if ($token->[1] eq 'a') {
3303: if ($token->[2]->{'href'}) {
3304: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3305: }
3306: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3307: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3308: } elsif ($token->[1] eq 'base') {
3309: $thisdir=$token->[2]->{'href'};
3310: }
3311: }
3312: }
3313: $thisdir=~s-/[^/]*$--;
1.356 albertel 3314: foreach my $link (@rlinks) {
1.692.4.2 raeburn 3315: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3316: ($link=~/^\//) ||
3317: ($link=~/^javascript:/i) ||
3318: ($link=~/^mailto:/i) ||
3319: ($link=~/^\#/)) {
3320: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3321: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3322: }
3323: }
3324: # -------------------------------------------------- Deal with Applet codebases
3325: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3326: return $output;
3327: }
3328:
1.112 bowersj2 3329: =pod
3330:
1.648 raeburn 3331: =item * &get_student_view()
1.112 bowersj2 3332:
3333: show a snapshot of what student was looking at
3334:
3335: =cut
3336:
1.10 albertel 3337: sub get_student_view {
1.186 albertel 3338: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3339: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3340: my (%form);
1.10 albertel 3341: my @elements=('symb','courseid','domain','username');
3342: foreach my $element (@elements) {
1.186 albertel 3343: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3344: }
1.186 albertel 3345: if (defined($moreenv)) {
3346: %form=(%form,%{$moreenv});
3347: }
1.236 albertel 3348: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3349: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3350: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3351: $userview=~s/\<body[^\>]*\>//gi;
3352: $userview=~s/\<\/body\>//gi;
3353: $userview=~s/\<html\>//gi;
3354: $userview=~s/\<\/html\>//gi;
3355: $userview=~s/\<head\>//gi;
3356: $userview=~s/\<\/head\>//gi;
3357: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3358: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3359: if (wantarray) {
3360: return ($userview,$response);
3361: } else {
3362: return $userview;
3363: }
3364: }
3365:
3366: sub get_student_view_with_retries {
3367: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3368:
3369: my $ok = 0; # True if we got a good response.
3370: my $content;
3371: my $response;
3372:
3373: # Try to get the student_view done. within the retries count:
3374:
3375: do {
3376: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3377: $ok = $response->is_success;
3378: if (!$ok) {
3379: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3380: }
3381: $retries--;
3382: } while (!$ok && ($retries > 0));
3383:
3384: if (!$ok) {
3385: $content = ''; # On error return an empty content.
3386: }
1.651 www 3387: if (wantarray) {
3388: return ($content, $response);
3389: } else {
3390: return $content;
3391: }
1.11 albertel 3392: }
3393:
1.112 bowersj2 3394: =pod
3395:
1.648 raeburn 3396: =item * &get_student_answers()
1.112 bowersj2 3397:
3398: show a snapshot of how student was answering problem
3399:
3400: =cut
3401:
1.11 albertel 3402: sub get_student_answers {
1.100 sakharuk 3403: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3404: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3405: my (%moreenv);
1.11 albertel 3406: my @elements=('symb','courseid','domain','username');
3407: foreach my $element (@elements) {
1.186 albertel 3408: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3409: }
1.186 albertel 3410: $moreenv{'grade_target'}='answer';
3411: %moreenv=(%form,%moreenv);
1.497 raeburn 3412: $feedurl = &Apache::lonnet::clutter($feedurl);
3413: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3414: return $userview;
1.1 albertel 3415: }
1.116 albertel 3416:
3417: =pod
3418:
3419: =item * &submlink()
3420:
1.242 albertel 3421: Inputs: $text $uname $udom $symb $target
1.116 albertel 3422:
3423: Returns: A link to grades.pm such as to see the SUBM view of a student
3424:
3425: =cut
3426:
3427: ###############################################
3428: sub submlink {
1.242 albertel 3429: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3430: if (!($uname && $udom)) {
3431: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3432: &Apache::lonnet::whichuser($symb);
1.116 albertel 3433: if (!$symb) { $symb=$cursymb; }
3434: }
1.254 matthew 3435: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3436: $symb=&escape($symb);
1.242 albertel 3437: if ($target) { $target="target=\"$target\""; }
3438: return '<a href="/adm/grades?&command=submission&'.
3439: 'symb='.$symb.'&student='.$uname.
3440: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3441: }
3442: ##############################################
3443:
3444: =pod
3445:
3446: =item * &pgrdlink()
3447:
3448: Inputs: $text $uname $udom $symb $target
3449:
3450: Returns: A link to grades.pm such as to see the PGRD view of a student
3451:
3452: =cut
3453:
3454: ###############################################
3455: sub pgrdlink {
3456: my $link=&submlink(@_);
3457: $link=~s/(&command=submission)/$1&showgrading=yes/;
3458: return $link;
3459: }
3460: ##############################################
3461:
3462: =pod
3463:
3464: =item * &pprmlink()
3465:
3466: Inputs: $text $uname $udom $symb $target
3467:
3468: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3469: student and a specific resource
1.242 albertel 3470:
3471: =cut
3472:
3473: ###############################################
3474: sub pprmlink {
3475: my ($text,$uname,$udom,$symb,$target)=@_;
3476: if (!($uname && $udom)) {
3477: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3478: &Apache::lonnet::whichuser($symb);
1.242 albertel 3479: if (!$symb) { $symb=$cursymb; }
3480: }
1.254 matthew 3481: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3482: $symb=&escape($symb);
1.242 albertel 3483: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3484: return '<a href="/adm/parmset?command=set&'.
3485: 'symb='.$symb.'&uname='.$uname.
3486: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3487: }
3488: ##############################################
1.37 matthew 3489:
1.112 bowersj2 3490: =pod
3491:
3492: =back
3493:
3494: =cut
3495:
1.37 matthew 3496: ###############################################
1.51 www 3497:
3498:
3499: sub timehash {
1.687 raeburn 3500: my ($thistime) = @_;
3501: my $timezone = &Apache::lonlocal::gettimezone();
3502: my $dt = DateTime->from_epoch(epoch => $thistime)
3503: ->set_time_zone($timezone);
3504: my $wday = $dt->day_of_week();
3505: if ($wday == 7) { $wday = 0; }
3506: return ( 'second' => $dt->second(),
3507: 'minute' => $dt->minute(),
3508: 'hour' => $dt->hour(),
3509: 'day' => $dt->day_of_month(),
3510: 'month' => $dt->month(),
3511: 'year' => $dt->year(),
3512: 'weekday' => $wday,
3513: 'dayyear' => $dt->day_of_year(),
3514: 'dlsav' => $dt->is_dst() );
1.51 www 3515: }
3516:
1.370 www 3517: sub utc_string {
3518: my ($date)=@_;
1.371 www 3519: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3520: }
3521:
1.51 www 3522: sub maketime {
3523: my %th=@_;
1.687 raeburn 3524: my ($epoch_time,$timezone,$dt);
3525: $timezone = &Apache::lonlocal::gettimezone();
3526: eval {
3527: $dt = DateTime->new( year => $th{'year'},
3528: month => $th{'month'},
3529: day => $th{'day'},
3530: hour => $th{'hour'},
3531: minute => $th{'minute'},
3532: second => $th{'second'},
3533: time_zone => $timezone,
3534: );
3535: };
3536: if (!$@) {
3537: $epoch_time = $dt->epoch;
3538: if ($epoch_time) {
3539: return $epoch_time;
3540: }
3541: }
1.51 www 3542: return POSIX::mktime(
3543: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3544: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3545: }
3546:
3547: #########################################
1.51 www 3548:
3549: sub findallcourses {
1.482 raeburn 3550: my ($roles,$uname,$udom) = @_;
1.355 albertel 3551: my %roles;
3552: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3553: my %courses;
1.51 www 3554: my $now=time;
1.482 raeburn 3555: if (!defined($uname)) {
3556: $uname = $env{'user.name'};
3557: }
3558: if (!defined($udom)) {
3559: $udom = $env{'user.domain'};
3560: }
3561: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3562: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3563: if (!%roles) {
3564: %roles = (
3565: cc => 1,
3566: in => 1,
3567: ep => 1,
3568: ta => 1,
3569: cr => 1,
3570: st => 1,
3571: );
3572: }
3573: foreach my $entry (keys(%roleshash)) {
3574: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3575: if ($trole =~ /^cr/) {
3576: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3577: } else {
3578: next if (!exists($roles{$trole}));
3579: }
3580: if ($tend) {
3581: next if ($tend < $now);
3582: }
3583: if ($tstart) {
3584: next if ($tstart > $now);
3585: }
3586: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3587: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3588: if ($secpart eq '') {
3589: ($cnum,$role) = split(/_/,$cnumpart);
3590: $sec = 'none';
3591: $realsec = '';
3592: } else {
3593: $cnum = $cnumpart;
3594: ($sec,$role) = split(/_/,$secpart);
3595: $realsec = $sec;
1.490 raeburn 3596: }
1.482 raeburn 3597: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3598: }
3599: } else {
3600: foreach my $key (keys(%env)) {
1.483 albertel 3601: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3602: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3603: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3604: next if ($role eq 'ca' || $role eq 'aa');
3605: next if (%roles && !exists($roles{$role}));
3606: my ($starttime,$endtime)=split(/\./,$env{$key});
3607: my $active=1;
3608: if ($starttime) {
3609: if ($now<$starttime) { $active=0; }
3610: }
3611: if ($endtime) {
3612: if ($now>$endtime) { $active=0; }
3613: }
3614: if ($active) {
3615: if ($sec eq '') {
3616: $sec = 'none';
3617: }
3618: $courses{$cdom.'_'.$cnum}{$sec} =
3619: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3620: }
3621: }
1.51 www 3622: }
3623: }
1.474 raeburn 3624: return %courses;
1.51 www 3625: }
1.37 matthew 3626:
1.54 www 3627: ###############################################
1.474 raeburn 3628:
3629: sub blockcheck {
1.482 raeburn 3630: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3631:
3632: if (!defined($udom)) {
3633: $udom = $env{'user.domain'};
3634: }
3635: if (!defined($uname)) {
3636: $uname = $env{'user.name'};
3637: }
3638:
3639: # If uname and udom are for a course, check for blocks in the course.
3640:
3641: if (&Apache::lonnet::is_course($udom,$uname)) {
3642: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3643: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3644: return ($startblock,$endblock);
3645: }
1.474 raeburn 3646:
1.502 raeburn 3647: my $startblock = 0;
3648: my $endblock = 0;
1.482 raeburn 3649: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3650:
1.490 raeburn 3651: # If uname is for a user, and activity is course-specific, i.e.,
3652: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3653:
1.490 raeburn 3654: if (($activity eq 'boards' || $activity eq 'chat' ||
3655: $activity eq 'groups') && ($env{'request.course.id'})) {
3656: foreach my $key (keys(%live_courses)) {
3657: if ($key ne $env{'request.course.id'}) {
3658: delete($live_courses{$key});
3659: }
3660: }
3661: }
3662:
3663: my $otheruser = 0;
3664: my %own_courses;
3665: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3666: # Resource belongs to user other than current user.
3667: $otheruser = 1;
3668: # Gather courses for current user
3669: %own_courses =
3670: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3671: }
3672:
3673: # Gather active course roles - course coordinator, instructor,
3674: # exam proctor, ta, student, or custom role.
1.474 raeburn 3675:
3676: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3677: my ($cdom,$cnum);
3678: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3679: $cdom = $env{'course.'.$course.'.domain'};
3680: $cnum = $env{'course.'.$course.'.num'};
3681: } else {
1.490 raeburn 3682: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3683: }
3684: my $no_ownblock = 0;
3685: my $no_userblock = 0;
1.533 raeburn 3686: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3687: # Check if current user has 'evb' priv for this
3688: if (defined($own_courses{$course})) {
3689: foreach my $sec (keys(%{$own_courses{$course}})) {
3690: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3691: if ($sec ne 'none') {
3692: $checkrole .= '/'.$sec;
3693: }
3694: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3695: $no_ownblock = 1;
3696: last;
3697: }
3698: }
3699: }
3700: # if they have 'evb' priv and are currently not playing student
3701: next if (($no_ownblock) &&
3702: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3703: }
1.474 raeburn 3704: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3705: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3706: if ($sec ne 'none') {
1.482 raeburn 3707: $checkrole .= '/'.$sec;
1.474 raeburn 3708: }
1.490 raeburn 3709: if ($otheruser) {
3710: # Resource belongs to user other than current user.
3711: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3712: my ($trole,$tdom,$tnum,$tsec);
3713: my $entry = $live_courses{$course}{$sec};
3714: if ($entry =~ /^cr/) {
3715: ($trole,$tdom,$tnum,$tsec) =
3716: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3717: } else {
3718: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3719: }
3720: my ($spec,$area,$trest,%allroles,%userroles);
3721: $area = '/'.$tdom.'/'.$tnum;
3722: $trest = $tnum;
3723: if ($tsec ne '') {
3724: $area .= '/'.$tsec;
3725: $trest .= '/'.$tsec;
3726: }
3727: $spec = $trole.'.'.$area;
3728: if ($trole =~ /^cr/) {
3729: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3730: $tdom,$spec,$trest,$area);
3731: } else {
3732: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3733: $tdom,$spec,$trest,$area);
3734: }
3735: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3736: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3737: if ($1) {
3738: $no_userblock = 1;
3739: last;
3740: }
3741: }
1.490 raeburn 3742: } else {
3743: # Resource belongs to current user
3744: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3745: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3746: $no_ownblock = 1;
3747: last;
3748: }
1.474 raeburn 3749: }
3750: }
3751: # if they have the evb priv and are currently not playing student
1.482 raeburn 3752: next if (($no_ownblock) &&
1.491 albertel 3753: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3754: next if ($no_userblock);
1.474 raeburn 3755:
1.490 raeburn 3756: # Retrieve blocking times and identity of blocker for course
3757: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3758:
3759: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3760: if (($start != 0) &&
3761: (($startblock == 0) || ($startblock > $start))) {
3762: $startblock = $start;
3763: }
3764: if (($end != 0) &&
3765: (($endblock == 0) || ($endblock < $end))) {
3766: $endblock = $end;
3767: }
1.490 raeburn 3768: }
3769: return ($startblock,$endblock);
3770: }
3771:
3772: sub get_blocks {
3773: my ($setters,$activity,$cdom,$cnum) = @_;
3774: my $startblock = 0;
3775: my $endblock = 0;
3776: my $course = $cdom.'_'.$cnum;
3777: $setters->{$course} = {};
3778: $setters->{$course}{'staff'} = [];
3779: $setters->{$course}{'times'} = [];
3780: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3781: foreach my $record (keys(%records)) {
3782: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3783: if ($start <= time && $end >= time) {
3784: my ($staff_name,$staff_dom,$title,$blocks) =
3785: &parse_block_record($records{$record});
3786: if ($blocks->{$activity} eq 'on') {
3787: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3788: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3789: if ( ($startblock == 0) || ($startblock > $start) ) {
3790: $startblock = $start;
1.490 raeburn 3791: }
1.491 albertel 3792: if ( ($endblock == 0) || ($endblock < $end) ) {
3793: $endblock = $end;
1.474 raeburn 3794: }
3795: }
3796: }
3797: }
3798: return ($startblock,$endblock);
3799: }
3800:
3801: sub parse_block_record {
3802: my ($record) = @_;
3803: my ($setuname,$setudom,$title,$blocks);
3804: if (ref($record) eq 'HASH') {
3805: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3806: $title = &unescape($record->{'event'});
3807: $blocks = $record->{'blocks'};
3808: } else {
3809: my @data = split(/:/,$record,3);
3810: if (scalar(@data) eq 2) {
3811: $title = $data[1];
3812: ($setuname,$setudom) = split(/@/,$data[0]);
3813: } else {
3814: ($setuname,$setudom,$title) = @data;
3815: }
3816: $blocks = { 'com' => 'on' };
3817: }
3818: return ($setuname,$setudom,$title,$blocks);
3819: }
3820:
3821: sub build_block_table {
3822: my ($startblock,$endblock,$setters) = @_;
3823: my %lt = &Apache::lonlocal::texthash(
3824: 'cacb' => 'Currently active communication blocks',
3825: 'cour' => 'Course',
3826: 'dura' => 'Duration',
3827: 'blse' => 'Block set by'
3828: );
3829: my $output;
1.476 raeburn 3830: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3831: $output .= &start_data_table();
3832: $output .= '
3833: <tr>
3834: <th>'.$lt{'cour'}.'</th>
3835: <th>'.$lt{'dura'}.'</th>
3836: <th>'.$lt{'blse'}.'</th>
3837: </tr>
3838: ';
3839: foreach my $course (keys(%{$setters})) {
3840: my %courseinfo=&Apache::lonnet::coursedescription($course);
3841: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3842: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3843: my $fullname = &plainname($uname,$udom);
3844: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3845: && $env{'user.name'} ne 'public'
3846: && $env{'user.domain'} ne 'public') {
3847: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3848: }
1.474 raeburn 3849: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3850: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3851: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3852: $output .= &Apache::loncommon::start_data_table_row().
3853: '<td>'.$courseinfo{'description'}.'</td>'.
3854: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3855: '<td>'.$fullname.'</td>'.
1.474 raeburn 3856: &Apache::loncommon::end_data_table_row();
3857: }
3858: }
3859: $output .= &end_data_table();
3860: }
3861:
1.490 raeburn 3862: sub blocking_status {
3863: my ($activity,$uname,$udom) = @_;
3864: my %setters;
3865: my ($blocked,$output,$ownitem,$is_course);
3866: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3867: if ($startblock && $endblock) {
3868: $blocked = 1;
3869: if (wantarray) {
3870: my $category;
3871: if ($activity eq 'boards') {
3872: $category = 'Discussion posts in this course';
3873: } elsif ($activity eq 'blogs') {
3874: $category = 'Blogs';
3875: } elsif ($activity eq 'port') {
3876: if (defined($uname) && defined($udom)) {
3877: if ($uname eq $env{'user.name'} &&
3878: $udom eq $env{'user.domain'}) {
3879: $ownitem = 1;
3880: }
3881: }
3882: $is_course = &Apache::lonnet::is_course($udom,$uname);
3883: if ($ownitem) {
3884: $category = 'Your portfolio files';
3885: } elsif ($is_course) {
3886: my $coursedesc;
3887: foreach my $course (keys(%setters)) {
3888: my %courseinfo =
3889: &Apache::lonnet::coursedescription($course);
3890: $coursedesc = $courseinfo{'description'};
3891: }
1.692.4.2 raeburn 3892: $category = "Group portfolio files in the course '$coursedesc'";
1.490 raeburn 3893: } else {
3894: $category = 'Portfolio files belonging to ';
3895: if ($env{'user.name'} eq 'public' &&
3896: $env{'user.domain'} eq 'public') {
3897: $category .= &plainname($uname,$udom);
3898: } else {
3899: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3900: }
3901: }
3902: } elsif ($activity eq 'groups') {
3903: $category = 'Groups in this course';
3904: }
3905: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3906: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3907: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3908: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3909: $output .= &build_block_table($startblock,$endblock,\%setters);
3910: }
3911: }
3912: }
3913: if (wantarray) {
3914: return ($blocked,$output);
3915: } else {
3916: return $blocked;
3917: }
3918: }
3919:
1.60 matthew 3920: ###############################################
3921:
1.682 raeburn 3922: sub check_ip_acc {
3923: my ($acc)=@_;
3924: &Apache::lonxml::debug("acc is $acc");
3925: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3926: return 1;
3927: }
3928: my $allowed=0;
3929: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3930:
3931: my $name;
3932: foreach my $pattern (split(',',$acc)) {
3933: $pattern =~ s/^\s*//;
3934: $pattern =~ s/\s*$//;
3935: if ($pattern =~ /\*$/) {
3936: #35.8.*
3937: $pattern=~s/\*//;
3938: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3939: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3940: #35.8.3.[34-56]
3941: my $low=$2;
3942: my $high=$3;
3943: $pattern=$1;
3944: if ($ip =~ /^\Q$pattern\E/) {
3945: my $last=(split(/\./,$ip))[3];
3946: if ($last <=$high && $last >=$low) { $allowed=1; }
3947: }
3948: } elsif ($pattern =~ /^\*/) {
3949: #*.msu.edu
3950: $pattern=~s/\*//;
3951: if (!defined($name)) {
3952: use Socket;
3953: my $netaddr=inet_aton($ip);
3954: ($name)=gethostbyaddr($netaddr,AF_INET);
3955: }
3956: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3957: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3958: #127.0.0.1
3959: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3960: } else {
3961: #some.name.com
3962: if (!defined($name)) {
3963: use Socket;
3964: my $netaddr=inet_aton($ip);
3965: ($name)=gethostbyaddr($netaddr,AF_INET);
3966: }
3967: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3968: }
3969: if ($allowed) { last; }
3970: }
3971: return $allowed;
3972: }
3973:
3974: ###############################################
3975:
1.60 matthew 3976: =pod
3977:
1.112 bowersj2 3978: =head1 Domain Template Functions
3979:
3980: =over 4
3981:
3982: =item * &determinedomain()
1.60 matthew 3983:
3984: Inputs: $domain (usually will be undef)
3985:
1.63 www 3986: Returns: Determines which domain should be used for designs
1.60 matthew 3987:
3988: =cut
1.54 www 3989:
1.60 matthew 3990: ###############################################
1.63 www 3991: sub determinedomain {
3992: my $domain=shift;
1.531 albertel 3993: if (! $domain) {
1.60 matthew 3994: # Determine domain if we have not been given one
3995: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3996: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3997: if ($env{'request.role.domain'}) {
3998: $domain=$env{'request.role.domain'};
1.60 matthew 3999: }
4000: }
1.63 www 4001: return $domain;
4002: }
4003: ###############################################
1.517 raeburn 4004:
1.518 albertel 4005: sub devalidate_domconfig_cache {
4006: my ($udom)=@_;
4007: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4008: }
4009:
4010: # ---------------------- Get domain configuration for a domain
4011: sub get_domainconf {
4012: my ($udom) = @_;
4013: my $cachetime=1800;
4014: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4015: if (defined($cached)) { return %{$result}; }
4016:
4017: my %domconfig = &Apache::lonnet::get_dom('configuration',
4018: ['login','rolecolors'],$udom);
1.632 raeburn 4019: my (%designhash,%legacy);
1.518 albertel 4020: if (keys(%domconfig) > 0) {
4021: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4022: if (keys(%{$domconfig{'login'}})) {
4023: foreach my $key (keys(%{$domconfig{'login'}})) {
1.692.4.2 raeburn 4024: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4025: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4026: $designhash{$udom.'.login.'.$key.'_'.$img} =
4027: $domconfig{'login'}{$key}{$img};
4028: }
4029: } else {
4030: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4031: }
1.632 raeburn 4032: }
4033: } else {
4034: $legacy{'login'} = 1;
1.518 albertel 4035: }
1.632 raeburn 4036: } else {
4037: $legacy{'login'} = 1;
1.518 albertel 4038: }
4039: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4040: if (keys(%{$domconfig{'rolecolors'}})) {
4041: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4042: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4043: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4044: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4045: }
1.518 albertel 4046: }
4047: }
1.632 raeburn 4048: } else {
4049: $legacy{'rolecolors'} = 1;
1.518 albertel 4050: }
1.632 raeburn 4051: } else {
4052: $legacy{'rolecolors'} = 1;
1.518 albertel 4053: }
1.632 raeburn 4054: if (keys(%legacy) > 0) {
4055: my %legacyhash = &get_legacy_domconf($udom);
4056: foreach my $item (keys(%legacyhash)) {
4057: if ($item =~ /^\Q$udom\E\.login/) {
4058: if ($legacy{'login'}) {
4059: $designhash{$item} = $legacyhash{$item};
4060: }
4061: } else {
4062: if ($legacy{'rolecolors'}) {
4063: $designhash{$item} = $legacyhash{$item};
4064: }
1.518 albertel 4065: }
4066: }
4067: }
1.632 raeburn 4068: } else {
4069: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4070: }
4071: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4072: $cachetime);
4073: return %designhash;
4074: }
4075:
1.632 raeburn 4076: sub get_legacy_domconf {
4077: my ($udom) = @_;
4078: my %legacyhash;
4079: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4080: my $designfile = $designdir.'/'.$udom.'.tab';
4081: if (-e $designfile) {
4082: if ( open (my $fh,"<$designfile") ) {
4083: while (my $line = <$fh>) {
4084: next if ($line =~ /^\#/);
4085: chomp($line);
4086: my ($key,$val)=(split(/\=/,$line));
4087: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4088: }
4089: close($fh);
4090: }
4091: }
4092: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4093: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4094: }
4095: return %legacyhash;
4096: }
4097:
1.63 www 4098: =pod
4099:
1.112 bowersj2 4100: =item * &domainlogo()
1.63 www 4101:
4102: Inputs: $domain (usually will be undef)
4103:
4104: Returns: A link to a domain logo, if the domain logo exists.
4105: If the domain logo does not exist, a description of the domain.
4106:
4107: =cut
1.112 bowersj2 4108:
1.63 www 4109: ###############################################
4110: sub domainlogo {
1.517 raeburn 4111: my $domain = &determinedomain(shift);
1.518 albertel 4112: my %designhash = &get_domainconf($domain);
1.517 raeburn 4113: # See if there is a logo
4114: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4115: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4116: if ($imgsrc =~ m{^/(adm|res)/}) {
4117: if ($imgsrc =~ m{^/res/}) {
4118: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4119: &Apache::lonnet::repcopy($local_name);
4120: }
4121: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4122: }
4123: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4124: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4125: return &Apache::lonnet::domain($domain,'description');
1.59 www 4126: } else {
1.60 matthew 4127: return '';
1.59 www 4128: }
4129: }
1.63 www 4130: ##############################################
4131:
4132: =pod
4133:
1.112 bowersj2 4134: =item * &designparm()
1.63 www 4135:
4136: Inputs: $which parameter; $domain (usually will be undef)
4137:
4138: Returns: value of designparamter $which
4139:
4140: =cut
1.112 bowersj2 4141:
1.397 albertel 4142:
1.400 albertel 4143: ##############################################
1.397 albertel 4144: sub designparm {
4145: my ($which,$domain)=@_;
1.258 albertel 4146: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4147: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4148: return '#000000';
4149: }
1.635 raeburn 4150: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4151: return '#FFFFFF';
4152: }
4153: if ($which=~/\.tabbg$/) {
4154: return '#CCCCCC';
4155: }
4156: }
1.397 albertel 4157: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4158: return $env{'environment.color.'.$which};
1.96 www 4159: }
1.63 www 4160: $domain=&determinedomain($domain);
1.518 albertel 4161: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4162: my $output;
1.517 raeburn 4163: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4164: $output = $domdesign{$domain.'.'.$which};
1.63 www 4165: } else {
1.520 raeburn 4166: $output = $defaultdesign{$which};
4167: }
4168: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4169: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4170: if ($output =~ m{^/(adm|res)/}) {
4171: if ($output =~ m{^/res/}) {
4172: my $local_name = &Apache::lonnet::filelocation('',$output);
4173: &Apache::lonnet::repcopy($local_name);
4174: }
1.520 raeburn 4175: $output = &lonhttpdurl($output);
4176: }
1.63 www 4177: }
1.520 raeburn 4178: return $output;
1.63 www 4179: }
1.59 www 4180:
1.60 matthew 4181: ###############################################
4182: ###############################################
4183:
4184: =pod
4185:
1.112 bowersj2 4186: =back
4187:
1.549 albertel 4188: =head1 HTML Helpers
1.112 bowersj2 4189:
4190: =over 4
4191:
4192: =item * &bodytag()
1.60 matthew 4193:
4194: Returns a uniform header for LON-CAPA web pages.
4195:
4196: Inputs:
4197:
1.112 bowersj2 4198: =over 4
4199:
4200: =item * $title, A title to be displayed on the page.
4201:
4202: =item * $function, the current role (can be undef).
4203:
4204: =item * $addentries, extra parameters for the <body> tag.
4205:
4206: =item * $bodyonly, if defined, only return the <body> tag.
4207:
4208: =item * $domain, if defined, force a given domain.
4209:
4210: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4211: text interface only)
1.60 matthew 4212:
1.326 albertel 4213: =item * $customtitle, alternate text to use instead of $title
4214: in the title box that appears, this text
4215: is not auto translated like the $title is
1.309 albertel 4216:
4217: =item * $notopbar, if true, keep the 'what is this' info but remove the
4218: navigational links
1.317 albertel 4219:
1.338 albertel 4220: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4221:
4222: =item * $notitle, if true keep the nav controls, but remove the title bar
4223:
1.361 albertel 4224: =item * $no_inline_link, if true and in remote mode, don't show the
4225: 'Switch To Inline Menu' link
4226:
1.460 albertel 4227: =item * $args, optional argument valid values are
4228: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4229: inherit_jsmath -> when creating popup window in a page,
4230: should it have jsmath forced on by the
4231: current page
1.460 albertel 4232:
1.112 bowersj2 4233: =back
4234:
1.60 matthew 4235: Returns: A uniform header for LON-CAPA web pages.
4236: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4237: If $bodyonly is undef or zero, an html string containing a <body> tag and
4238: other decorations will be returned.
4239:
4240: =cut
4241:
1.54 www 4242: sub bodytag {
1.309 albertel 4243: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4244: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4245:
1.460 albertel 4246: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4247:
1.183 matthew 4248: $function = &get_users_function() if (!$function);
1.339 albertel 4249: my $img = &designparm($function.'.img',$domain);
4250: my $font = &designparm($function.'.font',$domain);
4251: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4252:
1.692.4.2 raeburn 4253: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 4254: 'bgcolor' => $pgbg,
1.339 albertel 4255: 'text' => $font,
4256: 'alink' => &designparm($function.'.alink',$domain),
4257: 'vlink' => &designparm($function.'.vlink',$domain),
4258: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4259: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4260:
1.63 www 4261: # role and realm
1.378 raeburn 4262: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4263: if ($role eq 'ca') {
1.479 albertel 4264: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4265: $realm = &plainname($rname,$rdom);
1.378 raeburn 4266: }
1.55 www 4267: # realm
1.258 albertel 4268: if ($env{'request.course.id'}) {
1.378 raeburn 4269: if ($env{'request.role'} !~ /^cr/) {
4270: $role = &Apache::lonnet::plaintext($role,&course_type());
4271: }
1.359 albertel 4272: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4273: } else {
4274: $role = &Apache::lonnet::plaintext($role);
1.54 www 4275: }
1.433 albertel 4276:
1.359 albertel 4277: if (!$realm) { $realm=' '; }
1.55 www 4278: # Set messages
1.60 matthew 4279: my $messages=&domainlogo($domain);
1.330 albertel 4280:
1.438 albertel 4281: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4282:
1.101 www 4283: # construct main body tag
1.359 albertel 4284: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4285: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4286:
1.530 albertel 4287: if ($bodyonly) {
1.60 matthew 4288: return $bodytag;
1.258 albertel 4289: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4290: # Accessibility
1.224 raeburn 4291:
1.337 albertel 4292: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4293: if (!$notitle) {
1.337 albertel 4294: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4295: }
4296: return $bodytag;
1.359 albertel 4297: }
4298:
1.410 albertel 4299: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4300: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4301: undef($role);
1.434 albertel 4302: } else {
4303: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4304: }
1.359 albertel 4305:
4306: my $roleinfo=(<<ENDROLE);
4307: <td class="LC_title_bar_who">
4308: <div class="LC_title_bar_name">
1.410 albertel 4309: $name
1.361 albertel 4310:
1.359 albertel 4311: </div>
4312: <div class="LC_title_bar_role">
1.361 albertel 4313: $role
1.359 albertel 4314: </div>
4315: <div class="LC_title_bar_realm">
1.361 albertel 4316: $realm
1.359 albertel 4317: </div>
1.206 albertel 4318: </td>
4319: ENDROLE
1.235 raeburn 4320:
1.359 albertel 4321: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4322: if ($customtitle) {
4323: $titleinfo = $customtitle;
4324: }
4325: #
4326: # Extra info if you are the DC
4327: my $dc_info = '';
4328: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4329: $env{'course.'.$env{'request.course.id'}.
4330: '.domain'}.'/'})) {
4331: my $cid = $env{'request.course.id'};
4332: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4333: $dc_info =~ s/\s+$//;
1.359 albertel 4334: $dc_info = '('.$dc_info.')';
4335: }
4336:
1.644 www 4337: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4338: # No Remote
1.258 albertel 4339: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4340: $forcereg=1;
4341: }
4342:
4343: if (!$customtitle && $env{'request.state'} eq 'construct') {
4344: # this is for resources; directories have customtitle, and crumbs
4345: # and select recent are created in lonpubdir.pm
1.229 albertel 4346: my ($uname,$thisdisfn)=
1.258 albertel 4347: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4348: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4349: $formaction=~s/\/+/\//g;
4350:
1.359 albertel 4351: my $parentpath = '';
4352: my $lastitem = '';
4353: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4354: $parentpath = $1;
4355: $lastitem = $2;
4356: } else {
4357: $lastitem = $thisdisfn;
4358: }
4359: $titleinfo =
1.640 bisitz 4360: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4361: .'<b>'.&mt('Construction Space').'</b>: '
4362: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4363: .'" target="_top"><tt><b>'
4364: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
4365: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4366: .'</form>'
4367: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4368: }
1.359 albertel 4369:
1.337 albertel 4370: my $titletable;
1.338 albertel 4371: if (!$notitle) {
1.337 albertel 4372: $titletable =
1.359 albertel 4373: '<table id="LC_title_bar">'.
4374: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4375: '</tr></table>';
1.337 albertel 4376: }
1.359 albertel 4377: if ($notopbar) {
4378: $bodytag .= $titletable;
4379: } else {
4380: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4381: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4382: $titletable);
1.272 raeburn 4383: } else {
1.336 albertel 4384: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4385: $titletable;
1.272 raeburn 4386: }
1.235 raeburn 4387: }
4388: return $bodytag;
1.94 www 4389: }
1.95 www 4390:
1.93 www 4391: #
1.95 www 4392: # Top frame rendering, Remote is up
1.93 www 4393: #
1.359 albertel 4394:
1.517 raeburn 4395: my $imgsrc = $img;
4396: if ($img =~ /^\/adm/) {
1.575 albertel 4397: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4398: }
4399: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4400:
1.305 www 4401: # Explicit link to get inline menu
1.361 albertel 4402: my $menu= ($no_inline_link?''
4403: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4404: #
1.338 albertel 4405: if ($notitle) {
1.337 albertel 4406: return $bodytag;
4407: }
1.94 www 4408: return(<<ENDBODY);
1.60 matthew 4409: $bodytag
1.359 albertel 4410: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4411: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4412: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4413: </tr>
1.359 albertel 4414: <tr><td>$titleinfo $dc_info $menu</td>
4415: $roleinfo
1.368 albertel 4416: </tr>
1.356 albertel 4417: </table>
1.54 www 4418: ENDBODY
1.182 matthew 4419: }
4420:
1.330 albertel 4421: sub make_attr_string {
4422: my ($register,$attr_ref) = @_;
4423:
4424: if ($attr_ref && !ref($attr_ref)) {
4425: die("addentries Must be a hash ref ".
4426: join(':',caller(1))." ".
4427: join(':',caller(0))." ");
4428: }
4429:
4430: if ($register) {
1.339 albertel 4431: my ($on_load,$on_unload);
4432: foreach my $key (keys(%{$attr_ref})) {
4433: if (lc($key) eq 'onload') {
4434: $on_load.=$attr_ref->{$key}.';';
4435: delete($attr_ref->{$key});
4436:
4437: } elsif (lc($key) eq 'onunload') {
4438: $on_unload.=$attr_ref->{$key}.';';
4439: delete($attr_ref->{$key});
4440: }
4441: }
4442: $attr_ref->{'onload'} =
4443: &Apache::lonmenu::loadevents(). $on_load;
4444: $attr_ref->{'onunload'}=
4445: &Apache::lonmenu::unloadevents().$on_unload;
4446: }
4447:
4448: # Accessibility font enhance
4449: if ($env{'browser.fontenhance'} eq 'on') {
4450: my $style;
4451: foreach my $key (keys(%{$attr_ref})) {
4452: if (lc($key) eq 'style') {
4453: $style.=$attr_ref->{$key}.';';
4454: delete($attr_ref->{$key});
4455: }
4456: }
4457: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4458: }
1.339 albertel 4459:
4460: if ($env{'browser.blackwhite'} eq 'on') {
4461: delete($attr_ref->{'font'});
4462: delete($attr_ref->{'link'});
4463: delete($attr_ref->{'alink'});
4464: delete($attr_ref->{'vlink'});
4465: delete($attr_ref->{'bgcolor'});
4466: delete($attr_ref->{'background'});
4467: }
4468:
1.330 albertel 4469: my $attr_string;
4470: foreach my $attr (keys(%$attr_ref)) {
4471: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4472: }
4473: return $attr_string;
4474: }
4475:
4476:
1.182 matthew 4477: ###############################################
1.251 albertel 4478: ###############################################
4479:
4480: =pod
4481:
4482: =item * &endbodytag()
4483:
4484: Returns a uniform footer for LON-CAPA web pages.
4485:
1.635 raeburn 4486: Inputs: 1 - optional reference to an args hash
4487: If in the hash, key for noredirectlink has a value which evaluates to true,
4488: a 'Continue' link is not displayed if the page contains an
4489: internal redirect in the <head></head> section,
4490: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4491:
4492: =cut
4493:
4494: sub endbodytag {
1.635 raeburn 4495: my ($args) = @_;
1.251 albertel 4496: my $endbodytag='</body>';
1.269 albertel 4497: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4498: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4499: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4500: $endbodytag=
4501: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4502: &mt('Continue').'</a>'.
4503: $endbodytag;
4504: }
1.315 albertel 4505: }
1.251 albertel 4506: return $endbodytag;
4507: }
4508:
1.352 albertel 4509: =pod
4510:
4511: =item * &standard_css()
4512:
4513: Returns a style sheet
4514:
4515: Inputs: (all optional)
4516: domain -> force to color decorate a page for a specific
4517: domain
4518: function -> force usage of a specific rolish color scheme
4519: bgcolor -> override the default page bgcolor
4520:
4521: =cut
4522:
1.343 albertel 4523: sub standard_css {
1.345 albertel 4524: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4525: $function = &get_users_function() if (!$function);
4526: my $img = &designparm($function.'.img', $domain);
4527: my $tabbg = &designparm($function.'.tabbg', $domain);
4528: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4529: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4530: my $pgbg_or_bgcolor =
4531: $bgcolor ||
1.352 albertel 4532: &designparm($function.'.pgbg', $domain);
1.382 albertel 4533: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4534: my $alink = &designparm($function.'.alink', $domain);
4535: my $vlink = &designparm($function.'.vlink', $domain);
4536: my $link = &designparm($function.'.link', $domain);
4537:
1.602 albertel 4538: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4539: my $mono = 'monospace';
1.352 albertel 4540: my $data_table_head = $tabbg;
4541: my $data_table_light = '#EEEEEE';
1.470 banghart 4542: my $data_table_dark = '#DDDDDD';
4543: my $data_table_darker = '#CCCCCC';
1.349 albertel 4544: my $data_table_highlight = '#FFFF00';
1.352 albertel 4545: my $mail_new = '#FFBB77';
4546: my $mail_new_hover = '#DD9955';
4547: my $mail_read = '#BBBB77';
4548: my $mail_read_hover = '#999944';
4549: my $mail_replied = '#AAAA88';
4550: my $mail_replied_hover = '#888855';
4551: my $mail_other = '#99BBBB';
4552: my $mail_other_hover = '#669999';
1.391 albertel 4553: my $table_header = '#DDDDDD';
1.489 raeburn 4554: my $feedback_link_bg = '#BBBBBB';
1.692.4.3! raeburn 4555: my $lg_border_color = '#C8C8C8';
1.392 albertel 4556:
1.608 albertel 4557: my $border = ($env{'browser.type'} eq 'explorer' ||
1.692.4.2 raeburn 4558: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
4559: : '0 3px 0 4px';
1.448 albertel 4560:
1.523 albertel 4561:
1.343 albertel 4562: return <<END;
1.345 albertel 4563: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4564: a:focus { color: red; background: yellow }
1.510 albertel 4565: table.thinborder,
1.523 albertel 4566:
1.510 albertel 4567: table.thinborder tr th {
4568: border-style: solid;
4569: border-width: 1px;
4570: background: $tabbg;
4571: }
1.523 albertel 4572: table.thinborder tr td {
1.510 albertel 4573: border-style: solid;
4574: border-width: 1px
4575: }
1.426 albertel 4576:
1.343 albertel 4577: form, .inline { display: inline; }
4578: .center { text-align: center; }
1.593 albertel 4579: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4580: .LC_error {
4581: color: red;
4582: font-size: larger;
4583: }
1.457 albertel 4584: .LC_warning,
4585: .LC_diff_removed {
1.394 albertel 4586: color: red;
4587: }
1.532 albertel 4588:
4589: .LC_info,
1.457 albertel 4590: .LC_success,
4591: .LC_diff_added {
1.350 albertel 4592: color: green;
4593: }
1.692.4.2 raeburn 4594:
4595: div.LC_confirm_box {
4596: background-color: #FAFAFA;
4597: border: 1px solid $lg_border_color;
4598: margin-right: 0;
4599: padding: 5px;
4600: }
4601:
4602: div.LC_confirm_box .LC_error img,
4603: div.LC_confirm_box .LC_success img {
4604: vertical-align: middle;
1.543 albertel 4605: }
4606:
1.440 albertel 4607: .LC_icon {
1.692.4.2 raeburn 4608: border: none;
1.440 albertel 4609: }
1.539 albertel 4610: .LC_indexer_icon {
1.692.4.2 raeburn 4611: border: 0;
1.539 albertel 4612: height: 22px;
4613: }
1.543 albertel 4614: .LC_docs_spacer {
4615: width: 25px;
4616: height: 1px;
1.692.4.2 raeburn 4617: border: none;
1.543 albertel 4618: }
1.346 albertel 4619:
1.532 albertel 4620: .LC_internal_info {
1.692.4.2 raeburn 4621: color: #999999;
1.532 albertel 4622: }
4623:
1.458 albertel 4624: table.LC_pastsubmission {
4625: border: 1px solid black;
4626: margin: 2px;
4627: }
4628:
1.606 albertel 4629: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4630: width: 100%;
4631: background: $pgbg;
1.392 albertel 4632: border: 2px;
1.402 albertel 4633: border-collapse: separate;
1.692.4.2 raeburn 4634: padding: 0;
1.345 albertel 4635: }
1.392 albertel 4636:
1.606 albertel 4637: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4638: table#LC_title_bar.LC_with_remote {
1.359 albertel 4639: width: 100%;
1.392 albertel 4640: border-color: $pgbg;
4641: border-style: solid;
4642: border-width: $border;
4643:
1.379 albertel 4644: background: $pgbg;
4645: font-family: $sans;
1.392 albertel 4646: border-collapse: collapse;
1.692.4.2 raeburn 4647: padding: 0;
1.359 albertel 4648: }
1.392 albertel 4649:
1.409 albertel 4650: table.LC_docs_path {
4651: width: 100%;
4652: border: 0;
4653: background: $pgbg;
4654: font-family: $sans;
4655: border-collapse: collapse;
1.692.4.2 raeburn 4656: padding: 0;
1.409 albertel 4657: }
4658:
1.359 albertel 4659: table#LC_title_bar td {
4660: background: $tabbg;
4661: }
4662: table#LC_title_bar td.LC_title_bar_who {
4663: background: $tabbg;
4664: color: $font;
1.427 albertel 4665: font: small $sans;
1.359 albertel 4666: text-align: right;
4667: }
1.469 banghart 4668: span.LC_metadata {
4669: font-family: $sans;
4670: }
1.359 albertel 4671: span.LC_title_bar_title {
1.416 albertel 4672: font: bold x-large $sans;
1.359 albertel 4673: }
4674: table#LC_title_bar td.LC_title_bar_domain_logo {
4675: background: $sidebg;
4676: text-align: right;
1.692.4.2 raeburn 4677: padding: 0;
1.368 albertel 4678: }
4679: table#LC_title_bar td.LC_title_bar_role_logo {
4680: background: $sidebg;
1.692.4.2 raeburn 4681: padding: 0;
1.359 albertel 4682: }
4683:
1.346 albertel 4684: table#LC_menubuttons_mainmenu {
1.526 www 4685: width: 100%;
1.692.4.2 raeburn 4686: border: 0;
1.346 albertel 4687: border-spacing: 1px;
1.692.4.2 raeburn 4688: padding: 0 1px;
4689: margin: 0;
1.346 albertel 4690: border-collapse: separate;
4691: }
4692: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
1.692.4.2 raeburn 4693: border: none;
1.346 albertel 4694: }
1.345 albertel 4695: table#LC_top_nav td {
4696: background: $tabbg;
1.692.4.2 raeburn 4697: border: none;
1.407 albertel 4698: font-size: small;
1.345 albertel 4699: }
4700: table#LC_top_nav td a, div#LC_top_nav a {
4701: color: $font;
4702: font-family: $sans;
4703: }
1.364 albertel 4704: table#LC_top_nav td.LC_top_nav_logo {
4705: background: $tabbg;
1.432 albertel 4706: text-align: left;
1.408 albertel 4707: white-space: nowrap;
1.432 albertel 4708: width: 31px;
1.408 albertel 4709: }
4710: table#LC_top_nav td.LC_top_nav_logo img {
1.692.4.2 raeburn 4711: border: none;
1.408 albertel 4712: vertical-align: bottom;
1.364 albertel 4713: }
1.432 albertel 4714: table#LC_top_nav td.LC_top_nav_exit,
4715: table#LC_top_nav td.LC_top_nav_help {
4716: width: 2.0em;
4717: }
1.442 albertel 4718: table#LC_top_nav td.LC_top_nav_login {
4719: width: 4.0em;
4720: text-align: center;
4721: }
1.409 albertel 4722: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4723: background: $tabbg;
4724: color: $font;
4725: font-family: $sans;
1.358 albertel 4726: font-size: smaller;
1.357 albertel 4727: }
1.411 albertel 4728: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4729: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4730: background: $tabbg;
4731: color: $font;
4732: font-family: $sans;
4733: font-size: larger;
4734: text-align: right;
4735: }
1.383 albertel 4736: td.LC_table_cell_checkbox {
4737: text-align: center;
4738: }
1.522 albertel 4739: table#LC_mainmenu td.LC_mainmenu_column {
4740: vertical-align: top;
4741: }
4742:
1.346 albertel 4743: .LC_menubuttons_inline_text {
4744: color: $font;
4745: font-family: $sans;
4746: font-size: smaller;
4747: }
4748:
1.526 www 4749: .LC_menubuttons_link {
4750: text-decoration: none;
4751: }
1.692.4.2 raeburn 4752: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4753: .LC_menubuttons_category {
1.521 www 4754: color: $font;
1.526 www 4755: background: $pgbg;
1.521 www 4756: font-family: $sans;
4757: font-size: larger;
4758: font-weight: bold;
4759: }
4760:
1.346 albertel 4761: td.LC_menubuttons_text {
1.526 www 4762: width: 90%;
1.346 albertel 4763: color: $font;
4764: font-family: $sans;
4765: }
1.526 www 4766:
1.346 albertel 4767: td.LC_menubuttons_img {
4768: }
1.526 www 4769:
1.346 albertel 4770: .LC_current_location {
4771: font-family: $sans;
4772: background: $tabbg;
4773: }
4774: .LC_new_mail {
4775: font-family: $sans;
1.634 www 4776: background: $tabbg;
1.346 albertel 4777: font-weight: bold;
4778: }
1.347 albertel 4779:
1.527 www 4780: .LC_dropadd_labeltext {
4781: font-family: $sans;
4782: text-align: right;
4783: }
4784:
4785: .LC_preferences_labeltext {
4786: font-family: $sans;
4787: text-align: right;
4788: }
4789:
1.666 raeburn 4790: .LC_roleslog_note {
4791: font-size: smaller;
4792: }
4793:
1.692.4.2 raeburn 4794: .LC_mail_functions {
4795: font-weight: bold;
4796: }
4797:
1.440 albertel 4798: table.LC_aboutme_port {
1.692.4.2 raeburn 4799: border: none;
1.440 albertel 4800: border-collapse: collapse;
1.692.4.2 raeburn 4801: border-spacing: 0;
1.440 albertel 4802: }
1.349 albertel 4803: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4804: border: 1px solid #000000;
1.402 albertel 4805: border-collapse: separate;
1.426 albertel 4806: border-spacing: 1px;
1.610 albertel 4807: background: $pgbg;
1.347 albertel 4808: }
1.422 albertel 4809: .LC_data_table_dense {
4810: font-size: small;
4811: }
1.507 raeburn 4812: table.LC_nested_outer {
4813: border: 1px solid #000000;
1.589 raeburn 4814: border-collapse: collapse;
1.692.4.2 raeburn 4815: border-spacing: 0;
1.507 raeburn 4816: width: 100%;
4817: }
4818: table.LC_nested {
1.692.4.2 raeburn 4819: border: none;
1.589 raeburn 4820: border-collapse: collapse;
1.692.4.2 raeburn 4821: border-spacing: 0;
1.507 raeburn 4822: width: 100%;
4823: }
1.523 albertel 4824: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4825: table.LC_prior_tries tr th {
1.349 albertel 4826: font-weight: bold;
4827: background-color: $data_table_head;
1.421 albertel 4828: font-size: smaller;
1.347 albertel 4829: }
1.692.4.2 raeburn 4830: table.LC_data_table tr.LC_info_row > td {
4831: background-color: #CCCCCC;
4832: font-weight: bold;
4833: text-align: left;
4834: }
1.610 albertel 4835: table.LC_data_table tr.LC_odd_row > td,
1.692.4.2 raeburn 4836: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4837: table.LC_aboutme_port tr td {
1.349 albertel 4838: background-color: $data_table_light;
1.425 albertel 4839: padding: 2px;
1.347 albertel 4840: }
1.610 albertel 4841: table.LC_data_table tr.LC_even_row > td,
1.692.4.2 raeburn 4842: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4843: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4844: background-color: $data_table_dark;
1.692.4.2 raeburn 4845: padding: 2px;
1.347 albertel 4846: }
1.425 albertel 4847: table.LC_data_table tr.LC_data_table_highlight td {
4848: background-color: $data_table_darker;
4849: }
1.639 raeburn 4850: table.LC_data_table tr td.LC_leftcol_header {
4851: background-color: $data_table_head;
4852: font-weight: bold;
4853: }
1.451 albertel 4854: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4855: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4856: background-color: #FFFFFF;
1.421 albertel 4857: font-weight: bold;
4858: font-style: italic;
4859: text-align: center;
4860: padding: 8px;
1.347 albertel 4861: }
1.507 raeburn 4862: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4863: padding: 4ex
4864: }
1.507 raeburn 4865: table.LC_nested_outer tr th {
4866: font-weight: bold;
4867: background-color: $data_table_head;
4868: font-size: smaller;
4869: border-bottom: 1px solid #000000;
4870: }
4871: table.LC_nested_outer tr td.LC_subheader {
4872: background-color: $data_table_head;
4873: font-weight: bold;
4874: font-size: small;
4875: border-bottom: 1px solid #000000;
4876: text-align: right;
1.451 albertel 4877: }
1.507 raeburn 4878: table.LC_nested tr.LC_info_row td {
1.692.4.2 raeburn 4879: background-color: #CCCCCC;
1.451 albertel 4880: font-weight: bold;
4881: font-size: small;
1.507 raeburn 4882: text-align: center;
4883: }
1.589 raeburn 4884: table.LC_nested tr.LC_info_row td.LC_left_item,
4885: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4886: text-align: left;
1.451 albertel 4887: }
1.507 raeburn 4888: table.LC_nested td {
1.692.4.2 raeburn 4889: background-color: #FFFFFF;
1.451 albertel 4890: font-size: small;
1.507 raeburn 4891: }
4892: table.LC_nested_outer tr th.LC_right_item,
4893: table.LC_nested tr.LC_info_row td.LC_right_item,
4894: table.LC_nested tr.LC_odd_row td.LC_right_item,
4895: table.LC_nested tr td.LC_right_item {
1.451 albertel 4896: text-align: right;
4897: }
4898:
1.507 raeburn 4899: table.LC_nested tr.LC_odd_row td {
1.692.4.2 raeburn 4900: background-color: #EEEEEE;
1.451 albertel 4901: }
4902:
1.473 raeburn 4903: table.LC_createuser {
4904: }
4905:
4906: table.LC_createuser tr.LC_section_row td {
4907: font-size: smaller;
4908: }
4909:
4910: table.LC_createuser tr.LC_info_row td {
1.692.4.2 raeburn 4911: background-color: #CCCCCC;
1.473 raeburn 4912: font-weight: bold;
4913: text-align: center;
4914: }
4915:
1.349 albertel 4916: table.LC_calendar {
4917: border: 1px solid #000000;
4918: border-collapse: collapse;
4919: }
4920: table.LC_calendar_pickdate {
4921: font-size: xx-small;
4922: }
4923: table.LC_calendar tr td {
4924: border: 1px solid #000000;
4925: vertical-align: top;
4926: }
4927: table.LC_calendar tr td.LC_calendar_day_empty {
4928: background-color: $data_table_dark;
4929: }
4930: table.LC_calendar tr td.LC_calendar_day_current {
4931: background-color: $data_table_highlight;
4932: }
4933:
4934: table.LC_mail_list tr.LC_mail_new {
4935: background-color: $mail_new;
4936: }
4937: table.LC_mail_list tr.LC_mail_new:hover {
4938: background-color: $mail_new_hover;
4939: }
4940: table.LC_mail_list tr.LC_mail_read {
4941: background-color: $mail_read;
4942: }
4943: table.LC_mail_list tr.LC_mail_read:hover {
4944: background-color: $mail_read_hover;
4945: }
4946: table.LC_mail_list tr.LC_mail_replied {
4947: background-color: $mail_replied;
4948: }
4949: table.LC_mail_list tr.LC_mail_replied:hover {
4950: background-color: $mail_replied_hover;
4951: }
4952: table.LC_mail_list tr.LC_mail_other {
4953: background-color: $mail_other;
4954: }
4955: table.LC_mail_list tr.LC_mail_other:hover {
4956: background-color: $mail_other_hover;
4957: }
1.494 raeburn 4958: table.LC_mail_list tr.LC_mail_even {
4959: }
4960: table.LC_mail_list tr.LC_mail_odd {
4961: }
4962:
1.385 albertel 4963:
1.386 albertel 4964: table#LC_portfolio_actions {
4965: width: auto;
4966: background: $pgbg;
1.692.4.2 raeburn 4967: border: none;
1.386 albertel 4968: border-spacing: 2px 2px;
1.692.4.2 raeburn 4969: padding: 0;
4970: margin: 0;
1.386 albertel 4971: border-collapse: separate;
4972: }
4973: table#LC_portfolio_actions td.LC_label {
4974: background: $tabbg;
4975: text-align: right;
4976: }
4977: table#LC_portfolio_actions td.LC_value {
4978: background: $tabbg;
4979: }
1.385 albertel 4980:
1.391 albertel 4981: table#LC_cstr_controls {
4982: width: 100%;
4983: border-collapse: collapse;
4984: }
4985: table#LC_cstr_controls tr td {
4986: border: 4px solid $pgbg;
4987: padding: 4px;
4988: text-align: center;
4989: background: $tabbg;
4990: }
4991: table#LC_cstr_controls tr th {
4992: border: 4px solid $pgbg;
4993: background: $table_header;
4994: text-align: center;
4995: font-family: $sans;
4996: font-size: smaller;
4997: }
4998:
1.389 albertel 4999: table#LC_browser {
5000:
5001: }
5002: table#LC_browser tr th {
1.391 albertel 5003: background: $table_header;
1.389 albertel 5004: }
1.390 albertel 5005: table#LC_browser tr td {
5006: padding: 2px;
5007: }
1.389 albertel 5008: table#LC_browser tr.LC_browser_file,
5009: table#LC_browser tr.LC_browser_file_published {
5010: background: #CCFF88;
5011: }
5012: table#LC_browser tr.LC_browser_file_locked,
5013: table#LC_browser tr.LC_browser_file_unpublished {
5014: background: #FFAA99;
1.387 albertel 5015: }
1.389 albertel 5016: table#LC_browser tr.LC_browser_file_obsolete {
5017: background: #AAAAAA;
1.387 albertel 5018: }
1.455 albertel 5019: table#LC_browser tr.LC_browser_file_modified,
5020: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 5021: background: #FFFF77;
1.387 albertel 5022: }
1.389 albertel 5023: table#LC_browser tr.LC_browser_folder {
5024: background: #CCCCFF;
1.387 albertel 5025: }
1.692.4.2 raeburn 5026:
5027: table.LC_data_table tr > td.LC_roles_is {
5028: /* background: #77FF77; */
5029: }
5030: table.LC_data_table tr > td.LC_roles_future {
5031: background: #FFFF77;
5032: }
5033: table.LC_data_table tr > td.LC_roles_will {
5034: background: #FFAA77;
5035: }
5036: table.LC_data_table tr > td.LC_roles_expired {
5037: background: #FF7777;
5038: }
5039: table.LC_data_table tr > td.LC_roles_will_not {
5040: background: #AAFF77;
5041: }
5042: table.LC_data_table tr > td.LC_roles_selected {
5043: background: #11CC55;
5044: }
5045:
1.388 albertel 5046: span.LC_current_location {
5047: font-size: x-large;
5048: background: $pgbg;
5049: }
1.387 albertel 5050:
1.395 albertel 5051: span.LC_parm_menu_item {
5052: font-size: larger;
5053: font-family: $sans;
5054: }
5055: span.LC_parm_scope_all {
5056: color: red;
5057: }
5058: span.LC_parm_scope_folder {
5059: color: green;
5060: }
5061: span.LC_parm_scope_resource {
5062: color: orange;
5063: }
5064: span.LC_parm_part {
5065: color: blue;
5066: }
5067: span.LC_parm_folder, span.LC_parm_symb {
5068: font-size: x-small;
5069: font-family: $mono;
5070: color: #AAAAAA;
5071: }
5072:
1.396 albertel 5073: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
5074: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
5075: border: 1px solid black;
5076: border-collapse: collapse;
5077: }
5078: table.LC_parm_overview_restrictions td {
5079: border-width: 1px 4px 1px 4px;
5080: border-style: solid;
5081: border-color: $pgbg;
5082: text-align: center;
5083: }
5084: table.LC_parm_overview_restrictions th {
5085: background: $tabbg;
5086: border-width: 1px 4px 1px 4px;
5087: border-style: solid;
5088: border-color: $pgbg;
5089: }
1.398 albertel 5090: table#LC_helpmenu {
1.692.4.2 raeburn 5091: border: none;
1.398 albertel 5092: height: 55px;
1.692.4.2 raeburn 5093: border-spacing: 0;
1.398 albertel 5094: }
5095:
5096: table#LC_helpmenu fieldset legend {
5097: font-size: larger;
5098: font-weight: bold;
5099: }
1.397 albertel 5100: table#LC_helpmenu_links {
5101: width: 100%;
5102: border: 1px solid black;
5103: background: $pgbg;
1.692.4.2 raeburn 5104: padding: 0;
1.397 albertel 5105: border-spacing: 1px;
5106: }
5107: table#LC_helpmenu_links tr td {
5108: padding: 1px;
5109: background: $tabbg;
1.399 albertel 5110: text-align: center;
5111: font-weight: bold;
1.397 albertel 5112: }
1.396 albertel 5113:
1.397 albertel 5114: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5115: table#LC_helpmenu_links a:active {
5116: text-decoration: none;
5117: color: $font;
5118: }
5119: table#LC_helpmenu_links a:hover {
5120: text-decoration: underline;
5121: color: $vlink;
5122: }
1.396 albertel 5123:
1.417 albertel 5124: .LC_chrt_popup_exists {
5125: border: 1px solid #339933;
5126: margin: -1px;
5127: }
5128: .LC_chrt_popup_up {
5129: border: 1px solid yellow;
5130: margin: -1px;
5131: }
5132: .LC_chrt_popup {
5133: border: 1px solid #8888FF;
5134: background: #CCCCFF;
5135: }
1.421 albertel 5136: table.LC_pick_box {
5137: border-collapse: separate;
5138: background: white;
5139: border: 1px solid black;
5140: border-spacing: 1px;
5141: }
5142: table.LC_pick_box td.LC_pick_box_title {
5143: background: $tabbg;
5144: font-weight: bold;
5145: text-align: right;
1.692.4.2 raeburn 5146: vertical-align: top;
1.421 albertel 5147: width: 184px;
5148: padding: 8px;
5149: }
1.645 raeburn 5150: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5151: background: $tabbg;
5152: font-weight: bold;
5153: text-align: right;
5154: width: 350px;
5155: padding: 8px;
5156: }
5157:
1.579 raeburn 5158: table.LC_pick_box td.LC_pick_box_value {
5159: text-align: left;
5160: padding: 8px;
5161: }
5162: table.LC_pick_box td.LC_pick_box_select {
5163: text-align: left;
5164: padding: 8px;
5165: }
1.424 albertel 5166: table.LC_pick_box td.LC_pick_box_separator {
1.692.4.2 raeburn 5167: padding: 0;
1.421 albertel 5168: height: 1px;
5169: background: black;
5170: }
5171: table.LC_pick_box td.LC_pick_box_submit {
5172: text-align: right;
5173: }
1.579 raeburn 5174: table.LC_pick_box td.LC_evenrow_value {
5175: text-align: left;
5176: padding: 8px;
5177: background-color: $data_table_light;
5178: }
5179: table.LC_pick_box td.LC_oddrow_value {
5180: text-align: left;
5181: padding: 8px;
5182: background-color: $data_table_light;
5183: }
5184: table.LC_helpform_receipt {
5185: width: 620px;
5186: border-collapse: separate;
5187: background: white;
5188: border: 1px solid black;
5189: border-spacing: 1px;
5190: }
5191: table.LC_helpform_receipt td.LC_pick_box_title {
5192: background: $tabbg;
5193: font-weight: bold;
5194: text-align: right;
5195: width: 184px;
5196: padding: 8px;
5197: }
5198: table.LC_helpform_receipt td.LC_evenrow_value {
5199: text-align: left;
5200: padding: 8px;
5201: background-color: $data_table_light;
5202: }
5203: table.LC_helpform_receipt td.LC_oddrow_value {
5204: text-align: left;
5205: padding: 8px;
5206: background-color: $data_table_light;
5207: }
5208: table.LC_helpform_receipt td.LC_pick_box_separator {
1.692.4.2 raeburn 5209: padding: 0;
1.579 raeburn 5210: height: 1px;
5211: background: black;
5212: }
5213: span.LC_helpform_receipt_cat {
5214: font-weight: bold;
5215: }
1.424 albertel 5216: table.LC_group_priv_box {
5217: background: white;
5218: border: 1px solid black;
5219: border-spacing: 1px;
5220: }
5221: table.LC_group_priv_box td.LC_pick_box_title {
5222: background: $tabbg;
5223: font-weight: bold;
5224: text-align: right;
5225: width: 184px;
5226: }
5227: table.LC_group_priv_box td.LC_groups_fixed {
5228: background: $data_table_light;
5229: text-align: center;
5230: }
5231: table.LC_group_priv_box td.LC_groups_optional {
5232: background: $data_table_dark;
5233: text-align: center;
5234: }
5235: table.LC_group_priv_box td.LC_groups_functionality {
5236: background: $data_table_darker;
5237: text-align: center;
5238: font-weight: bold;
5239: }
5240: table.LC_group_priv td {
5241: text-align: left;
1.692.4.2 raeburn 5242: padding: 0;
1.424 albertel 5243: }
5244:
1.421 albertel 5245: table.LC_notify_front_page {
5246: background: white;
5247: border: 1px solid black;
5248: padding: 8px;
5249: }
5250: table.LC_notify_front_page td {
5251: padding: 8px;
5252: }
1.424 albertel 5253: .LC_navbuttons {
5254: margin: 2ex 0ex 2ex 0ex;
5255: }
1.423 albertel 5256: .LC_topic_bar {
5257: font-family: $sans;
5258: font-weight: bold;
5259: width: 100%;
5260: background: $tabbg;
5261: vertical-align: middle;
5262: margin: 2ex 0ex 2ex 0ex;
1.692.4.2 raeburn 5263: padding: 3px;
1.423 albertel 5264: }
5265: .LC_topic_bar span {
5266: vertical-align: middle;
5267: }
5268: .LC_topic_bar img {
5269: vertical-align: bottom;
5270: }
5271: table.LC_course_group_status {
5272: margin: 20px;
5273: }
5274: table.LC_status_selector td {
5275: vertical-align: top;
5276: text-align: center;
1.424 albertel 5277: padding: 4px;
5278: }
5279: table.LC_descriptive_input td.LC_description {
5280: vertical-align: top;
5281: text-align: right;
5282: font-weight: bold;
1.423 albertel 5283: }
1.599 albertel 5284: div.LC_feedback_link {
1.616 albertel 5285: clear: both;
1.599 albertel 5286: background: white;
5287: width: 100%;
1.489 raeburn 5288: }
5289: span.LC_feedback_link {
1.599 albertel 5290: background: $feedback_link_bg;
5291: font-size: larger;
5292: }
5293: span.LC_message_link {
5294: background: $feedback_link_bg;
5295: font-size: larger;
5296: position: absolute;
5297: right: 1em;
1.489 raeburn 5298: }
1.421 albertel 5299:
1.515 albertel 5300: table.LC_prior_tries {
1.524 albertel 5301: border: 1px solid #000000;
5302: border-collapse: separate;
5303: border-spacing: 1px;
1.515 albertel 5304: }
1.523 albertel 5305:
1.515 albertel 5306: table.LC_prior_tries td {
1.524 albertel 5307: padding: 2px;
1.515 albertel 5308: }
1.523 albertel 5309:
5310: .LC_answer_correct {
5311: background: #AAFFAA;
5312: color: black;
5313: }
5314: .LC_answer_charged_try {
5315: background: #FFAAAA ! important;
5316: color: black;
5317: }
5318: .LC_answer_not_charged_try,
5319: .LC_answer_no_grade,
5320: .LC_answer_late {
5321: background: #FFFFAA;
5322: color: black;
5323: }
5324: .LC_answer_previous {
5325: background: #AAAAFF;
5326: color: black;
5327: }
5328: .LC_answer_no_message {
5329: background: #FFFFFF;
5330: color: black;
5331: }
5332: .LC_answer_unknown {
5333: background: orange;
5334: color: black;
5335: }
5336:
5337:
1.529 albertel 5338: span.LC_prior_numerical,
5339: span.LC_prior_string,
5340: span.LC_prior_custom,
5341: span.LC_prior_reaction,
5342: span.LC_prior_math {
1.523 albertel 5343: font-family: monospace;
5344: white-space: pre;
5345: }
5346:
1.525 albertel 5347: span.LC_prior_string {
5348: font-family: monospace;
5349: white-space: pre;
5350: }
5351:
1.523 albertel 5352: table.LC_prior_option {
5353: width: 100%;
5354: border-collapse: collapse;
5355: }
1.528 albertel 5356: table.LC_prior_rank, table.LC_prior_match {
5357: border-collapse: collapse;
5358: }
5359: table.LC_prior_option tr td,
5360: table.LC_prior_rank tr td,
5361: table.LC_prior_match tr td {
1.524 albertel 5362: border: 1px solid #000000;
1.515 albertel 5363: }
5364:
1.519 raeburn 5365: span.LC_nobreak {
1.544 albertel 5366: white-space: nowrap;
1.519 raeburn 5367: }
5368:
1.576 raeburn 5369: span.LC_cusr_emph {
5370: font-style: italic;
5371: }
5372:
1.633 raeburn 5373: span.LC_cusr_subheading {
5374: font-weight: normal;
5375: font-size: 85%;
5376: }
5377:
1.545 albertel 5378: table.LC_docs_documents {
5379: background: #BBBBBB;
1.692.4.2 raeburn 5380: border-width: 0;
1.545 albertel 5381: border-collapse: collapse;
5382: }
5383:
5384: table.LC_docs_documents td.LC_docs_document {
5385: border: 2px solid black;
5386: padding: 4px;
5387: }
5388:
5389: .LC_docs_course_commands div {
5390: float: left;
5391: border: 4px solid #AAAAAA;
5392: padding: 4px;
5393: background: #DDDDCC;
5394: }
5395:
5396: .LC_docs_entry_move {
1.692.4.2 raeburn 5397: border: none;
1.545 albertel 5398: border-collapse: collapse;
1.544 albertel 5399: }
5400:
1.545 albertel 5401: .LC_docs_entry_move td {
5402: border: 2px solid #BBBBBB;
5403: background: #DDDDDD;
5404: }
5405:
5406: .LC_docs_editor td.LC_docs_entry_commands {
5407: background: #DDDDDD;
5408: font-size: x-small;
5409: }
1.544 albertel 5410: .LC_docs_copy {
1.545 albertel 5411: color: #000099;
1.544 albertel 5412: }
5413: .LC_docs_cut {
1.545 albertel 5414: color: #550044;
1.544 albertel 5415: }
5416: .LC_docs_rename {
1.545 albertel 5417: color: #009900;
1.544 albertel 5418: }
5419: .LC_docs_remove {
1.545 albertel 5420: color: #990000;
5421: }
5422:
1.547 albertel 5423: .LC_docs_reinit_warn,
5424: .LC_docs_ext_edit {
5425: font-size: x-small;
5426: }
5427:
1.545 albertel 5428: .LC_docs_editor td.LC_docs_entry_title,
5429: .LC_docs_editor td.LC_docs_entry_icon {
5430: background: #FFFFBB;
5431: }
5432: .LC_docs_editor td.LC_docs_entry_parameter {
5433: background: #BBBBFF;
5434: font-size: x-small;
5435: white-space: nowrap;
5436: }
5437:
5438: table.LC_docs_adddocs td,
5439: table.LC_docs_adddocs th {
5440: border: 1px solid #BBBBBB;
5441: padding: 4px;
5442: background: #DDDDDD;
1.543 albertel 5443: }
5444:
1.584 albertel 5445: table.LC_sty_begin {
5446: background: #BBFFBB;
5447: }
5448: table.LC_sty_end {
5449: background: #FFBBBB;
5450: }
5451:
1.589 raeburn 5452: table.LC_double_column {
1.692.4.2 raeburn 5453: border-width: 0;
1.589 raeburn 5454: border-collapse: collapse;
5455: width: 100%;
5456: padding: 2px;
5457: }
5458:
5459: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5460: top: 2px;
1.589 raeburn 5461: left: 2px;
5462: width: 47%;
5463: vertical-align: top;
5464: }
5465:
5466: table.LC_double_column tr td.LC_right_col {
5467: top: 2px;
5468: right: 2px;
5469: width: 47%;
5470: vertical-align: top;
5471: }
5472:
1.594 raeburn 5473: span.LC_role_level {
5474: font-weight: bold;
5475: }
5476:
1.591 raeburn 5477: div.LC_left_float {
5478: float: left;
5479: padding-right: 5%;
1.597 albertel 5480: padding-bottom: 4px;
1.591 raeburn 5481: }
5482:
5483: div.LC_clear_float_header {
1.597 albertel 5484: padding-bottom: 2px;
1.591 raeburn 5485: }
5486:
5487: div.LC_clear_float_footer {
1.597 albertel 5488: padding-top: 10px;
1.591 raeburn 5489: clear: both;
5490: }
5491:
1.597 albertel 5492:
1.601 albertel 5493: div.LC_grade_select_mode {
1.604 albertel 5494: font-family: $sans;
1.601 albertel 5495: }
5496: div.LC_grade_select_mode div div {
5497: margin: 5px;
5498: }
5499: div.LC_grade_select_mode_selector {
5500: margin: 5px;
5501: float: left;
5502: }
5503: div.LC_grade_select_mode_selector_header {
5504: font: bold medium $sans;
5505: }
5506: div.LC_grade_select_mode_type {
5507: clear: left;
5508: }
5509:
1.597 albertel 5510: div.LC_grade_show_user {
5511: margin-top: 20px;
5512: border: 1px solid black;
5513: }
5514: div.LC_grade_user_name {
5515: background: #DDDDEE;
5516: border-bottom: 1px solid black;
5517: font: bold large $sans;
5518: }
5519: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5520: background: #DDEEDD;
5521: }
5522:
5523: div.LC_grade_show_problem,
5524: div.LC_grade_submissions,
5525: div.LC_grade_message_center,
5526: div.LC_grade_info_links,
5527: div.LC_grade_assign {
5528: margin: 5px;
5529: width: 99%;
5530: background: #FFFFFF;
5531: }
5532: div.LC_grade_show_problem_header,
5533: div.LC_grade_submissions_header,
5534: div.LC_grade_message_center_header,
5535: div.LC_grade_assign_header {
5536: font: bold large $sans;
5537: }
5538: div.LC_grade_show_problem_problem,
5539: div.LC_grade_submissions_body,
5540: div.LC_grade_message_center_body,
5541: div.LC_grade_assign_body {
5542: border: 1px solid black;
5543: width: 99%;
5544: background: #FFFFFF;
5545: }
1.598 albertel 5546: span.LC_grade_check_note {
5547: font: normal medium $sans;
5548: display: inline;
5549: position: absolute;
5550: right: 1em;
5551: }
1.597 albertel 5552:
1.613 albertel 5553: table.LC_scantron_action {
5554: width: 100%;
5555: }
5556: table.LC_scantron_action tr th {
5557: font: normal bold $sans;
5558: }
1.600 albertel 5559:
1.614 albertel 5560: div.LC_edit_problem_header,
5561: div.LC_edit_problem_footer {
1.600 albertel 5562: font: normal medium $sans;
1.602 albertel 5563: margin: 2px;
1.600 albertel 5564: }
5565: div.LC_edit_problem_header,
1.602 albertel 5566: div.LC_edit_problem_header div,
1.614 albertel 5567: div.LC_edit_problem_footer,
5568: div.LC_edit_problem_footer div,
1.602 albertel 5569: div.LC_edit_problem_editxml_header,
5570: div.LC_edit_problem_editxml_header div {
1.600 albertel 5571: margin-top: 5px;
5572: }
1.602 albertel 5573: div.LC_edit_problem_header_edit_row {
5574: background: $tabbg;
5575: padding: 3px;
5576: margin-bottom: 5px;
5577: }
1.600 albertel 5578: div.LC_edit_problem_header_title {
1.602 albertel 5579: font: larger bold $sans;
5580: background: $tabbg;
5581: padding: 3px;
5582: }
5583: table.LC_edit_problem_header_title {
5584: font: larger bold $sans;
5585: width: 100%;
5586: border-color: $pgbg;
5587: border-style: solid;
5588: border-width: $border;
5589:
1.600 albertel 5590: background: $tabbg;
1.602 albertel 5591: border-collapse: collapse;
1.692.4.2 raeburn 5592: padding: 0;
1.602 albertel 5593: }
5594:
5595: div.LC_edit_problem_discards {
5596: float: left;
5597: padding-bottom: 5px;
5598: }
5599: div.LC_edit_problem_saves {
5600: float: right;
5601: padding-bottom: 5px;
1.600 albertel 5602: }
5603: hr.LC_edit_problem_divide {
1.602 albertel 5604: clear: both;
1.600 albertel 5605: color: $tabbg;
5606: background-color: $tabbg;
5607: height: 3px;
1.692.4.2 raeburn 5608: border: none;
1.600 albertel 5609: }
1.679 riegler 5610: img.stift{
1.678 riegler 5611: border-width:0;
1.679 riegler 5612: vertical-align:middle;
1.677 riegler 5613: }
1.680 riegler 5614:
1.681 riegler 5615: table#LC_mainmenu{
5616: margin-top:10px;
5617: width:80%;
5618:
5619: }
5620:
1.680 riegler 5621: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5622: vertical-align: top;
5623: width: 45%;
5624: }
5625: .LC_mainmenu_fieldset_category {
5626: color: $font;
5627: background: $pgbg;
5628: font-family: $sans;
5629: font-size: small;
5630: font-weight: bold;
5631: }
5632: fieldset#LC_mainmenu_fieldset {
1.692.4.2 raeburn 5633: margin:0 10px 10px 0;
5634:
5635: }
1.680 riegler 5636:
1.692.4.2 raeburn 5637: div.LC_createcourse {
5638: margin: 10px 10px 10px 10px;
1.680 riegler 5639: }
1.692.4.2 raeburn 5640:
1.343 albertel 5641: END
5642: }
5643:
1.306 albertel 5644: =pod
5645:
5646: =item * &headtag()
5647:
5648: Returns a uniform footer for LON-CAPA web pages.
5649:
1.307 albertel 5650: Inputs: $title - optional title for the head
5651: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5652: $args - optional arguments
1.319 albertel 5653: force_register - if is true call registerurl so the remote is
5654: informed
1.415 albertel 5655: redirect -> array ref of
5656: 1- seconds before redirect occurs
5657: 2- url to redirect to
5658: 3- whether the side effect should occur
1.315 albertel 5659: (side effect of setting
5660: $env{'internal.head.redirect'} to the url
5661: redirected too)
1.352 albertel 5662: domain -> force to color decorate a page for a specific
5663: domain
5664: function -> force usage of a specific rolish color scheme
5665: bgcolor -> override the default page bgcolor
1.460 albertel 5666: no_auto_mt_title
5667: -> prevent &mt()ing the title arg
1.464 albertel 5668:
1.306 albertel 5669: =cut
5670:
5671: sub headtag {
1.313 albertel 5672: my ($title,$head_extra,$args) = @_;
1.306 albertel 5673:
1.363 albertel 5674: my $function = $args->{'function'} || &get_users_function();
5675: my $domain = $args->{'domain'} || &determinedomain();
5676: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5677: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5678: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5679: #time(),
1.418 albertel 5680: $env{'environment.color.timestamp'},
1.363 albertel 5681: $function,$domain,$bgcolor);
5682:
1.369 www 5683: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5684:
1.308 albertel 5685: my $result =
5686: '<head>'.
1.461 albertel 5687: &font_settings();
1.319 albertel 5688:
1.461 albertel 5689: if (!$args->{'frameset'}) {
5690: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5691: }
1.319 albertel 5692: if ($args->{'force_register'}) {
5693: $result .= &Apache::lonmenu::registerurl(1);
5694: }
1.436 albertel 5695: if (!$args->{'no_nav_bar'}
5696: && !$args->{'only_body'}
5697: && !$args->{'frameset'}) {
5698: $result .= &help_menu_js();
5699: }
1.319 albertel 5700:
1.314 albertel 5701: if (ref($args->{'redirect'})) {
1.414 albertel 5702: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5703: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5704: if (!$inhibit_continue) {
5705: $env{'internal.head.redirect'} = $url;
5706: }
1.313 albertel 5707: $result.=<<ADDMETA
5708: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5709: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5710: ADDMETA
5711: }
1.306 albertel 5712: if (!defined($title)) {
5713: $title = 'The LearningOnline Network with CAPA';
5714: }
1.460 albertel 5715: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5716: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5717: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5718: .$head_extra;
1.306 albertel 5719: return $result;
5720: }
5721:
5722: =pod
5723:
1.340 albertel 5724: =item * &font_settings()
5725:
5726: Returns neccessary <meta> to set the proper encoding
5727:
5728: Inputs: none
5729:
5730: =cut
5731:
5732: sub font_settings {
5733: my $headerstring='';
1.647 www 5734: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5735: $headerstring.=
5736: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5737: }
5738: return $headerstring;
5739: }
5740:
1.341 albertel 5741: =pod
5742:
5743: =item * &xml_begin()
5744:
5745: Returns the needed doctype and <html>
5746:
5747: Inputs: none
5748:
5749: =cut
5750:
5751: sub xml_begin {
5752: my $output='';
5753:
1.592 albertel 5754: if ($env{'internal.start_page'}==1) {
5755: &Apache::lonhtmlcommon::init_htmlareafields();
5756: }
1.342 albertel 5757:
1.341 albertel 5758: if ($env{'browser.mathml'}) {
5759: $output='<?xml version="1.0"?>'
5760: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5761: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5762:
5763: # .'<!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">] >'
5764: .'<!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">'
5765: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5766: .'xmlns="http://www.w3.org/1999/xhtml">';
5767: } else {
5768: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5769: }
5770: return $output;
5771: }
1.340 albertel 5772:
5773: =pod
5774:
1.306 albertel 5775: =item * &endheadtag()
5776:
5777: Returns a uniform </head> for LON-CAPA web pages.
5778:
5779: Inputs: none
5780:
5781: =cut
5782:
5783: sub endheadtag {
5784: return '</head>';
5785: }
5786:
5787: =pod
5788:
5789: =item * &head()
5790:
5791: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5792:
1.648 raeburn 5793: Inputs:
5794:
5795: =over 4
5796:
5797: $title - optional title for the page
5798:
5799: $head_extra - optional extra HTML to put inside the <head>
5800:
5801: =back
1.405 albertel 5802:
1.306 albertel 5803: =cut
5804:
5805: sub head {
1.325 albertel 5806: my ($title,$head_extra,$args) = @_;
5807: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 5808: }
5809:
5810: =pod
5811:
5812: =item * &start_page()
5813:
5814: Returns a complete <html> .. <body> section for LON-CAPA web pages.
5815:
1.648 raeburn 5816: Inputs:
5817:
5818: =over 4
5819:
5820: $title - optional title for the page
5821:
5822: $head_extra - optional extra HTML to incude inside the <head>
5823:
5824: $args - additional optional args supported are:
5825:
5826: =over 8
5827:
5828: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 5829: arg on
1.648 raeburn 5830: no_nav_bar -> is true will set &bodytag() notopbar arg on
5831: add_entries -> additional attributes to add to the <body>
5832: domain -> force to color decorate a page for a
1.317 albertel 5833: specific domain
1.648 raeburn 5834: function -> force usage of a specific rolish color
1.317 albertel 5835: scheme
1.648 raeburn 5836: redirect -> see &headtag()
5837: bgcolor -> override the default page bg color
5838: js_ready -> return a string ready for being used in
1.317 albertel 5839: a javascript writeln
1.648 raeburn 5840: html_encode -> return a string ready for being used in
1.320 albertel 5841: a html attribute
1.648 raeburn 5842: force_register -> if is true will turn on the &bodytag()
1.317 albertel 5843: $forcereg arg
1.648 raeburn 5844: body_title -> alternate text to use instead of $title
1.326 albertel 5845: in the title box that appears, this text
5846: is not auto translated like the $title is
1.648 raeburn 5847: frameset -> if true will start with a <frameset>
1.330 albertel 5848: rather than <body>
1.648 raeburn 5849: no_title -> if true the title bar won't be shown
5850: skip_phases -> hash ref of
1.338 albertel 5851: head -> skip the <html><head> generation
5852: body -> skip all <body> generation
1.648 raeburn 5853: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 5854: 'Switch To Inline Menu' link
1.648 raeburn 5855: no_auto_mt_title -> prevent &mt()ing the title arg
5856: inherit_jsmath -> when creating popup window in a page,
5857: should it have jsmath forced on by the
5858: current page
1.361 albertel 5859:
1.648 raeburn 5860: =back
1.460 albertel 5861:
1.648 raeburn 5862: =back
1.562 albertel 5863:
1.306 albertel 5864: =cut
5865:
5866: sub start_page {
1.309 albertel 5867: my ($title,$head_extra,$args) = @_;
1.318 albertel 5868: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 5869: my %head_args;
1.352 albertel 5870: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 5871: 'bgcolor','frameset','no_nav_bar','only_body',
5872: 'no_auto_mt_title') {
1.319 albertel 5873: if (defined($args->{$arg})) {
1.324 raeburn 5874: $head_args{$arg} = $args->{$arg};
1.319 albertel 5875: }
1.313 albertel 5876: }
1.319 albertel 5877:
1.315 albertel 5878: $env{'internal.start_page'}++;
1.338 albertel 5879: my $result;
5880: if (! exists($args->{'skip_phases'}{'head'}) ) {
5881: $result.=
1.341 albertel 5882: &xml_begin().
1.338 albertel 5883: &headtag($title,$head_extra,\%head_args).&endheadtag();
5884: }
5885:
5886: if (! exists($args->{'skip_phases'}{'body'}) ) {
5887: if ($args->{'frameset'}) {
5888: my $attr_string = &make_attr_string($args->{'force_register'},
5889: $args->{'add_entries'});
5890: $result .= "\n<frameset $attr_string>\n";
5891: } else {
5892: $result .=
5893: &bodytag($title,
5894: $args->{'function'}, $args->{'add_entries'},
5895: $args->{'only_body'}, $args->{'domain'},
5896: $args->{'force_register'}, $args->{'body_title'},
5897: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 5898: $args->{'no_title'}, $args->{'no_inline_link'},
5899: $args);
1.338 albertel 5900: }
1.330 albertel 5901: }
1.338 albertel 5902:
1.315 albertel 5903: if ($args->{'js_ready'}) {
1.317 albertel 5904: $result = &js_ready($result);
1.315 albertel 5905: }
1.320 albertel 5906: if ($args->{'html_encode'}) {
5907: $result = &html_encode($result);
5908: }
1.692.4.2 raeburn 5909: #Breadcrumbs
5910: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
5911: &Apache::lonhtmlcommon::clear_breadcrumbs();
5912: #if any br links exists, add them to the breadcrumbs
5913: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5914: foreach my $crumb (@{$args->{'bread_crumbs'}}){
5915: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
5916: }
5917: }
1.306 albertel 5918:
1.692.4.2 raeburn 5919: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
5920: if (exists($args->{'bread_crumbs_component'})){
5921: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
5922: } else {
5923: $result .= &Apache::lonhtmlcommon::breadcrumbs();
5924: }
5925: }
5926: return $result;
1.692.4.3! raeburn 5927: }
1.330 albertel 5928:
1.306 albertel 5929: =pod
5930:
5931: =item * &head()
5932:
5933: Returns a complete </body></html> section for LON-CAPA web pages.
5934:
1.315 albertel 5935: Inputs: $args - additional optional args supported are:
5936: js_ready -> return a string ready for being used in
5937: a javascript writeln
1.320 albertel 5938: html_encode -> return a string ready for being used in
5939: a html attribute
1.330 albertel 5940: frameset -> if true will start with a <frameset>
5941: rather than <body>
1.493 albertel 5942: dicsussion -> if true will get discussion from
5943: lonxml::xmlend
5944: (you can pass the target and parser arguments
5945: through optional 'target' and 'parser' args
5946: to this routine)
1.306 albertel 5947:
5948: =cut
5949:
5950: sub end_page {
1.315 albertel 5951: my ($args) = @_;
5952: $env{'internal.end_page'}++;
1.330 albertel 5953: my $result;
1.335 albertel 5954: if ($args->{'discussion'}) {
5955: my ($target,$parser);
5956: if (ref($args->{'discussion'})) {
5957: ($target,$parser) =($args->{'discussion'}{'target'},
5958: $args->{'discussion'}{'parser'});
5959: }
5960: $result .= &Apache::lonxml::xmlend($target,$parser);
5961: }
5962:
1.330 albertel 5963: if ($args->{'frameset'}) {
5964: $result .= '</frameset>';
5965: } else {
1.635 raeburn 5966: $result .= &endbodytag($args);
1.330 albertel 5967: }
5968: $result .= "\n</html>";
5969:
1.315 albertel 5970: if ($args->{'js_ready'}) {
1.317 albertel 5971: $result = &js_ready($result);
1.315 albertel 5972: }
1.335 albertel 5973:
1.320 albertel 5974: if ($args->{'html_encode'}) {
5975: $result = &html_encode($result);
5976: }
1.335 albertel 5977:
1.315 albertel 5978: return $result;
5979: }
5980:
1.320 albertel 5981: sub html_encode {
5982: my ($result) = @_;
5983:
1.322 albertel 5984: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 5985:
5986: return $result;
5987: }
1.317 albertel 5988: sub js_ready {
5989: my ($result) = @_;
5990:
1.323 albertel 5991: $result =~ s/[\n\r]/ /xmsg;
5992: $result =~ s/\\/\\\\/xmsg;
5993: $result =~ s/'/\\'/xmsg;
1.372 albertel 5994: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 5995:
5996: return $result;
5997: }
5998:
1.315 albertel 5999: sub validate_page {
6000: if ( exists($env{'internal.start_page'})
1.316 albertel 6001: && $env{'internal.start_page'} > 1) {
6002: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6003: $env{'internal.start_page'}.' '.
1.316 albertel 6004: $ENV{'request.filename'});
1.315 albertel 6005: }
6006: if ( exists($env{'internal.end_page'})
1.316 albertel 6007: && $env{'internal.end_page'} > 1) {
6008: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6009: $env{'internal.end_page'}.' '.
1.316 albertel 6010: $env{'request.filename'});
1.315 albertel 6011: }
6012: if ( exists($env{'internal.start_page'})
6013: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6014: &Apache::lonnet::logthis('start_page called without end_page '.
6015: $env{'request.filename'});
1.315 albertel 6016: }
6017: if ( ! exists($env{'internal.start_page'})
6018: && exists($env{'internal.end_page'})) {
1.316 albertel 6019: &Apache::lonnet::logthis('end_page called without start_page'.
6020: $env{'request.filename'});
1.315 albertel 6021: }
1.306 albertel 6022: }
1.315 albertel 6023:
1.318 albertel 6024: sub simple_error_page {
6025: my ($r,$title,$msg) = @_;
6026: my $page =
6027: &Apache::loncommon::start_page($title).
6028: &mt($msg).
6029: &Apache::loncommon::end_page();
6030: if (ref($r)) {
6031: $r->print($page);
1.327 albertel 6032: return;
1.318 albertel 6033: }
6034: return $page;
6035: }
1.347 albertel 6036:
6037: {
1.610 albertel 6038: my @row_count;
1.347 albertel 6039: sub start_data_table {
1.422 albertel 6040: my ($add_class) = @_;
6041: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6042: unshift(@row_count,0);
1.422 albertel 6043: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6044: }
6045:
6046: sub end_data_table {
1.610 albertel 6047: shift(@row_count);
1.389 albertel 6048: return '</table>'."\n";;
1.347 albertel 6049: }
6050:
6051: sub start_data_table_row {
1.422 albertel 6052: my ($add_class) = @_;
1.610 albertel 6053: $row_count[0]++;
6054: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6055: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6056: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6057: }
1.471 banghart 6058:
6059: sub continue_data_table_row {
6060: my ($add_class) = @_;
1.610 albertel 6061: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6062: $css_class = (join(' ',$css_class,$add_class));
6063: return '<tr class="'.$css_class.'">'."\n";;
6064: }
1.347 albertel 6065:
6066: sub end_data_table_row {
1.389 albertel 6067: return '</tr>'."\n";;
1.347 albertel 6068: }
1.367 www 6069:
1.421 albertel 6070: sub start_data_table_empty_row {
1.610 albertel 6071: $row_count[0]++;
1.421 albertel 6072: return '<tr class="LC_empty_row" >'."\n";;
6073: }
6074:
6075: sub end_data_table_empty_row {
6076: return '</tr>'."\n";;
6077: }
6078:
1.367 www 6079: sub start_data_table_header_row {
1.389 albertel 6080: return '<tr class="LC_header_row">'."\n";;
1.367 www 6081: }
6082:
6083: sub end_data_table_header_row {
1.389 albertel 6084: return '</tr>'."\n";;
1.367 www 6085: }
1.347 albertel 6086: }
6087:
1.548 albertel 6088: =pod
6089:
6090: =item * &inhibit_menu_check($arg)
6091:
6092: Checks for a inhibitmenu state and generates output to preserve it
6093:
6094: Inputs: $arg - can be any of
6095: - undef - in which case the return value is a string
6096: to add into arguments list of a uri
6097: - 'input' - in which case the return value is a HTML
6098: <form> <input> field of type hidden to
6099: preserve the value
6100: - a url - in which case the return value is the url with
6101: the neccesary cgi args added to preserve the
6102: inhibitmenu state
6103: - a ref to a url - no return value, but the string is
6104: updated to include the neccessary cgi
6105: args to preserve the inhibitmenu state
6106:
6107: =cut
6108:
6109: sub inhibit_menu_check {
6110: my ($arg) = @_;
6111: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6112: if ($arg eq 'input') {
6113: if ($env{'form.inhibitmenu'}) {
6114: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6115: } else {
6116: return
6117: }
6118: }
6119: if ($env{'form.inhibitmenu'}) {
6120: if (ref($arg)) {
6121: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6122: } elsif ($arg eq '') {
6123: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6124: } else {
6125: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6126: }
6127: }
6128: if (!ref($arg)) {
6129: return $arg;
6130: }
6131: }
6132:
1.251 albertel 6133: ###############################################
1.182 matthew 6134:
6135: =pod
6136:
1.549 albertel 6137: =back
6138:
6139: =head1 User Information Routines
6140:
6141: =over 4
6142:
1.405 albertel 6143: =item * &get_users_function()
1.182 matthew 6144:
6145: Used by &bodytag to determine the current users primary role.
6146: Returns either 'student','coordinator','admin', or 'author'.
6147:
6148: =cut
6149:
6150: ###############################################
6151: sub get_users_function {
6152: my $function = 'student';
1.258 albertel 6153: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6154: $function='coordinator';
6155: }
1.258 albertel 6156: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6157: $function='admin';
6158: }
1.258 albertel 6159: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6160: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6161: $function='author';
6162: }
6163: return $function;
1.54 www 6164: }
1.99 www 6165:
6166: ###############################################
6167:
1.233 raeburn 6168: =pod
6169:
1.692.4.2 raeburn 6170: =item * &show_course()
6171:
6172: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
6173: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
6174: Inputs:
6175: None
6176:
6177: Outputs:
6178: Scalar: 1 if 'Course' to be used, 0 otherwise.
6179:
6180: =cut
6181:
6182: ###############################################
6183: sub show_course {
6184: my $course = !$env{'user.adv'};
6185: if (!$env{'user.adv'}) {
6186: foreach my $env (keys(%env)) {
6187: next if ($env !~ m/^user\.priv\./);
6188: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
6189: $course = 0;
6190: last;
6191: }
6192: }
6193: }
6194: return $course;
6195: }
6196:
6197: ###############################################
6198:
6199: =pod
6200:
1.542 raeburn 6201: =item * &check_user_status()
1.274 raeburn 6202:
6203: Determines current status of supplied role for a
6204: specific user. Roles can be active, previous or future.
6205:
6206: Inputs:
6207: user's domain, user's username, course's domain,
1.375 raeburn 6208: course's number, optional section ID.
1.274 raeburn 6209:
6210: Outputs:
6211: role status: active, previous or future.
6212:
6213: =cut
6214:
6215: sub check_user_status {
1.412 raeburn 6216: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6217: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6218: my @uroles = keys %userinfo;
6219: my $srchstr;
6220: my $active_chk = 'none';
1.412 raeburn 6221: my $now = time;
1.274 raeburn 6222: if (@uroles > 0) {
1.412 raeburn 6223: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6224: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6225: } else {
1.412 raeburn 6226: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6227: }
6228: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6229: my $role_end = 0;
6230: my $role_start = 0;
6231: $active_chk = 'active';
1.412 raeburn 6232: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6233: $role_end = $1;
6234: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6235: $role_start = $1;
1.274 raeburn 6236: }
6237: }
6238: if ($role_start > 0) {
1.412 raeburn 6239: if ($now < $role_start) {
1.274 raeburn 6240: $active_chk = 'future';
6241: }
6242: }
6243: if ($role_end > 0) {
1.412 raeburn 6244: if ($now > $role_end) {
1.274 raeburn 6245: $active_chk = 'previous';
6246: }
6247: }
6248: }
6249: }
6250: return $active_chk;
6251: }
6252:
6253: ###############################################
6254:
6255: =pod
6256:
1.405 albertel 6257: =item * &get_sections()
1.233 raeburn 6258:
6259: Determines all the sections for a course including
6260: sections with students and sections containing other roles.
1.419 raeburn 6261: Incoming parameters:
6262:
6263: 1. domain
6264: 2. course number
6265: 3. reference to array containing roles for which sections should
6266: be gathered (optional).
6267: 4. reference to array containing status types for which sections
6268: should be gathered (optional).
6269:
6270: If the third argument is undefined, sections are gathered for any role.
6271: If the fourth argument is undefined, sections are gathered for any status.
6272: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6273:
1.374 raeburn 6274: Returns section hash (keys are section IDs, values are
6275: number of users in each section), subject to the
1.419 raeburn 6276: optional roles filter, optional status filter
1.233 raeburn 6277:
6278: =cut
6279:
6280: ###############################################
6281: sub get_sections {
1.419 raeburn 6282: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6283: if (!defined($cdom) || !defined($cnum)) {
6284: my $cid = $env{'request.course.id'};
6285:
6286: return if (!defined($cid));
6287:
6288: $cdom = $env{'course.'.$cid.'.domain'};
6289: $cnum = $env{'course.'.$cid.'.num'};
6290: }
6291:
6292: my %sectioncount;
1.419 raeburn 6293: my $now = time;
1.240 albertel 6294:
1.366 albertel 6295: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6296: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6297: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6298: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6299: my $start_index = &Apache::loncoursedata::CL_START();
6300: my $end_index = &Apache::loncoursedata::CL_END();
6301: my $status;
1.366 albertel 6302: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6303: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6304: $data->[$status_index],
6305: $data->[$start_index],
6306: $data->[$end_index]);
6307: if ($stu_status eq 'Active') {
6308: $status = 'active';
6309: } elsif ($end < $now) {
6310: $status = 'previous';
6311: } elsif ($start > $now) {
6312: $status = 'future';
6313: }
6314: if ($section ne '-1' && $section !~ /^\s*$/) {
6315: if ((!defined($possible_status)) || (($status ne '') &&
6316: (grep/^\Q$status\E$/,@{$possible_status}))) {
6317: $sectioncount{$section}++;
6318: }
1.240 albertel 6319: }
6320: }
6321: }
6322: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6323: foreach my $user (sort(keys(%courseroles))) {
6324: if ($user !~ /^(\w{2})/) { next; }
6325: my ($role) = ($user =~ /^(\w{2})/);
6326: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6327: my ($section,$status);
1.240 albertel 6328: if ($role eq 'cr' &&
6329: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6330: $section=$1;
6331: }
6332: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6333: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6334: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6335: if ($end == -1 && $start == -1) {
6336: next; #deleted role
6337: }
6338: if (!defined($possible_status)) {
6339: $sectioncount{$section}++;
6340: } else {
6341: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6342: $status = 'active';
6343: } elsif ($end < $now) {
6344: $status = 'future';
6345: } elsif ($start > $now) {
6346: $status = 'previous';
6347: }
6348: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6349: $sectioncount{$section}++;
6350: }
6351: }
1.233 raeburn 6352: }
1.366 albertel 6353: return %sectioncount;
1.233 raeburn 6354: }
6355:
1.274 raeburn 6356: ###############################################
1.294 raeburn 6357:
6358: =pod
1.405 albertel 6359:
6360: =item * &get_course_users()
6361:
1.275 raeburn 6362: Retrieves usernames:domains for users in the specified course
6363: with specific role(s), and access status.
6364:
6365: Incoming parameters:
1.277 albertel 6366: 1. course domain
6367: 2. course number
6368: 3. access status: users must have - either active,
1.275 raeburn 6369: previous, future, or all.
1.277 albertel 6370: 4. reference to array of permissible roles
1.288 raeburn 6371: 5. reference to array of section restrictions (optional)
6372: 6. reference to results object (hash of hashes).
6373: 7. reference to optional userdata hash
1.609 raeburn 6374: 8. reference to optional statushash
1.630 raeburn 6375: 9. flag if privileged users (except those set to unhide in
6376: course settings) should be excluded
1.609 raeburn 6377: Keys of top level results hash are roles.
1.275 raeburn 6378: Keys of inner hashes are username:domain, with
6379: values set to access type.
1.288 raeburn 6380: Optional userdata hash returns an array with arguments in the
6381: same order as loncoursedata::get_classlist() for student data.
6382:
1.609 raeburn 6383: Optional statushash returns
6384:
1.288 raeburn 6385: Entries for end, start, section and status are blank because
6386: of the possibility of multiple values for non-student roles.
6387:
1.275 raeburn 6388: =cut
1.405 albertel 6389:
1.275 raeburn 6390: ###############################################
1.405 albertel 6391:
1.275 raeburn 6392: sub get_course_users {
1.630 raeburn 6393: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6394: my %idx = ();
1.419 raeburn 6395: my %seclists;
1.288 raeburn 6396:
6397: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6398: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6399: $idx{end} = &Apache::loncoursedata::CL_END();
6400: $idx{start} = &Apache::loncoursedata::CL_START();
6401: $idx{id} = &Apache::loncoursedata::CL_ID();
6402: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6403: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6404: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6405:
1.290 albertel 6406: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6407: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6408: my $now = time;
1.277 albertel 6409: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6410: my $match = 0;
1.412 raeburn 6411: my $secmatch = 0;
1.419 raeburn 6412: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6413: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6414: if ($section eq '') {
6415: $section = 'none';
6416: }
1.291 albertel 6417: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6418: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6419: $secmatch = 1;
6420: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6421: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6422: $secmatch = 1;
6423: }
6424: } else {
1.419 raeburn 6425: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6426: $secmatch = 1;
6427: }
1.290 albertel 6428: }
1.412 raeburn 6429: if (!$secmatch) {
6430: next;
6431: }
1.419 raeburn 6432: }
1.275 raeburn 6433: if (defined($$types{'active'})) {
1.288 raeburn 6434: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6435: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6436: $match = 1;
1.275 raeburn 6437: }
6438: }
6439: if (defined($$types{'previous'})) {
1.609 raeburn 6440: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6441: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6442: $match = 1;
1.275 raeburn 6443: }
6444: }
6445: if (defined($$types{'future'})) {
1.609 raeburn 6446: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6447: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6448: $match = 1;
1.275 raeburn 6449: }
6450: }
1.609 raeburn 6451: if ($match) {
6452: push(@{$seclists{$student}},$section);
6453: if (ref($userdata) eq 'HASH') {
6454: $$userdata{$student} = $$classlist{$student};
6455: }
6456: if (ref($statushash) eq 'HASH') {
6457: $statushash->{$student}{'st'}{$section} = $status;
6458: }
1.288 raeburn 6459: }
1.275 raeburn 6460: }
6461: }
1.412 raeburn 6462: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6463: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6464: my $now = time;
1.609 raeburn 6465: my %displaystatus = ( previous => 'Expired',
6466: active => 'Active',
6467: future => 'Future',
6468: );
1.630 raeburn 6469: my %nothide;
6470: if ($hidepriv) {
6471: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6472: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6473: if ($user !~ /:/) {
6474: $nothide{join(':',split(/[\@]/,$user))}=1;
6475: } else {
6476: $nothide{$user} = 1;
6477: }
6478: }
6479: }
1.439 raeburn 6480: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6481: my $match = 0;
1.412 raeburn 6482: my $secmatch = 0;
1.439 raeburn 6483: my $status;
1.412 raeburn 6484: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6485: $user =~ s/:$//;
1.439 raeburn 6486: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6487: if ($end == -1 || $start == -1) {
6488: next;
6489: }
6490: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6491: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6492: my ($uname,$udom) = split(/:/,$user);
6493: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6494: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6495: $secmatch = 1;
6496: } elsif ($usec eq '') {
1.420 albertel 6497: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6498: $secmatch = 1;
6499: }
6500: } else {
6501: if (grep(/^\Q$usec\E$/,@{$sections})) {
6502: $secmatch = 1;
6503: }
6504: }
6505: if (!$secmatch) {
6506: next;
6507: }
1.288 raeburn 6508: }
1.419 raeburn 6509: if ($usec eq '') {
6510: $usec = 'none';
6511: }
1.275 raeburn 6512: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6513: if ($hidepriv) {
6514: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6515: (!$nothide{$uname.':'.$udom})) {
6516: next;
6517: }
6518: }
1.503 raeburn 6519: if ($end > 0 && $end < $now) {
1.439 raeburn 6520: $status = 'previous';
6521: } elsif ($start > $now) {
6522: $status = 'future';
6523: } else {
6524: $status = 'active';
6525: }
1.277 albertel 6526: foreach my $type (keys(%{$types})) {
1.275 raeburn 6527: if ($status eq $type) {
1.420 albertel 6528: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6529: push(@{$$users{$role}{$user}},$type);
6530: }
1.288 raeburn 6531: $match = 1;
6532: }
6533: }
1.419 raeburn 6534: if (($match) && (ref($userdata) eq 'HASH')) {
6535: if (!exists($$userdata{$uname.':'.$udom})) {
6536: &get_user_info($udom,$uname,\%idx,$userdata);
6537: }
1.420 albertel 6538: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6539: push(@{$seclists{$uname.':'.$udom}},$usec);
6540: }
1.609 raeburn 6541: if (ref($statushash) eq 'HASH') {
6542: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6543: }
1.275 raeburn 6544: }
6545: }
6546: }
6547: }
1.290 albertel 6548: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6549: if ((defined($cdom)) && (defined($cnum))) {
6550: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6551: if ( defined($csettings{'internal.courseowner'}) ) {
6552: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6553: next if ($owner eq '');
6554: my ($ownername,$ownerdom);
6555: if ($owner =~ /^([^:]+):([^:]+)$/) {
6556: $ownername = $1;
6557: $ownerdom = $2;
6558: } else {
6559: $ownername = $owner;
6560: $ownerdom = $cdom;
6561: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6562: }
6563: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6564: if (defined($userdata) &&
1.609 raeburn 6565: !exists($$userdata{$owner})) {
6566: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6567: if (!grep(/^none$/,@{$seclists{$owner}})) {
6568: push(@{$seclists{$owner}},'none');
6569: }
6570: if (ref($statushash) eq 'HASH') {
6571: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6572: }
1.290 albertel 6573: }
1.279 raeburn 6574: }
6575: }
6576: }
1.419 raeburn 6577: foreach my $user (keys(%seclists)) {
6578: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6579: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6580: }
1.275 raeburn 6581: }
6582: return;
6583: }
6584:
1.288 raeburn 6585: sub get_user_info {
6586: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6587: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6588: &plainname($uname,$udom,'lastname');
1.291 albertel 6589: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6590: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6591: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6592: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6593: return;
6594: }
1.275 raeburn 6595:
1.472 raeburn 6596: ###############################################
6597:
6598: =pod
6599:
6600: =item * &get_user_quota()
6601:
6602: Retrieves quota assigned for storage of portfolio files for a user
6603:
6604: Incoming parameters:
6605: 1. user's username
6606: 2. user's domain
6607:
6608: Returns:
1.536 raeburn 6609: 1. Disk quota (in Mb) assigned to student.
6610: 2. (Optional) Type of setting: custom or default
6611: (individually assigned or default for user's
6612: institutional status).
6613: 3. (Optional) - User's institutional status (e.g., faculty, staff
6614: or student - types as defined in localenroll::inst_usertypes
6615: for user's domain, which determines default quota for user.
6616: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6617:
6618: If a value has been stored in the user's environment,
1.536 raeburn 6619: it will return that, otherwise it returns the maximal default
6620: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6621:
6622: =cut
6623:
6624: ###############################################
6625:
6626:
6627: sub get_user_quota {
6628: my ($uname,$udom) = @_;
1.536 raeburn 6629: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6630: if (!defined($udom)) {
6631: $udom = $env{'user.domain'};
6632: }
6633: if (!defined($uname)) {
6634: $uname = $env{'user.name'};
6635: }
6636: if (($udom eq '' || $uname eq '') ||
6637: ($udom eq 'public') && ($uname eq 'public')) {
6638: $quota = 0;
1.536 raeburn 6639: $quotatype = 'default';
6640: $defquota = 0;
1.472 raeburn 6641: } else {
1.536 raeburn 6642: my $inststatus;
1.472 raeburn 6643: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6644: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6645: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6646: } else {
1.536 raeburn 6647: my %userenv =
6648: &Apache::lonnet::get('environment',['portfolioquota',
6649: 'inststatus'],$udom,$uname);
1.472 raeburn 6650: my ($tmp) = keys(%userenv);
6651: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6652: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6653: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6654: } else {
6655: undef(%userenv);
6656: }
6657: }
1.536 raeburn 6658: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6659: if ($quota eq '') {
1.536 raeburn 6660: $quota = $defquota;
6661: $quotatype = 'default';
6662: } else {
6663: $quotatype = 'custom';
1.472 raeburn 6664: }
6665: }
1.536 raeburn 6666: if (wantarray) {
6667: return ($quota,$quotatype,$settingstatus,$defquota);
6668: } else {
6669: return $quota;
6670: }
1.472 raeburn 6671: }
6672:
6673: ###############################################
6674:
6675: =pod
6676:
6677: =item * &default_quota()
6678:
1.536 raeburn 6679: Retrieves default quota assigned for storage of user portfolio files,
6680: given an (optional) user's institutional status.
1.472 raeburn 6681:
6682: Incoming parameters:
6683: 1. domain
1.536 raeburn 6684: 2. (Optional) institutional status(es). This is a : separated list of
6685: status types (e.g., faculty, staff, student etc.)
6686: which apply to the user for whom the default is being retrieved.
6687: If the institutional status string in undefined, the domain
6688: default quota will be returned.
1.472 raeburn 6689:
6690: Returns:
6691: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6692: 2. (Optional) institutional type which determined the value of the
6693: default quota.
1.472 raeburn 6694:
6695: If a value has been stored in the domain's configuration db,
6696: it will return that, otherwise it returns 20 (for backwards
6697: compatibility with domains which have not set up a configuration
6698: db file; the original statically defined portfolio quota was 20 Mb).
6699:
1.536 raeburn 6700: If the user's status includes multiple types (e.g., staff and student),
6701: the largest default quota which applies to the user determines the
6702: default quota returned.
6703:
1.472 raeburn 6704: =cut
6705:
6706: ###############################################
6707:
6708:
6709: sub default_quota {
1.536 raeburn 6710: my ($udom,$inststatus) = @_;
6711: my ($defquota,$settingstatus);
6712: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6713: ['quotas'],$udom);
6714: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6715: if ($inststatus ne '') {
1.692.4.2 raeburn 6716: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 6717: foreach my $item (@statuses) {
1.692.4.2 raeburn 6718: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6719: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6720: if ($defquota eq '') {
6721: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6722: $settingstatus = $item;
6723: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6724: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6725: $settingstatus = $item;
6726: }
6727: }
6728: } else {
6729: if ($quotahash{'quotas'}{$item} ne '') {
6730: if ($defquota eq '') {
6731: $defquota = $quotahash{'quotas'}{$item};
6732: $settingstatus = $item;
6733: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6734: $defquota = $quotahash{'quotas'}{$item};
6735: $settingstatus = $item;
6736: }
1.536 raeburn 6737: }
6738: }
6739: }
6740: }
6741: if ($defquota eq '') {
1.692.4.2 raeburn 6742: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6743: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6744: } else {
6745: $defquota = $quotahash{'quotas'}{'default'};
6746: }
1.536 raeburn 6747: $settingstatus = 'default';
6748: }
6749: } else {
6750: $settingstatus = 'default';
6751: $defquota = 20;
6752: }
6753: if (wantarray) {
6754: return ($defquota,$settingstatus);
1.472 raeburn 6755: } else {
1.536 raeburn 6756: return $defquota;
1.472 raeburn 6757: }
6758: }
6759:
1.384 raeburn 6760: sub get_secgrprole_info {
6761: my ($cdom,$cnum,$needroles,$type) = @_;
6762: my %sections_count = &get_sections($cdom,$cnum);
6763: my @sections = (sort {$a <=> $b} keys(%sections_count));
6764: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6765: my @groups = sort(keys(%curr_groups));
6766: my $allroles = [];
6767: my $rolehash;
6768: my $accesshash = {
6769: active => 'Currently has access',
6770: future => 'Will have future access',
6771: previous => 'Previously had access',
6772: };
6773: if ($needroles) {
6774: $rolehash = {'all' => 'all'};
1.385 albertel 6775: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6776: if (&Apache::lonnet::error(%user_roles)) {
6777: undef(%user_roles);
6778: }
6779: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6780: my ($role)=split(/\:/,$item,2);
6781: if ($role eq 'cr') { next; }
6782: if ($role =~ /^cr/) {
6783: $$rolehash{$role} = (split('/',$role))[3];
6784: } else {
6785: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6786: }
6787: }
6788: foreach my $key (sort(keys(%{$rolehash}))) {
6789: push(@{$allroles},$key);
6790: }
6791: push (@{$allroles},'st');
6792: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6793: }
6794: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6795: }
6796:
1.555 raeburn 6797: sub user_picker {
1.627 raeburn 6798: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6799: my $currdom = $dom;
6800: my %curr_selected = (
6801: srchin => 'dom',
1.580 raeburn 6802: srchby => 'lastname',
1.555 raeburn 6803: );
6804: my $srchterm;
1.625 raeburn 6805: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6806: if ($srch->{'srchby'} ne '') {
6807: $curr_selected{'srchby'} = $srch->{'srchby'};
6808: }
6809: if ($srch->{'srchin'} ne '') {
6810: $curr_selected{'srchin'} = $srch->{'srchin'};
6811: }
6812: if ($srch->{'srchtype'} ne '') {
6813: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6814: }
6815: if ($srch->{'srchdomain'} ne '') {
6816: $currdom = $srch->{'srchdomain'};
6817: }
6818: $srchterm = $srch->{'srchterm'};
6819: }
6820: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6821: 'usr' => 'Search criteria',
1.563 raeburn 6822: 'doma' => 'Domain/institution to search',
1.558 albertel 6823: 'uname' => 'username',
6824: 'lastname' => 'last name',
1.555 raeburn 6825: 'lastfirst' => 'last name, first name',
1.558 albertel 6826: 'crs' => 'in this course',
1.576 raeburn 6827: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6828: 'alc' => 'all LON-CAPA',
1.573 raeburn 6829: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6830: 'exact' => 'is',
6831: 'contains' => 'contains',
1.569 raeburn 6832: 'begins' => 'begins with',
1.571 raeburn 6833: 'youm' => "You must include some text to search for.",
6834: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6835: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6836: 'yomc' => "You must choose a domain when using an institutional directory search.",
6837: 'ymcd' => "You must choose a domain when using a domain search.",
6838: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6839: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6840: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6841: );
1.563 raeburn 6842: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6843: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6844:
6845: my @srchins = ('crs','dom','alc','instd');
6846:
6847: foreach my $option (@srchins) {
6848: # FIXME 'alc' option unavailable until
6849: # loncreateuser::print_user_query_page()
6850: # has been completed.
6851: next if ($option eq 'alc');
6852: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6853: if ($curr_selected{'srchin'} eq $option) {
6854: $srchinsel .= '
6855: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6856: } else {
6857: $srchinsel .= '
6858: <option value="'.$option.'">'.$lt{$option}.'</option>';
6859: }
1.555 raeburn 6860: }
1.563 raeburn 6861: $srchinsel .= "\n </select>\n";
1.555 raeburn 6862:
6863: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 6864: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 6865: if ($curr_selected{'srchby'} eq $option) {
6866: $srchbysel .= '
6867: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6868: } else {
6869: $srchbysel .= '
6870: <option value="'.$option.'">'.$lt{$option}.'</option>';
6871: }
6872: }
6873: $srchbysel .= "\n </select>\n";
6874:
6875: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 6876: foreach my $option ('begins','contains','exact') {
1.555 raeburn 6877: if ($curr_selected{'srchtype'} eq $option) {
6878: $srchtypesel .= '
6879: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6880: } else {
6881: $srchtypesel .= '
6882: <option value="'.$option.'">'.$lt{$option}.'</option>';
6883: }
6884: }
6885: $srchtypesel .= "\n </select>\n";
6886:
1.558 albertel 6887: my ($newuserscript,$new_user_create);
1.556 raeburn 6888:
6889: if ($forcenewuser) {
1.576 raeburn 6890: if (ref($srch) eq 'HASH') {
6891: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 6892: if ($cancreate) {
6893: $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>';
6894: } else {
1.692.4.2 raeburn 6895: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 6896: my %usertypetext = (
6897: official => 'institutional',
6898: unofficial => 'non-institutional',
6899: );
1.692.4.2 raeburn 6900: $new_user_create = '<p class="LC_warning">'.
6901: &mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.
6902: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="'.$helplink.'">','</a>').'</p><br />';
1.627 raeburn 6903: }
1.576 raeburn 6904: }
6905: }
6906:
1.556 raeburn 6907: $newuserscript = <<"ENDSCRIPT";
6908:
1.570 raeburn 6909: function setSearch(createnew,callingForm) {
1.556 raeburn 6910: if (createnew == 1) {
1.570 raeburn 6911: for (var i=0; i<callingForm.srchby.length; i++) {
6912: if (callingForm.srchby.options[i].value == 'uname') {
6913: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6914: }
6915: }
1.570 raeburn 6916: for (var i=0; i<callingForm.srchin.length; i++) {
6917: if ( callingForm.srchin.options[i].value == 'dom') {
6918: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6919: }
6920: }
1.570 raeburn 6921: for (var i=0; i<callingForm.srchtype.length; i++) {
6922: if (callingForm.srchtype.options[i].value == 'exact') {
6923: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6924: }
6925: }
1.570 raeburn 6926: for (var i=0; i<callingForm.srchdomain.length; i++) {
6927: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6928: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6929: }
6930: }
6931: }
6932: }
6933: ENDSCRIPT
1.558 albertel 6934:
1.556 raeburn 6935: }
6936:
1.555 raeburn 6937: my $output = <<"END_BLOCK";
1.556 raeburn 6938: <script type="text/javascript">
1.570 raeburn 6939: function validateEntry(callingForm) {
1.558 albertel 6940:
1.556 raeburn 6941: var checkok = 1;
1.558 albertel 6942: var srchin;
1.570 raeburn 6943: for (var i=0; i<callingForm.srchin.length; i++) {
6944: if ( callingForm.srchin[i].checked ) {
6945: srchin = callingForm.srchin[i].value;
1.558 albertel 6946: }
6947: }
6948:
1.570 raeburn 6949: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6950: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6951: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6952: var srchterm = callingForm.srchterm.value;
6953: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6954: var msg = "";
6955:
6956: if (srchterm == "") {
6957: checkok = 0;
1.571 raeburn 6958: msg += "$lt{'youm'}\\n";
1.556 raeburn 6959: }
6960:
1.569 raeburn 6961: if (srchtype== 'begins') {
6962: if (srchterm.length < 2) {
6963: checkok = 0;
1.571 raeburn 6964: msg += "$lt{'thte'}\\n";
1.569 raeburn 6965: }
6966: }
6967:
1.556 raeburn 6968: if (srchtype== 'contains') {
6969: if (srchterm.length < 3) {
6970: checkok = 0;
1.571 raeburn 6971: msg += "$lt{'thet'}\\n";
1.556 raeburn 6972: }
6973: }
6974: if (srchin == 'instd') {
6975: if (srchdomain == '') {
6976: checkok = 0;
1.571 raeburn 6977: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6978: }
6979: }
6980: if (srchin == 'dom') {
6981: if (srchdomain == '') {
6982: checkok = 0;
1.571 raeburn 6983: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6984: }
6985: }
6986: if (srchby == 'lastfirst') {
6987: if (srchterm.indexOf(",") == -1) {
6988: checkok = 0;
1.571 raeburn 6989: msg += "$lt{'whus'}\\n";
1.556 raeburn 6990: }
6991: if (srchterm.indexOf(",") == srchterm.length -1) {
6992: checkok = 0;
1.571 raeburn 6993: msg += "$lt{'whse'}\\n";
1.556 raeburn 6994: }
6995: }
6996: if (checkok == 0) {
1.571 raeburn 6997: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6998: return;
6999: }
7000: if (checkok == 1) {
1.570 raeburn 7001: callingForm.submit();
1.556 raeburn 7002: }
7003: }
7004:
7005: $newuserscript
7006:
7007: </script>
1.558 albertel 7008:
7009: $new_user_create
7010:
1.555 raeburn 7011: <table>
1.558 albertel 7012: <tr>
1.573 raeburn 7013: <td>$lt{'doma'}:</td>
7014: <td>$domform</td>
7015: </td>
7016: </tr>
7017: <tr>
7018: <td>$lt{'usr'}:</td>
1.563 raeburn 7019: <td>$srchbysel
7020: $srchtypesel
7021: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7022: $srchinsel
1.563 raeburn 7023: </td>
7024: </tr>
1.555 raeburn 7025: </table>
7026: <br />
7027: END_BLOCK
1.558 albertel 7028:
1.555 raeburn 7029: return $output;
7030: }
7031:
1.612 raeburn 7032: sub user_rule_check {
1.615 raeburn 7033: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7034: my $response;
7035: if (ref($usershash) eq 'HASH') {
7036: foreach my $user (keys(%{$usershash})) {
7037: my ($uname,$udom) = split(/:/,$user);
7038: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7039: my ($id,$newuser);
1.612 raeburn 7040: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7041: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7042: $id = $usershash->{$user}->{'id'};
7043: }
7044: my $inst_response;
7045: if (ref($checks) eq 'HASH') {
7046: if (defined($checks->{'username'})) {
1.615 raeburn 7047: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7048: &Apache::lonnet::get_instuser($udom,$uname);
7049: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7050: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7051: &Apache::lonnet::get_instuser($udom,undef,$id);
7052: }
1.615 raeburn 7053: } else {
7054: ($inst_response,%{$inst_results->{$user}}) =
7055: &Apache::lonnet::get_instuser($udom,$uname);
7056: return;
1.612 raeburn 7057: }
1.615 raeburn 7058: if (!$got_rules->{$udom}) {
1.612 raeburn 7059: my %domconfig = &Apache::lonnet::get_dom('configuration',
7060: ['usercreation'],$udom);
7061: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7062: foreach my $item ('username','id') {
1.612 raeburn 7063: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7064: $$curr_rules{$udom}{$item} =
7065: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7066: }
7067: }
7068: }
1.615 raeburn 7069: $got_rules->{$udom} = 1;
1.585 raeburn 7070: }
1.612 raeburn 7071: foreach my $item (keys(%{$checks})) {
7072: if (ref($$curr_rules{$udom}) eq 'HASH') {
7073: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7074: if (@{$$curr_rules{$udom}{$item}} > 0) {
7075: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7076: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7077: if ($rule_check{$rule}) {
7078: $$rulematch{$user}{$item} = $rule;
7079: if ($inst_response eq 'ok') {
1.615 raeburn 7080: if (ref($inst_results) eq 'HASH') {
7081: if (ref($inst_results->{$user}) eq 'HASH') {
7082: if (keys(%{$inst_results->{$user}}) == 0) {
7083: $$alerts{$item}{$udom}{$uname} = 1;
7084: }
1.612 raeburn 7085: }
7086: }
1.615 raeburn 7087: }
7088: last;
1.585 raeburn 7089: }
7090: }
7091: }
7092: }
7093: }
7094: }
7095: }
7096: }
1.612 raeburn 7097: return;
7098: }
7099:
7100: sub user_rule_formats {
7101: my ($domain,$domdesc,$curr_rules,$check) = @_;
7102: my %text = (
7103: 'username' => 'Usernames',
7104: 'id' => 'IDs',
7105: );
7106: my $output;
7107: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7108: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7109: if (@{$ruleorder} > 0) {
7110: $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>';
7111: foreach my $rule (@{$ruleorder}) {
7112: if (ref($curr_rules) eq 'ARRAY') {
7113: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7114: if (ref($rules->{$rule}) eq 'HASH') {
7115: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7116: $rules->{$rule}{'desc'}.'</li>';
7117: }
7118: }
7119: }
7120: }
7121: $output .= '</ul>';
7122: }
7123: }
7124: return $output;
7125: }
7126:
7127: sub instrule_disallow_msg {
1.615 raeburn 7128: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7129: my $response;
7130: my %text = (
7131: item => 'username',
7132: items => 'usernames',
7133: match => 'matches',
7134: do => 'does',
7135: action => 'a username',
7136: one => 'one',
7137: );
7138: if ($count > 1) {
7139: $text{'item'} = 'usernames';
7140: $text{'match'} ='match';
7141: $text{'do'} = 'do';
7142: $text{'action'} = 'usernames',
7143: $text{'one'} = 'ones';
7144: }
7145: if ($checkitem eq 'id') {
7146: $text{'items'} = 'IDs';
7147: $text{'item'} = 'ID';
7148: $text{'action'} = 'an ID';
1.615 raeburn 7149: if ($count > 1) {
7150: $text{'item'} = 'IDs';
7151: $text{'action'} = 'IDs';
7152: }
1.612 raeburn 7153: }
1.674 bisitz 7154: $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 7155: if ($mode eq 'upload') {
7156: if ($checkitem eq 'username') {
7157: $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'}.");
7158: } elsif ($checkitem eq 'id') {
1.674 bisitz 7159: $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 7160: }
1.669 raeburn 7161: } elsif ($mode eq 'selfcreate') {
7162: if ($checkitem eq 'id') {
7163: $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.");
7164: }
1.615 raeburn 7165: } else {
7166: if ($checkitem eq 'username') {
7167: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7168: } elsif ($checkitem eq 'id') {
7169: $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.");
7170: }
1.612 raeburn 7171: }
7172: return $response;
1.585 raeburn 7173: }
7174:
1.624 raeburn 7175: sub personal_data_fieldtitles {
7176: my %fieldtitles = &Apache::lonlocal::texthash (
7177: id => 'Student/Employee ID',
7178: permanentemail => 'E-mail address',
7179: lastname => 'Last Name',
7180: firstname => 'First Name',
7181: middlename => 'Middle Name',
7182: generation => 'Generation',
7183: gen => 'Generation',
1.692.4.2 raeburn 7184: inststatus => 'Affiliation',
1.624 raeburn 7185: );
7186: return %fieldtitles;
7187: }
7188:
1.642 raeburn 7189: sub sorted_inst_types {
7190: my ($dom) = @_;
7191: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7192: my $othertitle = &mt('All users');
7193: if ($env{'request.course.id'}) {
1.668 raeburn 7194: $othertitle = &mt('Any users');
1.642 raeburn 7195: }
7196: my @types;
7197: if (ref($order) eq 'ARRAY') {
7198: @types = @{$order};
7199: }
7200: if (@types == 0) {
7201: if (ref($usertypes) eq 'HASH') {
7202: @types = sort(keys(%{$usertypes}));
7203: }
7204: }
7205: if (keys(%{$usertypes}) > 0) {
7206: $othertitle = &mt('Other users');
7207: }
7208: return ($othertitle,$usertypes,\@types);
7209: }
7210:
1.645 raeburn 7211: sub get_institutional_codes {
7212: my ($settings,$allcourses,$LC_code) = @_;
7213: # Get complete list of course sections to update
7214: my @currsections = ();
7215: my @currxlists = ();
7216: my $coursecode = $$settings{'internal.coursecode'};
7217:
7218: if ($$settings{'internal.sectionnums'} ne '') {
7219: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7220: }
7221:
7222: if ($$settings{'internal.crosslistings'} ne '') {
7223: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7224: }
7225:
7226: if (@currxlists > 0) {
7227: foreach (@currxlists) {
7228: if (m/^([^:]+):(\w*)$/) {
7229: unless (grep/^$1$/,@{$allcourses}) {
7230: push @{$allcourses},$1;
7231: $$LC_code{$1} = $2;
7232: }
7233: }
7234: }
7235: }
7236:
7237: if (@currsections > 0) {
7238: foreach (@currsections) {
7239: if (m/^(\w+):(\w*)$/) {
7240: my $sec = $coursecode.$1;
7241: my $lc_sec = $2;
7242: unless (grep/^$sec$/,@{$allcourses}) {
7243: push @{$allcourses},$sec;
7244: $$LC_code{$sec} = $lc_sec;
7245: }
7246: }
7247: }
7248: }
7249: return;
7250: }
7251:
1.112 bowersj2 7252: =pod
7253:
1.692.4.2 raeburn 7254: =head1 Slot Helpers
7255:
7256: =over 4
7257:
7258: =item * sorted_slots()
7259:
7260: Sorts an array of slot names in order of slot start time (earliest first).
7261:
7262: Inputs:
7263:
7264: =over 4
7265:
7266: slotsarr - Reference to array of unsorted slot names.
7267:
7268: slots - Reference to hash of hash, where outer hash keys are slot names.
7269:
7270: =back
7271:
7272: Returns:
7273:
7274: =over 4
7275:
7276: sorted - An array of slot names sorted by the start time of the slot.
7277:
7278: =back
7279:
7280: =back
7281:
7282: =cut
7283:
7284:
7285: sub sorted_slots {
7286: my ($slotsarr,$slots) = @_;
7287: my @sorted;
7288: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
7289: @sorted =
7290: sort {
7291: if (ref($slots->{$a}) && ref($slots->{$b})) {
7292: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
7293: }
7294: if (ref($slots->{$a})) { return -1;}
7295: if (ref($slots->{$b})) { return 1;}
7296: return 0;
7297: } @{$slotsarr};
7298: }
7299: return @sorted;
7300: }
7301:
7302: =pod
7303:
1.549 albertel 7304: =back
7305:
7306: =head1 HTTP Helpers
7307:
7308: =over 4
7309:
1.648 raeburn 7310: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7311:
1.258 albertel 7312: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7313: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7314: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7315:
7316: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7317: $possible_names is an ref to an array of form element names. As an example:
7318: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7319: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7320:
7321: =cut
1.1 albertel 7322:
1.6 albertel 7323: sub get_unprocessed_cgi {
1.25 albertel 7324: my ($query,$possible_names)= @_;
1.26 matthew 7325: # $Apache::lonxml::debug=1;
1.356 albertel 7326: foreach my $pair (split(/&/,$query)) {
7327: my ($name, $value) = split(/=/,$pair);
1.369 www 7328: $name = &unescape($name);
1.25 albertel 7329: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7330: $value =~ tr/+/ /;
7331: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7332: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7333: }
1.16 harris41 7334: }
1.6 albertel 7335: }
7336:
1.112 bowersj2 7337: =pod
7338:
1.648 raeburn 7339: =item * &cacheheader()
1.112 bowersj2 7340:
7341: returns cache-controlling header code
7342:
7343: =cut
7344:
1.7 albertel 7345: sub cacheheader {
1.258 albertel 7346: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7347: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7348: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7349: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7350: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7351: return $output;
1.7 albertel 7352: }
7353:
1.112 bowersj2 7354: =pod
7355:
1.648 raeburn 7356: =item * &no_cache($r)
1.112 bowersj2 7357:
7358: specifies header code to not have cache
7359:
7360: =cut
7361:
1.9 albertel 7362: sub no_cache {
1.216 albertel 7363: my ($r) = @_;
7364: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7365: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7366: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7367: $r->no_cache(1);
7368: $r->header_out("Expires" => $date);
7369: $r->header_out("Pragma" => "no-cache");
1.123 www 7370: }
7371:
7372: sub content_type {
1.181 albertel 7373: my ($r,$type,$charset) = @_;
1.299 foxr 7374: if ($r) {
7375: # Note that printout.pl calls this with undef for $r.
7376: &no_cache($r);
7377: }
1.258 albertel 7378: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7379: unless ($charset) {
7380: $charset=&Apache::lonlocal::current_encoding;
7381: }
7382: if ($charset) { $type.='; charset='.$charset; }
7383: if ($r) {
7384: $r->content_type($type);
7385: } else {
7386: print("Content-type: $type\n\n");
7387: }
1.9 albertel 7388: }
1.25 albertel 7389:
1.112 bowersj2 7390: =pod
7391:
1.648 raeburn 7392: =item * &add_to_env($name,$value)
1.112 bowersj2 7393:
1.258 albertel 7394: adds $name to the %env hash with value
1.112 bowersj2 7395: $value, if $name already exists, the entry is converted to an array
7396: reference and $value is added to the array.
7397:
7398: =cut
7399:
1.25 albertel 7400: sub add_to_env {
7401: my ($name,$value)=@_;
1.258 albertel 7402: if (defined($env{$name})) {
7403: if (ref($env{$name})) {
1.25 albertel 7404: #already have multiple values
1.258 albertel 7405: push(@{ $env{$name} },$value);
1.25 albertel 7406: } else {
7407: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7408: my $first=$env{$name};
7409: undef($env{$name});
7410: push(@{ $env{$name} },$first,$value);
1.25 albertel 7411: }
7412: } else {
1.258 albertel 7413: $env{$name}=$value;
1.25 albertel 7414: }
1.31 albertel 7415: }
1.149 albertel 7416:
7417: =pod
7418:
1.648 raeburn 7419: =item * &get_env_multiple($name)
1.149 albertel 7420:
1.258 albertel 7421: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7422: values may be defined and end up as an array ref.
7423:
7424: returns an array of values
7425:
7426: =cut
7427:
7428: sub get_env_multiple {
7429: my ($name) = @_;
7430: my @values;
1.258 albertel 7431: if (defined($env{$name})) {
1.149 albertel 7432: # exists is it an array
1.258 albertel 7433: if (ref($env{$name})) {
7434: @values=@{ $env{$name} };
1.149 albertel 7435: } else {
1.258 albertel 7436: $values[0]=$env{$name};
1.149 albertel 7437: }
7438: }
7439: return(@values);
7440: }
7441:
1.660 raeburn 7442: sub ask_for_embedded_content {
7443: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7444: my $upload_output = '
7445: <form name="upload_embedded" action="'.$actionurl.'"
7446: method="post" enctype="multipart/form-data">';
7447: $upload_output .= $state;
1.661 raeburn 7448: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7449:
7450: my $num = 0;
7451: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7452: $upload_output .= &start_data_table_row().
7453: '<td>'.$embed_file.'</td><td>';
7454: if ($args->{'ignore_remote_references'}
7455: && $embed_file =~ m{^\w+://}) {
7456: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7457: } elsif ($args->{'error_on_invalid_names'}
7458: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7459:
7460: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7461:
7462: } else {
7463: $upload_output .='
1.661 raeburn 7464: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7465: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7466: my $attrib = join(':',@{$$allfiles{$embed_file}});
7467: $upload_output .=
7468: "\n\t\t".
7469: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7470: $attrib.'" />';
7471: if (exists($$codebase{$embed_file})) {
7472: $upload_output .=
7473: "\n\t\t".
7474: '<input name="codebase_'.$num.'" type="hidden" value="'.
7475: &escape($$codebase{$embed_file}).'" />';
7476: }
7477: }
7478: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7479: $num++;
7480: }
7481: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7482: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7483: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7484: '.&mt('(only files for which a location has been provided will be uploaded)').'
7485: </form>';
7486: return $upload_output;
7487: }
7488:
1.661 raeburn 7489: sub upload_embedded {
7490: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7491: $current_disk_usage) = @_;
7492: my $output;
7493: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7494: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7495: my $orig_uploaded_filename =
7496: $env{'form.embedded_item_'.$i.'.filename'};
7497:
7498: $env{'form.embedded_orig_'.$i} =
7499: &unescape($env{'form.embedded_orig_'.$i});
7500: my ($path,$fname) =
7501: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7502: # no path, whole string is fname
7503: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7504:
7505: $path = $env{'form.currentpath'}.$path;
7506: $fname = &Apache::lonnet::clean_filename($fname);
7507: # See if there is anything left
7508: next if ($fname eq '');
7509:
7510: # Check if file already exists as a file or directory.
7511: my ($state,$msg);
7512: if ($context eq 'portfolio') {
7513: my $port_path = $dirpath;
7514: if ($group ne '') {
7515: $port_path = "groups/$group/$port_path";
7516: }
7517: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7518: $dir_root,$port_path,$disk_quota,
7519: $current_disk_usage,$uname,$udom);
7520: if ($state eq 'will_exceed_quota'
7521: || $state eq 'file_locked'
7522: || $state eq 'file_exists' ) {
7523: $output .= $msg;
7524: next;
7525: }
7526: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7527: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7528: if ($state eq 'exists') {
7529: $output .= $msg;
7530: next;
7531: }
7532: }
7533: # Check if extension is valid
7534: if (($fname =~ /\.(\w+)$/) &&
7535: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7536: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7537: next;
7538: } elsif (($fname =~ /\.(\w+)$/) &&
7539: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7540: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7541: next;
7542: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7543: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7544: next;
7545: }
7546:
7547: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7548: if ($context eq 'portfolio') {
7549: my $result=
7550: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7551: $dirpath.$path);
7552: if ($result !~ m|^/uploaded/|) {
7553: $output .= '<span class="LC_error">'
7554: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7555: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7556: .'</span><br />';
7557: next;
7558: } else {
7559: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7560: $path.$fname.'</span>').'</p>';
7561: }
7562: } else {
7563: # Save the file
7564: my $target = $env{'form.embedded_item_'.$i};
7565: my $fullpath = $dir_root.$dirpath.'/'.$path;
7566: my $dest = $fullpath.$fname;
7567: my $url = $url_root.$dirpath.'/'.$path.$fname;
7568: my @parts=split(/\//,$fullpath);
7569: my $count;
7570: my $filepath = $dir_root;
7571: for ($count=4;$count<=$#parts;$count++) {
7572: $filepath .= "/$parts[$count]";
7573: if ((-e $filepath)!=1) {
7574: mkdir($filepath,0770);
7575: }
7576: }
7577: my $fh;
7578: if (!open($fh,'>'.$dest)) {
7579: &Apache::lonnet::logthis('Failed to create '.$dest);
7580: $output .= '<span class="LC_error">'.
7581: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7582: '</span><br />';
7583: } else {
7584: if (!print $fh $env{'form.embedded_item_'.$i}) {
7585: &Apache::lonnet::logthis('Failed to write to '.$dest);
7586: $output .= '<span class="LC_error">'.
7587: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7588: '</span><br />';
7589: } else {
7590: if ($context eq 'testbank') {
7591: $output .= &mt('Embedded file uploaded successfully:').
7592: ' <a href="'.$url.'">'.
7593: $orig_uploaded_filename.'</a><br />';
7594: } else {
7595: $output .= '<font size="+2">'.
7596: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7597: $orig_uploaded_filename.'</a>').'</font><br />';
7598: }
7599: }
7600: close($fh);
7601: }
7602: }
7603: }
7604: return $output;
7605: }
7606:
7607: sub check_for_existing {
7608: my ($path,$fname,$element) = @_;
7609: my ($state,$msg);
7610: if (-d $path.'/'.$fname) {
7611: $state = 'exists';
7612: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7613: } elsif (-e $path.'/'.$fname) {
7614: $state = 'exists';
7615: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7616: }
7617: if ($state eq 'exists') {
7618: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7619: }
7620: return ($state,$msg);
7621: }
7622:
7623: sub check_for_upload {
7624: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7625: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7626: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7627: my $getpropath = 1;
7628: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7629: $getpropath);
7630: my $found_file = 0;
7631: my $locked_file = 0;
7632: foreach my $line (@dir_list) {
7633: my ($file_name)=split(/\&/,$line,2);
7634: if ($file_name eq $fname){
7635: $file_name = $path.$file_name;
7636: if ($group ne '') {
7637: $file_name = $group.$file_name;
7638: }
7639: $found_file = 1;
7640: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7641: $locked_file = 1;
7642: }
7643: }
7644: }
7645: if (($current_disk_usage + $filesize) > $disk_quota){
7646: my $msg = '<span class="LC_error">'.
7647: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7648: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7649: return ('will_exceed_quota',$msg);
7650: } elsif ($found_file) {
7651: if ($locked_file) {
7652: my $msg = '<span class="LC_error">';
7653: $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>');
7654: $msg .= '</span><br />';
7655: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7656: return ('file_locked',$msg);
7657: } else {
7658: my $msg = '<span class="LC_error">';
7659: $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'});
7660: $msg .= '</span>';
7661: $msg .= '<br />';
7662: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7663: return ('file_exists',$msg);
7664: }
7665: }
7666: }
7667:
1.31 albertel 7668:
1.41 ng 7669: =pod
1.45 matthew 7670:
1.464 albertel 7671: =back
1.41 ng 7672:
1.112 bowersj2 7673: =head1 CSV Upload/Handling functions
1.38 albertel 7674:
1.41 ng 7675: =over 4
7676:
1.648 raeburn 7677: =item * &upfile_store($r)
1.41 ng 7678:
7679: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7680: needs $env{'form.upfile'}
1.41 ng 7681: returns $datatoken to be put into hidden field
7682:
7683: =cut
1.31 albertel 7684:
7685: sub upfile_store {
7686: my $r=shift;
1.258 albertel 7687: $env{'form.upfile'}=~s/\r/\n/gs;
7688: $env{'form.upfile'}=~s/\f/\n/gs;
7689: $env{'form.upfile'}=~s/\n+/\n/gs;
7690: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7691:
1.258 albertel 7692: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7693: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7694: {
1.158 raeburn 7695: my $datafile = $r->dir_config('lonDaemons').
7696: '/tmp/'.$datatoken.'.tmp';
7697: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7698: print $fh $env{'form.upfile'};
1.158 raeburn 7699: close($fh);
7700: }
1.31 albertel 7701: }
7702: return $datatoken;
7703: }
7704:
1.56 matthew 7705: =pod
7706:
1.648 raeburn 7707: =item * &load_tmp_file($r)
1.41 ng 7708:
7709: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7710: needs $env{'form.datatoken'},
7711: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7712:
7713: =cut
1.31 albertel 7714:
7715: sub load_tmp_file {
7716: my $r=shift;
7717: my @studentdata=();
7718: {
1.158 raeburn 7719: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7720: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7721: if ( open(my $fh,"<$studentfile") ) {
7722: @studentdata=<$fh>;
7723: close($fh);
7724: }
1.31 albertel 7725: }
1.258 albertel 7726: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7727: }
7728:
1.56 matthew 7729: =pod
7730:
1.648 raeburn 7731: =item * &upfile_record_sep()
1.41 ng 7732:
7733: Separate uploaded file into records
7734: returns array of records,
1.258 albertel 7735: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7736:
7737: =cut
1.31 albertel 7738:
7739: sub upfile_record_sep {
1.258 albertel 7740: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7741: } else {
1.248 albertel 7742: my @records;
1.258 albertel 7743: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7744: if ($line=~/^\s*$/) { next; }
7745: push(@records,$line);
7746: }
7747: return @records;
1.31 albertel 7748: }
7749: }
7750:
1.56 matthew 7751: =pod
7752:
1.648 raeburn 7753: =item * &record_sep($record)
1.41 ng 7754:
1.258 albertel 7755: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7756:
7757: =cut
7758:
1.263 www 7759: sub takeleft {
7760: my $index=shift;
7761: return substr('0000'.$index,-4,4);
7762: }
7763:
1.31 albertel 7764: sub record_sep {
7765: my $record=shift;
7766: my %components=();
1.258 albertel 7767: if ($env{'form.upfiletype'} eq 'xml') {
7768: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7769: my $i=0;
1.356 albertel 7770: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7771: $field=~s/^(\"|\')//;
7772: $field=~s/(\"|\')$//;
1.263 www 7773: $components{&takeleft($i)}=$field;
1.31 albertel 7774: $i++;
7775: }
1.258 albertel 7776: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7777: my $i=0;
1.356 albertel 7778: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7779: $field=~s/^(\"|\')//;
7780: $field=~s/(\"|\')$//;
1.263 www 7781: $components{&takeleft($i)}=$field;
1.31 albertel 7782: $i++;
7783: }
7784: } else {
1.561 www 7785: my $separator=',';
1.480 banghart 7786: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7787: $separator=';';
1.480 banghart 7788: }
1.31 albertel 7789: my $i=0;
1.561 www 7790: # the character we are looking for to indicate the end of a quote or a record
7791: my $looking_for=$separator;
7792: # do not add the characters to the fields
7793: my $ignore=0;
7794: # we just encountered a separator (or the beginning of the record)
7795: my $just_found_separator=1;
7796: # store the field we are working on here
7797: my $field='';
7798: # work our way through all characters in record
7799: foreach my $character ($record=~/(.)/g) {
7800: if ($character eq $looking_for) {
7801: if ($character ne $separator) {
7802: # Found the end of a quote, again looking for separator
7803: $looking_for=$separator;
7804: $ignore=1;
7805: } else {
7806: # Found a separator, store away what we got
7807: $components{&takeleft($i)}=$field;
7808: $i++;
7809: $just_found_separator=1;
7810: $ignore=0;
7811: $field='';
7812: }
7813: next;
7814: }
7815: # single or double quotation marks after a separator indicate beginning of a quote
7816: # we are now looking for the end of the quote and need to ignore separators
7817: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7818: $looking_for=$character;
7819: next;
7820: }
7821: # ignore would be true after we reached the end of a quote
7822: if ($ignore) { next; }
7823: if (($just_found_separator) && ($character=~/\s/)) { next; }
7824: $field.=$character;
7825: $just_found_separator=0;
1.31 albertel 7826: }
1.561 www 7827: # catch the very last entry, since we never encountered the separator
7828: $components{&takeleft($i)}=$field;
1.31 albertel 7829: }
7830: return %components;
7831: }
7832:
1.144 matthew 7833: ######################################################
7834: ######################################################
7835:
1.56 matthew 7836: =pod
7837:
1.648 raeburn 7838: =item * &upfile_select_html()
1.41 ng 7839:
1.144 matthew 7840: Return HTML code to select a file from the users machine and specify
7841: the file type.
1.41 ng 7842:
7843: =cut
7844:
1.144 matthew 7845: ######################################################
7846: ######################################################
1.31 albertel 7847: sub upfile_select_html {
1.144 matthew 7848: my %Types = (
7849: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7850: semisv => &mt('Semicolon separated values'),
1.144 matthew 7851: space => &mt('Space separated'),
7852: tab => &mt('Tabulator separated'),
7853: # xml => &mt('HTML/XML'),
7854: );
7855: my $Str = '<input type="file" name="upfile" size="50" />'.
1.692.4.2 raeburn 7856: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 7857: foreach my $type (sort(keys(%Types))) {
7858: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7859: }
7860: $Str .= "</select>\n";
7861: return $Str;
1.31 albertel 7862: }
7863:
1.301 albertel 7864: sub get_samples {
7865: my ($records,$toget) = @_;
7866: my @samples=({});
7867: my $got=0;
7868: foreach my $rec (@$records) {
7869: my %temp = &record_sep($rec);
7870: if (! grep(/\S/, values(%temp))) { next; }
7871: if (%temp) {
7872: $samples[$got]=\%temp;
7873: $got++;
7874: if ($got == $toget) { last; }
7875: }
7876: }
7877: return \@samples;
7878: }
7879:
1.144 matthew 7880: ######################################################
7881: ######################################################
7882:
1.56 matthew 7883: =pod
7884:
1.648 raeburn 7885: =item * &csv_print_samples($r,$records)
1.41 ng 7886:
7887: Prints a table of sample values from each column uploaded $r is an
7888: Apache Request ref, $records is an arrayref from
7889: &Apache::loncommon::upfile_record_sep
7890:
7891: =cut
7892:
1.144 matthew 7893: ######################################################
7894: ######################################################
1.31 albertel 7895: sub csv_print_samples {
7896: my ($r,$records) = @_;
1.662 bisitz 7897: my $samples = &get_samples($records,5);
1.301 albertel 7898:
1.594 raeburn 7899: $r->print(&mt('Samples').'<br />'.&start_data_table().
7900: &start_data_table_header_row());
1.356 albertel 7901: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7902: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 7903: $r->print(&end_data_table_header_row());
1.301 albertel 7904: foreach my $hash (@$samples) {
1.594 raeburn 7905: $r->print(&start_data_table_row());
1.356 albertel 7906: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7907: $r->print('<td>');
1.356 albertel 7908: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 7909: $r->print('</td>');
7910: }
1.594 raeburn 7911: $r->print(&end_data_table_row());
1.31 albertel 7912: }
1.594 raeburn 7913: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 7914: }
7915:
1.144 matthew 7916: ######################################################
7917: ######################################################
7918:
1.56 matthew 7919: =pod
7920:
1.648 raeburn 7921: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 7922:
7923: Prints a table to create associations between values and table columns.
1.144 matthew 7924:
1.41 ng 7925: $r is an Apache Request ref,
7926: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7927: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7928:
7929: =cut
7930:
1.144 matthew 7931: ######################################################
7932: ######################################################
1.31 albertel 7933: sub csv_print_select_table {
7934: my ($r,$records,$d) = @_;
1.301 albertel 7935: my $i=0;
7936: my $samples = &get_samples($records,1);
1.144 matthew 7937: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7938: &start_data_table().&start_data_table_header_row().
1.144 matthew 7939: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7940: '<th>'.&mt('Column').'</th>'.
7941: &end_data_table_header_row()."\n");
1.356 albertel 7942: foreach my $array_ref (@$d) {
7943: my ($value,$display,$defaultcol)=@{ $array_ref };
1.689 bisitz 7944: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 7945:
7946: $r->print('<td><select name=f'.$i.
1.32 matthew 7947: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7948: $r->print('<option value="none"></option>');
1.356 albertel 7949: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7950: $r->print('<option value="'.$sample.'"'.
7951: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 7952: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 7953: }
1.594 raeburn 7954: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7955: $i++;
7956: }
1.594 raeburn 7957: $r->print(&end_data_table());
1.31 albertel 7958: $i--;
7959: return $i;
7960: }
1.56 matthew 7961:
1.144 matthew 7962: ######################################################
7963: ######################################################
7964:
1.56 matthew 7965: =pod
1.31 albertel 7966:
1.648 raeburn 7967: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 7968:
7969: Prints a table of sample values from the upload and can make associate samples to internal names.
7970:
7971: $r is an Apache Request ref,
7972: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7973: $d is an array of 2 element arrays (internal name, displayed name)
7974:
7975: =cut
7976:
1.144 matthew 7977: ######################################################
7978: ######################################################
1.31 albertel 7979: sub csv_samples_select_table {
7980: my ($r,$records,$d) = @_;
7981: my $i=0;
1.144 matthew 7982: #
1.662 bisitz 7983: my $max_samples = 5;
7984: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 7985: $r->print(&start_data_table().
7986: &start_data_table_header_row().'<th>'.
7987: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7988: &end_data_table_header_row());
1.301 albertel 7989:
7990: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7991: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7992: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7993: foreach my $option (@$d) {
7994: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7995: $r->print('<option value="'.$value.'"'.
1.253 albertel 7996: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7997: $display.'</option>');
1.31 albertel 7998: }
7999: $r->print('</select></td><td>');
1.662 bisitz 8000: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8001: if (defined($samples->[$line]{$key})) {
8002: $r->print($samples->[$line]{$key}."<br />\n");
8003: }
8004: }
1.594 raeburn 8005: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8006: $i++;
8007: }
1.594 raeburn 8008: $r->print(&end_data_table());
1.31 albertel 8009: $i--;
8010: return($i);
1.115 matthew 8011: }
8012:
1.144 matthew 8013: ######################################################
8014: ######################################################
8015:
1.115 matthew 8016: =pod
8017:
1.648 raeburn 8018: =item * &clean_excel_name($name)
1.115 matthew 8019:
8020: Returns a replacement for $name which does not contain any illegal characters.
8021:
8022: =cut
8023:
1.144 matthew 8024: ######################################################
8025: ######################################################
1.115 matthew 8026: sub clean_excel_name {
8027: my ($name) = @_;
8028: $name =~ s/[:\*\?\/\\]//g;
8029: if (length($name) > 31) {
8030: $name = substr($name,0,31);
8031: }
8032: return $name;
1.25 albertel 8033: }
1.84 albertel 8034:
1.85 albertel 8035: =pod
8036:
1.648 raeburn 8037: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8038:
8039: Returns either 1 or undef
8040:
8041: 1 if the part is to be hidden, undef if it is to be shown
8042:
8043: Arguments are:
8044:
8045: $id the id of the part to be checked
8046: $symb, optional the symb of the resource to check
8047: $udom, optional the domain of the user to check for
8048: $uname, optional the username of the user to check for
8049:
8050: =cut
1.84 albertel 8051:
8052: sub check_if_partid_hidden {
8053: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8054: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8055: $symb,$udom,$uname);
1.141 albertel 8056: my $truth=1;
8057: #if the string starts with !, then the list is the list to show not hide
8058: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8059: my @hiddenlist=split(/,/,$hiddenparts);
8060: foreach my $checkid (@hiddenlist) {
1.141 albertel 8061: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8062: }
1.141 albertel 8063: return !$truth;
1.84 albertel 8064: }
1.127 matthew 8065:
1.138 matthew 8066:
8067: ############################################################
8068: ############################################################
8069:
8070: =pod
8071:
1.157 matthew 8072: =back
8073:
1.138 matthew 8074: =head1 cgi-bin script and graphing routines
8075:
1.157 matthew 8076: =over 4
8077:
1.648 raeburn 8078: =item * &get_cgi_id()
1.138 matthew 8079:
8080: Inputs: none
8081:
8082: Returns an id which can be used to pass environment variables
8083: to various cgi-bin scripts. These environment variables will
8084: be removed from the users environment after a given time by
8085: the routine &Apache::lonnet::transfer_profile_to_env.
8086:
8087: =cut
8088:
8089: ############################################################
8090: ############################################################
1.152 albertel 8091: my $uniq=0;
1.136 matthew 8092: sub get_cgi_id {
1.154 albertel 8093: $uniq=($uniq+1)%100000;
1.280 albertel 8094: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8095: }
8096:
1.127 matthew 8097: ############################################################
8098: ############################################################
8099:
8100: =pod
8101:
1.648 raeburn 8102: =item * &DrawBarGraph()
1.127 matthew 8103:
1.138 matthew 8104: Facilitates the plotting of data in a (stacked) bar graph.
8105: Puts plot definition data into the users environment in order for
8106: graph.png to plot it. Returns an <img> tag for the plot.
8107: The bars on the plot are labeled '1','2',...,'n'.
8108:
8109: Inputs:
8110:
8111: =over 4
8112:
8113: =item $Title: string, the title of the plot
8114:
8115: =item $xlabel: string, text describing the X-axis of the plot
8116:
8117: =item $ylabel: string, text describing the Y-axis of the plot
8118:
8119: =item $Max: scalar, the maximum Y value to use in the plot
8120: If $Max is < any data point, the graph will not be rendered.
8121:
1.140 matthew 8122: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8123: they are plotted. If undefined, default values will be used.
8124:
1.178 matthew 8125: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8126:
1.138 matthew 8127: =item @Values: An array of array references. Each array reference holds data
8128: to be plotted in a stacked bar chart.
8129:
1.239 matthew 8130: =item If the final element of @Values is a hash reference the key/value
8131: pairs will be added to the graph definition.
8132:
1.138 matthew 8133: =back
8134:
8135: Returns:
8136:
8137: An <img> tag which references graph.png and the appropriate identifying
8138: information for the plot.
8139:
1.127 matthew 8140: =cut
8141:
8142: ############################################################
8143: ############################################################
1.134 matthew 8144: sub DrawBarGraph {
1.178 matthew 8145: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8146: #
8147: if (! defined($colors)) {
8148: $colors = ['#33ff00',
8149: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8150: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8151: ];
8152: }
1.228 matthew 8153: my $extra_settings = {};
8154: if (ref($Values[-1]) eq 'HASH') {
8155: $extra_settings = pop(@Values);
8156: }
1.127 matthew 8157: #
1.136 matthew 8158: my $identifier = &get_cgi_id();
8159: my $id = 'cgi.'.$identifier;
1.129 matthew 8160: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8161: return '';
8162: }
1.225 matthew 8163: #
8164: my @Labels;
8165: if (defined($labels)) {
8166: @Labels = @$labels;
8167: } else {
8168: for (my $i=0;$i<@{$Values[0]};$i++) {
8169: push (@Labels,$i+1);
8170: }
8171: }
8172: #
1.129 matthew 8173: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8174: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8175: my %ValuesHash;
8176: my $NumSets=1;
8177: foreach my $array (@Values) {
8178: next if (! ref($array));
1.136 matthew 8179: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8180: join(',',@$array);
1.129 matthew 8181: }
1.127 matthew 8182: #
1.136 matthew 8183: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8184: if ($NumBars < 3) {
8185: $width = 120+$NumBars*32;
1.220 matthew 8186: $xskip = 1;
1.225 matthew 8187: $bar_width = 30;
8188: } elsif ($NumBars < 5) {
8189: $width = 120+$NumBars*20;
8190: $xskip = 1;
8191: $bar_width = 20;
1.220 matthew 8192: } elsif ($NumBars < 10) {
1.136 matthew 8193: $width = 120+$NumBars*15;
8194: $xskip = 1;
8195: $bar_width = 15;
8196: } elsif ($NumBars <= 25) {
8197: $width = 120+$NumBars*11;
8198: $xskip = 5;
8199: $bar_width = 8;
8200: } elsif ($NumBars <= 50) {
8201: $width = 120+$NumBars*8;
8202: $xskip = 5;
8203: $bar_width = 4;
8204: } else {
8205: $width = 120+$NumBars*8;
8206: $xskip = 5;
8207: $bar_width = 4;
8208: }
8209: #
1.137 matthew 8210: $Max = 1 if ($Max < 1);
8211: if ( int($Max) < $Max ) {
8212: $Max++;
8213: $Max = int($Max);
8214: }
1.127 matthew 8215: $Title = '' if (! defined($Title));
8216: $xlabel = '' if (! defined($xlabel));
8217: $ylabel = '' if (! defined($ylabel));
1.369 www 8218: $ValuesHash{$id.'.title'} = &escape($Title);
8219: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8220: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8221: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8222: $ValuesHash{$id.'.NumBars'} = $NumBars;
8223: $ValuesHash{$id.'.NumSets'} = $NumSets;
8224: $ValuesHash{$id.'.PlotType'} = 'bar';
8225: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8226: $ValuesHash{$id.'.height'} = $height;
8227: $ValuesHash{$id.'.width'} = $width;
8228: $ValuesHash{$id.'.xskip'} = $xskip;
8229: $ValuesHash{$id.'.bar_width'} = $bar_width;
8230: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8231: #
1.228 matthew 8232: # Deal with other parameters
8233: while (my ($key,$value) = each(%$extra_settings)) {
8234: $ValuesHash{$id.'.'.$key} = $value;
8235: }
8236: #
1.646 raeburn 8237: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8238: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8239: }
8240:
8241: ############################################################
8242: ############################################################
8243:
8244: =pod
8245:
1.648 raeburn 8246: =item * &DrawXYGraph()
1.137 matthew 8247:
1.138 matthew 8248: Facilitates the plotting of data in an XY graph.
8249: Puts plot definition data into the users environment in order for
8250: graph.png to plot it. Returns an <img> tag for the plot.
8251:
8252: Inputs:
8253:
8254: =over 4
8255:
8256: =item $Title: string, the title of the plot
8257:
8258: =item $xlabel: string, text describing the X-axis of the plot
8259:
8260: =item $ylabel: string, text describing the Y-axis of the plot
8261:
8262: =item $Max: scalar, the maximum Y value to use in the plot
8263: If $Max is < any data point, the graph will not be rendered.
8264:
8265: =item $colors: Array ref containing the hex color codes for the data to be
8266: plotted in. If undefined, default values will be used.
8267:
8268: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8269:
8270: =item $Ydata: Array ref containing Array refs.
1.185 www 8271: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8272:
8273: =item %Values: hash indicating or overriding any default values which are
8274: passed to graph.png.
8275: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8276:
8277: =back
8278:
8279: Returns:
8280:
8281: An <img> tag which references graph.png and the appropriate identifying
8282: information for the plot.
8283:
1.137 matthew 8284: =cut
8285:
8286: ############################################################
8287: ############################################################
8288: sub DrawXYGraph {
8289: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8290: #
8291: # Create the identifier for the graph
8292: my $identifier = &get_cgi_id();
8293: my $id = 'cgi.'.$identifier;
8294: #
8295: $Title = '' if (! defined($Title));
8296: $xlabel = '' if (! defined($xlabel));
8297: $ylabel = '' if (! defined($ylabel));
8298: my %ValuesHash =
8299: (
1.369 www 8300: $id.'.title' => &escape($Title),
8301: $id.'.xlabel' => &escape($xlabel),
8302: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8303: $id.'.y_max_value'=> $Max,
8304: $id.'.labels' => join(',',@$Xlabels),
8305: $id.'.PlotType' => 'XY',
8306: );
8307: #
8308: if (defined($colors) && ref($colors) eq 'ARRAY') {
8309: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8310: }
8311: #
8312: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8313: return '';
8314: }
8315: my $NumSets=1;
1.138 matthew 8316: foreach my $array (@{$Ydata}){
1.137 matthew 8317: next if (! ref($array));
8318: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8319: }
1.138 matthew 8320: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8321: #
8322: # Deal with other parameters
8323: while (my ($key,$value) = each(%Values)) {
8324: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8325: }
8326: #
1.646 raeburn 8327: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8328: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8329: }
8330:
8331: ############################################################
8332: ############################################################
8333:
8334: =pod
8335:
1.648 raeburn 8336: =item * &DrawXYYGraph()
1.138 matthew 8337:
8338: Facilitates the plotting of data in an XY graph with two Y axes.
8339: Puts plot definition data into the users environment in order for
8340: graph.png to plot it. Returns an <img> tag for the plot.
8341:
8342: Inputs:
8343:
8344: =over 4
8345:
8346: =item $Title: string, the title of the plot
8347:
8348: =item $xlabel: string, text describing the X-axis of the plot
8349:
8350: =item $ylabel: string, text describing the Y-axis of the plot
8351:
8352: =item $colors: Array ref containing the hex color codes for the data to be
8353: plotted in. If undefined, default values will be used.
8354:
8355: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8356:
8357: =item $Ydata1: The first data set
8358:
8359: =item $Min1: The minimum value of the left Y-axis
8360:
8361: =item $Max1: The maximum value of the left Y-axis
8362:
8363: =item $Ydata2: The second data set
8364:
8365: =item $Min2: The minimum value of the right Y-axis
8366:
8367: =item $Max2: The maximum value of the left Y-axis
8368:
8369: =item %Values: hash indicating or overriding any default values which are
8370: passed to graph.png.
8371: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8372:
8373: =back
8374:
8375: Returns:
8376:
8377: An <img> tag which references graph.png and the appropriate identifying
8378: information for the plot.
1.136 matthew 8379:
8380: =cut
8381:
8382: ############################################################
8383: ############################################################
1.137 matthew 8384: sub DrawXYYGraph {
8385: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8386: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8387: #
8388: # Create the identifier for the graph
8389: my $identifier = &get_cgi_id();
8390: my $id = 'cgi.'.$identifier;
8391: #
8392: $Title = '' if (! defined($Title));
8393: $xlabel = '' if (! defined($xlabel));
8394: $ylabel = '' if (! defined($ylabel));
8395: my %ValuesHash =
8396: (
1.369 www 8397: $id.'.title' => &escape($Title),
8398: $id.'.xlabel' => &escape($xlabel),
8399: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8400: $id.'.labels' => join(',',@$Xlabels),
8401: $id.'.PlotType' => 'XY',
8402: $id.'.NumSets' => 2,
1.137 matthew 8403: $id.'.two_axes' => 1,
8404: $id.'.y1_max_value' => $Max1,
8405: $id.'.y1_min_value' => $Min1,
8406: $id.'.y2_max_value' => $Max2,
8407: $id.'.y2_min_value' => $Min2,
1.136 matthew 8408: );
8409: #
1.137 matthew 8410: if (defined($colors) && ref($colors) eq 'ARRAY') {
8411: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8412: }
8413: #
8414: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8415: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8416: return '';
8417: }
8418: my $NumSets=1;
1.137 matthew 8419: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8420: next if (! ref($array));
8421: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8422: }
8423: #
8424: # Deal with other parameters
8425: while (my ($key,$value) = each(%Values)) {
8426: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8427: }
8428: #
1.646 raeburn 8429: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8430: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8431: }
8432:
8433: ############################################################
8434: ############################################################
8435:
8436: =pod
8437:
1.157 matthew 8438: =back
8439:
1.139 matthew 8440: =head1 Statistics helper routines?
8441:
8442: Bad place for them but what the hell.
8443:
1.157 matthew 8444: =over 4
8445:
1.648 raeburn 8446: =item * &chartlink()
1.139 matthew 8447:
8448: Returns a link to the chart for a specific student.
8449:
8450: Inputs:
8451:
8452: =over 4
8453:
8454: =item $linktext: The text of the link
8455:
8456: =item $sname: The students username
8457:
8458: =item $sdomain: The students domain
8459:
8460: =back
8461:
1.157 matthew 8462: =back
8463:
1.139 matthew 8464: =cut
8465:
8466: ############################################################
8467: ############################################################
8468: sub chartlink {
8469: my ($linktext, $sname, $sdomain) = @_;
8470: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8471: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8472: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8473: '">'.$linktext.'</a>';
1.153 matthew 8474: }
8475:
8476: #######################################################
8477: #######################################################
8478:
8479: =pod
8480:
8481: =head1 Course Environment Routines
1.157 matthew 8482:
8483: =over 4
1.153 matthew 8484:
1.648 raeburn 8485: =item * &restore_course_settings()
1.153 matthew 8486:
1.648 raeburn 8487: =item * &store_course_settings()
1.153 matthew 8488:
8489: Restores/Store indicated form parameters from the course environment.
8490: Will not overwrite existing values of the form parameters.
8491:
8492: Inputs:
8493: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8494:
8495: a hash ref describing the data to be stored. For example:
8496:
8497: %Save_Parameters = ('Status' => 'scalar',
8498: 'chartoutputmode' => 'scalar',
8499: 'chartoutputdata' => 'scalar',
8500: 'Section' => 'array',
1.373 raeburn 8501: 'Group' => 'array',
1.153 matthew 8502: 'StudentData' => 'array',
8503: 'Maps' => 'array');
8504:
8505: Returns: both routines return nothing
8506:
1.631 raeburn 8507: =back
8508:
1.153 matthew 8509: =cut
8510:
8511: #######################################################
8512: #######################################################
8513: sub store_course_settings {
1.496 albertel 8514: return &store_settings($env{'request.course.id'},@_);
8515: }
8516:
8517: sub store_settings {
1.153 matthew 8518: # save to the environment
8519: # appenv the same items, just to be safe
1.300 albertel 8520: my $udom = $env{'user.domain'};
8521: my $uname = $env{'user.name'};
1.496 albertel 8522: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8523: my %SaveHash;
8524: my %AppHash;
8525: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8526: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8527: my $envname = 'environment.'.$basename;
1.258 albertel 8528: if (exists($env{'form.'.$setting})) {
1.153 matthew 8529: # Save this value away
8530: if ($type eq 'scalar' &&
1.258 albertel 8531: (! exists($env{$envname}) ||
8532: $env{$envname} ne $env{'form.'.$setting})) {
8533: $SaveHash{$basename} = $env{'form.'.$setting};
8534: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8535: } elsif ($type eq 'array') {
8536: my $stored_form;
1.258 albertel 8537: if (ref($env{'form.'.$setting})) {
1.153 matthew 8538: $stored_form = join(',',
8539: map {
1.369 www 8540: &escape($_);
1.258 albertel 8541: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8542: } else {
8543: $stored_form =
1.369 www 8544: &escape($env{'form.'.$setting});
1.153 matthew 8545: }
8546: # Determine if the array contents are the same.
1.258 albertel 8547: if ($stored_form ne $env{$envname}) {
1.153 matthew 8548: $SaveHash{$basename} = $stored_form;
8549: $AppHash{$envname} = $stored_form;
8550: }
8551: }
8552: }
8553: }
8554: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8555: $udom,$uname);
1.153 matthew 8556: if ($put_result !~ /^(ok|delayed)/) {
8557: &Apache::lonnet::logthis('unable to save form parameters, '.
8558: 'got error:'.$put_result);
8559: }
8560: # Make sure these settings stick around in this session, too
1.646 raeburn 8561: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8562: return;
8563: }
8564:
8565: sub restore_course_settings {
1.499 albertel 8566: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8567: }
8568:
8569: sub restore_settings {
8570: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8571: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8572: next if (exists($env{'form.'.$setting}));
1.496 albertel 8573: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8574: '.'.$setting;
1.258 albertel 8575: if (exists($env{$envname})) {
1.153 matthew 8576: if ($type eq 'scalar') {
1.258 albertel 8577: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8578: } elsif ($type eq 'array') {
1.258 albertel 8579: $env{'form.'.$setting} = [
1.153 matthew 8580: map {
1.369 www 8581: &unescape($_);
1.258 albertel 8582: } split(',',$env{$envname})
1.153 matthew 8583: ];
8584: }
8585: }
8586: }
1.127 matthew 8587: }
8588:
1.618 raeburn 8589: #######################################################
8590: #######################################################
8591:
8592: =pod
8593:
8594: =head1 Domain E-mail Routines
8595:
8596: =over 4
8597:
1.648 raeburn 8598: =item * &build_recipient_list()
1.618 raeburn 8599:
1.692.4.2 raeburn 8600: Build recipient lists for four types of e-mail:
8601: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
8602: (d) Help requests, generated by
8603: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 8604:
8605: Inputs:
1.619 raeburn 8606: defmail (scalar - email address of default recipient),
1.618 raeburn 8607: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8608: defdom (domain for which to retrieve configuration settings),
8609: origmail (scalar - email address of recipient from loncapa.conf,
8610: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8611:
1.655 raeburn 8612: Returns: comma separated list of addresses to which to send e-mail.
8613:
8614: =back
1.618 raeburn 8615:
8616: =cut
8617:
8618: ############################################################
8619: ############################################################
8620: sub build_recipient_list {
1.619 raeburn 8621: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8622: my @recipients;
8623: my $otheremails;
8624: my %domconfig =
8625: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8626: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.692.4.2 raeburn 8627: if (exists($domconfig{'contacts'}{$mailing})) {
8628: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8629: my @contacts = ('adminemail','supportemail');
8630: foreach my $item (@contacts) {
8631: if ($domconfig{'contacts'}{$mailing}{$item}) {
8632: my $addr = $domconfig{'contacts'}{$item};
8633: if (!grep(/^\Q$addr\E$/,@recipients)) {
8634: push(@recipients,$addr);
8635: }
1.619 raeburn 8636: }
1.692.4.2 raeburn 8637: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 8638: }
8639: }
1.692.4.2 raeburn 8640: } elsif ($origmail ne '') {
8641: push(@recipients,$origmail);
1.618 raeburn 8642: }
1.619 raeburn 8643: } elsif ($origmail ne '') {
8644: push(@recipients,$origmail);
1.618 raeburn 8645: }
1.688 raeburn 8646: if (defined($defmail)) {
8647: if ($defmail ne '') {
8648: push(@recipients,$defmail);
8649: }
1.618 raeburn 8650: }
8651: if ($otheremails) {
1.619 raeburn 8652: my @others;
8653: if ($otheremails =~ /,/) {
8654: @others = split(/,/,$otheremails);
1.618 raeburn 8655: } else {
1.619 raeburn 8656: push(@others,$otheremails);
8657: }
8658: foreach my $addr (@others) {
8659: if (!grep(/^\Q$addr\E$/,@recipients)) {
8660: push(@recipients,$addr);
8661: }
1.618 raeburn 8662: }
8663: }
1.619 raeburn 8664: my $recipientlist = join(',',@recipients);
1.618 raeburn 8665: return $recipientlist;
8666: }
8667:
1.127 matthew 8668: ############################################################
8669: ############################################################
1.154 albertel 8670:
1.655 raeburn 8671: =pod
8672:
8673: =head1 Course Catalog Routines
8674:
8675: =over 4
8676:
8677: =item * &gather_categories()
8678:
8679: Converts category definitions - keys of categories hash stored in
8680: coursecategories in configuration.db on the primary library server in a
8681: domain - to an array. Also generates javascript and idx hash used to
8682: generate Domain Coordinator interface for editing Course Categories.
8683:
8684: Inputs:
1.663 raeburn 8685:
1.655 raeburn 8686: categories (reference to hash of category definitions).
1.663 raeburn 8687:
1.655 raeburn 8688: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8689: categories and subcategories).
1.663 raeburn 8690:
1.655 raeburn 8691: idx (reference to hash of counters used in Domain Coordinator interface for
8692: editing Course Categories).
1.663 raeburn 8693:
1.655 raeburn 8694: jsarray (reference to array of categories used to create Javascript arrays for
8695: Domain Coordinator interface for editing Course Categories).
8696:
8697: Returns: nothing
8698:
8699: Side effects: populates cats, idx and jsarray.
8700:
8701: =cut
8702:
8703: sub gather_categories {
8704: my ($categories,$cats,$idx,$jsarray) = @_;
8705: my %counters;
8706: my $num = 0;
8707: foreach my $item (keys(%{$categories})) {
8708: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8709: if ($container eq '' && $depth == 0) {
8710: $cats->[$depth][$categories->{$item}] = $cat;
8711: } else {
8712: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8713: }
8714: my ($escitem,$tail) = split(/:/,$item,2);
8715: if ($counters{$tail} eq '') {
8716: $counters{$tail} = $num;
8717: $num ++;
8718: }
8719: if (ref($idx) eq 'HASH') {
8720: $idx->{$item} = $counters{$tail};
8721: }
8722: if (ref($jsarray) eq 'ARRAY') {
8723: push(@{$jsarray->[$counters{$tail}]},$item);
8724: }
8725: }
8726: return;
8727: }
8728:
8729: =pod
8730:
8731: =item * &extract_categories()
8732:
8733: Used to generate breadcrumb trails for course categories.
8734:
8735: Inputs:
1.663 raeburn 8736:
1.655 raeburn 8737: categories (reference to hash of category definitions).
1.663 raeburn 8738:
1.655 raeburn 8739: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8740: categories and subcategories).
1.663 raeburn 8741:
1.655 raeburn 8742: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8743:
1.655 raeburn 8744: allitems (reference to hash - key is category key
8745: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8746:
1.655 raeburn 8747: idx (reference to hash of counters used in Domain Coordinator interface for
8748: editing Course Categories).
1.663 raeburn 8749:
1.655 raeburn 8750: jsarray (reference to array of categories used to create Javascript arrays for
8751: Domain Coordinator interface for editing Course Categories).
8752:
1.665 raeburn 8753: subcats (reference to hash of arrays containing all subcategories within each
8754: category, -recursive)
8755:
1.655 raeburn 8756: Returns: nothing
8757:
8758: Side effects: populates trails and allitems hash references.
8759:
8760: =cut
8761:
8762: sub extract_categories {
1.665 raeburn 8763: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8764: if (ref($categories) eq 'HASH') {
8765: &gather_categories($categories,$cats,$idx,$jsarray);
8766: if (ref($cats->[0]) eq 'ARRAY') {
8767: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8768: my $name = $cats->[0][$i];
8769: my $item = &escape($name).'::0';
8770: my $trailstr;
8771: if ($name eq 'instcode') {
8772: $trailstr = &mt('Official courses (with institutional codes)');
8773: } else {
8774: $trailstr = $name;
8775: }
8776: if ($allitems->{$item} eq '') {
8777: push(@{$trails},$trailstr);
8778: $allitems->{$item} = scalar(@{$trails})-1;
8779: }
8780: my @parents = ($name);
8781: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8782: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8783: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8784: if (ref($subcats) eq 'HASH') {
8785: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8786: }
8787: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8788: }
8789: } else {
8790: if (ref($subcats) eq 'HASH') {
8791: $subcats->{$item} = [];
1.655 raeburn 8792: }
8793: }
8794: }
8795: }
8796: }
8797: return;
8798: }
8799:
8800: =pod
8801:
8802: =item *&recurse_categories()
8803:
8804: Recursively used to generate breadcrumb trails for course categories.
8805:
8806: Inputs:
1.663 raeburn 8807:
1.655 raeburn 8808: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8809: categories and subcategories).
1.663 raeburn 8810:
1.655 raeburn 8811: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8812:
8813: category (current course category, for which breadcrumb trail is being generated).
8814:
8815: trails (reference to array of breadcrumb trails for each category).
8816:
1.655 raeburn 8817: allitems (reference to hash - key is category key
8818: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8819:
1.655 raeburn 8820: parents (array containing containers directories for current category,
8821: back to top level).
8822:
8823: Returns: nothing
8824:
8825: Side effects: populates trails and allitems hash references
8826:
8827: =cut
8828:
8829: sub recurse_categories {
1.665 raeburn 8830: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8831: my $shallower = $depth - 1;
8832: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8833: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8834: my $name = $cats->[$depth]{$category}[$k];
8835: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8836: my $trailstr = join(' -> ',(@{$parents},$category));
8837: if ($allitems->{$item} eq '') {
8838: push(@{$trails},$trailstr);
8839: $allitems->{$item} = scalar(@{$trails})-1;
8840: }
8841: my $deeper = $depth+1;
8842: push(@{$parents},$category);
1.665 raeburn 8843: if (ref($subcats) eq 'HASH') {
8844: my $subcat = &escape($name).':'.$category.':'.$depth;
8845: for (my $j=@{$parents}; $j>=0; $j--) {
8846: my $higher;
8847: if ($j > 0) {
8848: $higher = &escape($parents->[$j]).':'.
8849: &escape($parents->[$j-1]).':'.$j;
8850: } else {
8851: $higher = &escape($parents->[$j]).'::'.$j;
8852: }
8853: push(@{$subcats->{$higher}},$subcat);
8854: }
8855: }
8856: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8857: $subcats);
1.655 raeburn 8858: pop(@{$parents});
8859: }
8860: } else {
8861: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8862: my $trailstr = join(' -> ',(@{$parents},$category));
8863: if ($allitems->{$item} eq '') {
8864: push(@{$trails},$trailstr);
8865: $allitems->{$item} = scalar(@{$trails})-1;
8866: }
8867: }
8868: return;
8869: }
8870:
1.663 raeburn 8871: =pod
8872:
8873: =item *&assign_categories_table()
8874:
8875: Create a datatable for display of hierarchical categories in a domain,
8876: with checkboxes to allow a course to be categorized.
8877:
8878: Inputs:
8879:
8880: cathash - reference to hash of categories defined for the domain (from
8881: configuration.db)
8882:
8883: currcat - scalar with an & separated list of categories assigned to a course.
8884:
8885: Returns: $output (markup to be displayed)
8886:
8887: =cut
8888:
8889: sub assign_categories_table {
8890: my ($cathash,$currcat) = @_;
8891: my $output;
8892: if (ref($cathash) eq 'HASH') {
8893: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
8894: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
8895: $maxdepth = scalar(@cats);
8896: if (@cats > 0) {
8897: my $itemcount = 0;
8898: if (ref($cats[0]) eq 'ARRAY') {
8899: $output = &Apache::loncommon::start_data_table();
8900: my @currcategories;
8901: if ($currcat ne '') {
8902: @currcategories = split('&',$currcat);
8903: }
8904: for (my $i=0; $i<@{$cats[0]}; $i++) {
8905: my $parent = $cats[0][$i];
8906: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8907: next if ($parent eq 'instcode');
8908: my $item = &escape($parent).'::0';
8909: my $checked = '';
8910: if (@currcategories > 0) {
8911: if (grep(/^\Q$item\E$/,@currcategories)) {
8912: $checked = ' checked="checked" ';
8913: }
8914: }
1.675 raeburn 8915: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
8916: '<input type="checkbox" name="usecategory" value="'.
8917: $item.'"'.$checked.' />'.$parent.'</span>'.
8918: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 8919: my $depth = 1;
8920: push(@path,$parent);
8921: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
8922: pop(@path);
8923: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8924: $itemcount ++;
8925: }
8926: $output .= &Apache::loncommon::end_data_table();
8927: }
8928: }
8929: }
8930: return $output;
8931: }
8932:
8933: =pod
8934:
8935: =item *&assign_category_rows()
8936:
8937: Create a datatable row for display of nested categories in a domain,
8938: with checkboxes to allow a course to be categorized,called recursively.
8939:
8940: Inputs:
8941:
8942: itemcount - track row number for alternating colors
8943:
8944: cats - reference to array of arrays/hashes which encapsulates hierarchy of
8945: categories and subcategories.
8946:
8947: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
8948:
8949: parent - parent of current category item
8950:
8951: path - Array containing all categories back up through the hierarchy from the
8952: current category to the top level.
8953:
8954: currcategories - reference to array of current categories assigned to the course
8955:
8956: Returns: $output (markup to be displayed).
8957:
8958: =cut
8959:
8960: sub assign_category_rows {
8961: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
8962: my ($text,$name,$item,$chgstr);
8963: if (ref($cats) eq 'ARRAY') {
8964: my $maxdepth = scalar(@{$cats});
8965: if (ref($cats->[$depth]) eq 'HASH') {
8966: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8967: my $numchildren = @{$cats->[$depth]{$parent}};
8968: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8969: $text .= '<td><table class="LC_datatable">';
8970: for (my $j=0; $j<$numchildren; $j++) {
8971: $name = $cats->[$depth]{$parent}[$j];
8972: $item = &escape($name).':'.&escape($parent).':'.$depth;
8973: my $deeper = $depth+1;
8974: my $checked = '';
8975: if (ref($currcategories) eq 'ARRAY') {
8976: if (@{$currcategories} > 0) {
8977: if (grep(/^\Q$item\E$/,@{$currcategories})) {
8978: $checked = ' checked="checked" ';
8979: }
8980: }
8981: }
1.664 raeburn 8982: $text .= '<tr><td><span class="LC_nobreak"><label>'.
8983: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 8984: $item.'"'.$checked.' />'.$name.'</label></span>'.
8985: '<input type="hidden" name="catname" value="'.$name.'" />'.
8986: '</td><td>';
1.663 raeburn 8987: if (ref($path) eq 'ARRAY') {
8988: push(@{$path},$name);
8989: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
8990: pop(@{$path});
8991: }
8992: $text .= '</td></tr>';
8993: }
8994: $text .= '</table></td>';
8995: }
8996: }
8997: }
8998: return $text;
8999: }
9000:
1.655 raeburn 9001: ############################################################
9002: ############################################################
9003:
9004:
1.443 albertel 9005: sub commit_customrole {
1.664 raeburn 9006: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9007: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9008: ($start?', '.&mt('starting').' '.localtime($start):'').
9009: ($end?', ending '.localtime($end):'').': <b>'.
9010: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9011: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9012: '</b><br />';
9013: return $output;
9014: }
9015:
9016: sub commit_standardrole {
1.541 raeburn 9017: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9018: my ($output,$logmsg,$linefeed);
9019: if ($context eq 'auto') {
9020: $linefeed = "\n";
9021: } else {
9022: $linefeed = "<br />\n";
9023: }
1.443 albertel 9024: if ($three eq 'st') {
1.541 raeburn 9025: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9026: $one,$two,$sec,$context);
9027: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9028: ($result eq 'unknown_course') || ($result eq 'refused')) {
9029: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9030: } else {
1.541 raeburn 9031: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9032: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9033: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9034: if ($context eq 'auto') {
9035: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9036: } else {
9037: $output .= '<b>'.$result.'</b>'.$linefeed.
9038: &mt('Add to classlist').': <b>ok</b>';
9039: }
9040: $output .= $linefeed;
1.443 albertel 9041: }
9042: } else {
9043: $output = &mt('Assigning').' '.$three.' in '.$url.
9044: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9045: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9046: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9047: if ($context eq 'auto') {
9048: $output .= $result.$linefeed;
9049: } else {
9050: $output .= '<b>'.$result.'</b>'.$linefeed;
9051: }
1.443 albertel 9052: }
9053: return $output;
9054: }
9055:
9056: sub commit_studentrole {
1.541 raeburn 9057: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9058: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9059: if ($context eq 'auto') {
9060: $linefeed = "\n";
9061: } else {
9062: $linefeed = '<br />'."\n";
9063: }
1.443 albertel 9064: if (defined($one) && defined($two)) {
9065: my $cid=$one.'_'.$two;
9066: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9067: my $secchange = 0;
9068: my $expire_role_result;
9069: my $modify_section_result;
1.628 raeburn 9070: if ($oldsec ne '-1') {
9071: if ($oldsec ne $sec) {
1.443 albertel 9072: $secchange = 1;
1.628 raeburn 9073: my $now = time;
1.443 albertel 9074: my $uurl='/'.$cid;
9075: $uurl=~s/\_/\//g;
9076: if ($oldsec) {
9077: $uurl.='/'.$oldsec;
9078: }
1.626 raeburn 9079: $oldsecurl = $uurl;
1.628 raeburn 9080: $expire_role_result =
1.652 raeburn 9081: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9082: if ($env{'request.course.sec'} ne '') {
9083: if ($expire_role_result eq 'refused') {
9084: my @roles = ('st');
9085: my @statuses = ('previous');
9086: my @roledoms = ($one);
9087: my $withsec = 1;
9088: my %roleshash =
9089: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9090: \@statuses,\@roles,\@roledoms,$withsec);
9091: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9092: my ($oldstart,$oldend) =
9093: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9094: if ($oldend > 0 && $oldend <= $now) {
9095: $expire_role_result = 'ok';
9096: }
9097: }
9098: }
9099: }
1.443 albertel 9100: $result = $expire_role_result;
9101: }
9102: }
9103: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9104: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9105: if ($modify_section_result =~ /^ok/) {
9106: if ($secchange == 1) {
1.628 raeburn 9107: if ($sec eq '') {
9108: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9109: } else {
9110: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9111: }
1.443 albertel 9112: } elsif ($oldsec eq '-1') {
1.628 raeburn 9113: if ($sec eq '') {
9114: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9115: } else {
9116: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9117: }
1.443 albertel 9118: } else {
1.628 raeburn 9119: if ($sec eq '') {
9120: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9121: } else {
9122: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9123: }
1.443 albertel 9124: }
9125: } else {
1.628 raeburn 9126: if ($secchange) {
9127: $$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;
9128: } else {
9129: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9130: }
1.443 albertel 9131: }
9132: $result = $modify_section_result;
9133: } elsif ($secchange == 1) {
1.628 raeburn 9134: if ($oldsec eq '') {
9135: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9136: } else {
9137: $$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;
9138: }
1.626 raeburn 9139: if ($expire_role_result eq 'refused') {
9140: my $newsecurl = '/'.$cid;
9141: $newsecurl =~ s/\_/\//g;
9142: if ($sec ne '') {
9143: $newsecurl.='/'.$sec;
9144: }
9145: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9146: if ($sec eq '') {
9147: $$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;
9148: } else {
9149: $$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;
9150: }
9151: }
9152: }
1.443 albertel 9153: }
9154: } else {
1.626 raeburn 9155: $$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 9156: $result = "error: incomplete course id\n";
9157: }
9158: return $result;
9159: }
9160:
9161: ############################################################
9162: ############################################################
9163:
1.566 albertel 9164: sub check_clone {
1.578 raeburn 9165: my ($args,$linefeed) = @_;
1.566 albertel 9166: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9167: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9168: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9169: my $clonemsg;
9170: my $can_clone = 0;
9171:
9172: if ($clonehome eq 'no_host') {
1.578 raeburn 9173: $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 9174: } else {
9175: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9176: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9177: $can_clone = 1;
9178: } else {
9179: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9180: $args->{'clonedomain'},$args->{'clonecourse'});
9181: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9182: if (grep(/^\*$/,@cloners)) {
9183: $can_clone = 1;
9184: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9185: $can_clone = 1;
9186: } else {
9187: my %roleshash =
9188: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9189: $args->{'ccdomain'},
9190: 'userroles',['active'],['cc'],
9191: [$args->{'clonedomain'}]);
9192: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9193: $can_clone = 1;
9194: } else {
9195: $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'});
9196: }
1.566 albertel 9197: }
1.578 raeburn 9198: }
1.566 albertel 9199: }
9200: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9201: }
9202:
1.444 albertel 9203: sub construct_course {
1.541 raeburn 9204: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9205: my $outcome;
1.541 raeburn 9206: my $linefeed = '<br />'."\n";
9207: if ($context eq 'auto') {
9208: $linefeed = "\n";
9209: }
1.566 albertel 9210:
9211: #
9212: # Are we cloning?
9213: #
9214: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9215: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9216: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9217: if ($context ne 'auto') {
1.578 raeburn 9218: if ($clonemsg ne '') {
9219: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9220: }
1.566 albertel 9221: }
9222: $outcome .= $clonemsg.$linefeed;
9223:
9224: if (!$can_clone) {
9225: return (0,$outcome);
9226: }
9227: }
9228:
1.444 albertel 9229: #
9230: # Open course
9231: #
9232: my $crstype = lc($args->{'crstype'});
9233: my %cenv=();
9234: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9235: $args->{'cdescr'},
9236: $args->{'curl'},
9237: $args->{'course_home'},
9238: $args->{'nonstandard'},
9239: $args->{'crscode'},
9240: $args->{'ccuname'}.':'.
9241: $args->{'ccdomain'},
9242: $args->{'crstype'});
9243:
9244: # Note: The testing routines depend on this being output; see
9245: # Utils::Course. This needs to at least be output as a comment
9246: # if anyone ever decides to not show this, and Utils::Course::new
9247: # will need to be suitably modified.
1.541 raeburn 9248: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9249: #
9250: # Check if created correctly
9251: #
1.479 albertel 9252: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9253: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9254: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9255:
1.444 albertel 9256: #
1.566 albertel 9257: # Do the cloning
9258: #
9259: if ($can_clone && $cloneid) {
9260: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9261: if ($context ne 'auto') {
9262: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9263: }
9264: $outcome .= $clonemsg.$linefeed;
9265: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9266: # Copy all files
1.637 www 9267: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9268: # Restore URL
1.566 albertel 9269: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9270: # Restore title
1.566 albertel 9271: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9272: # Mark as cloned
1.566 albertel 9273: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9274: # Need to clone grading mode
9275: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9276: $cenv{'grading'}=$newenv{'grading'};
9277: # Do not clone these environment entries
9278: &Apache::lonnet::del('environment',
9279: ['default_enrollment_start_date',
9280: 'default_enrollment_end_date',
9281: 'question.email',
9282: 'policy.email',
9283: 'comment.email',
9284: 'pch.users.denied',
1.692.4.2 raeburn 9285: 'plc.users.denied',
9286: 'hidefromcat',
9287: 'categories'],
1.638 www 9288: $$crsudom,$$crsunum);
1.444 albertel 9289: }
1.566 albertel 9290:
1.444 albertel 9291: #
9292: # Set environment (will override cloned, if existing)
9293: #
9294: my @sections = ();
9295: my @xlists = ();
9296: if ($args->{'crstype'}) {
9297: $cenv{'type'}=$args->{'crstype'};
9298: }
9299: if ($args->{'crsid'}) {
9300: $cenv{'courseid'}=$args->{'crsid'};
9301: }
9302: if ($args->{'crscode'}) {
9303: $cenv{'internal.coursecode'}=$args->{'crscode'};
9304: }
9305: if ($args->{'crsquota'} ne '') {
9306: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9307: } else {
9308: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9309: }
9310: if ($args->{'ccuname'}) {
9311: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9312: ':'.$args->{'ccdomain'};
9313: } else {
9314: $cenv{'internal.courseowner'} = $args->{'curruser'};
9315: }
9316: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9317: if ($args->{'crssections'}) {
9318: $cenv{'internal.sectionnums'} = '';
9319: if ($args->{'crssections'} =~ m/,/) {
9320: @sections = split/,/,$args->{'crssections'};
9321: } else {
9322: $sections[0] = $args->{'crssections'};
9323: }
9324: if (@sections > 0) {
9325: foreach my $item (@sections) {
9326: my ($sec,$gp) = split/:/,$item;
9327: my $class = $args->{'crscode'}.$sec;
9328: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9329: $cenv{'internal.sectionnums'} .= $item.',';
9330: unless ($addcheck eq 'ok') {
9331: push @badclasses, $class;
9332: }
9333: }
9334: $cenv{'internal.sectionnums'} =~ s/,$//;
9335: }
9336: }
9337: # do not hide course coordinator from staff listing,
9338: # even if privileged
9339: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9340: # add crosslistings
9341: if ($args->{'crsxlist'}) {
9342: $cenv{'internal.crosslistings'}='';
9343: if ($args->{'crsxlist'} =~ m/,/) {
9344: @xlists = split/,/,$args->{'crsxlist'};
9345: } else {
9346: $xlists[0] = $args->{'crsxlist'};
9347: }
9348: if (@xlists > 0) {
9349: foreach my $item (@xlists) {
9350: my ($xl,$gp) = split/:/,$item;
9351: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9352: $cenv{'internal.crosslistings'} .= $item.',';
9353: unless ($addcheck eq 'ok') {
9354: push @badclasses, $xl;
9355: }
9356: }
9357: $cenv{'internal.crosslistings'} =~ s/,$//;
9358: }
9359: }
9360: if ($args->{'autoadds'}) {
9361: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9362: }
9363: if ($args->{'autodrops'}) {
9364: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9365: }
9366: # check for notification of enrollment changes
9367: my @notified = ();
9368: if ($args->{'notify_owner'}) {
9369: if ($args->{'ccuname'} ne '') {
9370: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9371: }
9372: }
9373: if ($args->{'notify_dc'}) {
9374: if ($uname ne '') {
1.630 raeburn 9375: push(@notified,$uname.':'.$udom);
1.444 albertel 9376: }
9377: }
9378: if (@notified > 0) {
9379: my $notifylist;
9380: if (@notified > 1) {
9381: $notifylist = join(',',@notified);
9382: } else {
9383: $notifylist = $notified[0];
9384: }
9385: $cenv{'internal.notifylist'} = $notifylist;
9386: }
9387: if (@badclasses > 0) {
9388: my %lt=&Apache::lonlocal::texthash(
9389: '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',
9390: 'dnhr' => 'does not have rights to access enrollment in these classes',
9391: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9392: );
1.541 raeburn 9393: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9394: ' ('.$lt{'adby'}.')';
9395: if ($context eq 'auto') {
9396: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9397: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9398: foreach my $item (@badclasses) {
9399: if ($context eq 'auto') {
9400: $outcome .= " - $item\n";
9401: } else {
9402: $outcome .= "<li>$item</li>\n";
9403: }
9404: }
9405: if ($context eq 'auto') {
9406: $outcome .= $linefeed;
9407: } else {
1.566 albertel 9408: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9409: }
9410: }
1.444 albertel 9411: }
9412: if ($args->{'no_end_date'}) {
9413: $args->{'endaccess'} = 0;
9414: }
9415: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9416: $cenv{'internal.autoend'}=$args->{'enrollend'};
9417: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9418: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9419: if ($args->{'showphotos'}) {
9420: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9421: }
9422: $cenv{'internal.authtype'} = $args->{'authtype'};
9423: $cenv{'internal.autharg'} = $args->{'autharg'};
9424: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9425: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9426: 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');
9427: if ($context eq 'auto') {
9428: $outcome .= $krb_msg;
9429: } else {
1.566 albertel 9430: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9431: }
9432: $outcome .= $linefeed;
1.444 albertel 9433: }
9434: }
9435: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9436: if ($args->{'setpolicy'}) {
9437: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9438: }
9439: if ($args->{'setcontent'}) {
9440: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9441: }
9442: }
9443: if ($args->{'reshome'}) {
9444: $cenv{'reshome'}=$args->{'reshome'}.'/';
9445: $cenv{'reshome'}=~s/\/+$/\//;
9446: }
9447: #
9448: # course has keyed access
9449: #
9450: if ($args->{'setkeys'}) {
9451: $cenv{'keyaccess'}='yes';
9452: }
9453: # if specified, key authority is not course, but user
9454: # only active if keyaccess is yes
9455: if ($args->{'keyauth'}) {
1.487 albertel 9456: my ($user,$domain) = split(':',$args->{'keyauth'});
9457: $user = &LONCAPA::clean_username($user);
9458: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9459: if ($user ne '' && $domain ne '') {
1.487 albertel 9460: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9461: }
9462: }
9463:
9464: if ($args->{'disresdis'}) {
9465: $cenv{'pch.roles.denied'}='st';
9466: }
9467: if ($args->{'disablechat'}) {
9468: $cenv{'plc.roles.denied'}='st';
9469: }
9470:
9471: # Record we've not yet viewed the Course Initialization Helper for this
9472: # course
9473: $cenv{'course.helper.not.run'} = 1;
9474: #
9475: # Use new Randomseed
9476: #
9477: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9478: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9479: #
9480: # The encryption code and receipt prefix for this course
9481: #
9482: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9483: $cenv{'internal.encpref'}=100+int(9*rand(99));
9484: #
9485: # By default, use standard grading
9486: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9487:
1.541 raeburn 9488: $outcome .= $linefeed.&mt('Setting environment').': '.
9489: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9490: #
9491: # Open all assignments
9492: #
9493: if ($args->{'openall'}) {
9494: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9495: my %storecontent = ($storeunder => time,
9496: $storeunder.'.type' => 'date_start');
9497:
9498: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9499: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9500: }
9501: #
9502: # Set first page
9503: #
9504: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9505: || ($cloneid)) {
1.445 albertel 9506: use LONCAPA::map;
1.444 albertel 9507: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9508:
9509: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9510: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9511:
1.444 albertel 9512: $outcome .= ($fatal?$errtext:'read ok').' - ';
9513: my $title; my $url;
9514: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9515: $title=&mt('Syllabus');
1.444 albertel 9516: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9517: } else {
1.690 bisitz 9518: $title=&mt('Navigate Contents');
1.444 albertel 9519: $url='/adm/navmaps';
9520: }
1.445 albertel 9521:
9522: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9523: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9524:
9525: if ($errtext) { $fatal=2; }
1.541 raeburn 9526: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9527: }
1.566 albertel 9528:
9529: return (1,$outcome);
1.444 albertel 9530: }
9531:
9532: ############################################################
9533: ############################################################
9534:
1.378 raeburn 9535: sub course_type {
9536: my ($cid) = @_;
9537: if (!defined($cid)) {
9538: $cid = $env{'request.course.id'};
9539: }
1.404 albertel 9540: if (defined($env{'course.'.$cid.'.type'})) {
9541: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9542: } else {
9543: return 'Course';
1.377 raeburn 9544: }
9545: }
1.156 albertel 9546:
1.406 raeburn 9547: sub group_term {
9548: my $crstype = &course_type();
9549: my %names = (
9550: 'Course' => 'group',
9551: 'Group' => 'team',
9552: );
9553: return $names{$crstype};
9554: }
9555:
1.156 albertel 9556: sub icon {
9557: my ($file)=@_;
1.505 albertel 9558: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9559: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9560: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9561: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9562: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9563: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9564: $curfext.".gif") {
9565: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9566: $curfext.".gif";
9567: }
9568: }
1.249 albertel 9569: return &lonhttpdurl($iconname);
1.154 albertel 9570: }
1.84 albertel 9571:
1.575 albertel 9572: sub lonhttpdurl {
1.692 www 9573: #
9574: # Had been used for "small fry" static images on separate port 8080.
9575: # Modify here if lightweight http functionality desired again.
9576: # Currently eliminated due to increasing firewall issues.
9577: #
1.575 albertel 9578: my ($url)=@_;
1.692 www 9579: return $url;
1.215 albertel 9580: }
9581:
1.213 albertel 9582: sub connection_aborted {
9583: my ($r)=@_;
9584: $r->print(" ");$r->rflush();
9585: my $c = $r->connection;
9586: return $c->aborted();
9587: }
9588:
1.221 foxr 9589: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9590: # strings as 'strings'.
9591: sub escape_single {
1.221 foxr 9592: my ($input) = @_;
1.223 albertel 9593: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9594: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9595: return $input;
9596: }
1.223 albertel 9597:
1.222 foxr 9598: # Same as escape_single, but escape's "'s This
9599: # can be used for "strings"
9600: sub escape_double {
9601: my ($input) = @_;
9602: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9603: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9604: return $input;
9605: }
1.223 albertel 9606:
1.222 foxr 9607: # Escapes the last element of a full URL.
9608: sub escape_url {
9609: my ($url) = @_;
1.238 raeburn 9610: my @urlslices = split(/\//, $url,-1);
1.369 www 9611: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9612: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9613: }
1.462 albertel 9614:
1.692.4.2 raeburn 9615: sub compare_arrays {
9616: my ($arrayref1,$arrayref2) = @_;
9617: my (@difference,%count);
9618: @difference = ();
9619: %count = ();
9620: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
9621: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
9622: foreach my $element (keys(%count)) {
9623: if ($count{$element} == 1) {
9624: push(@difference,$element);
9625: }
9626: }
9627: }
9628: return @difference;
9629: }
9630:
1.462 albertel 9631: # -------------------------------------------------------- Initliaze user login
9632: sub init_user_environment {
1.463 albertel 9633: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9634: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9635:
9636: my $public=($username eq 'public' && $domain eq 'public');
9637:
9638: # See if old ID present, if so, remove
9639:
9640: my ($filename,$cookie,$userroles);
9641: my $now=time;
9642:
9643: if ($public) {
9644: my $max_public=100;
9645: my $oldest;
9646: my $oldest_time=0;
9647: for(my $next=1;$next<=$max_public;$next++) {
9648: if (-e $lonids."/publicuser_$next.id") {
9649: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9650: if ($mtime<$oldest_time || !$oldest_time) {
9651: $oldest_time=$mtime;
9652: $oldest=$next;
9653: }
9654: } else {
9655: $cookie="publicuser_$next";
9656: last;
9657: }
9658: }
9659: if (!$cookie) { $cookie="publicuser_$oldest"; }
9660: } else {
1.463 albertel 9661: # if this isn't a robot, kill any existing non-robot sessions
9662: if (!$args->{'robot'}) {
9663: opendir(DIR,$lonids);
9664: while ($filename=readdir(DIR)) {
9665: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9666: unlink($lonids.'/'.$filename);
9667: }
1.462 albertel 9668: }
1.463 albertel 9669: closedir(DIR);
1.462 albertel 9670: }
9671: # Give them a new cookie
1.463 albertel 9672: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9673: : $now.$$.int(rand(10000)));
1.463 albertel 9674: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9675:
9676: # Initialize roles
9677:
9678: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9679: }
9680: # ------------------------------------ Check browser type and MathML capability
9681:
9682: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9683: $clientunicode,$clientos) = &decode_user_agent($r);
9684:
9685: # -------------------------------------- Any accessibility options to remember?
9686: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9687: foreach my $option ('imagesuppress','appletsuppress',
9688: 'embedsuppress','fontenhance','blackwhite') {
9689: if ($form->{$option} eq 'true') {
9690: &Apache::lonnet::put('environment',{$option => 'on'},
9691: $domain,$username);
9692: } else {
9693: &Apache::lonnet::del('environment',[$option],
9694: $domain,$username);
9695: }
9696: }
9697: }
9698: # ------------------------------------------------------------- Get environment
9699:
9700: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9701: my ($tmp) = keys(%userenv);
9702: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9703: # default remote control to off
9704: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9705: } else {
9706: undef(%userenv);
9707: }
9708: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9709: $form->{'interface'}=$userenv{'interface'};
9710: }
9711: $env{'environment.remote'}=$userenv{'remote'};
9712: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9713:
9714: # --------------- Do not trust query string to be put directly into environment
9715: foreach my $option ('imagesuppress','appletsuppress',
9716: 'embedsuppress','fontenhance','blackwhite',
9717: 'interface','localpath','localres') {
9718: $form->{$option}=~s/[\n\r\=]//gs;
9719: }
9720: # --------------------------------------------------------- Write first profile
9721:
9722: {
9723: my %initial_env =
9724: ("user.name" => $username,
9725: "user.domain" => $domain,
9726: "user.home" => $authhost,
9727: "browser.type" => $clientbrowser,
9728: "browser.version" => $clientversion,
9729: "browser.mathml" => $clientmathml,
9730: "browser.unicode" => $clientunicode,
9731: "browser.os" => $clientos,
9732: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9733: "request.course.fn" => '',
9734: "request.course.uri" => '',
9735: "request.course.sec" => '',
9736: "request.role" => 'cm',
9737: "request.role.adv" => $env{'user.adv'},
9738: "request.host" => $ENV{'REMOTE_ADDR'},);
9739:
9740: if ($form->{'localpath'}) {
9741: $initial_env{"browser.localpath"} = $form->{'localpath'};
9742: $initial_env{"browser.localres"} = $form->{'localres'};
9743: }
9744:
9745: if ($public) {
9746: $initial_env{"environment.remote"} = "off";
9747: }
9748: if ($form->{'interface'}) {
9749: $form->{'interface'}=~s/\W//gs;
9750: $initial_env{"browser.interface"} = $form->{'interface'};
9751: $env{'browser.interface'}=$form->{'interface'};
9752: foreach my $option ('imagesuppress','appletsuppress',
9753: 'embedsuppress','fontenhance','blackwhite') {
9754: if (($form->{$option} eq 'true') ||
9755: ($userenv{$option} eq 'on')) {
9756: $initial_env{"browser.$option"} = "on";
9757: }
9758: }
9759: }
9760:
1.692.4.2 raeburn 9761: foreach my $tool ('aboutme','blog','portfolio') {
9762: $userenv{'availabletools.'.$tool} =
9763: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9764: }
9765:
9766: foreach my $crstype ('official','unofficial') {
9767: $userenv{'canrequest.'.$crstype} =
9768: &Apache::lonnet::usertools_access($username,$domain,$crstype,
9769: 'reload','requestcourses');
9770: }
9771:
1.462 albertel 9772: $env{'user.environment'} = "$lonids/$cookie.id";
9773:
9774: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9775: &GDBM_WRCREAT(),0640)) {
9776: &_add_to_env(\%disk_env,\%initial_env);
9777: &_add_to_env(\%disk_env,\%userenv,'environment.');
9778: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9779: if (ref($args->{'extra_env'})) {
9780: &_add_to_env(\%disk_env,$args->{'extra_env'});
9781: }
1.462 albertel 9782: untie(%disk_env);
9783: } else {
9784: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
9785: 'Could not create environment storage in lonauth: '.$!.'</font>');
9786: return 'error: '.$!;
9787: }
9788: }
9789: $env{'request.role'}='cm';
9790: $env{'request.role.adv'}=$env{'user.adv'};
9791: $env{'browser.type'}=$clientbrowser;
9792:
9793: return $cookie;
9794:
9795: }
9796:
9797: sub _add_to_env {
9798: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9799: if (ref($env_data) eq 'HASH') {
9800: while (my ($key,$value) = each(%$env_data)) {
9801: $idf->{$prefix.$key} = $value;
9802: $env{$prefix.$key} = $value;
9803: }
1.462 albertel 9804: }
9805: }
9806:
1.685 tempelho 9807: # --- Get the symbolic name of a problem and the url
9808: sub get_symb {
9809: my ($request,$silent) = @_;
1.692.4.2 raeburn 9810: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 9811: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9812: if ($symb eq '') {
9813: if (!$silent) {
9814: $request->print("Unable to handle ambiguous references:$url:.");
9815: return ();
9816: }
9817: }
9818: &Apache::lonenc::check_decrypt(\$symb);
9819: return ($symb);
9820: }
9821:
9822: # --------------------------------------------------------------Get annotation
9823:
9824: sub get_annotation {
9825: my ($symb,$enc) = @_;
9826:
9827: my $key = $symb;
9828: if (!$enc) {
9829: $key =
9830: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9831: }
9832: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9833: return $annotation{$key};
9834: }
9835:
9836: sub clean_symb {
1.692.4.2 raeburn 9837: my ($symb,$delete_enc) = @_;
1.685 tempelho 9838:
9839: &Apache::lonenc::check_decrypt(\$symb);
9840: my $enc = $env{'request.enc'};
1.692.4.2 raeburn 9841: if ($delete_enc) {
9842: delete($env{'request.enc'});
9843: }
1.685 tempelho 9844:
9845: return ($symb,$enc);
9846: }
1.462 albertel 9847:
1.41 ng 9848: =pod
9849:
9850: =back
9851:
1.112 bowersj2 9852: =cut
1.41 ng 9853:
1.112 bowersj2 9854: 1;
9855: __END__;
1.41 ng 9856:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>