Annotation of loncom/interface/loncommon.pm, revision 1.694
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.694 ! tempelho 4: # $Id: loncommon.pm,v 1.693 2008/11/14 13:29:28 droeschl Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.479 albertel 70: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 71: use DateTime::TimeZone;
1.687 raeburn 72: use DateTime::Locale::Catalog;
1.117 www 73:
1.517 raeburn 74: # ---------------------------------------------- Designs
75: use vars qw(%defaultdesign);
76:
1.22 www 77: my $readit;
78:
1.517 raeburn 79:
1.157 matthew 80: ##
81: ## Global Variables
82: ##
1.46 matthew 83:
1.643 foxr 84:
85: # ----------------------------------------------- SSI with retries:
86: #
87:
88: =pod
89:
1.648 raeburn 90: =head1 Server Side include with retries:
1.643 foxr 91:
92: =over 4
93:
1.648 raeburn 94: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 95:
96: Performs an ssi with some number of retries. Retries continue either
97: until the result is ok or until the retry count supplied by the
98: caller is exhausted.
99:
100: Inputs:
1.648 raeburn 101:
102: =over 4
103:
1.643 foxr 104: resource - Identifies the resource to insert.
1.648 raeburn 105:
1.643 foxr 106: retries - Count of the number of retries allowed.
1.648 raeburn 107:
1.643 foxr 108: form - Hash that identifies the rendering options.
109:
1.648 raeburn 110: =back
111:
112: Returns:
113:
114: =over 4
115:
1.643 foxr 116: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 117:
1.643 foxr 118: response - The response from the last attempt (which may or may not have been successful.
119:
1.648 raeburn 120: =back
121:
122: =back
123:
1.643 foxr 124: =cut
125:
126: sub ssi_with_retries {
127: my ($resource, $retries, %form) = @_;
128:
129:
130: my $ok = 0; # True if we got a good response.
131: my $content;
132: my $response;
133:
134: # Try to get the ssi done. within the retries count:
135:
136: do {
137: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
138: $ok = $response->is_success;
1.650 www 139: if (!$ok) {
140: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
141: }
1.643 foxr 142: $retries--;
143: } while (!$ok && ($retries > 0));
144:
145: if (!$ok) {
146: $content = ''; # On error return an empty content.
147: }
148: return ($content, $response);
149:
150: }
151:
152:
153:
1.20 www 154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 155: my %language;
1.124 www 156: my %supported_language;
1.12 harris41 157: my %cprtag;
1.192 taceyjo1 158: my %scprtag;
1.351 www 159: my %fe; my %fd; my %fm;
1.41 ng 160: my %category_extensions;
1.12 harris41 161:
1.46 matthew 162: # ---------------------------------------------- Thesaurus variables
1.144 matthew 163: #
164: # %Keywords:
165: # A hash used by &keyword to determine if a word is considered a keyword.
166: # $thesaurus_db_file
167: # Scalar containing the full path to the thesaurus database.
1.46 matthew 168:
169: my %Keywords;
170: my $thesaurus_db_file;
171:
1.144 matthew 172: #
173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
174: # thesaurus.tab, and filecategories.tab.
175: #
1.18 www 176: BEGIN {
1.46 matthew 177: # Variable initialization
178: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
179: #
1.22 www 180: unless ($readit) {
1.12 harris41 181: # ------------------------------------------------------------------- languages
182: {
1.158 raeburn 183: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
184: '/language.tab';
185: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 186: while (my $line = <$fh>) {
187: next if ($line=~/^\#/);
188: chomp($line);
189: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 190: $language{$key}=$val.' - '.$enc;
191: if ($sup) {
192: $supported_language{$key}=$sup;
193: }
194: }
195: close($fh);
196: }
1.12 harris41 197: }
198: # ------------------------------------------------------------------ copyrights
199: {
1.158 raeburn 200: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
201: '/copyright.tab';
202: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
206: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 207: $cprtag{$key}=$val;
208: }
209: close($fh);
210: }
1.12 harris41 211: }
1.351 www 212: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 213: {
214: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
215: '/source_copyright.tab';
216: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 217: while (my $line = <$fh>) {
218: next if ($line =~ /^\#/);
219: chomp($line);
220: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 221: $scprtag{$key}=$val;
222: }
223: close($fh);
224: }
225: }
1.63 www 226:
1.517 raeburn 227: # -------------------------------------------------------------- default domain designs
1.63 www 228: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 229: my $designfile = $designdir.'/default.tab';
230: if ( open (my $fh,"<$designfile") ) {
231: while (my $line = <$fh>) {
232: next if ($line =~ /^\#/);
233: chomp($line);
234: my ($key,$val)=(split(/\=/,$line));
235: if ($val) { $defaultdesign{$key}=$val; }
236: }
237: close($fh);
1.63 www 238: }
239:
1.15 harris41 240: # ------------------------------------------------------------- file categories
241: {
1.158 raeburn 242: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
243: '/filecategories.tab';
244: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 245: while (my $line = <$fh>) {
246: next if ($line =~ /^\#/);
247: chomp($line);
248: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 249: push @{$category_extensions{lc($category)}},$extension;
250: }
251: close($fh);
252: }
253:
1.15 harris41 254: }
1.12 harris41 255: # ------------------------------------------------------------------ file types
256: {
1.158 raeburn 257: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
258: '/filetypes.tab';
259: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 260: while (my $line = <$fh>) {
261: next if ($line =~ /^\#/);
262: chomp($line);
263: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 264: if ($descr ne '') {
265: $fe{$ending}=lc($emb);
266: $fd{$ending}=$descr;
1.351 www 267: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 268: }
269: }
270: close($fh);
271: }
1.12 harris41 272: }
1.22 www 273: &Apache::lonnet::logthis(
1.46 matthew 274: "<font color=yellow>INFO: Read file types</font>");
1.22 www 275: $readit=1;
1.46 matthew 276: } # end of unless($readit)
1.32 matthew 277:
278: }
1.112 bowersj2 279:
1.42 matthew 280: ###############################################################
281: ## HTML and Javascript Helper Functions ##
282: ###############################################################
283:
284: =pod
285:
1.112 bowersj2 286: =head1 HTML and Javascript Functions
1.42 matthew 287:
1.112 bowersj2 288: =over 4
289:
1.648 raeburn 290: =item * &browser_and_searcher_javascript()
1.112 bowersj2 291:
292: X<browsing, javascript>X<searching, javascript>Returns a string
293: containing javascript with two functions, C<openbrowser> and
294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
295: tags.
1.42 matthew 296:
1.648 raeburn 297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 298:
299: inputs: formname, elementname, only, omit
300:
301: formname and elementname indicate the name of the html form and name of
302: the element that the results of the browsing selection are to be placed in.
303:
304: Specifying 'only' will restrict the browser to displaying only files
1.185 www 305: with the given extension. Can be a comma separated list.
1.42 matthew 306:
307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 308: with the given extension. Can be a comma separated list.
1.42 matthew 309:
1.648 raeburn 310: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 311:
312: Inputs: formname, elementname
313:
314: formname and elementname specify the name of the html form and the name
315: of the element the selection from the search results will be placed in.
1.542 raeburn 316:
1.42 matthew 317: =cut
318:
319: sub browser_and_searcher_javascript {
1.199 albertel 320: my ($mode)=@_;
321: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 322: my $resurl=&escape_single(&lastresurl());
1.42 matthew 323: return <<END;
1.219 albertel 324: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 325: var editbrowser = null;
1.135 albertel 326: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 327: var url = '$resurl/?';
1.42 matthew 328: if (editbrowser == null) {
329: url += 'launch=1&';
330: }
331: url += 'catalogmode=interactive&';
1.199 albertel 332: url += 'mode=$mode&';
1.611 albertel 333: url += 'inhibitmenu=yes&';
1.42 matthew 334: url += 'form=' + formname + '&';
335: if (only != null) {
336: url += 'only=' + only + '&';
1.217 albertel 337: } else {
338: url += 'only=&';
339: }
1.42 matthew 340: if (omit != null) {
341: url += 'omit=' + omit + '&';
1.217 albertel 342: } else {
343: url += 'omit=&';
344: }
1.135 albertel 345: if (titleelement != null) {
346: url += 'titleelement=' + titleelement + '&';
1.217 albertel 347: } else {
348: url += 'titleelement=&';
349: }
1.42 matthew 350: url += 'element=' + elementname + '';
351: var title = 'Browser';
1.435 albertel 352: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 353: options += ',width=700,height=600';
354: editbrowser = open(url,title,options,'1');
355: editbrowser.focus();
356: }
357: var editsearcher;
1.135 albertel 358: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 359: var url = '/adm/searchcat?';
360: if (editsearcher == null) {
361: url += 'launch=1&';
362: }
363: url += 'catalogmode=interactive&';
1.199 albertel 364: url += 'mode=$mode&';
1.42 matthew 365: url += 'form=' + formname + '&';
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Search';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editsearcher = open(url,title,options,'1');
376: editsearcher.focus();
377: }
1.219 albertel 378: // END LON-CAPA Internal -->
1.42 matthew 379: END
1.170 www 380: }
381:
382: sub lastresurl {
1.258 albertel 383: if ($env{'environment.lastresurl'}) {
384: return $env{'environment.lastresurl'}
1.170 www 385: } else {
386: return '/res';
387: }
388: }
389:
390: sub storeresurl {
391: my $resurl=&Apache::lonnet::clutter(shift);
392: unless ($resurl=~/^\/res/) { return 0; }
393: $resurl=~s/\/$//;
394: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 395: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 396: return 1;
1.42 matthew 397: }
398:
1.74 www 399: sub studentbrowser_javascript {
1.111 www 400: unless (
1.258 albertel 401: (($env{'request.course.id'}) &&
1.302 albertel 402: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
403: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
404: '/'.$env{'request.course.sec'})
405: ))
1.258 albertel 406: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 407: ) { return ''; }
1.74 www 408: return (<<'ENDSTDBRW');
409: <script type="text/javascript" language="Javascript" >
410: var stdeditbrowser;
1.558 albertel 411: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74 www 412: var url = '/adm/pickstudent?';
413: var filter;
1.558 albertel 414: if (!ignorefilter) {
415: eval('filter=document.'+formname+'.'+uname+'.value;');
416: }
1.74 www 417: if (filter != null) {
418: if (filter != '') {
419: url += 'filter='+filter+'&';
420: }
421: }
422: url += 'form=' + formname + '&unameelement='+uname+
423: '&udomelement='+udom;
1.111 www 424: if (roleflag) { url+="&roles=1"; }
1.102 www 425: var title = 'Student_Browser';
1.74 www 426: var options = 'scrollbars=1,resizable=1,menubar=0';
427: options += ',width=700,height=600';
428: stdeditbrowser = open(url,title,options,'1');
429: stdeditbrowser.focus();
430: }
431: </script>
432: ENDSTDBRW
433: }
1.42 matthew 434:
1.74 www 435: sub selectstudent_link {
1.111 www 436: my ($form,$unameele,$udomele)=@_;
1.258 albertel 437: if ($env{'request.course.id'}) {
1.302 albertel 438: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
439: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
440: '/'.$env{'request.course.sec'})) {
1.111 www 441: return '';
442: }
443: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607 albertel 444: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 445: }
1.258 albertel 446: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 447: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 448: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 449: }
450: return '';
1.91 www 451: }
452:
1.653 raeburn 453: sub authorbrowser_javascript {
454: return <<"ENDAUTHORBRW";
455: <script type="text/javascript">
456: var stdeditbrowser;
457:
458: function openauthorbrowser(formname,udom) {
459: var url = '/adm/pickauthor?';
460: url += 'form='+formname+'&roledom='+udom;
461: var title = 'Author_Browser';
462: var options = 'scrollbars=1,resizable=1,menubar=0';
463: options += ',width=700,height=600';
464: stdeditbrowser = open(url,title,options,'1');
465: stdeditbrowser.focus();
466: }
467:
468: </script>
469: ENDAUTHORBRW
470: }
471:
1.91 www 472: sub coursebrowser_javascript {
1.468 raeburn 473: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 474: my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468 raeburn 475: my $output = '
1.538 albertel 476: <script type="text/javascript">
1.468 raeburn 477: var stdeditbrowser;'."\n";
478: $output .= <<"ENDSTDBRW";
1.377 raeburn 479: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 480: var url = '/adm/pickcourse?';
1.468 raeburn 481: var domainfilter = '';
482: var formid = getFormIdByName(formname);
483: if (formid > -1) {
484: var domid = getIndexByName(formid,udom);
485: if (domid > -1) {
486: if (document.forms[formid].elements[domid].type == 'select-one') {
487: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
488: }
489: if (document.forms[formid].elements[domid].type == 'hidden') {
490: domainfilter=document.forms[formid].elements[domid].value;
491: }
492: }
1.91 www 493: }
1.128 albertel 494: if (domainfilter != null) {
495: if (domainfilter != '') {
496: url += 'domainfilter='+domainfilter+'&';
497: }
498: }
1.91 www 499: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 500: '&cdomelement='+udom+
501: '&cnameelement='+desc;
1.468 raeburn 502: if (extra_element !=null && extra_element != '') {
1.594 raeburn 503: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 504: url += '&roleelement='+extra_element;
505: if (domainfilter == null || domainfilter == '') {
506: url += '&domainfilter='+extra_element;
507: }
1.234 raeburn 508: }
1.468 raeburn 509: else {
510: if (formname == 'portform') {
511: url += '&setroles='+extra_element;
512: }
513: }
1.230 raeburn 514: }
1.293 raeburn 515: if (multflag !=null && multflag != '') {
516: url += '&multiple='+multflag;
517: }
1.377 raeburn 518: if (crstype == 'Course/Group') {
519: if (formname == 'cu') {
520: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
521: if (crstype == "") {
522: alert("$crs_or_grp_alert");
523: return;
524: }
525: }
526: }
527: if (crstype !=null && crstype != '') {
528: url += '&type='+crstype;
529: }
1.102 www 530: var title = 'Course_Browser';
1.91 www 531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
1.468 raeburn 536:
537: function getFormIdByName(formname) {
538: for (var i=0;i<document.forms.length;i++) {
539: if (document.forms[i].name == formname) {
540: return i;
541: }
542: }
543: return -1;
544: }
545:
546: function getIndexByName(formid,item) {
547: for (var i=0;i<document.forms[formid].elements.length;i++) {
548: if (document.forms[formid].elements[i].name == item) {
549: return i;
550: }
551: }
552: return -1;
553: }
1.91 www 554: ENDSTDBRW
1.468 raeburn 555: if ($sec_element ne '') {
556: $output .= &setsec_javascript($sec_element,$formname);
557: }
558: $output .= '
559: </script>';
560: return $output;
561: }
562:
563: sub setsec_javascript {
564: my ($sec_element,$formname) = @_;
565: my $setsections = qq|
566: function setSect(sectionlist) {
1.629 raeburn 567: var sectionsArray = new Array();
568: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
569: sectionsArray = sectionlist.split(",");
570: }
1.468 raeburn 571: var numSections = sectionsArray.length;
572: document.$formname.$sec_element.length = 0;
573: if (numSections == 0) {
574: document.$formname.$sec_element.multiple=false;
575: document.$formname.$sec_element.size=1;
576: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
577: } else {
578: if (numSections == 1) {
579: document.$formname.$sec_element.multiple=false;
580: document.$formname.$sec_element.size=1;
581: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
582: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
583: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
584: } else {
585: for (var i=0; i<numSections; i++) {
586: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
587: }
588: document.$formname.$sec_element.multiple=true
589: if (numSections < 3) {
590: document.$formname.$sec_element.size=numSections;
591: } else {
592: document.$formname.$sec_element.size=3;
593: }
594: document.$formname.$sec_element.options[0].selected = false
595: }
596: }
1.91 www 597: }
1.468 raeburn 598: |;
599: return $setsections;
600: }
601:
1.91 www 602:
603: sub selectcourse_link {
1.377 raeburn 604: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 605: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
606: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 607: }
1.42 matthew 608:
1.653 raeburn 609: sub selectauthor_link {
610: my ($form,$udom)=@_;
611: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
612: &mt('Select Author').'</a>';
613: }
614:
1.273 raeburn 615: sub check_uncheck_jscript {
616: my $jscript = <<"ENDSCRT";
617: function checkAll(field) {
618: if (field.length > 0) {
619: for (i = 0; i < field.length; i++) {
620: field[i].checked = true ;
621: }
622: } else {
623: field.checked = true
624: }
625: }
626:
627: function uncheckAll(field) {
628: if (field.length > 0) {
629: for (i = 0; i < field.length; i++) {
630: field[i].checked = false ;
1.543 albertel 631: }
632: } else {
1.273 raeburn 633: field.checked = false ;
634: }
635: }
636: ENDSCRT
637: return $jscript;
638: }
639:
1.656 www 640: sub select_timezone {
1.659 raeburn 641: my ($name,$selected,$onchange,$includeempty)=@_;
642: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
643: if ($includeempty) {
644: $output .= '<option value=""';
645: if (($selected eq '') || ($selected eq 'local')) {
646: $output .= ' selected="selected" ';
647: }
648: $output .= '> </option>';
649: }
1.657 raeburn 650: my @timezones = DateTime::TimeZone->all_names;
651: foreach my $tzone (@timezones) {
652: $output.= '<option value="'.$tzone.'"';
653: if ($tzone eq $selected) {
654: $output.=' selected="selected"';
655: }
656: $output.=">$tzone</option>\n";
1.656 www 657: }
658: $output.="</select>";
659: return $output;
660: }
1.273 raeburn 661:
1.687 raeburn 662: sub select_datelocale {
663: my ($name,$selected,$onchange,$includeempty)=@_;
664: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
665: if ($includeempty) {
666: $output .= '<option value=""';
667: if ($selected eq '') {
668: $output .= ' selected="selected" ';
669: }
670: $output .= '> </option>';
671: }
672: my (@possibles,%locale_names);
673: my @locales = DateTime::Locale::Catalog::Locales;
674: foreach my $locale (@locales) {
675: if (ref($locale) eq 'HASH') {
676: my $id = $locale->{'id'};
677: if ($id ne '') {
678: my $en_terr = $locale->{'en_territory'};
679: my $native_terr = $locale->{'native_territory'};
680: my @languages = &preferred_languages();
681: if (grep(/^en$/,@languages) || !@languages) {
682: if ($en_terr ne '') {
683: $locale_names{$id} = '('.$en_terr.')';
684: } elsif ($native_terr ne '') {
685: $locale_names{$id} = $native_terr;
686: }
687: } else {
688: if ($native_terr ne '') {
689: $locale_names{$id} = $native_terr.' ';
690: } elsif ($en_terr ne '') {
691: $locale_names{$id} = '('.$en_terr.')';
692: }
693: }
694: push (@possibles,$id);
695: }
696: }
697: }
698: foreach my $item (sort(@possibles)) {
699: $output.= '<option value="'.$item.'"';
700: if ($item eq $selected) {
701: $output.=' selected="selected"';
702: }
703: $output.=">$item";
704: if ($locale_names{$item} ne '') {
705: $output.=" $locale_names{$item}</option>\n";
706: }
707: $output.="</option>\n";
708: }
709: $output.="</select>";
710: return $output;
711: }
712:
1.42 matthew 713: =pod
1.36 matthew 714:
1.648 raeburn 715: =item * &linked_select_forms(...)
1.36 matthew 716:
717: linked_select_forms returns a string containing a <script></script> block
718: and html for two <select> menus. The select menus will be linked in that
719: changing the value of the first menu will result in new values being placed
720: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 721: order unless a defined order is provided.
1.36 matthew 722:
723: linked_select_forms takes the following ordered inputs:
724:
725: =over 4
726:
1.112 bowersj2 727: =item * $formname, the name of the <form> tag
1.36 matthew 728:
1.112 bowersj2 729: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 730:
1.112 bowersj2 731: =item * $firstdefault, the default value for the first menu
1.36 matthew 732:
1.112 bowersj2 733: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 734:
1.112 bowersj2 735: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 736:
1.112 bowersj2 737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 738:
1.609 raeburn 739: =item * $menuorder, the order of values in the first menu
740:
1.41 ng 741: =back
742:
1.36 matthew 743: Below is an example of such a hash. Only the 'text', 'default', and
744: 'select2' keys must appear as stated. keys(%menu) are the possible
745: values for the first select menu. The text that coincides with the
1.41 ng 746: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 747: and text for the second menu are given in the hash pointed to by
748: $menu{$choice1}->{'select2'}.
749:
1.112 bowersj2 750: my %menu = ( A1 => { text =>"Choice A1" ,
751: default => "B3",
752: select2 => {
753: B1 => "Choice B1",
754: B2 => "Choice B2",
755: B3 => "Choice B3",
756: B4 => "Choice B4"
1.609 raeburn 757: },
758: order => ['B4','B3','B1','B2'],
1.112 bowersj2 759: },
760: A2 => { text =>"Choice A2" ,
761: default => "C2",
762: select2 => {
763: C1 => "Choice C1",
764: C2 => "Choice C2",
765: C3 => "Choice C3"
1.609 raeburn 766: },
767: order => ['C2','C1','C3'],
1.112 bowersj2 768: },
769: A3 => { text =>"Choice A3" ,
770: default => "D6",
771: select2 => {
772: D1 => "Choice D1",
773: D2 => "Choice D2",
774: D3 => "Choice D3",
775: D4 => "Choice D4",
776: D5 => "Choice D5",
777: D6 => "Choice D6",
778: D7 => "Choice D7"
1.609 raeburn 779: },
780: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 781: }
782: );
1.36 matthew 783:
784: =cut
785:
786: sub linked_select_forms {
787: my ($formname,
788: $middletext,
789: $firstdefault,
790: $firstselectname,
791: $secondselectname,
1.609 raeburn 792: $hashref,
793: $menuorder,
1.36 matthew 794: ) = @_;
795: my $second = "document.$formname.$secondselectname";
796: my $first = "document.$formname.$firstselectname";
797: # output the javascript to do the changing
798: my $result = '';
1.219 albertel 799: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 800: $result.="var select2data = new Object();\n";
801: $" = '","';
802: my $debug = '';
803: foreach my $s1 (sort(keys(%$hashref))) {
804: $result.="select2data.d_$s1 = new Object();\n";
805: $result.="select2data.d_$s1.def = new String('".
806: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 807: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 808: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 809: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
810: @s2values = @{$hashref->{$s1}->{'order'}};
811: }
1.36 matthew 812: $result.="\"@s2values\");\n";
813: $result.="select2data.d_$s1.texts = new Array(";
814: my @s2texts;
815: foreach my $value (@s2values) {
816: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
817: }
818: $result.="\"@s2texts\");\n";
819: }
820: $"=' ';
821: $result.= <<"END";
822:
823: function select1_changed() {
824: // Determine new choice
825: var newvalue = "d_" + $first.value;
826: // update select2
827: var values = select2data[newvalue].values;
828: var texts = select2data[newvalue].texts;
829: var select2def = select2data[newvalue].def;
830: var i;
831: // out with the old
832: for (i = 0; i < $second.options.length; i++) {
833: $second.options[i] = null;
834: }
835: // in with the nuclear
836: for (i=0;i<values.length; i++) {
837: $second.options[i] = new Option(values[i]);
1.143 matthew 838: $second.options[i].value = values[i];
1.36 matthew 839: $second.options[i].text = texts[i];
840: if (values[i] == select2def) {
841: $second.options[i].selected = true;
842: }
843: }
844: }
845: </script>
846: END
847: # output the initial values for the selection lists
848: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 849: my @order = sort(keys(%{$hashref}));
850: if (ref($menuorder) eq 'ARRAY') {
851: @order = @{$menuorder};
852: }
853: foreach my $value (@order) {
1.36 matthew 854: $result.=" <option value=\"$value\" ";
1.253 albertel 855: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 856: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 857: }
858: $result .= "</select>\n";
859: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
860: $result .= $middletext;
861: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
862: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 863:
864: my @secondorder = sort(keys(%select2));
865: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
866: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
867: }
868: foreach my $value (@secondorder) {
1.36 matthew 869: $result.=" <option value=\"$value\" ";
1.253 albertel 870: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 871: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 872: }
873: $result .= "</select>\n";
874: # return $debug;
875: return $result;
876: } # end of sub linked_select_forms {
877:
1.45 matthew 878: =pod
1.44 bowersj2 879:
1.648 raeburn 880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 881:
1.112 bowersj2 882: Returns a string corresponding to an HTML link to the given help
883: $topic, where $topic corresponds to the name of a .tex file in
884: /home/httpd/html/adm/help/tex, with underscores replaced by
885: spaces.
886:
887: $text will optionally be linked to the same topic, allowing you to
888: link text in addition to the graphic. If you do not want to link
889: text, but wish to specify one of the later parameters, pass an
890: empty string.
891:
892: $stayOnPage is a value that will be interpreted as a boolean. If true,
893: the link will not open a new window. If false, the link will open
894: a new window using Javascript. (Default is false.)
895:
896: $width and $height are optional numerical parameters that will
897: override the width and height of the popped up window, which may
898: be useful for certain help topics with big pictures included.
1.44 bowersj2 899:
900: =cut
901:
902: sub help_open_topic {
1.48 bowersj2 903: my ($topic, $text, $stayOnPage, $width, $height) = @_;
904: $text = "" if (not defined $text);
1.44 bowersj2 905: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 906: if ($env{'browser.interface'} eq 'textual') {
1.79 www 907: $stayOnPage=1;
908: }
1.44 bowersj2 909: $width = 350 if (not defined $width);
910: $height = 400 if (not defined $height);
911: my $filename = $topic;
912: $filename =~ s/ /_/g;
913:
1.48 bowersj2 914: my $template = "";
915: my $link;
1.572 banghart 916:
1.159 www 917: $topic=~s/\W/\_/g;
1.44 bowersj2 918:
1.572 banghart 919: if (!$stayOnPage) {
1.72 bowersj2 920: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 921: } else {
1.48 bowersj2 922: $link = "/adm/help/${filename}.hlp";
923: }
924:
925: # Add the text
1.572 banghart 926: if ($text ne "") {
1.77 www 927: $template .=
1.572 banghart 928: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
1.691 bisitz 929: "<td bgcolor='#5555FF'><span class=\"LC_nobreak\"><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 930: }
931:
932: # Add the graphic
1.179 matthew 933: my $title = &mt('Online Help');
1.667 raeburn 934: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48 bowersj2 935: $template .= <<"ENDTEMPLATE";
1.436 albertel 936: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 937: ENDTEMPLATE
1.691 bisitz 938: if ($text ne '') { $template.='</span></td></tr></table>' };
1.44 bowersj2 939: return $template;
940:
1.106 bowersj2 941: }
942:
943: # This is a quicky function for Latex cheatsheet editing, since it
944: # appears in at least four places
945: sub helpLatexCheatsheet {
946: my $other = shift;
947: my $addOther = '';
948: if ($other) {
949: $addOther = Apache::loncommon::help_open_topic($other, shift,
950: undef, undef, 600) .
951: '</td><td>';
952: }
953: return '<table><tr><td>'.
954: $addOther .
1.636 raeburn 955: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
1.106 bowersj2 956: undef,undef,600)
957: .'</td><td>'.
1.636 raeburn 958: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
1.106 bowersj2 959: undef,undef,600)
1.673 felicia 960: .'</td><td>'.
961: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
962: undef,undef,600)
1.106 bowersj2 963: .'</td></tr></table>';
1.172 www 964: }
965:
1.430 albertel 966: sub general_help {
967: my $helptopic='Student_Intro';
968: if ($env{'request.role'}=~/^(ca|au)/) {
969: $helptopic='Authoring_Intro';
970: } elsif ($env{'request.role'}=~/^cc/) {
971: $helptopic='Course_Coordination_Intro';
1.672 raeburn 972: } elsif ($env{'request.role'}=~/^dc/) {
973: $helptopic='Domain_Coordination_Intro';
1.430 albertel 974: }
975: return $helptopic;
976: }
977:
978: sub update_help_link {
979: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
980: my $origurl = $ENV{'REQUEST_URI'};
981: $origurl=~s|^/~|/priv/|;
982: my $timestamp = time;
983: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
984: $$datum = &escape($$datum);
985: }
986:
987: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
988: my $output .= <<"ENDOUTPUT";
989: <script type="text/javascript">
990: banner_link = '$banner_link';
991: </script>
992: ENDOUTPUT
993: return $output;
994: }
995:
996: # now just updates the help link and generates a blue icon
1.193 raeburn 997: sub help_open_menu {
1.430 albertel 998: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 999: = @_;
1.430 albertel 1000: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1001: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1002: # if environment.remote is on (using remote control UI)
1.572 banghart 1003: if ($env{'browser.interface'} eq 'textual' ||
1004: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1005: $stayOnPage=1;
1.430 albertel 1006: }
1007: my $output;
1008: if ($component_help) {
1009: if (!$text) {
1010: $output=&help_open_topic($component_help,undef,$stayOnPage,
1011: $width,$height);
1012: } else {
1013: my $help_text;
1014: $help_text=&unescape($topic);
1015: $output='<table><tr><td>'.
1016: &help_open_topic($component_help,$help_text,$stayOnPage,
1017: $width,$height).'</td></tr></table>';
1018: }
1019: }
1020: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1021: return $output.$banner_link;
1022: }
1023:
1024: sub top_nav_help {
1025: my ($text) = @_;
1.436 albertel 1026: $text = &mt($text);
1.572 banghart 1027: my $stay_on_page =
1.436 albertel 1028: ($env{'browser.interface'} eq 'textual' ||
1029: $env{'environment.remote'} eq 'off' );
1.572 banghart 1030: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1031: : "javascript:helpMenu('open')";
1.572 banghart 1032: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1033:
1.201 raeburn 1034: my $title = &mt('Get help');
1.436 albertel 1035:
1036: return <<"END";
1037: $banner_link
1038: <a href="$link" title="$title">$text</a>
1039: END
1040: }
1041:
1042: sub help_menu_js {
1043: my ($text) = @_;
1044:
1045: my $stayOnPage =
1046: ($env{'browser.interface'} eq 'textual' ||
1047: $env{'environment.remote'} eq 'off' );
1048:
1049: my $width = 620;
1050: my $height = 600;
1.430 albertel 1051: my $helptopic=&general_help();
1052: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1053: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1054: my $start_page =
1055: &Apache::loncommon::start_page('Help Menu', undef,
1056: {'frameset' => 1,
1057: 'js_ready' => 1,
1058: 'add_entries' => {
1059: 'border' => '0',
1.579 raeburn 1060: 'rows' => "110,*",},});
1.331 albertel 1061: my $end_page =
1062: &Apache::loncommon::end_page({'frameset' => 1,
1063: 'js_ready' => 1,});
1064:
1.436 albertel 1065: my $template .= <<"ENDTEMPLATE";
1066: <script type="text/javascript">
1.253 albertel 1067: // <!-- BEGIN LON-CAPA Internal
1068: // <![CDATA[
1.430 albertel 1069: var banner_link = '';
1.243 raeburn 1070: function helpMenu(target) {
1071: var caller = this;
1072: if (target == 'open') {
1073: var newWindow = null;
1074: try {
1.262 albertel 1075: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1076: }
1077: catch(error) {
1078: writeHelp(caller);
1079: return;
1080: }
1081: if (newWindow) {
1082: caller = newWindow;
1083: }
1.193 raeburn 1084: }
1.243 raeburn 1085: writeHelp(caller);
1086: return;
1087: }
1088: function writeHelp(caller) {
1.430 albertel 1089: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1090: caller.document.close()
1091: caller.focus()
1.193 raeburn 1092: }
1.253 albertel 1093: // ]]>
1.219 albertel 1094: // END LON-CAPA Internal -->
1.436 albertel 1095: </script>
1.193 raeburn 1096: ENDTEMPLATE
1097: return $template;
1098: }
1099:
1.172 www 1100: sub help_open_bug {
1101: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1102: unless ($env{'user.adv'}) { return ''; }
1.172 www 1103: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1104: $text = "" if (not defined $text);
1105: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1106: if ($env{'browser.interface'} eq 'textual' ||
1107: $env{'environment.remote'} eq 'off' ) {
1.172 www 1108: $stayOnPage=1;
1109: }
1.184 albertel 1110: $width = 600 if (not defined $width);
1111: $height = 600 if (not defined $height);
1.172 www 1112:
1113: $topic=~s/\W+/\+/g;
1114: my $link='';
1115: my $template='';
1.379 albertel 1116: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1117: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1118: if (!$stayOnPage)
1119: {
1120: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1121: }
1122: else
1123: {
1124: $link = $url;
1125: }
1126: # Add the text
1127: if ($text ne "")
1128: {
1129: $template .=
1130: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1131: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1132: }
1133:
1134: # Add the graphic
1.179 matthew 1135: my $title = &mt('Report a Bug');
1.215 albertel 1136: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1137: $template .= <<"ENDTEMPLATE";
1.436 albertel 1138: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1139: ENDTEMPLATE
1140: if ($text ne '') { $template.='</td></tr></table>' };
1141: return $template;
1142:
1143: }
1144:
1145: sub help_open_faq {
1146: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1147: unless ($env{'user.adv'}) { return ''; }
1.172 www 1148: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1149: $text = "" if (not defined $text);
1150: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1151: if ($env{'browser.interface'} eq 'textual' ||
1152: $env{'environment.remote'} eq 'off' ) {
1.172 www 1153: $stayOnPage=1;
1154: }
1155: $width = 350 if (not defined $width);
1156: $height = 400 if (not defined $height);
1157:
1158: $topic=~s/\W+/\+/g;
1159: my $link='';
1160: my $template='';
1161: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1162: if (!$stayOnPage)
1163: {
1164: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1165: }
1166: else
1167: {
1168: $link = $url;
1169: }
1170:
1171: # Add the text
1172: if ($text ne "")
1173: {
1174: $template .=
1.173 www 1175: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1176: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1177: }
1178:
1179: # Add the graphic
1.179 matthew 1180: my $title = &mt('View the FAQ');
1.215 albertel 1181: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1182: $template .= <<"ENDTEMPLATE";
1.436 albertel 1183: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1184: ENDTEMPLATE
1185: if ($text ne '') { $template.='</td></tr></table>' };
1186: return $template;
1187:
1.44 bowersj2 1188: }
1.37 matthew 1189:
1.180 matthew 1190: ###############################################################
1191: ###############################################################
1192:
1.45 matthew 1193: =pod
1194:
1.648 raeburn 1195: =item * &change_content_javascript():
1.256 matthew 1196:
1197: This and the next function allow you to create small sections of an
1198: otherwise static HTML page that you can update on the fly with
1199: Javascript, even in Netscape 4.
1200:
1201: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1202: must be written to the HTML page once. It will prove the Javascript
1203: function "change(name, content)". Calling the change function with the
1204: name of the section
1205: you want to update, matching the name passed to C<changable_area>, and
1206: the new content you want to put in there, will put the content into
1207: that area.
1208:
1209: B<Note>: Netscape 4 only reserves enough space for the changable area
1210: to contain room for the original contents. You need to "make space"
1211: for whatever changes you wish to make, and be B<sure> to check your
1212: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1213: it's adequate for updating a one-line status display, but little more.
1214: This script will set the space to 100% width, so you only need to
1215: worry about height in Netscape 4.
1216:
1217: Modern browsers are much less limiting, and if you can commit to the
1218: user not using Netscape 4, this feature may be used freely with
1219: pretty much any HTML.
1220:
1221: =cut
1222:
1223: sub change_content_javascript {
1224: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1225: if ($env{'browser.type'} eq 'netscape' &&
1226: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1227: return (<<NETSCAPE4);
1228: function change(name, content) {
1229: doc = document.layers[name+"___escape"].layers[0].document;
1230: doc.open();
1231: doc.write(content);
1232: doc.close();
1233: }
1234: NETSCAPE4
1235: } else {
1236: # Otherwise, we need to use semi-standards-compliant code
1237: # (technically, "innerHTML" isn't standard but the equivalent
1238: # is really scary, and every useful browser supports it
1239: return (<<DOMBASED);
1240: function change(name, content) {
1241: element = document.getElementById(name);
1242: element.innerHTML = content;
1243: }
1244: DOMBASED
1245: }
1246: }
1247:
1248: =pod
1249:
1.648 raeburn 1250: =item * &changable_area($name,$origContent):
1.256 matthew 1251:
1252: This provides a "changable area" that can be modified on the fly via
1253: the Javascript code provided in C<change_content_javascript>. $name is
1254: the name you will use to reference the area later; do not repeat the
1255: same name on a given HTML page more then once. $origContent is what
1256: the area will originally contain, which can be left blank.
1257:
1258: =cut
1259:
1260: sub changable_area {
1261: my ($name, $origContent) = @_;
1262:
1.258 albertel 1263: if ($env{'browser.type'} eq 'netscape' &&
1264: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1265: # If this is netscape 4, we need to use the Layer tag
1266: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1267: } else {
1268: return "<span id='$name'>$origContent</span>";
1269: }
1270: }
1271:
1272: =pod
1273:
1.648 raeburn 1274: =item * &viewport_geometry_js
1.590 raeburn 1275:
1276: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1277:
1278: =cut
1279:
1280:
1281: sub viewport_geometry_js {
1282: return <<"GEOMETRY";
1283: var Geometry = {};
1284: function init_geometry() {
1285: if (Geometry.init) { return };
1286: Geometry.init=1;
1287: if (window.innerHeight) {
1288: Geometry.getViewportHeight = function() { return window.innerHeight; };
1289: Geometry.getViewportWidth = function() { return window.innerWidth; };
1290: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1291: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1292: }
1293: else if (document.documentElement && document.documentElement.clientHeight) {
1294: Geometry.getViewportHeight =
1295: function() { return document.documentElement.clientHeight; };
1296: Geometry.getViewportWidth =
1297: function() { return document.documentElement.clientWidth; };
1298:
1299: Geometry.getHorizontalScroll =
1300: function() { return document.documentElement.scrollLeft; };
1301: Geometry.getVerticalScroll =
1302: function() { return document.documentElement.scrollTop; };
1303: }
1304: else if (document.body.clientHeight) {
1305: Geometry.getViewportHeight =
1306: function() { return document.body.clientHeight; };
1307: Geometry.getViewportWidth =
1308: function() { return document.body.clientWidth; };
1309: Geometry.getHorizontalScroll =
1310: function() { return document.body.scrollLeft; };
1311: Geometry.getVerticalScroll =
1312: function() { return document.body.scrollTop; };
1313: }
1314: }
1315:
1316: GEOMETRY
1317: }
1318:
1319: =pod
1320:
1.648 raeburn 1321: =item * &viewport_size_js()
1.590 raeburn 1322:
1323: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1324:
1325: =cut
1326:
1327: sub viewport_size_js {
1328: my $geometry = &viewport_geometry_js();
1329: return <<"DIMS";
1330:
1331: $geometry
1332:
1333: function getViewportDims(width,height) {
1334: init_geometry();
1335: width.value = Geometry.getViewportWidth();
1336: height.value = Geometry.getViewportHeight();
1337: return;
1338: }
1339:
1340: DIMS
1341: }
1342:
1343: =pod
1344:
1.648 raeburn 1345: =item * &resize_textarea_js()
1.565 albertel 1346:
1347: emits the needed javascript to resize a textarea to be as big as possible
1348:
1349: creates a function resize_textrea that takes two IDs first should be
1350: the id of the element to resize, second should be the id of a div that
1351: surrounds everything that comes after the textarea, this routine needs
1352: to be attached to the <body> for the onload and onresize events.
1353:
1.648 raeburn 1354: =back
1.565 albertel 1355:
1356: =cut
1357:
1358: sub resize_textarea_js {
1.590 raeburn 1359: my $geometry = &viewport_geometry_js();
1.565 albertel 1360: return <<"RESIZE";
1361: <script type="text/javascript">
1.590 raeburn 1362: $geometry
1.565 albertel 1363:
1.588 albertel 1364: function getX(element) {
1365: var x = 0;
1366: while (element) {
1367: x += element.offsetLeft;
1368: element = element.offsetParent;
1369: }
1370: return x;
1371: }
1372: function getY(element) {
1373: var y = 0;
1374: while (element) {
1375: y += element.offsetTop;
1376: element = element.offsetParent;
1377: }
1378: return y;
1379: }
1380:
1381:
1.565 albertel 1382: function resize_textarea(textarea_id,bottom_id) {
1383: init_geometry();
1384: var textarea = document.getElementById(textarea_id);
1385: //alert(textarea);
1386:
1.588 albertel 1387: var textarea_top = getY(textarea);
1.565 albertel 1388: var textarea_height = textarea.offsetHeight;
1389: var bottom = document.getElementById(bottom_id);
1.588 albertel 1390: var bottom_top = getY(bottom);
1.565 albertel 1391: var bottom_height = bottom.offsetHeight;
1392: var window_height = Geometry.getViewportHeight();
1.588 albertel 1393: var fudge = 23;
1.565 albertel 1394: var new_height = window_height-fudge-textarea_top-bottom_height;
1395: if (new_height < 300) {
1396: new_height = 300;
1397: }
1398: textarea.style.height=new_height+'px';
1399: }
1400: </script>
1401: RESIZE
1402:
1403: }
1404:
1405: =pod
1406:
1.256 matthew 1407: =head1 Excel and CSV file utility routines
1408:
1409: =over 4
1410:
1411: =cut
1412:
1413: ###############################################################
1414: ###############################################################
1415:
1416: =pod
1417:
1.648 raeburn 1418: =item * &csv_translate($text)
1.37 matthew 1419:
1.185 www 1420: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1421: format.
1422:
1423: =cut
1424:
1.180 matthew 1425: ###############################################################
1426: ###############################################################
1.37 matthew 1427: sub csv_translate {
1428: my $text = shift;
1429: $text =~ s/\"/\"\"/g;
1.209 albertel 1430: $text =~ s/\n/ /g;
1.37 matthew 1431: return $text;
1432: }
1.180 matthew 1433:
1434: ###############################################################
1435: ###############################################################
1436:
1437: =pod
1438:
1.648 raeburn 1439: =item * &define_excel_formats()
1.180 matthew 1440:
1441: Define some commonly used Excel cell formats.
1442:
1443: Currently supported formats:
1444:
1445: =over 4
1446:
1447: =item header
1448:
1449: =item bold
1450:
1451: =item h1
1452:
1453: =item h2
1454:
1455: =item h3
1456:
1.256 matthew 1457: =item h4
1458:
1459: =item i
1460:
1.180 matthew 1461: =item date
1462:
1463: =back
1464:
1465: Inputs: $workbook
1466:
1467: Returns: $format, a hash reference.
1468:
1469: =cut
1470:
1471: ###############################################################
1472: ###############################################################
1473: sub define_excel_formats {
1474: my ($workbook) = @_;
1475: my $format;
1476: $format->{'header'} = $workbook->add_format(bold => 1,
1477: bottom => 1,
1478: align => 'center');
1479: $format->{'bold'} = $workbook->add_format(bold=>1);
1480: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1481: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1482: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1483: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1484: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1485: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1486: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1487: return $format;
1488: }
1489:
1490: ###############################################################
1491: ###############################################################
1.113 bowersj2 1492:
1493: =pod
1494:
1.648 raeburn 1495: =item * &create_workbook()
1.255 matthew 1496:
1497: Create an Excel worksheet. If it fails, output message on the
1498: request object and return undefs.
1499:
1500: Inputs: Apache request object
1501:
1502: Returns (undef) on failure,
1503: Excel worksheet object, scalar with filename, and formats
1504: from &Apache::loncommon::define_excel_formats on success
1505:
1506: =cut
1507:
1508: ###############################################################
1509: ###############################################################
1510: sub create_workbook {
1511: my ($r) = @_;
1512: #
1513: # Create the excel spreadsheet
1514: my $filename = '/prtspool/'.
1.258 albertel 1515: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1516: time.'_'.rand(1000000000).'.xls';
1517: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1518: if (! defined($workbook)) {
1519: $r->log_error("Error creating excel spreadsheet $filename: $!");
1520: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1521: "This error has been logged. ".
1522: "Please alert your LON-CAPA administrator").
1523: '</p>');
1524: return (undef);
1525: }
1526: #
1527: $workbook->set_tempdir('/home/httpd/perl/tmp');
1528: #
1529: my $format = &Apache::loncommon::define_excel_formats($workbook);
1530: return ($workbook,$filename,$format);
1531: }
1532:
1533: ###############################################################
1534: ###############################################################
1535:
1536: =pod
1537:
1.648 raeburn 1538: =item * &create_text_file()
1.113 bowersj2 1539:
1.542 raeburn 1540: Create a file to write to and eventually make available to the user.
1.256 matthew 1541: If file creation fails, outputs an error message on the request object and
1542: return undefs.
1.113 bowersj2 1543:
1.256 matthew 1544: Inputs: Apache request object, and file suffix
1.113 bowersj2 1545:
1.256 matthew 1546: Returns (undef) on failure,
1547: Filehandle and filename on success.
1.113 bowersj2 1548:
1549: =cut
1550:
1.256 matthew 1551: ###############################################################
1552: ###############################################################
1553: sub create_text_file {
1554: my ($r,$suffix) = @_;
1555: if (! defined($suffix)) { $suffix = 'txt'; };
1556: my $fh;
1557: my $filename = '/prtspool/'.
1.258 albertel 1558: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1559: time.'_'.rand(1000000000).'.'.$suffix;
1560: $fh = Apache::File->new('>/home/httpd'.$filename);
1561: if (! defined($fh)) {
1562: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1563: $r->print(&mt('Problems occurred in creating the output file. '
1564: .'This error has been logged. '
1565: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1566: }
1.256 matthew 1567: return ($fh,$filename)
1.113 bowersj2 1568: }
1569:
1570:
1.256 matthew 1571: =pod
1.113 bowersj2 1572:
1573: =back
1574:
1575: =cut
1.37 matthew 1576:
1577: ###############################################################
1.33 matthew 1578: ## Home server <option> list generating code ##
1579: ###############################################################
1.35 matthew 1580:
1.169 www 1581: # ------------------------------------------
1582:
1583: sub domain_select {
1584: my ($name,$value,$multiple)=@_;
1585: my %domains=map {
1.514 albertel 1586: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1587: } &Apache::lonnet::all_domains();
1.169 www 1588: if ($multiple) {
1589: $domains{''}=&mt('Any domain');
1.550 albertel 1590: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1591: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1592: } else {
1.550 albertel 1593: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1594: return &select_form($name,$value,%domains);
1595: }
1596: }
1597:
1.282 albertel 1598: #-------------------------------------------
1599:
1600: =pod
1601:
1.519 raeburn 1602: =head1 Routines for form select boxes
1603:
1604: =over 4
1605:
1.648 raeburn 1606: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1607:
1608: Returns a string containing a <select> element int multiple mode
1609:
1610:
1611: Args:
1612: $name - name of the <select> element
1.506 raeburn 1613: $value - scalar or array ref of values that should already be selected
1.282 albertel 1614: $size - number of rows long the select element is
1.283 albertel 1615: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1616: (shown text should already have been &mt())
1.506 raeburn 1617: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1618:
1.282 albertel 1619: =cut
1620:
1621: #-------------------------------------------
1.169 www 1622: sub multiple_select_form {
1.284 albertel 1623: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1624: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1625: my $output='';
1.191 matthew 1626: if (! defined($size)) {
1627: $size = 4;
1.283 albertel 1628: if (scalar(keys(%$hash))<4) {
1629: $size = scalar(keys(%$hash));
1.191 matthew 1630: }
1631: }
1.169 www 1632: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501 banghart 1633: my @order;
1.506 raeburn 1634: if (ref($order) eq 'ARRAY') {
1635: @order = @{$order};
1636: } else {
1637: @order = sort(keys(%$hash));
1.501 banghart 1638: }
1639: if (exists($$hash{'select_form_order'})) {
1640: @order = @{$$hash{'select_form_order'}};
1641: }
1642:
1.284 albertel 1643: foreach my $key (@order) {
1.356 albertel 1644: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1645: $output.='selected="selected" ' if ($selected{$key});
1646: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1647: }
1648: $output.="</select>\n";
1649: return $output;
1650: }
1651:
1.88 www 1652: #-------------------------------------------
1653:
1654: =pod
1655:
1.648 raeburn 1656: =item * &select_form($defdom,$name,%hash)
1.88 www 1657:
1658: Returns a string containing a <select name='$name' size='1'> form to
1659: allow a user to select options from a hash option_name => displayed text.
1660: See lonrights.pm for an example invocation and use.
1661:
1662: =cut
1663:
1664: #-------------------------------------------
1665: sub select_form {
1666: my ($def,$name,%hash) = @_;
1667: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1668: my @keys;
1669: if (exists($hash{'select_form_order'})) {
1670: @keys=@{$hash{'select_form_order'}};
1671: } else {
1672: @keys=sort(keys(%hash));
1673: }
1.356 albertel 1674: foreach my $key (@keys) {
1675: $selectform.=
1676: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1677: ($key eq $def ? 'selected="selected" ' : '').
1678: ">".&mt($hash{$key})."</option>\n";
1.88 www 1679: }
1680: $selectform.="</select>";
1681: return $selectform;
1682: }
1683:
1.475 www 1684: # For display filters
1685:
1686: sub display_filter {
1687: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1688: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475 www 1689: return '<nobr><label>'.&mt('Records [_1]',
1690: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1691: (&mt('all'),10,20,50,100,1000,10000))).
1.478 www 1692: '</label></nobr> <nobr>'.
1.475 www 1693: &mt('Filter [_1]',
1.477 www 1694: &select_form($env{'form.displayfilter'},
1695: 'displayfilter',
1696: ('currentfolder' => 'Current folder/page',
1697: 'containing' => 'Containing phrase',
1698: 'none' => 'None'))).
1.478 www 1699: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475 www 1700: }
1701:
1.167 www 1702: sub gradeleveldescription {
1703: my $gradelevel=shift;
1704: my %gradelevels=(0 => 'Not specified',
1705: 1 => 'Grade 1',
1706: 2 => 'Grade 2',
1707: 3 => 'Grade 3',
1708: 4 => 'Grade 4',
1709: 5 => 'Grade 5',
1710: 6 => 'Grade 6',
1711: 7 => 'Grade 7',
1712: 8 => 'Grade 8',
1713: 9 => 'Grade 9',
1714: 10 => 'Grade 10',
1715: 11 => 'Grade 11',
1716: 12 => 'Grade 12',
1717: 13 => 'Grade 13',
1718: 14 => '100 Level',
1719: 15 => '200 Level',
1720: 16 => '300 Level',
1721: 17 => '400 Level',
1722: 18 => 'Graduate Level');
1723: return &mt($gradelevels{$gradelevel});
1724: }
1725:
1.163 www 1726: sub select_level_form {
1727: my ($deflevel,$name)=@_;
1728: unless ($deflevel) { $deflevel=0; }
1.167 www 1729: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1730: for (my $i=0; $i<=18; $i++) {
1731: $selectform.="<option value=\"$i\" ".
1.253 albertel 1732: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1733: ">".&gradeleveldescription($i)."</option>\n";
1734: }
1735: $selectform.="</select>";
1736: return $selectform;
1.163 www 1737: }
1.167 www 1738:
1.35 matthew 1739: #-------------------------------------------
1740:
1.45 matthew 1741: =pod
1742:
1.648 raeburn 1743: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35 matthew 1744:
1745: Returns a string containing a <select name='$name' size='1'> form to
1746: allow a user to select the domain to preform an operation in.
1747: See loncreateuser.pm for an example invocation and use.
1748:
1.90 www 1749: If the $includeempty flag is set, it also includes an empty choice ("no domain
1750: selected");
1751:
1.563 raeburn 1752: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1753:
1.35 matthew 1754: =cut
1755:
1756: #-------------------------------------------
1.34 matthew 1757: sub select_dom_form {
1.563 raeburn 1758: my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550 albertel 1759: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1760: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1761: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356 albertel 1762: foreach my $dom (@domains) {
1763: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1764: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1765: if ($showdomdesc) {
1766: if ($dom ne '') {
1767: my $domdesc = &Apache::lonnet::domain($dom,'description');
1768: if ($domdesc ne '') {
1769: $selectdomain .= ' ('.$domdesc.')';
1770: }
1771: }
1772: }
1773: $selectdomain .= "</option>\n";
1.34 matthew 1774: }
1775: $selectdomain.="</select>";
1776: return $selectdomain;
1777: }
1778:
1.35 matthew 1779: #-------------------------------------------
1780:
1.45 matthew 1781: =pod
1782:
1.648 raeburn 1783: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1784:
1.586 raeburn 1785: input: 4 arguments (two required, two optional) -
1786: $domain - domain of new user
1787: $name - name of form element
1788: $default - Value of 'default' causes a default item to be first
1789: option, and selected by default.
1790: $hide - Value of 'hide' causes hiding of the name of the server,
1791: if 1 server found, or default, if 0 found.
1.594 raeburn 1792: output: returns 2 items:
1.586 raeburn 1793: (a) form element which contains either:
1794: (i) <select name="$name">
1795: <option value="$hostid1">$hostid $servers{$hostid}</option>
1796: <option value="$hostid2">$hostid $servers{$hostid}</option>
1797: </select>
1798: form item if there are multiple library servers in $domain, or
1799: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1800: if there is only one library server in $domain.
1801:
1802: (b) number of library servers found.
1803:
1804: See loncreateuser.pm for example of use.
1.35 matthew 1805:
1806: =cut
1807:
1808: #-------------------------------------------
1.586 raeburn 1809: sub home_server_form_item {
1810: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1811: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1812: my $result;
1813: my $numlib = keys(%servers);
1814: if ($numlib > 1) {
1815: $result .= '<select name="'.$name.'" />'."\n";
1816: if ($default) {
1817: $result .= '<option value="default" selected>'.&mt('default').
1818: '</option>'."\n";
1819: }
1820: foreach my $hostid (sort(keys(%servers))) {
1821: $result.= '<option value="'.$hostid.'">'.
1822: $hostid.' '.$servers{$hostid}."</option>\n";
1823: }
1824: $result .= '</select>'."\n";
1825: } elsif ($numlib == 1) {
1826: my $hostid;
1827: foreach my $item (keys(%servers)) {
1828: $hostid = $item;
1829: }
1830: $result .= '<input type="hidden" name="'.$name.'" value="'.
1831: $hostid.'" />';
1832: if (!$hide) {
1833: $result .= $hostid.' '.$servers{$hostid};
1834: }
1835: $result .= "\n";
1836: } elsif ($default) {
1837: $result .= '<input type="hidden" name="'.$name.
1838: '" value="default" />';
1839: if (!$hide) {
1840: $result .= &mt('default');
1841: }
1842: $result .= "\n";
1.33 matthew 1843: }
1.586 raeburn 1844: return ($result,$numlib);
1.33 matthew 1845: }
1.112 bowersj2 1846:
1847: =pod
1848:
1.534 albertel 1849: =back
1850:
1.112 bowersj2 1851: =cut
1.87 matthew 1852:
1853: ###############################################################
1.112 bowersj2 1854: ## Decoding User Agent ##
1.87 matthew 1855: ###############################################################
1856:
1857: =pod
1858:
1.112 bowersj2 1859: =head1 Decoding the User Agent
1860:
1861: =over 4
1862:
1863: =item * &decode_user_agent()
1.87 matthew 1864:
1865: Inputs: $r
1866:
1867: Outputs:
1868:
1869: =over 4
1870:
1.112 bowersj2 1871: =item * $httpbrowser
1.87 matthew 1872:
1.112 bowersj2 1873: =item * $clientbrowser
1.87 matthew 1874:
1.112 bowersj2 1875: =item * $clientversion
1.87 matthew 1876:
1.112 bowersj2 1877: =item * $clientmathml
1.87 matthew 1878:
1.112 bowersj2 1879: =item * $clientunicode
1.87 matthew 1880:
1.112 bowersj2 1881: =item * $clientos
1.87 matthew 1882:
1883: =back
1884:
1.157 matthew 1885: =back
1886:
1.87 matthew 1887: =cut
1888:
1889: ###############################################################
1890: ###############################################################
1891: sub decode_user_agent {
1.247 albertel 1892: my ($r)=@_;
1.87 matthew 1893: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1894: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1895: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1896: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1897: my $clientbrowser='unknown';
1898: my $clientversion='0';
1899: my $clientmathml='';
1900: my $clientunicode='0';
1901: for (my $i=0;$i<=$#browsertype;$i++) {
1902: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1903: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1904: $clientbrowser=$bname;
1905: $httpbrowser=~/$vreg/i;
1906: $clientversion=$1;
1907: $clientmathml=($clientversion>=$minv);
1908: $clientunicode=($clientversion>=$univ);
1909: }
1910: }
1911: my $clientos='unknown';
1912: if (($httpbrowser=~/linux/i) ||
1913: ($httpbrowser=~/unix/i) ||
1914: ($httpbrowser=~/ux/i) ||
1915: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1916: if (($httpbrowser=~/vax/i) ||
1917: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1918: if ($httpbrowser=~/next/i) { $clientos='next'; }
1919: if (($httpbrowser=~/mac/i) ||
1920: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1921: if ($httpbrowser=~/win/i) { $clientos='win'; }
1922: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1923: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1924: $clientunicode,$clientos,);
1925: }
1926:
1.32 matthew 1927: ###############################################################
1928: ## Authentication changing form generation subroutines ##
1929: ###############################################################
1930: ##
1931: ## All of the authform_xxxxxxx subroutines take their inputs in a
1932: ## hash, and have reasonable default values.
1933: ##
1934: ## formname = the name given in the <form> tag.
1.35 matthew 1935: #-------------------------------------------
1936:
1.45 matthew 1937: =pod
1938:
1.112 bowersj2 1939: =head1 Authentication Routines
1940:
1941: =over 4
1942:
1.648 raeburn 1943: =item * &authform_xxxxxx()
1.35 matthew 1944:
1945: The authform_xxxxxx subroutines provide javascript and html forms which
1946: handle some of the conveniences required for authentication forms.
1947: This is not an optimal method, but it works.
1948:
1949: =over 4
1950:
1.112 bowersj2 1951: =item * authform_header
1.35 matthew 1952:
1.112 bowersj2 1953: =item * authform_authorwarning
1.35 matthew 1954:
1.112 bowersj2 1955: =item * authform_nochange
1.35 matthew 1956:
1.112 bowersj2 1957: =item * authform_kerberos
1.35 matthew 1958:
1.112 bowersj2 1959: =item * authform_internal
1.35 matthew 1960:
1.112 bowersj2 1961: =item * authform_filesystem
1.35 matthew 1962:
1963: =back
1964:
1.648 raeburn 1965: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1966:
1.35 matthew 1967: =cut
1968:
1969: #-------------------------------------------
1.32 matthew 1970: sub authform_header{
1971: my %in = (
1972: formname => 'cu',
1.80 albertel 1973: kerb_def_dom => '',
1.32 matthew 1974: @_,
1975: );
1976: $in{'formname'} = 'document.' . $in{'formname'};
1977: my $result='';
1.80 albertel 1978:
1979: #---------------------------------------------- Code for upper case translation
1980: my $Javascript_toUpperCase;
1981: unless ($in{kerb_def_dom}) {
1982: $Javascript_toUpperCase =<<"END";
1983: switch (choice) {
1984: case 'krb': currentform.elements[choicearg].value =
1985: currentform.elements[choicearg].value.toUpperCase();
1986: break;
1987: default:
1988: }
1989: END
1990: } else {
1991: $Javascript_toUpperCase = "";
1992: }
1993:
1.165 raeburn 1994: my $radioval = "'nochange'";
1.591 raeburn 1995: if (defined($in{'curr_authtype'})) {
1996: if ($in{'curr_authtype'} ne '') {
1997: $radioval = "'".$in{'curr_authtype'}."arg'";
1998: }
1.174 matthew 1999: }
1.165 raeburn 2000: my $argfield = 'null';
1.591 raeburn 2001: if (defined($in{'mode'})) {
1.165 raeburn 2002: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2003: if (defined($in{'curr_autharg'})) {
2004: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2005: $argfield = "'$in{'curr_autharg'}'";
2006: }
2007: }
2008: }
2009: }
2010:
1.32 matthew 2011: $result.=<<"END";
2012: var current = new Object();
1.165 raeburn 2013: current.radiovalue = $radioval;
2014: current.argfield = $argfield;
1.32 matthew 2015:
2016: function changed_radio(choice,currentform) {
2017: var choicearg = choice + 'arg';
2018: // If a radio button in changed, we need to change the argfield
2019: if (current.radiovalue != choice) {
2020: current.radiovalue = choice;
2021: if (current.argfield != null) {
2022: currentform.elements[current.argfield].value = '';
2023: }
2024: if (choice == 'nochange') {
2025: current.argfield = null;
2026: } else {
2027: current.argfield = choicearg;
2028: switch(choice) {
2029: case 'krb':
2030: currentform.elements[current.argfield].value =
2031: "$in{'kerb_def_dom'}";
2032: break;
2033: default:
2034: break;
2035: }
2036: }
2037: }
2038: return;
2039: }
1.22 www 2040:
1.32 matthew 2041: function changed_text(choice,currentform) {
2042: var choicearg = choice + 'arg';
2043: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2044: $Javascript_toUpperCase
1.32 matthew 2045: // clear old field
2046: if ((current.argfield != choicearg) && (current.argfield != null)) {
2047: currentform.elements[current.argfield].value = '';
2048: }
2049: current.argfield = choicearg;
2050: }
2051: set_auth_radio_buttons(choice,currentform);
2052: return;
1.20 www 2053: }
1.32 matthew 2054:
2055: function set_auth_radio_buttons(newvalue,currentform) {
2056: var i=0;
2057: while (i < currentform.login.length) {
2058: if (currentform.login[i].value == newvalue) { break; }
2059: i++;
2060: }
2061: if (i == currentform.login.length) {
2062: return;
2063: }
2064: current.radiovalue = newvalue;
2065: currentform.login[i].checked = true;
2066: return;
2067: }
2068: END
2069: return $result;
2070: }
2071:
2072: sub authform_authorwarning{
2073: my $result='';
1.144 matthew 2074: $result='<i>'.
2075: &mt('As a general rule, only authors or co-authors should be '.
2076: 'filesystem authenticated '.
2077: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2078: return $result;
2079: }
2080:
2081: sub authform_nochange{
2082: my %in = (
2083: formname => 'document.cu',
2084: kerb_def_dom => 'MSU.EDU',
2085: @_,
2086: );
1.586 raeburn 2087: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2088: my $result;
2089: if (keys(%can_assign) == 0) {
2090: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2091: } else {
2092: $result = '<label>'.&mt('[_1] Do not change login data',
2093: '<input type="radio" name="login" value="nochange" '.
2094: 'checked="checked" onclick="'.
1.281 albertel 2095: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2096: '</label>';
1.586 raeburn 2097: }
1.32 matthew 2098: return $result;
2099: }
2100:
1.591 raeburn 2101: sub authform_kerberos {
1.32 matthew 2102: my %in = (
2103: formname => 'document.cu',
2104: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2105: kerb_def_auth => 'krb4',
1.32 matthew 2106: @_,
2107: );
1.586 raeburn 2108: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2109: $autharg,$jscall);
2110: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2111: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2112: $check5 = ' checked="on"';
1.80 albertel 2113: } else {
1.586 raeburn 2114: $check4 = ' checked="on"';
1.80 albertel 2115: }
1.165 raeburn 2116: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2117: if (defined($in{'curr_authtype'})) {
2118: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2119: $krbcheck = ' checked="on"';
1.623 raeburn 2120: if (defined($in{'mode'})) {
2121: if ($in{'mode'} eq 'modifyuser') {
2122: $krbcheck = '';
2123: }
2124: }
1.591 raeburn 2125: if (defined($in{'curr_kerb_ver'})) {
2126: if ($in{'curr_krb_ver'} eq '5') {
2127: $check5 = ' checked="on"';
2128: $check4 = '';
2129: } else {
2130: $check4 = ' checked="on"';
2131: $check5 = '';
2132: }
1.586 raeburn 2133: }
1.591 raeburn 2134: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2135: $krbarg = $in{'curr_autharg'};
2136: }
1.586 raeburn 2137: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2138: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2139: $result =
2140: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2141: $in{'curr_autharg'},$krbver);
2142: } else {
2143: $result =
2144: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2145: }
2146: return $result;
2147: }
2148: }
2149: } else {
2150: if ($authnum == 1) {
2151: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2152: }
2153: }
1.586 raeburn 2154: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2155: return;
1.587 raeburn 2156: } elsif ($authtype eq '') {
1.591 raeburn 2157: if (defined($in{'mode'})) {
1.587 raeburn 2158: if ($in{'mode'} eq 'modifycourse') {
2159: if ($authnum == 1) {
2160: $authtype = '<input type="hidden" name="login" value="krb">';
2161: }
2162: }
2163: }
1.586 raeburn 2164: }
2165: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2166: if ($authtype eq '') {
2167: $authtype = '<input type="radio" name="login" value="krb" '.
2168: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2169: $krbcheck.' />';
2170: }
2171: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2172: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2173: $in{'curr_authtype'} eq 'krb5') ||
2174: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2175: $in{'curr_authtype'} eq 'krb4')) {
2176: $result .= &mt
1.144 matthew 2177: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2178: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2179: '<label>'.$authtype,
1.281 albertel 2180: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2181: 'value="'.$krbarg.'" '.
1.144 matthew 2182: 'onchange="'.$jscall.'" />',
1.281 albertel 2183: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2184: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2185: '</label>');
1.586 raeburn 2186: } elsif ($can_assign{'krb4'}) {
2187: $result .= &mt
2188: ('[_1] Kerberos authenticated with domain [_2] '.
2189: '[_3] Version 4 [_4]',
2190: '<label>'.$authtype,
2191: '</label><input type="text" size="10" name="krbarg" '.
2192: 'value="'.$krbarg.'" '.
2193: 'onchange="'.$jscall.'" />',
2194: '<label><input type="hidden" name="krbver" value="4" />',
2195: '</label>');
2196: } elsif ($can_assign{'krb5'}) {
2197: $result .= &mt
2198: ('[_1] Kerberos authenticated with domain [_2] '.
2199: '[_3] Version 5 [_4]',
2200: '<label>'.$authtype,
2201: '</label><input type="text" size="10" name="krbarg" '.
2202: 'value="'.$krbarg.'" '.
2203: 'onchange="'.$jscall.'" />',
2204: '<label><input type="hidden" name="krbver" value="5" />',
2205: '</label>');
2206: }
1.32 matthew 2207: return $result;
2208: }
2209:
2210: sub authform_internal{
1.586 raeburn 2211: my %in = (
1.32 matthew 2212: formname => 'document.cu',
2213: kerb_def_dom => 'MSU.EDU',
2214: @_,
2215: );
1.586 raeburn 2216: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2217: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2218: if (defined($in{'curr_authtype'})) {
2219: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2220: if ($can_assign{'int'}) {
2221: $intcheck = 'checked="on" ';
1.623 raeburn 2222: if (defined($in{'mode'})) {
2223: if ($in{'mode'} eq 'modifyuser') {
2224: $intcheck = '';
2225: }
2226: }
1.591 raeburn 2227: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2228: $intarg = $in{'curr_autharg'};
2229: }
2230: } else {
2231: $result = &mt('Currently internally authenticated.');
2232: return $result;
1.165 raeburn 2233: }
2234: }
1.586 raeburn 2235: } else {
2236: if ($authnum == 1) {
2237: $authtype = '<input type="hidden" name="login" value="int">';
2238: }
2239: }
2240: if (!$can_assign{'int'}) {
2241: return;
1.587 raeburn 2242: } elsif ($authtype eq '') {
1.591 raeburn 2243: if (defined($in{'mode'})) {
1.587 raeburn 2244: if ($in{'mode'} eq 'modifycourse') {
2245: if ($authnum == 1) {
2246: $authtype = '<input type="hidden" name="login" value="int">';
2247: }
2248: }
2249: }
1.165 raeburn 2250: }
1.586 raeburn 2251: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2252: if ($authtype eq '') {
2253: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2254: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2255: }
1.605 bisitz 2256: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2257: $intarg.'" onchange="'.$jscall.'" />';
2258: $result = &mt
1.144 matthew 2259: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2260: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2261: $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2262: return $result;
2263: }
2264:
2265: sub authform_local{
2266: my %in = (
2267: formname => 'document.cu',
2268: kerb_def_dom => 'MSU.EDU',
2269: @_,
2270: );
1.586 raeburn 2271: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2272: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2273: if (defined($in{'curr_authtype'})) {
2274: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2275: if ($can_assign{'loc'}) {
2276: $loccheck = 'checked="on" ';
1.623 raeburn 2277: if (defined($in{'mode'})) {
2278: if ($in{'mode'} eq 'modifyuser') {
2279: $loccheck = '';
2280: }
2281: }
1.591 raeburn 2282: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2283: $locarg = $in{'curr_autharg'};
2284: }
2285: } else {
2286: $result = &mt('Currently using local (institutional) authentication.');
2287: return $result;
1.165 raeburn 2288: }
2289: }
1.586 raeburn 2290: } else {
2291: if ($authnum == 1) {
2292: $authtype = '<input type="hidden" name="login" value="loc">';
2293: }
2294: }
2295: if (!$can_assign{'loc'}) {
2296: return;
1.587 raeburn 2297: } elsif ($authtype eq '') {
1.591 raeburn 2298: if (defined($in{'mode'})) {
1.587 raeburn 2299: if ($in{'mode'} eq 'modifycourse') {
2300: if ($authnum == 1) {
2301: $authtype = '<input type="hidden" name="login" value="loc">';
2302: }
2303: }
2304: }
1.165 raeburn 2305: }
1.586 raeburn 2306: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2307: if ($authtype eq '') {
2308: $authtype = '<input type="radio" name="login" value="loc" '.
2309: $loccheck.' onchange="'.$jscall.'" onclick="'.
2310: $jscall.'" />';
2311: }
2312: $autharg = '<input type="text" size="10" name="locarg" value="'.
2313: $locarg.'" onchange="'.$jscall.'" />';
2314: $result = &mt('[_1] Local Authentication with argument [_2]',
2315: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2316: return $result;
2317: }
2318:
2319: sub authform_filesystem{
2320: my %in = (
2321: formname => 'document.cu',
2322: kerb_def_dom => 'MSU.EDU',
2323: @_,
2324: );
1.586 raeburn 2325: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2326: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2327: if (defined($in{'curr_authtype'})) {
2328: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2329: if ($can_assign{'fsys'}) {
2330: $fsyscheck = 'checked="on" ';
1.623 raeburn 2331: if (defined($in{'mode'})) {
2332: if ($in{'mode'} eq 'modifyuser') {
2333: $fsyscheck = '';
2334: }
2335: }
1.586 raeburn 2336: } else {
2337: $result = &mt('Currently Filesystem Authenticated.');
2338: return $result;
2339: }
2340: }
2341: } else {
2342: if ($authnum == 1) {
2343: $authtype = '<input type="hidden" name="login" value="fsys">';
2344: }
2345: }
2346: if (!$can_assign{'fsys'}) {
2347: return;
1.587 raeburn 2348: } elsif ($authtype eq '') {
1.591 raeburn 2349: if (defined($in{'mode'})) {
1.587 raeburn 2350: if ($in{'mode'} eq 'modifycourse') {
2351: if ($authnum == 1) {
2352: $authtype = '<input type="hidden" name="login" value="fsys">';
2353: }
2354: }
2355: }
1.586 raeburn 2356: }
2357: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2358: if ($authtype eq '') {
2359: $authtype = '<input type="radio" name="login" value="fsys" '.
2360: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2361: $jscall.'" />';
2362: }
2363: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2364: ' onchange="'.$jscall.'" />';
2365: $result = &mt
1.144 matthew 2366: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2367: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2368: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2369: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2370: 'onchange="'.$jscall.'" />');
1.32 matthew 2371: return $result;
2372: }
2373:
1.586 raeburn 2374: sub get_assignable_auth {
2375: my ($dom) = @_;
2376: if ($dom eq '') {
2377: $dom = $env{'request.role.domain'};
2378: }
2379: my %can_assign = (
2380: krb4 => 1,
2381: krb5 => 1,
2382: int => 1,
2383: loc => 1,
2384: );
2385: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2386: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2387: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2388: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2389: my $context;
2390: if ($env{'request.role'} =~ /^au/) {
2391: $context = 'author';
2392: } elsif ($env{'request.role'} =~ /^dc/) {
2393: $context = 'domain';
2394: } elsif ($env{'request.course.id'}) {
2395: $context = 'course';
2396: }
2397: if ($context) {
2398: if (ref($authhash->{$context}) eq 'HASH') {
2399: %can_assign = %{$authhash->{$context}};
2400: }
2401: }
2402: }
2403: }
2404: my $authnum = 0;
2405: foreach my $key (keys(%can_assign)) {
2406: if ($can_assign{$key}) {
2407: $authnum ++;
2408: }
2409: }
2410: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2411: $authnum --;
2412: }
2413: return ($authnum,%can_assign);
2414: }
2415:
1.80 albertel 2416: ###############################################################
2417: ## Get Kerberos Defaults for Domain ##
2418: ###############################################################
2419: ##
2420: ## Returns default kerberos version and an associated argument
2421: ## as listed in file domain.tab. If not listed, provides
2422: ## appropriate default domain and kerberos version.
2423: ##
2424: #-------------------------------------------
2425:
2426: =pod
2427:
1.648 raeburn 2428: =item * &get_kerberos_defaults()
1.80 albertel 2429:
2430: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2431: version and domain. If not found, it defaults to version 4 and the
2432: domain of the server.
1.80 albertel 2433:
1.648 raeburn 2434: =over 4
2435:
1.80 albertel 2436: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2437:
1.648 raeburn 2438: =back
2439:
2440: =back
2441:
1.80 albertel 2442: =cut
2443:
2444: #-------------------------------------------
2445: sub get_kerberos_defaults {
2446: my $domain=shift;
1.641 raeburn 2447: my ($krbdef,$krbdefdom);
2448: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2449: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2450: $krbdef = $domdefaults{'auth_def'};
2451: $krbdefdom = $domdefaults{'auth_arg_def'};
2452: } else {
1.80 albertel 2453: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2454: my $krbdefdom=$1;
2455: $krbdefdom=~tr/a-z/A-Z/;
2456: $krbdef = "krb4";
2457: }
2458: return ($krbdef,$krbdefdom);
2459: }
1.112 bowersj2 2460:
1.32 matthew 2461:
1.46 matthew 2462: ###############################################################
2463: ## Thesaurus Functions ##
2464: ###############################################################
1.20 www 2465:
1.46 matthew 2466: =pod
1.20 www 2467:
1.112 bowersj2 2468: =head1 Thesaurus Functions
2469:
2470: =over 4
2471:
1.648 raeburn 2472: =item * &initialize_keywords()
1.46 matthew 2473:
2474: Initializes the package variable %Keywords if it is empty. Uses the
2475: package variable $thesaurus_db_file.
2476:
2477: =cut
2478:
2479: ###################################################
2480:
2481: sub initialize_keywords {
2482: return 1 if (scalar keys(%Keywords));
2483: # If we are here, %Keywords is empty, so fill it up
2484: # Make sure the file we need exists...
2485: if (! -e $thesaurus_db_file) {
2486: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2487: " failed because it does not exist");
2488: return 0;
2489: }
2490: # Set up the hash as a database
2491: my %thesaurus_db;
2492: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2493: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2494: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2495: $thesaurus_db_file);
2496: return 0;
2497: }
2498: # Get the average number of appearances of a word.
2499: my $avecount = $thesaurus_db{'average.count'};
2500: # Put keywords (those that appear > average) into %Keywords
2501: while (my ($word,$data)=each (%thesaurus_db)) {
2502: my ($count,undef) = split /:/,$data;
2503: $Keywords{$word}++ if ($count > $avecount);
2504: }
2505: untie %thesaurus_db;
2506: # Remove special values from %Keywords.
1.356 albertel 2507: foreach my $value ('total.count','average.count') {
2508: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2509: }
1.46 matthew 2510: return 1;
2511: }
2512:
2513: ###################################################
2514:
2515: =pod
2516:
1.648 raeburn 2517: =item * &keyword($word)
1.46 matthew 2518:
2519: Returns true if $word is a keyword. A keyword is a word that appears more
2520: than the average number of times in the thesaurus database. Calls
2521: &initialize_keywords
2522:
2523: =cut
2524:
2525: ###################################################
1.20 www 2526:
2527: sub keyword {
1.46 matthew 2528: return if (!&initialize_keywords());
2529: my $word=lc(shift());
2530: $word=~s/\W//g;
2531: return exists($Keywords{$word});
1.20 www 2532: }
1.46 matthew 2533:
2534: ###############################################################
2535:
2536: =pod
1.20 www 2537:
1.648 raeburn 2538: =item * &get_related_words()
1.46 matthew 2539:
1.160 matthew 2540: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2541: an array of words. If the keyword is not in the thesaurus, an empty array
2542: will be returned. The order of the words returned is determined by the
2543: database which holds them.
2544:
2545: Uses global $thesaurus_db_file.
2546:
2547: =cut
2548:
2549: ###############################################################
2550: sub get_related_words {
2551: my $keyword = shift;
2552: my %thesaurus_db;
2553: if (! -e $thesaurus_db_file) {
2554: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2555: "failed because the file does not exist");
2556: return ();
2557: }
2558: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2559: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2560: return ();
2561: }
2562: my @Words=();
1.429 www 2563: my $count=0;
1.46 matthew 2564: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2565: # The first element is the number of times
2566: # the word appears. We do not need it now.
1.429 www 2567: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2568: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2569: my $threshold=$mostfrequentcount/10;
2570: foreach my $possibleword (@RelatedWords) {
2571: my ($word,$wordcount)=split(/\,/,$possibleword);
2572: if ($wordcount>$threshold) {
2573: push(@Words,$word);
2574: $count++;
2575: if ($count>10) { last; }
2576: }
1.20 www 2577: }
2578: }
1.46 matthew 2579: untie %thesaurus_db;
2580: return @Words;
1.14 harris41 2581: }
1.46 matthew 2582:
1.112 bowersj2 2583: =pod
2584:
2585: =back
2586:
2587: =cut
1.61 www 2588:
2589: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2590: =pod
2591:
1.112 bowersj2 2592: =head1 User Name Functions
2593:
2594: =over 4
2595:
1.648 raeburn 2596: =item * &plainname($uname,$udom,$first)
1.81 albertel 2597:
1.112 bowersj2 2598: Takes a users logon name and returns it as a string in
1.226 albertel 2599: "first middle last generation" form
2600: if $first is set to 'lastname' then it returns it as
2601: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2602:
2603: =cut
1.61 www 2604:
1.295 www 2605:
1.81 albertel 2606: ###############################################################
1.61 www 2607: sub plainname {
1.226 albertel 2608: my ($uname,$udom,$first)=@_;
1.537 albertel 2609: return if (!defined($uname) || !defined($udom));
1.295 www 2610: my %names=&getnames($uname,$udom);
1.226 albertel 2611: my $name=&Apache::lonnet::format_name($names{'firstname'},
2612: $names{'middlename'},
2613: $names{'lastname'},
2614: $names{'generation'},$first);
2615: $name=~s/^\s+//;
1.62 www 2616: $name=~s/\s+$//;
2617: $name=~s/\s+/ /g;
1.353 albertel 2618: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2619: return $name;
1.61 www 2620: }
1.66 www 2621:
2622: # -------------------------------------------------------------------- Nickname
1.81 albertel 2623: =pod
2624:
1.648 raeburn 2625: =item * &nickname($uname,$udom)
1.81 albertel 2626:
2627: Gets a users name and returns it as a string as
2628:
2629: ""nickname""
1.66 www 2630:
1.81 albertel 2631: if the user has a nickname or
2632:
2633: "first middle last generation"
2634:
2635: if the user does not
2636:
2637: =cut
1.66 www 2638:
2639: sub nickname {
2640: my ($uname,$udom)=@_;
1.537 albertel 2641: return if (!defined($uname) || !defined($udom));
1.295 www 2642: my %names=&getnames($uname,$udom);
1.68 albertel 2643: my $name=$names{'nickname'};
1.66 www 2644: if ($name) {
2645: $name='"'.$name.'"';
2646: } else {
2647: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2648: $names{'lastname'}.' '.$names{'generation'};
2649: $name=~s/\s+$//;
2650: $name=~s/\s+/ /g;
2651: }
2652: return $name;
2653: }
2654:
1.295 www 2655: sub getnames {
2656: my ($uname,$udom)=@_;
1.537 albertel 2657: return if (!defined($uname) || !defined($udom));
1.433 albertel 2658: if ($udom eq 'public' && $uname eq 'public') {
2659: return ('lastname' => &mt('Public'));
2660: }
1.295 www 2661: my $id=$uname.':'.$udom;
2662: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2663: if ($cached) {
2664: return %{$names};
2665: } else {
2666: my %loadnames=&Apache::lonnet::get('environment',
2667: ['firstname','middlename','lastname','generation','nickname'],
2668: $udom,$uname);
2669: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2670: return %loadnames;
2671: }
2672: }
1.61 www 2673:
1.542 raeburn 2674: # -------------------------------------------------------------------- getemails
1.648 raeburn 2675:
1.542 raeburn 2676: =pod
2677:
1.648 raeburn 2678: =item * &getemails($uname,$udom)
1.542 raeburn 2679:
2680: Gets a user's email information and returns it as a hash with keys:
2681: notification, critnotification, permanentemail
2682:
2683: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2684: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2685:
1.648 raeburn 2686:
1.542 raeburn 2687: =cut
2688:
1.648 raeburn 2689:
1.466 albertel 2690: sub getemails {
2691: my ($uname,$udom)=@_;
2692: if ($udom eq 'public' && $uname eq 'public') {
2693: return;
2694: }
1.467 www 2695: if (!$udom) { $udom=$env{'user.domain'}; }
2696: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2697: my $id=$uname.':'.$udom;
2698: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2699: if ($cached) {
2700: return %{$names};
2701: } else {
2702: my %loadnames=&Apache::lonnet::get('environment',
2703: ['notification','critnotification',
2704: 'permanentemail'],
2705: $udom,$uname);
2706: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2707: return %loadnames;
2708: }
2709: }
2710:
1.551 albertel 2711: sub flush_email_cache {
2712: my ($uname,$udom)=@_;
2713: if (!$udom) { $udom =$env{'user.domain'}; }
2714: if (!$uname) { $uname=$env{'user.name'}; }
2715: return if ($udom eq 'public' && $uname eq 'public');
2716: my $id=$uname.':'.$udom;
2717: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2718: }
2719:
1.61 www 2720: # ------------------------------------------------------------------ Screenname
1.81 albertel 2721:
2722: =pod
2723:
1.648 raeburn 2724: =item * &screenname($uname,$udom)
1.81 albertel 2725:
2726: Gets a users screenname and returns it as a string
2727:
2728: =cut
1.61 www 2729:
2730: sub screenname {
2731: my ($uname,$udom)=@_;
1.258 albertel 2732: if ($uname eq $env{'user.name'} &&
2733: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2734: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2735: return $names{'screenname'};
1.62 www 2736: }
2737:
1.212 albertel 2738:
1.62 www 2739: # ------------------------------------------------------------- Message Wrapper
2740:
2741: sub messagewrapper {
1.369 www 2742: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2743: return
1.441 albertel 2744: '<a href="/adm/email?compose=individual&'.
2745: 'recname='.$username.'&recdom='.$domain.
2746: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2747: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2748: }
2749: # --------------------------------------------------------------- Notes Wrapper
2750:
2751: sub noteswrapper {
2752: my ($link,$un,$do)=@_;
2753: return
2754: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2755: }
2756: # ------------------------------------------------------------- Aboutme Wrapper
2757:
2758: sub aboutmewrapper {
1.166 www 2759: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2760: if (!defined($username) && !defined($domain)) {
2761: return;
2762: }
1.205 www 2763: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2764: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2765: }
2766:
2767: # ------------------------------------------------------------ Syllabus Wrapper
2768:
2769:
2770: sub syllabuswrapper {
1.109 matthew 2771: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2772: if ($fontcolor) {
2773: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2774: }
1.208 matthew 2775: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2776: }
1.14 harris41 2777:
1.208 matthew 2778: sub track_student_link {
1.268 albertel 2779: my ($linktext,$sname,$sdom,$target,$start) = @_;
2780: my $link ="/adm/trackstudent?";
1.208 matthew 2781: my $title = 'View recent activity';
2782: if (defined($sname) && $sname !~ /^\s*$/ &&
2783: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2784: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2785: $title .= ' of this student';
1.268 albertel 2786: }
1.208 matthew 2787: if (defined($target) && $target !~ /^\s*$/) {
2788: $target = qq{target="$target"};
2789: } else {
2790: $target = '';
2791: }
1.268 albertel 2792: if ($start) { $link.='&start='.$start; }
1.554 albertel 2793: $title = &mt($title);
2794: $linktext = &mt($linktext);
1.448 albertel 2795: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2796: &help_open_topic('View_recent_activity');
1.208 matthew 2797: }
2798:
1.508 www 2799: # ===================================================== Display a student photo
2800:
2801:
1.509 albertel 2802: sub student_image_tag {
1.508 www 2803: my ($domain,$user)=@_;
2804: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2805: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2806: return '<img src="'.$imgsrc.'" align="right" />';
2807: } else {
2808: return '';
2809: }
2810: }
2811:
1.112 bowersj2 2812: =pod
2813:
2814: =back
2815:
2816: =head1 Access .tab File Data
2817:
2818: =over 4
2819:
1.648 raeburn 2820: =item * &languageids()
1.112 bowersj2 2821:
2822: returns list of all language ids
2823:
2824: =cut
2825:
1.14 harris41 2826: sub languageids {
1.16 harris41 2827: return sort(keys(%language));
1.14 harris41 2828: }
2829:
1.112 bowersj2 2830: =pod
2831:
1.648 raeburn 2832: =item * &languagedescription()
1.112 bowersj2 2833:
2834: returns description of a specified language id
2835:
2836: =cut
2837:
1.14 harris41 2838: sub languagedescription {
1.125 www 2839: my $code=shift;
2840: return ($supported_language{$code}?'* ':'').
2841: $language{$code}.
1.126 www 2842: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2843: }
2844:
2845: sub plainlanguagedescription {
2846: my $code=shift;
2847: return $language{$code};
2848: }
2849:
2850: sub supportedlanguagecode {
2851: my $code=shift;
2852: return $supported_language{$code};
1.97 www 2853: }
2854:
1.112 bowersj2 2855: =pod
2856:
1.648 raeburn 2857: =item * ©rightids()
1.112 bowersj2 2858:
2859: returns list of all copyrights
2860:
2861: =cut
2862:
2863: sub copyrightids {
2864: return sort(keys(%cprtag));
2865: }
2866:
2867: =pod
2868:
1.648 raeburn 2869: =item * ©rightdescription()
1.112 bowersj2 2870:
2871: returns description of a specified copyright id
2872:
2873: =cut
2874:
2875: sub copyrightdescription {
1.166 www 2876: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2877: }
1.197 matthew 2878:
2879: =pod
2880:
1.648 raeburn 2881: =item * &source_copyrightids()
1.192 taceyjo1 2882:
2883: returns list of all source copyrights
2884:
2885: =cut
2886:
2887: sub source_copyrightids {
2888: return sort(keys(%scprtag));
2889: }
2890:
2891: =pod
2892:
1.648 raeburn 2893: =item * &source_copyrightdescription()
1.192 taceyjo1 2894:
2895: returns description of a specified source copyright id
2896:
2897: =cut
2898:
2899: sub source_copyrightdescription {
2900: return &mt($scprtag{shift(@_)});
2901: }
1.112 bowersj2 2902:
2903: =pod
2904:
1.648 raeburn 2905: =item * &filecategories()
1.112 bowersj2 2906:
2907: returns list of all file categories
2908:
2909: =cut
2910:
2911: sub filecategories {
2912: return sort(keys(%category_extensions));
2913: }
2914:
2915: =pod
2916:
1.648 raeburn 2917: =item * &filecategorytypes()
1.112 bowersj2 2918:
2919: returns list of file types belonging to a given file
2920: category
2921:
2922: =cut
2923:
2924: sub filecategorytypes {
1.356 albertel 2925: my ($cat) = @_;
2926: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2927: }
2928:
2929: =pod
2930:
1.648 raeburn 2931: =item * &fileembstyle()
1.112 bowersj2 2932:
2933: returns embedding style for a specified file type
2934:
2935: =cut
2936:
2937: sub fileembstyle {
2938: return $fe{lc(shift(@_))};
1.169 www 2939: }
2940:
1.351 www 2941: sub filemimetype {
2942: return $fm{lc(shift(@_))};
2943: }
2944:
1.169 www 2945:
2946: sub filecategoryselect {
2947: my ($name,$value)=@_;
1.189 matthew 2948: return &select_form($value,$name,
1.169 www 2949: '' => &mt('Any category'),
2950: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2951: }
2952:
2953: =pod
2954:
1.648 raeburn 2955: =item * &filedescription()
1.112 bowersj2 2956:
2957: returns description for a specified file type
2958:
2959: =cut
2960:
2961: sub filedescription {
1.188 matthew 2962: my $file_description = $fd{lc(shift())};
2963: $file_description =~ s:([\[\]]):~$1:g;
2964: return &mt($file_description);
1.112 bowersj2 2965: }
2966:
2967: =pod
2968:
1.648 raeburn 2969: =item * &filedescriptionex()
1.112 bowersj2 2970:
2971: returns description for a specified file type with
2972: extra formatting
2973:
2974: =cut
2975:
2976: sub filedescriptionex {
2977: my $ex=shift;
1.188 matthew 2978: my $file_description = $fd{lc($ex)};
2979: $file_description =~ s:([\[\]]):~$1:g;
2980: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 2981: }
2982:
2983: # End of .tab access
2984: =pod
2985:
2986: =back
2987:
2988: =cut
2989:
2990: # ------------------------------------------------------------------ File Types
2991: sub fileextensions {
2992: return sort(keys(%fe));
2993: }
2994:
1.97 www 2995: # ----------------------------------------------------------- Display Languages
2996: # returns a hash with all desired display languages
2997: #
2998:
2999: sub display_languages {
3000: my %languages=();
1.356 albertel 3001: foreach my $lang (&preferred_languages()) {
3002: $languages{$lang}=1;
1.97 www 3003: }
3004: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3005: if ($env{'form.displaylanguage'}) {
1.356 albertel 3006: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3007: $languages{$lang}=1;
1.97 www 3008: }
3009: }
3010: return %languages;
1.14 harris41 3011: }
3012:
1.117 www 3013: sub preferred_languages {
3014: my @languages=();
1.654 www 3015: if (($env{'request.role.adv'}) && ($env{'form.languages'})) {
3016: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$env{'form.languages'}));
3017: }
1.258 albertel 3018: if ($env{'course.'.$env{'request.course.id'}.'.languages'}) {
1.117 www 3019: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
1.258 albertel 3020: $env{'course.'.$env{'request.course.id'}.'.languages'}));
1.177 www 3021: }
1.654 www 3022:
1.258 albertel 3023: if ($env{'environment.languages'}) {
1.459 albertel 3024: @languages=(@languages,
3025: split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
1.118 www 3026: }
1.583 albertel 3027: my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'};
1.162 www 3028: if ($browser) {
1.583 albertel 3029: my @browser =
3030: map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
3031: push(@languages,@browser);
1.162 www 3032: }
1.641 raeburn 3033:
3034: foreach my $domtype ($env{'user.domain'},$env{'request.role.domain'},
3035: $Apache::lonnet::perlvar{'lonDefDomain'}) {
3036: if ($domtype ne '') {
3037: my %domdefs = &Apache::lonnet::get_domain_defaults($domtype);
3038: if ($domdefs{'lang_def'} ne '') {
3039: push(@languages,$domdefs{'lang_def'});
3040: }
3041: }
1.118 www 3042: }
1.686 raeburn 3043: return &get_genlanguages(@languages);
3044: }
3045:
3046: sub get_genlanguages {
3047: my (@languages) = @_;
1.118 www 3048: # turn "en-ca" into "en-ca,en"
3049: my @genlanguages;
1.356 albertel 3050: foreach my $lang (@languages) {
1.686 raeburn 3051: unless ($lang=~/\w/) { next; }
3052: push(@genlanguages,$lang);
3053: if ($lang=~/(\-|\_)/) {
3054: push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
3055: }
1.118 www 3056: }
1.583 albertel 3057: #uniqueify the languages list
3058: my %count;
3059: @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages;
1.118 www 3060: return @genlanguages;
1.117 www 3061: }
3062:
1.582 albertel 3063: sub languages {
3064: my ($possible_langs) = @_;
3065: my @preferred_langs = &preferred_languages();
3066: if (!ref($possible_langs)) {
3067: if( wantarray ) {
3068: return @preferred_langs;
3069: } else {
3070: return $preferred_langs[0];
3071: }
3072: }
3073: my %possibilities = map { $_ => 1 } (@$possible_langs);
3074: my @preferred_possibilities;
3075: foreach my $preferred_lang (@preferred_langs) {
3076: if (exists($possibilities{$preferred_lang})) {
3077: push(@preferred_possibilities, $preferred_lang);
3078: }
3079: }
3080: if( wantarray ) {
3081: return @preferred_possibilities;
3082: }
3083: return $preferred_possibilities[0];
3084: }
3085:
1.112 bowersj2 3086: ###############################################################
3087: ## Student Answer Attempts ##
3088: ###############################################################
3089:
3090: =pod
3091:
3092: =head1 Alternate Problem Views
3093:
3094: =over 4
3095:
1.648 raeburn 3096: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3097: $getattempt, $regexp, $gradesub)
3098:
3099: Return string with previous attempt on problem. Arguments:
3100:
3101: =over 4
3102:
3103: =item * $symb: Problem, including path
3104:
3105: =item * $username: username of the desired student
3106:
3107: =item * $domain: domain of the desired student
1.14 harris41 3108:
1.112 bowersj2 3109: =item * $course: Course ID
1.14 harris41 3110:
1.112 bowersj2 3111: =item * $getattempt: Leave blank for all attempts, otherwise put
3112: something
1.14 harris41 3113:
1.112 bowersj2 3114: =item * $regexp: if string matches this regexp, the string will be
3115: sent to $gradesub
1.14 harris41 3116:
1.112 bowersj2 3117: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3118:
1.112 bowersj2 3119: =back
1.14 harris41 3120:
1.112 bowersj2 3121: The output string is a table containing all desired attempts, if any.
1.16 harris41 3122:
1.112 bowersj2 3123: =cut
1.1 albertel 3124:
3125: sub get_previous_attempt {
1.43 ng 3126: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3127: my $prevattempts='';
1.43 ng 3128: no strict 'refs';
1.1 albertel 3129: if ($symb) {
1.3 albertel 3130: my (%returnhash)=
3131: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3132: if ($returnhash{'version'}) {
3133: my %lasthash=();
3134: my $version;
3135: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3136: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3137: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3138: }
1.1 albertel 3139: }
1.596 albertel 3140: $prevattempts=&start_data_table().&start_data_table_header_row();
3141: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3142: foreach my $key (sort(keys(%lasthash))) {
3143: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3144: if ($#parts > 0) {
1.31 albertel 3145: my $data=$parts[-1];
3146: pop(@parts);
1.596 albertel 3147: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3148: } else {
1.41 ng 3149: if ($#parts == 0) {
3150: $prevattempts.='<th>'.$parts[0].'</th>';
3151: } else {
3152: $prevattempts.='<th>'.$ign.'</th>';
3153: }
1.31 albertel 3154: }
1.16 harris41 3155: }
1.596 albertel 3156: $prevattempts.=&end_data_table_header_row();
1.40 ng 3157: if ($getattempt eq '') {
3158: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3159: $prevattempts.=&start_data_table_row().
3160: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3161: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3162: my $value = &format_previous_attempt_value($key,
3163: $returnhash{$version.':'.$key});
3164: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3165: }
1.596 albertel 3166: $prevattempts.=&end_data_table_row();
1.40 ng 3167: }
1.1 albertel 3168: }
1.596 albertel 3169: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3170: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3171: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3172: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3173: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3174: }
1.596 albertel 3175: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3176: } else {
1.596 albertel 3177: $prevattempts=
3178: &start_data_table().&start_data_table_row().
3179: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3180: &end_data_table_row().&end_data_table();
1.1 albertel 3181: }
3182: } else {
1.596 albertel 3183: $prevattempts=
3184: &start_data_table().&start_data_table_row().
3185: '<td>'.&mt('No data.').'</td>'.
3186: &end_data_table_row().&end_data_table();
1.1 albertel 3187: }
1.10 albertel 3188: }
3189:
1.581 albertel 3190: sub format_previous_attempt_value {
3191: my ($key,$value) = @_;
3192: if ($key =~ /timestamp/) {
3193: $value = &Apache::lonlocal::locallocaltime($value);
3194: } elsif (ref($value) eq 'ARRAY') {
3195: $value = '('.join(', ', @{ $value }).')';
3196: } else {
3197: $value = &unescape($value);
3198: }
3199: return $value;
3200: }
3201:
3202:
1.107 albertel 3203: sub relative_to_absolute {
3204: my ($url,$output)=@_;
3205: my $parser=HTML::TokeParser->new(\$output);
3206: my $token;
3207: my $thisdir=$url;
3208: my @rlinks=();
3209: while ($token=$parser->get_token) {
3210: if ($token->[0] eq 'S') {
3211: if ($token->[1] eq 'a') {
3212: if ($token->[2]->{'href'}) {
3213: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3214: }
3215: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3216: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3217: } elsif ($token->[1] eq 'base') {
3218: $thisdir=$token->[2]->{'href'};
3219: }
3220: }
3221: }
3222: $thisdir=~s-/[^/]*$--;
1.356 albertel 3223: foreach my $link (@rlinks) {
3224: unless (($link=~/^http:\/\//i) ||
3225: ($link=~/^\//) ||
3226: ($link=~/^javascript:/i) ||
3227: ($link=~/^mailto:/i) ||
3228: ($link=~/^\#/)) {
3229: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3230: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3231: }
3232: }
3233: # -------------------------------------------------- Deal with Applet codebases
3234: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3235: return $output;
3236: }
3237:
1.112 bowersj2 3238: =pod
3239:
1.648 raeburn 3240: =item * &get_student_view()
1.112 bowersj2 3241:
3242: show a snapshot of what student was looking at
3243:
3244: =cut
3245:
1.10 albertel 3246: sub get_student_view {
1.186 albertel 3247: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3248: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3249: my (%form);
1.10 albertel 3250: my @elements=('symb','courseid','domain','username');
3251: foreach my $element (@elements) {
1.186 albertel 3252: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3253: }
1.186 albertel 3254: if (defined($moreenv)) {
3255: %form=(%form,%{$moreenv});
3256: }
1.236 albertel 3257: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3258: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3259: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3260: $userview=~s/\<body[^\>]*\>//gi;
3261: $userview=~s/\<\/body\>//gi;
3262: $userview=~s/\<html\>//gi;
3263: $userview=~s/\<\/html\>//gi;
3264: $userview=~s/\<head\>//gi;
3265: $userview=~s/\<\/head\>//gi;
3266: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3267: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3268: if (wantarray) {
3269: return ($userview,$response);
3270: } else {
3271: return $userview;
3272: }
3273: }
3274:
3275: sub get_student_view_with_retries {
3276: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3277:
3278: my $ok = 0; # True if we got a good response.
3279: my $content;
3280: my $response;
3281:
3282: # Try to get the student_view done. within the retries count:
3283:
3284: do {
3285: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3286: $ok = $response->is_success;
3287: if (!$ok) {
3288: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3289: }
3290: $retries--;
3291: } while (!$ok && ($retries > 0));
3292:
3293: if (!$ok) {
3294: $content = ''; # On error return an empty content.
3295: }
1.651 www 3296: if (wantarray) {
3297: return ($content, $response);
3298: } else {
3299: return $content;
3300: }
1.11 albertel 3301: }
3302:
1.112 bowersj2 3303: =pod
3304:
1.648 raeburn 3305: =item * &get_student_answers()
1.112 bowersj2 3306:
3307: show a snapshot of how student was answering problem
3308:
3309: =cut
3310:
1.11 albertel 3311: sub get_student_answers {
1.100 sakharuk 3312: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3313: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3314: my (%moreenv);
1.11 albertel 3315: my @elements=('symb','courseid','domain','username');
3316: foreach my $element (@elements) {
1.186 albertel 3317: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3318: }
1.186 albertel 3319: $moreenv{'grade_target'}='answer';
3320: %moreenv=(%form,%moreenv);
1.497 raeburn 3321: $feedurl = &Apache::lonnet::clutter($feedurl);
3322: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3323: return $userview;
1.1 albertel 3324: }
1.116 albertel 3325:
3326: =pod
3327:
3328: =item * &submlink()
3329:
1.242 albertel 3330: Inputs: $text $uname $udom $symb $target
1.116 albertel 3331:
3332: Returns: A link to grades.pm such as to see the SUBM view of a student
3333:
3334: =cut
3335:
3336: ###############################################
3337: sub submlink {
1.242 albertel 3338: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3339: if (!($uname && $udom)) {
3340: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3341: &Apache::lonnet::whichuser($symb);
1.116 albertel 3342: if (!$symb) { $symb=$cursymb; }
3343: }
1.254 matthew 3344: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3345: $symb=&escape($symb);
1.242 albertel 3346: if ($target) { $target="target=\"$target\""; }
3347: return '<a href="/adm/grades?&command=submission&'.
3348: 'symb='.$symb.'&student='.$uname.
3349: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3350: }
3351: ##############################################
3352:
3353: =pod
3354:
3355: =item * &pgrdlink()
3356:
3357: Inputs: $text $uname $udom $symb $target
3358:
3359: Returns: A link to grades.pm such as to see the PGRD view of a student
3360:
3361: =cut
3362:
3363: ###############################################
3364: sub pgrdlink {
3365: my $link=&submlink(@_);
3366: $link=~s/(&command=submission)/$1&showgrading=yes/;
3367: return $link;
3368: }
3369: ##############################################
3370:
3371: =pod
3372:
3373: =item * &pprmlink()
3374:
3375: Inputs: $text $uname $udom $symb $target
3376:
3377: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3378: student and a specific resource
1.242 albertel 3379:
3380: =cut
3381:
3382: ###############################################
3383: sub pprmlink {
3384: my ($text,$uname,$udom,$symb,$target)=@_;
3385: if (!($uname && $udom)) {
3386: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3387: &Apache::lonnet::whichuser($symb);
1.242 albertel 3388: if (!$symb) { $symb=$cursymb; }
3389: }
1.254 matthew 3390: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3391: $symb=&escape($symb);
1.242 albertel 3392: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3393: return '<a href="/adm/parmset?command=set&'.
3394: 'symb='.$symb.'&uname='.$uname.
3395: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3396: }
3397: ##############################################
1.37 matthew 3398:
1.112 bowersj2 3399: =pod
3400:
3401: =back
3402:
3403: =cut
3404:
1.37 matthew 3405: ###############################################
1.51 www 3406:
3407:
3408: sub timehash {
1.687 raeburn 3409: my ($thistime) = @_;
3410: my $timezone = &Apache::lonlocal::gettimezone();
3411: my $dt = DateTime->from_epoch(epoch => $thistime)
3412: ->set_time_zone($timezone);
3413: my $wday = $dt->day_of_week();
3414: if ($wday == 7) { $wday = 0; }
3415: return ( 'second' => $dt->second(),
3416: 'minute' => $dt->minute(),
3417: 'hour' => $dt->hour(),
3418: 'day' => $dt->day_of_month(),
3419: 'month' => $dt->month(),
3420: 'year' => $dt->year(),
3421: 'weekday' => $wday,
3422: 'dayyear' => $dt->day_of_year(),
3423: 'dlsav' => $dt->is_dst() );
1.51 www 3424: }
3425:
1.370 www 3426: sub utc_string {
3427: my ($date)=@_;
1.371 www 3428: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3429: }
3430:
1.51 www 3431: sub maketime {
3432: my %th=@_;
1.687 raeburn 3433: my ($epoch_time,$timezone,$dt);
3434: $timezone = &Apache::lonlocal::gettimezone();
3435: eval {
3436: $dt = DateTime->new( year => $th{'year'},
3437: month => $th{'month'},
3438: day => $th{'day'},
3439: hour => $th{'hour'},
3440: minute => $th{'minute'},
3441: second => $th{'second'},
3442: time_zone => $timezone,
3443: );
3444: };
3445: if (!$@) {
3446: $epoch_time = $dt->epoch;
3447: if ($epoch_time) {
3448: return $epoch_time;
3449: }
3450: }
1.51 www 3451: return POSIX::mktime(
3452: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3453: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3454: }
3455:
3456: #########################################
1.51 www 3457:
3458: sub findallcourses {
1.482 raeburn 3459: my ($roles,$uname,$udom) = @_;
1.355 albertel 3460: my %roles;
3461: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3462: my %courses;
1.51 www 3463: my $now=time;
1.482 raeburn 3464: if (!defined($uname)) {
3465: $uname = $env{'user.name'};
3466: }
3467: if (!defined($udom)) {
3468: $udom = $env{'user.domain'};
3469: }
3470: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3471: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3472: if (!%roles) {
3473: %roles = (
3474: cc => 1,
3475: in => 1,
3476: ep => 1,
3477: ta => 1,
3478: cr => 1,
3479: st => 1,
3480: );
3481: }
3482: foreach my $entry (keys(%roleshash)) {
3483: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3484: if ($trole =~ /^cr/) {
3485: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3486: } else {
3487: next if (!exists($roles{$trole}));
3488: }
3489: if ($tend) {
3490: next if ($tend < $now);
3491: }
3492: if ($tstart) {
3493: next if ($tstart > $now);
3494: }
3495: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3496: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3497: if ($secpart eq '') {
3498: ($cnum,$role) = split(/_/,$cnumpart);
3499: $sec = 'none';
3500: $realsec = '';
3501: } else {
3502: $cnum = $cnumpart;
3503: ($sec,$role) = split(/_/,$secpart);
3504: $realsec = $sec;
1.490 raeburn 3505: }
1.482 raeburn 3506: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3507: }
3508: } else {
3509: foreach my $key (keys(%env)) {
1.483 albertel 3510: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3511: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3512: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3513: next if ($role eq 'ca' || $role eq 'aa');
3514: next if (%roles && !exists($roles{$role}));
3515: my ($starttime,$endtime)=split(/\./,$env{$key});
3516: my $active=1;
3517: if ($starttime) {
3518: if ($now<$starttime) { $active=0; }
3519: }
3520: if ($endtime) {
3521: if ($now>$endtime) { $active=0; }
3522: }
3523: if ($active) {
3524: if ($sec eq '') {
3525: $sec = 'none';
3526: }
3527: $courses{$cdom.'_'.$cnum}{$sec} =
3528: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3529: }
3530: }
1.51 www 3531: }
3532: }
1.474 raeburn 3533: return %courses;
1.51 www 3534: }
1.37 matthew 3535:
1.54 www 3536: ###############################################
1.474 raeburn 3537:
3538: sub blockcheck {
1.482 raeburn 3539: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3540:
3541: if (!defined($udom)) {
3542: $udom = $env{'user.domain'};
3543: }
3544: if (!defined($uname)) {
3545: $uname = $env{'user.name'};
3546: }
3547:
3548: # If uname and udom are for a course, check for blocks in the course.
3549:
3550: if (&Apache::lonnet::is_course($udom,$uname)) {
3551: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3552: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3553: return ($startblock,$endblock);
3554: }
1.474 raeburn 3555:
1.502 raeburn 3556: my $startblock = 0;
3557: my $endblock = 0;
1.482 raeburn 3558: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3559:
1.490 raeburn 3560: # If uname is for a user, and activity is course-specific, i.e.,
3561: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3562:
1.490 raeburn 3563: if (($activity eq 'boards' || $activity eq 'chat' ||
3564: $activity eq 'groups') && ($env{'request.course.id'})) {
3565: foreach my $key (keys(%live_courses)) {
3566: if ($key ne $env{'request.course.id'}) {
3567: delete($live_courses{$key});
3568: }
3569: }
3570: }
3571:
3572: my $otheruser = 0;
3573: my %own_courses;
3574: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3575: # Resource belongs to user other than current user.
3576: $otheruser = 1;
3577: # Gather courses for current user
3578: %own_courses =
3579: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3580: }
3581:
3582: # Gather active course roles - course coordinator, instructor,
3583: # exam proctor, ta, student, or custom role.
1.474 raeburn 3584:
3585: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3586: my ($cdom,$cnum);
3587: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3588: $cdom = $env{'course.'.$course.'.domain'};
3589: $cnum = $env{'course.'.$course.'.num'};
3590: } else {
1.490 raeburn 3591: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3592: }
3593: my $no_ownblock = 0;
3594: my $no_userblock = 0;
1.533 raeburn 3595: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3596: # Check if current user has 'evb' priv for this
3597: if (defined($own_courses{$course})) {
3598: foreach my $sec (keys(%{$own_courses{$course}})) {
3599: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3600: if ($sec ne 'none') {
3601: $checkrole .= '/'.$sec;
3602: }
3603: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3604: $no_ownblock = 1;
3605: last;
3606: }
3607: }
3608: }
3609: # if they have 'evb' priv and are currently not playing student
3610: next if (($no_ownblock) &&
3611: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3612: }
1.474 raeburn 3613: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3614: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3615: if ($sec ne 'none') {
1.482 raeburn 3616: $checkrole .= '/'.$sec;
1.474 raeburn 3617: }
1.490 raeburn 3618: if ($otheruser) {
3619: # Resource belongs to user other than current user.
3620: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3621: my ($trole,$tdom,$tnum,$tsec);
3622: my $entry = $live_courses{$course}{$sec};
3623: if ($entry =~ /^cr/) {
3624: ($trole,$tdom,$tnum,$tsec) =
3625: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3626: } else {
3627: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3628: }
3629: my ($spec,$area,$trest,%allroles,%userroles);
3630: $area = '/'.$tdom.'/'.$tnum;
3631: $trest = $tnum;
3632: if ($tsec ne '') {
3633: $area .= '/'.$tsec;
3634: $trest .= '/'.$tsec;
3635: }
3636: $spec = $trole.'.'.$area;
3637: if ($trole =~ /^cr/) {
3638: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3639: $tdom,$spec,$trest,$area);
3640: } else {
3641: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3642: $tdom,$spec,$trest,$area);
3643: }
3644: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3645: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3646: if ($1) {
3647: $no_userblock = 1;
3648: last;
3649: }
3650: }
1.490 raeburn 3651: } else {
3652: # Resource belongs to current user
3653: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3654: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3655: $no_ownblock = 1;
3656: last;
3657: }
1.474 raeburn 3658: }
3659: }
3660: # if they have the evb priv and are currently not playing student
1.482 raeburn 3661: next if (($no_ownblock) &&
1.491 albertel 3662: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3663: next if ($no_userblock);
1.474 raeburn 3664:
1.490 raeburn 3665: # Retrieve blocking times and identity of blocker for course
3666: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3667:
3668: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3669: if (($start != 0) &&
3670: (($startblock == 0) || ($startblock > $start))) {
3671: $startblock = $start;
3672: }
3673: if (($end != 0) &&
3674: (($endblock == 0) || ($endblock < $end))) {
3675: $endblock = $end;
3676: }
1.490 raeburn 3677: }
3678: return ($startblock,$endblock);
3679: }
3680:
3681: sub get_blocks {
3682: my ($setters,$activity,$cdom,$cnum) = @_;
3683: my $startblock = 0;
3684: my $endblock = 0;
3685: my $course = $cdom.'_'.$cnum;
3686: $setters->{$course} = {};
3687: $setters->{$course}{'staff'} = [];
3688: $setters->{$course}{'times'} = [];
3689: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3690: foreach my $record (keys(%records)) {
3691: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3692: if ($start <= time && $end >= time) {
3693: my ($staff_name,$staff_dom,$title,$blocks) =
3694: &parse_block_record($records{$record});
3695: if ($blocks->{$activity} eq 'on') {
3696: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3697: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3698: if ( ($startblock == 0) || ($startblock > $start) ) {
3699: $startblock = $start;
1.490 raeburn 3700: }
1.491 albertel 3701: if ( ($endblock == 0) || ($endblock < $end) ) {
3702: $endblock = $end;
1.474 raeburn 3703: }
3704: }
3705: }
3706: }
3707: return ($startblock,$endblock);
3708: }
3709:
3710: sub parse_block_record {
3711: my ($record) = @_;
3712: my ($setuname,$setudom,$title,$blocks);
3713: if (ref($record) eq 'HASH') {
3714: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3715: $title = &unescape($record->{'event'});
3716: $blocks = $record->{'blocks'};
3717: } else {
3718: my @data = split(/:/,$record,3);
3719: if (scalar(@data) eq 2) {
3720: $title = $data[1];
3721: ($setuname,$setudom) = split(/@/,$data[0]);
3722: } else {
3723: ($setuname,$setudom,$title) = @data;
3724: }
3725: $blocks = { 'com' => 'on' };
3726: }
3727: return ($setuname,$setudom,$title,$blocks);
3728: }
3729:
3730: sub build_block_table {
3731: my ($startblock,$endblock,$setters) = @_;
3732: my %lt = &Apache::lonlocal::texthash(
3733: 'cacb' => 'Currently active communication blocks',
3734: 'cour' => 'Course',
3735: 'dura' => 'Duration',
3736: 'blse' => 'Block set by'
3737: );
3738: my $output;
1.476 raeburn 3739: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3740: $output .= &start_data_table();
3741: $output .= '
3742: <tr>
3743: <th>'.$lt{'cour'}.'</th>
3744: <th>'.$lt{'dura'}.'</th>
3745: <th>'.$lt{'blse'}.'</th>
3746: </tr>
3747: ';
3748: foreach my $course (keys(%{$setters})) {
3749: my %courseinfo=&Apache::lonnet::coursedescription($course);
3750: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3751: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3752: my $fullname = &plainname($uname,$udom);
3753: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3754: && $env{'user.name'} ne 'public'
3755: && $env{'user.domain'} ne 'public') {
3756: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3757: }
1.474 raeburn 3758: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3759: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3760: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3761: $output .= &Apache::loncommon::start_data_table_row().
3762: '<td>'.$courseinfo{'description'}.'</td>'.
3763: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3764: '<td>'.$fullname.'</td>'.
1.474 raeburn 3765: &Apache::loncommon::end_data_table_row();
3766: }
3767: }
3768: $output .= &end_data_table();
3769: }
3770:
1.490 raeburn 3771: sub blocking_status {
3772: my ($activity,$uname,$udom) = @_;
3773: my %setters;
3774: my ($blocked,$output,$ownitem,$is_course);
3775: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3776: if ($startblock && $endblock) {
3777: $blocked = 1;
3778: if (wantarray) {
3779: my $category;
3780: if ($activity eq 'boards') {
3781: $category = 'Discussion posts in this course';
3782: } elsif ($activity eq 'blogs') {
3783: $category = 'Blogs';
3784: } elsif ($activity eq 'port') {
3785: if (defined($uname) && defined($udom)) {
3786: if ($uname eq $env{'user.name'} &&
3787: $udom eq $env{'user.domain'}) {
3788: $ownitem = 1;
3789: }
3790: }
3791: $is_course = &Apache::lonnet::is_course($udom,$uname);
3792: if ($ownitem) {
3793: $category = 'Your portfolio files';
3794: } elsif ($is_course) {
3795: my $coursedesc;
3796: foreach my $course (keys(%setters)) {
3797: my %courseinfo =
3798: &Apache::lonnet::coursedescription($course);
3799: $coursedesc = $courseinfo{'description'};
3800: }
3801: $category = "Group files in the course '$coursedesc'";
3802: } else {
3803: $category = 'Portfolio files belonging to ';
3804: if ($env{'user.name'} eq 'public' &&
3805: $env{'user.domain'} eq 'public') {
3806: $category .= &plainname($uname,$udom);
3807: } else {
3808: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3809: }
3810: }
3811: } elsif ($activity eq 'groups') {
3812: $category = 'Groups in this course';
3813: }
3814: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3815: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3816: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3817: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3818: $output .= &build_block_table($startblock,$endblock,\%setters);
3819: }
3820: }
3821: }
3822: if (wantarray) {
3823: return ($blocked,$output);
3824: } else {
3825: return $blocked;
3826: }
3827: }
3828:
1.60 matthew 3829: ###############################################
3830:
1.682 raeburn 3831: sub check_ip_acc {
3832: my ($acc)=@_;
3833: &Apache::lonxml::debug("acc is $acc");
3834: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3835: return 1;
3836: }
3837: my $allowed=0;
3838: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3839:
3840: my $name;
3841: foreach my $pattern (split(',',$acc)) {
3842: $pattern =~ s/^\s*//;
3843: $pattern =~ s/\s*$//;
3844: if ($pattern =~ /\*$/) {
3845: #35.8.*
3846: $pattern=~s/\*//;
3847: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3848: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3849: #35.8.3.[34-56]
3850: my $low=$2;
3851: my $high=$3;
3852: $pattern=$1;
3853: if ($ip =~ /^\Q$pattern\E/) {
3854: my $last=(split(/\./,$ip))[3];
3855: if ($last <=$high && $last >=$low) { $allowed=1; }
3856: }
3857: } elsif ($pattern =~ /^\*/) {
3858: #*.msu.edu
3859: $pattern=~s/\*//;
3860: if (!defined($name)) {
3861: use Socket;
3862: my $netaddr=inet_aton($ip);
3863: ($name)=gethostbyaddr($netaddr,AF_INET);
3864: }
3865: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3866: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3867: #127.0.0.1
3868: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3869: } else {
3870: #some.name.com
3871: if (!defined($name)) {
3872: use Socket;
3873: my $netaddr=inet_aton($ip);
3874: ($name)=gethostbyaddr($netaddr,AF_INET);
3875: }
3876: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3877: }
3878: if ($allowed) { last; }
3879: }
3880: return $allowed;
3881: }
3882:
3883: ###############################################
3884:
1.60 matthew 3885: =pod
3886:
1.112 bowersj2 3887: =head1 Domain Template Functions
3888:
3889: =over 4
3890:
3891: =item * &determinedomain()
1.60 matthew 3892:
3893: Inputs: $domain (usually will be undef)
3894:
1.63 www 3895: Returns: Determines which domain should be used for designs
1.60 matthew 3896:
3897: =cut
1.54 www 3898:
1.60 matthew 3899: ###############################################
1.63 www 3900: sub determinedomain {
3901: my $domain=shift;
1.531 albertel 3902: if (! $domain) {
1.60 matthew 3903: # Determine domain if we have not been given one
3904: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3905: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3906: if ($env{'request.role.domain'}) {
3907: $domain=$env{'request.role.domain'};
1.60 matthew 3908: }
3909: }
1.63 www 3910: return $domain;
3911: }
3912: ###############################################
1.517 raeburn 3913:
1.518 albertel 3914: sub devalidate_domconfig_cache {
3915: my ($udom)=@_;
3916: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3917: }
3918:
3919: # ---------------------- Get domain configuration for a domain
3920: sub get_domainconf {
3921: my ($udom) = @_;
3922: my $cachetime=1800;
3923: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3924: if (defined($cached)) { return %{$result}; }
3925:
3926: my %domconfig = &Apache::lonnet::get_dom('configuration',
3927: ['login','rolecolors'],$udom);
1.632 raeburn 3928: my (%designhash,%legacy);
1.518 albertel 3929: if (keys(%domconfig) > 0) {
3930: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3931: if (keys(%{$domconfig{'login'}})) {
3932: foreach my $key (keys(%{$domconfig{'login'}})) {
3933: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3934: }
3935: } else {
3936: $legacy{'login'} = 1;
1.518 albertel 3937: }
1.632 raeburn 3938: } else {
3939: $legacy{'login'} = 1;
1.518 albertel 3940: }
3941: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3942: if (keys(%{$domconfig{'rolecolors'}})) {
3943: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3944: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3945: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3946: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3947: }
1.518 albertel 3948: }
3949: }
1.632 raeburn 3950: } else {
3951: $legacy{'rolecolors'} = 1;
1.518 albertel 3952: }
1.632 raeburn 3953: } else {
3954: $legacy{'rolecolors'} = 1;
1.518 albertel 3955: }
1.632 raeburn 3956: if (keys(%legacy) > 0) {
3957: my %legacyhash = &get_legacy_domconf($udom);
3958: foreach my $item (keys(%legacyhash)) {
3959: if ($item =~ /^\Q$udom\E\.login/) {
3960: if ($legacy{'login'}) {
3961: $designhash{$item} = $legacyhash{$item};
3962: }
3963: } else {
3964: if ($legacy{'rolecolors'}) {
3965: $designhash{$item} = $legacyhash{$item};
3966: }
1.518 albertel 3967: }
3968: }
3969: }
1.632 raeburn 3970: } else {
3971: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3972: }
3973: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3974: $cachetime);
3975: return %designhash;
3976: }
3977:
1.632 raeburn 3978: sub get_legacy_domconf {
3979: my ($udom) = @_;
3980: my %legacyhash;
3981: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
3982: my $designfile = $designdir.'/'.$udom.'.tab';
3983: if (-e $designfile) {
3984: if ( open (my $fh,"<$designfile") ) {
3985: while (my $line = <$fh>) {
3986: next if ($line =~ /^\#/);
3987: chomp($line);
3988: my ($key,$val)=(split(/\=/,$line));
3989: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
3990: }
3991: close($fh);
3992: }
3993: }
3994: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
3995: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
3996: }
3997: return %legacyhash;
3998: }
3999:
1.63 www 4000: =pod
4001:
1.112 bowersj2 4002: =item * &domainlogo()
1.63 www 4003:
4004: Inputs: $domain (usually will be undef)
4005:
4006: Returns: A link to a domain logo, if the domain logo exists.
4007: If the domain logo does not exist, a description of the domain.
4008:
4009: =cut
1.112 bowersj2 4010:
1.63 www 4011: ###############################################
4012: sub domainlogo {
1.517 raeburn 4013: my $domain = &determinedomain(shift);
1.518 albertel 4014: my %designhash = &get_domainconf($domain);
1.517 raeburn 4015: # See if there is a logo
4016: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4017: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4018: if ($imgsrc =~ m{^/(adm|res)/}) {
4019: if ($imgsrc =~ m{^/res/}) {
4020: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4021: &Apache::lonnet::repcopy($local_name);
4022: }
4023: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4024: }
4025: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4026: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4027: return &Apache::lonnet::domain($domain,'description');
1.59 www 4028: } else {
1.60 matthew 4029: return '';
1.59 www 4030: }
4031: }
1.63 www 4032: ##############################################
4033:
4034: =pod
4035:
1.112 bowersj2 4036: =item * &designparm()
1.63 www 4037:
4038: Inputs: $which parameter; $domain (usually will be undef)
4039:
4040: Returns: value of designparamter $which
4041:
4042: =cut
1.112 bowersj2 4043:
1.397 albertel 4044:
1.400 albertel 4045: ##############################################
1.397 albertel 4046: sub designparm {
4047: my ($which,$domain)=@_;
1.258 albertel 4048: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4049: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4050: return '#000000';
4051: }
1.635 raeburn 4052: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4053: return '#FFFFFF';
4054: }
4055: if ($which=~/\.tabbg$/) {
4056: return '#CCCCCC';
4057: }
4058: }
1.397 albertel 4059: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4060: return $env{'environment.color.'.$which};
1.96 www 4061: }
1.63 www 4062: $domain=&determinedomain($domain);
1.518 albertel 4063: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4064: my $output;
1.517 raeburn 4065: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4066: $output = $domdesign{$domain.'.'.$which};
1.63 www 4067: } else {
1.520 raeburn 4068: $output = $defaultdesign{$which};
4069: }
4070: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4071: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4072: if ($output =~ m{^/(adm|res)/}) {
4073: if ($output =~ m{^/res/}) {
4074: my $local_name = &Apache::lonnet::filelocation('',$output);
4075: &Apache::lonnet::repcopy($local_name);
4076: }
1.520 raeburn 4077: $output = &lonhttpdurl($output);
4078: }
1.63 www 4079: }
1.520 raeburn 4080: return $output;
1.63 www 4081: }
1.59 www 4082:
1.60 matthew 4083: ###############################################
4084: ###############################################
4085:
4086: =pod
4087:
1.112 bowersj2 4088: =back
4089:
1.549 albertel 4090: =head1 HTML Helpers
1.112 bowersj2 4091:
4092: =over 4
4093:
4094: =item * &bodytag()
1.60 matthew 4095:
4096: Returns a uniform header for LON-CAPA web pages.
4097:
4098: Inputs:
4099:
1.112 bowersj2 4100: =over 4
4101:
4102: =item * $title, A title to be displayed on the page.
4103:
4104: =item * $function, the current role (can be undef).
4105:
4106: =item * $addentries, extra parameters for the <body> tag.
4107:
4108: =item * $bodyonly, if defined, only return the <body> tag.
4109:
4110: =item * $domain, if defined, force a given domain.
4111:
4112: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4113: text interface only)
1.60 matthew 4114:
1.326 albertel 4115: =item * $customtitle, alternate text to use instead of $title
4116: in the title box that appears, this text
4117: is not auto translated like the $title is
1.309 albertel 4118:
4119: =item * $notopbar, if true, keep the 'what is this' info but remove the
4120: navigational links
1.317 albertel 4121:
1.338 albertel 4122: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4123:
4124: =item * $notitle, if true keep the nav controls, but remove the title bar
4125:
1.361 albertel 4126: =item * $no_inline_link, if true and in remote mode, don't show the
4127: 'Switch To Inline Menu' link
4128:
1.460 albertel 4129: =item * $args, optional argument valid values are
4130: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4131: inherit_jsmath -> when creating popup window in a page,
4132: should it have jsmath forced on by the
4133: current page
1.460 albertel 4134:
1.112 bowersj2 4135: =back
4136:
1.60 matthew 4137: Returns: A uniform header for LON-CAPA web pages.
4138: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4139: If $bodyonly is undef or zero, an html string containing a <body> tag and
4140: other decorations will be returned.
4141:
4142: =cut
4143:
1.54 www 4144: sub bodytag {
1.309 albertel 4145: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4146: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4147:
1.460 albertel 4148: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4149:
1.183 matthew 4150: $function = &get_users_function() if (!$function);
1.339 albertel 4151: my $img = &designparm($function.'.img',$domain);
4152: my $font = &designparm($function.'.font',$domain);
4153: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4154:
4155: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4156: 'bgcolor' => $pgbg,
1.339 albertel 4157: 'text' => $font,
4158: 'alink' => &designparm($function.'.alink',$domain),
4159: 'vlink' => &designparm($function.'.vlink',$domain),
4160: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4161: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4162:
1.63 www 4163: # role and realm
1.378 raeburn 4164: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4165: if ($role eq 'ca') {
1.479 albertel 4166: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4167: $realm = &plainname($rname,$rdom);
1.378 raeburn 4168: }
1.55 www 4169: # realm
1.258 albertel 4170: if ($env{'request.course.id'}) {
1.378 raeburn 4171: if ($env{'request.role'} !~ /^cr/) {
4172: $role = &Apache::lonnet::plaintext($role,&course_type());
4173: }
1.359 albertel 4174: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4175: } else {
4176: $role = &Apache::lonnet::plaintext($role);
1.54 www 4177: }
1.433 albertel 4178:
1.359 albertel 4179: if (!$realm) { $realm=' '; }
1.55 www 4180: # Set messages
1.60 matthew 4181: my $messages=&domainlogo($domain);
1.330 albertel 4182:
1.438 albertel 4183: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4184:
1.101 www 4185: # construct main body tag
1.359 albertel 4186: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4187: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4188:
1.530 albertel 4189: if ($bodyonly) {
1.60 matthew 4190: return $bodytag;
1.258 albertel 4191: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4192: # Accessibility
1.224 raeburn 4193:
1.337 albertel 4194: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4195: if (!$notitle) {
1.337 albertel 4196: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4197: }
4198: return $bodytag;
1.359 albertel 4199: }
4200:
1.410 albertel 4201: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4202: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4203: undef($role);
1.434 albertel 4204: } else {
4205: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4206: }
1.359 albertel 4207:
4208: my $roleinfo=(<<ENDROLE);
4209: <td class="LC_title_bar_who">
4210: <div class="LC_title_bar_name">
1.410 albertel 4211: $name
1.361 albertel 4212:
1.359 albertel 4213: </div>
4214: <div class="LC_title_bar_role">
1.361 albertel 4215: $role
1.359 albertel 4216: </div>
4217: <div class="LC_title_bar_realm">
1.361 albertel 4218: $realm
1.359 albertel 4219: </div>
1.206 albertel 4220: </td>
4221: ENDROLE
1.235 raeburn 4222:
1.359 albertel 4223: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4224: if ($customtitle) {
4225: $titleinfo = $customtitle;
4226: }
4227: #
4228: # Extra info if you are the DC
4229: my $dc_info = '';
4230: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4231: $env{'course.'.$env{'request.course.id'}.
4232: '.domain'}.'/'})) {
4233: my $cid = $env{'request.course.id'};
4234: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4235: $dc_info =~ s/\s+$//;
1.359 albertel 4236: $dc_info = '('.$dc_info.')';
4237: }
4238:
1.644 www 4239: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4240: # No Remote
1.258 albertel 4241: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4242: $forcereg=1;
4243: }
4244:
4245: if (!$customtitle && $env{'request.state'} eq 'construct') {
4246: # this is for resources; directories have customtitle, and crumbs
4247: # and select recent are created in lonpubdir.pm
1.229 albertel 4248: my ($uname,$thisdisfn)=
1.258 albertel 4249: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4250: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4251: $formaction=~s/\/+/\//g;
4252:
1.359 albertel 4253: my $parentpath = '';
4254: my $lastitem = '';
4255: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4256: $parentpath = $1;
4257: $lastitem = $2;
4258: } else {
4259: $lastitem = $thisdisfn;
4260: }
4261: $titleinfo =
1.640 bisitz 4262: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4263: .'<b>'.&mt('Construction Space').'</b>: '
4264: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4265: .'" target="_top"><tt><b>'
4266: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
4267: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4268: .'</form>'
4269: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4270: }
1.359 albertel 4271:
1.337 albertel 4272: my $titletable;
1.338 albertel 4273: if (!$notitle) {
1.337 albertel 4274: $titletable =
1.359 albertel 4275: '<table id="LC_title_bar">'.
4276: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4277: '</tr></table>';
1.337 albertel 4278: }
1.359 albertel 4279: if ($notopbar) {
4280: $bodytag .= $titletable;
4281: } else {
4282: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4283: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4284: $titletable);
1.272 raeburn 4285: } else {
1.336 albertel 4286: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4287: $titletable;
1.272 raeburn 4288: }
1.235 raeburn 4289: }
4290: return $bodytag;
1.94 www 4291: }
1.95 www 4292:
1.93 www 4293: #
1.95 www 4294: # Top frame rendering, Remote is up
1.93 www 4295: #
1.359 albertel 4296:
1.517 raeburn 4297: my $imgsrc = $img;
4298: if ($img =~ /^\/adm/) {
1.575 albertel 4299: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4300: }
4301: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4302:
1.305 www 4303: # Explicit link to get inline menu
1.361 albertel 4304: my $menu= ($no_inline_link?''
4305: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4306: #
1.338 albertel 4307: if ($notitle) {
1.337 albertel 4308: return $bodytag;
4309: }
1.94 www 4310: return(<<ENDBODY);
1.60 matthew 4311: $bodytag
1.359 albertel 4312: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4313: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4314: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4315: </tr>
1.359 albertel 4316: <tr><td>$titleinfo $dc_info $menu</td>
4317: $roleinfo
1.368 albertel 4318: </tr>
1.356 albertel 4319: </table>
1.54 www 4320: ENDBODY
1.182 matthew 4321: }
4322:
1.330 albertel 4323: sub make_attr_string {
4324: my ($register,$attr_ref) = @_;
4325:
4326: if ($attr_ref && !ref($attr_ref)) {
4327: die("addentries Must be a hash ref ".
4328: join(':',caller(1))." ".
4329: join(':',caller(0))." ");
4330: }
4331:
4332: if ($register) {
1.339 albertel 4333: my ($on_load,$on_unload);
4334: foreach my $key (keys(%{$attr_ref})) {
4335: if (lc($key) eq 'onload') {
4336: $on_load.=$attr_ref->{$key}.';';
4337: delete($attr_ref->{$key});
4338:
4339: } elsif (lc($key) eq 'onunload') {
4340: $on_unload.=$attr_ref->{$key}.';';
4341: delete($attr_ref->{$key});
4342: }
4343: }
4344: $attr_ref->{'onload'} =
4345: &Apache::lonmenu::loadevents(). $on_load;
4346: $attr_ref->{'onunload'}=
4347: &Apache::lonmenu::unloadevents().$on_unload;
4348: }
4349:
4350: # Accessibility font enhance
4351: if ($env{'browser.fontenhance'} eq 'on') {
4352: my $style;
4353: foreach my $key (keys(%{$attr_ref})) {
4354: if (lc($key) eq 'style') {
4355: $style.=$attr_ref->{$key}.';';
4356: delete($attr_ref->{$key});
4357: }
4358: }
4359: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4360: }
1.339 albertel 4361:
4362: if ($env{'browser.blackwhite'} eq 'on') {
4363: delete($attr_ref->{'font'});
4364: delete($attr_ref->{'link'});
4365: delete($attr_ref->{'alink'});
4366: delete($attr_ref->{'vlink'});
4367: delete($attr_ref->{'bgcolor'});
4368: delete($attr_ref->{'background'});
4369: }
4370:
1.330 albertel 4371: my $attr_string;
4372: foreach my $attr (keys(%$attr_ref)) {
4373: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4374: }
4375: return $attr_string;
4376: }
4377:
4378:
1.182 matthew 4379: ###############################################
1.251 albertel 4380: ###############################################
4381:
4382: =pod
4383:
4384: =item * &endbodytag()
4385:
4386: Returns a uniform footer for LON-CAPA web pages.
4387:
1.635 raeburn 4388: Inputs: 1 - optional reference to an args hash
4389: If in the hash, key for noredirectlink has a value which evaluates to true,
4390: a 'Continue' link is not displayed if the page contains an
4391: internal redirect in the <head></head> section,
4392: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4393:
4394: =cut
4395:
4396: sub endbodytag {
1.635 raeburn 4397: my ($args) = @_;
1.251 albertel 4398: my $endbodytag='</body>';
1.269 albertel 4399: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4400: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4401: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4402: $endbodytag=
4403: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4404: &mt('Continue').'</a>'.
4405: $endbodytag;
4406: }
1.315 albertel 4407: }
1.251 albertel 4408: return $endbodytag;
4409: }
4410:
1.352 albertel 4411: =pod
4412:
4413: =item * &standard_css()
4414:
4415: Returns a style sheet
4416:
4417: Inputs: (all optional)
4418: domain -> force to color decorate a page for a specific
4419: domain
4420: function -> force usage of a specific rolish color scheme
4421: bgcolor -> override the default page bgcolor
4422:
4423: =cut
4424:
1.343 albertel 4425: sub standard_css {
1.345 albertel 4426: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4427: $function = &get_users_function() if (!$function);
4428: my $img = &designparm($function.'.img', $domain);
4429: my $tabbg = &designparm($function.'.tabbg', $domain);
4430: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4431: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4432: my $pgbg_or_bgcolor =
4433: $bgcolor ||
1.352 albertel 4434: &designparm($function.'.pgbg', $domain);
1.382 albertel 4435: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4436: my $alink = &designparm($function.'.alink', $domain);
4437: my $vlink = &designparm($function.'.vlink', $domain);
4438: my $link = &designparm($function.'.link', $domain);
4439:
1.602 albertel 4440: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4441: my $mono = 'monospace';
1.352 albertel 4442: my $data_table_head = $tabbg;
4443: my $data_table_light = '#EEEEEE';
1.470 banghart 4444: my $data_table_dark = '#DDDDDD';
4445: my $data_table_darker = '#CCCCCC';
1.349 albertel 4446: my $data_table_highlight = '#FFFF00';
1.352 albertel 4447: my $mail_new = '#FFBB77';
4448: my $mail_new_hover = '#DD9955';
4449: my $mail_read = '#BBBB77';
4450: my $mail_read_hover = '#999944';
4451: my $mail_replied = '#AAAA88';
4452: my $mail_replied_hover = '#888855';
4453: my $mail_other = '#99BBBB';
4454: my $mail_other_hover = '#669999';
1.391 albertel 4455: my $table_header = '#DDDDDD';
1.489 raeburn 4456: my $feedback_link_bg = '#BBBBBB';
1.392 albertel 4457:
1.608 albertel 4458: my $border = ($env{'browser.type'} eq 'explorer' ||
4459: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4460: : '0px 3px 0px 4px';
1.448 albertel 4461:
1.523 albertel 4462:
1.343 albertel 4463: return <<END;
1.345 albertel 4464: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4465: a:focus { color: red; background: yellow }
1.510 albertel 4466: table.thinborder,
1.523 albertel 4467:
1.510 albertel 4468: table.thinborder tr th {
4469: border-style: solid;
4470: border-width: 1px;
4471: background: $tabbg;
4472: }
1.523 albertel 4473: table.thinborder tr td {
1.510 albertel 4474: border-style: solid;
4475: border-width: 1px
4476: }
1.426 albertel 4477:
1.343 albertel 4478: form, .inline { display: inline; }
4479: .center { text-align: center; }
1.593 albertel 4480: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4481: .LC_error {
4482: color: red;
4483: font-size: larger;
4484: }
1.457 albertel 4485: .LC_warning,
4486: .LC_diff_removed {
1.394 albertel 4487: color: red;
4488: }
1.532 albertel 4489:
4490: .LC_info,
1.457 albertel 4491: .LC_success,
4492: .LC_diff_added {
1.350 albertel 4493: color: green;
4494: }
1.543 albertel 4495: .LC_unknown {
4496: color: yellow;
4497: }
4498:
1.440 albertel 4499: .LC_icon {
4500: border: 0px;
4501: }
1.539 albertel 4502: .LC_indexer_icon {
4503: border: 0px;
4504: height: 22px;
4505: }
1.543 albertel 4506: .LC_docs_spacer {
4507: width: 25px;
4508: height: 1px;
4509: border: 0px;
4510: }
1.346 albertel 4511:
1.532 albertel 4512: .LC_internal_info {
4513: color: #999;
4514: }
4515:
1.458 albertel 4516: table.LC_pastsubmission {
4517: border: 1px solid black;
4518: margin: 2px;
4519: }
4520:
1.606 albertel 4521: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4522: width: 100%;
4523: background: $pgbg;
1.392 albertel 4524: border: 2px;
1.402 albertel 4525: border-collapse: separate;
1.403 albertel 4526: padding: 0px;
1.345 albertel 4527: }
1.392 albertel 4528:
1.606 albertel 4529: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4530: table#LC_title_bar.LC_with_remote {
1.359 albertel 4531: width: 100%;
1.392 albertel 4532: border-color: $pgbg;
4533: border-style: solid;
4534: border-width: $border;
4535:
1.379 albertel 4536: background: $pgbg;
4537: font-family: $sans;
1.392 albertel 4538: border-collapse: collapse;
1.403 albertel 4539: padding: 0px;
1.359 albertel 4540: }
1.392 albertel 4541:
1.409 albertel 4542: table.LC_docs_path {
4543: width: 100%;
4544: border: 0;
4545: background: $pgbg;
4546: font-family: $sans;
4547: border-collapse: collapse;
4548: padding: 0px;
4549: }
4550:
1.359 albertel 4551: table#LC_title_bar td {
4552: background: $tabbg;
4553: }
4554: table#LC_title_bar td.LC_title_bar_who {
4555: background: $tabbg;
4556: color: $font;
1.427 albertel 4557: font: small $sans;
1.359 albertel 4558: text-align: right;
4559: }
1.469 banghart 4560: span.LC_metadata {
4561: font-family: $sans;
4562: }
1.359 albertel 4563: span.LC_title_bar_title {
1.416 albertel 4564: font: bold x-large $sans;
1.359 albertel 4565: }
4566: table#LC_title_bar td.LC_title_bar_domain_logo {
4567: background: $sidebg;
4568: text-align: right;
1.368 albertel 4569: padding: 0px;
4570: }
4571: table#LC_title_bar td.LC_title_bar_role_logo {
4572: background: $sidebg;
4573: padding: 0px;
1.359 albertel 4574: }
4575:
1.346 albertel 4576: table#LC_menubuttons_mainmenu {
1.526 www 4577: width: 100%;
1.346 albertel 4578: border: 0px;
4579: border-spacing: 1px;
1.372 albertel 4580: padding: 0px 1px;
1.346 albertel 4581: margin: 0px;
4582: border-collapse: separate;
4583: }
4584: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
4585: border: 0px;
4586: }
1.345 albertel 4587: table#LC_top_nav td {
4588: background: $tabbg;
1.392 albertel 4589: border: 0px;
1.407 albertel 4590: font-size: small;
1.345 albertel 4591: }
4592: table#LC_top_nav td a, div#LC_top_nav a {
4593: color: $font;
4594: font-family: $sans;
4595: }
1.364 albertel 4596: table#LC_top_nav td.LC_top_nav_logo {
4597: background: $tabbg;
1.432 albertel 4598: text-align: left;
1.408 albertel 4599: white-space: nowrap;
1.432 albertel 4600: width: 31px;
1.408 albertel 4601: }
4602: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4603: border: 0px;
1.408 albertel 4604: vertical-align: bottom;
1.364 albertel 4605: }
1.432 albertel 4606: table#LC_top_nav td.LC_top_nav_exit,
4607: table#LC_top_nav td.LC_top_nav_help {
4608: width: 2.0em;
4609: }
1.442 albertel 4610: table#LC_top_nav td.LC_top_nav_login {
4611: width: 4.0em;
4612: text-align: center;
4613: }
1.409 albertel 4614: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4615: background: $tabbg;
4616: color: $font;
4617: font-family: $sans;
1.358 albertel 4618: font-size: smaller;
1.357 albertel 4619: }
1.411 albertel 4620: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4621: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4622: background: $tabbg;
4623: color: $font;
4624: font-family: $sans;
4625: font-size: larger;
4626: text-align: right;
4627: }
1.383 albertel 4628: td.LC_table_cell_checkbox {
4629: text-align: center;
4630: }
1.522 albertel 4631: table#LC_mainmenu td.LC_mainmenu_column {
4632: vertical-align: top;
4633: }
4634:
1.346 albertel 4635: .LC_menubuttons_inline_text {
4636: color: $font;
4637: font-family: $sans;
4638: font-size: smaller;
4639: }
4640:
1.526 www 4641: .LC_menubuttons_link {
4642: text-decoration: none;
4643: }
1.680 riegler 4644: #2008--9-5: new menu style sheet.Changed category
1.522 albertel 4645: .LC_menubuttons_category {
1.521 www 4646: color: $font;
1.526 www 4647: background: $pgbg;
1.521 www 4648: font-family: $sans;
4649: font-size: larger;
4650: font-weight: bold;
4651: }
4652:
1.346 albertel 4653: td.LC_menubuttons_text {
1.526 www 4654: width: 90%;
1.346 albertel 4655: color: $font;
4656: font-family: $sans;
4657: }
1.526 www 4658:
1.346 albertel 4659: td.LC_menubuttons_img {
4660: }
1.526 www 4661:
1.346 albertel 4662: .LC_current_location {
4663: font-family: $sans;
4664: background: $tabbg;
4665: }
4666: .LC_new_mail {
4667: font-family: $sans;
1.634 www 4668: background: $tabbg;
1.346 albertel 4669: font-weight: bold;
4670: }
1.347 albertel 4671:
1.526 www 4672: .LC_rolesmenu_is {
4673: font-family: $sans;
4674: }
4675:
4676: .LC_rolesmenu_selected {
4677: font-family: $sans;
4678: }
4679:
4680: .LC_rolesmenu_future {
4681: font-family: $sans;
4682: }
4683:
4684:
4685: .LC_rolesmenu_will {
4686: font-family: $sans;
4687: }
4688:
4689: .LC_rolesmenu_will_not {
4690: font-family: $sans;
4691: }
4692:
4693: .LC_rolesmenu_expired {
4694: font-family: $sans;
4695: }
4696:
4697: .LC_rolesinfo {
4698: font-family: $sans;
4699: }
4700:
1.527 www 4701: .LC_dropadd_labeltext {
4702: font-family: $sans;
4703: text-align: right;
4704: }
4705:
4706: .LC_preferences_labeltext {
4707: font-family: $sans;
4708: text-align: right;
4709: }
4710:
1.666 raeburn 4711: .LC_roleslog_note {
4712: font-size: smaller;
4713: }
4714:
1.440 albertel 4715: table.LC_aboutme_port {
4716: border: 0px;
4717: border-collapse: collapse;
4718: border-spacing: 0px;
4719: }
1.349 albertel 4720: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4721: border: 1px solid #000000;
1.402 albertel 4722: border-collapse: separate;
1.426 albertel 4723: border-spacing: 1px;
1.610 albertel 4724: background: $pgbg;
1.347 albertel 4725: }
1.422 albertel 4726: .LC_data_table_dense {
4727: font-size: small;
4728: }
1.507 raeburn 4729: table.LC_nested_outer {
4730: border: 1px solid #000000;
1.589 raeburn 4731: border-collapse: collapse;
1.507 raeburn 4732: border-spacing: 0px;
4733: width: 100%;
4734: }
4735: table.LC_nested {
4736: border: 0px;
1.589 raeburn 4737: border-collapse: collapse;
1.507 raeburn 4738: border-spacing: 0px;
4739: width: 100%;
4740: }
1.523 albertel 4741: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4742: table.LC_prior_tries tr th {
1.349 albertel 4743: font-weight: bold;
4744: background-color: $data_table_head;
1.421 albertel 4745: font-size: smaller;
1.347 albertel 4746: }
1.610 albertel 4747: table.LC_data_table tr.LC_odd_row > td,
1.440 albertel 4748: table.LC_aboutme_port tr td {
1.349 albertel 4749: background-color: $data_table_light;
1.425 albertel 4750: padding: 2px;
1.347 albertel 4751: }
1.610 albertel 4752: table.LC_data_table tr.LC_even_row > td,
1.440 albertel 4753: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4754: background-color: $data_table_dark;
1.347 albertel 4755: }
1.425 albertel 4756: table.LC_data_table tr.LC_data_table_highlight td {
4757: background-color: $data_table_darker;
4758: }
1.639 raeburn 4759: table.LC_data_table tr td.LC_leftcol_header {
4760: background-color: $data_table_head;
4761: font-weight: bold;
4762: }
1.451 albertel 4763: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4764: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4765: background-color: #FFFFFF;
1.421 albertel 4766: font-weight: bold;
4767: font-style: italic;
4768: text-align: center;
4769: padding: 8px;
1.347 albertel 4770: }
1.507 raeburn 4771: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4772: padding: 4ex
4773: }
1.507 raeburn 4774: table.LC_nested_outer tr th {
4775: font-weight: bold;
4776: background-color: $data_table_head;
4777: font-size: smaller;
4778: border-bottom: 1px solid #000000;
4779: }
4780: table.LC_nested_outer tr td.LC_subheader {
4781: background-color: $data_table_head;
4782: font-weight: bold;
4783: font-size: small;
4784: border-bottom: 1px solid #000000;
4785: text-align: right;
1.451 albertel 4786: }
1.507 raeburn 4787: table.LC_nested tr.LC_info_row td {
1.451 albertel 4788: background-color: #CCC;
4789: font-weight: bold;
4790: font-size: small;
1.507 raeburn 4791: text-align: center;
4792: }
1.589 raeburn 4793: table.LC_nested tr.LC_info_row td.LC_left_item,
4794: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4795: text-align: left;
1.451 albertel 4796: }
1.507 raeburn 4797: table.LC_nested td {
1.451 albertel 4798: background-color: #FFF;
4799: font-size: small;
1.507 raeburn 4800: }
4801: table.LC_nested_outer tr th.LC_right_item,
4802: table.LC_nested tr.LC_info_row td.LC_right_item,
4803: table.LC_nested tr.LC_odd_row td.LC_right_item,
4804: table.LC_nested tr td.LC_right_item {
1.451 albertel 4805: text-align: right;
4806: }
4807:
1.507 raeburn 4808: table.LC_nested tr.LC_odd_row td {
1.451 albertel 4809: background-color: #EEE;
4810: }
4811:
1.473 raeburn 4812: table.LC_createuser {
4813: }
4814:
4815: table.LC_createuser tr.LC_section_row td {
4816: font-size: smaller;
4817: }
4818:
4819: table.LC_createuser tr.LC_info_row td {
4820: background-color: #CCC;
4821: font-weight: bold;
4822: text-align: center;
4823: }
4824:
1.349 albertel 4825: table.LC_calendar {
4826: border: 1px solid #000000;
4827: border-collapse: collapse;
4828: }
4829: table.LC_calendar_pickdate {
4830: font-size: xx-small;
4831: }
4832: table.LC_calendar tr td {
4833: border: 1px solid #000000;
4834: vertical-align: top;
4835: }
4836: table.LC_calendar tr td.LC_calendar_day_empty {
4837: background-color: $data_table_dark;
4838: }
4839: table.LC_calendar tr td.LC_calendar_day_current {
4840: background-color: $data_table_highlight;
4841: }
4842:
4843: table.LC_mail_list tr.LC_mail_new {
4844: background-color: $mail_new;
4845: }
4846: table.LC_mail_list tr.LC_mail_new:hover {
4847: background-color: $mail_new_hover;
4848: }
4849: table.LC_mail_list tr.LC_mail_read {
4850: background-color: $mail_read;
4851: }
4852: table.LC_mail_list tr.LC_mail_read:hover {
4853: background-color: $mail_read_hover;
4854: }
4855: table.LC_mail_list tr.LC_mail_replied {
4856: background-color: $mail_replied;
4857: }
4858: table.LC_mail_list tr.LC_mail_replied:hover {
4859: background-color: $mail_replied_hover;
4860: }
4861: table.LC_mail_list tr.LC_mail_other {
4862: background-color: $mail_other;
4863: }
4864: table.LC_mail_list tr.LC_mail_other:hover {
4865: background-color: $mail_other_hover;
4866: }
1.494 raeburn 4867: table.LC_mail_list tr.LC_mail_even {
4868: }
4869: table.LC_mail_list tr.LC_mail_odd {
4870: }
4871:
1.385 albertel 4872:
1.386 albertel 4873: table#LC_portfolio_actions {
4874: width: auto;
4875: background: $pgbg;
4876: border: 0px;
4877: border-spacing: 2px 2px;
4878: padding: 0px;
4879: margin: 0px;
4880: border-collapse: separate;
4881: }
4882: table#LC_portfolio_actions td.LC_label {
4883: background: $tabbg;
4884: text-align: right;
4885: }
4886: table#LC_portfolio_actions td.LC_value {
4887: background: $tabbg;
4888: }
1.385 albertel 4889:
1.391 albertel 4890: table#LC_cstr_controls {
4891: width: 100%;
4892: border-collapse: collapse;
4893: }
4894: table#LC_cstr_controls tr td {
4895: border: 4px solid $pgbg;
4896: padding: 4px;
4897: text-align: center;
4898: background: $tabbg;
4899: }
4900: table#LC_cstr_controls tr th {
4901: border: 4px solid $pgbg;
4902: background: $table_header;
4903: text-align: center;
4904: font-family: $sans;
4905: font-size: smaller;
4906: }
4907:
1.389 albertel 4908: table#LC_browser {
4909:
4910: }
4911: table#LC_browser tr th {
1.391 albertel 4912: background: $table_header;
1.389 albertel 4913: }
1.390 albertel 4914: table#LC_browser tr td {
4915: padding: 2px;
4916: }
1.389 albertel 4917: table#LC_browser tr.LC_browser_file,
4918: table#LC_browser tr.LC_browser_file_published {
4919: background: #CCFF88;
4920: }
4921: table#LC_browser tr.LC_browser_file_locked,
4922: table#LC_browser tr.LC_browser_file_unpublished {
4923: background: #FFAA99;
1.387 albertel 4924: }
1.389 albertel 4925: table#LC_browser tr.LC_browser_file_obsolete {
4926: background: #AAAAAA;
1.387 albertel 4927: }
1.455 albertel 4928: table#LC_browser tr.LC_browser_file_modified,
4929: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 4930: background: #FFFF77;
1.387 albertel 4931: }
1.389 albertel 4932: table#LC_browser tr.LC_browser_folder {
4933: background: #CCCCFF;
1.387 albertel 4934: }
1.388 albertel 4935: span.LC_current_location {
4936: font-size: x-large;
4937: background: $pgbg;
4938: }
1.387 albertel 4939:
1.395 albertel 4940: span.LC_parm_menu_item {
4941: font-size: larger;
4942: font-family: $sans;
4943: }
4944: span.LC_parm_scope_all {
4945: color: red;
4946: }
4947: span.LC_parm_scope_folder {
4948: color: green;
4949: }
4950: span.LC_parm_scope_resource {
4951: color: orange;
4952: }
4953: span.LC_parm_part {
4954: color: blue;
4955: }
4956: span.LC_parm_folder, span.LC_parm_symb {
4957: font-size: x-small;
4958: font-family: $mono;
4959: color: #AAAAAA;
4960: }
4961:
1.396 albertel 4962: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4963: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4964: border: 1px solid black;
4965: border-collapse: collapse;
4966: }
4967: table.LC_parm_overview_restrictions td {
4968: border-width: 1px 4px 1px 4px;
4969: border-style: solid;
4970: border-color: $pgbg;
4971: text-align: center;
4972: }
4973: table.LC_parm_overview_restrictions th {
4974: background: $tabbg;
4975: border-width: 1px 4px 1px 4px;
4976: border-style: solid;
4977: border-color: $pgbg;
4978: }
1.398 albertel 4979: table#LC_helpmenu {
4980: border: 0px;
4981: height: 55px;
4982: border-spacing: 0px;
4983: }
4984:
4985: table#LC_helpmenu fieldset legend {
4986: font-size: larger;
4987: font-weight: bold;
4988: }
1.397 albertel 4989: table#LC_helpmenu_links {
4990: width: 100%;
4991: border: 1px solid black;
4992: background: $pgbg;
4993: padding: 0px;
4994: border-spacing: 1px;
4995: }
4996: table#LC_helpmenu_links tr td {
4997: padding: 1px;
4998: background: $tabbg;
1.399 albertel 4999: text-align: center;
5000: font-weight: bold;
1.397 albertel 5001: }
1.396 albertel 5002:
1.397 albertel 5003: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5004: table#LC_helpmenu_links a:active {
5005: text-decoration: none;
5006: color: $font;
5007: }
5008: table#LC_helpmenu_links a:hover {
5009: text-decoration: underline;
5010: color: $vlink;
5011: }
1.396 albertel 5012:
1.417 albertel 5013: .LC_chrt_popup_exists {
5014: border: 1px solid #339933;
5015: margin: -1px;
5016: }
5017: .LC_chrt_popup_up {
5018: border: 1px solid yellow;
5019: margin: -1px;
5020: }
5021: .LC_chrt_popup {
5022: border: 1px solid #8888FF;
5023: background: #CCCCFF;
5024: }
1.421 albertel 5025: table.LC_pick_box {
5026: border-collapse: separate;
5027: background: white;
5028: border: 1px solid black;
5029: border-spacing: 1px;
5030: }
5031: table.LC_pick_box td.LC_pick_box_title {
5032: background: $tabbg;
5033: font-weight: bold;
5034: text-align: right;
5035: width: 184px;
5036: padding: 8px;
5037: }
1.645 raeburn 5038: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5039: background: $tabbg;
5040: font-weight: bold;
5041: text-align: right;
5042: width: 350px;
5043: padding: 8px;
5044: }
5045:
1.579 raeburn 5046: table.LC_pick_box td.LC_pick_box_value {
5047: text-align: left;
5048: padding: 8px;
5049: }
5050: table.LC_pick_box td.LC_pick_box_select {
5051: text-align: left;
5052: padding: 8px;
5053: }
1.424 albertel 5054: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5055: padding: 0px;
5056: height: 1px;
5057: background: black;
5058: }
5059: table.LC_pick_box td.LC_pick_box_submit {
5060: text-align: right;
5061: }
1.579 raeburn 5062: table.LC_pick_box td.LC_evenrow_value {
5063: text-align: left;
5064: padding: 8px;
5065: background-color: $data_table_light;
5066: }
5067: table.LC_pick_box td.LC_oddrow_value {
5068: text-align: left;
5069: padding: 8px;
5070: background-color: $data_table_light;
5071: }
5072: table.LC_helpform_receipt {
5073: width: 620px;
5074: border-collapse: separate;
5075: background: white;
5076: border: 1px solid black;
5077: border-spacing: 1px;
5078: }
5079: table.LC_helpform_receipt td.LC_pick_box_title {
5080: background: $tabbg;
5081: font-weight: bold;
5082: text-align: right;
5083: width: 184px;
5084: padding: 8px;
5085: }
5086: table.LC_helpform_receipt td.LC_evenrow_value {
5087: text-align: left;
5088: padding: 8px;
5089: background-color: $data_table_light;
5090: }
5091: table.LC_helpform_receipt td.LC_oddrow_value {
5092: text-align: left;
5093: padding: 8px;
5094: background-color: $data_table_light;
5095: }
5096: table.LC_helpform_receipt td.LC_pick_box_separator {
5097: padding: 0px;
5098: height: 1px;
5099: background: black;
5100: }
5101: span.LC_helpform_receipt_cat {
5102: font-weight: bold;
5103: }
1.424 albertel 5104: table.LC_group_priv_box {
5105: background: white;
5106: border: 1px solid black;
5107: border-spacing: 1px;
5108: }
5109: table.LC_group_priv_box td.LC_pick_box_title {
5110: background: $tabbg;
5111: font-weight: bold;
5112: text-align: right;
5113: width: 184px;
5114: }
5115: table.LC_group_priv_box td.LC_groups_fixed {
5116: background: $data_table_light;
5117: text-align: center;
5118: }
5119: table.LC_group_priv_box td.LC_groups_optional {
5120: background: $data_table_dark;
5121: text-align: center;
5122: }
5123: table.LC_group_priv_box td.LC_groups_functionality {
5124: background: $data_table_darker;
5125: text-align: center;
5126: font-weight: bold;
5127: }
5128: table.LC_group_priv td {
5129: text-align: left;
5130: padding: 0px;
5131: }
5132:
1.421 albertel 5133: table.LC_notify_front_page {
5134: background: white;
5135: border: 1px solid black;
5136: padding: 8px;
5137: }
5138: table.LC_notify_front_page td {
5139: padding: 8px;
5140: }
1.424 albertel 5141: .LC_navbuttons {
5142: margin: 2ex 0ex 2ex 0ex;
5143: }
1.423 albertel 5144: .LC_topic_bar {
5145: font-family: $sans;
5146: font-weight: bold;
5147: width: 100%;
5148: background: $tabbg;
5149: vertical-align: middle;
5150: margin: 2ex 0ex 2ex 0ex;
5151: }
5152: .LC_topic_bar span {
5153: vertical-align: middle;
5154: }
5155: .LC_topic_bar img {
5156: vertical-align: bottom;
5157: }
5158: table.LC_course_group_status {
5159: margin: 20px;
5160: }
5161: table.LC_status_selector td {
5162: vertical-align: top;
5163: text-align: center;
1.424 albertel 5164: padding: 4px;
5165: }
5166: table.LC_descriptive_input td.LC_description {
5167: vertical-align: top;
5168: text-align: right;
5169: font-weight: bold;
1.423 albertel 5170: }
1.599 albertel 5171: div.LC_feedback_link {
1.616 albertel 5172: clear: both;
1.599 albertel 5173: background: white;
5174: width: 100%;
1.489 raeburn 5175: }
5176: span.LC_feedback_link {
1.599 albertel 5177: background: $feedback_link_bg;
5178: font-size: larger;
5179: }
5180: span.LC_message_link {
5181: background: $feedback_link_bg;
5182: font-size: larger;
5183: position: absolute;
5184: right: 1em;
1.489 raeburn 5185: }
1.421 albertel 5186:
1.515 albertel 5187: table.LC_prior_tries {
1.524 albertel 5188: border: 1px solid #000000;
5189: border-collapse: separate;
5190: border-spacing: 1px;
1.515 albertel 5191: }
1.523 albertel 5192:
1.515 albertel 5193: table.LC_prior_tries td {
1.524 albertel 5194: padding: 2px;
1.515 albertel 5195: }
1.523 albertel 5196:
5197: .LC_answer_correct {
5198: background: #AAFFAA;
5199: color: black;
5200: }
5201: .LC_answer_charged_try {
5202: background: #FFAAAA ! important;
5203: color: black;
5204: }
5205: .LC_answer_not_charged_try,
5206: .LC_answer_no_grade,
5207: .LC_answer_late {
5208: background: #FFFFAA;
5209: color: black;
5210: }
5211: .LC_answer_previous {
5212: background: #AAAAFF;
5213: color: black;
5214: }
5215: .LC_answer_no_message {
5216: background: #FFFFFF;
5217: color: black;
5218: }
5219: .LC_answer_unknown {
5220: background: orange;
5221: color: black;
5222: }
5223:
5224:
1.529 albertel 5225: span.LC_prior_numerical,
5226: span.LC_prior_string,
5227: span.LC_prior_custom,
5228: span.LC_prior_reaction,
5229: span.LC_prior_math {
1.523 albertel 5230: font-family: monospace;
5231: white-space: pre;
5232: }
5233:
1.525 albertel 5234: span.LC_prior_string {
5235: font-family: monospace;
5236: white-space: pre;
5237: }
5238:
1.523 albertel 5239: table.LC_prior_option {
5240: width: 100%;
5241: border-collapse: collapse;
5242: }
1.528 albertel 5243: table.LC_prior_rank, table.LC_prior_match {
5244: border-collapse: collapse;
5245: }
5246: table.LC_prior_option tr td,
5247: table.LC_prior_rank tr td,
5248: table.LC_prior_match tr td {
1.524 albertel 5249: border: 1px solid #000000;
1.515 albertel 5250: }
5251:
1.519 raeburn 5252: span.LC_nobreak {
1.544 albertel 5253: white-space: nowrap;
1.519 raeburn 5254: }
5255:
1.576 raeburn 5256: span.LC_cusr_emph {
5257: font-style: italic;
5258: }
5259:
1.633 raeburn 5260: span.LC_cusr_subheading {
5261: font-weight: normal;
5262: font-size: 85%;
5263: }
5264:
1.545 albertel 5265: table.LC_docs_documents {
5266: background: #BBBBBB;
1.547 albertel 5267: border-width: 0px;
1.545 albertel 5268: border-collapse: collapse;
5269: }
5270:
5271: table.LC_docs_documents td.LC_docs_document {
5272: border: 2px solid black;
5273: padding: 4px;
5274: }
5275:
5276: .LC_docs_course_commands div {
5277: float: left;
5278: border: 4px solid #AAAAAA;
5279: padding: 4px;
5280: background: #DDDDCC;
5281: }
5282:
5283: .LC_docs_entry_move {
5284: border: 0px;
5285: border-collapse: collapse;
1.544 albertel 5286: }
5287:
1.545 albertel 5288: .LC_docs_entry_move td {
5289: border: 2px solid #BBBBBB;
5290: background: #DDDDDD;
5291: }
5292:
5293: .LC_docs_editor td.LC_docs_entry_commands {
5294: background: #DDDDDD;
5295: font-size: x-small;
5296: }
1.544 albertel 5297: .LC_docs_copy {
1.545 albertel 5298: color: #000099;
1.544 albertel 5299: }
5300: .LC_docs_cut {
1.545 albertel 5301: color: #550044;
1.544 albertel 5302: }
5303: .LC_docs_rename {
1.545 albertel 5304: color: #009900;
1.544 albertel 5305: }
5306: .LC_docs_remove {
1.545 albertel 5307: color: #990000;
5308: }
5309:
1.547 albertel 5310: .LC_docs_reinit_warn,
5311: .LC_docs_ext_edit {
5312: font-size: x-small;
5313: }
5314:
1.545 albertel 5315: .LC_docs_editor td.LC_docs_entry_title,
5316: .LC_docs_editor td.LC_docs_entry_icon {
5317: background: #FFFFBB;
5318: }
5319: .LC_docs_editor td.LC_docs_entry_parameter {
5320: background: #BBBBFF;
5321: font-size: x-small;
5322: white-space: nowrap;
5323: }
5324:
5325: table.LC_docs_adddocs td,
5326: table.LC_docs_adddocs th {
5327: border: 1px solid #BBBBBB;
5328: padding: 4px;
5329: background: #DDDDDD;
1.543 albertel 5330: }
5331:
1.584 albertel 5332: table.LC_sty_begin {
5333: background: #BBFFBB;
5334: }
5335: table.LC_sty_end {
5336: background: #FFBBBB;
5337: }
5338:
1.589 raeburn 5339: table.LC_double_column {
5340: border-width: 0px;
5341: border-collapse: collapse;
5342: width: 100%;
5343: padding: 2px;
5344: }
5345:
5346: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5347: top: 2px;
1.589 raeburn 5348: left: 2px;
5349: width: 47%;
5350: vertical-align: top;
5351: }
5352:
5353: table.LC_double_column tr td.LC_right_col {
5354: top: 2px;
5355: right: 2px;
5356: width: 47%;
5357: vertical-align: top;
5358: }
5359:
1.594 raeburn 5360: span.LC_role_level {
5361: font-weight: bold;
5362: }
5363:
1.591 raeburn 5364: div.LC_left_float {
5365: float: left;
5366: padding-right: 5%;
1.597 albertel 5367: padding-bottom: 4px;
1.591 raeburn 5368: }
5369:
5370: div.LC_clear_float_header {
1.597 albertel 5371: padding-bottom: 2px;
1.591 raeburn 5372: }
5373:
5374: div.LC_clear_float_footer {
1.597 albertel 5375: padding-top: 10px;
1.591 raeburn 5376: clear: both;
5377: }
5378:
1.597 albertel 5379:
1.601 albertel 5380: div.LC_grade_select_mode {
1.604 albertel 5381: font-family: $sans;
1.601 albertel 5382: }
5383: div.LC_grade_select_mode div div {
5384: margin: 5px;
5385: }
5386: div.LC_grade_select_mode_selector {
5387: margin: 5px;
5388: float: left;
5389: }
5390: div.LC_grade_select_mode_selector_header {
5391: font: bold medium $sans;
5392: }
5393: div.LC_grade_select_mode_type {
5394: clear: left;
5395: }
5396:
1.597 albertel 5397: div.LC_grade_show_user {
5398: margin-top: 20px;
5399: border: 1px solid black;
5400: }
5401: div.LC_grade_user_name {
5402: background: #DDDDEE;
5403: border-bottom: 1px solid black;
5404: font: bold large $sans;
5405: }
5406: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5407: background: #DDEEDD;
5408: }
5409:
5410: div.LC_grade_show_problem,
5411: div.LC_grade_submissions,
5412: div.LC_grade_message_center,
5413: div.LC_grade_info_links,
5414: div.LC_grade_assign {
5415: margin: 5px;
5416: width: 99%;
5417: background: #FFFFFF;
5418: }
5419: div.LC_grade_show_problem_header,
5420: div.LC_grade_submissions_header,
5421: div.LC_grade_message_center_header,
5422: div.LC_grade_assign_header {
5423: font: bold large $sans;
5424: }
5425: div.LC_grade_show_problem_problem,
5426: div.LC_grade_submissions_body,
5427: div.LC_grade_message_center_body,
5428: div.LC_grade_assign_body {
5429: border: 1px solid black;
5430: width: 99%;
5431: background: #FFFFFF;
5432: }
1.598 albertel 5433: span.LC_grade_check_note {
5434: font: normal medium $sans;
5435: display: inline;
5436: position: absolute;
5437: right: 1em;
5438: }
1.597 albertel 5439:
1.613 albertel 5440: table.LC_scantron_action {
5441: width: 100%;
5442: }
5443: table.LC_scantron_action tr th {
5444: font: normal bold $sans;
5445: }
1.600 albertel 5446:
1.614 albertel 5447: div.LC_edit_problem_header,
5448: div.LC_edit_problem_footer {
1.600 albertel 5449: font: normal medium $sans;
1.602 albertel 5450: margin: 2px;
1.600 albertel 5451: }
5452: div.LC_edit_problem_header,
1.602 albertel 5453: div.LC_edit_problem_header div,
1.614 albertel 5454: div.LC_edit_problem_footer,
5455: div.LC_edit_problem_footer div,
1.602 albertel 5456: div.LC_edit_problem_editxml_header,
5457: div.LC_edit_problem_editxml_header div {
1.600 albertel 5458: margin-top: 5px;
5459: }
1.602 albertel 5460: div.LC_edit_problem_header_edit_row {
5461: background: $tabbg;
5462: padding: 3px;
5463: margin-bottom: 5px;
5464: }
1.600 albertel 5465: div.LC_edit_problem_header_title {
1.602 albertel 5466: font: larger bold $sans;
5467: background: $tabbg;
5468: padding: 3px;
5469: }
5470: table.LC_edit_problem_header_title {
5471: font: larger bold $sans;
5472: width: 100%;
5473: border-color: $pgbg;
5474: border-style: solid;
5475: border-width: $border;
5476:
1.600 albertel 5477: background: $tabbg;
1.602 albertel 5478: border-collapse: collapse;
5479: padding: 0px
5480: }
5481:
5482: div.LC_edit_problem_discards {
5483: float: left;
5484: padding-bottom: 5px;
5485: }
5486: div.LC_edit_problem_saves {
5487: float: right;
5488: padding-bottom: 5px;
1.600 albertel 5489: }
5490: hr.LC_edit_problem_divide {
1.602 albertel 5491: clear: both;
1.600 albertel 5492: color: $tabbg;
5493: background-color: $tabbg;
5494: height: 3px;
5495: border: 0px;
5496: }
1.679 riegler 5497: img.stift{
1.678 riegler 5498: border-width:0;
1.679 riegler 5499: vertical-align:middle;
1.677 riegler 5500: }
1.680 riegler 5501:
1.681 riegler 5502: table#LC_mainmenu{
5503: margin-top:10px;
5504: width:80%;
5505:
5506: }
5507:
1.680 riegler 5508: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5509: vertical-align: top;
5510: width: 45%;
5511: }
5512: .LC_mainmenu_fieldset_category {
5513: color: $font;
5514: background: $pgbg;
5515: font-family: $sans;
5516: font-size: small;
5517: font-weight: bold;
5518: }
5519: fieldset#LC_mainmenu_fieldset {
1.681 riegler 5520: margin:0px 10px 10px 0px;
1.680 riegler 5521:
5522: }
1.693 droeschl 5523: /* ---- Remove when done ----
5524: # The following styles is part of the redesign of LON-CAPA and are
5525: # subject to change during this project.
5526: # Don't rely on their current functionality as they might be
5527: # changed or removed.
5528: # --------------------------*/
5529:
5530:
5531: body {
5532: font-family: Tahoma, Arial,Helvetica,sans-serif;
5533: font-size: 0.85em;
5534: line-height: 130%;
5535: color: RGB(45, 45, 45);
5536: }
5537:
5538: a:link,a:visited {
5539: /*color: RGB(0, 118, 127);*/
5540: /*text-decoration: underline;*/
5541: }
5542:
5543: a:hover{
5544: text-decoration:none;
5545: }
5546: /*a:hover,
5547: UL.smallMenu A:hover,
5548: UL.MenuBreadcrumbs A:hover,
5549: UL#TabMainMenuContent A:hover{
5550: color: rgb(200, 10, 50);
5551: }*/
5552:
5553: h1 {
5554: padding:5px 10px 5px 20px;
5555: line-height:130%;
5556: }
5557: h2,h4,h6 {
5558: /*color: RGB(0, 118, 127);*/
5559: }
5560: h2,h3,h4,h5,h6
5561: {
5562: margin:5px 0px 5px 0px;
5563: line-height:130%;
5564: }
5565:
5566: .right {
5567: text-align: right;
5568: }
5569:
5570: .center {
5571: text-align: center;
5572: }
5573:
5574: .left {
5575: text-align: left;
5576: }
5577:
5578:
5579: .HeadRight {
5580: text-align: right;
5581: float: right;
5582: margin: 0px;
5583: padding: 0px;
5584: right:0;
5585: position:absolute;
5586: }
5587:
5588: img {
5589: /* border: 0px; */
5590: }
5591:
5592: .personalBgColor {
5593: background: RGB(237, 239, 0) url(images/headHighlight.png) repeat-y left top;
5594: }
5595:
5596: p {
5597: padding: 10px;
5598: }
5599: DL,UL,Div,Fieldset {
5600: /*margin: 10px;*/
5601: overflow:hidden;
5602: }
5603: OL.smallMenu {
5604: margin: 0px 0px 0px 0px;
5605: }
5606:
5607: OL.smallMenu li {
5608: display: inline;
5609: padding: 5px 5px 0px 10px;
5610: vertical-align: top;
5611: }
5612:
5613: OL.smallMenu li img {
5614: vertical-align: bottom;
5615: }
5616:
5617: OL.smallMenu A {
5618: font-size: 90%;
5619: color: RGB(80, 80, 80);
5620: text-decoration: none;
5621: }
5622:
5623: OL#TabMainMenuContent {
5624:
5625: margin: 0px 0px 10px 0px;
5626: padding: 0px;
5627: }
5628:
5629: OL#TabMainMenuContent LI {
5630: display: inline;
5631: vertical-align: bottom;
5632: border-bottom: solid 1px RGB(175, 175, 175);
5633: border-right: solid 1px RGB(175, 175, 175);
5634: padding: 5px 15px 5px 15px;
5635: margin-right:4px;
5636: line-height: 140%;
5637: font-weight: bold;
5638: overflow:hidden;
5639: background: RGB(211, 206, 205) URL(images/TabMenuBG.png) repeat-x left top;
5640: }
5641:
5642: OL#TabMainMenuContent LI A {
5643: color: RGB(47, 47, 47);
5644: text-decoration: none;
5645: }
5646:
5647: OL#TabMainMenuContent DIV.columnSection {
5648: margin-bottom: 0px;
5649: }
5650:
5651: OL#MenuBreadcrumbs {
5652: border-top: solid 1px RGB(255, 255, 255);
5653: height: 20px;
5654: line-height: 20px;
5655: vertical-align: bottom;
5656: margin: 0px 0px 30px 0px;
5657: padding-left: 10px;
5658: list-style-position: inside;
5659: background: RGB(211, 206, 205) URL(images/TabMenuBG.png) repeat-x left
5660: top;
5661: }
5662:
5663: OL#MenuBreadcrumbs li {
5664: background: url(images/pfeil_white.png) no-repeat left center;
5665: display: inline;
5666: padding: 0px 0px 0px 10px;
5667: vertical-align: bottom;
5668: overflow:hidden;
5669: }
5670:
5671: OL#MenuBreadcrumbs LI A {
5672: text-decoration: none;
5673: font-size:90%;
5674: }
5675:
5676: h4.hcell {
5677: padding: 3px 10px 3px 10px;
5678: margin: 0px;
5679: background: RGB(0, 118, 127);
5680: color: white;
5681: border: outset 1px;
5682: }
5683:
5684: DIV.DivContentBoxSpecial
5685: {
5686: border: solid 1px RGB(100, 100, 100);
5687: }
5688:
5689: FIELDSET
5690: {
5691: /*width:78%;*/
5692: }
5693: DIV.DivContentBox,
5694: DIV.DivContentBoxSpecial {
5695: width: 80%;
5696: margin:10px;
5697: }
5698:
5699: FIELDSET legend,DL DT {
5700: font-weight: bold;
5701: font-size: 110%;
5702: /*padding-left: 0px;*/
5703: /* margin-left: 0px;*/
5704: }
5705:
5706: DIV.DivImportant {
5707: background: url(images/important.png) no-repeat center top;
5708: padding: 100px 10px 10px 10px;
5709: width: 200px;
5710: border: double 4px RGB(200, 200, 200);
5711: }
5712:
5713:
5714:
5715: DL.ListStyleClean DT {
5716: padding-right: 5px;
5717: display: table-header-group;
5718: }
5719:
5720: DL.ListStyleClean DD {
5721: display: table-row;
5722: }
5723:
5724: .ListStyleClean,
5725: .ListStyleSimple,
5726: .ListStyleNormal,
5727: .ListStyleNormal_Border,
5728: .ListStyleSpecial
5729: {
5730: /*display:block; */
5731: width: 400px;
5732: list-style-position: inside;
5733: list-style-type: none;
5734: overflow: hidden;
5735: padding: 0px;
5736: }
5737:
5738: .ListStyleClean li,
5739: .ListStyleSimple li,
5740: .ListStyleSimple DD,
5741: .ListStyleNormal li,
5742: .ListStyleNormal DD,
5743: .ListStyleSpecial li,
5744: .ListStyleSpecial DD
5745: {
5746: margin: 0px;
5747: padding: 5px 5px 5px 10px;
5748: clear: both;
5749: /*display:block;*/
5750: }
5751:
5752: .ListStyleClean LI,
5753: .ListStyleClean DD {
5754: padding-top: 0px;
5755: padding-bottom: 0px;
5756: }
5757:
5758: .ListStyleSimple DD,
5759: .ListStyleSimple LI{
5760: border-bottom: solid 1px RGB(150, 150, 150);
5761: }
5762:
5763: .ListStyleSpecial LI,
5764: .ListStyleSpecial DD {
5765: list-style-type: none;
5766: background-color: RGB(220, 220, 220);
5767: margin-bottom: 4px;
5768: }
5769:
5770: table.SimpleTable *{
5771: padding:10px;
5772: }
5773:
5774: table.SimpleTable td {
5775: vertical-align:top;
5776: border:solid 1px RGB(210,210,210);
5777: }
5778: table.SimpleTable thead{
5779: background:rgb(210,210,210);
5780: }
5781:
5782: DIV.columnSection {
5783: display: block;
5784: clear: both;
5785: overflow: hidden;
5786: margin:0px;
5787: }
5788:
5789: DIV.columnSection>* {
5790: float: left;
5791: margin: 10px 20px 10px 0px;
5792: overflow:hidden;
5793: }
5794:
5795: DIV.columnSection>FIELDSET,
5796: DIV.columnSection>DIV.DivContentBox,
5797: DIV.columnSection>DIV.DivContentBoxSpecial
5798: {
5799: width: 480px;
5800:
5801: }
5802:
1.694 ! tempelho 5803: .LC_loginpage_container {
! 5804: text-align:left;
! 5805: margin : 0 auto;
! 5806: width:65%;
! 5807: padding: 10px;
! 5808: height: auto;
! 5809: background-color:#FFFFFF;
! 5810: border:1px solid #CCCCCC;
! 5811: }
! 5812:
! 5813:
! 5814: .LC_loginpage_loginContainer {
! 5815: float:left;
! 5816: width:60%;
! 5817: }
! 5818:
! 5819: .LC_loginpage_loginInfo {
! 5820: margin-top:20px;
! 5821: margin-left:20px;
! 5822: float:left;
! 5823: width:30%;
! 5824: border:1px solid #CCCCCC;
! 5825: padding:10px;
! 5826: }
! 5827:
! 5828: .LC_loginpage_space {
! 5829: clear:both;
! 5830: margin-bottom:20px;
! 5831: border-bottom: 1px solid #CCCCCC;
! 5832: }
! 5833:
! 5834: .LC_loginpage_fieldset{
! 5835: border: 1px solid #CCCCCC;
! 5836: margin: 0 auto;
! 5837: }
! 5838:
! 5839: .LC_loginpage_legend{
! 5840: padding: 2px;
! 5841: margin: 0px;
! 5842: font-size:14px;
! 5843: font-weight:bold;
! 5844: }
! 5845:
! 5846:
1.693 droeschl 5847:
1.343 albertel 5848: END
5849: }
5850:
1.306 albertel 5851: =pod
5852:
5853: =item * &headtag()
5854:
5855: Returns a uniform footer for LON-CAPA web pages.
5856:
1.307 albertel 5857: Inputs: $title - optional title for the head
5858: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5859: $args - optional arguments
1.319 albertel 5860: force_register - if is true call registerurl so the remote is
5861: informed
1.415 albertel 5862: redirect -> array ref of
5863: 1- seconds before redirect occurs
5864: 2- url to redirect to
5865: 3- whether the side effect should occur
1.315 albertel 5866: (side effect of setting
5867: $env{'internal.head.redirect'} to the url
5868: redirected too)
1.352 albertel 5869: domain -> force to color decorate a page for a specific
5870: domain
5871: function -> force usage of a specific rolish color scheme
5872: bgcolor -> override the default page bgcolor
1.460 albertel 5873: no_auto_mt_title
5874: -> prevent &mt()ing the title arg
1.464 albertel 5875:
1.306 albertel 5876: =cut
5877:
5878: sub headtag {
1.313 albertel 5879: my ($title,$head_extra,$args) = @_;
1.306 albertel 5880:
1.363 albertel 5881: my $function = $args->{'function'} || &get_users_function();
5882: my $domain = $args->{'domain'} || &determinedomain();
5883: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5884: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5885: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5886: #time(),
1.418 albertel 5887: $env{'environment.color.timestamp'},
1.363 albertel 5888: $function,$domain,$bgcolor);
5889:
1.369 www 5890: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5891:
1.308 albertel 5892: my $result =
5893: '<head>'.
1.461 albertel 5894: &font_settings();
1.319 albertel 5895:
1.461 albertel 5896: if (!$args->{'frameset'}) {
5897: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5898: }
1.319 albertel 5899: if ($args->{'force_register'}) {
5900: $result .= &Apache::lonmenu::registerurl(1);
5901: }
1.436 albertel 5902: if (!$args->{'no_nav_bar'}
5903: && !$args->{'only_body'}
5904: && !$args->{'frameset'}) {
5905: $result .= &help_menu_js();
5906: }
1.319 albertel 5907:
1.314 albertel 5908: if (ref($args->{'redirect'})) {
1.414 albertel 5909: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5910: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5911: if (!$inhibit_continue) {
5912: $env{'internal.head.redirect'} = $url;
5913: }
1.313 albertel 5914: $result.=<<ADDMETA
5915: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5916: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5917: ADDMETA
5918: }
1.306 albertel 5919: if (!defined($title)) {
5920: $title = 'The LearningOnline Network with CAPA';
5921: }
1.460 albertel 5922: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5923: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5924: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5925: .$head_extra;
1.306 albertel 5926: return $result;
5927: }
5928:
5929: =pod
5930:
1.340 albertel 5931: =item * &font_settings()
5932:
5933: Returns neccessary <meta> to set the proper encoding
5934:
5935: Inputs: none
5936:
5937: =cut
5938:
5939: sub font_settings {
5940: my $headerstring='';
1.647 www 5941: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5942: $headerstring.=
5943: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5944: }
5945: return $headerstring;
5946: }
5947:
1.341 albertel 5948: =pod
5949:
5950: =item * &xml_begin()
5951:
5952: Returns the needed doctype and <html>
5953:
5954: Inputs: none
5955:
5956: =cut
5957:
5958: sub xml_begin {
5959: my $output='';
5960:
1.592 albertel 5961: if ($env{'internal.start_page'}==1) {
5962: &Apache::lonhtmlcommon::init_htmlareafields();
5963: }
1.342 albertel 5964:
1.341 albertel 5965: if ($env{'browser.mathml'}) {
5966: $output='<?xml version="1.0"?>'
5967: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5968: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5969:
5970: # .'<!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">] >'
5971: .'<!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">'
5972: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5973: .'xmlns="http://www.w3.org/1999/xhtml">';
5974: } else {
5975: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5976: }
5977: return $output;
5978: }
1.340 albertel 5979:
5980: =pod
5981:
1.306 albertel 5982: =item * &endheadtag()
5983:
5984: Returns a uniform </head> for LON-CAPA web pages.
5985:
5986: Inputs: none
5987:
5988: =cut
5989:
5990: sub endheadtag {
5991: return '</head>';
5992: }
5993:
5994: =pod
5995:
5996: =item * &head()
5997:
5998: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5999:
1.648 raeburn 6000: Inputs:
6001:
6002: =over 4
6003:
6004: $title - optional title for the page
6005:
6006: $head_extra - optional extra HTML to put inside the <head>
6007:
6008: =back
1.405 albertel 6009:
1.306 albertel 6010: =cut
6011:
6012: sub head {
1.325 albertel 6013: my ($title,$head_extra,$args) = @_;
6014: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6015: }
6016:
6017: =pod
6018:
6019: =item * &start_page()
6020:
6021: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6022:
1.648 raeburn 6023: Inputs:
6024:
6025: =over 4
6026:
6027: $title - optional title for the page
6028:
6029: $head_extra - optional extra HTML to incude inside the <head>
6030:
6031: $args - additional optional args supported are:
6032:
6033: =over 8
6034:
6035: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6036: arg on
1.648 raeburn 6037: no_nav_bar -> is true will set &bodytag() notopbar arg on
6038: add_entries -> additional attributes to add to the <body>
6039: domain -> force to color decorate a page for a
1.317 albertel 6040: specific domain
1.648 raeburn 6041: function -> force usage of a specific rolish color
1.317 albertel 6042: scheme
1.648 raeburn 6043: redirect -> see &headtag()
6044: bgcolor -> override the default page bg color
6045: js_ready -> return a string ready for being used in
1.317 albertel 6046: a javascript writeln
1.648 raeburn 6047: html_encode -> return a string ready for being used in
1.320 albertel 6048: a html attribute
1.648 raeburn 6049: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6050: $forcereg arg
1.648 raeburn 6051: body_title -> alternate text to use instead of $title
1.326 albertel 6052: in the title box that appears, this text
6053: is not auto translated like the $title is
1.648 raeburn 6054: frameset -> if true will start with a <frameset>
1.330 albertel 6055: rather than <body>
1.648 raeburn 6056: no_title -> if true the title bar won't be shown
6057: skip_phases -> hash ref of
1.338 albertel 6058: head -> skip the <html><head> generation
6059: body -> skip all <body> generation
1.648 raeburn 6060: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6061: 'Switch To Inline Menu' link
1.648 raeburn 6062: no_auto_mt_title -> prevent &mt()ing the title arg
6063: inherit_jsmath -> when creating popup window in a page,
6064: should it have jsmath forced on by the
6065: current page
1.361 albertel 6066:
1.648 raeburn 6067: =back
1.460 albertel 6068:
1.648 raeburn 6069: =back
1.562 albertel 6070:
1.306 albertel 6071: =cut
6072:
6073: sub start_page {
1.309 albertel 6074: my ($title,$head_extra,$args) = @_;
1.318 albertel 6075: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6076: my %head_args;
1.352 albertel 6077: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6078: 'bgcolor','frameset','no_nav_bar','only_body',
6079: 'no_auto_mt_title') {
1.319 albertel 6080: if (defined($args->{$arg})) {
1.324 raeburn 6081: $head_args{$arg} = $args->{$arg};
1.319 albertel 6082: }
1.313 albertel 6083: }
1.319 albertel 6084:
1.315 albertel 6085: $env{'internal.start_page'}++;
1.338 albertel 6086: my $result;
6087: if (! exists($args->{'skip_phases'}{'head'}) ) {
6088: $result.=
1.341 albertel 6089: &xml_begin().
1.338 albertel 6090: &headtag($title,$head_extra,\%head_args).&endheadtag();
6091: }
6092:
6093: if (! exists($args->{'skip_phases'}{'body'}) ) {
6094: if ($args->{'frameset'}) {
6095: my $attr_string = &make_attr_string($args->{'force_register'},
6096: $args->{'add_entries'});
6097: $result .= "\n<frameset $attr_string>\n";
6098: } else {
6099: $result .=
6100: &bodytag($title,
6101: $args->{'function'}, $args->{'add_entries'},
6102: $args->{'only_body'}, $args->{'domain'},
6103: $args->{'force_register'}, $args->{'body_title'},
6104: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6105: $args->{'no_title'}, $args->{'no_inline_link'},
6106: $args);
1.338 albertel 6107: }
1.330 albertel 6108: }
1.338 albertel 6109:
1.315 albertel 6110: if ($args->{'js_ready'}) {
1.317 albertel 6111: $result = &js_ready($result);
1.315 albertel 6112: }
1.320 albertel 6113: if ($args->{'html_encode'}) {
6114: $result = &html_encode($result);
6115: }
1.315 albertel 6116: return $result;
1.306 albertel 6117: }
6118:
1.330 albertel 6119:
1.306 albertel 6120: =pod
6121:
6122: =item * &head()
6123:
6124: Returns a complete </body></html> section for LON-CAPA web pages.
6125:
1.315 albertel 6126: Inputs: $args - additional optional args supported are:
6127: js_ready -> return a string ready for being used in
6128: a javascript writeln
1.320 albertel 6129: html_encode -> return a string ready for being used in
6130: a html attribute
1.330 albertel 6131: frameset -> if true will start with a <frameset>
6132: rather than <body>
1.493 albertel 6133: dicsussion -> if true will get discussion from
6134: lonxml::xmlend
6135: (you can pass the target and parser arguments
6136: through optional 'target' and 'parser' args
6137: to this routine)
1.306 albertel 6138:
6139: =cut
6140:
6141: sub end_page {
1.315 albertel 6142: my ($args) = @_;
6143: $env{'internal.end_page'}++;
1.330 albertel 6144: my $result;
1.335 albertel 6145: if ($args->{'discussion'}) {
6146: my ($target,$parser);
6147: if (ref($args->{'discussion'})) {
6148: ($target,$parser) =($args->{'discussion'}{'target'},
6149: $args->{'discussion'}{'parser'});
6150: }
6151: $result .= &Apache::lonxml::xmlend($target,$parser);
6152: }
6153:
1.330 albertel 6154: if ($args->{'frameset'}) {
6155: $result .= '</frameset>';
6156: } else {
1.635 raeburn 6157: $result .= &endbodytag($args);
1.330 albertel 6158: }
6159: $result .= "\n</html>";
6160:
1.315 albertel 6161: if ($args->{'js_ready'}) {
1.317 albertel 6162: $result = &js_ready($result);
1.315 albertel 6163: }
1.335 albertel 6164:
1.320 albertel 6165: if ($args->{'html_encode'}) {
6166: $result = &html_encode($result);
6167: }
1.335 albertel 6168:
1.315 albertel 6169: return $result;
6170: }
6171:
1.320 albertel 6172: sub html_encode {
6173: my ($result) = @_;
6174:
1.322 albertel 6175: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6176:
6177: return $result;
6178: }
1.317 albertel 6179: sub js_ready {
6180: my ($result) = @_;
6181:
1.323 albertel 6182: $result =~ s/[\n\r]/ /xmsg;
6183: $result =~ s/\\/\\\\/xmsg;
6184: $result =~ s/'/\\'/xmsg;
1.372 albertel 6185: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6186:
6187: return $result;
6188: }
6189:
1.315 albertel 6190: sub validate_page {
6191: if ( exists($env{'internal.start_page'})
1.316 albertel 6192: && $env{'internal.start_page'} > 1) {
6193: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6194: $env{'internal.start_page'}.' '.
1.316 albertel 6195: $ENV{'request.filename'});
1.315 albertel 6196: }
6197: if ( exists($env{'internal.end_page'})
1.316 albertel 6198: && $env{'internal.end_page'} > 1) {
6199: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6200: $env{'internal.end_page'}.' '.
1.316 albertel 6201: $env{'request.filename'});
1.315 albertel 6202: }
6203: if ( exists($env{'internal.start_page'})
6204: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6205: &Apache::lonnet::logthis('start_page called without end_page '.
6206: $env{'request.filename'});
1.315 albertel 6207: }
6208: if ( ! exists($env{'internal.start_page'})
6209: && exists($env{'internal.end_page'})) {
1.316 albertel 6210: &Apache::lonnet::logthis('end_page called without start_page'.
6211: $env{'request.filename'});
1.315 albertel 6212: }
1.306 albertel 6213: }
1.315 albertel 6214:
1.318 albertel 6215: sub simple_error_page {
6216: my ($r,$title,$msg) = @_;
6217: my $page =
6218: &Apache::loncommon::start_page($title).
6219: &mt($msg).
6220: &Apache::loncommon::end_page();
6221: if (ref($r)) {
6222: $r->print($page);
1.327 albertel 6223: return;
1.318 albertel 6224: }
6225: return $page;
6226: }
1.347 albertel 6227:
6228: {
1.610 albertel 6229: my @row_count;
1.347 albertel 6230: sub start_data_table {
1.422 albertel 6231: my ($add_class) = @_;
6232: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6233: unshift(@row_count,0);
1.422 albertel 6234: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6235: }
6236:
6237: sub end_data_table {
1.610 albertel 6238: shift(@row_count);
1.389 albertel 6239: return '</table>'."\n";;
1.347 albertel 6240: }
6241:
6242: sub start_data_table_row {
1.422 albertel 6243: my ($add_class) = @_;
1.610 albertel 6244: $row_count[0]++;
6245: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6246: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6247: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6248: }
1.471 banghart 6249:
6250: sub continue_data_table_row {
6251: my ($add_class) = @_;
1.610 albertel 6252: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6253: $css_class = (join(' ',$css_class,$add_class));
6254: return '<tr class="'.$css_class.'">'."\n";;
6255: }
1.347 albertel 6256:
6257: sub end_data_table_row {
1.389 albertel 6258: return '</tr>'."\n";;
1.347 albertel 6259: }
1.367 www 6260:
1.421 albertel 6261: sub start_data_table_empty_row {
1.610 albertel 6262: $row_count[0]++;
1.421 albertel 6263: return '<tr class="LC_empty_row" >'."\n";;
6264: }
6265:
6266: sub end_data_table_empty_row {
6267: return '</tr>'."\n";;
6268: }
6269:
1.367 www 6270: sub start_data_table_header_row {
1.389 albertel 6271: return '<tr class="LC_header_row">'."\n";;
1.367 www 6272: }
6273:
6274: sub end_data_table_header_row {
1.389 albertel 6275: return '</tr>'."\n";;
1.367 www 6276: }
1.347 albertel 6277: }
6278:
1.548 albertel 6279: =pod
6280:
6281: =item * &inhibit_menu_check($arg)
6282:
6283: Checks for a inhibitmenu state and generates output to preserve it
6284:
6285: Inputs: $arg - can be any of
6286: - undef - in which case the return value is a string
6287: to add into arguments list of a uri
6288: - 'input' - in which case the return value is a HTML
6289: <form> <input> field of type hidden to
6290: preserve the value
6291: - a url - in which case the return value is the url with
6292: the neccesary cgi args added to preserve the
6293: inhibitmenu state
6294: - a ref to a url - no return value, but the string is
6295: updated to include the neccessary cgi
6296: args to preserve the inhibitmenu state
6297:
6298: =cut
6299:
6300: sub inhibit_menu_check {
6301: my ($arg) = @_;
6302: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6303: if ($arg eq 'input') {
6304: if ($env{'form.inhibitmenu'}) {
6305: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6306: } else {
6307: return
6308: }
6309: }
6310: if ($env{'form.inhibitmenu'}) {
6311: if (ref($arg)) {
6312: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6313: } elsif ($arg eq '') {
6314: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6315: } else {
6316: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6317: }
6318: }
6319: if (!ref($arg)) {
6320: return $arg;
6321: }
6322: }
6323:
1.251 albertel 6324: ###############################################
1.182 matthew 6325:
6326: =pod
6327:
1.549 albertel 6328: =back
6329:
6330: =head1 User Information Routines
6331:
6332: =over 4
6333:
1.405 albertel 6334: =item * &get_users_function()
1.182 matthew 6335:
6336: Used by &bodytag to determine the current users primary role.
6337: Returns either 'student','coordinator','admin', or 'author'.
6338:
6339: =cut
6340:
6341: ###############################################
6342: sub get_users_function {
6343: my $function = 'student';
1.258 albertel 6344: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6345: $function='coordinator';
6346: }
1.258 albertel 6347: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6348: $function='admin';
6349: }
1.258 albertel 6350: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6351: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6352: $function='author';
6353: }
6354: return $function;
1.54 www 6355: }
1.99 www 6356:
6357: ###############################################
6358:
1.233 raeburn 6359: =pod
6360:
1.542 raeburn 6361: =item * &check_user_status()
1.274 raeburn 6362:
6363: Determines current status of supplied role for a
6364: specific user. Roles can be active, previous or future.
6365:
6366: Inputs:
6367: user's domain, user's username, course's domain,
1.375 raeburn 6368: course's number, optional section ID.
1.274 raeburn 6369:
6370: Outputs:
6371: role status: active, previous or future.
6372:
6373: =cut
6374:
6375: sub check_user_status {
1.412 raeburn 6376: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6377: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6378: my @uroles = keys %userinfo;
6379: my $srchstr;
6380: my $active_chk = 'none';
1.412 raeburn 6381: my $now = time;
1.274 raeburn 6382: if (@uroles > 0) {
1.412 raeburn 6383: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6384: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6385: } else {
1.412 raeburn 6386: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6387: }
6388: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6389: my $role_end = 0;
6390: my $role_start = 0;
6391: $active_chk = 'active';
1.412 raeburn 6392: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6393: $role_end = $1;
6394: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6395: $role_start = $1;
1.274 raeburn 6396: }
6397: }
6398: if ($role_start > 0) {
1.412 raeburn 6399: if ($now < $role_start) {
1.274 raeburn 6400: $active_chk = 'future';
6401: }
6402: }
6403: if ($role_end > 0) {
1.412 raeburn 6404: if ($now > $role_end) {
1.274 raeburn 6405: $active_chk = 'previous';
6406: }
6407: }
6408: }
6409: }
6410: return $active_chk;
6411: }
6412:
6413: ###############################################
6414:
6415: =pod
6416:
1.405 albertel 6417: =item * &get_sections()
1.233 raeburn 6418:
6419: Determines all the sections for a course including
6420: sections with students and sections containing other roles.
1.419 raeburn 6421: Incoming parameters:
6422:
6423: 1. domain
6424: 2. course number
6425: 3. reference to array containing roles for which sections should
6426: be gathered (optional).
6427: 4. reference to array containing status types for which sections
6428: should be gathered (optional).
6429:
6430: If the third argument is undefined, sections are gathered for any role.
6431: If the fourth argument is undefined, sections are gathered for any status.
6432: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6433:
1.374 raeburn 6434: Returns section hash (keys are section IDs, values are
6435: number of users in each section), subject to the
1.419 raeburn 6436: optional roles filter, optional status filter
1.233 raeburn 6437:
6438: =cut
6439:
6440: ###############################################
6441: sub get_sections {
1.419 raeburn 6442: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6443: if (!defined($cdom) || !defined($cnum)) {
6444: my $cid = $env{'request.course.id'};
6445:
6446: return if (!defined($cid));
6447:
6448: $cdom = $env{'course.'.$cid.'.domain'};
6449: $cnum = $env{'course.'.$cid.'.num'};
6450: }
6451:
6452: my %sectioncount;
1.419 raeburn 6453: my $now = time;
1.240 albertel 6454:
1.366 albertel 6455: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6456: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6457: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6458: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6459: my $start_index = &Apache::loncoursedata::CL_START();
6460: my $end_index = &Apache::loncoursedata::CL_END();
6461: my $status;
1.366 albertel 6462: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6463: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6464: $data->[$status_index],
6465: $data->[$start_index],
6466: $data->[$end_index]);
6467: if ($stu_status eq 'Active') {
6468: $status = 'active';
6469: } elsif ($end < $now) {
6470: $status = 'previous';
6471: } elsif ($start > $now) {
6472: $status = 'future';
6473: }
6474: if ($section ne '-1' && $section !~ /^\s*$/) {
6475: if ((!defined($possible_status)) || (($status ne '') &&
6476: (grep/^\Q$status\E$/,@{$possible_status}))) {
6477: $sectioncount{$section}++;
6478: }
1.240 albertel 6479: }
6480: }
6481: }
6482: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6483: foreach my $user (sort(keys(%courseroles))) {
6484: if ($user !~ /^(\w{2})/) { next; }
6485: my ($role) = ($user =~ /^(\w{2})/);
6486: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6487: my ($section,$status);
1.240 albertel 6488: if ($role eq 'cr' &&
6489: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6490: $section=$1;
6491: }
6492: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6493: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6494: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6495: if ($end == -1 && $start == -1) {
6496: next; #deleted role
6497: }
6498: if (!defined($possible_status)) {
6499: $sectioncount{$section}++;
6500: } else {
6501: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6502: $status = 'active';
6503: } elsif ($end < $now) {
6504: $status = 'future';
6505: } elsif ($start > $now) {
6506: $status = 'previous';
6507: }
6508: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6509: $sectioncount{$section}++;
6510: }
6511: }
1.233 raeburn 6512: }
1.366 albertel 6513: return %sectioncount;
1.233 raeburn 6514: }
6515:
1.274 raeburn 6516: ###############################################
1.294 raeburn 6517:
6518: =pod
1.405 albertel 6519:
6520: =item * &get_course_users()
6521:
1.275 raeburn 6522: Retrieves usernames:domains for users in the specified course
6523: with specific role(s), and access status.
6524:
6525: Incoming parameters:
1.277 albertel 6526: 1. course domain
6527: 2. course number
6528: 3. access status: users must have - either active,
1.275 raeburn 6529: previous, future, or all.
1.277 albertel 6530: 4. reference to array of permissible roles
1.288 raeburn 6531: 5. reference to array of section restrictions (optional)
6532: 6. reference to results object (hash of hashes).
6533: 7. reference to optional userdata hash
1.609 raeburn 6534: 8. reference to optional statushash
1.630 raeburn 6535: 9. flag if privileged users (except those set to unhide in
6536: course settings) should be excluded
1.609 raeburn 6537: Keys of top level results hash are roles.
1.275 raeburn 6538: Keys of inner hashes are username:domain, with
6539: values set to access type.
1.288 raeburn 6540: Optional userdata hash returns an array with arguments in the
6541: same order as loncoursedata::get_classlist() for student data.
6542:
1.609 raeburn 6543: Optional statushash returns
6544:
1.288 raeburn 6545: Entries for end, start, section and status are blank because
6546: of the possibility of multiple values for non-student roles.
6547:
1.275 raeburn 6548: =cut
1.405 albertel 6549:
1.275 raeburn 6550: ###############################################
1.405 albertel 6551:
1.275 raeburn 6552: sub get_course_users {
1.630 raeburn 6553: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6554: my %idx = ();
1.419 raeburn 6555: my %seclists;
1.288 raeburn 6556:
6557: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6558: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6559: $idx{end} = &Apache::loncoursedata::CL_END();
6560: $idx{start} = &Apache::loncoursedata::CL_START();
6561: $idx{id} = &Apache::loncoursedata::CL_ID();
6562: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6563: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6564: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6565:
1.290 albertel 6566: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6567: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6568: my $now = time;
1.277 albertel 6569: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6570: my $match = 0;
1.412 raeburn 6571: my $secmatch = 0;
1.419 raeburn 6572: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6573: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6574: if ($section eq '') {
6575: $section = 'none';
6576: }
1.291 albertel 6577: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6578: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6579: $secmatch = 1;
6580: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6581: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6582: $secmatch = 1;
6583: }
6584: } else {
1.419 raeburn 6585: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6586: $secmatch = 1;
6587: }
1.290 albertel 6588: }
1.412 raeburn 6589: if (!$secmatch) {
6590: next;
6591: }
1.419 raeburn 6592: }
1.275 raeburn 6593: if (defined($$types{'active'})) {
1.288 raeburn 6594: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6595: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6596: $match = 1;
1.275 raeburn 6597: }
6598: }
6599: if (defined($$types{'previous'})) {
1.609 raeburn 6600: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6601: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6602: $match = 1;
1.275 raeburn 6603: }
6604: }
6605: if (defined($$types{'future'})) {
1.609 raeburn 6606: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6607: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6608: $match = 1;
1.275 raeburn 6609: }
6610: }
1.609 raeburn 6611: if ($match) {
6612: push(@{$seclists{$student}},$section);
6613: if (ref($userdata) eq 'HASH') {
6614: $$userdata{$student} = $$classlist{$student};
6615: }
6616: if (ref($statushash) eq 'HASH') {
6617: $statushash->{$student}{'st'}{$section} = $status;
6618: }
1.288 raeburn 6619: }
1.275 raeburn 6620: }
6621: }
1.412 raeburn 6622: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6623: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6624: my $now = time;
1.609 raeburn 6625: my %displaystatus = ( previous => 'Expired',
6626: active => 'Active',
6627: future => 'Future',
6628: );
1.630 raeburn 6629: my %nothide;
6630: if ($hidepriv) {
6631: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6632: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6633: if ($user !~ /:/) {
6634: $nothide{join(':',split(/[\@]/,$user))}=1;
6635: } else {
6636: $nothide{$user} = 1;
6637: }
6638: }
6639: }
1.439 raeburn 6640: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6641: my $match = 0;
1.412 raeburn 6642: my $secmatch = 0;
1.439 raeburn 6643: my $status;
1.412 raeburn 6644: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6645: $user =~ s/:$//;
1.439 raeburn 6646: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6647: if ($end == -1 || $start == -1) {
6648: next;
6649: }
6650: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6651: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6652: my ($uname,$udom) = split(/:/,$user);
6653: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6654: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6655: $secmatch = 1;
6656: } elsif ($usec eq '') {
1.420 albertel 6657: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6658: $secmatch = 1;
6659: }
6660: } else {
6661: if (grep(/^\Q$usec\E$/,@{$sections})) {
6662: $secmatch = 1;
6663: }
6664: }
6665: if (!$secmatch) {
6666: next;
6667: }
1.288 raeburn 6668: }
1.419 raeburn 6669: if ($usec eq '') {
6670: $usec = 'none';
6671: }
1.275 raeburn 6672: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6673: if ($hidepriv) {
6674: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6675: (!$nothide{$uname.':'.$udom})) {
6676: next;
6677: }
6678: }
1.503 raeburn 6679: if ($end > 0 && $end < $now) {
1.439 raeburn 6680: $status = 'previous';
6681: } elsif ($start > $now) {
6682: $status = 'future';
6683: } else {
6684: $status = 'active';
6685: }
1.277 albertel 6686: foreach my $type (keys(%{$types})) {
1.275 raeburn 6687: if ($status eq $type) {
1.420 albertel 6688: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6689: push(@{$$users{$role}{$user}},$type);
6690: }
1.288 raeburn 6691: $match = 1;
6692: }
6693: }
1.419 raeburn 6694: if (($match) && (ref($userdata) eq 'HASH')) {
6695: if (!exists($$userdata{$uname.':'.$udom})) {
6696: &get_user_info($udom,$uname,\%idx,$userdata);
6697: }
1.420 albertel 6698: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6699: push(@{$seclists{$uname.':'.$udom}},$usec);
6700: }
1.609 raeburn 6701: if (ref($statushash) eq 'HASH') {
6702: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6703: }
1.275 raeburn 6704: }
6705: }
6706: }
6707: }
1.290 albertel 6708: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6709: if ((defined($cdom)) && (defined($cnum))) {
6710: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6711: if ( defined($csettings{'internal.courseowner'}) ) {
6712: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6713: next if ($owner eq '');
6714: my ($ownername,$ownerdom);
6715: if ($owner =~ /^([^:]+):([^:]+)$/) {
6716: $ownername = $1;
6717: $ownerdom = $2;
6718: } else {
6719: $ownername = $owner;
6720: $ownerdom = $cdom;
6721: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6722: }
6723: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6724: if (defined($userdata) &&
1.609 raeburn 6725: !exists($$userdata{$owner})) {
6726: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6727: if (!grep(/^none$/,@{$seclists{$owner}})) {
6728: push(@{$seclists{$owner}},'none');
6729: }
6730: if (ref($statushash) eq 'HASH') {
6731: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6732: }
1.290 albertel 6733: }
1.279 raeburn 6734: }
6735: }
6736: }
1.419 raeburn 6737: foreach my $user (keys(%seclists)) {
6738: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6739: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6740: }
1.275 raeburn 6741: }
6742: return;
6743: }
6744:
1.288 raeburn 6745: sub get_user_info {
6746: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6747: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6748: &plainname($uname,$udom,'lastname');
1.291 albertel 6749: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6750: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6751: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6752: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6753: return;
6754: }
1.275 raeburn 6755:
1.472 raeburn 6756: ###############################################
6757:
6758: =pod
6759:
6760: =item * &get_user_quota()
6761:
6762: Retrieves quota assigned for storage of portfolio files for a user
6763:
6764: Incoming parameters:
6765: 1. user's username
6766: 2. user's domain
6767:
6768: Returns:
1.536 raeburn 6769: 1. Disk quota (in Mb) assigned to student.
6770: 2. (Optional) Type of setting: custom or default
6771: (individually assigned or default for user's
6772: institutional status).
6773: 3. (Optional) - User's institutional status (e.g., faculty, staff
6774: or student - types as defined in localenroll::inst_usertypes
6775: for user's domain, which determines default quota for user.
6776: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6777:
6778: If a value has been stored in the user's environment,
1.536 raeburn 6779: it will return that, otherwise it returns the maximal default
6780: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6781:
6782: =cut
6783:
6784: ###############################################
6785:
6786:
6787: sub get_user_quota {
6788: my ($uname,$udom) = @_;
1.536 raeburn 6789: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6790: if (!defined($udom)) {
6791: $udom = $env{'user.domain'};
6792: }
6793: if (!defined($uname)) {
6794: $uname = $env{'user.name'};
6795: }
6796: if (($udom eq '' || $uname eq '') ||
6797: ($udom eq 'public') && ($uname eq 'public')) {
6798: $quota = 0;
1.536 raeburn 6799: $quotatype = 'default';
6800: $defquota = 0;
1.472 raeburn 6801: } else {
1.536 raeburn 6802: my $inststatus;
1.472 raeburn 6803: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6804: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6805: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6806: } else {
1.536 raeburn 6807: my %userenv =
6808: &Apache::lonnet::get('environment',['portfolioquota',
6809: 'inststatus'],$udom,$uname);
1.472 raeburn 6810: my ($tmp) = keys(%userenv);
6811: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6812: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6813: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6814: } else {
6815: undef(%userenv);
6816: }
6817: }
1.536 raeburn 6818: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6819: if ($quota eq '') {
1.536 raeburn 6820: $quota = $defquota;
6821: $quotatype = 'default';
6822: } else {
6823: $quotatype = 'custom';
1.472 raeburn 6824: }
6825: }
1.536 raeburn 6826: if (wantarray) {
6827: return ($quota,$quotatype,$settingstatus,$defquota);
6828: } else {
6829: return $quota;
6830: }
1.472 raeburn 6831: }
6832:
6833: ###############################################
6834:
6835: =pod
6836:
6837: =item * &default_quota()
6838:
1.536 raeburn 6839: Retrieves default quota assigned for storage of user portfolio files,
6840: given an (optional) user's institutional status.
1.472 raeburn 6841:
6842: Incoming parameters:
6843: 1. domain
1.536 raeburn 6844: 2. (Optional) institutional status(es). This is a : separated list of
6845: status types (e.g., faculty, staff, student etc.)
6846: which apply to the user for whom the default is being retrieved.
6847: If the institutional status string in undefined, the domain
6848: default quota will be returned.
1.472 raeburn 6849:
6850: Returns:
6851: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6852: 2. (Optional) institutional type which determined the value of the
6853: default quota.
1.472 raeburn 6854:
6855: If a value has been stored in the domain's configuration db,
6856: it will return that, otherwise it returns 20 (for backwards
6857: compatibility with domains which have not set up a configuration
6858: db file; the original statically defined portfolio quota was 20 Mb).
6859:
1.536 raeburn 6860: If the user's status includes multiple types (e.g., staff and student),
6861: the largest default quota which applies to the user determines the
6862: default quota returned.
6863:
1.472 raeburn 6864: =cut
6865:
6866: ###############################################
6867:
6868:
6869: sub default_quota {
1.536 raeburn 6870: my ($udom,$inststatus) = @_;
6871: my ($defquota,$settingstatus);
6872: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6873: ['quotas'],$udom);
6874: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6875: if ($inststatus ne '') {
6876: my @statuses = split(/:/,$inststatus);
6877: foreach my $item (@statuses) {
1.622 raeburn 6878: if ($quotahash{'quotas'}{$item} ne '') {
1.536 raeburn 6879: if ($defquota eq '') {
1.622 raeburn 6880: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6881: $settingstatus = $item;
1.622 raeburn 6882: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6883: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6884: $settingstatus = $item;
6885: }
6886: }
6887: }
6888: }
6889: if ($defquota eq '') {
1.622 raeburn 6890: $defquota = $quotahash{'quotas'}{'default'};
1.536 raeburn 6891: $settingstatus = 'default';
6892: }
6893: } else {
6894: $settingstatus = 'default';
6895: $defquota = 20;
6896: }
6897: if (wantarray) {
6898: return ($defquota,$settingstatus);
1.472 raeburn 6899: } else {
1.536 raeburn 6900: return $defquota;
1.472 raeburn 6901: }
6902: }
6903:
1.384 raeburn 6904: sub get_secgrprole_info {
6905: my ($cdom,$cnum,$needroles,$type) = @_;
6906: my %sections_count = &get_sections($cdom,$cnum);
6907: my @sections = (sort {$a <=> $b} keys(%sections_count));
6908: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6909: my @groups = sort(keys(%curr_groups));
6910: my $allroles = [];
6911: my $rolehash;
6912: my $accesshash = {
6913: active => 'Currently has access',
6914: future => 'Will have future access',
6915: previous => 'Previously had access',
6916: };
6917: if ($needroles) {
6918: $rolehash = {'all' => 'all'};
1.385 albertel 6919: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6920: if (&Apache::lonnet::error(%user_roles)) {
6921: undef(%user_roles);
6922: }
6923: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6924: my ($role)=split(/\:/,$item,2);
6925: if ($role eq 'cr') { next; }
6926: if ($role =~ /^cr/) {
6927: $$rolehash{$role} = (split('/',$role))[3];
6928: } else {
6929: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6930: }
6931: }
6932: foreach my $key (sort(keys(%{$rolehash}))) {
6933: push(@{$allroles},$key);
6934: }
6935: push (@{$allroles},'st');
6936: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6937: }
6938: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6939: }
6940:
1.555 raeburn 6941: sub user_picker {
1.627 raeburn 6942: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6943: my $currdom = $dom;
6944: my %curr_selected = (
6945: srchin => 'dom',
1.580 raeburn 6946: srchby => 'lastname',
1.555 raeburn 6947: );
6948: my $srchterm;
1.625 raeburn 6949: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6950: if ($srch->{'srchby'} ne '') {
6951: $curr_selected{'srchby'} = $srch->{'srchby'};
6952: }
6953: if ($srch->{'srchin'} ne '') {
6954: $curr_selected{'srchin'} = $srch->{'srchin'};
6955: }
6956: if ($srch->{'srchtype'} ne '') {
6957: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6958: }
6959: if ($srch->{'srchdomain'} ne '') {
6960: $currdom = $srch->{'srchdomain'};
6961: }
6962: $srchterm = $srch->{'srchterm'};
6963: }
6964: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6965: 'usr' => 'Search criteria',
1.563 raeburn 6966: 'doma' => 'Domain/institution to search',
1.558 albertel 6967: 'uname' => 'username',
6968: 'lastname' => 'last name',
1.555 raeburn 6969: 'lastfirst' => 'last name, first name',
1.558 albertel 6970: 'crs' => 'in this course',
1.576 raeburn 6971: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6972: 'alc' => 'all LON-CAPA',
1.573 raeburn 6973: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6974: 'exact' => 'is',
6975: 'contains' => 'contains',
1.569 raeburn 6976: 'begins' => 'begins with',
1.571 raeburn 6977: 'youm' => "You must include some text to search for.",
6978: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6979: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6980: 'yomc' => "You must choose a domain when using an institutional directory search.",
6981: 'ymcd' => "You must choose a domain when using a domain search.",
6982: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6983: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6984: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6985: );
1.563 raeburn 6986: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6987: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6988:
6989: my @srchins = ('crs','dom','alc','instd');
6990:
6991: foreach my $option (@srchins) {
6992: # FIXME 'alc' option unavailable until
6993: # loncreateuser::print_user_query_page()
6994: # has been completed.
6995: next if ($option eq 'alc');
6996: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6997: if ($curr_selected{'srchin'} eq $option) {
6998: $srchinsel .= '
6999: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7000: } else {
7001: $srchinsel .= '
7002: <option value="'.$option.'">'.$lt{$option}.'</option>';
7003: }
1.555 raeburn 7004: }
1.563 raeburn 7005: $srchinsel .= "\n </select>\n";
1.555 raeburn 7006:
7007: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7008: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7009: if ($curr_selected{'srchby'} eq $option) {
7010: $srchbysel .= '
7011: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7012: } else {
7013: $srchbysel .= '
7014: <option value="'.$option.'">'.$lt{$option}.'</option>';
7015: }
7016: }
7017: $srchbysel .= "\n </select>\n";
7018:
7019: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7020: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7021: if ($curr_selected{'srchtype'} eq $option) {
7022: $srchtypesel .= '
7023: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7024: } else {
7025: $srchtypesel .= '
7026: <option value="'.$option.'">'.$lt{$option}.'</option>';
7027: }
7028: }
7029: $srchtypesel .= "\n </select>\n";
7030:
1.558 albertel 7031: my ($newuserscript,$new_user_create);
1.556 raeburn 7032:
7033: if ($forcenewuser) {
1.576 raeburn 7034: if (ref($srch) eq 'HASH') {
7035: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7036: if ($cancreate) {
7037: $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>';
7038: } else {
7039: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7040: my %usertypetext = (
7041: official => 'institutional',
7042: unofficial => 'non-institutional',
7043: );
7044: $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 />';
7045: }
1.576 raeburn 7046: }
7047: }
7048:
1.556 raeburn 7049: $newuserscript = <<"ENDSCRIPT";
7050:
1.570 raeburn 7051: function setSearch(createnew,callingForm) {
1.556 raeburn 7052: if (createnew == 1) {
1.570 raeburn 7053: for (var i=0; i<callingForm.srchby.length; i++) {
7054: if (callingForm.srchby.options[i].value == 'uname') {
7055: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7056: }
7057: }
1.570 raeburn 7058: for (var i=0; i<callingForm.srchin.length; i++) {
7059: if ( callingForm.srchin.options[i].value == 'dom') {
7060: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7061: }
7062: }
1.570 raeburn 7063: for (var i=0; i<callingForm.srchtype.length; i++) {
7064: if (callingForm.srchtype.options[i].value == 'exact') {
7065: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7066: }
7067: }
1.570 raeburn 7068: for (var i=0; i<callingForm.srchdomain.length; i++) {
7069: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7070: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7071: }
7072: }
7073: }
7074: }
7075: ENDSCRIPT
1.558 albertel 7076:
1.556 raeburn 7077: }
7078:
1.555 raeburn 7079: my $output = <<"END_BLOCK";
1.556 raeburn 7080: <script type="text/javascript">
1.570 raeburn 7081: function validateEntry(callingForm) {
1.558 albertel 7082:
1.556 raeburn 7083: var checkok = 1;
1.558 albertel 7084: var srchin;
1.570 raeburn 7085: for (var i=0; i<callingForm.srchin.length; i++) {
7086: if ( callingForm.srchin[i].checked ) {
7087: srchin = callingForm.srchin[i].value;
1.558 albertel 7088: }
7089: }
7090:
1.570 raeburn 7091: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7092: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7093: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7094: var srchterm = callingForm.srchterm.value;
7095: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7096: var msg = "";
7097:
7098: if (srchterm == "") {
7099: checkok = 0;
1.571 raeburn 7100: msg += "$lt{'youm'}\\n";
1.556 raeburn 7101: }
7102:
1.569 raeburn 7103: if (srchtype== 'begins') {
7104: if (srchterm.length < 2) {
7105: checkok = 0;
1.571 raeburn 7106: msg += "$lt{'thte'}\\n";
1.569 raeburn 7107: }
7108: }
7109:
1.556 raeburn 7110: if (srchtype== 'contains') {
7111: if (srchterm.length < 3) {
7112: checkok = 0;
1.571 raeburn 7113: msg += "$lt{'thet'}\\n";
1.556 raeburn 7114: }
7115: }
7116: if (srchin == 'instd') {
7117: if (srchdomain == '') {
7118: checkok = 0;
1.571 raeburn 7119: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7120: }
7121: }
7122: if (srchin == 'dom') {
7123: if (srchdomain == '') {
7124: checkok = 0;
1.571 raeburn 7125: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7126: }
7127: }
7128: if (srchby == 'lastfirst') {
7129: if (srchterm.indexOf(",") == -1) {
7130: checkok = 0;
1.571 raeburn 7131: msg += "$lt{'whus'}\\n";
1.556 raeburn 7132: }
7133: if (srchterm.indexOf(",") == srchterm.length -1) {
7134: checkok = 0;
1.571 raeburn 7135: msg += "$lt{'whse'}\\n";
1.556 raeburn 7136: }
7137: }
7138: if (checkok == 0) {
1.571 raeburn 7139: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7140: return;
7141: }
7142: if (checkok == 1) {
1.570 raeburn 7143: callingForm.submit();
1.556 raeburn 7144: }
7145: }
7146:
7147: $newuserscript
7148:
7149: </script>
1.558 albertel 7150:
7151: $new_user_create
7152:
1.555 raeburn 7153: <table>
1.558 albertel 7154: <tr>
1.573 raeburn 7155: <td>$lt{'doma'}:</td>
7156: <td>$domform</td>
7157: </td>
7158: </tr>
7159: <tr>
7160: <td>$lt{'usr'}:</td>
1.563 raeburn 7161: <td>$srchbysel
7162: $srchtypesel
7163: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7164: $srchinsel
1.563 raeburn 7165: </td>
7166: </tr>
1.555 raeburn 7167: </table>
7168: <br />
7169: END_BLOCK
1.558 albertel 7170:
1.555 raeburn 7171: return $output;
7172: }
7173:
1.612 raeburn 7174: sub user_rule_check {
1.615 raeburn 7175: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7176: my $response;
7177: if (ref($usershash) eq 'HASH') {
7178: foreach my $user (keys(%{$usershash})) {
7179: my ($uname,$udom) = split(/:/,$user);
7180: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7181: my ($id,$newuser);
1.612 raeburn 7182: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7183: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7184: $id = $usershash->{$user}->{'id'};
7185: }
7186: my $inst_response;
7187: if (ref($checks) eq 'HASH') {
7188: if (defined($checks->{'username'})) {
1.615 raeburn 7189: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7190: &Apache::lonnet::get_instuser($udom,$uname);
7191: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7192: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7193: &Apache::lonnet::get_instuser($udom,undef,$id);
7194: }
1.615 raeburn 7195: } else {
7196: ($inst_response,%{$inst_results->{$user}}) =
7197: &Apache::lonnet::get_instuser($udom,$uname);
7198: return;
1.612 raeburn 7199: }
1.615 raeburn 7200: if (!$got_rules->{$udom}) {
1.612 raeburn 7201: my %domconfig = &Apache::lonnet::get_dom('configuration',
7202: ['usercreation'],$udom);
7203: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7204: foreach my $item ('username','id') {
1.612 raeburn 7205: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7206: $$curr_rules{$udom}{$item} =
7207: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7208: }
7209: }
7210: }
1.615 raeburn 7211: $got_rules->{$udom} = 1;
1.585 raeburn 7212: }
1.612 raeburn 7213: foreach my $item (keys(%{$checks})) {
7214: if (ref($$curr_rules{$udom}) eq 'HASH') {
7215: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7216: if (@{$$curr_rules{$udom}{$item}} > 0) {
7217: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7218: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7219: if ($rule_check{$rule}) {
7220: $$rulematch{$user}{$item} = $rule;
7221: if ($inst_response eq 'ok') {
1.615 raeburn 7222: if (ref($inst_results) eq 'HASH') {
7223: if (ref($inst_results->{$user}) eq 'HASH') {
7224: if (keys(%{$inst_results->{$user}}) == 0) {
7225: $$alerts{$item}{$udom}{$uname} = 1;
7226: }
1.612 raeburn 7227: }
7228: }
1.615 raeburn 7229: }
7230: last;
1.585 raeburn 7231: }
7232: }
7233: }
7234: }
7235: }
7236: }
7237: }
7238: }
1.612 raeburn 7239: return;
7240: }
7241:
7242: sub user_rule_formats {
7243: my ($domain,$domdesc,$curr_rules,$check) = @_;
7244: my %text = (
7245: 'username' => 'Usernames',
7246: 'id' => 'IDs',
7247: );
7248: my $output;
7249: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7250: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7251: if (@{$ruleorder} > 0) {
7252: $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>';
7253: foreach my $rule (@{$ruleorder}) {
7254: if (ref($curr_rules) eq 'ARRAY') {
7255: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7256: if (ref($rules->{$rule}) eq 'HASH') {
7257: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7258: $rules->{$rule}{'desc'}.'</li>';
7259: }
7260: }
7261: }
7262: }
7263: $output .= '</ul>';
7264: }
7265: }
7266: return $output;
7267: }
7268:
7269: sub instrule_disallow_msg {
1.615 raeburn 7270: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7271: my $response;
7272: my %text = (
7273: item => 'username',
7274: items => 'usernames',
7275: match => 'matches',
7276: do => 'does',
7277: action => 'a username',
7278: one => 'one',
7279: );
7280: if ($count > 1) {
7281: $text{'item'} = 'usernames';
7282: $text{'match'} ='match';
7283: $text{'do'} = 'do';
7284: $text{'action'} = 'usernames',
7285: $text{'one'} = 'ones';
7286: }
7287: if ($checkitem eq 'id') {
7288: $text{'items'} = 'IDs';
7289: $text{'item'} = 'ID';
7290: $text{'action'} = 'an ID';
1.615 raeburn 7291: if ($count > 1) {
7292: $text{'item'} = 'IDs';
7293: $text{'action'} = 'IDs';
7294: }
1.612 raeburn 7295: }
1.674 bisitz 7296: $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 7297: if ($mode eq 'upload') {
7298: if ($checkitem eq 'username') {
7299: $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'}.");
7300: } elsif ($checkitem eq 'id') {
1.674 bisitz 7301: $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 7302: }
1.669 raeburn 7303: } elsif ($mode eq 'selfcreate') {
7304: if ($checkitem eq 'id') {
7305: $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.");
7306: }
1.615 raeburn 7307: } else {
7308: if ($checkitem eq 'username') {
7309: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7310: } elsif ($checkitem eq 'id') {
7311: $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.");
7312: }
1.612 raeburn 7313: }
7314: return $response;
1.585 raeburn 7315: }
7316:
1.624 raeburn 7317: sub personal_data_fieldtitles {
7318: my %fieldtitles = &Apache::lonlocal::texthash (
7319: id => 'Student/Employee ID',
7320: permanentemail => 'E-mail address',
7321: lastname => 'Last Name',
7322: firstname => 'First Name',
7323: middlename => 'Middle Name',
7324: generation => 'Generation',
7325: gen => 'Generation',
7326: );
7327: return %fieldtitles;
7328: }
7329:
1.642 raeburn 7330: sub sorted_inst_types {
7331: my ($dom) = @_;
7332: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7333: my $othertitle = &mt('All users');
7334: if ($env{'request.course.id'}) {
1.668 raeburn 7335: $othertitle = &mt('Any users');
1.642 raeburn 7336: }
7337: my @types;
7338: if (ref($order) eq 'ARRAY') {
7339: @types = @{$order};
7340: }
7341: if (@types == 0) {
7342: if (ref($usertypes) eq 'HASH') {
7343: @types = sort(keys(%{$usertypes}));
7344: }
7345: }
7346: if (keys(%{$usertypes}) > 0) {
7347: $othertitle = &mt('Other users');
7348: }
7349: return ($othertitle,$usertypes,\@types);
7350: }
7351:
1.645 raeburn 7352: sub get_institutional_codes {
7353: my ($settings,$allcourses,$LC_code) = @_;
7354: # Get complete list of course sections to update
7355: my @currsections = ();
7356: my @currxlists = ();
7357: my $coursecode = $$settings{'internal.coursecode'};
7358:
7359: if ($$settings{'internal.sectionnums'} ne '') {
7360: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7361: }
7362:
7363: if ($$settings{'internal.crosslistings'} ne '') {
7364: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7365: }
7366:
7367: if (@currxlists > 0) {
7368: foreach (@currxlists) {
7369: if (m/^([^:]+):(\w*)$/) {
7370: unless (grep/^$1$/,@{$allcourses}) {
7371: push @{$allcourses},$1;
7372: $$LC_code{$1} = $2;
7373: }
7374: }
7375: }
7376: }
7377:
7378: if (@currsections > 0) {
7379: foreach (@currsections) {
7380: if (m/^(\w+):(\w*)$/) {
7381: my $sec = $coursecode.$1;
7382: my $lc_sec = $2;
7383: unless (grep/^$sec$/,@{$allcourses}) {
7384: push @{$allcourses},$sec;
7385: $$LC_code{$sec} = $lc_sec;
7386: }
7387: }
7388: }
7389: }
7390: return;
7391: }
7392:
1.112 bowersj2 7393: =pod
7394:
1.549 albertel 7395: =back
7396:
7397: =head1 HTTP Helpers
7398:
7399: =over 4
7400:
1.648 raeburn 7401: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7402:
1.258 albertel 7403: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7404: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7405: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7406:
7407: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7408: $possible_names is an ref to an array of form element names. As an example:
7409: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7410: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7411:
7412: =cut
1.1 albertel 7413:
1.6 albertel 7414: sub get_unprocessed_cgi {
1.25 albertel 7415: my ($query,$possible_names)= @_;
1.26 matthew 7416: # $Apache::lonxml::debug=1;
1.356 albertel 7417: foreach my $pair (split(/&/,$query)) {
7418: my ($name, $value) = split(/=/,$pair);
1.369 www 7419: $name = &unescape($name);
1.25 albertel 7420: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7421: $value =~ tr/+/ /;
7422: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7423: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7424: }
1.16 harris41 7425: }
1.6 albertel 7426: }
7427:
1.112 bowersj2 7428: =pod
7429:
1.648 raeburn 7430: =item * &cacheheader()
1.112 bowersj2 7431:
7432: returns cache-controlling header code
7433:
7434: =cut
7435:
1.7 albertel 7436: sub cacheheader {
1.258 albertel 7437: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7438: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7439: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7440: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7441: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7442: return $output;
1.7 albertel 7443: }
7444:
1.112 bowersj2 7445: =pod
7446:
1.648 raeburn 7447: =item * &no_cache($r)
1.112 bowersj2 7448:
7449: specifies header code to not have cache
7450:
7451: =cut
7452:
1.9 albertel 7453: sub no_cache {
1.216 albertel 7454: my ($r) = @_;
7455: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7456: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7457: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7458: $r->no_cache(1);
7459: $r->header_out("Expires" => $date);
7460: $r->header_out("Pragma" => "no-cache");
1.123 www 7461: }
7462:
7463: sub content_type {
1.181 albertel 7464: my ($r,$type,$charset) = @_;
1.299 foxr 7465: if ($r) {
7466: # Note that printout.pl calls this with undef for $r.
7467: &no_cache($r);
7468: }
1.258 albertel 7469: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7470: unless ($charset) {
7471: $charset=&Apache::lonlocal::current_encoding;
7472: }
7473: if ($charset) { $type.='; charset='.$charset; }
7474: if ($r) {
7475: $r->content_type($type);
7476: } else {
7477: print("Content-type: $type\n\n");
7478: }
1.9 albertel 7479: }
1.25 albertel 7480:
1.112 bowersj2 7481: =pod
7482:
1.648 raeburn 7483: =item * &add_to_env($name,$value)
1.112 bowersj2 7484:
1.258 albertel 7485: adds $name to the %env hash with value
1.112 bowersj2 7486: $value, if $name already exists, the entry is converted to an array
7487: reference and $value is added to the array.
7488:
7489: =cut
7490:
1.25 albertel 7491: sub add_to_env {
7492: my ($name,$value)=@_;
1.258 albertel 7493: if (defined($env{$name})) {
7494: if (ref($env{$name})) {
1.25 albertel 7495: #already have multiple values
1.258 albertel 7496: push(@{ $env{$name} },$value);
1.25 albertel 7497: } else {
7498: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7499: my $first=$env{$name};
7500: undef($env{$name});
7501: push(@{ $env{$name} },$first,$value);
1.25 albertel 7502: }
7503: } else {
1.258 albertel 7504: $env{$name}=$value;
1.25 albertel 7505: }
1.31 albertel 7506: }
1.149 albertel 7507:
7508: =pod
7509:
1.648 raeburn 7510: =item * &get_env_multiple($name)
1.149 albertel 7511:
1.258 albertel 7512: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7513: values may be defined and end up as an array ref.
7514:
7515: returns an array of values
7516:
7517: =cut
7518:
7519: sub get_env_multiple {
7520: my ($name) = @_;
7521: my @values;
1.258 albertel 7522: if (defined($env{$name})) {
1.149 albertel 7523: # exists is it an array
1.258 albertel 7524: if (ref($env{$name})) {
7525: @values=@{ $env{$name} };
1.149 albertel 7526: } else {
1.258 albertel 7527: $values[0]=$env{$name};
1.149 albertel 7528: }
7529: }
7530: return(@values);
7531: }
7532:
1.660 raeburn 7533: sub ask_for_embedded_content {
7534: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7535: my $upload_output = '
7536: <form name="upload_embedded" action="'.$actionurl.'"
7537: method="post" enctype="multipart/form-data">';
7538: $upload_output .= $state;
1.661 raeburn 7539: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7540:
7541: my $num = 0;
7542: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7543: $upload_output .= &start_data_table_row().
7544: '<td>'.$embed_file.'</td><td>';
7545: if ($args->{'ignore_remote_references'}
7546: && $embed_file =~ m{^\w+://}) {
7547: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7548: } elsif ($args->{'error_on_invalid_names'}
7549: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7550:
7551: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7552:
7553: } else {
7554: $upload_output .='
1.661 raeburn 7555: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7556: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7557: my $attrib = join(':',@{$$allfiles{$embed_file}});
7558: $upload_output .=
7559: "\n\t\t".
7560: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7561: $attrib.'" />';
7562: if (exists($$codebase{$embed_file})) {
7563: $upload_output .=
7564: "\n\t\t".
7565: '<input name="codebase_'.$num.'" type="hidden" value="'.
7566: &escape($$codebase{$embed_file}).'" />';
7567: }
7568: }
7569: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7570: $num++;
7571: }
7572: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7573: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7574: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7575: '.&mt('(only files for which a location has been provided will be uploaded)').'
7576: </form>';
7577: return $upload_output;
7578: }
7579:
1.661 raeburn 7580: sub upload_embedded {
7581: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7582: $current_disk_usage) = @_;
7583: my $output;
7584: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7585: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7586: my $orig_uploaded_filename =
7587: $env{'form.embedded_item_'.$i.'.filename'};
7588:
7589: $env{'form.embedded_orig_'.$i} =
7590: &unescape($env{'form.embedded_orig_'.$i});
7591: my ($path,$fname) =
7592: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7593: # no path, whole string is fname
7594: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7595:
7596: $path = $env{'form.currentpath'}.$path;
7597: $fname = &Apache::lonnet::clean_filename($fname);
7598: # See if there is anything left
7599: next if ($fname eq '');
7600:
7601: # Check if file already exists as a file or directory.
7602: my ($state,$msg);
7603: if ($context eq 'portfolio') {
7604: my $port_path = $dirpath;
7605: if ($group ne '') {
7606: $port_path = "groups/$group/$port_path";
7607: }
7608: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7609: $dir_root,$port_path,$disk_quota,
7610: $current_disk_usage,$uname,$udom);
7611: if ($state eq 'will_exceed_quota'
7612: || $state eq 'file_locked'
7613: || $state eq 'file_exists' ) {
7614: $output .= $msg;
7615: next;
7616: }
7617: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7618: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7619: if ($state eq 'exists') {
7620: $output .= $msg;
7621: next;
7622: }
7623: }
7624: # Check if extension is valid
7625: if (($fname =~ /\.(\w+)$/) &&
7626: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7627: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7628: next;
7629: } elsif (($fname =~ /\.(\w+)$/) &&
7630: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7631: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7632: next;
7633: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7634: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7635: next;
7636: }
7637:
7638: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7639: if ($context eq 'portfolio') {
7640: my $result=
7641: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7642: $dirpath.$path);
7643: if ($result !~ m|^/uploaded/|) {
7644: $output .= '<span class="LC_error">'
7645: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7646: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7647: .'</span><br />';
7648: next;
7649: } else {
7650: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7651: $path.$fname.'</span>').'</p>';
7652: }
7653: } else {
7654: # Save the file
7655: my $target = $env{'form.embedded_item_'.$i};
7656: my $fullpath = $dir_root.$dirpath.'/'.$path;
7657: my $dest = $fullpath.$fname;
7658: my $url = $url_root.$dirpath.'/'.$path.$fname;
7659: my @parts=split(/\//,$fullpath);
7660: my $count;
7661: my $filepath = $dir_root;
7662: for ($count=4;$count<=$#parts;$count++) {
7663: $filepath .= "/$parts[$count]";
7664: if ((-e $filepath)!=1) {
7665: mkdir($filepath,0770);
7666: }
7667: }
7668: my $fh;
7669: if (!open($fh,'>'.$dest)) {
7670: &Apache::lonnet::logthis('Failed to create '.$dest);
7671: $output .= '<span class="LC_error">'.
7672: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7673: '</span><br />';
7674: } else {
7675: if (!print $fh $env{'form.embedded_item_'.$i}) {
7676: &Apache::lonnet::logthis('Failed to write to '.$dest);
7677: $output .= '<span class="LC_error">'.
7678: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7679: '</span><br />';
7680: } else {
7681: if ($context eq 'testbank') {
7682: $output .= &mt('Embedded file uploaded successfully:').
7683: ' <a href="'.$url.'">'.
7684: $orig_uploaded_filename.'</a><br />';
7685: } else {
7686: $output .= '<font size="+2">'.
7687: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7688: $orig_uploaded_filename.'</a>').'</font><br />';
7689: }
7690: }
7691: close($fh);
7692: }
7693: }
7694: }
7695: return $output;
7696: }
7697:
7698: sub check_for_existing {
7699: my ($path,$fname,$element) = @_;
7700: my ($state,$msg);
7701: if (-d $path.'/'.$fname) {
7702: $state = 'exists';
7703: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7704: } elsif (-e $path.'/'.$fname) {
7705: $state = 'exists';
7706: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7707: }
7708: if ($state eq 'exists') {
7709: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7710: }
7711: return ($state,$msg);
7712: }
7713:
7714: sub check_for_upload {
7715: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7716: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7717: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7718: my $getpropath = 1;
7719: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7720: $getpropath);
7721: my $found_file = 0;
7722: my $locked_file = 0;
7723: foreach my $line (@dir_list) {
7724: my ($file_name)=split(/\&/,$line,2);
7725: if ($file_name eq $fname){
7726: $file_name = $path.$file_name;
7727: if ($group ne '') {
7728: $file_name = $group.$file_name;
7729: }
7730: $found_file = 1;
7731: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7732: $locked_file = 1;
7733: }
7734: }
7735: }
7736: if (($current_disk_usage + $filesize) > $disk_quota){
7737: my $msg = '<span class="LC_error">'.
7738: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7739: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7740: return ('will_exceed_quota',$msg);
7741: } elsif ($found_file) {
7742: if ($locked_file) {
7743: my $msg = '<span class="LC_error">';
7744: $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>');
7745: $msg .= '</span><br />';
7746: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7747: return ('file_locked',$msg);
7748: } else {
7749: my $msg = '<span class="LC_error">';
7750: $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'});
7751: $msg .= '</span>';
7752: $msg .= '<br />';
7753: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7754: return ('file_exists',$msg);
7755: }
7756: }
7757: }
7758:
1.31 albertel 7759:
1.41 ng 7760: =pod
1.45 matthew 7761:
1.464 albertel 7762: =back
1.41 ng 7763:
1.112 bowersj2 7764: =head1 CSV Upload/Handling functions
1.38 albertel 7765:
1.41 ng 7766: =over 4
7767:
1.648 raeburn 7768: =item * &upfile_store($r)
1.41 ng 7769:
7770: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7771: needs $env{'form.upfile'}
1.41 ng 7772: returns $datatoken to be put into hidden field
7773:
7774: =cut
1.31 albertel 7775:
7776: sub upfile_store {
7777: my $r=shift;
1.258 albertel 7778: $env{'form.upfile'}=~s/\r/\n/gs;
7779: $env{'form.upfile'}=~s/\f/\n/gs;
7780: $env{'form.upfile'}=~s/\n+/\n/gs;
7781: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7782:
1.258 albertel 7783: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7784: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7785: {
1.158 raeburn 7786: my $datafile = $r->dir_config('lonDaemons').
7787: '/tmp/'.$datatoken.'.tmp';
7788: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7789: print $fh $env{'form.upfile'};
1.158 raeburn 7790: close($fh);
7791: }
1.31 albertel 7792: }
7793: return $datatoken;
7794: }
7795:
1.56 matthew 7796: =pod
7797:
1.648 raeburn 7798: =item * &load_tmp_file($r)
1.41 ng 7799:
7800: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7801: needs $env{'form.datatoken'},
7802: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7803:
7804: =cut
1.31 albertel 7805:
7806: sub load_tmp_file {
7807: my $r=shift;
7808: my @studentdata=();
7809: {
1.158 raeburn 7810: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7811: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7812: if ( open(my $fh,"<$studentfile") ) {
7813: @studentdata=<$fh>;
7814: close($fh);
7815: }
1.31 albertel 7816: }
1.258 albertel 7817: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7818: }
7819:
1.56 matthew 7820: =pod
7821:
1.648 raeburn 7822: =item * &upfile_record_sep()
1.41 ng 7823:
7824: Separate uploaded file into records
7825: returns array of records,
1.258 albertel 7826: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7827:
7828: =cut
1.31 albertel 7829:
7830: sub upfile_record_sep {
1.258 albertel 7831: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7832: } else {
1.248 albertel 7833: my @records;
1.258 albertel 7834: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7835: if ($line=~/^\s*$/) { next; }
7836: push(@records,$line);
7837: }
7838: return @records;
1.31 albertel 7839: }
7840: }
7841:
1.56 matthew 7842: =pod
7843:
1.648 raeburn 7844: =item * &record_sep($record)
1.41 ng 7845:
1.258 albertel 7846: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7847:
7848: =cut
7849:
1.263 www 7850: sub takeleft {
7851: my $index=shift;
7852: return substr('0000'.$index,-4,4);
7853: }
7854:
1.31 albertel 7855: sub record_sep {
7856: my $record=shift;
7857: my %components=();
1.258 albertel 7858: if ($env{'form.upfiletype'} eq 'xml') {
7859: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7860: my $i=0;
1.356 albertel 7861: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7862: $field=~s/^(\"|\')//;
7863: $field=~s/(\"|\')$//;
1.263 www 7864: $components{&takeleft($i)}=$field;
1.31 albertel 7865: $i++;
7866: }
1.258 albertel 7867: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7868: my $i=0;
1.356 albertel 7869: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7870: $field=~s/^(\"|\')//;
7871: $field=~s/(\"|\')$//;
1.263 www 7872: $components{&takeleft($i)}=$field;
1.31 albertel 7873: $i++;
7874: }
7875: } else {
1.561 www 7876: my $separator=',';
1.480 banghart 7877: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7878: $separator=';';
1.480 banghart 7879: }
1.31 albertel 7880: my $i=0;
1.561 www 7881: # the character we are looking for to indicate the end of a quote or a record
7882: my $looking_for=$separator;
7883: # do not add the characters to the fields
7884: my $ignore=0;
7885: # we just encountered a separator (or the beginning of the record)
7886: my $just_found_separator=1;
7887: # store the field we are working on here
7888: my $field='';
7889: # work our way through all characters in record
7890: foreach my $character ($record=~/(.)/g) {
7891: if ($character eq $looking_for) {
7892: if ($character ne $separator) {
7893: # Found the end of a quote, again looking for separator
7894: $looking_for=$separator;
7895: $ignore=1;
7896: } else {
7897: # Found a separator, store away what we got
7898: $components{&takeleft($i)}=$field;
7899: $i++;
7900: $just_found_separator=1;
7901: $ignore=0;
7902: $field='';
7903: }
7904: next;
7905: }
7906: # single or double quotation marks after a separator indicate beginning of a quote
7907: # we are now looking for the end of the quote and need to ignore separators
7908: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7909: $looking_for=$character;
7910: next;
7911: }
7912: # ignore would be true after we reached the end of a quote
7913: if ($ignore) { next; }
7914: if (($just_found_separator) && ($character=~/\s/)) { next; }
7915: $field.=$character;
7916: $just_found_separator=0;
1.31 albertel 7917: }
1.561 www 7918: # catch the very last entry, since we never encountered the separator
7919: $components{&takeleft($i)}=$field;
1.31 albertel 7920: }
7921: return %components;
7922: }
7923:
1.144 matthew 7924: ######################################################
7925: ######################################################
7926:
1.56 matthew 7927: =pod
7928:
1.648 raeburn 7929: =item * &upfile_select_html()
1.41 ng 7930:
1.144 matthew 7931: Return HTML code to select a file from the users machine and specify
7932: the file type.
1.41 ng 7933:
7934: =cut
7935:
1.144 matthew 7936: ######################################################
7937: ######################################################
1.31 albertel 7938: sub upfile_select_html {
1.144 matthew 7939: my %Types = (
7940: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7941: semisv => &mt('Semicolon separated values'),
1.144 matthew 7942: space => &mt('Space separated'),
7943: tab => &mt('Tabulator separated'),
7944: # xml => &mt('HTML/XML'),
7945: );
7946: my $Str = '<input type="file" name="upfile" size="50" />'.
7947: '<br />Type: <select name="upfiletype">';
7948: foreach my $type (sort(keys(%Types))) {
7949: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7950: }
7951: $Str .= "</select>\n";
7952: return $Str;
1.31 albertel 7953: }
7954:
1.301 albertel 7955: sub get_samples {
7956: my ($records,$toget) = @_;
7957: my @samples=({});
7958: my $got=0;
7959: foreach my $rec (@$records) {
7960: my %temp = &record_sep($rec);
7961: if (! grep(/\S/, values(%temp))) { next; }
7962: if (%temp) {
7963: $samples[$got]=\%temp;
7964: $got++;
7965: if ($got == $toget) { last; }
7966: }
7967: }
7968: return \@samples;
7969: }
7970:
1.144 matthew 7971: ######################################################
7972: ######################################################
7973:
1.56 matthew 7974: =pod
7975:
1.648 raeburn 7976: =item * &csv_print_samples($r,$records)
1.41 ng 7977:
7978: Prints a table of sample values from each column uploaded $r is an
7979: Apache Request ref, $records is an arrayref from
7980: &Apache::loncommon::upfile_record_sep
7981:
7982: =cut
7983:
1.144 matthew 7984: ######################################################
7985: ######################################################
1.31 albertel 7986: sub csv_print_samples {
7987: my ($r,$records) = @_;
1.662 bisitz 7988: my $samples = &get_samples($records,5);
1.301 albertel 7989:
1.594 raeburn 7990: $r->print(&mt('Samples').'<br />'.&start_data_table().
7991: &start_data_table_header_row());
1.356 albertel 7992: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7993: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 7994: $r->print(&end_data_table_header_row());
1.301 albertel 7995: foreach my $hash (@$samples) {
1.594 raeburn 7996: $r->print(&start_data_table_row());
1.356 albertel 7997: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7998: $r->print('<td>');
1.356 albertel 7999: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8000: $r->print('</td>');
8001: }
1.594 raeburn 8002: $r->print(&end_data_table_row());
1.31 albertel 8003: }
1.594 raeburn 8004: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8005: }
8006:
1.144 matthew 8007: ######################################################
8008: ######################################################
8009:
1.56 matthew 8010: =pod
8011:
1.648 raeburn 8012: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8013:
8014: Prints a table to create associations between values and table columns.
1.144 matthew 8015:
1.41 ng 8016: $r is an Apache Request ref,
8017: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8018: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8019:
8020: =cut
8021:
1.144 matthew 8022: ######################################################
8023: ######################################################
1.31 albertel 8024: sub csv_print_select_table {
8025: my ($r,$records,$d) = @_;
1.301 albertel 8026: my $i=0;
8027: my $samples = &get_samples($records,1);
1.144 matthew 8028: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8029: &start_data_table().&start_data_table_header_row().
1.144 matthew 8030: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8031: '<th>'.&mt('Column').'</th>'.
8032: &end_data_table_header_row()."\n");
1.356 albertel 8033: foreach my $array_ref (@$d) {
8034: my ($value,$display,$defaultcol)=@{ $array_ref };
1.689 bisitz 8035: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8036:
8037: $r->print('<td><select name=f'.$i.
1.32 matthew 8038: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8039: $r->print('<option value="none"></option>');
1.356 albertel 8040: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8041: $r->print('<option value="'.$sample.'"'.
8042: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8043: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8044: }
1.594 raeburn 8045: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8046: $i++;
8047: }
1.594 raeburn 8048: $r->print(&end_data_table());
1.31 albertel 8049: $i--;
8050: return $i;
8051: }
1.56 matthew 8052:
1.144 matthew 8053: ######################################################
8054: ######################################################
8055:
1.56 matthew 8056: =pod
1.31 albertel 8057:
1.648 raeburn 8058: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8059:
8060: Prints a table of sample values from the upload and can make associate samples to internal names.
8061:
8062: $r is an Apache Request ref,
8063: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8064: $d is an array of 2 element arrays (internal name, displayed name)
8065:
8066: =cut
8067:
1.144 matthew 8068: ######################################################
8069: ######################################################
1.31 albertel 8070: sub csv_samples_select_table {
8071: my ($r,$records,$d) = @_;
8072: my $i=0;
1.144 matthew 8073: #
1.662 bisitz 8074: my $max_samples = 5;
8075: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8076: $r->print(&start_data_table().
8077: &start_data_table_header_row().'<th>'.
8078: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8079: &end_data_table_header_row());
1.301 albertel 8080:
8081: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8082: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8083: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8084: foreach my $option (@$d) {
8085: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8086: $r->print('<option value="'.$value.'"'.
1.253 albertel 8087: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8088: $display.'</option>');
1.31 albertel 8089: }
8090: $r->print('</select></td><td>');
1.662 bisitz 8091: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8092: if (defined($samples->[$line]{$key})) {
8093: $r->print($samples->[$line]{$key}."<br />\n");
8094: }
8095: }
1.594 raeburn 8096: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8097: $i++;
8098: }
1.594 raeburn 8099: $r->print(&end_data_table());
1.31 albertel 8100: $i--;
8101: return($i);
1.115 matthew 8102: }
8103:
1.144 matthew 8104: ######################################################
8105: ######################################################
8106:
1.115 matthew 8107: =pod
8108:
1.648 raeburn 8109: =item * &clean_excel_name($name)
1.115 matthew 8110:
8111: Returns a replacement for $name which does not contain any illegal characters.
8112:
8113: =cut
8114:
1.144 matthew 8115: ######################################################
8116: ######################################################
1.115 matthew 8117: sub clean_excel_name {
8118: my ($name) = @_;
8119: $name =~ s/[:\*\?\/\\]//g;
8120: if (length($name) > 31) {
8121: $name = substr($name,0,31);
8122: }
8123: return $name;
1.25 albertel 8124: }
1.84 albertel 8125:
1.85 albertel 8126: =pod
8127:
1.648 raeburn 8128: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8129:
8130: Returns either 1 or undef
8131:
8132: 1 if the part is to be hidden, undef if it is to be shown
8133:
8134: Arguments are:
8135:
8136: $id the id of the part to be checked
8137: $symb, optional the symb of the resource to check
8138: $udom, optional the domain of the user to check for
8139: $uname, optional the username of the user to check for
8140:
8141: =cut
1.84 albertel 8142:
8143: sub check_if_partid_hidden {
8144: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8145: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8146: $symb,$udom,$uname);
1.141 albertel 8147: my $truth=1;
8148: #if the string starts with !, then the list is the list to show not hide
8149: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8150: my @hiddenlist=split(/,/,$hiddenparts);
8151: foreach my $checkid (@hiddenlist) {
1.141 albertel 8152: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8153: }
1.141 albertel 8154: return !$truth;
1.84 albertel 8155: }
1.127 matthew 8156:
1.138 matthew 8157:
8158: ############################################################
8159: ############################################################
8160:
8161: =pod
8162:
1.157 matthew 8163: =back
8164:
1.138 matthew 8165: =head1 cgi-bin script and graphing routines
8166:
1.157 matthew 8167: =over 4
8168:
1.648 raeburn 8169: =item * &get_cgi_id()
1.138 matthew 8170:
8171: Inputs: none
8172:
8173: Returns an id which can be used to pass environment variables
8174: to various cgi-bin scripts. These environment variables will
8175: be removed from the users environment after a given time by
8176: the routine &Apache::lonnet::transfer_profile_to_env.
8177:
8178: =cut
8179:
8180: ############################################################
8181: ############################################################
1.152 albertel 8182: my $uniq=0;
1.136 matthew 8183: sub get_cgi_id {
1.154 albertel 8184: $uniq=($uniq+1)%100000;
1.280 albertel 8185: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8186: }
8187:
1.127 matthew 8188: ############################################################
8189: ############################################################
8190:
8191: =pod
8192:
1.648 raeburn 8193: =item * &DrawBarGraph()
1.127 matthew 8194:
1.138 matthew 8195: Facilitates the plotting of data in a (stacked) bar graph.
8196: Puts plot definition data into the users environment in order for
8197: graph.png to plot it. Returns an <img> tag for the plot.
8198: The bars on the plot are labeled '1','2',...,'n'.
8199:
8200: Inputs:
8201:
8202: =over 4
8203:
8204: =item $Title: string, the title of the plot
8205:
8206: =item $xlabel: string, text describing the X-axis of the plot
8207:
8208: =item $ylabel: string, text describing the Y-axis of the plot
8209:
8210: =item $Max: scalar, the maximum Y value to use in the plot
8211: If $Max is < any data point, the graph will not be rendered.
8212:
1.140 matthew 8213: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8214: they are plotted. If undefined, default values will be used.
8215:
1.178 matthew 8216: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8217:
1.138 matthew 8218: =item @Values: An array of array references. Each array reference holds data
8219: to be plotted in a stacked bar chart.
8220:
1.239 matthew 8221: =item If the final element of @Values is a hash reference the key/value
8222: pairs will be added to the graph definition.
8223:
1.138 matthew 8224: =back
8225:
8226: Returns:
8227:
8228: An <img> tag which references graph.png and the appropriate identifying
8229: information for the plot.
8230:
1.127 matthew 8231: =cut
8232:
8233: ############################################################
8234: ############################################################
1.134 matthew 8235: sub DrawBarGraph {
1.178 matthew 8236: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8237: #
8238: if (! defined($colors)) {
8239: $colors = ['#33ff00',
8240: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8241: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8242: ];
8243: }
1.228 matthew 8244: my $extra_settings = {};
8245: if (ref($Values[-1]) eq 'HASH') {
8246: $extra_settings = pop(@Values);
8247: }
1.127 matthew 8248: #
1.136 matthew 8249: my $identifier = &get_cgi_id();
8250: my $id = 'cgi.'.$identifier;
1.129 matthew 8251: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8252: return '';
8253: }
1.225 matthew 8254: #
8255: my @Labels;
8256: if (defined($labels)) {
8257: @Labels = @$labels;
8258: } else {
8259: for (my $i=0;$i<@{$Values[0]};$i++) {
8260: push (@Labels,$i+1);
8261: }
8262: }
8263: #
1.129 matthew 8264: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8265: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8266: my %ValuesHash;
8267: my $NumSets=1;
8268: foreach my $array (@Values) {
8269: next if (! ref($array));
1.136 matthew 8270: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8271: join(',',@$array);
1.129 matthew 8272: }
1.127 matthew 8273: #
1.136 matthew 8274: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8275: if ($NumBars < 3) {
8276: $width = 120+$NumBars*32;
1.220 matthew 8277: $xskip = 1;
1.225 matthew 8278: $bar_width = 30;
8279: } elsif ($NumBars < 5) {
8280: $width = 120+$NumBars*20;
8281: $xskip = 1;
8282: $bar_width = 20;
1.220 matthew 8283: } elsif ($NumBars < 10) {
1.136 matthew 8284: $width = 120+$NumBars*15;
8285: $xskip = 1;
8286: $bar_width = 15;
8287: } elsif ($NumBars <= 25) {
8288: $width = 120+$NumBars*11;
8289: $xskip = 5;
8290: $bar_width = 8;
8291: } elsif ($NumBars <= 50) {
8292: $width = 120+$NumBars*8;
8293: $xskip = 5;
8294: $bar_width = 4;
8295: } else {
8296: $width = 120+$NumBars*8;
8297: $xskip = 5;
8298: $bar_width = 4;
8299: }
8300: #
1.137 matthew 8301: $Max = 1 if ($Max < 1);
8302: if ( int($Max) < $Max ) {
8303: $Max++;
8304: $Max = int($Max);
8305: }
1.127 matthew 8306: $Title = '' if (! defined($Title));
8307: $xlabel = '' if (! defined($xlabel));
8308: $ylabel = '' if (! defined($ylabel));
1.369 www 8309: $ValuesHash{$id.'.title'} = &escape($Title);
8310: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8311: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8312: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8313: $ValuesHash{$id.'.NumBars'} = $NumBars;
8314: $ValuesHash{$id.'.NumSets'} = $NumSets;
8315: $ValuesHash{$id.'.PlotType'} = 'bar';
8316: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8317: $ValuesHash{$id.'.height'} = $height;
8318: $ValuesHash{$id.'.width'} = $width;
8319: $ValuesHash{$id.'.xskip'} = $xskip;
8320: $ValuesHash{$id.'.bar_width'} = $bar_width;
8321: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8322: #
1.228 matthew 8323: # Deal with other parameters
8324: while (my ($key,$value) = each(%$extra_settings)) {
8325: $ValuesHash{$id.'.'.$key} = $value;
8326: }
8327: #
1.646 raeburn 8328: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8329: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8330: }
8331:
8332: ############################################################
8333: ############################################################
8334:
8335: =pod
8336:
1.648 raeburn 8337: =item * &DrawXYGraph()
1.137 matthew 8338:
1.138 matthew 8339: Facilitates the plotting of data in an XY graph.
8340: Puts plot definition data into the users environment in order for
8341: graph.png to plot it. Returns an <img> tag for the plot.
8342:
8343: Inputs:
8344:
8345: =over 4
8346:
8347: =item $Title: string, the title of the plot
8348:
8349: =item $xlabel: string, text describing the X-axis of the plot
8350:
8351: =item $ylabel: string, text describing the Y-axis of the plot
8352:
8353: =item $Max: scalar, the maximum Y value to use in the plot
8354: If $Max is < any data point, the graph will not be rendered.
8355:
8356: =item $colors: Array ref containing the hex color codes for the data to be
8357: plotted in. If undefined, default values will be used.
8358:
8359: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8360:
8361: =item $Ydata: Array ref containing Array refs.
1.185 www 8362: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8363:
8364: =item %Values: hash indicating or overriding any default values which are
8365: passed to graph.png.
8366: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8367:
8368: =back
8369:
8370: Returns:
8371:
8372: An <img> tag which references graph.png and the appropriate identifying
8373: information for the plot.
8374:
1.137 matthew 8375: =cut
8376:
8377: ############################################################
8378: ############################################################
8379: sub DrawXYGraph {
8380: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8381: #
8382: # Create the identifier for the graph
8383: my $identifier = &get_cgi_id();
8384: my $id = 'cgi.'.$identifier;
8385: #
8386: $Title = '' if (! defined($Title));
8387: $xlabel = '' if (! defined($xlabel));
8388: $ylabel = '' if (! defined($ylabel));
8389: my %ValuesHash =
8390: (
1.369 www 8391: $id.'.title' => &escape($Title),
8392: $id.'.xlabel' => &escape($xlabel),
8393: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8394: $id.'.y_max_value'=> $Max,
8395: $id.'.labels' => join(',',@$Xlabels),
8396: $id.'.PlotType' => 'XY',
8397: );
8398: #
8399: if (defined($colors) && ref($colors) eq 'ARRAY') {
8400: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8401: }
8402: #
8403: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8404: return '';
8405: }
8406: my $NumSets=1;
1.138 matthew 8407: foreach my $array (@{$Ydata}){
1.137 matthew 8408: next if (! ref($array));
8409: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8410: }
1.138 matthew 8411: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8412: #
8413: # Deal with other parameters
8414: while (my ($key,$value) = each(%Values)) {
8415: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8416: }
8417: #
1.646 raeburn 8418: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8419: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8420: }
8421:
8422: ############################################################
8423: ############################################################
8424:
8425: =pod
8426:
1.648 raeburn 8427: =item * &DrawXYYGraph()
1.138 matthew 8428:
8429: Facilitates the plotting of data in an XY graph with two Y axes.
8430: Puts plot definition data into the users environment in order for
8431: graph.png to plot it. Returns an <img> tag for the plot.
8432:
8433: Inputs:
8434:
8435: =over 4
8436:
8437: =item $Title: string, the title of the plot
8438:
8439: =item $xlabel: string, text describing the X-axis of the plot
8440:
8441: =item $ylabel: string, text describing the Y-axis of the plot
8442:
8443: =item $colors: Array ref containing the hex color codes for the data to be
8444: plotted in. If undefined, default values will be used.
8445:
8446: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8447:
8448: =item $Ydata1: The first data set
8449:
8450: =item $Min1: The minimum value of the left Y-axis
8451:
8452: =item $Max1: The maximum value of the left Y-axis
8453:
8454: =item $Ydata2: The second data set
8455:
8456: =item $Min2: The minimum value of the right Y-axis
8457:
8458: =item $Max2: The maximum value of the left Y-axis
8459:
8460: =item %Values: hash indicating or overriding any default values which are
8461: passed to graph.png.
8462: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8463:
8464: =back
8465:
8466: Returns:
8467:
8468: An <img> tag which references graph.png and the appropriate identifying
8469: information for the plot.
1.136 matthew 8470:
8471: =cut
8472:
8473: ############################################################
8474: ############################################################
1.137 matthew 8475: sub DrawXYYGraph {
8476: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8477: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8478: #
8479: # Create the identifier for the graph
8480: my $identifier = &get_cgi_id();
8481: my $id = 'cgi.'.$identifier;
8482: #
8483: $Title = '' if (! defined($Title));
8484: $xlabel = '' if (! defined($xlabel));
8485: $ylabel = '' if (! defined($ylabel));
8486: my %ValuesHash =
8487: (
1.369 www 8488: $id.'.title' => &escape($Title),
8489: $id.'.xlabel' => &escape($xlabel),
8490: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8491: $id.'.labels' => join(',',@$Xlabels),
8492: $id.'.PlotType' => 'XY',
8493: $id.'.NumSets' => 2,
1.137 matthew 8494: $id.'.two_axes' => 1,
8495: $id.'.y1_max_value' => $Max1,
8496: $id.'.y1_min_value' => $Min1,
8497: $id.'.y2_max_value' => $Max2,
8498: $id.'.y2_min_value' => $Min2,
1.136 matthew 8499: );
8500: #
1.137 matthew 8501: if (defined($colors) && ref($colors) eq 'ARRAY') {
8502: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8503: }
8504: #
8505: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8506: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8507: return '';
8508: }
8509: my $NumSets=1;
1.137 matthew 8510: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8511: next if (! ref($array));
8512: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8513: }
8514: #
8515: # Deal with other parameters
8516: while (my ($key,$value) = each(%Values)) {
8517: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8518: }
8519: #
1.646 raeburn 8520: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8521: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8522: }
8523:
8524: ############################################################
8525: ############################################################
8526:
8527: =pod
8528:
1.157 matthew 8529: =back
8530:
1.139 matthew 8531: =head1 Statistics helper routines?
8532:
8533: Bad place for them but what the hell.
8534:
1.157 matthew 8535: =over 4
8536:
1.648 raeburn 8537: =item * &chartlink()
1.139 matthew 8538:
8539: Returns a link to the chart for a specific student.
8540:
8541: Inputs:
8542:
8543: =over 4
8544:
8545: =item $linktext: The text of the link
8546:
8547: =item $sname: The students username
8548:
8549: =item $sdomain: The students domain
8550:
8551: =back
8552:
1.157 matthew 8553: =back
8554:
1.139 matthew 8555: =cut
8556:
8557: ############################################################
8558: ############################################################
8559: sub chartlink {
8560: my ($linktext, $sname, $sdomain) = @_;
8561: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8562: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8563: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8564: '">'.$linktext.'</a>';
1.153 matthew 8565: }
8566:
8567: #######################################################
8568: #######################################################
8569:
8570: =pod
8571:
8572: =head1 Course Environment Routines
1.157 matthew 8573:
8574: =over 4
1.153 matthew 8575:
1.648 raeburn 8576: =item * &restore_course_settings()
1.153 matthew 8577:
1.648 raeburn 8578: =item * &store_course_settings()
1.153 matthew 8579:
8580: Restores/Store indicated form parameters from the course environment.
8581: Will not overwrite existing values of the form parameters.
8582:
8583: Inputs:
8584: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8585:
8586: a hash ref describing the data to be stored. For example:
8587:
8588: %Save_Parameters = ('Status' => 'scalar',
8589: 'chartoutputmode' => 'scalar',
8590: 'chartoutputdata' => 'scalar',
8591: 'Section' => 'array',
1.373 raeburn 8592: 'Group' => 'array',
1.153 matthew 8593: 'StudentData' => 'array',
8594: 'Maps' => 'array');
8595:
8596: Returns: both routines return nothing
8597:
1.631 raeburn 8598: =back
8599:
1.153 matthew 8600: =cut
8601:
8602: #######################################################
8603: #######################################################
8604: sub store_course_settings {
1.496 albertel 8605: return &store_settings($env{'request.course.id'},@_);
8606: }
8607:
8608: sub store_settings {
1.153 matthew 8609: # save to the environment
8610: # appenv the same items, just to be safe
1.300 albertel 8611: my $udom = $env{'user.domain'};
8612: my $uname = $env{'user.name'};
1.496 albertel 8613: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8614: my %SaveHash;
8615: my %AppHash;
8616: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8617: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8618: my $envname = 'environment.'.$basename;
1.258 albertel 8619: if (exists($env{'form.'.$setting})) {
1.153 matthew 8620: # Save this value away
8621: if ($type eq 'scalar' &&
1.258 albertel 8622: (! exists($env{$envname}) ||
8623: $env{$envname} ne $env{'form.'.$setting})) {
8624: $SaveHash{$basename} = $env{'form.'.$setting};
8625: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8626: } elsif ($type eq 'array') {
8627: my $stored_form;
1.258 albertel 8628: if (ref($env{'form.'.$setting})) {
1.153 matthew 8629: $stored_form = join(',',
8630: map {
1.369 www 8631: &escape($_);
1.258 albertel 8632: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8633: } else {
8634: $stored_form =
1.369 www 8635: &escape($env{'form.'.$setting});
1.153 matthew 8636: }
8637: # Determine if the array contents are the same.
1.258 albertel 8638: if ($stored_form ne $env{$envname}) {
1.153 matthew 8639: $SaveHash{$basename} = $stored_form;
8640: $AppHash{$envname} = $stored_form;
8641: }
8642: }
8643: }
8644: }
8645: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8646: $udom,$uname);
1.153 matthew 8647: if ($put_result !~ /^(ok|delayed)/) {
8648: &Apache::lonnet::logthis('unable to save form parameters, '.
8649: 'got error:'.$put_result);
8650: }
8651: # Make sure these settings stick around in this session, too
1.646 raeburn 8652: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8653: return;
8654: }
8655:
8656: sub restore_course_settings {
1.499 albertel 8657: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8658: }
8659:
8660: sub restore_settings {
8661: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8662: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8663: next if (exists($env{'form.'.$setting}));
1.496 albertel 8664: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8665: '.'.$setting;
1.258 albertel 8666: if (exists($env{$envname})) {
1.153 matthew 8667: if ($type eq 'scalar') {
1.258 albertel 8668: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8669: } elsif ($type eq 'array') {
1.258 albertel 8670: $env{'form.'.$setting} = [
1.153 matthew 8671: map {
1.369 www 8672: &unescape($_);
1.258 albertel 8673: } split(',',$env{$envname})
1.153 matthew 8674: ];
8675: }
8676: }
8677: }
1.127 matthew 8678: }
8679:
1.618 raeburn 8680: #######################################################
8681: #######################################################
8682:
8683: =pod
8684:
8685: =head1 Domain E-mail Routines
8686:
8687: =over 4
8688:
1.648 raeburn 8689: =item * &build_recipient_list()
1.618 raeburn 8690:
8691: Build recipient lists for three types of e-mail:
8692: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8693: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8694:
8695: Inputs:
1.619 raeburn 8696: defmail (scalar - email address of default recipient),
1.618 raeburn 8697: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8698: defdom (domain for which to retrieve configuration settings),
8699: origmail (scalar - email address of recipient from loncapa.conf,
8700: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8701:
1.655 raeburn 8702: Returns: comma separated list of addresses to which to send e-mail.
8703:
8704: =back
1.618 raeburn 8705:
8706: =cut
8707:
8708: ############################################################
8709: ############################################################
8710: sub build_recipient_list {
1.619 raeburn 8711: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8712: my @recipients;
8713: my $otheremails;
8714: my %domconfig =
8715: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8716: if (ref($domconfig{'contacts'}) eq 'HASH') {
8717: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8718: my @contacts = ('adminemail','supportemail');
8719: foreach my $item (@contacts) {
8720: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8721: my $addr = $domconfig{'contacts'}{$item};
8722: if (!grep(/^\Q$addr\E$/,@recipients)) {
8723: push(@recipients,$addr);
8724: }
1.618 raeburn 8725: }
8726: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8727: }
8728: }
1.619 raeburn 8729: } elsif ($origmail ne '') {
8730: push(@recipients,$origmail);
1.618 raeburn 8731: }
1.688 raeburn 8732: if (defined($defmail)) {
8733: if ($defmail ne '') {
8734: push(@recipients,$defmail);
8735: }
1.618 raeburn 8736: }
8737: if ($otheremails) {
1.619 raeburn 8738: my @others;
8739: if ($otheremails =~ /,/) {
8740: @others = split(/,/,$otheremails);
1.618 raeburn 8741: } else {
1.619 raeburn 8742: push(@others,$otheremails);
8743: }
8744: foreach my $addr (@others) {
8745: if (!grep(/^\Q$addr\E$/,@recipients)) {
8746: push(@recipients,$addr);
8747: }
1.618 raeburn 8748: }
8749: }
1.619 raeburn 8750: my $recipientlist = join(',',@recipients);
1.618 raeburn 8751: return $recipientlist;
8752: }
8753:
1.127 matthew 8754: ############################################################
8755: ############################################################
1.154 albertel 8756:
1.655 raeburn 8757: =pod
8758:
8759: =head1 Course Catalog Routines
8760:
8761: =over 4
8762:
8763: =item * &gather_categories()
8764:
8765: Converts category definitions - keys of categories hash stored in
8766: coursecategories in configuration.db on the primary library server in a
8767: domain - to an array. Also generates javascript and idx hash used to
8768: generate Domain Coordinator interface for editing Course Categories.
8769:
8770: Inputs:
1.663 raeburn 8771:
1.655 raeburn 8772: categories (reference to hash of category definitions).
1.663 raeburn 8773:
1.655 raeburn 8774: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8775: categories and subcategories).
1.663 raeburn 8776:
1.655 raeburn 8777: idx (reference to hash of counters used in Domain Coordinator interface for
8778: editing Course Categories).
1.663 raeburn 8779:
1.655 raeburn 8780: jsarray (reference to array of categories used to create Javascript arrays for
8781: Domain Coordinator interface for editing Course Categories).
8782:
8783: Returns: nothing
8784:
8785: Side effects: populates cats, idx and jsarray.
8786:
8787: =cut
8788:
8789: sub gather_categories {
8790: my ($categories,$cats,$idx,$jsarray) = @_;
8791: my %counters;
8792: my $num = 0;
8793: foreach my $item (keys(%{$categories})) {
8794: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8795: if ($container eq '' && $depth == 0) {
8796: $cats->[$depth][$categories->{$item}] = $cat;
8797: } else {
8798: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8799: }
8800: my ($escitem,$tail) = split(/:/,$item,2);
8801: if ($counters{$tail} eq '') {
8802: $counters{$tail} = $num;
8803: $num ++;
8804: }
8805: if (ref($idx) eq 'HASH') {
8806: $idx->{$item} = $counters{$tail};
8807: }
8808: if (ref($jsarray) eq 'ARRAY') {
8809: push(@{$jsarray->[$counters{$tail}]},$item);
8810: }
8811: }
8812: return;
8813: }
8814:
8815: =pod
8816:
8817: =item * &extract_categories()
8818:
8819: Used to generate breadcrumb trails for course categories.
8820:
8821: Inputs:
1.663 raeburn 8822:
1.655 raeburn 8823: categories (reference to hash of category definitions).
1.663 raeburn 8824:
1.655 raeburn 8825: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8826: categories and subcategories).
1.663 raeburn 8827:
1.655 raeburn 8828: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8829:
1.655 raeburn 8830: allitems (reference to hash - key is category key
8831: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8832:
1.655 raeburn 8833: idx (reference to hash of counters used in Domain Coordinator interface for
8834: editing Course Categories).
1.663 raeburn 8835:
1.655 raeburn 8836: jsarray (reference to array of categories used to create Javascript arrays for
8837: Domain Coordinator interface for editing Course Categories).
8838:
1.665 raeburn 8839: subcats (reference to hash of arrays containing all subcategories within each
8840: category, -recursive)
8841:
1.655 raeburn 8842: Returns: nothing
8843:
8844: Side effects: populates trails and allitems hash references.
8845:
8846: =cut
8847:
8848: sub extract_categories {
1.665 raeburn 8849: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8850: if (ref($categories) eq 'HASH') {
8851: &gather_categories($categories,$cats,$idx,$jsarray);
8852: if (ref($cats->[0]) eq 'ARRAY') {
8853: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8854: my $name = $cats->[0][$i];
8855: my $item = &escape($name).'::0';
8856: my $trailstr;
8857: if ($name eq 'instcode') {
8858: $trailstr = &mt('Official courses (with institutional codes)');
8859: } else {
8860: $trailstr = $name;
8861: }
8862: if ($allitems->{$item} eq '') {
8863: push(@{$trails},$trailstr);
8864: $allitems->{$item} = scalar(@{$trails})-1;
8865: }
8866: my @parents = ($name);
8867: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8868: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8869: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8870: if (ref($subcats) eq 'HASH') {
8871: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8872: }
8873: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8874: }
8875: } else {
8876: if (ref($subcats) eq 'HASH') {
8877: $subcats->{$item} = [];
1.655 raeburn 8878: }
8879: }
8880: }
8881: }
8882: }
8883: return;
8884: }
8885:
8886: =pod
8887:
8888: =item *&recurse_categories()
8889:
8890: Recursively used to generate breadcrumb trails for course categories.
8891:
8892: Inputs:
1.663 raeburn 8893:
1.655 raeburn 8894: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8895: categories and subcategories).
1.663 raeburn 8896:
1.655 raeburn 8897: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8898:
8899: category (current course category, for which breadcrumb trail is being generated).
8900:
8901: trails (reference to array of breadcrumb trails for each category).
8902:
1.655 raeburn 8903: allitems (reference to hash - key is category key
8904: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8905:
1.655 raeburn 8906: parents (array containing containers directories for current category,
8907: back to top level).
8908:
8909: Returns: nothing
8910:
8911: Side effects: populates trails and allitems hash references
8912:
8913: =cut
8914:
8915: sub recurse_categories {
1.665 raeburn 8916: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8917: my $shallower = $depth - 1;
8918: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8919: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8920: my $name = $cats->[$depth]{$category}[$k];
8921: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8922: my $trailstr = join(' -> ',(@{$parents},$category));
8923: if ($allitems->{$item} eq '') {
8924: push(@{$trails},$trailstr);
8925: $allitems->{$item} = scalar(@{$trails})-1;
8926: }
8927: my $deeper = $depth+1;
8928: push(@{$parents},$category);
1.665 raeburn 8929: if (ref($subcats) eq 'HASH') {
8930: my $subcat = &escape($name).':'.$category.':'.$depth;
8931: for (my $j=@{$parents}; $j>=0; $j--) {
8932: my $higher;
8933: if ($j > 0) {
8934: $higher = &escape($parents->[$j]).':'.
8935: &escape($parents->[$j-1]).':'.$j;
8936: } else {
8937: $higher = &escape($parents->[$j]).'::'.$j;
8938: }
8939: push(@{$subcats->{$higher}},$subcat);
8940: }
8941: }
8942: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8943: $subcats);
1.655 raeburn 8944: pop(@{$parents});
8945: }
8946: } else {
8947: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8948: my $trailstr = join(' -> ',(@{$parents},$category));
8949: if ($allitems->{$item} eq '') {
8950: push(@{$trails},$trailstr);
8951: $allitems->{$item} = scalar(@{$trails})-1;
8952: }
8953: }
8954: return;
8955: }
8956:
1.663 raeburn 8957: =pod
8958:
8959: =item *&assign_categories_table()
8960:
8961: Create a datatable for display of hierarchical categories in a domain,
8962: with checkboxes to allow a course to be categorized.
8963:
8964: Inputs:
8965:
8966: cathash - reference to hash of categories defined for the domain (from
8967: configuration.db)
8968:
8969: currcat - scalar with an & separated list of categories assigned to a course.
8970:
8971: Returns: $output (markup to be displayed)
8972:
8973: =cut
8974:
8975: sub assign_categories_table {
8976: my ($cathash,$currcat) = @_;
8977: my $output;
8978: if (ref($cathash) eq 'HASH') {
8979: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
8980: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
8981: $maxdepth = scalar(@cats);
8982: if (@cats > 0) {
8983: my $itemcount = 0;
8984: if (ref($cats[0]) eq 'ARRAY') {
8985: $output = &Apache::loncommon::start_data_table();
8986: my @currcategories;
8987: if ($currcat ne '') {
8988: @currcategories = split('&',$currcat);
8989: }
8990: for (my $i=0; $i<@{$cats[0]}; $i++) {
8991: my $parent = $cats[0][$i];
8992: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8993: next if ($parent eq 'instcode');
8994: my $item = &escape($parent).'::0';
8995: my $checked = '';
8996: if (@currcategories > 0) {
8997: if (grep(/^\Q$item\E$/,@currcategories)) {
8998: $checked = ' checked="checked" ';
8999: }
9000: }
1.675 raeburn 9001: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9002: '<input type="checkbox" name="usecategory" value="'.
9003: $item.'"'.$checked.' />'.$parent.'</span>'.
9004: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9005: my $depth = 1;
9006: push(@path,$parent);
9007: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9008: pop(@path);
9009: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9010: $itemcount ++;
9011: }
9012: $output .= &Apache::loncommon::end_data_table();
9013: }
9014: }
9015: }
9016: return $output;
9017: }
9018:
9019: =pod
9020:
9021: =item *&assign_category_rows()
9022:
9023: Create a datatable row for display of nested categories in a domain,
9024: with checkboxes to allow a course to be categorized,called recursively.
9025:
9026: Inputs:
9027:
9028: itemcount - track row number for alternating colors
9029:
9030: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9031: categories and subcategories.
9032:
9033: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9034:
9035: parent - parent of current category item
9036:
9037: path - Array containing all categories back up through the hierarchy from the
9038: current category to the top level.
9039:
9040: currcategories - reference to array of current categories assigned to the course
9041:
9042: Returns: $output (markup to be displayed).
9043:
9044: =cut
9045:
9046: sub assign_category_rows {
9047: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9048: my ($text,$name,$item,$chgstr);
9049: if (ref($cats) eq 'ARRAY') {
9050: my $maxdepth = scalar(@{$cats});
9051: if (ref($cats->[$depth]) eq 'HASH') {
9052: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9053: my $numchildren = @{$cats->[$depth]{$parent}};
9054: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9055: $text .= '<td><table class="LC_datatable">';
9056: for (my $j=0; $j<$numchildren; $j++) {
9057: $name = $cats->[$depth]{$parent}[$j];
9058: $item = &escape($name).':'.&escape($parent).':'.$depth;
9059: my $deeper = $depth+1;
9060: my $checked = '';
9061: if (ref($currcategories) eq 'ARRAY') {
9062: if (@{$currcategories} > 0) {
9063: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9064: $checked = ' checked="checked" ';
9065: }
9066: }
9067: }
1.664 raeburn 9068: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9069: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9070: $item.'"'.$checked.' />'.$name.'</label></span>'.
9071: '<input type="hidden" name="catname" value="'.$name.'" />'.
9072: '</td><td>';
1.663 raeburn 9073: if (ref($path) eq 'ARRAY') {
9074: push(@{$path},$name);
9075: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9076: pop(@{$path});
9077: }
9078: $text .= '</td></tr>';
9079: }
9080: $text .= '</table></td>';
9081: }
9082: }
9083: }
9084: return $text;
9085: }
9086:
1.655 raeburn 9087: ############################################################
9088: ############################################################
9089:
9090:
1.443 albertel 9091: sub commit_customrole {
1.664 raeburn 9092: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9093: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9094: ($start?', '.&mt('starting').' '.localtime($start):'').
9095: ($end?', ending '.localtime($end):'').': <b>'.
9096: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9097: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9098: '</b><br />';
9099: return $output;
9100: }
9101:
9102: sub commit_standardrole {
1.541 raeburn 9103: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9104: my ($output,$logmsg,$linefeed);
9105: if ($context eq 'auto') {
9106: $linefeed = "\n";
9107: } else {
9108: $linefeed = "<br />\n";
9109: }
1.443 albertel 9110: if ($three eq 'st') {
1.541 raeburn 9111: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9112: $one,$two,$sec,$context);
9113: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9114: ($result eq 'unknown_course') || ($result eq 'refused')) {
9115: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9116: } else {
1.541 raeburn 9117: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9118: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9119: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9120: if ($context eq 'auto') {
9121: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9122: } else {
9123: $output .= '<b>'.$result.'</b>'.$linefeed.
9124: &mt('Add to classlist').': <b>ok</b>';
9125: }
9126: $output .= $linefeed;
1.443 albertel 9127: }
9128: } else {
9129: $output = &mt('Assigning').' '.$three.' in '.$url.
9130: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9131: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9132: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9133: if ($context eq 'auto') {
9134: $output .= $result.$linefeed;
9135: } else {
9136: $output .= '<b>'.$result.'</b>'.$linefeed;
9137: }
1.443 albertel 9138: }
9139: return $output;
9140: }
9141:
9142: sub commit_studentrole {
1.541 raeburn 9143: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9144: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9145: if ($context eq 'auto') {
9146: $linefeed = "\n";
9147: } else {
9148: $linefeed = '<br />'."\n";
9149: }
1.443 albertel 9150: if (defined($one) && defined($two)) {
9151: my $cid=$one.'_'.$two;
9152: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9153: my $secchange = 0;
9154: my $expire_role_result;
9155: my $modify_section_result;
1.628 raeburn 9156: if ($oldsec ne '-1') {
9157: if ($oldsec ne $sec) {
1.443 albertel 9158: $secchange = 1;
1.628 raeburn 9159: my $now = time;
1.443 albertel 9160: my $uurl='/'.$cid;
9161: $uurl=~s/\_/\//g;
9162: if ($oldsec) {
9163: $uurl.='/'.$oldsec;
9164: }
1.626 raeburn 9165: $oldsecurl = $uurl;
1.628 raeburn 9166: $expire_role_result =
1.652 raeburn 9167: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9168: if ($env{'request.course.sec'} ne '') {
9169: if ($expire_role_result eq 'refused') {
9170: my @roles = ('st');
9171: my @statuses = ('previous');
9172: my @roledoms = ($one);
9173: my $withsec = 1;
9174: my %roleshash =
9175: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9176: \@statuses,\@roles,\@roledoms,$withsec);
9177: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9178: my ($oldstart,$oldend) =
9179: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9180: if ($oldend > 0 && $oldend <= $now) {
9181: $expire_role_result = 'ok';
9182: }
9183: }
9184: }
9185: }
1.443 albertel 9186: $result = $expire_role_result;
9187: }
9188: }
9189: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9190: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9191: if ($modify_section_result =~ /^ok/) {
9192: if ($secchange == 1) {
1.628 raeburn 9193: if ($sec eq '') {
9194: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9195: } else {
9196: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9197: }
1.443 albertel 9198: } elsif ($oldsec eq '-1') {
1.628 raeburn 9199: if ($sec eq '') {
9200: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9201: } else {
9202: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9203: }
1.443 albertel 9204: } else {
1.628 raeburn 9205: if ($sec eq '') {
9206: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9207: } else {
9208: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9209: }
1.443 albertel 9210: }
9211: } else {
1.628 raeburn 9212: if ($secchange) {
9213: $$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;
9214: } else {
9215: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9216: }
1.443 albertel 9217: }
9218: $result = $modify_section_result;
9219: } elsif ($secchange == 1) {
1.628 raeburn 9220: if ($oldsec eq '') {
9221: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9222: } else {
9223: $$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;
9224: }
1.626 raeburn 9225: if ($expire_role_result eq 'refused') {
9226: my $newsecurl = '/'.$cid;
9227: $newsecurl =~ s/\_/\//g;
9228: if ($sec ne '') {
9229: $newsecurl.='/'.$sec;
9230: }
9231: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9232: if ($sec eq '') {
9233: $$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;
9234: } else {
9235: $$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;
9236: }
9237: }
9238: }
1.443 albertel 9239: }
9240: } else {
1.626 raeburn 9241: $$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 9242: $result = "error: incomplete course id\n";
9243: }
9244: return $result;
9245: }
9246:
9247: ############################################################
9248: ############################################################
9249:
1.566 albertel 9250: sub check_clone {
1.578 raeburn 9251: my ($args,$linefeed) = @_;
1.566 albertel 9252: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9253: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9254: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9255: my $clonemsg;
9256: my $can_clone = 0;
9257:
9258: if ($clonehome eq 'no_host') {
1.578 raeburn 9259: $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 9260: } else {
9261: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9262: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9263: $can_clone = 1;
9264: } else {
9265: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9266: $args->{'clonedomain'},$args->{'clonecourse'});
9267: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9268: if (grep(/^\*$/,@cloners)) {
9269: $can_clone = 1;
9270: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9271: $can_clone = 1;
9272: } else {
9273: my %roleshash =
9274: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9275: $args->{'ccdomain'},
9276: 'userroles',['active'],['cc'],
9277: [$args->{'clonedomain'}]);
9278: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9279: $can_clone = 1;
9280: } else {
9281: $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'});
9282: }
1.566 albertel 9283: }
1.578 raeburn 9284: }
1.566 albertel 9285: }
9286: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9287: }
9288:
1.444 albertel 9289: sub construct_course {
1.541 raeburn 9290: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9291: my $outcome;
1.541 raeburn 9292: my $linefeed = '<br />'."\n";
9293: if ($context eq 'auto') {
9294: $linefeed = "\n";
9295: }
1.566 albertel 9296:
9297: #
9298: # Are we cloning?
9299: #
9300: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9301: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9302: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9303: if ($context ne 'auto') {
1.578 raeburn 9304: if ($clonemsg ne '') {
9305: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9306: }
1.566 albertel 9307: }
9308: $outcome .= $clonemsg.$linefeed;
9309:
9310: if (!$can_clone) {
9311: return (0,$outcome);
9312: }
9313: }
9314:
1.444 albertel 9315: #
9316: # Open course
9317: #
9318: my $crstype = lc($args->{'crstype'});
9319: my %cenv=();
9320: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9321: $args->{'cdescr'},
9322: $args->{'curl'},
9323: $args->{'course_home'},
9324: $args->{'nonstandard'},
9325: $args->{'crscode'},
9326: $args->{'ccuname'}.':'.
9327: $args->{'ccdomain'},
9328: $args->{'crstype'});
9329:
9330: # Note: The testing routines depend on this being output; see
9331: # Utils::Course. This needs to at least be output as a comment
9332: # if anyone ever decides to not show this, and Utils::Course::new
9333: # will need to be suitably modified.
1.541 raeburn 9334: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9335: #
9336: # Check if created correctly
9337: #
1.479 albertel 9338: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9339: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9340: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9341:
1.444 albertel 9342: #
1.566 albertel 9343: # Do the cloning
9344: #
9345: if ($can_clone && $cloneid) {
9346: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9347: if ($context ne 'auto') {
9348: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9349: }
9350: $outcome .= $clonemsg.$linefeed;
9351: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9352: # Copy all files
1.637 www 9353: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9354: # Restore URL
1.566 albertel 9355: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9356: # Restore title
1.566 albertel 9357: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9358: # Mark as cloned
1.566 albertel 9359: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9360: # Need to clone grading mode
9361: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9362: $cenv{'grading'}=$newenv{'grading'};
9363: # Do not clone these environment entries
9364: &Apache::lonnet::del('environment',
9365: ['default_enrollment_start_date',
9366: 'default_enrollment_end_date',
9367: 'question.email',
9368: 'policy.email',
9369: 'comment.email',
9370: 'pch.users.denied',
9371: 'plc.users.denied'],
9372: $$crsudom,$$crsunum);
1.444 albertel 9373: }
1.566 albertel 9374:
1.444 albertel 9375: #
9376: # Set environment (will override cloned, if existing)
9377: #
9378: my @sections = ();
9379: my @xlists = ();
9380: if ($args->{'crstype'}) {
9381: $cenv{'type'}=$args->{'crstype'};
9382: }
9383: if ($args->{'crsid'}) {
9384: $cenv{'courseid'}=$args->{'crsid'};
9385: }
9386: if ($args->{'crscode'}) {
9387: $cenv{'internal.coursecode'}=$args->{'crscode'};
9388: }
9389: if ($args->{'crsquota'} ne '') {
9390: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9391: } else {
9392: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9393: }
9394: if ($args->{'ccuname'}) {
9395: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9396: ':'.$args->{'ccdomain'};
9397: } else {
9398: $cenv{'internal.courseowner'} = $args->{'curruser'};
9399: }
9400: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9401: if ($args->{'crssections'}) {
9402: $cenv{'internal.sectionnums'} = '';
9403: if ($args->{'crssections'} =~ m/,/) {
9404: @sections = split/,/,$args->{'crssections'};
9405: } else {
9406: $sections[0] = $args->{'crssections'};
9407: }
9408: if (@sections > 0) {
9409: foreach my $item (@sections) {
9410: my ($sec,$gp) = split/:/,$item;
9411: my $class = $args->{'crscode'}.$sec;
9412: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9413: $cenv{'internal.sectionnums'} .= $item.',';
9414: unless ($addcheck eq 'ok') {
9415: push @badclasses, $class;
9416: }
9417: }
9418: $cenv{'internal.sectionnums'} =~ s/,$//;
9419: }
9420: }
9421: # do not hide course coordinator from staff listing,
9422: # even if privileged
9423: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9424: # add crosslistings
9425: if ($args->{'crsxlist'}) {
9426: $cenv{'internal.crosslistings'}='';
9427: if ($args->{'crsxlist'} =~ m/,/) {
9428: @xlists = split/,/,$args->{'crsxlist'};
9429: } else {
9430: $xlists[0] = $args->{'crsxlist'};
9431: }
9432: if (@xlists > 0) {
9433: foreach my $item (@xlists) {
9434: my ($xl,$gp) = split/:/,$item;
9435: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9436: $cenv{'internal.crosslistings'} .= $item.',';
9437: unless ($addcheck eq 'ok') {
9438: push @badclasses, $xl;
9439: }
9440: }
9441: $cenv{'internal.crosslistings'} =~ s/,$//;
9442: }
9443: }
9444: if ($args->{'autoadds'}) {
9445: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9446: }
9447: if ($args->{'autodrops'}) {
9448: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9449: }
9450: # check for notification of enrollment changes
9451: my @notified = ();
9452: if ($args->{'notify_owner'}) {
9453: if ($args->{'ccuname'} ne '') {
9454: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9455: }
9456: }
9457: if ($args->{'notify_dc'}) {
9458: if ($uname ne '') {
1.630 raeburn 9459: push(@notified,$uname.':'.$udom);
1.444 albertel 9460: }
9461: }
9462: if (@notified > 0) {
9463: my $notifylist;
9464: if (@notified > 1) {
9465: $notifylist = join(',',@notified);
9466: } else {
9467: $notifylist = $notified[0];
9468: }
9469: $cenv{'internal.notifylist'} = $notifylist;
9470: }
9471: if (@badclasses > 0) {
9472: my %lt=&Apache::lonlocal::texthash(
9473: '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',
9474: 'dnhr' => 'does not have rights to access enrollment in these classes',
9475: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9476: );
1.541 raeburn 9477: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9478: ' ('.$lt{'adby'}.')';
9479: if ($context eq 'auto') {
9480: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9481: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9482: foreach my $item (@badclasses) {
9483: if ($context eq 'auto') {
9484: $outcome .= " - $item\n";
9485: } else {
9486: $outcome .= "<li>$item</li>\n";
9487: }
9488: }
9489: if ($context eq 'auto') {
9490: $outcome .= $linefeed;
9491: } else {
1.566 albertel 9492: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9493: }
9494: }
1.444 albertel 9495: }
9496: if ($args->{'no_end_date'}) {
9497: $args->{'endaccess'} = 0;
9498: }
9499: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9500: $cenv{'internal.autoend'}=$args->{'enrollend'};
9501: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9502: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9503: if ($args->{'showphotos'}) {
9504: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9505: }
9506: $cenv{'internal.authtype'} = $args->{'authtype'};
9507: $cenv{'internal.autharg'} = $args->{'autharg'};
9508: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9509: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9510: 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');
9511: if ($context eq 'auto') {
9512: $outcome .= $krb_msg;
9513: } else {
1.566 albertel 9514: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9515: }
9516: $outcome .= $linefeed;
1.444 albertel 9517: }
9518: }
9519: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9520: if ($args->{'setpolicy'}) {
9521: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9522: }
9523: if ($args->{'setcontent'}) {
9524: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9525: }
9526: }
9527: if ($args->{'reshome'}) {
9528: $cenv{'reshome'}=$args->{'reshome'}.'/';
9529: $cenv{'reshome'}=~s/\/+$/\//;
9530: }
9531: #
9532: # course has keyed access
9533: #
9534: if ($args->{'setkeys'}) {
9535: $cenv{'keyaccess'}='yes';
9536: }
9537: # if specified, key authority is not course, but user
9538: # only active if keyaccess is yes
9539: if ($args->{'keyauth'}) {
1.487 albertel 9540: my ($user,$domain) = split(':',$args->{'keyauth'});
9541: $user = &LONCAPA::clean_username($user);
9542: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9543: if ($user ne '' && $domain ne '') {
1.487 albertel 9544: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9545: }
9546: }
9547:
9548: if ($args->{'disresdis'}) {
9549: $cenv{'pch.roles.denied'}='st';
9550: }
9551: if ($args->{'disablechat'}) {
9552: $cenv{'plc.roles.denied'}='st';
9553: }
9554:
9555: # Record we've not yet viewed the Course Initialization Helper for this
9556: # course
9557: $cenv{'course.helper.not.run'} = 1;
9558: #
9559: # Use new Randomseed
9560: #
9561: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9562: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9563: #
9564: # The encryption code and receipt prefix for this course
9565: #
9566: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9567: $cenv{'internal.encpref'}=100+int(9*rand(99));
9568: #
9569: # By default, use standard grading
9570: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9571:
1.541 raeburn 9572: $outcome .= $linefeed.&mt('Setting environment').': '.
9573: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9574: #
9575: # Open all assignments
9576: #
9577: if ($args->{'openall'}) {
9578: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9579: my %storecontent = ($storeunder => time,
9580: $storeunder.'.type' => 'date_start');
9581:
9582: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9583: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9584: }
9585: #
9586: # Set first page
9587: #
9588: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9589: || ($cloneid)) {
1.445 albertel 9590: use LONCAPA::map;
1.444 albertel 9591: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9592:
9593: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9594: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9595:
1.444 albertel 9596: $outcome .= ($fatal?$errtext:'read ok').' - ';
9597: my $title; my $url;
9598: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9599: $title=&mt('Syllabus');
1.444 albertel 9600: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9601: } else {
1.690 bisitz 9602: $title=&mt('Navigate Contents');
1.444 albertel 9603: $url='/adm/navmaps';
9604: }
1.445 albertel 9605:
9606: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9607: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9608:
9609: if ($errtext) { $fatal=2; }
1.541 raeburn 9610: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9611: }
1.566 albertel 9612:
9613: return (1,$outcome);
1.444 albertel 9614: }
9615:
9616: ############################################################
9617: ############################################################
9618:
1.378 raeburn 9619: sub course_type {
9620: my ($cid) = @_;
9621: if (!defined($cid)) {
9622: $cid = $env{'request.course.id'};
9623: }
1.404 albertel 9624: if (defined($env{'course.'.$cid.'.type'})) {
9625: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9626: } else {
9627: return 'Course';
1.377 raeburn 9628: }
9629: }
1.156 albertel 9630:
1.406 raeburn 9631: sub group_term {
9632: my $crstype = &course_type();
9633: my %names = (
9634: 'Course' => 'group',
9635: 'Group' => 'team',
9636: );
9637: return $names{$crstype};
9638: }
9639:
1.156 albertel 9640: sub icon {
9641: my ($file)=@_;
1.505 albertel 9642: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9643: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9644: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9645: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9646: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9647: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9648: $curfext.".gif") {
9649: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9650: $curfext.".gif";
9651: }
9652: }
1.249 albertel 9653: return &lonhttpdurl($iconname);
1.154 albertel 9654: }
1.84 albertel 9655:
1.575 albertel 9656: sub lonhttpdurl {
1.692 www 9657: #
9658: # Had been used for "small fry" static images on separate port 8080.
9659: # Modify here if lightweight http functionality desired again.
9660: # Currently eliminated due to increasing firewall issues.
9661: #
1.575 albertel 9662: my ($url)=@_;
1.692 www 9663: return $url;
1.215 albertel 9664: }
9665:
1.213 albertel 9666: sub connection_aborted {
9667: my ($r)=@_;
9668: $r->print(" ");$r->rflush();
9669: my $c = $r->connection;
9670: return $c->aborted();
9671: }
9672:
1.221 foxr 9673: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9674: # strings as 'strings'.
9675: sub escape_single {
1.221 foxr 9676: my ($input) = @_;
1.223 albertel 9677: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9678: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9679: return $input;
9680: }
1.223 albertel 9681:
1.222 foxr 9682: # Same as escape_single, but escape's "'s This
9683: # can be used for "strings"
9684: sub escape_double {
9685: my ($input) = @_;
9686: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9687: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9688: return $input;
9689: }
1.223 albertel 9690:
1.222 foxr 9691: # Escapes the last element of a full URL.
9692: sub escape_url {
9693: my ($url) = @_;
1.238 raeburn 9694: my @urlslices = split(/\//, $url,-1);
1.369 www 9695: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9696: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9697: }
1.462 albertel 9698:
9699: # -------------------------------------------------------- Initliaze user login
9700: sub init_user_environment {
1.463 albertel 9701: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9702: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9703:
9704: my $public=($username eq 'public' && $domain eq 'public');
9705:
9706: # See if old ID present, if so, remove
9707:
9708: my ($filename,$cookie,$userroles);
9709: my $now=time;
9710:
9711: if ($public) {
9712: my $max_public=100;
9713: my $oldest;
9714: my $oldest_time=0;
9715: for(my $next=1;$next<=$max_public;$next++) {
9716: if (-e $lonids."/publicuser_$next.id") {
9717: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9718: if ($mtime<$oldest_time || !$oldest_time) {
9719: $oldest_time=$mtime;
9720: $oldest=$next;
9721: }
9722: } else {
9723: $cookie="publicuser_$next";
9724: last;
9725: }
9726: }
9727: if (!$cookie) { $cookie="publicuser_$oldest"; }
9728: } else {
1.463 albertel 9729: # if this isn't a robot, kill any existing non-robot sessions
9730: if (!$args->{'robot'}) {
9731: opendir(DIR,$lonids);
9732: while ($filename=readdir(DIR)) {
9733: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9734: unlink($lonids.'/'.$filename);
9735: }
1.462 albertel 9736: }
1.463 albertel 9737: closedir(DIR);
1.462 albertel 9738: }
9739: # Give them a new cookie
1.463 albertel 9740: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9741: : $now.$$.int(rand(10000)));
1.463 albertel 9742: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9743:
9744: # Initialize roles
9745:
9746: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9747: }
9748: # ------------------------------------ Check browser type and MathML capability
9749:
9750: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9751: $clientunicode,$clientos) = &decode_user_agent($r);
9752:
9753: # -------------------------------------- Any accessibility options to remember?
9754: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9755: foreach my $option ('imagesuppress','appletsuppress',
9756: 'embedsuppress','fontenhance','blackwhite') {
9757: if ($form->{$option} eq 'true') {
9758: &Apache::lonnet::put('environment',{$option => 'on'},
9759: $domain,$username);
9760: } else {
9761: &Apache::lonnet::del('environment',[$option],
9762: $domain,$username);
9763: }
9764: }
9765: }
9766: # ------------------------------------------------------------- Get environment
9767:
9768: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9769: my ($tmp) = keys(%userenv);
9770: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9771: # default remote control to off
9772: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9773: } else {
9774: undef(%userenv);
9775: }
9776: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9777: $form->{'interface'}=$userenv{'interface'};
9778: }
9779: $env{'environment.remote'}=$userenv{'remote'};
9780: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9781:
9782: # --------------- Do not trust query string to be put directly into environment
9783: foreach my $option ('imagesuppress','appletsuppress',
9784: 'embedsuppress','fontenhance','blackwhite',
9785: 'interface','localpath','localres') {
9786: $form->{$option}=~s/[\n\r\=]//gs;
9787: }
9788: # --------------------------------------------------------- Write first profile
9789:
9790: {
9791: my %initial_env =
9792: ("user.name" => $username,
9793: "user.domain" => $domain,
9794: "user.home" => $authhost,
9795: "browser.type" => $clientbrowser,
9796: "browser.version" => $clientversion,
9797: "browser.mathml" => $clientmathml,
9798: "browser.unicode" => $clientunicode,
9799: "browser.os" => $clientos,
9800: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9801: "request.course.fn" => '',
9802: "request.course.uri" => '',
9803: "request.course.sec" => '',
9804: "request.role" => 'cm',
9805: "request.role.adv" => $env{'user.adv'},
9806: "request.host" => $ENV{'REMOTE_ADDR'},);
9807:
9808: if ($form->{'localpath'}) {
9809: $initial_env{"browser.localpath"} = $form->{'localpath'};
9810: $initial_env{"browser.localres"} = $form->{'localres'};
9811: }
9812:
9813: if ($public) {
9814: $initial_env{"environment.remote"} = "off";
9815: }
9816: if ($form->{'interface'}) {
9817: $form->{'interface'}=~s/\W//gs;
9818: $initial_env{"browser.interface"} = $form->{'interface'};
9819: $env{'browser.interface'}=$form->{'interface'};
9820: foreach my $option ('imagesuppress','appletsuppress',
9821: 'embedsuppress','fontenhance','blackwhite') {
9822: if (($form->{$option} eq 'true') ||
9823: ($userenv{$option} eq 'on')) {
9824: $initial_env{"browser.$option"} = "on";
9825: }
9826: }
9827: }
9828:
9829: $env{'user.environment'} = "$lonids/$cookie.id";
9830:
9831: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9832: &GDBM_WRCREAT(),0640)) {
9833: &_add_to_env(\%disk_env,\%initial_env);
9834: &_add_to_env(\%disk_env,\%userenv,'environment.');
9835: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9836: if (ref($args->{'extra_env'})) {
9837: &_add_to_env(\%disk_env,$args->{'extra_env'});
9838: }
1.462 albertel 9839: untie(%disk_env);
9840: } else {
9841: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
9842: 'Could not create environment storage in lonauth: '.$!.'</font>');
9843: return 'error: '.$!;
9844: }
9845: }
9846: $env{'request.role'}='cm';
9847: $env{'request.role.adv'}=$env{'user.adv'};
9848: $env{'browser.type'}=$clientbrowser;
9849:
9850: return $cookie;
9851:
9852: }
9853:
9854: sub _add_to_env {
9855: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 9856: if (ref($env_data) eq 'HASH') {
9857: while (my ($key,$value) = each(%$env_data)) {
9858: $idf->{$prefix.$key} = $value;
9859: $env{$prefix.$key} = $value;
9860: }
1.462 albertel 9861: }
9862: }
9863:
1.685 tempelho 9864: # --- Get the symbolic name of a problem and the url
9865: sub get_symb {
9866: my ($request,$silent) = @_;
9867: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
9868: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
9869: if ($symb eq '') {
9870: if (!$silent) {
9871: $request->print("Unable to handle ambiguous references:$url:.");
9872: return ();
9873: }
9874: }
9875: &Apache::lonenc::check_decrypt(\$symb);
9876: return ($symb);
9877: }
9878:
9879: # --------------------------------------------------------------Get annotation
9880:
9881: sub get_annotation {
9882: my ($symb,$enc) = @_;
9883:
9884: my $key = $symb;
9885: if (!$enc) {
9886: $key =
9887: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
9888: }
9889: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
9890: return $annotation{$key};
9891: }
9892:
9893: sub clean_symb {
9894: my ($symb) = @_;
9895:
9896: &Apache::lonenc::check_decrypt(\$symb);
9897: my $enc = $env{'request.enc'};
9898: delete($env{'request.enc'});
9899:
9900: return ($symb,$enc);
9901: }
1.462 albertel 9902:
1.41 ng 9903: =pod
9904:
9905: =back
9906:
1.112 bowersj2 9907: =cut
1.41 ng 9908:
1.112 bowersj2 9909: 1;
9910: __END__;
1.41 ng 9911:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>