Annotation of loncom/interface/loncommon.pm, revision 1.758
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.758 ! kaisler 4: # $Id: loncommon.pm,v 1.757 2009/02/25 21:06:27 schulted 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.755 neumanie 926: if ($text ne "") {
927: $template.="<a style=\"background-color:#3333AA;\" target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;\">$text</span></a>";
1.48 bowersj2 928: }
929:
930: # Add the graphic
1.179 matthew 931: my $title = &mt('Online Help');
1.667 raeburn 932: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48 bowersj2 933: $template .= <<"ENDTEMPLATE";
1.436 albertel 934: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 935: ENDTEMPLATE
1.755 neumanie 936:
1.44 bowersj2 937: return $template;
938:
1.106 bowersj2 939: }
940:
941: # This is a quicky function for Latex cheatsheet editing, since it
942: # appears in at least four places
943: sub helpLatexCheatsheet {
1.732 raeburn 944: my ($topic,$text,$not_author) = @_;
945: my $out;
1.106 bowersj2 946: my $addOther = '';
1.732 raeburn 947: if ($topic) {
948: $addOther = &Apache::loncommon::help_open_topic($topic,$text,
949: undef, undef, 600).
1.106 bowersj2 950: '</td><td>';
951: }
1.732 raeburn 952: $out = '<table><tr><td>'.
953: $addOther .
954: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
955: undef,undef,600).
956: '</td><td>'.
957: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
958: undef,undef,600).
959: '</td>';
960: unless ($not_author) {
961: $out .= '<td>'.
962: &Apache::loncommon::help_open_topic("Authoring_Output_Tags",&mt('Output Tags'),
963: undef,undef,600).
964: '</td>';
965: }
966: $out .= '</tr></table>';
967: return $out;
1.172 www 968: }
969:
1.430 albertel 970: sub general_help {
971: my $helptopic='Student_Intro';
972: if ($env{'request.role'}=~/^(ca|au)/) {
973: $helptopic='Authoring_Intro';
974: } elsif ($env{'request.role'}=~/^cc/) {
975: $helptopic='Course_Coordination_Intro';
1.672 raeburn 976: } elsif ($env{'request.role'}=~/^dc/) {
977: $helptopic='Domain_Coordination_Intro';
1.430 albertel 978: }
979: return $helptopic;
980: }
981:
982: sub update_help_link {
983: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
984: my $origurl = $ENV{'REQUEST_URI'};
985: $origurl=~s|^/~|/priv/|;
986: my $timestamp = time;
987: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
988: $$datum = &escape($$datum);
989: }
990:
991: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
992: my $output .= <<"ENDOUTPUT";
993: <script type="text/javascript">
994: banner_link = '$banner_link';
995: </script>
996: ENDOUTPUT
997: return $output;
998: }
999:
1000: # now just updates the help link and generates a blue icon
1.193 raeburn 1001: sub help_open_menu {
1.430 albertel 1002: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1003: = @_;
1.430 albertel 1004: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 1005: # only use pop-up help (stayOnPage == 0)
1.552 banghart 1006: # if environment.remote is on (using remote control UI)
1.572 banghart 1007: if ($env{'browser.interface'} eq 'textual' ||
1008: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 1009: $stayOnPage=1;
1.430 albertel 1010: }
1011: my $output;
1012: if ($component_help) {
1013: if (!$text) {
1014: $output=&help_open_topic($component_help,undef,$stayOnPage,
1015: $width,$height);
1016: } else {
1017: my $help_text;
1018: $help_text=&unescape($topic);
1019: $output='<table><tr><td>'.
1020: &help_open_topic($component_help,$help_text,$stayOnPage,
1021: $width,$height).'</td></tr></table>';
1022: }
1023: }
1024: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1025: return $output.$banner_link;
1026: }
1027:
1028: sub top_nav_help {
1029: my ($text) = @_;
1.436 albertel 1030: $text = &mt($text);
1.572 banghart 1031: my $stay_on_page =
1.436 albertel 1032: ($env{'browser.interface'} eq 'textual' ||
1033: $env{'environment.remote'} eq 'off' );
1.572 banghart 1034: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1035: : "javascript:helpMenu('open')";
1.572 banghart 1036: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1037:
1.201 raeburn 1038: my $title = &mt('Get help');
1.436 albertel 1039:
1040: return <<"END";
1041: $banner_link
1042: <a href="$link" title="$title">$text</a>
1043: END
1044: }
1045:
1046: sub help_menu_js {
1047: my ($text) = @_;
1048:
1049: my $stayOnPage =
1050: ($env{'browser.interface'} eq 'textual' ||
1051: $env{'environment.remote'} eq 'off' );
1052:
1053: my $width = 620;
1054: my $height = 600;
1.430 albertel 1055: my $helptopic=&general_help();
1056: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1057: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1058: my $start_page =
1059: &Apache::loncommon::start_page('Help Menu', undef,
1060: {'frameset' => 1,
1061: 'js_ready' => 1,
1062: 'add_entries' => {
1063: 'border' => '0',
1.579 raeburn 1064: 'rows' => "110,*",},});
1.331 albertel 1065: my $end_page =
1066: &Apache::loncommon::end_page({'frameset' => 1,
1067: 'js_ready' => 1,});
1068:
1.436 albertel 1069: my $template .= <<"ENDTEMPLATE";
1070: <script type="text/javascript">
1.253 albertel 1071: // <!-- BEGIN LON-CAPA Internal
1072: // <![CDATA[
1.430 albertel 1073: var banner_link = '';
1.243 raeburn 1074: function helpMenu(target) {
1075: var caller = this;
1076: if (target == 'open') {
1077: var newWindow = null;
1078: try {
1.262 albertel 1079: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1080: }
1081: catch(error) {
1082: writeHelp(caller);
1083: return;
1084: }
1085: if (newWindow) {
1086: caller = newWindow;
1087: }
1.193 raeburn 1088: }
1.243 raeburn 1089: writeHelp(caller);
1090: return;
1091: }
1092: function writeHelp(caller) {
1.430 albertel 1093: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1094: caller.document.close()
1095: caller.focus()
1.193 raeburn 1096: }
1.253 albertel 1097: // ]]>
1.219 albertel 1098: // END LON-CAPA Internal -->
1.436 albertel 1099: </script>
1.193 raeburn 1100: ENDTEMPLATE
1101: return $template;
1102: }
1103:
1.172 www 1104: sub help_open_bug {
1105: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1106: unless ($env{'user.adv'}) { return ''; }
1.172 www 1107: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1108: $text = "" if (not defined $text);
1109: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1110: if ($env{'browser.interface'} eq 'textual' ||
1111: $env{'environment.remote'} eq 'off' ) {
1.172 www 1112: $stayOnPage=1;
1113: }
1.184 albertel 1114: $width = 600 if (not defined $width);
1115: $height = 600 if (not defined $height);
1.172 www 1116:
1117: $topic=~s/\W+/\+/g;
1118: my $link='';
1119: my $template='';
1.379 albertel 1120: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1121: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1122: if (!$stayOnPage)
1123: {
1124: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1125: }
1126: else
1127: {
1128: $link = $url;
1129: }
1130: # Add the text
1131: if ($text ne "")
1132: {
1133: $template .=
1134: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1135: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1136: }
1137:
1138: # Add the graphic
1.179 matthew 1139: my $title = &mt('Report a Bug');
1.215 albertel 1140: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1141: $template .= <<"ENDTEMPLATE";
1.436 albertel 1142: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1143: ENDTEMPLATE
1144: if ($text ne '') { $template.='</td></tr></table>' };
1145: return $template;
1146:
1147: }
1148:
1149: sub help_open_faq {
1150: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1151: unless ($env{'user.adv'}) { return ''; }
1.172 www 1152: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1153: $text = "" if (not defined $text);
1154: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1155: if ($env{'browser.interface'} eq 'textual' ||
1156: $env{'environment.remote'} eq 'off' ) {
1.172 www 1157: $stayOnPage=1;
1158: }
1159: $width = 350 if (not defined $width);
1160: $height = 400 if (not defined $height);
1161:
1162: $topic=~s/\W+/\+/g;
1163: my $link='';
1164: my $template='';
1165: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1166: if (!$stayOnPage)
1167: {
1168: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1169: }
1170: else
1171: {
1172: $link = $url;
1173: }
1174:
1175: # Add the text
1176: if ($text ne "")
1177: {
1178: $template .=
1.173 www 1179: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1180: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1181: }
1182:
1183: # Add the graphic
1.179 matthew 1184: my $title = &mt('View the FAQ');
1.215 albertel 1185: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1186: $template .= <<"ENDTEMPLATE";
1.436 albertel 1187: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1188: ENDTEMPLATE
1189: if ($text ne '') { $template.='</td></tr></table>' };
1190: return $template;
1191:
1.44 bowersj2 1192: }
1.37 matthew 1193:
1.180 matthew 1194: ###############################################################
1195: ###############################################################
1196:
1.45 matthew 1197: =pod
1198:
1.648 raeburn 1199: =item * &change_content_javascript():
1.256 matthew 1200:
1201: This and the next function allow you to create small sections of an
1202: otherwise static HTML page that you can update on the fly with
1203: Javascript, even in Netscape 4.
1204:
1205: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1206: must be written to the HTML page once. It will prove the Javascript
1207: function "change(name, content)". Calling the change function with the
1208: name of the section
1209: you want to update, matching the name passed to C<changable_area>, and
1210: the new content you want to put in there, will put the content into
1211: that area.
1212:
1213: B<Note>: Netscape 4 only reserves enough space for the changable area
1214: to contain room for the original contents. You need to "make space"
1215: for whatever changes you wish to make, and be B<sure> to check your
1216: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1217: it's adequate for updating a one-line status display, but little more.
1218: This script will set the space to 100% width, so you only need to
1219: worry about height in Netscape 4.
1220:
1221: Modern browsers are much less limiting, and if you can commit to the
1222: user not using Netscape 4, this feature may be used freely with
1223: pretty much any HTML.
1224:
1225: =cut
1226:
1227: sub change_content_javascript {
1228: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1229: if ($env{'browser.type'} eq 'netscape' &&
1230: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1231: return (<<NETSCAPE4);
1232: function change(name, content) {
1233: doc = document.layers[name+"___escape"].layers[0].document;
1234: doc.open();
1235: doc.write(content);
1236: doc.close();
1237: }
1238: NETSCAPE4
1239: } else {
1240: # Otherwise, we need to use semi-standards-compliant code
1241: # (technically, "innerHTML" isn't standard but the equivalent
1242: # is really scary, and every useful browser supports it
1243: return (<<DOMBASED);
1244: function change(name, content) {
1245: element = document.getElementById(name);
1246: element.innerHTML = content;
1247: }
1248: DOMBASED
1249: }
1250: }
1251:
1252: =pod
1253:
1.648 raeburn 1254: =item * &changable_area($name,$origContent):
1.256 matthew 1255:
1256: This provides a "changable area" that can be modified on the fly via
1257: the Javascript code provided in C<change_content_javascript>. $name is
1258: the name you will use to reference the area later; do not repeat the
1259: same name on a given HTML page more then once. $origContent is what
1260: the area will originally contain, which can be left blank.
1261:
1262: =cut
1263:
1264: sub changable_area {
1265: my ($name, $origContent) = @_;
1266:
1.258 albertel 1267: if ($env{'browser.type'} eq 'netscape' &&
1268: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1269: # If this is netscape 4, we need to use the Layer tag
1270: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1271: } else {
1272: return "<span id='$name'>$origContent</span>";
1273: }
1274: }
1275:
1276: =pod
1277:
1.648 raeburn 1278: =item * &viewport_geometry_js
1.590 raeburn 1279:
1280: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1281:
1282: =cut
1283:
1284:
1285: sub viewport_geometry_js {
1286: return <<"GEOMETRY";
1287: var Geometry = {};
1288: function init_geometry() {
1289: if (Geometry.init) { return };
1290: Geometry.init=1;
1291: if (window.innerHeight) {
1292: Geometry.getViewportHeight = function() { return window.innerHeight; };
1293: Geometry.getViewportWidth = function() { return window.innerWidth; };
1294: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1295: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1296: }
1297: else if (document.documentElement && document.documentElement.clientHeight) {
1298: Geometry.getViewportHeight =
1299: function() { return document.documentElement.clientHeight; };
1300: Geometry.getViewportWidth =
1301: function() { return document.documentElement.clientWidth; };
1302:
1303: Geometry.getHorizontalScroll =
1304: function() { return document.documentElement.scrollLeft; };
1305: Geometry.getVerticalScroll =
1306: function() { return document.documentElement.scrollTop; };
1307: }
1308: else if (document.body.clientHeight) {
1309: Geometry.getViewportHeight =
1310: function() { return document.body.clientHeight; };
1311: Geometry.getViewportWidth =
1312: function() { return document.body.clientWidth; };
1313: Geometry.getHorizontalScroll =
1314: function() { return document.body.scrollLeft; };
1315: Geometry.getVerticalScroll =
1316: function() { return document.body.scrollTop; };
1317: }
1318: }
1319:
1320: GEOMETRY
1321: }
1322:
1323: =pod
1324:
1.648 raeburn 1325: =item * &viewport_size_js()
1.590 raeburn 1326:
1327: 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.
1328:
1329: =cut
1330:
1331: sub viewport_size_js {
1332: my $geometry = &viewport_geometry_js();
1333: return <<"DIMS";
1334:
1335: $geometry
1336:
1337: function getViewportDims(width,height) {
1338: init_geometry();
1339: width.value = Geometry.getViewportWidth();
1340: height.value = Geometry.getViewportHeight();
1341: return;
1342: }
1343:
1344: DIMS
1345: }
1346:
1347: =pod
1348:
1.648 raeburn 1349: =item * &resize_textarea_js()
1.565 albertel 1350:
1351: emits the needed javascript to resize a textarea to be as big as possible
1352:
1353: creates a function resize_textrea that takes two IDs first should be
1354: the id of the element to resize, second should be the id of a div that
1355: surrounds everything that comes after the textarea, this routine needs
1356: to be attached to the <body> for the onload and onresize events.
1357:
1.648 raeburn 1358: =back
1.565 albertel 1359:
1360: =cut
1361:
1362: sub resize_textarea_js {
1.590 raeburn 1363: my $geometry = &viewport_geometry_js();
1.565 albertel 1364: return <<"RESIZE";
1365: <script type="text/javascript">
1.590 raeburn 1366: $geometry
1.565 albertel 1367:
1.588 albertel 1368: function getX(element) {
1369: var x = 0;
1370: while (element) {
1371: x += element.offsetLeft;
1372: element = element.offsetParent;
1373: }
1374: return x;
1375: }
1376: function getY(element) {
1377: var y = 0;
1378: while (element) {
1379: y += element.offsetTop;
1380: element = element.offsetParent;
1381: }
1382: return y;
1383: }
1384:
1385:
1.565 albertel 1386: function resize_textarea(textarea_id,bottom_id) {
1387: init_geometry();
1388: var textarea = document.getElementById(textarea_id);
1389: //alert(textarea);
1390:
1.588 albertel 1391: var textarea_top = getY(textarea);
1.565 albertel 1392: var textarea_height = textarea.offsetHeight;
1393: var bottom = document.getElementById(bottom_id);
1.588 albertel 1394: var bottom_top = getY(bottom);
1.565 albertel 1395: var bottom_height = bottom.offsetHeight;
1396: var window_height = Geometry.getViewportHeight();
1.588 albertel 1397: var fudge = 23;
1.565 albertel 1398: var new_height = window_height-fudge-textarea_top-bottom_height;
1399: if (new_height < 300) {
1400: new_height = 300;
1401: }
1402: textarea.style.height=new_height+'px';
1403: }
1404: </script>
1405: RESIZE
1406:
1407: }
1408:
1409: =pod
1410:
1.256 matthew 1411: =head1 Excel and CSV file utility routines
1412:
1413: =over 4
1414:
1415: =cut
1416:
1417: ###############################################################
1418: ###############################################################
1419:
1420: =pod
1421:
1.648 raeburn 1422: =item * &csv_translate($text)
1.37 matthew 1423:
1.185 www 1424: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1425: format.
1426:
1427: =cut
1428:
1.180 matthew 1429: ###############################################################
1430: ###############################################################
1.37 matthew 1431: sub csv_translate {
1432: my $text = shift;
1433: $text =~ s/\"/\"\"/g;
1.209 albertel 1434: $text =~ s/\n/ /g;
1.37 matthew 1435: return $text;
1436: }
1.180 matthew 1437:
1438: ###############################################################
1439: ###############################################################
1440:
1441: =pod
1442:
1.648 raeburn 1443: =item * &define_excel_formats()
1.180 matthew 1444:
1445: Define some commonly used Excel cell formats.
1446:
1447: Currently supported formats:
1448:
1449: =over 4
1450:
1451: =item header
1452:
1453: =item bold
1454:
1455: =item h1
1456:
1457: =item h2
1458:
1459: =item h3
1460:
1.256 matthew 1461: =item h4
1462:
1463: =item i
1464:
1.180 matthew 1465: =item date
1466:
1467: =back
1468:
1469: Inputs: $workbook
1470:
1471: Returns: $format, a hash reference.
1472:
1473: =cut
1474:
1475: ###############################################################
1476: ###############################################################
1477: sub define_excel_formats {
1478: my ($workbook) = @_;
1479: my $format;
1480: $format->{'header'} = $workbook->add_format(bold => 1,
1481: bottom => 1,
1482: align => 'center');
1483: $format->{'bold'} = $workbook->add_format(bold=>1);
1484: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1485: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1486: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1487: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1488: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1489: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1490: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1491: return $format;
1492: }
1493:
1494: ###############################################################
1495: ###############################################################
1.113 bowersj2 1496:
1497: =pod
1498:
1.648 raeburn 1499: =item * &create_workbook()
1.255 matthew 1500:
1501: Create an Excel worksheet. If it fails, output message on the
1502: request object and return undefs.
1503:
1504: Inputs: Apache request object
1505:
1506: Returns (undef) on failure,
1507: Excel worksheet object, scalar with filename, and formats
1508: from &Apache::loncommon::define_excel_formats on success
1509:
1510: =cut
1511:
1512: ###############################################################
1513: ###############################################################
1514: sub create_workbook {
1515: my ($r) = @_;
1516: #
1517: # Create the excel spreadsheet
1518: my $filename = '/prtspool/'.
1.258 albertel 1519: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1520: time.'_'.rand(1000000000).'.xls';
1521: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1522: if (! defined($workbook)) {
1523: $r->log_error("Error creating excel spreadsheet $filename: $!");
1524: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1525: "This error has been logged. ".
1526: "Please alert your LON-CAPA administrator").
1527: '</p>');
1528: return (undef);
1529: }
1530: #
1531: $workbook->set_tempdir('/home/httpd/perl/tmp');
1532: #
1533: my $format = &Apache::loncommon::define_excel_formats($workbook);
1534: return ($workbook,$filename,$format);
1535: }
1536:
1537: ###############################################################
1538: ###############################################################
1539:
1540: =pod
1541:
1.648 raeburn 1542: =item * &create_text_file()
1.113 bowersj2 1543:
1.542 raeburn 1544: Create a file to write to and eventually make available to the user.
1.256 matthew 1545: If file creation fails, outputs an error message on the request object and
1546: return undefs.
1.113 bowersj2 1547:
1.256 matthew 1548: Inputs: Apache request object, and file suffix
1.113 bowersj2 1549:
1.256 matthew 1550: Returns (undef) on failure,
1551: Filehandle and filename on success.
1.113 bowersj2 1552:
1553: =cut
1554:
1.256 matthew 1555: ###############################################################
1556: ###############################################################
1557: sub create_text_file {
1558: my ($r,$suffix) = @_;
1559: if (! defined($suffix)) { $suffix = 'txt'; };
1560: my $fh;
1561: my $filename = '/prtspool/'.
1.258 albertel 1562: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1563: time.'_'.rand(1000000000).'.'.$suffix;
1564: $fh = Apache::File->new('>/home/httpd'.$filename);
1565: if (! defined($fh)) {
1566: $r->log_error("Couldn't open $filename for output $!");
1.683 bisitz 1567: $r->print(&mt('Problems occurred in creating the output file. '
1568: .'This error has been logged. '
1569: .'Please alert your LON-CAPA administrator.'));
1.113 bowersj2 1570: }
1.256 matthew 1571: return ($fh,$filename)
1.113 bowersj2 1572: }
1573:
1574:
1.256 matthew 1575: =pod
1.113 bowersj2 1576:
1577: =back
1578:
1579: =cut
1.37 matthew 1580:
1581: ###############################################################
1.33 matthew 1582: ## Home server <option> list generating code ##
1583: ###############################################################
1.35 matthew 1584:
1.169 www 1585: # ------------------------------------------
1586:
1587: sub domain_select {
1588: my ($name,$value,$multiple)=@_;
1589: my %domains=map {
1.514 albertel 1590: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1591: } &Apache::lonnet::all_domains();
1.169 www 1592: if ($multiple) {
1593: $domains{''}=&mt('Any domain');
1.550 albertel 1594: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1595: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1596: } else {
1.550 albertel 1597: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1598: return &select_form($name,$value,%domains);
1599: }
1600: }
1601:
1.282 albertel 1602: #-------------------------------------------
1603:
1604: =pod
1605:
1.519 raeburn 1606: =head1 Routines for form select boxes
1607:
1608: =over 4
1609:
1.648 raeburn 1610: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1611:
1612: Returns a string containing a <select> element int multiple mode
1613:
1614:
1615: Args:
1616: $name - name of the <select> element
1.506 raeburn 1617: $value - scalar or array ref of values that should already be selected
1.282 albertel 1618: $size - number of rows long the select element is
1.283 albertel 1619: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1620: (shown text should already have been &mt())
1.506 raeburn 1621: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1622:
1.282 albertel 1623: =cut
1624:
1625: #-------------------------------------------
1.169 www 1626: sub multiple_select_form {
1.284 albertel 1627: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1628: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1629: my $output='';
1.191 matthew 1630: if (! defined($size)) {
1631: $size = 4;
1.283 albertel 1632: if (scalar(keys(%$hash))<4) {
1633: $size = scalar(keys(%$hash));
1.191 matthew 1634: }
1635: }
1.734 bisitz 1636: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1637: my @order;
1.506 raeburn 1638: if (ref($order) eq 'ARRAY') {
1639: @order = @{$order};
1640: } else {
1641: @order = sort(keys(%$hash));
1.501 banghart 1642: }
1643: if (exists($$hash{'select_form_order'})) {
1644: @order = @{$$hash{'select_form_order'}};
1645: }
1646:
1.284 albertel 1647: foreach my $key (@order) {
1.356 albertel 1648: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1649: $output.='selected="selected" ' if ($selected{$key});
1650: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1651: }
1652: $output.="</select>\n";
1653: return $output;
1654: }
1655:
1.88 www 1656: #-------------------------------------------
1657:
1658: =pod
1659:
1.648 raeburn 1660: =item * &select_form($defdom,$name,%hash)
1.88 www 1661:
1662: Returns a string containing a <select name='$name' size='1'> form to
1663: allow a user to select options from a hash option_name => displayed text.
1664: See lonrights.pm for an example invocation and use.
1665:
1666: =cut
1667:
1668: #-------------------------------------------
1669: sub select_form {
1670: my ($def,$name,%hash) = @_;
1671: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1672: my @keys;
1673: if (exists($hash{'select_form_order'})) {
1674: @keys=@{$hash{'select_form_order'}};
1675: } else {
1676: @keys=sort(keys(%hash));
1677: }
1.356 albertel 1678: foreach my $key (@keys) {
1679: $selectform.=
1680: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1681: ($key eq $def ? 'selected="selected" ' : '').
1682: ">".&mt($hash{$key})."</option>\n";
1.88 www 1683: }
1684: $selectform.="</select>";
1685: return $selectform;
1686: }
1687:
1.475 www 1688: # For display filters
1689:
1690: sub display_filter {
1691: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1692: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714 bisitz 1693: return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475 www 1694: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1695: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 1696: '</label></span> <span class="LC_nobreak">'.
1.475 www 1697: &mt('Filter [_1]',
1.477 www 1698: &select_form($env{'form.displayfilter'},
1699: 'displayfilter',
1700: ('currentfolder' => 'Current folder/page',
1701: 'containing' => 'Containing phrase',
1702: 'none' => 'None'))).
1.714 bisitz 1703: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475 www 1704: }
1705:
1.167 www 1706: sub gradeleveldescription {
1707: my $gradelevel=shift;
1708: my %gradelevels=(0 => 'Not specified',
1709: 1 => 'Grade 1',
1710: 2 => 'Grade 2',
1711: 3 => 'Grade 3',
1712: 4 => 'Grade 4',
1713: 5 => 'Grade 5',
1714: 6 => 'Grade 6',
1715: 7 => 'Grade 7',
1716: 8 => 'Grade 8',
1717: 9 => 'Grade 9',
1718: 10 => 'Grade 10',
1719: 11 => 'Grade 11',
1720: 12 => 'Grade 12',
1721: 13 => 'Grade 13',
1722: 14 => '100 Level',
1723: 15 => '200 Level',
1724: 16 => '300 Level',
1725: 17 => '400 Level',
1726: 18 => 'Graduate Level');
1727: return &mt($gradelevels{$gradelevel});
1728: }
1729:
1.163 www 1730: sub select_level_form {
1731: my ($deflevel,$name)=@_;
1732: unless ($deflevel) { $deflevel=0; }
1.167 www 1733: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1734: for (my $i=0; $i<=18; $i++) {
1735: $selectform.="<option value=\"$i\" ".
1.253 albertel 1736: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1737: ">".&gradeleveldescription($i)."</option>\n";
1738: }
1739: $selectform.="</select>";
1740: return $selectform;
1.163 www 1741: }
1.167 www 1742:
1.35 matthew 1743: #-------------------------------------------
1744:
1.45 matthew 1745: =pod
1746:
1.743 raeburn 1747: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35 matthew 1748:
1749: Returns a string containing a <select name='$name' size='1'> form to
1750: allow a user to select the domain to preform an operation in.
1751: See loncreateuser.pm for an example invocation and use.
1752:
1.90 www 1753: If the $includeempty flag is set, it also includes an empty choice ("no domain
1754: selected");
1755:
1.743 raeburn 1756: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1757:
1758: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.
1.563 raeburn 1759:
1.35 matthew 1760: =cut
1761:
1762: #-------------------------------------------
1.34 matthew 1763: sub select_dom_form {
1.743 raeburn 1764: my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
1765: my $onchange;
1766: if ($autosubmit) {
1767: $onchange = ' onchange="this.form.submit()"';
1768: }
1.550 albertel 1769: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1770: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 1771: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 1772: foreach my $dom (@domains) {
1773: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1774: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1775: if ($showdomdesc) {
1776: if ($dom ne '') {
1777: my $domdesc = &Apache::lonnet::domain($dom,'description');
1778: if ($domdesc ne '') {
1779: $selectdomain .= ' ('.$domdesc.')';
1780: }
1781: }
1782: }
1783: $selectdomain .= "</option>\n";
1.34 matthew 1784: }
1785: $selectdomain.="</select>";
1786: return $selectdomain;
1787: }
1788:
1.35 matthew 1789: #-------------------------------------------
1790:
1.45 matthew 1791: =pod
1792:
1.648 raeburn 1793: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1794:
1.586 raeburn 1795: input: 4 arguments (two required, two optional) -
1796: $domain - domain of new user
1797: $name - name of form element
1798: $default - Value of 'default' causes a default item to be first
1799: option, and selected by default.
1800: $hide - Value of 'hide' causes hiding of the name of the server,
1801: if 1 server found, or default, if 0 found.
1.594 raeburn 1802: output: returns 2 items:
1.586 raeburn 1803: (a) form element which contains either:
1804: (i) <select name="$name">
1805: <option value="$hostid1">$hostid $servers{$hostid}</option>
1806: <option value="$hostid2">$hostid $servers{$hostid}</option>
1807: </select>
1808: form item if there are multiple library servers in $domain, or
1809: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1810: if there is only one library server in $domain.
1811:
1812: (b) number of library servers found.
1813:
1814: See loncreateuser.pm for example of use.
1.35 matthew 1815:
1816: =cut
1817:
1818: #-------------------------------------------
1.586 raeburn 1819: sub home_server_form_item {
1820: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1821: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1822: my $result;
1823: my $numlib = keys(%servers);
1824: if ($numlib > 1) {
1825: $result .= '<select name="'.$name.'" />'."\n";
1826: if ($default) {
1827: $result .= '<option value="default" selected>'.&mt('default').
1828: '</option>'."\n";
1829: }
1830: foreach my $hostid (sort(keys(%servers))) {
1831: $result.= '<option value="'.$hostid.'">'.
1832: $hostid.' '.$servers{$hostid}."</option>\n";
1833: }
1834: $result .= '</select>'."\n";
1835: } elsif ($numlib == 1) {
1836: my $hostid;
1837: foreach my $item (keys(%servers)) {
1838: $hostid = $item;
1839: }
1840: $result .= '<input type="hidden" name="'.$name.'" value="'.
1841: $hostid.'" />';
1842: if (!$hide) {
1843: $result .= $hostid.' '.$servers{$hostid};
1844: }
1845: $result .= "\n";
1846: } elsif ($default) {
1847: $result .= '<input type="hidden" name="'.$name.
1848: '" value="default" />';
1849: if (!$hide) {
1850: $result .= &mt('default');
1851: }
1852: $result .= "\n";
1.33 matthew 1853: }
1.586 raeburn 1854: return ($result,$numlib);
1.33 matthew 1855: }
1.112 bowersj2 1856:
1857: =pod
1858:
1.534 albertel 1859: =back
1860:
1.112 bowersj2 1861: =cut
1.87 matthew 1862:
1863: ###############################################################
1.112 bowersj2 1864: ## Decoding User Agent ##
1.87 matthew 1865: ###############################################################
1866:
1867: =pod
1868:
1.112 bowersj2 1869: =head1 Decoding the User Agent
1870:
1871: =over 4
1872:
1873: =item * &decode_user_agent()
1.87 matthew 1874:
1875: Inputs: $r
1876:
1877: Outputs:
1878:
1879: =over 4
1880:
1.112 bowersj2 1881: =item * $httpbrowser
1.87 matthew 1882:
1.112 bowersj2 1883: =item * $clientbrowser
1.87 matthew 1884:
1.112 bowersj2 1885: =item * $clientversion
1.87 matthew 1886:
1.112 bowersj2 1887: =item * $clientmathml
1.87 matthew 1888:
1.112 bowersj2 1889: =item * $clientunicode
1.87 matthew 1890:
1.112 bowersj2 1891: =item * $clientos
1.87 matthew 1892:
1893: =back
1894:
1.157 matthew 1895: =back
1896:
1.87 matthew 1897: =cut
1898:
1899: ###############################################################
1900: ###############################################################
1901: sub decode_user_agent {
1.247 albertel 1902: my ($r)=@_;
1.87 matthew 1903: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1904: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1905: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1906: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1907: my $clientbrowser='unknown';
1908: my $clientversion='0';
1909: my $clientmathml='';
1910: my $clientunicode='0';
1911: for (my $i=0;$i<=$#browsertype;$i++) {
1912: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1913: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1914: $clientbrowser=$bname;
1915: $httpbrowser=~/$vreg/i;
1916: $clientversion=$1;
1917: $clientmathml=($clientversion>=$minv);
1918: $clientunicode=($clientversion>=$univ);
1919: }
1920: }
1921: my $clientos='unknown';
1922: if (($httpbrowser=~/linux/i) ||
1923: ($httpbrowser=~/unix/i) ||
1924: ($httpbrowser=~/ux/i) ||
1925: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1926: if (($httpbrowser=~/vax/i) ||
1927: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1928: if ($httpbrowser=~/next/i) { $clientos='next'; }
1929: if (($httpbrowser=~/mac/i) ||
1930: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1931: if ($httpbrowser=~/win/i) { $clientos='win'; }
1932: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1933: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1934: $clientunicode,$clientos,);
1935: }
1936:
1.32 matthew 1937: ###############################################################
1938: ## Authentication changing form generation subroutines ##
1939: ###############################################################
1940: ##
1941: ## All of the authform_xxxxxxx subroutines take their inputs in a
1942: ## hash, and have reasonable default values.
1943: ##
1944: ## formname = the name given in the <form> tag.
1.35 matthew 1945: #-------------------------------------------
1946:
1.45 matthew 1947: =pod
1948:
1.112 bowersj2 1949: =head1 Authentication Routines
1950:
1951: =over 4
1952:
1.648 raeburn 1953: =item * &authform_xxxxxx()
1.35 matthew 1954:
1955: The authform_xxxxxx subroutines provide javascript and html forms which
1956: handle some of the conveniences required for authentication forms.
1957: This is not an optimal method, but it works.
1958:
1959: =over 4
1960:
1.112 bowersj2 1961: =item * authform_header
1.35 matthew 1962:
1.112 bowersj2 1963: =item * authform_authorwarning
1.35 matthew 1964:
1.112 bowersj2 1965: =item * authform_nochange
1.35 matthew 1966:
1.112 bowersj2 1967: =item * authform_kerberos
1.35 matthew 1968:
1.112 bowersj2 1969: =item * authform_internal
1.35 matthew 1970:
1.112 bowersj2 1971: =item * authform_filesystem
1.35 matthew 1972:
1973: =back
1974:
1.648 raeburn 1975: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1976:
1.35 matthew 1977: =cut
1978:
1979: #-------------------------------------------
1.32 matthew 1980: sub authform_header{
1981: my %in = (
1982: formname => 'cu',
1.80 albertel 1983: kerb_def_dom => '',
1.32 matthew 1984: @_,
1985: );
1986: $in{'formname'} = 'document.' . $in{'formname'};
1987: my $result='';
1.80 albertel 1988:
1989: #---------------------------------------------- Code for upper case translation
1990: my $Javascript_toUpperCase;
1991: unless ($in{kerb_def_dom}) {
1992: $Javascript_toUpperCase =<<"END";
1993: switch (choice) {
1994: case 'krb': currentform.elements[choicearg].value =
1995: currentform.elements[choicearg].value.toUpperCase();
1996: break;
1997: default:
1998: }
1999: END
2000: } else {
2001: $Javascript_toUpperCase = "";
2002: }
2003:
1.165 raeburn 2004: my $radioval = "'nochange'";
1.591 raeburn 2005: if (defined($in{'curr_authtype'})) {
2006: if ($in{'curr_authtype'} ne '') {
2007: $radioval = "'".$in{'curr_authtype'}."arg'";
2008: }
1.174 matthew 2009: }
1.165 raeburn 2010: my $argfield = 'null';
1.591 raeburn 2011: if (defined($in{'mode'})) {
1.165 raeburn 2012: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2013: if (defined($in{'curr_autharg'})) {
2014: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2015: $argfield = "'$in{'curr_autharg'}'";
2016: }
2017: }
2018: }
2019: }
2020:
1.32 matthew 2021: $result.=<<"END";
2022: var current = new Object();
1.165 raeburn 2023: current.radiovalue = $radioval;
2024: current.argfield = $argfield;
1.32 matthew 2025:
2026: function changed_radio(choice,currentform) {
2027: var choicearg = choice + 'arg';
2028: // If a radio button in changed, we need to change the argfield
2029: if (current.radiovalue != choice) {
2030: current.radiovalue = choice;
2031: if (current.argfield != null) {
2032: currentform.elements[current.argfield].value = '';
2033: }
2034: if (choice == 'nochange') {
2035: current.argfield = null;
2036: } else {
2037: current.argfield = choicearg;
2038: switch(choice) {
2039: case 'krb':
2040: currentform.elements[current.argfield].value =
2041: "$in{'kerb_def_dom'}";
2042: break;
2043: default:
2044: break;
2045: }
2046: }
2047: }
2048: return;
2049: }
1.22 www 2050:
1.32 matthew 2051: function changed_text(choice,currentform) {
2052: var choicearg = choice + 'arg';
2053: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2054: $Javascript_toUpperCase
1.32 matthew 2055: // clear old field
2056: if ((current.argfield != choicearg) && (current.argfield != null)) {
2057: currentform.elements[current.argfield].value = '';
2058: }
2059: current.argfield = choicearg;
2060: }
2061: set_auth_radio_buttons(choice,currentform);
2062: return;
1.20 www 2063: }
1.32 matthew 2064:
2065: function set_auth_radio_buttons(newvalue,currentform) {
2066: var i=0;
2067: while (i < currentform.login.length) {
2068: if (currentform.login[i].value == newvalue) { break; }
2069: i++;
2070: }
2071: if (i == currentform.login.length) {
2072: return;
2073: }
2074: current.radiovalue = newvalue;
2075: currentform.login[i].checked = true;
2076: return;
2077: }
2078: END
2079: return $result;
2080: }
2081:
2082: sub authform_authorwarning{
2083: my $result='';
1.144 matthew 2084: $result='<i>'.
2085: &mt('As a general rule, only authors or co-authors should be '.
2086: 'filesystem authenticated '.
2087: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2088: return $result;
2089: }
2090:
2091: sub authform_nochange{
2092: my %in = (
2093: formname => 'document.cu',
2094: kerb_def_dom => 'MSU.EDU',
2095: @_,
2096: );
1.586 raeburn 2097: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2098: my $result;
2099: if (keys(%can_assign) == 0) {
2100: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2101: } else {
2102: $result = '<label>'.&mt('[_1] Do not change login data',
2103: '<input type="radio" name="login" value="nochange" '.
2104: 'checked="checked" onclick="'.
1.281 albertel 2105: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2106: '</label>';
1.586 raeburn 2107: }
1.32 matthew 2108: return $result;
2109: }
2110:
1.591 raeburn 2111: sub authform_kerberos {
1.32 matthew 2112: my %in = (
2113: formname => 'document.cu',
2114: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2115: kerb_def_auth => 'krb4',
1.32 matthew 2116: @_,
2117: );
1.586 raeburn 2118: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2119: $autharg,$jscall);
2120: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2121: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2122: $check5 = ' checked="on"';
1.80 albertel 2123: } else {
1.586 raeburn 2124: $check4 = ' checked="on"';
1.80 albertel 2125: }
1.165 raeburn 2126: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2127: if (defined($in{'curr_authtype'})) {
2128: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2129: $krbcheck = ' checked="on"';
1.623 raeburn 2130: if (defined($in{'mode'})) {
2131: if ($in{'mode'} eq 'modifyuser') {
2132: $krbcheck = '';
2133: }
2134: }
1.591 raeburn 2135: if (defined($in{'curr_kerb_ver'})) {
2136: if ($in{'curr_krb_ver'} eq '5') {
2137: $check5 = ' checked="on"';
2138: $check4 = '';
2139: } else {
2140: $check4 = ' checked="on"';
2141: $check5 = '';
2142: }
1.586 raeburn 2143: }
1.591 raeburn 2144: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2145: $krbarg = $in{'curr_autharg'};
2146: }
1.586 raeburn 2147: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2148: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2149: $result =
2150: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2151: $in{'curr_autharg'},$krbver);
2152: } else {
2153: $result =
2154: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2155: }
2156: return $result;
2157: }
2158: }
2159: } else {
2160: if ($authnum == 1) {
2161: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2162: }
2163: }
1.586 raeburn 2164: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2165: return;
1.587 raeburn 2166: } elsif ($authtype eq '') {
1.591 raeburn 2167: if (defined($in{'mode'})) {
1.587 raeburn 2168: if ($in{'mode'} eq 'modifycourse') {
2169: if ($authnum == 1) {
2170: $authtype = '<input type="hidden" name="login" value="krb">';
2171: }
2172: }
2173: }
1.586 raeburn 2174: }
2175: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2176: if ($authtype eq '') {
2177: $authtype = '<input type="radio" name="login" value="krb" '.
2178: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2179: $krbcheck.' />';
2180: }
2181: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2182: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2183: $in{'curr_authtype'} eq 'krb5') ||
2184: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2185: $in{'curr_authtype'} eq 'krb4')) {
2186: $result .= &mt
1.144 matthew 2187: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2188: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2189: '<label>'.$authtype,
1.281 albertel 2190: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2191: 'value="'.$krbarg.'" '.
1.144 matthew 2192: 'onchange="'.$jscall.'" />',
1.281 albertel 2193: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2194: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2195: '</label>');
1.586 raeburn 2196: } elsif ($can_assign{'krb4'}) {
2197: $result .= &mt
2198: ('[_1] Kerberos authenticated with domain [_2] '.
2199: '[_3] Version 4 [_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="4" />',
2205: '</label>');
2206: } elsif ($can_assign{'krb5'}) {
2207: $result .= &mt
2208: ('[_1] Kerberos authenticated with domain [_2] '.
2209: '[_3] Version 5 [_4]',
2210: '<label>'.$authtype,
2211: '</label><input type="text" size="10" name="krbarg" '.
2212: 'value="'.$krbarg.'" '.
2213: 'onchange="'.$jscall.'" />',
2214: '<label><input type="hidden" name="krbver" value="5" />',
2215: '</label>');
2216: }
1.32 matthew 2217: return $result;
2218: }
2219:
2220: sub authform_internal{
1.586 raeburn 2221: my %in = (
1.32 matthew 2222: formname => 'document.cu',
2223: kerb_def_dom => 'MSU.EDU',
2224: @_,
2225: );
1.586 raeburn 2226: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2227: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2228: if (defined($in{'curr_authtype'})) {
2229: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2230: if ($can_assign{'int'}) {
2231: $intcheck = 'checked="on" ';
1.623 raeburn 2232: if (defined($in{'mode'})) {
2233: if ($in{'mode'} eq 'modifyuser') {
2234: $intcheck = '';
2235: }
2236: }
1.591 raeburn 2237: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2238: $intarg = $in{'curr_autharg'};
2239: }
2240: } else {
2241: $result = &mt('Currently internally authenticated.');
2242: return $result;
1.165 raeburn 2243: }
2244: }
1.586 raeburn 2245: } else {
2246: if ($authnum == 1) {
2247: $authtype = '<input type="hidden" name="login" value="int">';
2248: }
2249: }
2250: if (!$can_assign{'int'}) {
2251: return;
1.587 raeburn 2252: } elsif ($authtype eq '') {
1.591 raeburn 2253: if (defined($in{'mode'})) {
1.587 raeburn 2254: if ($in{'mode'} eq 'modifycourse') {
2255: if ($authnum == 1) {
2256: $authtype = '<input type="hidden" name="login" value="int">';
2257: }
2258: }
2259: }
1.165 raeburn 2260: }
1.586 raeburn 2261: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2262: if ($authtype eq '') {
2263: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2264: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2265: }
1.605 bisitz 2266: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2267: $intarg.'" onchange="'.$jscall.'" />';
2268: $result = &mt
1.144 matthew 2269: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2270: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2271: $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 2272: return $result;
2273: }
2274:
2275: sub authform_local{
2276: my %in = (
2277: formname => 'document.cu',
2278: kerb_def_dom => 'MSU.EDU',
2279: @_,
2280: );
1.586 raeburn 2281: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2282: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2283: if (defined($in{'curr_authtype'})) {
2284: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2285: if ($can_assign{'loc'}) {
2286: $loccheck = 'checked="on" ';
1.623 raeburn 2287: if (defined($in{'mode'})) {
2288: if ($in{'mode'} eq 'modifyuser') {
2289: $loccheck = '';
2290: }
2291: }
1.591 raeburn 2292: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2293: $locarg = $in{'curr_autharg'};
2294: }
2295: } else {
2296: $result = &mt('Currently using local (institutional) authentication.');
2297: return $result;
1.165 raeburn 2298: }
2299: }
1.586 raeburn 2300: } else {
2301: if ($authnum == 1) {
2302: $authtype = '<input type="hidden" name="login" value="loc">';
2303: }
2304: }
2305: if (!$can_assign{'loc'}) {
2306: return;
1.587 raeburn 2307: } elsif ($authtype eq '') {
1.591 raeburn 2308: if (defined($in{'mode'})) {
1.587 raeburn 2309: if ($in{'mode'} eq 'modifycourse') {
2310: if ($authnum == 1) {
2311: $authtype = '<input type="hidden" name="login" value="loc">';
2312: }
2313: }
2314: }
1.165 raeburn 2315: }
1.586 raeburn 2316: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2317: if ($authtype eq '') {
2318: $authtype = '<input type="radio" name="login" value="loc" '.
2319: $loccheck.' onchange="'.$jscall.'" onclick="'.
2320: $jscall.'" />';
2321: }
2322: $autharg = '<input type="text" size="10" name="locarg" value="'.
2323: $locarg.'" onchange="'.$jscall.'" />';
2324: $result = &mt('[_1] Local Authentication with argument [_2]',
2325: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2326: return $result;
2327: }
2328:
2329: sub authform_filesystem{
2330: my %in = (
2331: formname => 'document.cu',
2332: kerb_def_dom => 'MSU.EDU',
2333: @_,
2334: );
1.586 raeburn 2335: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2336: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2337: if (defined($in{'curr_authtype'})) {
2338: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2339: if ($can_assign{'fsys'}) {
2340: $fsyscheck = 'checked="on" ';
1.623 raeburn 2341: if (defined($in{'mode'})) {
2342: if ($in{'mode'} eq 'modifyuser') {
2343: $fsyscheck = '';
2344: }
2345: }
1.586 raeburn 2346: } else {
2347: $result = &mt('Currently Filesystem Authenticated.');
2348: return $result;
2349: }
2350: }
2351: } else {
2352: if ($authnum == 1) {
2353: $authtype = '<input type="hidden" name="login" value="fsys">';
2354: }
2355: }
2356: if (!$can_assign{'fsys'}) {
2357: return;
1.587 raeburn 2358: } elsif ($authtype eq '') {
1.591 raeburn 2359: if (defined($in{'mode'})) {
1.587 raeburn 2360: if ($in{'mode'} eq 'modifycourse') {
2361: if ($authnum == 1) {
2362: $authtype = '<input type="hidden" name="login" value="fsys">';
2363: }
2364: }
2365: }
1.586 raeburn 2366: }
2367: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2368: if ($authtype eq '') {
2369: $authtype = '<input type="radio" name="login" value="fsys" '.
2370: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2371: $jscall.'" />';
2372: }
2373: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2374: ' onchange="'.$jscall.'" />';
2375: $result = &mt
1.144 matthew 2376: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2377: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2378: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2379: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2380: 'onchange="'.$jscall.'" />');
1.32 matthew 2381: return $result;
2382: }
2383:
1.586 raeburn 2384: sub get_assignable_auth {
2385: my ($dom) = @_;
2386: if ($dom eq '') {
2387: $dom = $env{'request.role.domain'};
2388: }
2389: my %can_assign = (
2390: krb4 => 1,
2391: krb5 => 1,
2392: int => 1,
2393: loc => 1,
2394: );
2395: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2396: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2397: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2398: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2399: my $context;
2400: if ($env{'request.role'} =~ /^au/) {
2401: $context = 'author';
2402: } elsif ($env{'request.role'} =~ /^dc/) {
2403: $context = 'domain';
2404: } elsif ($env{'request.course.id'}) {
2405: $context = 'course';
2406: }
2407: if ($context) {
2408: if (ref($authhash->{$context}) eq 'HASH') {
2409: %can_assign = %{$authhash->{$context}};
2410: }
2411: }
2412: }
2413: }
2414: my $authnum = 0;
2415: foreach my $key (keys(%can_assign)) {
2416: if ($can_assign{$key}) {
2417: $authnum ++;
2418: }
2419: }
2420: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2421: $authnum --;
2422: }
2423: return ($authnum,%can_assign);
2424: }
2425:
1.80 albertel 2426: ###############################################################
2427: ## Get Kerberos Defaults for Domain ##
2428: ###############################################################
2429: ##
2430: ## Returns default kerberos version and an associated argument
2431: ## as listed in file domain.tab. If not listed, provides
2432: ## appropriate default domain and kerberos version.
2433: ##
2434: #-------------------------------------------
2435:
2436: =pod
2437:
1.648 raeburn 2438: =item * &get_kerberos_defaults()
1.80 albertel 2439:
2440: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2441: version and domain. If not found, it defaults to version 4 and the
2442: domain of the server.
1.80 albertel 2443:
1.648 raeburn 2444: =over 4
2445:
1.80 albertel 2446: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2447:
1.648 raeburn 2448: =back
2449:
2450: =back
2451:
1.80 albertel 2452: =cut
2453:
2454: #-------------------------------------------
2455: sub get_kerberos_defaults {
2456: my $domain=shift;
1.641 raeburn 2457: my ($krbdef,$krbdefdom);
2458: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2459: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2460: $krbdef = $domdefaults{'auth_def'};
2461: $krbdefdom = $domdefaults{'auth_arg_def'};
2462: } else {
1.80 albertel 2463: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2464: my $krbdefdom=$1;
2465: $krbdefdom=~tr/a-z/A-Z/;
2466: $krbdef = "krb4";
2467: }
2468: return ($krbdef,$krbdefdom);
2469: }
1.112 bowersj2 2470:
1.32 matthew 2471:
1.46 matthew 2472: ###############################################################
2473: ## Thesaurus Functions ##
2474: ###############################################################
1.20 www 2475:
1.46 matthew 2476: =pod
1.20 www 2477:
1.112 bowersj2 2478: =head1 Thesaurus Functions
2479:
2480: =over 4
2481:
1.648 raeburn 2482: =item * &initialize_keywords()
1.46 matthew 2483:
2484: Initializes the package variable %Keywords if it is empty. Uses the
2485: package variable $thesaurus_db_file.
2486:
2487: =cut
2488:
2489: ###################################################
2490:
2491: sub initialize_keywords {
2492: return 1 if (scalar keys(%Keywords));
2493: # If we are here, %Keywords is empty, so fill it up
2494: # Make sure the file we need exists...
2495: if (! -e $thesaurus_db_file) {
2496: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2497: " failed because it does not exist");
2498: return 0;
2499: }
2500: # Set up the hash as a database
2501: my %thesaurus_db;
2502: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2503: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2504: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2505: $thesaurus_db_file);
2506: return 0;
2507: }
2508: # Get the average number of appearances of a word.
2509: my $avecount = $thesaurus_db{'average.count'};
2510: # Put keywords (those that appear > average) into %Keywords
2511: while (my ($word,$data)=each (%thesaurus_db)) {
2512: my ($count,undef) = split /:/,$data;
2513: $Keywords{$word}++ if ($count > $avecount);
2514: }
2515: untie %thesaurus_db;
2516: # Remove special values from %Keywords.
1.356 albertel 2517: foreach my $value ('total.count','average.count') {
2518: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2519: }
1.46 matthew 2520: return 1;
2521: }
2522:
2523: ###################################################
2524:
2525: =pod
2526:
1.648 raeburn 2527: =item * &keyword($word)
1.46 matthew 2528:
2529: Returns true if $word is a keyword. A keyword is a word that appears more
2530: than the average number of times in the thesaurus database. Calls
2531: &initialize_keywords
2532:
2533: =cut
2534:
2535: ###################################################
1.20 www 2536:
2537: sub keyword {
1.46 matthew 2538: return if (!&initialize_keywords());
2539: my $word=lc(shift());
2540: $word=~s/\W//g;
2541: return exists($Keywords{$word});
1.20 www 2542: }
1.46 matthew 2543:
2544: ###############################################################
2545:
2546: =pod
1.20 www 2547:
1.648 raeburn 2548: =item * &get_related_words()
1.46 matthew 2549:
1.160 matthew 2550: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2551: an array of words. If the keyword is not in the thesaurus, an empty array
2552: will be returned. The order of the words returned is determined by the
2553: database which holds them.
2554:
2555: Uses global $thesaurus_db_file.
2556:
2557: =cut
2558:
2559: ###############################################################
2560: sub get_related_words {
2561: my $keyword = shift;
2562: my %thesaurus_db;
2563: if (! -e $thesaurus_db_file) {
2564: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2565: "failed because the file does not exist");
2566: return ();
2567: }
2568: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2569: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2570: return ();
2571: }
2572: my @Words=();
1.429 www 2573: my $count=0;
1.46 matthew 2574: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2575: # The first element is the number of times
2576: # the word appears. We do not need it now.
1.429 www 2577: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2578: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2579: my $threshold=$mostfrequentcount/10;
2580: foreach my $possibleword (@RelatedWords) {
2581: my ($word,$wordcount)=split(/\,/,$possibleword);
2582: if ($wordcount>$threshold) {
2583: push(@Words,$word);
2584: $count++;
2585: if ($count>10) { last; }
2586: }
1.20 www 2587: }
2588: }
1.46 matthew 2589: untie %thesaurus_db;
2590: return @Words;
1.14 harris41 2591: }
1.46 matthew 2592:
1.112 bowersj2 2593: =pod
2594:
2595: =back
2596:
2597: =cut
1.61 www 2598:
2599: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2600: =pod
2601:
1.112 bowersj2 2602: =head1 User Name Functions
2603:
2604: =over 4
2605:
1.648 raeburn 2606: =item * &plainname($uname,$udom,$first)
1.81 albertel 2607:
1.112 bowersj2 2608: Takes a users logon name and returns it as a string in
1.226 albertel 2609: "first middle last generation" form
2610: if $first is set to 'lastname' then it returns it as
2611: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2612:
2613: =cut
1.61 www 2614:
1.295 www 2615:
1.81 albertel 2616: ###############################################################
1.61 www 2617: sub plainname {
1.226 albertel 2618: my ($uname,$udom,$first)=@_;
1.537 albertel 2619: return if (!defined($uname) || !defined($udom));
1.295 www 2620: my %names=&getnames($uname,$udom);
1.226 albertel 2621: my $name=&Apache::lonnet::format_name($names{'firstname'},
2622: $names{'middlename'},
2623: $names{'lastname'},
2624: $names{'generation'},$first);
2625: $name=~s/^\s+//;
1.62 www 2626: $name=~s/\s+$//;
2627: $name=~s/\s+/ /g;
1.353 albertel 2628: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2629: return $name;
1.61 www 2630: }
1.66 www 2631:
2632: # -------------------------------------------------------------------- Nickname
1.81 albertel 2633: =pod
2634:
1.648 raeburn 2635: =item * &nickname($uname,$udom)
1.81 albertel 2636:
2637: Gets a users name and returns it as a string as
2638:
2639: ""nickname""
1.66 www 2640:
1.81 albertel 2641: if the user has a nickname or
2642:
2643: "first middle last generation"
2644:
2645: if the user does not
2646:
2647: =cut
1.66 www 2648:
2649: sub nickname {
2650: my ($uname,$udom)=@_;
1.537 albertel 2651: return if (!defined($uname) || !defined($udom));
1.295 www 2652: my %names=&getnames($uname,$udom);
1.68 albertel 2653: my $name=$names{'nickname'};
1.66 www 2654: if ($name) {
2655: $name='"'.$name.'"';
2656: } else {
2657: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2658: $names{'lastname'}.' '.$names{'generation'};
2659: $name=~s/\s+$//;
2660: $name=~s/\s+/ /g;
2661: }
2662: return $name;
2663: }
2664:
1.295 www 2665: sub getnames {
2666: my ($uname,$udom)=@_;
1.537 albertel 2667: return if (!defined($uname) || !defined($udom));
1.433 albertel 2668: if ($udom eq 'public' && $uname eq 'public') {
2669: return ('lastname' => &mt('Public'));
2670: }
1.295 www 2671: my $id=$uname.':'.$udom;
2672: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2673: if ($cached) {
2674: return %{$names};
2675: } else {
2676: my %loadnames=&Apache::lonnet::get('environment',
2677: ['firstname','middlename','lastname','generation','nickname'],
2678: $udom,$uname);
2679: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2680: return %loadnames;
2681: }
2682: }
1.61 www 2683:
1.542 raeburn 2684: # -------------------------------------------------------------------- getemails
1.648 raeburn 2685:
1.542 raeburn 2686: =pod
2687:
1.648 raeburn 2688: =item * &getemails($uname,$udom)
1.542 raeburn 2689:
2690: Gets a user's email information and returns it as a hash with keys:
2691: notification, critnotification, permanentemail
2692:
2693: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2694: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2695:
1.648 raeburn 2696:
1.542 raeburn 2697: =cut
2698:
1.648 raeburn 2699:
1.466 albertel 2700: sub getemails {
2701: my ($uname,$udom)=@_;
2702: if ($udom eq 'public' && $uname eq 'public') {
2703: return;
2704: }
1.467 www 2705: if (!$udom) { $udom=$env{'user.domain'}; }
2706: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2707: my $id=$uname.':'.$udom;
2708: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2709: if ($cached) {
2710: return %{$names};
2711: } else {
2712: my %loadnames=&Apache::lonnet::get('environment',
2713: ['notification','critnotification',
2714: 'permanentemail'],
2715: $udom,$uname);
2716: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2717: return %loadnames;
2718: }
2719: }
2720:
1.551 albertel 2721: sub flush_email_cache {
2722: my ($uname,$udom)=@_;
2723: if (!$udom) { $udom =$env{'user.domain'}; }
2724: if (!$uname) { $uname=$env{'user.name'}; }
2725: return if ($udom eq 'public' && $uname eq 'public');
2726: my $id=$uname.':'.$udom;
2727: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2728: }
2729:
1.728 raeburn 2730: # -------------------------------------------------------------------- getlangs
2731:
2732: =pod
2733:
2734: =item * &getlangs($uname,$udom)
2735:
2736: Gets a user's language preference and returns it as a hash with key:
2737: language.
2738:
2739: =cut
2740:
2741:
2742: sub getlangs {
2743: my ($uname,$udom) = @_;
2744: if (!$udom) { $udom =$env{'user.domain'}; }
2745: if (!$uname) { $uname=$env{'user.name'}; }
2746: my $id=$uname.':'.$udom;
2747: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
2748: if ($cached) {
2749: return %{$langs};
2750: } else {
2751: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
2752: $udom,$uname);
2753: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
2754: return %loadlangs;
2755: }
2756: }
2757:
2758: sub flush_langs_cache {
2759: my ($uname,$udom)=@_;
2760: if (!$udom) { $udom =$env{'user.domain'}; }
2761: if (!$uname) { $uname=$env{'user.name'}; }
2762: return if ($udom eq 'public' && $uname eq 'public');
2763: my $id=$uname.':'.$udom;
2764: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
2765: }
2766:
1.61 www 2767: # ------------------------------------------------------------------ Screenname
1.81 albertel 2768:
2769: =pod
2770:
1.648 raeburn 2771: =item * &screenname($uname,$udom)
1.81 albertel 2772:
2773: Gets a users screenname and returns it as a string
2774:
2775: =cut
1.61 www 2776:
2777: sub screenname {
2778: my ($uname,$udom)=@_;
1.258 albertel 2779: if ($uname eq $env{'user.name'} &&
2780: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2781: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2782: return $names{'screenname'};
1.62 www 2783: }
2784:
1.212 albertel 2785:
1.62 www 2786: # ------------------------------------------------------------- Message Wrapper
2787:
2788: sub messagewrapper {
1.369 www 2789: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2790: return
1.441 albertel 2791: '<a href="/adm/email?compose=individual&'.
2792: 'recname='.$username.'&recdom='.$domain.
2793: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2794: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2795: }
2796: # --------------------------------------------------------------- Notes Wrapper
2797:
2798: sub noteswrapper {
2799: my ($link,$un,$do)=@_;
2800: return
2801: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2802: }
2803: # ------------------------------------------------------------- Aboutme Wrapper
2804:
2805: sub aboutmewrapper {
1.166 www 2806: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2807: if (!defined($username) && !defined($domain)) {
2808: return;
2809: }
1.205 www 2810: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756 weissno 2811: ($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 2812: }
2813:
2814: # ------------------------------------------------------------ Syllabus Wrapper
2815:
2816:
2817: sub syllabuswrapper {
1.707 bisitz 2818: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 2819: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2820: }
1.14 harris41 2821:
1.208 matthew 2822: sub track_student_link {
1.268 albertel 2823: my ($linktext,$sname,$sdom,$target,$start) = @_;
2824: my $link ="/adm/trackstudent?";
1.208 matthew 2825: my $title = 'View recent activity';
2826: if (defined($sname) && $sname !~ /^\s*$/ &&
2827: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2828: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2829: $title .= ' of this student';
1.268 albertel 2830: }
1.208 matthew 2831: if (defined($target) && $target !~ /^\s*$/) {
2832: $target = qq{target="$target"};
2833: } else {
2834: $target = '';
2835: }
1.268 albertel 2836: if ($start) { $link.='&start='.$start; }
1.554 albertel 2837: $title = &mt($title);
2838: $linktext = &mt($linktext);
1.448 albertel 2839: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2840: &help_open_topic('View_recent_activity');
1.208 matthew 2841: }
2842:
1.508 www 2843: # ===================================================== Display a student photo
2844:
2845:
1.509 albertel 2846: sub student_image_tag {
1.508 www 2847: my ($domain,$user)=@_;
2848: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2849: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2850: return '<img src="'.$imgsrc.'" align="right" />';
2851: } else {
2852: return '';
2853: }
2854: }
2855:
1.112 bowersj2 2856: =pod
2857:
2858: =back
2859:
2860: =head1 Access .tab File Data
2861:
2862: =over 4
2863:
1.648 raeburn 2864: =item * &languageids()
1.112 bowersj2 2865:
2866: returns list of all language ids
2867:
2868: =cut
2869:
1.14 harris41 2870: sub languageids {
1.16 harris41 2871: return sort(keys(%language));
1.14 harris41 2872: }
2873:
1.112 bowersj2 2874: =pod
2875:
1.648 raeburn 2876: =item * &languagedescription()
1.112 bowersj2 2877:
2878: returns description of a specified language id
2879:
2880: =cut
2881:
1.14 harris41 2882: sub languagedescription {
1.125 www 2883: my $code=shift;
2884: return ($supported_language{$code}?'* ':'').
2885: $language{$code}.
1.126 www 2886: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2887: }
2888:
2889: sub plainlanguagedescription {
2890: my $code=shift;
2891: return $language{$code};
2892: }
2893:
2894: sub supportedlanguagecode {
2895: my $code=shift;
2896: return $supported_language{$code};
1.97 www 2897: }
2898:
1.112 bowersj2 2899: =pod
2900:
1.648 raeburn 2901: =item * ©rightids()
1.112 bowersj2 2902:
2903: returns list of all copyrights
2904:
2905: =cut
2906:
2907: sub copyrightids {
2908: return sort(keys(%cprtag));
2909: }
2910:
2911: =pod
2912:
1.648 raeburn 2913: =item * ©rightdescription()
1.112 bowersj2 2914:
2915: returns description of a specified copyright id
2916:
2917: =cut
2918:
2919: sub copyrightdescription {
1.166 www 2920: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2921: }
1.197 matthew 2922:
2923: =pod
2924:
1.648 raeburn 2925: =item * &source_copyrightids()
1.192 taceyjo1 2926:
2927: returns list of all source copyrights
2928:
2929: =cut
2930:
2931: sub source_copyrightids {
2932: return sort(keys(%scprtag));
2933: }
2934:
2935: =pod
2936:
1.648 raeburn 2937: =item * &source_copyrightdescription()
1.192 taceyjo1 2938:
2939: returns description of a specified source copyright id
2940:
2941: =cut
2942:
2943: sub source_copyrightdescription {
2944: return &mt($scprtag{shift(@_)});
2945: }
1.112 bowersj2 2946:
2947: =pod
2948:
1.648 raeburn 2949: =item * &filecategories()
1.112 bowersj2 2950:
2951: returns list of all file categories
2952:
2953: =cut
2954:
2955: sub filecategories {
2956: return sort(keys(%category_extensions));
2957: }
2958:
2959: =pod
2960:
1.648 raeburn 2961: =item * &filecategorytypes()
1.112 bowersj2 2962:
2963: returns list of file types belonging to a given file
2964: category
2965:
2966: =cut
2967:
2968: sub filecategorytypes {
1.356 albertel 2969: my ($cat) = @_;
2970: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2971: }
2972:
2973: =pod
2974:
1.648 raeburn 2975: =item * &fileembstyle()
1.112 bowersj2 2976:
2977: returns embedding style for a specified file type
2978:
2979: =cut
2980:
2981: sub fileembstyle {
2982: return $fe{lc(shift(@_))};
1.169 www 2983: }
2984:
1.351 www 2985: sub filemimetype {
2986: return $fm{lc(shift(@_))};
2987: }
2988:
1.169 www 2989:
2990: sub filecategoryselect {
2991: my ($name,$value)=@_;
1.189 matthew 2992: return &select_form($value,$name,
1.169 www 2993: '' => &mt('Any category'),
2994: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2995: }
2996:
2997: =pod
2998:
1.648 raeburn 2999: =item * &filedescription()
1.112 bowersj2 3000:
3001: returns description for a specified file type
3002:
3003: =cut
3004:
3005: sub filedescription {
1.188 matthew 3006: my $file_description = $fd{lc(shift())};
3007: $file_description =~ s:([\[\]]):~$1:g;
3008: return &mt($file_description);
1.112 bowersj2 3009: }
3010:
3011: =pod
3012:
1.648 raeburn 3013: =item * &filedescriptionex()
1.112 bowersj2 3014:
3015: returns description for a specified file type with
3016: extra formatting
3017:
3018: =cut
3019:
3020: sub filedescriptionex {
3021: my $ex=shift;
1.188 matthew 3022: my $file_description = $fd{lc($ex)};
3023: $file_description =~ s:([\[\]]):~$1:g;
3024: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3025: }
3026:
3027: # End of .tab access
3028: =pod
3029:
3030: =back
3031:
3032: =cut
3033:
3034: # ------------------------------------------------------------------ File Types
3035: sub fileextensions {
3036: return sort(keys(%fe));
3037: }
3038:
1.97 www 3039: # ----------------------------------------------------------- Display Languages
3040: # returns a hash with all desired display languages
3041: #
3042:
3043: sub display_languages {
3044: my %languages=();
1.695 raeburn 3045: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3046: $languages{$lang}=1;
1.97 www 3047: }
3048: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3049: if ($env{'form.displaylanguage'}) {
1.356 albertel 3050: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3051: $languages{$lang}=1;
1.97 www 3052: }
3053: }
3054: return %languages;
1.14 harris41 3055: }
3056:
1.582 albertel 3057: sub languages {
3058: my ($possible_langs) = @_;
1.695 raeburn 3059: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3060: if (!ref($possible_langs)) {
3061: if( wantarray ) {
3062: return @preferred_langs;
3063: } else {
3064: return $preferred_langs[0];
3065: }
3066: }
3067: my %possibilities = map { $_ => 1 } (@$possible_langs);
3068: my @preferred_possibilities;
3069: foreach my $preferred_lang (@preferred_langs) {
3070: if (exists($possibilities{$preferred_lang})) {
3071: push(@preferred_possibilities, $preferred_lang);
3072: }
3073: }
3074: if( wantarray ) {
3075: return @preferred_possibilities;
3076: }
3077: return $preferred_possibilities[0];
3078: }
3079:
1.742 raeburn 3080: sub user_lang {
3081: my ($touname,$toudom,$fromcid) = @_;
3082: my @userlangs;
3083: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3084: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3085: $env{'course.'.$fromcid.'.languages'}));
3086: } else {
3087: my %langhash = &getlangs($touname,$toudom);
3088: if ($langhash{'languages'} ne '') {
3089: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3090: } else {
3091: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3092: if ($domdefs{'lang_def'} ne '') {
3093: @userlangs = ($domdefs{'lang_def'});
3094: }
3095: }
3096: }
3097: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3098: my $user_lh = Apache::localize->get_handle(@languages);
3099: return $user_lh;
3100: }
3101:
3102:
1.112 bowersj2 3103: ###############################################################
3104: ## Student Answer Attempts ##
3105: ###############################################################
3106:
3107: =pod
3108:
3109: =head1 Alternate Problem Views
3110:
3111: =over 4
3112:
1.648 raeburn 3113: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3114: $getattempt, $regexp, $gradesub)
3115:
3116: Return string with previous attempt on problem. Arguments:
3117:
3118: =over 4
3119:
3120: =item * $symb: Problem, including path
3121:
3122: =item * $username: username of the desired student
3123:
3124: =item * $domain: domain of the desired student
1.14 harris41 3125:
1.112 bowersj2 3126: =item * $course: Course ID
1.14 harris41 3127:
1.112 bowersj2 3128: =item * $getattempt: Leave blank for all attempts, otherwise put
3129: something
1.14 harris41 3130:
1.112 bowersj2 3131: =item * $regexp: if string matches this regexp, the string will be
3132: sent to $gradesub
1.14 harris41 3133:
1.112 bowersj2 3134: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3135:
1.112 bowersj2 3136: =back
1.14 harris41 3137:
1.112 bowersj2 3138: The output string is a table containing all desired attempts, if any.
1.16 harris41 3139:
1.112 bowersj2 3140: =cut
1.1 albertel 3141:
3142: sub get_previous_attempt {
1.43 ng 3143: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3144: my $prevattempts='';
1.43 ng 3145: no strict 'refs';
1.1 albertel 3146: if ($symb) {
1.3 albertel 3147: my (%returnhash)=
3148: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3149: if ($returnhash{'version'}) {
3150: my %lasthash=();
3151: my $version;
3152: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3153: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3154: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3155: }
1.1 albertel 3156: }
1.596 albertel 3157: $prevattempts=&start_data_table().&start_data_table_header_row();
3158: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3159: foreach my $key (sort(keys(%lasthash))) {
3160: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3161: if ($#parts > 0) {
1.31 albertel 3162: my $data=$parts[-1];
3163: pop(@parts);
1.596 albertel 3164: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3165: } else {
1.41 ng 3166: if ($#parts == 0) {
3167: $prevattempts.='<th>'.$parts[0].'</th>';
3168: } else {
3169: $prevattempts.='<th>'.$ign.'</th>';
3170: }
1.31 albertel 3171: }
1.16 harris41 3172: }
1.596 albertel 3173: $prevattempts.=&end_data_table_header_row();
1.40 ng 3174: if ($getattempt eq '') {
3175: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3176: $prevattempts.=&start_data_table_row().
3177: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3178: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3179: my $value = &format_previous_attempt_value($key,
3180: $returnhash{$version.':'.$key});
3181: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3182: }
1.596 albertel 3183: $prevattempts.=&end_data_table_row();
1.40 ng 3184: }
1.1 albertel 3185: }
1.596 albertel 3186: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3187: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3188: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3189: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3190: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3191: }
1.596 albertel 3192: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3193: } else {
1.596 albertel 3194: $prevattempts=
3195: &start_data_table().&start_data_table_row().
3196: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3197: &end_data_table_row().&end_data_table();
1.1 albertel 3198: }
3199: } else {
1.596 albertel 3200: $prevattempts=
3201: &start_data_table().&start_data_table_row().
3202: '<td>'.&mt('No data.').'</td>'.
3203: &end_data_table_row().&end_data_table();
1.1 albertel 3204: }
1.10 albertel 3205: }
3206:
1.581 albertel 3207: sub format_previous_attempt_value {
3208: my ($key,$value) = @_;
3209: if ($key =~ /timestamp/) {
3210: $value = &Apache::lonlocal::locallocaltime($value);
3211: } elsif (ref($value) eq 'ARRAY') {
3212: $value = '('.join(', ', @{ $value }).')';
3213: } else {
3214: $value = &unescape($value);
3215: }
3216: return $value;
3217: }
3218:
3219:
1.107 albertel 3220: sub relative_to_absolute {
3221: my ($url,$output)=@_;
3222: my $parser=HTML::TokeParser->new(\$output);
3223: my $token;
3224: my $thisdir=$url;
3225: my @rlinks=();
3226: while ($token=$parser->get_token) {
3227: if ($token->[0] eq 'S') {
3228: if ($token->[1] eq 'a') {
3229: if ($token->[2]->{'href'}) {
3230: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3231: }
3232: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3233: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3234: } elsif ($token->[1] eq 'base') {
3235: $thisdir=$token->[2]->{'href'};
3236: }
3237: }
3238: }
3239: $thisdir=~s-/[^/]*$--;
1.356 albertel 3240: foreach my $link (@rlinks) {
1.726 raeburn 3241: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3242: ($link=~/^\//) ||
3243: ($link=~/^javascript:/i) ||
3244: ($link=~/^mailto:/i) ||
3245: ($link=~/^\#/)) {
3246: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3247: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3248: }
3249: }
3250: # -------------------------------------------------- Deal with Applet codebases
3251: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3252: return $output;
3253: }
3254:
1.112 bowersj2 3255: =pod
3256:
1.648 raeburn 3257: =item * &get_student_view()
1.112 bowersj2 3258:
3259: show a snapshot of what student was looking at
3260:
3261: =cut
3262:
1.10 albertel 3263: sub get_student_view {
1.186 albertel 3264: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3265: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3266: my (%form);
1.10 albertel 3267: my @elements=('symb','courseid','domain','username');
3268: foreach my $element (@elements) {
1.186 albertel 3269: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3270: }
1.186 albertel 3271: if (defined($moreenv)) {
3272: %form=(%form,%{$moreenv});
3273: }
1.236 albertel 3274: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3275: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3276: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3277: $userview=~s/\<body[^\>]*\>//gi;
3278: $userview=~s/\<\/body\>//gi;
3279: $userview=~s/\<html\>//gi;
3280: $userview=~s/\<\/html\>//gi;
3281: $userview=~s/\<head\>//gi;
3282: $userview=~s/\<\/head\>//gi;
3283: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3284: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3285: if (wantarray) {
3286: return ($userview,$response);
3287: } else {
3288: return $userview;
3289: }
3290: }
3291:
3292: sub get_student_view_with_retries {
3293: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3294:
3295: my $ok = 0; # True if we got a good response.
3296: my $content;
3297: my $response;
3298:
3299: # Try to get the student_view done. within the retries count:
3300:
3301: do {
3302: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3303: $ok = $response->is_success;
3304: if (!$ok) {
3305: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3306: }
3307: $retries--;
3308: } while (!$ok && ($retries > 0));
3309:
3310: if (!$ok) {
3311: $content = ''; # On error return an empty content.
3312: }
1.651 www 3313: if (wantarray) {
3314: return ($content, $response);
3315: } else {
3316: return $content;
3317: }
1.11 albertel 3318: }
3319:
1.112 bowersj2 3320: =pod
3321:
1.648 raeburn 3322: =item * &get_student_answers()
1.112 bowersj2 3323:
3324: show a snapshot of how student was answering problem
3325:
3326: =cut
3327:
1.11 albertel 3328: sub get_student_answers {
1.100 sakharuk 3329: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3330: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3331: my (%moreenv);
1.11 albertel 3332: my @elements=('symb','courseid','domain','username');
3333: foreach my $element (@elements) {
1.186 albertel 3334: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3335: }
1.186 albertel 3336: $moreenv{'grade_target'}='answer';
3337: %moreenv=(%form,%moreenv);
1.497 raeburn 3338: $feedurl = &Apache::lonnet::clutter($feedurl);
3339: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3340: return $userview;
1.1 albertel 3341: }
1.116 albertel 3342:
3343: =pod
3344:
3345: =item * &submlink()
3346:
1.242 albertel 3347: Inputs: $text $uname $udom $symb $target
1.116 albertel 3348:
3349: Returns: A link to grades.pm such as to see the SUBM view of a student
3350:
3351: =cut
3352:
3353: ###############################################
3354: sub submlink {
1.242 albertel 3355: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3356: if (!($uname && $udom)) {
3357: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3358: &Apache::lonnet::whichuser($symb);
1.116 albertel 3359: if (!$symb) { $symb=$cursymb; }
3360: }
1.254 matthew 3361: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3362: $symb=&escape($symb);
1.242 albertel 3363: if ($target) { $target="target=\"$target\""; }
3364: return '<a href="/adm/grades?&command=submission&'.
3365: 'symb='.$symb.'&student='.$uname.
3366: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3367: }
3368: ##############################################
3369:
3370: =pod
3371:
3372: =item * &pgrdlink()
3373:
3374: Inputs: $text $uname $udom $symb $target
3375:
3376: Returns: A link to grades.pm such as to see the PGRD view of a student
3377:
3378: =cut
3379:
3380: ###############################################
3381: sub pgrdlink {
3382: my $link=&submlink(@_);
3383: $link=~s/(&command=submission)/$1&showgrading=yes/;
3384: return $link;
3385: }
3386: ##############################################
3387:
3388: =pod
3389:
3390: =item * &pprmlink()
3391:
3392: Inputs: $text $uname $udom $symb $target
3393:
3394: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3395: student and a specific resource
1.242 albertel 3396:
3397: =cut
3398:
3399: ###############################################
3400: sub pprmlink {
3401: my ($text,$uname,$udom,$symb,$target)=@_;
3402: if (!($uname && $udom)) {
3403: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3404: &Apache::lonnet::whichuser($symb);
1.242 albertel 3405: if (!$symb) { $symb=$cursymb; }
3406: }
1.254 matthew 3407: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3408: $symb=&escape($symb);
1.242 albertel 3409: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3410: return '<a href="/adm/parmset?command=set&'.
3411: 'symb='.$symb.'&uname='.$uname.
3412: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3413: }
3414: ##############################################
1.37 matthew 3415:
1.112 bowersj2 3416: =pod
3417:
3418: =back
3419:
3420: =cut
3421:
1.37 matthew 3422: ###############################################
1.51 www 3423:
3424:
3425: sub timehash {
1.687 raeburn 3426: my ($thistime) = @_;
3427: my $timezone = &Apache::lonlocal::gettimezone();
3428: my $dt = DateTime->from_epoch(epoch => $thistime)
3429: ->set_time_zone($timezone);
3430: my $wday = $dt->day_of_week();
3431: if ($wday == 7) { $wday = 0; }
3432: return ( 'second' => $dt->second(),
3433: 'minute' => $dt->minute(),
3434: 'hour' => $dt->hour(),
3435: 'day' => $dt->day_of_month(),
3436: 'month' => $dt->month(),
3437: 'year' => $dt->year(),
3438: 'weekday' => $wday,
3439: 'dayyear' => $dt->day_of_year(),
3440: 'dlsav' => $dt->is_dst() );
1.51 www 3441: }
3442:
1.370 www 3443: sub utc_string {
3444: my ($date)=@_;
1.371 www 3445: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3446: }
3447:
1.51 www 3448: sub maketime {
3449: my %th=@_;
1.687 raeburn 3450: my ($epoch_time,$timezone,$dt);
3451: $timezone = &Apache::lonlocal::gettimezone();
3452: eval {
3453: $dt = DateTime->new( year => $th{'year'},
3454: month => $th{'month'},
3455: day => $th{'day'},
3456: hour => $th{'hour'},
3457: minute => $th{'minute'},
3458: second => $th{'second'},
3459: time_zone => $timezone,
3460: );
3461: };
3462: if (!$@) {
3463: $epoch_time = $dt->epoch;
3464: if ($epoch_time) {
3465: return $epoch_time;
3466: }
3467: }
1.51 www 3468: return POSIX::mktime(
3469: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3470: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3471: }
3472:
3473: #########################################
1.51 www 3474:
3475: sub findallcourses {
1.482 raeburn 3476: my ($roles,$uname,$udom) = @_;
1.355 albertel 3477: my %roles;
3478: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3479: my %courses;
1.51 www 3480: my $now=time;
1.482 raeburn 3481: if (!defined($uname)) {
3482: $uname = $env{'user.name'};
3483: }
3484: if (!defined($udom)) {
3485: $udom = $env{'user.domain'};
3486: }
3487: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3488: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3489: if (!%roles) {
3490: %roles = (
3491: cc => 1,
3492: in => 1,
3493: ep => 1,
3494: ta => 1,
3495: cr => 1,
3496: st => 1,
3497: );
3498: }
3499: foreach my $entry (keys(%roleshash)) {
3500: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3501: if ($trole =~ /^cr/) {
3502: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3503: } else {
3504: next if (!exists($roles{$trole}));
3505: }
3506: if ($tend) {
3507: next if ($tend < $now);
3508: }
3509: if ($tstart) {
3510: next if ($tstart > $now);
3511: }
3512: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3513: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3514: if ($secpart eq '') {
3515: ($cnum,$role) = split(/_/,$cnumpart);
3516: $sec = 'none';
3517: $realsec = '';
3518: } else {
3519: $cnum = $cnumpart;
3520: ($sec,$role) = split(/_/,$secpart);
3521: $realsec = $sec;
1.490 raeburn 3522: }
1.482 raeburn 3523: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3524: }
3525: } else {
3526: foreach my $key (keys(%env)) {
1.483 albertel 3527: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3528: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3529: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3530: next if ($role eq 'ca' || $role eq 'aa');
3531: next if (%roles && !exists($roles{$role}));
3532: my ($starttime,$endtime)=split(/\./,$env{$key});
3533: my $active=1;
3534: if ($starttime) {
3535: if ($now<$starttime) { $active=0; }
3536: }
3537: if ($endtime) {
3538: if ($now>$endtime) { $active=0; }
3539: }
3540: if ($active) {
3541: if ($sec eq '') {
3542: $sec = 'none';
3543: }
3544: $courses{$cdom.'_'.$cnum}{$sec} =
3545: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3546: }
3547: }
1.51 www 3548: }
3549: }
1.474 raeburn 3550: return %courses;
1.51 www 3551: }
1.37 matthew 3552:
1.54 www 3553: ###############################################
1.474 raeburn 3554:
3555: sub blockcheck {
1.482 raeburn 3556: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3557:
3558: if (!defined($udom)) {
3559: $udom = $env{'user.domain'};
3560: }
3561: if (!defined($uname)) {
3562: $uname = $env{'user.name'};
3563: }
3564:
3565: # If uname and udom are for a course, check for blocks in the course.
3566:
3567: if (&Apache::lonnet::is_course($udom,$uname)) {
3568: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3569: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3570: return ($startblock,$endblock);
3571: }
1.474 raeburn 3572:
1.502 raeburn 3573: my $startblock = 0;
3574: my $endblock = 0;
1.482 raeburn 3575: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3576:
1.490 raeburn 3577: # If uname is for a user, and activity is course-specific, i.e.,
3578: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3579:
1.490 raeburn 3580: if (($activity eq 'boards' || $activity eq 'chat' ||
3581: $activity eq 'groups') && ($env{'request.course.id'})) {
3582: foreach my $key (keys(%live_courses)) {
3583: if ($key ne $env{'request.course.id'}) {
3584: delete($live_courses{$key});
3585: }
3586: }
3587: }
3588:
3589: my $otheruser = 0;
3590: my %own_courses;
3591: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3592: # Resource belongs to user other than current user.
3593: $otheruser = 1;
3594: # Gather courses for current user
3595: %own_courses =
3596: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3597: }
3598:
3599: # Gather active course roles - course coordinator, instructor,
3600: # exam proctor, ta, student, or custom role.
1.474 raeburn 3601:
3602: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3603: my ($cdom,$cnum);
3604: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3605: $cdom = $env{'course.'.$course.'.domain'};
3606: $cnum = $env{'course.'.$course.'.num'};
3607: } else {
1.490 raeburn 3608: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3609: }
3610: my $no_ownblock = 0;
3611: my $no_userblock = 0;
1.533 raeburn 3612: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3613: # Check if current user has 'evb' priv for this
3614: if (defined($own_courses{$course})) {
3615: foreach my $sec (keys(%{$own_courses{$course}})) {
3616: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3617: if ($sec ne 'none') {
3618: $checkrole .= '/'.$sec;
3619: }
3620: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3621: $no_ownblock = 1;
3622: last;
3623: }
3624: }
3625: }
3626: # if they have 'evb' priv and are currently not playing student
3627: next if (($no_ownblock) &&
3628: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3629: }
1.474 raeburn 3630: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3631: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3632: if ($sec ne 'none') {
1.482 raeburn 3633: $checkrole .= '/'.$sec;
1.474 raeburn 3634: }
1.490 raeburn 3635: if ($otheruser) {
3636: # Resource belongs to user other than current user.
3637: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3638: my ($trole,$tdom,$tnum,$tsec);
3639: my $entry = $live_courses{$course}{$sec};
3640: if ($entry =~ /^cr/) {
3641: ($trole,$tdom,$tnum,$tsec) =
3642: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3643: } else {
3644: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3645: }
3646: my ($spec,$area,$trest,%allroles,%userroles);
3647: $area = '/'.$tdom.'/'.$tnum;
3648: $trest = $tnum;
3649: if ($tsec ne '') {
3650: $area .= '/'.$tsec;
3651: $trest .= '/'.$tsec;
3652: }
3653: $spec = $trole.'.'.$area;
3654: if ($trole =~ /^cr/) {
3655: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3656: $tdom,$spec,$trest,$area);
3657: } else {
3658: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3659: $tdom,$spec,$trest,$area);
3660: }
3661: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3662: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3663: if ($1) {
3664: $no_userblock = 1;
3665: last;
3666: }
3667: }
1.490 raeburn 3668: } else {
3669: # Resource belongs to current user
3670: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3671: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3672: $no_ownblock = 1;
3673: last;
3674: }
1.474 raeburn 3675: }
3676: }
3677: # if they have the evb priv and are currently not playing student
1.482 raeburn 3678: next if (($no_ownblock) &&
1.491 albertel 3679: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3680: next if ($no_userblock);
1.474 raeburn 3681:
1.490 raeburn 3682: # Retrieve blocking times and identity of blocker for course
3683: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3684:
3685: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3686: if (($start != 0) &&
3687: (($startblock == 0) || ($startblock > $start))) {
3688: $startblock = $start;
3689: }
3690: if (($end != 0) &&
3691: (($endblock == 0) || ($endblock < $end))) {
3692: $endblock = $end;
3693: }
1.490 raeburn 3694: }
3695: return ($startblock,$endblock);
3696: }
3697:
3698: sub get_blocks {
3699: my ($setters,$activity,$cdom,$cnum) = @_;
3700: my $startblock = 0;
3701: my $endblock = 0;
3702: my $course = $cdom.'_'.$cnum;
3703: $setters->{$course} = {};
3704: $setters->{$course}{'staff'} = [];
3705: $setters->{$course}{'times'} = [];
3706: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3707: foreach my $record (keys(%records)) {
3708: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3709: if ($start <= time && $end >= time) {
3710: my ($staff_name,$staff_dom,$title,$blocks) =
3711: &parse_block_record($records{$record});
3712: if ($blocks->{$activity} eq 'on') {
3713: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3714: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3715: if ( ($startblock == 0) || ($startblock > $start) ) {
3716: $startblock = $start;
1.490 raeburn 3717: }
1.491 albertel 3718: if ( ($endblock == 0) || ($endblock < $end) ) {
3719: $endblock = $end;
1.474 raeburn 3720: }
3721: }
3722: }
3723: }
3724: return ($startblock,$endblock);
3725: }
3726:
3727: sub parse_block_record {
3728: my ($record) = @_;
3729: my ($setuname,$setudom,$title,$blocks);
3730: if (ref($record) eq 'HASH') {
3731: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3732: $title = &unescape($record->{'event'});
3733: $blocks = $record->{'blocks'};
3734: } else {
3735: my @data = split(/:/,$record,3);
3736: if (scalar(@data) eq 2) {
3737: $title = $data[1];
3738: ($setuname,$setudom) = split(/@/,$data[0]);
3739: } else {
3740: ($setuname,$setudom,$title) = @data;
3741: }
3742: $blocks = { 'com' => 'on' };
3743: }
3744: return ($setuname,$setudom,$title,$blocks);
3745: }
3746:
3747: sub build_block_table {
3748: my ($startblock,$endblock,$setters) = @_;
3749: my %lt = &Apache::lonlocal::texthash(
3750: 'cacb' => 'Currently active communication blocks',
3751: 'cour' => 'Course',
3752: 'dura' => 'Duration',
3753: 'blse' => 'Block set by'
3754: );
3755: my $output;
1.476 raeburn 3756: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3757: $output .= &start_data_table();
3758: $output .= '
3759: <tr>
3760: <th>'.$lt{'cour'}.'</th>
3761: <th>'.$lt{'dura'}.'</th>
3762: <th>'.$lt{'blse'}.'</th>
3763: </tr>
3764: ';
3765: foreach my $course (keys(%{$setters})) {
3766: my %courseinfo=&Apache::lonnet::coursedescription($course);
3767: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3768: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3769: my $fullname = &plainname($uname,$udom);
3770: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3771: && $env{'user.name'} ne 'public'
3772: && $env{'user.domain'} ne 'public') {
3773: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3774: }
1.474 raeburn 3775: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3776: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3777: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3778: $output .= &Apache::loncommon::start_data_table_row().
3779: '<td>'.$courseinfo{'description'}.'</td>'.
3780: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3781: '<td>'.$fullname.'</td>'.
1.474 raeburn 3782: &Apache::loncommon::end_data_table_row();
3783: }
3784: }
3785: $output .= &end_data_table();
3786: }
3787:
1.490 raeburn 3788: sub blocking_status {
3789: my ($activity,$uname,$udom) = @_;
3790: my %setters;
3791: my ($blocked,$output,$ownitem,$is_course);
3792: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3793: if ($startblock && $endblock) {
3794: $blocked = 1;
3795: if (wantarray) {
3796: my $category;
3797: if ($activity eq 'boards') {
3798: $category = 'Discussion posts in this course';
3799: } elsif ($activity eq 'blogs') {
3800: $category = 'Blogs';
3801: } elsif ($activity eq 'port') {
3802: if (defined($uname) && defined($udom)) {
3803: if ($uname eq $env{'user.name'} &&
3804: $udom eq $env{'user.domain'}) {
3805: $ownitem = 1;
3806: }
3807: }
3808: $is_course = &Apache::lonnet::is_course($udom,$uname);
3809: if ($ownitem) {
3810: $category = 'Your portfolio files';
3811: } elsif ($is_course) {
3812: my $coursedesc;
3813: foreach my $course (keys(%setters)) {
3814: my %courseinfo =
3815: &Apache::lonnet::coursedescription($course);
3816: $coursedesc = $courseinfo{'description'};
3817: }
3818: $category = "Group files in the course '$coursedesc'";
3819: } else {
3820: $category = 'Portfolio files belonging to ';
3821: if ($env{'user.name'} eq 'public' &&
3822: $env{'user.domain'} eq 'public') {
3823: $category .= &plainname($uname,$udom);
3824: } else {
3825: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3826: }
3827: }
3828: } elsif ($activity eq 'groups') {
3829: $category = 'Groups in this course';
3830: }
3831: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3832: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3833: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3834: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3835: $output .= &build_block_table($startblock,$endblock,\%setters);
3836: }
3837: }
3838: }
3839: if (wantarray) {
3840: return ($blocked,$output);
3841: } else {
3842: return $blocked;
3843: }
3844: }
3845:
1.60 matthew 3846: ###############################################
3847:
1.682 raeburn 3848: sub check_ip_acc {
3849: my ($acc)=@_;
3850: &Apache::lonxml::debug("acc is $acc");
3851: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
3852: return 1;
3853: }
3854: my $allowed=0;
3855: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
3856:
3857: my $name;
3858: foreach my $pattern (split(',',$acc)) {
3859: $pattern =~ s/^\s*//;
3860: $pattern =~ s/\s*$//;
3861: if ($pattern =~ /\*$/) {
3862: #35.8.*
3863: $pattern=~s/\*//;
3864: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3865: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
3866: #35.8.3.[34-56]
3867: my $low=$2;
3868: my $high=$3;
3869: $pattern=$1;
3870: if ($ip =~ /^\Q$pattern\E/) {
3871: my $last=(split(/\./,$ip))[3];
3872: if ($last <=$high && $last >=$low) { $allowed=1; }
3873: }
3874: } elsif ($pattern =~ /^\*/) {
3875: #*.msu.edu
3876: $pattern=~s/\*//;
3877: if (!defined($name)) {
3878: use Socket;
3879: my $netaddr=inet_aton($ip);
3880: ($name)=gethostbyaddr($netaddr,AF_INET);
3881: }
3882: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3883: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
3884: #127.0.0.1
3885: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
3886: } else {
3887: #some.name.com
3888: if (!defined($name)) {
3889: use Socket;
3890: my $netaddr=inet_aton($ip);
3891: ($name)=gethostbyaddr($netaddr,AF_INET);
3892: }
3893: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
3894: }
3895: if ($allowed) { last; }
3896: }
3897: return $allowed;
3898: }
3899:
3900: ###############################################
3901:
1.60 matthew 3902: =pod
3903:
1.112 bowersj2 3904: =head1 Domain Template Functions
3905:
3906: =over 4
3907:
3908: =item * &determinedomain()
1.60 matthew 3909:
3910: Inputs: $domain (usually will be undef)
3911:
1.63 www 3912: Returns: Determines which domain should be used for designs
1.60 matthew 3913:
3914: =cut
1.54 www 3915:
1.60 matthew 3916: ###############################################
1.63 www 3917: sub determinedomain {
3918: my $domain=shift;
1.531 albertel 3919: if (! $domain) {
1.60 matthew 3920: # Determine domain if we have not been given one
3921: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3922: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3923: if ($env{'request.role.domain'}) {
3924: $domain=$env{'request.role.domain'};
1.60 matthew 3925: }
3926: }
1.63 www 3927: return $domain;
3928: }
3929: ###############################################
1.517 raeburn 3930:
1.518 albertel 3931: sub devalidate_domconfig_cache {
3932: my ($udom)=@_;
3933: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3934: }
3935:
3936: # ---------------------- Get domain configuration for a domain
3937: sub get_domainconf {
3938: my ($udom) = @_;
3939: my $cachetime=1800;
3940: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3941: if (defined($cached)) { return %{$result}; }
3942:
3943: my %domconfig = &Apache::lonnet::get_dom('configuration',
3944: ['login','rolecolors'],$udom);
1.632 raeburn 3945: my (%designhash,%legacy);
1.518 albertel 3946: if (keys(%domconfig) > 0) {
3947: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3948: if (keys(%{$domconfig{'login'}})) {
3949: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 3950: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
3951: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
3952: $designhash{$udom.'.login.'.$key.'_'.$img} =
3953: $domconfig{'login'}{$key}{$img};
3954: }
3955: } else {
3956: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3957: }
1.632 raeburn 3958: }
3959: } else {
3960: $legacy{'login'} = 1;
1.518 albertel 3961: }
1.632 raeburn 3962: } else {
3963: $legacy{'login'} = 1;
1.518 albertel 3964: }
3965: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3966: if (keys(%{$domconfig{'rolecolors'}})) {
3967: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3968: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3969: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3970: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3971: }
1.518 albertel 3972: }
3973: }
1.632 raeburn 3974: } else {
3975: $legacy{'rolecolors'} = 1;
1.518 albertel 3976: }
1.632 raeburn 3977: } else {
3978: $legacy{'rolecolors'} = 1;
1.518 albertel 3979: }
1.632 raeburn 3980: if (keys(%legacy) > 0) {
3981: my %legacyhash = &get_legacy_domconf($udom);
3982: foreach my $item (keys(%legacyhash)) {
3983: if ($item =~ /^\Q$udom\E\.login/) {
3984: if ($legacy{'login'}) {
3985: $designhash{$item} = $legacyhash{$item};
3986: }
3987: } else {
3988: if ($legacy{'rolecolors'}) {
3989: $designhash{$item} = $legacyhash{$item};
3990: }
1.518 albertel 3991: }
3992: }
3993: }
1.632 raeburn 3994: } else {
3995: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3996: }
3997: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3998: $cachetime);
3999: return %designhash;
4000: }
4001:
1.632 raeburn 4002: sub get_legacy_domconf {
4003: my ($udom) = @_;
4004: my %legacyhash;
4005: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4006: my $designfile = $designdir.'/'.$udom.'.tab';
4007: if (-e $designfile) {
4008: if ( open (my $fh,"<$designfile") ) {
4009: while (my $line = <$fh>) {
4010: next if ($line =~ /^\#/);
4011: chomp($line);
4012: my ($key,$val)=(split(/\=/,$line));
4013: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4014: }
4015: close($fh);
4016: }
4017: }
4018: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
4019: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4020: }
4021: return %legacyhash;
4022: }
4023:
1.63 www 4024: =pod
4025:
1.112 bowersj2 4026: =item * &domainlogo()
1.63 www 4027:
4028: Inputs: $domain (usually will be undef)
4029:
4030: Returns: A link to a domain logo, if the domain logo exists.
4031: If the domain logo does not exist, a description of the domain.
4032:
4033: =cut
1.112 bowersj2 4034:
1.63 www 4035: ###############################################
4036: sub domainlogo {
1.517 raeburn 4037: my $domain = &determinedomain(shift);
1.518 albertel 4038: my %designhash = &get_domainconf($domain);
1.517 raeburn 4039: # See if there is a logo
4040: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4041: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4042: if ($imgsrc =~ m{^/(adm|res)/}) {
4043: if ($imgsrc =~ m{^/res/}) {
4044: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4045: &Apache::lonnet::repcopy($local_name);
4046: }
4047: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4048: }
4049: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4050: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4051: return &Apache::lonnet::domain($domain,'description');
1.59 www 4052: } else {
1.60 matthew 4053: return '';
1.59 www 4054: }
4055: }
1.63 www 4056: ##############################################
4057:
4058: =pod
4059:
1.112 bowersj2 4060: =item * &designparm()
1.63 www 4061:
4062: Inputs: $which parameter; $domain (usually will be undef)
4063:
4064: Returns: value of designparamter $which
4065:
4066: =cut
1.112 bowersj2 4067:
1.397 albertel 4068:
1.400 albertel 4069: ##############################################
1.397 albertel 4070: sub designparm {
4071: my ($which,$domain)=@_;
1.258 albertel 4072: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 4073: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 4074: return '#000000';
4075: }
1.635 raeburn 4076: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 4077: return '#FFFFFF';
4078: }
4079: if ($which=~/\.tabbg$/) {
4080: return '#CCCCCC';
4081: }
4082: }
1.397 albertel 4083: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 4084: return $env{'environment.color.'.$which};
1.96 www 4085: }
1.63 www 4086: $domain=&determinedomain($domain);
1.518 albertel 4087: my %domdesign = &get_domainconf($domain);
1.520 raeburn 4088: my $output;
1.517 raeburn 4089: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 4090: $output = $domdesign{$domain.'.'.$which};
1.63 www 4091: } else {
1.520 raeburn 4092: $output = $defaultdesign{$which};
4093: }
4094: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4095: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4096: if ($output =~ m{^/(adm|res)/}) {
4097: if ($output =~ m{^/res/}) {
4098: my $local_name = &Apache::lonnet::filelocation('',$output);
4099: &Apache::lonnet::repcopy($local_name);
4100: }
1.520 raeburn 4101: $output = &lonhttpdurl($output);
4102: }
1.63 www 4103: }
1.520 raeburn 4104: return $output;
1.63 www 4105: }
1.59 www 4106:
1.60 matthew 4107: ###############################################
4108: ###############################################
4109:
4110: =pod
4111:
1.112 bowersj2 4112: =back
4113:
1.549 albertel 4114: =head1 HTML Helpers
1.112 bowersj2 4115:
4116: =over 4
4117:
4118: =item * &bodytag()
1.60 matthew 4119:
4120: Returns a uniform header for LON-CAPA web pages.
4121:
4122: Inputs:
4123:
1.112 bowersj2 4124: =over 4
4125:
4126: =item * $title, A title to be displayed on the page.
4127:
4128: =item * $function, the current role (can be undef).
4129:
4130: =item * $addentries, extra parameters for the <body> tag.
4131:
4132: =item * $bodyonly, if defined, only return the <body> tag.
4133:
4134: =item * $domain, if defined, force a given domain.
4135:
4136: =item * $forcereg, if page should register as content page (relevant for
1.86 www 4137: text interface only)
1.60 matthew 4138:
1.326 albertel 4139: =item * $customtitle, alternate text to use instead of $title
4140: in the title box that appears, this text
4141: is not auto translated like the $title is
1.309 albertel 4142:
4143: =item * $notopbar, if true, keep the 'what is this' info but remove the
4144: navigational links
1.317 albertel 4145:
1.338 albertel 4146: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
4147:
4148: =item * $notitle, if true keep the nav controls, but remove the title bar
4149:
1.361 albertel 4150: =item * $no_inline_link, if true and in remote mode, don't show the
4151: 'Switch To Inline Menu' link
4152:
1.460 albertel 4153: =item * $args, optional argument valid values are
4154: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 4155: inherit_jsmath -> when creating popup window in a page,
4156: should it have jsmath forced on by the
4157: current page
1.460 albertel 4158:
1.112 bowersj2 4159: =back
4160:
1.60 matthew 4161: Returns: A uniform header for LON-CAPA web pages.
4162: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
4163: If $bodyonly is undef or zero, an html string containing a <body> tag and
4164: other decorations will be returned.
4165:
4166: =cut
4167:
1.54 www 4168: sub bodytag {
1.309 albertel 4169: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4170: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4171:
1.460 albertel 4172: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4173:
1.183 matthew 4174: $function = &get_users_function() if (!$function);
1.339 albertel 4175: my $img = &designparm($function.'.img',$domain);
4176: my $font = &designparm($function.'.font',$domain);
4177: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4178:
4179: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4180: 'bgcolor' => $pgbg,
1.339 albertel 4181: 'text' => $font,
4182: 'alink' => &designparm($function.'.alink',$domain),
4183: 'vlink' => &designparm($function.'.vlink',$domain),
4184: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4185: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4186:
1.63 www 4187: # role and realm
1.378 raeburn 4188: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4189: if ($role eq 'ca') {
1.479 albertel 4190: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4191: $realm = &plainname($rname,$rdom);
1.378 raeburn 4192: }
1.55 www 4193: # realm
1.258 albertel 4194: if ($env{'request.course.id'}) {
1.378 raeburn 4195: if ($env{'request.role'} !~ /^cr/) {
4196: $role = &Apache::lonnet::plaintext($role,&course_type());
4197: }
1.359 albertel 4198: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4199: } else {
4200: $role = &Apache::lonnet::plaintext($role);
1.54 www 4201: }
1.433 albertel 4202:
1.359 albertel 4203: if (!$realm) { $realm=' '; }
1.55 www 4204: # Set messages
1.60 matthew 4205: my $messages=&domainlogo($domain);
1.330 albertel 4206:
1.438 albertel 4207: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4208:
1.101 www 4209: # construct main body tag
1.359 albertel 4210: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4211: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4212:
1.530 albertel 4213: if ($bodyonly) {
1.60 matthew 4214: return $bodytag;
1.258 albertel 4215: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4216: # Accessibility
1.224 raeburn 4217:
1.337 albertel 4218: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4219: if (!$notitle) {
1.337 albertel 4220: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4221: }
4222: return $bodytag;
1.359 albertel 4223: }
4224:
1.410 albertel 4225: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4226: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4227: undef($role);
1.434 albertel 4228: } else {
4229: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4230: }
1.359 albertel 4231:
4232: my $roleinfo=(<<ENDROLE);
4233: <td class="LC_title_bar_who">
4234: <div class="LC_title_bar_name">
1.410 albertel 4235: $name
1.361 albertel 4236:
1.359 albertel 4237: </div>
4238: <div class="LC_title_bar_role">
1.361 albertel 4239: $role
1.359 albertel 4240: </div>
4241: <div class="LC_title_bar_realm">
1.361 albertel 4242: $realm
1.359 albertel 4243: </div>
1.206 albertel 4244: </td>
4245: ENDROLE
1.235 raeburn 4246:
1.359 albertel 4247: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4248: if ($customtitle) {
4249: $titleinfo = $customtitle;
4250: }
4251: #
4252: # Extra info if you are the DC
4253: my $dc_info = '';
4254: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4255: $env{'course.'.$env{'request.course.id'}.
4256: '.domain'}.'/'})) {
4257: my $cid = $env{'request.course.id'};
4258: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4259: $dc_info =~ s/\s+$//;
1.359 albertel 4260: $dc_info = '('.$dc_info.')';
4261: }
4262:
1.644 www 4263: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4264: # No Remote
1.258 albertel 4265: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4266: $forcereg=1;
4267: }
4268:
4269: if (!$customtitle && $env{'request.state'} eq 'construct') {
4270: # this is for resources; directories have customtitle, and crumbs
4271: # and select recent are created in lonpubdir.pm
1.229 albertel 4272: my ($uname,$thisdisfn)=
1.258 albertel 4273: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4274: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4275: $formaction=~s/\/+/\//g;
4276:
1.359 albertel 4277: my $parentpath = '';
4278: my $lastitem = '';
4279: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4280: $parentpath = $1;
4281: $lastitem = $2;
4282: } else {
4283: $lastitem = $thisdisfn;
4284: }
4285: $titleinfo =
1.640 bisitz 4286: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4287: .'<b>'.&mt('Construction Space').'</b>: '
4288: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4289: .'" target="_top"><tt><b>'
1.705 tempelho 4290: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359 albertel 4291: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4292: .'</form>'
4293: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4294: }
1.359 albertel 4295:
1.337 albertel 4296: my $titletable;
1.338 albertel 4297: if (!$notitle) {
1.337 albertel 4298: $titletable =
1.359 albertel 4299: '<table id="LC_title_bar">'.
4300: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4301: '</tr></table>';
1.337 albertel 4302: }
1.359 albertel 4303: if ($notopbar) {
4304: $bodytag .= $titletable;
4305: } else {
4306: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4307: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4308: $titletable);
1.272 raeburn 4309: } else {
1.336 albertel 4310: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4311: $titletable;
1.272 raeburn 4312: }
1.235 raeburn 4313: }
4314: return $bodytag;
1.94 www 4315: }
1.95 www 4316:
1.93 www 4317: #
1.95 www 4318: # Top frame rendering, Remote is up
1.93 www 4319: #
1.359 albertel 4320:
1.517 raeburn 4321: my $imgsrc = $img;
4322: if ($img =~ /^\/adm/) {
1.575 albertel 4323: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4324: }
4325: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4326:
1.305 www 4327: # Explicit link to get inline menu
1.361 albertel 4328: my $menu= ($no_inline_link?''
4329: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4330: #
1.338 albertel 4331: if ($notitle) {
1.337 albertel 4332: return $bodytag;
4333: }
1.94 www 4334: return(<<ENDBODY);
1.60 matthew 4335: $bodytag
1.359 albertel 4336: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4337: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4338: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4339: </tr>
1.359 albertel 4340: <tr><td>$titleinfo $dc_info $menu</td>
4341: $roleinfo
1.368 albertel 4342: </tr>
1.356 albertel 4343: </table>
1.54 www 4344: ENDBODY
1.182 matthew 4345: }
4346:
1.330 albertel 4347: sub make_attr_string {
4348: my ($register,$attr_ref) = @_;
4349:
4350: if ($attr_ref && !ref($attr_ref)) {
4351: die("addentries Must be a hash ref ".
4352: join(':',caller(1))." ".
4353: join(':',caller(0))." ");
4354: }
4355:
4356: if ($register) {
1.339 albertel 4357: my ($on_load,$on_unload);
4358: foreach my $key (keys(%{$attr_ref})) {
4359: if (lc($key) eq 'onload') {
4360: $on_load.=$attr_ref->{$key}.';';
4361: delete($attr_ref->{$key});
4362:
4363: } elsif (lc($key) eq 'onunload') {
4364: $on_unload.=$attr_ref->{$key}.';';
4365: delete($attr_ref->{$key});
4366: }
4367: }
4368: $attr_ref->{'onload'} =
4369: &Apache::lonmenu::loadevents(). $on_load;
4370: $attr_ref->{'onunload'}=
4371: &Apache::lonmenu::unloadevents().$on_unload;
4372: }
4373:
4374: # Accessibility font enhance
4375: if ($env{'browser.fontenhance'} eq 'on') {
4376: my $style;
4377: foreach my $key (keys(%{$attr_ref})) {
4378: if (lc($key) eq 'style') {
4379: $style.=$attr_ref->{$key}.';';
4380: delete($attr_ref->{$key});
4381: }
4382: }
4383: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4384: }
1.339 albertel 4385:
4386: if ($env{'browser.blackwhite'} eq 'on') {
4387: delete($attr_ref->{'font'});
4388: delete($attr_ref->{'link'});
4389: delete($attr_ref->{'alink'});
4390: delete($attr_ref->{'vlink'});
4391: delete($attr_ref->{'bgcolor'});
4392: delete($attr_ref->{'background'});
4393: }
4394:
1.330 albertel 4395: my $attr_string;
4396: foreach my $attr (keys(%$attr_ref)) {
4397: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4398: }
4399: return $attr_string;
4400: }
4401:
4402:
1.182 matthew 4403: ###############################################
1.251 albertel 4404: ###############################################
4405:
4406: =pod
4407:
4408: =item * &endbodytag()
4409:
4410: Returns a uniform footer for LON-CAPA web pages.
4411:
1.635 raeburn 4412: Inputs: 1 - optional reference to an args hash
4413: If in the hash, key for noredirectlink has a value which evaluates to true,
4414: a 'Continue' link is not displayed if the page contains an
4415: internal redirect in the <head></head> section,
4416: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4417:
4418: =cut
4419:
4420: sub endbodytag {
1.635 raeburn 4421: my ($args) = @_;
1.251 albertel 4422: my $endbodytag='</body>';
1.269 albertel 4423: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4424: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4425: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4426: $endbodytag=
4427: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4428: &mt('Continue').'</a>'.
4429: $endbodytag;
4430: }
1.315 albertel 4431: }
1.251 albertel 4432: return $endbodytag;
4433: }
4434:
1.352 albertel 4435: =pod
4436:
4437: =item * &standard_css()
4438:
4439: Returns a style sheet
4440:
4441: Inputs: (all optional)
4442: domain -> force to color decorate a page for a specific
4443: domain
4444: function -> force usage of a specific rolish color scheme
4445: bgcolor -> override the default page bgcolor
4446:
4447: =cut
4448:
1.343 albertel 4449: sub standard_css {
1.345 albertel 4450: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4451: $function = &get_users_function() if (!$function);
4452: my $img = &designparm($function.'.img', $domain);
4453: my $tabbg = &designparm($function.'.tabbg', $domain);
4454: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4455: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4456: my $pgbg_or_bgcolor =
4457: $bgcolor ||
1.352 albertel 4458: &designparm($function.'.pgbg', $domain);
1.382 albertel 4459: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4460: my $alink = &designparm($function.'.alink', $domain);
4461: my $vlink = &designparm($function.'.vlink', $domain);
4462: my $link = &designparm($function.'.link', $domain);
4463:
1.704 muellerd 4464: my $loginbg = &designparm('login.sidebg',$domain);
1.712 muellerd 4465: my $bgcol = &designparm('login.bgcol',$domain);
4466: my $textcol = &designparm('login.textcol',$domain);
1.704 muellerd 4467:
1.602 albertel 4468: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4469: my $mono = 'monospace';
1.352 albertel 4470: my $data_table_head = $tabbg;
4471: my $data_table_light = '#EEEEEE';
1.470 banghart 4472: my $data_table_dark = '#DDDDDD';
4473: my $data_table_darker = '#CCCCCC';
1.349 albertel 4474: my $data_table_highlight = '#FFFF00';
1.352 albertel 4475: my $mail_new = '#FFBB77';
4476: my $mail_new_hover = '#DD9955';
4477: my $mail_read = '#BBBB77';
4478: my $mail_read_hover = '#999944';
4479: my $mail_replied = '#AAAA88';
4480: my $mail_replied_hover = '#888855';
4481: my $mail_other = '#99BBBB';
4482: my $mail_other_hover = '#669999';
1.391 albertel 4483: my $table_header = '#DDDDDD';
1.489 raeburn 4484: my $feedback_link_bg = '#BBBBBB';
1.701 harmsja 4485: my $lg_border_color = '#C8C8C8';
1.392 albertel 4486:
1.608 albertel 4487: my $border = ($env{'browser.type'} eq 'explorer' ||
4488: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4489: : '0px 3px 0px 4px';
1.448 albertel 4490:
1.523 albertel 4491:
1.343 albertel 4492: return <<END;
1.698 harmsja 4493: body{
4494: font-family: $sans;
4495: line-height:130%;
1.701 harmsja 4496: font-size:0.83em;
1.698 harmsja 4497: color:$font;
4498: }
1.701 harmsja 4499: a:link, a:visited { font-size:100%; }
1.698 harmsja 4500:
1.343 albertel 4501: a:focus { color: red; background: yellow }
1.510 albertel 4502: table.thinborder,
4503: table.thinborder tr th {
4504: border-style: solid;
4505: border-width: 1px;
1.698 harmsja 4506: border-color: $lg_border_color;
1.510 albertel 4507: background: $tabbg;
4508: }
1.523 albertel 4509: table.thinborder tr td {
1.510 albertel 4510: border-style: solid;
1.698 harmsja 4511: border-width: 1px;
4512: border-color: $lg_border_color;
1.510 albertel 4513: }
1.426 albertel 4514:
1.343 albertel 4515: form, .inline { display: inline; }
1.721 harmsja 4516:
4517: .LC_center { text-align: center; }
4518: .LC_left { text-align:left; }
4519: .LC_right {text-align:right;}
4520: .LC_middle {vertical-align:middle;}
4521: .LC_top {vertical-align:top;}
4522: .LC_bottom {vertical-align:bottom;}
4523:
4524: /* just for tests */
4525: .LC_300Box { width:300px; }
1.754 droeschl 4526: .LC_400Box {width:400px; }
1.721 harmsja 4527: .LC_500Box {width:500px; }
4528: .LC_600Box {width:600px; }
1.741 harmsja 4529: .LC_800Box {width:800px;}
1.721 harmsja 4530: /* end */
4531:
1.593 albertel 4532: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4533: .LC_error {
4534: color: red;
4535: font-size: larger;
4536: }
1.457 albertel 4537: .LC_warning,
4538: .LC_diff_removed {
1.733 bisitz 4539: color: red;
1.394 albertel 4540: }
1.532 albertel 4541:
4542: .LC_info,
1.457 albertel 4543: .LC_success,
4544: .LC_diff_added {
1.350 albertel 4545: color: green;
4546: }
1.543 albertel 4547: .LC_unknown {
4548: color: yellow;
4549: }
4550:
1.440 albertel 4551: .LC_icon {
4552: border: 0px;
4553: }
1.539 albertel 4554: .LC_indexer_icon {
4555: border: 0px;
4556: height: 22px;
4557: }
1.543 albertel 4558: .LC_docs_spacer {
4559: width: 25px;
4560: height: 1px;
4561: border: 0px;
4562: }
1.346 albertel 4563:
1.532 albertel 4564: .LC_internal_info {
1.735 bisitz 4565: color: #999999;
1.532 albertel 4566: }
4567:
1.458 albertel 4568: table.LC_pastsubmission {
4569: border: 1px solid black;
4570: margin: 2px;
4571: }
4572:
1.606 albertel 4573: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4574: width: 100%;
4575: background: $pgbg;
1.392 albertel 4576: border: 2px;
1.402 albertel 4577: border-collapse: separate;
1.403 albertel 4578: padding: 0px;
1.345 albertel 4579: }
1.392 albertel 4580:
1.606 albertel 4581: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4582: table#LC_title_bar.LC_with_remote {
1.359 albertel 4583: width: 100%;
1.392 albertel 4584: border-color: $pgbg;
4585: border-style: solid;
4586: border-width: $border;
4587:
1.379 albertel 4588: background: $pgbg;
4589: font-family: $sans;
1.392 albertel 4590: border-collapse: collapse;
1.403 albertel 4591: padding: 0px;
1.359 albertel 4592: }
1.409 albertel 4593: table.LC_docs_path {
4594: width: 100%;
4595: border: 0;
4596: background: $pgbg;
4597: font-family: $sans;
4598: border-collapse: collapse;
4599: padding: 0px;
4600: }
4601:
1.359 albertel 4602: table#LC_title_bar td {
4603: background: $tabbg;
4604: }
4605: table#LC_title_bar td.LC_title_bar_who {
4606: background: $tabbg;
4607: color: $font;
1.427 albertel 4608: font: small $sans;
1.359 albertel 4609: text-align: right;
4610: }
1.469 banghart 4611: span.LC_metadata {
4612: font-family: $sans;
4613: }
1.359 albertel 4614: span.LC_title_bar_title {
1.416 albertel 4615: font: bold x-large $sans;
1.359 albertel 4616: }
4617: table#LC_title_bar td.LC_title_bar_domain_logo {
4618: background: $sidebg;
4619: text-align: right;
1.368 albertel 4620: padding: 0px;
4621: }
4622: table#LC_title_bar td.LC_title_bar_role_logo {
4623: background: $sidebg;
4624: padding: 0px;
1.359 albertel 4625: }
4626:
1.706 harmsja 4627: table#LC_menubuttons img{
1.346 albertel 4628: border: 0px;
4629: }
1.345 albertel 4630: table#LC_top_nav td {
4631: background: $tabbg;
1.392 albertel 4632: border: 0px;
1.407 albertel 4633: font-size: small;
1.706 harmsja 4634: vertical-align:top;
4635: padding:2px 5px 2px 5px;
1.345 albertel 4636: }
4637: table#LC_top_nav td a, div#LC_top_nav a {
4638: color: $font;
4639: font-family: $sans;
4640: }
1.364 albertel 4641: table#LC_top_nav td.LC_top_nav_logo {
4642: background: $tabbg;
1.432 albertel 4643: text-align: left;
1.408 albertel 4644: white-space: nowrap;
1.432 albertel 4645: width: 31px;
1.408 albertel 4646: }
4647: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4648: border: 0px;
1.408 albertel 4649: vertical-align: bottom;
1.364 albertel 4650: }
1.432 albertel 4651: table#LC_top_nav td.LC_top_nav_exit,
4652: table#LC_top_nav td.LC_top_nav_help {
4653: width: 2.0em;
4654: }
1.442 albertel 4655: table#LC_top_nav td.LC_top_nav_login {
4656: width: 4.0em;
4657: text-align: center;
4658: }
1.409 albertel 4659: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4660: background: $tabbg;
4661: color: $font;
4662: font-family: $sans;
1.358 albertel 4663: font-size: smaller;
1.357 albertel 4664: }
1.411 albertel 4665: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4666: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4667: background: $tabbg;
4668: color: $font;
4669: font-family: $sans;
4670: font-size: larger;
4671: text-align: right;
4672: }
1.383 albertel 4673: td.LC_table_cell_checkbox {
4674: text-align: center;
4675: }
1.522 albertel 4676: table#LC_mainmenu td.LC_mainmenu_column {
4677: vertical-align: top;
4678: }
4679:
1.705 tempelho 4680: .LC_fontsize_small
4681: {
4682: font-size: 70%;
4683: }
4684:
4685: .LC_fontsize_medium
4686: {
4687: font-size: 85%;
4688: }
4689:
4690: .LC_fontsize_large
4691: {
4692: font-size: 120%;
4693: }
4694:
4695: .LC_fontcolor_red
4696: {
4697: color: #FF0000;
4698: }
4699:
1.346 albertel 4700: .LC_menubuttons_inline_text {
4701: color: $font;
4702: font-family: $sans;
1.698 harmsja 4703: font-size: 90%;
1.701 harmsja 4704: padding-left:3px;
1.346 albertel 4705: }
4706:
1.526 www 4707: .LC_menubuttons_link {
4708: text-decoration: none;
4709: }
1.698 harmsja 4710: /*2008--9-5: new menu style sheet.Changed category*/
1.522 albertel 4711: .LC_menubuttons_category {
1.521 www 4712: color: $font;
1.526 www 4713: background: $pgbg;
1.521 www 4714: font-family: $sans;
4715: font-size: larger;
4716: font-weight: bold;
4717: }
4718:
1.346 albertel 4719: td.LC_menubuttons_text {
1.701 harmsja 4720: color: $font;
1.346 albertel 4721: }
1.706 harmsja 4722:
4723:
1.526 www 4724:
1.346 albertel 4725: .LC_current_location {
4726: font-family: $sans;
4727: background: $tabbg;
4728: }
4729: .LC_new_mail {
4730: font-family: $sans;
1.634 www 4731: background: $tabbg;
1.346 albertel 4732: font-weight: bold;
4733: }
1.347 albertel 4734:
1.526 www 4735:
1.527 www 4736: .LC_dropadd_labeltext {
4737: font-family: $sans;
4738: text-align: right;
4739: }
4740:
4741: .LC_preferences_labeltext {
4742: font-family: $sans;
4743: text-align: right;
4744: }
4745:
1.666 raeburn 4746: .LC_roleslog_note {
1.701 harmsja 4747: font-size: small;
1.666 raeburn 4748: }
4749:
1.715 raeburn 4750: .LC_mail_functions {
4751: font-weight: bold;
4752: }
4753:
1.440 albertel 4754: table.LC_aboutme_port {
4755: border: 0px;
4756: border-collapse: collapse;
4757: border-spacing: 0px;
4758: }
1.349 albertel 4759: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4760: border: 1px solid #000000;
1.402 albertel 4761: border-collapse: separate;
1.426 albertel 4762: border-spacing: 1px;
1.610 albertel 4763: background: $pgbg;
1.347 albertel 4764: }
1.422 albertel 4765: .LC_data_table_dense {
4766: font-size: small;
4767: }
1.507 raeburn 4768: table.LC_nested_outer {
4769: border: 1px solid #000000;
1.589 raeburn 4770: border-collapse: collapse;
1.507 raeburn 4771: border-spacing: 0px;
4772: width: 100%;
4773: }
4774: table.LC_nested {
4775: border: 0px;
1.589 raeburn 4776: border-collapse: collapse;
1.507 raeburn 4777: border-spacing: 0px;
4778: width: 100%;
4779: }
1.523 albertel 4780: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4781: table.LC_prior_tries tr th {
1.349 albertel 4782: font-weight: bold;
4783: background-color: $data_table_head;
1.701 harmsja 4784: font-size:90%;
1.347 albertel 4785: }
1.711 raeburn 4786: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 4787: background-color: #CCCCCC;
1.711 raeburn 4788: font-weight: bold;
4789: text-align: left;
4790: }
1.610 albertel 4791: table.LC_data_table tr.LC_odd_row > td,
1.709 bisitz 4792: table.LC_pick_box tr > td.LC_odd_row,
1.440 albertel 4793: table.LC_aboutme_port tr td {
1.349 albertel 4794: background-color: $data_table_light;
1.425 albertel 4795: padding: 2px;
1.347 albertel 4796: }
1.610 albertel 4797: table.LC_data_table tr.LC_even_row > td,
1.709 bisitz 4798: table.LC_pick_box tr > td.LC_even_row,
1.440 albertel 4799: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4800: background-color: $data_table_dark;
1.709 bisitz 4801: padding: 2px;
1.347 albertel 4802: }
1.425 albertel 4803: table.LC_data_table tr.LC_data_table_highlight td {
4804: background-color: $data_table_darker;
4805: }
1.639 raeburn 4806: table.LC_data_table tr td.LC_leftcol_header {
4807: background-color: $data_table_head;
4808: font-weight: bold;
4809: }
1.451 albertel 4810: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4811: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4812: background-color: #FFFFFF;
1.421 albertel 4813: font-weight: bold;
4814: font-style: italic;
4815: text-align: center;
4816: padding: 8px;
1.347 albertel 4817: }
1.507 raeburn 4818: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4819: padding: 4ex
4820: }
1.507 raeburn 4821: table.LC_nested_outer tr th {
4822: font-weight: bold;
4823: background-color: $data_table_head;
1.701 harmsja 4824: font-size: small;
1.507 raeburn 4825: border-bottom: 1px solid #000000;
4826: }
4827: table.LC_nested_outer tr td.LC_subheader {
4828: background-color: $data_table_head;
4829: font-weight: bold;
4830: font-size: small;
4831: border-bottom: 1px solid #000000;
4832: text-align: right;
1.451 albertel 4833: }
1.507 raeburn 4834: table.LC_nested tr.LC_info_row td {
1.735 bisitz 4835: background-color: #CCCCCC;
1.451 albertel 4836: font-weight: bold;
4837: font-size: small;
1.507 raeburn 4838: text-align: center;
4839: }
1.589 raeburn 4840: table.LC_nested tr.LC_info_row td.LC_left_item,
4841: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4842: text-align: left;
1.451 albertel 4843: }
1.507 raeburn 4844: table.LC_nested td {
1.735 bisitz 4845: background-color: #FFFFFF;
1.451 albertel 4846: font-size: small;
1.507 raeburn 4847: }
4848: table.LC_nested_outer tr th.LC_right_item,
4849: table.LC_nested tr.LC_info_row td.LC_right_item,
4850: table.LC_nested tr.LC_odd_row td.LC_right_item,
4851: table.LC_nested tr td.LC_right_item {
1.451 albertel 4852: text-align: right;
4853: }
4854:
1.507 raeburn 4855: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 4856: background-color: #EEEEEE;
1.451 albertel 4857: }
4858:
1.473 raeburn 4859: table.LC_createuser {
4860: }
4861:
4862: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 4863: font-size: small;
1.473 raeburn 4864: }
4865:
4866: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 4867: background-color: #CCCCCC;
1.473 raeburn 4868: font-weight: bold;
4869: text-align: center;
4870: }
4871:
1.349 albertel 4872: table.LC_calendar {
4873: border: 1px solid #000000;
4874: border-collapse: collapse;
4875: }
4876: table.LC_calendar_pickdate {
4877: font-size: xx-small;
4878: }
4879: table.LC_calendar tr td {
4880: border: 1px solid #000000;
4881: vertical-align: top;
4882: }
4883: table.LC_calendar tr td.LC_calendar_day_empty {
4884: background-color: $data_table_dark;
4885: }
4886: table.LC_calendar tr td.LC_calendar_day_current {
4887: background-color: $data_table_highlight;
4888: }
4889:
4890: table.LC_mail_list tr.LC_mail_new {
4891: background-color: $mail_new;
4892: }
4893: table.LC_mail_list tr.LC_mail_new:hover {
4894: background-color: $mail_new_hover;
4895: }
4896: table.LC_mail_list tr.LC_mail_read {
4897: background-color: $mail_read;
4898: }
4899: table.LC_mail_list tr.LC_mail_read:hover {
4900: background-color: $mail_read_hover;
4901: }
4902: table.LC_mail_list tr.LC_mail_replied {
4903: background-color: $mail_replied;
4904: }
4905: table.LC_mail_list tr.LC_mail_replied:hover {
4906: background-color: $mail_replied_hover;
4907: }
4908: table.LC_mail_list tr.LC_mail_other {
4909: background-color: $mail_other;
4910: }
4911: table.LC_mail_list tr.LC_mail_other:hover {
4912: background-color: $mail_other_hover;
4913: }
1.494 raeburn 4914: table.LC_mail_list tr.LC_mail_even {
4915: }
4916: table.LC_mail_list tr.LC_mail_odd {
4917: }
4918:
1.696 bisitz 4919: table.LC_data_table tr > td.LC_browser_file,
4920: table.LC_data_table tr > td.LC_browser_file_published {
1.389 albertel 4921: background: #CCFF88;
4922: }
1.696 bisitz 4923: table.LC_data_table tr > td.LC_browser_file_locked,
4924: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 4925: background: #FFAA99;
1.387 albertel 4926: }
1.696 bisitz 4927: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.389 albertel 4928: background: #AAAAAA;
1.387 albertel 4929: }
1.696 bisitz 4930: table.LC_data_table tr > td.LC_browser_file_modified,
4931: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.389 albertel 4932: background: #FFFF77;
1.387 albertel 4933: }
1.696 bisitz 4934: table.LC_data_table tr.LC_browser_folder > td {
1.389 albertel 4935: background: #CCCCFF;
1.387 albertel 4936: }
1.696 bisitz 4937:
1.707 bisitz 4938: table.LC_data_table tr > td.LC_roles_is {
4939: /* background: #77FF77; */
4940: }
4941: table.LC_data_table tr > td.LC_roles_future {
4942: background: #FFFF77;
4943: }
4944: table.LC_data_table tr > td.LC_roles_will {
4945: background: #FFAA77;
4946: }
4947: table.LC_data_table tr > td.LC_roles_expired {
4948: background: #FF7777;
4949: }
4950: table.LC_data_table tr > td.LC_roles_will_not {
4951: background: #AAFF77;
4952: }
4953: table.LC_data_table tr > td.LC_roles_selected {
4954: background: #11CC55;
4955: }
4956:
1.388 albertel 4957: span.LC_current_location {
1.701 harmsja 4958: font-size:larger;
1.388 albertel 4959: background: $pgbg;
4960: }
1.387 albertel 4961:
1.395 albertel 4962: span.LC_parm_menu_item {
4963: font-size: larger;
4964: font-family: $sans;
4965: }
4966: span.LC_parm_scope_all {
4967: color: red;
4968: }
4969: span.LC_parm_scope_folder {
4970: color: green;
4971: }
4972: span.LC_parm_scope_resource {
4973: color: orange;
4974: }
4975: span.LC_parm_part {
4976: color: blue;
4977: }
4978: span.LC_parm_folder, span.LC_parm_symb {
4979: font-size: x-small;
4980: font-family: $mono;
4981: color: #AAAAAA;
4982: }
4983:
1.396 albertel 4984: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4985: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4986: border: 1px solid black;
4987: border-collapse: collapse;
4988: }
4989: table.LC_parm_overview_restrictions td {
4990: border-width: 1px 4px 1px 4px;
4991: border-style: solid;
4992: border-color: $pgbg;
4993: text-align: center;
4994: }
4995: table.LC_parm_overview_restrictions th {
4996: background: $tabbg;
4997: border-width: 1px 4px 1px 4px;
4998: border-style: solid;
4999: border-color: $pgbg;
5000: }
1.398 albertel 5001: table#LC_helpmenu {
5002: border: 0px;
5003: height: 55px;
5004: border-spacing: 0px;
5005: }
5006:
5007: table#LC_helpmenu fieldset legend {
5008: font-size: larger;
5009: font-weight: bold;
5010: }
1.397 albertel 5011: table#LC_helpmenu_links {
5012: width: 100%;
5013: border: 1px solid black;
5014: background: $pgbg;
5015: padding: 0px;
5016: border-spacing: 1px;
5017: }
5018: table#LC_helpmenu_links tr td {
5019: padding: 1px;
5020: background: $tabbg;
1.399 albertel 5021: text-align: center;
5022: font-weight: bold;
1.397 albertel 5023: }
1.396 albertel 5024:
1.397 albertel 5025: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
5026: table#LC_helpmenu_links a:active {
5027: text-decoration: none;
5028: color: $font;
5029: }
5030: table#LC_helpmenu_links a:hover {
5031: text-decoration: underline;
5032: color: $vlink;
5033: }
1.396 albertel 5034:
1.417 albertel 5035: .LC_chrt_popup_exists {
5036: border: 1px solid #339933;
5037: margin: -1px;
5038: }
5039: .LC_chrt_popup_up {
5040: border: 1px solid yellow;
5041: margin: -1px;
5042: }
5043: .LC_chrt_popup {
5044: border: 1px solid #8888FF;
5045: background: #CCCCFF;
5046: }
1.421 albertel 5047: table.LC_pick_box {
5048: border-collapse: separate;
5049: background: white;
5050: border: 1px solid black;
5051: border-spacing: 1px;
5052: }
5053: table.LC_pick_box td.LC_pick_box_title {
5054: background: $tabbg;
5055: font-weight: bold;
5056: text-align: right;
1.740 bisitz 5057: vertical-align: top;
1.421 albertel 5058: width: 184px;
5059: padding: 8px;
5060: }
1.645 raeburn 5061: table.LC_pick_box td.LC_selfenroll_pick_box_title {
5062: background: $tabbg;
5063: font-weight: bold;
5064: text-align: right;
5065: width: 350px;
5066: padding: 8px;
5067: }
5068:
1.579 raeburn 5069: table.LC_pick_box td.LC_pick_box_value {
5070: text-align: left;
5071: padding: 8px;
5072: }
5073: table.LC_pick_box td.LC_pick_box_select {
5074: text-align: left;
5075: padding: 8px;
5076: }
1.424 albertel 5077: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 5078: padding: 0px;
5079: height: 1px;
5080: background: black;
5081: }
5082: table.LC_pick_box td.LC_pick_box_submit {
5083: text-align: right;
5084: }
1.579 raeburn 5085: table.LC_pick_box td.LC_evenrow_value {
5086: text-align: left;
5087: padding: 8px;
5088: background-color: $data_table_light;
5089: }
5090: table.LC_pick_box td.LC_oddrow_value {
5091: text-align: left;
5092: padding: 8px;
5093: background-color: $data_table_light;
5094: }
5095: table.LC_helpform_receipt {
5096: width: 620px;
5097: border-collapse: separate;
5098: background: white;
5099: border: 1px solid black;
5100: border-spacing: 1px;
5101: }
5102: table.LC_helpform_receipt td.LC_pick_box_title {
5103: background: $tabbg;
5104: font-weight: bold;
5105: text-align: right;
5106: width: 184px;
5107: padding: 8px;
5108: }
5109: table.LC_helpform_receipt td.LC_evenrow_value {
5110: text-align: left;
5111: padding: 8px;
5112: background-color: $data_table_light;
5113: }
5114: table.LC_helpform_receipt td.LC_oddrow_value {
5115: text-align: left;
5116: padding: 8px;
5117: background-color: $data_table_light;
5118: }
5119: table.LC_helpform_receipt td.LC_pick_box_separator {
5120: padding: 0px;
5121: height: 1px;
5122: background: black;
5123: }
5124: span.LC_helpform_receipt_cat {
5125: font-weight: bold;
5126: }
1.424 albertel 5127: table.LC_group_priv_box {
5128: background: white;
5129: border: 1px solid black;
5130: border-spacing: 1px;
5131: }
5132: table.LC_group_priv_box td.LC_pick_box_title {
5133: background: $tabbg;
5134: font-weight: bold;
5135: text-align: right;
5136: width: 184px;
5137: }
5138: table.LC_group_priv_box td.LC_groups_fixed {
5139: background: $data_table_light;
5140: text-align: center;
5141: }
5142: table.LC_group_priv_box td.LC_groups_optional {
5143: background: $data_table_dark;
5144: text-align: center;
5145: }
5146: table.LC_group_priv_box td.LC_groups_functionality {
5147: background: $data_table_darker;
5148: text-align: center;
5149: font-weight: bold;
5150: }
5151: table.LC_group_priv td {
5152: text-align: left;
5153: padding: 0px;
5154: }
5155:
1.421 albertel 5156: table.LC_notify_front_page {
5157: background: white;
5158: border: 1px solid black;
5159: padding: 8px;
5160: }
5161: table.LC_notify_front_page td {
5162: padding: 8px;
5163: }
1.424 albertel 5164: .LC_navbuttons {
5165: margin: 2ex 0ex 2ex 0ex;
5166: }
1.423 albertel 5167: .LC_topic_bar {
5168: font-family: $sans;
5169: font-weight: bold;
5170: width: 100%;
5171: background: $tabbg;
5172: vertical-align: middle;
5173: margin: 2ex 0ex 2ex 0ex;
5174: }
5175: .LC_topic_bar span {
5176: vertical-align: middle;
5177: }
5178: .LC_topic_bar img {
5179: vertical-align: bottom;
5180: }
5181: table.LC_course_group_status {
5182: margin: 20px;
5183: }
5184: table.LC_status_selector td {
5185: vertical-align: top;
5186: text-align: center;
1.424 albertel 5187: padding: 4px;
5188: }
5189: table.LC_descriptive_input td.LC_description {
5190: vertical-align: top;
5191: text-align: right;
5192: font-weight: bold;
1.423 albertel 5193: }
1.599 albertel 5194: div.LC_feedback_link {
1.616 albertel 5195: clear: both;
1.599 albertel 5196: background: white;
5197: width: 100%;
1.489 raeburn 5198: }
5199: span.LC_feedback_link {
1.599 albertel 5200: background: $feedback_link_bg;
5201: font-size: larger;
5202: }
5203: span.LC_message_link {
5204: background: $feedback_link_bg;
5205: font-size: larger;
5206: position: absolute;
5207: right: 1em;
1.489 raeburn 5208: }
1.421 albertel 5209:
1.515 albertel 5210: table.LC_prior_tries {
1.524 albertel 5211: border: 1px solid #000000;
5212: border-collapse: separate;
5213: border-spacing: 1px;
1.515 albertel 5214: }
1.523 albertel 5215:
1.515 albertel 5216: table.LC_prior_tries td {
1.524 albertel 5217: padding: 2px;
1.515 albertel 5218: }
1.523 albertel 5219:
5220: .LC_answer_correct {
5221: background: #AAFFAA;
5222: color: black;
5223: }
5224: .LC_answer_charged_try {
5225: background: #FFAAAA ! important;
5226: color: black;
5227: }
5228: .LC_answer_not_charged_try,
5229: .LC_answer_no_grade,
5230: .LC_answer_late {
5231: background: #FFFFAA;
5232: color: black;
5233: }
5234: .LC_answer_previous {
5235: background: #AAAAFF;
5236: color: black;
5237: }
5238: .LC_answer_no_message {
5239: background: #FFFFFF;
5240: color: black;
5241: }
5242: .LC_answer_unknown {
5243: background: orange;
5244: color: black;
5245: }
5246:
5247:
1.529 albertel 5248: span.LC_prior_numerical,
5249: span.LC_prior_string,
5250: span.LC_prior_custom,
5251: span.LC_prior_reaction,
5252: span.LC_prior_math {
1.523 albertel 5253: font-family: monospace;
5254: white-space: pre;
5255: }
5256:
1.525 albertel 5257: span.LC_prior_string {
5258: font-family: monospace;
5259: white-space: pre;
5260: }
5261:
1.523 albertel 5262: table.LC_prior_option {
5263: width: 100%;
5264: border-collapse: collapse;
5265: }
1.528 albertel 5266: table.LC_prior_rank, table.LC_prior_match {
5267: border-collapse: collapse;
5268: }
5269: table.LC_prior_option tr td,
5270: table.LC_prior_rank tr td,
5271: table.LC_prior_match tr td {
1.524 albertel 5272: border: 1px solid #000000;
1.515 albertel 5273: }
5274:
1.519 raeburn 5275: span.LC_nobreak {
1.544 albertel 5276: white-space: nowrap;
1.519 raeburn 5277: }
5278:
1.576 raeburn 5279: span.LC_cusr_emph {
5280: font-style: italic;
5281: }
5282:
1.633 raeburn 5283: span.LC_cusr_subheading {
5284: font-weight: normal;
5285: font-size: 85%;
5286: }
5287:
1.545 albertel 5288: table.LC_docs_documents {
5289: background: #BBBBBB;
1.547 albertel 5290: border-width: 0px;
1.545 albertel 5291: border-collapse: collapse;
5292: }
5293:
5294: table.LC_docs_documents td.LC_docs_document {
5295: border: 2px solid black;
5296: padding: 4px;
5297: }
5298:
5299: .LC_docs_entry_move {
5300: border: 0px;
5301: border-collapse: collapse;
1.544 albertel 5302: }
5303:
1.545 albertel 5304: .LC_docs_entry_move td {
5305: border: 2px solid #BBBBBB;
5306: background: #DDDDDD;
5307: }
5308:
5309: .LC_docs_editor td.LC_docs_entry_commands {
5310: background: #DDDDDD;
5311: font-size: x-small;
5312: }
1.544 albertel 5313: .LC_docs_copy {
1.545 albertel 5314: color: #000099;
1.544 albertel 5315: }
5316: .LC_docs_cut {
1.545 albertel 5317: color: #550044;
1.544 albertel 5318: }
5319: .LC_docs_rename {
1.545 albertel 5320: color: #009900;
1.544 albertel 5321: }
5322: .LC_docs_remove {
1.545 albertel 5323: color: #990000;
5324: }
5325:
1.547 albertel 5326: .LC_docs_reinit_warn,
5327: .LC_docs_ext_edit {
5328: font-size: x-small;
5329: }
5330:
1.545 albertel 5331: .LC_docs_editor td.LC_docs_entry_title,
5332: .LC_docs_editor td.LC_docs_entry_icon {
5333: background: #FFFFBB;
5334: }
5335: .LC_docs_editor td.LC_docs_entry_parameter {
5336: background: #BBBBFF;
5337: font-size: x-small;
5338: white-space: nowrap;
5339: }
5340:
5341: table.LC_docs_adddocs td,
5342: table.LC_docs_adddocs th {
5343: border: 1px solid #BBBBBB;
5344: padding: 4px;
5345: background: #DDDDDD;
1.543 albertel 5346: }
5347:
1.584 albertel 5348: table.LC_sty_begin {
5349: background: #BBFFBB;
5350: }
5351: table.LC_sty_end {
5352: background: #FFBBBB;
5353: }
5354:
1.589 raeburn 5355: table.LC_double_column {
5356: border-width: 0px;
5357: border-collapse: collapse;
5358: width: 100%;
5359: padding: 2px;
5360: }
5361:
5362: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5363: top: 2px;
1.589 raeburn 5364: left: 2px;
5365: width: 47%;
5366: vertical-align: top;
5367: }
5368:
5369: table.LC_double_column tr td.LC_right_col {
5370: top: 2px;
5371: right: 2px;
5372: width: 47%;
5373: vertical-align: top;
5374: }
5375:
1.594 raeburn 5376: span.LC_role_level {
5377: font-weight: bold;
5378: }
5379:
1.591 raeburn 5380: div.LC_left_float {
5381: float: left;
5382: padding-right: 5%;
1.597 albertel 5383: padding-bottom: 4px;
1.591 raeburn 5384: }
5385:
5386: div.LC_clear_float_header {
1.597 albertel 5387: padding-bottom: 2px;
1.591 raeburn 5388: }
5389:
5390: div.LC_clear_float_footer {
1.597 albertel 5391: padding-top: 10px;
1.591 raeburn 5392: clear: both;
5393: }
5394:
1.597 albertel 5395:
5396: div.LC_grade_show_user {
5397: margin-top: 20px;
5398: border: 1px solid black;
5399: }
5400: div.LC_grade_user_name {
5401: background: #DDDDEE;
5402: border-bottom: 1px solid black;
1.705 tempelho 5403: font-weight: bold;
5404: font-size: large;
1.597 albertel 5405: }
5406: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5407: background: #DDEEDD;
5408: }
5409:
5410: div.LC_grade_show_problem,
5411: div.LC_grade_submissions,
5412: div.LC_grade_message_center,
5413: div.LC_grade_info_links,
5414: div.LC_grade_assign {
5415: margin: 5px;
5416: width: 99%;
5417: background: #FFFFFF;
5418: }
5419: div.LC_grade_show_problem_header,
5420: div.LC_grade_submissions_header,
5421: div.LC_grade_message_center_header,
5422: div.LC_grade_assign_header {
1.705 tempelho 5423: font-weight: bold;
5424: font-size: large;
1.597 albertel 5425: }
5426: div.LC_grade_show_problem_problem,
5427: div.LC_grade_submissions_body,
5428: div.LC_grade_message_center_body,
5429: div.LC_grade_assign_body {
5430: border: 1px solid black;
5431: width: 99%;
5432: background: #FFFFFF;
5433: }
1.598 albertel 5434: span.LC_grade_check_note {
1.705 tempelho 5435: font-weight: normal;
5436: font-size: medium;
1.598 albertel 5437: display: inline;
5438: position: absolute;
5439: right: 1em;
5440: }
1.597 albertel 5441:
1.613 albertel 5442: table.LC_scantron_action {
5443: width: 100%;
5444: }
5445: table.LC_scantron_action tr th {
1.698 harmsja 5446: font-weight:bold;
5447: font-style:normal;
1.613 albertel 5448: }
1.698 harmsja 5449: .LC_edit_problem_header,
1.614 albertel 5450: div.LC_edit_problem_footer {
1.705 tempelho 5451: font-weight: normal;
5452: font-size: medium;
1.602 albertel 5453: margin: 2px;
1.600 albertel 5454: }
5455: div.LC_edit_problem_header,
1.602 albertel 5456: div.LC_edit_problem_header div,
1.614 albertel 5457: div.LC_edit_problem_footer,
5458: div.LC_edit_problem_footer div,
1.602 albertel 5459: div.LC_edit_problem_editxml_header,
5460: div.LC_edit_problem_editxml_header div {
1.600 albertel 5461: margin-top: 5px;
5462: }
1.602 albertel 5463: div.LC_edit_problem_header_edit_row {
5464: background: $tabbg;
5465: padding: 3px;
5466: margin-bottom: 5px;
5467: }
1.600 albertel 5468: div.LC_edit_problem_header_title {
1.705 tempelho 5469: font-weight: bold;
5470: font-size: larger;
1.602 albertel 5471: background: $tabbg;
5472: padding: 3px;
5473: }
5474: table.LC_edit_problem_header_title {
1.705 tempelho 5475: font-size: larger;
5476: font-weight: bold;
1.602 albertel 5477: width: 100%;
5478: border-color: $pgbg;
5479: border-style: solid;
5480: border-width: $border;
5481:
1.600 albertel 5482: background: $tabbg;
1.602 albertel 5483: border-collapse: collapse;
5484: padding: 0px
5485: }
5486:
5487: div.LC_edit_problem_discards {
5488: float: left;
5489: padding-bottom: 5px;
5490: }
5491: div.LC_edit_problem_saves {
5492: float: right;
5493: padding-bottom: 5px;
1.600 albertel 5494: }
5495: hr.LC_edit_problem_divide {
1.602 albertel 5496: clear: both;
1.600 albertel 5497: color: $tabbg;
5498: background-color: $tabbg;
5499: height: 3px;
5500: border: 0px;
5501: }
1.679 riegler 5502: img.stift{
1.678 riegler 5503: border-width:0;
1.679 riegler 5504: vertical-align:middle;
1.677 riegler 5505: }
1.680 riegler 5506:
1.681 riegler 5507: table#LC_mainmenu{
5508: margin-top:10px;
5509: width:80%;
5510:
5511: }
5512:
1.680 riegler 5513: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
5514: vertical-align: top;
5515: width: 45%;
5516: }
5517: .LC_mainmenu_fieldset_category {
5518: color: $font;
5519: background: $pgbg;
5520: font-family: $sans;
5521: font-size: small;
5522: font-weight: bold;
5523: }
5524:
1.716 raeburn 5525: div.LC_createcourse {
5526: margin: 10px 10px 10px 10px;
5527: }
5528:
1.693 droeschl 5529: /* ---- Remove when done ----
5530: # The following styles is part of the redesign of LON-CAPA and are
5531: # subject to change during this project.
5532: # Don't rely on their current functionality as they might be
5533: # changed or removed.
5534: # --------------------------*/
5535:
1.698 harmsja 5536: a:hover,
1.721 harmsja 5537: ol.LC_smallMenu a:hover,
5538: ol#LC_MenuBreadcrumbs a:hover,
5539: ol#LC_PathBreadcrumbs a:hover,
5540: ul#LC_TabMainMenuContent a:hover,
5541: .LC_FormSectionClearButton input:hover
5542: ul.LC_TabContent li:hover a{
1.698 harmsja 5543: color:#BF2317;
5544: text-decoration:none;
1.693 droeschl 5545: }
5546:
5547: h1 {
1.721 harmsja 5548: padding:5px 10px 5px 20px;
1.693 droeschl 5549: line-height:130%;
5550: }
1.698 harmsja 5551:
1.693 droeschl 5552: h2,h3,h4,h5,h6
5553: {
1.721 harmsja 5554: margin:5px 0px 5px 0px;
5555: padding:0px;
5556: line-height:130%;
1.693 droeschl 5557: }
1.721 harmsja 5558: .LC_hcell{
1.698 harmsja 5559: padding:3px 15px 3px 15px;
5560: margin:0px;
1.703 harmsja 5561: background-color:$tabbg;
5562: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 5563: }
1.721 harmsja 5564: .LC_noBorder {
1.698 harmsja 5565: border:0px;
5566: }
1.693 droeschl 5567:
1.722 harmsja 5568: .LC_bgLightGrey{
1.741 harmsja 5569: background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
1.722 harmsja 5570: }
1.741 harmsja 5571:
1.693 droeschl 5572:
1.698 harmsja 5573: /* Main Header with discription of Person, Course, etc. */
1.721 harmsja 5574: .LC_HeadRight {
1.693 droeschl 5575: text-align: right;
5576: float: right;
5577: margin: 0px;
5578: padding: 0px;
1.698 harmsja 5579: right:0;
1.693 droeschl 5580: position:absolute;
1.698 harmsja 5581: overflow:hidden;
1.693 droeschl 5582: }
5583:
1.721 harmsja 5584: p, .LC_ContentBox {
1.698 harmsja 5585: padding: 10px;
5586:
5587: }
1.721 harmsja 5588: .LC_FormSectionClearButton input {
1.741 harmsja 5589: background-color:transparent;
1.698 harmsja 5590: border:0px;
5591: cursor:pointer;
5592: text-decoration:underline;
1.693 droeschl 5593: }
5594:
5595:
1.698 harmsja 5596: dl,ul,div,fieldset {
5597: margin: 10px 10px 10px 0px;
1.693 droeschl 5598: overflow:hidden;
5599: }
1.721 harmsja 5600: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698 harmsja 5601: margin: 0px;
1.693 droeschl 5602: }
5603:
1.721 harmsja 5604: ol.LC_smallMenu li {
1.693 droeschl 5605: display: inline;
5606: padding: 5px 5px 0px 10px;
5607: vertical-align: top;
5608: }
5609:
1.721 harmsja 5610: ol.LC_smallMenu li img {
1.693 droeschl 5611: vertical-align: bottom;
5612: }
5613:
1.721 harmsja 5614: ol.LC_smallMenu a {
1.693 droeschl 5615: font-size: 90%;
5616: color: RGB(80, 80, 80);
5617: text-decoration: none;
5618: }
1.744 ehlerst 5619: ol#LC_TabMainMenueContent, ul.LC_TabContent ,
1.741 harmsja 5620: ul.LC_TabContentBigger {
1.721 harmsja 5621: display:block;
5622: list-style:none;
1.741 harmsja 5623: margin: 0px;
1.693 droeschl 5624: padding: 0px;
5625: }
5626:
1.744 ehlerst 5627: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741 harmsja 5628: ul.LC_TabContentBigger li{
1.693 droeschl 5629: display: inline;
1.741 harmsja 5630: border-right: solid 1px $lg_border_color;
5631: float:left;
5632: line-height:140%;
5633: white-space:nowrap;
5634: }
5635: ol#LC_TabMainMenuContent li{
1.693 droeschl 5636: vertical-align: bottom;
5637: border-bottom: solid 1px RGB(175, 175, 175);
1.721 harmsja 5638: padding: 5px 10px 5px 10px;
1.741 harmsja 5639: margin-right:5px;
5640: margin-bottom:3px;
1.693 droeschl 5641: font-weight: bold;
1.723 riegler 5642: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5643: }
5644:
1.721 harmsja 5645: ol#LC_TabMainMenuContent li a{
1.693 droeschl 5646: color: RGB(47, 47, 47);
5647: text-decoration: none;
5648: }
1.721 harmsja 5649: ul.LC_TabContent {
1.741 harmsja 5650: min-height:1.6em;
1.721 harmsja 5651: }
5652: ul.LC_TabContent li{
1.741 harmsja 5653: vertical-align:middle;
5654: padding:0px 10px 0px 10px;
1.745 ehlerst 5655: background-color:$tabbg;
5656: border-bottom:solid 1px $lg_border_color;
1.721 harmsja 5657: }
1.744 ehlerst 5658: ul.LC_TabContent li a, ul.LC_TabContent li{
1.721 harmsja 5659: color:rgb(47,47,47);
5660: text-decoration:none;
5661: font-size:95%;
5662: font-weight:bold;
5663: }
1.744 ehlerst 5664: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
5665: background-color:#FFFFFF;
1.745 ehlerst 5666: border-bottom:solid 1px #FFFFFF;
1.744 ehlerst 5667: }
1.741 harmsja 5668: ul.LC_TabContentBigger li{
5669: vertical-align:bottom;
5670: border-top:solid 1px $lg_border_color;
5671: border-left:solid 1px $lg_border_color;
5672: padding:5px 10px 5px 10px;
5673: margin-left:2px;
5674: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
5675: }
1.744 ehlerst 5676: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
5677: background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
5678: }
1.741 harmsja 5679: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
5680: font-size:110%;
5681: font-weight:bold;
5682: }
5683: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
5684: {
5685: margin:0px;
1.737 tempelho 5686: }
5687:
1.721 harmsja 5688: .LC_hideThis
5689: {
5690: display:none;
5691: visibility:hidden;
1.693 droeschl 5692: }
5693:
1.721 harmsja 5694: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
1.693 droeschl 5695: border-top: solid 1px RGB(255, 255, 255);
5696: height: 20px;
5697: line-height: 20px;
5698: vertical-align: bottom;
5699: margin: 0px 0px 30px 0px;
5700: padding-left: 10px;
5701: list-style-position: inside;
1.723 riegler 5702: background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693 droeschl 5703: }
5704:
1.721 harmsja 5705: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
1.741 harmsja 5706: /*
1.723 riegler 5707: background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.741 harmsja 5708: */
1.693 droeschl 5709: display: inline;
5710: padding: 0px 0px 0px 10px;
5711: vertical-align: bottom;
5712: overflow:hidden;
5713: }
5714:
1.721 harmsja 5715: ol#LC_MenuBreadcrumbs li a {
1.693 droeschl 5716: text-decoration: none;
5717: font-size:90%;
5718: }
1.721 harmsja 5719: ol#LC_PathBreadcrumbs li a{
1.698 harmsja 5720: text-decoration:none;
5721: font-size:100%;
5722: font-weight:bold;
1.693 droeschl 5723: }
1.721 harmsja 5724: .LC_ContentBoxSpecial
1.693 droeschl 5725: {
1.701 harmsja 5726: border: solid 1px $lg_border_color;
1.746 neumanie 5727: }
5728: .LC_ContentBoxSpecialContactInfo
5729: {
5730: border: solid 1px $lg_border_color;
5731: max-width:25%;
5732: min-width:25%;
1.698 harmsja 5733: }
1.747 neumanie 5734: .LC_AboutMe_Image
5735: {
5736: float:left;
5737: margin-right:10px;
5738: }
5739: .LC_Clear_AboutMe_Image
5740: {
5741: clear:left;
5742: }
1.721 harmsja 5743: dl.LC_ListStyleClean dt {
1.693 droeschl 5744: padding-right: 5px;
5745: display: table-header-group;
5746: }
5747:
1.721 harmsja 5748: dl.LC_ListStyleClean dd {
1.693 droeschl 5749: display: table-row;
5750: }
5751:
1.721 harmsja 5752: .LC_ListStyleClean,
5753: .LC_ListStyleSimple,
5754: .LC_ListStyleNormal,
5755: .LC_ListStyleNormal_Border,
5756: .LC_ListStyleSpecial
1.693 droeschl 5757: {
5758: /*display:block; */
5759: list-style-position: inside;
5760: list-style-type: none;
5761: overflow: hidden;
5762: padding: 0px;
5763: }
5764:
1.721 harmsja 5765: .LC_ListStyleSimple li,
5766: .LC_ListStyleSimple dd,
5767: .LC_ListStyleNormal li,
5768: .LC_ListStyleNormal dd,
5769: .LC_ListStyleSpecial li,
5770: .LC_ListStyleSpecial dd
1.693 droeschl 5771: {
5772: margin: 0px;
5773: padding: 5px 5px 5px 10px;
5774: clear: both;
5775: }
5776:
1.721 harmsja 5777: .LC_ListStyleClean li,
5778: .LC_ListStyleClean dd {
1.693 droeschl 5779: padding-top: 0px;
5780: padding-bottom: 0px;
5781: }
5782:
1.721 harmsja 5783: .LC_ListStyleSimple dd,
5784: .LC_ListStyleSimple li{
1.698 harmsja 5785: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 5786: }
5787:
1.721 harmsja 5788: .LC_ListStyleSpecial li,
5789: .LC_ListStyleSpecial dd {
1.693 droeschl 5790: list-style-type: none;
5791: background-color: RGB(220, 220, 220);
5792: margin-bottom: 4px;
5793: }
5794:
1.721 harmsja 5795: table.LC_SimpleTable {
1.698 harmsja 5796: margin:5px;
5797: border:solid 1px $lg_border_color;
1.693 droeschl 5798: }
5799:
1.721 harmsja 5800: table.LC_SimpleTable tr {
1.698 harmsja 5801: padding:0px;
5802: border:solid 1px $lg_border_color;
1.693 droeschl 5803: }
1.721 harmsja 5804: table.LC_SimpleTable thead{
1.698 harmsja 5805: background:rgb(220,220,220);
1.693 droeschl 5806: }
5807:
1.721 harmsja 5808: div.LC_columnSection {
1.693 droeschl 5809: display: block;
5810: clear: both;
5811: overflow: hidden;
5812: margin:0px;
5813: }
5814:
1.721 harmsja 5815: div.LC_columnSection>* {
1.693 droeschl 5816: float: left;
5817: margin: 10px 20px 10px 0px;
1.747 neumanie 5818: overflow:hidden;
1.693 droeschl 5819: }
1.721 harmsja 5820:
1.719 ehlerst 5821: .ContentBoxSpecialTemplate
5822: {
1.747 neumanie 5823: border: solid 1px $lg_border_color;
1.719 ehlerst 5824: }
5825: .ContentBoxTemplate {
5826: padding:10px;
5827: }
5828:
1.721 harmsja 5829: div.LC_columnSection > .ContentBoxTemplate,
5830: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719 ehlerst 5831: {
5832: width: 600px;
5833: }
1.753 droeschl 5834:
1.720 ehlerst 5835: .clear{
5836: clear: both;
5837: line-height: 0px;
5838: font-size: 0px;
5839: height: 0px;
5840: }
1.693 droeschl 5841:
1.694 tempelho 5842: .LC_loginpage_container {
5843: text-align:left;
5844: margin : 0 auto;
5845: width:65%;
5846: padding: 10px;
5847: height: auto;
1.712 muellerd 5848: background-color:#FFFFFF;
1.694 tempelho 5849: border:1px solid #CCCCCC;
5850: }
5851:
5852:
5853: .LC_loginpage_loginContainer {
5854: float:left;
1.712 muellerd 5855: width: 182px;
5856: border:1px solid #CCCCCC;
5857: background-color:$loginbg;
1.694 tempelho 5858: }
5859:
1.717 tempelho 5860: .LC_loginpage_loginContainer h2{
1.712 muellerd 5861: margin-top:0;
5862: display:block;
5863: background:$bgcol;
5864: color:$textcol;
5865: padding-left:5px;
5866: }
1.694 tempelho 5867: .LC_loginpage_loginInfo {
5868: margin-left:20px;
5869: float:left;
5870: width:30%;
5871: border:1px solid #CCCCCC;
5872: padding:10px;
5873: }
5874:
1.712 muellerd 5875: .LC_loginpage_loginDomain {
5876: margin-right:20px;
5877: width:20%;
5878: float:left;
5879: padding:10px;
5880: }
5881:
1.694 tempelho 5882: .LC_loginpage_space {
1.754 droeschl 5883: clear: both;
5884: margin-bottom: 20px;
1.694 tempelho 5885: border-bottom: 1px solid #CCCCCC;
5886: }
5887:
1.748 schulted 5888: table em{
1.754 droeschl 5889: font-weight: bold;
5890: font-style: normal;
1.748 schulted 5891: }
5892:
1.753 droeschl 5893: table#LC_tableOfContent{
5894: border-collapse: collapse;
1.754 droeschl 5895: border-spacing: 0;
5896: padding: 3px;
5897: border: 0;
5898: background-color: #FFFFFF;
5899: font-size: 90%;
1.753 droeschl 5900: }
5901: table#LC_tableOfContent a {
5902: text-decoration: none;
5903: }
5904:
5905: table#LC_tableOfContent tr.LC_trOdd{
1.754 droeschl 5906: background-color: #EEEEEE;
1.753 droeschl 5907: }
5908:
5909: table#LC_tableOfContent img{
5910: border: none;
5911: height: 1.3em;
5912: vertical-align: text-bottom;
5913: margin-right: 0.3em;
5914: }
1.757 schulted 5915:
5916: a#LC_content_toolbar_firsthomework{
5917: background-image:url(/res/adm/pages/open-first-problem.gif);
5918: }
5919:
5920: a#LC_content_toolbar_launchnav{
5921: background-image:url(/res/adm/pages/start-navigation.gif);
5922: }
5923:
5924: a#LC_content_toolbar_closenav{
5925: background-image:url(/res/adm/pages/close-navigation.gif);
5926: }
5927:
5928: a#LC_content_toolbar_everything{
5929: background-image:url(/res/adm/pages/show-all.gif);
5930: }
5931:
5932: a#LC_content_toolbar_uncompleted{
5933: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
5934: }
5935:
5936: #LC_content_toolbar_clearbubbles{
5937: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
5938: }
5939:
5940: a#LC_content_toolbar_changefolder{
5941: background : url(/res/adm/pages/close-all-folders.gif) top center ;
5942: }
5943:
5944: a#LC_content_toolbar_changefolder_toggled{
5945: background-image:url(/res/adm/pages/open-all-folders.gif);
5946: }
5947:
5948: ul#LC_toolbar li a:hover{
5949: background-position: bottom center;
5950: }
5951:
5952: ul#LC_toolbar{
5953: padding:0;
5954: margin: 2px;
5955: list-style:none;
5956: position:relative;
5957: background-color:white;
5958: }
5959:
5960: ul#LC_toolbar li{
5961: border:1px solid white;
5962: padding:0;
5963: margin: 0;
5964: display:inline-block;
5965: vertical-align:middle;
5966: }
5967:
5968: a.LC_toolbarItem{
5969: display:inline-block;
5970: padding:0;
5971: margin:0;
5972: height: 32px;
5973: width: 32px;
5974: color:white;
5975: border:0 none;
5976: background-repeat:no-repeat;
5977: background-color:transparent;
5978: }
5979:
5980:
1.343 albertel 5981: END
5982: }
5983:
1.306 albertel 5984: =pod
5985:
5986: =item * &headtag()
5987:
5988: Returns a uniform footer for LON-CAPA web pages.
5989:
1.307 albertel 5990: Inputs: $title - optional title for the head
5991: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5992: $args - optional arguments
1.319 albertel 5993: force_register - if is true call registerurl so the remote is
5994: informed
1.415 albertel 5995: redirect -> array ref of
5996: 1- seconds before redirect occurs
5997: 2- url to redirect to
5998: 3- whether the side effect should occur
1.315 albertel 5999: (side effect of setting
6000: $env{'internal.head.redirect'} to the url
6001: redirected too)
1.352 albertel 6002: domain -> force to color decorate a page for a specific
6003: domain
6004: function -> force usage of a specific rolish color scheme
6005: bgcolor -> override the default page bgcolor
1.460 albertel 6006: no_auto_mt_title
6007: -> prevent &mt()ing the title arg
1.464 albertel 6008:
1.306 albertel 6009: =cut
6010:
6011: sub headtag {
1.313 albertel 6012: my ($title,$head_extra,$args) = @_;
1.306 albertel 6013:
1.363 albertel 6014: my $function = $args->{'function'} || &get_users_function();
6015: my $domain = $args->{'domain'} || &determinedomain();
6016: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 6017: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 6018: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 6019: #time(),
1.418 albertel 6020: $env{'environment.color.timestamp'},
1.363 albertel 6021: $function,$domain,$bgcolor);
6022:
1.369 www 6023: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 6024:
1.308 albertel 6025: my $result =
6026: '<head>'.
1.461 albertel 6027: &font_settings();
1.319 albertel 6028:
1.461 albertel 6029: if (!$args->{'frameset'}) {
6030: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
6031: }
1.319 albertel 6032: if ($args->{'force_register'}) {
6033: $result .= &Apache::lonmenu::registerurl(1);
6034: }
1.436 albertel 6035: if (!$args->{'no_nav_bar'}
6036: && !$args->{'only_body'}
6037: && !$args->{'frameset'}) {
6038: $result .= &help_menu_js();
6039: }
1.319 albertel 6040:
1.314 albertel 6041: if (ref($args->{'redirect'})) {
1.414 albertel 6042: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 6043: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 6044: if (!$inhibit_continue) {
6045: $env{'internal.head.redirect'} = $url;
6046: }
1.313 albertel 6047: $result.=<<ADDMETA
6048: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 6049: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 6050: ADDMETA
6051: }
1.306 albertel 6052: if (!defined($title)) {
6053: $title = 'The LearningOnline Network with CAPA';
6054: }
1.460 albertel 6055: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
6056: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 6057: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
6058: .$head_extra;
1.306 albertel 6059: return $result;
6060: }
6061:
6062: =pod
6063:
1.340 albertel 6064: =item * &font_settings()
6065:
6066: Returns neccessary <meta> to set the proper encoding
6067:
6068: Inputs: none
6069:
6070: =cut
6071:
6072: sub font_settings {
6073: my $headerstring='';
1.647 www 6074: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 6075: $headerstring.=
6076: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
6077: }
6078: return $headerstring;
6079: }
6080:
1.341 albertel 6081: =pod
6082:
6083: =item * &xml_begin()
6084:
6085: Returns the needed doctype and <html>
6086:
6087: Inputs: none
6088:
6089: =cut
6090:
6091: sub xml_begin {
6092: my $output='';
6093:
1.592 albertel 6094: if ($env{'internal.start_page'}==1) {
6095: &Apache::lonhtmlcommon::init_htmlareafields();
6096: }
1.342 albertel 6097:
1.341 albertel 6098: if ($env{'browser.mathml'}) {
6099: $output='<?xml version="1.0"?>'
6100: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
6101: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
6102:
6103: # .'<!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">] >'
6104: .'<!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">'
6105: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
6106: .'xmlns="http://www.w3.org/1999/xhtml">';
6107: } else {
6108: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
6109: }
6110: return $output;
6111: }
1.340 albertel 6112:
6113: =pod
6114:
1.306 albertel 6115: =item * &endheadtag()
6116:
6117: Returns a uniform </head> for LON-CAPA web pages.
6118:
6119: Inputs: none
6120:
6121: =cut
6122:
6123: sub endheadtag {
6124: return '</head>';
6125: }
6126:
6127: =pod
6128:
6129: =item * &head()
6130:
6131: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
6132:
1.648 raeburn 6133: Inputs:
6134:
6135: =over 4
6136:
6137: $title - optional title for the page
6138:
6139: $head_extra - optional extra HTML to put inside the <head>
6140:
6141: =back
1.405 albertel 6142:
1.306 albertel 6143: =cut
6144:
6145: sub head {
1.325 albertel 6146: my ($title,$head_extra,$args) = @_;
6147: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 6148: }
6149:
6150: =pod
6151:
6152: =item * &start_page()
6153:
6154: Returns a complete <html> .. <body> section for LON-CAPA web pages.
6155:
1.648 raeburn 6156: Inputs:
6157:
6158: =over 4
6159:
6160: $title - optional title for the page
6161:
6162: $head_extra - optional extra HTML to incude inside the <head>
6163:
6164: $args - additional optional args supported are:
6165:
6166: =over 8
6167:
6168: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 6169: arg on
1.648 raeburn 6170: no_nav_bar -> is true will set &bodytag() notopbar arg on
6171: add_entries -> additional attributes to add to the <body>
6172: domain -> force to color decorate a page for a
1.317 albertel 6173: specific domain
1.648 raeburn 6174: function -> force usage of a specific rolish color
1.317 albertel 6175: scheme
1.648 raeburn 6176: redirect -> see &headtag()
6177: bgcolor -> override the default page bg color
6178: js_ready -> return a string ready for being used in
1.317 albertel 6179: a javascript writeln
1.648 raeburn 6180: html_encode -> return a string ready for being used in
1.320 albertel 6181: a html attribute
1.648 raeburn 6182: force_register -> if is true will turn on the &bodytag()
1.317 albertel 6183: $forcereg arg
1.648 raeburn 6184: body_title -> alternate text to use instead of $title
1.326 albertel 6185: in the title box that appears, this text
6186: is not auto translated like the $title is
1.648 raeburn 6187: frameset -> if true will start with a <frameset>
1.330 albertel 6188: rather than <body>
1.648 raeburn 6189: no_title -> if true the title bar won't be shown
6190: skip_phases -> hash ref of
1.338 albertel 6191: head -> skip the <html><head> generation
6192: body -> skip all <body> generation
1.648 raeburn 6193: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 6194: 'Switch To Inline Menu' link
1.648 raeburn 6195: no_auto_mt_title -> prevent &mt()ing the title arg
6196: inherit_jsmath -> when creating popup window in a page,
6197: should it have jsmath forced on by the
6198: current page
1.361 albertel 6199:
1.648 raeburn 6200: =back
1.460 albertel 6201:
1.648 raeburn 6202: =back
1.562 albertel 6203:
1.306 albertel 6204: =cut
6205:
6206: sub start_page {
1.309 albertel 6207: my ($title,$head_extra,$args) = @_;
1.318 albertel 6208: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 6209: my %head_args;
1.352 albertel 6210: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 6211: 'bgcolor','frameset','no_nav_bar','only_body',
6212: 'no_auto_mt_title') {
1.319 albertel 6213: if (defined($args->{$arg})) {
1.324 raeburn 6214: $head_args{$arg} = $args->{$arg};
1.319 albertel 6215: }
1.313 albertel 6216: }
1.319 albertel 6217:
1.315 albertel 6218: $env{'internal.start_page'}++;
1.338 albertel 6219: my $result;
6220: if (! exists($args->{'skip_phases'}{'head'}) ) {
6221: $result.=
1.341 albertel 6222: &xml_begin().
1.338 albertel 6223: &headtag($title,$head_extra,\%head_args).&endheadtag();
6224: }
6225:
6226: if (! exists($args->{'skip_phases'}{'body'}) ) {
6227: if ($args->{'frameset'}) {
6228: my $attr_string = &make_attr_string($args->{'force_register'},
6229: $args->{'add_entries'});
6230: $result .= "\n<frameset $attr_string>\n";
6231: } else {
6232: $result .=
6233: &bodytag($title,
6234: $args->{'function'}, $args->{'add_entries'},
6235: $args->{'only_body'}, $args->{'domain'},
6236: $args->{'force_register'}, $args->{'body_title'},
6237: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 6238: $args->{'no_title'}, $args->{'no_inline_link'},
6239: $args);
1.338 albertel 6240: }
1.330 albertel 6241: }
1.338 albertel 6242:
1.315 albertel 6243: if ($args->{'js_ready'}) {
1.713 kaisler 6244: $result = &js_ready($result);
1.315 albertel 6245: }
1.320 albertel 6246: if ($args->{'html_encode'}) {
1.713 kaisler 6247: $result = &html_encode($result);
6248: }
6249:
1.758 ! kaisler 6250: #Breadcrumbs
! 6251: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
! 6252: &Apache::lonhtmlcommon::clear_breadcrumbs();
! 6253: #if any br links exists, add them to the breadcrumbs
! 6254: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
! 6255: foreach my $crumb (@{$args->{'bread_crumbs'}}){
! 6256: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
! 6257: }
! 6258: }
! 6259:
! 6260: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
! 6261: if(exists($args->{'bread_crumbs_component'})){
! 6262: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
! 6263: }else{
! 6264: $result .= &Apache::lonhtmlcommon::breadcrumbs();
! 6265: }
1.320 albertel 6266: }
1.315 albertel 6267: return $result;
1.306 albertel 6268: }
6269:
1.330 albertel 6270:
1.306 albertel 6271: =pod
6272:
6273: =item * &head()
6274:
6275: Returns a complete </body></html> section for LON-CAPA web pages.
6276:
1.315 albertel 6277: Inputs: $args - additional optional args supported are:
6278: js_ready -> return a string ready for being used in
6279: a javascript writeln
1.320 albertel 6280: html_encode -> return a string ready for being used in
6281: a html attribute
1.330 albertel 6282: frameset -> if true will start with a <frameset>
6283: rather than <body>
1.493 albertel 6284: dicsussion -> if true will get discussion from
6285: lonxml::xmlend
6286: (you can pass the target and parser arguments
6287: through optional 'target' and 'parser' args
6288: to this routine)
1.306 albertel 6289:
6290: =cut
6291:
6292: sub end_page {
1.315 albertel 6293: my ($args) = @_;
6294: $env{'internal.end_page'}++;
1.330 albertel 6295: my $result;
1.335 albertel 6296: if ($args->{'discussion'}) {
6297: my ($target,$parser);
6298: if (ref($args->{'discussion'})) {
6299: ($target,$parser) =($args->{'discussion'}{'target'},
6300: $args->{'discussion'}{'parser'});
6301: }
6302: $result .= &Apache::lonxml::xmlend($target,$parser);
6303: }
6304:
1.330 albertel 6305: if ($args->{'frameset'}) {
6306: $result .= '</frameset>';
6307: } else {
1.635 raeburn 6308: $result .= &endbodytag($args);
1.330 albertel 6309: }
6310: $result .= "\n</html>";
6311:
1.315 albertel 6312: if ($args->{'js_ready'}) {
1.317 albertel 6313: $result = &js_ready($result);
1.315 albertel 6314: }
1.335 albertel 6315:
1.320 albertel 6316: if ($args->{'html_encode'}) {
6317: $result = &html_encode($result);
6318: }
1.335 albertel 6319:
1.315 albertel 6320: return $result;
6321: }
6322:
1.320 albertel 6323: sub html_encode {
6324: my ($result) = @_;
6325:
1.322 albertel 6326: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 6327:
6328: return $result;
6329: }
1.317 albertel 6330: sub js_ready {
6331: my ($result) = @_;
6332:
1.323 albertel 6333: $result =~ s/[\n\r]/ /xmsg;
6334: $result =~ s/\\/\\\\/xmsg;
6335: $result =~ s/'/\\'/xmsg;
1.372 albertel 6336: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 6337:
6338: return $result;
6339: }
6340:
1.315 albertel 6341: sub validate_page {
6342: if ( exists($env{'internal.start_page'})
1.316 albertel 6343: && $env{'internal.start_page'} > 1) {
6344: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 6345: $env{'internal.start_page'}.' '.
1.316 albertel 6346: $ENV{'request.filename'});
1.315 albertel 6347: }
6348: if ( exists($env{'internal.end_page'})
1.316 albertel 6349: && $env{'internal.end_page'} > 1) {
6350: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 6351: $env{'internal.end_page'}.' '.
1.316 albertel 6352: $env{'request.filename'});
1.315 albertel 6353: }
6354: if ( exists($env{'internal.start_page'})
6355: && ! exists($env{'internal.end_page'})) {
1.316 albertel 6356: &Apache::lonnet::logthis('start_page called without end_page '.
6357: $env{'request.filename'});
1.315 albertel 6358: }
6359: if ( ! exists($env{'internal.start_page'})
6360: && exists($env{'internal.end_page'})) {
1.316 albertel 6361: &Apache::lonnet::logthis('end_page called without start_page'.
6362: $env{'request.filename'});
1.315 albertel 6363: }
1.306 albertel 6364: }
1.315 albertel 6365:
1.318 albertel 6366: sub simple_error_page {
6367: my ($r,$title,$msg) = @_;
6368: my $page =
6369: &Apache::loncommon::start_page($title).
6370: &mt($msg).
6371: &Apache::loncommon::end_page();
6372: if (ref($r)) {
6373: $r->print($page);
1.327 albertel 6374: return;
1.318 albertel 6375: }
6376: return $page;
6377: }
1.347 albertel 6378:
6379: {
1.610 albertel 6380: my @row_count;
1.347 albertel 6381: sub start_data_table {
1.422 albertel 6382: my ($add_class) = @_;
6383: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 6384: unshift(@row_count,0);
1.422 albertel 6385: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 6386: }
6387:
6388: sub end_data_table {
1.610 albertel 6389: shift(@row_count);
1.389 albertel 6390: return '</table>'."\n";;
1.347 albertel 6391: }
6392:
6393: sub start_data_table_row {
1.422 albertel 6394: my ($add_class) = @_;
1.610 albertel 6395: $row_count[0]++;
6396: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 6397: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 6398: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 6399: }
1.471 banghart 6400:
6401: sub continue_data_table_row {
6402: my ($add_class) = @_;
1.610 albertel 6403: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 6404: $css_class = (join(' ',$css_class,$add_class));
6405: return '<tr class="'.$css_class.'">'."\n";;
6406: }
1.347 albertel 6407:
6408: sub end_data_table_row {
1.389 albertel 6409: return '</tr>'."\n";;
1.347 albertel 6410: }
1.367 www 6411:
1.421 albertel 6412: sub start_data_table_empty_row {
1.707 bisitz 6413: # $row_count[0]++;
1.421 albertel 6414: return '<tr class="LC_empty_row" >'."\n";;
6415: }
6416:
6417: sub end_data_table_empty_row {
6418: return '</tr>'."\n";;
6419: }
6420:
1.367 www 6421: sub start_data_table_header_row {
1.389 albertel 6422: return '<tr class="LC_header_row">'."\n";;
1.367 www 6423: }
6424:
6425: sub end_data_table_header_row {
1.389 albertel 6426: return '</tr>'."\n";;
1.367 www 6427: }
1.347 albertel 6428: }
6429:
1.548 albertel 6430: =pod
6431:
6432: =item * &inhibit_menu_check($arg)
6433:
6434: Checks for a inhibitmenu state and generates output to preserve it
6435:
6436: Inputs: $arg - can be any of
6437: - undef - in which case the return value is a string
6438: to add into arguments list of a uri
6439: - 'input' - in which case the return value is a HTML
6440: <form> <input> field of type hidden to
6441: preserve the value
6442: - a url - in which case the return value is the url with
6443: the neccesary cgi args added to preserve the
6444: inhibitmenu state
6445: - a ref to a url - no return value, but the string is
6446: updated to include the neccessary cgi
6447: args to preserve the inhibitmenu state
6448:
6449: =cut
6450:
6451: sub inhibit_menu_check {
6452: my ($arg) = @_;
6453: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6454: if ($arg eq 'input') {
6455: if ($env{'form.inhibitmenu'}) {
6456: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
6457: } else {
6458: return
6459: }
6460: }
6461: if ($env{'form.inhibitmenu'}) {
6462: if (ref($arg)) {
6463: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6464: } elsif ($arg eq '') {
6465: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
6466: } else {
6467: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
6468: }
6469: }
6470: if (!ref($arg)) {
6471: return $arg;
6472: }
6473: }
6474:
1.251 albertel 6475: ###############################################
1.182 matthew 6476:
6477: =pod
6478:
1.549 albertel 6479: =back
6480:
6481: =head1 User Information Routines
6482:
6483: =over 4
6484:
1.405 albertel 6485: =item * &get_users_function()
1.182 matthew 6486:
6487: Used by &bodytag to determine the current users primary role.
6488: Returns either 'student','coordinator','admin', or 'author'.
6489:
6490: =cut
6491:
6492: ###############################################
6493: sub get_users_function {
6494: my $function = 'student';
1.258 albertel 6495: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 6496: $function='coordinator';
6497: }
1.258 albertel 6498: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 6499: $function='admin';
6500: }
1.258 albertel 6501: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 6502: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
6503: $function='author';
6504: }
6505: return $function;
1.54 www 6506: }
1.99 www 6507:
6508: ###############################################
6509:
1.233 raeburn 6510: =pod
6511:
1.542 raeburn 6512: =item * &check_user_status()
1.274 raeburn 6513:
6514: Determines current status of supplied role for a
6515: specific user. Roles can be active, previous or future.
6516:
6517: Inputs:
6518: user's domain, user's username, course's domain,
1.375 raeburn 6519: course's number, optional section ID.
1.274 raeburn 6520:
6521: Outputs:
6522: role status: active, previous or future.
6523:
6524: =cut
6525:
6526: sub check_user_status {
1.412 raeburn 6527: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 6528: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
6529: my @uroles = keys %userinfo;
6530: my $srchstr;
6531: my $active_chk = 'none';
1.412 raeburn 6532: my $now = time;
1.274 raeburn 6533: if (@uroles > 0) {
1.412 raeburn 6534: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 6535: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
6536: } else {
1.412 raeburn 6537: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
6538: }
6539: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 6540: my $role_end = 0;
6541: my $role_start = 0;
6542: $active_chk = 'active';
1.412 raeburn 6543: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
6544: $role_end = $1;
6545: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
6546: $role_start = $1;
1.274 raeburn 6547: }
6548: }
6549: if ($role_start > 0) {
1.412 raeburn 6550: if ($now < $role_start) {
1.274 raeburn 6551: $active_chk = 'future';
6552: }
6553: }
6554: if ($role_end > 0) {
1.412 raeburn 6555: if ($now > $role_end) {
1.274 raeburn 6556: $active_chk = 'previous';
6557: }
6558: }
6559: }
6560: }
6561: return $active_chk;
6562: }
6563:
6564: ###############################################
6565:
6566: =pod
6567:
1.405 albertel 6568: =item * &get_sections()
1.233 raeburn 6569:
6570: Determines all the sections for a course including
6571: sections with students and sections containing other roles.
1.419 raeburn 6572: Incoming parameters:
6573:
6574: 1. domain
6575: 2. course number
6576: 3. reference to array containing roles for which sections should
6577: be gathered (optional).
6578: 4. reference to array containing status types for which sections
6579: should be gathered (optional).
6580:
6581: If the third argument is undefined, sections are gathered for any role.
6582: If the fourth argument is undefined, sections are gathered for any status.
6583: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 6584:
1.374 raeburn 6585: Returns section hash (keys are section IDs, values are
6586: number of users in each section), subject to the
1.419 raeburn 6587: optional roles filter, optional status filter
1.233 raeburn 6588:
6589: =cut
6590:
6591: ###############################################
6592: sub get_sections {
1.419 raeburn 6593: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 6594: if (!defined($cdom) || !defined($cnum)) {
6595: my $cid = $env{'request.course.id'};
6596:
6597: return if (!defined($cid));
6598:
6599: $cdom = $env{'course.'.$cid.'.domain'};
6600: $cnum = $env{'course.'.$cid.'.num'};
6601: }
6602:
6603: my %sectioncount;
1.419 raeburn 6604: my $now = time;
1.240 albertel 6605:
1.366 albertel 6606: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 6607: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 6608: my $sec_index = &Apache::loncoursedata::CL_SECTION();
6609: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 6610: my $start_index = &Apache::loncoursedata::CL_START();
6611: my $end_index = &Apache::loncoursedata::CL_END();
6612: my $status;
1.366 albertel 6613: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 6614: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
6615: $data->[$status_index],
6616: $data->[$start_index],
6617: $data->[$end_index]);
6618: if ($stu_status eq 'Active') {
6619: $status = 'active';
6620: } elsif ($end < $now) {
6621: $status = 'previous';
6622: } elsif ($start > $now) {
6623: $status = 'future';
6624: }
6625: if ($section ne '-1' && $section !~ /^\s*$/) {
6626: if ((!defined($possible_status)) || (($status ne '') &&
6627: (grep/^\Q$status\E$/,@{$possible_status}))) {
6628: $sectioncount{$section}++;
6629: }
1.240 albertel 6630: }
6631: }
6632: }
6633: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6634: foreach my $user (sort(keys(%courseroles))) {
6635: if ($user !~ /^(\w{2})/) { next; }
6636: my ($role) = ($user =~ /^(\w{2})/);
6637: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 6638: my ($section,$status);
1.240 albertel 6639: if ($role eq 'cr' &&
6640: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6641: $section=$1;
6642: }
6643: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6644: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6645: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6646: if ($end == -1 && $start == -1) {
6647: next; #deleted role
6648: }
6649: if (!defined($possible_status)) {
6650: $sectioncount{$section}++;
6651: } else {
6652: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6653: $status = 'active';
6654: } elsif ($end < $now) {
6655: $status = 'future';
6656: } elsif ($start > $now) {
6657: $status = 'previous';
6658: }
6659: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6660: $sectioncount{$section}++;
6661: }
6662: }
1.233 raeburn 6663: }
1.366 albertel 6664: return %sectioncount;
1.233 raeburn 6665: }
6666:
1.274 raeburn 6667: ###############################################
1.294 raeburn 6668:
6669: =pod
1.405 albertel 6670:
6671: =item * &get_course_users()
6672:
1.275 raeburn 6673: Retrieves usernames:domains for users in the specified course
6674: with specific role(s), and access status.
6675:
6676: Incoming parameters:
1.277 albertel 6677: 1. course domain
6678: 2. course number
6679: 3. access status: users must have - either active,
1.275 raeburn 6680: previous, future, or all.
1.277 albertel 6681: 4. reference to array of permissible roles
1.288 raeburn 6682: 5. reference to array of section restrictions (optional)
6683: 6. reference to results object (hash of hashes).
6684: 7. reference to optional userdata hash
1.609 raeburn 6685: 8. reference to optional statushash
1.630 raeburn 6686: 9. flag if privileged users (except those set to unhide in
6687: course settings) should be excluded
1.609 raeburn 6688: Keys of top level results hash are roles.
1.275 raeburn 6689: Keys of inner hashes are username:domain, with
6690: values set to access type.
1.288 raeburn 6691: Optional userdata hash returns an array with arguments in the
6692: same order as loncoursedata::get_classlist() for student data.
6693:
1.609 raeburn 6694: Optional statushash returns
6695:
1.288 raeburn 6696: Entries for end, start, section and status are blank because
6697: of the possibility of multiple values for non-student roles.
6698:
1.275 raeburn 6699: =cut
1.405 albertel 6700:
1.275 raeburn 6701: ###############################################
1.405 albertel 6702:
1.275 raeburn 6703: sub get_course_users {
1.630 raeburn 6704: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6705: my %idx = ();
1.419 raeburn 6706: my %seclists;
1.288 raeburn 6707:
6708: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6709: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6710: $idx{end} = &Apache::loncoursedata::CL_END();
6711: $idx{start} = &Apache::loncoursedata::CL_START();
6712: $idx{id} = &Apache::loncoursedata::CL_ID();
6713: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6714: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6715: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6716:
1.290 albertel 6717: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6718: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6719: my $now = time;
1.277 albertel 6720: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6721: my $match = 0;
1.412 raeburn 6722: my $secmatch = 0;
1.419 raeburn 6723: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6724: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6725: if ($section eq '') {
6726: $section = 'none';
6727: }
1.291 albertel 6728: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6729: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6730: $secmatch = 1;
6731: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6732: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6733: $secmatch = 1;
6734: }
6735: } else {
1.419 raeburn 6736: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6737: $secmatch = 1;
6738: }
1.290 albertel 6739: }
1.412 raeburn 6740: if (!$secmatch) {
6741: next;
6742: }
1.419 raeburn 6743: }
1.275 raeburn 6744: if (defined($$types{'active'})) {
1.288 raeburn 6745: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6746: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6747: $match = 1;
1.275 raeburn 6748: }
6749: }
6750: if (defined($$types{'previous'})) {
1.609 raeburn 6751: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6752: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6753: $match = 1;
1.275 raeburn 6754: }
6755: }
6756: if (defined($$types{'future'})) {
1.609 raeburn 6757: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6758: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6759: $match = 1;
1.275 raeburn 6760: }
6761: }
1.609 raeburn 6762: if ($match) {
6763: push(@{$seclists{$student}},$section);
6764: if (ref($userdata) eq 'HASH') {
6765: $$userdata{$student} = $$classlist{$student};
6766: }
6767: if (ref($statushash) eq 'HASH') {
6768: $statushash->{$student}{'st'}{$section} = $status;
6769: }
1.288 raeburn 6770: }
1.275 raeburn 6771: }
6772: }
1.412 raeburn 6773: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6774: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6775: my $now = time;
1.609 raeburn 6776: my %displaystatus = ( previous => 'Expired',
6777: active => 'Active',
6778: future => 'Future',
6779: );
1.630 raeburn 6780: my %nothide;
6781: if ($hidepriv) {
6782: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6783: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6784: if ($user !~ /:/) {
6785: $nothide{join(':',split(/[\@]/,$user))}=1;
6786: } else {
6787: $nothide{$user} = 1;
6788: }
6789: }
6790: }
1.439 raeburn 6791: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6792: my $match = 0;
1.412 raeburn 6793: my $secmatch = 0;
1.439 raeburn 6794: my $status;
1.412 raeburn 6795: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6796: $user =~ s/:$//;
1.439 raeburn 6797: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6798: if ($end == -1 || $start == -1) {
6799: next;
6800: }
6801: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6802: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6803: my ($uname,$udom) = split(/:/,$user);
6804: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6805: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6806: $secmatch = 1;
6807: } elsif ($usec eq '') {
1.420 albertel 6808: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6809: $secmatch = 1;
6810: }
6811: } else {
6812: if (grep(/^\Q$usec\E$/,@{$sections})) {
6813: $secmatch = 1;
6814: }
6815: }
6816: if (!$secmatch) {
6817: next;
6818: }
1.288 raeburn 6819: }
1.419 raeburn 6820: if ($usec eq '') {
6821: $usec = 'none';
6822: }
1.275 raeburn 6823: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6824: if ($hidepriv) {
6825: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6826: (!$nothide{$uname.':'.$udom})) {
6827: next;
6828: }
6829: }
1.503 raeburn 6830: if ($end > 0 && $end < $now) {
1.439 raeburn 6831: $status = 'previous';
6832: } elsif ($start > $now) {
6833: $status = 'future';
6834: } else {
6835: $status = 'active';
6836: }
1.277 albertel 6837: foreach my $type (keys(%{$types})) {
1.275 raeburn 6838: if ($status eq $type) {
1.420 albertel 6839: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6840: push(@{$$users{$role}{$user}},$type);
6841: }
1.288 raeburn 6842: $match = 1;
6843: }
6844: }
1.419 raeburn 6845: if (($match) && (ref($userdata) eq 'HASH')) {
6846: if (!exists($$userdata{$uname.':'.$udom})) {
6847: &get_user_info($udom,$uname,\%idx,$userdata);
6848: }
1.420 albertel 6849: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6850: push(@{$seclists{$uname.':'.$udom}},$usec);
6851: }
1.609 raeburn 6852: if (ref($statushash) eq 'HASH') {
6853: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6854: }
1.275 raeburn 6855: }
6856: }
6857: }
6858: }
1.290 albertel 6859: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6860: if ((defined($cdom)) && (defined($cnum))) {
6861: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6862: if ( defined($csettings{'internal.courseowner'}) ) {
6863: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6864: next if ($owner eq '');
6865: my ($ownername,$ownerdom);
6866: if ($owner =~ /^([^:]+):([^:]+)$/) {
6867: $ownername = $1;
6868: $ownerdom = $2;
6869: } else {
6870: $ownername = $owner;
6871: $ownerdom = $cdom;
6872: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6873: }
6874: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6875: if (defined($userdata) &&
1.609 raeburn 6876: !exists($$userdata{$owner})) {
6877: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6878: if (!grep(/^none$/,@{$seclists{$owner}})) {
6879: push(@{$seclists{$owner}},'none');
6880: }
6881: if (ref($statushash) eq 'HASH') {
6882: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6883: }
1.290 albertel 6884: }
1.279 raeburn 6885: }
6886: }
6887: }
1.419 raeburn 6888: foreach my $user (keys(%seclists)) {
6889: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6890: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6891: }
1.275 raeburn 6892: }
6893: return;
6894: }
6895:
1.288 raeburn 6896: sub get_user_info {
6897: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6898: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6899: &plainname($uname,$udom,'lastname');
1.291 albertel 6900: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6901: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6902: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6903: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6904: return;
6905: }
1.275 raeburn 6906:
1.472 raeburn 6907: ###############################################
6908:
6909: =pod
6910:
6911: =item * &get_user_quota()
6912:
6913: Retrieves quota assigned for storage of portfolio files for a user
6914:
6915: Incoming parameters:
6916: 1. user's username
6917: 2. user's domain
6918:
6919: Returns:
1.536 raeburn 6920: 1. Disk quota (in Mb) assigned to student.
6921: 2. (Optional) Type of setting: custom or default
6922: (individually assigned or default for user's
6923: institutional status).
6924: 3. (Optional) - User's institutional status (e.g., faculty, staff
6925: or student - types as defined in localenroll::inst_usertypes
6926: for user's domain, which determines default quota for user.
6927: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6928:
6929: If a value has been stored in the user's environment,
1.536 raeburn 6930: it will return that, otherwise it returns the maximal default
6931: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6932:
6933: =cut
6934:
6935: ###############################################
6936:
6937:
6938: sub get_user_quota {
6939: my ($uname,$udom) = @_;
1.536 raeburn 6940: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6941: if (!defined($udom)) {
6942: $udom = $env{'user.domain'};
6943: }
6944: if (!defined($uname)) {
6945: $uname = $env{'user.name'};
6946: }
6947: if (($udom eq '' || $uname eq '') ||
6948: ($udom eq 'public') && ($uname eq 'public')) {
6949: $quota = 0;
1.536 raeburn 6950: $quotatype = 'default';
6951: $defquota = 0;
1.472 raeburn 6952: } else {
1.536 raeburn 6953: my $inststatus;
1.472 raeburn 6954: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6955: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6956: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6957: } else {
1.536 raeburn 6958: my %userenv =
6959: &Apache::lonnet::get('environment',['portfolioquota',
6960: 'inststatus'],$udom,$uname);
1.472 raeburn 6961: my ($tmp) = keys(%userenv);
6962: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6963: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6964: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6965: } else {
6966: undef(%userenv);
6967: }
6968: }
1.536 raeburn 6969: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6970: if ($quota eq '') {
1.536 raeburn 6971: $quota = $defquota;
6972: $quotatype = 'default';
6973: } else {
6974: $quotatype = 'custom';
1.472 raeburn 6975: }
6976: }
1.536 raeburn 6977: if (wantarray) {
6978: return ($quota,$quotatype,$settingstatus,$defquota);
6979: } else {
6980: return $quota;
6981: }
1.472 raeburn 6982: }
6983:
6984: ###############################################
6985:
6986: =pod
6987:
6988: =item * &default_quota()
6989:
1.536 raeburn 6990: Retrieves default quota assigned for storage of user portfolio files,
6991: given an (optional) user's institutional status.
1.472 raeburn 6992:
6993: Incoming parameters:
6994: 1. domain
1.536 raeburn 6995: 2. (Optional) institutional status(es). This is a : separated list of
6996: status types (e.g., faculty, staff, student etc.)
6997: which apply to the user for whom the default is being retrieved.
6998: If the institutional status string in undefined, the domain
6999: default quota will be returned.
1.472 raeburn 7000:
7001: Returns:
7002: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 7003: 2. (Optional) institutional type which determined the value of the
7004: default quota.
1.472 raeburn 7005:
7006: If a value has been stored in the domain's configuration db,
7007: it will return that, otherwise it returns 20 (for backwards
7008: compatibility with domains which have not set up a configuration
7009: db file; the original statically defined portfolio quota was 20 Mb).
7010:
1.536 raeburn 7011: If the user's status includes multiple types (e.g., staff and student),
7012: the largest default quota which applies to the user determines the
7013: default quota returned.
7014:
1.472 raeburn 7015: =cut
7016:
7017: ###############################################
7018:
7019:
7020: sub default_quota {
1.536 raeburn 7021: my ($udom,$inststatus) = @_;
7022: my ($defquota,$settingstatus);
7023: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 7024: ['quotas'],$udom);
7025: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 7026: if ($inststatus ne '') {
7027: my @statuses = split(/:/,$inststatus);
7028: foreach my $item (@statuses) {
1.711 raeburn 7029: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7030: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
7031: if ($defquota eq '') {
7032: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7033: $settingstatus = $item;
7034: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
7035: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
7036: $settingstatus = $item;
7037: }
7038: }
7039: } else {
7040: if ($quotahash{'quotas'}{$item} ne '') {
7041: if ($defquota eq '') {
7042: $defquota = $quotahash{'quotas'}{$item};
7043: $settingstatus = $item;
7044: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
7045: $defquota = $quotahash{'quotas'}{$item};
7046: $settingstatus = $item;
7047: }
1.536 raeburn 7048: }
7049: }
7050: }
7051: }
7052: if ($defquota eq '') {
1.711 raeburn 7053: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
7054: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
7055: } else {
7056: $defquota = $quotahash{'quotas'}{'default'};
7057: }
1.536 raeburn 7058: $settingstatus = 'default';
7059: }
7060: } else {
7061: $settingstatus = 'default';
7062: $defquota = 20;
7063: }
7064: if (wantarray) {
7065: return ($defquota,$settingstatus);
1.472 raeburn 7066: } else {
1.536 raeburn 7067: return $defquota;
1.472 raeburn 7068: }
7069: }
7070:
1.384 raeburn 7071: sub get_secgrprole_info {
7072: my ($cdom,$cnum,$needroles,$type) = @_;
7073: my %sections_count = &get_sections($cdom,$cnum);
7074: my @sections = (sort {$a <=> $b} keys(%sections_count));
7075: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
7076: my @groups = sort(keys(%curr_groups));
7077: my $allroles = [];
7078: my $rolehash;
7079: my $accesshash = {
7080: active => 'Currently has access',
7081: future => 'Will have future access',
7082: previous => 'Previously had access',
7083: };
7084: if ($needroles) {
7085: $rolehash = {'all' => 'all'};
1.385 albertel 7086: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
7087: if (&Apache::lonnet::error(%user_roles)) {
7088: undef(%user_roles);
7089: }
7090: foreach my $item (keys(%user_roles)) {
1.384 raeburn 7091: my ($role)=split(/\:/,$item,2);
7092: if ($role eq 'cr') { next; }
7093: if ($role =~ /^cr/) {
7094: $$rolehash{$role} = (split('/',$role))[3];
7095: } else {
7096: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
7097: }
7098: }
7099: foreach my $key (sort(keys(%{$rolehash}))) {
7100: push(@{$allroles},$key);
7101: }
7102: push (@{$allroles},'st');
7103: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
7104: }
7105: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
7106: }
7107:
1.555 raeburn 7108: sub user_picker {
1.627 raeburn 7109: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 7110: my $currdom = $dom;
7111: my %curr_selected = (
7112: srchin => 'dom',
1.580 raeburn 7113: srchby => 'lastname',
1.555 raeburn 7114: );
7115: my $srchterm;
1.625 raeburn 7116: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 7117: if ($srch->{'srchby'} ne '') {
7118: $curr_selected{'srchby'} = $srch->{'srchby'};
7119: }
7120: if ($srch->{'srchin'} ne '') {
7121: $curr_selected{'srchin'} = $srch->{'srchin'};
7122: }
7123: if ($srch->{'srchtype'} ne '') {
7124: $curr_selected{'srchtype'} = $srch->{'srchtype'};
7125: }
7126: if ($srch->{'srchdomain'} ne '') {
7127: $currdom = $srch->{'srchdomain'};
7128: }
7129: $srchterm = $srch->{'srchterm'};
7130: }
7131: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 7132: 'usr' => 'Search criteria',
1.563 raeburn 7133: 'doma' => 'Domain/institution to search',
1.558 albertel 7134: 'uname' => 'username',
7135: 'lastname' => 'last name',
1.555 raeburn 7136: 'lastfirst' => 'last name, first name',
1.558 albertel 7137: 'crs' => 'in this course',
1.576 raeburn 7138: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 7139: 'alc' => 'all LON-CAPA',
1.573 raeburn 7140: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 7141: 'exact' => 'is',
7142: 'contains' => 'contains',
1.569 raeburn 7143: 'begins' => 'begins with',
1.571 raeburn 7144: 'youm' => "You must include some text to search for.",
7145: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
7146: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
7147: 'yomc' => "You must choose a domain when using an institutional directory search.",
7148: 'ymcd' => "You must choose a domain when using a domain search.",
7149: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
7150: 'whse' => "When searching by last,first you must include at least one character in the first name.",
7151: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 7152: );
1.563 raeburn 7153: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
7154: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 7155:
7156: my @srchins = ('crs','dom','alc','instd');
7157:
7158: foreach my $option (@srchins) {
7159: # FIXME 'alc' option unavailable until
7160: # loncreateuser::print_user_query_page()
7161: # has been completed.
7162: next if ($option eq 'alc');
7163: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 7164: if ($curr_selected{'srchin'} eq $option) {
7165: $srchinsel .= '
7166: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7167: } else {
7168: $srchinsel .= '
7169: <option value="'.$option.'">'.$lt{$option}.'</option>';
7170: }
1.555 raeburn 7171: }
1.563 raeburn 7172: $srchinsel .= "\n </select>\n";
1.555 raeburn 7173:
7174: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 7175: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 7176: if ($curr_selected{'srchby'} eq $option) {
7177: $srchbysel .= '
7178: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7179: } else {
7180: $srchbysel .= '
7181: <option value="'.$option.'">'.$lt{$option}.'</option>';
7182: }
7183: }
7184: $srchbysel .= "\n </select>\n";
7185:
7186: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 7187: foreach my $option ('begins','contains','exact') {
1.555 raeburn 7188: if ($curr_selected{'srchtype'} eq $option) {
7189: $srchtypesel .= '
7190: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
7191: } else {
7192: $srchtypesel .= '
7193: <option value="'.$option.'">'.$lt{$option}.'</option>';
7194: }
7195: }
7196: $srchtypesel .= "\n </select>\n";
7197:
1.558 albertel 7198: my ($newuserscript,$new_user_create);
1.556 raeburn 7199:
7200: if ($forcenewuser) {
1.576 raeburn 7201: if (ref($srch) eq 'HASH') {
7202: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 7203: if ($cancreate) {
7204: $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>';
7205: } else {
7206: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
7207: my %usertypetext = (
7208: official => 'institutional',
7209: unofficial => 'non-institutional',
7210: );
7211: $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 />';
7212: }
1.576 raeburn 7213: }
7214: }
7215:
1.556 raeburn 7216: $newuserscript = <<"ENDSCRIPT";
7217:
1.570 raeburn 7218: function setSearch(createnew,callingForm) {
1.556 raeburn 7219: if (createnew == 1) {
1.570 raeburn 7220: for (var i=0; i<callingForm.srchby.length; i++) {
7221: if (callingForm.srchby.options[i].value == 'uname') {
7222: callingForm.srchby.selectedIndex = i;
1.556 raeburn 7223: }
7224: }
1.570 raeburn 7225: for (var i=0; i<callingForm.srchin.length; i++) {
7226: if ( callingForm.srchin.options[i].value == 'dom') {
7227: callingForm.srchin.selectedIndex = i;
1.556 raeburn 7228: }
7229: }
1.570 raeburn 7230: for (var i=0; i<callingForm.srchtype.length; i++) {
7231: if (callingForm.srchtype.options[i].value == 'exact') {
7232: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 7233: }
7234: }
1.570 raeburn 7235: for (var i=0; i<callingForm.srchdomain.length; i++) {
7236: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
7237: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 7238: }
7239: }
7240: }
7241: }
7242: ENDSCRIPT
1.558 albertel 7243:
1.556 raeburn 7244: }
7245:
1.555 raeburn 7246: my $output = <<"END_BLOCK";
1.556 raeburn 7247: <script type="text/javascript">
1.570 raeburn 7248: function validateEntry(callingForm) {
1.558 albertel 7249:
1.556 raeburn 7250: var checkok = 1;
1.558 albertel 7251: var srchin;
1.570 raeburn 7252: for (var i=0; i<callingForm.srchin.length; i++) {
7253: if ( callingForm.srchin[i].checked ) {
7254: srchin = callingForm.srchin[i].value;
1.558 albertel 7255: }
7256: }
7257:
1.570 raeburn 7258: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
7259: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
7260: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
7261: var srchterm = callingForm.srchterm.value;
7262: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 7263: var msg = "";
7264:
7265: if (srchterm == "") {
7266: checkok = 0;
1.571 raeburn 7267: msg += "$lt{'youm'}\\n";
1.556 raeburn 7268: }
7269:
1.569 raeburn 7270: if (srchtype== 'begins') {
7271: if (srchterm.length < 2) {
7272: checkok = 0;
1.571 raeburn 7273: msg += "$lt{'thte'}\\n";
1.569 raeburn 7274: }
7275: }
7276:
1.556 raeburn 7277: if (srchtype== 'contains') {
7278: if (srchterm.length < 3) {
7279: checkok = 0;
1.571 raeburn 7280: msg += "$lt{'thet'}\\n";
1.556 raeburn 7281: }
7282: }
7283: if (srchin == 'instd') {
7284: if (srchdomain == '') {
7285: checkok = 0;
1.571 raeburn 7286: msg += "$lt{'yomc'}\\n";
1.556 raeburn 7287: }
7288: }
7289: if (srchin == 'dom') {
7290: if (srchdomain == '') {
7291: checkok = 0;
1.571 raeburn 7292: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 7293: }
7294: }
7295: if (srchby == 'lastfirst') {
7296: if (srchterm.indexOf(",") == -1) {
7297: checkok = 0;
1.571 raeburn 7298: msg += "$lt{'whus'}\\n";
1.556 raeburn 7299: }
7300: if (srchterm.indexOf(",") == srchterm.length -1) {
7301: checkok = 0;
1.571 raeburn 7302: msg += "$lt{'whse'}\\n";
1.556 raeburn 7303: }
7304: }
7305: if (checkok == 0) {
1.571 raeburn 7306: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 7307: return;
7308: }
7309: if (checkok == 1) {
1.570 raeburn 7310: callingForm.submit();
1.556 raeburn 7311: }
7312: }
7313:
7314: $newuserscript
7315:
7316: </script>
1.558 albertel 7317:
7318: $new_user_create
7319:
1.555 raeburn 7320: <table>
1.558 albertel 7321: <tr>
1.573 raeburn 7322: <td>$lt{'doma'}:</td>
7323: <td>$domform</td>
7324: </td>
7325: </tr>
7326: <tr>
7327: <td>$lt{'usr'}:</td>
1.563 raeburn 7328: <td>$srchbysel
7329: $srchtypesel
7330: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 7331: $srchinsel
1.563 raeburn 7332: </td>
7333: </tr>
1.555 raeburn 7334: </table>
7335: <br />
7336: END_BLOCK
1.558 albertel 7337:
1.555 raeburn 7338: return $output;
7339: }
7340:
1.612 raeburn 7341: sub user_rule_check {
1.615 raeburn 7342: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 7343: my $response;
7344: if (ref($usershash) eq 'HASH') {
7345: foreach my $user (keys(%{$usershash})) {
7346: my ($uname,$udom) = split(/:/,$user);
7347: next if ($udom eq '' || $uname eq '');
1.615 raeburn 7348: my ($id,$newuser);
1.612 raeburn 7349: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 7350: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 7351: $id = $usershash->{$user}->{'id'};
7352: }
7353: my $inst_response;
7354: if (ref($checks) eq 'HASH') {
7355: if (defined($checks->{'username'})) {
1.615 raeburn 7356: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7357: &Apache::lonnet::get_instuser($udom,$uname);
7358: } elsif (defined($checks->{'id'})) {
1.615 raeburn 7359: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 7360: &Apache::lonnet::get_instuser($udom,undef,$id);
7361: }
1.615 raeburn 7362: } else {
7363: ($inst_response,%{$inst_results->{$user}}) =
7364: &Apache::lonnet::get_instuser($udom,$uname);
7365: return;
1.612 raeburn 7366: }
1.615 raeburn 7367: if (!$got_rules->{$udom}) {
1.612 raeburn 7368: my %domconfig = &Apache::lonnet::get_dom('configuration',
7369: ['usercreation'],$udom);
7370: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 7371: foreach my $item ('username','id') {
1.612 raeburn 7372: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
7373: $$curr_rules{$udom}{$item} =
7374: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 7375: }
7376: }
7377: }
1.615 raeburn 7378: $got_rules->{$udom} = 1;
1.585 raeburn 7379: }
1.612 raeburn 7380: foreach my $item (keys(%{$checks})) {
7381: if (ref($$curr_rules{$udom}) eq 'HASH') {
7382: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
7383: if (@{$$curr_rules{$udom}{$item}} > 0) {
7384: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
7385: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
7386: if ($rule_check{$rule}) {
7387: $$rulematch{$user}{$item} = $rule;
7388: if ($inst_response eq 'ok') {
1.615 raeburn 7389: if (ref($inst_results) eq 'HASH') {
7390: if (ref($inst_results->{$user}) eq 'HASH') {
7391: if (keys(%{$inst_results->{$user}}) == 0) {
7392: $$alerts{$item}{$udom}{$uname} = 1;
7393: }
1.612 raeburn 7394: }
7395: }
1.615 raeburn 7396: }
7397: last;
1.585 raeburn 7398: }
7399: }
7400: }
7401: }
7402: }
7403: }
7404: }
7405: }
1.612 raeburn 7406: return;
7407: }
7408:
7409: sub user_rule_formats {
7410: my ($domain,$domdesc,$curr_rules,$check) = @_;
7411: my %text = (
7412: 'username' => 'Usernames',
7413: 'id' => 'IDs',
7414: );
7415: my $output;
7416: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
7417: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
7418: if (@{$ruleorder} > 0) {
7419: $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>';
7420: foreach my $rule (@{$ruleorder}) {
7421: if (ref($curr_rules) eq 'ARRAY') {
7422: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
7423: if (ref($rules->{$rule}) eq 'HASH') {
7424: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
7425: $rules->{$rule}{'desc'}.'</li>';
7426: }
7427: }
7428: }
7429: }
7430: $output .= '</ul>';
7431: }
7432: }
7433: return $output;
7434: }
7435:
7436: sub instrule_disallow_msg {
1.615 raeburn 7437: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 7438: my $response;
7439: my %text = (
7440: item => 'username',
7441: items => 'usernames',
7442: match => 'matches',
7443: do => 'does',
7444: action => 'a username',
7445: one => 'one',
7446: );
7447: if ($count > 1) {
7448: $text{'item'} = 'usernames';
7449: $text{'match'} ='match';
7450: $text{'do'} = 'do';
7451: $text{'action'} = 'usernames',
7452: $text{'one'} = 'ones';
7453: }
7454: if ($checkitem eq 'id') {
7455: $text{'items'} = 'IDs';
7456: $text{'item'} = 'ID';
7457: $text{'action'} = 'an ID';
1.615 raeburn 7458: if ($count > 1) {
7459: $text{'item'} = 'IDs';
7460: $text{'action'} = 'IDs';
7461: }
1.612 raeburn 7462: }
1.674 bisitz 7463: $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 7464: if ($mode eq 'upload') {
7465: if ($checkitem eq 'username') {
7466: $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'}.");
7467: } elsif ($checkitem eq 'id') {
1.674 bisitz 7468: $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 7469: }
1.669 raeburn 7470: } elsif ($mode eq 'selfcreate') {
7471: if ($checkitem eq 'id') {
7472: $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.");
7473: }
1.615 raeburn 7474: } else {
7475: if ($checkitem eq 'username') {
7476: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
7477: } elsif ($checkitem eq 'id') {
7478: $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.");
7479: }
1.612 raeburn 7480: }
7481: return $response;
1.585 raeburn 7482: }
7483:
1.624 raeburn 7484: sub personal_data_fieldtitles {
7485: my %fieldtitles = &Apache::lonlocal::texthash (
7486: id => 'Student/Employee ID',
7487: permanentemail => 'E-mail address',
7488: lastname => 'Last Name',
7489: firstname => 'First Name',
7490: middlename => 'Middle Name',
7491: generation => 'Generation',
7492: gen => 'Generation',
7493: );
7494: return %fieldtitles;
7495: }
7496:
1.642 raeburn 7497: sub sorted_inst_types {
7498: my ($dom) = @_;
7499: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
7500: my $othertitle = &mt('All users');
7501: if ($env{'request.course.id'}) {
1.668 raeburn 7502: $othertitle = &mt('Any users');
1.642 raeburn 7503: }
7504: my @types;
7505: if (ref($order) eq 'ARRAY') {
7506: @types = @{$order};
7507: }
7508: if (@types == 0) {
7509: if (ref($usertypes) eq 'HASH') {
7510: @types = sort(keys(%{$usertypes}));
7511: }
7512: }
7513: if (keys(%{$usertypes}) > 0) {
7514: $othertitle = &mt('Other users');
7515: }
7516: return ($othertitle,$usertypes,\@types);
7517: }
7518:
1.645 raeburn 7519: sub get_institutional_codes {
7520: my ($settings,$allcourses,$LC_code) = @_;
7521: # Get complete list of course sections to update
7522: my @currsections = ();
7523: my @currxlists = ();
7524: my $coursecode = $$settings{'internal.coursecode'};
7525:
7526: if ($$settings{'internal.sectionnums'} ne '') {
7527: @currsections = split(/,/,$$settings{'internal.sectionnums'});
7528: }
7529:
7530: if ($$settings{'internal.crosslistings'} ne '') {
7531: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
7532: }
7533:
7534: if (@currxlists > 0) {
7535: foreach (@currxlists) {
7536: if (m/^([^:]+):(\w*)$/) {
7537: unless (grep/^$1$/,@{$allcourses}) {
7538: push @{$allcourses},$1;
7539: $$LC_code{$1} = $2;
7540: }
7541: }
7542: }
7543: }
7544:
7545: if (@currsections > 0) {
7546: foreach (@currsections) {
7547: if (m/^(\w+):(\w*)$/) {
7548: my $sec = $coursecode.$1;
7549: my $lc_sec = $2;
7550: unless (grep/^$sec$/,@{$allcourses}) {
7551: push @{$allcourses},$sec;
7552: $$LC_code{$sec} = $lc_sec;
7553: }
7554: }
7555: }
7556: }
7557: return;
7558: }
7559:
1.112 bowersj2 7560: =pod
7561:
1.549 albertel 7562: =back
7563:
7564: =head1 HTTP Helpers
7565:
7566: =over 4
7567:
1.648 raeburn 7568: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 7569:
1.258 albertel 7570: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 7571: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 7572: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 7573:
7574: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
7575: $possible_names is an ref to an array of form element names. As an example:
7576: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 7577: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 7578:
7579: =cut
1.1 albertel 7580:
1.6 albertel 7581: sub get_unprocessed_cgi {
1.25 albertel 7582: my ($query,$possible_names)= @_;
1.26 matthew 7583: # $Apache::lonxml::debug=1;
1.356 albertel 7584: foreach my $pair (split(/&/,$query)) {
7585: my ($name, $value) = split(/=/,$pair);
1.369 www 7586: $name = &unescape($name);
1.25 albertel 7587: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
7588: $value =~ tr/+/ /;
7589: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 7590: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 7591: }
1.16 harris41 7592: }
1.6 albertel 7593: }
7594:
1.112 bowersj2 7595: =pod
7596:
1.648 raeburn 7597: =item * &cacheheader()
1.112 bowersj2 7598:
7599: returns cache-controlling header code
7600:
7601: =cut
7602:
1.7 albertel 7603: sub cacheheader {
1.258 albertel 7604: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 7605: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
7606: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 7607: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
7608: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 7609: return $output;
1.7 albertel 7610: }
7611:
1.112 bowersj2 7612: =pod
7613:
1.648 raeburn 7614: =item * &no_cache($r)
1.112 bowersj2 7615:
7616: specifies header code to not have cache
7617:
7618: =cut
7619:
1.9 albertel 7620: sub no_cache {
1.216 albertel 7621: my ($r) = @_;
7622: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 7623: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 7624: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
7625: $r->no_cache(1);
7626: $r->header_out("Expires" => $date);
7627: $r->header_out("Pragma" => "no-cache");
1.123 www 7628: }
7629:
7630: sub content_type {
1.181 albertel 7631: my ($r,$type,$charset) = @_;
1.299 foxr 7632: if ($r) {
7633: # Note that printout.pl calls this with undef for $r.
7634: &no_cache($r);
7635: }
1.258 albertel 7636: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 7637: unless ($charset) {
7638: $charset=&Apache::lonlocal::current_encoding;
7639: }
7640: if ($charset) { $type.='; charset='.$charset; }
7641: if ($r) {
7642: $r->content_type($type);
7643: } else {
7644: print("Content-type: $type\n\n");
7645: }
1.9 albertel 7646: }
1.25 albertel 7647:
1.112 bowersj2 7648: =pod
7649:
1.648 raeburn 7650: =item * &add_to_env($name,$value)
1.112 bowersj2 7651:
1.258 albertel 7652: adds $name to the %env hash with value
1.112 bowersj2 7653: $value, if $name already exists, the entry is converted to an array
7654: reference and $value is added to the array.
7655:
7656: =cut
7657:
1.25 albertel 7658: sub add_to_env {
7659: my ($name,$value)=@_;
1.258 albertel 7660: if (defined($env{$name})) {
7661: if (ref($env{$name})) {
1.25 albertel 7662: #already have multiple values
1.258 albertel 7663: push(@{ $env{$name} },$value);
1.25 albertel 7664: } else {
7665: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7666: my $first=$env{$name};
7667: undef($env{$name});
7668: push(@{ $env{$name} },$first,$value);
1.25 albertel 7669: }
7670: } else {
1.258 albertel 7671: $env{$name}=$value;
1.25 albertel 7672: }
1.31 albertel 7673: }
1.149 albertel 7674:
7675: =pod
7676:
1.648 raeburn 7677: =item * &get_env_multiple($name)
1.149 albertel 7678:
1.258 albertel 7679: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7680: values may be defined and end up as an array ref.
7681:
7682: returns an array of values
7683:
7684: =cut
7685:
7686: sub get_env_multiple {
7687: my ($name) = @_;
7688: my @values;
1.258 albertel 7689: if (defined($env{$name})) {
1.149 albertel 7690: # exists is it an array
1.258 albertel 7691: if (ref($env{$name})) {
7692: @values=@{ $env{$name} };
1.149 albertel 7693: } else {
1.258 albertel 7694: $values[0]=$env{$name};
1.149 albertel 7695: }
7696: }
7697: return(@values);
7698: }
7699:
1.660 raeburn 7700: sub ask_for_embedded_content {
7701: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7702: my $upload_output = '
7703: <form name="upload_embedded" action="'.$actionurl.'"
7704: method="post" enctype="multipart/form-data">';
7705: $upload_output .= $state;
1.661 raeburn 7706: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7707:
7708: my $num = 0;
7709: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7710: $upload_output .= &start_data_table_row().
7711: '<td>'.$embed_file.'</td><td>';
7712: if ($args->{'ignore_remote_references'}
7713: && $embed_file =~ m{^\w+://}) {
7714: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7715: } elsif ($args->{'error_on_invalid_names'}
7716: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7717:
7718: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7719:
7720: } else {
7721: $upload_output .='
1.661 raeburn 7722: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7723: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7724: my $attrib = join(':',@{$$allfiles{$embed_file}});
7725: $upload_output .=
7726: "\n\t\t".
7727: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7728: $attrib.'" />';
7729: if (exists($$codebase{$embed_file})) {
7730: $upload_output .=
7731: "\n\t\t".
7732: '<input name="codebase_'.$num.'" type="hidden" value="'.
7733: &escape($$codebase{$embed_file}).'" />';
7734: }
7735: }
7736: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7737: $num++;
7738: }
7739: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7740: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7741: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7742: '.&mt('(only files for which a location has been provided will be uploaded)').'
7743: </form>';
7744: return $upload_output;
7745: }
7746:
1.661 raeburn 7747: sub upload_embedded {
7748: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7749: $current_disk_usage) = @_;
7750: my $output;
7751: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7752: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7753: my $orig_uploaded_filename =
7754: $env{'form.embedded_item_'.$i.'.filename'};
7755:
7756: $env{'form.embedded_orig_'.$i} =
7757: &unescape($env{'form.embedded_orig_'.$i});
7758: my ($path,$fname) =
7759: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7760: # no path, whole string is fname
7761: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7762:
7763: $path = $env{'form.currentpath'}.$path;
7764: $fname = &Apache::lonnet::clean_filename($fname);
7765: # See if there is anything left
7766: next if ($fname eq '');
7767:
7768: # Check if file already exists as a file or directory.
7769: my ($state,$msg);
7770: if ($context eq 'portfolio') {
7771: my $port_path = $dirpath;
7772: if ($group ne '') {
7773: $port_path = "groups/$group/$port_path";
7774: }
7775: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7776: $dir_root,$port_path,$disk_quota,
7777: $current_disk_usage,$uname,$udom);
7778: if ($state eq 'will_exceed_quota'
7779: || $state eq 'file_locked'
7780: || $state eq 'file_exists' ) {
7781: $output .= $msg;
7782: next;
7783: }
7784: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7785: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7786: if ($state eq 'exists') {
7787: $output .= $msg;
7788: next;
7789: }
7790: }
7791: # Check if extension is valid
7792: if (($fname =~ /\.(\w+)$/) &&
7793: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7794: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7795: next;
7796: } elsif (($fname =~ /\.(\w+)$/) &&
7797: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7798: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7799: next;
7800: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7801: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7802: next;
7803: }
7804:
7805: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7806: if ($context eq 'portfolio') {
7807: my $result=
7808: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7809: $dirpath.$path);
7810: if ($result !~ m|^/uploaded/|) {
7811: $output .= '<span class="LC_error">'
7812: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7813: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7814: .'</span><br />';
7815: next;
7816: } else {
7817: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7818: $path.$fname.'</span>').'</p>';
7819: }
7820: } else {
7821: # Save the file
7822: my $target = $env{'form.embedded_item_'.$i};
7823: my $fullpath = $dir_root.$dirpath.'/'.$path;
7824: my $dest = $fullpath.$fname;
7825: my $url = $url_root.$dirpath.'/'.$path.$fname;
7826: my @parts=split(/\//,$fullpath);
7827: my $count;
7828: my $filepath = $dir_root;
7829: for ($count=4;$count<=$#parts;$count++) {
7830: $filepath .= "/$parts[$count]";
7831: if ((-e $filepath)!=1) {
7832: mkdir($filepath,0770);
7833: }
7834: }
7835: my $fh;
7836: if (!open($fh,'>'.$dest)) {
7837: &Apache::lonnet::logthis('Failed to create '.$dest);
7838: $output .= '<span class="LC_error">'.
7839: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7840: '</span><br />';
7841: } else {
7842: if (!print $fh $env{'form.embedded_item_'.$i}) {
7843: &Apache::lonnet::logthis('Failed to write to '.$dest);
7844: $output .= '<span class="LC_error">'.
7845: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7846: '</span><br />';
7847: } else {
7848: if ($context eq 'testbank') {
7849: $output .= &mt('Embedded file uploaded successfully:').
7850: ' <a href="'.$url.'">'.
7851: $orig_uploaded_filename.'</a><br />';
7852: } else {
1.705 tempelho 7853: $output .= '<span class=\"LC_fontsize_large\">'.
1.661 raeburn 7854: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705 tempelho 7855: $orig_uploaded_filename.'</a>').'</span><br />';
1.661 raeburn 7856: }
7857: }
7858: close($fh);
7859: }
7860: }
7861: }
7862: return $output;
7863: }
7864:
7865: sub check_for_existing {
7866: my ($path,$fname,$element) = @_;
7867: my ($state,$msg);
7868: if (-d $path.'/'.$fname) {
7869: $state = 'exists';
7870: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7871: } elsif (-e $path.'/'.$fname) {
7872: $state = 'exists';
7873: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7874: }
7875: if ($state eq 'exists') {
7876: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7877: }
7878: return ($state,$msg);
7879: }
7880:
7881: sub check_for_upload {
7882: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7883: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7884: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7885: my $getpropath = 1;
7886: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7887: $getpropath);
7888: my $found_file = 0;
7889: my $locked_file = 0;
7890: foreach my $line (@dir_list) {
7891: my ($file_name)=split(/\&/,$line,2);
7892: if ($file_name eq $fname){
7893: $file_name = $path.$file_name;
7894: if ($group ne '') {
7895: $file_name = $group.$file_name;
7896: }
7897: $found_file = 1;
7898: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7899: $locked_file = 1;
7900: }
7901: }
7902: }
7903: if (($current_disk_usage + $filesize) > $disk_quota){
7904: my $msg = '<span class="LC_error">'.
7905: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7906: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7907: return ('will_exceed_quota',$msg);
7908: } elsif ($found_file) {
7909: if ($locked_file) {
7910: my $msg = '<span class="LC_error">';
7911: $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>');
7912: $msg .= '</span><br />';
7913: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7914: return ('file_locked',$msg);
7915: } else {
7916: my $msg = '<span class="LC_error">';
7917: $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'});
7918: $msg .= '</span>';
7919: $msg .= '<br />';
7920: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7921: return ('file_exists',$msg);
7922: }
7923: }
7924: }
7925:
1.31 albertel 7926:
1.41 ng 7927: =pod
1.45 matthew 7928:
1.464 albertel 7929: =back
1.41 ng 7930:
1.112 bowersj2 7931: =head1 CSV Upload/Handling functions
1.38 albertel 7932:
1.41 ng 7933: =over 4
7934:
1.648 raeburn 7935: =item * &upfile_store($r)
1.41 ng 7936:
7937: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7938: needs $env{'form.upfile'}
1.41 ng 7939: returns $datatoken to be put into hidden field
7940:
7941: =cut
1.31 albertel 7942:
7943: sub upfile_store {
7944: my $r=shift;
1.258 albertel 7945: $env{'form.upfile'}=~s/\r/\n/gs;
7946: $env{'form.upfile'}=~s/\f/\n/gs;
7947: $env{'form.upfile'}=~s/\n+/\n/gs;
7948: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7949:
1.258 albertel 7950: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7951: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7952: {
1.158 raeburn 7953: my $datafile = $r->dir_config('lonDaemons').
7954: '/tmp/'.$datatoken.'.tmp';
7955: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7956: print $fh $env{'form.upfile'};
1.158 raeburn 7957: close($fh);
7958: }
1.31 albertel 7959: }
7960: return $datatoken;
7961: }
7962:
1.56 matthew 7963: =pod
7964:
1.648 raeburn 7965: =item * &load_tmp_file($r)
1.41 ng 7966:
7967: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7968: needs $env{'form.datatoken'},
7969: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7970:
7971: =cut
1.31 albertel 7972:
7973: sub load_tmp_file {
7974: my $r=shift;
7975: my @studentdata=();
7976: {
1.158 raeburn 7977: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7978: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7979: if ( open(my $fh,"<$studentfile") ) {
7980: @studentdata=<$fh>;
7981: close($fh);
7982: }
1.31 albertel 7983: }
1.258 albertel 7984: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7985: }
7986:
1.56 matthew 7987: =pod
7988:
1.648 raeburn 7989: =item * &upfile_record_sep()
1.41 ng 7990:
7991: Separate uploaded file into records
7992: returns array of records,
1.258 albertel 7993: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7994:
7995: =cut
1.31 albertel 7996:
7997: sub upfile_record_sep {
1.258 albertel 7998: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7999: } else {
1.248 albertel 8000: my @records;
1.258 albertel 8001: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 8002: if ($line=~/^\s*$/) { next; }
8003: push(@records,$line);
8004: }
8005: return @records;
1.31 albertel 8006: }
8007: }
8008:
1.56 matthew 8009: =pod
8010:
1.648 raeburn 8011: =item * &record_sep($record)
1.41 ng 8012:
1.258 albertel 8013: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 8014:
8015: =cut
8016:
1.263 www 8017: sub takeleft {
8018: my $index=shift;
8019: return substr('0000'.$index,-4,4);
8020: }
8021:
1.31 albertel 8022: sub record_sep {
8023: my $record=shift;
8024: my %components=();
1.258 albertel 8025: if ($env{'form.upfiletype'} eq 'xml') {
8026: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 8027: my $i=0;
1.356 albertel 8028: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 8029: $field=~s/^(\"|\')//;
8030: $field=~s/(\"|\')$//;
1.263 www 8031: $components{&takeleft($i)}=$field;
1.31 albertel 8032: $i++;
8033: }
1.258 albertel 8034: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 8035: my $i=0;
1.356 albertel 8036: foreach my $field (split(/\t/,$record)) {
1.31 albertel 8037: $field=~s/^(\"|\')//;
8038: $field=~s/(\"|\')$//;
1.263 www 8039: $components{&takeleft($i)}=$field;
1.31 albertel 8040: $i++;
8041: }
8042: } else {
1.561 www 8043: my $separator=',';
1.480 banghart 8044: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 8045: $separator=';';
1.480 banghart 8046: }
1.31 albertel 8047: my $i=0;
1.561 www 8048: # the character we are looking for to indicate the end of a quote or a record
8049: my $looking_for=$separator;
8050: # do not add the characters to the fields
8051: my $ignore=0;
8052: # we just encountered a separator (or the beginning of the record)
8053: my $just_found_separator=1;
8054: # store the field we are working on here
8055: my $field='';
8056: # work our way through all characters in record
8057: foreach my $character ($record=~/(.)/g) {
8058: if ($character eq $looking_for) {
8059: if ($character ne $separator) {
8060: # Found the end of a quote, again looking for separator
8061: $looking_for=$separator;
8062: $ignore=1;
8063: } else {
8064: # Found a separator, store away what we got
8065: $components{&takeleft($i)}=$field;
8066: $i++;
8067: $just_found_separator=1;
8068: $ignore=0;
8069: $field='';
8070: }
8071: next;
8072: }
8073: # single or double quotation marks after a separator indicate beginning of a quote
8074: # we are now looking for the end of the quote and need to ignore separators
8075: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
8076: $looking_for=$character;
8077: next;
8078: }
8079: # ignore would be true after we reached the end of a quote
8080: if ($ignore) { next; }
8081: if (($just_found_separator) && ($character=~/\s/)) { next; }
8082: $field.=$character;
8083: $just_found_separator=0;
1.31 albertel 8084: }
1.561 www 8085: # catch the very last entry, since we never encountered the separator
8086: $components{&takeleft($i)}=$field;
1.31 albertel 8087: }
8088: return %components;
8089: }
8090:
1.144 matthew 8091: ######################################################
8092: ######################################################
8093:
1.56 matthew 8094: =pod
8095:
1.648 raeburn 8096: =item * &upfile_select_html()
1.41 ng 8097:
1.144 matthew 8098: Return HTML code to select a file from the users machine and specify
8099: the file type.
1.41 ng 8100:
8101: =cut
8102:
1.144 matthew 8103: ######################################################
8104: ######################################################
1.31 albertel 8105: sub upfile_select_html {
1.144 matthew 8106: my %Types = (
8107: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 8108: semisv => &mt('Semicolon separated values'),
1.144 matthew 8109: space => &mt('Space separated'),
8110: tab => &mt('Tabulator separated'),
8111: # xml => &mt('HTML/XML'),
8112: );
8113: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 8114: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 8115: foreach my $type (sort(keys(%Types))) {
8116: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
8117: }
8118: $Str .= "</select>\n";
8119: return $Str;
1.31 albertel 8120: }
8121:
1.301 albertel 8122: sub get_samples {
8123: my ($records,$toget) = @_;
8124: my @samples=({});
8125: my $got=0;
8126: foreach my $rec (@$records) {
8127: my %temp = &record_sep($rec);
8128: if (! grep(/\S/, values(%temp))) { next; }
8129: if (%temp) {
8130: $samples[$got]=\%temp;
8131: $got++;
8132: if ($got == $toget) { last; }
8133: }
8134: }
8135: return \@samples;
8136: }
8137:
1.144 matthew 8138: ######################################################
8139: ######################################################
8140:
1.56 matthew 8141: =pod
8142:
1.648 raeburn 8143: =item * &csv_print_samples($r,$records)
1.41 ng 8144:
8145: Prints a table of sample values from each column uploaded $r is an
8146: Apache Request ref, $records is an arrayref from
8147: &Apache::loncommon::upfile_record_sep
8148:
8149: =cut
8150:
1.144 matthew 8151: ######################################################
8152: ######################################################
1.31 albertel 8153: sub csv_print_samples {
8154: my ($r,$records) = @_;
1.662 bisitz 8155: my $samples = &get_samples($records,5);
1.301 albertel 8156:
1.594 raeburn 8157: $r->print(&mt('Samples').'<br />'.&start_data_table().
8158: &start_data_table_header_row());
1.356 albertel 8159: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8160: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 8161: $r->print(&end_data_table_header_row());
1.301 albertel 8162: foreach my $hash (@$samples) {
1.594 raeburn 8163: $r->print(&start_data_table_row());
1.356 albertel 8164: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 8165: $r->print('<td>');
1.356 albertel 8166: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 8167: $r->print('</td>');
8168: }
1.594 raeburn 8169: $r->print(&end_data_table_row());
1.31 albertel 8170: }
1.594 raeburn 8171: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 8172: }
8173:
1.144 matthew 8174: ######################################################
8175: ######################################################
8176:
1.56 matthew 8177: =pod
8178:
1.648 raeburn 8179: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 8180:
8181: Prints a table to create associations between values and table columns.
1.144 matthew 8182:
1.41 ng 8183: $r is an Apache Request ref,
8184: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 8185: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 8186:
8187: =cut
8188:
1.144 matthew 8189: ######################################################
8190: ######################################################
1.31 albertel 8191: sub csv_print_select_table {
8192: my ($r,$records,$d) = @_;
1.301 albertel 8193: my $i=0;
8194: my $samples = &get_samples($records,1);
1.144 matthew 8195: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 8196: &start_data_table().&start_data_table_header_row().
1.144 matthew 8197: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 8198: '<th>'.&mt('Column').'</th>'.
8199: &end_data_table_header_row()."\n");
1.356 albertel 8200: foreach my $array_ref (@$d) {
8201: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 8202: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 8203:
8204: $r->print('<td><select name=f'.$i.
1.32 matthew 8205: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 8206: $r->print('<option value="none"></option>');
1.356 albertel 8207: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
8208: $r->print('<option value="'.$sample.'"'.
8209: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 8210: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 8211: }
1.594 raeburn 8212: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 8213: $i++;
8214: }
1.594 raeburn 8215: $r->print(&end_data_table());
1.31 albertel 8216: $i--;
8217: return $i;
8218: }
1.56 matthew 8219:
1.144 matthew 8220: ######################################################
8221: ######################################################
8222:
1.56 matthew 8223: =pod
1.31 albertel 8224:
1.648 raeburn 8225: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 8226:
8227: Prints a table of sample values from the upload and can make associate samples to internal names.
8228:
8229: $r is an Apache Request ref,
8230: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
8231: $d is an array of 2 element arrays (internal name, displayed name)
8232:
8233: =cut
8234:
1.144 matthew 8235: ######################################################
8236: ######################################################
1.31 albertel 8237: sub csv_samples_select_table {
8238: my ($r,$records,$d) = @_;
8239: my $i=0;
1.144 matthew 8240: #
1.662 bisitz 8241: my $max_samples = 5;
8242: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 8243: $r->print(&start_data_table().
8244: &start_data_table_header_row().'<th>'.
8245: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
8246: &end_data_table_header_row());
1.301 albertel 8247:
8248: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 8249: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 8250: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 8251: foreach my $option (@$d) {
8252: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 8253: $r->print('<option value="'.$value.'"'.
1.253 albertel 8254: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 8255: $display.'</option>');
1.31 albertel 8256: }
8257: $r->print('</select></td><td>');
1.662 bisitz 8258: foreach my $line (0..($max_samples-1)) {
1.301 albertel 8259: if (defined($samples->[$line]{$key})) {
8260: $r->print($samples->[$line]{$key}."<br />\n");
8261: }
8262: }
1.594 raeburn 8263: $r->print('</td>'.&end_data_table_row());
1.31 albertel 8264: $i++;
8265: }
1.594 raeburn 8266: $r->print(&end_data_table());
1.31 albertel 8267: $i--;
8268: return($i);
1.115 matthew 8269: }
8270:
1.144 matthew 8271: ######################################################
8272: ######################################################
8273:
1.115 matthew 8274: =pod
8275:
1.648 raeburn 8276: =item * &clean_excel_name($name)
1.115 matthew 8277:
8278: Returns a replacement for $name which does not contain any illegal characters.
8279:
8280: =cut
8281:
1.144 matthew 8282: ######################################################
8283: ######################################################
1.115 matthew 8284: sub clean_excel_name {
8285: my ($name) = @_;
8286: $name =~ s/[:\*\?\/\\]//g;
8287: if (length($name) > 31) {
8288: $name = substr($name,0,31);
8289: }
8290: return $name;
1.25 albertel 8291: }
1.84 albertel 8292:
1.85 albertel 8293: =pod
8294:
1.648 raeburn 8295: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 8296:
8297: Returns either 1 or undef
8298:
8299: 1 if the part is to be hidden, undef if it is to be shown
8300:
8301: Arguments are:
8302:
8303: $id the id of the part to be checked
8304: $symb, optional the symb of the resource to check
8305: $udom, optional the domain of the user to check for
8306: $uname, optional the username of the user to check for
8307:
8308: =cut
1.84 albertel 8309:
8310: sub check_if_partid_hidden {
8311: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 8312: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 8313: $symb,$udom,$uname);
1.141 albertel 8314: my $truth=1;
8315: #if the string starts with !, then the list is the list to show not hide
8316: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 8317: my @hiddenlist=split(/,/,$hiddenparts);
8318: foreach my $checkid (@hiddenlist) {
1.141 albertel 8319: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 8320: }
1.141 albertel 8321: return !$truth;
1.84 albertel 8322: }
1.127 matthew 8323:
1.138 matthew 8324:
8325: ############################################################
8326: ############################################################
8327:
8328: =pod
8329:
1.157 matthew 8330: =back
8331:
1.138 matthew 8332: =head1 cgi-bin script and graphing routines
8333:
1.157 matthew 8334: =over 4
8335:
1.648 raeburn 8336: =item * &get_cgi_id()
1.138 matthew 8337:
8338: Inputs: none
8339:
8340: Returns an id which can be used to pass environment variables
8341: to various cgi-bin scripts. These environment variables will
8342: be removed from the users environment after a given time by
8343: the routine &Apache::lonnet::transfer_profile_to_env.
8344:
8345: =cut
8346:
8347: ############################################################
8348: ############################################################
1.152 albertel 8349: my $uniq=0;
1.136 matthew 8350: sub get_cgi_id {
1.154 albertel 8351: $uniq=($uniq+1)%100000;
1.280 albertel 8352: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 8353: }
8354:
1.127 matthew 8355: ############################################################
8356: ############################################################
8357:
8358: =pod
8359:
1.648 raeburn 8360: =item * &DrawBarGraph()
1.127 matthew 8361:
1.138 matthew 8362: Facilitates the plotting of data in a (stacked) bar graph.
8363: Puts plot definition data into the users environment in order for
8364: graph.png to plot it. Returns an <img> tag for the plot.
8365: The bars on the plot are labeled '1','2',...,'n'.
8366:
8367: Inputs:
8368:
8369: =over 4
8370:
8371: =item $Title: string, the title of the plot
8372:
8373: =item $xlabel: string, text describing the X-axis of the plot
8374:
8375: =item $ylabel: string, text describing the Y-axis of the plot
8376:
8377: =item $Max: scalar, the maximum Y value to use in the plot
8378: If $Max is < any data point, the graph will not be rendered.
8379:
1.140 matthew 8380: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 8381: they are plotted. If undefined, default values will be used.
8382:
1.178 matthew 8383: =item $labels: array ref holding the labels to use on the x-axis for the bars.
8384:
1.138 matthew 8385: =item @Values: An array of array references. Each array reference holds data
8386: to be plotted in a stacked bar chart.
8387:
1.239 matthew 8388: =item If the final element of @Values is a hash reference the key/value
8389: pairs will be added to the graph definition.
8390:
1.138 matthew 8391: =back
8392:
8393: Returns:
8394:
8395: An <img> tag which references graph.png and the appropriate identifying
8396: information for the plot.
8397:
1.127 matthew 8398: =cut
8399:
8400: ############################################################
8401: ############################################################
1.134 matthew 8402: sub DrawBarGraph {
1.178 matthew 8403: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 8404: #
8405: if (! defined($colors)) {
8406: $colors = ['#33ff00',
8407: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
8408: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
8409: ];
8410: }
1.228 matthew 8411: my $extra_settings = {};
8412: if (ref($Values[-1]) eq 'HASH') {
8413: $extra_settings = pop(@Values);
8414: }
1.127 matthew 8415: #
1.136 matthew 8416: my $identifier = &get_cgi_id();
8417: my $id = 'cgi.'.$identifier;
1.129 matthew 8418: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 8419: return '';
8420: }
1.225 matthew 8421: #
8422: my @Labels;
8423: if (defined($labels)) {
8424: @Labels = @$labels;
8425: } else {
8426: for (my $i=0;$i<@{$Values[0]};$i++) {
8427: push (@Labels,$i+1);
8428: }
8429: }
8430: #
1.129 matthew 8431: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 8432: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 8433: my %ValuesHash;
8434: my $NumSets=1;
8435: foreach my $array (@Values) {
8436: next if (! ref($array));
1.136 matthew 8437: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 8438: join(',',@$array);
1.129 matthew 8439: }
1.127 matthew 8440: #
1.136 matthew 8441: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 8442: if ($NumBars < 3) {
8443: $width = 120+$NumBars*32;
1.220 matthew 8444: $xskip = 1;
1.225 matthew 8445: $bar_width = 30;
8446: } elsif ($NumBars < 5) {
8447: $width = 120+$NumBars*20;
8448: $xskip = 1;
8449: $bar_width = 20;
1.220 matthew 8450: } elsif ($NumBars < 10) {
1.136 matthew 8451: $width = 120+$NumBars*15;
8452: $xskip = 1;
8453: $bar_width = 15;
8454: } elsif ($NumBars <= 25) {
8455: $width = 120+$NumBars*11;
8456: $xskip = 5;
8457: $bar_width = 8;
8458: } elsif ($NumBars <= 50) {
8459: $width = 120+$NumBars*8;
8460: $xskip = 5;
8461: $bar_width = 4;
8462: } else {
8463: $width = 120+$NumBars*8;
8464: $xskip = 5;
8465: $bar_width = 4;
8466: }
8467: #
1.137 matthew 8468: $Max = 1 if ($Max < 1);
8469: if ( int($Max) < $Max ) {
8470: $Max++;
8471: $Max = int($Max);
8472: }
1.127 matthew 8473: $Title = '' if (! defined($Title));
8474: $xlabel = '' if (! defined($xlabel));
8475: $ylabel = '' if (! defined($ylabel));
1.369 www 8476: $ValuesHash{$id.'.title'} = &escape($Title);
8477: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
8478: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 8479: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 8480: $ValuesHash{$id.'.NumBars'} = $NumBars;
8481: $ValuesHash{$id.'.NumSets'} = $NumSets;
8482: $ValuesHash{$id.'.PlotType'} = 'bar';
8483: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8484: $ValuesHash{$id.'.height'} = $height;
8485: $ValuesHash{$id.'.width'} = $width;
8486: $ValuesHash{$id.'.xskip'} = $xskip;
8487: $ValuesHash{$id.'.bar_width'} = $bar_width;
8488: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 8489: #
1.228 matthew 8490: # Deal with other parameters
8491: while (my ($key,$value) = each(%$extra_settings)) {
8492: $ValuesHash{$id.'.'.$key} = $value;
8493: }
8494: #
1.646 raeburn 8495: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 8496: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8497: }
8498:
8499: ############################################################
8500: ############################################################
8501:
8502: =pod
8503:
1.648 raeburn 8504: =item * &DrawXYGraph()
1.137 matthew 8505:
1.138 matthew 8506: Facilitates the plotting of data in an XY graph.
8507: Puts plot definition data into the users environment in order for
8508: graph.png to plot it. Returns an <img> tag for the plot.
8509:
8510: Inputs:
8511:
8512: =over 4
8513:
8514: =item $Title: string, the title of the plot
8515:
8516: =item $xlabel: string, text describing the X-axis of the plot
8517:
8518: =item $ylabel: string, text describing the Y-axis of the plot
8519:
8520: =item $Max: scalar, the maximum Y value to use in the plot
8521: If $Max is < any data point, the graph will not be rendered.
8522:
8523: =item $colors: Array ref containing the hex color codes for the data to be
8524: plotted in. If undefined, default values will be used.
8525:
8526: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8527:
8528: =item $Ydata: Array ref containing Array refs.
1.185 www 8529: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 8530:
8531: =item %Values: hash indicating or overriding any default values which are
8532: passed to graph.png.
8533: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8534:
8535: =back
8536:
8537: Returns:
8538:
8539: An <img> tag which references graph.png and the appropriate identifying
8540: information for the plot.
8541:
1.137 matthew 8542: =cut
8543:
8544: ############################################################
8545: ############################################################
8546: sub DrawXYGraph {
8547: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
8548: #
8549: # Create the identifier for the graph
8550: my $identifier = &get_cgi_id();
8551: my $id = 'cgi.'.$identifier;
8552: #
8553: $Title = '' if (! defined($Title));
8554: $xlabel = '' if (! defined($xlabel));
8555: $ylabel = '' if (! defined($ylabel));
8556: my %ValuesHash =
8557: (
1.369 www 8558: $id.'.title' => &escape($Title),
8559: $id.'.xlabel' => &escape($xlabel),
8560: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 8561: $id.'.y_max_value'=> $Max,
8562: $id.'.labels' => join(',',@$Xlabels),
8563: $id.'.PlotType' => 'XY',
8564: );
8565: #
8566: if (defined($colors) && ref($colors) eq 'ARRAY') {
8567: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8568: }
8569: #
8570: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
8571: return '';
8572: }
8573: my $NumSets=1;
1.138 matthew 8574: foreach my $array (@{$Ydata}){
1.137 matthew 8575: next if (! ref($array));
8576: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
8577: }
1.138 matthew 8578: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 8579: #
8580: # Deal with other parameters
8581: while (my ($key,$value) = each(%Values)) {
8582: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 8583: }
8584: #
1.646 raeburn 8585: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 8586: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
8587: }
8588:
8589: ############################################################
8590: ############################################################
8591:
8592: =pod
8593:
1.648 raeburn 8594: =item * &DrawXYYGraph()
1.138 matthew 8595:
8596: Facilitates the plotting of data in an XY graph with two Y axes.
8597: Puts plot definition data into the users environment in order for
8598: graph.png to plot it. Returns an <img> tag for the plot.
8599:
8600: Inputs:
8601:
8602: =over 4
8603:
8604: =item $Title: string, the title of the plot
8605:
8606: =item $xlabel: string, text describing the X-axis of the plot
8607:
8608: =item $ylabel: string, text describing the Y-axis of the plot
8609:
8610: =item $colors: Array ref containing the hex color codes for the data to be
8611: plotted in. If undefined, default values will be used.
8612:
8613: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
8614:
8615: =item $Ydata1: The first data set
8616:
8617: =item $Min1: The minimum value of the left Y-axis
8618:
8619: =item $Max1: The maximum value of the left Y-axis
8620:
8621: =item $Ydata2: The second data set
8622:
8623: =item $Min2: The minimum value of the right Y-axis
8624:
8625: =item $Max2: The maximum value of the left Y-axis
8626:
8627: =item %Values: hash indicating or overriding any default values which are
8628: passed to graph.png.
8629: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
8630:
8631: =back
8632:
8633: Returns:
8634:
8635: An <img> tag which references graph.png and the appropriate identifying
8636: information for the plot.
1.136 matthew 8637:
8638: =cut
8639:
8640: ############################################################
8641: ############################################################
1.137 matthew 8642: sub DrawXYYGraph {
8643: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
8644: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 8645: #
8646: # Create the identifier for the graph
8647: my $identifier = &get_cgi_id();
8648: my $id = 'cgi.'.$identifier;
8649: #
8650: $Title = '' if (! defined($Title));
8651: $xlabel = '' if (! defined($xlabel));
8652: $ylabel = '' if (! defined($ylabel));
8653: my %ValuesHash =
8654: (
1.369 www 8655: $id.'.title' => &escape($Title),
8656: $id.'.xlabel' => &escape($xlabel),
8657: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8658: $id.'.labels' => join(',',@$Xlabels),
8659: $id.'.PlotType' => 'XY',
8660: $id.'.NumSets' => 2,
1.137 matthew 8661: $id.'.two_axes' => 1,
8662: $id.'.y1_max_value' => $Max1,
8663: $id.'.y1_min_value' => $Min1,
8664: $id.'.y2_max_value' => $Max2,
8665: $id.'.y2_min_value' => $Min2,
1.136 matthew 8666: );
8667: #
1.137 matthew 8668: if (defined($colors) && ref($colors) eq 'ARRAY') {
8669: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8670: }
8671: #
8672: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8673: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8674: return '';
8675: }
8676: my $NumSets=1;
1.137 matthew 8677: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8678: next if (! ref($array));
8679: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8680: }
8681: #
8682: # Deal with other parameters
8683: while (my ($key,$value) = each(%Values)) {
8684: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8685: }
8686: #
1.646 raeburn 8687: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8688: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8689: }
8690:
8691: ############################################################
8692: ############################################################
8693:
8694: =pod
8695:
1.157 matthew 8696: =back
8697:
1.139 matthew 8698: =head1 Statistics helper routines?
8699:
8700: Bad place for them but what the hell.
8701:
1.157 matthew 8702: =over 4
8703:
1.648 raeburn 8704: =item * &chartlink()
1.139 matthew 8705:
8706: Returns a link to the chart for a specific student.
8707:
8708: Inputs:
8709:
8710: =over 4
8711:
8712: =item $linktext: The text of the link
8713:
8714: =item $sname: The students username
8715:
8716: =item $sdomain: The students domain
8717:
8718: =back
8719:
1.157 matthew 8720: =back
8721:
1.139 matthew 8722: =cut
8723:
8724: ############################################################
8725: ############################################################
8726: sub chartlink {
8727: my ($linktext, $sname, $sdomain) = @_;
8728: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8729: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8730: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8731: '">'.$linktext.'</a>';
1.153 matthew 8732: }
8733:
8734: #######################################################
8735: #######################################################
8736:
8737: =pod
8738:
8739: =head1 Course Environment Routines
1.157 matthew 8740:
8741: =over 4
1.153 matthew 8742:
1.648 raeburn 8743: =item * &restore_course_settings()
1.153 matthew 8744:
1.648 raeburn 8745: =item * &store_course_settings()
1.153 matthew 8746:
8747: Restores/Store indicated form parameters from the course environment.
8748: Will not overwrite existing values of the form parameters.
8749:
8750: Inputs:
8751: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8752:
8753: a hash ref describing the data to be stored. For example:
8754:
8755: %Save_Parameters = ('Status' => 'scalar',
8756: 'chartoutputmode' => 'scalar',
8757: 'chartoutputdata' => 'scalar',
8758: 'Section' => 'array',
1.373 raeburn 8759: 'Group' => 'array',
1.153 matthew 8760: 'StudentData' => 'array',
8761: 'Maps' => 'array');
8762:
8763: Returns: both routines return nothing
8764:
1.631 raeburn 8765: =back
8766:
1.153 matthew 8767: =cut
8768:
8769: #######################################################
8770: #######################################################
8771: sub store_course_settings {
1.496 albertel 8772: return &store_settings($env{'request.course.id'},@_);
8773: }
8774:
8775: sub store_settings {
1.153 matthew 8776: # save to the environment
8777: # appenv the same items, just to be safe
1.300 albertel 8778: my $udom = $env{'user.domain'};
8779: my $uname = $env{'user.name'};
1.496 albertel 8780: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8781: my %SaveHash;
8782: my %AppHash;
8783: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8784: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8785: my $envname = 'environment.'.$basename;
1.258 albertel 8786: if (exists($env{'form.'.$setting})) {
1.153 matthew 8787: # Save this value away
8788: if ($type eq 'scalar' &&
1.258 albertel 8789: (! exists($env{$envname}) ||
8790: $env{$envname} ne $env{'form.'.$setting})) {
8791: $SaveHash{$basename} = $env{'form.'.$setting};
8792: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8793: } elsif ($type eq 'array') {
8794: my $stored_form;
1.258 albertel 8795: if (ref($env{'form.'.$setting})) {
1.153 matthew 8796: $stored_form = join(',',
8797: map {
1.369 www 8798: &escape($_);
1.258 albertel 8799: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8800: } else {
8801: $stored_form =
1.369 www 8802: &escape($env{'form.'.$setting});
1.153 matthew 8803: }
8804: # Determine if the array contents are the same.
1.258 albertel 8805: if ($stored_form ne $env{$envname}) {
1.153 matthew 8806: $SaveHash{$basename} = $stored_form;
8807: $AppHash{$envname} = $stored_form;
8808: }
8809: }
8810: }
8811: }
8812: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8813: $udom,$uname);
1.153 matthew 8814: if ($put_result !~ /^(ok|delayed)/) {
8815: &Apache::lonnet::logthis('unable to save form parameters, '.
8816: 'got error:'.$put_result);
8817: }
8818: # Make sure these settings stick around in this session, too
1.646 raeburn 8819: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8820: return;
8821: }
8822:
8823: sub restore_course_settings {
1.499 albertel 8824: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8825: }
8826:
8827: sub restore_settings {
8828: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8829: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8830: next if (exists($env{'form.'.$setting}));
1.496 albertel 8831: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8832: '.'.$setting;
1.258 albertel 8833: if (exists($env{$envname})) {
1.153 matthew 8834: if ($type eq 'scalar') {
1.258 albertel 8835: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8836: } elsif ($type eq 'array') {
1.258 albertel 8837: $env{'form.'.$setting} = [
1.153 matthew 8838: map {
1.369 www 8839: &unescape($_);
1.258 albertel 8840: } split(',',$env{$envname})
1.153 matthew 8841: ];
8842: }
8843: }
8844: }
1.127 matthew 8845: }
8846:
1.618 raeburn 8847: #######################################################
8848: #######################################################
8849:
8850: =pod
8851:
8852: =head1 Domain E-mail Routines
8853:
8854: =over 4
8855:
1.648 raeburn 8856: =item * &build_recipient_list()
1.618 raeburn 8857:
8858: Build recipient lists for three types of e-mail:
8859: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8860: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8861:
8862: Inputs:
1.619 raeburn 8863: defmail (scalar - email address of default recipient),
1.618 raeburn 8864: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8865: defdom (domain for which to retrieve configuration settings),
8866: origmail (scalar - email address of recipient from loncapa.conf,
8867: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8868:
1.655 raeburn 8869: Returns: comma separated list of addresses to which to send e-mail.
8870:
8871: =back
1.618 raeburn 8872:
8873: =cut
8874:
8875: ############################################################
8876: ############################################################
8877: sub build_recipient_list {
1.619 raeburn 8878: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8879: my @recipients;
8880: my $otheremails;
8881: my %domconfig =
8882: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8883: if (ref($domconfig{'contacts'}) eq 'HASH') {
8884: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8885: my @contacts = ('adminemail','supportemail');
8886: foreach my $item (@contacts) {
8887: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8888: my $addr = $domconfig{'contacts'}{$item};
8889: if (!grep(/^\Q$addr\E$/,@recipients)) {
8890: push(@recipients,$addr);
8891: }
1.618 raeburn 8892: }
8893: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8894: }
8895: }
1.619 raeburn 8896: } elsif ($origmail ne '') {
8897: push(@recipients,$origmail);
1.618 raeburn 8898: }
1.688 raeburn 8899: if (defined($defmail)) {
8900: if ($defmail ne '') {
8901: push(@recipients,$defmail);
8902: }
1.618 raeburn 8903: }
8904: if ($otheremails) {
1.619 raeburn 8905: my @others;
8906: if ($otheremails =~ /,/) {
8907: @others = split(/,/,$otheremails);
1.618 raeburn 8908: } else {
1.619 raeburn 8909: push(@others,$otheremails);
8910: }
8911: foreach my $addr (@others) {
8912: if (!grep(/^\Q$addr\E$/,@recipients)) {
8913: push(@recipients,$addr);
8914: }
1.618 raeburn 8915: }
8916: }
1.619 raeburn 8917: my $recipientlist = join(',',@recipients);
1.618 raeburn 8918: return $recipientlist;
8919: }
8920:
1.127 matthew 8921: ############################################################
8922: ############################################################
1.154 albertel 8923:
1.655 raeburn 8924: =pod
8925:
8926: =head1 Course Catalog Routines
8927:
8928: =over 4
8929:
8930: =item * &gather_categories()
8931:
8932: Converts category definitions - keys of categories hash stored in
8933: coursecategories in configuration.db on the primary library server in a
8934: domain - to an array. Also generates javascript and idx hash used to
8935: generate Domain Coordinator interface for editing Course Categories.
8936:
8937: Inputs:
1.663 raeburn 8938:
1.655 raeburn 8939: categories (reference to hash of category definitions).
1.663 raeburn 8940:
1.655 raeburn 8941: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8942: categories and subcategories).
1.663 raeburn 8943:
1.655 raeburn 8944: idx (reference to hash of counters used in Domain Coordinator interface for
8945: editing Course Categories).
1.663 raeburn 8946:
1.655 raeburn 8947: jsarray (reference to array of categories used to create Javascript arrays for
8948: Domain Coordinator interface for editing Course Categories).
8949:
8950: Returns: nothing
8951:
8952: Side effects: populates cats, idx and jsarray.
8953:
8954: =cut
8955:
8956: sub gather_categories {
8957: my ($categories,$cats,$idx,$jsarray) = @_;
8958: my %counters;
8959: my $num = 0;
8960: foreach my $item (keys(%{$categories})) {
8961: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8962: if ($container eq '' && $depth == 0) {
8963: $cats->[$depth][$categories->{$item}] = $cat;
8964: } else {
8965: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8966: }
8967: my ($escitem,$tail) = split(/:/,$item,2);
8968: if ($counters{$tail} eq '') {
8969: $counters{$tail} = $num;
8970: $num ++;
8971: }
8972: if (ref($idx) eq 'HASH') {
8973: $idx->{$item} = $counters{$tail};
8974: }
8975: if (ref($jsarray) eq 'ARRAY') {
8976: push(@{$jsarray->[$counters{$tail}]},$item);
8977: }
8978: }
8979: return;
8980: }
8981:
8982: =pod
8983:
8984: =item * &extract_categories()
8985:
8986: Used to generate breadcrumb trails for course categories.
8987:
8988: Inputs:
1.663 raeburn 8989:
1.655 raeburn 8990: categories (reference to hash of category definitions).
1.663 raeburn 8991:
1.655 raeburn 8992: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8993: categories and subcategories).
1.663 raeburn 8994:
1.655 raeburn 8995: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8996:
1.655 raeburn 8997: allitems (reference to hash - key is category key
8998: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8999:
1.655 raeburn 9000: idx (reference to hash of counters used in Domain Coordinator interface for
9001: editing Course Categories).
1.663 raeburn 9002:
1.655 raeburn 9003: jsarray (reference to array of categories used to create Javascript arrays for
9004: Domain Coordinator interface for editing Course Categories).
9005:
1.665 raeburn 9006: subcats (reference to hash of arrays containing all subcategories within each
9007: category, -recursive)
9008:
1.655 raeburn 9009: Returns: nothing
9010:
9011: Side effects: populates trails and allitems hash references.
9012:
9013: =cut
9014:
9015: sub extract_categories {
1.665 raeburn 9016: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 9017: if (ref($categories) eq 'HASH') {
9018: &gather_categories($categories,$cats,$idx,$jsarray);
9019: if (ref($cats->[0]) eq 'ARRAY') {
9020: for (my $i=0; $i<@{$cats->[0]}; $i++) {
9021: my $name = $cats->[0][$i];
9022: my $item = &escape($name).'::0';
9023: my $trailstr;
9024: if ($name eq 'instcode') {
9025: $trailstr = &mt('Official courses (with institutional codes)');
9026: } else {
9027: $trailstr = $name;
9028: }
9029: if ($allitems->{$item} eq '') {
9030: push(@{$trails},$trailstr);
9031: $allitems->{$item} = scalar(@{$trails})-1;
9032: }
9033: my @parents = ($name);
9034: if (ref($cats->[1]{$name}) eq 'ARRAY') {
9035: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
9036: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 9037: if (ref($subcats) eq 'HASH') {
9038: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
9039: }
9040: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
9041: }
9042: } else {
9043: if (ref($subcats) eq 'HASH') {
9044: $subcats->{$item} = [];
1.655 raeburn 9045: }
9046: }
9047: }
9048: }
9049: }
9050: return;
9051: }
9052:
9053: =pod
9054:
9055: =item *&recurse_categories()
9056:
9057: Recursively used to generate breadcrumb trails for course categories.
9058:
9059: Inputs:
1.663 raeburn 9060:
1.655 raeburn 9061: cats (reference to array of arrays/hashes which encapsulates hierarchy of
9062: categories and subcategories).
1.663 raeburn 9063:
1.655 raeburn 9064: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 9065:
9066: category (current course category, for which breadcrumb trail is being generated).
9067:
9068: trails (reference to array of breadcrumb trails for each category).
9069:
1.655 raeburn 9070: allitems (reference to hash - key is category key
9071: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 9072:
1.655 raeburn 9073: parents (array containing containers directories for current category,
9074: back to top level).
9075:
9076: Returns: nothing
9077:
9078: Side effects: populates trails and allitems hash references
9079:
9080: =cut
9081:
9082: sub recurse_categories {
1.665 raeburn 9083: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 9084: my $shallower = $depth - 1;
9085: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
9086: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
9087: my $name = $cats->[$depth]{$category}[$k];
9088: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9089: my $trailstr = join(' -> ',(@{$parents},$category));
9090: if ($allitems->{$item} eq '') {
9091: push(@{$trails},$trailstr);
9092: $allitems->{$item} = scalar(@{$trails})-1;
9093: }
9094: my $deeper = $depth+1;
9095: push(@{$parents},$category);
1.665 raeburn 9096: if (ref($subcats) eq 'HASH') {
9097: my $subcat = &escape($name).':'.$category.':'.$depth;
9098: for (my $j=@{$parents}; $j>=0; $j--) {
9099: my $higher;
9100: if ($j > 0) {
9101: $higher = &escape($parents->[$j]).':'.
9102: &escape($parents->[$j-1]).':'.$j;
9103: } else {
9104: $higher = &escape($parents->[$j]).'::'.$j;
9105: }
9106: push(@{$subcats->{$higher}},$subcat);
9107: }
9108: }
9109: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
9110: $subcats);
1.655 raeburn 9111: pop(@{$parents});
9112: }
9113: } else {
9114: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
9115: my $trailstr = join(' -> ',(@{$parents},$category));
9116: if ($allitems->{$item} eq '') {
9117: push(@{$trails},$trailstr);
9118: $allitems->{$item} = scalar(@{$trails})-1;
9119: }
9120: }
9121: return;
9122: }
9123:
1.663 raeburn 9124: =pod
9125:
9126: =item *&assign_categories_table()
9127:
9128: Create a datatable for display of hierarchical categories in a domain,
9129: with checkboxes to allow a course to be categorized.
9130:
9131: Inputs:
9132:
9133: cathash - reference to hash of categories defined for the domain (from
9134: configuration.db)
9135:
9136: currcat - scalar with an & separated list of categories assigned to a course.
9137:
9138: Returns: $output (markup to be displayed)
9139:
9140: =cut
9141:
9142: sub assign_categories_table {
9143: my ($cathash,$currcat) = @_;
9144: my $output;
9145: if (ref($cathash) eq 'HASH') {
9146: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
9147: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
9148: $maxdepth = scalar(@cats);
9149: if (@cats > 0) {
9150: my $itemcount = 0;
9151: if (ref($cats[0]) eq 'ARRAY') {
9152: $output = &Apache::loncommon::start_data_table();
9153: my @currcategories;
9154: if ($currcat ne '') {
9155: @currcategories = split('&',$currcat);
9156: }
9157: for (my $i=0; $i<@{$cats[0]}; $i++) {
9158: my $parent = $cats[0][$i];
9159: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9160: next if ($parent eq 'instcode');
9161: my $item = &escape($parent).'::0';
9162: my $checked = '';
9163: if (@currcategories > 0) {
9164: if (grep(/^\Q$item\E$/,@currcategories)) {
9165: $checked = ' checked="checked" ';
9166: }
9167: }
1.675 raeburn 9168: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
9169: '<input type="checkbox" name="usecategory" value="'.
9170: $item.'"'.$checked.' />'.$parent.'</span>'.
9171: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 9172: my $depth = 1;
9173: push(@path,$parent);
9174: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
9175: pop(@path);
9176: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9177: $itemcount ++;
9178: }
9179: $output .= &Apache::loncommon::end_data_table();
9180: }
9181: }
9182: }
9183: return $output;
9184: }
9185:
9186: =pod
9187:
9188: =item *&assign_category_rows()
9189:
9190: Create a datatable row for display of nested categories in a domain,
9191: with checkboxes to allow a course to be categorized,called recursively.
9192:
9193: Inputs:
9194:
9195: itemcount - track row number for alternating colors
9196:
9197: cats - reference to array of arrays/hashes which encapsulates hierarchy of
9198: categories and subcategories.
9199:
9200: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
9201:
9202: parent - parent of current category item
9203:
9204: path - Array containing all categories back up through the hierarchy from the
9205: current category to the top level.
9206:
9207: currcategories - reference to array of current categories assigned to the course
9208:
9209: Returns: $output (markup to be displayed).
9210:
9211: =cut
9212:
9213: sub assign_category_rows {
9214: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
9215: my ($text,$name,$item,$chgstr);
9216: if (ref($cats) eq 'ARRAY') {
9217: my $maxdepth = scalar(@{$cats});
9218: if (ref($cats->[$depth]) eq 'HASH') {
9219: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9220: my $numchildren = @{$cats->[$depth]{$parent}};
9221: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
9222: $text .= '<td><table class="LC_datatable">';
9223: for (my $j=0; $j<$numchildren; $j++) {
9224: $name = $cats->[$depth]{$parent}[$j];
9225: $item = &escape($name).':'.&escape($parent).':'.$depth;
9226: my $deeper = $depth+1;
9227: my $checked = '';
9228: if (ref($currcategories) eq 'ARRAY') {
9229: if (@{$currcategories} > 0) {
9230: if (grep(/^\Q$item\E$/,@{$currcategories})) {
9231: $checked = ' checked="checked" ';
9232: }
9233: }
9234: }
1.664 raeburn 9235: $text .= '<tr><td><span class="LC_nobreak"><label>'.
9236: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 9237: $item.'"'.$checked.' />'.$name.'</label></span>'.
9238: '<input type="hidden" name="catname" value="'.$name.'" />'.
9239: '</td><td>';
1.663 raeburn 9240: if (ref($path) eq 'ARRAY') {
9241: push(@{$path},$name);
9242: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
9243: pop(@{$path});
9244: }
9245: $text .= '</td></tr>';
9246: }
9247: $text .= '</table></td>';
9248: }
9249: }
9250: }
9251: return $text;
9252: }
9253:
1.655 raeburn 9254: ############################################################
9255: ############################################################
9256:
9257:
1.443 albertel 9258: sub commit_customrole {
1.664 raeburn 9259: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 9260: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 9261: ($start?', '.&mt('starting').' '.localtime($start):'').
9262: ($end?', ending '.localtime($end):'').': <b>'.
9263: &Apache::lonnet::assigncustomrole(
1.664 raeburn 9264: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 9265: '</b><br />';
9266: return $output;
9267: }
9268:
9269: sub commit_standardrole {
1.541 raeburn 9270: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
9271: my ($output,$logmsg,$linefeed);
9272: if ($context eq 'auto') {
9273: $linefeed = "\n";
9274: } else {
9275: $linefeed = "<br />\n";
9276: }
1.443 albertel 9277: if ($three eq 'st') {
1.541 raeburn 9278: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
9279: $one,$two,$sec,$context);
9280: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 9281: ($result eq 'unknown_course') || ($result eq 'refused')) {
9282: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 9283: } else {
1.541 raeburn 9284: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 9285: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9286: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
9287: if ($context eq 'auto') {
9288: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
9289: } else {
9290: $output .= '<b>'.$result.'</b>'.$linefeed.
9291: &mt('Add to classlist').': <b>ok</b>';
9292: }
9293: $output .= $linefeed;
1.443 albertel 9294: }
9295: } else {
9296: $output = &mt('Assigning').' '.$three.' in '.$url.
9297: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 9298: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 9299: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 9300: if ($context eq 'auto') {
9301: $output .= $result.$linefeed;
9302: } else {
9303: $output .= '<b>'.$result.'</b>'.$linefeed;
9304: }
1.443 albertel 9305: }
9306: return $output;
9307: }
9308:
9309: sub commit_studentrole {
1.541 raeburn 9310: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 9311: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 9312: if ($context eq 'auto') {
9313: $linefeed = "\n";
9314: } else {
9315: $linefeed = '<br />'."\n";
9316: }
1.443 albertel 9317: if (defined($one) && defined($two)) {
9318: my $cid=$one.'_'.$two;
9319: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
9320: my $secchange = 0;
9321: my $expire_role_result;
9322: my $modify_section_result;
1.628 raeburn 9323: if ($oldsec ne '-1') {
9324: if ($oldsec ne $sec) {
1.443 albertel 9325: $secchange = 1;
1.628 raeburn 9326: my $now = time;
1.443 albertel 9327: my $uurl='/'.$cid;
9328: $uurl=~s/\_/\//g;
9329: if ($oldsec) {
9330: $uurl.='/'.$oldsec;
9331: }
1.626 raeburn 9332: $oldsecurl = $uurl;
1.628 raeburn 9333: $expire_role_result =
1.652 raeburn 9334: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 9335: if ($env{'request.course.sec'} ne '') {
9336: if ($expire_role_result eq 'refused') {
9337: my @roles = ('st');
9338: my @statuses = ('previous');
9339: my @roledoms = ($one);
9340: my $withsec = 1;
9341: my %roleshash =
9342: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
9343: \@statuses,\@roles,\@roledoms,$withsec);
9344: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
9345: my ($oldstart,$oldend) =
9346: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
9347: if ($oldend > 0 && $oldend <= $now) {
9348: $expire_role_result = 'ok';
9349: }
9350: }
9351: }
9352: }
1.443 albertel 9353: $result = $expire_role_result;
9354: }
9355: }
9356: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 9357: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 9358: if ($modify_section_result =~ /^ok/) {
9359: if ($secchange == 1) {
1.628 raeburn 9360: if ($sec eq '') {
9361: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
9362: } else {
9363: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
9364: }
1.443 albertel 9365: } elsif ($oldsec eq '-1') {
1.628 raeburn 9366: if ($sec eq '') {
9367: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
9368: } else {
9369: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9370: }
1.443 albertel 9371: } else {
1.628 raeburn 9372: if ($sec eq '') {
9373: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
9374: } else {
9375: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
9376: }
1.443 albertel 9377: }
9378: } else {
1.628 raeburn 9379: if ($secchange) {
9380: $$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;
9381: } else {
9382: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
9383: }
1.443 albertel 9384: }
9385: $result = $modify_section_result;
9386: } elsif ($secchange == 1) {
1.628 raeburn 9387: if ($oldsec eq '') {
9388: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
9389: } else {
9390: $$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;
9391: }
1.626 raeburn 9392: if ($expire_role_result eq 'refused') {
9393: my $newsecurl = '/'.$cid;
9394: $newsecurl =~ s/\_/\//g;
9395: if ($sec ne '') {
9396: $newsecurl.='/'.$sec;
9397: }
9398: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
9399: if ($sec eq '') {
9400: $$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;
9401: } else {
9402: $$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;
9403: }
9404: }
9405: }
1.443 albertel 9406: }
9407: } else {
1.626 raeburn 9408: $$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 9409: $result = "error: incomplete course id\n";
9410: }
9411: return $result;
9412: }
9413:
9414: ############################################################
9415: ############################################################
9416:
1.566 albertel 9417: sub check_clone {
1.578 raeburn 9418: my ($args,$linefeed) = @_;
1.566 albertel 9419: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
9420: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
9421: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
9422: my $clonemsg;
9423: my $can_clone = 0;
9424:
9425: if ($clonehome eq 'no_host') {
1.578 raeburn 9426: $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 9427: } else {
9428: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 9429: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 9430: $can_clone = 1;
9431: } else {
9432: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
9433: $args->{'clonedomain'},$args->{'clonecourse'});
9434: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 9435: if (grep(/^\*$/,@cloners)) {
9436: $can_clone = 1;
9437: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
9438: $can_clone = 1;
9439: } else {
9440: my %roleshash =
9441: &Apache::lonnet::get_my_roles($args->{'ccuname'},
9442: $args->{'ccdomain'},
9443: 'userroles',['active'],['cc'],
9444: [$args->{'clonedomain'}]);
9445: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
9446: $can_clone = 1;
9447: } else {
9448: $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'});
9449: }
1.566 albertel 9450: }
1.578 raeburn 9451: }
1.566 albertel 9452: }
9453: return ($can_clone, $clonemsg, $cloneid, $clonehome);
9454: }
9455:
1.444 albertel 9456: sub construct_course {
1.541 raeburn 9457: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 9458: my $outcome;
1.541 raeburn 9459: my $linefeed = '<br />'."\n";
9460: if ($context eq 'auto') {
9461: $linefeed = "\n";
9462: }
1.566 albertel 9463:
9464: #
9465: # Are we cloning?
9466: #
9467: my ($can_clone, $clonemsg, $cloneid, $clonehome);
9468: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 9469: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 9470: if ($context ne 'auto') {
1.578 raeburn 9471: if ($clonemsg ne '') {
9472: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
9473: }
1.566 albertel 9474: }
9475: $outcome .= $clonemsg.$linefeed;
9476:
9477: if (!$can_clone) {
9478: return (0,$outcome);
9479: }
9480: }
9481:
1.444 albertel 9482: #
9483: # Open course
9484: #
9485: my $crstype = lc($args->{'crstype'});
9486: my %cenv=();
9487: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
9488: $args->{'cdescr'},
9489: $args->{'curl'},
9490: $args->{'course_home'},
9491: $args->{'nonstandard'},
9492: $args->{'crscode'},
9493: $args->{'ccuname'}.':'.
9494: $args->{'ccdomain'},
9495: $args->{'crstype'});
9496:
9497: # Note: The testing routines depend on this being output; see
9498: # Utils::Course. This needs to at least be output as a comment
9499: # if anyone ever decides to not show this, and Utils::Course::new
9500: # will need to be suitably modified.
1.541 raeburn 9501: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 9502: #
9503: # Check if created correctly
9504: #
1.479 albertel 9505: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 9506: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 9507: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 9508:
1.444 albertel 9509: #
1.566 albertel 9510: # Do the cloning
9511: #
9512: if ($can_clone && $cloneid) {
9513: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
9514: if ($context ne 'auto') {
9515: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
9516: }
9517: $outcome .= $clonemsg.$linefeed;
9518: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 9519: # Copy all files
1.637 www 9520: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 9521: # Restore URL
1.566 albertel 9522: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 9523: # Restore title
1.566 albertel 9524: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 9525: # Mark as cloned
1.566 albertel 9526: $cenv{'clonedfrom'}=$cloneid;
1.638 www 9527: # Need to clone grading mode
9528: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
9529: $cenv{'grading'}=$newenv{'grading'};
9530: # Do not clone these environment entries
9531: &Apache::lonnet::del('environment',
9532: ['default_enrollment_start_date',
9533: 'default_enrollment_end_date',
9534: 'question.email',
9535: 'policy.email',
9536: 'comment.email',
9537: 'pch.users.denied',
1.725 raeburn 9538: 'plc.users.denied',
9539: 'hidefromcat',
9540: 'categories'],
1.638 www 9541: $$crsudom,$$crsunum);
1.444 albertel 9542: }
1.566 albertel 9543:
1.444 albertel 9544: #
9545: # Set environment (will override cloned, if existing)
9546: #
9547: my @sections = ();
9548: my @xlists = ();
9549: if ($args->{'crstype'}) {
9550: $cenv{'type'}=$args->{'crstype'};
9551: }
9552: if ($args->{'crsid'}) {
9553: $cenv{'courseid'}=$args->{'crsid'};
9554: }
9555: if ($args->{'crscode'}) {
9556: $cenv{'internal.coursecode'}=$args->{'crscode'};
9557: }
9558: if ($args->{'crsquota'} ne '') {
9559: $cenv{'internal.coursequota'}=$args->{'crsquota'};
9560: } else {
9561: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
9562: }
9563: if ($args->{'ccuname'}) {
9564: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
9565: ':'.$args->{'ccdomain'};
9566: } else {
9567: $cenv{'internal.courseowner'} = $args->{'curruser'};
9568: }
9569: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
9570: if ($args->{'crssections'}) {
9571: $cenv{'internal.sectionnums'} = '';
9572: if ($args->{'crssections'} =~ m/,/) {
9573: @sections = split/,/,$args->{'crssections'};
9574: } else {
9575: $sections[0] = $args->{'crssections'};
9576: }
9577: if (@sections > 0) {
9578: foreach my $item (@sections) {
9579: my ($sec,$gp) = split/:/,$item;
9580: my $class = $args->{'crscode'}.$sec;
9581: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
9582: $cenv{'internal.sectionnums'} .= $item.',';
9583: unless ($addcheck eq 'ok') {
9584: push @badclasses, $class;
9585: }
9586: }
9587: $cenv{'internal.sectionnums'} =~ s/,$//;
9588: }
9589: }
9590: # do not hide course coordinator from staff listing,
9591: # even if privileged
9592: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9593: # add crosslistings
9594: if ($args->{'crsxlist'}) {
9595: $cenv{'internal.crosslistings'}='';
9596: if ($args->{'crsxlist'} =~ m/,/) {
9597: @xlists = split/,/,$args->{'crsxlist'};
9598: } else {
9599: $xlists[0] = $args->{'crsxlist'};
9600: }
9601: if (@xlists > 0) {
9602: foreach my $item (@xlists) {
9603: my ($xl,$gp) = split/:/,$item;
9604: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
9605: $cenv{'internal.crosslistings'} .= $item.',';
9606: unless ($addcheck eq 'ok') {
9607: push @badclasses, $xl;
9608: }
9609: }
9610: $cenv{'internal.crosslistings'} =~ s/,$//;
9611: }
9612: }
9613: if ($args->{'autoadds'}) {
9614: $cenv{'internal.autoadds'}=$args->{'autoadds'};
9615: }
9616: if ($args->{'autodrops'}) {
9617: $cenv{'internal.autodrops'}=$args->{'autodrops'};
9618: }
9619: # check for notification of enrollment changes
9620: my @notified = ();
9621: if ($args->{'notify_owner'}) {
9622: if ($args->{'ccuname'} ne '') {
9623: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
9624: }
9625: }
9626: if ($args->{'notify_dc'}) {
9627: if ($uname ne '') {
1.630 raeburn 9628: push(@notified,$uname.':'.$udom);
1.444 albertel 9629: }
9630: }
9631: if (@notified > 0) {
9632: my $notifylist;
9633: if (@notified > 1) {
9634: $notifylist = join(',',@notified);
9635: } else {
9636: $notifylist = $notified[0];
9637: }
9638: $cenv{'internal.notifylist'} = $notifylist;
9639: }
9640: if (@badclasses > 0) {
9641: my %lt=&Apache::lonlocal::texthash(
9642: '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',
9643: 'dnhr' => 'does not have rights to access enrollment in these classes',
9644: 'adby' => 'as determined by the policies of your institution on access to official classlists'
9645: );
1.541 raeburn 9646: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
9647: ' ('.$lt{'adby'}.')';
9648: if ($context eq 'auto') {
9649: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 9650: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 9651: foreach my $item (@badclasses) {
9652: if ($context eq 'auto') {
9653: $outcome .= " - $item\n";
9654: } else {
9655: $outcome .= "<li>$item</li>\n";
9656: }
9657: }
9658: if ($context eq 'auto') {
9659: $outcome .= $linefeed;
9660: } else {
1.566 albertel 9661: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 9662: }
9663: }
1.444 albertel 9664: }
9665: if ($args->{'no_end_date'}) {
9666: $args->{'endaccess'} = 0;
9667: }
9668: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9669: $cenv{'internal.autoend'}=$args->{'enrollend'};
9670: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9671: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9672: if ($args->{'showphotos'}) {
9673: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9674: }
9675: $cenv{'internal.authtype'} = $args->{'authtype'};
9676: $cenv{'internal.autharg'} = $args->{'autharg'};
9677: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9678: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9679: 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');
9680: if ($context eq 'auto') {
9681: $outcome .= $krb_msg;
9682: } else {
1.566 albertel 9683: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9684: }
9685: $outcome .= $linefeed;
1.444 albertel 9686: }
9687: }
9688: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9689: if ($args->{'setpolicy'}) {
9690: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9691: }
9692: if ($args->{'setcontent'}) {
9693: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9694: }
9695: }
9696: if ($args->{'reshome'}) {
9697: $cenv{'reshome'}=$args->{'reshome'}.'/';
9698: $cenv{'reshome'}=~s/\/+$/\//;
9699: }
9700: #
9701: # course has keyed access
9702: #
9703: if ($args->{'setkeys'}) {
9704: $cenv{'keyaccess'}='yes';
9705: }
9706: # if specified, key authority is not course, but user
9707: # only active if keyaccess is yes
9708: if ($args->{'keyauth'}) {
1.487 albertel 9709: my ($user,$domain) = split(':',$args->{'keyauth'});
9710: $user = &LONCAPA::clean_username($user);
9711: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9712: if ($user ne '' && $domain ne '') {
1.487 albertel 9713: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9714: }
9715: }
9716:
9717: if ($args->{'disresdis'}) {
9718: $cenv{'pch.roles.denied'}='st';
9719: }
9720: if ($args->{'disablechat'}) {
9721: $cenv{'plc.roles.denied'}='st';
9722: }
9723:
9724: # Record we've not yet viewed the Course Initialization Helper for this
9725: # course
9726: $cenv{'course.helper.not.run'} = 1;
9727: #
9728: # Use new Randomseed
9729: #
9730: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9731: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9732: #
9733: # The encryption code and receipt prefix for this course
9734: #
9735: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9736: $cenv{'internal.encpref'}=100+int(9*rand(99));
9737: #
9738: # By default, use standard grading
9739: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9740:
1.541 raeburn 9741: $outcome .= $linefeed.&mt('Setting environment').': '.
9742: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9743: #
9744: # Open all assignments
9745: #
9746: if ($args->{'openall'}) {
9747: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9748: my %storecontent = ($storeunder => time,
9749: $storeunder.'.type' => 'date_start');
9750:
9751: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9752: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9753: }
9754: #
9755: # Set first page
9756: #
9757: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9758: || ($cloneid)) {
1.445 albertel 9759: use LONCAPA::map;
1.444 albertel 9760: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9761:
9762: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9763: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9764:
1.444 albertel 9765: $outcome .= ($fatal?$errtext:'read ok').' - ';
9766: my $title; my $url;
9767: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 9768: $title=&mt('Syllabus');
1.444 albertel 9769: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9770: } else {
1.690 bisitz 9771: $title=&mt('Navigate Contents');
1.444 albertel 9772: $url='/adm/navmaps';
9773: }
1.445 albertel 9774:
9775: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9776: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9777:
9778: if ($errtext) { $fatal=2; }
1.541 raeburn 9779: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9780: }
1.566 albertel 9781:
9782: return (1,$outcome);
1.444 albertel 9783: }
9784:
9785: ############################################################
9786: ############################################################
9787:
1.378 raeburn 9788: sub course_type {
9789: my ($cid) = @_;
9790: if (!defined($cid)) {
9791: $cid = $env{'request.course.id'};
9792: }
1.404 albertel 9793: if (defined($env{'course.'.$cid.'.type'})) {
9794: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9795: } else {
9796: return 'Course';
1.377 raeburn 9797: }
9798: }
1.156 albertel 9799:
1.406 raeburn 9800: sub group_term {
9801: my $crstype = &course_type();
9802: my %names = (
9803: 'Course' => 'group',
9804: 'Group' => 'team',
9805: );
9806: return $names{$crstype};
9807: }
9808:
1.156 albertel 9809: sub icon {
9810: my ($file)=@_;
1.505 albertel 9811: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9812: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9813: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9814: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9815: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9816: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9817: $curfext.".gif") {
9818: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9819: $curfext.".gif";
9820: }
9821: }
1.249 albertel 9822: return &lonhttpdurl($iconname);
1.154 albertel 9823: }
1.84 albertel 9824:
1.575 albertel 9825: sub lonhttpdurl {
1.692 www 9826: #
9827: # Had been used for "small fry" static images on separate port 8080.
9828: # Modify here if lightweight http functionality desired again.
9829: # Currently eliminated due to increasing firewall issues.
9830: #
1.575 albertel 9831: my ($url)=@_;
1.692 www 9832: return $url;
1.215 albertel 9833: }
9834:
1.213 albertel 9835: sub connection_aborted {
9836: my ($r)=@_;
9837: $r->print(" ");$r->rflush();
9838: my $c = $r->connection;
9839: return $c->aborted();
9840: }
9841:
1.221 foxr 9842: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9843: # strings as 'strings'.
9844: sub escape_single {
1.221 foxr 9845: my ($input) = @_;
1.223 albertel 9846: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9847: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9848: return $input;
9849: }
1.223 albertel 9850:
1.222 foxr 9851: # Same as escape_single, but escape's "'s This
9852: # can be used for "strings"
9853: sub escape_double {
9854: my ($input) = @_;
9855: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9856: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9857: return $input;
9858: }
1.223 albertel 9859:
1.222 foxr 9860: # Escapes the last element of a full URL.
9861: sub escape_url {
9862: my ($url) = @_;
1.238 raeburn 9863: my @urlslices = split(/\//, $url,-1);
1.369 www 9864: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9865: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9866: }
1.462 albertel 9867:
9868: # -------------------------------------------------------- Initliaze user login
9869: sub init_user_environment {
1.463 albertel 9870: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9871: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9872:
9873: my $public=($username eq 'public' && $domain eq 'public');
9874:
9875: # See if old ID present, if so, remove
9876:
9877: my ($filename,$cookie,$userroles);
9878: my $now=time;
9879:
9880: if ($public) {
9881: my $max_public=100;
9882: my $oldest;
9883: my $oldest_time=0;
9884: for(my $next=1;$next<=$max_public;$next++) {
9885: if (-e $lonids."/publicuser_$next.id") {
9886: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9887: if ($mtime<$oldest_time || !$oldest_time) {
9888: $oldest_time=$mtime;
9889: $oldest=$next;
9890: }
9891: } else {
9892: $cookie="publicuser_$next";
9893: last;
9894: }
9895: }
9896: if (!$cookie) { $cookie="publicuser_$oldest"; }
9897: } else {
1.463 albertel 9898: # if this isn't a robot, kill any existing non-robot sessions
9899: if (!$args->{'robot'}) {
9900: opendir(DIR,$lonids);
9901: while ($filename=readdir(DIR)) {
9902: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9903: unlink($lonids.'/'.$filename);
9904: }
1.462 albertel 9905: }
1.463 albertel 9906: closedir(DIR);
1.462 albertel 9907: }
9908: # Give them a new cookie
1.463 albertel 9909: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 9910: : $now.$$.int(rand(10000)));
1.463 albertel 9911: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9912:
9913: # Initialize roles
9914:
9915: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9916: }
9917: # ------------------------------------ Check browser type and MathML capability
9918:
9919: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9920: $clientunicode,$clientos) = &decode_user_agent($r);
9921:
9922: # -------------------------------------- Any accessibility options to remember?
9923: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9924: foreach my $option ('imagesuppress','appletsuppress',
9925: 'embedsuppress','fontenhance','blackwhite') {
9926: if ($form->{$option} eq 'true') {
9927: &Apache::lonnet::put('environment',{$option => 'on'},
9928: $domain,$username);
9929: } else {
9930: &Apache::lonnet::del('environment',[$option],
9931: $domain,$username);
9932: }
9933: }
9934: }
9935: # ------------------------------------------------------------- Get environment
9936:
9937: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9938: my ($tmp) = keys(%userenv);
9939: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9940: # default remote control to off
9941: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9942: } else {
9943: undef(%userenv);
9944: }
9945: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9946: $form->{'interface'}=$userenv{'interface'};
9947: }
9948: $env{'environment.remote'}=$userenv{'remote'};
9949: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9950:
9951: # --------------- Do not trust query string to be put directly into environment
9952: foreach my $option ('imagesuppress','appletsuppress',
9953: 'embedsuppress','fontenhance','blackwhite',
9954: 'interface','localpath','localres') {
9955: $form->{$option}=~s/[\n\r\=]//gs;
9956: }
9957: # --------------------------------------------------------- Write first profile
9958:
9959: {
9960: my %initial_env =
9961: ("user.name" => $username,
9962: "user.domain" => $domain,
9963: "user.home" => $authhost,
9964: "browser.type" => $clientbrowser,
9965: "browser.version" => $clientversion,
9966: "browser.mathml" => $clientmathml,
9967: "browser.unicode" => $clientunicode,
9968: "browser.os" => $clientos,
9969: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9970: "request.course.fn" => '',
9971: "request.course.uri" => '',
9972: "request.course.sec" => '',
9973: "request.role" => 'cm',
9974: "request.role.adv" => $env{'user.adv'},
9975: "request.host" => $ENV{'REMOTE_ADDR'},);
9976:
9977: if ($form->{'localpath'}) {
9978: $initial_env{"browser.localpath"} = $form->{'localpath'};
9979: $initial_env{"browser.localres"} = $form->{'localres'};
9980: }
9981:
9982: if ($public) {
9983: $initial_env{"environment.remote"} = "off";
9984: }
9985: if ($form->{'interface'}) {
9986: $form->{'interface'}=~s/\W//gs;
9987: $initial_env{"browser.interface"} = $form->{'interface'};
9988: $env{'browser.interface'}=$form->{'interface'};
9989: foreach my $option ('imagesuppress','appletsuppress',
9990: 'embedsuppress','fontenhance','blackwhite') {
9991: if (($form->{$option} eq 'true') ||
9992: ($userenv{$option} eq 'on')) {
9993: $initial_env{"browser.$option"} = "on";
9994: }
9995: }
9996: }
9997:
1.724 raeburn 9998: foreach my $tool ('aboutme','blog','portfolio') {
9999: $userenv{'availabletools.'.$tool} =
10000: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
10001: }
10002:
1.462 albertel 10003: $env{'user.environment'} = "$lonids/$cookie.id";
10004:
10005: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
10006: &GDBM_WRCREAT(),0640)) {
10007: &_add_to_env(\%disk_env,\%initial_env);
10008: &_add_to_env(\%disk_env,\%userenv,'environment.');
10009: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 10010: if (ref($args->{'extra_env'})) {
10011: &_add_to_env(\%disk_env,$args->{'extra_env'});
10012: }
1.462 albertel 10013: untie(%disk_env);
10014: } else {
1.705 tempelho 10015: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
10016: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 10017: return 'error: '.$!;
10018: }
10019: }
10020: $env{'request.role'}='cm';
10021: $env{'request.role.adv'}=$env{'user.adv'};
10022: $env{'browser.type'}=$clientbrowser;
10023:
10024: return $cookie;
10025:
10026: }
10027:
10028: sub _add_to_env {
10029: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 10030: if (ref($env_data) eq 'HASH') {
10031: while (my ($key,$value) = each(%$env_data)) {
10032: $idf->{$prefix.$key} = $value;
10033: $env{$prefix.$key} = $value;
10034: }
1.462 albertel 10035: }
10036: }
10037:
1.685 tempelho 10038: # --- Get the symbolic name of a problem and the url
10039: sub get_symb {
10040: my ($request,$silent) = @_;
1.726 raeburn 10041: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 10042: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
10043: if ($symb eq '') {
10044: if (!$silent) {
10045: $request->print("Unable to handle ambiguous references:$url:.");
10046: return ();
10047: }
10048: }
10049: &Apache::lonenc::check_decrypt(\$symb);
10050: return ($symb);
10051: }
10052:
10053: # --------------------------------------------------------------Get annotation
10054:
10055: sub get_annotation {
10056: my ($symb,$enc) = @_;
10057:
10058: my $key = $symb;
10059: if (!$enc) {
10060: $key =
10061: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
10062: }
10063: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
10064: return $annotation{$key};
10065: }
10066:
10067: sub clean_symb {
1.731 raeburn 10068: my ($symb,$delete_enc) = @_;
1.685 tempelho 10069:
10070: &Apache::lonenc::check_decrypt(\$symb);
10071: my $enc = $env{'request.enc'};
1.731 raeburn 10072: if ($delete_enc) {
1.730 raeburn 10073: delete($env{'request.enc'});
10074: }
1.685 tempelho 10075:
10076: return ($symb,$enc);
10077: }
1.462 albertel 10078:
1.41 ng 10079: =pod
10080:
10081: =back
10082:
1.112 bowersj2 10083: =cut
1.41 ng 10084:
1.112 bowersj2 10085: 1;
10086: __END__;
1.41 ng 10087:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>