Annotation of loncom/interface/loncommon.pm, revision 1.692.4.2
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.2! raeburn 4: # $Id: loncommon.pm,v 1.692.4.1 2009/05/19 00:16:11 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 = '';
979: if ($other) {
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.392 albertel 4555:
1.608 albertel 4556: my $border = ($env{'browser.type'} eq 'explorer' ||
1.692.4.2! raeburn 4557: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
! 4558: : '0 3px 0 4px';
1.448 albertel 4559:
1.523 albertel 4560:
1.343 albertel 4561: return <<END;
1.345 albertel 4562: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4563: a:focus { color: red; background: yellow }
1.510 albertel 4564: table.thinborder,
1.523 albertel 4565:
1.510 albertel 4566: table.thinborder tr th {
4567: border-style: solid;
4568: border-width: 1px;
4569: background: $tabbg;
4570: }
1.523 albertel 4571: table.thinborder tr td {
1.510 albertel 4572: border-style: solid;
4573: border-width: 1px
4574: }
1.426 albertel 4575:
1.343 albertel 4576: form, .inline { display: inline; }
4577: .center { text-align: center; }
1.593 albertel 4578: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4579: .LC_error {
4580: color: red;
4581: font-size: larger;
4582: }
1.457 albertel 4583: .LC_warning,
4584: .LC_diff_removed {
1.394 albertel 4585: color: red;
4586: }
1.532 albertel 4587:
4588: .LC_info,
1.457 albertel 4589: .LC_success,
4590: .LC_diff_added {
1.350 albertel 4591: color: green;
4592: }
1.692.4.2! raeburn 4593:
! 4594: div.LC_confirm_box {
! 4595: background-color: #FAFAFA;
! 4596: border: 1px solid $lg_border_color;
! 4597: margin-right: 0;
! 4598: padding: 5px;
! 4599: }
! 4600:
! 4601: div.LC_confirm_box .LC_error img,
! 4602: div.LC_confirm_box .LC_success img {
! 4603: vertical-align: middle;
1.543 albertel 4604: }
4605:
1.440 albertel 4606: .LC_icon {
1.692.4.2! raeburn 4607: border: none;
1.440 albertel 4608: }
1.539 albertel 4609: .LC_indexer_icon {
1.692.4.2! raeburn 4610: border: 0;
1.539 albertel 4611: height: 22px;
4612: }
1.543 albertel 4613: .LC_docs_spacer {
4614: width: 25px;
4615: height: 1px;
1.692.4.2! raeburn 4616: border: none;
1.543 albertel 4617: }
1.346 albertel 4618:
1.532 albertel 4619: .LC_internal_info {
1.692.4.2! raeburn 4620: color: #999999;
1.532 albertel 4621: }
4622:
1.458 albertel 4623: table.LC_pastsubmission {
4624: border: 1px solid black;
4625: margin: 2px;
4626: }
4627:
1.606 albertel 4628: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4629: width: 100%;
4630: background: $pgbg;
1.392 albertel 4631: border: 2px;
1.402 albertel 4632: border-collapse: separate;
1.692.4.2! raeburn 4633: padding: 0;
1.345 albertel 4634: }
1.392 albertel 4635:
1.606 albertel 4636: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4637: table#LC_title_bar.LC_with_remote {
1.359 albertel 4638: width: 100%;
1.392 albertel 4639: border-color: $pgbg;
4640: border-style: solid;
4641: border-width: $border;
4642:
1.379 albertel 4643: background: $pgbg;
4644: font-family: $sans;
1.392 albertel 4645: border-collapse: collapse;
1.692.4.2! raeburn 4646: padding: 0;
1.359 albertel 4647: }
1.392 albertel 4648:
1.409 albertel 4649: table.LC_docs_path {
4650: width: 100%;
4651: border: 0;
4652: background: $pgbg;
4653: font-family: $sans;
4654: border-collapse: collapse;
1.692.4.2! raeburn 4655: padding: 0;
1.409 albertel 4656: }
4657:
1.359 albertel 4658: table#LC_title_bar td {
4659: background: $tabbg;
4660: }
4661: table#LC_title_bar td.LC_title_bar_who {
4662: background: $tabbg;
4663: color: $font;
1.427 albertel 4664: font: small $sans;
1.359 albertel 4665: text-align: right;
4666: }
1.469 banghart 4667: span.LC_metadata {
4668: font-family: $sans;
4669: }
1.359 albertel 4670: span.LC_title_bar_title {
1.416 albertel 4671: font: bold x-large $sans;
1.359 albertel 4672: }
4673: table#LC_title_bar td.LC_title_bar_domain_logo {
4674: background: $sidebg;
4675: text-align: right;
1.692.4.2! raeburn 4676: padding: 0;
1.368 albertel 4677: }
4678: table#LC_title_bar td.LC_title_bar_role_logo {
4679: background: $sidebg;
1.692.4.2! raeburn 4680: padding: 0;
1.359 albertel 4681: }
4682:
1.346 albertel 4683: table#LC_menubuttons_mainmenu {
1.526 www 4684: width: 100%;
1.692.4.2! raeburn 4685: border: 0;
1.346 albertel 4686: border-spacing: 1px;
1.692.4.2! raeburn 4687: padding: 0 1px;
! 4688: margin: 0;
1.346 albertel 4689: border-collapse: separate;
4690: }
4691: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
1.692.4.2! raeburn 4692: border: none;
1.346 albertel 4693: }
1.345 albertel 4694: table#LC_top_nav td {
4695: background: $tabbg;
1.692.4.2! raeburn 4696: border: none;
1.407 albertel 4697: font-size: small;
1.345 albertel 4698: }
4699: table#LC_top_nav td a, div#LC_top_nav a {
4700: color: $font;
4701: font-family: $sans;
4702: }
1.364 albertel 4703: table#LC_top_nav td.LC_top_nav_logo {
4704: background: $tabbg;
1.432 albertel 4705: text-align: left;
1.408 albertel 4706: white-space: nowrap;
1.432 albertel 4707: width: 31px;
1.408 albertel 4708: }
4709: table#LC_top_nav td.LC_top_nav_logo img {
1.692.4.2! raeburn 4710: border: none;
1.408 albertel 4711: vertical-align: bottom;
1.364 albertel 4712: }
1.432 albertel 4713: table#LC_top_nav td.LC_top_nav_exit,
4714: table#LC_top_nav td.LC_top_nav_help {
4715: width: 2.0em;
4716: }
1.442 albertel 4717: table#LC_top_nav td.LC_top_nav_login {
4718: width: 4.0em;
4719: text-align: center;
4720: }
1.409 albertel 4721: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4722: background: $tabbg;
4723: color: $font;
4724: font-family: $sans;
1.358 albertel 4725: font-size: smaller;
1.357 albertel 4726: }
1.411 albertel 4727: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4728: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4729: background: $tabbg;
4730: color: $font;
4731: font-family: $sans;
4732: font-size: larger;
4733: text-align: right;
4734: }
1.383 albertel 4735: td.LC_table_cell_checkbox {
4736: text-align: center;
4737: }
1.522 albertel 4738: table#LC_mainmenu td.LC_mainmenu_column {
4739: vertical-align: top;
4740: }
4741:
1.346 albertel 4742: .LC_menubuttons_inline_text {
4743: color: $font;
4744: font-family: $sans;
4745: font-size: smaller;
4746: }
4747:
1.526 www 4748: .LC_menubuttons_link {
4749: text-decoration: none;
4750: }
1.692.4.2! raeburn 4751: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4752: .LC_menubuttons_category {
1.521 www 4753: color: $font;
1.526 www 4754: background: $pgbg;
1.521 www 4755: font-family: $sans;
4756: font-size: larger;
4757: font-weight: bold;
4758: }
4759:
1.346 albertel 4760: td.LC_menubuttons_text {
1.526 www 4761: width: 90%;
1.346 albertel 4762: color: $font;
4763: font-family: $sans;
4764: }
1.526 www 4765:
1.346 albertel 4766: td.LC_menubuttons_img {
4767: }
1.526 www 4768:
1.346 albertel 4769: .LC_current_location {
4770: font-family: $sans;
4771: background: $tabbg;
4772: }
4773: .LC_new_mail {
4774: font-family: $sans;
1.634 www 4775: background: $tabbg;
1.346 albertel 4776: font-weight: bold;
4777: }
1.347 albertel 4778:
1.527 www 4779: .LC_dropadd_labeltext {
4780: font-family: $sans;
4781: text-align: right;
4782: }
4783:
4784: .LC_preferences_labeltext {
4785: font-family: $sans;
4786: text-align: right;
4787: }
4788:
1.666 raeburn 4789: .LC_roleslog_note {
4790: font-size: smaller;
4791: }
4792:
1.692.4.2! raeburn 4793: .LC_mail_functions {
! 4794: font-weight: bold;
! 4795: }
! 4796:
1.440 albertel 4797: table.LC_aboutme_port {
1.692.4.2! raeburn 4798: border: none;
1.440 albertel 4799: border-collapse: collapse;
1.692.4.2! raeburn 4800: border-spacing: 0;
1.440 albertel 4801: }
1.349 albertel 4802: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4803: border: 1px solid #000000;
1.402 albertel 4804: border-collapse: separate;
1.426 albertel 4805: border-spacing: 1px;
1.610 albertel 4806: background: $pgbg;
1.347 albertel 4807: }
1.422 albertel 4808: .LC_data_table_dense {
4809: font-size: small;
4810: }
1.507 raeburn 4811: table.LC_nested_outer {
4812: border: 1px solid #000000;
1.589 raeburn 4813: border-collapse: collapse;
1.692.4.2! raeburn 4814: border-spacing: 0;
1.507 raeburn 4815: width: 100%;
4816: }
4817: table.LC_nested {
1.692.4.2! raeburn 4818: border: none;
1.589 raeburn 4819: border-collapse: collapse;
1.692.4.2! raeburn 4820: border-spacing: 0;
1.507 raeburn 4821: width: 100%;
4822: }
1.523 albertel 4823: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4824: table.LC_prior_tries tr th {
1.349 albertel 4825: font-weight: bold;
4826: background-color: $data_table_head;
1.421 albertel 4827: font-size: smaller;
1.347 albertel 4828: }
1.692.4.2! raeburn 4829: table.LC_data_table tr.LC_info_row > td {
! 4830: background-color: #CCCCCC;
! 4831: font-weight: bold;
! 4832: text-align: left;
! 4833: }
1.610 albertel 4834: table.LC_data_table tr.LC_odd_row > td,
1.692.4.2! raeburn 4835: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4836: table.LC_aboutme_port tr td {
1.349 albertel 4837: background-color: $data_table_light;
1.425 albertel 4838: padding: 2px;
1.347 albertel 4839: }
1.610 albertel 4840: table.LC_data_table tr.LC_even_row > td,
1.692.4.2! raeburn 4841: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4842: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4843: background-color: $data_table_dark;
1.692.4.2! raeburn 4844: padding: 2px;
1.347 albertel 4845: }
1.425 albertel 4846: table.LC_data_table tr.LC_data_table_highlight td {
4847: background-color: $data_table_darker;
4848: }
1.639 raeburn 4849: table.LC_data_table tr td.LC_leftcol_header {
4850: background-color: $data_table_head;
4851: font-weight: bold;
4852: }
1.451 albertel 4853: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4854: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4855: background-color: #FFFFFF;
1.421 albertel 4856: font-weight: bold;
4857: font-style: italic;
4858: text-align: center;
4859: padding: 8px;
1.347 albertel 4860: }
1.507 raeburn 4861: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4862: padding: 4ex
4863: }
1.507 raeburn 4864: table.LC_nested_outer tr th {
4865: font-weight: bold;
4866: background-color: $data_table_head;
4867: font-size: smaller;
4868: border-bottom: 1px solid #000000;
4869: }
4870: table.LC_nested_outer tr td.LC_subheader {
4871: background-color: $data_table_head;
4872: font-weight: bold;
4873: font-size: small;
4874: border-bottom: 1px solid #000000;
4875: text-align: right;
1.451 albertel 4876: }
1.507 raeburn 4877: table.LC_nested tr.LC_info_row td {
1.692.4.2! raeburn 4878: background-color: #CCCCCC;
1.451 albertel 4879: font-weight: bold;
4880: font-size: small;
1.507 raeburn 4881: text-align: center;
4882: }
1.589 raeburn 4883: table.LC_nested tr.LC_info_row td.LC_left_item,
4884: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4885: text-align: left;
1.451 albertel 4886: }
1.507 raeburn 4887: table.LC_nested td {
1.692.4.2! raeburn 4888: background-color: #FFFFFF;
1.451 albertel 4889: font-size: small;
1.507 raeburn 4890: }
4891: table.LC_nested_outer tr th.LC_right_item,
4892: table.LC_nested tr.LC_info_row td.LC_right_item,
4893: table.LC_nested tr.LC_odd_row td.LC_right_item,
4894: table.LC_nested tr td.LC_right_item {
1.451 albertel 4895: text-align: right;
4896: }
4897:
1.507 raeburn 4898: table.LC_nested tr.LC_odd_row td {
1.692.4.2! raeburn 4899: background-color: #EEEEEE;
1.451 albertel 4900: }
4901:
1.473 raeburn 4902: table.LC_createuser {
4903: }
4904:
4905: table.LC_createuser tr.LC_section_row td {
4906: font-size: smaller;
4907: }
4908:
4909: table.LC_createuser tr.LC_info_row td {
1.692.4.2! raeburn 4910: background-color: #CCCCCC;
1.473 raeburn 4911: font-weight: bold;
4912: text-align: center;
4913: }
4914:
1.349 albertel 4915: table.LC_calendar {
4916: border: 1px solid #000000;
4917: border-collapse: collapse;
4918: }
4919: table.LC_calendar_pickdate {
4920: font-size: xx-small;
4921: }
4922: table.LC_calendar tr td {
4923: border: 1px solid #000000;
4924: vertical-align: top;
4925: }
4926: table.LC_calendar tr td.LC_calendar_day_empty {
4927: background-color: $data_table_dark;
4928: }
4929: table.LC_calendar tr td.LC_calendar_day_current {
4930: background-color: $data_table_highlight;
4931: }
4932:
4933: table.LC_mail_list tr.LC_mail_new {
4934: background-color: $mail_new;
4935: }
4936: table.LC_mail_list tr.LC_mail_new:hover {
4937: background-color: $mail_new_hover;
4938: }
4939: table.LC_mail_list tr.LC_mail_read {
4940: background-color: $mail_read;
4941: }
4942: table.LC_mail_list tr.LC_mail_read:hover {
4943: background-color: $mail_read_hover;
4944: }
4945: table.LC_mail_list tr.LC_mail_replied {
4946: background-color: $mail_replied;
4947: }
4948: table.LC_mail_list tr.LC_mail_replied:hover {
4949: background-color: $mail_replied_hover;
4950: }
4951: table.LC_mail_list tr.LC_mail_other {
4952: background-color: $mail_other;
4953: }
4954: table.LC_mail_list tr.LC_mail_other:hover {
4955: background-color: $mail_other_hover;
4956: }
1.494 raeburn 4957: table.LC_mail_list tr.LC_mail_even {
4958: }
4959: table.LC_mail_list tr.LC_mail_odd {
4960: }
4961:
1.385 albertel 4962:
1.386 albertel 4963: table#LC_portfolio_actions {
4964: width: auto;
4965: background: $pgbg;
1.692.4.2! raeburn 4966: border: none;
1.386 albertel 4967: border-spacing: 2px 2px;
1.692.4.2! raeburn 4968: padding: 0;
! 4969: margin: 0;
1.386 albertel 4970: border-collapse: separate;
4971: }
4972: table#LC_portfolio_actions td.LC_label {
4973: background: $tabbg;
4974: text-align: right;
4975: }
4976: table#LC_portfolio_actions td.LC_value {
4977: background: $tabbg;
4978: }
1.385 albertel 4979:
1.391 albertel 4980: table#LC_cstr_controls {
4981: width: 100%;
4982: border-collapse: collapse;
4983: }
4984: table#LC_cstr_controls tr td {
4985: border: 4px solid $pgbg;
4986: padding: 4px;
4987: text-align: center;
4988: background: $tabbg;
4989: }
4990: table#LC_cstr_controls tr th {
4991: border: 4px solid $pgbg;
4992: background: $table_header;
4993: text-align: center;
4994: font-family: $sans;
4995: font-size: smaller;
4996: }
4997:
1.389 albertel 4998: table#LC_browser {
4999:
5000: }
5001: table#LC_browser tr th {
1.391 albertel 5002: background: $table_header;
1.389 albertel 5003: }
1.390 albertel 5004: table#LC_browser tr td {
5005: padding: 2px;
5006: }
1.389 albertel 5007: table#LC_browser tr.LC_browser_file,
5008: table#LC_browser tr.LC_browser_file_published {
5009: background: #CCFF88;
5010: }
5011: table#LC_browser tr.LC_browser_file_locked,
5012: table#LC_browser tr.LC_browser_file_unpublished {
5013: background: #FFAA99;
1.387 albertel 5014: }
1.389 albertel 5015: table#LC_browser tr.LC_browser_file_obsolete {
5016: background: #AAAAAA;
1.387 albertel 5017: }
1.455 albertel 5018: table#LC_browser tr.LC_browser_file_modified,
5019: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 5020: background: #FFFF77;
1.387 albertel 5021: }
1.389 albertel 5022: table#LC_browser tr.LC_browser_folder {
5023: background: #CCCCFF;
1.387 albertel 5024: }
1.692.4.2! raeburn 5025:
! 5026: table.LC_data_table tr > td.LC_roles_is {
! 5027: /* background: #77FF77; */
! 5028: }
! 5029: table.LC_data_table tr > td.LC_roles_future {
! 5030: background: #FFFF77;
! 5031: }
! 5032: table.LC_data_table tr > td.LC_roles_will {
! 5033: background: #FFAA77;
! 5034: }
! 5035: table.LC_data_table tr > td.LC_roles_expired {
! 5036: background: #FF7777;
! 5037: }
! 5038: table.LC_data_table tr > td.LC_roles_will_not {
! 5039: background: #AAFF77;
! 5040: }
! 5041: table.LC_data_table tr > td.LC_roles_selected {
! 5042: background: #11CC55;
! 5043: }
! 5044:
1.388 albertel 5045: span.LC_current_location {
5046: font-size: x-large;
5047: background: $pgbg;
5048: }
1.387 albertel 5049:
1.395 albertel 5050: span.LC_parm_menu_item {
5051: font-size: larger;
5052: font-family: $sans;
5053: }
5054: span.LC_parm_scope_all {
5055: color: red;
5056: }
5057: span.LC_parm_scope_folder {
5058: color: green;
5059: }
5060: span.LC_parm_scope_resource {
5061: color: orange;
5062: }
5063: span.LC_parm_part {
5064: color: blue;
5065: }
5066: span.LC_parm_folder, span.LC_parm_symb {
5067: font-size: x-small;
5068: font-family: $mono;
5069: color: #AAAAAA;
5070: }
5071:
1.396 albertel 5072: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
5073: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
5074: border: 1px solid black;
5075: border-collapse: collapse;
5076: }
5077: table.LC_parm_overview_restrictions td {
5078: border-width: 1px 4px 1px 4px;
5079: border-style: solid;
5080: border-color: $pgbg;
5081: text-align: center;
5082: }
5083: table.LC_parm_overview_restrictions th {
5084: background: $tabbg;
5085: border-width: 1px 4px 1px 4px;
5086: border-style: solid;
5087: border-color: $pgbg;
5088: }
1.398 albertel 5089: table#LC_helpmenu {
1.692.4.2! raeburn 5090: border: none;
1.398 albertel 5091: height: 55px;
1.692.4.2! raeburn 5092: border-spacing: 0;
1.398 albertel 5093: }
5094:
5095: table#LC_helpmenu fieldset legend {
5096: font-size: larger;
5097: font-weight: bold;
5098: }
1.397 albertel 5099: table#LC_helpmenu_links {
5100: width: 100%;
5101: border: 1px solid black;
5102: background: $pgbg;
1.692.4.2! raeburn 5103: padding: 0;
1.397 albertel 5104: border-spacing: 1px;
5105: }
5106: table#LC_helpmenu_links tr td {
5107: padding: 1px;
5108: background: $tabbg;
1.399 albertel 5109: text-align: center;
5110: font-weight: bold;
1.397 albertel 5111: }
1.396 albertel 5112:
1.397 albertel 5113: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5114: table#LC_helpmenu_links a:active {
5115: text-decoration: none;
5116: color: $font;
5117: }
5118: table#LC_helpmenu_links a:hover {
5119: text-decoration: underline;
5120: color: $vlink;
5121: }
1.396 albertel 5122:
1.417 albertel 5123: .LC_chrt_popup_exists {
5124: border: 1px solid #339933;
5125: margin: -1px;
5126: }
5127: .LC_chrt_popup_up {
5128: border: 1px solid yellow;
5129: margin: -1px;
5130: }
5131: .LC_chrt_popup {
5132: border: 1px solid #8888FF;
5133: background: #CCCCFF;
5134: }
1.421 albertel 5135: table.LC_pick_box {
5136: border-collapse: separate;
5137: background: white;
5138: border: 1px solid black;
5139: border-spacing: 1px;
5140: }
5141: table.LC_pick_box td.LC_pick_box_title {
5142: background: $tabbg;
5143: font-weight: bold;
5144: text-align: right;
1.692.4.2! raeburn 5145: vertical-align: top;
1.421 albertel 5146: width: 184px;
5147: padding: 8px;
5148: }
1.645 raeburn 5149: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5150: background: $tabbg;
5151: font-weight: bold;
5152: text-align: right;
5153: width: 350px;
5154: padding: 8px;
5155: }
5156:
1.579 raeburn 5157: table.LC_pick_box td.LC_pick_box_value {
5158: text-align: left;
5159: padding: 8px;
5160: }
5161: table.LC_pick_box td.LC_pick_box_select {
5162: text-align: left;
5163: padding: 8px;
5164: }
1.424 albertel 5165: table.LC_pick_box td.LC_pick_box_separator {
1.692.4.2! raeburn 5166: padding: 0;
1.421 albertel 5167: height: 1px;
5168: background: black;
5169: }
5170: table.LC_pick_box td.LC_pick_box_submit {
5171: text-align: right;
5172: }
1.579 raeburn 5173: table.LC_pick_box td.LC_evenrow_value {
5174: text-align: left;
5175: padding: 8px;
5176: background-color: $data_table_light;
5177: }
5178: table.LC_pick_box td.LC_oddrow_value {
5179: text-align: left;
5180: padding: 8px;
5181: background-color: $data_table_light;
5182: }
5183: table.LC_helpform_receipt {
5184: width: 620px;
5185: border-collapse: separate;
5186: background: white;
5187: border: 1px solid black;
5188: border-spacing: 1px;
5189: }
5190: table.LC_helpform_receipt td.LC_pick_box_title {
5191: background: $tabbg;
5192: font-weight: bold;
5193: text-align: right;
5194: width: 184px;
5195: padding: 8px;
5196: }
5197: table.LC_helpform_receipt td.LC_evenrow_value {
5198: text-align: left;
5199: padding: 8px;
5200: background-color: $data_table_light;
5201: }
5202: table.LC_helpform_receipt td.LC_oddrow_value {
5203: text-align: left;
5204: padding: 8px;
5205: background-color: $data_table_light;
5206: }
5207: table.LC_helpform_receipt td.LC_pick_box_separator {
1.692.4.2! raeburn 5208: padding: 0;
1.579 raeburn 5209: height: 1px;
5210: background: black;
5211: }
5212: span.LC_helpform_receipt_cat {
5213: font-weight: bold;
5214: }
1.424 albertel 5215: table.LC_group_priv_box {
5216: background: white;
5217: border: 1px solid black;
5218: border-spacing: 1px;
5219: }
5220: table.LC_group_priv_box td.LC_pick_box_title {
5221: background: $tabbg;
5222: font-weight: bold;
5223: text-align: right;
5224: width: 184px;
5225: }
5226: table.LC_group_priv_box td.LC_groups_fixed {
5227: background: $data_table_light;
5228: text-align: center;
5229: }
5230: table.LC_group_priv_box td.LC_groups_optional {
5231: background: $data_table_dark;
5232: text-align: center;
5233: }
5234: table.LC_group_priv_box td.LC_groups_functionality {
5235: background: $data_table_darker;
5236: text-align: center;
5237: font-weight: bold;
5238: }
5239: table.LC_group_priv td {
5240: text-align: left;
1.692.4.2! raeburn 5241: padding: 0;
1.424 albertel 5242: }
5243:
1.421 albertel 5244: table.LC_notify_front_page {
5245: background: white;
5246: border: 1px solid black;
5247: padding: 8px;
5248: }
5249: table.LC_notify_front_page td {
5250: padding: 8px;
5251: }
1.424 albertel 5252: .LC_navbuttons {
5253: margin: 2ex 0ex 2ex 0ex;
5254: }
1.423 albertel 5255: .LC_topic_bar {
5256: font-family: $sans;
5257: font-weight: bold;
5258: width: 100%;
5259: background: $tabbg;
5260: vertical-align: middle;
5261: margin: 2ex 0ex 2ex 0ex;
1.692.4.2! raeburn 5262: padding: 3px;
1.423 albertel 5263: }
5264: .LC_topic_bar span {
5265: vertical-align: middle;
5266: }
5267: .LC_topic_bar img {
5268: vertical-align: bottom;
5269: }
5270: table.LC_course_group_status {
5271: margin: 20px;
5272: }
5273: table.LC_status_selector td {
5274: vertical-align: top;
5275: text-align: center;
1.424 albertel 5276: padding: 4px;
5277: }
5278: table.LC_descriptive_input td.LC_description {
5279: vertical-align: top;
5280: text-align: right;
5281: font-weight: bold;
1.423 albertel 5282: }
1.599 albertel 5283: div.LC_feedback_link {
1.616 albertel 5284: clear: both;
1.599 albertel 5285: background: white;
5286: width: 100%;
1.489 raeburn 5287: }
5288: span.LC_feedback_link {
1.599 albertel 5289: background: $feedback_link_bg;
5290: font-size: larger;
5291: }
5292: span.LC_message_link {
5293: background: $feedback_link_bg;
5294: font-size: larger;
5295: position: absolute;
5296: right: 1em;
1.489 raeburn 5297: }
1.421 albertel 5298:
1.515 albertel 5299: table.LC_prior_tries {
1.524 albertel 5300: border: 1px solid #000000;
5301: border-collapse: separate;
5302: border-spacing: 1px;
1.515 albertel 5303: }
1.523 albertel 5304:
1.515 albertel 5305: table.LC_prior_tries td {
1.524 albertel 5306: padding: 2px;
1.515 albertel 5307: }
1.523 albertel 5308:
5309: .LC_answer_correct {
5310: background: #AAFFAA;
5311: color: black;
5312: }
5313: .LC_answer_charged_try {
5314: background: #FFAAAA ! important;
5315: color: black;
5316: }
5317: .LC_answer_not_charged_try,
5318: .LC_answer_no_grade,
5319: .LC_answer_late {
5320: background: #FFFFAA;
5321: color: black;
5322: }
5323: .LC_answer_previous {
5324: background: #AAAAFF;
5325: color: black;
5326: }
5327: .LC_answer_no_message {
5328: background: #FFFFFF;
5329: color: black;
5330: }
5331: .LC_answer_unknown {
5332: background: orange;
5333: color: black;
5334: }
5335:
5336:
1.529 albertel 5337: span.LC_prior_numerical,
5338: span.LC_prior_string,
5339: span.LC_prior_custom,
5340: span.LC_prior_reaction,
5341: span.LC_prior_math {
1.523 albertel 5342: font-family: monospace;
5343: white-space: pre;
5344: }
5345:
1.525 albertel 5346: span.LC_prior_string {
5347: font-family: monospace;
5348: white-space: pre;
5349: }
5350:
1.523 albertel 5351: table.LC_prior_option {
5352: width: 100%;
5353: border-collapse: collapse;
5354: }
1.528 albertel 5355: table.LC_prior_rank, table.LC_prior_match {
5356: border-collapse: collapse;
5357: }
5358: table.LC_prior_option tr td,
5359: table.LC_prior_rank tr td,
5360: table.LC_prior_match tr td {
1.524 albertel 5361: border: 1px solid #000000;
1.515 albertel 5362: }
5363:
1.519 raeburn 5364: span.LC_nobreak {
1.544 albertel 5365: white-space: nowrap;
1.519 raeburn 5366: }
5367:
1.576 raeburn 5368: span.LC_cusr_emph {
5369: font-style: italic;
5370: }
5371:
1.633 raeburn 5372: span.LC_cusr_subheading {
5373: font-weight: normal;
5374: font-size: 85%;
5375: }
5376:
1.545 albertel 5377: table.LC_docs_documents {
5378: background: #BBBBBB;
1.692.4.2! raeburn 5379: border-width: 0;
1.545 albertel 5380: border-collapse: collapse;
5381: }
5382:
5383: table.LC_docs_documents td.LC_docs_document {
5384: border: 2px solid black;
5385: padding: 4px;
5386: }
5387:
5388: .LC_docs_course_commands div {
5389: float: left;
5390: border: 4px solid #AAAAAA;
5391: padding: 4px;
5392: background: #DDDDCC;
5393: }
5394:
5395: .LC_docs_entry_move {
1.692.4.2! raeburn 5396: border: none;
1.545 albertel 5397: border-collapse: collapse;
1.544 albertel 5398: }
5399:
1.545 albertel 5400: .LC_docs_entry_move td {
5401: border: 2px solid #BBBBBB;
5402: background: #DDDDDD;
5403: }
5404:
5405: .LC_docs_editor td.LC_docs_entry_commands {
5406: background: #DDDDDD;
5407: font-size: x-small;
5408: }
1.544 albertel 5409: .LC_docs_copy {
1.545 albertel 5410: color: #000099;
1.544 albertel 5411: }
5412: .LC_docs_cut {
1.545 albertel 5413: color: #550044;
1.544 albertel 5414: }
5415: .LC_docs_rename {
1.545 albertel 5416: color: #009900;
1.544 albertel 5417: }
5418: .LC_docs_remove {
1.545 albertel 5419: color: #990000;
5420: }
5421:
1.547 albertel 5422: .LC_docs_reinit_warn,
5423: .LC_docs_ext_edit {
5424: font-size: x-small;
5425: }
5426:
1.545 albertel 5427: .LC_docs_editor td.LC_docs_entry_title,
5428: .LC_docs_editor td.LC_docs_entry_icon {
5429: background: #FFFFBB;
5430: }
5431: .LC_docs_editor td.LC_docs_entry_parameter {
5432: background: #BBBBFF;
5433: font-size: x-small;
5434: white-space: nowrap;
5435: }
5436:
5437: table.LC_docs_adddocs td,
5438: table.LC_docs_adddocs th {
5439: border: 1px solid #BBBBBB;
5440: padding: 4px;
5441: background: #DDDDDD;
1.543 albertel 5442: }
5443:
1.584 albertel 5444: table.LC_sty_begin {
5445: background: #BBFFBB;
5446: }
5447: table.LC_sty_end {
5448: background: #FFBBBB;
5449: }
5450:
1.589 raeburn 5451: table.LC_double_column {
1.692.4.2! raeburn 5452: border-width: 0;
1.589 raeburn 5453: border-collapse: collapse;
5454: width: 100%;
5455: padding: 2px;
5456: }
5457:
5458: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5459: top: 2px;
1.589 raeburn 5460: left: 2px;
5461: width: 47%;
5462: vertical-align: top;
5463: }
5464:
5465: table.LC_double_column tr td.LC_right_col {
5466: top: 2px;
5467: right: 2px;
5468: width: 47%;
5469: vertical-align: top;
5470: }
5471:
1.594 raeburn 5472: span.LC_role_level {
5473: font-weight: bold;
5474: }
5475:
1.591 raeburn 5476: div.LC_left_float {
5477: float: left;
5478: padding-right: 5%;
1.597 albertel 5479: padding-bottom: 4px;
1.591 raeburn 5480: }
5481:
5482: div.LC_clear_float_header {
1.597 albertel 5483: padding-bottom: 2px;
1.591 raeburn 5484: }
5485:
5486: div.LC_clear_float_footer {
1.597 albertel 5487: padding-top: 10px;
1.591 raeburn 5488: clear: both;
5489: }
5490:
1.597 albertel 5491:
1.601 albertel 5492: div.LC_grade_select_mode {
1.604 albertel 5493: font-family: $sans;
1.601 albertel 5494: }
5495: div.LC_grade_select_mode div div {
5496: margin: 5px;
5497: }
5498: div.LC_grade_select_mode_selector {
5499: margin: 5px;
5500: float: left;
5501: }
5502: div.LC_grade_select_mode_selector_header {
5503: font: bold medium $sans;
5504: }
5505: div.LC_grade_select_mode_type {
5506: clear: left;
5507: }
5508:
1.597 albertel 5509: div.LC_grade_show_user {
5510: margin-top: 20px;
5511: border: 1px solid black;
5512: }
5513: div.LC_grade_user_name {
5514: background: #DDDDEE;
5515: border-bottom: 1px solid black;
5516: font: bold large $sans;
5517: }
5518: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5519: background: #DDEEDD;
5520: }
5521:
5522: div.LC_grade_show_problem,
5523: div.LC_grade_submissions,
5524: div.LC_grade_message_center,
5525: div.LC_grade_info_links,
5526: div.LC_grade_assign {
5527: margin: 5px;
5528: width: 99%;
5529: background: #FFFFFF;
5530: }
5531: div.LC_grade_show_problem_header,
5532: div.LC_grade_submissions_header,
5533: div.LC_grade_message_center_header,
5534: div.LC_grade_assign_header {
5535: font: bold large $sans;
5536: }
5537: div.LC_grade_show_problem_problem,
5538: div.LC_grade_submissions_body,
5539: div.LC_grade_message_center_body,
5540: div.LC_grade_assign_body {
5541: border: 1px solid black;
5542: width: 99%;
5543: background: #FFFFFF;
5544: }
1.598 albertel 5545: span.LC_grade_check_note {
5546: font: normal medium $sans;
5547: display: inline;
5548: position: absolute;
5549: right: 1em;
5550: }
1.597 albertel 5551:
1.613 albertel 5552: table.LC_scantron_action {
5553: width: 100%;
5554: }
5555: table.LC_scantron_action tr th {
5556: font: normal bold $sans;
5557: }
1.600 albertel 5558:
1.614 albertel 5559: div.LC_edit_problem_header,
5560: div.LC_edit_problem_footer {
1.600 albertel 5561: font: normal medium $sans;
1.602 albertel 5562: margin: 2px;
1.600 albertel 5563: }
5564: div.LC_edit_problem_header,
1.602 albertel 5565: div.LC_edit_problem_header div,
1.614 albertel 5566: div.LC_edit_problem_footer,
5567: div.LC_edit_problem_footer div,
1.602 albertel 5568: div.LC_edit_problem_editxml_header,
5569: div.LC_edit_problem_editxml_header div {
1.600 albertel 5570: margin-top: 5px;
5571: }
1.602 albertel 5572: div.LC_edit_problem_header_edit_row {
5573: background: $tabbg;
5574: padding: 3px;
5575: margin-bottom: 5px;
5576: }
1.600 albertel 5577: div.LC_edit_problem_header_title {
1.602 albertel 5578: font: larger bold $sans;
5579: background: $tabbg;
5580: padding: 3px;
5581: }
5582: table.LC_edit_problem_header_title {
5583: font: larger bold $sans;
5584: width: 100%;
5585: border-color: $pgbg;
5586: border-style: solid;
5587: border-width: $border;
5588:
1.600 albertel 5589: background: $tabbg;
1.602 albertel 5590: border-collapse: collapse;
1.692.4.2! raeburn 5591: padding: 0;
1.602 albertel 5592: }
5593:
5594: div.LC_edit_problem_discards {
5595: float: left;
5596: padding-bottom: 5px;
5597: }
5598: div.LC_edit_problem_saves {
5599: float: right;
5600: padding-bottom: 5px;
1.600 albertel 5601: }
5602: hr.LC_edit_problem_divide {
1.602 albertel 5603: clear: both;
1.600 albertel 5604: color: $tabbg;
5605: background-color: $tabbg;
5606: height: 3px;
1.692.4.2! raeburn 5607: border: none;
1.600 albertel 5608: }
1.679 riegler 5609: img.stift{
1.678 riegler 5610: border-width:0;
1.679 riegler 5611: vertical-align:middle;
1.677 riegler 5612: }
1.680 riegler 5613:
1.681 riegler 5614: table#LC_mainmenu{
5615: margin-top:10px;
5616: width:80%;
5617:
5618: }
5619:
1.680 riegler 5620: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5621: vertical-align: top;
5622: width: 45%;
5623: }
5624: .LC_mainmenu_fieldset_category {
5625: color: $font;
5626: background: $pgbg;
5627: font-family: $sans;
5628: font-size: small;
5629: font-weight: bold;
5630: }
5631: fieldset#LC_mainmenu_fieldset {
1.692.4.2! raeburn 5632: margin:0 10px 10px 0;
! 5633:
! 5634: }
1.680 riegler 5635:
1.692.4.2! raeburn 5636: div.LC_createcourse {
! 5637: margin: 10px 10px 10px 10px;
1.680 riegler 5638: }
1.692.4.2! raeburn 5639:
1.343 albertel 5640: END
5641: }
5642:
1.306 albertel 5643: =pod
5644:
5645: =item * &headtag()
5646:
5647: Returns a uniform footer for LON-CAPA web pages.
5648:
1.307 albertel 5649: Inputs: $title - optional title for the head
5650: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5651: $args - optional arguments
1.319 albertel 5652: force_register - if is true call registerurl so the remote is
5653: informed
1.415 albertel 5654: redirect -> array ref of
5655: 1- seconds before redirect occurs
5656: 2- url to redirect to
5657: 3- whether the side effect should occur
1.315 albertel 5658: (side effect of setting
5659: $env{'internal.head.redirect'} to the url
5660: redirected too)
1.352 albertel 5661: domain -> force to color decorate a page for a specific
5662: domain
5663: function -> force usage of a specific rolish color scheme
5664: bgcolor -> override the default page bgcolor
1.460 albertel 5665: no_auto_mt_title
5666: -> prevent &mt()ing the title arg
1.464 albertel 5667:
1.306 albertel 5668: =cut
5669:
5670: sub headtag {
1.313 albertel 5671: my ($title,$head_extra,$args) = @_;
1.306 albertel 5672:
1.363 albertel 5673: my $function = $args->{'function'} || &get_users_function();
5674: my $domain = $args->{'domain'} || &determinedomain();
5675: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5676: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5677: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5678: #time(),
1.418 albertel 5679: $env{'environment.color.timestamp'},
1.363 albertel 5680: $function,$domain,$bgcolor);
5681:
1.369 www 5682: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5683:
1.308 albertel 5684: my $result =
5685: '<head>'.
1.461 albertel 5686: &font_settings();
1.319 albertel 5687:
1.461 albertel 5688: if (!$args->{'frameset'}) {
5689: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5690: }
1.319 albertel 5691: if ($args->{'force_register'}) {
5692: $result .= &Apache::lonmenu::registerurl(1);
5693: }
1.436 albertel 5694: if (!$args->{'no_nav_bar'}
5695: && !$args->{'only_body'}
5696: && !$args->{'frameset'}) {
5697: $result .= &help_menu_js();
5698: }
1.319 albertel 5699:
1.314 albertel 5700: if (ref($args->{'redirect'})) {
1.414 albertel 5701: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5702: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5703: if (!$inhibit_continue) {
5704: $env{'internal.head.redirect'} = $url;
5705: }
1.313 albertel 5706: $result.=<<ADDMETA
5707: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5708: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5709: ADDMETA
5710: }
1.306 albertel 5711: if (!defined($title)) {
5712: $title = 'The LearningOnline Network with CAPA';
5713: }
1.460 albertel 5714: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5715: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5716: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5717: .$head_extra;
1.306 albertel 5718: return $result;
5719: }
5720:
5721: =pod
5722:
1.340 albertel 5723: =item * &font_settings()
5724:
5725: Returns neccessary <meta> to set the proper encoding
5726:
5727: Inputs: none
5728:
5729: =cut
5730:
5731: sub font_settings {
5732: my $headerstring='';
1.647 www 5733: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5734: $headerstring.=
5735: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5736: }
5737: return $headerstring;
5738: }
5739:
1.341 albertel 5740: =pod
5741:
5742: =item * &xml_begin()
5743:
5744: Returns the needed doctype and <html>
5745:
5746: Inputs: none
5747:
5748: =cut
5749:
5750: sub xml_begin {
5751: my $output='';
5752:
1.592 albertel 5753: if ($env{'internal.start_page'}==1) {
5754: &Apache::lonhtmlcommon::init_htmlareafields();
5755: }
1.342 albertel 5756:
1.341 albertel 5757: if ($env{'browser.mathml'}) {
5758: $output='<?xml version="1.0"?>'
5759: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5760: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5761:
5762: # .'<!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">] >'
5763: .'<!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">'
5764: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5765: .'xmlns="http://www.w3.org/1999/xhtml">';
5766: } else {
5767: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5768: }
5769: return $output;
5770: }
1.340 albertel 5771:
5772: =pod
5773:
1.306 albertel 5774: =item * &endheadtag()
5775:
5776: Returns a uniform </head> for LON-CAPA web pages.
5777:
5778: Inputs: none
5779:
5780: =cut
5781:
5782: sub endheadtag {
5783: return '</head>';
5784: }
5785:
5786: =pod
5787:
5788: =item * &head()
5789:
5790: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5791:
1.648 raeburn 5792: Inputs:
5793:
5794: =over 4
5795:
5796: $title - optional title for the page
5797:
5798: $head_extra - optional extra HTML to put inside the <head>
5799:
5800: =back
1.405 albertel 5801:
1.306 albertel 5802: =cut
5803:
5804: sub head {
1.325 albertel 5805: my ($title,$head_extra,$args) = @_;
5806: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 5807: }
5808:
5809: =pod
5810:
5811: =item * &start_page()
5812:
5813: Returns a complete <html> .. <body> section for LON-CAPA web pages.
5814:
1.648 raeburn 5815: Inputs:
5816:
5817: =over 4
5818:
5819: $title - optional title for the page
5820:
5821: $head_extra - optional extra HTML to incude inside the <head>
5822:
5823: $args - additional optional args supported are:
5824:
5825: =over 8
5826:
5827: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 5828: arg on
1.648 raeburn 5829: no_nav_bar -> is true will set &bodytag() notopbar arg on
5830: add_entries -> additional attributes to add to the <body>
5831: domain -> force to color decorate a page for a
1.317 albertel 5832: specific domain
1.648 raeburn 5833: function -> force usage of a specific rolish color
1.317 albertel 5834: scheme
1.648 raeburn 5835: redirect -> see &headtag()
5836: bgcolor -> override the default page bg color
5837: js_ready -> return a string ready for being used in
1.317 albertel 5838: a javascript writeln
1.648 raeburn 5839: html_encode -> return a string ready for being used in
1.320 albertel 5840: a html attribute
1.648 raeburn 5841: force_register -> if is true will turn on the &bodytag()
1.317 albertel 5842: $forcereg arg
1.648 raeburn 5843: body_title -> alternate text to use instead of $title
1.326 albertel 5844: in the title box that appears, this text
5845: is not auto translated like the $title is
1.648 raeburn 5846: frameset -> if true will start with a <frameset>
1.330 albertel 5847: rather than <body>
1.648 raeburn 5848: no_title -> if true the title bar won't be shown
5849: skip_phases -> hash ref of
1.338 albertel 5850: head -> skip the <html><head> generation
5851: body -> skip all <body> generation
1.648 raeburn 5852: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 5853: 'Switch To Inline Menu' link
1.648 raeburn 5854: no_auto_mt_title -> prevent &mt()ing the title arg
5855: inherit_jsmath -> when creating popup window in a page,
5856: should it have jsmath forced on by the
5857: current page
1.361 albertel 5858:
1.648 raeburn 5859: =back
1.460 albertel 5860:
1.648 raeburn 5861: =back
1.562 albertel 5862:
1.306 albertel 5863: =cut
5864:
5865: sub start_page {
1.309 albertel 5866: my ($title,$head_extra,$args) = @_;
1.318 albertel 5867: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 5868: my %head_args;
1.352 albertel 5869: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 5870: 'bgcolor','frameset','no_nav_bar','only_body',
5871: 'no_auto_mt_title') {
1.319 albertel 5872: if (defined($args->{$arg})) {
1.324 raeburn 5873: $head_args{$arg} = $args->{$arg};
1.319 albertel 5874: }
1.313 albertel 5875: }
1.319 albertel 5876:
1.315 albertel 5877: $env{'internal.start_page'}++;
1.338 albertel 5878: my $result;
5879: if (! exists($args->{'skip_phases'}{'head'}) ) {
5880: $result.=
1.341 albertel 5881: &xml_begin().
1.338 albertel 5882: &headtag($title,$head_extra,\%head_args).&endheadtag();
5883: }
5884:
5885: if (! exists($args->{'skip_phases'}{'body'}) ) {
5886: if ($args->{'frameset'}) {
5887: my $attr_string = &make_attr_string($args->{'force_register'},
5888: $args->{'add_entries'});
5889: $result .= "\n<frameset $attr_string>\n";
5890: } else {
5891: $result .=
5892: &bodytag($title,
5893: $args->{'function'}, $args->{'add_entries'},
5894: $args->{'only_body'}, $args->{'domain'},
5895: $args->{'force_register'}, $args->{'body_title'},
5896: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 5897: $args->{'no_title'}, $args->{'no_inline_link'},
5898: $args);
1.338 albertel 5899: }
1.330 albertel 5900: }
1.338 albertel 5901:
1.315 albertel 5902: if ($args->{'js_ready'}) {
1.317 albertel 5903: $result = &js_ready($result);
1.315 albertel 5904: }
1.320 albertel 5905: if ($args->{'html_encode'}) {
5906: $result = &html_encode($result);
5907: }
1.692.4.2! raeburn 5908: #Breadcrumbs
! 5909: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
! 5910: &Apache::lonhtmlcommon::clear_breadcrumbs();
! 5911: #if any br links exists, add them to the breadcrumbs
! 5912: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
! 5913: foreach my $crumb (@{$args->{'bread_crumbs'}}){
! 5914: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
! 5915: }
! 5916: }
1.306 albertel 5917:
1.692.4.2! raeburn 5918: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
! 5919: if (exists($args->{'bread_crumbs_component'})){
! 5920: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
! 5921: } else {
! 5922: $result .= &Apache::lonhtmlcommon::breadcrumbs();
! 5923: }
! 5924: }
! 5925: return $result;
1.330 albertel 5926:
1.306 albertel 5927: =pod
5928:
5929: =item * &head()
5930:
5931: Returns a complete </body></html> section for LON-CAPA web pages.
5932:
1.315 albertel 5933: Inputs: $args - additional optional args supported are:
5934: js_ready -> return a string ready for being used in
5935: a javascript writeln
1.320 albertel 5936: html_encode -> return a string ready for being used in
5937: a html attribute
1.330 albertel 5938: frameset -> if true will start with a <frameset>
5939: rather than <body>
1.493 albertel 5940: dicsussion -> if true will get discussion from
5941: lonxml::xmlend
5942: (you can pass the target and parser arguments
5943: through optional 'target' and 'parser' args
5944: to this routine)
1.306 albertel 5945:
5946: =cut
5947:
5948: sub end_page {
1.315 albertel 5949: my ($args) = @_;
5950: $env{'internal.end_page'}++;
1.330 albertel 5951: my $result;
1.335 albertel 5952: if ($args->{'discussion'}) {
5953: my ($target,$parser);
5954: if (ref($args->{'discussion'})) {
5955: ($target,$parser) =($args->{'discussion'}{'target'},
5956: $args->{'discussion'}{'parser'});
5957: }
5958: $result .= &Apache::lonxml::xmlend($target,$parser);
5959: }
5960:
1.330 albertel 5961: if ($args->{'frameset'}) {
5962: $result .= '</frameset>';
5963: } else {
1.635 raeburn 5964: $result .= &endbodytag($args);
1.330 albertel 5965: }
5966: $result .= "\n</html>";
5967:
1.315 albertel 5968: if ($args->{'js_ready'}) {
1.317 albertel 5969: $result = &js_ready($result);
1.315 albertel 5970: }
1.335 albertel 5971:
1.320 albertel 5972: if ($args->{'html_encode'}) {
5973: $result = &html_encode($result);
5974: }
1.335 albertel 5975:
1.315 albertel 5976: return $result;
5977: }
5978:
1.320 albertel 5979: sub html_encode {
5980: my ($result) = @_;
5981:
1.322 albertel 5982: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 5983:
5984: return $result;
5985: }
1.317 albertel 5986: sub js_ready {
5987: my ($result) = @_;
5988:
1.323 albertel 5989: $result =~ s/[\n\r]/ /xmsg;
5990: $result =~ s/\\/\\\\/xmsg;
5991: $result =~ s/'/\\'/xmsg;
1.372 albertel 5992: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 5993:
5994: return $result;
5995: }
5996:
1.315 albertel 5997: sub validate_page {
5998: if ( exists($env{'internal.start_page'})
1.316 albertel 5999: && $env{'internal.start_page'} > 1) {
6000: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6001: $env{'internal.start_page'}.' '.
1.316 albertel 6002: $ENV{'request.filename'});
1.315 albertel 6003: }
6004: if ( exists($env{'internal.end_page'})
1.316 albertel 6005: && $env{'internal.end_page'} > 1) {
6006: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6007: $env{'internal.end_page'}.' '.
1.316 albertel 6008: $env{'request.filename'});
1.315 albertel 6009: }
6010: if ( exists($env{'internal.start_page'})
6011: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6012: &Apache::lonnet::logthis('start_page called without end_page '.
6013: $env{'request.filename'});
1.315 albertel 6014: }
6015: if ( ! exists($env{'internal.start_page'})
6016: && exists($env{'internal.end_page'})) {
1.316 albertel 6017: &Apache::lonnet::logthis('end_page called without start_page'.
6018: $env{'request.filename'});
1.315 albertel 6019: }
1.306 albertel 6020: }
1.315 albertel 6021:
1.318 albertel 6022: sub simple_error_page {
6023: my ($r,$title,$msg) = @_;
6024: my $page =
6025: &Apache::loncommon::start_page($title).
6026: &mt($msg).
6027: &Apache::loncommon::end_page();
6028: if (ref($r)) {
6029: $r->print($page);
1.327 albertel 6030: return;
1.318 albertel 6031: }
6032: return $page;
6033: }
1.347 albertel 6034:
6035: {
1.610 albertel 6036: my @row_count;
1.347 albertel 6037: sub start_data_table {
1.422 albertel 6038: my ($add_class) = @_;
6039: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6040: unshift(@row_count,0);
1.422 albertel 6041: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6042: }
6043:
6044: sub end_data_table {
1.610 albertel 6045: shift(@row_count);
1.389 albertel 6046: return '</table>'."\n";;
1.347 albertel 6047: }
6048:
6049: sub start_data_table_row {
1.422 albertel 6050: my ($add_class) = @_;
1.610 albertel 6051: $row_count[0]++;
6052: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6053: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6054: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6055: }
1.471 banghart 6056:
6057: sub continue_data_table_row {
6058: my ($add_class) = @_;
1.610 albertel 6059: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6060: $css_class = (join(' ',$css_class,$add_class));
6061: return '<tr class="'.$css_class.'">'."\n";;
6062: }
1.347 albertel 6063:
6064: sub end_data_table_row {
1.389 albertel 6065: return '</tr>'."\n";;
1.347 albertel 6066: }
1.367 www 6067:
1.421 albertel 6068: sub start_data_table_empty_row {
1.610 albertel 6069: $row_count[0]++;
1.421 albertel 6070: return '<tr class="LC_empty_row" >'."\n";;
6071: }
6072:
6073: sub end_data_table_empty_row {
6074: return '</tr>'."\n";;
6075: }
6076:
1.367 www 6077: sub start_data_table_header_row {
1.389 albertel 6078: return '<tr class="LC_header_row">'."\n";;
1.367 www 6079: }
6080:
6081: sub end_data_table_header_row {
1.389 albertel 6082: return '</tr>'."\n";;
1.367 www 6083: }
1.347 albertel 6084: }
6085:
1.548 albertel 6086: =pod
6087:
6088: =item * &inhibit_menu_check($arg)
6089:
6090: Checks for a inhibitmenu state and generates output to preserve it
6091:
6092: Inputs: $arg - can be any of
6093: - undef - in which case the return value is a string
6094: to add into arguments list of a uri
6095: - 'input' - in which case the return value is a HTML
6096: <form> <input> field of type hidden to
6097: preserve the value
6098: - a url - in which case the return value is the url with
6099: the neccesary cgi args added to preserve the
6100: inhibitmenu state
6101: - a ref to a url - no return value, but the string is
6102: updated to include the neccessary cgi
6103: args to preserve the inhibitmenu state
6104:
6105: =cut
6106:
6107: sub inhibit_menu_check {
6108: my ($arg) = @_;
6109: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6110: if ($arg eq 'input') {
6111: if ($env{'form.inhibitmenu'}) {
6112: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6113: } else {
6114: return
6115: }
6116: }
6117: if ($env{'form.inhibitmenu'}) {
6118: if (ref($arg)) {
6119: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6120: } elsif ($arg eq '') {
6121: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6122: } else {
6123: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6124: }
6125: }
6126: if (!ref($arg)) {
6127: return $arg;
6128: }
6129: }
6130:
1.251 albertel 6131: ###############################################
1.182 matthew 6132:
6133: =pod
6134:
1.549 albertel 6135: =back
6136:
6137: =head1 User Information Routines
6138:
6139: =over 4
6140:
1.405 albertel 6141: =item * &get_users_function()
1.182 matthew 6142:
6143: Used by &bodytag to determine the current users primary role.
6144: Returns either 'student','coordinator','admin', or 'author'.
6145:
6146: =cut
6147:
6148: ###############################################
6149: sub get_users_function {
6150: my $function = 'student';
1.258 albertel 6151: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6152: $function='coordinator';
6153: }
1.258 albertel 6154: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6155: $function='admin';
6156: }
1.258 albertel 6157: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6158: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6159: $function='author';
6160: }
6161: return $function;
1.54 www 6162: }
1.99 www 6163:
6164: ###############################################
6165:
1.233 raeburn 6166: =pod
6167:
1.692.4.2! raeburn 6168: =item * &show_course()
! 6169:
! 6170: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
! 6171: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
! 6172: Inputs:
! 6173: None
! 6174:
! 6175: Outputs:
! 6176: Scalar: 1 if 'Course' to be used, 0 otherwise.
! 6177:
! 6178: =cut
! 6179:
! 6180: ###############################################
! 6181: sub show_course {
! 6182: my $course = !$env{'user.adv'};
! 6183: if (!$env{'user.adv'}) {
! 6184: foreach my $env (keys(%env)) {
! 6185: next if ($env !~ m/^user\.priv\./);
! 6186: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
! 6187: $course = 0;
! 6188: last;
! 6189: }
! 6190: }
! 6191: }
! 6192: return $course;
! 6193: }
! 6194:
! 6195: ###############################################
! 6196:
! 6197: =pod
! 6198:
1.542 raeburn 6199: =item * &check_user_status()
1.274 raeburn 6200:
6201: Determines current status of supplied role for a
6202: specific user. Roles can be active, previous or future.
6203:
6204: Inputs:
6205: user's domain, user's username, course's domain,
1.375 raeburn 6206: course's number, optional section ID.
1.274 raeburn 6207:
6208: Outputs:
6209: role status: active, previous or future.
6210:
6211: =cut
6212:
6213: sub check_user_status {
1.412 raeburn 6214: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6215: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6216: my @uroles = keys %userinfo;
6217: my $srchstr;
6218: my $active_chk = 'none';
1.412 raeburn 6219: my $now = time;
1.274 raeburn 6220: if (@uroles > 0) {
1.412 raeburn 6221: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6222: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6223: } else {
1.412 raeburn 6224: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6225: }
6226: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6227: my $role_end = 0;
6228: my $role_start = 0;
6229: $active_chk = 'active';
1.412 raeburn 6230: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6231: $role_end = $1;
6232: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6233: $role_start = $1;
1.274 raeburn 6234: }
6235: }
6236: if ($role_start > 0) {
1.412 raeburn 6237: if ($now < $role_start) {
1.274 raeburn 6238: $active_chk = 'future';
6239: }
6240: }
6241: if ($role_end > 0) {
1.412 raeburn 6242: if ($now > $role_end) {
1.274 raeburn 6243: $active_chk = 'previous';
6244: }
6245: }
6246: }
6247: }
6248: return $active_chk;
6249: }
6250:
6251: ###############################################
6252:
6253: =pod
6254:
1.405 albertel 6255: =item * &get_sections()
1.233 raeburn 6256:
6257: Determines all the sections for a course including
6258: sections with students and sections containing other roles.
1.419 raeburn 6259: Incoming parameters:
6260:
6261: 1. domain
6262: 2. course number
6263: 3. reference to array containing roles for which sections should
6264: be gathered (optional).
6265: 4. reference to array containing status types for which sections
6266: should be gathered (optional).
6267:
6268: If the third argument is undefined, sections are gathered for any role.
6269: If the fourth argument is undefined, sections are gathered for any status.
6270: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6271:
1.374 raeburn 6272: Returns section hash (keys are section IDs, values are
6273: number of users in each section), subject to the
1.419 raeburn 6274: optional roles filter, optional status filter
1.233 raeburn 6275:
6276: =cut
6277:
6278: ###############################################
6279: sub get_sections {
1.419 raeburn 6280: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6281: if (!defined($cdom) || !defined($cnum)) {
6282: my $cid = $env{'request.course.id'};
6283:
6284: return if (!defined($cid));
6285:
6286: $cdom = $env{'course.'.$cid.'.domain'};
6287: $cnum = $env{'course.'.$cid.'.num'};
6288: }
6289:
6290: my %sectioncount;
1.419 raeburn 6291: my $now = time;
1.240 albertel 6292:
1.366 albertel 6293: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6294: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6295: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6296: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6297: my $start_index = &Apache::loncoursedata::CL_START();
6298: my $end_index = &Apache::loncoursedata::CL_END();
6299: my $status;
1.366 albertel 6300: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6301: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6302: $data->[$status_index],
6303: $data->[$start_index],
6304: $data->[$end_index]);
6305: if ($stu_status eq 'Active') {
6306: $status = 'active';
6307: } elsif ($end < $now) {
6308: $status = 'previous';
6309: } elsif ($start > $now) {
6310: $status = 'future';
6311: }
6312: if ($section ne '-1' && $section !~ /^\s*$/) {
6313: if ((!defined($possible_status)) || (($status ne '') &&
6314: (grep/^\Q$status\E$/,@{$possible_status}))) {
6315: $sectioncount{$section}++;
6316: }
1.240 albertel 6317: }
6318: }
6319: }
6320: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6321: foreach my $user (sort(keys(%courseroles))) {
6322: if ($user !~ /^(\w{2})/) { next; }
6323: my ($role) = ($user =~ /^(\w{2})/);
6324: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6325: my ($section,$status);
1.240 albertel 6326: if ($role eq 'cr' &&
6327: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6328: $section=$1;
6329: }
6330: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6331: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6332: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6333: if ($end == -1 && $start == -1) {
6334: next; #deleted role
6335: }
6336: if (!defined($possible_status)) {
6337: $sectioncount{$section}++;
6338: } else {
6339: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6340: $status = 'active';
6341: } elsif ($end < $now) {
6342: $status = 'future';
6343: } elsif ($start > $now) {
6344: $status = 'previous';
6345: }
6346: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6347: $sectioncount{$section}++;
6348: }
6349: }
1.233 raeburn 6350: }
1.366 albertel 6351: return %sectioncount;
1.233 raeburn 6352: }
6353:
1.274 raeburn 6354: ###############################################
1.294 raeburn 6355:
6356: =pod
1.405 albertel 6357:
6358: =item * &get_course_users()
6359:
1.275 raeburn 6360: Retrieves usernames:domains for users in the specified course
6361: with specific role(s), and access status.
6362:
6363: Incoming parameters:
1.277 albertel 6364: 1. course domain
6365: 2. course number
6366: 3. access status: users must have - either active,
1.275 raeburn 6367: previous, future, or all.
1.277 albertel 6368: 4. reference to array of permissible roles
1.288 raeburn 6369: 5. reference to array of section restrictions (optional)
6370: 6. reference to results object (hash of hashes).
6371: 7. reference to optional userdata hash
1.609 raeburn 6372: 8. reference to optional statushash
1.630 raeburn 6373: 9. flag if privileged users (except those set to unhide in
6374: course settings) should be excluded
1.609 raeburn 6375: Keys of top level results hash are roles.
1.275 raeburn 6376: Keys of inner hashes are username:domain, with
6377: values set to access type.
1.288 raeburn 6378: Optional userdata hash returns an array with arguments in the
6379: same order as loncoursedata::get_classlist() for student data.
6380:
1.609 raeburn 6381: Optional statushash returns
6382:
1.288 raeburn 6383: Entries for end, start, section and status are blank because
6384: of the possibility of multiple values for non-student roles.
6385:
1.275 raeburn 6386: =cut
1.405 albertel 6387:
1.275 raeburn 6388: ###############################################
1.405 albertel 6389:
1.275 raeburn 6390: sub get_course_users {
1.630 raeburn 6391: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6392: my %idx = ();
1.419 raeburn 6393: my %seclists;
1.288 raeburn 6394:
6395: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6396: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6397: $idx{end} = &Apache::loncoursedata::CL_END();
6398: $idx{start} = &Apache::loncoursedata::CL_START();
6399: $idx{id} = &Apache::loncoursedata::CL_ID();
6400: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6401: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6402: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6403:
1.290 albertel 6404: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6405: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6406: my $now = time;
1.277 albertel 6407: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6408: my $match = 0;
1.412 raeburn 6409: my $secmatch = 0;
1.419 raeburn 6410: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6411: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6412: if ($section eq '') {
6413: $section = 'none';
6414: }
1.291 albertel 6415: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6416: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6417: $secmatch = 1;
6418: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6419: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6420: $secmatch = 1;
6421: }
6422: } else {
1.419 raeburn 6423: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6424: $secmatch = 1;
6425: }
1.290 albertel 6426: }
1.412 raeburn 6427: if (!$secmatch) {
6428: next;
6429: }
1.419 raeburn 6430: }
1.275 raeburn 6431: if (defined($$types{'active'})) {
1.288 raeburn 6432: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6433: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6434: $match = 1;
1.275 raeburn 6435: }
6436: }
6437: if (defined($$types{'previous'})) {
1.609 raeburn 6438: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6439: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6440: $match = 1;
1.275 raeburn 6441: }
6442: }
6443: if (defined($$types{'future'})) {
1.609 raeburn 6444: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6445: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6446: $match = 1;
1.275 raeburn 6447: }
6448: }
1.609 raeburn 6449: if ($match) {
6450: push(@{$seclists{$student}},$section);
6451: if (ref($userdata) eq 'HASH') {
6452: $$userdata{$student} = $$classlist{$student};
6453: }
6454: if (ref($statushash) eq 'HASH') {
6455: $statushash->{$student}{'st'}{$section} = $status;
6456: }
1.288 raeburn 6457: }
1.275 raeburn 6458: }
6459: }
1.412 raeburn 6460: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6461: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6462: my $now = time;
1.609 raeburn 6463: my %displaystatus = ( previous => 'Expired',
6464: active => 'Active',
6465: future => 'Future',
6466: );
1.630 raeburn 6467: my %nothide;
6468: if ($hidepriv) {
6469: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6470: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6471: if ($user !~ /:/) {
6472: $nothide{join(':',split(/[\@]/,$user))}=1;
6473: } else {
6474: $nothide{$user} = 1;
6475: }
6476: }
6477: }
1.439 raeburn 6478: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6479: my $match = 0;
1.412 raeburn 6480: my $secmatch = 0;
1.439 raeburn 6481: my $status;
1.412 raeburn 6482: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6483: $user =~ s/:$//;
1.439 raeburn 6484: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6485: if ($end == -1 || $start == -1) {
6486: next;
6487: }
6488: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6489: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6490: my ($uname,$udom) = split(/:/,$user);
6491: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6492: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6493: $secmatch = 1;
6494: } elsif ($usec eq '') {
1.420 albertel 6495: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6496: $secmatch = 1;
6497: }
6498: } else {
6499: if (grep(/^\Q$usec\E$/,@{$sections})) {
6500: $secmatch = 1;
6501: }
6502: }
6503: if (!$secmatch) {
6504: next;
6505: }
1.288 raeburn 6506: }
1.419 raeburn 6507: if ($usec eq '') {
6508: $usec = 'none';
6509: }
1.275 raeburn 6510: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6511: if ($hidepriv) {
6512: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6513: (!$nothide{$uname.':'.$udom})) {
6514: next;
6515: }
6516: }
1.503 raeburn 6517: if ($end > 0 && $end < $now) {
1.439 raeburn 6518: $status = 'previous';
6519: } elsif ($start > $now) {
6520: $status = 'future';
6521: } else {
6522: $status = 'active';
6523: }
1.277 albertel 6524: foreach my $type (keys(%{$types})) {
1.275 raeburn 6525: if ($status eq $type) {
1.420 albertel 6526: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6527: push(@{$$users{$role}{$user}},$type);
6528: }
1.288 raeburn 6529: $match = 1;
6530: }
6531: }
1.419 raeburn 6532: if (($match) && (ref($userdata) eq 'HASH')) {
6533: if (!exists($$userdata{$uname.':'.$udom})) {
6534: &get_user_info($udom,$uname,\%idx,$userdata);
6535: }
1.420 albertel 6536: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6537: push(@{$seclists{$uname.':'.$udom}},$usec);
6538: }
1.609 raeburn 6539: if (ref($statushash) eq 'HASH') {
6540: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6541: }
1.275 raeburn 6542: }
6543: }
6544: }
6545: }
1.290 albertel 6546: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6547: if ((defined($cdom)) && (defined($cnum))) {
6548: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6549: if ( defined($csettings{'internal.courseowner'}) ) {
6550: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6551: next if ($owner eq '');
6552: my ($ownername,$ownerdom);
6553: if ($owner =~ /^([^:]+):([^:]+)$/) {
6554: $ownername = $1;
6555: $ownerdom = $2;
6556: } else {
6557: $ownername = $owner;
6558: $ownerdom = $cdom;
6559: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6560: }
6561: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6562: if (defined($userdata) &&
1.609 raeburn 6563: !exists($$userdata{$owner})) {
6564: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6565: if (!grep(/^none$/,@{$seclists{$owner}})) {
6566: push(@{$seclists{$owner}},'none');
6567: }
6568: if (ref($statushash) eq 'HASH') {
6569: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6570: }
1.290 albertel 6571: }
1.279 raeburn 6572: }
6573: }
6574: }
1.419 raeburn 6575: foreach my $user (keys(%seclists)) {
6576: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6577: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6578: }
1.275 raeburn 6579: }
6580: return;
6581: }
6582:
1.288 raeburn 6583: sub get_user_info {
6584: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6585: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6586: &plainname($uname,$udom,'lastname');
1.291 albertel 6587: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6588: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6589: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6590: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6591: return;
6592: }
1.275 raeburn 6593:
1.472 raeburn 6594: ###############################################
6595:
6596: =pod
6597:
6598: =item * &get_user_quota()
6599:
6600: Retrieves quota assigned for storage of portfolio files for a user
6601:
6602: Incoming parameters:
6603: 1. user's username
6604: 2. user's domain
6605:
6606: Returns:
1.536 raeburn 6607: 1. Disk quota (in Mb) assigned to student.
6608: 2. (Optional) Type of setting: custom or default
6609: (individually assigned or default for user's
6610: institutional status).
6611: 3. (Optional) - User's institutional status (e.g., faculty, staff
6612: or student - types as defined in localenroll::inst_usertypes
6613: for user's domain, which determines default quota for user.
6614: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6615:
6616: If a value has been stored in the user's environment,
1.536 raeburn 6617: it will return that, otherwise it returns the maximal default
6618: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6619:
6620: =cut
6621:
6622: ###############################################
6623:
6624:
6625: sub get_user_quota {
6626: my ($uname,$udom) = @_;
1.536 raeburn 6627: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6628: if (!defined($udom)) {
6629: $udom = $env{'user.domain'};
6630: }
6631: if (!defined($uname)) {
6632: $uname = $env{'user.name'};
6633: }
6634: if (($udom eq '' || $uname eq '') ||
6635: ($udom eq 'public') && ($uname eq 'public')) {
6636: $quota = 0;
1.536 raeburn 6637: $quotatype = 'default';
6638: $defquota = 0;
1.472 raeburn 6639: } else {
1.536 raeburn 6640: my $inststatus;
1.472 raeburn 6641: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6642: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6643: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6644: } else {
1.536 raeburn 6645: my %userenv =
6646: &Apache::lonnet::get('environment',['portfolioquota',
6647: 'inststatus'],$udom,$uname);
1.472 raeburn 6648: my ($tmp) = keys(%userenv);
6649: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6650: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6651: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6652: } else {
6653: undef(%userenv);
6654: }
6655: }
1.536 raeburn 6656: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6657: if ($quota eq '') {
1.536 raeburn 6658: $quota = $defquota;
6659: $quotatype = 'default';
6660: } else {
6661: $quotatype = 'custom';
1.472 raeburn 6662: }
6663: }
1.536 raeburn 6664: if (wantarray) {
6665: return ($quota,$quotatype,$settingstatus,$defquota);
6666: } else {
6667: return $quota;
6668: }
1.472 raeburn 6669: }
6670:
6671: ###############################################
6672:
6673: =pod
6674:
6675: =item * &default_quota()
6676:
1.536 raeburn 6677: Retrieves default quota assigned for storage of user portfolio files,
6678: given an (optional) user's institutional status.
1.472 raeburn 6679:
6680: Incoming parameters:
6681: 1. domain
1.536 raeburn 6682: 2. (Optional) institutional status(es). This is a : separated list of
6683: status types (e.g., faculty, staff, student etc.)
6684: which apply to the user for whom the default is being retrieved.
6685: If the institutional status string in undefined, the domain
6686: default quota will be returned.
1.472 raeburn 6687:
6688: Returns:
6689: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6690: 2. (Optional) institutional type which determined the value of the
6691: default quota.
1.472 raeburn 6692:
6693: If a value has been stored in the domain's configuration db,
6694: it will return that, otherwise it returns 20 (for backwards
6695: compatibility with domains which have not set up a configuration
6696: db file; the original statically defined portfolio quota was 20 Mb).
6697:
1.536 raeburn 6698: If the user's status includes multiple types (e.g., staff and student),
6699: the largest default quota which applies to the user determines the
6700: default quota returned.
6701:
1.472 raeburn 6702: =cut
6703:
6704: ###############################################
6705:
6706:
6707: sub default_quota {
1.536 raeburn 6708: my ($udom,$inststatus) = @_;
6709: my ($defquota,$settingstatus);
6710: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6711: ['quotas'],$udom);
6712: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6713: if ($inststatus ne '') {
1.692.4.2! raeburn 6714: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 6715: foreach my $item (@statuses) {
1.692.4.2! raeburn 6716: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
! 6717: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
! 6718: if ($defquota eq '') {
! 6719: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
! 6720: $settingstatus = $item;
! 6721: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
! 6722: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
! 6723: $settingstatus = $item;
! 6724: }
! 6725: }
! 6726: } else {
! 6727: if ($quotahash{'quotas'}{$item} ne '') {
! 6728: if ($defquota eq '') {
! 6729: $defquota = $quotahash{'quotas'}{$item};
! 6730: $settingstatus = $item;
! 6731: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
! 6732: $defquota = $quotahash{'quotas'}{$item};
! 6733: $settingstatus = $item;
! 6734: }
1.536 raeburn 6735: }
6736: }
6737: }
6738: }
6739: if ($defquota eq '') {
1.692.4.2! raeburn 6740: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
! 6741: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
! 6742: } else {
! 6743: $defquota = $quotahash{'quotas'}{'default'};
! 6744: }
1.536 raeburn 6745: $settingstatus = 'default';
6746: }
6747: } else {
6748: $settingstatus = 'default';
6749: $defquota = 20;
6750: }
6751: if (wantarray) {
6752: return ($defquota,$settingstatus);
1.472 raeburn 6753: } else {
1.536 raeburn 6754: return $defquota;
1.472 raeburn 6755: }
6756: }
6757:
1.384 raeburn 6758: sub get_secgrprole_info {
6759: my ($cdom,$cnum,$needroles,$type) = @_;
6760: my %sections_count = &get_sections($cdom,$cnum);
6761: my @sections = (sort {$a <=> $b} keys(%sections_count));
6762: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6763: my @groups = sort(keys(%curr_groups));
6764: my $allroles = [];
6765: my $rolehash;
6766: my $accesshash = {
6767: active => 'Currently has access',
6768: future => 'Will have future access',
6769: previous => 'Previously had access',
6770: };
6771: if ($needroles) {
6772: $rolehash = {'all' => 'all'};
1.385 albertel 6773: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6774: if (&Apache::lonnet::error(%user_roles)) {
6775: undef(%user_roles);
6776: }
6777: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6778: my ($role)=split(/\:/,$item,2);
6779: if ($role eq 'cr') { next; }
6780: if ($role =~ /^cr/) {
6781: $$rolehash{$role} = (split('/',$role))[3];
6782: } else {
6783: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6784: }
6785: }
6786: foreach my $key (sort(keys(%{$rolehash}))) {
6787: push(@{$allroles},$key);
6788: }
6789: push (@{$allroles},'st');
6790: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6791: }
6792: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6793: }
6794:
1.555 raeburn 6795: sub user_picker {
1.627 raeburn 6796: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6797: my $currdom = $dom;
6798: my %curr_selected = (
6799: srchin => 'dom',
1.580 raeburn 6800: srchby => 'lastname',
1.555 raeburn 6801: );
6802: my $srchterm;
1.625 raeburn 6803: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6804: if ($srch->{'srchby'} ne '') {
6805: $curr_selected{'srchby'} = $srch->{'srchby'};
6806: }
6807: if ($srch->{'srchin'} ne '') {
6808: $curr_selected{'srchin'} = $srch->{'srchin'};
6809: }
6810: if ($srch->{'srchtype'} ne '') {
6811: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6812: }
6813: if ($srch->{'srchdomain'} ne '') {
6814: $currdom = $srch->{'srchdomain'};
6815: }
6816: $srchterm = $srch->{'srchterm'};
6817: }
6818: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6819: 'usr' => 'Search criteria',
1.563 raeburn 6820: 'doma' => 'Domain/institution to search',
1.558 albertel 6821: 'uname' => 'username',
6822: 'lastname' => 'last name',
1.555 raeburn 6823: 'lastfirst' => 'last name, first name',
1.558 albertel 6824: 'crs' => 'in this course',
1.576 raeburn 6825: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6826: 'alc' => 'all LON-CAPA',
1.573 raeburn 6827: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6828: 'exact' => 'is',
6829: 'contains' => 'contains',
1.569 raeburn 6830: 'begins' => 'begins with',
1.571 raeburn 6831: 'youm' => "You must include some text to search for.",
6832: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6833: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6834: 'yomc' => "You must choose a domain when using an institutional directory search.",
6835: 'ymcd' => "You must choose a domain when using a domain search.",
6836: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6837: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6838: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6839: );
1.563 raeburn 6840: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6841: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6842:
6843: my @srchins = ('crs','dom','alc','instd');
6844:
6845: foreach my $option (@srchins) {
6846: # FIXME 'alc' option unavailable until
6847: # loncreateuser::print_user_query_page()
6848: # has been completed.
6849: next if ($option eq 'alc');
6850: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6851: if ($curr_selected{'srchin'} eq $option) {
6852: $srchinsel .= '
6853: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6854: } else {
6855: $srchinsel .= '
6856: <option value="'.$option.'">'.$lt{$option}.'</option>';
6857: }
1.555 raeburn 6858: }
1.563 raeburn 6859: $srchinsel .= "\n </select>\n";
1.555 raeburn 6860:
6861: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 6862: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 6863: if ($curr_selected{'srchby'} eq $option) {
6864: $srchbysel .= '
6865: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6866: } else {
6867: $srchbysel .= '
6868: <option value="'.$option.'">'.$lt{$option}.'</option>';
6869: }
6870: }
6871: $srchbysel .= "\n </select>\n";
6872:
6873: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 6874: foreach my $option ('begins','contains','exact') {
1.555 raeburn 6875: if ($curr_selected{'srchtype'} eq $option) {
6876: $srchtypesel .= '
6877: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6878: } else {
6879: $srchtypesel .= '
6880: <option value="'.$option.'">'.$lt{$option}.'</option>';
6881: }
6882: }
6883: $srchtypesel .= "\n </select>\n";
6884:
1.558 albertel 6885: my ($newuserscript,$new_user_create);
1.556 raeburn 6886:
6887: if ($forcenewuser) {
1.576 raeburn 6888: if (ref($srch) eq 'HASH') {
6889: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 6890: if ($cancreate) {
6891: $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>';
6892: } else {
1.692.4.2! raeburn 6893: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 6894: my %usertypetext = (
6895: official => 'institutional',
6896: unofficial => 'non-institutional',
6897: );
1.692.4.2! raeburn 6898: $new_user_create = '<p class="LC_warning">'.
! 6899: &mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.
! 6900: &mt('Please contact the [_1]helpdesk[_2] for assistance.','<a href="'.$helplink.'">','</a>').'</p><br />';
1.627 raeburn 6901: }
1.576 raeburn 6902: }
6903: }
6904:
1.556 raeburn 6905: $newuserscript = <<"ENDSCRIPT";
6906:
1.570 raeburn 6907: function setSearch(createnew,callingForm) {
1.556 raeburn 6908: if (createnew == 1) {
1.570 raeburn 6909: for (var i=0; i<callingForm.srchby.length; i++) {
6910: if (callingForm.srchby.options[i].value == 'uname') {
6911: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6912: }
6913: }
1.570 raeburn 6914: for (var i=0; i<callingForm.srchin.length; i++) {
6915: if ( callingForm.srchin.options[i].value == 'dom') {
6916: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6917: }
6918: }
1.570 raeburn 6919: for (var i=0; i<callingForm.srchtype.length; i++) {
6920: if (callingForm.srchtype.options[i].value == 'exact') {
6921: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6922: }
6923: }
1.570 raeburn 6924: for (var i=0; i<callingForm.srchdomain.length; i++) {
6925: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6926: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6927: }
6928: }
6929: }
6930: }
6931: ENDSCRIPT
1.558 albertel 6932:
1.556 raeburn 6933: }
6934:
1.555 raeburn 6935: my $output = <<"END_BLOCK";
1.556 raeburn 6936: <script type="text/javascript">
1.570 raeburn 6937: function validateEntry(callingForm) {
1.558 albertel 6938:
1.556 raeburn 6939: var checkok = 1;
1.558 albertel 6940: var srchin;
1.570 raeburn 6941: for (var i=0; i<callingForm.srchin.length; i++) {
6942: if ( callingForm.srchin[i].checked ) {
6943: srchin = callingForm.srchin[i].value;
1.558 albertel 6944: }
6945: }
6946:
1.570 raeburn 6947: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6948: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6949: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6950: var srchterm = callingForm.srchterm.value;
6951: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6952: var msg = "";
6953:
6954: if (srchterm == "") {
6955: checkok = 0;
1.571 raeburn 6956: msg += "$lt{'youm'}\\n";
1.556 raeburn 6957: }
6958:
1.569 raeburn 6959: if (srchtype== 'begins') {
6960: if (srchterm.length < 2) {
6961: checkok = 0;
1.571 raeburn 6962: msg += "$lt{'thte'}\\n";
1.569 raeburn 6963: }
6964: }
6965:
1.556 raeburn 6966: if (srchtype== 'contains') {
6967: if (srchterm.length < 3) {
6968: checkok = 0;
1.571 raeburn 6969: msg += "$lt{'thet'}\\n";
1.556 raeburn 6970: }
6971: }
6972: if (srchin == 'instd') {
6973: if (srchdomain == '') {
6974: checkok = 0;
1.571 raeburn 6975: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6976: }
6977: }
6978: if (srchin == 'dom') {
6979: if (srchdomain == '') {
6980: checkok = 0;
1.571 raeburn 6981: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6982: }
6983: }
6984: if (srchby == 'lastfirst') {
6985: if (srchterm.indexOf(",") == -1) {
6986: checkok = 0;
1.571 raeburn 6987: msg += "$lt{'whus'}\\n";
1.556 raeburn 6988: }
6989: if (srchterm.indexOf(",") == srchterm.length -1) {
6990: checkok = 0;
1.571 raeburn 6991: msg += "$lt{'whse'}\\n";
1.556 raeburn 6992: }
6993: }
6994: if (checkok == 0) {
1.571 raeburn 6995: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6996: return;
6997: }
6998: if (checkok == 1) {
1.570 raeburn 6999: callingForm.submit();
1.556 raeburn 7000: }
7001: }
7002:
7003: $newuserscript
7004:
7005: </script>
1.558 albertel 7006:
7007: $new_user_create
7008:
1.555 raeburn 7009: <table>
1.558 albertel 7010: <tr>
1.573 raeburn 7011: <td>$lt{'doma'}:</td>
7012: <td>$domform</td>
7013: </td>
7014: </tr>
7015: <tr>
7016: <td>$lt{'usr'}:</td>
1.563 raeburn 7017: <td>$srchbysel
7018: $srchtypesel
7019: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7020: $srchinsel
1.563 raeburn 7021: </td>
7022: </tr>
1.555 raeburn 7023: </table>
7024: <br />
7025: END_BLOCK
1.558 albertel 7026:
1.555 raeburn 7027: return $output;
7028: }
7029:
1.612 raeburn 7030: sub user_rule_check {
1.615 raeburn 7031: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7032: my $response;
7033: if (ref($usershash) eq 'HASH') {
7034: foreach my $user (keys(%{$usershash})) {
7035: my ($uname,$udom) = split(/:/,$user);
7036: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7037: my ($id,$newuser);
1.612 raeburn 7038: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7039: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7040: $id = $usershash->{$user}->{'id'};
7041: }
7042: my $inst_response;
7043: if (ref($checks) eq 'HASH') {
7044: if (defined($checks->{'username'})) {
1.615 raeburn 7045: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7046: &Apache::lonnet::get_instuser($udom,$uname);
7047: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7048: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7049: &Apache::lonnet::get_instuser($udom,undef,$id);
7050: }
1.615 raeburn 7051: } else {
7052: ($inst_response,%{$inst_results->{$user}}) =
7053: &Apache::lonnet::get_instuser($udom,$uname);
7054: return;
1.612 raeburn 7055: }
1.615 raeburn 7056: if (!$got_rules->{$udom}) {
1.612 raeburn 7057: my %domconfig = &Apache::lonnet::get_dom('configuration',
7058: ['usercreation'],$udom);
7059: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7060: foreach my $item ('username','id') {
1.612 raeburn 7061: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7062: $$curr_rules{$udom}{$item} =
7063: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7064: }
7065: }
7066: }
1.615 raeburn 7067: $got_rules->{$udom} = 1;
1.585 raeburn 7068: }
1.612 raeburn 7069: foreach my $item (keys(%{$checks})) {
7070: if (ref($$curr_rules{$udom}) eq 'HASH') {
7071: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7072: if (@{$$curr_rules{$udom}{$item}} > 0) {
7073: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7074: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7075: if ($rule_check{$rule}) {
7076: $$rulematch{$user}{$item} = $rule;
7077: if ($inst_response eq 'ok') {
1.615 raeburn 7078: if (ref($inst_results) eq 'HASH') {
7079: if (ref($inst_results->{$user}) eq 'HASH') {
7080: if (keys(%{$inst_results->{$user}}) == 0) {
7081: $$alerts{$item}{$udom}{$uname} = 1;
7082: }
1.612 raeburn 7083: }
7084: }
1.615 raeburn 7085: }
7086: last;
1.585 raeburn 7087: }
7088: }
7089: }
7090: }
7091: }
7092: }
7093: }
7094: }
1.612 raeburn 7095: return;
7096: }
7097:
7098: sub user_rule_formats {
7099: my ($domain,$domdesc,$curr_rules,$check) = @_;
7100: my %text = (
7101: 'username' => 'Usernames',
7102: 'id' => 'IDs',
7103: );
7104: my $output;
7105: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7106: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7107: if (@{$ruleorder} > 0) {
7108: $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>';
7109: foreach my $rule (@{$ruleorder}) {
7110: if (ref($curr_rules) eq 'ARRAY') {
7111: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7112: if (ref($rules->{$rule}) eq 'HASH') {
7113: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7114: $rules->{$rule}{'desc'}.'</li>';
7115: }
7116: }
7117: }
7118: }
7119: $output .= '</ul>';
7120: }
7121: }
7122: return $output;
7123: }
7124:
7125: sub instrule_disallow_msg {
1.615 raeburn 7126: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7127: my $response;
7128: my %text = (
7129: item => 'username',
7130: items => 'usernames',
7131: match => 'matches',
7132: do => 'does',
7133: action => 'a username',
7134: one => 'one',
7135: );
7136: if ($count > 1) {
7137: $text{'item'} = 'usernames';
7138: $text{'match'} ='match';
7139: $text{'do'} = 'do';
7140: $text{'action'} = 'usernames',
7141: $text{'one'} = 'ones';
7142: }
7143: if ($checkitem eq 'id') {
7144: $text{'items'} = 'IDs';
7145: $text{'item'} = 'ID';
7146: $text{'action'} = 'an ID';
1.615 raeburn 7147: if ($count > 1) {
7148: $text{'item'} = 'IDs';
7149: $text{'action'} = 'IDs';
7150: }
1.612 raeburn 7151: }
1.674 bisitz 7152: $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 7153: if ($mode eq 'upload') {
7154: if ($checkitem eq 'username') {
7155: $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'}.");
7156: } elsif ($checkitem eq 'id') {
1.674 bisitz 7157: $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 7158: }
1.669 raeburn 7159: } elsif ($mode eq 'selfcreate') {
7160: if ($checkitem eq 'id') {
7161: $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.");
7162: }
1.615 raeburn 7163: } else {
7164: if ($checkitem eq 'username') {
7165: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7166: } elsif ($checkitem eq 'id') {
7167: $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.");
7168: }
1.612 raeburn 7169: }
7170: return $response;
1.585 raeburn 7171: }
7172:
1.624 raeburn 7173: sub personal_data_fieldtitles {
7174: my %fieldtitles = &Apache::lonlocal::texthash (
7175: id => 'Student/Employee ID',
7176: permanentemail => 'E-mail address',
7177: lastname => 'Last Name',
7178: firstname => 'First Name',
7179: middlename => 'Middle Name',
7180: generation => 'Generation',
7181: gen => 'Generation',
1.692.4.2! raeburn 7182: inststatus => 'Affiliation',
1.624 raeburn 7183: );
7184: return %fieldtitles;
7185: }
7186:
1.642 raeburn 7187: sub sorted_inst_types {
7188: my ($dom) = @_;
7189: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7190: my $othertitle = &mt('All users');
7191: if ($env{'request.course.id'}) {
1.668 raeburn 7192: $othertitle = &mt('Any users');
1.642 raeburn 7193: }
7194: my @types;
7195: if (ref($order) eq 'ARRAY') {
7196: @types = @{$order};
7197: }
7198: if (@types == 0) {
7199: if (ref($usertypes) eq 'HASH') {
7200: @types = sort(keys(%{$usertypes}));
7201: }
7202: }
7203: if (keys(%{$usertypes}) > 0) {
7204: $othertitle = &mt('Other users');
7205: }
7206: return ($othertitle,$usertypes,\@types);
7207: }
7208:
1.645 raeburn 7209: sub get_institutional_codes {
7210: my ($settings,$allcourses,$LC_code) = @_;
7211: # Get complete list of course sections to update
7212: my @currsections = ();
7213: my @currxlists = ();
7214: my $coursecode = $$settings{'internal.coursecode'};
7215:
7216: if ($$settings{'internal.sectionnums'} ne '') {
7217: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7218: }
7219:
7220: if ($$settings{'internal.crosslistings'} ne '') {
7221: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7222: }
7223:
7224: if (@currxlists > 0) {
7225: foreach (@currxlists) {
7226: if (m/^([^:]+):(\w*)$/) {
7227: unless (grep/^$1$/,@{$allcourses}) {
7228: push @{$allcourses},$1;
7229: $$LC_code{$1} = $2;
7230: }
7231: }
7232: }
7233: }
7234:
7235: if (@currsections > 0) {
7236: foreach (@currsections) {
7237: if (m/^(\w+):(\w*)$/) {
7238: my $sec = $coursecode.$1;
7239: my $lc_sec = $2;
7240: unless (grep/^$sec$/,@{$allcourses}) {
7241: push @{$allcourses},$sec;
7242: $$LC_code{$sec} = $lc_sec;
7243: }
7244: }
7245: }
7246: }
7247: return;
7248: }
7249:
1.112 bowersj2 7250: =pod
7251:
1.692.4.2! raeburn 7252: =head1 Slot Helpers
! 7253:
! 7254: =over 4
! 7255:
! 7256: =item * sorted_slots()
! 7257:
! 7258: Sorts an array of slot names in order of slot start time (earliest first).
! 7259:
! 7260: Inputs:
! 7261:
! 7262: =over 4
! 7263:
! 7264: slotsarr - Reference to array of unsorted slot names.
! 7265:
! 7266: slots - Reference to hash of hash, where outer hash keys are slot names.
! 7267:
! 7268: =back
! 7269:
! 7270: Returns:
! 7271:
! 7272: =over 4
! 7273:
! 7274: sorted - An array of slot names sorted by the start time of the slot.
! 7275:
! 7276: =back
! 7277:
! 7278: =back
! 7279:
! 7280: =cut
! 7281:
! 7282:
! 7283: sub sorted_slots {
! 7284: my ($slotsarr,$slots) = @_;
! 7285: my @sorted;
! 7286: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
! 7287: @sorted =
! 7288: sort {
! 7289: if (ref($slots->{$a}) && ref($slots->{$b})) {
! 7290: return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
! 7291: }
! 7292: if (ref($slots->{$a})) { return -1;}
! 7293: if (ref($slots->{$b})) { return 1;}
! 7294: return 0;
! 7295: } @{$slotsarr};
! 7296: }
! 7297: return @sorted;
! 7298: }
! 7299:
! 7300: =pod
! 7301:
1.549 albertel 7302: =back
7303:
7304: =head1 HTTP Helpers
7305:
7306: =over 4
7307:
1.648 raeburn 7308: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7309:
1.258 albertel 7310: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7311: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7312: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7313:
7314: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7315: $possible_names is an ref to an array of form element names. As an example:
7316: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7317: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7318:
7319: =cut
1.1 albertel 7320:
1.6 albertel 7321: sub get_unprocessed_cgi {
1.25 albertel 7322: my ($query,$possible_names)= @_;
1.26 matthew 7323: # $Apache::lonxml::debug=1;
1.356 albertel 7324: foreach my $pair (split(/&/,$query)) {
7325: my ($name, $value) = split(/=/,$pair);
1.369 www 7326: $name = &unescape($name);
1.25 albertel 7327: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7328: $value =~ tr/+/ /;
7329: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7330: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7331: }
1.16 harris41 7332: }
1.6 albertel 7333: }
7334:
1.112 bowersj2 7335: =pod
7336:
1.648 raeburn 7337: =item * &cacheheader()
1.112 bowersj2 7338:
7339: returns cache-controlling header code
7340:
7341: =cut
7342:
1.7 albertel 7343: sub cacheheader {
1.258 albertel 7344: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7345: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7346: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7347: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7348: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7349: return $output;
1.7 albertel 7350: }
7351:
1.112 bowersj2 7352: =pod
7353:
1.648 raeburn 7354: =item * &no_cache($r)
1.112 bowersj2 7355:
7356: specifies header code to not have cache
7357:
7358: =cut
7359:
1.9 albertel 7360: sub no_cache {
1.216 albertel 7361: my ($r) = @_;
7362: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7363: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7364: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7365: $r->no_cache(1);
7366: $r->header_out("Expires" => $date);
7367: $r->header_out("Pragma" => "no-cache");
1.123 www 7368: }
7369:
7370: sub content_type {
1.181 albertel 7371: my ($r,$type,$charset) = @_;
1.299 foxr 7372: if ($r) {
7373: # Note that printout.pl calls this with undef for $r.
7374: &no_cache($r);
7375: }
1.258 albertel 7376: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7377: unless ($charset) {
7378: $charset=&Apache::lonlocal::current_encoding;
7379: }
7380: if ($charset) { $type.='; charset='.$charset; }
7381: if ($r) {
7382: $r->content_type($type);
7383: } else {
7384: print("Content-type: $type\n\n");
7385: }
1.9 albertel 7386: }
1.25 albertel 7387:
1.112 bowersj2 7388: =pod
7389:
1.648 raeburn 7390: =item * &add_to_env($name,$value)
1.112 bowersj2 7391:
1.258 albertel 7392: adds $name to the %env hash with value
1.112 bowersj2 7393: $value, if $name already exists, the entry is converted to an array
7394: reference and $value is added to the array.
7395:
7396: =cut
7397:
1.25 albertel 7398: sub add_to_env {
7399: my ($name,$value)=@_;
1.258 albertel 7400: if (defined($env{$name})) {
7401: if (ref($env{$name})) {
1.25 albertel 7402: #already have multiple values
1.258 albertel 7403: push(@{ $env{$name} },$value);
1.25 albertel 7404: } else {
7405: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7406: my $first=$env{$name};
7407: undef($env{$name});
7408: push(@{ $env{$name} },$first,$value);
1.25 albertel 7409: }
7410: } else {
1.258 albertel 7411: $env{$name}=$value;
1.25 albertel 7412: }
1.31 albertel 7413: }
1.149 albertel 7414:
7415: =pod
7416:
1.648 raeburn 7417: =item * &get_env_multiple($name)
1.149 albertel 7418:
1.258 albertel 7419: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7420: values may be defined and end up as an array ref.
7421:
7422: returns an array of values
7423:
7424: =cut
7425:
7426: sub get_env_multiple {
7427: my ($name) = @_;
7428: my @values;
1.258 albertel 7429: if (defined($env{$name})) {
1.149 albertel 7430: # exists is it an array
1.258 albertel 7431: if (ref($env{$name})) {
7432: @values=@{ $env{$name} };
1.149 albertel 7433: } else {
1.258 albertel 7434: $values[0]=$env{$name};
1.149 albertel 7435: }
7436: }
7437: return(@values);
7438: }
7439:
1.660 raeburn 7440: sub ask_for_embedded_content {
7441: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7442: my $upload_output = '
7443: <form name="upload_embedded" action="'.$actionurl.'"
7444: method="post" enctype="multipart/form-data">';
7445: $upload_output .= $state;
1.661 raeburn 7446: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7447:
7448: my $num = 0;
7449: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7450: $upload_output .= &start_data_table_row().
7451: '<td>'.$embed_file.'</td><td>';
7452: if ($args->{'ignore_remote_references'}
7453: && $embed_file =~ m{^\w+://}) {
7454: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7455: } elsif ($args->{'error_on_invalid_names'}
7456: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7457:
7458: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7459:
7460: } else {
7461: $upload_output .='
1.661 raeburn 7462: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7463: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7464: my $attrib = join(':',@{$$allfiles{$embed_file}});
7465: $upload_output .=
7466: "\n\t\t".
7467: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7468: $attrib.'" />';
7469: if (exists($$codebase{$embed_file})) {
7470: $upload_output .=
7471: "\n\t\t".
7472: '<input name="codebase_'.$num.'" type="hidden" value="'.
7473: &escape($$codebase{$embed_file}).'" />';
7474: }
7475: }
7476: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7477: $num++;
7478: }
7479: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7480: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7481: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7482: '.&mt('(only files for which a location has been provided will be uploaded)').'
7483: </form>';
7484: return $upload_output;
7485: }
7486:
1.661 raeburn 7487: sub upload_embedded {
7488: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7489: $current_disk_usage) = @_;
7490: my $output;
7491: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7492: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7493: my $orig_uploaded_filename =
7494: $env{'form.embedded_item_'.$i.'.filename'};
7495:
7496: $env{'form.embedded_orig_'.$i} =
7497: &unescape($env{'form.embedded_orig_'.$i});
7498: my ($path,$fname) =
7499: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7500: # no path, whole string is fname
7501: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7502:
7503: $path = $env{'form.currentpath'}.$path;
7504: $fname = &Apache::lonnet::clean_filename($fname);
7505: # See if there is anything left
7506: next if ($fname eq '');
7507:
7508: # Check if file already exists as a file or directory.
7509: my ($state,$msg);
7510: if ($context eq 'portfolio') {
7511: my $port_path = $dirpath;
7512: if ($group ne '') {
7513: $port_path = "groups/$group/$port_path";
7514: }
7515: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7516: $dir_root,$port_path,$disk_quota,
7517: $current_disk_usage,$uname,$udom);
7518: if ($state eq 'will_exceed_quota'
7519: || $state eq 'file_locked'
7520: || $state eq 'file_exists' ) {
7521: $output .= $msg;
7522: next;
7523: }
7524: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7525: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7526: if ($state eq 'exists') {
7527: $output .= $msg;
7528: next;
7529: }
7530: }
7531: # Check if extension is valid
7532: if (($fname =~ /\.(\w+)$/) &&
7533: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7534: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7535: next;
7536: } elsif (($fname =~ /\.(\w+)$/) &&
7537: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7538: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7539: next;
7540: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7541: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7542: next;
7543: }
7544:
7545: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7546: if ($context eq 'portfolio') {
7547: my $result=
7548: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7549: $dirpath.$path);
7550: if ($result !~ m|^/uploaded/|) {
7551: $output .= '<span class="LC_error">'
7552: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7553: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7554: .'</span><br />';
7555: next;
7556: } else {
7557: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7558: $path.$fname.'</span>').'</p>';
7559: }
7560: } else {
7561: # Save the file
7562: my $target = $env{'form.embedded_item_'.$i};
7563: my $fullpath = $dir_root.$dirpath.'/'.$path;
7564: my $dest = $fullpath.$fname;
7565: my $url = $url_root.$dirpath.'/'.$path.$fname;
7566: my @parts=split(/\//,$fullpath);
7567: my $count;
7568: my $filepath = $dir_root;
7569: for ($count=4;$count<=$#parts;$count++) {
7570: $filepath .= "/$parts[$count]";
7571: if ((-e $filepath)!=1) {
7572: mkdir($filepath,0770);
7573: }
7574: }
7575: my $fh;
7576: if (!open($fh,'>'.$dest)) {
7577: &Apache::lonnet::logthis('Failed to create '.$dest);
7578: $output .= '<span class="LC_error">'.
7579: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7580: '</span><br />';
7581: } else {
7582: if (!print $fh $env{'form.embedded_item_'.$i}) {
7583: &Apache::lonnet::logthis('Failed to write to '.$dest);
7584: $output .= '<span class="LC_error">'.
7585: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7586: '</span><br />';
7587: } else {
7588: if ($context eq 'testbank') {
7589: $output .= &mt('Embedded file uploaded successfully:').
7590: ' <a href="'.$url.'">'.
7591: $orig_uploaded_filename.'</a><br />';
7592: } else {
7593: $output .= '<font size="+2">'.
7594: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7595: $orig_uploaded_filename.'</a>').'</font><br />';
7596: }
7597: }
7598: close($fh);
7599: }
7600: }
7601: }
7602: return $output;
7603: }
7604:
7605: sub check_for_existing {
7606: my ($path,$fname,$element) = @_;
7607: my ($state,$msg);
7608: if (-d $path.'/'.$fname) {
7609: $state = 'exists';
7610: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7611: } elsif (-e $path.'/'.$fname) {
7612: $state = 'exists';
7613: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7614: }
7615: if ($state eq 'exists') {
7616: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7617: }
7618: return ($state,$msg);
7619: }
7620:
7621: sub check_for_upload {
7622: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7623: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7624: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7625: my $getpropath = 1;
7626: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7627: $getpropath);
7628: my $found_file = 0;
7629: my $locked_file = 0;
7630: foreach my $line (@dir_list) {
7631: my ($file_name)=split(/\&/,$line,2);
7632: if ($file_name eq $fname){
7633: $file_name = $path.$file_name;
7634: if ($group ne '') {
7635: $file_name = $group.$file_name;
7636: }
7637: $found_file = 1;
7638: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7639: $locked_file = 1;
7640: }
7641: }
7642: }
7643: if (($current_disk_usage + $filesize) > $disk_quota){
7644: my $msg = '<span class="LC_error">'.
7645: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7646: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7647: return ('will_exceed_quota',$msg);
7648: } elsif ($found_file) {
7649: if ($locked_file) {
7650: my $msg = '<span class="LC_error">';
7651: $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>');
7652: $msg .= '</span><br />';
7653: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7654: return ('file_locked',$msg);
7655: } else {
7656: my $msg = '<span class="LC_error">';
7657: $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'});
7658: $msg .= '</span>';
7659: $msg .= '<br />';
7660: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7661: return ('file_exists',$msg);
7662: }
7663: }
7664: }
7665:
1.31 albertel 7666:
1.41 ng 7667: =pod
1.45 matthew 7668:
1.464 albertel 7669: =back
1.41 ng 7670:
1.112 bowersj2 7671: =head1 CSV Upload/Handling functions
1.38 albertel 7672:
1.41 ng 7673: =over 4
7674:
1.648 raeburn 7675: =item * &upfile_store($r)
1.41 ng 7676:
7677: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7678: needs $env{'form.upfile'}
1.41 ng 7679: returns $datatoken to be put into hidden field
7680:
7681: =cut
1.31 albertel 7682:
7683: sub upfile_store {
7684: my $r=shift;
1.258 albertel 7685: $env{'form.upfile'}=~s/\r/\n/gs;
7686: $env{'form.upfile'}=~s/\f/\n/gs;
7687: $env{'form.upfile'}=~s/\n+/\n/gs;
7688: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7689:
1.258 albertel 7690: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7691: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7692: {
1.158 raeburn 7693: my $datafile = $r->dir_config('lonDaemons').
7694: '/tmp/'.$datatoken.'.tmp';
7695: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7696: print $fh $env{'form.upfile'};
1.158 raeburn 7697: close($fh);
7698: }
1.31 albertel 7699: }
7700: return $datatoken;
7701: }
7702:
1.56 matthew 7703: =pod
7704:
1.648 raeburn 7705: =item * &load_tmp_file($r)
1.41 ng 7706:
7707: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7708: needs $env{'form.datatoken'},
7709: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7710:
7711: =cut
1.31 albertel 7712:
7713: sub load_tmp_file {
7714: my $r=shift;
7715: my @studentdata=();
7716: {
1.158 raeburn 7717: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7718: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7719: if ( open(my $fh,"<$studentfile") ) {
7720: @studentdata=<$fh>;
7721: close($fh);
7722: }
1.31 albertel 7723: }
1.258 albertel 7724: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7725: }
7726:
1.56 matthew 7727: =pod
7728:
1.648 raeburn 7729: =item * &upfile_record_sep()
1.41 ng 7730:
7731: Separate uploaded file into records
7732: returns array of records,
1.258 albertel 7733: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7734:
7735: =cut
1.31 albertel 7736:
7737: sub upfile_record_sep {
1.258 albertel 7738: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7739: } else {
1.248 albertel 7740: my @records;
1.258 albertel 7741: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7742: if ($line=~/^\s*$/) { next; }
7743: push(@records,$line);
7744: }
7745: return @records;
1.31 albertel 7746: }
7747: }
7748:
1.56 matthew 7749: =pod
7750:
1.648 raeburn 7751: =item * &record_sep($record)
1.41 ng 7752:
1.258 albertel 7753: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7754:
7755: =cut
7756:
1.263 www 7757: sub takeleft {
7758: my $index=shift;
7759: return substr('0000'.$index,-4,4);
7760: }
7761:
1.31 albertel 7762: sub record_sep {
7763: my $record=shift;
7764: my %components=();
1.258 albertel 7765: if ($env{'form.upfiletype'} eq 'xml') {
7766: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7767: my $i=0;
1.356 albertel 7768: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7769: $field=~s/^(\"|\')//;
7770: $field=~s/(\"|\')$//;
1.263 www 7771: $components{&takeleft($i)}=$field;
1.31 albertel 7772: $i++;
7773: }
1.258 albertel 7774: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7775: my $i=0;
1.356 albertel 7776: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7777: $field=~s/^(\"|\')//;
7778: $field=~s/(\"|\')$//;
1.263 www 7779: $components{&takeleft($i)}=$field;
1.31 albertel 7780: $i++;
7781: }
7782: } else {
1.561 www 7783: my $separator=',';
1.480 banghart 7784: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7785: $separator=';';
1.480 banghart 7786: }
1.31 albertel 7787: my $i=0;
1.561 www 7788: # the character we are looking for to indicate the end of a quote or a record
7789: my $looking_for=$separator;
7790: # do not add the characters to the fields
7791: my $ignore=0;
7792: # we just encountered a separator (or the beginning of the record)
7793: my $just_found_separator=1;
7794: # store the field we are working on here
7795: my $field='';
7796: # work our way through all characters in record
7797: foreach my $character ($record=~/(.)/g) {
7798: if ($character eq $looking_for) {
7799: if ($character ne $separator) {
7800: # Found the end of a quote, again looking for separator
7801: $looking_for=$separator;
7802: $ignore=1;
7803: } else {
7804: # Found a separator, store away what we got
7805: $components{&takeleft($i)}=$field;
7806: $i++;
7807: $just_found_separator=1;
7808: $ignore=0;
7809: $field='';
7810: }
7811: next;
7812: }
7813: # single or double quotation marks after a separator indicate beginning of a quote
7814: # we are now looking for the end of the quote and need to ignore separators
7815: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7816: $looking_for=$character;
7817: next;
7818: }
7819: # ignore would be true after we reached the end of a quote
7820: if ($ignore) { next; }
7821: if (($just_found_separator) && ($character=~/\s/)) { next; }
7822: $field.=$character;
7823: $just_found_separator=0;
1.31 albertel 7824: }
1.561 www 7825: # catch the very last entry, since we never encountered the separator
7826: $components{&takeleft($i)}=$field;
1.31 albertel 7827: }
7828: return %components;
7829: }
7830:
1.144 matthew 7831: ######################################################
7832: ######################################################
7833:
1.56 matthew 7834: =pod
7835:
1.648 raeburn 7836: =item * &upfile_select_html()
1.41 ng 7837:
1.144 matthew 7838: Return HTML code to select a file from the users machine and specify
7839: the file type.
1.41 ng 7840:
7841: =cut
7842:
1.144 matthew 7843: ######################################################
7844: ######################################################
1.31 albertel 7845: sub upfile_select_html {
1.144 matthew 7846: my %Types = (
7847: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7848: semisv => &mt('Semicolon separated values'),
1.144 matthew 7849: space => &mt('Space separated'),
7850: tab => &mt('Tabulator separated'),
7851: # xml => &mt('HTML/XML'),
7852: );
7853: my $Str = '<input type="file" name="upfile" size="50" />'.
1.692.4.2! raeburn 7854: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 7855: foreach my $type (sort(keys(%Types))) {
7856: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7857: }
7858: $Str .= "</select>\n";
7859: return $Str;
1.31 albertel 7860: }
7861:
1.301 albertel 7862: sub get_samples {
7863: my ($records,$toget) = @_;
7864: my @samples=({});
7865: my $got=0;
7866: foreach my $rec (@$records) {
7867: my %temp = &record_sep($rec);
7868: if (! grep(/\S/, values(%temp))) { next; }
7869: if (%temp) {
7870: $samples[$got]=\%temp;
7871: $got++;
7872: if ($got == $toget) { last; }
7873: }
7874: }
7875: return \@samples;
7876: }
7877:
1.144 matthew 7878: ######################################################
7879: ######################################################
7880:
1.56 matthew 7881: =pod
7882:
1.648 raeburn 7883: =item * &csv_print_samples($r,$records)
1.41 ng 7884:
7885: Prints a table of sample values from each column uploaded $r is an
7886: Apache Request ref, $records is an arrayref from
7887: &Apache::loncommon::upfile_record_sep
7888:
7889: =cut
7890:
1.144 matthew 7891: ######################################################
7892: ######################################################
1.31 albertel 7893: sub csv_print_samples {
7894: my ($r,$records) = @_;
1.662 bisitz 7895: my $samples = &get_samples($records,5);
1.301 albertel 7896:
1.594 raeburn 7897: $r->print(&mt('Samples').'<br />'.&start_data_table().
7898: &start_data_table_header_row());
1.356 albertel 7899: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7900: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 7901: $r->print(&end_data_table_header_row());
1.301 albertel 7902: foreach my $hash (@$samples) {
1.594 raeburn 7903: $r->print(&start_data_table_row());
1.356 albertel 7904: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7905: $r->print('<td>');
1.356 albertel 7906: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 7907: $r->print('</td>');
7908: }
1.594 raeburn 7909: $r->print(&end_data_table_row());
1.31 albertel 7910: }
1.594 raeburn 7911: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 7912: }
7913:
1.144 matthew 7914: ######################################################
7915: ######################################################
7916:
1.56 matthew 7917: =pod
7918:
1.648 raeburn 7919: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 7920:
7921: Prints a table to create associations between values and table columns.
1.144 matthew 7922:
1.41 ng 7923: $r is an Apache Request ref,
7924: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7925: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7926:
7927: =cut
7928:
1.144 matthew 7929: ######################################################
7930: ######################################################
1.31 albertel 7931: sub csv_print_select_table {
7932: my ($r,$records,$d) = @_;
1.301 albertel 7933: my $i=0;
7934: my $samples = &get_samples($records,1);
1.144 matthew 7935: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7936: &start_data_table().&start_data_table_header_row().
1.144 matthew 7937: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7938: '<th>'.&mt('Column').'</th>'.
7939: &end_data_table_header_row()."\n");
1.356 albertel 7940: foreach my $array_ref (@$d) {
7941: my ($value,$display,$defaultcol)=@{ $array_ref };
1.689 bisitz 7942: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 7943:
7944: $r->print('<td><select name=f'.$i.
1.32 matthew 7945: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7946: $r->print('<option value="none"></option>');
1.356 albertel 7947: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7948: $r->print('<option value="'.$sample.'"'.
7949: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 7950: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 7951: }
1.594 raeburn 7952: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7953: $i++;
7954: }
1.594 raeburn 7955: $r->print(&end_data_table());
1.31 albertel 7956: $i--;
7957: return $i;
7958: }
1.56 matthew 7959:
1.144 matthew 7960: ######################################################
7961: ######################################################
7962:
1.56 matthew 7963: =pod
1.31 albertel 7964:
1.648 raeburn 7965: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 7966:
7967: Prints a table of sample values from the upload and can make associate samples to internal names.
7968:
7969: $r is an Apache Request ref,
7970: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7971: $d is an array of 2 element arrays (internal name, displayed name)
7972:
7973: =cut
7974:
1.144 matthew 7975: ######################################################
7976: ######################################################
1.31 albertel 7977: sub csv_samples_select_table {
7978: my ($r,$records,$d) = @_;
7979: my $i=0;
1.144 matthew 7980: #
1.662 bisitz 7981: my $max_samples = 5;
7982: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 7983: $r->print(&start_data_table().
7984: &start_data_table_header_row().'<th>'.
7985: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7986: &end_data_table_header_row());
1.301 albertel 7987:
7988: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7989: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7990: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7991: foreach my $option (@$d) {
7992: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7993: $r->print('<option value="'.$value.'"'.
1.253 albertel 7994: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7995: $display.'</option>');
1.31 albertel 7996: }
7997: $r->print('</select></td><td>');
1.662 bisitz 7998: foreach my $line (0..($max_samples-1)) {
1.301 albertel 7999: if (defined($samples->[$line]{$key})) {
8000: $r->print($samples->[$line]{$key}."<br />\n");
8001: }
8002: }
1.594 raeburn 8003: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8004: $i++;
8005: }
1.594 raeburn 8006: $r->print(&end_data_table());
1.31 albertel 8007: $i--;
8008: return($i);
1.115 matthew 8009: }
8010:
1.144 matthew 8011: ######################################################
8012: ######################################################
8013:
1.115 matthew 8014: =pod
8015:
1.648 raeburn 8016: =item * &clean_excel_name($name)
1.115 matthew 8017:
8018: Returns a replacement for $name which does not contain any illegal characters.
8019:
8020: =cut
8021:
1.144 matthew 8022: ######################################################
8023: ######################################################
1.115 matthew 8024: sub clean_excel_name {
8025: my ($name) = @_;
8026: $name =~ s/[:\*\?\/\\]//g;
8027: if (length($name) > 31) {
8028: $name = substr($name,0,31);
8029: }
8030: return $name;
1.25 albertel 8031: }
1.84 albertel 8032:
1.85 albertel 8033: =pod
8034:
1.648 raeburn 8035: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8036:
8037: Returns either 1 or undef
8038:
8039: 1 if the part is to be hidden, undef if it is to be shown
8040:
8041: Arguments are:
8042:
8043: $id the id of the part to be checked
8044: $symb, optional the symb of the resource to check
8045: $udom, optional the domain of the user to check for
8046: $uname, optional the username of the user to check for
8047:
8048: =cut
1.84 albertel 8049:
8050: sub check_if_partid_hidden {
8051: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8052: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8053: $symb,$udom,$uname);
1.141 albertel 8054: my $truth=1;
8055: #if the string starts with !, then the list is the list to show not hide
8056: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8057: my @hiddenlist=split(/,/,$hiddenparts);
8058: foreach my $checkid (@hiddenlist) {
1.141 albertel 8059: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8060: }
1.141 albertel 8061: return !$truth;
1.84 albertel 8062: }
1.127 matthew 8063:
1.138 matthew 8064:
8065: ############################################################
8066: ############################################################
8067:
8068: =pod
8069:
1.157 matthew 8070: =back
8071:
1.138 matthew 8072: =head1 cgi-bin script and graphing routines
8073:
1.157 matthew 8074: =over 4
8075:
1.648 raeburn 8076: =item * &get_cgi_id()
1.138 matthew 8077:
8078: Inputs: none
8079:
8080: Returns an id which can be used to pass environment variables
8081: to various cgi-bin scripts. These environment variables will
8082: be removed from the users environment after a given time by
8083: the routine &Apache::lonnet::transfer_profile_to_env.
8084:
8085: =cut
8086:
8087: ############################################################
8088: ############################################################
1.152 albertel 8089: my $uniq=0;
1.136 matthew 8090: sub get_cgi_id {
1.154 albertel 8091: $uniq=($uniq+1)%100000;
1.280 albertel 8092: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8093: }
8094:
1.127 matthew 8095: ############################################################
8096: ############################################################
8097:
8098: =pod
8099:
1.648 raeburn 8100: =item * &DrawBarGraph()
1.127 matthew 8101:
1.138 matthew 8102: Facilitates the plotting of data in a (stacked) bar graph.
8103: Puts plot definition data into the users environment in order for
8104: graph.png to plot it. Returns an <img> tag for the plot.
8105: The bars on the plot are labeled '1','2',...,'n'.
8106:
8107: Inputs:
8108:
8109: =over 4
8110:
8111: =item $Title: string, the title of the plot
8112:
8113: =item $xlabel: string, text describing the X-axis of the plot
8114:
8115: =item $ylabel: string, text describing the Y-axis of the plot
8116:
8117: =item $Max: scalar, the maximum Y value to use in the plot
8118: If $Max is < any data point, the graph will not be rendered.
8119:
1.140 matthew 8120: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8121: they are plotted. If undefined, default values will be used.
8122:
1.178 matthew 8123: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8124:
1.138 matthew 8125: =item @Values: An array of array references. Each array reference holds data
8126: to be plotted in a stacked bar chart.
8127:
1.239 matthew 8128: =item If the final element of @Values is a hash reference the key/value
8129: pairs will be added to the graph definition.
8130:
1.138 matthew 8131: =back
8132:
8133: Returns:
8134:
8135: An <img> tag which references graph.png and the appropriate identifying
8136: information for the plot.
8137:
1.127 matthew 8138: =cut
8139:
8140: ############################################################
8141: ############################################################
1.134 matthew 8142: sub DrawBarGraph {
1.178 matthew 8143: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8144: #
8145: if (! defined($colors)) {
8146: $colors = ['#33ff00',
8147: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8148: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8149: ];
8150: }
1.228 matthew 8151: my $extra_settings = {};
8152: if (ref($Values[-1]) eq 'HASH') {
8153: $extra_settings = pop(@Values);
8154: }
1.127 matthew 8155: #
1.136 matthew 8156: my $identifier = &get_cgi_id();
8157: my $id = 'cgi.'.$identifier;
1.129 matthew 8158: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8159: return '';
8160: }
1.225 matthew 8161: #
8162: my @Labels;
8163: if (defined($labels)) {
8164: @Labels = @$labels;
8165: } else {
8166: for (my $i=0;$i<@{$Values[0]};$i++) {
8167: push (@Labels,$i+1);
8168: }
8169: }
8170: #
1.129 matthew 8171: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8172: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8173: my %ValuesHash;
8174: my $NumSets=1;
8175: foreach my $array (@Values) {
8176: next if (! ref($array));
1.136 matthew 8177: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8178: join(',',@$array);
1.129 matthew 8179: }
1.127 matthew 8180: #
1.136 matthew 8181: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8182: if ($NumBars < 3) {
8183: $width = 120+$NumBars*32;
1.220 matthew 8184: $xskip = 1;
1.225 matthew 8185: $bar_width = 30;
8186: } elsif ($NumBars < 5) {
8187: $width = 120+$NumBars*20;
8188: $xskip = 1;
8189: $bar_width = 20;
1.220 matthew 8190: } elsif ($NumBars < 10) {
1.136 matthew 8191: $width = 120+$NumBars*15;
8192: $xskip = 1;
8193: $bar_width = 15;
8194: } elsif ($NumBars <= 25) {
8195: $width = 120+$NumBars*11;
8196: $xskip = 5;
8197: $bar_width = 8;
8198: } elsif ($NumBars <= 50) {
8199: $width = 120+$NumBars*8;
8200: $xskip = 5;
8201: $bar_width = 4;
8202: } else {
8203: $width = 120+$NumBars*8;
8204: $xskip = 5;
8205: $bar_width = 4;
8206: }
8207: #
1.137 matthew 8208: $Max = 1 if ($Max < 1);
8209: if ( int($Max) < $Max ) {
8210: $Max++;
8211: $Max = int($Max);
8212: }
1.127 matthew 8213: $Title = '' if (! defined($Title));
8214: $xlabel = '' if (! defined($xlabel));
8215: $ylabel = '' if (! defined($ylabel));
1.369 www 8216: $ValuesHash{$id.'.title'} = &escape($Title);
8217: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8218: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8219: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8220: $ValuesHash{$id.'.NumBars'} = $NumBars;
8221: $ValuesHash{$id.'.NumSets'} = $NumSets;
8222: $ValuesHash{$id.'.PlotType'} = 'bar';
8223: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8224: $ValuesHash{$id.'.height'} = $height;
8225: $ValuesHash{$id.'.width'} = $width;
8226: $ValuesHash{$id.'.xskip'} = $xskip;
8227: $ValuesHash{$id.'.bar_width'} = $bar_width;
8228: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8229: #
1.228 matthew 8230: # Deal with other parameters
8231: while (my ($key,$value) = each(%$extra_settings)) {
8232: $ValuesHash{$id.'.'.$key} = $value;
8233: }
8234: #
1.646 raeburn 8235: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8236: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8237: }
8238:
8239: ############################################################
8240: ############################################################
8241:
8242: =pod
8243:
1.648 raeburn 8244: =item * &DrawXYGraph()
1.137 matthew 8245:
1.138 matthew 8246: Facilitates the plotting of data in an XY graph.
8247: Puts plot definition data into the users environment in order for
8248: graph.png to plot it. Returns an <img> tag for the plot.
8249:
8250: Inputs:
8251:
8252: =over 4
8253:
8254: =item $Title: string, the title of the plot
8255:
8256: =item $xlabel: string, text describing the X-axis of the plot
8257:
8258: =item $ylabel: string, text describing the Y-axis of the plot
8259:
8260: =item $Max: scalar, the maximum Y value to use in the plot
8261: If $Max is < any data point, the graph will not be rendered.
8262:
8263: =item $colors: Array ref containing the hex color codes for the data to be
8264: plotted in. If undefined, default values will be used.
8265:
8266: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8267:
8268: =item $Ydata: Array ref containing Array refs.
1.185 www 8269: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8270:
8271: =item %Values: hash indicating or overriding any default values which are
8272: passed to graph.png.
8273: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8274:
8275: =back
8276:
8277: Returns:
8278:
8279: An <img> tag which references graph.png and the appropriate identifying
8280: information for the plot.
8281:
1.137 matthew 8282: =cut
8283:
8284: ############################################################
8285: ############################################################
8286: sub DrawXYGraph {
8287: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8288: #
8289: # Create the identifier for the graph
8290: my $identifier = &get_cgi_id();
8291: my $id = 'cgi.'.$identifier;
8292: #
8293: $Title = '' if (! defined($Title));
8294: $xlabel = '' if (! defined($xlabel));
8295: $ylabel = '' if (! defined($ylabel));
8296: my %ValuesHash =
8297: (
1.369 www 8298: $id.'.title' => &escape($Title),
8299: $id.'.xlabel' => &escape($xlabel),
8300: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8301: $id.'.y_max_value'=> $Max,
8302: $id.'.labels' => join(',',@$Xlabels),
8303: $id.'.PlotType' => 'XY',
8304: );
8305: #
8306: if (defined($colors) && ref($colors) eq 'ARRAY') {
8307: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8308: }
8309: #
8310: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8311: return '';
8312: }
8313: my $NumSets=1;
1.138 matthew 8314: foreach my $array (@{$Ydata}){
1.137 matthew 8315: next if (! ref($array));
8316: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8317: }
1.138 matthew 8318: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8319: #
8320: # Deal with other parameters
8321: while (my ($key,$value) = each(%Values)) {
8322: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8323: }
8324: #
1.646 raeburn 8325: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8326: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8327: }
8328:
8329: ############################################################
8330: ############################################################
8331:
8332: =pod
8333:
1.648 raeburn 8334: =item * &DrawXYYGraph()
1.138 matthew 8335:
8336: Facilitates the plotting of data in an XY graph with two Y axes.
8337: Puts plot definition data into the users environment in order for
8338: graph.png to plot it. Returns an <img> tag for the plot.
8339:
8340: Inputs:
8341:
8342: =over 4
8343:
8344: =item $Title: string, the title of the plot
8345:
8346: =item $xlabel: string, text describing the X-axis of the plot
8347:
8348: =item $ylabel: string, text describing the Y-axis of the plot
8349:
8350: =item $colors: Array ref containing the hex color codes for the data to be
8351: plotted in. If undefined, default values will be used.
8352:
8353: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8354:
8355: =item $Ydata1: The first data set
8356:
8357: =item $Min1: The minimum value of the left Y-axis
8358:
8359: =item $Max1: The maximum value of the left Y-axis
8360:
8361: =item $Ydata2: The second data set
8362:
8363: =item $Min2: The minimum value of the right Y-axis
8364:
8365: =item $Max2: The maximum value of the left Y-axis
8366:
8367: =item %Values: hash indicating or overriding any default values which are
8368: passed to graph.png.
8369: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8370:
8371: =back
8372:
8373: Returns:
8374:
8375: An <img> tag which references graph.png and the appropriate identifying
8376: information for the plot.
1.136 matthew 8377:
8378: =cut
8379:
8380: ############################################################
8381: ############################################################
1.137 matthew 8382: sub DrawXYYGraph {
8383: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8384: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8385: #
8386: # Create the identifier for the graph
8387: my $identifier = &get_cgi_id();
8388: my $id = 'cgi.'.$identifier;
8389: #
8390: $Title = '' if (! defined($Title));
8391: $xlabel = '' if (! defined($xlabel));
8392: $ylabel = '' if (! defined($ylabel));
8393: my %ValuesHash =
8394: (
1.369 www 8395: $id.'.title' => &escape($Title),
8396: $id.'.xlabel' => &escape($xlabel),
8397: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8398: $id.'.labels' => join(',',@$Xlabels),
8399: $id.'.PlotType' => 'XY',
8400: $id.'.NumSets' => 2,
1.137 matthew 8401: $id.'.two_axes' => 1,
8402: $id.'.y1_max_value' => $Max1,
8403: $id.'.y1_min_value' => $Min1,
8404: $id.'.y2_max_value' => $Max2,
8405: $id.'.y2_min_value' => $Min2,
1.136 matthew 8406: );
8407: #
1.137 matthew 8408: if (defined($colors) && ref($colors) eq 'ARRAY') {
8409: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8410: }
8411: #
8412: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8413: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8414: return '';
8415: }
8416: my $NumSets=1;
1.137 matthew 8417: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8418: next if (! ref($array));
8419: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8420: }
8421: #
8422: # Deal with other parameters
8423: while (my ($key,$value) = each(%Values)) {
8424: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8425: }
8426: #
1.646 raeburn 8427: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8428: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8429: }
8430:
8431: ############################################################
8432: ############################################################
8433:
8434: =pod
8435:
1.157 matthew 8436: =back
8437:
1.139 matthew 8438: =head1 Statistics helper routines?
8439:
8440: Bad place for them but what the hell.
8441:
1.157 matthew 8442: =over 4
8443:
1.648 raeburn 8444: =item * &chartlink()
1.139 matthew 8445:
8446: Returns a link to the chart for a specific student.
8447:
8448: Inputs:
8449:
8450: =over 4
8451:
8452: =item $linktext: The text of the link
8453:
8454: =item $sname: The students username
8455:
8456: =item $sdomain: The students domain
8457:
8458: =back
8459:
1.157 matthew 8460: =back
8461:
1.139 matthew 8462: =cut
8463:
8464: ############################################################
8465: ############################################################
8466: sub chartlink {
8467: my ($linktext, $sname, $sdomain) = @_;
8468: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8469: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8470: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8471: '">'.$linktext.'</a>';
1.153 matthew 8472: }
8473:
8474: #######################################################
8475: #######################################################
8476:
8477: =pod
8478:
8479: =head1 Course Environment Routines
1.157 matthew 8480:
8481: =over 4
1.153 matthew 8482:
1.648 raeburn 8483: =item * &restore_course_settings()
1.153 matthew 8484:
1.648 raeburn 8485: =item * &store_course_settings()
1.153 matthew 8486:
8487: Restores/Store indicated form parameters from the course environment.
8488: Will not overwrite existing values of the form parameters.
8489:
8490: Inputs:
8491: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8492:
8493: a hash ref describing the data to be stored. For example:
8494:
8495: %Save_Parameters = ('Status' => 'scalar',
8496: 'chartoutputmode' => 'scalar',
8497: 'chartoutputdata' => 'scalar',
8498: 'Section' => 'array',
1.373 raeburn 8499: 'Group' => 'array',
1.153 matthew 8500: 'StudentData' => 'array',
8501: 'Maps' => 'array');
8502:
8503: Returns: both routines return nothing
8504:
1.631 raeburn 8505: =back
8506:
1.153 matthew 8507: =cut
8508:
8509: #######################################################
8510: #######################################################
8511: sub store_course_settings {
1.496 albertel 8512: return &store_settings($env{'request.course.id'},@_);
8513: }
8514:
8515: sub store_settings {
1.153 matthew 8516: # save to the environment
8517: # appenv the same items, just to be safe
1.300 albertel 8518: my $udom = $env{'user.domain'};
8519: my $uname = $env{'user.name'};
1.496 albertel 8520: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8521: my %SaveHash;
8522: my %AppHash;
8523: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8524: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8525: my $envname = 'environment.'.$basename;
1.258 albertel 8526: if (exists($env{'form.'.$setting})) {
1.153 matthew 8527: # Save this value away
8528: if ($type eq 'scalar' &&
1.258 albertel 8529: (! exists($env{$envname}) ||
8530: $env{$envname} ne $env{'form.'.$setting})) {
8531: $SaveHash{$basename} = $env{'form.'.$setting};
8532: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8533: } elsif ($type eq 'array') {
8534: my $stored_form;
1.258 albertel 8535: if (ref($env{'form.'.$setting})) {
1.153 matthew 8536: $stored_form = join(',',
8537: map {
1.369 www 8538: &escape($_);
1.258 albertel 8539: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8540: } else {
8541: $stored_form =
1.369 www 8542: &escape($env{'form.'.$setting});
1.153 matthew 8543: }
8544: # Determine if the array contents are the same.
1.258 albertel 8545: if ($stored_form ne $env{$envname}) {
1.153 matthew 8546: $SaveHash{$basename} = $stored_form;
8547: $AppHash{$envname} = $stored_form;
8548: }
8549: }
8550: }
8551: }
8552: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8553: $udom,$uname);
1.153 matthew 8554: if ($put_result !~ /^(ok|delayed)/) {
8555: &Apache::lonnet::logthis('unable to save form parameters, '.
8556: 'got error:'.$put_result);
8557: }
8558: # Make sure these settings stick around in this session, too
1.646 raeburn 8559: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8560: return;
8561: }
8562:
8563: sub restore_course_settings {
1.499 albertel 8564: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8565: }
8566:
8567: sub restore_settings {
8568: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8569: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8570: next if (exists($env{'form.'.$setting}));
1.496 albertel 8571: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8572: '.'.$setting;
1.258 albertel 8573: if (exists($env{$envname})) {
1.153 matthew 8574: if ($type eq 'scalar') {
1.258 albertel 8575: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8576: } elsif ($type eq 'array') {
1.258 albertel 8577: $env{'form.'.$setting} = [
1.153 matthew 8578: map {
1.369 www 8579: &unescape($_);
1.258 albertel 8580: } split(',',$env{$envname})
1.153 matthew 8581: ];
8582: }
8583: }
8584: }
1.127 matthew 8585: }
8586:
1.618 raeburn 8587: #######################################################
8588: #######################################################
8589:
8590: =pod
8591:
8592: =head1 Domain E-mail Routines
8593:
8594: =over 4
8595:
1.648 raeburn 8596: =item * &build_recipient_list()
1.618 raeburn 8597:
1.692.4.2! raeburn 8598: Build recipient lists for four types of e-mail:
! 8599: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
! 8600: (d) Help requests, generated by
! 8601: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618 raeburn 8602:
8603: Inputs:
1.619 raeburn 8604: defmail (scalar - email address of default recipient),
1.618 raeburn 8605: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8606: defdom (domain for which to retrieve configuration settings),
8607: origmail (scalar - email address of recipient from loncapa.conf,
8608: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8609:
1.655 raeburn 8610: Returns: comma separated list of addresses to which to send e-mail.
8611:
8612: =back
1.618 raeburn 8613:
8614: =cut
8615:
8616: ############################################################
8617: ############################################################
8618: sub build_recipient_list {
1.619 raeburn 8619: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8620: my @recipients;
8621: my $otheremails;
8622: my %domconfig =
8623: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8624: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.692.4.2! raeburn 8625: if (exists($domconfig{'contacts'}{$mailing})) {
! 8626: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
! 8627: my @contacts = ('adminemail','supportemail');
! 8628: foreach my $item (@contacts) {
! 8629: if ($domconfig{'contacts'}{$mailing}{$item}) {
! 8630: my $addr = $domconfig{'contacts'}{$item};
! 8631: if (!grep(/^\Q$addr\E$/,@recipients)) {
! 8632: push(@recipients,$addr);
! 8633: }
1.619 raeburn 8634: }
1.692.4.2! raeburn 8635: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 8636: }
8637: }
1.692.4.2! raeburn 8638: } elsif ($origmail ne '') {
! 8639: push(@recipients,$origmail);
1.618 raeburn 8640: }
1.619 raeburn 8641: } elsif ($origmail ne '') {
8642: push(@recipients,$origmail);
1.618 raeburn 8643: }
1.688 raeburn 8644: if (defined($defmail)) {
8645: if ($defmail ne '') {
8646: push(@recipients,$defmail);
8647: }
1.618 raeburn 8648: }
8649: if ($otheremails) {
1.619 raeburn 8650: my @others;
8651: if ($otheremails =~ /,/) {
8652: @others = split(/,/,$otheremails);
1.618 raeburn 8653: } else {
1.619 raeburn 8654: push(@others,$otheremails);
8655: }
8656: foreach my $addr (@others) {
8657: if (!grep(/^\Q$addr\E$/,@recipients)) {
8658: push(@recipients,$addr);
8659: }
1.618 raeburn 8660: }
8661: }
1.619 raeburn 8662: my $recipientlist = join(',',@recipients);
1.618 raeburn 8663: return $recipientlist;
8664: }
8665:
1.127 matthew 8666: ############################################################
8667: ############################################################
1.154 albertel 8668:
1.655 raeburn 8669: =pod
8670:
8671: =head1 Course Catalog Routines
8672:
8673: =over 4
8674:
8675: =item * &gather_categories()
8676:
8677: Converts category definitions - keys of categories hash stored in
8678: coursecategories in configuration.db on the primary library server in a
8679: domain - to an array. Also generates javascript and idx hash used to
8680: generate Domain Coordinator interface for editing Course Categories.
8681:
8682: Inputs:
1.663 raeburn 8683:
1.655 raeburn 8684: categories (reference to hash of category definitions).
1.663 raeburn 8685:
1.655 raeburn 8686: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8687: categories and subcategories).
1.663 raeburn 8688:
1.655 raeburn 8689: idx (reference to hash of counters used in Domain Coordinator interface for
8690: editing Course Categories).
1.663 raeburn 8691:
1.655 raeburn 8692: jsarray (reference to array of categories used to create Javascript arrays for
8693: Domain Coordinator interface for editing Course Categories).
8694:
8695: Returns: nothing
8696:
8697: Side effects: populates cats, idx and jsarray.
8698:
8699: =cut
8700:
8701: sub gather_categories {
8702: my ($categories,$cats,$idx,$jsarray) = @_;
8703: my %counters;
8704: my $num = 0;
8705: foreach my $item (keys(%{$categories})) {
8706: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8707: if ($container eq '' && $depth == 0) {
8708: $cats->[$depth][$categories->{$item}] = $cat;
8709: } else {
8710: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8711: }
8712: my ($escitem,$tail) = split(/:/,$item,2);
8713: if ($counters{$tail} eq '') {
8714: $counters{$tail} = $num;
8715: $num ++;
8716: }
8717: if (ref($idx) eq 'HASH') {
8718: $idx->{$item} = $counters{$tail};
8719: }
8720: if (ref($jsarray) eq 'ARRAY') {
8721: push(@{$jsarray->[$counters{$tail}]},$item);
8722: }
8723: }
8724: return;
8725: }
8726:
8727: =pod
8728:
8729: =item * &extract_categories()
8730:
8731: Used to generate breadcrumb trails for course categories.
8732:
8733: Inputs:
1.663 raeburn 8734:
1.655 raeburn 8735: categories (reference to hash of category definitions).
1.663 raeburn 8736:
1.655 raeburn 8737: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8738: categories and subcategories).
1.663 raeburn 8739:
1.655 raeburn 8740: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8741:
1.655 raeburn 8742: allitems (reference to hash - key is category key
8743: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8744:
1.655 raeburn 8745: idx (reference to hash of counters used in Domain Coordinator interface for
8746: editing Course Categories).
1.663 raeburn 8747:
1.655 raeburn 8748: jsarray (reference to array of categories used to create Javascript arrays for
8749: Domain Coordinator interface for editing Course Categories).
8750:
1.665 raeburn 8751: subcats (reference to hash of arrays containing all subcategories within each
8752: category, -recursive)
8753:
1.655 raeburn 8754: Returns: nothing
8755:
8756: Side effects: populates trails and allitems hash references.
8757:
8758: =cut
8759:
8760: sub extract_categories {
1.665 raeburn 8761: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8762: if (ref($categories) eq 'HASH') {
8763: &gather_categories($categories,$cats,$idx,$jsarray);
8764: if (ref($cats->[0]) eq 'ARRAY') {
8765: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8766: my $name = $cats->[0][$i];
8767: my $item = &escape($name).'::0';
8768: my $trailstr;
8769: if ($name eq 'instcode') {
8770: $trailstr = &mt('Official courses (with institutional codes)');
8771: } else {
8772: $trailstr = $name;
8773: }
8774: if ($allitems->{$item} eq '') {
8775: push(@{$trails},$trailstr);
8776: $allitems->{$item} = scalar(@{$trails})-1;
8777: }
8778: my @parents = ($name);
8779: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8780: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8781: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8782: if (ref($subcats) eq 'HASH') {
8783: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8784: }
8785: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8786: }
8787: } else {
8788: if (ref($subcats) eq 'HASH') {
8789: $subcats->{$item} = [];
1.655 raeburn 8790: }
8791: }
8792: }
8793: }
8794: }
8795: return;
8796: }
8797:
8798: =pod
8799:
8800: =item *&recurse_categories()
8801:
8802: Recursively used to generate breadcrumb trails for course categories.
8803:
8804: Inputs:
1.663 raeburn 8805:
1.655 raeburn 8806: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8807: categories and subcategories).
1.663 raeburn 8808:
1.655 raeburn 8809: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8810:
8811: category (current course category, for which breadcrumb trail is being generated).
8812:
8813: trails (reference to array of breadcrumb trails for each category).
8814:
1.655 raeburn 8815: allitems (reference to hash - key is category key
8816: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8817:
1.655 raeburn 8818: parents (array containing containers directories for current category,
8819: back to top level).
8820:
8821: Returns: nothing
8822:
8823: Side effects: populates trails and allitems hash references
8824:
8825: =cut
8826:
8827: sub recurse_categories {
1.665 raeburn 8828: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8829: my $shallower = $depth - 1;
8830: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8831: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8832: my $name = $cats->[$depth]{$category}[$k];
8833: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8834: my $trailstr = join(' -> ',(@{$parents},$category));
8835: if ($allitems->{$item} eq '') {
8836: push(@{$trails},$trailstr);
8837: $allitems->{$item} = scalar(@{$trails})-1;
8838: }
8839: my $deeper = $depth+1;
8840: push(@{$parents},$category);
1.665 raeburn 8841: if (ref($subcats) eq 'HASH') {
8842: my $subcat = &escape($name).':'.$category.':'.$depth;
8843: for (my $j=@{$parents}; $j>=0; $j--) {
8844: my $higher;
8845: if ($j > 0) {
8846: $higher = &escape($parents->[$j]).':'.
8847: &escape($parents->[$j-1]).':'.$j;
8848: } else {
8849: $higher = &escape($parents->[$j]).'::'.$j;
8850: }
8851: push(@{$subcats->{$higher}},$subcat);
8852: }
8853: }
8854: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8855: $subcats);
1.655 raeburn 8856: pop(@{$parents});
8857: }
8858: } else {
8859: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8860: my $trailstr = join(' -> ',(@{$parents},$category));
8861: if ($allitems->{$item} eq '') {
8862: push(@{$trails},$trailstr);
8863: $allitems->{$item} = scalar(@{$trails})-1;
8864: }
8865: }
8866: return;
8867: }
8868:
1.663 raeburn 8869: =pod
8870:
8871: =item *&assign_categories_table()
8872:
8873: Create a datatable for display of hierarchical categories in a domain,
8874: with checkboxes to allow a course to be categorized.
8875:
8876: Inputs:
8877:
8878: cathash - reference to hash of categories defined for the domain (from
8879: configuration.db)
8880:
8881: currcat - scalar with an & separated list of categories assigned to a course.
8882:
8883: Returns: $output (markup to be displayed)
8884:
8885: =cut
8886:
8887: sub assign_categories_table {
8888: my ($cathash,$currcat) = @_;
8889: my $output;
8890: if (ref($cathash) eq 'HASH') {
8891: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
8892: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
8893: $maxdepth = scalar(@cats);
8894: if (@cats > 0) {
8895: my $itemcount = 0;
8896: if (ref($cats[0]) eq 'ARRAY') {
8897: $output = &Apache::loncommon::start_data_table();
8898: my @currcategories;
8899: if ($currcat ne '') {
8900: @currcategories = split('&',$currcat);
8901: }
8902: for (my $i=0; $i<@{$cats[0]}; $i++) {
8903: my $parent = $cats[0][$i];
8904: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8905: next if ($parent eq 'instcode');
8906: my $item = &escape($parent).'::0';
8907: my $checked = '';
8908: if (@currcategories > 0) {
8909: if (grep(/^\Q$item\E$/,@currcategories)) {
8910: $checked = ' checked="checked" ';
8911: }
8912: }
1.675 raeburn 8913: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
8914: '<input type="checkbox" name="usecategory" value="'.
8915: $item.'"'.$checked.' />'.$parent.'</span>'.
8916: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 8917: my $depth = 1;
8918: push(@path,$parent);
8919: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
8920: pop(@path);
8921: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8922: $itemcount ++;
8923: }
8924: $output .= &Apache::loncommon::end_data_table();
8925: }
8926: }
8927: }
8928: return $output;
8929: }
8930:
8931: =pod
8932:
8933: =item *&assign_category_rows()
8934:
8935: Create a datatable row for display of nested categories in a domain,
8936: with checkboxes to allow a course to be categorized,called recursively.
8937:
8938: Inputs:
8939:
8940: itemcount - track row number for alternating colors
8941:
8942: cats - reference to array of arrays/hashes which encapsulates hierarchy of
8943: categories and subcategories.
8944:
8945: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
8946:
8947: parent - parent of current category item
8948:
8949: path - Array containing all categories back up through the hierarchy from the
8950: current category to the top level.
8951:
8952: currcategories - reference to array of current categories assigned to the course
8953:
8954: Returns: $output (markup to be displayed).
8955:
8956: =cut
8957:
8958: sub assign_category_rows {
8959: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
8960: my ($text,$name,$item,$chgstr);
8961: if (ref($cats) eq 'ARRAY') {
8962: my $maxdepth = scalar(@{$cats});
8963: if (ref($cats->[$depth]) eq 'HASH') {
8964: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8965: my $numchildren = @{$cats->[$depth]{$parent}};
8966: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8967: $text .= '<td><table class="LC_datatable">';
8968: for (my $j=0; $j<$numchildren; $j++) {
8969: $name = $cats->[$depth]{$parent}[$j];
8970: $item = &escape($name).':'.&escape($parent).':'.$depth;
8971: my $deeper = $depth+1;
8972: my $checked = '';
8973: if (ref($currcategories) eq 'ARRAY') {
8974: if (@{$currcategories} > 0) {
8975: if (grep(/^\Q$item\E$/,@{$currcategories})) {
8976: $checked = ' checked="checked" ';
8977: }
8978: }
8979: }
1.664 raeburn 8980: $text .= '<tr><td><span class="LC_nobreak"><label>'.
8981: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 8982: $item.'"'.$checked.' />'.$name.'</label></span>'.
8983: '<input type="hidden" name="catname" value="'.$name.'" />'.
8984: '</td><td>';
1.663 raeburn 8985: if (ref($path) eq 'ARRAY') {
8986: push(@{$path},$name);
8987: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
8988: pop(@{$path});
8989: }
8990: $text .= '</td></tr>';
8991: }
8992: $text .= '</table></td>';
8993: }
8994: }
8995: }
8996: return $text;
8997: }
8998:
1.655 raeburn 8999: ############################################################
9000: ############################################################
9001:
9002:
1.443 albertel 9003: sub commit_customrole {
1.664 raeburn 9004: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9005: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9006: ($start?', '.&mt('starting').' '.localtime($start):'').
9007: ($end?', ending '.localtime($end):'').': <b>'.
9008: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9009: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9010: '</b><br />';
9011: return $output;
9012: }
9013:
9014: sub commit_standardrole {
1.541 raeburn 9015: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9016: my ($output,$logmsg,$linefeed);
9017: if ($context eq 'auto') {
9018: $linefeed = "\n";
9019: } else {
9020: $linefeed = "<br />\n";
9021: }
1.443 albertel 9022: if ($three eq 'st') {
1.541 raeburn 9023: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9024: $one,$two,$sec,$context);
9025: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9026: ($result eq 'unknown_course') || ($result eq 'refused')) {
9027: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9028: } else {
1.541 raeburn 9029: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9030: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9031: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9032: if ($context eq 'auto') {
9033: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9034: } else {
9035: $output .= '<b>'.$result.'</b>'.$linefeed.
9036: &mt('Add to classlist').': <b>ok</b>';
9037: }
9038: $output .= $linefeed;
1.443 albertel 9039: }
9040: } else {
9041: $output = &mt('Assigning').' '.$three.' in '.$url.
9042: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9043: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9044: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9045: if ($context eq 'auto') {
9046: $output .= $result.$linefeed;
9047: } else {
9048: $output .= '<b>'.$result.'</b>'.$linefeed;
9049: }
1.443 albertel 9050: }
9051: return $output;
9052: }
9053:
9054: sub commit_studentrole {
1.541 raeburn 9055: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9056: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9057: if ($context eq 'auto') {
9058: $linefeed = "\n";
9059: } else {
9060: $linefeed = '<br />'."\n";
9061: }
1.443 albertel 9062: if (defined($one) && defined($two)) {
9063: my $cid=$one.'_'.$two;
9064: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9065: my $secchange = 0;
9066: my $expire_role_result;
9067: my $modify_section_result;
1.628 raeburn 9068: if ($oldsec ne '-1') {
9069: if ($oldsec ne $sec) {
1.443 albertel 9070: $secchange = 1;
1.628 raeburn 9071: my $now = time;
1.443 albertel 9072: my $uurl='/'.$cid;
9073: $uurl=~s/\_/\//g;
9074: if ($oldsec) {
9075: $uurl.='/'.$oldsec;
9076: }
1.626 raeburn 9077: $oldsecurl = $uurl;
1.628 raeburn 9078: $expire_role_result =
1.652 raeburn 9079: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9080: if ($env{'request.course.sec'} ne '') {
9081: if ($expire_role_result eq 'refused') {
9082: my @roles = ('st');
9083: my @statuses = ('previous');
9084: my @roledoms = ($one);
9085: my $withsec = 1;
9086: my %roleshash =
9087: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9088: \@statuses,\@roles,\@roledoms,$withsec);
9089: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9090: my ($oldstart,$oldend) =
9091: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9092: if ($oldend > 0 && $oldend <= $now) {
9093: $expire_role_result = 'ok';
9094: }
9095: }
9096: }
9097: }
1.443 albertel 9098: $result = $expire_role_result;
9099: }
9100: }
9101: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9102: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9103: if ($modify_section_result =~ /^ok/) {
9104: if ($secchange == 1) {
1.628 raeburn 9105: if ($sec eq '') {
9106: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9107: } else {
9108: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9109: }
1.443 albertel 9110: } elsif ($oldsec eq '-1') {
1.628 raeburn 9111: if ($sec eq '') {
9112: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9113: } else {
9114: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9115: }
1.443 albertel 9116: } else {
1.628 raeburn 9117: if ($sec eq '') {
9118: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9119: } else {
9120: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9121: }
1.443 albertel 9122: }
9123: } else {
1.628 raeburn 9124: if ($secchange) {
9125: $$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;
9126: } else {
9127: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9128: }
1.443 albertel 9129: }
9130: $result = $modify_section_result;
9131: } elsif ($secchange == 1) {
1.628 raeburn 9132: if ($oldsec eq '') {
9133: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9134: } else {
9135: $$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;
9136: }
1.626 raeburn 9137: if ($expire_role_result eq 'refused') {
9138: my $newsecurl = '/'.$cid;
9139: $newsecurl =~ s/\_/\//g;
9140: if ($sec ne '') {
9141: $newsecurl.='/'.$sec;
9142: }
9143: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9144: if ($sec eq '') {
9145: $$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;
9146: } else {
9147: $$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;
9148: }
9149: }
9150: }
1.443 albertel 9151: }
9152: } else {
1.626 raeburn 9153: $$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 9154: $result = "error: incomplete course id\n";
9155: }
9156: return $result;
9157: }
9158:
9159: ############################################################
9160: ############################################################
9161:
1.566 albertel 9162: sub check_clone {
1.578 raeburn 9163: my ($args,$linefeed) = @_;
1.566 albertel 9164: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9165: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9166: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9167: my $clonemsg;
9168: my $can_clone = 0;
9169:
9170: if ($clonehome eq 'no_host') {
1.578 raeburn 9171: $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 9172: } else {
9173: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9174: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9175: $can_clone = 1;
9176: } else {
9177: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9178: $args->{'clonedomain'},$args->{'clonecourse'});
9179: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9180: if (grep(/^\*$/,@cloners)) {
9181: $can_clone = 1;
9182: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9183: $can_clone = 1;
9184: } else {
9185: my %roleshash =
9186: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9187: $args->{'ccdomain'},
9188: 'userroles',['active'],['cc'],
9189: [$args->{'clonedomain'}]);
9190: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9191: $can_clone = 1;
9192: } else {
9193: $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'});
9194: }
1.566 albertel 9195: }
1.578 raeburn 9196: }
1.566 albertel 9197: }
9198: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9199: }
9200:
1.444 albertel 9201: sub construct_course {
1.541 raeburn 9202: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9203: my $outcome;
1.541 raeburn 9204: my $linefeed = '<br />'."\n";
9205: if ($context eq 'auto') {
9206: $linefeed = "\n";
9207: }
1.566 albertel 9208:
9209: #
9210: # Are we cloning?
9211: #
9212: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9213: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9214: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9215: if ($context ne 'auto') {
1.578 raeburn 9216: if ($clonemsg ne '') {
9217: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9218: }
1.566 albertel 9219: }
9220: $outcome .= $clonemsg.$linefeed;
9221:
9222: if (!$can_clone) {
9223: return (0,$outcome);
9224: }
9225: }
9226:
1.444 albertel 9227: #
9228: # Open course
9229: #
9230: my $crstype = lc($args->{'crstype'});
9231: my %cenv=();
9232: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9233: $args->{'cdescr'},
9234: $args->{'curl'},
9235: $args->{'course_home'},
9236: $args->{'nonstandard'},
9237: $args->{'crscode'},
9238: $args->{'ccuname'}.':'.
9239: $args->{'ccdomain'},
9240: $args->{'crstype'});
9241:
9242: # Note: The testing routines depend on this being output; see
9243: # Utils::Course. This needs to at least be output as a comment
9244: # if anyone ever decides to not show this, and Utils::Course::new
9245: # will need to be suitably modified.
1.541 raeburn 9246: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9247: #
9248: # Check if created correctly
9249: #
1.479 albertel 9250: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9251: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9252: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9253:
1.444 albertel 9254: #
1.566 albertel 9255: # Do the cloning
9256: #
9257: if ($can_clone && $cloneid) {
9258: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9259: if ($context ne 'auto') {
9260: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9261: }
9262: $outcome .= $clonemsg.$linefeed;
9263: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9264: # Copy all files
1.637 www 9265: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9266: # Restore URL
1.566 albertel 9267: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9268: # Restore title
1.566 albertel 9269: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9270: # Mark as cloned
1.566 albertel 9271: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9272: # Need to clone grading mode
9273: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9274: $cenv{'grading'}=$newenv{'grading'};
9275: # Do not clone these environment entries
9276: &Apache::lonnet::del('environment',
9277: ['default_enrollment_start_date',
9278: 'default_enrollment_end_date',
9279: 'question.email',
9280: 'policy.email',
9281: 'comment.email',
9282: 'pch.users.denied',
1.692.4.2! raeburn 9283: 'plc.users.denied',
! 9284: 'hidefromcat',
! 9285: 'categories'],
1.638 www 9286: $$crsudom,$$crsunum);
1.444 albertel 9287: }
1.566 albertel 9288:
1.444 albertel 9289: #
9290: # Set environment (will override cloned, if existing)
9291: #
9292: my @sections = ();
9293: my @xlists = ();
9294: if ($args->{'crstype'}) {
9295: $cenv{'type'}=$args->{'crstype'};
9296: }
9297: if ($args->{'crsid'}) {
9298: $cenv{'courseid'}=$args->{'crsid'};
9299: }
9300: if ($args->{'crscode'}) {
9301: $cenv{'internal.coursecode'}=$args->{'crscode'};
9302: }
9303: if ($args->{'crsquota'} ne '') {
9304: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9305: } else {
9306: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9307: }
9308: if ($args->{'ccuname'}) {
9309: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9310: ':'.$args->{'ccdomain'};
9311: } else {
9312: $cenv{'internal.courseowner'} = $args->{'curruser'};
9313: }
9314: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9315: if ($args->{'crssections'}) {
9316: $cenv{'internal.sectionnums'} = '';
9317: if ($args->{'crssections'} =~ m/,/) {
9318: @sections = split/,/,$args->{'crssections'};
9319: } else {
9320: $sections[0] = $args->{'crssections'};
9321: }
9322: if (@sections > 0) {
9323: foreach my $item (@sections) {
9324: my ($sec,$gp) = split/:/,$item;
9325: my $class = $args->{'crscode'}.$sec;
9326: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9327: $cenv{'internal.sectionnums'} .= $item.',';
9328: unless ($addcheck eq 'ok') {
9329: push @badclasses, $class;
9330: }
9331: }
9332: $cenv{'internal.sectionnums'} =~ s/,$//;
9333: }
9334: }
9335: # do not hide course coordinator from staff listing,
9336: # even if privileged
9337: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9338: # add crosslistings
9339: if ($args->{'crsxlist'}) {
9340: $cenv{'internal.crosslistings'}='';
9341: if ($args->{'crsxlist'} =~ m/,/) {
9342: @xlists = split/,/,$args->{'crsxlist'};
9343: } else {
9344: $xlists[0] = $args->{'crsxlist'};
9345: }
9346: if (@xlists > 0) {
9347: foreach my $item (@xlists) {
9348: my ($xl,$gp) = split/:/,$item;
9349: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9350: $cenv{'internal.crosslistings'} .= $item.',';
9351: unless ($addcheck eq 'ok') {
9352: push @badclasses, $xl;
9353: }
9354: }
9355: $cenv{'internal.crosslistings'} =~ s/,$//;
9356: }
9357: }
9358: if ($args->{'autoadds'}) {
9359: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9360: }
9361: if ($args->{'autodrops'}) {
9362: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9363: }
9364: # check for notification of enrollment changes
9365: my @notified = ();
9366: if ($args->{'notify_owner'}) {
9367: if ($args->{'ccuname'} ne '') {
9368: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9369: }
9370: }
9371: if ($args->{'notify_dc'}) {
9372: if ($uname ne '') {
1.630 raeburn 9373: push(@notified,$uname.':'.$udom);
1.444 albertel 9374: }
9375: }
9376: if (@notified > 0) {
9377: my $notifylist;
9378: if (@notified > 1) {
9379: $notifylist = join(',',@notified);
9380: } else {
9381: $notifylist = $notified[0];
9382: }
9383: $cenv{'internal.notifylist'} = $notifylist;
9384: }
9385: if (@badclasses > 0) {
9386: my %lt=&Apache::lonlocal::texthash(
9387: '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',
9388: 'dnhr' => 'does not have rights to access enrollment in these classes',
9389: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9390: );
1.541 raeburn 9391: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9392: ' ('.$lt{'adby'}.')';
9393: if ($context eq 'auto') {
9394: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9395: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9396: foreach my $item (@badclasses) {
9397: if ($context eq 'auto') {
9398: $outcome .= " - $item\n";
9399: } else {
9400: $outcome .= "<li>$item</li>\n";
9401: }
9402: }
9403: if ($context eq 'auto') {
9404: $outcome .= $linefeed;
9405: } else {
1.566 albertel 9406: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9407: }
9408: }
1.444 albertel 9409: }
9410: if ($args->{'no_end_date'}) {
9411: $args->{'endaccess'} = 0;
9412: }
9413: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9414: $cenv{'internal.autoend'}=$args->{'enrollend'};
9415: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9416: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9417: if ($args->{'showphotos'}) {
9418: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9419: }
9420: $cenv{'internal.authtype'} = $args->{'authtype'};
9421: $cenv{'internal.autharg'} = $args->{'autharg'};
9422: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9423: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9424: 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');
9425: if ($context eq 'auto') {
9426: $outcome .= $krb_msg;
9427: } else {
1.566 albertel 9428: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9429: }
9430: $outcome .= $linefeed;
1.444 albertel 9431: }
9432: }
9433: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9434: if ($args->{'setpolicy'}) {
9435: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9436: }
9437: if ($args->{'setcontent'}) {
9438: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9439: }
9440: }
9441: if ($args->{'reshome'}) {
9442: $cenv{'reshome'}=$args->{'reshome'}.'/';
9443: $cenv{'reshome'}=~s/\/+$/\//;
9444: }
9445: #
9446: # course has keyed access
9447: #
9448: if ($args->{'setkeys'}) {
9449: $cenv{'keyaccess'}='yes';
9450: }
9451: # if specified, key authority is not course, but user
9452: # only active if keyaccess is yes
9453: if ($args->{'keyauth'}) {
1.487 albertel 9454: my ($user,$domain) = split(':',$args->{'keyauth'});
9455: $user = &LONCAPA::clean_username($user);
9456: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9457: if ($user ne '' && $domain ne '') {
1.487 albertel 9458: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9459: }
9460: }
9461:
9462: if ($args->{'disresdis'}) {
9463: $cenv{'pch.roles.denied'}='st';
9464: }
9465: if ($args->{'disablechat'}) {
9466: $cenv{'plc.roles.denied'}='st';
9467: }
9468:
9469: # Record we've not yet viewed the Course Initialization Helper for this
9470: # course
9471: $cenv{'course.helper.not.run'} = 1;
9472: #
9473: # Use new Randomseed
9474: #
9475: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9476: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9477: #
9478: # The encryption code and receipt prefix for this course
9479: #
9480: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9481: $cenv{'internal.encpref'}=100+int(9*rand(99));
9482: #
9483: # By default, use standard grading
9484: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9485:
1.541 raeburn 9486: $outcome .= $linefeed.&mt('Setting environment').': '.
9487: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9488: #
9489: # Open all assignments
9490: #
9491: if ($args->{'openall'}) {
9492: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9493: my %storecontent = ($storeunder => time,
9494: $storeunder.'.type' => 'date_start');
9495:
9496: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9497: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9498: }
9499: #
9500: # Set first page
9501: #
9502: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9503: || ($cloneid)) {
1.445 albertel 9504: use LONCAPA::map;
1.444 albertel 9505: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9506:
9507: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9508: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9509:
1.444 albertel 9510: $outcome .= ($fatal?$errtext:'read ok').' - ';
9511: my $title; my $url;
9512: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9513: $title=&mt('Syllabus');
1.444 albertel 9514: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9515: } else {
1.690 bisitz 9516: $title=&mt('Navigate Contents');
1.444 albertel 9517: $url='/adm/navmaps';
9518: }
1.445 albertel 9519:
9520: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9521: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9522:
9523: if ($errtext) { $fatal=2; }
1.541 raeburn 9524: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9525: }
1.566 albertel 9526:
9527: return (1,$outcome);
1.444 albertel 9528: }
9529:
9530: ############################################################
9531: ############################################################
9532:
1.378 raeburn 9533: sub course_type {
9534: my ($cid) = @_;
9535: if (!defined($cid)) {
9536: $cid = $env{'request.course.id'};
9537: }
1.404 albertel 9538: if (defined($env{'course.'.$cid.'.type'})) {
9539: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9540: } else {
9541: return 'Course';
1.377 raeburn 9542: }
9543: }
1.156 albertel 9544:
1.406 raeburn 9545: sub group_term {
9546: my $crstype = &course_type();
9547: my %names = (
9548: 'Course' => 'group',
9549: 'Group' => 'team',
9550: );
9551: return $names{$crstype};
9552: }
9553:
1.156 albertel 9554: sub icon {
9555: my ($file)=@_;
1.505 albertel 9556: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9557: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9558: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9559: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9560: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9561: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9562: $curfext.".gif") {
9563: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9564: $curfext.".gif";
9565: }
9566: }
1.249 albertel 9567: return &lonhttpdurl($iconname);
1.154 albertel 9568: }
1.84 albertel 9569:
1.575 albertel 9570: sub lonhttpdurl {
1.692 www 9571: #
9572: # Had been used for "small fry" static images on separate port 8080.
9573: # Modify here if lightweight http functionality desired again.
9574: # Currently eliminated due to increasing firewall issues.
9575: #
1.575 albertel 9576: my ($url)=@_;
1.692 www 9577: return $url;
1.215 albertel 9578: }
9579:
1.213 albertel 9580: sub connection_aborted {
9581: my ($r)=@_;
9582: $r->print(" ");$r->rflush();
9583: my $c = $r->connection;
9584: return $c->aborted();
9585: }
9586:
1.221 foxr 9587: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9588: # strings as 'strings'.
9589: sub escape_single {
1.221 foxr 9590: my ($input) = @_;
1.223 albertel 9591: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9592: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9593: return $input;
9594: }
1.223 albertel 9595:
1.222 foxr 9596: # Same as escape_single, but escape's "'s This
9597: # can be used for "strings"
9598: sub escape_double {
9599: my ($input) = @_;
9600: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9601: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9602: return $input;
9603: }
1.223 albertel 9604:
1.222 foxr 9605: # Escapes the last element of a full URL.
9606: sub escape_url {
9607: my ($url) = @_;
1.238 raeburn 9608: my @urlslices = split(/\//, $url,-1);
1.369 www 9609: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9610: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9611: }
1.462 albertel 9612:
1.692.4.2! raeburn 9613: sub compare_arrays {
! 9614: my ($arrayref1,$arrayref2) = @_;
! 9615: my (@difference,%count);
! 9616: @difference = ();
! 9617: %count = ();
! 9618: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
! 9619: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
! 9620: foreach my $element (keys(%count)) {
! 9621: if ($count{$element} == 1) {
! 9622: push(@difference,$element);
! 9623: }
! 9624: }
! 9625: }
! 9626: return @difference;
! 9627: }
! 9628:
1.462 albertel 9629: # -------------------------------------------------------- Initliaze user login
9630: sub init_user_environment {
1.463 albertel 9631: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9632: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9633:
9634: my $public=($username eq 'public' && $domain eq 'public');
9635:
9636: # See if old ID present, if so, remove
9637:
9638: my ($filename,$cookie,$userroles);
9639: my $now=time;
9640:
9641: if ($public) {
9642: my $max_public=100;
9643: my $oldest;
9644: my $oldest_time=0;
9645: for(my $next=1;$next<=$max_public;$next++) {
9646: if (-e $lonids."/publicuser_$next.id") {
9647: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9648: if ($mtime<$oldest_time || !$oldest_time) {
9649: $oldest_time=$mtime;
9650: $oldest=$next;
9651: }
9652: } else {
9653: $cookie="publicuser_$next";
9654: last;
9655: }
9656: }
9657: if (!$cookie) { $cookie="publicuser_$oldest"; }
9658: } else {
1.463 albertel 9659: # if this isn't a robot, kill any existing non-robot sessions
9660: if (!$args->{'robot'}) {
9661: opendir(DIR,$lonids);
9662: while ($filename=readdir(DIR)) {
9663: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9664: unlink($lonids.'/'.$filename);
9665: }
1.462 albertel 9666: }
1.463 albertel 9667: closedir(DIR);
1.462 albertel 9668: }
9669: # Give them a new cookie
1.463 albertel 9670: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9671: : $now.$$.int(rand(10000)));
1.463 albertel 9672: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9673:
9674: # Initialize roles
9675:
9676: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9677: }
9678: # ------------------------------------ Check browser type and MathML capability
9679:
9680: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9681: $clientunicode,$clientos) = &decode_user_agent($r);
9682:
9683: # -------------------------------------- Any accessibility options to remember?
9684: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9685: foreach my $option ('imagesuppress','appletsuppress',
9686: 'embedsuppress','fontenhance','blackwhite') {
9687: if ($form->{$option} eq 'true') {
9688: &Apache::lonnet::put('environment',{$option => 'on'},
9689: $domain,$username);
9690: } else {
9691: &Apache::lonnet::del('environment',[$option],
9692: $domain,$username);
9693: }
9694: }
9695: }
9696: # ------------------------------------------------------------- Get environment
9697:
9698: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9699: my ($tmp) = keys(%userenv);
9700: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9701: # default remote control to off
9702: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9703: } else {
9704: undef(%userenv);
9705: }
9706: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9707: $form->{'interface'}=$userenv{'interface'};
9708: }
9709: $env{'environment.remote'}=$userenv{'remote'};
9710: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9711:
9712: # --------------- Do not trust query string to be put directly into environment
9713: foreach my $option ('imagesuppress','appletsuppress',
9714: 'embedsuppress','fontenhance','blackwhite',
9715: 'interface','localpath','localres') {
9716: $form->{$option}=~s/[\n\r\=]//gs;
9717: }
9718: # --------------------------------------------------------- Write first profile
9719:
9720: {
9721: my %initial_env =
9722: ("user.name" => $username,
9723: "user.domain" => $domain,
9724: "user.home" => $authhost,
9725: "browser.type" => $clientbrowser,
9726: "browser.version" => $clientversion,
9727: "browser.mathml" => $clientmathml,
9728: "browser.unicode" => $clientunicode,
9729: "browser.os" => $clientos,
9730: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9731: "request.course.fn" => '',
9732: "request.course.uri" => '',
9733: "request.course.sec" => '',
9734: "request.role" => 'cm',
9735: "request.role.adv" => $env{'user.adv'},
9736: "request.host" => $ENV{'REMOTE_ADDR'},);
9737:
9738: if ($form->{'localpath'}) {
9739: $initial_env{"browser.localpath"} = $form->{'localpath'};
9740: $initial_env{"browser.localres"} = $form->{'localres'};
9741: }
9742:
9743: if ($public) {
9744: $initial_env{"environment.remote"} = "off";
9745: }
9746: if ($form->{'interface'}) {
9747: $form->{'interface'}=~s/\W//gs;
9748: $initial_env{"browser.interface"} = $form->{'interface'};
9749: $env{'browser.interface'}=$form->{'interface'};
9750: foreach my $option ('imagesuppress','appletsuppress',
9751: 'embedsuppress','fontenhance','blackwhite') {
9752: if (($form->{$option} eq 'true') ||
9753: ($userenv{$option} eq 'on')) {
9754: $initial_env{"browser.$option"} = "on";
9755: }
9756: }
9757: }
9758:
1.692.4.2! raeburn 9759: foreach my $tool ('aboutme','blog','portfolio') {
! 9760: $userenv{'availabletools.'.$tool} =
! 9761: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
! 9762: }
! 9763:
! 9764: foreach my $crstype ('official','unofficial') {
! 9765: $userenv{'canrequest.'.$crstype} =
! 9766: &Apache::lonnet::usertools_access($username,$domain,$crstype,
! 9767: 'reload','requestcourses');
! 9768: }
! 9769:
1.462 albertel 9770: $env{'user.environment'} = "$lonids/$cookie.id";
9771:
9772: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9773: &GDBM_WRCREAT(),0640)) {
9774: &_add_to_env(\%disk_env,\%initial_env);
9775: &_add_to_env(\%disk_env,\%userenv,'environment.');
9776: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9777: if (ref($args->{'extra_env'})) {
9778: &_add_to_env(\%disk_env,$args->{'extra_env'});
9779: }
1.462 albertel 9780: untie(%disk_env);
9781: } else {
9782: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
9783: 'Could not create environment storage in lonauth: '.$!.'</font>');
9784: return 'error: '.$!;
9785: }
9786: }
9787: $env{'request.role'}='cm';
9788: $env{'request.role.adv'}=$env{'user.adv'};
9789: $env{'browser.type'}=$clientbrowser;
9790:
9791: return $cookie;
9792:
9793: }
9794:
9795: sub _add_to_env {
9796: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9797: if (ref($env_data) eq 'HASH') {
9798: while (my ($key,$value) = each(%$env_data)) {
9799: $idf->{$prefix.$key} = $value;
9800: $env{$prefix.$key} = $value;
9801: }
1.462 albertel 9802: }
9803: }
9804:
1.685 tempelho 9805: # --- Get the symbolic name of a problem and the url
9806: sub get_symb {
9807: my ($request,$silent) = @_;
1.692.4.2! raeburn 9808: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 9809: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9810: if ($symb eq '') {
9811: if (!$silent) {
9812: $request->print("Unable to handle ambiguous references:$url:.");
9813: return ();
9814: }
9815: }
9816: &Apache::lonenc::check_decrypt(\$symb);
9817: return ($symb);
9818: }
9819:
9820: # --------------------------------------------------------------Get annotation
9821:
9822: sub get_annotation {
9823: my ($symb,$enc) = @_;
9824:
9825: my $key = $symb;
9826: if (!$enc) {
9827: $key =
9828: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9829: }
9830: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9831: return $annotation{$key};
9832: }
9833:
9834: sub clean_symb {
1.692.4.2! raeburn 9835: my ($symb,$delete_enc) = @_;
1.685 tempelho 9836:
9837: &Apache::lonenc::check_decrypt(\$symb);
9838: my $enc = $env{'request.enc'};
1.692.4.2! raeburn 9839: if ($delete_enc) {
! 9840: delete($env{'request.enc'});
! 9841: }
1.685 tempelho 9842:
9843: return ($symb,$enc);
9844: }
1.462 albertel 9845:
1.41 ng 9846: =pod
9847:
9848: =back
9849:
1.112 bowersj2 9850: =cut
1.41 ng 9851:
1.112 bowersj2 9852: 1;
9853: __END__;
1.41 ng 9854:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>