Annotation of loncom/interface/loncommon.pm, revision 1.636.2.6
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.636.2.6! raeburn 4: # $Id: loncommon.pm,v 1.636.2.5 2008/03/23 23:13:26 raeburn 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.139 matthew 64: use HTML::Entities;
1.334 albertel 65: use Apache::lonhtmlcommon();
66: use Apache::loncoursedata();
1.344 albertel 67: use Apache::lontexconvert();
1.444 albertel 68: use Apache::lonclonecourse();
1.479 albertel 69: use LONCAPA qw(:DEFAULT :match);
1.117 www 70:
1.517 raeburn 71: # ---------------------------------------------- Designs
72: use vars qw(%defaultdesign);
73:
1.22 www 74: my $readit;
75:
1.517 raeburn 76:
1.157 matthew 77: ##
78: ## Global Variables
79: ##
1.46 matthew 80:
1.636.2.4 raeburn 81: # ----------------------------------------------- SSI with retries:
82: #
83:
84: =pod
85:
86: =head1 Server Side include with retries:
87:
88: =over 4
89:
90: =item * &ssi_with_retries(resource,retries form)
91:
92: Performs an ssi with some number of retries. Retries continue either
93: until the result is ok or until the retry count supplied by the
94: caller is exhausted.
95:
96: Inputs:
97:
98: =over 4
99:
100: resource - Identifies the resource to insert.
101:
102: retries - Count of the number of retries allowed.
103:
104: form - Hash that identifies the rendering options.
105:
106: =back
107:
108: Returns:
109:
110: =over 4
111:
112: content - The content of the response. If retries were exhausted this is empty.
113:
114: response - The response from the last attempt (which may or may not have been successful.
115:
116: =back
117:
118: =back
119:
120: =cut
121:
122: sub ssi_with_retries {
123: my ($resource, $retries, %form) = @_;
124:
125:
126: my $ok = 0; # True if we got a good response.
127: my $content;
128: my $response;
129:
130: # Try to get the ssi done. within the retries count:
131:
132: do {
133: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
134: $ok = $response->is_success;
1.636.2.6! raeburn 135: if (!$ok) {
! 136: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
! 137: }
1.636.2.4 raeburn 138: $retries--;
139: } while (!$ok && ($retries > 0));
140:
141: if (!$ok) {
142: $content = ''; # On error return an empty content.
143: }
144: return ($content, $response);
145:
146: }
147:
148:
149:
1.20 www 150: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 151: my %language;
1.124 www 152: my %supported_language;
1.12 harris41 153: my %cprtag;
1.192 taceyjo1 154: my %scprtag;
1.351 www 155: my %fe; my %fd; my %fm;
1.41 ng 156: my %category_extensions;
1.12 harris41 157:
1.46 matthew 158: # ---------------------------------------------- Thesaurus variables
1.144 matthew 159: #
160: # %Keywords:
161: # A hash used by &keyword to determine if a word is considered a keyword.
162: # $thesaurus_db_file
163: # Scalar containing the full path to the thesaurus database.
1.46 matthew 164:
165: my %Keywords;
166: my $thesaurus_db_file;
167:
1.144 matthew 168: #
169: # Initialize values from language.tab, copyright.tab, filetypes.tab,
170: # thesaurus.tab, and filecategories.tab.
171: #
1.18 www 172: BEGIN {
1.46 matthew 173: # Variable initialization
174: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
175: #
1.22 www 176: unless ($readit) {
1.12 harris41 177: # ------------------------------------------------------------------- languages
178: {
1.158 raeburn 179: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
180: '/language.tab';
181: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 182: while (my $line = <$fh>) {
183: next if ($line=~/^\#/);
184: chomp($line);
185: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 186: $language{$key}=$val.' - '.$enc;
187: if ($sup) {
188: $supported_language{$key}=$sup;
189: }
190: }
191: close($fh);
192: }
1.12 harris41 193: }
194: # ------------------------------------------------------------------ copyrights
195: {
1.158 raeburn 196: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
197: '/copyright.tab';
198: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 199: while (my $line = <$fh>) {
200: next if ($line=~/^\#/);
201: chomp($line);
202: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 203: $cprtag{$key}=$val;
204: }
205: close($fh);
206: }
1.12 harris41 207: }
1.351 www 208: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 209: {
210: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
211: '/source_copyright.tab';
212: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 213: while (my $line = <$fh>) {
214: next if ($line =~ /^\#/);
215: chomp($line);
216: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 217: $scprtag{$key}=$val;
218: }
219: close($fh);
220: }
221: }
1.63 www 222:
1.517 raeburn 223: # -------------------------------------------------------------- default domain designs
1.63 www 224: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 225: my $designfile = $designdir.'/default.tab';
226: if ( open (my $fh,"<$designfile") ) {
227: while (my $line = <$fh>) {
228: next if ($line =~ /^\#/);
229: chomp($line);
230: my ($key,$val)=(split(/\=/,$line));
231: if ($val) { $defaultdesign{$key}=$val; }
232: }
233: close($fh);
1.63 www 234: }
235:
1.15 harris41 236: # ------------------------------------------------------------- file categories
237: {
1.158 raeburn 238: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
239: '/filecategories.tab';
240: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 241: while (my $line = <$fh>) {
242: next if ($line =~ /^\#/);
243: chomp($line);
244: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 245: push @{$category_extensions{lc($category)}},$extension;
246: }
247: close($fh);
248: }
249:
1.15 harris41 250: }
1.12 harris41 251: # ------------------------------------------------------------------ file types
252: {
1.158 raeburn 253: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
254: '/filetypes.tab';
255: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 256: while (my $line = <$fh>) {
257: next if ($line =~ /^\#/);
258: chomp($line);
259: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 260: if ($descr ne '') {
261: $fe{$ending}=lc($emb);
262: $fd{$ending}=$descr;
1.351 www 263: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 264: }
265: }
266: close($fh);
267: }
1.12 harris41 268: }
1.22 www 269: &Apache::lonnet::logthis(
1.46 matthew 270: "<font color=yellow>INFO: Read file types</font>");
1.22 www 271: $readit=1;
1.46 matthew 272: } # end of unless($readit)
1.32 matthew 273:
274: }
1.112 bowersj2 275:
1.42 matthew 276: ###############################################################
277: ## HTML and Javascript Helper Functions ##
278: ###############################################################
279:
280: =pod
281:
1.112 bowersj2 282: =head1 HTML and Javascript Functions
1.42 matthew 283:
1.112 bowersj2 284: =over 4
285:
286: =item * browser_and_searcher_javascript ()
287:
288: X<browsing, javascript>X<searching, javascript>Returns a string
289: containing javascript with two functions, C<openbrowser> and
290: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
291: tags.
1.42 matthew 292:
1.112 bowersj2 293: =item * openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 294:
295: inputs: formname, elementname, only, omit
296:
297: formname and elementname indicate the name of the html form and name of
298: the element that the results of the browsing selection are to be placed in.
299:
300: Specifying 'only' will restrict the browser to displaying only files
1.185 www 301: with the given extension. Can be a comma separated list.
1.42 matthew 302:
303: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 304: with the given extension. Can be a comma separated list.
1.42 matthew 305:
1.112 bowersj2 306: =item * opensearcher(formname, elementname) [javascript]
1.42 matthew 307:
308: Inputs: formname, elementname
309:
310: formname and elementname specify the name of the html form and the name
311: of the element the selection from the search results will be placed in.
1.542 raeburn 312:
1.42 matthew 313: =cut
314:
315: sub browser_and_searcher_javascript {
1.199 albertel 316: my ($mode)=@_;
317: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 318: my $resurl=&escape_single(&lastresurl());
1.42 matthew 319: return <<END;
1.219 albertel 320: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 321: var editbrowser = null;
1.135 albertel 322: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 323: var url = '$resurl/?';
1.42 matthew 324: if (editbrowser == null) {
325: url += 'launch=1&';
326: }
327: url += 'catalogmode=interactive&';
1.199 albertel 328: url += 'mode=$mode&';
1.611 albertel 329: url += 'inhibitmenu=yes&';
1.42 matthew 330: url += 'form=' + formname + '&';
331: if (only != null) {
332: url += 'only=' + only + '&';
1.217 albertel 333: } else {
334: url += 'only=&';
335: }
1.42 matthew 336: if (omit != null) {
337: url += 'omit=' + omit + '&';
1.217 albertel 338: } else {
339: url += 'omit=&';
340: }
1.135 albertel 341: if (titleelement != null) {
342: url += 'titleelement=' + titleelement + '&';
1.217 albertel 343: } else {
344: url += 'titleelement=&';
345: }
1.42 matthew 346: url += 'element=' + elementname + '';
347: var title = 'Browser';
1.435 albertel 348: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 349: options += ',width=700,height=600';
350: editbrowser = open(url,title,options,'1');
351: editbrowser.focus();
352: }
353: var editsearcher;
1.135 albertel 354: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 355: var url = '/adm/searchcat?';
356: if (editsearcher == null) {
357: url += 'launch=1&';
358: }
359: url += 'catalogmode=interactive&';
1.199 albertel 360: url += 'mode=$mode&';
1.42 matthew 361: url += 'form=' + formname + '&';
1.135 albertel 362: if (titleelement != null) {
363: url += 'titleelement=' + titleelement + '&';
1.217 albertel 364: } else {
365: url += 'titleelement=&';
366: }
1.42 matthew 367: url += 'element=' + elementname + '';
368: var title = 'Search';
1.435 albertel 369: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 370: options += ',width=700,height=600';
371: editsearcher = open(url,title,options,'1');
372: editsearcher.focus();
373: }
1.219 albertel 374: // END LON-CAPA Internal -->
1.42 matthew 375: END
1.170 www 376: }
377:
378: sub lastresurl {
1.258 albertel 379: if ($env{'environment.lastresurl'}) {
380: return $env{'environment.lastresurl'}
1.170 www 381: } else {
382: return '/res';
383: }
384: }
385:
386: sub storeresurl {
387: my $resurl=&Apache::lonnet::clutter(shift);
388: unless ($resurl=~/^\/res/) { return 0; }
389: $resurl=~s/\/$//;
390: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
391: &Apache::lonnet::appenv('environment.lastresurl' => $resurl);
392: return 1;
1.42 matthew 393: }
394:
1.74 www 395: sub studentbrowser_javascript {
1.111 www 396: unless (
1.258 albertel 397: (($env{'request.course.id'}) &&
1.302 albertel 398: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
399: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
400: '/'.$env{'request.course.sec'})
401: ))
1.258 albertel 402: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 403: ) { return ''; }
1.74 www 404: return (<<'ENDSTDBRW');
405: <script type="text/javascript" language="Javascript" >
406: var stdeditbrowser;
1.558 albertel 407: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74 www 408: var url = '/adm/pickstudent?';
409: var filter;
1.558 albertel 410: if (!ignorefilter) {
411: eval('filter=document.'+formname+'.'+uname+'.value;');
412: }
1.74 www 413: if (filter != null) {
414: if (filter != '') {
415: url += 'filter='+filter+'&';
416: }
417: }
418: url += 'form=' + formname + '&unameelement='+uname+
419: '&udomelement='+udom;
1.111 www 420: if (roleflag) { url+="&roles=1"; }
1.102 www 421: var title = 'Student_Browser';
1.74 www 422: var options = 'scrollbars=1,resizable=1,menubar=0';
423: options += ',width=700,height=600';
424: stdeditbrowser = open(url,title,options,'1');
425: stdeditbrowser.focus();
426: }
427: </script>
428: ENDSTDBRW
429: }
1.42 matthew 430:
1.74 www 431: sub selectstudent_link {
1.111 www 432: my ($form,$unameele,$udomele)=@_;
1.258 albertel 433: if ($env{'request.course.id'}) {
1.302 albertel 434: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
435: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
436: '/'.$env{'request.course.sec'})) {
1.111 www 437: return '';
438: }
439: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607 albertel 440: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 441: }
1.258 albertel 442: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 443: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 444: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 445: }
446: return '';
1.91 www 447: }
448:
449: sub coursebrowser_javascript {
1.468 raeburn 450: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 451: 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 452: my $output = '
1.538 albertel 453: <script type="text/javascript">
1.468 raeburn 454: var stdeditbrowser;'."\n";
455: $output .= <<"ENDSTDBRW";
1.377 raeburn 456: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 457: var url = '/adm/pickcourse?';
1.468 raeburn 458: var domainfilter = '';
459: var formid = getFormIdByName(formname);
460: if (formid > -1) {
461: var domid = getIndexByName(formid,udom);
462: if (domid > -1) {
463: if (document.forms[formid].elements[domid].type == 'select-one') {
464: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
465: }
466: if (document.forms[formid].elements[domid].type == 'hidden') {
467: domainfilter=document.forms[formid].elements[domid].value;
468: }
469: }
1.91 www 470: }
1.128 albertel 471: if (domainfilter != null) {
472: if (domainfilter != '') {
473: url += 'domainfilter='+domainfilter+'&';
474: }
475: }
1.91 www 476: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 477: '&cdomelement='+udom+
478: '&cnameelement='+desc;
1.468 raeburn 479: if (extra_element !=null && extra_element != '') {
1.594 raeburn 480: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 481: url += '&roleelement='+extra_element;
482: if (domainfilter == null || domainfilter == '') {
483: url += '&domainfilter='+extra_element;
484: }
1.234 raeburn 485: }
1.468 raeburn 486: else {
487: if (formname == 'portform') {
488: url += '&setroles='+extra_element;
489: }
490: }
1.230 raeburn 491: }
1.293 raeburn 492: if (multflag !=null && multflag != '') {
493: url += '&multiple='+multflag;
494: }
1.377 raeburn 495: if (crstype == 'Course/Group') {
496: if (formname == 'cu') {
497: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
498: if (crstype == "") {
499: alert("$crs_or_grp_alert");
500: return;
501: }
502: }
503: }
504: if (crstype !=null && crstype != '') {
505: url += '&type='+crstype;
506: }
1.102 www 507: var title = 'Course_Browser';
1.91 www 508: var options = 'scrollbars=1,resizable=1,menubar=0';
509: options += ',width=700,height=600';
510: stdeditbrowser = open(url,title,options,'1');
511: stdeditbrowser.focus();
512: }
1.468 raeburn 513:
514: function getFormIdByName(formname) {
515: for (var i=0;i<document.forms.length;i++) {
516: if (document.forms[i].name == formname) {
517: return i;
518: }
519: }
520: return -1;
521: }
522:
523: function getIndexByName(formid,item) {
524: for (var i=0;i<document.forms[formid].elements.length;i++) {
525: if (document.forms[formid].elements[i].name == item) {
526: return i;
527: }
528: }
529: return -1;
530: }
1.91 www 531: ENDSTDBRW
1.468 raeburn 532: if ($sec_element ne '') {
533: $output .= &setsec_javascript($sec_element,$formname);
534: }
535: $output .= '
536: </script>';
537: return $output;
538: }
539:
540: sub setsec_javascript {
541: my ($sec_element,$formname) = @_;
542: my $setsections = qq|
543: function setSect(sectionlist) {
1.629 raeburn 544: var sectionsArray = new Array();
545: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
546: sectionsArray = sectionlist.split(",");
547: }
1.468 raeburn 548: var numSections = sectionsArray.length;
549: document.$formname.$sec_element.length = 0;
550: if (numSections == 0) {
551: document.$formname.$sec_element.multiple=false;
552: document.$formname.$sec_element.size=1;
553: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
554: } else {
555: if (numSections == 1) {
556: document.$formname.$sec_element.multiple=false;
557: document.$formname.$sec_element.size=1;
558: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
559: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
560: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
561: } else {
562: for (var i=0; i<numSections; i++) {
563: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
564: }
565: document.$formname.$sec_element.multiple=true
566: if (numSections < 3) {
567: document.$formname.$sec_element.size=numSections;
568: } else {
569: document.$formname.$sec_element.size=3;
570: }
571: document.$formname.$sec_element.options[0].selected = false
572: }
573: }
1.91 www 574: }
1.468 raeburn 575: |;
576: return $setsections;
577: }
578:
1.91 www 579:
580: sub selectcourse_link {
1.377 raeburn 581: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 582: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
583: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 584: }
1.42 matthew 585:
1.273 raeburn 586: sub check_uncheck_jscript {
587: my $jscript = <<"ENDSCRT";
588: function checkAll(field) {
589: if (field.length > 0) {
590: for (i = 0; i < field.length; i++) {
591: field[i].checked = true ;
592: }
593: } else {
594: field.checked = true
595: }
596: }
597:
598: function uncheckAll(field) {
599: if (field.length > 0) {
600: for (i = 0; i < field.length; i++) {
601: field[i].checked = false ;
1.543 albertel 602: }
603: } else {
1.273 raeburn 604: field.checked = false ;
605: }
606: }
607: ENDSCRT
608: return $jscript;
609: }
610:
611:
1.42 matthew 612: =pod
1.36 matthew 613:
1.112 bowersj2 614: =item * linked_select_forms(...)
1.36 matthew 615:
616: linked_select_forms returns a string containing a <script></script> block
617: and html for two <select> menus. The select menus will be linked in that
618: changing the value of the first menu will result in new values being placed
619: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 620: order unless a defined order is provided.
1.36 matthew 621:
622: linked_select_forms takes the following ordered inputs:
623:
624: =over 4
625:
1.112 bowersj2 626: =item * $formname, the name of the <form> tag
1.36 matthew 627:
1.112 bowersj2 628: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 629:
1.112 bowersj2 630: =item * $firstdefault, the default value for the first menu
1.36 matthew 631:
1.112 bowersj2 632: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 633:
1.112 bowersj2 634: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 635:
1.112 bowersj2 636: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 637:
1.609 raeburn 638: =item * $menuorder, the order of values in the first menu
639:
1.41 ng 640: =back
641:
1.36 matthew 642: Below is an example of such a hash. Only the 'text', 'default', and
643: 'select2' keys must appear as stated. keys(%menu) are the possible
644: values for the first select menu. The text that coincides with the
1.41 ng 645: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 646: and text for the second menu are given in the hash pointed to by
647: $menu{$choice1}->{'select2'}.
648:
1.112 bowersj2 649: my %menu = ( A1 => { text =>"Choice A1" ,
650: default => "B3",
651: select2 => {
652: B1 => "Choice B1",
653: B2 => "Choice B2",
654: B3 => "Choice B3",
655: B4 => "Choice B4"
1.609 raeburn 656: },
657: order => ['B4','B3','B1','B2'],
1.112 bowersj2 658: },
659: A2 => { text =>"Choice A2" ,
660: default => "C2",
661: select2 => {
662: C1 => "Choice C1",
663: C2 => "Choice C2",
664: C3 => "Choice C3"
1.609 raeburn 665: },
666: order => ['C2','C1','C3'],
1.112 bowersj2 667: },
668: A3 => { text =>"Choice A3" ,
669: default => "D6",
670: select2 => {
671: D1 => "Choice D1",
672: D2 => "Choice D2",
673: D3 => "Choice D3",
674: D4 => "Choice D4",
675: D5 => "Choice D5",
676: D6 => "Choice D6",
677: D7 => "Choice D7"
1.609 raeburn 678: },
679: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 680: }
681: );
1.36 matthew 682:
683: =cut
684:
685: sub linked_select_forms {
686: my ($formname,
687: $middletext,
688: $firstdefault,
689: $firstselectname,
690: $secondselectname,
1.609 raeburn 691: $hashref,
692: $menuorder,
1.36 matthew 693: ) = @_;
694: my $second = "document.$formname.$secondselectname";
695: my $first = "document.$formname.$firstselectname";
696: # output the javascript to do the changing
697: my $result = '';
1.219 albertel 698: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 699: $result.="var select2data = new Object();\n";
700: $" = '","';
701: my $debug = '';
702: foreach my $s1 (sort(keys(%$hashref))) {
703: $result.="select2data.d_$s1 = new Object();\n";
704: $result.="select2data.d_$s1.def = new String('".
705: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 706: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 707: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 708: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
709: @s2values = @{$hashref->{$s1}->{'order'}};
710: }
1.36 matthew 711: $result.="\"@s2values\");\n";
712: $result.="select2data.d_$s1.texts = new Array(";
713: my @s2texts;
714: foreach my $value (@s2values) {
715: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
716: }
717: $result.="\"@s2texts\");\n";
718: }
719: $"=' ';
720: $result.= <<"END";
721:
722: function select1_changed() {
723: // Determine new choice
724: var newvalue = "d_" + $first.value;
725: // update select2
726: var values = select2data[newvalue].values;
727: var texts = select2data[newvalue].texts;
728: var select2def = select2data[newvalue].def;
729: var i;
730: // out with the old
731: for (i = 0; i < $second.options.length; i++) {
732: $second.options[i] = null;
733: }
734: // in with the nuclear
735: for (i=0;i<values.length; i++) {
736: $second.options[i] = new Option(values[i]);
1.143 matthew 737: $second.options[i].value = values[i];
1.36 matthew 738: $second.options[i].text = texts[i];
739: if (values[i] == select2def) {
740: $second.options[i].selected = true;
741: }
742: }
743: }
744: </script>
745: END
746: # output the initial values for the selection lists
747: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 748: my @order = sort(keys(%{$hashref}));
749: if (ref($menuorder) eq 'ARRAY') {
750: @order = @{$menuorder};
751: }
752: foreach my $value (@order) {
1.36 matthew 753: $result.=" <option value=\"$value\" ";
1.253 albertel 754: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 755: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 756: }
757: $result .= "</select>\n";
758: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
759: $result .= $middletext;
760: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
761: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 762:
763: my @secondorder = sort(keys(%select2));
764: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
765: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
766: }
767: foreach my $value (@secondorder) {
1.36 matthew 768: $result.=" <option value=\"$value\" ";
1.253 albertel 769: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 770: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 771: }
772: $result .= "</select>\n";
773: # return $debug;
774: return $result;
775: } # end of sub linked_select_forms {
776:
1.45 matthew 777: =pod
1.44 bowersj2 778:
1.112 bowersj2 779: =item * help_open_topic($topic, $text, $stayOnPage, $width, $height)
1.44 bowersj2 780:
1.112 bowersj2 781: Returns a string corresponding to an HTML link to the given help
782: $topic, where $topic corresponds to the name of a .tex file in
783: /home/httpd/html/adm/help/tex, with underscores replaced by
784: spaces.
785:
786: $text will optionally be linked to the same topic, allowing you to
787: link text in addition to the graphic. If you do not want to link
788: text, but wish to specify one of the later parameters, pass an
789: empty string.
790:
791: $stayOnPage is a value that will be interpreted as a boolean. If true,
792: the link will not open a new window. If false, the link will open
793: a new window using Javascript. (Default is false.)
794:
795: $width and $height are optional numerical parameters that will
796: override the width and height of the popped up window, which may
797: be useful for certain help topics with big pictures included.
1.44 bowersj2 798:
799: =cut
800:
801: sub help_open_topic {
1.48 bowersj2 802: my ($topic, $text, $stayOnPage, $width, $height) = @_;
803: $text = "" if (not defined $text);
1.44 bowersj2 804: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 805: if ($env{'browser.interface'} eq 'textual') {
1.79 www 806: $stayOnPage=1;
807: }
1.44 bowersj2 808: $width = 350 if (not defined $width);
809: $height = 400 if (not defined $height);
810: my $filename = $topic;
811: $filename =~ s/ /_/g;
812:
1.48 bowersj2 813: my $template = "";
814: my $link;
1.572 banghart 815:
1.159 www 816: $topic=~s/\W/\_/g;
1.44 bowersj2 817:
1.572 banghart 818: if (!$stayOnPage) {
1.72 bowersj2 819: $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 820: } else {
1.48 bowersj2 821: $link = "/adm/help/${filename}.hlp";
822: }
823:
824: # Add the text
1.572 banghart 825: if ($text ne "") {
1.77 www 826: $template .=
1.572 banghart 827: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
828: "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 829: }
830:
831: # Add the graphic
1.179 matthew 832: my $title = &mt('Online Help');
1.215 albertel 833: my $helpicon=&lonhttpdurl("/adm/help/gif/smallHelp.gif");
1.48 bowersj2 834: $template .= <<"ENDTEMPLATE";
1.436 albertel 835: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 836: ENDTEMPLATE
1.78 www 837: if ($text ne '') { $template.='</td></tr></table>' };
1.44 bowersj2 838: return $template;
839:
1.106 bowersj2 840: }
841:
842: # This is a quicky function for Latex cheatsheet editing, since it
843: # appears in at least four places
844: sub helpLatexCheatsheet {
845: my $other = shift;
846: my $addOther = '';
847: if ($other) {
848: $addOther = Apache::loncommon::help_open_topic($other, shift,
849: undef, undef, 600) .
850: '</td><td>';
851: }
852: return '<table><tr><td>'.
853: $addOther .
1.636 raeburn 854: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
1.106 bowersj2 855: undef,undef,600)
856: .'</td><td>'.
1.636 raeburn 857: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
1.106 bowersj2 858: undef,undef,600)
859: .'</td></tr></table>';
1.172 www 860: }
861:
1.430 albertel 862: sub general_help {
863: my $helptopic='Student_Intro';
864: if ($env{'request.role'}=~/^(ca|au)/) {
865: $helptopic='Authoring_Intro';
866: } elsif ($env{'request.role'}=~/^cc/) {
867: $helptopic='Course_Coordination_Intro';
868: }
869: return $helptopic;
870: }
871:
872: sub update_help_link {
873: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
874: my $origurl = $ENV{'REQUEST_URI'};
875: $origurl=~s|^/~|/priv/|;
876: my $timestamp = time;
877: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
878: $$datum = &escape($$datum);
879: }
880:
881: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
882: my $output .= <<"ENDOUTPUT";
883: <script type="text/javascript">
884: banner_link = '$banner_link';
885: </script>
886: ENDOUTPUT
887: return $output;
888: }
889:
890: # now just updates the help link and generates a blue icon
1.193 raeburn 891: sub help_open_menu {
1.430 albertel 892: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 893: = @_;
1.430 albertel 894: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 895: # only use pop-up help (stayOnPage == 0)
1.552 banghart 896: # if environment.remote is on (using remote control UI)
1.572 banghart 897: if ($env{'browser.interface'} eq 'textual' ||
898: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 899: $stayOnPage=1;
1.430 albertel 900: }
901: my $output;
902: if ($component_help) {
903: if (!$text) {
904: $output=&help_open_topic($component_help,undef,$stayOnPage,
905: $width,$height);
906: } else {
907: my $help_text;
908: $help_text=&unescape($topic);
909: $output='<table><tr><td>'.
910: &help_open_topic($component_help,$help_text,$stayOnPage,
911: $width,$height).'</td></tr></table>';
912: }
913: }
914: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
915: return $output.$banner_link;
916: }
917:
918: sub top_nav_help {
919: my ($text) = @_;
1.436 albertel 920: $text = &mt($text);
1.572 banghart 921: my $stay_on_page =
1.436 albertel 922: ($env{'browser.interface'} eq 'textual' ||
923: $env{'environment.remote'} eq 'off' );
1.572 banghart 924: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 925: : "javascript:helpMenu('open')";
1.572 banghart 926: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 927:
1.201 raeburn 928: my $title = &mt('Get help');
1.436 albertel 929:
930: return <<"END";
931: $banner_link
932: <a href="$link" title="$title">$text</a>
933: END
934: }
935:
936: sub help_menu_js {
937: my ($text) = @_;
938:
939: my $stayOnPage =
940: ($env{'browser.interface'} eq 'textual' ||
941: $env{'environment.remote'} eq 'off' );
942:
943: my $width = 620;
944: my $height = 600;
1.430 albertel 945: my $helptopic=&general_help();
946: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 947: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 948: my $start_page =
949: &Apache::loncommon::start_page('Help Menu', undef,
950: {'frameset' => 1,
951: 'js_ready' => 1,
952: 'add_entries' => {
953: 'border' => '0',
1.579 raeburn 954: 'rows' => "110,*",},});
1.331 albertel 955: my $end_page =
956: &Apache::loncommon::end_page({'frameset' => 1,
957: 'js_ready' => 1,});
958:
1.436 albertel 959: my $template .= <<"ENDTEMPLATE";
960: <script type="text/javascript">
1.253 albertel 961: // <!-- BEGIN LON-CAPA Internal
962: // <![CDATA[
1.430 albertel 963: var banner_link = '';
1.243 raeburn 964: function helpMenu(target) {
965: var caller = this;
966: if (target == 'open') {
967: var newWindow = null;
968: try {
1.262 albertel 969: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 970: }
971: catch(error) {
972: writeHelp(caller);
973: return;
974: }
975: if (newWindow) {
976: caller = newWindow;
977: }
1.193 raeburn 978: }
1.243 raeburn 979: writeHelp(caller);
980: return;
981: }
982: function writeHelp(caller) {
1.430 albertel 983: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 984: caller.document.close()
985: caller.focus()
1.193 raeburn 986: }
1.253 albertel 987: // ]]>
1.219 albertel 988: // END LON-CAPA Internal -->
1.436 albertel 989: </script>
1.193 raeburn 990: ENDTEMPLATE
991: return $template;
992: }
993:
1.172 www 994: sub help_open_bug {
995: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 996: unless ($env{'user.adv'}) { return ''; }
1.172 www 997: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
998: $text = "" if (not defined $text);
999: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1000: if ($env{'browser.interface'} eq 'textual' ||
1001: $env{'environment.remote'} eq 'off' ) {
1.172 www 1002: $stayOnPage=1;
1003: }
1.184 albertel 1004: $width = 600 if (not defined $width);
1005: $height = 600 if (not defined $height);
1.172 www 1006:
1007: $topic=~s/\W+/\+/g;
1008: my $link='';
1009: my $template='';
1.379 albertel 1010: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1011: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1012: if (!$stayOnPage)
1013: {
1014: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1015: }
1016: else
1017: {
1018: $link = $url;
1019: }
1020: # Add the text
1021: if ($text ne "")
1022: {
1023: $template .=
1024: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1025: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1026: }
1027:
1028: # Add the graphic
1.179 matthew 1029: my $title = &mt('Report a Bug');
1.215 albertel 1030: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1031: $template .= <<"ENDTEMPLATE";
1.436 albertel 1032: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1033: ENDTEMPLATE
1034: if ($text ne '') { $template.='</td></tr></table>' };
1035: return $template;
1036:
1037: }
1038:
1039: sub help_open_faq {
1040: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1041: unless ($env{'user.adv'}) { return ''; }
1.172 www 1042: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1043: $text = "" if (not defined $text);
1044: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1045: if ($env{'browser.interface'} eq 'textual' ||
1046: $env{'environment.remote'} eq 'off' ) {
1.172 www 1047: $stayOnPage=1;
1048: }
1049: $width = 350 if (not defined $width);
1050: $height = 400 if (not defined $height);
1051:
1052: $topic=~s/\W+/\+/g;
1053: my $link='';
1054: my $template='';
1055: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1056: if (!$stayOnPage)
1057: {
1058: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1059: }
1060: else
1061: {
1062: $link = $url;
1063: }
1064:
1065: # Add the text
1066: if ($text ne "")
1067: {
1068: $template .=
1.173 www 1069: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1070: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1071: }
1072:
1073: # Add the graphic
1.179 matthew 1074: my $title = &mt('View the FAQ');
1.215 albertel 1075: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1076: $template .= <<"ENDTEMPLATE";
1.436 albertel 1077: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1078: ENDTEMPLATE
1079: if ($text ne '') { $template.='</td></tr></table>' };
1080: return $template;
1081:
1.44 bowersj2 1082: }
1.37 matthew 1083:
1.180 matthew 1084: ###############################################################
1085: ###############################################################
1086:
1.45 matthew 1087: =pod
1088:
1.256 matthew 1089: =item * change_content_javascript():
1090:
1091: This and the next function allow you to create small sections of an
1092: otherwise static HTML page that you can update on the fly with
1093: Javascript, even in Netscape 4.
1094:
1095: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1096: must be written to the HTML page once. It will prove the Javascript
1097: function "change(name, content)". Calling the change function with the
1098: name of the section
1099: you want to update, matching the name passed to C<changable_area>, and
1100: the new content you want to put in there, will put the content into
1101: that area.
1102:
1103: B<Note>: Netscape 4 only reserves enough space for the changable area
1104: to contain room for the original contents. You need to "make space"
1105: for whatever changes you wish to make, and be B<sure> to check your
1106: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1107: it's adequate for updating a one-line status display, but little more.
1108: This script will set the space to 100% width, so you only need to
1109: worry about height in Netscape 4.
1110:
1111: Modern browsers are much less limiting, and if you can commit to the
1112: user not using Netscape 4, this feature may be used freely with
1113: pretty much any HTML.
1114:
1115: =cut
1116:
1117: sub change_content_javascript {
1118: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1119: if ($env{'browser.type'} eq 'netscape' &&
1120: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1121: return (<<NETSCAPE4);
1122: function change(name, content) {
1123: doc = document.layers[name+"___escape"].layers[0].document;
1124: doc.open();
1125: doc.write(content);
1126: doc.close();
1127: }
1128: NETSCAPE4
1129: } else {
1130: # Otherwise, we need to use semi-standards-compliant code
1131: # (technically, "innerHTML" isn't standard but the equivalent
1132: # is really scary, and every useful browser supports it
1133: return (<<DOMBASED);
1134: function change(name, content) {
1135: element = document.getElementById(name);
1136: element.innerHTML = content;
1137: }
1138: DOMBASED
1139: }
1140: }
1141:
1142: =pod
1143:
1144: =item * changable_area($name, $origContent):
1145:
1146: This provides a "changable area" that can be modified on the fly via
1147: the Javascript code provided in C<change_content_javascript>. $name is
1148: the name you will use to reference the area later; do not repeat the
1149: same name on a given HTML page more then once. $origContent is what
1150: the area will originally contain, which can be left blank.
1151:
1152: =cut
1153:
1154: sub changable_area {
1155: my ($name, $origContent) = @_;
1156:
1.258 albertel 1157: if ($env{'browser.type'} eq 'netscape' &&
1158: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1159: # If this is netscape 4, we need to use the Layer tag
1160: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1161: } else {
1162: return "<span id='$name'>$origContent</span>";
1163: }
1164: }
1165:
1166: =pod
1167:
1.590 raeburn 1168: =item * viewport_geometry_js {
1169:
1170: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1171:
1172: =cut
1173:
1174:
1175: sub viewport_geometry_js {
1176: return <<"GEOMETRY";
1177: var Geometry = {};
1178: function init_geometry() {
1179: if (Geometry.init) { return };
1180: Geometry.init=1;
1181: if (window.innerHeight) {
1182: Geometry.getViewportHeight = function() { return window.innerHeight; };
1183: Geometry.getViewportWidth = function() { return window.innerWidth; };
1184: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1185: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1186: }
1187: else if (document.documentElement && document.documentElement.clientHeight) {
1188: Geometry.getViewportHeight =
1189: function() { return document.documentElement.clientHeight; };
1190: Geometry.getViewportWidth =
1191: function() { return document.documentElement.clientWidth; };
1192:
1193: Geometry.getHorizontalScroll =
1194: function() { return document.documentElement.scrollLeft; };
1195: Geometry.getVerticalScroll =
1196: function() { return document.documentElement.scrollTop; };
1197: }
1198: else if (document.body.clientHeight) {
1199: Geometry.getViewportHeight =
1200: function() { return document.body.clientHeight; };
1201: Geometry.getViewportWidth =
1202: function() { return document.body.clientWidth; };
1203: Geometry.getHorizontalScroll =
1204: function() { return document.body.scrollLeft; };
1205: Geometry.getVerticalScroll =
1206: function() { return document.body.scrollTop; };
1207: }
1208: }
1209:
1210: GEOMETRY
1211: }
1212:
1213: =pod
1214:
1215: =item * viewport_size_js {
1216:
1217: 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.
1218:
1219: =cut
1220:
1221: sub viewport_size_js {
1222: my $geometry = &viewport_geometry_js();
1223: return <<"DIMS";
1224:
1225: $geometry
1226:
1227: function getViewportDims(width,height) {
1228: init_geometry();
1229: width.value = Geometry.getViewportWidth();
1230: height.value = Geometry.getViewportHeight();
1231: return;
1232: }
1233:
1234: DIMS
1235: }
1236:
1237: =pod
1238:
1.565 albertel 1239: =item * resize_textarea_js
1240:
1241: emits the needed javascript to resize a textarea to be as big as possible
1242:
1243: creates a function resize_textrea that takes two IDs first should be
1244: the id of the element to resize, second should be the id of a div that
1245: surrounds everything that comes after the textarea, this routine needs
1246: to be attached to the <body> for the onload and onresize events.
1247:
1248:
1249: =cut
1250:
1251: sub resize_textarea_js {
1.590 raeburn 1252: my $geometry = &viewport_geometry_js();
1.565 albertel 1253: return <<"RESIZE";
1254: <script type="text/javascript">
1.590 raeburn 1255: $geometry
1.565 albertel 1256:
1.588 albertel 1257: function getX(element) {
1258: var x = 0;
1259: while (element) {
1260: x += element.offsetLeft;
1261: element = element.offsetParent;
1262: }
1263: return x;
1264: }
1265: function getY(element) {
1266: var y = 0;
1267: while (element) {
1268: y += element.offsetTop;
1269: element = element.offsetParent;
1270: }
1271: return y;
1272: }
1273:
1274:
1.565 albertel 1275: function resize_textarea(textarea_id,bottom_id) {
1276: init_geometry();
1277: var textarea = document.getElementById(textarea_id);
1278: //alert(textarea);
1279:
1.588 albertel 1280: var textarea_top = getY(textarea);
1.565 albertel 1281: var textarea_height = textarea.offsetHeight;
1282: var bottom = document.getElementById(bottom_id);
1.588 albertel 1283: var bottom_top = getY(bottom);
1.565 albertel 1284: var bottom_height = bottom.offsetHeight;
1285: var window_height = Geometry.getViewportHeight();
1.588 albertel 1286: var fudge = 23;
1.565 albertel 1287: var new_height = window_height-fudge-textarea_top-bottom_height;
1288: if (new_height < 300) {
1289: new_height = 300;
1290: }
1291: textarea.style.height=new_height+'px';
1292: }
1293: </script>
1294: RESIZE
1295:
1296: }
1297:
1298: =pod
1299:
1.256 matthew 1300: =back
1.542 raeburn 1301:
1.256 matthew 1302: =head1 Excel and CSV file utility routines
1303:
1304: =over 4
1305:
1306: =cut
1307:
1308: ###############################################################
1309: ###############################################################
1310:
1311: =pod
1312:
1.112 bowersj2 1313: =item * csv_translate($text)
1.37 matthew 1314:
1.185 www 1315: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1316: format.
1317:
1318: =cut
1319:
1.180 matthew 1320: ###############################################################
1321: ###############################################################
1.37 matthew 1322: sub csv_translate {
1323: my $text = shift;
1324: $text =~ s/\"/\"\"/g;
1.209 albertel 1325: $text =~ s/\n/ /g;
1.37 matthew 1326: return $text;
1327: }
1.180 matthew 1328:
1329: ###############################################################
1330: ###############################################################
1331:
1332: =pod
1333:
1334: =item * define_excel_formats
1335:
1336: Define some commonly used Excel cell formats.
1337:
1338: Currently supported formats:
1339:
1340: =over 4
1341:
1342: =item header
1343:
1344: =item bold
1345:
1346: =item h1
1347:
1348: =item h2
1349:
1350: =item h3
1351:
1.256 matthew 1352: =item h4
1353:
1354: =item i
1355:
1.180 matthew 1356: =item date
1357:
1358: =back
1359:
1360: Inputs: $workbook
1361:
1362: Returns: $format, a hash reference.
1363:
1364: =cut
1365:
1366: ###############################################################
1367: ###############################################################
1368: sub define_excel_formats {
1369: my ($workbook) = @_;
1370: my $format;
1371: $format->{'header'} = $workbook->add_format(bold => 1,
1372: bottom => 1,
1373: align => 'center');
1374: $format->{'bold'} = $workbook->add_format(bold=>1);
1375: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1376: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1377: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1378: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1379: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1380: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1381: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1382: return $format;
1383: }
1384:
1385: ###############################################################
1386: ###############################################################
1.113 bowersj2 1387:
1388: =pod
1389:
1.256 matthew 1390: =item * create_workbook
1.255 matthew 1391:
1392: Create an Excel worksheet. If it fails, output message on the
1393: request object and return undefs.
1394:
1395: Inputs: Apache request object
1396:
1397: Returns (undef) on failure,
1398: Excel worksheet object, scalar with filename, and formats
1399: from &Apache::loncommon::define_excel_formats on success
1400:
1401: =cut
1402:
1403: ###############################################################
1404: ###############################################################
1405: sub create_workbook {
1406: my ($r) = @_;
1407: #
1408: # Create the excel spreadsheet
1409: my $filename = '/prtspool/'.
1.258 albertel 1410: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1411: time.'_'.rand(1000000000).'.xls';
1412: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1413: if (! defined($workbook)) {
1414: $r->log_error("Error creating excel spreadsheet $filename: $!");
1415: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1416: "This error has been logged. ".
1417: "Please alert your LON-CAPA administrator").
1418: '</p>');
1419: return (undef);
1420: }
1421: #
1422: $workbook->set_tempdir('/home/httpd/perl/tmp');
1423: #
1424: my $format = &Apache::loncommon::define_excel_formats($workbook);
1425: return ($workbook,$filename,$format);
1426: }
1427:
1428: ###############################################################
1429: ###############################################################
1430:
1431: =pod
1432:
1.256 matthew 1433: =item * create_text_file
1.113 bowersj2 1434:
1.542 raeburn 1435: Create a file to write to and eventually make available to the user.
1.256 matthew 1436: If file creation fails, outputs an error message on the request object and
1437: return undefs.
1.113 bowersj2 1438:
1.256 matthew 1439: Inputs: Apache request object, and file suffix
1.113 bowersj2 1440:
1.256 matthew 1441: Returns (undef) on failure,
1442: Filehandle and filename on success.
1.113 bowersj2 1443:
1444: =cut
1445:
1.256 matthew 1446: ###############################################################
1447: ###############################################################
1448: sub create_text_file {
1449: my ($r,$suffix) = @_;
1450: if (! defined($suffix)) { $suffix = 'txt'; };
1451: my $fh;
1452: my $filename = '/prtspool/'.
1.258 albertel 1453: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1454: time.'_'.rand(1000000000).'.'.$suffix;
1455: $fh = Apache::File->new('>/home/httpd'.$filename);
1456: if (! defined($fh)) {
1457: $r->log_error("Couldn't open $filename for output $!");
1458: $r->print("Problems occured in creating the output file. ".
1459: "This error has been logged. ".
1460: "Please alert your LON-CAPA administrator.");
1.113 bowersj2 1461: }
1.256 matthew 1462: return ($fh,$filename)
1.113 bowersj2 1463: }
1464:
1465:
1.256 matthew 1466: =pod
1.113 bowersj2 1467:
1468: =back
1469:
1470: =cut
1.37 matthew 1471:
1472: ###############################################################
1.33 matthew 1473: ## Home server <option> list generating code ##
1474: ###############################################################
1.35 matthew 1475:
1.169 www 1476: # ------------------------------------------
1477:
1478: sub domain_select {
1479: my ($name,$value,$multiple)=@_;
1480: my %domains=map {
1.514 albertel 1481: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1482: } &Apache::lonnet::all_domains();
1.169 www 1483: if ($multiple) {
1484: $domains{''}=&mt('Any domain');
1.550 albertel 1485: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1486: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1487: } else {
1.550 albertel 1488: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1489: return &select_form($name,$value,%domains);
1490: }
1491: }
1492:
1.282 albertel 1493: #-------------------------------------------
1494:
1495: =pod
1496:
1.519 raeburn 1497: =head1 Routines for form select boxes
1498:
1499: =over 4
1500:
1.287 albertel 1501: =item * multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1502:
1503: Returns a string containing a <select> element int multiple mode
1504:
1505:
1506: Args:
1507: $name - name of the <select> element
1.506 raeburn 1508: $value - scalar or array ref of values that should already be selected
1.282 albertel 1509: $size - number of rows long the select element is
1.283 albertel 1510: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1511: (shown text should already have been &mt())
1.506 raeburn 1512: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1513:
1.282 albertel 1514: =cut
1515:
1516: #-------------------------------------------
1.169 www 1517: sub multiple_select_form {
1.284 albertel 1518: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1519: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1520: my $output='';
1.191 matthew 1521: if (! defined($size)) {
1522: $size = 4;
1.283 albertel 1523: if (scalar(keys(%$hash))<4) {
1524: $size = scalar(keys(%$hash));
1.191 matthew 1525: }
1526: }
1.169 www 1527: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501 banghart 1528: my @order;
1.506 raeburn 1529: if (ref($order) eq 'ARRAY') {
1530: @order = @{$order};
1531: } else {
1532: @order = sort(keys(%$hash));
1.501 banghart 1533: }
1534: if (exists($$hash{'select_form_order'})) {
1535: @order = @{$$hash{'select_form_order'}};
1536: }
1537:
1.284 albertel 1538: foreach my $key (@order) {
1.356 albertel 1539: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1540: $output.='selected="selected" ' if ($selected{$key});
1541: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1542: }
1543: $output.="</select>\n";
1544: return $output;
1545: }
1546:
1.88 www 1547: #-------------------------------------------
1548:
1549: =pod
1550:
1.112 bowersj2 1551: =item * select_form($defdom,$name,%hash)
1.88 www 1552:
1553: Returns a string containing a <select name='$name' size='1'> form to
1554: allow a user to select options from a hash option_name => displayed text.
1555: See lonrights.pm for an example invocation and use.
1556:
1557: =cut
1558:
1559: #-------------------------------------------
1560: sub select_form {
1561: my ($def,$name,%hash) = @_;
1562: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1563: my @keys;
1564: if (exists($hash{'select_form_order'})) {
1565: @keys=@{$hash{'select_form_order'}};
1566: } else {
1567: @keys=sort(keys(%hash));
1568: }
1.356 albertel 1569: foreach my $key (@keys) {
1570: $selectform.=
1571: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1572: ($key eq $def ? 'selected="selected" ' : '').
1573: ">".&mt($hash{$key})."</option>\n";
1.88 www 1574: }
1575: $selectform.="</select>";
1576: return $selectform;
1577: }
1578:
1.475 www 1579: # For display filters
1580:
1581: sub display_filter {
1582: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1583: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475 www 1584: return '<nobr><label>'.&mt('Records [_1]',
1585: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1586: (&mt('all'),10,20,50,100,1000,10000))).
1.478 www 1587: '</label></nobr> <nobr>'.
1.475 www 1588: &mt('Filter [_1]',
1.477 www 1589: &select_form($env{'form.displayfilter'},
1590: 'displayfilter',
1591: ('currentfolder' => 'Current folder/page',
1592: 'containing' => 'Containing phrase',
1593: 'none' => 'None'))).
1.478 www 1594: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475 www 1595: }
1596:
1.167 www 1597: sub gradeleveldescription {
1598: my $gradelevel=shift;
1599: my %gradelevels=(0 => 'Not specified',
1600: 1 => 'Grade 1',
1601: 2 => 'Grade 2',
1602: 3 => 'Grade 3',
1603: 4 => 'Grade 4',
1604: 5 => 'Grade 5',
1605: 6 => 'Grade 6',
1606: 7 => 'Grade 7',
1607: 8 => 'Grade 8',
1608: 9 => 'Grade 9',
1609: 10 => 'Grade 10',
1610: 11 => 'Grade 11',
1611: 12 => 'Grade 12',
1612: 13 => 'Grade 13',
1613: 14 => '100 Level',
1614: 15 => '200 Level',
1615: 16 => '300 Level',
1616: 17 => '400 Level',
1617: 18 => 'Graduate Level');
1618: return &mt($gradelevels{$gradelevel});
1619: }
1620:
1.163 www 1621: sub select_level_form {
1622: my ($deflevel,$name)=@_;
1623: unless ($deflevel) { $deflevel=0; }
1.167 www 1624: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1625: for (my $i=0; $i<=18; $i++) {
1626: $selectform.="<option value=\"$i\" ".
1.253 albertel 1627: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1628: ">".&gradeleveldescription($i)."</option>\n";
1629: }
1630: $selectform.="</select>";
1631: return $selectform;
1.163 www 1632: }
1.167 www 1633:
1.35 matthew 1634: #-------------------------------------------
1635:
1.45 matthew 1636: =pod
1637:
1.563 raeburn 1638: =item * select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35 matthew 1639:
1640: Returns a string containing a <select name='$name' size='1'> form to
1641: allow a user to select the domain to preform an operation in.
1642: See loncreateuser.pm for an example invocation and use.
1643:
1.90 www 1644: If the $includeempty flag is set, it also includes an empty choice ("no domain
1645: selected");
1646:
1.563 raeburn 1647: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1648:
1.35 matthew 1649: =cut
1650:
1651: #-------------------------------------------
1.34 matthew 1652: sub select_dom_form {
1.563 raeburn 1653: my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550 albertel 1654: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1655: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1656: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356 albertel 1657: foreach my $dom (@domains) {
1658: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1659: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1660: if ($showdomdesc) {
1661: if ($dom ne '') {
1662: my $domdesc = &Apache::lonnet::domain($dom,'description');
1663: if ($domdesc ne '') {
1664: $selectdomain .= ' ('.$domdesc.')';
1665: }
1666: }
1667: }
1668: $selectdomain .= "</option>\n";
1.34 matthew 1669: }
1670: $selectdomain.="</select>";
1671: return $selectdomain;
1672: }
1673:
1.35 matthew 1674: #-------------------------------------------
1675:
1.45 matthew 1676: =pod
1677:
1.586 raeburn 1678: =item * home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1679:
1.586 raeburn 1680: input: 4 arguments (two required, two optional) -
1681: $domain - domain of new user
1682: $name - name of form element
1683: $default - Value of 'default' causes a default item to be first
1684: option, and selected by default.
1685: $hide - Value of 'hide' causes hiding of the name of the server,
1686: if 1 server found, or default, if 0 found.
1.594 raeburn 1687: output: returns 2 items:
1.586 raeburn 1688: (a) form element which contains either:
1689: (i) <select name="$name">
1690: <option value="$hostid1">$hostid $servers{$hostid}</option>
1691: <option value="$hostid2">$hostid $servers{$hostid}</option>
1692: </select>
1693: form item if there are multiple library servers in $domain, or
1694: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1695: if there is only one library server in $domain.
1696:
1697: (b) number of library servers found.
1698:
1699: See loncreateuser.pm for example of use.
1.35 matthew 1700:
1701: =cut
1702:
1703: #-------------------------------------------
1.586 raeburn 1704: sub home_server_form_item {
1705: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1706: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1707: my $result;
1708: my $numlib = keys(%servers);
1709: if ($numlib > 1) {
1710: $result .= '<select name="'.$name.'" />'."\n";
1711: if ($default) {
1712: $result .= '<option value="default" selected>'.&mt('default').
1713: '</option>'."\n";
1714: }
1715: foreach my $hostid (sort(keys(%servers))) {
1716: $result.= '<option value="'.$hostid.'">'.
1717: $hostid.' '.$servers{$hostid}."</option>\n";
1718: }
1719: $result .= '</select>'."\n";
1720: } elsif ($numlib == 1) {
1721: my $hostid;
1722: foreach my $item (keys(%servers)) {
1723: $hostid = $item;
1724: }
1725: $result .= '<input type="hidden" name="'.$name.'" value="'.
1726: $hostid.'" />';
1727: if (!$hide) {
1728: $result .= $hostid.' '.$servers{$hostid};
1729: }
1730: $result .= "\n";
1731: } elsif ($default) {
1732: $result .= '<input type="hidden" name="'.$name.
1733: '" value="default" />';
1734: if (!$hide) {
1735: $result .= &mt('default');
1736: }
1737: $result .= "\n";
1.33 matthew 1738: }
1.586 raeburn 1739: return ($result,$numlib);
1.33 matthew 1740: }
1.112 bowersj2 1741:
1742: =pod
1743:
1.534 albertel 1744: =back
1745:
1.112 bowersj2 1746: =cut
1.87 matthew 1747:
1748: ###############################################################
1.112 bowersj2 1749: ## Decoding User Agent ##
1.87 matthew 1750: ###############################################################
1751:
1752: =pod
1753:
1.112 bowersj2 1754: =head1 Decoding the User Agent
1755:
1756: =over 4
1757:
1758: =item * &decode_user_agent()
1.87 matthew 1759:
1760: Inputs: $r
1761:
1762: Outputs:
1763:
1764: =over 4
1765:
1.112 bowersj2 1766: =item * $httpbrowser
1.87 matthew 1767:
1.112 bowersj2 1768: =item * $clientbrowser
1.87 matthew 1769:
1.112 bowersj2 1770: =item * $clientversion
1.87 matthew 1771:
1.112 bowersj2 1772: =item * $clientmathml
1.87 matthew 1773:
1.112 bowersj2 1774: =item * $clientunicode
1.87 matthew 1775:
1.112 bowersj2 1776: =item * $clientos
1.87 matthew 1777:
1778: =back
1779:
1.157 matthew 1780: =back
1781:
1.87 matthew 1782: =cut
1783:
1784: ###############################################################
1785: ###############################################################
1786: sub decode_user_agent {
1.247 albertel 1787: my ($r)=@_;
1.87 matthew 1788: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1789: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1790: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1791: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1792: my $clientbrowser='unknown';
1793: my $clientversion='0';
1794: my $clientmathml='';
1795: my $clientunicode='0';
1796: for (my $i=0;$i<=$#browsertype;$i++) {
1797: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1798: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1799: $clientbrowser=$bname;
1800: $httpbrowser=~/$vreg/i;
1801: $clientversion=$1;
1802: $clientmathml=($clientversion>=$minv);
1803: $clientunicode=($clientversion>=$univ);
1804: }
1805: }
1806: my $clientos='unknown';
1807: if (($httpbrowser=~/linux/i) ||
1808: ($httpbrowser=~/unix/i) ||
1809: ($httpbrowser=~/ux/i) ||
1810: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1811: if (($httpbrowser=~/vax/i) ||
1812: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1813: if ($httpbrowser=~/next/i) { $clientos='next'; }
1814: if (($httpbrowser=~/mac/i) ||
1815: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1816: if ($httpbrowser=~/win/i) { $clientos='win'; }
1817: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1818: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1819: $clientunicode,$clientos,);
1820: }
1821:
1.32 matthew 1822: ###############################################################
1823: ## Authentication changing form generation subroutines ##
1824: ###############################################################
1825: ##
1826: ## All of the authform_xxxxxxx subroutines take their inputs in a
1827: ## hash, and have reasonable default values.
1828: ##
1829: ## formname = the name given in the <form> tag.
1.35 matthew 1830: #-------------------------------------------
1831:
1.45 matthew 1832: =pod
1833:
1.112 bowersj2 1834: =head1 Authentication Routines
1835:
1836: =over 4
1837:
1838: =item * authform_xxxxxx
1.35 matthew 1839:
1840: The authform_xxxxxx subroutines provide javascript and html forms which
1841: handle some of the conveniences required for authentication forms.
1842: This is not an optimal method, but it works.
1843:
1844: See loncreateuser.pm for invocation and use examples.
1845:
1846: =over 4
1847:
1.112 bowersj2 1848: =item * authform_header
1.35 matthew 1849:
1.112 bowersj2 1850: =item * authform_authorwarning
1.35 matthew 1851:
1.112 bowersj2 1852: =item * authform_nochange
1.35 matthew 1853:
1.112 bowersj2 1854: =item * authform_kerberos
1.35 matthew 1855:
1.112 bowersj2 1856: =item * authform_internal
1.35 matthew 1857:
1.112 bowersj2 1858: =item * authform_filesystem
1.35 matthew 1859:
1860: =back
1861:
1.157 matthew 1862: =back
1863:
1.35 matthew 1864: =cut
1865:
1866: #-------------------------------------------
1.32 matthew 1867: sub authform_header{
1868: my %in = (
1869: formname => 'cu',
1.80 albertel 1870: kerb_def_dom => '',
1.32 matthew 1871: @_,
1872: );
1873: $in{'formname'} = 'document.' . $in{'formname'};
1874: my $result='';
1.80 albertel 1875:
1876: #---------------------------------------------- Code for upper case translation
1877: my $Javascript_toUpperCase;
1878: unless ($in{kerb_def_dom}) {
1879: $Javascript_toUpperCase =<<"END";
1880: switch (choice) {
1881: case 'krb': currentform.elements[choicearg].value =
1882: currentform.elements[choicearg].value.toUpperCase();
1883: break;
1884: default:
1885: }
1886: END
1887: } else {
1888: $Javascript_toUpperCase = "";
1889: }
1890:
1.165 raeburn 1891: my $radioval = "'nochange'";
1.591 raeburn 1892: if (defined($in{'curr_authtype'})) {
1893: if ($in{'curr_authtype'} ne '') {
1894: $radioval = "'".$in{'curr_authtype'}."arg'";
1895: }
1.174 matthew 1896: }
1.165 raeburn 1897: my $argfield = 'null';
1.591 raeburn 1898: if (defined($in{'mode'})) {
1.165 raeburn 1899: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 1900: if (defined($in{'curr_autharg'})) {
1901: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 1902: $argfield = "'$in{'curr_autharg'}'";
1903: }
1904: }
1905: }
1906: }
1907:
1.32 matthew 1908: $result.=<<"END";
1909: var current = new Object();
1.165 raeburn 1910: current.radiovalue = $radioval;
1911: current.argfield = $argfield;
1.32 matthew 1912:
1913: function changed_radio(choice,currentform) {
1914: var choicearg = choice + 'arg';
1915: // If a radio button in changed, we need to change the argfield
1916: if (current.radiovalue != choice) {
1917: current.radiovalue = choice;
1918: if (current.argfield != null) {
1919: currentform.elements[current.argfield].value = '';
1920: }
1921: if (choice == 'nochange') {
1922: current.argfield = null;
1923: } else {
1924: current.argfield = choicearg;
1925: switch(choice) {
1926: case 'krb':
1927: currentform.elements[current.argfield].value =
1928: "$in{'kerb_def_dom'}";
1929: break;
1930: default:
1931: break;
1932: }
1933: }
1934: }
1935: return;
1936: }
1.22 www 1937:
1.32 matthew 1938: function changed_text(choice,currentform) {
1939: var choicearg = choice + 'arg';
1940: if (currentform.elements[choicearg].value !='') {
1.80 albertel 1941: $Javascript_toUpperCase
1.32 matthew 1942: // clear old field
1943: if ((current.argfield != choicearg) && (current.argfield != null)) {
1944: currentform.elements[current.argfield].value = '';
1945: }
1946: current.argfield = choicearg;
1947: }
1948: set_auth_radio_buttons(choice,currentform);
1949: return;
1.20 www 1950: }
1.32 matthew 1951:
1952: function set_auth_radio_buttons(newvalue,currentform) {
1953: var i=0;
1954: while (i < currentform.login.length) {
1955: if (currentform.login[i].value == newvalue) { break; }
1956: i++;
1957: }
1958: if (i == currentform.login.length) {
1959: return;
1960: }
1961: current.radiovalue = newvalue;
1962: currentform.login[i].checked = true;
1963: return;
1964: }
1965: END
1966: return $result;
1967: }
1968:
1969: sub authform_authorwarning{
1970: my $result='';
1.144 matthew 1971: $result='<i>'.
1972: &mt('As a general rule, only authors or co-authors should be '.
1973: 'filesystem authenticated '.
1974: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 1975: return $result;
1976: }
1977:
1978: sub authform_nochange{
1979: my %in = (
1980: formname => 'document.cu',
1981: kerb_def_dom => 'MSU.EDU',
1982: @_,
1983: );
1.586 raeburn 1984: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1985: my $result;
1986: if (keys(%can_assign) == 0) {
1987: $result = &mt('Under you current role you are not permitted to change login settings for this user');
1988: } else {
1989: $result = '<label>'.&mt('[_1] Do not change login data',
1990: '<input type="radio" name="login" value="nochange" '.
1991: 'checked="checked" onclick="'.
1.281 albertel 1992: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
1993: '</label>';
1.586 raeburn 1994: }
1.32 matthew 1995: return $result;
1996: }
1997:
1.591 raeburn 1998: sub authform_kerberos {
1.32 matthew 1999: my %in = (
2000: formname => 'document.cu',
2001: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2002: kerb_def_auth => 'krb4',
1.32 matthew 2003: @_,
2004: );
1.586 raeburn 2005: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2006: $autharg,$jscall);
2007: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2008: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2009: $check5 = ' checked="on"';
1.80 albertel 2010: } else {
1.586 raeburn 2011: $check4 = ' checked="on"';
1.80 albertel 2012: }
1.165 raeburn 2013: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2014: if (defined($in{'curr_authtype'})) {
2015: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2016: $krbcheck = ' checked="on"';
1.623 raeburn 2017: if (defined($in{'mode'})) {
2018: if ($in{'mode'} eq 'modifyuser') {
2019: $krbcheck = '';
2020: }
2021: }
1.591 raeburn 2022: if (defined($in{'curr_kerb_ver'})) {
2023: if ($in{'curr_krb_ver'} eq '5') {
2024: $check5 = ' checked="on"';
2025: $check4 = '';
2026: } else {
2027: $check4 = ' checked="on"';
2028: $check5 = '';
2029: }
1.586 raeburn 2030: }
1.591 raeburn 2031: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2032: $krbarg = $in{'curr_autharg'};
2033: }
1.586 raeburn 2034: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2035: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2036: $result =
2037: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2038: $in{'curr_autharg'},$krbver);
2039: } else {
2040: $result =
2041: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2042: }
2043: return $result;
2044: }
2045: }
2046: } else {
2047: if ($authnum == 1) {
2048: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2049: }
2050: }
1.586 raeburn 2051: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2052: return;
1.587 raeburn 2053: } elsif ($authtype eq '') {
1.591 raeburn 2054: if (defined($in{'mode'})) {
1.587 raeburn 2055: if ($in{'mode'} eq 'modifycourse') {
2056: if ($authnum == 1) {
2057: $authtype = '<input type="hidden" name="login" value="krb">';
2058: }
2059: }
2060: }
1.586 raeburn 2061: }
2062: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2063: if ($authtype eq '') {
2064: $authtype = '<input type="radio" name="login" value="krb" '.
2065: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2066: $krbcheck.' />';
2067: }
2068: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2069: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2070: $in{'curr_authtype'} eq 'krb5') ||
2071: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2072: $in{'curr_authtype'} eq 'krb4')) {
2073: $result .= &mt
1.144 matthew 2074: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2075: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2076: '<label>'.$authtype,
1.281 albertel 2077: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2078: 'value="'.$krbarg.'" '.
1.144 matthew 2079: 'onchange="'.$jscall.'" />',
1.281 albertel 2080: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2081: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2082: '</label>');
1.586 raeburn 2083: } elsif ($can_assign{'krb4'}) {
2084: $result .= &mt
2085: ('[_1] Kerberos authenticated with domain [_2] '.
2086: '[_3] Version 4 [_4]',
2087: '<label>'.$authtype,
2088: '</label><input type="text" size="10" name="krbarg" '.
2089: 'value="'.$krbarg.'" '.
2090: 'onchange="'.$jscall.'" />',
2091: '<label><input type="hidden" name="krbver" value="4" />',
2092: '</label>');
2093: } elsif ($can_assign{'krb5'}) {
2094: $result .= &mt
2095: ('[_1] Kerberos authenticated with domain [_2] '.
2096: '[_3] Version 5 [_4]',
2097: '<label>'.$authtype,
2098: '</label><input type="text" size="10" name="krbarg" '.
2099: 'value="'.$krbarg.'" '.
2100: 'onchange="'.$jscall.'" />',
2101: '<label><input type="hidden" name="krbver" value="5" />',
2102: '</label>');
2103: }
1.32 matthew 2104: return $result;
2105: }
2106:
2107: sub authform_internal{
1.586 raeburn 2108: my %in = (
1.32 matthew 2109: formname => 'document.cu',
2110: kerb_def_dom => 'MSU.EDU',
2111: @_,
2112: );
1.586 raeburn 2113: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2114: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2115: if (defined($in{'curr_authtype'})) {
2116: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2117: if ($can_assign{'int'}) {
2118: $intcheck = 'checked="on" ';
1.623 raeburn 2119: if (defined($in{'mode'})) {
2120: if ($in{'mode'} eq 'modifyuser') {
2121: $intcheck = '';
2122: }
2123: }
1.591 raeburn 2124: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2125: $intarg = $in{'curr_autharg'};
2126: }
2127: } else {
2128: $result = &mt('Currently internally authenticated.');
2129: return $result;
1.165 raeburn 2130: }
2131: }
1.586 raeburn 2132: } else {
2133: if ($authnum == 1) {
2134: $authtype = '<input type="hidden" name="login" value="int">';
2135: }
2136: }
2137: if (!$can_assign{'int'}) {
2138: return;
1.587 raeburn 2139: } elsif ($authtype eq '') {
1.591 raeburn 2140: if (defined($in{'mode'})) {
1.587 raeburn 2141: if ($in{'mode'} eq 'modifycourse') {
2142: if ($authnum == 1) {
2143: $authtype = '<input type="hidden" name="login" value="int">';
2144: }
2145: }
2146: }
1.165 raeburn 2147: }
1.586 raeburn 2148: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2149: if ($authtype eq '') {
2150: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2151: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2152: }
1.605 bisitz 2153: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2154: $intarg.'" onchange="'.$jscall.'" />';
2155: $result = &mt
1.144 matthew 2156: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2157: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2158: $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 2159: return $result;
2160: }
2161:
2162: sub authform_local{
2163: my %in = (
2164: formname => 'document.cu',
2165: kerb_def_dom => 'MSU.EDU',
2166: @_,
2167: );
1.586 raeburn 2168: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2169: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2170: if (defined($in{'curr_authtype'})) {
2171: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2172: if ($can_assign{'loc'}) {
2173: $loccheck = 'checked="on" ';
1.623 raeburn 2174: if (defined($in{'mode'})) {
2175: if ($in{'mode'} eq 'modifyuser') {
2176: $loccheck = '';
2177: }
2178: }
1.591 raeburn 2179: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2180: $locarg = $in{'curr_autharg'};
2181: }
2182: } else {
2183: $result = &mt('Currently using local (institutional) authentication.');
2184: return $result;
1.165 raeburn 2185: }
2186: }
1.586 raeburn 2187: } else {
2188: if ($authnum == 1) {
2189: $authtype = '<input type="hidden" name="login" value="loc">';
2190: }
2191: }
2192: if (!$can_assign{'loc'}) {
2193: return;
1.587 raeburn 2194: } elsif ($authtype eq '') {
1.591 raeburn 2195: if (defined($in{'mode'})) {
1.587 raeburn 2196: if ($in{'mode'} eq 'modifycourse') {
2197: if ($authnum == 1) {
2198: $authtype = '<input type="hidden" name="login" value="loc">';
2199: }
2200: }
2201: }
1.165 raeburn 2202: }
1.586 raeburn 2203: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2204: if ($authtype eq '') {
2205: $authtype = '<input type="radio" name="login" value="loc" '.
2206: $loccheck.' onchange="'.$jscall.'" onclick="'.
2207: $jscall.'" />';
2208: }
2209: $autharg = '<input type="text" size="10" name="locarg" value="'.
2210: $locarg.'" onchange="'.$jscall.'" />';
2211: $result = &mt('[_1] Local Authentication with argument [_2]',
2212: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2213: return $result;
2214: }
2215:
2216: sub authform_filesystem{
2217: my %in = (
2218: formname => 'document.cu',
2219: kerb_def_dom => 'MSU.EDU',
2220: @_,
2221: );
1.586 raeburn 2222: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2223: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2224: if (defined($in{'curr_authtype'})) {
2225: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2226: if ($can_assign{'fsys'}) {
2227: $fsyscheck = 'checked="on" ';
1.623 raeburn 2228: if (defined($in{'mode'})) {
2229: if ($in{'mode'} eq 'modifyuser') {
2230: $fsyscheck = '';
2231: }
2232: }
1.586 raeburn 2233: } else {
2234: $result = &mt('Currently Filesystem Authenticated.');
2235: return $result;
2236: }
2237: }
2238: } else {
2239: if ($authnum == 1) {
2240: $authtype = '<input type="hidden" name="login" value="fsys">';
2241: }
2242: }
2243: if (!$can_assign{'fsys'}) {
2244: return;
1.587 raeburn 2245: } elsif ($authtype eq '') {
1.591 raeburn 2246: if (defined($in{'mode'})) {
1.587 raeburn 2247: if ($in{'mode'} eq 'modifycourse') {
2248: if ($authnum == 1) {
2249: $authtype = '<input type="hidden" name="login" value="fsys">';
2250: }
2251: }
2252: }
1.586 raeburn 2253: }
2254: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2255: if ($authtype eq '') {
2256: $authtype = '<input type="radio" name="login" value="fsys" '.
2257: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2258: $jscall.'" />';
2259: }
2260: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2261: ' onchange="'.$jscall.'" />';
2262: $result = &mt
1.144 matthew 2263: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2264: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2265: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2266: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2267: 'onchange="'.$jscall.'" />');
1.32 matthew 2268: return $result;
2269: }
2270:
1.586 raeburn 2271: sub get_assignable_auth {
2272: my ($dom) = @_;
2273: if ($dom eq '') {
2274: $dom = $env{'request.role.domain'};
2275: }
2276: my %can_assign = (
2277: krb4 => 1,
2278: krb5 => 1,
2279: int => 1,
2280: loc => 1,
2281: );
2282: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2283: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2284: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2285: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2286: my $context;
2287: if ($env{'request.role'} =~ /^au/) {
2288: $context = 'author';
2289: } elsif ($env{'request.role'} =~ /^dc/) {
2290: $context = 'domain';
2291: } elsif ($env{'request.course.id'}) {
2292: $context = 'course';
2293: }
2294: if ($context) {
2295: if (ref($authhash->{$context}) eq 'HASH') {
2296: %can_assign = %{$authhash->{$context}};
2297: }
2298: }
2299: }
2300: }
2301: my $authnum = 0;
2302: foreach my $key (keys(%can_assign)) {
2303: if ($can_assign{$key}) {
2304: $authnum ++;
2305: }
2306: }
2307: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2308: $authnum --;
2309: }
2310: return ($authnum,%can_assign);
2311: }
2312:
1.80 albertel 2313: ###############################################################
2314: ## Get Authentication Defaults for Domain ##
2315: ###############################################################
2316:
2317: =pod
2318:
1.112 bowersj2 2319: =head1 Domains and Authentication
2320:
2321: Returns default authentication type and an associated argument as
2322: listed in file 'domain.tab'.
2323:
2324: =over 4
2325:
2326: =item * get_auth_defaults
1.80 albertel 2327:
2328: get_auth_defaults($target_domain) returns the default authentication
2329: type and an associated argument (initial password or a kerberos domain).
2330: These values are stored in lonTabs/domain.tab
2331:
2332: ($def_auth, $def_arg) = &get_auth_defaults($target_domain);
2333:
2334: If target_domain is not found in domain.tab, returns nothing ('').
2335:
2336: =cut
2337:
2338: #-------------------------------------------
2339: sub get_auth_defaults {
2340: my $domain=shift;
1.514 albertel 2341: return (&Apache::lonnet::domain($domain,'auth_def'),
2342: &Apache::lonnet::domain($domain,'auth_arg_def'));
2343:
1.80 albertel 2344: }
2345: ###############################################################
2346: ## End Get Authentication Defaults for Domain ##
2347: ###############################################################
2348:
2349: ###############################################################
2350: ## Get Kerberos Defaults for Domain ##
2351: ###############################################################
2352: ##
2353: ## Returns default kerberos version and an associated argument
2354: ## as listed in file domain.tab. If not listed, provides
2355: ## appropriate default domain and kerberos version.
2356: ##
2357: #-------------------------------------------
2358:
2359: =pod
2360:
1.112 bowersj2 2361: =item * get_kerberos_defaults
1.80 albertel 2362:
2363: get_kerberos_defaults($target_domain) returns the default kerberos
2364: version and domain. If not found in domain.tabs, it defaults to
2365: version 4 and the domain of the server.
2366:
2367: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2368:
2369: =cut
2370:
2371: #-------------------------------------------
2372: sub get_kerberos_defaults {
2373: my $domain=shift;
2374: my ($krbdef,$krbdefdom) =
2375: &Apache::loncommon::get_auth_defaults($domain);
2376: unless ($krbdef =~/^krb/ && $krbdefdom) {
2377: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2378: my $krbdefdom=$1;
2379: $krbdefdom=~tr/a-z/A-Z/;
2380: $krbdef = "krb4";
2381: }
2382: return ($krbdef,$krbdefdom);
2383: }
1.112 bowersj2 2384:
2385: =pod
2386:
2387: =back
2388:
2389: =cut
1.32 matthew 2390:
1.46 matthew 2391: ###############################################################
2392: ## Thesaurus Functions ##
2393: ###############################################################
1.20 www 2394:
1.46 matthew 2395: =pod
1.20 www 2396:
1.112 bowersj2 2397: =head1 Thesaurus Functions
2398:
2399: =over 4
2400:
2401: =item * initialize_keywords
1.46 matthew 2402:
2403: Initializes the package variable %Keywords if it is empty. Uses the
2404: package variable $thesaurus_db_file.
2405:
2406: =cut
2407:
2408: ###################################################
2409:
2410: sub initialize_keywords {
2411: return 1 if (scalar keys(%Keywords));
2412: # If we are here, %Keywords is empty, so fill it up
2413: # Make sure the file we need exists...
2414: if (! -e $thesaurus_db_file) {
2415: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2416: " failed because it does not exist");
2417: return 0;
2418: }
2419: # Set up the hash as a database
2420: my %thesaurus_db;
2421: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2422: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2423: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2424: $thesaurus_db_file);
2425: return 0;
2426: }
2427: # Get the average number of appearances of a word.
2428: my $avecount = $thesaurus_db{'average.count'};
2429: # Put keywords (those that appear > average) into %Keywords
2430: while (my ($word,$data)=each (%thesaurus_db)) {
2431: my ($count,undef) = split /:/,$data;
2432: $Keywords{$word}++ if ($count > $avecount);
2433: }
2434: untie %thesaurus_db;
2435: # Remove special values from %Keywords.
1.356 albertel 2436: foreach my $value ('total.count','average.count') {
2437: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2438: }
1.46 matthew 2439: return 1;
2440: }
2441:
2442: ###################################################
2443:
2444: =pod
2445:
1.112 bowersj2 2446: =item * keyword($word)
1.46 matthew 2447:
2448: Returns true if $word is a keyword. A keyword is a word that appears more
2449: than the average number of times in the thesaurus database. Calls
2450: &initialize_keywords
2451:
2452: =cut
2453:
2454: ###################################################
1.20 www 2455:
2456: sub keyword {
1.46 matthew 2457: return if (!&initialize_keywords());
2458: my $word=lc(shift());
2459: $word=~s/\W//g;
2460: return exists($Keywords{$word});
1.20 www 2461: }
1.46 matthew 2462:
2463: ###############################################################
2464:
2465: =pod
1.20 www 2466:
1.112 bowersj2 2467: =item * get_related_words
1.46 matthew 2468:
1.160 matthew 2469: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2470: an array of words. If the keyword is not in the thesaurus, an empty array
2471: will be returned. The order of the words returned is determined by the
2472: database which holds them.
2473:
2474: Uses global $thesaurus_db_file.
2475:
2476: =cut
2477:
2478: ###############################################################
2479: sub get_related_words {
2480: my $keyword = shift;
2481: my %thesaurus_db;
2482: if (! -e $thesaurus_db_file) {
2483: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2484: "failed because the file does not exist");
2485: return ();
2486: }
2487: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2488: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2489: return ();
2490: }
2491: my @Words=();
1.429 www 2492: my $count=0;
1.46 matthew 2493: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2494: # The first element is the number of times
2495: # the word appears. We do not need it now.
1.429 www 2496: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2497: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2498: my $threshold=$mostfrequentcount/10;
2499: foreach my $possibleword (@RelatedWords) {
2500: my ($word,$wordcount)=split(/\,/,$possibleword);
2501: if ($wordcount>$threshold) {
2502: push(@Words,$word);
2503: $count++;
2504: if ($count>10) { last; }
2505: }
1.20 www 2506: }
2507: }
1.46 matthew 2508: untie %thesaurus_db;
2509: return @Words;
1.14 harris41 2510: }
1.46 matthew 2511:
1.112 bowersj2 2512: =pod
2513:
2514: =back
2515:
2516: =cut
1.61 www 2517:
2518: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2519: =pod
2520:
1.112 bowersj2 2521: =head1 User Name Functions
2522:
2523: =over 4
2524:
1.226 albertel 2525: =item * plainname($uname,$udom,$first)
1.81 albertel 2526:
1.112 bowersj2 2527: Takes a users logon name and returns it as a string in
1.226 albertel 2528: "first middle last generation" form
2529: if $first is set to 'lastname' then it returns it as
2530: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2531:
2532: =cut
1.61 www 2533:
1.295 www 2534:
1.81 albertel 2535: ###############################################################
1.61 www 2536: sub plainname {
1.226 albertel 2537: my ($uname,$udom,$first)=@_;
1.537 albertel 2538: return if (!defined($uname) || !defined($udom));
1.295 www 2539: my %names=&getnames($uname,$udom);
1.226 albertel 2540: my $name=&Apache::lonnet::format_name($names{'firstname'},
2541: $names{'middlename'},
2542: $names{'lastname'},
2543: $names{'generation'},$first);
2544: $name=~s/^\s+//;
1.62 www 2545: $name=~s/\s+$//;
2546: $name=~s/\s+/ /g;
1.353 albertel 2547: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2548: return $name;
1.61 www 2549: }
1.66 www 2550:
2551: # -------------------------------------------------------------------- Nickname
1.81 albertel 2552: =pod
2553:
1.112 bowersj2 2554: =item * nickname($uname,$udom)
1.81 albertel 2555:
2556: Gets a users name and returns it as a string as
2557:
2558: ""nickname""
1.66 www 2559:
1.81 albertel 2560: if the user has a nickname or
2561:
2562: "first middle last generation"
2563:
2564: if the user does not
2565:
2566: =cut
1.66 www 2567:
2568: sub nickname {
2569: my ($uname,$udom)=@_;
1.537 albertel 2570: return if (!defined($uname) || !defined($udom));
1.295 www 2571: my %names=&getnames($uname,$udom);
1.68 albertel 2572: my $name=$names{'nickname'};
1.66 www 2573: if ($name) {
2574: $name='"'.$name.'"';
2575: } else {
2576: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2577: $names{'lastname'}.' '.$names{'generation'};
2578: $name=~s/\s+$//;
2579: $name=~s/\s+/ /g;
2580: }
2581: return $name;
2582: }
2583:
1.295 www 2584: sub getnames {
2585: my ($uname,$udom)=@_;
1.537 albertel 2586: return if (!defined($uname) || !defined($udom));
1.433 albertel 2587: if ($udom eq 'public' && $uname eq 'public') {
2588: return ('lastname' => &mt('Public'));
2589: }
1.295 www 2590: my $id=$uname.':'.$udom;
2591: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2592: if ($cached) {
2593: return %{$names};
2594: } else {
2595: my %loadnames=&Apache::lonnet::get('environment',
2596: ['firstname','middlename','lastname','generation','nickname'],
2597: $udom,$uname);
2598: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2599: return %loadnames;
2600: }
2601: }
1.61 www 2602:
1.542 raeburn 2603: # -------------------------------------------------------------------- getemails
2604: =pod
2605:
2606: =item * getemails($uname,$udom)
2607:
2608: Gets a user's email information and returns it as a hash with keys:
2609: notification, critnotification, permanentemail
2610:
2611: For notification and critnotification, values are comma-separated lists
2612: of e-mail address(es); for permanentemail, value is a single e-mail address.
2613:
2614: =cut
2615:
1.466 albertel 2616: sub getemails {
2617: my ($uname,$udom)=@_;
2618: if ($udom eq 'public' && $uname eq 'public') {
2619: return;
2620: }
1.467 www 2621: if (!$udom) { $udom=$env{'user.domain'}; }
2622: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2623: my $id=$uname.':'.$udom;
2624: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2625: if ($cached) {
2626: return %{$names};
2627: } else {
2628: my %loadnames=&Apache::lonnet::get('environment',
2629: ['notification','critnotification',
2630: 'permanentemail'],
2631: $udom,$uname);
2632: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2633: return %loadnames;
2634: }
2635: }
2636:
1.551 albertel 2637: sub flush_email_cache {
2638: my ($uname,$udom)=@_;
2639: if (!$udom) { $udom =$env{'user.domain'}; }
2640: if (!$uname) { $uname=$env{'user.name'}; }
2641: return if ($udom eq 'public' && $uname eq 'public');
2642: my $id=$uname.':'.$udom;
2643: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2644: }
2645:
1.61 www 2646: # ------------------------------------------------------------------ Screenname
1.81 albertel 2647:
2648: =pod
2649:
1.112 bowersj2 2650: =item * screenname($uname,$udom)
1.81 albertel 2651:
2652: Gets a users screenname and returns it as a string
2653:
2654: =cut
1.61 www 2655:
2656: sub screenname {
2657: my ($uname,$udom)=@_;
1.258 albertel 2658: if ($uname eq $env{'user.name'} &&
2659: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2660: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2661: return $names{'screenname'};
1.62 www 2662: }
2663:
1.212 albertel 2664:
1.62 www 2665: # ------------------------------------------------------------- Message Wrapper
2666:
2667: sub messagewrapper {
1.369 www 2668: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2669: return
1.441 albertel 2670: '<a href="/adm/email?compose=individual&'.
2671: 'recname='.$username.'&recdom='.$domain.
2672: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2673: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2674: }
2675: # --------------------------------------------------------------- Notes Wrapper
2676:
2677: sub noteswrapper {
2678: my ($link,$un,$do)=@_;
2679: return
2680: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2681: }
2682: # ------------------------------------------------------------- Aboutme Wrapper
2683:
2684: sub aboutmewrapper {
1.166 www 2685: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2686: if (!defined($username) && !defined($domain)) {
2687: return;
2688: }
1.205 www 2689: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2690: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2691: }
2692:
2693: # ------------------------------------------------------------ Syllabus Wrapper
2694:
2695:
2696: sub syllabuswrapper {
1.109 matthew 2697: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2698: if ($fontcolor) {
2699: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2700: }
1.208 matthew 2701: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2702: }
1.14 harris41 2703:
1.208 matthew 2704: sub track_student_link {
1.268 albertel 2705: my ($linktext,$sname,$sdom,$target,$start) = @_;
2706: my $link ="/adm/trackstudent?";
1.208 matthew 2707: my $title = 'View recent activity';
2708: if (defined($sname) && $sname !~ /^\s*$/ &&
2709: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2710: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2711: $title .= ' of this student';
1.268 albertel 2712: }
1.208 matthew 2713: if (defined($target) && $target !~ /^\s*$/) {
2714: $target = qq{target="$target"};
2715: } else {
2716: $target = '';
2717: }
1.268 albertel 2718: if ($start) { $link.='&start='.$start; }
1.554 albertel 2719: $title = &mt($title);
2720: $linktext = &mt($linktext);
1.448 albertel 2721: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2722: &help_open_topic('View_recent_activity');
1.208 matthew 2723: }
2724:
1.508 www 2725: # ===================================================== Display a student photo
2726:
2727:
1.509 albertel 2728: sub student_image_tag {
1.508 www 2729: my ($domain,$user)=@_;
2730: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2731: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2732: return '<img src="'.$imgsrc.'" align="right" />';
2733: } else {
2734: return '';
2735: }
2736: }
2737:
1.112 bowersj2 2738: =pod
2739:
2740: =back
2741:
2742: =head1 Access .tab File Data
2743:
2744: =over 4
2745:
2746: =item * languageids()
2747:
2748: returns list of all language ids
2749:
2750: =cut
2751:
1.14 harris41 2752: sub languageids {
1.16 harris41 2753: return sort(keys(%language));
1.14 harris41 2754: }
2755:
1.112 bowersj2 2756: =pod
2757:
2758: =item * languagedescription()
2759:
2760: returns description of a specified language id
2761:
2762: =cut
2763:
1.14 harris41 2764: sub languagedescription {
1.125 www 2765: my $code=shift;
2766: return ($supported_language{$code}?'* ':'').
2767: $language{$code}.
1.126 www 2768: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2769: }
2770:
2771: sub plainlanguagedescription {
2772: my $code=shift;
2773: return $language{$code};
2774: }
2775:
2776: sub supportedlanguagecode {
2777: my $code=shift;
2778: return $supported_language{$code};
1.97 www 2779: }
2780:
1.112 bowersj2 2781: =pod
2782:
2783: =item * copyrightids()
2784:
2785: returns list of all copyrights
2786:
2787: =cut
2788:
2789: sub copyrightids {
2790: return sort(keys(%cprtag));
2791: }
2792:
2793: =pod
2794:
2795: =item * copyrightdescription()
2796:
2797: returns description of a specified copyright id
2798:
2799: =cut
2800:
2801: sub copyrightdescription {
1.166 www 2802: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2803: }
1.197 matthew 2804:
2805: =pod
2806:
1.192 taceyjo1 2807: =item * source_copyrightids()
2808:
2809: returns list of all source copyrights
2810:
2811: =cut
2812:
2813: sub source_copyrightids {
2814: return sort(keys(%scprtag));
2815: }
2816:
2817: =pod
2818:
2819: =item * source_copyrightdescription()
2820:
2821: returns description of a specified source copyright id
2822:
2823: =cut
2824:
2825: sub source_copyrightdescription {
2826: return &mt($scprtag{shift(@_)});
2827: }
1.112 bowersj2 2828:
2829: =pod
2830:
2831: =item * filecategories()
2832:
2833: returns list of all file categories
2834:
2835: =cut
2836:
2837: sub filecategories {
2838: return sort(keys(%category_extensions));
2839: }
2840:
2841: =pod
2842:
2843: =item * filecategorytypes()
2844:
2845: returns list of file types belonging to a given file
2846: category
2847:
2848: =cut
2849:
2850: sub filecategorytypes {
1.356 albertel 2851: my ($cat) = @_;
2852: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2853: }
2854:
2855: =pod
2856:
2857: =item * fileembstyle()
2858:
2859: returns embedding style for a specified file type
2860:
2861: =cut
2862:
2863: sub fileembstyle {
2864: return $fe{lc(shift(@_))};
1.169 www 2865: }
2866:
1.351 www 2867: sub filemimetype {
2868: return $fm{lc(shift(@_))};
2869: }
2870:
1.169 www 2871:
2872: sub filecategoryselect {
2873: my ($name,$value)=@_;
1.189 matthew 2874: return &select_form($value,$name,
1.169 www 2875: '' => &mt('Any category'),
2876: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2877: }
2878:
2879: =pod
2880:
2881: =item * filedescription()
2882:
2883: returns description for a specified file type
2884:
2885: =cut
2886:
2887: sub filedescription {
1.188 matthew 2888: my $file_description = $fd{lc(shift())};
2889: $file_description =~ s:([\[\]]):~$1:g;
2890: return &mt($file_description);
1.112 bowersj2 2891: }
2892:
2893: =pod
2894:
2895: =item * filedescriptionex()
2896:
2897: returns description for a specified file type with
2898: extra formatting
2899:
2900: =cut
2901:
2902: sub filedescriptionex {
2903: my $ex=shift;
1.188 matthew 2904: my $file_description = $fd{lc($ex)};
2905: $file_description =~ s:([\[\]]):~$1:g;
2906: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 2907: }
2908:
2909: # End of .tab access
2910: =pod
2911:
2912: =back
2913:
2914: =cut
2915:
2916: # ------------------------------------------------------------------ File Types
2917: sub fileextensions {
2918: return sort(keys(%fe));
2919: }
2920:
1.97 www 2921: # ----------------------------------------------------------- Display Languages
2922: # returns a hash with all desired display languages
2923: #
2924:
2925: sub display_languages {
2926: my %languages=();
1.356 albertel 2927: foreach my $lang (&preferred_languages()) {
2928: $languages{$lang}=1;
1.97 www 2929: }
2930: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 2931: if ($env{'form.displaylanguage'}) {
1.356 albertel 2932: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
2933: $languages{$lang}=1;
1.97 www 2934: }
2935: }
2936: return %languages;
1.14 harris41 2937: }
2938:
1.117 www 2939: sub preferred_languages {
2940: my @languages=();
1.258 albertel 2941: if ($env{'course.'.$env{'request.course.id'}.'.languages'}) {
1.117 www 2942: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
1.258 albertel 2943: $env{'course.'.$env{'request.course.id'}.'.languages'}));
1.177 www 2944: }
1.258 albertel 2945: if ($env{'environment.languages'}) {
1.459 albertel 2946: @languages=(@languages,
2947: split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
1.118 www 2948: }
1.583 albertel 2949: my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'};
1.162 www 2950: if ($browser) {
1.583 albertel 2951: my @browser =
2952: map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
2953: push(@languages,@browser);
1.162 www 2954: }
1.514 albertel 2955: if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) {
1.118 www 2956: @languages=(@languages,
1.514 albertel 2957: &Apache::lonnet::domain($env{'user.domain'},
2958: 'lang_def'));
1.118 www 2959: }
1.514 albertel 2960: if (&Apache::lonnet::domain($env{'request.role.domain'},'lang_def')) {
1.118 www 2961: @languages=(@languages,
1.514 albertel 2962: &Apache::lonnet::domain($env{'request.role.domain'},
2963: 'lang_def'));
1.118 www 2964: }
1.514 albertel 2965: if (&Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
2966: 'lang_def')) {
1.118 www 2967: @languages=(@languages,
1.514 albertel 2968: &Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
2969: 'lang_def'));
1.118 www 2970: }
2971: # turn "en-ca" into "en-ca,en"
2972: my @genlanguages;
1.356 albertel 2973: foreach my $lang (@languages) {
2974: unless ($lang=~/\w/) { next; }
1.583 albertel 2975: push(@genlanguages,$lang);
1.356 albertel 2976: if ($lang=~/(\-|\_)/) {
2977: push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
1.118 www 2978: }
2979: }
1.583 albertel 2980: #uniqueify the languages list
2981: my %count;
2982: @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages;
1.118 www 2983: return @genlanguages;
1.117 www 2984: }
2985:
1.582 albertel 2986: sub languages {
2987: my ($possible_langs) = @_;
2988: my @preferred_langs = &preferred_languages();
2989: if (!ref($possible_langs)) {
2990: if( wantarray ) {
2991: return @preferred_langs;
2992: } else {
2993: return $preferred_langs[0];
2994: }
2995: }
2996: my %possibilities = map { $_ => 1 } (@$possible_langs);
2997: my @preferred_possibilities;
2998: foreach my $preferred_lang (@preferred_langs) {
2999: if (exists($possibilities{$preferred_lang})) {
3000: push(@preferred_possibilities, $preferred_lang);
3001: }
3002: }
3003: if( wantarray ) {
3004: return @preferred_possibilities;
3005: }
3006: return $preferred_possibilities[0];
3007: }
3008:
1.112 bowersj2 3009: ###############################################################
3010: ## Student Answer Attempts ##
3011: ###############################################################
3012:
3013: =pod
3014:
3015: =head1 Alternate Problem Views
3016:
3017: =over 4
3018:
3019: =item * get_previous_attempt($symb, $username, $domain, $course,
3020: $getattempt, $regexp, $gradesub)
3021:
3022: Return string with previous attempt on problem. Arguments:
3023:
3024: =over 4
3025:
3026: =item * $symb: Problem, including path
3027:
3028: =item * $username: username of the desired student
3029:
3030: =item * $domain: domain of the desired student
1.14 harris41 3031:
1.112 bowersj2 3032: =item * $course: Course ID
1.14 harris41 3033:
1.112 bowersj2 3034: =item * $getattempt: Leave blank for all attempts, otherwise put
3035: something
1.14 harris41 3036:
1.112 bowersj2 3037: =item * $regexp: if string matches this regexp, the string will be
3038: sent to $gradesub
1.14 harris41 3039:
1.112 bowersj2 3040: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3041:
1.112 bowersj2 3042: =back
1.14 harris41 3043:
1.112 bowersj2 3044: The output string is a table containing all desired attempts, if any.
1.16 harris41 3045:
1.112 bowersj2 3046: =cut
1.1 albertel 3047:
3048: sub get_previous_attempt {
1.43 ng 3049: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3050: my $prevattempts='';
1.43 ng 3051: no strict 'refs';
1.1 albertel 3052: if ($symb) {
1.3 albertel 3053: my (%returnhash)=
3054: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3055: if ($returnhash{'version'}) {
3056: my %lasthash=();
3057: my $version;
3058: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3059: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3060: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3061: }
1.1 albertel 3062: }
1.596 albertel 3063: $prevattempts=&start_data_table().&start_data_table_header_row();
3064: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3065: foreach my $key (sort(keys(%lasthash))) {
3066: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3067: if ($#parts > 0) {
1.31 albertel 3068: my $data=$parts[-1];
3069: pop(@parts);
1.596 albertel 3070: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3071: } else {
1.41 ng 3072: if ($#parts == 0) {
3073: $prevattempts.='<th>'.$parts[0].'</th>';
3074: } else {
3075: $prevattempts.='<th>'.$ign.'</th>';
3076: }
1.31 albertel 3077: }
1.16 harris41 3078: }
1.596 albertel 3079: $prevattempts.=&end_data_table_header_row();
1.40 ng 3080: if ($getattempt eq '') {
3081: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3082: $prevattempts.=&start_data_table_row().
3083: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3084: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3085: my $value = &format_previous_attempt_value($key,
3086: $returnhash{$version.':'.$key});
3087: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3088: }
1.596 albertel 3089: $prevattempts.=&end_data_table_row();
1.40 ng 3090: }
1.1 albertel 3091: }
1.596 albertel 3092: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3093: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3094: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3095: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3096: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3097: }
1.596 albertel 3098: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3099: } else {
1.596 albertel 3100: $prevattempts=
3101: &start_data_table().&start_data_table_row().
3102: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3103: &end_data_table_row().&end_data_table();
1.1 albertel 3104: }
3105: } else {
1.596 albertel 3106: $prevattempts=
3107: &start_data_table().&start_data_table_row().
3108: '<td>'.&mt('No data.').'</td>'.
3109: &end_data_table_row().&end_data_table();
1.1 albertel 3110: }
1.10 albertel 3111: }
3112:
1.581 albertel 3113: sub format_previous_attempt_value {
3114: my ($key,$value) = @_;
3115: if ($key =~ /timestamp/) {
3116: $value = &Apache::lonlocal::locallocaltime($value);
3117: } elsif (ref($value) eq 'ARRAY') {
3118: $value = '('.join(', ', @{ $value }).')';
3119: } else {
3120: $value = &unescape($value);
3121: }
3122: return $value;
3123: }
3124:
3125:
1.107 albertel 3126: sub relative_to_absolute {
3127: my ($url,$output)=@_;
3128: my $parser=HTML::TokeParser->new(\$output);
3129: my $token;
3130: my $thisdir=$url;
3131: my @rlinks=();
3132: while ($token=$parser->get_token) {
3133: if ($token->[0] eq 'S') {
3134: if ($token->[1] eq 'a') {
3135: if ($token->[2]->{'href'}) {
3136: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3137: }
3138: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3139: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3140: } elsif ($token->[1] eq 'base') {
3141: $thisdir=$token->[2]->{'href'};
3142: }
3143: }
3144: }
3145: $thisdir=~s-/[^/]*$--;
1.356 albertel 3146: foreach my $link (@rlinks) {
3147: unless (($link=~/^http:\/\//i) ||
3148: ($link=~/^\//) ||
3149: ($link=~/^javascript:/i) ||
3150: ($link=~/^mailto:/i) ||
3151: ($link=~/^\#/)) {
3152: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3153: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3154: }
3155: }
3156: # -------------------------------------------------- Deal with Applet codebases
3157: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3158: return $output;
3159: }
3160:
1.112 bowersj2 3161: =pod
3162:
3163: =item * get_student_view
3164:
3165: show a snapshot of what student was looking at
3166:
3167: =cut
3168:
1.10 albertel 3169: sub get_student_view {
1.186 albertel 3170: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3171: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3172: my (%form);
1.10 albertel 3173: my @elements=('symb','courseid','domain','username');
3174: foreach my $element (@elements) {
1.186 albertel 3175: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3176: }
1.186 albertel 3177: if (defined($moreenv)) {
3178: %form=(%form,%{$moreenv});
3179: }
1.236 albertel 3180: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3181: $feedurl=&Apache::lonnet::clutter($feedurl);
1.636.2.6! raeburn 3182: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3183: $userview=~s/\<body[^\>]*\>//gi;
3184: $userview=~s/\<\/body\>//gi;
3185: $userview=~s/\<html\>//gi;
3186: $userview=~s/\<\/html\>//gi;
3187: $userview=~s/\<head\>//gi;
3188: $userview=~s/\<\/head\>//gi;
3189: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3190: $userview=&relative_to_absolute($feedurl,$userview);
1.636.2.6! raeburn 3191: if (wantarray) {
! 3192: return ($userview,$response);
! 3193: } else {
! 3194: return $userview;
! 3195: }
! 3196: }
! 3197:
! 3198: sub get_student_view_with_retries {
! 3199: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
! 3200:
! 3201: my $ok = 0; # True if we got a good response.
! 3202: my $content;
! 3203: my $response;
! 3204:
! 3205: # Try to get the student_view done. within the retries count:
! 3206:
! 3207: do {
! 3208: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
! 3209: $ok = $response->is_success;
! 3210: if (!$ok) {
! 3211: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
! 3212: }
! 3213: $retries--;
! 3214: } while (!$ok && ($retries > 0));
! 3215:
! 3216: if (!$ok) {
! 3217: $content = ''; # On error return an empty content.
! 3218: }
! 3219: if (wantarray) {
! 3220: return ($content, $response);
! 3221: } else {
! 3222: return $content;
! 3223: }
1.11 albertel 3224: }
3225:
1.112 bowersj2 3226: =pod
3227:
3228: =item * get_student_answers()
3229:
3230: show a snapshot of how student was answering problem
3231:
3232: =cut
3233:
1.11 albertel 3234: sub get_student_answers {
1.100 sakharuk 3235: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3236: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3237: my (%moreenv);
1.11 albertel 3238: my @elements=('symb','courseid','domain','username');
3239: foreach my $element (@elements) {
1.186 albertel 3240: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3241: }
1.186 albertel 3242: $moreenv{'grade_target'}='answer';
3243: %moreenv=(%form,%moreenv);
1.497 raeburn 3244: $feedurl = &Apache::lonnet::clutter($feedurl);
3245: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3246: return $userview;
1.1 albertel 3247: }
1.116 albertel 3248:
3249: =pod
3250:
3251: =item * &submlink()
3252:
1.242 albertel 3253: Inputs: $text $uname $udom $symb $target
1.116 albertel 3254:
3255: Returns: A link to grades.pm such as to see the SUBM view of a student
3256:
3257: =cut
3258:
3259: ###############################################
3260: sub submlink {
1.242 albertel 3261: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3262: if (!($uname && $udom)) {
3263: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3264: &Apache::lonnet::whichuser($symb);
1.116 albertel 3265: if (!$symb) { $symb=$cursymb; }
3266: }
1.254 matthew 3267: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3268: $symb=&escape($symb);
1.242 albertel 3269: if ($target) { $target="target=\"$target\""; }
3270: return '<a href="/adm/grades?&command=submission&'.
3271: 'symb='.$symb.'&student='.$uname.
3272: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3273: }
3274: ##############################################
3275:
3276: =pod
3277:
3278: =item * &pgrdlink()
3279:
3280: Inputs: $text $uname $udom $symb $target
3281:
3282: Returns: A link to grades.pm such as to see the PGRD view of a student
3283:
3284: =cut
3285:
3286: ###############################################
3287: sub pgrdlink {
3288: my $link=&submlink(@_);
3289: $link=~s/(&command=submission)/$1&showgrading=yes/;
3290: return $link;
3291: }
3292: ##############################################
3293:
3294: =pod
3295:
3296: =item * &pprmlink()
3297:
3298: Inputs: $text $uname $udom $symb $target
3299:
3300: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3301: student and a specific resource
1.242 albertel 3302:
3303: =cut
3304:
3305: ###############################################
3306: sub pprmlink {
3307: my ($text,$uname,$udom,$symb,$target)=@_;
3308: if (!($uname && $udom)) {
3309: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3310: &Apache::lonnet::whichuser($symb);
1.242 albertel 3311: if (!$symb) { $symb=$cursymb; }
3312: }
1.254 matthew 3313: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3314: $symb=&escape($symb);
1.242 albertel 3315: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3316: return '<a href="/adm/parmset?command=set&'.
3317: 'symb='.$symb.'&uname='.$uname.
3318: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3319: }
3320: ##############################################
1.37 matthew 3321:
1.112 bowersj2 3322: =pod
3323:
3324: =back
3325:
3326: =cut
3327:
1.37 matthew 3328: ###############################################
1.51 www 3329:
3330:
3331: sub timehash {
3332: my @ltime=localtime(shift);
3333: return ( 'seconds' => $ltime[0],
3334: 'minutes' => $ltime[1],
3335: 'hours' => $ltime[2],
3336: 'day' => $ltime[3],
3337: 'month' => $ltime[4]+1,
3338: 'year' => $ltime[5]+1900,
3339: 'weekday' => $ltime[6],
3340: 'dayyear' => $ltime[7]+1,
3341: 'dlsav' => $ltime[8] );
3342: }
3343:
1.370 www 3344: sub utc_string {
3345: my ($date)=@_;
1.371 www 3346: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3347: }
3348:
1.51 www 3349: sub maketime {
3350: my %th=@_;
3351: return POSIX::mktime(
3352: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3353: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3354: }
3355:
3356: #########################################
1.51 www 3357:
3358: sub findallcourses {
1.482 raeburn 3359: my ($roles,$uname,$udom) = @_;
1.355 albertel 3360: my %roles;
3361: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3362: my %courses;
1.51 www 3363: my $now=time;
1.482 raeburn 3364: if (!defined($uname)) {
3365: $uname = $env{'user.name'};
3366: }
3367: if (!defined($udom)) {
3368: $udom = $env{'user.domain'};
3369: }
3370: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3371: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3372: if (!%roles) {
3373: %roles = (
3374: cc => 1,
3375: in => 1,
3376: ep => 1,
3377: ta => 1,
3378: cr => 1,
3379: st => 1,
3380: );
3381: }
3382: foreach my $entry (keys(%roleshash)) {
3383: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3384: if ($trole =~ /^cr/) {
3385: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3386: } else {
3387: next if (!exists($roles{$trole}));
3388: }
3389: if ($tend) {
3390: next if ($tend < $now);
3391: }
3392: if ($tstart) {
3393: next if ($tstart > $now);
3394: }
3395: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3396: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3397: if ($secpart eq '') {
3398: ($cnum,$role) = split(/_/,$cnumpart);
3399: $sec = 'none';
3400: $realsec = '';
3401: } else {
3402: $cnum = $cnumpart;
3403: ($sec,$role) = split(/_/,$secpart);
3404: $realsec = $sec;
1.490 raeburn 3405: }
1.482 raeburn 3406: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3407: }
3408: } else {
3409: foreach my $key (keys(%env)) {
1.483 albertel 3410: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3411: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3412: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3413: next if ($role eq 'ca' || $role eq 'aa');
3414: next if (%roles && !exists($roles{$role}));
3415: my ($starttime,$endtime)=split(/\./,$env{$key});
3416: my $active=1;
3417: if ($starttime) {
3418: if ($now<$starttime) { $active=0; }
3419: }
3420: if ($endtime) {
3421: if ($now>$endtime) { $active=0; }
3422: }
3423: if ($active) {
3424: if ($sec eq '') {
3425: $sec = 'none';
3426: }
3427: $courses{$cdom.'_'.$cnum}{$sec} =
3428: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3429: }
3430: }
1.51 www 3431: }
3432: }
1.474 raeburn 3433: return %courses;
1.51 www 3434: }
1.37 matthew 3435:
1.54 www 3436: ###############################################
1.474 raeburn 3437:
3438: sub blockcheck {
1.482 raeburn 3439: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3440:
3441: if (!defined($udom)) {
3442: $udom = $env{'user.domain'};
3443: }
3444: if (!defined($uname)) {
3445: $uname = $env{'user.name'};
3446: }
3447:
3448: # If uname and udom are for a course, check for blocks in the course.
3449:
3450: if (&Apache::lonnet::is_course($udom,$uname)) {
3451: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3452: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3453: return ($startblock,$endblock);
3454: }
1.474 raeburn 3455:
1.502 raeburn 3456: my $startblock = 0;
3457: my $endblock = 0;
1.482 raeburn 3458: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3459:
1.490 raeburn 3460: # If uname is for a user, and activity is course-specific, i.e.,
3461: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3462:
1.490 raeburn 3463: if (($activity eq 'boards' || $activity eq 'chat' ||
3464: $activity eq 'groups') && ($env{'request.course.id'})) {
3465: foreach my $key (keys(%live_courses)) {
3466: if ($key ne $env{'request.course.id'}) {
3467: delete($live_courses{$key});
3468: }
3469: }
3470: }
3471:
3472: my $otheruser = 0;
3473: my %own_courses;
3474: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3475: # Resource belongs to user other than current user.
3476: $otheruser = 1;
3477: # Gather courses for current user
3478: %own_courses =
3479: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3480: }
3481:
3482: # Gather active course roles - course coordinator, instructor,
3483: # exam proctor, ta, student, or custom role.
1.474 raeburn 3484:
3485: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3486: my ($cdom,$cnum);
3487: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3488: $cdom = $env{'course.'.$course.'.domain'};
3489: $cnum = $env{'course.'.$course.'.num'};
3490: } else {
1.490 raeburn 3491: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3492: }
3493: my $no_ownblock = 0;
3494: my $no_userblock = 0;
1.533 raeburn 3495: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3496: # Check if current user has 'evb' priv for this
3497: if (defined($own_courses{$course})) {
3498: foreach my $sec (keys(%{$own_courses{$course}})) {
3499: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3500: if ($sec ne 'none') {
3501: $checkrole .= '/'.$sec;
3502: }
3503: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3504: $no_ownblock = 1;
3505: last;
3506: }
3507: }
3508: }
3509: # if they have 'evb' priv and are currently not playing student
3510: next if (($no_ownblock) &&
3511: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3512: }
1.474 raeburn 3513: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3514: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3515: if ($sec ne 'none') {
1.482 raeburn 3516: $checkrole .= '/'.$sec;
1.474 raeburn 3517: }
1.490 raeburn 3518: if ($otheruser) {
3519: # Resource belongs to user other than current user.
3520: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3521: my ($trole,$tdom,$tnum,$tsec);
3522: my $entry = $live_courses{$course}{$sec};
3523: if ($entry =~ /^cr/) {
3524: ($trole,$tdom,$tnum,$tsec) =
3525: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3526: } else {
3527: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3528: }
3529: my ($spec,$area,$trest,%allroles,%userroles);
3530: $area = '/'.$tdom.'/'.$tnum;
3531: $trest = $tnum;
3532: if ($tsec ne '') {
3533: $area .= '/'.$tsec;
3534: $trest .= '/'.$tsec;
3535: }
3536: $spec = $trole.'.'.$area;
3537: if ($trole =~ /^cr/) {
3538: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3539: $tdom,$spec,$trest,$area);
3540: } else {
3541: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3542: $tdom,$spec,$trest,$area);
3543: }
3544: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3545: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3546: if ($1) {
3547: $no_userblock = 1;
3548: last;
3549: }
3550: }
1.490 raeburn 3551: } else {
3552: # Resource belongs to current user
3553: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3554: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3555: $no_ownblock = 1;
3556: last;
3557: }
1.474 raeburn 3558: }
3559: }
3560: # if they have the evb priv and are currently not playing student
1.482 raeburn 3561: next if (($no_ownblock) &&
1.491 albertel 3562: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3563: next if ($no_userblock);
1.474 raeburn 3564:
1.490 raeburn 3565: # Retrieve blocking times and identity of blocker for course
3566: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3567:
3568: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3569: if (($start != 0) &&
3570: (($startblock == 0) || ($startblock > $start))) {
3571: $startblock = $start;
3572: }
3573: if (($end != 0) &&
3574: (($endblock == 0) || ($endblock < $end))) {
3575: $endblock = $end;
3576: }
1.490 raeburn 3577: }
3578: return ($startblock,$endblock);
3579: }
3580:
3581: sub get_blocks {
3582: my ($setters,$activity,$cdom,$cnum) = @_;
3583: my $startblock = 0;
3584: my $endblock = 0;
3585: my $course = $cdom.'_'.$cnum;
3586: $setters->{$course} = {};
3587: $setters->{$course}{'staff'} = [];
3588: $setters->{$course}{'times'} = [];
3589: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3590: foreach my $record (keys(%records)) {
3591: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3592: if ($start <= time && $end >= time) {
3593: my ($staff_name,$staff_dom,$title,$blocks) =
3594: &parse_block_record($records{$record});
3595: if ($blocks->{$activity} eq 'on') {
3596: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3597: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3598: if ( ($startblock == 0) || ($startblock > $start) ) {
3599: $startblock = $start;
1.490 raeburn 3600: }
1.491 albertel 3601: if ( ($endblock == 0) || ($endblock < $end) ) {
3602: $endblock = $end;
1.474 raeburn 3603: }
3604: }
3605: }
3606: }
3607: return ($startblock,$endblock);
3608: }
3609:
3610: sub parse_block_record {
3611: my ($record) = @_;
3612: my ($setuname,$setudom,$title,$blocks);
3613: if (ref($record) eq 'HASH') {
3614: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3615: $title = &unescape($record->{'event'});
3616: $blocks = $record->{'blocks'};
3617: } else {
3618: my @data = split(/:/,$record,3);
3619: if (scalar(@data) eq 2) {
3620: $title = $data[1];
3621: ($setuname,$setudom) = split(/@/,$data[0]);
3622: } else {
3623: ($setuname,$setudom,$title) = @data;
3624: }
3625: $blocks = { 'com' => 'on' };
3626: }
3627: return ($setuname,$setudom,$title,$blocks);
3628: }
3629:
3630: sub build_block_table {
3631: my ($startblock,$endblock,$setters) = @_;
3632: my %lt = &Apache::lonlocal::texthash(
3633: 'cacb' => 'Currently active communication blocks',
3634: 'cour' => 'Course',
3635: 'dura' => 'Duration',
3636: 'blse' => 'Block set by'
3637: );
3638: my $output;
1.476 raeburn 3639: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3640: $output .= &start_data_table();
3641: $output .= '
3642: <tr>
3643: <th>'.$lt{'cour'}.'</th>
3644: <th>'.$lt{'dura'}.'</th>
3645: <th>'.$lt{'blse'}.'</th>
3646: </tr>
3647: ';
3648: foreach my $course (keys(%{$setters})) {
3649: my %courseinfo=&Apache::lonnet::coursedescription($course);
3650: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3651: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3652: my $fullname = &plainname($uname,$udom);
3653: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3654: && $env{'user.name'} ne 'public'
3655: && $env{'user.domain'} ne 'public') {
3656: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3657: }
1.474 raeburn 3658: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3659: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3660: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3661: $output .= &Apache::loncommon::start_data_table_row().
3662: '<td>'.$courseinfo{'description'}.'</td>'.
3663: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3664: '<td>'.$fullname.'</td>'.
1.474 raeburn 3665: &Apache::loncommon::end_data_table_row();
3666: }
3667: }
3668: $output .= &end_data_table();
3669: }
3670:
1.490 raeburn 3671: sub blocking_status {
3672: my ($activity,$uname,$udom) = @_;
3673: my %setters;
3674: my ($blocked,$output,$ownitem,$is_course);
3675: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3676: if ($startblock && $endblock) {
3677: $blocked = 1;
3678: if (wantarray) {
3679: my $category;
3680: if ($activity eq 'boards') {
3681: $category = 'Discussion posts in this course';
3682: } elsif ($activity eq 'blogs') {
3683: $category = 'Blogs';
3684: } elsif ($activity eq 'port') {
3685: if (defined($uname) && defined($udom)) {
3686: if ($uname eq $env{'user.name'} &&
3687: $udom eq $env{'user.domain'}) {
3688: $ownitem = 1;
3689: }
3690: }
3691: $is_course = &Apache::lonnet::is_course($udom,$uname);
3692: if ($ownitem) {
3693: $category = 'Your portfolio files';
3694: } elsif ($is_course) {
3695: my $coursedesc;
3696: foreach my $course (keys(%setters)) {
3697: my %courseinfo =
3698: &Apache::lonnet::coursedescription($course);
3699: $coursedesc = $courseinfo{'description'};
3700: }
3701: $category = "Group files in the course '$coursedesc'";
3702: } else {
3703: $category = 'Portfolio files belonging to ';
3704: if ($env{'user.name'} eq 'public' &&
3705: $env{'user.domain'} eq 'public') {
3706: $category .= &plainname($uname,$udom);
3707: } else {
3708: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3709: }
3710: }
3711: } elsif ($activity eq 'groups') {
3712: $category = 'Groups in this course';
3713: }
3714: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3715: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3716: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3717: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3718: $output .= &build_block_table($startblock,$endblock,\%setters);
3719: }
3720: }
3721: }
3722: if (wantarray) {
3723: return ($blocked,$output);
3724: } else {
3725: return $blocked;
3726: }
3727: }
3728:
1.60 matthew 3729: ###############################################
3730:
3731: =pod
3732:
1.112 bowersj2 3733: =head1 Domain Template Functions
3734:
3735: =over 4
3736:
3737: =item * &determinedomain()
1.60 matthew 3738:
3739: Inputs: $domain (usually will be undef)
3740:
1.63 www 3741: Returns: Determines which domain should be used for designs
1.60 matthew 3742:
3743: =cut
1.54 www 3744:
1.60 matthew 3745: ###############################################
1.63 www 3746: sub determinedomain {
3747: my $domain=shift;
1.531 albertel 3748: if (! $domain) {
1.60 matthew 3749: # Determine domain if we have not been given one
3750: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3751: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3752: if ($env{'request.role.domain'}) {
3753: $domain=$env{'request.role.domain'};
1.60 matthew 3754: }
3755: }
1.63 www 3756: return $domain;
3757: }
3758: ###############################################
1.517 raeburn 3759:
1.518 albertel 3760: sub devalidate_domconfig_cache {
3761: my ($udom)=@_;
3762: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3763: }
3764:
3765: # ---------------------- Get domain configuration for a domain
3766: sub get_domainconf {
3767: my ($udom) = @_;
3768: my $cachetime=1800;
3769: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3770: if (defined($cached)) { return %{$result}; }
3771:
3772: my %domconfig = &Apache::lonnet::get_dom('configuration',
3773: ['login','rolecolors'],$udom);
1.632 raeburn 3774: my (%designhash,%legacy);
1.518 albertel 3775: if (keys(%domconfig) > 0) {
3776: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3777: if (keys(%{$domconfig{'login'}})) {
3778: foreach my $key (keys(%{$domconfig{'login'}})) {
3779: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3780: }
3781: } else {
3782: $legacy{'login'} = 1;
1.518 albertel 3783: }
1.632 raeburn 3784: } else {
3785: $legacy{'login'} = 1;
1.518 albertel 3786: }
3787: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3788: if (keys(%{$domconfig{'rolecolors'}})) {
3789: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3790: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3791: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3792: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3793: }
1.518 albertel 3794: }
3795: }
1.632 raeburn 3796: } else {
3797: $legacy{'rolecolors'} = 1;
1.518 albertel 3798: }
1.632 raeburn 3799: } else {
3800: $legacy{'rolecolors'} = 1;
1.518 albertel 3801: }
1.632 raeburn 3802: if (keys(%legacy) > 0) {
3803: my %legacyhash = &get_legacy_domconf($udom);
3804: foreach my $item (keys(%legacyhash)) {
3805: if ($item =~ /^\Q$udom\E\.login/) {
3806: if ($legacy{'login'}) {
3807: $designhash{$item} = $legacyhash{$item};
3808: }
3809: } else {
3810: if ($legacy{'rolecolors'}) {
3811: $designhash{$item} = $legacyhash{$item};
3812: }
1.518 albertel 3813: }
3814: }
3815: }
1.632 raeburn 3816: } else {
3817: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3818: }
3819: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3820: $cachetime);
3821: return %designhash;
3822: }
3823:
1.632 raeburn 3824: sub get_legacy_domconf {
3825: my ($udom) = @_;
3826: my %legacyhash;
3827: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
3828: my $designfile = $designdir.'/'.$udom.'.tab';
3829: if (-e $designfile) {
3830: if ( open (my $fh,"<$designfile") ) {
3831: while (my $line = <$fh>) {
3832: next if ($line =~ /^\#/);
3833: chomp($line);
3834: my ($key,$val)=(split(/\=/,$line));
3835: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
3836: }
3837: close($fh);
3838: }
3839: }
3840: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
3841: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
3842: }
3843: return %legacyhash;
3844: }
3845:
1.63 www 3846: =pod
3847:
1.112 bowersj2 3848: =item * &domainlogo()
1.63 www 3849:
3850: Inputs: $domain (usually will be undef)
3851:
3852: Returns: A link to a domain logo, if the domain logo exists.
3853: If the domain logo does not exist, a description of the domain.
3854:
3855: =cut
1.112 bowersj2 3856:
1.63 www 3857: ###############################################
3858: sub domainlogo {
1.517 raeburn 3859: my $domain = &determinedomain(shift);
1.518 albertel 3860: my %designhash = &get_domainconf($domain);
1.517 raeburn 3861: # See if there is a logo
3862: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 3863: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 3864: if ($imgsrc =~ m{^/(adm|res)/}) {
3865: if ($imgsrc =~ m{^/res/}) {
3866: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
3867: &Apache::lonnet::repcopy($local_name);
3868: }
3869: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 3870: }
3871: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 3872: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
3873: return &Apache::lonnet::domain($domain,'description');
1.59 www 3874: } else {
1.60 matthew 3875: return '';
1.59 www 3876: }
3877: }
1.63 www 3878: ##############################################
3879:
3880: =pod
3881:
1.112 bowersj2 3882: =item * &designparm()
1.63 www 3883:
3884: Inputs: $which parameter; $domain (usually will be undef)
3885:
3886: Returns: value of designparamter $which
3887:
3888: =cut
1.112 bowersj2 3889:
1.397 albertel 3890:
1.400 albertel 3891: ##############################################
1.397 albertel 3892: sub designparm {
3893: my ($which,$domain)=@_;
1.258 albertel 3894: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 3895: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 3896: return '#000000';
3897: }
1.635 raeburn 3898: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 3899: return '#FFFFFF';
3900: }
3901: if ($which=~/\.tabbg$/) {
3902: return '#CCCCCC';
3903: }
3904: }
1.397 albertel 3905: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 3906: return $env{'environment.color.'.$which};
1.96 www 3907: }
1.63 www 3908: $domain=&determinedomain($domain);
1.518 albertel 3909: my %domdesign = &get_domainconf($domain);
1.520 raeburn 3910: my $output;
1.517 raeburn 3911: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 3912: $output = $domdesign{$domain.'.'.$which};
1.63 www 3913: } else {
1.520 raeburn 3914: $output = $defaultdesign{$which};
3915: }
3916: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 3917: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 3918: if ($output =~ m{^/(adm|res)/}) {
3919: if ($output =~ m{^/res/}) {
3920: my $local_name = &Apache::lonnet::filelocation('',$output);
3921: &Apache::lonnet::repcopy($local_name);
3922: }
1.520 raeburn 3923: $output = &lonhttpdurl($output);
3924: }
1.63 www 3925: }
1.520 raeburn 3926: return $output;
1.63 www 3927: }
1.59 www 3928:
1.60 matthew 3929: ###############################################
3930: ###############################################
3931:
3932: =pod
3933:
1.112 bowersj2 3934: =back
3935:
1.549 albertel 3936: =head1 HTML Helpers
1.112 bowersj2 3937:
3938: =over 4
3939:
3940: =item * &bodytag()
1.60 matthew 3941:
3942: Returns a uniform header for LON-CAPA web pages.
3943:
3944: Inputs:
3945:
1.112 bowersj2 3946: =over 4
3947:
3948: =item * $title, A title to be displayed on the page.
3949:
3950: =item * $function, the current role (can be undef).
3951:
3952: =item * $addentries, extra parameters for the <body> tag.
3953:
3954: =item * $bodyonly, if defined, only return the <body> tag.
3955:
3956: =item * $domain, if defined, force a given domain.
3957:
3958: =item * $forcereg, if page should register as content page (relevant for
1.86 www 3959: text interface only)
1.60 matthew 3960:
1.326 albertel 3961: =item * $customtitle, alternate text to use instead of $title
3962: in the title box that appears, this text
3963: is not auto translated like the $title is
1.309 albertel 3964:
3965: =item * $notopbar, if true, keep the 'what is this' info but remove the
3966: navigational links
1.317 albertel 3967:
1.338 albertel 3968: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
3969:
3970: =item * $notitle, if true keep the nav controls, but remove the title bar
3971:
1.361 albertel 3972: =item * $no_inline_link, if true and in remote mode, don't show the
3973: 'Switch To Inline Menu' link
3974:
1.460 albertel 3975: =item * $args, optional argument valid values are
3976: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 3977: inherit_jsmath -> when creating popup window in a page,
3978: should it have jsmath forced on by the
3979: current page
1.460 albertel 3980:
1.112 bowersj2 3981: =back
3982:
1.60 matthew 3983: Returns: A uniform header for LON-CAPA web pages.
3984: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
3985: If $bodyonly is undef or zero, an html string containing a <body> tag and
3986: other decorations will be returned.
3987:
3988: =cut
3989:
1.54 www 3990: sub bodytag {
1.309 albertel 3991: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 3992: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 3993:
1.460 albertel 3994: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 3995:
1.183 matthew 3996: $function = &get_users_function() if (!$function);
1.339 albertel 3997: my $img = &designparm($function.'.img',$domain);
3998: my $font = &designparm($function.'.font',$domain);
3999: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4000:
4001: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4002: 'bgcolor' => $pgbg,
1.339 albertel 4003: 'text' => $font,
4004: 'alink' => &designparm($function.'.alink',$domain),
4005: 'vlink' => &designparm($function.'.vlink',$domain),
4006: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4007: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4008:
1.63 www 4009: # role and realm
1.378 raeburn 4010: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4011: if ($role eq 'ca') {
1.479 albertel 4012: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4013: $realm = &plainname($rname,$rdom);
1.378 raeburn 4014: }
1.55 www 4015: # realm
1.258 albertel 4016: if ($env{'request.course.id'}) {
1.378 raeburn 4017: if ($env{'request.role'} !~ /^cr/) {
4018: $role = &Apache::lonnet::plaintext($role,&course_type());
4019: }
1.359 albertel 4020: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4021: } else {
4022: $role = &Apache::lonnet::plaintext($role);
1.54 www 4023: }
1.433 albertel 4024:
1.359 albertel 4025: if (!$realm) { $realm=' '; }
1.55 www 4026: # Set messages
1.60 matthew 4027: my $messages=&domainlogo($domain);
1.330 albertel 4028:
1.438 albertel 4029: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4030:
1.101 www 4031: # construct main body tag
1.359 albertel 4032: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4033: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4034:
1.530 albertel 4035: if ($bodyonly) {
1.60 matthew 4036: return $bodytag;
1.258 albertel 4037: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4038: # Accessibility
1.224 raeburn 4039:
1.337 albertel 4040: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4041: if (!$notitle) {
1.337 albertel 4042: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4043: }
4044: return $bodytag;
1.359 albertel 4045: }
4046:
1.410 albertel 4047: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4048: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4049: undef($role);
1.434 albertel 4050: } else {
4051: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4052: }
1.359 albertel 4053:
4054: my $roleinfo=(<<ENDROLE);
4055: <td class="LC_title_bar_who">
4056: <div class="LC_title_bar_name">
1.410 albertel 4057: $name
1.361 albertel 4058:
1.359 albertel 4059: </div>
4060: <div class="LC_title_bar_role">
1.361 albertel 4061: $role
1.359 albertel 4062: </div>
4063: <div class="LC_title_bar_realm">
1.361 albertel 4064: $realm
1.359 albertel 4065: </div>
1.206 albertel 4066: </td>
4067: ENDROLE
1.235 raeburn 4068:
1.359 albertel 4069: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4070: if ($customtitle) {
4071: $titleinfo = $customtitle;
4072: }
4073: #
4074: # Extra info if you are the DC
4075: my $dc_info = '';
4076: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4077: $env{'course.'.$env{'request.course.id'}.
4078: '.domain'}.'/'})) {
4079: my $cid = $env{'request.course.id'};
4080: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4081: $dc_info =~ s/\s+$//;
1.359 albertel 4082: $dc_info = '('.$dc_info.')';
4083: }
4084:
1.636.2.5 raeburn 4085: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4086: # No Remote
1.258 albertel 4087: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4088: $forcereg=1;
4089: }
4090:
4091: if (!$customtitle && $env{'request.state'} eq 'construct') {
4092: # this is for resources; directories have customtitle, and crumbs
4093: # and select recent are created in lonpubdir.pm
1.229 albertel 4094: my ($uname,$thisdisfn)=
1.258 albertel 4095: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4096: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4097: $formaction=~s/\/+/\//g;
4098:
1.359 albertel 4099: my $parentpath = '';
4100: my $lastitem = '';
4101: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4102: $parentpath = $1;
4103: $lastitem = $2;
4104: } else {
4105: $lastitem = $thisdisfn;
4106: }
4107: $titleinfo =
1.636.2.3 raeburn 4108: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4109: .'<b>'.&mt('Construction Space').'</b>: '
4110: .'<form name="dirs" method="post" action="'.$formaction.'"'
4111: .' target="_top"><tt><b>'
1.359 albertel 4112: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
4113: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4114: .'</form>'
4115: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4116: }
1.359 albertel 4117:
1.337 albertel 4118: my $titletable;
1.338 albertel 4119: if (!$notitle) {
1.337 albertel 4120: $titletable =
1.359 albertel 4121: '<table id="LC_title_bar">'.
4122: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4123: '</tr></table>';
1.337 albertel 4124: }
1.359 albertel 4125: if ($notopbar) {
4126: $bodytag .= $titletable;
4127: } else {
4128: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4129: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4130: $titletable);
1.272 raeburn 4131: } else {
1.336 albertel 4132: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4133: $titletable;
1.272 raeburn 4134: }
1.235 raeburn 4135: }
4136: return $bodytag;
1.94 www 4137: }
1.95 www 4138:
1.93 www 4139: #
1.95 www 4140: # Top frame rendering, Remote is up
1.93 www 4141: #
1.359 albertel 4142:
1.517 raeburn 4143: my $imgsrc = $img;
4144: if ($img =~ /^\/adm/) {
1.575 albertel 4145: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4146: }
4147: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4148:
1.305 www 4149: # Explicit link to get inline menu
1.361 albertel 4150: my $menu= ($no_inline_link?''
4151: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4152: #
1.338 albertel 4153: if ($notitle) {
1.337 albertel 4154: return $bodytag;
4155: }
1.94 www 4156: return(<<ENDBODY);
1.60 matthew 4157: $bodytag
1.359 albertel 4158: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4159: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4160: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4161: </tr>
1.359 albertel 4162: <tr><td>$titleinfo $dc_info $menu</td>
4163: $roleinfo
1.368 albertel 4164: </tr>
1.356 albertel 4165: </table>
1.54 www 4166: ENDBODY
1.182 matthew 4167: }
4168:
1.330 albertel 4169: sub make_attr_string {
4170: my ($register,$attr_ref) = @_;
4171:
4172: if ($attr_ref && !ref($attr_ref)) {
4173: die("addentries Must be a hash ref ".
4174: join(':',caller(1))." ".
4175: join(':',caller(0))." ");
4176: }
4177:
4178: if ($register) {
1.339 albertel 4179: my ($on_load,$on_unload);
4180: foreach my $key (keys(%{$attr_ref})) {
4181: if (lc($key) eq 'onload') {
4182: $on_load.=$attr_ref->{$key}.';';
4183: delete($attr_ref->{$key});
4184:
4185: } elsif (lc($key) eq 'onunload') {
4186: $on_unload.=$attr_ref->{$key}.';';
4187: delete($attr_ref->{$key});
4188: }
4189: }
4190: $attr_ref->{'onload'} =
4191: &Apache::lonmenu::loadevents(). $on_load;
4192: $attr_ref->{'onunload'}=
4193: &Apache::lonmenu::unloadevents().$on_unload;
4194: }
4195:
4196: # Accessibility font enhance
4197: if ($env{'browser.fontenhance'} eq 'on') {
4198: my $style;
4199: foreach my $key (keys(%{$attr_ref})) {
4200: if (lc($key) eq 'style') {
4201: $style.=$attr_ref->{$key}.';';
4202: delete($attr_ref->{$key});
4203: }
4204: }
4205: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4206: }
1.339 albertel 4207:
4208: if ($env{'browser.blackwhite'} eq 'on') {
4209: delete($attr_ref->{'font'});
4210: delete($attr_ref->{'link'});
4211: delete($attr_ref->{'alink'});
4212: delete($attr_ref->{'vlink'});
4213: delete($attr_ref->{'bgcolor'});
4214: delete($attr_ref->{'background'});
4215: }
4216:
1.330 albertel 4217: my $attr_string;
4218: foreach my $attr (keys(%$attr_ref)) {
4219: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4220: }
4221: return $attr_string;
4222: }
4223:
4224:
1.182 matthew 4225: ###############################################
1.251 albertel 4226: ###############################################
4227:
4228: =pod
4229:
4230: =item * &endbodytag()
4231:
4232: Returns a uniform footer for LON-CAPA web pages.
4233:
1.635 raeburn 4234: Inputs: 1 - optional reference to an args hash
4235: If in the hash, key for noredirectlink has a value which evaluates to true,
4236: a 'Continue' link is not displayed if the page contains an
4237: internal redirect in the <head></head> section,
4238: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4239:
4240: =cut
4241:
4242: sub endbodytag {
1.635 raeburn 4243: my ($args) = @_;
1.251 albertel 4244: my $endbodytag='</body>';
1.269 albertel 4245: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4246: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4247: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4248: $endbodytag=
4249: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4250: &mt('Continue').'</a>'.
4251: $endbodytag;
4252: }
1.315 albertel 4253: }
1.251 albertel 4254: return $endbodytag;
4255: }
4256:
1.352 albertel 4257: =pod
4258:
4259: =item * &standard_css()
4260:
4261: Returns a style sheet
4262:
4263: Inputs: (all optional)
4264: domain -> force to color decorate a page for a specific
4265: domain
4266: function -> force usage of a specific rolish color scheme
4267: bgcolor -> override the default page bgcolor
4268:
4269: =cut
4270:
1.343 albertel 4271: sub standard_css {
1.345 albertel 4272: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4273: $function = &get_users_function() if (!$function);
4274: my $img = &designparm($function.'.img', $domain);
4275: my $tabbg = &designparm($function.'.tabbg', $domain);
4276: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4277: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4278: my $pgbg_or_bgcolor =
4279: $bgcolor ||
1.352 albertel 4280: &designparm($function.'.pgbg', $domain);
1.382 albertel 4281: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4282: my $alink = &designparm($function.'.alink', $domain);
4283: my $vlink = &designparm($function.'.vlink', $domain);
4284: my $link = &designparm($function.'.link', $domain);
4285:
1.602 albertel 4286: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4287: my $mono = 'monospace';
1.352 albertel 4288: my $data_table_head = $tabbg;
4289: my $data_table_light = '#EEEEEE';
1.470 banghart 4290: my $data_table_dark = '#DDDDDD';
4291: my $data_table_darker = '#CCCCCC';
1.349 albertel 4292: my $data_table_highlight = '#FFFF00';
1.352 albertel 4293: my $mail_new = '#FFBB77';
4294: my $mail_new_hover = '#DD9955';
4295: my $mail_read = '#BBBB77';
4296: my $mail_read_hover = '#999944';
4297: my $mail_replied = '#AAAA88';
4298: my $mail_replied_hover = '#888855';
4299: my $mail_other = '#99BBBB';
4300: my $mail_other_hover = '#669999';
1.391 albertel 4301: my $table_header = '#DDDDDD';
1.489 raeburn 4302: my $feedback_link_bg = '#BBBBBB';
1.392 albertel 4303:
1.608 albertel 4304: my $border = ($env{'browser.type'} eq 'explorer' ||
4305: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4306: : '0px 3px 0px 4px';
1.448 albertel 4307:
1.523 albertel 4308:
1.343 albertel 4309: return <<END;
1.345 albertel 4310: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4311: a:focus { color: red; background: yellow }
1.510 albertel 4312: table.thinborder,
1.523 albertel 4313:
1.510 albertel 4314: table.thinborder tr th {
4315: border-style: solid;
4316: border-width: 1px;
4317: background: $tabbg;
4318: }
1.523 albertel 4319: table.thinborder tr td {
1.510 albertel 4320: border-style: solid;
4321: border-width: 1px
4322: }
1.426 albertel 4323:
1.343 albertel 4324: form, .inline { display: inline; }
4325: .center { text-align: center; }
1.593 albertel 4326: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4327: .LC_error {
4328: color: red;
4329: font-size: larger;
4330: }
1.457 albertel 4331: .LC_warning,
4332: .LC_diff_removed {
1.394 albertel 4333: color: red;
4334: }
1.532 albertel 4335:
4336: .LC_info,
1.457 albertel 4337: .LC_success,
4338: .LC_diff_added {
1.350 albertel 4339: color: green;
4340: }
1.543 albertel 4341: .LC_unknown {
4342: color: yellow;
4343: }
4344:
1.440 albertel 4345: .LC_icon {
4346: border: 0px;
4347: }
1.539 albertel 4348: .LC_indexer_icon {
4349: border: 0px;
4350: height: 22px;
4351: }
1.543 albertel 4352: .LC_docs_spacer {
4353: width: 25px;
4354: height: 1px;
4355: border: 0px;
4356: }
1.346 albertel 4357:
1.532 albertel 4358: .LC_internal_info {
4359: color: #999;
4360: }
4361:
1.458 albertel 4362: table.LC_pastsubmission {
4363: border: 1px solid black;
4364: margin: 2px;
4365: }
4366:
1.606 albertel 4367: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4368: width: 100%;
4369: background: $pgbg;
1.392 albertel 4370: border: 2px;
1.402 albertel 4371: border-collapse: separate;
1.403 albertel 4372: padding: 0px;
1.345 albertel 4373: }
1.392 albertel 4374:
1.606 albertel 4375: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4376: table#LC_title_bar.LC_with_remote {
1.359 albertel 4377: width: 100%;
1.392 albertel 4378: border-color: $pgbg;
4379: border-style: solid;
4380: border-width: $border;
4381:
1.379 albertel 4382: background: $pgbg;
4383: font-family: $sans;
1.392 albertel 4384: border-collapse: collapse;
1.403 albertel 4385: padding: 0px;
1.359 albertel 4386: }
1.392 albertel 4387:
1.409 albertel 4388: table.LC_docs_path {
4389: width: 100%;
4390: border: 0;
4391: background: $pgbg;
4392: font-family: $sans;
4393: border-collapse: collapse;
4394: padding: 0px;
4395: }
4396:
1.359 albertel 4397: table#LC_title_bar td {
4398: background: $tabbg;
4399: }
4400: table#LC_title_bar td.LC_title_bar_who {
4401: background: $tabbg;
4402: color: $font;
1.427 albertel 4403: font: small $sans;
1.359 albertel 4404: text-align: right;
4405: }
1.469 banghart 4406: span.LC_metadata {
4407: font-family: $sans;
4408: }
1.359 albertel 4409: span.LC_title_bar_title {
1.416 albertel 4410: font: bold x-large $sans;
1.359 albertel 4411: }
4412: table#LC_title_bar td.LC_title_bar_domain_logo {
4413: background: $sidebg;
4414: text-align: right;
1.368 albertel 4415: padding: 0px;
4416: }
4417: table#LC_title_bar td.LC_title_bar_role_logo {
4418: background: $sidebg;
4419: padding: 0px;
1.359 albertel 4420: }
4421:
1.346 albertel 4422: table#LC_menubuttons_mainmenu {
1.526 www 4423: width: 100%;
1.346 albertel 4424: border: 0px;
4425: border-spacing: 1px;
1.372 albertel 4426: padding: 0px 1px;
1.346 albertel 4427: margin: 0px;
4428: border-collapse: separate;
4429: }
4430: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
4431: border: 0px;
4432: }
1.345 albertel 4433: table#LC_top_nav td {
4434: background: $tabbg;
1.392 albertel 4435: border: 0px;
1.407 albertel 4436: font-size: small;
1.345 albertel 4437: }
4438: table#LC_top_nav td a, div#LC_top_nav a {
4439: color: $font;
4440: font-family: $sans;
4441: }
1.364 albertel 4442: table#LC_top_nav td.LC_top_nav_logo {
4443: background: $tabbg;
1.432 albertel 4444: text-align: left;
1.408 albertel 4445: white-space: nowrap;
1.432 albertel 4446: width: 31px;
1.408 albertel 4447: }
4448: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4449: border: 0px;
1.408 albertel 4450: vertical-align: bottom;
1.364 albertel 4451: }
1.432 albertel 4452: table#LC_top_nav td.LC_top_nav_exit,
4453: table#LC_top_nav td.LC_top_nav_help {
4454: width: 2.0em;
4455: }
1.442 albertel 4456: table#LC_top_nav td.LC_top_nav_login {
4457: width: 4.0em;
4458: text-align: center;
4459: }
1.409 albertel 4460: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4461: background: $tabbg;
4462: color: $font;
4463: font-family: $sans;
1.358 albertel 4464: font-size: smaller;
1.357 albertel 4465: }
1.411 albertel 4466: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4467: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4468: background: $tabbg;
4469: color: $font;
4470: font-family: $sans;
4471: font-size: larger;
4472: text-align: right;
4473: }
1.383 albertel 4474: td.LC_table_cell_checkbox {
4475: text-align: center;
4476: }
4477:
1.522 albertel 4478: table#LC_mainmenu td.LC_mainmenu_column {
4479: vertical-align: top;
4480: }
4481:
1.346 albertel 4482: .LC_menubuttons_inline_text {
4483: color: $font;
4484: font-family: $sans;
4485: font-size: smaller;
4486: }
4487:
1.526 www 4488: .LC_menubuttons_link {
4489: text-decoration: none;
4490: }
4491:
1.522 albertel 4492: .LC_menubuttons_category {
1.521 www 4493: color: $font;
1.526 www 4494: background: $pgbg;
1.521 www 4495: font-family: $sans;
4496: font-size: larger;
4497: font-weight: bold;
4498: }
4499:
1.346 albertel 4500: td.LC_menubuttons_text {
1.526 www 4501: width: 90%;
1.346 albertel 4502: color: $font;
4503: font-family: $sans;
4504: }
1.526 www 4505:
1.346 albertel 4506: td.LC_menubuttons_img {
4507: }
1.526 www 4508:
1.346 albertel 4509: .LC_current_location {
4510: font-family: $sans;
4511: background: $tabbg;
4512: }
4513: .LC_new_mail {
4514: font-family: $sans;
1.634 www 4515: background: $tabbg;
1.346 albertel 4516: font-weight: bold;
4517: }
1.347 albertel 4518:
1.526 www 4519: .LC_rolesmenu_is {
4520: font-family: $sans;
4521: }
4522:
4523: .LC_rolesmenu_selected {
4524: font-family: $sans;
4525: }
4526:
4527: .LC_rolesmenu_future {
4528: font-family: $sans;
4529: }
4530:
4531:
4532: .LC_rolesmenu_will {
4533: font-family: $sans;
4534: }
4535:
4536: .LC_rolesmenu_will_not {
4537: font-family: $sans;
4538: }
4539:
4540: .LC_rolesmenu_expired {
4541: font-family: $sans;
4542: }
4543:
4544: .LC_rolesinfo {
4545: font-family: $sans;
4546: }
4547:
1.527 www 4548: .LC_dropadd_labeltext {
4549: font-family: $sans;
4550: text-align: right;
4551: }
4552:
4553: .LC_preferences_labeltext {
4554: font-family: $sans;
4555: text-align: right;
4556: }
4557:
1.440 albertel 4558: table.LC_aboutme_port {
4559: border: 0px;
4560: border-collapse: collapse;
4561: border-spacing: 0px;
4562: }
1.349 albertel 4563: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4564: border: 1px solid #000000;
1.402 albertel 4565: border-collapse: separate;
1.426 albertel 4566: border-spacing: 1px;
1.610 albertel 4567: background: $pgbg;
1.347 albertel 4568: }
1.422 albertel 4569: .LC_data_table_dense {
4570: font-size: small;
4571: }
1.507 raeburn 4572: table.LC_nested_outer {
4573: border: 1px solid #000000;
1.589 raeburn 4574: border-collapse: collapse;
1.507 raeburn 4575: border-spacing: 0px;
4576: width: 100%;
4577: }
4578: table.LC_nested {
4579: border: 0px;
1.589 raeburn 4580: border-collapse: collapse;
1.507 raeburn 4581: border-spacing: 0px;
4582: width: 100%;
4583: }
1.523 albertel 4584: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4585: table.LC_prior_tries tr th {
1.349 albertel 4586: font-weight: bold;
4587: background-color: $data_table_head;
1.421 albertel 4588: font-size: smaller;
1.347 albertel 4589: }
1.610 albertel 4590: table.LC_data_table tr.LC_odd_row > td,
1.440 albertel 4591: table.LC_aboutme_port tr td {
1.349 albertel 4592: background-color: $data_table_light;
1.425 albertel 4593: padding: 2px;
1.347 albertel 4594: }
1.610 albertel 4595: table.LC_data_table tr.LC_even_row > td,
1.440 albertel 4596: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4597: background-color: $data_table_dark;
1.347 albertel 4598: }
1.425 albertel 4599: table.LC_data_table tr.LC_data_table_highlight td {
4600: background-color: $data_table_darker;
4601: }
1.636.2.2 raeburn 4602: table.LC_data_table tr td.LC_leftcol_header {
4603: background-color: $data_table_head;
4604: font-weight: bold;
4605: }
1.451 albertel 4606: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4607: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4608: background-color: #FFFFFF;
1.421 albertel 4609: font-weight: bold;
4610: font-style: italic;
4611: text-align: center;
4612: padding: 8px;
1.347 albertel 4613: }
1.507 raeburn 4614: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4615: padding: 4ex
4616: }
1.507 raeburn 4617: table.LC_nested_outer tr th {
4618: font-weight: bold;
4619: background-color: $data_table_head;
4620: font-size: smaller;
4621: border-bottom: 1px solid #000000;
4622: }
4623: table.LC_nested_outer tr td.LC_subheader {
4624: background-color: $data_table_head;
4625: font-weight: bold;
4626: font-size: small;
4627: border-bottom: 1px solid #000000;
4628: text-align: right;
1.451 albertel 4629: }
1.507 raeburn 4630: table.LC_nested tr.LC_info_row td {
1.451 albertel 4631: background-color: #CCC;
4632: font-weight: bold;
4633: font-size: small;
1.507 raeburn 4634: text-align: center;
4635: }
1.589 raeburn 4636: table.LC_nested tr.LC_info_row td.LC_left_item,
4637: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4638: text-align: left;
1.451 albertel 4639: }
1.507 raeburn 4640: table.LC_nested td {
1.451 albertel 4641: background-color: #FFF;
4642: font-size: small;
1.507 raeburn 4643: }
4644: table.LC_nested_outer tr th.LC_right_item,
4645: table.LC_nested tr.LC_info_row td.LC_right_item,
4646: table.LC_nested tr.LC_odd_row td.LC_right_item,
4647: table.LC_nested tr td.LC_right_item {
1.451 albertel 4648: text-align: right;
4649: }
4650:
1.507 raeburn 4651: table.LC_nested tr.LC_odd_row td {
1.451 albertel 4652: background-color: #EEE;
4653: }
4654:
1.473 raeburn 4655: table.LC_createuser {
4656: }
4657:
4658: table.LC_createuser tr.LC_section_row td {
4659: font-size: smaller;
4660: }
4661:
4662: table.LC_createuser tr.LC_info_row td {
4663: background-color: #CCC;
4664: font-weight: bold;
4665: text-align: center;
4666: }
4667:
1.349 albertel 4668: table.LC_calendar {
4669: border: 1px solid #000000;
4670: border-collapse: collapse;
4671: }
4672: table.LC_calendar_pickdate {
4673: font-size: xx-small;
4674: }
4675: table.LC_calendar tr td {
4676: border: 1px solid #000000;
4677: vertical-align: top;
4678: }
4679: table.LC_calendar tr td.LC_calendar_day_empty {
4680: background-color: $data_table_dark;
4681: }
4682: table.LC_calendar tr td.LC_calendar_day_current {
4683: background-color: $data_table_highlight;
4684: }
4685:
4686: table.LC_mail_list tr.LC_mail_new {
4687: background-color: $mail_new;
4688: }
4689: table.LC_mail_list tr.LC_mail_new:hover {
4690: background-color: $mail_new_hover;
4691: }
4692: table.LC_mail_list tr.LC_mail_read {
4693: background-color: $mail_read;
4694: }
4695: table.LC_mail_list tr.LC_mail_read:hover {
4696: background-color: $mail_read_hover;
4697: }
4698: table.LC_mail_list tr.LC_mail_replied {
4699: background-color: $mail_replied;
4700: }
4701: table.LC_mail_list tr.LC_mail_replied:hover {
4702: background-color: $mail_replied_hover;
4703: }
4704: table.LC_mail_list tr.LC_mail_other {
4705: background-color: $mail_other;
4706: }
4707: table.LC_mail_list tr.LC_mail_other:hover {
4708: background-color: $mail_other_hover;
4709: }
1.494 raeburn 4710: table.LC_mail_list tr.LC_mail_even {
4711: }
4712: table.LC_mail_list tr.LC_mail_odd {
4713: }
4714:
1.385 albertel 4715:
1.386 albertel 4716: table#LC_portfolio_actions {
4717: width: auto;
4718: background: $pgbg;
4719: border: 0px;
4720: border-spacing: 2px 2px;
4721: padding: 0px;
4722: margin: 0px;
4723: border-collapse: separate;
4724: }
4725: table#LC_portfolio_actions td.LC_label {
4726: background: $tabbg;
4727: text-align: right;
4728: }
4729: table#LC_portfolio_actions td.LC_value {
4730: background: $tabbg;
4731: }
1.385 albertel 4732:
1.391 albertel 4733: table#LC_cstr_controls {
4734: width: 100%;
4735: border-collapse: collapse;
4736: }
4737: table#LC_cstr_controls tr td {
4738: border: 4px solid $pgbg;
4739: padding: 4px;
4740: text-align: center;
4741: background: $tabbg;
4742: }
4743: table#LC_cstr_controls tr th {
4744: border: 4px solid $pgbg;
4745: background: $table_header;
4746: text-align: center;
4747: font-family: $sans;
4748: font-size: smaller;
4749: }
4750:
1.389 albertel 4751: table#LC_browser {
4752:
4753: }
4754: table#LC_browser tr th {
1.391 albertel 4755: background: $table_header;
1.389 albertel 4756: }
1.390 albertel 4757: table#LC_browser tr td {
4758: padding: 2px;
4759: }
1.389 albertel 4760: table#LC_browser tr.LC_browser_file,
4761: table#LC_browser tr.LC_browser_file_published {
4762: background: #CCFF88;
4763: }
4764: table#LC_browser tr.LC_browser_file_locked,
4765: table#LC_browser tr.LC_browser_file_unpublished {
4766: background: #FFAA99;
1.387 albertel 4767: }
1.389 albertel 4768: table#LC_browser tr.LC_browser_file_obsolete {
4769: background: #AAAAAA;
1.387 albertel 4770: }
1.455 albertel 4771: table#LC_browser tr.LC_browser_file_modified,
4772: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 4773: background: #FFFF77;
1.387 albertel 4774: }
1.389 albertel 4775: table#LC_browser tr.LC_browser_folder {
4776: background: #CCCCFF;
1.387 albertel 4777: }
1.388 albertel 4778: span.LC_current_location {
4779: font-size: x-large;
4780: background: $pgbg;
4781: }
1.387 albertel 4782:
1.395 albertel 4783: span.LC_parm_menu_item {
4784: font-size: larger;
4785: font-family: $sans;
4786: }
4787: span.LC_parm_scope_all {
4788: color: red;
4789: }
4790: span.LC_parm_scope_folder {
4791: color: green;
4792: }
4793: span.LC_parm_scope_resource {
4794: color: orange;
4795: }
4796: span.LC_parm_part {
4797: color: blue;
4798: }
4799: span.LC_parm_folder, span.LC_parm_symb {
4800: font-size: x-small;
4801: font-family: $mono;
4802: color: #AAAAAA;
4803: }
4804:
1.396 albertel 4805: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4806: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4807: border: 1px solid black;
4808: border-collapse: collapse;
4809: }
4810: table.LC_parm_overview_restrictions td {
4811: border-width: 1px 4px 1px 4px;
4812: border-style: solid;
4813: border-color: $pgbg;
4814: text-align: center;
4815: }
4816: table.LC_parm_overview_restrictions th {
4817: background: $tabbg;
4818: border-width: 1px 4px 1px 4px;
4819: border-style: solid;
4820: border-color: $pgbg;
4821: }
1.398 albertel 4822: table#LC_helpmenu {
4823: border: 0px;
4824: height: 55px;
4825: border-spacing: 0px;
4826: }
4827:
4828: table#LC_helpmenu fieldset legend {
4829: font-size: larger;
4830: font-weight: bold;
4831: }
1.397 albertel 4832: table#LC_helpmenu_links {
4833: width: 100%;
4834: border: 1px solid black;
4835: background: $pgbg;
4836: padding: 0px;
4837: border-spacing: 1px;
4838: }
4839: table#LC_helpmenu_links tr td {
4840: padding: 1px;
4841: background: $tabbg;
1.399 albertel 4842: text-align: center;
4843: font-weight: bold;
1.397 albertel 4844: }
1.396 albertel 4845:
1.397 albertel 4846: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
4847: table#LC_helpmenu_links a:active {
4848: text-decoration: none;
4849: color: $font;
4850: }
4851: table#LC_helpmenu_links a:hover {
4852: text-decoration: underline;
4853: color: $vlink;
4854: }
1.396 albertel 4855:
1.417 albertel 4856: .LC_chrt_popup_exists {
4857: border: 1px solid #339933;
4858: margin: -1px;
4859: }
4860: .LC_chrt_popup_up {
4861: border: 1px solid yellow;
4862: margin: -1px;
4863: }
4864: .LC_chrt_popup {
4865: border: 1px solid #8888FF;
4866: background: #CCCCFF;
4867: }
1.421 albertel 4868: table.LC_pick_box {
4869: border-collapse: separate;
4870: background: white;
4871: border: 1px solid black;
4872: border-spacing: 1px;
4873: }
4874: table.LC_pick_box td.LC_pick_box_title {
4875: background: $tabbg;
4876: font-weight: bold;
4877: text-align: right;
4878: width: 184px;
4879: padding: 8px;
4880: }
1.579 raeburn 4881: table.LC_pick_box td.LC_pick_box_value {
4882: text-align: left;
4883: padding: 8px;
4884: }
4885: table.LC_pick_box td.LC_pick_box_select {
4886: text-align: left;
4887: padding: 8px;
4888: }
1.424 albertel 4889: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 4890: padding: 0px;
4891: height: 1px;
4892: background: black;
4893: }
4894: table.LC_pick_box td.LC_pick_box_submit {
4895: text-align: right;
4896: }
1.579 raeburn 4897: table.LC_pick_box td.LC_evenrow_value {
4898: text-align: left;
4899: padding: 8px;
4900: background-color: $data_table_light;
4901: }
4902: table.LC_pick_box td.LC_oddrow_value {
4903: text-align: left;
4904: padding: 8px;
4905: background-color: $data_table_light;
4906: }
4907: table.LC_helpform_receipt {
4908: width: 620px;
4909: border-collapse: separate;
4910: background: white;
4911: border: 1px solid black;
4912: border-spacing: 1px;
4913: }
4914: table.LC_helpform_receipt td.LC_pick_box_title {
4915: background: $tabbg;
4916: font-weight: bold;
4917: text-align: right;
4918: width: 184px;
4919: padding: 8px;
4920: }
4921: table.LC_helpform_receipt td.LC_evenrow_value {
4922: text-align: left;
4923: padding: 8px;
4924: background-color: $data_table_light;
4925: }
4926: table.LC_helpform_receipt td.LC_oddrow_value {
4927: text-align: left;
4928: padding: 8px;
4929: background-color: $data_table_light;
4930: }
4931: table.LC_helpform_receipt td.LC_pick_box_separator {
4932: padding: 0px;
4933: height: 1px;
4934: background: black;
4935: }
4936: span.LC_helpform_receipt_cat {
4937: font-weight: bold;
4938: }
1.424 albertel 4939: table.LC_group_priv_box {
4940: background: white;
4941: border: 1px solid black;
4942: border-spacing: 1px;
4943: }
4944: table.LC_group_priv_box td.LC_pick_box_title {
4945: background: $tabbg;
4946: font-weight: bold;
4947: text-align: right;
4948: width: 184px;
4949: }
4950: table.LC_group_priv_box td.LC_groups_fixed {
4951: background: $data_table_light;
4952: text-align: center;
4953: }
4954: table.LC_group_priv_box td.LC_groups_optional {
4955: background: $data_table_dark;
4956: text-align: center;
4957: }
4958: table.LC_group_priv_box td.LC_groups_functionality {
4959: background: $data_table_darker;
4960: text-align: center;
4961: font-weight: bold;
4962: }
4963: table.LC_group_priv td {
4964: text-align: left;
4965: padding: 0px;
4966: }
4967:
1.421 albertel 4968: table.LC_notify_front_page {
4969: background: white;
4970: border: 1px solid black;
4971: padding: 8px;
4972: }
4973: table.LC_notify_front_page td {
4974: padding: 8px;
4975: }
1.424 albertel 4976: .LC_navbuttons {
4977: margin: 2ex 0ex 2ex 0ex;
4978: }
1.423 albertel 4979: .LC_topic_bar {
4980: font-family: $sans;
4981: font-weight: bold;
4982: width: 100%;
4983: background: $tabbg;
4984: vertical-align: middle;
4985: margin: 2ex 0ex 2ex 0ex;
4986: }
4987: .LC_topic_bar span {
4988: vertical-align: middle;
4989: }
4990: .LC_topic_bar img {
4991: vertical-align: bottom;
4992: }
4993: table.LC_course_group_status {
4994: margin: 20px;
4995: }
4996: table.LC_status_selector td {
4997: vertical-align: top;
4998: text-align: center;
1.424 albertel 4999: padding: 4px;
5000: }
5001: table.LC_descriptive_input td.LC_description {
5002: vertical-align: top;
5003: text-align: right;
5004: font-weight: bold;
1.423 albertel 5005: }
1.599 albertel 5006: div.LC_feedback_link {
1.616 albertel 5007: clear: both;
1.599 albertel 5008: background: white;
5009: width: 100%;
1.489 raeburn 5010: }
5011: span.LC_feedback_link {
1.599 albertel 5012: background: $feedback_link_bg;
5013: font-size: larger;
5014: }
5015: span.LC_message_link {
5016: background: $feedback_link_bg;
5017: font-size: larger;
5018: position: absolute;
5019: right: 1em;
1.489 raeburn 5020: }
1.421 albertel 5021:
1.515 albertel 5022: table.LC_prior_tries {
1.524 albertel 5023: border: 1px solid #000000;
5024: border-collapse: separate;
5025: border-spacing: 1px;
1.515 albertel 5026: }
1.523 albertel 5027:
1.515 albertel 5028: table.LC_prior_tries td {
1.524 albertel 5029: padding: 2px;
1.515 albertel 5030: }
1.523 albertel 5031:
5032: .LC_answer_correct {
5033: background: #AAFFAA;
5034: color: black;
5035: }
5036: .LC_answer_charged_try {
5037: background: #FFAAAA ! important;
5038: color: black;
5039: }
5040: .LC_answer_not_charged_try,
5041: .LC_answer_no_grade,
5042: .LC_answer_late {
5043: background: #FFFFAA;
5044: color: black;
5045: }
5046: .LC_answer_previous {
5047: background: #AAAAFF;
5048: color: black;
5049: }
5050: .LC_answer_no_message {
5051: background: #FFFFFF;
5052: color: black;
5053: }
5054: .LC_answer_unknown {
5055: background: orange;
5056: color: black;
5057: }
5058:
5059:
1.529 albertel 5060: span.LC_prior_numerical,
5061: span.LC_prior_string,
5062: span.LC_prior_custom,
5063: span.LC_prior_reaction,
5064: span.LC_prior_math {
1.523 albertel 5065: font-family: monospace;
5066: white-space: pre;
5067: }
5068:
1.525 albertel 5069: span.LC_prior_string {
5070: font-family: monospace;
5071: white-space: pre;
5072: }
5073:
1.523 albertel 5074: table.LC_prior_option {
5075: width: 100%;
5076: border-collapse: collapse;
5077: }
1.528 albertel 5078: table.LC_prior_rank, table.LC_prior_match {
5079: border-collapse: collapse;
5080: }
5081: table.LC_prior_option tr td,
5082: table.LC_prior_rank tr td,
5083: table.LC_prior_match tr td {
1.524 albertel 5084: border: 1px solid #000000;
1.515 albertel 5085: }
5086:
1.519 raeburn 5087: span.LC_nobreak {
1.544 albertel 5088: white-space: nowrap;
1.519 raeburn 5089: }
5090:
1.576 raeburn 5091: span.LC_cusr_emph {
5092: font-style: italic;
5093: }
5094:
1.633 raeburn 5095: span.LC_cusr_subheading {
5096: font-weight: normal;
5097: font-size: 85%;
5098: }
5099:
1.545 albertel 5100: table.LC_docs_documents {
5101: background: #BBBBBB;
1.547 albertel 5102: border-width: 0px;
1.545 albertel 5103: border-collapse: collapse;
5104: }
5105:
5106: table.LC_docs_documents td.LC_docs_document {
5107: border: 2px solid black;
5108: padding: 4px;
5109: }
5110:
5111: .LC_docs_course_commands div {
5112: float: left;
5113: border: 4px solid #AAAAAA;
5114: padding: 4px;
5115: background: #DDDDCC;
5116: }
5117:
5118: .LC_docs_entry_move {
5119: border: 0px;
5120: border-collapse: collapse;
1.544 albertel 5121: }
5122:
1.545 albertel 5123: .LC_docs_entry_move td {
5124: border: 2px solid #BBBBBB;
5125: background: #DDDDDD;
5126: }
5127:
5128: .LC_docs_editor td.LC_docs_entry_commands {
5129: background: #DDDDDD;
5130: font-size: x-small;
5131: }
1.544 albertel 5132: .LC_docs_copy {
1.545 albertel 5133: color: #000099;
1.544 albertel 5134: }
5135: .LC_docs_cut {
1.545 albertel 5136: color: #550044;
1.544 albertel 5137: }
5138: .LC_docs_rename {
1.545 albertel 5139: color: #009900;
1.544 albertel 5140: }
5141: .LC_docs_remove {
1.545 albertel 5142: color: #990000;
5143: }
5144:
1.547 albertel 5145: .LC_docs_reinit_warn,
5146: .LC_docs_ext_edit {
5147: font-size: x-small;
5148: }
5149:
1.545 albertel 5150: .LC_docs_editor td.LC_docs_entry_title,
5151: .LC_docs_editor td.LC_docs_entry_icon {
5152: background: #FFFFBB;
5153: }
5154: .LC_docs_editor td.LC_docs_entry_parameter {
5155: background: #BBBBFF;
5156: font-size: x-small;
5157: white-space: nowrap;
5158: }
5159:
5160: table.LC_docs_adddocs td,
5161: table.LC_docs_adddocs th {
5162: border: 1px solid #BBBBBB;
5163: padding: 4px;
5164: background: #DDDDDD;
1.543 albertel 5165: }
5166:
1.584 albertel 5167: table.LC_sty_begin {
5168: background: #BBFFBB;
5169: }
5170: table.LC_sty_end {
5171: background: #FFBBBB;
5172: }
5173:
1.589 raeburn 5174: table.LC_double_column {
5175: border-width: 0px;
5176: border-collapse: collapse;
5177: width: 100%;
5178: padding: 2px;
5179: }
5180:
5181: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5182: top: 2px;
1.589 raeburn 5183: left: 2px;
5184: width: 47%;
5185: vertical-align: top;
5186: }
5187:
5188: table.LC_double_column tr td.LC_right_col {
5189: top: 2px;
5190: right: 2px;
5191: width: 47%;
5192: vertical-align: top;
5193: }
5194:
1.594 raeburn 5195: span.LC_role_level {
5196: font-weight: bold;
5197: }
5198:
1.591 raeburn 5199: div.LC_left_float {
5200: float: left;
5201: padding-right: 5%;
1.597 albertel 5202: padding-bottom: 4px;
1.591 raeburn 5203: }
5204:
5205: div.LC_clear_float_header {
1.597 albertel 5206: padding-bottom: 2px;
1.591 raeburn 5207: }
5208:
5209: div.LC_clear_float_footer {
1.597 albertel 5210: padding-top: 10px;
1.591 raeburn 5211: clear: both;
5212: }
5213:
1.597 albertel 5214:
1.601 albertel 5215: div.LC_grade_select_mode {
1.604 albertel 5216: font-family: $sans;
1.601 albertel 5217: }
5218: div.LC_grade_select_mode div div {
5219: margin: 5px;
5220: }
5221: div.LC_grade_select_mode_selector {
5222: margin: 5px;
5223: float: left;
5224: }
5225: div.LC_grade_select_mode_selector_header {
5226: font: bold medium $sans;
5227: }
5228: div.LC_grade_select_mode_type {
5229: clear: left;
5230: }
5231:
1.597 albertel 5232: div.LC_grade_show_user {
5233: margin-top: 20px;
5234: border: 1px solid black;
5235: }
5236: div.LC_grade_user_name {
5237: background: #DDDDEE;
5238: border-bottom: 1px solid black;
5239: font: bold large $sans;
5240: }
5241: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5242: background: #DDEEDD;
5243: }
5244:
5245: div.LC_grade_show_problem,
5246: div.LC_grade_submissions,
5247: div.LC_grade_message_center,
5248: div.LC_grade_info_links,
5249: div.LC_grade_assign {
5250: margin: 5px;
5251: width: 99%;
5252: background: #FFFFFF;
5253: }
5254: div.LC_grade_show_problem_header,
5255: div.LC_grade_submissions_header,
5256: div.LC_grade_message_center_header,
5257: div.LC_grade_assign_header {
5258: font: bold large $sans;
5259: }
5260: div.LC_grade_show_problem_problem,
5261: div.LC_grade_submissions_body,
5262: div.LC_grade_message_center_body,
5263: div.LC_grade_assign_body {
5264: border: 1px solid black;
5265: width: 99%;
5266: background: #FFFFFF;
5267: }
1.598 albertel 5268: span.LC_grade_check_note {
5269: font: normal medium $sans;
5270: display: inline;
5271: position: absolute;
5272: right: 1em;
5273: }
1.597 albertel 5274:
1.613 albertel 5275: table.LC_scantron_action {
5276: width: 100%;
5277: }
5278: table.LC_scantron_action tr th {
5279: font: normal bold $sans;
5280: }
1.600 albertel 5281:
1.614 albertel 5282: div.LC_edit_problem_header,
5283: div.LC_edit_problem_footer {
1.600 albertel 5284: font: normal medium $sans;
1.602 albertel 5285: margin: 2px;
1.600 albertel 5286: }
5287: div.LC_edit_problem_header,
1.602 albertel 5288: div.LC_edit_problem_header div,
1.614 albertel 5289: div.LC_edit_problem_footer,
5290: div.LC_edit_problem_footer div,
1.602 albertel 5291: div.LC_edit_problem_editxml_header,
5292: div.LC_edit_problem_editxml_header div {
1.600 albertel 5293: margin-top: 5px;
5294: }
1.602 albertel 5295: div.LC_edit_problem_header_edit_row {
5296: background: $tabbg;
5297: padding: 3px;
5298: margin-bottom: 5px;
5299: }
1.600 albertel 5300: div.LC_edit_problem_header_title {
1.602 albertel 5301: font: larger bold $sans;
5302: background: $tabbg;
5303: padding: 3px;
5304: }
5305: table.LC_edit_problem_header_title {
5306: font: larger bold $sans;
5307: width: 100%;
5308: border-color: $pgbg;
5309: border-style: solid;
5310: border-width: $border;
5311:
1.600 albertel 5312: background: $tabbg;
1.602 albertel 5313: border-collapse: collapse;
5314: padding: 0px
5315: }
5316:
5317: div.LC_edit_problem_discards {
5318: float: left;
5319: padding-bottom: 5px;
5320: }
5321: div.LC_edit_problem_saves {
5322: float: right;
5323: padding-bottom: 5px;
1.600 albertel 5324: }
5325: hr.LC_edit_problem_divide {
1.602 albertel 5326: clear: both;
1.600 albertel 5327: color: $tabbg;
5328: background-color: $tabbg;
5329: height: 3px;
5330: border: 0px;
5331: }
1.343 albertel 5332: END
5333: }
5334:
1.306 albertel 5335: =pod
5336:
5337: =item * &headtag()
5338:
5339: Returns a uniform footer for LON-CAPA web pages.
5340:
1.307 albertel 5341: Inputs: $title - optional title for the head
5342: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5343: $args - optional arguments
1.319 albertel 5344: force_register - if is true call registerurl so the remote is
5345: informed
1.415 albertel 5346: redirect -> array ref of
5347: 1- seconds before redirect occurs
5348: 2- url to redirect to
5349: 3- whether the side effect should occur
1.315 albertel 5350: (side effect of setting
5351: $env{'internal.head.redirect'} to the url
5352: redirected too)
1.352 albertel 5353: domain -> force to color decorate a page for a specific
5354: domain
5355: function -> force usage of a specific rolish color scheme
5356: bgcolor -> override the default page bgcolor
1.460 albertel 5357: no_auto_mt_title
5358: -> prevent &mt()ing the title arg
1.464 albertel 5359:
1.306 albertel 5360: =cut
5361:
5362: sub headtag {
1.313 albertel 5363: my ($title,$head_extra,$args) = @_;
1.306 albertel 5364:
1.363 albertel 5365: my $function = $args->{'function'} || &get_users_function();
5366: my $domain = $args->{'domain'} || &determinedomain();
5367: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5368: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5369: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5370: #time(),
1.418 albertel 5371: $env{'environment.color.timestamp'},
1.363 albertel 5372: $function,$domain,$bgcolor);
5373:
1.369 www 5374: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5375:
1.308 albertel 5376: my $result =
5377: '<head>'.
1.461 albertel 5378: &font_settings();
1.319 albertel 5379:
1.461 albertel 5380: if (!$args->{'frameset'}) {
5381: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5382: }
1.319 albertel 5383: if ($args->{'force_register'}) {
5384: $result .= &Apache::lonmenu::registerurl(1);
5385: }
1.436 albertel 5386: if (!$args->{'no_nav_bar'}
5387: && !$args->{'only_body'}
5388: && !$args->{'frameset'}) {
5389: $result .= &help_menu_js();
5390: }
1.319 albertel 5391:
1.314 albertel 5392: if (ref($args->{'redirect'})) {
1.414 albertel 5393: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5394: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5395: if (!$inhibit_continue) {
5396: $env{'internal.head.redirect'} = $url;
5397: }
1.313 albertel 5398: $result.=<<ADDMETA
5399: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5400: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5401: ADDMETA
5402: }
1.306 albertel 5403: if (!defined($title)) {
5404: $title = 'The LearningOnline Network with CAPA';
5405: }
1.460 albertel 5406: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5407: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5408: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5409: .$head_extra;
1.306 albertel 5410: return $result;
5411: }
5412:
5413: =pod
5414:
1.340 albertel 5415: =item * &font_settings()
5416:
5417: Returns neccessary <meta> to set the proper encoding
5418:
5419: Inputs: none
5420:
5421: =cut
5422:
5423: sub font_settings {
5424: my $headerstring='';
5425: if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) {
5426: $headerstring.=
5427: '<meta Content-Type="text/html; charset=x-mac-roman" />';
5428: } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
5429: $headerstring.=
5430: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5431: }
5432: return $headerstring;
5433: }
5434:
1.341 albertel 5435: =pod
5436:
5437: =item * &xml_begin()
5438:
5439: Returns the needed doctype and <html>
5440:
5441: Inputs: none
5442:
5443: =cut
5444:
5445: sub xml_begin {
5446: my $output='';
5447:
1.592 albertel 5448: if ($env{'internal.start_page'}==1) {
5449: &Apache::lonhtmlcommon::init_htmlareafields();
5450: }
1.342 albertel 5451:
1.341 albertel 5452: if ($env{'browser.mathml'}) {
5453: $output='<?xml version="1.0"?>'
5454: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5455: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5456:
5457: # .'<!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">] >'
5458: .'<!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">'
5459: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5460: .'xmlns="http://www.w3.org/1999/xhtml">';
5461: } else {
5462: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5463: }
5464: return $output;
5465: }
1.340 albertel 5466:
5467: =pod
5468:
1.306 albertel 5469: =item * &endheadtag()
5470:
5471: Returns a uniform </head> for LON-CAPA web pages.
5472:
5473: Inputs: none
5474:
5475: =cut
5476:
5477: sub endheadtag {
5478: return '</head>';
5479: }
5480:
5481: =pod
5482:
5483: =item * &head()
5484:
5485: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5486:
5487: Inputs: $title - optional title for the page
1.307 albertel 5488: $head_extra - optional extra HTML to put inside the <head>
1.405 albertel 5489:
1.306 albertel 5490: =cut
5491:
5492: sub head {
1.325 albertel 5493: my ($title,$head_extra,$args) = @_;
5494: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 5495: }
5496:
5497: =pod
5498:
5499: =item * &start_page()
5500:
5501: Returns a complete <html> .. <body> section for LON-CAPA web pages.
5502:
5503: Inputs: $title - optional title for the page
5504: $head_extra - optional extra HTML to incude inside the <head>
1.315 albertel 5505: $args - additional optional args supported are:
1.317 albertel 5506: only_body -> is true will set &bodytag() onlybodytag
5507: arg on
5508: no_nav_bar -> is true will set &bodytag() notopbar arg on
5509: add_entries -> additional attributes to add to the <body>
5510: domain -> force to color decorate a page for a
5511: specific domain
5512: function -> force usage of a specific rolish color
5513: scheme
5514: redirect -> see &headtag()
5515: bgcolor -> override the default page bg color
5516: js_ready -> return a string ready for being used in
5517: a javascript writeln
1.320 albertel 5518: html_encode -> return a string ready for being used in
5519: a html attribute
1.317 albertel 5520: force_register -> if is true will turn on the &bodytag()
5521: $forcereg arg
1.326 albertel 5522: body_title -> alternate text to use instead of $title
5523: in the title box that appears, this text
5524: is not auto translated like the $title is
1.330 albertel 5525: frameset -> if true will start with a <frameset>
5526: rather than <body>
1.338 albertel 5527: no_title -> if true the title bar won't be shown
5528: skip_phases -> hash ref of
5529: head -> skip the <html><head> generation
5530: body -> skip all <body> generation
1.337 albertel 5531:
1.361 albertel 5532: no_inline_link -> if true and in remote mode, don't show the
5533: 'Switch To Inline Menu' link
5534:
1.460 albertel 5535: no_auto_mt_title -> prevent &mt()ing the title arg
5536:
1.562 albertel 5537: inherit_jsmath -> when creating popup window in a page,
5538: should it have jsmath forced on by the
5539: current page
5540:
1.306 albertel 5541: =cut
5542:
5543: sub start_page {
1.309 albertel 5544: my ($title,$head_extra,$args) = @_;
1.318 albertel 5545: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 5546: my %head_args;
1.352 albertel 5547: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 5548: 'bgcolor','frameset','no_nav_bar','only_body',
5549: 'no_auto_mt_title') {
1.319 albertel 5550: if (defined($args->{$arg})) {
1.324 raeburn 5551: $head_args{$arg} = $args->{$arg};
1.319 albertel 5552: }
1.313 albertel 5553: }
1.319 albertel 5554:
1.315 albertel 5555: $env{'internal.start_page'}++;
1.338 albertel 5556: my $result;
5557: if (! exists($args->{'skip_phases'}{'head'}) ) {
5558: $result.=
1.341 albertel 5559: &xml_begin().
1.338 albertel 5560: &headtag($title,$head_extra,\%head_args).&endheadtag();
5561: }
5562:
5563: if (! exists($args->{'skip_phases'}{'body'}) ) {
5564: if ($args->{'frameset'}) {
5565: my $attr_string = &make_attr_string($args->{'force_register'},
5566: $args->{'add_entries'});
5567: $result .= "\n<frameset $attr_string>\n";
5568: } else {
5569: $result .=
5570: &bodytag($title,
5571: $args->{'function'}, $args->{'add_entries'},
5572: $args->{'only_body'}, $args->{'domain'},
5573: $args->{'force_register'}, $args->{'body_title'},
5574: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 5575: $args->{'no_title'}, $args->{'no_inline_link'},
5576: $args);
1.338 albertel 5577: }
1.330 albertel 5578: }
1.338 albertel 5579:
1.315 albertel 5580: if ($args->{'js_ready'}) {
1.317 albertel 5581: $result = &js_ready($result);
1.315 albertel 5582: }
1.320 albertel 5583: if ($args->{'html_encode'}) {
5584: $result = &html_encode($result);
5585: }
1.315 albertel 5586: return $result;
1.306 albertel 5587: }
5588:
1.330 albertel 5589:
1.306 albertel 5590: =pod
5591:
5592: =item * &head()
5593:
5594: Returns a complete </body></html> section for LON-CAPA web pages.
5595:
1.315 albertel 5596: Inputs: $args - additional optional args supported are:
5597: js_ready -> return a string ready for being used in
5598: a javascript writeln
1.320 albertel 5599: html_encode -> return a string ready for being used in
5600: a html attribute
1.330 albertel 5601: frameset -> if true will start with a <frameset>
5602: rather than <body>
1.493 albertel 5603: dicsussion -> if true will get discussion from
5604: lonxml::xmlend
5605: (you can pass the target and parser arguments
5606: through optional 'target' and 'parser' args
5607: to this routine)
1.306 albertel 5608:
5609: =cut
5610:
5611: sub end_page {
1.315 albertel 5612: my ($args) = @_;
5613: $env{'internal.end_page'}++;
1.330 albertel 5614: my $result;
1.335 albertel 5615: if ($args->{'discussion'}) {
5616: my ($target,$parser);
5617: if (ref($args->{'discussion'})) {
5618: ($target,$parser) =($args->{'discussion'}{'target'},
5619: $args->{'discussion'}{'parser'});
5620: }
5621: $result .= &Apache::lonxml::xmlend($target,$parser);
5622: }
5623:
1.330 albertel 5624: if ($args->{'frameset'}) {
5625: $result .= '</frameset>';
5626: } else {
1.635 raeburn 5627: $result .= &endbodytag($args);
1.330 albertel 5628: }
5629: $result .= "\n</html>";
5630:
1.315 albertel 5631: if ($args->{'js_ready'}) {
1.317 albertel 5632: $result = &js_ready($result);
1.315 albertel 5633: }
1.335 albertel 5634:
1.320 albertel 5635: if ($args->{'html_encode'}) {
5636: $result = &html_encode($result);
5637: }
1.335 albertel 5638:
1.315 albertel 5639: return $result;
5640: }
5641:
1.320 albertel 5642: sub html_encode {
5643: my ($result) = @_;
5644:
1.322 albertel 5645: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 5646:
5647: return $result;
5648: }
1.317 albertel 5649: sub js_ready {
5650: my ($result) = @_;
5651:
1.323 albertel 5652: $result =~ s/[\n\r]/ /xmsg;
5653: $result =~ s/\\/\\\\/xmsg;
5654: $result =~ s/'/\\'/xmsg;
1.372 albertel 5655: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 5656:
5657: return $result;
5658: }
5659:
1.315 albertel 5660: sub validate_page {
5661: if ( exists($env{'internal.start_page'})
1.316 albertel 5662: && $env{'internal.start_page'} > 1) {
5663: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 5664: $env{'internal.start_page'}.' '.
1.316 albertel 5665: $ENV{'request.filename'});
1.315 albertel 5666: }
5667: if ( exists($env{'internal.end_page'})
1.316 albertel 5668: && $env{'internal.end_page'} > 1) {
5669: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 5670: $env{'internal.end_page'}.' '.
1.316 albertel 5671: $env{'request.filename'});
1.315 albertel 5672: }
5673: if ( exists($env{'internal.start_page'})
5674: && ! exists($env{'internal.end_page'})) {
1.316 albertel 5675: &Apache::lonnet::logthis('start_page called without end_page '.
5676: $env{'request.filename'});
1.315 albertel 5677: }
5678: if ( ! exists($env{'internal.start_page'})
5679: && exists($env{'internal.end_page'})) {
1.316 albertel 5680: &Apache::lonnet::logthis('end_page called without start_page'.
5681: $env{'request.filename'});
1.315 albertel 5682: }
1.306 albertel 5683: }
1.315 albertel 5684:
1.318 albertel 5685: sub simple_error_page {
5686: my ($r,$title,$msg) = @_;
5687: my $page =
5688: &Apache::loncommon::start_page($title).
5689: &mt($msg).
5690: &Apache::loncommon::end_page();
5691: if (ref($r)) {
5692: $r->print($page);
1.327 albertel 5693: return;
1.318 albertel 5694: }
5695: return $page;
5696: }
1.347 albertel 5697:
5698: {
1.610 albertel 5699: my @row_count;
1.347 albertel 5700: sub start_data_table {
1.422 albertel 5701: my ($add_class) = @_;
5702: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 5703: unshift(@row_count,0);
1.422 albertel 5704: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 5705: }
5706:
5707: sub end_data_table {
1.610 albertel 5708: shift(@row_count);
1.389 albertel 5709: return '</table>'."\n";;
1.347 albertel 5710: }
5711:
5712: sub start_data_table_row {
1.422 albertel 5713: my ($add_class) = @_;
1.610 albertel 5714: $row_count[0]++;
5715: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 5716: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 5717: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 5718: }
1.471 banghart 5719:
5720: sub continue_data_table_row {
5721: my ($add_class) = @_;
1.610 albertel 5722: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 5723: $css_class = (join(' ',$css_class,$add_class));
5724: return '<tr class="'.$css_class.'">'."\n";;
5725: }
1.347 albertel 5726:
5727: sub end_data_table_row {
1.389 albertel 5728: return '</tr>'."\n";;
1.347 albertel 5729: }
1.367 www 5730:
1.421 albertel 5731: sub start_data_table_empty_row {
1.610 albertel 5732: $row_count[0]++;
1.421 albertel 5733: return '<tr class="LC_empty_row" >'."\n";;
5734: }
5735:
5736: sub end_data_table_empty_row {
5737: return '</tr>'."\n";;
5738: }
5739:
1.367 www 5740: sub start_data_table_header_row {
1.389 albertel 5741: return '<tr class="LC_header_row">'."\n";;
1.367 www 5742: }
5743:
5744: sub end_data_table_header_row {
1.389 albertel 5745: return '</tr>'."\n";;
1.367 www 5746: }
1.347 albertel 5747: }
5748:
1.548 albertel 5749: =pod
5750:
5751: =item * &inhibit_menu_check($arg)
5752:
5753: Checks for a inhibitmenu state and generates output to preserve it
5754:
5755: Inputs: $arg - can be any of
5756: - undef - in which case the return value is a string
5757: to add into arguments list of a uri
5758: - 'input' - in which case the return value is a HTML
5759: <form> <input> field of type hidden to
5760: preserve the value
5761: - a url - in which case the return value is the url with
5762: the neccesary cgi args added to preserve the
5763: inhibitmenu state
5764: - a ref to a url - no return value, but the string is
5765: updated to include the neccessary cgi
5766: args to preserve the inhibitmenu state
5767:
5768: =cut
5769:
5770: sub inhibit_menu_check {
5771: my ($arg) = @_;
5772: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5773: if ($arg eq 'input') {
5774: if ($env{'form.inhibitmenu'}) {
5775: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
5776: } else {
5777: return
5778: }
5779: }
5780: if ($env{'form.inhibitmenu'}) {
5781: if (ref($arg)) {
5782: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5783: } elsif ($arg eq '') {
5784: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
5785: } else {
5786: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5787: }
5788: }
5789: if (!ref($arg)) {
5790: return $arg;
5791: }
5792: }
5793:
1.251 albertel 5794: ###############################################
1.182 matthew 5795:
5796: =pod
5797:
1.549 albertel 5798: =back
5799:
5800: =head1 User Information Routines
5801:
5802: =over 4
5803:
1.405 albertel 5804: =item * &get_users_function()
1.182 matthew 5805:
5806: Used by &bodytag to determine the current users primary role.
5807: Returns either 'student','coordinator','admin', or 'author'.
5808:
5809: =cut
5810:
5811: ###############################################
5812: sub get_users_function {
5813: my $function = 'student';
1.258 albertel 5814: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 5815: $function='coordinator';
5816: }
1.258 albertel 5817: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 5818: $function='admin';
5819: }
1.258 albertel 5820: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 5821: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
5822: $function='author';
5823: }
5824: return $function;
1.54 www 5825: }
1.99 www 5826:
5827: ###############################################
5828:
1.233 raeburn 5829: =pod
5830:
1.542 raeburn 5831: =item * &check_user_status()
1.274 raeburn 5832:
5833: Determines current status of supplied role for a
5834: specific user. Roles can be active, previous or future.
5835:
5836: Inputs:
5837: user's domain, user's username, course's domain,
1.375 raeburn 5838: course's number, optional section ID.
1.274 raeburn 5839:
5840: Outputs:
5841: role status: active, previous or future.
5842:
5843: =cut
5844:
5845: sub check_user_status {
1.412 raeburn 5846: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 5847: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
5848: my @uroles = keys %userinfo;
5849: my $srchstr;
5850: my $active_chk = 'none';
1.412 raeburn 5851: my $now = time;
1.274 raeburn 5852: if (@uroles > 0) {
1.412 raeburn 5853: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 5854: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
5855: } else {
1.412 raeburn 5856: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
5857: }
5858: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 5859: my $role_end = 0;
5860: my $role_start = 0;
5861: $active_chk = 'active';
1.412 raeburn 5862: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
5863: $role_end = $1;
5864: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
5865: $role_start = $1;
1.274 raeburn 5866: }
5867: }
5868: if ($role_start > 0) {
1.412 raeburn 5869: if ($now < $role_start) {
1.274 raeburn 5870: $active_chk = 'future';
5871: }
5872: }
5873: if ($role_end > 0) {
1.412 raeburn 5874: if ($now > $role_end) {
1.274 raeburn 5875: $active_chk = 'previous';
5876: }
5877: }
5878: }
5879: }
5880: return $active_chk;
5881: }
5882:
5883: ###############################################
5884:
5885: =pod
5886:
1.405 albertel 5887: =item * &get_sections()
1.233 raeburn 5888:
5889: Determines all the sections for a course including
5890: sections with students and sections containing other roles.
1.419 raeburn 5891: Incoming parameters:
5892:
5893: 1. domain
5894: 2. course number
5895: 3. reference to array containing roles for which sections should
5896: be gathered (optional).
5897: 4. reference to array containing status types for which sections
5898: should be gathered (optional).
5899:
5900: If the third argument is undefined, sections are gathered for any role.
5901: If the fourth argument is undefined, sections are gathered for any status.
5902: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 5903:
1.374 raeburn 5904: Returns section hash (keys are section IDs, values are
5905: number of users in each section), subject to the
1.419 raeburn 5906: optional roles filter, optional status filter
1.233 raeburn 5907:
5908: =cut
5909:
5910: ###############################################
5911: sub get_sections {
1.419 raeburn 5912: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 5913: if (!defined($cdom) || !defined($cnum)) {
5914: my $cid = $env{'request.course.id'};
5915:
5916: return if (!defined($cid));
5917:
5918: $cdom = $env{'course.'.$cid.'.domain'};
5919: $cnum = $env{'course.'.$cid.'.num'};
5920: }
5921:
5922: my %sectioncount;
1.419 raeburn 5923: my $now = time;
1.240 albertel 5924:
1.366 albertel 5925: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 5926: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 5927: my $sec_index = &Apache::loncoursedata::CL_SECTION();
5928: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 5929: my $start_index = &Apache::loncoursedata::CL_START();
5930: my $end_index = &Apache::loncoursedata::CL_END();
5931: my $status;
1.366 albertel 5932: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 5933: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
5934: $data->[$status_index],
5935: $data->[$start_index],
5936: $data->[$end_index]);
5937: if ($stu_status eq 'Active') {
5938: $status = 'active';
5939: } elsif ($end < $now) {
5940: $status = 'previous';
5941: } elsif ($start > $now) {
5942: $status = 'future';
5943: }
5944: if ($section ne '-1' && $section !~ /^\s*$/) {
5945: if ((!defined($possible_status)) || (($status ne '') &&
5946: (grep/^\Q$status\E$/,@{$possible_status}))) {
5947: $sectioncount{$section}++;
5948: }
1.240 albertel 5949: }
5950: }
5951: }
5952: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
5953: foreach my $user (sort(keys(%courseroles))) {
5954: if ($user !~ /^(\w{2})/) { next; }
5955: my ($role) = ($user =~ /^(\w{2})/);
5956: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 5957: my ($section,$status);
1.240 albertel 5958: if ($role eq 'cr' &&
5959: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
5960: $section=$1;
5961: }
5962: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
5963: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 5964: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
5965: if ($end == -1 && $start == -1) {
5966: next; #deleted role
5967: }
5968: if (!defined($possible_status)) {
5969: $sectioncount{$section}++;
5970: } else {
5971: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
5972: $status = 'active';
5973: } elsif ($end < $now) {
5974: $status = 'future';
5975: } elsif ($start > $now) {
5976: $status = 'previous';
5977: }
5978: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
5979: $sectioncount{$section}++;
5980: }
5981: }
1.233 raeburn 5982: }
1.366 albertel 5983: return %sectioncount;
1.233 raeburn 5984: }
5985:
1.274 raeburn 5986: ###############################################
1.294 raeburn 5987:
5988: =pod
1.405 albertel 5989:
5990: =item * &get_course_users()
5991:
1.275 raeburn 5992: Retrieves usernames:domains for users in the specified course
5993: with specific role(s), and access status.
5994:
5995: Incoming parameters:
1.277 albertel 5996: 1. course domain
5997: 2. course number
5998: 3. access status: users must have - either active,
1.275 raeburn 5999: previous, future, or all.
1.277 albertel 6000: 4. reference to array of permissible roles
1.288 raeburn 6001: 5. reference to array of section restrictions (optional)
6002: 6. reference to results object (hash of hashes).
6003: 7. reference to optional userdata hash
1.609 raeburn 6004: 8. reference to optional statushash
1.630 raeburn 6005: 9. flag if privileged users (except those set to unhide in
6006: course settings) should be excluded
1.609 raeburn 6007: Keys of top level results hash are roles.
1.275 raeburn 6008: Keys of inner hashes are username:domain, with
6009: values set to access type.
1.288 raeburn 6010: Optional userdata hash returns an array with arguments in the
6011: same order as loncoursedata::get_classlist() for student data.
6012:
1.609 raeburn 6013: Optional statushash returns
6014:
1.288 raeburn 6015: Entries for end, start, section and status are blank because
6016: of the possibility of multiple values for non-student roles.
6017:
1.275 raeburn 6018: =cut
1.405 albertel 6019:
1.275 raeburn 6020: ###############################################
1.405 albertel 6021:
1.275 raeburn 6022: sub get_course_users {
1.630 raeburn 6023: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6024: my %idx = ();
1.419 raeburn 6025: my %seclists;
1.288 raeburn 6026:
6027: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6028: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6029: $idx{end} = &Apache::loncoursedata::CL_END();
6030: $idx{start} = &Apache::loncoursedata::CL_START();
6031: $idx{id} = &Apache::loncoursedata::CL_ID();
6032: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6033: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6034: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6035:
1.290 albertel 6036: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6037: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6038: my $now = time;
1.277 albertel 6039: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6040: my $match = 0;
1.412 raeburn 6041: my $secmatch = 0;
1.419 raeburn 6042: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6043: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6044: if ($section eq '') {
6045: $section = 'none';
6046: }
1.291 albertel 6047: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6048: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6049: $secmatch = 1;
6050: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6051: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6052: $secmatch = 1;
6053: }
6054: } else {
1.419 raeburn 6055: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6056: $secmatch = 1;
6057: }
1.290 albertel 6058: }
1.412 raeburn 6059: if (!$secmatch) {
6060: next;
6061: }
1.419 raeburn 6062: }
1.275 raeburn 6063: if (defined($$types{'active'})) {
1.288 raeburn 6064: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6065: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6066: $match = 1;
1.275 raeburn 6067: }
6068: }
6069: if (defined($$types{'previous'})) {
1.609 raeburn 6070: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6071: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6072: $match = 1;
1.275 raeburn 6073: }
6074: }
6075: if (defined($$types{'future'})) {
1.609 raeburn 6076: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6077: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6078: $match = 1;
1.275 raeburn 6079: }
6080: }
1.609 raeburn 6081: if ($match) {
6082: push(@{$seclists{$student}},$section);
6083: if (ref($userdata) eq 'HASH') {
6084: $$userdata{$student} = $$classlist{$student};
6085: }
6086: if (ref($statushash) eq 'HASH') {
6087: $statushash->{$student}{'st'}{$section} = $status;
6088: }
1.288 raeburn 6089: }
1.275 raeburn 6090: }
6091: }
1.412 raeburn 6092: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6093: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6094: my $now = time;
1.609 raeburn 6095: my %displaystatus = ( previous => 'Expired',
6096: active => 'Active',
6097: future => 'Future',
6098: );
1.630 raeburn 6099: my %nothide;
6100: if ($hidepriv) {
6101: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6102: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6103: if ($user !~ /:/) {
6104: $nothide{join(':',split(/[\@]/,$user))}=1;
6105: } else {
6106: $nothide{$user} = 1;
6107: }
6108: }
6109: }
1.439 raeburn 6110: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6111: my $match = 0;
1.412 raeburn 6112: my $secmatch = 0;
1.439 raeburn 6113: my $status;
1.412 raeburn 6114: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6115: $user =~ s/:$//;
1.439 raeburn 6116: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6117: if ($end == -1 || $start == -1) {
6118: next;
6119: }
6120: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6121: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6122: my ($uname,$udom) = split(/:/,$user);
6123: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6124: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6125: $secmatch = 1;
6126: } elsif ($usec eq '') {
1.420 albertel 6127: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6128: $secmatch = 1;
6129: }
6130: } else {
6131: if (grep(/^\Q$usec\E$/,@{$sections})) {
6132: $secmatch = 1;
6133: }
6134: }
6135: if (!$secmatch) {
6136: next;
6137: }
1.288 raeburn 6138: }
1.419 raeburn 6139: if ($usec eq '') {
6140: $usec = 'none';
6141: }
1.275 raeburn 6142: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6143: if ($hidepriv) {
6144: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6145: (!$nothide{$uname.':'.$udom})) {
6146: next;
6147: }
6148: }
1.503 raeburn 6149: if ($end > 0 && $end < $now) {
1.439 raeburn 6150: $status = 'previous';
6151: } elsif ($start > $now) {
6152: $status = 'future';
6153: } else {
6154: $status = 'active';
6155: }
1.277 albertel 6156: foreach my $type (keys(%{$types})) {
1.275 raeburn 6157: if ($status eq $type) {
1.420 albertel 6158: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6159: push(@{$$users{$role}{$user}},$type);
6160: }
1.288 raeburn 6161: $match = 1;
6162: }
6163: }
1.419 raeburn 6164: if (($match) && (ref($userdata) eq 'HASH')) {
6165: if (!exists($$userdata{$uname.':'.$udom})) {
6166: &get_user_info($udom,$uname,\%idx,$userdata);
6167: }
1.420 albertel 6168: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6169: push(@{$seclists{$uname.':'.$udom}},$usec);
6170: }
1.609 raeburn 6171: if (ref($statushash) eq 'HASH') {
6172: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6173: }
1.275 raeburn 6174: }
6175: }
6176: }
6177: }
1.290 albertel 6178: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6179: if ((defined($cdom)) && (defined($cnum))) {
6180: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6181: if ( defined($csettings{'internal.courseowner'}) ) {
6182: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6183: next if ($owner eq '');
6184: my ($ownername,$ownerdom);
6185: if ($owner =~ /^([^:]+):([^:]+)$/) {
6186: $ownername = $1;
6187: $ownerdom = $2;
6188: } else {
6189: $ownername = $owner;
6190: $ownerdom = $cdom;
6191: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6192: }
6193: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6194: if (defined($userdata) &&
1.609 raeburn 6195: !exists($$userdata{$owner})) {
6196: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6197: if (!grep(/^none$/,@{$seclists{$owner}})) {
6198: push(@{$seclists{$owner}},'none');
6199: }
6200: if (ref($statushash) eq 'HASH') {
6201: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6202: }
1.290 albertel 6203: }
1.279 raeburn 6204: }
6205: }
6206: }
1.419 raeburn 6207: foreach my $user (keys(%seclists)) {
6208: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6209: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6210: }
1.275 raeburn 6211: }
6212: return;
6213: }
6214:
1.288 raeburn 6215: sub get_user_info {
6216: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6217: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6218: &plainname($uname,$udom,'lastname');
1.291 albertel 6219: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6220: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6221: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6222: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6223: return;
6224: }
1.275 raeburn 6225:
1.472 raeburn 6226: ###############################################
6227:
6228: =pod
6229:
6230: =item * &get_user_quota()
6231:
6232: Retrieves quota assigned for storage of portfolio files for a user
6233:
6234: Incoming parameters:
6235: 1. user's username
6236: 2. user's domain
6237:
6238: Returns:
1.536 raeburn 6239: 1. Disk quota (in Mb) assigned to student.
6240: 2. (Optional) Type of setting: custom or default
6241: (individually assigned or default for user's
6242: institutional status).
6243: 3. (Optional) - User's institutional status (e.g., faculty, staff
6244: or student - types as defined in localenroll::inst_usertypes
6245: for user's domain, which determines default quota for user.
6246: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6247:
6248: If a value has been stored in the user's environment,
1.536 raeburn 6249: it will return that, otherwise it returns the maximal default
6250: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6251:
6252: =cut
6253:
6254: ###############################################
6255:
6256:
6257: sub get_user_quota {
6258: my ($uname,$udom) = @_;
1.536 raeburn 6259: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6260: if (!defined($udom)) {
6261: $udom = $env{'user.domain'};
6262: }
6263: if (!defined($uname)) {
6264: $uname = $env{'user.name'};
6265: }
6266: if (($udom eq '' || $uname eq '') ||
6267: ($udom eq 'public') && ($uname eq 'public')) {
6268: $quota = 0;
1.536 raeburn 6269: $quotatype = 'default';
6270: $defquota = 0;
1.472 raeburn 6271: } else {
1.536 raeburn 6272: my $inststatus;
1.472 raeburn 6273: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6274: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6275: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6276: } else {
1.536 raeburn 6277: my %userenv =
6278: &Apache::lonnet::get('environment',['portfolioquota',
6279: 'inststatus'],$udom,$uname);
1.472 raeburn 6280: my ($tmp) = keys(%userenv);
6281: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6282: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6283: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6284: } else {
6285: undef(%userenv);
6286: }
6287: }
1.536 raeburn 6288: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6289: if ($quota eq '') {
1.536 raeburn 6290: $quota = $defquota;
6291: $quotatype = 'default';
6292: } else {
6293: $quotatype = 'custom';
1.472 raeburn 6294: }
6295: }
1.536 raeburn 6296: if (wantarray) {
6297: return ($quota,$quotatype,$settingstatus,$defquota);
6298: } else {
6299: return $quota;
6300: }
1.472 raeburn 6301: }
6302:
6303: ###############################################
6304:
6305: =pod
6306:
6307: =item * &default_quota()
6308:
1.536 raeburn 6309: Retrieves default quota assigned for storage of user portfolio files,
6310: given an (optional) user's institutional status.
1.472 raeburn 6311:
6312: Incoming parameters:
6313: 1. domain
1.536 raeburn 6314: 2. (Optional) institutional status(es). This is a : separated list of
6315: status types (e.g., faculty, staff, student etc.)
6316: which apply to the user for whom the default is being retrieved.
6317: If the institutional status string in undefined, the domain
6318: default quota will be returned.
1.472 raeburn 6319:
6320: Returns:
6321: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6322: 2. (Optional) institutional type which determined the value of the
6323: default quota.
1.472 raeburn 6324:
6325: If a value has been stored in the domain's configuration db,
6326: it will return that, otherwise it returns 20 (for backwards
6327: compatibility with domains which have not set up a configuration
6328: db file; the original statically defined portfolio quota was 20 Mb).
6329:
1.536 raeburn 6330: If the user's status includes multiple types (e.g., staff and student),
6331: the largest default quota which applies to the user determines the
6332: default quota returned.
6333:
1.472 raeburn 6334: =cut
6335:
6336: ###############################################
6337:
6338:
6339: sub default_quota {
1.536 raeburn 6340: my ($udom,$inststatus) = @_;
6341: my ($defquota,$settingstatus);
6342: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6343: ['quotas'],$udom);
6344: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6345: if ($inststatus ne '') {
6346: my @statuses = split(/:/,$inststatus);
6347: foreach my $item (@statuses) {
1.622 raeburn 6348: if ($quotahash{'quotas'}{$item} ne '') {
1.536 raeburn 6349: if ($defquota eq '') {
1.622 raeburn 6350: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6351: $settingstatus = $item;
1.622 raeburn 6352: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6353: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6354: $settingstatus = $item;
6355: }
6356: }
6357: }
6358: }
6359: if ($defquota eq '') {
1.622 raeburn 6360: $defquota = $quotahash{'quotas'}{'default'};
1.536 raeburn 6361: $settingstatus = 'default';
6362: }
6363: } else {
6364: $settingstatus = 'default';
6365: $defquota = 20;
6366: }
6367: if (wantarray) {
6368: return ($defquota,$settingstatus);
1.472 raeburn 6369: } else {
1.536 raeburn 6370: return $defquota;
1.472 raeburn 6371: }
6372: }
6373:
1.384 raeburn 6374: sub get_secgrprole_info {
6375: my ($cdom,$cnum,$needroles,$type) = @_;
6376: my %sections_count = &get_sections($cdom,$cnum);
6377: my @sections = (sort {$a <=> $b} keys(%sections_count));
6378: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6379: my @groups = sort(keys(%curr_groups));
6380: my $allroles = [];
6381: my $rolehash;
6382: my $accesshash = {
6383: active => 'Currently has access',
6384: future => 'Will have future access',
6385: previous => 'Previously had access',
6386: };
6387: if ($needroles) {
6388: $rolehash = {'all' => 'all'};
1.385 albertel 6389: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6390: if (&Apache::lonnet::error(%user_roles)) {
6391: undef(%user_roles);
6392: }
6393: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6394: my ($role)=split(/\:/,$item,2);
6395: if ($role eq 'cr') { next; }
6396: if ($role =~ /^cr/) {
6397: $$rolehash{$role} = (split('/',$role))[3];
6398: } else {
6399: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6400: }
6401: }
6402: foreach my $key (sort(keys(%{$rolehash}))) {
6403: push(@{$allroles},$key);
6404: }
6405: push (@{$allroles},'st');
6406: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6407: }
6408: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6409: }
6410:
1.555 raeburn 6411: sub user_picker {
1.627 raeburn 6412: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6413: my $currdom = $dom;
6414: my %curr_selected = (
6415: srchin => 'dom',
1.580 raeburn 6416: srchby => 'lastname',
1.555 raeburn 6417: );
6418: my $srchterm;
1.625 raeburn 6419: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6420: if ($srch->{'srchby'} ne '') {
6421: $curr_selected{'srchby'} = $srch->{'srchby'};
6422: }
6423: if ($srch->{'srchin'} ne '') {
6424: $curr_selected{'srchin'} = $srch->{'srchin'};
6425: }
6426: if ($srch->{'srchtype'} ne '') {
6427: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6428: }
6429: if ($srch->{'srchdomain'} ne '') {
6430: $currdom = $srch->{'srchdomain'};
6431: }
6432: $srchterm = $srch->{'srchterm'};
6433: }
6434: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6435: 'usr' => 'Search criteria',
1.563 raeburn 6436: 'doma' => 'Domain/institution to search',
1.558 albertel 6437: 'uname' => 'username',
6438: 'lastname' => 'last name',
1.555 raeburn 6439: 'lastfirst' => 'last name, first name',
1.558 albertel 6440: 'crs' => 'in this course',
1.576 raeburn 6441: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6442: 'alc' => 'all LON-CAPA',
1.573 raeburn 6443: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6444: 'exact' => 'is',
6445: 'contains' => 'contains',
1.569 raeburn 6446: 'begins' => 'begins with',
1.571 raeburn 6447: 'youm' => "You must include some text to search for.",
6448: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6449: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6450: 'yomc' => "You must choose a domain when using an institutional directory search.",
6451: 'ymcd' => "You must choose a domain when using a domain search.",
6452: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6453: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6454: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6455: );
1.563 raeburn 6456: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6457: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6458:
6459: my @srchins = ('crs','dom','alc','instd');
6460:
6461: foreach my $option (@srchins) {
6462: # FIXME 'alc' option unavailable until
6463: # loncreateuser::print_user_query_page()
6464: # has been completed.
6465: next if ($option eq 'alc');
6466: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6467: if ($curr_selected{'srchin'} eq $option) {
6468: $srchinsel .= '
6469: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6470: } else {
6471: $srchinsel .= '
6472: <option value="'.$option.'">'.$lt{$option}.'</option>';
6473: }
1.555 raeburn 6474: }
1.563 raeburn 6475: $srchinsel .= "\n </select>\n";
1.555 raeburn 6476:
6477: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 6478: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 6479: if ($curr_selected{'srchby'} eq $option) {
6480: $srchbysel .= '
6481: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6482: } else {
6483: $srchbysel .= '
6484: <option value="'.$option.'">'.$lt{$option}.'</option>';
6485: }
6486: }
6487: $srchbysel .= "\n </select>\n";
6488:
6489: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 6490: foreach my $option ('begins','contains','exact') {
1.555 raeburn 6491: if ($curr_selected{'srchtype'} eq $option) {
6492: $srchtypesel .= '
6493: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6494: } else {
6495: $srchtypesel .= '
6496: <option value="'.$option.'">'.$lt{$option}.'</option>';
6497: }
6498: }
6499: $srchtypesel .= "\n </select>\n";
6500:
1.558 albertel 6501: my ($newuserscript,$new_user_create);
1.556 raeburn 6502:
6503: if ($forcenewuser) {
1.576 raeburn 6504: if (ref($srch) eq 'HASH') {
6505: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 6506: if ($cancreate) {
6507: $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>';
6508: } else {
6509: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
6510: my %usertypetext = (
6511: official => 'institutional',
6512: unofficial => 'non-institutional',
6513: );
6514: $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 />';
6515: }
1.576 raeburn 6516: }
6517: }
6518:
1.556 raeburn 6519: $newuserscript = <<"ENDSCRIPT";
6520:
1.570 raeburn 6521: function setSearch(createnew,callingForm) {
1.556 raeburn 6522: if (createnew == 1) {
1.570 raeburn 6523: for (var i=0; i<callingForm.srchby.length; i++) {
6524: if (callingForm.srchby.options[i].value == 'uname') {
6525: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6526: }
6527: }
1.570 raeburn 6528: for (var i=0; i<callingForm.srchin.length; i++) {
6529: if ( callingForm.srchin.options[i].value == 'dom') {
6530: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6531: }
6532: }
1.570 raeburn 6533: for (var i=0; i<callingForm.srchtype.length; i++) {
6534: if (callingForm.srchtype.options[i].value == 'exact') {
6535: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6536: }
6537: }
1.570 raeburn 6538: for (var i=0; i<callingForm.srchdomain.length; i++) {
6539: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6540: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6541: }
6542: }
6543: }
6544: }
6545: ENDSCRIPT
1.558 albertel 6546:
1.556 raeburn 6547: }
6548:
1.555 raeburn 6549: my $output = <<"END_BLOCK";
1.556 raeburn 6550: <script type="text/javascript">
1.570 raeburn 6551: function validateEntry(callingForm) {
1.558 albertel 6552:
1.556 raeburn 6553: var checkok = 1;
1.558 albertel 6554: var srchin;
1.570 raeburn 6555: for (var i=0; i<callingForm.srchin.length; i++) {
6556: if ( callingForm.srchin[i].checked ) {
6557: srchin = callingForm.srchin[i].value;
1.558 albertel 6558: }
6559: }
6560:
1.570 raeburn 6561: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6562: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6563: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6564: var srchterm = callingForm.srchterm.value;
6565: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6566: var msg = "";
6567:
6568: if (srchterm == "") {
6569: checkok = 0;
1.571 raeburn 6570: msg += "$lt{'youm'}\\n";
1.556 raeburn 6571: }
6572:
1.569 raeburn 6573: if (srchtype== 'begins') {
6574: if (srchterm.length < 2) {
6575: checkok = 0;
1.571 raeburn 6576: msg += "$lt{'thte'}\\n";
1.569 raeburn 6577: }
6578: }
6579:
1.556 raeburn 6580: if (srchtype== 'contains') {
6581: if (srchterm.length < 3) {
6582: checkok = 0;
1.571 raeburn 6583: msg += "$lt{'thet'}\\n";
1.556 raeburn 6584: }
6585: }
6586: if (srchin == 'instd') {
6587: if (srchdomain == '') {
6588: checkok = 0;
1.571 raeburn 6589: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6590: }
6591: }
6592: if (srchin == 'dom') {
6593: if (srchdomain == '') {
6594: checkok = 0;
1.571 raeburn 6595: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6596: }
6597: }
6598: if (srchby == 'lastfirst') {
6599: if (srchterm.indexOf(",") == -1) {
6600: checkok = 0;
1.571 raeburn 6601: msg += "$lt{'whus'}\\n";
1.556 raeburn 6602: }
6603: if (srchterm.indexOf(",") == srchterm.length -1) {
6604: checkok = 0;
1.571 raeburn 6605: msg += "$lt{'whse'}\\n";
1.556 raeburn 6606: }
6607: }
6608: if (checkok == 0) {
1.571 raeburn 6609: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6610: return;
6611: }
6612: if (checkok == 1) {
1.570 raeburn 6613: callingForm.submit();
1.556 raeburn 6614: }
6615: }
6616:
6617: $newuserscript
6618:
6619: </script>
1.558 albertel 6620:
6621: $new_user_create
6622:
1.555 raeburn 6623: <table>
1.558 albertel 6624: <tr>
1.573 raeburn 6625: <td>$lt{'doma'}:</td>
6626: <td>$domform</td>
6627: </td>
6628: </tr>
6629: <tr>
6630: <td>$lt{'usr'}:</td>
1.563 raeburn 6631: <td>$srchbysel
6632: $srchtypesel
6633: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 6634: $srchinsel
1.563 raeburn 6635: </td>
6636: </tr>
1.555 raeburn 6637: </table>
6638: <br />
6639: END_BLOCK
1.558 albertel 6640:
1.555 raeburn 6641: return $output;
6642: }
6643:
1.612 raeburn 6644: sub user_rule_check {
1.615 raeburn 6645: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 6646: my $response;
6647: if (ref($usershash) eq 'HASH') {
6648: foreach my $user (keys(%{$usershash})) {
6649: my ($uname,$udom) = split(/:/,$user);
6650: next if ($udom eq '' || $uname eq '');
1.615 raeburn 6651: my ($id,$newuser);
1.612 raeburn 6652: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 6653: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 6654: $id = $usershash->{$user}->{'id'};
6655: }
6656: my $inst_response;
6657: if (ref($checks) eq 'HASH') {
6658: if (defined($checks->{'username'})) {
1.615 raeburn 6659: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6660: &Apache::lonnet::get_instuser($udom,$uname);
6661: } elsif (defined($checks->{'id'})) {
1.615 raeburn 6662: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6663: &Apache::lonnet::get_instuser($udom,undef,$id);
6664: }
1.615 raeburn 6665: } else {
6666: ($inst_response,%{$inst_results->{$user}}) =
6667: &Apache::lonnet::get_instuser($udom,$uname);
6668: return;
1.612 raeburn 6669: }
1.615 raeburn 6670: if (!$got_rules->{$udom}) {
1.612 raeburn 6671: my %domconfig = &Apache::lonnet::get_dom('configuration',
6672: ['usercreation'],$udom);
6673: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 6674: foreach my $item ('username','id') {
1.612 raeburn 6675: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6676: $$curr_rules{$udom}{$item} =
6677: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 6678: }
6679: }
6680: }
1.615 raeburn 6681: $got_rules->{$udom} = 1;
1.585 raeburn 6682: }
1.612 raeburn 6683: foreach my $item (keys(%{$checks})) {
6684: if (ref($$curr_rules{$udom}) eq 'HASH') {
6685: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
6686: if (@{$$curr_rules{$udom}{$item}} > 0) {
6687: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
6688: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
6689: if ($rule_check{$rule}) {
6690: $$rulematch{$user}{$item} = $rule;
6691: if ($inst_response eq 'ok') {
1.615 raeburn 6692: if (ref($inst_results) eq 'HASH') {
6693: if (ref($inst_results->{$user}) eq 'HASH') {
6694: if (keys(%{$inst_results->{$user}}) == 0) {
6695: $$alerts{$item}{$udom}{$uname} = 1;
6696: }
1.612 raeburn 6697: }
6698: }
1.615 raeburn 6699: }
6700: last;
1.585 raeburn 6701: }
6702: }
6703: }
6704: }
6705: }
6706: }
6707: }
6708: }
1.612 raeburn 6709: return;
6710: }
6711:
6712: sub user_rule_formats {
6713: my ($domain,$domdesc,$curr_rules,$check) = @_;
6714: my %text = (
6715: 'username' => 'Usernames',
6716: 'id' => 'IDs',
6717: );
6718: my $output;
6719: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
6720: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
6721: if (@{$ruleorder} > 0) {
6722: $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>';
6723: foreach my $rule (@{$ruleorder}) {
6724: if (ref($curr_rules) eq 'ARRAY') {
6725: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
6726: if (ref($rules->{$rule}) eq 'HASH') {
6727: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
6728: $rules->{$rule}{'desc'}.'</li>';
6729: }
6730: }
6731: }
6732: }
6733: $output .= '</ul>';
6734: }
6735: }
6736: return $output;
6737: }
6738:
6739: sub instrule_disallow_msg {
1.615 raeburn 6740: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 6741: my $response;
6742: my %text = (
6743: item => 'username',
6744: items => 'usernames',
6745: match => 'matches',
6746: do => 'does',
6747: action => 'a username',
6748: one => 'one',
6749: );
6750: if ($count > 1) {
6751: $text{'item'} = 'usernames';
6752: $text{'match'} ='match';
6753: $text{'do'} = 'do';
6754: $text{'action'} = 'usernames',
6755: $text{'one'} = 'ones';
6756: }
6757: if ($checkitem eq 'id') {
6758: $text{'items'} = 'IDs';
6759: $text{'item'} = 'ID';
6760: $text{'action'} = 'an ID';
1.615 raeburn 6761: if ($count > 1) {
6762: $text{'item'} = 'IDs';
6763: $text{'action'} = 'IDs';
6764: }
1.612 raeburn 6765: }
6766: $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for <span class=\"LC_cusr_emph\">[_1]</span>, but the $text{'item'} $text{'do'} not exist in the institutional directory.",$domdesc).'<br />';
1.615 raeburn 6767: if ($mode eq 'upload') {
6768: if ($checkitem eq 'username') {
6769: $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'}.");
6770: } elsif ($checkitem eq 'id') {
6771: $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 ID/Student Number field.");
6772: }
6773: } else {
6774: if ($checkitem eq 'username') {
6775: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
6776: } elsif ($checkitem eq 'id') {
6777: $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.");
6778: }
1.612 raeburn 6779: }
6780: return $response;
1.585 raeburn 6781: }
6782:
1.624 raeburn 6783: sub personal_data_fieldtitles {
6784: my %fieldtitles = &Apache::lonlocal::texthash (
6785: id => 'Student/Employee ID',
6786: permanentemail => 'E-mail address',
6787: lastname => 'Last Name',
6788: firstname => 'First Name',
6789: middlename => 'Middle Name',
6790: generation => 'Generation',
6791: gen => 'Generation',
6792: );
6793: return %fieldtitles;
6794: }
6795:
1.112 bowersj2 6796: =pod
6797:
1.549 albertel 6798: =back
6799:
6800: =head1 HTTP Helpers
6801:
6802: =over 4
6803:
1.112 bowersj2 6804: =item * get_unprocessed_cgi($query,$possible_names)
6805:
1.258 albertel 6806: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 6807: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 6808: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 6809:
6810: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
6811: $possible_names is an ref to an array of form element names. As an example:
6812: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 6813: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 6814:
6815: =cut
1.1 albertel 6816:
1.6 albertel 6817: sub get_unprocessed_cgi {
1.25 albertel 6818: my ($query,$possible_names)= @_;
1.26 matthew 6819: # $Apache::lonxml::debug=1;
1.356 albertel 6820: foreach my $pair (split(/&/,$query)) {
6821: my ($name, $value) = split(/=/,$pair);
1.369 www 6822: $name = &unescape($name);
1.25 albertel 6823: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
6824: $value =~ tr/+/ /;
6825: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 6826: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 6827: }
1.16 harris41 6828: }
1.6 albertel 6829: }
6830:
1.112 bowersj2 6831: =pod
6832:
6833: =item * cacheheader()
6834:
6835: returns cache-controlling header code
6836:
6837: =cut
6838:
1.7 albertel 6839: sub cacheheader {
1.258 albertel 6840: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 6841: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
6842: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 6843: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
6844: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 6845: return $output;
1.7 albertel 6846: }
6847:
1.112 bowersj2 6848: =pod
6849:
6850: =item * no_cache($r)
6851:
6852: specifies header code to not have cache
6853:
6854: =cut
6855:
1.9 albertel 6856: sub no_cache {
1.216 albertel 6857: my ($r) = @_;
6858: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 6859: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 6860: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
6861: $r->no_cache(1);
6862: $r->header_out("Expires" => $date);
6863: $r->header_out("Pragma" => "no-cache");
1.123 www 6864: }
6865:
6866: sub content_type {
1.181 albertel 6867: my ($r,$type,$charset) = @_;
1.299 foxr 6868: if ($r) {
6869: # Note that printout.pl calls this with undef for $r.
6870: &no_cache($r);
6871: }
1.258 albertel 6872: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 6873: unless ($charset) {
6874: $charset=&Apache::lonlocal::current_encoding;
6875: }
6876: if ($charset) { $type.='; charset='.$charset; }
6877: if ($r) {
6878: $r->content_type($type);
6879: } else {
6880: print("Content-type: $type\n\n");
6881: }
1.9 albertel 6882: }
1.25 albertel 6883:
1.112 bowersj2 6884: =pod
6885:
6886: =item * add_to_env($name,$value)
6887:
1.258 albertel 6888: adds $name to the %env hash with value
1.112 bowersj2 6889: $value, if $name already exists, the entry is converted to an array
6890: reference and $value is added to the array.
6891:
6892: =cut
6893:
1.25 albertel 6894: sub add_to_env {
6895: my ($name,$value)=@_;
1.258 albertel 6896: if (defined($env{$name})) {
6897: if (ref($env{$name})) {
1.25 albertel 6898: #already have multiple values
1.258 albertel 6899: push(@{ $env{$name} },$value);
1.25 albertel 6900: } else {
6901: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 6902: my $first=$env{$name};
6903: undef($env{$name});
6904: push(@{ $env{$name} },$first,$value);
1.25 albertel 6905: }
6906: } else {
1.258 albertel 6907: $env{$name}=$value;
1.25 albertel 6908: }
1.31 albertel 6909: }
1.149 albertel 6910:
6911: =pod
6912:
6913: =item * get_env_multiple($name)
6914:
1.258 albertel 6915: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 6916: values may be defined and end up as an array ref.
6917:
6918: returns an array of values
6919:
6920: =cut
6921:
6922: sub get_env_multiple {
6923: my ($name) = @_;
6924: my @values;
1.258 albertel 6925: if (defined($env{$name})) {
1.149 albertel 6926: # exists is it an array
1.258 albertel 6927: if (ref($env{$name})) {
6928: @values=@{ $env{$name} };
1.149 albertel 6929: } else {
1.258 albertel 6930: $values[0]=$env{$name};
1.149 albertel 6931: }
6932: }
6933: return(@values);
6934: }
6935:
1.31 albertel 6936:
1.41 ng 6937: =pod
1.45 matthew 6938:
1.464 albertel 6939: =back
1.41 ng 6940:
1.112 bowersj2 6941: =head1 CSV Upload/Handling functions
1.38 albertel 6942:
1.41 ng 6943: =over 4
6944:
1.112 bowersj2 6945: =item * upfile_store($r)
1.41 ng 6946:
6947: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 6948: needs $env{'form.upfile'}
1.41 ng 6949: returns $datatoken to be put into hidden field
6950:
6951: =cut
1.31 albertel 6952:
6953: sub upfile_store {
6954: my $r=shift;
1.258 albertel 6955: $env{'form.upfile'}=~s/\r/\n/gs;
6956: $env{'form.upfile'}=~s/\f/\n/gs;
6957: $env{'form.upfile'}=~s/\n+/\n/gs;
6958: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 6959:
1.258 albertel 6960: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
6961: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 6962: {
1.158 raeburn 6963: my $datafile = $r->dir_config('lonDaemons').
6964: '/tmp/'.$datatoken.'.tmp';
6965: if ( open(my $fh,">$datafile") ) {
1.258 albertel 6966: print $fh $env{'form.upfile'};
1.158 raeburn 6967: close($fh);
6968: }
1.31 albertel 6969: }
6970: return $datatoken;
6971: }
6972:
1.56 matthew 6973: =pod
6974:
1.112 bowersj2 6975: =item * load_tmp_file($r)
1.41 ng 6976:
6977: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 6978: needs $env{'form.datatoken'},
6979: sets $env{'form.upfile'} to the contents of the file
1.41 ng 6980:
6981: =cut
1.31 albertel 6982:
6983: sub load_tmp_file {
6984: my $r=shift;
6985: my @studentdata=();
6986: {
1.158 raeburn 6987: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 6988: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 6989: if ( open(my $fh,"<$studentfile") ) {
6990: @studentdata=<$fh>;
6991: close($fh);
6992: }
1.31 albertel 6993: }
1.258 albertel 6994: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 6995: }
6996:
1.56 matthew 6997: =pod
6998:
1.112 bowersj2 6999: =item * upfile_record_sep()
1.41 ng 7000:
7001: Separate uploaded file into records
7002: returns array of records,
1.258 albertel 7003: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7004:
7005: =cut
1.31 albertel 7006:
7007: sub upfile_record_sep {
1.258 albertel 7008: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7009: } else {
1.248 albertel 7010: my @records;
1.258 albertel 7011: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7012: if ($line=~/^\s*$/) { next; }
7013: push(@records,$line);
7014: }
7015: return @records;
1.31 albertel 7016: }
7017: }
7018:
1.56 matthew 7019: =pod
7020:
1.112 bowersj2 7021: =item * record_sep($record)
1.41 ng 7022:
1.258 albertel 7023: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7024:
7025: =cut
7026:
1.263 www 7027: sub takeleft {
7028: my $index=shift;
7029: return substr('0000'.$index,-4,4);
7030: }
7031:
1.31 albertel 7032: sub record_sep {
7033: my $record=shift;
7034: my %components=();
1.258 albertel 7035: if ($env{'form.upfiletype'} eq 'xml') {
7036: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7037: my $i=0;
1.356 albertel 7038: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7039: $field=~s/^(\"|\')//;
7040: $field=~s/(\"|\')$//;
1.263 www 7041: $components{&takeleft($i)}=$field;
1.31 albertel 7042: $i++;
7043: }
1.258 albertel 7044: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7045: my $i=0;
1.356 albertel 7046: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7047: $field=~s/^(\"|\')//;
7048: $field=~s/(\"|\')$//;
1.263 www 7049: $components{&takeleft($i)}=$field;
1.31 albertel 7050: $i++;
7051: }
7052: } else {
1.561 www 7053: my $separator=',';
1.480 banghart 7054: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7055: $separator=';';
1.480 banghart 7056: }
1.31 albertel 7057: my $i=0;
1.561 www 7058: # the character we are looking for to indicate the end of a quote or a record
7059: my $looking_for=$separator;
7060: # do not add the characters to the fields
7061: my $ignore=0;
7062: # we just encountered a separator (or the beginning of the record)
7063: my $just_found_separator=1;
7064: # store the field we are working on here
7065: my $field='';
7066: # work our way through all characters in record
7067: foreach my $character ($record=~/(.)/g) {
7068: if ($character eq $looking_for) {
7069: if ($character ne $separator) {
7070: # Found the end of a quote, again looking for separator
7071: $looking_for=$separator;
7072: $ignore=1;
7073: } else {
7074: # Found a separator, store away what we got
7075: $components{&takeleft($i)}=$field;
7076: $i++;
7077: $just_found_separator=1;
7078: $ignore=0;
7079: $field='';
7080: }
7081: next;
7082: }
7083: # single or double quotation marks after a separator indicate beginning of a quote
7084: # we are now looking for the end of the quote and need to ignore separators
7085: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7086: $looking_for=$character;
7087: next;
7088: }
7089: # ignore would be true after we reached the end of a quote
7090: if ($ignore) { next; }
7091: if (($just_found_separator) && ($character=~/\s/)) { next; }
7092: $field.=$character;
7093: $just_found_separator=0;
1.31 albertel 7094: }
1.561 www 7095: # catch the very last entry, since we never encountered the separator
7096: $components{&takeleft($i)}=$field;
1.31 albertel 7097: }
7098: return %components;
7099: }
7100:
1.144 matthew 7101: ######################################################
7102: ######################################################
7103:
1.56 matthew 7104: =pod
7105:
1.112 bowersj2 7106: =item * upfile_select_html()
1.41 ng 7107:
1.144 matthew 7108: Return HTML code to select a file from the users machine and specify
7109: the file type.
1.41 ng 7110:
7111: =cut
7112:
1.144 matthew 7113: ######################################################
7114: ######################################################
1.31 albertel 7115: sub upfile_select_html {
1.144 matthew 7116: my %Types = (
7117: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7118: semisv => &mt('Semicolon separated values'),
1.144 matthew 7119: space => &mt('Space separated'),
7120: tab => &mt('Tabulator separated'),
7121: # xml => &mt('HTML/XML'),
7122: );
7123: my $Str = '<input type="file" name="upfile" size="50" />'.
7124: '<br />Type: <select name="upfiletype">';
7125: foreach my $type (sort(keys(%Types))) {
7126: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7127: }
7128: $Str .= "</select>\n";
7129: return $Str;
1.31 albertel 7130: }
7131:
1.301 albertel 7132: sub get_samples {
7133: my ($records,$toget) = @_;
7134: my @samples=({});
7135: my $got=0;
7136: foreach my $rec (@$records) {
7137: my %temp = &record_sep($rec);
7138: if (! grep(/\S/, values(%temp))) { next; }
7139: if (%temp) {
7140: $samples[$got]=\%temp;
7141: $got++;
7142: if ($got == $toget) { last; }
7143: }
7144: }
7145: return \@samples;
7146: }
7147:
1.144 matthew 7148: ######################################################
7149: ######################################################
7150:
1.56 matthew 7151: =pod
7152:
1.112 bowersj2 7153: =item * csv_print_samples($r,$records)
1.41 ng 7154:
7155: Prints a table of sample values from each column uploaded $r is an
7156: Apache Request ref, $records is an arrayref from
7157: &Apache::loncommon::upfile_record_sep
7158:
7159: =cut
7160:
1.144 matthew 7161: ######################################################
7162: ######################################################
1.31 albertel 7163: sub csv_print_samples {
7164: my ($r,$records) = @_;
1.301 albertel 7165: my $samples = &get_samples($records,3);
7166:
1.594 raeburn 7167: $r->print(&mt('Samples').'<br />'.&start_data_table().
7168: &start_data_table_header_row());
1.356 albertel 7169: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7170: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 7171: $r->print(&end_data_table_header_row());
1.301 albertel 7172: foreach my $hash (@$samples) {
1.594 raeburn 7173: $r->print(&start_data_table_row());
1.356 albertel 7174: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7175: $r->print('<td>');
1.356 albertel 7176: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 7177: $r->print('</td>');
7178: }
1.594 raeburn 7179: $r->print(&end_data_table_row());
1.31 albertel 7180: }
1.594 raeburn 7181: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 7182: }
7183:
1.144 matthew 7184: ######################################################
7185: ######################################################
7186:
1.56 matthew 7187: =pod
7188:
1.112 bowersj2 7189: =item * csv_print_select_table($r,$records,$d)
1.41 ng 7190:
7191: Prints a table to create associations between values and table columns.
1.144 matthew 7192:
1.41 ng 7193: $r is an Apache Request ref,
7194: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7195: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7196:
7197: =cut
7198:
1.144 matthew 7199: ######################################################
7200: ######################################################
1.31 albertel 7201: sub csv_print_select_table {
7202: my ($r,$records,$d) = @_;
1.301 albertel 7203: my $i=0;
7204: my $samples = &get_samples($records,1);
1.144 matthew 7205: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7206: &start_data_table().&start_data_table_header_row().
1.144 matthew 7207: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7208: '<th>'.&mt('Column').'</th>'.
7209: &end_data_table_header_row()."\n");
1.356 albertel 7210: foreach my $array_ref (@$d) {
7211: my ($value,$display,$defaultcol)=@{ $array_ref };
1.594 raeburn 7212: $r->print(&start_data_table_row().'<tr><td>'.$display.'</td>');
1.31 albertel 7213:
7214: $r->print('<td><select name=f'.$i.
1.32 matthew 7215: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7216: $r->print('<option value="none"></option>');
1.356 albertel 7217: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7218: $r->print('<option value="'.$sample.'"'.
7219: ($sample eq $defaultcol ? ' selected="selected" ' : '').
7220: '>Column '.($sample+1).'</option>');
1.31 albertel 7221: }
1.594 raeburn 7222: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7223: $i++;
7224: }
1.594 raeburn 7225: $r->print(&end_data_table());
1.31 albertel 7226: $i--;
7227: return $i;
7228: }
1.56 matthew 7229:
1.144 matthew 7230: ######################################################
7231: ######################################################
7232:
1.56 matthew 7233: =pod
1.31 albertel 7234:
1.112 bowersj2 7235: =item * csv_samples_select_table($r,$records,$d)
1.41 ng 7236:
7237: Prints a table of sample values from the upload and can make associate samples to internal names.
7238:
7239: $r is an Apache Request ref,
7240: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7241: $d is an array of 2 element arrays (internal name, displayed name)
7242:
7243: =cut
7244:
1.144 matthew 7245: ######################################################
7246: ######################################################
1.31 albertel 7247: sub csv_samples_select_table {
7248: my ($r,$records,$d) = @_;
7249: my $i=0;
1.144 matthew 7250: #
1.301 albertel 7251: my $samples = &get_samples($records,3);
1.594 raeburn 7252: $r->print(&start_data_table().
7253: &start_data_table_header_row().'<th>'.
7254: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7255: &end_data_table_header_row());
1.301 albertel 7256:
7257: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7258: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7259: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7260: foreach my $option (@$d) {
7261: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7262: $r->print('<option value="'.$value.'"'.
1.253 albertel 7263: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7264: $display.'</option>');
1.31 albertel 7265: }
7266: $r->print('</select></td><td>');
1.301 albertel 7267: foreach my $line (0..2) {
7268: if (defined($samples->[$line]{$key})) {
7269: $r->print($samples->[$line]{$key}."<br />\n");
7270: }
7271: }
1.594 raeburn 7272: $r->print('</td>'.&end_data_table_row());
1.31 albertel 7273: $i++;
7274: }
1.594 raeburn 7275: $r->print(&end_data_table());
1.31 albertel 7276: $i--;
7277: return($i);
1.115 matthew 7278: }
7279:
1.144 matthew 7280: ######################################################
7281: ######################################################
7282:
1.115 matthew 7283: =pod
7284:
7285: =item clean_excel_name($name)
7286:
7287: Returns a replacement for $name which does not contain any illegal characters.
7288:
7289: =cut
7290:
1.144 matthew 7291: ######################################################
7292: ######################################################
1.115 matthew 7293: sub clean_excel_name {
7294: my ($name) = @_;
7295: $name =~ s/[:\*\?\/\\]//g;
7296: if (length($name) > 31) {
7297: $name = substr($name,0,31);
7298: }
7299: return $name;
1.25 albertel 7300: }
1.84 albertel 7301:
1.85 albertel 7302: =pod
7303:
1.112 bowersj2 7304: =item * check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 7305:
7306: Returns either 1 or undef
7307:
7308: 1 if the part is to be hidden, undef if it is to be shown
7309:
7310: Arguments are:
7311:
7312: $id the id of the part to be checked
7313: $symb, optional the symb of the resource to check
7314: $udom, optional the domain of the user to check for
7315: $uname, optional the username of the user to check for
7316:
7317: =cut
1.84 albertel 7318:
7319: sub check_if_partid_hidden {
7320: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 7321: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 7322: $symb,$udom,$uname);
1.141 albertel 7323: my $truth=1;
7324: #if the string starts with !, then the list is the list to show not hide
7325: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 7326: my @hiddenlist=split(/,/,$hiddenparts);
7327: foreach my $checkid (@hiddenlist) {
1.141 albertel 7328: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 7329: }
1.141 albertel 7330: return !$truth;
1.84 albertel 7331: }
1.127 matthew 7332:
1.138 matthew 7333:
7334: ############################################################
7335: ############################################################
7336:
7337: =pod
7338:
1.157 matthew 7339: =back
7340:
1.138 matthew 7341: =head1 cgi-bin script and graphing routines
7342:
1.157 matthew 7343: =over 4
7344:
1.138 matthew 7345: =item get_cgi_id
7346:
7347: Inputs: none
7348:
7349: Returns an id which can be used to pass environment variables
7350: to various cgi-bin scripts. These environment variables will
7351: be removed from the users environment after a given time by
7352: the routine &Apache::lonnet::transfer_profile_to_env.
7353:
7354: =cut
7355:
7356: ############################################################
7357: ############################################################
1.152 albertel 7358: my $uniq=0;
1.136 matthew 7359: sub get_cgi_id {
1.154 albertel 7360: $uniq=($uniq+1)%100000;
1.280 albertel 7361: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 7362: }
7363:
1.127 matthew 7364: ############################################################
7365: ############################################################
7366:
7367: =pod
7368:
1.134 matthew 7369: =item DrawBarGraph
1.127 matthew 7370:
1.138 matthew 7371: Facilitates the plotting of data in a (stacked) bar graph.
7372: Puts plot definition data into the users environment in order for
7373: graph.png to plot it. Returns an <img> tag for the plot.
7374: The bars on the plot are labeled '1','2',...,'n'.
7375:
7376: Inputs:
7377:
7378: =over 4
7379:
7380: =item $Title: string, the title of the plot
7381:
7382: =item $xlabel: string, text describing the X-axis of the plot
7383:
7384: =item $ylabel: string, text describing the Y-axis of the plot
7385:
7386: =item $Max: scalar, the maximum Y value to use in the plot
7387: If $Max is < any data point, the graph will not be rendered.
7388:
1.140 matthew 7389: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 7390: they are plotted. If undefined, default values will be used.
7391:
1.178 matthew 7392: =item $labels: array ref holding the labels to use on the x-axis for the bars.
7393:
1.138 matthew 7394: =item @Values: An array of array references. Each array reference holds data
7395: to be plotted in a stacked bar chart.
7396:
1.239 matthew 7397: =item If the final element of @Values is a hash reference the key/value
7398: pairs will be added to the graph definition.
7399:
1.138 matthew 7400: =back
7401:
7402: Returns:
7403:
7404: An <img> tag which references graph.png and the appropriate identifying
7405: information for the plot.
7406:
1.127 matthew 7407: =cut
7408:
7409: ############################################################
7410: ############################################################
1.134 matthew 7411: sub DrawBarGraph {
1.178 matthew 7412: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 7413: #
7414: if (! defined($colors)) {
7415: $colors = ['#33ff00',
7416: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
7417: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
7418: ];
7419: }
1.228 matthew 7420: my $extra_settings = {};
7421: if (ref($Values[-1]) eq 'HASH') {
7422: $extra_settings = pop(@Values);
7423: }
1.127 matthew 7424: #
1.136 matthew 7425: my $identifier = &get_cgi_id();
7426: my $id = 'cgi.'.$identifier;
1.129 matthew 7427: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 7428: return '';
7429: }
1.225 matthew 7430: #
7431: my @Labels;
7432: if (defined($labels)) {
7433: @Labels = @$labels;
7434: } else {
7435: for (my $i=0;$i<@{$Values[0]};$i++) {
7436: push (@Labels,$i+1);
7437: }
7438: }
7439: #
1.129 matthew 7440: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 7441: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 7442: my %ValuesHash;
7443: my $NumSets=1;
7444: foreach my $array (@Values) {
7445: next if (! ref($array));
1.136 matthew 7446: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 7447: join(',',@$array);
1.129 matthew 7448: }
1.127 matthew 7449: #
1.136 matthew 7450: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 7451: if ($NumBars < 3) {
7452: $width = 120+$NumBars*32;
1.220 matthew 7453: $xskip = 1;
1.225 matthew 7454: $bar_width = 30;
7455: } elsif ($NumBars < 5) {
7456: $width = 120+$NumBars*20;
7457: $xskip = 1;
7458: $bar_width = 20;
1.220 matthew 7459: } elsif ($NumBars < 10) {
1.136 matthew 7460: $width = 120+$NumBars*15;
7461: $xskip = 1;
7462: $bar_width = 15;
7463: } elsif ($NumBars <= 25) {
7464: $width = 120+$NumBars*11;
7465: $xskip = 5;
7466: $bar_width = 8;
7467: } elsif ($NumBars <= 50) {
7468: $width = 120+$NumBars*8;
7469: $xskip = 5;
7470: $bar_width = 4;
7471: } else {
7472: $width = 120+$NumBars*8;
7473: $xskip = 5;
7474: $bar_width = 4;
7475: }
7476: #
1.137 matthew 7477: $Max = 1 if ($Max < 1);
7478: if ( int($Max) < $Max ) {
7479: $Max++;
7480: $Max = int($Max);
7481: }
1.127 matthew 7482: $Title = '' if (! defined($Title));
7483: $xlabel = '' if (! defined($xlabel));
7484: $ylabel = '' if (! defined($ylabel));
1.369 www 7485: $ValuesHash{$id.'.title'} = &escape($Title);
7486: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
7487: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 7488: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 7489: $ValuesHash{$id.'.NumBars'} = $NumBars;
7490: $ValuesHash{$id.'.NumSets'} = $NumSets;
7491: $ValuesHash{$id.'.PlotType'} = 'bar';
7492: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7493: $ValuesHash{$id.'.height'} = $height;
7494: $ValuesHash{$id.'.width'} = $width;
7495: $ValuesHash{$id.'.xskip'} = $xskip;
7496: $ValuesHash{$id.'.bar_width'} = $bar_width;
7497: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 7498: #
1.228 matthew 7499: # Deal with other parameters
7500: while (my ($key,$value) = each(%$extra_settings)) {
7501: $ValuesHash{$id.'.'.$key} = $value;
7502: }
7503: #
1.137 matthew 7504: &Apache::lonnet::appenv(%ValuesHash);
7505: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7506: }
7507:
7508: ############################################################
7509: ############################################################
7510:
7511: =pod
7512:
7513: =item DrawXYGraph
7514:
1.138 matthew 7515: Facilitates the plotting of data in an XY graph.
7516: Puts plot definition data into the users environment in order for
7517: graph.png to plot it. Returns an <img> tag for the plot.
7518:
7519: Inputs:
7520:
7521: =over 4
7522:
7523: =item $Title: string, the title of the plot
7524:
7525: =item $xlabel: string, text describing the X-axis of the plot
7526:
7527: =item $ylabel: string, text describing the Y-axis of the plot
7528:
7529: =item $Max: scalar, the maximum Y value to use in the plot
7530: If $Max is < any data point, the graph will not be rendered.
7531:
7532: =item $colors: Array ref containing the hex color codes for the data to be
7533: plotted in. If undefined, default values will be used.
7534:
7535: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7536:
7537: =item $Ydata: Array ref containing Array refs.
1.185 www 7538: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 7539:
7540: =item %Values: hash indicating or overriding any default values which are
7541: passed to graph.png.
7542: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7543:
7544: =back
7545:
7546: Returns:
7547:
7548: An <img> tag which references graph.png and the appropriate identifying
7549: information for the plot.
7550:
1.137 matthew 7551: =cut
7552:
7553: ############################################################
7554: ############################################################
7555: sub DrawXYGraph {
7556: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
7557: #
7558: # Create the identifier for the graph
7559: my $identifier = &get_cgi_id();
7560: my $id = 'cgi.'.$identifier;
7561: #
7562: $Title = '' if (! defined($Title));
7563: $xlabel = '' if (! defined($xlabel));
7564: $ylabel = '' if (! defined($ylabel));
7565: my %ValuesHash =
7566: (
1.369 www 7567: $id.'.title' => &escape($Title),
7568: $id.'.xlabel' => &escape($xlabel),
7569: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 7570: $id.'.y_max_value'=> $Max,
7571: $id.'.labels' => join(',',@$Xlabels),
7572: $id.'.PlotType' => 'XY',
7573: );
7574: #
7575: if (defined($colors) && ref($colors) eq 'ARRAY') {
7576: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7577: }
7578: #
7579: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
7580: return '';
7581: }
7582: my $NumSets=1;
1.138 matthew 7583: foreach my $array (@{$Ydata}){
1.137 matthew 7584: next if (! ref($array));
7585: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
7586: }
1.138 matthew 7587: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 7588: #
7589: # Deal with other parameters
7590: while (my ($key,$value) = each(%Values)) {
7591: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 7592: }
7593: #
1.136 matthew 7594: &Apache::lonnet::appenv(%ValuesHash);
7595: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7596: }
7597:
7598: ############################################################
7599: ############################################################
7600:
7601: =pod
7602:
1.138 matthew 7603: =item DrawXYYGraph
7604:
7605: Facilitates the plotting of data in an XY graph with two Y axes.
7606: Puts plot definition data into the users environment in order for
7607: graph.png to plot it. Returns an <img> tag for the plot.
7608:
7609: Inputs:
7610:
7611: =over 4
7612:
7613: =item $Title: string, the title of the plot
7614:
7615: =item $xlabel: string, text describing the X-axis of the plot
7616:
7617: =item $ylabel: string, text describing the Y-axis of the plot
7618:
7619: =item $colors: Array ref containing the hex color codes for the data to be
7620: plotted in. If undefined, default values will be used.
7621:
7622: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7623:
7624: =item $Ydata1: The first data set
7625:
7626: =item $Min1: The minimum value of the left Y-axis
7627:
7628: =item $Max1: The maximum value of the left Y-axis
7629:
7630: =item $Ydata2: The second data set
7631:
7632: =item $Min2: The minimum value of the right Y-axis
7633:
7634: =item $Max2: The maximum value of the left Y-axis
7635:
7636: =item %Values: hash indicating or overriding any default values which are
7637: passed to graph.png.
7638: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7639:
7640: =back
7641:
7642: Returns:
7643:
7644: An <img> tag which references graph.png and the appropriate identifying
7645: information for the plot.
1.136 matthew 7646:
7647: =cut
7648:
7649: ############################################################
7650: ############################################################
1.137 matthew 7651: sub DrawXYYGraph {
7652: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
7653: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 7654: #
7655: # Create the identifier for the graph
7656: my $identifier = &get_cgi_id();
7657: my $id = 'cgi.'.$identifier;
7658: #
7659: $Title = '' if (! defined($Title));
7660: $xlabel = '' if (! defined($xlabel));
7661: $ylabel = '' if (! defined($ylabel));
7662: my %ValuesHash =
7663: (
1.369 www 7664: $id.'.title' => &escape($Title),
7665: $id.'.xlabel' => &escape($xlabel),
7666: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 7667: $id.'.labels' => join(',',@$Xlabels),
7668: $id.'.PlotType' => 'XY',
7669: $id.'.NumSets' => 2,
1.137 matthew 7670: $id.'.two_axes' => 1,
7671: $id.'.y1_max_value' => $Max1,
7672: $id.'.y1_min_value' => $Min1,
7673: $id.'.y2_max_value' => $Max2,
7674: $id.'.y2_min_value' => $Min2,
1.136 matthew 7675: );
7676: #
1.137 matthew 7677: if (defined($colors) && ref($colors) eq 'ARRAY') {
7678: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7679: }
7680: #
7681: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
7682: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 7683: return '';
7684: }
7685: my $NumSets=1;
1.137 matthew 7686: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 7687: next if (! ref($array));
7688: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 7689: }
7690: #
7691: # Deal with other parameters
7692: while (my ($key,$value) = each(%Values)) {
7693: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 7694: }
7695: #
7696: &Apache::lonnet::appenv(%ValuesHash);
1.130 albertel 7697: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 7698: }
7699:
7700: ############################################################
7701: ############################################################
7702:
7703: =pod
7704:
1.157 matthew 7705: =back
7706:
1.139 matthew 7707: =head1 Statistics helper routines?
7708:
7709: Bad place for them but what the hell.
7710:
1.157 matthew 7711: =over 4
7712:
1.139 matthew 7713: =item &chartlink
7714:
7715: Returns a link to the chart for a specific student.
7716:
7717: Inputs:
7718:
7719: =over 4
7720:
7721: =item $linktext: The text of the link
7722:
7723: =item $sname: The students username
7724:
7725: =item $sdomain: The students domain
7726:
7727: =back
7728:
1.157 matthew 7729: =back
7730:
1.139 matthew 7731: =cut
7732:
7733: ############################################################
7734: ############################################################
7735: sub chartlink {
7736: my ($linktext, $sname, $sdomain) = @_;
7737: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 7738: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 7739: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 7740: '">'.$linktext.'</a>';
1.153 matthew 7741: }
7742:
7743: #######################################################
7744: #######################################################
7745:
7746: =pod
7747:
7748: =head1 Course Environment Routines
1.157 matthew 7749:
7750: =over 4
1.153 matthew 7751:
7752: =item &restore_course_settings
7753:
7754: =item &store_course_settings
7755:
7756: Restores/Store indicated form parameters from the course environment.
7757: Will not overwrite existing values of the form parameters.
7758:
7759: Inputs:
7760: a scalar describing the data (e.g. 'chart', 'problem_analysis')
7761:
7762: a hash ref describing the data to be stored. For example:
7763:
7764: %Save_Parameters = ('Status' => 'scalar',
7765: 'chartoutputmode' => 'scalar',
7766: 'chartoutputdata' => 'scalar',
7767: 'Section' => 'array',
1.373 raeburn 7768: 'Group' => 'array',
1.153 matthew 7769: 'StudentData' => 'array',
7770: 'Maps' => 'array');
7771:
7772: Returns: both routines return nothing
7773:
1.631 raeburn 7774: =back
7775:
1.153 matthew 7776: =cut
7777:
7778: #######################################################
7779: #######################################################
7780: sub store_course_settings {
1.496 albertel 7781: return &store_settings($env{'request.course.id'},@_);
7782: }
7783:
7784: sub store_settings {
1.153 matthew 7785: # save to the environment
7786: # appenv the same items, just to be safe
1.300 albertel 7787: my $udom = $env{'user.domain'};
7788: my $uname = $env{'user.name'};
1.496 albertel 7789: my ($context,$prefix,$Settings) = @_;
1.153 matthew 7790: my %SaveHash;
7791: my %AppHash;
7792: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 7793: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 7794: my $envname = 'environment.'.$basename;
1.258 albertel 7795: if (exists($env{'form.'.$setting})) {
1.153 matthew 7796: # Save this value away
7797: if ($type eq 'scalar' &&
1.258 albertel 7798: (! exists($env{$envname}) ||
7799: $env{$envname} ne $env{'form.'.$setting})) {
7800: $SaveHash{$basename} = $env{'form.'.$setting};
7801: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 7802: } elsif ($type eq 'array') {
7803: my $stored_form;
1.258 albertel 7804: if (ref($env{'form.'.$setting})) {
1.153 matthew 7805: $stored_form = join(',',
7806: map {
1.369 www 7807: &escape($_);
1.258 albertel 7808: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 7809: } else {
7810: $stored_form =
1.369 www 7811: &escape($env{'form.'.$setting});
1.153 matthew 7812: }
7813: # Determine if the array contents are the same.
1.258 albertel 7814: if ($stored_form ne $env{$envname}) {
1.153 matthew 7815: $SaveHash{$basename} = $stored_form;
7816: $AppHash{$envname} = $stored_form;
7817: }
7818: }
7819: }
7820: }
7821: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 7822: $udom,$uname);
1.153 matthew 7823: if ($put_result !~ /^(ok|delayed)/) {
7824: &Apache::lonnet::logthis('unable to save form parameters, '.
7825: 'got error:'.$put_result);
7826: }
7827: # Make sure these settings stick around in this session, too
7828: &Apache::lonnet::appenv(%AppHash);
7829: return;
7830: }
7831:
7832: sub restore_course_settings {
1.499 albertel 7833: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 7834: }
7835:
7836: sub restore_settings {
7837: my ($context,$prefix,$Settings) = @_;
1.153 matthew 7838: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 7839: next if (exists($env{'form.'.$setting}));
1.496 albertel 7840: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 7841: '.'.$setting;
1.258 albertel 7842: if (exists($env{$envname})) {
1.153 matthew 7843: if ($type eq 'scalar') {
1.258 albertel 7844: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 7845: } elsif ($type eq 'array') {
1.258 albertel 7846: $env{'form.'.$setting} = [
1.153 matthew 7847: map {
1.369 www 7848: &unescape($_);
1.258 albertel 7849: } split(',',$env{$envname})
1.153 matthew 7850: ];
7851: }
7852: }
7853: }
1.127 matthew 7854: }
7855:
1.618 raeburn 7856: #######################################################
7857: #######################################################
7858:
7859: =pod
7860:
7861: =head1 Domain E-mail Routines
7862:
7863: =over 4
7864:
7865: =item &build_recipient_list
7866:
7867: Build recipient lists for three types of e-mail:
7868: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 7869: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 7870:
7871: Inputs:
1.619 raeburn 7872: defmail (scalar - email address of default recipient),
1.618 raeburn 7873: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 7874: defdom (domain for which to retrieve configuration settings),
7875: origmail (scalar - email address of recipient from loncapa.conf,
7876: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 7877:
7878: Returns: comma separated list of addresses to which to send e-mail.
7879:
7880: =cut
7881:
7882: ############################################################
7883: ############################################################
7884: sub build_recipient_list {
1.619 raeburn 7885: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 7886: my @recipients;
7887: my $otheremails;
7888: my %domconfig =
7889: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
7890: if (ref($domconfig{'contacts'}) eq 'HASH') {
7891: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
7892: my @contacts = ('adminemail','supportemail');
7893: foreach my $item (@contacts) {
7894: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 7895: my $addr = $domconfig{'contacts'}{$item};
7896: if (!grep(/^\Q$addr\E$/,@recipients)) {
7897: push(@recipients,$addr);
7898: }
1.618 raeburn 7899: }
7900: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
7901: }
7902: }
1.619 raeburn 7903: } elsif ($origmail ne '') {
7904: push(@recipients,$origmail);
1.618 raeburn 7905: }
7906: if ($defmail ne '') {
7907: push(@recipients,$defmail);
7908: }
7909: if ($otheremails) {
1.619 raeburn 7910: my @others;
7911: if ($otheremails =~ /,/) {
7912: @others = split(/,/,$otheremails);
1.618 raeburn 7913: } else {
1.619 raeburn 7914: push(@others,$otheremails);
7915: }
7916: foreach my $addr (@others) {
7917: if (!grep(/^\Q$addr\E$/,@recipients)) {
7918: push(@recipients,$addr);
7919: }
1.618 raeburn 7920: }
7921: }
1.619 raeburn 7922: my $recipientlist = join(',',@recipients);
1.618 raeburn 7923: return $recipientlist;
7924: }
7925:
1.127 matthew 7926: ############################################################
7927: ############################################################
1.154 albertel 7928:
1.443 albertel 7929: sub commit_customrole {
7930: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
1.630 raeburn 7931: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 7932: ($start?', '.&mt('starting').' '.localtime($start):'').
7933: ($end?', ending '.localtime($end):'').': <b>'.
7934: &Apache::lonnet::assigncustomrole(
7935: $udom,$uname,$url,$three,$four,$five,$end,$start).
7936: '</b><br />';
7937: return $output;
7938: }
7939:
7940: sub commit_standardrole {
1.541 raeburn 7941: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
7942: my ($output,$logmsg,$linefeed);
7943: if ($context eq 'auto') {
7944: $linefeed = "\n";
7945: } else {
7946: $linefeed = "<br />\n";
7947: }
1.443 albertel 7948: if ($three eq 'st') {
1.541 raeburn 7949: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
7950: $one,$two,$sec,$context);
7951: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 7952: ($result eq 'unknown_course') || ($result eq 'refused')) {
7953: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 7954: } else {
1.541 raeburn 7955: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 7956: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 7957: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
7958: if ($context eq 'auto') {
7959: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
7960: } else {
7961: $output .= '<b>'.$result.'</b>'.$linefeed.
7962: &mt('Add to classlist').': <b>ok</b>';
7963: }
7964: $output .= $linefeed;
1.443 albertel 7965: }
7966: } else {
7967: $output = &mt('Assigning').' '.$three.' in '.$url.
7968: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 7969: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
7970: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start);
7971: if ($context eq 'auto') {
7972: $output .= $result.$linefeed;
7973: } else {
7974: $output .= '<b>'.$result.'</b>'.$linefeed;
7975: }
1.443 albertel 7976: }
7977: return $output;
7978: }
7979:
7980: sub commit_studentrole {
1.541 raeburn 7981: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 7982: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 7983: if ($context eq 'auto') {
7984: $linefeed = "\n";
7985: } else {
7986: $linefeed = '<br />'."\n";
7987: }
1.443 albertel 7988: if (defined($one) && defined($two)) {
7989: my $cid=$one.'_'.$two;
7990: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
7991: my $secchange = 0;
7992: my $expire_role_result;
7993: my $modify_section_result;
1.628 raeburn 7994: if ($oldsec ne '-1') {
7995: if ($oldsec ne $sec) {
1.443 albertel 7996: $secchange = 1;
1.628 raeburn 7997: my $now = time;
1.443 albertel 7998: my $uurl='/'.$cid;
7999: $uurl=~s/\_/\//g;
8000: if ($oldsec) {
8001: $uurl.='/'.$oldsec;
8002: }
1.626 raeburn 8003: $oldsecurl = $uurl;
1.628 raeburn 8004: $expire_role_result =
8005: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now);
8006: if ($env{'request.course.sec'} ne '') {
8007: if ($expire_role_result eq 'refused') {
8008: my @roles = ('st');
8009: my @statuses = ('previous');
8010: my @roledoms = ($one);
8011: my $withsec = 1;
8012: my %roleshash =
8013: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
8014: \@statuses,\@roles,\@roledoms,$withsec);
8015: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
8016: my ($oldstart,$oldend) =
8017: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
8018: if ($oldend > 0 && $oldend <= $now) {
8019: $expire_role_result = 'ok';
8020: }
8021: }
8022: }
8023: }
1.443 albertel 8024: $result = $expire_role_result;
8025: }
8026: }
8027: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
8028: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
8029: if ($modify_section_result =~ /^ok/) {
8030: if ($secchange == 1) {
1.628 raeburn 8031: if ($sec eq '') {
8032: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
8033: } else {
8034: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
8035: }
1.443 albertel 8036: } elsif ($oldsec eq '-1') {
1.628 raeburn 8037: if ($sec eq '') {
8038: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
8039: } else {
8040: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8041: }
1.443 albertel 8042: } else {
1.628 raeburn 8043: if ($sec eq '') {
8044: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
8045: } else {
8046: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8047: }
1.443 albertel 8048: }
8049: } else {
1.628 raeburn 8050: if ($secchange) {
8051: $$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;
8052: } else {
8053: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
8054: }
1.443 albertel 8055: }
8056: $result = $modify_section_result;
8057: } elsif ($secchange == 1) {
1.628 raeburn 8058: if ($oldsec eq '') {
8059: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
8060: } else {
8061: $$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;
8062: }
1.626 raeburn 8063: if ($expire_role_result eq 'refused') {
8064: my $newsecurl = '/'.$cid;
8065: $newsecurl =~ s/\_/\//g;
8066: if ($sec ne '') {
8067: $newsecurl.='/'.$sec;
8068: }
8069: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
8070: if ($sec eq '') {
8071: $$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;
8072: } else {
8073: $$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;
8074: }
8075: }
8076: }
1.443 albertel 8077: }
8078: } else {
1.626 raeburn 8079: $$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 8080: $result = "error: incomplete course id\n";
8081: }
8082: return $result;
8083: }
8084:
8085: ############################################################
8086: ############################################################
8087:
1.566 albertel 8088: sub check_clone {
1.578 raeburn 8089: my ($args,$linefeed) = @_;
1.566 albertel 8090: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
8091: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
8092: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
8093: my $clonemsg;
8094: my $can_clone = 0;
8095:
8096: if ($clonehome eq 'no_host') {
1.578 raeburn 8097: $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 8098: } else {
8099: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 8100: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 8101: $can_clone = 1;
8102: } else {
8103: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
8104: $args->{'clonedomain'},$args->{'clonecourse'});
8105: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 8106: if (grep(/^\*$/,@cloners)) {
8107: $can_clone = 1;
8108: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
8109: $can_clone = 1;
8110: } else {
8111: my %roleshash =
8112: &Apache::lonnet::get_my_roles($args->{'ccuname'},
8113: $args->{'ccdomain'},
8114: 'userroles',['active'],['cc'],
8115: [$args->{'clonedomain'}]);
8116: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
8117: $can_clone = 1;
8118: } else {
8119: $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'});
8120: }
1.566 albertel 8121: }
1.578 raeburn 8122: }
1.566 albertel 8123: }
8124: return ($can_clone, $clonemsg, $cloneid, $clonehome);
8125: }
8126:
1.444 albertel 8127: sub construct_course {
1.541 raeburn 8128: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 8129: my $outcome;
1.541 raeburn 8130: my $linefeed = '<br />'."\n";
8131: if ($context eq 'auto') {
8132: $linefeed = "\n";
8133: }
1.566 albertel 8134:
8135: #
8136: # Are we cloning?
8137: #
8138: my ($can_clone, $clonemsg, $cloneid, $clonehome);
8139: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 8140: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 8141: if ($context ne 'auto') {
1.578 raeburn 8142: if ($clonemsg ne '') {
8143: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
8144: }
1.566 albertel 8145: }
8146: $outcome .= $clonemsg.$linefeed;
8147:
8148: if (!$can_clone) {
8149: return (0,$outcome);
8150: }
8151: }
8152:
1.444 albertel 8153: #
8154: # Open course
8155: #
8156: my $crstype = lc($args->{'crstype'});
8157: my %cenv=();
8158: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
8159: $args->{'cdescr'},
8160: $args->{'curl'},
8161: $args->{'course_home'},
8162: $args->{'nonstandard'},
8163: $args->{'crscode'},
8164: $args->{'ccuname'}.':'.
8165: $args->{'ccdomain'},
8166: $args->{'crstype'});
8167:
8168: # Note: The testing routines depend on this being output; see
8169: # Utils::Course. This needs to at least be output as a comment
8170: # if anyone ever decides to not show this, and Utils::Course::new
8171: # will need to be suitably modified.
1.541 raeburn 8172: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 8173: #
8174: # Check if created correctly
8175: #
1.479 albertel 8176: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 8177: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 8178: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 8179:
1.444 albertel 8180: #
1.566 albertel 8181: # Do the cloning
8182: #
8183: if ($can_clone && $cloneid) {
8184: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
8185: if ($context ne 'auto') {
8186: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
8187: }
8188: $outcome .= $clonemsg.$linefeed;
8189: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 8190: # Copy all files
1.566 albertel 8191: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);
1.444 albertel 8192: # Restore URL
1.566 albertel 8193: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 8194: # Restore title
1.566 albertel 8195: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 8196: # Mark as cloned
1.566 albertel 8197: $cenv{'clonedfrom'}=$cloneid;
1.636.2.1 raeburn 8198: # Need to clone grading mode
8199: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
8200: $cenv{'grading'}=$newenv{'grading'};
8201: # Do not clone these environment entries
8202: &Apache::lonnet::del('environment',
8203: ['default_enrollment_start_date',
8204: 'default_enrollment_end_date',
8205: 'question.email',
8206: 'policy.email',
8207: 'comment.email',
8208: 'pch.users.denied',
8209: 'plc.users.denied'],
8210: $$crsudom,$$crsunum);
1.444 albertel 8211: }
1.566 albertel 8212:
1.444 albertel 8213: #
8214: # Set environment (will override cloned, if existing)
8215: #
8216: my @sections = ();
8217: my @xlists = ();
8218: if ($args->{'crstype'}) {
8219: $cenv{'type'}=$args->{'crstype'};
8220: }
8221: if ($args->{'crsid'}) {
8222: $cenv{'courseid'}=$args->{'crsid'};
8223: }
8224: if ($args->{'crscode'}) {
8225: $cenv{'internal.coursecode'}=$args->{'crscode'};
8226: }
8227: if ($args->{'crsquota'} ne '') {
8228: $cenv{'internal.coursequota'}=$args->{'crsquota'};
8229: } else {
8230: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
8231: }
8232: if ($args->{'ccuname'}) {
8233: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
8234: ':'.$args->{'ccdomain'};
8235: } else {
8236: $cenv{'internal.courseowner'} = $args->{'curruser'};
8237: }
8238:
8239: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
8240: if ($args->{'crssections'}) {
8241: $cenv{'internal.sectionnums'} = '';
8242: if ($args->{'crssections'} =~ m/,/) {
8243: @sections = split/,/,$args->{'crssections'};
8244: } else {
8245: $sections[0] = $args->{'crssections'};
8246: }
8247: if (@sections > 0) {
8248: foreach my $item (@sections) {
8249: my ($sec,$gp) = split/:/,$item;
8250: my $class = $args->{'crscode'}.$sec;
8251: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
8252: $cenv{'internal.sectionnums'} .= $item.',';
8253: unless ($addcheck eq 'ok') {
8254: push @badclasses, $class;
8255: }
8256: }
8257: $cenv{'internal.sectionnums'} =~ s/,$//;
8258: }
8259: }
8260: # do not hide course coordinator from staff listing,
8261: # even if privileged
8262: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8263: # add crosslistings
8264: if ($args->{'crsxlist'}) {
8265: $cenv{'internal.crosslistings'}='';
8266: if ($args->{'crsxlist'} =~ m/,/) {
8267: @xlists = split/,/,$args->{'crsxlist'};
8268: } else {
8269: $xlists[0] = $args->{'crsxlist'};
8270: }
8271: if (@xlists > 0) {
8272: foreach my $item (@xlists) {
8273: my ($xl,$gp) = split/:/,$item;
8274: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
8275: $cenv{'internal.crosslistings'} .= $item.',';
8276: unless ($addcheck eq 'ok') {
8277: push @badclasses, $xl;
8278: }
8279: }
8280: $cenv{'internal.crosslistings'} =~ s/,$//;
8281: }
8282: }
8283: if ($args->{'autoadds'}) {
8284: $cenv{'internal.autoadds'}=$args->{'autoadds'};
8285: }
8286: if ($args->{'autodrops'}) {
8287: $cenv{'internal.autodrops'}=$args->{'autodrops'};
8288: }
8289: # check for notification of enrollment changes
8290: my @notified = ();
8291: if ($args->{'notify_owner'}) {
8292: if ($args->{'ccuname'} ne '') {
8293: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
8294: }
8295: }
8296: if ($args->{'notify_dc'}) {
8297: if ($uname ne '') {
1.630 raeburn 8298: push(@notified,$uname.':'.$udom);
1.444 albertel 8299: }
8300: }
8301: if (@notified > 0) {
8302: my $notifylist;
8303: if (@notified > 1) {
8304: $notifylist = join(',',@notified);
8305: } else {
8306: $notifylist = $notified[0];
8307: }
8308: $cenv{'internal.notifylist'} = $notifylist;
8309: }
8310: if (@badclasses > 0) {
8311: my %lt=&Apache::lonlocal::texthash(
8312: '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',
8313: 'dnhr' => 'does not have rights to access enrollment in these classes',
8314: 'adby' => 'as determined by the policies of your institution on access to official classlists'
8315: );
1.541 raeburn 8316: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
8317: ' ('.$lt{'adby'}.')';
8318: if ($context eq 'auto') {
8319: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 8320: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 8321: foreach my $item (@badclasses) {
8322: if ($context eq 'auto') {
8323: $outcome .= " - $item\n";
8324: } else {
8325: $outcome .= "<li>$item</li>\n";
8326: }
8327: }
8328: if ($context eq 'auto') {
8329: $outcome .= $linefeed;
8330: } else {
1.566 albertel 8331: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 8332: }
8333: }
1.444 albertel 8334: }
8335: if ($args->{'no_end_date'}) {
8336: $args->{'endaccess'} = 0;
8337: }
8338: $cenv{'internal.autostart'}=$args->{'enrollstart'};
8339: $cenv{'internal.autoend'}=$args->{'enrollend'};
8340: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
8341: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
8342: if ($args->{'showphotos'}) {
8343: $cenv{'internal.showphotos'}=$args->{'showphotos'};
8344: }
8345: $cenv{'internal.authtype'} = $args->{'authtype'};
8346: $cenv{'internal.autharg'} = $args->{'autharg'};
8347: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
8348: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 8349: 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');
8350: if ($context eq 'auto') {
8351: $outcome .= $krb_msg;
8352: } else {
1.566 albertel 8353: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 8354: }
8355: $outcome .= $linefeed;
1.444 albertel 8356: }
8357: }
8358: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
8359: if ($args->{'setpolicy'}) {
8360: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8361: }
8362: if ($args->{'setcontent'}) {
8363: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8364: }
8365: }
8366: if ($args->{'reshome'}) {
8367: $cenv{'reshome'}=$args->{'reshome'}.'/';
8368: $cenv{'reshome'}=~s/\/+$/\//;
8369: }
8370: #
8371: # course has keyed access
8372: #
8373: if ($args->{'setkeys'}) {
8374: $cenv{'keyaccess'}='yes';
8375: }
8376: # if specified, key authority is not course, but user
8377: # only active if keyaccess is yes
8378: if ($args->{'keyauth'}) {
1.487 albertel 8379: my ($user,$domain) = split(':',$args->{'keyauth'});
8380: $user = &LONCAPA::clean_username($user);
8381: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 8382: if ($user ne '' && $domain ne '') {
1.487 albertel 8383: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 8384: }
8385: }
8386:
8387: if ($args->{'disresdis'}) {
8388: $cenv{'pch.roles.denied'}='st';
8389: }
8390: if ($args->{'disablechat'}) {
8391: $cenv{'plc.roles.denied'}='st';
8392: }
8393:
8394: # Record we've not yet viewed the Course Initialization Helper for this
8395: # course
8396: $cenv{'course.helper.not.run'} = 1;
8397: #
8398: # Use new Randomseed
8399: #
8400: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
8401: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
8402: #
8403: # The encryption code and receipt prefix for this course
8404: #
8405: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
8406: $cenv{'internal.encpref'}=100+int(9*rand(99));
8407: #
8408: # By default, use standard grading
8409: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
8410:
1.541 raeburn 8411: $outcome .= $linefeed.&mt('Setting environment').': '.
8412: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 8413: #
8414: # Open all assignments
8415: #
8416: if ($args->{'openall'}) {
8417: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
8418: my %storecontent = ($storeunder => time,
8419: $storeunder.'.type' => 'date_start');
8420:
8421: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 8422: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 8423: }
8424: #
8425: # Set first page
8426: #
8427: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
8428: || ($cloneid)) {
1.445 albertel 8429: use LONCAPA::map;
1.444 albertel 8430: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 8431:
8432: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
8433: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
8434:
1.444 albertel 8435: $outcome .= ($fatal?$errtext:'read ok').' - ';
8436: my $title; my $url;
8437: if ($args->{'firstres'} eq 'syl') {
8438: $title='Syllabus';
8439: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
8440: } else {
8441: $title='Navigate Contents';
8442: $url='/adm/navmaps';
8443: }
1.445 albertel 8444:
8445: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
8446: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
8447:
8448: if ($errtext) { $fatal=2; }
1.541 raeburn 8449: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 8450: }
1.566 albertel 8451:
8452: return (1,$outcome);
1.444 albertel 8453: }
8454:
8455: ############################################################
8456: ############################################################
8457:
1.378 raeburn 8458: sub course_type {
8459: my ($cid) = @_;
8460: if (!defined($cid)) {
8461: $cid = $env{'request.course.id'};
8462: }
1.404 albertel 8463: if (defined($env{'course.'.$cid.'.type'})) {
8464: return $env{'course.'.$cid.'.type'};
1.378 raeburn 8465: } else {
8466: return 'Course';
1.377 raeburn 8467: }
8468: }
1.156 albertel 8469:
1.406 raeburn 8470: sub group_term {
8471: my $crstype = &course_type();
8472: my %names = (
8473: 'Course' => 'group',
8474: 'Group' => 'team',
8475: );
8476: return $names{$crstype};
8477: }
8478:
1.156 albertel 8479: sub icon {
8480: my ($file)=@_;
1.505 albertel 8481: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 8482: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 8483: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 8484: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
8485: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
8486: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
8487: $curfext.".gif") {
8488: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
8489: $curfext.".gif";
8490: }
8491: }
1.249 albertel 8492: return &lonhttpdurl($iconname);
1.154 albertel 8493: }
1.84 albertel 8494:
1.575 albertel 8495: sub lonhttpd_port {
1.215 albertel 8496: my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
8497: if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
1.574 albertel 8498: # IE doesn't like a secure page getting images from a non-secure
8499: # port (when logging we haven't parsed the browser type so default
8500: # back to secure
8501: if ((!exists($env{'browser.type'}) || $env{'browser.type'} eq 'explorer')
8502: && $ENV{'SERVER_PORT'} == 443) {
1.575 albertel 8503: return 443;
8504: }
8505: return $lonhttpd_port;
8506:
8507: }
8508:
8509: sub lonhttpdurl {
8510: my ($url)=@_;
8511:
8512: my $lonhttpd_port = &lonhttpd_port();
8513: if ($lonhttpd_port == 443) {
1.574 albertel 8514: return 'https://'.$ENV{'SERVER_NAME'}.$url;
8515: }
1.215 albertel 8516: return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
8517: }
8518:
1.213 albertel 8519: sub connection_aborted {
8520: my ($r)=@_;
8521: $r->print(" ");$r->rflush();
8522: my $c = $r->connection;
8523: return $c->aborted();
8524: }
8525:
1.221 foxr 8526: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 8527: # strings as 'strings'.
8528: sub escape_single {
1.221 foxr 8529: my ($input) = @_;
1.223 albertel 8530: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 8531: $input =~ s/\'/\\\'/g; # Esacpe the 's....
8532: return $input;
8533: }
1.223 albertel 8534:
1.222 foxr 8535: # Same as escape_single, but escape's "'s This
8536: # can be used for "strings"
8537: sub escape_double {
8538: my ($input) = @_;
8539: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
8540: $input =~ s/\"/\\\"/g; # Esacpe the "s....
8541: return $input;
8542: }
1.223 albertel 8543:
1.222 foxr 8544: # Escapes the last element of a full URL.
8545: sub escape_url {
8546: my ($url) = @_;
1.238 raeburn 8547: my @urlslices = split(/\//, $url,-1);
1.369 www 8548: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 8549: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 8550: }
1.462 albertel 8551:
8552: # -------------------------------------------------------- Initliaze user login
8553: sub init_user_environment {
1.463 albertel 8554: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 8555: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
8556:
8557: my $public=($username eq 'public' && $domain eq 'public');
8558:
8559: # See if old ID present, if so, remove
8560:
8561: my ($filename,$cookie,$userroles);
8562: my $now=time;
8563:
8564: if ($public) {
8565: my $max_public=100;
8566: my $oldest;
8567: my $oldest_time=0;
8568: for(my $next=1;$next<=$max_public;$next++) {
8569: if (-e $lonids."/publicuser_$next.id") {
8570: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
8571: if ($mtime<$oldest_time || !$oldest_time) {
8572: $oldest_time=$mtime;
8573: $oldest=$next;
8574: }
8575: } else {
8576: $cookie="publicuser_$next";
8577: last;
8578: }
8579: }
8580: if (!$cookie) { $cookie="publicuser_$oldest"; }
8581: } else {
1.463 albertel 8582: # if this isn't a robot, kill any existing non-robot sessions
8583: if (!$args->{'robot'}) {
8584: opendir(DIR,$lonids);
8585: while ($filename=readdir(DIR)) {
8586: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
8587: unlink($lonids.'/'.$filename);
8588: }
1.462 albertel 8589: }
1.463 albertel 8590: closedir(DIR);
1.462 albertel 8591: }
8592: # Give them a new cookie
1.463 albertel 8593: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
8594: : $now);
8595: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 8596:
8597: # Initialize roles
8598:
8599: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
8600: }
8601: # ------------------------------------ Check browser type and MathML capability
8602:
8603: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
8604: $clientunicode,$clientos) = &decode_user_agent($r);
8605:
8606: # -------------------------------------- Any accessibility options to remember?
8607: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
8608: foreach my $option ('imagesuppress','appletsuppress',
8609: 'embedsuppress','fontenhance','blackwhite') {
8610: if ($form->{$option} eq 'true') {
8611: &Apache::lonnet::put('environment',{$option => 'on'},
8612: $domain,$username);
8613: } else {
8614: &Apache::lonnet::del('environment',[$option],
8615: $domain,$username);
8616: }
8617: }
8618: }
8619: # ------------------------------------------------------------- Get environment
8620:
8621: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
8622: my ($tmp) = keys(%userenv);
8623: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8624: # default remote control to off
8625: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
8626: } else {
8627: undef(%userenv);
8628: }
8629: if (($userenv{'interface'}) && (!$form->{'interface'})) {
8630: $form->{'interface'}=$userenv{'interface'};
8631: }
8632: $env{'environment.remote'}=$userenv{'remote'};
8633: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
8634:
8635: # --------------- Do not trust query string to be put directly into environment
8636: foreach my $option ('imagesuppress','appletsuppress',
8637: 'embedsuppress','fontenhance','blackwhite',
8638: 'interface','localpath','localres') {
8639: $form->{$option}=~s/[\n\r\=]//gs;
8640: }
8641: # --------------------------------------------------------- Write first profile
8642:
8643: {
8644: my %initial_env =
8645: ("user.name" => $username,
8646: "user.domain" => $domain,
8647: "user.home" => $authhost,
8648: "browser.type" => $clientbrowser,
8649: "browser.version" => $clientversion,
8650: "browser.mathml" => $clientmathml,
8651: "browser.unicode" => $clientunicode,
8652: "browser.os" => $clientos,
8653: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
8654: "request.course.fn" => '',
8655: "request.course.uri" => '',
8656: "request.course.sec" => '',
8657: "request.role" => 'cm',
8658: "request.role.adv" => $env{'user.adv'},
8659: "request.host" => $ENV{'REMOTE_ADDR'},);
8660:
8661: if ($form->{'localpath'}) {
8662: $initial_env{"browser.localpath"} = $form->{'localpath'};
8663: $initial_env{"browser.localres"} = $form->{'localres'};
8664: }
8665:
8666: if ($public) {
8667: $initial_env{"environment.remote"} = "off";
8668: }
8669: if ($form->{'interface'}) {
8670: $form->{'interface'}=~s/\W//gs;
8671: $initial_env{"browser.interface"} = $form->{'interface'};
8672: $env{'browser.interface'}=$form->{'interface'};
8673: foreach my $option ('imagesuppress','appletsuppress',
8674: 'embedsuppress','fontenhance','blackwhite') {
8675: if (($form->{$option} eq 'true') ||
8676: ($userenv{$option} eq 'on')) {
8677: $initial_env{"browser.$option"} = "on";
8678: }
8679: }
8680: }
8681:
8682: $env{'user.environment'} = "$lonids/$cookie.id";
8683:
8684: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
8685: &GDBM_WRCREAT(),0640)) {
8686: &_add_to_env(\%disk_env,\%initial_env);
8687: &_add_to_env(\%disk_env,\%userenv,'environment.');
8688: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 8689: if (ref($args->{'extra_env'})) {
8690: &_add_to_env(\%disk_env,$args->{'extra_env'});
8691: }
1.462 albertel 8692: untie(%disk_env);
8693: } else {
8694: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
8695: 'Could not create environment storage in lonauth: '.$!.'</font>');
8696: return 'error: '.$!;
8697: }
8698: }
8699: $env{'request.role'}='cm';
8700: $env{'request.role.adv'}=$env{'user.adv'};
8701: $env{'browser.type'}=$clientbrowser;
8702:
8703: return $cookie;
8704:
8705: }
8706:
8707: sub _add_to_env {
8708: my ($idf,$env_data,$prefix) = @_;
8709: while (my ($key,$value) = each(%$env_data)) {
8710: $idf->{$prefix.$key} = $value;
8711: $env{$prefix.$key} = $value;
8712: }
8713: }
8714:
8715:
1.41 ng 8716: =pod
8717:
8718: =back
8719:
1.112 bowersj2 8720: =cut
1.41 ng 8721:
1.112 bowersj2 8722: 1;
8723: __END__;
1.41 ng 8724:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>