Annotation of loncom/interface/loncommon.pm, revision 1.742
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.742 ! raeburn 4: # $Id: loncommon.pm,v 1.741 2009/02/03 19:36:19 harmsja 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.742 ! raeburn 3076: sub user_lang {
! 3077: my ($touname,$toudom,$fromcid) = @_;
! 3078: my @userlangs;
! 3079: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
! 3080: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
! 3081: $env{'course.'.$fromcid.'.languages'}));
! 3082: } else {
! 3083: my %langhash = &getlangs($touname,$toudom);
! 3084: if ($langhash{'languages'} ne '') {
! 3085: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
! 3086: } else {
! 3087: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
! 3088: if ($domdefs{'lang_def'} ne '') {
! 3089: @userlangs = ($domdefs{'lang_def'});
! 3090: }
! 3091: }
! 3092: }
! 3093: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
! 3094: my $user_lh = Apache::localize->get_handle(@languages);
! 3095: return $user_lh;
! 3096: }
! 3097:
! 3098:
1.112 bowersj2 3099: ###############################################################
3100: ## Student Answer Attempts ##
3101: ###############################################################
3102:
3103: =pod
3104:
3105: =head1 Alternate Problem Views
3106:
3107: =over 4
3108:
1.648 raeburn 3109: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3110: $getattempt, $regexp, $gradesub)
3111:
3112: Return string with previous attempt on problem. Arguments:
3113:
3114: =over 4
3115:
3116: =item * $symb: Problem, including path
3117:
3118: =item * $username: username of the desired student
3119:
3120: =item * $domain: domain of the desired student
1.14 harris41 3121:
1.112 bowersj2 3122: =item * $course: Course ID
1.14 harris41 3123:
1.112 bowersj2 3124: =item * $getattempt: Leave blank for all attempts, otherwise put
3125: something
1.14 harris41 3126:
1.112 bowersj2 3127: =item * $regexp: if string matches this regexp, the string will be
3128: sent to $gradesub
1.14 harris41 3129:
1.112 bowersj2 3130: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3131:
1.112 bowersj2 3132: =back
1.14 harris41 3133:
1.112 bowersj2 3134: The output string is a table containing all desired attempts, if any.
1.16 harris41 3135:
1.112 bowersj2 3136: =cut
1.1 albertel 3137:
3138: sub get_previous_attempt {
1.43 ng 3139: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3140: my $prevattempts='';
1.43 ng 3141: no strict 'refs';
1.1 albertel 3142: if ($symb) {
1.3 albertel 3143: my (%returnhash)=
3144: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3145: if ($returnhash{'version'}) {
3146: my %lasthash=();
3147: my $version;
3148: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3149: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3150: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3151: }
1.1 albertel 3152: }
1.596 albertel 3153: $prevattempts=&start_data_table().&start_data_table_header_row();
3154: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3155: foreach my $key (sort(keys(%lasthash))) {
3156: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3157: if ($#parts > 0) {
1.31 albertel 3158: my $data=$parts[-1];
3159: pop(@parts);
1.596 albertel 3160: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3161: } else {
1.41 ng 3162: if ($#parts == 0) {
3163: $prevattempts.='<th>'.$parts[0].'</th>';
3164: } else {
3165: $prevattempts.='<th>'.$ign.'</th>';
3166: }
1.31 albertel 3167: }
1.16 harris41 3168: }
1.596 albertel 3169: $prevattempts.=&end_data_table_header_row();
1.40 ng 3170: if ($getattempt eq '') {
3171: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3172: $prevattempts.=&start_data_table_row().
3173: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3174: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3175: my $value = &format_previous_attempt_value($key,
3176: $returnhash{$version.':'.$key});
3177: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3178: }
1.596 albertel 3179: $prevattempts.=&end_data_table_row();
1.40 ng 3180: }
1.1 albertel 3181: }
1.596 albertel 3182: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3183: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3184: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3185: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3186: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3187: }
1.596 albertel 3188: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3189: } else {
1.596 albertel 3190: $prevattempts=
3191: &start_data_table().&start_data_table_row().
3192: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3193: &end_data_table_row().&end_data_table();
1.1 albertel 3194: }
3195: } else {
1.596 albertel 3196: $prevattempts=
3197: &start_data_table().&start_data_table_row().
3198: '<td>'.&mt('No data.').'</td>'.
3199: &end_data_table_row().&end_data_table();
1.1 albertel 3200: }
1.10 albertel 3201: }
3202:
1.581 albertel 3203: sub format_previous_attempt_value {
3204: my ($key,$value) = @_;
3205: if ($key =~ /timestamp/) {
3206: $value = &Apache::lonlocal::locallocaltime($value);
3207: } elsif (ref($value) eq 'ARRAY') {
3208: $value = '('.join(', ', @{ $value }).')';
3209: } else {
3210: $value = &unescape($value);
3211: }
3212: return $value;
3213: }
3214:
3215:
1.107 albertel 3216: sub relative_to_absolute {
3217: my ($url,$output)=@_;
3218: my $parser=HTML::TokeParser->new(\$output);
3219: my $token;
3220: my $thisdir=$url;
3221: my @rlinks=();
3222: while ($token=$parser->get_token) {
3223: if ($token->[0] eq 'S') {
3224: if ($token->[1] eq 'a') {
3225: if ($token->[2]->{'href'}) {
3226: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3227: }
3228: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3229: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3230: } elsif ($token->[1] eq 'base') {
3231: $thisdir=$token->[2]->{'href'};
3232: }
3233: }
3234: }
3235: $thisdir=~s-/[^/]*$--;
1.356 albertel 3236: foreach my $link (@rlinks) {
1.726 raeburn 3237: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3238: ($link=~/^\//) ||
3239: ($link=~/^javascript:/i) ||
3240: ($link=~/^mailto:/i) ||
3241: ($link=~/^\#/)) {
3242: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3243: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3244: }
3245: }
3246: # -------------------------------------------------- Deal with Applet codebases
3247: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3248: return $output;
3249: }
3250:
1.112 bowersj2 3251: =pod
3252:
1.648 raeburn 3253: =item * &get_student_view()
1.112 bowersj2 3254:
3255: show a snapshot of what student was looking at
3256:
3257: =cut
3258:
1.10 albertel 3259: sub get_student_view {
1.186 albertel 3260: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3261: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3262: my (%form);
1.10 albertel 3263: my @elements=('symb','courseid','domain','username');
3264: foreach my $element (@elements) {
1.186 albertel 3265: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3266: }
1.186 albertel 3267: if (defined($moreenv)) {
3268: %form=(%form,%{$moreenv});
3269: }
1.236 albertel 3270: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3271: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3272: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3273: $userview=~s/\<body[^\>]*\>//gi;
3274: $userview=~s/\<\/body\>//gi;
3275: $userview=~s/\<html\>//gi;
3276: $userview=~s/\<\/html\>//gi;
3277: $userview=~s/\<head\>//gi;
3278: $userview=~s/\<\/head\>//gi;
3279: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3280: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3281: if (wantarray) {
3282: return ($userview,$response);
3283: } else {
3284: return $userview;
3285: }
3286: }
3287:
3288: sub get_student_view_with_retries {
3289: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3290:
3291: my $ok = 0; # True if we got a good response.
3292: my $content;
3293: my $response;
3294:
3295: # Try to get the student_view done. within the retries count:
3296:
3297: do {
3298: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3299: $ok = $response->is_success;
3300: if (!$ok) {
3301: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3302: }
3303: $retries--;
3304: } while (!$ok && ($retries > 0));
3305:
3306: if (!$ok) {
3307: $content = ''; # On error return an empty content.
3308: }
1.651 www 3309: if (wantarray) {
3310: return ($content, $response);
3311: } else {
3312: return $content;
3313: }
1.11 albertel 3314: }
3315:
1.112 bowersj2 3316: =pod
3317:
1.648 raeburn 3318: =item * &get_student_answers()
1.112 bowersj2 3319:
3320: show a snapshot of how student was answering problem
3321:
3322: =cut
3323:
1.11 albertel 3324: sub get_student_answers {
1.100 sakharuk 3325: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3326: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3327: my (%moreenv);
1.11 albertel 3328: my @elements=('symb','courseid','domain','username');
3329: foreach my $element (@elements) {
1.186 albertel 3330: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3331: }
1.186 albertel 3332: $moreenv{'grade_target'}='answer';
3333: %moreenv=(%form,%moreenv);
1.497 raeburn 3334: $feedurl = &Apache::lonnet::clutter($feedurl);
3335: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3336: return $userview;
1.1 albertel 3337: }
1.116 albertel 3338:
3339: =pod
3340:
3341: =item * &submlink()
3342:
1.242 albertel 3343: Inputs: $text $uname $udom $symb $target
1.116 albertel 3344:
3345: Returns: A link to grades.pm such as to see the SUBM view of a student
3346:
3347: =cut
3348:
3349: ###############################################
3350: sub submlink {
1.242 albertel 3351: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3352: if (!($uname && $udom)) {
3353: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3354: &Apache::lonnet::whichuser($symb);
1.116 albertel 3355: if (!$symb) { $symb=$cursymb; }
3356: }
1.254 matthew 3357: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3358: $symb=&escape($symb);
1.242 albertel 3359: if ($target) { $target="target=\"$target\""; }
3360: return '<a href="/adm/grades?&command=submission&'.
3361: 'symb='.$symb.'&student='.$uname.
3362: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3363: }
3364: ##############################################
3365:
3366: =pod
3367:
3368: =item * &pgrdlink()
3369:
3370: Inputs: $text $uname $udom $symb $target
3371:
3372: Returns: A link to grades.pm such as to see the PGRD view of a student
3373:
3374: =cut
3375:
3376: ###############################################
3377: sub pgrdlink {
3378: my $link=&submlink(@_);
3379: $link=~s/(&command=submission)/$1&showgrading=yes/;
3380: return $link;
3381: }
3382: ##############################################
3383:
3384: =pod
3385:
3386: =item * &pprmlink()
3387:
3388: Inputs: $text $uname $udom $symb $target
3389:
3390: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3391: student and a specific resource
1.242 albertel 3392:
3393: =cut
3394:
3395: ###############################################
3396: sub pprmlink {
3397: my ($text,$uname,$udom,$symb,$target)=@_;
3398: if (!($uname && $udom)) {
3399: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3400: &Apache::lonnet::whichuser($symb);
1.242 albertel 3401: if (!$symb) { $symb=$cursymb; }
3402: }
1.254 matthew 3403: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3404: $symb=&escape($symb);
1.242 albertel 3405: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3406: return '<a href="/adm/parmset?command=set&'.
3407: 'symb='.$symb.'&uname='.$uname.
3408: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3409: }
3410: ##############################################
1.37 matthew 3411:
1.112 bowersj2 3412: =pod
3413:
3414: =back
3415:
3416: =cut
3417:
1.37 matthew 3418: ###############################################
1.51 www 3419:
3420:
3421: sub timehash {
1.687 raeburn 3422: my ($thistime) = @_;
3423: my $timezone = &Apache::lonlocal::gettimezone();
3424: my $dt = DateTime->from_epoch(epoch => $thistime)
3425: ->set_time_zone($timezone);
3426: my $wday = $dt->day_of_week();
3427: if ($wday == 7) { $wday = 0; }
3428: return ( 'second' => $dt->second(),
3429: 'minute' => $dt->minute(),
3430: 'hour' => $dt->hour(),
3431: 'day' => $dt->day_of_month(),
3432: 'month' => $dt->month(),
3433: 'year' => $dt->year(),
3434: 'weekday' => $wday,
3435: 'dayyear' => $dt->day_of_year(),
3436: 'dlsav' => $dt->is_dst() );
1.51 www 3437: }
3438:
1.370 www 3439: sub utc_string {
3440: my ($date)=@_;
1.371 www 3441: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3442: }
3443:
1.51 www 3444: sub maketime {
3445: my %th=@_;
1.687 raeburn 3446: my ($epoch_time,$timezone,$dt);
3447: $timezone = &Apache::lonlocal::gettimezone();
3448: eval {
3449: $dt = DateTime->new( year => $th{'year'},
3450: month => $th{'month'},
3451: day => $th{'day'},
3452: hour => $th{'hour'},
3453: minute => $th{'minute'},
3454: second => $th{'second'},
3455: time_zone => $timezone,
3456: );
3457: };
3458: if (!$@) {
3459: $epoch_time = $dt->epoch;
3460: if ($epoch_time) {
3461: return $epoch_time;
3462: }
3463: }
1.51 www 3464: return POSIX::mktime(
3465: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3466: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3467: }
3468:
3469: #########################################
1.51 www 3470:
3471: sub findallcourses {
1.482 raeburn 3472: my ($roles,$uname,$udom) = @_;
1.355 albertel 3473: my %roles;
3474: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3475: my %courses;
1.51 www 3476: my $now=time;
1.482 raeburn 3477: if (!defined($uname)) {
3478: $uname = $env{'user.name'};
3479: }
3480: if (!defined($udom)) {
3481: $udom = $env{'user.domain'};
3482: }
3483: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3484: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3485: if (!%roles) {
3486: %roles = (
3487: cc => 1,
3488: in => 1,
3489: ep => 1,
3490: ta => 1,
3491: cr => 1,
3492: st => 1,
3493: );
3494: }
3495: foreach my $entry (keys(%roleshash)) {
3496: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3497: if ($trole =~ /^cr/) {
3498: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3499: } else {
3500: next if (!exists($roles{$trole}));
3501: }
3502: if ($tend) {
3503: next if ($tend < $now);
3504: }
3505: if ($tstart) {
3506: next if ($tstart > $now);
3507: }
3508: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3509: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3510: if ($secpart eq '') {
3511: ($cnum,$role) = split(/_/,$cnumpart);
3512: $sec = 'none';
3513: $realsec = '';
3514: } else {
3515: $cnum = $cnumpart;
3516: ($sec,$role) = split(/_/,$secpart);
3517: $realsec = $sec;
1.490 raeburn 3518: }
1.482 raeburn 3519: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3520: }
3521: } else {
3522: foreach my $key (keys(%env)) {
1.483 albertel 3523: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3524: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3525: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3526: next if ($role eq 'ca' || $role eq 'aa');
3527: next if (%roles && !exists($roles{$role}));
3528: my ($starttime,$endtime)=split(/\./,$env{$key});
3529: my $active=1;
3530: if ($starttime) {
3531: if ($now<$starttime) { $active=0; }
3532: }
3533: if ($endtime) {
3534: if ($now>$endtime) { $active=0; }
3535: }
3536: if ($active) {
3537: if ($sec eq '') {
3538: $sec = 'none';
3539: }
3540: $courses{$cdom.'_'.$cnum}{$sec} =
3541: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3542: }
3543: }
1.51 www 3544: }
3545: }
1.474 raeburn 3546: return %courses;
1.51 www 3547: }
1.37 matthew 3548:
1.54 www 3549: ###############################################
1.474 raeburn 3550:
3551: sub blockcheck {
1.482 raeburn 3552: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3553:
3554: if (!defined($udom)) {
3555: $udom = $env{'user.domain'};
3556: }
3557: if (!defined($uname)) {
3558: $uname = $env{'user.name'};
3559: }
3560:
3561: # If uname and udom are for a course, check for blocks in the course.
3562:
3563: if (&Apache::lonnet::is_course($udom,$uname)) {
3564: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3565: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3566: return ($startblock,$endblock);
3567: }
1.474 raeburn 3568:
1.502 raeburn 3569: my $startblock = 0;
3570: my $endblock = 0;
1.482 raeburn 3571: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3572:
1.490 raeburn 3573: # If uname is for a user, and activity is course-specific, i.e.,
3574: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3575:
1.490 raeburn 3576: if (($activity eq 'boards' || $activity eq 'chat' ||
3577: $activity eq 'groups') && ($env{'request.course.id'})) {
3578: foreach my $key (keys(%live_courses)) {
3579: if ($key ne $env{'request.course.id'}) {
3580: delete($live_courses{$key});
3581: }
3582: }
3583: }
3584:
3585: my $otheruser = 0;
3586: my %own_courses;
3587: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3588: # Resource belongs to user other than current user.
3589: $otheruser = 1;
3590: # Gather courses for current user
3591: %own_courses =
3592: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3593: }
3594:
3595: # Gather active course roles - course coordinator, instructor,
3596: # exam proctor, ta, student, or custom role.
1.474 raeburn 3597:
3598: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3599: my ($cdom,$cnum);
3600: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3601: $cdom = $env{'course.'.$course.'.domain'};
3602: $cnum = $env{'course.'.$course.'.num'};
3603: } else {
1.490 raeburn 3604: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3605: }
3606: my $no_ownblock = 0;
3607: my $no_userblock = 0;
1.533 raeburn 3608: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3609: # Check if current user has 'evb' priv for this
3610: if (defined($own_courses{$course})) {
3611: foreach my $sec (keys(%{$own_courses{$course}})) {
3612: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3613: if ($sec ne 'none') {
3614: $checkrole .= '/'.$sec;
3615: }
3616: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3617: $no_ownblock = 1;
3618: last;
3619: }
3620: }
3621: }
3622: # if they have 'evb' priv and are currently not playing student
3623: next if (($no_ownblock) &&
3624: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3625: }
1.474 raeburn 3626: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3627: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3628: if ($sec ne 'none') {
1.482 raeburn 3629: $checkrole .= '/'.$sec;
1.474 raeburn 3630: }
1.490 raeburn 3631: if ($otheruser) {
3632: # Resource belongs to user other than current user.
3633: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3634: my ($trole,$tdom,$tnum,$tsec);
3635: my $entry = $live_courses{$course}{$sec};
3636: if ($entry =~ /^cr/) {
3637: ($trole,$tdom,$tnum,$tsec) =
3638: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3639: } else {
3640: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3641: }
3642: my ($spec,$area,$trest,%allroles,%userroles);
3643: $area = '/'.$tdom.'/'.$tnum;
3644: $trest = $tnum;
3645: if ($tsec ne '') {
3646: $area .= '/'.$tsec;
3647: $trest .= '/'.$tsec;
3648: }
3649: $spec = $trole.'.'.$area;
3650: if ($trole =~ /^cr/) {
3651: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3652: $tdom,$spec,$trest,$area);
3653: } else {
3654: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3655: $tdom,$spec,$trest,$area);
3656: }
3657: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3658: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3659: if ($1) {
3660: $no_userblock = 1;
3661: last;
3662: }
3663: }
1.490 raeburn 3664: } else {
3665: # Resource belongs to current user
3666: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3667: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3668: $no_ownblock = 1;
3669: last;
3670: }
1.474 raeburn 3671: }
3672: }
3673: # if they have the evb priv and are currently not playing student
1.482 raeburn 3674: next if (($no_ownblock) &&
1.491 albertel 3675: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3676: next if ($no_userblock);
1.474 raeburn 3677:
1.490 raeburn 3678: # Retrieve blocking times and identity of blocker for course
3679: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3680:
3681: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3682: if (($start != 0) &&
3683: (($startblock == 0) || ($startblock > $start))) {
3684: $startblock = $start;
3685: }
3686: if (($end != 0) &&
3687: (($endblock == 0) || ($endblock < $end))) {
3688: $endblock = $end;
3689: }
1.490 raeburn 3690: }
3691: return ($startblock,$endblock);
3692: }
3693:
3694: sub get_blocks {
3695: my ($setters,$activity,$cdom,$cnum) = @_;
3696: my $startblock = 0;
3697: my $endblock = 0;
3698: my $course = $cdom.'_'.$cnum;
3699: $setters->{$course} = {};
3700: $setters->{$course}{'staff'} = [];
3701: $setters->{$course}{'times'} = [];
3702: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3703: foreach my $record (keys(%records)) {
3704: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3705: if ($start <= time && $end >= time) {
3706: my ($staff_name,$staff_dom,$title,$blocks) =
3707: &parse_block_record($records{$record});
3708: if ($blocks->{$activity} eq 'on') {
3709: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3710: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3711: if ( ($startblock == 0) || ($startblock > $start) ) {
3712: $startblock = $start;
1.490 raeburn 3713: }
1.491 albertel 3714: if ( ($endblock == 0) || ($endblock < $end) ) {
3715: $endblock = $end;
1.474 raeburn 3716: }
3717: }
3718: }
3719: }
3720: return ($startblock,$endblock);
3721: }
3722:
3723: sub parse_block_record {
3724: my ($record) = @_;
3725: my ($setuname,$setudom,$title,$blocks);
3726: if (ref($record) eq 'HASH') {
3727: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3728: $title = &unescape($record->{'event'});
3729: $blocks = $record->{'blocks'};
3730: } else {
3731: my @data = split(/:/,$record,3);
3732: if (scalar(@data) eq 2) {
3733: $title = $data[1];
3734: ($setuname,$setudom) = split(/@/,$data[0]);
3735: } else {
3736: ($setuname,$setudom,$title) = @data;
3737: }
3738: $blocks = { 'com' => 'on' };
3739: }
3740: return ($setuname,$setudom,$title,$blocks);
3741: }
3742:
3743: sub build_block_table {
3744: my ($startblock,$endblock,$setters) = @_;
3745: my %lt = &Apache::lonlocal::texthash(
3746: 'cacb' => 'Currently active communication blocks',
3747: 'cour' => 'Course',
3748: 'dura' => 'Duration',
3749: 'blse' => 'Block set by'
3750: );
3751: my $output;
1.476 raeburn 3752: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3753: $output .= &start_data_table();
3754: $output .= '
3755: <tr>
3756: <th>'.$lt{'cour'}.'</th>
3757: <th>'.$lt{'dura'}.'</th>
3758: <th>'.$lt{'blse'}.'</th>
3759: </tr>
3760: ';
3761: foreach my $course (keys(%{$setters})) {
3762: my %courseinfo=&Apache::lonnet::coursedescription($course);
3763: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3764: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3765: my $fullname = &plainname($uname,$udom);
3766: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3767: && $env{'user.name'} ne 'public'
3768: && $env{'user.domain'} ne 'public') {
3769: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3770: }
1.474 raeburn 3771: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3772: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3773: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3774: $output .= &Apache::loncommon::start_data_table_row().
3775: '<td>'.$courseinfo{'description'}.'</td>'.
3776: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3777: '<td>'.$fullname.'</td>'.
1.474 raeburn 3778: &Apache::loncommon::end_data_table_row();
3779: }
3780: }
3781: $output .= &end_data_table();
3782: }
3783:
1.490 raeburn 3784: sub blocking_status {
3785: my ($activity,$uname,$udom) = @_;
3786: my %setters;
3787: my ($blocked,$output,$ownitem,$is_course);
3788: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3789: if ($startblock && $endblock) {
3790: $blocked = 1;
3791: if (wantarray) {
3792: my $category;
3793: if ($activity eq 'boards') {
3794: $category = 'Discussion posts in this course';
3795: } elsif ($activity eq 'blogs') {
3796: $category = 'Blogs';
3797: } elsif ($activity eq 'port') {
3798: if (defined($uname) && defined($udom)) {
3799: if ($uname eq $env{'user.name'} &&
3800: $udom eq $env{'user.domain'}) {
3801: $ownitem = 1;
3802: }
3803: }
3804: $is_course = &Apache::lonnet::is_course($udom,$uname);
3805: if ($ownitem) {
3806: $category = 'Your portfolio files';
3807: } elsif ($is_course) {
3808: my $coursedesc;
3809: foreach my $course (keys(%setters)) {
3810: my %courseinfo =
3811: &Apache::lonnet::coursedescription($course);
3812: $coursedesc = $courseinfo{'description'};
3813: }
3814: $category = "Group files in the course '$coursedesc'";
3815: } else {
3816: $category = 'Portfolio files belonging to ';
3817: if ($env{'user.name'} eq 'public' &&
3818: $env{'user.domain'} eq 'public') {
3819: $category .= &plainname($uname,$udom);
3820: } else {
3821: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3822: }
3823: }
3824: } elsif ($activity eq 'groups') {
3825: $category = 'Groups in this course';
3826: }
3827: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3828: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3829: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3830: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3831: $output .= &build_block_table($startblock,$endblock,\%setters);
3832: }
3833: }
3834: }
3835: if (wantarray) {
3836: return ($blocked,$output);
3837: } else {
3838: return $blocked;
3839: }
3840: }
3841:
1.60 matthew 3842: ###############################################
3843:
1.682 raeburn 3844: sub check_ip_acc {
3845: my ($acc)=@_;
3846: &Apache::lonxml::debug("acc is $acc");
3847: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3848: return 1;
3849: }
3850: my $allowed=0;
3851: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3852:
3853: my $name;
3854: foreach my $pattern (split(',',$acc)) {
3855: $pattern =~ s/^\s*//;
3856: $pattern =~ s/\s*$//;
3857: if ($pattern =~ /\*$/) {
3858: #35.8.*
3859: $pattern=~s/\*//;
3860: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3861: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3862: #35.8.3.[34-56]
3863: my $low=$2;
3864: my $high=$3;
3865: $pattern=$1;
3866: if ($ip =~ /^\Q$pattern\E/) {
3867: my $last=(split(/\./,$ip))[3];
3868: if ($last <=$high && $last >=$low) { $allowed=1; }
3869: }
3870: } elsif ($pattern =~ /^\*/) {
3871: #*.msu.edu
3872: $pattern=~s/\*//;
3873: if (!defined($name)) {
3874: use Socket;
3875: my $netaddr=inet_aton($ip);
3876: ($name)=gethostbyaddr($netaddr,AF_INET);
3877: }
3878: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3879: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3880: #127.0.0.1
3881: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3882: } else {
3883: #some.name.com
3884: if (!defined($name)) {
3885: use Socket;
3886: my $netaddr=inet_aton($ip);
3887: ($name)=gethostbyaddr($netaddr,AF_INET);
3888: }
3889: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3890: }
3891: if ($allowed) { last; }
3892: }
3893: return $allowed;
3894: }
3895:
3896: ###############################################
3897:
1.60 matthew 3898: =pod
3899:
1.112 bowersj2 3900: =head1 Domain Template Functions
3901:
3902: =over 4
3903:
3904: =item * &determinedomain()
1.60 matthew 3905:
3906: Inputs: $domain (usually will be undef)
3907:
1.63 www 3908: Returns: Determines which domain should be used for designs
1.60 matthew 3909:
3910: =cut
1.54 www 3911:
1.60 matthew 3912: ###############################################
1.63 www 3913: sub determinedomain {
3914: my $domain=shift;
1.531 albertel 3915: if (! $domain) {
1.60 matthew 3916: # Determine domain if we have not been given one
3917: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3918: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3919: if ($env{'request.role.domain'}) {
3920: $domain=$env{'request.role.domain'};
1.60 matthew 3921: }
3922: }
1.63 www 3923: return $domain;
3924: }
3925: ###############################################
1.517 raeburn 3926:
1.518 albertel 3927: sub devalidate_domconfig_cache {
3928: my ($udom)=@_;
3929: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3930: }
3931:
3932: # ---------------------- Get domain configuration for a domain
3933: sub get_domainconf {
3934: my ($udom) = @_;
3935: my $cachetime=1800;
3936: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3937: if (defined($cached)) { return %{$result}; }
3938:
3939: my %domconfig = &Apache::lonnet::get_dom('configuration',
3940: ['login','rolecolors'],$udom);
1.632 raeburn 3941: my (%designhash,%legacy);
1.518 albertel 3942: if (keys(%domconfig) > 0) {
3943: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3944: if (keys(%{$domconfig{'login'}})) {
3945: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3946: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3947: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3948: $designhash{$udom.'.login.'.$key.'_'.$img} =
3949: $domconfig{'login'}{$key}{$img};
3950: }
3951: } else {
3952: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3953: }
1.632 raeburn 3954: }
3955: } else {
3956: $legacy{'login'} = 1;
1.518 albertel 3957: }
1.632 raeburn 3958: } else {
3959: $legacy{'login'} = 1;
1.518 albertel 3960: }
3961: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3962: if (keys(%{$domconfig{'rolecolors'}})) {
3963: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3964: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3965: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3966: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3967: }
1.518 albertel 3968: }
3969: }
1.632 raeburn 3970: } else {
3971: $legacy{'rolecolors'} = 1;
1.518 albertel 3972: }
1.632 raeburn 3973: } else {
3974: $legacy{'rolecolors'} = 1;
1.518 albertel 3975: }
1.632 raeburn 3976: if (keys(%legacy) > 0) {
3977: my %legacyhash = &get_legacy_domconf($udom);
3978: foreach my $item (keys(%legacyhash)) {
3979: if ($item =~ /^\Q$udom\E\.login/) {
3980: if ($legacy{'login'}) {
3981: $designhash{$item} = $legacyhash{$item};
3982: }
3983: } else {
3984: if ($legacy{'rolecolors'}) {
3985: $designhash{$item} = $legacyhash{$item};
3986: }
1.518 albertel 3987: }
3988: }
3989: }
1.632 raeburn 3990: } else {
3991: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3992: }
3993: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3994: $cachetime);
3995: return %designhash;
3996: }
3997:
1.632 raeburn 3998: sub get_legacy_domconf {
3999: my ($udom) = @_;
4000: my %legacyhash;
4001: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4002: my $designfile = $designdir.'/'.$udom.'.tab';
4003: if (-e $designfile) {
4004: if ( open (my $fh,"<$designfile") ) {
4005: while (my $line = <$fh>) {
4006: next if ($line =~ /^\#/);
4007: chomp($line);
4008: my ($key,$val)=(split(/\=/,$line));
4009: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4010: }
4011: close($fh);
4012: }
4013: }
4014: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4015: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4016: }
4017: return %legacyhash;
4018: }
4019:
1.63 www 4020: =pod
4021:
1.112 bowersj2 4022: =item * &domainlogo()
1.63 www 4023:
4024: Inputs: $domain (usually will be undef)
4025:
4026: Returns: A link to a domain logo, if the domain logo exists.
4027: If the domain logo does not exist, a description of the domain.
4028:
4029: =cut
1.112 bowersj2 4030:
1.63 www 4031: ###############################################
4032: sub domainlogo {
1.517 raeburn 4033: my $domain = &determinedomain(shift);
1.518 albertel 4034: my %designhash = &get_domainconf($domain);
1.517 raeburn 4035: # See if there is a logo
4036: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4037: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4038: if ($imgsrc =~ m{^/(adm|res)/}) {
4039: if ($imgsrc =~ m{^/res/}) {
4040: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4041: &Apache::lonnet::repcopy($local_name);
4042: }
4043: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4044: }
4045: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4046: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4047: return &Apache::lonnet::domain($domain,'description');
1.59 www 4048: } else {
1.60 matthew 4049: return '';
1.59 www 4050: }
4051: }
1.63 www 4052: ##############################################
4053:
4054: =pod
4055:
1.112 bowersj2 4056: =item * &designparm()
1.63 www 4057:
4058: Inputs: $which parameter; $domain (usually will be undef)
4059:
4060: Returns: value of designparamter $which
4061:
4062: =cut
1.112 bowersj2 4063:
1.397 albertel 4064:
1.400 albertel 4065: ##############################################
1.397 albertel 4066: sub designparm {
4067: my ($which,$domain)=@_;
1.258 albertel 4068: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4069: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4070: return '#000000';
4071: }
1.635 raeburn 4072: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4073: return '#FFFFFF';
4074: }
4075: if ($which=~/\.tabbg$/) {
4076: return '#CCCCCC';
4077: }
4078: }
1.397 albertel 4079: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4080: return $env{'environment.color.'.$which};
1.96 www 4081: }
1.63 www 4082: $domain=&determinedomain($domain);
1.518 albertel 4083: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4084: my $output;
1.517 raeburn 4085: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4086: $output = $domdesign{$domain.'.'.$which};
1.63 www 4087: } else {
1.520 raeburn 4088: $output = $defaultdesign{$which};
4089: }
4090: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4091: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4092: if ($output =~ m{^/(adm|res)/}) {
4093: if ($output =~ m{^/res/}) {
4094: my $local_name = &Apache::lonnet::filelocation('',$output);
4095: &Apache::lonnet::repcopy($local_name);
4096: }
1.520 raeburn 4097: $output = &lonhttpdurl($output);
4098: }
1.63 www 4099: }
1.520 raeburn 4100: return $output;
1.63 www 4101: }
1.59 www 4102:
1.60 matthew 4103: ###############################################
4104: ###############################################
4105:
4106: =pod
4107:
1.112 bowersj2 4108: =back
4109:
1.549 albertel 4110: =head1 HTML Helpers
1.112 bowersj2 4111:
4112: =over 4
4113:
4114: =item * &bodytag()
1.60 matthew 4115:
4116: Returns a uniform header for LON-CAPA web pages.
4117:
4118: Inputs:
4119:
1.112 bowersj2 4120: =over 4
4121:
4122: =item * $title, A title to be displayed on the page.
4123:
4124: =item * $function, the current role (can be undef).
4125:
4126: =item * $addentries, extra parameters for the <body> tag.
4127:
4128: =item * $bodyonly, if defined, only return the <body> tag.
4129:
4130: =item * $domain, if defined, force a given domain.
4131:
4132: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4133: text interface only)
1.60 matthew 4134:
1.326 albertel 4135: =item * $customtitle, alternate text to use instead of $title
4136: in the title box that appears, this text
4137: is not auto translated like the $title is
1.309 albertel 4138:
4139: =item * $notopbar, if true, keep the 'what is this' info but remove the
4140: navigational links
1.317 albertel 4141:
1.338 albertel 4142: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4143:
4144: =item * $notitle, if true keep the nav controls, but remove the title bar
4145:
1.361 albertel 4146: =item * $no_inline_link, if true and in remote mode, don't show the
4147: 'Switch To Inline Menu' link
4148:
1.460 albertel 4149: =item * $args, optional argument valid values are
4150: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4151: inherit_jsmath -> when creating popup window in a page,
4152: should it have jsmath forced on by the
4153: current page
1.460 albertel 4154:
1.112 bowersj2 4155: =back
4156:
1.60 matthew 4157: Returns: A uniform header for LON-CAPA web pages.
4158: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4159: If $bodyonly is undef or zero, an html string containing a <body> tag and
4160: other decorations will be returned.
4161:
4162: =cut
4163:
1.54 www 4164: sub bodytag {
1.309 albertel 4165: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4166: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4167:
1.460 albertel 4168: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4169:
1.183 matthew 4170: $function = &get_users_function() if (!$function);
1.339 albertel 4171: my $img = &designparm($function.'.img',$domain);
4172: my $font = &designparm($function.'.font',$domain);
4173: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4174:
4175: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4176: 'bgcolor' => $pgbg,
1.339 albertel 4177: 'text' => $font,
4178: 'alink' => &designparm($function.'.alink',$domain),
4179: 'vlink' => &designparm($function.'.vlink',$domain),
4180: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4181: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4182:
1.63 www 4183: # role and realm
1.378 raeburn 4184: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4185: if ($role eq 'ca') {
1.479 albertel 4186: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4187: $realm = &plainname($rname,$rdom);
1.378 raeburn 4188: }
1.55 www 4189: # realm
1.258 albertel 4190: if ($env{'request.course.id'}) {
1.378 raeburn 4191: if ($env{'request.role'} !~ /^cr/) {
4192: $role = &Apache::lonnet::plaintext($role,&course_type());
4193: }
1.359 albertel 4194: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4195: } else {
4196: $role = &Apache::lonnet::plaintext($role);
1.54 www 4197: }
1.433 albertel 4198:
1.359 albertel 4199: if (!$realm) { $realm=' '; }
1.55 www 4200: # Set messages
1.60 matthew 4201: my $messages=&domainlogo($domain);
1.330 albertel 4202:
1.438 albertel 4203: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4204:
1.101 www 4205: # construct main body tag
1.359 albertel 4206: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4207: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4208:
1.530 albertel 4209: if ($bodyonly) {
1.60 matthew 4210: return $bodytag;
1.258 albertel 4211: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4212: # Accessibility
1.224 raeburn 4213:
1.337 albertel 4214: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4215: if (!$notitle) {
1.337 albertel 4216: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4217: }
4218: return $bodytag;
1.359 albertel 4219: }
4220:
1.410 albertel 4221: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4222: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4223: undef($role);
1.434 albertel 4224: } else {
4225: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4226: }
1.359 albertel 4227:
4228: my $roleinfo=(<<ENDROLE);
4229: <td class="LC_title_bar_who">
4230: <div class="LC_title_bar_name">
1.410 albertel 4231: $name
1.361 albertel 4232:
1.359 albertel 4233: </div>
4234: <div class="LC_title_bar_role">
1.361 albertel 4235: $role
1.359 albertel 4236: </div>
4237: <div class="LC_title_bar_realm">
1.361 albertel 4238: $realm
1.359 albertel 4239: </div>
1.206 albertel 4240: </td>
4241: ENDROLE
1.235 raeburn 4242:
1.359 albertel 4243: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4244: if ($customtitle) {
4245: $titleinfo = $customtitle;
4246: }
4247: #
4248: # Extra info if you are the DC
4249: my $dc_info = '';
4250: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4251: $env{'course.'.$env{'request.course.id'}.
4252: '.domain'}.'/'})) {
4253: my $cid = $env{'request.course.id'};
4254: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4255: $dc_info =~ s/\s+$//;
1.359 albertel 4256: $dc_info = '('.$dc_info.')';
4257: }
4258:
1.644 www 4259: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4260: # No Remote
1.258 albertel 4261: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4262: $forcereg=1;
4263: }
4264:
4265: if (!$customtitle && $env{'request.state'} eq 'construct') {
4266: # this is for resources; directories have customtitle, and crumbs
4267: # and select recent are created in lonpubdir.pm
1.229 albertel 4268: my ($uname,$thisdisfn)=
1.258 albertel 4269: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4270: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4271: $formaction=~s/\/+/\//g;
4272:
1.359 albertel 4273: my $parentpath = '';
4274: my $lastitem = '';
4275: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4276: $parentpath = $1;
4277: $lastitem = $2;
4278: } else {
4279: $lastitem = $thisdisfn;
4280: }
4281: $titleinfo =
1.640 bisitz 4282: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4283: .'<b>'.&mt('Construction Space').'</b>: '
4284: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4285: .'" target="_top"><tt><b>'
1.705 tempelho 4286: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4287: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4288: .'</form>'
4289: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4290: }
1.359 albertel 4291:
1.337 albertel 4292: my $titletable;
1.338 albertel 4293: if (!$notitle) {
1.337 albertel 4294: $titletable =
1.359 albertel 4295: '<table id="LC_title_bar">'.
4296: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4297: '</tr></table>';
1.337 albertel 4298: }
1.359 albertel 4299: if ($notopbar) {
4300: $bodytag .= $titletable;
4301: } else {
4302: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4303: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4304: $titletable);
1.272 raeburn 4305: } else {
1.336 albertel 4306: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4307: $titletable;
1.272 raeburn 4308: }
1.235 raeburn 4309: }
4310: return $bodytag;
1.94 www 4311: }
1.95 www 4312:
1.93 www 4313: #
1.95 www 4314: # Top frame rendering, Remote is up
1.93 www 4315: #
1.359 albertel 4316:
1.517 raeburn 4317: my $imgsrc = $img;
4318: if ($img =~ /^\/adm/) {
1.575 albertel 4319: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4320: }
4321: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4322:
1.305 www 4323: # Explicit link to get inline menu
1.361 albertel 4324: my $menu= ($no_inline_link?''
4325: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4326: #
1.338 albertel 4327: if ($notitle) {
1.337 albertel 4328: return $bodytag;
4329: }
1.94 www 4330: return(<<ENDBODY);
1.60 matthew 4331: $bodytag
1.359 albertel 4332: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4333: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4334: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4335: </tr>
1.359 albertel 4336: <tr><td>$titleinfo $dc_info $menu</td>
4337: $roleinfo
1.368 albertel 4338: </tr>
1.356 albertel 4339: </table>
1.54 www 4340: ENDBODY
1.182 matthew 4341: }
4342:
1.330 albertel 4343: sub make_attr_string {
4344: my ($register,$attr_ref) = @_;
4345:
4346: if ($attr_ref && !ref($attr_ref)) {
4347: die("addentries Must be a hash ref ".
4348: join(':',caller(1))." ".
4349: join(':',caller(0))." ");
4350: }
4351:
4352: if ($register) {
1.339 albertel 4353: my ($on_load,$on_unload);
4354: foreach my $key (keys(%{$attr_ref})) {
4355: if (lc($key) eq 'onload') {
4356: $on_load.=$attr_ref->{$key}.';';
4357: delete($attr_ref->{$key});
4358:
4359: } elsif (lc($key) eq 'onunload') {
4360: $on_unload.=$attr_ref->{$key}.';';
4361: delete($attr_ref->{$key});
4362: }
4363: }
4364: $attr_ref->{'onload'} =
4365: &Apache::lonmenu::loadevents(). $on_load;
4366: $attr_ref->{'onunload'}=
4367: &Apache::lonmenu::unloadevents().$on_unload;
4368: }
4369:
4370: # Accessibility font enhance
4371: if ($env{'browser.fontenhance'} eq 'on') {
4372: my $style;
4373: foreach my $key (keys(%{$attr_ref})) {
4374: if (lc($key) eq 'style') {
4375: $style.=$attr_ref->{$key}.';';
4376: delete($attr_ref->{$key});
4377: }
4378: }
4379: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4380: }
1.339 albertel 4381:
4382: if ($env{'browser.blackwhite'} eq 'on') {
4383: delete($attr_ref->{'font'});
4384: delete($attr_ref->{'link'});
4385: delete($attr_ref->{'alink'});
4386: delete($attr_ref->{'vlink'});
4387: delete($attr_ref->{'bgcolor'});
4388: delete($attr_ref->{'background'});
4389: }
4390:
1.330 albertel 4391: my $attr_string;
4392: foreach my $attr (keys(%$attr_ref)) {
4393: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4394: }
4395: return $attr_string;
4396: }
4397:
4398:
1.182 matthew 4399: ###############################################
1.251 albertel 4400: ###############################################
4401:
4402: =pod
4403:
4404: =item * &endbodytag()
4405:
4406: Returns a uniform footer for LON-CAPA web pages.
4407:
1.635 raeburn 4408: Inputs: 1 - optional reference to an args hash
4409: If in the hash, key for noredirectlink has a value which evaluates to true,
4410: a 'Continue' link is not displayed if the page contains an
4411: internal redirect in the <head></head> section,
4412: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4413:
4414: =cut
4415:
4416: sub endbodytag {
1.635 raeburn 4417: my ($args) = @_;
1.251 albertel 4418: my $endbodytag='</body>';
1.269 albertel 4419: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4420: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4421: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4422: $endbodytag=
4423: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4424: &mt('Continue').'</a>'.
4425: $endbodytag;
4426: }
1.315 albertel 4427: }
1.251 albertel 4428: return $endbodytag;
4429: }
4430:
1.352 albertel 4431: =pod
4432:
4433: =item * &standard_css()
4434:
4435: Returns a style sheet
4436:
4437: Inputs: (all optional)
4438: domain -> force to color decorate a page for a specific
4439: domain
4440: function -> force usage of a specific rolish color scheme
4441: bgcolor -> override the default page bgcolor
4442:
4443: =cut
4444:
1.343 albertel 4445: sub standard_css {
1.345 albertel 4446: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4447: $function = &get_users_function() if (!$function);
4448: my $img = &designparm($function.'.img', $domain);
4449: my $tabbg = &designparm($function.'.tabbg', $domain);
4450: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4451: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4452: my $pgbg_or_bgcolor =
4453: $bgcolor ||
1.352 albertel 4454: &designparm($function.'.pgbg', $domain);
1.382 albertel 4455: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4456: my $alink = &designparm($function.'.alink', $domain);
4457: my $vlink = &designparm($function.'.vlink', $domain);
4458: my $link = &designparm($function.'.link', $domain);
4459:
1.704 muellerd 4460: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4461: my $bgcol = &designparm('login.bgcol',$domain);
4462: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4463:
1.602 albertel 4464: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4465: my $mono = 'monospace';
1.352 albertel 4466: my $data_table_head = $tabbg;
4467: my $data_table_light = '#EEEEEE';
1.470 banghart 4468: my $data_table_dark = '#DDDDDD';
4469: my $data_table_darker = '#CCCCCC';
1.349 albertel 4470: my $data_table_highlight = '#FFFF00';
1.352 albertel 4471: my $mail_new = '#FFBB77';
4472: my $mail_new_hover = '#DD9955';
4473: my $mail_read = '#BBBB77';
4474: my $mail_read_hover = '#999944';
4475: my $mail_replied = '#AAAA88';
4476: my $mail_replied_hover = '#888855';
4477: my $mail_other = '#99BBBB';
4478: my $mail_other_hover = '#669999';
1.391 albertel 4479: my $table_header = '#DDDDDD';
1.489 raeburn 4480: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4481: my $lg_border_color = '#C8C8C8';
1.392 albertel 4482:
1.608 albertel 4483: my $border = ($env{'browser.type'} eq 'explorer' ||
4484: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4485: : '0px 3px 0px 4px';
1.448 albertel 4486:
1.523 albertel 4487:
1.343 albertel 4488: return <<END;
1.698 harmsja 4489: body{
4490: font-family: $sans;
4491: line-height:130%;
1.701 harmsja 4492: font-size:0.83em;
1.698 harmsja 4493: color:$font;
4494: }
1.701 harmsja 4495: a:link, a:visited { font-size:100%; }
1.698 harmsja 4496:
1.343 albertel 4497: a:focus { color: red; background: yellow }
1.510 albertel 4498: table.thinborder,
4499: table.thinborder tr th {
4500: border-style: solid;
4501: border-width: 1px;
1.698 harmsja 4502: border-color: $lg_border_color;
1.510 albertel 4503: background: $tabbg;
4504: }
1.523 albertel 4505: table.thinborder tr td {
1.510 albertel 4506: border-style: solid;
1.698 harmsja 4507: border-width: 1px;
4508: border-color: $lg_border_color;
1.510 albertel 4509: }
1.426 albertel 4510:
1.343 albertel 4511: form, .inline { display: inline; }
1.721 harmsja 4512:
4513: .LC_center { text-align: center; }
4514: .LC_left { text-align:left; }
4515: .LC_right {text-align:right;}
4516: .LC_middle {vertical-align:middle;}
4517: .LC_top {vertical-align:top;}
4518: .LC_bottom {vertical-align:bottom;}
4519:
4520: /* just for tests */
4521: .LC_300Box { width:300px; }
4522: .LC_200Box {width:200px; }
4523: .LC_500Box {width:500px; }
4524: .LC_600Box {width:600px; }
1.741 harmsja 4525: .LC_800Box {width:800px;}
1.721 harmsja 4526: /* end */
4527:
1.593 albertel 4528: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4529: .LC_error {
4530: color: red;
4531: font-size: larger;
4532: }
1.457 albertel 4533: .LC_warning,
4534: .LC_diff_removed {
1.733 bisitz 4535: color: red;
1.394 albertel 4536: }
1.532 albertel 4537:
4538: .LC_info,
1.457 albertel 4539: .LC_success,
4540: .LC_diff_added {
1.350 albertel 4541: color: green;
4542: }
1.543 albertel 4543: .LC_unknown {
4544: color: yellow;
4545: }
4546:
1.440 albertel 4547: .LC_icon {
4548: border: 0px;
4549: }
1.539 albertel 4550: .LC_indexer_icon {
4551: border: 0px;
4552: height: 22px;
4553: }
1.543 albertel 4554: .LC_docs_spacer {
4555: width: 25px;
4556: height: 1px;
4557: border: 0px;
4558: }
1.346 albertel 4559:
1.532 albertel 4560: .LC_internal_info {
1.735 bisitz 4561: color: #999999;
1.532 albertel 4562: }
4563:
1.458 albertel 4564: table.LC_pastsubmission {
4565: border: 1px solid black;
4566: margin: 2px;
4567: }
4568:
1.606 albertel 4569: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4570: width: 100%;
4571: background: $pgbg;
1.392 albertel 4572: border: 2px;
1.402 albertel 4573: border-collapse: separate;
1.403 albertel 4574: padding: 0px;
1.345 albertel 4575: }
1.392 albertel 4576:
1.606 albertel 4577: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4578: table#LC_title_bar.LC_with_remote {
1.359 albertel 4579: width: 100%;
1.392 albertel 4580: border-color: $pgbg;
4581: border-style: solid;
4582: border-width: $border;
4583:
1.379 albertel 4584: background: $pgbg;
4585: font-family: $sans;
1.392 albertel 4586: border-collapse: collapse;
1.403 albertel 4587: padding: 0px;
1.359 albertel 4588: }
1.409 albertel 4589: table.LC_docs_path {
4590: width: 100%;
4591: border: 0;
4592: background: $pgbg;
4593: font-family: $sans;
4594: border-collapse: collapse;
4595: padding: 0px;
4596: }
4597:
1.359 albertel 4598: table#LC_title_bar td {
4599: background: $tabbg;
4600: }
4601: table#LC_title_bar td.LC_title_bar_who {
4602: background: $tabbg;
4603: color: $font;
1.427 albertel 4604: font: small $sans;
1.359 albertel 4605: text-align: right;
4606: }
1.469 banghart 4607: span.LC_metadata {
4608: font-family: $sans;
4609: }
1.359 albertel 4610: span.LC_title_bar_title {
1.416 albertel 4611: font: bold x-large $sans;
1.359 albertel 4612: }
4613: table#LC_title_bar td.LC_title_bar_domain_logo {
4614: background: $sidebg;
4615: text-align: right;
1.368 albertel 4616: padding: 0px;
4617: }
4618: table#LC_title_bar td.LC_title_bar_role_logo {
4619: background: $sidebg;
4620: padding: 0px;
1.359 albertel 4621: }
4622:
1.706 harmsja 4623: table#LC_menubuttons img{
1.346 albertel 4624: border: 0px;
4625: }
1.345 albertel 4626: table#LC_top_nav td {
4627: background: $tabbg;
1.392 albertel 4628: border: 0px;
1.407 albertel 4629: font-size: small;
1.706 harmsja 4630: vertical-align:top;
4631: padding:2px 5px 2px 5px;
1.345 albertel 4632: }
4633: table#LC_top_nav td a, div#LC_top_nav a {
4634: color: $font;
4635: font-family: $sans;
4636: }
1.364 albertel 4637: table#LC_top_nav td.LC_top_nav_logo {
4638: background: $tabbg;
1.432 albertel 4639: text-align: left;
1.408 albertel 4640: white-space: nowrap;
1.432 albertel 4641: width: 31px;
1.408 albertel 4642: }
4643: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4644: border: 0px;
1.408 albertel 4645: vertical-align: bottom;
1.364 albertel 4646: }
1.432 albertel 4647: table#LC_top_nav td.LC_top_nav_exit,
4648: table#LC_top_nav td.LC_top_nav_help {
4649: width: 2.0em;
4650: }
1.442 albertel 4651: table#LC_top_nav td.LC_top_nav_login {
4652: width: 4.0em;
4653: text-align: center;
4654: }
1.409 albertel 4655: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4656: background: $tabbg;
4657: color: $font;
4658: font-family: $sans;
1.358 albertel 4659: font-size: smaller;
1.357 albertel 4660: }
1.411 albertel 4661: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4662: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4663: background: $tabbg;
4664: color: $font;
4665: font-family: $sans;
4666: font-size: larger;
4667: text-align: right;
4668: }
1.383 albertel 4669: td.LC_table_cell_checkbox {
4670: text-align: center;
4671: }
1.522 albertel 4672: table#LC_mainmenu td.LC_mainmenu_column {
4673: vertical-align: top;
4674: }
4675:
1.705 tempelho 4676: .LC_fontsize_small
4677: {
4678: font-size: 70%;
4679: }
4680:
4681: .LC_fontsize_medium
4682: {
4683: font-size: 85%;
4684: }
4685:
4686: .LC_fontsize_large
4687: {
4688: font-size: 120%;
4689: }
4690:
4691: .LC_fontcolor_red
4692: {
4693: color: #FF0000;
4694: }
4695:
1.346 albertel 4696: .LC_menubuttons_inline_text {
4697: color: $font;
4698: font-family: $sans;
1.698 harmsja 4699: font-size: 90%;
1.701 harmsja 4700: padding-left:3px;
1.346 albertel 4701: }
4702:
1.526 www 4703: .LC_menubuttons_link {
4704: text-decoration: none;
4705: }
1.698 harmsja 4706: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4707: .LC_menubuttons_category {
1.521 www 4708: color: $font;
1.526 www 4709: background: $pgbg;
1.521 www 4710: font-family: $sans;
4711: font-size: larger;
4712: font-weight: bold;
4713: }
4714:
1.346 albertel 4715: td.LC_menubuttons_text {
1.701 harmsja 4716: color: $font;
1.346 albertel 4717: }
1.706 harmsja 4718:
4719:
1.526 www 4720:
1.346 albertel 4721: .LC_current_location {
4722: font-family: $sans;
4723: background: $tabbg;
4724: }
4725: .LC_new_mail {
4726: font-family: $sans;
1.634 www 4727: background: $tabbg;
1.346 albertel 4728: font-weight: bold;
4729: }
1.347 albertel 4730:
1.526 www 4731:
1.527 www 4732: .LC_dropadd_labeltext {
4733: font-family: $sans;
4734: text-align: right;
4735: }
4736:
4737: .LC_preferences_labeltext {
4738: font-family: $sans;
4739: text-align: right;
4740: }
4741:
1.666 raeburn 4742: .LC_roleslog_note {
1.701 harmsja 4743: font-size: small;
1.666 raeburn 4744: }
4745:
1.715 raeburn 4746: .LC_mail_functions {
4747: font-weight: bold;
4748: }
4749:
1.440 albertel 4750: table.LC_aboutme_port {
4751: border: 0px;
4752: border-collapse: collapse;
4753: border-spacing: 0px;
4754: }
1.349 albertel 4755: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4756: border: 1px solid #000000;
1.402 albertel 4757: border-collapse: separate;
1.426 albertel 4758: border-spacing: 1px;
1.610 albertel 4759: background: $pgbg;
1.347 albertel 4760: }
1.422 albertel 4761: .LC_data_table_dense {
4762: font-size: small;
4763: }
1.507 raeburn 4764: table.LC_nested_outer {
4765: border: 1px solid #000000;
1.589 raeburn 4766: border-collapse: collapse;
1.507 raeburn 4767: border-spacing: 0px;
4768: width: 100%;
4769: }
4770: table.LC_nested {
4771: border: 0px;
1.589 raeburn 4772: border-collapse: collapse;
1.507 raeburn 4773: border-spacing: 0px;
4774: width: 100%;
4775: }
1.523 albertel 4776: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4777: table.LC_prior_tries tr th {
1.349 albertel 4778: font-weight: bold;
4779: background-color: $data_table_head;
1.701 harmsja 4780: font-size:90%;
1.347 albertel 4781: }
1.711 raeburn 4782: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4783: background-color: #CCCCCC;
1.711 raeburn 4784: font-weight: bold;
4785: text-align: left;
4786: }
1.610 albertel 4787: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4788: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4789: table.LC_aboutme_port tr td {
1.349 albertel 4790: background-color: $data_table_light;
1.425 albertel 4791: padding: 2px;
1.347 albertel 4792: }
1.610 albertel 4793: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4794: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4795: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4796: background-color: $data_table_dark;
1.709 bisitz 4797: padding: 2px;
1.347 albertel 4798: }
1.425 albertel 4799: table.LC_data_table tr.LC_data_table_highlight td {
4800: background-color: $data_table_darker;
4801: }
1.639 raeburn 4802: table.LC_data_table tr td.LC_leftcol_header {
4803: background-color: $data_table_head;
4804: font-weight: bold;
4805: }
1.451 albertel 4806: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4807: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4808: background-color: #FFFFFF;
1.421 albertel 4809: font-weight: bold;
4810: font-style: italic;
4811: text-align: center;
4812: padding: 8px;
1.347 albertel 4813: }
1.507 raeburn 4814: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4815: padding: 4ex
4816: }
1.507 raeburn 4817: table.LC_nested_outer tr th {
4818: font-weight: bold;
4819: background-color: $data_table_head;
1.701 harmsja 4820: font-size: small;
1.507 raeburn 4821: border-bottom: 1px solid #000000;
4822: }
4823: table.LC_nested_outer tr td.LC_subheader {
4824: background-color: $data_table_head;
4825: font-weight: bold;
4826: font-size: small;
4827: border-bottom: 1px solid #000000;
4828: text-align: right;
1.451 albertel 4829: }
1.507 raeburn 4830: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4831: background-color: #CCCCCC;
1.451 albertel 4832: font-weight: bold;
4833: font-size: small;
1.507 raeburn 4834: text-align: center;
4835: }
1.589 raeburn 4836: table.LC_nested tr.LC_info_row td.LC_left_item,
4837: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4838: text-align: left;
1.451 albertel 4839: }
1.507 raeburn 4840: table.LC_nested td {
1.735 bisitz 4841: background-color: #FFFFFF;
1.451 albertel 4842: font-size: small;
1.507 raeburn 4843: }
4844: table.LC_nested_outer tr th.LC_right_item,
4845: table.LC_nested tr.LC_info_row td.LC_right_item,
4846: table.LC_nested tr.LC_odd_row td.LC_right_item,
4847: table.LC_nested tr td.LC_right_item {
1.451 albertel 4848: text-align: right;
4849: }
4850:
1.507 raeburn 4851: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4852: background-color: #EEEEEE;
1.451 albertel 4853: }
4854:
1.473 raeburn 4855: table.LC_createuser {
4856: }
4857:
4858: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4859: font-size: small;
1.473 raeburn 4860: }
4861:
4862: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4863: background-color: #CCCCCC;
1.473 raeburn 4864: font-weight: bold;
4865: text-align: center;
4866: }
4867:
1.349 albertel 4868: table.LC_calendar {
4869: border: 1px solid #000000;
4870: border-collapse: collapse;
4871: }
4872: table.LC_calendar_pickdate {
4873: font-size: xx-small;
4874: }
4875: table.LC_calendar tr td {
4876: border: 1px solid #000000;
4877: vertical-align: top;
4878: }
4879: table.LC_calendar tr td.LC_calendar_day_empty {
4880: background-color: $data_table_dark;
4881: }
4882: table.LC_calendar tr td.LC_calendar_day_current {
4883: background-color: $data_table_highlight;
4884: }
4885:
4886: table.LC_mail_list tr.LC_mail_new {
4887: background-color: $mail_new;
4888: }
4889: table.LC_mail_list tr.LC_mail_new:hover {
4890: background-color: $mail_new_hover;
4891: }
4892: table.LC_mail_list tr.LC_mail_read {
4893: background-color: $mail_read;
4894: }
4895: table.LC_mail_list tr.LC_mail_read:hover {
4896: background-color: $mail_read_hover;
4897: }
4898: table.LC_mail_list tr.LC_mail_replied {
4899: background-color: $mail_replied;
4900: }
4901: table.LC_mail_list tr.LC_mail_replied:hover {
4902: background-color: $mail_replied_hover;
4903: }
4904: table.LC_mail_list tr.LC_mail_other {
4905: background-color: $mail_other;
4906: }
4907: table.LC_mail_list tr.LC_mail_other:hover {
4908: background-color: $mail_other_hover;
4909: }
1.494 raeburn 4910: table.LC_mail_list tr.LC_mail_even {
4911: }
4912: table.LC_mail_list tr.LC_mail_odd {
4913: }
4914:
1.696 bisitz 4915: table.LC_data_table tr > td.LC_browser_file,
4916: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 4917: background: #CCFF88;
4918: }
1.696 bisitz 4919: table.LC_data_table tr > td.LC_browser_file_locked,
4920: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 4921: background: #FFAA99;
1.387 albertel 4922: }
1.696 bisitz 4923: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.389 albertel 4924: background: #AAAAAA;
1.387 albertel 4925: }
1.696 bisitz 4926: table.LC_data_table tr > td.LC_browser_file_modified,
4927: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.389 albertel 4928: background: #FFFF77;
1.387 albertel 4929: }
1.696 bisitz 4930: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 4931: background: #CCCCFF;
1.387 albertel 4932: }
1.696 bisitz 4933:
1.707 bisitz 4934: table.LC_data_table tr > td.LC_roles_is {
4935: /* background: #77FF77; */
4936: }
4937: table.LC_data_table tr > td.LC_roles_future {
4938: background: #FFFF77;
4939: }
4940: table.LC_data_table tr > td.LC_roles_will {
4941: background: #FFAA77;
4942: }
4943: table.LC_data_table tr > td.LC_roles_expired {
4944: background: #FF7777;
4945: }
4946: table.LC_data_table tr > td.LC_roles_will_not {
4947: background: #AAFF77;
4948: }
4949: table.LC_data_table tr > td.LC_roles_selected {
4950: background: #11CC55;
4951: }
4952:
1.388 albertel 4953: span.LC_current_location {
1.701 harmsja 4954: font-size:larger;
1.388 albertel 4955: background: $pgbg;
4956: }
1.387 albertel 4957:
1.395 albertel 4958: span.LC_parm_menu_item {
4959: font-size: larger;
4960: font-family: $sans;
4961: }
4962: span.LC_parm_scope_all {
4963: color: red;
4964: }
4965: span.LC_parm_scope_folder {
4966: color: green;
4967: }
4968: span.LC_parm_scope_resource {
4969: color: orange;
4970: }
4971: span.LC_parm_part {
4972: color: blue;
4973: }
4974: span.LC_parm_folder, span.LC_parm_symb {
4975: font-size: x-small;
4976: font-family: $mono;
4977: color: #AAAAAA;
4978: }
4979:
1.396 albertel 4980: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4981: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4982: border: 1px solid black;
4983: border-collapse: collapse;
4984: }
4985: table.LC_parm_overview_restrictions td {
4986: border-width: 1px 4px 1px 4px;
4987: border-style: solid;
4988: border-color: $pgbg;
4989: text-align: center;
4990: }
4991: table.LC_parm_overview_restrictions th {
4992: background: $tabbg;
4993: border-width: 1px 4px 1px 4px;
4994: border-style: solid;
4995: border-color: $pgbg;
4996: }
1.398 albertel 4997: table#LC_helpmenu {
4998: border: 0px;
4999: height: 55px;
5000: border-spacing: 0px;
5001: }
5002:
5003: table#LC_helpmenu fieldset legend {
5004: font-size: larger;
5005: font-weight: bold;
5006: }
1.397 albertel 5007: table#LC_helpmenu_links {
5008: width: 100%;
5009: border: 1px solid black;
5010: background: $pgbg;
5011: padding: 0px;
5012: border-spacing: 1px;
5013: }
5014: table#LC_helpmenu_links tr td {
5015: padding: 1px;
5016: background: $tabbg;
1.399 albertel 5017: text-align: center;
5018: font-weight: bold;
1.397 albertel 5019: }
1.396 albertel 5020:
1.397 albertel 5021: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5022: table#LC_helpmenu_links a:active {
5023: text-decoration: none;
5024: color: $font;
5025: }
5026: table#LC_helpmenu_links a:hover {
5027: text-decoration: underline;
5028: color: $vlink;
5029: }
1.396 albertel 5030:
1.417 albertel 5031: .LC_chrt_popup_exists {
5032: border: 1px solid #339933;
5033: margin: -1px;
5034: }
5035: .LC_chrt_popup_up {
5036: border: 1px solid yellow;
5037: margin: -1px;
5038: }
5039: .LC_chrt_popup {
5040: border: 1px solid #8888FF;
5041: background: #CCCCFF;
5042: }
1.421 albertel 5043: table.LC_pick_box {
5044: border-collapse: separate;
5045: background: white;
5046: border: 1px solid black;
5047: border-spacing: 1px;
5048: }
5049: table.LC_pick_box td.LC_pick_box_title {
5050: background: $tabbg;
5051: font-weight: bold;
5052: text-align: right;
1.740 bisitz 5053: vertical-align: top;
1.421 albertel 5054: width: 184px;
5055: padding: 8px;
5056: }
1.645 raeburn 5057: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5058: background: $tabbg;
5059: font-weight: bold;
5060: text-align: right;
5061: width: 350px;
5062: padding: 8px;
5063: }
5064:
1.579 raeburn 5065: table.LC_pick_box td.LC_pick_box_value {
5066: text-align: left;
5067: padding: 8px;
5068: }
5069: table.LC_pick_box td.LC_pick_box_select {
5070: text-align: left;
5071: padding: 8px;
5072: }
1.424 albertel 5073: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5074: padding: 0px;
5075: height: 1px;
5076: background: black;
5077: }
5078: table.LC_pick_box td.LC_pick_box_submit {
5079: text-align: right;
5080: }
1.579 raeburn 5081: table.LC_pick_box td.LC_evenrow_value {
5082: text-align: left;
5083: padding: 8px;
5084: background-color: $data_table_light;
5085: }
5086: table.LC_pick_box td.LC_oddrow_value {
5087: text-align: left;
5088: padding: 8px;
5089: background-color: $data_table_light;
5090: }
5091: table.LC_helpform_receipt {
5092: width: 620px;
5093: border-collapse: separate;
5094: background: white;
5095: border: 1px solid black;
5096: border-spacing: 1px;
5097: }
5098: table.LC_helpform_receipt td.LC_pick_box_title {
5099: background: $tabbg;
5100: font-weight: bold;
5101: text-align: right;
5102: width: 184px;
5103: padding: 8px;
5104: }
5105: table.LC_helpform_receipt td.LC_evenrow_value {
5106: text-align: left;
5107: padding: 8px;
5108: background-color: $data_table_light;
5109: }
5110: table.LC_helpform_receipt td.LC_oddrow_value {
5111: text-align: left;
5112: padding: 8px;
5113: background-color: $data_table_light;
5114: }
5115: table.LC_helpform_receipt td.LC_pick_box_separator {
5116: padding: 0px;
5117: height: 1px;
5118: background: black;
5119: }
5120: span.LC_helpform_receipt_cat {
5121: font-weight: bold;
5122: }
1.424 albertel 5123: table.LC_group_priv_box {
5124: background: white;
5125: border: 1px solid black;
5126: border-spacing: 1px;
5127: }
5128: table.LC_group_priv_box td.LC_pick_box_title {
5129: background: $tabbg;
5130: font-weight: bold;
5131: text-align: right;
5132: width: 184px;
5133: }
5134: table.LC_group_priv_box td.LC_groups_fixed {
5135: background: $data_table_light;
5136: text-align: center;
5137: }
5138: table.LC_group_priv_box td.LC_groups_optional {
5139: background: $data_table_dark;
5140: text-align: center;
5141: }
5142: table.LC_group_priv_box td.LC_groups_functionality {
5143: background: $data_table_darker;
5144: text-align: center;
5145: font-weight: bold;
5146: }
5147: table.LC_group_priv td {
5148: text-align: left;
5149: padding: 0px;
5150: }
5151:
1.421 albertel 5152: table.LC_notify_front_page {
5153: background: white;
5154: border: 1px solid black;
5155: padding: 8px;
5156: }
5157: table.LC_notify_front_page td {
5158: padding: 8px;
5159: }
1.424 albertel 5160: .LC_navbuttons {
5161: margin: 2ex 0ex 2ex 0ex;
5162: }
1.423 albertel 5163: .LC_topic_bar {
5164: font-family: $sans;
5165: font-weight: bold;
5166: width: 100%;
5167: background: $tabbg;
5168: vertical-align: middle;
5169: margin: 2ex 0ex 2ex 0ex;
5170: }
5171: .LC_topic_bar span {
5172: vertical-align: middle;
5173: }
5174: .LC_topic_bar img {
5175: vertical-align: bottom;
5176: }
5177: table.LC_course_group_status {
5178: margin: 20px;
5179: }
5180: table.LC_status_selector td {
5181: vertical-align: top;
5182: text-align: center;
1.424 albertel 5183: padding: 4px;
5184: }
5185: table.LC_descriptive_input td.LC_description {
5186: vertical-align: top;
5187: text-align: right;
5188: font-weight: bold;
1.423 albertel 5189: }
1.599 albertel 5190: div.LC_feedback_link {
1.616 albertel 5191: clear: both;
1.599 albertel 5192: background: white;
5193: width: 100%;
1.489 raeburn 5194: }
5195: span.LC_feedback_link {
1.599 albertel 5196: background: $feedback_link_bg;
5197: font-size: larger;
5198: }
5199: span.LC_message_link {
5200: background: $feedback_link_bg;
5201: font-size: larger;
5202: position: absolute;
5203: right: 1em;
1.489 raeburn 5204: }
1.421 albertel 5205:
1.515 albertel 5206: table.LC_prior_tries {
1.524 albertel 5207: border: 1px solid #000000;
5208: border-collapse: separate;
5209: border-spacing: 1px;
1.515 albertel 5210: }
1.523 albertel 5211:
1.515 albertel 5212: table.LC_prior_tries td {
1.524 albertel 5213: padding: 2px;
1.515 albertel 5214: }
1.523 albertel 5215:
5216: .LC_answer_correct {
5217: background: #AAFFAA;
5218: color: black;
5219: }
5220: .LC_answer_charged_try {
5221: background: #FFAAAA ! important;
5222: color: black;
5223: }
5224: .LC_answer_not_charged_try,
5225: .LC_answer_no_grade,
5226: .LC_answer_late {
5227: background: #FFFFAA;
5228: color: black;
5229: }
5230: .LC_answer_previous {
5231: background: #AAAAFF;
5232: color: black;
5233: }
5234: .LC_answer_no_message {
5235: background: #FFFFFF;
5236: color: black;
5237: }
5238: .LC_answer_unknown {
5239: background: orange;
5240: color: black;
5241: }
5242:
5243:
1.529 albertel 5244: span.LC_prior_numerical,
5245: span.LC_prior_string,
5246: span.LC_prior_custom,
5247: span.LC_prior_reaction,
5248: span.LC_prior_math {
1.523 albertel 5249: font-family: monospace;
5250: white-space: pre;
5251: }
5252:
1.525 albertel 5253: span.LC_prior_string {
5254: font-family: monospace;
5255: white-space: pre;
5256: }
5257:
1.523 albertel 5258: table.LC_prior_option {
5259: width: 100%;
5260: border-collapse: collapse;
5261: }
1.528 albertel 5262: table.LC_prior_rank, table.LC_prior_match {
5263: border-collapse: collapse;
5264: }
5265: table.LC_prior_option tr td,
5266: table.LC_prior_rank tr td,
5267: table.LC_prior_match tr td {
1.524 albertel 5268: border: 1px solid #000000;
1.515 albertel 5269: }
5270:
1.519 raeburn 5271: span.LC_nobreak {
1.544 albertel 5272: white-space: nowrap;
1.519 raeburn 5273: }
5274:
1.576 raeburn 5275: span.LC_cusr_emph {
5276: font-style: italic;
5277: }
5278:
1.633 raeburn 5279: span.LC_cusr_subheading {
5280: font-weight: normal;
5281: font-size: 85%;
5282: }
5283:
1.545 albertel 5284: table.LC_docs_documents {
5285: background: #BBBBBB;
1.547 albertel 5286: border-width: 0px;
1.545 albertel 5287: border-collapse: collapse;
5288: }
5289:
5290: table.LC_docs_documents td.LC_docs_document {
5291: border: 2px solid black;
5292: padding: 4px;
5293: }
5294:
5295: .LC_docs_entry_move {
5296: border: 0px;
5297: border-collapse: collapse;
1.544 albertel 5298: }
5299:
1.545 albertel 5300: .LC_docs_entry_move td {
5301: border: 2px solid #BBBBBB;
5302: background: #DDDDDD;
5303: }
5304:
5305: .LC_docs_editor td.LC_docs_entry_commands {
5306: background: #DDDDDD;
5307: font-size: x-small;
5308: }
1.544 albertel 5309: .LC_docs_copy {
1.545 albertel 5310: color: #000099;
1.544 albertel 5311: }
5312: .LC_docs_cut {
1.545 albertel 5313: color: #550044;
1.544 albertel 5314: }
5315: .LC_docs_rename {
1.545 albertel 5316: color: #009900;
1.544 albertel 5317: }
5318: .LC_docs_remove {
1.545 albertel 5319: color: #990000;
5320: }
5321:
1.547 albertel 5322: .LC_docs_reinit_warn,
5323: .LC_docs_ext_edit {
5324: font-size: x-small;
5325: }
5326:
1.545 albertel 5327: .LC_docs_editor td.LC_docs_entry_title,
5328: .LC_docs_editor td.LC_docs_entry_icon {
5329: background: #FFFFBB;
5330: }
5331: .LC_docs_editor td.LC_docs_entry_parameter {
5332: background: #BBBBFF;
5333: font-size: x-small;
5334: white-space: nowrap;
5335: }
5336:
5337: table.LC_docs_adddocs td,
5338: table.LC_docs_adddocs th {
5339: border: 1px solid #BBBBBB;
5340: padding: 4px;
5341: background: #DDDDDD;
1.543 albertel 5342: }
5343:
1.584 albertel 5344: table.LC_sty_begin {
5345: background: #BBFFBB;
5346: }
5347: table.LC_sty_end {
5348: background: #FFBBBB;
5349: }
5350:
1.589 raeburn 5351: table.LC_double_column {
5352: border-width: 0px;
5353: border-collapse: collapse;
5354: width: 100%;
5355: padding: 2px;
5356: }
5357:
5358: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5359: top: 2px;
1.589 raeburn 5360: left: 2px;
5361: width: 47%;
5362: vertical-align: top;
5363: }
5364:
5365: table.LC_double_column tr td.LC_right_col {
5366: top: 2px;
5367: right: 2px;
5368: width: 47%;
5369: vertical-align: top;
5370: }
5371:
1.594 raeburn 5372: span.LC_role_level {
5373: font-weight: bold;
5374: }
5375:
1.591 raeburn 5376: div.LC_left_float {
5377: float: left;
5378: padding-right: 5%;
1.597 albertel 5379: padding-bottom: 4px;
1.591 raeburn 5380: }
5381:
5382: div.LC_clear_float_header {
1.597 albertel 5383: padding-bottom: 2px;
1.591 raeburn 5384: }
5385:
5386: div.LC_clear_float_footer {
1.597 albertel 5387: padding-top: 10px;
1.591 raeburn 5388: clear: both;
5389: }
5390:
1.597 albertel 5391:
5392: div.LC_grade_show_user {
5393: margin-top: 20px;
5394: border: 1px solid black;
5395: }
5396: div.LC_grade_user_name {
5397: background: #DDDDEE;
5398: border-bottom: 1px solid black;
1.705 tempelho 5399: font-weight: bold;
5400: font-size: large;
1.597 albertel 5401: }
5402: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5403: background: #DDEEDD;
5404: }
5405:
5406: div.LC_grade_show_problem,
5407: div.LC_grade_submissions,
5408: div.LC_grade_message_center,
5409: div.LC_grade_info_links,
5410: div.LC_grade_assign {
5411: margin: 5px;
5412: width: 99%;
5413: background: #FFFFFF;
5414: }
5415: div.LC_grade_show_problem_header,
5416: div.LC_grade_submissions_header,
5417: div.LC_grade_message_center_header,
5418: div.LC_grade_assign_header {
1.705 tempelho 5419: font-weight: bold;
5420: font-size: large;
1.597 albertel 5421: }
5422: div.LC_grade_show_problem_problem,
5423: div.LC_grade_submissions_body,
5424: div.LC_grade_message_center_body,
5425: div.LC_grade_assign_body {
5426: border: 1px solid black;
5427: width: 99%;
5428: background: #FFFFFF;
5429: }
1.598 albertel 5430: span.LC_grade_check_note {
1.705 tempelho 5431: font-weight: normal;
5432: font-size: medium;
1.598 albertel 5433: display: inline;
5434: position: absolute;
5435: right: 1em;
5436: }
1.597 albertel 5437:
1.613 albertel 5438: table.LC_scantron_action {
5439: width: 100%;
5440: }
5441: table.LC_scantron_action tr th {
1.698 harmsja 5442: font-weight:bold;
5443: font-style:normal;
1.613 albertel 5444: }
1.698 harmsja 5445: .LC_edit_problem_header,
1.614 albertel 5446: div.LC_edit_problem_footer {
1.705 tempelho 5447: font-weight: normal;
5448: font-size: medium;
1.602 albertel 5449: margin: 2px;
1.600 albertel 5450: }
5451: div.LC_edit_problem_header,
1.602 albertel 5452: div.LC_edit_problem_header div,
1.614 albertel 5453: div.LC_edit_problem_footer,
5454: div.LC_edit_problem_footer div,
1.602 albertel 5455: div.LC_edit_problem_editxml_header,
5456: div.LC_edit_problem_editxml_header div {
1.600 albertel 5457: margin-top: 5px;
5458: }
1.602 albertel 5459: div.LC_edit_problem_header_edit_row {
5460: background: $tabbg;
5461: padding: 3px;
5462: margin-bottom: 5px;
5463: }
1.600 albertel 5464: div.LC_edit_problem_header_title {
1.705 tempelho 5465: font-weight: bold;
5466: font-size: larger;
1.602 albertel 5467: background: $tabbg;
5468: padding: 3px;
5469: }
5470: table.LC_edit_problem_header_title {
1.705 tempelho 5471: font-size: larger;
5472: font-weight: bold;
1.602 albertel 5473: width: 100%;
5474: border-color: $pgbg;
5475: border-style: solid;
5476: border-width: $border;
5477:
1.600 albertel 5478: background: $tabbg;
1.602 albertel 5479: border-collapse: collapse;
5480: padding: 0px
5481: }
5482:
5483: div.LC_edit_problem_discards {
5484: float: left;
5485: padding-bottom: 5px;
5486: }
5487: div.LC_edit_problem_saves {
5488: float: right;
5489: padding-bottom: 5px;
1.600 albertel 5490: }
5491: hr.LC_edit_problem_divide {
1.602 albertel 5492: clear: both;
1.600 albertel 5493: color: $tabbg;
5494: background-color: $tabbg;
5495: height: 3px;
5496: border: 0px;
5497: }
1.679 riegler 5498: img.stift{
1.678 riegler 5499: border-width:0;
1.679 riegler 5500: vertical-align:middle;
1.677 riegler 5501: }
1.680 riegler 5502:
1.681 riegler 5503: table#LC_mainmenu{
5504: margin-top:10px;
5505: width:80%;
5506:
5507: }
5508:
1.680 riegler 5509: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5510: vertical-align: top;
5511: width: 45%;
5512: }
5513: .LC_mainmenu_fieldset_category {
5514: color: $font;
5515: background: $pgbg;
5516: font-family: $sans;
5517: font-size: small;
5518: font-weight: bold;
5519: }
5520:
1.716 raeburn 5521: div.LC_createcourse {
5522: margin: 10px 10px 10px 10px;
5523: }
5524:
1.693 droeschl 5525: /* ---- Remove when done ----
5526: # The following styles is part of the redesign of LON-CAPA and are
5527: # subject to change during this project.
5528: # Don't rely on their current functionality as they might be
5529: # changed or removed.
5530: # --------------------------*/
5531:
1.698 harmsja 5532: a:hover,
1.721 harmsja 5533: ol.LC_smallMenu a:hover,
5534: ol#LC_MenuBreadcrumbs a:hover,
5535: ol#LC_PathBreadcrumbs a:hover,
5536: ul#LC_TabMainMenuContent a:hover,
5537: .LC_FormSectionClearButton input:hover
5538: ul.LC_TabContent li:hover a{
1.698 harmsja 5539: color:#BF2317;
5540: text-decoration:none;
1.693 droeschl 5541: }
5542:
5543: h1 {
1.721 harmsja 5544: padding:5px 10px 5px 20px;
1.693 droeschl 5545: line-height:130%;
5546: }
1.698 harmsja 5547:
1.693 droeschl 5548: h2,h3,h4,h5,h6
5549: {
1.721 harmsja 5550: margin:5px 0px 5px 0px;
5551: padding:0px;
5552: line-height:130%;
1.693 droeschl 5553: }
1.721 harmsja 5554: .LC_hcell{
1.698 harmsja 5555: padding:3px 15px 3px 15px;
5556: margin:0px;
1.703 harmsja 5557: background-color:$tabbg;
5558: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5559: }
1.721 harmsja 5560: .LC_noBorder {
1.698 harmsja 5561: border:0px;
5562: }
1.693 droeschl 5563:
1.722 harmsja 5564: .LC_bgLightGrey{
1.741 harmsja 5565: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
1.722 harmsja 5566: }
1.741 harmsja 5567:
1.693 droeschl 5568:
1.698 harmsja 5569: /* Main Header with discription of Person, Course, etc. */
1.721 harmsja 5570: .LC_HeadRight {
1.693 droeschl 5571: text-align: right;
5572: float: right;
5573: margin: 0px;
5574: padding: 0px;
1.698 harmsja 5575: right:0;
1.693 droeschl 5576: position:absolute;
1.698 harmsja 5577: overflow:hidden;
1.693 droeschl 5578: }
5579:
1.721 harmsja 5580: p, .LC_ContentBox {
1.698 harmsja 5581: padding: 10px;
5582:
5583: }
1.721 harmsja 5584: .LC_FormSectionClearButton input {
1.741 harmsja 5585: background-color:transparent;
1.698 harmsja 5586: border:0px;
5587: cursor:pointer;
5588: text-decoration:underline;
1.693 droeschl 5589: }
5590:
5591:
1.698 harmsja 5592: dl,ul,div,fieldset {
5593: margin: 10px 10px 10px 0px;
1.693 droeschl 5594: overflow:hidden;
5595: }
1.721 harmsja 5596: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5597: margin: 0px;
1.693 droeschl 5598: }
5599:
1.721 harmsja 5600: ol.LC_smallMenu li {
1.693 droeschl 5601: display: inline;
5602: padding: 5px 5px 0px 10px;
5603: vertical-align: top;
5604: }
5605:
1.721 harmsja 5606: ol.LC_smallMenu li img {
1.693 droeschl 5607: vertical-align: bottom;
5608: }
5609:
1.721 harmsja 5610: ol.LC_smallMenu a {
1.693 droeschl 5611: font-size: 90%;
5612: color: RGB(80, 80, 80);
5613: text-decoration: none;
5614: }
1.741 harmsja 5615: ol#LC_TabMainMenueContent, ul.LC_TabContent,
5616: ul.LC_TabContentBigger {
1.721 harmsja 5617: display:block;
5618: list-style:none;
1.741 harmsja 5619: margin: 0px;
1.693 droeschl 5620: padding: 0px;
5621: }
5622:
1.741 harmsja 5623: ol#LC_TabMainMenuContent li, ul.LC_TabContent,
5624: ul.LC_TabContentBigger li{
1.693 droeschl 5625: display: inline;
1.741 harmsja 5626: border-right: solid 1px $lg_border_color;
5627: float:left;
5628: line-height:140%;
5629: white-space:nowrap;
5630: }
5631: ol#LC_TabMainMenuContent li{
1.693 droeschl 5632: vertical-align: bottom;
5633: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5634: padding: 5px 10px 5px 10px;
1.741 harmsja 5635: margin-right:5px;
5636: margin-bottom:3px;
1.693 droeschl 5637: font-weight: bold;
1.723 riegler 5638: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5639: }
5640:
1.721 harmsja 5641: ol#LC_TabMainMenuContent li a{
1.693 droeschl 5642: color: RGB(47, 47, 47);
5643: text-decoration: none;
5644: }
1.721 harmsja 5645: ul.LC_TabContent {
1.741 harmsja 5646: min-height:1.6em;
5647: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5648: }
5649: ul.LC_TabContent li{
1.741 harmsja 5650: vertical-align:middle;
5651: padding:0px 10px 0px 10px;
1.721 harmsja 5652: }
5653: ul.LC_TabContent li a, ul.LC_TabContent li{
5654: color:rgb(47,47,47);
5655: text-decoration:none;
5656: font-size:95%;
5657: font-weight:bold;
5658: }
1.741 harmsja 5659: ul.LC_TabContentBigger li{
5660: vertical-align:bottom;
5661: border-top:solid 1px $lg_border_color;
5662: border-left:solid 1px $lg_border_color;
5663: padding:5px 10px 5px 10px;
5664: margin-left:2px;
5665: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5666: }
5667: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5668: font-size:110%;
5669: font-weight:bold;
5670: }
5671: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
5672: {
5673: margin:0px;
1.737 tempelho 5674: }
5675:
1.721 harmsja 5676: .LC_hideThis
5677: {
5678: display:none;
5679: visibility:hidden;
1.693 droeschl 5680: }
5681:
1.721 harmsja 5682: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
1.693 droeschl 5683: border-top: solid 1px RGB(255, 255, 255);
5684: height: 20px;
5685: line-height: 20px;
5686: vertical-align: bottom;
5687: margin: 0px 0px 30px 0px;
5688: padding-left: 10px;
5689: list-style-position: inside;
1.723 riegler 5690: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5691: }
5692:
1.721 harmsja 5693: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
1.741 harmsja 5694: /*
1.723 riegler 5695: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.741 harmsja 5696: */
1.693 droeschl 5697: display: inline;
5698: padding: 0px 0px 0px 10px;
5699: vertical-align: bottom;
5700: overflow:hidden;
5701: }
5702:
1.721 harmsja 5703: ol#LC_MenuBreadcrumbs li a {
1.693 droeschl 5704: text-decoration: none;
5705: font-size:90%;
5706: }
1.721 harmsja 5707: ol#LC_PathBreadcrumbs li a{
1.698 harmsja 5708: text-decoration:none;
5709: font-size:100%;
5710: font-weight:bold;
1.693 droeschl 5711: }
1.721 harmsja 5712: .LC_ContentBoxSpecial
1.693 droeschl 5713: {
1.701 harmsja 5714: border: solid 1px $lg_border_color;
1.698 harmsja 5715: }
1.693 droeschl 5716:
1.721 harmsja 5717: dl.LC_ListStyleClean dt {
1.693 droeschl 5718: padding-right: 5px;
5719: display: table-header-group;
5720: }
5721:
1.721 harmsja 5722: dl.LC_ListStyleClean dd {
1.693 droeschl 5723: display: table-row;
5724: }
5725:
1.721 harmsja 5726: .LC_ListStyleClean,
5727: .LC_ListStyleSimple,
5728: .LC_ListStyleNormal,
5729: .LC_ListStyleNormal_Border,
5730: .LC_ListStyleSpecial
1.693 droeschl 5731: {
5732: /*display:block; */
5733: list-style-position: inside;
5734: list-style-type: none;
5735: overflow: hidden;
5736: padding: 0px;
5737: }
5738:
1.721 harmsja 5739: .LC_ListStyleSimple li,
5740: .LC_ListStyleSimple dd,
5741: .LC_ListStyleNormal li,
5742: .LC_ListStyleNormal dd,
5743: .LC_ListStyleSpecial li,
5744: .LC_ListStyleSpecial dd
1.693 droeschl 5745: {
5746: margin: 0px;
5747: padding: 5px 5px 5px 10px;
5748: clear: both;
5749: }
5750:
1.721 harmsja 5751: .LC_ListStyleClean li,
5752: .LC_ListStyleClean dd {
1.693 droeschl 5753: padding-top: 0px;
5754: padding-bottom: 0px;
5755: }
5756:
1.721 harmsja 5757: .LC_ListStyleSimple dd,
5758: .LC_ListStyleSimple li{
1.698 harmsja 5759: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 5760: }
5761:
1.721 harmsja 5762: .LC_ListStyleSpecial li,
5763: .LC_ListStyleSpecial dd {
1.693 droeschl 5764: list-style-type: none;
5765: background-color: RGB(220, 220, 220);
5766: margin-bottom: 4px;
5767: }
5768:
1.721 harmsja 5769: table.LC_SimpleTable {
1.698 harmsja 5770: margin:5px;
5771: border:solid 1px $lg_border_color;
1.693 droeschl 5772: }
5773:
1.721 harmsja 5774: table.LC_SimpleTable tr {
1.698 harmsja 5775: padding:0px;
5776: border:solid 1px $lg_border_color;
1.693 droeschl 5777: }
1.721 harmsja 5778: table.LC_SimpleTable thead{
1.698 harmsja 5779: background:rgb(220,220,220);
1.693 droeschl 5780: }
5781:
1.721 harmsja 5782: div.LC_columnSection {
1.693 droeschl 5783: display: block;
5784: clear: both;
5785: overflow: hidden;
5786: margin:0px;
5787: }
5788:
1.721 harmsja 5789: div.LC_columnSection>* {
1.693 droeschl 5790: float: left;
5791: margin: 10px 20px 10px 0px;
5792: overflow:hidden;
5793: }
1.721 harmsja 5794: div.LC_columnSection > .LC_ContentBox,
5795: div.LC_columnSection > .LC_ContentBoxSpecial
1.693 droeschl 5796: {
1.721 harmsja 5797: width: 400px;
1.693 droeschl 5798: }
1.721 harmsja 5799:
1.719 ehlerst 5800: .ContentBoxSpecialTemplate
5801: {
5802: border: solid 1px $lg_border_color;
5803: }
5804: .ContentBoxTemplate {
5805: padding:10px;
5806: }
5807:
1.721 harmsja 5808: div.LC_columnSection > .ContentBoxTemplate,
5809: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719 ehlerst 5810: {
5811: width: 600px;
5812:
5813: }
5814:
1.720 ehlerst 5815: .clear{
5816: clear: both;
5817: line-height: 0px;
5818: font-size: 0px;
5819: height: 0px;
5820: }
1.693 droeschl 5821:
1.694 tempelho 5822: .LC_loginpage_container {
5823: text-align:left;
5824: margin : 0 auto;
5825: width:65%;
5826: padding: 10px;
5827: height: auto;
1.712 muellerd 5828: background-color:#FFFFFF;
1.694 tempelho 5829: border:1px solid #CCCCCC;
5830: }
5831:
5832:
5833: .LC_loginpage_loginContainer {
5834: float:left;
1.712 muellerd 5835: width: 182px;
5836: border:1px solid #CCCCCC;
5837: background-color:$loginbg;
1.694 tempelho 5838: }
5839:
1.717 tempelho 5840: .LC_loginpage_loginContainer h2{
1.712 muellerd 5841: margin-top:0;
5842: display:block;
5843: background:$bgcol;
5844: color:$textcol;
5845: padding-left:5px;
5846: }
1.694 tempelho 5847: .LC_loginpage_loginInfo {
5848: margin-left:20px;
5849: float:left;
5850: width:30%;
5851: border:1px solid #CCCCCC;
5852: padding:10px;
5853: }
5854:
1.712 muellerd 5855: .LC_loginpage_loginDomain {
5856: margin-right:20px;
5857: width:20%;
5858: float:left;
5859: padding:10px;
5860: }
5861:
1.694 tempelho 5862: .LC_loginpage_space {
5863: clear:both;
5864: margin-bottom:20px;
5865: border-bottom: 1px solid #CCCCCC;
5866: }
5867:
1.343 albertel 5868: END
5869: }
5870:
1.306 albertel 5871: =pod
5872:
5873: =item * &headtag()
5874:
5875: Returns a uniform footer for LON-CAPA web pages.
5876:
1.307 albertel 5877: Inputs: $title - optional title for the head
5878: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5879: $args - optional arguments
1.319 albertel 5880: force_register - if is true call registerurl so the remote is
5881: informed
1.415 albertel 5882: redirect -> array ref of
5883: 1- seconds before redirect occurs
5884: 2- url to redirect to
5885: 3- whether the side effect should occur
1.315 albertel 5886: (side effect of setting
5887: $env{'internal.head.redirect'} to the url
5888: redirected too)
1.352 albertel 5889: domain -> force to color decorate a page for a specific
5890: domain
5891: function -> force usage of a specific rolish color scheme
5892: bgcolor -> override the default page bgcolor
1.460 albertel 5893: no_auto_mt_title
5894: -> prevent &mt()ing the title arg
1.464 albertel 5895:
1.306 albertel 5896: =cut
5897:
5898: sub headtag {
1.313 albertel 5899: my ($title,$head_extra,$args) = @_;
1.306 albertel 5900:
1.363 albertel 5901: my $function = $args->{'function'} || &get_users_function();
5902: my $domain = $args->{'domain'} || &determinedomain();
5903: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5904: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5905: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5906: #time(),
1.418 albertel 5907: $env{'environment.color.timestamp'},
1.363 albertel 5908: $function,$domain,$bgcolor);
5909:
1.369 www 5910: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5911:
1.308 albertel 5912: my $result =
5913: '<head>'.
1.461 albertel 5914: &font_settings();
1.319 albertel 5915:
1.461 albertel 5916: if (!$args->{'frameset'}) {
5917: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5918: }
1.319 albertel 5919: if ($args->{'force_register'}) {
5920: $result .= &Apache::lonmenu::registerurl(1);
5921: }
1.436 albertel 5922: if (!$args->{'no_nav_bar'}
5923: && !$args->{'only_body'}
5924: && !$args->{'frameset'}) {
5925: $result .= &help_menu_js();
5926: }
1.319 albertel 5927:
1.314 albertel 5928: if (ref($args->{'redirect'})) {
1.414 albertel 5929: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5930: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5931: if (!$inhibit_continue) {
5932: $env{'internal.head.redirect'} = $url;
5933: }
1.313 albertel 5934: $result.=<<ADDMETA
5935: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5936: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5937: ADDMETA
5938: }
1.306 albertel 5939: if (!defined($title)) {
5940: $title = 'The LearningOnline Network with CAPA';
5941: }
1.460 albertel 5942: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5943: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5944: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5945: .$head_extra;
1.306 albertel 5946: return $result;
5947: }
5948:
5949: =pod
5950:
1.340 albertel 5951: =item * &font_settings()
5952:
5953: Returns neccessary <meta> to set the proper encoding
5954:
5955: Inputs: none
5956:
5957: =cut
5958:
5959: sub font_settings {
5960: my $headerstring='';
1.647 www 5961: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5962: $headerstring.=
5963: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5964: }
5965: return $headerstring;
5966: }
5967:
1.341 albertel 5968: =pod
5969:
5970: =item * &xml_begin()
5971:
5972: Returns the needed doctype and <html>
5973:
5974: Inputs: none
5975:
5976: =cut
5977:
5978: sub xml_begin {
5979: my $output='';
5980:
1.592 albertel 5981: if ($env{'internal.start_page'}==1) {
5982: &Apache::lonhtmlcommon::init_htmlareafields();
5983: }
1.342 albertel 5984:
1.341 albertel 5985: if ($env{'browser.mathml'}) {
5986: $output='<?xml version="1.0"?>'
5987: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5988: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5989:
5990: # .'<!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">] >'
5991: .'<!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">'
5992: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5993: .'xmlns="http://www.w3.org/1999/xhtml">';
5994: } else {
5995: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5996: }
5997: return $output;
5998: }
1.340 albertel 5999:
6000: =pod
6001:
1.306 albertel 6002: =item * &endheadtag()
6003:
6004: Returns a uniform </head> for LON-CAPA web pages.
6005:
6006: Inputs: none
6007:
6008: =cut
6009:
6010: sub endheadtag {
6011: return '</head>';
6012: }
6013:
6014: =pod
6015:
6016: =item * &head()
6017:
6018: Returns a uniform complete <head>..</head> 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 put inside the <head>
6027:
6028: =back
1.405 albertel 6029:
1.306 albertel 6030: =cut
6031:
6032: sub head {
1.325 albertel 6033: my ($title,$head_extra,$args) = @_;
6034: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6035: }
6036:
6037: =pod
6038:
6039: =item * &start_page()
6040:
6041: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6042:
1.648 raeburn 6043: Inputs:
6044:
6045: =over 4
6046:
6047: $title - optional title for the page
6048:
6049: $head_extra - optional extra HTML to incude inside the <head>
6050:
6051: $args - additional optional args supported are:
6052:
6053: =over 8
6054:
6055: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6056: arg on
1.648 raeburn 6057: no_nav_bar -> is true will set &bodytag() notopbar arg on
6058: add_entries -> additional attributes to add to the <body>
6059: domain -> force to color decorate a page for a
1.317 albertel 6060: specific domain
1.648 raeburn 6061: function -> force usage of a specific rolish color
1.317 albertel 6062: scheme
1.648 raeburn 6063: redirect -> see &headtag()
6064: bgcolor -> override the default page bg color
6065: js_ready -> return a string ready for being used in
1.317 albertel 6066: a javascript writeln
1.648 raeburn 6067: html_encode -> return a string ready for being used in
1.320 albertel 6068: a html attribute
1.648 raeburn 6069: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6070: $forcereg arg
1.648 raeburn 6071: body_title -> alternate text to use instead of $title
1.326 albertel 6072: in the title box that appears, this text
6073: is not auto translated like the $title is
1.648 raeburn 6074: frameset -> if true will start with a <frameset>
1.330 albertel 6075: rather than <body>
1.648 raeburn 6076: no_title -> if true the title bar won't be shown
6077: skip_phases -> hash ref of
1.338 albertel 6078: head -> skip the <html><head> generation
6079: body -> skip all <body> generation
1.648 raeburn 6080: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6081: 'Switch To Inline Menu' link
1.648 raeburn 6082: no_auto_mt_title -> prevent &mt()ing the title arg
6083: inherit_jsmath -> when creating popup window in a page,
6084: should it have jsmath forced on by the
6085: current page
1.361 albertel 6086:
1.648 raeburn 6087: =back
1.460 albertel 6088:
1.648 raeburn 6089: =back
1.562 albertel 6090:
1.306 albertel 6091: =cut
6092:
6093: sub start_page {
1.309 albertel 6094: my ($title,$head_extra,$args) = @_;
1.318 albertel 6095: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6096: my %head_args;
1.352 albertel 6097: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6098: 'bgcolor','frameset','no_nav_bar','only_body',
6099: 'no_auto_mt_title') {
1.319 albertel 6100: if (defined($args->{$arg})) {
1.324 raeburn 6101: $head_args{$arg} = $args->{$arg};
1.319 albertel 6102: }
1.313 albertel 6103: }
1.319 albertel 6104:
1.315 albertel 6105: $env{'internal.start_page'}++;
1.338 albertel 6106: my $result;
6107: if (! exists($args->{'skip_phases'}{'head'}) ) {
6108: $result.=
1.341 albertel 6109: &xml_begin().
1.338 albertel 6110: &headtag($title,$head_extra,\%head_args).&endheadtag();
6111: }
6112:
6113: if (! exists($args->{'skip_phases'}{'body'}) ) {
6114: if ($args->{'frameset'}) {
6115: my $attr_string = &make_attr_string($args->{'force_register'},
6116: $args->{'add_entries'});
6117: $result .= "\n<frameset $attr_string>\n";
6118: } else {
6119: $result .=
6120: &bodytag($title,
6121: $args->{'function'}, $args->{'add_entries'},
6122: $args->{'only_body'}, $args->{'domain'},
6123: $args->{'force_register'}, $args->{'body_title'},
6124: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6125: $args->{'no_title'}, $args->{'no_inline_link'},
6126: $args);
1.338 albertel 6127: }
1.330 albertel 6128: }
1.338 albertel 6129:
1.315 albertel 6130: if ($args->{'js_ready'}) {
1.713 kaisler 6131: $result = &js_ready($result);
1.315 albertel 6132: }
1.320 albertel 6133: if ($args->{'html_encode'}) {
1.713 kaisler 6134: $result = &html_encode($result);
6135: }
6136:
1.718 raeburn 6137: if (exists($args->{'bread_crumbs'})) {
6138: &Apache::lonhtmlcommon::clear_breadcrumbs();
6139: if (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
6140: foreach my $crumb (@{$args->{'bread_crumbs'}}){
6141: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
6142: }
6143: }
6144: $result .= &Apache::lonhtmlcommon::breadcrumbs();
1.320 albertel 6145: }
1.713 kaisler 6146:
1.315 albertel 6147: return $result;
1.306 albertel 6148: }
6149:
1.330 albertel 6150:
1.306 albertel 6151: =pod
6152:
6153: =item * &head()
6154:
6155: Returns a complete </body></html> section for LON-CAPA web pages.
6156:
1.315 albertel 6157: Inputs: $args - additional optional args supported are:
6158: js_ready -> return a string ready for being used in
6159: a javascript writeln
1.320 albertel 6160: html_encode -> return a string ready for being used in
6161: a html attribute
1.330 albertel 6162: frameset -> if true will start with a <frameset>
6163: rather than <body>
1.493 albertel 6164: dicsussion -> if true will get discussion from
6165: lonxml::xmlend
6166: (you can pass the target and parser arguments
6167: through optional 'target' and 'parser' args
6168: to this routine)
1.306 albertel 6169:
6170: =cut
6171:
6172: sub end_page {
1.315 albertel 6173: my ($args) = @_;
6174: $env{'internal.end_page'}++;
1.330 albertel 6175: my $result;
1.335 albertel 6176: if ($args->{'discussion'}) {
6177: my ($target,$parser);
6178: if (ref($args->{'discussion'})) {
6179: ($target,$parser) =($args->{'discussion'}{'target'},
6180: $args->{'discussion'}{'parser'});
6181: }
6182: $result .= &Apache::lonxml::xmlend($target,$parser);
6183: }
6184:
1.330 albertel 6185: if ($args->{'frameset'}) {
6186: $result .= '</frameset>';
6187: } else {
1.635 raeburn 6188: $result .= &endbodytag($args);
1.330 albertel 6189: }
6190: $result .= "\n</html>";
6191:
1.315 albertel 6192: if ($args->{'js_ready'}) {
1.317 albertel 6193: $result = &js_ready($result);
1.315 albertel 6194: }
1.335 albertel 6195:
1.320 albertel 6196: if ($args->{'html_encode'}) {
6197: $result = &html_encode($result);
6198: }
1.335 albertel 6199:
1.315 albertel 6200: return $result;
6201: }
6202:
1.320 albertel 6203: sub html_encode {
6204: my ($result) = @_;
6205:
1.322 albertel 6206: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6207:
6208: return $result;
6209: }
1.317 albertel 6210: sub js_ready {
6211: my ($result) = @_;
6212:
1.323 albertel 6213: $result =~ s/[\n\r]/ /xmsg;
6214: $result =~ s/\\/\\\\/xmsg;
6215: $result =~ s/'/\\'/xmsg;
1.372 albertel 6216: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6217:
6218: return $result;
6219: }
6220:
1.315 albertel 6221: sub validate_page {
6222: if ( exists($env{'internal.start_page'})
1.316 albertel 6223: && $env{'internal.start_page'} > 1) {
6224: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6225: $env{'internal.start_page'}.' '.
1.316 albertel 6226: $ENV{'request.filename'});
1.315 albertel 6227: }
6228: if ( exists($env{'internal.end_page'})
1.316 albertel 6229: && $env{'internal.end_page'} > 1) {
6230: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6231: $env{'internal.end_page'}.' '.
1.316 albertel 6232: $env{'request.filename'});
1.315 albertel 6233: }
6234: if ( exists($env{'internal.start_page'})
6235: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6236: &Apache::lonnet::logthis('start_page called without end_page '.
6237: $env{'request.filename'});
1.315 albertel 6238: }
6239: if ( ! exists($env{'internal.start_page'})
6240: && exists($env{'internal.end_page'})) {
1.316 albertel 6241: &Apache::lonnet::logthis('end_page called without start_page'.
6242: $env{'request.filename'});
1.315 albertel 6243: }
1.306 albertel 6244: }
1.315 albertel 6245:
1.318 albertel 6246: sub simple_error_page {
6247: my ($r,$title,$msg) = @_;
6248: my $page =
6249: &Apache::loncommon::start_page($title).
6250: &mt($msg).
6251: &Apache::loncommon::end_page();
6252: if (ref($r)) {
6253: $r->print($page);
1.327 albertel 6254: return;
1.318 albertel 6255: }
6256: return $page;
6257: }
1.347 albertel 6258:
6259: {
1.610 albertel 6260: my @row_count;
1.347 albertel 6261: sub start_data_table {
1.422 albertel 6262: my ($add_class) = @_;
6263: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6264: unshift(@row_count,0);
1.422 albertel 6265: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6266: }
6267:
6268: sub end_data_table {
1.610 albertel 6269: shift(@row_count);
1.389 albertel 6270: return '</table>'."\n";;
1.347 albertel 6271: }
6272:
6273: sub start_data_table_row {
1.422 albertel 6274: my ($add_class) = @_;
1.610 albertel 6275: $row_count[0]++;
6276: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6277: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6278: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6279: }
1.471 banghart 6280:
6281: sub continue_data_table_row {
6282: my ($add_class) = @_;
1.610 albertel 6283: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6284: $css_class = (join(' ',$css_class,$add_class));
6285: return '<tr class="'.$css_class.'">'."\n";;
6286: }
1.347 albertel 6287:
6288: sub end_data_table_row {
1.389 albertel 6289: return '</tr>'."\n";;
1.347 albertel 6290: }
1.367 www 6291:
1.421 albertel 6292: sub start_data_table_empty_row {
1.707 bisitz 6293: # $row_count[0]++;
1.421 albertel 6294: return '<tr class="LC_empty_row" >'."\n";;
6295: }
6296:
6297: sub end_data_table_empty_row {
6298: return '</tr>'."\n";;
6299: }
6300:
1.367 www 6301: sub start_data_table_header_row {
1.389 albertel 6302: return '<tr class="LC_header_row">'."\n";;
1.367 www 6303: }
6304:
6305: sub end_data_table_header_row {
1.389 albertel 6306: return '</tr>'."\n";;
1.367 www 6307: }
1.347 albertel 6308: }
6309:
1.548 albertel 6310: =pod
6311:
6312: =item * &inhibit_menu_check($arg)
6313:
6314: Checks for a inhibitmenu state and generates output to preserve it
6315:
6316: Inputs: $arg - can be any of
6317: - undef - in which case the return value is a string
6318: to add into arguments list of a uri
6319: - 'input' - in which case the return value is a HTML
6320: <form> <input> field of type hidden to
6321: preserve the value
6322: - a url - in which case the return value is the url with
6323: the neccesary cgi args added to preserve the
6324: inhibitmenu state
6325: - a ref to a url - no return value, but the string is
6326: updated to include the neccessary cgi
6327: args to preserve the inhibitmenu state
6328:
6329: =cut
6330:
6331: sub inhibit_menu_check {
6332: my ($arg) = @_;
6333: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6334: if ($arg eq 'input') {
6335: if ($env{'form.inhibitmenu'}) {
6336: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6337: } else {
6338: return
6339: }
6340: }
6341: if ($env{'form.inhibitmenu'}) {
6342: if (ref($arg)) {
6343: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6344: } elsif ($arg eq '') {
6345: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6346: } else {
6347: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6348: }
6349: }
6350: if (!ref($arg)) {
6351: return $arg;
6352: }
6353: }
6354:
1.251 albertel 6355: ###############################################
1.182 matthew 6356:
6357: =pod
6358:
1.549 albertel 6359: =back
6360:
6361: =head1 User Information Routines
6362:
6363: =over 4
6364:
1.405 albertel 6365: =item * &get_users_function()
1.182 matthew 6366:
6367: Used by &bodytag to determine the current users primary role.
6368: Returns either 'student','coordinator','admin', or 'author'.
6369:
6370: =cut
6371:
6372: ###############################################
6373: sub get_users_function {
6374: my $function = 'student';
1.258 albertel 6375: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6376: $function='coordinator';
6377: }
1.258 albertel 6378: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6379: $function='admin';
6380: }
1.258 albertel 6381: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6382: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6383: $function='author';
6384: }
6385: return $function;
1.54 www 6386: }
1.99 www 6387:
6388: ###############################################
6389:
1.233 raeburn 6390: =pod
6391:
1.542 raeburn 6392: =item * &check_user_status()
1.274 raeburn 6393:
6394: Determines current status of supplied role for a
6395: specific user. Roles can be active, previous or future.
6396:
6397: Inputs:
6398: user's domain, user's username, course's domain,
1.375 raeburn 6399: course's number, optional section ID.
1.274 raeburn 6400:
6401: Outputs:
6402: role status: active, previous or future.
6403:
6404: =cut
6405:
6406: sub check_user_status {
1.412 raeburn 6407: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6408: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6409: my @uroles = keys %userinfo;
6410: my $srchstr;
6411: my $active_chk = 'none';
1.412 raeburn 6412: my $now = time;
1.274 raeburn 6413: if (@uroles > 0) {
1.412 raeburn 6414: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6415: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6416: } else {
1.412 raeburn 6417: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6418: }
6419: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6420: my $role_end = 0;
6421: my $role_start = 0;
6422: $active_chk = 'active';
1.412 raeburn 6423: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6424: $role_end = $1;
6425: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6426: $role_start = $1;
1.274 raeburn 6427: }
6428: }
6429: if ($role_start > 0) {
1.412 raeburn 6430: if ($now < $role_start) {
1.274 raeburn 6431: $active_chk = 'future';
6432: }
6433: }
6434: if ($role_end > 0) {
1.412 raeburn 6435: if ($now > $role_end) {
1.274 raeburn 6436: $active_chk = 'previous';
6437: }
6438: }
6439: }
6440: }
6441: return $active_chk;
6442: }
6443:
6444: ###############################################
6445:
6446: =pod
6447:
1.405 albertel 6448: =item * &get_sections()
1.233 raeburn 6449:
6450: Determines all the sections for a course including
6451: sections with students and sections containing other roles.
1.419 raeburn 6452: Incoming parameters:
6453:
6454: 1. domain
6455: 2. course number
6456: 3. reference to array containing roles for which sections should
6457: be gathered (optional).
6458: 4. reference to array containing status types for which sections
6459: should be gathered (optional).
6460:
6461: If the third argument is undefined, sections are gathered for any role.
6462: If the fourth argument is undefined, sections are gathered for any status.
6463: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6464:
1.374 raeburn 6465: Returns section hash (keys are section IDs, values are
6466: number of users in each section), subject to the
1.419 raeburn 6467: optional roles filter, optional status filter
1.233 raeburn 6468:
6469: =cut
6470:
6471: ###############################################
6472: sub get_sections {
1.419 raeburn 6473: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6474: if (!defined($cdom) || !defined($cnum)) {
6475: my $cid = $env{'request.course.id'};
6476:
6477: return if (!defined($cid));
6478:
6479: $cdom = $env{'course.'.$cid.'.domain'};
6480: $cnum = $env{'course.'.$cid.'.num'};
6481: }
6482:
6483: my %sectioncount;
1.419 raeburn 6484: my $now = time;
1.240 albertel 6485:
1.366 albertel 6486: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6487: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6488: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6489: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6490: my $start_index = &Apache::loncoursedata::CL_START();
6491: my $end_index = &Apache::loncoursedata::CL_END();
6492: my $status;
1.366 albertel 6493: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6494: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6495: $data->[$status_index],
6496: $data->[$start_index],
6497: $data->[$end_index]);
6498: if ($stu_status eq 'Active') {
6499: $status = 'active';
6500: } elsif ($end < $now) {
6501: $status = 'previous';
6502: } elsif ($start > $now) {
6503: $status = 'future';
6504: }
6505: if ($section ne '-1' && $section !~ /^\s*$/) {
6506: if ((!defined($possible_status)) || (($status ne '') &&
6507: (grep/^\Q$status\E$/,@{$possible_status}))) {
6508: $sectioncount{$section}++;
6509: }
1.240 albertel 6510: }
6511: }
6512: }
6513: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6514: foreach my $user (sort(keys(%courseroles))) {
6515: if ($user !~ /^(\w{2})/) { next; }
6516: my ($role) = ($user =~ /^(\w{2})/);
6517: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6518: my ($section,$status);
1.240 albertel 6519: if ($role eq 'cr' &&
6520: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6521: $section=$1;
6522: }
6523: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6524: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6525: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6526: if ($end == -1 && $start == -1) {
6527: next; #deleted role
6528: }
6529: if (!defined($possible_status)) {
6530: $sectioncount{$section}++;
6531: } else {
6532: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6533: $status = 'active';
6534: } elsif ($end < $now) {
6535: $status = 'future';
6536: } elsif ($start > $now) {
6537: $status = 'previous';
6538: }
6539: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6540: $sectioncount{$section}++;
6541: }
6542: }
1.233 raeburn 6543: }
1.366 albertel 6544: return %sectioncount;
1.233 raeburn 6545: }
6546:
1.274 raeburn 6547: ###############################################
1.294 raeburn 6548:
6549: =pod
1.405 albertel 6550:
6551: =item * &get_course_users()
6552:
1.275 raeburn 6553: Retrieves usernames:domains for users in the specified course
6554: with specific role(s), and access status.
6555:
6556: Incoming parameters:
1.277 albertel 6557: 1. course domain
6558: 2. course number
6559: 3. access status: users must have - either active,
1.275 raeburn 6560: previous, future, or all.
1.277 albertel 6561: 4. reference to array of permissible roles
1.288 raeburn 6562: 5. reference to array of section restrictions (optional)
6563: 6. reference to results object (hash of hashes).
6564: 7. reference to optional userdata hash
1.609 raeburn 6565: 8. reference to optional statushash
1.630 raeburn 6566: 9. flag if privileged users (except those set to unhide in
6567: course settings) should be excluded
1.609 raeburn 6568: Keys of top level results hash are roles.
1.275 raeburn 6569: Keys of inner hashes are username:domain, with
6570: values set to access type.
1.288 raeburn 6571: Optional userdata hash returns an array with arguments in the
6572: same order as loncoursedata::get_classlist() for student data.
6573:
1.609 raeburn 6574: Optional statushash returns
6575:
1.288 raeburn 6576: Entries for end, start, section and status are blank because
6577: of the possibility of multiple values for non-student roles.
6578:
1.275 raeburn 6579: =cut
1.405 albertel 6580:
1.275 raeburn 6581: ###############################################
1.405 albertel 6582:
1.275 raeburn 6583: sub get_course_users {
1.630 raeburn 6584: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6585: my %idx = ();
1.419 raeburn 6586: my %seclists;
1.288 raeburn 6587:
6588: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6589: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6590: $idx{end} = &Apache::loncoursedata::CL_END();
6591: $idx{start} = &Apache::loncoursedata::CL_START();
6592: $idx{id} = &Apache::loncoursedata::CL_ID();
6593: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6594: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6595: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6596:
1.290 albertel 6597: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6598: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6599: my $now = time;
1.277 albertel 6600: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6601: my $match = 0;
1.412 raeburn 6602: my $secmatch = 0;
1.419 raeburn 6603: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6604: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6605: if ($section eq '') {
6606: $section = 'none';
6607: }
1.291 albertel 6608: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6609: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6610: $secmatch = 1;
6611: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6612: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6613: $secmatch = 1;
6614: }
6615: } else {
1.419 raeburn 6616: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6617: $secmatch = 1;
6618: }
1.290 albertel 6619: }
1.412 raeburn 6620: if (!$secmatch) {
6621: next;
6622: }
1.419 raeburn 6623: }
1.275 raeburn 6624: if (defined($$types{'active'})) {
1.288 raeburn 6625: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6626: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6627: $match = 1;
1.275 raeburn 6628: }
6629: }
6630: if (defined($$types{'previous'})) {
1.609 raeburn 6631: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6632: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6633: $match = 1;
1.275 raeburn 6634: }
6635: }
6636: if (defined($$types{'future'})) {
1.609 raeburn 6637: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6638: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6639: $match = 1;
1.275 raeburn 6640: }
6641: }
1.609 raeburn 6642: if ($match) {
6643: push(@{$seclists{$student}},$section);
6644: if (ref($userdata) eq 'HASH') {
6645: $$userdata{$student} = $$classlist{$student};
6646: }
6647: if (ref($statushash) eq 'HASH') {
6648: $statushash->{$student}{'st'}{$section} = $status;
6649: }
1.288 raeburn 6650: }
1.275 raeburn 6651: }
6652: }
1.412 raeburn 6653: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6654: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6655: my $now = time;
1.609 raeburn 6656: my %displaystatus = ( previous => 'Expired',
6657: active => 'Active',
6658: future => 'Future',
6659: );
1.630 raeburn 6660: my %nothide;
6661: if ($hidepriv) {
6662: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6663: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6664: if ($user !~ /:/) {
6665: $nothide{join(':',split(/[\@]/,$user))}=1;
6666: } else {
6667: $nothide{$user} = 1;
6668: }
6669: }
6670: }
1.439 raeburn 6671: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6672: my $match = 0;
1.412 raeburn 6673: my $secmatch = 0;
1.439 raeburn 6674: my $status;
1.412 raeburn 6675: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6676: $user =~ s/:$//;
1.439 raeburn 6677: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6678: if ($end == -1 || $start == -1) {
6679: next;
6680: }
6681: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6682: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6683: my ($uname,$udom) = split(/:/,$user);
6684: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6685: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6686: $secmatch = 1;
6687: } elsif ($usec eq '') {
1.420 albertel 6688: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6689: $secmatch = 1;
6690: }
6691: } else {
6692: if (grep(/^\Q$usec\E$/,@{$sections})) {
6693: $secmatch = 1;
6694: }
6695: }
6696: if (!$secmatch) {
6697: next;
6698: }
1.288 raeburn 6699: }
1.419 raeburn 6700: if ($usec eq '') {
6701: $usec = 'none';
6702: }
1.275 raeburn 6703: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6704: if ($hidepriv) {
6705: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6706: (!$nothide{$uname.':'.$udom})) {
6707: next;
6708: }
6709: }
1.503 raeburn 6710: if ($end > 0 && $end < $now) {
1.439 raeburn 6711: $status = 'previous';
6712: } elsif ($start > $now) {
6713: $status = 'future';
6714: } else {
6715: $status = 'active';
6716: }
1.277 albertel 6717: foreach my $type (keys(%{$types})) {
1.275 raeburn 6718: if ($status eq $type) {
1.420 albertel 6719: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6720: push(@{$$users{$role}{$user}},$type);
6721: }
1.288 raeburn 6722: $match = 1;
6723: }
6724: }
1.419 raeburn 6725: if (($match) && (ref($userdata) eq 'HASH')) {
6726: if (!exists($$userdata{$uname.':'.$udom})) {
6727: &get_user_info($udom,$uname,\%idx,$userdata);
6728: }
1.420 albertel 6729: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6730: push(@{$seclists{$uname.':'.$udom}},$usec);
6731: }
1.609 raeburn 6732: if (ref($statushash) eq 'HASH') {
6733: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6734: }
1.275 raeburn 6735: }
6736: }
6737: }
6738: }
1.290 albertel 6739: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6740: if ((defined($cdom)) && (defined($cnum))) {
6741: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6742: if ( defined($csettings{'internal.courseowner'}) ) {
6743: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6744: next if ($owner eq '');
6745: my ($ownername,$ownerdom);
6746: if ($owner =~ /^([^:]+):([^:]+)$/) {
6747: $ownername = $1;
6748: $ownerdom = $2;
6749: } else {
6750: $ownername = $owner;
6751: $ownerdom = $cdom;
6752: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6753: }
6754: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6755: if (defined($userdata) &&
1.609 raeburn 6756: !exists($$userdata{$owner})) {
6757: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6758: if (!grep(/^none$/,@{$seclists{$owner}})) {
6759: push(@{$seclists{$owner}},'none');
6760: }
6761: if (ref($statushash) eq 'HASH') {
6762: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6763: }
1.290 albertel 6764: }
1.279 raeburn 6765: }
6766: }
6767: }
1.419 raeburn 6768: foreach my $user (keys(%seclists)) {
6769: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6770: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6771: }
1.275 raeburn 6772: }
6773: return;
6774: }
6775:
1.288 raeburn 6776: sub get_user_info {
6777: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6778: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6779: &plainname($uname,$udom,'lastname');
1.291 albertel 6780: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6781: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6782: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6783: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6784: return;
6785: }
1.275 raeburn 6786:
1.472 raeburn 6787: ###############################################
6788:
6789: =pod
6790:
6791: =item * &get_user_quota()
6792:
6793: Retrieves quota assigned for storage of portfolio files for a user
6794:
6795: Incoming parameters:
6796: 1. user's username
6797: 2. user's domain
6798:
6799: Returns:
1.536 raeburn 6800: 1. Disk quota (in Mb) assigned to student.
6801: 2. (Optional) Type of setting: custom or default
6802: (individually assigned or default for user's
6803: institutional status).
6804: 3. (Optional) - User's institutional status (e.g., faculty, staff
6805: or student - types as defined in localenroll::inst_usertypes
6806: for user's domain, which determines default quota for user.
6807: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6808:
6809: If a value has been stored in the user's environment,
1.536 raeburn 6810: it will return that, otherwise it returns the maximal default
6811: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6812:
6813: =cut
6814:
6815: ###############################################
6816:
6817:
6818: sub get_user_quota {
6819: my ($uname,$udom) = @_;
1.536 raeburn 6820: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6821: if (!defined($udom)) {
6822: $udom = $env{'user.domain'};
6823: }
6824: if (!defined($uname)) {
6825: $uname = $env{'user.name'};
6826: }
6827: if (($udom eq '' || $uname eq '') ||
6828: ($udom eq 'public') && ($uname eq 'public')) {
6829: $quota = 0;
1.536 raeburn 6830: $quotatype = 'default';
6831: $defquota = 0;
1.472 raeburn 6832: } else {
1.536 raeburn 6833: my $inststatus;
1.472 raeburn 6834: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6835: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6836: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6837: } else {
1.536 raeburn 6838: my %userenv =
6839: &Apache::lonnet::get('environment',['portfolioquota',
6840: 'inststatus'],$udom,$uname);
1.472 raeburn 6841: my ($tmp) = keys(%userenv);
6842: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6843: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6844: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6845: } else {
6846: undef(%userenv);
6847: }
6848: }
1.536 raeburn 6849: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6850: if ($quota eq '') {
1.536 raeburn 6851: $quota = $defquota;
6852: $quotatype = 'default';
6853: } else {
6854: $quotatype = 'custom';
1.472 raeburn 6855: }
6856: }
1.536 raeburn 6857: if (wantarray) {
6858: return ($quota,$quotatype,$settingstatus,$defquota);
6859: } else {
6860: return $quota;
6861: }
1.472 raeburn 6862: }
6863:
6864: ###############################################
6865:
6866: =pod
6867:
6868: =item * &default_quota()
6869:
1.536 raeburn 6870: Retrieves default quota assigned for storage of user portfolio files,
6871: given an (optional) user's institutional status.
1.472 raeburn 6872:
6873: Incoming parameters:
6874: 1. domain
1.536 raeburn 6875: 2. (Optional) institutional status(es). This is a : separated list of
6876: status types (e.g., faculty, staff, student etc.)
6877: which apply to the user for whom the default is being retrieved.
6878: If the institutional status string in undefined, the domain
6879: default quota will be returned.
1.472 raeburn 6880:
6881: Returns:
6882: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6883: 2. (Optional) institutional type which determined the value of the
6884: default quota.
1.472 raeburn 6885:
6886: If a value has been stored in the domain's configuration db,
6887: it will return that, otherwise it returns 20 (for backwards
6888: compatibility with domains which have not set up a configuration
6889: db file; the original statically defined portfolio quota was 20 Mb).
6890:
1.536 raeburn 6891: If the user's status includes multiple types (e.g., staff and student),
6892: the largest default quota which applies to the user determines the
6893: default quota returned.
6894:
1.472 raeburn 6895: =cut
6896:
6897: ###############################################
6898:
6899:
6900: sub default_quota {
1.536 raeburn 6901: my ($udom,$inststatus) = @_;
6902: my ($defquota,$settingstatus);
6903: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6904: ['quotas'],$udom);
6905: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6906: if ($inststatus ne '') {
6907: my @statuses = split(/:/,$inststatus);
6908: foreach my $item (@statuses) {
1.711 raeburn 6909: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6910: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
6911: if ($defquota eq '') {
6912: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6913: $settingstatus = $item;
6914: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
6915: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
6916: $settingstatus = $item;
6917: }
6918: }
6919: } else {
6920: if ($quotahash{'quotas'}{$item} ne '') {
6921: if ($defquota eq '') {
6922: $defquota = $quotahash{'quotas'}{$item};
6923: $settingstatus = $item;
6924: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6925: $defquota = $quotahash{'quotas'}{$item};
6926: $settingstatus = $item;
6927: }
1.536 raeburn 6928: }
6929: }
6930: }
6931: }
6932: if ($defquota eq '') {
1.711 raeburn 6933: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
6934: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
6935: } else {
6936: $defquota = $quotahash{'quotas'}{'default'};
6937: }
1.536 raeburn 6938: $settingstatus = 'default';
6939: }
6940: } else {
6941: $settingstatus = 'default';
6942: $defquota = 20;
6943: }
6944: if (wantarray) {
6945: return ($defquota,$settingstatus);
1.472 raeburn 6946: } else {
1.536 raeburn 6947: return $defquota;
1.472 raeburn 6948: }
6949: }
6950:
1.384 raeburn 6951: sub get_secgrprole_info {
6952: my ($cdom,$cnum,$needroles,$type) = @_;
6953: my %sections_count = &get_sections($cdom,$cnum);
6954: my @sections = (sort {$a <=> $b} keys(%sections_count));
6955: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6956: my @groups = sort(keys(%curr_groups));
6957: my $allroles = [];
6958: my $rolehash;
6959: my $accesshash = {
6960: active => 'Currently has access',
6961: future => 'Will have future access',
6962: previous => 'Previously had access',
6963: };
6964: if ($needroles) {
6965: $rolehash = {'all' => 'all'};
1.385 albertel 6966: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6967: if (&Apache::lonnet::error(%user_roles)) {
6968: undef(%user_roles);
6969: }
6970: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6971: my ($role)=split(/\:/,$item,2);
6972: if ($role eq 'cr') { next; }
6973: if ($role =~ /^cr/) {
6974: $$rolehash{$role} = (split('/',$role))[3];
6975: } else {
6976: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6977: }
6978: }
6979: foreach my $key (sort(keys(%{$rolehash}))) {
6980: push(@{$allroles},$key);
6981: }
6982: push (@{$allroles},'st');
6983: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6984: }
6985: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6986: }
6987:
1.555 raeburn 6988: sub user_picker {
1.627 raeburn 6989: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6990: my $currdom = $dom;
6991: my %curr_selected = (
6992: srchin => 'dom',
1.580 raeburn 6993: srchby => 'lastname',
1.555 raeburn 6994: );
6995: my $srchterm;
1.625 raeburn 6996: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6997: if ($srch->{'srchby'} ne '') {
6998: $curr_selected{'srchby'} = $srch->{'srchby'};
6999: }
7000: if ($srch->{'srchin'} ne '') {
7001: $curr_selected{'srchin'} = $srch->{'srchin'};
7002: }
7003: if ($srch->{'srchtype'} ne '') {
7004: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7005: }
7006: if ($srch->{'srchdomain'} ne '') {
7007: $currdom = $srch->{'srchdomain'};
7008: }
7009: $srchterm = $srch->{'srchterm'};
7010: }
7011: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7012: 'usr' => 'Search criteria',
1.563 raeburn 7013: 'doma' => 'Domain/institution to search',
1.558 albertel 7014: 'uname' => 'username',
7015: 'lastname' => 'last name',
1.555 raeburn 7016: 'lastfirst' => 'last name, first name',
1.558 albertel 7017: 'crs' => 'in this course',
1.576 raeburn 7018: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7019: 'alc' => 'all LON-CAPA',
1.573 raeburn 7020: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7021: 'exact' => 'is',
7022: 'contains' => 'contains',
1.569 raeburn 7023: 'begins' => 'begins with',
1.571 raeburn 7024: 'youm' => "You must include some text to search for.",
7025: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7026: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7027: 'yomc' => "You must choose a domain when using an institutional directory search.",
7028: 'ymcd' => "You must choose a domain when using a domain search.",
7029: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7030: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7031: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7032: );
1.563 raeburn 7033: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7034: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7035:
7036: my @srchins = ('crs','dom','alc','instd');
7037:
7038: foreach my $option (@srchins) {
7039: # FIXME 'alc' option unavailable until
7040: # loncreateuser::print_user_query_page()
7041: # has been completed.
7042: next if ($option eq 'alc');
7043: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7044: if ($curr_selected{'srchin'} eq $option) {
7045: $srchinsel .= '
7046: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7047: } else {
7048: $srchinsel .= '
7049: <option value="'.$option.'">'.$lt{$option}.'</option>';
7050: }
1.555 raeburn 7051: }
1.563 raeburn 7052: $srchinsel .= "\n </select>\n";
1.555 raeburn 7053:
7054: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7055: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7056: if ($curr_selected{'srchby'} eq $option) {
7057: $srchbysel .= '
7058: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7059: } else {
7060: $srchbysel .= '
7061: <option value="'.$option.'">'.$lt{$option}.'</option>';
7062: }
7063: }
7064: $srchbysel .= "\n </select>\n";
7065:
7066: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7067: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7068: if ($curr_selected{'srchtype'} eq $option) {
7069: $srchtypesel .= '
7070: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7071: } else {
7072: $srchtypesel .= '
7073: <option value="'.$option.'">'.$lt{$option}.'</option>';
7074: }
7075: }
7076: $srchtypesel .= "\n </select>\n";
7077:
1.558 albertel 7078: my ($newuserscript,$new_user_create);
1.556 raeburn 7079:
7080: if ($forcenewuser) {
1.576 raeburn 7081: if (ref($srch) eq 'HASH') {
7082: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7083: if ($cancreate) {
7084: $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>';
7085: } else {
7086: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7087: my %usertypetext = (
7088: official => 'institutional',
7089: unofficial => 'non-institutional',
7090: );
7091: $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 />';
7092: }
1.576 raeburn 7093: }
7094: }
7095:
1.556 raeburn 7096: $newuserscript = <<"ENDSCRIPT";
7097:
1.570 raeburn 7098: function setSearch(createnew,callingForm) {
1.556 raeburn 7099: if (createnew == 1) {
1.570 raeburn 7100: for (var i=0; i<callingForm.srchby.length; i++) {
7101: if (callingForm.srchby.options[i].value == 'uname') {
7102: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7103: }
7104: }
1.570 raeburn 7105: for (var i=0; i<callingForm.srchin.length; i++) {
7106: if ( callingForm.srchin.options[i].value == 'dom') {
7107: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7108: }
7109: }
1.570 raeburn 7110: for (var i=0; i<callingForm.srchtype.length; i++) {
7111: if (callingForm.srchtype.options[i].value == 'exact') {
7112: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7113: }
7114: }
1.570 raeburn 7115: for (var i=0; i<callingForm.srchdomain.length; i++) {
7116: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7117: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7118: }
7119: }
7120: }
7121: }
7122: ENDSCRIPT
1.558 albertel 7123:
1.556 raeburn 7124: }
7125:
1.555 raeburn 7126: my $output = <<"END_BLOCK";
1.556 raeburn 7127: <script type="text/javascript">
1.570 raeburn 7128: function validateEntry(callingForm) {
1.558 albertel 7129:
1.556 raeburn 7130: var checkok = 1;
1.558 albertel 7131: var srchin;
1.570 raeburn 7132: for (var i=0; i<callingForm.srchin.length; i++) {
7133: if ( callingForm.srchin[i].checked ) {
7134: srchin = callingForm.srchin[i].value;
1.558 albertel 7135: }
7136: }
7137:
1.570 raeburn 7138: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7139: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7140: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7141: var srchterm = callingForm.srchterm.value;
7142: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7143: var msg = "";
7144:
7145: if (srchterm == "") {
7146: checkok = 0;
1.571 raeburn 7147: msg += "$lt{'youm'}\\n";
1.556 raeburn 7148: }
7149:
1.569 raeburn 7150: if (srchtype== 'begins') {
7151: if (srchterm.length < 2) {
7152: checkok = 0;
1.571 raeburn 7153: msg += "$lt{'thte'}\\n";
1.569 raeburn 7154: }
7155: }
7156:
1.556 raeburn 7157: if (srchtype== 'contains') {
7158: if (srchterm.length < 3) {
7159: checkok = 0;
1.571 raeburn 7160: msg += "$lt{'thet'}\\n";
1.556 raeburn 7161: }
7162: }
7163: if (srchin == 'instd') {
7164: if (srchdomain == '') {
7165: checkok = 0;
1.571 raeburn 7166: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7167: }
7168: }
7169: if (srchin == 'dom') {
7170: if (srchdomain == '') {
7171: checkok = 0;
1.571 raeburn 7172: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7173: }
7174: }
7175: if (srchby == 'lastfirst') {
7176: if (srchterm.indexOf(",") == -1) {
7177: checkok = 0;
1.571 raeburn 7178: msg += "$lt{'whus'}\\n";
1.556 raeburn 7179: }
7180: if (srchterm.indexOf(",") == srchterm.length -1) {
7181: checkok = 0;
1.571 raeburn 7182: msg += "$lt{'whse'}\\n";
1.556 raeburn 7183: }
7184: }
7185: if (checkok == 0) {
1.571 raeburn 7186: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7187: return;
7188: }
7189: if (checkok == 1) {
1.570 raeburn 7190: callingForm.submit();
1.556 raeburn 7191: }
7192: }
7193:
7194: $newuserscript
7195:
7196: </script>
1.558 albertel 7197:
7198: $new_user_create
7199:
1.555 raeburn 7200: <table>
1.558 albertel 7201: <tr>
1.573 raeburn 7202: <td>$lt{'doma'}:</td>
7203: <td>$domform</td>
7204: </td>
7205: </tr>
7206: <tr>
7207: <td>$lt{'usr'}:</td>
1.563 raeburn 7208: <td>$srchbysel
7209: $srchtypesel
7210: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7211: $srchinsel
1.563 raeburn 7212: </td>
7213: </tr>
1.555 raeburn 7214: </table>
7215: <br />
7216: END_BLOCK
1.558 albertel 7217:
1.555 raeburn 7218: return $output;
7219: }
7220:
1.612 raeburn 7221: sub user_rule_check {
1.615 raeburn 7222: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7223: my $response;
7224: if (ref($usershash) eq 'HASH') {
7225: foreach my $user (keys(%{$usershash})) {
7226: my ($uname,$udom) = split(/:/,$user);
7227: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7228: my ($id,$newuser);
1.612 raeburn 7229: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7230: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7231: $id = $usershash->{$user}->{'id'};
7232: }
7233: my $inst_response;
7234: if (ref($checks) eq 'HASH') {
7235: if (defined($checks->{'username'})) {
1.615 raeburn 7236: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7237: &Apache::lonnet::get_instuser($udom,$uname);
7238: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7239: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7240: &Apache::lonnet::get_instuser($udom,undef,$id);
7241: }
1.615 raeburn 7242: } else {
7243: ($inst_response,%{$inst_results->{$user}}) =
7244: &Apache::lonnet::get_instuser($udom,$uname);
7245: return;
1.612 raeburn 7246: }
1.615 raeburn 7247: if (!$got_rules->{$udom}) {
1.612 raeburn 7248: my %domconfig = &Apache::lonnet::get_dom('configuration',
7249: ['usercreation'],$udom);
7250: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7251: foreach my $item ('username','id') {
1.612 raeburn 7252: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7253: $$curr_rules{$udom}{$item} =
7254: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7255: }
7256: }
7257: }
1.615 raeburn 7258: $got_rules->{$udom} = 1;
1.585 raeburn 7259: }
1.612 raeburn 7260: foreach my $item (keys(%{$checks})) {
7261: if (ref($$curr_rules{$udom}) eq 'HASH') {
7262: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7263: if (@{$$curr_rules{$udom}{$item}} > 0) {
7264: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7265: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7266: if ($rule_check{$rule}) {
7267: $$rulematch{$user}{$item} = $rule;
7268: if ($inst_response eq 'ok') {
1.615 raeburn 7269: if (ref($inst_results) eq 'HASH') {
7270: if (ref($inst_results->{$user}) eq 'HASH') {
7271: if (keys(%{$inst_results->{$user}}) == 0) {
7272: $$alerts{$item}{$udom}{$uname} = 1;
7273: }
1.612 raeburn 7274: }
7275: }
1.615 raeburn 7276: }
7277: last;
1.585 raeburn 7278: }
7279: }
7280: }
7281: }
7282: }
7283: }
7284: }
7285: }
1.612 raeburn 7286: return;
7287: }
7288:
7289: sub user_rule_formats {
7290: my ($domain,$domdesc,$curr_rules,$check) = @_;
7291: my %text = (
7292: 'username' => 'Usernames',
7293: 'id' => 'IDs',
7294: );
7295: my $output;
7296: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7297: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7298: if (@{$ruleorder} > 0) {
7299: $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>';
7300: foreach my $rule (@{$ruleorder}) {
7301: if (ref($curr_rules) eq 'ARRAY') {
7302: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7303: if (ref($rules->{$rule}) eq 'HASH') {
7304: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7305: $rules->{$rule}{'desc'}.'</li>';
7306: }
7307: }
7308: }
7309: }
7310: $output .= '</ul>';
7311: }
7312: }
7313: return $output;
7314: }
7315:
7316: sub instrule_disallow_msg {
1.615 raeburn 7317: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7318: my $response;
7319: my %text = (
7320: item => 'username',
7321: items => 'usernames',
7322: match => 'matches',
7323: do => 'does',
7324: action => 'a username',
7325: one => 'one',
7326: );
7327: if ($count > 1) {
7328: $text{'item'} = 'usernames';
7329: $text{'match'} ='match';
7330: $text{'do'} = 'do';
7331: $text{'action'} = 'usernames',
7332: $text{'one'} = 'ones';
7333: }
7334: if ($checkitem eq 'id') {
7335: $text{'items'} = 'IDs';
7336: $text{'item'} = 'ID';
7337: $text{'action'} = 'an ID';
1.615 raeburn 7338: if ($count > 1) {
7339: $text{'item'} = 'IDs';
7340: $text{'action'} = 'IDs';
7341: }
1.612 raeburn 7342: }
1.674 bisitz 7343: $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 7344: if ($mode eq 'upload') {
7345: if ($checkitem eq 'username') {
7346: $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'}.");
7347: } elsif ($checkitem eq 'id') {
1.674 bisitz 7348: $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 7349: }
1.669 raeburn 7350: } elsif ($mode eq 'selfcreate') {
7351: if ($checkitem eq 'id') {
7352: $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.");
7353: }
1.615 raeburn 7354: } else {
7355: if ($checkitem eq 'username') {
7356: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7357: } elsif ($checkitem eq 'id') {
7358: $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.");
7359: }
1.612 raeburn 7360: }
7361: return $response;
1.585 raeburn 7362: }
7363:
1.624 raeburn 7364: sub personal_data_fieldtitles {
7365: my %fieldtitles = &Apache::lonlocal::texthash (
7366: id => 'Student/Employee ID',
7367: permanentemail => 'E-mail address',
7368: lastname => 'Last Name',
7369: firstname => 'First Name',
7370: middlename => 'Middle Name',
7371: generation => 'Generation',
7372: gen => 'Generation',
7373: );
7374: return %fieldtitles;
7375: }
7376:
1.642 raeburn 7377: sub sorted_inst_types {
7378: my ($dom) = @_;
7379: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7380: my $othertitle = &mt('All users');
7381: if ($env{'request.course.id'}) {
1.668 raeburn 7382: $othertitle = &mt('Any users');
1.642 raeburn 7383: }
7384: my @types;
7385: if (ref($order) eq 'ARRAY') {
7386: @types = @{$order};
7387: }
7388: if (@types == 0) {
7389: if (ref($usertypes) eq 'HASH') {
7390: @types = sort(keys(%{$usertypes}));
7391: }
7392: }
7393: if (keys(%{$usertypes}) > 0) {
7394: $othertitle = &mt('Other users');
7395: }
7396: return ($othertitle,$usertypes,\@types);
7397: }
7398:
1.645 raeburn 7399: sub get_institutional_codes {
7400: my ($settings,$allcourses,$LC_code) = @_;
7401: # Get complete list of course sections to update
7402: my @currsections = ();
7403: my @currxlists = ();
7404: my $coursecode = $$settings{'internal.coursecode'};
7405:
7406: if ($$settings{'internal.sectionnums'} ne '') {
7407: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7408: }
7409:
7410: if ($$settings{'internal.crosslistings'} ne '') {
7411: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7412: }
7413:
7414: if (@currxlists > 0) {
7415: foreach (@currxlists) {
7416: if (m/^([^:]+):(\w*)$/) {
7417: unless (grep/^$1$/,@{$allcourses}) {
7418: push @{$allcourses},$1;
7419: $$LC_code{$1} = $2;
7420: }
7421: }
7422: }
7423: }
7424:
7425: if (@currsections > 0) {
7426: foreach (@currsections) {
7427: if (m/^(\w+):(\w*)$/) {
7428: my $sec = $coursecode.$1;
7429: my $lc_sec = $2;
7430: unless (grep/^$sec$/,@{$allcourses}) {
7431: push @{$allcourses},$sec;
7432: $$LC_code{$sec} = $lc_sec;
7433: }
7434: }
7435: }
7436: }
7437: return;
7438: }
7439:
1.112 bowersj2 7440: =pod
7441:
1.549 albertel 7442: =back
7443:
7444: =head1 HTTP Helpers
7445:
7446: =over 4
7447:
1.648 raeburn 7448: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7449:
1.258 albertel 7450: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7451: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7452: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7453:
7454: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7455: $possible_names is an ref to an array of form element names. As an example:
7456: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7457: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7458:
7459: =cut
1.1 albertel 7460:
1.6 albertel 7461: sub get_unprocessed_cgi {
1.25 albertel 7462: my ($query,$possible_names)= @_;
1.26 matthew 7463: # $Apache::lonxml::debug=1;
1.356 albertel 7464: foreach my $pair (split(/&/,$query)) {
7465: my ($name, $value) = split(/=/,$pair);
1.369 www 7466: $name = &unescape($name);
1.25 albertel 7467: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7468: $value =~ tr/+/ /;
7469: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7470: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7471: }
1.16 harris41 7472: }
1.6 albertel 7473: }
7474:
1.112 bowersj2 7475: =pod
7476:
1.648 raeburn 7477: =item * &cacheheader()
1.112 bowersj2 7478:
7479: returns cache-controlling header code
7480:
7481: =cut
7482:
1.7 albertel 7483: sub cacheheader {
1.258 albertel 7484: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7485: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7486: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7487: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7488: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7489: return $output;
1.7 albertel 7490: }
7491:
1.112 bowersj2 7492: =pod
7493:
1.648 raeburn 7494: =item * &no_cache($r)
1.112 bowersj2 7495:
7496: specifies header code to not have cache
7497:
7498: =cut
7499:
1.9 albertel 7500: sub no_cache {
1.216 albertel 7501: my ($r) = @_;
7502: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7503: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7504: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7505: $r->no_cache(1);
7506: $r->header_out("Expires" => $date);
7507: $r->header_out("Pragma" => "no-cache");
1.123 www 7508: }
7509:
7510: sub content_type {
1.181 albertel 7511: my ($r,$type,$charset) = @_;
1.299 foxr 7512: if ($r) {
7513: # Note that printout.pl calls this with undef for $r.
7514: &no_cache($r);
7515: }
1.258 albertel 7516: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7517: unless ($charset) {
7518: $charset=&Apache::lonlocal::current_encoding;
7519: }
7520: if ($charset) { $type.='; charset='.$charset; }
7521: if ($r) {
7522: $r->content_type($type);
7523: } else {
7524: print("Content-type: $type\n\n");
7525: }
1.9 albertel 7526: }
1.25 albertel 7527:
1.112 bowersj2 7528: =pod
7529:
1.648 raeburn 7530: =item * &add_to_env($name,$value)
1.112 bowersj2 7531:
1.258 albertel 7532: adds $name to the %env hash with value
1.112 bowersj2 7533: $value, if $name already exists, the entry is converted to an array
7534: reference and $value is added to the array.
7535:
7536: =cut
7537:
1.25 albertel 7538: sub add_to_env {
7539: my ($name,$value)=@_;
1.258 albertel 7540: if (defined($env{$name})) {
7541: if (ref($env{$name})) {
1.25 albertel 7542: #already have multiple values
1.258 albertel 7543: push(@{ $env{$name} },$value);
1.25 albertel 7544: } else {
7545: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7546: my $first=$env{$name};
7547: undef($env{$name});
7548: push(@{ $env{$name} },$first,$value);
1.25 albertel 7549: }
7550: } else {
1.258 albertel 7551: $env{$name}=$value;
1.25 albertel 7552: }
1.31 albertel 7553: }
1.149 albertel 7554:
7555: =pod
7556:
1.648 raeburn 7557: =item * &get_env_multiple($name)
1.149 albertel 7558:
1.258 albertel 7559: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7560: values may be defined and end up as an array ref.
7561:
7562: returns an array of values
7563:
7564: =cut
7565:
7566: sub get_env_multiple {
7567: my ($name) = @_;
7568: my @values;
1.258 albertel 7569: if (defined($env{$name})) {
1.149 albertel 7570: # exists is it an array
1.258 albertel 7571: if (ref($env{$name})) {
7572: @values=@{ $env{$name} };
1.149 albertel 7573: } else {
1.258 albertel 7574: $values[0]=$env{$name};
1.149 albertel 7575: }
7576: }
7577: return(@values);
7578: }
7579:
1.660 raeburn 7580: sub ask_for_embedded_content {
7581: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7582: my $upload_output = '
7583: <form name="upload_embedded" action="'.$actionurl.'"
7584: method="post" enctype="multipart/form-data">';
7585: $upload_output .= $state;
1.661 raeburn 7586: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7587:
7588: my $num = 0;
7589: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7590: $upload_output .= &start_data_table_row().
7591: '<td>'.$embed_file.'</td><td>';
7592: if ($args->{'ignore_remote_references'}
7593: && $embed_file =~ m{^\w+://}) {
7594: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7595: } elsif ($args->{'error_on_invalid_names'}
7596: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7597:
7598: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7599:
7600: } else {
7601: $upload_output .='
1.661 raeburn 7602: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7603: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7604: my $attrib = join(':',@{$$allfiles{$embed_file}});
7605: $upload_output .=
7606: "\n\t\t".
7607: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7608: $attrib.'" />';
7609: if (exists($$codebase{$embed_file})) {
7610: $upload_output .=
7611: "\n\t\t".
7612: '<input name="codebase_'.$num.'" type="hidden" value="'.
7613: &escape($$codebase{$embed_file}).'" />';
7614: }
7615: }
7616: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7617: $num++;
7618: }
7619: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7620: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7621: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7622: '.&mt('(only files for which a location has been provided will be uploaded)').'
7623: </form>';
7624: return $upload_output;
7625: }
7626:
1.661 raeburn 7627: sub upload_embedded {
7628: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7629: $current_disk_usage) = @_;
7630: my $output;
7631: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7632: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7633: my $orig_uploaded_filename =
7634: $env{'form.embedded_item_'.$i.'.filename'};
7635:
7636: $env{'form.embedded_orig_'.$i} =
7637: &unescape($env{'form.embedded_orig_'.$i});
7638: my ($path,$fname) =
7639: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7640: # no path, whole string is fname
7641: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7642:
7643: $path = $env{'form.currentpath'}.$path;
7644: $fname = &Apache::lonnet::clean_filename($fname);
7645: # See if there is anything left
7646: next if ($fname eq '');
7647:
7648: # Check if file already exists as a file or directory.
7649: my ($state,$msg);
7650: if ($context eq 'portfolio') {
7651: my $port_path = $dirpath;
7652: if ($group ne '') {
7653: $port_path = "groups/$group/$port_path";
7654: }
7655: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7656: $dir_root,$port_path,$disk_quota,
7657: $current_disk_usage,$uname,$udom);
7658: if ($state eq 'will_exceed_quota'
7659: || $state eq 'file_locked'
7660: || $state eq 'file_exists' ) {
7661: $output .= $msg;
7662: next;
7663: }
7664: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7665: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7666: if ($state eq 'exists') {
7667: $output .= $msg;
7668: next;
7669: }
7670: }
7671: # Check if extension is valid
7672: if (($fname =~ /\.(\w+)$/) &&
7673: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7674: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7675: next;
7676: } elsif (($fname =~ /\.(\w+)$/) &&
7677: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7678: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7679: next;
7680: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7681: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7682: next;
7683: }
7684:
7685: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7686: if ($context eq 'portfolio') {
7687: my $result=
7688: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7689: $dirpath.$path);
7690: if ($result !~ m|^/uploaded/|) {
7691: $output .= '<span class="LC_error">'
7692: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7693: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7694: .'</span><br />';
7695: next;
7696: } else {
7697: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7698: $path.$fname.'</span>').'</p>';
7699: }
7700: } else {
7701: # Save the file
7702: my $target = $env{'form.embedded_item_'.$i};
7703: my $fullpath = $dir_root.$dirpath.'/'.$path;
7704: my $dest = $fullpath.$fname;
7705: my $url = $url_root.$dirpath.'/'.$path.$fname;
7706: my @parts=split(/\//,$fullpath);
7707: my $count;
7708: my $filepath = $dir_root;
7709: for ($count=4;$count<=$#parts;$count++) {
7710: $filepath .= "/$parts[$count]";
7711: if ((-e $filepath)!=1) {
7712: mkdir($filepath,0770);
7713: }
7714: }
7715: my $fh;
7716: if (!open($fh,'>'.$dest)) {
7717: &Apache::lonnet::logthis('Failed to create '.$dest);
7718: $output .= '<span class="LC_error">'.
7719: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7720: '</span><br />';
7721: } else {
7722: if (!print $fh $env{'form.embedded_item_'.$i}) {
7723: &Apache::lonnet::logthis('Failed to write to '.$dest);
7724: $output .= '<span class="LC_error">'.
7725: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7726: '</span><br />';
7727: } else {
7728: if ($context eq 'testbank') {
7729: $output .= &mt('Embedded file uploaded successfully:').
7730: ' <a href="'.$url.'">'.
7731: $orig_uploaded_filename.'</a><br />';
7732: } else {
1.705 tempelho 7733: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 7734: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 7735: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 7736: }
7737: }
7738: close($fh);
7739: }
7740: }
7741: }
7742: return $output;
7743: }
7744:
7745: sub check_for_existing {
7746: my ($path,$fname,$element) = @_;
7747: my ($state,$msg);
7748: if (-d $path.'/'.$fname) {
7749: $state = 'exists';
7750: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7751: } elsif (-e $path.'/'.$fname) {
7752: $state = 'exists';
7753: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7754: }
7755: if ($state eq 'exists') {
7756: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7757: }
7758: return ($state,$msg);
7759: }
7760:
7761: sub check_for_upload {
7762: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7763: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7764: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7765: my $getpropath = 1;
7766: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7767: $getpropath);
7768: my $found_file = 0;
7769: my $locked_file = 0;
7770: foreach my $line (@dir_list) {
7771: my ($file_name)=split(/\&/,$line,2);
7772: if ($file_name eq $fname){
7773: $file_name = $path.$file_name;
7774: if ($group ne '') {
7775: $file_name = $group.$file_name;
7776: }
7777: $found_file = 1;
7778: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7779: $locked_file = 1;
7780: }
7781: }
7782: }
7783: if (($current_disk_usage + $filesize) > $disk_quota){
7784: my $msg = '<span class="LC_error">'.
7785: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7786: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7787: return ('will_exceed_quota',$msg);
7788: } elsif ($found_file) {
7789: if ($locked_file) {
7790: my $msg = '<span class="LC_error">';
7791: $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>');
7792: $msg .= '</span><br />';
7793: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7794: return ('file_locked',$msg);
7795: } else {
7796: my $msg = '<span class="LC_error">';
7797: $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'});
7798: $msg .= '</span>';
7799: $msg .= '<br />';
7800: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7801: return ('file_exists',$msg);
7802: }
7803: }
7804: }
7805:
1.31 albertel 7806:
1.41 ng 7807: =pod
1.45 matthew 7808:
1.464 albertel 7809: =back
1.41 ng 7810:
1.112 bowersj2 7811: =head1 CSV Upload/Handling functions
1.38 albertel 7812:
1.41 ng 7813: =over 4
7814:
1.648 raeburn 7815: =item * &upfile_store($r)
1.41 ng 7816:
7817: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7818: needs $env{'form.upfile'}
1.41 ng 7819: returns $datatoken to be put into hidden field
7820:
7821: =cut
1.31 albertel 7822:
7823: sub upfile_store {
7824: my $r=shift;
1.258 albertel 7825: $env{'form.upfile'}=~s/\r/\n/gs;
7826: $env{'form.upfile'}=~s/\f/\n/gs;
7827: $env{'form.upfile'}=~s/\n+/\n/gs;
7828: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7829:
1.258 albertel 7830: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7831: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7832: {
1.158 raeburn 7833: my $datafile = $r->dir_config('lonDaemons').
7834: '/tmp/'.$datatoken.'.tmp';
7835: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7836: print $fh $env{'form.upfile'};
1.158 raeburn 7837: close($fh);
7838: }
1.31 albertel 7839: }
7840: return $datatoken;
7841: }
7842:
1.56 matthew 7843: =pod
7844:
1.648 raeburn 7845: =item * &load_tmp_file($r)
1.41 ng 7846:
7847: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7848: needs $env{'form.datatoken'},
7849: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7850:
7851: =cut
1.31 albertel 7852:
7853: sub load_tmp_file {
7854: my $r=shift;
7855: my @studentdata=();
7856: {
1.158 raeburn 7857: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7858: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7859: if ( open(my $fh,"<$studentfile") ) {
7860: @studentdata=<$fh>;
7861: close($fh);
7862: }
1.31 albertel 7863: }
1.258 albertel 7864: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7865: }
7866:
1.56 matthew 7867: =pod
7868:
1.648 raeburn 7869: =item * &upfile_record_sep()
1.41 ng 7870:
7871: Separate uploaded file into records
7872: returns array of records,
1.258 albertel 7873: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7874:
7875: =cut
1.31 albertel 7876:
7877: sub upfile_record_sep {
1.258 albertel 7878: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7879: } else {
1.248 albertel 7880: my @records;
1.258 albertel 7881: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7882: if ($line=~/^\s*$/) { next; }
7883: push(@records,$line);
7884: }
7885: return @records;
1.31 albertel 7886: }
7887: }
7888:
1.56 matthew 7889: =pod
7890:
1.648 raeburn 7891: =item * &record_sep($record)
1.41 ng 7892:
1.258 albertel 7893: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7894:
7895: =cut
7896:
1.263 www 7897: sub takeleft {
7898: my $index=shift;
7899: return substr('0000'.$index,-4,4);
7900: }
7901:
1.31 albertel 7902: sub record_sep {
7903: my $record=shift;
7904: my %components=();
1.258 albertel 7905: if ($env{'form.upfiletype'} eq 'xml') {
7906: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7907: my $i=0;
1.356 albertel 7908: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7909: $field=~s/^(\"|\')//;
7910: $field=~s/(\"|\')$//;
1.263 www 7911: $components{&takeleft($i)}=$field;
1.31 albertel 7912: $i++;
7913: }
1.258 albertel 7914: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7915: my $i=0;
1.356 albertel 7916: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7917: $field=~s/^(\"|\')//;
7918: $field=~s/(\"|\')$//;
1.263 www 7919: $components{&takeleft($i)}=$field;
1.31 albertel 7920: $i++;
7921: }
7922: } else {
1.561 www 7923: my $separator=',';
1.480 banghart 7924: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7925: $separator=';';
1.480 banghart 7926: }
1.31 albertel 7927: my $i=0;
1.561 www 7928: # the character we are looking for to indicate the end of a quote or a record
7929: my $looking_for=$separator;
7930: # do not add the characters to the fields
7931: my $ignore=0;
7932: # we just encountered a separator (or the beginning of the record)
7933: my $just_found_separator=1;
7934: # store the field we are working on here
7935: my $field='';
7936: # work our way through all characters in record
7937: foreach my $character ($record=~/(.)/g) {
7938: if ($character eq $looking_for) {
7939: if ($character ne $separator) {
7940: # Found the end of a quote, again looking for separator
7941: $looking_for=$separator;
7942: $ignore=1;
7943: } else {
7944: # Found a separator, store away what we got
7945: $components{&takeleft($i)}=$field;
7946: $i++;
7947: $just_found_separator=1;
7948: $ignore=0;
7949: $field='';
7950: }
7951: next;
7952: }
7953: # single or double quotation marks after a separator indicate beginning of a quote
7954: # we are now looking for the end of the quote and need to ignore separators
7955: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7956: $looking_for=$character;
7957: next;
7958: }
7959: # ignore would be true after we reached the end of a quote
7960: if ($ignore) { next; }
7961: if (($just_found_separator) && ($character=~/\s/)) { next; }
7962: $field.=$character;
7963: $just_found_separator=0;
1.31 albertel 7964: }
1.561 www 7965: # catch the very last entry, since we never encountered the separator
7966: $components{&takeleft($i)}=$field;
1.31 albertel 7967: }
7968: return %components;
7969: }
7970:
1.144 matthew 7971: ######################################################
7972: ######################################################
7973:
1.56 matthew 7974: =pod
7975:
1.648 raeburn 7976: =item * &upfile_select_html()
1.41 ng 7977:
1.144 matthew 7978: Return HTML code to select a file from the users machine and specify
7979: the file type.
1.41 ng 7980:
7981: =cut
7982:
1.144 matthew 7983: ######################################################
7984: ######################################################
1.31 albertel 7985: sub upfile_select_html {
1.144 matthew 7986: my %Types = (
7987: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7988: semisv => &mt('Semicolon separated values'),
1.144 matthew 7989: space => &mt('Space separated'),
7990: tab => &mt('Tabulator separated'),
7991: # xml => &mt('HTML/XML'),
7992: );
7993: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 7994: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 7995: foreach my $type (sort(keys(%Types))) {
7996: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7997: }
7998: $Str .= "</select>\n";
7999: return $Str;
1.31 albertel 8000: }
8001:
1.301 albertel 8002: sub get_samples {
8003: my ($records,$toget) = @_;
8004: my @samples=({});
8005: my $got=0;
8006: foreach my $rec (@$records) {
8007: my %temp = &record_sep($rec);
8008: if (! grep(/\S/, values(%temp))) { next; }
8009: if (%temp) {
8010: $samples[$got]=\%temp;
8011: $got++;
8012: if ($got == $toget) { last; }
8013: }
8014: }
8015: return \@samples;
8016: }
8017:
1.144 matthew 8018: ######################################################
8019: ######################################################
8020:
1.56 matthew 8021: =pod
8022:
1.648 raeburn 8023: =item * &csv_print_samples($r,$records)
1.41 ng 8024:
8025: Prints a table of sample values from each column uploaded $r is an
8026: Apache Request ref, $records is an arrayref from
8027: &Apache::loncommon::upfile_record_sep
8028:
8029: =cut
8030:
1.144 matthew 8031: ######################################################
8032: ######################################################
1.31 albertel 8033: sub csv_print_samples {
8034: my ($r,$records) = @_;
1.662 bisitz 8035: my $samples = &get_samples($records,5);
1.301 albertel 8036:
1.594 raeburn 8037: $r->print(&mt('Samples').'<br />'.&start_data_table().
8038: &start_data_table_header_row());
1.356 albertel 8039: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8040: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8041: $r->print(&end_data_table_header_row());
1.301 albertel 8042: foreach my $hash (@$samples) {
1.594 raeburn 8043: $r->print(&start_data_table_row());
1.356 albertel 8044: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8045: $r->print('<td>');
1.356 albertel 8046: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8047: $r->print('</td>');
8048: }
1.594 raeburn 8049: $r->print(&end_data_table_row());
1.31 albertel 8050: }
1.594 raeburn 8051: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8052: }
8053:
1.144 matthew 8054: ######################################################
8055: ######################################################
8056:
1.56 matthew 8057: =pod
8058:
1.648 raeburn 8059: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8060:
8061: Prints a table to create associations between values and table columns.
1.144 matthew 8062:
1.41 ng 8063: $r is an Apache Request ref,
8064: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8065: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8066:
8067: =cut
8068:
1.144 matthew 8069: ######################################################
8070: ######################################################
1.31 albertel 8071: sub csv_print_select_table {
8072: my ($r,$records,$d) = @_;
1.301 albertel 8073: my $i=0;
8074: my $samples = &get_samples($records,1);
1.144 matthew 8075: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8076: &start_data_table().&start_data_table_header_row().
1.144 matthew 8077: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8078: '<th>'.&mt('Column').'</th>'.
8079: &end_data_table_header_row()."\n");
1.356 albertel 8080: foreach my $array_ref (@$d) {
8081: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8082: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8083:
8084: $r->print('<td><select name=f'.$i.
1.32 matthew 8085: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8086: $r->print('<option value="none"></option>');
1.356 albertel 8087: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8088: $r->print('<option value="'.$sample.'"'.
8089: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8090: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8091: }
1.594 raeburn 8092: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8093: $i++;
8094: }
1.594 raeburn 8095: $r->print(&end_data_table());
1.31 albertel 8096: $i--;
8097: return $i;
8098: }
1.56 matthew 8099:
1.144 matthew 8100: ######################################################
8101: ######################################################
8102:
1.56 matthew 8103: =pod
1.31 albertel 8104:
1.648 raeburn 8105: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8106:
8107: Prints a table of sample values from the upload and can make associate samples to internal names.
8108:
8109: $r is an Apache Request ref,
8110: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8111: $d is an array of 2 element arrays (internal name, displayed name)
8112:
8113: =cut
8114:
1.144 matthew 8115: ######################################################
8116: ######################################################
1.31 albertel 8117: sub csv_samples_select_table {
8118: my ($r,$records,$d) = @_;
8119: my $i=0;
1.144 matthew 8120: #
1.662 bisitz 8121: my $max_samples = 5;
8122: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8123: $r->print(&start_data_table().
8124: &start_data_table_header_row().'<th>'.
8125: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8126: &end_data_table_header_row());
1.301 albertel 8127:
8128: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8129: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8130: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8131: foreach my $option (@$d) {
8132: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8133: $r->print('<option value="'.$value.'"'.
1.253 albertel 8134: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8135: $display.'</option>');
1.31 albertel 8136: }
8137: $r->print('</select></td><td>');
1.662 bisitz 8138: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8139: if (defined($samples->[$line]{$key})) {
8140: $r->print($samples->[$line]{$key}."<br />\n");
8141: }
8142: }
1.594 raeburn 8143: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8144: $i++;
8145: }
1.594 raeburn 8146: $r->print(&end_data_table());
1.31 albertel 8147: $i--;
8148: return($i);
1.115 matthew 8149: }
8150:
1.144 matthew 8151: ######################################################
8152: ######################################################
8153:
1.115 matthew 8154: =pod
8155:
1.648 raeburn 8156: =item * &clean_excel_name($name)
1.115 matthew 8157:
8158: Returns a replacement for $name which does not contain any illegal characters.
8159:
8160: =cut
8161:
1.144 matthew 8162: ######################################################
8163: ######################################################
1.115 matthew 8164: sub clean_excel_name {
8165: my ($name) = @_;
8166: $name =~ s/[:\*\?\/\\]//g;
8167: if (length($name) > 31) {
8168: $name = substr($name,0,31);
8169: }
8170: return $name;
1.25 albertel 8171: }
1.84 albertel 8172:
1.85 albertel 8173: =pod
8174:
1.648 raeburn 8175: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8176:
8177: Returns either 1 or undef
8178:
8179: 1 if the part is to be hidden, undef if it is to be shown
8180:
8181: Arguments are:
8182:
8183: $id the id of the part to be checked
8184: $symb, optional the symb of the resource to check
8185: $udom, optional the domain of the user to check for
8186: $uname, optional the username of the user to check for
8187:
8188: =cut
1.84 albertel 8189:
8190: sub check_if_partid_hidden {
8191: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8192: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8193: $symb,$udom,$uname);
1.141 albertel 8194: my $truth=1;
8195: #if the string starts with !, then the list is the list to show not hide
8196: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8197: my @hiddenlist=split(/,/,$hiddenparts);
8198: foreach my $checkid (@hiddenlist) {
1.141 albertel 8199: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8200: }
1.141 albertel 8201: return !$truth;
1.84 albertel 8202: }
1.127 matthew 8203:
1.138 matthew 8204:
8205: ############################################################
8206: ############################################################
8207:
8208: =pod
8209:
1.157 matthew 8210: =back
8211:
1.138 matthew 8212: =head1 cgi-bin script and graphing routines
8213:
1.157 matthew 8214: =over 4
8215:
1.648 raeburn 8216: =item * &get_cgi_id()
1.138 matthew 8217:
8218: Inputs: none
8219:
8220: Returns an id which can be used to pass environment variables
8221: to various cgi-bin scripts. These environment variables will
8222: be removed from the users environment after a given time by
8223: the routine &Apache::lonnet::transfer_profile_to_env.
8224:
8225: =cut
8226:
8227: ############################################################
8228: ############################################################
1.152 albertel 8229: my $uniq=0;
1.136 matthew 8230: sub get_cgi_id {
1.154 albertel 8231: $uniq=($uniq+1)%100000;
1.280 albertel 8232: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8233: }
8234:
1.127 matthew 8235: ############################################################
8236: ############################################################
8237:
8238: =pod
8239:
1.648 raeburn 8240: =item * &DrawBarGraph()
1.127 matthew 8241:
1.138 matthew 8242: Facilitates the plotting of data in a (stacked) bar graph.
8243: Puts plot definition data into the users environment in order for
8244: graph.png to plot it. Returns an <img> tag for the plot.
8245: The bars on the plot are labeled '1','2',...,'n'.
8246:
8247: Inputs:
8248:
8249: =over 4
8250:
8251: =item $Title: string, the title of the plot
8252:
8253: =item $xlabel: string, text describing the X-axis of the plot
8254:
8255: =item $ylabel: string, text describing the Y-axis of the plot
8256:
8257: =item $Max: scalar, the maximum Y value to use in the plot
8258: If $Max is < any data point, the graph will not be rendered.
8259:
1.140 matthew 8260: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8261: they are plotted. If undefined, default values will be used.
8262:
1.178 matthew 8263: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8264:
1.138 matthew 8265: =item @Values: An array of array references. Each array reference holds data
8266: to be plotted in a stacked bar chart.
8267:
1.239 matthew 8268: =item If the final element of @Values is a hash reference the key/value
8269: pairs will be added to the graph definition.
8270:
1.138 matthew 8271: =back
8272:
8273: Returns:
8274:
8275: An <img> tag which references graph.png and the appropriate identifying
8276: information for the plot.
8277:
1.127 matthew 8278: =cut
8279:
8280: ############################################################
8281: ############################################################
1.134 matthew 8282: sub DrawBarGraph {
1.178 matthew 8283: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8284: #
8285: if (! defined($colors)) {
8286: $colors = ['#33ff00',
8287: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8288: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8289: ];
8290: }
1.228 matthew 8291: my $extra_settings = {};
8292: if (ref($Values[-1]) eq 'HASH') {
8293: $extra_settings = pop(@Values);
8294: }
1.127 matthew 8295: #
1.136 matthew 8296: my $identifier = &get_cgi_id();
8297: my $id = 'cgi.'.$identifier;
1.129 matthew 8298: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8299: return '';
8300: }
1.225 matthew 8301: #
8302: my @Labels;
8303: if (defined($labels)) {
8304: @Labels = @$labels;
8305: } else {
8306: for (my $i=0;$i<@{$Values[0]};$i++) {
8307: push (@Labels,$i+1);
8308: }
8309: }
8310: #
1.129 matthew 8311: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8312: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8313: my %ValuesHash;
8314: my $NumSets=1;
8315: foreach my $array (@Values) {
8316: next if (! ref($array));
1.136 matthew 8317: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8318: join(',',@$array);
1.129 matthew 8319: }
1.127 matthew 8320: #
1.136 matthew 8321: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8322: if ($NumBars < 3) {
8323: $width = 120+$NumBars*32;
1.220 matthew 8324: $xskip = 1;
1.225 matthew 8325: $bar_width = 30;
8326: } elsif ($NumBars < 5) {
8327: $width = 120+$NumBars*20;
8328: $xskip = 1;
8329: $bar_width = 20;
1.220 matthew 8330: } elsif ($NumBars < 10) {
1.136 matthew 8331: $width = 120+$NumBars*15;
8332: $xskip = 1;
8333: $bar_width = 15;
8334: } elsif ($NumBars <= 25) {
8335: $width = 120+$NumBars*11;
8336: $xskip = 5;
8337: $bar_width = 8;
8338: } elsif ($NumBars <= 50) {
8339: $width = 120+$NumBars*8;
8340: $xskip = 5;
8341: $bar_width = 4;
8342: } else {
8343: $width = 120+$NumBars*8;
8344: $xskip = 5;
8345: $bar_width = 4;
8346: }
8347: #
1.137 matthew 8348: $Max = 1 if ($Max < 1);
8349: if ( int($Max) < $Max ) {
8350: $Max++;
8351: $Max = int($Max);
8352: }
1.127 matthew 8353: $Title = '' if (! defined($Title));
8354: $xlabel = '' if (! defined($xlabel));
8355: $ylabel = '' if (! defined($ylabel));
1.369 www 8356: $ValuesHash{$id.'.title'} = &escape($Title);
8357: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8358: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8359: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8360: $ValuesHash{$id.'.NumBars'} = $NumBars;
8361: $ValuesHash{$id.'.NumSets'} = $NumSets;
8362: $ValuesHash{$id.'.PlotType'} = 'bar';
8363: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8364: $ValuesHash{$id.'.height'} = $height;
8365: $ValuesHash{$id.'.width'} = $width;
8366: $ValuesHash{$id.'.xskip'} = $xskip;
8367: $ValuesHash{$id.'.bar_width'} = $bar_width;
8368: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8369: #
1.228 matthew 8370: # Deal with other parameters
8371: while (my ($key,$value) = each(%$extra_settings)) {
8372: $ValuesHash{$id.'.'.$key} = $value;
8373: }
8374: #
1.646 raeburn 8375: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8376: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8377: }
8378:
8379: ############################################################
8380: ############################################################
8381:
8382: =pod
8383:
1.648 raeburn 8384: =item * &DrawXYGraph()
1.137 matthew 8385:
1.138 matthew 8386: Facilitates the plotting of data in an XY graph.
8387: Puts plot definition data into the users environment in order for
8388: graph.png to plot it. Returns an <img> tag for the plot.
8389:
8390: Inputs:
8391:
8392: =over 4
8393:
8394: =item $Title: string, the title of the plot
8395:
8396: =item $xlabel: string, text describing the X-axis of the plot
8397:
8398: =item $ylabel: string, text describing the Y-axis of the plot
8399:
8400: =item $Max: scalar, the maximum Y value to use in the plot
8401: If $Max is < any data point, the graph will not be rendered.
8402:
8403: =item $colors: Array ref containing the hex color codes for the data to be
8404: plotted in. If undefined, default values will be used.
8405:
8406: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8407:
8408: =item $Ydata: Array ref containing Array refs.
1.185 www 8409: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8410:
8411: =item %Values: hash indicating or overriding any default values which are
8412: passed to graph.png.
8413: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8414:
8415: =back
8416:
8417: Returns:
8418:
8419: An <img> tag which references graph.png and the appropriate identifying
8420: information for the plot.
8421:
1.137 matthew 8422: =cut
8423:
8424: ############################################################
8425: ############################################################
8426: sub DrawXYGraph {
8427: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8428: #
8429: # Create the identifier for the graph
8430: my $identifier = &get_cgi_id();
8431: my $id = 'cgi.'.$identifier;
8432: #
8433: $Title = '' if (! defined($Title));
8434: $xlabel = '' if (! defined($xlabel));
8435: $ylabel = '' if (! defined($ylabel));
8436: my %ValuesHash =
8437: (
1.369 www 8438: $id.'.title' => &escape($Title),
8439: $id.'.xlabel' => &escape($xlabel),
8440: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8441: $id.'.y_max_value'=> $Max,
8442: $id.'.labels' => join(',',@$Xlabels),
8443: $id.'.PlotType' => 'XY',
8444: );
8445: #
8446: if (defined($colors) && ref($colors) eq 'ARRAY') {
8447: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8448: }
8449: #
8450: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8451: return '';
8452: }
8453: my $NumSets=1;
1.138 matthew 8454: foreach my $array (@{$Ydata}){
1.137 matthew 8455: next if (! ref($array));
8456: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8457: }
1.138 matthew 8458: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8459: #
8460: # Deal with other parameters
8461: while (my ($key,$value) = each(%Values)) {
8462: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8463: }
8464: #
1.646 raeburn 8465: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8466: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8467: }
8468:
8469: ############################################################
8470: ############################################################
8471:
8472: =pod
8473:
1.648 raeburn 8474: =item * &DrawXYYGraph()
1.138 matthew 8475:
8476: Facilitates the plotting of data in an XY graph with two Y axes.
8477: Puts plot definition data into the users environment in order for
8478: graph.png to plot it. Returns an <img> tag for the plot.
8479:
8480: Inputs:
8481:
8482: =over 4
8483:
8484: =item $Title: string, the title of the plot
8485:
8486: =item $xlabel: string, text describing the X-axis of the plot
8487:
8488: =item $ylabel: string, text describing the Y-axis of the plot
8489:
8490: =item $colors: Array ref containing the hex color codes for the data to be
8491: plotted in. If undefined, default values will be used.
8492:
8493: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8494:
8495: =item $Ydata1: The first data set
8496:
8497: =item $Min1: The minimum value of the left Y-axis
8498:
8499: =item $Max1: The maximum value of the left Y-axis
8500:
8501: =item $Ydata2: The second data set
8502:
8503: =item $Min2: The minimum value of the right Y-axis
8504:
8505: =item $Max2: The maximum value of the left Y-axis
8506:
8507: =item %Values: hash indicating or overriding any default values which are
8508: passed to graph.png.
8509: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8510:
8511: =back
8512:
8513: Returns:
8514:
8515: An <img> tag which references graph.png and the appropriate identifying
8516: information for the plot.
1.136 matthew 8517:
8518: =cut
8519:
8520: ############################################################
8521: ############################################################
1.137 matthew 8522: sub DrawXYYGraph {
8523: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8524: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8525: #
8526: # Create the identifier for the graph
8527: my $identifier = &get_cgi_id();
8528: my $id = 'cgi.'.$identifier;
8529: #
8530: $Title = '' if (! defined($Title));
8531: $xlabel = '' if (! defined($xlabel));
8532: $ylabel = '' if (! defined($ylabel));
8533: my %ValuesHash =
8534: (
1.369 www 8535: $id.'.title' => &escape($Title),
8536: $id.'.xlabel' => &escape($xlabel),
8537: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8538: $id.'.labels' => join(',',@$Xlabels),
8539: $id.'.PlotType' => 'XY',
8540: $id.'.NumSets' => 2,
1.137 matthew 8541: $id.'.two_axes' => 1,
8542: $id.'.y1_max_value' => $Max1,
8543: $id.'.y1_min_value' => $Min1,
8544: $id.'.y2_max_value' => $Max2,
8545: $id.'.y2_min_value' => $Min2,
1.136 matthew 8546: );
8547: #
1.137 matthew 8548: if (defined($colors) && ref($colors) eq 'ARRAY') {
8549: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8550: }
8551: #
8552: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8553: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8554: return '';
8555: }
8556: my $NumSets=1;
1.137 matthew 8557: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8558: next if (! ref($array));
8559: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8560: }
8561: #
8562: # Deal with other parameters
8563: while (my ($key,$value) = each(%Values)) {
8564: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8565: }
8566: #
1.646 raeburn 8567: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8568: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8569: }
8570:
8571: ############################################################
8572: ############################################################
8573:
8574: =pod
8575:
1.157 matthew 8576: =back
8577:
1.139 matthew 8578: =head1 Statistics helper routines?
8579:
8580: Bad place for them but what the hell.
8581:
1.157 matthew 8582: =over 4
8583:
1.648 raeburn 8584: =item * &chartlink()
1.139 matthew 8585:
8586: Returns a link to the chart for a specific student.
8587:
8588: Inputs:
8589:
8590: =over 4
8591:
8592: =item $linktext: The text of the link
8593:
8594: =item $sname: The students username
8595:
8596: =item $sdomain: The students domain
8597:
8598: =back
8599:
1.157 matthew 8600: =back
8601:
1.139 matthew 8602: =cut
8603:
8604: ############################################################
8605: ############################################################
8606: sub chartlink {
8607: my ($linktext, $sname, $sdomain) = @_;
8608: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8609: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8610: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8611: '">'.$linktext.'</a>';
1.153 matthew 8612: }
8613:
8614: #######################################################
8615: #######################################################
8616:
8617: =pod
8618:
8619: =head1 Course Environment Routines
1.157 matthew 8620:
8621: =over 4
1.153 matthew 8622:
1.648 raeburn 8623: =item * &restore_course_settings()
1.153 matthew 8624:
1.648 raeburn 8625: =item * &store_course_settings()
1.153 matthew 8626:
8627: Restores/Store indicated form parameters from the course environment.
8628: Will not overwrite existing values of the form parameters.
8629:
8630: Inputs:
8631: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8632:
8633: a hash ref describing the data to be stored. For example:
8634:
8635: %Save_Parameters = ('Status' => 'scalar',
8636: 'chartoutputmode' => 'scalar',
8637: 'chartoutputdata' => 'scalar',
8638: 'Section' => 'array',
1.373 raeburn 8639: 'Group' => 'array',
1.153 matthew 8640: 'StudentData' => 'array',
8641: 'Maps' => 'array');
8642:
8643: Returns: both routines return nothing
8644:
1.631 raeburn 8645: =back
8646:
1.153 matthew 8647: =cut
8648:
8649: #######################################################
8650: #######################################################
8651: sub store_course_settings {
1.496 albertel 8652: return &store_settings($env{'request.course.id'},@_);
8653: }
8654:
8655: sub store_settings {
1.153 matthew 8656: # save to the environment
8657: # appenv the same items, just to be safe
1.300 albertel 8658: my $udom = $env{'user.domain'};
8659: my $uname = $env{'user.name'};
1.496 albertel 8660: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8661: my %SaveHash;
8662: my %AppHash;
8663: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8664: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8665: my $envname = 'environment.'.$basename;
1.258 albertel 8666: if (exists($env{'form.'.$setting})) {
1.153 matthew 8667: # Save this value away
8668: if ($type eq 'scalar' &&
1.258 albertel 8669: (! exists($env{$envname}) ||
8670: $env{$envname} ne $env{'form.'.$setting})) {
8671: $SaveHash{$basename} = $env{'form.'.$setting};
8672: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8673: } elsif ($type eq 'array') {
8674: my $stored_form;
1.258 albertel 8675: if (ref($env{'form.'.$setting})) {
1.153 matthew 8676: $stored_form = join(',',
8677: map {
1.369 www 8678: &escape($_);
1.258 albertel 8679: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8680: } else {
8681: $stored_form =
1.369 www 8682: &escape($env{'form.'.$setting});
1.153 matthew 8683: }
8684: # Determine if the array contents are the same.
1.258 albertel 8685: if ($stored_form ne $env{$envname}) {
1.153 matthew 8686: $SaveHash{$basename} = $stored_form;
8687: $AppHash{$envname} = $stored_form;
8688: }
8689: }
8690: }
8691: }
8692: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8693: $udom,$uname);
1.153 matthew 8694: if ($put_result !~ /^(ok|delayed)/) {
8695: &Apache::lonnet::logthis('unable to save form parameters, '.
8696: 'got error:'.$put_result);
8697: }
8698: # Make sure these settings stick around in this session, too
1.646 raeburn 8699: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8700: return;
8701: }
8702:
8703: sub restore_course_settings {
1.499 albertel 8704: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8705: }
8706:
8707: sub restore_settings {
8708: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8709: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8710: next if (exists($env{'form.'.$setting}));
1.496 albertel 8711: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8712: '.'.$setting;
1.258 albertel 8713: if (exists($env{$envname})) {
1.153 matthew 8714: if ($type eq 'scalar') {
1.258 albertel 8715: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8716: } elsif ($type eq 'array') {
1.258 albertel 8717: $env{'form.'.$setting} = [
1.153 matthew 8718: map {
1.369 www 8719: &unescape($_);
1.258 albertel 8720: } split(',',$env{$envname})
1.153 matthew 8721: ];
8722: }
8723: }
8724: }
1.127 matthew 8725: }
8726:
1.618 raeburn 8727: #######################################################
8728: #######################################################
8729:
8730: =pod
8731:
8732: =head1 Domain E-mail Routines
8733:
8734: =over 4
8735:
1.648 raeburn 8736: =item * &build_recipient_list()
1.618 raeburn 8737:
8738: Build recipient lists for three types of e-mail:
8739: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8740: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8741:
8742: Inputs:
1.619 raeburn 8743: defmail (scalar - email address of default recipient),
1.618 raeburn 8744: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8745: defdom (domain for which to retrieve configuration settings),
8746: origmail (scalar - email address of recipient from loncapa.conf,
8747: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8748:
1.655 raeburn 8749: Returns: comma separated list of addresses to which to send e-mail.
8750:
8751: =back
1.618 raeburn 8752:
8753: =cut
8754:
8755: ############################################################
8756: ############################################################
8757: sub build_recipient_list {
1.619 raeburn 8758: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8759: my @recipients;
8760: my $otheremails;
8761: my %domconfig =
8762: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8763: if (ref($domconfig{'contacts'}) eq 'HASH') {
8764: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8765: my @contacts = ('adminemail','supportemail');
8766: foreach my $item (@contacts) {
8767: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8768: my $addr = $domconfig{'contacts'}{$item};
8769: if (!grep(/^\Q$addr\E$/,@recipients)) {
8770: push(@recipients,$addr);
8771: }
1.618 raeburn 8772: }
8773: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8774: }
8775: }
1.619 raeburn 8776: } elsif ($origmail ne '') {
8777: push(@recipients,$origmail);
1.618 raeburn 8778: }
1.688 raeburn 8779: if (defined($defmail)) {
8780: if ($defmail ne '') {
8781: push(@recipients,$defmail);
8782: }
1.618 raeburn 8783: }
8784: if ($otheremails) {
1.619 raeburn 8785: my @others;
8786: if ($otheremails =~ /,/) {
8787: @others = split(/,/,$otheremails);
1.618 raeburn 8788: } else {
1.619 raeburn 8789: push(@others,$otheremails);
8790: }
8791: foreach my $addr (@others) {
8792: if (!grep(/^\Q$addr\E$/,@recipients)) {
8793: push(@recipients,$addr);
8794: }
1.618 raeburn 8795: }
8796: }
1.619 raeburn 8797: my $recipientlist = join(',',@recipients);
1.618 raeburn 8798: return $recipientlist;
8799: }
8800:
1.127 matthew 8801: ############################################################
8802: ############################################################
1.154 albertel 8803:
1.655 raeburn 8804: =pod
8805:
8806: =head1 Course Catalog Routines
8807:
8808: =over 4
8809:
8810: =item * &gather_categories()
8811:
8812: Converts category definitions - keys of categories hash stored in
8813: coursecategories in configuration.db on the primary library server in a
8814: domain - to an array. Also generates javascript and idx hash used to
8815: generate Domain Coordinator interface for editing Course Categories.
8816:
8817: Inputs:
1.663 raeburn 8818:
1.655 raeburn 8819: categories (reference to hash of category definitions).
1.663 raeburn 8820:
1.655 raeburn 8821: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8822: categories and subcategories).
1.663 raeburn 8823:
1.655 raeburn 8824: idx (reference to hash of counters used in Domain Coordinator interface for
8825: editing Course Categories).
1.663 raeburn 8826:
1.655 raeburn 8827: jsarray (reference to array of categories used to create Javascript arrays for
8828: Domain Coordinator interface for editing Course Categories).
8829:
8830: Returns: nothing
8831:
8832: Side effects: populates cats, idx and jsarray.
8833:
8834: =cut
8835:
8836: sub gather_categories {
8837: my ($categories,$cats,$idx,$jsarray) = @_;
8838: my %counters;
8839: my $num = 0;
8840: foreach my $item (keys(%{$categories})) {
8841: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8842: if ($container eq '' && $depth == 0) {
8843: $cats->[$depth][$categories->{$item}] = $cat;
8844: } else {
8845: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8846: }
8847: my ($escitem,$tail) = split(/:/,$item,2);
8848: if ($counters{$tail} eq '') {
8849: $counters{$tail} = $num;
8850: $num ++;
8851: }
8852: if (ref($idx) eq 'HASH') {
8853: $idx->{$item} = $counters{$tail};
8854: }
8855: if (ref($jsarray) eq 'ARRAY') {
8856: push(@{$jsarray->[$counters{$tail}]},$item);
8857: }
8858: }
8859: return;
8860: }
8861:
8862: =pod
8863:
8864: =item * &extract_categories()
8865:
8866: Used to generate breadcrumb trails for course categories.
8867:
8868: Inputs:
1.663 raeburn 8869:
1.655 raeburn 8870: categories (reference to hash of category definitions).
1.663 raeburn 8871:
1.655 raeburn 8872: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8873: categories and subcategories).
1.663 raeburn 8874:
1.655 raeburn 8875: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8876:
1.655 raeburn 8877: allitems (reference to hash - key is category key
8878: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8879:
1.655 raeburn 8880: idx (reference to hash of counters used in Domain Coordinator interface for
8881: editing Course Categories).
1.663 raeburn 8882:
1.655 raeburn 8883: jsarray (reference to array of categories used to create Javascript arrays for
8884: Domain Coordinator interface for editing Course Categories).
8885:
1.665 raeburn 8886: subcats (reference to hash of arrays containing all subcategories within each
8887: category, -recursive)
8888:
1.655 raeburn 8889: Returns: nothing
8890:
8891: Side effects: populates trails and allitems hash references.
8892:
8893: =cut
8894:
8895: sub extract_categories {
1.665 raeburn 8896: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8897: if (ref($categories) eq 'HASH') {
8898: &gather_categories($categories,$cats,$idx,$jsarray);
8899: if (ref($cats->[0]) eq 'ARRAY') {
8900: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8901: my $name = $cats->[0][$i];
8902: my $item = &escape($name).'::0';
8903: my $trailstr;
8904: if ($name eq 'instcode') {
8905: $trailstr = &mt('Official courses (with institutional codes)');
8906: } else {
8907: $trailstr = $name;
8908: }
8909: if ($allitems->{$item} eq '') {
8910: push(@{$trails},$trailstr);
8911: $allitems->{$item} = scalar(@{$trails})-1;
8912: }
8913: my @parents = ($name);
8914: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8915: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8916: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8917: if (ref($subcats) eq 'HASH') {
8918: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8919: }
8920: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8921: }
8922: } else {
8923: if (ref($subcats) eq 'HASH') {
8924: $subcats->{$item} = [];
1.655 raeburn 8925: }
8926: }
8927: }
8928: }
8929: }
8930: return;
8931: }
8932:
8933: =pod
8934:
8935: =item *&recurse_categories()
8936:
8937: Recursively used to generate breadcrumb trails for course categories.
8938:
8939: Inputs:
1.663 raeburn 8940:
1.655 raeburn 8941: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8942: categories and subcategories).
1.663 raeburn 8943:
1.655 raeburn 8944: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8945:
8946: category (current course category, for which breadcrumb trail is being generated).
8947:
8948: trails (reference to array of breadcrumb trails for each category).
8949:
1.655 raeburn 8950: allitems (reference to hash - key is category key
8951: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8952:
1.655 raeburn 8953: parents (array containing containers directories for current category,
8954: back to top level).
8955:
8956: Returns: nothing
8957:
8958: Side effects: populates trails and allitems hash references
8959:
8960: =cut
8961:
8962: sub recurse_categories {
1.665 raeburn 8963: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8964: my $shallower = $depth - 1;
8965: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8966: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8967: my $name = $cats->[$depth]{$category}[$k];
8968: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8969: my $trailstr = join(' -> ',(@{$parents},$category));
8970: if ($allitems->{$item} eq '') {
8971: push(@{$trails},$trailstr);
8972: $allitems->{$item} = scalar(@{$trails})-1;
8973: }
8974: my $deeper = $depth+1;
8975: push(@{$parents},$category);
1.665 raeburn 8976: if (ref($subcats) eq 'HASH') {
8977: my $subcat = &escape($name).':'.$category.':'.$depth;
8978: for (my $j=@{$parents}; $j>=0; $j--) {
8979: my $higher;
8980: if ($j > 0) {
8981: $higher = &escape($parents->[$j]).':'.
8982: &escape($parents->[$j-1]).':'.$j;
8983: } else {
8984: $higher = &escape($parents->[$j]).'::'.$j;
8985: }
8986: push(@{$subcats->{$higher}},$subcat);
8987: }
8988: }
8989: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8990: $subcats);
1.655 raeburn 8991: pop(@{$parents});
8992: }
8993: } else {
8994: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8995: my $trailstr = join(' -> ',(@{$parents},$category));
8996: if ($allitems->{$item} eq '') {
8997: push(@{$trails},$trailstr);
8998: $allitems->{$item} = scalar(@{$trails})-1;
8999: }
9000: }
9001: return;
9002: }
9003:
1.663 raeburn 9004: =pod
9005:
9006: =item *&assign_categories_table()
9007:
9008: Create a datatable for display of hierarchical categories in a domain,
9009: with checkboxes to allow a course to be categorized.
9010:
9011: Inputs:
9012:
9013: cathash - reference to hash of categories defined for the domain (from
9014: configuration.db)
9015:
9016: currcat - scalar with an & separated list of categories assigned to a course.
9017:
9018: Returns: $output (markup to be displayed)
9019:
9020: =cut
9021:
9022: sub assign_categories_table {
9023: my ($cathash,$currcat) = @_;
9024: my $output;
9025: if (ref($cathash) eq 'HASH') {
9026: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9027: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9028: $maxdepth = scalar(@cats);
9029: if (@cats > 0) {
9030: my $itemcount = 0;
9031: if (ref($cats[0]) eq 'ARRAY') {
9032: $output = &Apache::loncommon::start_data_table();
9033: my @currcategories;
9034: if ($currcat ne '') {
9035: @currcategories = split('&',$currcat);
9036: }
9037: for (my $i=0; $i<@{$cats[0]}; $i++) {
9038: my $parent = $cats[0][$i];
9039: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9040: next if ($parent eq 'instcode');
9041: my $item = &escape($parent).'::0';
9042: my $checked = '';
9043: if (@currcategories > 0) {
9044: if (grep(/^\Q$item\E$/,@currcategories)) {
9045: $checked = ' checked="checked" ';
9046: }
9047: }
1.675 raeburn 9048: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9049: '<input type="checkbox" name="usecategory" value="'.
9050: $item.'"'.$checked.' />'.$parent.'</span>'.
9051: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9052: my $depth = 1;
9053: push(@path,$parent);
9054: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9055: pop(@path);
9056: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9057: $itemcount ++;
9058: }
9059: $output .= &Apache::loncommon::end_data_table();
9060: }
9061: }
9062: }
9063: return $output;
9064: }
9065:
9066: =pod
9067:
9068: =item *&assign_category_rows()
9069:
9070: Create a datatable row for display of nested categories in a domain,
9071: with checkboxes to allow a course to be categorized,called recursively.
9072:
9073: Inputs:
9074:
9075: itemcount - track row number for alternating colors
9076:
9077: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9078: categories and subcategories.
9079:
9080: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9081:
9082: parent - parent of current category item
9083:
9084: path - Array containing all categories back up through the hierarchy from the
9085: current category to the top level.
9086:
9087: currcategories - reference to array of current categories assigned to the course
9088:
9089: Returns: $output (markup to be displayed).
9090:
9091: =cut
9092:
9093: sub assign_category_rows {
9094: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9095: my ($text,$name,$item,$chgstr);
9096: if (ref($cats) eq 'ARRAY') {
9097: my $maxdepth = scalar(@{$cats});
9098: if (ref($cats->[$depth]) eq 'HASH') {
9099: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9100: my $numchildren = @{$cats->[$depth]{$parent}};
9101: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9102: $text .= '<td><table class="LC_datatable">';
9103: for (my $j=0; $j<$numchildren; $j++) {
9104: $name = $cats->[$depth]{$parent}[$j];
9105: $item = &escape($name).':'.&escape($parent).':'.$depth;
9106: my $deeper = $depth+1;
9107: my $checked = '';
9108: if (ref($currcategories) eq 'ARRAY') {
9109: if (@{$currcategories} > 0) {
9110: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9111: $checked = ' checked="checked" ';
9112: }
9113: }
9114: }
1.664 raeburn 9115: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9116: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9117: $item.'"'.$checked.' />'.$name.'</label></span>'.
9118: '<input type="hidden" name="catname" value="'.$name.'" />'.
9119: '</td><td>';
1.663 raeburn 9120: if (ref($path) eq 'ARRAY') {
9121: push(@{$path},$name);
9122: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9123: pop(@{$path});
9124: }
9125: $text .= '</td></tr>';
9126: }
9127: $text .= '</table></td>';
9128: }
9129: }
9130: }
9131: return $text;
9132: }
9133:
1.655 raeburn 9134: ############################################################
9135: ############################################################
9136:
9137:
1.443 albertel 9138: sub commit_customrole {
1.664 raeburn 9139: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9140: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9141: ($start?', '.&mt('starting').' '.localtime($start):'').
9142: ($end?', ending '.localtime($end):'').': <b>'.
9143: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9144: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9145: '</b><br />';
9146: return $output;
9147: }
9148:
9149: sub commit_standardrole {
1.541 raeburn 9150: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9151: my ($output,$logmsg,$linefeed);
9152: if ($context eq 'auto') {
9153: $linefeed = "\n";
9154: } else {
9155: $linefeed = "<br />\n";
9156: }
1.443 albertel 9157: if ($three eq 'st') {
1.541 raeburn 9158: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9159: $one,$two,$sec,$context);
9160: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9161: ($result eq 'unknown_course') || ($result eq 'refused')) {
9162: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9163: } else {
1.541 raeburn 9164: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9165: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9166: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9167: if ($context eq 'auto') {
9168: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9169: } else {
9170: $output .= '<b>'.$result.'</b>'.$linefeed.
9171: &mt('Add to classlist').': <b>ok</b>';
9172: }
9173: $output .= $linefeed;
1.443 albertel 9174: }
9175: } else {
9176: $output = &mt('Assigning').' '.$three.' in '.$url.
9177: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9178: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9179: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9180: if ($context eq 'auto') {
9181: $output .= $result.$linefeed;
9182: } else {
9183: $output .= '<b>'.$result.'</b>'.$linefeed;
9184: }
1.443 albertel 9185: }
9186: return $output;
9187: }
9188:
9189: sub commit_studentrole {
1.541 raeburn 9190: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9191: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9192: if ($context eq 'auto') {
9193: $linefeed = "\n";
9194: } else {
9195: $linefeed = '<br />'."\n";
9196: }
1.443 albertel 9197: if (defined($one) && defined($two)) {
9198: my $cid=$one.'_'.$two;
9199: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9200: my $secchange = 0;
9201: my $expire_role_result;
9202: my $modify_section_result;
1.628 raeburn 9203: if ($oldsec ne '-1') {
9204: if ($oldsec ne $sec) {
1.443 albertel 9205: $secchange = 1;
1.628 raeburn 9206: my $now = time;
1.443 albertel 9207: my $uurl='/'.$cid;
9208: $uurl=~s/\_/\//g;
9209: if ($oldsec) {
9210: $uurl.='/'.$oldsec;
9211: }
1.626 raeburn 9212: $oldsecurl = $uurl;
1.628 raeburn 9213: $expire_role_result =
1.652 raeburn 9214: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9215: if ($env{'request.course.sec'} ne '') {
9216: if ($expire_role_result eq 'refused') {
9217: my @roles = ('st');
9218: my @statuses = ('previous');
9219: my @roledoms = ($one);
9220: my $withsec = 1;
9221: my %roleshash =
9222: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9223: \@statuses,\@roles,\@roledoms,$withsec);
9224: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9225: my ($oldstart,$oldend) =
9226: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9227: if ($oldend > 0 && $oldend <= $now) {
9228: $expire_role_result = 'ok';
9229: }
9230: }
9231: }
9232: }
1.443 albertel 9233: $result = $expire_role_result;
9234: }
9235: }
9236: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9237: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9238: if ($modify_section_result =~ /^ok/) {
9239: if ($secchange == 1) {
1.628 raeburn 9240: if ($sec eq '') {
9241: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9242: } else {
9243: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9244: }
1.443 albertel 9245: } elsif ($oldsec eq '-1') {
1.628 raeburn 9246: if ($sec eq '') {
9247: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9248: } else {
9249: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9250: }
1.443 albertel 9251: } else {
1.628 raeburn 9252: if ($sec eq '') {
9253: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9254: } else {
9255: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9256: }
1.443 albertel 9257: }
9258: } else {
1.628 raeburn 9259: if ($secchange) {
9260: $$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;
9261: } else {
9262: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9263: }
1.443 albertel 9264: }
9265: $result = $modify_section_result;
9266: } elsif ($secchange == 1) {
1.628 raeburn 9267: if ($oldsec eq '') {
9268: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9269: } else {
9270: $$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;
9271: }
1.626 raeburn 9272: if ($expire_role_result eq 'refused') {
9273: my $newsecurl = '/'.$cid;
9274: $newsecurl =~ s/\_/\//g;
9275: if ($sec ne '') {
9276: $newsecurl.='/'.$sec;
9277: }
9278: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9279: if ($sec eq '') {
9280: $$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;
9281: } else {
9282: $$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;
9283: }
9284: }
9285: }
1.443 albertel 9286: }
9287: } else {
1.626 raeburn 9288: $$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 9289: $result = "error: incomplete course id\n";
9290: }
9291: return $result;
9292: }
9293:
9294: ############################################################
9295: ############################################################
9296:
1.566 albertel 9297: sub check_clone {
1.578 raeburn 9298: my ($args,$linefeed) = @_;
1.566 albertel 9299: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9300: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9301: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9302: my $clonemsg;
9303: my $can_clone = 0;
9304:
9305: if ($clonehome eq 'no_host') {
1.578 raeburn 9306: $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 9307: } else {
9308: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9309: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9310: $can_clone = 1;
9311: } else {
9312: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9313: $args->{'clonedomain'},$args->{'clonecourse'});
9314: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9315: if (grep(/^\*$/,@cloners)) {
9316: $can_clone = 1;
9317: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9318: $can_clone = 1;
9319: } else {
9320: my %roleshash =
9321: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9322: $args->{'ccdomain'},
9323: 'userroles',['active'],['cc'],
9324: [$args->{'clonedomain'}]);
9325: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9326: $can_clone = 1;
9327: } else {
9328: $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'});
9329: }
1.566 albertel 9330: }
1.578 raeburn 9331: }
1.566 albertel 9332: }
9333: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9334: }
9335:
1.444 albertel 9336: sub construct_course {
1.541 raeburn 9337: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9338: my $outcome;
1.541 raeburn 9339: my $linefeed = '<br />'."\n";
9340: if ($context eq 'auto') {
9341: $linefeed = "\n";
9342: }
1.566 albertel 9343:
9344: #
9345: # Are we cloning?
9346: #
9347: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9348: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9349: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9350: if ($context ne 'auto') {
1.578 raeburn 9351: if ($clonemsg ne '') {
9352: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9353: }
1.566 albertel 9354: }
9355: $outcome .= $clonemsg.$linefeed;
9356:
9357: if (!$can_clone) {
9358: return (0,$outcome);
9359: }
9360: }
9361:
1.444 albertel 9362: #
9363: # Open course
9364: #
9365: my $crstype = lc($args->{'crstype'});
9366: my %cenv=();
9367: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9368: $args->{'cdescr'},
9369: $args->{'curl'},
9370: $args->{'course_home'},
9371: $args->{'nonstandard'},
9372: $args->{'crscode'},
9373: $args->{'ccuname'}.':'.
9374: $args->{'ccdomain'},
9375: $args->{'crstype'});
9376:
9377: # Note: The testing routines depend on this being output; see
9378: # Utils::Course. This needs to at least be output as a comment
9379: # if anyone ever decides to not show this, and Utils::Course::new
9380: # will need to be suitably modified.
1.541 raeburn 9381: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9382: #
9383: # Check if created correctly
9384: #
1.479 albertel 9385: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9386: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9387: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9388:
1.444 albertel 9389: #
1.566 albertel 9390: # Do the cloning
9391: #
9392: if ($can_clone && $cloneid) {
9393: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9394: if ($context ne 'auto') {
9395: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9396: }
9397: $outcome .= $clonemsg.$linefeed;
9398: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9399: # Copy all files
1.637 www 9400: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9401: # Restore URL
1.566 albertel 9402: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9403: # Restore title
1.566 albertel 9404: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9405: # Mark as cloned
1.566 albertel 9406: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9407: # Need to clone grading mode
9408: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9409: $cenv{'grading'}=$newenv{'grading'};
9410: # Do not clone these environment entries
9411: &Apache::lonnet::del('environment',
9412: ['default_enrollment_start_date',
9413: 'default_enrollment_end_date',
9414: 'question.email',
9415: 'policy.email',
9416: 'comment.email',
9417: 'pch.users.denied',
1.725 raeburn 9418: 'plc.users.denied',
9419: 'hidefromcat',
9420: 'categories'],
1.638 www 9421: $$crsudom,$$crsunum);
1.444 albertel 9422: }
1.566 albertel 9423:
1.444 albertel 9424: #
9425: # Set environment (will override cloned, if existing)
9426: #
9427: my @sections = ();
9428: my @xlists = ();
9429: if ($args->{'crstype'}) {
9430: $cenv{'type'}=$args->{'crstype'};
9431: }
9432: if ($args->{'crsid'}) {
9433: $cenv{'courseid'}=$args->{'crsid'};
9434: }
9435: if ($args->{'crscode'}) {
9436: $cenv{'internal.coursecode'}=$args->{'crscode'};
9437: }
9438: if ($args->{'crsquota'} ne '') {
9439: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9440: } else {
9441: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9442: }
9443: if ($args->{'ccuname'}) {
9444: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9445: ':'.$args->{'ccdomain'};
9446: } else {
9447: $cenv{'internal.courseowner'} = $args->{'curruser'};
9448: }
9449: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9450: if ($args->{'crssections'}) {
9451: $cenv{'internal.sectionnums'} = '';
9452: if ($args->{'crssections'} =~ m/,/) {
9453: @sections = split/,/,$args->{'crssections'};
9454: } else {
9455: $sections[0] = $args->{'crssections'};
9456: }
9457: if (@sections > 0) {
9458: foreach my $item (@sections) {
9459: my ($sec,$gp) = split/:/,$item;
9460: my $class = $args->{'crscode'}.$sec;
9461: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9462: $cenv{'internal.sectionnums'} .= $item.',';
9463: unless ($addcheck eq 'ok') {
9464: push @badclasses, $class;
9465: }
9466: }
9467: $cenv{'internal.sectionnums'} =~ s/,$//;
9468: }
9469: }
9470: # do not hide course coordinator from staff listing,
9471: # even if privileged
9472: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9473: # add crosslistings
9474: if ($args->{'crsxlist'}) {
9475: $cenv{'internal.crosslistings'}='';
9476: if ($args->{'crsxlist'} =~ m/,/) {
9477: @xlists = split/,/,$args->{'crsxlist'};
9478: } else {
9479: $xlists[0] = $args->{'crsxlist'};
9480: }
9481: if (@xlists > 0) {
9482: foreach my $item (@xlists) {
9483: my ($xl,$gp) = split/:/,$item;
9484: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9485: $cenv{'internal.crosslistings'} .= $item.',';
9486: unless ($addcheck eq 'ok') {
9487: push @badclasses, $xl;
9488: }
9489: }
9490: $cenv{'internal.crosslistings'} =~ s/,$//;
9491: }
9492: }
9493: if ($args->{'autoadds'}) {
9494: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9495: }
9496: if ($args->{'autodrops'}) {
9497: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9498: }
9499: # check for notification of enrollment changes
9500: my @notified = ();
9501: if ($args->{'notify_owner'}) {
9502: if ($args->{'ccuname'} ne '') {
9503: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9504: }
9505: }
9506: if ($args->{'notify_dc'}) {
9507: if ($uname ne '') {
1.630 raeburn 9508: push(@notified,$uname.':'.$udom);
1.444 albertel 9509: }
9510: }
9511: if (@notified > 0) {
9512: my $notifylist;
9513: if (@notified > 1) {
9514: $notifylist = join(',',@notified);
9515: } else {
9516: $notifylist = $notified[0];
9517: }
9518: $cenv{'internal.notifylist'} = $notifylist;
9519: }
9520: if (@badclasses > 0) {
9521: my %lt=&Apache::lonlocal::texthash(
9522: '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',
9523: 'dnhr' => 'does not have rights to access enrollment in these classes',
9524: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9525: );
1.541 raeburn 9526: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9527: ' ('.$lt{'adby'}.')';
9528: if ($context eq 'auto') {
9529: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9530: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9531: foreach my $item (@badclasses) {
9532: if ($context eq 'auto') {
9533: $outcome .= " - $item\n";
9534: } else {
9535: $outcome .= "<li>$item</li>\n";
9536: }
9537: }
9538: if ($context eq 'auto') {
9539: $outcome .= $linefeed;
9540: } else {
1.566 albertel 9541: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9542: }
9543: }
1.444 albertel 9544: }
9545: if ($args->{'no_end_date'}) {
9546: $args->{'endaccess'} = 0;
9547: }
9548: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9549: $cenv{'internal.autoend'}=$args->{'enrollend'};
9550: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9551: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9552: if ($args->{'showphotos'}) {
9553: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9554: }
9555: $cenv{'internal.authtype'} = $args->{'authtype'};
9556: $cenv{'internal.autharg'} = $args->{'autharg'};
9557: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9558: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9559: 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');
9560: if ($context eq 'auto') {
9561: $outcome .= $krb_msg;
9562: } else {
1.566 albertel 9563: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9564: }
9565: $outcome .= $linefeed;
1.444 albertel 9566: }
9567: }
9568: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9569: if ($args->{'setpolicy'}) {
9570: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9571: }
9572: if ($args->{'setcontent'}) {
9573: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9574: }
9575: }
9576: if ($args->{'reshome'}) {
9577: $cenv{'reshome'}=$args->{'reshome'}.'/';
9578: $cenv{'reshome'}=~s/\/+$/\//;
9579: }
9580: #
9581: # course has keyed access
9582: #
9583: if ($args->{'setkeys'}) {
9584: $cenv{'keyaccess'}='yes';
9585: }
9586: # if specified, key authority is not course, but user
9587: # only active if keyaccess is yes
9588: if ($args->{'keyauth'}) {
1.487 albertel 9589: my ($user,$domain) = split(':',$args->{'keyauth'});
9590: $user = &LONCAPA::clean_username($user);
9591: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9592: if ($user ne '' && $domain ne '') {
1.487 albertel 9593: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9594: }
9595: }
9596:
9597: if ($args->{'disresdis'}) {
9598: $cenv{'pch.roles.denied'}='st';
9599: }
9600: if ($args->{'disablechat'}) {
9601: $cenv{'plc.roles.denied'}='st';
9602: }
9603:
9604: # Record we've not yet viewed the Course Initialization Helper for this
9605: # course
9606: $cenv{'course.helper.not.run'} = 1;
9607: #
9608: # Use new Randomseed
9609: #
9610: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9611: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9612: #
9613: # The encryption code and receipt prefix for this course
9614: #
9615: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9616: $cenv{'internal.encpref'}=100+int(9*rand(99));
9617: #
9618: # By default, use standard grading
9619: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9620:
1.541 raeburn 9621: $outcome .= $linefeed.&mt('Setting environment').': '.
9622: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9623: #
9624: # Open all assignments
9625: #
9626: if ($args->{'openall'}) {
9627: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9628: my %storecontent = ($storeunder => time,
9629: $storeunder.'.type' => 'date_start');
9630:
9631: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9632: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9633: }
9634: #
9635: # Set first page
9636: #
9637: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9638: || ($cloneid)) {
1.445 albertel 9639: use LONCAPA::map;
1.444 albertel 9640: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9641:
9642: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9643: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9644:
1.444 albertel 9645: $outcome .= ($fatal?$errtext:'read ok').' - ';
9646: my $title; my $url;
9647: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9648: $title=&mt('Syllabus');
1.444 albertel 9649: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9650: } else {
1.690 bisitz 9651: $title=&mt('Navigate Contents');
1.444 albertel 9652: $url='/adm/navmaps';
9653: }
1.445 albertel 9654:
9655: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9656: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9657:
9658: if ($errtext) { $fatal=2; }
1.541 raeburn 9659: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9660: }
1.566 albertel 9661:
9662: return (1,$outcome);
1.444 albertel 9663: }
9664:
9665: ############################################################
9666: ############################################################
9667:
1.378 raeburn 9668: sub course_type {
9669: my ($cid) = @_;
9670: if (!defined($cid)) {
9671: $cid = $env{'request.course.id'};
9672: }
1.404 albertel 9673: if (defined($env{'course.'.$cid.'.type'})) {
9674: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9675: } else {
9676: return 'Course';
1.377 raeburn 9677: }
9678: }
1.156 albertel 9679:
1.406 raeburn 9680: sub group_term {
9681: my $crstype = &course_type();
9682: my %names = (
9683: 'Course' => 'group',
9684: 'Group' => 'team',
9685: );
9686: return $names{$crstype};
9687: }
9688:
1.156 albertel 9689: sub icon {
9690: my ($file)=@_;
1.505 albertel 9691: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9692: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9693: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9694: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9695: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9696: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9697: $curfext.".gif") {
9698: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9699: $curfext.".gif";
9700: }
9701: }
1.249 albertel 9702: return &lonhttpdurl($iconname);
1.154 albertel 9703: }
1.84 albertel 9704:
1.575 albertel 9705: sub lonhttpdurl {
1.692 www 9706: #
9707: # Had been used for "small fry" static images on separate port 8080.
9708: # Modify here if lightweight http functionality desired again.
9709: # Currently eliminated due to increasing firewall issues.
9710: #
1.575 albertel 9711: my ($url)=@_;
1.692 www 9712: return $url;
1.215 albertel 9713: }
9714:
1.213 albertel 9715: sub connection_aborted {
9716: my ($r)=@_;
9717: $r->print(" ");$r->rflush();
9718: my $c = $r->connection;
9719: return $c->aborted();
9720: }
9721:
1.221 foxr 9722: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9723: # strings as 'strings'.
9724: sub escape_single {
1.221 foxr 9725: my ($input) = @_;
1.223 albertel 9726: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9727: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9728: return $input;
9729: }
1.223 albertel 9730:
1.222 foxr 9731: # Same as escape_single, but escape's "'s This
9732: # can be used for "strings"
9733: sub escape_double {
9734: my ($input) = @_;
9735: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9736: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9737: return $input;
9738: }
1.223 albertel 9739:
1.222 foxr 9740: # Escapes the last element of a full URL.
9741: sub escape_url {
9742: my ($url) = @_;
1.238 raeburn 9743: my @urlslices = split(/\//, $url,-1);
1.369 www 9744: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9745: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9746: }
1.462 albertel 9747:
9748: # -------------------------------------------------------- Initliaze user login
9749: sub init_user_environment {
1.463 albertel 9750: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9751: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9752:
9753: my $public=($username eq 'public' && $domain eq 'public');
9754:
9755: # See if old ID present, if so, remove
9756:
9757: my ($filename,$cookie,$userroles);
9758: my $now=time;
9759:
9760: if ($public) {
9761: my $max_public=100;
9762: my $oldest;
9763: my $oldest_time=0;
9764: for(my $next=1;$next<=$max_public;$next++) {
9765: if (-e $lonids."/publicuser_$next.id") {
9766: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9767: if ($mtime<$oldest_time || !$oldest_time) {
9768: $oldest_time=$mtime;
9769: $oldest=$next;
9770: }
9771: } else {
9772: $cookie="publicuser_$next";
9773: last;
9774: }
9775: }
9776: if (!$cookie) { $cookie="publicuser_$oldest"; }
9777: } else {
1.463 albertel 9778: # if this isn't a robot, kill any existing non-robot sessions
9779: if (!$args->{'robot'}) {
9780: opendir(DIR,$lonids);
9781: while ($filename=readdir(DIR)) {
9782: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9783: unlink($lonids.'/'.$filename);
9784: }
1.462 albertel 9785: }
1.463 albertel 9786: closedir(DIR);
1.462 albertel 9787: }
9788: # Give them a new cookie
1.463 albertel 9789: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9790: : $now.$$.int(rand(10000)));
1.463 albertel 9791: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9792:
9793: # Initialize roles
9794:
9795: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9796: }
9797: # ------------------------------------ Check browser type and MathML capability
9798:
9799: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9800: $clientunicode,$clientos) = &decode_user_agent($r);
9801:
9802: # -------------------------------------- Any accessibility options to remember?
9803: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9804: foreach my $option ('imagesuppress','appletsuppress',
9805: 'embedsuppress','fontenhance','blackwhite') {
9806: if ($form->{$option} eq 'true') {
9807: &Apache::lonnet::put('environment',{$option => 'on'},
9808: $domain,$username);
9809: } else {
9810: &Apache::lonnet::del('environment',[$option],
9811: $domain,$username);
9812: }
9813: }
9814: }
9815: # ------------------------------------------------------------- Get environment
9816:
9817: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9818: my ($tmp) = keys(%userenv);
9819: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9820: # default remote control to off
9821: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9822: } else {
9823: undef(%userenv);
9824: }
9825: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9826: $form->{'interface'}=$userenv{'interface'};
9827: }
9828: $env{'environment.remote'}=$userenv{'remote'};
9829: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9830:
9831: # --------------- Do not trust query string to be put directly into environment
9832: foreach my $option ('imagesuppress','appletsuppress',
9833: 'embedsuppress','fontenhance','blackwhite',
9834: 'interface','localpath','localres') {
9835: $form->{$option}=~s/[\n\r\=]//gs;
9836: }
9837: # --------------------------------------------------------- Write first profile
9838:
9839: {
9840: my %initial_env =
9841: ("user.name" => $username,
9842: "user.domain" => $domain,
9843: "user.home" => $authhost,
9844: "browser.type" => $clientbrowser,
9845: "browser.version" => $clientversion,
9846: "browser.mathml" => $clientmathml,
9847: "browser.unicode" => $clientunicode,
9848: "browser.os" => $clientos,
9849: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9850: "request.course.fn" => '',
9851: "request.course.uri" => '',
9852: "request.course.sec" => '',
9853: "request.role" => 'cm',
9854: "request.role.adv" => $env{'user.adv'},
9855: "request.host" => $ENV{'REMOTE_ADDR'},);
9856:
9857: if ($form->{'localpath'}) {
9858: $initial_env{"browser.localpath"} = $form->{'localpath'};
9859: $initial_env{"browser.localres"} = $form->{'localres'};
9860: }
9861:
9862: if ($public) {
9863: $initial_env{"environment.remote"} = "off";
9864: }
9865: if ($form->{'interface'}) {
9866: $form->{'interface'}=~s/\W//gs;
9867: $initial_env{"browser.interface"} = $form->{'interface'};
9868: $env{'browser.interface'}=$form->{'interface'};
9869: foreach my $option ('imagesuppress','appletsuppress',
9870: 'embedsuppress','fontenhance','blackwhite') {
9871: if (($form->{$option} eq 'true') ||
9872: ($userenv{$option} eq 'on')) {
9873: $initial_env{"browser.$option"} = "on";
9874: }
9875: }
9876: }
9877:
1.724 raeburn 9878: foreach my $tool ('aboutme','blog','portfolio') {
9879: $userenv{'availabletools.'.$tool} =
9880: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
9881: }
9882:
1.462 albertel 9883: $env{'user.environment'} = "$lonids/$cookie.id";
9884:
9885: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9886: &GDBM_WRCREAT(),0640)) {
9887: &_add_to_env(\%disk_env,\%initial_env);
9888: &_add_to_env(\%disk_env,\%userenv,'environment.');
9889: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9890: if (ref($args->{'extra_env'})) {
9891: &_add_to_env(\%disk_env,$args->{'extra_env'});
9892: }
1.462 albertel 9893: untie(%disk_env);
9894: } else {
1.705 tempelho 9895: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
9896: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 9897: return 'error: '.$!;
9898: }
9899: }
9900: $env{'request.role'}='cm';
9901: $env{'request.role.adv'}=$env{'user.adv'};
9902: $env{'browser.type'}=$clientbrowser;
9903:
9904: return $cookie;
9905:
9906: }
9907:
9908: sub _add_to_env {
9909: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9910: if (ref($env_data) eq 'HASH') {
9911: while (my ($key,$value) = each(%$env_data)) {
9912: $idf->{$prefix.$key} = $value;
9913: $env{$prefix.$key} = $value;
9914: }
1.462 albertel 9915: }
9916: }
9917:
1.685 tempelho 9918: # --- Get the symbolic name of a problem and the url
9919: sub get_symb {
9920: my ($request,$silent) = @_;
1.726 raeburn 9921: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 9922: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9923: if ($symb eq '') {
9924: if (!$silent) {
9925: $request->print("Unable to handle ambiguous references:$url:.");
9926: return ();
9927: }
9928: }
9929: &Apache::lonenc::check_decrypt(\$symb);
9930: return ($symb);
9931: }
9932:
9933: # --------------------------------------------------------------Get annotation
9934:
9935: sub get_annotation {
9936: my ($symb,$enc) = @_;
9937:
9938: my $key = $symb;
9939: if (!$enc) {
9940: $key =
9941: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9942: }
9943: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9944: return $annotation{$key};
9945: }
9946:
9947: sub clean_symb {
1.731 raeburn 9948: my ($symb,$delete_enc) = @_;
1.685 tempelho 9949:
9950: &Apache::lonenc::check_decrypt(\$symb);
9951: my $enc = $env{'request.enc'};
1.731 raeburn 9952: if ($delete_enc) {
1.730 raeburn 9953: delete($env{'request.enc'});
9954: }
1.685 tempelho 9955:
9956: return ($symb,$enc);
9957: }
1.462 albertel 9958:
1.41 ng 9959: =pod
9960:
9961: =back
9962:
1.112 bowersj2 9963: =cut
1.41 ng 9964:
1.112 bowersj2 9965: 1;
9966: __END__;
1.41 ng 9967:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>