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