Annotation of loncom/interface/loncommon.pm, revision 1.671
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.671 ! raeburn 4: # $Id: loncommon.pm,v 1.670 2008/07/13 19:36:50 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.657 raeburn 70: use DateTime::TimeZone;
1.117 www 71:
1.517 raeburn 72: # ---------------------------------------------- Designs
73: use vars qw(%defaultdesign);
74:
1.22 www 75: my $readit;
76:
1.517 raeburn 77:
1.157 matthew 78: ##
79: ## Global Variables
80: ##
1.46 matthew 81:
1.643 foxr 82:
83: # ----------------------------------------------- SSI with retries:
84: #
85:
86: =pod
87:
1.648 raeburn 88: =head1 Server Side include with retries:
1.643 foxr 89:
90: =over 4
91:
1.648 raeburn 92: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 93:
94: Performs an ssi with some number of retries. Retries continue either
95: until the result is ok or until the retry count supplied by the
96: caller is exhausted.
97:
98: Inputs:
1.648 raeburn 99:
100: =over 4
101:
1.643 foxr 102: resource - Identifies the resource to insert.
1.648 raeburn 103:
1.643 foxr 104: retries - Count of the number of retries allowed.
1.648 raeburn 105:
1.643 foxr 106: form - Hash that identifies the rendering options.
107:
1.648 raeburn 108: =back
109:
110: Returns:
111:
112: =over 4
113:
1.643 foxr 114: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 115:
1.643 foxr 116: response - The response from the last attempt (which may or may not have been successful.
117:
1.648 raeburn 118: =back
119:
120: =back
121:
1.643 foxr 122: =cut
123:
124: sub ssi_with_retries {
125: my ($resource, $retries, %form) = @_;
126:
127:
128: my $ok = 0; # True if we got a good response.
129: my $content;
130: my $response;
131:
132: # Try to get the ssi done. within the retries count:
133:
134: do {
135: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
136: $ok = $response->is_success;
1.650 www 137: if (!$ok) {
138: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
139: }
1.643 foxr 140: $retries--;
141: } while (!$ok && ($retries > 0));
142:
143: if (!$ok) {
144: $content = ''; # On error return an empty content.
145: }
146: return ($content, $response);
147:
148: }
149:
150:
151:
1.20 www 152: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 153: my %language;
1.124 www 154: my %supported_language;
1.12 harris41 155: my %cprtag;
1.192 taceyjo1 156: my %scprtag;
1.351 www 157: my %fe; my %fd; my %fm;
1.41 ng 158: my %category_extensions;
1.12 harris41 159:
1.46 matthew 160: # ---------------------------------------------- Thesaurus variables
1.144 matthew 161: #
162: # %Keywords:
163: # A hash used by &keyword to determine if a word is considered a keyword.
164: # $thesaurus_db_file
165: # Scalar containing the full path to the thesaurus database.
1.46 matthew 166:
167: my %Keywords;
168: my $thesaurus_db_file;
169:
1.144 matthew 170: #
171: # Initialize values from language.tab, copyright.tab, filetypes.tab,
172: # thesaurus.tab, and filecategories.tab.
173: #
1.18 www 174: BEGIN {
1.46 matthew 175: # Variable initialization
176: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
177: #
1.22 www 178: unless ($readit) {
1.12 harris41 179: # ------------------------------------------------------------------- languages
180: {
1.158 raeburn 181: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
182: '/language.tab';
183: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 184: while (my $line = <$fh>) {
185: next if ($line=~/^\#/);
186: chomp($line);
187: my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158 raeburn 188: $language{$key}=$val.' - '.$enc;
189: if ($sup) {
190: $supported_language{$key}=$sup;
191: }
192: }
193: close($fh);
194: }
1.12 harris41 195: }
196: # ------------------------------------------------------------------ copyrights
197: {
1.158 raeburn 198: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
199: '/copyright.tab';
200: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 201: while (my $line = <$fh>) {
202: next if ($line=~/^\#/);
203: chomp($line);
204: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 205: $cprtag{$key}=$val;
206: }
207: close($fh);
208: }
1.12 harris41 209: }
1.351 www 210: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 211: {
212: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
213: '/source_copyright.tab';
214: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 215: while (my $line = <$fh>) {
216: next if ($line =~ /^\#/);
217: chomp($line);
218: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 219: $scprtag{$key}=$val;
220: }
221: close($fh);
222: }
223: }
1.63 www 224:
1.517 raeburn 225: # -------------------------------------------------------------- default domain designs
1.63 www 226: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 227: my $designfile = $designdir.'/default.tab';
228: if ( open (my $fh,"<$designfile") ) {
229: while (my $line = <$fh>) {
230: next if ($line =~ /^\#/);
231: chomp($line);
232: my ($key,$val)=(split(/\=/,$line));
233: if ($val) { $defaultdesign{$key}=$val; }
234: }
235: close($fh);
1.63 www 236: }
237:
1.15 harris41 238: # ------------------------------------------------------------- file categories
239: {
1.158 raeburn 240: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
241: '/filecategories.tab';
242: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 243: while (my $line = <$fh>) {
244: next if ($line =~ /^\#/);
245: chomp($line);
246: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 247: push @{$category_extensions{lc($category)}},$extension;
248: }
249: close($fh);
250: }
251:
1.15 harris41 252: }
1.12 harris41 253: # ------------------------------------------------------------------ file types
254: {
1.158 raeburn 255: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
256: '/filetypes.tab';
257: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 262: if ($descr ne '') {
263: $fe{$ending}=lc($emb);
264: $fd{$ending}=$descr;
1.351 www 265: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 266: }
267: }
268: close($fh);
269: }
1.12 harris41 270: }
1.22 www 271: &Apache::lonnet::logthis(
1.46 matthew 272: "<font color=yellow>INFO: Read file types</font>");
1.22 www 273: $readit=1;
1.46 matthew 274: } # end of unless($readit)
1.32 matthew 275:
276: }
1.112 bowersj2 277:
1.42 matthew 278: ###############################################################
279: ## HTML and Javascript Helper Functions ##
280: ###############################################################
281:
282: =pod
283:
1.112 bowersj2 284: =head1 HTML and Javascript Functions
1.42 matthew 285:
1.112 bowersj2 286: =over 4
287:
1.648 raeburn 288: =item * &browser_and_searcher_javascript()
1.112 bowersj2 289:
290: X<browsing, javascript>X<searching, javascript>Returns a string
291: containing javascript with two functions, C<openbrowser> and
292: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
293: tags.
1.42 matthew 294:
1.648 raeburn 295: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 296:
297: inputs: formname, elementname, only, omit
298:
299: formname and elementname indicate the name of the html form and name of
300: the element that the results of the browsing selection are to be placed in.
301:
302: Specifying 'only' will restrict the browser to displaying only files
1.185 www 303: with the given extension. Can be a comma separated list.
1.42 matthew 304:
305: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 306: with the given extension. Can be a comma separated list.
1.42 matthew 307:
1.648 raeburn 308: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 309:
310: Inputs: formname, elementname
311:
312: formname and elementname specify the name of the html form and the name
313: of the element the selection from the search results will be placed in.
1.542 raeburn 314:
1.42 matthew 315: =cut
316:
317: sub browser_and_searcher_javascript {
1.199 albertel 318: my ($mode)=@_;
319: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 320: my $resurl=&escape_single(&lastresurl());
1.42 matthew 321: return <<END;
1.219 albertel 322: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 323: var editbrowser = null;
1.135 albertel 324: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 325: var url = '$resurl/?';
1.42 matthew 326: if (editbrowser == null) {
327: url += 'launch=1&';
328: }
329: url += 'catalogmode=interactive&';
1.199 albertel 330: url += 'mode=$mode&';
1.611 albertel 331: url += 'inhibitmenu=yes&';
1.42 matthew 332: url += 'form=' + formname + '&';
333: if (only != null) {
334: url += 'only=' + only + '&';
1.217 albertel 335: } else {
336: url += 'only=&';
337: }
1.42 matthew 338: if (omit != null) {
339: url += 'omit=' + omit + '&';
1.217 albertel 340: } else {
341: url += 'omit=&';
342: }
1.135 albertel 343: if (titleelement != null) {
344: url += 'titleelement=' + titleelement + '&';
1.217 albertel 345: } else {
346: url += 'titleelement=&';
347: }
1.42 matthew 348: url += 'element=' + elementname + '';
349: var title = 'Browser';
1.435 albertel 350: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 351: options += ',width=700,height=600';
352: editbrowser = open(url,title,options,'1');
353: editbrowser.focus();
354: }
355: var editsearcher;
1.135 albertel 356: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 357: var url = '/adm/searchcat?';
358: if (editsearcher == null) {
359: url += 'launch=1&';
360: }
361: url += 'catalogmode=interactive&';
1.199 albertel 362: url += 'mode=$mode&';
1.42 matthew 363: url += 'form=' + formname + '&';
1.135 albertel 364: if (titleelement != null) {
365: url += 'titleelement=' + titleelement + '&';
1.217 albertel 366: } else {
367: url += 'titleelement=&';
368: }
1.42 matthew 369: url += 'element=' + elementname + '';
370: var title = 'Search';
1.435 albertel 371: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 372: options += ',width=700,height=600';
373: editsearcher = open(url,title,options,'1');
374: editsearcher.focus();
375: }
1.219 albertel 376: // END LON-CAPA Internal -->
1.42 matthew 377: END
1.170 www 378: }
379:
380: sub lastresurl {
1.258 albertel 381: if ($env{'environment.lastresurl'}) {
382: return $env{'environment.lastresurl'}
1.170 www 383: } else {
384: return '/res';
385: }
386: }
387:
388: sub storeresurl {
389: my $resurl=&Apache::lonnet::clutter(shift);
390: unless ($resurl=~/^\/res/) { return 0; }
391: $resurl=~s/\/$//;
392: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 393: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 394: return 1;
1.42 matthew 395: }
396:
1.74 www 397: sub studentbrowser_javascript {
1.111 www 398: unless (
1.258 albertel 399: (($env{'request.course.id'}) &&
1.302 albertel 400: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
401: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
402: '/'.$env{'request.course.sec'})
403: ))
1.258 albertel 404: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 405: ) { return ''; }
1.74 www 406: return (<<'ENDSTDBRW');
407: <script type="text/javascript" language="Javascript" >
408: var stdeditbrowser;
1.558 albertel 409: function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
1.74 www 410: var url = '/adm/pickstudent?';
411: var filter;
1.558 albertel 412: if (!ignorefilter) {
413: eval('filter=document.'+formname+'.'+uname+'.value;');
414: }
1.74 www 415: if (filter != null) {
416: if (filter != '') {
417: url += 'filter='+filter+'&';
418: }
419: }
420: url += 'form=' + formname + '&unameelement='+uname+
421: '&udomelement='+udom;
1.111 www 422: if (roleflag) { url+="&roles=1"; }
1.102 www 423: var title = 'Student_Browser';
1.74 www 424: var options = 'scrollbars=1,resizable=1,menubar=0';
425: options += ',width=700,height=600';
426: stdeditbrowser = open(url,title,options,'1');
427: stdeditbrowser.focus();
428: }
429: </script>
430: ENDSTDBRW
431: }
1.42 matthew 432:
1.74 www 433: sub selectstudent_link {
1.111 www 434: my ($form,$unameele,$udomele)=@_;
1.258 albertel 435: if ($env{'request.course.id'}) {
1.302 albertel 436: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
437: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
438: '/'.$env{'request.course.sec'})) {
1.111 www 439: return '';
440: }
441: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607 albertel 442: '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74 www 443: }
1.258 albertel 444: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111 www 445: return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119 www 446: '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111 www 447: }
448: return '';
1.91 www 449: }
450:
1.653 raeburn 451: sub authorbrowser_javascript {
452: return <<"ENDAUTHORBRW";
453: <script type="text/javascript">
454: var stdeditbrowser;
455:
456: function openauthorbrowser(formname,udom) {
457: var url = '/adm/pickauthor?';
458: url += 'form='+formname+'&roledom='+udom;
459: var title = 'Author_Browser';
460: var options = 'scrollbars=1,resizable=1,menubar=0';
461: options += ',width=700,height=600';
462: stdeditbrowser = open(url,title,options,'1');
463: stdeditbrowser.focus();
464: }
465:
466: </script>
467: ENDAUTHORBRW
468: }
469:
1.91 www 470: sub coursebrowser_javascript {
1.468 raeburn 471: my ($domainfilter,$sec_element,$formname)=@_;
1.377 raeburn 472: 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 473: my $output = '
1.538 albertel 474: <script type="text/javascript">
1.468 raeburn 475: var stdeditbrowser;'."\n";
476: $output .= <<"ENDSTDBRW";
1.377 raeburn 477: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91 www 478: var url = '/adm/pickcourse?';
1.468 raeburn 479: var domainfilter = '';
480: var formid = getFormIdByName(formname);
481: if (formid > -1) {
482: var domid = getIndexByName(formid,udom);
483: if (domid > -1) {
484: if (document.forms[formid].elements[domid].type == 'select-one') {
485: domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
486: }
487: if (document.forms[formid].elements[domid].type == 'hidden') {
488: domainfilter=document.forms[formid].elements[domid].value;
489: }
490: }
1.91 www 491: }
1.128 albertel 492: if (domainfilter != null) {
493: if (domainfilter != '') {
494: url += 'domainfilter='+domainfilter+'&';
495: }
496: }
1.91 www 497: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 498: '&cdomelement='+udom+
499: '&cnameelement='+desc;
1.468 raeburn 500: if (extra_element !=null && extra_element != '') {
1.594 raeburn 501: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 502: url += '&roleelement='+extra_element;
503: if (domainfilter == null || domainfilter == '') {
504: url += '&domainfilter='+extra_element;
505: }
1.234 raeburn 506: }
1.468 raeburn 507: else {
508: if (formname == 'portform') {
509: url += '&setroles='+extra_element;
510: }
511: }
1.230 raeburn 512: }
1.293 raeburn 513: if (multflag !=null && multflag != '') {
514: url += '&multiple='+multflag;
515: }
1.377 raeburn 516: if (crstype == 'Course/Group') {
517: if (formname == 'cu') {
518: crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
519: if (crstype == "") {
520: alert("$crs_or_grp_alert");
521: return;
522: }
523: }
524: }
525: if (crstype !=null && crstype != '') {
526: url += '&type='+crstype;
527: }
1.102 www 528: var title = 'Course_Browser';
1.91 www 529: var options = 'scrollbars=1,resizable=1,menubar=0';
530: options += ',width=700,height=600';
531: stdeditbrowser = open(url,title,options,'1');
532: stdeditbrowser.focus();
533: }
1.468 raeburn 534:
535: function getFormIdByName(formname) {
536: for (var i=0;i<document.forms.length;i++) {
537: if (document.forms[i].name == formname) {
538: return i;
539: }
540: }
541: return -1;
542: }
543:
544: function getIndexByName(formid,item) {
545: for (var i=0;i<document.forms[formid].elements.length;i++) {
546: if (document.forms[formid].elements[i].name == item) {
547: return i;
548: }
549: }
550: return -1;
551: }
1.91 www 552: ENDSTDBRW
1.468 raeburn 553: if ($sec_element ne '') {
554: $output .= &setsec_javascript($sec_element,$formname);
555: }
556: $output .= '
557: </script>';
558: return $output;
559: }
560:
561: sub setsec_javascript {
562: my ($sec_element,$formname) = @_;
563: my $setsections = qq|
564: function setSect(sectionlist) {
1.629 raeburn 565: var sectionsArray = new Array();
566: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
567: sectionsArray = sectionlist.split(",");
568: }
1.468 raeburn 569: var numSections = sectionsArray.length;
570: document.$formname.$sec_element.length = 0;
571: if (numSections == 0) {
572: document.$formname.$sec_element.multiple=false;
573: document.$formname.$sec_element.size=1;
574: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
575: } else {
576: if (numSections == 1) {
577: document.$formname.$sec_element.multiple=false;
578: document.$formname.$sec_element.size=1;
579: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
580: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
581: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
582: } else {
583: for (var i=0; i<numSections; i++) {
584: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
585: }
586: document.$formname.$sec_element.multiple=true
587: if (numSections < 3) {
588: document.$formname.$sec_element.size=numSections;
589: } else {
590: document.$formname.$sec_element.size=3;
591: }
592: document.$formname.$sec_element.options[0].selected = false
593: }
594: }
1.91 www 595: }
1.468 raeburn 596: |;
597: return $setsections;
598: }
599:
1.91 www 600:
601: sub selectcourse_link {
1.377 raeburn 602: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492 albertel 603: return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
604: '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74 www 605: }
1.42 matthew 606:
1.653 raeburn 607: sub selectauthor_link {
608: my ($form,$udom)=@_;
609: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
610: &mt('Select Author').'</a>';
611: }
612:
1.273 raeburn 613: sub check_uncheck_jscript {
614: my $jscript = <<"ENDSCRT";
615: function checkAll(field) {
616: if (field.length > 0) {
617: for (i = 0; i < field.length; i++) {
618: field[i].checked = true ;
619: }
620: } else {
621: field.checked = true
622: }
623: }
624:
625: function uncheckAll(field) {
626: if (field.length > 0) {
627: for (i = 0; i < field.length; i++) {
628: field[i].checked = false ;
1.543 albertel 629: }
630: } else {
1.273 raeburn 631: field.checked = false ;
632: }
633: }
634: ENDSCRT
635: return $jscript;
636: }
637:
1.656 www 638: sub select_timezone {
1.659 raeburn 639: my ($name,$selected,$onchange,$includeempty)=@_;
640: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
641: if ($includeempty) {
642: $output .= '<option value=""';
643: if (($selected eq '') || ($selected eq 'local')) {
644: $output .= ' selected="selected" ';
645: }
646: $output .= '> </option>';
647: }
1.657 raeburn 648: my @timezones = DateTime::TimeZone->all_names;
649: foreach my $tzone (@timezones) {
650: $output.= '<option value="'.$tzone.'"';
651: if ($tzone eq $selected) {
652: $output.=' selected="selected"';
653: }
654: $output.=">$tzone</option>\n";
1.656 www 655: }
656: $output.="</select>";
657: return $output;
658: }
1.273 raeburn 659:
1.42 matthew 660: =pod
1.36 matthew 661:
1.648 raeburn 662: =item * &linked_select_forms(...)
1.36 matthew 663:
664: linked_select_forms returns a string containing a <script></script> block
665: and html for two <select> menus. The select menus will be linked in that
666: changing the value of the first menu will result in new values being placed
667: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 668: order unless a defined order is provided.
1.36 matthew 669:
670: linked_select_forms takes the following ordered inputs:
671:
672: =over 4
673:
1.112 bowersj2 674: =item * $formname, the name of the <form> tag
1.36 matthew 675:
1.112 bowersj2 676: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 677:
1.112 bowersj2 678: =item * $firstdefault, the default value for the first menu
1.36 matthew 679:
1.112 bowersj2 680: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 681:
1.112 bowersj2 682: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 683:
1.112 bowersj2 684: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 685:
1.609 raeburn 686: =item * $menuorder, the order of values in the first menu
687:
1.41 ng 688: =back
689:
1.36 matthew 690: Below is an example of such a hash. Only the 'text', 'default', and
691: 'select2' keys must appear as stated. keys(%menu) are the possible
692: values for the first select menu. The text that coincides with the
1.41 ng 693: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 694: and text for the second menu are given in the hash pointed to by
695: $menu{$choice1}->{'select2'}.
696:
1.112 bowersj2 697: my %menu = ( A1 => { text =>"Choice A1" ,
698: default => "B3",
699: select2 => {
700: B1 => "Choice B1",
701: B2 => "Choice B2",
702: B3 => "Choice B3",
703: B4 => "Choice B4"
1.609 raeburn 704: },
705: order => ['B4','B3','B1','B2'],
1.112 bowersj2 706: },
707: A2 => { text =>"Choice A2" ,
708: default => "C2",
709: select2 => {
710: C1 => "Choice C1",
711: C2 => "Choice C2",
712: C3 => "Choice C3"
1.609 raeburn 713: },
714: order => ['C2','C1','C3'],
1.112 bowersj2 715: },
716: A3 => { text =>"Choice A3" ,
717: default => "D6",
718: select2 => {
719: D1 => "Choice D1",
720: D2 => "Choice D2",
721: D3 => "Choice D3",
722: D4 => "Choice D4",
723: D5 => "Choice D5",
724: D6 => "Choice D6",
725: D7 => "Choice D7"
1.609 raeburn 726: },
727: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 728: }
729: );
1.36 matthew 730:
731: =cut
732:
733: sub linked_select_forms {
734: my ($formname,
735: $middletext,
736: $firstdefault,
737: $firstselectname,
738: $secondselectname,
1.609 raeburn 739: $hashref,
740: $menuorder,
1.36 matthew 741: ) = @_;
742: my $second = "document.$formname.$secondselectname";
743: my $first = "document.$formname.$firstselectname";
744: # output the javascript to do the changing
745: my $result = '';
1.219 albertel 746: $result.="<script type=\"text/javascript\">\n";
1.36 matthew 747: $result.="var select2data = new Object();\n";
748: $" = '","';
749: my $debug = '';
750: foreach my $s1 (sort(keys(%$hashref))) {
751: $result.="select2data.d_$s1 = new Object();\n";
752: $result.="select2data.d_$s1.def = new String('".
753: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 754: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 755: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 756: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
757: @s2values = @{$hashref->{$s1}->{'order'}};
758: }
1.36 matthew 759: $result.="\"@s2values\");\n";
760: $result.="select2data.d_$s1.texts = new Array(";
761: my @s2texts;
762: foreach my $value (@s2values) {
763: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
764: }
765: $result.="\"@s2texts\");\n";
766: }
767: $"=' ';
768: $result.= <<"END";
769:
770: function select1_changed() {
771: // Determine new choice
772: var newvalue = "d_" + $first.value;
773: // update select2
774: var values = select2data[newvalue].values;
775: var texts = select2data[newvalue].texts;
776: var select2def = select2data[newvalue].def;
777: var i;
778: // out with the old
779: for (i = 0; i < $second.options.length; i++) {
780: $second.options[i] = null;
781: }
782: // in with the nuclear
783: for (i=0;i<values.length; i++) {
784: $second.options[i] = new Option(values[i]);
1.143 matthew 785: $second.options[i].value = values[i];
1.36 matthew 786: $second.options[i].text = texts[i];
787: if (values[i] == select2def) {
788: $second.options[i].selected = true;
789: }
790: }
791: }
792: </script>
793: END
794: # output the initial values for the selection lists
795: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609 raeburn 796: my @order = sort(keys(%{$hashref}));
797: if (ref($menuorder) eq 'ARRAY') {
798: @order = @{$menuorder};
799: }
800: foreach my $value (@order) {
1.36 matthew 801: $result.=" <option value=\"$value\" ";
1.253 albertel 802: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 803: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 804: }
805: $result .= "</select>\n";
806: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
807: $result .= $middletext;
808: $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
809: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 810:
811: my @secondorder = sort(keys(%select2));
812: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
813: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
814: }
815: foreach my $value (@secondorder) {
1.36 matthew 816: $result.=" <option value=\"$value\" ";
1.253 albertel 817: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 818: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 819: }
820: $result .= "</select>\n";
821: # return $debug;
822: return $result;
823: } # end of sub linked_select_forms {
824:
1.45 matthew 825: =pod
1.44 bowersj2 826:
1.648 raeburn 827: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44 bowersj2 828:
1.112 bowersj2 829: Returns a string corresponding to an HTML link to the given help
830: $topic, where $topic corresponds to the name of a .tex file in
831: /home/httpd/html/adm/help/tex, with underscores replaced by
832: spaces.
833:
834: $text will optionally be linked to the same topic, allowing you to
835: link text in addition to the graphic. If you do not want to link
836: text, but wish to specify one of the later parameters, pass an
837: empty string.
838:
839: $stayOnPage is a value that will be interpreted as a boolean. If true,
840: the link will not open a new window. If false, the link will open
841: a new window using Javascript. (Default is false.)
842:
843: $width and $height are optional numerical parameters that will
844: override the width and height of the popped up window, which may
845: be useful for certain help topics with big pictures included.
1.44 bowersj2 846:
847: =cut
848:
849: sub help_open_topic {
1.48 bowersj2 850: my ($topic, $text, $stayOnPage, $width, $height) = @_;
851: $text = "" if (not defined $text);
1.44 bowersj2 852: $stayOnPage = 0 if (not defined $stayOnPage);
1.552 banghart 853: if ($env{'browser.interface'} eq 'textual') {
1.79 www 854: $stayOnPage=1;
855: }
1.44 bowersj2 856: $width = 350 if (not defined $width);
857: $height = 400 if (not defined $height);
858: my $filename = $topic;
859: $filename =~ s/ /_/g;
860:
1.48 bowersj2 861: my $template = "";
862: my $link;
1.572 banghart 863:
1.159 www 864: $topic=~s/\W/\_/g;
1.44 bowersj2 865:
1.572 banghart 866: if (!$stayOnPage) {
1.72 bowersj2 867: $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 868: } else {
1.48 bowersj2 869: $link = "/adm/help/${filename}.hlp";
870: }
871:
872: # Add the text
1.572 banghart 873: if ($text ne "") {
1.77 www 874: $template .=
1.572 banghart 875: "<table bgcolor='#3333AA' cellspacing='1' cellpadding='1' border='0'><tr>".
876: "<td bgcolor='#5555FF'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.48 bowersj2 877: }
878:
879: # Add the graphic
1.179 matthew 880: my $title = &mt('Online Help');
1.667 raeburn 881: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.48 bowersj2 882: $template .= <<"ENDTEMPLATE";
1.436 albertel 883: <a target="_top" href="$link" title="$title"><img src="$helpicon" border="0" alt="(Help: $topic)" /></a>
1.44 bowersj2 884: ENDTEMPLATE
1.78 www 885: if ($text ne '') { $template.='</td></tr></table>' };
1.44 bowersj2 886: return $template;
887:
1.106 bowersj2 888: }
889:
890: # This is a quicky function for Latex cheatsheet editing, since it
891: # appears in at least four places
892: sub helpLatexCheatsheet {
893: my $other = shift;
894: my $addOther = '';
895: if ($other) {
896: $addOther = Apache::loncommon::help_open_topic($other, shift,
897: undef, undef, 600) .
898: '</td><td>';
899: }
900: return '<table><tr><td>'.
901: $addOther .
1.636 raeburn 902: &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
1.106 bowersj2 903: undef,undef,600)
904: .'</td><td>'.
1.636 raeburn 905: &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
1.106 bowersj2 906: undef,undef,600)
907: .'</td></tr></table>';
1.172 www 908: }
909:
1.430 albertel 910: sub general_help {
911: my $helptopic='Student_Intro';
912: if ($env{'request.role'}=~/^(ca|au)/) {
913: $helptopic='Authoring_Intro';
914: } elsif ($env{'request.role'}=~/^cc/) {
915: $helptopic='Course_Coordination_Intro';
916: }
917: return $helptopic;
918: }
919:
920: sub update_help_link {
921: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
922: my $origurl = $ENV{'REQUEST_URI'};
923: $origurl=~s|^/~|/priv/|;
924: my $timestamp = time;
925: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
926: $$datum = &escape($$datum);
927: }
928:
929: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
930: my $output .= <<"ENDOUTPUT";
931: <script type="text/javascript">
932: banner_link = '$banner_link';
933: </script>
934: ENDOUTPUT
935: return $output;
936: }
937:
938: # now just updates the help link and generates a blue icon
1.193 raeburn 939: sub help_open_menu {
1.430 albertel 940: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 941: = @_;
1.430 albertel 942: $stayOnPage = 0 if (not defined $stayOnPage);
1.572 banghart 943: # only use pop-up help (stayOnPage == 0)
1.552 banghart 944: # if environment.remote is on (using remote control UI)
1.572 banghart 945: if ($env{'browser.interface'} eq 'textual' ||
946: $env{'environment.remote'} eq 'off' ) {
1.552 banghart 947: $stayOnPage=1;
1.430 albertel 948: }
949: my $output;
950: if ($component_help) {
951: if (!$text) {
952: $output=&help_open_topic($component_help,undef,$stayOnPage,
953: $width,$height);
954: } else {
955: my $help_text;
956: $help_text=&unescape($topic);
957: $output='<table><tr><td>'.
958: &help_open_topic($component_help,$help_text,$stayOnPage,
959: $width,$height).'</td></tr></table>';
960: }
961: }
962: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
963: return $output.$banner_link;
964: }
965:
966: sub top_nav_help {
967: my ($text) = @_;
1.436 albertel 968: $text = &mt($text);
1.572 banghart 969: my $stay_on_page =
1.436 albertel 970: ($env{'browser.interface'} eq 'textual' ||
971: $env{'environment.remote'} eq 'off' );
1.572 banghart 972: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 973: : "javascript:helpMenu('open')";
1.572 banghart 974: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 975:
1.201 raeburn 976: my $title = &mt('Get help');
1.436 albertel 977:
978: return <<"END";
979: $banner_link
980: <a href="$link" title="$title">$text</a>
981: END
982: }
983:
984: sub help_menu_js {
985: my ($text) = @_;
986:
987: my $stayOnPage =
988: ($env{'browser.interface'} eq 'textual' ||
989: $env{'environment.remote'} eq 'off' );
990:
991: my $width = 620;
992: my $height = 600;
1.430 albertel 993: my $helptopic=&general_help();
994: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 995: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 996: my $start_page =
997: &Apache::loncommon::start_page('Help Menu', undef,
998: {'frameset' => 1,
999: 'js_ready' => 1,
1000: 'add_entries' => {
1001: 'border' => '0',
1.579 raeburn 1002: 'rows' => "110,*",},});
1.331 albertel 1003: my $end_page =
1004: &Apache::loncommon::end_page({'frameset' => 1,
1005: 'js_ready' => 1,});
1006:
1.436 albertel 1007: my $template .= <<"ENDTEMPLATE";
1008: <script type="text/javascript">
1.253 albertel 1009: // <!-- BEGIN LON-CAPA Internal
1010: // <![CDATA[
1.430 albertel 1011: var banner_link = '';
1.243 raeburn 1012: function helpMenu(target) {
1013: var caller = this;
1014: if (target == 'open') {
1015: var newWindow = null;
1016: try {
1.262 albertel 1017: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1018: }
1019: catch(error) {
1020: writeHelp(caller);
1021: return;
1022: }
1023: if (newWindow) {
1024: caller = newWindow;
1025: }
1.193 raeburn 1026: }
1.243 raeburn 1027: writeHelp(caller);
1028: return;
1029: }
1030: function writeHelp(caller) {
1.430 albertel 1031: caller.document.writeln('$start_page<frame name="bannerframe" src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243 raeburn 1032: caller.document.close()
1033: caller.focus()
1.193 raeburn 1034: }
1.253 albertel 1035: // ]]>
1.219 albertel 1036: // END LON-CAPA Internal -->
1.436 albertel 1037: </script>
1.193 raeburn 1038: ENDTEMPLATE
1039: return $template;
1040: }
1041:
1.172 www 1042: sub help_open_bug {
1043: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1044: unless ($env{'user.adv'}) { return ''; }
1.172 www 1045: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1046: $text = "" if (not defined $text);
1047: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1048: if ($env{'browser.interface'} eq 'textual' ||
1049: $env{'environment.remote'} eq 'off' ) {
1.172 www 1050: $stayOnPage=1;
1051: }
1.184 albertel 1052: $width = 600 if (not defined $width);
1053: $height = 600 if (not defined $height);
1.172 www 1054:
1055: $topic=~s/\W+/\+/g;
1056: my $link='';
1057: my $template='';
1.379 albertel 1058: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1059: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1060: if (!$stayOnPage)
1061: {
1062: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1063: }
1064: else
1065: {
1066: $link = $url;
1067: }
1068: # Add the text
1069: if ($text ne "")
1070: {
1071: $template .=
1072: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1073: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1074: }
1075:
1076: # Add the graphic
1.179 matthew 1077: my $title = &mt('Report a Bug');
1.215 albertel 1078: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1079: $template .= <<"ENDTEMPLATE";
1.436 albertel 1080: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1081: ENDTEMPLATE
1082: if ($text ne '') { $template.='</td></tr></table>' };
1083: return $template;
1084:
1085: }
1086:
1087: sub help_open_faq {
1088: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1089: unless ($env{'user.adv'}) { return ''; }
1.172 www 1090: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1091: $text = "" if (not defined $text);
1092: $stayOnPage = 0 if (not defined $stayOnPage);
1.258 albertel 1093: if ($env{'browser.interface'} eq 'textual' ||
1094: $env{'environment.remote'} eq 'off' ) {
1.172 www 1095: $stayOnPage=1;
1096: }
1097: $width = 350 if (not defined $width);
1098: $height = 400 if (not defined $height);
1099:
1100: $topic=~s/\W+/\+/g;
1101: my $link='';
1102: my $template='';
1103: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1104: if (!$stayOnPage)
1105: {
1106: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1107: }
1108: else
1109: {
1110: $link = $url;
1111: }
1112:
1113: # Add the text
1114: if ($text ne "")
1115: {
1116: $template .=
1.173 www 1117: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.436 albertel 1118: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><font color='#FFFFFF' size='2'>$text</font></a>";
1.172 www 1119: }
1120:
1121: # Add the graphic
1.179 matthew 1122: my $title = &mt('View the FAQ');
1.215 albertel 1123: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1124: $template .= <<"ENDTEMPLATE";
1.436 albertel 1125: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1126: ENDTEMPLATE
1127: if ($text ne '') { $template.='</td></tr></table>' };
1128: return $template;
1129:
1.44 bowersj2 1130: }
1.37 matthew 1131:
1.180 matthew 1132: ###############################################################
1133: ###############################################################
1134:
1.45 matthew 1135: =pod
1136:
1.648 raeburn 1137: =item * &change_content_javascript():
1.256 matthew 1138:
1139: This and the next function allow you to create small sections of an
1140: otherwise static HTML page that you can update on the fly with
1141: Javascript, even in Netscape 4.
1142:
1143: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1144: must be written to the HTML page once. It will prove the Javascript
1145: function "change(name, content)". Calling the change function with the
1146: name of the section
1147: you want to update, matching the name passed to C<changable_area>, and
1148: the new content you want to put in there, will put the content into
1149: that area.
1150:
1151: B<Note>: Netscape 4 only reserves enough space for the changable area
1152: to contain room for the original contents. You need to "make space"
1153: for whatever changes you wish to make, and be B<sure> to check your
1154: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1155: it's adequate for updating a one-line status display, but little more.
1156: This script will set the space to 100% width, so you only need to
1157: worry about height in Netscape 4.
1158:
1159: Modern browsers are much less limiting, and if you can commit to the
1160: user not using Netscape 4, this feature may be used freely with
1161: pretty much any HTML.
1162:
1163: =cut
1164:
1165: sub change_content_javascript {
1166: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1167: if ($env{'browser.type'} eq 'netscape' &&
1168: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1169: return (<<NETSCAPE4);
1170: function change(name, content) {
1171: doc = document.layers[name+"___escape"].layers[0].document;
1172: doc.open();
1173: doc.write(content);
1174: doc.close();
1175: }
1176: NETSCAPE4
1177: } else {
1178: # Otherwise, we need to use semi-standards-compliant code
1179: # (technically, "innerHTML" isn't standard but the equivalent
1180: # is really scary, and every useful browser supports it
1181: return (<<DOMBASED);
1182: function change(name, content) {
1183: element = document.getElementById(name);
1184: element.innerHTML = content;
1185: }
1186: DOMBASED
1187: }
1188: }
1189:
1190: =pod
1191:
1.648 raeburn 1192: =item * &changable_area($name,$origContent):
1.256 matthew 1193:
1194: This provides a "changable area" that can be modified on the fly via
1195: the Javascript code provided in C<change_content_javascript>. $name is
1196: the name you will use to reference the area later; do not repeat the
1197: same name on a given HTML page more then once. $origContent is what
1198: the area will originally contain, which can be left blank.
1199:
1200: =cut
1201:
1202: sub changable_area {
1203: my ($name, $origContent) = @_;
1204:
1.258 albertel 1205: if ($env{'browser.type'} eq 'netscape' &&
1206: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1207: # If this is netscape 4, we need to use the Layer tag
1208: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1209: } else {
1210: return "<span id='$name'>$origContent</span>";
1211: }
1212: }
1213:
1214: =pod
1215:
1.648 raeburn 1216: =item * &viewport_geometry_js
1.590 raeburn 1217:
1218: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1219:
1220: =cut
1221:
1222:
1223: sub viewport_geometry_js {
1224: return <<"GEOMETRY";
1225: var Geometry = {};
1226: function init_geometry() {
1227: if (Geometry.init) { return };
1228: Geometry.init=1;
1229: if (window.innerHeight) {
1230: Geometry.getViewportHeight = function() { return window.innerHeight; };
1231: Geometry.getViewportWidth = function() { return window.innerWidth; };
1232: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1233: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1234: }
1235: else if (document.documentElement && document.documentElement.clientHeight) {
1236: Geometry.getViewportHeight =
1237: function() { return document.documentElement.clientHeight; };
1238: Geometry.getViewportWidth =
1239: function() { return document.documentElement.clientWidth; };
1240:
1241: Geometry.getHorizontalScroll =
1242: function() { return document.documentElement.scrollLeft; };
1243: Geometry.getVerticalScroll =
1244: function() { return document.documentElement.scrollTop; };
1245: }
1246: else if (document.body.clientHeight) {
1247: Geometry.getViewportHeight =
1248: function() { return document.body.clientHeight; };
1249: Geometry.getViewportWidth =
1250: function() { return document.body.clientWidth; };
1251: Geometry.getHorizontalScroll =
1252: function() { return document.body.scrollLeft; };
1253: Geometry.getVerticalScroll =
1254: function() { return document.body.scrollTop; };
1255: }
1256: }
1257:
1258: GEOMETRY
1259: }
1260:
1261: =pod
1262:
1.648 raeburn 1263: =item * &viewport_size_js()
1.590 raeburn 1264:
1265: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1266:
1267: =cut
1268:
1269: sub viewport_size_js {
1270: my $geometry = &viewport_geometry_js();
1271: return <<"DIMS";
1272:
1273: $geometry
1274:
1275: function getViewportDims(width,height) {
1276: init_geometry();
1277: width.value = Geometry.getViewportWidth();
1278: height.value = Geometry.getViewportHeight();
1279: return;
1280: }
1281:
1282: DIMS
1283: }
1284:
1285: =pod
1286:
1.648 raeburn 1287: =item * &resize_textarea_js()
1.565 albertel 1288:
1289: emits the needed javascript to resize a textarea to be as big as possible
1290:
1291: creates a function resize_textrea that takes two IDs first should be
1292: the id of the element to resize, second should be the id of a div that
1293: surrounds everything that comes after the textarea, this routine needs
1294: to be attached to the <body> for the onload and onresize events.
1295:
1.648 raeburn 1296: =back
1.565 albertel 1297:
1298: =cut
1299:
1300: sub resize_textarea_js {
1.590 raeburn 1301: my $geometry = &viewport_geometry_js();
1.565 albertel 1302: return <<"RESIZE";
1303: <script type="text/javascript">
1.590 raeburn 1304: $geometry
1.565 albertel 1305:
1.588 albertel 1306: function getX(element) {
1307: var x = 0;
1308: while (element) {
1309: x += element.offsetLeft;
1310: element = element.offsetParent;
1311: }
1312: return x;
1313: }
1314: function getY(element) {
1315: var y = 0;
1316: while (element) {
1317: y += element.offsetTop;
1318: element = element.offsetParent;
1319: }
1320: return y;
1321: }
1322:
1323:
1.565 albertel 1324: function resize_textarea(textarea_id,bottom_id) {
1325: init_geometry();
1326: var textarea = document.getElementById(textarea_id);
1327: //alert(textarea);
1328:
1.588 albertel 1329: var textarea_top = getY(textarea);
1.565 albertel 1330: var textarea_height = textarea.offsetHeight;
1331: var bottom = document.getElementById(bottom_id);
1.588 albertel 1332: var bottom_top = getY(bottom);
1.565 albertel 1333: var bottom_height = bottom.offsetHeight;
1334: var window_height = Geometry.getViewportHeight();
1.588 albertel 1335: var fudge = 23;
1.565 albertel 1336: var new_height = window_height-fudge-textarea_top-bottom_height;
1337: if (new_height < 300) {
1338: new_height = 300;
1339: }
1340: textarea.style.height=new_height+'px';
1341: }
1342: </script>
1343: RESIZE
1344:
1345: }
1346:
1347: =pod
1348:
1.256 matthew 1349: =head1 Excel and CSV file utility routines
1350:
1351: =over 4
1352:
1353: =cut
1354:
1355: ###############################################################
1356: ###############################################################
1357:
1358: =pod
1359:
1.648 raeburn 1360: =item * &csv_translate($text)
1.37 matthew 1361:
1.185 www 1362: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1363: format.
1364:
1365: =cut
1366:
1.180 matthew 1367: ###############################################################
1368: ###############################################################
1.37 matthew 1369: sub csv_translate {
1370: my $text = shift;
1371: $text =~ s/\"/\"\"/g;
1.209 albertel 1372: $text =~ s/\n/ /g;
1.37 matthew 1373: return $text;
1374: }
1.180 matthew 1375:
1376: ###############################################################
1377: ###############################################################
1378:
1379: =pod
1380:
1.648 raeburn 1381: =item * &define_excel_formats()
1.180 matthew 1382:
1383: Define some commonly used Excel cell formats.
1384:
1385: Currently supported formats:
1386:
1387: =over 4
1388:
1389: =item header
1390:
1391: =item bold
1392:
1393: =item h1
1394:
1395: =item h2
1396:
1397: =item h3
1398:
1.256 matthew 1399: =item h4
1400:
1401: =item i
1402:
1.180 matthew 1403: =item date
1404:
1405: =back
1406:
1407: Inputs: $workbook
1408:
1409: Returns: $format, a hash reference.
1410:
1411: =cut
1412:
1413: ###############################################################
1414: ###############################################################
1415: sub define_excel_formats {
1416: my ($workbook) = @_;
1417: my $format;
1418: $format->{'header'} = $workbook->add_format(bold => 1,
1419: bottom => 1,
1420: align => 'center');
1421: $format->{'bold'} = $workbook->add_format(bold=>1);
1422: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1423: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1424: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1425: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1426: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1427: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1428: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1429: return $format;
1430: }
1431:
1432: ###############################################################
1433: ###############################################################
1.113 bowersj2 1434:
1435: =pod
1436:
1.648 raeburn 1437: =item * &create_workbook()
1.255 matthew 1438:
1439: Create an Excel worksheet. If it fails, output message on the
1440: request object and return undefs.
1441:
1442: Inputs: Apache request object
1443:
1444: Returns (undef) on failure,
1445: Excel worksheet object, scalar with filename, and formats
1446: from &Apache::loncommon::define_excel_formats on success
1447:
1448: =cut
1449:
1450: ###############################################################
1451: ###############################################################
1452: sub create_workbook {
1453: my ($r) = @_;
1454: #
1455: # Create the excel spreadsheet
1456: my $filename = '/prtspool/'.
1.258 albertel 1457: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1458: time.'_'.rand(1000000000).'.xls';
1459: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1460: if (! defined($workbook)) {
1461: $r->log_error("Error creating excel spreadsheet $filename: $!");
1462: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1463: "This error has been logged. ".
1464: "Please alert your LON-CAPA administrator").
1465: '</p>');
1466: return (undef);
1467: }
1468: #
1469: $workbook->set_tempdir('/home/httpd/perl/tmp');
1470: #
1471: my $format = &Apache::loncommon::define_excel_formats($workbook);
1472: return ($workbook,$filename,$format);
1473: }
1474:
1475: ###############################################################
1476: ###############################################################
1477:
1478: =pod
1479:
1.648 raeburn 1480: =item * &create_text_file()
1.113 bowersj2 1481:
1.542 raeburn 1482: Create a file to write to and eventually make available to the user.
1.256 matthew 1483: If file creation fails, outputs an error message on the request object and
1484: return undefs.
1.113 bowersj2 1485:
1.256 matthew 1486: Inputs: Apache request object, and file suffix
1.113 bowersj2 1487:
1.256 matthew 1488: Returns (undef) on failure,
1489: Filehandle and filename on success.
1.113 bowersj2 1490:
1491: =cut
1492:
1.256 matthew 1493: ###############################################################
1494: ###############################################################
1495: sub create_text_file {
1496: my ($r,$suffix) = @_;
1497: if (! defined($suffix)) { $suffix = 'txt'; };
1498: my $fh;
1499: my $filename = '/prtspool/'.
1.258 albertel 1500: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1501: time.'_'.rand(1000000000).'.'.$suffix;
1502: $fh = Apache::File->new('>/home/httpd'.$filename);
1503: if (! defined($fh)) {
1504: $r->log_error("Couldn't open $filename for output $!");
1505: $r->print("Problems occured in creating the output file. ".
1506: "This error has been logged. ".
1507: "Please alert your LON-CAPA administrator.");
1.113 bowersj2 1508: }
1.256 matthew 1509: return ($fh,$filename)
1.113 bowersj2 1510: }
1511:
1512:
1.256 matthew 1513: =pod
1.113 bowersj2 1514:
1515: =back
1516:
1517: =cut
1.37 matthew 1518:
1519: ###############################################################
1.33 matthew 1520: ## Home server <option> list generating code ##
1521: ###############################################################
1.35 matthew 1522:
1.169 www 1523: # ------------------------------------------
1524:
1525: sub domain_select {
1526: my ($name,$value,$multiple)=@_;
1527: my %domains=map {
1.514 albertel 1528: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1529: } &Apache::lonnet::all_domains();
1.169 www 1530: if ($multiple) {
1531: $domains{''}=&mt('Any domain');
1.550 albertel 1532: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1533: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1534: } else {
1.550 albertel 1535: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169 www 1536: return &select_form($name,$value,%domains);
1537: }
1538: }
1539:
1.282 albertel 1540: #-------------------------------------------
1541:
1542: =pod
1543:
1.519 raeburn 1544: =head1 Routines for form select boxes
1545:
1546: =over 4
1547:
1.648 raeburn 1548: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1549:
1550: Returns a string containing a <select> element int multiple mode
1551:
1552:
1553: Args:
1554: $name - name of the <select> element
1.506 raeburn 1555: $value - scalar or array ref of values that should already be selected
1.282 albertel 1556: $size - number of rows long the select element is
1.283 albertel 1557: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1558: (shown text should already have been &mt())
1.506 raeburn 1559: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1560:
1.282 albertel 1561: =cut
1562:
1563: #-------------------------------------------
1.169 www 1564: sub multiple_select_form {
1.284 albertel 1565: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1566: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1567: my $output='';
1.191 matthew 1568: if (! defined($size)) {
1569: $size = 4;
1.283 albertel 1570: if (scalar(keys(%$hash))<4) {
1571: $size = scalar(keys(%$hash));
1.191 matthew 1572: }
1573: }
1.169 www 1574: $output.="\n<select name='$name' size='$size' multiple='1'>";
1.501 banghart 1575: my @order;
1.506 raeburn 1576: if (ref($order) eq 'ARRAY') {
1577: @order = @{$order};
1578: } else {
1579: @order = sort(keys(%$hash));
1.501 banghart 1580: }
1581: if (exists($$hash{'select_form_order'})) {
1582: @order = @{$$hash{'select_form_order'}};
1583: }
1584:
1.284 albertel 1585: foreach my $key (@order) {
1.356 albertel 1586: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1587: $output.='selected="selected" ' if ($selected{$key});
1588: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1589: }
1590: $output.="</select>\n";
1591: return $output;
1592: }
1593:
1.88 www 1594: #-------------------------------------------
1595:
1596: =pod
1597:
1.648 raeburn 1598: =item * &select_form($defdom,$name,%hash)
1.88 www 1599:
1600: Returns a string containing a <select name='$name' size='1'> form to
1601: allow a user to select options from a hash option_name => displayed text.
1602: See lonrights.pm for an example invocation and use.
1603:
1604: =cut
1605:
1606: #-------------------------------------------
1607: sub select_form {
1608: my ($def,$name,%hash) = @_;
1609: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128 albertel 1610: my @keys;
1611: if (exists($hash{'select_form_order'})) {
1612: @keys=@{$hash{'select_form_order'}};
1613: } else {
1614: @keys=sort(keys(%hash));
1615: }
1.356 albertel 1616: foreach my $key (@keys) {
1617: $selectform.=
1618: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
1619: ($key eq $def ? 'selected="selected" ' : '').
1620: ">".&mt($hash{$key})."</option>\n";
1.88 www 1621: }
1622: $selectform.="</select>";
1623: return $selectform;
1624: }
1625:
1.475 www 1626: # For display filters
1627:
1628: sub display_filter {
1629: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 1630: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.475 www 1631: return '<nobr><label>'.&mt('Records [_1]',
1632: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
1633: (&mt('all'),10,20,50,100,1000,10000))).
1.478 www 1634: '</label></nobr> <nobr>'.
1.475 www 1635: &mt('Filter [_1]',
1.477 www 1636: &select_form($env{'form.displayfilter'},
1637: 'displayfilter',
1638: ('currentfolder' => 'Current folder/page',
1639: 'containing' => 'Containing phrase',
1640: 'none' => 'None'))).
1.478 www 1641: '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></nobr>';
1.475 www 1642: }
1643:
1.167 www 1644: sub gradeleveldescription {
1645: my $gradelevel=shift;
1646: my %gradelevels=(0 => 'Not specified',
1647: 1 => 'Grade 1',
1648: 2 => 'Grade 2',
1649: 3 => 'Grade 3',
1650: 4 => 'Grade 4',
1651: 5 => 'Grade 5',
1652: 6 => 'Grade 6',
1653: 7 => 'Grade 7',
1654: 8 => 'Grade 8',
1655: 9 => 'Grade 9',
1656: 10 => 'Grade 10',
1657: 11 => 'Grade 11',
1658: 12 => 'Grade 12',
1659: 13 => 'Grade 13',
1660: 14 => '100 Level',
1661: 15 => '200 Level',
1662: 16 => '300 Level',
1663: 17 => '400 Level',
1664: 18 => 'Graduate Level');
1665: return &mt($gradelevels{$gradelevel});
1666: }
1667:
1.163 www 1668: sub select_level_form {
1669: my ($deflevel,$name)=@_;
1670: unless ($deflevel) { $deflevel=0; }
1.167 www 1671: my $selectform = "<select name=\"$name\" size=\"1\">\n";
1672: for (my $i=0; $i<=18; $i++) {
1673: $selectform.="<option value=\"$i\" ".
1.253 albertel 1674: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 1675: ">".&gradeleveldescription($i)."</option>\n";
1676: }
1677: $selectform.="</select>";
1678: return $selectform;
1.163 www 1679: }
1.167 www 1680:
1.35 matthew 1681: #-------------------------------------------
1682:
1.45 matthew 1683: =pod
1684:
1.648 raeburn 1685: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc)
1.35 matthew 1686:
1687: Returns a string containing a <select name='$name' size='1'> form to
1688: allow a user to select the domain to preform an operation in.
1689: See loncreateuser.pm for an example invocation and use.
1690:
1.90 www 1691: If the $includeempty flag is set, it also includes an empty choice ("no domain
1692: selected");
1693:
1.563 raeburn 1694: If the $showdomdesc flag is set, the domain name is followed by the domain description.
1695:
1.35 matthew 1696: =cut
1697:
1698: #-------------------------------------------
1.34 matthew 1699: sub select_dom_form {
1.563 raeburn 1700: my ($defdom,$name,$includeempty,$showdomdesc) = @_;
1.550 albertel 1701: my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90 www 1702: if ($includeempty) { @domains=('',@domains); }
1.34 matthew 1703: my $selectdomain = "<select name=\"$name\" size=\"1\">\n";
1.356 albertel 1704: foreach my $dom (@domains) {
1705: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 1706: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
1707: if ($showdomdesc) {
1708: if ($dom ne '') {
1709: my $domdesc = &Apache::lonnet::domain($dom,'description');
1710: if ($domdesc ne '') {
1711: $selectdomain .= ' ('.$domdesc.')';
1712: }
1713: }
1714: }
1715: $selectdomain .= "</option>\n";
1.34 matthew 1716: }
1717: $selectdomain.="</select>";
1718: return $selectdomain;
1719: }
1720:
1.35 matthew 1721: #-------------------------------------------
1722:
1.45 matthew 1723: =pod
1724:
1.648 raeburn 1725: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 1726:
1.586 raeburn 1727: input: 4 arguments (two required, two optional) -
1728: $domain - domain of new user
1729: $name - name of form element
1730: $default - Value of 'default' causes a default item to be first
1731: option, and selected by default.
1732: $hide - Value of 'hide' causes hiding of the name of the server,
1733: if 1 server found, or default, if 0 found.
1.594 raeburn 1734: output: returns 2 items:
1.586 raeburn 1735: (a) form element which contains either:
1736: (i) <select name="$name">
1737: <option value="$hostid1">$hostid $servers{$hostid}</option>
1738: <option value="$hostid2">$hostid $servers{$hostid}</option>
1739: </select>
1740: form item if there are multiple library servers in $domain, or
1741: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
1742: if there is only one library server in $domain.
1743:
1744: (b) number of library servers found.
1745:
1746: See loncreateuser.pm for example of use.
1.35 matthew 1747:
1748: =cut
1749:
1750: #-------------------------------------------
1.586 raeburn 1751: sub home_server_form_item {
1752: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 1753: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 1754: my $result;
1755: my $numlib = keys(%servers);
1756: if ($numlib > 1) {
1757: $result .= '<select name="'.$name.'" />'."\n";
1758: if ($default) {
1759: $result .= '<option value="default" selected>'.&mt('default').
1760: '</option>'."\n";
1761: }
1762: foreach my $hostid (sort(keys(%servers))) {
1763: $result.= '<option value="'.$hostid.'">'.
1764: $hostid.' '.$servers{$hostid}."</option>\n";
1765: }
1766: $result .= '</select>'."\n";
1767: } elsif ($numlib == 1) {
1768: my $hostid;
1769: foreach my $item (keys(%servers)) {
1770: $hostid = $item;
1771: }
1772: $result .= '<input type="hidden" name="'.$name.'" value="'.
1773: $hostid.'" />';
1774: if (!$hide) {
1775: $result .= $hostid.' '.$servers{$hostid};
1776: }
1777: $result .= "\n";
1778: } elsif ($default) {
1779: $result .= '<input type="hidden" name="'.$name.
1780: '" value="default" />';
1781: if (!$hide) {
1782: $result .= &mt('default');
1783: }
1784: $result .= "\n";
1.33 matthew 1785: }
1.586 raeburn 1786: return ($result,$numlib);
1.33 matthew 1787: }
1.112 bowersj2 1788:
1789: =pod
1790:
1.534 albertel 1791: =back
1792:
1.112 bowersj2 1793: =cut
1.87 matthew 1794:
1795: ###############################################################
1.112 bowersj2 1796: ## Decoding User Agent ##
1.87 matthew 1797: ###############################################################
1798:
1799: =pod
1800:
1.112 bowersj2 1801: =head1 Decoding the User Agent
1802:
1803: =over 4
1804:
1805: =item * &decode_user_agent()
1.87 matthew 1806:
1807: Inputs: $r
1808:
1809: Outputs:
1810:
1811: =over 4
1812:
1.112 bowersj2 1813: =item * $httpbrowser
1.87 matthew 1814:
1.112 bowersj2 1815: =item * $clientbrowser
1.87 matthew 1816:
1.112 bowersj2 1817: =item * $clientversion
1.87 matthew 1818:
1.112 bowersj2 1819: =item * $clientmathml
1.87 matthew 1820:
1.112 bowersj2 1821: =item * $clientunicode
1.87 matthew 1822:
1.112 bowersj2 1823: =item * $clientos
1.87 matthew 1824:
1825: =back
1826:
1.157 matthew 1827: =back
1828:
1.87 matthew 1829: =cut
1830:
1831: ###############################################################
1832: ###############################################################
1833: sub decode_user_agent {
1.247 albertel 1834: my ($r)=@_;
1.87 matthew 1835: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
1836: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
1837: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 1838: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 1839: my $clientbrowser='unknown';
1840: my $clientversion='0';
1841: my $clientmathml='';
1842: my $clientunicode='0';
1843: for (my $i=0;$i<=$#browsertype;$i++) {
1844: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
1845: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
1846: $clientbrowser=$bname;
1847: $httpbrowser=~/$vreg/i;
1848: $clientversion=$1;
1849: $clientmathml=($clientversion>=$minv);
1850: $clientunicode=($clientversion>=$univ);
1851: }
1852: }
1853: my $clientos='unknown';
1854: if (($httpbrowser=~/linux/i) ||
1855: ($httpbrowser=~/unix/i) ||
1856: ($httpbrowser=~/ux/i) ||
1857: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
1858: if (($httpbrowser=~/vax/i) ||
1859: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
1860: if ($httpbrowser=~/next/i) { $clientos='next'; }
1861: if (($httpbrowser=~/mac/i) ||
1862: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1863: if ($httpbrowser=~/win/i) { $clientos='win'; }
1864: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1865: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1866: $clientunicode,$clientos,);
1867: }
1868:
1.32 matthew 1869: ###############################################################
1870: ## Authentication changing form generation subroutines ##
1871: ###############################################################
1872: ##
1873: ## All of the authform_xxxxxxx subroutines take their inputs in a
1874: ## hash, and have reasonable default values.
1875: ##
1876: ## formname = the name given in the <form> tag.
1.35 matthew 1877: #-------------------------------------------
1878:
1.45 matthew 1879: =pod
1880:
1.112 bowersj2 1881: =head1 Authentication Routines
1882:
1883: =over 4
1884:
1.648 raeburn 1885: =item * &authform_xxxxxx()
1.35 matthew 1886:
1887: The authform_xxxxxx subroutines provide javascript and html forms which
1888: handle some of the conveniences required for authentication forms.
1889: This is not an optimal method, but it works.
1890:
1891: =over 4
1892:
1.112 bowersj2 1893: =item * authform_header
1.35 matthew 1894:
1.112 bowersj2 1895: =item * authform_authorwarning
1.35 matthew 1896:
1.112 bowersj2 1897: =item * authform_nochange
1.35 matthew 1898:
1.112 bowersj2 1899: =item * authform_kerberos
1.35 matthew 1900:
1.112 bowersj2 1901: =item * authform_internal
1.35 matthew 1902:
1.112 bowersj2 1903: =item * authform_filesystem
1.35 matthew 1904:
1905: =back
1906:
1.648 raeburn 1907: See loncreateuser.pm for invocation and use examples.
1.157 matthew 1908:
1.35 matthew 1909: =cut
1910:
1911: #-------------------------------------------
1.32 matthew 1912: sub authform_header{
1913: my %in = (
1914: formname => 'cu',
1.80 albertel 1915: kerb_def_dom => '',
1.32 matthew 1916: @_,
1917: );
1918: $in{'formname'} = 'document.' . $in{'formname'};
1919: my $result='';
1.80 albertel 1920:
1921: #---------------------------------------------- Code for upper case translation
1922: my $Javascript_toUpperCase;
1923: unless ($in{kerb_def_dom}) {
1924: $Javascript_toUpperCase =<<"END";
1925: switch (choice) {
1926: case 'krb': currentform.elements[choicearg].value =
1927: currentform.elements[choicearg].value.toUpperCase();
1928: break;
1929: default:
1930: }
1931: END
1932: } else {
1933: $Javascript_toUpperCase = "";
1934: }
1935:
1.165 raeburn 1936: my $radioval = "'nochange'";
1.591 raeburn 1937: if (defined($in{'curr_authtype'})) {
1938: if ($in{'curr_authtype'} ne '') {
1939: $radioval = "'".$in{'curr_authtype'}."arg'";
1940: }
1.174 matthew 1941: }
1.165 raeburn 1942: my $argfield = 'null';
1.591 raeburn 1943: if (defined($in{'mode'})) {
1.165 raeburn 1944: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 1945: if (defined($in{'curr_autharg'})) {
1946: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 1947: $argfield = "'$in{'curr_autharg'}'";
1948: }
1949: }
1950: }
1951: }
1952:
1.32 matthew 1953: $result.=<<"END";
1954: var current = new Object();
1.165 raeburn 1955: current.radiovalue = $radioval;
1956: current.argfield = $argfield;
1.32 matthew 1957:
1958: function changed_radio(choice,currentform) {
1959: var choicearg = choice + 'arg';
1960: // If a radio button in changed, we need to change the argfield
1961: if (current.radiovalue != choice) {
1962: current.radiovalue = choice;
1963: if (current.argfield != null) {
1964: currentform.elements[current.argfield].value = '';
1965: }
1966: if (choice == 'nochange') {
1967: current.argfield = null;
1968: } else {
1969: current.argfield = choicearg;
1970: switch(choice) {
1971: case 'krb':
1972: currentform.elements[current.argfield].value =
1973: "$in{'kerb_def_dom'}";
1974: break;
1975: default:
1976: break;
1977: }
1978: }
1979: }
1980: return;
1981: }
1.22 www 1982:
1.32 matthew 1983: function changed_text(choice,currentform) {
1984: var choicearg = choice + 'arg';
1985: if (currentform.elements[choicearg].value !='') {
1.80 albertel 1986: $Javascript_toUpperCase
1.32 matthew 1987: // clear old field
1988: if ((current.argfield != choicearg) && (current.argfield != null)) {
1989: currentform.elements[current.argfield].value = '';
1990: }
1991: current.argfield = choicearg;
1992: }
1993: set_auth_radio_buttons(choice,currentform);
1994: return;
1.20 www 1995: }
1.32 matthew 1996:
1997: function set_auth_radio_buttons(newvalue,currentform) {
1998: var i=0;
1999: while (i < currentform.login.length) {
2000: if (currentform.login[i].value == newvalue) { break; }
2001: i++;
2002: }
2003: if (i == currentform.login.length) {
2004: return;
2005: }
2006: current.radiovalue = newvalue;
2007: currentform.login[i].checked = true;
2008: return;
2009: }
2010: END
2011: return $result;
2012: }
2013:
2014: sub authform_authorwarning{
2015: my $result='';
1.144 matthew 2016: $result='<i>'.
2017: &mt('As a general rule, only authors or co-authors should be '.
2018: 'filesystem authenticated '.
2019: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2020: return $result;
2021: }
2022:
2023: sub authform_nochange{
2024: my %in = (
2025: formname => 'document.cu',
2026: kerb_def_dom => 'MSU.EDU',
2027: @_,
2028: );
1.586 raeburn 2029: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
2030: my $result;
2031: if (keys(%can_assign) == 0) {
2032: $result = &mt('Under you current role you are not permitted to change login settings for this user');
2033: } else {
2034: $result = '<label>'.&mt('[_1] Do not change login data',
2035: '<input type="radio" name="login" value="nochange" '.
2036: 'checked="checked" onclick="'.
1.281 albertel 2037: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2038: '</label>';
1.586 raeburn 2039: }
1.32 matthew 2040: return $result;
2041: }
2042:
1.591 raeburn 2043: sub authform_kerberos {
1.32 matthew 2044: my %in = (
2045: formname => 'document.cu',
2046: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2047: kerb_def_auth => 'krb4',
1.32 matthew 2048: @_,
2049: );
1.586 raeburn 2050: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2051: $autharg,$jscall);
2052: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2053: if ($in{'kerb_def_auth'} eq 'krb5') {
1.586 raeburn 2054: $check5 = ' checked="on"';
1.80 albertel 2055: } else {
1.586 raeburn 2056: $check4 = ' checked="on"';
1.80 albertel 2057: }
1.165 raeburn 2058: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2059: if (defined($in{'curr_authtype'})) {
2060: if ($in{'curr_authtype'} eq 'krb') {
1.586 raeburn 2061: $krbcheck = ' checked="on"';
1.623 raeburn 2062: if (defined($in{'mode'})) {
2063: if ($in{'mode'} eq 'modifyuser') {
2064: $krbcheck = '';
2065: }
2066: }
1.591 raeburn 2067: if (defined($in{'curr_kerb_ver'})) {
2068: if ($in{'curr_krb_ver'} eq '5') {
2069: $check5 = ' checked="on"';
2070: $check4 = '';
2071: } else {
2072: $check4 = ' checked="on"';
2073: $check5 = '';
2074: }
1.586 raeburn 2075: }
1.591 raeburn 2076: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2077: $krbarg = $in{'curr_autharg'};
2078: }
1.586 raeburn 2079: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2080: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2081: $result =
2082: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2083: $in{'curr_autharg'},$krbver);
2084: } else {
2085: $result =
2086: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2087: }
2088: return $result;
2089: }
2090: }
2091: } else {
2092: if ($authnum == 1) {
2093: $authtype = '<input type="hidden" name="login" value="krb">';
1.165 raeburn 2094: }
2095: }
1.586 raeburn 2096: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2097: return;
1.587 raeburn 2098: } elsif ($authtype eq '') {
1.591 raeburn 2099: if (defined($in{'mode'})) {
1.587 raeburn 2100: if ($in{'mode'} eq 'modifycourse') {
2101: if ($authnum == 1) {
2102: $authtype = '<input type="hidden" name="login" value="krb">';
2103: }
2104: }
2105: }
1.586 raeburn 2106: }
2107: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2108: if ($authtype eq '') {
2109: $authtype = '<input type="radio" name="login" value="krb" '.
2110: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2111: $krbcheck.' />';
2112: }
2113: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
2114: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
2115: $in{'curr_authtype'} eq 'krb5') ||
2116: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
2117: $in{'curr_authtype'} eq 'krb4')) {
2118: $result .= &mt
1.144 matthew 2119: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2120: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2121: '<label>'.$authtype,
1.281 albertel 2122: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2123: 'value="'.$krbarg.'" '.
1.144 matthew 2124: 'onchange="'.$jscall.'" />',
1.281 albertel 2125: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2126: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2127: '</label>');
1.586 raeburn 2128: } elsif ($can_assign{'krb4'}) {
2129: $result .= &mt
2130: ('[_1] Kerberos authenticated with domain [_2] '.
2131: '[_3] Version 4 [_4]',
2132: '<label>'.$authtype,
2133: '</label><input type="text" size="10" name="krbarg" '.
2134: 'value="'.$krbarg.'" '.
2135: 'onchange="'.$jscall.'" />',
2136: '<label><input type="hidden" name="krbver" value="4" />',
2137: '</label>');
2138: } elsif ($can_assign{'krb5'}) {
2139: $result .= &mt
2140: ('[_1] Kerberos authenticated with domain [_2] '.
2141: '[_3] Version 5 [_4]',
2142: '<label>'.$authtype,
2143: '</label><input type="text" size="10" name="krbarg" '.
2144: 'value="'.$krbarg.'" '.
2145: 'onchange="'.$jscall.'" />',
2146: '<label><input type="hidden" name="krbver" value="5" />',
2147: '</label>');
2148: }
1.32 matthew 2149: return $result;
2150: }
2151:
2152: sub authform_internal{
1.586 raeburn 2153: my %in = (
1.32 matthew 2154: formname => 'document.cu',
2155: kerb_def_dom => 'MSU.EDU',
2156: @_,
2157: );
1.586 raeburn 2158: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
2159: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2160: if (defined($in{'curr_authtype'})) {
2161: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2162: if ($can_assign{'int'}) {
2163: $intcheck = 'checked="on" ';
1.623 raeburn 2164: if (defined($in{'mode'})) {
2165: if ($in{'mode'} eq 'modifyuser') {
2166: $intcheck = '';
2167: }
2168: }
1.591 raeburn 2169: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2170: $intarg = $in{'curr_autharg'};
2171: }
2172: } else {
2173: $result = &mt('Currently internally authenticated.');
2174: return $result;
1.165 raeburn 2175: }
2176: }
1.586 raeburn 2177: } else {
2178: if ($authnum == 1) {
2179: $authtype = '<input type="hidden" name="login" value="int">';
2180: }
2181: }
2182: if (!$can_assign{'int'}) {
2183: return;
1.587 raeburn 2184: } elsif ($authtype eq '') {
1.591 raeburn 2185: if (defined($in{'mode'})) {
1.587 raeburn 2186: if ($in{'mode'} eq 'modifycourse') {
2187: if ($authnum == 1) {
2188: $authtype = '<input type="hidden" name="login" value="int">';
2189: }
2190: }
2191: }
1.165 raeburn 2192: }
1.586 raeburn 2193: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2194: if ($authtype eq '') {
2195: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2196: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2197: }
1.605 bisitz 2198: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2199: $intarg.'" onchange="'.$jscall.'" />';
2200: $result = &mt
1.144 matthew 2201: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2202: '<label>'.$authtype,'</label>'.$autharg);
1.620 www 2203: $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2204: return $result;
2205: }
2206:
2207: sub authform_local{
2208: my %in = (
2209: formname => 'document.cu',
2210: kerb_def_dom => 'MSU.EDU',
2211: @_,
2212: );
1.586 raeburn 2213: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
2214: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2215: if (defined($in{'curr_authtype'})) {
2216: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2217: if ($can_assign{'loc'}) {
2218: $loccheck = 'checked="on" ';
1.623 raeburn 2219: if (defined($in{'mode'})) {
2220: if ($in{'mode'} eq 'modifyuser') {
2221: $loccheck = '';
2222: }
2223: }
1.591 raeburn 2224: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2225: $locarg = $in{'curr_autharg'};
2226: }
2227: } else {
2228: $result = &mt('Currently using local (institutional) authentication.');
2229: return $result;
1.165 raeburn 2230: }
2231: }
1.586 raeburn 2232: } else {
2233: if ($authnum == 1) {
2234: $authtype = '<input type="hidden" name="login" value="loc">';
2235: }
2236: }
2237: if (!$can_assign{'loc'}) {
2238: return;
1.587 raeburn 2239: } elsif ($authtype eq '') {
1.591 raeburn 2240: if (defined($in{'mode'})) {
1.587 raeburn 2241: if ($in{'mode'} eq 'modifycourse') {
2242: if ($authnum == 1) {
2243: $authtype = '<input type="hidden" name="login" value="loc">';
2244: }
2245: }
2246: }
1.165 raeburn 2247: }
1.586 raeburn 2248: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2249: if ($authtype eq '') {
2250: $authtype = '<input type="radio" name="login" value="loc" '.
2251: $loccheck.' onchange="'.$jscall.'" onclick="'.
2252: $jscall.'" />';
2253: }
2254: $autharg = '<input type="text" size="10" name="locarg" value="'.
2255: $locarg.'" onchange="'.$jscall.'" />';
2256: $result = &mt('[_1] Local Authentication with argument [_2]',
2257: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2258: return $result;
2259: }
2260:
2261: sub authform_filesystem{
2262: my %in = (
2263: formname => 'document.cu',
2264: kerb_def_dom => 'MSU.EDU',
2265: @_,
2266: );
1.586 raeburn 2267: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
2268: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2269: if (defined($in{'curr_authtype'})) {
2270: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2271: if ($can_assign{'fsys'}) {
2272: $fsyscheck = 'checked="on" ';
1.623 raeburn 2273: if (defined($in{'mode'})) {
2274: if ($in{'mode'} eq 'modifyuser') {
2275: $fsyscheck = '';
2276: }
2277: }
1.586 raeburn 2278: } else {
2279: $result = &mt('Currently Filesystem Authenticated.');
2280: return $result;
2281: }
2282: }
2283: } else {
2284: if ($authnum == 1) {
2285: $authtype = '<input type="hidden" name="login" value="fsys">';
2286: }
2287: }
2288: if (!$can_assign{'fsys'}) {
2289: return;
1.587 raeburn 2290: } elsif ($authtype eq '') {
1.591 raeburn 2291: if (defined($in{'mode'})) {
1.587 raeburn 2292: if ($in{'mode'} eq 'modifycourse') {
2293: if ($authnum == 1) {
2294: $authtype = '<input type="hidden" name="login" value="fsys">';
2295: }
2296: }
2297: }
1.586 raeburn 2298: }
2299: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2300: if ($authtype eq '') {
2301: $authtype = '<input type="radio" name="login" value="fsys" '.
2302: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2303: $jscall.'" />';
2304: }
2305: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2306: ' onchange="'.$jscall.'" />';
2307: $result = &mt
1.144 matthew 2308: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2309: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2310: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2311: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2312: 'onchange="'.$jscall.'" />');
1.32 matthew 2313: return $result;
2314: }
2315:
1.586 raeburn 2316: sub get_assignable_auth {
2317: my ($dom) = @_;
2318: if ($dom eq '') {
2319: $dom = $env{'request.role.domain'};
2320: }
2321: my %can_assign = (
2322: krb4 => 1,
2323: krb5 => 1,
2324: int => 1,
2325: loc => 1,
2326: );
2327: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2328: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2329: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2330: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2331: my $context;
2332: if ($env{'request.role'} =~ /^au/) {
2333: $context = 'author';
2334: } elsif ($env{'request.role'} =~ /^dc/) {
2335: $context = 'domain';
2336: } elsif ($env{'request.course.id'}) {
2337: $context = 'course';
2338: }
2339: if ($context) {
2340: if (ref($authhash->{$context}) eq 'HASH') {
2341: %can_assign = %{$authhash->{$context}};
2342: }
2343: }
2344: }
2345: }
2346: my $authnum = 0;
2347: foreach my $key (keys(%can_assign)) {
2348: if ($can_assign{$key}) {
2349: $authnum ++;
2350: }
2351: }
2352: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2353: $authnum --;
2354: }
2355: return ($authnum,%can_assign);
2356: }
2357:
1.80 albertel 2358: ###############################################################
2359: ## Get Kerberos Defaults for Domain ##
2360: ###############################################################
2361: ##
2362: ## Returns default kerberos version and an associated argument
2363: ## as listed in file domain.tab. If not listed, provides
2364: ## appropriate default domain and kerberos version.
2365: ##
2366: #-------------------------------------------
2367:
2368: =pod
2369:
1.648 raeburn 2370: =item * &get_kerberos_defaults()
1.80 albertel 2371:
2372: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2373: version and domain. If not found, it defaults to version 4 and the
2374: domain of the server.
1.80 albertel 2375:
1.648 raeburn 2376: =over 4
2377:
1.80 albertel 2378: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2379:
1.648 raeburn 2380: =back
2381:
2382: =back
2383:
1.80 albertel 2384: =cut
2385:
2386: #-------------------------------------------
2387: sub get_kerberos_defaults {
2388: my $domain=shift;
1.641 raeburn 2389: my ($krbdef,$krbdefdom);
2390: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2391: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2392: $krbdef = $domdefaults{'auth_def'};
2393: $krbdefdom = $domdefaults{'auth_arg_def'};
2394: } else {
1.80 albertel 2395: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2396: my $krbdefdom=$1;
2397: $krbdefdom=~tr/a-z/A-Z/;
2398: $krbdef = "krb4";
2399: }
2400: return ($krbdef,$krbdefdom);
2401: }
1.112 bowersj2 2402:
1.32 matthew 2403:
1.46 matthew 2404: ###############################################################
2405: ## Thesaurus Functions ##
2406: ###############################################################
1.20 www 2407:
1.46 matthew 2408: =pod
1.20 www 2409:
1.112 bowersj2 2410: =head1 Thesaurus Functions
2411:
2412: =over 4
2413:
1.648 raeburn 2414: =item * &initialize_keywords()
1.46 matthew 2415:
2416: Initializes the package variable %Keywords if it is empty. Uses the
2417: package variable $thesaurus_db_file.
2418:
2419: =cut
2420:
2421: ###################################################
2422:
2423: sub initialize_keywords {
2424: return 1 if (scalar keys(%Keywords));
2425: # If we are here, %Keywords is empty, so fill it up
2426: # Make sure the file we need exists...
2427: if (! -e $thesaurus_db_file) {
2428: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2429: " failed because it does not exist");
2430: return 0;
2431: }
2432: # Set up the hash as a database
2433: my %thesaurus_db;
2434: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2435: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2436: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2437: $thesaurus_db_file);
2438: return 0;
2439: }
2440: # Get the average number of appearances of a word.
2441: my $avecount = $thesaurus_db{'average.count'};
2442: # Put keywords (those that appear > average) into %Keywords
2443: while (my ($word,$data)=each (%thesaurus_db)) {
2444: my ($count,undef) = split /:/,$data;
2445: $Keywords{$word}++ if ($count > $avecount);
2446: }
2447: untie %thesaurus_db;
2448: # Remove special values from %Keywords.
1.356 albertel 2449: foreach my $value ('total.count','average.count') {
2450: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2451: }
1.46 matthew 2452: return 1;
2453: }
2454:
2455: ###################################################
2456:
2457: =pod
2458:
1.648 raeburn 2459: =item * &keyword($word)
1.46 matthew 2460:
2461: Returns true if $word is a keyword. A keyword is a word that appears more
2462: than the average number of times in the thesaurus database. Calls
2463: &initialize_keywords
2464:
2465: =cut
2466:
2467: ###################################################
1.20 www 2468:
2469: sub keyword {
1.46 matthew 2470: return if (!&initialize_keywords());
2471: my $word=lc(shift());
2472: $word=~s/\W//g;
2473: return exists($Keywords{$word});
1.20 www 2474: }
1.46 matthew 2475:
2476: ###############################################################
2477:
2478: =pod
1.20 www 2479:
1.648 raeburn 2480: =item * &get_related_words()
1.46 matthew 2481:
1.160 matthew 2482: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 2483: an array of words. If the keyword is not in the thesaurus, an empty array
2484: will be returned. The order of the words returned is determined by the
2485: database which holds them.
2486:
2487: Uses global $thesaurus_db_file.
2488:
2489: =cut
2490:
2491: ###############################################################
2492: sub get_related_words {
2493: my $keyword = shift;
2494: my %thesaurus_db;
2495: if (! -e $thesaurus_db_file) {
2496: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
2497: "failed because the file does not exist");
2498: return ();
2499: }
2500: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2501: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2502: return ();
2503: }
2504: my @Words=();
1.429 www 2505: my $count=0;
1.46 matthew 2506: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 2507: # The first element is the number of times
2508: # the word appears. We do not need it now.
1.429 www 2509: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
2510: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
2511: my $threshold=$mostfrequentcount/10;
2512: foreach my $possibleword (@RelatedWords) {
2513: my ($word,$wordcount)=split(/\,/,$possibleword);
2514: if ($wordcount>$threshold) {
2515: push(@Words,$word);
2516: $count++;
2517: if ($count>10) { last; }
2518: }
1.20 www 2519: }
2520: }
1.46 matthew 2521: untie %thesaurus_db;
2522: return @Words;
1.14 harris41 2523: }
1.46 matthew 2524:
1.112 bowersj2 2525: =pod
2526:
2527: =back
2528:
2529: =cut
1.61 www 2530:
2531: # -------------------------------------------------------------- Plaintext name
1.81 albertel 2532: =pod
2533:
1.112 bowersj2 2534: =head1 User Name Functions
2535:
2536: =over 4
2537:
1.648 raeburn 2538: =item * &plainname($uname,$udom,$first)
1.81 albertel 2539:
1.112 bowersj2 2540: Takes a users logon name and returns it as a string in
1.226 albertel 2541: "first middle last generation" form
2542: if $first is set to 'lastname' then it returns it as
2543: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 2544:
2545: =cut
1.61 www 2546:
1.295 www 2547:
1.81 albertel 2548: ###############################################################
1.61 www 2549: sub plainname {
1.226 albertel 2550: my ($uname,$udom,$first)=@_;
1.537 albertel 2551: return if (!defined($uname) || !defined($udom));
1.295 www 2552: my %names=&getnames($uname,$udom);
1.226 albertel 2553: my $name=&Apache::lonnet::format_name($names{'firstname'},
2554: $names{'middlename'},
2555: $names{'lastname'},
2556: $names{'generation'},$first);
2557: $name=~s/^\s+//;
1.62 www 2558: $name=~s/\s+$//;
2559: $name=~s/\s+/ /g;
1.353 albertel 2560: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 2561: return $name;
1.61 www 2562: }
1.66 www 2563:
2564: # -------------------------------------------------------------------- Nickname
1.81 albertel 2565: =pod
2566:
1.648 raeburn 2567: =item * &nickname($uname,$udom)
1.81 albertel 2568:
2569: Gets a users name and returns it as a string as
2570:
2571: ""nickname""
1.66 www 2572:
1.81 albertel 2573: if the user has a nickname or
2574:
2575: "first middle last generation"
2576:
2577: if the user does not
2578:
2579: =cut
1.66 www 2580:
2581: sub nickname {
2582: my ($uname,$udom)=@_;
1.537 albertel 2583: return if (!defined($uname) || !defined($udom));
1.295 www 2584: my %names=&getnames($uname,$udom);
1.68 albertel 2585: my $name=$names{'nickname'};
1.66 www 2586: if ($name) {
2587: $name='"'.$name.'"';
2588: } else {
2589: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
2590: $names{'lastname'}.' '.$names{'generation'};
2591: $name=~s/\s+$//;
2592: $name=~s/\s+/ /g;
2593: }
2594: return $name;
2595: }
2596:
1.295 www 2597: sub getnames {
2598: my ($uname,$udom)=@_;
1.537 albertel 2599: return if (!defined($uname) || !defined($udom));
1.433 albertel 2600: if ($udom eq 'public' && $uname eq 'public') {
2601: return ('lastname' => &mt('Public'));
2602: }
1.295 www 2603: my $id=$uname.':'.$udom;
2604: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
2605: if ($cached) {
2606: return %{$names};
2607: } else {
2608: my %loadnames=&Apache::lonnet::get('environment',
2609: ['firstname','middlename','lastname','generation','nickname'],
2610: $udom,$uname);
2611: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
2612: return %loadnames;
2613: }
2614: }
1.61 www 2615:
1.542 raeburn 2616: # -------------------------------------------------------------------- getemails
1.648 raeburn 2617:
1.542 raeburn 2618: =pod
2619:
1.648 raeburn 2620: =item * &getemails($uname,$udom)
1.542 raeburn 2621:
2622: Gets a user's email information and returns it as a hash with keys:
2623: notification, critnotification, permanentemail
2624:
2625: For notification and critnotification, values are comma-separated lists
1.648 raeburn 2626: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 2627:
1.648 raeburn 2628:
1.542 raeburn 2629: =cut
2630:
1.648 raeburn 2631:
1.466 albertel 2632: sub getemails {
2633: my ($uname,$udom)=@_;
2634: if ($udom eq 'public' && $uname eq 'public') {
2635: return;
2636: }
1.467 www 2637: if (!$udom) { $udom=$env{'user.domain'}; }
2638: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 2639: my $id=$uname.':'.$udom;
2640: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
2641: if ($cached) {
2642: return %{$names};
2643: } else {
2644: my %loadnames=&Apache::lonnet::get('environment',
2645: ['notification','critnotification',
2646: 'permanentemail'],
2647: $udom,$uname);
2648: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
2649: return %loadnames;
2650: }
2651: }
2652:
1.551 albertel 2653: sub flush_email_cache {
2654: my ($uname,$udom)=@_;
2655: if (!$udom) { $udom =$env{'user.domain'}; }
2656: if (!$uname) { $uname=$env{'user.name'}; }
2657: return if ($udom eq 'public' && $uname eq 'public');
2658: my $id=$uname.':'.$udom;
2659: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
2660: }
2661:
1.61 www 2662: # ------------------------------------------------------------------ Screenname
1.81 albertel 2663:
2664: =pod
2665:
1.648 raeburn 2666: =item * &screenname($uname,$udom)
1.81 albertel 2667:
2668: Gets a users screenname and returns it as a string
2669:
2670: =cut
1.61 www 2671:
2672: sub screenname {
2673: my ($uname,$udom)=@_;
1.258 albertel 2674: if ($uname eq $env{'user.name'} &&
2675: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 2676: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 2677: return $names{'screenname'};
1.62 www 2678: }
2679:
1.212 albertel 2680:
1.62 www 2681: # ------------------------------------------------------------- Message Wrapper
2682:
2683: sub messagewrapper {
1.369 www 2684: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 2685: return
1.441 albertel 2686: '<a href="/adm/email?compose=individual&'.
2687: 'recname='.$username.'&recdom='.$domain.
2688: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 2689: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 2690: }
2691: # --------------------------------------------------------------- Notes Wrapper
2692:
2693: sub noteswrapper {
2694: my ($link,$un,$do)=@_;
2695: return
2696: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 2697: }
2698: # ------------------------------------------------------------- Aboutme Wrapper
2699:
2700: sub aboutmewrapper {
1.166 www 2701: my ($link,$username,$domain,$target)=@_;
1.447 raeburn 2702: if (!defined($username) && !defined($domain)) {
2703: return;
2704: }
1.205 www 2705: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.454 banghart 2706: ($target?' target="$target"':'').' title="'.&mt("View this user's personal page").'">'.$link.'</a>';
1.62 www 2707: }
2708:
2709: # ------------------------------------------------------------ Syllabus Wrapper
2710:
2711:
2712: sub syllabuswrapper {
1.109 matthew 2713: my ($linktext,$coursedir,$domain,$fontcolor)=@_;
2714: if ($fontcolor) {
2715: $linktext='<font color="'.$fontcolor.'">'.$linktext.'</font>';
2716: }
1.208 matthew 2717: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 2718: }
1.14 harris41 2719:
1.208 matthew 2720: sub track_student_link {
1.268 albertel 2721: my ($linktext,$sname,$sdom,$target,$start) = @_;
2722: my $link ="/adm/trackstudent?";
1.208 matthew 2723: my $title = 'View recent activity';
2724: if (defined($sname) && $sname !~ /^\s*$/ &&
2725: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 2726: $link .= "selected_student=$sname:$sdom";
1.208 matthew 2727: $title .= ' of this student';
1.268 albertel 2728: }
1.208 matthew 2729: if (defined($target) && $target !~ /^\s*$/) {
2730: $target = qq{target="$target"};
2731: } else {
2732: $target = '';
2733: }
1.268 albertel 2734: if ($start) { $link.='&start='.$start; }
1.554 albertel 2735: $title = &mt($title);
2736: $linktext = &mt($linktext);
1.448 albertel 2737: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
2738: &help_open_topic('View_recent_activity');
1.208 matthew 2739: }
2740:
1.508 www 2741: # ===================================================== Display a student photo
2742:
2743:
1.509 albertel 2744: sub student_image_tag {
1.508 www 2745: my ($domain,$user)=@_;
2746: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
2747: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
2748: return '<img src="'.$imgsrc.'" align="right" />';
2749: } else {
2750: return '';
2751: }
2752: }
2753:
1.112 bowersj2 2754: =pod
2755:
2756: =back
2757:
2758: =head1 Access .tab File Data
2759:
2760: =over 4
2761:
1.648 raeburn 2762: =item * &languageids()
1.112 bowersj2 2763:
2764: returns list of all language ids
2765:
2766: =cut
2767:
1.14 harris41 2768: sub languageids {
1.16 harris41 2769: return sort(keys(%language));
1.14 harris41 2770: }
2771:
1.112 bowersj2 2772: =pod
2773:
1.648 raeburn 2774: =item * &languagedescription()
1.112 bowersj2 2775:
2776: returns description of a specified language id
2777:
2778: =cut
2779:
1.14 harris41 2780: sub languagedescription {
1.125 www 2781: my $code=shift;
2782: return ($supported_language{$code}?'* ':'').
2783: $language{$code}.
1.126 www 2784: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 2785: }
2786:
2787: sub plainlanguagedescription {
2788: my $code=shift;
2789: return $language{$code};
2790: }
2791:
2792: sub supportedlanguagecode {
2793: my $code=shift;
2794: return $supported_language{$code};
1.97 www 2795: }
2796:
1.112 bowersj2 2797: =pod
2798:
1.648 raeburn 2799: =item * ©rightids()
1.112 bowersj2 2800:
2801: returns list of all copyrights
2802:
2803: =cut
2804:
2805: sub copyrightids {
2806: return sort(keys(%cprtag));
2807: }
2808:
2809: =pod
2810:
1.648 raeburn 2811: =item * ©rightdescription()
1.112 bowersj2 2812:
2813: returns description of a specified copyright id
2814:
2815: =cut
2816:
2817: sub copyrightdescription {
1.166 www 2818: return &mt($cprtag{shift(@_)});
1.112 bowersj2 2819: }
1.197 matthew 2820:
2821: =pod
2822:
1.648 raeburn 2823: =item * &source_copyrightids()
1.192 taceyjo1 2824:
2825: returns list of all source copyrights
2826:
2827: =cut
2828:
2829: sub source_copyrightids {
2830: return sort(keys(%scprtag));
2831: }
2832:
2833: =pod
2834:
1.648 raeburn 2835: =item * &source_copyrightdescription()
1.192 taceyjo1 2836:
2837: returns description of a specified source copyright id
2838:
2839: =cut
2840:
2841: sub source_copyrightdescription {
2842: return &mt($scprtag{shift(@_)});
2843: }
1.112 bowersj2 2844:
2845: =pod
2846:
1.648 raeburn 2847: =item * &filecategories()
1.112 bowersj2 2848:
2849: returns list of all file categories
2850:
2851: =cut
2852:
2853: sub filecategories {
2854: return sort(keys(%category_extensions));
2855: }
2856:
2857: =pod
2858:
1.648 raeburn 2859: =item * &filecategorytypes()
1.112 bowersj2 2860:
2861: returns list of file types belonging to a given file
2862: category
2863:
2864: =cut
2865:
2866: sub filecategorytypes {
1.356 albertel 2867: my ($cat) = @_;
2868: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 2869: }
2870:
2871: =pod
2872:
1.648 raeburn 2873: =item * &fileembstyle()
1.112 bowersj2 2874:
2875: returns embedding style for a specified file type
2876:
2877: =cut
2878:
2879: sub fileembstyle {
2880: return $fe{lc(shift(@_))};
1.169 www 2881: }
2882:
1.351 www 2883: sub filemimetype {
2884: return $fm{lc(shift(@_))};
2885: }
2886:
1.169 www 2887:
2888: sub filecategoryselect {
2889: my ($name,$value)=@_;
1.189 matthew 2890: return &select_form($value,$name,
1.169 www 2891: '' => &mt('Any category'),
2892: map { $_,$_ } sort(keys(%category_extensions)));
1.112 bowersj2 2893: }
2894:
2895: =pod
2896:
1.648 raeburn 2897: =item * &filedescription()
1.112 bowersj2 2898:
2899: returns description for a specified file type
2900:
2901: =cut
2902:
2903: sub filedescription {
1.188 matthew 2904: my $file_description = $fd{lc(shift())};
2905: $file_description =~ s:([\[\]]):~$1:g;
2906: return &mt($file_description);
1.112 bowersj2 2907: }
2908:
2909: =pod
2910:
1.648 raeburn 2911: =item * &filedescriptionex()
1.112 bowersj2 2912:
2913: returns description for a specified file type with
2914: extra formatting
2915:
2916: =cut
2917:
2918: sub filedescriptionex {
2919: my $ex=shift;
1.188 matthew 2920: my $file_description = $fd{lc($ex)};
2921: $file_description =~ s:([\[\]]):~$1:g;
2922: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 2923: }
2924:
2925: # End of .tab access
2926: =pod
2927:
2928: =back
2929:
2930: =cut
2931:
2932: # ------------------------------------------------------------------ File Types
2933: sub fileextensions {
2934: return sort(keys(%fe));
2935: }
2936:
1.97 www 2937: # ----------------------------------------------------------- Display Languages
2938: # returns a hash with all desired display languages
2939: #
2940:
2941: sub display_languages {
2942: my %languages=();
1.356 albertel 2943: foreach my $lang (&preferred_languages()) {
2944: $languages{$lang}=1;
1.97 www 2945: }
2946: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 2947: if ($env{'form.displaylanguage'}) {
1.356 albertel 2948: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
2949: $languages{$lang}=1;
1.97 www 2950: }
2951: }
2952: return %languages;
1.14 harris41 2953: }
2954:
1.117 www 2955: sub preferred_languages {
2956: my @languages=();
1.654 www 2957: if (($env{'request.role.adv'}) && ($env{'form.languages'})) {
2958: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$env{'form.languages'}));
2959: }
1.258 albertel 2960: if ($env{'course.'.$env{'request.course.id'}.'.languages'}) {
1.117 www 2961: @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
1.258 albertel 2962: $env{'course.'.$env{'request.course.id'}.'.languages'}));
1.177 www 2963: }
1.654 www 2964:
1.258 albertel 2965: if ($env{'environment.languages'}) {
1.459 albertel 2966: @languages=(@languages,
2967: split(/\s*(\,|\;|\:)\s*/,$env{'environment.languages'}));
1.118 www 2968: }
1.583 albertel 2969: my $browser=$ENV{'HTTP_ACCEPT_LANGUAGE'};
1.162 www 2970: if ($browser) {
1.583 albertel 2971: my @browser =
2972: map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
2973: push(@languages,@browser);
1.162 www 2974: }
1.641 raeburn 2975:
2976: foreach my $domtype ($env{'user.domain'},$env{'request.role.domain'},
2977: $Apache::lonnet::perlvar{'lonDefDomain'}) {
2978: if ($domtype ne '') {
2979: my %domdefs = &Apache::lonnet::get_domain_defaults($domtype);
2980: if ($domdefs{'lang_def'} ne '') {
2981: push(@languages,$domdefs{'lang_def'});
2982: }
2983: }
1.118 www 2984: }
2985: # turn "en-ca" into "en-ca,en"
2986: my @genlanguages;
1.356 albertel 2987: foreach my $lang (@languages) {
2988: unless ($lang=~/\w/) { next; }
1.583 albertel 2989: push(@genlanguages,$lang);
1.356 albertel 2990: if ($lang=~/(\-|\_)/) {
2991: push(@genlanguages,(split(/(\-|\_)/,$lang))[0]);
1.118 www 2992: }
2993: }
1.583 albertel 2994: #uniqueify the languages list
2995: my %count;
2996: @genlanguages = map { $count{$_}++ == 0 ? $_ : () } @genlanguages;
1.118 www 2997: return @genlanguages;
1.117 www 2998: }
2999:
1.582 albertel 3000: sub languages {
3001: my ($possible_langs) = @_;
3002: my @preferred_langs = &preferred_languages();
3003: if (!ref($possible_langs)) {
3004: if( wantarray ) {
3005: return @preferred_langs;
3006: } else {
3007: return $preferred_langs[0];
3008: }
3009: }
3010: my %possibilities = map { $_ => 1 } (@$possible_langs);
3011: my @preferred_possibilities;
3012: foreach my $preferred_lang (@preferred_langs) {
3013: if (exists($possibilities{$preferred_lang})) {
3014: push(@preferred_possibilities, $preferred_lang);
3015: }
3016: }
3017: if( wantarray ) {
3018: return @preferred_possibilities;
3019: }
3020: return $preferred_possibilities[0];
3021: }
3022:
1.112 bowersj2 3023: ###############################################################
3024: ## Student Answer Attempts ##
3025: ###############################################################
3026:
3027: =pod
3028:
3029: =head1 Alternate Problem Views
3030:
3031: =over 4
3032:
1.648 raeburn 3033: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3034: $getattempt, $regexp, $gradesub)
3035:
3036: Return string with previous attempt on problem. Arguments:
3037:
3038: =over 4
3039:
3040: =item * $symb: Problem, including path
3041:
3042: =item * $username: username of the desired student
3043:
3044: =item * $domain: domain of the desired student
1.14 harris41 3045:
1.112 bowersj2 3046: =item * $course: Course ID
1.14 harris41 3047:
1.112 bowersj2 3048: =item * $getattempt: Leave blank for all attempts, otherwise put
3049: something
1.14 harris41 3050:
1.112 bowersj2 3051: =item * $regexp: if string matches this regexp, the string will be
3052: sent to $gradesub
1.14 harris41 3053:
1.112 bowersj2 3054: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3055:
1.112 bowersj2 3056: =back
1.14 harris41 3057:
1.112 bowersj2 3058: The output string is a table containing all desired attempts, if any.
1.16 harris41 3059:
1.112 bowersj2 3060: =cut
1.1 albertel 3061:
3062: sub get_previous_attempt {
1.43 ng 3063: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3064: my $prevattempts='';
1.43 ng 3065: no strict 'refs';
1.1 albertel 3066: if ($symb) {
1.3 albertel 3067: my (%returnhash)=
3068: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3069: if ($returnhash{'version'}) {
3070: my %lasthash=();
3071: my $version;
3072: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3073: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3074: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3075: }
1.1 albertel 3076: }
1.596 albertel 3077: $prevattempts=&start_data_table().&start_data_table_header_row();
3078: $prevattempts.='<th>'.&mt('History').'</th>';
1.356 albertel 3079: foreach my $key (sort(keys(%lasthash))) {
3080: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3081: if ($#parts > 0) {
1.31 albertel 3082: my $data=$parts[-1];
3083: pop(@parts);
1.596 albertel 3084: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.31 albertel 3085: } else {
1.41 ng 3086: if ($#parts == 0) {
3087: $prevattempts.='<th>'.$parts[0].'</th>';
3088: } else {
3089: $prevattempts.='<th>'.$ign.'</th>';
3090: }
1.31 albertel 3091: }
1.16 harris41 3092: }
1.596 albertel 3093: $prevattempts.=&end_data_table_header_row();
1.40 ng 3094: if ($getattempt eq '') {
3095: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596 albertel 3096: $prevattempts.=&start_data_table_row().
3097: '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356 albertel 3098: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3099: my $value = &format_previous_attempt_value($key,
3100: $returnhash{$version.':'.$key});
3101: $prevattempts.='<td>'.$value.' </td>';
1.40 ng 3102: }
1.596 albertel 3103: $prevattempts.=&end_data_table_row();
1.40 ng 3104: }
1.1 albertel 3105: }
1.596 albertel 3106: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3107: foreach my $key (sort(keys(%lasthash))) {
1.581 albertel 3108: my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356 albertel 3109: if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40 ng 3110: $prevattempts.='<td>'.$value.' </td>';
1.16 harris41 3111: }
1.596 albertel 3112: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3113: } else {
1.596 albertel 3114: $prevattempts=
3115: &start_data_table().&start_data_table_row().
3116: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3117: &end_data_table_row().&end_data_table();
1.1 albertel 3118: }
3119: } else {
1.596 albertel 3120: $prevattempts=
3121: &start_data_table().&start_data_table_row().
3122: '<td>'.&mt('No data.').'</td>'.
3123: &end_data_table_row().&end_data_table();
1.1 albertel 3124: }
1.10 albertel 3125: }
3126:
1.581 albertel 3127: sub format_previous_attempt_value {
3128: my ($key,$value) = @_;
3129: if ($key =~ /timestamp/) {
3130: $value = &Apache::lonlocal::locallocaltime($value);
3131: } elsif (ref($value) eq 'ARRAY') {
3132: $value = '('.join(', ', @{ $value }).')';
3133: } else {
3134: $value = &unescape($value);
3135: }
3136: return $value;
3137: }
3138:
3139:
1.107 albertel 3140: sub relative_to_absolute {
3141: my ($url,$output)=@_;
3142: my $parser=HTML::TokeParser->new(\$output);
3143: my $token;
3144: my $thisdir=$url;
3145: my @rlinks=();
3146: while ($token=$parser->get_token) {
3147: if ($token->[0] eq 'S') {
3148: if ($token->[1] eq 'a') {
3149: if ($token->[2]->{'href'}) {
3150: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3151: }
3152: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3153: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3154: } elsif ($token->[1] eq 'base') {
3155: $thisdir=$token->[2]->{'href'};
3156: }
3157: }
3158: }
3159: $thisdir=~s-/[^/]*$--;
1.356 albertel 3160: foreach my $link (@rlinks) {
3161: unless (($link=~/^http:\/\//i) ||
3162: ($link=~/^\//) ||
3163: ($link=~/^javascript:/i) ||
3164: ($link=~/^mailto:/i) ||
3165: ($link=~/^\#/)) {
3166: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3167: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3168: }
3169: }
3170: # -------------------------------------------------- Deal with Applet codebases
3171: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3172: return $output;
3173: }
3174:
1.112 bowersj2 3175: =pod
3176:
1.648 raeburn 3177: =item * &get_student_view()
1.112 bowersj2 3178:
3179: show a snapshot of what student was looking at
3180:
3181: =cut
3182:
1.10 albertel 3183: sub get_student_view {
1.186 albertel 3184: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3185: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3186: my (%form);
1.10 albertel 3187: my @elements=('symb','courseid','domain','username');
3188: foreach my $element (@elements) {
1.186 albertel 3189: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3190: }
1.186 albertel 3191: if (defined($moreenv)) {
3192: %form=(%form,%{$moreenv});
3193: }
1.236 albertel 3194: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3195: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3196: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3197: $userview=~s/\<body[^\>]*\>//gi;
3198: $userview=~s/\<\/body\>//gi;
3199: $userview=~s/\<html\>//gi;
3200: $userview=~s/\<\/html\>//gi;
3201: $userview=~s/\<head\>//gi;
3202: $userview=~s/\<\/head\>//gi;
3203: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 3204: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 3205: if (wantarray) {
3206: return ($userview,$response);
3207: } else {
3208: return $userview;
3209: }
3210: }
3211:
3212: sub get_student_view_with_retries {
3213: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
3214:
3215: my $ok = 0; # True if we got a good response.
3216: my $content;
3217: my $response;
3218:
3219: # Try to get the student_view done. within the retries count:
3220:
3221: do {
3222: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
3223: $ok = $response->is_success;
3224: if (!$ok) {
3225: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
3226: }
3227: $retries--;
3228: } while (!$ok && ($retries > 0));
3229:
3230: if (!$ok) {
3231: $content = ''; # On error return an empty content.
3232: }
1.651 www 3233: if (wantarray) {
3234: return ($content, $response);
3235: } else {
3236: return $content;
3237: }
1.11 albertel 3238: }
3239:
1.112 bowersj2 3240: =pod
3241:
1.648 raeburn 3242: =item * &get_student_answers()
1.112 bowersj2 3243:
3244: show a snapshot of how student was answering problem
3245:
3246: =cut
3247:
1.11 albertel 3248: sub get_student_answers {
1.100 sakharuk 3249: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 3250: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3251: my (%moreenv);
1.11 albertel 3252: my @elements=('symb','courseid','domain','username');
3253: foreach my $element (@elements) {
1.186 albertel 3254: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3255: }
1.186 albertel 3256: $moreenv{'grade_target'}='answer';
3257: %moreenv=(%form,%moreenv);
1.497 raeburn 3258: $feedurl = &Apache::lonnet::clutter($feedurl);
3259: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 3260: return $userview;
1.1 albertel 3261: }
1.116 albertel 3262:
3263: =pod
3264:
3265: =item * &submlink()
3266:
1.242 albertel 3267: Inputs: $text $uname $udom $symb $target
1.116 albertel 3268:
3269: Returns: A link to grades.pm such as to see the SUBM view of a student
3270:
3271: =cut
3272:
3273: ###############################################
3274: sub submlink {
1.242 albertel 3275: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 3276: if (!($uname && $udom)) {
3277: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3278: &Apache::lonnet::whichuser($symb);
1.116 albertel 3279: if (!$symb) { $symb=$cursymb; }
3280: }
1.254 matthew 3281: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3282: $symb=&escape($symb);
1.242 albertel 3283: if ($target) { $target="target=\"$target\""; }
3284: return '<a href="/adm/grades?&command=submission&'.
3285: 'symb='.$symb.'&student='.$uname.
3286: '&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
3287: }
3288: ##############################################
3289:
3290: =pod
3291:
3292: =item * &pgrdlink()
3293:
3294: Inputs: $text $uname $udom $symb $target
3295:
3296: Returns: A link to grades.pm such as to see the PGRD view of a student
3297:
3298: =cut
3299:
3300: ###############################################
3301: sub pgrdlink {
3302: my $link=&submlink(@_);
3303: $link=~s/(&command=submission)/$1&showgrading=yes/;
3304: return $link;
3305: }
3306: ##############################################
3307:
3308: =pod
3309:
3310: =item * &pprmlink()
3311:
3312: Inputs: $text $uname $udom $symb $target
3313:
3314: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 3315: student and a specific resource
1.242 albertel 3316:
3317: =cut
3318:
3319: ###############################################
3320: sub pprmlink {
3321: my ($text,$uname,$udom,$symb,$target)=@_;
3322: if (!($uname && $udom)) {
3323: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 3324: &Apache::lonnet::whichuser($symb);
1.242 albertel 3325: if (!$symb) { $symb=$cursymb; }
3326: }
1.254 matthew 3327: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 3328: $symb=&escape($symb);
1.242 albertel 3329: if ($target) { $target="target=\"$target\""; }
1.595 albertel 3330: return '<a href="/adm/parmset?command=set&'.
3331: 'symb='.$symb.'&uname='.$uname.
3332: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 3333: }
3334: ##############################################
1.37 matthew 3335:
1.112 bowersj2 3336: =pod
3337:
3338: =back
3339:
3340: =cut
3341:
1.37 matthew 3342: ###############################################
1.51 www 3343:
3344:
3345: sub timehash {
3346: my @ltime=localtime(shift);
3347: return ( 'seconds' => $ltime[0],
3348: 'minutes' => $ltime[1],
3349: 'hours' => $ltime[2],
3350: 'day' => $ltime[3],
3351: 'month' => $ltime[4]+1,
3352: 'year' => $ltime[5]+1900,
3353: 'weekday' => $ltime[6],
3354: 'dayyear' => $ltime[7]+1,
3355: 'dlsav' => $ltime[8] );
3356: }
3357:
1.370 www 3358: sub utc_string {
3359: my ($date)=@_;
1.371 www 3360: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 3361: }
3362:
1.51 www 3363: sub maketime {
3364: my %th=@_;
3365: return POSIX::mktime(
3366: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 3367: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 3368: }
3369:
3370: #########################################
1.51 www 3371:
3372: sub findallcourses {
1.482 raeburn 3373: my ($roles,$uname,$udom) = @_;
1.355 albertel 3374: my %roles;
3375: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 3376: my %courses;
1.51 www 3377: my $now=time;
1.482 raeburn 3378: if (!defined($uname)) {
3379: $uname = $env{'user.name'};
3380: }
3381: if (!defined($udom)) {
3382: $udom = $env{'user.domain'};
3383: }
3384: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
3385: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
3386: if (!%roles) {
3387: %roles = (
3388: cc => 1,
3389: in => 1,
3390: ep => 1,
3391: ta => 1,
3392: cr => 1,
3393: st => 1,
3394: );
3395: }
3396: foreach my $entry (keys(%roleshash)) {
3397: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
3398: if ($trole =~ /^cr/) {
3399: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
3400: } else {
3401: next if (!exists($roles{$trole}));
3402: }
3403: if ($tend) {
3404: next if ($tend < $now);
3405: }
3406: if ($tstart) {
3407: next if ($tstart > $now);
3408: }
3409: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
3410: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
3411: if ($secpart eq '') {
3412: ($cnum,$role) = split(/_/,$cnumpart);
3413: $sec = 'none';
3414: $realsec = '';
3415: } else {
3416: $cnum = $cnumpart;
3417: ($sec,$role) = split(/_/,$secpart);
3418: $realsec = $sec;
1.490 raeburn 3419: }
1.482 raeburn 3420: $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
3421: }
3422: } else {
3423: foreach my $key (keys(%env)) {
1.483 albertel 3424: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
3425: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 3426: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
3427: next if ($role eq 'ca' || $role eq 'aa');
3428: next if (%roles && !exists($roles{$role}));
3429: my ($starttime,$endtime)=split(/\./,$env{$key});
3430: my $active=1;
3431: if ($starttime) {
3432: if ($now<$starttime) { $active=0; }
3433: }
3434: if ($endtime) {
3435: if ($now>$endtime) { $active=0; }
3436: }
3437: if ($active) {
3438: if ($sec eq '') {
3439: $sec = 'none';
3440: }
3441: $courses{$cdom.'_'.$cnum}{$sec} =
3442: $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474 raeburn 3443: }
3444: }
1.51 www 3445: }
3446: }
1.474 raeburn 3447: return %courses;
1.51 www 3448: }
1.37 matthew 3449:
1.54 www 3450: ###############################################
1.474 raeburn 3451:
3452: sub blockcheck {
1.482 raeburn 3453: my ($setters,$activity,$uname,$udom) = @_;
1.490 raeburn 3454:
3455: if (!defined($udom)) {
3456: $udom = $env{'user.domain'};
3457: }
3458: if (!defined($uname)) {
3459: $uname = $env{'user.name'};
3460: }
3461:
3462: # If uname and udom are for a course, check for blocks in the course.
3463:
3464: if (&Apache::lonnet::is_course($udom,$uname)) {
3465: my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502 raeburn 3466: my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490 raeburn 3467: return ($startblock,$endblock);
3468: }
1.474 raeburn 3469:
1.502 raeburn 3470: my $startblock = 0;
3471: my $endblock = 0;
1.482 raeburn 3472: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 3473:
1.490 raeburn 3474: # If uname is for a user, and activity is course-specific, i.e.,
3475: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 3476:
1.490 raeburn 3477: if (($activity eq 'boards' || $activity eq 'chat' ||
3478: $activity eq 'groups') && ($env{'request.course.id'})) {
3479: foreach my $key (keys(%live_courses)) {
3480: if ($key ne $env{'request.course.id'}) {
3481: delete($live_courses{$key});
3482: }
3483: }
3484: }
3485:
3486: my $otheruser = 0;
3487: my %own_courses;
3488: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
3489: # Resource belongs to user other than current user.
3490: $otheruser = 1;
3491: # Gather courses for current user
3492: %own_courses =
3493: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
3494: }
3495:
3496: # Gather active course roles - course coordinator, instructor,
3497: # exam proctor, ta, student, or custom role.
1.474 raeburn 3498:
3499: foreach my $course (keys(%live_courses)) {
1.482 raeburn 3500: my ($cdom,$cnum);
3501: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
3502: $cdom = $env{'course.'.$course.'.domain'};
3503: $cnum = $env{'course.'.$course.'.num'};
3504: } else {
1.490 raeburn 3505: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 3506: }
3507: my $no_ownblock = 0;
3508: my $no_userblock = 0;
1.533 raeburn 3509: if ($otheruser && $activity ne 'com') {
1.490 raeburn 3510: # Check if current user has 'evb' priv for this
3511: if (defined($own_courses{$course})) {
3512: foreach my $sec (keys(%{$own_courses{$course}})) {
3513: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
3514: if ($sec ne 'none') {
3515: $checkrole .= '/'.$sec;
3516: }
3517: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3518: $no_ownblock = 1;
3519: last;
3520: }
3521: }
3522: }
3523: # if they have 'evb' priv and are currently not playing student
3524: next if (($no_ownblock) &&
3525: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
3526: }
1.474 raeburn 3527: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 3528: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 3529: if ($sec ne 'none') {
1.482 raeburn 3530: $checkrole .= '/'.$sec;
1.474 raeburn 3531: }
1.490 raeburn 3532: if ($otheruser) {
3533: # Resource belongs to user other than current user.
3534: # Assemble privs for that user, and check for 'evb' priv.
1.482 raeburn 3535: my ($trole,$tdom,$tnum,$tsec);
3536: my $entry = $live_courses{$course}{$sec};
3537: if ($entry =~ /^cr/) {
3538: ($trole,$tdom,$tnum,$tsec) =
3539: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
3540: } else {
3541: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
3542: }
3543: my ($spec,$area,$trest,%allroles,%userroles);
3544: $area = '/'.$tdom.'/'.$tnum;
3545: $trest = $tnum;
3546: if ($tsec ne '') {
3547: $area .= '/'.$tsec;
3548: $trest .= '/'.$tsec;
3549: }
3550: $spec = $trole.'.'.$area;
3551: if ($trole =~ /^cr/) {
3552: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
3553: $tdom,$spec,$trest,$area);
3554: } else {
3555: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
3556: $tdom,$spec,$trest,$area);
3557: }
3558: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486 raeburn 3559: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
3560: if ($1) {
3561: $no_userblock = 1;
3562: last;
3563: }
3564: }
1.490 raeburn 3565: } else {
3566: # Resource belongs to current user
3567: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 3568: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
3569: $no_ownblock = 1;
3570: last;
3571: }
1.474 raeburn 3572: }
3573: }
3574: # if they have the evb priv and are currently not playing student
1.482 raeburn 3575: next if (($no_ownblock) &&
1.491 albertel 3576: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 3577: next if ($no_userblock);
1.474 raeburn 3578:
1.490 raeburn 3579: # Retrieve blocking times and identity of blocker for course
3580: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 3581:
3582: my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
3583: if (($start != 0) &&
3584: (($startblock == 0) || ($startblock > $start))) {
3585: $startblock = $start;
3586: }
3587: if (($end != 0) &&
3588: (($endblock == 0) || ($endblock < $end))) {
3589: $endblock = $end;
3590: }
1.490 raeburn 3591: }
3592: return ($startblock,$endblock);
3593: }
3594:
3595: sub get_blocks {
3596: my ($setters,$activity,$cdom,$cnum) = @_;
3597: my $startblock = 0;
3598: my $endblock = 0;
3599: my $course = $cdom.'_'.$cnum;
3600: $setters->{$course} = {};
3601: $setters->{$course}{'staff'} = [];
3602: $setters->{$course}{'times'} = [];
3603: my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
3604: foreach my $record (keys(%records)) {
3605: my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
3606: if ($start <= time && $end >= time) {
3607: my ($staff_name,$staff_dom,$title,$blocks) =
3608: &parse_block_record($records{$record});
3609: if ($blocks->{$activity} eq 'on') {
3610: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
3611: push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491 albertel 3612: if ( ($startblock == 0) || ($startblock > $start) ) {
3613: $startblock = $start;
1.490 raeburn 3614: }
1.491 albertel 3615: if ( ($endblock == 0) || ($endblock < $end) ) {
3616: $endblock = $end;
1.474 raeburn 3617: }
3618: }
3619: }
3620: }
3621: return ($startblock,$endblock);
3622: }
3623:
3624: sub parse_block_record {
3625: my ($record) = @_;
3626: my ($setuname,$setudom,$title,$blocks);
3627: if (ref($record) eq 'HASH') {
3628: ($setuname,$setudom) = split(/:/,$record->{'setter'});
3629: $title = &unescape($record->{'event'});
3630: $blocks = $record->{'blocks'};
3631: } else {
3632: my @data = split(/:/,$record,3);
3633: if (scalar(@data) eq 2) {
3634: $title = $data[1];
3635: ($setuname,$setudom) = split(/@/,$data[0]);
3636: } else {
3637: ($setuname,$setudom,$title) = @data;
3638: }
3639: $blocks = { 'com' => 'on' };
3640: }
3641: return ($setuname,$setudom,$title,$blocks);
3642: }
3643:
3644: sub build_block_table {
3645: my ($startblock,$endblock,$setters) = @_;
3646: my %lt = &Apache::lonlocal::texthash(
3647: 'cacb' => 'Currently active communication blocks',
3648: 'cour' => 'Course',
3649: 'dura' => 'Duration',
3650: 'blse' => 'Block set by'
3651: );
3652: my $output;
1.476 raeburn 3653: $output = '<br />'.$lt{'cacb'}.':<br />';
1.474 raeburn 3654: $output .= &start_data_table();
3655: $output .= '
3656: <tr>
3657: <th>'.$lt{'cour'}.'</th>
3658: <th>'.$lt{'dura'}.'</th>
3659: <th>'.$lt{'blse'}.'</th>
3660: </tr>
3661: ';
3662: foreach my $course (keys(%{$setters})) {
3663: my %courseinfo=&Apache::lonnet::coursedescription($course);
3664: for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
3665: my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490 raeburn 3666: my $fullname = &plainname($uname,$udom);
3667: if (defined($env{'user.name'}) && defined($env{'user.domain'})
3668: && $env{'user.name'} ne 'public'
3669: && $env{'user.domain'} ne 'public') {
3670: $fullname = &aboutmewrapper($fullname,$uname,$udom);
3671: }
1.474 raeburn 3672: my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
3673: $openblock = &Apache::lonlocal::locallocaltime($openblock);
3674: $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
3675: $output .= &Apache::loncommon::start_data_table_row().
3676: '<td>'.$courseinfo{'description'}.'</td>'.
3677: '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490 raeburn 3678: '<td>'.$fullname.'</td>'.
1.474 raeburn 3679: &Apache::loncommon::end_data_table_row();
3680: }
3681: }
3682: $output .= &end_data_table();
3683: }
3684:
1.490 raeburn 3685: sub blocking_status {
3686: my ($activity,$uname,$udom) = @_;
3687: my %setters;
3688: my ($blocked,$output,$ownitem,$is_course);
3689: my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
3690: if ($startblock && $endblock) {
3691: $blocked = 1;
3692: if (wantarray) {
3693: my $category;
3694: if ($activity eq 'boards') {
3695: $category = 'Discussion posts in this course';
3696: } elsif ($activity eq 'blogs') {
3697: $category = 'Blogs';
3698: } elsif ($activity eq 'port') {
3699: if (defined($uname) && defined($udom)) {
3700: if ($uname eq $env{'user.name'} &&
3701: $udom eq $env{'user.domain'}) {
3702: $ownitem = 1;
3703: }
3704: }
3705: $is_course = &Apache::lonnet::is_course($udom,$uname);
3706: if ($ownitem) {
3707: $category = 'Your portfolio files';
3708: } elsif ($is_course) {
3709: my $coursedesc;
3710: foreach my $course (keys(%setters)) {
3711: my %courseinfo =
3712: &Apache::lonnet::coursedescription($course);
3713: $coursedesc = $courseinfo{'description'};
3714: }
3715: $category = "Group files in the course '$coursedesc'";
3716: } else {
3717: $category = 'Portfolio files belonging to ';
3718: if ($env{'user.name'} eq 'public' &&
3719: $env{'user.domain'} eq 'public') {
3720: $category .= &plainname($uname,$udom);
3721: } else {
3722: $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);
3723: }
3724: }
3725: } elsif ($activity eq 'groups') {
3726: $category = 'Groups in this course';
3727: }
3728: my $showstart = &Apache::lonlocal::locallocaltime($startblock);
3729: my $showend = &Apache::lonlocal::locallocaltime($endblock);
3730: $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
3731: if (!($activity eq 'port' && !($ownitem) && !($is_course))) {
3732: $output .= &build_block_table($startblock,$endblock,\%setters);
3733: }
3734: }
3735: }
3736: if (wantarray) {
3737: return ($blocked,$output);
3738: } else {
3739: return $blocked;
3740: }
3741: }
3742:
1.60 matthew 3743: ###############################################
3744:
3745: =pod
3746:
1.112 bowersj2 3747: =head1 Domain Template Functions
3748:
3749: =over 4
3750:
3751: =item * &determinedomain()
1.60 matthew 3752:
3753: Inputs: $domain (usually will be undef)
3754:
1.63 www 3755: Returns: Determines which domain should be used for designs
1.60 matthew 3756:
3757: =cut
1.54 www 3758:
1.60 matthew 3759: ###############################################
1.63 www 3760: sub determinedomain {
3761: my $domain=shift;
1.531 albertel 3762: if (! $domain) {
1.60 matthew 3763: # Determine domain if we have not been given one
3764: $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258 albertel 3765: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
3766: if ($env{'request.role.domain'}) {
3767: $domain=$env{'request.role.domain'};
1.60 matthew 3768: }
3769: }
1.63 www 3770: return $domain;
3771: }
3772: ###############################################
1.517 raeburn 3773:
1.518 albertel 3774: sub devalidate_domconfig_cache {
3775: my ($udom)=@_;
3776: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
3777: }
3778:
3779: # ---------------------- Get domain configuration for a domain
3780: sub get_domainconf {
3781: my ($udom) = @_;
3782: my $cachetime=1800;
3783: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
3784: if (defined($cached)) { return %{$result}; }
3785:
3786: my %domconfig = &Apache::lonnet::get_dom('configuration',
3787: ['login','rolecolors'],$udom);
1.632 raeburn 3788: my (%designhash,%legacy);
1.518 albertel 3789: if (keys(%domconfig) > 0) {
3790: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 3791: if (keys(%{$domconfig{'login'}})) {
3792: foreach my $key (keys(%{$domconfig{'login'}})) {
3793: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
3794: }
3795: } else {
3796: $legacy{'login'} = 1;
1.518 albertel 3797: }
1.632 raeburn 3798: } else {
3799: $legacy{'login'} = 1;
1.518 albertel 3800: }
3801: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 3802: if (keys(%{$domconfig{'rolecolors'}})) {
3803: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
3804: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
3805: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
3806: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
3807: }
1.518 albertel 3808: }
3809: }
1.632 raeburn 3810: } else {
3811: $legacy{'rolecolors'} = 1;
1.518 albertel 3812: }
1.632 raeburn 3813: } else {
3814: $legacy{'rolecolors'} = 1;
1.518 albertel 3815: }
1.632 raeburn 3816: if (keys(%legacy) > 0) {
3817: my %legacyhash = &get_legacy_domconf($udom);
3818: foreach my $item (keys(%legacyhash)) {
3819: if ($item =~ /^\Q$udom\E\.login/) {
3820: if ($legacy{'login'}) {
3821: $designhash{$item} = $legacyhash{$item};
3822: }
3823: } else {
3824: if ($legacy{'rolecolors'}) {
3825: $designhash{$item} = $legacyhash{$item};
3826: }
1.518 albertel 3827: }
3828: }
3829: }
1.632 raeburn 3830: } else {
3831: %designhash = &get_legacy_domconf($udom);
1.518 albertel 3832: }
3833: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
3834: $cachetime);
3835: return %designhash;
3836: }
3837:
1.632 raeburn 3838: sub get_legacy_domconf {
3839: my ($udom) = @_;
3840: my %legacyhash;
3841: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
3842: my $designfile = $designdir.'/'.$udom.'.tab';
3843: if (-e $designfile) {
3844: if ( open (my $fh,"<$designfile") ) {
3845: while (my $line = <$fh>) {
3846: next if ($line =~ /^\#/);
3847: chomp($line);
3848: my ($key,$val)=(split(/\=/,$line));
3849: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
3850: }
3851: close($fh);
3852: }
3853: }
3854: if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
3855: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
3856: }
3857: return %legacyhash;
3858: }
3859:
1.63 www 3860: =pod
3861:
1.112 bowersj2 3862: =item * &domainlogo()
1.63 www 3863:
3864: Inputs: $domain (usually will be undef)
3865:
3866: Returns: A link to a domain logo, if the domain logo exists.
3867: If the domain logo does not exist, a description of the domain.
3868:
3869: =cut
1.112 bowersj2 3870:
1.63 www 3871: ###############################################
3872: sub domainlogo {
1.517 raeburn 3873: my $domain = &determinedomain(shift);
1.518 albertel 3874: my %designhash = &get_domainconf($domain);
1.517 raeburn 3875: # See if there is a logo
3876: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 3877: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 3878: if ($imgsrc =~ m{^/(adm|res)/}) {
3879: if ($imgsrc =~ m{^/res/}) {
3880: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
3881: &Apache::lonnet::repcopy($local_name);
3882: }
3883: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 3884: }
3885: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 3886: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
3887: return &Apache::lonnet::domain($domain,'description');
1.59 www 3888: } else {
1.60 matthew 3889: return '';
1.59 www 3890: }
3891: }
1.63 www 3892: ##############################################
3893:
3894: =pod
3895:
1.112 bowersj2 3896: =item * &designparm()
1.63 www 3897:
3898: Inputs: $which parameter; $domain (usually will be undef)
3899:
3900: Returns: value of designparamter $which
3901:
3902: =cut
1.112 bowersj2 3903:
1.397 albertel 3904:
1.400 albertel 3905: ##############################################
1.397 albertel 3906: sub designparm {
3907: my ($which,$domain)=@_;
1.258 albertel 3908: if ($env{'browser.blackwhite'} eq 'on') {
1.635 raeburn 3909: if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110 www 3910: return '#000000';
3911: }
1.635 raeburn 3912: if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110 www 3913: return '#FFFFFF';
3914: }
3915: if ($which=~/\.tabbg$/) {
3916: return '#CCCCCC';
3917: }
3918: }
1.397 albertel 3919: if (exists($env{'environment.color.'.$which})) {
1.258 albertel 3920: return $env{'environment.color.'.$which};
1.96 www 3921: }
1.63 www 3922: $domain=&determinedomain($domain);
1.518 albertel 3923: my %domdesign = &get_domainconf($domain);
1.520 raeburn 3924: my $output;
1.517 raeburn 3925: if ($domdesign{$domain.'.'.$which} ne '') {
1.520 raeburn 3926: $output = $domdesign{$domain.'.'.$which};
1.63 www 3927: } else {
1.520 raeburn 3928: $output = $defaultdesign{$which};
3929: }
3930: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 3931: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 3932: if ($output =~ m{^/(adm|res)/}) {
3933: if ($output =~ m{^/res/}) {
3934: my $local_name = &Apache::lonnet::filelocation('',$output);
3935: &Apache::lonnet::repcopy($local_name);
3936: }
1.520 raeburn 3937: $output = &lonhttpdurl($output);
3938: }
1.63 www 3939: }
1.520 raeburn 3940: return $output;
1.63 www 3941: }
1.59 www 3942:
1.60 matthew 3943: ###############################################
3944: ###############################################
3945:
3946: =pod
3947:
1.112 bowersj2 3948: =back
3949:
1.549 albertel 3950: =head1 HTML Helpers
1.112 bowersj2 3951:
3952: =over 4
3953:
3954: =item * &bodytag()
1.60 matthew 3955:
3956: Returns a uniform header for LON-CAPA web pages.
3957:
3958: Inputs:
3959:
1.112 bowersj2 3960: =over 4
3961:
3962: =item * $title, A title to be displayed on the page.
3963:
3964: =item * $function, the current role (can be undef).
3965:
3966: =item * $addentries, extra parameters for the <body> tag.
3967:
3968: =item * $bodyonly, if defined, only return the <body> tag.
3969:
3970: =item * $domain, if defined, force a given domain.
3971:
3972: =item * $forcereg, if page should register as content page (relevant for
1.86 www 3973: text interface only)
1.60 matthew 3974:
1.326 albertel 3975: =item * $customtitle, alternate text to use instead of $title
3976: in the title box that appears, this text
3977: is not auto translated like the $title is
1.309 albertel 3978:
3979: =item * $notopbar, if true, keep the 'what is this' info but remove the
3980: navigational links
1.317 albertel 3981:
1.338 albertel 3982: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
3983:
3984: =item * $notitle, if true keep the nav controls, but remove the title bar
3985:
1.361 albertel 3986: =item * $no_inline_link, if true and in remote mode, don't show the
3987: 'Switch To Inline Menu' link
3988:
1.460 albertel 3989: =item * $args, optional argument valid values are
3990: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 3991: inherit_jsmath -> when creating popup window in a page,
3992: should it have jsmath forced on by the
3993: current page
1.460 albertel 3994:
1.112 bowersj2 3995: =back
3996:
1.60 matthew 3997: Returns: A uniform header for LON-CAPA web pages.
3998: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
3999: If $bodyonly is undef or zero, an html string containing a <body> tag and
4000: other decorations will be returned.
4001:
4002: =cut
4003:
1.54 www 4004: sub bodytag {
1.309 albertel 4005: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460 albertel 4006: $notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339 albertel 4007:
1.460 albertel 4008: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 4009:
1.183 matthew 4010: $function = &get_users_function() if (!$function);
1.339 albertel 4011: my $img = &designparm($function.'.img',$domain);
4012: my $font = &designparm($function.'.font',$domain);
4013: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
4014:
4015: my %design = ( 'style' => 'margin-top: 0px',
1.535 albertel 4016: 'bgcolor' => $pgbg,
1.339 albertel 4017: 'text' => $font,
4018: 'alink' => &designparm($function.'.alink',$domain),
4019: 'vlink' => &designparm($function.'.vlink',$domain),
4020: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 4021: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 4022:
1.63 www 4023: # role and realm
1.378 raeburn 4024: my ($role,$realm) = split(/\./,$env{'request.role'},2);
4025: if ($role eq 'ca') {
1.479 albertel 4026: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 4027: $realm = &plainname($rname,$rdom);
1.378 raeburn 4028: }
1.55 www 4029: # realm
1.258 albertel 4030: if ($env{'request.course.id'}) {
1.378 raeburn 4031: if ($env{'request.role'} !~ /^cr/) {
4032: $role = &Apache::lonnet::plaintext($role,&course_type());
4033: }
1.359 albertel 4034: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 4035: } else {
4036: $role = &Apache::lonnet::plaintext($role);
1.54 www 4037: }
1.433 albertel 4038:
1.359 albertel 4039: if (!$realm) { $realm=' '; }
1.55 www 4040: # Set messages
1.60 matthew 4041: my $messages=&domainlogo($domain);
1.330 albertel 4042:
1.438 albertel 4043: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 4044:
1.101 www 4045: # construct main body tag
1.359 albertel 4046: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 4047: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 4048:
1.530 albertel 4049: if ($bodyonly) {
1.60 matthew 4050: return $bodytag;
1.258 albertel 4051: } elsif ($env{'browser.interface'} eq 'textual') {
1.95 www 4052: # Accessibility
1.224 raeburn 4053:
1.337 albertel 4054: $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338 albertel 4055: if (!$notitle) {
1.337 albertel 4056: $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
4057: }
4058: return $bodytag;
1.359 albertel 4059: }
4060:
1.410 albertel 4061: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433 albertel 4062: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
4063: undef($role);
1.434 albertel 4064: } else {
4065: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433 albertel 4066: }
1.359 albertel 4067:
4068: my $roleinfo=(<<ENDROLE);
4069: <td class="LC_title_bar_who">
4070: <div class="LC_title_bar_name">
1.410 albertel 4071: $name
1.361 albertel 4072:
1.359 albertel 4073: </div>
4074: <div class="LC_title_bar_role">
1.361 albertel 4075: $role
1.359 albertel 4076: </div>
4077: <div class="LC_title_bar_realm">
1.361 albertel 4078: $realm
1.359 albertel 4079: </div>
1.206 albertel 4080: </td>
4081: ENDROLE
1.235 raeburn 4082:
1.359 albertel 4083: my $titleinfo = '<span class="LC_title_bar_title">'.$title.'</span>';
4084: if ($customtitle) {
4085: $titleinfo = $customtitle;
4086: }
4087: #
4088: # Extra info if you are the DC
4089: my $dc_info = '';
4090: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
4091: $env{'course.'.$env{'request.course.id'}.
4092: '.domain'}.'/'})) {
4093: my $cid = $env{'request.course.id'};
4094: $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 4095: $dc_info =~ s/\s+$//;
1.359 albertel 4096: $dc_info = '('.$dc_info.')';
4097: }
4098:
1.644 www 4099: if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359 albertel 4100: # No Remote
1.258 albertel 4101: if ($env{'request.state'} eq 'construct') {
1.359 albertel 4102: $forcereg=1;
4103: }
4104:
4105: if (!$customtitle && $env{'request.state'} eq 'construct') {
4106: # this is for resources; directories have customtitle, and crumbs
4107: # and select recent are created in lonpubdir.pm
1.229 albertel 4108: my ($uname,$thisdisfn)=
1.258 albertel 4109: ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229 albertel 4110: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
4111: $formaction=~s/\/+/\//g;
4112:
1.359 albertel 4113: my $parentpath = '';
4114: my $lastitem = '';
4115: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
4116: $parentpath = $1;
4117: $lastitem = $2;
4118: } else {
4119: $lastitem = $thisdisfn;
4120: }
4121: $titleinfo =
1.640 bisitz 4122: &Apache::loncommon::help_open_menu('','',3,'Authoring')
4123: .'<b>'.&mt('Construction Space').'</b>: '
4124: .'<form name="dirs" method="post" action="'.$formaction
1.359 albertel 4125: .'" target="_top"><tt><b>'
4126: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<font size=\"+1\">$lastitem</font></b></tt><br />"
4127: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
4128: .'</form>'
4129: .&Apache::lonmenu::constspaceform();
1.235 raeburn 4130: }
1.359 albertel 4131:
1.337 albertel 4132: my $titletable;
1.338 albertel 4133: if (!$notitle) {
1.337 albertel 4134: $titletable =
1.359 albertel 4135: '<table id="LC_title_bar">'.
4136: "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
4137: '</tr></table>';
1.337 albertel 4138: }
1.359 albertel 4139: if ($notopbar) {
4140: $bodytag .= $titletable;
4141: } else {
4142: if ($env{'request.state'} eq 'construct') {
1.337 albertel 4143: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
4144: $titletable);
1.272 raeburn 4145: } else {
1.336 albertel 4146: $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359 albertel 4147: $titletable;
1.272 raeburn 4148: }
1.235 raeburn 4149: }
4150: return $bodytag;
1.94 www 4151: }
1.95 www 4152:
1.93 www 4153: #
1.95 www 4154: # Top frame rendering, Remote is up
1.93 www 4155: #
1.359 albertel 4156:
1.517 raeburn 4157: my $imgsrc = $img;
4158: if ($img =~ /^\/adm/) {
1.575 albertel 4159: $imgsrc = &lonhttpdurl($img);
1.517 raeburn 4160: }
4161: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359 albertel 4162:
1.305 www 4163: # Explicit link to get inline menu
1.361 albertel 4164: my $menu= ($no_inline_link?''
4165: :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245 matthew 4166: #
1.338 albertel 4167: if ($notitle) {
1.337 albertel 4168: return $bodytag;
4169: }
1.94 www 4170: return(<<ENDBODY);
1.60 matthew 4171: $bodytag
1.359 albertel 4172: <table id="LC_title_bar" class="LC_with_remote">
1.368 albertel 4173: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359 albertel 4174: <td class="LC_title_bar_domain_logo">$messages </td>
1.54 www 4175: </tr>
1.359 albertel 4176: <tr><td>$titleinfo $dc_info $menu</td>
4177: $roleinfo
1.368 albertel 4178: </tr>
1.356 albertel 4179: </table>
1.54 www 4180: ENDBODY
1.182 matthew 4181: }
4182:
1.330 albertel 4183: sub make_attr_string {
4184: my ($register,$attr_ref) = @_;
4185:
4186: if ($attr_ref && !ref($attr_ref)) {
4187: die("addentries Must be a hash ref ".
4188: join(':',caller(1))." ".
4189: join(':',caller(0))." ");
4190: }
4191:
4192: if ($register) {
1.339 albertel 4193: my ($on_load,$on_unload);
4194: foreach my $key (keys(%{$attr_ref})) {
4195: if (lc($key) eq 'onload') {
4196: $on_load.=$attr_ref->{$key}.';';
4197: delete($attr_ref->{$key});
4198:
4199: } elsif (lc($key) eq 'onunload') {
4200: $on_unload.=$attr_ref->{$key}.';';
4201: delete($attr_ref->{$key});
4202: }
4203: }
4204: $attr_ref->{'onload'} =
4205: &Apache::lonmenu::loadevents(). $on_load;
4206: $attr_ref->{'onunload'}=
4207: &Apache::lonmenu::unloadevents().$on_unload;
4208: }
4209:
4210: # Accessibility font enhance
4211: if ($env{'browser.fontenhance'} eq 'on') {
4212: my $style;
4213: foreach my $key (keys(%{$attr_ref})) {
4214: if (lc($key) eq 'style') {
4215: $style.=$attr_ref->{$key}.';';
4216: delete($attr_ref->{$key});
4217: }
4218: }
4219: $attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330 albertel 4220: }
1.339 albertel 4221:
4222: if ($env{'browser.blackwhite'} eq 'on') {
4223: delete($attr_ref->{'font'});
4224: delete($attr_ref->{'link'});
4225: delete($attr_ref->{'alink'});
4226: delete($attr_ref->{'vlink'});
4227: delete($attr_ref->{'bgcolor'});
4228: delete($attr_ref->{'background'});
4229: }
4230:
1.330 albertel 4231: my $attr_string;
4232: foreach my $attr (keys(%$attr_ref)) {
4233: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
4234: }
4235: return $attr_string;
4236: }
4237:
4238:
1.182 matthew 4239: ###############################################
1.251 albertel 4240: ###############################################
4241:
4242: =pod
4243:
4244: =item * &endbodytag()
4245:
4246: Returns a uniform footer for LON-CAPA web pages.
4247:
1.635 raeburn 4248: Inputs: 1 - optional reference to an args hash
4249: If in the hash, key for noredirectlink has a value which evaluates to true,
4250: a 'Continue' link is not displayed if the page contains an
4251: internal redirect in the <head></head> section,
4252: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 4253:
4254: =cut
4255:
4256: sub endbodytag {
1.635 raeburn 4257: my ($args) = @_;
1.251 albertel 4258: my $endbodytag='</body>';
1.269 albertel 4259: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 4260: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 4261: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
4262: $endbodytag=
4263: "<br /><a href=\"$env{'internal.head.redirect'}\">".
4264: &mt('Continue').'</a>'.
4265: $endbodytag;
4266: }
1.315 albertel 4267: }
1.251 albertel 4268: return $endbodytag;
4269: }
4270:
1.352 albertel 4271: =pod
4272:
4273: =item * &standard_css()
4274:
4275: Returns a style sheet
4276:
4277: Inputs: (all optional)
4278: domain -> force to color decorate a page for a specific
4279: domain
4280: function -> force usage of a specific rolish color scheme
4281: bgcolor -> override the default page bgcolor
4282:
4283: =cut
4284:
1.343 albertel 4285: sub standard_css {
1.345 albertel 4286: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 4287: $function = &get_users_function() if (!$function);
4288: my $img = &designparm($function.'.img', $domain);
4289: my $tabbg = &designparm($function.'.tabbg', $domain);
4290: my $font = &designparm($function.'.font', $domain);
1.345 albertel 4291: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 4292: my $pgbg_or_bgcolor =
4293: $bgcolor ||
1.352 albertel 4294: &designparm($function.'.pgbg', $domain);
1.382 albertel 4295: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 4296: my $alink = &designparm($function.'.alink', $domain);
4297: my $vlink = &designparm($function.'.vlink', $domain);
4298: my $link = &designparm($function.'.link', $domain);
4299:
1.602 albertel 4300: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 4301: my $mono = 'monospace';
1.352 albertel 4302: my $data_table_head = $tabbg;
4303: my $data_table_light = '#EEEEEE';
1.470 banghart 4304: my $data_table_dark = '#DDDDDD';
4305: my $data_table_darker = '#CCCCCC';
1.349 albertel 4306: my $data_table_highlight = '#FFFF00';
1.352 albertel 4307: my $mail_new = '#FFBB77';
4308: my $mail_new_hover = '#DD9955';
4309: my $mail_read = '#BBBB77';
4310: my $mail_read_hover = '#999944';
4311: my $mail_replied = '#AAAA88';
4312: my $mail_replied_hover = '#888855';
4313: my $mail_other = '#99BBBB';
4314: my $mail_other_hover = '#669999';
1.391 albertel 4315: my $table_header = '#DDDDDD';
1.489 raeburn 4316: my $feedback_link_bg = '#BBBBBB';
1.392 albertel 4317:
1.608 albertel 4318: my $border = ($env{'browser.type'} eq 'explorer' ||
4319: $env{'browser.type'} eq 'safari' ) ? '0px 2px 0px 2px'
4320: : '0px 3px 0px 4px';
1.448 albertel 4321:
1.523 albertel 4322:
1.343 albertel 4323: return <<END;
1.345 albertel 4324: h1, h2, h3, th { font-family: $sans }
1.343 albertel 4325: a:focus { color: red; background: yellow }
1.510 albertel 4326: table.thinborder,
1.523 albertel 4327:
1.510 albertel 4328: table.thinborder tr th {
4329: border-style: solid;
4330: border-width: 1px;
4331: background: $tabbg;
4332: }
1.523 albertel 4333: table.thinborder tr td {
1.510 albertel 4334: border-style: solid;
4335: border-width: 1px
4336: }
1.426 albertel 4337:
1.343 albertel 4338: form, .inline { display: inline; }
4339: .center { text-align: center; }
1.593 albertel 4340: .LC_filename {font-family: $mono; white-space:pre;}
1.350 albertel 4341: .LC_error {
4342: color: red;
4343: font-size: larger;
4344: }
1.457 albertel 4345: .LC_warning,
4346: .LC_diff_removed {
1.394 albertel 4347: color: red;
4348: }
1.532 albertel 4349:
4350: .LC_info,
1.457 albertel 4351: .LC_success,
4352: .LC_diff_added {
1.350 albertel 4353: color: green;
4354: }
1.543 albertel 4355: .LC_unknown {
4356: color: yellow;
4357: }
4358:
1.440 albertel 4359: .LC_icon {
4360: border: 0px;
4361: }
1.539 albertel 4362: .LC_indexer_icon {
4363: border: 0px;
4364: height: 22px;
4365: }
1.543 albertel 4366: .LC_docs_spacer {
4367: width: 25px;
4368: height: 1px;
4369: border: 0px;
4370: }
1.346 albertel 4371:
1.532 albertel 4372: .LC_internal_info {
4373: color: #999;
4374: }
4375:
1.458 albertel 4376: table.LC_pastsubmission {
4377: border: 1px solid black;
4378: margin: 2px;
4379: }
4380:
1.606 albertel 4381: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345 albertel 4382: width: 100%;
4383: background: $pgbg;
1.392 albertel 4384: border: 2px;
1.402 albertel 4385: border-collapse: separate;
1.403 albertel 4386: padding: 0px;
1.345 albertel 4387: }
1.392 albertel 4388:
1.606 albertel 4389: table#LC_title_bar, table.LC_breadcrumbs,
1.393 albertel 4390: table#LC_title_bar.LC_with_remote {
1.359 albertel 4391: width: 100%;
1.392 albertel 4392: border-color: $pgbg;
4393: border-style: solid;
4394: border-width: $border;
4395:
1.379 albertel 4396: background: $pgbg;
4397: font-family: $sans;
1.392 albertel 4398: border-collapse: collapse;
1.403 albertel 4399: padding: 0px;
1.359 albertel 4400: }
1.392 albertel 4401:
1.409 albertel 4402: table.LC_docs_path {
4403: width: 100%;
4404: border: 0;
4405: background: $pgbg;
4406: font-family: $sans;
4407: border-collapse: collapse;
4408: padding: 0px;
4409: }
4410:
1.359 albertel 4411: table#LC_title_bar td {
4412: background: $tabbg;
4413: }
4414: table#LC_title_bar td.LC_title_bar_who {
4415: background: $tabbg;
4416: color: $font;
1.427 albertel 4417: font: small $sans;
1.359 albertel 4418: text-align: right;
4419: }
1.469 banghart 4420: span.LC_metadata {
4421: font-family: $sans;
4422: }
1.359 albertel 4423: span.LC_title_bar_title {
1.416 albertel 4424: font: bold x-large $sans;
1.359 albertel 4425: }
4426: table#LC_title_bar td.LC_title_bar_domain_logo {
4427: background: $sidebg;
4428: text-align: right;
1.368 albertel 4429: padding: 0px;
4430: }
4431: table#LC_title_bar td.LC_title_bar_role_logo {
4432: background: $sidebg;
4433: padding: 0px;
1.359 albertel 4434: }
4435:
1.346 albertel 4436: table#LC_menubuttons_mainmenu {
1.526 www 4437: width: 100%;
1.346 albertel 4438: border: 0px;
4439: border-spacing: 1px;
1.372 albertel 4440: padding: 0px 1px;
1.346 albertel 4441: margin: 0px;
4442: border-collapse: separate;
4443: }
4444: table#LC_menubuttons img, table#LC_menubuttons_mainmenu img {
4445: border: 0px;
4446: }
1.345 albertel 4447: table#LC_top_nav td {
4448: background: $tabbg;
1.392 albertel 4449: border: 0px;
1.407 albertel 4450: font-size: small;
1.345 albertel 4451: }
4452: table#LC_top_nav td a, div#LC_top_nav a {
4453: color: $font;
4454: font-family: $sans;
4455: }
1.364 albertel 4456: table#LC_top_nav td.LC_top_nav_logo {
4457: background: $tabbg;
1.432 albertel 4458: text-align: left;
1.408 albertel 4459: white-space: nowrap;
1.432 albertel 4460: width: 31px;
1.408 albertel 4461: }
4462: table#LC_top_nav td.LC_top_nav_logo img {
1.432 albertel 4463: border: 0px;
1.408 albertel 4464: vertical-align: bottom;
1.364 albertel 4465: }
1.432 albertel 4466: table#LC_top_nav td.LC_top_nav_exit,
4467: table#LC_top_nav td.LC_top_nav_help {
4468: width: 2.0em;
4469: }
1.442 albertel 4470: table#LC_top_nav td.LC_top_nav_login {
4471: width: 4.0em;
4472: text-align: center;
4473: }
1.409 albertel 4474: table.LC_breadcrumbs td, table.LC_docs_path td {
1.357 albertel 4475: background: $tabbg;
4476: color: $font;
4477: font-family: $sans;
1.358 albertel 4478: font-size: smaller;
1.357 albertel 4479: }
1.411 albertel 4480: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409 albertel 4481: table.LC_docs_path td.LC_docs_path_component {
1.357 albertel 4482: background: $tabbg;
4483: color: $font;
4484: font-family: $sans;
4485: font-size: larger;
4486: text-align: right;
4487: }
1.383 albertel 4488: td.LC_table_cell_checkbox {
4489: text-align: center;
4490: }
4491:
1.522 albertel 4492: table#LC_mainmenu td.LC_mainmenu_column {
4493: vertical-align: top;
4494: }
4495:
1.346 albertel 4496: .LC_menubuttons_inline_text {
4497: color: $font;
4498: font-family: $sans;
4499: font-size: smaller;
4500: }
4501:
1.526 www 4502: .LC_menubuttons_link {
4503: text-decoration: none;
4504: }
4505:
1.522 albertel 4506: .LC_menubuttons_category {
1.521 www 4507: color: $font;
1.526 www 4508: background: $pgbg;
1.521 www 4509: font-family: $sans;
4510: font-size: larger;
4511: font-weight: bold;
4512: }
4513:
1.346 albertel 4514: td.LC_menubuttons_text {
1.526 www 4515: width: 90%;
1.346 albertel 4516: color: $font;
4517: font-family: $sans;
4518: }
1.526 www 4519:
1.346 albertel 4520: td.LC_menubuttons_img {
4521: }
1.526 www 4522:
1.346 albertel 4523: .LC_current_location {
4524: font-family: $sans;
4525: background: $tabbg;
4526: }
4527: .LC_new_mail {
4528: font-family: $sans;
1.634 www 4529: background: $tabbg;
1.346 albertel 4530: font-weight: bold;
4531: }
1.347 albertel 4532:
1.526 www 4533: .LC_rolesmenu_is {
4534: font-family: $sans;
4535: }
4536:
4537: .LC_rolesmenu_selected {
4538: font-family: $sans;
4539: }
4540:
4541: .LC_rolesmenu_future {
4542: font-family: $sans;
4543: }
4544:
4545:
4546: .LC_rolesmenu_will {
4547: font-family: $sans;
4548: }
4549:
4550: .LC_rolesmenu_will_not {
4551: font-family: $sans;
4552: }
4553:
4554: .LC_rolesmenu_expired {
4555: font-family: $sans;
4556: }
4557:
4558: .LC_rolesinfo {
4559: font-family: $sans;
4560: }
4561:
1.527 www 4562: .LC_dropadd_labeltext {
4563: font-family: $sans;
4564: text-align: right;
4565: }
4566:
4567: .LC_preferences_labeltext {
4568: font-family: $sans;
4569: text-align: right;
4570: }
4571:
1.666 raeburn 4572: .LC_roleslog_note {
4573: font-size: smaller;
4574: }
4575:
1.440 albertel 4576: table.LC_aboutme_port {
4577: border: 0px;
4578: border-collapse: collapse;
4579: border-spacing: 0px;
4580: }
1.349 albertel 4581: table.LC_data_table, table.LC_mail_list {
1.347 albertel 4582: border: 1px solid #000000;
1.402 albertel 4583: border-collapse: separate;
1.426 albertel 4584: border-spacing: 1px;
1.610 albertel 4585: background: $pgbg;
1.347 albertel 4586: }
1.422 albertel 4587: .LC_data_table_dense {
4588: font-size: small;
4589: }
1.507 raeburn 4590: table.LC_nested_outer {
4591: border: 1px solid #000000;
1.589 raeburn 4592: border-collapse: collapse;
1.507 raeburn 4593: border-spacing: 0px;
4594: width: 100%;
4595: }
4596: table.LC_nested {
4597: border: 0px;
1.589 raeburn 4598: border-collapse: collapse;
1.507 raeburn 4599: border-spacing: 0px;
4600: width: 100%;
4601: }
1.523 albertel 4602: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
4603: table.LC_prior_tries tr th {
1.349 albertel 4604: font-weight: bold;
4605: background-color: $data_table_head;
1.421 albertel 4606: font-size: smaller;
1.347 albertel 4607: }
1.610 albertel 4608: table.LC_data_table tr.LC_odd_row > td,
1.440 albertel 4609: table.LC_aboutme_port tr td {
1.349 albertel 4610: background-color: $data_table_light;
1.425 albertel 4611: padding: 2px;
1.347 albertel 4612: }
1.610 albertel 4613: table.LC_data_table tr.LC_even_row > td,
1.440 albertel 4614: table.LC_aboutme_port tr.LC_even_row td {
1.349 albertel 4615: background-color: $data_table_dark;
1.347 albertel 4616: }
1.425 albertel 4617: table.LC_data_table tr.LC_data_table_highlight td {
4618: background-color: $data_table_darker;
4619: }
1.639 raeburn 4620: table.LC_data_table tr td.LC_leftcol_header {
4621: background-color: $data_table_head;
4622: font-weight: bold;
4623: }
1.451 albertel 4624: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 4625: table.LC_nested tr.LC_empty_row td {
1.347 albertel 4626: background-color: #FFFFFF;
1.421 albertel 4627: font-weight: bold;
4628: font-style: italic;
4629: text-align: center;
4630: padding: 8px;
1.347 albertel 4631: }
1.507 raeburn 4632: table.LC_nested tr.LC_empty_row td {
1.465 albertel 4633: padding: 4ex
4634: }
1.507 raeburn 4635: table.LC_nested_outer tr th {
4636: font-weight: bold;
4637: background-color: $data_table_head;
4638: font-size: smaller;
4639: border-bottom: 1px solid #000000;
4640: }
4641: table.LC_nested_outer tr td.LC_subheader {
4642: background-color: $data_table_head;
4643: font-weight: bold;
4644: font-size: small;
4645: border-bottom: 1px solid #000000;
4646: text-align: right;
1.451 albertel 4647: }
1.507 raeburn 4648: table.LC_nested tr.LC_info_row td {
1.451 albertel 4649: background-color: #CCC;
4650: font-weight: bold;
4651: font-size: small;
1.507 raeburn 4652: text-align: center;
4653: }
1.589 raeburn 4654: table.LC_nested tr.LC_info_row td.LC_left_item,
4655: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 4656: text-align: left;
1.451 albertel 4657: }
1.507 raeburn 4658: table.LC_nested td {
1.451 albertel 4659: background-color: #FFF;
4660: font-size: small;
1.507 raeburn 4661: }
4662: table.LC_nested_outer tr th.LC_right_item,
4663: table.LC_nested tr.LC_info_row td.LC_right_item,
4664: table.LC_nested tr.LC_odd_row td.LC_right_item,
4665: table.LC_nested tr td.LC_right_item {
1.451 albertel 4666: text-align: right;
4667: }
4668:
1.507 raeburn 4669: table.LC_nested tr.LC_odd_row td {
1.451 albertel 4670: background-color: #EEE;
4671: }
4672:
1.473 raeburn 4673: table.LC_createuser {
4674: }
4675:
4676: table.LC_createuser tr.LC_section_row td {
4677: font-size: smaller;
4678: }
4679:
4680: table.LC_createuser tr.LC_info_row td {
4681: background-color: #CCC;
4682: font-weight: bold;
4683: text-align: center;
4684: }
4685:
1.349 albertel 4686: table.LC_calendar {
4687: border: 1px solid #000000;
4688: border-collapse: collapse;
4689: }
4690: table.LC_calendar_pickdate {
4691: font-size: xx-small;
4692: }
4693: table.LC_calendar tr td {
4694: border: 1px solid #000000;
4695: vertical-align: top;
4696: }
4697: table.LC_calendar tr td.LC_calendar_day_empty {
4698: background-color: $data_table_dark;
4699: }
4700: table.LC_calendar tr td.LC_calendar_day_current {
4701: background-color: $data_table_highlight;
4702: }
4703:
4704: table.LC_mail_list tr.LC_mail_new {
4705: background-color: $mail_new;
4706: }
4707: table.LC_mail_list tr.LC_mail_new:hover {
4708: background-color: $mail_new_hover;
4709: }
4710: table.LC_mail_list tr.LC_mail_read {
4711: background-color: $mail_read;
4712: }
4713: table.LC_mail_list tr.LC_mail_read:hover {
4714: background-color: $mail_read_hover;
4715: }
4716: table.LC_mail_list tr.LC_mail_replied {
4717: background-color: $mail_replied;
4718: }
4719: table.LC_mail_list tr.LC_mail_replied:hover {
4720: background-color: $mail_replied_hover;
4721: }
4722: table.LC_mail_list tr.LC_mail_other {
4723: background-color: $mail_other;
4724: }
4725: table.LC_mail_list tr.LC_mail_other:hover {
4726: background-color: $mail_other_hover;
4727: }
1.494 raeburn 4728: table.LC_mail_list tr.LC_mail_even {
4729: }
4730: table.LC_mail_list tr.LC_mail_odd {
4731: }
4732:
1.385 albertel 4733:
1.386 albertel 4734: table#LC_portfolio_actions {
4735: width: auto;
4736: background: $pgbg;
4737: border: 0px;
4738: border-spacing: 2px 2px;
4739: padding: 0px;
4740: margin: 0px;
4741: border-collapse: separate;
4742: }
4743: table#LC_portfolio_actions td.LC_label {
4744: background: $tabbg;
4745: text-align: right;
4746: }
4747: table#LC_portfolio_actions td.LC_value {
4748: background: $tabbg;
4749: }
1.385 albertel 4750:
1.391 albertel 4751: table#LC_cstr_controls {
4752: width: 100%;
4753: border-collapse: collapse;
4754: }
4755: table#LC_cstr_controls tr td {
4756: border: 4px solid $pgbg;
4757: padding: 4px;
4758: text-align: center;
4759: background: $tabbg;
4760: }
4761: table#LC_cstr_controls tr th {
4762: border: 4px solid $pgbg;
4763: background: $table_header;
4764: text-align: center;
4765: font-family: $sans;
4766: font-size: smaller;
4767: }
4768:
1.389 albertel 4769: table#LC_browser {
4770:
4771: }
4772: table#LC_browser tr th {
1.391 albertel 4773: background: $table_header;
1.389 albertel 4774: }
1.390 albertel 4775: table#LC_browser tr td {
4776: padding: 2px;
4777: }
1.389 albertel 4778: table#LC_browser tr.LC_browser_file,
4779: table#LC_browser tr.LC_browser_file_published {
4780: background: #CCFF88;
4781: }
4782: table#LC_browser tr.LC_browser_file_locked,
4783: table#LC_browser tr.LC_browser_file_unpublished {
4784: background: #FFAA99;
1.387 albertel 4785: }
1.389 albertel 4786: table#LC_browser tr.LC_browser_file_obsolete {
4787: background: #AAAAAA;
1.387 albertel 4788: }
1.455 albertel 4789: table#LC_browser tr.LC_browser_file_modified,
4790: table#LC_browser tr.LC_browser_file_metamodified {
1.389 albertel 4791: background: #FFFF77;
1.387 albertel 4792: }
1.389 albertel 4793: table#LC_browser tr.LC_browser_folder {
4794: background: #CCCCFF;
1.387 albertel 4795: }
1.388 albertel 4796: span.LC_current_location {
4797: font-size: x-large;
4798: background: $pgbg;
4799: }
1.387 albertel 4800:
1.395 albertel 4801: span.LC_parm_menu_item {
4802: font-size: larger;
4803: font-family: $sans;
4804: }
4805: span.LC_parm_scope_all {
4806: color: red;
4807: }
4808: span.LC_parm_scope_folder {
4809: color: green;
4810: }
4811: span.LC_parm_scope_resource {
4812: color: orange;
4813: }
4814: span.LC_parm_part {
4815: color: blue;
4816: }
4817: span.LC_parm_folder, span.LC_parm_symb {
4818: font-size: x-small;
4819: font-family: $mono;
4820: color: #AAAAAA;
4821: }
4822:
1.396 albertel 4823: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
4824: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
4825: border: 1px solid black;
4826: border-collapse: collapse;
4827: }
4828: table.LC_parm_overview_restrictions td {
4829: border-width: 1px 4px 1px 4px;
4830: border-style: solid;
4831: border-color: $pgbg;
4832: text-align: center;
4833: }
4834: table.LC_parm_overview_restrictions th {
4835: background: $tabbg;
4836: border-width: 1px 4px 1px 4px;
4837: border-style: solid;
4838: border-color: $pgbg;
4839: }
1.398 albertel 4840: table#LC_helpmenu {
4841: border: 0px;
4842: height: 55px;
4843: border-spacing: 0px;
4844: }
4845:
4846: table#LC_helpmenu fieldset legend {
4847: font-size: larger;
4848: font-weight: bold;
4849: }
1.397 albertel 4850: table#LC_helpmenu_links {
4851: width: 100%;
4852: border: 1px solid black;
4853: background: $pgbg;
4854: padding: 0px;
4855: border-spacing: 1px;
4856: }
4857: table#LC_helpmenu_links tr td {
4858: padding: 1px;
4859: background: $tabbg;
1.399 albertel 4860: text-align: center;
4861: font-weight: bold;
1.397 albertel 4862: }
1.396 albertel 4863:
1.397 albertel 4864: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
4865: table#LC_helpmenu_links a:active {
4866: text-decoration: none;
4867: color: $font;
4868: }
4869: table#LC_helpmenu_links a:hover {
4870: text-decoration: underline;
4871: color: $vlink;
4872: }
1.396 albertel 4873:
1.417 albertel 4874: .LC_chrt_popup_exists {
4875: border: 1px solid #339933;
4876: margin: -1px;
4877: }
4878: .LC_chrt_popup_up {
4879: border: 1px solid yellow;
4880: margin: -1px;
4881: }
4882: .LC_chrt_popup {
4883: border: 1px solid #8888FF;
4884: background: #CCCCFF;
4885: }
1.421 albertel 4886: table.LC_pick_box {
4887: border-collapse: separate;
4888: background: white;
4889: border: 1px solid black;
4890: border-spacing: 1px;
4891: }
4892: table.LC_pick_box td.LC_pick_box_title {
4893: background: $tabbg;
4894: font-weight: bold;
4895: text-align: right;
4896: width: 184px;
4897: padding: 8px;
4898: }
1.645 raeburn 4899: table.LC_pick_box td.LC_selfenroll_pick_box_title {
4900: background: $tabbg;
4901: font-weight: bold;
4902: text-align: right;
4903: width: 350px;
4904: padding: 8px;
4905: }
4906:
1.579 raeburn 4907: table.LC_pick_box td.LC_pick_box_value {
4908: text-align: left;
4909: padding: 8px;
4910: }
4911: table.LC_pick_box td.LC_pick_box_select {
4912: text-align: left;
4913: padding: 8px;
4914: }
1.424 albertel 4915: table.LC_pick_box td.LC_pick_box_separator {
1.421 albertel 4916: padding: 0px;
4917: height: 1px;
4918: background: black;
4919: }
4920: table.LC_pick_box td.LC_pick_box_submit {
4921: text-align: right;
4922: }
1.579 raeburn 4923: table.LC_pick_box td.LC_evenrow_value {
4924: text-align: left;
4925: padding: 8px;
4926: background-color: $data_table_light;
4927: }
4928: table.LC_pick_box td.LC_oddrow_value {
4929: text-align: left;
4930: padding: 8px;
4931: background-color: $data_table_light;
4932: }
4933: table.LC_helpform_receipt {
4934: width: 620px;
4935: border-collapse: separate;
4936: background: white;
4937: border: 1px solid black;
4938: border-spacing: 1px;
4939: }
4940: table.LC_helpform_receipt td.LC_pick_box_title {
4941: background: $tabbg;
4942: font-weight: bold;
4943: text-align: right;
4944: width: 184px;
4945: padding: 8px;
4946: }
4947: table.LC_helpform_receipt td.LC_evenrow_value {
4948: text-align: left;
4949: padding: 8px;
4950: background-color: $data_table_light;
4951: }
4952: table.LC_helpform_receipt td.LC_oddrow_value {
4953: text-align: left;
4954: padding: 8px;
4955: background-color: $data_table_light;
4956: }
4957: table.LC_helpform_receipt td.LC_pick_box_separator {
4958: padding: 0px;
4959: height: 1px;
4960: background: black;
4961: }
4962: span.LC_helpform_receipt_cat {
4963: font-weight: bold;
4964: }
1.424 albertel 4965: table.LC_group_priv_box {
4966: background: white;
4967: border: 1px solid black;
4968: border-spacing: 1px;
4969: }
4970: table.LC_group_priv_box td.LC_pick_box_title {
4971: background: $tabbg;
4972: font-weight: bold;
4973: text-align: right;
4974: width: 184px;
4975: }
4976: table.LC_group_priv_box td.LC_groups_fixed {
4977: background: $data_table_light;
4978: text-align: center;
4979: }
4980: table.LC_group_priv_box td.LC_groups_optional {
4981: background: $data_table_dark;
4982: text-align: center;
4983: }
4984: table.LC_group_priv_box td.LC_groups_functionality {
4985: background: $data_table_darker;
4986: text-align: center;
4987: font-weight: bold;
4988: }
4989: table.LC_group_priv td {
4990: text-align: left;
4991: padding: 0px;
4992: }
4993:
1.421 albertel 4994: table.LC_notify_front_page {
4995: background: white;
4996: border: 1px solid black;
4997: padding: 8px;
4998: }
4999: table.LC_notify_front_page td {
5000: padding: 8px;
5001: }
1.424 albertel 5002: .LC_navbuttons {
5003: margin: 2ex 0ex 2ex 0ex;
5004: }
1.423 albertel 5005: .LC_topic_bar {
5006: font-family: $sans;
5007: font-weight: bold;
5008: width: 100%;
5009: background: $tabbg;
5010: vertical-align: middle;
5011: margin: 2ex 0ex 2ex 0ex;
5012: }
5013: .LC_topic_bar span {
5014: vertical-align: middle;
5015: }
5016: .LC_topic_bar img {
5017: vertical-align: bottom;
5018: }
5019: table.LC_course_group_status {
5020: margin: 20px;
5021: }
5022: table.LC_status_selector td {
5023: vertical-align: top;
5024: text-align: center;
1.424 albertel 5025: padding: 4px;
5026: }
5027: table.LC_descriptive_input td.LC_description {
5028: vertical-align: top;
5029: text-align: right;
5030: font-weight: bold;
1.423 albertel 5031: }
1.599 albertel 5032: div.LC_feedback_link {
1.616 albertel 5033: clear: both;
1.599 albertel 5034: background: white;
5035: width: 100%;
1.489 raeburn 5036: }
5037: span.LC_feedback_link {
1.599 albertel 5038: background: $feedback_link_bg;
5039: font-size: larger;
5040: }
5041: span.LC_message_link {
5042: background: $feedback_link_bg;
5043: font-size: larger;
5044: position: absolute;
5045: right: 1em;
1.489 raeburn 5046: }
1.421 albertel 5047:
1.515 albertel 5048: table.LC_prior_tries {
1.524 albertel 5049: border: 1px solid #000000;
5050: border-collapse: separate;
5051: border-spacing: 1px;
1.515 albertel 5052: }
1.523 albertel 5053:
1.515 albertel 5054: table.LC_prior_tries td {
1.524 albertel 5055: padding: 2px;
1.515 albertel 5056: }
1.523 albertel 5057:
5058: .LC_answer_correct {
5059: background: #AAFFAA;
5060: color: black;
5061: }
5062: .LC_answer_charged_try {
5063: background: #FFAAAA ! important;
5064: color: black;
5065: }
5066: .LC_answer_not_charged_try,
5067: .LC_answer_no_grade,
5068: .LC_answer_late {
5069: background: #FFFFAA;
5070: color: black;
5071: }
5072: .LC_answer_previous {
5073: background: #AAAAFF;
5074: color: black;
5075: }
5076: .LC_answer_no_message {
5077: background: #FFFFFF;
5078: color: black;
5079: }
5080: .LC_answer_unknown {
5081: background: orange;
5082: color: black;
5083: }
5084:
5085:
1.529 albertel 5086: span.LC_prior_numerical,
5087: span.LC_prior_string,
5088: span.LC_prior_custom,
5089: span.LC_prior_reaction,
5090: span.LC_prior_math {
1.523 albertel 5091: font-family: monospace;
5092: white-space: pre;
5093: }
5094:
1.525 albertel 5095: span.LC_prior_string {
5096: font-family: monospace;
5097: white-space: pre;
5098: }
5099:
1.523 albertel 5100: table.LC_prior_option {
5101: width: 100%;
5102: border-collapse: collapse;
5103: }
1.528 albertel 5104: table.LC_prior_rank, table.LC_prior_match {
5105: border-collapse: collapse;
5106: }
5107: table.LC_prior_option tr td,
5108: table.LC_prior_rank tr td,
5109: table.LC_prior_match tr td {
1.524 albertel 5110: border: 1px solid #000000;
1.515 albertel 5111: }
5112:
1.519 raeburn 5113: span.LC_nobreak {
1.544 albertel 5114: white-space: nowrap;
1.519 raeburn 5115: }
5116:
1.576 raeburn 5117: span.LC_cusr_emph {
5118: font-style: italic;
5119: }
5120:
1.633 raeburn 5121: span.LC_cusr_subheading {
5122: font-weight: normal;
5123: font-size: 85%;
5124: }
5125:
1.545 albertel 5126: table.LC_docs_documents {
5127: background: #BBBBBB;
1.547 albertel 5128: border-width: 0px;
1.545 albertel 5129: border-collapse: collapse;
5130: }
5131:
5132: table.LC_docs_documents td.LC_docs_document {
5133: border: 2px solid black;
5134: padding: 4px;
5135: }
5136:
5137: .LC_docs_course_commands div {
5138: float: left;
5139: border: 4px solid #AAAAAA;
5140: padding: 4px;
5141: background: #DDDDCC;
5142: }
5143:
5144: .LC_docs_entry_move {
5145: border: 0px;
5146: border-collapse: collapse;
1.544 albertel 5147: }
5148:
1.545 albertel 5149: .LC_docs_entry_move td {
5150: border: 2px solid #BBBBBB;
5151: background: #DDDDDD;
5152: }
5153:
5154: .LC_docs_editor td.LC_docs_entry_commands {
5155: background: #DDDDDD;
5156: font-size: x-small;
5157: }
1.544 albertel 5158: .LC_docs_copy {
1.545 albertel 5159: color: #000099;
1.544 albertel 5160: }
5161: .LC_docs_cut {
1.545 albertel 5162: color: #550044;
1.544 albertel 5163: }
5164: .LC_docs_rename {
1.545 albertel 5165: color: #009900;
1.544 albertel 5166: }
5167: .LC_docs_remove {
1.545 albertel 5168: color: #990000;
5169: }
5170:
1.547 albertel 5171: .LC_docs_reinit_warn,
5172: .LC_docs_ext_edit {
5173: font-size: x-small;
5174: }
5175:
1.545 albertel 5176: .LC_docs_editor td.LC_docs_entry_title,
5177: .LC_docs_editor td.LC_docs_entry_icon {
5178: background: #FFFFBB;
5179: }
5180: .LC_docs_editor td.LC_docs_entry_parameter {
5181: background: #BBBBFF;
5182: font-size: x-small;
5183: white-space: nowrap;
5184: }
5185:
5186: table.LC_docs_adddocs td,
5187: table.LC_docs_adddocs th {
5188: border: 1px solid #BBBBBB;
5189: padding: 4px;
5190: background: #DDDDDD;
1.543 albertel 5191: }
5192:
1.584 albertel 5193: table.LC_sty_begin {
5194: background: #BBFFBB;
5195: }
5196: table.LC_sty_end {
5197: background: #FFBBBB;
5198: }
5199:
1.589 raeburn 5200: table.LC_double_column {
5201: border-width: 0px;
5202: border-collapse: collapse;
5203: width: 100%;
5204: padding: 2px;
5205: }
5206:
5207: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 5208: top: 2px;
1.589 raeburn 5209: left: 2px;
5210: width: 47%;
5211: vertical-align: top;
5212: }
5213:
5214: table.LC_double_column tr td.LC_right_col {
5215: top: 2px;
5216: right: 2px;
5217: width: 47%;
5218: vertical-align: top;
5219: }
5220:
1.594 raeburn 5221: span.LC_role_level {
5222: font-weight: bold;
5223: }
5224:
1.591 raeburn 5225: div.LC_left_float {
5226: float: left;
5227: padding-right: 5%;
1.597 albertel 5228: padding-bottom: 4px;
1.591 raeburn 5229: }
5230:
5231: div.LC_clear_float_header {
1.597 albertel 5232: padding-bottom: 2px;
1.591 raeburn 5233: }
5234:
5235: div.LC_clear_float_footer {
1.597 albertel 5236: padding-top: 10px;
1.591 raeburn 5237: clear: both;
5238: }
5239:
1.597 albertel 5240:
1.601 albertel 5241: div.LC_grade_select_mode {
1.604 albertel 5242: font-family: $sans;
1.601 albertel 5243: }
5244: div.LC_grade_select_mode div div {
5245: margin: 5px;
5246: }
5247: div.LC_grade_select_mode_selector {
5248: margin: 5px;
5249: float: left;
5250: }
5251: div.LC_grade_select_mode_selector_header {
5252: font: bold medium $sans;
5253: }
5254: div.LC_grade_select_mode_type {
5255: clear: left;
5256: }
5257:
1.597 albertel 5258: div.LC_grade_show_user {
5259: margin-top: 20px;
5260: border: 1px solid black;
5261: }
5262: div.LC_grade_user_name {
5263: background: #DDDDEE;
5264: border-bottom: 1px solid black;
5265: font: bold large $sans;
5266: }
5267: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
5268: background: #DDEEDD;
5269: }
5270:
5271: div.LC_grade_show_problem,
5272: div.LC_grade_submissions,
5273: div.LC_grade_message_center,
5274: div.LC_grade_info_links,
5275: div.LC_grade_assign {
5276: margin: 5px;
5277: width: 99%;
5278: background: #FFFFFF;
5279: }
5280: div.LC_grade_show_problem_header,
5281: div.LC_grade_submissions_header,
5282: div.LC_grade_message_center_header,
5283: div.LC_grade_assign_header {
5284: font: bold large $sans;
5285: }
5286: div.LC_grade_show_problem_problem,
5287: div.LC_grade_submissions_body,
5288: div.LC_grade_message_center_body,
5289: div.LC_grade_assign_body {
5290: border: 1px solid black;
5291: width: 99%;
5292: background: #FFFFFF;
5293: }
1.598 albertel 5294: span.LC_grade_check_note {
5295: font: normal medium $sans;
5296: display: inline;
5297: position: absolute;
5298: right: 1em;
5299: }
1.597 albertel 5300:
1.613 albertel 5301: table.LC_scantron_action {
5302: width: 100%;
5303: }
5304: table.LC_scantron_action tr th {
5305: font: normal bold $sans;
5306: }
1.600 albertel 5307:
1.614 albertel 5308: div.LC_edit_problem_header,
5309: div.LC_edit_problem_footer {
1.600 albertel 5310: font: normal medium $sans;
1.602 albertel 5311: margin: 2px;
1.600 albertel 5312: }
5313: div.LC_edit_problem_header,
1.602 albertel 5314: div.LC_edit_problem_header div,
1.614 albertel 5315: div.LC_edit_problem_footer,
5316: div.LC_edit_problem_footer div,
1.602 albertel 5317: div.LC_edit_problem_editxml_header,
5318: div.LC_edit_problem_editxml_header div {
1.600 albertel 5319: margin-top: 5px;
5320: }
1.602 albertel 5321: div.LC_edit_problem_header_edit_row {
5322: background: $tabbg;
5323: padding: 3px;
5324: margin-bottom: 5px;
5325: }
1.600 albertel 5326: div.LC_edit_problem_header_title {
1.602 albertel 5327: font: larger bold $sans;
5328: background: $tabbg;
5329: padding: 3px;
5330: }
5331: table.LC_edit_problem_header_title {
5332: font: larger bold $sans;
5333: width: 100%;
5334: border-color: $pgbg;
5335: border-style: solid;
5336: border-width: $border;
5337:
1.600 albertel 5338: background: $tabbg;
1.602 albertel 5339: border-collapse: collapse;
5340: padding: 0px
5341: }
5342:
5343: div.LC_edit_problem_discards {
5344: float: left;
5345: padding-bottom: 5px;
5346: }
5347: div.LC_edit_problem_saves {
5348: float: right;
5349: padding-bottom: 5px;
1.600 albertel 5350: }
5351: hr.LC_edit_problem_divide {
1.602 albertel 5352: clear: both;
1.600 albertel 5353: color: $tabbg;
5354: background-color: $tabbg;
5355: height: 3px;
5356: border: 0px;
5357: }
1.343 albertel 5358: END
5359: }
5360:
1.306 albertel 5361: =pod
5362:
5363: =item * &headtag()
5364:
5365: Returns a uniform footer for LON-CAPA web pages.
5366:
1.307 albertel 5367: Inputs: $title - optional title for the head
5368: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 5369: $args - optional arguments
1.319 albertel 5370: force_register - if is true call registerurl so the remote is
5371: informed
1.415 albertel 5372: redirect -> array ref of
5373: 1- seconds before redirect occurs
5374: 2- url to redirect to
5375: 3- whether the side effect should occur
1.315 albertel 5376: (side effect of setting
5377: $env{'internal.head.redirect'} to the url
5378: redirected too)
1.352 albertel 5379: domain -> force to color decorate a page for a specific
5380: domain
5381: function -> force usage of a specific rolish color scheme
5382: bgcolor -> override the default page bgcolor
1.460 albertel 5383: no_auto_mt_title
5384: -> prevent &mt()ing the title arg
1.464 albertel 5385:
1.306 albertel 5386: =cut
5387:
5388: sub headtag {
1.313 albertel 5389: my ($title,$head_extra,$args) = @_;
1.306 albertel 5390:
1.363 albertel 5391: my $function = $args->{'function'} || &get_users_function();
5392: my $domain = $args->{'domain'} || &determinedomain();
5393: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 5394: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 5395: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 5396: #time(),
1.418 albertel 5397: $env{'environment.color.timestamp'},
1.363 albertel 5398: $function,$domain,$bgcolor);
5399:
1.369 www 5400: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 5401:
1.308 albertel 5402: my $result =
5403: '<head>'.
1.461 albertel 5404: &font_settings();
1.319 albertel 5405:
1.461 albertel 5406: if (!$args->{'frameset'}) {
5407: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
5408: }
1.319 albertel 5409: if ($args->{'force_register'}) {
5410: $result .= &Apache::lonmenu::registerurl(1);
5411: }
1.436 albertel 5412: if (!$args->{'no_nav_bar'}
5413: && !$args->{'only_body'}
5414: && !$args->{'frameset'}) {
5415: $result .= &help_menu_js();
5416: }
1.319 albertel 5417:
1.314 albertel 5418: if (ref($args->{'redirect'})) {
1.414 albertel 5419: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 5420: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 5421: if (!$inhibit_continue) {
5422: $env{'internal.head.redirect'} = $url;
5423: }
1.313 albertel 5424: $result.=<<ADDMETA
5425: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 5426: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 5427: ADDMETA
5428: }
1.306 albertel 5429: if (!defined($title)) {
5430: $title = 'The LearningOnline Network with CAPA';
5431: }
1.460 albertel 5432: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
5433: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 5434: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
5435: .$head_extra;
1.306 albertel 5436: return $result;
5437: }
5438:
5439: =pod
5440:
1.340 albertel 5441: =item * &font_settings()
5442:
5443: Returns neccessary <meta> to set the proper encoding
5444:
5445: Inputs: none
5446:
5447: =cut
5448:
5449: sub font_settings {
5450: my $headerstring='';
1.647 www 5451: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 5452: $headerstring.=
5453: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
5454: }
5455: return $headerstring;
5456: }
5457:
1.341 albertel 5458: =pod
5459:
5460: =item * &xml_begin()
5461:
5462: Returns the needed doctype and <html>
5463:
5464: Inputs: none
5465:
5466: =cut
5467:
5468: sub xml_begin {
5469: my $output='';
5470:
1.592 albertel 5471: if ($env{'internal.start_page'}==1) {
5472: &Apache::lonhtmlcommon::init_htmlareafields();
5473: }
1.342 albertel 5474:
1.341 albertel 5475: if ($env{'browser.mathml'}) {
5476: $output='<?xml version="1.0"?>'
5477: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
5478: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
5479:
5480: # .'<!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">] >'
5481: .'<!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">'
5482: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
5483: .'xmlns="http://www.w3.org/1999/xhtml">';
5484: } else {
5485: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
5486: }
5487: return $output;
5488: }
1.340 albertel 5489:
5490: =pod
5491:
1.306 albertel 5492: =item * &endheadtag()
5493:
5494: Returns a uniform </head> for LON-CAPA web pages.
5495:
5496: Inputs: none
5497:
5498: =cut
5499:
5500: sub endheadtag {
5501: return '</head>';
5502: }
5503:
5504: =pod
5505:
5506: =item * &head()
5507:
5508: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
5509:
1.648 raeburn 5510: Inputs:
5511:
5512: =over 4
5513:
5514: $title - optional title for the page
5515:
5516: $head_extra - optional extra HTML to put inside the <head>
5517:
5518: =back
1.405 albertel 5519:
1.306 albertel 5520: =cut
5521:
5522: sub head {
1.325 albertel 5523: my ($title,$head_extra,$args) = @_;
5524: return &headtag($title,$head_extra,$args).&endheadtag();
1.306 albertel 5525: }
5526:
5527: =pod
5528:
5529: =item * &start_page()
5530:
5531: Returns a complete <html> .. <body> section for LON-CAPA web pages.
5532:
1.648 raeburn 5533: Inputs:
5534:
5535: =over 4
5536:
5537: $title - optional title for the page
5538:
5539: $head_extra - optional extra HTML to incude inside the <head>
5540:
5541: $args - additional optional args supported are:
5542:
5543: =over 8
5544:
5545: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 5546: arg on
1.648 raeburn 5547: no_nav_bar -> is true will set &bodytag() notopbar arg on
5548: add_entries -> additional attributes to add to the <body>
5549: domain -> force to color decorate a page for a
1.317 albertel 5550: specific domain
1.648 raeburn 5551: function -> force usage of a specific rolish color
1.317 albertel 5552: scheme
1.648 raeburn 5553: redirect -> see &headtag()
5554: bgcolor -> override the default page bg color
5555: js_ready -> return a string ready for being used in
1.317 albertel 5556: a javascript writeln
1.648 raeburn 5557: html_encode -> return a string ready for being used in
1.320 albertel 5558: a html attribute
1.648 raeburn 5559: force_register -> if is true will turn on the &bodytag()
1.317 albertel 5560: $forcereg arg
1.648 raeburn 5561: body_title -> alternate text to use instead of $title
1.326 albertel 5562: in the title box that appears, this text
5563: is not auto translated like the $title is
1.648 raeburn 5564: frameset -> if true will start with a <frameset>
1.330 albertel 5565: rather than <body>
1.648 raeburn 5566: no_title -> if true the title bar won't be shown
5567: skip_phases -> hash ref of
1.338 albertel 5568: head -> skip the <html><head> generation
5569: body -> skip all <body> generation
1.648 raeburn 5570: no_inline_link -> if true and in remote mode, don't show the
1.361 albertel 5571: 'Switch To Inline Menu' link
1.648 raeburn 5572: no_auto_mt_title -> prevent &mt()ing the title arg
5573: inherit_jsmath -> when creating popup window in a page,
5574: should it have jsmath forced on by the
5575: current page
1.361 albertel 5576:
1.648 raeburn 5577: =back
1.460 albertel 5578:
1.648 raeburn 5579: =back
1.562 albertel 5580:
1.306 albertel 5581: =cut
5582:
5583: sub start_page {
1.309 albertel 5584: my ($title,$head_extra,$args) = @_;
1.318 albertel 5585: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313 albertel 5586: my %head_args;
1.352 albertel 5587: foreach my $arg ('redirect','force_register','domain','function',
1.460 albertel 5588: 'bgcolor','frameset','no_nav_bar','only_body',
5589: 'no_auto_mt_title') {
1.319 albertel 5590: if (defined($args->{$arg})) {
1.324 raeburn 5591: $head_args{$arg} = $args->{$arg};
1.319 albertel 5592: }
1.313 albertel 5593: }
1.319 albertel 5594:
1.315 albertel 5595: $env{'internal.start_page'}++;
1.338 albertel 5596: my $result;
5597: if (! exists($args->{'skip_phases'}{'head'}) ) {
5598: $result.=
1.341 albertel 5599: &xml_begin().
1.338 albertel 5600: &headtag($title,$head_extra,\%head_args).&endheadtag();
5601: }
5602:
5603: if (! exists($args->{'skip_phases'}{'body'}) ) {
5604: if ($args->{'frameset'}) {
5605: my $attr_string = &make_attr_string($args->{'force_register'},
5606: $args->{'add_entries'});
5607: $result .= "\n<frameset $attr_string>\n";
5608: } else {
5609: $result .=
5610: &bodytag($title,
5611: $args->{'function'}, $args->{'add_entries'},
5612: $args->{'only_body'}, $args->{'domain'},
5613: $args->{'force_register'}, $args->{'body_title'},
5614: $args->{'no_nav_bar'}, $args->{'bgcolor'},
1.460 albertel 5615: $args->{'no_title'}, $args->{'no_inline_link'},
5616: $args);
1.338 albertel 5617: }
1.330 albertel 5618: }
1.338 albertel 5619:
1.315 albertel 5620: if ($args->{'js_ready'}) {
1.317 albertel 5621: $result = &js_ready($result);
1.315 albertel 5622: }
1.320 albertel 5623: if ($args->{'html_encode'}) {
5624: $result = &html_encode($result);
5625: }
1.315 albertel 5626: return $result;
1.306 albertel 5627: }
5628:
1.330 albertel 5629:
1.306 albertel 5630: =pod
5631:
5632: =item * &head()
5633:
5634: Returns a complete </body></html> section for LON-CAPA web pages.
5635:
1.315 albertel 5636: Inputs: $args - additional optional args supported are:
5637: js_ready -> return a string ready for being used in
5638: a javascript writeln
1.320 albertel 5639: html_encode -> return a string ready for being used in
5640: a html attribute
1.330 albertel 5641: frameset -> if true will start with a <frameset>
5642: rather than <body>
1.493 albertel 5643: dicsussion -> if true will get discussion from
5644: lonxml::xmlend
5645: (you can pass the target and parser arguments
5646: through optional 'target' and 'parser' args
5647: to this routine)
1.306 albertel 5648:
5649: =cut
5650:
5651: sub end_page {
1.315 albertel 5652: my ($args) = @_;
5653: $env{'internal.end_page'}++;
1.330 albertel 5654: my $result;
1.335 albertel 5655: if ($args->{'discussion'}) {
5656: my ($target,$parser);
5657: if (ref($args->{'discussion'})) {
5658: ($target,$parser) =($args->{'discussion'}{'target'},
5659: $args->{'discussion'}{'parser'});
5660: }
5661: $result .= &Apache::lonxml::xmlend($target,$parser);
5662: }
5663:
1.330 albertel 5664: if ($args->{'frameset'}) {
5665: $result .= '</frameset>';
5666: } else {
1.635 raeburn 5667: $result .= &endbodytag($args);
1.330 albertel 5668: }
5669: $result .= "\n</html>";
5670:
1.315 albertel 5671: if ($args->{'js_ready'}) {
1.317 albertel 5672: $result = &js_ready($result);
1.315 albertel 5673: }
1.335 albertel 5674:
1.320 albertel 5675: if ($args->{'html_encode'}) {
5676: $result = &html_encode($result);
5677: }
1.335 albertel 5678:
1.315 albertel 5679: return $result;
5680: }
5681:
1.320 albertel 5682: sub html_encode {
5683: my ($result) = @_;
5684:
1.322 albertel 5685: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 5686:
5687: return $result;
5688: }
1.317 albertel 5689: sub js_ready {
5690: my ($result) = @_;
5691:
1.323 albertel 5692: $result =~ s/[\n\r]/ /xmsg;
5693: $result =~ s/\\/\\\\/xmsg;
5694: $result =~ s/'/\\'/xmsg;
1.372 albertel 5695: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 5696:
5697: return $result;
5698: }
5699:
1.315 albertel 5700: sub validate_page {
5701: if ( exists($env{'internal.start_page'})
1.316 albertel 5702: && $env{'internal.start_page'} > 1) {
5703: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 5704: $env{'internal.start_page'}.' '.
1.316 albertel 5705: $ENV{'request.filename'});
1.315 albertel 5706: }
5707: if ( exists($env{'internal.end_page'})
1.316 albertel 5708: && $env{'internal.end_page'} > 1) {
5709: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 5710: $env{'internal.end_page'}.' '.
1.316 albertel 5711: $env{'request.filename'});
1.315 albertel 5712: }
5713: if ( exists($env{'internal.start_page'})
5714: && ! exists($env{'internal.end_page'})) {
1.316 albertel 5715: &Apache::lonnet::logthis('start_page called without end_page '.
5716: $env{'request.filename'});
1.315 albertel 5717: }
5718: if ( ! exists($env{'internal.start_page'})
5719: && exists($env{'internal.end_page'})) {
1.316 albertel 5720: &Apache::lonnet::logthis('end_page called without start_page'.
5721: $env{'request.filename'});
1.315 albertel 5722: }
1.306 albertel 5723: }
1.315 albertel 5724:
1.318 albertel 5725: sub simple_error_page {
5726: my ($r,$title,$msg) = @_;
5727: my $page =
5728: &Apache::loncommon::start_page($title).
5729: &mt($msg).
5730: &Apache::loncommon::end_page();
5731: if (ref($r)) {
5732: $r->print($page);
1.327 albertel 5733: return;
1.318 albertel 5734: }
5735: return $page;
5736: }
1.347 albertel 5737:
5738: {
1.610 albertel 5739: my @row_count;
1.347 albertel 5740: sub start_data_table {
1.422 albertel 5741: my ($add_class) = @_;
5742: my $css_class = (join(' ','LC_data_table',$add_class));
1.610 albertel 5743: unshift(@row_count,0);
1.422 albertel 5744: return '<table class="'.$css_class.'">'."\n";
1.347 albertel 5745: }
5746:
5747: sub end_data_table {
1.610 albertel 5748: shift(@row_count);
1.389 albertel 5749: return '</table>'."\n";;
1.347 albertel 5750: }
5751:
5752: sub start_data_table_row {
1.422 albertel 5753: my ($add_class) = @_;
1.610 albertel 5754: $row_count[0]++;
5755: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428 albertel 5756: $css_class = (join(' ',$css_class,$add_class));
1.422 albertel 5757: return '<tr class="'.$css_class.'">'."\n";;
1.347 albertel 5758: }
1.471 banghart 5759:
5760: sub continue_data_table_row {
5761: my ($add_class) = @_;
1.610 albertel 5762: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471 banghart 5763: $css_class = (join(' ',$css_class,$add_class));
5764: return '<tr class="'.$css_class.'">'."\n";;
5765: }
1.347 albertel 5766:
5767: sub end_data_table_row {
1.389 albertel 5768: return '</tr>'."\n";;
1.347 albertel 5769: }
1.367 www 5770:
1.421 albertel 5771: sub start_data_table_empty_row {
1.610 albertel 5772: $row_count[0]++;
1.421 albertel 5773: return '<tr class="LC_empty_row" >'."\n";;
5774: }
5775:
5776: sub end_data_table_empty_row {
5777: return '</tr>'."\n";;
5778: }
5779:
1.367 www 5780: sub start_data_table_header_row {
1.389 albertel 5781: return '<tr class="LC_header_row">'."\n";;
1.367 www 5782: }
5783:
5784: sub end_data_table_header_row {
1.389 albertel 5785: return '</tr>'."\n";;
1.367 www 5786: }
1.347 albertel 5787: }
5788:
1.548 albertel 5789: =pod
5790:
5791: =item * &inhibit_menu_check($arg)
5792:
5793: Checks for a inhibitmenu state and generates output to preserve it
5794:
5795: Inputs: $arg - can be any of
5796: - undef - in which case the return value is a string
5797: to add into arguments list of a uri
5798: - 'input' - in which case the return value is a HTML
5799: <form> <input> field of type hidden to
5800: preserve the value
5801: - a url - in which case the return value is the url with
5802: the neccesary cgi args added to preserve the
5803: inhibitmenu state
5804: - a ref to a url - no return value, but the string is
5805: updated to include the neccessary cgi
5806: args to preserve the inhibitmenu state
5807:
5808: =cut
5809:
5810: sub inhibit_menu_check {
5811: my ($arg) = @_;
5812: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5813: if ($arg eq 'input') {
5814: if ($env{'form.inhibitmenu'}) {
5815: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
5816: } else {
5817: return
5818: }
5819: }
5820: if ($env{'form.inhibitmenu'}) {
5821: if (ref($arg)) {
5822: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5823: } elsif ($arg eq '') {
5824: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
5825: } else {
5826: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
5827: }
5828: }
5829: if (!ref($arg)) {
5830: return $arg;
5831: }
5832: }
5833:
1.251 albertel 5834: ###############################################
1.182 matthew 5835:
5836: =pod
5837:
1.549 albertel 5838: =back
5839:
5840: =head1 User Information Routines
5841:
5842: =over 4
5843:
1.405 albertel 5844: =item * &get_users_function()
1.182 matthew 5845:
5846: Used by &bodytag to determine the current users primary role.
5847: Returns either 'student','coordinator','admin', or 'author'.
5848:
5849: =cut
5850:
5851: ###############################################
5852: sub get_users_function {
5853: my $function = 'student';
1.258 albertel 5854: if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182 matthew 5855: $function='coordinator';
5856: }
1.258 albertel 5857: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 5858: $function='admin';
5859: }
1.258 albertel 5860: if (($env{'request.role'}=~/^(au|ca)/) ||
1.182 matthew 5861: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
5862: $function='author';
5863: }
5864: return $function;
1.54 www 5865: }
1.99 www 5866:
5867: ###############################################
5868:
1.233 raeburn 5869: =pod
5870:
1.542 raeburn 5871: =item * &check_user_status()
1.274 raeburn 5872:
5873: Determines current status of supplied role for a
5874: specific user. Roles can be active, previous or future.
5875:
5876: Inputs:
5877: user's domain, user's username, course's domain,
1.375 raeburn 5878: course's number, optional section ID.
1.274 raeburn 5879:
5880: Outputs:
5881: role status: active, previous or future.
5882:
5883: =cut
5884:
5885: sub check_user_status {
1.412 raeburn 5886: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274 raeburn 5887: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
5888: my @uroles = keys %userinfo;
5889: my $srchstr;
5890: my $active_chk = 'none';
1.412 raeburn 5891: my $now = time;
1.274 raeburn 5892: if (@uroles > 0) {
1.412 raeburn 5893: if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 5894: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
5895: } else {
1.412 raeburn 5896: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
5897: }
5898: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 5899: my $role_end = 0;
5900: my $role_start = 0;
5901: $active_chk = 'active';
1.412 raeburn 5902: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
5903: $role_end = $1;
5904: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
5905: $role_start = $1;
1.274 raeburn 5906: }
5907: }
5908: if ($role_start > 0) {
1.412 raeburn 5909: if ($now < $role_start) {
1.274 raeburn 5910: $active_chk = 'future';
5911: }
5912: }
5913: if ($role_end > 0) {
1.412 raeburn 5914: if ($now > $role_end) {
1.274 raeburn 5915: $active_chk = 'previous';
5916: }
5917: }
5918: }
5919: }
5920: return $active_chk;
5921: }
5922:
5923: ###############################################
5924:
5925: =pod
5926:
1.405 albertel 5927: =item * &get_sections()
1.233 raeburn 5928:
5929: Determines all the sections for a course including
5930: sections with students and sections containing other roles.
1.419 raeburn 5931: Incoming parameters:
5932:
5933: 1. domain
5934: 2. course number
5935: 3. reference to array containing roles for which sections should
5936: be gathered (optional).
5937: 4. reference to array containing status types for which sections
5938: should be gathered (optional).
5939:
5940: If the third argument is undefined, sections are gathered for any role.
5941: If the fourth argument is undefined, sections are gathered for any status.
5942: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 5943:
1.374 raeburn 5944: Returns section hash (keys are section IDs, values are
5945: number of users in each section), subject to the
1.419 raeburn 5946: optional roles filter, optional status filter
1.233 raeburn 5947:
5948: =cut
5949:
5950: ###############################################
5951: sub get_sections {
1.419 raeburn 5952: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 5953: if (!defined($cdom) || !defined($cnum)) {
5954: my $cid = $env{'request.course.id'};
5955:
5956: return if (!defined($cid));
5957:
5958: $cdom = $env{'course.'.$cid.'.domain'};
5959: $cnum = $env{'course.'.$cid.'.num'};
5960: }
5961:
5962: my %sectioncount;
1.419 raeburn 5963: my $now = time;
1.240 albertel 5964:
1.366 albertel 5965: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 5966: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 5967: my $sec_index = &Apache::loncoursedata::CL_SECTION();
5968: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 5969: my $start_index = &Apache::loncoursedata::CL_START();
5970: my $end_index = &Apache::loncoursedata::CL_END();
5971: my $status;
1.366 albertel 5972: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 5973: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
5974: $data->[$status_index],
5975: $data->[$start_index],
5976: $data->[$end_index]);
5977: if ($stu_status eq 'Active') {
5978: $status = 'active';
5979: } elsif ($end < $now) {
5980: $status = 'previous';
5981: } elsif ($start > $now) {
5982: $status = 'future';
5983: }
5984: if ($section ne '-1' && $section !~ /^\s*$/) {
5985: if ((!defined($possible_status)) || (($status ne '') &&
5986: (grep/^\Q$status\E$/,@{$possible_status}))) {
5987: $sectioncount{$section}++;
5988: }
1.240 albertel 5989: }
5990: }
5991: }
5992: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
5993: foreach my $user (sort(keys(%courseroles))) {
5994: if ($user !~ /^(\w{2})/) { next; }
5995: my ($role) = ($user =~ /^(\w{2})/);
5996: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 5997: my ($section,$status);
1.240 albertel 5998: if ($role eq 'cr' &&
5999: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
6000: $section=$1;
6001: }
6002: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
6003: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 6004: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
6005: if ($end == -1 && $start == -1) {
6006: next; #deleted role
6007: }
6008: if (!defined($possible_status)) {
6009: $sectioncount{$section}++;
6010: } else {
6011: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
6012: $status = 'active';
6013: } elsif ($end < $now) {
6014: $status = 'future';
6015: } elsif ($start > $now) {
6016: $status = 'previous';
6017: }
6018: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
6019: $sectioncount{$section}++;
6020: }
6021: }
1.233 raeburn 6022: }
1.366 albertel 6023: return %sectioncount;
1.233 raeburn 6024: }
6025:
1.274 raeburn 6026: ###############################################
1.294 raeburn 6027:
6028: =pod
1.405 albertel 6029:
6030: =item * &get_course_users()
6031:
1.275 raeburn 6032: Retrieves usernames:domains for users in the specified course
6033: with specific role(s), and access status.
6034:
6035: Incoming parameters:
1.277 albertel 6036: 1. course domain
6037: 2. course number
6038: 3. access status: users must have - either active,
1.275 raeburn 6039: previous, future, or all.
1.277 albertel 6040: 4. reference to array of permissible roles
1.288 raeburn 6041: 5. reference to array of section restrictions (optional)
6042: 6. reference to results object (hash of hashes).
6043: 7. reference to optional userdata hash
1.609 raeburn 6044: 8. reference to optional statushash
1.630 raeburn 6045: 9. flag if privileged users (except those set to unhide in
6046: course settings) should be excluded
1.609 raeburn 6047: Keys of top level results hash are roles.
1.275 raeburn 6048: Keys of inner hashes are username:domain, with
6049: values set to access type.
1.288 raeburn 6050: Optional userdata hash returns an array with arguments in the
6051: same order as loncoursedata::get_classlist() for student data.
6052:
1.609 raeburn 6053: Optional statushash returns
6054:
1.288 raeburn 6055: Entries for end, start, section and status are blank because
6056: of the possibility of multiple values for non-student roles.
6057:
1.275 raeburn 6058: =cut
1.405 albertel 6059:
1.275 raeburn 6060: ###############################################
1.405 albertel 6061:
1.275 raeburn 6062: sub get_course_users {
1.630 raeburn 6063: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 6064: my %idx = ();
1.419 raeburn 6065: my %seclists;
1.288 raeburn 6066:
6067: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
6068: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
6069: $idx{end} = &Apache::loncoursedata::CL_END();
6070: $idx{start} = &Apache::loncoursedata::CL_START();
6071: $idx{id} = &Apache::loncoursedata::CL_ID();
6072: $idx{section} = &Apache::loncoursedata::CL_SECTION();
6073: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
6074: $idx{status} = &Apache::loncoursedata::CL_STATUS();
6075:
1.290 albertel 6076: if (grep(/^st$/,@{$roles})) {
1.276 albertel 6077: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 6078: my $now = time;
1.277 albertel 6079: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 6080: my $match = 0;
1.412 raeburn 6081: my $secmatch = 0;
1.419 raeburn 6082: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 6083: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 6084: if ($section eq '') {
6085: $section = 'none';
6086: }
1.291 albertel 6087: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6088: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6089: $secmatch = 1;
6090: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 6091: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6092: $secmatch = 1;
6093: }
6094: } else {
1.419 raeburn 6095: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 6096: $secmatch = 1;
6097: }
1.290 albertel 6098: }
1.412 raeburn 6099: if (!$secmatch) {
6100: next;
6101: }
1.419 raeburn 6102: }
1.275 raeburn 6103: if (defined($$types{'active'})) {
1.288 raeburn 6104: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 6105: push(@{$$users{st}{$student}},'active');
1.288 raeburn 6106: $match = 1;
1.275 raeburn 6107: }
6108: }
6109: if (defined($$types{'previous'})) {
1.609 raeburn 6110: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 6111: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 6112: $match = 1;
1.275 raeburn 6113: }
6114: }
6115: if (defined($$types{'future'})) {
1.609 raeburn 6116: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 6117: push(@{$$users{st}{$student}},'future');
1.288 raeburn 6118: $match = 1;
1.275 raeburn 6119: }
6120: }
1.609 raeburn 6121: if ($match) {
6122: push(@{$seclists{$student}},$section);
6123: if (ref($userdata) eq 'HASH') {
6124: $$userdata{$student} = $$classlist{$student};
6125: }
6126: if (ref($statushash) eq 'HASH') {
6127: $statushash->{$student}{'st'}{$section} = $status;
6128: }
1.288 raeburn 6129: }
1.275 raeburn 6130: }
6131: }
1.412 raeburn 6132: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 6133: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6134: my $now = time;
1.609 raeburn 6135: my %displaystatus = ( previous => 'Expired',
6136: active => 'Active',
6137: future => 'Future',
6138: );
1.630 raeburn 6139: my %nothide;
6140: if ($hidepriv) {
6141: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
6142: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
6143: if ($user !~ /:/) {
6144: $nothide{join(':',split(/[\@]/,$user))}=1;
6145: } else {
6146: $nothide{$user} = 1;
6147: }
6148: }
6149: }
1.439 raeburn 6150: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 6151: my $match = 0;
1.412 raeburn 6152: my $secmatch = 0;
1.439 raeburn 6153: my $status;
1.412 raeburn 6154: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 6155: $user =~ s/:$//;
1.439 raeburn 6156: my ($end,$start) = split(/:/,$coursepersonnel{$person});
6157: if ($end == -1 || $start == -1) {
6158: next;
6159: }
6160: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
6161: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 6162: my ($uname,$udom) = split(/:/,$user);
6163: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 6164: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 6165: $secmatch = 1;
6166: } elsif ($usec eq '') {
1.420 albertel 6167: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 6168: $secmatch = 1;
6169: }
6170: } else {
6171: if (grep(/^\Q$usec\E$/,@{$sections})) {
6172: $secmatch = 1;
6173: }
6174: }
6175: if (!$secmatch) {
6176: next;
6177: }
1.288 raeburn 6178: }
1.419 raeburn 6179: if ($usec eq '') {
6180: $usec = 'none';
6181: }
1.275 raeburn 6182: if ($uname ne '' && $udom ne '') {
1.630 raeburn 6183: if ($hidepriv) {
6184: if ((&Apache::lonnet::privileged($uname,$udom)) &&
6185: (!$nothide{$uname.':'.$udom})) {
6186: next;
6187: }
6188: }
1.503 raeburn 6189: if ($end > 0 && $end < $now) {
1.439 raeburn 6190: $status = 'previous';
6191: } elsif ($start > $now) {
6192: $status = 'future';
6193: } else {
6194: $status = 'active';
6195: }
1.277 albertel 6196: foreach my $type (keys(%{$types})) {
1.275 raeburn 6197: if ($status eq $type) {
1.420 albertel 6198: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 6199: push(@{$$users{$role}{$user}},$type);
6200: }
1.288 raeburn 6201: $match = 1;
6202: }
6203: }
1.419 raeburn 6204: if (($match) && (ref($userdata) eq 'HASH')) {
6205: if (!exists($$userdata{$uname.':'.$udom})) {
6206: &get_user_info($udom,$uname,\%idx,$userdata);
6207: }
1.420 albertel 6208: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 6209: push(@{$seclists{$uname.':'.$udom}},$usec);
6210: }
1.609 raeburn 6211: if (ref($statushash) eq 'HASH') {
6212: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
6213: }
1.275 raeburn 6214: }
6215: }
6216: }
6217: }
1.290 albertel 6218: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 6219: if ((defined($cdom)) && (defined($cnum))) {
6220: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
6221: if ( defined($csettings{'internal.courseowner'}) ) {
6222: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 6223: next if ($owner eq '');
6224: my ($ownername,$ownerdom);
6225: if ($owner =~ /^([^:]+):([^:]+)$/) {
6226: $ownername = $1;
6227: $ownerdom = $2;
6228: } else {
6229: $ownername = $owner;
6230: $ownerdom = $cdom;
6231: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 6232: }
6233: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 6234: if (defined($userdata) &&
1.609 raeburn 6235: !exists($$userdata{$owner})) {
6236: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
6237: if (!grep(/^none$/,@{$seclists{$owner}})) {
6238: push(@{$seclists{$owner}},'none');
6239: }
6240: if (ref($statushash) eq 'HASH') {
6241: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 6242: }
1.290 albertel 6243: }
1.279 raeburn 6244: }
6245: }
6246: }
1.419 raeburn 6247: foreach my $user (keys(%seclists)) {
6248: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
6249: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
6250: }
1.275 raeburn 6251: }
6252: return;
6253: }
6254:
1.288 raeburn 6255: sub get_user_info {
6256: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 6257: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
6258: &plainname($uname,$udom,'lastname');
1.291 albertel 6259: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 6260: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 6261: my %idhash = &Apache::lonnet::idrget($udom,($uname));
6262: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 6263: return;
6264: }
1.275 raeburn 6265:
1.472 raeburn 6266: ###############################################
6267:
6268: =pod
6269:
6270: =item * &get_user_quota()
6271:
6272: Retrieves quota assigned for storage of portfolio files for a user
6273:
6274: Incoming parameters:
6275: 1. user's username
6276: 2. user's domain
6277:
6278: Returns:
1.536 raeburn 6279: 1. Disk quota (in Mb) assigned to student.
6280: 2. (Optional) Type of setting: custom or default
6281: (individually assigned or default for user's
6282: institutional status).
6283: 3. (Optional) - User's institutional status (e.g., faculty, staff
6284: or student - types as defined in localenroll::inst_usertypes
6285: for user's domain, which determines default quota for user.
6286: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 6287:
6288: If a value has been stored in the user's environment,
1.536 raeburn 6289: it will return that, otherwise it returns the maximal default
6290: defined for the user's instituional status(es) in the domain.
1.472 raeburn 6291:
6292: =cut
6293:
6294: ###############################################
6295:
6296:
6297: sub get_user_quota {
6298: my ($uname,$udom) = @_;
1.536 raeburn 6299: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 6300: if (!defined($udom)) {
6301: $udom = $env{'user.domain'};
6302: }
6303: if (!defined($uname)) {
6304: $uname = $env{'user.name'};
6305: }
6306: if (($udom eq '' || $uname eq '') ||
6307: ($udom eq 'public') && ($uname eq 'public')) {
6308: $quota = 0;
1.536 raeburn 6309: $quotatype = 'default';
6310: $defquota = 0;
1.472 raeburn 6311: } else {
1.536 raeburn 6312: my $inststatus;
1.472 raeburn 6313: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
6314: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 6315: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 6316: } else {
1.536 raeburn 6317: my %userenv =
6318: &Apache::lonnet::get('environment',['portfolioquota',
6319: 'inststatus'],$udom,$uname);
1.472 raeburn 6320: my ($tmp) = keys(%userenv);
6321: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
6322: $quota = $userenv{'portfolioquota'};
1.536 raeburn 6323: $inststatus = $userenv{'inststatus'};
1.472 raeburn 6324: } else {
6325: undef(%userenv);
6326: }
6327: }
1.536 raeburn 6328: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 6329: if ($quota eq '') {
1.536 raeburn 6330: $quota = $defquota;
6331: $quotatype = 'default';
6332: } else {
6333: $quotatype = 'custom';
1.472 raeburn 6334: }
6335: }
1.536 raeburn 6336: if (wantarray) {
6337: return ($quota,$quotatype,$settingstatus,$defquota);
6338: } else {
6339: return $quota;
6340: }
1.472 raeburn 6341: }
6342:
6343: ###############################################
6344:
6345: =pod
6346:
6347: =item * &default_quota()
6348:
1.536 raeburn 6349: Retrieves default quota assigned for storage of user portfolio files,
6350: given an (optional) user's institutional status.
1.472 raeburn 6351:
6352: Incoming parameters:
6353: 1. domain
1.536 raeburn 6354: 2. (Optional) institutional status(es). This is a : separated list of
6355: status types (e.g., faculty, staff, student etc.)
6356: which apply to the user for whom the default is being retrieved.
6357: If the institutional status string in undefined, the domain
6358: default quota will be returned.
1.472 raeburn 6359:
6360: Returns:
6361: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 6362: 2. (Optional) institutional type which determined the value of the
6363: default quota.
1.472 raeburn 6364:
6365: If a value has been stored in the domain's configuration db,
6366: it will return that, otherwise it returns 20 (for backwards
6367: compatibility with domains which have not set up a configuration
6368: db file; the original statically defined portfolio quota was 20 Mb).
6369:
1.536 raeburn 6370: If the user's status includes multiple types (e.g., staff and student),
6371: the largest default quota which applies to the user determines the
6372: default quota returned.
6373:
1.472 raeburn 6374: =cut
6375:
6376: ###############################################
6377:
6378:
6379: sub default_quota {
1.536 raeburn 6380: my ($udom,$inststatus) = @_;
6381: my ($defquota,$settingstatus);
6382: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 6383: ['quotas'],$udom);
6384: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 6385: if ($inststatus ne '') {
6386: my @statuses = split(/:/,$inststatus);
6387: foreach my $item (@statuses) {
1.622 raeburn 6388: if ($quotahash{'quotas'}{$item} ne '') {
1.536 raeburn 6389: if ($defquota eq '') {
1.622 raeburn 6390: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6391: $settingstatus = $item;
1.622 raeburn 6392: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
6393: $defquota = $quotahash{'quotas'}{$item};
1.536 raeburn 6394: $settingstatus = $item;
6395: }
6396: }
6397: }
6398: }
6399: if ($defquota eq '') {
1.622 raeburn 6400: $defquota = $quotahash{'quotas'}{'default'};
1.536 raeburn 6401: $settingstatus = 'default';
6402: }
6403: } else {
6404: $settingstatus = 'default';
6405: $defquota = 20;
6406: }
6407: if (wantarray) {
6408: return ($defquota,$settingstatus);
1.472 raeburn 6409: } else {
1.536 raeburn 6410: return $defquota;
1.472 raeburn 6411: }
6412: }
6413:
1.384 raeburn 6414: sub get_secgrprole_info {
6415: my ($cdom,$cnum,$needroles,$type) = @_;
6416: my %sections_count = &get_sections($cdom,$cnum);
6417: my @sections = (sort {$a <=> $b} keys(%sections_count));
6418: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
6419: my @groups = sort(keys(%curr_groups));
6420: my $allroles = [];
6421: my $rolehash;
6422: my $accesshash = {
6423: active => 'Currently has access',
6424: future => 'Will have future access',
6425: previous => 'Previously had access',
6426: };
6427: if ($needroles) {
6428: $rolehash = {'all' => 'all'};
1.385 albertel 6429: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
6430: if (&Apache::lonnet::error(%user_roles)) {
6431: undef(%user_roles);
6432: }
6433: foreach my $item (keys(%user_roles)) {
1.384 raeburn 6434: my ($role)=split(/\:/,$item,2);
6435: if ($role eq 'cr') { next; }
6436: if ($role =~ /^cr/) {
6437: $$rolehash{$role} = (split('/',$role))[3];
6438: } else {
6439: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
6440: }
6441: }
6442: foreach my $key (sort(keys(%{$rolehash}))) {
6443: push(@{$allroles},$key);
6444: }
6445: push (@{$allroles},'st');
6446: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
6447: }
6448: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
6449: }
6450:
1.555 raeburn 6451: sub user_picker {
1.627 raeburn 6452: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555 raeburn 6453: my $currdom = $dom;
6454: my %curr_selected = (
6455: srchin => 'dom',
1.580 raeburn 6456: srchby => 'lastname',
1.555 raeburn 6457: );
6458: my $srchterm;
1.625 raeburn 6459: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 6460: if ($srch->{'srchby'} ne '') {
6461: $curr_selected{'srchby'} = $srch->{'srchby'};
6462: }
6463: if ($srch->{'srchin'} ne '') {
6464: $curr_selected{'srchin'} = $srch->{'srchin'};
6465: }
6466: if ($srch->{'srchtype'} ne '') {
6467: $curr_selected{'srchtype'} = $srch->{'srchtype'};
6468: }
6469: if ($srch->{'srchdomain'} ne '') {
6470: $currdom = $srch->{'srchdomain'};
6471: }
6472: $srchterm = $srch->{'srchterm'};
6473: }
6474: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 6475: 'usr' => 'Search criteria',
1.563 raeburn 6476: 'doma' => 'Domain/institution to search',
1.558 albertel 6477: 'uname' => 'username',
6478: 'lastname' => 'last name',
1.555 raeburn 6479: 'lastfirst' => 'last name, first name',
1.558 albertel 6480: 'crs' => 'in this course',
1.576 raeburn 6481: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 6482: 'alc' => 'all LON-CAPA',
1.573 raeburn 6483: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 6484: 'exact' => 'is',
6485: 'contains' => 'contains',
1.569 raeburn 6486: 'begins' => 'begins with',
1.571 raeburn 6487: 'youm' => "You must include some text to search for.",
6488: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
6489: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
6490: 'yomc' => "You must choose a domain when using an institutional directory search.",
6491: 'ymcd' => "You must choose a domain when using a domain search.",
6492: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
6493: 'whse' => "When searching by last,first you must include at least one character in the first name.",
6494: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 6495: );
1.563 raeburn 6496: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
6497: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 6498:
6499: my @srchins = ('crs','dom','alc','instd');
6500:
6501: foreach my $option (@srchins) {
6502: # FIXME 'alc' option unavailable until
6503: # loncreateuser::print_user_query_page()
6504: # has been completed.
6505: next if ($option eq 'alc');
6506: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 6507: if ($curr_selected{'srchin'} eq $option) {
6508: $srchinsel .= '
6509: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6510: } else {
6511: $srchinsel .= '
6512: <option value="'.$option.'">'.$lt{$option}.'</option>';
6513: }
1.555 raeburn 6514: }
1.563 raeburn 6515: $srchinsel .= "\n </select>\n";
1.555 raeburn 6516:
6517: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 6518: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 6519: if ($curr_selected{'srchby'} eq $option) {
6520: $srchbysel .= '
6521: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6522: } else {
6523: $srchbysel .= '
6524: <option value="'.$option.'">'.$lt{$option}.'</option>';
6525: }
6526: }
6527: $srchbysel .= "\n </select>\n";
6528:
6529: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 6530: foreach my $option ('begins','contains','exact') {
1.555 raeburn 6531: if ($curr_selected{'srchtype'} eq $option) {
6532: $srchtypesel .= '
6533: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
6534: } else {
6535: $srchtypesel .= '
6536: <option value="'.$option.'">'.$lt{$option}.'</option>';
6537: }
6538: }
6539: $srchtypesel .= "\n </select>\n";
6540:
1.558 albertel 6541: my ($newuserscript,$new_user_create);
1.556 raeburn 6542:
6543: if ($forcenewuser) {
1.576 raeburn 6544: if (ref($srch) eq 'HASH') {
6545: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627 raeburn 6546: if ($cancreate) {
6547: $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>';
6548: } else {
6549: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
6550: my %usertypetext = (
6551: official => 'institutional',
6552: unofficial => 'non-institutional',
6553: );
6554: $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
6555: }
1.576 raeburn 6556: }
6557: }
6558:
1.556 raeburn 6559: $newuserscript = <<"ENDSCRIPT";
6560:
1.570 raeburn 6561: function setSearch(createnew,callingForm) {
1.556 raeburn 6562: if (createnew == 1) {
1.570 raeburn 6563: for (var i=0; i<callingForm.srchby.length; i++) {
6564: if (callingForm.srchby.options[i].value == 'uname') {
6565: callingForm.srchby.selectedIndex = i;
1.556 raeburn 6566: }
6567: }
1.570 raeburn 6568: for (var i=0; i<callingForm.srchin.length; i++) {
6569: if ( callingForm.srchin.options[i].value == 'dom') {
6570: callingForm.srchin.selectedIndex = i;
1.556 raeburn 6571: }
6572: }
1.570 raeburn 6573: for (var i=0; i<callingForm.srchtype.length; i++) {
6574: if (callingForm.srchtype.options[i].value == 'exact') {
6575: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 6576: }
6577: }
1.570 raeburn 6578: for (var i=0; i<callingForm.srchdomain.length; i++) {
6579: if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
6580: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 6581: }
6582: }
6583: }
6584: }
6585: ENDSCRIPT
1.558 albertel 6586:
1.556 raeburn 6587: }
6588:
1.555 raeburn 6589: my $output = <<"END_BLOCK";
1.556 raeburn 6590: <script type="text/javascript">
1.570 raeburn 6591: function validateEntry(callingForm) {
1.558 albertel 6592:
1.556 raeburn 6593: var checkok = 1;
1.558 albertel 6594: var srchin;
1.570 raeburn 6595: for (var i=0; i<callingForm.srchin.length; i++) {
6596: if ( callingForm.srchin[i].checked ) {
6597: srchin = callingForm.srchin[i].value;
1.558 albertel 6598: }
6599: }
6600:
1.570 raeburn 6601: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
6602: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
6603: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
6604: var srchterm = callingForm.srchterm.value;
6605: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 6606: var msg = "";
6607:
6608: if (srchterm == "") {
6609: checkok = 0;
1.571 raeburn 6610: msg += "$lt{'youm'}\\n";
1.556 raeburn 6611: }
6612:
1.569 raeburn 6613: if (srchtype== 'begins') {
6614: if (srchterm.length < 2) {
6615: checkok = 0;
1.571 raeburn 6616: msg += "$lt{'thte'}\\n";
1.569 raeburn 6617: }
6618: }
6619:
1.556 raeburn 6620: if (srchtype== 'contains') {
6621: if (srchterm.length < 3) {
6622: checkok = 0;
1.571 raeburn 6623: msg += "$lt{'thet'}\\n";
1.556 raeburn 6624: }
6625: }
6626: if (srchin == 'instd') {
6627: if (srchdomain == '') {
6628: checkok = 0;
1.571 raeburn 6629: msg += "$lt{'yomc'}\\n";
1.556 raeburn 6630: }
6631: }
6632: if (srchin == 'dom') {
6633: if (srchdomain == '') {
6634: checkok = 0;
1.571 raeburn 6635: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 6636: }
6637: }
6638: if (srchby == 'lastfirst') {
6639: if (srchterm.indexOf(",") == -1) {
6640: checkok = 0;
1.571 raeburn 6641: msg += "$lt{'whus'}\\n";
1.556 raeburn 6642: }
6643: if (srchterm.indexOf(",") == srchterm.length -1) {
6644: checkok = 0;
1.571 raeburn 6645: msg += "$lt{'whse'}\\n";
1.556 raeburn 6646: }
6647: }
6648: if (checkok == 0) {
1.571 raeburn 6649: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 6650: return;
6651: }
6652: if (checkok == 1) {
1.570 raeburn 6653: callingForm.submit();
1.556 raeburn 6654: }
6655: }
6656:
6657: $newuserscript
6658:
6659: </script>
1.558 albertel 6660:
6661: $new_user_create
6662:
1.555 raeburn 6663: <table>
1.558 albertel 6664: <tr>
1.573 raeburn 6665: <td>$lt{'doma'}:</td>
6666: <td>$domform</td>
6667: </td>
6668: </tr>
6669: <tr>
6670: <td>$lt{'usr'}:</td>
1.563 raeburn 6671: <td>$srchbysel
6672: $srchtypesel
6673: <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564 albertel 6674: $srchinsel
1.563 raeburn 6675: </td>
6676: </tr>
1.555 raeburn 6677: </table>
6678: <br />
6679: END_BLOCK
1.558 albertel 6680:
1.555 raeburn 6681: return $output;
6682: }
6683:
1.612 raeburn 6684: sub user_rule_check {
1.615 raeburn 6685: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 6686: my $response;
6687: if (ref($usershash) eq 'HASH') {
6688: foreach my $user (keys(%{$usershash})) {
6689: my ($uname,$udom) = split(/:/,$user);
6690: next if ($udom eq '' || $uname eq '');
1.615 raeburn 6691: my ($id,$newuser);
1.612 raeburn 6692: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 6693: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 6694: $id = $usershash->{$user}->{'id'};
6695: }
6696: my $inst_response;
6697: if (ref($checks) eq 'HASH') {
6698: if (defined($checks->{'username'})) {
1.615 raeburn 6699: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6700: &Apache::lonnet::get_instuser($udom,$uname);
6701: } elsif (defined($checks->{'id'})) {
1.615 raeburn 6702: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 6703: &Apache::lonnet::get_instuser($udom,undef,$id);
6704: }
1.615 raeburn 6705: } else {
6706: ($inst_response,%{$inst_results->{$user}}) =
6707: &Apache::lonnet::get_instuser($udom,$uname);
6708: return;
1.612 raeburn 6709: }
1.615 raeburn 6710: if (!$got_rules->{$udom}) {
1.612 raeburn 6711: my %domconfig = &Apache::lonnet::get_dom('configuration',
6712: ['usercreation'],$udom);
6713: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 6714: foreach my $item ('username','id') {
1.612 raeburn 6715: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
6716: $$curr_rules{$udom}{$item} =
6717: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 6718: }
6719: }
6720: }
1.615 raeburn 6721: $got_rules->{$udom} = 1;
1.585 raeburn 6722: }
1.612 raeburn 6723: foreach my $item (keys(%{$checks})) {
6724: if (ref($$curr_rules{$udom}) eq 'HASH') {
6725: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
6726: if (@{$$curr_rules{$udom}{$item}} > 0) {
6727: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
6728: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
6729: if ($rule_check{$rule}) {
6730: $$rulematch{$user}{$item} = $rule;
6731: if ($inst_response eq 'ok') {
1.615 raeburn 6732: if (ref($inst_results) eq 'HASH') {
6733: if (ref($inst_results->{$user}) eq 'HASH') {
6734: if (keys(%{$inst_results->{$user}}) == 0) {
6735: $$alerts{$item}{$udom}{$uname} = 1;
6736: }
1.612 raeburn 6737: }
6738: }
1.615 raeburn 6739: }
6740: last;
1.585 raeburn 6741: }
6742: }
6743: }
6744: }
6745: }
6746: }
6747: }
6748: }
1.612 raeburn 6749: return;
6750: }
6751:
6752: sub user_rule_formats {
6753: my ($domain,$domdesc,$curr_rules,$check) = @_;
6754: my %text = (
6755: 'username' => 'Usernames',
6756: 'id' => 'IDs',
6757: );
6758: my $output;
6759: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
6760: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
6761: if (@{$ruleorder} > 0) {
6762: $output = '<br />'.&mt("$text{$check} with the following format(s) may <span class=\"LC_cusr_emph\">only</span> be used for verified users at [_1]:",$domdesc).' <ul>';
6763: foreach my $rule (@{$ruleorder}) {
6764: if (ref($curr_rules) eq 'ARRAY') {
6765: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
6766: if (ref($rules->{$rule}) eq 'HASH') {
6767: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
6768: $rules->{$rule}{'desc'}.'</li>';
6769: }
6770: }
6771: }
6772: }
6773: $output .= '</ul>';
6774: }
6775: }
6776: return $output;
6777: }
6778:
6779: sub instrule_disallow_msg {
1.615 raeburn 6780: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 6781: my $response;
6782: my %text = (
6783: item => 'username',
6784: items => 'usernames',
6785: match => 'matches',
6786: do => 'does',
6787: action => 'a username',
6788: one => 'one',
6789: );
6790: if ($count > 1) {
6791: $text{'item'} = 'usernames';
6792: $text{'match'} ='match';
6793: $text{'do'} = 'do';
6794: $text{'action'} = 'usernames',
6795: $text{'one'} = 'ones';
6796: }
6797: if ($checkitem eq 'id') {
6798: $text{'items'} = 'IDs';
6799: $text{'item'} = 'ID';
6800: $text{'action'} = 'an ID';
1.615 raeburn 6801: if ($count > 1) {
6802: $text{'item'} = 'IDs';
6803: $text{'action'} = 'IDs';
6804: }
1.612 raeburn 6805: }
6806: $response = &mt("The $text{'item'} you chose $text{'match'} the format of $text{'items'} defined for <span class=\"LC_cusr_emph\">[_1]</span>, but the $text{'item'} $text{'do'} not exist in the institutional directory.",$domdesc).'<br />';
1.615 raeburn 6807: if ($mode eq 'upload') {
6808: if ($checkitem eq 'username') {
6809: $response .= &mt("You will need to modify your upload file so it will include $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
6810: } elsif ($checkitem eq 'id') {
6811: $response .= &mt("Either upload a file which includes $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or when associating fields with data columns, omit an association for the ID/Student Number field.");
6812: }
1.669 raeburn 6813: } elsif ($mode eq 'selfcreate') {
6814: if ($checkitem eq 'id') {
6815: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
6816: }
1.615 raeburn 6817: } else {
6818: if ($checkitem eq 'username') {
6819: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
6820: } elsif ($checkitem eq 'id') {
6821: $response .= &mt("You must either choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}, or leave the ID field blank.");
6822: }
1.612 raeburn 6823: }
6824: return $response;
1.585 raeburn 6825: }
6826:
1.624 raeburn 6827: sub personal_data_fieldtitles {
6828: my %fieldtitles = &Apache::lonlocal::texthash (
6829: id => 'Student/Employee ID',
6830: permanentemail => 'E-mail address',
6831: lastname => 'Last Name',
6832: firstname => 'First Name',
6833: middlename => 'Middle Name',
6834: generation => 'Generation',
6835: gen => 'Generation',
6836: );
6837: return %fieldtitles;
6838: }
6839:
1.642 raeburn 6840: sub sorted_inst_types {
6841: my ($dom) = @_;
6842: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
6843: my $othertitle = &mt('All users');
6844: if ($env{'request.course.id'}) {
1.668 raeburn 6845: $othertitle = &mt('Any users');
1.642 raeburn 6846: }
6847: my @types;
6848: if (ref($order) eq 'ARRAY') {
6849: @types = @{$order};
6850: }
6851: if (@types == 0) {
6852: if (ref($usertypes) eq 'HASH') {
6853: @types = sort(keys(%{$usertypes}));
6854: }
6855: }
6856: if (keys(%{$usertypes}) > 0) {
6857: $othertitle = &mt('Other users');
6858: }
6859: return ($othertitle,$usertypes,\@types);
6860: }
6861:
1.645 raeburn 6862: sub get_institutional_codes {
6863: my ($settings,$allcourses,$LC_code) = @_;
6864: # Get complete list of course sections to update
6865: my @currsections = ();
6866: my @currxlists = ();
6867: my $coursecode = $$settings{'internal.coursecode'};
6868:
6869: if ($$settings{'internal.sectionnums'} ne '') {
6870: @currsections = split(/,/,$$settings{'internal.sectionnums'});
6871: }
6872:
6873: if ($$settings{'internal.crosslistings'} ne '') {
6874: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
6875: }
6876:
6877: if (@currxlists > 0) {
6878: foreach (@currxlists) {
6879: if (m/^([^:]+):(\w*)$/) {
6880: unless (grep/^$1$/,@{$allcourses}) {
6881: push @{$allcourses},$1;
6882: $$LC_code{$1} = $2;
6883: }
6884: }
6885: }
6886: }
6887:
6888: if (@currsections > 0) {
6889: foreach (@currsections) {
6890: if (m/^(\w+):(\w*)$/) {
6891: my $sec = $coursecode.$1;
6892: my $lc_sec = $2;
6893: unless (grep/^$sec$/,@{$allcourses}) {
6894: push @{$allcourses},$sec;
6895: $$LC_code{$sec} = $lc_sec;
6896: }
6897: }
6898: }
6899: }
6900: return;
6901: }
6902:
1.112 bowersj2 6903: =pod
6904:
1.549 albertel 6905: =back
6906:
6907: =head1 HTTP Helpers
6908:
6909: =over 4
6910:
1.648 raeburn 6911: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 6912:
1.258 albertel 6913: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 6914: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 6915: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 6916:
6917: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
6918: $possible_names is an ref to an array of form element names. As an example:
6919: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 6920: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 6921:
6922: =cut
1.1 albertel 6923:
1.6 albertel 6924: sub get_unprocessed_cgi {
1.25 albertel 6925: my ($query,$possible_names)= @_;
1.26 matthew 6926: # $Apache::lonxml::debug=1;
1.356 albertel 6927: foreach my $pair (split(/&/,$query)) {
6928: my ($name, $value) = split(/=/,$pair);
1.369 www 6929: $name = &unescape($name);
1.25 albertel 6930: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
6931: $value =~ tr/+/ /;
6932: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 6933: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 6934: }
1.16 harris41 6935: }
1.6 albertel 6936: }
6937:
1.112 bowersj2 6938: =pod
6939:
1.648 raeburn 6940: =item * &cacheheader()
1.112 bowersj2 6941:
6942: returns cache-controlling header code
6943:
6944: =cut
6945:
1.7 albertel 6946: sub cacheheader {
1.258 albertel 6947: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 6948: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
6949: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 6950: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
6951: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 6952: return $output;
1.7 albertel 6953: }
6954:
1.112 bowersj2 6955: =pod
6956:
1.648 raeburn 6957: =item * &no_cache($r)
1.112 bowersj2 6958:
6959: specifies header code to not have cache
6960:
6961: =cut
6962:
1.9 albertel 6963: sub no_cache {
1.216 albertel 6964: my ($r) = @_;
6965: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 6966: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 6967: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
6968: $r->no_cache(1);
6969: $r->header_out("Expires" => $date);
6970: $r->header_out("Pragma" => "no-cache");
1.123 www 6971: }
6972:
6973: sub content_type {
1.181 albertel 6974: my ($r,$type,$charset) = @_;
1.299 foxr 6975: if ($r) {
6976: # Note that printout.pl calls this with undef for $r.
6977: &no_cache($r);
6978: }
1.258 albertel 6979: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 6980: unless ($charset) {
6981: $charset=&Apache::lonlocal::current_encoding;
6982: }
6983: if ($charset) { $type.='; charset='.$charset; }
6984: if ($r) {
6985: $r->content_type($type);
6986: } else {
6987: print("Content-type: $type\n\n");
6988: }
1.9 albertel 6989: }
1.25 albertel 6990:
1.112 bowersj2 6991: =pod
6992:
1.648 raeburn 6993: =item * &add_to_env($name,$value)
1.112 bowersj2 6994:
1.258 albertel 6995: adds $name to the %env hash with value
1.112 bowersj2 6996: $value, if $name already exists, the entry is converted to an array
6997: reference and $value is added to the array.
6998:
6999: =cut
7000:
1.25 albertel 7001: sub add_to_env {
7002: my ($name,$value)=@_;
1.258 albertel 7003: if (defined($env{$name})) {
7004: if (ref($env{$name})) {
1.25 albertel 7005: #already have multiple values
1.258 albertel 7006: push(@{ $env{$name} },$value);
1.25 albertel 7007: } else {
7008: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 7009: my $first=$env{$name};
7010: undef($env{$name});
7011: push(@{ $env{$name} },$first,$value);
1.25 albertel 7012: }
7013: } else {
1.258 albertel 7014: $env{$name}=$value;
1.25 albertel 7015: }
1.31 albertel 7016: }
1.149 albertel 7017:
7018: =pod
7019:
1.648 raeburn 7020: =item * &get_env_multiple($name)
1.149 albertel 7021:
1.258 albertel 7022: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 7023: values may be defined and end up as an array ref.
7024:
7025: returns an array of values
7026:
7027: =cut
7028:
7029: sub get_env_multiple {
7030: my ($name) = @_;
7031: my @values;
1.258 albertel 7032: if (defined($env{$name})) {
1.149 albertel 7033: # exists is it an array
1.258 albertel 7034: if (ref($env{$name})) {
7035: @values=@{ $env{$name} };
1.149 albertel 7036: } else {
1.258 albertel 7037: $values[0]=$env{$name};
1.149 albertel 7038: }
7039: }
7040: return(@values);
7041: }
7042:
1.660 raeburn 7043: sub ask_for_embedded_content {
7044: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
7045: my $upload_output = '
7046: <form name="upload_embedded" action="'.$actionurl.'"
7047: method="post" enctype="multipart/form-data">';
7048: $upload_output .= $state;
1.661 raeburn 7049: $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660 raeburn 7050:
7051: my $num = 0;
7052: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
7053: $upload_output .= &start_data_table_row().
7054: '<td>'.$embed_file.'</td><td>';
7055: if ($args->{'ignore_remote_references'}
7056: && $embed_file =~ m{^\w+://}) {
7057: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
7058: } elsif ($args->{'error_on_invalid_names'}
7059: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
7060:
7061: $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
7062:
7063: } else {
7064: $upload_output .='
1.661 raeburn 7065: <input name="embedded_item_'.$num.'" type="file" value="" />
1.660 raeburn 7066: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
7067: my $attrib = join(':',@{$$allfiles{$embed_file}});
7068: $upload_output .=
7069: "\n\t\t".
7070: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
7071: $attrib.'" />';
7072: if (exists($$codebase{$embed_file})) {
7073: $upload_output .=
7074: "\n\t\t".
7075: '<input name="codebase_'.$num.'" type="hidden" value="'.
7076: &escape($$codebase{$embed_file}).'" />';
7077: }
7078: }
7079: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
7080: $num++;
7081: }
7082: $upload_output .= &Apache::loncommon::end_data_table().'<br />
7083: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
7084: <input type ="submit" value="'.&mt('Upload Listed Files').'" />
7085: '.&mt('(only files for which a location has been provided will be uploaded)').'
7086: </form>';
7087: return $upload_output;
7088: }
7089:
1.661 raeburn 7090: sub upload_embedded {
7091: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
7092: $current_disk_usage) = @_;
7093: my $output;
7094: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
7095: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
7096: my $orig_uploaded_filename =
7097: $env{'form.embedded_item_'.$i.'.filename'};
7098:
7099: $env{'form.embedded_orig_'.$i} =
7100: &unescape($env{'form.embedded_orig_'.$i});
7101: my ($path,$fname) =
7102: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
7103: # no path, whole string is fname
7104: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
7105:
7106: $path = $env{'form.currentpath'}.$path;
7107: $fname = &Apache::lonnet::clean_filename($fname);
7108: # See if there is anything left
7109: next if ($fname eq '');
7110:
7111: # Check if file already exists as a file or directory.
7112: my ($state,$msg);
7113: if ($context eq 'portfolio') {
7114: my $port_path = $dirpath;
7115: if ($group ne '') {
7116: $port_path = "groups/$group/$port_path";
7117: }
7118: ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
7119: $dir_root,$port_path,$disk_quota,
7120: $current_disk_usage,$uname,$udom);
7121: if ($state eq 'will_exceed_quota'
7122: || $state eq 'file_locked'
7123: || $state eq 'file_exists' ) {
7124: $output .= $msg;
7125: next;
7126: }
7127: } elsif (($context eq 'author') || ($context eq 'testbank')) {
7128: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
7129: if ($state eq 'exists') {
7130: $output .= $msg;
7131: next;
7132: }
7133: }
7134: # Check if extension is valid
7135: if (($fname =~ /\.(\w+)$/) &&
7136: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7137: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
7138: next;
7139: } elsif (($fname =~ /\.(\w+)$/) &&
7140: (!defined(&Apache::loncommon::fileembstyle($1)))) {
7141: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7142: next;
7143: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
7144: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
7145: next;
7146: }
7147:
7148: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
7149: if ($context eq 'portfolio') {
7150: my $result=
7151: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
7152: $dirpath.$path);
7153: if ($result !~ m|^/uploaded/|) {
7154: $output .= '<span class="LC_error">'
7155: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
7156: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
7157: .'</span><br />';
7158: next;
7159: } else {
7160: $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
7161: $path.$fname.'</span>').'</p>';
7162: }
7163: } else {
7164: # Save the file
7165: my $target = $env{'form.embedded_item_'.$i};
7166: my $fullpath = $dir_root.$dirpath.'/'.$path;
7167: my $dest = $fullpath.$fname;
7168: my $url = $url_root.$dirpath.'/'.$path.$fname;
7169: my @parts=split(/\//,$fullpath);
7170: my $count;
7171: my $filepath = $dir_root;
7172: for ($count=4;$count<=$#parts;$count++) {
7173: $filepath .= "/$parts[$count]";
7174: if ((-e $filepath)!=1) {
7175: mkdir($filepath,0770);
7176: }
7177: }
7178: my $fh;
7179: if (!open($fh,'>'.$dest)) {
7180: &Apache::lonnet::logthis('Failed to create '.$dest);
7181: $output .= '<span class="LC_error">'.
7182: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7183: '</span><br />';
7184: } else {
7185: if (!print $fh $env{'form.embedded_item_'.$i}) {
7186: &Apache::lonnet::logthis('Failed to write to '.$dest);
7187: $output .= '<span class="LC_error">'.
7188: &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
7189: '</span><br />';
7190: } else {
7191: if ($context eq 'testbank') {
7192: $output .= &mt('Embedded file uploaded successfully:').
7193: ' <a href="'.$url.'">'.
7194: $orig_uploaded_filename.'</a><br />';
7195: } else {
7196: $output .= '<font size="+2">'.
7197: &mt('View embedded file: [_1]','<a href="'.$url.'">'.
7198: $orig_uploaded_filename.'</a>').'</font><br />';
7199: }
7200: }
7201: close($fh);
7202: }
7203: }
7204: }
7205: return $output;
7206: }
7207:
7208: sub check_for_existing {
7209: my ($path,$fname,$element) = @_;
7210: my ($state,$msg);
7211: if (-d $path.'/'.$fname) {
7212: $state = 'exists';
7213: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7214: } elsif (-e $path.'/'.$fname) {
7215: $state = 'exists';
7216: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
7217: }
7218: if ($state eq 'exists') {
7219: $msg = '<span class="LC_error">'.$msg.'</span><br />';
7220: }
7221: return ($state,$msg);
7222: }
7223:
7224: sub check_for_upload {
7225: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
7226: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
7227: my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
7228: my $getpropath = 1;
7229: my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
7230: $getpropath);
7231: my $found_file = 0;
7232: my $locked_file = 0;
7233: foreach my $line (@dir_list) {
7234: my ($file_name)=split(/\&/,$line,2);
7235: if ($file_name eq $fname){
7236: $file_name = $path.$file_name;
7237: if ($group ne '') {
7238: $file_name = $group.$file_name;
7239: }
7240: $found_file = 1;
7241: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
7242: $locked_file = 1;
7243: }
7244: }
7245: }
7246: if (($current_disk_usage + $filesize) > $disk_quota){
7247: my $msg = '<span class="LC_error">'.
7248: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
7249: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
7250: return ('will_exceed_quota',$msg);
7251: } elsif ($found_file) {
7252: if ($locked_file) {
7253: my $msg = '<span class="LC_error">';
7254: $msg .= &mt('Unable to upload [_1]. A locked file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>','<span class="LC_filename">'.$port_path.$env{'form.currentpath'}.'</span>');
7255: $msg .= '</span><br />';
7256: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
7257: return ('file_locked',$msg);
7258: } else {
7259: my $msg = '<span class="LC_error">';
7260: $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
7261: $msg .= '</span>';
7262: $msg .= '<br />';
7263: $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
7264: return ('file_exists',$msg);
7265: }
7266: }
7267: }
7268:
1.31 albertel 7269:
1.41 ng 7270: =pod
1.45 matthew 7271:
1.464 albertel 7272: =back
1.41 ng 7273:
1.112 bowersj2 7274: =head1 CSV Upload/Handling functions
1.38 albertel 7275:
1.41 ng 7276: =over 4
7277:
1.648 raeburn 7278: =item * &upfile_store($r)
1.41 ng 7279:
7280: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 7281: needs $env{'form.upfile'}
1.41 ng 7282: returns $datatoken to be put into hidden field
7283:
7284: =cut
1.31 albertel 7285:
7286: sub upfile_store {
7287: my $r=shift;
1.258 albertel 7288: $env{'form.upfile'}=~s/\r/\n/gs;
7289: $env{'form.upfile'}=~s/\f/\n/gs;
7290: $env{'form.upfile'}=~s/\n+/\n/gs;
7291: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 7292:
1.258 albertel 7293: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
7294: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 7295: {
1.158 raeburn 7296: my $datafile = $r->dir_config('lonDaemons').
7297: '/tmp/'.$datatoken.'.tmp';
7298: if ( open(my $fh,">$datafile") ) {
1.258 albertel 7299: print $fh $env{'form.upfile'};
1.158 raeburn 7300: close($fh);
7301: }
1.31 albertel 7302: }
7303: return $datatoken;
7304: }
7305:
1.56 matthew 7306: =pod
7307:
1.648 raeburn 7308: =item * &load_tmp_file($r)
1.41 ng 7309:
7310: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 7311: needs $env{'form.datatoken'},
7312: sets $env{'form.upfile'} to the contents of the file
1.41 ng 7313:
7314: =cut
1.31 albertel 7315:
7316: sub load_tmp_file {
7317: my $r=shift;
7318: my @studentdata=();
7319: {
1.158 raeburn 7320: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 7321: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 7322: if ( open(my $fh,"<$studentfile") ) {
7323: @studentdata=<$fh>;
7324: close($fh);
7325: }
1.31 albertel 7326: }
1.258 albertel 7327: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 7328: }
7329:
1.56 matthew 7330: =pod
7331:
1.648 raeburn 7332: =item * &upfile_record_sep()
1.41 ng 7333:
7334: Separate uploaded file into records
7335: returns array of records,
1.258 albertel 7336: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 7337:
7338: =cut
1.31 albertel 7339:
7340: sub upfile_record_sep {
1.258 albertel 7341: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 7342: } else {
1.248 albertel 7343: my @records;
1.258 albertel 7344: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 7345: if ($line=~/^\s*$/) { next; }
7346: push(@records,$line);
7347: }
7348: return @records;
1.31 albertel 7349: }
7350: }
7351:
1.56 matthew 7352: =pod
7353:
1.648 raeburn 7354: =item * &record_sep($record)
1.41 ng 7355:
1.258 albertel 7356: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 7357:
7358: =cut
7359:
1.263 www 7360: sub takeleft {
7361: my $index=shift;
7362: return substr('0000'.$index,-4,4);
7363: }
7364:
1.31 albertel 7365: sub record_sep {
7366: my $record=shift;
7367: my %components=();
1.258 albertel 7368: if ($env{'form.upfiletype'} eq 'xml') {
7369: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 7370: my $i=0;
1.356 albertel 7371: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 7372: $field=~s/^(\"|\')//;
7373: $field=~s/(\"|\')$//;
1.263 www 7374: $components{&takeleft($i)}=$field;
1.31 albertel 7375: $i++;
7376: }
1.258 albertel 7377: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 7378: my $i=0;
1.356 albertel 7379: foreach my $field (split(/\t/,$record)) {
1.31 albertel 7380: $field=~s/^(\"|\')//;
7381: $field=~s/(\"|\')$//;
1.263 www 7382: $components{&takeleft($i)}=$field;
1.31 albertel 7383: $i++;
7384: }
7385: } else {
1.561 www 7386: my $separator=',';
1.480 banghart 7387: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 7388: $separator=';';
1.480 banghart 7389: }
1.31 albertel 7390: my $i=0;
1.561 www 7391: # the character we are looking for to indicate the end of a quote or a record
7392: my $looking_for=$separator;
7393: # do not add the characters to the fields
7394: my $ignore=0;
7395: # we just encountered a separator (or the beginning of the record)
7396: my $just_found_separator=1;
7397: # store the field we are working on here
7398: my $field='';
7399: # work our way through all characters in record
7400: foreach my $character ($record=~/(.)/g) {
7401: if ($character eq $looking_for) {
7402: if ($character ne $separator) {
7403: # Found the end of a quote, again looking for separator
7404: $looking_for=$separator;
7405: $ignore=1;
7406: } else {
7407: # Found a separator, store away what we got
7408: $components{&takeleft($i)}=$field;
7409: $i++;
7410: $just_found_separator=1;
7411: $ignore=0;
7412: $field='';
7413: }
7414: next;
7415: }
7416: # single or double quotation marks after a separator indicate beginning of a quote
7417: # we are now looking for the end of the quote and need to ignore separators
7418: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
7419: $looking_for=$character;
7420: next;
7421: }
7422: # ignore would be true after we reached the end of a quote
7423: if ($ignore) { next; }
7424: if (($just_found_separator) && ($character=~/\s/)) { next; }
7425: $field.=$character;
7426: $just_found_separator=0;
1.31 albertel 7427: }
1.561 www 7428: # catch the very last entry, since we never encountered the separator
7429: $components{&takeleft($i)}=$field;
1.31 albertel 7430: }
7431: return %components;
7432: }
7433:
1.144 matthew 7434: ######################################################
7435: ######################################################
7436:
1.56 matthew 7437: =pod
7438:
1.648 raeburn 7439: =item * &upfile_select_html()
1.41 ng 7440:
1.144 matthew 7441: Return HTML code to select a file from the users machine and specify
7442: the file type.
1.41 ng 7443:
7444: =cut
7445:
1.144 matthew 7446: ######################################################
7447: ######################################################
1.31 albertel 7448: sub upfile_select_html {
1.144 matthew 7449: my %Types = (
7450: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 7451: semisv => &mt('Semicolon separated values'),
1.144 matthew 7452: space => &mt('Space separated'),
7453: tab => &mt('Tabulator separated'),
7454: # xml => &mt('HTML/XML'),
7455: );
7456: my $Str = '<input type="file" name="upfile" size="50" />'.
7457: '<br />Type: <select name="upfiletype">';
7458: foreach my $type (sort(keys(%Types))) {
7459: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
7460: }
7461: $Str .= "</select>\n";
7462: return $Str;
1.31 albertel 7463: }
7464:
1.301 albertel 7465: sub get_samples {
7466: my ($records,$toget) = @_;
7467: my @samples=({});
7468: my $got=0;
7469: foreach my $rec (@$records) {
7470: my %temp = &record_sep($rec);
7471: if (! grep(/\S/, values(%temp))) { next; }
7472: if (%temp) {
7473: $samples[$got]=\%temp;
7474: $got++;
7475: if ($got == $toget) { last; }
7476: }
7477: }
7478: return \@samples;
7479: }
7480:
1.144 matthew 7481: ######################################################
7482: ######################################################
7483:
1.56 matthew 7484: =pod
7485:
1.648 raeburn 7486: =item * &csv_print_samples($r,$records)
1.41 ng 7487:
7488: Prints a table of sample values from each column uploaded $r is an
7489: Apache Request ref, $records is an arrayref from
7490: &Apache::loncommon::upfile_record_sep
7491:
7492: =cut
7493:
1.144 matthew 7494: ######################################################
7495: ######################################################
1.31 albertel 7496: sub csv_print_samples {
7497: my ($r,$records) = @_;
1.662 bisitz 7498: my $samples = &get_samples($records,5);
1.301 albertel 7499:
1.594 raeburn 7500: $r->print(&mt('Samples').'<br />'.&start_data_table().
7501: &start_data_table_header_row());
1.356 albertel 7502: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7503: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 7504: $r->print(&end_data_table_header_row());
1.301 albertel 7505: foreach my $hash (@$samples) {
1.594 raeburn 7506: $r->print(&start_data_table_row());
1.356 albertel 7507: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 7508: $r->print('<td>');
1.356 albertel 7509: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 7510: $r->print('</td>');
7511: }
1.594 raeburn 7512: $r->print(&end_data_table_row());
1.31 albertel 7513: }
1.594 raeburn 7514: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 7515: }
7516:
1.144 matthew 7517: ######################################################
7518: ######################################################
7519:
1.56 matthew 7520: =pod
7521:
1.648 raeburn 7522: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 7523:
7524: Prints a table to create associations between values and table columns.
1.144 matthew 7525:
1.41 ng 7526: $r is an Apache Request ref,
7527: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 7528: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 7529:
7530: =cut
7531:
1.144 matthew 7532: ######################################################
7533: ######################################################
1.31 albertel 7534: sub csv_print_select_table {
7535: my ($r,$records,$d) = @_;
1.301 albertel 7536: my $i=0;
7537: my $samples = &get_samples($records,1);
1.144 matthew 7538: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 7539: &start_data_table().&start_data_table_header_row().
1.144 matthew 7540: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 7541: '<th>'.&mt('Column').'</th>'.
7542: &end_data_table_header_row()."\n");
1.356 albertel 7543: foreach my $array_ref (@$d) {
7544: my ($value,$display,$defaultcol)=@{ $array_ref };
1.594 raeburn 7545: $r->print(&start_data_table_row().'<tr><td>'.$display.'</td>');
1.31 albertel 7546:
7547: $r->print('<td><select name=f'.$i.
1.32 matthew 7548: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 7549: $r->print('<option value="none"></option>');
1.356 albertel 7550: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
7551: $r->print('<option value="'.$sample.'"'.
7552: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 7553: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 7554: }
1.594 raeburn 7555: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 7556: $i++;
7557: }
1.594 raeburn 7558: $r->print(&end_data_table());
1.31 albertel 7559: $i--;
7560: return $i;
7561: }
1.56 matthew 7562:
1.144 matthew 7563: ######################################################
7564: ######################################################
7565:
1.56 matthew 7566: =pod
1.31 albertel 7567:
1.648 raeburn 7568: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 7569:
7570: Prints a table of sample values from the upload and can make associate samples to internal names.
7571:
7572: $r is an Apache Request ref,
7573: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
7574: $d is an array of 2 element arrays (internal name, displayed name)
7575:
7576: =cut
7577:
1.144 matthew 7578: ######################################################
7579: ######################################################
1.31 albertel 7580: sub csv_samples_select_table {
7581: my ($r,$records,$d) = @_;
7582: my $i=0;
1.144 matthew 7583: #
1.662 bisitz 7584: my $max_samples = 5;
7585: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 7586: $r->print(&start_data_table().
7587: &start_data_table_header_row().'<th>'.
7588: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
7589: &end_data_table_header_row());
1.301 albertel 7590:
7591: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 7592: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 7593: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 7594: foreach my $option (@$d) {
7595: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 7596: $r->print('<option value="'.$value.'"'.
1.253 albertel 7597: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 7598: $display.'</option>');
1.31 albertel 7599: }
7600: $r->print('</select></td><td>');
1.662 bisitz 7601: foreach my $line (0..($max_samples-1)) {
1.301 albertel 7602: if (defined($samples->[$line]{$key})) {
7603: $r->print($samples->[$line]{$key}."<br />\n");
7604: }
7605: }
1.594 raeburn 7606: $r->print('</td>'.&end_data_table_row());
1.31 albertel 7607: $i++;
7608: }
1.594 raeburn 7609: $r->print(&end_data_table());
1.31 albertel 7610: $i--;
7611: return($i);
1.115 matthew 7612: }
7613:
1.144 matthew 7614: ######################################################
7615: ######################################################
7616:
1.115 matthew 7617: =pod
7618:
1.648 raeburn 7619: =item * &clean_excel_name($name)
1.115 matthew 7620:
7621: Returns a replacement for $name which does not contain any illegal characters.
7622:
7623: =cut
7624:
1.144 matthew 7625: ######################################################
7626: ######################################################
1.115 matthew 7627: sub clean_excel_name {
7628: my ($name) = @_;
7629: $name =~ s/[:\*\?\/\\]//g;
7630: if (length($name) > 31) {
7631: $name = substr($name,0,31);
7632: }
7633: return $name;
1.25 albertel 7634: }
1.84 albertel 7635:
1.85 albertel 7636: =pod
7637:
1.648 raeburn 7638: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 7639:
7640: Returns either 1 or undef
7641:
7642: 1 if the part is to be hidden, undef if it is to be shown
7643:
7644: Arguments are:
7645:
7646: $id the id of the part to be checked
7647: $symb, optional the symb of the resource to check
7648: $udom, optional the domain of the user to check for
7649: $uname, optional the username of the user to check for
7650:
7651: =cut
1.84 albertel 7652:
7653: sub check_if_partid_hidden {
7654: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 7655: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 7656: $symb,$udom,$uname);
1.141 albertel 7657: my $truth=1;
7658: #if the string starts with !, then the list is the list to show not hide
7659: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 7660: my @hiddenlist=split(/,/,$hiddenparts);
7661: foreach my $checkid (@hiddenlist) {
1.141 albertel 7662: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 7663: }
1.141 albertel 7664: return !$truth;
1.84 albertel 7665: }
1.127 matthew 7666:
1.138 matthew 7667:
7668: ############################################################
7669: ############################################################
7670:
7671: =pod
7672:
1.157 matthew 7673: =back
7674:
1.138 matthew 7675: =head1 cgi-bin script and graphing routines
7676:
1.157 matthew 7677: =over 4
7678:
1.648 raeburn 7679: =item * &get_cgi_id()
1.138 matthew 7680:
7681: Inputs: none
7682:
7683: Returns an id which can be used to pass environment variables
7684: to various cgi-bin scripts. These environment variables will
7685: be removed from the users environment after a given time by
7686: the routine &Apache::lonnet::transfer_profile_to_env.
7687:
7688: =cut
7689:
7690: ############################################################
7691: ############################################################
1.152 albertel 7692: my $uniq=0;
1.136 matthew 7693: sub get_cgi_id {
1.154 albertel 7694: $uniq=($uniq+1)%100000;
1.280 albertel 7695: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 7696: }
7697:
1.127 matthew 7698: ############################################################
7699: ############################################################
7700:
7701: =pod
7702:
1.648 raeburn 7703: =item * &DrawBarGraph()
1.127 matthew 7704:
1.138 matthew 7705: Facilitates the plotting of data in a (stacked) bar graph.
7706: Puts plot definition data into the users environment in order for
7707: graph.png to plot it. Returns an <img> tag for the plot.
7708: The bars on the plot are labeled '1','2',...,'n'.
7709:
7710: Inputs:
7711:
7712: =over 4
7713:
7714: =item $Title: string, the title of the plot
7715:
7716: =item $xlabel: string, text describing the X-axis of the plot
7717:
7718: =item $ylabel: string, text describing the Y-axis of the plot
7719:
7720: =item $Max: scalar, the maximum Y value to use in the plot
7721: If $Max is < any data point, the graph will not be rendered.
7722:
1.140 matthew 7723: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 7724: they are plotted. If undefined, default values will be used.
7725:
1.178 matthew 7726: =item $labels: array ref holding the labels to use on the x-axis for the bars.
7727:
1.138 matthew 7728: =item @Values: An array of array references. Each array reference holds data
7729: to be plotted in a stacked bar chart.
7730:
1.239 matthew 7731: =item If the final element of @Values is a hash reference the key/value
7732: pairs will be added to the graph definition.
7733:
1.138 matthew 7734: =back
7735:
7736: Returns:
7737:
7738: An <img> tag which references graph.png and the appropriate identifying
7739: information for the plot.
7740:
1.127 matthew 7741: =cut
7742:
7743: ############################################################
7744: ############################################################
1.134 matthew 7745: sub DrawBarGraph {
1.178 matthew 7746: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 7747: #
7748: if (! defined($colors)) {
7749: $colors = ['#33ff00',
7750: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
7751: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
7752: ];
7753: }
1.228 matthew 7754: my $extra_settings = {};
7755: if (ref($Values[-1]) eq 'HASH') {
7756: $extra_settings = pop(@Values);
7757: }
1.127 matthew 7758: #
1.136 matthew 7759: my $identifier = &get_cgi_id();
7760: my $id = 'cgi.'.$identifier;
1.129 matthew 7761: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 7762: return '';
7763: }
1.225 matthew 7764: #
7765: my @Labels;
7766: if (defined($labels)) {
7767: @Labels = @$labels;
7768: } else {
7769: for (my $i=0;$i<@{$Values[0]};$i++) {
7770: push (@Labels,$i+1);
7771: }
7772: }
7773: #
1.129 matthew 7774: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 7775: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 7776: my %ValuesHash;
7777: my $NumSets=1;
7778: foreach my $array (@Values) {
7779: next if (! ref($array));
1.136 matthew 7780: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 7781: join(',',@$array);
1.129 matthew 7782: }
1.127 matthew 7783: #
1.136 matthew 7784: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 7785: if ($NumBars < 3) {
7786: $width = 120+$NumBars*32;
1.220 matthew 7787: $xskip = 1;
1.225 matthew 7788: $bar_width = 30;
7789: } elsif ($NumBars < 5) {
7790: $width = 120+$NumBars*20;
7791: $xskip = 1;
7792: $bar_width = 20;
1.220 matthew 7793: } elsif ($NumBars < 10) {
1.136 matthew 7794: $width = 120+$NumBars*15;
7795: $xskip = 1;
7796: $bar_width = 15;
7797: } elsif ($NumBars <= 25) {
7798: $width = 120+$NumBars*11;
7799: $xskip = 5;
7800: $bar_width = 8;
7801: } elsif ($NumBars <= 50) {
7802: $width = 120+$NumBars*8;
7803: $xskip = 5;
7804: $bar_width = 4;
7805: } else {
7806: $width = 120+$NumBars*8;
7807: $xskip = 5;
7808: $bar_width = 4;
7809: }
7810: #
1.137 matthew 7811: $Max = 1 if ($Max < 1);
7812: if ( int($Max) < $Max ) {
7813: $Max++;
7814: $Max = int($Max);
7815: }
1.127 matthew 7816: $Title = '' if (! defined($Title));
7817: $xlabel = '' if (! defined($xlabel));
7818: $ylabel = '' if (! defined($ylabel));
1.369 www 7819: $ValuesHash{$id.'.title'} = &escape($Title);
7820: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
7821: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 7822: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 7823: $ValuesHash{$id.'.NumBars'} = $NumBars;
7824: $ValuesHash{$id.'.NumSets'} = $NumSets;
7825: $ValuesHash{$id.'.PlotType'} = 'bar';
7826: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7827: $ValuesHash{$id.'.height'} = $height;
7828: $ValuesHash{$id.'.width'} = $width;
7829: $ValuesHash{$id.'.xskip'} = $xskip;
7830: $ValuesHash{$id.'.bar_width'} = $bar_width;
7831: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 7832: #
1.228 matthew 7833: # Deal with other parameters
7834: while (my ($key,$value) = each(%$extra_settings)) {
7835: $ValuesHash{$id.'.'.$key} = $value;
7836: }
7837: #
1.646 raeburn 7838: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 7839: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7840: }
7841:
7842: ############################################################
7843: ############################################################
7844:
7845: =pod
7846:
1.648 raeburn 7847: =item * &DrawXYGraph()
1.137 matthew 7848:
1.138 matthew 7849: Facilitates the plotting of data in an XY graph.
7850: Puts plot definition data into the users environment in order for
7851: graph.png to plot it. Returns an <img> tag for the plot.
7852:
7853: Inputs:
7854:
7855: =over 4
7856:
7857: =item $Title: string, the title of the plot
7858:
7859: =item $xlabel: string, text describing the X-axis of the plot
7860:
7861: =item $ylabel: string, text describing the Y-axis of the plot
7862:
7863: =item $Max: scalar, the maximum Y value to use in the plot
7864: If $Max is < any data point, the graph will not be rendered.
7865:
7866: =item $colors: Array ref containing the hex color codes for the data to be
7867: plotted in. If undefined, default values will be used.
7868:
7869: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7870:
7871: =item $Ydata: Array ref containing Array refs.
1.185 www 7872: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 7873:
7874: =item %Values: hash indicating or overriding any default values which are
7875: passed to graph.png.
7876: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7877:
7878: =back
7879:
7880: Returns:
7881:
7882: An <img> tag which references graph.png and the appropriate identifying
7883: information for the plot.
7884:
1.137 matthew 7885: =cut
7886:
7887: ############################################################
7888: ############################################################
7889: sub DrawXYGraph {
7890: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
7891: #
7892: # Create the identifier for the graph
7893: my $identifier = &get_cgi_id();
7894: my $id = 'cgi.'.$identifier;
7895: #
7896: $Title = '' if (! defined($Title));
7897: $xlabel = '' if (! defined($xlabel));
7898: $ylabel = '' if (! defined($ylabel));
7899: my %ValuesHash =
7900: (
1.369 www 7901: $id.'.title' => &escape($Title),
7902: $id.'.xlabel' => &escape($xlabel),
7903: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 7904: $id.'.y_max_value'=> $Max,
7905: $id.'.labels' => join(',',@$Xlabels),
7906: $id.'.PlotType' => 'XY',
7907: );
7908: #
7909: if (defined($colors) && ref($colors) eq 'ARRAY') {
7910: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
7911: }
7912: #
7913: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
7914: return '';
7915: }
7916: my $NumSets=1;
1.138 matthew 7917: foreach my $array (@{$Ydata}){
1.137 matthew 7918: next if (! ref($array));
7919: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
7920: }
1.138 matthew 7921: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 7922: #
7923: # Deal with other parameters
7924: while (my ($key,$value) = each(%Values)) {
7925: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 7926: }
7927: #
1.646 raeburn 7928: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 7929: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
7930: }
7931:
7932: ############################################################
7933: ############################################################
7934:
7935: =pod
7936:
1.648 raeburn 7937: =item * &DrawXYYGraph()
1.138 matthew 7938:
7939: Facilitates the plotting of data in an XY graph with two Y axes.
7940: Puts plot definition data into the users environment in order for
7941: graph.png to plot it. Returns an <img> tag for the plot.
7942:
7943: Inputs:
7944:
7945: =over 4
7946:
7947: =item $Title: string, the title of the plot
7948:
7949: =item $xlabel: string, text describing the X-axis of the plot
7950:
7951: =item $ylabel: string, text describing the Y-axis of the plot
7952:
7953: =item $colors: Array ref containing the hex color codes for the data to be
7954: plotted in. If undefined, default values will be used.
7955:
7956: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
7957:
7958: =item $Ydata1: The first data set
7959:
7960: =item $Min1: The minimum value of the left Y-axis
7961:
7962: =item $Max1: The maximum value of the left Y-axis
7963:
7964: =item $Ydata2: The second data set
7965:
7966: =item $Min2: The minimum value of the right Y-axis
7967:
7968: =item $Max2: The maximum value of the left Y-axis
7969:
7970: =item %Values: hash indicating or overriding any default values which are
7971: passed to graph.png.
7972: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
7973:
7974: =back
7975:
7976: Returns:
7977:
7978: An <img> tag which references graph.png and the appropriate identifying
7979: information for the plot.
1.136 matthew 7980:
7981: =cut
7982:
7983: ############################################################
7984: ############################################################
1.137 matthew 7985: sub DrawXYYGraph {
7986: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
7987: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 7988: #
7989: # Create the identifier for the graph
7990: my $identifier = &get_cgi_id();
7991: my $id = 'cgi.'.$identifier;
7992: #
7993: $Title = '' if (! defined($Title));
7994: $xlabel = '' if (! defined($xlabel));
7995: $ylabel = '' if (! defined($ylabel));
7996: my %ValuesHash =
7997: (
1.369 www 7998: $id.'.title' => &escape($Title),
7999: $id.'.xlabel' => &escape($xlabel),
8000: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 8001: $id.'.labels' => join(',',@$Xlabels),
8002: $id.'.PlotType' => 'XY',
8003: $id.'.NumSets' => 2,
1.137 matthew 8004: $id.'.two_axes' => 1,
8005: $id.'.y1_max_value' => $Max1,
8006: $id.'.y1_min_value' => $Min1,
8007: $id.'.y2_max_value' => $Max2,
8008: $id.'.y2_min_value' => $Min2,
1.136 matthew 8009: );
8010: #
1.137 matthew 8011: if (defined($colors) && ref($colors) eq 'ARRAY') {
8012: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
8013: }
8014: #
8015: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
8016: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 8017: return '';
8018: }
8019: my $NumSets=1;
1.137 matthew 8020: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 8021: next if (! ref($array));
8022: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 8023: }
8024: #
8025: # Deal with other parameters
8026: while (my ($key,$value) = each(%Values)) {
8027: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 8028: }
8029: #
1.646 raeburn 8030: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 8031: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 8032: }
8033:
8034: ############################################################
8035: ############################################################
8036:
8037: =pod
8038:
1.157 matthew 8039: =back
8040:
1.139 matthew 8041: =head1 Statistics helper routines?
8042:
8043: Bad place for them but what the hell.
8044:
1.157 matthew 8045: =over 4
8046:
1.648 raeburn 8047: =item * &chartlink()
1.139 matthew 8048:
8049: Returns a link to the chart for a specific student.
8050:
8051: Inputs:
8052:
8053: =over 4
8054:
8055: =item $linktext: The text of the link
8056:
8057: =item $sname: The students username
8058:
8059: =item $sdomain: The students domain
8060:
8061: =back
8062:
1.157 matthew 8063: =back
8064:
1.139 matthew 8065: =cut
8066:
8067: ############################################################
8068: ############################################################
8069: sub chartlink {
8070: my ($linktext, $sname, $sdomain) = @_;
8071: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 8072: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 8073: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 8074: '">'.$linktext.'</a>';
1.153 matthew 8075: }
8076:
8077: #######################################################
8078: #######################################################
8079:
8080: =pod
8081:
8082: =head1 Course Environment Routines
1.157 matthew 8083:
8084: =over 4
1.153 matthew 8085:
1.648 raeburn 8086: =item * &restore_course_settings()
1.153 matthew 8087:
1.648 raeburn 8088: =item * &store_course_settings()
1.153 matthew 8089:
8090: Restores/Store indicated form parameters from the course environment.
8091: Will not overwrite existing values of the form parameters.
8092:
8093: Inputs:
8094: a scalar describing the data (e.g. 'chart', 'problem_analysis')
8095:
8096: a hash ref describing the data to be stored. For example:
8097:
8098: %Save_Parameters = ('Status' => 'scalar',
8099: 'chartoutputmode' => 'scalar',
8100: 'chartoutputdata' => 'scalar',
8101: 'Section' => 'array',
1.373 raeburn 8102: 'Group' => 'array',
1.153 matthew 8103: 'StudentData' => 'array',
8104: 'Maps' => 'array');
8105:
8106: Returns: both routines return nothing
8107:
1.631 raeburn 8108: =back
8109:
1.153 matthew 8110: =cut
8111:
8112: #######################################################
8113: #######################################################
8114: sub store_course_settings {
1.496 albertel 8115: return &store_settings($env{'request.course.id'},@_);
8116: }
8117:
8118: sub store_settings {
1.153 matthew 8119: # save to the environment
8120: # appenv the same items, just to be safe
1.300 albertel 8121: my $udom = $env{'user.domain'};
8122: my $uname = $env{'user.name'};
1.496 albertel 8123: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8124: my %SaveHash;
8125: my %AppHash;
8126: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 8127: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 8128: my $envname = 'environment.'.$basename;
1.258 albertel 8129: if (exists($env{'form.'.$setting})) {
1.153 matthew 8130: # Save this value away
8131: if ($type eq 'scalar' &&
1.258 albertel 8132: (! exists($env{$envname}) ||
8133: $env{$envname} ne $env{'form.'.$setting})) {
8134: $SaveHash{$basename} = $env{'form.'.$setting};
8135: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 8136: } elsif ($type eq 'array') {
8137: my $stored_form;
1.258 albertel 8138: if (ref($env{'form.'.$setting})) {
1.153 matthew 8139: $stored_form = join(',',
8140: map {
1.369 www 8141: &escape($_);
1.258 albertel 8142: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 8143: } else {
8144: $stored_form =
1.369 www 8145: &escape($env{'form.'.$setting});
1.153 matthew 8146: }
8147: # Determine if the array contents are the same.
1.258 albertel 8148: if ($stored_form ne $env{$envname}) {
1.153 matthew 8149: $SaveHash{$basename} = $stored_form;
8150: $AppHash{$envname} = $stored_form;
8151: }
8152: }
8153: }
8154: }
8155: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 8156: $udom,$uname);
1.153 matthew 8157: if ($put_result !~ /^(ok|delayed)/) {
8158: &Apache::lonnet::logthis('unable to save form parameters, '.
8159: 'got error:'.$put_result);
8160: }
8161: # Make sure these settings stick around in this session, too
1.646 raeburn 8162: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 8163: return;
8164: }
8165:
8166: sub restore_course_settings {
1.499 albertel 8167: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 8168: }
8169:
8170: sub restore_settings {
8171: my ($context,$prefix,$Settings) = @_;
1.153 matthew 8172: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 8173: next if (exists($env{'form.'.$setting}));
1.496 albertel 8174: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 8175: '.'.$setting;
1.258 albertel 8176: if (exists($env{$envname})) {
1.153 matthew 8177: if ($type eq 'scalar') {
1.258 albertel 8178: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 8179: } elsif ($type eq 'array') {
1.258 albertel 8180: $env{'form.'.$setting} = [
1.153 matthew 8181: map {
1.369 www 8182: &unescape($_);
1.258 albertel 8183: } split(',',$env{$envname})
1.153 matthew 8184: ];
8185: }
8186: }
8187: }
1.127 matthew 8188: }
8189:
1.618 raeburn 8190: #######################################################
8191: #######################################################
8192:
8193: =pod
8194:
8195: =head1 Domain E-mail Routines
8196:
8197: =over 4
8198:
1.648 raeburn 8199: =item * &build_recipient_list()
1.618 raeburn 8200:
8201: Build recipient lists for three types of e-mail:
8202: (a) Error Reports, (b) Package Updates, (c) Help requests, generated by
1.619 raeburn 8203: lonerrorhandler.pm, CHECKRPMS and lonsupportreq.pm respectively.
1.618 raeburn 8204:
8205: Inputs:
1.619 raeburn 8206: defmail (scalar - email address of default recipient),
1.618 raeburn 8207: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 8208: defdom (domain for which to retrieve configuration settings),
8209: origmail (scalar - email address of recipient from loncapa.conf,
8210: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 8211:
1.655 raeburn 8212: Returns: comma separated list of addresses to which to send e-mail.
8213:
8214: =back
1.618 raeburn 8215:
8216: =cut
8217:
8218: ############################################################
8219: ############################################################
8220: sub build_recipient_list {
1.619 raeburn 8221: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 8222: my @recipients;
8223: my $otheremails;
8224: my %domconfig =
8225: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
8226: if (ref($domconfig{'contacts'}) eq 'HASH') {
8227: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
8228: my @contacts = ('adminemail','supportemail');
8229: foreach my $item (@contacts) {
8230: if ($domconfig{'contacts'}{$mailing}{$item}) {
1.619 raeburn 8231: my $addr = $domconfig{'contacts'}{$item};
8232: if (!grep(/^\Q$addr\E$/,@recipients)) {
8233: push(@recipients,$addr);
8234: }
1.618 raeburn 8235: }
8236: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
8237: }
8238: }
1.619 raeburn 8239: } elsif ($origmail ne '') {
8240: push(@recipients,$origmail);
1.618 raeburn 8241: }
8242: if ($defmail ne '') {
8243: push(@recipients,$defmail);
8244: }
8245: if ($otheremails) {
1.619 raeburn 8246: my @others;
8247: if ($otheremails =~ /,/) {
8248: @others = split(/,/,$otheremails);
1.618 raeburn 8249: } else {
1.619 raeburn 8250: push(@others,$otheremails);
8251: }
8252: foreach my $addr (@others) {
8253: if (!grep(/^\Q$addr\E$/,@recipients)) {
8254: push(@recipients,$addr);
8255: }
1.618 raeburn 8256: }
8257: }
1.619 raeburn 8258: my $recipientlist = join(',',@recipients);
1.618 raeburn 8259: return $recipientlist;
8260: }
8261:
1.127 matthew 8262: ############################################################
8263: ############################################################
1.154 albertel 8264:
1.655 raeburn 8265: =pod
8266:
8267: =head1 Course Catalog Routines
8268:
8269: =over 4
8270:
8271: =item * &gather_categories()
8272:
8273: Converts category definitions - keys of categories hash stored in
8274: coursecategories in configuration.db on the primary library server in a
8275: domain - to an array. Also generates javascript and idx hash used to
8276: generate Domain Coordinator interface for editing Course Categories.
8277:
8278: Inputs:
1.663 raeburn 8279:
1.655 raeburn 8280: categories (reference to hash of category definitions).
1.663 raeburn 8281:
1.655 raeburn 8282: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8283: categories and subcategories).
1.663 raeburn 8284:
1.655 raeburn 8285: idx (reference to hash of counters used in Domain Coordinator interface for
8286: editing Course Categories).
1.663 raeburn 8287:
1.655 raeburn 8288: jsarray (reference to array of categories used to create Javascript arrays for
8289: Domain Coordinator interface for editing Course Categories).
8290:
8291: Returns: nothing
8292:
8293: Side effects: populates cats, idx and jsarray.
8294:
8295: =cut
8296:
8297: sub gather_categories {
8298: my ($categories,$cats,$idx,$jsarray) = @_;
8299: my %counters;
8300: my $num = 0;
8301: foreach my $item (keys(%{$categories})) {
8302: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8303: if ($container eq '' && $depth == 0) {
8304: $cats->[$depth][$categories->{$item}] = $cat;
8305: } else {
8306: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
8307: }
8308: my ($escitem,$tail) = split(/:/,$item,2);
8309: if ($counters{$tail} eq '') {
8310: $counters{$tail} = $num;
8311: $num ++;
8312: }
8313: if (ref($idx) eq 'HASH') {
8314: $idx->{$item} = $counters{$tail};
8315: }
8316: if (ref($jsarray) eq 'ARRAY') {
8317: push(@{$jsarray->[$counters{$tail}]},$item);
8318: }
8319: }
8320: return;
8321: }
8322:
8323: =pod
8324:
8325: =item * &extract_categories()
8326:
8327: Used to generate breadcrumb trails for course categories.
8328:
8329: Inputs:
1.663 raeburn 8330:
1.655 raeburn 8331: categories (reference to hash of category definitions).
1.663 raeburn 8332:
1.655 raeburn 8333: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8334: categories and subcategories).
1.663 raeburn 8335:
1.655 raeburn 8336: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 8337:
1.655 raeburn 8338: allitems (reference to hash - key is category key
8339: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8340:
1.655 raeburn 8341: idx (reference to hash of counters used in Domain Coordinator interface for
8342: editing Course Categories).
1.663 raeburn 8343:
1.655 raeburn 8344: jsarray (reference to array of categories used to create Javascript arrays for
8345: Domain Coordinator interface for editing Course Categories).
8346:
1.665 raeburn 8347: subcats (reference to hash of arrays containing all subcategories within each
8348: category, -recursive)
8349:
1.655 raeburn 8350: Returns: nothing
8351:
8352: Side effects: populates trails and allitems hash references.
8353:
8354: =cut
8355:
8356: sub extract_categories {
1.665 raeburn 8357: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 8358: if (ref($categories) eq 'HASH') {
8359: &gather_categories($categories,$cats,$idx,$jsarray);
8360: if (ref($cats->[0]) eq 'ARRAY') {
8361: for (my $i=0; $i<@{$cats->[0]}; $i++) {
8362: my $name = $cats->[0][$i];
8363: my $item = &escape($name).'::0';
8364: my $trailstr;
8365: if ($name eq 'instcode') {
8366: $trailstr = &mt('Official courses (with institutional codes)');
8367: } else {
8368: $trailstr = $name;
8369: }
8370: if ($allitems->{$item} eq '') {
8371: push(@{$trails},$trailstr);
8372: $allitems->{$item} = scalar(@{$trails})-1;
8373: }
8374: my @parents = ($name);
8375: if (ref($cats->[1]{$name}) eq 'ARRAY') {
8376: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
8377: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 8378: if (ref($subcats) eq 'HASH') {
8379: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
8380: }
8381: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
8382: }
8383: } else {
8384: if (ref($subcats) eq 'HASH') {
8385: $subcats->{$item} = [];
1.655 raeburn 8386: }
8387: }
8388: }
8389: }
8390: }
8391: return;
8392: }
8393:
8394: =pod
8395:
8396: =item *&recurse_categories()
8397:
8398: Recursively used to generate breadcrumb trails for course categories.
8399:
8400: Inputs:
1.663 raeburn 8401:
1.655 raeburn 8402: cats (reference to array of arrays/hashes which encapsulates hierarchy of
8403: categories and subcategories).
1.663 raeburn 8404:
1.655 raeburn 8405: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 8406:
8407: category (current course category, for which breadcrumb trail is being generated).
8408:
8409: trails (reference to array of breadcrumb trails for each category).
8410:
1.655 raeburn 8411: allitems (reference to hash - key is category key
8412: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 8413:
1.655 raeburn 8414: parents (array containing containers directories for current category,
8415: back to top level).
8416:
8417: Returns: nothing
8418:
8419: Side effects: populates trails and allitems hash references
8420:
8421: =cut
8422:
8423: sub recurse_categories {
1.665 raeburn 8424: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 8425: my $shallower = $depth - 1;
8426: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
8427: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
8428: my $name = $cats->[$depth]{$category}[$k];
8429: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8430: my $trailstr = join(' -> ',(@{$parents},$category));
8431: if ($allitems->{$item} eq '') {
8432: push(@{$trails},$trailstr);
8433: $allitems->{$item} = scalar(@{$trails})-1;
8434: }
8435: my $deeper = $depth+1;
8436: push(@{$parents},$category);
1.665 raeburn 8437: if (ref($subcats) eq 'HASH') {
8438: my $subcat = &escape($name).':'.$category.':'.$depth;
8439: for (my $j=@{$parents}; $j>=0; $j--) {
8440: my $higher;
8441: if ($j > 0) {
8442: $higher = &escape($parents->[$j]).':'.
8443: &escape($parents->[$j-1]).':'.$j;
8444: } else {
8445: $higher = &escape($parents->[$j]).'::'.$j;
8446: }
8447: push(@{$subcats->{$higher}},$subcat);
8448: }
8449: }
8450: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
8451: $subcats);
1.655 raeburn 8452: pop(@{$parents});
8453: }
8454: } else {
8455: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
8456: my $trailstr = join(' -> ',(@{$parents},$category));
8457: if ($allitems->{$item} eq '') {
8458: push(@{$trails},$trailstr);
8459: $allitems->{$item} = scalar(@{$trails})-1;
8460: }
8461: }
8462: return;
8463: }
8464:
1.663 raeburn 8465: =pod
8466:
8467: =item *&assign_categories_table()
8468:
8469: Create a datatable for display of hierarchical categories in a domain,
8470: with checkboxes to allow a course to be categorized.
8471:
8472: Inputs:
8473:
8474: cathash - reference to hash of categories defined for the domain (from
8475: configuration.db)
8476:
8477: currcat - scalar with an & separated list of categories assigned to a course.
8478:
8479: Returns: $output (markup to be displayed)
8480:
8481: =cut
8482:
8483: sub assign_categories_table {
8484: my ($cathash,$currcat) = @_;
8485: my $output;
8486: if (ref($cathash) eq 'HASH') {
8487: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
8488: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
8489: $maxdepth = scalar(@cats);
8490: if (@cats > 0) {
8491: my $itemcount = 0;
8492: if (ref($cats[0]) eq 'ARRAY') {
8493: $output = &Apache::loncommon::start_data_table();
8494: my @currcategories;
8495: if ($currcat ne '') {
8496: @currcategories = split('&',$currcat);
8497: }
8498: for (my $i=0; $i<@{$cats[0]}; $i++) {
8499: my $parent = $cats[0][$i];
8500: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8501: next if ($parent eq 'instcode');
8502: my $item = &escape($parent).'::0';
8503: my $checked = '';
8504: if (@currcategories > 0) {
8505: if (grep(/^\Q$item\E$/,@currcategories)) {
8506: $checked = ' checked="checked" ';
8507: }
8508: }
8509: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8510: .'<input type="checkbox" name="usecategory" value="'.
1.670 raeburn 8511: $item.'"'.$checked.' />'.$parent.'</span></td>';
1.663 raeburn 8512: my $depth = 1;
8513: push(@path,$parent);
8514: $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
8515: pop(@path);
8516: $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8517: $itemcount ++;
8518: }
8519: $output .= &Apache::loncommon::end_data_table();
8520: }
8521: }
8522: }
8523: return $output;
8524: }
8525:
8526: =pod
8527:
8528: =item *&assign_category_rows()
8529:
8530: Create a datatable row for display of nested categories in a domain,
8531: with checkboxes to allow a course to be categorized,called recursively.
8532:
8533: Inputs:
8534:
8535: itemcount - track row number for alternating colors
8536:
8537: cats - reference to array of arrays/hashes which encapsulates hierarchy of
8538: categories and subcategories.
8539:
8540: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
8541:
8542: parent - parent of current category item
8543:
8544: path - Array containing all categories back up through the hierarchy from the
8545: current category to the top level.
8546:
8547: currcategories - reference to array of current categories assigned to the course
8548:
8549: Returns: $output (markup to be displayed).
8550:
8551: =cut
8552:
8553: sub assign_category_rows {
8554: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
8555: my ($text,$name,$item,$chgstr);
8556: if (ref($cats) eq 'ARRAY') {
8557: my $maxdepth = scalar(@{$cats});
8558: if (ref($cats->[$depth]) eq 'HASH') {
8559: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
8560: my $numchildren = @{$cats->[$depth]{$parent}};
8561: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8562: $text .= '<td><table class="LC_datatable">';
8563: for (my $j=0; $j<$numchildren; $j++) {
8564: $name = $cats->[$depth]{$parent}[$j];
8565: $item = &escape($name).':'.&escape($parent).':'.$depth;
8566: my $deeper = $depth+1;
8567: my $checked = '';
8568: if (ref($currcategories) eq 'ARRAY') {
8569: if (@{$currcategories} > 0) {
8570: if (grep(/^\Q$item\E$/,@{$currcategories})) {
8571: $checked = ' checked="checked" ';
8572: }
8573: }
8574: }
1.664 raeburn 8575: $text .= '<tr><td><span class="LC_nobreak"><label>'.
8576: '<input type="checkbox" name="usecategory" value="'.
8577: $item.'"'.$checked.' />'.$name.'</label></span></td><td>';
1.663 raeburn 8578: if (ref($path) eq 'ARRAY') {
8579: push(@{$path},$name);
8580: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
8581: pop(@{$path});
8582: }
8583: $text .= '</td></tr>';
8584: }
8585: $text .= '</table></td>';
8586: }
8587: }
8588: }
8589: return $text;
8590: }
8591:
1.655 raeburn 8592: ############################################################
8593: ############################################################
8594:
8595:
1.443 albertel 8596: sub commit_customrole {
1.664 raeburn 8597: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 8598: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 8599: ($start?', '.&mt('starting').' '.localtime($start):'').
8600: ($end?', ending '.localtime($end):'').': <b>'.
8601: &Apache::lonnet::assigncustomrole(
1.664 raeburn 8602: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 8603: '</b><br />';
8604: return $output;
8605: }
8606:
8607: sub commit_standardrole {
1.541 raeburn 8608: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
8609: my ($output,$logmsg,$linefeed);
8610: if ($context eq 'auto') {
8611: $linefeed = "\n";
8612: } else {
8613: $linefeed = "<br />\n";
8614: }
1.443 albertel 8615: if ($three eq 'st') {
1.541 raeburn 8616: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
8617: $one,$two,$sec,$context);
8618: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 8619: ($result eq 'unknown_course') || ($result eq 'refused')) {
8620: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 8621: } else {
1.541 raeburn 8622: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 8623: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 8624: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
8625: if ($context eq 'auto') {
8626: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
8627: } else {
8628: $output .= '<b>'.$result.'</b>'.$linefeed.
8629: &mt('Add to classlist').': <b>ok</b>';
8630: }
8631: $output .= $linefeed;
1.443 albertel 8632: }
8633: } else {
8634: $output = &mt('Assigning').' '.$three.' in '.$url.
8635: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 8636: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 8637: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 8638: if ($context eq 'auto') {
8639: $output .= $result.$linefeed;
8640: } else {
8641: $output .= '<b>'.$result.'</b>'.$linefeed;
8642: }
1.443 albertel 8643: }
8644: return $output;
8645: }
8646:
8647: sub commit_studentrole {
1.541 raeburn 8648: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626 raeburn 8649: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 8650: if ($context eq 'auto') {
8651: $linefeed = "\n";
8652: } else {
8653: $linefeed = '<br />'."\n";
8654: }
1.443 albertel 8655: if (defined($one) && defined($two)) {
8656: my $cid=$one.'_'.$two;
8657: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
8658: my $secchange = 0;
8659: my $expire_role_result;
8660: my $modify_section_result;
1.628 raeburn 8661: if ($oldsec ne '-1') {
8662: if ($oldsec ne $sec) {
1.443 albertel 8663: $secchange = 1;
1.628 raeburn 8664: my $now = time;
1.443 albertel 8665: my $uurl='/'.$cid;
8666: $uurl=~s/\_/\//g;
8667: if ($oldsec) {
8668: $uurl.='/'.$oldsec;
8669: }
1.626 raeburn 8670: $oldsecurl = $uurl;
1.628 raeburn 8671: $expire_role_result =
1.652 raeburn 8672: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 8673: if ($env{'request.course.sec'} ne '') {
8674: if ($expire_role_result eq 'refused') {
8675: my @roles = ('st');
8676: my @statuses = ('previous');
8677: my @roledoms = ($one);
8678: my $withsec = 1;
8679: my %roleshash =
8680: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
8681: \@statuses,\@roles,\@roledoms,$withsec);
8682: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
8683: my ($oldstart,$oldend) =
8684: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
8685: if ($oldend > 0 && $oldend <= $now) {
8686: $expire_role_result = 'ok';
8687: }
8688: }
8689: }
8690: }
1.443 albertel 8691: $result = $expire_role_result;
8692: }
8693: }
8694: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652 raeburn 8695: $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443 albertel 8696: if ($modify_section_result =~ /^ok/) {
8697: if ($secchange == 1) {
1.628 raeburn 8698: if ($sec eq '') {
8699: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
8700: } else {
8701: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
8702: }
1.443 albertel 8703: } elsif ($oldsec eq '-1') {
1.628 raeburn 8704: if ($sec eq '') {
8705: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
8706: } else {
8707: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8708: }
1.443 albertel 8709: } else {
1.628 raeburn 8710: if ($sec eq '') {
8711: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
8712: } else {
8713: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
8714: }
1.443 albertel 8715: }
8716: } else {
1.628 raeburn 8717: if ($secchange) {
8718: $$logmsg .= &mt('Error when attempting section change for [_1] from old section "[_2]" to new section: "[_3]" in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed;
8719: } else {
8720: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
8721: }
1.443 albertel 8722: }
8723: $result = $modify_section_result;
8724: } elsif ($secchange == 1) {
1.628 raeburn 8725: if ($oldsec eq '') {
8726: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
8727: } else {
8728: $$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
8729: }
1.626 raeburn 8730: if ($expire_role_result eq 'refused') {
8731: my $newsecurl = '/'.$cid;
8732: $newsecurl =~ s/\_/\//g;
8733: if ($sec ne '') {
8734: $newsecurl.='/'.$sec;
8735: }
8736: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
8737: if ($sec eq '') {
8738: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed;
8739: } else {
8740: $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed;
8741: }
8742: }
8743: }
1.443 albertel 8744: }
8745: } else {
1.626 raeburn 8746: $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed;
1.443 albertel 8747: $result = "error: incomplete course id\n";
8748: }
8749: return $result;
8750: }
8751:
8752: ############################################################
8753: ############################################################
8754:
1.566 albertel 8755: sub check_clone {
1.578 raeburn 8756: my ($args,$linefeed) = @_;
1.566 albertel 8757: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
8758: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
8759: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
8760: my $clonemsg;
8761: my $can_clone = 0;
8762:
8763: if ($clonehome eq 'no_host') {
1.578 raeburn 8764: $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 8765: } else {
8766: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568 albertel 8767: if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566 albertel 8768: $can_clone = 1;
8769: } else {
8770: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
8771: $args->{'clonedomain'},$args->{'clonecourse'});
8772: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 8773: if (grep(/^\*$/,@cloners)) {
8774: $can_clone = 1;
8775: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
8776: $can_clone = 1;
8777: } else {
8778: my %roleshash =
8779: &Apache::lonnet::get_my_roles($args->{'ccuname'},
8780: $args->{'ccdomain'},
8781: 'userroles',['active'],['cc'],
8782: [$args->{'clonedomain'}]);
8783: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
8784: $can_clone = 1;
8785: } else {
8786: $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'});
8787: }
1.566 albertel 8788: }
1.578 raeburn 8789: }
1.566 albertel 8790: }
8791: return ($can_clone, $clonemsg, $cloneid, $clonehome);
8792: }
8793:
1.444 albertel 8794: sub construct_course {
1.541 raeburn 8795: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444 albertel 8796: my $outcome;
1.541 raeburn 8797: my $linefeed = '<br />'."\n";
8798: if ($context eq 'auto') {
8799: $linefeed = "\n";
8800: }
1.566 albertel 8801:
8802: #
8803: # Are we cloning?
8804: #
8805: my ($can_clone, $clonemsg, $cloneid, $clonehome);
8806: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 8807: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 8808: if ($context ne 'auto') {
1.578 raeburn 8809: if ($clonemsg ne '') {
8810: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
8811: }
1.566 albertel 8812: }
8813: $outcome .= $clonemsg.$linefeed;
8814:
8815: if (!$can_clone) {
8816: return (0,$outcome);
8817: }
8818: }
8819:
1.444 albertel 8820: #
8821: # Open course
8822: #
8823: my $crstype = lc($args->{'crstype'});
8824: my %cenv=();
8825: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
8826: $args->{'cdescr'},
8827: $args->{'curl'},
8828: $args->{'course_home'},
8829: $args->{'nonstandard'},
8830: $args->{'crscode'},
8831: $args->{'ccuname'}.':'.
8832: $args->{'ccdomain'},
8833: $args->{'crstype'});
8834:
8835: # Note: The testing routines depend on this being output; see
8836: # Utils::Course. This needs to at least be output as a comment
8837: # if anyone ever decides to not show this, and Utils::Course::new
8838: # will need to be suitably modified.
1.541 raeburn 8839: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444 albertel 8840: #
8841: # Check if created correctly
8842: #
1.479 albertel 8843: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 8844: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541 raeburn 8845: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 8846:
1.444 albertel 8847: #
1.566 albertel 8848: # Do the cloning
8849: #
8850: if ($can_clone && $cloneid) {
8851: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
8852: if ($context ne 'auto') {
8853: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
8854: }
8855: $outcome .= $clonemsg.$linefeed;
8856: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 8857: # Copy all files
1.637 www 8858: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 8859: # Restore URL
1.566 albertel 8860: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 8861: # Restore title
1.566 albertel 8862: $cenv{'description'}=$oldcenv{'description'};
1.444 albertel 8863: # Mark as cloned
1.566 albertel 8864: $cenv{'clonedfrom'}=$cloneid;
1.638 www 8865: # Need to clone grading mode
8866: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
8867: $cenv{'grading'}=$newenv{'grading'};
8868: # Do not clone these environment entries
8869: &Apache::lonnet::del('environment',
8870: ['default_enrollment_start_date',
8871: 'default_enrollment_end_date',
8872: 'question.email',
8873: 'policy.email',
8874: 'comment.email',
8875: 'pch.users.denied',
8876: 'plc.users.denied'],
8877: $$crsudom,$$crsunum);
1.444 albertel 8878: }
1.566 albertel 8879:
1.444 albertel 8880: #
8881: # Set environment (will override cloned, if existing)
8882: #
8883: my @sections = ();
8884: my @xlists = ();
8885: if ($args->{'crstype'}) {
8886: $cenv{'type'}=$args->{'crstype'};
8887: }
8888: if ($args->{'crsid'}) {
8889: $cenv{'courseid'}=$args->{'crsid'};
8890: }
8891: if ($args->{'crscode'}) {
8892: $cenv{'internal.coursecode'}=$args->{'crscode'};
8893: }
8894: if ($args->{'crsquota'} ne '') {
8895: $cenv{'internal.coursequota'}=$args->{'crsquota'};
8896: } else {
8897: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
8898: }
8899: if ($args->{'ccuname'}) {
8900: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
8901: ':'.$args->{'ccdomain'};
8902: } else {
8903: $cenv{'internal.courseowner'} = $args->{'curruser'};
8904: }
8905: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
8906: if ($args->{'crssections'}) {
8907: $cenv{'internal.sectionnums'} = '';
8908: if ($args->{'crssections'} =~ m/,/) {
8909: @sections = split/,/,$args->{'crssections'};
8910: } else {
8911: $sections[0] = $args->{'crssections'};
8912: }
8913: if (@sections > 0) {
8914: foreach my $item (@sections) {
8915: my ($sec,$gp) = split/:/,$item;
8916: my $class = $args->{'crscode'}.$sec;
8917: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
8918: $cenv{'internal.sectionnums'} .= $item.',';
8919: unless ($addcheck eq 'ok') {
8920: push @badclasses, $class;
8921: }
8922: }
8923: $cenv{'internal.sectionnums'} =~ s/,$//;
8924: }
8925: }
8926: # do not hide course coordinator from staff listing,
8927: # even if privileged
8928: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
8929: # add crosslistings
8930: if ($args->{'crsxlist'}) {
8931: $cenv{'internal.crosslistings'}='';
8932: if ($args->{'crsxlist'} =~ m/,/) {
8933: @xlists = split/,/,$args->{'crsxlist'};
8934: } else {
8935: $xlists[0] = $args->{'crsxlist'};
8936: }
8937: if (@xlists > 0) {
8938: foreach my $item (@xlists) {
8939: my ($xl,$gp) = split/:/,$item;
8940: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
8941: $cenv{'internal.crosslistings'} .= $item.',';
8942: unless ($addcheck eq 'ok') {
8943: push @badclasses, $xl;
8944: }
8945: }
8946: $cenv{'internal.crosslistings'} =~ s/,$//;
8947: }
8948: }
8949: if ($args->{'autoadds'}) {
8950: $cenv{'internal.autoadds'}=$args->{'autoadds'};
8951: }
8952: if ($args->{'autodrops'}) {
8953: $cenv{'internal.autodrops'}=$args->{'autodrops'};
8954: }
8955: # check for notification of enrollment changes
8956: my @notified = ();
8957: if ($args->{'notify_owner'}) {
8958: if ($args->{'ccuname'} ne '') {
8959: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
8960: }
8961: }
8962: if ($args->{'notify_dc'}) {
8963: if ($uname ne '') {
1.630 raeburn 8964: push(@notified,$uname.':'.$udom);
1.444 albertel 8965: }
8966: }
8967: if (@notified > 0) {
8968: my $notifylist;
8969: if (@notified > 1) {
8970: $notifylist = join(',',@notified);
8971: } else {
8972: $notifylist = $notified[0];
8973: }
8974: $cenv{'internal.notifylist'} = $notifylist;
8975: }
8976: if (@badclasses > 0) {
8977: my %lt=&Apache::lonlocal::texthash(
8978: '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',
8979: 'dnhr' => 'does not have rights to access enrollment in these classes',
8980: 'adby' => 'as determined by the policies of your institution on access to official classlists'
8981: );
1.541 raeburn 8982: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
8983: ' ('.$lt{'adby'}.')';
8984: if ($context eq 'auto') {
8985: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 8986: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 8987: foreach my $item (@badclasses) {
8988: if ($context eq 'auto') {
8989: $outcome .= " - $item\n";
8990: } else {
8991: $outcome .= "<li>$item</li>\n";
8992: }
8993: }
8994: if ($context eq 'auto') {
8995: $outcome .= $linefeed;
8996: } else {
1.566 albertel 8997: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 8998: }
8999: }
1.444 albertel 9000: }
9001: if ($args->{'no_end_date'}) {
9002: $args->{'endaccess'} = 0;
9003: }
9004: $cenv{'internal.autostart'}=$args->{'enrollstart'};
9005: $cenv{'internal.autoend'}=$args->{'enrollend'};
9006: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
9007: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
9008: if ($args->{'showphotos'}) {
9009: $cenv{'internal.showphotos'}=$args->{'showphotos'};
9010: }
9011: $cenv{'internal.authtype'} = $args->{'authtype'};
9012: $cenv{'internal.autharg'} = $args->{'autharg'};
9013: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
9014: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 9015: 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');
9016: if ($context eq 'auto') {
9017: $outcome .= $krb_msg;
9018: } else {
1.566 albertel 9019: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 9020: }
9021: $outcome .= $linefeed;
1.444 albertel 9022: }
9023: }
9024: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
9025: if ($args->{'setpolicy'}) {
9026: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9027: }
9028: if ($args->{'setcontent'}) {
9029: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
9030: }
9031: }
9032: if ($args->{'reshome'}) {
9033: $cenv{'reshome'}=$args->{'reshome'}.'/';
9034: $cenv{'reshome'}=~s/\/+$/\//;
9035: }
9036: #
9037: # course has keyed access
9038: #
9039: if ($args->{'setkeys'}) {
9040: $cenv{'keyaccess'}='yes';
9041: }
9042: # if specified, key authority is not course, but user
9043: # only active if keyaccess is yes
9044: if ($args->{'keyauth'}) {
1.487 albertel 9045: my ($user,$domain) = split(':',$args->{'keyauth'});
9046: $user = &LONCAPA::clean_username($user);
9047: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 9048: if ($user ne '' && $domain ne '') {
1.487 albertel 9049: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 9050: }
9051: }
9052:
9053: if ($args->{'disresdis'}) {
9054: $cenv{'pch.roles.denied'}='st';
9055: }
9056: if ($args->{'disablechat'}) {
9057: $cenv{'plc.roles.denied'}='st';
9058: }
9059:
9060: # Record we've not yet viewed the Course Initialization Helper for this
9061: # course
9062: $cenv{'course.helper.not.run'} = 1;
9063: #
9064: # Use new Randomseed
9065: #
9066: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
9067: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
9068: #
9069: # The encryption code and receipt prefix for this course
9070: #
9071: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
9072: $cenv{'internal.encpref'}=100+int(9*rand(99));
9073: #
9074: # By default, use standard grading
9075: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
9076:
1.541 raeburn 9077: $outcome .= $linefeed.&mt('Setting environment').': '.
9078: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9079: #
9080: # Open all assignments
9081: #
9082: if ($args->{'openall'}) {
9083: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
9084: my %storecontent = ($storeunder => time,
9085: $storeunder.'.type' => 'date_start');
9086:
9087: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 9088: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 9089: }
9090: #
9091: # Set first page
9092: #
9093: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
9094: || ($cloneid)) {
1.445 albertel 9095: use LONCAPA::map;
1.444 albertel 9096: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 9097:
9098: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
9099: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
9100:
1.444 albertel 9101: $outcome .= ($fatal?$errtext:'read ok').' - ';
9102: my $title; my $url;
9103: if ($args->{'firstres'} eq 'syl') {
9104: $title='Syllabus';
9105: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
9106: } else {
9107: $title='Navigate Contents';
9108: $url='/adm/navmaps';
9109: }
1.445 albertel 9110:
9111: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
9112: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
9113:
9114: if ($errtext) { $fatal=2; }
1.541 raeburn 9115: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 9116: }
1.566 albertel 9117:
9118: return (1,$outcome);
1.444 albertel 9119: }
9120:
9121: ############################################################
9122: ############################################################
9123:
1.378 raeburn 9124: sub course_type {
9125: my ($cid) = @_;
9126: if (!defined($cid)) {
9127: $cid = $env{'request.course.id'};
9128: }
1.404 albertel 9129: if (defined($env{'course.'.$cid.'.type'})) {
9130: return $env{'course.'.$cid.'.type'};
1.378 raeburn 9131: } else {
9132: return 'Course';
1.377 raeburn 9133: }
9134: }
1.156 albertel 9135:
1.406 raeburn 9136: sub group_term {
9137: my $crstype = &course_type();
9138: my %names = (
9139: 'Course' => 'group',
9140: 'Group' => 'team',
9141: );
9142: return $names{$crstype};
9143: }
9144:
1.156 albertel 9145: sub icon {
9146: my ($file)=@_;
1.505 albertel 9147: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 9148: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 9149: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 9150: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
9151: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
9152: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9153: $curfext.".gif") {
9154: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
9155: $curfext.".gif";
9156: }
9157: }
1.249 albertel 9158: return &lonhttpdurl($iconname);
1.154 albertel 9159: }
1.84 albertel 9160:
1.575 albertel 9161: sub lonhttpd_port {
1.215 albertel 9162: my $lonhttpd_port=$Apache::lonnet::perlvar{'lonhttpdPort'};
9163: if (!defined($lonhttpd_port)) { $lonhttpd_port='8080'; }
1.574 albertel 9164: # IE doesn't like a secure page getting images from a non-secure
9165: # port (when logging we haven't parsed the browser type so default
9166: # back to secure
9167: if ((!exists($env{'browser.type'}) || $env{'browser.type'} eq 'explorer')
9168: && $ENV{'SERVER_PORT'} == 443) {
1.575 albertel 9169: return 443;
9170: }
9171: return $lonhttpd_port;
9172:
9173: }
9174:
9175: sub lonhttpdurl {
9176: my ($url)=@_;
9177:
9178: my $lonhttpd_port = &lonhttpd_port();
9179: if ($lonhttpd_port == 443) {
1.574 albertel 9180: return 'https://'.$ENV{'SERVER_NAME'}.$url;
9181: }
1.215 albertel 9182: return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
9183: }
9184:
1.213 albertel 9185: sub connection_aborted {
9186: my ($r)=@_;
9187: $r->print(" ");$r->rflush();
9188: my $c = $r->connection;
9189: return $c->aborted();
9190: }
9191:
1.221 foxr 9192: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 9193: # strings as 'strings'.
9194: sub escape_single {
1.221 foxr 9195: my ($input) = @_;
1.223 albertel 9196: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 9197: $input =~ s/\'/\\\'/g; # Esacpe the 's....
9198: return $input;
9199: }
1.223 albertel 9200:
1.222 foxr 9201: # Same as escape_single, but escape's "'s This
9202: # can be used for "strings"
9203: sub escape_double {
9204: my ($input) = @_;
9205: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
9206: $input =~ s/\"/\\\"/g; # Esacpe the "s....
9207: return $input;
9208: }
1.223 albertel 9209:
1.222 foxr 9210: # Escapes the last element of a full URL.
9211: sub escape_url {
9212: my ($url) = @_;
1.238 raeburn 9213: my @urlslices = split(/\//, $url,-1);
1.369 www 9214: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 9215: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 9216: }
1.462 albertel 9217:
9218: # -------------------------------------------------------- Initliaze user login
9219: sub init_user_environment {
1.463 albertel 9220: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 9221: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
9222:
9223: my $public=($username eq 'public' && $domain eq 'public');
9224:
9225: # See if old ID present, if so, remove
9226:
9227: my ($filename,$cookie,$userroles);
9228: my $now=time;
9229:
9230: if ($public) {
9231: my $max_public=100;
9232: my $oldest;
9233: my $oldest_time=0;
9234: for(my $next=1;$next<=$max_public;$next++) {
9235: if (-e $lonids."/publicuser_$next.id") {
9236: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
9237: if ($mtime<$oldest_time || !$oldest_time) {
9238: $oldest_time=$mtime;
9239: $oldest=$next;
9240: }
9241: } else {
9242: $cookie="publicuser_$next";
9243: last;
9244: }
9245: }
9246: if (!$cookie) { $cookie="publicuser_$oldest"; }
9247: } else {
1.463 albertel 9248: # if this isn't a robot, kill any existing non-robot sessions
9249: if (!$args->{'robot'}) {
9250: opendir(DIR,$lonids);
9251: while ($filename=readdir(DIR)) {
9252: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
9253: unlink($lonids.'/'.$filename);
9254: }
1.462 albertel 9255: }
1.463 albertel 9256: closedir(DIR);
1.462 albertel 9257: }
9258: # Give them a new cookie
1.463 albertel 9259: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
9260: : $now);
9261: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 9262:
9263: # Initialize roles
9264:
9265: $userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
9266: }
9267: # ------------------------------------ Check browser type and MathML capability
9268:
9269: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
9270: $clientunicode,$clientos) = &decode_user_agent($r);
9271:
9272: # -------------------------------------- Any accessibility options to remember?
9273: if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
9274: foreach my $option ('imagesuppress','appletsuppress',
9275: 'embedsuppress','fontenhance','blackwhite') {
9276: if ($form->{$option} eq 'true') {
9277: &Apache::lonnet::put('environment',{$option => 'on'},
9278: $domain,$username);
9279: } else {
9280: &Apache::lonnet::del('environment',[$option],
9281: $domain,$username);
9282: }
9283: }
9284: }
9285: # ------------------------------------------------------------- Get environment
9286:
9287: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
9288: my ($tmp) = keys(%userenv);
9289: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9290: # default remote control to off
9291: if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
9292: } else {
9293: undef(%userenv);
9294: }
9295: if (($userenv{'interface'}) && (!$form->{'interface'})) {
9296: $form->{'interface'}=$userenv{'interface'};
9297: }
9298: $env{'environment.remote'}=$userenv{'remote'};
9299: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
9300:
9301: # --------------- Do not trust query string to be put directly into environment
9302: foreach my $option ('imagesuppress','appletsuppress',
9303: 'embedsuppress','fontenhance','blackwhite',
9304: 'interface','localpath','localres') {
9305: $form->{$option}=~s/[\n\r\=]//gs;
9306: }
9307: # --------------------------------------------------------- Write first profile
9308:
9309: {
9310: my %initial_env =
9311: ("user.name" => $username,
9312: "user.domain" => $domain,
9313: "user.home" => $authhost,
9314: "browser.type" => $clientbrowser,
9315: "browser.version" => $clientversion,
9316: "browser.mathml" => $clientmathml,
9317: "browser.unicode" => $clientunicode,
9318: "browser.os" => $clientos,
9319: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
9320: "request.course.fn" => '',
9321: "request.course.uri" => '',
9322: "request.course.sec" => '',
9323: "request.role" => 'cm',
9324: "request.role.adv" => $env{'user.adv'},
9325: "request.host" => $ENV{'REMOTE_ADDR'},);
9326:
9327: if ($form->{'localpath'}) {
9328: $initial_env{"browser.localpath"} = $form->{'localpath'};
9329: $initial_env{"browser.localres"} = $form->{'localres'};
9330: }
9331:
9332: if ($public) {
9333: $initial_env{"environment.remote"} = "off";
9334: }
9335: if ($form->{'interface'}) {
9336: $form->{'interface'}=~s/\W//gs;
9337: $initial_env{"browser.interface"} = $form->{'interface'};
9338: $env{'browser.interface'}=$form->{'interface'};
9339: foreach my $option ('imagesuppress','appletsuppress',
9340: 'embedsuppress','fontenhance','blackwhite') {
9341: if (($form->{$option} eq 'true') ||
9342: ($userenv{$option} eq 'on')) {
9343: $initial_env{"browser.$option"} = "on";
9344: }
9345: }
9346: }
9347:
9348: $env{'user.environment'} = "$lonids/$cookie.id";
9349:
9350: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
9351: &GDBM_WRCREAT(),0640)) {
9352: &_add_to_env(\%disk_env,\%initial_env);
9353: &_add_to_env(\%disk_env,\%userenv,'environment.');
9354: &_add_to_env(\%disk_env,$userroles);
1.463 albertel 9355: if (ref($args->{'extra_env'})) {
9356: &_add_to_env(\%disk_env,$args->{'extra_env'});
9357: }
1.462 albertel 9358: untie(%disk_env);
9359: } else {
9360: &Apache::lonnet::logthis("<font color=\"blue\">WARNING: ".
9361: 'Could not create environment storage in lonauth: '.$!.'</font>');
9362: return 'error: '.$!;
9363: }
9364: }
9365: $env{'request.role'}='cm';
9366: $env{'request.role.adv'}=$env{'user.adv'};
9367: $env{'browser.type'}=$clientbrowser;
9368:
9369: return $cookie;
9370:
9371: }
9372:
9373: sub _add_to_env {
9374: my ($idf,$env_data,$prefix) = @_;
9375: while (my ($key,$value) = each(%$env_data)) {
9376: $idf->{$prefix.$key} = $value;
9377: $env{$prefix.$key} = $value;
9378: }
9379: }
9380:
9381:
1.41 ng 9382: =pod
9383:
9384: =back
9385:
1.112 bowersj2 9386: =cut
1.41 ng 9387:
1.112 bowersj2 9388: 1;
9389: __END__;
1.41 ng 9390:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>