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