Annotation of loncom/interface/loncommon.pm, revision 1.623
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.623 ! raeburn 4: # $Id: loncommon.pm,v 1.622 2007/12/08 00:03:32 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.20 www 81: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 82: my %language;
1.124 www 83: my %supported_language;
1.12 harris41 84: my %cprtag;
1.192 taceyjo1 85: my %scprtag;
1.351 www 86: my %fe; my %fd; my %fm;
1.41 ng 87: my %category_extensions;
1.12 harris41 88:
1.46 matthew 89: # ---------------------------------------------- Thesaurus variables
1.144 matthew 90: #
91: # %Keywords:
92: # A hash used by &keyword to determine if a word is considered a keyword.
93: # $thesaurus_db_file
94: # Scalar containing the full path to the thesaurus database.
1.46 matthew 95:
96: my %Keywords;
97: my $thesaurus_db_file;
98:
1.144 matthew 99: #
100: # Initialize values from language.tab, copyright.tab, filetypes.tab,
101: # thesaurus.tab, and filecategories.tab.
102: #
1.18 www 103: BEGIN {
1.46 matthew 104: # Variable initialization
105: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
106: #
1.22 www 107: unless ($readit) {
1.12 harris41 108: # ------------------------------------------------------------------- languages
109: {
1.158 raeburn 110: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
111: '/language.tab';
112: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 113: while (my $line = <$fh>) {
114: next if ($line=~/^\#/);
115: chomp($line);
116: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 117: $language{$key}=$val.' - '.$enc;
118: if ($sup) {
119: $supported_language{$key}=$sup;
120: }
121: }
122: close($fh);
123: }
1.12 harris41 124: }
125: # ------------------------------------------------------------------ copyrights
126: {
1.158 raeburn 127: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
128: '/copyright.tab';
129: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 130: while (my $line = <$fh>) {
131: next if ($line=~/^\#/);
132: chomp($line);
133: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 134: $cprtag{$key}=$val;
135: }
136: close($fh);
137: }
1.12 harris41 138: }
1.351 www 139: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 140: {
141: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
142: '/source_copyright.tab';
143: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 144: while (my $line = <$fh>) {
145: next if ($line =~ /^\#/);
146: chomp($line);
147: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 148: $scprtag{$key}=$val;
149: }
150: close($fh);
151: }
152: }
1.63 www 153:
1.517 raeburn 154: # -------------------------------------------------------------- default domain designs
1.63 www 155: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 156: my $designfile = $designdir.'/default.tab';
157: if ( open (my $fh,"<$designfile") ) {
158: while (my $line = <$fh>) {
159: next if ($line =~ /^\#/);
160: chomp($line);
161: my ($key,$val)=(split(/\=/,$line));
162: if ($val) { $defaultdesign{$key}=$val; }
163: }
164: close($fh);
1.63 www 165: }
166:
1.15 harris41 167: # ------------------------------------------------------------- file categories
168: {
1.158 raeburn 169: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
170: '/filecategories.tab';
171: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 172: while (my $line = <$fh>) {
173: next if ($line =~ /^\#/);
174: chomp($line);
175: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 176: push @{$category_extensions{lc($category)}},$extension;
177: }
178: close($fh);
179: }
180:
1.15 harris41 181: }
1.12 harris41 182: # ------------------------------------------------------------------ file types
183: {
1.158 raeburn 184: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
185: '/filetypes.tab';
186: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 187: while (my $line = <$fh>) {
188: next if ($line =~ /^\#/);
189: chomp($line);
190: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 191: if ($descr ne '') {
192: $fe{$ending}=lc($emb);
193: $fd{$ending}=$descr;
1.351 www 194: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 195: }
196: }
197: close($fh);
198: }
1.12 harris41 199: }
1.22 www 200: &Apache::lonnet::logthis(
1.46 matthew 201: "<font color=yellow>INFO: Read file types</font>");
1.22 www 202: $readit=1;
1.46 matthew 203: } # end of unless($readit)
1.32 matthew 204:
205: }
1.112 bowersj2 206:
1.42 matthew 207: ###############################################################
208: ## HTML and Javascript Helper Functions ##
209: ###############################################################
210:
211: =pod
212:
1.112 bowersj2 213: =head1 HTML and Javascript Functions
1.42 matthew 214:
1.112 bowersj2 215: =over 4
216:
217: =item * browser_and_searcher_javascript ()
218:
219: X<browsing, javascript>X<searching, javascript>Returns a string
220: containing javascript with two functions, C<openbrowser> and
221: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
222: tags.
1.42 matthew 223:
1.112 bowersj2 224: =item * openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 225:
226: inputs: formname, elementname, only, omit
227:
228: formname and elementname indicate the name of the html form and name of
229: the element that the results of the browsing selection are to be placed in.
230:
231: Specifying 'only' will restrict the browser to displaying only files
1.185 www 232: with the given extension. Can be a comma separated list.
1.42 matthew 233:
234: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 235: with the given extension. Can be a comma separated list.
1.42 matthew 236:
1.112 bowersj2 237: =item * opensearcher(formname, elementname) [javascript]
1.42 matthew 238:
239: Inputs: formname, elementname
240:
241: formname and elementname specify the name of the html form and the name
242: of the element the selection from the search results will be placed in.
1.542 raeburn 243:
1.42 matthew 244: =cut
245:
246: sub browser_and_searcher_javascript {
1.199 albertel 247: my ($mode)=@_;
248: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 249: my $resurl=&escape_single(&lastresurl());
1.42 matthew 250: return <<END;
1.219 albertel 251: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 252: var editbrowser = null;
1.135 albertel 253: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 254: var url = '$resurl/?';
1.42 matthew 255: if (editbrowser == null) {
256: url += 'launch=1&';
257: }
258: url += 'catalogmode=interactive&';
1.199 albertel 259: url += 'mode=$mode&';
1.611 albertel 260: url += 'inhibitmenu=yes&';
1.42 matthew 261: url += 'form=' + formname + '&';
262: if (only != null) {
263: url += 'only=' + only + '&';
1.217 albertel 264: } else {
265: url += 'only=&';
266: }
1.42 matthew 267: if (omit != null) {
268: url += 'omit=' + omit + '&';
1.217 albertel 269: } else {
270: url += 'omit=&';
271: }
1.135 albertel 272: if (titleelement != null) {
273: url += 'titleelement=' + titleelement + '&';
1.217 albertel 274: } else {
275: url += 'titleelement=&';
276: }
1.42 matthew 277: url += 'element=' + elementname + '';
278: var title = 'Browser';
1.435 albertel 279: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 280: options += ',width=700,height=600';
281: editbrowser = open(url,title,options,'1');
282: editbrowser.focus();
283: }
284: var editsearcher;
1.135 albertel 285: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 286: var url = '/adm/searchcat?';
287: if (editsearcher == null) {
288: url += 'launch=1&';
289: }
290: url += 'catalogmode=interactive&';
1.199 albertel 291: url += 'mode=$mode&';
1.42 matthew 292: url += 'form=' + formname + '&';
1.135 albertel 293: if (titleelement != null) {
294: url += 'titleelement=' + titleelement + '&';
1.217 albertel 295: } else {
296: url += 'titleelement=&';
297: }
1.42 matthew 298: url += 'element=' + elementname + '';
299: var title = 'Search';
1.435 albertel 300: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 301: options += ',width=700,height=600';
302: editsearcher = open(url,title,options,'1');
303: editsearcher.focus();
304: }
1.219 albertel 305: // END LON-CAPA Internal -->
1.42 matthew 306: END
1.170 www 307: }
308:
309: sub lastresurl {
1.258 albertel 310: if ($env{'environment.lastresurl'}) {
311: return $env{'environment.lastresurl'}
1.170 www 312: } else {
313: return '/res';
314: }
315: }
316:
317: sub storeresurl {
318: my $resurl=&Apache::lonnet::clutter(shift);
319: unless ($resurl=~/^\/res/) { return 0; }
320: $resurl=~s/\/$//;
321: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
322: &Apache::lonnet::appenv('environment.lastresurl' => $resurl);
323: return 1;
1.42 matthew 324: }
325:
1.74 www 326: sub studentbrowser_javascript {
1.111 www 327: unless (
1.258 albertel 328: (($env{'request.course.id'}) &&
1.302 albertel 329: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
330: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
331: '/'.$env{'request.course.sec'})
332: ))
1.258 albertel 333: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 334: ) { return ''; }
1.74 www 335: return (<<'ENDSTDBRW');
336: <script type="text/javascript" language="Javascript" >
337: var stdeditbrowser;
1.558 albertel 338: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74 www 339: var url = '/adm/pickstudent?';
340: var filter;
1.558 albertel 341: if (!ignorefilter) {
342: eval('filter=document.'+formname+'.'+uname+'.value;');
343: }
1.74 www 344: if (filter != null) {
345: if (filter != '') {
346: url += 'filter='+filter+'&';
347: }
348: }
349: url += 'form=' + formname + '&unameelement='+uname+
350: '&udomelement='+udom;
1.111 www 351: if (roleflag) { url+="&roles=1"; }
1.102 www 352: var title = 'Student_Browser';
1.74 www 353: var options = 'scrollbars=1,resizable=1,menubar=0';
354: options += ',width=700,height=600';
355: stdeditbrowser = open(url,title,options,'1');
356: stdeditbrowser.focus();
357: }
358: </script>
359: ENDSTDBRW
360: }
1.42 matthew 361:
1.74 www 362: sub selectstudent_link {
1.111 www 363: my ($form,$unameele,$udomele)=@_;
1.258 albertel 364: if ($env{'request.course.id'}) {
1.302 albertel 365: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
366: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
367: '/'.$env{'request.course.sec'})) {
1.111 www 368: return '';
369: }
370: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607 albertel 371: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 372: }
1.258 albertel 373: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 374: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 375: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 376: }
377: return '';
1.91 www 378: }
379:
380: sub coursebrowser_javascript {
1.468 raeburn 381: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 382: 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 383: my $output = '
1.538 albertel 384: <script type="text/javascript">
1.468 raeburn 385: var stdeditbrowser;'."\n";
386: $output .= <<"ENDSTDBRW";
1.377 raeburn 387: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 388: var url = '/adm/pickcourse?';
1.468 raeburn 389: var domainfilter = '';
390: var formid = getFormIdByName(formname);
391: if (formid > -1) {
392: var domid = getIndexByName(formid,udom);
393: if (domid > -1) {
394: if (document.forms[formid].elements[domid].type == 'select-one') {
395: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
396: }
397: if (document.forms[formid].elements[domid].type == 'hidden') {
398: domainfilter=document.forms[formid].elements[domid].value;
399: }
400: }
1.91 www 401: }
1.128 albertel 402: if (domainfilter != null) {
403: if (domainfilter != '') {
404: url += 'domainfilter='+domainfilter+'&';
405: }
406: }
1.91 www 407: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 408: '&cdomelement='+udom+
409: '&cnameelement='+desc;
1.468 raeburn 410: if (extra_element !=null && extra_element != '') {
1.594 raeburn 411: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 412: url += '&roleelement='+extra_element;
413: if (domainfilter == null || domainfilter == '') {
414: url += '&domainfilter='+extra_element;
415: }
1.234 raeburn 416: }
1.468 raeburn 417: else {
418: if (formname == 'portform') {
419: url += '&setroles='+extra_element;
420: }
421: }
1.230 raeburn 422: }
1.293 raeburn 423: if (multflag !=null && multflag != '') {
424: url += '&multiple='+multflag;
425: }
1.377 raeburn 426: if (crstype == 'Course/Group') {
427: if (formname == 'cu') {
428: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
429: if (crstype == "") {
430: alert("$crs_or_grp_alert");
431: return;
432: }
433: }
434: }
435: if (crstype !=null && crstype != '') {
436: url += '&type='+crstype;
437: }
1.102 www 438: var title = 'Course_Browser';
1.91 www 439: var options = 'scrollbars=1,resizable=1,menubar=0';
440: options += ',width=700,height=600';
441: stdeditbrowser = open(url,title,options,'1');
442: stdeditbrowser.focus();
443: }
1.468 raeburn 444:
445: function getFormIdByName(formname) {
446: for (var i=0;i<document.forms.length;i++) {
447: if (document.forms[i].name == formname) {
448: return i;
449: }
450: }
451: return -1;
452: }
453:
454: function getIndexByName(formid,item) {
455: for (var i=0;i<document.forms[formid].elements.length;i++) {
456: if (document.forms[formid].elements[i].name == item) {
457: return i;
458: }
459: }
460: return -1;
461: }
1.91 www 462: ENDSTDBRW
1.468 raeburn 463: if ($sec_element ne '') {
464: $output .= &setsec_javascript($sec_element,$formname);
465: }
466: $output .= '
467: </script>';
468: return $output;
469: }
470:
471: sub setsec_javascript {
472: my ($sec_element,$formname) = @_;
473: my $setsections = qq|
474: function setSect(sectionlist) {
475: var sectionsArray = sectionlist.split(",");
476: var numSections = sectionsArray.length;
477: document.$formname.$sec_element.length = 0;
478: if (numSections == 0) {
479: document.$formname.$sec_element.multiple=false;
480: document.$formname.$sec_element.size=1;
481: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
482: } else {
483: if (numSections == 1) {
484: document.$formname.$sec_element.multiple=false;
485: document.$formname.$sec_element.size=1;
486: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
487: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
488: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
489: } else {
490: for (var i=0; i<numSections; i++) {
491: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
492: }
493: document.$formname.$sec_element.multiple=true
494: if (numSections < 3) {
495: document.$formname.$sec_element.size=numSections;
496: } else {
497: document.$formname.$sec_element.size=3;
498: }
499: document.$formname.$sec_element.options[0].selected = false
500: }
501: }
1.91 www 502: }
1.468 raeburn 503: |;
504: return $setsections;
505: }
506:
1.91 www 507:
508: sub selectcourse_link {
1.377 raeburn 509: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 510: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
511: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 512: }
1.42 matthew 513:
1.273 raeburn 514: sub check_uncheck_jscript {
515: my $jscript = <<"ENDSCRT";
516: function checkAll(field) {
517: if (field.length > 0) {
518: for (i = 0; i < field.length; i++) {
519: field[i].checked = true ;
520: }
521: } else {
522: field.checked = true
523: }
524: }
525:
526: function uncheckAll(field) {
527: if (field.length > 0) {
528: for (i = 0; i < field.length; i++) {
529: field[i].checked = false ;
1.543 albertel 530: }
531: } else {
1.273 raeburn 532: field.checked = false ;
533: }
534: }
535: ENDSCRT
536: return $jscript;
537: }
538:
539:
1.42 matthew 540: =pod
1.36 matthew 541:
1.112 bowersj2 542: =item * linked_select_forms(...)
1.36 matthew 543:
544: linked_select_forms returns a string containing a <script></script> block
545: and html for two <select> menus. The select menus will be linked in that
546: changing the value of the first menu will result in new values being placed
547: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 548: order unless a defined order is provided.
1.36 matthew 549:
550: linked_select_forms takes the following ordered inputs:
551:
552: =over 4
553:
1.112 bowersj2 554: =item * $formname, the name of the <form> tag
1.36 matthew 555:
1.112 bowersj2 556: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 557:
1.112 bowersj2 558: =item * $firstdefault, the default value for the first menu
1.36 matthew 559:
1.112 bowersj2 560: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 561:
1.112 bowersj2 562: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 563:
1.112 bowersj2 564: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 565:
1.609 raeburn 566: =item * $menuorder, the order of values in the first menu
567:
1.41 ng 568: =back
569:
1.36 matthew 570: Below is an example of such a hash. Only the 'text', 'default', and
571: 'select2' keys must appear as stated. keys(%menu) are the possible
572: values for the first select menu. The text that coincides with the
1.41 ng 573: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 574: and text for the second menu are given in the hash pointed to by
575: $menu{$choice1}->{'select2'}.
576:
1.112 bowersj2 577: my %menu = ( A1 => { text =>"Choice A1" ,
578: default => "B3",
579: select2 => {
580: B1 => "Choice B1",
581: B2 => "Choice B2",
582: B3 => "Choice B3",
583: B4 => "Choice B4"
1.609 raeburn 584: },
585: order => ['B4','B3','B1','B2'],
1.112 bowersj2 586: },
587: A2 => { text =>"Choice A2" ,
588: default => "C2",
589: select2 => {
590: C1 => "Choice C1",
591: C2 => "Choice C2",
592: C3 => "Choice C3"
1.609 raeburn 593: },
594: order => ['C2','C1','C3'],
1.112 bowersj2 595: },
596: A3 => { text =>"Choice A3" ,
597: default => "D6",
598: select2 => {
599: D1 => "Choice D1",
600: D2 => "Choice D2",
601: D3 => "Choice D3",
602: D4 => "Choice D4",
603: D5 => "Choice D5",
604: D6 => "Choice D6",
605: D7 => "Choice D7"
1.609 raeburn 606: },
607: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 608: }
609: );
1.36 matthew 610:
611: =cut
612:
613: sub linked_select_forms {
614: my ($formname,
615: $middletext,
616: $firstdefault,
617: $firstselectname,
618: $secondselectname,
1.609 raeburn 619: $hashref,
620: $menuorder,
1.36 matthew 621: ) = @_;
622: my $second = "document.$formname.$secondselectname";
623: my $first = "document.$formname.$firstselectname";
624: # output the javascript to do the changing
625: my $result = '';
1.219 albertel 626: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 627: $result.="var select2data = new Object();\n";
628: $" = '","';
629: my $debug = '';
630: foreach my $s1 (sort(keys(%$hashref))) {
631: $result.="select2data.d_$s1 = new Object();\n";
632: $result.="select2data.d_$s1.def = new String('".
633: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 634: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 635: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 636: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
637: @s2values = @{$hashref->{$s1}->{'order'}};
638: }
1.36 matthew 639: $result.="\"@s2values\");\n";
640: $result.="select2data.d_$s1.texts = new Array(";
641: my @s2texts;
642: foreach my $value (@s2values) {
643: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
644: }
645: $result.="\"@s2texts\");\n";
646: }
647: $"=' ';
648: $result.= <<"END";
649:
650: function select1_changed() {
651: // Determine new choice
652: var newvalue = "d_" + $first.value;
653: // update select2
654: var values = select2data[newvalue].values;
655: var texts = select2data[newvalue].texts;
656: var select2def = select2data[newvalue].def;
657: var i;
658: // out with the old
659: for (i = 0; i < $second.options.length; i++) {
660: $second.options[i] = null;
661: }
662: // in with the nuclear
663: for (i=0;i<values.length; i++) {
664: $second.options[i] = new Option(values[i]);
1.143 matthew 665: $second.options[i].value = values[i];
1.36 matthew 666: $second.options[i].text = texts[i];
667: if (values[i] == select2def) {
668: $second.options[i].selected = true;
669: }
670: }
671: }
672: </script>
673: END
674: # output the initial values for the selection lists
675: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 676: my @order = sort(keys(%{$hashref}));
677: if (ref($menuorder) eq 'ARRAY') {
678: @order = @{$menuorder};
679: }
680: foreach my $value (@order) {
1.36 matthew 681: $result.=" <option value=\"$value\" ";
1.253 albertel 682: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 683: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 684: }
685: $result .= "</select>\n";
686: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
687: $result .= $middletext;
688: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
689: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 690:
691: my @secondorder = sort(keys(%select2));
692: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
693: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
694: }
695: foreach my $value (@secondorder) {
1.36 matthew 696: $result.=" <option value=\"$value\" ";
1.253 albertel 697: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 698: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 699: }
700: $result .= "</select>\n";
701: # return $debug;
702: return $result;
703: } # end of sub linked_select_forms {
704:
1.45 matthew 705: =pod
1.44 bowersj2 706:
1.112 bowersj2 707: =item * help_open_topic($topic, $text, $stayOnPage, $width, $height)
1.44 bowersj2 708:
1.112 bowersj2 709: Returns a string corresponding to an HTML link to the given help
710: $topic, where $topic corresponds to the name of a .tex file in
711: /home/httpd/html/adm/help/tex, with underscores replaced by
712: spaces.
713:
714: $text will optionally be linked to the same topic, allowing you to
715: link text in addition to the graphic. If you do not want to link
716: text, but wish to specify one of the later parameters, pass an
717: empty string.
718:
719: $stayOnPage is a value that will be interpreted as a boolean. If true,
720: the link will not open a new window. If false, the link will open
721: a new window using Javascript. (Default is false.)
722:
723: $width and $height are optional numerical parameters that will
724: override the width and height of the popped up window, which may
725: be useful for certain help topics with big pictures included.
1.44 bowersj2 726:
727: =cut
728:
729: sub help_open_topic {
1.48 bowersj2 730: my ($topic, $text, $stayOnPage, $width, $height) = @_;
731: $text = "" if (not defined $text);
1.44 bowersj2 732: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 733: if ($env{'browser.interface'} eq 'textual') {
1.79 www 734: $stayOnPage=1;
735: }
1.44 bowersj2 736: $width = 350 if (not defined $width);
737: $height = 400 if (not defined $height);
738: my $filename = $topic;
739: $filename =~ s/ /_/g;
740:
1.48 bowersj2 741: my $template = "";
742: my $link;
1.572 banghart 743:
1.159 www 744: $topic=~s/\W/\_/g;
1.44 bowersj2 745:
1.572 banghart 746: if (!$stayOnPage) {
1.72 bowersj2 747: $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 748: } else {
1.48 bowersj2 749: $link = "/adm/help/${filename}.hlp";
750: }
751:
752: # Add the text
1.572 banghart 753: if ($text ne "") {
1.77 www 754: $template .=
1.572 banghart 755: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
756: "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 757: }
758:
759: # Add the graphic
1.179 matthew 760: my $title = &mt('Online Help');
1.215 albertel 761: my $helpicon=&lonhttpdurl("/adm/help/gif/smallHelp.gif");
1.48 bowersj2 762: $template .= <<"ENDTEMPLATE";
1.436 albertel 763: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 764: ENDTEMPLATE
1.78 www 765: if ($text ne '') { $template.='</td></tr></table>' };
1.44 bowersj2 766: return $template;
767:
1.106 bowersj2 768: }
769:
770: # This is a quicky function for Latex cheatsheet editing, since it
771: # appears in at least four places
772: sub helpLatexCheatsheet {
773: my $other = shift;
774: my $addOther = '';
775: if ($other) {
776: $addOther = Apache::loncommon::help_open_topic($other, shift,
777: undef, undef, 600) .
778: '</td><td>';
779: }
780: return '<table><tr><td>'.
781: $addOther .
782: &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
783: undef,undef,600)
784: .'</td><td>'.
785: &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
786: undef,undef,600)
787: .'</td></tr></table>';
1.172 www 788: }
789:
1.430 albertel 790: sub general_help {
791: my $helptopic='Student_Intro';
792: if ($env{'request.role'}=~/^(ca|au)/) {
793: $helptopic='Authoring_Intro';
794: } elsif ($env{'request.role'}=~/^cc/) {
795: $helptopic='Course_Coordination_Intro';
796: }
797: return $helptopic;
798: }
799:
800: sub update_help_link {
801: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
802: my $origurl = $ENV{'REQUEST_URI'};
803: $origurl=~s|^/~|/priv/|;
804: my $timestamp = time;
805: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
806: $$datum = &escape($$datum);
807: }
808:
809: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
810: my $output .= <<"ENDOUTPUT";
811: <script type="text/javascript">
812: banner_link = '$banner_link';
813: </script>
814: ENDOUTPUT
815: return $output;
816: }
817:
818: # now just updates the help link and generates a blue icon
1.193 raeburn 819: sub help_open_menu {
1.430 albertel 820: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 821: = @_;
1.430 albertel 822: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 823: # only use pop-up help (stayOnPage == 0)
1.552 banghart 824: # if environment.remote is on (using remote control UI)
1.572 banghart 825: if ($env{'browser.interface'} eq 'textual' ||
826: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 827: $stayOnPage=1;
1.430 albertel 828: }
829: my $output;
830: if ($component_help) {
831: if (!$text) {
832: $output=&help_open_topic($component_help,undef,$stayOnPage,
833: $width,$height);
834: } else {
835: my $help_text;
836: $help_text=&unescape($topic);
837: $output='<table><tr><td>'.
838: &help_open_topic($component_help,$help_text,$stayOnPage,
839: $width,$height).'</td></tr></table>';
840: }
841: }
842: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
843: return $output.$banner_link;
844: }
845:
846: sub top_nav_help {
847: my ($text) = @_;
1.436 albertel 848: $text = &mt($text);
1.572 banghart 849: my $stay_on_page =
1.436 albertel 850: ($env{'browser.interface'} eq 'textual' ||
851: $env{'environment.remote'} eq 'off' );
1.572 banghart 852: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 853: : "javascript:helpMenu('open')";
1.572 banghart 854: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 855:
1.201 raeburn 856: my $title = &mt('Get help');
1.436 albertel 857:
858: return <<"END";
859: $banner_link
860: <a href="$link" title="$title">$text</a>
861: END
862: }
863:
864: sub help_menu_js {
865: my ($text) = @_;
866:
867: my $stayOnPage =
868: ($env{'browser.interface'} eq 'textual' ||
869: $env{'environment.remote'} eq 'off' );
870:
871: my $width = 620;
872: my $height = 600;
1.430 albertel 873: my $helptopic=&general_help();
874: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 875: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 876: my $start_page =
877: &Apache::loncommon::start_page('Help Menu', undef,
878: {'frameset' => 1,
879: 'js_ready' => 1,
880: 'add_entries' => {
881: 'border' => '0',
1.579 raeburn 882: 'rows' => "110,*",},});
1.331 albertel 883: my $end_page =
884: &Apache::loncommon::end_page({'frameset' => 1,
885: 'js_ready' => 1,});
886:
1.436 albertel 887: my $template .= <<"ENDTEMPLATE";
888: <script type="text/javascript">
1.253 albertel 889: // <!-- BEGIN LON-CAPA Internal
890: // <![CDATA[
1.430 albertel 891: var banner_link = '';
1.243 raeburn 892: function helpMenu(target) {
893: var caller = this;
894: if (target == 'open') {
895: var newWindow = null;
896: try {
1.262 albertel 897: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 898: }
899: catch(error) {
900: writeHelp(caller);
901: return;
902: }
903: if (newWindow) {
904: caller = newWindow;
905: }
1.193 raeburn 906: }
1.243 raeburn 907: writeHelp(caller);
908: return;
909: }
910: function writeHelp(caller) {
1.430 albertel 911: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 912: caller.document.close()
913: caller.focus()
1.193 raeburn 914: }
1.253 albertel 915: // ]]>
1.219 albertel 916: // END LON-CAPA Internal -->
1.436 albertel 917: </script>
1.193 raeburn 918: ENDTEMPLATE
919: return $template;
920: }
921:
1.172 www 922: sub help_open_bug {
923: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 924: unless ($env{'user.adv'}) { return ''; }
1.172 www 925: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
926: $text = "" if (not defined $text);
927: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 928: if ($env{'browser.interface'} eq 'textual' ||
929: $env{'environment.remote'} eq 'off' ) {
1.172 www 930: $stayOnPage=1;
931: }
1.184 albertel 932: $width = 600 if (not defined $width);
933: $height = 600 if (not defined $height);
1.172 www 934:
935: $topic=~s/\W+/\+/g;
936: my $link='';
937: my $template='';
1.379 albertel 938: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
939: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 940: if (!$stayOnPage)
941: {
942: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
943: }
944: else
945: {
946: $link = $url;
947: }
948: # Add the text
949: if ($text ne "")
950: {
951: $template .=
952: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 953: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 954: }
955:
956: # Add the graphic
1.179 matthew 957: my $title = &mt('Report a Bug');
1.215 albertel 958: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 959: $template .= <<"ENDTEMPLATE";
1.436 albertel 960: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 961: ENDTEMPLATE
962: if ($text ne '') { $template.='</td></tr></table>' };
963: return $template;
964:
965: }
966:
967: sub help_open_faq {
968: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 969: unless ($env{'user.adv'}) { return ''; }
1.172 www 970: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
971: $text = "" if (not defined $text);
972: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 973: if ($env{'browser.interface'} eq 'textual' ||
974: $env{'environment.remote'} eq 'off' ) {
1.172 www 975: $stayOnPage=1;
976: }
977: $width = 350 if (not defined $width);
978: $height = 400 if (not defined $height);
979:
980: $topic=~s/\W+/\+/g;
981: my $link='';
982: my $template='';
983: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
984: if (!$stayOnPage)
985: {
986: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
987: }
988: else
989: {
990: $link = $url;
991: }
992:
993: # Add the text
994: if ($text ne "")
995: {
996: $template .=
1.173 www 997: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 998: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 999: }
1000:
1001: # Add the graphic
1.179 matthew 1002: my $title = &mt('View the FAQ');
1.215 albertel 1003: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1004: $template .= <<"ENDTEMPLATE";
1.436 albertel 1005: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1006: ENDTEMPLATE
1007: if ($text ne '') { $template.='</td></tr></table>' };
1008: return $template;
1009:
1.44 bowersj2 1010: }
1.37 matthew 1011:
1.180 matthew 1012: ###############################################################
1013: ###############################################################
1014:
1.45 matthew 1015: =pod
1016:
1.256 matthew 1017: =item * change_content_javascript():
1018:
1019: This and the next function allow you to create small sections of an
1020: otherwise static HTML page that you can update on the fly with
1021: Javascript, even in Netscape 4.
1022:
1023: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1024: must be written to the HTML page once. It will prove the Javascript
1025: function "change(name, content)". Calling the change function with the
1026: name of the section
1027: you want to update, matching the name passed to C<changable_area>, and
1028: the new content you want to put in there, will put the content into
1029: that area.
1030:
1031: B<Note>: Netscape 4 only reserves enough space for the changable area
1032: to contain room for the original contents. You need to "make space"
1033: for whatever changes you wish to make, and be B<sure> to check your
1034: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1035: it's adequate for updating a one-line status display, but little more.
1036: This script will set the space to 100% width, so you only need to
1037: worry about height in Netscape 4.
1038:
1039: Modern browsers are much less limiting, and if you can commit to the
1040: user not using Netscape 4, this feature may be used freely with
1041: pretty much any HTML.
1042:
1043: =cut
1044:
1045: sub change_content_javascript {
1046: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1047: if ($env{'browser.type'} eq 'netscape' &&
1048: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1049: return (<<NETSCAPE4);
1050: function change(name, content) {
1051: doc = document.layers[name+"___escape"].layers[0].document;
1052: doc.open();
1053: doc.write(content);
1054: doc.close();
1055: }
1056: NETSCAPE4
1057: } else {
1058: # Otherwise, we need to use semi-standards-compliant code
1059: # (technically, "innerHTML" isn't standard but the equivalent
1060: # is really scary, and every useful browser supports it
1061: return (<<DOMBASED);
1062: function change(name, content) {
1063: element = document.getElementById(name);
1064: element.innerHTML = content;
1065: }
1066: DOMBASED
1067: }
1068: }
1069:
1070: =pod
1071:
1072: =item * changable_area($name, $origContent):
1073:
1074: This provides a "changable area" that can be modified on the fly via
1075: the Javascript code provided in C<change_content_javascript>. $name is
1076: the name you will use to reference the area later; do not repeat the
1077: same name on a given HTML page more then once. $origContent is what
1078: the area will originally contain, which can be left blank.
1079:
1080: =cut
1081:
1082: sub changable_area {
1083: my ($name, $origContent) = @_;
1084:
1.258 albertel 1085: if ($env{'browser.type'} eq 'netscape' &&
1086: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1087: # If this is netscape 4, we need to use the Layer tag
1088: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1089: } else {
1090: return "<span id='$name'>$origContent</span>";
1091: }
1092: }
1093:
1094: =pod
1095:
1.590 raeburn 1096: =item * viewport_geometry_js {
1097:
1098: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1099:
1100: =cut
1101:
1102:
1103: sub viewport_geometry_js {
1104: return <<"GEOMETRY";
1105: var Geometry = {};
1106: function init_geometry() {
1107: if (Geometry.init) { return };
1108: Geometry.init=1;
1109: if (window.innerHeight) {
1110: Geometry.getViewportHeight = function() { return window.innerHeight; };
1111: Geometry.getViewportWidth = function() { return window.innerWidth; };
1112: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1113: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1114: }
1115: else if (document.documentElement && document.documentElement.clientHeight) {
1116: Geometry.getViewportHeight =
1117: function() { return document.documentElement.clientHeight; };
1118: Geometry.getViewportWidth =
1119: function() { return document.documentElement.clientWidth; };
1120:
1121: Geometry.getHorizontalScroll =
1122: function() { return document.documentElement.scrollLeft; };
1123: Geometry.getVerticalScroll =
1124: function() { return document.documentElement.scrollTop; };
1125: }
1126: else if (document.body.clientHeight) {
1127: Geometry.getViewportHeight =
1128: function() { return document.body.clientHeight; };
1129: Geometry.getViewportWidth =
1130: function() { return document.body.clientWidth; };
1131: Geometry.getHorizontalScroll =
1132: function() { return document.body.scrollLeft; };
1133: Geometry.getVerticalScroll =
1134: function() { return document.body.scrollTop; };
1135: }
1136: }
1137:
1138: GEOMETRY
1139: }
1140:
1141: =pod
1142:
1143: =item * viewport_size_js {
1144:
1145: 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.
1146:
1147: =cut
1148:
1149: sub viewport_size_js {
1150: my $geometry = &viewport_geometry_js();
1151: return <<"DIMS";
1152:
1153: $geometry
1154:
1155: function getViewportDims(width,height) {
1156: init_geometry();
1157: width.value = Geometry.getViewportWidth();
1158: height.value = Geometry.getViewportHeight();
1159: return;
1160: }
1161:
1162: DIMS
1163: }
1164:
1165: =pod
1166:
1.565 albertel 1167: =item * resize_textarea_js
1168:
1169: emits the needed javascript to resize a textarea to be as big as possible
1170:
1171: creates a function resize_textrea that takes two IDs first should be
1172: the id of the element to resize, second should be the id of a div that
1173: surrounds everything that comes after the textarea, this routine needs
1174: to be attached to the <body> for the onload and onresize events.
1175:
1176:
1177: =cut
1178:
1179: sub resize_textarea_js {
1.590 raeburn 1180: my $geometry = &viewport_geometry_js();
1.565 albertel 1181: return <<"RESIZE";
1182: <script type="text/javascript">
1.590 raeburn 1183: $geometry
1.565 albertel 1184:
1.588 albertel 1185: function getX(element) {
1186: var x = 0;
1187: while (element) {
1188: x += element.offsetLeft;
1189: element = element.offsetParent;
1190: }
1191: return x;
1192: }
1193: function getY(element) {
1194: var y = 0;
1195: while (element) {
1196: y += element.offsetTop;
1197: element = element.offsetParent;
1198: }
1199: return y;
1200: }
1201:
1202:
1.565 albertel 1203: function resize_textarea(textarea_id,bottom_id) {
1204: init_geometry();
1205: var textarea = document.getElementById(textarea_id);
1206: //alert(textarea);
1207:
1.588 albertel 1208: var textarea_top = getY(textarea);
1.565 albertel 1209: var textarea_height = textarea.offsetHeight;
1210: var bottom = document.getElementById(bottom_id);
1.588 albertel 1211: var bottom_top = getY(bottom);
1.565 albertel 1212: var bottom_height = bottom.offsetHeight;
1213: var window_height = Geometry.getViewportHeight();
1.588 albertel 1214: var fudge = 23;
1.565 albertel 1215: var new_height = window_height-fudge-textarea_top-bottom_height;
1216: if (new_height < 300) {
1217: new_height = 300;
1218: }
1219: textarea.style.height=new_height+'px';
1220: }
1221: </script>
1222: RESIZE
1223:
1224: }
1225:
1226: =pod
1227:
1.256 matthew 1228: =back
1.542 raeburn 1229:
1.256 matthew 1230: =head1 Excel and CSV file utility routines
1231:
1232: =over 4
1233:
1234: =cut
1235:
1236: ###############################################################
1237: ###############################################################
1238:
1239: =pod
1240:
1.112 bowersj2 1241: =item * csv_translate($text)
1.37 matthew 1242:
1.185 www 1243: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1244: format.
1245:
1246: =cut
1247:
1.180 matthew 1248: ###############################################################
1249: ###############################################################
1.37 matthew 1250: sub csv_translate {
1251: my $text = shift;
1252: $text =~ s/\"/\"\"/g;
1.209 albertel 1253: $text =~ s/\n/ /g;
1.37 matthew 1254: return $text;
1255: }
1.180 matthew 1256:
1257: ###############################################################
1258: ###############################################################
1259:
1260: =pod
1261:
1262: =item * define_excel_formats
1263:
1264: Define some commonly used Excel cell formats.
1265:
1266: Currently supported formats:
1267:
1268: =over 4
1269:
1270: =item header
1271:
1272: =item bold
1273:
1274: =item h1
1275:
1276: =item h2
1277:
1278: =item h3
1279:
1.256 matthew 1280: =item h4
1281:
1282: =item i
1283:
1.180 matthew 1284: =item date
1285:
1286: =back
1287:
1288: Inputs: $workbook
1289:
1290: Returns: $format, a hash reference.
1291:
1292: =cut
1293:
1294: ###############################################################
1295: ###############################################################
1296: sub define_excel_formats {
1297: my ($workbook) = @_;
1298: my $format;
1299: $format->{'header'} = $workbook->add_format(bold => 1,
1300: bottom => 1,
1301: align => 'center');
1302: $format->{'bold'} = $workbook->add_format(bold=>1);
1303: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1304: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1305: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1306: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1307: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1308: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1309: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1310: return $format;
1311: }
1312:
1313: ###############################################################
1314: ###############################################################
1.113 bowersj2 1315:
1316: =pod
1317:
1.256 matthew 1318: =item * create_workbook
1.255 matthew 1319:
1320: Create an Excel worksheet. If it fails, output message on the
1321: request object and return undefs.
1322:
1323: Inputs: Apache request object
1324:
1325: Returns (undef) on failure,
1326: Excel worksheet object, scalar with filename, and formats
1327: from &Apache::loncommon::define_excel_formats on success
1328:
1329: =cut
1330:
1331: ###############################################################
1332: ###############################################################
1333: sub create_workbook {
1334: my ($r) = @_;
1335: #
1336: # Create the excel spreadsheet
1337: my $filename = '/prtspool/'.
1.258 albertel 1338: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1339: time.'_'.rand(1000000000).'.xls';
1340: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1341: if (! defined($workbook)) {
1342: $r->log_error("Error creating excel spreadsheet $filename: $!");
1343: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1344: "This error has been logged. ".
1345: "Please alert your LON-CAPA administrator").
1346: '</p>');
1347: return (undef);
1348: }
1349: #
1350: $workbook->set_tempdir('/home/httpd/perl/tmp');
1351: #
1352: my $format = &Apache::loncommon::define_excel_formats($workbook);
1353: return ($workbook,$filename,$format);
1354: }
1355:
1356: ###############################################################
1357: ###############################################################
1358:
1359: =pod
1360:
1.256 matthew 1361: =item * create_text_file
1.113 bowersj2 1362:
1.542 raeburn 1363: Create a file to write to and eventually make available to the user.
1.256 matthew 1364: If file creation fails, outputs an error message on the request object and
1365: return undefs.
1.113 bowersj2 1366:
1.256 matthew 1367: Inputs: Apache request object, and file suffix
1.113 bowersj2 1368:
1.256 matthew 1369: Returns (undef) on failure,
1370: Filehandle and filename on success.
1.113 bowersj2 1371:
1372: =cut
1373:
1.256 matthew 1374: ###############################################################
1375: ###############################################################
1376: sub create_text_file {
1377: my ($r,$suffix) = @_;
1378: if (! defined($suffix)) { $suffix = 'txt'; };
1379: my $fh;
1380: my $filename = '/prtspool/'.
1.258 albertel 1381: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1382: time.'_'.rand(1000000000).'.'.$suffix;
1383: $fh = Apache::File->new('>/home/httpd'.$filename);
1384: if (! defined($fh)) {
1385: $r->log_error("Couldn't open $filename for output $!");
1386: $r->print("Problems occured in creating the output file. ".
1387: "This error has been logged. ".
1388: "Please alert your LON-CAPA administrator.");
1.113 bowersj2 1389: }
1.256 matthew 1390: return ($fh,$filename)
1.113 bowersj2 1391: }
1392:
1393:
1.256 matthew 1394: =pod
1.113 bowersj2 1395:
1396: =back
1397:
1398: =cut
1.37 matthew 1399:
1400: ###############################################################
1.33 matthew 1401: ## Home server <option> list generating code ##
1402: ###############################################################
1.35 matthew 1403:
1.169 www 1404: # ------------------------------------------
1405:
1406: sub domain_select {
1407: my ($name,$value,$multiple)=@_;
1408: my %domains=map {
1.514 albertel 1409: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1410: } &Apache::lonnet::all_domains();
1.169 www 1411: if ($multiple) {
1412: $domains{''}=&mt('Any domain');
1.550 albertel 1413: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1414: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1415: } else {
1.550 albertel 1416: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1417: return &select_form($name,$value,%domains);
1418: }
1419: }
1420:
1.282 albertel 1421: #-------------------------------------------
1422:
1423: =pod
1424:
1.519 raeburn 1425: =head1 Routines for form select boxes
1426:
1427: =over 4
1428:
1.287 albertel 1429: =item * multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1430:
1431: Returns a string containing a <select> element int multiple mode
1432:
1433:
1434: Args:
1435: $name - name of the <select> element
1.506 raeburn 1436: $value - scalar or array ref of values that should already be selected
1.282 albertel 1437: $size - number of rows long the select element is
1.283 albertel 1438: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1439: (shown text should already have been &mt())
1.506 raeburn 1440: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1441:
1.282 albertel 1442: =cut
1443:
1444: #-------------------------------------------
1.169 www 1445: sub multiple_select_form {
1.284 albertel 1446: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1447: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1448: my $output='';
1.191 matthew 1449: if (! defined($size)) {
1450: $size = 4;
1.283 albertel 1451: if (scalar(keys(%$hash))<4) {
1452: $size = scalar(keys(%$hash));
1.191 matthew 1453: }
1454: }
1.169 www 1455: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501 banghart 1456: my @order;
1.506 raeburn 1457: if (ref($order) eq 'ARRAY') {
1458: @order = @{$order};
1459: } else {
1460: @order = sort(keys(%$hash));
1.501 banghart 1461: }
1462: if (exists($$hash{'select_form_order'})) {
1463: @order = @{$$hash{'select_form_order'}};
1464: }
1465:
1.284 albertel 1466: foreach my $key (@order) {
1.356 albertel 1467: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1468: $output.='selected="selected" ' if ($selected{$key});
1469: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1470: }
1471: $output.="</select>\n";
1472: return $output;
1473: }
1474:
1.88 www 1475: #-------------------------------------------
1476:
1477: =pod
1478:
1.112 bowersj2 1479: =item * select_form($defdom,$name,%hash)
1.88 www 1480:
1481: Returns a string containing a <select name='$name' size='1'> form to
1482: allow a user to select options from a hash option_name => displayed text.
1483: See lonrights.pm for an example invocation and use.
1484:
1485: =cut
1486:
1487: #-------------------------------------------
1488: sub select_form {
1489: my ($def,$name,%hash) = @_;
1490: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1491: my @keys;
1492: if (exists($hash{'select_form_order'})) {
1493: @keys=@{$hash{'select_form_order'}};
1494: } else {
1495: @keys=sort(keys(%hash));
1496: }
1.356 albertel 1497: foreach my $key (@keys) {
1498: $selectform.=
1499: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1500: ($key eq $def ? 'selected="selected" ' : '').
1501: ">".&mt($hash{$key})."</option>\n";
1.88 www 1502: }
1503: $selectform.="</select>";
1504: return $selectform;
1505: }
1506:
1.475 www 1507: # For display filters
1508:
1509: sub display_filter {
1510: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1511: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475 www 1512: return '<nobr><label>'.&mt('Records [_1]',
1513: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1514: (&mt('all'),10,20,50,100,1000,10000))).
1.478 www 1515: '</label></nobr> <nobr>'.
1.475 www 1516: &mt('Filter [_1]',
1.477 www 1517: &select_form($env{'form.displayfilter'},
1518: 'displayfilter',
1519: ('currentfolder' => 'Current folder/page',
1520: 'containing' => 'Containing phrase',
1521: 'none' => 'None'))).
1.478 www 1522: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475 www 1523: }
1524:
1.167 www 1525: sub gradeleveldescription {
1526: my $gradelevel=shift;
1527: my %gradelevels=(0 => 'Not specified',
1528: 1 => 'Grade 1',
1529: 2 => 'Grade 2',
1530: 3 => 'Grade 3',
1531: 4 => 'Grade 4',
1532: 5 => 'Grade 5',
1533: 6 => 'Grade 6',
1534: 7 => 'Grade 7',
1535: 8 => 'Grade 8',
1536: 9 => 'Grade 9',
1537: 10 => 'Grade 10',
1538: 11 => 'Grade 11',
1539: 12 => 'Grade 12',
1540: 13 => 'Grade 13',
1541: 14 => '100 Level',
1542: 15 => '200 Level',
1543: 16 => '300 Level',
1544: 17 => '400 Level',
1545: 18 => 'Graduate Level');
1546: return &mt($gradelevels{$gradelevel});
1547: }
1548:
1.163 www 1549: sub select_level_form {
1550: my ($deflevel,$name)=@_;
1551: unless ($deflevel) { $deflevel=0; }
1.167 www 1552: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1553: for (my $i=0; $i<=18; $i++) {
1554: $selectform.="<option value=\"$i\" ".
1.253 albertel 1555: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1556: ">".&gradeleveldescription($i)."</option>\n";
1557: }
1558: $selectform.="</select>";
1559: return $selectform;
1.163 www 1560: }
1.167 www 1561:
1.35 matthew 1562: #-------------------------------------------
1563:
1.45 matthew 1564: =pod
1565:
1.563 raeburn 1566: =item * select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35 matthew 1567:
1568: Returns a string containing a <select name='$name' size='1'> form to
1569: allow a user to select the domain to preform an operation in.
1570: See loncreateuser.pm for an example invocation and use.
1571:
1.90 www 1572: If the $includeempty flag is set, it also includes an empty choice ("no domain
1573: selected");
1574:
1.563 raeburn 1575: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1576:
1.35 matthew 1577: =cut
1578:
1579: #-------------------------------------------
1.34 matthew 1580: sub select_dom_form {
1.563 raeburn 1581: my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550 albertel 1582: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1583: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1584: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356 albertel 1585: foreach my $dom (@domains) {
1586: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1587: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1588: if ($showdomdesc) {
1589: if ($dom ne '') {
1590: my $domdesc = &Apache::lonnet::domain($dom,'description');
1591: if ($domdesc ne '') {
1592: $selectdomain .= ' ('.$domdesc.')';
1593: }
1594: }
1595: }
1596: $selectdomain .= "</option>\n";
1.34 matthew 1597: }
1598: $selectdomain.="</select>";
1599: return $selectdomain;
1600: }
1601:
1.35 matthew 1602: #-------------------------------------------
1603:
1.45 matthew 1604: =pod
1605:
1.586 raeburn 1606: =item * home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1607:
1.586 raeburn 1608: input: 4 arguments (two required, two optional) -
1609: $domain - domain of new user
1610: $name - name of form element
1611: $default - Value of 'default' causes a default item to be first
1612: option, and selected by default.
1613: $hide - Value of 'hide' causes hiding of the name of the server,
1614: if 1 server found, or default, if 0 found.
1.594 raeburn 1615: output: returns 2 items:
1.586 raeburn 1616: (a) form element which contains either:
1617: (i) <select name="$name">
1618: <option value="$hostid1">$hostid $servers{$hostid}</option>
1619: <option value="$hostid2">$hostid $servers{$hostid}</option>
1620: </select>
1621: form item if there are multiple library servers in $domain, or
1622: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1623: if there is only one library server in $domain.
1624:
1625: (b) number of library servers found.
1626:
1627: See loncreateuser.pm for example of use.
1.35 matthew 1628:
1629: =cut
1630:
1631: #-------------------------------------------
1.586 raeburn 1632: sub home_server_form_item {
1633: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1634: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1635: my $result;
1636: my $numlib = keys(%servers);
1637: if ($numlib > 1) {
1638: $result .= '<select name="'.$name.'" />'."\n";
1639: if ($default) {
1640: $result .= '<option value="default" selected>'.&mt('default').
1641: '</option>'."\n";
1642: }
1643: foreach my $hostid (sort(keys(%servers))) {
1644: $result.= '<option value="'.$hostid.'">'.
1645: $hostid.' '.$servers{$hostid}."</option>\n";
1646: }
1647: $result .= '</select>'."\n";
1648: } elsif ($numlib == 1) {
1649: my $hostid;
1650: foreach my $item (keys(%servers)) {
1651: $hostid = $item;
1652: }
1653: $result .= '<input type="hidden" name="'.$name.'" value="'.
1654: $hostid.'" />';
1655: if (!$hide) {
1656: $result .= $hostid.' '.$servers{$hostid};
1657: }
1658: $result .= "\n";
1659: } elsif ($default) {
1660: $result .= '<input type="hidden" name="'.$name.
1661: '" value="default" />';
1662: if (!$hide) {
1663: $result .= &mt('default');
1664: }
1665: $result .= "\n";
1.33 matthew 1666: }
1.586 raeburn 1667: return ($result,$numlib);
1.33 matthew 1668: }
1.112 bowersj2 1669:
1670: =pod
1671:
1.534 albertel 1672: =back
1673:
1.112 bowersj2 1674: =cut
1.87 matthew 1675:
1676: ###############################################################
1.112 bowersj2 1677: ## Decoding User Agent ##
1.87 matthew 1678: ###############################################################
1679:
1680: =pod
1681:
1.112 bowersj2 1682: =head1 Decoding the User Agent
1683:
1684: =over 4
1685:
1686: =item * &decode_user_agent()
1.87 matthew 1687:
1688: Inputs: $r
1689:
1690: Outputs:
1691:
1692: =over 4
1693:
1.112 bowersj2 1694: =item * $httpbrowser
1.87 matthew 1695:
1.112 bowersj2 1696: =item * $clientbrowser
1.87 matthew 1697:
1.112 bowersj2 1698: =item * $clientversion
1.87 matthew 1699:
1.112 bowersj2 1700: =item * $clientmathml
1.87 matthew 1701:
1.112 bowersj2 1702: =item * $clientunicode
1.87 matthew 1703:
1.112 bowersj2 1704: =item * $clientos
1.87 matthew 1705:
1706: =back
1707:
1.157 matthew 1708: =back
1709:
1.87 matthew 1710: =cut
1711:
1712: ###############################################################
1713: ###############################################################
1714: sub decode_user_agent {
1.247 albertel 1715: my ($r)=@_;
1.87 matthew 1716: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1717: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1718: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1719: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1720: my $clientbrowser='unknown';
1721: my $clientversion='0';
1722: my $clientmathml='';
1723: my $clientunicode='0';
1724: for (my $i=0;$i<=$#browsertype;$i++) {
1725: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1726: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1727: $clientbrowser=$bname;
1728: $httpbrowser=~/$vreg/i;
1729: $clientversion=$1;
1730: $clientmathml=($clientversion>=$minv);
1731: $clientunicode=($clientversion>=$univ);
1732: }
1733: }
1734: my $clientos='unknown';
1735: if (($httpbrowser=~/linux/i) ||
1736: ($httpbrowser=~/unix/i) ||
1737: ($httpbrowser=~/ux/i) ||
1738: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1739: if (($httpbrowser=~/vax/i) ||
1740: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1741: if ($httpbrowser=~/next/i) { $clientos='next'; }
1742: if (($httpbrowser=~/mac/i) ||
1743: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1744: if ($httpbrowser=~/win/i) { $clientos='win'; }
1745: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1746: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1747: $clientunicode,$clientos,);
1748: }
1749:
1.32 matthew 1750: ###############################################################
1751: ## Authentication changing form generation subroutines ##
1752: ###############################################################
1753: ##
1754: ## All of the authform_xxxxxxx subroutines take their inputs in a
1755: ## hash, and have reasonable default values.
1756: ##
1757: ## formname = the name given in the <form> tag.
1.35 matthew 1758: #-------------------------------------------
1759:
1.45 matthew 1760: =pod
1761:
1.112 bowersj2 1762: =head1 Authentication Routines
1763:
1764: =over 4
1765:
1766: =item * authform_xxxxxx
1.35 matthew 1767:
1768: The authform_xxxxxx subroutines provide javascript and html forms which
1769: handle some of the conveniences required for authentication forms.
1770: This is not an optimal method, but it works.
1771:
1772: See loncreateuser.pm for invocation and use examples.
1773:
1774: =over 4
1775:
1.112 bowersj2 1776: =item * authform_header
1.35 matthew 1777:
1.112 bowersj2 1778: =item * authform_authorwarning
1.35 matthew 1779:
1.112 bowersj2 1780: =item * authform_nochange
1.35 matthew 1781:
1.112 bowersj2 1782: =item * authform_kerberos
1.35 matthew 1783:
1.112 bowersj2 1784: =item * authform_internal
1.35 matthew 1785:
1.112 bowersj2 1786: =item * authform_filesystem
1.35 matthew 1787:
1788: =back
1789:
1.157 matthew 1790: =back
1791:
1.35 matthew 1792: =cut
1793:
1794: #-------------------------------------------
1.32 matthew 1795: sub authform_header{
1796: my %in = (
1797: formname => 'cu',
1.80 albertel 1798: kerb_def_dom => '',
1.32 matthew 1799: @_,
1800: );
1801: $in{'formname'} = 'document.' . $in{'formname'};
1802: my $result='';
1.80 albertel 1803:
1804: #---------------------------------------------- Code for upper case translation
1805: my $Javascript_toUpperCase;
1806: unless ($in{kerb_def_dom}) {
1807: $Javascript_toUpperCase =<<"END";
1808: switch (choice) {
1809: case 'krb': currentform.elements[choicearg].value =
1810: currentform.elements[choicearg].value.toUpperCase();
1811: break;
1812: default:
1813: }
1814: END
1815: } else {
1816: $Javascript_toUpperCase = "";
1817: }
1818:
1.165 raeburn 1819: my $radioval = "'nochange'";
1.591 raeburn 1820: if (defined($in{'curr_authtype'})) {
1821: if ($in{'curr_authtype'} ne '') {
1822: $radioval = "'".$in{'curr_authtype'}."arg'";
1823: }
1.174 matthew 1824: }
1.165 raeburn 1825: my $argfield = 'null';
1.591 raeburn 1826: if (defined($in{'mode'})) {
1.165 raeburn 1827: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 1828: if (defined($in{'curr_autharg'})) {
1829: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 1830: $argfield = "'$in{'curr_autharg'}'";
1831: }
1832: }
1833: }
1834: }
1835:
1.32 matthew 1836: $result.=<<"END";
1837: var current = new Object();
1.165 raeburn 1838: current.radiovalue = $radioval;
1839: current.argfield = $argfield;
1.32 matthew 1840:
1841: function changed_radio(choice,currentform) {
1842: var choicearg = choice + 'arg';
1843: // If a radio button in changed, we need to change the argfield
1844: if (current.radiovalue != choice) {
1845: current.radiovalue = choice;
1846: if (current.argfield != null) {
1847: currentform.elements[current.argfield].value = '';
1848: }
1849: if (choice == 'nochange') {
1850: current.argfield = null;
1851: } else {
1852: current.argfield = choicearg;
1853: switch(choice) {
1854: case 'krb':
1855: currentform.elements[current.argfield].value =
1856: "$in{'kerb_def_dom'}";
1857: break;
1858: default:
1859: break;
1860: }
1861: }
1862: }
1863: return;
1864: }
1.22 www 1865:
1.32 matthew 1866: function changed_text(choice,currentform) {
1867: var choicearg = choice + 'arg';
1868: if (currentform.elements[choicearg].value !='') {
1.80 albertel 1869: $Javascript_toUpperCase
1.32 matthew 1870: // clear old field
1871: if ((current.argfield != choicearg) && (current.argfield != null)) {
1872: currentform.elements[current.argfield].value = '';
1873: }
1874: current.argfield = choicearg;
1875: }
1876: set_auth_radio_buttons(choice,currentform);
1877: return;
1.20 www 1878: }
1.32 matthew 1879:
1880: function set_auth_radio_buttons(newvalue,currentform) {
1881: var i=0;
1882: while (i < currentform.login.length) {
1883: if (currentform.login[i].value == newvalue) { break; }
1884: i++;
1885: }
1886: if (i == currentform.login.length) {
1887: return;
1888: }
1889: current.radiovalue = newvalue;
1890: currentform.login[i].checked = true;
1891: return;
1892: }
1893: END
1894: return $result;
1895: }
1896:
1897: sub authform_authorwarning{
1898: my $result='';
1.144 matthew 1899: $result='<i>'.
1900: &mt('As a general rule, only authors or co-authors should be '.
1901: 'filesystem authenticated '.
1902: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 1903: return $result;
1904: }
1905:
1906: sub authform_nochange{
1907: my %in = (
1908: formname => 'document.cu',
1909: kerb_def_dom => 'MSU.EDU',
1910: @_,
1911: );
1.586 raeburn 1912: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1913: my $result;
1914: if (keys(%can_assign) == 0) {
1915: $result = &mt('Under you current role you are not permitted to change login settings for this user');
1916: } else {
1917: $result = '<label>'.&mt('[_1] Do not change login data',
1918: '<input type="radio" name="login" value="nochange" '.
1919: 'checked="checked" onclick="'.
1.281 albertel 1920: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
1921: '</label>';
1.586 raeburn 1922: }
1.32 matthew 1923: return $result;
1924: }
1925:
1.591 raeburn 1926: sub authform_kerberos {
1.32 matthew 1927: my %in = (
1928: formname => 'document.cu',
1929: kerb_def_dom => 'MSU.EDU',
1.80 albertel 1930: kerb_def_auth => 'krb4',
1.32 matthew 1931: @_,
1932: );
1.586 raeburn 1933: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1934: $autharg,$jscall);
1935: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 1936: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 1937: $check5 = ' checked="on"';
1.80 albertel 1938: } else {
1.586 raeburn 1939: $check4 = ' checked="on"';
1.80 albertel 1940: }
1.165 raeburn 1941: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 1942: if (defined($in{'curr_authtype'})) {
1943: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 1944: $krbcheck = ' checked="on"';
1.623 ! raeburn 1945: if (defined($in{'mode'})) {
! 1946: if ($in{'mode'} eq 'modifyuser') {
! 1947: $krbcheck = '';
! 1948: }
! 1949: }
1.591 raeburn 1950: if (defined($in{'curr_kerb_ver'})) {
1951: if ($in{'curr_krb_ver'} eq '5') {
1952: $check5 = ' checked="on"';
1953: $check4 = '';
1954: } else {
1955: $check4 = ' checked="on"';
1956: $check5 = '';
1957: }
1.586 raeburn 1958: }
1.591 raeburn 1959: if (defined($in{'curr_autharg'})) {
1.165 raeburn 1960: $krbarg = $in{'curr_autharg'};
1961: }
1.586 raeburn 1962: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 1963: if (defined($in{'curr_autharg'})) {
1.586 raeburn 1964: $result =
1965: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1966: $in{'curr_autharg'},$krbver);
1967: } else {
1968: $result =
1969: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
1970: }
1971: return $result;
1972: }
1973: }
1974: } else {
1975: if ($authnum == 1) {
1976: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 1977: }
1978: }
1.586 raeburn 1979: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1980: return;
1.587 raeburn 1981: } elsif ($authtype eq '') {
1.591 raeburn 1982: if (defined($in{'mode'})) {
1.587 raeburn 1983: if ($in{'mode'} eq 'modifycourse') {
1984: if ($authnum == 1) {
1985: $authtype = '<input type="hidden" name="login" value="krb">';
1986: }
1987: }
1988: }
1.586 raeburn 1989: }
1990: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
1991: if ($authtype eq '') {
1992: $authtype = '<input type="radio" name="login" value="krb" '.
1993: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1994: $krbcheck.' />';
1995: }
1996: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1997: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1998: $in{'curr_authtype'} eq 'krb5') ||
1999: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2000: $in{'curr_authtype'} eq 'krb4')) {
2001: $result .= &mt
1.144 matthew 2002: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2003: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2004: '<label>'.$authtype,
1.281 albertel 2005: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2006: 'value="'.$krbarg.'" '.
1.144 matthew 2007: 'onchange="'.$jscall.'" />',
1.281 albertel 2008: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2009: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2010: '</label>');
1.586 raeburn 2011: } elsif ($can_assign{'krb4'}) {
2012: $result .= &mt
2013: ('[_1] Kerberos authenticated with domain [_2] '.
2014: '[_3] Version 4 [_4]',
2015: '<label>'.$authtype,
2016: '</label><input type="text" size="10" name="krbarg" '.
2017: 'value="'.$krbarg.'" '.
2018: 'onchange="'.$jscall.'" />',
2019: '<label><input type="hidden" name="krbver" value="4" />',
2020: '</label>');
2021: } elsif ($can_assign{'krb5'}) {
2022: $result .= &mt
2023: ('[_1] Kerberos authenticated with domain [_2] '.
2024: '[_3] Version 5 [_4]',
2025: '<label>'.$authtype,
2026: '</label><input type="text" size="10" name="krbarg" '.
2027: 'value="'.$krbarg.'" '.
2028: 'onchange="'.$jscall.'" />',
2029: '<label><input type="hidden" name="krbver" value="5" />',
2030: '</label>');
2031: }
1.32 matthew 2032: return $result;
2033: }
2034:
2035: sub authform_internal{
1.586 raeburn 2036: my %in = (
1.32 matthew 2037: formname => 'document.cu',
2038: kerb_def_dom => 'MSU.EDU',
2039: @_,
2040: );
1.586 raeburn 2041: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2042: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2043: if (defined($in{'curr_authtype'})) {
2044: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2045: if ($can_assign{'int'}) {
2046: $intcheck = 'checked="on" ';
1.623 ! raeburn 2047: if (defined($in{'mode'})) {
! 2048: if ($in{'mode'} eq 'modifyuser') {
! 2049: $intcheck = '';
! 2050: }
! 2051: }
1.591 raeburn 2052: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2053: $intarg = $in{'curr_autharg'};
2054: }
2055: } else {
2056: $result = &mt('Currently internally authenticated.');
2057: return $result;
1.165 raeburn 2058: }
2059: }
1.586 raeburn 2060: } else {
2061: if ($authnum == 1) {
2062: $authtype = '<input type="hidden" name="login" value="int">';
2063: }
2064: }
2065: if (!$can_assign{'int'}) {
2066: return;
1.587 raeburn 2067: } elsif ($authtype eq '') {
1.591 raeburn 2068: if (defined($in{'mode'})) {
1.587 raeburn 2069: if ($in{'mode'} eq 'modifycourse') {
2070: if ($authnum == 1) {
2071: $authtype = '<input type="hidden" name="login" value="int">';
2072: }
2073: }
2074: }
1.165 raeburn 2075: }
1.586 raeburn 2076: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2077: if ($authtype eq '') {
2078: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2079: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2080: }
1.605 bisitz 2081: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2082: $intarg.'" onchange="'.$jscall.'" />';
2083: $result = &mt
1.144 matthew 2084: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2085: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2086: $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 2087: return $result;
2088: }
2089:
2090: sub authform_local{
2091: my %in = (
2092: formname => 'document.cu',
2093: kerb_def_dom => 'MSU.EDU',
2094: @_,
2095: );
1.586 raeburn 2096: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2097: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2098: if (defined($in{'curr_authtype'})) {
2099: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2100: if ($can_assign{'loc'}) {
2101: $loccheck = 'checked="on" ';
1.623 ! raeburn 2102: if (defined($in{'mode'})) {
! 2103: if ($in{'mode'} eq 'modifyuser') {
! 2104: $loccheck = '';
! 2105: }
! 2106: }
1.591 raeburn 2107: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2108: $locarg = $in{'curr_autharg'};
2109: }
2110: } else {
2111: $result = &mt('Currently using local (institutional) authentication.');
2112: return $result;
1.165 raeburn 2113: }
2114: }
1.586 raeburn 2115: } else {
2116: if ($authnum == 1) {
2117: $authtype = '<input type="hidden" name="login" value="loc">';
2118: }
2119: }
2120: if (!$can_assign{'loc'}) {
2121: return;
1.587 raeburn 2122: } elsif ($authtype eq '') {
1.591 raeburn 2123: if (defined($in{'mode'})) {
1.587 raeburn 2124: if ($in{'mode'} eq 'modifycourse') {
2125: if ($authnum == 1) {
2126: $authtype = '<input type="hidden" name="login" value="loc">';
2127: }
2128: }
2129: }
1.165 raeburn 2130: }
1.586 raeburn 2131: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2132: if ($authtype eq '') {
2133: $authtype = '<input type="radio" name="login" value="loc" '.
2134: $loccheck.' onchange="'.$jscall.'" onclick="'.
2135: $jscall.'" />';
2136: }
2137: $autharg = '<input type="text" size="10" name="locarg" value="'.
2138: $locarg.'" onchange="'.$jscall.'" />';
2139: $result = &mt('[_1] Local Authentication with argument [_2]',
2140: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2141: return $result;
2142: }
2143:
2144: sub authform_filesystem{
2145: my %in = (
2146: formname => 'document.cu',
2147: kerb_def_dom => 'MSU.EDU',
2148: @_,
2149: );
1.586 raeburn 2150: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2151: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2152: if (defined($in{'curr_authtype'})) {
2153: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2154: if ($can_assign{'fsys'}) {
2155: $fsyscheck = 'checked="on" ';
1.623 ! raeburn 2156: if (defined($in{'mode'})) {
! 2157: if ($in{'mode'} eq 'modifyuser') {
! 2158: $fsyscheck = '';
! 2159: }
! 2160: }
1.586 raeburn 2161: } else {
2162: $result = &mt('Currently Filesystem Authenticated.');
2163: return $result;
2164: }
2165: }
2166: } else {
2167: if ($authnum == 1) {
2168: $authtype = '<input type="hidden" name="login" value="fsys">';
2169: }
2170: }
2171: if (!$can_assign{'fsys'}) {
2172: return;
1.587 raeburn 2173: } elsif ($authtype eq '') {
1.591 raeburn 2174: if (defined($in{'mode'})) {
1.587 raeburn 2175: if ($in{'mode'} eq 'modifycourse') {
2176: if ($authnum == 1) {
2177: $authtype = '<input type="hidden" name="login" value="fsys">';
2178: }
2179: }
2180: }
1.586 raeburn 2181: }
2182: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2183: if ($authtype eq '') {
2184: $authtype = '<input type="radio" name="login" value="fsys" '.
2185: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2186: $jscall.'" />';
2187: }
2188: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2189: ' onchange="'.$jscall.'" />';
2190: $result = &mt
1.144 matthew 2191: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2192: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2193: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2194: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2195: 'onchange="'.$jscall.'" />');
1.32 matthew 2196: return $result;
2197: }
2198:
1.586 raeburn 2199: sub get_assignable_auth {
2200: my ($dom) = @_;
2201: if ($dom eq '') {
2202: $dom = $env{'request.role.domain'};
2203: }
2204: my %can_assign = (
2205: krb4 => 1,
2206: krb5 => 1,
2207: int => 1,
2208: loc => 1,
2209: );
2210: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2211: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2212: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2213: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2214: my $context;
2215: if ($env{'request.role'} =~ /^au/) {
2216: $context = 'author';
2217: } elsif ($env{'request.role'} =~ /^dc/) {
2218: $context = 'domain';
2219: } elsif ($env{'request.course.id'}) {
2220: $context = 'course';
2221: }
2222: if ($context) {
2223: if (ref($authhash->{$context}) eq 'HASH') {
2224: %can_assign = %{$authhash->{$context}};
2225: }
2226: }
2227: }
2228: }
2229: my $authnum = 0;
2230: foreach my $key (keys(%can_assign)) {
2231: if ($can_assign{$key}) {
2232: $authnum ++;
2233: }
2234: }
2235: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2236: $authnum --;
2237: }
2238: return ($authnum,%can_assign);
2239: }
2240:
1.80 albertel 2241: ###############################################################
2242: ## Get Authentication Defaults for Domain ##
2243: ###############################################################
2244:
2245: =pod
2246:
1.112 bowersj2 2247: =head1 Domains and Authentication
2248:
2249: Returns default authentication type and an associated argument as
2250: listed in file 'domain.tab'.
2251:
2252: =over 4
2253:
2254: =item * get_auth_defaults
1.80 albertel 2255:
2256: get_auth_defaults($target_domain) returns the default authentication
2257: type and an associated argument (initial password or a kerberos domain).
2258: These values are stored in lonTabs/domain.tab
2259:
2260: ($def_auth, $def_arg) = &get_auth_defaults($target_domain);
2261:
2262: If target_domain is not found in domain.tab, returns nothing ('').
2263:
2264: =cut
2265:
2266: #-------------------------------------------
2267: sub get_auth_defaults {
2268: my $domain=shift;
1.514 albertel 2269: return (&Apache::lonnet::domain($domain,'auth_def'),
2270: &Apache::lonnet::domain($domain,'auth_arg_def'));
2271:
1.80 albertel 2272: }
2273: ###############################################################
2274: ## End Get Authentication Defaults for Domain ##
2275: ###############################################################
2276:
2277: ###############################################################
2278: ## Get Kerberos Defaults for Domain ##
2279: ###############################################################
2280: ##
2281: ## Returns default kerberos version and an associated argument
2282: ## as listed in file domain.tab. If not listed, provides
2283: ## appropriate default domain and kerberos version.
2284: ##
2285: #-------------------------------------------
2286:
2287: =pod
2288:
1.112 bowersj2 2289: =item * get_kerberos_defaults
1.80 albertel 2290:
2291: get_kerberos_defaults($target_domain) returns the default kerberos
2292: version and domain. If not found in domain.tabs, it defaults to
2293: version 4 and the domain of the server.
2294:
2295: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2296:
2297: =cut
2298:
2299: #-------------------------------------------
2300: sub get_kerberos_defaults {
2301: my $domain=shift;
2302: my ($krbdef,$krbdefdom) =
2303: &Apache::loncommon::get_auth_defaults($domain);
2304: unless ($krbdef =~/^krb/ && $krbdefdom) {
2305: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2306: my $krbdefdom=$1;
2307: $krbdefdom=~tr/a-z/A-Z/;
2308: $krbdef = "krb4";
2309: }
2310: return ($krbdef,$krbdefdom);
2311: }
1.112 bowersj2 2312:
2313: =pod
2314:
2315: =back
2316:
2317: =cut
1.32 matthew 2318:
1.46 matthew 2319: ###############################################################
2320: ## Thesaurus Functions ##
2321: ###############################################################
1.20 www 2322:
1.46 matthew 2323: =pod
1.20 www 2324:
1.112 bowersj2 2325: =head1 Thesaurus Functions
2326:
2327: =over 4
2328:
2329: =item * initialize_keywords
1.46 matthew 2330:
2331: Initializes the package variable %Keywords if it is empty. Uses the
2332: package variable $thesaurus_db_file.
2333:
2334: =cut
2335:
2336: ###################################################
2337:
2338: sub initialize_keywords {
2339: return 1 if (scalar keys(%Keywords));
2340: # If we are here, %Keywords is empty, so fill it up
2341: # Make sure the file we need exists...
2342: if (! -e $thesaurus_db_file) {
2343: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2344: " failed because it does not exist");
2345: return 0;
2346: }
2347: # Set up the hash as a database
2348: my %thesaurus_db;
2349: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2350: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2351: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2352: $thesaurus_db_file);
2353: return 0;
2354: }
2355: # Get the average number of appearances of a word.
2356: my $avecount = $thesaurus_db{'average.count'};
2357: # Put keywords (those that appear > average) into %Keywords
2358: while (my ($word,$data)=each (%thesaurus_db)) {
2359: my ($count,undef) = split /:/,$data;
2360: $Keywords{$word}++ if ($count > $avecount);
2361: }
2362: untie %thesaurus_db;
2363: # Remove special values from %Keywords.
1.356 albertel 2364: foreach my $value ('total.count','average.count') {
2365: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2366: }
1.46 matthew 2367: return 1;
2368: }
2369:
2370: ###################################################
2371:
2372: =pod
2373:
1.112 bowersj2 2374: =item * keyword($word)
1.46 matthew 2375:
2376: Returns true if $word is a keyword. A keyword is a word that appears more
2377: than the average number of times in the thesaurus database. Calls
2378: &initialize_keywords
2379:
2380: =cut
2381:
2382: ###################################################
1.20 www 2383:
2384: sub keyword {
1.46 matthew 2385: return if (!&initialize_keywords());
2386: my $word=lc(shift());
2387: $word=~s/\W//g;
2388: return exists($Keywords{$word});
1.20 www 2389: }
1.46 matthew 2390:
2391: ###############################################################
2392:
2393: =pod
1.20 www 2394:
1.112 bowersj2 2395: =item * get_related_words
1.46 matthew 2396:
1.160 matthew 2397: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2398: an array of words. If the keyword is not in the thesaurus, an empty array
2399: will be returned. The order of the words returned is determined by the
2400: database which holds them.
2401:
2402: Uses global $thesaurus_db_file.
2403:
2404: =cut
2405:
2406: ###############################################################
2407: sub get_related_words {
2408: my $keyword = shift;
2409: my %thesaurus_db;
2410: if (! -e $thesaurus_db_file) {
2411: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2412: "failed because the file does not exist");
2413: return ();
2414: }
2415: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2416: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2417: return ();
2418: }
2419: my @Words=();
1.429 www 2420: my $count=0;
1.46 matthew 2421: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2422: # The first element is the number of times
2423: # the word appears. We do not need it now.
1.429 www 2424: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2425: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2426: my $threshold=$mostfrequentcount/10;
2427: foreach my $possibleword (@RelatedWords) {
2428: my ($word,$wordcount)=split(/\,/,$possibleword);
2429: if ($wordcount>$threshold) {
2430: push(@Words,$word);
2431: $count++;
2432: if ($count>10) { last; }
2433: }
1.20 www 2434: }
2435: }
1.46 matthew 2436: untie %thesaurus_db;
2437: return @Words;
1.14 harris41 2438: }
1.46 matthew 2439:
1.112 bowersj2 2440: =pod
2441:
2442: =back
2443:
2444: =cut
1.61 www 2445:
2446: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2447: =pod
2448:
1.112 bowersj2 2449: =head1 User Name Functions
2450:
2451: =over 4
2452:
1.226 albertel 2453: =item * plainname($uname,$udom,$first)
1.81 albertel 2454:
1.112 bowersj2 2455: Takes a users logon name and returns it as a string in
1.226 albertel 2456: "first middle last generation" form
2457: if $first is set to 'lastname' then it returns it as
2458: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2459:
2460: =cut
1.61 www 2461:
1.295 www 2462:
1.81 albertel 2463: ###############################################################
1.61 www 2464: sub plainname {
1.226 albertel 2465: my ($uname,$udom,$first)=@_;
1.537 albertel 2466: return if (!defined($uname) || !defined($udom));
1.295 www 2467: my %names=&getnames($uname,$udom);
1.226 albertel 2468: my $name=&Apache::lonnet::format_name($names{'firstname'},
2469: $names{'middlename'},
2470: $names{'lastname'},
2471: $names{'generation'},$first);
2472: $name=~s/^\s+//;
1.62 www 2473: $name=~s/\s+$//;
2474: $name=~s/\s+/ /g;
1.353 albertel 2475: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2476: return $name;
1.61 www 2477: }
1.66 www 2478:
2479: # -------------------------------------------------------------------- Nickname
1.81 albertel 2480: =pod
2481:
1.112 bowersj2 2482: =item * nickname($uname,$udom)
1.81 albertel 2483:
2484: Gets a users name and returns it as a string as
2485:
2486: ""nickname""
1.66 www 2487:
1.81 albertel 2488: if the user has a nickname or
2489:
2490: "first middle last generation"
2491:
2492: if the user does not
2493:
2494: =cut
1.66 www 2495:
2496: sub nickname {
2497: my ($uname,$udom)=@_;
1.537 albertel 2498: return if (!defined($uname) || !defined($udom));
1.295 www 2499: my %names=&getnames($uname,$udom);
1.68 albertel 2500: my $name=$names{'nickname'};
1.66 www 2501: if ($name) {
2502: $name='"'.$name.'"';
2503: } else {
2504: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2505: $names{'lastname'}.' '.$names{'generation'};
2506: $name=~s/\s+$//;
2507: $name=~s/\s+/ /g;
2508: }
2509: return $name;
2510: }
2511:
1.295 www 2512: sub getnames {
2513: my ($uname,$udom)=@_;
1.537 albertel 2514: return if (!defined($uname) || !defined($udom));
1.433 albertel 2515: if ($udom eq 'public' && $uname eq 'public') {
2516: return ('lastname' => &mt('Public'));
2517: }
1.295 www 2518: my $id=$uname.':'.$udom;
2519: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2520: if ($cached) {
2521: return %{$names};
2522: } else {
2523: my %loadnames=&Apache::lonnet::get('environment',
2524: ['firstname','middlename','lastname','generation','nickname'],
2525: $udom,$uname);
2526: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2527: return %loadnames;
2528: }
2529: }
1.61 www 2530:
1.542 raeburn 2531: # -------------------------------------------------------------------- getemails
2532: =pod
2533:
2534: =item * getemails($uname,$udom)
2535:
2536: Gets a user's email information and returns it as a hash with keys:
2537: notification, critnotification, permanentemail
2538:
2539: For notification and critnotification, values are comma-separated lists
2540: of e-mail address(es); for permanentemail, value is a single e-mail address.
2541:
2542: =cut
2543:
1.466 albertel 2544: sub getemails {
2545: my ($uname,$udom)=@_;
2546: if ($udom eq 'public' && $uname eq 'public') {
2547: return;
2548: }
1.467 www 2549: if (!$udom) { $udom=$env{'user.domain'}; }
2550: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2551: my $id=$uname.':'.$udom;
2552: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2553: if ($cached) {
2554: return %{$names};
2555: } else {
2556: my %loadnames=&Apache::lonnet::get('environment',
2557: ['notification','critnotification',
2558: 'permanentemail'],
2559: $udom,$uname);
2560: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2561: return %loadnames;
2562: }
2563: }
2564:
1.551 albertel 2565: sub flush_email_cache {
2566: my ($uname,$udom)=@_;
2567: if (!$udom) { $udom =$env{'user.domain'}; }
2568: if (!$uname) { $uname=$env{'user.name'}; }
2569: return if ($udom eq 'public' && $uname eq 'public');
2570: my $id=$uname.':'.$udom;
2571: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2572: }
2573:
1.61 www 2574: # ------------------------------------------------------------------ Screenname
1.81 albertel 2575:
2576: =pod
2577:
1.112 bowersj2 2578: =item * screenname($uname,$udom)
1.81 albertel 2579:
2580: Gets a users screenname and returns it as a string
2581:
2582: =cut
1.61 www 2583:
2584: sub screenname {
2585: my ($uname,$udom)=@_;
1.258 albertel 2586: if ($uname eq $env{'user.name'} &&
2587: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2588: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2589: return $names{'screenname'};
1.62 www 2590: }
2591:
1.212 albertel 2592:
1.62 www 2593: # ------------------------------------------------------------- Message Wrapper
2594:
2595: sub messagewrapper {
1.369 www 2596: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2597: return
1.441 albertel 2598: '<a href="/adm/email?compose=individual&'.
2599: 'recname='.$username.'&recdom='.$domain.
2600: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2601: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2602: }
2603: # --------------------------------------------------------------- Notes Wrapper
2604:
2605: sub noteswrapper {
2606: my ($link,$un,$do)=@_;
2607: return
2608: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2609: }
2610: # ------------------------------------------------------------- Aboutme Wrapper
2611:
2612: sub aboutmewrapper {
1.166 www 2613: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2614: if (!defined($username) && !defined($domain)) {
2615: return;
2616: }
1.205 www 2617: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2618: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2619: }
2620:
2621: # ------------------------------------------------------------ Syllabus Wrapper
2622:
2623:
2624: sub syllabuswrapper {
1.109 matthew 2625: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2626: if ($fontcolor) {
2627: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2628: }
1.208 matthew 2629: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2630: }
1.14 harris41 2631:
1.208 matthew 2632: sub track_student_link {
1.268 albertel 2633: my ($linktext,$sname,$sdom,$target,$start) = @_;
2634: my $link ="/adm/trackstudent?";
1.208 matthew 2635: my $title = 'View recent activity';
2636: if (defined($sname) && $sname !~ /^\s*$/ &&
2637: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2638: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2639: $title .= ' of this student';
1.268 albertel 2640: }
1.208 matthew 2641: if (defined($target) && $target !~ /^\s*$/) {
2642: $target = qq{target="$target"};
2643: } else {
2644: $target = '';
2645: }
1.268 albertel 2646: if ($start) { $link.='&start='.$start; }
1.554 albertel 2647: $title = &mt($title);
2648: $linktext = &mt($linktext);
1.448 albertel 2649: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2650: &help_open_topic('View_recent_activity');
1.208 matthew 2651: }
2652:
1.508 www 2653: # ===================================================== Display a student photo
2654:
2655:
1.509 albertel 2656: sub student_image_tag {
1.508 www 2657: my ($domain,$user)=@_;
2658: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2659: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2660: return '<img src="'.$imgsrc.'" align="right" />';
2661: } else {
2662: return '';
2663: }
2664: }
2665:
1.112 bowersj2 2666: =pod
2667:
2668: =back
2669:
2670: =head1 Access .tab File Data
2671:
2672: =over 4
2673:
2674: =item * languageids()
2675:
2676: returns list of all language ids
2677:
2678: =cut
2679:
1.14 harris41 2680: sub languageids {
1.16 harris41 2681: return sort(keys(%language));
1.14 harris41 2682: }
2683:
1.112 bowersj2 2684: =pod
2685:
2686: =item * languagedescription()
2687:
2688: returns description of a specified language id
2689:
2690: =cut
2691:
1.14 harris41 2692: sub languagedescription {
1.125 www 2693: my $code=shift;
2694: return ($supported_language{$code}?'* ':'').
2695: $language{$code}.
1.126 www 2696: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2697: }
2698:
2699: sub plainlanguagedescription {
2700: my $code=shift;
2701: return $language{$code};
2702: }
2703:
2704: sub supportedlanguagecode {
2705: my $code=shift;
2706: return $supported_language{$code};
1.97 www 2707: }
2708:
1.112 bowersj2 2709: =pod
2710:
2711: =item * copyrightids()
2712:
2713: returns list of all copyrights
2714:
2715: =cut
2716:
2717: sub copyrightids {
2718: return sort(keys(%cprtag));
2719: }
2720:
2721: =pod
2722:
2723: =item * copyrightdescription()
2724:
2725: returns description of a specified copyright id
2726:
2727: =cut
2728:
2729: sub copyrightdescription {
1.166 www 2730: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2731: }
1.197 matthew 2732:
2733: =pod
2734:
1.192 taceyjo1 2735: =item * source_copyrightids()
2736:
2737: returns list of all source copyrights
2738:
2739: =cut
2740:
2741: sub source_copyrightids {
2742: return sort(keys(%scprtag));
2743: }
2744:
2745: =pod
2746:
2747: =item * source_copyrightdescription()
2748:
2749: returns description of a specified source copyright id
2750:
2751: =cut
2752:
2753: sub source_copyrightdescription {
2754: return &mt($scprtag{shift(@_)});
2755: }
1.112 bowersj2 2756:
2757: =pod
2758:
2759: =item * filecategories()
2760:
2761: returns list of all file categories
2762:
2763: =cut
2764:
2765: sub filecategories {
2766: return sort(keys(%category_extensions));
2767: }
2768:
2769: =pod
2770:
2771: =item * filecategorytypes()
2772:
2773: returns list of file types belonging to a given file
2774: category
2775:
2776: =cut
2777:
2778: sub filecategorytypes {
1.356 albertel 2779: my ($cat) = @_;
2780: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2781: }
2782:
2783: =pod
2784:
2785: =item * fileembstyle()
2786:
2787: returns embedding style for a specified file type
2788:
2789: =cut
2790:
2791: sub fileembstyle {
2792: return $fe{lc(shift(@_))};
1.169 www 2793: }
2794:
1.351 www 2795: sub filemimetype {
2796: return $fm{lc(shift(@_))};
2797: }
2798:
1.169 www 2799:
2800: sub filecategoryselect {
2801: my ($name,$value)=@_;
1.189 matthew 2802: return &select_form($value,$name,
1.169 www 2803: '' => &mt('Any category'),
2804: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2805: }
2806:
2807: =pod
2808:
2809: =item * filedescription()
2810:
2811: returns description for a specified file type
2812:
2813: =cut
2814:
2815: sub filedescription {
1.188 matthew 2816: my $file_description = $fd{lc(shift())};
2817: $file_description =~ s:([\[\]]):~$1:g;
2818: return &mt($file_description);
1.112 bowersj2 2819: }
2820:
2821: =pod
2822:
2823: =item * filedescriptionex()
2824:
2825: returns description for a specified file type with
2826: extra formatting
2827:
2828: =cut
2829:
2830: sub filedescriptionex {
2831: my $ex=shift;
1.188 matthew 2832: my $file_description = $fd{lc($ex)};
2833: $file_description =~ s:([\[\]]):~$1:g;
2834: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 2835: }
2836:
2837: # End of .tab access
2838: =pod
2839:
2840: =back
2841:
2842: =cut
2843:
2844: # ------------------------------------------------------------------ File Types
2845: sub fileextensions {
2846: return sort(keys(%fe));
2847: }
2848:
1.97 www 2849: # ----------------------------------------------------------- Display Languages
2850: # returns a hash with all desired display languages
2851: #
2852:
2853: sub display_languages {
2854: my %languages=();
1.356 albertel 2855: foreach my $lang (&preferred_languages()) {
2856: $languages{$lang}=1;
1.97 www 2857: }
2858: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 2859: if ($env{'form.displaylanguage'}) {
1.356 albertel 2860: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
2861: $languages{$lang}=1;
1.97 www 2862: }
2863: }
2864: return %languages;
1.14 harris41 2865: }
2866:
1.117 www 2867: sub preferred_languages {
2868: my @languages=();
1.258 albertel 2869: if ($env{'course.'.$env{'request.course.id'}.'.languages'}) {
1.117 www 2870: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
1.258 albertel 2871: $env{'course.'.$env{'request.course.id'}.'.languages'}));
1.177 www 2872: }
1.258 albertel 2873: if ($env{'environment.languages'}) {
1.459 albertel 2874: @languages=(@languages,
2875: split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
1.118 www 2876: }
1.583 albertel 2877: my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'};
1.162 www 2878: if ($browser) {
1.583 albertel 2879: my @browser =
2880: map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
2881: push(@languages,@browser);
1.162 www 2882: }
1.514 albertel 2883: if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) {
1.118 www 2884: @languages=(@languages,
1.514 albertel 2885: &Apache::lonnet::domain($env{'user.domain'},
2886: 'lang_def'));
1.118 www 2887: }
1.514 albertel 2888: if (&Apache::lonnet::domain($env{'request.role.domain'},'lang_def')) {
1.118 www 2889: @languages=(@languages,
1.514 albertel 2890: &Apache::lonnet::domain($env{'request.role.domain'},
2891: 'lang_def'));
1.118 www 2892: }
1.514 albertel 2893: if (&Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
2894: 'lang_def')) {
1.118 www 2895: @languages=(@languages,
1.514 albertel 2896: &Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
2897: 'lang_def'));
1.118 www 2898: }
2899: # turn "en-ca" into "en-ca,en"
2900: my @genlanguages;
1.356 albertel 2901: foreach my $lang (@languages) {
2902: unless ($lang=~/\w/) { next; }
1.583 albertel 2903: push(@genlanguages,$lang);
1.356 albertel 2904: if ($lang=~/(\-|\_)/) {
2905: push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
1.118 www 2906: }
2907: }
1.583 albertel 2908: #uniqueify the languages list
2909: my %count;
2910: @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages;
1.118 www 2911: return @genlanguages;
1.117 www 2912: }
2913:
1.582 albertel 2914: sub languages {
2915: my ($possible_langs) = @_;
2916: my @preferred_langs = &preferred_languages();
2917: if (!ref($possible_langs)) {
2918: if( wantarray ) {
2919: return @preferred_langs;
2920: } else {
2921: return $preferred_langs[0];
2922: }
2923: }
2924: my %possibilities = map { $_ => 1 } (@$possible_langs);
2925: my @preferred_possibilities;
2926: foreach my $preferred_lang (@preferred_langs) {
2927: if (exists($possibilities{$preferred_lang})) {
2928: push(@preferred_possibilities, $preferred_lang);
2929: }
2930: }
2931: if( wantarray ) {
2932: return @preferred_possibilities;
2933: }
2934: return $preferred_possibilities[0];
2935: }
2936:
1.112 bowersj2 2937: ###############################################################
2938: ## Student Answer Attempts ##
2939: ###############################################################
2940:
2941: =pod
2942:
2943: =head1 Alternate Problem Views
2944:
2945: =over 4
2946:
2947: =item * get_previous_attempt($symb, $username, $domain, $course,
2948: $getattempt, $regexp, $gradesub)
2949:
2950: Return string with previous attempt on problem. Arguments:
2951:
2952: =over 4
2953:
2954: =item * $symb: Problem, including path
2955:
2956: =item * $username: username of the desired student
2957:
2958: =item * $domain: domain of the desired student
1.14 harris41 2959:
1.112 bowersj2 2960: =item * $course: Course ID
1.14 harris41 2961:
1.112 bowersj2 2962: =item * $getattempt: Leave blank for all attempts, otherwise put
2963: something
1.14 harris41 2964:
1.112 bowersj2 2965: =item * $regexp: if string matches this regexp, the string will be
2966: sent to $gradesub
1.14 harris41 2967:
1.112 bowersj2 2968: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 2969:
1.112 bowersj2 2970: =back
1.14 harris41 2971:
1.112 bowersj2 2972: The output string is a table containing all desired attempts, if any.
1.16 harris41 2973:
1.112 bowersj2 2974: =cut
1.1 albertel 2975:
2976: sub get_previous_attempt {
1.43 ng 2977: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 2978: my $prevattempts='';
1.43 ng 2979: no strict 'refs';
1.1 albertel 2980: if ($symb) {
1.3 albertel 2981: my (%returnhash)=
2982: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 2983: if ($returnhash{'version'}) {
2984: my %lasthash=();
2985: my $version;
2986: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 2987: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
2988: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 2989: }
1.1 albertel 2990: }
1.596 albertel 2991: $prevattempts=&start_data_table().&start_data_table_header_row();
2992: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 2993: foreach my $key (sort(keys(%lasthash))) {
2994: my ($ign,@parts) = split(/\./,$key);
1.41 ng 2995: if ($#parts > 0) {
1.31 albertel 2996: my $data=$parts[-1];
2997: pop(@parts);
1.596 albertel 2998: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 2999: } else {
1.41 ng 3000: if ($#parts == 0) {
3001: $prevattempts.='<th>'.$parts[0].'</th>';
3002: } else {
3003: $prevattempts.='<th>'.$ign.'</th>';
3004: }
1.31 albertel 3005: }
1.16 harris41 3006: }
1.596 albertel 3007: $prevattempts.=&end_data_table_header_row();
1.40 ng 3008: if ($getattempt eq '') {
3009: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3010: $prevattempts.=&start_data_table_row().
3011: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3012: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3013: my $value = &format_previous_attempt_value($key,
3014: $returnhash{$version.':'.$key});
3015: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3016: }
1.596 albertel 3017: $prevattempts.=&end_data_table_row();
1.40 ng 3018: }
1.1 albertel 3019: }
1.596 albertel 3020: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3021: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3022: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3023: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3024: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3025: }
1.596 albertel 3026: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3027: } else {
1.596 albertel 3028: $prevattempts=
3029: &start_data_table().&start_data_table_row().
3030: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3031: &end_data_table_row().&end_data_table();
1.1 albertel 3032: }
3033: } else {
1.596 albertel 3034: $prevattempts=
3035: &start_data_table().&start_data_table_row().
3036: '<td>'.&mt('No data.').'</td>'.
3037: &end_data_table_row().&end_data_table();
1.1 albertel 3038: }
1.10 albertel 3039: }
3040:
1.581 albertel 3041: sub format_previous_attempt_value {
3042: my ($key,$value) = @_;
3043: if ($key =~ /timestamp/) {
3044: $value = &Apache::lonlocal::locallocaltime($value);
3045: } elsif (ref($value) eq 'ARRAY') {
3046: $value = '('.join(', ', @{ $value }).')';
3047: } else {
3048: $value = &unescape($value);
3049: }
3050: return $value;
3051: }
3052:
3053:
1.107 albertel 3054: sub relative_to_absolute {
3055: my ($url,$output)=@_;
3056: my $parser=HTML::TokeParser->new(\$output);
3057: my $token;
3058: my $thisdir=$url;
3059: my @rlinks=();
3060: while ($token=$parser->get_token) {
3061: if ($token->[0] eq 'S') {
3062: if ($token->[1] eq 'a') {
3063: if ($token->[2]->{'href'}) {
3064: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3065: }
3066: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3067: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3068: } elsif ($token->[1] eq 'base') {
3069: $thisdir=$token->[2]->{'href'};
3070: }
3071: }
3072: }
3073: $thisdir=~s-/[^/]*$--;
1.356 albertel 3074: foreach my $link (@rlinks) {
3075: unless (($link=~/^http:\/\//i) ||
3076: ($link=~/^\//) ||
3077: ($link=~/^javascript:/i) ||
3078: ($link=~/^mailto:/i) ||
3079: ($link=~/^\#/)) {
3080: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3081: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3082: }
3083: }
3084: # -------------------------------------------------- Deal with Applet codebases
3085: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3086: return $output;
3087: }
3088:
1.112 bowersj2 3089: =pod
3090:
3091: =item * get_student_view
3092:
3093: show a snapshot of what student was looking at
3094:
3095: =cut
3096:
1.10 albertel 3097: sub get_student_view {
1.186 albertel 3098: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3099: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3100: my (%form);
1.10 albertel 3101: my @elements=('symb','courseid','domain','username');
3102: foreach my $element (@elements) {
1.186 albertel 3103: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3104: }
1.186 albertel 3105: if (defined($moreenv)) {
3106: %form=(%form,%{$moreenv});
3107: }
1.236 albertel 3108: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3109: $feedurl=&Apache::lonnet::clutter($feedurl);
1.186 albertel 3110: my $userview=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3111: $userview=~s/\<body[^\>]*\>//gi;
3112: $userview=~s/\<\/body\>//gi;
3113: $userview=~s/\<html\>//gi;
3114: $userview=~s/\<\/html\>//gi;
3115: $userview=~s/\<head\>//gi;
3116: $userview=~s/\<\/head\>//gi;
3117: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3118: $userview=&relative_to_absolute($feedurl,$userview);
1.11 albertel 3119: return $userview;
3120: }
3121:
1.112 bowersj2 3122: =pod
3123:
3124: =item * get_student_answers()
3125:
3126: show a snapshot of how student was answering problem
3127:
3128: =cut
3129:
1.11 albertel 3130: sub get_student_answers {
1.100 sakharuk 3131: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3132: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3133: my (%moreenv);
1.11 albertel 3134: my @elements=('symb','courseid','domain','username');
3135: foreach my $element (@elements) {
1.186 albertel 3136: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3137: }
1.186 albertel 3138: $moreenv{'grade_target'}='answer';
3139: %moreenv=(%form,%moreenv);
1.497 raeburn 3140: $feedurl = &Apache::lonnet::clutter($feedurl);
3141: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3142: return $userview;
1.1 albertel 3143: }
1.116 albertel 3144:
3145: =pod
3146:
3147: =item * &submlink()
3148:
1.242 albertel 3149: Inputs: $text $uname $udom $symb $target
1.116 albertel 3150:
3151: Returns: A link to grades.pm such as to see the SUBM view of a student
3152:
3153: =cut
3154:
3155: ###############################################
3156: sub submlink {
1.242 albertel 3157: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3158: if (!($uname && $udom)) {
3159: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3160: &Apache::lonnet::whichuser($symb);
1.116 albertel 3161: if (!$symb) { $symb=$cursymb; }
3162: }
1.254 matthew 3163: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3164: $symb=&escape($symb);
1.242 albertel 3165: if ($target) { $target="target=\"$target\""; }
3166: return '<a href="/adm/grades?&command=submission&'.
3167: 'symb='.$symb.'&student='.$uname.
3168: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3169: }
3170: ##############################################
3171:
3172: =pod
3173:
3174: =item * &pgrdlink()
3175:
3176: Inputs: $text $uname $udom $symb $target
3177:
3178: Returns: A link to grades.pm such as to see the PGRD view of a student
3179:
3180: =cut
3181:
3182: ###############################################
3183: sub pgrdlink {
3184: my $link=&submlink(@_);
3185: $link=~s/(&command=submission)/$1&showgrading=yes/;
3186: return $link;
3187: }
3188: ##############################################
3189:
3190: =pod
3191:
3192: =item * &pprmlink()
3193:
3194: Inputs: $text $uname $udom $symb $target
3195:
3196: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3197: student and a specific resource
1.242 albertel 3198:
3199: =cut
3200:
3201: ###############################################
3202: sub pprmlink {
3203: my ($text,$uname,$udom,$symb,$target)=@_;
3204: if (!($uname && $udom)) {
3205: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3206: &Apache::lonnet::whichuser($symb);
1.242 albertel 3207: if (!$symb) { $symb=$cursymb; }
3208: }
1.254 matthew 3209: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3210: $symb=&escape($symb);
1.242 albertel 3211: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3212: return '<a href="/adm/parmset?command=set&'.
3213: 'symb='.$symb.'&uname='.$uname.
3214: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3215: }
3216: ##############################################
1.37 matthew 3217:
1.112 bowersj2 3218: =pod
3219:
3220: =back
3221:
3222: =cut
3223:
1.37 matthew 3224: ###############################################
1.51 www 3225:
3226:
3227: sub timehash {
3228: my @ltime=localtime(shift);
3229: return ( 'seconds' => $ltime[0],
3230: 'minutes' => $ltime[1],
3231: 'hours' => $ltime[2],
3232: 'day' => $ltime[3],
3233: 'month' => $ltime[4]+1,
3234: 'year' => $ltime[5]+1900,
3235: 'weekday' => $ltime[6],
3236: 'dayyear' => $ltime[7]+1,
3237: 'dlsav' => $ltime[8] );
3238: }
3239:
1.370 www 3240: sub utc_string {
3241: my ($date)=@_;
1.371 www 3242: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3243: }
3244:
1.51 www 3245: sub maketime {
3246: my %th=@_;
3247: return POSIX::mktime(
3248: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3249: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3250: }
3251:
3252: #########################################
1.51 www 3253:
3254: sub findallcourses {
1.482 raeburn 3255: my ($roles,$uname,$udom) = @_;
1.355 albertel 3256: my %roles;
3257: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3258: my %courses;
1.51 www 3259: my $now=time;
1.482 raeburn 3260: if (!defined($uname)) {
3261: $uname = $env{'user.name'};
3262: }
3263: if (!defined($udom)) {
3264: $udom = $env{'user.domain'};
3265: }
3266: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3267: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3268: if (!%roles) {
3269: %roles = (
3270: cc => 1,
3271: in => 1,
3272: ep => 1,
3273: ta => 1,
3274: cr => 1,
3275: st => 1,
3276: );
3277: }
3278: foreach my $entry (keys(%roleshash)) {
3279: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3280: if ($trole =~ /^cr/) {
3281: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3282: } else {
3283: next if (!exists($roles{$trole}));
3284: }
3285: if ($tend) {
3286: next if ($tend < $now);
3287: }
3288: if ($tstart) {
3289: next if ($tstart > $now);
3290: }
3291: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3292: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3293: if ($secpart eq '') {
3294: ($cnum,$role) = split(/_/,$cnumpart);
3295: $sec = 'none';
3296: $realsec = '';
3297: } else {
3298: $cnum = $cnumpart;
3299: ($sec,$role) = split(/_/,$secpart);
3300: $realsec = $sec;
1.490 raeburn 3301: }
1.482 raeburn 3302: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3303: }
3304: } else {
3305: foreach my $key (keys(%env)) {
1.483 albertel 3306: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3307: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3308: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3309: next if ($role eq 'ca' || $role eq 'aa');
3310: next if (%roles && !exists($roles{$role}));
3311: my ($starttime,$endtime)=split(/\./,$env{$key});
3312: my $active=1;
3313: if ($starttime) {
3314: if ($now<$starttime) { $active=0; }
3315: }
3316: if ($endtime) {
3317: if ($now>$endtime) { $active=0; }
3318: }
3319: if ($active) {
3320: if ($sec eq '') {
3321: $sec = 'none';
3322: }
3323: $courses{$cdom.'_'.$cnum}{$sec} =
3324: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3325: }
3326: }
1.51 www 3327: }
3328: }
1.474 raeburn 3329: return %courses;
1.51 www 3330: }
1.37 matthew 3331:
1.54 www 3332: ###############################################
1.474 raeburn 3333:
3334: sub blockcheck {
1.482 raeburn 3335: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3336:
3337: if (!defined($udom)) {
3338: $udom = $env{'user.domain'};
3339: }
3340: if (!defined($uname)) {
3341: $uname = $env{'user.name'};
3342: }
3343:
3344: # If uname and udom are for a course, check for blocks in the course.
3345:
3346: if (&Apache::lonnet::is_course($udom,$uname)) {
3347: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3348: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3349: return ($startblock,$endblock);
3350: }
1.474 raeburn 3351:
1.502 raeburn 3352: my $startblock = 0;
3353: my $endblock = 0;
1.482 raeburn 3354: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3355:
1.490 raeburn 3356: # If uname is for a user, and activity is course-specific, i.e.,
3357: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3358:
1.490 raeburn 3359: if (($activity eq 'boards' || $activity eq 'chat' ||
3360: $activity eq 'groups') && ($env{'request.course.id'})) {
3361: foreach my $key (keys(%live_courses)) {
3362: if ($key ne $env{'request.course.id'}) {
3363: delete($live_courses{$key});
3364: }
3365: }
3366: }
3367:
3368: my $otheruser = 0;
3369: my %own_courses;
3370: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3371: # Resource belongs to user other than current user.
3372: $otheruser = 1;
3373: # Gather courses for current user
3374: %own_courses =
3375: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3376: }
3377:
3378: # Gather active course roles - course coordinator, instructor,
3379: # exam proctor, ta, student, or custom role.
1.474 raeburn 3380:
3381: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3382: my ($cdom,$cnum);
3383: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3384: $cdom = $env{'course.'.$course.'.domain'};
3385: $cnum = $env{'course.'.$course.'.num'};
3386: } else {
1.490 raeburn 3387: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3388: }
3389: my $no_ownblock = 0;
3390: my $no_userblock = 0;
1.533 raeburn 3391: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3392: # Check if current user has 'evb' priv for this
3393: if (defined($own_courses{$course})) {
3394: foreach my $sec (keys(%{$own_courses{$course}})) {
3395: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3396: if ($sec ne 'none') {
3397: $checkrole .= '/'.$sec;
3398: }
3399: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3400: $no_ownblock = 1;
3401: last;
3402: }
3403: }
3404: }
3405: # if they have 'evb' priv and are currently not playing student
3406: next if (($no_ownblock) &&
3407: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3408: }
1.474 raeburn 3409: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3410: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3411: if ($sec ne 'none') {
1.482 raeburn 3412: $checkrole .= '/'.$sec;
1.474 raeburn 3413: }
1.490 raeburn 3414: if ($otheruser) {
3415: # Resource belongs to user other than current user.
3416: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3417: my ($trole,$tdom,$tnum,$tsec);
3418: my $entry = $live_courses{$course}{$sec};
3419: if ($entry =~ /^cr/) {
3420: ($trole,$tdom,$tnum,$tsec) =
3421: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3422: } else {
3423: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3424: }
3425: my ($spec,$area,$trest,%allroles,%userroles);
3426: $area = '/'.$tdom.'/'.$tnum;
3427: $trest = $tnum;
3428: if ($tsec ne '') {
3429: $area .= '/'.$tsec;
3430: $trest .= '/'.$tsec;
3431: }
3432: $spec = $trole.'.'.$area;
3433: if ($trole =~ /^cr/) {
3434: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3435: $tdom,$spec,$trest,$area);
3436: } else {
3437: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3438: $tdom,$spec,$trest,$area);
3439: }
3440: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3441: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3442: if ($1) {
3443: $no_userblock = 1;
3444: last;
3445: }
3446: }
1.490 raeburn 3447: } else {
3448: # Resource belongs to current user
3449: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3450: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3451: $no_ownblock = 1;
3452: last;
3453: }
1.474 raeburn 3454: }
3455: }
3456: # if they have the evb priv and are currently not playing student
1.482 raeburn 3457: next if (($no_ownblock) &&
1.491 albertel 3458: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3459: next if ($no_userblock);
1.474 raeburn 3460:
1.490 raeburn 3461: # Retrieve blocking times and identity of blocker for course
3462: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3463:
3464: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3465: if (($start != 0) &&
3466: (($startblock == 0) || ($startblock > $start))) {
3467: $startblock = $start;
3468: }
3469: if (($end != 0) &&
3470: (($endblock == 0) || ($endblock < $end))) {
3471: $endblock = $end;
3472: }
1.490 raeburn 3473: }
3474: return ($startblock,$endblock);
3475: }
3476:
3477: sub get_blocks {
3478: my ($setters,$activity,$cdom,$cnum) = @_;
3479: my $startblock = 0;
3480: my $endblock = 0;
3481: my $course = $cdom.'_'.$cnum;
3482: $setters->{$course} = {};
3483: $setters->{$course}{'staff'} = [];
3484: $setters->{$course}{'times'} = [];
3485: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3486: foreach my $record (keys(%records)) {
3487: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3488: if ($start <= time && $end >= time) {
3489: my ($staff_name,$staff_dom,$title,$blocks) =
3490: &parse_block_record($records{$record});
3491: if ($blocks->{$activity} eq 'on') {
3492: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3493: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3494: if ( ($startblock == 0) || ($startblock > $start) ) {
3495: $startblock = $start;
1.490 raeburn 3496: }
1.491 albertel 3497: if ( ($endblock == 0) || ($endblock < $end) ) {
3498: $endblock = $end;
1.474 raeburn 3499: }
3500: }
3501: }
3502: }
3503: return ($startblock,$endblock);
3504: }
3505:
3506: sub parse_block_record {
3507: my ($record) = @_;
3508: my ($setuname,$setudom,$title,$blocks);
3509: if (ref($record) eq 'HASH') {
3510: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3511: $title = &unescape($record->{'event'});
3512: $blocks = $record->{'blocks'};
3513: } else {
3514: my @data = split(/:/,$record,3);
3515: if (scalar(@data) eq 2) {
3516: $title = $data[1];
3517: ($setuname,$setudom) = split(/@/,$data[0]);
3518: } else {
3519: ($setuname,$setudom,$title) = @data;
3520: }
3521: $blocks = { 'com' => 'on' };
3522: }
3523: return ($setuname,$setudom,$title,$blocks);
3524: }
3525:
3526: sub build_block_table {
3527: my ($startblock,$endblock,$setters) = @_;
3528: my %lt = &Apache::lonlocal::texthash(
3529: 'cacb' => 'Currently active communication blocks',
3530: 'cour' => 'Course',
3531: 'dura' => 'Duration',
3532: 'blse' => 'Block set by'
3533: );
3534: my $output;
1.476 raeburn 3535: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3536: $output .= &start_data_table();
3537: $output .= '
3538: <tr>
3539: <th>'.$lt{'cour'}.'</th>
3540: <th>'.$lt{'dura'}.'</th>
3541: <th>'.$lt{'blse'}.'</th>
3542: </tr>
3543: ';
3544: foreach my $course (keys(%{$setters})) {
3545: my %courseinfo=&Apache::lonnet::coursedescription($course);
3546: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3547: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3548: my $fullname = &plainname($uname,$udom);
3549: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3550: && $env{'user.name'} ne 'public'
3551: && $env{'user.domain'} ne 'public') {
3552: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3553: }
1.474 raeburn 3554: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3555: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3556: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3557: $output .= &Apache::loncommon::start_data_table_row().
3558: '<td>'.$courseinfo{'description'}.'</td>'.
3559: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3560: '<td>'.$fullname.'</td>'.
1.474 raeburn 3561: &Apache::loncommon::end_data_table_row();
3562: }
3563: }
3564: $output .= &end_data_table();
3565: }
3566:
1.490 raeburn 3567: sub blocking_status {
3568: my ($activity,$uname,$udom) = @_;
3569: my %setters;
3570: my ($blocked,$output,$ownitem,$is_course);
3571: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3572: if ($startblock && $endblock) {
3573: $blocked = 1;
3574: if (wantarray) {
3575: my $category;
3576: if ($activity eq 'boards') {
3577: $category = 'Discussion posts in this course';
3578: } elsif ($activity eq 'blogs') {
3579: $category = 'Blogs';
3580: } elsif ($activity eq 'port') {
3581: if (defined($uname) && defined($udom)) {
3582: if ($uname eq $env{'user.name'} &&
3583: $udom eq $env{'user.domain'}) {
3584: $ownitem = 1;
3585: }
3586: }
3587: $is_course = &Apache::lonnet::is_course($udom,$uname);
3588: if ($ownitem) {
3589: $category = 'Your portfolio files';
3590: } elsif ($is_course) {
3591: my $coursedesc;
3592: foreach my $course (keys(%setters)) {
3593: my %courseinfo =
3594: &Apache::lonnet::coursedescription($course);
3595: $coursedesc = $courseinfo{'description'};
3596: }
3597: $category = "Group files in the course '$coursedesc'";
3598: } else {
3599: $category = 'Portfolio files belonging to ';
3600: if ($env{'user.name'} eq 'public' &&
3601: $env{'user.domain'} eq 'public') {
3602: $category .= &plainname($uname,$udom);
3603: } else {
3604: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3605: }
3606: }
3607: } elsif ($activity eq 'groups') {
3608: $category = 'Groups in this course';
3609: }
3610: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3611: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3612: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3613: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3614: $output .= &build_block_table($startblock,$endblock,\%setters);
3615: }
3616: }
3617: }
3618: if (wantarray) {
3619: return ($blocked,$output);
3620: } else {
3621: return $blocked;
3622: }
3623: }
3624:
1.60 matthew 3625: ###############################################
3626:
3627: =pod
3628:
1.112 bowersj2 3629: =head1 Domain Template Functions
3630:
3631: =over 4
3632:
3633: =item * &determinedomain()
1.60 matthew 3634:
3635: Inputs: $domain (usually will be undef)
3636:
1.63 www 3637: Returns: Determines which domain should be used for designs
1.60 matthew 3638:
3639: =cut
1.54 www 3640:
1.60 matthew 3641: ###############################################
1.63 www 3642: sub determinedomain {
3643: my $domain=shift;
1.531 albertel 3644: if (! $domain) {
1.60 matthew 3645: # Determine domain if we have not been given one
3646: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3647: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3648: if ($env{'request.role.domain'}) {
3649: $domain=$env{'request.role.domain'};
1.60 matthew 3650: }
3651: }
1.63 www 3652: return $domain;
3653: }
3654: ###############################################
1.517 raeburn 3655:
1.518 albertel 3656: sub devalidate_domconfig_cache {
3657: my ($udom)=@_;
3658: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3659: }
3660:
3661: # ---------------------- Get domain configuration for a domain
3662: sub get_domainconf {
3663: my ($udom) = @_;
3664: my $cachetime=1800;
3665: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3666: if (defined($cached)) { return %{$result}; }
3667:
3668: my %domconfig = &Apache::lonnet::get_dom('configuration',
3669: ['login','rolecolors'],$udom);
3670: my %designhash;
3671: if (keys(%domconfig) > 0) {
3672: if (ref($domconfig{'login'}) eq 'HASH') {
3673: foreach my $key (keys(%{$domconfig{'login'}})) {
3674: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3675: }
3676: }
3677: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
3678: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3679: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3680: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3681: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3682: }
3683: }
3684: }
3685: }
3686: } else {
3687: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
3688: my $designfile = $designdir.'/'.$udom.'.tab';
3689: if (-e $designfile) {
3690: if ( open (my $fh,"<$designfile") ) {
3691: while (my $line = <$fh>) {
3692: next if ($line =~ /^\#/);
3693: chomp($line);
3694: my ($key,$val)=(split(/\=/,$line));
3695: if ($val) { $designhash{$udom.'.'.$key}=$val; }
3696: }
3697: close($fh);
3698: }
3699: }
3700: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
1.519 raeburn 3701: $designhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
1.518 albertel 3702: }
3703: }
3704: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3705: $cachetime);
3706: return %designhash;
3707: }
3708:
1.63 www 3709: =pod
3710:
1.112 bowersj2 3711: =item * &domainlogo()
1.63 www 3712:
3713: Inputs: $domain (usually will be undef)
3714:
3715: Returns: A link to a domain logo, if the domain logo exists.
3716: If the domain logo does not exist, a description of the domain.
3717:
3718: =cut
1.112 bowersj2 3719:
1.63 www 3720: ###############################################
3721: sub domainlogo {
1.517 raeburn 3722: my $domain = &determinedomain(shift);
1.518 albertel 3723: my %designhash = &get_domainconf($domain);
1.517 raeburn 3724: # See if there is a logo
3725: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 3726: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 3727: if ($imgsrc =~ m{^/(adm|res)/}) {
3728: if ($imgsrc =~ m{^/res/}) {
3729: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
3730: &Apache::lonnet::repcopy($local_name);
3731: }
3732: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 3733: }
3734: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 3735: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
3736: return &Apache::lonnet::domain($domain,'description');
1.59 www 3737: } else {
1.60 matthew 3738: return '';
1.59 www 3739: }
3740: }
1.63 www 3741: ##############################################
3742:
3743: =pod
3744:
1.112 bowersj2 3745: =item * &designparm()
1.63 www 3746:
3747: Inputs: $which parameter; $domain (usually will be undef)
3748:
3749: Returns: value of designparamter $which
3750:
3751: =cut
1.112 bowersj2 3752:
1.397 albertel 3753:
1.400 albertel 3754: ##############################################
1.397 albertel 3755: sub designparm {
3756: my ($which,$domain)=@_;
1.258 albertel 3757: if ($env{'browser.blackwhite'} eq 'on') {
1.110 www 3758: if ($which=~/\.(font|alink|vlink|link)$/) {
3759: return '#000000';
3760: }
3761: if ($which=~/\.(pgbg|sidebg)$/) {
3762: return '#FFFFFF';
3763: }
3764: if ($which=~/\.tabbg$/) {
3765: return '#CCCCCC';
3766: }
3767: }
1.397 albertel 3768: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 3769: return $env{'environment.color.'.$which};
1.96 www 3770: }
1.63 www 3771: $domain=&determinedomain($domain);
1.518 albertel 3772: my %domdesign = &get_domainconf($domain);
1.520 raeburn 3773: my $output;
1.517 raeburn 3774: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 3775: $output = $domdesign{$domain.'.'.$which};
1.63 www 3776: } else {
1.520 raeburn 3777: $output = $defaultdesign{$which};
3778: }
3779: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
3780: ($which =~ /login\.(img|logo|domlogo)/)) {
1.538 albertel 3781: if ($output =~ m{^/(adm|res)/}) {
3782: if ($output =~ m{^/res/}) {
3783: my $local_name = &Apache::lonnet::filelocation('',$output);
3784: &Apache::lonnet::repcopy($local_name);
3785: }
1.520 raeburn 3786: $output = &lonhttpdurl($output);
3787: }
1.63 www 3788: }
1.520 raeburn 3789: return $output;
1.63 www 3790: }
1.59 www 3791:
1.60 matthew 3792: ###############################################
3793: ###############################################
3794:
3795: =pod
3796:
1.112 bowersj2 3797: =back
3798:
1.549 albertel 3799: =head1 HTML Helpers
1.112 bowersj2 3800:
3801: =over 4
3802:
3803: =item * &bodytag()
1.60 matthew 3804:
3805: Returns a uniform header for LON-CAPA web pages.
3806:
3807: Inputs:
3808:
1.112 bowersj2 3809: =over 4
3810:
3811: =item * $title, A title to be displayed on the page.
3812:
3813: =item * $function, the current role (can be undef).
3814:
3815: =item * $addentries, extra parameters for the <body> tag.
3816:
3817: =item * $bodyonly, if defined, only return the <body> tag.
3818:
3819: =item * $domain, if defined, force a given domain.
3820:
3821: =item * $forcereg, if page should register as content page (relevant for
1.86 www 3822: text interface only)
1.60 matthew 3823:
1.326 albertel 3824: =item * $customtitle, alternate text to use instead of $title
3825: in the title box that appears, this text
3826: is not auto translated like the $title is
1.309 albertel 3827:
3828: =item * $notopbar, if true, keep the 'what is this' info but remove the
3829: navigational links
1.317 albertel 3830:
1.338 albertel 3831: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
3832:
3833: =item * $notitle, if true keep the nav controls, but remove the title bar
3834:
1.361 albertel 3835: =item * $no_inline_link, if true and in remote mode, don't show the
3836: 'Switch To Inline Menu' link
3837:
1.460 albertel 3838: =item * $args, optional argument valid values are
3839: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 3840: inherit_jsmath -> when creating popup window in a page,
3841: should it have jsmath forced on by the
3842: current page
1.460 albertel 3843:
1.112 bowersj2 3844: =back
3845:
1.60 matthew 3846: Returns: A uniform header for LON-CAPA web pages.
3847: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
3848: If $bodyonly is undef or zero, an html string containing a <body> tag and
3849: other decorations will be returned.
3850:
3851: =cut
3852:
1.54 www 3853: sub bodytag {
1.309 albertel 3854: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 3855: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 3856:
1.460 albertel 3857: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 3858:
1.183 matthew 3859: $function = &get_users_function() if (!$function);
1.339 albertel 3860: my $img = &designparm($function.'.img',$domain);
3861: my $font = &designparm($function.'.font',$domain);
3862: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
3863:
3864: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 3865: 'bgcolor' => $pgbg,
1.339 albertel 3866: 'text' => $font,
3867: 'alink' => &designparm($function.'.alink',$domain),
3868: 'vlink' => &designparm($function.'.vlink',$domain),
3869: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 3870: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 3871:
1.63 www 3872: # role and realm
1.378 raeburn 3873: my ($role,$realm) = split(/\./,$env{'request.role'},2);
3874: if ($role eq 'ca') {
1.479 albertel 3875: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 3876: $realm = &plainname($rname,$rdom);
1.378 raeburn 3877: }
1.55 www 3878: # realm
1.258 albertel 3879: if ($env{'request.course.id'}) {
1.378 raeburn 3880: if ($env{'request.role'} !~ /^cr/) {
3881: $role = &Apache::lonnet::plaintext($role,&course_type());
3882: }
1.359 albertel 3883: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 3884: } else {
3885: $role = &Apache::lonnet::plaintext($role);
1.54 www 3886: }
1.433 albertel 3887:
1.359 albertel 3888: if (!$realm) { $realm=' '; }
1.55 www 3889: # Set messages
1.60 matthew 3890: my $messages=&domainlogo($domain);
1.330 albertel 3891:
1.438 albertel 3892: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 3893:
1.101 www 3894: # construct main body tag
1.359 albertel 3895: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 3896: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 3897:
1.530 albertel 3898: if ($bodyonly) {
1.60 matthew 3899: return $bodytag;
1.258 albertel 3900: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 3901: # Accessibility
1.224 raeburn 3902:
1.337 albertel 3903: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 3904: if (!$notitle) {
1.337 albertel 3905: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
3906: }
3907: return $bodytag;
1.359 albertel 3908: }
3909:
1.410 albertel 3910: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 3911: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
3912: undef($role);
1.434 albertel 3913: } else {
3914: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 3915: }
1.359 albertel 3916:
3917: my $roleinfo=(<<ENDROLE);
3918: <td class="LC_title_bar_who">
3919: <div class="LC_title_bar_name">
1.410 albertel 3920: $name
1.361 albertel 3921:
1.359 albertel 3922: </div>
3923: <div class="LC_title_bar_role">
1.361 albertel 3924: $role
1.359 albertel 3925: </div>
3926: <div class="LC_title_bar_realm">
1.361 albertel 3927: $realm
1.359 albertel 3928: </div>
1.206 albertel 3929: </td>
3930: ENDROLE
1.235 raeburn 3931:
1.359 albertel 3932: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
3933: if ($customtitle) {
3934: $titleinfo = $customtitle;
3935: }
3936: #
3937: # Extra info if you are the DC
3938: my $dc_info = '';
3939: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
3940: $env{'course.'.$env{'request.course.id'}.
3941: '.domain'}.'/'})) {
3942: my $cid = $env{'request.course.id'};
3943: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 3944: $dc_info =~ s/\s+$//;
1.359 albertel 3945: $dc_info = '('.$dc_info.')';
3946: }
3947:
3948: if ($env{'environment.remote'} eq 'off') {
3949: # No Remote
1.258 albertel 3950: if ($env{'request.state'} eq 'construct') {
1.359 albertel 3951: $forcereg=1;
3952: }
3953:
3954: if (!$customtitle && $env{'request.state'} eq 'construct') {
3955: # this is for resources; directories have customtitle, and crumbs
3956: # and select recent are created in lonpubdir.pm
1.229 albertel 3957: my ($uname,$thisdisfn)=
1.258 albertel 3958: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 3959: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
3960: $formaction=~s/\/+/\//g;
3961:
1.359 albertel 3962: my $parentpath = '';
3963: my $lastitem = '';
3964: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
3965: $parentpath = $1;
3966: $lastitem = $2;
3967: } else {
3968: $lastitem = $thisdisfn;
3969: }
3970: $titleinfo =
1.401 albertel 3971: &Apache::loncommon::help_open_menu('','',3,'Authoring').
1.359 albertel 3972: '<b>Construction Space</b>: '.
3973: '<form name="dirs" method="post" action="'.$formaction
3974: .'" target="_top"><tt><b>'
3975: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
3976: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
3977: .'</form>'
3978: .&Apache::lonmenu::constspaceform();
1.235 raeburn 3979: }
1.359 albertel 3980:
1.337 albertel 3981: my $titletable;
1.338 albertel 3982: if (!$notitle) {
1.337 albertel 3983: $titletable =
1.359 albertel 3984: '<table id="LC_title_bar">'.
3985: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
3986: '</tr></table>';
1.337 albertel 3987: }
1.359 albertel 3988: if ($notopbar) {
3989: $bodytag .= $titletable;
3990: } else {
3991: if ($env{'request.state'} eq 'construct') {
1.337 albertel 3992: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
3993: $titletable);
1.272 raeburn 3994: } else {
1.336 albertel 3995: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 3996: $titletable;
1.272 raeburn 3997: }
1.235 raeburn 3998: }
3999: return $bodytag;
1.94 www 4000: }
1.95 www 4001:
1.93 www 4002: #
1.95 www 4003: # Top frame rendering, Remote is up
1.93 www 4004: #
1.359 albertel 4005:
1.517 raeburn 4006: my $imgsrc = $img;
4007: if ($img =~ /^\/adm/) {
1.575 albertel 4008: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4009: }
4010: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4011:
1.305 www 4012: # Explicit link to get inline menu
1.361 albertel 4013: my $menu= ($no_inline_link?''
4014: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4015: #
1.338 albertel 4016: if ($notitle) {
1.337 albertel 4017: return $bodytag;
4018: }
1.94 www 4019: return(<<ENDBODY);
1.60 matthew 4020: $bodytag
1.359 albertel 4021: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4022: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4023: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4024: </tr>
1.359 albertel 4025: <tr><td>$titleinfo $dc_info $menu</td>
4026: $roleinfo
1.368 albertel 4027: </tr>
1.356 albertel 4028: </table>
1.54 www 4029: ENDBODY
1.182 matthew 4030: }
4031:
1.330 albertel 4032: sub make_attr_string {
4033: my ($register,$attr_ref) = @_;
4034:
4035: if ($attr_ref && !ref($attr_ref)) {
4036: die("addentries Must be a hash ref ".
4037: join(':',caller(1))." ".
4038: join(':',caller(0))." ");
4039: }
4040:
4041: if ($register) {
1.339 albertel 4042: my ($on_load,$on_unload);
4043: foreach my $key (keys(%{$attr_ref})) {
4044: if (lc($key) eq 'onload') {
4045: $on_load.=$attr_ref->{$key}.';';
4046: delete($attr_ref->{$key});
4047:
4048: } elsif (lc($key) eq 'onunload') {
4049: $on_unload.=$attr_ref->{$key}.';';
4050: delete($attr_ref->{$key});
4051: }
4052: }
4053: $attr_ref->{'onload'} =
4054: &Apache::lonmenu::loadevents(). $on_load;
4055: $attr_ref->{'onunload'}=
4056: &Apache::lonmenu::unloadevents().$on_unload;
4057: }
4058:
4059: # Accessibility font enhance
4060: if ($env{'browser.fontenhance'} eq 'on') {
4061: my $style;
4062: foreach my $key (keys(%{$attr_ref})) {
4063: if (lc($key) eq 'style') {
4064: $style.=$attr_ref->{$key}.';';
4065: delete($attr_ref->{$key});
4066: }
4067: }
4068: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4069: }
1.339 albertel 4070:
4071: if ($env{'browser.blackwhite'} eq 'on') {
4072: delete($attr_ref->{'font'});
4073: delete($attr_ref->{'link'});
4074: delete($attr_ref->{'alink'});
4075: delete($attr_ref->{'vlink'});
4076: delete($attr_ref->{'bgcolor'});
4077: delete($attr_ref->{'background'});
4078: }
4079:
1.330 albertel 4080: my $attr_string;
4081: foreach my $attr (keys(%$attr_ref)) {
4082: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4083: }
4084: return $attr_string;
4085: }
4086:
4087:
1.182 matthew 4088: ###############################################
1.251 albertel 4089: ###############################################
4090:
4091: =pod
4092:
4093: =item * &endbodytag()
4094:
4095: Returns a uniform footer for LON-CAPA web pages.
4096:
1.306 albertel 4097: Inputs: none
1.251 albertel 4098:
4099: =cut
4100:
4101: sub endbodytag {
4102: my $endbodytag='</body>';
1.269 albertel 4103: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4104: if ( exists( $env{'internal.head.redirect'} ) ) {
4105: $endbodytag=
4106: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4107: &mt('Continue').'</a>'.
4108: $endbodytag;
4109: }
1.251 albertel 4110: return $endbodytag;
4111: }
4112:
1.352 albertel 4113: =pod
4114:
4115: =item * &standard_css()
4116:
4117: Returns a style sheet
4118:
4119: Inputs: (all optional)
4120: domain -> force to color decorate a page for a specific
4121: domain
4122: function -> force usage of a specific rolish color scheme
4123: bgcolor -> override the default page bgcolor
4124:
4125: =cut
4126:
1.343 albertel 4127: sub standard_css {
1.345 albertel 4128: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4129: $function = &get_users_function() if (!$function);
4130: my $img = &designparm($function.'.img', $domain);
4131: my $tabbg = &designparm($function.'.tabbg', $domain);
4132: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4133: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4134: my $pgbg_or_bgcolor =
4135: $bgcolor ||
1.352 albertel 4136: &designparm($function.'.pgbg', $domain);
1.382 albertel 4137: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4138: my $alink = &designparm($function.'.alink', $domain);
4139: my $vlink = &designparm($function.'.vlink', $domain);
4140: my $link = &designparm($function.'.link', $domain);
4141:
1.602 albertel 4142: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4143: my $mono = 'monospace';
1.352 albertel 4144: my $data_table_head = $tabbg;
4145: my $data_table_light = '#EEEEEE';
1.470 banghart 4146: my $data_table_dark = '#DDDDDD';
4147: my $data_table_darker = '#CCCCCC';
1.349 albertel 4148: my $data_table_highlight = '#FFFF00';
1.352 albertel 4149: my $mail_new = '#FFBB77';
4150: my $mail_new_hover = '#DD9955';
4151: my $mail_read = '#BBBB77';
4152: my $mail_read_hover = '#999944';
4153: my $mail_replied = '#AAAA88';
4154: my $mail_replied_hover = '#888855';
4155: my $mail_other = '#99BBBB';
4156: my $mail_other_hover = '#669999';
1.391 albertel 4157: my $table_header = '#DDDDDD';
1.489 raeburn 4158: my $feedback_link_bg = '#BBBBBB';
1.392 albertel 4159:
1.608 albertel 4160: my $border = ($env{'browser.type'} eq 'explorer' ||
4161: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4162: : '0px 3px 0px 4px';
1.448 albertel 4163:
1.523 albertel 4164:
1.343 albertel 4165: return <<END;
1.345 albertel 4166: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4167: a:focus { color: red; background: yellow }
1.510 albertel 4168: table.thinborder,
1.523 albertel 4169:
1.510 albertel 4170: table.thinborder tr th {
4171: border-style: solid;
4172: border-width: 1px;
4173: background: $tabbg;
4174: }
1.523 albertel 4175: table.thinborder tr td {
1.510 albertel 4176: border-style: solid;
4177: border-width: 1px
4178: }
1.426 albertel 4179:
1.343 albertel 4180: form, .inline { display: inline; }
4181: .center { text-align: center; }
1.593 albertel 4182: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4183: .LC_error {
4184: color: red;
4185: font-size: larger;
4186: }
1.457 albertel 4187: .LC_warning,
4188: .LC_diff_removed {
1.394 albertel 4189: color: red;
4190: }
1.532 albertel 4191:
4192: .LC_info,
1.457 albertel 4193: .LC_success,
4194: .LC_diff_added {
1.350 albertel 4195: color: green;
4196: }
1.543 albertel 4197: .LC_unknown {
4198: color: yellow;
4199: }
4200:
1.440 albertel 4201: .LC_icon {
4202: border: 0px;
4203: }
1.539 albertel 4204: .LC_indexer_icon {
4205: border: 0px;
4206: height: 22px;
4207: }
1.543 albertel 4208: .LC_docs_spacer {
4209: width: 25px;
4210: height: 1px;
4211: border: 0px;
4212: }
1.346 albertel 4213:
1.532 albertel 4214: .LC_internal_info {
4215: color: #999;
4216: }
4217:
1.458 albertel 4218: table.LC_pastsubmission {
4219: border: 1px solid black;
4220: margin: 2px;
4221: }
4222:
1.606 albertel 4223: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4224: width: 100%;
4225: background: $pgbg;
1.392 albertel 4226: border: 2px;
1.402 albertel 4227: border-collapse: separate;
1.403 albertel 4228: padding: 0px;
1.345 albertel 4229: }
1.392 albertel 4230:
1.606 albertel 4231: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4232: table#LC_title_bar.LC_with_remote {
1.359 albertel 4233: width: 100%;
1.392 albertel 4234: border-color: $pgbg;
4235: border-style: solid;
4236: border-width: $border;
4237:
1.379 albertel 4238: background: $pgbg;
4239: font-family: $sans;
1.392 albertel 4240: border-collapse: collapse;
1.403 albertel 4241: padding: 0px;
1.359 albertel 4242: }
1.392 albertel 4243:
1.409 albertel 4244: table.LC_docs_path {
4245: width: 100%;
4246: border: 0;
4247: background: $pgbg;
4248: font-family: $sans;
4249: border-collapse: collapse;
4250: padding: 0px;
4251: }
4252:
1.359 albertel 4253: table#LC_title_bar td {
4254: background: $tabbg;
4255: }
4256: table#LC_title_bar td.LC_title_bar_who {
4257: background: $tabbg;
4258: color: $font;
1.427 albertel 4259: font: small $sans;
1.359 albertel 4260: text-align: right;
4261: }
1.469 banghart 4262: span.LC_metadata {
4263: font-family: $sans;
4264: }
1.359 albertel 4265: span.LC_title_bar_title {
1.416 albertel 4266: font: bold x-large $sans;
1.359 albertel 4267: }
4268: table#LC_title_bar td.LC_title_bar_domain_logo {
4269: background: $sidebg;
4270: text-align: right;
1.368 albertel 4271: padding: 0px;
4272: }
4273: table#LC_title_bar td.LC_title_bar_role_logo {
4274: background: $sidebg;
4275: padding: 0px;
1.359 albertel 4276: }
4277:
1.346 albertel 4278: table#LC_menubuttons_mainmenu {
1.526 www 4279: width: 100%;
1.346 albertel 4280: border: 0px;
4281: border-spacing: 1px;
1.372 albertel 4282: padding: 0px 1px;
1.346 albertel 4283: margin: 0px;
4284: border-collapse: separate;
4285: }
4286: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
4287: border: 0px;
4288: }
1.345 albertel 4289: table#LC_top_nav td {
4290: background: $tabbg;
1.392 albertel 4291: border: 0px;
1.407 albertel 4292: font-size: small;
1.345 albertel 4293: }
4294: table#LC_top_nav td a, div#LC_top_nav a {
4295: color: $font;
4296: font-family: $sans;
4297: }
1.364 albertel 4298: table#LC_top_nav td.LC_top_nav_logo {
4299: background: $tabbg;
1.432 albertel 4300: text-align: left;
1.408 albertel 4301: white-space: nowrap;
1.432 albertel 4302: width: 31px;
1.408 albertel 4303: }
4304: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4305: border: 0px;
1.408 albertel 4306: vertical-align: bottom;
1.364 albertel 4307: }
1.432 albertel 4308: table#LC_top_nav td.LC_top_nav_exit,
4309: table#LC_top_nav td.LC_top_nav_help {
4310: width: 2.0em;
4311: }
1.442 albertel 4312: table#LC_top_nav td.LC_top_nav_login {
4313: width: 4.0em;
4314: text-align: center;
4315: }
1.409 albertel 4316: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4317: background: $tabbg;
4318: color: $font;
4319: font-family: $sans;
1.358 albertel 4320: font-size: smaller;
1.357 albertel 4321: }
1.411 albertel 4322: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4323: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4324: background: $tabbg;
4325: color: $font;
4326: font-family: $sans;
4327: font-size: larger;
4328: text-align: right;
4329: }
1.383 albertel 4330: td.LC_table_cell_checkbox {
4331: text-align: center;
4332: }
4333:
1.522 albertel 4334: table#LC_mainmenu td.LC_mainmenu_column {
4335: vertical-align: top;
4336: }
4337:
1.346 albertel 4338: .LC_menubuttons_inline_text {
4339: color: $font;
4340: font-family: $sans;
4341: font-size: smaller;
4342: }
4343:
1.526 www 4344: .LC_menubuttons_link {
4345: text-decoration: none;
4346: }
4347:
1.522 albertel 4348: .LC_menubuttons_category {
1.521 www 4349: color: $font;
1.526 www 4350: background: $pgbg;
1.521 www 4351: font-family: $sans;
4352: font-size: larger;
4353: font-weight: bold;
4354: }
4355:
1.346 albertel 4356: td.LC_menubuttons_text {
1.526 www 4357: width: 90%;
1.346 albertel 4358: color: $font;
4359: font-family: $sans;
4360: }
1.526 www 4361:
1.346 albertel 4362: td.LC_menubuttons_img {
4363: }
1.526 www 4364:
1.346 albertel 4365: .LC_current_location {
4366: font-family: $sans;
4367: background: $tabbg;
4368: }
4369: .LC_new_mail {
4370: font-family: $sans;
4371: font-weight: bold;
4372: }
1.347 albertel 4373:
1.526 www 4374: .LC_rolesmenu_is {
4375: font-family: $sans;
4376: }
4377:
4378: .LC_rolesmenu_selected {
4379: font-family: $sans;
4380: }
4381:
4382: .LC_rolesmenu_future {
4383: font-family: $sans;
4384: }
4385:
4386:
4387: .LC_rolesmenu_will {
4388: font-family: $sans;
4389: }
4390:
4391: .LC_rolesmenu_will_not {
4392: font-family: $sans;
4393: }
4394:
4395: .LC_rolesmenu_expired {
4396: font-family: $sans;
4397: }
4398:
4399: .LC_rolesinfo {
4400: font-family: $sans;
4401: }
4402:
1.527 www 4403: .LC_dropadd_labeltext {
4404: font-family: $sans;
4405: text-align: right;
4406: }
4407:
4408: .LC_preferences_labeltext {
4409: font-family: $sans;
4410: text-align: right;
4411: }
4412:
1.440 albertel 4413: table.LC_aboutme_port {
4414: border: 0px;
4415: border-collapse: collapse;
4416: border-spacing: 0px;
4417: }
1.349 albertel 4418: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4419: border: 1px solid #000000;
1.402 albertel 4420: border-collapse: separate;
1.426 albertel 4421: border-spacing: 1px;
1.610 albertel 4422: background: $pgbg;
1.347 albertel 4423: }
1.422 albertel 4424: .LC_data_table_dense {
4425: font-size: small;
4426: }
1.507 raeburn 4427: table.LC_nested_outer {
4428: border: 1px solid #000000;
1.589 raeburn 4429: border-collapse: collapse;
1.507 raeburn 4430: border-spacing: 0px;
4431: width: 100%;
4432: }
4433: table.LC_nested {
4434: border: 0px;
1.589 raeburn 4435: border-collapse: collapse;
1.507 raeburn 4436: border-spacing: 0px;
4437: width: 100%;
4438: }
1.523 albertel 4439: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4440: table.LC_prior_tries tr th {
1.349 albertel 4441: font-weight: bold;
4442: background-color: $data_table_head;
1.421 albertel 4443: font-size: smaller;
1.347 albertel 4444: }
1.610 albertel 4445: table.LC_data_table tr.LC_odd_row > td,
1.440 albertel 4446: table.LC_aboutme_port tr td {
1.349 albertel 4447: background-color: $data_table_light;
1.425 albertel 4448: padding: 2px;
1.347 albertel 4449: }
1.610 albertel 4450: table.LC_data_table tr.LC_even_row > td,
1.440 albertel 4451: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4452: background-color: $data_table_dark;
1.347 albertel 4453: }
1.425 albertel 4454: table.LC_data_table tr.LC_data_table_highlight td {
4455: background-color: $data_table_darker;
4456: }
1.451 albertel 4457: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4458: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4459: background-color: #FFFFFF;
1.421 albertel 4460: font-weight: bold;
4461: font-style: italic;
4462: text-align: center;
4463: padding: 8px;
1.347 albertel 4464: }
1.507 raeburn 4465: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4466: padding: 4ex
4467: }
1.507 raeburn 4468: table.LC_nested_outer tr th {
4469: font-weight: bold;
4470: background-color: $data_table_head;
4471: font-size: smaller;
4472: border-bottom: 1px solid #000000;
4473: }
4474: table.LC_nested_outer tr td.LC_subheader {
4475: background-color: $data_table_head;
4476: font-weight: bold;
4477: font-size: small;
4478: border-bottom: 1px solid #000000;
4479: text-align: right;
1.451 albertel 4480: }
1.507 raeburn 4481: table.LC_nested tr.LC_info_row td {
1.451 albertel 4482: background-color: #CCC;
4483: font-weight: bold;
4484: font-size: small;
1.507 raeburn 4485: text-align: center;
4486: }
1.589 raeburn 4487: table.LC_nested tr.LC_info_row td.LC_left_item,
4488: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4489: text-align: left;
1.451 albertel 4490: }
1.507 raeburn 4491: table.LC_nested td {
1.451 albertel 4492: background-color: #FFF;
4493: font-size: small;
1.507 raeburn 4494: }
4495: table.LC_nested_outer tr th.LC_right_item,
4496: table.LC_nested tr.LC_info_row td.LC_right_item,
4497: table.LC_nested tr.LC_odd_row td.LC_right_item,
4498: table.LC_nested tr td.LC_right_item {
1.451 albertel 4499: text-align: right;
4500: }
4501:
1.507 raeburn 4502: table.LC_nested tr.LC_odd_row td {
1.451 albertel 4503: background-color: #EEE;
4504: }
4505:
1.473 raeburn 4506: table.LC_createuser {
4507: }
4508:
4509: table.LC_createuser tr.LC_section_row td {
4510: font-size: smaller;
4511: }
4512:
4513: table.LC_createuser tr.LC_info_row td {
4514: background-color: #CCC;
4515: font-weight: bold;
4516: text-align: center;
4517: }
4518:
1.349 albertel 4519: table.LC_calendar {
4520: border: 1px solid #000000;
4521: border-collapse: collapse;
4522: }
4523: table.LC_calendar_pickdate {
4524: font-size: xx-small;
4525: }
4526: table.LC_calendar tr td {
4527: border: 1px solid #000000;
4528: vertical-align: top;
4529: }
4530: table.LC_calendar tr td.LC_calendar_day_empty {
4531: background-color: $data_table_dark;
4532: }
4533: table.LC_calendar tr td.LC_calendar_day_current {
4534: background-color: $data_table_highlight;
4535: }
4536:
4537: table.LC_mail_list tr.LC_mail_new {
4538: background-color: $mail_new;
4539: }
4540: table.LC_mail_list tr.LC_mail_new:hover {
4541: background-color: $mail_new_hover;
4542: }
4543: table.LC_mail_list tr.LC_mail_read {
4544: background-color: $mail_read;
4545: }
4546: table.LC_mail_list tr.LC_mail_read:hover {
4547: background-color: $mail_read_hover;
4548: }
4549: table.LC_mail_list tr.LC_mail_replied {
4550: background-color: $mail_replied;
4551: }
4552: table.LC_mail_list tr.LC_mail_replied:hover {
4553: background-color: $mail_replied_hover;
4554: }
4555: table.LC_mail_list tr.LC_mail_other {
4556: background-color: $mail_other;
4557: }
4558: table.LC_mail_list tr.LC_mail_other:hover {
4559: background-color: $mail_other_hover;
4560: }
1.494 raeburn 4561: table.LC_mail_list tr.LC_mail_even {
4562: }
4563: table.LC_mail_list tr.LC_mail_odd {
4564: }
4565:
1.385 albertel 4566:
1.386 albertel 4567: table#LC_portfolio_actions {
4568: width: auto;
4569: background: $pgbg;
4570: border: 0px;
4571: border-spacing: 2px 2px;
4572: padding: 0px;
4573: margin: 0px;
4574: border-collapse: separate;
4575: }
4576: table#LC_portfolio_actions td.LC_label {
4577: background: $tabbg;
4578: text-align: right;
4579: }
4580: table#LC_portfolio_actions td.LC_value {
4581: background: $tabbg;
4582: }
1.385 albertel 4583:
1.391 albertel 4584: table#LC_cstr_controls {
4585: width: 100%;
4586: border-collapse: collapse;
4587: }
4588: table#LC_cstr_controls tr td {
4589: border: 4px solid $pgbg;
4590: padding: 4px;
4591: text-align: center;
4592: background: $tabbg;
4593: }
4594: table#LC_cstr_controls tr th {
4595: border: 4px solid $pgbg;
4596: background: $table_header;
4597: text-align: center;
4598: font-family: $sans;
4599: font-size: smaller;
4600: }
4601:
1.389 albertel 4602: table#LC_browser {
4603:
4604: }
4605: table#LC_browser tr th {
1.391 albertel 4606: background: $table_header;
1.389 albertel 4607: }
1.390 albertel 4608: table#LC_browser tr td {
4609: padding: 2px;
4610: }
1.389 albertel 4611: table#LC_browser tr.LC_browser_file,
4612: table#LC_browser tr.LC_browser_file_published {
4613: background: #CCFF88;
4614: }
4615: table#LC_browser tr.LC_browser_file_locked,
4616: table#LC_browser tr.LC_browser_file_unpublished {
4617: background: #FFAA99;
1.387 albertel 4618: }
1.389 albertel 4619: table#LC_browser tr.LC_browser_file_obsolete {
4620: background: #AAAAAA;
1.387 albertel 4621: }
1.455 albertel 4622: table#LC_browser tr.LC_browser_file_modified,
4623: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 4624: background: #FFFF77;
1.387 albertel 4625: }
1.389 albertel 4626: table#LC_browser tr.LC_browser_folder {
4627: background: #CCCCFF;
1.387 albertel 4628: }
1.388 albertel 4629: span.LC_current_location {
4630: font-size: x-large;
4631: background: $pgbg;
4632: }
1.387 albertel 4633:
1.395 albertel 4634: span.LC_parm_menu_item {
4635: font-size: larger;
4636: font-family: $sans;
4637: }
4638: span.LC_parm_scope_all {
4639: color: red;
4640: }
4641: span.LC_parm_scope_folder {
4642: color: green;
4643: }
4644: span.LC_parm_scope_resource {
4645: color: orange;
4646: }
4647: span.LC_parm_part {
4648: color: blue;
4649: }
4650: span.LC_parm_folder, span.LC_parm_symb {
4651: font-size: x-small;
4652: font-family: $mono;
4653: color: #AAAAAA;
4654: }
4655:
1.396 albertel 4656: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4657: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4658: border: 1px solid black;
4659: border-collapse: collapse;
4660: }
4661: table.LC_parm_overview_restrictions td {
4662: border-width: 1px 4px 1px 4px;
4663: border-style: solid;
4664: border-color: $pgbg;
4665: text-align: center;
4666: }
4667: table.LC_parm_overview_restrictions th {
4668: background: $tabbg;
4669: border-width: 1px 4px 1px 4px;
4670: border-style: solid;
4671: border-color: $pgbg;
4672: }
1.398 albertel 4673: table#LC_helpmenu {
4674: border: 0px;
4675: height: 55px;
4676: border-spacing: 0px;
4677: }
4678:
4679: table#LC_helpmenu fieldset legend {
4680: font-size: larger;
4681: font-weight: bold;
4682: }
1.397 albertel 4683: table#LC_helpmenu_links {
4684: width: 100%;
4685: border: 1px solid black;
4686: background: $pgbg;
4687: padding: 0px;
4688: border-spacing: 1px;
4689: }
4690: table#LC_helpmenu_links tr td {
4691: padding: 1px;
4692: background: $tabbg;
1.399 albertel 4693: text-align: center;
4694: font-weight: bold;
1.397 albertel 4695: }
1.396 albertel 4696:
1.397 albertel 4697: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
4698: table#LC_helpmenu_links a:active {
4699: text-decoration: none;
4700: color: $font;
4701: }
4702: table#LC_helpmenu_links a:hover {
4703: text-decoration: underline;
4704: color: $vlink;
4705: }
1.396 albertel 4706:
1.417 albertel 4707: .LC_chrt_popup_exists {
4708: border: 1px solid #339933;
4709: margin: -1px;
4710: }
4711: .LC_chrt_popup_up {
4712: border: 1px solid yellow;
4713: margin: -1px;
4714: }
4715: .LC_chrt_popup {
4716: border: 1px solid #8888FF;
4717: background: #CCCCFF;
4718: }
1.421 albertel 4719: table.LC_pick_box {
4720: border-collapse: separate;
4721: background: white;
4722: border: 1px solid black;
4723: border-spacing: 1px;
4724: }
4725: table.LC_pick_box td.LC_pick_box_title {
4726: background: $tabbg;
4727: font-weight: bold;
4728: text-align: right;
4729: width: 184px;
4730: padding: 8px;
4731: }
1.579 raeburn 4732: table.LC_pick_box td.LC_pick_box_value {
4733: text-align: left;
4734: padding: 8px;
4735: }
4736: table.LC_pick_box td.LC_pick_box_select {
4737: text-align: left;
4738: padding: 8px;
4739: }
1.424 albertel 4740: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 4741: padding: 0px;
4742: height: 1px;
4743: background: black;
4744: }
4745: table.LC_pick_box td.LC_pick_box_submit {
4746: text-align: right;
4747: }
1.579 raeburn 4748: table.LC_pick_box td.LC_evenrow_value {
4749: text-align: left;
4750: padding: 8px;
4751: background-color: $data_table_light;
4752: }
4753: table.LC_pick_box td.LC_oddrow_value {
4754: text-align: left;
4755: padding: 8px;
4756: background-color: $data_table_light;
4757: }
4758: table.LC_helpform_receipt {
4759: width: 620px;
4760: border-collapse: separate;
4761: background: white;
4762: border: 1px solid black;
4763: border-spacing: 1px;
4764: }
4765: table.LC_helpform_receipt td.LC_pick_box_title {
4766: background: $tabbg;
4767: font-weight: bold;
4768: text-align: right;
4769: width: 184px;
4770: padding: 8px;
4771: }
4772: table.LC_helpform_receipt td.LC_evenrow_value {
4773: text-align: left;
4774: padding: 8px;
4775: background-color: $data_table_light;
4776: }
4777: table.LC_helpform_receipt td.LC_oddrow_value {
4778: text-align: left;
4779: padding: 8px;
4780: background-color: $data_table_light;
4781: }
4782: table.LC_helpform_receipt td.LC_pick_box_separator {
4783: padding: 0px;
4784: height: 1px;
4785: background: black;
4786: }
4787: span.LC_helpform_receipt_cat {
4788: font-weight: bold;
4789: }
1.424 albertel 4790: table.LC_group_priv_box {
4791: background: white;
4792: border: 1px solid black;
4793: border-spacing: 1px;
4794: }
4795: table.LC_group_priv_box td.LC_pick_box_title {
4796: background: $tabbg;
4797: font-weight: bold;
4798: text-align: right;
4799: width: 184px;
4800: }
4801: table.LC_group_priv_box td.LC_groups_fixed {
4802: background: $data_table_light;
4803: text-align: center;
4804: }
4805: table.LC_group_priv_box td.LC_groups_optional {
4806: background: $data_table_dark;
4807: text-align: center;
4808: }
4809: table.LC_group_priv_box td.LC_groups_functionality {
4810: background: $data_table_darker;
4811: text-align: center;
4812: font-weight: bold;
4813: }
4814: table.LC_group_priv td {
4815: text-align: left;
4816: padding: 0px;
4817: }
4818:
1.421 albertel 4819: table.LC_notify_front_page {
4820: background: white;
4821: border: 1px solid black;
4822: padding: 8px;
4823: }
4824: table.LC_notify_front_page td {
4825: padding: 8px;
4826: }
1.424 albertel 4827: .LC_navbuttons {
4828: margin: 2ex 0ex 2ex 0ex;
4829: }
1.423 albertel 4830: .LC_topic_bar {
4831: font-family: $sans;
4832: font-weight: bold;
4833: width: 100%;
4834: background: $tabbg;
4835: vertical-align: middle;
4836: margin: 2ex 0ex 2ex 0ex;
4837: }
4838: .LC_topic_bar span {
4839: vertical-align: middle;
4840: }
4841: .LC_topic_bar img {
4842: vertical-align: bottom;
4843: }
4844: table.LC_course_group_status {
4845: margin: 20px;
4846: }
4847: table.LC_status_selector td {
4848: vertical-align: top;
4849: text-align: center;
1.424 albertel 4850: padding: 4px;
4851: }
4852: table.LC_descriptive_input td.LC_description {
4853: vertical-align: top;
4854: text-align: right;
4855: font-weight: bold;
1.423 albertel 4856: }
1.599 albertel 4857: div.LC_feedback_link {
1.616 albertel 4858: clear: both;
1.599 albertel 4859: background: white;
4860: width: 100%;
1.489 raeburn 4861: }
4862: span.LC_feedback_link {
1.599 albertel 4863: background: $feedback_link_bg;
4864: font-size: larger;
4865: }
4866: span.LC_message_link {
4867: background: $feedback_link_bg;
4868: font-size: larger;
4869: position: absolute;
4870: right: 1em;
1.489 raeburn 4871: }
1.421 albertel 4872:
1.515 albertel 4873: table.LC_prior_tries {
1.524 albertel 4874: border: 1px solid #000000;
4875: border-collapse: separate;
4876: border-spacing: 1px;
1.515 albertel 4877: }
1.523 albertel 4878:
1.515 albertel 4879: table.LC_prior_tries td {
1.524 albertel 4880: padding: 2px;
1.515 albertel 4881: }
1.523 albertel 4882:
4883: .LC_answer_correct {
4884: background: #AAFFAA;
4885: color: black;
4886: }
4887: .LC_answer_charged_try {
4888: background: #FFAAAA ! important;
4889: color: black;
4890: }
4891: .LC_answer_not_charged_try,
4892: .LC_answer_no_grade,
4893: .LC_answer_late {
4894: background: #FFFFAA;
4895: color: black;
4896: }
4897: .LC_answer_previous {
4898: background: #AAAAFF;
4899: color: black;
4900: }
4901: .LC_answer_no_message {
4902: background: #FFFFFF;
4903: color: black;
4904: }
4905: .LC_answer_unknown {
4906: background: orange;
4907: color: black;
4908: }
4909:
4910:
1.529 albertel 4911: span.LC_prior_numerical,
4912: span.LC_prior_string,
4913: span.LC_prior_custom,
4914: span.LC_prior_reaction,
4915: span.LC_prior_math {
1.523 albertel 4916: font-family: monospace;
4917: white-space: pre;
4918: }
4919:
1.525 albertel 4920: span.LC_prior_string {
4921: font-family: monospace;
4922: white-space: pre;
4923: }
4924:
1.523 albertel 4925: table.LC_prior_option {
4926: width: 100%;
4927: border-collapse: collapse;
4928: }
1.528 albertel 4929: table.LC_prior_rank, table.LC_prior_match {
4930: border-collapse: collapse;
4931: }
4932: table.LC_prior_option tr td,
4933: table.LC_prior_rank tr td,
4934: table.LC_prior_match tr td {
1.524 albertel 4935: border: 1px solid #000000;
1.515 albertel 4936: }
4937:
1.519 raeburn 4938: span.LC_nobreak {
1.544 albertel 4939: white-space: nowrap;
1.519 raeburn 4940: }
4941:
1.576 raeburn 4942: span.LC_cusr_emph {
4943: font-style: italic;
4944: }
4945:
1.545 albertel 4946: table.LC_docs_documents {
4947: background: #BBBBBB;
1.547 albertel 4948: border-width: 0px;
1.545 albertel 4949: border-collapse: collapse;
4950: }
4951:
4952: table.LC_docs_documents td.LC_docs_document {
4953: border: 2px solid black;
4954: padding: 4px;
4955: }
4956:
4957: .LC_docs_course_commands div {
4958: float: left;
4959: border: 4px solid #AAAAAA;
4960: padding: 4px;
4961: background: #DDDDCC;
4962: }
4963:
4964: .LC_docs_entry_move {
4965: border: 0px;
4966: border-collapse: collapse;
1.544 albertel 4967: }
4968:
1.545 albertel 4969: .LC_docs_entry_move td {
4970: border: 2px solid #BBBBBB;
4971: background: #DDDDDD;
4972: }
4973:
4974: .LC_docs_editor td.LC_docs_entry_commands {
4975: background: #DDDDDD;
4976: font-size: x-small;
4977: }
1.544 albertel 4978: .LC_docs_copy {
1.545 albertel 4979: color: #000099;
1.544 albertel 4980: }
4981: .LC_docs_cut {
1.545 albertel 4982: color: #550044;
1.544 albertel 4983: }
4984: .LC_docs_rename {
1.545 albertel 4985: color: #009900;
1.544 albertel 4986: }
4987: .LC_docs_remove {
1.545 albertel 4988: color: #990000;
4989: }
4990:
1.547 albertel 4991: .LC_docs_reinit_warn,
4992: .LC_docs_ext_edit {
4993: font-size: x-small;
4994: }
4995:
1.545 albertel 4996: .LC_docs_editor td.LC_docs_entry_title,
4997: .LC_docs_editor td.LC_docs_entry_icon {
4998: background: #FFFFBB;
4999: }
5000: .LC_docs_editor td.LC_docs_entry_parameter {
5001: background: #BBBBFF;
5002: font-size: x-small;
5003: white-space: nowrap;
5004: }
5005:
5006: table.LC_docs_adddocs td,
5007: table.LC_docs_adddocs th {
5008: border: 1px solid #BBBBBB;
5009: padding: 4px;
5010: background: #DDDDDD;
1.543 albertel 5011: }
5012:
1.584 albertel 5013: table.LC_sty_begin {
5014: background: #BBFFBB;
5015: }
5016: table.LC_sty_end {
5017: background: #FFBBBB;
5018: }
5019:
1.589 raeburn 5020: table.LC_double_column {
5021: border-width: 0px;
5022: border-collapse: collapse;
5023: width: 100%;
5024: padding: 2px;
5025: }
5026:
5027: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5028: top: 2px;
1.589 raeburn 5029: left: 2px;
5030: width: 47%;
5031: vertical-align: top;
5032: }
5033:
5034: table.LC_double_column tr td.LC_right_col {
5035: top: 2px;
5036: right: 2px;
5037: width: 47%;
5038: vertical-align: top;
5039: }
5040:
1.594 raeburn 5041: span.LC_role_level {
5042: font-weight: bold;
5043: }
5044:
1.591 raeburn 5045: div.LC_left_float {
5046: float: left;
5047: padding-right: 5%;
1.597 albertel 5048: padding-bottom: 4px;
1.591 raeburn 5049: }
5050:
5051: div.LC_clear_float_header {
1.597 albertel 5052: padding-bottom: 2px;
1.591 raeburn 5053: }
5054:
5055: div.LC_clear_float_footer {
1.597 albertel 5056: padding-top: 10px;
1.591 raeburn 5057: clear: both;
5058: }
5059:
1.597 albertel 5060:
1.601 albertel 5061: div.LC_grade_select_mode {
1.604 albertel 5062: font-family: $sans;
1.601 albertel 5063: }
5064: div.LC_grade_select_mode div div {
5065: margin: 5px;
5066: }
5067: div.LC_grade_select_mode_selector {
5068: margin: 5px;
5069: float: left;
5070: }
5071: div.LC_grade_select_mode_selector_header {
5072: font: bold medium $sans;
5073: }
5074: div.LC_grade_select_mode_type {
5075: clear: left;
5076: }
5077:
1.597 albertel 5078: div.LC_grade_show_user {
5079: margin-top: 20px;
5080: border: 1px solid black;
5081: }
5082: div.LC_grade_user_name {
5083: background: #DDDDEE;
5084: border-bottom: 1px solid black;
5085: font: bold large $sans;
5086: }
5087: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5088: background: #DDEEDD;
5089: }
5090:
5091: div.LC_grade_show_problem,
5092: div.LC_grade_submissions,
5093: div.LC_grade_message_center,
5094: div.LC_grade_info_links,
5095: div.LC_grade_assign {
5096: margin: 5px;
5097: width: 99%;
5098: background: #FFFFFF;
5099: }
5100: div.LC_grade_show_problem_header,
5101: div.LC_grade_submissions_header,
5102: div.LC_grade_message_center_header,
5103: div.LC_grade_assign_header {
5104: font: bold large $sans;
5105: }
5106: div.LC_grade_show_problem_problem,
5107: div.LC_grade_submissions_body,
5108: div.LC_grade_message_center_body,
5109: div.LC_grade_assign_body {
5110: border: 1px solid black;
5111: width: 99%;
5112: background: #FFFFFF;
5113: }
1.598 albertel 5114: span.LC_grade_check_note {
5115: font: normal medium $sans;
5116: display: inline;
5117: position: absolute;
5118: right: 1em;
5119: }
1.597 albertel 5120:
1.613 albertel 5121: table.LC_scantron_action {
5122: width: 100%;
5123: }
5124: table.LC_scantron_action tr th {
5125: font: normal bold $sans;
5126: }
1.600 albertel 5127:
1.614 albertel 5128: div.LC_edit_problem_header,
5129: div.LC_edit_problem_footer {
1.600 albertel 5130: font: normal medium $sans;
1.602 albertel 5131: margin: 2px;
1.600 albertel 5132: }
5133: div.LC_edit_problem_header,
1.602 albertel 5134: div.LC_edit_problem_header div,
1.614 albertel 5135: div.LC_edit_problem_footer,
5136: div.LC_edit_problem_footer div,
1.602 albertel 5137: div.LC_edit_problem_editxml_header,
5138: div.LC_edit_problem_editxml_header div {
1.600 albertel 5139: margin-top: 5px;
5140: }
1.602 albertel 5141: div.LC_edit_problem_header_edit_row {
5142: background: $tabbg;
5143: padding: 3px;
5144: margin-bottom: 5px;
5145: }
1.600 albertel 5146: div.LC_edit_problem_header_title {
1.602 albertel 5147: font: larger bold $sans;
5148: background: $tabbg;
5149: padding: 3px;
5150: }
5151: table.LC_edit_problem_header_title {
5152: font: larger bold $sans;
5153: width: 100%;
5154: border-color: $pgbg;
5155: border-style: solid;
5156: border-width: $border;
5157:
1.600 albertel 5158: background: $tabbg;
1.602 albertel 5159: border-collapse: collapse;
5160: padding: 0px
5161: }
5162:
5163: div.LC_edit_problem_discards {
5164: float: left;
5165: padding-bottom: 5px;
5166: }
5167: div.LC_edit_problem_saves {
5168: float: right;
5169: padding-bottom: 5px;
1.600 albertel 5170: }
5171: hr.LC_edit_problem_divide {
1.602 albertel 5172: clear: both;
1.600 albertel 5173: color: $tabbg;
5174: background-color: $tabbg;
5175: height: 3px;
5176: border: 0px;
5177: }
1.343 albertel 5178: END
5179: }
5180:
1.306 albertel 5181: =pod
5182:
5183: =item * &headtag()
5184:
5185: Returns a uniform footer for LON-CAPA web pages.
5186:
1.307 albertel 5187: Inputs: $title - optional title for the head
5188: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5189: $args - optional arguments
1.319 albertel 5190: force_register - if is true call registerurl so the remote is
5191: informed
1.415 albertel 5192: redirect -> array ref of
5193: 1- seconds before redirect occurs
5194: 2- url to redirect to
5195: 3- whether the side effect should occur
1.315 albertel 5196: (side effect of setting
5197: $env{'internal.head.redirect'} to the url
5198: redirected too)
1.352 albertel 5199: domain -> force to color decorate a page for a specific
5200: domain
5201: function -> force usage of a specific rolish color scheme
5202: bgcolor -> override the default page bgcolor
1.460 albertel 5203: no_auto_mt_title
5204: -> prevent &mt()ing the title arg
1.464 albertel 5205:
1.306 albertel 5206: =cut
5207:
5208: sub headtag {
1.313 albertel 5209: my ($title,$head_extra,$args) = @_;
1.306 albertel 5210:
1.363 albertel 5211: my $function = $args->{'function'} || &get_users_function();
5212: my $domain = $args->{'domain'} || &determinedomain();
5213: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5214: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5215: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5216: #time(),
1.418 albertel 5217: $env{'environment.color.timestamp'},
1.363 albertel 5218: $function,$domain,$bgcolor);
5219:
1.369 www 5220: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5221:
1.308 albertel 5222: my $result =
5223: '<head>'.
1.461 albertel 5224: &font_settings();
1.319 albertel 5225:
1.461 albertel 5226: if (!$args->{'frameset'}) {
5227: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5228: }
1.319 albertel 5229: if ($args->{'force_register'}) {
5230: $result .= &Apache::lonmenu::registerurl(1);
5231: }
1.436 albertel 5232: if (!$args->{'no_nav_bar'}
5233: && !$args->{'only_body'}
5234: && !$args->{'frameset'}) {
5235: $result .= &help_menu_js();
5236: }
1.319 albertel 5237:
1.314 albertel 5238: if (ref($args->{'redirect'})) {
1.414 albertel 5239: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5240: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5241: if (!$inhibit_continue) {
5242: $env{'internal.head.redirect'} = $url;
5243: }
1.313 albertel 5244: $result.=<<ADDMETA
5245: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5246: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5247: ADDMETA
5248: }
1.306 albertel 5249: if (!defined($title)) {
5250: $title = 'The LearningOnline Network with CAPA';
5251: }
1.460 albertel 5252: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5253: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5254: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5255: .$head_extra;
1.306 albertel 5256: return $result;
5257: }
5258:
5259: =pod
5260:
1.340 albertel 5261: =item * &font_settings()
5262:
5263: Returns neccessary <meta> to set the proper encoding
5264:
5265: Inputs: none
5266:
5267: =cut
5268:
5269: sub font_settings {
5270: my $headerstring='';
5271: if (($env{'browser.os'} eq 'mac') && (!$env{'browser.mathml'})) {
5272: $headerstring.=
5273: '<meta Content-Type="text/html; charset=x-mac-roman" />';
5274: } elsif (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
5275: $headerstring.=
5276: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5277: }
5278: return $headerstring;
5279: }
5280:
1.341 albertel 5281: =pod
5282:
5283: =item * &xml_begin()
5284:
5285: Returns the needed doctype and <html>
5286:
5287: Inputs: none
5288:
5289: =cut
5290:
5291: sub xml_begin {
5292: my $output='';
5293:
1.592 albertel 5294: if ($env{'internal.start_page'}==1) {
5295: &Apache::lonhtmlcommon::init_htmlareafields();
5296: }
1.342 albertel 5297:
1.341 albertel 5298: if ($env{'browser.mathml'}) {
5299: $output='<?xml version="1.0"?>'
5300: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5301: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5302:
5303: # .'<!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">] >'
5304: .'<!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">'
5305: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5306: .'xmlns="http://www.w3.org/1999/xhtml">';
5307: } else {
5308: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5309: }
5310: return $output;
5311: }
1.340 albertel 5312:
5313: =pod
5314:
1.306 albertel 5315: =item * &endheadtag()
5316:
5317: Returns a uniform </head> for LON-CAPA web pages.
5318:
5319: Inputs: none
5320:
5321: =cut
5322:
5323: sub endheadtag {
5324: return '</head>';
5325: }
5326:
5327: =pod
5328:
5329: =item * &head()
5330:
5331: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5332:
5333: Inputs: $title - optional title for the page
1.307 albertel 5334: $head_extra - optional extra HTML to put inside the <head>
1.405 albertel 5335:
1.306 albertel 5336: =cut
5337:
5338: sub head {
1.325 albertel 5339: my ($title,$head_extra,$args) = @_;
5340: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 5341: }
5342:
5343: =pod
5344:
5345: =item * &start_page()
5346:
5347: Returns a complete <html> .. <body> section for LON-CAPA web pages.
5348:
5349: Inputs: $title - optional title for the page
5350: $head_extra - optional extra HTML to incude inside the <head>
1.315 albertel 5351: $args - additional optional args supported are:
1.317 albertel 5352: only_body -> is true will set &bodytag() onlybodytag
5353: arg on
5354: no_nav_bar -> is true will set &bodytag() notopbar arg on
5355: add_entries -> additional attributes to add to the <body>
5356: domain -> force to color decorate a page for a
5357: specific domain
5358: function -> force usage of a specific rolish color
5359: scheme
5360: redirect -> see &headtag()
5361: bgcolor -> override the default page bg color
5362: js_ready -> return a string ready for being used in
5363: a javascript writeln
1.320 albertel 5364: html_encode -> return a string ready for being used in
5365: a html attribute
1.317 albertel 5366: force_register -> if is true will turn on the &bodytag()
5367: $forcereg arg
1.326 albertel 5368: body_title -> alternate text to use instead of $title
5369: in the title box that appears, this text
5370: is not auto translated like the $title is
1.330 albertel 5371: frameset -> if true will start with a <frameset>
5372: rather than <body>
1.338 albertel 5373: no_title -> if true the title bar won't be shown
5374: skip_phases -> hash ref of
5375: head -> skip the <html><head> generation
5376: body -> skip all <body> generation
1.337 albertel 5377:
1.361 albertel 5378: no_inline_link -> if true and in remote mode, don't show the
5379: 'Switch To Inline Menu' link
5380:
1.460 albertel 5381: no_auto_mt_title -> prevent &mt()ing the title arg
5382:
1.562 albertel 5383: inherit_jsmath -> when creating popup window in a page,
5384: should it have jsmath forced on by the
5385: current page
5386:
1.306 albertel 5387: =cut
5388:
5389: sub start_page {
1.309 albertel 5390: my ($title,$head_extra,$args) = @_;
1.318 albertel 5391: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 5392: my %head_args;
1.352 albertel 5393: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 5394: 'bgcolor','frameset','no_nav_bar','only_body',
5395: 'no_auto_mt_title') {
1.319 albertel 5396: if (defined($args->{$arg})) {
1.324 raeburn 5397: $head_args{$arg} = $args->{$arg};
1.319 albertel 5398: }
1.313 albertel 5399: }
1.319 albertel 5400:
1.315 albertel 5401: $env{'internal.start_page'}++;
1.338 albertel 5402: my $result;
5403: if (! exists($args->{'skip_phases'}{'head'}) ) {
5404: $result.=
1.341 albertel 5405: &xml_begin().
1.338 albertel 5406: &headtag($title,$head_extra,\%head_args).&endheadtag();
5407: }
5408:
5409: if (! exists($args->{'skip_phases'}{'body'}) ) {
5410: if ($args->{'frameset'}) {
5411: my $attr_string = &make_attr_string($args->{'force_register'},
5412: $args->{'add_entries'});
5413: $result .= "\n<frameset $attr_string>\n";
5414: } else {
5415: $result .=
5416: &bodytag($title,
5417: $args->{'function'}, $args->{'add_entries'},
5418: $args->{'only_body'}, $args->{'domain'},
5419: $args->{'force_register'}, $args->{'body_title'},
5420: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 5421: $args->{'no_title'}, $args->{'no_inline_link'},
5422: $args);
1.338 albertel 5423: }
1.330 albertel 5424: }
1.338 albertel 5425:
1.315 albertel 5426: if ($args->{'js_ready'}) {
1.317 albertel 5427: $result = &js_ready($result);
1.315 albertel 5428: }
1.320 albertel 5429: if ($args->{'html_encode'}) {
5430: $result = &html_encode($result);
5431: }
1.315 albertel 5432: return $result;
1.306 albertel 5433: }
5434:
1.330 albertel 5435:
1.306 albertel 5436: =pod
5437:
5438: =item * &head()
5439:
5440: Returns a complete </body></html> section for LON-CAPA web pages.
5441:
1.315 albertel 5442: Inputs: $args - additional optional args supported are:
5443: js_ready -> return a string ready for being used in
5444: a javascript writeln
1.320 albertel 5445: html_encode -> return a string ready for being used in
5446: a html attribute
1.330 albertel 5447: frameset -> if true will start with a <frameset>
5448: rather than <body>
1.493 albertel 5449: dicsussion -> if true will get discussion from
5450: lonxml::xmlend
5451: (you can pass the target and parser arguments
5452: through optional 'target' and 'parser' args
5453: to this routine)
1.306 albertel 5454:
5455: =cut
5456:
5457: sub end_page {
1.315 albertel 5458: my ($args) = @_;
5459: $env{'internal.end_page'}++;
1.330 albertel 5460: my $result;
1.335 albertel 5461: if ($args->{'discussion'}) {
5462: my ($target,$parser);
5463: if (ref($args->{'discussion'})) {
5464: ($target,$parser) =($args->{'discussion'}{'target'},
5465: $args->{'discussion'}{'parser'});
5466: }
5467: $result .= &Apache::lonxml::xmlend($target,$parser);
5468: }
5469:
1.330 albertel 5470: if ($args->{'frameset'}) {
5471: $result .= '</frameset>';
5472: } else {
5473: $result .= &endbodytag();
5474: }
5475: $result .= "\n</html>";
5476:
1.315 albertel 5477: if ($args->{'js_ready'}) {
1.317 albertel 5478: $result = &js_ready($result);
1.315 albertel 5479: }
1.335 albertel 5480:
1.320 albertel 5481: if ($args->{'html_encode'}) {
5482: $result = &html_encode($result);
5483: }
1.335 albertel 5484:
1.315 albertel 5485: return $result;
5486: }
5487:
1.320 albertel 5488: sub html_encode {
5489: my ($result) = @_;
5490:
1.322 albertel 5491: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 5492:
5493: return $result;
5494: }
1.317 albertel 5495: sub js_ready {
5496: my ($result) = @_;
5497:
1.323 albertel 5498: $result =~ s/[\n\r]/ /xmsg;
5499: $result =~ s/\\/\\\\/xmsg;
5500: $result =~ s/'/\\'/xmsg;
1.372 albertel 5501: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 5502:
5503: return $result;
5504: }
5505:
1.315 albertel 5506: sub validate_page {
5507: if ( exists($env{'internal.start_page'})
1.316 albertel 5508: && $env{'internal.start_page'} > 1) {
5509: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 5510: $env{'internal.start_page'}.' '.
1.316 albertel 5511: $ENV{'request.filename'});
1.315 albertel 5512: }
5513: if ( exists($env{'internal.end_page'})
1.316 albertel 5514: && $env{'internal.end_page'} > 1) {
5515: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 5516: $env{'internal.end_page'}.' '.
1.316 albertel 5517: $env{'request.filename'});
1.315 albertel 5518: }
5519: if ( exists($env{'internal.start_page'})
5520: && ! exists($env{'internal.end_page'})) {
1.316 albertel 5521: &Apache::lonnet::logthis('start_page called without end_page '.
5522: $env{'request.filename'});
1.315 albertel 5523: }
5524: if ( ! exists($env{'internal.start_page'})
5525: && exists($env{'internal.end_page'})) {
1.316 albertel 5526: &Apache::lonnet::logthis('end_page called without start_page'.
5527: $env{'request.filename'});
1.315 albertel 5528: }
1.306 albertel 5529: }
1.315 albertel 5530:
1.318 albertel 5531: sub simple_error_page {
5532: my ($r,$title,$msg) = @_;
5533: my $page =
5534: &Apache::loncommon::start_page($title).
5535: &mt($msg).
5536: &Apache::loncommon::end_page();
5537: if (ref($r)) {
5538: $r->print($page);
1.327 albertel 5539: return;
1.318 albertel 5540: }
5541: return $page;
5542: }
1.347 albertel 5543:
5544: {
1.610 albertel 5545: my @row_count;
1.347 albertel 5546: sub start_data_table {
1.422 albertel 5547: my ($add_class) = @_;
5548: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 5549: unshift(@row_count,0);
1.422 albertel 5550: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 5551: }
5552:
5553: sub end_data_table {
1.610 albertel 5554: shift(@row_count);
1.389 albertel 5555: return '</table>'."\n";;
1.347 albertel 5556: }
5557:
5558: sub start_data_table_row {
1.422 albertel 5559: my ($add_class) = @_;
1.610 albertel 5560: $row_count[0]++;
5561: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 5562: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 5563: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 5564: }
1.471 banghart 5565:
5566: sub continue_data_table_row {
5567: my ($add_class) = @_;
1.610 albertel 5568: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 5569: $css_class = (join(' ',$css_class,$add_class));
5570: return '<tr class="'.$css_class.'">'."\n";;
5571: }
1.347 albertel 5572:
5573: sub end_data_table_row {
1.389 albertel 5574: return '</tr>'."\n";;
1.347 albertel 5575: }
1.367 www 5576:
1.421 albertel 5577: sub start_data_table_empty_row {
1.610 albertel 5578: $row_count[0]++;
1.421 albertel 5579: return '<tr class="LC_empty_row" >'."\n";;
5580: }
5581:
5582: sub end_data_table_empty_row {
5583: return '</tr>'."\n";;
5584: }
5585:
1.367 www 5586: sub start_data_table_header_row {
1.389 albertel 5587: return '<tr class="LC_header_row">'."\n";;
1.367 www 5588: }
5589:
5590: sub end_data_table_header_row {
1.389 albertel 5591: return '</tr>'."\n";;
1.367 www 5592: }
1.347 albertel 5593: }
5594:
1.548 albertel 5595: =pod
5596:
5597: =item * &inhibit_menu_check($arg)
5598:
5599: Checks for a inhibitmenu state and generates output to preserve it
5600:
5601: Inputs: $arg - can be any of
5602: - undef - in which case the return value is a string
5603: to add into arguments list of a uri
5604: - 'input' - in which case the return value is a HTML
5605: <form> <input> field of type hidden to
5606: preserve the value
5607: - a url - in which case the return value is the url with
5608: the neccesary cgi args added to preserve the
5609: inhibitmenu state
5610: - a ref to a url - no return value, but the string is
5611: updated to include the neccessary cgi
5612: args to preserve the inhibitmenu state
5613:
5614: =cut
5615:
5616: sub inhibit_menu_check {
5617: my ($arg) = @_;
5618: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5619: if ($arg eq 'input') {
5620: if ($env{'form.inhibitmenu'}) {
5621: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
5622: } else {
5623: return
5624: }
5625: }
5626: if ($env{'form.inhibitmenu'}) {
5627: if (ref($arg)) {
5628: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5629: } elsif ($arg eq '') {
5630: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
5631: } else {
5632: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5633: }
5634: }
5635: if (!ref($arg)) {
5636: return $arg;
5637: }
5638: }
5639:
1.251 albertel 5640: ###############################################
1.182 matthew 5641:
5642: =pod
5643:
1.549 albertel 5644: =back
5645:
5646: =head1 User Information Routines
5647:
5648: =over 4
5649:
1.405 albertel 5650: =item * &get_users_function()
1.182 matthew 5651:
5652: Used by &bodytag to determine the current users primary role.
5653: Returns either 'student','coordinator','admin', or 'author'.
5654:
5655: =cut
5656:
5657: ###############################################
5658: sub get_users_function {
5659: my $function = 'student';
1.258 albertel 5660: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 5661: $function='coordinator';
5662: }
1.258 albertel 5663: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 5664: $function='admin';
5665: }
1.258 albertel 5666: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 5667: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
5668: $function='author';
5669: }
5670: return $function;
1.54 www 5671: }
1.99 www 5672:
5673: ###############################################
5674:
1.233 raeburn 5675: =pod
5676:
1.542 raeburn 5677: =item * &check_user_status()
1.274 raeburn 5678:
5679: Determines current status of supplied role for a
5680: specific user. Roles can be active, previous or future.
5681:
5682: Inputs:
5683: user's domain, user's username, course's domain,
1.375 raeburn 5684: course's number, optional section ID.
1.274 raeburn 5685:
5686: Outputs:
5687: role status: active, previous or future.
5688:
5689: =cut
5690:
5691: sub check_user_status {
1.412 raeburn 5692: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 5693: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
5694: my @uroles = keys %userinfo;
5695: my $srchstr;
5696: my $active_chk = 'none';
1.412 raeburn 5697: my $now = time;
1.274 raeburn 5698: if (@uroles > 0) {
1.412 raeburn 5699: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 5700: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
5701: } else {
1.412 raeburn 5702: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
5703: }
5704: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 5705: my $role_end = 0;
5706: my $role_start = 0;
5707: $active_chk = 'active';
1.412 raeburn 5708: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
5709: $role_end = $1;
5710: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
5711: $role_start = $1;
1.274 raeburn 5712: }
5713: }
5714: if ($role_start > 0) {
1.412 raeburn 5715: if ($now < $role_start) {
1.274 raeburn 5716: $active_chk = 'future';
5717: }
5718: }
5719: if ($role_end > 0) {
1.412 raeburn 5720: if ($now > $role_end) {
1.274 raeburn 5721: $active_chk = 'previous';
5722: }
5723: }
5724: }
5725: }
5726: return $active_chk;
5727: }
5728:
5729: ###############################################
5730:
5731: =pod
5732:
1.405 albertel 5733: =item * &get_sections()
1.233 raeburn 5734:
5735: Determines all the sections for a course including
5736: sections with students and sections containing other roles.
1.419 raeburn 5737: Incoming parameters:
5738:
5739: 1. domain
5740: 2. course number
5741: 3. reference to array containing roles for which sections should
5742: be gathered (optional).
5743: 4. reference to array containing status types for which sections
5744: should be gathered (optional).
5745:
5746: If the third argument is undefined, sections are gathered for any role.
5747: If the fourth argument is undefined, sections are gathered for any status.
5748: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 5749:
1.374 raeburn 5750: Returns section hash (keys are section IDs, values are
5751: number of users in each section), subject to the
1.419 raeburn 5752: optional roles filter, optional status filter
1.233 raeburn 5753:
5754: =cut
5755:
5756: ###############################################
5757: sub get_sections {
1.419 raeburn 5758: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 5759: if (!defined($cdom) || !defined($cnum)) {
5760: my $cid = $env{'request.course.id'};
5761:
5762: return if (!defined($cid));
5763:
5764: $cdom = $env{'course.'.$cid.'.domain'};
5765: $cnum = $env{'course.'.$cid.'.num'};
5766: }
5767:
5768: my %sectioncount;
1.419 raeburn 5769: my $now = time;
1.240 albertel 5770:
1.366 albertel 5771: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 5772: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 5773: my $sec_index = &Apache::loncoursedata::CL_SECTION();
5774: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 5775: my $start_index = &Apache::loncoursedata::CL_START();
5776: my $end_index = &Apache::loncoursedata::CL_END();
5777: my $status;
1.366 albertel 5778: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 5779: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
5780: $data->[$status_index],
5781: $data->[$start_index],
5782: $data->[$end_index]);
5783: if ($stu_status eq 'Active') {
5784: $status = 'active';
5785: } elsif ($end < $now) {
5786: $status = 'previous';
5787: } elsif ($start > $now) {
5788: $status = 'future';
5789: }
5790: if ($section ne '-1' && $section !~ /^\s*$/) {
5791: if ((!defined($possible_status)) || (($status ne '') &&
5792: (grep/^\Q$status\E$/,@{$possible_status}))) {
5793: $sectioncount{$section}++;
5794: }
1.240 albertel 5795: }
5796: }
5797: }
5798: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
5799: foreach my $user (sort(keys(%courseroles))) {
5800: if ($user !~ /^(\w{2})/) { next; }
5801: my ($role) = ($user =~ /^(\w{2})/);
5802: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 5803: my ($section,$status);
1.240 albertel 5804: if ($role eq 'cr' &&
5805: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
5806: $section=$1;
5807: }
5808: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
5809: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 5810: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
5811: if ($end == -1 && $start == -1) {
5812: next; #deleted role
5813: }
5814: if (!defined($possible_status)) {
5815: $sectioncount{$section}++;
5816: } else {
5817: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
5818: $status = 'active';
5819: } elsif ($end < $now) {
5820: $status = 'future';
5821: } elsif ($start > $now) {
5822: $status = 'previous';
5823: }
5824: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
5825: $sectioncount{$section}++;
5826: }
5827: }
1.233 raeburn 5828: }
1.366 albertel 5829: return %sectioncount;
1.233 raeburn 5830: }
5831:
1.274 raeburn 5832: ###############################################
1.294 raeburn 5833:
5834: =pod
1.405 albertel 5835:
5836: =item * &get_course_users()
5837:
1.275 raeburn 5838: Retrieves usernames:domains for users in the specified course
5839: with specific role(s), and access status.
5840:
5841: Incoming parameters:
1.277 albertel 5842: 1. course domain
5843: 2. course number
5844: 3. access status: users must have - either active,
1.275 raeburn 5845: previous, future, or all.
1.277 albertel 5846: 4. reference to array of permissible roles
1.288 raeburn 5847: 5. reference to array of section restrictions (optional)
5848: 6. reference to results object (hash of hashes).
5849: 7. reference to optional userdata hash
1.609 raeburn 5850: 8. reference to optional statushash
5851: Keys of top level results hash are roles.
1.275 raeburn 5852: Keys of inner hashes are username:domain, with
5853: values set to access type.
1.288 raeburn 5854: Optional userdata hash returns an array with arguments in the
5855: same order as loncoursedata::get_classlist() for student data.
5856:
1.609 raeburn 5857: Optional statushash returns
5858:
1.288 raeburn 5859: Entries for end, start, section and status are blank because
5860: of the possibility of multiple values for non-student roles.
5861:
1.275 raeburn 5862: =cut
1.405 albertel 5863:
1.275 raeburn 5864: ###############################################
1.405 albertel 5865:
1.275 raeburn 5866: sub get_course_users {
1.609 raeburn 5867: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash) = @_;
1.288 raeburn 5868: my %idx = ();
1.419 raeburn 5869: my %seclists;
1.288 raeburn 5870:
5871: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
5872: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
5873: $idx{end} = &Apache::loncoursedata::CL_END();
5874: $idx{start} = &Apache::loncoursedata::CL_START();
5875: $idx{id} = &Apache::loncoursedata::CL_ID();
5876: $idx{section} = &Apache::loncoursedata::CL_SECTION();
5877: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
5878: $idx{status} = &Apache::loncoursedata::CL_STATUS();
5879:
1.290 albertel 5880: if (grep(/^st$/,@{$roles})) {
1.276 albertel 5881: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 5882: my $now = time;
1.277 albertel 5883: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 5884: my $match = 0;
1.412 raeburn 5885: my $secmatch = 0;
1.419 raeburn 5886: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 5887: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 5888: if ($section eq '') {
5889: $section = 'none';
5890: }
1.291 albertel 5891: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 5892: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 5893: $secmatch = 1;
5894: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 5895: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 5896: $secmatch = 1;
5897: }
5898: } else {
1.419 raeburn 5899: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 5900: $secmatch = 1;
5901: }
1.290 albertel 5902: }
1.412 raeburn 5903: if (!$secmatch) {
5904: next;
5905: }
1.419 raeburn 5906: }
1.275 raeburn 5907: if (defined($$types{'active'})) {
1.288 raeburn 5908: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 5909: push(@{$$users{st}{$student}},'active');
1.288 raeburn 5910: $match = 1;
1.275 raeburn 5911: }
5912: }
5913: if (defined($$types{'previous'})) {
1.609 raeburn 5914: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 5915: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 5916: $match = 1;
1.275 raeburn 5917: }
5918: }
5919: if (defined($$types{'future'})) {
1.609 raeburn 5920: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 5921: push(@{$$users{st}{$student}},'future');
1.288 raeburn 5922: $match = 1;
1.275 raeburn 5923: }
5924: }
1.609 raeburn 5925: if ($match) {
5926: push(@{$seclists{$student}},$section);
5927: if (ref($userdata) eq 'HASH') {
5928: $$userdata{$student} = $$classlist{$student};
5929: }
5930: if (ref($statushash) eq 'HASH') {
5931: $statushash->{$student}{'st'}{$section} = $status;
5932: }
1.288 raeburn 5933: }
1.275 raeburn 5934: }
5935: }
1.412 raeburn 5936: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 5937: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
5938: my $now = time;
1.609 raeburn 5939: my %displaystatus = ( previous => 'Expired',
5940: active => 'Active',
5941: future => 'Future',
5942: );
1.439 raeburn 5943: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 5944: my $match = 0;
1.412 raeburn 5945: my $secmatch = 0;
1.439 raeburn 5946: my $status;
1.412 raeburn 5947: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 5948: $user =~ s/:$//;
1.439 raeburn 5949: my ($end,$start) = split(/:/,$coursepersonnel{$person});
5950: if ($end == -1 || $start == -1) {
5951: next;
5952: }
5953: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
5954: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 5955: my ($uname,$udom) = split(/:/,$user);
5956: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 5957: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 5958: $secmatch = 1;
5959: } elsif ($usec eq '') {
1.420 albertel 5960: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 5961: $secmatch = 1;
5962: }
5963: } else {
5964: if (grep(/^\Q$usec\E$/,@{$sections})) {
5965: $secmatch = 1;
5966: }
5967: }
5968: if (!$secmatch) {
5969: next;
5970: }
1.288 raeburn 5971: }
1.419 raeburn 5972: if ($usec eq '') {
5973: $usec = 'none';
5974: }
1.275 raeburn 5975: if ($uname ne '' && $udom ne '') {
1.503 raeburn 5976: if ($end > 0 && $end < $now) {
1.439 raeburn 5977: $status = 'previous';
5978: } elsif ($start > $now) {
5979: $status = 'future';
5980: } else {
5981: $status = 'active';
5982: }
1.277 albertel 5983: foreach my $type (keys(%{$types})) {
1.275 raeburn 5984: if ($status eq $type) {
1.420 albertel 5985: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 5986: push(@{$$users{$role}{$user}},$type);
5987: }
1.288 raeburn 5988: $match = 1;
5989: }
5990: }
1.419 raeburn 5991: if (($match) && (ref($userdata) eq 'HASH')) {
5992: if (!exists($$userdata{$uname.':'.$udom})) {
5993: &get_user_info($udom,$uname,\%idx,$userdata);
5994: }
1.420 albertel 5995: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 5996: push(@{$seclists{$uname.':'.$udom}},$usec);
5997: }
1.609 raeburn 5998: if (ref($statushash) eq 'HASH') {
5999: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6000: }
1.275 raeburn 6001: }
6002: }
6003: }
6004: }
1.290 albertel 6005: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6006: if ((defined($cdom)) && (defined($cnum))) {
6007: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6008: if ( defined($csettings{'internal.courseowner'}) ) {
6009: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6010: next if ($owner eq '');
6011: my ($ownername,$ownerdom);
6012: if ($owner =~ /^([^:]+):([^:]+)$/) {
6013: $ownername = $1;
6014: $ownerdom = $2;
6015: } else {
6016: $ownername = $owner;
6017: $ownerdom = $cdom;
6018: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6019: }
6020: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6021: if (defined($userdata) &&
1.609 raeburn 6022: !exists($$userdata{$owner})) {
6023: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6024: if (!grep(/^none$/,@{$seclists{$owner}})) {
6025: push(@{$seclists{$owner}},'none');
6026: }
6027: if (ref($statushash) eq 'HASH') {
6028: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6029: }
1.290 albertel 6030: }
1.279 raeburn 6031: }
6032: }
6033: }
1.419 raeburn 6034: foreach my $user (keys(%seclists)) {
6035: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6036: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6037: }
1.275 raeburn 6038: }
6039: return;
6040: }
6041:
1.288 raeburn 6042: sub get_user_info {
6043: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6044: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6045: &plainname($uname,$udom,'lastname');
1.291 albertel 6046: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6047: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6048: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6049: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6050: return;
6051: }
1.275 raeburn 6052:
1.472 raeburn 6053: ###############################################
6054:
6055: =pod
6056:
6057: =item * &get_user_quota()
6058:
6059: Retrieves quota assigned for storage of portfolio files for a user
6060:
6061: Incoming parameters:
6062: 1. user's username
6063: 2. user's domain
6064:
6065: Returns:
1.536 raeburn 6066: 1. Disk quota (in Mb) assigned to student.
6067: 2. (Optional) Type of setting: custom or default
6068: (individually assigned or default for user's
6069: institutional status).
6070: 3. (Optional) - User's institutional status (e.g., faculty, staff
6071: or student - types as defined in localenroll::inst_usertypes
6072: for user's domain, which determines default quota for user.
6073: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6074:
6075: If a value has been stored in the user's environment,
1.536 raeburn 6076: it will return that, otherwise it returns the maximal default
6077: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6078:
6079: =cut
6080:
6081: ###############################################
6082:
6083:
6084: sub get_user_quota {
6085: my ($uname,$udom) = @_;
1.536 raeburn 6086: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6087: if (!defined($udom)) {
6088: $udom = $env{'user.domain'};
6089: }
6090: if (!defined($uname)) {
6091: $uname = $env{'user.name'};
6092: }
6093: if (($udom eq '' || $uname eq '') ||
6094: ($udom eq 'public') && ($uname eq 'public')) {
6095: $quota = 0;
1.536 raeburn 6096: $quotatype = 'default';
6097: $defquota = 0;
1.472 raeburn 6098: } else {
1.536 raeburn 6099: my $inststatus;
1.472 raeburn 6100: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6101: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6102: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6103: } else {
1.536 raeburn 6104: my %userenv =
6105: &Apache::lonnet::get('environment',['portfolioquota',
6106: 'inststatus'],$udom,$uname);
1.472 raeburn 6107: my ($tmp) = keys(%userenv);
6108: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6109: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6110: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6111: } else {
6112: undef(%userenv);
6113: }
6114: }
1.536 raeburn 6115: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6116: if ($quota eq '') {
1.536 raeburn 6117: $quota = $defquota;
6118: $quotatype = 'default';
6119: } else {
6120: $quotatype = 'custom';
1.472 raeburn 6121: }
6122: }
1.536 raeburn 6123: if (wantarray) {
6124: return ($quota,$quotatype,$settingstatus,$defquota);
6125: } else {
6126: return $quota;
6127: }
1.472 raeburn 6128: }
6129:
6130: ###############################################
6131:
6132: =pod
6133:
6134: =item * &default_quota()
6135:
1.536 raeburn 6136: Retrieves default quota assigned for storage of user portfolio files,
6137: given an (optional) user's institutional status.
1.472 raeburn 6138:
6139: Incoming parameters:
6140: 1. domain
1.536 raeburn 6141: 2. (Optional) institutional status(es). This is a : separated list of
6142: status types (e.g., faculty, staff, student etc.)
6143: which apply to the user for whom the default is being retrieved.
6144: If the institutional status string in undefined, the domain
6145: default quota will be returned.
1.472 raeburn 6146:
6147: Returns:
6148: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6149: 2. (Optional) institutional type which determined the value of the
6150: default quota.
1.472 raeburn 6151:
6152: If a value has been stored in the domain's configuration db,
6153: it will return that, otherwise it returns 20 (for backwards
6154: compatibility with domains which have not set up a configuration
6155: db file; the original statically defined portfolio quota was 20 Mb).
6156:
1.536 raeburn 6157: If the user's status includes multiple types (e.g., staff and student),
6158: the largest default quota which applies to the user determines the
6159: default quota returned.
6160:
1.472 raeburn 6161: =cut
6162:
6163: ###############################################
6164:
6165:
6166: sub default_quota {
1.536 raeburn 6167: my ($udom,$inststatus) = @_;
6168: my ($defquota,$settingstatus);
6169: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6170: ['quotas'],$udom);
6171: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6172: if ($inststatus ne '') {
6173: my @statuses = split(/:/,$inststatus);
6174: foreach my $item (@statuses) {
1.622 raeburn 6175: if ($quotahash{'quotas'}{$item} ne '') {
1.536 raeburn 6176: if ($defquota eq '') {
1.622 raeburn 6177: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6178: $settingstatus = $item;
1.622 raeburn 6179: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6180: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6181: $settingstatus = $item;
6182: }
6183: }
6184: }
6185: }
6186: if ($defquota eq '') {
1.622 raeburn 6187: $defquota = $quotahash{'quotas'}{'default'};
1.536 raeburn 6188: $settingstatus = 'default';
6189: }
6190: } else {
6191: $settingstatus = 'default';
6192: $defquota = 20;
6193: }
6194: if (wantarray) {
6195: return ($defquota,$settingstatus);
1.472 raeburn 6196: } else {
1.536 raeburn 6197: return $defquota;
1.472 raeburn 6198: }
6199: }
6200:
1.384 raeburn 6201: sub get_secgrprole_info {
6202: my ($cdom,$cnum,$needroles,$type) = @_;
6203: my %sections_count = &get_sections($cdom,$cnum);
6204: my @sections = (sort {$a <=> $b} keys(%sections_count));
6205: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6206: my @groups = sort(keys(%curr_groups));
6207: my $allroles = [];
6208: my $rolehash;
6209: my $accesshash = {
6210: active => 'Currently has access',
6211: future => 'Will have future access',
6212: previous => 'Previously had access',
6213: };
6214: if ($needroles) {
6215: $rolehash = {'all' => 'all'};
1.385 albertel 6216: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6217: if (&Apache::lonnet::error(%user_roles)) {
6218: undef(%user_roles);
6219: }
6220: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6221: my ($role)=split(/\:/,$item,2);
6222: if ($role eq 'cr') { next; }
6223: if ($role =~ /^cr/) {
6224: $$rolehash{$role} = (split('/',$role))[3];
6225: } else {
6226: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6227: }
6228: }
6229: foreach my $key (sort(keys(%{$rolehash}))) {
6230: push(@{$allroles},$key);
6231: }
6232: push (@{$allroles},'st');
6233: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6234: }
6235: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6236: }
6237:
1.555 raeburn 6238: sub user_picker {
1.570 raeburn 6239: my ($dom,$srch,$forcenewuser,$caller) = @_;
1.555 raeburn 6240: my $currdom = $dom;
6241: my %curr_selected = (
6242: srchin => 'dom',
1.580 raeburn 6243: srchby => 'lastname',
1.555 raeburn 6244: );
6245: my $srchterm;
6246: if (ref($srch) eq 'HASH') {
6247: if ($srch->{'srchby'} ne '') {
6248: $curr_selected{'srchby'} = $srch->{'srchby'};
6249: }
6250: if ($srch->{'srchin'} ne '') {
6251: $curr_selected{'srchin'} = $srch->{'srchin'};
6252: }
6253: if ($srch->{'srchtype'} ne '') {
6254: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6255: }
6256: if ($srch->{'srchdomain'} ne '') {
6257: $currdom = $srch->{'srchdomain'};
6258: }
6259: $srchterm = $srch->{'srchterm'};
6260: }
6261: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6262: 'usr' => 'Search criteria',
1.563 raeburn 6263: 'doma' => 'Domain/institution to search',
1.558 albertel 6264: 'uname' => 'username',
6265: 'lastname' => 'last name',
1.555 raeburn 6266: 'lastfirst' => 'last name, first name',
1.558 albertel 6267: 'crs' => 'in this course',
1.576 raeburn 6268: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6269: 'alc' => 'all LON-CAPA',
1.573 raeburn 6270: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6271: 'exact' => 'is',
6272: 'contains' => 'contains',
1.569 raeburn 6273: 'begins' => 'begins with',
1.571 raeburn 6274: 'youm' => "You must include some text to search for.",
6275: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6276: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6277: 'yomc' => "You must choose a domain when using an institutional directory search.",
6278: 'ymcd' => "You must choose a domain when using a domain search.",
6279: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6280: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6281: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6282: );
1.563 raeburn 6283: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6284: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6285:
6286: my @srchins = ('crs','dom','alc','instd');
6287:
6288: foreach my $option (@srchins) {
6289: # FIXME 'alc' option unavailable until
6290: # loncreateuser::print_user_query_page()
6291: # has been completed.
6292: next if ($option eq 'alc');
6293: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6294: if ($curr_selected{'srchin'} eq $option) {
6295: $srchinsel .= '
6296: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6297: } else {
6298: $srchinsel .= '
6299: <option value="'.$option.'">'.$lt{$option}.'</option>';
6300: }
1.555 raeburn 6301: }
1.563 raeburn 6302: $srchinsel .= "\n </select>\n";
1.555 raeburn 6303:
6304: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 6305: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 6306: if ($curr_selected{'srchby'} eq $option) {
6307: $srchbysel .= '
6308: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6309: } else {
6310: $srchbysel .= '
6311: <option value="'.$option.'">'.$lt{$option}.'</option>';
6312: }
6313: }
6314: $srchbysel .= "\n </select>\n";
6315:
6316: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 6317: foreach my $option ('begins','contains','exact') {
1.555 raeburn 6318: if ($curr_selected{'srchtype'} eq $option) {
6319: $srchtypesel .= '
6320: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6321: } else {
6322: $srchtypesel .= '
6323: <option value="'.$option.'">'.$lt{$option}.'</option>';
6324: }
6325: }
6326: $srchtypesel .= "\n </select>\n";
6327:
1.558 albertel 6328: my ($newuserscript,$new_user_create);
1.556 raeburn 6329:
6330: if ($forcenewuser) {
1.576 raeburn 6331: if (ref($srch) eq 'HASH') {
6332: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
6333: $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>';
6334: }
6335: }
6336:
1.556 raeburn 6337: $newuserscript = <<"ENDSCRIPT";
6338:
1.570 raeburn 6339: function setSearch(createnew,callingForm) {
1.556 raeburn 6340: if (createnew == 1) {
1.570 raeburn 6341: for (var i=0; i<callingForm.srchby.length; i++) {
6342: if (callingForm.srchby.options[i].value == 'uname') {
6343: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6344: }
6345: }
1.570 raeburn 6346: for (var i=0; i<callingForm.srchin.length; i++) {
6347: if ( callingForm.srchin.options[i].value == 'dom') {
6348: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6349: }
6350: }
1.570 raeburn 6351: for (var i=0; i<callingForm.srchtype.length; i++) {
6352: if (callingForm.srchtype.options[i].value == 'exact') {
6353: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6354: }
6355: }
1.570 raeburn 6356: for (var i=0; i<callingForm.srchdomain.length; i++) {
6357: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6358: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6359: }
6360: }
6361: }
6362: }
6363: ENDSCRIPT
1.558 albertel 6364:
1.556 raeburn 6365: }
6366:
1.555 raeburn 6367: my $output = <<"END_BLOCK";
1.556 raeburn 6368: <script type="text/javascript">
1.570 raeburn 6369: function validateEntry(callingForm) {
1.558 albertel 6370:
1.556 raeburn 6371: var checkok = 1;
1.558 albertel 6372: var srchin;
1.570 raeburn 6373: for (var i=0; i<callingForm.srchin.length; i++) {
6374: if ( callingForm.srchin[i].checked ) {
6375: srchin = callingForm.srchin[i].value;
1.558 albertel 6376: }
6377: }
6378:
1.570 raeburn 6379: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6380: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6381: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6382: var srchterm = callingForm.srchterm.value;
6383: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6384: var msg = "";
6385:
6386: if (srchterm == "") {
6387: checkok = 0;
1.571 raeburn 6388: msg += "$lt{'youm'}\\n";
1.556 raeburn 6389: }
6390:
1.569 raeburn 6391: if (srchtype== 'begins') {
6392: if (srchterm.length < 2) {
6393: checkok = 0;
1.571 raeburn 6394: msg += "$lt{'thte'}\\n";
1.569 raeburn 6395: }
6396: }
6397:
1.556 raeburn 6398: if (srchtype== 'contains') {
6399: if (srchterm.length < 3) {
6400: checkok = 0;
1.571 raeburn 6401: msg += "$lt{'thet'}\\n";
1.556 raeburn 6402: }
6403: }
6404: if (srchin == 'instd') {
6405: if (srchdomain == '') {
6406: checkok = 0;
1.571 raeburn 6407: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6408: }
6409: }
6410: if (srchin == 'dom') {
6411: if (srchdomain == '') {
6412: checkok = 0;
1.571 raeburn 6413: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6414: }
6415: }
6416: if (srchby == 'lastfirst') {
6417: if (srchterm.indexOf(",") == -1) {
6418: checkok = 0;
1.571 raeburn 6419: msg += "$lt{'whus'}\\n";
1.556 raeburn 6420: }
6421: if (srchterm.indexOf(",") == srchterm.length -1) {
6422: checkok = 0;
1.571 raeburn 6423: msg += "$lt{'whse'}\\n";
1.556 raeburn 6424: }
6425: }
6426: if (checkok == 0) {
1.571 raeburn 6427: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6428: return;
6429: }
6430: if (checkok == 1) {
1.570 raeburn 6431: callingForm.submit();
1.556 raeburn 6432: }
6433: }
6434:
6435: $newuserscript
6436:
6437: </script>
1.558 albertel 6438:
6439: $new_user_create
6440:
1.555 raeburn 6441: <table>
1.558 albertel 6442: <tr>
1.573 raeburn 6443: <td>$lt{'doma'}:</td>
6444: <td>$domform</td>
6445: </td>
6446: </tr>
6447: <tr>
6448: <td>$lt{'usr'}:</td>
1.563 raeburn 6449: <td>$srchbysel
6450: $srchtypesel
6451: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 6452: $srchinsel
1.563 raeburn 6453: </td>
6454: </tr>
1.555 raeburn 6455: </table>
6456: <br />
6457: END_BLOCK
1.558 albertel 6458:
1.555 raeburn 6459: return $output;
6460: }
6461:
1.612 raeburn 6462: sub user_rule_check {
1.615 raeburn 6463: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 6464: my $response;
6465: if (ref($usershash) eq 'HASH') {
6466: foreach my $user (keys(%{$usershash})) {
6467: my ($uname,$udom) = split(/:/,$user);
6468: next if ($udom eq '' || $uname eq '');
1.615 raeburn 6469: my ($id,$newuser);
1.612 raeburn 6470: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 6471: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 6472: $id = $usershash->{$user}->{'id'};
6473: }
6474: my $inst_response;
6475: if (ref($checks) eq 'HASH') {
6476: if (defined($checks->{'username'})) {
1.615 raeburn 6477: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6478: &Apache::lonnet::get_instuser($udom,$uname);
6479: } elsif (defined($checks->{'id'})) {
1.615 raeburn 6480: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6481: &Apache::lonnet::get_instuser($udom,undef,$id);
6482: }
1.615 raeburn 6483: } else {
6484: ($inst_response,%{$inst_results->{$user}}) =
6485: &Apache::lonnet::get_instuser($udom,$uname);
6486: return;
1.612 raeburn 6487: }
1.615 raeburn 6488: if (!$got_rules->{$udom}) {
1.612 raeburn 6489: my %domconfig = &Apache::lonnet::get_dom('configuration',
6490: ['usercreation'],$udom);
6491: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 6492: foreach my $item ('username','id') {
1.612 raeburn 6493: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6494: $$curr_rules{$udom}{$item} =
6495: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 6496: }
6497: }
6498: }
1.615 raeburn 6499: $got_rules->{$udom} = 1;
1.585 raeburn 6500: }
1.612 raeburn 6501: foreach my $item (keys(%{$checks})) {
6502: if (ref($$curr_rules{$udom}) eq 'HASH') {
6503: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
6504: if (@{$$curr_rules{$udom}{$item}} > 0) {
6505: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
6506: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
6507: if ($rule_check{$rule}) {
6508: $$rulematch{$user}{$item} = $rule;
6509: if ($inst_response eq 'ok') {
1.615 raeburn 6510: if (ref($inst_results) eq 'HASH') {
6511: if (ref($inst_results->{$user}) eq 'HASH') {
6512: if (keys(%{$inst_results->{$user}}) == 0) {
6513: $$alerts{$item}{$udom}{$uname} = 1;
6514: }
1.612 raeburn 6515: }
6516: }
1.615 raeburn 6517: }
6518: last;
1.585 raeburn 6519: }
6520: }
6521: }
6522: }
6523: }
6524: }
6525: }
6526: }
1.612 raeburn 6527: return;
6528: }
6529:
6530: sub user_rule_formats {
6531: my ($domain,$domdesc,$curr_rules,$check) = @_;
6532: my %text = (
6533: 'username' => 'Usernames',
6534: 'id' => 'IDs',
6535: );
6536: my $output;
6537: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
6538: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
6539: if (@{$ruleorder} > 0) {
6540: $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>';
6541: foreach my $rule (@{$ruleorder}) {
6542: if (ref($curr_rules) eq 'ARRAY') {
6543: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
6544: if (ref($rules->{$rule}) eq 'HASH') {
6545: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
6546: $rules->{$rule}{'desc'}.'</li>';
6547: }
6548: }
6549: }
6550: }
6551: $output .= '</ul>';
6552: }
6553: }
6554: return $output;
6555: }
6556:
6557: sub instrule_disallow_msg {
1.615 raeburn 6558: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 6559: my $response;
6560: my %text = (
6561: item => 'username',
6562: items => 'usernames',
6563: match => 'matches',
6564: do => 'does',
6565: action => 'a username',
6566: one => 'one',
6567: );
6568: if ($count > 1) {
6569: $text{'item'} = 'usernames';
6570: $text{'match'} ='match';
6571: $text{'do'} = 'do';
6572: $text{'action'} = 'usernames',
6573: $text{'one'} = 'ones';
6574: }
6575: if ($checkitem eq 'id') {
6576: $text{'items'} = 'IDs';
6577: $text{'item'} = 'ID';
6578: $text{'action'} = 'an ID';
1.615 raeburn 6579: if ($count > 1) {
6580: $text{'item'} = 'IDs';
6581: $text{'action'} = 'IDs';
6582: }
1.612 raeburn 6583: }
6584: $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 6585: if ($mode eq 'upload') {
6586: if ($checkitem eq 'username') {
6587: $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'}.");
6588: } elsif ($checkitem eq 'id') {
6589: $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.");
6590: }
6591: } else {
6592: if ($checkitem eq 'username') {
6593: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
6594: } elsif ($checkitem eq 'id') {
6595: $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.");
6596: }
1.612 raeburn 6597: }
6598: return $response;
1.585 raeburn 6599: }
6600:
1.112 bowersj2 6601: =pod
6602:
1.549 albertel 6603: =back
6604:
6605: =head1 HTTP Helpers
6606:
6607: =over 4
6608:
1.112 bowersj2 6609: =item * get_unprocessed_cgi($query,$possible_names)
6610:
1.258 albertel 6611: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 6612: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 6613: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 6614:
6615: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
6616: $possible_names is an ref to an array of form element names. As an example:
6617: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 6618: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 6619:
6620: =cut
1.1 albertel 6621:
1.6 albertel 6622: sub get_unprocessed_cgi {
1.25 albertel 6623: my ($query,$possible_names)= @_;
1.26 matthew 6624: # $Apache::lonxml::debug=1;
1.356 albertel 6625: foreach my $pair (split(/&/,$query)) {
6626: my ($name, $value) = split(/=/,$pair);
1.369 www 6627: $name = &unescape($name);
1.25 albertel 6628: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
6629: $value =~ tr/+/ /;
6630: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 6631: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 6632: }
1.16 harris41 6633: }
1.6 albertel 6634: }
6635:
1.112 bowersj2 6636: =pod
6637:
6638: =item * cacheheader()
6639:
6640: returns cache-controlling header code
6641:
6642: =cut
6643:
1.7 albertel 6644: sub cacheheader {
1.258 albertel 6645: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 6646: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
6647: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 6648: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
6649: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 6650: return $output;
1.7 albertel 6651: }
6652:
1.112 bowersj2 6653: =pod
6654:
6655: =item * no_cache($r)
6656:
6657: specifies header code to not have cache
6658:
6659: =cut
6660:
1.9 albertel 6661: sub no_cache {
1.216 albertel 6662: my ($r) = @_;
6663: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 6664: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 6665: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
6666: $r->no_cache(1);
6667: $r->header_out("Expires" => $date);
6668: $r->header_out("Pragma" => "no-cache");
1.123 www 6669: }
6670:
6671: sub content_type {
1.181 albertel 6672: my ($r,$type,$charset) = @_;
1.299 foxr 6673: if ($r) {
6674: # Note that printout.pl calls this with undef for $r.
6675: &no_cache($r);
6676: }
1.258 albertel 6677: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 6678: unless ($charset) {
6679: $charset=&Apache::lonlocal::current_encoding;
6680: }
6681: if ($charset) { $type.='; charset='.$charset; }
6682: if ($r) {
6683: $r->content_type($type);
6684: } else {
6685: print("Content-type: $type\n\n");
6686: }
1.9 albertel 6687: }
1.25 albertel 6688:
1.112 bowersj2 6689: =pod
6690:
6691: =item * add_to_env($name,$value)
6692:
1.258 albertel 6693: adds $name to the %env hash with value
1.112 bowersj2 6694: $value, if $name already exists, the entry is converted to an array
6695: reference and $value is added to the array.
6696:
6697: =cut
6698:
1.25 albertel 6699: sub add_to_env {
6700: my ($name,$value)=@_;
1.258 albertel 6701: if (defined($env{$name})) {
6702: if (ref($env{$name})) {
1.25 albertel 6703: #already have multiple values
1.258 albertel 6704: push(@{ $env{$name} },$value);
1.25 albertel 6705: } else {
6706: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 6707: my $first=$env{$name};
6708: undef($env{$name});
6709: push(@{ $env{$name} },$first,$value);
1.25 albertel 6710: }
6711: } else {
1.258 albertel 6712: $env{$name}=$value;
1.25 albertel 6713: }
1.31 albertel 6714: }
1.149 albertel 6715:
6716: =pod
6717:
6718: =item * get_env_multiple($name)
6719:
1.258 albertel 6720: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 6721: values may be defined and end up as an array ref.
6722:
6723: returns an array of values
6724:
6725: =cut
6726:
6727: sub get_env_multiple {
6728: my ($name) = @_;
6729: my @values;
1.258 albertel 6730: if (defined($env{$name})) {
1.149 albertel 6731: # exists is it an array
1.258 albertel 6732: if (ref($env{$name})) {
6733: @values=@{ $env{$name} };
1.149 albertel 6734: } else {
1.258 albertel 6735: $values[0]=$env{$name};
1.149 albertel 6736: }
6737: }
6738: return(@values);
6739: }
6740:
1.31 albertel 6741:
1.41 ng 6742: =pod
1.45 matthew 6743:
1.464 albertel 6744: =back
1.41 ng 6745:
1.112 bowersj2 6746: =head1 CSV Upload/Handling functions
1.38 albertel 6747:
1.41 ng 6748: =over 4
6749:
1.112 bowersj2 6750: =item * upfile_store($r)
1.41 ng 6751:
6752: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 6753: needs $env{'form.upfile'}
1.41 ng 6754: returns $datatoken to be put into hidden field
6755:
6756: =cut
1.31 albertel 6757:
6758: sub upfile_store {
6759: my $r=shift;
1.258 albertel 6760: $env{'form.upfile'}=~s/\r/\n/gs;
6761: $env{'form.upfile'}=~s/\f/\n/gs;
6762: $env{'form.upfile'}=~s/\n+/\n/gs;
6763: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 6764:
1.258 albertel 6765: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
6766: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 6767: {
1.158 raeburn 6768: my $datafile = $r->dir_config('lonDaemons').
6769: '/tmp/'.$datatoken.'.tmp';
6770: if ( open(my $fh,">$datafile") ) {
1.258 albertel 6771: print $fh $env{'form.upfile'};
1.158 raeburn 6772: close($fh);
6773: }
1.31 albertel 6774: }
6775: return $datatoken;
6776: }
6777:
1.56 matthew 6778: =pod
6779:
1.112 bowersj2 6780: =item * load_tmp_file($r)
1.41 ng 6781:
6782: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 6783: needs $env{'form.datatoken'},
6784: sets $env{'form.upfile'} to the contents of the file
1.41 ng 6785:
6786: =cut
1.31 albertel 6787:
6788: sub load_tmp_file {
6789: my $r=shift;
6790: my @studentdata=();
6791: {
1.158 raeburn 6792: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 6793: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 6794: if ( open(my $fh,"<$studentfile") ) {
6795: @studentdata=<$fh>;
6796: close($fh);
6797: }
1.31 albertel 6798: }
1.258 albertel 6799: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 6800: }
6801:
1.56 matthew 6802: =pod
6803:
1.112 bowersj2 6804: =item * upfile_record_sep()
1.41 ng 6805:
6806: Separate uploaded file into records
6807: returns array of records,
1.258 albertel 6808: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 6809:
6810: =cut
1.31 albertel 6811:
6812: sub upfile_record_sep {
1.258 albertel 6813: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 6814: } else {
1.248 albertel 6815: my @records;
1.258 albertel 6816: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 6817: if ($line=~/^\s*$/) { next; }
6818: push(@records,$line);
6819: }
6820: return @records;
1.31 albertel 6821: }
6822: }
6823:
1.56 matthew 6824: =pod
6825:
1.112 bowersj2 6826: =item * record_sep($record)
1.41 ng 6827:
1.258 albertel 6828: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 6829:
6830: =cut
6831:
1.263 www 6832: sub takeleft {
6833: my $index=shift;
6834: return substr('0000'.$index,-4,4);
6835: }
6836:
1.31 albertel 6837: sub record_sep {
6838: my $record=shift;
6839: my %components=();
1.258 albertel 6840: if ($env{'form.upfiletype'} eq 'xml') {
6841: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 6842: my $i=0;
1.356 albertel 6843: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 6844: $field=~s/^(\"|\')//;
6845: $field=~s/(\"|\')$//;
1.263 www 6846: $components{&takeleft($i)}=$field;
1.31 albertel 6847: $i++;
6848: }
1.258 albertel 6849: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 6850: my $i=0;
1.356 albertel 6851: foreach my $field (split(/\t/,$record)) {
1.31 albertel 6852: $field=~s/^(\"|\')//;
6853: $field=~s/(\"|\')$//;
1.263 www 6854: $components{&takeleft($i)}=$field;
1.31 albertel 6855: $i++;
6856: }
6857: } else {
1.561 www 6858: my $separator=',';
1.480 banghart 6859: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 6860: $separator=';';
1.480 banghart 6861: }
1.31 albertel 6862: my $i=0;
1.561 www 6863: # the character we are looking for to indicate the end of a quote or a record
6864: my $looking_for=$separator;
6865: # do not add the characters to the fields
6866: my $ignore=0;
6867: # we just encountered a separator (or the beginning of the record)
6868: my $just_found_separator=1;
6869: # store the field we are working on here
6870: my $field='';
6871: # work our way through all characters in record
6872: foreach my $character ($record=~/(.)/g) {
6873: if ($character eq $looking_for) {
6874: if ($character ne $separator) {
6875: # Found the end of a quote, again looking for separator
6876: $looking_for=$separator;
6877: $ignore=1;
6878: } else {
6879: # Found a separator, store away what we got
6880: $components{&takeleft($i)}=$field;
6881: $i++;
6882: $just_found_separator=1;
6883: $ignore=0;
6884: $field='';
6885: }
6886: next;
6887: }
6888: # single or double quotation marks after a separator indicate beginning of a quote
6889: # we are now looking for the end of the quote and need to ignore separators
6890: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
6891: $looking_for=$character;
6892: next;
6893: }
6894: # ignore would be true after we reached the end of a quote
6895: if ($ignore) { next; }
6896: if (($just_found_separator) && ($character=~/\s/)) { next; }
6897: $field.=$character;
6898: $just_found_separator=0;
1.31 albertel 6899: }
1.561 www 6900: # catch the very last entry, since we never encountered the separator
6901: $components{&takeleft($i)}=$field;
1.31 albertel 6902: }
6903: return %components;
6904: }
6905:
1.144 matthew 6906: ######################################################
6907: ######################################################
6908:
1.56 matthew 6909: =pod
6910:
1.112 bowersj2 6911: =item * upfile_select_html()
1.41 ng 6912:
1.144 matthew 6913: Return HTML code to select a file from the users machine and specify
6914: the file type.
1.41 ng 6915:
6916: =cut
6917:
1.144 matthew 6918: ######################################################
6919: ######################################################
1.31 albertel 6920: sub upfile_select_html {
1.144 matthew 6921: my %Types = (
6922: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 6923: semisv => &mt('Semicolon separated values'),
1.144 matthew 6924: space => &mt('Space separated'),
6925: tab => &mt('Tabulator separated'),
6926: # xml => &mt('HTML/XML'),
6927: );
6928: my $Str = '<input type="file" name="upfile" size="50" />'.
6929: '<br />Type: <select name="upfiletype">';
6930: foreach my $type (sort(keys(%Types))) {
6931: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
6932: }
6933: $Str .= "</select>\n";
6934: return $Str;
1.31 albertel 6935: }
6936:
1.301 albertel 6937: sub get_samples {
6938: my ($records,$toget) = @_;
6939: my @samples=({});
6940: my $got=0;
6941: foreach my $rec (@$records) {
6942: my %temp = &record_sep($rec);
6943: if (! grep(/\S/, values(%temp))) { next; }
6944: if (%temp) {
6945: $samples[$got]=\%temp;
6946: $got++;
6947: if ($got == $toget) { last; }
6948: }
6949: }
6950: return \@samples;
6951: }
6952:
1.144 matthew 6953: ######################################################
6954: ######################################################
6955:
1.56 matthew 6956: =pod
6957:
1.112 bowersj2 6958: =item * csv_print_samples($r,$records)
1.41 ng 6959:
6960: Prints a table of sample values from each column uploaded $r is an
6961: Apache Request ref, $records is an arrayref from
6962: &Apache::loncommon::upfile_record_sep
6963:
6964: =cut
6965:
1.144 matthew 6966: ######################################################
6967: ######################################################
1.31 albertel 6968: sub csv_print_samples {
6969: my ($r,$records) = @_;
1.301 albertel 6970: my $samples = &get_samples($records,3);
6971:
1.594 raeburn 6972: $r->print(&mt('Samples').'<br />'.&start_data_table().
6973: &start_data_table_header_row());
1.356 albertel 6974: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
6975: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 6976: $r->print(&end_data_table_header_row());
1.301 albertel 6977: foreach my $hash (@$samples) {
1.594 raeburn 6978: $r->print(&start_data_table_row());
1.356 albertel 6979: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 6980: $r->print('<td>');
1.356 albertel 6981: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 6982: $r->print('</td>');
6983: }
1.594 raeburn 6984: $r->print(&end_data_table_row());
1.31 albertel 6985: }
1.594 raeburn 6986: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 6987: }
6988:
1.144 matthew 6989: ######################################################
6990: ######################################################
6991:
1.56 matthew 6992: =pod
6993:
1.112 bowersj2 6994: =item * csv_print_select_table($r,$records,$d)
1.41 ng 6995:
6996: Prints a table to create associations between values and table columns.
1.144 matthew 6997:
1.41 ng 6998: $r is an Apache Request ref,
6999: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7000: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7001:
7002: =cut
7003:
1.144 matthew 7004: ######################################################
7005: ######################################################
1.31 albertel 7006: sub csv_print_select_table {
7007: my ($r,$records,$d) = @_;
1.301 albertel 7008: my $i=0;
7009: my $samples = &get_samples($records,1);
1.144 matthew 7010: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7011: &start_data_table().&start_data_table_header_row().
1.144 matthew 7012: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7013: '<th>'.&mt('Column').'</th>'.
7014: &end_data_table_header_row()."\n");
1.356 albertel 7015: foreach my $array_ref (@$d) {
7016: my ($value,$display,$defaultcol)=@{ $array_ref };
1.594 raeburn 7017: $r->print(&start_data_table_row().'<tr><td>'.$display.'</td>');
1.31 albertel 7018:
7019: $r->print('<td><select name=f'.$i.
1.32 matthew 7020: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7021: $r->print('<option value="none"></option>');
1.356 albertel 7022: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7023: $r->print('<option value="'.$sample.'"'.
7024: ($sample eq $defaultcol ? ' selected="selected" ' : '').
7025: '>Column '.($sample+1).'</option>');
1.31 albertel 7026: }
1.594 raeburn 7027: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7028: $i++;
7029: }
1.594 raeburn 7030: $r->print(&end_data_table());
1.31 albertel 7031: $i--;
7032: return $i;
7033: }
1.56 matthew 7034:
1.144 matthew 7035: ######################################################
7036: ######################################################
7037:
1.56 matthew 7038: =pod
1.31 albertel 7039:
1.112 bowersj2 7040: =item * csv_samples_select_table($r,$records,$d)
1.41 ng 7041:
7042: Prints a table of sample values from the upload and can make associate samples to internal names.
7043:
7044: $r is an Apache Request ref,
7045: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7046: $d is an array of 2 element arrays (internal name, displayed name)
7047:
7048: =cut
7049:
1.144 matthew 7050: ######################################################
7051: ######################################################
1.31 albertel 7052: sub csv_samples_select_table {
7053: my ($r,$records,$d) = @_;
7054: my $i=0;
1.144 matthew 7055: #
1.301 albertel 7056: my $samples = &get_samples($records,3);
1.594 raeburn 7057: $r->print(&start_data_table().
7058: &start_data_table_header_row().'<th>'.
7059: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7060: &end_data_table_header_row());
1.301 albertel 7061:
7062: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7063: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7064: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7065: foreach my $option (@$d) {
7066: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7067: $r->print('<option value="'.$value.'"'.
1.253 albertel 7068: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7069: $display.'</option>');
1.31 albertel 7070: }
7071: $r->print('</select></td><td>');
1.301 albertel 7072: foreach my $line (0..2) {
7073: if (defined($samples->[$line]{$key})) {
7074: $r->print($samples->[$line]{$key}."<br />\n");
7075: }
7076: }
1.594 raeburn 7077: $r->print('</td>'.&end_data_table_row());
1.31 albertel 7078: $i++;
7079: }
1.594 raeburn 7080: $r->print(&end_data_table());
1.31 albertel 7081: $i--;
7082: return($i);
1.115 matthew 7083: }
7084:
1.144 matthew 7085: ######################################################
7086: ######################################################
7087:
1.115 matthew 7088: =pod
7089:
7090: =item clean_excel_name($name)
7091:
7092: Returns a replacement for $name which does not contain any illegal characters.
7093:
7094: =cut
7095:
1.144 matthew 7096: ######################################################
7097: ######################################################
1.115 matthew 7098: sub clean_excel_name {
7099: my ($name) = @_;
7100: $name =~ s/[:\*\?\/\\]//g;
7101: if (length($name) > 31) {
7102: $name = substr($name,0,31);
7103: }
7104: return $name;
1.25 albertel 7105: }
1.84 albertel 7106:
1.85 albertel 7107: =pod
7108:
1.112 bowersj2 7109: =item * check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 7110:
7111: Returns either 1 or undef
7112:
7113: 1 if the part is to be hidden, undef if it is to be shown
7114:
7115: Arguments are:
7116:
7117: $id the id of the part to be checked
7118: $symb, optional the symb of the resource to check
7119: $udom, optional the domain of the user to check for
7120: $uname, optional the username of the user to check for
7121:
7122: =cut
1.84 albertel 7123:
7124: sub check_if_partid_hidden {
7125: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 7126: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 7127: $symb,$udom,$uname);
1.141 albertel 7128: my $truth=1;
7129: #if the string starts with !, then the list is the list to show not hide
7130: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 7131: my @hiddenlist=split(/,/,$hiddenparts);
7132: foreach my $checkid (@hiddenlist) {
1.141 albertel 7133: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 7134: }
1.141 albertel 7135: return !$truth;
1.84 albertel 7136: }
1.127 matthew 7137:
1.138 matthew 7138:
7139: ############################################################
7140: ############################################################
7141:
7142: =pod
7143:
1.157 matthew 7144: =back
7145:
1.138 matthew 7146: =head1 cgi-bin script and graphing routines
7147:
1.157 matthew 7148: =over 4
7149:
1.138 matthew 7150: =item get_cgi_id
7151:
7152: Inputs: none
7153:
7154: Returns an id which can be used to pass environment variables
7155: to various cgi-bin scripts. These environment variables will
7156: be removed from the users environment after a given time by
7157: the routine &Apache::lonnet::transfer_profile_to_env.
7158:
7159: =cut
7160:
7161: ############################################################
7162: ############################################################
1.152 albertel 7163: my $uniq=0;
1.136 matthew 7164: sub get_cgi_id {
1.154 albertel 7165: $uniq=($uniq+1)%100000;
1.280 albertel 7166: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 7167: }
7168:
1.127 matthew 7169: ############################################################
7170: ############################################################
7171:
7172: =pod
7173:
1.134 matthew 7174: =item DrawBarGraph
1.127 matthew 7175:
1.138 matthew 7176: Facilitates the plotting of data in a (stacked) bar graph.
7177: Puts plot definition data into the users environment in order for
7178: graph.png to plot it. Returns an <img> tag for the plot.
7179: The bars on the plot are labeled '1','2',...,'n'.
7180:
7181: Inputs:
7182:
7183: =over 4
7184:
7185: =item $Title: string, the title of the plot
7186:
7187: =item $xlabel: string, text describing the X-axis of the plot
7188:
7189: =item $ylabel: string, text describing the Y-axis of the plot
7190:
7191: =item $Max: scalar, the maximum Y value to use in the plot
7192: If $Max is < any data point, the graph will not be rendered.
7193:
1.140 matthew 7194: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 7195: they are plotted. If undefined, default values will be used.
7196:
1.178 matthew 7197: =item $labels: array ref holding the labels to use on the x-axis for the bars.
7198:
1.138 matthew 7199: =item @Values: An array of array references. Each array reference holds data
7200: to be plotted in a stacked bar chart.
7201:
1.239 matthew 7202: =item If the final element of @Values is a hash reference the key/value
7203: pairs will be added to the graph definition.
7204:
1.138 matthew 7205: =back
7206:
7207: Returns:
7208:
7209: An <img> tag which references graph.png and the appropriate identifying
7210: information for the plot.
7211:
1.127 matthew 7212: =cut
7213:
7214: ############################################################
7215: ############################################################
1.134 matthew 7216: sub DrawBarGraph {
1.178 matthew 7217: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 7218: #
7219: if (! defined($colors)) {
7220: $colors = ['#33ff00',
7221: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
7222: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
7223: ];
7224: }
1.228 matthew 7225: my $extra_settings = {};
7226: if (ref($Values[-1]) eq 'HASH') {
7227: $extra_settings = pop(@Values);
7228: }
1.127 matthew 7229: #
1.136 matthew 7230: my $identifier = &get_cgi_id();
7231: my $id = 'cgi.'.$identifier;
1.129 matthew 7232: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 7233: return '';
7234: }
1.225 matthew 7235: #
7236: my @Labels;
7237: if (defined($labels)) {
7238: @Labels = @$labels;
7239: } else {
7240: for (my $i=0;$i<@{$Values[0]};$i++) {
7241: push (@Labels,$i+1);
7242: }
7243: }
7244: #
1.129 matthew 7245: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 7246: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 7247: my %ValuesHash;
7248: my $NumSets=1;
7249: foreach my $array (@Values) {
7250: next if (! ref($array));
1.136 matthew 7251: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 7252: join(',',@$array);
1.129 matthew 7253: }
1.127 matthew 7254: #
1.136 matthew 7255: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 7256: if ($NumBars < 3) {
7257: $width = 120+$NumBars*32;
1.220 matthew 7258: $xskip = 1;
1.225 matthew 7259: $bar_width = 30;
7260: } elsif ($NumBars < 5) {
7261: $width = 120+$NumBars*20;
7262: $xskip = 1;
7263: $bar_width = 20;
1.220 matthew 7264: } elsif ($NumBars < 10) {
1.136 matthew 7265: $width = 120+$NumBars*15;
7266: $xskip = 1;
7267: $bar_width = 15;
7268: } elsif ($NumBars <= 25) {
7269: $width = 120+$NumBars*11;
7270: $xskip = 5;
7271: $bar_width = 8;
7272: } elsif ($NumBars <= 50) {
7273: $width = 120+$NumBars*8;
7274: $xskip = 5;
7275: $bar_width = 4;
7276: } else {
7277: $width = 120+$NumBars*8;
7278: $xskip = 5;
7279: $bar_width = 4;
7280: }
7281: #
1.137 matthew 7282: $Max = 1 if ($Max < 1);
7283: if ( int($Max) < $Max ) {
7284: $Max++;
7285: $Max = int($Max);
7286: }
1.127 matthew 7287: $Title = '' if (! defined($Title));
7288: $xlabel = '' if (! defined($xlabel));
7289: $ylabel = '' if (! defined($ylabel));
1.369 www 7290: $ValuesHash{$id.'.title'} = &escape($Title);
7291: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
7292: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 7293: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 7294: $ValuesHash{$id.'.NumBars'} = $NumBars;
7295: $ValuesHash{$id.'.NumSets'} = $NumSets;
7296: $ValuesHash{$id.'.PlotType'} = 'bar';
7297: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7298: $ValuesHash{$id.'.height'} = $height;
7299: $ValuesHash{$id.'.width'} = $width;
7300: $ValuesHash{$id.'.xskip'} = $xskip;
7301: $ValuesHash{$id.'.bar_width'} = $bar_width;
7302: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 7303: #
1.228 matthew 7304: # Deal with other parameters
7305: while (my ($key,$value) = each(%$extra_settings)) {
7306: $ValuesHash{$id.'.'.$key} = $value;
7307: }
7308: #
1.137 matthew 7309: &Apache::lonnet::appenv(%ValuesHash);
7310: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7311: }
7312:
7313: ############################################################
7314: ############################################################
7315:
7316: =pod
7317:
7318: =item DrawXYGraph
7319:
1.138 matthew 7320: Facilitates the plotting of data in an XY graph.
7321: Puts plot definition data into the users environment in order for
7322: graph.png to plot it. Returns an <img> tag for the plot.
7323:
7324: Inputs:
7325:
7326: =over 4
7327:
7328: =item $Title: string, the title of the plot
7329:
7330: =item $xlabel: string, text describing the X-axis of the plot
7331:
7332: =item $ylabel: string, text describing the Y-axis of the plot
7333:
7334: =item $Max: scalar, the maximum Y value to use in the plot
7335: If $Max is < any data point, the graph will not be rendered.
7336:
7337: =item $colors: Array ref containing the hex color codes for the data to be
7338: plotted in. If undefined, default values will be used.
7339:
7340: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7341:
7342: =item $Ydata: Array ref containing Array refs.
1.185 www 7343: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 7344:
7345: =item %Values: hash indicating or overriding any default values which are
7346: passed to graph.png.
7347: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7348:
7349: =back
7350:
7351: Returns:
7352:
7353: An <img> tag which references graph.png and the appropriate identifying
7354: information for the plot.
7355:
1.137 matthew 7356: =cut
7357:
7358: ############################################################
7359: ############################################################
7360: sub DrawXYGraph {
7361: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
7362: #
7363: # Create the identifier for the graph
7364: my $identifier = &get_cgi_id();
7365: my $id = 'cgi.'.$identifier;
7366: #
7367: $Title = '' if (! defined($Title));
7368: $xlabel = '' if (! defined($xlabel));
7369: $ylabel = '' if (! defined($ylabel));
7370: my %ValuesHash =
7371: (
1.369 www 7372: $id.'.title' => &escape($Title),
7373: $id.'.xlabel' => &escape($xlabel),
7374: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 7375: $id.'.y_max_value'=> $Max,
7376: $id.'.labels' => join(',',@$Xlabels),
7377: $id.'.PlotType' => 'XY',
7378: );
7379: #
7380: if (defined($colors) && ref($colors) eq 'ARRAY') {
7381: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7382: }
7383: #
7384: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
7385: return '';
7386: }
7387: my $NumSets=1;
1.138 matthew 7388: foreach my $array (@{$Ydata}){
1.137 matthew 7389: next if (! ref($array));
7390: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
7391: }
1.138 matthew 7392: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 7393: #
7394: # Deal with other parameters
7395: while (my ($key,$value) = each(%Values)) {
7396: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 7397: }
7398: #
1.136 matthew 7399: &Apache::lonnet::appenv(%ValuesHash);
7400: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7401: }
7402:
7403: ############################################################
7404: ############################################################
7405:
7406: =pod
7407:
1.138 matthew 7408: =item DrawXYYGraph
7409:
7410: Facilitates the plotting of data in an XY graph with two Y axes.
7411: Puts plot definition data into the users environment in order for
7412: graph.png to plot it. Returns an <img> tag for the plot.
7413:
7414: Inputs:
7415:
7416: =over 4
7417:
7418: =item $Title: string, the title of the plot
7419:
7420: =item $xlabel: string, text describing the X-axis of the plot
7421:
7422: =item $ylabel: string, text describing the Y-axis of the plot
7423:
7424: =item $colors: Array ref containing the hex color codes for the data to be
7425: plotted in. If undefined, default values will be used.
7426:
7427: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7428:
7429: =item $Ydata1: The first data set
7430:
7431: =item $Min1: The minimum value of the left Y-axis
7432:
7433: =item $Max1: The maximum value of the left Y-axis
7434:
7435: =item $Ydata2: The second data set
7436:
7437: =item $Min2: The minimum value of the right Y-axis
7438:
7439: =item $Max2: The maximum value of the left Y-axis
7440:
7441: =item %Values: hash indicating or overriding any default values which are
7442: passed to graph.png.
7443: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7444:
7445: =back
7446:
7447: Returns:
7448:
7449: An <img> tag which references graph.png and the appropriate identifying
7450: information for the plot.
1.136 matthew 7451:
7452: =cut
7453:
7454: ############################################################
7455: ############################################################
1.137 matthew 7456: sub DrawXYYGraph {
7457: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
7458: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 7459: #
7460: # Create the identifier for the graph
7461: my $identifier = &get_cgi_id();
7462: my $id = 'cgi.'.$identifier;
7463: #
7464: $Title = '' if (! defined($Title));
7465: $xlabel = '' if (! defined($xlabel));
7466: $ylabel = '' if (! defined($ylabel));
7467: my %ValuesHash =
7468: (
1.369 www 7469: $id.'.title' => &escape($Title),
7470: $id.'.xlabel' => &escape($xlabel),
7471: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 7472: $id.'.labels' => join(',',@$Xlabels),
7473: $id.'.PlotType' => 'XY',
7474: $id.'.NumSets' => 2,
1.137 matthew 7475: $id.'.two_axes' => 1,
7476: $id.'.y1_max_value' => $Max1,
7477: $id.'.y1_min_value' => $Min1,
7478: $id.'.y2_max_value' => $Max2,
7479: $id.'.y2_min_value' => $Min2,
1.136 matthew 7480: );
7481: #
1.137 matthew 7482: if (defined($colors) && ref($colors) eq 'ARRAY') {
7483: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7484: }
7485: #
7486: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
7487: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 7488: return '';
7489: }
7490: my $NumSets=1;
1.137 matthew 7491: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 7492: next if (! ref($array));
7493: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 7494: }
7495: #
7496: # Deal with other parameters
7497: while (my ($key,$value) = each(%Values)) {
7498: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 7499: }
7500: #
7501: &Apache::lonnet::appenv(%ValuesHash);
1.130 albertel 7502: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 7503: }
7504:
7505: ############################################################
7506: ############################################################
7507:
7508: =pod
7509:
1.157 matthew 7510: =back
7511:
1.139 matthew 7512: =head1 Statistics helper routines?
7513:
7514: Bad place for them but what the hell.
7515:
1.157 matthew 7516: =over 4
7517:
1.139 matthew 7518: =item &chartlink
7519:
7520: Returns a link to the chart for a specific student.
7521:
7522: Inputs:
7523:
7524: =over 4
7525:
7526: =item $linktext: The text of the link
7527:
7528: =item $sname: The students username
7529:
7530: =item $sdomain: The students domain
7531:
7532: =back
7533:
1.157 matthew 7534: =back
7535:
1.139 matthew 7536: =cut
7537:
7538: ############################################################
7539: ############################################################
7540: sub chartlink {
7541: my ($linktext, $sname, $sdomain) = @_;
7542: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 7543: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 7544: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 7545: '">'.$linktext.'</a>';
1.153 matthew 7546: }
7547:
7548: #######################################################
7549: #######################################################
7550:
7551: =pod
7552:
7553: =head1 Course Environment Routines
1.157 matthew 7554:
7555: =over 4
1.153 matthew 7556:
7557: =item &restore_course_settings
7558:
7559: =item &store_course_settings
7560:
7561: Restores/Store indicated form parameters from the course environment.
7562: Will not overwrite existing values of the form parameters.
7563:
7564: Inputs:
7565: a scalar describing the data (e.g. 'chart', 'problem_analysis')
7566:
7567: a hash ref describing the data to be stored. For example:
7568:
7569: %Save_Parameters = ('Status' => 'scalar',
7570: 'chartoutputmode' => 'scalar',
7571: 'chartoutputdata' => 'scalar',
7572: 'Section' => 'array',
1.373 raeburn 7573: 'Group' => 'array',
1.153 matthew 7574: 'StudentData' => 'array',
7575: 'Maps' => 'array');
7576:
7577: Returns: both routines return nothing
7578:
7579: =cut
7580:
7581: #######################################################
7582: #######################################################
7583: sub store_course_settings {
1.496 albertel 7584: return &store_settings($env{'request.course.id'},@_);
7585: }
7586:
7587: sub store_settings {
1.153 matthew 7588: # save to the environment
7589: # appenv the same items, just to be safe
1.300 albertel 7590: my $udom = $env{'user.domain'};
7591: my $uname = $env{'user.name'};
1.496 albertel 7592: my ($context,$prefix,$Settings) = @_;
1.153 matthew 7593: my %SaveHash;
7594: my %AppHash;
7595: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 7596: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 7597: my $envname = 'environment.'.$basename;
1.258 albertel 7598: if (exists($env{'form.'.$setting})) {
1.153 matthew 7599: # Save this value away
7600: if ($type eq 'scalar' &&
1.258 albertel 7601: (! exists($env{$envname}) ||
7602: $env{$envname} ne $env{'form.'.$setting})) {
7603: $SaveHash{$basename} = $env{'form.'.$setting};
7604: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 7605: } elsif ($type eq 'array') {
7606: my $stored_form;
1.258 albertel 7607: if (ref($env{'form.'.$setting})) {
1.153 matthew 7608: $stored_form = join(',',
7609: map {
1.369 www 7610: &escape($_);
1.258 albertel 7611: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 7612: } else {
7613: $stored_form =
1.369 www 7614: &escape($env{'form.'.$setting});
1.153 matthew 7615: }
7616: # Determine if the array contents are the same.
1.258 albertel 7617: if ($stored_form ne $env{$envname}) {
1.153 matthew 7618: $SaveHash{$basename} = $stored_form;
7619: $AppHash{$envname} = $stored_form;
7620: }
7621: }
7622: }
7623: }
7624: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 7625: $udom,$uname);
1.153 matthew 7626: if ($put_result !~ /^(ok|delayed)/) {
7627: &Apache::lonnet::logthis('unable to save form parameters, '.
7628: 'got error:'.$put_result);
7629: }
7630: # Make sure these settings stick around in this session, too
7631: &Apache::lonnet::appenv(%AppHash);
7632: return;
7633: }
7634:
7635: sub restore_course_settings {
1.499 albertel 7636: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 7637: }
7638:
7639: sub restore_settings {
7640: my ($context,$prefix,$Settings) = @_;
1.153 matthew 7641: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 7642: next if (exists($env{'form.'.$setting}));
1.496 albertel 7643: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 7644: '.'.$setting;
1.258 albertel 7645: if (exists($env{$envname})) {
1.153 matthew 7646: if ($type eq 'scalar') {
1.258 albertel 7647: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 7648: } elsif ($type eq 'array') {
1.258 albertel 7649: $env{'form.'.$setting} = [
1.153 matthew 7650: map {
1.369 www 7651: &unescape($_);
1.258 albertel 7652: } split(',',$env{$envname})
1.153 matthew 7653: ];
7654: }
7655: }
7656: }
1.127 matthew 7657: }
7658:
1.618 raeburn 7659: #######################################################
7660: #######################################################
7661:
7662: =pod
7663:
7664: =head1 Domain E-mail Routines
7665:
7666: =over 4
7667:
7668: =item &build_recipient_list
7669:
7670: Build recipient lists for three types of e-mail:
7671: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 7672: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 7673:
7674: Inputs:
1.619 raeburn 7675: defmail (scalar - email address of default recipient),
1.618 raeburn 7676: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 7677: defdom (domain for which to retrieve configuration settings),
7678: origmail (scalar - email address of recipient from loncapa.conf,
7679: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 7680:
7681: Returns: comma separated list of addresses to which to send e-mail.
7682:
7683: =cut
7684:
7685: ############################################################
7686: ############################################################
7687: sub build_recipient_list {
1.619 raeburn 7688: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 7689: my @recipients;
7690: my $otheremails;
7691: my %domconfig =
7692: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
7693: if (ref($domconfig{'contacts'}) eq 'HASH') {
7694: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
7695: my @contacts = ('adminemail','supportemail');
7696: foreach my $item (@contacts) {
7697: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 7698: my $addr = $domconfig{'contacts'}{$item};
7699: if (!grep(/^\Q$addr\E$/,@recipients)) {
7700: push(@recipients,$addr);
7701: }
1.618 raeburn 7702: }
7703: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
7704: }
7705: }
1.619 raeburn 7706: } elsif ($origmail ne '') {
7707: push(@recipients,$origmail);
1.618 raeburn 7708: }
7709: if ($defmail ne '') {
7710: push(@recipients,$defmail);
7711: }
7712: if ($otheremails) {
1.619 raeburn 7713: my @others;
7714: if ($otheremails =~ /,/) {
7715: @others = split(/,/,$otheremails);
1.618 raeburn 7716: } else {
1.619 raeburn 7717: push(@others,$otheremails);
7718: }
7719: foreach my $addr (@others) {
7720: if (!grep(/^\Q$addr\E$/,@recipients)) {
7721: push(@recipients,$addr);
7722: }
1.618 raeburn 7723: }
7724: }
1.619 raeburn 7725: my $recipientlist = join(',',@recipients);
1.618 raeburn 7726: return $recipientlist;
7727: }
7728:
1.127 matthew 7729: ############################################################
7730: ############################################################
1.154 albertel 7731:
1.443 albertel 7732: sub commit_customrole {
7733: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
7734: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
7735: ($start?', '.&mt('starting').' '.localtime($start):'').
7736: ($end?', ending '.localtime($end):'').': <b>'.
7737: &Apache::lonnet::assigncustomrole(
7738: $udom,$uname,$url,$three,$four,$five,$end,$start).
7739: '</b><br />';
7740: return $output;
7741: }
7742:
7743: sub commit_standardrole {
1.541 raeburn 7744: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
7745: my ($output,$logmsg,$linefeed);
7746: if ($context eq 'auto') {
7747: $linefeed = "\n";
7748: } else {
7749: $linefeed = "<br />\n";
7750: }
1.443 albertel 7751: if ($three eq 'st') {
1.541 raeburn 7752: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
7753: $one,$two,$sec,$context);
7754: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
7755: ($result eq 'unknown_course')) {
1.443 albertel 7756: $output = "Error: $result\n";
7757: } else {
1.541 raeburn 7758: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 7759: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 7760: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
7761: if ($context eq 'auto') {
7762: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
7763: } else {
7764: $output .= '<b>'.$result.'</b>'.$linefeed.
7765: &mt('Add to classlist').': <b>ok</b>';
7766: }
7767: $output .= $linefeed;
1.443 albertel 7768: }
7769: } else {
7770: $output = &mt('Assigning').' '.$three.' in '.$url.
7771: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 7772: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
7773: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start);
7774: if ($context eq 'auto') {
7775: $output .= $result.$linefeed;
7776: } else {
7777: $output .= '<b>'.$result.'</b>'.$linefeed;
7778: }
1.443 albertel 7779: }
7780: return $output;
7781: }
7782:
7783: sub commit_studentrole {
1.541 raeburn 7784: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
7785: my ($result,$linefeed);
7786: if ($context eq 'auto') {
7787: $linefeed = "\n";
7788: } else {
7789: $linefeed = '<br />'."\n";
7790: }
1.443 albertel 7791: if (defined($one) && defined($two)) {
7792: my $cid=$one.'_'.$two;
7793: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
7794: my $secchange = 0;
7795: my $expire_role_result;
7796: my $modify_section_result;
7797: unless ($oldsec eq '-1') {
7798: unless ($sec eq $oldsec) {
7799: $secchange = 1;
7800: my $uurl='/'.$cid;
7801: $uurl=~s/\_/\//g;
7802: if ($oldsec) {
7803: $uurl.='/'.$oldsec;
7804: }
7805: $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
7806: $result = $expire_role_result;
7807: }
7808: }
7809: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
7810: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
7811: if ($modify_section_result =~ /^ok/) {
7812: if ($secchange == 1) {
7813: $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
7814: } elsif ($oldsec eq '-1') {
7815: $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
7816: } else {
7817: $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
7818: }
7819: } else {
7820: $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
7821: }
7822: $result = $modify_section_result;
7823: } elsif ($secchange == 1) {
7824: $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
7825: }
7826: } else {
7827: $$logmsg .= "Incomplete course id defined. Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
7828: $result = "error: incomplete course id\n";
7829: }
7830: return $result;
7831: }
7832:
7833: ############################################################
7834: ############################################################
7835:
1.566 albertel 7836: sub check_clone {
1.578 raeburn 7837: my ($args,$linefeed) = @_;
1.566 albertel 7838: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
7839: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
7840: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
7841: my $clonemsg;
7842: my $can_clone = 0;
7843:
7844: if ($clonehome eq 'no_host') {
1.578 raeburn 7845: $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 7846: } else {
7847: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 7848: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 7849: $can_clone = 1;
7850: } else {
7851: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
7852: $args->{'clonedomain'},$args->{'clonecourse'});
7853: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 7854: if (grep(/^\*$/,@cloners)) {
7855: $can_clone = 1;
7856: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
7857: $can_clone = 1;
7858: } else {
7859: my %roleshash =
7860: &Apache::lonnet::get_my_roles($args->{'ccuname'},
7861: $args->{'ccdomain'},
7862: 'userroles',['active'],['cc'],
7863: [$args->{'clonedomain'}]);
7864: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
7865: $can_clone = 1;
7866: } else {
7867: $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'});
7868: }
1.566 albertel 7869: }
1.578 raeburn 7870: }
1.566 albertel 7871: }
7872: return ($can_clone, $clonemsg, $cloneid, $clonehome);
7873: }
7874:
1.444 albertel 7875: sub construct_course {
1.541 raeburn 7876: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 7877: my $outcome;
1.541 raeburn 7878: my $linefeed = '<br />'."\n";
7879: if ($context eq 'auto') {
7880: $linefeed = "\n";
7881: }
1.566 albertel 7882:
7883: #
7884: # Are we cloning?
7885: #
7886: my ($can_clone, $clonemsg, $cloneid, $clonehome);
7887: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 7888: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 7889: if ($context ne 'auto') {
1.578 raeburn 7890: if ($clonemsg ne '') {
7891: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
7892: }
1.566 albertel 7893: }
7894: $outcome .= $clonemsg.$linefeed;
7895:
7896: if (!$can_clone) {
7897: return (0,$outcome);
7898: }
7899: }
7900:
1.444 albertel 7901: #
7902: # Open course
7903: #
7904: my $crstype = lc($args->{'crstype'});
7905: my %cenv=();
7906: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
7907: $args->{'cdescr'},
7908: $args->{'curl'},
7909: $args->{'course_home'},
7910: $args->{'nonstandard'},
7911: $args->{'crscode'},
7912: $args->{'ccuname'}.':'.
7913: $args->{'ccdomain'},
7914: $args->{'crstype'});
7915:
7916: # Note: The testing routines depend on this being output; see
7917: # Utils::Course. This needs to at least be output as a comment
7918: # if anyone ever decides to not show this, and Utils::Course::new
7919: # will need to be suitably modified.
1.541 raeburn 7920: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 7921: #
7922: # Check if created correctly
7923: #
1.479 albertel 7924: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 7925: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 7926: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 7927:
1.444 albertel 7928: #
1.566 albertel 7929: # Do the cloning
7930: #
7931: if ($can_clone && $cloneid) {
7932: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
7933: if ($context ne 'auto') {
7934: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
7935: }
7936: $outcome .= $clonemsg.$linefeed;
7937: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 7938: # Copy all files
1.566 albertel 7939: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);
1.444 albertel 7940: # Restore URL
1.566 albertel 7941: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 7942: # Restore title
1.566 albertel 7943: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 7944: # restore grading mode
1.566 albertel 7945: if (defined($oldcenv{'grading'})) {
7946: $cenv{'grading'}=$oldcenv{'grading'};
7947: }
1.444 albertel 7948: # Mark as cloned
1.566 albertel 7949: $cenv{'clonedfrom'}=$cloneid;
7950: delete($cenv{'default_enrollment_start_date'});
7951: delete($cenv{'default_enrollment_end_date'});
1.444 albertel 7952: }
1.566 albertel 7953:
1.444 albertel 7954: #
7955: # Set environment (will override cloned, if existing)
7956: #
7957: my @sections = ();
7958: my @xlists = ();
7959: if ($args->{'crstype'}) {
7960: $cenv{'type'}=$args->{'crstype'};
7961: }
7962: if ($args->{'crsid'}) {
7963: $cenv{'courseid'}=$args->{'crsid'};
7964: }
7965: if ($args->{'crscode'}) {
7966: $cenv{'internal.coursecode'}=$args->{'crscode'};
7967: }
7968: if ($args->{'crsquota'} ne '') {
7969: $cenv{'internal.coursequota'}=$args->{'crsquota'};
7970: } else {
7971: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
7972: }
7973: if ($args->{'ccuname'}) {
7974: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
7975: ':'.$args->{'ccdomain'};
7976: } else {
7977: $cenv{'internal.courseowner'} = $args->{'curruser'};
7978: }
7979:
7980: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
7981: if ($args->{'crssections'}) {
7982: $cenv{'internal.sectionnums'} = '';
7983: if ($args->{'crssections'} =~ m/,/) {
7984: @sections = split/,/,$args->{'crssections'};
7985: } else {
7986: $sections[0] = $args->{'crssections'};
7987: }
7988: if (@sections > 0) {
7989: foreach my $item (@sections) {
7990: my ($sec,$gp) = split/:/,$item;
7991: my $class = $args->{'crscode'}.$sec;
7992: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
7993: $cenv{'internal.sectionnums'} .= $item.',';
7994: unless ($addcheck eq 'ok') {
7995: push @badclasses, $class;
7996: }
7997: }
7998: $cenv{'internal.sectionnums'} =~ s/,$//;
7999: }
8000: }
8001: # do not hide course coordinator from staff listing,
8002: # even if privileged
8003: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8004: # add crosslistings
8005: if ($args->{'crsxlist'}) {
8006: $cenv{'internal.crosslistings'}='';
8007: if ($args->{'crsxlist'} =~ m/,/) {
8008: @xlists = split/,/,$args->{'crsxlist'};
8009: } else {
8010: $xlists[0] = $args->{'crsxlist'};
8011: }
8012: if (@xlists > 0) {
8013: foreach my $item (@xlists) {
8014: my ($xl,$gp) = split/:/,$item;
8015: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
8016: $cenv{'internal.crosslistings'} .= $item.',';
8017: unless ($addcheck eq 'ok') {
8018: push @badclasses, $xl;
8019: }
8020: }
8021: $cenv{'internal.crosslistings'} =~ s/,$//;
8022: }
8023: }
8024: if ($args->{'autoadds'}) {
8025: $cenv{'internal.autoadds'}=$args->{'autoadds'};
8026: }
8027: if ($args->{'autodrops'}) {
8028: $cenv{'internal.autodrops'}=$args->{'autodrops'};
8029: }
8030: # check for notification of enrollment changes
8031: my @notified = ();
8032: if ($args->{'notify_owner'}) {
8033: if ($args->{'ccuname'} ne '') {
8034: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
8035: }
8036: }
8037: if ($args->{'notify_dc'}) {
8038: if ($uname ne '') {
8039: push(@notified,$uname.'@'.$udom);
8040: }
8041: }
8042: if (@notified > 0) {
8043: my $notifylist;
8044: if (@notified > 1) {
8045: $notifylist = join(',',@notified);
8046: } else {
8047: $notifylist = $notified[0];
8048: }
8049: $cenv{'internal.notifylist'} = $notifylist;
8050: }
8051: if (@badclasses > 0) {
8052: my %lt=&Apache::lonlocal::texthash(
8053: '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',
8054: 'dnhr' => 'does not have rights to access enrollment in these classes',
8055: 'adby' => 'as determined by the policies of your institution on access to official classlists'
8056: );
1.541 raeburn 8057: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
8058: ' ('.$lt{'adby'}.')';
8059: if ($context eq 'auto') {
8060: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 8061: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 8062: foreach my $item (@badclasses) {
8063: if ($context eq 'auto') {
8064: $outcome .= " - $item\n";
8065: } else {
8066: $outcome .= "<li>$item</li>\n";
8067: }
8068: }
8069: if ($context eq 'auto') {
8070: $outcome .= $linefeed;
8071: } else {
1.566 albertel 8072: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 8073: }
8074: }
1.444 albertel 8075: }
8076: if ($args->{'no_end_date'}) {
8077: $args->{'endaccess'} = 0;
8078: }
8079: $cenv{'internal.autostart'}=$args->{'enrollstart'};
8080: $cenv{'internal.autoend'}=$args->{'enrollend'};
8081: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
8082: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
8083: if ($args->{'showphotos'}) {
8084: $cenv{'internal.showphotos'}=$args->{'showphotos'};
8085: }
8086: $cenv{'internal.authtype'} = $args->{'authtype'};
8087: $cenv{'internal.autharg'} = $args->{'autharg'};
8088: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
8089: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 8090: 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');
8091: if ($context eq 'auto') {
8092: $outcome .= $krb_msg;
8093: } else {
1.566 albertel 8094: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 8095: }
8096: $outcome .= $linefeed;
1.444 albertel 8097: }
8098: }
8099: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
8100: if ($args->{'setpolicy'}) {
8101: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8102: }
8103: if ($args->{'setcontent'}) {
8104: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8105: }
8106: }
8107: if ($args->{'reshome'}) {
8108: $cenv{'reshome'}=$args->{'reshome'}.'/';
8109: $cenv{'reshome'}=~s/\/+$/\//;
8110: }
8111: #
8112: # course has keyed access
8113: #
8114: if ($args->{'setkeys'}) {
8115: $cenv{'keyaccess'}='yes';
8116: }
8117: # if specified, key authority is not course, but user
8118: # only active if keyaccess is yes
8119: if ($args->{'keyauth'}) {
1.487 albertel 8120: my ($user,$domain) = split(':',$args->{'keyauth'});
8121: $user = &LONCAPA::clean_username($user);
8122: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 8123: if ($user ne '' && $domain ne '') {
1.487 albertel 8124: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 8125: }
8126: }
8127:
8128: if ($args->{'disresdis'}) {
8129: $cenv{'pch.roles.denied'}='st';
8130: }
8131: if ($args->{'disablechat'}) {
8132: $cenv{'plc.roles.denied'}='st';
8133: }
8134:
8135: # Record we've not yet viewed the Course Initialization Helper for this
8136: # course
8137: $cenv{'course.helper.not.run'} = 1;
8138: #
8139: # Use new Randomseed
8140: #
8141: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
8142: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
8143: #
8144: # The encryption code and receipt prefix for this course
8145: #
8146: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
8147: $cenv{'internal.encpref'}=100+int(9*rand(99));
8148: #
8149: # By default, use standard grading
8150: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
8151:
1.541 raeburn 8152: $outcome .= $linefeed.&mt('Setting environment').': '.
8153: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 8154: #
8155: # Open all assignments
8156: #
8157: if ($args->{'openall'}) {
8158: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
8159: my %storecontent = ($storeunder => time,
8160: $storeunder.'.type' => 'date_start');
8161:
8162: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 8163: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 8164: }
8165: #
8166: # Set first page
8167: #
8168: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
8169: || ($cloneid)) {
1.445 albertel 8170: use LONCAPA::map;
1.444 albertel 8171: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 8172:
8173: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
8174: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
8175:
1.444 albertel 8176: $outcome .= ($fatal?$errtext:'read ok').' - ';
8177: my $title; my $url;
8178: if ($args->{'firstres'} eq 'syl') {
8179: $title='Syllabus';
8180: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
8181: } else {
8182: $title='Navigate Contents';
8183: $url='/adm/navmaps';
8184: }
1.445 albertel 8185:
8186: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
8187: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
8188:
8189: if ($errtext) { $fatal=2; }
1.541 raeburn 8190: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 8191: }
1.566 albertel 8192:
8193: return (1,$outcome);
1.444 albertel 8194: }
8195:
8196: ############################################################
8197: ############################################################
8198:
1.378 raeburn 8199: sub course_type {
8200: my ($cid) = @_;
8201: if (!defined($cid)) {
8202: $cid = $env{'request.course.id'};
8203: }
1.404 albertel 8204: if (defined($env{'course.'.$cid.'.type'})) {
8205: return $env{'course.'.$cid.'.type'};
1.378 raeburn 8206: } else {
8207: return 'Course';
1.377 raeburn 8208: }
8209: }
1.156 albertel 8210:
1.406 raeburn 8211: sub group_term {
8212: my $crstype = &course_type();
8213: my %names = (
8214: 'Course' => 'group',
8215: 'Group' => 'team',
8216: );
8217: return $names{$crstype};
8218: }
8219:
1.156 albertel 8220: sub icon {
8221: my ($file)=@_;
1.505 albertel 8222: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 8223: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 8224: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 8225: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
8226: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
8227: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
8228: $curfext.".gif") {
8229: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
8230: $curfext.".gif";
8231: }
8232: }
1.249 albertel 8233: return &lonhttpdurl($iconname);
1.154 albertel 8234: }
1.84 albertel 8235:
1.575 albertel 8236: sub lonhttpd_port {
1.215 albertel 8237: my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
8238: if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
1.574 albertel 8239: # IE doesn't like a secure page getting images from a non-secure
8240: # port (when logging we haven't parsed the browser type so default
8241: # back to secure
8242: if ((!exists($env{'browser.type'}) || $env{'browser.type'} eq 'explorer')
8243: && $ENV{'SERVER_PORT'} == 443) {
1.575 albertel 8244: return 443;
8245: }
8246: return $lonhttpd_port;
8247:
8248: }
8249:
8250: sub lonhttpdurl {
8251: my ($url)=@_;
8252:
8253: my $lonhttpd_port = &lonhttpd_port();
8254: if ($lonhttpd_port == 443) {
1.574 albertel 8255: return 'https://'.$ENV{'SERVER_NAME'}.$url;
8256: }
1.215 albertel 8257: return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
8258: }
8259:
1.213 albertel 8260: sub connection_aborted {
8261: my ($r)=@_;
8262: $r->print(" ");$r->rflush();
8263: my $c = $r->connection;
8264: return $c->aborted();
8265: }
8266:
1.221 foxr 8267: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 8268: # strings as 'strings'.
8269: sub escape_single {
1.221 foxr 8270: my ($input) = @_;
1.223 albertel 8271: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 8272: $input =~ s/\'/\\\'/g; # Esacpe the 's....
8273: return $input;
8274: }
1.223 albertel 8275:
1.222 foxr 8276: # Same as escape_single, but escape's "'s This
8277: # can be used for "strings"
8278: sub escape_double {
8279: my ($input) = @_;
8280: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
8281: $input =~ s/\"/\\\"/g; # Esacpe the "s....
8282: return $input;
8283: }
1.223 albertel 8284:
1.222 foxr 8285: # Escapes the last element of a full URL.
8286: sub escape_url {
8287: my ($url) = @_;
1.238 raeburn 8288: my @urlslices = split(/\//, $url,-1);
1.369 www 8289: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 8290: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 8291: }
1.462 albertel 8292:
8293: # -------------------------------------------------------- Initliaze user login
8294: sub init_user_environment {
1.463 albertel 8295: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 8296: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
8297:
8298: my $public=($username eq 'public' && $domain eq 'public');
8299:
8300: # See if old ID present, if so, remove
8301:
8302: my ($filename,$cookie,$userroles);
8303: my $now=time;
8304:
8305: if ($public) {
8306: my $max_public=100;
8307: my $oldest;
8308: my $oldest_time=0;
8309: for(my $next=1;$next<=$max_public;$next++) {
8310: if (-e $lonids."/publicuser_$next.id") {
8311: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
8312: if ($mtime<$oldest_time || !$oldest_time) {
8313: $oldest_time=$mtime;
8314: $oldest=$next;
8315: }
8316: } else {
8317: $cookie="publicuser_$next";
8318: last;
8319: }
8320: }
8321: if (!$cookie) { $cookie="publicuser_$oldest"; }
8322: } else {
1.463 albertel 8323: # if this isn't a robot, kill any existing non-robot sessions
8324: if (!$args->{'robot'}) {
8325: opendir(DIR,$lonids);
8326: while ($filename=readdir(DIR)) {
8327: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
8328: unlink($lonids.'/'.$filename);
8329: }
1.462 albertel 8330: }
1.463 albertel 8331: closedir(DIR);
1.462 albertel 8332: }
8333: # Give them a new cookie
1.463 albertel 8334: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
8335: : $now);
8336: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 8337:
8338: # Initialize roles
8339:
8340: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
8341: }
8342: # ------------------------------------ Check browser type and MathML capability
8343:
8344: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
8345: $clientunicode,$clientos) = &decode_user_agent($r);
8346:
8347: # -------------------------------------- Any accessibility options to remember?
8348: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
8349: foreach my $option ('imagesuppress','appletsuppress',
8350: 'embedsuppress','fontenhance','blackwhite') {
8351: if ($form->{$option} eq 'true') {
8352: &Apache::lonnet::put('environment',{$option => 'on'},
8353: $domain,$username);
8354: } else {
8355: &Apache::lonnet::del('environment',[$option],
8356: $domain,$username);
8357: }
8358: }
8359: }
8360: # ------------------------------------------------------------- Get environment
8361:
8362: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
8363: my ($tmp) = keys(%userenv);
8364: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8365: # default remote control to off
8366: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
8367: } else {
8368: undef(%userenv);
8369: }
8370: if (($userenv{'interface'}) && (!$form->{'interface'})) {
8371: $form->{'interface'}=$userenv{'interface'};
8372: }
8373: $env{'environment.remote'}=$userenv{'remote'};
8374: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
8375:
8376: # --------------- Do not trust query string to be put directly into environment
8377: foreach my $option ('imagesuppress','appletsuppress',
8378: 'embedsuppress','fontenhance','blackwhite',
8379: 'interface','localpath','localres') {
8380: $form->{$option}=~s/[\n\r\=]//gs;
8381: }
8382: # --------------------------------------------------------- Write first profile
8383:
8384: {
8385: my %initial_env =
8386: ("user.name" => $username,
8387: "user.domain" => $domain,
8388: "user.home" => $authhost,
8389: "browser.type" => $clientbrowser,
8390: "browser.version" => $clientversion,
8391: "browser.mathml" => $clientmathml,
8392: "browser.unicode" => $clientunicode,
8393: "browser.os" => $clientos,
8394: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
8395: "request.course.fn" => '',
8396: "request.course.uri" => '',
8397: "request.course.sec" => '',
8398: "request.role" => 'cm',
8399: "request.role.adv" => $env{'user.adv'},
8400: "request.host" => $ENV{'REMOTE_ADDR'},);
8401:
8402: if ($form->{'localpath'}) {
8403: $initial_env{"browser.localpath"} = $form->{'localpath'};
8404: $initial_env{"browser.localres"} = $form->{'localres'};
8405: }
8406:
8407: if ($public) {
8408: $initial_env{"environment.remote"} = "off";
8409: }
8410: if ($form->{'interface'}) {
8411: $form->{'interface'}=~s/\W//gs;
8412: $initial_env{"browser.interface"} = $form->{'interface'};
8413: $env{'browser.interface'}=$form->{'interface'};
8414: foreach my $option ('imagesuppress','appletsuppress',
8415: 'embedsuppress','fontenhance','blackwhite') {
8416: if (($form->{$option} eq 'true') ||
8417: ($userenv{$option} eq 'on')) {
8418: $initial_env{"browser.$option"} = "on";
8419: }
8420: }
8421: }
8422:
8423: $env{'user.environment'} = "$lonids/$cookie.id";
8424:
8425: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
8426: &GDBM_WRCREAT(),0640)) {
8427: &_add_to_env(\%disk_env,\%initial_env);
8428: &_add_to_env(\%disk_env,\%userenv,'environment.');
8429: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 8430: if (ref($args->{'extra_env'})) {
8431: &_add_to_env(\%disk_env,$args->{'extra_env'});
8432: }
1.462 albertel 8433: untie(%disk_env);
8434: } else {
8435: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
8436: 'Could not create environment storage in lonauth: '.$!.'</font>');
8437: return 'error: '.$!;
8438: }
8439: }
8440: $env{'request.role'}='cm';
8441: $env{'request.role.adv'}=$env{'user.adv'};
8442: $env{'browser.type'}=$clientbrowser;
8443:
8444: return $cookie;
8445:
8446: }
8447:
8448: sub _add_to_env {
8449: my ($idf,$env_data,$prefix) = @_;
8450: while (my ($key,$value) = each(%$env_data)) {
8451: $idf->{$prefix.$key} = $value;
8452: $env{$prefix.$key} = $value;
8453: }
8454: }
8455:
8456:
1.41 ng 8457: =pod
8458:
8459: =back
8460:
1.112 bowersj2 8461: =cut
1.41 ng 8462:
1.112 bowersj2 8463: 1;
8464: __END__;
1.41 ng 8465:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>