Annotation of loncom/interface/loncommon.pm, revision 1.628
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.628 ! raeburn 4: # $Id: loncommon.pm,v 1.627 2007/12/21 05:19:04 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.627 raeburn 6239: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
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;
1.625 raeburn 6246: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 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'}) {
1.627 raeburn 6333: if ($cancreate) {
6334: $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>';
6335: } else {
6336: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
6337: my %usertypetext = (
6338: official => 'institutional',
6339: unofficial => 'non-institutional',
6340: );
6341: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
6342: }
1.576 raeburn 6343: }
6344: }
6345:
1.556 raeburn 6346: $newuserscript = <<"ENDSCRIPT";
6347:
1.570 raeburn 6348: function setSearch(createnew,callingForm) {
1.556 raeburn 6349: if (createnew == 1) {
1.570 raeburn 6350: for (var i=0; i<callingForm.srchby.length; i++) {
6351: if (callingForm.srchby.options[i].value == 'uname') {
6352: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6353: }
6354: }
1.570 raeburn 6355: for (var i=0; i<callingForm.srchin.length; i++) {
6356: if ( callingForm.srchin.options[i].value == 'dom') {
6357: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6358: }
6359: }
1.570 raeburn 6360: for (var i=0; i<callingForm.srchtype.length; i++) {
6361: if (callingForm.srchtype.options[i].value == 'exact') {
6362: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6363: }
6364: }
1.570 raeburn 6365: for (var i=0; i<callingForm.srchdomain.length; i++) {
6366: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6367: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6368: }
6369: }
6370: }
6371: }
6372: ENDSCRIPT
1.558 albertel 6373:
1.556 raeburn 6374: }
6375:
1.555 raeburn 6376: my $output = <<"END_BLOCK";
1.556 raeburn 6377: <script type="text/javascript">
1.570 raeburn 6378: function validateEntry(callingForm) {
1.558 albertel 6379:
1.556 raeburn 6380: var checkok = 1;
1.558 albertel 6381: var srchin;
1.570 raeburn 6382: for (var i=0; i<callingForm.srchin.length; i++) {
6383: if ( callingForm.srchin[i].checked ) {
6384: srchin = callingForm.srchin[i].value;
1.558 albertel 6385: }
6386: }
6387:
1.570 raeburn 6388: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6389: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6390: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6391: var srchterm = callingForm.srchterm.value;
6392: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6393: var msg = "";
6394:
6395: if (srchterm == "") {
6396: checkok = 0;
1.571 raeburn 6397: msg += "$lt{'youm'}\\n";
1.556 raeburn 6398: }
6399:
1.569 raeburn 6400: if (srchtype== 'begins') {
6401: if (srchterm.length < 2) {
6402: checkok = 0;
1.571 raeburn 6403: msg += "$lt{'thte'}\\n";
1.569 raeburn 6404: }
6405: }
6406:
1.556 raeburn 6407: if (srchtype== 'contains') {
6408: if (srchterm.length < 3) {
6409: checkok = 0;
1.571 raeburn 6410: msg += "$lt{'thet'}\\n";
1.556 raeburn 6411: }
6412: }
6413: if (srchin == 'instd') {
6414: if (srchdomain == '') {
6415: checkok = 0;
1.571 raeburn 6416: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6417: }
6418: }
6419: if (srchin == 'dom') {
6420: if (srchdomain == '') {
6421: checkok = 0;
1.571 raeburn 6422: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6423: }
6424: }
6425: if (srchby == 'lastfirst') {
6426: if (srchterm.indexOf(",") == -1) {
6427: checkok = 0;
1.571 raeburn 6428: msg += "$lt{'whus'}\\n";
1.556 raeburn 6429: }
6430: if (srchterm.indexOf(",") == srchterm.length -1) {
6431: checkok = 0;
1.571 raeburn 6432: msg += "$lt{'whse'}\\n";
1.556 raeburn 6433: }
6434: }
6435: if (checkok == 0) {
1.571 raeburn 6436: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6437: return;
6438: }
6439: if (checkok == 1) {
1.570 raeburn 6440: callingForm.submit();
1.556 raeburn 6441: }
6442: }
6443:
6444: $newuserscript
6445:
6446: </script>
1.558 albertel 6447:
6448: $new_user_create
6449:
1.555 raeburn 6450: <table>
1.558 albertel 6451: <tr>
1.573 raeburn 6452: <td>$lt{'doma'}:</td>
6453: <td>$domform</td>
6454: </td>
6455: </tr>
6456: <tr>
6457: <td>$lt{'usr'}:</td>
1.563 raeburn 6458: <td>$srchbysel
6459: $srchtypesel
6460: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 6461: $srchinsel
1.563 raeburn 6462: </td>
6463: </tr>
1.555 raeburn 6464: </table>
6465: <br />
6466: END_BLOCK
1.558 albertel 6467:
1.555 raeburn 6468: return $output;
6469: }
6470:
1.612 raeburn 6471: sub user_rule_check {
1.615 raeburn 6472: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 6473: my $response;
6474: if (ref($usershash) eq 'HASH') {
6475: foreach my $user (keys(%{$usershash})) {
6476: my ($uname,$udom) = split(/:/,$user);
6477: next if ($udom eq '' || $uname eq '');
1.615 raeburn 6478: my ($id,$newuser);
1.612 raeburn 6479: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 6480: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 6481: $id = $usershash->{$user}->{'id'};
6482: }
6483: my $inst_response;
6484: if (ref($checks) eq 'HASH') {
6485: if (defined($checks->{'username'})) {
1.615 raeburn 6486: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6487: &Apache::lonnet::get_instuser($udom,$uname);
6488: } elsif (defined($checks->{'id'})) {
1.615 raeburn 6489: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6490: &Apache::lonnet::get_instuser($udom,undef,$id);
6491: }
1.615 raeburn 6492: } else {
6493: ($inst_response,%{$inst_results->{$user}}) =
6494: &Apache::lonnet::get_instuser($udom,$uname);
6495: return;
1.612 raeburn 6496: }
1.615 raeburn 6497: if (!$got_rules->{$udom}) {
1.612 raeburn 6498: my %domconfig = &Apache::lonnet::get_dom('configuration',
6499: ['usercreation'],$udom);
6500: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 6501: foreach my $item ('username','id') {
1.612 raeburn 6502: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6503: $$curr_rules{$udom}{$item} =
6504: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 6505: }
6506: }
6507: }
1.615 raeburn 6508: $got_rules->{$udom} = 1;
1.585 raeburn 6509: }
1.612 raeburn 6510: foreach my $item (keys(%{$checks})) {
6511: if (ref($$curr_rules{$udom}) eq 'HASH') {
6512: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
6513: if (@{$$curr_rules{$udom}{$item}} > 0) {
6514: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
6515: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
6516: if ($rule_check{$rule}) {
6517: $$rulematch{$user}{$item} = $rule;
6518: if ($inst_response eq 'ok') {
1.615 raeburn 6519: if (ref($inst_results) eq 'HASH') {
6520: if (ref($inst_results->{$user}) eq 'HASH') {
6521: if (keys(%{$inst_results->{$user}}) == 0) {
6522: $$alerts{$item}{$udom}{$uname} = 1;
6523: }
1.612 raeburn 6524: }
6525: }
1.615 raeburn 6526: }
6527: last;
1.585 raeburn 6528: }
6529: }
6530: }
6531: }
6532: }
6533: }
6534: }
6535: }
1.612 raeburn 6536: return;
6537: }
6538:
6539: sub user_rule_formats {
6540: my ($domain,$domdesc,$curr_rules,$check) = @_;
6541: my %text = (
6542: 'username' => 'Usernames',
6543: 'id' => 'IDs',
6544: );
6545: my $output;
6546: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
6547: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
6548: if (@{$ruleorder} > 0) {
6549: $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>';
6550: foreach my $rule (@{$ruleorder}) {
6551: if (ref($curr_rules) eq 'ARRAY') {
6552: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
6553: if (ref($rules->{$rule}) eq 'HASH') {
6554: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
6555: $rules->{$rule}{'desc'}.'</li>';
6556: }
6557: }
6558: }
6559: }
6560: $output .= '</ul>';
6561: }
6562: }
6563: return $output;
6564: }
6565:
6566: sub instrule_disallow_msg {
1.615 raeburn 6567: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 6568: my $response;
6569: my %text = (
6570: item => 'username',
6571: items => 'usernames',
6572: match => 'matches',
6573: do => 'does',
6574: action => 'a username',
6575: one => 'one',
6576: );
6577: if ($count > 1) {
6578: $text{'item'} = 'usernames';
6579: $text{'match'} ='match';
6580: $text{'do'} = 'do';
6581: $text{'action'} = 'usernames',
6582: $text{'one'} = 'ones';
6583: }
6584: if ($checkitem eq 'id') {
6585: $text{'items'} = 'IDs';
6586: $text{'item'} = 'ID';
6587: $text{'action'} = 'an ID';
1.615 raeburn 6588: if ($count > 1) {
6589: $text{'item'} = 'IDs';
6590: $text{'action'} = 'IDs';
6591: }
1.612 raeburn 6592: }
6593: $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 6594: if ($mode eq 'upload') {
6595: if ($checkitem eq 'username') {
6596: $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'}.");
6597: } elsif ($checkitem eq 'id') {
6598: $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.");
6599: }
6600: } else {
6601: if ($checkitem eq 'username') {
6602: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
6603: } elsif ($checkitem eq 'id') {
6604: $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.");
6605: }
1.612 raeburn 6606: }
6607: return $response;
1.585 raeburn 6608: }
6609:
1.624 raeburn 6610: sub personal_data_fieldtitles {
6611: my %fieldtitles = &Apache::lonlocal::texthash (
6612: id => 'Student/Employee ID',
6613: permanentemail => 'E-mail address',
6614: lastname => 'Last Name',
6615: firstname => 'First Name',
6616: middlename => 'Middle Name',
6617: generation => 'Generation',
6618: gen => 'Generation',
6619: );
6620: return %fieldtitles;
6621: }
6622:
1.112 bowersj2 6623: =pod
6624:
1.549 albertel 6625: =back
6626:
6627: =head1 HTTP Helpers
6628:
6629: =over 4
6630:
1.112 bowersj2 6631: =item * get_unprocessed_cgi($query,$possible_names)
6632:
1.258 albertel 6633: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 6634: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 6635: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 6636:
6637: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
6638: $possible_names is an ref to an array of form element names. As an example:
6639: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 6640: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 6641:
6642: =cut
1.1 albertel 6643:
1.6 albertel 6644: sub get_unprocessed_cgi {
1.25 albertel 6645: my ($query,$possible_names)= @_;
1.26 matthew 6646: # $Apache::lonxml::debug=1;
1.356 albertel 6647: foreach my $pair (split(/&/,$query)) {
6648: my ($name, $value) = split(/=/,$pair);
1.369 www 6649: $name = &unescape($name);
1.25 albertel 6650: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
6651: $value =~ tr/+/ /;
6652: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 6653: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 6654: }
1.16 harris41 6655: }
1.6 albertel 6656: }
6657:
1.112 bowersj2 6658: =pod
6659:
6660: =item * cacheheader()
6661:
6662: returns cache-controlling header code
6663:
6664: =cut
6665:
1.7 albertel 6666: sub cacheheader {
1.258 albertel 6667: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 6668: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
6669: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 6670: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
6671: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 6672: return $output;
1.7 albertel 6673: }
6674:
1.112 bowersj2 6675: =pod
6676:
6677: =item * no_cache($r)
6678:
6679: specifies header code to not have cache
6680:
6681: =cut
6682:
1.9 albertel 6683: sub no_cache {
1.216 albertel 6684: my ($r) = @_;
6685: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 6686: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 6687: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
6688: $r->no_cache(1);
6689: $r->header_out("Expires" => $date);
6690: $r->header_out("Pragma" => "no-cache");
1.123 www 6691: }
6692:
6693: sub content_type {
1.181 albertel 6694: my ($r,$type,$charset) = @_;
1.299 foxr 6695: if ($r) {
6696: # Note that printout.pl calls this with undef for $r.
6697: &no_cache($r);
6698: }
1.258 albertel 6699: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 6700: unless ($charset) {
6701: $charset=&Apache::lonlocal::current_encoding;
6702: }
6703: if ($charset) { $type.='; charset='.$charset; }
6704: if ($r) {
6705: $r->content_type($type);
6706: } else {
6707: print("Content-type: $type\n\n");
6708: }
1.9 albertel 6709: }
1.25 albertel 6710:
1.112 bowersj2 6711: =pod
6712:
6713: =item * add_to_env($name,$value)
6714:
1.258 albertel 6715: adds $name to the %env hash with value
1.112 bowersj2 6716: $value, if $name already exists, the entry is converted to an array
6717: reference and $value is added to the array.
6718:
6719: =cut
6720:
1.25 albertel 6721: sub add_to_env {
6722: my ($name,$value)=@_;
1.258 albertel 6723: if (defined($env{$name})) {
6724: if (ref($env{$name})) {
1.25 albertel 6725: #already have multiple values
1.258 albertel 6726: push(@{ $env{$name} },$value);
1.25 albertel 6727: } else {
6728: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 6729: my $first=$env{$name};
6730: undef($env{$name});
6731: push(@{ $env{$name} },$first,$value);
1.25 albertel 6732: }
6733: } else {
1.258 albertel 6734: $env{$name}=$value;
1.25 albertel 6735: }
1.31 albertel 6736: }
1.149 albertel 6737:
6738: =pod
6739:
6740: =item * get_env_multiple($name)
6741:
1.258 albertel 6742: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 6743: values may be defined and end up as an array ref.
6744:
6745: returns an array of values
6746:
6747: =cut
6748:
6749: sub get_env_multiple {
6750: my ($name) = @_;
6751: my @values;
1.258 albertel 6752: if (defined($env{$name})) {
1.149 albertel 6753: # exists is it an array
1.258 albertel 6754: if (ref($env{$name})) {
6755: @values=@{ $env{$name} };
1.149 albertel 6756: } else {
1.258 albertel 6757: $values[0]=$env{$name};
1.149 albertel 6758: }
6759: }
6760: return(@values);
6761: }
6762:
1.31 albertel 6763:
1.41 ng 6764: =pod
1.45 matthew 6765:
1.464 albertel 6766: =back
1.41 ng 6767:
1.112 bowersj2 6768: =head1 CSV Upload/Handling functions
1.38 albertel 6769:
1.41 ng 6770: =over 4
6771:
1.112 bowersj2 6772: =item * upfile_store($r)
1.41 ng 6773:
6774: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 6775: needs $env{'form.upfile'}
1.41 ng 6776: returns $datatoken to be put into hidden field
6777:
6778: =cut
1.31 albertel 6779:
6780: sub upfile_store {
6781: my $r=shift;
1.258 albertel 6782: $env{'form.upfile'}=~s/\r/\n/gs;
6783: $env{'form.upfile'}=~s/\f/\n/gs;
6784: $env{'form.upfile'}=~s/\n+/\n/gs;
6785: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 6786:
1.258 albertel 6787: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
6788: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 6789: {
1.158 raeburn 6790: my $datafile = $r->dir_config('lonDaemons').
6791: '/tmp/'.$datatoken.'.tmp';
6792: if ( open(my $fh,">$datafile") ) {
1.258 albertel 6793: print $fh $env{'form.upfile'};
1.158 raeburn 6794: close($fh);
6795: }
1.31 albertel 6796: }
6797: return $datatoken;
6798: }
6799:
1.56 matthew 6800: =pod
6801:
1.112 bowersj2 6802: =item * load_tmp_file($r)
1.41 ng 6803:
6804: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 6805: needs $env{'form.datatoken'},
6806: sets $env{'form.upfile'} to the contents of the file
1.41 ng 6807:
6808: =cut
1.31 albertel 6809:
6810: sub load_tmp_file {
6811: my $r=shift;
6812: my @studentdata=();
6813: {
1.158 raeburn 6814: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 6815: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 6816: if ( open(my $fh,"<$studentfile") ) {
6817: @studentdata=<$fh>;
6818: close($fh);
6819: }
1.31 albertel 6820: }
1.258 albertel 6821: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 6822: }
6823:
1.56 matthew 6824: =pod
6825:
1.112 bowersj2 6826: =item * upfile_record_sep()
1.41 ng 6827:
6828: Separate uploaded file into records
6829: returns array of records,
1.258 albertel 6830: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 6831:
6832: =cut
1.31 albertel 6833:
6834: sub upfile_record_sep {
1.258 albertel 6835: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 6836: } else {
1.248 albertel 6837: my @records;
1.258 albertel 6838: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 6839: if ($line=~/^\s*$/) { next; }
6840: push(@records,$line);
6841: }
6842: return @records;
1.31 albertel 6843: }
6844: }
6845:
1.56 matthew 6846: =pod
6847:
1.112 bowersj2 6848: =item * record_sep($record)
1.41 ng 6849:
1.258 albertel 6850: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 6851:
6852: =cut
6853:
1.263 www 6854: sub takeleft {
6855: my $index=shift;
6856: return substr('0000'.$index,-4,4);
6857: }
6858:
1.31 albertel 6859: sub record_sep {
6860: my $record=shift;
6861: my %components=();
1.258 albertel 6862: if ($env{'form.upfiletype'} eq 'xml') {
6863: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 6864: my $i=0;
1.356 albertel 6865: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 6866: $field=~s/^(\"|\')//;
6867: $field=~s/(\"|\')$//;
1.263 www 6868: $components{&takeleft($i)}=$field;
1.31 albertel 6869: $i++;
6870: }
1.258 albertel 6871: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 6872: my $i=0;
1.356 albertel 6873: foreach my $field (split(/\t/,$record)) {
1.31 albertel 6874: $field=~s/^(\"|\')//;
6875: $field=~s/(\"|\')$//;
1.263 www 6876: $components{&takeleft($i)}=$field;
1.31 albertel 6877: $i++;
6878: }
6879: } else {
1.561 www 6880: my $separator=',';
1.480 banghart 6881: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 6882: $separator=';';
1.480 banghart 6883: }
1.31 albertel 6884: my $i=0;
1.561 www 6885: # the character we are looking for to indicate the end of a quote or a record
6886: my $looking_for=$separator;
6887: # do not add the characters to the fields
6888: my $ignore=0;
6889: # we just encountered a separator (or the beginning of the record)
6890: my $just_found_separator=1;
6891: # store the field we are working on here
6892: my $field='';
6893: # work our way through all characters in record
6894: foreach my $character ($record=~/(.)/g) {
6895: if ($character eq $looking_for) {
6896: if ($character ne $separator) {
6897: # Found the end of a quote, again looking for separator
6898: $looking_for=$separator;
6899: $ignore=1;
6900: } else {
6901: # Found a separator, store away what we got
6902: $components{&takeleft($i)}=$field;
6903: $i++;
6904: $just_found_separator=1;
6905: $ignore=0;
6906: $field='';
6907: }
6908: next;
6909: }
6910: # single or double quotation marks after a separator indicate beginning of a quote
6911: # we are now looking for the end of the quote and need to ignore separators
6912: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
6913: $looking_for=$character;
6914: next;
6915: }
6916: # ignore would be true after we reached the end of a quote
6917: if ($ignore) { next; }
6918: if (($just_found_separator) && ($character=~/\s/)) { next; }
6919: $field.=$character;
6920: $just_found_separator=0;
1.31 albertel 6921: }
1.561 www 6922: # catch the very last entry, since we never encountered the separator
6923: $components{&takeleft($i)}=$field;
1.31 albertel 6924: }
6925: return %components;
6926: }
6927:
1.144 matthew 6928: ######################################################
6929: ######################################################
6930:
1.56 matthew 6931: =pod
6932:
1.112 bowersj2 6933: =item * upfile_select_html()
1.41 ng 6934:
1.144 matthew 6935: Return HTML code to select a file from the users machine and specify
6936: the file type.
1.41 ng 6937:
6938: =cut
6939:
1.144 matthew 6940: ######################################################
6941: ######################################################
1.31 albertel 6942: sub upfile_select_html {
1.144 matthew 6943: my %Types = (
6944: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 6945: semisv => &mt('Semicolon separated values'),
1.144 matthew 6946: space => &mt('Space separated'),
6947: tab => &mt('Tabulator separated'),
6948: # xml => &mt('HTML/XML'),
6949: );
6950: my $Str = '<input type="file" name="upfile" size="50" />'.
6951: '<br />Type: <select name="upfiletype">';
6952: foreach my $type (sort(keys(%Types))) {
6953: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
6954: }
6955: $Str .= "</select>\n";
6956: return $Str;
1.31 albertel 6957: }
6958:
1.301 albertel 6959: sub get_samples {
6960: my ($records,$toget) = @_;
6961: my @samples=({});
6962: my $got=0;
6963: foreach my $rec (@$records) {
6964: my %temp = &record_sep($rec);
6965: if (! grep(/\S/, values(%temp))) { next; }
6966: if (%temp) {
6967: $samples[$got]=\%temp;
6968: $got++;
6969: if ($got == $toget) { last; }
6970: }
6971: }
6972: return \@samples;
6973: }
6974:
1.144 matthew 6975: ######################################################
6976: ######################################################
6977:
1.56 matthew 6978: =pod
6979:
1.112 bowersj2 6980: =item * csv_print_samples($r,$records)
1.41 ng 6981:
6982: Prints a table of sample values from each column uploaded $r is an
6983: Apache Request ref, $records is an arrayref from
6984: &Apache::loncommon::upfile_record_sep
6985:
6986: =cut
6987:
1.144 matthew 6988: ######################################################
6989: ######################################################
1.31 albertel 6990: sub csv_print_samples {
6991: my ($r,$records) = @_;
1.301 albertel 6992: my $samples = &get_samples($records,3);
6993:
1.594 raeburn 6994: $r->print(&mt('Samples').'<br />'.&start_data_table().
6995: &start_data_table_header_row());
1.356 albertel 6996: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
6997: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 6998: $r->print(&end_data_table_header_row());
1.301 albertel 6999: foreach my $hash (@$samples) {
1.594 raeburn 7000: $r->print(&start_data_table_row());
1.356 albertel 7001: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7002: $r->print('<td>');
1.356 albertel 7003: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 7004: $r->print('</td>');
7005: }
1.594 raeburn 7006: $r->print(&end_data_table_row());
1.31 albertel 7007: }
1.594 raeburn 7008: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 7009: }
7010:
1.144 matthew 7011: ######################################################
7012: ######################################################
7013:
1.56 matthew 7014: =pod
7015:
1.112 bowersj2 7016: =item * csv_print_select_table($r,$records,$d)
1.41 ng 7017:
7018: Prints a table to create associations between values and table columns.
1.144 matthew 7019:
1.41 ng 7020: $r is an Apache Request ref,
7021: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7022: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7023:
7024: =cut
7025:
1.144 matthew 7026: ######################################################
7027: ######################################################
1.31 albertel 7028: sub csv_print_select_table {
7029: my ($r,$records,$d) = @_;
1.301 albertel 7030: my $i=0;
7031: my $samples = &get_samples($records,1);
1.144 matthew 7032: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7033: &start_data_table().&start_data_table_header_row().
1.144 matthew 7034: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7035: '<th>'.&mt('Column').'</th>'.
7036: &end_data_table_header_row()."\n");
1.356 albertel 7037: foreach my $array_ref (@$d) {
7038: my ($value,$display,$defaultcol)=@{ $array_ref };
1.594 raeburn 7039: $r->print(&start_data_table_row().'<tr><td>'.$display.'</td>');
1.31 albertel 7040:
7041: $r->print('<td><select name=f'.$i.
1.32 matthew 7042: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7043: $r->print('<option value="none"></option>');
1.356 albertel 7044: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7045: $r->print('<option value="'.$sample.'"'.
7046: ($sample eq $defaultcol ? ' selected="selected" ' : '').
7047: '>Column '.($sample+1).'</option>');
1.31 albertel 7048: }
1.594 raeburn 7049: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7050: $i++;
7051: }
1.594 raeburn 7052: $r->print(&end_data_table());
1.31 albertel 7053: $i--;
7054: return $i;
7055: }
1.56 matthew 7056:
1.144 matthew 7057: ######################################################
7058: ######################################################
7059:
1.56 matthew 7060: =pod
1.31 albertel 7061:
1.112 bowersj2 7062: =item * csv_samples_select_table($r,$records,$d)
1.41 ng 7063:
7064: Prints a table of sample values from the upload and can make associate samples to internal names.
7065:
7066: $r is an Apache Request ref,
7067: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7068: $d is an array of 2 element arrays (internal name, displayed name)
7069:
7070: =cut
7071:
1.144 matthew 7072: ######################################################
7073: ######################################################
1.31 albertel 7074: sub csv_samples_select_table {
7075: my ($r,$records,$d) = @_;
7076: my $i=0;
1.144 matthew 7077: #
1.301 albertel 7078: my $samples = &get_samples($records,3);
1.594 raeburn 7079: $r->print(&start_data_table().
7080: &start_data_table_header_row().'<th>'.
7081: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7082: &end_data_table_header_row());
1.301 albertel 7083:
7084: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7085: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7086: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7087: foreach my $option (@$d) {
7088: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7089: $r->print('<option value="'.$value.'"'.
1.253 albertel 7090: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7091: $display.'</option>');
1.31 albertel 7092: }
7093: $r->print('</select></td><td>');
1.301 albertel 7094: foreach my $line (0..2) {
7095: if (defined($samples->[$line]{$key})) {
7096: $r->print($samples->[$line]{$key}."<br />\n");
7097: }
7098: }
1.594 raeburn 7099: $r->print('</td>'.&end_data_table_row());
1.31 albertel 7100: $i++;
7101: }
1.594 raeburn 7102: $r->print(&end_data_table());
1.31 albertel 7103: $i--;
7104: return($i);
1.115 matthew 7105: }
7106:
1.144 matthew 7107: ######################################################
7108: ######################################################
7109:
1.115 matthew 7110: =pod
7111:
7112: =item clean_excel_name($name)
7113:
7114: Returns a replacement for $name which does not contain any illegal characters.
7115:
7116: =cut
7117:
1.144 matthew 7118: ######################################################
7119: ######################################################
1.115 matthew 7120: sub clean_excel_name {
7121: my ($name) = @_;
7122: $name =~ s/[:\*\?\/\\]//g;
7123: if (length($name) > 31) {
7124: $name = substr($name,0,31);
7125: }
7126: return $name;
1.25 albertel 7127: }
1.84 albertel 7128:
1.85 albertel 7129: =pod
7130:
1.112 bowersj2 7131: =item * check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 7132:
7133: Returns either 1 or undef
7134:
7135: 1 if the part is to be hidden, undef if it is to be shown
7136:
7137: Arguments are:
7138:
7139: $id the id of the part to be checked
7140: $symb, optional the symb of the resource to check
7141: $udom, optional the domain of the user to check for
7142: $uname, optional the username of the user to check for
7143:
7144: =cut
1.84 albertel 7145:
7146: sub check_if_partid_hidden {
7147: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 7148: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 7149: $symb,$udom,$uname);
1.141 albertel 7150: my $truth=1;
7151: #if the string starts with !, then the list is the list to show not hide
7152: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 7153: my @hiddenlist=split(/,/,$hiddenparts);
7154: foreach my $checkid (@hiddenlist) {
1.141 albertel 7155: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 7156: }
1.141 albertel 7157: return !$truth;
1.84 albertel 7158: }
1.127 matthew 7159:
1.138 matthew 7160:
7161: ############################################################
7162: ############################################################
7163:
7164: =pod
7165:
1.157 matthew 7166: =back
7167:
1.138 matthew 7168: =head1 cgi-bin script and graphing routines
7169:
1.157 matthew 7170: =over 4
7171:
1.138 matthew 7172: =item get_cgi_id
7173:
7174: Inputs: none
7175:
7176: Returns an id which can be used to pass environment variables
7177: to various cgi-bin scripts. These environment variables will
7178: be removed from the users environment after a given time by
7179: the routine &Apache::lonnet::transfer_profile_to_env.
7180:
7181: =cut
7182:
7183: ############################################################
7184: ############################################################
1.152 albertel 7185: my $uniq=0;
1.136 matthew 7186: sub get_cgi_id {
1.154 albertel 7187: $uniq=($uniq+1)%100000;
1.280 albertel 7188: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 7189: }
7190:
1.127 matthew 7191: ############################################################
7192: ############################################################
7193:
7194: =pod
7195:
1.134 matthew 7196: =item DrawBarGraph
1.127 matthew 7197:
1.138 matthew 7198: Facilitates the plotting of data in a (stacked) bar graph.
7199: Puts plot definition data into the users environment in order for
7200: graph.png to plot it. Returns an <img> tag for the plot.
7201: The bars on the plot are labeled '1','2',...,'n'.
7202:
7203: Inputs:
7204:
7205: =over 4
7206:
7207: =item $Title: string, the title of the plot
7208:
7209: =item $xlabel: string, text describing the X-axis of the plot
7210:
7211: =item $ylabel: string, text describing the Y-axis of the plot
7212:
7213: =item $Max: scalar, the maximum Y value to use in the plot
7214: If $Max is < any data point, the graph will not be rendered.
7215:
1.140 matthew 7216: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 7217: they are plotted. If undefined, default values will be used.
7218:
1.178 matthew 7219: =item $labels: array ref holding the labels to use on the x-axis for the bars.
7220:
1.138 matthew 7221: =item @Values: An array of array references. Each array reference holds data
7222: to be plotted in a stacked bar chart.
7223:
1.239 matthew 7224: =item If the final element of @Values is a hash reference the key/value
7225: pairs will be added to the graph definition.
7226:
1.138 matthew 7227: =back
7228:
7229: Returns:
7230:
7231: An <img> tag which references graph.png and the appropriate identifying
7232: information for the plot.
7233:
1.127 matthew 7234: =cut
7235:
7236: ############################################################
7237: ############################################################
1.134 matthew 7238: sub DrawBarGraph {
1.178 matthew 7239: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 7240: #
7241: if (! defined($colors)) {
7242: $colors = ['#33ff00',
7243: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
7244: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
7245: ];
7246: }
1.228 matthew 7247: my $extra_settings = {};
7248: if (ref($Values[-1]) eq 'HASH') {
7249: $extra_settings = pop(@Values);
7250: }
1.127 matthew 7251: #
1.136 matthew 7252: my $identifier = &get_cgi_id();
7253: my $id = 'cgi.'.$identifier;
1.129 matthew 7254: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 7255: return '';
7256: }
1.225 matthew 7257: #
7258: my @Labels;
7259: if (defined($labels)) {
7260: @Labels = @$labels;
7261: } else {
7262: for (my $i=0;$i<@{$Values[0]};$i++) {
7263: push (@Labels,$i+1);
7264: }
7265: }
7266: #
1.129 matthew 7267: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 7268: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 7269: my %ValuesHash;
7270: my $NumSets=1;
7271: foreach my $array (@Values) {
7272: next if (! ref($array));
1.136 matthew 7273: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 7274: join(',',@$array);
1.129 matthew 7275: }
1.127 matthew 7276: #
1.136 matthew 7277: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 7278: if ($NumBars < 3) {
7279: $width = 120+$NumBars*32;
1.220 matthew 7280: $xskip = 1;
1.225 matthew 7281: $bar_width = 30;
7282: } elsif ($NumBars < 5) {
7283: $width = 120+$NumBars*20;
7284: $xskip = 1;
7285: $bar_width = 20;
1.220 matthew 7286: } elsif ($NumBars < 10) {
1.136 matthew 7287: $width = 120+$NumBars*15;
7288: $xskip = 1;
7289: $bar_width = 15;
7290: } elsif ($NumBars <= 25) {
7291: $width = 120+$NumBars*11;
7292: $xskip = 5;
7293: $bar_width = 8;
7294: } elsif ($NumBars <= 50) {
7295: $width = 120+$NumBars*8;
7296: $xskip = 5;
7297: $bar_width = 4;
7298: } else {
7299: $width = 120+$NumBars*8;
7300: $xskip = 5;
7301: $bar_width = 4;
7302: }
7303: #
1.137 matthew 7304: $Max = 1 if ($Max < 1);
7305: if ( int($Max) < $Max ) {
7306: $Max++;
7307: $Max = int($Max);
7308: }
1.127 matthew 7309: $Title = '' if (! defined($Title));
7310: $xlabel = '' if (! defined($xlabel));
7311: $ylabel = '' if (! defined($ylabel));
1.369 www 7312: $ValuesHash{$id.'.title'} = &escape($Title);
7313: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
7314: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 7315: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 7316: $ValuesHash{$id.'.NumBars'} = $NumBars;
7317: $ValuesHash{$id.'.NumSets'} = $NumSets;
7318: $ValuesHash{$id.'.PlotType'} = 'bar';
7319: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7320: $ValuesHash{$id.'.height'} = $height;
7321: $ValuesHash{$id.'.width'} = $width;
7322: $ValuesHash{$id.'.xskip'} = $xskip;
7323: $ValuesHash{$id.'.bar_width'} = $bar_width;
7324: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 7325: #
1.228 matthew 7326: # Deal with other parameters
7327: while (my ($key,$value) = each(%$extra_settings)) {
7328: $ValuesHash{$id.'.'.$key} = $value;
7329: }
7330: #
1.137 matthew 7331: &Apache::lonnet::appenv(%ValuesHash);
7332: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7333: }
7334:
7335: ############################################################
7336: ############################################################
7337:
7338: =pod
7339:
7340: =item DrawXYGraph
7341:
1.138 matthew 7342: Facilitates the plotting of data in an XY graph.
7343: Puts plot definition data into the users environment in order for
7344: graph.png to plot it. Returns an <img> tag for the plot.
7345:
7346: Inputs:
7347:
7348: =over 4
7349:
7350: =item $Title: string, the title of the plot
7351:
7352: =item $xlabel: string, text describing the X-axis of the plot
7353:
7354: =item $ylabel: string, text describing the Y-axis of the plot
7355:
7356: =item $Max: scalar, the maximum Y value to use in the plot
7357: If $Max is < any data point, the graph will not be rendered.
7358:
7359: =item $colors: Array ref containing the hex color codes for the data to be
7360: plotted in. If undefined, default values will be used.
7361:
7362: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7363:
7364: =item $Ydata: Array ref containing Array refs.
1.185 www 7365: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 7366:
7367: =item %Values: hash indicating or overriding any default values which are
7368: passed to graph.png.
7369: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7370:
7371: =back
7372:
7373: Returns:
7374:
7375: An <img> tag which references graph.png and the appropriate identifying
7376: information for the plot.
7377:
1.137 matthew 7378: =cut
7379:
7380: ############################################################
7381: ############################################################
7382: sub DrawXYGraph {
7383: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
7384: #
7385: # Create the identifier for the graph
7386: my $identifier = &get_cgi_id();
7387: my $id = 'cgi.'.$identifier;
7388: #
7389: $Title = '' if (! defined($Title));
7390: $xlabel = '' if (! defined($xlabel));
7391: $ylabel = '' if (! defined($ylabel));
7392: my %ValuesHash =
7393: (
1.369 www 7394: $id.'.title' => &escape($Title),
7395: $id.'.xlabel' => &escape($xlabel),
7396: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 7397: $id.'.y_max_value'=> $Max,
7398: $id.'.labels' => join(',',@$Xlabels),
7399: $id.'.PlotType' => 'XY',
7400: );
7401: #
7402: if (defined($colors) && ref($colors) eq 'ARRAY') {
7403: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7404: }
7405: #
7406: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
7407: return '';
7408: }
7409: my $NumSets=1;
1.138 matthew 7410: foreach my $array (@{$Ydata}){
1.137 matthew 7411: next if (! ref($array));
7412: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
7413: }
1.138 matthew 7414: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 7415: #
7416: # Deal with other parameters
7417: while (my ($key,$value) = each(%Values)) {
7418: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 7419: }
7420: #
1.136 matthew 7421: &Apache::lonnet::appenv(%ValuesHash);
7422: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7423: }
7424:
7425: ############################################################
7426: ############################################################
7427:
7428: =pod
7429:
1.138 matthew 7430: =item DrawXYYGraph
7431:
7432: Facilitates the plotting of data in an XY graph with two Y axes.
7433: Puts plot definition data into the users environment in order for
7434: graph.png to plot it. Returns an <img> tag for the plot.
7435:
7436: Inputs:
7437:
7438: =over 4
7439:
7440: =item $Title: string, the title of the plot
7441:
7442: =item $xlabel: string, text describing the X-axis of the plot
7443:
7444: =item $ylabel: string, text describing the Y-axis of the plot
7445:
7446: =item $colors: Array ref containing the hex color codes for the data to be
7447: plotted in. If undefined, default values will be used.
7448:
7449: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7450:
7451: =item $Ydata1: The first data set
7452:
7453: =item $Min1: The minimum value of the left Y-axis
7454:
7455: =item $Max1: The maximum value of the left Y-axis
7456:
7457: =item $Ydata2: The second data set
7458:
7459: =item $Min2: The minimum value of the right Y-axis
7460:
7461: =item $Max2: The maximum value of the left Y-axis
7462:
7463: =item %Values: hash indicating or overriding any default values which are
7464: passed to graph.png.
7465: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7466:
7467: =back
7468:
7469: Returns:
7470:
7471: An <img> tag which references graph.png and the appropriate identifying
7472: information for the plot.
1.136 matthew 7473:
7474: =cut
7475:
7476: ############################################################
7477: ############################################################
1.137 matthew 7478: sub DrawXYYGraph {
7479: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
7480: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 7481: #
7482: # Create the identifier for the graph
7483: my $identifier = &get_cgi_id();
7484: my $id = 'cgi.'.$identifier;
7485: #
7486: $Title = '' if (! defined($Title));
7487: $xlabel = '' if (! defined($xlabel));
7488: $ylabel = '' if (! defined($ylabel));
7489: my %ValuesHash =
7490: (
1.369 www 7491: $id.'.title' => &escape($Title),
7492: $id.'.xlabel' => &escape($xlabel),
7493: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 7494: $id.'.labels' => join(',',@$Xlabels),
7495: $id.'.PlotType' => 'XY',
7496: $id.'.NumSets' => 2,
1.137 matthew 7497: $id.'.two_axes' => 1,
7498: $id.'.y1_max_value' => $Max1,
7499: $id.'.y1_min_value' => $Min1,
7500: $id.'.y2_max_value' => $Max2,
7501: $id.'.y2_min_value' => $Min2,
1.136 matthew 7502: );
7503: #
1.137 matthew 7504: if (defined($colors) && ref($colors) eq 'ARRAY') {
7505: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7506: }
7507: #
7508: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
7509: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 7510: return '';
7511: }
7512: my $NumSets=1;
1.137 matthew 7513: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 7514: next if (! ref($array));
7515: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 7516: }
7517: #
7518: # Deal with other parameters
7519: while (my ($key,$value) = each(%Values)) {
7520: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 7521: }
7522: #
7523: &Apache::lonnet::appenv(%ValuesHash);
1.130 albertel 7524: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 7525: }
7526:
7527: ############################################################
7528: ############################################################
7529:
7530: =pod
7531:
1.157 matthew 7532: =back
7533:
1.139 matthew 7534: =head1 Statistics helper routines?
7535:
7536: Bad place for them but what the hell.
7537:
1.157 matthew 7538: =over 4
7539:
1.139 matthew 7540: =item &chartlink
7541:
7542: Returns a link to the chart for a specific student.
7543:
7544: Inputs:
7545:
7546: =over 4
7547:
7548: =item $linktext: The text of the link
7549:
7550: =item $sname: The students username
7551:
7552: =item $sdomain: The students domain
7553:
7554: =back
7555:
1.157 matthew 7556: =back
7557:
1.139 matthew 7558: =cut
7559:
7560: ############################################################
7561: ############################################################
7562: sub chartlink {
7563: my ($linktext, $sname, $sdomain) = @_;
7564: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 7565: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 7566: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 7567: '">'.$linktext.'</a>';
1.153 matthew 7568: }
7569:
7570: #######################################################
7571: #######################################################
7572:
7573: =pod
7574:
7575: =head1 Course Environment Routines
1.157 matthew 7576:
7577: =over 4
1.153 matthew 7578:
7579: =item &restore_course_settings
7580:
7581: =item &store_course_settings
7582:
7583: Restores/Store indicated form parameters from the course environment.
7584: Will not overwrite existing values of the form parameters.
7585:
7586: Inputs:
7587: a scalar describing the data (e.g. 'chart', 'problem_analysis')
7588:
7589: a hash ref describing the data to be stored. For example:
7590:
7591: %Save_Parameters = ('Status' => 'scalar',
7592: 'chartoutputmode' => 'scalar',
7593: 'chartoutputdata' => 'scalar',
7594: 'Section' => 'array',
1.373 raeburn 7595: 'Group' => 'array',
1.153 matthew 7596: 'StudentData' => 'array',
7597: 'Maps' => 'array');
7598:
7599: Returns: both routines return nothing
7600:
7601: =cut
7602:
7603: #######################################################
7604: #######################################################
7605: sub store_course_settings {
1.496 albertel 7606: return &store_settings($env{'request.course.id'},@_);
7607: }
7608:
7609: sub store_settings {
1.153 matthew 7610: # save to the environment
7611: # appenv the same items, just to be safe
1.300 albertel 7612: my $udom = $env{'user.domain'};
7613: my $uname = $env{'user.name'};
1.496 albertel 7614: my ($context,$prefix,$Settings) = @_;
1.153 matthew 7615: my %SaveHash;
7616: my %AppHash;
7617: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 7618: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 7619: my $envname = 'environment.'.$basename;
1.258 albertel 7620: if (exists($env{'form.'.$setting})) {
1.153 matthew 7621: # Save this value away
7622: if ($type eq 'scalar' &&
1.258 albertel 7623: (! exists($env{$envname}) ||
7624: $env{$envname} ne $env{'form.'.$setting})) {
7625: $SaveHash{$basename} = $env{'form.'.$setting};
7626: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 7627: } elsif ($type eq 'array') {
7628: my $stored_form;
1.258 albertel 7629: if (ref($env{'form.'.$setting})) {
1.153 matthew 7630: $stored_form = join(',',
7631: map {
1.369 www 7632: &escape($_);
1.258 albertel 7633: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 7634: } else {
7635: $stored_form =
1.369 www 7636: &escape($env{'form.'.$setting});
1.153 matthew 7637: }
7638: # Determine if the array contents are the same.
1.258 albertel 7639: if ($stored_form ne $env{$envname}) {
1.153 matthew 7640: $SaveHash{$basename} = $stored_form;
7641: $AppHash{$envname} = $stored_form;
7642: }
7643: }
7644: }
7645: }
7646: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 7647: $udom,$uname);
1.153 matthew 7648: if ($put_result !~ /^(ok|delayed)/) {
7649: &Apache::lonnet::logthis('unable to save form parameters, '.
7650: 'got error:'.$put_result);
7651: }
7652: # Make sure these settings stick around in this session, too
7653: &Apache::lonnet::appenv(%AppHash);
7654: return;
7655: }
7656:
7657: sub restore_course_settings {
1.499 albertel 7658: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 7659: }
7660:
7661: sub restore_settings {
7662: my ($context,$prefix,$Settings) = @_;
1.153 matthew 7663: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 7664: next if (exists($env{'form.'.$setting}));
1.496 albertel 7665: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 7666: '.'.$setting;
1.258 albertel 7667: if (exists($env{$envname})) {
1.153 matthew 7668: if ($type eq 'scalar') {
1.258 albertel 7669: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 7670: } elsif ($type eq 'array') {
1.258 albertel 7671: $env{'form.'.$setting} = [
1.153 matthew 7672: map {
1.369 www 7673: &unescape($_);
1.258 albertel 7674: } split(',',$env{$envname})
1.153 matthew 7675: ];
7676: }
7677: }
7678: }
1.127 matthew 7679: }
7680:
1.618 raeburn 7681: #######################################################
7682: #######################################################
7683:
7684: =pod
7685:
7686: =head1 Domain E-mail Routines
7687:
7688: =over 4
7689:
7690: =item &build_recipient_list
7691:
7692: Build recipient lists for three types of e-mail:
7693: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 7694: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 7695:
7696: Inputs:
1.619 raeburn 7697: defmail (scalar - email address of default recipient),
1.618 raeburn 7698: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 7699: defdom (domain for which to retrieve configuration settings),
7700: origmail (scalar - email address of recipient from loncapa.conf,
7701: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 7702:
7703: Returns: comma separated list of addresses to which to send e-mail.
7704:
7705: =cut
7706:
7707: ############################################################
7708: ############################################################
7709: sub build_recipient_list {
1.619 raeburn 7710: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 7711: my @recipients;
7712: my $otheremails;
7713: my %domconfig =
7714: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
7715: if (ref($domconfig{'contacts'}) eq 'HASH') {
7716: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
7717: my @contacts = ('adminemail','supportemail');
7718: foreach my $item (@contacts) {
7719: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 7720: my $addr = $domconfig{'contacts'}{$item};
7721: if (!grep(/^\Q$addr\E$/,@recipients)) {
7722: push(@recipients,$addr);
7723: }
1.618 raeburn 7724: }
7725: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
7726: }
7727: }
1.619 raeburn 7728: } elsif ($origmail ne '') {
7729: push(@recipients,$origmail);
1.618 raeburn 7730: }
7731: if ($defmail ne '') {
7732: push(@recipients,$defmail);
7733: }
7734: if ($otheremails) {
1.619 raeburn 7735: my @others;
7736: if ($otheremails =~ /,/) {
7737: @others = split(/,/,$otheremails);
1.618 raeburn 7738: } else {
1.619 raeburn 7739: push(@others,$otheremails);
7740: }
7741: foreach my $addr (@others) {
7742: if (!grep(/^\Q$addr\E$/,@recipients)) {
7743: push(@recipients,$addr);
7744: }
1.618 raeburn 7745: }
7746: }
1.619 raeburn 7747: my $recipientlist = join(',',@recipients);
1.618 raeburn 7748: return $recipientlist;
7749: }
7750:
1.127 matthew 7751: ############################################################
7752: ############################################################
1.154 albertel 7753:
1.443 albertel 7754: sub commit_customrole {
7755: my ($udom,$uname,$url,$three,$four,$five,$start,$end) = @_;
7756: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
7757: ($start?', '.&mt('starting').' '.localtime($start):'').
7758: ($end?', ending '.localtime($end):'').': <b>'.
7759: &Apache::lonnet::assigncustomrole(
7760: $udom,$uname,$url,$three,$four,$five,$end,$start).
7761: '</b><br />';
7762: return $output;
7763: }
7764:
7765: sub commit_standardrole {
1.541 raeburn 7766: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
7767: my ($output,$logmsg,$linefeed);
7768: if ($context eq 'auto') {
7769: $linefeed = "\n";
7770: } else {
7771: $linefeed = "<br />\n";
7772: }
1.443 albertel 7773: if ($three eq 'st') {
1.541 raeburn 7774: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
7775: $one,$two,$sec,$context);
7776: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 7777: ($result eq 'unknown_course') || ($result eq 'refused')) {
7778: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 7779: } else {
1.541 raeburn 7780: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 7781: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 7782: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
7783: if ($context eq 'auto') {
7784: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
7785: } else {
7786: $output .= '<b>'.$result.'</b>'.$linefeed.
7787: &mt('Add to classlist').': <b>ok</b>';
7788: }
7789: $output .= $linefeed;
1.443 albertel 7790: }
7791: } else {
7792: $output = &mt('Assigning').' '.$three.' in '.$url.
7793: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 7794: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
7795: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start);
7796: if ($context eq 'auto') {
7797: $output .= $result.$linefeed;
7798: } else {
7799: $output .= '<b>'.$result.'</b>'.$linefeed;
7800: }
1.443 albertel 7801: }
7802: return $output;
7803: }
7804:
7805: sub commit_studentrole {
1.541 raeburn 7806: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 7807: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 7808: if ($context eq 'auto') {
7809: $linefeed = "\n";
7810: } else {
7811: $linefeed = '<br />'."\n";
7812: }
1.443 albertel 7813: if (defined($one) && defined($two)) {
7814: my $cid=$one.'_'.$two;
7815: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
7816: my $secchange = 0;
7817: my $expire_role_result;
7818: my $modify_section_result;
1.628 ! raeburn 7819: if ($oldsec ne '-1') {
! 7820: if ($oldsec ne $sec) {
1.443 albertel 7821: $secchange = 1;
1.628 ! raeburn 7822: my $now = time;
1.443 albertel 7823: my $uurl='/'.$cid;
7824: $uurl=~s/\_/\//g;
7825: if ($oldsec) {
7826: $uurl.='/'.$oldsec;
7827: }
1.626 raeburn 7828: $oldsecurl = $uurl;
1.628 ! raeburn 7829: $expire_role_result =
! 7830: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now);
! 7831: if ($env{'request.course.sec'} ne '') {
! 7832: if ($expire_role_result eq 'refused') {
! 7833: my @roles = ('st');
! 7834: my @statuses = ('previous');
! 7835: my @roledoms = ($one);
! 7836: my $withsec = 1;
! 7837: my %roleshash =
! 7838: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
! 7839: \@statuses,\@roles,\@roledoms,$withsec);
! 7840: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
! 7841: my ($oldstart,$oldend) =
! 7842: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
! 7843: if ($oldend > 0 && $oldend <= $now) {
! 7844: $expire_role_result = 'ok';
! 7845: }
! 7846: }
! 7847: }
! 7848: }
1.443 albertel 7849: $result = $expire_role_result;
7850: }
7851: }
7852: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
7853: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
7854: if ($modify_section_result =~ /^ok/) {
7855: if ($secchange == 1) {
1.628 ! raeburn 7856: if ($sec eq '') {
! 7857: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
! 7858: } else {
! 7859: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
! 7860: }
1.443 albertel 7861: } elsif ($oldsec eq '-1') {
1.628 ! raeburn 7862: if ($sec eq '') {
! 7863: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
! 7864: } else {
! 7865: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
! 7866: }
1.443 albertel 7867: } else {
1.628 ! raeburn 7868: if ($sec eq '') {
! 7869: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
! 7870: } else {
! 7871: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
! 7872: }
1.443 albertel 7873: }
7874: } else {
1.628 ! raeburn 7875: if ($secchange) {
! 7876: $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed;
! 7877: } else {
! 7878: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
! 7879: }
1.443 albertel 7880: }
7881: $result = $modify_section_result;
7882: } elsif ($secchange == 1) {
1.628 ! raeburn 7883: if ($oldsec eq '') {
! 7884: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
! 7885: } else {
! 7886: $$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
! 7887: }
1.626 raeburn 7888: if ($expire_role_result eq 'refused') {
7889: my $newsecurl = '/'.$cid;
7890: $newsecurl =~ s/\_/\//g;
7891: if ($sec ne '') {
7892: $newsecurl.='/'.$sec;
7893: }
7894: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
7895: if ($sec eq '') {
7896: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed;
7897: } else {
7898: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed;
7899: }
7900: }
7901: }
1.443 albertel 7902: }
7903: } else {
1.626 raeburn 7904: $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed;
1.443 albertel 7905: $result = "error: incomplete course id\n";
7906: }
7907: return $result;
7908: }
7909:
7910: ############################################################
7911: ############################################################
7912:
1.566 albertel 7913: sub check_clone {
1.578 raeburn 7914: my ($args,$linefeed) = @_;
1.566 albertel 7915: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
7916: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
7917: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
7918: my $clonemsg;
7919: my $can_clone = 0;
7920:
7921: if ($clonehome eq 'no_host') {
1.578 raeburn 7922: $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 7923: } else {
7924: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 7925: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 7926: $can_clone = 1;
7927: } else {
7928: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
7929: $args->{'clonedomain'},$args->{'clonecourse'});
7930: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 7931: if (grep(/^\*$/,@cloners)) {
7932: $can_clone = 1;
7933: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
7934: $can_clone = 1;
7935: } else {
7936: my %roleshash =
7937: &Apache::lonnet::get_my_roles($args->{'ccuname'},
7938: $args->{'ccdomain'},
7939: 'userroles',['active'],['cc'],
7940: [$args->{'clonedomain'}]);
7941: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
7942: $can_clone = 1;
7943: } else {
7944: $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'});
7945: }
1.566 albertel 7946: }
1.578 raeburn 7947: }
1.566 albertel 7948: }
7949: return ($can_clone, $clonemsg, $cloneid, $clonehome);
7950: }
7951:
1.444 albertel 7952: sub construct_course {
1.541 raeburn 7953: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 7954: my $outcome;
1.541 raeburn 7955: my $linefeed = '<br />'."\n";
7956: if ($context eq 'auto') {
7957: $linefeed = "\n";
7958: }
1.566 albertel 7959:
7960: #
7961: # Are we cloning?
7962: #
7963: my ($can_clone, $clonemsg, $cloneid, $clonehome);
7964: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 7965: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 7966: if ($context ne 'auto') {
1.578 raeburn 7967: if ($clonemsg ne '') {
7968: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
7969: }
1.566 albertel 7970: }
7971: $outcome .= $clonemsg.$linefeed;
7972:
7973: if (!$can_clone) {
7974: return (0,$outcome);
7975: }
7976: }
7977:
1.444 albertel 7978: #
7979: # Open course
7980: #
7981: my $crstype = lc($args->{'crstype'});
7982: my %cenv=();
7983: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
7984: $args->{'cdescr'},
7985: $args->{'curl'},
7986: $args->{'course_home'},
7987: $args->{'nonstandard'},
7988: $args->{'crscode'},
7989: $args->{'ccuname'}.':'.
7990: $args->{'ccdomain'},
7991: $args->{'crstype'});
7992:
7993: # Note: The testing routines depend on this being output; see
7994: # Utils::Course. This needs to at least be output as a comment
7995: # if anyone ever decides to not show this, and Utils::Course::new
7996: # will need to be suitably modified.
1.541 raeburn 7997: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 7998: #
7999: # Check if created correctly
8000: #
1.479 albertel 8001: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 8002: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 8003: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 8004:
1.444 albertel 8005: #
1.566 albertel 8006: # Do the cloning
8007: #
8008: if ($can_clone && $cloneid) {
8009: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
8010: if ($context ne 'auto') {
8011: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
8012: }
8013: $outcome .= $clonemsg.$linefeed;
8014: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 8015: # Copy all files
1.566 albertel 8016: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);
1.444 albertel 8017: # Restore URL
1.566 albertel 8018: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 8019: # Restore title
1.566 albertel 8020: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 8021: # restore grading mode
1.566 albertel 8022: if (defined($oldcenv{'grading'})) {
8023: $cenv{'grading'}=$oldcenv{'grading'};
8024: }
1.444 albertel 8025: # Mark as cloned
1.566 albertel 8026: $cenv{'clonedfrom'}=$cloneid;
8027: delete($cenv{'default_enrollment_start_date'});
8028: delete($cenv{'default_enrollment_end_date'});
1.444 albertel 8029: }
1.566 albertel 8030:
1.444 albertel 8031: #
8032: # Set environment (will override cloned, if existing)
8033: #
8034: my @sections = ();
8035: my @xlists = ();
8036: if ($args->{'crstype'}) {
8037: $cenv{'type'}=$args->{'crstype'};
8038: }
8039: if ($args->{'crsid'}) {
8040: $cenv{'courseid'}=$args->{'crsid'};
8041: }
8042: if ($args->{'crscode'}) {
8043: $cenv{'internal.coursecode'}=$args->{'crscode'};
8044: }
8045: if ($args->{'crsquota'} ne '') {
8046: $cenv{'internal.coursequota'}=$args->{'crsquota'};
8047: } else {
8048: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
8049: }
8050: if ($args->{'ccuname'}) {
8051: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
8052: ':'.$args->{'ccdomain'};
8053: } else {
8054: $cenv{'internal.courseowner'} = $args->{'curruser'};
8055: }
8056:
8057: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
8058: if ($args->{'crssections'}) {
8059: $cenv{'internal.sectionnums'} = '';
8060: if ($args->{'crssections'} =~ m/,/) {
8061: @sections = split/,/,$args->{'crssections'};
8062: } else {
8063: $sections[0] = $args->{'crssections'};
8064: }
8065: if (@sections > 0) {
8066: foreach my $item (@sections) {
8067: my ($sec,$gp) = split/:/,$item;
8068: my $class = $args->{'crscode'}.$sec;
8069: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
8070: $cenv{'internal.sectionnums'} .= $item.',';
8071: unless ($addcheck eq 'ok') {
8072: push @badclasses, $class;
8073: }
8074: }
8075: $cenv{'internal.sectionnums'} =~ s/,$//;
8076: }
8077: }
8078: # do not hide course coordinator from staff listing,
8079: # even if privileged
8080: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8081: # add crosslistings
8082: if ($args->{'crsxlist'}) {
8083: $cenv{'internal.crosslistings'}='';
8084: if ($args->{'crsxlist'} =~ m/,/) {
8085: @xlists = split/,/,$args->{'crsxlist'};
8086: } else {
8087: $xlists[0] = $args->{'crsxlist'};
8088: }
8089: if (@xlists > 0) {
8090: foreach my $item (@xlists) {
8091: my ($xl,$gp) = split/:/,$item;
8092: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
8093: $cenv{'internal.crosslistings'} .= $item.',';
8094: unless ($addcheck eq 'ok') {
8095: push @badclasses, $xl;
8096: }
8097: }
8098: $cenv{'internal.crosslistings'} =~ s/,$//;
8099: }
8100: }
8101: if ($args->{'autoadds'}) {
8102: $cenv{'internal.autoadds'}=$args->{'autoadds'};
8103: }
8104: if ($args->{'autodrops'}) {
8105: $cenv{'internal.autodrops'}=$args->{'autodrops'};
8106: }
8107: # check for notification of enrollment changes
8108: my @notified = ();
8109: if ($args->{'notify_owner'}) {
8110: if ($args->{'ccuname'} ne '') {
8111: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
8112: }
8113: }
8114: if ($args->{'notify_dc'}) {
8115: if ($uname ne '') {
8116: push(@notified,$uname.'@'.$udom);
8117: }
8118: }
8119: if (@notified > 0) {
8120: my $notifylist;
8121: if (@notified > 1) {
8122: $notifylist = join(',',@notified);
8123: } else {
8124: $notifylist = $notified[0];
8125: }
8126: $cenv{'internal.notifylist'} = $notifylist;
8127: }
8128: if (@badclasses > 0) {
8129: my %lt=&Apache::lonlocal::texthash(
8130: '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',
8131: 'dnhr' => 'does not have rights to access enrollment in these classes',
8132: 'adby' => 'as determined by the policies of your institution on access to official classlists'
8133: );
1.541 raeburn 8134: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
8135: ' ('.$lt{'adby'}.')';
8136: if ($context eq 'auto') {
8137: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 8138: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 8139: foreach my $item (@badclasses) {
8140: if ($context eq 'auto') {
8141: $outcome .= " - $item\n";
8142: } else {
8143: $outcome .= "<li>$item</li>\n";
8144: }
8145: }
8146: if ($context eq 'auto') {
8147: $outcome .= $linefeed;
8148: } else {
1.566 albertel 8149: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 8150: }
8151: }
1.444 albertel 8152: }
8153: if ($args->{'no_end_date'}) {
8154: $args->{'endaccess'} = 0;
8155: }
8156: $cenv{'internal.autostart'}=$args->{'enrollstart'};
8157: $cenv{'internal.autoend'}=$args->{'enrollend'};
8158: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
8159: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
8160: if ($args->{'showphotos'}) {
8161: $cenv{'internal.showphotos'}=$args->{'showphotos'};
8162: }
8163: $cenv{'internal.authtype'} = $args->{'authtype'};
8164: $cenv{'internal.autharg'} = $args->{'autharg'};
8165: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
8166: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 8167: 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');
8168: if ($context eq 'auto') {
8169: $outcome .= $krb_msg;
8170: } else {
1.566 albertel 8171: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 8172: }
8173: $outcome .= $linefeed;
1.444 albertel 8174: }
8175: }
8176: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
8177: if ($args->{'setpolicy'}) {
8178: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8179: }
8180: if ($args->{'setcontent'}) {
8181: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8182: }
8183: }
8184: if ($args->{'reshome'}) {
8185: $cenv{'reshome'}=$args->{'reshome'}.'/';
8186: $cenv{'reshome'}=~s/\/+$/\//;
8187: }
8188: #
8189: # course has keyed access
8190: #
8191: if ($args->{'setkeys'}) {
8192: $cenv{'keyaccess'}='yes';
8193: }
8194: # if specified, key authority is not course, but user
8195: # only active if keyaccess is yes
8196: if ($args->{'keyauth'}) {
1.487 albertel 8197: my ($user,$domain) = split(':',$args->{'keyauth'});
8198: $user = &LONCAPA::clean_username($user);
8199: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 8200: if ($user ne '' && $domain ne '') {
1.487 albertel 8201: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 8202: }
8203: }
8204:
8205: if ($args->{'disresdis'}) {
8206: $cenv{'pch.roles.denied'}='st';
8207: }
8208: if ($args->{'disablechat'}) {
8209: $cenv{'plc.roles.denied'}='st';
8210: }
8211:
8212: # Record we've not yet viewed the Course Initialization Helper for this
8213: # course
8214: $cenv{'course.helper.not.run'} = 1;
8215: #
8216: # Use new Randomseed
8217: #
8218: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
8219: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
8220: #
8221: # The encryption code and receipt prefix for this course
8222: #
8223: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
8224: $cenv{'internal.encpref'}=100+int(9*rand(99));
8225: #
8226: # By default, use standard grading
8227: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
8228:
1.541 raeburn 8229: $outcome .= $linefeed.&mt('Setting environment').': '.
8230: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 8231: #
8232: # Open all assignments
8233: #
8234: if ($args->{'openall'}) {
8235: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
8236: my %storecontent = ($storeunder => time,
8237: $storeunder.'.type' => 'date_start');
8238:
8239: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 8240: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 8241: }
8242: #
8243: # Set first page
8244: #
8245: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
8246: || ($cloneid)) {
1.445 albertel 8247: use LONCAPA::map;
1.444 albertel 8248: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 8249:
8250: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
8251: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
8252:
1.444 albertel 8253: $outcome .= ($fatal?$errtext:'read ok').' - ';
8254: my $title; my $url;
8255: if ($args->{'firstres'} eq 'syl') {
8256: $title='Syllabus';
8257: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
8258: } else {
8259: $title='Navigate Contents';
8260: $url='/adm/navmaps';
8261: }
1.445 albertel 8262:
8263: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
8264: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
8265:
8266: if ($errtext) { $fatal=2; }
1.541 raeburn 8267: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 8268: }
1.566 albertel 8269:
8270: return (1,$outcome);
1.444 albertel 8271: }
8272:
8273: ############################################################
8274: ############################################################
8275:
1.378 raeburn 8276: sub course_type {
8277: my ($cid) = @_;
8278: if (!defined($cid)) {
8279: $cid = $env{'request.course.id'};
8280: }
1.404 albertel 8281: if (defined($env{'course.'.$cid.'.type'})) {
8282: return $env{'course.'.$cid.'.type'};
1.378 raeburn 8283: } else {
8284: return 'Course';
1.377 raeburn 8285: }
8286: }
1.156 albertel 8287:
1.406 raeburn 8288: sub group_term {
8289: my $crstype = &course_type();
8290: my %names = (
8291: 'Course' => 'group',
8292: 'Group' => 'team',
8293: );
8294: return $names{$crstype};
8295: }
8296:
1.156 albertel 8297: sub icon {
8298: my ($file)=@_;
1.505 albertel 8299: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 8300: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 8301: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 8302: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
8303: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
8304: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
8305: $curfext.".gif") {
8306: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
8307: $curfext.".gif";
8308: }
8309: }
1.249 albertel 8310: return &lonhttpdurl($iconname);
1.154 albertel 8311: }
1.84 albertel 8312:
1.575 albertel 8313: sub lonhttpd_port {
1.215 albertel 8314: my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
8315: if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
1.574 albertel 8316: # IE doesn't like a secure page getting images from a non-secure
8317: # port (when logging we haven't parsed the browser type so default
8318: # back to secure
8319: if ((!exists($env{'browser.type'}) || $env{'browser.type'} eq 'explorer')
8320: && $ENV{'SERVER_PORT'} == 443) {
1.575 albertel 8321: return 443;
8322: }
8323: return $lonhttpd_port;
8324:
8325: }
8326:
8327: sub lonhttpdurl {
8328: my ($url)=@_;
8329:
8330: my $lonhttpd_port = &lonhttpd_port();
8331: if ($lonhttpd_port == 443) {
1.574 albertel 8332: return 'https://'.$ENV{'SERVER_NAME'}.$url;
8333: }
1.215 albertel 8334: return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
8335: }
8336:
1.213 albertel 8337: sub connection_aborted {
8338: my ($r)=@_;
8339: $r->print(" ");$r->rflush();
8340: my $c = $r->connection;
8341: return $c->aborted();
8342: }
8343:
1.221 foxr 8344: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 8345: # strings as 'strings'.
8346: sub escape_single {
1.221 foxr 8347: my ($input) = @_;
1.223 albertel 8348: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 8349: $input =~ s/\'/\\\'/g; # Esacpe the 's....
8350: return $input;
8351: }
1.223 albertel 8352:
1.222 foxr 8353: # Same as escape_single, but escape's "'s This
8354: # can be used for "strings"
8355: sub escape_double {
8356: my ($input) = @_;
8357: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
8358: $input =~ s/\"/\\\"/g; # Esacpe the "s....
8359: return $input;
8360: }
1.223 albertel 8361:
1.222 foxr 8362: # Escapes the last element of a full URL.
8363: sub escape_url {
8364: my ($url) = @_;
1.238 raeburn 8365: my @urlslices = split(/\//, $url,-1);
1.369 www 8366: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 8367: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 8368: }
1.462 albertel 8369:
8370: # -------------------------------------------------------- Initliaze user login
8371: sub init_user_environment {
1.463 albertel 8372: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 8373: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
8374:
8375: my $public=($username eq 'public' && $domain eq 'public');
8376:
8377: # See if old ID present, if so, remove
8378:
8379: my ($filename,$cookie,$userroles);
8380: my $now=time;
8381:
8382: if ($public) {
8383: my $max_public=100;
8384: my $oldest;
8385: my $oldest_time=0;
8386: for(my $next=1;$next<=$max_public;$next++) {
8387: if (-e $lonids."/publicuser_$next.id") {
8388: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
8389: if ($mtime<$oldest_time || !$oldest_time) {
8390: $oldest_time=$mtime;
8391: $oldest=$next;
8392: }
8393: } else {
8394: $cookie="publicuser_$next";
8395: last;
8396: }
8397: }
8398: if (!$cookie) { $cookie="publicuser_$oldest"; }
8399: } else {
1.463 albertel 8400: # if this isn't a robot, kill any existing non-robot sessions
8401: if (!$args->{'robot'}) {
8402: opendir(DIR,$lonids);
8403: while ($filename=readdir(DIR)) {
8404: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
8405: unlink($lonids.'/'.$filename);
8406: }
1.462 albertel 8407: }
1.463 albertel 8408: closedir(DIR);
1.462 albertel 8409: }
8410: # Give them a new cookie
1.463 albertel 8411: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
8412: : $now);
8413: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 8414:
8415: # Initialize roles
8416:
8417: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
8418: }
8419: # ------------------------------------ Check browser type and MathML capability
8420:
8421: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
8422: $clientunicode,$clientos) = &decode_user_agent($r);
8423:
8424: # -------------------------------------- Any accessibility options to remember?
8425: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
8426: foreach my $option ('imagesuppress','appletsuppress',
8427: 'embedsuppress','fontenhance','blackwhite') {
8428: if ($form->{$option} eq 'true') {
8429: &Apache::lonnet::put('environment',{$option => 'on'},
8430: $domain,$username);
8431: } else {
8432: &Apache::lonnet::del('environment',[$option],
8433: $domain,$username);
8434: }
8435: }
8436: }
8437: # ------------------------------------------------------------- Get environment
8438:
8439: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
8440: my ($tmp) = keys(%userenv);
8441: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8442: # default remote control to off
8443: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
8444: } else {
8445: undef(%userenv);
8446: }
8447: if (($userenv{'interface'}) && (!$form->{'interface'})) {
8448: $form->{'interface'}=$userenv{'interface'};
8449: }
8450: $env{'environment.remote'}=$userenv{'remote'};
8451: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
8452:
8453: # --------------- Do not trust query string to be put directly into environment
8454: foreach my $option ('imagesuppress','appletsuppress',
8455: 'embedsuppress','fontenhance','blackwhite',
8456: 'interface','localpath','localres') {
8457: $form->{$option}=~s/[\n\r\=]//gs;
8458: }
8459: # --------------------------------------------------------- Write first profile
8460:
8461: {
8462: my %initial_env =
8463: ("user.name" => $username,
8464: "user.domain" => $domain,
8465: "user.home" => $authhost,
8466: "browser.type" => $clientbrowser,
8467: "browser.version" => $clientversion,
8468: "browser.mathml" => $clientmathml,
8469: "browser.unicode" => $clientunicode,
8470: "browser.os" => $clientos,
8471: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
8472: "request.course.fn" => '',
8473: "request.course.uri" => '',
8474: "request.course.sec" => '',
8475: "request.role" => 'cm',
8476: "request.role.adv" => $env{'user.adv'},
8477: "request.host" => $ENV{'REMOTE_ADDR'},);
8478:
8479: if ($form->{'localpath'}) {
8480: $initial_env{"browser.localpath"} = $form->{'localpath'};
8481: $initial_env{"browser.localres"} = $form->{'localres'};
8482: }
8483:
8484: if ($public) {
8485: $initial_env{"environment.remote"} = "off";
8486: }
8487: if ($form->{'interface'}) {
8488: $form->{'interface'}=~s/\W//gs;
8489: $initial_env{"browser.interface"} = $form->{'interface'};
8490: $env{'browser.interface'}=$form->{'interface'};
8491: foreach my $option ('imagesuppress','appletsuppress',
8492: 'embedsuppress','fontenhance','blackwhite') {
8493: if (($form->{$option} eq 'true') ||
8494: ($userenv{$option} eq 'on')) {
8495: $initial_env{"browser.$option"} = "on";
8496: }
8497: }
8498: }
8499:
8500: $env{'user.environment'} = "$lonids/$cookie.id";
8501:
8502: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
8503: &GDBM_WRCREAT(),0640)) {
8504: &_add_to_env(\%disk_env,\%initial_env);
8505: &_add_to_env(\%disk_env,\%userenv,'environment.');
8506: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 8507: if (ref($args->{'extra_env'})) {
8508: &_add_to_env(\%disk_env,$args->{'extra_env'});
8509: }
1.462 albertel 8510: untie(%disk_env);
8511: } else {
8512: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
8513: 'Could not create environment storage in lonauth: '.$!.'</font>');
8514: return 'error: '.$!;
8515: }
8516: }
8517: $env{'request.role'}='cm';
8518: $env{'request.role.adv'}=$env{'user.adv'};
8519: $env{'browser.type'}=$clientbrowser;
8520:
8521: return $cookie;
8522:
8523: }
8524:
8525: sub _add_to_env {
8526: my ($idf,$env_data,$prefix) = @_;
8527: while (my ($key,$value) = each(%$env_data)) {
8528: $idf->{$prefix.$key} = $value;
8529: $env{$prefix.$key} = $value;
8530: }
8531: }
8532:
8533:
1.41 ng 8534: =pod
8535:
8536: =back
8537:
1.112 bowersj2 8538: =cut
1.41 ng 8539:
1.112 bowersj2 8540: 1;
8541: __END__;
1.41 ng 8542:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>