Annotation of loncom/interface/loncommon.pm, revision 1.741
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.741 ! harmsja 4: # $Id: loncommon.pm,v 1.740 2009/02/02 17:21:16 bisitz 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.705 tempelho 274: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
409: <script type="text/javascript" language="Javascript" >
410: var stdeditbrowser;
1.558 albertel 411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74 www 412: var url = '/adm/pickstudent?';
413: var filter;
1.558 albertel 414: if (!ignorefilter) {
415: eval('filter=document.'+formname+'.'+uname+'.value;');
416: }
1.74 www 417: if (filter != null) {
418: if (filter != '') {
419: url += 'filter='+filter+'&';
420: }
421: }
422: url += 'form=' + formname + '&unameelement='+uname+
423: '&udomelement='+udom;
1.111 www 424: if (roleflag) { url+="&roles=1"; }
1.102 www 425: var title = 'Student_Browser';
1.74 www 426: var options = 'scrollbars=1,resizable=1,menubar=0';
427: options += ',width=700,height=600';
428: stdeditbrowser = open(url,title,options,'1');
429: stdeditbrowser.focus();
430: }
431: </script>
432: ENDSTDBRW
433: }
1.42 matthew 434:
1.74 www 435: sub selectstudent_link {
1.111 www 436: my ($form,$unameele,$udomele)=@_;
1.258 albertel 437: if ($env{'request.course.id'}) {
1.302 albertel 438: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
439: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
440: '/'.$env{'request.course.sec'})) {
1.111 www 441: return '';
442: }
443: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607 albertel 444: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 445: }
1.258 albertel 446: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 447: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 448: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 449: }
450: return '';
1.91 www 451: }
452:
1.653 raeburn 453: sub authorbrowser_javascript {
454: return <<"ENDAUTHORBRW";
455: <script type="text/javascript">
456: var stdeditbrowser;
457:
458: function openauthorbrowser(formname,udom) {
459: var url = '/adm/pickauthor?';
460: url += 'form='+formname+'&roledom='+udom;
461: var title = 'Author_Browser';
462: var options = 'scrollbars=1,resizable=1,menubar=0';
463: options += ',width=700,height=600';
464: stdeditbrowser = open(url,title,options,'1');
465: stdeditbrowser.focus();
466: }
467:
468: </script>
469: ENDAUTHORBRW
470: }
471:
1.91 www 472: sub coursebrowser_javascript {
1.468 raeburn 473: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 474: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468 raeburn 475: my $output = '
1.538 albertel 476: <script type="text/javascript">
1.468 raeburn 477: var stdeditbrowser;'."\n";
478: $output .= <<"ENDSTDBRW";
1.377 raeburn 479: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 480: var url = '/adm/pickcourse?';
1.468 raeburn 481: var domainfilter = '';
482: var formid = getFormIdByName(formname);
483: if (formid > -1) {
484: var domid = getIndexByName(formid,udom);
485: if (domid > -1) {
486: if (document.forms[formid].elements[domid].type == 'select-one') {
487: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
488: }
489: if (document.forms[formid].elements[domid].type == 'hidden') {
490: domainfilter=document.forms[formid].elements[domid].value;
491: }
492: }
1.91 www 493: }
1.128 albertel 494: if (domainfilter != null) {
495: if (domainfilter != '') {
496: url += 'domainfilter='+domainfilter+'&';
497: }
498: }
1.91 www 499: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 500: '&cdomelement='+udom+
501: '&cnameelement='+desc;
1.468 raeburn 502: if (extra_element !=null && extra_element != '') {
1.594 raeburn 503: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 504: url += '&roleelement='+extra_element;
505: if (domainfilter == null || domainfilter == '') {
506: url += '&domainfilter='+extra_element;
507: }
1.234 raeburn 508: }
1.468 raeburn 509: else {
510: if (formname == 'portform') {
511: url += '&setroles='+extra_element;
512: }
513: }
1.230 raeburn 514: }
1.293 raeburn 515: if (multflag !=null && multflag != '') {
516: url += '&multiple='+multflag;
517: }
1.377 raeburn 518: if (crstype == 'Course/Group') {
519: if (formname == 'cu') {
520: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
521: if (crstype == "") {
522: alert("$crs_or_grp_alert");
523: return;
524: }
525: }
526: }
527: if (crstype !=null && crstype != '') {
528: url += '&type='+crstype;
529: }
1.102 www 530: var title = 'Course_Browser';
1.91 www 531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
1.468 raeburn 536:
537: function getFormIdByName(formname) {
538: for (var i=0;i<document.forms.length;i++) {
539: if (document.forms[i].name == formname) {
540: return i;
541: }
542: }
543: return -1;
544: }
545:
546: function getIndexByName(formid,item) {
547: for (var i=0;i<document.forms[formid].elements.length;i++) {
548: if (document.forms[formid].elements[i].name == item) {
549: return i;
550: }
551: }
552: return -1;
553: }
1.91 www 554: ENDSTDBRW
1.468 raeburn 555: if ($sec_element ne '') {
556: $output .= &setsec_javascript($sec_element,$formname);
557: }
558: $output .= '
559: </script>';
560: return $output;
561: }
562:
563: sub setsec_javascript {
564: my ($sec_element,$formname) = @_;
565: my $setsections = qq|
566: function setSect(sectionlist) {
1.629 raeburn 567: var sectionsArray = new Array();
568: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
569: sectionsArray = sectionlist.split(",");
570: }
1.468 raeburn 571: var numSections = sectionsArray.length;
572: document.$formname.$sec_element.length = 0;
573: if (numSections == 0) {
574: document.$formname.$sec_element.multiple=false;
575: document.$formname.$sec_element.size=1;
576: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
577: } else {
578: if (numSections == 1) {
579: document.$formname.$sec_element.multiple=false;
580: document.$formname.$sec_element.size=1;
581: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
582: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
583: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
584: } else {
585: for (var i=0; i<numSections; i++) {
586: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
587: }
588: document.$formname.$sec_element.multiple=true
589: if (numSections < 3) {
590: document.$formname.$sec_element.size=numSections;
591: } else {
592: document.$formname.$sec_element.size=3;
593: }
594: document.$formname.$sec_element.options[0].selected = false
595: }
596: }
1.91 www 597: }
1.468 raeburn 598: |;
599: return $setsections;
600: }
601:
1.91 www 602:
603: sub selectcourse_link {
1.377 raeburn 604: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 605: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
606: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 607: }
1.42 matthew 608:
1.653 raeburn 609: sub selectauthor_link {
610: my ($form,$udom)=@_;
611: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
612: &mt('Select Author').'</a>';
613: }
614:
1.273 raeburn 615: sub check_uncheck_jscript {
616: my $jscript = <<"ENDSCRT";
617: function checkAll(field) {
618: if (field.length > 0) {
619: for (i = 0; i < field.length; i++) {
620: field[i].checked = true ;
621: }
622: } else {
623: field.checked = true
624: }
625: }
626:
627: function uncheckAll(field) {
628: if (field.length > 0) {
629: for (i = 0; i < field.length; i++) {
630: field[i].checked = false ;
1.543 albertel 631: }
632: } else {
1.273 raeburn 633: field.checked = false ;
634: }
635: }
636: ENDSCRT
637: return $jscript;
638: }
639:
1.656 www 640: sub select_timezone {
1.659 raeburn 641: my ($name,$selected,$onchange,$includeempty)=@_;
642: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
643: if ($includeempty) {
644: $output .= '<option value=""';
645: if (($selected eq '') || ($selected eq 'local')) {
646: $output .= ' selected="selected" ';
647: }
648: $output .= '> </option>';
649: }
1.657 raeburn 650: my @timezones = DateTime::TimeZone->all_names;
651: foreach my $tzone (@timezones) {
652: $output.= '<option value="'.$tzone.'"';
653: if ($tzone eq $selected) {
654: $output.=' selected="selected"';
655: }
656: $output.=">$tzone</option>\n";
1.656 www 657: }
658: $output.="</select>";
659: return $output;
660: }
1.273 raeburn 661:
1.687 raeburn 662: sub select_datelocale {
663: my ($name,$selected,$onchange,$includeempty)=@_;
664: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
665: if ($includeempty) {
666: $output .= '<option value=""';
667: if ($selected eq '') {
668: $output .= ' selected="selected" ';
669: }
670: $output .= '> </option>';
671: }
672: my (@possibles,%locale_names);
673: my @locales = DateTime::Locale::Catalog::Locales;
674: foreach my $locale (@locales) {
675: if (ref($locale) eq 'HASH') {
676: my $id = $locale->{'id'};
677: if ($id ne '') {
678: my $en_terr = $locale->{'en_territory'};
679: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 680: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 681: if (grep(/^en$/,@languages) || !@languages) {
682: if ($en_terr ne '') {
683: $locale_names{$id} = '('.$en_terr.')';
684: } elsif ($native_terr ne '') {
685: $locale_names{$id} = $native_terr;
686: }
687: } else {
688: if ($native_terr ne '') {
689: $locale_names{$id} = $native_terr.' ';
690: } elsif ($en_terr ne '') {
691: $locale_names{$id} = '('.$en_terr.')';
692: }
693: }
694: push (@possibles,$id);
695: }
696: }
697: }
698: foreach my $item (sort(@possibles)) {
699: $output.= '<option value="'.$item.'"';
700: if ($item eq $selected) {
701: $output.=' selected="selected"';
702: }
703: $output.=">$item";
704: if ($locale_names{$item} ne '') {
705: $output.=" $locale_names{$item}</option>\n";
706: }
707: $output.="</option>\n";
708: }
709: $output.="</select>";
710: return $output;
711: }
712:
1.42 matthew 713: =pod
1.36 matthew 714:
1.648 raeburn 715: =item * &linked_select_forms(...)
1.36 matthew 716:
717: linked_select_forms returns a string containing a <script></script> block
718: and html for two <select> menus. The select menus will be linked in that
719: changing the value of the first menu will result in new values being placed
720: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 721: order unless a defined order is provided.
1.36 matthew 722:
723: linked_select_forms takes the following ordered inputs:
724:
725: =over 4
726:
1.112 bowersj2 727: =item * $formname, the name of the <form> tag
1.36 matthew 728:
1.112 bowersj2 729: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 730:
1.112 bowersj2 731: =item * $firstdefault, the default value for the first menu
1.36 matthew 732:
1.112 bowersj2 733: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 734:
1.112 bowersj2 735: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 736:
1.112 bowersj2 737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 738:
1.609 raeburn 739: =item * $menuorder, the order of values in the first menu
740:
1.41 ng 741: =back
742:
1.36 matthew 743: Below is an example of such a hash. Only the 'text', 'default', and
744: 'select2' keys must appear as stated. keys(%menu) are the possible
745: values for the first select menu. The text that coincides with the
1.41 ng 746: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 747: and text for the second menu are given in the hash pointed to by
748: $menu{$choice1}->{'select2'}.
749:
1.112 bowersj2 750: my %menu = ( A1 => { text =>"Choice A1" ,
751: default => "B3",
752: select2 => {
753: B1 => "Choice B1",
754: B2 => "Choice B2",
755: B3 => "Choice B3",
756: B4 => "Choice B4"
1.609 raeburn 757: },
758: order => ['B4','B3','B1','B2'],
1.112 bowersj2 759: },
760: A2 => { text =>"Choice A2" ,
761: default => "C2",
762: select2 => {
763: C1 => "Choice C1",
764: C2 => "Choice C2",
765: C3 => "Choice C3"
1.609 raeburn 766: },
767: order => ['C2','C1','C3'],
1.112 bowersj2 768: },
769: A3 => { text =>"Choice A3" ,
770: default => "D6",
771: select2 => {
772: D1 => "Choice D1",
773: D2 => "Choice D2",
774: D3 => "Choice D3",
775: D4 => "Choice D4",
776: D5 => "Choice D5",
777: D6 => "Choice D6",
778: D7 => "Choice D7"
1.609 raeburn 779: },
780: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 781: }
782: );
1.36 matthew 783:
784: =cut
785:
786: sub linked_select_forms {
787: my ($formname,
788: $middletext,
789: $firstdefault,
790: $firstselectname,
791: $secondselectname,
1.609 raeburn 792: $hashref,
793: $menuorder,
1.36 matthew 794: ) = @_;
795: my $second = "document.$formname.$secondselectname";
796: my $first = "document.$formname.$firstselectname";
797: # output the javascript to do the changing
798: my $result = '';
1.219 albertel 799: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 800: $result.="var select2data = new Object();\n";
801: $" = '","';
802: my $debug = '';
803: foreach my $s1 (sort(keys(%$hashref))) {
804: $result.="select2data.d_$s1 = new Object();\n";
805: $result.="select2data.d_$s1.def = new String('".
806: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 807: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 808: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 809: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
810: @s2values = @{$hashref->{$s1}->{'order'}};
811: }
1.36 matthew 812: $result.="\"@s2values\");\n";
813: $result.="select2data.d_$s1.texts = new Array(";
814: my @s2texts;
815: foreach my $value (@s2values) {
816: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
817: }
818: $result.="\"@s2texts\");\n";
819: }
820: $"=' ';
821: $result.= <<"END";
822:
823: function select1_changed() {
824: // Determine new choice
825: var newvalue = "d_" + $first.value;
826: // update select2
827: var values = select2data[newvalue].values;
828: var texts = select2data[newvalue].texts;
829: var select2def = select2data[newvalue].def;
830: var i;
831: // out with the old
832: for (i = 0; i < $second.options.length; i++) {
833: $second.options[i] = null;
834: }
835: // in with the nuclear
836: for (i=0;i<values.length; i++) {
837: $second.options[i] = new Option(values[i]);
1.143 matthew 838: $second.options[i].value = values[i];
1.36 matthew 839: $second.options[i].text = texts[i];
840: if (values[i] == select2def) {
841: $second.options[i].selected = true;
842: }
843: }
844: }
845: </script>
846: END
847: # output the initial values for the selection lists
848: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 849: my @order = sort(keys(%{$hashref}));
850: if (ref($menuorder) eq 'ARRAY') {
851: @order = @{$menuorder};
852: }
853: foreach my $value (@order) {
1.36 matthew 854: $result.=" <option value=\"$value\" ";
1.253 albertel 855: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 856: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 857: }
858: $result .= "</select>\n";
859: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
860: $result .= $middletext;
861: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
862: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 863:
864: my @secondorder = sort(keys(%select2));
865: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
866: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
867: }
868: foreach my $value (@secondorder) {
1.36 matthew 869: $result.=" <option value=\"$value\" ";
1.253 albertel 870: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 871: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 872: }
873: $result .= "</select>\n";
874: # return $debug;
875: return $result;
876: } # end of sub linked_select_forms {
877:
1.45 matthew 878: =pod
1.44 bowersj2 879:
1.648 raeburn 880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 881:
1.112 bowersj2 882: Returns a string corresponding to an HTML link to the given help
883: $topic, where $topic corresponds to the name of a .tex file in
884: /home/httpd/html/adm/help/tex, with underscores replaced by
885: spaces.
886:
887: $text will optionally be linked to the same topic, allowing you to
888: link text in addition to the graphic. If you do not want to link
889: text, but wish to specify one of the later parameters, pass an
890: empty string.
891:
892: $stayOnPage is a value that will be interpreted as a boolean. If true,
893: the link will not open a new window. If false, the link will open
894: a new window using Javascript. (Default is false.)
895:
896: $width and $height are optional numerical parameters that will
897: override the width and height of the popped up window, which may
898: be useful for certain help topics with big pictures included.
1.44 bowersj2 899:
900: =cut
901:
902: sub help_open_topic {
1.48 bowersj2 903: my ($topic, $text, $stayOnPage, $width, $height) = @_;
904: $text = "" if (not defined $text);
1.44 bowersj2 905: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 906: if ($env{'browser.interface'} eq 'textual') {
1.79 www 907: $stayOnPage=1;
908: }
1.44 bowersj2 909: $width = 350 if (not defined $width);
910: $height = 400 if (not defined $height);
911: my $filename = $topic;
912: $filename =~ s/ /_/g;
913:
1.48 bowersj2 914: my $template = "";
915: my $link;
1.572 banghart 916:
1.159 www 917: $topic=~s/\W/\_/g;
1.44 bowersj2 918:
1.572 banghart 919: if (!$stayOnPage) {
1.72 bowersj2 920: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 921: } else {
1.48 bowersj2 922: $link = "/adm/help/${filename}.hlp";
923: }
924:
925: # Add the text
1.572 banghart 926: if ($text ne "") {
1.77 www 927: $template .=
1.572 banghart 928: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 929: "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.48 bowersj2 930: }
931:
932: # Add the graphic
1.179 matthew 933: my $title = &mt('Online Help');
1.667 raeburn 934: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48 bowersj2 935: $template .= <<"ENDTEMPLATE";
1.436 albertel 936: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 937: ENDTEMPLATE
1.705 tempelho 938: if ($text ne '') { $template.='</td></tr></table>' };
1.44 bowersj2 939: return $template;
940:
1.106 bowersj2 941: }
942:
943: # This is a quicky function for Latex cheatsheet editing, since it
944: # appears in at least four places
945: sub helpLatexCheatsheet {
1.732 raeburn 946: my ($topic,$text,$not_author) = @_;
947: my $out;
1.106 bowersj2 948: my $addOther = '';
1.732 raeburn 949: if ($topic) {
950: $addOther = &Apache::loncommon::help_open_topic($topic,$text,
951: undef, undef, 600).
1.106 bowersj2 952: '</td><td>';
953: }
1.732 raeburn 954: $out = '<table><tr><td>'.
955: $addOther .
956: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
957: undef,undef,600).
958: '</td><td>'.
959: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
960: undef,undef,600).
961: '</td>';
962: unless ($not_author) {
963: $out .= '<td>'.
964: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
965: undef,undef,600).
966: '</td>';
967: }
968: $out .= '</tr></table>';
969: return $out;
1.172 www 970: }
971:
1.430 albertel 972: sub general_help {
973: my $helptopic='Student_Intro';
974: if ($env{'request.role'}=~/^(ca|au)/) {
975: $helptopic='Authoring_Intro';
976: } elsif ($env{'request.role'}=~/^cc/) {
977: $helptopic='Course_Coordination_Intro';
1.672 raeburn 978: } elsif ($env{'request.role'}=~/^dc/) {
979: $helptopic='Domain_Coordination_Intro';
1.430 albertel 980: }
981: return $helptopic;
982: }
983:
984: sub update_help_link {
985: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
986: my $origurl = $ENV{'REQUEST_URI'};
987: $origurl=~s|^/~|/priv/|;
988: my $timestamp = time;
989: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
990: $$datum = &escape($$datum);
991: }
992:
993: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
994: my $output .= <<"ENDOUTPUT";
995: <script type="text/javascript">
996: banner_link = '$banner_link';
997: </script>
998: ENDOUTPUT
999: return $output;
1000: }
1001:
1002: # now just updates the help link and generates a blue icon
1.193 raeburn 1003: sub help_open_menu {
1.430 albertel 1004: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1005: = @_;
1.430 albertel 1006: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1007: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1008: # if environment.remote is on (using remote control UI)
1.572 banghart 1009: if ($env{'browser.interface'} eq 'textual' ||
1010: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1011: $stayOnPage=1;
1.430 albertel 1012: }
1013: my $output;
1014: if ($component_help) {
1015: if (!$text) {
1016: $output=&help_open_topic($component_help,undef,$stayOnPage,
1017: $width,$height);
1018: } else {
1019: my $help_text;
1020: $help_text=&unescape($topic);
1021: $output='<table><tr><td>'.
1022: &help_open_topic($component_help,$help_text,$stayOnPage,
1023: $width,$height).'</td></tr></table>';
1024: }
1025: }
1026: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1027: return $output.$banner_link;
1028: }
1029:
1030: sub top_nav_help {
1031: my ($text) = @_;
1.436 albertel 1032: $text = &mt($text);
1.572 banghart 1033: my $stay_on_page =
1.436 albertel 1034: ($env{'browser.interface'} eq 'textual' ||
1035: $env{'environment.remote'} eq 'off' );
1.572 banghart 1036: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1037: : "javascript:helpMenu('open')";
1.572 banghart 1038: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1039:
1.201 raeburn 1040: my $title = &mt('Get help');
1.436 albertel 1041:
1042: return <<"END";
1043: $banner_link
1044: <a href="$link" title="$title">$text</a>
1045: END
1046: }
1047:
1048: sub help_menu_js {
1049: my ($text) = @_;
1050:
1051: my $stayOnPage =
1052: ($env{'browser.interface'} eq 'textual' ||
1053: $env{'environment.remote'} eq 'off' );
1054:
1055: my $width = 620;
1056: my $height = 600;
1.430 albertel 1057: my $helptopic=&general_help();
1058: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1059: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1060: my $start_page =
1061: &Apache::loncommon::start_page('Help Menu', undef,
1062: {'frameset' => 1,
1063: 'js_ready' => 1,
1064: 'add_entries' => {
1065: 'border' => '0',
1.579 raeburn 1066: 'rows' => "110,*",},});
1.331 albertel 1067: my $end_page =
1068: &Apache::loncommon::end_page({'frameset' => 1,
1069: 'js_ready' => 1,});
1070:
1.436 albertel 1071: my $template .= <<"ENDTEMPLATE";
1072: <script type="text/javascript">
1.253 albertel 1073: // <!-- BEGIN LON-CAPA Internal
1074: // <![CDATA[
1.430 albertel 1075: var banner_link = '';
1.243 raeburn 1076: function helpMenu(target) {
1077: var caller = this;
1078: if (target == 'open') {
1079: var newWindow = null;
1080: try {
1.262 albertel 1081: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1082: }
1083: catch(error) {
1084: writeHelp(caller);
1085: return;
1086: }
1087: if (newWindow) {
1088: caller = newWindow;
1089: }
1.193 raeburn 1090: }
1.243 raeburn 1091: writeHelp(caller);
1092: return;
1093: }
1094: function writeHelp(caller) {
1.430 albertel 1095: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1096: caller.document.close()
1097: caller.focus()
1.193 raeburn 1098: }
1.253 albertel 1099: // ]]>
1.219 albertel 1100: // END LON-CAPA Internal -->
1.436 albertel 1101: </script>
1.193 raeburn 1102: ENDTEMPLATE
1103: return $template;
1104: }
1105:
1.172 www 1106: sub help_open_bug {
1107: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1108: unless ($env{'user.adv'}) { return ''; }
1.172 www 1109: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1110: $text = "" if (not defined $text);
1111: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1112: if ($env{'browser.interface'} eq 'textual' ||
1113: $env{'environment.remote'} eq 'off' ) {
1.172 www 1114: $stayOnPage=1;
1115: }
1.184 albertel 1116: $width = 600 if (not defined $width);
1117: $height = 600 if (not defined $height);
1.172 www 1118:
1119: $topic=~s/\W+/\+/g;
1120: my $link='';
1121: my $template='';
1.379 albertel 1122: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1123: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1124: if (!$stayOnPage)
1125: {
1126: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1127: }
1128: else
1129: {
1130: $link = $url;
1131: }
1132: # Add the text
1133: if ($text ne "")
1134: {
1135: $template .=
1136: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1137: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1138: }
1139:
1140: # Add the graphic
1.179 matthew 1141: my $title = &mt('Report a Bug');
1.215 albertel 1142: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1143: $template .= <<"ENDTEMPLATE";
1.436 albertel 1144: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1145: ENDTEMPLATE
1146: if ($text ne '') { $template.='</td></tr></table>' };
1147: return $template;
1148:
1149: }
1150:
1151: sub help_open_faq {
1152: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1153: unless ($env{'user.adv'}) { return ''; }
1.172 www 1154: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1155: $text = "" if (not defined $text);
1156: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1157: if ($env{'browser.interface'} eq 'textual' ||
1158: $env{'environment.remote'} eq 'off' ) {
1.172 www 1159: $stayOnPage=1;
1160: }
1161: $width = 350 if (not defined $width);
1162: $height = 400 if (not defined $height);
1163:
1164: $topic=~s/\W+/\+/g;
1165: my $link='';
1166: my $template='';
1167: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1168: if (!$stayOnPage)
1169: {
1170: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1171: }
1172: else
1173: {
1174: $link = $url;
1175: }
1176:
1177: # Add the text
1178: if ($text ne "")
1179: {
1180: $template .=
1.173 www 1181: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1182: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1183: }
1184:
1185: # Add the graphic
1.179 matthew 1186: my $title = &mt('View the FAQ');
1.215 albertel 1187: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1188: $template .= <<"ENDTEMPLATE";
1.436 albertel 1189: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1190: ENDTEMPLATE
1191: if ($text ne '') { $template.='</td></tr></table>' };
1192: return $template;
1193:
1.44 bowersj2 1194: }
1.37 matthew 1195:
1.180 matthew 1196: ###############################################################
1197: ###############################################################
1198:
1.45 matthew 1199: =pod
1200:
1.648 raeburn 1201: =item * &change_content_javascript():
1.256 matthew 1202:
1203: This and the next function allow you to create small sections of an
1204: otherwise static HTML page that you can update on the fly with
1205: Javascript, even in Netscape 4.
1206:
1207: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1208: must be written to the HTML page once. It will prove the Javascript
1209: function "change(name, content)". Calling the change function with the
1210: name of the section
1211: you want to update, matching the name passed to C<changable_area>, and
1212: the new content you want to put in there, will put the content into
1213: that area.
1214:
1215: B<Note>: Netscape 4 only reserves enough space for the changable area
1216: to contain room for the original contents. You need to "make space"
1217: for whatever changes you wish to make, and be B<sure> to check your
1218: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1219: it's adequate for updating a one-line status display, but little more.
1220: This script will set the space to 100% width, so you only need to
1221: worry about height in Netscape 4.
1222:
1223: Modern browsers are much less limiting, and if you can commit to the
1224: user not using Netscape 4, this feature may be used freely with
1225: pretty much any HTML.
1226:
1227: =cut
1228:
1229: sub change_content_javascript {
1230: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1231: if ($env{'browser.type'} eq 'netscape' &&
1232: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1233: return (<<NETSCAPE4);
1234: function change(name, content) {
1235: doc = document.layers[name+"___escape"].layers[0].document;
1236: doc.open();
1237: doc.write(content);
1238: doc.close();
1239: }
1240: NETSCAPE4
1241: } else {
1242: # Otherwise, we need to use semi-standards-compliant code
1243: # (technically, "innerHTML" isn't standard but the equivalent
1244: # is really scary, and every useful browser supports it
1245: return (<<DOMBASED);
1246: function change(name, content) {
1247: element = document.getElementById(name);
1248: element.innerHTML = content;
1249: }
1250: DOMBASED
1251: }
1252: }
1253:
1254: =pod
1255:
1.648 raeburn 1256: =item * &changable_area($name,$origContent):
1.256 matthew 1257:
1258: This provides a "changable area" that can be modified on the fly via
1259: the Javascript code provided in C<change_content_javascript>. $name is
1260: the name you will use to reference the area later; do not repeat the
1261: same name on a given HTML page more then once. $origContent is what
1262: the area will originally contain, which can be left blank.
1263:
1264: =cut
1265:
1266: sub changable_area {
1267: my ($name, $origContent) = @_;
1268:
1.258 albertel 1269: if ($env{'browser.type'} eq 'netscape' &&
1270: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1271: # If this is netscape 4, we need to use the Layer tag
1272: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1273: } else {
1274: return "<span id='$name'>$origContent</span>";
1275: }
1276: }
1277:
1278: =pod
1279:
1.648 raeburn 1280: =item * &viewport_geometry_js
1.590 raeburn 1281:
1282: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1283:
1284: =cut
1285:
1286:
1287: sub viewport_geometry_js {
1288: return <<"GEOMETRY";
1289: var Geometry = {};
1290: function init_geometry() {
1291: if (Geometry.init) { return };
1292: Geometry.init=1;
1293: if (window.innerHeight) {
1294: Geometry.getViewportHeight = function() { return window.innerHeight; };
1295: Geometry.getViewportWidth = function() { return window.innerWidth; };
1296: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1297: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1298: }
1299: else if (document.documentElement && document.documentElement.clientHeight) {
1300: Geometry.getViewportHeight =
1301: function() { return document.documentElement.clientHeight; };
1302: Geometry.getViewportWidth =
1303: function() { return document.documentElement.clientWidth; };
1304:
1305: Geometry.getHorizontalScroll =
1306: function() { return document.documentElement.scrollLeft; };
1307: Geometry.getVerticalScroll =
1308: function() { return document.documentElement.scrollTop; };
1309: }
1310: else if (document.body.clientHeight) {
1311: Geometry.getViewportHeight =
1312: function() { return document.body.clientHeight; };
1313: Geometry.getViewportWidth =
1314: function() { return document.body.clientWidth; };
1315: Geometry.getHorizontalScroll =
1316: function() { return document.body.scrollLeft; };
1317: Geometry.getVerticalScroll =
1318: function() { return document.body.scrollTop; };
1319: }
1320: }
1321:
1322: GEOMETRY
1323: }
1324:
1325: =pod
1326:
1.648 raeburn 1327: =item * &viewport_size_js()
1.590 raeburn 1328:
1329: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1330:
1331: =cut
1332:
1333: sub viewport_size_js {
1334: my $geometry = &viewport_geometry_js();
1335: return <<"DIMS";
1336:
1337: $geometry
1338:
1339: function getViewportDims(width,height) {
1340: init_geometry();
1341: width.value = Geometry.getViewportWidth();
1342: height.value = Geometry.getViewportHeight();
1343: return;
1344: }
1345:
1346: DIMS
1347: }
1348:
1349: =pod
1350:
1.648 raeburn 1351: =item * &resize_textarea_js()
1.565 albertel 1352:
1353: emits the needed javascript to resize a textarea to be as big as possible
1354:
1355: creates a function resize_textrea that takes two IDs first should be
1356: the id of the element to resize, second should be the id of a div that
1357: surrounds everything that comes after the textarea, this routine needs
1358: to be attached to the <body> for the onload and onresize events.
1359:
1.648 raeburn 1360: =back
1.565 albertel 1361:
1362: =cut
1363:
1364: sub resize_textarea_js {
1.590 raeburn 1365: my $geometry = &viewport_geometry_js();
1.565 albertel 1366: return <<"RESIZE";
1367: <script type="text/javascript">
1.590 raeburn 1368: $geometry
1.565 albertel 1369:
1.588 albertel 1370: function getX(element) {
1371: var x = 0;
1372: while (element) {
1373: x += element.offsetLeft;
1374: element = element.offsetParent;
1375: }
1376: return x;
1377: }
1378: function getY(element) {
1379: var y = 0;
1380: while (element) {
1381: y += element.offsetTop;
1382: element = element.offsetParent;
1383: }
1384: return y;
1385: }
1386:
1387:
1.565 albertel 1388: function resize_textarea(textarea_id,bottom_id) {
1389: init_geometry();
1390: var textarea = document.getElementById(textarea_id);
1391: //alert(textarea);
1392:
1.588 albertel 1393: var textarea_top = getY(textarea);
1.565 albertel 1394: var textarea_height = textarea.offsetHeight;
1395: var bottom = document.getElementById(bottom_id);
1.588 albertel 1396: var bottom_top = getY(bottom);
1.565 albertel 1397: var bottom_height = bottom.offsetHeight;
1398: var window_height = Geometry.getViewportHeight();
1.588 albertel 1399: var fudge = 23;
1.565 albertel 1400: var new_height = window_height-fudge-textarea_top-bottom_height;
1401: if (new_height < 300) {
1402: new_height = 300;
1403: }
1404: textarea.style.height=new_height+'px';
1405: }
1406: </script>
1407: RESIZE
1408:
1409: }
1410:
1411: =pod
1412:
1.256 matthew 1413: =head1 Excel and CSV file utility routines
1414:
1415: =over 4
1416:
1417: =cut
1418:
1419: ###############################################################
1420: ###############################################################
1421:
1422: =pod
1423:
1.648 raeburn 1424: =item * &csv_translate($text)
1.37 matthew 1425:
1.185 www 1426: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1427: format.
1428:
1429: =cut
1430:
1.180 matthew 1431: ###############################################################
1432: ###############################################################
1.37 matthew 1433: sub csv_translate {
1434: my $text = shift;
1435: $text =~ s/\"/\"\"/g;
1.209 albertel 1436: $text =~ s/\n/ /g;
1.37 matthew 1437: return $text;
1438: }
1.180 matthew 1439:
1440: ###############################################################
1441: ###############################################################
1442:
1443: =pod
1444:
1.648 raeburn 1445: =item * &define_excel_formats()
1.180 matthew 1446:
1447: Define some commonly used Excel cell formats.
1448:
1449: Currently supported formats:
1450:
1451: =over 4
1452:
1453: =item header
1454:
1455: =item bold
1456:
1457: =item h1
1458:
1459: =item h2
1460:
1461: =item h3
1462:
1.256 matthew 1463: =item h4
1464:
1465: =item i
1466:
1.180 matthew 1467: =item date
1468:
1469: =back
1470:
1471: Inputs: $workbook
1472:
1473: Returns: $format, a hash reference.
1474:
1475: =cut
1476:
1477: ###############################################################
1478: ###############################################################
1479: sub define_excel_formats {
1480: my ($workbook) = @_;
1481: my $format;
1482: $format->{'header'} = $workbook->add_format(bold => 1,
1483: bottom => 1,
1484: align => 'center');
1485: $format->{'bold'} = $workbook->add_format(bold=>1);
1486: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1487: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1488: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1489: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1490: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1491: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1492: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1493: return $format;
1494: }
1495:
1496: ###############################################################
1497: ###############################################################
1.113 bowersj2 1498:
1499: =pod
1500:
1.648 raeburn 1501: =item * &create_workbook()
1.255 matthew 1502:
1503: Create an Excel worksheet. If it fails, output message on the
1504: request object and return undefs.
1505:
1506: Inputs: Apache request object
1507:
1508: Returns (undef) on failure,
1509: Excel worksheet object, scalar with filename, and formats
1510: from &Apache::loncommon::define_excel_formats on success
1511:
1512: =cut
1513:
1514: ###############################################################
1515: ###############################################################
1516: sub create_workbook {
1517: my ($r) = @_;
1518: #
1519: # Create the excel spreadsheet
1520: my $filename = '/prtspool/'.
1.258 albertel 1521: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1522: time.'_'.rand(1000000000).'.xls';
1523: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1524: if (! defined($workbook)) {
1525: $r->log_error("Error creating excel spreadsheet $filename: $!");
1526: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1527: "This error has been logged. ".
1528: "Please alert your LON-CAPA administrator").
1529: '</p>');
1530: return (undef);
1531: }
1532: #
1533: $workbook->set_tempdir('/home/httpd/perl/tmp');
1534: #
1535: my $format = &Apache::loncommon::define_excel_formats($workbook);
1536: return ($workbook,$filename,$format);
1537: }
1538:
1539: ###############################################################
1540: ###############################################################
1541:
1542: =pod
1543:
1.648 raeburn 1544: =item * &create_text_file()
1.113 bowersj2 1545:
1.542 raeburn 1546: Create a file to write to and eventually make available to the user.
1.256 matthew 1547: If file creation fails, outputs an error message on the request object and
1548: return undefs.
1.113 bowersj2 1549:
1.256 matthew 1550: Inputs: Apache request object, and file suffix
1.113 bowersj2 1551:
1.256 matthew 1552: Returns (undef) on failure,
1553: Filehandle and filename on success.
1.113 bowersj2 1554:
1555: =cut
1556:
1.256 matthew 1557: ###############################################################
1558: ###############################################################
1559: sub create_text_file {
1560: my ($r,$suffix) = @_;
1561: if (! defined($suffix)) { $suffix = 'txt'; };
1562: my $fh;
1563: my $filename = '/prtspool/'.
1.258 albertel 1564: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1565: time.'_'.rand(1000000000).'.'.$suffix;
1566: $fh = Apache::File->new('>/home/httpd'.$filename);
1567: if (! defined($fh)) {
1568: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1569: $r->print(&mt('Problems occurred in creating the output file. '
1570: .'This error has been logged. '
1571: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1572: }
1.256 matthew 1573: return ($fh,$filename)
1.113 bowersj2 1574: }
1575:
1576:
1.256 matthew 1577: =pod
1.113 bowersj2 1578:
1579: =back
1580:
1581: =cut
1.37 matthew 1582:
1583: ###############################################################
1.33 matthew 1584: ## Home server <option> list generating code ##
1585: ###############################################################
1.35 matthew 1586:
1.169 www 1587: # ------------------------------------------
1588:
1589: sub domain_select {
1590: my ($name,$value,$multiple)=@_;
1591: my %domains=map {
1.514 albertel 1592: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1593: } &Apache::lonnet::all_domains();
1.169 www 1594: if ($multiple) {
1595: $domains{''}=&mt('Any domain');
1.550 albertel 1596: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1597: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1598: } else {
1.550 albertel 1599: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1600: return &select_form($name,$value,%domains);
1601: }
1602: }
1603:
1.282 albertel 1604: #-------------------------------------------
1605:
1606: =pod
1607:
1.519 raeburn 1608: =head1 Routines for form select boxes
1609:
1610: =over 4
1611:
1.648 raeburn 1612: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1613:
1614: Returns a string containing a <select> element int multiple mode
1615:
1616:
1617: Args:
1618: $name - name of the <select> element
1.506 raeburn 1619: $value - scalar or array ref of values that should already be selected
1.282 albertel 1620: $size - number of rows long the select element is
1.283 albertel 1621: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1622: (shown text should already have been &mt())
1.506 raeburn 1623: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1624:
1.282 albertel 1625: =cut
1626:
1627: #-------------------------------------------
1.169 www 1628: sub multiple_select_form {
1.284 albertel 1629: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1630: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1631: my $output='';
1.191 matthew 1632: if (! defined($size)) {
1633: $size = 4;
1.283 albertel 1634: if (scalar(keys(%$hash))<4) {
1635: $size = scalar(keys(%$hash));
1.191 matthew 1636: }
1637: }
1.734 bisitz 1638: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1639: my @order;
1.506 raeburn 1640: if (ref($order) eq 'ARRAY') {
1641: @order = @{$order};
1642: } else {
1643: @order = sort(keys(%$hash));
1.501 banghart 1644: }
1645: if (exists($$hash{'select_form_order'})) {
1646: @order = @{$$hash{'select_form_order'}};
1647: }
1648:
1.284 albertel 1649: foreach my $key (@order) {
1.356 albertel 1650: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1651: $output.='selected="selected" ' if ($selected{$key});
1652: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1653: }
1654: $output.="</select>\n";
1655: return $output;
1656: }
1657:
1.88 www 1658: #-------------------------------------------
1659:
1660: =pod
1661:
1.648 raeburn 1662: =item * &select_form($defdom,$name,%hash)
1.88 www 1663:
1664: Returns a string containing a <select name='$name' size='1'> form to
1665: allow a user to select options from a hash option_name => displayed text.
1666: See lonrights.pm for an example invocation and use.
1667:
1668: =cut
1669:
1670: #-------------------------------------------
1671: sub select_form {
1672: my ($def,$name,%hash) = @_;
1673: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1674: my @keys;
1675: if (exists($hash{'select_form_order'})) {
1676: @keys=@{$hash{'select_form_order'}};
1677: } else {
1678: @keys=sort(keys(%hash));
1679: }
1.356 albertel 1680: foreach my $key (@keys) {
1681: $selectform.=
1682: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1683: ($key eq $def ? 'selected="selected" ' : '').
1684: ">".&mt($hash{$key})."</option>\n";
1.88 www 1685: }
1686: $selectform.="</select>";
1687: return $selectform;
1688: }
1689:
1.475 www 1690: # For display filters
1691:
1692: sub display_filter {
1693: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1694: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1695: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1696: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1697: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1698: '</label></span> <span class="LC_nobreak">'.
1.475 www 1699: &mt('Filter [_1]',
1.477 www 1700: &select_form($env{'form.displayfilter'},
1701: 'displayfilter',
1702: ('currentfolder' => 'Current folder/page',
1703: 'containing' => 'Containing phrase',
1704: 'none' => 'None'))).
1.714 bisitz 1705: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1706: }
1707:
1.167 www 1708: sub gradeleveldescription {
1709: my $gradelevel=shift;
1710: my %gradelevels=(0 => 'Not specified',
1711: 1 => 'Grade 1',
1712: 2 => 'Grade 2',
1713: 3 => 'Grade 3',
1714: 4 => 'Grade 4',
1715: 5 => 'Grade 5',
1716: 6 => 'Grade 6',
1717: 7 => 'Grade 7',
1718: 8 => 'Grade 8',
1719: 9 => 'Grade 9',
1720: 10 => 'Grade 10',
1721: 11 => 'Grade 11',
1722: 12 => 'Grade 12',
1723: 13 => 'Grade 13',
1724: 14 => '100 Level',
1725: 15 => '200 Level',
1726: 16 => '300 Level',
1727: 17 => '400 Level',
1728: 18 => 'Graduate Level');
1729: return &mt($gradelevels{$gradelevel});
1730: }
1731:
1.163 www 1732: sub select_level_form {
1733: my ($deflevel,$name)=@_;
1734: unless ($deflevel) { $deflevel=0; }
1.167 www 1735: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1736: for (my $i=0; $i<=18; $i++) {
1737: $selectform.="<option value=\"$i\" ".
1.253 albertel 1738: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1739: ">".&gradeleveldescription($i)."</option>\n";
1740: }
1741: $selectform.="</select>";
1742: return $selectform;
1.163 www 1743: }
1.167 www 1744:
1.35 matthew 1745: #-------------------------------------------
1746:
1.45 matthew 1747: =pod
1748:
1.648 raeburn 1749: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35 matthew 1750:
1751: Returns a string containing a <select name='$name' size='1'> form to
1752: allow a user to select the domain to preform an operation in.
1753: See loncreateuser.pm for an example invocation and use.
1754:
1.90 www 1755: If the $includeempty flag is set, it also includes an empty choice ("no domain
1756: selected");
1757:
1.563 raeburn 1758: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1759:
1.35 matthew 1760: =cut
1761:
1762: #-------------------------------------------
1.34 matthew 1763: sub select_dom_form {
1.563 raeburn 1764: my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550 albertel 1765: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1766: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1767: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356 albertel 1768: foreach my $dom (@domains) {
1769: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1770: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1771: if ($showdomdesc) {
1772: if ($dom ne '') {
1773: my $domdesc = &Apache::lonnet::domain($dom,'description');
1774: if ($domdesc ne '') {
1775: $selectdomain .= ' ('.$domdesc.')';
1776: }
1777: }
1778: }
1779: $selectdomain .= "</option>\n";
1.34 matthew 1780: }
1781: $selectdomain.="</select>";
1782: return $selectdomain;
1783: }
1784:
1.35 matthew 1785: #-------------------------------------------
1786:
1.45 matthew 1787: =pod
1788:
1.648 raeburn 1789: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1790:
1.586 raeburn 1791: input: 4 arguments (two required, two optional) -
1792: $domain - domain of new user
1793: $name - name of form element
1794: $default - Value of 'default' causes a default item to be first
1795: option, and selected by default.
1796: $hide - Value of 'hide' causes hiding of the name of the server,
1797: if 1 server found, or default, if 0 found.
1.594 raeburn 1798: output: returns 2 items:
1.586 raeburn 1799: (a) form element which contains either:
1800: (i) <select name="$name">
1801: <option value="$hostid1">$hostid $servers{$hostid}</option>
1802: <option value="$hostid2">$hostid $servers{$hostid}</option>
1803: </select>
1804: form item if there are multiple library servers in $domain, or
1805: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1806: if there is only one library server in $domain.
1807:
1808: (b) number of library servers found.
1809:
1810: See loncreateuser.pm for example of use.
1.35 matthew 1811:
1812: =cut
1813:
1814: #-------------------------------------------
1.586 raeburn 1815: sub home_server_form_item {
1816: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1817: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1818: my $result;
1819: my $numlib = keys(%servers);
1820: if ($numlib > 1) {
1821: $result .= '<select name="'.$name.'" />'."\n";
1822: if ($default) {
1823: $result .= '<option value="default" selected>'.&mt('default').
1824: '</option>'."\n";
1825: }
1826: foreach my $hostid (sort(keys(%servers))) {
1827: $result.= '<option value="'.$hostid.'">'.
1828: $hostid.' '.$servers{$hostid}."</option>\n";
1829: }
1830: $result .= '</select>'."\n";
1831: } elsif ($numlib == 1) {
1832: my $hostid;
1833: foreach my $item (keys(%servers)) {
1834: $hostid = $item;
1835: }
1836: $result .= '<input type="hidden" name="'.$name.'" value="'.
1837: $hostid.'" />';
1838: if (!$hide) {
1839: $result .= $hostid.' '.$servers{$hostid};
1840: }
1841: $result .= "\n";
1842: } elsif ($default) {
1843: $result .= '<input type="hidden" name="'.$name.
1844: '" value="default" />';
1845: if (!$hide) {
1846: $result .= &mt('default');
1847: }
1848: $result .= "\n";
1.33 matthew 1849: }
1.586 raeburn 1850: return ($result,$numlib);
1.33 matthew 1851: }
1.112 bowersj2 1852:
1853: =pod
1854:
1.534 albertel 1855: =back
1856:
1.112 bowersj2 1857: =cut
1.87 matthew 1858:
1859: ###############################################################
1.112 bowersj2 1860: ## Decoding User Agent ##
1.87 matthew 1861: ###############################################################
1862:
1863: =pod
1864:
1.112 bowersj2 1865: =head1 Decoding the User Agent
1866:
1867: =over 4
1868:
1869: =item * &decode_user_agent()
1.87 matthew 1870:
1871: Inputs: $r
1872:
1873: Outputs:
1874:
1875: =over 4
1876:
1.112 bowersj2 1877: =item * $httpbrowser
1.87 matthew 1878:
1.112 bowersj2 1879: =item * $clientbrowser
1.87 matthew 1880:
1.112 bowersj2 1881: =item * $clientversion
1.87 matthew 1882:
1.112 bowersj2 1883: =item * $clientmathml
1.87 matthew 1884:
1.112 bowersj2 1885: =item * $clientunicode
1.87 matthew 1886:
1.112 bowersj2 1887: =item * $clientos
1.87 matthew 1888:
1889: =back
1890:
1.157 matthew 1891: =back
1892:
1.87 matthew 1893: =cut
1894:
1895: ###############################################################
1896: ###############################################################
1897: sub decode_user_agent {
1.247 albertel 1898: my ($r)=@_;
1.87 matthew 1899: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1900: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1901: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1902: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1903: my $clientbrowser='unknown';
1904: my $clientversion='0';
1905: my $clientmathml='';
1906: my $clientunicode='0';
1907: for (my $i=0;$i<=$#browsertype;$i++) {
1908: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1909: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1910: $clientbrowser=$bname;
1911: $httpbrowser=~/$vreg/i;
1912: $clientversion=$1;
1913: $clientmathml=($clientversion>=$minv);
1914: $clientunicode=($clientversion>=$univ);
1915: }
1916: }
1917: my $clientos='unknown';
1918: if (($httpbrowser=~/linux/i) ||
1919: ($httpbrowser=~/unix/i) ||
1920: ($httpbrowser=~/ux/i) ||
1921: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1922: if (($httpbrowser=~/vax/i) ||
1923: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1924: if ($httpbrowser=~/next/i) { $clientos='next'; }
1925: if (($httpbrowser=~/mac/i) ||
1926: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1927: if ($httpbrowser=~/win/i) { $clientos='win'; }
1928: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1929: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1930: $clientunicode,$clientos,);
1931: }
1932:
1.32 matthew 1933: ###############################################################
1934: ## Authentication changing form generation subroutines ##
1935: ###############################################################
1936: ##
1937: ## All of the authform_xxxxxxx subroutines take their inputs in a
1938: ## hash, and have reasonable default values.
1939: ##
1940: ## formname = the name given in the <form> tag.
1.35 matthew 1941: #-------------------------------------------
1942:
1.45 matthew 1943: =pod
1944:
1.112 bowersj2 1945: =head1 Authentication Routines
1946:
1947: =over 4
1948:
1.648 raeburn 1949: =item * &authform_xxxxxx()
1.35 matthew 1950:
1951: The authform_xxxxxx subroutines provide javascript and html forms which
1952: handle some of the conveniences required for authentication forms.
1953: This is not an optimal method, but it works.
1954:
1955: =over 4
1956:
1.112 bowersj2 1957: =item * authform_header
1.35 matthew 1958:
1.112 bowersj2 1959: =item * authform_authorwarning
1.35 matthew 1960:
1.112 bowersj2 1961: =item * authform_nochange
1.35 matthew 1962:
1.112 bowersj2 1963: =item * authform_kerberos
1.35 matthew 1964:
1.112 bowersj2 1965: =item * authform_internal
1.35 matthew 1966:
1.112 bowersj2 1967: =item * authform_filesystem
1.35 matthew 1968:
1969: =back
1970:
1.648 raeburn 1971: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1972:
1.35 matthew 1973: =cut
1974:
1975: #-------------------------------------------
1.32 matthew 1976: sub authform_header{
1977: my %in = (
1978: formname => 'cu',
1.80 albertel 1979: kerb_def_dom => '',
1.32 matthew 1980: @_,
1981: );
1982: $in{'formname'} = 'document.' . $in{'formname'};
1983: my $result='';
1.80 albertel 1984:
1985: #---------------------------------------------- Code for upper case translation
1986: my $Javascript_toUpperCase;
1987: unless ($in{kerb_def_dom}) {
1988: $Javascript_toUpperCase =<<"END";
1989: switch (choice) {
1990: case 'krb': currentform.elements[choicearg].value =
1991: currentform.elements[choicearg].value.toUpperCase();
1992: break;
1993: default:
1994: }
1995: END
1996: } else {
1997: $Javascript_toUpperCase = "";
1998: }
1999:
1.165 raeburn 2000: my $radioval = "'nochange'";
1.591 raeburn 2001: if (defined($in{'curr_authtype'})) {
2002: if ($in{'curr_authtype'} ne '') {
2003: $radioval = "'".$in{'curr_authtype'}."arg'";
2004: }
1.174 matthew 2005: }
1.165 raeburn 2006: my $argfield = 'null';
1.591 raeburn 2007: if (defined($in{'mode'})) {
1.165 raeburn 2008: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2009: if (defined($in{'curr_autharg'})) {
2010: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2011: $argfield = "'$in{'curr_autharg'}'";
2012: }
2013: }
2014: }
2015: }
2016:
1.32 matthew 2017: $result.=<<"END";
2018: var current = new Object();
1.165 raeburn 2019: current.radiovalue = $radioval;
2020: current.argfield = $argfield;
1.32 matthew 2021:
2022: function changed_radio(choice,currentform) {
2023: var choicearg = choice + 'arg';
2024: // If a radio button in changed, we need to change the argfield
2025: if (current.radiovalue != choice) {
2026: current.radiovalue = choice;
2027: if (current.argfield != null) {
2028: currentform.elements[current.argfield].value = '';
2029: }
2030: if (choice == 'nochange') {
2031: current.argfield = null;
2032: } else {
2033: current.argfield = choicearg;
2034: switch(choice) {
2035: case 'krb':
2036: currentform.elements[current.argfield].value =
2037: "$in{'kerb_def_dom'}";
2038: break;
2039: default:
2040: break;
2041: }
2042: }
2043: }
2044: return;
2045: }
1.22 www 2046:
1.32 matthew 2047: function changed_text(choice,currentform) {
2048: var choicearg = choice + 'arg';
2049: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2050: $Javascript_toUpperCase
1.32 matthew 2051: // clear old field
2052: if ((current.argfield != choicearg) && (current.argfield != null)) {
2053: currentform.elements[current.argfield].value = '';
2054: }
2055: current.argfield = choicearg;
2056: }
2057: set_auth_radio_buttons(choice,currentform);
2058: return;
1.20 www 2059: }
1.32 matthew 2060:
2061: function set_auth_radio_buttons(newvalue,currentform) {
2062: var i=0;
2063: while (i < currentform.login.length) {
2064: if (currentform.login[i].value == newvalue) { break; }
2065: i++;
2066: }
2067: if (i == currentform.login.length) {
2068: return;
2069: }
2070: current.radiovalue = newvalue;
2071: currentform.login[i].checked = true;
2072: return;
2073: }
2074: END
2075: return $result;
2076: }
2077:
2078: sub authform_authorwarning{
2079: my $result='';
1.144 matthew 2080: $result='<i>'.
2081: &mt('As a general rule, only authors or co-authors should be '.
2082: 'filesystem authenticated '.
2083: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2084: return $result;
2085: }
2086:
2087: sub authform_nochange{
2088: my %in = (
2089: formname => 'document.cu',
2090: kerb_def_dom => 'MSU.EDU',
2091: @_,
2092: );
1.586 raeburn 2093: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2094: my $result;
2095: if (keys(%can_assign) == 0) {
2096: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2097: } else {
2098: $result = '<label>'.&mt('[_1] Do not change login data',
2099: '<input type="radio" name="login" value="nochange" '.
2100: 'checked="checked" onclick="'.
1.281 albertel 2101: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2102: '</label>';
1.586 raeburn 2103: }
1.32 matthew 2104: return $result;
2105: }
2106:
1.591 raeburn 2107: sub authform_kerberos {
1.32 matthew 2108: my %in = (
2109: formname => 'document.cu',
2110: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2111: kerb_def_auth => 'krb4',
1.32 matthew 2112: @_,
2113: );
1.586 raeburn 2114: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2115: $autharg,$jscall);
2116: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2117: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2118: $check5 = ' checked="on"';
1.80 albertel 2119: } else {
1.586 raeburn 2120: $check4 = ' checked="on"';
1.80 albertel 2121: }
1.165 raeburn 2122: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2123: if (defined($in{'curr_authtype'})) {
2124: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2125: $krbcheck = ' checked="on"';
1.623 raeburn 2126: if (defined($in{'mode'})) {
2127: if ($in{'mode'} eq 'modifyuser') {
2128: $krbcheck = '';
2129: }
2130: }
1.591 raeburn 2131: if (defined($in{'curr_kerb_ver'})) {
2132: if ($in{'curr_krb_ver'} eq '5') {
2133: $check5 = ' checked="on"';
2134: $check4 = '';
2135: } else {
2136: $check4 = ' checked="on"';
2137: $check5 = '';
2138: }
1.586 raeburn 2139: }
1.591 raeburn 2140: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2141: $krbarg = $in{'curr_autharg'};
2142: }
1.586 raeburn 2143: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2144: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2145: $result =
2146: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2147: $in{'curr_autharg'},$krbver);
2148: } else {
2149: $result =
2150: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2151: }
2152: return $result;
2153: }
2154: }
2155: } else {
2156: if ($authnum == 1) {
2157: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2158: }
2159: }
1.586 raeburn 2160: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2161: return;
1.587 raeburn 2162: } elsif ($authtype eq '') {
1.591 raeburn 2163: if (defined($in{'mode'})) {
1.587 raeburn 2164: if ($in{'mode'} eq 'modifycourse') {
2165: if ($authnum == 1) {
2166: $authtype = '<input type="hidden" name="login" value="krb">';
2167: }
2168: }
2169: }
1.586 raeburn 2170: }
2171: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2172: if ($authtype eq '') {
2173: $authtype = '<input type="radio" name="login" value="krb" '.
2174: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2175: $krbcheck.' />';
2176: }
2177: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2178: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2179: $in{'curr_authtype'} eq 'krb5') ||
2180: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2181: $in{'curr_authtype'} eq 'krb4')) {
2182: $result .= &mt
1.144 matthew 2183: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2184: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2185: '<label>'.$authtype,
1.281 albertel 2186: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2187: 'value="'.$krbarg.'" '.
1.144 matthew 2188: 'onchange="'.$jscall.'" />',
1.281 albertel 2189: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2190: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2191: '</label>');
1.586 raeburn 2192: } elsif ($can_assign{'krb4'}) {
2193: $result .= &mt
2194: ('[_1] Kerberos authenticated with domain [_2] '.
2195: '[_3] Version 4 [_4]',
2196: '<label>'.$authtype,
2197: '</label><input type="text" size="10" name="krbarg" '.
2198: 'value="'.$krbarg.'" '.
2199: 'onchange="'.$jscall.'" />',
2200: '<label><input type="hidden" name="krbver" value="4" />',
2201: '</label>');
2202: } elsif ($can_assign{'krb5'}) {
2203: $result .= &mt
2204: ('[_1] Kerberos authenticated with domain [_2] '.
2205: '[_3] Version 5 [_4]',
2206: '<label>'.$authtype,
2207: '</label><input type="text" size="10" name="krbarg" '.
2208: 'value="'.$krbarg.'" '.
2209: 'onchange="'.$jscall.'" />',
2210: '<label><input type="hidden" name="krbver" value="5" />',
2211: '</label>');
2212: }
1.32 matthew 2213: return $result;
2214: }
2215:
2216: sub authform_internal{
1.586 raeburn 2217: my %in = (
1.32 matthew 2218: formname => 'document.cu',
2219: kerb_def_dom => 'MSU.EDU',
2220: @_,
2221: );
1.586 raeburn 2222: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2223: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2224: if (defined($in{'curr_authtype'})) {
2225: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2226: if ($can_assign{'int'}) {
2227: $intcheck = 'checked="on" ';
1.623 raeburn 2228: if (defined($in{'mode'})) {
2229: if ($in{'mode'} eq 'modifyuser') {
2230: $intcheck = '';
2231: }
2232: }
1.591 raeburn 2233: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2234: $intarg = $in{'curr_autharg'};
2235: }
2236: } else {
2237: $result = &mt('Currently internally authenticated.');
2238: return $result;
1.165 raeburn 2239: }
2240: }
1.586 raeburn 2241: } else {
2242: if ($authnum == 1) {
2243: $authtype = '<input type="hidden" name="login" value="int">';
2244: }
2245: }
2246: if (!$can_assign{'int'}) {
2247: return;
1.587 raeburn 2248: } elsif ($authtype eq '') {
1.591 raeburn 2249: if (defined($in{'mode'})) {
1.587 raeburn 2250: if ($in{'mode'} eq 'modifycourse') {
2251: if ($authnum == 1) {
2252: $authtype = '<input type="hidden" name="login" value="int">';
2253: }
2254: }
2255: }
1.165 raeburn 2256: }
1.586 raeburn 2257: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2258: if ($authtype eq '') {
2259: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2260: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2261: }
1.605 bisitz 2262: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2263: $intarg.'" onchange="'.$jscall.'" />';
2264: $result = &mt
1.144 matthew 2265: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2266: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2267: $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 2268: return $result;
2269: }
2270:
2271: sub authform_local{
2272: my %in = (
2273: formname => 'document.cu',
2274: kerb_def_dom => 'MSU.EDU',
2275: @_,
2276: );
1.586 raeburn 2277: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2278: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2279: if (defined($in{'curr_authtype'})) {
2280: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2281: if ($can_assign{'loc'}) {
2282: $loccheck = 'checked="on" ';
1.623 raeburn 2283: if (defined($in{'mode'})) {
2284: if ($in{'mode'} eq 'modifyuser') {
2285: $loccheck = '';
2286: }
2287: }
1.591 raeburn 2288: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2289: $locarg = $in{'curr_autharg'};
2290: }
2291: } else {
2292: $result = &mt('Currently using local (institutional) authentication.');
2293: return $result;
1.165 raeburn 2294: }
2295: }
1.586 raeburn 2296: } else {
2297: if ($authnum == 1) {
2298: $authtype = '<input type="hidden" name="login" value="loc">';
2299: }
2300: }
2301: if (!$can_assign{'loc'}) {
2302: return;
1.587 raeburn 2303: } elsif ($authtype eq '') {
1.591 raeburn 2304: if (defined($in{'mode'})) {
1.587 raeburn 2305: if ($in{'mode'} eq 'modifycourse') {
2306: if ($authnum == 1) {
2307: $authtype = '<input type="hidden" name="login" value="loc">';
2308: }
2309: }
2310: }
1.165 raeburn 2311: }
1.586 raeburn 2312: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2313: if ($authtype eq '') {
2314: $authtype = '<input type="radio" name="login" value="loc" '.
2315: $loccheck.' onchange="'.$jscall.'" onclick="'.
2316: $jscall.'" />';
2317: }
2318: $autharg = '<input type="text" size="10" name="locarg" value="'.
2319: $locarg.'" onchange="'.$jscall.'" />';
2320: $result = &mt('[_1] Local Authentication with argument [_2]',
2321: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2322: return $result;
2323: }
2324:
2325: sub authform_filesystem{
2326: my %in = (
2327: formname => 'document.cu',
2328: kerb_def_dom => 'MSU.EDU',
2329: @_,
2330: );
1.586 raeburn 2331: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2332: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2333: if (defined($in{'curr_authtype'})) {
2334: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2335: if ($can_assign{'fsys'}) {
2336: $fsyscheck = 'checked="on" ';
1.623 raeburn 2337: if (defined($in{'mode'})) {
2338: if ($in{'mode'} eq 'modifyuser') {
2339: $fsyscheck = '';
2340: }
2341: }
1.586 raeburn 2342: } else {
2343: $result = &mt('Currently Filesystem Authenticated.');
2344: return $result;
2345: }
2346: }
2347: } else {
2348: if ($authnum == 1) {
2349: $authtype = '<input type="hidden" name="login" value="fsys">';
2350: }
2351: }
2352: if (!$can_assign{'fsys'}) {
2353: return;
1.587 raeburn 2354: } elsif ($authtype eq '') {
1.591 raeburn 2355: if (defined($in{'mode'})) {
1.587 raeburn 2356: if ($in{'mode'} eq 'modifycourse') {
2357: if ($authnum == 1) {
2358: $authtype = '<input type="hidden" name="login" value="fsys">';
2359: }
2360: }
2361: }
1.586 raeburn 2362: }
2363: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2364: if ($authtype eq '') {
2365: $authtype = '<input type="radio" name="login" value="fsys" '.
2366: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2367: $jscall.'" />';
2368: }
2369: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2370: ' onchange="'.$jscall.'" />';
2371: $result = &mt
1.144 matthew 2372: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2373: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2374: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2375: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2376: 'onchange="'.$jscall.'" />');
1.32 matthew 2377: return $result;
2378: }
2379:
1.586 raeburn 2380: sub get_assignable_auth {
2381: my ($dom) = @_;
2382: if ($dom eq '') {
2383: $dom = $env{'request.role.domain'};
2384: }
2385: my %can_assign = (
2386: krb4 => 1,
2387: krb5 => 1,
2388: int => 1,
2389: loc => 1,
2390: );
2391: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2392: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2393: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2394: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2395: my $context;
2396: if ($env{'request.role'} =~ /^au/) {
2397: $context = 'author';
2398: } elsif ($env{'request.role'} =~ /^dc/) {
2399: $context = 'domain';
2400: } elsif ($env{'request.course.id'}) {
2401: $context = 'course';
2402: }
2403: if ($context) {
2404: if (ref($authhash->{$context}) eq 'HASH') {
2405: %can_assign = %{$authhash->{$context}};
2406: }
2407: }
2408: }
2409: }
2410: my $authnum = 0;
2411: foreach my $key (keys(%can_assign)) {
2412: if ($can_assign{$key}) {
2413: $authnum ++;
2414: }
2415: }
2416: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2417: $authnum --;
2418: }
2419: return ($authnum,%can_assign);
2420: }
2421:
1.80 albertel 2422: ###############################################################
2423: ## Get Kerberos Defaults for Domain ##
2424: ###############################################################
2425: ##
2426: ## Returns default kerberos version and an associated argument
2427: ## as listed in file domain.tab. If not listed, provides
2428: ## appropriate default domain and kerberos version.
2429: ##
2430: #-------------------------------------------
2431:
2432: =pod
2433:
1.648 raeburn 2434: =item * &get_kerberos_defaults()
1.80 albertel 2435:
2436: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2437: version and domain. If not found, it defaults to version 4 and the
2438: domain of the server.
1.80 albertel 2439:
1.648 raeburn 2440: =over 4
2441:
1.80 albertel 2442: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2443:
1.648 raeburn 2444: =back
2445:
2446: =back
2447:
1.80 albertel 2448: =cut
2449:
2450: #-------------------------------------------
2451: sub get_kerberos_defaults {
2452: my $domain=shift;
1.641 raeburn 2453: my ($krbdef,$krbdefdom);
2454: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2455: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2456: $krbdef = $domdefaults{'auth_def'};
2457: $krbdefdom = $domdefaults{'auth_arg_def'};
2458: } else {
1.80 albertel 2459: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2460: my $krbdefdom=$1;
2461: $krbdefdom=~tr/a-z/A-Z/;
2462: $krbdef = "krb4";
2463: }
2464: return ($krbdef,$krbdefdom);
2465: }
1.112 bowersj2 2466:
1.32 matthew 2467:
1.46 matthew 2468: ###############################################################
2469: ## Thesaurus Functions ##
2470: ###############################################################
1.20 www 2471:
1.46 matthew 2472: =pod
1.20 www 2473:
1.112 bowersj2 2474: =head1 Thesaurus Functions
2475:
2476: =over 4
2477:
1.648 raeburn 2478: =item * &initialize_keywords()
1.46 matthew 2479:
2480: Initializes the package variable %Keywords if it is empty. Uses the
2481: package variable $thesaurus_db_file.
2482:
2483: =cut
2484:
2485: ###################################################
2486:
2487: sub initialize_keywords {
2488: return 1 if (scalar keys(%Keywords));
2489: # If we are here, %Keywords is empty, so fill it up
2490: # Make sure the file we need exists...
2491: if (! -e $thesaurus_db_file) {
2492: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2493: " failed because it does not exist");
2494: return 0;
2495: }
2496: # Set up the hash as a database
2497: my %thesaurus_db;
2498: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2499: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2500: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2501: $thesaurus_db_file);
2502: return 0;
2503: }
2504: # Get the average number of appearances of a word.
2505: my $avecount = $thesaurus_db{'average.count'};
2506: # Put keywords (those that appear > average) into %Keywords
2507: while (my ($word,$data)=each (%thesaurus_db)) {
2508: my ($count,undef) = split /:/,$data;
2509: $Keywords{$word}++ if ($count > $avecount);
2510: }
2511: untie %thesaurus_db;
2512: # Remove special values from %Keywords.
1.356 albertel 2513: foreach my $value ('total.count','average.count') {
2514: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2515: }
1.46 matthew 2516: return 1;
2517: }
2518:
2519: ###################################################
2520:
2521: =pod
2522:
1.648 raeburn 2523: =item * &keyword($word)
1.46 matthew 2524:
2525: Returns true if $word is a keyword. A keyword is a word that appears more
2526: than the average number of times in the thesaurus database. Calls
2527: &initialize_keywords
2528:
2529: =cut
2530:
2531: ###################################################
1.20 www 2532:
2533: sub keyword {
1.46 matthew 2534: return if (!&initialize_keywords());
2535: my $word=lc(shift());
2536: $word=~s/\W//g;
2537: return exists($Keywords{$word});
1.20 www 2538: }
1.46 matthew 2539:
2540: ###############################################################
2541:
2542: =pod
1.20 www 2543:
1.648 raeburn 2544: =item * &get_related_words()
1.46 matthew 2545:
1.160 matthew 2546: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2547: an array of words. If the keyword is not in the thesaurus, an empty array
2548: will be returned. The order of the words returned is determined by the
2549: database which holds them.
2550:
2551: Uses global $thesaurus_db_file.
2552:
2553: =cut
2554:
2555: ###############################################################
2556: sub get_related_words {
2557: my $keyword = shift;
2558: my %thesaurus_db;
2559: if (! -e $thesaurus_db_file) {
2560: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2561: "failed because the file does not exist");
2562: return ();
2563: }
2564: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2565: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2566: return ();
2567: }
2568: my @Words=();
1.429 www 2569: my $count=0;
1.46 matthew 2570: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2571: # The first element is the number of times
2572: # the word appears. We do not need it now.
1.429 www 2573: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2574: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2575: my $threshold=$mostfrequentcount/10;
2576: foreach my $possibleword (@RelatedWords) {
2577: my ($word,$wordcount)=split(/\,/,$possibleword);
2578: if ($wordcount>$threshold) {
2579: push(@Words,$word);
2580: $count++;
2581: if ($count>10) { last; }
2582: }
1.20 www 2583: }
2584: }
1.46 matthew 2585: untie %thesaurus_db;
2586: return @Words;
1.14 harris41 2587: }
1.46 matthew 2588:
1.112 bowersj2 2589: =pod
2590:
2591: =back
2592:
2593: =cut
1.61 www 2594:
2595: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2596: =pod
2597:
1.112 bowersj2 2598: =head1 User Name Functions
2599:
2600: =over 4
2601:
1.648 raeburn 2602: =item * &plainname($uname,$udom,$first)
1.81 albertel 2603:
1.112 bowersj2 2604: Takes a users logon name and returns it as a string in
1.226 albertel 2605: "first middle last generation" form
2606: if $first is set to 'lastname' then it returns it as
2607: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2608:
2609: =cut
1.61 www 2610:
1.295 www 2611:
1.81 albertel 2612: ###############################################################
1.61 www 2613: sub plainname {
1.226 albertel 2614: my ($uname,$udom,$first)=@_;
1.537 albertel 2615: return if (!defined($uname) || !defined($udom));
1.295 www 2616: my %names=&getnames($uname,$udom);
1.226 albertel 2617: my $name=&Apache::lonnet::format_name($names{'firstname'},
2618: $names{'middlename'},
2619: $names{'lastname'},
2620: $names{'generation'},$first);
2621: $name=~s/^\s+//;
1.62 www 2622: $name=~s/\s+$//;
2623: $name=~s/\s+/ /g;
1.353 albertel 2624: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2625: return $name;
1.61 www 2626: }
1.66 www 2627:
2628: # -------------------------------------------------------------------- Nickname
1.81 albertel 2629: =pod
2630:
1.648 raeburn 2631: =item * &nickname($uname,$udom)
1.81 albertel 2632:
2633: Gets a users name and returns it as a string as
2634:
2635: ""nickname""
1.66 www 2636:
1.81 albertel 2637: if the user has a nickname or
2638:
2639: "first middle last generation"
2640:
2641: if the user does not
2642:
2643: =cut
1.66 www 2644:
2645: sub nickname {
2646: my ($uname,$udom)=@_;
1.537 albertel 2647: return if (!defined($uname) || !defined($udom));
1.295 www 2648: my %names=&getnames($uname,$udom);
1.68 albertel 2649: my $name=$names{'nickname'};
1.66 www 2650: if ($name) {
2651: $name='"'.$name.'"';
2652: } else {
2653: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2654: $names{'lastname'}.' '.$names{'generation'};
2655: $name=~s/\s+$//;
2656: $name=~s/\s+/ /g;
2657: }
2658: return $name;
2659: }
2660:
1.295 www 2661: sub getnames {
2662: my ($uname,$udom)=@_;
1.537 albertel 2663: return if (!defined($uname) || !defined($udom));
1.433 albertel 2664: if ($udom eq 'public' && $uname eq 'public') {
2665: return ('lastname' => &mt('Public'));
2666: }
1.295 www 2667: my $id=$uname.':'.$udom;
2668: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2669: if ($cached) {
2670: return %{$names};
2671: } else {
2672: my %loadnames=&Apache::lonnet::get('environment',
2673: ['firstname','middlename','lastname','generation','nickname'],
2674: $udom,$uname);
2675: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2676: return %loadnames;
2677: }
2678: }
1.61 www 2679:
1.542 raeburn 2680: # -------------------------------------------------------------------- getemails
1.648 raeburn 2681:
1.542 raeburn 2682: =pod
2683:
1.648 raeburn 2684: =item * &getemails($uname,$udom)
1.542 raeburn 2685:
2686: Gets a user's email information and returns it as a hash with keys:
2687: notification, critnotification, permanentemail
2688:
2689: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2690: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2691:
1.648 raeburn 2692:
1.542 raeburn 2693: =cut
2694:
1.648 raeburn 2695:
1.466 albertel 2696: sub getemails {
2697: my ($uname,$udom)=@_;
2698: if ($udom eq 'public' && $uname eq 'public') {
2699: return;
2700: }
1.467 www 2701: if (!$udom) { $udom=$env{'user.domain'}; }
2702: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2703: my $id=$uname.':'.$udom;
2704: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2705: if ($cached) {
2706: return %{$names};
2707: } else {
2708: my %loadnames=&Apache::lonnet::get('environment',
2709: ['notification','critnotification',
2710: 'permanentemail'],
2711: $udom,$uname);
2712: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2713: return %loadnames;
2714: }
2715: }
2716:
1.551 albertel 2717: sub flush_email_cache {
2718: my ($uname,$udom)=@_;
2719: if (!$udom) { $udom =$env{'user.domain'}; }
2720: if (!$uname) { $uname=$env{'user.name'}; }
2721: return if ($udom eq 'public' && $uname eq 'public');
2722: my $id=$uname.':'.$udom;
2723: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2724: }
2725:
1.728 raeburn 2726: # -------------------------------------------------------------------- getlangs
2727:
2728: =pod
2729:
2730: =item * &getlangs($uname,$udom)
2731:
2732: Gets a user's language preference and returns it as a hash with key:
2733: language.
2734:
2735: =cut
2736:
2737:
2738: sub getlangs {
2739: my ($uname,$udom) = @_;
2740: if (!$udom) { $udom =$env{'user.domain'}; }
2741: if (!$uname) { $uname=$env{'user.name'}; }
2742: my $id=$uname.':'.$udom;
2743: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2744: if ($cached) {
2745: return %{$langs};
2746: } else {
2747: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2748: $udom,$uname);
2749: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2750: return %loadlangs;
2751: }
2752: }
2753:
2754: sub flush_langs_cache {
2755: my ($uname,$udom)=@_;
2756: if (!$udom) { $udom =$env{'user.domain'}; }
2757: if (!$uname) { $uname=$env{'user.name'}; }
2758: return if ($udom eq 'public' && $uname eq 'public');
2759: my $id=$uname.':'.$udom;
2760: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2761: }
2762:
1.61 www 2763: # ------------------------------------------------------------------ Screenname
1.81 albertel 2764:
2765: =pod
2766:
1.648 raeburn 2767: =item * &screenname($uname,$udom)
1.81 albertel 2768:
2769: Gets a users screenname and returns it as a string
2770:
2771: =cut
1.61 www 2772:
2773: sub screenname {
2774: my ($uname,$udom)=@_;
1.258 albertel 2775: if ($uname eq $env{'user.name'} &&
2776: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2777: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2778: return $names{'screenname'};
1.62 www 2779: }
2780:
1.212 albertel 2781:
1.62 www 2782: # ------------------------------------------------------------- Message Wrapper
2783:
2784: sub messagewrapper {
1.369 www 2785: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2786: return
1.441 albertel 2787: '<a href="/adm/email?compose=individual&'.
2788: 'recname='.$username.'&recdom='.$domain.
2789: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2790: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2791: }
2792: # --------------------------------------------------------------- Notes Wrapper
2793:
2794: sub noteswrapper {
2795: my ($link,$un,$do)=@_;
2796: return
2797: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2798: }
2799: # ------------------------------------------------------------- Aboutme Wrapper
2800:
2801: sub aboutmewrapper {
1.166 www 2802: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2803: if (!defined($username) && !defined($domain)) {
2804: return;
2805: }
1.205 www 2806: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2807: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2808: }
2809:
2810: # ------------------------------------------------------------ Syllabus Wrapper
2811:
2812:
2813: sub syllabuswrapper {
1.707 bisitz 2814: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2815: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2816: }
1.14 harris41 2817:
1.208 matthew 2818: sub track_student_link {
1.268 albertel 2819: my ($linktext,$sname,$sdom,$target,$start) = @_;
2820: my $link ="/adm/trackstudent?";
1.208 matthew 2821: my $title = 'View recent activity';
2822: if (defined($sname) && $sname !~ /^\s*$/ &&
2823: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2824: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2825: $title .= ' of this student';
1.268 albertel 2826: }
1.208 matthew 2827: if (defined($target) && $target !~ /^\s*$/) {
2828: $target = qq{target="$target"};
2829: } else {
2830: $target = '';
2831: }
1.268 albertel 2832: if ($start) { $link.='&start='.$start; }
1.554 albertel 2833: $title = &mt($title);
2834: $linktext = &mt($linktext);
1.448 albertel 2835: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2836: &help_open_topic('View_recent_activity');
1.208 matthew 2837: }
2838:
1.508 www 2839: # ===================================================== Display a student photo
2840:
2841:
1.509 albertel 2842: sub student_image_tag {
1.508 www 2843: my ($domain,$user)=@_;
2844: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2845: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2846: return '<img src="'.$imgsrc.'" align="right" />';
2847: } else {
2848: return '';
2849: }
2850: }
2851:
1.112 bowersj2 2852: =pod
2853:
2854: =back
2855:
2856: =head1 Access .tab File Data
2857:
2858: =over 4
2859:
1.648 raeburn 2860: =item * &languageids()
1.112 bowersj2 2861:
2862: returns list of all language ids
2863:
2864: =cut
2865:
1.14 harris41 2866: sub languageids {
1.16 harris41 2867: return sort(keys(%language));
1.14 harris41 2868: }
2869:
1.112 bowersj2 2870: =pod
2871:
1.648 raeburn 2872: =item * &languagedescription()
1.112 bowersj2 2873:
2874: returns description of a specified language id
2875:
2876: =cut
2877:
1.14 harris41 2878: sub languagedescription {
1.125 www 2879: my $code=shift;
2880: return ($supported_language{$code}?'* ':'').
2881: $language{$code}.
1.126 www 2882: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2883: }
2884:
2885: sub plainlanguagedescription {
2886: my $code=shift;
2887: return $language{$code};
2888: }
2889:
2890: sub supportedlanguagecode {
2891: my $code=shift;
2892: return $supported_language{$code};
1.97 www 2893: }
2894:
1.112 bowersj2 2895: =pod
2896:
1.648 raeburn 2897: =item * ©rightids()
1.112 bowersj2 2898:
2899: returns list of all copyrights
2900:
2901: =cut
2902:
2903: sub copyrightids {
2904: return sort(keys(%cprtag));
2905: }
2906:
2907: =pod
2908:
1.648 raeburn 2909: =item * ©rightdescription()
1.112 bowersj2 2910:
2911: returns description of a specified copyright id
2912:
2913: =cut
2914:
2915: sub copyrightdescription {
1.166 www 2916: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2917: }
1.197 matthew 2918:
2919: =pod
2920:
1.648 raeburn 2921: =item * &source_copyrightids()
1.192 taceyjo1 2922:
2923: returns list of all source copyrights
2924:
2925: =cut
2926:
2927: sub source_copyrightids {
2928: return sort(keys(%scprtag));
2929: }
2930:
2931: =pod
2932:
1.648 raeburn 2933: =item * &source_copyrightdescription()
1.192 taceyjo1 2934:
2935: returns description of a specified source copyright id
2936:
2937: =cut
2938:
2939: sub source_copyrightdescription {
2940: return &mt($scprtag{shift(@_)});
2941: }
1.112 bowersj2 2942:
2943: =pod
2944:
1.648 raeburn 2945: =item * &filecategories()
1.112 bowersj2 2946:
2947: returns list of all file categories
2948:
2949: =cut
2950:
2951: sub filecategories {
2952: return sort(keys(%category_extensions));
2953: }
2954:
2955: =pod
2956:
1.648 raeburn 2957: =item * &filecategorytypes()
1.112 bowersj2 2958:
2959: returns list of file types belonging to a given file
2960: category
2961:
2962: =cut
2963:
2964: sub filecategorytypes {
1.356 albertel 2965: my ($cat) = @_;
2966: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2967: }
2968:
2969: =pod
2970:
1.648 raeburn 2971: =item * &fileembstyle()
1.112 bowersj2 2972:
2973: returns embedding style for a specified file type
2974:
2975: =cut
2976:
2977: sub fileembstyle {
2978: return $fe{lc(shift(@_))};
1.169 www 2979: }
2980:
1.351 www 2981: sub filemimetype {
2982: return $fm{lc(shift(@_))};
2983: }
2984:
1.169 www 2985:
2986: sub filecategoryselect {
2987: my ($name,$value)=@_;
1.189 matthew 2988: return &select_form($value,$name,
1.169 www 2989: '' => &mt('Any category'),
2990: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2991: }
2992:
2993: =pod
2994:
1.648 raeburn 2995: =item * &filedescription()
1.112 bowersj2 2996:
2997: returns description for a specified file type
2998:
2999: =cut
3000:
3001: sub filedescription {
1.188 matthew 3002: my $file_description = $fd{lc(shift())};
3003: $file_description =~ s:([\[\]]):~$1:g;
3004: return &mt($file_description);
1.112 bowersj2 3005: }
3006:
3007: =pod
3008:
1.648 raeburn 3009: =item * &filedescriptionex()
1.112 bowersj2 3010:
3011: returns description for a specified file type with
3012: extra formatting
3013:
3014: =cut
3015:
3016: sub filedescriptionex {
3017: my $ex=shift;
1.188 matthew 3018: my $file_description = $fd{lc($ex)};
3019: $file_description =~ s:([\[\]]):~$1:g;
3020: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3021: }
3022:
3023: # End of .tab access
3024: =pod
3025:
3026: =back
3027:
3028: =cut
3029:
3030: # ------------------------------------------------------------------ File Types
3031: sub fileextensions {
3032: return sort(keys(%fe));
3033: }
3034:
1.97 www 3035: # ----------------------------------------------------------- Display Languages
3036: # returns a hash with all desired display languages
3037: #
3038:
3039: sub display_languages {
3040: my %languages=();
1.695 raeburn 3041: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3042: $languages{$lang}=1;
1.97 www 3043: }
3044: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3045: if ($env{'form.displaylanguage'}) {
1.356 albertel 3046: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3047: $languages{$lang}=1;
1.97 www 3048: }
3049: }
3050: return %languages;
1.14 harris41 3051: }
3052:
1.582 albertel 3053: sub languages {
3054: my ($possible_langs) = @_;
1.695 raeburn 3055: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3056: if (!ref($possible_langs)) {
3057: if( wantarray ) {
3058: return @preferred_langs;
3059: } else {
3060: return $preferred_langs[0];
3061: }
3062: }
3063: my %possibilities = map { $_ => 1 } (@$possible_langs);
3064: my @preferred_possibilities;
3065: foreach my $preferred_lang (@preferred_langs) {
3066: if (exists($possibilities{$preferred_lang})) {
3067: push(@preferred_possibilities, $preferred_lang);
3068: }
3069: }
3070: if( wantarray ) {
3071: return @preferred_possibilities;
3072: }
3073: return $preferred_possibilities[0];
3074: }
3075:
1.112 bowersj2 3076: ###############################################################
3077: ## Student Answer Attempts ##
3078: ###############################################################
3079:
3080: =pod
3081:
3082: =head1 Alternate Problem Views
3083:
3084: =over 4
3085:
1.648 raeburn 3086: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3087: $getattempt, $regexp, $gradesub)
3088:
3089: Return string with previous attempt on problem. Arguments:
3090:
3091: =over 4
3092:
3093: =item * $symb: Problem, including path
3094:
3095: =item * $username: username of the desired student
3096:
3097: =item * $domain: domain of the desired student
1.14 harris41 3098:
1.112 bowersj2 3099: =item * $course: Course ID
1.14 harris41 3100:
1.112 bowersj2 3101: =item * $getattempt: Leave blank for all attempts, otherwise put
3102: something
1.14 harris41 3103:
1.112 bowersj2 3104: =item * $regexp: if string matches this regexp, the string will be
3105: sent to $gradesub
1.14 harris41 3106:
1.112 bowersj2 3107: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3108:
1.112 bowersj2 3109: =back
1.14 harris41 3110:
1.112 bowersj2 3111: The output string is a table containing all desired attempts, if any.
1.16 harris41 3112:
1.112 bowersj2 3113: =cut
1.1 albertel 3114:
3115: sub get_previous_attempt {
1.43 ng 3116: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3117: my $prevattempts='';
1.43 ng 3118: no strict 'refs';
1.1 albertel 3119: if ($symb) {
1.3 albertel 3120: my (%returnhash)=
3121: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3122: if ($returnhash{'version'}) {
3123: my %lasthash=();
3124: my $version;
3125: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3126: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3127: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3128: }
1.1 albertel 3129: }
1.596 albertel 3130: $prevattempts=&start_data_table().&start_data_table_header_row();
3131: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3132: foreach my $key (sort(keys(%lasthash))) {
3133: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3134: if ($#parts > 0) {
1.31 albertel 3135: my $data=$parts[-1];
3136: pop(@parts);
1.596 albertel 3137: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3138: } else {
1.41 ng 3139: if ($#parts == 0) {
3140: $prevattempts.='<th>'.$parts[0].'</th>';
3141: } else {
3142: $prevattempts.='<th>'.$ign.'</th>';
3143: }
1.31 albertel 3144: }
1.16 harris41 3145: }
1.596 albertel 3146: $prevattempts.=&end_data_table_header_row();
1.40 ng 3147: if ($getattempt eq '') {
3148: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3149: $prevattempts.=&start_data_table_row().
3150: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3151: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3152: my $value = &format_previous_attempt_value($key,
3153: $returnhash{$version.':'.$key});
3154: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3155: }
1.596 albertel 3156: $prevattempts.=&end_data_table_row();
1.40 ng 3157: }
1.1 albertel 3158: }
1.596 albertel 3159: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3160: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3161: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3162: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3163: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3164: }
1.596 albertel 3165: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3166: } else {
1.596 albertel 3167: $prevattempts=
3168: &start_data_table().&start_data_table_row().
3169: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3170: &end_data_table_row().&end_data_table();
1.1 albertel 3171: }
3172: } else {
1.596 albertel 3173: $prevattempts=
3174: &start_data_table().&start_data_table_row().
3175: '<td>'.&mt('No data.').'</td>'.
3176: &end_data_table_row().&end_data_table();
1.1 albertel 3177: }
1.10 albertel 3178: }
3179:
1.581 albertel 3180: sub format_previous_attempt_value {
3181: my ($key,$value) = @_;
3182: if ($key =~ /timestamp/) {
3183: $value = &Apache::lonlocal::locallocaltime($value);
3184: } elsif (ref($value) eq 'ARRAY') {
3185: $value = '('.join(', ', @{ $value }).')';
3186: } else {
3187: $value = &unescape($value);
3188: }
3189: return $value;
3190: }
3191:
3192:
1.107 albertel 3193: sub relative_to_absolute {
3194: my ($url,$output)=@_;
3195: my $parser=HTML::TokeParser->new(\$output);
3196: my $token;
3197: my $thisdir=$url;
3198: my @rlinks=();
3199: while ($token=$parser->get_token) {
3200: if ($token->[0] eq 'S') {
3201: if ($token->[1] eq 'a') {
3202: if ($token->[2]->{'href'}) {
3203: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3204: }
3205: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3206: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3207: } elsif ($token->[1] eq 'base') {
3208: $thisdir=$token->[2]->{'href'};
3209: }
3210: }
3211: }
3212: $thisdir=~s-/[^/]*$--;
1.356 albertel 3213: foreach my $link (@rlinks) {
1.726 raeburn 3214: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3215: ($link=~/^\//) ||
3216: ($link=~/^javascript:/i) ||
3217: ($link=~/^mailto:/i) ||
3218: ($link=~/^\#/)) {
3219: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3220: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3221: }
3222: }
3223: # -------------------------------------------------- Deal with Applet codebases
3224: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3225: return $output;
3226: }
3227:
1.112 bowersj2 3228: =pod
3229:
1.648 raeburn 3230: =item * &get_student_view()
1.112 bowersj2 3231:
3232: show a snapshot of what student was looking at
3233:
3234: =cut
3235:
1.10 albertel 3236: sub get_student_view {
1.186 albertel 3237: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3238: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3239: my (%form);
1.10 albertel 3240: my @elements=('symb','courseid','domain','username');
3241: foreach my $element (@elements) {
1.186 albertel 3242: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3243: }
1.186 albertel 3244: if (defined($moreenv)) {
3245: %form=(%form,%{$moreenv});
3246: }
1.236 albertel 3247: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3248: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3249: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3250: $userview=~s/\<body[^\>]*\>//gi;
3251: $userview=~s/\<\/body\>//gi;
3252: $userview=~s/\<html\>//gi;
3253: $userview=~s/\<\/html\>//gi;
3254: $userview=~s/\<head\>//gi;
3255: $userview=~s/\<\/head\>//gi;
3256: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3257: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3258: if (wantarray) {
3259: return ($userview,$response);
3260: } else {
3261: return $userview;
3262: }
3263: }
3264:
3265: sub get_student_view_with_retries {
3266: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3267:
3268: my $ok = 0; # True if we got a good response.
3269: my $content;
3270: my $response;
3271:
3272: # Try to get the student_view done. within the retries count:
3273:
3274: do {
3275: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3276: $ok = $response->is_success;
3277: if (!$ok) {
3278: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3279: }
3280: $retries--;
3281: } while (!$ok && ($retries > 0));
3282:
3283: if (!$ok) {
3284: $content = ''; # On error return an empty content.
3285: }
1.651 www 3286: if (wantarray) {
3287: return ($content, $response);
3288: } else {
3289: return $content;
3290: }
1.11 albertel 3291: }
3292:
1.112 bowersj2 3293: =pod
3294:
1.648 raeburn 3295: =item * &get_student_answers()
1.112 bowersj2 3296:
3297: show a snapshot of how student was answering problem
3298:
3299: =cut
3300:
1.11 albertel 3301: sub get_student_answers {
1.100 sakharuk 3302: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3303: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3304: my (%moreenv);
1.11 albertel 3305: my @elements=('symb','courseid','domain','username');
3306: foreach my $element (@elements) {
1.186 albertel 3307: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3308: }
1.186 albertel 3309: $moreenv{'grade_target'}='answer';
3310: %moreenv=(%form,%moreenv);
1.497 raeburn 3311: $feedurl = &Apache::lonnet::clutter($feedurl);
3312: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3313: return $userview;
1.1 albertel 3314: }
1.116 albertel 3315:
3316: =pod
3317:
3318: =item * &submlink()
3319:
1.242 albertel 3320: Inputs: $text $uname $udom $symb $target
1.116 albertel 3321:
3322: Returns: A link to grades.pm such as to see the SUBM view of a student
3323:
3324: =cut
3325:
3326: ###############################################
3327: sub submlink {
1.242 albertel 3328: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3329: if (!($uname && $udom)) {
3330: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3331: &Apache::lonnet::whichuser($symb);
1.116 albertel 3332: if (!$symb) { $symb=$cursymb; }
3333: }
1.254 matthew 3334: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3335: $symb=&escape($symb);
1.242 albertel 3336: if ($target) { $target="target=\"$target\""; }
3337: return '<a href="/adm/grades?&command=submission&'.
3338: 'symb='.$symb.'&student='.$uname.
3339: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3340: }
3341: ##############################################
3342:
3343: =pod
3344:
3345: =item * &pgrdlink()
3346:
3347: Inputs: $text $uname $udom $symb $target
3348:
3349: Returns: A link to grades.pm such as to see the PGRD view of a student
3350:
3351: =cut
3352:
3353: ###############################################
3354: sub pgrdlink {
3355: my $link=&submlink(@_);
3356: $link=~s/(&command=submission)/$1&showgrading=yes/;
3357: return $link;
3358: }
3359: ##############################################
3360:
3361: =pod
3362:
3363: =item * &pprmlink()
3364:
3365: Inputs: $text $uname $udom $symb $target
3366:
3367: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3368: student and a specific resource
1.242 albertel 3369:
3370: =cut
3371:
3372: ###############################################
3373: sub pprmlink {
3374: my ($text,$uname,$udom,$symb,$target)=@_;
3375: if (!($uname && $udom)) {
3376: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3377: &Apache::lonnet::whichuser($symb);
1.242 albertel 3378: if (!$symb) { $symb=$cursymb; }
3379: }
1.254 matthew 3380: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3381: $symb=&escape($symb);
1.242 albertel 3382: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3383: return '<a href="/adm/parmset?command=set&'.
3384: 'symb='.$symb.'&uname='.$uname.
3385: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3386: }
3387: ##############################################
1.37 matthew 3388:
1.112 bowersj2 3389: =pod
3390:
3391: =back
3392:
3393: =cut
3394:
1.37 matthew 3395: ###############################################
1.51 www 3396:
3397:
3398: sub timehash {
1.687 raeburn 3399: my ($thistime) = @_;
3400: my $timezone = &Apache::lonlocal::gettimezone();
3401: my $dt = DateTime->from_epoch(epoch => $thistime)
3402: ->set_time_zone($timezone);
3403: my $wday = $dt->day_of_week();
3404: if ($wday == 7) { $wday = 0; }
3405: return ( 'second' => $dt->second(),
3406: 'minute' => $dt->minute(),
3407: 'hour' => $dt->hour(),
3408: 'day' => $dt->day_of_month(),
3409: 'month' => $dt->month(),
3410: 'year' => $dt->year(),
3411: 'weekday' => $wday,
3412: 'dayyear' => $dt->day_of_year(),
3413: 'dlsav' => $dt->is_dst() );
1.51 www 3414: }
3415:
1.370 www 3416: sub utc_string {
3417: my ($date)=@_;
1.371 www 3418: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3419: }
3420:
1.51 www 3421: sub maketime {
3422: my %th=@_;
1.687 raeburn 3423: my ($epoch_time,$timezone,$dt);
3424: $timezone = &Apache::lonlocal::gettimezone();
3425: eval {
3426: $dt = DateTime->new( year => $th{'year'},
3427: month => $th{'month'},
3428: day => $th{'day'},
3429: hour => $th{'hour'},
3430: minute => $th{'minute'},
3431: second => $th{'second'},
3432: time_zone => $timezone,
3433: );
3434: };
3435: if (!$@) {
3436: $epoch_time = $dt->epoch;
3437: if ($epoch_time) {
3438: return $epoch_time;
3439: }
3440: }
1.51 www 3441: return POSIX::mktime(
3442: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3443: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3444: }
3445:
3446: #########################################
1.51 www 3447:
3448: sub findallcourses {
1.482 raeburn 3449: my ($roles,$uname,$udom) = @_;
1.355 albertel 3450: my %roles;
3451: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3452: my %courses;
1.51 www 3453: my $now=time;
1.482 raeburn 3454: if (!defined($uname)) {
3455: $uname = $env{'user.name'};
3456: }
3457: if (!defined($udom)) {
3458: $udom = $env{'user.domain'};
3459: }
3460: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3461: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3462: if (!%roles) {
3463: %roles = (
3464: cc => 1,
3465: in => 1,
3466: ep => 1,
3467: ta => 1,
3468: cr => 1,
3469: st => 1,
3470: );
3471: }
3472: foreach my $entry (keys(%roleshash)) {
3473: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3474: if ($trole =~ /^cr/) {
3475: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3476: } else {
3477: next if (!exists($roles{$trole}));
3478: }
3479: if ($tend) {
3480: next if ($tend < $now);
3481: }
3482: if ($tstart) {
3483: next if ($tstart > $now);
3484: }
3485: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3486: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3487: if ($secpart eq '') {
3488: ($cnum,$role) = split(/_/,$cnumpart);
3489: $sec = 'none';
3490: $realsec = '';
3491: } else {
3492: $cnum = $cnumpart;
3493: ($sec,$role) = split(/_/,$secpart);
3494: $realsec = $sec;
1.490 raeburn 3495: }
1.482 raeburn 3496: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3497: }
3498: } else {
3499: foreach my $key (keys(%env)) {
1.483 albertel 3500: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3501: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3502: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3503: next if ($role eq 'ca' || $role eq 'aa');
3504: next if (%roles && !exists($roles{$role}));
3505: my ($starttime,$endtime)=split(/\./,$env{$key});
3506: my $active=1;
3507: if ($starttime) {
3508: if ($now<$starttime) { $active=0; }
3509: }
3510: if ($endtime) {
3511: if ($now>$endtime) { $active=0; }
3512: }
3513: if ($active) {
3514: if ($sec eq '') {
3515: $sec = 'none';
3516: }
3517: $courses{$cdom.'_'.$cnum}{$sec} =
3518: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3519: }
3520: }
1.51 www 3521: }
3522: }
1.474 raeburn 3523: return %courses;
1.51 www 3524: }
1.37 matthew 3525:
1.54 www 3526: ###############################################
1.474 raeburn 3527:
3528: sub blockcheck {
1.482 raeburn 3529: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3530:
3531: if (!defined($udom)) {
3532: $udom = $env{'user.domain'};
3533: }
3534: if (!defined($uname)) {
3535: $uname = $env{'user.name'};
3536: }
3537:
3538: # If uname and udom are for a course, check for blocks in the course.
3539:
3540: if (&Apache::lonnet::is_course($udom,$uname)) {
3541: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3542: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3543: return ($startblock,$endblock);
3544: }
1.474 raeburn 3545:
1.502 raeburn 3546: my $startblock = 0;
3547: my $endblock = 0;
1.482 raeburn 3548: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3549:
1.490 raeburn 3550: # If uname is for a user, and activity is course-specific, i.e.,
3551: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3552:
1.490 raeburn 3553: if (($activity eq 'boards' || $activity eq 'chat' ||
3554: $activity eq 'groups') && ($env{'request.course.id'})) {
3555: foreach my $key (keys(%live_courses)) {
3556: if ($key ne $env{'request.course.id'}) {
3557: delete($live_courses{$key});
3558: }
3559: }
3560: }
3561:
3562: my $otheruser = 0;
3563: my %own_courses;
3564: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3565: # Resource belongs to user other than current user.
3566: $otheruser = 1;
3567: # Gather courses for current user
3568: %own_courses =
3569: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3570: }
3571:
3572: # Gather active course roles - course coordinator, instructor,
3573: # exam proctor, ta, student, or custom role.
1.474 raeburn 3574:
3575: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3576: my ($cdom,$cnum);
3577: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3578: $cdom = $env{'course.'.$course.'.domain'};
3579: $cnum = $env{'course.'.$course.'.num'};
3580: } else {
1.490 raeburn 3581: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3582: }
3583: my $no_ownblock = 0;
3584: my $no_userblock = 0;
1.533 raeburn 3585: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3586: # Check if current user has 'evb' priv for this
3587: if (defined($own_courses{$course})) {
3588: foreach my $sec (keys(%{$own_courses{$course}})) {
3589: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3590: if ($sec ne 'none') {
3591: $checkrole .= '/'.$sec;
3592: }
3593: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3594: $no_ownblock = 1;
3595: last;
3596: }
3597: }
3598: }
3599: # if they have 'evb' priv and are currently not playing student
3600: next if (($no_ownblock) &&
3601: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3602: }
1.474 raeburn 3603: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3604: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3605: if ($sec ne 'none') {
1.482 raeburn 3606: $checkrole .= '/'.$sec;
1.474 raeburn 3607: }
1.490 raeburn 3608: if ($otheruser) {
3609: # Resource belongs to user other than current user.
3610: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3611: my ($trole,$tdom,$tnum,$tsec);
3612: my $entry = $live_courses{$course}{$sec};
3613: if ($entry =~ /^cr/) {
3614: ($trole,$tdom,$tnum,$tsec) =
3615: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3616: } else {
3617: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3618: }
3619: my ($spec,$area,$trest,%allroles,%userroles);
3620: $area = '/'.$tdom.'/'.$tnum;
3621: $trest = $tnum;
3622: if ($tsec ne '') {
3623: $area .= '/'.$tsec;
3624: $trest .= '/'.$tsec;
3625: }
3626: $spec = $trole.'.'.$area;
3627: if ($trole =~ /^cr/) {
3628: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3629: $tdom,$spec,$trest,$area);
3630: } else {
3631: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3632: $tdom,$spec,$trest,$area);
3633: }
3634: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3635: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3636: if ($1) {
3637: $no_userblock = 1;
3638: last;
3639: }
3640: }
1.490 raeburn 3641: } else {
3642: # Resource belongs to current user
3643: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3644: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3645: $no_ownblock = 1;
3646: last;
3647: }
1.474 raeburn 3648: }
3649: }
3650: # if they have the evb priv and are currently not playing student
1.482 raeburn 3651: next if (($no_ownblock) &&
1.491 albertel 3652: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3653: next if ($no_userblock);
1.474 raeburn 3654:
1.490 raeburn 3655: # Retrieve blocking times and identity of blocker for course
3656: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3657:
3658: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3659: if (($start != 0) &&
3660: (($startblock == 0) || ($startblock > $start))) {
3661: $startblock = $start;
3662: }
3663: if (($end != 0) &&
3664: (($endblock == 0) || ($endblock < $end))) {
3665: $endblock = $end;
3666: }
1.490 raeburn 3667: }
3668: return ($startblock,$endblock);
3669: }
3670:
3671: sub get_blocks {
3672: my ($setters,$activity,$cdom,$cnum) = @_;
3673: my $startblock = 0;
3674: my $endblock = 0;
3675: my $course = $cdom.'_'.$cnum;
3676: $setters->{$course} = {};
3677: $setters->{$course}{'staff'} = [];
3678: $setters->{$course}{'times'} = [];
3679: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3680: foreach my $record (keys(%records)) {
3681: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3682: if ($start <= time && $end >= time) {
3683: my ($staff_name,$staff_dom,$title,$blocks) =
3684: &parse_block_record($records{$record});
3685: if ($blocks->{$activity} eq 'on') {
3686: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3687: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3688: if ( ($startblock == 0) || ($startblock > $start) ) {
3689: $startblock = $start;
1.490 raeburn 3690: }
1.491 albertel 3691: if ( ($endblock == 0) || ($endblock < $end) ) {
3692: $endblock = $end;
1.474 raeburn 3693: }
3694: }
3695: }
3696: }
3697: return ($startblock,$endblock);
3698: }
3699:
3700: sub parse_block_record {
3701: my ($record) = @_;
3702: my ($setuname,$setudom,$title,$blocks);
3703: if (ref($record) eq 'HASH') {
3704: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3705: $title = &unescape($record->{'event'});
3706: $blocks = $record->{'blocks'};
3707: } else {
3708: my @data = split(/:/,$record,3);
3709: if (scalar(@data) eq 2) {
3710: $title = $data[1];
3711: ($setuname,$setudom) = split(/@/,$data[0]);
3712: } else {
3713: ($setuname,$setudom,$title) = @data;
3714: }
3715: $blocks = { 'com' => 'on' };
3716: }
3717: return ($setuname,$setudom,$title,$blocks);
3718: }
3719:
3720: sub build_block_table {
3721: my ($startblock,$endblock,$setters) = @_;
3722: my %lt = &Apache::lonlocal::texthash(
3723: 'cacb' => 'Currently active communication blocks',
3724: 'cour' => 'Course',
3725: 'dura' => 'Duration',
3726: 'blse' => 'Block set by'
3727: );
3728: my $output;
1.476 raeburn 3729: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3730: $output .= &start_data_table();
3731: $output .= '
3732: <tr>
3733: <th>'.$lt{'cour'}.'</th>
3734: <th>'.$lt{'dura'}.'</th>
3735: <th>'.$lt{'blse'}.'</th>
3736: </tr>
3737: ';
3738: foreach my $course (keys(%{$setters})) {
3739: my %courseinfo=&Apache::lonnet::coursedescription($course);
3740: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3741: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3742: my $fullname = &plainname($uname,$udom);
3743: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3744: && $env{'user.name'} ne 'public'
3745: && $env{'user.domain'} ne 'public') {
3746: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3747: }
1.474 raeburn 3748: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3749: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3750: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3751: $output .= &Apache::loncommon::start_data_table_row().
3752: '<td>'.$courseinfo{'description'}.'</td>'.
3753: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3754: '<td>'.$fullname.'</td>'.
1.474 raeburn 3755: &Apache::loncommon::end_data_table_row();
3756: }
3757: }
3758: $output .= &end_data_table();
3759: }
3760:
1.490 raeburn 3761: sub blocking_status {
3762: my ($activity,$uname,$udom) = @_;
3763: my %setters;
3764: my ($blocked,$output,$ownitem,$is_course);
3765: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3766: if ($startblock && $endblock) {
3767: $blocked = 1;
3768: if (wantarray) {
3769: my $category;
3770: if ($activity eq 'boards') {
3771: $category = 'Discussion posts in this course';
3772: } elsif ($activity eq 'blogs') {
3773: $category = 'Blogs';
3774: } elsif ($activity eq 'port') {
3775: if (defined($uname) && defined($udom)) {
3776: if ($uname eq $env{'user.name'} &&
3777: $udom eq $env{'user.domain'}) {
3778: $ownitem = 1;
3779: }
3780: }
3781: $is_course = &Apache::lonnet::is_course($udom,$uname);
3782: if ($ownitem) {
3783: $category = 'Your portfolio files';
3784: } elsif ($is_course) {
3785: my $coursedesc;
3786: foreach my $course (keys(%setters)) {
3787: my %courseinfo =
3788: &Apache::lonnet::coursedescription($course);
3789: $coursedesc = $courseinfo{'description'};
3790: }
3791: $category = "Group files in the course '$coursedesc'";
3792: } else {
3793: $category = 'Portfolio files belonging to ';
3794: if ($env{'user.name'} eq 'public' &&
3795: $env{'user.domain'} eq 'public') {
3796: $category .= &plainname($uname,$udom);
3797: } else {
3798: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3799: }
3800: }
3801: } elsif ($activity eq 'groups') {
3802: $category = 'Groups in this course';
3803: }
3804: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3805: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3806: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3807: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3808: $output .= &build_block_table($startblock,$endblock,\%setters);
3809: }
3810: }
3811: }
3812: if (wantarray) {
3813: return ($blocked,$output);
3814: } else {
3815: return $blocked;
3816: }
3817: }
3818:
1.60 matthew 3819: ###############################################
3820:
1.682 raeburn 3821: sub check_ip_acc {
3822: my ($acc)=@_;
3823: &Apache::lonxml::debug("acc is $acc");
3824: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3825: return 1;
3826: }
3827: my $allowed=0;
3828: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3829:
3830: my $name;
3831: foreach my $pattern (split(',',$acc)) {
3832: $pattern =~ s/^\s*//;
3833: $pattern =~ s/\s*$//;
3834: if ($pattern =~ /\*$/) {
3835: #35.8.*
3836: $pattern=~s/\*//;
3837: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3838: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3839: #35.8.3.[34-56]
3840: my $low=$2;
3841: my $high=$3;
3842: $pattern=$1;
3843: if ($ip =~ /^\Q$pattern\E/) {
3844: my $last=(split(/\./,$ip))[3];
3845: if ($last <=$high && $last >=$low) { $allowed=1; }
3846: }
3847: } elsif ($pattern =~ /^\*/) {
3848: #*.msu.edu
3849: $pattern=~s/\*//;
3850: if (!defined($name)) {
3851: use Socket;
3852: my $netaddr=inet_aton($ip);
3853: ($name)=gethostbyaddr($netaddr,AF_INET);
3854: }
3855: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3856: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3857: #127.0.0.1
3858: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3859: } else {
3860: #some.name.com
3861: if (!defined($name)) {
3862: use Socket;
3863: my $netaddr=inet_aton($ip);
3864: ($name)=gethostbyaddr($netaddr,AF_INET);
3865: }
3866: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3867: }
3868: if ($allowed) { last; }
3869: }
3870: return $allowed;
3871: }
3872:
3873: ###############################################
3874:
1.60 matthew 3875: =pod
3876:
1.112 bowersj2 3877: =head1 Domain Template Functions
3878:
3879: =over 4
3880:
3881: =item * &determinedomain()
1.60 matthew 3882:
3883: Inputs: $domain (usually will be undef)
3884:
1.63 www 3885: Returns: Determines which domain should be used for designs
1.60 matthew 3886:
3887: =cut
1.54 www 3888:
1.60 matthew 3889: ###############################################
1.63 www 3890: sub determinedomain {
3891: my $domain=shift;
1.531 albertel 3892: if (! $domain) {
1.60 matthew 3893: # Determine domain if we have not been given one
3894: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3895: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3896: if ($env{'request.role.domain'}) {
3897: $domain=$env{'request.role.domain'};
1.60 matthew 3898: }
3899: }
1.63 www 3900: return $domain;
3901: }
3902: ###############################################
1.517 raeburn 3903:
1.518 albertel 3904: sub devalidate_domconfig_cache {
3905: my ($udom)=@_;
3906: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3907: }
3908:
3909: # ---------------------- Get domain configuration for a domain
3910: sub get_domainconf {
3911: my ($udom) = @_;
3912: my $cachetime=1800;
3913: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3914: if (defined($cached)) { return %{$result}; }
3915:
3916: my %domconfig = &Apache::lonnet::get_dom('configuration',
3917: ['login','rolecolors'],$udom);
1.632 raeburn 3918: my (%designhash,%legacy);
1.518 albertel 3919: if (keys(%domconfig) > 0) {
3920: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3921: if (keys(%{$domconfig{'login'}})) {
3922: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3923: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3924: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3925: $designhash{$udom.'.login.'.$key.'_'.$img} =
3926: $domconfig{'login'}{$key}{$img};
3927: }
3928: } else {
3929: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3930: }
1.632 raeburn 3931: }
3932: } else {
3933: $legacy{'login'} = 1;
1.518 albertel 3934: }
1.632 raeburn 3935: } else {
3936: $legacy{'login'} = 1;
1.518 albertel 3937: }
3938: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3939: if (keys(%{$domconfig{'rolecolors'}})) {
3940: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3941: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3942: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3943: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3944: }
1.518 albertel 3945: }
3946: }
1.632 raeburn 3947: } else {
3948: $legacy{'rolecolors'} = 1;
1.518 albertel 3949: }
1.632 raeburn 3950: } else {
3951: $legacy{'rolecolors'} = 1;
1.518 albertel 3952: }
1.632 raeburn 3953: if (keys(%legacy) > 0) {
3954: my %legacyhash = &get_legacy_domconf($udom);
3955: foreach my $item (keys(%legacyhash)) {
3956: if ($item =~ /^\Q$udom\E\.login/) {
3957: if ($legacy{'login'}) {
3958: $designhash{$item} = $legacyhash{$item};
3959: }
3960: } else {
3961: if ($legacy{'rolecolors'}) {
3962: $designhash{$item} = $legacyhash{$item};
3963: }
1.518 albertel 3964: }
3965: }
3966: }
1.632 raeburn 3967: } else {
3968: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3969: }
3970: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3971: $cachetime);
3972: return %designhash;
3973: }
3974:
1.632 raeburn 3975: sub get_legacy_domconf {
3976: my ($udom) = @_;
3977: my %legacyhash;
3978: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
3979: my $designfile = $designdir.'/'.$udom.'.tab';
3980: if (-e $designfile) {
3981: if ( open (my $fh,"<$designfile") ) {
3982: while (my $line = <$fh>) {
3983: next if ($line =~ /^\#/);
3984: chomp($line);
3985: my ($key,$val)=(split(/\=/,$line));
3986: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
3987: }
3988: close($fh);
3989: }
3990: }
3991: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
3992: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
3993: }
3994: return %legacyhash;
3995: }
3996:
1.63 www 3997: =pod
3998:
1.112 bowersj2 3999: =item * &domainlogo()
1.63 www 4000:
4001: Inputs: $domain (usually will be undef)
4002:
4003: Returns: A link to a domain logo, if the domain logo exists.
4004: If the domain logo does not exist, a description of the domain.
4005:
4006: =cut
1.112 bowersj2 4007:
1.63 www 4008: ###############################################
4009: sub domainlogo {
1.517 raeburn 4010: my $domain = &determinedomain(shift);
1.518 albertel 4011: my %designhash = &get_domainconf($domain);
1.517 raeburn 4012: # See if there is a logo
4013: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4014: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4015: if ($imgsrc =~ m{^/(adm|res)/}) {
4016: if ($imgsrc =~ m{^/res/}) {
4017: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4018: &Apache::lonnet::repcopy($local_name);
4019: }
4020: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4021: }
4022: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4023: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4024: return &Apache::lonnet::domain($domain,'description');
1.59 www 4025: } else {
1.60 matthew 4026: return '';
1.59 www 4027: }
4028: }
1.63 www 4029: ##############################################
4030:
4031: =pod
4032:
1.112 bowersj2 4033: =item * &designparm()
1.63 www 4034:
4035: Inputs: $which parameter; $domain (usually will be undef)
4036:
4037: Returns: value of designparamter $which
4038:
4039: =cut
1.112 bowersj2 4040:
1.397 albertel 4041:
1.400 albertel 4042: ##############################################
1.397 albertel 4043: sub designparm {
4044: my ($which,$domain)=@_;
1.258 albertel 4045: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4046: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4047: return '#000000';
4048: }
1.635 raeburn 4049: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4050: return '#FFFFFF';
4051: }
4052: if ($which=~/\.tabbg$/) {
4053: return '#CCCCCC';
4054: }
4055: }
1.397 albertel 4056: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4057: return $env{'environment.color.'.$which};
1.96 www 4058: }
1.63 www 4059: $domain=&determinedomain($domain);
1.518 albertel 4060: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4061: my $output;
1.517 raeburn 4062: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4063: $output = $domdesign{$domain.'.'.$which};
1.63 www 4064: } else {
1.520 raeburn 4065: $output = $defaultdesign{$which};
4066: }
4067: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4068: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4069: if ($output =~ m{^/(adm|res)/}) {
4070: if ($output =~ m{^/res/}) {
4071: my $local_name = &Apache::lonnet::filelocation('',$output);
4072: &Apache::lonnet::repcopy($local_name);
4073: }
1.520 raeburn 4074: $output = &lonhttpdurl($output);
4075: }
1.63 www 4076: }
1.520 raeburn 4077: return $output;
1.63 www 4078: }
1.59 www 4079:
1.60 matthew 4080: ###############################################
4081: ###############################################
4082:
4083: =pod
4084:
1.112 bowersj2 4085: =back
4086:
1.549 albertel 4087: =head1 HTML Helpers
1.112 bowersj2 4088:
4089: =over 4
4090:
4091: =item * &bodytag()
1.60 matthew 4092:
4093: Returns a uniform header for LON-CAPA web pages.
4094:
4095: Inputs:
4096:
1.112 bowersj2 4097: =over 4
4098:
4099: =item * $title, A title to be displayed on the page.
4100:
4101: =item * $function, the current role (can be undef).
4102:
4103: =item * $addentries, extra parameters for the <body> tag.
4104:
4105: =item * $bodyonly, if defined, only return the <body> tag.
4106:
4107: =item * $domain, if defined, force a given domain.
4108:
4109: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4110: text interface only)
1.60 matthew 4111:
1.326 albertel 4112: =item * $customtitle, alternate text to use instead of $title
4113: in the title box that appears, this text
4114: is not auto translated like the $title is
1.309 albertel 4115:
4116: =item * $notopbar, if true, keep the 'what is this' info but remove the
4117: navigational links
1.317 albertel 4118:
1.338 albertel 4119: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4120:
4121: =item * $notitle, if true keep the nav controls, but remove the title bar
4122:
1.361 albertel 4123: =item * $no_inline_link, if true and in remote mode, don't show the
4124: 'Switch To Inline Menu' link
4125:
1.460 albertel 4126: =item * $args, optional argument valid values are
4127: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4128: inherit_jsmath -> when creating popup window in a page,
4129: should it have jsmath forced on by the
4130: current page
1.460 albertel 4131:
1.112 bowersj2 4132: =back
4133:
1.60 matthew 4134: Returns: A uniform header for LON-CAPA web pages.
4135: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4136: If $bodyonly is undef or zero, an html string containing a <body> tag and
4137: other decorations will be returned.
4138:
4139: =cut
4140:
1.54 www 4141: sub bodytag {
1.309 albertel 4142: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4143: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4144:
1.460 albertel 4145: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4146:
1.183 matthew 4147: $function = &get_users_function() if (!$function);
1.339 albertel 4148: my $img = &designparm($function.'.img',$domain);
4149: my $font = &designparm($function.'.font',$domain);
4150: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4151:
4152: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4153: 'bgcolor' => $pgbg,
1.339 albertel 4154: 'text' => $font,
4155: 'alink' => &designparm($function.'.alink',$domain),
4156: 'vlink' => &designparm($function.'.vlink',$domain),
4157: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4158: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4159:
1.63 www 4160: # role and realm
1.378 raeburn 4161: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4162: if ($role eq 'ca') {
1.479 albertel 4163: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4164: $realm = &plainname($rname,$rdom);
1.378 raeburn 4165: }
1.55 www 4166: # realm
1.258 albertel 4167: if ($env{'request.course.id'}) {
1.378 raeburn 4168: if ($env{'request.role'} !~ /^cr/) {
4169: $role = &Apache::lonnet::plaintext($role,&course_type());
4170: }
1.359 albertel 4171: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4172: } else {
4173: $role = &Apache::lonnet::plaintext($role);
1.54 www 4174: }
1.433 albertel 4175:
1.359 albertel 4176: if (!$realm) { $realm=' '; }
1.55 www 4177: # Set messages
1.60 matthew 4178: my $messages=&domainlogo($domain);
1.330 albertel 4179:
1.438 albertel 4180: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4181:
1.101 www 4182: # construct main body tag
1.359 albertel 4183: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4184: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4185:
1.530 albertel 4186: if ($bodyonly) {
1.60 matthew 4187: return $bodytag;
1.258 albertel 4188: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4189: # Accessibility
1.224 raeburn 4190:
1.337 albertel 4191: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4192: if (!$notitle) {
1.337 albertel 4193: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4194: }
4195: return $bodytag;
1.359 albertel 4196: }
4197:
1.410 albertel 4198: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4199: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4200: undef($role);
1.434 albertel 4201: } else {
4202: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4203: }
1.359 albertel 4204:
4205: my $roleinfo=(<<ENDROLE);
4206: <td class="LC_title_bar_who">
4207: <div class="LC_title_bar_name">
1.410 albertel 4208: $name
1.361 albertel 4209:
1.359 albertel 4210: </div>
4211: <div class="LC_title_bar_role">
1.361 albertel 4212: $role
1.359 albertel 4213: </div>
4214: <div class="LC_title_bar_realm">
1.361 albertel 4215: $realm
1.359 albertel 4216: </div>
1.206 albertel 4217: </td>
4218: ENDROLE
1.235 raeburn 4219:
1.359 albertel 4220: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4221: if ($customtitle) {
4222: $titleinfo = $customtitle;
4223: }
4224: #
4225: # Extra info if you are the DC
4226: my $dc_info = '';
4227: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4228: $env{'course.'.$env{'request.course.id'}.
4229: '.domain'}.'/'})) {
4230: my $cid = $env{'request.course.id'};
4231: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4232: $dc_info =~ s/\s+$//;
1.359 albertel 4233: $dc_info = '('.$dc_info.')';
4234: }
4235:
1.644 www 4236: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4237: # No Remote
1.258 albertel 4238: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4239: $forcereg=1;
4240: }
4241:
4242: if (!$customtitle && $env{'request.state'} eq 'construct') {
4243: # this is for resources; directories have customtitle, and crumbs
4244: # and select recent are created in lonpubdir.pm
1.229 albertel 4245: my ($uname,$thisdisfn)=
1.258 albertel 4246: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4247: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4248: $formaction=~s/\/+/\//g;
4249:
1.359 albertel 4250: my $parentpath = '';
4251: my $lastitem = '';
4252: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4253: $parentpath = $1;
4254: $lastitem = $2;
4255: } else {
4256: $lastitem = $thisdisfn;
4257: }
4258: $titleinfo =
1.640 bisitz 4259: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4260: .'<b>'.&mt('Construction Space').'</b>: '
4261: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4262: .'" target="_top"><tt><b>'
1.705 tempelho 4263: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4264: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4265: .'</form>'
4266: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4267: }
1.359 albertel 4268:
1.337 albertel 4269: my $titletable;
1.338 albertel 4270: if (!$notitle) {
1.337 albertel 4271: $titletable =
1.359 albertel 4272: '<table id="LC_title_bar">'.
4273: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4274: '</tr></table>';
1.337 albertel 4275: }
1.359 albertel 4276: if ($notopbar) {
4277: $bodytag .= $titletable;
4278: } else {
4279: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4280: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4281: $titletable);
1.272 raeburn 4282: } else {
1.336 albertel 4283: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4284: $titletable;
1.272 raeburn 4285: }
1.235 raeburn 4286: }
4287: return $bodytag;
1.94 www 4288: }
1.95 www 4289:
1.93 www 4290: #
1.95 www 4291: # Top frame rendering, Remote is up
1.93 www 4292: #
1.359 albertel 4293:
1.517 raeburn 4294: my $imgsrc = $img;
4295: if ($img =~ /^\/adm/) {
1.575 albertel 4296: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4297: }
4298: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4299:
1.305 www 4300: # Explicit link to get inline menu
1.361 albertel 4301: my $menu= ($no_inline_link?''
4302: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4303: #
1.338 albertel 4304: if ($notitle) {
1.337 albertel 4305: return $bodytag;
4306: }
1.94 www 4307: return(<<ENDBODY);
1.60 matthew 4308: $bodytag
1.359 albertel 4309: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4310: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4311: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4312: </tr>
1.359 albertel 4313: <tr><td>$titleinfo $dc_info $menu</td>
4314: $roleinfo
1.368 albertel 4315: </tr>
1.356 albertel 4316: </table>
1.54 www 4317: ENDBODY
1.182 matthew 4318: }
4319:
1.330 albertel 4320: sub make_attr_string {
4321: my ($register,$attr_ref) = @_;
4322:
4323: if ($attr_ref && !ref($attr_ref)) {
4324: die("addentries Must be a hash ref ".
4325: join(':',caller(1))." ".
4326: join(':',caller(0))." ");
4327: }
4328:
4329: if ($register) {
1.339 albertel 4330: my ($on_load,$on_unload);
4331: foreach my $key (keys(%{$attr_ref})) {
4332: if (lc($key) eq 'onload') {
4333: $on_load.=$attr_ref->{$key}.';';
4334: delete($attr_ref->{$key});
4335:
4336: } elsif (lc($key) eq 'onunload') {
4337: $on_unload.=$attr_ref->{$key}.';';
4338: delete($attr_ref->{$key});
4339: }
4340: }
4341: $attr_ref->{'onload'} =
4342: &Apache::lonmenu::loadevents(). $on_load;
4343: $attr_ref->{'onunload'}=
4344: &Apache::lonmenu::unloadevents().$on_unload;
4345: }
4346:
4347: # Accessibility font enhance
4348: if ($env{'browser.fontenhance'} eq 'on') {
4349: my $style;
4350: foreach my $key (keys(%{$attr_ref})) {
4351: if (lc($key) eq 'style') {
4352: $style.=$attr_ref->{$key}.';';
4353: delete($attr_ref->{$key});
4354: }
4355: }
4356: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4357: }
1.339 albertel 4358:
4359: if ($env{'browser.blackwhite'} eq 'on') {
4360: delete($attr_ref->{'font'});
4361: delete($attr_ref->{'link'});
4362: delete($attr_ref->{'alink'});
4363: delete($attr_ref->{'vlink'});
4364: delete($attr_ref->{'bgcolor'});
4365: delete($attr_ref->{'background'});
4366: }
4367:
1.330 albertel 4368: my $attr_string;
4369: foreach my $attr (keys(%$attr_ref)) {
4370: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4371: }
4372: return $attr_string;
4373: }
4374:
4375:
1.182 matthew 4376: ###############################################
1.251 albertel 4377: ###############################################
4378:
4379: =pod
4380:
4381: =item * &endbodytag()
4382:
4383: Returns a uniform footer for LON-CAPA web pages.
4384:
1.635 raeburn 4385: Inputs: 1 - optional reference to an args hash
4386: If in the hash, key for noredirectlink has a value which evaluates to true,
4387: a 'Continue' link is not displayed if the page contains an
4388: internal redirect in the <head></head> section,
4389: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4390:
4391: =cut
4392:
4393: sub endbodytag {
1.635 raeburn 4394: my ($args) = @_;
1.251 albertel 4395: my $endbodytag='</body>';
1.269 albertel 4396: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4397: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4398: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4399: $endbodytag=
4400: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4401: &mt('Continue').'</a>'.
4402: $endbodytag;
4403: }
1.315 albertel 4404: }
1.251 albertel 4405: return $endbodytag;
4406: }
4407:
1.352 albertel 4408: =pod
4409:
4410: =item * &standard_css()
4411:
4412: Returns a style sheet
4413:
4414: Inputs: (all optional)
4415: domain -> force to color decorate a page for a specific
4416: domain
4417: function -> force usage of a specific rolish color scheme
4418: bgcolor -> override the default page bgcolor
4419:
4420: =cut
4421:
1.343 albertel 4422: sub standard_css {
1.345 albertel 4423: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4424: $function = &get_users_function() if (!$function);
4425: my $img = &designparm($function.'.img', $domain);
4426: my $tabbg = &designparm($function.'.tabbg', $domain);
4427: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4428: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4429: my $pgbg_or_bgcolor =
4430: $bgcolor ||
1.352 albertel 4431: &designparm($function.'.pgbg', $domain);
1.382 albertel 4432: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4433: my $alink = &designparm($function.'.alink', $domain);
4434: my $vlink = &designparm($function.'.vlink', $domain);
4435: my $link = &designparm($function.'.link', $domain);
4436:
1.704 muellerd 4437: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4438: my $bgcol = &designparm('login.bgcol',$domain);
4439: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4440:
1.602 albertel 4441: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4442: my $mono = 'monospace';
1.352 albertel 4443: my $data_table_head = $tabbg;
4444: my $data_table_light = '#EEEEEE';
1.470 banghart 4445: my $data_table_dark = '#DDDDDD';
4446: my $data_table_darker = '#CCCCCC';
1.349 albertel 4447: my $data_table_highlight = '#FFFF00';
1.352 albertel 4448: my $mail_new = '#FFBB77';
4449: my $mail_new_hover = '#DD9955';
4450: my $mail_read = '#BBBB77';
4451: my $mail_read_hover = '#999944';
4452: my $mail_replied = '#AAAA88';
4453: my $mail_replied_hover = '#888855';
4454: my $mail_other = '#99BBBB';
4455: my $mail_other_hover = '#669999';
1.391 albertel 4456: my $table_header = '#DDDDDD';
1.489 raeburn 4457: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4458: my $lg_border_color = '#C8C8C8';
1.392 albertel 4459:
1.608 albertel 4460: my $border = ($env{'browser.type'} eq 'explorer' ||
4461: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4462: : '0px 3px 0px 4px';
1.448 albertel 4463:
1.523 albertel 4464:
1.343 albertel 4465: return <<END;
1.698 harmsja 4466: body{
4467: font-family: $sans;
4468: line-height:130%;
1.701 harmsja 4469: font-size:0.83em;
1.698 harmsja 4470: color:$font;
4471: }
1.701 harmsja 4472: a:link, a:visited { font-size:100%; }
1.698 harmsja 4473:
1.343 albertel 4474: a:focus { color: red; background: yellow }
1.510 albertel 4475: table.thinborder,
4476: table.thinborder tr th {
4477: border-style: solid;
4478: border-width: 1px;
1.698 harmsja 4479: border-color: $lg_border_color;
1.510 albertel 4480: background: $tabbg;
4481: }
1.523 albertel 4482: table.thinborder tr td {
1.510 albertel 4483: border-style: solid;
1.698 harmsja 4484: border-width: 1px;
4485: border-color: $lg_border_color;
1.510 albertel 4486: }
1.426 albertel 4487:
1.343 albertel 4488: form, .inline { display: inline; }
1.721 harmsja 4489:
4490: .LC_center { text-align: center; }
4491: .LC_left { text-align:left; }
4492: .LC_right {text-align:right;}
4493: .LC_middle {vertical-align:middle;}
4494: .LC_top {vertical-align:top;}
4495: .LC_bottom {vertical-align:bottom;}
4496:
4497: /* just for tests */
4498: .LC_300Box { width:300px; }
4499: .LC_200Box {width:200px; }
4500: .LC_500Box {width:500px; }
4501: .LC_600Box {width:600px; }
1.741 ! harmsja 4502: .LC_800Box {width:800px;}
1.721 harmsja 4503: /* end */
4504:
1.593 albertel 4505: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4506: .LC_error {
4507: color: red;
4508: font-size: larger;
4509: }
1.457 albertel 4510: .LC_warning,
4511: .LC_diff_removed {
1.733 bisitz 4512: color: red;
1.394 albertel 4513: }
1.532 albertel 4514:
4515: .LC_info,
1.457 albertel 4516: .LC_success,
4517: .LC_diff_added {
1.350 albertel 4518: color: green;
4519: }
1.543 albertel 4520: .LC_unknown {
4521: color: yellow;
4522: }
4523:
1.440 albertel 4524: .LC_icon {
4525: border: 0px;
4526: }
1.539 albertel 4527: .LC_indexer_icon {
4528: border: 0px;
4529: height: 22px;
4530: }
1.543 albertel 4531: .LC_docs_spacer {
4532: width: 25px;
4533: height: 1px;
4534: border: 0px;
4535: }
1.346 albertel 4536:
1.532 albertel 4537: .LC_internal_info {
1.735 bisitz 4538: color: #999999;
1.532 albertel 4539: }
4540:
1.458 albertel 4541: table.LC_pastsubmission {
4542: border: 1px solid black;
4543: margin: 2px;
4544: }
4545:
1.606 albertel 4546: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4547: width: 100%;
4548: background: $pgbg;
1.392 albertel 4549: border: 2px;
1.402 albertel 4550: border-collapse: separate;
1.403 albertel 4551: padding: 0px;
1.345 albertel 4552: }
1.392 albertel 4553:
1.606 albertel 4554: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4555: table#LC_title_bar.LC_with_remote {
1.359 albertel 4556: width: 100%;
1.392 albertel 4557: border-color: $pgbg;
4558: border-style: solid;
4559: border-width: $border;
4560:
1.379 albertel 4561: background: $pgbg;
4562: font-family: $sans;
1.392 albertel 4563: border-collapse: collapse;
1.403 albertel 4564: padding: 0px;
1.359 albertel 4565: }
1.409 albertel 4566: table.LC_docs_path {
4567: width: 100%;
4568: border: 0;
4569: background: $pgbg;
4570: font-family: $sans;
4571: border-collapse: collapse;
4572: padding: 0px;
4573: }
4574:
1.359 albertel 4575: table#LC_title_bar td {
4576: background: $tabbg;
4577: }
4578: table#LC_title_bar td.LC_title_bar_who {
4579: background: $tabbg;
4580: color: $font;
1.427 albertel 4581: font: small $sans;
1.359 albertel 4582: text-align: right;
4583: }
1.469 banghart 4584: span.LC_metadata {
4585: font-family: $sans;
4586: }
1.359 albertel 4587: span.LC_title_bar_title {
1.416 albertel 4588: font: bold x-large $sans;
1.359 albertel 4589: }
4590: table#LC_title_bar td.LC_title_bar_domain_logo {
4591: background: $sidebg;
4592: text-align: right;
1.368 albertel 4593: padding: 0px;
4594: }
4595: table#LC_title_bar td.LC_title_bar_role_logo {
4596: background: $sidebg;
4597: padding: 0px;
1.359 albertel 4598: }
4599:
1.706 harmsja 4600: table#LC_menubuttons img{
1.346 albertel 4601: border: 0px;
4602: }
1.345 albertel 4603: table#LC_top_nav td {
4604: background: $tabbg;
1.392 albertel 4605: border: 0px;
1.407 albertel 4606: font-size: small;
1.706 harmsja 4607: vertical-align:top;
4608: padding:2px 5px 2px 5px;
1.345 albertel 4609: }
4610: table#LC_top_nav td a, div#LC_top_nav a {
4611: color: $font;
4612: font-family: $sans;
4613: }
1.364 albertel 4614: table#LC_top_nav td.LC_top_nav_logo {
4615: background: $tabbg;
1.432 albertel 4616: text-align: left;
1.408 albertel 4617: white-space: nowrap;
1.432 albertel 4618: width: 31px;
1.408 albertel 4619: }
4620: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4621: border: 0px;
1.408 albertel 4622: vertical-align: bottom;
1.364 albertel 4623: }
1.432 albertel 4624: table#LC_top_nav td.LC_top_nav_exit,
4625: table#LC_top_nav td.LC_top_nav_help {
4626: width: 2.0em;
4627: }
1.442 albertel 4628: table#LC_top_nav td.LC_top_nav_login {
4629: width: 4.0em;
4630: text-align: center;
4631: }
1.409 albertel 4632: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4633: background: $tabbg;
4634: color: $font;
4635: font-family: $sans;
1.358 albertel 4636: font-size: smaller;
1.357 albertel 4637: }
1.411 albertel 4638: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4639: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4640: background: $tabbg;
4641: color: $font;
4642: font-family: $sans;
4643: font-size: larger;
4644: text-align: right;
4645: }
1.383 albertel 4646: td.LC_table_cell_checkbox {
4647: text-align: center;
4648: }
1.522 albertel 4649: table#LC_mainmenu td.LC_mainmenu_column {
4650: vertical-align: top;
4651: }
4652:
1.705 tempelho 4653: .LC_fontsize_small
4654: {
4655: font-size: 70%;
4656: }
4657:
4658: .LC_fontsize_medium
4659: {
4660: font-size: 85%;
4661: }
4662:
4663: .LC_fontsize_large
4664: {
4665: font-size: 120%;
4666: }
4667:
4668: .LC_fontcolor_red
4669: {
4670: color: #FF0000;
4671: }
4672:
1.346 albertel 4673: .LC_menubuttons_inline_text {
4674: color: $font;
4675: font-family: $sans;
1.698 harmsja 4676: font-size: 90%;
1.701 harmsja 4677: padding-left:3px;
1.346 albertel 4678: }
4679:
1.526 www 4680: .LC_menubuttons_link {
4681: text-decoration: none;
4682: }
1.698 harmsja 4683: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4684: .LC_menubuttons_category {
1.521 www 4685: color: $font;
1.526 www 4686: background: $pgbg;
1.521 www 4687: font-family: $sans;
4688: font-size: larger;
4689: font-weight: bold;
4690: }
4691:
1.346 albertel 4692: td.LC_menubuttons_text {
1.701 harmsja 4693: color: $font;
1.346 albertel 4694: }
1.706 harmsja 4695:
4696:
1.526 www 4697:
1.346 albertel 4698: .LC_current_location {
4699: font-family: $sans;
4700: background: $tabbg;
4701: }
4702: .LC_new_mail {
4703: font-family: $sans;
1.634 www 4704: background: $tabbg;
1.346 albertel 4705: font-weight: bold;
4706: }
1.347 albertel 4707:
1.526 www 4708:
1.527 www 4709: .LC_dropadd_labeltext {
4710: font-family: $sans;
4711: text-align: right;
4712: }
4713:
4714: .LC_preferences_labeltext {
4715: font-family: $sans;
4716: text-align: right;
4717: }
4718:
1.666 raeburn 4719: .LC_roleslog_note {
1.701 harmsja 4720: font-size: small;
1.666 raeburn 4721: }
4722:
1.715 raeburn 4723: .LC_mail_functions {
4724: font-weight: bold;
4725: }
4726:
1.440 albertel 4727: table.LC_aboutme_port {
4728: border: 0px;
4729: border-collapse: collapse;
4730: border-spacing: 0px;
4731: }
1.349 albertel 4732: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4733: border: 1px solid #000000;
1.402 albertel 4734: border-collapse: separate;
1.426 albertel 4735: border-spacing: 1px;
1.610 albertel 4736: background: $pgbg;
1.347 albertel 4737: }
1.422 albertel 4738: .LC_data_table_dense {
4739: font-size: small;
4740: }
1.507 raeburn 4741: table.LC_nested_outer {
4742: border: 1px solid #000000;
1.589 raeburn 4743: border-collapse: collapse;
1.507 raeburn 4744: border-spacing: 0px;
4745: width: 100%;
4746: }
4747: table.LC_nested {
4748: border: 0px;
1.589 raeburn 4749: border-collapse: collapse;
1.507 raeburn 4750: border-spacing: 0px;
4751: width: 100%;
4752: }
1.523 albertel 4753: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4754: table.LC_prior_tries tr th {
1.349 albertel 4755: font-weight: bold;
4756: background-color: $data_table_head;
1.701 harmsja 4757: font-size:90%;
1.347 albertel 4758: }
1.711 raeburn 4759: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4760: background-color: #CCCCCC;
1.711 raeburn 4761: font-weight: bold;
4762: text-align: left;
4763: }
1.610 albertel 4764: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4765: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4766: table.LC_aboutme_port tr td {
1.349 albertel 4767: background-color: $data_table_light;
1.425 albertel 4768: padding: 2px;
1.347 albertel 4769: }
1.610 albertel 4770: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4771: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4772: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4773: background-color: $data_table_dark;
1.709 bisitz 4774: padding: 2px;
1.347 albertel 4775: }
1.425 albertel 4776: table.LC_data_table tr.LC_data_table_highlight td {
4777: background-color: $data_table_darker;
4778: }
1.639 raeburn 4779: table.LC_data_table tr td.LC_leftcol_header {
4780: background-color: $data_table_head;
4781: font-weight: bold;
4782: }
1.451 albertel 4783: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4784: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4785: background-color: #FFFFFF;
1.421 albertel 4786: font-weight: bold;
4787: font-style: italic;
4788: text-align: center;
4789: padding: 8px;
1.347 albertel 4790: }
1.507 raeburn 4791: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4792: padding: 4ex
4793: }
1.507 raeburn 4794: table.LC_nested_outer tr th {
4795: font-weight: bold;
4796: background-color: $data_table_head;
1.701 harmsja 4797: font-size: small;
1.507 raeburn 4798: border-bottom: 1px solid #000000;
4799: }
4800: table.LC_nested_outer tr td.LC_subheader {
4801: background-color: $data_table_head;
4802: font-weight: bold;
4803: font-size: small;
4804: border-bottom: 1px solid #000000;
4805: text-align: right;
1.451 albertel 4806: }
1.507 raeburn 4807: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4808: background-color: #CCCCCC;
1.451 albertel 4809: font-weight: bold;
4810: font-size: small;
1.507 raeburn 4811: text-align: center;
4812: }
1.589 raeburn 4813: table.LC_nested tr.LC_info_row td.LC_left_item,
4814: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4815: text-align: left;
1.451 albertel 4816: }
1.507 raeburn 4817: table.LC_nested td {
1.735 bisitz 4818: background-color: #FFFFFF;
1.451 albertel 4819: font-size: small;
1.507 raeburn 4820: }
4821: table.LC_nested_outer tr th.LC_right_item,
4822: table.LC_nested tr.LC_info_row td.LC_right_item,
4823: table.LC_nested tr.LC_odd_row td.LC_right_item,
4824: table.LC_nested tr td.LC_right_item {
1.451 albertel 4825: text-align: right;
4826: }
4827:
1.507 raeburn 4828: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4829: background-color: #EEEEEE;
1.451 albertel 4830: }
4831:
1.473 raeburn 4832: table.LC_createuser {
4833: }
4834:
4835: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4836: font-size: small;
1.473 raeburn 4837: }
4838:
4839: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4840: background-color: #CCCCCC;
1.473 raeburn 4841: font-weight: bold;
4842: text-align: center;
4843: }
4844:
1.349 albertel 4845: table.LC_calendar {
4846: border: 1px solid #000000;
4847: border-collapse: collapse;
4848: }
4849: table.LC_calendar_pickdate {
4850: font-size: xx-small;
4851: }
4852: table.LC_calendar tr td {
4853: border: 1px solid #000000;
4854: vertical-align: top;
4855: }
4856: table.LC_calendar tr td.LC_calendar_day_empty {
4857: background-color: $data_table_dark;
4858: }
4859: table.LC_calendar tr td.LC_calendar_day_current {
4860: background-color: $data_table_highlight;
4861: }
4862:
4863: table.LC_mail_list tr.LC_mail_new {
4864: background-color: $mail_new;
4865: }
4866: table.LC_mail_list tr.LC_mail_new:hover {
4867: background-color: $mail_new_hover;
4868: }
4869: table.LC_mail_list tr.LC_mail_read {
4870: background-color: $mail_read;
4871: }
4872: table.LC_mail_list tr.LC_mail_read:hover {
4873: background-color: $mail_read_hover;
4874: }
4875: table.LC_mail_list tr.LC_mail_replied {
4876: background-color: $mail_replied;
4877: }
4878: table.LC_mail_list tr.LC_mail_replied:hover {
4879: background-color: $mail_replied_hover;
4880: }
4881: table.LC_mail_list tr.LC_mail_other {
4882: background-color: $mail_other;
4883: }
4884: table.LC_mail_list tr.LC_mail_other:hover {
4885: background-color: $mail_other_hover;
4886: }
1.494 raeburn 4887: table.LC_mail_list tr.LC_mail_even {
4888: }
4889: table.LC_mail_list tr.LC_mail_odd {
4890: }
4891:
1.696 bisitz 4892: table.LC_data_table tr > td.LC_browser_file,
4893: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 4894: background: #CCFF88;
4895: }
1.696 bisitz 4896: table.LC_data_table tr > td.LC_browser_file_locked,
4897: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 4898: background: #FFAA99;
1.387 albertel 4899: }
1.696 bisitz 4900: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.389 albertel 4901: background: #AAAAAA;
1.387 albertel 4902: }
1.696 bisitz 4903: table.LC_data_table tr > td.LC_browser_file_modified,
4904: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.389 albertel 4905: background: #FFFF77;
1.387 albertel 4906: }
1.696 bisitz 4907: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 4908: background: #CCCCFF;
1.387 albertel 4909: }
1.696 bisitz 4910:
1.707 bisitz 4911: table.LC_data_table tr > td.LC_roles_is {
4912: /* background: #77FF77; */
4913: }
4914: table.LC_data_table tr > td.LC_roles_future {
4915: background: #FFFF77;
4916: }
4917: table.LC_data_table tr > td.LC_roles_will {
4918: background: #FFAA77;
4919: }
4920: table.LC_data_table tr > td.LC_roles_expired {
4921: background: #FF7777;
4922: }
4923: table.LC_data_table tr > td.LC_roles_will_not {
4924: background: #AAFF77;
4925: }
4926: table.LC_data_table tr > td.LC_roles_selected {
4927: background: #11CC55;
4928: }
4929:
1.388 albertel 4930: span.LC_current_location {
1.701 harmsja 4931: font-size:larger;
1.388 albertel 4932: background: $pgbg;
4933: }
1.387 albertel 4934:
1.395 albertel 4935: span.LC_parm_menu_item {
4936: font-size: larger;
4937: font-family: $sans;
4938: }
4939: span.LC_parm_scope_all {
4940: color: red;
4941: }
4942: span.LC_parm_scope_folder {
4943: color: green;
4944: }
4945: span.LC_parm_scope_resource {
4946: color: orange;
4947: }
4948: span.LC_parm_part {
4949: color: blue;
4950: }
4951: span.LC_parm_folder, span.LC_parm_symb {
4952: font-size: x-small;
4953: font-family: $mono;
4954: color: #AAAAAA;
4955: }
4956:
1.396 albertel 4957: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4958: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4959: border: 1px solid black;
4960: border-collapse: collapse;
4961: }
4962: table.LC_parm_overview_restrictions td {
4963: border-width: 1px 4px 1px 4px;
4964: border-style: solid;
4965: border-color: $pgbg;
4966: text-align: center;
4967: }
4968: table.LC_parm_overview_restrictions th {
4969: background: $tabbg;
4970: border-width: 1px 4px 1px 4px;
4971: border-style: solid;
4972: border-color: $pgbg;
4973: }
1.398 albertel 4974: table#LC_helpmenu {
4975: border: 0px;
4976: height: 55px;
4977: border-spacing: 0px;
4978: }
4979:
4980: table#LC_helpmenu fieldset legend {
4981: font-size: larger;
4982: font-weight: bold;
4983: }
1.397 albertel 4984: table#LC_helpmenu_links {
4985: width: 100%;
4986: border: 1px solid black;
4987: background: $pgbg;
4988: padding: 0px;
4989: border-spacing: 1px;
4990: }
4991: table#LC_helpmenu_links tr td {
4992: padding: 1px;
4993: background: $tabbg;
1.399 albertel 4994: text-align: center;
4995: font-weight: bold;
1.397 albertel 4996: }
1.396 albertel 4997:
1.397 albertel 4998: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
4999: table#LC_helpmenu_links a:active {
5000: text-decoration: none;
5001: color: $font;
5002: }
5003: table#LC_helpmenu_links a:hover {
5004: text-decoration: underline;
5005: color: $vlink;
5006: }
1.396 albertel 5007:
1.417 albertel 5008: .LC_chrt_popup_exists {
5009: border: 1px solid #339933;
5010: margin: -1px;
5011: }
5012: .LC_chrt_popup_up {
5013: border: 1px solid yellow;
5014: margin: -1px;
5015: }
5016: .LC_chrt_popup {
5017: border: 1px solid #8888FF;
5018: background: #CCCCFF;
5019: }
1.421 albertel 5020: table.LC_pick_box {
5021: border-collapse: separate;
5022: background: white;
5023: border: 1px solid black;
5024: border-spacing: 1px;
5025: }
5026: table.LC_pick_box td.LC_pick_box_title {
5027: background: $tabbg;
5028: font-weight: bold;
5029: text-align: right;
1.740 bisitz 5030: vertical-align: top;
1.421 albertel 5031: width: 184px;
5032: padding: 8px;
5033: }
1.645 raeburn 5034: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5035: background: $tabbg;
5036: font-weight: bold;
5037: text-align: right;
5038: width: 350px;
5039: padding: 8px;
5040: }
5041:
1.579 raeburn 5042: table.LC_pick_box td.LC_pick_box_value {
5043: text-align: left;
5044: padding: 8px;
5045: }
5046: table.LC_pick_box td.LC_pick_box_select {
5047: text-align: left;
5048: padding: 8px;
5049: }
1.424 albertel 5050: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5051: padding: 0px;
5052: height: 1px;
5053: background: black;
5054: }
5055: table.LC_pick_box td.LC_pick_box_submit {
5056: text-align: right;
5057: }
1.579 raeburn 5058: table.LC_pick_box td.LC_evenrow_value {
5059: text-align: left;
5060: padding: 8px;
5061: background-color: $data_table_light;
5062: }
5063: table.LC_pick_box td.LC_oddrow_value {
5064: text-align: left;
5065: padding: 8px;
5066: background-color: $data_table_light;
5067: }
5068: table.LC_helpform_receipt {
5069: width: 620px;
5070: border-collapse: separate;
5071: background: white;
5072: border: 1px solid black;
5073: border-spacing: 1px;
5074: }
5075: table.LC_helpform_receipt td.LC_pick_box_title {
5076: background: $tabbg;
5077: font-weight: bold;
5078: text-align: right;
5079: width: 184px;
5080: padding: 8px;
5081: }
5082: table.LC_helpform_receipt td.LC_evenrow_value {
5083: text-align: left;
5084: padding: 8px;
5085: background-color: $data_table_light;
5086: }
5087: table.LC_helpform_receipt td.LC_oddrow_value {
5088: text-align: left;
5089: padding: 8px;
5090: background-color: $data_table_light;
5091: }
5092: table.LC_helpform_receipt td.LC_pick_box_separator {
5093: padding: 0px;
5094: height: 1px;
5095: background: black;
5096: }
5097: span.LC_helpform_receipt_cat {
5098: font-weight: bold;
5099: }
1.424 albertel 5100: table.LC_group_priv_box {
5101: background: white;
5102: border: 1px solid black;
5103: border-spacing: 1px;
5104: }
5105: table.LC_group_priv_box td.LC_pick_box_title {
5106: background: $tabbg;
5107: font-weight: bold;
5108: text-align: right;
5109: width: 184px;
5110: }
5111: table.LC_group_priv_box td.LC_groups_fixed {
5112: background: $data_table_light;
5113: text-align: center;
5114: }
5115: table.LC_group_priv_box td.LC_groups_optional {
5116: background: $data_table_dark;
5117: text-align: center;
5118: }
5119: table.LC_group_priv_box td.LC_groups_functionality {
5120: background: $data_table_darker;
5121: text-align: center;
5122: font-weight: bold;
5123: }
5124: table.LC_group_priv td {
5125: text-align: left;
5126: padding: 0px;
5127: }
5128:
1.421 albertel 5129: table.LC_notify_front_page {
5130: background: white;
5131: border: 1px solid black;
5132: padding: 8px;
5133: }
5134: table.LC_notify_front_page td {
5135: padding: 8px;
5136: }
1.424 albertel 5137: .LC_navbuttons {
5138: margin: 2ex 0ex 2ex 0ex;
5139: }
1.423 albertel 5140: .LC_topic_bar {
5141: font-family: $sans;
5142: font-weight: bold;
5143: width: 100%;
5144: background: $tabbg;
5145: vertical-align: middle;
5146: margin: 2ex 0ex 2ex 0ex;
5147: }
5148: .LC_topic_bar span {
5149: vertical-align: middle;
5150: }
5151: .LC_topic_bar img {
5152: vertical-align: bottom;
5153: }
5154: table.LC_course_group_status {
5155: margin: 20px;
5156: }
5157: table.LC_status_selector td {
5158: vertical-align: top;
5159: text-align: center;
1.424 albertel 5160: padding: 4px;
5161: }
5162: table.LC_descriptive_input td.LC_description {
5163: vertical-align: top;
5164: text-align: right;
5165: font-weight: bold;
1.423 albertel 5166: }
1.599 albertel 5167: div.LC_feedback_link {
1.616 albertel 5168: clear: both;
1.599 albertel 5169: background: white;
5170: width: 100%;
1.489 raeburn 5171: }
5172: span.LC_feedback_link {
1.599 albertel 5173: background: $feedback_link_bg;
5174: font-size: larger;
5175: }
5176: span.LC_message_link {
5177: background: $feedback_link_bg;
5178: font-size: larger;
5179: position: absolute;
5180: right: 1em;
1.489 raeburn 5181: }
1.421 albertel 5182:
1.515 albertel 5183: table.LC_prior_tries {
1.524 albertel 5184: border: 1px solid #000000;
5185: border-collapse: separate;
5186: border-spacing: 1px;
1.515 albertel 5187: }
1.523 albertel 5188:
1.515 albertel 5189: table.LC_prior_tries td {
1.524 albertel 5190: padding: 2px;
1.515 albertel 5191: }
1.523 albertel 5192:
5193: .LC_answer_correct {
5194: background: #AAFFAA;
5195: color: black;
5196: }
5197: .LC_answer_charged_try {
5198: background: #FFAAAA ! important;
5199: color: black;
5200: }
5201: .LC_answer_not_charged_try,
5202: .LC_answer_no_grade,
5203: .LC_answer_late {
5204: background: #FFFFAA;
5205: color: black;
5206: }
5207: .LC_answer_previous {
5208: background: #AAAAFF;
5209: color: black;
5210: }
5211: .LC_answer_no_message {
5212: background: #FFFFFF;
5213: color: black;
5214: }
5215: .LC_answer_unknown {
5216: background: orange;
5217: color: black;
5218: }
5219:
5220:
1.529 albertel 5221: span.LC_prior_numerical,
5222: span.LC_prior_string,
5223: span.LC_prior_custom,
5224: span.LC_prior_reaction,
5225: span.LC_prior_math {
1.523 albertel 5226: font-family: monospace;
5227: white-space: pre;
5228: }
5229:
1.525 albertel 5230: span.LC_prior_string {
5231: font-family: monospace;
5232: white-space: pre;
5233: }
5234:
1.523 albertel 5235: table.LC_prior_option {
5236: width: 100%;
5237: border-collapse: collapse;
5238: }
1.528 albertel 5239: table.LC_prior_rank, table.LC_prior_match {
5240: border-collapse: collapse;
5241: }
5242: table.LC_prior_option tr td,
5243: table.LC_prior_rank tr td,
5244: table.LC_prior_match tr td {
1.524 albertel 5245: border: 1px solid #000000;
1.515 albertel 5246: }
5247:
1.519 raeburn 5248: span.LC_nobreak {
1.544 albertel 5249: white-space: nowrap;
1.519 raeburn 5250: }
5251:
1.576 raeburn 5252: span.LC_cusr_emph {
5253: font-style: italic;
5254: }
5255:
1.633 raeburn 5256: span.LC_cusr_subheading {
5257: font-weight: normal;
5258: font-size: 85%;
5259: }
5260:
1.545 albertel 5261: table.LC_docs_documents {
5262: background: #BBBBBB;
1.547 albertel 5263: border-width: 0px;
1.545 albertel 5264: border-collapse: collapse;
5265: }
5266:
5267: table.LC_docs_documents td.LC_docs_document {
5268: border: 2px solid black;
5269: padding: 4px;
5270: }
5271:
5272: .LC_docs_entry_move {
5273: border: 0px;
5274: border-collapse: collapse;
1.544 albertel 5275: }
5276:
1.545 albertel 5277: .LC_docs_entry_move td {
5278: border: 2px solid #BBBBBB;
5279: background: #DDDDDD;
5280: }
5281:
5282: .LC_docs_editor td.LC_docs_entry_commands {
5283: background: #DDDDDD;
5284: font-size: x-small;
5285: }
1.544 albertel 5286: .LC_docs_copy {
1.545 albertel 5287: color: #000099;
1.544 albertel 5288: }
5289: .LC_docs_cut {
1.545 albertel 5290: color: #550044;
1.544 albertel 5291: }
5292: .LC_docs_rename {
1.545 albertel 5293: color: #009900;
1.544 albertel 5294: }
5295: .LC_docs_remove {
1.545 albertel 5296: color: #990000;
5297: }
5298:
1.547 albertel 5299: .LC_docs_reinit_warn,
5300: .LC_docs_ext_edit {
5301: font-size: x-small;
5302: }
5303:
1.545 albertel 5304: .LC_docs_editor td.LC_docs_entry_title,
5305: .LC_docs_editor td.LC_docs_entry_icon {
5306: background: #FFFFBB;
5307: }
5308: .LC_docs_editor td.LC_docs_entry_parameter {
5309: background: #BBBBFF;
5310: font-size: x-small;
5311: white-space: nowrap;
5312: }
5313:
5314: table.LC_docs_adddocs td,
5315: table.LC_docs_adddocs th {
5316: border: 1px solid #BBBBBB;
5317: padding: 4px;
5318: background: #DDDDDD;
1.543 albertel 5319: }
5320:
1.584 albertel 5321: table.LC_sty_begin {
5322: background: #BBFFBB;
5323: }
5324: table.LC_sty_end {
5325: background: #FFBBBB;
5326: }
5327:
1.589 raeburn 5328: table.LC_double_column {
5329: border-width: 0px;
5330: border-collapse: collapse;
5331: width: 100%;
5332: padding: 2px;
5333: }
5334:
5335: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5336: top: 2px;
1.589 raeburn 5337: left: 2px;
5338: width: 47%;
5339: vertical-align: top;
5340: }
5341:
5342: table.LC_double_column tr td.LC_right_col {
5343: top: 2px;
5344: right: 2px;
5345: width: 47%;
5346: vertical-align: top;
5347: }
5348:
1.594 raeburn 5349: span.LC_role_level {
5350: font-weight: bold;
5351: }
5352:
1.591 raeburn 5353: div.LC_left_float {
5354: float: left;
5355: padding-right: 5%;
1.597 albertel 5356: padding-bottom: 4px;
1.591 raeburn 5357: }
5358:
5359: div.LC_clear_float_header {
1.597 albertel 5360: padding-bottom: 2px;
1.591 raeburn 5361: }
5362:
5363: div.LC_clear_float_footer {
1.597 albertel 5364: padding-top: 10px;
1.591 raeburn 5365: clear: both;
5366: }
5367:
1.597 albertel 5368:
5369: div.LC_grade_show_user {
5370: margin-top: 20px;
5371: border: 1px solid black;
5372: }
5373: div.LC_grade_user_name {
5374: background: #DDDDEE;
5375: border-bottom: 1px solid black;
1.705 tempelho 5376: font-weight: bold;
5377: font-size: large;
1.597 albertel 5378: }
5379: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5380: background: #DDEEDD;
5381: }
5382:
5383: div.LC_grade_show_problem,
5384: div.LC_grade_submissions,
5385: div.LC_grade_message_center,
5386: div.LC_grade_info_links,
5387: div.LC_grade_assign {
5388: margin: 5px;
5389: width: 99%;
5390: background: #FFFFFF;
5391: }
5392: div.LC_grade_show_problem_header,
5393: div.LC_grade_submissions_header,
5394: div.LC_grade_message_center_header,
5395: div.LC_grade_assign_header {
1.705 tempelho 5396: font-weight: bold;
5397: font-size: large;
1.597 albertel 5398: }
5399: div.LC_grade_show_problem_problem,
5400: div.LC_grade_submissions_body,
5401: div.LC_grade_message_center_body,
5402: div.LC_grade_assign_body {
5403: border: 1px solid black;
5404: width: 99%;
5405: background: #FFFFFF;
5406: }
1.598 albertel 5407: span.LC_grade_check_note {
1.705 tempelho 5408: font-weight: normal;
5409: font-size: medium;
1.598 albertel 5410: display: inline;
5411: position: absolute;
5412: right: 1em;
5413: }
1.597 albertel 5414:
1.613 albertel 5415: table.LC_scantron_action {
5416: width: 100%;
5417: }
5418: table.LC_scantron_action tr th {
1.698 harmsja 5419: font-weight:bold;
5420: font-style:normal;
1.613 albertel 5421: }
1.698 harmsja 5422: .LC_edit_problem_header,
1.614 albertel 5423: div.LC_edit_problem_footer {
1.705 tempelho 5424: font-weight: normal;
5425: font-size: medium;
1.602 albertel 5426: margin: 2px;
1.600 albertel 5427: }
5428: div.LC_edit_problem_header,
1.602 albertel 5429: div.LC_edit_problem_header div,
1.614 albertel 5430: div.LC_edit_problem_footer,
5431: div.LC_edit_problem_footer div,
1.602 albertel 5432: div.LC_edit_problem_editxml_header,
5433: div.LC_edit_problem_editxml_header div {
1.600 albertel 5434: margin-top: 5px;
5435: }
1.602 albertel 5436: div.LC_edit_problem_header_edit_row {
5437: background: $tabbg;
5438: padding: 3px;
5439: margin-bottom: 5px;
5440: }
1.600 albertel 5441: div.LC_edit_problem_header_title {
1.705 tempelho 5442: font-weight: bold;
5443: font-size: larger;
1.602 albertel 5444: background: $tabbg;
5445: padding: 3px;
5446: }
5447: table.LC_edit_problem_header_title {
1.705 tempelho 5448: font-size: larger;
5449: font-weight: bold;
1.602 albertel 5450: width: 100%;
5451: border-color: $pgbg;
5452: border-style: solid;
5453: border-width: $border;
5454:
1.600 albertel 5455: background: $tabbg;
1.602 albertel 5456: border-collapse: collapse;
5457: padding: 0px
5458: }
5459:
5460: div.LC_edit_problem_discards {
5461: float: left;
5462: padding-bottom: 5px;
5463: }
5464: div.LC_edit_problem_saves {
5465: float: right;
5466: padding-bottom: 5px;
1.600 albertel 5467: }
5468: hr.LC_edit_problem_divide {
1.602 albertel 5469: clear: both;
1.600 albertel 5470: color: $tabbg;
5471: background-color: $tabbg;
5472: height: 3px;
5473: border: 0px;
5474: }
1.679 riegler 5475: img.stift{
1.678 riegler 5476: border-width:0;
1.679 riegler 5477: vertical-align:middle;
1.677 riegler 5478: }
1.680 riegler 5479:
1.681 riegler 5480: table#LC_mainmenu{
5481: margin-top:10px;
5482: width:80%;
5483:
5484: }
5485:
1.680 riegler 5486: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5487: vertical-align: top;
5488: width: 45%;
5489: }
5490: .LC_mainmenu_fieldset_category {
5491: color: $font;
5492: background: $pgbg;
5493: font-family: $sans;
5494: font-size: small;
5495: font-weight: bold;
5496: }
5497:
1.716 raeburn 5498: div.LC_createcourse {
5499: margin: 10px 10px 10px 10px;
5500: }
5501:
1.693 droeschl 5502: /* ---- Remove when done ----
5503: # The following styles is part of the redesign of LON-CAPA and are
5504: # subject to change during this project.
5505: # Don't rely on their current functionality as they might be
5506: # changed or removed.
5507: # --------------------------*/
5508:
1.698 harmsja 5509: a:hover,
1.721 harmsja 5510: ol.LC_smallMenu a:hover,
5511: ol#LC_MenuBreadcrumbs a:hover,
5512: ol#LC_PathBreadcrumbs a:hover,
5513: ul#LC_TabMainMenuContent a:hover,
5514: .LC_FormSectionClearButton input:hover
5515: ul.LC_TabContent li:hover a{
1.698 harmsja 5516: color:#BF2317;
5517: text-decoration:none;
1.693 droeschl 5518: }
5519:
5520: h1 {
1.721 harmsja 5521: padding:5px 10px 5px 20px;
1.693 droeschl 5522: line-height:130%;
5523: }
1.698 harmsja 5524:
1.693 droeschl 5525: h2,h3,h4,h5,h6
5526: {
1.721 harmsja 5527: margin:5px 0px 5px 0px;
5528: padding:0px;
5529: line-height:130%;
1.693 droeschl 5530: }
1.721 harmsja 5531: .LC_hcell{
1.698 harmsja 5532: padding:3px 15px 3px 15px;
5533: margin:0px;
1.703 harmsja 5534: background-color:$tabbg;
5535: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5536: }
1.721 harmsja 5537: .LC_noBorder {
1.698 harmsja 5538: border:0px;
5539: }
1.693 droeschl 5540:
1.722 harmsja 5541: .LC_bgLightGrey{
1.741 ! harmsja 5542: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
1.722 harmsja 5543: }
1.741 ! harmsja 5544:
1.693 droeschl 5545:
1.698 harmsja 5546: /* Main Header with discription of Person, Course, etc. */
1.721 harmsja 5547: .LC_HeadRight {
1.693 droeschl 5548: text-align: right;
5549: float: right;
5550: margin: 0px;
5551: padding: 0px;
1.698 harmsja 5552: right:0;
1.693 droeschl 5553: position:absolute;
1.698 harmsja 5554: overflow:hidden;
1.693 droeschl 5555: }
5556:
1.721 harmsja 5557: p, .LC_ContentBox {
1.698 harmsja 5558: padding: 10px;
5559:
5560: }
1.721 harmsja 5561: .LC_FormSectionClearButton input {
1.741 ! harmsja 5562: background-color:transparent;
1.698 harmsja 5563: border:0px;
5564: cursor:pointer;
5565: text-decoration:underline;
1.693 droeschl 5566: }
5567:
5568:
1.698 harmsja 5569: dl,ul,div,fieldset {
5570: margin: 10px 10px 10px 0px;
1.693 droeschl 5571: overflow:hidden;
5572: }
1.721 harmsja 5573: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5574: margin: 0px;
1.693 droeschl 5575: }
5576:
1.721 harmsja 5577: ol.LC_smallMenu li {
1.693 droeschl 5578: display: inline;
5579: padding: 5px 5px 0px 10px;
5580: vertical-align: top;
5581: }
5582:
1.721 harmsja 5583: ol.LC_smallMenu li img {
1.693 droeschl 5584: vertical-align: bottom;
5585: }
5586:
1.721 harmsja 5587: ol.LC_smallMenu a {
1.693 droeschl 5588: font-size: 90%;
5589: color: RGB(80, 80, 80);
5590: text-decoration: none;
5591: }
1.741 ! harmsja 5592: ol#LC_TabMainMenueContent, ul.LC_TabContent,
! 5593: ul.LC_TabContentBigger {
1.721 harmsja 5594: display:block;
5595: list-style:none;
1.741 ! harmsja 5596: margin: 0px;
1.693 droeschl 5597: padding: 0px;
5598: }
5599:
1.741 ! harmsja 5600: ol#LC_TabMainMenuContent li, ul.LC_TabContent,
! 5601: ul.LC_TabContentBigger li{
1.693 droeschl 5602: display: inline;
1.741 ! harmsja 5603: border-right: solid 1px $lg_border_color;
! 5604: float:left;
! 5605: line-height:140%;
! 5606: white-space:nowrap;
! 5607: }
! 5608: ol#LC_TabMainMenuContent li{
1.693 droeschl 5609: vertical-align: bottom;
5610: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5611: padding: 5px 10px 5px 10px;
1.741 ! harmsja 5612: margin-right:5px;
! 5613: margin-bottom:3px;
1.693 droeschl 5614: font-weight: bold;
1.723 riegler 5615: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5616: }
5617:
1.721 harmsja 5618: ol#LC_TabMainMenuContent li a{
1.693 droeschl 5619: color: RGB(47, 47, 47);
5620: text-decoration: none;
5621: }
1.721 harmsja 5622: ul.LC_TabContent {
1.741 ! harmsja 5623: min-height:1.6em;
! 5624: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5625: }
5626: ul.LC_TabContent li{
1.741 ! harmsja 5627: vertical-align:middle;
! 5628: padding:0px 10px 0px 10px;
1.721 harmsja 5629: }
5630: ul.LC_TabContent li a, ul.LC_TabContent li{
5631: color:rgb(47,47,47);
5632: text-decoration:none;
5633: font-size:95%;
5634: font-weight:bold;
5635: }
1.741 ! harmsja 5636: ul.LC_TabContentBigger li{
! 5637: vertical-align:bottom;
! 5638: border-top:solid 1px $lg_border_color;
! 5639: border-left:solid 1px $lg_border_color;
! 5640: padding:5px 10px 5px 10px;
! 5641: margin-left:2px;
! 5642: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
! 5643: }
! 5644: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
! 5645: font-size:110%;
! 5646: font-weight:bold;
! 5647: }
! 5648: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
! 5649: {
! 5650: margin:0px;
1.737 tempelho 5651: }
5652:
1.721 harmsja 5653: .LC_hideThis
5654: {
5655: display:none;
5656: visibility:hidden;
1.693 droeschl 5657: }
5658:
1.721 harmsja 5659: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
1.693 droeschl 5660: border-top: solid 1px RGB(255, 255, 255);
5661: height: 20px;
5662: line-height: 20px;
5663: vertical-align: bottom;
5664: margin: 0px 0px 30px 0px;
5665: padding-left: 10px;
5666: list-style-position: inside;
1.723 riegler 5667: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5668: }
5669:
1.721 harmsja 5670: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
1.741 ! harmsja 5671: /*
1.723 riegler 5672: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.741 ! harmsja 5673: */
1.693 droeschl 5674: display: inline;
5675: padding: 0px 0px 0px 10px;
5676: vertical-align: bottom;
5677: overflow:hidden;
5678: }
5679:
1.721 harmsja 5680: ol#LC_MenuBreadcrumbs li a {
1.693 droeschl 5681: text-decoration: none;
5682: font-size:90%;
5683: }
1.721 harmsja 5684: ol#LC_PathBreadcrumbs li a{
1.698 harmsja 5685: text-decoration:none;
5686: font-size:100%;
5687: font-weight:bold;
1.693 droeschl 5688: }
1.721 harmsja 5689: .LC_ContentBoxSpecial
1.693 droeschl 5690: {
1.701 harmsja 5691: border: solid 1px $lg_border_color;
1.698 harmsja 5692: }
1.693 droeschl 5693:
1.721 harmsja 5694: dl.LC_ListStyleClean dt {
1.693 droeschl 5695: padding-right: 5px;
5696: display: table-header-group;
5697: }
5698:
1.721 harmsja 5699: dl.LC_ListStyleClean dd {
1.693 droeschl 5700: display: table-row;
5701: }
5702:
1.721 harmsja 5703: .LC_ListStyleClean,
5704: .LC_ListStyleSimple,
5705: .LC_ListStyleNormal,
5706: .LC_ListStyleNormal_Border,
5707: .LC_ListStyleSpecial
1.693 droeschl 5708: {
5709: /*display:block; */
5710: list-style-position: inside;
5711: list-style-type: none;
5712: overflow: hidden;
5713: padding: 0px;
5714: }
5715:
1.721 harmsja 5716: .LC_ListStyleSimple li,
5717: .LC_ListStyleSimple dd,
5718: .LC_ListStyleNormal li,
5719: .LC_ListStyleNormal dd,
5720: .LC_ListStyleSpecial li,
5721: .LC_ListStyleSpecial dd
1.693 droeschl 5722: {
5723: margin: 0px;
5724: padding: 5px 5px 5px 10px;
5725: clear: both;
5726: }
5727:
1.721 harmsja 5728: .LC_ListStyleClean li,
5729: .LC_ListStyleClean dd {
1.693 droeschl 5730: padding-top: 0px;
5731: padding-bottom: 0px;
5732: }
5733:
1.721 harmsja 5734: .LC_ListStyleSimple dd,
5735: .LC_ListStyleSimple li{
1.698 harmsja 5736: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 5737: }
5738:
1.721 harmsja 5739: .LC_ListStyleSpecial li,
5740: .LC_ListStyleSpecial dd {
1.693 droeschl 5741: list-style-type: none;
5742: background-color: RGB(220, 220, 220);
5743: margin-bottom: 4px;
5744: }
5745:
1.721 harmsja 5746: table.LC_SimpleTable {
1.698 harmsja 5747: margin:5px;
5748: border:solid 1px $lg_border_color;
1.693 droeschl 5749: }
5750:
1.721 harmsja 5751: table.LC_SimpleTable tr {
1.698 harmsja 5752: padding:0px;
5753: border:solid 1px $lg_border_color;
1.693 droeschl 5754: }
1.721 harmsja 5755: table.LC_SimpleTable thead{
1.698 harmsja 5756: background:rgb(220,220,220);
1.693 droeschl 5757: }
5758:
1.721 harmsja 5759: div.LC_columnSection {
1.693 droeschl 5760: display: block;
5761: clear: both;
5762: overflow: hidden;
5763: margin:0px;
5764: }
5765:
1.721 harmsja 5766: div.LC_columnSection>* {
1.693 droeschl 5767: float: left;
5768: margin: 10px 20px 10px 0px;
5769: overflow:hidden;
5770: }
1.721 harmsja 5771: div.LC_columnSection > .LC_ContentBox,
5772: div.LC_columnSection > .LC_ContentBoxSpecial
1.693 droeschl 5773: {
1.721 harmsja 5774: width: 400px;
1.693 droeschl 5775: }
1.721 harmsja 5776:
1.719 ehlerst 5777: .ContentBoxSpecialTemplate
5778: {
5779: border: solid 1px $lg_border_color;
5780: }
5781: .ContentBoxTemplate {
5782: padding:10px;
5783: }
5784:
1.721 harmsja 5785: div.LC_columnSection > .ContentBoxTemplate,
5786: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719 ehlerst 5787: {
5788: width: 600px;
5789:
5790: }
5791:
1.720 ehlerst 5792: .clear{
5793: clear: both;
5794: line-height: 0px;
5795: font-size: 0px;
5796: height: 0px;
5797: }
1.693 droeschl 5798:
1.694 tempelho 5799: .LC_loginpage_container {
5800: text-align:left;
5801: margin : 0 auto;
5802: width:65%;
5803: padding: 10px;
5804: height: auto;
1.712 muellerd 5805: background-color:#FFFFFF;
1.694 tempelho 5806: border:1px solid #CCCCCC;
5807: }
5808:
5809:
5810: .LC_loginpage_loginContainer {
5811: float:left;
1.712 muellerd 5812: width: 182px;
5813: border:1px solid #CCCCCC;
5814: background-color:$loginbg;
1.694 tempelho 5815: }
5816:
1.717 tempelho 5817: .LC_loginpage_loginContainer h2{
1.712 muellerd 5818: margin-top:0;
5819: display:block;
5820: background:$bgcol;
5821: color:$textcol;
5822: padding-left:5px;
5823: }
1.694 tempelho 5824: .LC_loginpage_loginInfo {
5825: margin-left:20px;
5826: float:left;
5827: width:30%;
5828: border:1px solid #CCCCCC;
5829: padding:10px;
5830: }
5831:
1.712 muellerd 5832: .LC_loginpage_loginDomain {
5833: margin-right:20px;
5834: width:20%;
5835: float:left;
5836: padding:10px;
5837: }
5838:
1.694 tempelho 5839: .LC_loginpage_space {
5840: clear:both;
5841: margin-bottom:20px;
5842: border-bottom: 1px solid #CCCCCC;
5843: }
5844:
1.343 albertel 5845: END
5846: }
5847:
1.306 albertel 5848: =pod
5849:
5850: =item * &headtag()
5851:
5852: Returns a uniform footer for LON-CAPA web pages.
5853:
1.307 albertel 5854: Inputs: $title - optional title for the head
5855: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5856: $args - optional arguments
1.319 albertel 5857: force_register - if is true call registerurl so the remote is
5858: informed
1.415 albertel 5859: redirect -> array ref of
5860: 1- seconds before redirect occurs
5861: 2- url to redirect to
5862: 3- whether the side effect should occur
1.315 albertel 5863: (side effect of setting
5864: $env{'internal.head.redirect'} to the url
5865: redirected too)
1.352 albertel 5866: domain -> force to color decorate a page for a specific
5867: domain
5868: function -> force usage of a specific rolish color scheme
5869: bgcolor -> override the default page bgcolor
1.460 albertel 5870: no_auto_mt_title
5871: -> prevent &mt()ing the title arg
1.464 albertel 5872:
1.306 albertel 5873: =cut
5874:
5875: sub headtag {
1.313 albertel 5876: my ($title,$head_extra,$args) = @_;
1.306 albertel 5877:
1.363 albertel 5878: my $function = $args->{'function'} || &get_users_function();
5879: my $domain = $args->{'domain'} || &determinedomain();
5880: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5881: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5882: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5883: #time(),
1.418 albertel 5884: $env{'environment.color.timestamp'},
1.363 albertel 5885: $function,$domain,$bgcolor);
5886:
1.369 www 5887: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5888:
1.308 albertel 5889: my $result =
5890: '<head>'.
1.461 albertel 5891: &font_settings();
1.319 albertel 5892:
1.461 albertel 5893: if (!$args->{'frameset'}) {
5894: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5895: }
1.319 albertel 5896: if ($args->{'force_register'}) {
5897: $result .= &Apache::lonmenu::registerurl(1);
5898: }
1.436 albertel 5899: if (!$args->{'no_nav_bar'}
5900: && !$args->{'only_body'}
5901: && !$args->{'frameset'}) {
5902: $result .= &help_menu_js();
5903: }
1.319 albertel 5904:
1.314 albertel 5905: if (ref($args->{'redirect'})) {
1.414 albertel 5906: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5907: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5908: if (!$inhibit_continue) {
5909: $env{'internal.head.redirect'} = $url;
5910: }
1.313 albertel 5911: $result.=<<ADDMETA
5912: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5913: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5914: ADDMETA
5915: }
1.306 albertel 5916: if (!defined($title)) {
5917: $title = 'The LearningOnline Network with CAPA';
5918: }
1.460 albertel 5919: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5920: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5921: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5922: .$head_extra;
1.306 albertel 5923: return $result;
5924: }
5925:
5926: =pod
5927:
1.340 albertel 5928: =item * &font_settings()
5929:
5930: Returns neccessary <meta> to set the proper encoding
5931:
5932: Inputs: none
5933:
5934: =cut
5935:
5936: sub font_settings {
5937: my $headerstring='';
1.647 www 5938: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5939: $headerstring.=
5940: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5941: }
5942: return $headerstring;
5943: }
5944:
1.341 albertel 5945: =pod
5946:
5947: =item * &xml_begin()
5948:
5949: Returns the needed doctype and <html>
5950:
5951: Inputs: none
5952:
5953: =cut
5954:
5955: sub xml_begin {
5956: my $output='';
5957:
1.592 albertel 5958: if ($env{'internal.start_page'}==1) {
5959: &Apache::lonhtmlcommon::init_htmlareafields();
5960: }
1.342 albertel 5961:
1.341 albertel 5962: if ($env{'browser.mathml'}) {
5963: $output='<?xml version="1.0"?>'
5964: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5965: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5966:
5967: # .'<!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">] >'
5968: .'<!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">'
5969: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5970: .'xmlns="http://www.w3.org/1999/xhtml">';
5971: } else {
5972: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5973: }
5974: return $output;
5975: }
1.340 albertel 5976:
5977: =pod
5978:
1.306 albertel 5979: =item * &endheadtag()
5980:
5981: Returns a uniform </head> for LON-CAPA web pages.
5982:
5983: Inputs: none
5984:
5985: =cut
5986:
5987: sub endheadtag {
5988: return '</head>';
5989: }
5990:
5991: =pod
5992:
5993: =item * &head()
5994:
5995: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5996:
1.648 raeburn 5997: Inputs:
5998:
5999: =over 4
6000:
6001: $title - optional title for the page
6002:
6003: $head_extra - optional extra HTML to put inside the <head>
6004:
6005: =back
1.405 albertel 6006:
1.306 albertel 6007: =cut
6008:
6009: sub head {
1.325 albertel 6010: my ($title,$head_extra,$args) = @_;
6011: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6012: }
6013:
6014: =pod
6015:
6016: =item * &start_page()
6017:
6018: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6019:
1.648 raeburn 6020: Inputs:
6021:
6022: =over 4
6023:
6024: $title - optional title for the page
6025:
6026: $head_extra - optional extra HTML to incude inside the <head>
6027:
6028: $args - additional optional args supported are:
6029:
6030: =over 8
6031:
6032: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6033: arg on
1.648 raeburn 6034: no_nav_bar -> is true will set &bodytag() notopbar arg on
6035: add_entries -> additional attributes to add to the <body>
6036: domain -> force to color decorate a page for a
1.317 albertel 6037: specific domain
1.648 raeburn 6038: function -> force usage of a specific rolish color
1.317 albertel 6039: scheme
1.648 raeburn 6040: redirect -> see &headtag()
6041: bgcolor -> override the default page bg color
6042: js_ready -> return a string ready for being used in
1.317 albertel 6043: a javascript writeln
1.648 raeburn 6044: html_encode -> return a string ready for being used in
1.320 albertel 6045: a html attribute
1.648 raeburn 6046: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6047: $forcereg arg
1.648 raeburn 6048: body_title -> alternate text to use instead of $title
1.326 albertel 6049: in the title box that appears, this text
6050: is not auto translated like the $title is
1.648 raeburn 6051: frameset -> if true will start with a <frameset>
1.330 albertel 6052: rather than <body>
1.648 raeburn 6053: no_title -> if true the title bar won't be shown
6054: skip_phases -> hash ref of
1.338 albertel 6055: head -> skip the <html><head> generation
6056: body -> skip all <body> generation
1.648 raeburn 6057: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6058: 'Switch To Inline Menu' link
1.648 raeburn 6059: no_auto_mt_title -> prevent &mt()ing the title arg
6060: inherit_jsmath -> when creating popup window in a page,
6061: should it have jsmath forced on by the
6062: current page
1.361 albertel 6063:
1.648 raeburn 6064: =back
1.460 albertel 6065:
1.648 raeburn 6066: =back
1.562 albertel 6067:
1.306 albertel 6068: =cut
6069:
6070: sub start_page {
1.309 albertel 6071: my ($title,$head_extra,$args) = @_;
1.318 albertel 6072: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6073: my %head_args;
1.352 albertel 6074: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6075: 'bgcolor','frameset','no_nav_bar','only_body',
6076: 'no_auto_mt_title') {
1.319 albertel 6077: if (defined($args->{$arg})) {
1.324 raeburn 6078: $head_args{$arg} = $args->{$arg};
1.319 albertel 6079: }
1.313 albertel 6080: }
1.319 albertel 6081:
1.315 albertel 6082: $env{'internal.start_page'}++;
1.338 albertel 6083: my $result;
6084: if (! exists($args->{'skip_phases'}{'head'}) ) {
6085: $result.=
1.341 albertel 6086: &xml_begin().
1.338 albertel 6087: &headtag($title,$head_extra,\%head_args).&endheadtag();
6088: }
6089:
6090: if (! exists($args->{'skip_phases'}{'body'}) ) {
6091: if ($args->{'frameset'}) {
6092: my $attr_string = &make_attr_string($args->{'force_register'},
6093: $args->{'add_entries'});
6094: $result .= "\n<frameset $attr_string>\n";
6095: } else {
6096: $result .=
6097: &bodytag($title,
6098: $args->{'function'}, $args->{'add_entries'},
6099: $args->{'only_body'}, $args->{'domain'},
6100: $args->{'force_register'}, $args->{'body_title'},
6101: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6102: $args->{'no_title'}, $args->{'no_inline_link'},
6103: $args);
1.338 albertel 6104: }
1.330 albertel 6105: }
1.338 albertel 6106:
1.315 albertel 6107: if ($args->{'js_ready'}) {
1.713 kaisler 6108: $result = &js_ready($result);
1.315 albertel 6109: }
1.320 albertel 6110: if ($args->{'html_encode'}) {
1.713 kaisler 6111: $result = &html_encode($result);
6112: }
6113:
1.718 raeburn 6114: if (exists($args->{'bread_crumbs'})) {
6115: &Apache::lonhtmlcommon::clear_breadcrumbs();
6116: if (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6117: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6118: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6119: }
6120: }
6121: $result .= &Apache::lonhtmlcommon::breadcrumbs();
1.320 albertel 6122: }
1.713 kaisler 6123:
1.315 albertel 6124: return $result;
1.306 albertel 6125: }
6126:
1.330 albertel 6127:
1.306 albertel 6128: =pod
6129:
6130: =item * &head()
6131:
6132: Returns a complete </body></html> section for LON-CAPA web pages.
6133:
1.315 albertel 6134: Inputs: $args - additional optional args supported are:
6135: js_ready -> return a string ready for being used in
6136: a javascript writeln
1.320 albertel 6137: html_encode -> return a string ready for being used in
6138: a html attribute
1.330 albertel 6139: frameset -> if true will start with a <frameset>
6140: rather than <body>
1.493 albertel 6141: dicsussion -> if true will get discussion from
6142: lonxml::xmlend
6143: (you can pass the target and parser arguments
6144: through optional 'target' and 'parser' args
6145: to this routine)
1.306 albertel 6146:
6147: =cut
6148:
6149: sub end_page {
1.315 albertel 6150: my ($args) = @_;
6151: $env{'internal.end_page'}++;
1.330 albertel 6152: my $result;
1.335 albertel 6153: if ($args->{'discussion'}) {
6154: my ($target,$parser);
6155: if (ref($args->{'discussion'})) {
6156: ($target,$parser) =($args->{'discussion'}{'target'},
6157: $args->{'discussion'}{'parser'});
6158: }
6159: $result .= &Apache::lonxml::xmlend($target,$parser);
6160: }
6161:
1.330 albertel 6162: if ($args->{'frameset'}) {
6163: $result .= '</frameset>';
6164: } else {
1.635 raeburn 6165: $result .= &endbodytag($args);
1.330 albertel 6166: }
6167: $result .= "\n</html>";
6168:
1.315 albertel 6169: if ($args->{'js_ready'}) {
1.317 albertel 6170: $result = &js_ready($result);
1.315 albertel 6171: }
1.335 albertel 6172:
1.320 albertel 6173: if ($args->{'html_encode'}) {
6174: $result = &html_encode($result);
6175: }
1.335 albertel 6176:
1.315 albertel 6177: return $result;
6178: }
6179:
1.320 albertel 6180: sub html_encode {
6181: my ($result) = @_;
6182:
1.322 albertel 6183: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6184:
6185: return $result;
6186: }
1.317 albertel 6187: sub js_ready {
6188: my ($result) = @_;
6189:
1.323 albertel 6190: $result =~ s/[\n\r]/ /xmsg;
6191: $result =~ s/\\/\\\\/xmsg;
6192: $result =~ s/'/\\'/xmsg;
1.372 albertel 6193: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6194:
6195: return $result;
6196: }
6197:
1.315 albertel 6198: sub validate_page {
6199: if ( exists($env{'internal.start_page'})
1.316 albertel 6200: && $env{'internal.start_page'} > 1) {
6201: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6202: $env{'internal.start_page'}.' '.
1.316 albertel 6203: $ENV{'request.filename'});
1.315 albertel 6204: }
6205: if ( exists($env{'internal.end_page'})
1.316 albertel 6206: && $env{'internal.end_page'} > 1) {
6207: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6208: $env{'internal.end_page'}.' '.
1.316 albertel 6209: $env{'request.filename'});
1.315 albertel 6210: }
6211: if ( exists($env{'internal.start_page'})
6212: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6213: &Apache::lonnet::logthis('start_page called without end_page '.
6214: $env{'request.filename'});
1.315 albertel 6215: }
6216: if ( ! exists($env{'internal.start_page'})
6217: && exists($env{'internal.end_page'})) {
1.316 albertel 6218: &Apache::lonnet::logthis('end_page called without start_page'.
6219: $env{'request.filename'});
1.315 albertel 6220: }
1.306 albertel 6221: }
1.315 albertel 6222:
1.318 albertel 6223: sub simple_error_page {
6224: my ($r,$title,$msg) = @_;
6225: my $page =
6226: &Apache::loncommon::start_page($title).
6227: &mt($msg).
6228: &Apache::loncommon::end_page();
6229: if (ref($r)) {
6230: $r->print($page);
1.327 albertel 6231: return;
1.318 albertel 6232: }
6233: return $page;
6234: }
1.347 albertel 6235:
6236: {
1.610 albertel 6237: my @row_count;
1.347 albertel 6238: sub start_data_table {
1.422 albertel 6239: my ($add_class) = @_;
6240: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6241: unshift(@row_count,0);
1.422 albertel 6242: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6243: }
6244:
6245: sub end_data_table {
1.610 albertel 6246: shift(@row_count);
1.389 albertel 6247: return '</table>'."\n";;
1.347 albertel 6248: }
6249:
6250: sub start_data_table_row {
1.422 albertel 6251: my ($add_class) = @_;
1.610 albertel 6252: $row_count[0]++;
6253: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6254: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6255: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6256: }
1.471 banghart 6257:
6258: sub continue_data_table_row {
6259: my ($add_class) = @_;
1.610 albertel 6260: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6261: $css_class = (join(' ',$css_class,$add_class));
6262: return '<tr class="'.$css_class.'">'."\n";;
6263: }
1.347 albertel 6264:
6265: sub end_data_table_row {
1.389 albertel 6266: return '</tr>'."\n";;
1.347 albertel 6267: }
1.367 www 6268:
1.421 albertel 6269: sub start_data_table_empty_row {
1.707 bisitz 6270: # $row_count[0]++;
1.421 albertel 6271: return '<tr class="LC_empty_row" >'."\n";;
6272: }
6273:
6274: sub end_data_table_empty_row {
6275: return '</tr>'."\n";;
6276: }
6277:
1.367 www 6278: sub start_data_table_header_row {
1.389 albertel 6279: return '<tr class="LC_header_row">'."\n";;
1.367 www 6280: }
6281:
6282: sub end_data_table_header_row {
1.389 albertel 6283: return '</tr>'."\n";;
1.367 www 6284: }
1.347 albertel 6285: }
6286:
1.548 albertel 6287: =pod
6288:
6289: =item * &inhibit_menu_check($arg)
6290:
6291: Checks for a inhibitmenu state and generates output to preserve it
6292:
6293: Inputs: $arg - can be any of
6294: - undef - in which case the return value is a string
6295: to add into arguments list of a uri
6296: - 'input' - in which case the return value is a HTML
6297: <form> <input> field of type hidden to
6298: preserve the value
6299: - a url - in which case the return value is the url with
6300: the neccesary cgi args added to preserve the
6301: inhibitmenu state
6302: - a ref to a url - no return value, but the string is
6303: updated to include the neccessary cgi
6304: args to preserve the inhibitmenu state
6305:
6306: =cut
6307:
6308: sub inhibit_menu_check {
6309: my ($arg) = @_;
6310: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6311: if ($arg eq 'input') {
6312: if ($env{'form.inhibitmenu'}) {
6313: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6314: } else {
6315: return
6316: }
6317: }
6318: if ($env{'form.inhibitmenu'}) {
6319: if (ref($arg)) {
6320: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6321: } elsif ($arg eq '') {
6322: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6323: } else {
6324: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6325: }
6326: }
6327: if (!ref($arg)) {
6328: return $arg;
6329: }
6330: }
6331:
1.251 albertel 6332: ###############################################
1.182 matthew 6333:
6334: =pod
6335:
1.549 albertel 6336: =back
6337:
6338: =head1 User Information Routines
6339:
6340: =over 4
6341:
1.405 albertel 6342: =item * &get_users_function()
1.182 matthew 6343:
6344: Used by &bodytag to determine the current users primary role.
6345: Returns either 'student','coordinator','admin', or 'author'.
6346:
6347: =cut
6348:
6349: ###############################################
6350: sub get_users_function {
6351: my $function = 'student';
1.258 albertel 6352: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6353: $function='coordinator';
6354: }
1.258 albertel 6355: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6356: $function='admin';
6357: }
1.258 albertel 6358: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6359: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6360: $function='author';
6361: }
6362: return $function;
1.54 www 6363: }
1.99 www 6364:
6365: ###############################################
6366:
1.233 raeburn 6367: =pod
6368:
1.542 raeburn 6369: =item * &check_user_status()
1.274 raeburn 6370:
6371: Determines current status of supplied role for a
6372: specific user. Roles can be active, previous or future.
6373:
6374: Inputs:
6375: user's domain, user's username, course's domain,
1.375 raeburn 6376: course's number, optional section ID.
1.274 raeburn 6377:
6378: Outputs:
6379: role status: active, previous or future.
6380:
6381: =cut
6382:
6383: sub check_user_status {
1.412 raeburn 6384: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6385: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6386: my @uroles = keys %userinfo;
6387: my $srchstr;
6388: my $active_chk = 'none';
1.412 raeburn 6389: my $now = time;
1.274 raeburn 6390: if (@uroles > 0) {
1.412 raeburn 6391: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6392: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6393: } else {
1.412 raeburn 6394: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6395: }
6396: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6397: my $role_end = 0;
6398: my $role_start = 0;
6399: $active_chk = 'active';
1.412 raeburn 6400: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6401: $role_end = $1;
6402: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6403: $role_start = $1;
1.274 raeburn 6404: }
6405: }
6406: if ($role_start > 0) {
1.412 raeburn 6407: if ($now < $role_start) {
1.274 raeburn 6408: $active_chk = 'future';
6409: }
6410: }
6411: if ($role_end > 0) {
1.412 raeburn 6412: if ($now > $role_end) {
1.274 raeburn 6413: $active_chk = 'previous';
6414: }
6415: }
6416: }
6417: }
6418: return $active_chk;
6419: }
6420:
6421: ###############################################
6422:
6423: =pod
6424:
1.405 albertel 6425: =item * &get_sections()
1.233 raeburn 6426:
6427: Determines all the sections for a course including
6428: sections with students and sections containing other roles.
1.419 raeburn 6429: Incoming parameters:
6430:
6431: 1. domain
6432: 2. course number
6433: 3. reference to array containing roles for which sections should
6434: be gathered (optional).
6435: 4. reference to array containing status types for which sections
6436: should be gathered (optional).
6437:
6438: If the third argument is undefined, sections are gathered for any role.
6439: If the fourth argument is undefined, sections are gathered for any status.
6440: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6441:
1.374 raeburn 6442: Returns section hash (keys are section IDs, values are
6443: number of users in each section), subject to the
1.419 raeburn 6444: optional roles filter, optional status filter
1.233 raeburn 6445:
6446: =cut
6447:
6448: ###############################################
6449: sub get_sections {
1.419 raeburn 6450: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6451: if (!defined($cdom) || !defined($cnum)) {
6452: my $cid = $env{'request.course.id'};
6453:
6454: return if (!defined($cid));
6455:
6456: $cdom = $env{'course.'.$cid.'.domain'};
6457: $cnum = $env{'course.'.$cid.'.num'};
6458: }
6459:
6460: my %sectioncount;
1.419 raeburn 6461: my $now = time;
1.240 albertel 6462:
1.366 albertel 6463: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6464: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6465: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6466: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6467: my $start_index = &Apache::loncoursedata::CL_START();
6468: my $end_index = &Apache::loncoursedata::CL_END();
6469: my $status;
1.366 albertel 6470: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6471: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6472: $data->[$status_index],
6473: $data->[$start_index],
6474: $data->[$end_index]);
6475: if ($stu_status eq 'Active') {
6476: $status = 'active';
6477: } elsif ($end < $now) {
6478: $status = 'previous';
6479: } elsif ($start > $now) {
6480: $status = 'future';
6481: }
6482: if ($section ne '-1' && $section !~ /^\s*$/) {
6483: if ((!defined($possible_status)) || (($status ne '') &&
6484: (grep/^\Q$status\E$/,@{$possible_status}))) {
6485: $sectioncount{$section}++;
6486: }
1.240 albertel 6487: }
6488: }
6489: }
6490: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6491: foreach my $user (sort(keys(%courseroles))) {
6492: if ($user !~ /^(\w{2})/) { next; }
6493: my ($role) = ($user =~ /^(\w{2})/);
6494: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6495: my ($section,$status);
1.240 albertel 6496: if ($role eq 'cr' &&
6497: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6498: $section=$1;
6499: }
6500: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6501: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6502: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6503: if ($end == -1 && $start == -1) {
6504: next; #deleted role
6505: }
6506: if (!defined($possible_status)) {
6507: $sectioncount{$section}++;
6508: } else {
6509: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6510: $status = 'active';
6511: } elsif ($end < $now) {
6512: $status = 'future';
6513: } elsif ($start > $now) {
6514: $status = 'previous';
6515: }
6516: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6517: $sectioncount{$section}++;
6518: }
6519: }
1.233 raeburn 6520: }
1.366 albertel 6521: return %sectioncount;
1.233 raeburn 6522: }
6523:
1.274 raeburn 6524: ###############################################
1.294 raeburn 6525:
6526: =pod
1.405 albertel 6527:
6528: =item * &get_course_users()
6529:
1.275 raeburn 6530: Retrieves usernames:domains for users in the specified course
6531: with specific role(s), and access status.
6532:
6533: Incoming parameters:
1.277 albertel 6534: 1. course domain
6535: 2. course number
6536: 3. access status: users must have - either active,
1.275 raeburn 6537: previous, future, or all.
1.277 albertel 6538: 4. reference to array of permissible roles
1.288 raeburn 6539: 5. reference to array of section restrictions (optional)
6540: 6. reference to results object (hash of hashes).
6541: 7. reference to optional userdata hash
1.609 raeburn 6542: 8. reference to optional statushash
1.630 raeburn 6543: 9. flag if privileged users (except those set to unhide in
6544: course settings) should be excluded
1.609 raeburn 6545: Keys of top level results hash are roles.
1.275 raeburn 6546: Keys of inner hashes are username:domain, with
6547: values set to access type.
1.288 raeburn 6548: Optional userdata hash returns an array with arguments in the
6549: same order as loncoursedata::get_classlist() for student data.
6550:
1.609 raeburn 6551: Optional statushash returns
6552:
1.288 raeburn 6553: Entries for end, start, section and status are blank because
6554: of the possibility of multiple values for non-student roles.
6555:
1.275 raeburn 6556: =cut
1.405 albertel 6557:
1.275 raeburn 6558: ###############################################
1.405 albertel 6559:
1.275 raeburn 6560: sub get_course_users {
1.630 raeburn 6561: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6562: my %idx = ();
1.419 raeburn 6563: my %seclists;
1.288 raeburn 6564:
6565: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6566: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6567: $idx{end} = &Apache::loncoursedata::CL_END();
6568: $idx{start} = &Apache::loncoursedata::CL_START();
6569: $idx{id} = &Apache::loncoursedata::CL_ID();
6570: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6571: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6572: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6573:
1.290 albertel 6574: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6575: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6576: my $now = time;
1.277 albertel 6577: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6578: my $match = 0;
1.412 raeburn 6579: my $secmatch = 0;
1.419 raeburn 6580: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6581: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6582: if ($section eq '') {
6583: $section = 'none';
6584: }
1.291 albertel 6585: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6586: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6587: $secmatch = 1;
6588: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6589: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6590: $secmatch = 1;
6591: }
6592: } else {
1.419 raeburn 6593: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6594: $secmatch = 1;
6595: }
1.290 albertel 6596: }
1.412 raeburn 6597: if (!$secmatch) {
6598: next;
6599: }
1.419 raeburn 6600: }
1.275 raeburn 6601: if (defined($$types{'active'})) {
1.288 raeburn 6602: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6603: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6604: $match = 1;
1.275 raeburn 6605: }
6606: }
6607: if (defined($$types{'previous'})) {
1.609 raeburn 6608: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6609: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6610: $match = 1;
1.275 raeburn 6611: }
6612: }
6613: if (defined($$types{'future'})) {
1.609 raeburn 6614: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6615: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6616: $match = 1;
1.275 raeburn 6617: }
6618: }
1.609 raeburn 6619: if ($match) {
6620: push(@{$seclists{$student}},$section);
6621: if (ref($userdata) eq 'HASH') {
6622: $$userdata{$student} = $$classlist{$student};
6623: }
6624: if (ref($statushash) eq 'HASH') {
6625: $statushash->{$student}{'st'}{$section} = $status;
6626: }
1.288 raeburn 6627: }
1.275 raeburn 6628: }
6629: }
1.412 raeburn 6630: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6631: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6632: my $now = time;
1.609 raeburn 6633: my %displaystatus = ( previous => 'Expired',
6634: active => 'Active',
6635: future => 'Future',
6636: );
1.630 raeburn 6637: my %nothide;
6638: if ($hidepriv) {
6639: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6640: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6641: if ($user !~ /:/) {
6642: $nothide{join(':',split(/[\@]/,$user))}=1;
6643: } else {
6644: $nothide{$user} = 1;
6645: }
6646: }
6647: }
1.439 raeburn 6648: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6649: my $match = 0;
1.412 raeburn 6650: my $secmatch = 0;
1.439 raeburn 6651: my $status;
1.412 raeburn 6652: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6653: $user =~ s/:$//;
1.439 raeburn 6654: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6655: if ($end == -1 || $start == -1) {
6656: next;
6657: }
6658: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6659: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6660: my ($uname,$udom) = split(/:/,$user);
6661: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6662: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6663: $secmatch = 1;
6664: } elsif ($usec eq '') {
1.420 albertel 6665: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6666: $secmatch = 1;
6667: }
6668: } else {
6669: if (grep(/^\Q$usec\E$/,@{$sections})) {
6670: $secmatch = 1;
6671: }
6672: }
6673: if (!$secmatch) {
6674: next;
6675: }
1.288 raeburn 6676: }
1.419 raeburn 6677: if ($usec eq '') {
6678: $usec = 'none';
6679: }
1.275 raeburn 6680: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6681: if ($hidepriv) {
6682: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6683: (!$nothide{$uname.':'.$udom})) {
6684: next;
6685: }
6686: }
1.503 raeburn 6687: if ($end > 0 && $end < $now) {
1.439 raeburn 6688: $status = 'previous';
6689: } elsif ($start > $now) {
6690: $status = 'future';
6691: } else {
6692: $status = 'active';
6693: }
1.277 albertel 6694: foreach my $type (keys(%{$types})) {
1.275 raeburn 6695: if ($status eq $type) {
1.420 albertel 6696: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6697: push(@{$$users{$role}{$user}},$type);
6698: }
1.288 raeburn 6699: $match = 1;
6700: }
6701: }
1.419 raeburn 6702: if (($match) && (ref($userdata) eq 'HASH')) {
6703: if (!exists($$userdata{$uname.':'.$udom})) {
6704: &get_user_info($udom,$uname,\%idx,$userdata);
6705: }
1.420 albertel 6706: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6707: push(@{$seclists{$uname.':'.$udom}},$usec);
6708: }
1.609 raeburn 6709: if (ref($statushash) eq 'HASH') {
6710: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6711: }
1.275 raeburn 6712: }
6713: }
6714: }
6715: }
1.290 albertel 6716: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6717: if ((defined($cdom)) && (defined($cnum))) {
6718: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6719: if ( defined($csettings{'internal.courseowner'}) ) {
6720: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6721: next if ($owner eq '');
6722: my ($ownername,$ownerdom);
6723: if ($owner =~ /^([^:]+):([^:]+)$/) {
6724: $ownername = $1;
6725: $ownerdom = $2;
6726: } else {
6727: $ownername = $owner;
6728: $ownerdom = $cdom;
6729: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6730: }
6731: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6732: if (defined($userdata) &&
1.609 raeburn 6733: !exists($$userdata{$owner})) {
6734: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6735: if (!grep(/^none$/,@{$seclists{$owner}})) {
6736: push(@{$seclists{$owner}},'none');
6737: }
6738: if (ref($statushash) eq 'HASH') {
6739: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6740: }
1.290 albertel 6741: }
1.279 raeburn 6742: }
6743: }
6744: }
1.419 raeburn 6745: foreach my $user (keys(%seclists)) {
6746: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6747: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6748: }
1.275 raeburn 6749: }
6750: return;
6751: }
6752:
1.288 raeburn 6753: sub get_user_info {
6754: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6755: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6756: &plainname($uname,$udom,'lastname');
1.291 albertel 6757: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6758: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6759: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6760: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6761: return;
6762: }
1.275 raeburn 6763:
1.472 raeburn 6764: ###############################################
6765:
6766: =pod
6767:
6768: =item * &get_user_quota()
6769:
6770: Retrieves quota assigned for storage of portfolio files for a user
6771:
6772: Incoming parameters:
6773: 1. user's username
6774: 2. user's domain
6775:
6776: Returns:
1.536 raeburn 6777: 1. Disk quota (in Mb) assigned to student.
6778: 2. (Optional) Type of setting: custom or default
6779: (individually assigned or default for user's
6780: institutional status).
6781: 3. (Optional) - User's institutional status (e.g., faculty, staff
6782: or student - types as defined in localenroll::inst_usertypes
6783: for user's domain, which determines default quota for user.
6784: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6785:
6786: If a value has been stored in the user's environment,
1.536 raeburn 6787: it will return that, otherwise it returns the maximal default
6788: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6789:
6790: =cut
6791:
6792: ###############################################
6793:
6794:
6795: sub get_user_quota {
6796: my ($uname,$udom) = @_;
1.536 raeburn 6797: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6798: if (!defined($udom)) {
6799: $udom = $env{'user.domain'};
6800: }
6801: if (!defined($uname)) {
6802: $uname = $env{'user.name'};
6803: }
6804: if (($udom eq '' || $uname eq '') ||
6805: ($udom eq 'public') && ($uname eq 'public')) {
6806: $quota = 0;
1.536 raeburn 6807: $quotatype = 'default';
6808: $defquota = 0;
1.472 raeburn 6809: } else {
1.536 raeburn 6810: my $inststatus;
1.472 raeburn 6811: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6812: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6813: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6814: } else {
1.536 raeburn 6815: my %userenv =
6816: &Apache::lonnet::get('environment',['portfolioquota',
6817: 'inststatus'],$udom,$uname);
1.472 raeburn 6818: my ($tmp) = keys(%userenv);
6819: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6820: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6821: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6822: } else {
6823: undef(%userenv);
6824: }
6825: }
1.536 raeburn 6826: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6827: if ($quota eq '') {
1.536 raeburn 6828: $quota = $defquota;
6829: $quotatype = 'default';
6830: } else {
6831: $quotatype = 'custom';
1.472 raeburn 6832: }
6833: }
1.536 raeburn 6834: if (wantarray) {
6835: return ($quota,$quotatype,$settingstatus,$defquota);
6836: } else {
6837: return $quota;
6838: }
1.472 raeburn 6839: }
6840:
6841: ###############################################
6842:
6843: =pod
6844:
6845: =item * &default_quota()
6846:
1.536 raeburn 6847: Retrieves default quota assigned for storage of user portfolio files,
6848: given an (optional) user's institutional status.
1.472 raeburn 6849:
6850: Incoming parameters:
6851: 1. domain
1.536 raeburn 6852: 2. (Optional) institutional status(es). This is a : separated list of
6853: status types (e.g., faculty, staff, student etc.)
6854: which apply to the user for whom the default is being retrieved.
6855: If the institutional status string in undefined, the domain
6856: default quota will be returned.
1.472 raeburn 6857:
6858: Returns:
6859: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6860: 2. (Optional) institutional type which determined the value of the
6861: default quota.
1.472 raeburn 6862:
6863: If a value has been stored in the domain's configuration db,
6864: it will return that, otherwise it returns 20 (for backwards
6865: compatibility with domains which have not set up a configuration
6866: db file; the original statically defined portfolio quota was 20 Mb).
6867:
1.536 raeburn 6868: If the user's status includes multiple types (e.g., staff and student),
6869: the largest default quota which applies to the user determines the
6870: default quota returned.
6871:
1.472 raeburn 6872: =cut
6873:
6874: ###############################################
6875:
6876:
6877: sub default_quota {
1.536 raeburn 6878: my ($udom,$inststatus) = @_;
6879: my ($defquota,$settingstatus);
6880: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6881: ['quotas'],$udom);
6882: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6883: if ($inststatus ne '') {
6884: my @statuses = split(/:/,$inststatus);
6885: foreach my $item (@statuses) {
1.711 raeburn 6886: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6887: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6888: if ($defquota eq '') {
6889: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6890: $settingstatus = $item;
6891: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6892: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6893: $settingstatus = $item;
6894: }
6895: }
6896: } else {
6897: if ($quotahash{'quotas'}{$item} ne '') {
6898: if ($defquota eq '') {
6899: $defquota = $quotahash{'quotas'}{$item};
6900: $settingstatus = $item;
6901: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6902: $defquota = $quotahash{'quotas'}{$item};
6903: $settingstatus = $item;
6904: }
1.536 raeburn 6905: }
6906: }
6907: }
6908: }
6909: if ($defquota eq '') {
1.711 raeburn 6910: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6911: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6912: } else {
6913: $defquota = $quotahash{'quotas'}{'default'};
6914: }
1.536 raeburn 6915: $settingstatus = 'default';
6916: }
6917: } else {
6918: $settingstatus = 'default';
6919: $defquota = 20;
6920: }
6921: if (wantarray) {
6922: return ($defquota,$settingstatus);
1.472 raeburn 6923: } else {
1.536 raeburn 6924: return $defquota;
1.472 raeburn 6925: }
6926: }
6927:
1.384 raeburn 6928: sub get_secgrprole_info {
6929: my ($cdom,$cnum,$needroles,$type) = @_;
6930: my %sections_count = &get_sections($cdom,$cnum);
6931: my @sections = (sort {$a <=> $b} keys(%sections_count));
6932: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6933: my @groups = sort(keys(%curr_groups));
6934: my $allroles = [];
6935: my $rolehash;
6936: my $accesshash = {
6937: active => 'Currently has access',
6938: future => 'Will have future access',
6939: previous => 'Previously had access',
6940: };
6941: if ($needroles) {
6942: $rolehash = {'all' => 'all'};
1.385 albertel 6943: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6944: if (&Apache::lonnet::error(%user_roles)) {
6945: undef(%user_roles);
6946: }
6947: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6948: my ($role)=split(/\:/,$item,2);
6949: if ($role eq 'cr') { next; }
6950: if ($role =~ /^cr/) {
6951: $$rolehash{$role} = (split('/',$role))[3];
6952: } else {
6953: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6954: }
6955: }
6956: foreach my $key (sort(keys(%{$rolehash}))) {
6957: push(@{$allroles},$key);
6958: }
6959: push (@{$allroles},'st');
6960: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6961: }
6962: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6963: }
6964:
1.555 raeburn 6965: sub user_picker {
1.627 raeburn 6966: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6967: my $currdom = $dom;
6968: my %curr_selected = (
6969: srchin => 'dom',
1.580 raeburn 6970: srchby => 'lastname',
1.555 raeburn 6971: );
6972: my $srchterm;
1.625 raeburn 6973: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6974: if ($srch->{'srchby'} ne '') {
6975: $curr_selected{'srchby'} = $srch->{'srchby'};
6976: }
6977: if ($srch->{'srchin'} ne '') {
6978: $curr_selected{'srchin'} = $srch->{'srchin'};
6979: }
6980: if ($srch->{'srchtype'} ne '') {
6981: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6982: }
6983: if ($srch->{'srchdomain'} ne '') {
6984: $currdom = $srch->{'srchdomain'};
6985: }
6986: $srchterm = $srch->{'srchterm'};
6987: }
6988: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6989: 'usr' => 'Search criteria',
1.563 raeburn 6990: 'doma' => 'Domain/institution to search',
1.558 albertel 6991: 'uname' => 'username',
6992: 'lastname' => 'last name',
1.555 raeburn 6993: 'lastfirst' => 'last name, first name',
1.558 albertel 6994: 'crs' => 'in this course',
1.576 raeburn 6995: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6996: 'alc' => 'all LON-CAPA',
1.573 raeburn 6997: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6998: 'exact' => 'is',
6999: 'contains' => 'contains',
1.569 raeburn 7000: 'begins' => 'begins with',
1.571 raeburn 7001: 'youm' => "You must include some text to search for.",
7002: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7003: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7004: 'yomc' => "You must choose a domain when using an institutional directory search.",
7005: 'ymcd' => "You must choose a domain when using a domain search.",
7006: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7007: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7008: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7009: );
1.563 raeburn 7010: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7011: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7012:
7013: my @srchins = ('crs','dom','alc','instd');
7014:
7015: foreach my $option (@srchins) {
7016: # FIXME 'alc' option unavailable until
7017: # loncreateuser::print_user_query_page()
7018: # has been completed.
7019: next if ($option eq 'alc');
7020: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7021: if ($curr_selected{'srchin'} eq $option) {
7022: $srchinsel .= '
7023: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7024: } else {
7025: $srchinsel .= '
7026: <option value="'.$option.'">'.$lt{$option}.'</option>';
7027: }
1.555 raeburn 7028: }
1.563 raeburn 7029: $srchinsel .= "\n </select>\n";
1.555 raeburn 7030:
7031: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7032: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7033: if ($curr_selected{'srchby'} eq $option) {
7034: $srchbysel .= '
7035: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7036: } else {
7037: $srchbysel .= '
7038: <option value="'.$option.'">'.$lt{$option}.'</option>';
7039: }
7040: }
7041: $srchbysel .= "\n </select>\n";
7042:
7043: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7044: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7045: if ($curr_selected{'srchtype'} eq $option) {
7046: $srchtypesel .= '
7047: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7048: } else {
7049: $srchtypesel .= '
7050: <option value="'.$option.'">'.$lt{$option}.'</option>';
7051: }
7052: }
7053: $srchtypesel .= "\n </select>\n";
7054:
1.558 albertel 7055: my ($newuserscript,$new_user_create);
1.556 raeburn 7056:
7057: if ($forcenewuser) {
1.576 raeburn 7058: if (ref($srch) eq 'HASH') {
7059: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7060: if ($cancreate) {
7061: $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>';
7062: } else {
7063: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7064: my %usertypetext = (
7065: official => 'institutional',
7066: unofficial => 'non-institutional',
7067: );
7068: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
7069: }
1.576 raeburn 7070: }
7071: }
7072:
1.556 raeburn 7073: $newuserscript = <<"ENDSCRIPT";
7074:
1.570 raeburn 7075: function setSearch(createnew,callingForm) {
1.556 raeburn 7076: if (createnew == 1) {
1.570 raeburn 7077: for (var i=0; i<callingForm.srchby.length; i++) {
7078: if (callingForm.srchby.options[i].value == 'uname') {
7079: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7080: }
7081: }
1.570 raeburn 7082: for (var i=0; i<callingForm.srchin.length; i++) {
7083: if ( callingForm.srchin.options[i].value == 'dom') {
7084: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7085: }
7086: }
1.570 raeburn 7087: for (var i=0; i<callingForm.srchtype.length; i++) {
7088: if (callingForm.srchtype.options[i].value == 'exact') {
7089: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7090: }
7091: }
1.570 raeburn 7092: for (var i=0; i<callingForm.srchdomain.length; i++) {
7093: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7094: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7095: }
7096: }
7097: }
7098: }
7099: ENDSCRIPT
1.558 albertel 7100:
1.556 raeburn 7101: }
7102:
1.555 raeburn 7103: my $output = <<"END_BLOCK";
1.556 raeburn 7104: <script type="text/javascript">
1.570 raeburn 7105: function validateEntry(callingForm) {
1.558 albertel 7106:
1.556 raeburn 7107: var checkok = 1;
1.558 albertel 7108: var srchin;
1.570 raeburn 7109: for (var i=0; i<callingForm.srchin.length; i++) {
7110: if ( callingForm.srchin[i].checked ) {
7111: srchin = callingForm.srchin[i].value;
1.558 albertel 7112: }
7113: }
7114:
1.570 raeburn 7115: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7116: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7117: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7118: var srchterm = callingForm.srchterm.value;
7119: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7120: var msg = "";
7121:
7122: if (srchterm == "") {
7123: checkok = 0;
1.571 raeburn 7124: msg += "$lt{'youm'}\\n";
1.556 raeburn 7125: }
7126:
1.569 raeburn 7127: if (srchtype== 'begins') {
7128: if (srchterm.length < 2) {
7129: checkok = 0;
1.571 raeburn 7130: msg += "$lt{'thte'}\\n";
1.569 raeburn 7131: }
7132: }
7133:
1.556 raeburn 7134: if (srchtype== 'contains') {
7135: if (srchterm.length < 3) {
7136: checkok = 0;
1.571 raeburn 7137: msg += "$lt{'thet'}\\n";
1.556 raeburn 7138: }
7139: }
7140: if (srchin == 'instd') {
7141: if (srchdomain == '') {
7142: checkok = 0;
1.571 raeburn 7143: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7144: }
7145: }
7146: if (srchin == 'dom') {
7147: if (srchdomain == '') {
7148: checkok = 0;
1.571 raeburn 7149: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7150: }
7151: }
7152: if (srchby == 'lastfirst') {
7153: if (srchterm.indexOf(",") == -1) {
7154: checkok = 0;
1.571 raeburn 7155: msg += "$lt{'whus'}\\n";
1.556 raeburn 7156: }
7157: if (srchterm.indexOf(",") == srchterm.length -1) {
7158: checkok = 0;
1.571 raeburn 7159: msg += "$lt{'whse'}\\n";
1.556 raeburn 7160: }
7161: }
7162: if (checkok == 0) {
1.571 raeburn 7163: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7164: return;
7165: }
7166: if (checkok == 1) {
1.570 raeburn 7167: callingForm.submit();
1.556 raeburn 7168: }
7169: }
7170:
7171: $newuserscript
7172:
7173: </script>
1.558 albertel 7174:
7175: $new_user_create
7176:
1.555 raeburn 7177: <table>
1.558 albertel 7178: <tr>
1.573 raeburn 7179: <td>$lt{'doma'}:</td>
7180: <td>$domform</td>
7181: </td>
7182: </tr>
7183: <tr>
7184: <td>$lt{'usr'}:</td>
1.563 raeburn 7185: <td>$srchbysel
7186: $srchtypesel
7187: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7188: $srchinsel
1.563 raeburn 7189: </td>
7190: </tr>
1.555 raeburn 7191: </table>
7192: <br />
7193: END_BLOCK
1.558 albertel 7194:
1.555 raeburn 7195: return $output;
7196: }
7197:
1.612 raeburn 7198: sub user_rule_check {
1.615 raeburn 7199: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7200: my $response;
7201: if (ref($usershash) eq 'HASH') {
7202: foreach my $user (keys(%{$usershash})) {
7203: my ($uname,$udom) = split(/:/,$user);
7204: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7205: my ($id,$newuser);
1.612 raeburn 7206: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7207: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7208: $id = $usershash->{$user}->{'id'};
7209: }
7210: my $inst_response;
7211: if (ref($checks) eq 'HASH') {
7212: if (defined($checks->{'username'})) {
1.615 raeburn 7213: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7214: &Apache::lonnet::get_instuser($udom,$uname);
7215: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7216: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7217: &Apache::lonnet::get_instuser($udom,undef,$id);
7218: }
1.615 raeburn 7219: } else {
7220: ($inst_response,%{$inst_results->{$user}}) =
7221: &Apache::lonnet::get_instuser($udom,$uname);
7222: return;
1.612 raeburn 7223: }
1.615 raeburn 7224: if (!$got_rules->{$udom}) {
1.612 raeburn 7225: my %domconfig = &Apache::lonnet::get_dom('configuration',
7226: ['usercreation'],$udom);
7227: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7228: foreach my $item ('username','id') {
1.612 raeburn 7229: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7230: $$curr_rules{$udom}{$item} =
7231: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7232: }
7233: }
7234: }
1.615 raeburn 7235: $got_rules->{$udom} = 1;
1.585 raeburn 7236: }
1.612 raeburn 7237: foreach my $item (keys(%{$checks})) {
7238: if (ref($$curr_rules{$udom}) eq 'HASH') {
7239: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7240: if (@{$$curr_rules{$udom}{$item}} > 0) {
7241: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7242: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7243: if ($rule_check{$rule}) {
7244: $$rulematch{$user}{$item} = $rule;
7245: if ($inst_response eq 'ok') {
1.615 raeburn 7246: if (ref($inst_results) eq 'HASH') {
7247: if (ref($inst_results->{$user}) eq 'HASH') {
7248: if (keys(%{$inst_results->{$user}}) == 0) {
7249: $$alerts{$item}{$udom}{$uname} = 1;
7250: }
1.612 raeburn 7251: }
7252: }
1.615 raeburn 7253: }
7254: last;
1.585 raeburn 7255: }
7256: }
7257: }
7258: }
7259: }
7260: }
7261: }
7262: }
1.612 raeburn 7263: return;
7264: }
7265:
7266: sub user_rule_formats {
7267: my ($domain,$domdesc,$curr_rules,$check) = @_;
7268: my %text = (
7269: 'username' => 'Usernames',
7270: 'id' => 'IDs',
7271: );
7272: my $output;
7273: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7274: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7275: if (@{$ruleorder} > 0) {
7276: $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>';
7277: foreach my $rule (@{$ruleorder}) {
7278: if (ref($curr_rules) eq 'ARRAY') {
7279: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7280: if (ref($rules->{$rule}) eq 'HASH') {
7281: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7282: $rules->{$rule}{'desc'}.'</li>';
7283: }
7284: }
7285: }
7286: }
7287: $output .= '</ul>';
7288: }
7289: }
7290: return $output;
7291: }
7292:
7293: sub instrule_disallow_msg {
1.615 raeburn 7294: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7295: my $response;
7296: my %text = (
7297: item => 'username',
7298: items => 'usernames',
7299: match => 'matches',
7300: do => 'does',
7301: action => 'a username',
7302: one => 'one',
7303: );
7304: if ($count > 1) {
7305: $text{'item'} = 'usernames';
7306: $text{'match'} ='match';
7307: $text{'do'} = 'do';
7308: $text{'action'} = 'usernames',
7309: $text{'one'} = 'ones';
7310: }
7311: if ($checkitem eq 'id') {
7312: $text{'items'} = 'IDs';
7313: $text{'item'} = 'ID';
7314: $text{'action'} = 'an ID';
1.615 raeburn 7315: if ($count > 1) {
7316: $text{'item'} = 'IDs';
7317: $text{'action'} = 'IDs';
7318: }
1.612 raeburn 7319: }
1.674 bisitz 7320: $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 7321: if ($mode eq 'upload') {
7322: if ($checkitem eq 'username') {
7323: $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'}.");
7324: } elsif ($checkitem eq 'id') {
1.674 bisitz 7325: $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 7326: }
1.669 raeburn 7327: } elsif ($mode eq 'selfcreate') {
7328: if ($checkitem eq 'id') {
7329: $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.");
7330: }
1.615 raeburn 7331: } else {
7332: if ($checkitem eq 'username') {
7333: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7334: } elsif ($checkitem eq 'id') {
7335: $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.");
7336: }
1.612 raeburn 7337: }
7338: return $response;
1.585 raeburn 7339: }
7340:
1.624 raeburn 7341: sub personal_data_fieldtitles {
7342: my %fieldtitles = &Apache::lonlocal::texthash (
7343: id => 'Student/Employee ID',
7344: permanentemail => 'E-mail address',
7345: lastname => 'Last Name',
7346: firstname => 'First Name',
7347: middlename => 'Middle Name',
7348: generation => 'Generation',
7349: gen => 'Generation',
7350: );
7351: return %fieldtitles;
7352: }
7353:
1.642 raeburn 7354: sub sorted_inst_types {
7355: my ($dom) = @_;
7356: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7357: my $othertitle = &mt('All users');
7358: if ($env{'request.course.id'}) {
1.668 raeburn 7359: $othertitle = &mt('Any users');
1.642 raeburn 7360: }
7361: my @types;
7362: if (ref($order) eq 'ARRAY') {
7363: @types = @{$order};
7364: }
7365: if (@types == 0) {
7366: if (ref($usertypes) eq 'HASH') {
7367: @types = sort(keys(%{$usertypes}));
7368: }
7369: }
7370: if (keys(%{$usertypes}) > 0) {
7371: $othertitle = &mt('Other users');
7372: }
7373: return ($othertitle,$usertypes,\@types);
7374: }
7375:
1.645 raeburn 7376: sub get_institutional_codes {
7377: my ($settings,$allcourses,$LC_code) = @_;
7378: # Get complete list of course sections to update
7379: my @currsections = ();
7380: my @currxlists = ();
7381: my $coursecode = $$settings{'internal.coursecode'};
7382:
7383: if ($$settings{'internal.sectionnums'} ne '') {
7384: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7385: }
7386:
7387: if ($$settings{'internal.crosslistings'} ne '') {
7388: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7389: }
7390:
7391: if (@currxlists > 0) {
7392: foreach (@currxlists) {
7393: if (m/^([^:]+):(\w*)$/) {
7394: unless (grep/^$1$/,@{$allcourses}) {
7395: push @{$allcourses},$1;
7396: $$LC_code{$1} = $2;
7397: }
7398: }
7399: }
7400: }
7401:
7402: if (@currsections > 0) {
7403: foreach (@currsections) {
7404: if (m/^(\w+):(\w*)$/) {
7405: my $sec = $coursecode.$1;
7406: my $lc_sec = $2;
7407: unless (grep/^$sec$/,@{$allcourses}) {
7408: push @{$allcourses},$sec;
7409: $$LC_code{$sec} = $lc_sec;
7410: }
7411: }
7412: }
7413: }
7414: return;
7415: }
7416:
1.112 bowersj2 7417: =pod
7418:
1.549 albertel 7419: =back
7420:
7421: =head1 HTTP Helpers
7422:
7423: =over 4
7424:
1.648 raeburn 7425: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7426:
1.258 albertel 7427: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7428: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7429: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7430:
7431: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7432: $possible_names is an ref to an array of form element names. As an example:
7433: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7434: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7435:
7436: =cut
1.1 albertel 7437:
1.6 albertel 7438: sub get_unprocessed_cgi {
1.25 albertel 7439: my ($query,$possible_names)= @_;
1.26 matthew 7440: # $Apache::lonxml::debug=1;
1.356 albertel 7441: foreach my $pair (split(/&/,$query)) {
7442: my ($name, $value) = split(/=/,$pair);
1.369 www 7443: $name = &unescape($name);
1.25 albertel 7444: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7445: $value =~ tr/+/ /;
7446: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7447: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7448: }
1.16 harris41 7449: }
1.6 albertel 7450: }
7451:
1.112 bowersj2 7452: =pod
7453:
1.648 raeburn 7454: =item * &cacheheader()
1.112 bowersj2 7455:
7456: returns cache-controlling header code
7457:
7458: =cut
7459:
1.7 albertel 7460: sub cacheheader {
1.258 albertel 7461: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7462: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7463: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7464: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7465: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7466: return $output;
1.7 albertel 7467: }
7468:
1.112 bowersj2 7469: =pod
7470:
1.648 raeburn 7471: =item * &no_cache($r)
1.112 bowersj2 7472:
7473: specifies header code to not have cache
7474:
7475: =cut
7476:
1.9 albertel 7477: sub no_cache {
1.216 albertel 7478: my ($r) = @_;
7479: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7480: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7481: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7482: $r->no_cache(1);
7483: $r->header_out("Expires" => $date);
7484: $r->header_out("Pragma" => "no-cache");
1.123 www 7485: }
7486:
7487: sub content_type {
1.181 albertel 7488: my ($r,$type,$charset) = @_;
1.299 foxr 7489: if ($r) {
7490: # Note that printout.pl calls this with undef for $r.
7491: &no_cache($r);
7492: }
1.258 albertel 7493: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7494: unless ($charset) {
7495: $charset=&Apache::lonlocal::current_encoding;
7496: }
7497: if ($charset) { $type.='; charset='.$charset; }
7498: if ($r) {
7499: $r->content_type($type);
7500: } else {
7501: print("Content-type: $type\n\n");
7502: }
1.9 albertel 7503: }
1.25 albertel 7504:
1.112 bowersj2 7505: =pod
7506:
1.648 raeburn 7507: =item * &add_to_env($name,$value)
1.112 bowersj2 7508:
1.258 albertel 7509: adds $name to the %env hash with value
1.112 bowersj2 7510: $value, if $name already exists, the entry is converted to an array
7511: reference and $value is added to the array.
7512:
7513: =cut
7514:
1.25 albertel 7515: sub add_to_env {
7516: my ($name,$value)=@_;
1.258 albertel 7517: if (defined($env{$name})) {
7518: if (ref($env{$name})) {
1.25 albertel 7519: #already have multiple values
1.258 albertel 7520: push(@{ $env{$name} },$value);
1.25 albertel 7521: } else {
7522: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7523: my $first=$env{$name};
7524: undef($env{$name});
7525: push(@{ $env{$name} },$first,$value);
1.25 albertel 7526: }
7527: } else {
1.258 albertel 7528: $env{$name}=$value;
1.25 albertel 7529: }
1.31 albertel 7530: }
1.149 albertel 7531:
7532: =pod
7533:
1.648 raeburn 7534: =item * &get_env_multiple($name)
1.149 albertel 7535:
1.258 albertel 7536: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7537: values may be defined and end up as an array ref.
7538:
7539: returns an array of values
7540:
7541: =cut
7542:
7543: sub get_env_multiple {
7544: my ($name) = @_;
7545: my @values;
1.258 albertel 7546: if (defined($env{$name})) {
1.149 albertel 7547: # exists is it an array
1.258 albertel 7548: if (ref($env{$name})) {
7549: @values=@{ $env{$name} };
1.149 albertel 7550: } else {
1.258 albertel 7551: $values[0]=$env{$name};
1.149 albertel 7552: }
7553: }
7554: return(@values);
7555: }
7556:
1.660 raeburn 7557: sub ask_for_embedded_content {
7558: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7559: my $upload_output = '
7560: <form name="upload_embedded" action="'.$actionurl.'"
7561: method="post" enctype="multipart/form-data">';
7562: $upload_output .= $state;
1.661 raeburn 7563: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7564:
7565: my $num = 0;
7566: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7567: $upload_output .= &start_data_table_row().
7568: '<td>'.$embed_file.'</td><td>';
7569: if ($args->{'ignore_remote_references'}
7570: && $embed_file =~ m{^\w+://}) {
7571: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7572: } elsif ($args->{'error_on_invalid_names'}
7573: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7574:
7575: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7576:
7577: } else {
7578: $upload_output .='
1.661 raeburn 7579: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7580: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7581: my $attrib = join(':',@{$$allfiles{$embed_file}});
7582: $upload_output .=
7583: "\n\t\t".
7584: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7585: $attrib.'" />';
7586: if (exists($$codebase{$embed_file})) {
7587: $upload_output .=
7588: "\n\t\t".
7589: '<input name="codebase_'.$num.'" type="hidden" value="'.
7590: &escape($$codebase{$embed_file}).'" />';
7591: }
7592: }
7593: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7594: $num++;
7595: }
7596: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7597: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7598: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7599: '.&mt('(only files for which a location has been provided will be uploaded)').'
7600: </form>';
7601: return $upload_output;
7602: }
7603:
1.661 raeburn 7604: sub upload_embedded {
7605: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7606: $current_disk_usage) = @_;
7607: my $output;
7608: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7609: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7610: my $orig_uploaded_filename =
7611: $env{'form.embedded_item_'.$i.'.filename'};
7612:
7613: $env{'form.embedded_orig_'.$i} =
7614: &unescape($env{'form.embedded_orig_'.$i});
7615: my ($path,$fname) =
7616: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7617: # no path, whole string is fname
7618: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7619:
7620: $path = $env{'form.currentpath'}.$path;
7621: $fname = &Apache::lonnet::clean_filename($fname);
7622: # See if there is anything left
7623: next if ($fname eq '');
7624:
7625: # Check if file already exists as a file or directory.
7626: my ($state,$msg);
7627: if ($context eq 'portfolio') {
7628: my $port_path = $dirpath;
7629: if ($group ne '') {
7630: $port_path = "groups/$group/$port_path";
7631: }
7632: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7633: $dir_root,$port_path,$disk_quota,
7634: $current_disk_usage,$uname,$udom);
7635: if ($state eq 'will_exceed_quota'
7636: || $state eq 'file_locked'
7637: || $state eq 'file_exists' ) {
7638: $output .= $msg;
7639: next;
7640: }
7641: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7642: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7643: if ($state eq 'exists') {
7644: $output .= $msg;
7645: next;
7646: }
7647: }
7648: # Check if extension is valid
7649: if (($fname =~ /\.(\w+)$/) &&
7650: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7651: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7652: next;
7653: } elsif (($fname =~ /\.(\w+)$/) &&
7654: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7655: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7656: next;
7657: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7658: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7659: next;
7660: }
7661:
7662: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7663: if ($context eq 'portfolio') {
7664: my $result=
7665: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7666: $dirpath.$path);
7667: if ($result !~ m|^/uploaded/|) {
7668: $output .= '<span class="LC_error">'
7669: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7670: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7671: .'</span><br />';
7672: next;
7673: } else {
7674: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7675: $path.$fname.'</span>').'</p>';
7676: }
7677: } else {
7678: # Save the file
7679: my $target = $env{'form.embedded_item_'.$i};
7680: my $fullpath = $dir_root.$dirpath.'/'.$path;
7681: my $dest = $fullpath.$fname;
7682: my $url = $url_root.$dirpath.'/'.$path.$fname;
7683: my @parts=split(/\//,$fullpath);
7684: my $count;
7685: my $filepath = $dir_root;
7686: for ($count=4;$count<=$#parts;$count++) {
7687: $filepath .= "/$parts[$count]";
7688: if ((-e $filepath)!=1) {
7689: mkdir($filepath,0770);
7690: }
7691: }
7692: my $fh;
7693: if (!open($fh,'>'.$dest)) {
7694: &Apache::lonnet::logthis('Failed to create '.$dest);
7695: $output .= '<span class="LC_error">'.
7696: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7697: '</span><br />';
7698: } else {
7699: if (!print $fh $env{'form.embedded_item_'.$i}) {
7700: &Apache::lonnet::logthis('Failed to write to '.$dest);
7701: $output .= '<span class="LC_error">'.
7702: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7703: '</span><br />';
7704: } else {
7705: if ($context eq 'testbank') {
7706: $output .= &mt('Embedded file uploaded successfully:').
7707: ' <a href="'.$url.'">'.
7708: $orig_uploaded_filename.'</a><br />';
7709: } else {
1.705 tempelho 7710: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 7711: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 7712: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 7713: }
7714: }
7715: close($fh);
7716: }
7717: }
7718: }
7719: return $output;
7720: }
7721:
7722: sub check_for_existing {
7723: my ($path,$fname,$element) = @_;
7724: my ($state,$msg);
7725: if (-d $path.'/'.$fname) {
7726: $state = 'exists';
7727: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7728: } elsif (-e $path.'/'.$fname) {
7729: $state = 'exists';
7730: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7731: }
7732: if ($state eq 'exists') {
7733: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7734: }
7735: return ($state,$msg);
7736: }
7737:
7738: sub check_for_upload {
7739: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7740: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7741: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7742: my $getpropath = 1;
7743: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7744: $getpropath);
7745: my $found_file = 0;
7746: my $locked_file = 0;
7747: foreach my $line (@dir_list) {
7748: my ($file_name)=split(/\&/,$line,2);
7749: if ($file_name eq $fname){
7750: $file_name = $path.$file_name;
7751: if ($group ne '') {
7752: $file_name = $group.$file_name;
7753: }
7754: $found_file = 1;
7755: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7756: $locked_file = 1;
7757: }
7758: }
7759: }
7760: if (($current_disk_usage + $filesize) > $disk_quota){
7761: my $msg = '<span class="LC_error">'.
7762: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7763: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7764: return ('will_exceed_quota',$msg);
7765: } elsif ($found_file) {
7766: if ($locked_file) {
7767: my $msg = '<span class="LC_error">';
7768: $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>');
7769: $msg .= '</span><br />';
7770: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7771: return ('file_locked',$msg);
7772: } else {
7773: my $msg = '<span class="LC_error">';
7774: $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'});
7775: $msg .= '</span>';
7776: $msg .= '<br />';
7777: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7778: return ('file_exists',$msg);
7779: }
7780: }
7781: }
7782:
1.31 albertel 7783:
1.41 ng 7784: =pod
1.45 matthew 7785:
1.464 albertel 7786: =back
1.41 ng 7787:
1.112 bowersj2 7788: =head1 CSV Upload/Handling functions
1.38 albertel 7789:
1.41 ng 7790: =over 4
7791:
1.648 raeburn 7792: =item * &upfile_store($r)
1.41 ng 7793:
7794: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7795: needs $env{'form.upfile'}
1.41 ng 7796: returns $datatoken to be put into hidden field
7797:
7798: =cut
1.31 albertel 7799:
7800: sub upfile_store {
7801: my $r=shift;
1.258 albertel 7802: $env{'form.upfile'}=~s/\r/\n/gs;
7803: $env{'form.upfile'}=~s/\f/\n/gs;
7804: $env{'form.upfile'}=~s/\n+/\n/gs;
7805: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7806:
1.258 albertel 7807: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7808: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7809: {
1.158 raeburn 7810: my $datafile = $r->dir_config('lonDaemons').
7811: '/tmp/'.$datatoken.'.tmp';
7812: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7813: print $fh $env{'form.upfile'};
1.158 raeburn 7814: close($fh);
7815: }
1.31 albertel 7816: }
7817: return $datatoken;
7818: }
7819:
1.56 matthew 7820: =pod
7821:
1.648 raeburn 7822: =item * &load_tmp_file($r)
1.41 ng 7823:
7824: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7825: needs $env{'form.datatoken'},
7826: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7827:
7828: =cut
1.31 albertel 7829:
7830: sub load_tmp_file {
7831: my $r=shift;
7832: my @studentdata=();
7833: {
1.158 raeburn 7834: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7835: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7836: if ( open(my $fh,"<$studentfile") ) {
7837: @studentdata=<$fh>;
7838: close($fh);
7839: }
1.31 albertel 7840: }
1.258 albertel 7841: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7842: }
7843:
1.56 matthew 7844: =pod
7845:
1.648 raeburn 7846: =item * &upfile_record_sep()
1.41 ng 7847:
7848: Separate uploaded file into records
7849: returns array of records,
1.258 albertel 7850: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7851:
7852: =cut
1.31 albertel 7853:
7854: sub upfile_record_sep {
1.258 albertel 7855: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7856: } else {
1.248 albertel 7857: my @records;
1.258 albertel 7858: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7859: if ($line=~/^\s*$/) { next; }
7860: push(@records,$line);
7861: }
7862: return @records;
1.31 albertel 7863: }
7864: }
7865:
1.56 matthew 7866: =pod
7867:
1.648 raeburn 7868: =item * &record_sep($record)
1.41 ng 7869:
1.258 albertel 7870: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7871:
7872: =cut
7873:
1.263 www 7874: sub takeleft {
7875: my $index=shift;
7876: return substr('0000'.$index,-4,4);
7877: }
7878:
1.31 albertel 7879: sub record_sep {
7880: my $record=shift;
7881: my %components=();
1.258 albertel 7882: if ($env{'form.upfiletype'} eq 'xml') {
7883: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7884: my $i=0;
1.356 albertel 7885: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7886: $field=~s/^(\"|\')//;
7887: $field=~s/(\"|\')$//;
1.263 www 7888: $components{&takeleft($i)}=$field;
1.31 albertel 7889: $i++;
7890: }
1.258 albertel 7891: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7892: my $i=0;
1.356 albertel 7893: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7894: $field=~s/^(\"|\')//;
7895: $field=~s/(\"|\')$//;
1.263 www 7896: $components{&takeleft($i)}=$field;
1.31 albertel 7897: $i++;
7898: }
7899: } else {
1.561 www 7900: my $separator=',';
1.480 banghart 7901: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7902: $separator=';';
1.480 banghart 7903: }
1.31 albertel 7904: my $i=0;
1.561 www 7905: # the character we are looking for to indicate the end of a quote or a record
7906: my $looking_for=$separator;
7907: # do not add the characters to the fields
7908: my $ignore=0;
7909: # we just encountered a separator (or the beginning of the record)
7910: my $just_found_separator=1;
7911: # store the field we are working on here
7912: my $field='';
7913: # work our way through all characters in record
7914: foreach my $character ($record=~/(.)/g) {
7915: if ($character eq $looking_for) {
7916: if ($character ne $separator) {
7917: # Found the end of a quote, again looking for separator
7918: $looking_for=$separator;
7919: $ignore=1;
7920: } else {
7921: # Found a separator, store away what we got
7922: $components{&takeleft($i)}=$field;
7923: $i++;
7924: $just_found_separator=1;
7925: $ignore=0;
7926: $field='';
7927: }
7928: next;
7929: }
7930: # single or double quotation marks after a separator indicate beginning of a quote
7931: # we are now looking for the end of the quote and need to ignore separators
7932: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7933: $looking_for=$character;
7934: next;
7935: }
7936: # ignore would be true after we reached the end of a quote
7937: if ($ignore) { next; }
7938: if (($just_found_separator) && ($character=~/\s/)) { next; }
7939: $field.=$character;
7940: $just_found_separator=0;
1.31 albertel 7941: }
1.561 www 7942: # catch the very last entry, since we never encountered the separator
7943: $components{&takeleft($i)}=$field;
1.31 albertel 7944: }
7945: return %components;
7946: }
7947:
1.144 matthew 7948: ######################################################
7949: ######################################################
7950:
1.56 matthew 7951: =pod
7952:
1.648 raeburn 7953: =item * &upfile_select_html()
1.41 ng 7954:
1.144 matthew 7955: Return HTML code to select a file from the users machine and specify
7956: the file type.
1.41 ng 7957:
7958: =cut
7959:
1.144 matthew 7960: ######################################################
7961: ######################################################
1.31 albertel 7962: sub upfile_select_html {
1.144 matthew 7963: my %Types = (
7964: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7965: semisv => &mt('Semicolon separated values'),
1.144 matthew 7966: space => &mt('Space separated'),
7967: tab => &mt('Tabulator separated'),
7968: # xml => &mt('HTML/XML'),
7969: );
7970: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 7971: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 7972: foreach my $type (sort(keys(%Types))) {
7973: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7974: }
7975: $Str .= "</select>\n";
7976: return $Str;
1.31 albertel 7977: }
7978:
1.301 albertel 7979: sub get_samples {
7980: my ($records,$toget) = @_;
7981: my @samples=({});
7982: my $got=0;
7983: foreach my $rec (@$records) {
7984: my %temp = &record_sep($rec);
7985: if (! grep(/\S/, values(%temp))) { next; }
7986: if (%temp) {
7987: $samples[$got]=\%temp;
7988: $got++;
7989: if ($got == $toget) { last; }
7990: }
7991: }
7992: return \@samples;
7993: }
7994:
1.144 matthew 7995: ######################################################
7996: ######################################################
7997:
1.56 matthew 7998: =pod
7999:
1.648 raeburn 8000: =item * &csv_print_samples($r,$records)
1.41 ng 8001:
8002: Prints a table of sample values from each column uploaded $r is an
8003: Apache Request ref, $records is an arrayref from
8004: &Apache::loncommon::upfile_record_sep
8005:
8006: =cut
8007:
1.144 matthew 8008: ######################################################
8009: ######################################################
1.31 albertel 8010: sub csv_print_samples {
8011: my ($r,$records) = @_;
1.662 bisitz 8012: my $samples = &get_samples($records,5);
1.301 albertel 8013:
1.594 raeburn 8014: $r->print(&mt('Samples').'<br />'.&start_data_table().
8015: &start_data_table_header_row());
1.356 albertel 8016: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8017: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8018: $r->print(&end_data_table_header_row());
1.301 albertel 8019: foreach my $hash (@$samples) {
1.594 raeburn 8020: $r->print(&start_data_table_row());
1.356 albertel 8021: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8022: $r->print('<td>');
1.356 albertel 8023: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8024: $r->print('</td>');
8025: }
1.594 raeburn 8026: $r->print(&end_data_table_row());
1.31 albertel 8027: }
1.594 raeburn 8028: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8029: }
8030:
1.144 matthew 8031: ######################################################
8032: ######################################################
8033:
1.56 matthew 8034: =pod
8035:
1.648 raeburn 8036: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8037:
8038: Prints a table to create associations between values and table columns.
1.144 matthew 8039:
1.41 ng 8040: $r is an Apache Request ref,
8041: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8042: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8043:
8044: =cut
8045:
1.144 matthew 8046: ######################################################
8047: ######################################################
1.31 albertel 8048: sub csv_print_select_table {
8049: my ($r,$records,$d) = @_;
1.301 albertel 8050: my $i=0;
8051: my $samples = &get_samples($records,1);
1.144 matthew 8052: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8053: &start_data_table().&start_data_table_header_row().
1.144 matthew 8054: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8055: '<th>'.&mt('Column').'</th>'.
8056: &end_data_table_header_row()."\n");
1.356 albertel 8057: foreach my $array_ref (@$d) {
8058: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8059: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8060:
8061: $r->print('<td><select name=f'.$i.
1.32 matthew 8062: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8063: $r->print('<option value="none"></option>');
1.356 albertel 8064: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8065: $r->print('<option value="'.$sample.'"'.
8066: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8067: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8068: }
1.594 raeburn 8069: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8070: $i++;
8071: }
1.594 raeburn 8072: $r->print(&end_data_table());
1.31 albertel 8073: $i--;
8074: return $i;
8075: }
1.56 matthew 8076:
1.144 matthew 8077: ######################################################
8078: ######################################################
8079:
1.56 matthew 8080: =pod
1.31 albertel 8081:
1.648 raeburn 8082: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8083:
8084: Prints a table of sample values from the upload and can make associate samples to internal names.
8085:
8086: $r is an Apache Request ref,
8087: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8088: $d is an array of 2 element arrays (internal name, displayed name)
8089:
8090: =cut
8091:
1.144 matthew 8092: ######################################################
8093: ######################################################
1.31 albertel 8094: sub csv_samples_select_table {
8095: my ($r,$records,$d) = @_;
8096: my $i=0;
1.144 matthew 8097: #
1.662 bisitz 8098: my $max_samples = 5;
8099: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8100: $r->print(&start_data_table().
8101: &start_data_table_header_row().'<th>'.
8102: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8103: &end_data_table_header_row());
1.301 albertel 8104:
8105: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8106: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8107: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8108: foreach my $option (@$d) {
8109: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8110: $r->print('<option value="'.$value.'"'.
1.253 albertel 8111: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8112: $display.'</option>');
1.31 albertel 8113: }
8114: $r->print('</select></td><td>');
1.662 bisitz 8115: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8116: if (defined($samples->[$line]{$key})) {
8117: $r->print($samples->[$line]{$key}."<br />\n");
8118: }
8119: }
1.594 raeburn 8120: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8121: $i++;
8122: }
1.594 raeburn 8123: $r->print(&end_data_table());
1.31 albertel 8124: $i--;
8125: return($i);
1.115 matthew 8126: }
8127:
1.144 matthew 8128: ######################################################
8129: ######################################################
8130:
1.115 matthew 8131: =pod
8132:
1.648 raeburn 8133: =item * &clean_excel_name($name)
1.115 matthew 8134:
8135: Returns a replacement for $name which does not contain any illegal characters.
8136:
8137: =cut
8138:
1.144 matthew 8139: ######################################################
8140: ######################################################
1.115 matthew 8141: sub clean_excel_name {
8142: my ($name) = @_;
8143: $name =~ s/[:\*\?\/\\]//g;
8144: if (length($name) > 31) {
8145: $name = substr($name,0,31);
8146: }
8147: return $name;
1.25 albertel 8148: }
1.84 albertel 8149:
1.85 albertel 8150: =pod
8151:
1.648 raeburn 8152: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8153:
8154: Returns either 1 or undef
8155:
8156: 1 if the part is to be hidden, undef if it is to be shown
8157:
8158: Arguments are:
8159:
8160: $id the id of the part to be checked
8161: $symb, optional the symb of the resource to check
8162: $udom, optional the domain of the user to check for
8163: $uname, optional the username of the user to check for
8164:
8165: =cut
1.84 albertel 8166:
8167: sub check_if_partid_hidden {
8168: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8169: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8170: $symb,$udom,$uname);
1.141 albertel 8171: my $truth=1;
8172: #if the string starts with !, then the list is the list to show not hide
8173: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8174: my @hiddenlist=split(/,/,$hiddenparts);
8175: foreach my $checkid (@hiddenlist) {
1.141 albertel 8176: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8177: }
1.141 albertel 8178: return !$truth;
1.84 albertel 8179: }
1.127 matthew 8180:
1.138 matthew 8181:
8182: ############################################################
8183: ############################################################
8184:
8185: =pod
8186:
1.157 matthew 8187: =back
8188:
1.138 matthew 8189: =head1 cgi-bin script and graphing routines
8190:
1.157 matthew 8191: =over 4
8192:
1.648 raeburn 8193: =item * &get_cgi_id()
1.138 matthew 8194:
8195: Inputs: none
8196:
8197: Returns an id which can be used to pass environment variables
8198: to various cgi-bin scripts. These environment variables will
8199: be removed from the users environment after a given time by
8200: the routine &Apache::lonnet::transfer_profile_to_env.
8201:
8202: =cut
8203:
8204: ############################################################
8205: ############################################################
1.152 albertel 8206: my $uniq=0;
1.136 matthew 8207: sub get_cgi_id {
1.154 albertel 8208: $uniq=($uniq+1)%100000;
1.280 albertel 8209: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8210: }
8211:
1.127 matthew 8212: ############################################################
8213: ############################################################
8214:
8215: =pod
8216:
1.648 raeburn 8217: =item * &DrawBarGraph()
1.127 matthew 8218:
1.138 matthew 8219: Facilitates the plotting of data in a (stacked) bar graph.
8220: Puts plot definition data into the users environment in order for
8221: graph.png to plot it. Returns an <img> tag for the plot.
8222: The bars on the plot are labeled '1','2',...,'n'.
8223:
8224: Inputs:
8225:
8226: =over 4
8227:
8228: =item $Title: string, the title of the plot
8229:
8230: =item $xlabel: string, text describing the X-axis of the plot
8231:
8232: =item $ylabel: string, text describing the Y-axis of the plot
8233:
8234: =item $Max: scalar, the maximum Y value to use in the plot
8235: If $Max is < any data point, the graph will not be rendered.
8236:
1.140 matthew 8237: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8238: they are plotted. If undefined, default values will be used.
8239:
1.178 matthew 8240: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8241:
1.138 matthew 8242: =item @Values: An array of array references. Each array reference holds data
8243: to be plotted in a stacked bar chart.
8244:
1.239 matthew 8245: =item If the final element of @Values is a hash reference the key/value
8246: pairs will be added to the graph definition.
8247:
1.138 matthew 8248: =back
8249:
8250: Returns:
8251:
8252: An <img> tag which references graph.png and the appropriate identifying
8253: information for the plot.
8254:
1.127 matthew 8255: =cut
8256:
8257: ############################################################
8258: ############################################################
1.134 matthew 8259: sub DrawBarGraph {
1.178 matthew 8260: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8261: #
8262: if (! defined($colors)) {
8263: $colors = ['#33ff00',
8264: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8265: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8266: ];
8267: }
1.228 matthew 8268: my $extra_settings = {};
8269: if (ref($Values[-1]) eq 'HASH') {
8270: $extra_settings = pop(@Values);
8271: }
1.127 matthew 8272: #
1.136 matthew 8273: my $identifier = &get_cgi_id();
8274: my $id = 'cgi.'.$identifier;
1.129 matthew 8275: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8276: return '';
8277: }
1.225 matthew 8278: #
8279: my @Labels;
8280: if (defined($labels)) {
8281: @Labels = @$labels;
8282: } else {
8283: for (my $i=0;$i<@{$Values[0]};$i++) {
8284: push (@Labels,$i+1);
8285: }
8286: }
8287: #
1.129 matthew 8288: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8289: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8290: my %ValuesHash;
8291: my $NumSets=1;
8292: foreach my $array (@Values) {
8293: next if (! ref($array));
1.136 matthew 8294: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8295: join(',',@$array);
1.129 matthew 8296: }
1.127 matthew 8297: #
1.136 matthew 8298: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8299: if ($NumBars < 3) {
8300: $width = 120+$NumBars*32;
1.220 matthew 8301: $xskip = 1;
1.225 matthew 8302: $bar_width = 30;
8303: } elsif ($NumBars < 5) {
8304: $width = 120+$NumBars*20;
8305: $xskip = 1;
8306: $bar_width = 20;
1.220 matthew 8307: } elsif ($NumBars < 10) {
1.136 matthew 8308: $width = 120+$NumBars*15;
8309: $xskip = 1;
8310: $bar_width = 15;
8311: } elsif ($NumBars <= 25) {
8312: $width = 120+$NumBars*11;
8313: $xskip = 5;
8314: $bar_width = 8;
8315: } elsif ($NumBars <= 50) {
8316: $width = 120+$NumBars*8;
8317: $xskip = 5;
8318: $bar_width = 4;
8319: } else {
8320: $width = 120+$NumBars*8;
8321: $xskip = 5;
8322: $bar_width = 4;
8323: }
8324: #
1.137 matthew 8325: $Max = 1 if ($Max < 1);
8326: if ( int($Max) < $Max ) {
8327: $Max++;
8328: $Max = int($Max);
8329: }
1.127 matthew 8330: $Title = '' if (! defined($Title));
8331: $xlabel = '' if (! defined($xlabel));
8332: $ylabel = '' if (! defined($ylabel));
1.369 www 8333: $ValuesHash{$id.'.title'} = &escape($Title);
8334: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8335: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8336: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8337: $ValuesHash{$id.'.NumBars'} = $NumBars;
8338: $ValuesHash{$id.'.NumSets'} = $NumSets;
8339: $ValuesHash{$id.'.PlotType'} = 'bar';
8340: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8341: $ValuesHash{$id.'.height'} = $height;
8342: $ValuesHash{$id.'.width'} = $width;
8343: $ValuesHash{$id.'.xskip'} = $xskip;
8344: $ValuesHash{$id.'.bar_width'} = $bar_width;
8345: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8346: #
1.228 matthew 8347: # Deal with other parameters
8348: while (my ($key,$value) = each(%$extra_settings)) {
8349: $ValuesHash{$id.'.'.$key} = $value;
8350: }
8351: #
1.646 raeburn 8352: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8353: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8354: }
8355:
8356: ############################################################
8357: ############################################################
8358:
8359: =pod
8360:
1.648 raeburn 8361: =item * &DrawXYGraph()
1.137 matthew 8362:
1.138 matthew 8363: Facilitates the plotting of data in an XY graph.
8364: Puts plot definition data into the users environment in order for
8365: graph.png to plot it. Returns an <img> tag for the plot.
8366:
8367: Inputs:
8368:
8369: =over 4
8370:
8371: =item $Title: string, the title of the plot
8372:
8373: =item $xlabel: string, text describing the X-axis of the plot
8374:
8375: =item $ylabel: string, text describing the Y-axis of the plot
8376:
8377: =item $Max: scalar, the maximum Y value to use in the plot
8378: If $Max is < any data point, the graph will not be rendered.
8379:
8380: =item $colors: Array ref containing the hex color codes for the data to be
8381: plotted in. If undefined, default values will be used.
8382:
8383: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8384:
8385: =item $Ydata: Array ref containing Array refs.
1.185 www 8386: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8387:
8388: =item %Values: hash indicating or overriding any default values which are
8389: passed to graph.png.
8390: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8391:
8392: =back
8393:
8394: Returns:
8395:
8396: An <img> tag which references graph.png and the appropriate identifying
8397: information for the plot.
8398:
1.137 matthew 8399: =cut
8400:
8401: ############################################################
8402: ############################################################
8403: sub DrawXYGraph {
8404: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8405: #
8406: # Create the identifier for the graph
8407: my $identifier = &get_cgi_id();
8408: my $id = 'cgi.'.$identifier;
8409: #
8410: $Title = '' if (! defined($Title));
8411: $xlabel = '' if (! defined($xlabel));
8412: $ylabel = '' if (! defined($ylabel));
8413: my %ValuesHash =
8414: (
1.369 www 8415: $id.'.title' => &escape($Title),
8416: $id.'.xlabel' => &escape($xlabel),
8417: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8418: $id.'.y_max_value'=> $Max,
8419: $id.'.labels' => join(',',@$Xlabels),
8420: $id.'.PlotType' => 'XY',
8421: );
8422: #
8423: if (defined($colors) && ref($colors) eq 'ARRAY') {
8424: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8425: }
8426: #
8427: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8428: return '';
8429: }
8430: my $NumSets=1;
1.138 matthew 8431: foreach my $array (@{$Ydata}){
1.137 matthew 8432: next if (! ref($array));
8433: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8434: }
1.138 matthew 8435: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8436: #
8437: # Deal with other parameters
8438: while (my ($key,$value) = each(%Values)) {
8439: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8440: }
8441: #
1.646 raeburn 8442: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8443: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8444: }
8445:
8446: ############################################################
8447: ############################################################
8448:
8449: =pod
8450:
1.648 raeburn 8451: =item * &DrawXYYGraph()
1.138 matthew 8452:
8453: Facilitates the plotting of data in an XY graph with two Y axes.
8454: Puts plot definition data into the users environment in order for
8455: graph.png to plot it. Returns an <img> tag for the plot.
8456:
8457: Inputs:
8458:
8459: =over 4
8460:
8461: =item $Title: string, the title of the plot
8462:
8463: =item $xlabel: string, text describing the X-axis of the plot
8464:
8465: =item $ylabel: string, text describing the Y-axis of the plot
8466:
8467: =item $colors: Array ref containing the hex color codes for the data to be
8468: plotted in. If undefined, default values will be used.
8469:
8470: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8471:
8472: =item $Ydata1: The first data set
8473:
8474: =item $Min1: The minimum value of the left Y-axis
8475:
8476: =item $Max1: The maximum value of the left Y-axis
8477:
8478: =item $Ydata2: The second data set
8479:
8480: =item $Min2: The minimum value of the right Y-axis
8481:
8482: =item $Max2: The maximum value of the left Y-axis
8483:
8484: =item %Values: hash indicating or overriding any default values which are
8485: passed to graph.png.
8486: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8487:
8488: =back
8489:
8490: Returns:
8491:
8492: An <img> tag which references graph.png and the appropriate identifying
8493: information for the plot.
1.136 matthew 8494:
8495: =cut
8496:
8497: ############################################################
8498: ############################################################
1.137 matthew 8499: sub DrawXYYGraph {
8500: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8501: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8502: #
8503: # Create the identifier for the graph
8504: my $identifier = &get_cgi_id();
8505: my $id = 'cgi.'.$identifier;
8506: #
8507: $Title = '' if (! defined($Title));
8508: $xlabel = '' if (! defined($xlabel));
8509: $ylabel = '' if (! defined($ylabel));
8510: my %ValuesHash =
8511: (
1.369 www 8512: $id.'.title' => &escape($Title),
8513: $id.'.xlabel' => &escape($xlabel),
8514: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8515: $id.'.labels' => join(',',@$Xlabels),
8516: $id.'.PlotType' => 'XY',
8517: $id.'.NumSets' => 2,
1.137 matthew 8518: $id.'.two_axes' => 1,
8519: $id.'.y1_max_value' => $Max1,
8520: $id.'.y1_min_value' => $Min1,
8521: $id.'.y2_max_value' => $Max2,
8522: $id.'.y2_min_value' => $Min2,
1.136 matthew 8523: );
8524: #
1.137 matthew 8525: if (defined($colors) && ref($colors) eq 'ARRAY') {
8526: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8527: }
8528: #
8529: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8530: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8531: return '';
8532: }
8533: my $NumSets=1;
1.137 matthew 8534: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8535: next if (! ref($array));
8536: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8537: }
8538: #
8539: # Deal with other parameters
8540: while (my ($key,$value) = each(%Values)) {
8541: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8542: }
8543: #
1.646 raeburn 8544: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8545: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8546: }
8547:
8548: ############################################################
8549: ############################################################
8550:
8551: =pod
8552:
1.157 matthew 8553: =back
8554:
1.139 matthew 8555: =head1 Statistics helper routines?
8556:
8557: Bad place for them but what the hell.
8558:
1.157 matthew 8559: =over 4
8560:
1.648 raeburn 8561: =item * &chartlink()
1.139 matthew 8562:
8563: Returns a link to the chart for a specific student.
8564:
8565: Inputs:
8566:
8567: =over 4
8568:
8569: =item $linktext: The text of the link
8570:
8571: =item $sname: The students username
8572:
8573: =item $sdomain: The students domain
8574:
8575: =back
8576:
1.157 matthew 8577: =back
8578:
1.139 matthew 8579: =cut
8580:
8581: ############################################################
8582: ############################################################
8583: sub chartlink {
8584: my ($linktext, $sname, $sdomain) = @_;
8585: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8586: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8587: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8588: '">'.$linktext.'</a>';
1.153 matthew 8589: }
8590:
8591: #######################################################
8592: #######################################################
8593:
8594: =pod
8595:
8596: =head1 Course Environment Routines
1.157 matthew 8597:
8598: =over 4
1.153 matthew 8599:
1.648 raeburn 8600: =item * &restore_course_settings()
1.153 matthew 8601:
1.648 raeburn 8602: =item * &store_course_settings()
1.153 matthew 8603:
8604: Restores/Store indicated form parameters from the course environment.
8605: Will not overwrite existing values of the form parameters.
8606:
8607: Inputs:
8608: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8609:
8610: a hash ref describing the data to be stored. For example:
8611:
8612: %Save_Parameters = ('Status' => 'scalar',
8613: 'chartoutputmode' => 'scalar',
8614: 'chartoutputdata' => 'scalar',
8615: 'Section' => 'array',
1.373 raeburn 8616: 'Group' => 'array',
1.153 matthew 8617: 'StudentData' => 'array',
8618: 'Maps' => 'array');
8619:
8620: Returns: both routines return nothing
8621:
1.631 raeburn 8622: =back
8623:
1.153 matthew 8624: =cut
8625:
8626: #######################################################
8627: #######################################################
8628: sub store_course_settings {
1.496 albertel 8629: return &store_settings($env{'request.course.id'},@_);
8630: }
8631:
8632: sub store_settings {
1.153 matthew 8633: # save to the environment
8634: # appenv the same items, just to be safe
1.300 albertel 8635: my $udom = $env{'user.domain'};
8636: my $uname = $env{'user.name'};
1.496 albertel 8637: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8638: my %SaveHash;
8639: my %AppHash;
8640: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8641: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8642: my $envname = 'environment.'.$basename;
1.258 albertel 8643: if (exists($env{'form.'.$setting})) {
1.153 matthew 8644: # Save this value away
8645: if ($type eq 'scalar' &&
1.258 albertel 8646: (! exists($env{$envname}) ||
8647: $env{$envname} ne $env{'form.'.$setting})) {
8648: $SaveHash{$basename} = $env{'form.'.$setting};
8649: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8650: } elsif ($type eq 'array') {
8651: my $stored_form;
1.258 albertel 8652: if (ref($env{'form.'.$setting})) {
1.153 matthew 8653: $stored_form = join(',',
8654: map {
1.369 www 8655: &escape($_);
1.258 albertel 8656: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8657: } else {
8658: $stored_form =
1.369 www 8659: &escape($env{'form.'.$setting});
1.153 matthew 8660: }
8661: # Determine if the array contents are the same.
1.258 albertel 8662: if ($stored_form ne $env{$envname}) {
1.153 matthew 8663: $SaveHash{$basename} = $stored_form;
8664: $AppHash{$envname} = $stored_form;
8665: }
8666: }
8667: }
8668: }
8669: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8670: $udom,$uname);
1.153 matthew 8671: if ($put_result !~ /^(ok|delayed)/) {
8672: &Apache::lonnet::logthis('unable to save form parameters, '.
8673: 'got error:'.$put_result);
8674: }
8675: # Make sure these settings stick around in this session, too
1.646 raeburn 8676: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8677: return;
8678: }
8679:
8680: sub restore_course_settings {
1.499 albertel 8681: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8682: }
8683:
8684: sub restore_settings {
8685: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8686: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8687: next if (exists($env{'form.'.$setting}));
1.496 albertel 8688: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8689: '.'.$setting;
1.258 albertel 8690: if (exists($env{$envname})) {
1.153 matthew 8691: if ($type eq 'scalar') {
1.258 albertel 8692: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8693: } elsif ($type eq 'array') {
1.258 albertel 8694: $env{'form.'.$setting} = [
1.153 matthew 8695: map {
1.369 www 8696: &unescape($_);
1.258 albertel 8697: } split(',',$env{$envname})
1.153 matthew 8698: ];
8699: }
8700: }
8701: }
1.127 matthew 8702: }
8703:
1.618 raeburn 8704: #######################################################
8705: #######################################################
8706:
8707: =pod
8708:
8709: =head1 Domain E-mail Routines
8710:
8711: =over 4
8712:
1.648 raeburn 8713: =item * &build_recipient_list()
1.618 raeburn 8714:
8715: Build recipient lists for three types of e-mail:
8716: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8717: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8718:
8719: Inputs:
1.619 raeburn 8720: defmail (scalar - email address of default recipient),
1.618 raeburn 8721: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8722: defdom (domain for which to retrieve configuration settings),
8723: origmail (scalar - email address of recipient from loncapa.conf,
8724: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8725:
1.655 raeburn 8726: Returns: comma separated list of addresses to which to send e-mail.
8727:
8728: =back
1.618 raeburn 8729:
8730: =cut
8731:
8732: ############################################################
8733: ############################################################
8734: sub build_recipient_list {
1.619 raeburn 8735: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8736: my @recipients;
8737: my $otheremails;
8738: my %domconfig =
8739: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8740: if (ref($domconfig{'contacts'}) eq 'HASH') {
8741: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8742: my @contacts = ('adminemail','supportemail');
8743: foreach my $item (@contacts) {
8744: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8745: my $addr = $domconfig{'contacts'}{$item};
8746: if (!grep(/^\Q$addr\E$/,@recipients)) {
8747: push(@recipients,$addr);
8748: }
1.618 raeburn 8749: }
8750: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8751: }
8752: }
1.619 raeburn 8753: } elsif ($origmail ne '') {
8754: push(@recipients,$origmail);
1.618 raeburn 8755: }
1.688 raeburn 8756: if (defined($defmail)) {
8757: if ($defmail ne '') {
8758: push(@recipients,$defmail);
8759: }
1.618 raeburn 8760: }
8761: if ($otheremails) {
1.619 raeburn 8762: my @others;
8763: if ($otheremails =~ /,/) {
8764: @others = split(/,/,$otheremails);
1.618 raeburn 8765: } else {
1.619 raeburn 8766: push(@others,$otheremails);
8767: }
8768: foreach my $addr (@others) {
8769: if (!grep(/^\Q$addr\E$/,@recipients)) {
8770: push(@recipients,$addr);
8771: }
1.618 raeburn 8772: }
8773: }
1.619 raeburn 8774: my $recipientlist = join(',',@recipients);
1.618 raeburn 8775: return $recipientlist;
8776: }
8777:
1.127 matthew 8778: ############################################################
8779: ############################################################
1.154 albertel 8780:
1.655 raeburn 8781: =pod
8782:
8783: =head1 Course Catalog Routines
8784:
8785: =over 4
8786:
8787: =item * &gather_categories()
8788:
8789: Converts category definitions - keys of categories hash stored in
8790: coursecategories in configuration.db on the primary library server in a
8791: domain - to an array. Also generates javascript and idx hash used to
8792: generate Domain Coordinator interface for editing Course Categories.
8793:
8794: Inputs:
1.663 raeburn 8795:
1.655 raeburn 8796: categories (reference to hash of category definitions).
1.663 raeburn 8797:
1.655 raeburn 8798: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8799: categories and subcategories).
1.663 raeburn 8800:
1.655 raeburn 8801: idx (reference to hash of counters used in Domain Coordinator interface for
8802: editing Course Categories).
1.663 raeburn 8803:
1.655 raeburn 8804: jsarray (reference to array of categories used to create Javascript arrays for
8805: Domain Coordinator interface for editing Course Categories).
8806:
8807: Returns: nothing
8808:
8809: Side effects: populates cats, idx and jsarray.
8810:
8811: =cut
8812:
8813: sub gather_categories {
8814: my ($categories,$cats,$idx,$jsarray) = @_;
8815: my %counters;
8816: my $num = 0;
8817: foreach my $item (keys(%{$categories})) {
8818: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8819: if ($container eq '' && $depth == 0) {
8820: $cats->[$depth][$categories->{$item}] = $cat;
8821: } else {
8822: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8823: }
8824: my ($escitem,$tail) = split(/:/,$item,2);
8825: if ($counters{$tail} eq '') {
8826: $counters{$tail} = $num;
8827: $num ++;
8828: }
8829: if (ref($idx) eq 'HASH') {
8830: $idx->{$item} = $counters{$tail};
8831: }
8832: if (ref($jsarray) eq 'ARRAY') {
8833: push(@{$jsarray->[$counters{$tail}]},$item);
8834: }
8835: }
8836: return;
8837: }
8838:
8839: =pod
8840:
8841: =item * &extract_categories()
8842:
8843: Used to generate breadcrumb trails for course categories.
8844:
8845: Inputs:
1.663 raeburn 8846:
1.655 raeburn 8847: categories (reference to hash of category definitions).
1.663 raeburn 8848:
1.655 raeburn 8849: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8850: categories and subcategories).
1.663 raeburn 8851:
1.655 raeburn 8852: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8853:
1.655 raeburn 8854: allitems (reference to hash - key is category key
8855: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8856:
1.655 raeburn 8857: idx (reference to hash of counters used in Domain Coordinator interface for
8858: editing Course Categories).
1.663 raeburn 8859:
1.655 raeburn 8860: jsarray (reference to array of categories used to create Javascript arrays for
8861: Domain Coordinator interface for editing Course Categories).
8862:
1.665 raeburn 8863: subcats (reference to hash of arrays containing all subcategories within each
8864: category, -recursive)
8865:
1.655 raeburn 8866: Returns: nothing
8867:
8868: Side effects: populates trails and allitems hash references.
8869:
8870: =cut
8871:
8872: sub extract_categories {
1.665 raeburn 8873: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8874: if (ref($categories) eq 'HASH') {
8875: &gather_categories($categories,$cats,$idx,$jsarray);
8876: if (ref($cats->[0]) eq 'ARRAY') {
8877: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8878: my $name = $cats->[0][$i];
8879: my $item = &escape($name).'::0';
8880: my $trailstr;
8881: if ($name eq 'instcode') {
8882: $trailstr = &mt('Official courses (with institutional codes)');
8883: } else {
8884: $trailstr = $name;
8885: }
8886: if ($allitems->{$item} eq '') {
8887: push(@{$trails},$trailstr);
8888: $allitems->{$item} = scalar(@{$trails})-1;
8889: }
8890: my @parents = ($name);
8891: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8892: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8893: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8894: if (ref($subcats) eq 'HASH') {
8895: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8896: }
8897: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8898: }
8899: } else {
8900: if (ref($subcats) eq 'HASH') {
8901: $subcats->{$item} = [];
1.655 raeburn 8902: }
8903: }
8904: }
8905: }
8906: }
8907: return;
8908: }
8909:
8910: =pod
8911:
8912: =item *&recurse_categories()
8913:
8914: Recursively used to generate breadcrumb trails for course categories.
8915:
8916: Inputs:
1.663 raeburn 8917:
1.655 raeburn 8918: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8919: categories and subcategories).
1.663 raeburn 8920:
1.655 raeburn 8921: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8922:
8923: category (current course category, for which breadcrumb trail is being generated).
8924:
8925: trails (reference to array of breadcrumb trails for each category).
8926:
1.655 raeburn 8927: allitems (reference to hash - key is category key
8928: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8929:
1.655 raeburn 8930: parents (array containing containers directories for current category,
8931: back to top level).
8932:
8933: Returns: nothing
8934:
8935: Side effects: populates trails and allitems hash references
8936:
8937: =cut
8938:
8939: sub recurse_categories {
1.665 raeburn 8940: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8941: my $shallower = $depth - 1;
8942: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8943: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8944: my $name = $cats->[$depth]{$category}[$k];
8945: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8946: my $trailstr = join(' -> ',(@{$parents},$category));
8947: if ($allitems->{$item} eq '') {
8948: push(@{$trails},$trailstr);
8949: $allitems->{$item} = scalar(@{$trails})-1;
8950: }
8951: my $deeper = $depth+1;
8952: push(@{$parents},$category);
1.665 raeburn 8953: if (ref($subcats) eq 'HASH') {
8954: my $subcat = &escape($name).':'.$category.':'.$depth;
8955: for (my $j=@{$parents}; $j>=0; $j--) {
8956: my $higher;
8957: if ($j > 0) {
8958: $higher = &escape($parents->[$j]).':'.
8959: &escape($parents->[$j-1]).':'.$j;
8960: } else {
8961: $higher = &escape($parents->[$j]).'::'.$j;
8962: }
8963: push(@{$subcats->{$higher}},$subcat);
8964: }
8965: }
8966: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8967: $subcats);
1.655 raeburn 8968: pop(@{$parents});
8969: }
8970: } else {
8971: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8972: my $trailstr = join(' -> ',(@{$parents},$category));
8973: if ($allitems->{$item} eq '') {
8974: push(@{$trails},$trailstr);
8975: $allitems->{$item} = scalar(@{$trails})-1;
8976: }
8977: }
8978: return;
8979: }
8980:
1.663 raeburn 8981: =pod
8982:
8983: =item *&assign_categories_table()
8984:
8985: Create a datatable for display of hierarchical categories in a domain,
8986: with checkboxes to allow a course to be categorized.
8987:
8988: Inputs:
8989:
8990: cathash - reference to hash of categories defined for the domain (from
8991: configuration.db)
8992:
8993: currcat - scalar with an & separated list of categories assigned to a course.
8994:
8995: Returns: $output (markup to be displayed)
8996:
8997: =cut
8998:
8999: sub assign_categories_table {
9000: my ($cathash,$currcat) = @_;
9001: my $output;
9002: if (ref($cathash) eq 'HASH') {
9003: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9004: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9005: $maxdepth = scalar(@cats);
9006: if (@cats > 0) {
9007: my $itemcount = 0;
9008: if (ref($cats[0]) eq 'ARRAY') {
9009: $output = &Apache::loncommon::start_data_table();
9010: my @currcategories;
9011: if ($currcat ne '') {
9012: @currcategories = split('&',$currcat);
9013: }
9014: for (my $i=0; $i<@{$cats[0]}; $i++) {
9015: my $parent = $cats[0][$i];
9016: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9017: next if ($parent eq 'instcode');
9018: my $item = &escape($parent).'::0';
9019: my $checked = '';
9020: if (@currcategories > 0) {
9021: if (grep(/^\Q$item\E$/,@currcategories)) {
9022: $checked = ' checked="checked" ';
9023: }
9024: }
1.675 raeburn 9025: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9026: '<input type="checkbox" name="usecategory" value="'.
9027: $item.'"'.$checked.' />'.$parent.'</span>'.
9028: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9029: my $depth = 1;
9030: push(@path,$parent);
9031: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9032: pop(@path);
9033: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9034: $itemcount ++;
9035: }
9036: $output .= &Apache::loncommon::end_data_table();
9037: }
9038: }
9039: }
9040: return $output;
9041: }
9042:
9043: =pod
9044:
9045: =item *&assign_category_rows()
9046:
9047: Create a datatable row for display of nested categories in a domain,
9048: with checkboxes to allow a course to be categorized,called recursively.
9049:
9050: Inputs:
9051:
9052: itemcount - track row number for alternating colors
9053:
9054: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9055: categories and subcategories.
9056:
9057: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9058:
9059: parent - parent of current category item
9060:
9061: path - Array containing all categories back up through the hierarchy from the
9062: current category to the top level.
9063:
9064: currcategories - reference to array of current categories assigned to the course
9065:
9066: Returns: $output (markup to be displayed).
9067:
9068: =cut
9069:
9070: sub assign_category_rows {
9071: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9072: my ($text,$name,$item,$chgstr);
9073: if (ref($cats) eq 'ARRAY') {
9074: my $maxdepth = scalar(@{$cats});
9075: if (ref($cats->[$depth]) eq 'HASH') {
9076: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9077: my $numchildren = @{$cats->[$depth]{$parent}};
9078: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9079: $text .= '<td><table class="LC_datatable">';
9080: for (my $j=0; $j<$numchildren; $j++) {
9081: $name = $cats->[$depth]{$parent}[$j];
9082: $item = &escape($name).':'.&escape($parent).':'.$depth;
9083: my $deeper = $depth+1;
9084: my $checked = '';
9085: if (ref($currcategories) eq 'ARRAY') {
9086: if (@{$currcategories} > 0) {
9087: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9088: $checked = ' checked="checked" ';
9089: }
9090: }
9091: }
1.664 raeburn 9092: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9093: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9094: $item.'"'.$checked.' />'.$name.'</label></span>'.
9095: '<input type="hidden" name="catname" value="'.$name.'" />'.
9096: '</td><td>';
1.663 raeburn 9097: if (ref($path) eq 'ARRAY') {
9098: push(@{$path},$name);
9099: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9100: pop(@{$path});
9101: }
9102: $text .= '</td></tr>';
9103: }
9104: $text .= '</table></td>';
9105: }
9106: }
9107: }
9108: return $text;
9109: }
9110:
1.655 raeburn 9111: ############################################################
9112: ############################################################
9113:
9114:
1.443 albertel 9115: sub commit_customrole {
1.664 raeburn 9116: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9117: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9118: ($start?', '.&mt('starting').' '.localtime($start):'').
9119: ($end?', ending '.localtime($end):'').': <b>'.
9120: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9121: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9122: '</b><br />';
9123: return $output;
9124: }
9125:
9126: sub commit_standardrole {
1.541 raeburn 9127: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9128: my ($output,$logmsg,$linefeed);
9129: if ($context eq 'auto') {
9130: $linefeed = "\n";
9131: } else {
9132: $linefeed = "<br />\n";
9133: }
1.443 albertel 9134: if ($three eq 'st') {
1.541 raeburn 9135: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9136: $one,$two,$sec,$context);
9137: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9138: ($result eq 'unknown_course') || ($result eq 'refused')) {
9139: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9140: } else {
1.541 raeburn 9141: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9142: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9143: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9144: if ($context eq 'auto') {
9145: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9146: } else {
9147: $output .= '<b>'.$result.'</b>'.$linefeed.
9148: &mt('Add to classlist').': <b>ok</b>';
9149: }
9150: $output .= $linefeed;
1.443 albertel 9151: }
9152: } else {
9153: $output = &mt('Assigning').' '.$three.' in '.$url.
9154: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9155: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9156: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9157: if ($context eq 'auto') {
9158: $output .= $result.$linefeed;
9159: } else {
9160: $output .= '<b>'.$result.'</b>'.$linefeed;
9161: }
1.443 albertel 9162: }
9163: return $output;
9164: }
9165:
9166: sub commit_studentrole {
1.541 raeburn 9167: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9168: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9169: if ($context eq 'auto') {
9170: $linefeed = "\n";
9171: } else {
9172: $linefeed = '<br />'."\n";
9173: }
1.443 albertel 9174: if (defined($one) && defined($two)) {
9175: my $cid=$one.'_'.$two;
9176: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9177: my $secchange = 0;
9178: my $expire_role_result;
9179: my $modify_section_result;
1.628 raeburn 9180: if ($oldsec ne '-1') {
9181: if ($oldsec ne $sec) {
1.443 albertel 9182: $secchange = 1;
1.628 raeburn 9183: my $now = time;
1.443 albertel 9184: my $uurl='/'.$cid;
9185: $uurl=~s/\_/\//g;
9186: if ($oldsec) {
9187: $uurl.='/'.$oldsec;
9188: }
1.626 raeburn 9189: $oldsecurl = $uurl;
1.628 raeburn 9190: $expire_role_result =
1.652 raeburn 9191: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9192: if ($env{'request.course.sec'} ne '') {
9193: if ($expire_role_result eq 'refused') {
9194: my @roles = ('st');
9195: my @statuses = ('previous');
9196: my @roledoms = ($one);
9197: my $withsec = 1;
9198: my %roleshash =
9199: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9200: \@statuses,\@roles,\@roledoms,$withsec);
9201: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9202: my ($oldstart,$oldend) =
9203: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9204: if ($oldend > 0 && $oldend <= $now) {
9205: $expire_role_result = 'ok';
9206: }
9207: }
9208: }
9209: }
1.443 albertel 9210: $result = $expire_role_result;
9211: }
9212: }
9213: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9214: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9215: if ($modify_section_result =~ /^ok/) {
9216: if ($secchange == 1) {
1.628 raeburn 9217: if ($sec eq '') {
9218: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9219: } else {
9220: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9221: }
1.443 albertel 9222: } elsif ($oldsec eq '-1') {
1.628 raeburn 9223: if ($sec eq '') {
9224: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9225: } else {
9226: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9227: }
1.443 albertel 9228: } else {
1.628 raeburn 9229: if ($sec eq '') {
9230: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9231: } else {
9232: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9233: }
1.443 albertel 9234: }
9235: } else {
1.628 raeburn 9236: if ($secchange) {
9237: $$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;
9238: } else {
9239: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9240: }
1.443 albertel 9241: }
9242: $result = $modify_section_result;
9243: } elsif ($secchange == 1) {
1.628 raeburn 9244: if ($oldsec eq '') {
9245: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9246: } else {
9247: $$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;
9248: }
1.626 raeburn 9249: if ($expire_role_result eq 'refused') {
9250: my $newsecurl = '/'.$cid;
9251: $newsecurl =~ s/\_/\//g;
9252: if ($sec ne '') {
9253: $newsecurl.='/'.$sec;
9254: }
9255: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9256: if ($sec eq '') {
9257: $$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;
9258: } else {
9259: $$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;
9260: }
9261: }
9262: }
1.443 albertel 9263: }
9264: } else {
1.626 raeburn 9265: $$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 9266: $result = "error: incomplete course id\n";
9267: }
9268: return $result;
9269: }
9270:
9271: ############################################################
9272: ############################################################
9273:
1.566 albertel 9274: sub check_clone {
1.578 raeburn 9275: my ($args,$linefeed) = @_;
1.566 albertel 9276: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9277: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9278: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9279: my $clonemsg;
9280: my $can_clone = 0;
9281:
9282: if ($clonehome eq 'no_host') {
1.578 raeburn 9283: $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 9284: } else {
9285: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9286: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9287: $can_clone = 1;
9288: } else {
9289: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9290: $args->{'clonedomain'},$args->{'clonecourse'});
9291: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9292: if (grep(/^\*$/,@cloners)) {
9293: $can_clone = 1;
9294: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9295: $can_clone = 1;
9296: } else {
9297: my %roleshash =
9298: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9299: $args->{'ccdomain'},
9300: 'userroles',['active'],['cc'],
9301: [$args->{'clonedomain'}]);
9302: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9303: $can_clone = 1;
9304: } else {
9305: $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'});
9306: }
1.566 albertel 9307: }
1.578 raeburn 9308: }
1.566 albertel 9309: }
9310: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9311: }
9312:
1.444 albertel 9313: sub construct_course {
1.541 raeburn 9314: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9315: my $outcome;
1.541 raeburn 9316: my $linefeed = '<br />'."\n";
9317: if ($context eq 'auto') {
9318: $linefeed = "\n";
9319: }
1.566 albertel 9320:
9321: #
9322: # Are we cloning?
9323: #
9324: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9325: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9326: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9327: if ($context ne 'auto') {
1.578 raeburn 9328: if ($clonemsg ne '') {
9329: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9330: }
1.566 albertel 9331: }
9332: $outcome .= $clonemsg.$linefeed;
9333:
9334: if (!$can_clone) {
9335: return (0,$outcome);
9336: }
9337: }
9338:
1.444 albertel 9339: #
9340: # Open course
9341: #
9342: my $crstype = lc($args->{'crstype'});
9343: my %cenv=();
9344: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9345: $args->{'cdescr'},
9346: $args->{'curl'},
9347: $args->{'course_home'},
9348: $args->{'nonstandard'},
9349: $args->{'crscode'},
9350: $args->{'ccuname'}.':'.
9351: $args->{'ccdomain'},
9352: $args->{'crstype'});
9353:
9354: # Note: The testing routines depend on this being output; see
9355: # Utils::Course. This needs to at least be output as a comment
9356: # if anyone ever decides to not show this, and Utils::Course::new
9357: # will need to be suitably modified.
1.541 raeburn 9358: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9359: #
9360: # Check if created correctly
9361: #
1.479 albertel 9362: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9363: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9364: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9365:
1.444 albertel 9366: #
1.566 albertel 9367: # Do the cloning
9368: #
9369: if ($can_clone && $cloneid) {
9370: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9371: if ($context ne 'auto') {
9372: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9373: }
9374: $outcome .= $clonemsg.$linefeed;
9375: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9376: # Copy all files
1.637 www 9377: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9378: # Restore URL
1.566 albertel 9379: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9380: # Restore title
1.566 albertel 9381: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9382: # Mark as cloned
1.566 albertel 9383: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9384: # Need to clone grading mode
9385: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9386: $cenv{'grading'}=$newenv{'grading'};
9387: # Do not clone these environment entries
9388: &Apache::lonnet::del('environment',
9389: ['default_enrollment_start_date',
9390: 'default_enrollment_end_date',
9391: 'question.email',
9392: 'policy.email',
9393: 'comment.email',
9394: 'pch.users.denied',
1.725 raeburn 9395: 'plc.users.denied',
9396: 'hidefromcat',
9397: 'categories'],
1.638 www 9398: $$crsudom,$$crsunum);
1.444 albertel 9399: }
1.566 albertel 9400:
1.444 albertel 9401: #
9402: # Set environment (will override cloned, if existing)
9403: #
9404: my @sections = ();
9405: my @xlists = ();
9406: if ($args->{'crstype'}) {
9407: $cenv{'type'}=$args->{'crstype'};
9408: }
9409: if ($args->{'crsid'}) {
9410: $cenv{'courseid'}=$args->{'crsid'};
9411: }
9412: if ($args->{'crscode'}) {
9413: $cenv{'internal.coursecode'}=$args->{'crscode'};
9414: }
9415: if ($args->{'crsquota'} ne '') {
9416: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9417: } else {
9418: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9419: }
9420: if ($args->{'ccuname'}) {
9421: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9422: ':'.$args->{'ccdomain'};
9423: } else {
9424: $cenv{'internal.courseowner'} = $args->{'curruser'};
9425: }
9426: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9427: if ($args->{'crssections'}) {
9428: $cenv{'internal.sectionnums'} = '';
9429: if ($args->{'crssections'} =~ m/,/) {
9430: @sections = split/,/,$args->{'crssections'};
9431: } else {
9432: $sections[0] = $args->{'crssections'};
9433: }
9434: if (@sections > 0) {
9435: foreach my $item (@sections) {
9436: my ($sec,$gp) = split/:/,$item;
9437: my $class = $args->{'crscode'}.$sec;
9438: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9439: $cenv{'internal.sectionnums'} .= $item.',';
9440: unless ($addcheck eq 'ok') {
9441: push @badclasses, $class;
9442: }
9443: }
9444: $cenv{'internal.sectionnums'} =~ s/,$//;
9445: }
9446: }
9447: # do not hide course coordinator from staff listing,
9448: # even if privileged
9449: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9450: # add crosslistings
9451: if ($args->{'crsxlist'}) {
9452: $cenv{'internal.crosslistings'}='';
9453: if ($args->{'crsxlist'} =~ m/,/) {
9454: @xlists = split/,/,$args->{'crsxlist'};
9455: } else {
9456: $xlists[0] = $args->{'crsxlist'};
9457: }
9458: if (@xlists > 0) {
9459: foreach my $item (@xlists) {
9460: my ($xl,$gp) = split/:/,$item;
9461: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9462: $cenv{'internal.crosslistings'} .= $item.',';
9463: unless ($addcheck eq 'ok') {
9464: push @badclasses, $xl;
9465: }
9466: }
9467: $cenv{'internal.crosslistings'} =~ s/,$//;
9468: }
9469: }
9470: if ($args->{'autoadds'}) {
9471: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9472: }
9473: if ($args->{'autodrops'}) {
9474: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9475: }
9476: # check for notification of enrollment changes
9477: my @notified = ();
9478: if ($args->{'notify_owner'}) {
9479: if ($args->{'ccuname'} ne '') {
9480: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9481: }
9482: }
9483: if ($args->{'notify_dc'}) {
9484: if ($uname ne '') {
1.630 raeburn 9485: push(@notified,$uname.':'.$udom);
1.444 albertel 9486: }
9487: }
9488: if (@notified > 0) {
9489: my $notifylist;
9490: if (@notified > 1) {
9491: $notifylist = join(',',@notified);
9492: } else {
9493: $notifylist = $notified[0];
9494: }
9495: $cenv{'internal.notifylist'} = $notifylist;
9496: }
9497: if (@badclasses > 0) {
9498: my %lt=&Apache::lonlocal::texthash(
9499: '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',
9500: 'dnhr' => 'does not have rights to access enrollment in these classes',
9501: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9502: );
1.541 raeburn 9503: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9504: ' ('.$lt{'adby'}.')';
9505: if ($context eq 'auto') {
9506: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9507: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9508: foreach my $item (@badclasses) {
9509: if ($context eq 'auto') {
9510: $outcome .= " - $item\n";
9511: } else {
9512: $outcome .= "<li>$item</li>\n";
9513: }
9514: }
9515: if ($context eq 'auto') {
9516: $outcome .= $linefeed;
9517: } else {
1.566 albertel 9518: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9519: }
9520: }
1.444 albertel 9521: }
9522: if ($args->{'no_end_date'}) {
9523: $args->{'endaccess'} = 0;
9524: }
9525: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9526: $cenv{'internal.autoend'}=$args->{'enrollend'};
9527: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9528: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9529: if ($args->{'showphotos'}) {
9530: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9531: }
9532: $cenv{'internal.authtype'} = $args->{'authtype'};
9533: $cenv{'internal.autharg'} = $args->{'autharg'};
9534: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9535: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9536: 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');
9537: if ($context eq 'auto') {
9538: $outcome .= $krb_msg;
9539: } else {
1.566 albertel 9540: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9541: }
9542: $outcome .= $linefeed;
1.444 albertel 9543: }
9544: }
9545: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9546: if ($args->{'setpolicy'}) {
9547: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9548: }
9549: if ($args->{'setcontent'}) {
9550: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9551: }
9552: }
9553: if ($args->{'reshome'}) {
9554: $cenv{'reshome'}=$args->{'reshome'}.'/';
9555: $cenv{'reshome'}=~s/\/+$/\//;
9556: }
9557: #
9558: # course has keyed access
9559: #
9560: if ($args->{'setkeys'}) {
9561: $cenv{'keyaccess'}='yes';
9562: }
9563: # if specified, key authority is not course, but user
9564: # only active if keyaccess is yes
9565: if ($args->{'keyauth'}) {
1.487 albertel 9566: my ($user,$domain) = split(':',$args->{'keyauth'});
9567: $user = &LONCAPA::clean_username($user);
9568: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9569: if ($user ne '' && $domain ne '') {
1.487 albertel 9570: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9571: }
9572: }
9573:
9574: if ($args->{'disresdis'}) {
9575: $cenv{'pch.roles.denied'}='st';
9576: }
9577: if ($args->{'disablechat'}) {
9578: $cenv{'plc.roles.denied'}='st';
9579: }
9580:
9581: # Record we've not yet viewed the Course Initialization Helper for this
9582: # course
9583: $cenv{'course.helper.not.run'} = 1;
9584: #
9585: # Use new Randomseed
9586: #
9587: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9588: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9589: #
9590: # The encryption code and receipt prefix for this course
9591: #
9592: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9593: $cenv{'internal.encpref'}=100+int(9*rand(99));
9594: #
9595: # By default, use standard grading
9596: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9597:
1.541 raeburn 9598: $outcome .= $linefeed.&mt('Setting environment').': '.
9599: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9600: #
9601: # Open all assignments
9602: #
9603: if ($args->{'openall'}) {
9604: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9605: my %storecontent = ($storeunder => time,
9606: $storeunder.'.type' => 'date_start');
9607:
9608: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9609: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9610: }
9611: #
9612: # Set first page
9613: #
9614: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9615: || ($cloneid)) {
1.445 albertel 9616: use LONCAPA::map;
1.444 albertel 9617: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9618:
9619: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9620: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9621:
1.444 albertel 9622: $outcome .= ($fatal?$errtext:'read ok').' - ';
9623: my $title; my $url;
9624: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9625: $title=&mt('Syllabus');
1.444 albertel 9626: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9627: } else {
1.690 bisitz 9628: $title=&mt('Navigate Contents');
1.444 albertel 9629: $url='/adm/navmaps';
9630: }
1.445 albertel 9631:
9632: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9633: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9634:
9635: if ($errtext) { $fatal=2; }
1.541 raeburn 9636: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9637: }
1.566 albertel 9638:
9639: return (1,$outcome);
1.444 albertel 9640: }
9641:
9642: ############################################################
9643: ############################################################
9644:
1.378 raeburn 9645: sub course_type {
9646: my ($cid) = @_;
9647: if (!defined($cid)) {
9648: $cid = $env{'request.course.id'};
9649: }
1.404 albertel 9650: if (defined($env{'course.'.$cid.'.type'})) {
9651: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9652: } else {
9653: return 'Course';
1.377 raeburn 9654: }
9655: }
1.156 albertel 9656:
1.406 raeburn 9657: sub group_term {
9658: my $crstype = &course_type();
9659: my %names = (
9660: 'Course' => 'group',
9661: 'Group' => 'team',
9662: );
9663: return $names{$crstype};
9664: }
9665:
1.156 albertel 9666: sub icon {
9667: my ($file)=@_;
1.505 albertel 9668: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9669: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9670: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9671: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9672: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9673: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9674: $curfext.".gif") {
9675: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9676: $curfext.".gif";
9677: }
9678: }
1.249 albertel 9679: return &lonhttpdurl($iconname);
1.154 albertel 9680: }
1.84 albertel 9681:
1.575 albertel 9682: sub lonhttpdurl {
1.692 www 9683: #
9684: # Had been used for "small fry" static images on separate port 8080.
9685: # Modify here if lightweight http functionality desired again.
9686: # Currently eliminated due to increasing firewall issues.
9687: #
1.575 albertel 9688: my ($url)=@_;
1.692 www 9689: return $url;
1.215 albertel 9690: }
9691:
1.213 albertel 9692: sub connection_aborted {
9693: my ($r)=@_;
9694: $r->print(" ");$r->rflush();
9695: my $c = $r->connection;
9696: return $c->aborted();
9697: }
9698:
1.221 foxr 9699: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9700: # strings as 'strings'.
9701: sub escape_single {
1.221 foxr 9702: my ($input) = @_;
1.223 albertel 9703: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9704: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9705: return $input;
9706: }
1.223 albertel 9707:
1.222 foxr 9708: # Same as escape_single, but escape's "'s This
9709: # can be used for "strings"
9710: sub escape_double {
9711: my ($input) = @_;
9712: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9713: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9714: return $input;
9715: }
1.223 albertel 9716:
1.222 foxr 9717: # Escapes the last element of a full URL.
9718: sub escape_url {
9719: my ($url) = @_;
1.238 raeburn 9720: my @urlslices = split(/\//, $url,-1);
1.369 www 9721: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9722: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9723: }
1.462 albertel 9724:
9725: # -------------------------------------------------------- Initliaze user login
9726: sub init_user_environment {
1.463 albertel 9727: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9728: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9729:
9730: my $public=($username eq 'public' && $domain eq 'public');
9731:
9732: # See if old ID present, if so, remove
9733:
9734: my ($filename,$cookie,$userroles);
9735: my $now=time;
9736:
9737: if ($public) {
9738: my $max_public=100;
9739: my $oldest;
9740: my $oldest_time=0;
9741: for(my $next=1;$next<=$max_public;$next++) {
9742: if (-e $lonids."/publicuser_$next.id") {
9743: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9744: if ($mtime<$oldest_time || !$oldest_time) {
9745: $oldest_time=$mtime;
9746: $oldest=$next;
9747: }
9748: } else {
9749: $cookie="publicuser_$next";
9750: last;
9751: }
9752: }
9753: if (!$cookie) { $cookie="publicuser_$oldest"; }
9754: } else {
1.463 albertel 9755: # if this isn't a robot, kill any existing non-robot sessions
9756: if (!$args->{'robot'}) {
9757: opendir(DIR,$lonids);
9758: while ($filename=readdir(DIR)) {
9759: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9760: unlink($lonids.'/'.$filename);
9761: }
1.462 albertel 9762: }
1.463 albertel 9763: closedir(DIR);
1.462 albertel 9764: }
9765: # Give them a new cookie
1.463 albertel 9766: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9767: : $now.$$.int(rand(10000)));
1.463 albertel 9768: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9769:
9770: # Initialize roles
9771:
9772: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9773: }
9774: # ------------------------------------ Check browser type and MathML capability
9775:
9776: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9777: $clientunicode,$clientos) = &decode_user_agent($r);
9778:
9779: # -------------------------------------- Any accessibility options to remember?
9780: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9781: foreach my $option ('imagesuppress','appletsuppress',
9782: 'embedsuppress','fontenhance','blackwhite') {
9783: if ($form->{$option} eq 'true') {
9784: &Apache::lonnet::put('environment',{$option => 'on'},
9785: $domain,$username);
9786: } else {
9787: &Apache::lonnet::del('environment',[$option],
9788: $domain,$username);
9789: }
9790: }
9791: }
9792: # ------------------------------------------------------------- Get environment
9793:
9794: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9795: my ($tmp) = keys(%userenv);
9796: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9797: # default remote control to off
9798: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9799: } else {
9800: undef(%userenv);
9801: }
9802: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9803: $form->{'interface'}=$userenv{'interface'};
9804: }
9805: $env{'environment.remote'}=$userenv{'remote'};
9806: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9807:
9808: # --------------- Do not trust query string to be put directly into environment
9809: foreach my $option ('imagesuppress','appletsuppress',
9810: 'embedsuppress','fontenhance','blackwhite',
9811: 'interface','localpath','localres') {
9812: $form->{$option}=~s/[\n\r\=]//gs;
9813: }
9814: # --------------------------------------------------------- Write first profile
9815:
9816: {
9817: my %initial_env =
9818: ("user.name" => $username,
9819: "user.domain" => $domain,
9820: "user.home" => $authhost,
9821: "browser.type" => $clientbrowser,
9822: "browser.version" => $clientversion,
9823: "browser.mathml" => $clientmathml,
9824: "browser.unicode" => $clientunicode,
9825: "browser.os" => $clientos,
9826: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9827: "request.course.fn" => '',
9828: "request.course.uri" => '',
9829: "request.course.sec" => '',
9830: "request.role" => 'cm',
9831: "request.role.adv" => $env{'user.adv'},
9832: "request.host" => $ENV{'REMOTE_ADDR'},);
9833:
9834: if ($form->{'localpath'}) {
9835: $initial_env{"browser.localpath"} = $form->{'localpath'};
9836: $initial_env{"browser.localres"} = $form->{'localres'};
9837: }
9838:
9839: if ($public) {
9840: $initial_env{"environment.remote"} = "off";
9841: }
9842: if ($form->{'interface'}) {
9843: $form->{'interface'}=~s/\W//gs;
9844: $initial_env{"browser.interface"} = $form->{'interface'};
9845: $env{'browser.interface'}=$form->{'interface'};
9846: foreach my $option ('imagesuppress','appletsuppress',
9847: 'embedsuppress','fontenhance','blackwhite') {
9848: if (($form->{$option} eq 'true') ||
9849: ($userenv{$option} eq 'on')) {
9850: $initial_env{"browser.$option"} = "on";
9851: }
9852: }
9853: }
9854:
1.724 raeburn 9855: foreach my $tool ('aboutme','blog','portfolio') {
9856: $userenv{'availabletools.'.$tool} =
9857: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9858: }
9859:
1.462 albertel 9860: $env{'user.environment'} = "$lonids/$cookie.id";
9861:
9862: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9863: &GDBM_WRCREAT(),0640)) {
9864: &_add_to_env(\%disk_env,\%initial_env);
9865: &_add_to_env(\%disk_env,\%userenv,'environment.');
9866: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9867: if (ref($args->{'extra_env'})) {
9868: &_add_to_env(\%disk_env,$args->{'extra_env'});
9869: }
1.462 albertel 9870: untie(%disk_env);
9871: } else {
1.705 tempelho 9872: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
9873: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 9874: return 'error: '.$!;
9875: }
9876: }
9877: $env{'request.role'}='cm';
9878: $env{'request.role.adv'}=$env{'user.adv'};
9879: $env{'browser.type'}=$clientbrowser;
9880:
9881: return $cookie;
9882:
9883: }
9884:
9885: sub _add_to_env {
9886: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9887: if (ref($env_data) eq 'HASH') {
9888: while (my ($key,$value) = each(%$env_data)) {
9889: $idf->{$prefix.$key} = $value;
9890: $env{$prefix.$key} = $value;
9891: }
1.462 albertel 9892: }
9893: }
9894:
1.685 tempelho 9895: # --- Get the symbolic name of a problem and the url
9896: sub get_symb {
9897: my ($request,$silent) = @_;
1.726 raeburn 9898: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 9899: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9900: if ($symb eq '') {
9901: if (!$silent) {
9902: $request->print("Unable to handle ambiguous references:$url:.");
9903: return ();
9904: }
9905: }
9906: &Apache::lonenc::check_decrypt(\$symb);
9907: return ($symb);
9908: }
9909:
9910: # --------------------------------------------------------------Get annotation
9911:
9912: sub get_annotation {
9913: my ($symb,$enc) = @_;
9914:
9915: my $key = $symb;
9916: if (!$enc) {
9917: $key =
9918: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9919: }
9920: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9921: return $annotation{$key};
9922: }
9923:
9924: sub clean_symb {
1.731 raeburn 9925: my ($symb,$delete_enc) = @_;
1.685 tempelho 9926:
9927: &Apache::lonenc::check_decrypt(\$symb);
9928: my $enc = $env{'request.enc'};
1.731 raeburn 9929: if ($delete_enc) {
1.730 raeburn 9930: delete($env{'request.enc'});
9931: }
1.685 tempelho 9932:
9933: return ($symb,$enc);
9934: }
1.462 albertel 9935:
1.41 ng 9936: =pod
9937:
9938: =back
9939:
1.112 bowersj2 9940: =cut
1.41 ng 9941:
1.112 bowersj2 9942: 1;
9943: __END__;
1.41 ng 9944:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>