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