Annotation of loncom/interface/loncommon.pm, revision 1.1117
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1117 ! raeburn 4: # $Id: loncommon.pm,v 1.1116 2013/03/01 04:48:59 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.479 albertel 72: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 73: use DateTime::TimeZone;
1.687 raeburn 74: use DateTime::Locale::Catalog;
1.1091 foxr 75: use Text::Aspell;
1.1094 raeburn 76: use Authen::Captcha;
77: use Captcha::reCAPTCHA;
1.117 www 78:
1.517 raeburn 79: # ---------------------------------------------- Designs
80: use vars qw(%defaultdesign);
81:
1.22 www 82: my $readit;
83:
1.517 raeburn 84:
1.157 matthew 85: ##
86: ## Global Variables
87: ##
1.46 matthew 88:
1.643 foxr 89:
90: # ----------------------------------------------- SSI with retries:
91: #
92:
93: =pod
94:
1.648 raeburn 95: =head1 Server Side include with retries:
1.643 foxr 96:
97: =over 4
98:
1.648 raeburn 99: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 100:
101: Performs an ssi with some number of retries. Retries continue either
102: until the result is ok or until the retry count supplied by the
103: caller is exhausted.
104:
105: Inputs:
1.648 raeburn 106:
107: =over 4
108:
1.643 foxr 109: resource - Identifies the resource to insert.
1.648 raeburn 110:
1.643 foxr 111: retries - Count of the number of retries allowed.
1.648 raeburn 112:
1.643 foxr 113: form - Hash that identifies the rendering options.
114:
1.648 raeburn 115: =back
116:
117: Returns:
118:
119: =over 4
120:
1.643 foxr 121: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 122:
1.643 foxr 123: response - The response from the last attempt (which may or may not have been successful.
124:
1.648 raeburn 125: =back
126:
127: =back
128:
1.643 foxr 129: =cut
130:
131: sub ssi_with_retries {
132: my ($resource, $retries, %form) = @_;
133:
134:
135: my $ok = 0; # True if we got a good response.
136: my $content;
137: my $response;
138:
139: # Try to get the ssi done. within the retries count:
140:
141: do {
142: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
143: $ok = $response->is_success;
1.650 www 144: if (!$ok) {
145: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
146: }
1.643 foxr 147: $retries--;
148: } while (!$ok && ($retries > 0));
149:
150: if (!$ok) {
151: $content = ''; # On error return an empty content.
152: }
153: return ($content, $response);
154:
155: }
156:
157:
158:
1.20 www 159: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 160: my %language;
1.124 www 161: my %supported_language;
1.1088 foxr 162: my %supported_codes;
1.1048 foxr 163: my %latex_language; # For choosing hyphenation in <transl..>
164: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 165: my %cprtag;
1.192 taceyjo1 166: my %scprtag;
1.351 www 167: my %fe; my %fd; my %fm;
1.41 ng 168: my %category_extensions;
1.12 harris41 169:
1.46 matthew 170: # ---------------------------------------------- Thesaurus variables
1.144 matthew 171: #
172: # %Keywords:
173: # A hash used by &keyword to determine if a word is considered a keyword.
174: # $thesaurus_db_file
175: # Scalar containing the full path to the thesaurus database.
1.46 matthew 176:
177: my %Keywords;
178: my $thesaurus_db_file;
179:
1.144 matthew 180: #
181: # Initialize values from language.tab, copyright.tab, filetypes.tab,
182: # thesaurus.tab, and filecategories.tab.
183: #
1.18 www 184: BEGIN {
1.46 matthew 185: # Variable initialization
186: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
187: #
1.22 www 188: unless ($readit) {
1.12 harris41 189: # ------------------------------------------------------------------- languages
190: {
1.158 raeburn 191: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
192: '/language.tab';
193: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 194: while (my $line = <$fh>) {
195: next if ($line=~/^\#/);
196: chomp($line);
1.1088 foxr 197: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 198: $language{$key}=$val.' - '.$enc;
199: if ($sup) {
200: $supported_language{$key}=$sup;
1.1088 foxr 201: $supported_codes{$key} = $code;
1.158 raeburn 202: }
1.1048 foxr 203: if ($latex) {
204: $latex_language_bykey{$key} = $latex;
1.1088 foxr 205: $latex_language{$code} = $latex;
1.1048 foxr 206: }
1.158 raeburn 207: }
208: close($fh);
209: }
1.12 harris41 210: }
211: # ------------------------------------------------------------------ copyrights
212: {
1.158 raeburn 213: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
214: '/copyright.tab';
215: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 216: while (my $line = <$fh>) {
217: next if ($line=~/^\#/);
218: chomp($line);
219: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 220: $cprtag{$key}=$val;
221: }
222: close($fh);
223: }
1.12 harris41 224: }
1.351 www 225: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 226: {
227: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
228: '/source_copyright.tab';
229: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 230: while (my $line = <$fh>) {
231: next if ($line =~ /^\#/);
232: chomp($line);
233: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 234: $scprtag{$key}=$val;
235: }
236: close($fh);
237: }
238: }
1.63 www 239:
1.517 raeburn 240: # -------------------------------------------------------------- default domain designs
1.63 www 241: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 242: my $designfile = $designdir.'/default.tab';
243: if ( open (my $fh,"<$designfile") ) {
244: while (my $line = <$fh>) {
245: next if ($line =~ /^\#/);
246: chomp($line);
247: my ($key,$val)=(split(/\=/,$line));
248: if ($val) { $defaultdesign{$key}=$val; }
249: }
250: close($fh);
1.63 www 251: }
252:
1.15 harris41 253: # ------------------------------------------------------------- file categories
254: {
1.158 raeburn 255: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
256: '/filecategories.tab';
257: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 258: while (my $line = <$fh>) {
259: next if ($line =~ /^\#/);
260: chomp($line);
261: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 262: push @{$category_extensions{lc($category)}},$extension;
263: }
264: close($fh);
265: }
266:
1.15 harris41 267: }
1.12 harris41 268: # ------------------------------------------------------------------ file types
269: {
1.158 raeburn 270: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
271: '/filetypes.tab';
272: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 273: while (my $line = <$fh>) {
274: next if ($line =~ /^\#/);
275: chomp($line);
276: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 277: if ($descr ne '') {
278: $fe{$ending}=lc($emb);
279: $fd{$ending}=$descr;
1.351 www 280: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 281: }
282: }
283: close($fh);
284: }
1.12 harris41 285: }
1.22 www 286: &Apache::lonnet::logthis(
1.705 tempelho 287: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 288: $readit=1;
1.46 matthew 289: } # end of unless($readit)
1.32 matthew 290:
291: }
1.112 bowersj2 292:
1.42 matthew 293: ###############################################################
294: ## HTML and Javascript Helper Functions ##
295: ###############################################################
296:
297: =pod
298:
1.112 bowersj2 299: =head1 HTML and Javascript Functions
1.42 matthew 300:
1.112 bowersj2 301: =over 4
302:
1.648 raeburn 303: =item * &browser_and_searcher_javascript()
1.112 bowersj2 304:
305: X<browsing, javascript>X<searching, javascript>Returns a string
306: containing javascript with two functions, C<openbrowser> and
307: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
308: tags.
1.42 matthew 309:
1.648 raeburn 310: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 311:
312: inputs: formname, elementname, only, omit
313:
314: formname and elementname indicate the name of the html form and name of
315: the element that the results of the browsing selection are to be placed in.
316:
317: Specifying 'only' will restrict the browser to displaying only files
1.185 www 318: with the given extension. Can be a comma separated list.
1.42 matthew 319:
320: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
1.648 raeburn 323: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 324:
325: Inputs: formname, elementname
326:
327: formname and elementname specify the name of the html form and the name
328: of the element the selection from the search results will be placed in.
1.542 raeburn 329:
1.42 matthew 330: =cut
331:
332: sub browser_and_searcher_javascript {
1.199 albertel 333: my ($mode)=@_;
334: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 335: my $resurl=&escape_single(&lastresurl());
1.42 matthew 336: return <<END;
1.219 albertel 337: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 338: var editbrowser = null;
1.135 albertel 339: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 340: var url = '$resurl/?';
1.42 matthew 341: if (editbrowser == null) {
342: url += 'launch=1&';
343: }
344: url += 'catalogmode=interactive&';
1.199 albertel 345: url += 'mode=$mode&';
1.611 albertel 346: url += 'inhibitmenu=yes&';
1.42 matthew 347: url += 'form=' + formname + '&';
348: if (only != null) {
349: url += 'only=' + only + '&';
1.217 albertel 350: } else {
351: url += 'only=&';
352: }
1.42 matthew 353: if (omit != null) {
354: url += 'omit=' + omit + '&';
1.217 albertel 355: } else {
356: url += 'omit=&';
357: }
1.135 albertel 358: if (titleelement != null) {
359: url += 'titleelement=' + titleelement + '&';
1.217 albertel 360: } else {
361: url += 'titleelement=&';
362: }
1.42 matthew 363: url += 'element=' + elementname + '';
364: var title = 'Browser';
1.435 albertel 365: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 366: options += ',width=700,height=600';
367: editbrowser = open(url,title,options,'1');
368: editbrowser.focus();
369: }
370: var editsearcher;
1.135 albertel 371: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 372: var url = '/adm/searchcat?';
373: if (editsearcher == null) {
374: url += 'launch=1&';
375: }
376: url += 'catalogmode=interactive&';
1.199 albertel 377: url += 'mode=$mode&';
1.42 matthew 378: url += 'form=' + formname + '&';
1.135 albertel 379: if (titleelement != null) {
380: url += 'titleelement=' + titleelement + '&';
1.217 albertel 381: } else {
382: url += 'titleelement=&';
383: }
1.42 matthew 384: url += 'element=' + elementname + '';
385: var title = 'Search';
1.435 albertel 386: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 387: options += ',width=700,height=600';
388: editsearcher = open(url,title,options,'1');
389: editsearcher.focus();
390: }
1.219 albertel 391: // END LON-CAPA Internal -->
1.42 matthew 392: END
1.170 www 393: }
394:
395: sub lastresurl {
1.258 albertel 396: if ($env{'environment.lastresurl'}) {
397: return $env{'environment.lastresurl'}
1.170 www 398: } else {
399: return '/res';
400: }
401: }
402:
403: sub storeresurl {
404: my $resurl=&Apache::lonnet::clutter(shift);
405: unless ($resurl=~/^\/res/) { return 0; }
406: $resurl=~s/\/$//;
407: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 408: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 409: return 1;
1.42 matthew 410: }
411:
1.74 www 412: sub studentbrowser_javascript {
1.111 www 413: unless (
1.258 albertel 414: (($env{'request.course.id'}) &&
1.302 albertel 415: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
416: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
417: '/'.$env{'request.course.sec'})
418: ))
1.258 albertel 419: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 420: ) { return ''; }
1.74 www 421: return (<<'ENDSTDBRW');
1.776 bisitz 422: <script type="text/javascript" language="Javascript">
1.824 bisitz 423: // <![CDATA[
1.74 www 424: var stdeditbrowser;
1.999 www 425: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 426: var url = '/adm/pickstudent?';
427: var filter;
1.558 albertel 428: if (!ignorefilter) {
429: eval('filter=document.'+formname+'.'+uname+'.value;');
430: }
1.74 www 431: if (filter != null) {
432: if (filter != '') {
433: url += 'filter='+filter+'&';
434: }
435: }
436: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 437: '&udomelement='+udom+
438: '&clicker='+clicker;
1.111 www 439: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 440: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 441: var title = 'Student_Browser';
1.74 www 442: var options = 'scrollbars=1,resizable=1,menubar=0';
443: options += ',width=700,height=600';
444: stdeditbrowser = open(url,title,options,'1');
445: stdeditbrowser.focus();
446: }
1.824 bisitz 447: // ]]>
1.74 www 448: </script>
449: ENDSTDBRW
450: }
1.42 matthew 451:
1.1003 www 452: sub resourcebrowser_javascript {
453: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 454: return (<<'ENDRESBRW');
1.1003 www 455: <script type="text/javascript" language="Javascript">
456: // <![CDATA[
457: var reseditbrowser;
1.1004 www 458: function openresbrowser(formname,reslink) {
1.1005 www 459: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 460: var title = 'Resource_Browser';
461: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 462: options += ',width=700,height=500';
1.1004 www 463: reseditbrowser = open(url,title,options,'1');
464: reseditbrowser.focus();
1.1003 www 465: }
466: // ]]>
467: </script>
1.1004 www 468: ENDRESBRW
1.1003 www 469: }
470:
1.74 www 471: sub selectstudent_link {
1.999 www 472: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
473: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
474: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
475: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 476: if ($env{'request.course.id'}) {
1.302 albertel 477: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
478: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
479: '/'.$env{'request.course.sec'})) {
1.111 www 480: return '';
481: }
1.999 www 482: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 483: if ($courseadvonly) {
484: $callargs .= ",'',1,1";
485: }
486: return '<span class="LC_nobreak">'.
487: '<a href="javascript:openstdbrowser('.$callargs.');">'.
488: &mt('Select User').'</a></span>';
1.74 www 489: }
1.258 albertel 490: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 491: $callargs .= ",'',1";
1.793 raeburn 492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openstdbrowser('.$callargs.');">'.
494: &mt('Select User').'</a></span>';
1.111 www 495: }
496: return '';
1.91 www 497: }
498:
1.1004 www 499: sub selectresource_link {
500: my ($form,$reslink,$arg)=@_;
501:
502: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
503: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
504: unless ($env{'request.course.id'}) { return $arg; }
505: return '<span class="LC_nobreak">'.
506: '<a href="javascript:openresbrowser('.$callargs.');">'.
507: $arg.'</a></span>';
508: }
509:
510:
511:
1.653 raeburn 512: sub authorbrowser_javascript {
513: return <<"ENDAUTHORBRW";
1.776 bisitz 514: <script type="text/javascript" language="JavaScript">
1.824 bisitz 515: // <![CDATA[
1.653 raeburn 516: var stdeditbrowser;
517:
518: function openauthorbrowser(formname,udom) {
519: var url = '/adm/pickauthor?';
520: url += 'form='+formname+'&roledom='+udom;
521: var title = 'Author_Browser';
522: var options = 'scrollbars=1,resizable=1,menubar=0';
523: options += ',width=700,height=600';
524: stdeditbrowser = open(url,title,options,'1');
525: stdeditbrowser.focus();
526: }
527:
1.824 bisitz 528: // ]]>
1.653 raeburn 529: </script>
530: ENDAUTHORBRW
531: }
532:
1.91 www 533: sub coursebrowser_javascript {
1.1116 raeburn 534: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
535: $credits_element) = @_;
1.932 raeburn 536: my $wintitle = 'Course_Browser';
1.931 raeburn 537: if ($crstype eq 'Community') {
1.932 raeburn 538: $wintitle = 'Community_Browser';
1.909 raeburn 539: }
1.876 raeburn 540: my $id_functions = &javascript_index_functions();
541: my $output = '
1.776 bisitz 542: <script type="text/javascript" language="JavaScript">
1.824 bisitz 543: // <![CDATA[
1.468 raeburn 544: var stdeditbrowser;'."\n";
1.876 raeburn 545:
546: $output .= <<"ENDSTDBRW";
1.909 raeburn 547: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 548: var url = '/adm/pickcourse?';
1.895 raeburn 549: var formid = getFormIdByName(formname);
1.876 raeburn 550: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 551: if (domainfilter != null) {
552: if (domainfilter != '') {
553: url += 'domainfilter='+domainfilter+'&';
554: }
555: }
1.91 www 556: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 557: '&cdomelement='+udom+
558: '&cnameelement='+desc;
1.468 raeburn 559: if (extra_element !=null && extra_element != '') {
1.594 raeburn 560: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 561: url += '&roleelement='+extra_element;
562: if (domainfilter == null || domainfilter == '') {
563: url += '&domainfilter='+extra_element;
564: }
1.234 raeburn 565: }
1.468 raeburn 566: else {
567: if (formname == 'portform') {
568: url += '&setroles='+extra_element;
1.800 raeburn 569: } else {
570: if (formname == 'rules') {
571: url += '&fixeddom='+extra_element;
572: }
1.468 raeburn 573: }
574: }
1.230 raeburn 575: }
1.909 raeburn 576: if (type != null && type != '') {
577: url += '&type='+type;
578: }
579: if (type_elem != null && type_elem != '') {
580: url += '&typeelement='+type_elem;
581: }
1.872 raeburn 582: if (formname == 'ccrs') {
583: var ownername = document.forms[formid].ccuname.value;
584: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
585: url += '&cloner='+ownername+':'+ownerdom;
586: }
1.293 raeburn 587: if (multflag !=null && multflag != '') {
588: url += '&multiple='+multflag;
589: }
1.909 raeburn 590: var title = '$wintitle';
1.91 www 591: var options = 'scrollbars=1,resizable=1,menubar=0';
592: options += ',width=700,height=600';
593: stdeditbrowser = open(url,title,options,'1');
594: stdeditbrowser.focus();
595: }
1.876 raeburn 596: $id_functions
597: ENDSTDBRW
1.1116 raeburn 598: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
599: $output .= &setsec_javascript($sec_element,$formname,$role_element,
600: $credits_element);
1.876 raeburn 601: }
602: $output .= '
603: // ]]>
604: </script>';
605: return $output;
606: }
607:
608: sub javascript_index_functions {
609: return <<"ENDJS";
610:
611: function getFormIdByName(formname) {
612: for (var i=0;i<document.forms.length;i++) {
613: if (document.forms[i].name == formname) {
614: return i;
615: }
616: }
617: return -1;
618: }
619:
620: function getIndexByName(formid,item) {
621: for (var i=0;i<document.forms[formid].elements.length;i++) {
622: if (document.forms[formid].elements[i].name == item) {
623: return i;
624: }
625: }
626: return -1;
627: }
1.468 raeburn 628:
1.876 raeburn 629: function getDomainFromSelectbox(formname,udom) {
630: var userdom;
631: var formid = getFormIdByName(formname);
632: if (formid > -1) {
633: var domid = getIndexByName(formid,udom);
634: if (domid > -1) {
635: if (document.forms[formid].elements[domid].type == 'select-one') {
636: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
637: }
638: if (document.forms[formid].elements[domid].type == 'hidden') {
639: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 640: }
641: }
642: }
1.876 raeburn 643: return userdom;
644: }
645:
646: ENDJS
1.468 raeburn 647:
1.876 raeburn 648: }
649:
1.1017 raeburn 650: sub javascript_array_indexof {
1.1018 raeburn 651: return <<ENDJS;
1.1017 raeburn 652: <script type="text/javascript" language="JavaScript">
653: // <![CDATA[
654:
655: if (!Array.prototype.indexOf) {
656: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
657: "use strict";
658: if (this === void 0 || this === null) {
659: throw new TypeError();
660: }
661: var t = Object(this);
662: var len = t.length >>> 0;
663: if (len === 0) {
664: return -1;
665: }
666: var n = 0;
667: if (arguments.length > 0) {
668: n = Number(arguments[1]);
1.1088 foxr 669: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 670: n = 0;
671: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
672: n = (n > 0 || -1) * Math.floor(Math.abs(n));
673: }
674: }
675: if (n >= len) {
676: return -1;
677: }
678: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
679: for (; k < len; k++) {
680: if (k in t && t[k] === searchElement) {
681: return k;
682: }
683: }
684: return -1;
685: }
686: }
687:
688: // ]]>
689: </script>
690:
691: ENDJS
692:
693: }
694:
1.876 raeburn 695: sub userbrowser_javascript {
696: my $id_functions = &javascript_index_functions();
697: return <<"ENDUSERBRW";
698:
1.888 raeburn 699: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 700: var url = '/adm/pickuser?';
701: var userdom = getDomainFromSelectbox(formname,udom);
702: if (userdom != null) {
703: if (userdom != '') {
704: url += 'srchdom='+userdom+'&';
705: }
706: }
707: url += 'form=' + formname + '&unameelement='+uname+
708: '&udomelement='+udom+
709: '&ulastelement='+ulast+
710: '&ufirstelement='+ufirst+
711: '&uemailelement='+uemail+
1.881 raeburn 712: '&hideudomelement='+hideudom+
713: '&coursedom='+crsdom;
1.888 raeburn 714: if ((caller != null) && (caller != undefined)) {
715: url += '&caller='+caller;
716: }
1.876 raeburn 717: var title = 'User_Browser';
718: var options = 'scrollbars=1,resizable=1,menubar=0';
719: options += ',width=700,height=600';
720: var stdeditbrowser = open(url,title,options,'1');
721: stdeditbrowser.focus();
722: }
723:
1.888 raeburn 724: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 725: var formid = getFormIdByName(formname);
726: if (formid > -1) {
1.888 raeburn 727: var unameid = getIndexByName(formid,uname);
1.876 raeburn 728: var domid = getIndexByName(formid,udom);
729: var hidedomid = getIndexByName(formid,origdom);
730: if (hidedomid > -1) {
731: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 732: var unameval = document.forms[formid].elements[unameid].value;
733: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
734: if (domid > -1) {
735: var slct = document.forms[formid].elements[domid];
736: if (slct.type == 'select-one') {
737: var i;
738: for (i=0;i<slct.length;i++) {
739: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
740: }
741: }
742: if (slct.type == 'hidden') {
743: slct.value = fixeddom;
1.876 raeburn 744: }
745: }
1.468 raeburn 746: }
747: }
748: }
1.876 raeburn 749: return;
750: }
751:
752: $id_functions
753: ENDUSERBRW
1.468 raeburn 754: }
755:
756: sub setsec_javascript {
1.1116 raeburn 757: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 758: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
759: $communityrolestr);
760: if ($role_element ne '') {
761: my @allroles = ('st','ta','ep','in','ad');
762: foreach my $crstype ('Course','Community') {
763: if ($crstype eq 'Community') {
764: foreach my $role (@allroles) {
765: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
766: }
767: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
768: } else {
769: foreach my $role (@allroles) {
770: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
771: }
772: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
773: }
774: }
775: $rolestr = '"'.join('","',@allroles).'"';
776: $courserolestr = '"'.join('","',@courserolenames).'"';
777: $communityrolestr = '"'.join('","',@communityrolenames).'"';
778: }
1.468 raeburn 779: my $setsections = qq|
780: function setSect(sectionlist) {
1.629 raeburn 781: var sectionsArray = new Array();
782: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
783: sectionsArray = sectionlist.split(",");
784: }
1.468 raeburn 785: var numSections = sectionsArray.length;
786: document.$formname.$sec_element.length = 0;
787: if (numSections == 0) {
788: document.$formname.$sec_element.multiple=false;
789: document.$formname.$sec_element.size=1;
790: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
791: } else {
792: if (numSections == 1) {
793: document.$formname.$sec_element.multiple=false;
794: document.$formname.$sec_element.size=1;
795: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
796: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
797: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
798: } else {
799: for (var i=0; i<numSections; i++) {
800: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
801: }
802: document.$formname.$sec_element.multiple=true
803: if (numSections < 3) {
804: document.$formname.$sec_element.size=numSections;
805: } else {
806: document.$formname.$sec_element.size=3;
807: }
808: document.$formname.$sec_element.options[0].selected = false
809: }
810: }
1.91 www 811: }
1.905 raeburn 812:
813: function setRole(crstype) {
1.468 raeburn 814: |;
1.905 raeburn 815: if ($role_element eq '') {
816: $setsections .= ' return;
817: }
818: ';
819: } else {
820: $setsections .= qq|
821: var elementLength = document.$formname.$role_element.length;
822: var allroles = Array($rolestr);
823: var courserolenames = Array($courserolestr);
824: var communityrolenames = Array($communityrolestr);
825: if (elementLength != undefined) {
826: if (document.$formname.$role_element.options[5].value == 'cc') {
827: if (crstype == 'Course') {
828: return;
829: } else {
830: allroles[5] = 'co';
831: for (var i=0; i<6; i++) {
832: document.$formname.$role_element.options[i].value = allroles[i];
833: document.$formname.$role_element.options[i].text = communityrolenames[i];
834: }
835: }
836: } else {
837: if (crstype == 'Community') {
838: return;
839: } else {
840: allroles[5] = 'cc';
841: for (var i=0; i<6; i++) {
842: document.$formname.$role_element.options[i].value = allroles[i];
843: document.$formname.$role_element.options[i].text = courserolenames[i];
844: }
845: }
846: }
847: }
848: return;
849: }
850: |;
851: }
1.1116 raeburn 852: if ($credits_element) {
853: $setsections .= qq|
854: function setCredits(defaultcredits) {
855: document.$formname.$credits_element.value = defaultcredits;
856: return;
857: }
858: |;
859: }
1.468 raeburn 860: return $setsections;
861: }
862:
1.91 www 863: sub selectcourse_link {
1.909 raeburn 864: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
865: $typeelement) = @_;
866: my $type = $selecttype;
1.871 raeburn 867: my $linktext = &mt('Select Course');
868: if ($selecttype eq 'Community') {
1.909 raeburn 869: $linktext = &mt('Select Community');
1.906 raeburn 870: } elsif ($selecttype eq 'Course/Community') {
871: $linktext = &mt('Select Course/Community');
1.909 raeburn 872: $type = '';
1.1019 raeburn 873: } elsif ($selecttype eq 'Select') {
874: $linktext = &mt('Select');
875: $type = '';
1.871 raeburn 876: }
1.787 bisitz 877: return '<span class="LC_nobreak">'
878: ."<a href='"
879: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
880: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 881: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 882: ."'>".$linktext.'</a>'
1.787 bisitz 883: .'</span>';
1.74 www 884: }
1.42 matthew 885:
1.653 raeburn 886: sub selectauthor_link {
887: my ($form,$udom)=@_;
888: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
889: &mt('Select Author').'</a>';
890: }
891:
1.876 raeburn 892: sub selectuser_link {
1.881 raeburn 893: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 894: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 895: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 896: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 897: ');">'.$linktext.'</a>';
1.876 raeburn 898: }
899:
1.273 raeburn 900: sub check_uncheck_jscript {
901: my $jscript = <<"ENDSCRT";
902: function checkAll(field) {
903: if (field.length > 0) {
904: for (i = 0; i < field.length; i++) {
1.1093 raeburn 905: if (!field[i].disabled) {
906: field[i].checked = true;
907: }
1.273 raeburn 908: }
909: } else {
1.1093 raeburn 910: if (!field.disabled) {
911: field.checked = true;
912: }
1.273 raeburn 913: }
914: }
915:
916: function uncheckAll(field) {
917: if (field.length > 0) {
918: for (i = 0; i < field.length; i++) {
919: field[i].checked = false ;
1.543 albertel 920: }
921: } else {
1.273 raeburn 922: field.checked = false ;
923: }
924: }
925: ENDSCRT
926: return $jscript;
927: }
928:
1.656 www 929: sub select_timezone {
1.659 raeburn 930: my ($name,$selected,$onchange,$includeempty)=@_;
931: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
932: if ($includeempty) {
933: $output .= '<option value=""';
934: if (($selected eq '') || ($selected eq 'local')) {
935: $output .= ' selected="selected" ';
936: }
937: $output .= '> </option>';
938: }
1.657 raeburn 939: my @timezones = DateTime::TimeZone->all_names;
940: foreach my $tzone (@timezones) {
941: $output.= '<option value="'.$tzone.'"';
942: if ($tzone eq $selected) {
943: $output.=' selected="selected"';
944: }
945: $output.=">$tzone</option>\n";
1.656 www 946: }
947: $output.="</select>";
948: return $output;
949: }
1.273 raeburn 950:
1.687 raeburn 951: sub select_datelocale {
952: my ($name,$selected,$onchange,$includeempty)=@_;
953: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
954: if ($includeempty) {
955: $output .= '<option value=""';
956: if ($selected eq '') {
957: $output .= ' selected="selected" ';
958: }
959: $output .= '> </option>';
960: }
961: my (@possibles,%locale_names);
962: my @locales = DateTime::Locale::Catalog::Locales;
963: foreach my $locale (@locales) {
964: if (ref($locale) eq 'HASH') {
965: my $id = $locale->{'id'};
966: if ($id ne '') {
967: my $en_terr = $locale->{'en_territory'};
968: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 969: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 970: if (grep(/^en$/,@languages) || !@languages) {
971: if ($en_terr ne '') {
972: $locale_names{$id} = '('.$en_terr.')';
973: } elsif ($native_terr ne '') {
974: $locale_names{$id} = $native_terr;
975: }
976: } else {
977: if ($native_terr ne '') {
978: $locale_names{$id} = $native_terr.' ';
979: } elsif ($en_terr ne '') {
980: $locale_names{$id} = '('.$en_terr.')';
981: }
982: }
983: push (@possibles,$id);
984: }
985: }
986: }
987: foreach my $item (sort(@possibles)) {
988: $output.= '<option value="'.$item.'"';
989: if ($item eq $selected) {
990: $output.=' selected="selected"';
991: }
992: $output.=">$item";
993: if ($locale_names{$item} ne '') {
994: $output.=" $locale_names{$item}</option>\n";
995: }
996: $output.="</option>\n";
997: }
998: $output.="</select>";
999: return $output;
1000: }
1001:
1.792 raeburn 1002: sub select_language {
1003: my ($name,$selected,$includeempty) = @_;
1004: my %langchoices;
1005: if ($includeempty) {
1.1117 ! raeburn 1006: %langchoices = ('' => 'No language preference');
1.792 raeburn 1007: }
1008: foreach my $id (&languageids()) {
1009: my $code = &supportedlanguagecode($id);
1010: if ($code) {
1011: $langchoices{$code} = &plainlanguagedescription($id);
1012: }
1013: }
1.1117 ! raeburn 1014: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1015: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1016: }
1017:
1.42 matthew 1018: =pod
1.36 matthew 1019:
1.1088 foxr 1020:
1021: =item * &list_languages()
1022:
1023: Returns an array reference that is suitable for use in language prompters.
1024: Each array element is itself a two element array. The first element
1025: is the language code. The second element a descsriptiuon of the
1026: language itself. This is suitable for use in e.g.
1027: &Apache::edit::select_arg (once dereferenced that is).
1028:
1029: =cut
1030:
1031: sub list_languages {
1032: my @lang_choices;
1033:
1034: foreach my $id (&languageids()) {
1035: my $code = &supportedlanguagecode($id);
1036: if ($code) {
1037: my $selector = $supported_codes{$id};
1038: my $description = &plainlanguagedescription($id);
1039: push (@lang_choices, [$selector, $description]);
1040: }
1041: }
1042: return \@lang_choices;
1043: }
1044:
1045: =pod
1046:
1.648 raeburn 1047: =item * &linked_select_forms(...)
1.36 matthew 1048:
1049: linked_select_forms returns a string containing a <script></script> block
1050: and html for two <select> menus. The select menus will be linked in that
1051: changing the value of the first menu will result in new values being placed
1052: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1053: order unless a defined order is provided.
1.36 matthew 1054:
1055: linked_select_forms takes the following ordered inputs:
1056:
1057: =over 4
1058:
1.112 bowersj2 1059: =item * $formname, the name of the <form> tag
1.36 matthew 1060:
1.112 bowersj2 1061: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1062:
1.112 bowersj2 1063: =item * $firstdefault, the default value for the first menu
1.36 matthew 1064:
1.112 bowersj2 1065: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1066:
1.112 bowersj2 1067: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1068:
1.112 bowersj2 1069: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1070:
1.609 raeburn 1071: =item * $menuorder, the order of values in the first menu
1072:
1.1115 raeburn 1073: =item * $onchangefirst, additional javascript call to execute for an onchange
1074: event for the first <select> tag
1075:
1076: =item * $onchangesecond, additional javascript call to execute for an onchange
1077: event for the second <select> tag
1078:
1.41 ng 1079: =back
1080:
1.36 matthew 1081: Below is an example of such a hash. Only the 'text', 'default', and
1082: 'select2' keys must appear as stated. keys(%menu) are the possible
1083: values for the first select menu. The text that coincides with the
1.41 ng 1084: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1085: and text for the second menu are given in the hash pointed to by
1086: $menu{$choice1}->{'select2'}.
1087:
1.112 bowersj2 1088: my %menu = ( A1 => { text =>"Choice A1" ,
1089: default => "B3",
1090: select2 => {
1091: B1 => "Choice B1",
1092: B2 => "Choice B2",
1093: B3 => "Choice B3",
1094: B4 => "Choice B4"
1.609 raeburn 1095: },
1096: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1097: },
1098: A2 => { text =>"Choice A2" ,
1099: default => "C2",
1100: select2 => {
1101: C1 => "Choice C1",
1102: C2 => "Choice C2",
1103: C3 => "Choice C3"
1.609 raeburn 1104: },
1105: order => ['C2','C1','C3'],
1.112 bowersj2 1106: },
1107: A3 => { text =>"Choice A3" ,
1108: default => "D6",
1109: select2 => {
1110: D1 => "Choice D1",
1111: D2 => "Choice D2",
1112: D3 => "Choice D3",
1113: D4 => "Choice D4",
1114: D5 => "Choice D5",
1115: D6 => "Choice D6",
1116: D7 => "Choice D7"
1.609 raeburn 1117: },
1118: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1119: }
1120: );
1.36 matthew 1121:
1122: =cut
1123:
1124: sub linked_select_forms {
1125: my ($formname,
1126: $middletext,
1127: $firstdefault,
1128: $firstselectname,
1129: $secondselectname,
1.609 raeburn 1130: $hashref,
1131: $menuorder,
1.1115 raeburn 1132: $onchangefirst,
1133: $onchangesecond
1.36 matthew 1134: ) = @_;
1135: my $second = "document.$formname.$secondselectname";
1136: my $first = "document.$formname.$firstselectname";
1137: # output the javascript to do the changing
1138: my $result = '';
1.776 bisitz 1139: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1140: $result.="// <![CDATA[\n";
1.36 matthew 1141: $result.="var select2data = new Object();\n";
1142: $" = '","';
1143: my $debug = '';
1144: foreach my $s1 (sort(keys(%$hashref))) {
1145: $result.="select2data.d_$s1 = new Object();\n";
1146: $result.="select2data.d_$s1.def = new String('".
1147: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1148: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1149: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1150: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1151: @s2values = @{$hashref->{$s1}->{'order'}};
1152: }
1.36 matthew 1153: $result.="\"@s2values\");\n";
1154: $result.="select2data.d_$s1.texts = new Array(";
1155: my @s2texts;
1156: foreach my $value (@s2values) {
1157: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1158: }
1159: $result.="\"@s2texts\");\n";
1160: }
1161: $"=' ';
1162: $result.= <<"END";
1163:
1164: function select1_changed() {
1165: // Determine new choice
1166: var newvalue = "d_" + $first.value;
1167: // update select2
1168: var values = select2data[newvalue].values;
1169: var texts = select2data[newvalue].texts;
1170: var select2def = select2data[newvalue].def;
1171: var i;
1172: // out with the old
1173: for (i = 0; i < $second.options.length; i++) {
1174: $second.options[i] = null;
1175: }
1176: // in with the nuclear
1177: for (i=0;i<values.length; i++) {
1178: $second.options[i] = new Option(values[i]);
1.143 matthew 1179: $second.options[i].value = values[i];
1.36 matthew 1180: $second.options[i].text = texts[i];
1181: if (values[i] == select2def) {
1182: $second.options[i].selected = true;
1183: }
1184: }
1185: }
1.824 bisitz 1186: // ]]>
1.36 matthew 1187: </script>
1188: END
1189: # output the initial values for the selection lists
1.1115 raeburn 1190: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1191: my @order = sort(keys(%{$hashref}));
1192: if (ref($menuorder) eq 'ARRAY') {
1193: @order = @{$menuorder};
1194: }
1195: foreach my $value (@order) {
1.36 matthew 1196: $result.=" <option value=\"$value\" ";
1.253 albertel 1197: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1198: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1199: }
1200: $result .= "</select>\n";
1201: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1202: $result .= $middletext;
1.1115 raeburn 1203: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1204: if ($onchangesecond) {
1205: $result .= ' onchange="'.$onchangesecond.'"';
1206: }
1207: $result .= ">\n";
1.36 matthew 1208: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1209:
1210: my @secondorder = sort(keys(%select2));
1211: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1212: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1213: }
1214: foreach my $value (@secondorder) {
1.36 matthew 1215: $result.=" <option value=\"$value\" ";
1.253 albertel 1216: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1217: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1218: }
1219: $result .= "</select>\n";
1220: # return $debug;
1221: return $result;
1222: } # end of sub linked_select_forms {
1223:
1.45 matthew 1224: =pod
1.44 bowersj2 1225:
1.973 raeburn 1226: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1227:
1.112 bowersj2 1228: Returns a string corresponding to an HTML link to the given help
1229: $topic, where $topic corresponds to the name of a .tex file in
1230: /home/httpd/html/adm/help/tex, with underscores replaced by
1231: spaces.
1232:
1233: $text will optionally be linked to the same topic, allowing you to
1234: link text in addition to the graphic. If you do not want to link
1235: text, but wish to specify one of the later parameters, pass an
1236: empty string.
1237:
1238: $stayOnPage is a value that will be interpreted as a boolean. If true,
1239: the link will not open a new window. If false, the link will open
1240: a new window using Javascript. (Default is false.)
1241:
1242: $width and $height are optional numerical parameters that will
1243: override the width and height of the popped up window, which may
1.973 raeburn 1244: be useful for certain help topics with big pictures included.
1245:
1246: $imgid is the id of the img tag used for the help icon. This may be
1247: used in a javascript call to switch the image src. See
1248: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1249:
1250: =cut
1251:
1252: sub help_open_topic {
1.973 raeburn 1253: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1254: $text = "" if (not defined $text);
1.44 bowersj2 1255: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1256: $width = 500 if (not defined $width);
1.44 bowersj2 1257: $height = 400 if (not defined $height);
1258: my $filename = $topic;
1259: $filename =~ s/ /_/g;
1260:
1.48 bowersj2 1261: my $template = "";
1262: my $link;
1.572 banghart 1263:
1.159 www 1264: $topic=~s/\W/\_/g;
1.44 bowersj2 1265:
1.572 banghart 1266: if (!$stayOnPage) {
1.1033 www 1267: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1268: } elsif ($stayOnPage eq 'popup') {
1269: $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 1270: } else {
1.48 bowersj2 1271: $link = "/adm/help/${filename}.hlp";
1272: }
1273:
1274: # Add the text
1.755 neumanie 1275: if ($text ne "") {
1.763 bisitz 1276: $template.='<span class="LC_help_open_topic">'
1277: .'<a target="_top" href="'.$link.'">'
1278: .$text.'</a>';
1.48 bowersj2 1279: }
1280:
1.763 bisitz 1281: # (Always) Add the graphic
1.179 matthew 1282: my $title = &mt('Online Help');
1.667 raeburn 1283: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1284: if ($imgid ne '') {
1285: $imgid = ' id="'.$imgid.'"';
1286: }
1.763 bisitz 1287: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1288: .'<img src="'.$helpicon.'" border="0"'
1289: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1290: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1291: .' /></a>';
1292: if ($text ne "") {
1293: $template.='</span>';
1294: }
1.44 bowersj2 1295: return $template;
1296:
1.106 bowersj2 1297: }
1298:
1299: # This is a quicky function for Latex cheatsheet editing, since it
1300: # appears in at least four places
1301: sub helpLatexCheatsheet {
1.1037 www 1302: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1303: my $out;
1.106 bowersj2 1304: my $addOther = '';
1.732 raeburn 1305: if ($topic) {
1.1037 www 1306: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1307: }
1308: $out = '<span>' # Start cheatsheet
1309: .$addOther
1310: .'<span>'
1.1037 www 1311: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1312: .'</span> <span>'
1.1037 www 1313: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1314: .'</span>';
1.732 raeburn 1315: unless ($not_author) {
1.763 bisitz 1316: $out .= ' <span>'
1.1037 www 1317: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763 bisitz 1318: .'</span>';
1.732 raeburn 1319: }
1.763 bisitz 1320: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1321: return $out;
1.172 www 1322: }
1323:
1.430 albertel 1324: sub general_help {
1325: my $helptopic='Student_Intro';
1326: if ($env{'request.role'}=~/^(ca|au)/) {
1327: $helptopic='Authoring_Intro';
1.907 raeburn 1328: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1329: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1330: } elsif ($env{'request.role'}=~/^dc/) {
1331: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1332: }
1333: return $helptopic;
1334: }
1335:
1336: sub update_help_link {
1337: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1338: my $origurl = $ENV{'REQUEST_URI'};
1339: $origurl=~s|^/~|/priv/|;
1340: my $timestamp = time;
1341: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1342: $$datum = &escape($$datum);
1343: }
1344:
1345: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1346: my $output .= <<"ENDOUTPUT";
1347: <script type="text/javascript">
1.824 bisitz 1348: // <![CDATA[
1.430 albertel 1349: banner_link = '$banner_link';
1.824 bisitz 1350: // ]]>
1.430 albertel 1351: </script>
1352: ENDOUTPUT
1353: return $output;
1354: }
1355:
1356: # now just updates the help link and generates a blue icon
1.193 raeburn 1357: sub help_open_menu {
1.430 albertel 1358: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1359: = @_;
1.949 droeschl 1360: $stayOnPage = 1;
1.430 albertel 1361: my $output;
1362: if ($component_help) {
1363: if (!$text) {
1364: $output=&help_open_topic($component_help,undef,$stayOnPage,
1365: $width,$height);
1366: } else {
1367: my $help_text;
1368: $help_text=&unescape($topic);
1369: $output='<table><tr><td>'.
1370: &help_open_topic($component_help,$help_text,$stayOnPage,
1371: $width,$height).'</td></tr></table>';
1372: }
1373: }
1374: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1375: return $output.$banner_link;
1376: }
1377:
1378: sub top_nav_help {
1379: my ($text) = @_;
1.436 albertel 1380: $text = &mt($text);
1.949 droeschl 1381: my $stay_on_page = 1;
1382:
1.572 banghart 1383: my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436 albertel 1384: : "javascript:helpMenu('open')";
1.572 banghart 1385: my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436 albertel 1386:
1.201 raeburn 1387: my $title = &mt('Get help');
1.436 albertel 1388:
1389: return <<"END";
1390: $banner_link
1391: <a href="$link" title="$title">$text</a>
1392: END
1393: }
1394:
1395: sub help_menu_js {
1396: my ($text) = @_;
1.949 droeschl 1397: my $stayOnPage = 1;
1.436 albertel 1398: my $width = 620;
1399: my $height = 600;
1.430 albertel 1400: my $helptopic=&general_help();
1401: my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1402: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1403: my $start_page =
1404: &Apache::loncommon::start_page('Help Menu', undef,
1405: {'frameset' => 1,
1406: 'js_ready' => 1,
1407: 'add_entries' => {
1408: 'border' => '0',
1.579 raeburn 1409: 'rows' => "110,*",},});
1.331 albertel 1410: my $end_page =
1411: &Apache::loncommon::end_page({'frameset' => 1,
1412: 'js_ready' => 1,});
1413:
1.436 albertel 1414: my $template .= <<"ENDTEMPLATE";
1415: <script type="text/javascript">
1.877 bisitz 1416: // <![CDATA[
1.253 albertel 1417: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1418: var banner_link = '';
1.243 raeburn 1419: function helpMenu(target) {
1420: var caller = this;
1421: if (target == 'open') {
1422: var newWindow = null;
1423: try {
1.262 albertel 1424: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1425: }
1426: catch(error) {
1427: writeHelp(caller);
1428: return;
1429: }
1430: if (newWindow) {
1431: caller = newWindow;
1432: }
1.193 raeburn 1433: }
1.243 raeburn 1434: writeHelp(caller);
1435: return;
1436: }
1437: function writeHelp(caller) {
1.1072 raeburn 1438: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243 raeburn 1439: caller.document.close()
1440: caller.focus()
1.193 raeburn 1441: }
1.877 bisitz 1442: // END LON-CAPA Internal -->
1.253 albertel 1443: // ]]>
1.436 albertel 1444: </script>
1.193 raeburn 1445: ENDTEMPLATE
1446: return $template;
1447: }
1448:
1.172 www 1449: sub help_open_bug {
1450: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1451: unless ($env{'user.adv'}) { return ''; }
1.172 www 1452: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1453: $text = "" if (not defined $text);
1454: $stayOnPage=1;
1.184 albertel 1455: $width = 600 if (not defined $width);
1456: $height = 600 if (not defined $height);
1.172 www 1457:
1458: $topic=~s/\W+/\+/g;
1459: my $link='';
1460: my $template='';
1.379 albertel 1461: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1462: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1463: if (!$stayOnPage)
1464: {
1465: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1466: }
1467: else
1468: {
1469: $link = $url;
1470: }
1471: # Add the text
1472: if ($text ne "")
1473: {
1474: $template .=
1475: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1476: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1477: }
1478:
1479: # Add the graphic
1.179 matthew 1480: my $title = &mt('Report a Bug');
1.215 albertel 1481: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1482: $template .= <<"ENDTEMPLATE";
1.436 albertel 1483: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1484: ENDTEMPLATE
1485: if ($text ne '') { $template.='</td></tr></table>' };
1486: return $template;
1487:
1488: }
1489:
1490: sub help_open_faq {
1491: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1492: unless ($env{'user.adv'}) { return ''; }
1.172 www 1493: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1494: $text = "" if (not defined $text);
1495: $stayOnPage=1;
1496: $width = 350 if (not defined $width);
1497: $height = 400 if (not defined $height);
1498:
1499: $topic=~s/\W+/\+/g;
1500: my $link='';
1501: my $template='';
1502: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1503: if (!$stayOnPage)
1504: {
1505: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1506: }
1507: else
1508: {
1509: $link = $url;
1510: }
1511:
1512: # Add the text
1513: if ($text ne "")
1514: {
1515: $template .=
1.173 www 1516: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1517: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1518: }
1519:
1520: # Add the graphic
1.179 matthew 1521: my $title = &mt('View the FAQ');
1.215 albertel 1522: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1523: $template .= <<"ENDTEMPLATE";
1.436 albertel 1524: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1525: ENDTEMPLATE
1526: if ($text ne '') { $template.='</td></tr></table>' };
1527: return $template;
1528:
1.44 bowersj2 1529: }
1.37 matthew 1530:
1.180 matthew 1531: ###############################################################
1532: ###############################################################
1533:
1.45 matthew 1534: =pod
1535:
1.648 raeburn 1536: =item * &change_content_javascript():
1.256 matthew 1537:
1538: This and the next function allow you to create small sections of an
1539: otherwise static HTML page that you can update on the fly with
1540: Javascript, even in Netscape 4.
1541:
1542: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1543: must be written to the HTML page once. It will prove the Javascript
1544: function "change(name, content)". Calling the change function with the
1545: name of the section
1546: you want to update, matching the name passed to C<changable_area>, and
1547: the new content you want to put in there, will put the content into
1548: that area.
1549:
1550: B<Note>: Netscape 4 only reserves enough space for the changable area
1551: to contain room for the original contents. You need to "make space"
1552: for whatever changes you wish to make, and be B<sure> to check your
1553: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1554: it's adequate for updating a one-line status display, but little more.
1555: This script will set the space to 100% width, so you only need to
1556: worry about height in Netscape 4.
1557:
1558: Modern browsers are much less limiting, and if you can commit to the
1559: user not using Netscape 4, this feature may be used freely with
1560: pretty much any HTML.
1561:
1562: =cut
1563:
1564: sub change_content_javascript {
1565: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1566: if ($env{'browser.type'} eq 'netscape' &&
1567: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1568: return (<<NETSCAPE4);
1569: function change(name, content) {
1570: doc = document.layers[name+"___escape"].layers[0].document;
1571: doc.open();
1572: doc.write(content);
1573: doc.close();
1574: }
1575: NETSCAPE4
1576: } else {
1577: # Otherwise, we need to use semi-standards-compliant code
1578: # (technically, "innerHTML" isn't standard but the equivalent
1579: # is really scary, and every useful browser supports it
1580: return (<<DOMBASED);
1581: function change(name, content) {
1582: element = document.getElementById(name);
1583: element.innerHTML = content;
1584: }
1585: DOMBASED
1586: }
1587: }
1588:
1589: =pod
1590:
1.648 raeburn 1591: =item * &changable_area($name,$origContent):
1.256 matthew 1592:
1593: This provides a "changable area" that can be modified on the fly via
1594: the Javascript code provided in C<change_content_javascript>. $name is
1595: the name you will use to reference the area later; do not repeat the
1596: same name on a given HTML page more then once. $origContent is what
1597: the area will originally contain, which can be left blank.
1598:
1599: =cut
1600:
1601: sub changable_area {
1602: my ($name, $origContent) = @_;
1603:
1.258 albertel 1604: if ($env{'browser.type'} eq 'netscape' &&
1605: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1606: # If this is netscape 4, we need to use the Layer tag
1607: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1608: } else {
1609: return "<span id='$name'>$origContent</span>";
1610: }
1611: }
1612:
1613: =pod
1614:
1.648 raeburn 1615: =item * &viewport_geometry_js
1.590 raeburn 1616:
1617: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1618:
1619: =cut
1620:
1621:
1622: sub viewport_geometry_js {
1623: return <<"GEOMETRY";
1624: var Geometry = {};
1625: function init_geometry() {
1626: if (Geometry.init) { return };
1627: Geometry.init=1;
1628: if (window.innerHeight) {
1629: Geometry.getViewportHeight = function() { return window.innerHeight; };
1630: Geometry.getViewportWidth = function() { return window.innerWidth; };
1631: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1632: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1633: }
1634: else if (document.documentElement && document.documentElement.clientHeight) {
1635: Geometry.getViewportHeight =
1636: function() { return document.documentElement.clientHeight; };
1637: Geometry.getViewportWidth =
1638: function() { return document.documentElement.clientWidth; };
1639:
1640: Geometry.getHorizontalScroll =
1641: function() { return document.documentElement.scrollLeft; };
1642: Geometry.getVerticalScroll =
1643: function() { return document.documentElement.scrollTop; };
1644: }
1645: else if (document.body.clientHeight) {
1646: Geometry.getViewportHeight =
1647: function() { return document.body.clientHeight; };
1648: Geometry.getViewportWidth =
1649: function() { return document.body.clientWidth; };
1650: Geometry.getHorizontalScroll =
1651: function() { return document.body.scrollLeft; };
1652: Geometry.getVerticalScroll =
1653: function() { return document.body.scrollTop; };
1654: }
1655: }
1656:
1657: GEOMETRY
1658: }
1659:
1660: =pod
1661:
1.648 raeburn 1662: =item * &viewport_size_js()
1.590 raeburn 1663:
1664: 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.
1665:
1666: =cut
1667:
1668: sub viewport_size_js {
1669: my $geometry = &viewport_geometry_js();
1670: return <<"DIMS";
1671:
1672: $geometry
1673:
1674: function getViewportDims(width,height) {
1675: init_geometry();
1676: width.value = Geometry.getViewportWidth();
1677: height.value = Geometry.getViewportHeight();
1678: return;
1679: }
1680:
1681: DIMS
1682: }
1683:
1684: =pod
1685:
1.648 raeburn 1686: =item * &resize_textarea_js()
1.565 albertel 1687:
1688: emits the needed javascript to resize a textarea to be as big as possible
1689:
1690: creates a function resize_textrea that takes two IDs first should be
1691: the id of the element to resize, second should be the id of a div that
1692: surrounds everything that comes after the textarea, this routine needs
1693: to be attached to the <body> for the onload and onresize events.
1694:
1.648 raeburn 1695: =back
1.565 albertel 1696:
1697: =cut
1698:
1699: sub resize_textarea_js {
1.590 raeburn 1700: my $geometry = &viewport_geometry_js();
1.565 albertel 1701: return <<"RESIZE";
1702: <script type="text/javascript">
1.824 bisitz 1703: // <![CDATA[
1.590 raeburn 1704: $geometry
1.565 albertel 1705:
1.588 albertel 1706: function getX(element) {
1707: var x = 0;
1708: while (element) {
1709: x += element.offsetLeft;
1710: element = element.offsetParent;
1711: }
1712: return x;
1713: }
1714: function getY(element) {
1715: var y = 0;
1716: while (element) {
1717: y += element.offsetTop;
1718: element = element.offsetParent;
1719: }
1720: return y;
1721: }
1722:
1723:
1.565 albertel 1724: function resize_textarea(textarea_id,bottom_id) {
1725: init_geometry();
1726: var textarea = document.getElementById(textarea_id);
1727: //alert(textarea);
1728:
1.588 albertel 1729: var textarea_top = getY(textarea);
1.565 albertel 1730: var textarea_height = textarea.offsetHeight;
1731: var bottom = document.getElementById(bottom_id);
1.588 albertel 1732: var bottom_top = getY(bottom);
1.565 albertel 1733: var bottom_height = bottom.offsetHeight;
1734: var window_height = Geometry.getViewportHeight();
1.588 albertel 1735: var fudge = 23;
1.565 albertel 1736: var new_height = window_height-fudge-textarea_top-bottom_height;
1737: if (new_height < 300) {
1738: new_height = 300;
1739: }
1740: textarea.style.height=new_height+'px';
1741: }
1.824 bisitz 1742: // ]]>
1.565 albertel 1743: </script>
1744: RESIZE
1745:
1746: }
1747:
1748: =pod
1749:
1.256 matthew 1750: =head1 Excel and CSV file utility routines
1751:
1752: =over 4
1753:
1754: =cut
1755:
1756: ###############################################################
1757: ###############################################################
1758:
1759: =pod
1760:
1.648 raeburn 1761: =item * &csv_translate($text)
1.37 matthew 1762:
1.185 www 1763: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1764: format.
1765:
1766: =cut
1767:
1.180 matthew 1768: ###############################################################
1769: ###############################################################
1.37 matthew 1770: sub csv_translate {
1771: my $text = shift;
1772: $text =~ s/\"/\"\"/g;
1.209 albertel 1773: $text =~ s/\n/ /g;
1.37 matthew 1774: return $text;
1775: }
1.180 matthew 1776:
1777: ###############################################################
1778: ###############################################################
1779:
1780: =pod
1781:
1.648 raeburn 1782: =item * &define_excel_formats()
1.180 matthew 1783:
1784: Define some commonly used Excel cell formats.
1785:
1786: Currently supported formats:
1787:
1788: =over 4
1789:
1790: =item header
1791:
1792: =item bold
1793:
1794: =item h1
1795:
1796: =item h2
1797:
1798: =item h3
1799:
1.256 matthew 1800: =item h4
1801:
1802: =item i
1803:
1.180 matthew 1804: =item date
1805:
1806: =back
1807:
1808: Inputs: $workbook
1809:
1810: Returns: $format, a hash reference.
1811:
1.1057 foxr 1812:
1.180 matthew 1813: =cut
1814:
1815: ###############################################################
1816: ###############################################################
1817: sub define_excel_formats {
1818: my ($workbook) = @_;
1819: my $format;
1820: $format->{'header'} = $workbook->add_format(bold => 1,
1821: bottom => 1,
1822: align => 'center');
1823: $format->{'bold'} = $workbook->add_format(bold=>1);
1824: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1825: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1826: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1827: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1828: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1829: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1830: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1831: return $format;
1832: }
1833:
1834: ###############################################################
1835: ###############################################################
1.113 bowersj2 1836:
1837: =pod
1838:
1.648 raeburn 1839: =item * &create_workbook()
1.255 matthew 1840:
1841: Create an Excel worksheet. If it fails, output message on the
1842: request object and return undefs.
1843:
1844: Inputs: Apache request object
1845:
1846: Returns (undef) on failure,
1847: Excel worksheet object, scalar with filename, and formats
1848: from &Apache::loncommon::define_excel_formats on success
1849:
1850: =cut
1851:
1852: ###############################################################
1853: ###############################################################
1854: sub create_workbook {
1855: my ($r) = @_;
1856: #
1857: # Create the excel spreadsheet
1858: my $filename = '/prtspool/'.
1.258 albertel 1859: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1860: time.'_'.rand(1000000000).'.xls';
1861: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1862: if (! defined($workbook)) {
1863: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1864: $r->print(
1865: '<p class="LC_error">'
1866: .&mt('Problems occurred in creating the new Excel file.')
1867: .' '.&mt('This error has been logged.')
1868: .' '.&mt('Please alert your LON-CAPA administrator.')
1869: .'</p>'
1870: );
1.255 matthew 1871: return (undef);
1872: }
1873: #
1.1014 foxr 1874: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1875: #
1876: my $format = &Apache::loncommon::define_excel_formats($workbook);
1877: return ($workbook,$filename,$format);
1878: }
1879:
1880: ###############################################################
1881: ###############################################################
1882:
1883: =pod
1884:
1.648 raeburn 1885: =item * &create_text_file()
1.113 bowersj2 1886:
1.542 raeburn 1887: Create a file to write to and eventually make available to the user.
1.256 matthew 1888: If file creation fails, outputs an error message on the request object and
1889: return undefs.
1.113 bowersj2 1890:
1.256 matthew 1891: Inputs: Apache request object, and file suffix
1.113 bowersj2 1892:
1.256 matthew 1893: Returns (undef) on failure,
1894: Filehandle and filename on success.
1.113 bowersj2 1895:
1896: =cut
1897:
1.256 matthew 1898: ###############################################################
1899: ###############################################################
1900: sub create_text_file {
1901: my ($r,$suffix) = @_;
1902: if (! defined($suffix)) { $suffix = 'txt'; };
1903: my $fh;
1904: my $filename = '/prtspool/'.
1.258 albertel 1905: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1906: time.'_'.rand(1000000000).'.'.$suffix;
1907: $fh = Apache::File->new('>/home/httpd'.$filename);
1908: if (! defined($fh)) {
1909: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1910: $r->print(
1911: '<p class="LC_error">'
1912: .&mt('Problems occurred in creating the output file.')
1913: .' '.&mt('This error has been logged.')
1914: .' '.&mt('Please alert your LON-CAPA administrator.')
1915: .'</p>'
1916: );
1.113 bowersj2 1917: }
1.256 matthew 1918: return ($fh,$filename)
1.113 bowersj2 1919: }
1920:
1921:
1.256 matthew 1922: =pod
1.113 bowersj2 1923:
1924: =back
1925:
1926: =cut
1.37 matthew 1927:
1928: ###############################################################
1.33 matthew 1929: ## Home server <option> list generating code ##
1930: ###############################################################
1.35 matthew 1931:
1.169 www 1932: # ------------------------------------------
1933:
1934: sub domain_select {
1935: my ($name,$value,$multiple)=@_;
1936: my %domains=map {
1.514 albertel 1937: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1938: } &Apache::lonnet::all_domains();
1.169 www 1939: if ($multiple) {
1940: $domains{''}=&mt('Any domain');
1.550 albertel 1941: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1942: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1943: } else {
1.550 albertel 1944: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1945: return &select_form($name,$value,\%domains);
1.169 www 1946: }
1947: }
1948:
1.282 albertel 1949: #-------------------------------------------
1950:
1951: =pod
1952:
1.519 raeburn 1953: =head1 Routines for form select boxes
1954:
1955: =over 4
1956:
1.648 raeburn 1957: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1958:
1959: Returns a string containing a <select> element int multiple mode
1960:
1961:
1962: Args:
1963: $name - name of the <select> element
1.506 raeburn 1964: $value - scalar or array ref of values that should already be selected
1.282 albertel 1965: $size - number of rows long the select element is
1.283 albertel 1966: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1967: (shown text should already have been &mt())
1.506 raeburn 1968: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1969:
1.282 albertel 1970: =cut
1971:
1972: #-------------------------------------------
1.169 www 1973: sub multiple_select_form {
1.284 albertel 1974: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1975: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1976: my $output='';
1.191 matthew 1977: if (! defined($size)) {
1978: $size = 4;
1.283 albertel 1979: if (scalar(keys(%$hash))<4) {
1980: $size = scalar(keys(%$hash));
1.191 matthew 1981: }
1982: }
1.734 bisitz 1983: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1984: my @order;
1.506 raeburn 1985: if (ref($order) eq 'ARRAY') {
1986: @order = @{$order};
1987: } else {
1988: @order = sort(keys(%$hash));
1.501 banghart 1989: }
1990: if (exists($$hash{'select_form_order'})) {
1991: @order = @{$$hash{'select_form_order'}};
1992: }
1993:
1.284 albertel 1994: foreach my $key (@order) {
1.356 albertel 1995: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1996: $output.='selected="selected" ' if ($selected{$key});
1997: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1998: }
1999: $output.="</select>\n";
2000: return $output;
2001: }
2002:
1.88 www 2003: #-------------------------------------------
2004:
2005: =pod
2006:
1.970 raeburn 2007: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2008:
2009: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2010: allow a user to select options from a ref to a hash containing:
2011: option_name => displayed text. An optional $onchange can include
2012: a javascript onchange item, e.g., onchange="this.form.submit();"
2013:
1.88 www 2014: See lonrights.pm for an example invocation and use.
2015:
2016: =cut
2017:
2018: #-------------------------------------------
2019: sub select_form {
1.970 raeburn 2020: my ($def,$name,$hashref,$onchange) = @_;
2021: return unless (ref($hashref) eq 'HASH');
2022: if ($onchange) {
2023: $onchange = ' onchange="'.$onchange.'"';
2024: }
2025: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2026: my @keys;
1.970 raeburn 2027: if (exists($hashref->{'select_form_order'})) {
2028: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2029: } else {
1.970 raeburn 2030: @keys=sort(keys(%{$hashref}));
1.128 albertel 2031: }
1.356 albertel 2032: foreach my $key (@keys) {
2033: $selectform.=
2034: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2035: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2036: ">".$hashref->{$key}."</option>\n";
1.88 www 2037: }
2038: $selectform.="</select>";
2039: return $selectform;
2040: }
2041:
1.475 www 2042: # For display filters
2043:
2044: sub display_filter {
1.1074 raeburn 2045: my ($context) = @_;
1.475 www 2046: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2047: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2048: my $phraseinput = 'hidden';
2049: my $includeinput = 'hidden';
2050: my ($checked,$includetypestext);
2051: if ($env{'form.displayfilter'} eq 'containing') {
2052: $phraseinput = 'text';
2053: if ($context eq 'parmslog') {
2054: $includeinput = 'checkbox';
2055: if ($env{'form.includetypes'}) {
2056: $checked = ' checked="checked"';
2057: }
2058: $includetypestext = &mt('Include parameter types');
2059: }
2060: } else {
2061: $includetypestext = ' ';
2062: }
2063: my ($additional,$secondid,$thirdid);
2064: if ($context eq 'parmslog') {
2065: $additional =
2066: '<label><input type="'.$includeinput.'" name="includetypes"'.
2067: $checked.' name="includetypes" value="1" id="includetypes" />'.
2068: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2069: '</label>';
2070: $secondid = 'includetypes';
2071: $thirdid = 'includetypestext';
2072: }
2073: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2074: '$secondid','$thirdid')";
2075: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2076: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2077: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2078: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2079: &mt('Filter: [_1]',
1.477 www 2080: &select_form($env{'form.displayfilter'},
2081: 'displayfilter',
1.970 raeburn 2082: {'currentfolder' => 'Current folder/page',
1.477 www 2083: 'containing' => 'Containing phrase',
1.1074 raeburn 2084: 'none' => 'None'},$onchange)).' '.
2085: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2086: &HTML::Entities::encode($env{'form.containingphrase'}).
2087: '" />'.$additional;
2088: }
2089:
2090: sub display_filter_js {
2091: my $includetext = &mt('Include parameter types');
2092: return <<"ENDJS";
2093:
2094: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2095: var firstType = 'hidden';
2096: if (setter.options[setter.selectedIndex].value == 'containing') {
2097: firstType = 'text';
2098: }
2099: firstObject = document.getElementById(firstid);
2100: if (typeof(firstObject) == 'object') {
2101: if (firstObject.type != firstType) {
2102: changeInputType(firstObject,firstType);
2103: }
2104: }
2105: if (context == 'parmslog') {
2106: var secondType = 'hidden';
2107: if (firstType == 'text') {
2108: secondType = 'checkbox';
2109: }
2110: secondObject = document.getElementById(secondid);
2111: if (typeof(secondObject) == 'object') {
2112: if (secondObject.type != secondType) {
2113: changeInputType(secondObject,secondType);
2114: }
2115: }
2116: var textItem = document.getElementById(thirdid);
2117: var currtext = textItem.innerHTML;
2118: var newtext;
2119: if (firstType == 'text') {
2120: newtext = '$includetext';
2121: } else {
2122: newtext = ' ';
2123: }
2124: if (currtext != newtext) {
2125: textItem.innerHTML = newtext;
2126: }
2127: }
2128: return;
2129: }
2130:
2131: function changeInputType(oldObject,newType) {
2132: var newObject = document.createElement('input');
2133: newObject.type = newType;
2134: if (oldObject.size) {
2135: newObject.size = oldObject.size;
2136: }
2137: if (oldObject.value) {
2138: newObject.value = oldObject.value;
2139: }
2140: if (oldObject.name) {
2141: newObject.name = oldObject.name;
2142: }
2143: if (oldObject.id) {
2144: newObject.id = oldObject.id;
2145: }
2146: oldObject.parentNode.replaceChild(newObject,oldObject);
2147: return;
2148: }
2149:
2150: ENDJS
1.475 www 2151: }
2152:
1.167 www 2153: sub gradeleveldescription {
2154: my $gradelevel=shift;
2155: my %gradelevels=(0 => 'Not specified',
2156: 1 => 'Grade 1',
2157: 2 => 'Grade 2',
2158: 3 => 'Grade 3',
2159: 4 => 'Grade 4',
2160: 5 => 'Grade 5',
2161: 6 => 'Grade 6',
2162: 7 => 'Grade 7',
2163: 8 => 'Grade 8',
2164: 9 => 'Grade 9',
2165: 10 => 'Grade 10',
2166: 11 => 'Grade 11',
2167: 12 => 'Grade 12',
2168: 13 => 'Grade 13',
2169: 14 => '100 Level',
2170: 15 => '200 Level',
2171: 16 => '300 Level',
2172: 17 => '400 Level',
2173: 18 => 'Graduate Level');
2174: return &mt($gradelevels{$gradelevel});
2175: }
2176:
1.163 www 2177: sub select_level_form {
2178: my ($deflevel,$name)=@_;
2179: unless ($deflevel) { $deflevel=0; }
1.167 www 2180: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2181: for (my $i=0; $i<=18; $i++) {
2182: $selectform.="<option value=\"$i\" ".
1.253 albertel 2183: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2184: ">".&gradeleveldescription($i)."</option>\n";
2185: }
2186: $selectform.="</select>";
2187: return $selectform;
1.163 www 2188: }
1.167 www 2189:
1.35 matthew 2190: #-------------------------------------------
2191:
1.45 matthew 2192: =pod
2193:
1.910 raeburn 2194: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35 matthew 2195:
2196: Returns a string containing a <select name='$name' size='1'> form to
2197: allow a user to select the domain to preform an operation in.
2198: See loncreateuser.pm for an example invocation and use.
2199:
1.90 www 2200: If the $includeempty flag is set, it also includes an empty choice ("no domain
2201: selected");
2202:
1.743 raeburn 2203: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2204:
1.910 raeburn 2205: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2206:
2207: The optional $incdoms is a reference to an array of domains which will be the only available options.
1.563 raeburn 2208:
1.35 matthew 2209: =cut
2210:
2211: #-------------------------------------------
1.34 matthew 2212: sub select_dom_form {
1.910 raeburn 2213: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872 raeburn 2214: if ($onchange) {
1.874 raeburn 2215: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2216: }
1.910 raeburn 2217: my @domains;
2218: if (ref($incdoms) eq 'ARRAY') {
2219: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2220: } else {
2221: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2222: }
1.90 www 2223: if ($includeempty) { @domains=('',@domains); }
1.743 raeburn 2224: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2225: foreach my $dom (@domains) {
2226: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2227: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2228: if ($showdomdesc) {
2229: if ($dom ne '') {
2230: my $domdesc = &Apache::lonnet::domain($dom,'description');
2231: if ($domdesc ne '') {
2232: $selectdomain .= ' ('.$domdesc.')';
2233: }
2234: }
2235: }
2236: $selectdomain .= "</option>\n";
1.34 matthew 2237: }
2238: $selectdomain.="</select>";
2239: return $selectdomain;
2240: }
2241:
1.35 matthew 2242: #-------------------------------------------
2243:
1.45 matthew 2244: =pod
2245:
1.648 raeburn 2246: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2247:
1.586 raeburn 2248: input: 4 arguments (two required, two optional) -
2249: $domain - domain of new user
2250: $name - name of form element
2251: $default - Value of 'default' causes a default item to be first
2252: option, and selected by default.
2253: $hide - Value of 'hide' causes hiding of the name of the server,
2254: if 1 server found, or default, if 0 found.
1.594 raeburn 2255: output: returns 2 items:
1.586 raeburn 2256: (a) form element which contains either:
2257: (i) <select name="$name">
2258: <option value="$hostid1">$hostid $servers{$hostid}</option>
2259: <option value="$hostid2">$hostid $servers{$hostid}</option>
2260: </select>
2261: form item if there are multiple library servers in $domain, or
2262: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2263: if there is only one library server in $domain.
2264:
2265: (b) number of library servers found.
2266:
2267: See loncreateuser.pm for example of use.
1.35 matthew 2268:
2269: =cut
2270:
2271: #-------------------------------------------
1.586 raeburn 2272: sub home_server_form_item {
2273: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2274: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2275: my $result;
2276: my $numlib = keys(%servers);
2277: if ($numlib > 1) {
2278: $result .= '<select name="'.$name.'" />'."\n";
2279: if ($default) {
1.804 bisitz 2280: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2281: '</option>'."\n";
2282: }
2283: foreach my $hostid (sort(keys(%servers))) {
2284: $result.= '<option value="'.$hostid.'">'.
2285: $hostid.' '.$servers{$hostid}."</option>\n";
2286: }
2287: $result .= '</select>'."\n";
2288: } elsif ($numlib == 1) {
2289: my $hostid;
2290: foreach my $item (keys(%servers)) {
2291: $hostid = $item;
2292: }
2293: $result .= '<input type="hidden" name="'.$name.'" value="'.
2294: $hostid.'" />';
2295: if (!$hide) {
2296: $result .= $hostid.' '.$servers{$hostid};
2297: }
2298: $result .= "\n";
2299: } elsif ($default) {
2300: $result .= '<input type="hidden" name="'.$name.
2301: '" value="default" />';
2302: if (!$hide) {
2303: $result .= &mt('default');
2304: }
2305: $result .= "\n";
1.33 matthew 2306: }
1.586 raeburn 2307: return ($result,$numlib);
1.33 matthew 2308: }
1.112 bowersj2 2309:
2310: =pod
2311:
1.534 albertel 2312: =back
2313:
1.112 bowersj2 2314: =cut
1.87 matthew 2315:
2316: ###############################################################
1.112 bowersj2 2317: ## Decoding User Agent ##
1.87 matthew 2318: ###############################################################
2319:
2320: =pod
2321:
1.112 bowersj2 2322: =head1 Decoding the User Agent
2323:
2324: =over 4
2325:
2326: =item * &decode_user_agent()
1.87 matthew 2327:
2328: Inputs: $r
2329:
2330: Outputs:
2331:
2332: =over 4
2333:
1.112 bowersj2 2334: =item * $httpbrowser
1.87 matthew 2335:
1.112 bowersj2 2336: =item * $clientbrowser
1.87 matthew 2337:
1.112 bowersj2 2338: =item * $clientversion
1.87 matthew 2339:
1.112 bowersj2 2340: =item * $clientmathml
1.87 matthew 2341:
1.112 bowersj2 2342: =item * $clientunicode
1.87 matthew 2343:
1.112 bowersj2 2344: =item * $clientos
1.87 matthew 2345:
2346: =back
2347:
1.157 matthew 2348: =back
2349:
1.87 matthew 2350: =cut
2351:
2352: ###############################################################
2353: ###############################################################
2354: sub decode_user_agent {
1.247 albertel 2355: my ($r)=@_;
1.87 matthew 2356: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2357: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2358: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2359: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2360: my $clientbrowser='unknown';
2361: my $clientversion='0';
2362: my $clientmathml='';
2363: my $clientunicode='0';
2364: for (my $i=0;$i<=$#browsertype;$i++) {
2365: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
2366: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2367: $clientbrowser=$bname;
2368: $httpbrowser=~/$vreg/i;
2369: $clientversion=$1;
2370: $clientmathml=($clientversion>=$minv);
2371: $clientunicode=($clientversion>=$univ);
2372: }
2373: }
2374: my $clientos='unknown';
2375: if (($httpbrowser=~/linux/i) ||
2376: ($httpbrowser=~/unix/i) ||
2377: ($httpbrowser=~/ux/i) ||
2378: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2379: if (($httpbrowser=~/vax/i) ||
2380: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2381: if ($httpbrowser=~/next/i) { $clientos='next'; }
2382: if (($httpbrowser=~/mac/i) ||
2383: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
2384: if ($httpbrowser=~/win/i) { $clientos='win'; }
2385: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
2386: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
2387: $clientunicode,$clientos,);
2388: }
2389:
1.32 matthew 2390: ###############################################################
2391: ## Authentication changing form generation subroutines ##
2392: ###############################################################
2393: ##
2394: ## All of the authform_xxxxxxx subroutines take their inputs in a
2395: ## hash, and have reasonable default values.
2396: ##
2397: ## formname = the name given in the <form> tag.
1.35 matthew 2398: #-------------------------------------------
2399:
1.45 matthew 2400: =pod
2401:
1.112 bowersj2 2402: =head1 Authentication Routines
2403:
2404: =over 4
2405:
1.648 raeburn 2406: =item * &authform_xxxxxx()
1.35 matthew 2407:
2408: The authform_xxxxxx subroutines provide javascript and html forms which
2409: handle some of the conveniences required for authentication forms.
2410: This is not an optimal method, but it works.
2411:
2412: =over 4
2413:
1.112 bowersj2 2414: =item * authform_header
1.35 matthew 2415:
1.112 bowersj2 2416: =item * authform_authorwarning
1.35 matthew 2417:
1.112 bowersj2 2418: =item * authform_nochange
1.35 matthew 2419:
1.112 bowersj2 2420: =item * authform_kerberos
1.35 matthew 2421:
1.112 bowersj2 2422: =item * authform_internal
1.35 matthew 2423:
1.112 bowersj2 2424: =item * authform_filesystem
1.35 matthew 2425:
2426: =back
2427:
1.648 raeburn 2428: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2429:
1.35 matthew 2430: =cut
2431:
2432: #-------------------------------------------
1.32 matthew 2433: sub authform_header{
2434: my %in = (
2435: formname => 'cu',
1.80 albertel 2436: kerb_def_dom => '',
1.32 matthew 2437: @_,
2438: );
2439: $in{'formname'} = 'document.' . $in{'formname'};
2440: my $result='';
1.80 albertel 2441:
2442: #---------------------------------------------- Code for upper case translation
2443: my $Javascript_toUpperCase;
2444: unless ($in{kerb_def_dom}) {
2445: $Javascript_toUpperCase =<<"END";
2446: switch (choice) {
2447: case 'krb': currentform.elements[choicearg].value =
2448: currentform.elements[choicearg].value.toUpperCase();
2449: break;
2450: default:
2451: }
2452: END
2453: } else {
2454: $Javascript_toUpperCase = "";
2455: }
2456:
1.165 raeburn 2457: my $radioval = "'nochange'";
1.591 raeburn 2458: if (defined($in{'curr_authtype'})) {
2459: if ($in{'curr_authtype'} ne '') {
2460: $radioval = "'".$in{'curr_authtype'}."arg'";
2461: }
1.174 matthew 2462: }
1.165 raeburn 2463: my $argfield = 'null';
1.591 raeburn 2464: if (defined($in{'mode'})) {
1.165 raeburn 2465: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2466: if (defined($in{'curr_autharg'})) {
2467: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2468: $argfield = "'$in{'curr_autharg'}'";
2469: }
2470: }
2471: }
2472: }
2473:
1.32 matthew 2474: $result.=<<"END";
2475: var current = new Object();
1.165 raeburn 2476: current.radiovalue = $radioval;
2477: current.argfield = $argfield;
1.32 matthew 2478:
2479: function changed_radio(choice,currentform) {
2480: var choicearg = choice + 'arg';
2481: // If a radio button in changed, we need to change the argfield
2482: if (current.radiovalue != choice) {
2483: current.radiovalue = choice;
2484: if (current.argfield != null) {
2485: currentform.elements[current.argfield].value = '';
2486: }
2487: if (choice == 'nochange') {
2488: current.argfield = null;
2489: } else {
2490: current.argfield = choicearg;
2491: switch(choice) {
2492: case 'krb':
2493: currentform.elements[current.argfield].value =
2494: "$in{'kerb_def_dom'}";
2495: break;
2496: default:
2497: break;
2498: }
2499: }
2500: }
2501: return;
2502: }
1.22 www 2503:
1.32 matthew 2504: function changed_text(choice,currentform) {
2505: var choicearg = choice + 'arg';
2506: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2507: $Javascript_toUpperCase
1.32 matthew 2508: // clear old field
2509: if ((current.argfield != choicearg) && (current.argfield != null)) {
2510: currentform.elements[current.argfield].value = '';
2511: }
2512: current.argfield = choicearg;
2513: }
2514: set_auth_radio_buttons(choice,currentform);
2515: return;
1.20 www 2516: }
1.32 matthew 2517:
2518: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2519: var numauthchoices = currentform.login.length;
2520: if (typeof numauthchoices == "undefined") {
2521: return;
2522: }
1.32 matthew 2523: var i=0;
1.986 raeburn 2524: while (i < numauthchoices) {
1.32 matthew 2525: if (currentform.login[i].value == newvalue) { break; }
2526: i++;
2527: }
1.986 raeburn 2528: if (i == numauthchoices) {
1.32 matthew 2529: return;
2530: }
2531: current.radiovalue = newvalue;
2532: currentform.login[i].checked = true;
2533: return;
2534: }
2535: END
2536: return $result;
2537: }
2538:
1.1106 raeburn 2539: sub authform_authorwarning {
1.32 matthew 2540: my $result='';
1.144 matthew 2541: $result='<i>'.
2542: &mt('As a general rule, only authors or co-authors should be '.
2543: 'filesystem authenticated '.
2544: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2545: return $result;
2546: }
2547:
1.1106 raeburn 2548: sub authform_nochange {
1.32 matthew 2549: my %in = (
2550: formname => 'document.cu',
2551: kerb_def_dom => 'MSU.EDU',
2552: @_,
2553: );
1.1106 raeburn 2554: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2555: my $result;
1.1104 raeburn 2556: if (!$authnum) {
1.1105 raeburn 2557: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2558: } else {
2559: $result = '<label>'.&mt('[_1] Do not change login data',
2560: '<input type="radio" name="login" value="nochange" '.
2561: 'checked="checked" onclick="'.
1.281 albertel 2562: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2563: '</label>';
1.586 raeburn 2564: }
1.32 matthew 2565: return $result;
2566: }
2567:
1.591 raeburn 2568: sub authform_kerberos {
1.32 matthew 2569: my %in = (
2570: formname => 'document.cu',
2571: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2572: kerb_def_auth => 'krb4',
1.32 matthew 2573: @_,
2574: );
1.586 raeburn 2575: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2576: $autharg,$jscall);
1.1106 raeburn 2577: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2578: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2579: $check5 = ' checked="checked"';
1.80 albertel 2580: } else {
1.772 bisitz 2581: $check4 = ' checked="checked"';
1.80 albertel 2582: }
1.165 raeburn 2583: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2584: if (defined($in{'curr_authtype'})) {
2585: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2586: $krbcheck = ' checked="checked"';
1.623 raeburn 2587: if (defined($in{'mode'})) {
2588: if ($in{'mode'} eq 'modifyuser') {
2589: $krbcheck = '';
2590: }
2591: }
1.591 raeburn 2592: if (defined($in{'curr_kerb_ver'})) {
2593: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2594: $check5 = ' checked="checked"';
1.591 raeburn 2595: $check4 = '';
2596: } else {
1.772 bisitz 2597: $check4 = ' checked="checked"';
1.591 raeburn 2598: $check5 = '';
2599: }
1.586 raeburn 2600: }
1.591 raeburn 2601: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2602: $krbarg = $in{'curr_autharg'};
2603: }
1.586 raeburn 2604: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2605: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2606: $result =
2607: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2608: $in{'curr_autharg'},$krbver);
2609: } else {
2610: $result =
2611: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2612: }
2613: return $result;
2614: }
2615: }
2616: } else {
2617: if ($authnum == 1) {
1.784 bisitz 2618: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2619: }
2620: }
1.586 raeburn 2621: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2622: return;
1.587 raeburn 2623: } elsif ($authtype eq '') {
1.591 raeburn 2624: if (defined($in{'mode'})) {
1.587 raeburn 2625: if ($in{'mode'} eq 'modifycourse') {
2626: if ($authnum == 1) {
1.1104 raeburn 2627: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2628: }
2629: }
2630: }
1.586 raeburn 2631: }
2632: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2633: if ($authtype eq '') {
2634: $authtype = '<input type="radio" name="login" value="krb" '.
2635: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2636: $krbcheck.' />';
2637: }
2638: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2639: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2640: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2641: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2642: $in{'curr_authtype'} eq 'krb4')) {
2643: $result .= &mt
1.144 matthew 2644: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2645: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2646: '<label>'.$authtype,
1.281 albertel 2647: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2648: 'value="'.$krbarg.'" '.
1.144 matthew 2649: 'onchange="'.$jscall.'" />',
1.281 albertel 2650: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2651: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2652: '</label>');
1.586 raeburn 2653: } elsif ($can_assign{'krb4'}) {
2654: $result .= &mt
2655: ('[_1] Kerberos authenticated with domain [_2] '.
2656: '[_3] Version 4 [_4]',
2657: '<label>'.$authtype,
2658: '</label><input type="text" size="10" name="krbarg" '.
2659: 'value="'.$krbarg.'" '.
2660: 'onchange="'.$jscall.'" />',
2661: '<label><input type="hidden" name="krbver" value="4" />',
2662: '</label>');
2663: } elsif ($can_assign{'krb5'}) {
2664: $result .= &mt
2665: ('[_1] Kerberos authenticated with domain [_2] '.
2666: '[_3] Version 5 [_4]',
2667: '<label>'.$authtype,
2668: '</label><input type="text" size="10" name="krbarg" '.
2669: 'value="'.$krbarg.'" '.
2670: 'onchange="'.$jscall.'" />',
2671: '<label><input type="hidden" name="krbver" value="5" />',
2672: '</label>');
2673: }
1.32 matthew 2674: return $result;
2675: }
2676:
1.1106 raeburn 2677: sub authform_internal {
1.586 raeburn 2678: my %in = (
1.32 matthew 2679: formname => 'document.cu',
2680: kerb_def_dom => 'MSU.EDU',
2681: @_,
2682: );
1.586 raeburn 2683: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2684: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2685: if (defined($in{'curr_authtype'})) {
2686: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2687: if ($can_assign{'int'}) {
1.772 bisitz 2688: $intcheck = 'checked="checked" ';
1.623 raeburn 2689: if (defined($in{'mode'})) {
2690: if ($in{'mode'} eq 'modifyuser') {
2691: $intcheck = '';
2692: }
2693: }
1.591 raeburn 2694: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2695: $intarg = $in{'curr_autharg'};
2696: }
2697: } else {
2698: $result = &mt('Currently internally authenticated.');
2699: return $result;
1.165 raeburn 2700: }
2701: }
1.586 raeburn 2702: } else {
2703: if ($authnum == 1) {
1.784 bisitz 2704: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2705: }
2706: }
2707: if (!$can_assign{'int'}) {
2708: return;
1.587 raeburn 2709: } elsif ($authtype eq '') {
1.591 raeburn 2710: if (defined($in{'mode'})) {
1.587 raeburn 2711: if ($in{'mode'} eq 'modifycourse') {
2712: if ($authnum == 1) {
1.1104 raeburn 2713: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2714: }
2715: }
2716: }
1.165 raeburn 2717: }
1.586 raeburn 2718: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2719: if ($authtype eq '') {
2720: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2721: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2722: }
1.605 bisitz 2723: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2724: $intarg.'" onchange="'.$jscall.'" />';
2725: $result = &mt
1.144 matthew 2726: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2727: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2728: $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 2729: return $result;
2730: }
2731:
1.1104 raeburn 2732: sub authform_local {
1.32 matthew 2733: my %in = (
2734: formname => 'document.cu',
2735: kerb_def_dom => 'MSU.EDU',
2736: @_,
2737: );
1.586 raeburn 2738: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2739: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2740: if (defined($in{'curr_authtype'})) {
2741: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2742: if ($can_assign{'loc'}) {
1.772 bisitz 2743: $loccheck = 'checked="checked" ';
1.623 raeburn 2744: if (defined($in{'mode'})) {
2745: if ($in{'mode'} eq 'modifyuser') {
2746: $loccheck = '';
2747: }
2748: }
1.591 raeburn 2749: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2750: $locarg = $in{'curr_autharg'};
2751: }
2752: } else {
2753: $result = &mt('Currently using local (institutional) authentication.');
2754: return $result;
1.165 raeburn 2755: }
2756: }
1.586 raeburn 2757: } else {
2758: if ($authnum == 1) {
1.784 bisitz 2759: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2760: }
2761: }
2762: if (!$can_assign{'loc'}) {
2763: return;
1.587 raeburn 2764: } elsif ($authtype eq '') {
1.591 raeburn 2765: if (defined($in{'mode'})) {
1.587 raeburn 2766: if ($in{'mode'} eq 'modifycourse') {
2767: if ($authnum == 1) {
1.1104 raeburn 2768: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2769: }
2770: }
2771: }
1.165 raeburn 2772: }
1.586 raeburn 2773: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2774: if ($authtype eq '') {
2775: $authtype = '<input type="radio" name="login" value="loc" '.
2776: $loccheck.' onchange="'.$jscall.'" onclick="'.
2777: $jscall.'" />';
2778: }
2779: $autharg = '<input type="text" size="10" name="locarg" value="'.
2780: $locarg.'" onchange="'.$jscall.'" />';
2781: $result = &mt('[_1] Local Authentication with argument [_2]',
2782: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2783: return $result;
2784: }
2785:
1.1106 raeburn 2786: sub authform_filesystem {
1.32 matthew 2787: my %in = (
2788: formname => 'document.cu',
2789: kerb_def_dom => 'MSU.EDU',
2790: @_,
2791: );
1.586 raeburn 2792: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2793: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2794: if (defined($in{'curr_authtype'})) {
2795: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2796: if ($can_assign{'fsys'}) {
1.772 bisitz 2797: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2798: if (defined($in{'mode'})) {
2799: if ($in{'mode'} eq 'modifyuser') {
2800: $fsyscheck = '';
2801: }
2802: }
1.586 raeburn 2803: } else {
2804: $result = &mt('Currently Filesystem Authenticated.');
2805: return $result;
2806: }
2807: }
2808: } else {
2809: if ($authnum == 1) {
1.784 bisitz 2810: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2811: }
2812: }
2813: if (!$can_assign{'fsys'}) {
2814: return;
1.587 raeburn 2815: } elsif ($authtype eq '') {
1.591 raeburn 2816: if (defined($in{'mode'})) {
1.587 raeburn 2817: if ($in{'mode'} eq 'modifycourse') {
2818: if ($authnum == 1) {
1.1104 raeburn 2819: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2820: }
2821: }
2822: }
1.586 raeburn 2823: }
2824: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2825: if ($authtype eq '') {
2826: $authtype = '<input type="radio" name="login" value="fsys" '.
2827: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2828: $jscall.'" />';
2829: }
2830: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2831: ' onchange="'.$jscall.'" />';
2832: $result = &mt
1.144 matthew 2833: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2834: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2835: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2836: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2837: 'onchange="'.$jscall.'" />');
1.32 matthew 2838: return $result;
2839: }
2840:
1.586 raeburn 2841: sub get_assignable_auth {
2842: my ($dom) = @_;
2843: if ($dom eq '') {
2844: $dom = $env{'request.role.domain'};
2845: }
2846: my %can_assign = (
2847: krb4 => 1,
2848: krb5 => 1,
2849: int => 1,
2850: loc => 1,
2851: );
2852: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2853: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2854: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2855: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2856: my $context;
2857: if ($env{'request.role'} =~ /^au/) {
2858: $context = 'author';
2859: } elsif ($env{'request.role'} =~ /^dc/) {
2860: $context = 'domain';
2861: } elsif ($env{'request.course.id'}) {
2862: $context = 'course';
2863: }
2864: if ($context) {
2865: if (ref($authhash->{$context}) eq 'HASH') {
2866: %can_assign = %{$authhash->{$context}};
2867: }
2868: }
2869: }
2870: }
2871: my $authnum = 0;
2872: foreach my $key (keys(%can_assign)) {
2873: if ($can_assign{$key}) {
2874: $authnum ++;
2875: }
2876: }
2877: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2878: $authnum --;
2879: }
2880: return ($authnum,%can_assign);
2881: }
2882:
1.80 albertel 2883: ###############################################################
2884: ## Get Kerberos Defaults for Domain ##
2885: ###############################################################
2886: ##
2887: ## Returns default kerberos version and an associated argument
2888: ## as listed in file domain.tab. If not listed, provides
2889: ## appropriate default domain and kerberos version.
2890: ##
2891: #-------------------------------------------
2892:
2893: =pod
2894:
1.648 raeburn 2895: =item * &get_kerberos_defaults()
1.80 albertel 2896:
2897: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2898: version and domain. If not found, it defaults to version 4 and the
2899: domain of the server.
1.80 albertel 2900:
1.648 raeburn 2901: =over 4
2902:
1.80 albertel 2903: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2904:
1.648 raeburn 2905: =back
2906:
2907: =back
2908:
1.80 albertel 2909: =cut
2910:
2911: #-------------------------------------------
2912: sub get_kerberos_defaults {
2913: my $domain=shift;
1.641 raeburn 2914: my ($krbdef,$krbdefdom);
2915: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2916: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2917: $krbdef = $domdefaults{'auth_def'};
2918: $krbdefdom = $domdefaults{'auth_arg_def'};
2919: } else {
1.80 albertel 2920: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2921: my $krbdefdom=$1;
2922: $krbdefdom=~tr/a-z/A-Z/;
2923: $krbdef = "krb4";
2924: }
2925: return ($krbdef,$krbdefdom);
2926: }
1.112 bowersj2 2927:
1.32 matthew 2928:
1.46 matthew 2929: ###############################################################
2930: ## Thesaurus Functions ##
2931: ###############################################################
1.20 www 2932:
1.46 matthew 2933: =pod
1.20 www 2934:
1.112 bowersj2 2935: =head1 Thesaurus Functions
2936:
2937: =over 4
2938:
1.648 raeburn 2939: =item * &initialize_keywords()
1.46 matthew 2940:
2941: Initializes the package variable %Keywords if it is empty. Uses the
2942: package variable $thesaurus_db_file.
2943:
2944: =cut
2945:
2946: ###################################################
2947:
2948: sub initialize_keywords {
2949: return 1 if (scalar keys(%Keywords));
2950: # If we are here, %Keywords is empty, so fill it up
2951: # Make sure the file we need exists...
2952: if (! -e $thesaurus_db_file) {
2953: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2954: " failed because it does not exist");
2955: return 0;
2956: }
2957: # Set up the hash as a database
2958: my %thesaurus_db;
2959: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2960: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2961: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2962: $thesaurus_db_file);
2963: return 0;
2964: }
2965: # Get the average number of appearances of a word.
2966: my $avecount = $thesaurus_db{'average.count'};
2967: # Put keywords (those that appear > average) into %Keywords
2968: while (my ($word,$data)=each (%thesaurus_db)) {
2969: my ($count,undef) = split /:/,$data;
2970: $Keywords{$word}++ if ($count > $avecount);
2971: }
2972: untie %thesaurus_db;
2973: # Remove special values from %Keywords.
1.356 albertel 2974: foreach my $value ('total.count','average.count') {
2975: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 2976: }
1.46 matthew 2977: return 1;
2978: }
2979:
2980: ###################################################
2981:
2982: =pod
2983:
1.648 raeburn 2984: =item * &keyword($word)
1.46 matthew 2985:
2986: Returns true if $word is a keyword. A keyword is a word that appears more
2987: than the average number of times in the thesaurus database. Calls
2988: &initialize_keywords
2989:
2990: =cut
2991:
2992: ###################################################
1.20 www 2993:
2994: sub keyword {
1.46 matthew 2995: return if (!&initialize_keywords());
2996: my $word=lc(shift());
2997: $word=~s/\W//g;
2998: return exists($Keywords{$word});
1.20 www 2999: }
1.46 matthew 3000:
3001: ###############################################################
3002:
3003: =pod
1.20 www 3004:
1.648 raeburn 3005: =item * &get_related_words()
1.46 matthew 3006:
1.160 matthew 3007: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3008: an array of words. If the keyword is not in the thesaurus, an empty array
3009: will be returned. The order of the words returned is determined by the
3010: database which holds them.
3011:
3012: Uses global $thesaurus_db_file.
3013:
1.1057 foxr 3014:
1.46 matthew 3015: =cut
3016:
3017: ###############################################################
3018: sub get_related_words {
3019: my $keyword = shift;
3020: my %thesaurus_db;
3021: if (! -e $thesaurus_db_file) {
3022: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3023: "failed because the file does not exist");
3024: return ();
3025: }
3026: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3027: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3028: return ();
3029: }
3030: my @Words=();
1.429 www 3031: my $count=0;
1.46 matthew 3032: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3033: # The first element is the number of times
3034: # the word appears. We do not need it now.
1.429 www 3035: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3036: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3037: my $threshold=$mostfrequentcount/10;
3038: foreach my $possibleword (@RelatedWords) {
3039: my ($word,$wordcount)=split(/\,/,$possibleword);
3040: if ($wordcount>$threshold) {
3041: push(@Words,$word);
3042: $count++;
3043: if ($count>10) { last; }
3044: }
1.20 www 3045: }
3046: }
1.46 matthew 3047: untie %thesaurus_db;
3048: return @Words;
1.14 harris41 3049: }
1.1090 foxr 3050: ###############################################################
3051: #
3052: # Spell checking
3053: #
3054:
3055: =pod
3056:
3057: =head1 Spell checking
3058:
3059: =over 4
3060:
3061: =item * &check_spelling($wordlist $language)
3062:
3063: Takes a string containing words and feeds it to an external
3064: spellcheck program via a pipeline. Returns a string containing
3065: them mis-spelled words.
3066:
3067: Parameters:
3068:
3069: =over 4
3070:
3071: =item - $wordlist
3072:
3073: String that will be fed into the spellcheck program.
3074:
3075: =item - $language
3076:
3077: Language string that specifies the language for which the spell
3078: check will be performed.
3079:
3080: =back
3081:
3082: =back
3083:
3084: Note: This sub assumes that aspell is installed.
3085:
3086:
3087: =cut
3088:
1.46 matthew 3089:
1.112 bowersj2 3090: =pod
3091:
3092: =back
3093:
3094: =cut
1.61 www 3095:
1.1090 foxr 3096: sub check_spelling {
3097: my ($wordlist, $language) = @_;
1.1091 foxr 3098: my @misspellings;
3099:
3100: # Generate the speller and set the langauge.
3101: # if explicitly selected:
1.1090 foxr 3102:
1.1091 foxr 3103: my $speller = Text::Aspell->new;
1.1090 foxr 3104: if ($language) {
1.1091 foxr 3105: $speller->set_option('lang', $language);
1.1090 foxr 3106: }
3107:
1.1091 foxr 3108: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3109:
1.1091 foxr 3110: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3111:
1.1091 foxr 3112: foreach my $word (@words) {
3113: if(! $speller->check($word)) {
3114: push(@misspellings, $word);
1.1090 foxr 3115: }
3116: }
1.1091 foxr 3117: return join(' ', @misspellings);
3118:
1.1090 foxr 3119: }
3120:
1.61 www 3121: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3122: =pod
3123:
1.112 bowersj2 3124: =head1 User Name Functions
3125:
3126: =over 4
3127:
1.648 raeburn 3128: =item * &plainname($uname,$udom,$first)
1.81 albertel 3129:
1.112 bowersj2 3130: Takes a users logon name and returns it as a string in
1.226 albertel 3131: "first middle last generation" form
3132: if $first is set to 'lastname' then it returns it as
3133: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3134:
3135: =cut
1.61 www 3136:
1.295 www 3137:
1.81 albertel 3138: ###############################################################
1.61 www 3139: sub plainname {
1.226 albertel 3140: my ($uname,$udom,$first)=@_;
1.537 albertel 3141: return if (!defined($uname) || !defined($udom));
1.295 www 3142: my %names=&getnames($uname,$udom);
1.226 albertel 3143: my $name=&Apache::lonnet::format_name($names{'firstname'},
3144: $names{'middlename'},
3145: $names{'lastname'},
3146: $names{'generation'},$first);
3147: $name=~s/^\s+//;
1.62 www 3148: $name=~s/\s+$//;
3149: $name=~s/\s+/ /g;
1.353 albertel 3150: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3151: return $name;
1.61 www 3152: }
1.66 www 3153:
3154: # -------------------------------------------------------------------- Nickname
1.81 albertel 3155: =pod
3156:
1.648 raeburn 3157: =item * &nickname($uname,$udom)
1.81 albertel 3158:
3159: Gets a users name and returns it as a string as
3160:
3161: ""nickname""
1.66 www 3162:
1.81 albertel 3163: if the user has a nickname or
3164:
3165: "first middle last generation"
3166:
3167: if the user does not
3168:
3169: =cut
1.66 www 3170:
3171: sub nickname {
3172: my ($uname,$udom)=@_;
1.537 albertel 3173: return if (!defined($uname) || !defined($udom));
1.295 www 3174: my %names=&getnames($uname,$udom);
1.68 albertel 3175: my $name=$names{'nickname'};
1.66 www 3176: if ($name) {
3177: $name='"'.$name.'"';
3178: } else {
3179: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3180: $names{'lastname'}.' '.$names{'generation'};
3181: $name=~s/\s+$//;
3182: $name=~s/\s+/ /g;
3183: }
3184: return $name;
3185: }
3186:
1.295 www 3187: sub getnames {
3188: my ($uname,$udom)=@_;
1.537 albertel 3189: return if (!defined($uname) || !defined($udom));
1.433 albertel 3190: if ($udom eq 'public' && $uname eq 'public') {
3191: return ('lastname' => &mt('Public'));
3192: }
1.295 www 3193: my $id=$uname.':'.$udom;
3194: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3195: if ($cached) {
3196: return %{$names};
3197: } else {
3198: my %loadnames=&Apache::lonnet::get('environment',
3199: ['firstname','middlename','lastname','generation','nickname'],
3200: $udom,$uname);
3201: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3202: return %loadnames;
3203: }
3204: }
1.61 www 3205:
1.542 raeburn 3206: # -------------------------------------------------------------------- getemails
1.648 raeburn 3207:
1.542 raeburn 3208: =pod
3209:
1.648 raeburn 3210: =item * &getemails($uname,$udom)
1.542 raeburn 3211:
3212: Gets a user's email information and returns it as a hash with keys:
3213: notification, critnotification, permanentemail
3214:
3215: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3216: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3217:
1.648 raeburn 3218:
1.542 raeburn 3219: =cut
3220:
1.648 raeburn 3221:
1.466 albertel 3222: sub getemails {
3223: my ($uname,$udom)=@_;
3224: if ($udom eq 'public' && $uname eq 'public') {
3225: return;
3226: }
1.467 www 3227: if (!$udom) { $udom=$env{'user.domain'}; }
3228: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3229: my $id=$uname.':'.$udom;
3230: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3231: if ($cached) {
3232: return %{$names};
3233: } else {
3234: my %loadnames=&Apache::lonnet::get('environment',
3235: ['notification','critnotification',
3236: 'permanentemail'],
3237: $udom,$uname);
3238: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3239: return %loadnames;
3240: }
3241: }
3242:
1.551 albertel 3243: sub flush_email_cache {
3244: my ($uname,$udom)=@_;
3245: if (!$udom) { $udom =$env{'user.domain'}; }
3246: if (!$uname) { $uname=$env{'user.name'}; }
3247: return if ($udom eq 'public' && $uname eq 'public');
3248: my $id=$uname.':'.$udom;
3249: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3250: }
3251:
1.728 raeburn 3252: # -------------------------------------------------------------------- getlangs
3253:
3254: =pod
3255:
3256: =item * &getlangs($uname,$udom)
3257:
3258: Gets a user's language preference and returns it as a hash with key:
3259: language.
3260:
3261: =cut
3262:
3263:
3264: sub getlangs {
3265: my ($uname,$udom) = @_;
3266: if (!$udom) { $udom =$env{'user.domain'}; }
3267: if (!$uname) { $uname=$env{'user.name'}; }
3268: my $id=$uname.':'.$udom;
3269: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3270: if ($cached) {
3271: return %{$langs};
3272: } else {
3273: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3274: $udom,$uname);
3275: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3276: return %loadlangs;
3277: }
3278: }
3279:
3280: sub flush_langs_cache {
3281: my ($uname,$udom)=@_;
3282: if (!$udom) { $udom =$env{'user.domain'}; }
3283: if (!$uname) { $uname=$env{'user.name'}; }
3284: return if ($udom eq 'public' && $uname eq 'public');
3285: my $id=$uname.':'.$udom;
3286: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3287: }
3288:
1.61 www 3289: # ------------------------------------------------------------------ Screenname
1.81 albertel 3290:
3291: =pod
3292:
1.648 raeburn 3293: =item * &screenname($uname,$udom)
1.81 albertel 3294:
3295: Gets a users screenname and returns it as a string
3296:
3297: =cut
1.61 www 3298:
3299: sub screenname {
3300: my ($uname,$udom)=@_;
1.258 albertel 3301: if ($uname eq $env{'user.name'} &&
3302: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3303: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3304: return $names{'screenname'};
1.62 www 3305: }
3306:
1.212 albertel 3307:
1.802 bisitz 3308: # ------------------------------------------------------------- Confirm Wrapper
3309: =pod
3310:
3311: =item confirmwrapper
3312:
3313: Wrap messages about completion of operation in box
3314:
3315: =cut
3316:
3317: sub confirmwrapper {
3318: my ($message)=@_;
3319: if ($message) {
3320: return "\n".'<div class="LC_confirm_box">'."\n"
3321: .$message."\n"
3322: .'</div>'."\n";
3323: } else {
3324: return $message;
3325: }
3326: }
3327:
1.62 www 3328: # ------------------------------------------------------------- Message Wrapper
3329:
3330: sub messagewrapper {
1.369 www 3331: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3332: return
1.441 albertel 3333: '<a href="/adm/email?compose=individual&'.
3334: 'recname='.$username.'&recdom='.$domain.
3335: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3336: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3337: }
1.802 bisitz 3338:
1.74 www 3339: # --------------------------------------------------------------- Notes Wrapper
3340:
3341: sub noteswrapper {
3342: my ($link,$un,$do)=@_;
3343: return
1.896 amueller 3344: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3345: }
1.802 bisitz 3346:
1.62 www 3347: # ------------------------------------------------------------- Aboutme Wrapper
3348:
3349: sub aboutmewrapper {
1.1070 raeburn 3350: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3351: if (!defined($username) && !defined($domain)) {
3352: return;
3353: }
1.1096 raeburn 3354: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3355: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3356: }
3357:
3358: # ------------------------------------------------------------ Syllabus Wrapper
3359:
3360: sub syllabuswrapper {
1.707 bisitz 3361: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3362: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3363: }
1.14 harris41 3364:
1.802 bisitz 3365: # -----------------------------------------------------------------------------
3366:
1.208 matthew 3367: sub track_student_link {
1.887 raeburn 3368: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3369: my $link ="/adm/trackstudent?";
1.208 matthew 3370: my $title = 'View recent activity';
3371: if (defined($sname) && $sname !~ /^\s*$/ &&
3372: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3373: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3374: $title .= ' of this student';
1.268 albertel 3375: }
1.208 matthew 3376: if (defined($target) && $target !~ /^\s*$/) {
3377: $target = qq{target="$target"};
3378: } else {
3379: $target = '';
3380: }
1.268 albertel 3381: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3382: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3383: $title = &mt($title);
3384: $linktext = &mt($linktext);
1.448 albertel 3385: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3386: &help_open_topic('View_recent_activity');
1.208 matthew 3387: }
3388:
1.781 raeburn 3389: sub slot_reservations_link {
3390: my ($linktext,$sname,$sdom,$target) = @_;
3391: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3392: my $title = 'View slot reservation history';
3393: if (defined($sname) && $sname !~ /^\s*$/ &&
3394: defined($sdom) && $sdom !~ /^\s*$/) {
3395: $link .= "&uname=$sname&udom=$sdom";
3396: $title .= ' of this student';
3397: }
3398: if (defined($target) && $target !~ /^\s*$/) {
3399: $target = qq{target="$target"};
3400: } else {
3401: $target = '';
3402: }
3403: $title = &mt($title);
3404: $linktext = &mt($linktext);
3405: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3406: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3407:
3408: }
3409:
1.508 www 3410: # ===================================================== Display a student photo
3411:
3412:
1.509 albertel 3413: sub student_image_tag {
1.508 www 3414: my ($domain,$user)=@_;
3415: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3416: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3417: return '<img src="'.$imgsrc.'" align="right" />';
3418: } else {
3419: return '';
3420: }
3421: }
3422:
1.112 bowersj2 3423: =pod
3424:
3425: =back
3426:
3427: =head1 Access .tab File Data
3428:
3429: =over 4
3430:
1.648 raeburn 3431: =item * &languageids()
1.112 bowersj2 3432:
3433: returns list of all language ids
3434:
3435: =cut
3436:
1.14 harris41 3437: sub languageids {
1.16 harris41 3438: return sort(keys(%language));
1.14 harris41 3439: }
3440:
1.112 bowersj2 3441: =pod
3442:
1.648 raeburn 3443: =item * &languagedescription()
1.112 bowersj2 3444:
3445: returns description of a specified language id
3446:
3447: =cut
3448:
1.14 harris41 3449: sub languagedescription {
1.125 www 3450: my $code=shift;
3451: return ($supported_language{$code}?'* ':'').
3452: $language{$code}.
1.126 www 3453: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3454: }
3455:
1.1048 foxr 3456: =pod
3457:
3458: =item * &plainlanguagedescription
3459:
3460: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3461: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3462:
3463: =cut
3464:
1.145 www 3465: sub plainlanguagedescription {
3466: my $code=shift;
3467: return $language{$code};
3468: }
3469:
1.1048 foxr 3470: =pod
3471:
3472: =item * &supportedlanguagecode
3473:
3474: Returns the supported language code (e.g. sptutf maps to pt) given a language
3475: code.
3476:
3477: =cut
3478:
1.145 www 3479: sub supportedlanguagecode {
3480: my $code=shift;
3481: return $supported_language{$code};
1.97 www 3482: }
3483:
1.112 bowersj2 3484: =pod
3485:
1.1048 foxr 3486: =item * &latexlanguage()
3487:
3488: Given a language key code returns the correspondnig language to use
3489: to select the correct hyphenation on LaTeX printouts. This is undef if there
3490: is no supported hyphenation for the language code.
3491:
3492: =cut
3493:
3494: sub latexlanguage {
3495: my $code = shift;
3496: return $latex_language{$code};
3497: }
3498:
3499: =pod
3500:
3501: =item * &latexhyphenation()
3502:
3503: Same as above but what's supplied is the language as it might be stored
3504: in the metadata.
3505:
3506: =cut
3507:
3508: sub latexhyphenation {
3509: my $key = shift;
3510: return $latex_language_bykey{$key};
3511: }
3512:
3513: =pod
3514:
1.648 raeburn 3515: =item * ©rightids()
1.112 bowersj2 3516:
3517: returns list of all copyrights
3518:
3519: =cut
3520:
3521: sub copyrightids {
3522: return sort(keys(%cprtag));
3523: }
3524:
3525: =pod
3526:
1.648 raeburn 3527: =item * ©rightdescription()
1.112 bowersj2 3528:
3529: returns description of a specified copyright id
3530:
3531: =cut
3532:
3533: sub copyrightdescription {
1.166 www 3534: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3535: }
1.197 matthew 3536:
3537: =pod
3538:
1.648 raeburn 3539: =item * &source_copyrightids()
1.192 taceyjo1 3540:
3541: returns list of all source copyrights
3542:
3543: =cut
3544:
3545: sub source_copyrightids {
3546: return sort(keys(%scprtag));
3547: }
3548:
3549: =pod
3550:
1.648 raeburn 3551: =item * &source_copyrightdescription()
1.192 taceyjo1 3552:
3553: returns description of a specified source copyright id
3554:
3555: =cut
3556:
3557: sub source_copyrightdescription {
3558: return &mt($scprtag{shift(@_)});
3559: }
1.112 bowersj2 3560:
3561: =pod
3562:
1.648 raeburn 3563: =item * &filecategories()
1.112 bowersj2 3564:
3565: returns list of all file categories
3566:
3567: =cut
3568:
3569: sub filecategories {
3570: return sort(keys(%category_extensions));
3571: }
3572:
3573: =pod
3574:
1.648 raeburn 3575: =item * &filecategorytypes()
1.112 bowersj2 3576:
3577: returns list of file types belonging to a given file
3578: category
3579:
3580: =cut
3581:
3582: sub filecategorytypes {
1.356 albertel 3583: my ($cat) = @_;
3584: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3585: }
3586:
3587: =pod
3588:
1.648 raeburn 3589: =item * &fileembstyle()
1.112 bowersj2 3590:
3591: returns embedding style for a specified file type
3592:
3593: =cut
3594:
3595: sub fileembstyle {
3596: return $fe{lc(shift(@_))};
1.169 www 3597: }
3598:
1.351 www 3599: sub filemimetype {
3600: return $fm{lc(shift(@_))};
3601: }
3602:
1.169 www 3603:
3604: sub filecategoryselect {
3605: my ($name,$value)=@_;
1.189 matthew 3606: return &select_form($value,$name,
1.970 raeburn 3607: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3608: }
3609:
3610: =pod
3611:
1.648 raeburn 3612: =item * &filedescription()
1.112 bowersj2 3613:
3614: returns description for a specified file type
3615:
3616: =cut
3617:
3618: sub filedescription {
1.188 matthew 3619: my $file_description = $fd{lc(shift())};
3620: $file_description =~ s:([\[\]]):~$1:g;
3621: return &mt($file_description);
1.112 bowersj2 3622: }
3623:
3624: =pod
3625:
1.648 raeburn 3626: =item * &filedescriptionex()
1.112 bowersj2 3627:
3628: returns description for a specified file type with
3629: extra formatting
3630:
3631: =cut
3632:
3633: sub filedescriptionex {
3634: my $ex=shift;
1.188 matthew 3635: my $file_description = $fd{lc($ex)};
3636: $file_description =~ s:([\[\]]):~$1:g;
3637: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3638: }
3639:
3640: # End of .tab access
3641: =pod
3642:
3643: =back
3644:
3645: =cut
3646:
3647: # ------------------------------------------------------------------ File Types
3648: sub fileextensions {
3649: return sort(keys(%fe));
3650: }
3651:
1.97 www 3652: # ----------------------------------------------------------- Display Languages
3653: # returns a hash with all desired display languages
3654: #
3655:
3656: sub display_languages {
3657: my %languages=();
1.695 raeburn 3658: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3659: $languages{$lang}=1;
1.97 www 3660: }
3661: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3662: if ($env{'form.displaylanguage'}) {
1.356 albertel 3663: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3664: $languages{$lang}=1;
1.97 www 3665: }
3666: }
3667: return %languages;
1.14 harris41 3668: }
3669:
1.582 albertel 3670: sub languages {
3671: my ($possible_langs) = @_;
1.695 raeburn 3672: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3673: if (!ref($possible_langs)) {
3674: if( wantarray ) {
3675: return @preferred_langs;
3676: } else {
3677: return $preferred_langs[0];
3678: }
3679: }
3680: my %possibilities = map { $_ => 1 } (@$possible_langs);
3681: my @preferred_possibilities;
3682: foreach my $preferred_lang (@preferred_langs) {
3683: if (exists($possibilities{$preferred_lang})) {
3684: push(@preferred_possibilities, $preferred_lang);
3685: }
3686: }
3687: if( wantarray ) {
3688: return @preferred_possibilities;
3689: }
3690: return $preferred_possibilities[0];
3691: }
3692:
1.742 raeburn 3693: sub user_lang {
3694: my ($touname,$toudom,$fromcid) = @_;
3695: my @userlangs;
3696: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3697: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3698: $env{'course.'.$fromcid.'.languages'}));
3699: } else {
3700: my %langhash = &getlangs($touname,$toudom);
3701: if ($langhash{'languages'} ne '') {
3702: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3703: } else {
3704: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3705: if ($domdefs{'lang_def'} ne '') {
3706: @userlangs = ($domdefs{'lang_def'});
3707: }
3708: }
3709: }
3710: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3711: my $user_lh = Apache::localize->get_handle(@languages);
3712: return $user_lh;
3713: }
3714:
3715:
1.112 bowersj2 3716: ###############################################################
3717: ## Student Answer Attempts ##
3718: ###############################################################
3719:
3720: =pod
3721:
3722: =head1 Alternate Problem Views
3723:
3724: =over 4
3725:
1.648 raeburn 3726: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3727: $getattempt, $regexp, $gradesub)
3728:
3729: Return string with previous attempt on problem. Arguments:
3730:
3731: =over 4
3732:
3733: =item * $symb: Problem, including path
3734:
3735: =item * $username: username of the desired student
3736:
3737: =item * $domain: domain of the desired student
1.14 harris41 3738:
1.112 bowersj2 3739: =item * $course: Course ID
1.14 harris41 3740:
1.112 bowersj2 3741: =item * $getattempt: Leave blank for all attempts, otherwise put
3742: something
1.14 harris41 3743:
1.112 bowersj2 3744: =item * $regexp: if string matches this regexp, the string will be
3745: sent to $gradesub
1.14 harris41 3746:
1.112 bowersj2 3747: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3748:
1.112 bowersj2 3749: =back
1.14 harris41 3750:
1.112 bowersj2 3751: The output string is a table containing all desired attempts, if any.
1.16 harris41 3752:
1.112 bowersj2 3753: =cut
1.1 albertel 3754:
3755: sub get_previous_attempt {
1.43 ng 3756: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3757: my $prevattempts='';
1.43 ng 3758: no strict 'refs';
1.1 albertel 3759: if ($symb) {
1.3 albertel 3760: my (%returnhash)=
3761: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3762: if ($returnhash{'version'}) {
3763: my %lasthash=();
3764: my $version;
3765: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3766: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3767: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3768: }
1.1 albertel 3769: }
1.596 albertel 3770: $prevattempts=&start_data_table().&start_data_table_header_row();
3771: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3772: my (%typeparts,%lasthidden);
1.945 raeburn 3773: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3774: foreach my $key (sort(keys(%lasthash))) {
3775: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3776: if ($#parts > 0) {
1.31 albertel 3777: my $data=$parts[-1];
1.989 raeburn 3778: next if ($data eq 'foilorder');
1.31 albertel 3779: pop(@parts);
1.1010 www 3780: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3781: if ($data eq 'type') {
3782: unless ($showsurv) {
3783: my $id = join(',',@parts);
3784: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3785: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3786: $lasthidden{$ign.'.'.$id} = 1;
3787: }
1.945 raeburn 3788: }
1.1010 www 3789: }
1.31 albertel 3790: } else {
1.41 ng 3791: if ($#parts == 0) {
3792: $prevattempts.='<th>'.$parts[0].'</th>';
3793: } else {
3794: $prevattempts.='<th>'.$ign.'</th>';
3795: }
1.31 albertel 3796: }
1.16 harris41 3797: }
1.596 albertel 3798: $prevattempts.=&end_data_table_header_row();
1.40 ng 3799: if ($getattempt eq '') {
3800: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3801: my @hidden;
3802: if (%typeparts) {
3803: foreach my $id (keys(%typeparts)) {
3804: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3805: push(@hidden,$id);
3806: }
3807: }
3808: }
3809: $prevattempts.=&start_data_table_row().
3810: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3811: if (@hidden) {
3812: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3813: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3814: my $hide;
3815: foreach my $id (@hidden) {
3816: if ($key =~ /^\Q$id\E/) {
3817: $hide = 1;
3818: last;
3819: }
3820: }
3821: if ($hide) {
3822: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3823: if (($data eq 'award') || ($data eq 'awarddetail')) {
3824: my $value = &format_previous_attempt_value($key,
3825: $returnhash{$version.':'.$key});
3826: $prevattempts.='<td>'.$value.' </td>';
3827: } else {
3828: $prevattempts.='<td> </td>';
3829: }
3830: } else {
3831: if ($key =~ /\./) {
3832: my $value = &format_previous_attempt_value($key,
3833: $returnhash{$version.':'.$key});
3834: $prevattempts.='<td>'.$value.' </td>';
3835: } else {
3836: $prevattempts.='<td> </td>';
3837: }
3838: }
3839: }
3840: } else {
3841: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3842: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3843: my $value = &format_previous_attempt_value($key,
3844: $returnhash{$version.':'.$key});
3845: $prevattempts.='<td>'.$value.' </td>';
3846: }
3847: }
3848: $prevattempts.=&end_data_table_row();
1.40 ng 3849: }
1.1 albertel 3850: }
1.945 raeburn 3851: my @currhidden = keys(%lasthidden);
1.596 albertel 3852: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3853: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3854: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3855: if (%typeparts) {
3856: my $hidden;
3857: foreach my $id (@currhidden) {
3858: if ($key =~ /^\Q$id\E/) {
3859: $hidden = 1;
3860: last;
3861: }
3862: }
3863: if ($hidden) {
3864: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3865: if (($data eq 'award') || ($data eq 'awarddetail')) {
3866: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3867: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3868: $value = &$gradesub($value);
3869: }
3870: $prevattempts.='<td>'.$value.' </td>';
3871: } else {
3872: $prevattempts.='<td> </td>';
3873: }
3874: } else {
3875: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3876: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3877: $value = &$gradesub($value);
3878: }
3879: $prevattempts.='<td>'.$value.' </td>';
3880: }
3881: } else {
3882: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3883: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3884: $value = &$gradesub($value);
3885: }
3886: $prevattempts.='<td>'.$value.' </td>';
3887: }
1.16 harris41 3888: }
1.596 albertel 3889: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3890: } else {
1.596 albertel 3891: $prevattempts=
3892: &start_data_table().&start_data_table_row().
3893: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3894: &end_data_table_row().&end_data_table();
1.1 albertel 3895: }
3896: } else {
1.596 albertel 3897: $prevattempts=
3898: &start_data_table().&start_data_table_row().
3899: '<td>'.&mt('No data.').'</td>'.
3900: &end_data_table_row().&end_data_table();
1.1 albertel 3901: }
1.10 albertel 3902: }
3903:
1.581 albertel 3904: sub format_previous_attempt_value {
3905: my ($key,$value) = @_;
1.1011 www 3906: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3907: $value = &Apache::lonlocal::locallocaltime($value);
3908: } elsif (ref($value) eq 'ARRAY') {
3909: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3910: } elsif ($key =~ /answerstring$/) {
3911: my %answers = &Apache::lonnet::str2hash($value);
3912: my @anskeys = sort(keys(%answers));
3913: if (@anskeys == 1) {
3914: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3915: if ($answer =~ m{\0}) {
3916: $answer =~ s{\0}{,}g;
1.988 raeburn 3917: }
3918: my $tag_internal_answer_name = 'INTERNAL';
3919: if ($anskeys[0] eq $tag_internal_answer_name) {
3920: $value = $answer;
3921: } else {
3922: $value = $anskeys[0].'='.$answer;
3923: }
3924: } else {
3925: foreach my $ans (@anskeys) {
3926: my $answer = $answers{$ans};
1.1001 raeburn 3927: if ($answer =~ m{\0}) {
3928: $answer =~ s{\0}{,}g;
1.988 raeburn 3929: }
3930: $value .= $ans.'='.$answer.'<br />';;
3931: }
3932: }
1.581 albertel 3933: } else {
3934: $value = &unescape($value);
3935: }
3936: return $value;
3937: }
3938:
3939:
1.107 albertel 3940: sub relative_to_absolute {
3941: my ($url,$output)=@_;
3942: my $parser=HTML::TokeParser->new(\$output);
3943: my $token;
3944: my $thisdir=$url;
3945: my @rlinks=();
3946: while ($token=$parser->get_token) {
3947: if ($token->[0] eq 'S') {
3948: if ($token->[1] eq 'a') {
3949: if ($token->[2]->{'href'}) {
3950: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3951: }
3952: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3953: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3954: } elsif ($token->[1] eq 'base') {
3955: $thisdir=$token->[2]->{'href'};
3956: }
3957: }
3958: }
3959: $thisdir=~s-/[^/]*$--;
1.356 albertel 3960: foreach my $link (@rlinks) {
1.726 raeburn 3961: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 3962: ($link=~/^\//) ||
3963: ($link=~/^javascript:/i) ||
3964: ($link=~/^mailto:/i) ||
3965: ($link=~/^\#/)) {
3966: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
3967: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 3968: }
3969: }
3970: # -------------------------------------------------- Deal with Applet codebases
3971: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
3972: return $output;
3973: }
3974:
1.112 bowersj2 3975: =pod
3976:
1.648 raeburn 3977: =item * &get_student_view()
1.112 bowersj2 3978:
3979: show a snapshot of what student was looking at
3980:
3981: =cut
3982:
1.10 albertel 3983: sub get_student_view {
1.186 albertel 3984: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 3985: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 3986: my (%form);
1.10 albertel 3987: my @elements=('symb','courseid','domain','username');
3988: foreach my $element (@elements) {
1.186 albertel 3989: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 3990: }
1.186 albertel 3991: if (defined($moreenv)) {
3992: %form=(%form,%{$moreenv});
3993: }
1.236 albertel 3994: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 3995: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 3996: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 3997: $userview=~s/\<body[^\>]*\>//gi;
3998: $userview=~s/\<\/body\>//gi;
3999: $userview=~s/\<html\>//gi;
4000: $userview=~s/\<\/html\>//gi;
4001: $userview=~s/\<head\>//gi;
4002: $userview=~s/\<\/head\>//gi;
4003: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4004: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4005: if (wantarray) {
4006: return ($userview,$response);
4007: } else {
4008: return $userview;
4009: }
4010: }
4011:
4012: sub get_student_view_with_retries {
4013: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4014:
4015: my $ok = 0; # True if we got a good response.
4016: my $content;
4017: my $response;
4018:
4019: # Try to get the student_view done. within the retries count:
4020:
4021: do {
4022: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4023: $ok = $response->is_success;
4024: if (!$ok) {
4025: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4026: }
4027: $retries--;
4028: } while (!$ok && ($retries > 0));
4029:
4030: if (!$ok) {
4031: $content = ''; # On error return an empty content.
4032: }
1.651 www 4033: if (wantarray) {
4034: return ($content, $response);
4035: } else {
4036: return $content;
4037: }
1.11 albertel 4038: }
4039:
1.112 bowersj2 4040: =pod
4041:
1.648 raeburn 4042: =item * &get_student_answers()
1.112 bowersj2 4043:
4044: show a snapshot of how student was answering problem
4045:
4046: =cut
4047:
1.11 albertel 4048: sub get_student_answers {
1.100 sakharuk 4049: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4050: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4051: my (%moreenv);
1.11 albertel 4052: my @elements=('symb','courseid','domain','username');
4053: foreach my $element (@elements) {
1.186 albertel 4054: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4055: }
1.186 albertel 4056: $moreenv{'grade_target'}='answer';
4057: %moreenv=(%form,%moreenv);
1.497 raeburn 4058: $feedurl = &Apache::lonnet::clutter($feedurl);
4059: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4060: return $userview;
1.1 albertel 4061: }
1.116 albertel 4062:
4063: =pod
4064:
4065: =item * &submlink()
4066:
1.242 albertel 4067: Inputs: $text $uname $udom $symb $target
1.116 albertel 4068:
4069: Returns: A link to grades.pm such as to see the SUBM view of a student
4070:
4071: =cut
4072:
4073: ###############################################
4074: sub submlink {
1.242 albertel 4075: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4076: if (!($uname && $udom)) {
4077: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4078: &Apache::lonnet::whichuser($symb);
1.116 albertel 4079: if (!$symb) { $symb=$cursymb; }
4080: }
1.254 matthew 4081: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4082: $symb=&escape($symb);
1.960 bisitz 4083: if ($target) { $target=" target=\"$target\""; }
4084: return
4085: '<a href="/adm/grades?command=submission'.
4086: '&symb='.$symb.
4087: '&student='.$uname.
4088: '&userdom='.$udom.'"'.
4089: $target.'>'.$text.'</a>';
1.242 albertel 4090: }
4091: ##############################################
4092:
4093: =pod
4094:
4095: =item * &pgrdlink()
4096:
4097: Inputs: $text $uname $udom $symb $target
4098:
4099: Returns: A link to grades.pm such as to see the PGRD view of a student
4100:
4101: =cut
4102:
4103: ###############################################
4104: sub pgrdlink {
4105: my $link=&submlink(@_);
4106: $link=~s/(&command=submission)/$1&showgrading=yes/;
4107: return $link;
4108: }
4109: ##############################################
4110:
4111: =pod
4112:
4113: =item * &pprmlink()
4114:
4115: Inputs: $text $uname $udom $symb $target
4116:
4117: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4118: student and a specific resource
1.242 albertel 4119:
4120: =cut
4121:
4122: ###############################################
4123: sub pprmlink {
4124: my ($text,$uname,$udom,$symb,$target)=@_;
4125: if (!($uname && $udom)) {
4126: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4127: &Apache::lonnet::whichuser($symb);
1.242 albertel 4128: if (!$symb) { $symb=$cursymb; }
4129: }
1.254 matthew 4130: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4131: $symb=&escape($symb);
1.242 albertel 4132: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4133: return '<a href="/adm/parmset?command=set&'.
4134: 'symb='.$symb.'&uname='.$uname.
4135: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4136: }
4137: ##############################################
1.37 matthew 4138:
1.112 bowersj2 4139: =pod
4140:
4141: =back
4142:
4143: =cut
4144:
1.37 matthew 4145: ###############################################
1.51 www 4146:
4147:
4148: sub timehash {
1.687 raeburn 4149: my ($thistime) = @_;
4150: my $timezone = &Apache::lonlocal::gettimezone();
4151: my $dt = DateTime->from_epoch(epoch => $thistime)
4152: ->set_time_zone($timezone);
4153: my $wday = $dt->day_of_week();
4154: if ($wday == 7) { $wday = 0; }
4155: return ( 'second' => $dt->second(),
4156: 'minute' => $dt->minute(),
4157: 'hour' => $dt->hour(),
4158: 'day' => $dt->day_of_month(),
4159: 'month' => $dt->month(),
4160: 'year' => $dt->year(),
4161: 'weekday' => $wday,
4162: 'dayyear' => $dt->day_of_year(),
4163: 'dlsav' => $dt->is_dst() );
1.51 www 4164: }
4165:
1.370 www 4166: sub utc_string {
4167: my ($date)=@_;
1.371 www 4168: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4169: }
4170:
1.51 www 4171: sub maketime {
4172: my %th=@_;
1.687 raeburn 4173: my ($epoch_time,$timezone,$dt);
4174: $timezone = &Apache::lonlocal::gettimezone();
4175: eval {
4176: $dt = DateTime->new( year => $th{'year'},
4177: month => $th{'month'},
4178: day => $th{'day'},
4179: hour => $th{'hour'},
4180: minute => $th{'minute'},
4181: second => $th{'second'},
4182: time_zone => $timezone,
4183: );
4184: };
4185: if (!$@) {
4186: $epoch_time = $dt->epoch;
4187: if ($epoch_time) {
4188: return $epoch_time;
4189: }
4190: }
1.51 www 4191: return POSIX::mktime(
4192: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4193: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4194: }
4195:
4196: #########################################
1.51 www 4197:
4198: sub findallcourses {
1.482 raeburn 4199: my ($roles,$uname,$udom) = @_;
1.355 albertel 4200: my %roles;
4201: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4202: my %courses;
1.51 www 4203: my $now=time;
1.482 raeburn 4204: if (!defined($uname)) {
4205: $uname = $env{'user.name'};
4206: }
4207: if (!defined($udom)) {
4208: $udom = $env{'user.domain'};
4209: }
4210: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4211: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4212: if (!%roles) {
4213: %roles = (
4214: cc => 1,
1.907 raeburn 4215: co => 1,
1.482 raeburn 4216: in => 1,
4217: ep => 1,
4218: ta => 1,
4219: cr => 1,
4220: st => 1,
4221: );
4222: }
4223: foreach my $entry (keys(%roleshash)) {
4224: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4225: if ($trole =~ /^cr/) {
4226: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4227: } else {
4228: next if (!exists($roles{$trole}));
4229: }
4230: if ($tend) {
4231: next if ($tend < $now);
4232: }
4233: if ($tstart) {
4234: next if ($tstart > $now);
4235: }
1.1058 raeburn 4236: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4237: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4238: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4239: if ($secpart eq '') {
4240: ($cnum,$role) = split(/_/,$cnumpart);
4241: $sec = 'none';
1.1058 raeburn 4242: $value .= $cnum.'/';
1.482 raeburn 4243: } else {
4244: $cnum = $cnumpart;
4245: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4246: $value .= $cnum.'/'.$sec;
4247: }
4248: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4249: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4250: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4251: }
4252: } else {
4253: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4254: }
1.482 raeburn 4255: }
4256: } else {
4257: foreach my $key (keys(%env)) {
1.483 albertel 4258: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4259: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4260: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4261: next if ($role eq 'ca' || $role eq 'aa');
4262: next if (%roles && !exists($roles{$role}));
4263: my ($starttime,$endtime)=split(/\./,$env{$key});
4264: my $active=1;
4265: if ($starttime) {
4266: if ($now<$starttime) { $active=0; }
4267: }
4268: if ($endtime) {
4269: if ($now>$endtime) { $active=0; }
4270: }
4271: if ($active) {
1.1058 raeburn 4272: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4273: if ($sec eq '') {
4274: $sec = 'none';
1.1058 raeburn 4275: } else {
4276: $value .= $sec;
4277: }
4278: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4279: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4280: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4281: }
4282: } else {
4283: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4284: }
1.474 raeburn 4285: }
4286: }
1.51 www 4287: }
4288: }
1.474 raeburn 4289: return %courses;
1.51 www 4290: }
1.37 matthew 4291:
1.54 www 4292: ###############################################
1.474 raeburn 4293:
4294: sub blockcheck {
1.1062 raeburn 4295: my ($setters,$activity,$uname,$udom,$url) = @_;
1.490 raeburn 4296:
4297: if (!defined($udom)) {
4298: $udom = $env{'user.domain'};
4299: }
4300: if (!defined($uname)) {
4301: $uname = $env{'user.name'};
4302: }
4303:
4304: # If uname and udom are for a course, check for blocks in the course.
4305:
4306: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062 raeburn 4307: my ($startblock,$endblock,$triggerblock) =
4308: &get_blocks($setters,$activity,$udom,$uname,$url);
4309: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4310: }
1.474 raeburn 4311:
1.502 raeburn 4312: my $startblock = 0;
4313: my $endblock = 0;
1.1062 raeburn 4314: my $triggerblock = '';
1.482 raeburn 4315: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4316:
1.490 raeburn 4317: # If uname is for a user, and activity is course-specific, i.e.,
4318: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4319:
1.490 raeburn 4320: if (($activity eq 'boards' || $activity eq 'chat' ||
4321: $activity eq 'groups') && ($env{'request.course.id'})) {
4322: foreach my $key (keys(%live_courses)) {
4323: if ($key ne $env{'request.course.id'}) {
4324: delete($live_courses{$key});
4325: }
4326: }
4327: }
4328:
4329: my $otheruser = 0;
4330: my %own_courses;
4331: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4332: # Resource belongs to user other than current user.
4333: $otheruser = 1;
4334: # Gather courses for current user
4335: %own_courses =
4336: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4337: }
4338:
4339: # Gather active course roles - course coordinator, instructor,
4340: # exam proctor, ta, student, or custom role.
1.474 raeburn 4341:
4342: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4343: my ($cdom,$cnum);
4344: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4345: $cdom = $env{'course.'.$course.'.domain'};
4346: $cnum = $env{'course.'.$course.'.num'};
4347: } else {
1.490 raeburn 4348: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4349: }
4350: my $no_ownblock = 0;
4351: my $no_userblock = 0;
1.533 raeburn 4352: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4353: # Check if current user has 'evb' priv for this
4354: if (defined($own_courses{$course})) {
4355: foreach my $sec (keys(%{$own_courses{$course}})) {
4356: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4357: if ($sec ne 'none') {
4358: $checkrole .= '/'.$sec;
4359: }
4360: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4361: $no_ownblock = 1;
4362: last;
4363: }
4364: }
4365: }
4366: # if they have 'evb' priv and are currently not playing student
4367: next if (($no_ownblock) &&
4368: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4369: }
1.474 raeburn 4370: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4371: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4372: if ($sec ne 'none') {
1.482 raeburn 4373: $checkrole .= '/'.$sec;
1.474 raeburn 4374: }
1.490 raeburn 4375: if ($otheruser) {
4376: # Resource belongs to user other than current user.
4377: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4378: my (%allroles,%userroles);
4379: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4380: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4381: my ($trole,$tdom,$tnum,$tsec);
4382: if ($entry =~ /^cr/) {
4383: ($trole,$tdom,$tnum,$tsec) =
4384: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4385: } else {
4386: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4387: }
4388: my ($spec,$area,$trest);
4389: $area = '/'.$tdom.'/'.$tnum;
4390: $trest = $tnum;
4391: if ($tsec ne '') {
4392: $area .= '/'.$tsec;
4393: $trest .= '/'.$tsec;
4394: }
4395: $spec = $trole.'.'.$area;
4396: if ($trole =~ /^cr/) {
4397: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4398: $tdom,$spec,$trest,$area);
4399: } else {
4400: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4401: $tdom,$spec,$trest,$area);
4402: }
4403: }
4404: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4405: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4406: if ($1) {
4407: $no_userblock = 1;
4408: last;
4409: }
1.486 raeburn 4410: }
4411: }
1.490 raeburn 4412: } else {
4413: # Resource belongs to current user
4414: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4415: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4416: $no_ownblock = 1;
4417: last;
4418: }
1.474 raeburn 4419: }
4420: }
4421: # if they have the evb priv and are currently not playing student
1.482 raeburn 4422: next if (($no_ownblock) &&
1.491 albertel 4423: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4424: next if ($no_userblock);
1.474 raeburn 4425:
1.866 kalberla 4426: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4427: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4428:
1.1062 raeburn 4429: my ($start,$end,$trigger) =
4430: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4431: if (($start != 0) &&
4432: (($startblock == 0) || ($startblock > $start))) {
4433: $startblock = $start;
1.1062 raeburn 4434: if ($trigger ne '') {
4435: $triggerblock = $trigger;
4436: }
1.502 raeburn 4437: }
4438: if (($end != 0) &&
4439: (($endblock == 0) || ($endblock < $end))) {
4440: $endblock = $end;
1.1062 raeburn 4441: if ($trigger ne '') {
4442: $triggerblock = $trigger;
4443: }
1.502 raeburn 4444: }
1.490 raeburn 4445: }
1.1062 raeburn 4446: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4447: }
4448:
4449: sub get_blocks {
1.1062 raeburn 4450: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4451: my $startblock = 0;
4452: my $endblock = 0;
1.1062 raeburn 4453: my $triggerblock = '';
1.490 raeburn 4454: my $course = $cdom.'_'.$cnum;
4455: $setters->{$course} = {};
4456: $setters->{$course}{'staff'} = [];
4457: $setters->{$course}{'times'} = [];
1.1062 raeburn 4458: $setters->{$course}{'triggers'} = [];
4459: my (@blockers,%triggered);
4460: my $now = time;
4461: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4462: if ($activity eq 'docs') {
4463: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4464: foreach my $block (@blockers) {
4465: if ($block =~ /^firstaccess____(.+)$/) {
4466: my $item = $1;
4467: my $type = 'map';
4468: my $timersymb = $item;
4469: if ($item eq 'course') {
4470: $type = 'course';
4471: } elsif ($item =~ /___\d+___/) {
4472: $type = 'resource';
4473: } else {
4474: $timersymb = &Apache::lonnet::symbread($item);
4475: }
4476: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4477: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4478: $triggered{$block} = {
4479: start => $start,
4480: end => $end,
4481: type => $type,
4482: };
4483: }
4484: }
4485: } else {
4486: foreach my $block (keys(%commblocks)) {
4487: if ($block =~ m/^(\d+)____(\d+)$/) {
4488: my ($start,$end) = ($1,$2);
4489: if ($start <= time && $end >= time) {
4490: if (ref($commblocks{$block}) eq 'HASH') {
4491: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4492: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4493: unless(grep(/^\Q$block\E$/,@blockers)) {
4494: push(@blockers,$block);
4495: }
4496: }
4497: }
4498: }
4499: }
4500: } elsif ($block =~ /^firstaccess____(.+)$/) {
4501: my $item = $1;
4502: my $timersymb = $item;
4503: my $type = 'map';
4504: if ($item eq 'course') {
4505: $type = 'course';
4506: } elsif ($item =~ /___\d+___/) {
4507: $type = 'resource';
4508: } else {
4509: $timersymb = &Apache::lonnet::symbread($item);
4510: }
4511: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4512: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4513: if ($start && $end) {
4514: if (($start <= time) && ($end >= time)) {
4515: unless (grep(/^\Q$block\E$/,@blockers)) {
4516: push(@blockers,$block);
4517: $triggered{$block} = {
4518: start => $start,
4519: end => $end,
4520: type => $type,
4521: };
4522: }
4523: }
1.490 raeburn 4524: }
1.1062 raeburn 4525: }
4526: }
4527: }
4528: foreach my $blocker (@blockers) {
4529: my ($staff_name,$staff_dom,$title,$blocks) =
4530: &parse_block_record($commblocks{$blocker});
4531: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4532: my ($start,$end,$triggertype);
4533: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4534: ($start,$end) = ($1,$2);
4535: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4536: $start = $triggered{$blocker}{'start'};
4537: $end = $triggered{$blocker}{'end'};
4538: $triggertype = $triggered{$blocker}{'type'};
4539: }
4540: if ($start) {
4541: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4542: if ($triggertype) {
4543: push(@{$$setters{$course}{'triggers'}},$triggertype);
4544: } else {
4545: push(@{$$setters{$course}{'triggers'}},0);
4546: }
4547: if ( ($startblock == 0) || ($startblock > $start) ) {
4548: $startblock = $start;
4549: if ($triggertype) {
4550: $triggerblock = $blocker;
1.474 raeburn 4551: }
4552: }
1.1062 raeburn 4553: if ( ($endblock == 0) || ($endblock < $end) ) {
4554: $endblock = $end;
4555: if ($triggertype) {
4556: $triggerblock = $blocker;
4557: }
4558: }
1.474 raeburn 4559: }
4560: }
1.1062 raeburn 4561: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4562: }
4563:
4564: sub parse_block_record {
4565: my ($record) = @_;
4566: my ($setuname,$setudom,$title,$blocks);
4567: if (ref($record) eq 'HASH') {
4568: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4569: $title = &unescape($record->{'event'});
4570: $blocks = $record->{'blocks'};
4571: } else {
4572: my @data = split(/:/,$record,3);
4573: if (scalar(@data) eq 2) {
4574: $title = $data[1];
4575: ($setuname,$setudom) = split(/@/,$data[0]);
4576: } else {
4577: ($setuname,$setudom,$title) = @data;
4578: }
4579: $blocks = { 'com' => 'on' };
4580: }
4581: return ($setuname,$setudom,$title,$blocks);
4582: }
4583:
1.854 kalberla 4584: sub blocking_status {
1.1062 raeburn 4585: my ($activity,$uname,$udom,$url) = @_;
1.1061 raeburn 4586: my %setters;
1.890 droeschl 4587:
1.1061 raeburn 4588: # check for active blocking
1.1062 raeburn 4589: my ($startblock,$endblock,$triggerblock) =
4590: &blockcheck(\%setters,$activity,$uname,$udom,$url);
4591: my $blocked = 0;
4592: if ($startblock && $endblock) {
4593: $blocked = 1;
4594: }
1.890 droeschl 4595:
1.1061 raeburn 4596: # caller just wants to know whether a block is active
4597: if (!wantarray) { return $blocked; }
4598:
4599: # build a link to a popup window containing the details
4600: my $querystring = "?activity=$activity";
4601: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4602: if ($activity eq 'port') {
4603: $querystring .= "&udom=$udom" if $udom;
4604: $querystring .= "&uname=$uname" if $uname;
4605: } elsif ($activity eq 'docs') {
4606: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4607: }
1.1061 raeburn 4608:
4609: my $output .= <<'END_MYBLOCK';
4610: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4611: var options = "width=" + w + ",height=" + h + ",";
4612: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4613: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4614: var newWin = window.open(url, wdwName, options);
4615: newWin.focus();
4616: }
1.890 droeschl 4617: END_MYBLOCK
1.854 kalberla 4618:
1.1061 raeburn 4619: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4620:
1.1061 raeburn 4621: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4622: my $text = &mt('Communication Blocked');
4623: if ($activity eq 'docs') {
4624: $text = &mt('Content Access Blocked');
1.1063 raeburn 4625: } elsif ($activity eq 'printout') {
4626: $text = &mt('Printing Blocked');
1.1062 raeburn 4627: }
1.1061 raeburn 4628: $output .= <<"END_BLOCK";
1.867 kalberla 4629: <div class='LC_comblock'>
1.869 kalberla 4630: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4631: title='$text'>
4632: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4633: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4634: title='$text'>$text</a>
1.867 kalberla 4635: </div>
4636:
4637: END_BLOCK
1.474 raeburn 4638:
1.1061 raeburn 4639: return ($blocked, $output);
1.854 kalberla 4640: }
1.490 raeburn 4641:
1.60 matthew 4642: ###############################################
4643:
1.682 raeburn 4644: sub check_ip_acc {
4645: my ($acc)=@_;
4646: &Apache::lonxml::debug("acc is $acc");
4647: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4648: return 1;
4649: }
4650: my $allowed=0;
4651: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4652:
4653: my $name;
4654: foreach my $pattern (split(',',$acc)) {
4655: $pattern =~ s/^\s*//;
4656: $pattern =~ s/\s*$//;
4657: if ($pattern =~ /\*$/) {
4658: #35.8.*
4659: $pattern=~s/\*//;
4660: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4661: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4662: #35.8.3.[34-56]
4663: my $low=$2;
4664: my $high=$3;
4665: $pattern=$1;
4666: if ($ip =~ /^\Q$pattern\E/) {
4667: my $last=(split(/\./,$ip))[3];
4668: if ($last <=$high && $last >=$low) { $allowed=1; }
4669: }
4670: } elsif ($pattern =~ /^\*/) {
4671: #*.msu.edu
4672: $pattern=~s/\*//;
4673: if (!defined($name)) {
4674: use Socket;
4675: my $netaddr=inet_aton($ip);
4676: ($name)=gethostbyaddr($netaddr,AF_INET);
4677: }
4678: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4679: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4680: #127.0.0.1
4681: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4682: } else {
4683: #some.name.com
4684: if (!defined($name)) {
4685: use Socket;
4686: my $netaddr=inet_aton($ip);
4687: ($name)=gethostbyaddr($netaddr,AF_INET);
4688: }
4689: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4690: }
4691: if ($allowed) { last; }
4692: }
4693: return $allowed;
4694: }
4695:
4696: ###############################################
4697:
1.60 matthew 4698: =pod
4699:
1.112 bowersj2 4700: =head1 Domain Template Functions
4701:
4702: =over 4
4703:
4704: =item * &determinedomain()
1.60 matthew 4705:
4706: Inputs: $domain (usually will be undef)
4707:
1.63 www 4708: Returns: Determines which domain should be used for designs
1.60 matthew 4709:
4710: =cut
1.54 www 4711:
1.60 matthew 4712: ###############################################
1.63 www 4713: sub determinedomain {
4714: my $domain=shift;
1.531 albertel 4715: if (! $domain) {
1.60 matthew 4716: # Determine domain if we have not been given one
1.893 raeburn 4717: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4718: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4719: if ($env{'request.role.domain'}) {
4720: $domain=$env{'request.role.domain'};
1.60 matthew 4721: }
4722: }
1.63 www 4723: return $domain;
4724: }
4725: ###############################################
1.517 raeburn 4726:
1.518 albertel 4727: sub devalidate_domconfig_cache {
4728: my ($udom)=@_;
4729: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4730: }
4731:
4732: # ---------------------- Get domain configuration for a domain
4733: sub get_domainconf {
4734: my ($udom) = @_;
4735: my $cachetime=1800;
4736: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4737: if (defined($cached)) { return %{$result}; }
4738:
4739: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4740: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4741: my (%designhash,%legacy);
1.518 albertel 4742: if (keys(%domconfig) > 0) {
4743: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4744: if (keys(%{$domconfig{'login'}})) {
4745: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4746: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4747: if ($key eq 'loginvia') {
4748: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4749: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4750: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4751: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4752: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4753: $designhash{$udom.'.login.loginvia'} = $server;
4754: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4755:
4756: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4757: } else {
1.1013 raeburn 4758: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4759: }
4760: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4761: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4762: }
1.946 raeburn 4763: }
4764: }
4765: }
4766: }
4767: } else {
4768: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4769: $designhash{$udom.'.login.'.$key.'_'.$img} =
4770: $domconfig{'login'}{$key}{$img};
4771: }
1.699 raeburn 4772: }
4773: } else {
4774: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4775: }
1.632 raeburn 4776: }
4777: } else {
4778: $legacy{'login'} = 1;
1.518 albertel 4779: }
1.632 raeburn 4780: } else {
4781: $legacy{'login'} = 1;
1.518 albertel 4782: }
4783: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4784: if (keys(%{$domconfig{'rolecolors'}})) {
4785: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4786: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4787: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4788: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4789: }
1.518 albertel 4790: }
4791: }
1.632 raeburn 4792: } else {
4793: $legacy{'rolecolors'} = 1;
1.518 albertel 4794: }
1.632 raeburn 4795: } else {
4796: $legacy{'rolecolors'} = 1;
1.518 albertel 4797: }
1.948 raeburn 4798: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4799: if ($domconfig{'autoenroll'}{'co-owners'}) {
4800: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4801: }
4802: }
1.632 raeburn 4803: if (keys(%legacy) > 0) {
4804: my %legacyhash = &get_legacy_domconf($udom);
4805: foreach my $item (keys(%legacyhash)) {
4806: if ($item =~ /^\Q$udom\E\.login/) {
4807: if ($legacy{'login'}) {
4808: $designhash{$item} = $legacyhash{$item};
4809: }
4810: } else {
4811: if ($legacy{'rolecolors'}) {
4812: $designhash{$item} = $legacyhash{$item};
4813: }
1.518 albertel 4814: }
4815: }
4816: }
1.632 raeburn 4817: } else {
4818: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4819: }
4820: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4821: $cachetime);
4822: return %designhash;
4823: }
4824:
1.632 raeburn 4825: sub get_legacy_domconf {
4826: my ($udom) = @_;
4827: my %legacyhash;
4828: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4829: my $designfile = $designdir.'/'.$udom.'.tab';
4830: if (-e $designfile) {
4831: if ( open (my $fh,"<$designfile") ) {
4832: while (my $line = <$fh>) {
4833: next if ($line =~ /^\#/);
4834: chomp($line);
4835: my ($key,$val)=(split(/\=/,$line));
4836: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4837: }
4838: close($fh);
4839: }
4840: }
1.1026 raeburn 4841: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4842: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4843: }
4844: return %legacyhash;
4845: }
4846:
1.63 www 4847: =pod
4848:
1.112 bowersj2 4849: =item * &domainlogo()
1.63 www 4850:
4851: Inputs: $domain (usually will be undef)
4852:
4853: Returns: A link to a domain logo, if the domain logo exists.
4854: If the domain logo does not exist, a description of the domain.
4855:
4856: =cut
1.112 bowersj2 4857:
1.63 www 4858: ###############################################
4859: sub domainlogo {
1.517 raeburn 4860: my $domain = &determinedomain(shift);
1.518 albertel 4861: my %designhash = &get_domainconf($domain);
1.517 raeburn 4862: # See if there is a logo
4863: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4864: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4865: if ($imgsrc =~ m{^/(adm|res)/}) {
4866: if ($imgsrc =~ m{^/res/}) {
4867: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4868: &Apache::lonnet::repcopy($local_name);
4869: }
4870: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4871: }
4872: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4873: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4874: return &Apache::lonnet::domain($domain,'description');
1.59 www 4875: } else {
1.60 matthew 4876: return '';
1.59 www 4877: }
4878: }
1.63 www 4879: ##############################################
4880:
4881: =pod
4882:
1.112 bowersj2 4883: =item * &designparm()
1.63 www 4884:
4885: Inputs: $which parameter; $domain (usually will be undef)
4886:
4887: Returns: value of designparamter $which
4888:
4889: =cut
1.112 bowersj2 4890:
1.397 albertel 4891:
1.400 albertel 4892: ##############################################
1.397 albertel 4893: sub designparm {
4894: my ($which,$domain)=@_;
4895: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4896: return $env{'environment.color.'.$which};
1.96 www 4897: }
1.63 www 4898: $domain=&determinedomain($domain);
1.1016 raeburn 4899: my %domdesign;
4900: unless ($domain eq 'public') {
4901: %domdesign = &get_domainconf($domain);
4902: }
1.520 raeburn 4903: my $output;
1.517 raeburn 4904: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4905: $output = $domdesign{$domain.'.'.$which};
1.63 www 4906: } else {
1.520 raeburn 4907: $output = $defaultdesign{$which};
4908: }
4909: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4910: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4911: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4912: if ($output =~ m{^/res/}) {
4913: my $local_name = &Apache::lonnet::filelocation('',$output);
4914: &Apache::lonnet::repcopy($local_name);
4915: }
1.520 raeburn 4916: $output = &lonhttpdurl($output);
4917: }
1.63 www 4918: }
1.520 raeburn 4919: return $output;
1.63 www 4920: }
1.59 www 4921:
1.822 bisitz 4922: ##############################################
4923: =pod
4924:
1.832 bisitz 4925: =item * &authorspace()
4926:
1.1028 raeburn 4927: Inputs: $url (usually will be undef).
1.832 bisitz 4928:
1.1028 raeburn 4929: Returns: Path to Construction Space containing the resource or
4930: directory being viewed (or for which action is being taken).
4931: If $url is provided, and begins /priv/<domain>/<uname>
4932: the path will be that portion of the $context argument.
4933: Otherwise the path will be for the author space of the current
4934: user when the current role is author, or for that of the
4935: co-author/assistant co-author space when the current role
4936: is co-author or assistant co-author.
1.832 bisitz 4937:
4938: =cut
4939:
4940: sub authorspace {
1.1028 raeburn 4941: my ($url) = @_;
4942: if ($url ne '') {
4943: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4944: return $1;
4945: }
4946: }
1.832 bisitz 4947: my $caname = '';
1.1024 www 4948: my $cadom = '';
1.1028 raeburn 4949: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4950: ($cadom,$caname) =
1.832 bisitz 4951: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4952: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4953: $caname = $env{'user.name'};
1.1024 www 4954: $cadom = $env{'user.domain'};
1.832 bisitz 4955: }
1.1028 raeburn 4956: if (($caname ne '') && ($cadom ne '')) {
4957: return "/priv/$cadom/$caname/";
4958: }
4959: return;
1.832 bisitz 4960: }
4961:
4962: ##############################################
4963: =pod
4964:
1.822 bisitz 4965: =item * &head_subbox()
4966:
4967: Inputs: $content (contains HTML code with page functions, etc.)
4968:
4969: Returns: HTML div with $content
4970: To be included in page header
4971:
4972: =cut
4973:
4974: sub head_subbox {
4975: my ($content)=@_;
4976: my $output =
1.993 raeburn 4977: '<div class="LC_head_subbox">'
1.822 bisitz 4978: .$content
4979: .'</div>'
4980: }
4981:
4982: ##############################################
4983: =pod
4984:
4985: =item * &CSTR_pageheader()
4986:
1.1026 raeburn 4987: Input: (optional) filename from which breadcrumb trail is built.
4988: In most cases no input as needed, as $env{'request.filename'}
4989: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 4990:
4991: Returns: HTML div with CSTR path and recent box
4992: To be included on Construction Space pages
4993:
4994: =cut
4995:
4996: sub CSTR_pageheader {
1.1026 raeburn 4997: my ($trailfile) = @_;
4998: if ($trailfile eq '') {
4999: $trailfile = $env{'request.filename'};
5000: }
5001:
5002: # this is for resources; directories have customtitle, and crumbs
5003: # and select recent are created in lonpubdir.pm
5004:
5005: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5006: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5007: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5008: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5009: $formaction =~ s{/+}{/}g;
1.822 bisitz 5010:
5011: my $parentpath = '';
5012: my $lastitem = '';
5013: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5014: $parentpath = $1;
5015: $lastitem = $2;
5016: } else {
5017: $lastitem = $thisdisfn;
5018: }
1.921 bisitz 5019:
5020: my $output =
1.822 bisitz 5021: '<div>'
5022: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
5023: .'<b>'.&mt('Construction Space:').'</b> '
5024: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5025: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5026: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5027:
5028: if ($lastitem) {
5029: $output .=
5030: '<span class="LC_filename">'
5031: .$lastitem
5032: .'</span>';
5033: }
5034: $output .=
5035: '<br />'
1.822 bisitz 5036: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5037: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5038: .'</form>'
5039: .&Apache::lonmenu::constspaceform()
5040: .'</div>';
1.921 bisitz 5041:
5042: return $output;
1.822 bisitz 5043: }
5044:
1.60 matthew 5045: ###############################################
5046: ###############################################
5047:
5048: =pod
5049:
1.112 bowersj2 5050: =back
5051:
1.549 albertel 5052: =head1 HTML Helpers
1.112 bowersj2 5053:
5054: =over 4
5055:
5056: =item * &bodytag()
1.60 matthew 5057:
5058: Returns a uniform header for LON-CAPA web pages.
5059:
5060: Inputs:
5061:
1.112 bowersj2 5062: =over 4
5063:
5064: =item * $title, A title to be displayed on the page.
5065:
5066: =item * $function, the current role (can be undef).
5067:
5068: =item * $addentries, extra parameters for the <body> tag.
5069:
5070: =item * $bodyonly, if defined, only return the <body> tag.
5071:
5072: =item * $domain, if defined, force a given domain.
5073:
5074: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5075: text interface only)
1.60 matthew 5076:
1.814 bisitz 5077: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5078: navigational links
1.317 albertel 5079:
1.338 albertel 5080: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5081:
1.460 albertel 5082: =item * $args, optional argument valid values are
5083: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5084: inherit_jsmath -> when creating popup window in a page,
5085: should it have jsmath forced on by the
5086: current page
1.460 albertel 5087:
1.1096 raeburn 5088: =item * $advtoolsref, optional argument, ref to an array containing
5089: inlineremote items to be added in "Functions" menu below
5090: breadcrumbs.
5091:
1.112 bowersj2 5092: =back
5093:
1.60 matthew 5094: Returns: A uniform header for LON-CAPA web pages.
5095: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5096: If $bodyonly is undef or zero, an html string containing a <body> tag and
5097: other decorations will be returned.
5098:
5099: =cut
5100:
1.54 www 5101: sub bodytag {
1.831 bisitz 5102: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5103: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5104:
1.954 raeburn 5105: my $public;
5106: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5107: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5108: $public = 1;
5109: }
1.460 albertel 5110: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339 albertel 5111:
1.183 matthew 5112: $function = &get_users_function() if (!$function);
1.339 albertel 5113: my $img = &designparm($function.'.img',$domain);
5114: my $font = &designparm($function.'.font',$domain);
5115: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5116:
1.803 bisitz 5117: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5118: 'bgcolor' => $pgbg,
1.339 albertel 5119: 'text' => $font,
5120: 'alink' => &designparm($function.'.alink',$domain),
5121: 'vlink' => &designparm($function.'.vlink',$domain),
5122: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5123: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5124:
1.63 www 5125: # role and realm
1.378 raeburn 5126: my ($role,$realm) = split(/\./,$env{'request.role'},2);
5127: if ($role eq 'ca') {
1.479 albertel 5128: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5129: $realm = &plainname($rname,$rdom);
1.378 raeburn 5130: }
1.55 www 5131: # realm
1.258 albertel 5132: if ($env{'request.course.id'}) {
1.378 raeburn 5133: if ($env{'request.role'} !~ /^cr/) {
5134: $role = &Apache::lonnet::plaintext($role,&course_type());
5135: }
1.898 raeburn 5136: if ($env{'request.course.sec'}) {
5137: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5138: }
1.359 albertel 5139: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5140: } else {
5141: $role = &Apache::lonnet::plaintext($role);
1.54 www 5142: }
1.433 albertel 5143:
1.359 albertel 5144: if (!$realm) { $realm=' '; }
1.330 albertel 5145:
1.438 albertel 5146: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5147:
1.101 www 5148: # construct main body tag
1.359 albertel 5149: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5150: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5151:
1.530 albertel 5152: if ($bodyonly) {
1.60 matthew 5153: return $bodytag;
1.798 tempelho 5154: }
1.359 albertel 5155:
1.410 albertel 5156: my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954 raeburn 5157: if ($public) {
1.433 albertel 5158: undef($role);
1.434 albertel 5159: } else {
1.1070 raeburn 5160: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5161: undef,'LC_menubuttons_link');
1.433 albertel 5162: }
1.359 albertel 5163:
1.762 bisitz 5164: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5165: #
5166: # Extra info if you are the DC
5167: my $dc_info = '';
5168: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5169: $env{'course.'.$env{'request.course.id'}.
5170: '.domain'}.'/'})) {
5171: my $cid = $env{'request.course.id'};
1.917 raeburn 5172: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5173: $dc_info =~ s/\s+$//;
1.359 albertel 5174: }
5175:
1.898 raeburn 5176: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5177: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5178:
1.916 droeschl 5179: if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
5180: return $bodytag;
5181: }
1.903 droeschl 5182:
5183: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5184:
5185: # if ($env{'request.state'} eq 'construct') {
5186: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5187: # }
5188:
1.359 albertel 5189:
5190:
1.916 droeschl 5191: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5192: if ($dc_info) {
5193: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5194: }
1.916 droeschl 5195: $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
5196: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5197: return $bodytag;
5198: }
1.894 droeschl 5199:
1.927 raeburn 5200: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
5201: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
5202: }
1.916 droeschl 5203:
1.903 droeschl 5204: $bodytag .= Apache::lonhtmlcommon::scripttag(
5205: Apache::lonmenu::utilityfunctions(), 'start');
1.816 bisitz 5206:
1.903 droeschl 5207: $bodytag .= Apache::lonmenu::primary_menu();
1.852 droeschl 5208:
1.917 raeburn 5209: if ($dc_info) {
5210: $dc_info = &dc_courseid_toggle($dc_info);
5211: }
5212: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5213:
1.903 droeschl 5214: #don't show menus for public users
1.954 raeburn 5215: if (!$public){
1.903 droeschl 5216: $bodytag .= Apache::lonmenu::secondary_menu();
5217: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5218: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5219: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5220: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5221: $args->{'bread_crumbs'});
1.1096 raeburn 5222: } elsif ($forcereg) {
5223: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5224: $args->{'group'});
5225: } else {
5226: $bodytag .=
5227: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5228: $forcereg,$args->{'group'},
5229: $args->{'bread_crumbs'},
5230: $advtoolsref);
1.920 raeburn 5231: }
1.903 droeschl 5232: }else{
5233: # this is to seperate menu from content when there's no secondary
5234: # menu. Especially needed for public accessible ressources.
5235: $bodytag .= '<hr style="clear:both" />';
5236: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5237: }
1.903 droeschl 5238:
1.235 raeburn 5239: return $bodytag;
1.182 matthew 5240: }
5241:
1.917 raeburn 5242: sub dc_courseid_toggle {
5243: my ($dc_info) = @_;
1.980 raeburn 5244: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5245: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5246: &mt('(More ...)').'</a></span>'.
5247: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5248: }
5249:
1.330 albertel 5250: sub make_attr_string {
5251: my ($register,$attr_ref) = @_;
5252:
5253: if ($attr_ref && !ref($attr_ref)) {
5254: die("addentries Must be a hash ref ".
5255: join(':',caller(1))." ".
5256: join(':',caller(0))." ");
5257: }
5258:
5259: if ($register) {
1.339 albertel 5260: my ($on_load,$on_unload);
5261: foreach my $key (keys(%{$attr_ref})) {
5262: if (lc($key) eq 'onload') {
5263: $on_load.=$attr_ref->{$key}.';';
5264: delete($attr_ref->{$key});
5265:
5266: } elsif (lc($key) eq 'onunload') {
5267: $on_unload.=$attr_ref->{$key}.';';
5268: delete($attr_ref->{$key});
5269: }
5270: }
1.953 droeschl 5271: $attr_ref->{'onload'} = $on_load;
5272: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5273: }
1.339 albertel 5274:
1.330 albertel 5275: my $attr_string;
5276: foreach my $attr (keys(%$attr_ref)) {
5277: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5278: }
5279: return $attr_string;
5280: }
5281:
5282:
1.182 matthew 5283: ###############################################
1.251 albertel 5284: ###############################################
5285:
5286: =pod
5287:
5288: =item * &endbodytag()
5289:
5290: Returns a uniform footer for LON-CAPA web pages.
5291:
1.635 raeburn 5292: Inputs: 1 - optional reference to an args hash
5293: If in the hash, key for noredirectlink has a value which evaluates to true,
5294: a 'Continue' link is not displayed if the page contains an
5295: internal redirect in the <head></head> section,
5296: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5297:
5298: =cut
5299:
5300: sub endbodytag {
1.635 raeburn 5301: my ($args) = @_;
1.1080 raeburn 5302: my $endbodytag;
5303: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5304: $endbodytag='</body>';
5305: }
1.269 albertel 5306: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5307: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5308: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5309: $endbodytag=
5310: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5311: &mt('Continue').'</a>'.
5312: $endbodytag;
5313: }
1.315 albertel 5314: }
1.251 albertel 5315: return $endbodytag;
5316: }
5317:
1.352 albertel 5318: =pod
5319:
5320: =item * &standard_css()
5321:
5322: Returns a style sheet
5323:
5324: Inputs: (all optional)
5325: domain -> force to color decorate a page for a specific
5326: domain
5327: function -> force usage of a specific rolish color scheme
5328: bgcolor -> override the default page bgcolor
5329:
5330: =cut
5331:
1.343 albertel 5332: sub standard_css {
1.345 albertel 5333: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5334: $function = &get_users_function() if (!$function);
5335: my $img = &designparm($function.'.img', $domain);
5336: my $tabbg = &designparm($function.'.tabbg', $domain);
5337: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5338: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5339: #second colour for later usage
1.345 albertel 5340: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5341: my $pgbg_or_bgcolor =
5342: $bgcolor ||
1.352 albertel 5343: &designparm($function.'.pgbg', $domain);
1.382 albertel 5344: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5345: my $alink = &designparm($function.'.alink', $domain);
5346: my $vlink = &designparm($function.'.vlink', $domain);
5347: my $link = &designparm($function.'.link', $domain);
5348:
1.602 albertel 5349: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5350: my $mono = 'monospace';
1.850 bisitz 5351: my $data_table_head = $sidebg;
5352: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5353: my $data_table_dark = '#E0E0E0';
1.470 banghart 5354: my $data_table_darker = '#CCCCCC';
1.349 albertel 5355: my $data_table_highlight = '#FFFF00';
1.352 albertel 5356: my $mail_new = '#FFBB77';
5357: my $mail_new_hover = '#DD9955';
5358: my $mail_read = '#BBBB77';
5359: my $mail_read_hover = '#999944';
5360: my $mail_replied = '#AAAA88';
5361: my $mail_replied_hover = '#888855';
5362: my $mail_other = '#99BBBB';
5363: my $mail_other_hover = '#669999';
1.391 albertel 5364: my $table_header = '#DDDDDD';
1.489 raeburn 5365: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5366: my $lg_border_color = '#C8C8C8';
1.952 onken 5367: my $button_hover = '#BF2317';
1.392 albertel 5368:
1.608 albertel 5369: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5370: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5371: : '0 3px 0 4px';
1.448 albertel 5372:
1.523 albertel 5373:
1.343 albertel 5374: return <<END;
1.947 droeschl 5375:
5376: /* needed for iframe to allow 100% height in FF */
5377: body, html {
5378: margin: 0;
5379: padding: 0 0.5%;
5380: height: 99%; /* to avoid scrollbars */
5381: }
5382:
1.795 www 5383: body {
1.911 bisitz 5384: font-family: $sans;
5385: line-height:130%;
5386: font-size:0.83em;
5387: color:$font;
1.795 www 5388: }
5389:
1.959 onken 5390: a:focus,
5391: a:focus img {
1.795 www 5392: color: red;
5393: }
1.698 harmsja 5394:
1.911 bisitz 5395: form, .inline {
5396: display: inline;
1.795 www 5397: }
1.721 harmsja 5398:
1.795 www 5399: .LC_right {
1.911 bisitz 5400: text-align:right;
1.795 www 5401: }
5402:
5403: .LC_middle {
1.911 bisitz 5404: vertical-align:middle;
1.795 www 5405: }
1.721 harmsja 5406:
1.911 bisitz 5407: .LC_400Box {
5408: width:400px;
5409: }
1.721 harmsja 5410:
1.947 droeschl 5411: .LC_iframecontainer {
5412: width: 98%;
5413: margin: 0;
5414: position: fixed;
5415: top: 8.5em;
5416: bottom: 0;
5417: }
5418:
5419: .LC_iframecontainer iframe{
5420: border: none;
5421: width: 100%;
5422: height: 100%;
5423: }
5424:
1.778 bisitz 5425: .LC_filename {
5426: font-family: $mono;
5427: white-space:pre;
1.921 bisitz 5428: font-size: 120%;
1.778 bisitz 5429: }
5430:
5431: .LC_fileicon {
5432: border: none;
5433: height: 1.3em;
5434: vertical-align: text-bottom;
5435: margin-right: 0.3em;
5436: text-decoration:none;
5437: }
5438:
1.1008 www 5439: .LC_setting {
5440: text-decoration:underline;
5441: }
5442:
1.350 albertel 5443: .LC_error {
5444: color: red;
5445: }
1.795 www 5446:
1.1097 bisitz 5447: .LC_warning {
5448: color: darkorange;
5449: }
5450:
1.457 albertel 5451: .LC_diff_removed {
1.733 bisitz 5452: color: red;
1.394 albertel 5453: }
1.532 albertel 5454:
5455: .LC_info,
1.457 albertel 5456: .LC_success,
5457: .LC_diff_added {
1.350 albertel 5458: color: green;
5459: }
1.795 www 5460:
1.802 bisitz 5461: div.LC_confirm_box {
5462: background-color: #FAFAFA;
5463: border: 1px solid $lg_border_color;
5464: margin-right: 0;
5465: padding: 5px;
5466: }
5467:
5468: div.LC_confirm_box .LC_error img,
5469: div.LC_confirm_box .LC_success img {
5470: vertical-align: middle;
5471: }
5472:
1.440 albertel 5473: .LC_icon {
1.771 droeschl 5474: border: none;
1.790 droeschl 5475: vertical-align: middle;
1.771 droeschl 5476: }
5477:
1.543 albertel 5478: .LC_docs_spacer {
5479: width: 25px;
5480: height: 1px;
1.771 droeschl 5481: border: none;
1.543 albertel 5482: }
1.346 albertel 5483:
1.532 albertel 5484: .LC_internal_info {
1.735 bisitz 5485: color: #999999;
1.532 albertel 5486: }
5487:
1.794 www 5488: .LC_discussion {
1.1050 www 5489: background: $data_table_dark;
1.911 bisitz 5490: border: 1px solid black;
5491: margin: 2px;
1.794 www 5492: }
5493:
5494: .LC_disc_action_left {
1.1050 www 5495: background: $sidebg;
1.911 bisitz 5496: text-align: left;
1.1050 www 5497: padding: 4px;
5498: margin: 2px;
1.794 www 5499: }
5500:
5501: .LC_disc_action_right {
1.1050 www 5502: background: $sidebg;
1.911 bisitz 5503: text-align: right;
1.1050 www 5504: padding: 4px;
5505: margin: 2px;
1.794 www 5506: }
5507:
5508: .LC_disc_new_item {
1.911 bisitz 5509: background: white;
5510: border: 2px solid red;
1.1050 www 5511: margin: 4px;
5512: padding: 4px;
1.794 www 5513: }
5514:
5515: .LC_disc_old_item {
1.911 bisitz 5516: background: white;
1.1050 www 5517: margin: 4px;
5518: padding: 4px;
1.794 www 5519: }
5520:
1.458 albertel 5521: table.LC_pastsubmission {
5522: border: 1px solid black;
5523: margin: 2px;
5524: }
5525:
1.924 bisitz 5526: table#LC_menubuttons {
1.345 albertel 5527: width: 100%;
5528: background: $pgbg;
1.392 albertel 5529: border: 2px;
1.402 albertel 5530: border-collapse: separate;
1.803 bisitz 5531: padding: 0;
1.345 albertel 5532: }
1.392 albertel 5533:
1.801 tempelho 5534: table#LC_title_bar a {
5535: color: $fontmenu;
5536: }
1.836 bisitz 5537:
1.807 droeschl 5538: table#LC_title_bar {
1.819 tempelho 5539: clear: both;
1.836 bisitz 5540: display: none;
1.807 droeschl 5541: }
5542:
1.795 www 5543: table#LC_title_bar,
1.933 droeschl 5544: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5545: table#LC_title_bar.LC_with_remote {
1.359 albertel 5546: width: 100%;
1.392 albertel 5547: border-color: $pgbg;
5548: border-style: solid;
5549: border-width: $border;
1.379 albertel 5550: background: $pgbg;
1.801 tempelho 5551: color: $fontmenu;
1.392 albertel 5552: border-collapse: collapse;
1.803 bisitz 5553: padding: 0;
1.819 tempelho 5554: margin: 0;
1.359 albertel 5555: }
1.795 www 5556:
1.933 droeschl 5557: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5558: margin: 0;
5559: padding: 0;
1.933 droeschl 5560: position: relative;
5561: list-style: none;
1.913 droeschl 5562: }
1.933 droeschl 5563: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5564: display: inline;
5565: }
1.933 droeschl 5566:
5567: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5568: padding: 0;
1.933 droeschl 5569: margin: 0;
5570: float: left;
1.913 droeschl 5571: }
1.933 droeschl 5572: .LC_breadcrumb_tools_tools {
5573: padding: 0;
5574: margin: 0;
1.913 droeschl 5575: float: right;
5576: }
5577:
1.359 albertel 5578: table#LC_title_bar td {
5579: background: $tabbg;
5580: }
1.795 www 5581:
1.911 bisitz 5582: table#LC_menubuttons img {
1.803 bisitz 5583: border: none;
1.346 albertel 5584: }
1.795 www 5585:
1.842 droeschl 5586: .LC_breadcrumbs_component {
1.911 bisitz 5587: float: right;
5588: margin: 0 1em;
1.357 albertel 5589: }
1.842 droeschl 5590: .LC_breadcrumbs_component img {
1.911 bisitz 5591: vertical-align: middle;
1.777 tempelho 5592: }
1.795 www 5593:
1.383 albertel 5594: td.LC_table_cell_checkbox {
5595: text-align: center;
5596: }
1.795 www 5597:
5598: .LC_fontsize_small {
1.911 bisitz 5599: font-size: 70%;
1.705 tempelho 5600: }
5601:
1.844 bisitz 5602: #LC_breadcrumbs {
1.911 bisitz 5603: clear:both;
5604: background: $sidebg;
5605: border-bottom: 1px solid $lg_border_color;
5606: line-height: 2.5em;
1.933 droeschl 5607: overflow: hidden;
1.911 bisitz 5608: margin: 0;
5609: padding: 0;
1.995 raeburn 5610: text-align: left;
1.819 tempelho 5611: }
1.862 bisitz 5612:
1.1098 bisitz 5613: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5614: clear:both;
5615: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5616: border: 1px solid $sidebg;
1.1098 bisitz 5617: margin: 0 0 10px 0;
1.966 bisitz 5618: padding: 3px;
1.995 raeburn 5619: text-align: left;
1.822 bisitz 5620: }
5621:
1.795 www 5622: .LC_fontsize_medium {
1.911 bisitz 5623: font-size: 85%;
1.705 tempelho 5624: }
5625:
1.795 www 5626: .LC_fontsize_large {
1.911 bisitz 5627: font-size: 120%;
1.705 tempelho 5628: }
5629:
1.346 albertel 5630: .LC_menubuttons_inline_text {
5631: color: $font;
1.698 harmsja 5632: font-size: 90%;
1.701 harmsja 5633: padding-left:3px;
1.346 albertel 5634: }
5635:
1.934 droeschl 5636: .LC_menubuttons_inline_text img{
5637: vertical-align: middle;
5638: }
5639:
1.1051 www 5640: li.LC_menubuttons_inline_text img {
1.951 onken 5641: cursor:pointer;
1.1002 droeschl 5642: text-decoration: none;
1.951 onken 5643: }
5644:
1.526 www 5645: .LC_menubuttons_link {
5646: text-decoration: none;
5647: }
1.795 www 5648:
1.522 albertel 5649: .LC_menubuttons_category {
1.521 www 5650: color: $font;
1.526 www 5651: background: $pgbg;
1.521 www 5652: font-size: larger;
5653: font-weight: bold;
5654: }
5655:
1.346 albertel 5656: td.LC_menubuttons_text {
1.911 bisitz 5657: color: $font;
1.346 albertel 5658: }
1.706 harmsja 5659:
1.346 albertel 5660: .LC_current_location {
5661: background: $tabbg;
5662: }
1.795 www 5663:
1.938 bisitz 5664: table.LC_data_table {
1.347 albertel 5665: border: 1px solid #000000;
1.402 albertel 5666: border-collapse: separate;
1.426 albertel 5667: border-spacing: 1px;
1.610 albertel 5668: background: $pgbg;
1.347 albertel 5669: }
1.795 www 5670:
1.422 albertel 5671: .LC_data_table_dense {
5672: font-size: small;
5673: }
1.795 www 5674:
1.507 raeburn 5675: table.LC_nested_outer {
5676: border: 1px solid #000000;
1.589 raeburn 5677: border-collapse: collapse;
1.803 bisitz 5678: border-spacing: 0;
1.507 raeburn 5679: width: 100%;
5680: }
1.795 www 5681:
1.879 raeburn 5682: table.LC_innerpickbox,
1.507 raeburn 5683: table.LC_nested {
1.803 bisitz 5684: border: none;
1.589 raeburn 5685: border-collapse: collapse;
1.803 bisitz 5686: border-spacing: 0;
1.507 raeburn 5687: width: 100%;
5688: }
1.795 www 5689:
1.911 bisitz 5690: table.LC_data_table tr th,
5691: table.LC_calendar tr th,
1.879 raeburn 5692: table.LC_prior_tries tr th,
5693: table.LC_innerpickbox tr th {
1.349 albertel 5694: font-weight: bold;
5695: background-color: $data_table_head;
1.801 tempelho 5696: color:$fontmenu;
1.701 harmsja 5697: font-size:90%;
1.347 albertel 5698: }
1.795 www 5699:
1.879 raeburn 5700: table.LC_innerpickbox tr th,
5701: table.LC_innerpickbox tr td {
5702: vertical-align: top;
5703: }
5704:
1.711 raeburn 5705: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5706: background-color: #CCCCCC;
1.711 raeburn 5707: font-weight: bold;
5708: text-align: left;
5709: }
1.795 www 5710:
1.912 bisitz 5711: table.LC_data_table tr.LC_odd_row > td {
5712: background-color: $data_table_light;
5713: padding: 2px;
5714: vertical-align: top;
5715: }
5716:
1.809 bisitz 5717: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5718: background-color: $data_table_light;
1.912 bisitz 5719: vertical-align: top;
5720: }
5721:
5722: table.LC_data_table tr.LC_even_row > td {
5723: background-color: $data_table_dark;
1.425 albertel 5724: padding: 2px;
1.900 bisitz 5725: vertical-align: top;
1.347 albertel 5726: }
1.795 www 5727:
1.809 bisitz 5728: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5729: background-color: $data_table_dark;
1.900 bisitz 5730: vertical-align: top;
1.347 albertel 5731: }
1.795 www 5732:
1.425 albertel 5733: table.LC_data_table tr.LC_data_table_highlight td {
5734: background-color: $data_table_darker;
5735: }
1.795 www 5736:
1.639 raeburn 5737: table.LC_data_table tr td.LC_leftcol_header {
5738: background-color: $data_table_head;
5739: font-weight: bold;
5740: }
1.795 www 5741:
1.451 albertel 5742: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5743: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5744: font-weight: bold;
5745: font-style: italic;
5746: text-align: center;
5747: padding: 8px;
1.347 albertel 5748: }
1.795 www 5749:
1.1114 raeburn 5750: table.LC_data_table tr.LC_empty_row td,
5751: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5752: background-color: $sidebg;
5753: }
5754:
5755: table.LC_nested tr.LC_empty_row td {
5756: background-color: #FFFFFF;
5757: }
5758:
1.890 droeschl 5759: table.LC_caption {
5760: }
5761:
1.507 raeburn 5762: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5763: padding: 4ex
5764: }
1.795 www 5765:
1.507 raeburn 5766: table.LC_nested_outer tr th {
5767: font-weight: bold;
1.801 tempelho 5768: color:$fontmenu;
1.507 raeburn 5769: background-color: $data_table_head;
1.701 harmsja 5770: font-size: small;
1.507 raeburn 5771: border-bottom: 1px solid #000000;
5772: }
1.795 www 5773:
1.507 raeburn 5774: table.LC_nested_outer tr td.LC_subheader {
5775: background-color: $data_table_head;
5776: font-weight: bold;
5777: font-size: small;
5778: border-bottom: 1px solid #000000;
5779: text-align: right;
1.451 albertel 5780: }
1.795 www 5781:
1.507 raeburn 5782: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5783: background-color: #CCCCCC;
1.451 albertel 5784: font-weight: bold;
5785: font-size: small;
1.507 raeburn 5786: text-align: center;
5787: }
1.795 www 5788:
1.589 raeburn 5789: table.LC_nested tr.LC_info_row td.LC_left_item,
5790: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5791: text-align: left;
1.451 albertel 5792: }
1.795 www 5793:
1.507 raeburn 5794: table.LC_nested td {
1.735 bisitz 5795: background-color: #FFFFFF;
1.451 albertel 5796: font-size: small;
1.507 raeburn 5797: }
1.795 www 5798:
1.507 raeburn 5799: table.LC_nested_outer tr th.LC_right_item,
5800: table.LC_nested tr.LC_info_row td.LC_right_item,
5801: table.LC_nested tr.LC_odd_row td.LC_right_item,
5802: table.LC_nested tr td.LC_right_item {
1.451 albertel 5803: text-align: right;
5804: }
5805:
1.507 raeburn 5806: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5807: background-color: #EEEEEE;
1.451 albertel 5808: }
5809:
1.473 raeburn 5810: table.LC_createuser {
5811: }
5812:
5813: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5814: font-size: small;
1.473 raeburn 5815: }
5816:
5817: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5818: background-color: #CCCCCC;
1.473 raeburn 5819: font-weight: bold;
5820: text-align: center;
5821: }
5822:
1.349 albertel 5823: table.LC_calendar {
5824: border: 1px solid #000000;
5825: border-collapse: collapse;
1.917 raeburn 5826: width: 98%;
1.349 albertel 5827: }
1.795 www 5828:
1.349 albertel 5829: table.LC_calendar_pickdate {
5830: font-size: xx-small;
5831: }
1.795 www 5832:
1.349 albertel 5833: table.LC_calendar tr td {
5834: border: 1px solid #000000;
5835: vertical-align: top;
1.917 raeburn 5836: width: 14%;
1.349 albertel 5837: }
1.795 www 5838:
1.349 albertel 5839: table.LC_calendar tr td.LC_calendar_day_empty {
5840: background-color: $data_table_dark;
5841: }
1.795 www 5842:
1.779 bisitz 5843: table.LC_calendar tr td.LC_calendar_day_current {
5844: background-color: $data_table_highlight;
1.777 tempelho 5845: }
1.795 www 5846:
1.938 bisitz 5847: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5848: background-color: $mail_new;
5849: }
1.795 www 5850:
1.938 bisitz 5851: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5852: background-color: $mail_new_hover;
5853: }
1.795 www 5854:
1.938 bisitz 5855: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5856: background-color: $mail_read;
5857: }
1.795 www 5858:
1.938 bisitz 5859: /*
5860: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5861: background-color: $mail_read_hover;
5862: }
1.938 bisitz 5863: */
1.795 www 5864:
1.938 bisitz 5865: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5866: background-color: $mail_replied;
5867: }
1.795 www 5868:
1.938 bisitz 5869: /*
5870: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5871: background-color: $mail_replied_hover;
5872: }
1.938 bisitz 5873: */
1.795 www 5874:
1.938 bisitz 5875: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5876: background-color: $mail_other;
5877: }
1.795 www 5878:
1.938 bisitz 5879: /*
5880: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5881: background-color: $mail_other_hover;
5882: }
1.938 bisitz 5883: */
1.494 raeburn 5884:
1.777 tempelho 5885: table.LC_data_table tr > td.LC_browser_file,
5886: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5887: background: #AAEE77;
1.389 albertel 5888: }
1.795 www 5889:
1.777 tempelho 5890: table.LC_data_table tr > td.LC_browser_file_locked,
5891: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5892: background: #FFAA99;
1.387 albertel 5893: }
1.795 www 5894:
1.777 tempelho 5895: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5896: background: #888888;
1.779 bisitz 5897: }
1.795 www 5898:
1.777 tempelho 5899: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5900: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5901: background: #F8F866;
1.777 tempelho 5902: }
1.795 www 5903:
1.696 bisitz 5904: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5905: background: #E0E8FF;
1.387 albertel 5906: }
1.696 bisitz 5907:
1.707 bisitz 5908: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5909: /* background: #77FF77; */
1.707 bisitz 5910: }
1.795 www 5911:
1.707 bisitz 5912: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5913: border-right: 8px solid #FFFF77;
1.707 bisitz 5914: }
1.795 www 5915:
1.707 bisitz 5916: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5917: border-right: 8px solid #FFAA77;
1.707 bisitz 5918: }
1.795 www 5919:
1.707 bisitz 5920: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5921: border-right: 8px solid #FF7777;
1.707 bisitz 5922: }
1.795 www 5923:
1.707 bisitz 5924: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5925: border-right: 8px solid #AAFF77;
1.707 bisitz 5926: }
1.795 www 5927:
1.707 bisitz 5928: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5929: border-right: 8px solid #11CC55;
1.707 bisitz 5930: }
5931:
1.388 albertel 5932: span.LC_current_location {
1.701 harmsja 5933: font-size:larger;
1.388 albertel 5934: background: $pgbg;
5935: }
1.387 albertel 5936:
1.1029 www 5937: span.LC_current_nav_location {
5938: font-weight:bold;
5939: background: $sidebg;
5940: }
5941:
1.395 albertel 5942: span.LC_parm_menu_item {
5943: font-size: larger;
5944: }
1.795 www 5945:
1.395 albertel 5946: span.LC_parm_scope_all {
5947: color: red;
5948: }
1.795 www 5949:
1.395 albertel 5950: span.LC_parm_scope_folder {
5951: color: green;
5952: }
1.795 www 5953:
1.395 albertel 5954: span.LC_parm_scope_resource {
5955: color: orange;
5956: }
1.795 www 5957:
1.395 albertel 5958: span.LC_parm_part {
5959: color: blue;
5960: }
1.795 www 5961:
1.911 bisitz 5962: span.LC_parm_folder,
5963: span.LC_parm_symb {
1.395 albertel 5964: font-size: x-small;
5965: font-family: $mono;
5966: color: #AAAAAA;
5967: }
5968:
1.977 bisitz 5969: ul.LC_parm_parmlist li {
5970: display: inline-block;
5971: padding: 0.3em 0.8em;
5972: vertical-align: top;
5973: width: 150px;
5974: border-top:1px solid $lg_border_color;
5975: }
5976:
1.795 www 5977: td.LC_parm_overview_level_menu,
5978: td.LC_parm_overview_map_menu,
5979: td.LC_parm_overview_parm_selectors,
5980: td.LC_parm_overview_restrictions {
1.396 albertel 5981: border: 1px solid black;
5982: border-collapse: collapse;
5983: }
1.795 www 5984:
1.396 albertel 5985: table.LC_parm_overview_restrictions td {
5986: border-width: 1px 4px 1px 4px;
5987: border-style: solid;
5988: border-color: $pgbg;
5989: text-align: center;
5990: }
1.795 www 5991:
1.396 albertel 5992: table.LC_parm_overview_restrictions th {
5993: background: $tabbg;
5994: border-width: 1px 4px 1px 4px;
5995: border-style: solid;
5996: border-color: $pgbg;
5997: }
1.795 www 5998:
1.398 albertel 5999: table#LC_helpmenu {
1.803 bisitz 6000: border: none;
1.398 albertel 6001: height: 55px;
1.803 bisitz 6002: border-spacing: 0;
1.398 albertel 6003: }
6004:
6005: table#LC_helpmenu fieldset legend {
6006: font-size: larger;
6007: }
1.795 www 6008:
1.397 albertel 6009: table#LC_helpmenu_links {
6010: width: 100%;
6011: border: 1px solid black;
6012: background: $pgbg;
1.803 bisitz 6013: padding: 0;
1.397 albertel 6014: border-spacing: 1px;
6015: }
1.795 www 6016:
1.397 albertel 6017: table#LC_helpmenu_links tr td {
6018: padding: 1px;
6019: background: $tabbg;
1.399 albertel 6020: text-align: center;
6021: font-weight: bold;
1.397 albertel 6022: }
1.396 albertel 6023:
1.795 www 6024: table#LC_helpmenu_links a:link,
6025: table#LC_helpmenu_links a:visited,
1.397 albertel 6026: table#LC_helpmenu_links a:active {
6027: text-decoration: none;
6028: color: $font;
6029: }
1.795 www 6030:
1.397 albertel 6031: table#LC_helpmenu_links a:hover {
6032: text-decoration: underline;
6033: color: $vlink;
6034: }
1.396 albertel 6035:
1.417 albertel 6036: .LC_chrt_popup_exists {
6037: border: 1px solid #339933;
6038: margin: -1px;
6039: }
1.795 www 6040:
1.417 albertel 6041: .LC_chrt_popup_up {
6042: border: 1px solid yellow;
6043: margin: -1px;
6044: }
1.795 www 6045:
1.417 albertel 6046: .LC_chrt_popup {
6047: border: 1px solid #8888FF;
6048: background: #CCCCFF;
6049: }
1.795 www 6050:
1.421 albertel 6051: table.LC_pick_box {
6052: border-collapse: separate;
6053: background: white;
6054: border: 1px solid black;
6055: border-spacing: 1px;
6056: }
1.795 www 6057:
1.421 albertel 6058: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6059: background: $sidebg;
1.421 albertel 6060: font-weight: bold;
1.900 bisitz 6061: text-align: left;
1.740 bisitz 6062: vertical-align: top;
1.421 albertel 6063: width: 184px;
6064: padding: 8px;
6065: }
1.795 www 6066:
1.579 raeburn 6067: table.LC_pick_box td.LC_pick_box_value {
6068: text-align: left;
6069: padding: 8px;
6070: }
1.795 www 6071:
1.579 raeburn 6072: table.LC_pick_box td.LC_pick_box_select {
6073: text-align: left;
6074: padding: 8px;
6075: }
1.795 www 6076:
1.424 albertel 6077: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6078: padding: 0;
1.421 albertel 6079: height: 1px;
6080: background: black;
6081: }
1.795 www 6082:
1.421 albertel 6083: table.LC_pick_box td.LC_pick_box_submit {
6084: text-align: right;
6085: }
1.795 www 6086:
1.579 raeburn 6087: table.LC_pick_box td.LC_evenrow_value {
6088: text-align: left;
6089: padding: 8px;
6090: background-color: $data_table_light;
6091: }
1.795 www 6092:
1.579 raeburn 6093: table.LC_pick_box td.LC_oddrow_value {
6094: text-align: left;
6095: padding: 8px;
6096: background-color: $data_table_light;
6097: }
1.795 www 6098:
1.579 raeburn 6099: span.LC_helpform_receipt_cat {
6100: font-weight: bold;
6101: }
1.795 www 6102:
1.424 albertel 6103: table.LC_group_priv_box {
6104: background: white;
6105: border: 1px solid black;
6106: border-spacing: 1px;
6107: }
1.795 www 6108:
1.424 albertel 6109: table.LC_group_priv_box td.LC_pick_box_title {
6110: background: $tabbg;
6111: font-weight: bold;
6112: text-align: right;
6113: width: 184px;
6114: }
1.795 www 6115:
1.424 albertel 6116: table.LC_group_priv_box td.LC_groups_fixed {
6117: background: $data_table_light;
6118: text-align: center;
6119: }
1.795 www 6120:
1.424 albertel 6121: table.LC_group_priv_box td.LC_groups_optional {
6122: background: $data_table_dark;
6123: text-align: center;
6124: }
1.795 www 6125:
1.424 albertel 6126: table.LC_group_priv_box td.LC_groups_functionality {
6127: background: $data_table_darker;
6128: text-align: center;
6129: font-weight: bold;
6130: }
1.795 www 6131:
1.424 albertel 6132: table.LC_group_priv td {
6133: text-align: left;
1.803 bisitz 6134: padding: 0;
1.424 albertel 6135: }
6136:
6137: .LC_navbuttons {
6138: margin: 2ex 0ex 2ex 0ex;
6139: }
1.795 www 6140:
1.423 albertel 6141: .LC_topic_bar {
6142: font-weight: bold;
6143: background: $tabbg;
1.918 wenzelju 6144: margin: 1em 0em 1em 2em;
1.805 bisitz 6145: padding: 3px;
1.918 wenzelju 6146: font-size: 1.2em;
1.423 albertel 6147: }
1.795 www 6148:
1.423 albertel 6149: .LC_topic_bar span {
1.918 wenzelju 6150: left: 0.5em;
6151: position: absolute;
1.423 albertel 6152: vertical-align: middle;
1.918 wenzelju 6153: font-size: 1.2em;
1.423 albertel 6154: }
1.795 www 6155:
1.423 albertel 6156: table.LC_course_group_status {
6157: margin: 20px;
6158: }
1.795 www 6159:
1.423 albertel 6160: table.LC_status_selector td {
6161: vertical-align: top;
6162: text-align: center;
1.424 albertel 6163: padding: 4px;
6164: }
1.795 www 6165:
1.599 albertel 6166: div.LC_feedback_link {
1.616 albertel 6167: clear: both;
1.829 kalberla 6168: background: $sidebg;
1.779 bisitz 6169: width: 100%;
1.829 kalberla 6170: padding-bottom: 10px;
6171: border: 1px $tabbg solid;
1.833 kalberla 6172: height: 22px;
6173: line-height: 22px;
6174: padding-top: 5px;
6175: }
6176:
6177: div.LC_feedback_link img {
6178: height: 22px;
1.867 kalberla 6179: vertical-align:middle;
1.829 kalberla 6180: }
6181:
1.911 bisitz 6182: div.LC_feedback_link a {
1.829 kalberla 6183: text-decoration: none;
1.489 raeburn 6184: }
1.795 www 6185:
1.867 kalberla 6186: div.LC_comblock {
1.911 bisitz 6187: display:inline;
1.867 kalberla 6188: color:$font;
6189: font-size:90%;
6190: }
6191:
6192: div.LC_feedback_link div.LC_comblock {
6193: padding-left:5px;
6194: }
6195:
6196: div.LC_feedback_link div.LC_comblock a {
6197: color:$font;
6198: }
6199:
1.489 raeburn 6200: span.LC_feedback_link {
1.858 bisitz 6201: /* background: $feedback_link_bg; */
1.599 albertel 6202: font-size: larger;
6203: }
1.795 www 6204:
1.599 albertel 6205: span.LC_message_link {
1.858 bisitz 6206: /* background: $feedback_link_bg; */
1.599 albertel 6207: font-size: larger;
6208: position: absolute;
6209: right: 1em;
1.489 raeburn 6210: }
1.421 albertel 6211:
1.515 albertel 6212: table.LC_prior_tries {
1.524 albertel 6213: border: 1px solid #000000;
6214: border-collapse: separate;
6215: border-spacing: 1px;
1.515 albertel 6216: }
1.523 albertel 6217:
1.515 albertel 6218: table.LC_prior_tries td {
1.524 albertel 6219: padding: 2px;
1.515 albertel 6220: }
1.523 albertel 6221:
6222: .LC_answer_correct {
1.795 www 6223: background: lightgreen;
6224: color: darkgreen;
6225: padding: 6px;
1.523 albertel 6226: }
1.795 www 6227:
1.523 albertel 6228: .LC_answer_charged_try {
1.797 www 6229: background: #FFAAAA;
1.795 www 6230: color: darkred;
6231: padding: 6px;
1.523 albertel 6232: }
1.795 www 6233:
1.779 bisitz 6234: .LC_answer_not_charged_try,
1.523 albertel 6235: .LC_answer_no_grade,
6236: .LC_answer_late {
1.795 www 6237: background: lightyellow;
1.523 albertel 6238: color: black;
1.795 www 6239: padding: 6px;
1.523 albertel 6240: }
1.795 www 6241:
1.523 albertel 6242: .LC_answer_previous {
1.795 www 6243: background: lightblue;
6244: color: darkblue;
6245: padding: 6px;
1.523 albertel 6246: }
1.795 www 6247:
1.779 bisitz 6248: .LC_answer_no_message {
1.777 tempelho 6249: background: #FFFFFF;
6250: color: black;
1.795 www 6251: padding: 6px;
1.779 bisitz 6252: }
1.795 www 6253:
1.779 bisitz 6254: .LC_answer_unknown {
6255: background: orange;
6256: color: black;
1.795 www 6257: padding: 6px;
1.777 tempelho 6258: }
1.795 www 6259:
1.529 albertel 6260: span.LC_prior_numerical,
6261: span.LC_prior_string,
6262: span.LC_prior_custom,
6263: span.LC_prior_reaction,
6264: span.LC_prior_math {
1.925 bisitz 6265: font-family: $mono;
1.523 albertel 6266: white-space: pre;
6267: }
6268:
1.525 albertel 6269: span.LC_prior_string {
1.925 bisitz 6270: font-family: $mono;
1.525 albertel 6271: white-space: pre;
6272: }
6273:
1.523 albertel 6274: table.LC_prior_option {
6275: width: 100%;
6276: border-collapse: collapse;
6277: }
1.795 www 6278:
1.911 bisitz 6279: table.LC_prior_rank,
1.795 www 6280: table.LC_prior_match {
1.528 albertel 6281: border-collapse: collapse;
6282: }
1.795 www 6283:
1.528 albertel 6284: table.LC_prior_option tr td,
6285: table.LC_prior_rank tr td,
6286: table.LC_prior_match tr td {
1.524 albertel 6287: border: 1px solid #000000;
1.515 albertel 6288: }
6289:
1.855 bisitz 6290: .LC_nobreak {
1.544 albertel 6291: white-space: nowrap;
1.519 raeburn 6292: }
6293:
1.576 raeburn 6294: span.LC_cusr_emph {
6295: font-style: italic;
6296: }
6297:
1.633 raeburn 6298: span.LC_cusr_subheading {
6299: font-weight: normal;
6300: font-size: 85%;
6301: }
6302:
1.861 bisitz 6303: div.LC_docs_entry_move {
1.859 bisitz 6304: border: 1px solid #BBBBBB;
1.545 albertel 6305: background: #DDDDDD;
1.861 bisitz 6306: width: 22px;
1.859 bisitz 6307: padding: 1px;
6308: margin: 0;
1.545 albertel 6309: }
6310:
1.861 bisitz 6311: table.LC_data_table tr > td.LC_docs_entry_commands,
6312: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6313: font-size: x-small;
6314: }
1.795 www 6315:
1.861 bisitz 6316: .LC_docs_entry_parameter {
6317: white-space: nowrap;
6318: }
6319:
1.544 albertel 6320: .LC_docs_copy {
1.545 albertel 6321: color: #000099;
1.544 albertel 6322: }
1.795 www 6323:
1.544 albertel 6324: .LC_docs_cut {
1.545 albertel 6325: color: #550044;
1.544 albertel 6326: }
1.795 www 6327:
1.544 albertel 6328: .LC_docs_rename {
1.545 albertel 6329: color: #009900;
1.544 albertel 6330: }
1.795 www 6331:
1.544 albertel 6332: .LC_docs_remove {
1.545 albertel 6333: color: #990000;
6334: }
6335:
1.547 albertel 6336: .LC_docs_reinit_warn,
6337: .LC_docs_ext_edit {
6338: font-size: x-small;
6339: }
6340:
1.545 albertel 6341: table.LC_docs_adddocs td,
6342: table.LC_docs_adddocs th {
6343: border: 1px solid #BBBBBB;
6344: padding: 4px;
6345: background: #DDDDDD;
1.543 albertel 6346: }
6347:
1.584 albertel 6348: table.LC_sty_begin {
6349: background: #BBFFBB;
6350: }
1.795 www 6351:
1.584 albertel 6352: table.LC_sty_end {
6353: background: #FFBBBB;
6354: }
6355:
1.589 raeburn 6356: table.LC_double_column {
1.803 bisitz 6357: border-width: 0;
1.589 raeburn 6358: border-collapse: collapse;
6359: width: 100%;
6360: padding: 2px;
6361: }
6362:
6363: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6364: top: 2px;
1.589 raeburn 6365: left: 2px;
6366: width: 47%;
6367: vertical-align: top;
6368: }
6369:
6370: table.LC_double_column tr td.LC_right_col {
6371: top: 2px;
1.779 bisitz 6372: right: 2px;
1.589 raeburn 6373: width: 47%;
6374: vertical-align: top;
6375: }
6376:
1.591 raeburn 6377: div.LC_left_float {
6378: float: left;
6379: padding-right: 5%;
1.597 albertel 6380: padding-bottom: 4px;
1.591 raeburn 6381: }
6382:
6383: div.LC_clear_float_header {
1.597 albertel 6384: padding-bottom: 2px;
1.591 raeburn 6385: }
6386:
6387: div.LC_clear_float_footer {
1.597 albertel 6388: padding-top: 10px;
1.591 raeburn 6389: clear: both;
6390: }
6391:
1.597 albertel 6392: div.LC_grade_show_user {
1.941 bisitz 6393: /* border-left: 5px solid $sidebg; */
6394: border-top: 5px solid #000000;
6395: margin: 50px 0 0 0;
1.936 bisitz 6396: padding: 15px 0 5px 10px;
1.597 albertel 6397: }
1.795 www 6398:
1.936 bisitz 6399: div.LC_grade_show_user_odd_row {
1.941 bisitz 6400: /* border-left: 5px solid #000000; */
6401: }
6402:
6403: div.LC_grade_show_user div.LC_Box {
6404: margin-right: 50px;
1.597 albertel 6405: }
6406:
6407: div.LC_grade_submissions,
6408: div.LC_grade_message_center,
1.936 bisitz 6409: div.LC_grade_info_links {
1.597 albertel 6410: margin: 5px;
6411: width: 99%;
6412: background: #FFFFFF;
6413: }
1.795 www 6414:
1.597 albertel 6415: div.LC_grade_submissions_header,
1.936 bisitz 6416: div.LC_grade_message_center_header {
1.705 tempelho 6417: font-weight: bold;
6418: font-size: large;
1.597 albertel 6419: }
1.795 www 6420:
1.597 albertel 6421: div.LC_grade_submissions_body,
1.936 bisitz 6422: div.LC_grade_message_center_body {
1.597 albertel 6423: border: 1px solid black;
6424: width: 99%;
6425: background: #FFFFFF;
6426: }
1.795 www 6427:
1.613 albertel 6428: table.LC_scantron_action {
6429: width: 100%;
6430: }
1.795 www 6431:
1.613 albertel 6432: table.LC_scantron_action tr th {
1.698 harmsja 6433: font-weight:bold;
6434: font-style:normal;
1.613 albertel 6435: }
1.795 www 6436:
1.779 bisitz 6437: .LC_edit_problem_header,
1.614 albertel 6438: div.LC_edit_problem_footer {
1.705 tempelho 6439: font-weight: normal;
6440: font-size: medium;
1.602 albertel 6441: margin: 2px;
1.1060 bisitz 6442: background-color: $sidebg;
1.600 albertel 6443: }
1.795 www 6444:
1.600 albertel 6445: div.LC_edit_problem_header,
1.602 albertel 6446: div.LC_edit_problem_header div,
1.614 albertel 6447: div.LC_edit_problem_footer,
6448: div.LC_edit_problem_footer div,
1.602 albertel 6449: div.LC_edit_problem_editxml_header,
6450: div.LC_edit_problem_editxml_header div {
1.600 albertel 6451: margin-top: 5px;
6452: }
1.795 www 6453:
1.600 albertel 6454: div.LC_edit_problem_header_title {
1.705 tempelho 6455: font-weight: bold;
6456: font-size: larger;
1.602 albertel 6457: background: $tabbg;
6458: padding: 3px;
1.1060 bisitz 6459: margin: 0 0 5px 0;
1.602 albertel 6460: }
1.795 www 6461:
1.602 albertel 6462: table.LC_edit_problem_header_title {
6463: width: 100%;
1.600 albertel 6464: background: $tabbg;
1.602 albertel 6465: }
6466:
6467: div.LC_edit_problem_discards {
6468: float: left;
6469: padding-bottom: 5px;
6470: }
1.795 www 6471:
1.602 albertel 6472: div.LC_edit_problem_saves {
6473: float: right;
6474: padding-bottom: 5px;
1.600 albertel 6475: }
1.795 www 6476:
1.911 bisitz 6477: img.stift {
1.803 bisitz 6478: border-width: 0;
6479: vertical-align: middle;
1.677 riegler 6480: }
1.680 riegler 6481:
1.923 bisitz 6482: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6483: vertical-align: top;
1.777 tempelho 6484: }
1.795 www 6485:
1.716 raeburn 6486: div.LC_createcourse {
1.911 bisitz 6487: margin: 10px 10px 10px 10px;
1.716 raeburn 6488: }
6489:
1.917 raeburn 6490: .LC_dccid {
6491: margin: 0.2em 0 0 0;
6492: padding: 0;
6493: font-size: 90%;
6494: display:none;
6495: }
6496:
1.897 wenzelju 6497: ol.LC_primary_menu a:hover,
1.721 harmsja 6498: ol#LC_MenuBreadcrumbs a:hover,
6499: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6500: ul#LC_secondary_menu a:hover,
1.721 harmsja 6501: .LC_FormSectionClearButton input:hover
1.795 www 6502: ul.LC_TabContent li:hover a {
1.952 onken 6503: color:$button_hover;
1.911 bisitz 6504: text-decoration:none;
1.693 droeschl 6505: }
6506:
1.779 bisitz 6507: h1 {
1.911 bisitz 6508: padding: 0;
6509: line-height:130%;
1.693 droeschl 6510: }
1.698 harmsja 6511:
1.911 bisitz 6512: h2,
6513: h3,
6514: h4,
6515: h5,
6516: h6 {
6517: margin: 5px 0 5px 0;
6518: padding: 0;
6519: line-height:130%;
1.693 droeschl 6520: }
1.795 www 6521:
6522: .LC_hcell {
1.911 bisitz 6523: padding:3px 15px 3px 15px;
6524: margin: 0;
6525: background-color:$tabbg;
6526: color:$fontmenu;
6527: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6528: }
1.795 www 6529:
1.840 bisitz 6530: .LC_Box > .LC_hcell {
1.911 bisitz 6531: margin: 0 -10px 10px -10px;
1.835 bisitz 6532: }
6533:
1.721 harmsja 6534: .LC_noBorder {
1.911 bisitz 6535: border: 0;
1.698 harmsja 6536: }
1.693 droeschl 6537:
1.721 harmsja 6538: .LC_FormSectionClearButton input {
1.911 bisitz 6539: background-color:transparent;
6540: border: none;
6541: cursor:pointer;
6542: text-decoration:underline;
1.693 droeschl 6543: }
1.763 bisitz 6544:
6545: .LC_help_open_topic {
1.911 bisitz 6546: color: #FFFFFF;
6547: background-color: #EEEEFF;
6548: margin: 1px;
6549: padding: 4px;
6550: border: 1px solid #000033;
6551: white-space: nowrap;
6552: /* vertical-align: middle; */
1.759 neumanie 6553: }
1.693 droeschl 6554:
1.911 bisitz 6555: dl,
6556: ul,
6557: div,
6558: fieldset {
6559: margin: 10px 10px 10px 0;
6560: /* overflow: hidden; */
1.693 droeschl 6561: }
1.795 www 6562:
1.838 bisitz 6563: fieldset > legend {
1.911 bisitz 6564: font-weight: bold;
6565: padding: 0 5px 0 5px;
1.838 bisitz 6566: }
6567:
1.813 bisitz 6568: #LC_nav_bar {
1.911 bisitz 6569: float: left;
1.995 raeburn 6570: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6571: margin: 0 0 2px 0;
1.807 droeschl 6572: }
6573:
1.916 droeschl 6574: #LC_realm {
6575: margin: 0.2em 0 0 0;
6576: padding: 0;
6577: font-weight: bold;
6578: text-align: center;
1.995 raeburn 6579: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6580: }
6581:
1.911 bisitz 6582: #LC_nav_bar em {
6583: font-weight: bold;
6584: font-style: normal;
1.807 droeschl 6585: }
6586:
1.897 wenzelju 6587: ol.LC_primary_menu {
1.911 bisitz 6588: float: right;
1.934 droeschl 6589: margin: 0;
1.1076 raeburn 6590: padding: 0;
1.995 raeburn 6591: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6592: }
6593:
1.852 droeschl 6594: ol#LC_PathBreadcrumbs {
1.911 bisitz 6595: margin: 0;
1.693 droeschl 6596: }
6597:
1.897 wenzelju 6598: ol.LC_primary_menu li {
1.1076 raeburn 6599: color: RGB(80, 80, 80);
6600: vertical-align: middle;
6601: text-align: left;
6602: list-style: none;
6603: float: left;
6604: }
6605:
6606: ol.LC_primary_menu li a {
6607: display: block;
6608: margin: 0;
6609: padding: 0 5px 0 10px;
6610: text-decoration: none;
6611: }
6612:
6613: ol.LC_primary_menu li ul {
6614: display: none;
6615: width: 10em;
6616: background-color: $data_table_light;
6617: }
6618:
6619: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6620: display: block;
6621: position: absolute;
6622: margin: 0;
6623: padding: 0;
1.1078 raeburn 6624: z-index: 2;
1.1076 raeburn 6625: }
6626:
6627: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6628: font-size: 90%;
1.911 bisitz 6629: vertical-align: top;
1.1076 raeburn 6630: float: none;
1.1079 raeburn 6631: border-left: 1px solid black;
6632: border-right: 1px solid black;
1.1076 raeburn 6633: }
6634:
6635: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6636: background-color:$data_table_light;
1.1076 raeburn 6637: }
6638:
6639: ol.LC_primary_menu li li a:hover {
6640: color:$button_hover;
6641: background-color:$data_table_dark;
1.693 droeschl 6642: }
6643:
1.897 wenzelju 6644: ol.LC_primary_menu li img {
1.911 bisitz 6645: vertical-align: bottom;
1.934 droeschl 6646: height: 1.1em;
1.1077 raeburn 6647: margin: 0.2em 0 0 0;
1.693 droeschl 6648: }
6649:
1.897 wenzelju 6650: ol.LC_primary_menu a {
1.911 bisitz 6651: color: RGB(80, 80, 80);
6652: text-decoration: none;
1.693 droeschl 6653: }
1.795 www 6654:
1.949 droeschl 6655: ol.LC_primary_menu a.LC_new_message {
6656: font-weight:bold;
6657: color: darkred;
6658: }
6659:
1.975 raeburn 6660: ol.LC_docs_parameters {
6661: margin-left: 0;
6662: padding: 0;
6663: list-style: none;
6664: }
6665:
6666: ol.LC_docs_parameters li {
6667: margin: 0;
6668: padding-right: 20px;
6669: display: inline;
6670: }
6671:
1.976 raeburn 6672: ol.LC_docs_parameters li:before {
6673: content: "\\002022 \\0020";
6674: }
6675:
6676: li.LC_docs_parameters_title {
6677: font-weight: bold;
6678: }
6679:
6680: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6681: content: "";
6682: }
6683:
1.897 wenzelju 6684: ul#LC_secondary_menu {
1.1107 raeburn 6685: clear: right;
1.911 bisitz 6686: color: $fontmenu;
6687: background: $tabbg;
6688: list-style: none;
6689: padding: 0;
6690: margin: 0;
6691: width: 100%;
1.995 raeburn 6692: text-align: left;
1.1107 raeburn 6693: float: left;
1.808 droeschl 6694: }
6695:
1.897 wenzelju 6696: ul#LC_secondary_menu li {
1.911 bisitz 6697: font-weight: bold;
6698: line-height: 1.8em;
1.1107 raeburn 6699: border-right: 1px solid black;
6700: float: left;
6701: }
6702:
6703: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6704: background-color: $data_table_light;
6705: }
6706:
6707: ul#LC_secondary_menu li a {
1.911 bisitz 6708: padding: 0 0.8em;
1.1107 raeburn 6709: }
6710:
6711: ul#LC_secondary_menu li ul {
6712: display: none;
6713: }
6714:
6715: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6716: display: block;
6717: position: absolute;
6718: margin: 0;
6719: padding: 0;
6720: list-style:none;
6721: float: none;
6722: background-color: $data_table_light;
6723: z-index: 2;
6724: margin-left: -1px;
6725: }
6726:
6727: ul#LC_secondary_menu li ul li {
6728: font-size: 90%;
6729: vertical-align: top;
6730: border-left: 1px solid black;
1.911 bisitz 6731: border-right: 1px solid black;
1.1107 raeburn 6732: background-color: $data_table_light
6733: list-style:none;
6734: float: none;
6735: }
6736:
6737: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6738: background-color: $data_table_dark;
1.807 droeschl 6739: }
6740:
1.847 tempelho 6741: ul.LC_TabContent {
1.911 bisitz 6742: display:block;
6743: background: $sidebg;
6744: border-bottom: solid 1px $lg_border_color;
6745: list-style:none;
1.1020 raeburn 6746: margin: -1px -10px 0 -10px;
1.911 bisitz 6747: padding: 0;
1.693 droeschl 6748: }
6749:
1.795 www 6750: ul.LC_TabContent li,
6751: ul.LC_TabContentBigger li {
1.911 bisitz 6752: float:left;
1.741 harmsja 6753: }
1.795 www 6754:
1.897 wenzelju 6755: ul#LC_secondary_menu li a {
1.911 bisitz 6756: color: $fontmenu;
6757: text-decoration: none;
1.693 droeschl 6758: }
1.795 www 6759:
1.721 harmsja 6760: ul.LC_TabContent {
1.952 onken 6761: min-height:20px;
1.721 harmsja 6762: }
1.795 www 6763:
6764: ul.LC_TabContent li {
1.911 bisitz 6765: vertical-align:middle;
1.959 onken 6766: padding: 0 16px 0 10px;
1.911 bisitz 6767: background-color:$tabbg;
6768: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6769: border-left: solid 1px $font;
1.721 harmsja 6770: }
1.795 www 6771:
1.847 tempelho 6772: ul.LC_TabContent .right {
1.911 bisitz 6773: float:right;
1.847 tempelho 6774: }
6775:
1.911 bisitz 6776: ul.LC_TabContent li a,
6777: ul.LC_TabContent li {
6778: color:rgb(47,47,47);
6779: text-decoration:none;
6780: font-size:95%;
6781: font-weight:bold;
1.952 onken 6782: min-height:20px;
6783: }
6784:
1.959 onken 6785: ul.LC_TabContent li a:hover,
6786: ul.LC_TabContent li a:focus {
1.952 onken 6787: color: $button_hover;
1.959 onken 6788: background:none;
6789: outline:none;
1.952 onken 6790: }
6791:
6792: ul.LC_TabContent li:hover {
6793: color: $button_hover;
6794: cursor:pointer;
1.721 harmsja 6795: }
1.795 www 6796:
1.911 bisitz 6797: ul.LC_TabContent li.active {
1.952 onken 6798: color: $font;
1.911 bisitz 6799: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6800: border-bottom:solid 1px #FFFFFF;
6801: cursor: default;
1.744 ehlerst 6802: }
1.795 www 6803:
1.959 onken 6804: ul.LC_TabContent li.active a {
6805: color:$font;
6806: background:#FFFFFF;
6807: outline: none;
6808: }
1.1047 raeburn 6809:
6810: ul.LC_TabContent li.goback {
6811: float: left;
6812: border-left: none;
6813: }
6814:
1.870 tempelho 6815: #maincoursedoc {
1.911 bisitz 6816: clear:both;
1.870 tempelho 6817: }
6818:
6819: ul.LC_TabContentBigger {
1.911 bisitz 6820: display:block;
6821: list-style:none;
6822: padding: 0;
1.870 tempelho 6823: }
6824:
1.795 www 6825: ul.LC_TabContentBigger li {
1.911 bisitz 6826: vertical-align:bottom;
6827: height: 30px;
6828: font-size:110%;
6829: font-weight:bold;
6830: color: #737373;
1.841 tempelho 6831: }
6832:
1.957 onken 6833: ul.LC_TabContentBigger li.active {
6834: position: relative;
6835: top: 1px;
6836: }
6837:
1.870 tempelho 6838: ul.LC_TabContentBigger li a {
1.911 bisitz 6839: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6840: height: 30px;
6841: line-height: 30px;
6842: text-align: center;
6843: display: block;
6844: text-decoration: none;
1.958 onken 6845: outline: none;
1.741 harmsja 6846: }
1.795 www 6847:
1.870 tempelho 6848: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6849: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6850: color:$font;
1.744 ehlerst 6851: }
1.795 www 6852:
1.870 tempelho 6853: ul.LC_TabContentBigger li b {
1.911 bisitz 6854: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6855: display: block;
6856: float: left;
6857: padding: 0 30px;
1.957 onken 6858: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6859: }
6860:
1.956 onken 6861: ul.LC_TabContentBigger li:hover b {
6862: color:$button_hover;
6863: }
6864:
1.870 tempelho 6865: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6866: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6867: color:$font;
1.957 onken 6868: border: 0;
1.741 harmsja 6869: }
1.693 droeschl 6870:
1.870 tempelho 6871:
1.862 bisitz 6872: ul.LC_CourseBreadcrumbs {
6873: background: $sidebg;
1.1020 raeburn 6874: height: 2em;
1.862 bisitz 6875: padding-left: 10px;
1.1020 raeburn 6876: margin: 0;
1.862 bisitz 6877: list-style-position: inside;
6878: }
6879:
1.911 bisitz 6880: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6881: ol#LC_PathBreadcrumbs {
1.911 bisitz 6882: padding-left: 10px;
6883: margin: 0;
1.933 droeschl 6884: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6885: }
6886:
1.911 bisitz 6887: ol#LC_MenuBreadcrumbs li,
6888: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6889: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6890: display: inline;
1.933 droeschl 6891: white-space: normal;
1.693 droeschl 6892: }
6893:
1.823 bisitz 6894: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6895: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6896: text-decoration: none;
6897: font-size:90%;
1.693 droeschl 6898: }
1.795 www 6899:
1.969 droeschl 6900: ol#LC_MenuBreadcrumbs h1 {
6901: display: inline;
6902: font-size: 90%;
6903: line-height: 2.5em;
6904: margin: 0;
6905: padding: 0;
6906: }
6907:
1.795 www 6908: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6909: text-decoration:none;
6910: font-size:100%;
6911: font-weight:bold;
1.693 droeschl 6912: }
1.795 www 6913:
1.840 bisitz 6914: .LC_Box {
1.911 bisitz 6915: border: solid 1px $lg_border_color;
6916: padding: 0 10px 10px 10px;
1.746 neumanie 6917: }
1.795 www 6918:
1.1020 raeburn 6919: .LC_DocsBox {
6920: border: solid 1px $lg_border_color;
6921: padding: 0 0 10px 10px;
6922: }
6923:
1.795 www 6924: .LC_AboutMe_Image {
1.911 bisitz 6925: float:left;
6926: margin-right:10px;
1.747 neumanie 6927: }
1.795 www 6928:
6929: .LC_Clear_AboutMe_Image {
1.911 bisitz 6930: clear:left;
1.747 neumanie 6931: }
1.795 www 6932:
1.721 harmsja 6933: dl.LC_ListStyleClean dt {
1.911 bisitz 6934: padding-right: 5px;
6935: display: table-header-group;
1.693 droeschl 6936: }
6937:
1.721 harmsja 6938: dl.LC_ListStyleClean dd {
1.911 bisitz 6939: display: table-row;
1.693 droeschl 6940: }
6941:
1.721 harmsja 6942: .LC_ListStyleClean,
6943: .LC_ListStyleSimple,
6944: .LC_ListStyleNormal,
1.795 www 6945: .LC_ListStyleSpecial {
1.911 bisitz 6946: /* display:block; */
6947: list-style-position: inside;
6948: list-style-type: none;
6949: overflow: hidden;
6950: padding: 0;
1.693 droeschl 6951: }
6952:
1.721 harmsja 6953: .LC_ListStyleSimple li,
6954: .LC_ListStyleSimple dd,
6955: .LC_ListStyleNormal li,
6956: .LC_ListStyleNormal dd,
6957: .LC_ListStyleSpecial li,
1.795 www 6958: .LC_ListStyleSpecial dd {
1.911 bisitz 6959: margin: 0;
6960: padding: 5px 5px 5px 10px;
6961: clear: both;
1.693 droeschl 6962: }
6963:
1.721 harmsja 6964: .LC_ListStyleClean li,
6965: .LC_ListStyleClean dd {
1.911 bisitz 6966: padding-top: 0;
6967: padding-bottom: 0;
1.693 droeschl 6968: }
6969:
1.721 harmsja 6970: .LC_ListStyleSimple dd,
1.795 www 6971: .LC_ListStyleSimple li {
1.911 bisitz 6972: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 6973: }
6974:
1.721 harmsja 6975: .LC_ListStyleSpecial li,
6976: .LC_ListStyleSpecial dd {
1.911 bisitz 6977: list-style-type: none;
6978: background-color: RGB(220, 220, 220);
6979: margin-bottom: 4px;
1.693 droeschl 6980: }
6981:
1.721 harmsja 6982: table.LC_SimpleTable {
1.911 bisitz 6983: margin:5px;
6984: border:solid 1px $lg_border_color;
1.795 www 6985: }
1.693 droeschl 6986:
1.721 harmsja 6987: table.LC_SimpleTable tr {
1.911 bisitz 6988: padding: 0;
6989: border:solid 1px $lg_border_color;
1.693 droeschl 6990: }
1.795 www 6991:
6992: table.LC_SimpleTable thead {
1.911 bisitz 6993: background:rgb(220,220,220);
1.693 droeschl 6994: }
6995:
1.721 harmsja 6996: div.LC_columnSection {
1.911 bisitz 6997: display: block;
6998: clear: both;
6999: overflow: hidden;
7000: margin: 0;
1.693 droeschl 7001: }
7002:
1.721 harmsja 7003: div.LC_columnSection>* {
1.911 bisitz 7004: float: left;
7005: margin: 10px 20px 10px 0;
7006: overflow:hidden;
1.693 droeschl 7007: }
1.721 harmsja 7008:
1.795 www 7009: table em {
1.911 bisitz 7010: font-weight: bold;
7011: font-style: normal;
1.748 schulted 7012: }
1.795 www 7013:
1.779 bisitz 7014: table.LC_tableBrowseRes,
1.795 www 7015: table.LC_tableOfContent {
1.911 bisitz 7016: border:none;
7017: border-spacing: 1px;
7018: padding: 3px;
7019: background-color: #FFFFFF;
7020: font-size: 90%;
1.753 droeschl 7021: }
1.789 droeschl 7022:
1.911 bisitz 7023: table.LC_tableOfContent {
7024: border-collapse: collapse;
1.789 droeschl 7025: }
7026:
1.771 droeschl 7027: table.LC_tableBrowseRes a,
1.768 schulted 7028: table.LC_tableOfContent a {
1.911 bisitz 7029: background-color: transparent;
7030: text-decoration: none;
1.753 droeschl 7031: }
7032:
1.795 www 7033: table.LC_tableOfContent img {
1.911 bisitz 7034: border: none;
7035: height: 1.3em;
7036: vertical-align: text-bottom;
7037: margin-right: 0.3em;
1.753 droeschl 7038: }
1.757 schulted 7039:
1.795 www 7040: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7041: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7042: }
7043:
1.795 www 7044: a#LC_content_toolbar_everything {
1.911 bisitz 7045: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7046: }
7047:
1.795 www 7048: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7049: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7050: }
7051:
1.795 www 7052: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7053: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7054: }
7055:
1.795 www 7056: a#LC_content_toolbar_changefolder {
1.911 bisitz 7057: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7058: }
7059:
1.795 www 7060: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7061: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7062: }
7063:
1.1043 raeburn 7064: a#LC_content_toolbar_edittoplevel {
7065: background-image:url(/res/adm/pages/edittoplevel.gif);
7066: }
7067:
1.795 www 7068: ul#LC_toolbar li a:hover {
1.911 bisitz 7069: background-position: bottom center;
1.757 schulted 7070: }
7071:
1.795 www 7072: ul#LC_toolbar {
1.911 bisitz 7073: padding: 0;
7074: margin: 2px;
7075: list-style:none;
7076: position:relative;
7077: background-color:white;
1.1082 raeburn 7078: overflow: auto;
1.757 schulted 7079: }
7080:
1.795 www 7081: ul#LC_toolbar li {
1.911 bisitz 7082: border:1px solid white;
7083: padding: 0;
7084: margin: 0;
7085: float: left;
7086: display:inline;
7087: vertical-align:middle;
1.1082 raeburn 7088: white-space: nowrap;
1.911 bisitz 7089: }
1.757 schulted 7090:
1.783 amueller 7091:
1.795 www 7092: a.LC_toolbarItem {
1.911 bisitz 7093: display:block;
7094: padding: 0;
7095: margin: 0;
7096: height: 32px;
7097: width: 32px;
7098: color:white;
7099: border: none;
7100: background-repeat:no-repeat;
7101: background-color:transparent;
1.757 schulted 7102: }
7103:
1.915 droeschl 7104: ul.LC_funclist {
7105: margin: 0;
7106: padding: 0.5em 1em 0.5em 0;
7107: }
7108:
1.933 droeschl 7109: ul.LC_funclist > li:first-child {
7110: font-weight:bold;
7111: margin-left:0.8em;
7112: }
7113:
1.915 droeschl 7114: ul.LC_funclist + ul.LC_funclist {
7115: /*
7116: left border as a seperator if we have more than
7117: one list
7118: */
7119: border-left: 1px solid $sidebg;
7120: /*
7121: this hides the left border behind the border of the
7122: outer box if element is wrapped to the next 'line'
7123: */
7124: margin-left: -1px;
7125: }
7126:
1.843 bisitz 7127: ul.LC_funclist li {
1.915 droeschl 7128: display: inline;
1.782 bisitz 7129: white-space: nowrap;
1.915 droeschl 7130: margin: 0 0 0 25px;
7131: line-height: 150%;
1.782 bisitz 7132: }
7133:
1.974 wenzelju 7134: .LC_hidden {
7135: display: none;
7136: }
7137:
1.1030 www 7138: .LCmodal-overlay {
7139: position:fixed;
7140: top:0;
7141: right:0;
7142: bottom:0;
7143: left:0;
7144: height:100%;
7145: width:100%;
7146: margin:0;
7147: padding:0;
7148: background:#999;
7149: opacity:.75;
7150: filter: alpha(opacity=75);
7151: -moz-opacity: 0.75;
7152: z-index:101;
7153: }
7154:
7155: * html .LCmodal-overlay {
7156: position: absolute;
7157: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7158: }
7159:
7160: .LCmodal-window {
7161: position:fixed;
7162: top:50%;
7163: left:50%;
7164: margin:0;
7165: padding:0;
7166: z-index:102;
7167: }
7168:
7169: * html .LCmodal-window {
7170: position:absolute;
7171: }
7172:
7173: .LCclose-window {
7174: position:absolute;
7175: width:32px;
7176: height:32px;
7177: right:8px;
7178: top:8px;
7179: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7180: text-indent:-99999px;
7181: overflow:hidden;
7182: cursor:pointer;
7183: }
7184:
1.1100 raeburn 7185: /*
7186: styles used by TTH when "Default set of options to pass to tth/m
7187: when converting TeX" in course settings has been set
7188:
7189: option passed: -t
7190:
7191: */
7192:
7193: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7194: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7195: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7196: td div.norm {line-height:normal;}
7197:
7198: /*
7199: option passed -y3
7200: */
7201:
7202: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7203: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7204: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7205:
1.343 albertel 7206: END
7207: }
7208:
1.306 albertel 7209: =pod
7210:
7211: =item * &headtag()
7212:
7213: Returns a uniform footer for LON-CAPA web pages.
7214:
1.307 albertel 7215: Inputs: $title - optional title for the head
7216: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7217: $args - optional arguments
1.319 albertel 7218: force_register - if is true call registerurl so the remote is
7219: informed
1.415 albertel 7220: redirect -> array ref of
7221: 1- seconds before redirect occurs
7222: 2- url to redirect to
7223: 3- whether the side effect should occur
1.315 albertel 7224: (side effect of setting
7225: $env{'internal.head.redirect'} to the url
7226: redirected too)
1.352 albertel 7227: domain -> force to color decorate a page for a specific
7228: domain
7229: function -> force usage of a specific rolish color scheme
7230: bgcolor -> override the default page bgcolor
1.460 albertel 7231: no_auto_mt_title
7232: -> prevent &mt()ing the title arg
1.464 albertel 7233:
1.306 albertel 7234: =cut
7235:
7236: sub headtag {
1.313 albertel 7237: my ($title,$head_extra,$args) = @_;
1.306 albertel 7238:
1.363 albertel 7239: my $function = $args->{'function'} || &get_users_function();
7240: my $domain = $args->{'domain'} || &determinedomain();
7241: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.418 albertel 7242: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7243: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7244: #time(),
1.418 albertel 7245: $env{'environment.color.timestamp'},
1.363 albertel 7246: $function,$domain,$bgcolor);
7247:
1.369 www 7248: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7249:
1.308 albertel 7250: my $result =
7251: '<head>'.
1.461 albertel 7252: &font_settings();
1.319 albertel 7253:
1.1064 raeburn 7254: my $inhibitprint = &print_suppression();
7255:
1.461 albertel 7256: if (!$args->{'frameset'}) {
7257: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7258: }
1.962 droeschl 7259: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7260: $result .= Apache::lonxml::display_title();
1.319 albertel 7261: }
1.436 albertel 7262: if (!$args->{'no_nav_bar'}
7263: && !$args->{'only_body'}
7264: && !$args->{'frameset'}) {
7265: $result .= &help_menu_js();
1.1032 www 7266: $result.=&modal_window();
1.1038 www 7267: $result.=&togglebox_script();
1.1034 www 7268: $result.=&wishlist_window();
1.1041 www 7269: $result.=&LCprogressbarUpdate_script();
1.1034 www 7270: } else {
7271: if ($args->{'add_modal'}) {
7272: $result.=&modal_window();
7273: }
7274: if ($args->{'add_wishlist'}) {
7275: $result.=&wishlist_window();
7276: }
1.1038 www 7277: if ($args->{'add_togglebox'}) {
7278: $result.=&togglebox_script();
7279: }
1.1041 www 7280: if ($args->{'add_progressbar'}) {
7281: $result.=&LCprogressbarUpdate_script();
7282: }
1.436 albertel 7283: }
1.314 albertel 7284: if (ref($args->{'redirect'})) {
1.414 albertel 7285: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7286: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7287: if (!$inhibit_continue) {
7288: $env{'internal.head.redirect'} = $url;
7289: }
1.313 albertel 7290: $result.=<<ADDMETA
7291: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7292: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7293: ADDMETA
7294: }
1.306 albertel 7295: if (!defined($title)) {
7296: $title = 'The LearningOnline Network with CAPA';
7297: }
1.460 albertel 7298: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7299: $result .= '<title> LON-CAPA '.$title.'</title>'
1.414 albertel 7300: .'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064 raeburn 7301: .$inhibitprint
1.414 albertel 7302: .$head_extra;
1.962 droeschl 7303: return $result.'</head>';
1.306 albertel 7304: }
7305:
7306: =pod
7307:
1.340 albertel 7308: =item * &font_settings()
7309:
7310: Returns neccessary <meta> to set the proper encoding
7311:
7312: Inputs: none
7313:
7314: =cut
7315:
7316: sub font_settings {
7317: my $headerstring='';
1.647 www 7318: if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340 albertel 7319: $headerstring.=
7320: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
7321: }
7322: return $headerstring;
7323: }
7324:
1.341 albertel 7325: =pod
7326:
1.1064 raeburn 7327: =item * &print_suppression()
7328:
7329: In course context returns css which causes the body to be blank when media="print",
7330: if printout generation is unavailable for the current resource.
7331:
7332: This could be because:
7333:
7334: (a) printstartdate is in the future
7335:
7336: (b) printenddate is in the past
7337:
7338: (c) there is an active exam block with "printout"
7339: functionality blocked
7340:
7341: Users with pav, pfo or evb privileges are exempt.
7342:
7343: Inputs: none
7344:
7345: =cut
7346:
7347:
7348: sub print_suppression {
7349: my $noprint;
7350: if ($env{'request.course.id'}) {
7351: my $scope = $env{'request.course.id'};
7352: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7353: (&Apache::lonnet::allowed('pfo',$scope))) {
7354: return;
7355: }
7356: if ($env{'request.course.sec'} ne '') {
7357: $scope .= "/$env{'request.course.sec'}";
7358: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7359: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7360: return;
1.1064 raeburn 7361: }
7362: }
7363: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7364: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065 raeburn 7365: my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064 raeburn 7366: if ($blocked) {
7367: my $checkrole = "cm./$cdom/$cnum";
7368: if ($env{'request.course.sec'} ne '') {
7369: $checkrole .= "/$env{'request.course.sec'}";
7370: }
7371: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7372: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7373: $noprint = 1;
7374: }
7375: }
7376: unless ($noprint) {
7377: my $symb = &Apache::lonnet::symbread();
7378: if ($symb ne '') {
7379: my $navmap = Apache::lonnavmaps::navmap->new();
7380: if (ref($navmap)) {
7381: my $res = $navmap->getBySymb($symb);
7382: if (ref($res)) {
7383: if (!$res->resprintable()) {
7384: $noprint = 1;
7385: }
7386: }
7387: }
7388: }
7389: }
7390: if ($noprint) {
7391: return <<"ENDSTYLE";
7392: <style type="text/css" media="print">
7393: body { display:none }
7394: </style>
7395: ENDSTYLE
7396: }
7397: }
7398: return;
7399: }
7400:
7401: =pod
7402:
1.341 albertel 7403: =item * &xml_begin()
7404:
7405: Returns the needed doctype and <html>
7406:
7407: Inputs: none
7408:
7409: =cut
7410:
7411: sub xml_begin {
7412: my $output='';
7413:
7414: if ($env{'browser.mathml'}) {
7415: $output='<?xml version="1.0"?>'
7416: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7417: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7418:
7419: # .'<!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">] >'
7420: .'<!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">'
7421: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7422: .'xmlns="http://www.w3.org/1999/xhtml">';
7423: } else {
1.849 bisitz 7424: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
7425: .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341 albertel 7426: }
7427: return $output;
7428: }
1.340 albertel 7429:
7430: =pod
7431:
1.306 albertel 7432: =item * &start_page()
7433:
7434: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7435:
1.648 raeburn 7436: Inputs:
7437:
7438: =over 4
7439:
7440: $title - optional title for the page
7441:
7442: $head_extra - optional extra HTML to incude inside the <head>
7443:
7444: $args - additional optional args supported are:
7445:
7446: =over 8
7447:
7448: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7449: arg on
1.814 bisitz 7450: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7451: add_entries -> additional attributes to add to the <body>
7452: domain -> force to color decorate a page for a
1.317 albertel 7453: specific domain
1.648 raeburn 7454: function -> force usage of a specific rolish color
1.317 albertel 7455: scheme
1.648 raeburn 7456: redirect -> see &headtag()
7457: bgcolor -> override the default page bg color
7458: js_ready -> return a string ready for being used in
1.317 albertel 7459: a javascript writeln
1.648 raeburn 7460: html_encode -> return a string ready for being used in
1.320 albertel 7461: a html attribute
1.648 raeburn 7462: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7463: $forcereg arg
1.648 raeburn 7464: frameset -> if true will start with a <frameset>
1.330 albertel 7465: rather than <body>
1.648 raeburn 7466: skip_phases -> hash ref of
1.338 albertel 7467: head -> skip the <html><head> generation
7468: body -> skip all <body> generation
1.648 raeburn 7469: no_auto_mt_title -> prevent &mt()ing the title arg
7470: inherit_jsmath -> when creating popup window in a page,
7471: should it have jsmath forced on by the
7472: current page
1.867 kalberla 7473: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7474: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7475: group -> includes the current group, if page is for a
7476: specific group
1.361 albertel 7477:
1.648 raeburn 7478: =back
1.460 albertel 7479:
1.648 raeburn 7480: =back
1.562 albertel 7481:
1.306 albertel 7482: =cut
7483:
7484: sub start_page {
1.309 albertel 7485: my ($title,$head_extra,$args) = @_;
1.318 albertel 7486: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7487:
1.315 albertel 7488: $env{'internal.start_page'}++;
1.1096 raeburn 7489: my ($result,@advtools);
1.964 droeschl 7490:
1.338 albertel 7491: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030 www 7492: $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338 albertel 7493: }
7494:
7495: if (! exists($args->{'skip_phases'}{'body'}) ) {
7496: if ($args->{'frameset'}) {
7497: my $attr_string = &make_attr_string($args->{'force_register'},
7498: $args->{'add_entries'});
7499: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7500: } else {
7501: $result .=
7502: &bodytag($title,
7503: $args->{'function'}, $args->{'add_entries'},
7504: $args->{'only_body'}, $args->{'domain'},
7505: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7506: $args->{'bgcolor'}, $args,
7507: \@advtools);
1.831 bisitz 7508: }
1.330 albertel 7509: }
1.338 albertel 7510:
1.315 albertel 7511: if ($args->{'js_ready'}) {
1.713 kaisler 7512: $result = &js_ready($result);
1.315 albertel 7513: }
1.320 albertel 7514: if ($args->{'html_encode'}) {
1.713 kaisler 7515: $result = &html_encode($result);
7516: }
7517:
1.813 bisitz 7518: # Preparation for new and consistent functionlist at top of screen
7519: # if ($args->{'functionlist'}) {
7520: # $result .= &build_functionlist();
7521: #}
7522:
1.964 droeschl 7523: # Don't add anything more if only_body wanted or in const space
7524: return $result if $args->{'only_body'}
7525: || $env{'request.state'} eq 'construct';
1.813 bisitz 7526:
7527: #Breadcrumbs
1.758 kaisler 7528: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7529: &Apache::lonhtmlcommon::clear_breadcrumbs();
7530: #if any br links exists, add them to the breadcrumbs
7531: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7532: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7533: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7534: }
7535: }
1.1096 raeburn 7536: # if @advtools array contains items add then to the breadcrumbs
7537: if (@advtools > 0) {
7538: &Apache::lonmenu::advtools_crumbs(@advtools);
7539: }
1.758 kaisler 7540:
7541: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7542: if(exists($args->{'bread_crumbs_component'})){
7543: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7544: }else{
7545: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7546: }
1.320 albertel 7547: }
1.315 albertel 7548: return $result;
1.306 albertel 7549: }
7550:
7551: sub end_page {
1.315 albertel 7552: my ($args) = @_;
7553: $env{'internal.end_page'}++;
1.330 albertel 7554: my $result;
1.335 albertel 7555: if ($args->{'discussion'}) {
7556: my ($target,$parser);
7557: if (ref($args->{'discussion'})) {
7558: ($target,$parser) =($args->{'discussion'}{'target'},
7559: $args->{'discussion'}{'parser'});
7560: }
7561: $result .= &Apache::lonxml::xmlend($target,$parser);
7562: }
1.330 albertel 7563: if ($args->{'frameset'}) {
7564: $result .= '</frameset>';
7565: } else {
1.635 raeburn 7566: $result .= &endbodytag($args);
1.330 albertel 7567: }
1.1080 raeburn 7568: unless ($args->{'notbody'}) {
7569: $result .= "\n</html>";
7570: }
1.330 albertel 7571:
1.315 albertel 7572: if ($args->{'js_ready'}) {
1.317 albertel 7573: $result = &js_ready($result);
1.315 albertel 7574: }
1.335 albertel 7575:
1.320 albertel 7576: if ($args->{'html_encode'}) {
7577: $result = &html_encode($result);
7578: }
1.335 albertel 7579:
1.315 albertel 7580: return $result;
7581: }
7582:
1.1034 www 7583: sub wishlist_window {
7584: return(<<'ENDWISHLIST');
1.1046 raeburn 7585: <script type="text/javascript">
1.1034 www 7586: // <![CDATA[
7587: // <!-- BEGIN LON-CAPA Internal
7588: function set_wishlistlink(title, path) {
7589: if (!title) {
7590: title = document.title;
7591: title = title.replace(/^LON-CAPA /,'');
7592: }
7593: if (!path) {
7594: path = location.pathname;
7595: }
7596: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7597: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7598: }
7599: // END LON-CAPA Internal -->
7600: // ]]>
7601: </script>
7602: ENDWISHLIST
7603: }
7604:
1.1030 www 7605: sub modal_window {
7606: return(<<'ENDMODAL');
1.1046 raeburn 7607: <script type="text/javascript">
1.1030 www 7608: // <![CDATA[
7609: // <!-- BEGIN LON-CAPA Internal
7610: var modalWindow = {
7611: parent:"body",
7612: windowId:null,
7613: content:null,
7614: width:null,
7615: height:null,
7616: close:function()
7617: {
7618: $(".LCmodal-window").remove();
7619: $(".LCmodal-overlay").remove();
7620: },
7621: open:function()
7622: {
7623: var modal = "";
7624: modal += "<div class=\"LCmodal-overlay\"></div>";
7625: modal += "<div id=\"" + this.windowId + "\" class=\"LCmodal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
7626: modal += this.content;
7627: modal += "</div>";
7628:
7629: $(this.parent).append(modal);
7630:
7631: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7632: $(".LCclose-window").click(function(){modalWindow.close();});
7633: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7634: }
7635: };
1.1031 www 7636: var openMyModal = function(source,width,height,scrolling)
1.1030 www 7637: {
7638: modalWindow.windowId = "myModal";
7639: modalWindow.width = width;
7640: modalWindow.height = height;
1.1031 www 7641: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'></iframe>";
1.1030 www 7642: modalWindow.open();
7643: };
7644: // END LON-CAPA Internal -->
7645: // ]]>
7646: </script>
7647: ENDMODAL
7648: }
7649:
7650: sub modal_link {
1.1052 www 7651: my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030 www 7652: unless ($width) { $width=480; }
7653: unless ($height) { $height=400; }
1.1031 www 7654: unless ($scrolling) { $scrolling='yes'; }
1.1074 raeburn 7655: my $target_attr;
7656: if (defined($target)) {
7657: $target_attr = 'target="'.$target.'"';
7658: }
7659: return <<"ENDLINK";
7660: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
7661: $linktext</a>
7662: ENDLINK
1.1030 www 7663: }
7664:
1.1032 www 7665: sub modal_adhoc_script {
7666: my ($funcname,$width,$height,$content)=@_;
7667: return (<<ENDADHOC);
1.1046 raeburn 7668: <script type="text/javascript">
1.1032 www 7669: // <![CDATA[
7670: var $funcname = function()
7671: {
7672: modalWindow.windowId = "myModal";
7673: modalWindow.width = $width;
7674: modalWindow.height = $height;
7675: modalWindow.content = '$content';
7676: modalWindow.open();
7677: };
7678: // ]]>
7679: </script>
7680: ENDADHOC
7681: }
7682:
1.1041 www 7683: sub modal_adhoc_inner {
7684: my ($funcname,$width,$height,$content)=@_;
7685: my $innerwidth=$width-20;
7686: $content=&js_ready(
1.1042 www 7687: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041 www 7688: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
7689: $content.
7690: &end_scrollbox().
7691: &end_page()
7692: );
7693: return &modal_adhoc_script($funcname,$width,$height,$content);
7694: }
7695:
7696: sub modal_adhoc_window {
7697: my ($funcname,$width,$height,$content,$linktext)=@_;
7698: return &modal_adhoc_inner($funcname,$width,$height,$content).
7699: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7700: }
7701:
7702: sub modal_adhoc_launch {
7703: my ($funcname,$width,$height,$content)=@_;
7704: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7705: <script type="text/javascript">
7706: // <![CDATA[
7707: $funcname();
7708: // ]]>
7709: </script>
7710: ENDLAUNCH
7711: }
7712:
7713: sub modal_adhoc_close {
7714: return (<<ENDCLOSE);
7715: <script type="text/javascript">
7716: // <![CDATA[
7717: modalWindow.close();
7718: // ]]>
7719: </script>
7720: ENDCLOSE
7721: }
7722:
1.1038 www 7723: sub togglebox_script {
7724: return(<<ENDTOGGLE);
7725: <script type="text/javascript">
7726: // <![CDATA[
7727: function LCtoggleDisplay(id,hidetext,showtext) {
7728: link = document.getElementById(id + "link").childNodes[0];
7729: with (document.getElementById(id).style) {
7730: if (display == "none" ) {
7731: display = "inline";
7732: link.nodeValue = hidetext;
7733: } else {
7734: display = "none";
7735: link.nodeValue = showtext;
7736: }
7737: }
7738: }
7739: // ]]>
7740: </script>
7741: ENDTOGGLE
7742: }
7743:
1.1039 www 7744: sub start_togglebox {
7745: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7746: unless ($heading) { $heading=''; } else { $heading.=' '; }
7747: unless ($showtext) { $showtext=&mt('show'); }
7748: unless ($hidetext) { $hidetext=&mt('hide'); }
7749: unless ($headerbg) { $headerbg='#FFFFFF'; }
7750: return &start_data_table().
7751: &start_data_table_header_row().
7752: '<td bgcolor="'.$headerbg.'">'.$heading.
7753: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7754: $showtext.'\')">'.$showtext.'</a>]</td>'.
7755: &end_data_table_header_row().
7756: '<tr id="'.$id.'" style="display:none""><td>';
7757: }
7758:
7759: sub end_togglebox {
7760: return '</td></tr>'.&end_data_table();
7761: }
7762:
1.1041 www 7763: sub LCprogressbar_script {
1.1045 www 7764: my ($id)=@_;
1.1041 www 7765: return(<<ENDPROGRESS);
7766: <script type="text/javascript">
7767: // <![CDATA[
1.1045 www 7768: \$('#progressbar$id').progressbar({
1.1041 www 7769: value: 0,
7770: change: function(event, ui) {
7771: var newVal = \$(this).progressbar('option', 'value');
7772: \$('.pblabel', this).text(LCprogressTxt);
7773: }
7774: });
7775: // ]]>
7776: </script>
7777: ENDPROGRESS
7778: }
7779:
7780: sub LCprogressbarUpdate_script {
7781: return(<<ENDPROGRESSUPDATE);
7782: <style type="text/css">
7783: .ui-progressbar { position:relative; }
7784: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7785: </style>
7786: <script type="text/javascript">
7787: // <![CDATA[
1.1045 www 7788: var LCprogressTxt='---';
7789:
7790: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7791: LCprogressTxt=progresstext;
1.1045 www 7792: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7793: }
7794: // ]]>
7795: </script>
7796: ENDPROGRESSUPDATE
7797: }
7798:
1.1042 www 7799: my $LClastpercent;
1.1045 www 7800: my $LCidcnt;
7801: my $LCcurrentid;
1.1042 www 7802:
1.1041 www 7803: sub LCprogressbar {
1.1042 www 7804: my ($r)=(@_);
7805: $LClastpercent=0;
1.1045 www 7806: $LCidcnt++;
7807: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7808: my $starting=&mt('Starting');
7809: my $content=(<<ENDPROGBAR);
7810: <p>
1.1045 www 7811: <div id="progressbar$LCcurrentid">
1.1041 www 7812: <span class="pblabel">$starting</span>
7813: </div>
7814: </p>
7815: ENDPROGBAR
1.1045 www 7816: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7817: }
7818:
7819: sub LCprogressbarUpdate {
1.1042 www 7820: my ($r,$val,$text)=@_;
7821: unless ($val) {
7822: if ($LClastpercent) {
7823: $val=$LClastpercent;
7824: } else {
7825: $val=0;
7826: }
7827: }
1.1041 www 7828: if ($val<0) { $val=0; }
7829: if ($val>100) { $val=0; }
1.1042 www 7830: $LClastpercent=$val;
1.1041 www 7831: unless ($text) { $text=$val.'%'; }
7832: $text=&js_ready($text);
1.1044 www 7833: &r_print($r,<<ENDUPDATE);
1.1041 www 7834: <script type="text/javascript">
7835: // <![CDATA[
1.1045 www 7836: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7837: // ]]>
7838: </script>
7839: ENDUPDATE
1.1035 www 7840: }
7841:
1.1042 www 7842: sub LCprogressbarClose {
7843: my ($r)=@_;
7844: $LClastpercent=0;
1.1044 www 7845: &r_print($r,<<ENDCLOSE);
1.1042 www 7846: <script type="text/javascript">
7847: // <![CDATA[
1.1045 www 7848: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7849: // ]]>
7850: </script>
7851: ENDCLOSE
1.1044 www 7852: }
7853:
7854: sub r_print {
7855: my ($r,$to_print)=@_;
7856: if ($r) {
7857: $r->print($to_print);
7858: $r->rflush();
7859: } else {
7860: print($to_print);
7861: }
1.1042 www 7862: }
7863:
1.320 albertel 7864: sub html_encode {
7865: my ($result) = @_;
7866:
1.322 albertel 7867: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7868:
7869: return $result;
7870: }
1.1044 www 7871:
1.317 albertel 7872: sub js_ready {
7873: my ($result) = @_;
7874:
1.323 albertel 7875: $result =~ s/[\n\r]/ /xmsg;
7876: $result =~ s/\\/\\\\/xmsg;
7877: $result =~ s/'/\\'/xmsg;
1.372 albertel 7878: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7879:
7880: return $result;
7881: }
7882:
1.315 albertel 7883: sub validate_page {
7884: if ( exists($env{'internal.start_page'})
1.316 albertel 7885: && $env{'internal.start_page'} > 1) {
7886: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7887: $env{'internal.start_page'}.' '.
1.316 albertel 7888: $ENV{'request.filename'});
1.315 albertel 7889: }
7890: if ( exists($env{'internal.end_page'})
1.316 albertel 7891: && $env{'internal.end_page'} > 1) {
7892: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7893: $env{'internal.end_page'}.' '.
1.316 albertel 7894: $env{'request.filename'});
1.315 albertel 7895: }
7896: if ( exists($env{'internal.start_page'})
7897: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7898: &Apache::lonnet::logthis('start_page called without end_page '.
7899: $env{'request.filename'});
1.315 albertel 7900: }
7901: if ( ! exists($env{'internal.start_page'})
7902: && exists($env{'internal.end_page'})) {
1.316 albertel 7903: &Apache::lonnet::logthis('end_page called without start_page'.
7904: $env{'request.filename'});
1.315 albertel 7905: }
1.306 albertel 7906: }
1.315 albertel 7907:
1.996 www 7908:
7909: sub start_scrollbox {
1.1075 raeburn 7910: my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998 raeburn 7911: unless ($outerwidth) { $outerwidth='520px'; }
7912: unless ($width) { $width='500px'; }
7913: unless ($height) { $height='200px'; }
1.1075 raeburn 7914: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7915: if ($id ne '') {
1.1020 raeburn 7916: $table_id = " id='table_$id'";
7917: $div_id = " id='div_$id'";
1.1018 raeburn 7918: }
1.1075 raeburn 7919: if ($bgcolor ne '') {
7920: $tdcol = "background-color: $bgcolor;";
7921: }
7922: return <<"END";
7923: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
7924: END
1.996 www 7925: }
7926:
7927: sub end_scrollbox {
1.1036 www 7928: return '</div></td></tr></table>';
1.996 www 7929: }
7930:
1.318 albertel 7931: sub simple_error_page {
7932: my ($r,$title,$msg) = @_;
7933: my $page =
7934: &Apache::loncommon::start_page($title).
1.1097 bisitz 7935: '<p class="LC_error">'.&mt($msg).'</p>'.
1.318 albertel 7936: &Apache::loncommon::end_page();
7937: if (ref($r)) {
7938: $r->print($page);
1.327 albertel 7939: return;
1.318 albertel 7940: }
7941: return $page;
7942: }
1.347 albertel 7943:
7944: {
1.610 albertel 7945: my @row_count;
1.961 onken 7946:
7947: sub start_data_table_count {
7948: unshift(@row_count, 0);
7949: return;
7950: }
7951:
7952: sub end_data_table_count {
7953: shift(@row_count);
7954: return;
7955: }
7956:
1.347 albertel 7957: sub start_data_table {
1.1018 raeburn 7958: my ($add_class,$id) = @_;
1.422 albertel 7959: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 7960: my $table_id;
7961: if (defined($id)) {
7962: $table_id = ' id="'.$id.'"';
7963: }
1.961 onken 7964: &start_data_table_count();
1.1018 raeburn 7965: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 7966: }
7967:
7968: sub end_data_table {
1.961 onken 7969: &end_data_table_count();
1.389 albertel 7970: return '</table>'."\n";;
1.347 albertel 7971: }
7972:
7973: sub start_data_table_row {
1.974 wenzelju 7974: my ($add_class, $id) = @_;
1.610 albertel 7975: $row_count[0]++;
7976: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 7977: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 7978: $id = (' id="'.$id.'"') unless ($id eq '');
7979: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 7980: }
1.471 banghart 7981:
7982: sub continue_data_table_row {
1.974 wenzelju 7983: my ($add_class, $id) = @_;
1.610 albertel 7984: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 7985: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
7986: $id = (' id="'.$id.'"') unless ($id eq '');
7987: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 7988: }
1.347 albertel 7989:
7990: sub end_data_table_row {
1.389 albertel 7991: return '</tr>'."\n";;
1.347 albertel 7992: }
1.367 www 7993:
1.421 albertel 7994: sub start_data_table_empty_row {
1.707 bisitz 7995: # $row_count[0]++;
1.421 albertel 7996: return '<tr class="LC_empty_row" >'."\n";;
7997: }
7998:
7999: sub end_data_table_empty_row {
8000: return '</tr>'."\n";;
8001: }
8002:
1.367 www 8003: sub start_data_table_header_row {
1.389 albertel 8004: return '<tr class="LC_header_row">'."\n";;
1.367 www 8005: }
8006:
8007: sub end_data_table_header_row {
1.389 albertel 8008: return '</tr>'."\n";;
1.367 www 8009: }
1.890 droeschl 8010:
8011: sub data_table_caption {
8012: my $caption = shift;
8013: return "<caption class=\"LC_caption\">$caption</caption>";
8014: }
1.347 albertel 8015: }
8016:
1.548 albertel 8017: =pod
8018:
8019: =item * &inhibit_menu_check($arg)
8020:
8021: Checks for a inhibitmenu state and generates output to preserve it
8022:
8023: Inputs: $arg - can be any of
8024: - undef - in which case the return value is a string
8025: to add into arguments list of a uri
8026: - 'input' - in which case the return value is a HTML
8027: <form> <input> field of type hidden to
8028: preserve the value
8029: - a url - in which case the return value is the url with
8030: the neccesary cgi args added to preserve the
8031: inhibitmenu state
8032: - a ref to a url - no return value, but the string is
8033: updated to include the neccessary cgi
8034: args to preserve the inhibitmenu state
8035:
8036: =cut
8037:
8038: sub inhibit_menu_check {
8039: my ($arg) = @_;
8040: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8041: if ($arg eq 'input') {
8042: if ($env{'form.inhibitmenu'}) {
8043: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8044: } else {
8045: return
8046: }
8047: }
8048: if ($env{'form.inhibitmenu'}) {
8049: if (ref($arg)) {
8050: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8051: } elsif ($arg eq '') {
8052: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8053: } else {
8054: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8055: }
8056: }
8057: if (!ref($arg)) {
8058: return $arg;
8059: }
8060: }
8061:
1.251 albertel 8062: ###############################################
1.182 matthew 8063:
8064: =pod
8065:
1.549 albertel 8066: =back
8067:
8068: =head1 User Information Routines
8069:
8070: =over 4
8071:
1.405 albertel 8072: =item * &get_users_function()
1.182 matthew 8073:
8074: Used by &bodytag to determine the current users primary role.
8075: Returns either 'student','coordinator','admin', or 'author'.
8076:
8077: =cut
8078:
8079: ###############################################
8080: sub get_users_function {
1.815 tempelho 8081: my $function = 'norole';
1.818 tempelho 8082: if ($env{'request.role'}=~/^(st)/) {
8083: $function='student';
8084: }
1.907 raeburn 8085: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8086: $function='coordinator';
8087: }
1.258 albertel 8088: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8089: $function='admin';
8090: }
1.826 bisitz 8091: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8092: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8093: $function='author';
8094: }
8095: return $function;
1.54 www 8096: }
1.99 www 8097:
8098: ###############################################
8099:
1.233 raeburn 8100: =pod
8101:
1.821 raeburn 8102: =item * &show_course()
8103:
8104: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8105: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8106:
8107: Inputs:
8108: None
8109:
8110: Outputs:
8111: Scalar: 1 if 'Course' to be used, 0 otherwise.
8112:
8113: =cut
8114:
8115: ###############################################
8116: sub show_course {
8117: my $course = !$env{'user.adv'};
8118: if (!$env{'user.adv'}) {
8119: foreach my $env (keys(%env)) {
8120: next if ($env !~ m/^user\.priv\./);
8121: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8122: $course = 0;
8123: last;
8124: }
8125: }
8126: }
8127: return $course;
8128: }
8129:
8130: ###############################################
8131:
8132: =pod
8133:
1.542 raeburn 8134: =item * &check_user_status()
1.274 raeburn 8135:
8136: Determines current status of supplied role for a
8137: specific user. Roles can be active, previous or future.
8138:
8139: Inputs:
8140: user's domain, user's username, course's domain,
1.375 raeburn 8141: course's number, optional section ID.
1.274 raeburn 8142:
8143: Outputs:
8144: role status: active, previous or future.
8145:
8146: =cut
8147:
8148: sub check_user_status {
1.412 raeburn 8149: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8150: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8151: my @uroles = keys %userinfo;
8152: my $srchstr;
8153: my $active_chk = 'none';
1.412 raeburn 8154: my $now = time;
1.274 raeburn 8155: if (@uroles > 0) {
1.908 raeburn 8156: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8157: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8158: } else {
1.412 raeburn 8159: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8160: }
8161: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8162: my $role_end = 0;
8163: my $role_start = 0;
8164: $active_chk = 'active';
1.412 raeburn 8165: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8166: $role_end = $1;
8167: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8168: $role_start = $1;
1.274 raeburn 8169: }
8170: }
8171: if ($role_start > 0) {
1.412 raeburn 8172: if ($now < $role_start) {
1.274 raeburn 8173: $active_chk = 'future';
8174: }
8175: }
8176: if ($role_end > 0) {
1.412 raeburn 8177: if ($now > $role_end) {
1.274 raeburn 8178: $active_chk = 'previous';
8179: }
8180: }
8181: }
8182: }
8183: return $active_chk;
8184: }
8185:
8186: ###############################################
8187:
8188: =pod
8189:
1.405 albertel 8190: =item * &get_sections()
1.233 raeburn 8191:
8192: Determines all the sections for a course including
8193: sections with students and sections containing other roles.
1.419 raeburn 8194: Incoming parameters:
8195:
8196: 1. domain
8197: 2. course number
8198: 3. reference to array containing roles for which sections should
8199: be gathered (optional).
8200: 4. reference to array containing status types for which sections
8201: should be gathered (optional).
8202:
8203: If the third argument is undefined, sections are gathered for any role.
8204: If the fourth argument is undefined, sections are gathered for any status.
8205: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8206:
1.374 raeburn 8207: Returns section hash (keys are section IDs, values are
8208: number of users in each section), subject to the
1.419 raeburn 8209: optional roles filter, optional status filter
1.233 raeburn 8210:
8211: =cut
8212:
8213: ###############################################
8214: sub get_sections {
1.419 raeburn 8215: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8216: if (!defined($cdom) || !defined($cnum)) {
8217: my $cid = $env{'request.course.id'};
8218:
8219: return if (!defined($cid));
8220:
8221: $cdom = $env{'course.'.$cid.'.domain'};
8222: $cnum = $env{'course.'.$cid.'.num'};
8223: }
8224:
8225: my %sectioncount;
1.419 raeburn 8226: my $now = time;
1.240 albertel 8227:
1.366 albertel 8228: if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276 albertel 8229: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8230: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8231: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8232: my $start_index = &Apache::loncoursedata::CL_START();
8233: my $end_index = &Apache::loncoursedata::CL_END();
8234: my $status;
1.366 albertel 8235: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8236: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8237: $data->[$status_index],
8238: $data->[$start_index],
8239: $data->[$end_index]);
8240: if ($stu_status eq 'Active') {
8241: $status = 'active';
8242: } elsif ($end < $now) {
8243: $status = 'previous';
8244: } elsif ($start > $now) {
8245: $status = 'future';
8246: }
8247: if ($section ne '-1' && $section !~ /^\s*$/) {
8248: if ((!defined($possible_status)) || (($status ne '') &&
8249: (grep/^\Q$status\E$/,@{$possible_status}))) {
8250: $sectioncount{$section}++;
8251: }
1.240 albertel 8252: }
8253: }
8254: }
8255: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8256: foreach my $user (sort(keys(%courseroles))) {
8257: if ($user !~ /^(\w{2})/) { next; }
8258: my ($role) = ($user =~ /^(\w{2})/);
8259: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8260: my ($section,$status);
1.240 albertel 8261: if ($role eq 'cr' &&
8262: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8263: $section=$1;
8264: }
8265: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8266: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8267: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8268: if ($end == -1 && $start == -1) {
8269: next; #deleted role
8270: }
8271: if (!defined($possible_status)) {
8272: $sectioncount{$section}++;
8273: } else {
8274: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8275: $status = 'active';
8276: } elsif ($end < $now) {
8277: $status = 'future';
8278: } elsif ($start > $now) {
8279: $status = 'previous';
8280: }
8281: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8282: $sectioncount{$section}++;
8283: }
8284: }
1.233 raeburn 8285: }
1.366 albertel 8286: return %sectioncount;
1.233 raeburn 8287: }
8288:
1.274 raeburn 8289: ###############################################
1.294 raeburn 8290:
8291: =pod
1.405 albertel 8292:
8293: =item * &get_course_users()
8294:
1.275 raeburn 8295: Retrieves usernames:domains for users in the specified course
8296: with specific role(s), and access status.
8297:
8298: Incoming parameters:
1.277 albertel 8299: 1. course domain
8300: 2. course number
8301: 3. access status: users must have - either active,
1.275 raeburn 8302: previous, future, or all.
1.277 albertel 8303: 4. reference to array of permissible roles
1.288 raeburn 8304: 5. reference to array of section restrictions (optional)
8305: 6. reference to results object (hash of hashes).
8306: 7. reference to optional userdata hash
1.609 raeburn 8307: 8. reference to optional statushash
1.630 raeburn 8308: 9. flag if privileged users (except those set to unhide in
8309: course settings) should be excluded
1.609 raeburn 8310: Keys of top level results hash are roles.
1.275 raeburn 8311: Keys of inner hashes are username:domain, with
8312: values set to access type.
1.288 raeburn 8313: Optional userdata hash returns an array with arguments in the
8314: same order as loncoursedata::get_classlist() for student data.
8315:
1.609 raeburn 8316: Optional statushash returns
8317:
1.288 raeburn 8318: Entries for end, start, section and status are blank because
8319: of the possibility of multiple values for non-student roles.
8320:
1.275 raeburn 8321: =cut
1.405 albertel 8322:
1.275 raeburn 8323: ###############################################
1.405 albertel 8324:
1.275 raeburn 8325: sub get_course_users {
1.630 raeburn 8326: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8327: my %idx = ();
1.419 raeburn 8328: my %seclists;
1.288 raeburn 8329:
8330: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8331: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8332: $idx{end} = &Apache::loncoursedata::CL_END();
8333: $idx{start} = &Apache::loncoursedata::CL_START();
8334: $idx{id} = &Apache::loncoursedata::CL_ID();
8335: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8336: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8337: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8338:
1.290 albertel 8339: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8340: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8341: my $now = time;
1.277 albertel 8342: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8343: my $match = 0;
1.412 raeburn 8344: my $secmatch = 0;
1.419 raeburn 8345: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8346: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8347: if ($section eq '') {
8348: $section = 'none';
8349: }
1.291 albertel 8350: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8351: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8352: $secmatch = 1;
8353: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8354: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8355: $secmatch = 1;
8356: }
8357: } else {
1.419 raeburn 8358: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8359: $secmatch = 1;
8360: }
1.290 albertel 8361: }
1.412 raeburn 8362: if (!$secmatch) {
8363: next;
8364: }
1.419 raeburn 8365: }
1.275 raeburn 8366: if (defined($$types{'active'})) {
1.288 raeburn 8367: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8368: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8369: $match = 1;
1.275 raeburn 8370: }
8371: }
8372: if (defined($$types{'previous'})) {
1.609 raeburn 8373: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8374: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8375: $match = 1;
1.275 raeburn 8376: }
8377: }
8378: if (defined($$types{'future'})) {
1.609 raeburn 8379: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8380: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8381: $match = 1;
1.275 raeburn 8382: }
8383: }
1.609 raeburn 8384: if ($match) {
8385: push(@{$seclists{$student}},$section);
8386: if (ref($userdata) eq 'HASH') {
8387: $$userdata{$student} = $$classlist{$student};
8388: }
8389: if (ref($statushash) eq 'HASH') {
8390: $statushash->{$student}{'st'}{$section} = $status;
8391: }
1.288 raeburn 8392: }
1.275 raeburn 8393: }
8394: }
1.412 raeburn 8395: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8396: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8397: my $now = time;
1.609 raeburn 8398: my %displaystatus = ( previous => 'Expired',
8399: active => 'Active',
8400: future => 'Future',
8401: );
1.630 raeburn 8402: my %nothide;
8403: if ($hidepriv) {
8404: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8405: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8406: if ($user !~ /:/) {
8407: $nothide{join(':',split(/[\@]/,$user))}=1;
8408: } else {
8409: $nothide{$user} = 1;
8410: }
8411: }
8412: }
1.439 raeburn 8413: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8414: my $match = 0;
1.412 raeburn 8415: my $secmatch = 0;
1.439 raeburn 8416: my $status;
1.412 raeburn 8417: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8418: $user =~ s/:$//;
1.439 raeburn 8419: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8420: if ($end == -1 || $start == -1) {
8421: next;
8422: }
8423: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8424: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8425: my ($uname,$udom) = split(/:/,$user);
8426: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8427: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8428: $secmatch = 1;
8429: } elsif ($usec eq '') {
1.420 albertel 8430: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8431: $secmatch = 1;
8432: }
8433: } else {
8434: if (grep(/^\Q$usec\E$/,@{$sections})) {
8435: $secmatch = 1;
8436: }
8437: }
8438: if (!$secmatch) {
8439: next;
8440: }
1.288 raeburn 8441: }
1.419 raeburn 8442: if ($usec eq '') {
8443: $usec = 'none';
8444: }
1.275 raeburn 8445: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8446: if ($hidepriv) {
8447: if ((&Apache::lonnet::privileged($uname,$udom)) &&
8448: (!$nothide{$uname.':'.$udom})) {
8449: next;
8450: }
8451: }
1.503 raeburn 8452: if ($end > 0 && $end < $now) {
1.439 raeburn 8453: $status = 'previous';
8454: } elsif ($start > $now) {
8455: $status = 'future';
8456: } else {
8457: $status = 'active';
8458: }
1.277 albertel 8459: foreach my $type (keys(%{$types})) {
1.275 raeburn 8460: if ($status eq $type) {
1.420 albertel 8461: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8462: push(@{$$users{$role}{$user}},$type);
8463: }
1.288 raeburn 8464: $match = 1;
8465: }
8466: }
1.419 raeburn 8467: if (($match) && (ref($userdata) eq 'HASH')) {
8468: if (!exists($$userdata{$uname.':'.$udom})) {
8469: &get_user_info($udom,$uname,\%idx,$userdata);
8470: }
1.420 albertel 8471: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8472: push(@{$seclists{$uname.':'.$udom}},$usec);
8473: }
1.609 raeburn 8474: if (ref($statushash) eq 'HASH') {
8475: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8476: }
1.275 raeburn 8477: }
8478: }
8479: }
8480: }
1.290 albertel 8481: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8482: if ((defined($cdom)) && (defined($cnum))) {
8483: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8484: if ( defined($csettings{'internal.courseowner'}) ) {
8485: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8486: next if ($owner eq '');
8487: my ($ownername,$ownerdom);
8488: if ($owner =~ /^([^:]+):([^:]+)$/) {
8489: $ownername = $1;
8490: $ownerdom = $2;
8491: } else {
8492: $ownername = $owner;
8493: $ownerdom = $cdom;
8494: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8495: }
8496: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8497: if (defined($userdata) &&
1.609 raeburn 8498: !exists($$userdata{$owner})) {
8499: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8500: if (!grep(/^none$/,@{$seclists{$owner}})) {
8501: push(@{$seclists{$owner}},'none');
8502: }
8503: if (ref($statushash) eq 'HASH') {
8504: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8505: }
1.290 albertel 8506: }
1.279 raeburn 8507: }
8508: }
8509: }
1.419 raeburn 8510: foreach my $user (keys(%seclists)) {
8511: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8512: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8513: }
1.275 raeburn 8514: }
8515: return;
8516: }
8517:
1.288 raeburn 8518: sub get_user_info {
8519: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8520: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8521: &plainname($uname,$udom,'lastname');
1.291 albertel 8522: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8523: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8524: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8525: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8526: return;
8527: }
1.275 raeburn 8528:
1.472 raeburn 8529: ###############################################
8530:
8531: =pod
8532:
8533: =item * &get_user_quota()
8534:
8535: Retrieves quota assigned for storage of portfolio files for a user
8536:
8537: Incoming parameters:
8538: 1. user's username
8539: 2. user's domain
8540:
8541: Returns:
1.536 raeburn 8542: 1. Disk quota (in Mb) assigned to student.
8543: 2. (Optional) Type of setting: custom or default
8544: (individually assigned or default for user's
8545: institutional status).
8546: 3. (Optional) - User's institutional status (e.g., faculty, staff
8547: or student - types as defined in localenroll::inst_usertypes
8548: for user's domain, which determines default quota for user.
8549: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8550:
8551: If a value has been stored in the user's environment,
1.536 raeburn 8552: it will return that, otherwise it returns the maximal default
8553: defined for the user's instituional status(es) in the domain.
1.472 raeburn 8554:
8555: =cut
8556:
8557: ###############################################
8558:
8559:
8560: sub get_user_quota {
8561: my ($uname,$udom) = @_;
1.536 raeburn 8562: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8563: if (!defined($udom)) {
8564: $udom = $env{'user.domain'};
8565: }
8566: if (!defined($uname)) {
8567: $uname = $env{'user.name'};
8568: }
8569: if (($udom eq '' || $uname eq '') ||
8570: ($udom eq 'public') && ($uname eq 'public')) {
8571: $quota = 0;
1.536 raeburn 8572: $quotatype = 'default';
8573: $defquota = 0;
1.472 raeburn 8574: } else {
1.536 raeburn 8575: my $inststatus;
1.472 raeburn 8576: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8577: $quota = $env{'environment.portfolioquota'};
1.536 raeburn 8578: $inststatus = $env{'environment.inststatus'};
1.472 raeburn 8579: } else {
1.536 raeburn 8580: my %userenv =
8581: &Apache::lonnet::get('environment',['portfolioquota',
8582: 'inststatus'],$udom,$uname);
1.472 raeburn 8583: my ($tmp) = keys(%userenv);
8584: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8585: $quota = $userenv{'portfolioquota'};
1.536 raeburn 8586: $inststatus = $userenv{'inststatus'};
1.472 raeburn 8587: } else {
8588: undef(%userenv);
8589: }
8590: }
1.536 raeburn 8591: ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472 raeburn 8592: if ($quota eq '') {
1.536 raeburn 8593: $quota = $defquota;
8594: $quotatype = 'default';
8595: } else {
8596: $quotatype = 'custom';
1.472 raeburn 8597: }
8598: }
1.536 raeburn 8599: if (wantarray) {
8600: return ($quota,$quotatype,$settingstatus,$defquota);
8601: } else {
8602: return $quota;
8603: }
1.472 raeburn 8604: }
8605:
8606: ###############################################
8607:
8608: =pod
8609:
8610: =item * &default_quota()
8611:
1.536 raeburn 8612: Retrieves default quota assigned for storage of user portfolio files,
8613: given an (optional) user's institutional status.
1.472 raeburn 8614:
8615: Incoming parameters:
8616: 1. domain
1.536 raeburn 8617: 2. (Optional) institutional status(es). This is a : separated list of
8618: status types (e.g., faculty, staff, student etc.)
8619: which apply to the user for whom the default is being retrieved.
8620: If the institutional status string in undefined, the domain
8621: default quota will be returned.
1.472 raeburn 8622:
8623: Returns:
8624: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536 raeburn 8625: 2. (Optional) institutional type which determined the value of the
8626: default quota.
1.472 raeburn 8627:
8628: If a value has been stored in the domain's configuration db,
8629: it will return that, otherwise it returns 20 (for backwards
8630: compatibility with domains which have not set up a configuration
8631: db file; the original statically defined portfolio quota was 20 Mb).
8632:
1.536 raeburn 8633: If the user's status includes multiple types (e.g., staff and student),
8634: the largest default quota which applies to the user determines the
8635: default quota returned.
8636:
1.780 raeburn 8637: =back
8638:
1.472 raeburn 8639: =cut
8640:
8641: ###############################################
8642:
8643:
8644: sub default_quota {
1.536 raeburn 8645: my ($udom,$inststatus) = @_;
8646: my ($defquota,$settingstatus);
8647: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8648: ['quotas'],$udom);
8649: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8650: if ($inststatus ne '') {
1.765 raeburn 8651: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8652: foreach my $item (@statuses) {
1.711 raeburn 8653: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8654: if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
8655: if ($defquota eq '') {
8656: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8657: $settingstatus = $item;
8658: } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
8659: $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
8660: $settingstatus = $item;
8661: }
8662: }
8663: } else {
8664: if ($quotahash{'quotas'}{$item} ne '') {
8665: if ($defquota eq '') {
8666: $defquota = $quotahash{'quotas'}{$item};
8667: $settingstatus = $item;
8668: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8669: $defquota = $quotahash{'quotas'}{$item};
8670: $settingstatus = $item;
8671: }
1.536 raeburn 8672: }
8673: }
8674: }
8675: }
8676: if ($defquota eq '') {
1.711 raeburn 8677: if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
8678: $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
8679: } else {
8680: $defquota = $quotahash{'quotas'}{'default'};
8681: }
1.536 raeburn 8682: $settingstatus = 'default';
8683: }
8684: } else {
8685: $settingstatus = 'default';
8686: $defquota = 20;
8687: }
8688: if (wantarray) {
8689: return ($defquota,$settingstatus);
1.472 raeburn 8690: } else {
1.536 raeburn 8691: return $defquota;
1.472 raeburn 8692: }
8693: }
8694:
1.384 raeburn 8695: sub get_secgrprole_info {
8696: my ($cdom,$cnum,$needroles,$type) = @_;
8697: my %sections_count = &get_sections($cdom,$cnum);
8698: my @sections = (sort {$a <=> $b} keys(%sections_count));
8699: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
8700: my @groups = sort(keys(%curr_groups));
8701: my $allroles = [];
8702: my $rolehash;
8703: my $accesshash = {
8704: active => 'Currently has access',
8705: future => 'Will have future access',
8706: previous => 'Previously had access',
8707: };
8708: if ($needroles) {
8709: $rolehash = {'all' => 'all'};
1.385 albertel 8710: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8711: if (&Apache::lonnet::error(%user_roles)) {
8712: undef(%user_roles);
8713: }
8714: foreach my $item (keys(%user_roles)) {
1.384 raeburn 8715: my ($role)=split(/\:/,$item,2);
8716: if ($role eq 'cr') { next; }
8717: if ($role =~ /^cr/) {
8718: $$rolehash{$role} = (split('/',$role))[3];
8719: } else {
8720: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
8721: }
8722: }
8723: foreach my $key (sort(keys(%{$rolehash}))) {
8724: push(@{$allroles},$key);
8725: }
8726: push (@{$allroles},'st');
8727: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
8728: }
8729: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
8730: }
8731:
1.555 raeburn 8732: sub user_picker {
1.994 raeburn 8733: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 8734: my $currdom = $dom;
8735: my %curr_selected = (
8736: srchin => 'dom',
1.580 raeburn 8737: srchby => 'lastname',
1.555 raeburn 8738: );
8739: my $srchterm;
1.625 raeburn 8740: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 8741: if ($srch->{'srchby'} ne '') {
8742: $curr_selected{'srchby'} = $srch->{'srchby'};
8743: }
8744: if ($srch->{'srchin'} ne '') {
8745: $curr_selected{'srchin'} = $srch->{'srchin'};
8746: }
8747: if ($srch->{'srchtype'} ne '') {
8748: $curr_selected{'srchtype'} = $srch->{'srchtype'};
8749: }
8750: if ($srch->{'srchdomain'} ne '') {
8751: $currdom = $srch->{'srchdomain'};
8752: }
8753: $srchterm = $srch->{'srchterm'};
8754: }
8755: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 8756: 'usr' => 'Search criteria',
1.563 raeburn 8757: 'doma' => 'Domain/institution to search',
1.558 albertel 8758: 'uname' => 'username',
8759: 'lastname' => 'last name',
1.555 raeburn 8760: 'lastfirst' => 'last name, first name',
1.558 albertel 8761: 'crs' => 'in this course',
1.576 raeburn 8762: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 8763: 'alc' => 'all LON-CAPA',
1.573 raeburn 8764: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 8765: 'exact' => 'is',
8766: 'contains' => 'contains',
1.569 raeburn 8767: 'begins' => 'begins with',
1.571 raeburn 8768: 'youm' => "You must include some text to search for.",
8769: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
8770: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
8771: 'yomc' => "You must choose a domain when using an institutional directory search.",
8772: 'ymcd' => "You must choose a domain when using a domain search.",
8773: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
8774: 'whse' => "When searching by last,first you must include at least one character in the first name.",
8775: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 8776: );
1.563 raeburn 8777: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
8778: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 8779:
8780: my @srchins = ('crs','dom','alc','instd');
8781:
8782: foreach my $option (@srchins) {
8783: # FIXME 'alc' option unavailable until
8784: # loncreateuser::print_user_query_page()
8785: # has been completed.
8786: next if ($option eq 'alc');
1.880 raeburn 8787: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 8788: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 8789: if ($curr_selected{'srchin'} eq $option) {
8790: $srchinsel .= '
8791: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8792: } else {
8793: $srchinsel .= '
8794: <option value="'.$option.'">'.$lt{$option}.'</option>';
8795: }
1.555 raeburn 8796: }
1.563 raeburn 8797: $srchinsel .= "\n </select>\n";
1.555 raeburn 8798:
8799: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 8800: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 8801: if ($curr_selected{'srchby'} eq $option) {
8802: $srchbysel .= '
8803: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8804: } else {
8805: $srchbysel .= '
8806: <option value="'.$option.'">'.$lt{$option}.'</option>';
8807: }
8808: }
8809: $srchbysel .= "\n </select>\n";
8810:
8811: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 8812: foreach my $option ('begins','contains','exact') {
1.555 raeburn 8813: if ($curr_selected{'srchtype'} eq $option) {
8814: $srchtypesel .= '
8815: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
8816: } else {
8817: $srchtypesel .= '
8818: <option value="'.$option.'">'.$lt{$option}.'</option>';
8819: }
8820: }
8821: $srchtypesel .= "\n </select>\n";
8822:
1.558 albertel 8823: my ($newuserscript,$new_user_create);
1.994 raeburn 8824: my $context_dom = $env{'request.role.domain'};
8825: if ($context eq 'requestcrs') {
8826: if ($env{'form.coursedom'} ne '') {
8827: $context_dom = $env{'form.coursedom'};
8828: }
8829: }
1.556 raeburn 8830: if ($forcenewuser) {
1.576 raeburn 8831: if (ref($srch) eq 'HASH') {
1.994 raeburn 8832: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 8833: if ($cancreate) {
8834: $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>';
8835: } else {
1.799 bisitz 8836: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 8837: my %usertypetext = (
8838: official => 'institutional',
8839: unofficial => 'non-institutional',
8840: );
1.799 bisitz 8841: $new_user_create = '<p class="LC_warning">'
8842: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
8843: .' '
8844: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
8845: ,'<a href="'.$helplink.'">','</a>')
8846: .'</p><br />';
1.627 raeburn 8847: }
1.576 raeburn 8848: }
8849: }
8850:
1.556 raeburn 8851: $newuserscript = <<"ENDSCRIPT";
8852:
1.570 raeburn 8853: function setSearch(createnew,callingForm) {
1.556 raeburn 8854: if (createnew == 1) {
1.570 raeburn 8855: for (var i=0; i<callingForm.srchby.length; i++) {
8856: if (callingForm.srchby.options[i].value == 'uname') {
8857: callingForm.srchby.selectedIndex = i;
1.556 raeburn 8858: }
8859: }
1.570 raeburn 8860: for (var i=0; i<callingForm.srchin.length; i++) {
8861: if ( callingForm.srchin.options[i].value == 'dom') {
8862: callingForm.srchin.selectedIndex = i;
1.556 raeburn 8863: }
8864: }
1.570 raeburn 8865: for (var i=0; i<callingForm.srchtype.length; i++) {
8866: if (callingForm.srchtype.options[i].value == 'exact') {
8867: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 8868: }
8869: }
1.570 raeburn 8870: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 8871: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 8872: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 8873: }
8874: }
8875: }
8876: }
8877: ENDSCRIPT
1.558 albertel 8878:
1.556 raeburn 8879: }
8880:
1.555 raeburn 8881: my $output = <<"END_BLOCK";
1.556 raeburn 8882: <script type="text/javascript">
1.824 bisitz 8883: // <![CDATA[
1.570 raeburn 8884: function validateEntry(callingForm) {
1.558 albertel 8885:
1.556 raeburn 8886: var checkok = 1;
1.558 albertel 8887: var srchin;
1.570 raeburn 8888: for (var i=0; i<callingForm.srchin.length; i++) {
8889: if ( callingForm.srchin[i].checked ) {
8890: srchin = callingForm.srchin[i].value;
1.558 albertel 8891: }
8892: }
8893:
1.570 raeburn 8894: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
8895: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
8896: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
8897: var srchterm = callingForm.srchterm.value;
8898: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 8899: var msg = "";
8900:
8901: if (srchterm == "") {
8902: checkok = 0;
1.571 raeburn 8903: msg += "$lt{'youm'}\\n";
1.556 raeburn 8904: }
8905:
1.569 raeburn 8906: if (srchtype== 'begins') {
8907: if (srchterm.length < 2) {
8908: checkok = 0;
1.571 raeburn 8909: msg += "$lt{'thte'}\\n";
1.569 raeburn 8910: }
8911: }
8912:
1.556 raeburn 8913: if (srchtype== 'contains') {
8914: if (srchterm.length < 3) {
8915: checkok = 0;
1.571 raeburn 8916: msg += "$lt{'thet'}\\n";
1.556 raeburn 8917: }
8918: }
8919: if (srchin == 'instd') {
8920: if (srchdomain == '') {
8921: checkok = 0;
1.571 raeburn 8922: msg += "$lt{'yomc'}\\n";
1.556 raeburn 8923: }
8924: }
8925: if (srchin == 'dom') {
8926: if (srchdomain == '') {
8927: checkok = 0;
1.571 raeburn 8928: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 8929: }
8930: }
8931: if (srchby == 'lastfirst') {
8932: if (srchterm.indexOf(",") == -1) {
8933: checkok = 0;
1.571 raeburn 8934: msg += "$lt{'whus'}\\n";
1.556 raeburn 8935: }
8936: if (srchterm.indexOf(",") == srchterm.length -1) {
8937: checkok = 0;
1.571 raeburn 8938: msg += "$lt{'whse'}\\n";
1.556 raeburn 8939: }
8940: }
8941: if (checkok == 0) {
1.571 raeburn 8942: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 8943: return;
8944: }
8945: if (checkok == 1) {
1.570 raeburn 8946: callingForm.submit();
1.556 raeburn 8947: }
8948: }
8949:
8950: $newuserscript
8951:
1.824 bisitz 8952: // ]]>
1.556 raeburn 8953: </script>
1.558 albertel 8954:
8955: $new_user_create
8956:
1.555 raeburn 8957: END_BLOCK
1.558 albertel 8958:
1.876 raeburn 8959: $output .= &Apache::lonhtmlcommon::start_pick_box().
8960: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
8961: $domform.
8962: &Apache::lonhtmlcommon::row_closure().
8963: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
8964: $srchbysel.
8965: $srchtypesel.
8966: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
8967: $srchinsel.
8968: &Apache::lonhtmlcommon::row_closure(1).
8969: &Apache::lonhtmlcommon::end_pick_box().
8970: '<br />';
1.555 raeburn 8971: return $output;
8972: }
8973:
1.612 raeburn 8974: sub user_rule_check {
1.615 raeburn 8975: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 8976: my $response;
8977: if (ref($usershash) eq 'HASH') {
8978: foreach my $user (keys(%{$usershash})) {
8979: my ($uname,$udom) = split(/:/,$user);
8980: next if ($udom eq '' || $uname eq '');
1.615 raeburn 8981: my ($id,$newuser);
1.612 raeburn 8982: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 8983: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 8984: $id = $usershash->{$user}->{'id'};
8985: }
8986: my $inst_response;
8987: if (ref($checks) eq 'HASH') {
8988: if (defined($checks->{'username'})) {
1.615 raeburn 8989: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8990: &Apache::lonnet::get_instuser($udom,$uname);
8991: } elsif (defined($checks->{'id'})) {
1.615 raeburn 8992: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 8993: &Apache::lonnet::get_instuser($udom,undef,$id);
8994: }
1.615 raeburn 8995: } else {
8996: ($inst_response,%{$inst_results->{$user}}) =
8997: &Apache::lonnet::get_instuser($udom,$uname);
8998: return;
1.612 raeburn 8999: }
1.615 raeburn 9000: if (!$got_rules->{$udom}) {
1.612 raeburn 9001: my %domconfig = &Apache::lonnet::get_dom('configuration',
9002: ['usercreation'],$udom);
9003: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9004: foreach my $item ('username','id') {
1.612 raeburn 9005: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9006: $$curr_rules{$udom}{$item} =
9007: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9008: }
9009: }
9010: }
1.615 raeburn 9011: $got_rules->{$udom} = 1;
1.585 raeburn 9012: }
1.612 raeburn 9013: foreach my $item (keys(%{$checks})) {
9014: if (ref($$curr_rules{$udom}) eq 'HASH') {
9015: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9016: if (@{$$curr_rules{$udom}{$item}} > 0) {
9017: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9018: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9019: if ($rule_check{$rule}) {
9020: $$rulematch{$user}{$item} = $rule;
9021: if ($inst_response eq 'ok') {
1.615 raeburn 9022: if (ref($inst_results) eq 'HASH') {
9023: if (ref($inst_results->{$user}) eq 'HASH') {
9024: if (keys(%{$inst_results->{$user}}) == 0) {
9025: $$alerts{$item}{$udom}{$uname} = 1;
9026: }
1.612 raeburn 9027: }
9028: }
1.615 raeburn 9029: }
9030: last;
1.585 raeburn 9031: }
9032: }
9033: }
9034: }
9035: }
9036: }
9037: }
9038: }
1.612 raeburn 9039: return;
9040: }
9041:
9042: sub user_rule_formats {
9043: my ($domain,$domdesc,$curr_rules,$check) = @_;
9044: my %text = (
9045: 'username' => 'Usernames',
9046: 'id' => 'IDs',
9047: );
9048: my $output;
9049: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9050: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9051: if (@{$ruleorder} > 0) {
1.1102 raeburn 9052: $output = '<br />'.
9053: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9054: '<span class="LC_cusr_emph">','</span>',$domdesc).
9055: ' <ul>';
1.612 raeburn 9056: foreach my $rule (@{$ruleorder}) {
9057: if (ref($curr_rules) eq 'ARRAY') {
9058: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9059: if (ref($rules->{$rule}) eq 'HASH') {
9060: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9061: $rules->{$rule}{'desc'}.'</li>';
9062: }
9063: }
9064: }
9065: }
9066: $output .= '</ul>';
9067: }
9068: }
9069: return $output;
9070: }
9071:
9072: sub instrule_disallow_msg {
1.615 raeburn 9073: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9074: my $response;
9075: my %text = (
9076: item => 'username',
9077: items => 'usernames',
9078: match => 'matches',
9079: do => 'does',
9080: action => 'a username',
9081: one => 'one',
9082: );
9083: if ($count > 1) {
9084: $text{'item'} = 'usernames';
9085: $text{'match'} ='match';
9086: $text{'do'} = 'do';
9087: $text{'action'} = 'usernames',
9088: $text{'one'} = 'ones';
9089: }
9090: if ($checkitem eq 'id') {
9091: $text{'items'} = 'IDs';
9092: $text{'item'} = 'ID';
9093: $text{'action'} = 'an ID';
1.615 raeburn 9094: if ($count > 1) {
9095: $text{'item'} = 'IDs';
9096: $text{'action'} = 'IDs';
9097: }
1.612 raeburn 9098: }
1.674 bisitz 9099: $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 9100: if ($mode eq 'upload') {
9101: if ($checkitem eq 'username') {
9102: $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'}.");
9103: } elsif ($checkitem eq 'id') {
1.674 bisitz 9104: $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 9105: }
1.669 raeburn 9106: } elsif ($mode eq 'selfcreate') {
9107: if ($checkitem eq 'id') {
9108: $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.");
9109: }
1.615 raeburn 9110: } else {
9111: if ($checkitem eq 'username') {
9112: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9113: } elsif ($checkitem eq 'id') {
9114: $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.");
9115: }
1.612 raeburn 9116: }
9117: return $response;
1.585 raeburn 9118: }
9119:
1.624 raeburn 9120: sub personal_data_fieldtitles {
9121: my %fieldtitles = &Apache::lonlocal::texthash (
9122: id => 'Student/Employee ID',
9123: permanentemail => 'E-mail address',
9124: lastname => 'Last Name',
9125: firstname => 'First Name',
9126: middlename => 'Middle Name',
9127: generation => 'Generation',
9128: gen => 'Generation',
1.765 raeburn 9129: inststatus => 'Affiliation',
1.624 raeburn 9130: );
9131: return %fieldtitles;
9132: }
9133:
1.642 raeburn 9134: sub sorted_inst_types {
9135: my ($dom) = @_;
9136: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9137: my $othertitle = &mt('All users');
9138: if ($env{'request.course.id'}) {
1.668 raeburn 9139: $othertitle = &mt('Any users');
1.642 raeburn 9140: }
9141: my @types;
9142: if (ref($order) eq 'ARRAY') {
9143: @types = @{$order};
9144: }
9145: if (@types == 0) {
9146: if (ref($usertypes) eq 'HASH') {
9147: @types = sort(keys(%{$usertypes}));
9148: }
9149: }
9150: if (keys(%{$usertypes}) > 0) {
9151: $othertitle = &mt('Other users');
9152: }
9153: return ($othertitle,$usertypes,\@types);
9154: }
9155:
1.645 raeburn 9156: sub get_institutional_codes {
9157: my ($settings,$allcourses,$LC_code) = @_;
9158: # Get complete list of course sections to update
9159: my @currsections = ();
9160: my @currxlists = ();
9161: my $coursecode = $$settings{'internal.coursecode'};
9162:
9163: if ($$settings{'internal.sectionnums'} ne '') {
9164: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9165: }
9166:
9167: if ($$settings{'internal.crosslistings'} ne '') {
9168: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9169: }
9170:
9171: if (@currxlists > 0) {
9172: foreach (@currxlists) {
9173: if (m/^([^:]+):(\w*)$/) {
9174: unless (grep/^$1$/,@{$allcourses}) {
9175: push @{$allcourses},$1;
9176: $$LC_code{$1} = $2;
9177: }
9178: }
9179: }
9180: }
9181:
9182: if (@currsections > 0) {
9183: foreach (@currsections) {
9184: if (m/^(\w+):(\w*)$/) {
9185: my $sec = $coursecode.$1;
9186: my $lc_sec = $2;
9187: unless (grep/^$sec$/,@{$allcourses}) {
9188: push @{$allcourses},$sec;
9189: $$LC_code{$sec} = $lc_sec;
9190: }
9191: }
9192: }
9193: }
9194: return;
9195: }
9196:
1.971 raeburn 9197: sub get_standard_codeitems {
9198: return ('Year','Semester','Department','Number','Section');
9199: }
9200:
1.112 bowersj2 9201: =pod
9202:
1.780 raeburn 9203: =head1 Slot Helpers
9204:
9205: =over 4
9206:
9207: =item * sorted_slots()
9208:
1.1040 raeburn 9209: Sorts an array of slot names in order of an optional sort key,
9210: default sort is by slot start time (earliest first).
1.780 raeburn 9211:
9212: Inputs:
9213:
9214: =over 4
9215:
9216: slotsarr - Reference to array of unsorted slot names.
9217:
9218: slots - Reference to hash of hash, where outer hash keys are slot names.
9219:
1.1040 raeburn 9220: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9221:
1.549 albertel 9222: =back
9223:
1.780 raeburn 9224: Returns:
9225:
9226: =over 4
9227:
1.1040 raeburn 9228: sorted - An array of slot names sorted by a specified sort key
9229: (default sort key is start time of the slot).
1.780 raeburn 9230:
9231: =back
9232:
9233: =cut
9234:
9235:
9236: sub sorted_slots {
1.1040 raeburn 9237: my ($slotsarr,$slots,$sortkey) = @_;
9238: if ($sortkey eq '') {
9239: $sortkey = 'starttime';
9240: }
1.780 raeburn 9241: my @sorted;
9242: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9243: @sorted =
9244: sort {
9245: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9246: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9247: }
9248: if (ref($slots->{$a})) { return -1;}
9249: if (ref($slots->{$b})) { return 1;}
9250: return 0;
9251: } @{$slotsarr};
9252: }
9253: return @sorted;
9254: }
9255:
1.1040 raeburn 9256: =pod
9257:
9258: =item * get_future_slots()
9259:
9260: Inputs:
9261:
9262: =over 4
9263:
9264: cnum - course number
9265:
9266: cdom - course domain
9267:
9268: now - current UNIX time
9269:
9270: symb - optional symb
9271:
9272: =back
9273:
9274: Returns:
9275:
9276: =over 4
9277:
9278: sorted_reservable - ref to array of student_schedulable slots currently
9279: reservable, ordered by end date of reservation period.
9280:
9281: reservable_now - ref to hash of student_schedulable slots currently
9282: reservable.
9283:
9284: Keys in inner hash are:
9285: (a) symb: either blank or symb to which slot use is restricted.
9286: (b) endreserve: end date of reservation period.
9287:
9288: sorted_future - ref to array of student_schedulable slots reservable in
9289: the future, ordered by start date of reservation period.
9290:
9291: future_reservable - ref to hash of student_schedulable slots reservable
9292: in the future.
9293:
9294: Keys in inner hash are:
9295: (a) symb: either blank or symb to which slot use is restricted.
9296: (b) startreserve: start date of reservation period.
9297:
9298: =back
9299:
9300: =cut
9301:
9302: sub get_future_slots {
9303: my ($cnum,$cdom,$now,$symb) = @_;
9304: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9305: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9306: foreach my $slot (keys(%slots)) {
9307: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9308: if ($symb) {
9309: next if (($slots{$slot}->{'symb'} ne '') &&
9310: ($slots{$slot}->{'symb'} ne $symb));
9311: }
9312: if (($slots{$slot}->{'starttime'} > $now) &&
9313: ($slots{$slot}->{'endtime'} > $now)) {
9314: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9315: my $userallowed = 0;
9316: if ($slots{$slot}->{'allowedsections'}) {
9317: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9318: if (!defined($env{'request.role.sec'})
9319: && grep(/^No section assigned$/,@allowed_sec)) {
9320: $userallowed=1;
9321: } else {
9322: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9323: $userallowed=1;
9324: }
9325: }
9326: unless ($userallowed) {
9327: if (defined($env{'request.course.groups'})) {
9328: my @groups = split(/:/,$env{'request.course.groups'});
9329: foreach my $group (@groups) {
9330: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9331: $userallowed=1;
9332: last;
9333: }
9334: }
9335: }
9336: }
9337: }
9338: if ($slots{$slot}->{'allowedusers'}) {
9339: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9340: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9341: if (grep(/^\Q$user\E$/,@allowed_users)) {
9342: $userallowed = 1;
9343: }
9344: }
9345: next unless($userallowed);
9346: }
9347: my $startreserve = $slots{$slot}->{'startreserve'};
9348: my $endreserve = $slots{$slot}->{'endreserve'};
9349: my $symb = $slots{$slot}->{'symb'};
9350: if (($startreserve < $now) &&
9351: (!$endreserve || $endreserve > $now)) {
9352: my $lastres = $endreserve;
9353: if (!$lastres) {
9354: $lastres = $slots{$slot}->{'starttime'};
9355: }
9356: $reservable_now{$slot} = {
9357: symb => $symb,
9358: endreserve => $lastres
9359: };
9360: } elsif (($startreserve > $now) &&
9361: (!$endreserve || $endreserve > $startreserve)) {
9362: $future_reservable{$slot} = {
9363: symb => $symb,
9364: startreserve => $startreserve
9365: };
9366: }
9367: }
9368: }
9369: my @unsorted_reservable = keys(%reservable_now);
9370: if (@unsorted_reservable > 0) {
9371: @sorted_reservable =
9372: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9373: }
9374: my @unsorted_future = keys(%future_reservable);
9375: if (@unsorted_future > 0) {
9376: @sorted_future =
9377: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9378: }
9379: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9380: }
1.780 raeburn 9381:
9382: =pod
9383:
1.1057 foxr 9384: =back
9385:
1.549 albertel 9386: =head1 HTTP Helpers
9387:
9388: =over 4
9389:
1.648 raeburn 9390: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9391:
1.258 albertel 9392: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9393: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9394: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9395:
9396: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9397: $possible_names is an ref to an array of form element names. As an example:
9398: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9399: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9400:
9401: =cut
1.1 albertel 9402:
1.6 albertel 9403: sub get_unprocessed_cgi {
1.25 albertel 9404: my ($query,$possible_names)= @_;
1.26 matthew 9405: # $Apache::lonxml::debug=1;
1.356 albertel 9406: foreach my $pair (split(/&/,$query)) {
9407: my ($name, $value) = split(/=/,$pair);
1.369 www 9408: $name = &unescape($name);
1.25 albertel 9409: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9410: $value =~ tr/+/ /;
9411: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9412: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9413: }
1.16 harris41 9414: }
1.6 albertel 9415: }
9416:
1.112 bowersj2 9417: =pod
9418:
1.648 raeburn 9419: =item * &cacheheader()
1.112 bowersj2 9420:
9421: returns cache-controlling header code
9422:
9423: =cut
9424:
1.7 albertel 9425: sub cacheheader {
1.258 albertel 9426: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9427: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9428: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9429: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9430: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9431: return $output;
1.7 albertel 9432: }
9433:
1.112 bowersj2 9434: =pod
9435:
1.648 raeburn 9436: =item * &no_cache($r)
1.112 bowersj2 9437:
9438: specifies header code to not have cache
9439:
9440: =cut
9441:
1.9 albertel 9442: sub no_cache {
1.216 albertel 9443: my ($r) = @_;
9444: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9445: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9446: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9447: $r->no_cache(1);
9448: $r->header_out("Expires" => $date);
9449: $r->header_out("Pragma" => "no-cache");
1.123 www 9450: }
9451:
9452: sub content_type {
1.181 albertel 9453: my ($r,$type,$charset) = @_;
1.299 foxr 9454: if ($r) {
9455: # Note that printout.pl calls this with undef for $r.
9456: &no_cache($r);
9457: }
1.258 albertel 9458: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9459: unless ($charset) {
9460: $charset=&Apache::lonlocal::current_encoding;
9461: }
9462: if ($charset) { $type.='; charset='.$charset; }
9463: if ($r) {
9464: $r->content_type($type);
9465: } else {
9466: print("Content-type: $type\n\n");
9467: }
1.9 albertel 9468: }
1.25 albertel 9469:
1.112 bowersj2 9470: =pod
9471:
1.648 raeburn 9472: =item * &add_to_env($name,$value)
1.112 bowersj2 9473:
1.258 albertel 9474: adds $name to the %env hash with value
1.112 bowersj2 9475: $value, if $name already exists, the entry is converted to an array
9476: reference and $value is added to the array.
9477:
9478: =cut
9479:
1.25 albertel 9480: sub add_to_env {
9481: my ($name,$value)=@_;
1.258 albertel 9482: if (defined($env{$name})) {
9483: if (ref($env{$name})) {
1.25 albertel 9484: #already have multiple values
1.258 albertel 9485: push(@{ $env{$name} },$value);
1.25 albertel 9486: } else {
9487: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9488: my $first=$env{$name};
9489: undef($env{$name});
9490: push(@{ $env{$name} },$first,$value);
1.25 albertel 9491: }
9492: } else {
1.258 albertel 9493: $env{$name}=$value;
1.25 albertel 9494: }
1.31 albertel 9495: }
1.149 albertel 9496:
9497: =pod
9498:
1.648 raeburn 9499: =item * &get_env_multiple($name)
1.149 albertel 9500:
1.258 albertel 9501: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9502: values may be defined and end up as an array ref.
9503:
9504: returns an array of values
9505:
9506: =cut
9507:
9508: sub get_env_multiple {
9509: my ($name) = @_;
9510: my @values;
1.258 albertel 9511: if (defined($env{$name})) {
1.149 albertel 9512: # exists is it an array
1.258 albertel 9513: if (ref($env{$name})) {
9514: @values=@{ $env{$name} };
1.149 albertel 9515: } else {
1.258 albertel 9516: $values[0]=$env{$name};
1.149 albertel 9517: }
9518: }
9519: return(@values);
9520: }
9521:
1.660 raeburn 9522: sub ask_for_embedded_content {
9523: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9524: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9525: %currsubfile,%unused,$rem);
1.1071 raeburn 9526: my $counter = 0;
9527: my $numnew = 0;
1.987 raeburn 9528: my $numremref = 0;
9529: my $numinvalid = 0;
9530: my $numpathchg = 0;
9531: my $numexisting = 0;
1.1071 raeburn 9532: my $numunused = 0;
9533: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
9534: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
9535: my $heading = &mt('Upload embedded files');
9536: my $buttontext = &mt('Upload');
9537:
1.1085 raeburn 9538: my $navmap;
9539: if ($env{'request.course.id'}) {
9540: $navmap = Apache::lonnavmaps::navmap->new();
9541: }
1.984 raeburn 9542: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9543: my $current_path='/';
9544: if ($env{'form.currentpath'}) {
9545: $current_path = $env{'form.currentpath'};
9546: }
9547: if ($actionurl eq '/adm/coursegrp_portfolio') {
9548: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9549: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
9550: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9551: } else {
9552: $udom = $env{'user.domain'};
9553: $uname = $env{'user.name'};
9554: $url = '/userfiles/portfolio';
9555: }
1.987 raeburn 9556: $toplevel = $url.'/';
1.984 raeburn 9557: $url .= $current_path;
9558: $getpropath = 1;
1.987 raeburn 9559: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9560: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9561: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9562: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9563: $toplevel = $url;
1.984 raeburn 9564: if ($rest ne '') {
1.987 raeburn 9565: $url .= $rest;
9566: }
9567: } elsif ($actionurl eq '/adm/coursedocs') {
9568: if (ref($args) eq 'HASH') {
1.1071 raeburn 9569: $url = $args->{'docs_url'};
9570: $toplevel = $url;
1.1084 raeburn 9571: if ($args->{'context'} eq 'paste') {
9572: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9573: ($path) =
9574: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9575: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9576: $fileloc =~ s{^/}{};
9577: }
1.1071 raeburn 9578: }
1.1084 raeburn 9579: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9580: if ($env{'request.course.id'} ne '') {
9581: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9582: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9583: if (ref($args) eq 'HASH') {
9584: $url = $args->{'docs_url'};
9585: $title = $args->{'docs_title'};
9586: $toplevel = "/$url";
1.1085 raeburn 9587: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1071 raeburn 9588: ($path) =
9589: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9590: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9591: $fileloc =~ s{^/}{};
9592: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9593: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9594: }
1.987 raeburn 9595: }
9596: }
9597: my $now = time();
9598: foreach my $embed_file (keys(%{$allfiles})) {
9599: my $absolutepath;
9600: if ($embed_file =~ m{^\w+://}) {
9601: $newfiles{$embed_file} = 1;
9602: $mapping{$embed_file} = $embed_file;
9603: } else {
9604: if ($embed_file =~ m{^/}) {
9605: $absolutepath = $embed_file;
9606: $embed_file =~ s{^(/+)}{};
9607: }
9608: if ($embed_file =~ m{/}) {
9609: my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
9610: $path = &check_for_traversal($path,$url,$toplevel);
9611: my $item = $fname;
9612: if ($path ne '') {
9613: $item = $path.'/'.$fname;
9614: $subdependencies{$path}{$fname} = 1;
9615: } else {
9616: $dependencies{$item} = 1;
9617: }
9618: if ($absolutepath) {
9619: $mapping{$item} = $absolutepath;
9620: } else {
9621: $mapping{$item} = $embed_file;
9622: }
9623: } else {
9624: $dependencies{$embed_file} = 1;
9625: if ($absolutepath) {
9626: $mapping{$embed_file} = $absolutepath;
9627: } else {
9628: $mapping{$embed_file} = $embed_file;
9629: }
9630: }
1.984 raeburn 9631: }
9632: }
1.1071 raeburn 9633: my $dirptr = 16384;
1.984 raeburn 9634: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9635: $currsubfile{$path} = {};
1.984 raeburn 9636: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9637: my ($sublistref,$listerror) =
9638: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9639: if (ref($sublistref) eq 'ARRAY') {
9640: foreach my $line (@{$sublistref}) {
9641: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9642: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9643: }
1.984 raeburn 9644: }
1.987 raeburn 9645: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9646: if (opendir(my $dir,$url.'/'.$path)) {
9647: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9648: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9649: }
1.1084 raeburn 9650: } elsif (($actionurl eq '/adm/dependencies') ||
9651: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9652: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9653: if ($env{'request.course.id'} ne '') {
9654: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9655: if ($dir ne '') {
9656: my ($sublistref,$listerror) =
9657: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
9658: if (ref($sublistref) eq 'ARRAY') {
9659: foreach my $line (@{$sublistref}) {
9660: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
9661: undef,$mtime)=split(/\&/,$line,12);
9662: unless (($testdir&$dirptr) ||
9663: ($file_name =~ /^\.\.?$/)) {
9664: $currsubfile{$path}{$file_name} = [$size,$mtime];
9665: }
9666: }
9667: }
9668: }
1.984 raeburn 9669: }
9670: }
9671: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 9672: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 9673: my $item = $path.'/'.$file;
9674: unless ($mapping{$item} eq $item) {
9675: $pathchanges{$item} = 1;
9676: }
9677: $existing{$item} = 1;
9678: $numexisting ++;
9679: } else {
9680: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 9681: }
9682: }
1.1071 raeburn 9683: if ($actionurl eq '/adm/dependencies') {
9684: foreach my $path (keys(%currsubfile)) {
9685: if (ref($currsubfile{$path}) eq 'HASH') {
9686: foreach my $file (keys(%{$currsubfile{$path}})) {
9687: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 9688: next if (($rem ne '') &&
9689: (($env{"httpref.$rem"."$path/$file"} ne '') ||
9690: (ref($navmap) &&
9691: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
9692: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9693: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 9694: $unused{$path.'/'.$file} = 1;
9695: }
9696: }
9697: }
9698: }
9699: }
1.984 raeburn 9700: }
1.987 raeburn 9701: my %currfile;
1.984 raeburn 9702: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9703: my ($dirlistref,$listerror) =
9704: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
9705: if (ref($dirlistref) eq 'ARRAY') {
9706: foreach my $line (@{$dirlistref}) {
9707: my ($file_name,$rest) = split(/\&/,$line,2);
9708: $currfile{$file_name} = 1;
9709: }
1.984 raeburn 9710: }
1.987 raeburn 9711: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9712: if (opendir(my $dir,$url)) {
1.987 raeburn 9713: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 9714: map {$currfile{$_} = 1;} @dir_list;
9715: }
1.1084 raeburn 9716: } elsif (($actionurl eq '/adm/dependencies') ||
9717: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9718: ($args->{'context'} eq 'paste'))) {
1.1071 raeburn 9719: if ($env{'request.course.id'} ne '') {
9720: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
9721: if ($dir ne '') {
9722: my ($dirlistref,$listerror) =
9723: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
9724: if (ref($dirlistref) eq 'ARRAY') {
9725: foreach my $line (@{$dirlistref}) {
9726: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
9727: $size,undef,$mtime)=split(/\&/,$line,12);
9728: unless (($testdir&$dirptr) ||
9729: ($file_name =~ /^\.\.?$/)) {
9730: $currfile{$file_name} = [$size,$mtime];
9731: }
9732: }
9733: }
9734: }
9735: }
1.984 raeburn 9736: }
9737: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 9738: if (exists($currfile{$file})) {
1.987 raeburn 9739: unless ($mapping{$file} eq $file) {
9740: $pathchanges{$file} = 1;
9741: }
9742: $existing{$file} = 1;
9743: $numexisting ++;
9744: } else {
1.984 raeburn 9745: $newfiles{$file} = 1;
9746: }
9747: }
1.1071 raeburn 9748: foreach my $file (keys(%currfile)) {
9749: unless (($file eq $filename) ||
9750: ($file eq $filename.'.bak') ||
9751: ($dependencies{$file})) {
1.1085 raeburn 9752: if ($actionurl eq '/adm/dependencies') {
9753: next if (($rem ne '') &&
9754: (($env{"httpref.$rem".$file} ne '') ||
9755: (ref($navmap) &&
9756: (($navmap->getResourceByUrl($rem.$file) ne '') ||
9757: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
9758: ($navmap->getResourceByUrl($rem.$1)))))));
9759: }
1.1071 raeburn 9760: $unused{$file} = 1;
9761: }
9762: }
1.1084 raeburn 9763: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
9764: ($args->{'context'} eq 'paste')) {
9765: $counter = scalar(keys(%existing));
9766: $numpathchg = scalar(keys(%pathchanges));
9767: return ($output,$counter,$numpathchg,\%existing);
9768: }
1.984 raeburn 9769: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 9770: if ($actionurl eq '/adm/dependencies') {
9771: next if ($embed_file =~ m{^\w+://});
9772: }
1.660 raeburn 9773: $upload_output .= &start_data_table_row().
1.1071 raeburn 9774: '<td><img src="'.&icon($embed_file).'" /> '.
9775: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 9776: unless ($mapping{$embed_file} eq $embed_file) {
9777: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
9778: }
9779: $upload_output .= '</td><td>';
1.1071 raeburn 9780: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.660 raeburn 9781: $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987 raeburn 9782: $numremref++;
1.660 raeburn 9783: } elsif ($args->{'error_on_invalid_names'}
9784: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.987 raeburn 9785: $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
9786: $numinvalid++;
1.660 raeburn 9787: } else {
1.1071 raeburn 9788: $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 9789: $embed_file,\%mapping,
1.1071 raeburn 9790: $allfiles,$codebase,'upload');
9791: $counter ++;
9792: $numnew ++;
1.987 raeburn 9793: }
9794: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
9795: }
9796: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 9797: if ($actionurl eq '/adm/dependencies') {
9798: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
9799: $modify_output .= &start_data_table_row().
9800: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
9801: '<img src="'.&icon($embed_file).'" border="0" />'.
9802: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
9803: '<td>'.$size.'</td>'.
9804: '<td>'.$mtime.'</td>'.
9805: '<td><label><input type="checkbox" name="mod_upload_dep" '.
9806: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
9807: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
9808: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
9809: &embedded_file_element('upload_embedded',$counter,
9810: $embed_file,\%mapping,
9811: $allfiles,$codebase,'modify').
9812: '</div></td>'.
9813: &end_data_table_row()."\n";
9814: $counter ++;
9815: } else {
9816: $upload_output .= &start_data_table_row().
9817: '<td><span class="LC_filename">'.$embed_file.'</span></td>';
9818: '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
9819: &Apache::loncommon::end_data_table_row()."\n";
9820: }
9821: }
9822: my $delidx = $counter;
9823: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
9824: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
9825: $delete_output .= &start_data_table_row().
9826: '<td><img src="'.&icon($oldfile).'" />'.
9827: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
9828: '<td>'.$size.'</td>'.
9829: '<td>'.$mtime.'</td>'.
9830: '<td><label><input type="checkbox" name="del_upload_dep" '.
9831: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
9832: &embedded_file_element('upload_embedded',$delidx,
9833: $oldfile,\%mapping,$allfiles,
9834: $codebase,'delete').'</td>'.
9835: &end_data_table_row()."\n";
9836: $numunused ++;
9837: $delidx ++;
1.987 raeburn 9838: }
9839: if ($upload_output) {
9840: $upload_output = &start_data_table().
9841: $upload_output.
9842: &end_data_table()."\n";
9843: }
1.1071 raeburn 9844: if ($modify_output) {
9845: $modify_output = &start_data_table().
9846: &start_data_table_header_row().
9847: '<th>'.&mt('File').'</th>'.
9848: '<th>'.&mt('Size (KB)').'</th>'.
9849: '<th>'.&mt('Modified').'</th>'.
9850: '<th>'.&mt('Upload replacement?').'</th>'.
9851: &end_data_table_header_row().
9852: $modify_output.
9853: &end_data_table()."\n";
9854: }
9855: if ($delete_output) {
9856: $delete_output = &start_data_table().
9857: &start_data_table_header_row().
9858: '<th>'.&mt('File').'</th>'.
9859: '<th>'.&mt('Size (KB)').'</th>'.
9860: '<th>'.&mt('Modified').'</th>'.
9861: '<th>'.&mt('Delete?').'</th>'.
9862: &end_data_table_header_row().
9863: $delete_output.
9864: &end_data_table()."\n";
9865: }
1.987 raeburn 9866: my $applies = 0;
9867: if ($numremref) {
9868: $applies ++;
9869: }
9870: if ($numinvalid) {
9871: $applies ++;
9872: }
9873: if ($numexisting) {
9874: $applies ++;
9875: }
1.1071 raeburn 9876: if ($counter || $numunused) {
1.987 raeburn 9877: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
9878: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 9879: $state.'<h3>'.$heading.'</h3>';
9880: if ($actionurl eq '/adm/dependencies') {
9881: if ($numnew) {
9882: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
9883: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
9884: $upload_output.'<br />'."\n";
9885: }
9886: if ($numexisting) {
9887: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
9888: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
9889: $modify_output.'<br />'."\n";
9890: $buttontext = &mt('Save changes');
9891: }
9892: if ($numunused) {
9893: $output .= '<h4>'.&mt('Unused files').'</h4>'.
9894: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
9895: $delete_output.'<br />'."\n";
9896: $buttontext = &mt('Save changes');
9897: }
9898: } else {
9899: $output .= $upload_output.'<br />'."\n";
9900: }
9901: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
9902: $counter.'" />'."\n";
9903: if ($actionurl eq '/adm/dependencies') {
9904: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
9905: $numnew.'" />'."\n";
9906: } elsif ($actionurl eq '') {
1.987 raeburn 9907: $output .= '<input type="hidden" name="phase" value="three" />';
9908: }
9909: } elsif ($applies) {
9910: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
9911: if ($applies > 1) {
9912: $output .=
9913: &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
9914: if ($numremref) {
9915: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
9916: }
9917: if ($numinvalid) {
9918: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
9919: }
9920: if ($numexisting) {
9921: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
9922: }
9923: $output .= '</ul><br />';
9924: } elsif ($numremref) {
9925: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
9926: } elsif ($numinvalid) {
9927: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
9928: } elsif ($numexisting) {
9929: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
9930: }
9931: $output .= $upload_output.'<br />';
9932: }
9933: my ($pathchange_output,$chgcount);
1.1071 raeburn 9934: $chgcount = $counter;
1.987 raeburn 9935: if (keys(%pathchanges) > 0) {
9936: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 9937: if ($counter) {
1.987 raeburn 9938: $output .= &embedded_file_element('pathchange',$chgcount,
9939: $embed_file,\%mapping,
1.1071 raeburn 9940: $allfiles,$codebase,'change');
1.987 raeburn 9941: } else {
9942: $pathchange_output .=
9943: &start_data_table_row().
9944: '<td><input type ="checkbox" name="namechange" value="'.
9945: $chgcount.'" checked="checked" /></td>'.
9946: '<td>'.$mapping{$embed_file}.'</td>'.
9947: '<td>'.$embed_file.
9948: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 9949: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 9950: '</td>'.&end_data_table_row();
1.660 raeburn 9951: }
1.987 raeburn 9952: $numpathchg ++;
9953: $chgcount ++;
1.660 raeburn 9954: }
9955: }
1.1071 raeburn 9956: if ($counter) {
1.987 raeburn 9957: if ($numpathchg) {
9958: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
9959: $numpathchg.'" />'."\n";
9960: }
9961: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9962: ($actionurl eq '/adm/imsimport')) {
9963: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
9964: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
9965: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 9966: } elsif ($actionurl eq '/adm/dependencies') {
9967: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 9968: }
1.1071 raeburn 9969: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 9970: } elsif ($numpathchg) {
9971: my %pathchange = ();
9972: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
9973: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
9974: $output .= '<p>'.&mt('or').'</p>';
9975: }
9976: }
1.1071 raeburn 9977: return ($output,$counter,$numpathchg);
1.987 raeburn 9978: }
9979:
9980: sub embedded_file_element {
1.1071 raeburn 9981: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 9982: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
9983: (ref($codebase) eq 'HASH'));
9984: my $output;
1.1071 raeburn 9985: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 9986: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
9987: }
9988: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
9989: &escape($embed_file).'" />';
9990: unless (($context eq 'upload_embedded') &&
9991: ($mapping->{$embed_file} eq $embed_file)) {
9992: $output .='
9993: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
9994: }
9995: my $attrib;
9996: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
9997: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
9998: }
9999: $output .=
10000: "\n\t\t".
10001: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10002: $attrib.'" />';
10003: if (exists($codebase->{$mapping->{$embed_file}})) {
10004: $output .=
10005: "\n\t\t".
10006: '<input name="codebase_'.$num.'" type="hidden" value="'.
10007: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10008: }
1.987 raeburn 10009: return $output;
1.660 raeburn 10010: }
10011:
1.1071 raeburn 10012: sub get_dependency_details {
10013: my ($currfile,$currsubfile,$embed_file) = @_;
10014: my ($size,$mtime,$showsize,$showmtime);
10015: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10016: if ($embed_file =~ m{/}) {
10017: my ($path,$fname) = split(/\//,$embed_file);
10018: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10019: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10020: }
10021: } else {
10022: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10023: ($size,$mtime) = @{$currfile->{$embed_file}};
10024: }
10025: }
10026: $showsize = $size/1024.0;
10027: $showsize = sprintf("%.1f",$showsize);
10028: if ($mtime > 0) {
10029: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10030: }
10031: }
10032: return ($showsize,$showmtime);
10033: }
10034:
10035: sub ask_embedded_js {
10036: return <<"END";
10037: <script type="text/javascript"">
10038: // <![CDATA[
10039: function toggleBrowse(counter) {
10040: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10041: var fileid = document.getElementById('embedded_item_'+counter);
10042: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10043: if (chkboxid.checked == true) {
10044: uploaddivid.style.display='block';
10045: } else {
10046: uploaddivid.style.display='none';
10047: fileid.value = '';
10048: }
10049: }
10050: // ]]>
10051: </script>
10052:
10053: END
10054: }
10055:
1.661 raeburn 10056: sub upload_embedded {
10057: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10058: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10059: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10060: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10061: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10062: my $orig_uploaded_filename =
10063: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10064: foreach my $type ('orig','ref','attrib','codebase') {
10065: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10066: $env{'form.embedded_'.$type.'_'.$i} =
10067: &unescape($env{'form.embedded_'.$type.'_'.$i});
10068: }
10069: }
1.661 raeburn 10070: my ($path,$fname) =
10071: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10072: # no path, whole string is fname
10073: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10074: $fname = &Apache::lonnet::clean_filename($fname);
10075: # See if there is anything left
10076: next if ($fname eq '');
10077:
10078: # Check if file already exists as a file or directory.
10079: my ($state,$msg);
10080: if ($context eq 'portfolio') {
10081: my $port_path = $dirpath;
10082: if ($group ne '') {
10083: $port_path = "groups/$group/$port_path";
10084: }
1.987 raeburn 10085: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10086: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10087: $dir_root,$port_path,$disk_quota,
10088: $current_disk_usage,$uname,$udom);
10089: if ($state eq 'will_exceed_quota'
1.984 raeburn 10090: || $state eq 'file_locked') {
1.661 raeburn 10091: $output .= $msg;
10092: next;
10093: }
10094: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10095: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10096: if ($state eq 'exists') {
10097: $output .= $msg;
10098: next;
10099: }
10100: }
10101: # Check if extension is valid
10102: if (($fname =~ /\.(\w+)$/) &&
10103: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987 raeburn 10104: $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661 raeburn 10105: next;
10106: } elsif (($fname =~ /\.(\w+)$/) &&
10107: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10108: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10109: next;
10110: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987 raeburn 10111: $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661 raeburn 10112: next;
10113: }
10114: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
10115: if ($context eq 'portfolio') {
1.984 raeburn 10116: my $result;
10117: if ($state eq 'existingfile') {
10118: $result=
10119: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987 raeburn 10120: $dirpath.$env{'form.currentpath'}.$path);
1.661 raeburn 10121: } else {
1.984 raeburn 10122: $result=
10123: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10124: $dirpath.
10125: $env{'form.currentpath'}.$path);
1.984 raeburn 10126: if ($result !~ m|^/uploaded/|) {
10127: $output .= '<span class="LC_error">'
10128: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10129: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10130: .'</span><br />';
10131: next;
10132: } else {
1.987 raeburn 10133: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10134: $path.$fname.'</span>').'<br />';
1.984 raeburn 10135: }
1.661 raeburn 10136: }
1.987 raeburn 10137: } elsif ($context eq 'coursedoc') {
10138: my $result =
10139: &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
10140: $dirpath.'/'.$path);
10141: if ($result !~ m|^/uploaded/|) {
10142: $output .= '<span class="LC_error">'
10143: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10144: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10145: .'</span><br />';
10146: next;
10147: } else {
10148: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10149: $path.$fname.'</span>').'<br />';
10150: }
1.661 raeburn 10151: } else {
10152: # Save the file
10153: my $target = $env{'form.embedded_item_'.$i};
10154: my $fullpath = $dir_root.$dirpath.'/'.$path;
10155: my $dest = $fullpath.$fname;
10156: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10157: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10158: my $count;
10159: my $filepath = $dir_root;
1.1027 raeburn 10160: foreach my $subdir (@parts) {
10161: $filepath .= "/$subdir";
10162: if (!-e $filepath) {
1.661 raeburn 10163: mkdir($filepath,0770);
10164: }
10165: }
10166: my $fh;
10167: if (!open($fh,'>'.$dest)) {
10168: &Apache::lonnet::logthis('Failed to create '.$dest);
10169: $output .= '<span class="LC_error">'.
1.1071 raeburn 10170: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10171: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10172: '</span><br />';
10173: } else {
10174: if (!print $fh $env{'form.embedded_item_'.$i}) {
10175: &Apache::lonnet::logthis('Failed to write to '.$dest);
10176: $output .= '<span class="LC_error">'.
1.1071 raeburn 10177: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10178: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10179: '</span><br />';
10180: } else {
1.987 raeburn 10181: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10182: $url.'</span>').'<br />';
10183: unless ($context eq 'testbank') {
10184: $footer .= &mt('View embedded file: [_1]',
10185: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10186: }
10187: }
10188: close($fh);
10189: }
10190: }
10191: if ($env{'form.embedded_ref_'.$i}) {
10192: $pathchange{$i} = 1;
10193: }
10194: }
10195: if ($output) {
10196: $output = '<p>'.$output.'</p>';
10197: }
10198: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10199: $returnflag = 'ok';
1.1071 raeburn 10200: my $numpathchgs = scalar(keys(%pathchange));
10201: if ($numpathchgs > 0) {
1.987 raeburn 10202: if ($context eq 'portfolio') {
10203: $output .= '<p>'.&mt('or').'</p>';
10204: } elsif ($context eq 'testbank') {
1.1071 raeburn 10205: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10206: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10207: $returnflag = 'modify_orightml';
10208: }
10209: }
1.1071 raeburn 10210: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10211: }
10212:
10213: sub modify_html_form {
10214: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10215: my $end = 0;
10216: my $modifyform;
10217: if ($context eq 'upload_embedded') {
10218: return unless (ref($pathchange) eq 'HASH');
10219: if ($env{'form.number_embedded_items'}) {
10220: $end += $env{'form.number_embedded_items'};
10221: }
10222: if ($env{'form.number_pathchange_items'}) {
10223: $end += $env{'form.number_pathchange_items'};
10224: }
10225: if ($end) {
10226: for (my $i=0; $i<$end; $i++) {
10227: if ($i < $env{'form.number_embedded_items'}) {
10228: next unless($pathchange->{$i});
10229: }
10230: $modifyform .=
10231: &start_data_table_row().
10232: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10233: 'checked="checked" /></td>'.
10234: '<td>'.$env{'form.embedded_ref_'.$i}.
10235: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10236: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10237: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10238: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10239: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10240: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10241: '<td>'.$env{'form.embedded_orig_'.$i}.
10242: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10243: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10244: &end_data_table_row();
1.1071 raeburn 10245: }
1.987 raeburn 10246: }
10247: } else {
10248: $modifyform = $pathchgtable;
10249: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10250: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10251: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10252: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10253: }
10254: }
10255: if ($modifyform) {
1.1071 raeburn 10256: if ($actionurl eq '/adm/dependencies') {
10257: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10258: }
1.987 raeburn 10259: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10260: '<p>'.&mt('Changes need to be made to the reference(s) used for one or more of the dependencies, if your HTML file is to work correctly:').'<ol>'."\n".
10261: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10262: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10263: '</ol></p>'."\n".'<p>'.
10264: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10265: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10266: &start_data_table()."\n".
10267: &start_data_table_header_row().
10268: '<th>'.&mt('Change?').'</th>'.
10269: '<th>'.&mt('Current reference').'</th>'.
10270: '<th>'.&mt('Required reference').'</th>'.
10271: &end_data_table_header_row()."\n".
10272: $modifyform.
10273: &end_data_table().'<br />'."\n".$hiddenstate.
10274: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10275: '</form>'."\n";
10276: }
10277: return;
10278: }
10279:
10280: sub modify_html_refs {
10281: my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
10282: my $container;
10283: if ($context eq 'portfolio') {
10284: $container = $env{'form.container'};
10285: } elsif ($context eq 'coursedoc') {
10286: $container = $env{'form.primaryurl'};
1.1071 raeburn 10287: } elsif ($context eq 'manage_dependencies') {
10288: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10289: $container = "/$container";
1.987 raeburn 10290: } else {
1.1027 raeburn 10291: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10292: }
10293: my (%allfiles,%codebase,$output,$content);
10294: my @changes = &get_env_multiple('form.namechange');
1.1071 raeburn 10295: unless (@changes > 0) {
10296: if (wantarray) {
10297: return ('',0,0);
10298: } else {
10299: return;
10300: }
10301: }
10302: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10303: ($context eq 'manage_dependencies')) {
10304: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10305: if (wantarray) {
10306: return ('',0,0);
10307: } else {
10308: return;
10309: }
10310: }
1.987 raeburn 10311: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10312: if ($content eq '-1') {
10313: if (wantarray) {
10314: return ('',0,0);
10315: } else {
10316: return;
10317: }
10318: }
1.987 raeburn 10319: } else {
1.1071 raeburn 10320: unless ($container =~ /^\Q$dir_root\E/) {
10321: if (wantarray) {
10322: return ('',0,0);
10323: } else {
10324: return;
10325: }
10326: }
1.987 raeburn 10327: if (open(my $fh,"<$container")) {
10328: $content = join('', <$fh>);
10329: close($fh);
10330: } else {
1.1071 raeburn 10331: if (wantarray) {
10332: return ('',0,0);
10333: } else {
10334: return;
10335: }
1.987 raeburn 10336: }
10337: }
10338: my ($count,$codebasecount) = (0,0);
10339: my $mm = new File::MMagic;
10340: my $mime_type = $mm->checktype_contents($content);
10341: if ($mime_type eq 'text/html') {
10342: my $parse_result =
10343: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10344: \%codebase,\$content);
10345: if ($parse_result eq 'ok') {
10346: foreach my $i (@changes) {
10347: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10348: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10349: if ($allfiles{$ref}) {
10350: my $newname = $orig;
10351: my ($attrib_regexp,$codebase);
1.1006 raeburn 10352: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10353: if ($attrib_regexp =~ /:/) {
10354: $attrib_regexp =~ s/\:/|/g;
10355: }
10356: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10357: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10358: $count += $numchg;
10359: }
10360: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10361: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10362: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10363: $codebasecount ++;
10364: }
10365: }
10366: }
10367: if ($count || $codebasecount) {
10368: my $saveresult;
1.1071 raeburn 10369: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
10370: ($context eq 'manage_dependencies')) {
1.987 raeburn 10371: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10372: if ($url eq $container) {
10373: my ($fname) = ($container =~ m{/([^/]+)$});
10374: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10375: $count,'<span class="LC_filename">'.
1.1071 raeburn 10376: $fname.'</span>').'</p>';
1.987 raeburn 10377: } else {
10378: $output = '<p class="LC_error">'.
10379: &mt('Error: update failed for: [_1].',
10380: '<span class="LC_filename">'.
10381: $container.'</span>').'</p>';
10382: }
10383: } else {
10384: if (open(my $fh,">$container")) {
10385: print $fh $content;
10386: close($fh);
10387: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10388: $count,'<span class="LC_filename">'.
10389: $container.'</span>').'</p>';
1.661 raeburn 10390: } else {
1.987 raeburn 10391: $output = '<p class="LC_error">'.
10392: &mt('Error: could not update [_1].',
10393: '<span class="LC_filename">'.
10394: $container.'</span>').'</p>';
1.661 raeburn 10395: }
10396: }
10397: }
1.987 raeburn 10398: } else {
10399: &logthis('Failed to parse '.$container.
10400: ' to modify references: '.$parse_result);
1.661 raeburn 10401: }
10402: }
1.1071 raeburn 10403: if (wantarray) {
10404: return ($output,$count,$codebasecount);
10405: } else {
10406: return $output;
10407: }
1.661 raeburn 10408: }
10409:
10410: sub check_for_existing {
10411: my ($path,$fname,$element) = @_;
10412: my ($state,$msg);
10413: if (-d $path.'/'.$fname) {
10414: $state = 'exists';
10415: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10416: } elsif (-e $path.'/'.$fname) {
10417: $state = 'exists';
10418: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10419: }
10420: if ($state eq 'exists') {
10421: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10422: }
10423: return ($state,$msg);
10424: }
10425:
10426: sub check_for_upload {
10427: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10428: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10429: my $filesize = length($env{'form.'.$element});
10430: if (!$filesize) {
10431: my $msg = '<span class="LC_error">'.
10432: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10433: '<span class="LC_filename">'.$fname.'</span>',
10434: $filesize).'<br />'.
1.1007 raeburn 10435: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10436: '</span>';
10437: return ('zero_bytes',$msg);
10438: }
10439: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10440: my $getpropath = 1;
1.1021 raeburn 10441: my ($dirlistref,$listerror) =
10442: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10443: my $found_file = 0;
10444: my $locked_file = 0;
1.991 raeburn 10445: my @lockers;
10446: my $navmap;
10447: if ($env{'request.course.id'}) {
10448: $navmap = Apache::lonnavmaps::navmap->new();
10449: }
1.1021 raeburn 10450: if (ref($dirlistref) eq 'ARRAY') {
10451: foreach my $line (@{$dirlistref}) {
10452: my ($file_name,$rest)=split(/\&/,$line,2);
10453: if ($file_name eq $fname){
10454: $file_name = $path.$file_name;
10455: if ($group ne '') {
10456: $file_name = $group.$file_name;
10457: }
10458: $found_file = 1;
10459: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10460: foreach my $lock (@lockers) {
10461: if (ref($lock) eq 'ARRAY') {
10462: my ($symb,$crsid) = @{$lock};
10463: if ($crsid eq $env{'request.course.id'}) {
10464: if (ref($navmap)) {
10465: my $res = $navmap->getBySymb($symb);
10466: foreach my $part (@{$res->parts()}) {
10467: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10468: unless (($slot_status == $res->RESERVED) ||
10469: ($slot_status == $res->RESERVED_LOCATION)) {
10470: $locked_file = 1;
10471: }
1.991 raeburn 10472: }
1.1021 raeburn 10473: } else {
10474: $locked_file = 1;
1.991 raeburn 10475: }
10476: } else {
10477: $locked_file = 1;
10478: }
10479: }
1.1021 raeburn 10480: }
10481: } else {
10482: my @info = split(/\&/,$rest);
10483: my $currsize = $info[6]/1000;
10484: if ($currsize < $filesize) {
10485: my $extra = $filesize - $currsize;
10486: if (($current_disk_usage + $extra) > $disk_quota) {
10487: my $msg = '<span class="LC_error">'.
10488: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
10489: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
10490: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10491: $disk_quota,$current_disk_usage);
10492: return ('will_exceed_quota',$msg);
10493: }
1.984 raeburn 10494: }
10495: }
1.661 raeburn 10496: }
10497: }
10498: }
10499: if (($current_disk_usage + $filesize) > $disk_quota){
10500: my $msg = '<span class="LC_error">'.
10501: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
10502: '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
10503: return ('will_exceed_quota',$msg);
10504: } elsif ($found_file) {
10505: if ($locked_file) {
10506: my $msg = '<span class="LC_error">';
10507: $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>');
10508: $msg .= '</span><br />';
10509: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10510: return ('file_locked',$msg);
10511: } else {
10512: my $msg = '<span class="LC_error">';
1.984 raeburn 10513: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661 raeburn 10514: $msg .= '</span>';
1.984 raeburn 10515: return ('existingfile',$msg);
1.661 raeburn 10516: }
10517: }
10518: }
10519:
1.987 raeburn 10520: sub check_for_traversal {
10521: my ($path,$url,$toplevel) = @_;
10522: my @parts=split(/\//,$path);
10523: my $cleanpath;
10524: my $fullpath = $url;
10525: for (my $i=0;$i<@parts;$i++) {
10526: next if ($parts[$i] eq '.');
10527: if ($parts[$i] eq '..') {
10528: $fullpath =~ s{([^/]+/)$}{};
10529: } else {
10530: $fullpath .= $parts[$i].'/';
10531: }
10532: }
10533: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10534: $cleanpath = $1;
10535: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
10536: my $curr_toprel = $1;
10537: my @parts = split(/\//,$curr_toprel);
10538: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
10539: my @urlparts = split(/\//,$url_toprel);
10540: my $doubledots;
10541: my $startdiff = -1;
10542: for (my $i=0; $i<@urlparts; $i++) {
10543: if ($startdiff == -1) {
10544: unless ($urlparts[$i] eq $parts[$i]) {
10545: $startdiff = $i;
10546: $doubledots .= '../';
10547: }
10548: } else {
10549: $doubledots .= '../';
10550: }
10551: }
10552: if ($startdiff > -1) {
10553: $cleanpath = $doubledots;
10554: for (my $i=$startdiff; $i<@parts; $i++) {
10555: $cleanpath .= $parts[$i].'/';
10556: }
10557: }
10558: }
10559: $cleanpath =~ s{(/)$}{};
10560: return $cleanpath;
10561: }
1.31 albertel 10562:
1.1053 raeburn 10563: sub is_archive_file {
10564: my ($mimetype) = @_;
10565: if (($mimetype eq 'application/octet-stream') ||
10566: ($mimetype eq 'application/x-stuffit') ||
10567: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
10568: return 1;
10569: }
10570: return;
10571: }
10572:
10573: sub decompress_form {
1.1065 raeburn 10574: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 10575: my %lt = &Apache::lonlocal::texthash (
10576: this => 'This file is an archive file.',
1.1067 raeburn 10577: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 10578: itsc => 'Its contents are as follows:',
1.1053 raeburn 10579: youm => 'You may wish to extract its contents.',
10580: extr => 'Extract contents',
1.1067 raeburn 10581: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
10582: proa => 'Process automatically?',
1.1053 raeburn 10583: yes => 'Yes',
10584: no => 'No',
1.1067 raeburn 10585: fold => 'Title for folder containing movie',
10586: movi => 'Title for page containing embedded movie',
1.1053 raeburn 10587: );
1.1065 raeburn 10588: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 10589: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 10590: my $info = &list_archive_contents($fileloc,\@paths);
10591: if (@paths) {
10592: foreach my $path (@paths) {
10593: $path =~ s{^/}{};
1.1067 raeburn 10594: if ($path =~ m{^([^/]+)/$}) {
10595: $topdir = $1;
10596: }
1.1065 raeburn 10597: if ($path =~ m{^([^/]+)/}) {
10598: $toplevel{$1} = $path;
10599: } else {
10600: $toplevel{$path} = $path;
10601: }
10602: }
10603: }
1.1067 raeburn 10604: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
10605: my @camtasia = ("$topdir/","$topdir/index.html",
10606: "$topdir/media/",
10607: "$topdir/media/$topdir.mp4",
10608: "$topdir/media/FirstFrame.png",
10609: "$topdir/media/player.swf",
10610: "$topdir/media/swfobject.js",
10611: "$topdir/media/expressInstall.swf");
10612: my @diffs = &compare_arrays(\@paths,\@camtasia);
10613: if (@diffs == 0) {
10614: $is_camtasia = 1;
10615: }
10616: }
10617: my $output;
10618: if ($is_camtasia) {
10619: $output = <<"ENDCAM";
10620: <script type="text/javascript" language="Javascript">
10621: // <![CDATA[
10622:
10623: function camtasiaToggle() {
10624: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
10625: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
10626: if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
10627:
10628: document.getElementById('camtasia_titles').style.display='block';
10629: } else {
10630: document.getElementById('camtasia_titles').style.display='none';
10631: }
10632: }
10633: }
10634: return;
10635: }
10636:
10637: // ]]>
10638: </script>
10639: <p>$lt{'camt'}</p>
10640: ENDCAM
1.1065 raeburn 10641: } else {
1.1067 raeburn 10642: $output = '<p>'.$lt{'this'};
10643: if ($info eq '') {
10644: $output .= ' '.$lt{'youm'}.'</p>'."\n";
10645: } else {
10646: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
10647: '<div><pre>'.$info.'</pre></div>';
10648: }
1.1065 raeburn 10649: }
1.1067 raeburn 10650: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 10651: my $duplicates;
10652: my $num = 0;
10653: if (ref($dirlist) eq 'ARRAY') {
10654: foreach my $item (@{$dirlist}) {
10655: if (ref($item) eq 'ARRAY') {
10656: if (exists($toplevel{$item->[0]})) {
10657: $duplicates .=
10658: &start_data_table_row().
10659: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
10660: 'value="0" checked="checked" />'.&mt('No').'</label>'.
10661: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
10662: 'value="1" />'.&mt('Yes').'</label>'.
10663: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
10664: '<td>'.$item->[0].'</td>';
10665: if ($item->[2]) {
10666: $duplicates .= '<td>'.&mt('Directory').'</td>';
10667: } else {
10668: $duplicates .= '<td>'.&mt('File').'</td>';
10669: }
10670: $duplicates .= '<td>'.$item->[3].'</td>'.
10671: '<td>'.
10672: &Apache::lonlocal::locallocaltime($item->[4]).
10673: '</td>'.
10674: &end_data_table_row();
10675: $num ++;
10676: }
10677: }
10678: }
10679: }
10680: my $itemcount;
10681: if (@paths > 0) {
10682: $itemcount = scalar(@paths);
10683: } else {
10684: $itemcount = 1;
10685: }
1.1067 raeburn 10686: if ($is_camtasia) {
10687: $output .= $lt{'auto'}.'<br />'.
10688: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
10689: '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
10690: $lt{'yes'}.'</label> <label>'.
10691: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
10692: $lt{'no'}.'</label></span><br />'.
10693: '<div id="camtasia_titles" style="display:block">'.
10694: &Apache::lonhtmlcommon::start_pick_box().
10695: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
10696: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
10697: &Apache::lonhtmlcommon::row_closure().
10698: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
10699: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
10700: &Apache::lonhtmlcommon::row_closure(1).
10701: &Apache::lonhtmlcommon::end_pick_box().
10702: '</div>';
10703: }
1.1065 raeburn 10704: $output .=
10705: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 10706: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
10707: "\n";
1.1065 raeburn 10708: if ($duplicates ne '') {
10709: $output .= '<p><span class="LC_warning">'.
10710: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
10711: &start_data_table().
10712: &start_data_table_header_row().
10713: '<th>'.&mt('Overwrite?').'</th>'.
10714: '<th>'.&mt('Name').'</th>'.
10715: '<th>'.&mt('Type').'</th>'.
10716: '<th>'.&mt('Size').'</th>'.
10717: '<th>'.&mt('Last modified').'</th>'.
10718: &end_data_table_header_row().
10719: $duplicates.
10720: &end_data_table().
10721: '</p>';
10722: }
1.1067 raeburn 10723: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 10724: if (ref($hiddenelements) eq 'HASH') {
10725: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
10726: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
10727: }
10728: }
10729: $output .= <<"END";
1.1067 raeburn 10730: <br />
1.1053 raeburn 10731: <input type="submit" name="decompress" value="$lt{'extr'}" />
10732: </form>
10733: $noextract
10734: END
10735: return $output;
10736: }
10737:
1.1065 raeburn 10738: sub decompression_utility {
10739: my ($program) = @_;
10740: my @utilities = ('tar','gunzip','bunzip2','unzip');
10741: my $location;
10742: if (grep(/^\Q$program\E$/,@utilities)) {
10743: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
10744: '/usr/sbin/') {
10745: if (-x $dir.$program) {
10746: $location = $dir.$program;
10747: last;
10748: }
10749: }
10750: }
10751: return $location;
10752: }
10753:
10754: sub list_archive_contents {
10755: my ($file,$pathsref) = @_;
10756: my (@cmd,$output);
10757: my $needsregexp;
10758: if ($file =~ /\.zip$/) {
10759: @cmd = (&decompression_utility('unzip'),"-l");
10760: $needsregexp = 1;
10761: } elsif (($file =~ m/\.tar\.gz$/) ||
10762: ($file =~ /\.tgz$/)) {
10763: @cmd = (&decompression_utility('tar'),"-ztf");
10764: } elsif ($file =~ /\.tar\.bz2$/) {
10765: @cmd = (&decompression_utility('tar'),"-jtf");
10766: } elsif ($file =~ m|\.tar$|) {
10767: @cmd = (&decompression_utility('tar'),"-tf");
10768: }
10769: if (@cmd) {
10770: undef($!);
10771: undef($@);
10772: if (open(my $fh,"-|", @cmd, $file)) {
10773: while (my $line = <$fh>) {
10774: $output .= $line;
10775: chomp($line);
10776: my $item;
10777: if ($needsregexp) {
10778: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
10779: } else {
10780: $item = $line;
10781: }
10782: if ($item ne '') {
10783: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
10784: push(@{$pathsref},$item);
10785: }
10786: }
10787: }
10788: close($fh);
10789: }
10790: }
10791: return $output;
10792: }
10793:
1.1053 raeburn 10794: sub decompress_uploaded_file {
10795: my ($file,$dir) = @_;
10796: &Apache::lonnet::appenv({'cgi.file' => $file});
10797: &Apache::lonnet::appenv({'cgi.dir' => $dir});
10798: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
10799: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
10800: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
10801: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
10802: my $decompressed = $env{'cgi.decompressed'};
10803: &Apache::lonnet::delenv('cgi.file');
10804: &Apache::lonnet::delenv('cgi.dir');
10805: &Apache::lonnet::delenv('cgi.decompressed');
10806: return ($decompressed,$result);
10807: }
10808:
1.1055 raeburn 10809: sub process_decompression {
10810: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
10811: my ($dir,$error,$warning,$output);
10812: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
10813: $error = &mt('File name not a supported archive file type.').
10814: '<br />'.&mt('File name should end with one of: [_1].',
10815: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
10816: } else {
10817: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
10818: if ($docuhome eq 'no_host') {
10819: $error = &mt('Could not determine home server for course.');
10820: } else {
10821: my @ids=&Apache::lonnet::current_machine_ids();
10822: my $currdir = "$dir_root/$destination";
10823: if (grep(/^\Q$docuhome\E$/,@ids)) {
10824: $dir = &LONCAPA::propath($docudom,$docuname).
10825: "$dir_root/$destination";
10826: } else {
10827: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
10828: "$dir_root/$docudom/$docuname/$destination";
10829: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
10830: $error = &mt('Archive file not found.');
10831: }
10832: }
1.1065 raeburn 10833: my (@to_overwrite,@to_skip);
10834: if ($env{'form.archive_overwrite_total'} > 0) {
10835: my $total = $env{'form.archive_overwrite_total'};
10836: for (my $i=0; $i<$total; $i++) {
10837: if ($env{'form.archive_overwrite_'.$i} == 1) {
10838: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
10839: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
10840: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
10841: }
10842: }
10843: }
10844: my $numskip = scalar(@to_skip);
10845: if (($numskip > 0) &&
10846: ($numskip == $env{'form.archive_itemcount'})) {
10847: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
10848: } elsif ($dir eq '') {
1.1055 raeburn 10849: $error = &mt('Directory containing archive file unavailable.');
10850: } elsif (!$error) {
1.1065 raeburn 10851: my ($decompressed,$display);
10852: if ($numskip > 0) {
10853: my $tempdir = time.'_'.$$.int(rand(10000));
10854: mkdir("$dir/$tempdir",0755);
10855: system("mv $dir/$file $dir/$tempdir/$file");
10856: ($decompressed,$display) =
10857: &decompress_uploaded_file($file,"$dir/$tempdir");
10858: foreach my $item (@to_skip) {
10859: if (($item ne '') && ($item !~ /\.\./)) {
10860: if (-f "$dir/$tempdir/$item") {
10861: unlink("$dir/$tempdir/$item");
10862: } elsif (-d "$dir/$tempdir/$item") {
10863: system("rm -rf $dir/$tempdir/$item");
10864: }
10865: }
10866: }
10867: system("mv $dir/$tempdir/* $dir");
10868: rmdir("$dir/$tempdir");
10869: } else {
10870: ($decompressed,$display) =
10871: &decompress_uploaded_file($file,$dir);
10872: }
1.1055 raeburn 10873: if ($decompressed eq 'ok') {
1.1065 raeburn 10874: $output = '<p class="LC_info">'.
10875: &mt('Files extracted successfully from archive.').
10876: '</p>'."\n";
1.1055 raeburn 10877: my ($warning,$result,@contents);
10878: my ($newdirlistref,$newlisterror) =
10879: &Apache::lonnet::dirlist($currdir,$docudom,
10880: $docuname,1);
10881: my (%is_dir,%changes,@newitems);
10882: my $dirptr = 16384;
1.1065 raeburn 10883: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 10884: foreach my $dir_line (@{$newdirlistref}) {
10885: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 10886: unless (($item =~ /^\.+$/) || ($item eq $file) ||
10887: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 10888: push(@newitems,$item);
10889: if ($dirptr&$testdir) {
10890: $is_dir{$item} = 1;
10891: }
10892: $changes{$item} = 1;
10893: }
10894: }
10895: }
10896: if (keys(%changes) > 0) {
10897: foreach my $item (sort(@newitems)) {
10898: if ($changes{$item}) {
10899: push(@contents,$item);
10900: }
10901: }
10902: }
10903: if (@contents > 0) {
1.1067 raeburn 10904: my $wantform;
10905: unless ($env{'form.autoextract_camtasia'}) {
10906: $wantform = 1;
10907: }
1.1056 raeburn 10908: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 10909: my ($count,$datatable) = &get_extracted($docudom,$docuname,
10910: $currdir,\%is_dir,
10911: \%children,\%parent,
1.1056 raeburn 10912: \@contents,\%dirorder,
10913: \%titles,$wantform);
1.1055 raeburn 10914: if ($datatable ne '') {
10915: $output .= &archive_options_form('decompressed',$datatable,
10916: $count,$hiddenelem);
1.1065 raeburn 10917: my $startcount = 6;
1.1055 raeburn 10918: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 10919: \%titles,\%children);
1.1055 raeburn 10920: }
1.1067 raeburn 10921: if ($env{'form.autoextract_camtasia'}) {
10922: my %displayed;
10923: my $total = 1;
10924: $env{'form.archive_directory'} = [];
10925: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
10926: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
10927: $path =~ s{/$}{};
10928: my $item;
10929: if ($path ne '') {
10930: $item = "$path/$titles{$i}";
10931: } else {
10932: $item = $titles{$i};
10933: }
10934: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
10935: if ($item eq $contents[0]) {
10936: push(@{$env{'form.archive_directory'}},$i);
10937: $env{'form.archive_'.$i} = 'display';
10938: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
10939: $displayed{'folder'} = $i;
10940: } elsif ($item eq "$contents[0]/index.html") {
10941: $env{'form.archive_'.$i} = 'display';
10942: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
10943: $displayed{'web'} = $i;
10944: } else {
10945: if ($item eq "$contents[0]/media") {
10946: push(@{$env{'form.archive_directory'}},$i);
10947: }
10948: $env{'form.archive_'.$i} = 'dependency';
10949: }
10950: $total ++;
10951: }
10952: for (my $i=1; $i<$total; $i++) {
10953: next if ($i == $displayed{'web'});
10954: next if ($i == $displayed{'folder'});
10955: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
10956: }
10957: $env{'form.phase'} = 'decompress_cleanup';
10958: $env{'form.archivedelete'} = 1;
10959: $env{'form.archive_count'} = $total-1;
10960: $output .=
10961: &process_extracted_files('coursedocs',$docudom,
10962: $docuname,$destination,
10963: $dir_root,$hiddenelem);
10964: }
1.1055 raeburn 10965: } else {
10966: $warning = &mt('No new items extracted from archive file.');
10967: }
10968: } else {
10969: $output = $display;
10970: $error = &mt('An error occurred during extraction from the archive file.');
10971: }
10972: }
10973: }
10974: }
10975: if ($error) {
10976: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
10977: $error.'</p>'."\n";
10978: }
10979: if ($warning) {
10980: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
10981: }
10982: return $output;
10983: }
10984:
10985: sub get_extracted {
1.1056 raeburn 10986: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
10987: $titles,$wantform) = @_;
1.1055 raeburn 10988: my $count = 0;
10989: my $depth = 0;
10990: my $datatable;
1.1056 raeburn 10991: my @hierarchy;
1.1055 raeburn 10992: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 10993: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
10994: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 10995: foreach my $item (@{$contents}) {
10996: $count ++;
1.1056 raeburn 10997: @{$dirorder->{$count}} = @hierarchy;
10998: $titles->{$count} = $item;
1.1055 raeburn 10999: &archive_hierarchy($depth,$count,$parent,$children);
11000: if ($wantform) {
11001: $datatable .= &archive_row($is_dir->{$item},$item,
11002: $currdir,$depth,$count);
11003: }
11004: if ($is_dir->{$item}) {
11005: $depth ++;
1.1056 raeburn 11006: push(@hierarchy,$count);
11007: $parent->{$depth} = $count;
1.1055 raeburn 11008: $datatable .=
11009: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11010: \$depth,\$count,\@hierarchy,$dirorder,
11011: $children,$parent,$titles,$wantform);
1.1055 raeburn 11012: $depth --;
1.1056 raeburn 11013: pop(@hierarchy);
1.1055 raeburn 11014: }
11015: }
11016: return ($count,$datatable);
11017: }
11018:
11019: sub recurse_extracted_archive {
1.1056 raeburn 11020: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11021: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11022: my $result='';
1.1056 raeburn 11023: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11024: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11025: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11026: return $result;
11027: }
11028: my $dirptr = 16384;
11029: my ($newdirlistref,$newlisterror) =
11030: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11031: if (ref($newdirlistref) eq 'ARRAY') {
11032: foreach my $dir_line (@{$newdirlistref}) {
11033: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11034: unless ($item =~ /^\.+$/) {
11035: $$count ++;
1.1056 raeburn 11036: @{$dirorder->{$$count}} = @{$hierarchy};
11037: $titles->{$$count} = $item;
1.1055 raeburn 11038: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11039:
1.1055 raeburn 11040: my $is_dir;
11041: if ($dirptr&$testdir) {
11042: $is_dir = 1;
11043: }
11044: if ($wantform) {
11045: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11046: }
11047: if ($is_dir) {
11048: $$depth ++;
1.1056 raeburn 11049: push(@{$hierarchy},$$count);
11050: $parent->{$$depth} = $$count;
1.1055 raeburn 11051: $result .=
11052: &recurse_extracted_archive("$currdir/$item",$docudom,
11053: $docuname,$depth,$count,
1.1056 raeburn 11054: $hierarchy,$dirorder,$children,
11055: $parent,$titles,$wantform);
1.1055 raeburn 11056: $$depth --;
1.1056 raeburn 11057: pop(@{$hierarchy});
1.1055 raeburn 11058: }
11059: }
11060: }
11061: }
11062: return $result;
11063: }
11064:
11065: sub archive_hierarchy {
11066: my ($depth,$count,$parent,$children) =@_;
11067: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11068: if (exists($parent->{$depth})) {
11069: $children->{$parent->{$depth}} .= $count.':';
11070: }
11071: }
11072: return;
11073: }
11074:
11075: sub archive_row {
11076: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11077: my ($name) = ($item =~ m{([^/]+)$});
11078: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11079: 'display' => 'Add as file',
1.1055 raeburn 11080: 'dependency' => 'Include as dependency',
11081: 'discard' => 'Discard',
11082: );
11083: if ($is_dir) {
1.1059 raeburn 11084: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11085: }
1.1056 raeburn 11086: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11087: my $offset = 0;
1.1055 raeburn 11088: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11089: $offset ++;
1.1065 raeburn 11090: if ($action ne 'display') {
11091: $offset ++;
11092: }
1.1055 raeburn 11093: $output .= '<td><span class="LC_nobreak">'.
11094: '<label><input type="radio" name="archive_'.$count.
11095: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11096: my $text = $choices{$action};
11097: if ($is_dir) {
11098: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11099: if ($action eq 'display') {
1.1059 raeburn 11100: $text = &mt('Add as folder');
1.1055 raeburn 11101: }
1.1056 raeburn 11102: } else {
11103: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11104:
11105: }
11106: $output .= ' /> '.$choices{$action}.'</label></span>';
11107: if ($action eq 'dependency') {
11108: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11109: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11110: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11111: '<option value=""></option>'."\n".
11112: '</select>'."\n".
11113: '</div>';
1.1059 raeburn 11114: } elsif ($action eq 'display') {
11115: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11116: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11117: '</div>';
1.1055 raeburn 11118: }
1.1056 raeburn 11119: $output .= '</td>';
1.1055 raeburn 11120: }
11121: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11122: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11123: for (my $i=0; $i<$depth; $i++) {
11124: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11125: }
11126: if ($is_dir) {
11127: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11128: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11129: } else {
11130: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11131: }
11132: $output .= ' '.$name.'</td>'."\n".
11133: &end_data_table_row();
11134: return $output;
11135: }
11136:
11137: sub archive_options_form {
1.1065 raeburn 11138: my ($form,$display,$count,$hiddenelem) = @_;
11139: my %lt = &Apache::lonlocal::texthash(
11140: perm => 'Permanently remove archive file?',
11141: hows => 'How should each extracted item be incorporated in the course?',
11142: cont => 'Content actions for all',
11143: addf => 'Add as folder/file',
11144: incd => 'Include as dependency for a displayed file',
11145: disc => 'Discard',
11146: no => 'No',
11147: yes => 'Yes',
11148: save => 'Save',
11149: );
11150: my $output = <<"END";
11151: <form name="$form" method="post" action="">
11152: <p><span class="LC_nobreak">$lt{'perm'}
11153: <label>
11154: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11155: </label>
11156:
11157: <label>
11158: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11159: </span>
11160: </p>
11161: <input type="hidden" name="phase" value="decompress_cleanup" />
11162: <br />$lt{'hows'}
11163: <div class="LC_columnSection">
11164: <fieldset>
11165: <legend>$lt{'cont'}</legend>
11166: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11167: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11168: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11169: </fieldset>
11170: </div>
11171: END
11172: return $output.
1.1055 raeburn 11173: &start_data_table()."\n".
1.1065 raeburn 11174: $display."\n".
1.1055 raeburn 11175: &end_data_table()."\n".
11176: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11177: $hiddenelem.
1.1065 raeburn 11178: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11179: '</form>';
11180: }
11181:
11182: sub archive_javascript {
1.1056 raeburn 11183: my ($startcount,$numitems,$titles,$children) = @_;
11184: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11185: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11186: my $scripttag = <<START;
11187: <script type="text/javascript">
11188: // <![CDATA[
11189:
11190: function checkAll(form,prefix) {
11191: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11192: for (var i=0; i < form.elements.length; i++) {
11193: var id = form.elements[i].id;
11194: if ((id != '') && (id != undefined)) {
11195: if (idstr.test(id)) {
11196: if (form.elements[i].type == 'radio') {
11197: form.elements[i].checked = true;
1.1056 raeburn 11198: var nostart = i-$startcount;
1.1059 raeburn 11199: var offset = nostart%7;
11200: var count = (nostart-offset)/7;
1.1056 raeburn 11201: dependencyCheck(form,count,offset);
1.1055 raeburn 11202: }
11203: }
11204: }
11205: }
11206: }
11207:
11208: function propagateCheck(form,count) {
11209: if (count > 0) {
1.1059 raeburn 11210: var startelement = $startcount + ((count-1) * 7);
11211: for (var j=1; j<6; j++) {
11212: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11213: var item = startelement + j;
11214: if (form.elements[item].type == 'radio') {
11215: if (form.elements[item].checked) {
11216: containerCheck(form,count,j);
11217: break;
11218: }
1.1055 raeburn 11219: }
11220: }
11221: }
11222: }
11223: }
11224:
11225: numitems = $numitems
1.1056 raeburn 11226: var titles = new Array(numitems);
11227: var parents = new Array(numitems);
1.1055 raeburn 11228: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11229: parents[i] = new Array;
1.1055 raeburn 11230: }
1.1059 raeburn 11231: var maintitle = '$maintitle';
1.1055 raeburn 11232:
11233: START
11234:
1.1056 raeburn 11235: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11236: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11237: for (my $i=0; $i<@contents; $i ++) {
11238: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11239: }
11240: }
11241:
1.1056 raeburn 11242: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11243: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11244: }
11245:
1.1055 raeburn 11246: $scripttag .= <<END;
11247:
11248: function containerCheck(form,count,offset) {
11249: if (count > 0) {
1.1056 raeburn 11250: dependencyCheck(form,count,offset);
1.1059 raeburn 11251: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11252: form.elements[item].checked = true;
11253: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11254: if (parents[count].length > 0) {
11255: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11256: containerCheck(form,parents[count][j],offset);
11257: }
11258: }
11259: }
11260: }
11261: }
11262:
11263: function dependencyCheck(form,count,offset) {
11264: if (count > 0) {
1.1059 raeburn 11265: var chosen = (offset+$startcount)+7*(count-1);
11266: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11267: var currtype = form.elements[depitem].type;
11268: if (form.elements[chosen].value == 'dependency') {
11269: document.getElementById('arc_depon_'+count).style.display='block';
11270: form.elements[depitem].options.length = 0;
11271: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11272: for (var i=1; i<=numitems; i++) {
11273: if (i == count) {
11274: continue;
11275: }
1.1059 raeburn 11276: var startelement = $startcount + (i-1) * 7;
11277: for (var j=1; j<6; j++) {
11278: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11279: var item = startelement + j;
11280: if (form.elements[item].type == 'radio') {
11281: if (form.elements[item].checked) {
11282: if (form.elements[item].value == 'display') {
11283: var n = form.elements[depitem].options.length;
11284: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11285: }
11286: }
11287: }
11288: }
11289: }
11290: }
11291: } else {
11292: document.getElementById('arc_depon_'+count).style.display='none';
11293: form.elements[depitem].options.length = 0;
11294: form.elements[depitem].options[0] = new Option('Select','',true,true);
11295: }
1.1059 raeburn 11296: titleCheck(form,count,offset);
1.1056 raeburn 11297: }
11298: }
11299:
11300: function propagateSelect(form,count,offset) {
11301: if (count > 0) {
1.1065 raeburn 11302: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11303: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11304: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11305: if (parents[count].length > 0) {
11306: for (var j=0; j<parents[count].length; j++) {
11307: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11308: }
11309: }
11310: }
11311: }
11312: }
1.1056 raeburn 11313:
11314: function containerSelect(form,count,offset,picked) {
11315: if (count > 0) {
1.1065 raeburn 11316: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11317: if (form.elements[item].type == 'radio') {
11318: if (form.elements[item].value == 'dependency') {
11319: if (form.elements[item+1].type == 'select-one') {
11320: for (var i=0; i<form.elements[item+1].options.length; i++) {
11321: if (form.elements[item+1].options[i].value == picked) {
11322: form.elements[item+1].selectedIndex = i;
11323: break;
11324: }
11325: }
11326: }
11327: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11328: if (parents[count].length > 0) {
11329: for (var j=0; j<parents[count].length; j++) {
11330: containerSelect(form,parents[count][j],offset,picked);
11331: }
11332: }
11333: }
11334: }
11335: }
11336: }
11337: }
11338:
1.1059 raeburn 11339: function titleCheck(form,count,offset) {
11340: if (count > 0) {
11341: var chosen = (offset+$startcount)+7*(count-1);
11342: var depitem = $startcount + ((count-1) * 7) + 2;
11343: var currtype = form.elements[depitem].type;
11344: if (form.elements[chosen].value == 'display') {
11345: document.getElementById('arc_title_'+count).style.display='block';
11346: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11347: document.getElementById('archive_title_'+count).value=maintitle;
11348: }
11349: } else {
11350: document.getElementById('arc_title_'+count).style.display='none';
11351: if (currtype == 'text') {
11352: document.getElementById('archive_title_'+count).value='';
11353: }
11354: }
11355: }
11356: return;
11357: }
11358:
1.1055 raeburn 11359: // ]]>
11360: </script>
11361: END
11362: return $scripttag;
11363: }
11364:
11365: sub process_extracted_files {
1.1067 raeburn 11366: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11367: my $numitems = $env{'form.archive_count'};
11368: return unless ($numitems);
11369: my @ids=&Apache::lonnet::current_machine_ids();
11370: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11371: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11372: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11373: if (grep(/^\Q$docuhome\E$/,@ids)) {
11374: $prefix = &LONCAPA::propath($docudom,$docuname);
11375: $pathtocheck = "$dir_root/$destination";
11376: $dir = $dir_root;
11377: $ishome = 1;
11378: } else {
11379: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11380: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11381: $dir = "$dir_root/$docudom/$docuname";
11382: }
11383: my $currdir = "$dir_root/$destination";
11384: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11385: if ($env{'form.folderpath'}) {
11386: my @items = split('&',$env{'form.folderpath'});
11387: $folders{'0'} = $items[-2];
1.1099 raeburn 11388: if ($env{'form.folderpath'} =~ /\:1$/) {
11389: $containers{'0'}='page';
11390: } else {
11391: $containers{'0'}='sequence';
11392: }
1.1055 raeburn 11393: }
11394: my @archdirs = &get_env_multiple('form.archive_directory');
11395: if ($numitems) {
11396: for (my $i=1; $i<=$numitems; $i++) {
11397: my $path = $env{'form.archive_content_'.$i};
11398: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11399: my $item = $1;
11400: $toplevelitems{$item} = $i;
11401: if (grep(/^\Q$i\E$/,@archdirs)) {
11402: $is_dir{$item} = 1;
11403: }
11404: }
11405: }
11406: }
1.1067 raeburn 11407: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11408: if (keys(%toplevelitems) > 0) {
11409: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11410: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11411: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11412: }
1.1066 raeburn 11413: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11414: if ($numitems) {
11415: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11416: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11417: my $path = $env{'form.archive_content_'.$i};
11418: if ($path =~ /^\Q$pathtocheck\E/) {
11419: if ($env{'form.archive_'.$i} eq 'discard') {
11420: if ($prefix ne '' && $path ne '') {
11421: if (-e $prefix.$path) {
1.1066 raeburn 11422: if ((@archdirs > 0) &&
11423: (grep(/^\Q$i\E$/,@archdirs))) {
11424: $todeletedir{$prefix.$path} = 1;
11425: } else {
11426: $todelete{$prefix.$path} = 1;
11427: }
1.1055 raeburn 11428: }
11429: }
11430: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11431: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11432: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11433: $docstitle = $env{'form.archive_title_'.$i};
11434: if ($docstitle eq '') {
11435: $docstitle = $title;
11436: }
1.1055 raeburn 11437: $outer = 0;
1.1056 raeburn 11438: if (ref($dirorder{$i}) eq 'ARRAY') {
11439: if (@{$dirorder{$i}} > 0) {
11440: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11441: if ($env{'form.archive_'.$item} eq 'display') {
11442: $outer = $item;
11443: last;
11444: }
11445: }
11446: }
11447: }
11448: my ($errtext,$fatal) =
11449: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11450: '/'.$folders{$outer}.'.'.
11451: $containers{$outer});
11452: next if ($fatal);
11453: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11454: if ($context eq 'coursedocs') {
1.1056 raeburn 11455: $mapinner{$i} = time;
1.1055 raeburn 11456: $folders{$i} = 'default_'.$mapinner{$i};
11457: $containers{$i} = 'sequence';
11458: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11459: $folders{$i}.'.'.$containers{$i};
11460: my $newidx = &LONCAPA::map::getresidx();
11461: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11462: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11463: push(@LONCAPA::map::order,$newidx);
11464: my ($outtext,$errtext) =
11465: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11466: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11467: '.'.$containers{$outer},1,1);
1.1056 raeburn 11468: $newseqid{$i} = $newidx;
1.1067 raeburn 11469: unless ($errtext) {
11470: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11471: }
1.1055 raeburn 11472: }
11473: } else {
11474: if ($context eq 'coursedocs') {
11475: my $newidx=&LONCAPA::map::getresidx();
11476: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11477: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11478: $title;
11479: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11480: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11481: }
11482: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11483: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11484: }
11485: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11486: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11487: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11488: unless ($ishome) {
11489: my $fetch = "$newdest{$i}/$title";
11490: $fetch =~ s/^\Q$prefix$dir\E//;
11491: $prompttofetch{$fetch} = 1;
11492: }
1.1055 raeburn 11493: }
11494: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11495: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11496: push(@LONCAPA::map::order, $newidx);
11497: my ($outtext,$errtext)=
11498: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11499: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11500: '.'.$containers{$outer},1,1);
1.1067 raeburn 11501: unless ($errtext) {
11502: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11503: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11504: }
11505: }
1.1055 raeburn 11506: }
11507: }
1.1086 raeburn 11508: }
11509: } else {
11510: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11511: }
11512: }
11513: for (my $i=1; $i<=$numitems; $i++) {
11514: next unless ($env{'form.archive_'.$i} eq 'dependency');
11515: my $path = $env{'form.archive_content_'.$i};
11516: if ($path =~ /^\Q$pathtocheck\E/) {
11517: my ($title) = ($path =~ m{/([^/]+)$});
11518: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
11519: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
11520: if (ref($dirorder{$i}) eq 'ARRAY') {
11521: my ($itemidx,$fullpath,$relpath);
11522: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
11523: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 11524: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 11525: if ($dirorder{$i}->[$j] eq $container) {
11526: $itemidx = $j;
1.1056 raeburn 11527: }
11528: }
1.1086 raeburn 11529: }
11530: if ($itemidx eq '') {
11531: $itemidx = 0;
11532: }
11533: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
11534: if ($mapinner{$referrer{$i}}) {
11535: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
11536: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11537: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11538: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11539: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11540: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11541: if (!-e $fullpath) {
11542: mkdir($fullpath,0755);
1.1056 raeburn 11543: }
11544: }
1.1086 raeburn 11545: } else {
11546: last;
1.1056 raeburn 11547: }
1.1086 raeburn 11548: }
11549: }
11550: } elsif ($newdest{$referrer{$i}}) {
11551: $fullpath = $newdest{$referrer{$i}};
11552: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
11553: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
11554: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
11555: last;
11556: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
11557: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
11558: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
11559: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
11560: if (!-e $fullpath) {
11561: mkdir($fullpath,0755);
1.1056 raeburn 11562: }
11563: }
1.1086 raeburn 11564: } else {
11565: last;
1.1056 raeburn 11566: }
1.1055 raeburn 11567: }
11568: }
1.1086 raeburn 11569: if ($fullpath ne '') {
11570: if (-e "$prefix$path") {
11571: system("mv $prefix$path $fullpath/$title");
11572: }
11573: if (-e "$fullpath/$title") {
11574: my $showpath;
11575: if ($relpath ne '') {
11576: $showpath = "$relpath/$title";
11577: } else {
11578: $showpath = "/$title";
11579: }
11580: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
11581: }
11582: unless ($ishome) {
11583: my $fetch = "$fullpath/$title";
11584: $fetch =~ s/^\Q$prefix$dir\E//;
11585: $prompttofetch{$fetch} = 1;
11586: }
11587: }
1.1055 raeburn 11588: }
1.1086 raeburn 11589: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
11590: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
11591: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 11592: }
11593: } else {
11594: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
11595: }
11596: }
11597: if (keys(%todelete)) {
11598: foreach my $key (keys(%todelete)) {
11599: unlink($key);
1.1066 raeburn 11600: }
11601: }
11602: if (keys(%todeletedir)) {
11603: foreach my $key (keys(%todeletedir)) {
11604: rmdir($key);
11605: }
11606: }
11607: foreach my $dir (sort(keys(%is_dir))) {
11608: if (($pathtocheck ne '') && ($dir ne '')) {
11609: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 11610: }
11611: }
1.1067 raeburn 11612: if ($result ne '') {
11613: $output .= '<ul>'."\n".
11614: $result."\n".
11615: '</ul>';
11616: }
11617: unless ($ishome) {
11618: my $replicationfail;
11619: foreach my $item (keys(%prompttofetch)) {
11620: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
11621: unless ($fetchresult eq 'ok') {
11622: $replicationfail .= '<li>'.$item.'</li>'."\n";
11623: }
11624: }
11625: if ($replicationfail) {
11626: $output .= '<p class="LC_error">'.
11627: &mt('Course home server failed to retrieve:').'<ul>'.
11628: $replicationfail.
11629: '</ul></p>';
11630: }
11631: }
1.1055 raeburn 11632: } else {
11633: $warning = &mt('No items found in archive.');
11634: }
11635: if ($error) {
11636: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11637: $error.'</p>'."\n";
11638: }
11639: if ($warning) {
11640: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11641: }
11642: return $output;
11643: }
11644:
1.1066 raeburn 11645: sub cleanup_empty_dirs {
11646: my ($path) = @_;
11647: if (($path ne '') && (-d $path)) {
11648: if (opendir(my $dirh,$path)) {
11649: my @dircontents = grep(!/^\./,readdir($dirh));
11650: my $numitems = 0;
11651: foreach my $item (@dircontents) {
11652: if (-d "$path/$item") {
1.1111 raeburn 11653: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 11654: if (-e "$path/$item") {
11655: $numitems ++;
11656: }
11657: } else {
11658: $numitems ++;
11659: }
11660: }
11661: if ($numitems == 0) {
11662: rmdir($path);
11663: }
11664: closedir($dirh);
11665: }
11666: }
11667: return;
11668: }
11669:
1.41 ng 11670: =pod
1.45 matthew 11671:
1.1068 raeburn 11672: =item &get_folder_hierarchy()
11673:
11674: Provides hierarchy of names of folders/sub-folders containing the current
11675: item,
11676:
11677: Inputs: 3
11678: - $navmap - navmaps object
11679:
11680: - $map - url for map (either the trigger itself, or map containing
11681: the resource, which is the trigger).
11682:
11683: - $showitem - 1 => show title for map itself; 0 => do not show.
11684:
11685: Outputs: 1 @pathitems - array of folder/subfolder names.
11686:
11687: =cut
11688:
11689: sub get_folder_hierarchy {
11690: my ($navmap,$map,$showitem) = @_;
11691: my @pathitems;
11692: if (ref($navmap)) {
11693: my $mapres = $navmap->getResourceByUrl($map);
11694: if (ref($mapres)) {
11695: my $pcslist = $mapres->map_hierarchy();
11696: if ($pcslist ne '') {
11697: my @pcs = split(/,/,$pcslist);
11698: foreach my $pc (@pcs) {
11699: if ($pc == 1) {
11700: push(@pathitems,&mt('Main Course Documents'));
11701: } else {
11702: my $res = $navmap->getByMapPc($pc);
11703: if (ref($res)) {
11704: my $title = $res->compTitle();
11705: $title =~ s/\W+/_/g;
11706: if ($title ne '') {
11707: push(@pathitems,$title);
11708: }
11709: }
11710: }
11711: }
11712: }
1.1071 raeburn 11713: if ($showitem) {
11714: if ($mapres->{ID} eq '0.0') {
11715: push(@pathitems,&mt('Main Course Documents'));
11716: } else {
11717: my $maptitle = $mapres->compTitle();
11718: $maptitle =~ s/\W+/_/g;
11719: if ($maptitle ne '') {
11720: push(@pathitems,$maptitle);
11721: }
1.1068 raeburn 11722: }
11723: }
11724: }
11725: }
11726: return @pathitems;
11727: }
11728:
11729: =pod
11730:
1.1015 raeburn 11731: =item * &get_turnedin_filepath()
11732:
11733: Determines path in a user's portfolio file for storage of files uploaded
11734: to a specific essayresponse or dropbox item.
11735:
11736: Inputs: 3 required + 1 optional.
11737: $symb is symb for resource, $uname and $udom are for current user (required).
11738: $caller is optional (can be "submission", if routine is called when storing
11739: an upoaded file when "Submit Answer" button was pressed).
11740:
11741: Returns array containing $path and $multiresp.
11742: $path is path in portfolio. $multiresp is 1 if this resource contains more
11743: than one file upload item. Callers of routine should append partid as a
11744: subdirectory to $path in cases where $multiresp is 1.
11745:
11746: Called by: homework/essayresponse.pm and homework/structuretags.pm
11747:
11748: =cut
11749:
11750: sub get_turnedin_filepath {
11751: my ($symb,$uname,$udom,$caller) = @_;
11752: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
11753: my $turnindir;
11754: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
11755: $turnindir = $userhash{'turnindir'};
11756: my ($path,$multiresp);
11757: if ($turnindir eq '') {
11758: if ($caller eq 'submission') {
11759: $turnindir = &mt('turned in');
11760: $turnindir =~ s/\W+/_/g;
11761: my %newhash = (
11762: 'turnindir' => $turnindir,
11763: );
11764: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
11765: }
11766: }
11767: if ($turnindir ne '') {
11768: $path = '/'.$turnindir.'/';
11769: my ($multipart,$turnin,@pathitems);
11770: my $navmap = Apache::lonnavmaps::navmap->new();
11771: if (defined($navmap)) {
11772: my $mapres = $navmap->getResourceByUrl($map);
11773: if (ref($mapres)) {
11774: my $pcslist = $mapres->map_hierarchy();
11775: if ($pcslist ne '') {
11776: foreach my $pc (split(/,/,$pcslist)) {
11777: my $res = $navmap->getByMapPc($pc);
11778: if (ref($res)) {
11779: my $title = $res->compTitle();
11780: $title =~ s/\W+/_/g;
11781: if ($title ne '') {
11782: push(@pathitems,$title);
11783: }
11784: }
11785: }
11786: }
11787: my $maptitle = $mapres->compTitle();
11788: $maptitle =~ s/\W+/_/g;
11789: if ($maptitle ne '') {
11790: push(@pathitems,$maptitle);
11791: }
11792: unless ($env{'request.state'} eq 'construct') {
11793: my $res = $navmap->getBySymb($symb);
11794: if (ref($res)) {
11795: my $partlist = $res->parts();
11796: my $totaluploads = 0;
11797: if (ref($partlist) eq 'ARRAY') {
11798: foreach my $part (@{$partlist}) {
11799: my @types = $res->responseType($part);
11800: my @ids = $res->responseIds($part);
11801: for (my $i=0; $i < scalar(@ids); $i++) {
11802: if ($types[$i] eq 'essay') {
11803: my $partid = $part.'_'.$ids[$i];
11804: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
11805: $totaluploads ++;
11806: }
11807: }
11808: }
11809: }
11810: if ($totaluploads > 1) {
11811: $multiresp = 1;
11812: }
11813: }
11814: }
11815: }
11816: } else {
11817: return;
11818: }
11819: } else {
11820: return;
11821: }
11822: my $restitle=&Apache::lonnet::gettitle($symb);
11823: $restitle =~ s/\W+/_/g;
11824: if ($restitle eq '') {
11825: $restitle = ($resurl =~ m{/[^/]+$});
11826: if ($restitle eq '') {
11827: $restitle = time;
11828: }
11829: }
11830: push(@pathitems,$restitle);
11831: $path .= join('/',@pathitems);
11832: }
11833: return ($path,$multiresp);
11834: }
11835:
11836: =pod
11837:
1.464 albertel 11838: =back
1.41 ng 11839:
1.112 bowersj2 11840: =head1 CSV Upload/Handling functions
1.38 albertel 11841:
1.41 ng 11842: =over 4
11843:
1.648 raeburn 11844: =item * &upfile_store($r)
1.41 ng 11845:
11846: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 11847: needs $env{'form.upfile'}
1.41 ng 11848: returns $datatoken to be put into hidden field
11849:
11850: =cut
1.31 albertel 11851:
11852: sub upfile_store {
11853: my $r=shift;
1.258 albertel 11854: $env{'form.upfile'}=~s/\r/\n/gs;
11855: $env{'form.upfile'}=~s/\f/\n/gs;
11856: $env{'form.upfile'}=~s/\n+/\n/gs;
11857: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 11858:
1.258 albertel 11859: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
11860: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 11861: {
1.158 raeburn 11862: my $datafile = $r->dir_config('lonDaemons').
11863: '/tmp/'.$datatoken.'.tmp';
11864: if ( open(my $fh,">$datafile") ) {
1.258 albertel 11865: print $fh $env{'form.upfile'};
1.158 raeburn 11866: close($fh);
11867: }
1.31 albertel 11868: }
11869: return $datatoken;
11870: }
11871:
1.56 matthew 11872: =pod
11873:
1.648 raeburn 11874: =item * &load_tmp_file($r)
1.41 ng 11875:
11876: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 11877: needs $env{'form.datatoken'},
11878: sets $env{'form.upfile'} to the contents of the file
1.41 ng 11879:
11880: =cut
1.31 albertel 11881:
11882: sub load_tmp_file {
11883: my $r=shift;
11884: my @studentdata=();
11885: {
1.158 raeburn 11886: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 11887: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 11888: if ( open(my $fh,"<$studentfile") ) {
11889: @studentdata=<$fh>;
11890: close($fh);
11891: }
1.31 albertel 11892: }
1.258 albertel 11893: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 11894: }
11895:
1.56 matthew 11896: =pod
11897:
1.648 raeburn 11898: =item * &upfile_record_sep()
1.41 ng 11899:
11900: Separate uploaded file into records
11901: returns array of records,
1.258 albertel 11902: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 11903:
11904: =cut
1.31 albertel 11905:
11906: sub upfile_record_sep {
1.258 albertel 11907: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 11908: } else {
1.248 albertel 11909: my @records;
1.258 albertel 11910: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 11911: if ($line=~/^\s*$/) { next; }
11912: push(@records,$line);
11913: }
11914: return @records;
1.31 albertel 11915: }
11916: }
11917:
1.56 matthew 11918: =pod
11919:
1.648 raeburn 11920: =item * &record_sep($record)
1.41 ng 11921:
1.258 albertel 11922: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 11923:
11924: =cut
11925:
1.263 www 11926: sub takeleft {
11927: my $index=shift;
11928: return substr('0000'.$index,-4,4);
11929: }
11930:
1.31 albertel 11931: sub record_sep {
11932: my $record=shift;
11933: my %components=();
1.258 albertel 11934: if ($env{'form.upfiletype'} eq 'xml') {
11935: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 11936: my $i=0;
1.356 albertel 11937: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 11938: $field=~s/^(\"|\')//;
11939: $field=~s/(\"|\')$//;
1.263 www 11940: $components{&takeleft($i)}=$field;
1.31 albertel 11941: $i++;
11942: }
1.258 albertel 11943: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 11944: my $i=0;
1.356 albertel 11945: foreach my $field (split(/\t/,$record)) {
1.31 albertel 11946: $field=~s/^(\"|\')//;
11947: $field=~s/(\"|\')$//;
1.263 www 11948: $components{&takeleft($i)}=$field;
1.31 albertel 11949: $i++;
11950: }
11951: } else {
1.561 www 11952: my $separator=',';
1.480 banghart 11953: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 11954: $separator=';';
1.480 banghart 11955: }
1.31 albertel 11956: my $i=0;
1.561 www 11957: # the character we are looking for to indicate the end of a quote or a record
11958: my $looking_for=$separator;
11959: # do not add the characters to the fields
11960: my $ignore=0;
11961: # we just encountered a separator (or the beginning of the record)
11962: my $just_found_separator=1;
11963: # store the field we are working on here
11964: my $field='';
11965: # work our way through all characters in record
11966: foreach my $character ($record=~/(.)/g) {
11967: if ($character eq $looking_for) {
11968: if ($character ne $separator) {
11969: # Found the end of a quote, again looking for separator
11970: $looking_for=$separator;
11971: $ignore=1;
11972: } else {
11973: # Found a separator, store away what we got
11974: $components{&takeleft($i)}=$field;
11975: $i++;
11976: $just_found_separator=1;
11977: $ignore=0;
11978: $field='';
11979: }
11980: next;
11981: }
11982: # single or double quotation marks after a separator indicate beginning of a quote
11983: # we are now looking for the end of the quote and need to ignore separators
11984: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
11985: $looking_for=$character;
11986: next;
11987: }
11988: # ignore would be true after we reached the end of a quote
11989: if ($ignore) { next; }
11990: if (($just_found_separator) && ($character=~/\s/)) { next; }
11991: $field.=$character;
11992: $just_found_separator=0;
1.31 albertel 11993: }
1.561 www 11994: # catch the very last entry, since we never encountered the separator
11995: $components{&takeleft($i)}=$field;
1.31 albertel 11996: }
11997: return %components;
11998: }
11999:
1.144 matthew 12000: ######################################################
12001: ######################################################
12002:
1.56 matthew 12003: =pod
12004:
1.648 raeburn 12005: =item * &upfile_select_html()
1.41 ng 12006:
1.144 matthew 12007: Return HTML code to select a file from the users machine and specify
12008: the file type.
1.41 ng 12009:
12010: =cut
12011:
1.144 matthew 12012: ######################################################
12013: ######################################################
1.31 albertel 12014: sub upfile_select_html {
1.144 matthew 12015: my %Types = (
12016: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12017: semisv => &mt('Semicolon separated values'),
1.144 matthew 12018: space => &mt('Space separated'),
12019: tab => &mt('Tabulator separated'),
12020: # xml => &mt('HTML/XML'),
12021: );
12022: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12023: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12024: foreach my $type (sort(keys(%Types))) {
12025: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12026: }
12027: $Str .= "</select>\n";
12028: return $Str;
1.31 albertel 12029: }
12030:
1.301 albertel 12031: sub get_samples {
12032: my ($records,$toget) = @_;
12033: my @samples=({});
12034: my $got=0;
12035: foreach my $rec (@$records) {
12036: my %temp = &record_sep($rec);
12037: if (! grep(/\S/, values(%temp))) { next; }
12038: if (%temp) {
12039: $samples[$got]=\%temp;
12040: $got++;
12041: if ($got == $toget) { last; }
12042: }
12043: }
12044: return \@samples;
12045: }
12046:
1.144 matthew 12047: ######################################################
12048: ######################################################
12049:
1.56 matthew 12050: =pod
12051:
1.648 raeburn 12052: =item * &csv_print_samples($r,$records)
1.41 ng 12053:
12054: Prints a table of sample values from each column uploaded $r is an
12055: Apache Request ref, $records is an arrayref from
12056: &Apache::loncommon::upfile_record_sep
12057:
12058: =cut
12059:
1.144 matthew 12060: ######################################################
12061: ######################################################
1.31 albertel 12062: sub csv_print_samples {
12063: my ($r,$records) = @_;
1.662 bisitz 12064: my $samples = &get_samples($records,5);
1.301 albertel 12065:
1.594 raeburn 12066: $r->print(&mt('Samples').'<br />'.&start_data_table().
12067: &start_data_table_header_row());
1.356 albertel 12068: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12069: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12070: $r->print(&end_data_table_header_row());
1.301 albertel 12071: foreach my $hash (@$samples) {
1.594 raeburn 12072: $r->print(&start_data_table_row());
1.356 albertel 12073: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12074: $r->print('<td>');
1.356 albertel 12075: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12076: $r->print('</td>');
12077: }
1.594 raeburn 12078: $r->print(&end_data_table_row());
1.31 albertel 12079: }
1.594 raeburn 12080: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12081: }
12082:
1.144 matthew 12083: ######################################################
12084: ######################################################
12085:
1.56 matthew 12086: =pod
12087:
1.648 raeburn 12088: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12089:
12090: Prints a table to create associations between values and table columns.
1.144 matthew 12091:
1.41 ng 12092: $r is an Apache Request ref,
12093: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12094: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12095:
12096: =cut
12097:
1.144 matthew 12098: ######################################################
12099: ######################################################
1.31 albertel 12100: sub csv_print_select_table {
12101: my ($r,$records,$d) = @_;
1.301 albertel 12102: my $i=0;
12103: my $samples = &get_samples($records,1);
1.144 matthew 12104: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12105: &start_data_table().&start_data_table_header_row().
1.144 matthew 12106: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12107: '<th>'.&mt('Column').'</th>'.
12108: &end_data_table_header_row()."\n");
1.356 albertel 12109: foreach my $array_ref (@$d) {
12110: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12111: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12112:
1.875 bisitz 12113: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12114: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12115: $r->print('<option value="none"></option>');
1.356 albertel 12116: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12117: $r->print('<option value="'.$sample.'"'.
12118: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12119: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12120: }
1.594 raeburn 12121: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12122: $i++;
12123: }
1.594 raeburn 12124: $r->print(&end_data_table());
1.31 albertel 12125: $i--;
12126: return $i;
12127: }
1.56 matthew 12128:
1.144 matthew 12129: ######################################################
12130: ######################################################
12131:
1.56 matthew 12132: =pod
1.31 albertel 12133:
1.648 raeburn 12134: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12135:
12136: Prints a table of sample values from the upload and can make associate samples to internal names.
12137:
12138: $r is an Apache Request ref,
12139: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12140: $d is an array of 2 element arrays (internal name, displayed name)
12141:
12142: =cut
12143:
1.144 matthew 12144: ######################################################
12145: ######################################################
1.31 albertel 12146: sub csv_samples_select_table {
12147: my ($r,$records,$d) = @_;
12148: my $i=0;
1.144 matthew 12149: #
1.662 bisitz 12150: my $max_samples = 5;
12151: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12152: $r->print(&start_data_table().
12153: &start_data_table_header_row().'<th>'.
12154: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12155: &end_data_table_header_row());
1.301 albertel 12156:
12157: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12158: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12159: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12160: foreach my $option (@$d) {
12161: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12162: $r->print('<option value="'.$value.'"'.
1.253 albertel 12163: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12164: $display.'</option>');
1.31 albertel 12165: }
12166: $r->print('</select></td><td>');
1.662 bisitz 12167: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12168: if (defined($samples->[$line]{$key})) {
12169: $r->print($samples->[$line]{$key}."<br />\n");
12170: }
12171: }
1.594 raeburn 12172: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12173: $i++;
12174: }
1.594 raeburn 12175: $r->print(&end_data_table());
1.31 albertel 12176: $i--;
12177: return($i);
1.115 matthew 12178: }
12179:
1.144 matthew 12180: ######################################################
12181: ######################################################
12182:
1.115 matthew 12183: =pod
12184:
1.648 raeburn 12185: =item * &clean_excel_name($name)
1.115 matthew 12186:
12187: Returns a replacement for $name which does not contain any illegal characters.
12188:
12189: =cut
12190:
1.144 matthew 12191: ######################################################
12192: ######################################################
1.115 matthew 12193: sub clean_excel_name {
12194: my ($name) = @_;
12195: $name =~ s/[:\*\?\/\\]//g;
12196: if (length($name) > 31) {
12197: $name = substr($name,0,31);
12198: }
12199: return $name;
1.25 albertel 12200: }
1.84 albertel 12201:
1.85 albertel 12202: =pod
12203:
1.648 raeburn 12204: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12205:
12206: Returns either 1 or undef
12207:
12208: 1 if the part is to be hidden, undef if it is to be shown
12209:
12210: Arguments are:
12211:
12212: $id the id of the part to be checked
12213: $symb, optional the symb of the resource to check
12214: $udom, optional the domain of the user to check for
12215: $uname, optional the username of the user to check for
12216:
12217: =cut
1.84 albertel 12218:
12219: sub check_if_partid_hidden {
12220: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12221: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12222: $symb,$udom,$uname);
1.141 albertel 12223: my $truth=1;
12224: #if the string starts with !, then the list is the list to show not hide
12225: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12226: my @hiddenlist=split(/,/,$hiddenparts);
12227: foreach my $checkid (@hiddenlist) {
1.141 albertel 12228: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12229: }
1.141 albertel 12230: return !$truth;
1.84 albertel 12231: }
1.127 matthew 12232:
1.138 matthew 12233:
12234: ############################################################
12235: ############################################################
12236:
12237: =pod
12238:
1.157 matthew 12239: =back
12240:
1.138 matthew 12241: =head1 cgi-bin script and graphing routines
12242:
1.157 matthew 12243: =over 4
12244:
1.648 raeburn 12245: =item * &get_cgi_id()
1.138 matthew 12246:
12247: Inputs: none
12248:
12249: Returns an id which can be used to pass environment variables
12250: to various cgi-bin scripts. These environment variables will
12251: be removed from the users environment after a given time by
12252: the routine &Apache::lonnet::transfer_profile_to_env.
12253:
12254: =cut
12255:
12256: ############################################################
12257: ############################################################
1.152 albertel 12258: my $uniq=0;
1.136 matthew 12259: sub get_cgi_id {
1.154 albertel 12260: $uniq=($uniq+1)%100000;
1.280 albertel 12261: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12262: }
12263:
1.127 matthew 12264: ############################################################
12265: ############################################################
12266:
12267: =pod
12268:
1.648 raeburn 12269: =item * &DrawBarGraph()
1.127 matthew 12270:
1.138 matthew 12271: Facilitates the plotting of data in a (stacked) bar graph.
12272: Puts plot definition data into the users environment in order for
12273: graph.png to plot it. Returns an <img> tag for the plot.
12274: The bars on the plot are labeled '1','2',...,'n'.
12275:
12276: Inputs:
12277:
12278: =over 4
12279:
12280: =item $Title: string, the title of the plot
12281:
12282: =item $xlabel: string, text describing the X-axis of the plot
12283:
12284: =item $ylabel: string, text describing the Y-axis of the plot
12285:
12286: =item $Max: scalar, the maximum Y value to use in the plot
12287: If $Max is < any data point, the graph will not be rendered.
12288:
1.140 matthew 12289: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12290: they are plotted. If undefined, default values will be used.
12291:
1.178 matthew 12292: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12293:
1.138 matthew 12294: =item @Values: An array of array references. Each array reference holds data
12295: to be plotted in a stacked bar chart.
12296:
1.239 matthew 12297: =item If the final element of @Values is a hash reference the key/value
12298: pairs will be added to the graph definition.
12299:
1.138 matthew 12300: =back
12301:
12302: Returns:
12303:
12304: An <img> tag which references graph.png and the appropriate identifying
12305: information for the plot.
12306:
1.127 matthew 12307: =cut
12308:
12309: ############################################################
12310: ############################################################
1.134 matthew 12311: sub DrawBarGraph {
1.178 matthew 12312: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12313: #
12314: if (! defined($colors)) {
12315: $colors = ['#33ff00',
12316: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12317: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12318: ];
12319: }
1.228 matthew 12320: my $extra_settings = {};
12321: if (ref($Values[-1]) eq 'HASH') {
12322: $extra_settings = pop(@Values);
12323: }
1.127 matthew 12324: #
1.136 matthew 12325: my $identifier = &get_cgi_id();
12326: my $id = 'cgi.'.$identifier;
1.129 matthew 12327: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12328: return '';
12329: }
1.225 matthew 12330: #
12331: my @Labels;
12332: if (defined($labels)) {
12333: @Labels = @$labels;
12334: } else {
12335: for (my $i=0;$i<@{$Values[0]};$i++) {
12336: push (@Labels,$i+1);
12337: }
12338: }
12339: #
1.129 matthew 12340: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12341: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12342: my %ValuesHash;
12343: my $NumSets=1;
12344: foreach my $array (@Values) {
12345: next if (! ref($array));
1.136 matthew 12346: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12347: join(',',@$array);
1.129 matthew 12348: }
1.127 matthew 12349: #
1.136 matthew 12350: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12351: if ($NumBars < 3) {
12352: $width = 120+$NumBars*32;
1.220 matthew 12353: $xskip = 1;
1.225 matthew 12354: $bar_width = 30;
12355: } elsif ($NumBars < 5) {
12356: $width = 120+$NumBars*20;
12357: $xskip = 1;
12358: $bar_width = 20;
1.220 matthew 12359: } elsif ($NumBars < 10) {
1.136 matthew 12360: $width = 120+$NumBars*15;
12361: $xskip = 1;
12362: $bar_width = 15;
12363: } elsif ($NumBars <= 25) {
12364: $width = 120+$NumBars*11;
12365: $xskip = 5;
12366: $bar_width = 8;
12367: } elsif ($NumBars <= 50) {
12368: $width = 120+$NumBars*8;
12369: $xskip = 5;
12370: $bar_width = 4;
12371: } else {
12372: $width = 120+$NumBars*8;
12373: $xskip = 5;
12374: $bar_width = 4;
12375: }
12376: #
1.137 matthew 12377: $Max = 1 if ($Max < 1);
12378: if ( int($Max) < $Max ) {
12379: $Max++;
12380: $Max = int($Max);
12381: }
1.127 matthew 12382: $Title = '' if (! defined($Title));
12383: $xlabel = '' if (! defined($xlabel));
12384: $ylabel = '' if (! defined($ylabel));
1.369 www 12385: $ValuesHash{$id.'.title'} = &escape($Title);
12386: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12387: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12388: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12389: $ValuesHash{$id.'.NumBars'} = $NumBars;
12390: $ValuesHash{$id.'.NumSets'} = $NumSets;
12391: $ValuesHash{$id.'.PlotType'} = 'bar';
12392: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12393: $ValuesHash{$id.'.height'} = $height;
12394: $ValuesHash{$id.'.width'} = $width;
12395: $ValuesHash{$id.'.xskip'} = $xskip;
12396: $ValuesHash{$id.'.bar_width'} = $bar_width;
12397: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12398: #
1.228 matthew 12399: # Deal with other parameters
12400: while (my ($key,$value) = each(%$extra_settings)) {
12401: $ValuesHash{$id.'.'.$key} = $value;
12402: }
12403: #
1.646 raeburn 12404: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12405: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12406: }
12407:
12408: ############################################################
12409: ############################################################
12410:
12411: =pod
12412:
1.648 raeburn 12413: =item * &DrawXYGraph()
1.137 matthew 12414:
1.138 matthew 12415: Facilitates the plotting of data in an XY graph.
12416: Puts plot definition data into the users environment in order for
12417: graph.png to plot it. Returns an <img> tag for the plot.
12418:
12419: Inputs:
12420:
12421: =over 4
12422:
12423: =item $Title: string, the title of the plot
12424:
12425: =item $xlabel: string, text describing the X-axis of the plot
12426:
12427: =item $ylabel: string, text describing the Y-axis of the plot
12428:
12429: =item $Max: scalar, the maximum Y value to use in the plot
12430: If $Max is < any data point, the graph will not be rendered.
12431:
12432: =item $colors: Array ref containing the hex color codes for the data to be
12433: plotted in. If undefined, default values will be used.
12434:
12435: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12436:
12437: =item $Ydata: Array ref containing Array refs.
1.185 www 12438: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12439:
12440: =item %Values: hash indicating or overriding any default values which are
12441: passed to graph.png.
12442: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12443:
12444: =back
12445:
12446: Returns:
12447:
12448: An <img> tag which references graph.png and the appropriate identifying
12449: information for the plot.
12450:
1.137 matthew 12451: =cut
12452:
12453: ############################################################
12454: ############################################################
12455: sub DrawXYGraph {
12456: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12457: #
12458: # Create the identifier for the graph
12459: my $identifier = &get_cgi_id();
12460: my $id = 'cgi.'.$identifier;
12461: #
12462: $Title = '' if (! defined($Title));
12463: $xlabel = '' if (! defined($xlabel));
12464: $ylabel = '' if (! defined($ylabel));
12465: my %ValuesHash =
12466: (
1.369 www 12467: $id.'.title' => &escape($Title),
12468: $id.'.xlabel' => &escape($xlabel),
12469: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12470: $id.'.y_max_value'=> $Max,
12471: $id.'.labels' => join(',',@$Xlabels),
12472: $id.'.PlotType' => 'XY',
12473: );
12474: #
12475: if (defined($colors) && ref($colors) eq 'ARRAY') {
12476: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12477: }
12478: #
12479: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12480: return '';
12481: }
12482: my $NumSets=1;
1.138 matthew 12483: foreach my $array (@{$Ydata}){
1.137 matthew 12484: next if (! ref($array));
12485: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12486: }
1.138 matthew 12487: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12488: #
12489: # Deal with other parameters
12490: while (my ($key,$value) = each(%Values)) {
12491: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12492: }
12493: #
1.646 raeburn 12494: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12495: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12496: }
12497:
12498: ############################################################
12499: ############################################################
12500:
12501: =pod
12502:
1.648 raeburn 12503: =item * &DrawXYYGraph()
1.138 matthew 12504:
12505: Facilitates the plotting of data in an XY graph with two Y axes.
12506: Puts plot definition data into the users environment in order for
12507: graph.png to plot it. Returns an <img> tag for the plot.
12508:
12509: Inputs:
12510:
12511: =over 4
12512:
12513: =item $Title: string, the title of the plot
12514:
12515: =item $xlabel: string, text describing the X-axis of the plot
12516:
12517: =item $ylabel: string, text describing the Y-axis of the plot
12518:
12519: =item $colors: Array ref containing the hex color codes for the data to be
12520: plotted in. If undefined, default values will be used.
12521:
12522: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12523:
12524: =item $Ydata1: The first data set
12525:
12526: =item $Min1: The minimum value of the left Y-axis
12527:
12528: =item $Max1: The maximum value of the left Y-axis
12529:
12530: =item $Ydata2: The second data set
12531:
12532: =item $Min2: The minimum value of the right Y-axis
12533:
12534: =item $Max2: The maximum value of the left Y-axis
12535:
12536: =item %Values: hash indicating or overriding any default values which are
12537: passed to graph.png.
12538: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12539:
12540: =back
12541:
12542: Returns:
12543:
12544: An <img> tag which references graph.png and the appropriate identifying
12545: information for the plot.
1.136 matthew 12546:
12547: =cut
12548:
12549: ############################################################
12550: ############################################################
1.137 matthew 12551: sub DrawXYYGraph {
12552: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
12553: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 12554: #
12555: # Create the identifier for the graph
12556: my $identifier = &get_cgi_id();
12557: my $id = 'cgi.'.$identifier;
12558: #
12559: $Title = '' if (! defined($Title));
12560: $xlabel = '' if (! defined($xlabel));
12561: $ylabel = '' if (! defined($ylabel));
12562: my %ValuesHash =
12563: (
1.369 www 12564: $id.'.title' => &escape($Title),
12565: $id.'.xlabel' => &escape($xlabel),
12566: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 12567: $id.'.labels' => join(',',@$Xlabels),
12568: $id.'.PlotType' => 'XY',
12569: $id.'.NumSets' => 2,
1.137 matthew 12570: $id.'.two_axes' => 1,
12571: $id.'.y1_max_value' => $Max1,
12572: $id.'.y1_min_value' => $Min1,
12573: $id.'.y2_max_value' => $Max2,
12574: $id.'.y2_min_value' => $Min2,
1.136 matthew 12575: );
12576: #
1.137 matthew 12577: if (defined($colors) && ref($colors) eq 'ARRAY') {
12578: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12579: }
12580: #
12581: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
12582: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 12583: return '';
12584: }
12585: my $NumSets=1;
1.137 matthew 12586: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 12587: next if (! ref($array));
12588: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 12589: }
12590: #
12591: # Deal with other parameters
12592: while (my ($key,$value) = each(%Values)) {
12593: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 12594: }
12595: #
1.646 raeburn 12596: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 12597: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 12598: }
12599:
12600: ############################################################
12601: ############################################################
12602:
12603: =pod
12604:
1.157 matthew 12605: =back
12606:
1.139 matthew 12607: =head1 Statistics helper routines?
12608:
12609: Bad place for them but what the hell.
12610:
1.157 matthew 12611: =over 4
12612:
1.648 raeburn 12613: =item * &chartlink()
1.139 matthew 12614:
12615: Returns a link to the chart for a specific student.
12616:
12617: Inputs:
12618:
12619: =over 4
12620:
12621: =item $linktext: The text of the link
12622:
12623: =item $sname: The students username
12624:
12625: =item $sdomain: The students domain
12626:
12627: =back
12628:
1.157 matthew 12629: =back
12630:
1.139 matthew 12631: =cut
12632:
12633: ############################################################
12634: ############################################################
12635: sub chartlink {
12636: my ($linktext, $sname, $sdomain) = @_;
12637: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 12638: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 12639: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 12640: '">'.$linktext.'</a>';
1.153 matthew 12641: }
12642:
12643: #######################################################
12644: #######################################################
12645:
12646: =pod
12647:
12648: =head1 Course Environment Routines
1.157 matthew 12649:
12650: =over 4
1.153 matthew 12651:
1.648 raeburn 12652: =item * &restore_course_settings()
1.153 matthew 12653:
1.648 raeburn 12654: =item * &store_course_settings()
1.153 matthew 12655:
12656: Restores/Store indicated form parameters from the course environment.
12657: Will not overwrite existing values of the form parameters.
12658:
12659: Inputs:
12660: a scalar describing the data (e.g. 'chart', 'problem_analysis')
12661:
12662: a hash ref describing the data to be stored. For example:
12663:
12664: %Save_Parameters = ('Status' => 'scalar',
12665: 'chartoutputmode' => 'scalar',
12666: 'chartoutputdata' => 'scalar',
12667: 'Section' => 'array',
1.373 raeburn 12668: 'Group' => 'array',
1.153 matthew 12669: 'StudentData' => 'array',
12670: 'Maps' => 'array');
12671:
12672: Returns: both routines return nothing
12673:
1.631 raeburn 12674: =back
12675:
1.153 matthew 12676: =cut
12677:
12678: #######################################################
12679: #######################################################
12680: sub store_course_settings {
1.496 albertel 12681: return &store_settings($env{'request.course.id'},@_);
12682: }
12683:
12684: sub store_settings {
1.153 matthew 12685: # save to the environment
12686: # appenv the same items, just to be safe
1.300 albertel 12687: my $udom = $env{'user.domain'};
12688: my $uname = $env{'user.name'};
1.496 albertel 12689: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12690: my %SaveHash;
12691: my %AppHash;
12692: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 12693: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 12694: my $envname = 'environment.'.$basename;
1.258 albertel 12695: if (exists($env{'form.'.$setting})) {
1.153 matthew 12696: # Save this value away
12697: if ($type eq 'scalar' &&
1.258 albertel 12698: (! exists($env{$envname}) ||
12699: $env{$envname} ne $env{'form.'.$setting})) {
12700: $SaveHash{$basename} = $env{'form.'.$setting};
12701: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 12702: } elsif ($type eq 'array') {
12703: my $stored_form;
1.258 albertel 12704: if (ref($env{'form.'.$setting})) {
1.153 matthew 12705: $stored_form = join(',',
12706: map {
1.369 www 12707: &escape($_);
1.258 albertel 12708: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 12709: } else {
12710: $stored_form =
1.369 www 12711: &escape($env{'form.'.$setting});
1.153 matthew 12712: }
12713: # Determine if the array contents are the same.
1.258 albertel 12714: if ($stored_form ne $env{$envname}) {
1.153 matthew 12715: $SaveHash{$basename} = $stored_form;
12716: $AppHash{$envname} = $stored_form;
12717: }
12718: }
12719: }
12720: }
12721: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 12722: $udom,$uname);
1.153 matthew 12723: if ($put_result !~ /^(ok|delayed)/) {
12724: &Apache::lonnet::logthis('unable to save form parameters, '.
12725: 'got error:'.$put_result);
12726: }
12727: # Make sure these settings stick around in this session, too
1.646 raeburn 12728: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 12729: return;
12730: }
12731:
12732: sub restore_course_settings {
1.499 albertel 12733: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 12734: }
12735:
12736: sub restore_settings {
12737: my ($context,$prefix,$Settings) = @_;
1.153 matthew 12738: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 12739: next if (exists($env{'form.'.$setting}));
1.496 albertel 12740: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 12741: '.'.$setting;
1.258 albertel 12742: if (exists($env{$envname})) {
1.153 matthew 12743: if ($type eq 'scalar') {
1.258 albertel 12744: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 12745: } elsif ($type eq 'array') {
1.258 albertel 12746: $env{'form.'.$setting} = [
1.153 matthew 12747: map {
1.369 www 12748: &unescape($_);
1.258 albertel 12749: } split(',',$env{$envname})
1.153 matthew 12750: ];
12751: }
12752: }
12753: }
1.127 matthew 12754: }
12755:
1.618 raeburn 12756: #######################################################
12757: #######################################################
12758:
12759: =pod
12760:
12761: =head1 Domain E-mail Routines
12762:
12763: =over 4
12764:
1.648 raeburn 12765: =item * &build_recipient_list()
1.618 raeburn 12766:
1.884 raeburn 12767: Build recipient lists for five types of e-mail:
1.766 raeburn 12768: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884 raeburn 12769: (d) Help requests, (e) Course requests needing approval, generated by
12770: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
12771: loncoursequeueadmin.pm respectively.
1.618 raeburn 12772:
12773: Inputs:
1.619 raeburn 12774: defmail (scalar - email address of default recipient),
1.618 raeburn 12775: mailing type (scalar - errormail, packagesmail, or helpdeskmail),
1.619 raeburn 12776: defdom (domain for which to retrieve configuration settings),
12777: origmail (scalar - email address of recipient from loncapa.conf,
12778: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 12779:
1.655 raeburn 12780: Returns: comma separated list of addresses to which to send e-mail.
12781:
12782: =back
1.618 raeburn 12783:
12784: =cut
12785:
12786: ############################################################
12787: ############################################################
12788: sub build_recipient_list {
1.619 raeburn 12789: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 12790: my @recipients;
12791: my $otheremails;
12792: my %domconfig =
12793: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
12794: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 12795: if (exists($domconfig{'contacts'}{$mailing})) {
12796: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
12797: my @contacts = ('adminemail','supportemail');
12798: foreach my $item (@contacts) {
12799: if ($domconfig{'contacts'}{$mailing}{$item}) {
12800: my $addr = $domconfig{'contacts'}{$item};
12801: if (!grep(/^\Q$addr\E$/,@recipients)) {
12802: push(@recipients,$addr);
12803: }
1.619 raeburn 12804: }
1.766 raeburn 12805: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 12806: }
12807: }
1.766 raeburn 12808: } elsif ($origmail ne '') {
12809: push(@recipients,$origmail);
1.618 raeburn 12810: }
1.619 raeburn 12811: } elsif ($origmail ne '') {
12812: push(@recipients,$origmail);
1.618 raeburn 12813: }
1.688 raeburn 12814: if (defined($defmail)) {
12815: if ($defmail ne '') {
12816: push(@recipients,$defmail);
12817: }
1.618 raeburn 12818: }
12819: if ($otheremails) {
1.619 raeburn 12820: my @others;
12821: if ($otheremails =~ /,/) {
12822: @others = split(/,/,$otheremails);
1.618 raeburn 12823: } else {
1.619 raeburn 12824: push(@others,$otheremails);
12825: }
12826: foreach my $addr (@others) {
12827: if (!grep(/^\Q$addr\E$/,@recipients)) {
12828: push(@recipients,$addr);
12829: }
1.618 raeburn 12830: }
12831: }
1.619 raeburn 12832: my $recipientlist = join(',',@recipients);
1.618 raeburn 12833: return $recipientlist;
12834: }
12835:
1.127 matthew 12836: ############################################################
12837: ############################################################
1.154 albertel 12838:
1.655 raeburn 12839: =pod
12840:
12841: =head1 Course Catalog Routines
12842:
12843: =over 4
12844:
12845: =item * &gather_categories()
12846:
12847: Converts category definitions - keys of categories hash stored in
12848: coursecategories in configuration.db on the primary library server in a
12849: domain - to an array. Also generates javascript and idx hash used to
12850: generate Domain Coordinator interface for editing Course Categories.
12851:
12852: Inputs:
1.663 raeburn 12853:
1.655 raeburn 12854: categories (reference to hash of category definitions).
1.663 raeburn 12855:
1.655 raeburn 12856: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12857: categories and subcategories).
1.663 raeburn 12858:
1.655 raeburn 12859: idx (reference to hash of counters used in Domain Coordinator interface for
12860: editing Course Categories).
1.663 raeburn 12861:
1.655 raeburn 12862: jsarray (reference to array of categories used to create Javascript arrays for
12863: Domain Coordinator interface for editing Course Categories).
12864:
12865: Returns: nothing
12866:
12867: Side effects: populates cats, idx and jsarray.
12868:
12869: =cut
12870:
12871: sub gather_categories {
12872: my ($categories,$cats,$idx,$jsarray) = @_;
12873: my %counters;
12874: my $num = 0;
12875: foreach my $item (keys(%{$categories})) {
12876: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12877: if ($container eq '' && $depth == 0) {
12878: $cats->[$depth][$categories->{$item}] = $cat;
12879: } else {
12880: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
12881: }
12882: my ($escitem,$tail) = split(/:/,$item,2);
12883: if ($counters{$tail} eq '') {
12884: $counters{$tail} = $num;
12885: $num ++;
12886: }
12887: if (ref($idx) eq 'HASH') {
12888: $idx->{$item} = $counters{$tail};
12889: }
12890: if (ref($jsarray) eq 'ARRAY') {
12891: push(@{$jsarray->[$counters{$tail}]},$item);
12892: }
12893: }
12894: return;
12895: }
12896:
12897: =pod
12898:
12899: =item * &extract_categories()
12900:
12901: Used to generate breadcrumb trails for course categories.
12902:
12903: Inputs:
1.663 raeburn 12904:
1.655 raeburn 12905: categories (reference to hash of category definitions).
1.663 raeburn 12906:
1.655 raeburn 12907: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12908: categories and subcategories).
1.663 raeburn 12909:
1.655 raeburn 12910: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 12911:
1.655 raeburn 12912: allitems (reference to hash - key is category key
12913: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12914:
1.655 raeburn 12915: idx (reference to hash of counters used in Domain Coordinator interface for
12916: editing Course Categories).
1.663 raeburn 12917:
1.655 raeburn 12918: jsarray (reference to array of categories used to create Javascript arrays for
12919: Domain Coordinator interface for editing Course Categories).
12920:
1.665 raeburn 12921: subcats (reference to hash of arrays containing all subcategories within each
12922: category, -recursive)
12923:
1.655 raeburn 12924: Returns: nothing
12925:
12926: Side effects: populates trails and allitems hash references.
12927:
12928: =cut
12929:
12930: sub extract_categories {
1.665 raeburn 12931: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 12932: if (ref($categories) eq 'HASH') {
12933: &gather_categories($categories,$cats,$idx,$jsarray);
12934: if (ref($cats->[0]) eq 'ARRAY') {
12935: for (my $i=0; $i<@{$cats->[0]}; $i++) {
12936: my $name = $cats->[0][$i];
12937: my $item = &escape($name).'::0';
12938: my $trailstr;
12939: if ($name eq 'instcode') {
12940: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 12941: } elsif ($name eq 'communities') {
12942: $trailstr = &mt('Communities');
1.655 raeburn 12943: } else {
12944: $trailstr = $name;
12945: }
12946: if ($allitems->{$item} eq '') {
12947: push(@{$trails},$trailstr);
12948: $allitems->{$item} = scalar(@{$trails})-1;
12949: }
12950: my @parents = ($name);
12951: if (ref($cats->[1]{$name}) eq 'ARRAY') {
12952: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
12953: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 12954: if (ref($subcats) eq 'HASH') {
12955: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
12956: }
12957: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
12958: }
12959: } else {
12960: if (ref($subcats) eq 'HASH') {
12961: $subcats->{$item} = [];
1.655 raeburn 12962: }
12963: }
12964: }
12965: }
12966: }
12967: return;
12968: }
12969:
12970: =pod
12971:
12972: =item *&recurse_categories()
12973:
12974: Recursively used to generate breadcrumb trails for course categories.
12975:
12976: Inputs:
1.663 raeburn 12977:
1.655 raeburn 12978: cats (reference to array of arrays/hashes which encapsulates hierarchy of
12979: categories and subcategories).
1.663 raeburn 12980:
1.655 raeburn 12981: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 12982:
12983: category (current course category, for which breadcrumb trail is being generated).
12984:
12985: trails (reference to array of breadcrumb trails for each category).
12986:
1.655 raeburn 12987: allitems (reference to hash - key is category key
12988: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 12989:
1.655 raeburn 12990: parents (array containing containers directories for current category,
12991: back to top level).
12992:
12993: Returns: nothing
12994:
12995: Side effects: populates trails and allitems hash references
12996:
12997: =cut
12998:
12999: sub recurse_categories {
1.665 raeburn 13000: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13001: my $shallower = $depth - 1;
13002: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13003: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13004: my $name = $cats->[$depth]{$category}[$k];
13005: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13006: my $trailstr = join(' -> ',(@{$parents},$category));
13007: if ($allitems->{$item} eq '') {
13008: push(@{$trails},$trailstr);
13009: $allitems->{$item} = scalar(@{$trails})-1;
13010: }
13011: my $deeper = $depth+1;
13012: push(@{$parents},$category);
1.665 raeburn 13013: if (ref($subcats) eq 'HASH') {
13014: my $subcat = &escape($name).':'.$category.':'.$depth;
13015: for (my $j=@{$parents}; $j>=0; $j--) {
13016: my $higher;
13017: if ($j > 0) {
13018: $higher = &escape($parents->[$j]).':'.
13019: &escape($parents->[$j-1]).':'.$j;
13020: } else {
13021: $higher = &escape($parents->[$j]).'::'.$j;
13022: }
13023: push(@{$subcats->{$higher}},$subcat);
13024: }
13025: }
13026: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13027: $subcats);
1.655 raeburn 13028: pop(@{$parents});
13029: }
13030: } else {
13031: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13032: my $trailstr = join(' -> ',(@{$parents},$category));
13033: if ($allitems->{$item} eq '') {
13034: push(@{$trails},$trailstr);
13035: $allitems->{$item} = scalar(@{$trails})-1;
13036: }
13037: }
13038: return;
13039: }
13040:
1.663 raeburn 13041: =pod
13042:
13043: =item *&assign_categories_table()
13044:
13045: Create a datatable for display of hierarchical categories in a domain,
13046: with checkboxes to allow a course to be categorized.
13047:
13048: Inputs:
13049:
13050: cathash - reference to hash of categories defined for the domain (from
13051: configuration.db)
13052:
13053: currcat - scalar with an & separated list of categories assigned to a course.
13054:
1.919 raeburn 13055: type - scalar contains course type (Course or Community).
13056:
1.663 raeburn 13057: Returns: $output (markup to be displayed)
13058:
13059: =cut
13060:
13061: sub assign_categories_table {
1.919 raeburn 13062: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13063: my $output;
13064: if (ref($cathash) eq 'HASH') {
13065: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13066: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13067: $maxdepth = scalar(@cats);
13068: if (@cats > 0) {
13069: my $itemcount = 0;
13070: if (ref($cats[0]) eq 'ARRAY') {
13071: my @currcategories;
13072: if ($currcat ne '') {
13073: @currcategories = split('&',$currcat);
13074: }
1.919 raeburn 13075: my $table;
1.663 raeburn 13076: for (my $i=0; $i<@{$cats[0]}; $i++) {
13077: my $parent = $cats[0][$i];
1.919 raeburn 13078: next if ($parent eq 'instcode');
13079: if ($type eq 'Community') {
13080: next unless ($parent eq 'communities');
13081: } else {
13082: next if ($parent eq 'communities');
13083: }
1.663 raeburn 13084: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13085: my $item = &escape($parent).'::0';
13086: my $checked = '';
13087: if (@currcategories > 0) {
13088: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13089: $checked = ' checked="checked"';
1.663 raeburn 13090: }
13091: }
1.919 raeburn 13092: my $parent_title = $parent;
13093: if ($parent eq 'communities') {
13094: $parent_title = &mt('Communities');
13095: }
13096: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13097: '<input type="checkbox" name="usecategory" value="'.
13098: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13099: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13100: my $depth = 1;
13101: push(@path,$parent);
1.919 raeburn 13102: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13103: pop(@path);
1.919 raeburn 13104: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13105: $itemcount ++;
13106: }
1.919 raeburn 13107: if ($itemcount) {
13108: $output = &Apache::loncommon::start_data_table().
13109: $table.
13110: &Apache::loncommon::end_data_table();
13111: }
1.663 raeburn 13112: }
13113: }
13114: }
13115: return $output;
13116: }
13117:
13118: =pod
13119:
13120: =item *&assign_category_rows()
13121:
13122: Create a datatable row for display of nested categories in a domain,
13123: with checkboxes to allow a course to be categorized,called recursively.
13124:
13125: Inputs:
13126:
13127: itemcount - track row number for alternating colors
13128:
13129: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13130: categories and subcategories.
13131:
13132: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13133:
13134: parent - parent of current category item
13135:
13136: path - Array containing all categories back up through the hierarchy from the
13137: current category to the top level.
13138:
13139: currcategories - reference to array of current categories assigned to the course
13140:
13141: Returns: $output (markup to be displayed).
13142:
13143: =cut
13144:
13145: sub assign_category_rows {
13146: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13147: my ($text,$name,$item,$chgstr);
13148: if (ref($cats) eq 'ARRAY') {
13149: my $maxdepth = scalar(@{$cats});
13150: if (ref($cats->[$depth]) eq 'HASH') {
13151: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13152: my $numchildren = @{$cats->[$depth]{$parent}};
13153: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13154: $text .= '<td><table class="LC_datatable">';
13155: for (my $j=0; $j<$numchildren; $j++) {
13156: $name = $cats->[$depth]{$parent}[$j];
13157: $item = &escape($name).':'.&escape($parent).':'.$depth;
13158: my $deeper = $depth+1;
13159: my $checked = '';
13160: if (ref($currcategories) eq 'ARRAY') {
13161: if (@{$currcategories} > 0) {
13162: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13163: $checked = ' checked="checked"';
1.663 raeburn 13164: }
13165: }
13166: }
1.664 raeburn 13167: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13168: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13169: $item.'"'.$checked.' />'.$name.'</label></span>'.
13170: '<input type="hidden" name="catname" value="'.$name.'" />'.
13171: '</td><td>';
1.663 raeburn 13172: if (ref($path) eq 'ARRAY') {
13173: push(@{$path},$name);
13174: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13175: pop(@{$path});
13176: }
13177: $text .= '</td></tr>';
13178: }
13179: $text .= '</table></td>';
13180: }
13181: }
13182: }
13183: return $text;
13184: }
13185:
1.655 raeburn 13186: ############################################################
13187: ############################################################
13188:
13189:
1.443 albertel 13190: sub commit_customrole {
1.664 raeburn 13191: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13192: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13193: ($start?', '.&mt('starting').' '.localtime($start):'').
13194: ($end?', ending '.localtime($end):'').': <b>'.
13195: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13196: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13197: '</b><br />';
13198: return $output;
13199: }
13200:
13201: sub commit_standardrole {
1.1116 raeburn 13202: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13203: my ($output,$logmsg,$linefeed);
13204: if ($context eq 'auto') {
13205: $linefeed = "\n";
13206: } else {
13207: $linefeed = "<br />\n";
13208: }
1.443 albertel 13209: if ($three eq 'st') {
1.541 raeburn 13210: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13211: $one,$two,$sec,$context,$credits);
1.541 raeburn 13212: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13213: ($result eq 'unknown_course') || ($result eq 'refused')) {
13214: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13215: } else {
1.541 raeburn 13216: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13217: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13218: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13219: if ($context eq 'auto') {
13220: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13221: } else {
13222: $output .= '<b>'.$result.'</b>'.$linefeed.
13223: &mt('Add to classlist').': <b>ok</b>';
13224: }
13225: $output .= $linefeed;
1.443 albertel 13226: }
13227: } else {
13228: $output = &mt('Assigning').' '.$three.' in '.$url.
13229: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13230: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13231: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13232: if ($context eq 'auto') {
13233: $output .= $result.$linefeed;
13234: } else {
13235: $output .= '<b>'.$result.'</b>'.$linefeed;
13236: }
1.443 albertel 13237: }
13238: return $output;
13239: }
13240:
13241: sub commit_studentrole {
1.1116 raeburn 13242: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13243: $credits) = @_;
1.626 raeburn 13244: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13245: if ($context eq 'auto') {
13246: $linefeed = "\n";
13247: } else {
13248: $linefeed = '<br />'."\n";
13249: }
1.443 albertel 13250: if (defined($one) && defined($two)) {
13251: my $cid=$one.'_'.$two;
13252: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13253: my $secchange = 0;
13254: my $expire_role_result;
13255: my $modify_section_result;
1.628 raeburn 13256: if ($oldsec ne '-1') {
13257: if ($oldsec ne $sec) {
1.443 albertel 13258: $secchange = 1;
1.628 raeburn 13259: my $now = time;
1.443 albertel 13260: my $uurl='/'.$cid;
13261: $uurl=~s/\_/\//g;
13262: if ($oldsec) {
13263: $uurl.='/'.$oldsec;
13264: }
1.626 raeburn 13265: $oldsecurl = $uurl;
1.628 raeburn 13266: $expire_role_result =
1.652 raeburn 13267: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13268: if ($env{'request.course.sec'} ne '') {
13269: if ($expire_role_result eq 'refused') {
13270: my @roles = ('st');
13271: my @statuses = ('previous');
13272: my @roledoms = ($one);
13273: my $withsec = 1;
13274: my %roleshash =
13275: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13276: \@statuses,\@roles,\@roledoms,$withsec);
13277: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13278: my ($oldstart,$oldend) =
13279: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13280: if ($oldend > 0 && $oldend <= $now) {
13281: $expire_role_result = 'ok';
13282: }
13283: }
13284: }
13285: }
1.443 albertel 13286: $result = $expire_role_result;
13287: }
13288: }
13289: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13290: $modify_section_result =
13291: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13292: undef,undef,undef,$sec,
13293: $end,$start,'','',$cid,
13294: '',$context,$credits);
1.443 albertel 13295: if ($modify_section_result =~ /^ok/) {
13296: if ($secchange == 1) {
1.628 raeburn 13297: if ($sec eq '') {
13298: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13299: } else {
13300: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13301: }
1.443 albertel 13302: } elsif ($oldsec eq '-1') {
1.628 raeburn 13303: if ($sec eq '') {
13304: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13305: } else {
13306: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13307: }
1.443 albertel 13308: } else {
1.628 raeburn 13309: if ($sec eq '') {
13310: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13311: } else {
13312: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13313: }
1.443 albertel 13314: }
13315: } else {
1.1115 raeburn 13316: if ($secchange) {
1.628 raeburn 13317: $$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;
13318: } else {
13319: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13320: }
1.443 albertel 13321: }
13322: $result = $modify_section_result;
13323: } elsif ($secchange == 1) {
1.628 raeburn 13324: if ($oldsec eq '') {
1.1103 raeburn 13325: $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_2] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
1.628 raeburn 13326: } else {
13327: $$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;
13328: }
1.626 raeburn 13329: if ($expire_role_result eq 'refused') {
13330: my $newsecurl = '/'.$cid;
13331: $newsecurl =~ s/\_/\//g;
13332: if ($sec ne '') {
13333: $newsecurl.='/'.$sec;
13334: }
13335: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13336: if ($sec eq '') {
13337: $$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;
13338: } else {
13339: $$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;
13340: }
13341: }
13342: }
1.443 albertel 13343: }
13344: } else {
1.626 raeburn 13345: $$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 13346: $result = "error: incomplete course id\n";
13347: }
13348: return $result;
13349: }
13350:
1.1108 raeburn 13351: sub show_role_extent {
13352: my ($scope,$context,$role) = @_;
13353: $scope =~ s{^/}{};
13354: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13355: push(@courseroles,'co');
13356: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13357: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13358: $scope =~ s{/}{_};
13359: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13360: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13361: my ($audom,$auname) = split(/\//,$scope);
13362: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13363: &Apache::loncommon::plainname($auname,$audom).'</span>');
13364: } else {
13365: $scope =~ s{/$}{};
13366: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13367: &Apache::lonnet::domain($scope,'description').'</span>');
13368: }
13369: }
13370:
1.443 albertel 13371: ############################################################
13372: ############################################################
13373:
1.566 albertel 13374: sub check_clone {
1.578 raeburn 13375: my ($args,$linefeed) = @_;
1.566 albertel 13376: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13377: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13378: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13379: my $clonemsg;
13380: my $can_clone = 0;
1.944 raeburn 13381: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13382: if ($lctype ne 'community') {
13383: $lctype = 'course';
13384: }
1.566 albertel 13385: if ($clonehome eq 'no_host') {
1.944 raeburn 13386: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13387: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
13388: } else {
13389: $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'});
13390: }
1.566 albertel 13391: } else {
13392: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13393: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13394: if ($clonedesc{'type'} ne 'Community') {
13395: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
13396: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13397: }
13398: }
1.882 raeburn 13399: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13400: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13401: $can_clone = 1;
13402: } else {
13403: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13404: $args->{'clonedomain'},$args->{'clonecourse'});
13405: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13406: if (grep(/^\*$/,@cloners)) {
13407: $can_clone = 1;
13408: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13409: $can_clone = 1;
13410: } else {
1.908 raeburn 13411: my $ccrole = 'cc';
1.944 raeburn 13412: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13413: $ccrole = 'co';
13414: }
1.578 raeburn 13415: my %roleshash =
13416: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13417: $args->{'ccdomain'},
1.908 raeburn 13418: 'userroles',['active'],[$ccrole],
1.578 raeburn 13419: [$args->{'clonedomain'}]);
1.908 raeburn 13420: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13421: $can_clone = 1;
13422: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13423: $can_clone = 1;
13424: } else {
1.944 raeburn 13425: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13426: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
13427: } else {
13428: $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'});
13429: }
1.578 raeburn 13430: }
1.566 albertel 13431: }
1.578 raeburn 13432: }
1.566 albertel 13433: }
13434: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13435: }
13436:
1.444 albertel 13437: sub construct_course {
1.885 raeburn 13438: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444 albertel 13439: my $outcome;
1.541 raeburn 13440: my $linefeed = '<br />'."\n";
13441: if ($context eq 'auto') {
13442: $linefeed = "\n";
13443: }
1.566 albertel 13444:
13445: #
13446: # Are we cloning?
13447: #
13448: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13449: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13450: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13451: if ($context ne 'auto') {
1.578 raeburn 13452: if ($clonemsg ne '') {
13453: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13454: }
1.566 albertel 13455: }
13456: $outcome .= $clonemsg.$linefeed;
13457:
13458: if (!$can_clone) {
13459: return (0,$outcome);
13460: }
13461: }
13462:
1.444 albertel 13463: #
13464: # Open course
13465: #
13466: my $crstype = lc($args->{'crstype'});
13467: my %cenv=();
13468: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13469: $args->{'cdescr'},
13470: $args->{'curl'},
13471: $args->{'course_home'},
13472: $args->{'nonstandard'},
13473: $args->{'crscode'},
13474: $args->{'ccuname'}.':'.
13475: $args->{'ccdomain'},
1.882 raeburn 13476: $args->{'crstype'},
1.885 raeburn 13477: $cnum,$context,$category);
1.444 albertel 13478:
13479: # Note: The testing routines depend on this being output; see
13480: # Utils::Course. This needs to at least be output as a comment
13481: # if anyone ever decides to not show this, and Utils::Course::new
13482: # will need to be suitably modified.
1.541 raeburn 13483: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13484: if ($$courseid =~ /^error:/) {
13485: return (0,$outcome);
13486: }
13487:
1.444 albertel 13488: #
13489: # Check if created correctly
13490: #
1.479 albertel 13491: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 13492: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 13493: if ($crsuhome eq 'no_host') {
13494: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
13495: return (0,$outcome);
13496: }
1.541 raeburn 13497: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 13498:
1.444 albertel 13499: #
1.566 albertel 13500: # Do the cloning
13501: #
13502: if ($can_clone && $cloneid) {
13503: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
13504: if ($context ne 'auto') {
13505: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
13506: }
13507: $outcome .= $clonemsg.$linefeed;
13508: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 13509: # Copy all files
1.637 www 13510: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 13511: # Restore URL
1.566 albertel 13512: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 13513: # Restore title
1.566 albertel 13514: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 13515: # Restore creation date, creator and creation context.
13516: $cenv{'internal.created'}=$oldcenv{'internal.created'};
13517: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
13518: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 13519: # Mark as cloned
1.566 albertel 13520: $cenv{'clonedfrom'}=$cloneid;
1.638 www 13521: # Need to clone grading mode
13522: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
13523: $cenv{'grading'}=$newenv{'grading'};
13524: # Do not clone these environment entries
13525: &Apache::lonnet::del('environment',
13526: ['default_enrollment_start_date',
13527: 'default_enrollment_end_date',
13528: 'question.email',
13529: 'policy.email',
13530: 'comment.email',
13531: 'pch.users.denied',
1.725 raeburn 13532: 'plc.users.denied',
13533: 'hidefromcat',
13534: 'categories'],
1.638 www 13535: $$crsudom,$$crsunum);
1.444 albertel 13536: }
1.566 albertel 13537:
1.444 albertel 13538: #
13539: # Set environment (will override cloned, if existing)
13540: #
13541: my @sections = ();
13542: my @xlists = ();
13543: if ($args->{'crstype'}) {
13544: $cenv{'type'}=$args->{'crstype'};
13545: }
13546: if ($args->{'crsid'}) {
13547: $cenv{'courseid'}=$args->{'crsid'};
13548: }
13549: if ($args->{'crscode'}) {
13550: $cenv{'internal.coursecode'}=$args->{'crscode'};
13551: }
13552: if ($args->{'crsquota'} ne '') {
13553: $cenv{'internal.coursequota'}=$args->{'crsquota'};
13554: } else {
13555: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
13556: }
13557: if ($args->{'ccuname'}) {
13558: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
13559: ':'.$args->{'ccdomain'};
13560: } else {
13561: $cenv{'internal.courseowner'} = $args->{'curruser'};
13562: }
1.1116 raeburn 13563: if ($args->{'defaultcredits'}) {
13564: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
13565: }
1.444 albertel 13566: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
13567: if ($args->{'crssections'}) {
13568: $cenv{'internal.sectionnums'} = '';
13569: if ($args->{'crssections'} =~ m/,/) {
13570: @sections = split/,/,$args->{'crssections'};
13571: } else {
13572: $sections[0] = $args->{'crssections'};
13573: }
13574: if (@sections > 0) {
13575: foreach my $item (@sections) {
13576: my ($sec,$gp) = split/:/,$item;
13577: my $class = $args->{'crscode'}.$sec;
13578: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
13579: $cenv{'internal.sectionnums'} .= $item.',';
13580: unless ($addcheck eq 'ok') {
13581: push @badclasses, $class;
13582: }
13583: }
13584: $cenv{'internal.sectionnums'} =~ s/,$//;
13585: }
13586: }
13587: # do not hide course coordinator from staff listing,
13588: # even if privileged
13589: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13590: # add crosslistings
13591: if ($args->{'crsxlist'}) {
13592: $cenv{'internal.crosslistings'}='';
13593: if ($args->{'crsxlist'} =~ m/,/) {
13594: @xlists = split/,/,$args->{'crsxlist'};
13595: } else {
13596: $xlists[0] = $args->{'crsxlist'};
13597: }
13598: if (@xlists > 0) {
13599: foreach my $item (@xlists) {
13600: my ($xl,$gp) = split/:/,$item;
13601: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
13602: $cenv{'internal.crosslistings'} .= $item.',';
13603: unless ($addcheck eq 'ok') {
13604: push @badclasses, $xl;
13605: }
13606: }
13607: $cenv{'internal.crosslistings'} =~ s/,$//;
13608: }
13609: }
13610: if ($args->{'autoadds'}) {
13611: $cenv{'internal.autoadds'}=$args->{'autoadds'};
13612: }
13613: if ($args->{'autodrops'}) {
13614: $cenv{'internal.autodrops'}=$args->{'autodrops'};
13615: }
13616: # check for notification of enrollment changes
13617: my @notified = ();
13618: if ($args->{'notify_owner'}) {
13619: if ($args->{'ccuname'} ne '') {
13620: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
13621: }
13622: }
13623: if ($args->{'notify_dc'}) {
13624: if ($uname ne '') {
1.630 raeburn 13625: push(@notified,$uname.':'.$udom);
1.444 albertel 13626: }
13627: }
13628: if (@notified > 0) {
13629: my $notifylist;
13630: if (@notified > 1) {
13631: $notifylist = join(',',@notified);
13632: } else {
13633: $notifylist = $notified[0];
13634: }
13635: $cenv{'internal.notifylist'} = $notifylist;
13636: }
13637: if (@badclasses > 0) {
13638: my %lt=&Apache::lonlocal::texthash(
13639: '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',
13640: 'dnhr' => 'does not have rights to access enrollment in these classes',
13641: 'adby' => 'as determined by the policies of your institution on access to official classlists'
13642: );
1.541 raeburn 13643: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
13644: ' ('.$lt{'adby'}.')';
13645: if ($context eq 'auto') {
13646: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 13647: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 13648: foreach my $item (@badclasses) {
13649: if ($context eq 'auto') {
13650: $outcome .= " - $item\n";
13651: } else {
13652: $outcome .= "<li>$item</li>\n";
13653: }
13654: }
13655: if ($context eq 'auto') {
13656: $outcome .= $linefeed;
13657: } else {
1.566 albertel 13658: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 13659: }
13660: }
1.444 albertel 13661: }
13662: if ($args->{'no_end_date'}) {
13663: $args->{'endaccess'} = 0;
13664: }
13665: $cenv{'internal.autostart'}=$args->{'enrollstart'};
13666: $cenv{'internal.autoend'}=$args->{'enrollend'};
13667: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
13668: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
13669: if ($args->{'showphotos'}) {
13670: $cenv{'internal.showphotos'}=$args->{'showphotos'};
13671: }
13672: $cenv{'internal.authtype'} = $args->{'authtype'};
13673: $cenv{'internal.autharg'} = $args->{'autharg'};
13674: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
13675: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 13676: 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');
13677: if ($context eq 'auto') {
13678: $outcome .= $krb_msg;
13679: } else {
1.566 albertel 13680: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 13681: }
13682: $outcome .= $linefeed;
1.444 albertel 13683: }
13684: }
13685: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
13686: if ($args->{'setpolicy'}) {
13687: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13688: }
13689: if ($args->{'setcontent'}) {
13690: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
13691: }
13692: }
13693: if ($args->{'reshome'}) {
13694: $cenv{'reshome'}=$args->{'reshome'}.'/';
13695: $cenv{'reshome'}=~s/\/+$/\//;
13696: }
13697: #
13698: # course has keyed access
13699: #
13700: if ($args->{'setkeys'}) {
13701: $cenv{'keyaccess'}='yes';
13702: }
13703: # if specified, key authority is not course, but user
13704: # only active if keyaccess is yes
13705: if ($args->{'keyauth'}) {
1.487 albertel 13706: my ($user,$domain) = split(':',$args->{'keyauth'});
13707: $user = &LONCAPA::clean_username($user);
13708: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 13709: if ($user ne '' && $domain ne '') {
1.487 albertel 13710: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 13711: }
13712: }
13713:
13714: if ($args->{'disresdis'}) {
13715: $cenv{'pch.roles.denied'}='st';
13716: }
13717: if ($args->{'disablechat'}) {
13718: $cenv{'plc.roles.denied'}='st';
13719: }
13720:
13721: # Record we've not yet viewed the Course Initialization Helper for this
13722: # course
13723: $cenv{'course.helper.not.run'} = 1;
13724: #
13725: # Use new Randomseed
13726: #
13727: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
13728: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
13729: #
13730: # The encryption code and receipt prefix for this course
13731: #
13732: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
13733: $cenv{'internal.encpref'}=100+int(9*rand(99));
13734: #
13735: # By default, use standard grading
13736: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
13737:
1.541 raeburn 13738: $outcome .= $linefeed.&mt('Setting environment').': '.
13739: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13740: #
13741: # Open all assignments
13742: #
13743: if ($args->{'openall'}) {
13744: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
13745: my %storecontent = ($storeunder => time,
13746: $storeunder.'.type' => 'date_start');
13747:
13748: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 13749: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 13750: }
13751: #
13752: # Set first page
13753: #
13754: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
13755: || ($cloneid)) {
1.445 albertel 13756: use LONCAPA::map;
1.444 albertel 13757: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 13758:
13759: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
13760: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
13761:
1.444 albertel 13762: $outcome .= ($fatal?$errtext:'read ok').' - ';
13763: my $title; my $url;
13764: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 13765: $title=&mt('Syllabus');
1.444 albertel 13766: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
13767: } else {
1.963 raeburn 13768: $title=&mt('Table of Contents');
1.444 albertel 13769: $url='/adm/navmaps';
13770: }
1.445 albertel 13771:
13772: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
13773: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
13774:
13775: if ($errtext) { $fatal=2; }
1.541 raeburn 13776: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 13777: }
1.566 albertel 13778:
13779: return (1,$outcome);
1.444 albertel 13780: }
13781:
13782: ############################################################
13783: ############################################################
13784:
1.953 droeschl 13785: #SD
13786: # only Community and Course, or anything else?
1.378 raeburn 13787: sub course_type {
13788: my ($cid) = @_;
13789: if (!defined($cid)) {
13790: $cid = $env{'request.course.id'};
13791: }
1.404 albertel 13792: if (defined($env{'course.'.$cid.'.type'})) {
13793: return $env{'course.'.$cid.'.type'};
1.378 raeburn 13794: } else {
13795: return 'Course';
1.377 raeburn 13796: }
13797: }
1.156 albertel 13798:
1.406 raeburn 13799: sub group_term {
13800: my $crstype = &course_type();
13801: my %names = (
13802: 'Course' => 'group',
1.865 raeburn 13803: 'Community' => 'group',
1.406 raeburn 13804: );
13805: return $names{$crstype};
13806: }
13807:
1.902 raeburn 13808: sub course_types {
13809: my @types = ('official','unofficial','community');
13810: my %typename = (
13811: official => 'Official course',
13812: unofficial => 'Unofficial course',
13813: community => 'Community',
13814: );
13815: return (\@types,\%typename);
13816: }
13817:
1.156 albertel 13818: sub icon {
13819: my ($file)=@_;
1.505 albertel 13820: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 13821: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 13822: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 13823: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
13824: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
13825: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13826: $curfext.".gif") {
13827: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
13828: $curfext.".gif";
13829: }
13830: }
1.249 albertel 13831: return &lonhttpdurl($iconname);
1.154 albertel 13832: }
1.84 albertel 13833:
1.575 albertel 13834: sub lonhttpdurl {
1.692 www 13835: #
13836: # Had been used for "small fry" static images on separate port 8080.
13837: # Modify here if lightweight http functionality desired again.
13838: # Currently eliminated due to increasing firewall issues.
13839: #
1.575 albertel 13840: my ($url)=@_;
1.692 www 13841: return $url;
1.215 albertel 13842: }
13843:
1.213 albertel 13844: sub connection_aborted {
13845: my ($r)=@_;
13846: $r->print(" ");$r->rflush();
13847: my $c = $r->connection;
13848: return $c->aborted();
13849: }
13850:
1.221 foxr 13851: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 13852: # strings as 'strings'.
13853: sub escape_single {
1.221 foxr 13854: my ($input) = @_;
1.223 albertel 13855: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 13856: $input =~ s/\'/\\\'/g; # Esacpe the 's....
13857: return $input;
13858: }
1.223 albertel 13859:
1.222 foxr 13860: # Same as escape_single, but escape's "'s This
13861: # can be used for "strings"
13862: sub escape_double {
13863: my ($input) = @_;
13864: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
13865: $input =~ s/\"/\\\"/g; # Esacpe the "s....
13866: return $input;
13867: }
1.223 albertel 13868:
1.222 foxr 13869: # Escapes the last element of a full URL.
13870: sub escape_url {
13871: my ($url) = @_;
1.238 raeburn 13872: my @urlslices = split(/\//, $url,-1);
1.369 www 13873: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 13874: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 13875: }
1.462 albertel 13876:
1.820 raeburn 13877: sub compare_arrays {
13878: my ($arrayref1,$arrayref2) = @_;
13879: my (@difference,%count);
13880: @difference = ();
13881: %count = ();
13882: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
13883: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
13884: foreach my $element (keys(%count)) {
13885: if ($count{$element} == 1) {
13886: push(@difference,$element);
13887: }
13888: }
13889: }
13890: return @difference;
13891: }
13892:
1.817 bisitz 13893: # -------------------------------------------------------- Initialize user login
1.462 albertel 13894: sub init_user_environment {
1.463 albertel 13895: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 13896: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
13897:
13898: my $public=($username eq 'public' && $domain eq 'public');
13899:
13900: # See if old ID present, if so, remove
13901:
1.1062 raeburn 13902: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 13903: my $now=time;
13904:
13905: if ($public) {
13906: my $max_public=100;
13907: my $oldest;
13908: my $oldest_time=0;
13909: for(my $next=1;$next<=$max_public;$next++) {
13910: if (-e $lonids."/publicuser_$next.id") {
13911: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
13912: if ($mtime<$oldest_time || !$oldest_time) {
13913: $oldest_time=$mtime;
13914: $oldest=$next;
13915: }
13916: } else {
13917: $cookie="publicuser_$next";
13918: last;
13919: }
13920: }
13921: if (!$cookie) { $cookie="publicuser_$oldest"; }
13922: } else {
1.463 albertel 13923: # if this isn't a robot, kill any existing non-robot sessions
13924: if (!$args->{'robot'}) {
13925: opendir(DIR,$lonids);
13926: while ($filename=readdir(DIR)) {
13927: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
13928: unlink($lonids.'/'.$filename);
13929: }
1.462 albertel 13930: }
1.463 albertel 13931: closedir(DIR);
1.462 albertel 13932: }
13933: # Give them a new cookie
1.463 albertel 13934: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 13935: : $now.$$.int(rand(10000)));
1.463 albertel 13936: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 13937:
13938: # Initialize roles
13939:
1.1062 raeburn 13940: ($userroles,$firstaccenv,$timerintenv) =
13941: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 13942: }
13943: # ------------------------------------ Check browser type and MathML capability
13944:
13945: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
13946: $clientunicode,$clientos) = &decode_user_agent($r);
13947:
13948: # ------------------------------------------------------------- Get environment
13949:
13950: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
13951: my ($tmp) = keys(%userenv);
13952: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
13953: } else {
13954: undef(%userenv);
13955: }
13956: if (($userenv{'interface'}) && (!$form->{'interface'})) {
13957: $form->{'interface'}=$userenv{'interface'};
13958: }
13959: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
13960:
13961: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 13962: foreach my $option ('interface','localpath','localres') {
13963: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 13964: }
13965: # --------------------------------------------------------- Write first profile
13966:
13967: {
13968: my %initial_env =
13969: ("user.name" => $username,
13970: "user.domain" => $domain,
13971: "user.home" => $authhost,
13972: "browser.type" => $clientbrowser,
13973: "browser.version" => $clientversion,
13974: "browser.mathml" => $clientmathml,
13975: "browser.unicode" => $clientunicode,
13976: "browser.os" => $clientos,
13977: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
13978: "request.course.fn" => '',
13979: "request.course.uri" => '',
13980: "request.course.sec" => '',
13981: "request.role" => 'cm',
13982: "request.role.adv" => $env{'user.adv'},
13983: "request.host" => $ENV{'REMOTE_ADDR'},);
13984:
13985: if ($form->{'localpath'}) {
13986: $initial_env{"browser.localpath"} = $form->{'localpath'};
13987: $initial_env{"browser.localres"} = $form->{'localres'};
13988: }
13989:
13990: if ($form->{'interface'}) {
13991: $form->{'interface'}=~s/\W//gs;
13992: $initial_env{"browser.interface"} = $form->{'interface'};
13993: $env{'browser.interface'}=$form->{'interface'};
13994: }
13995:
1.981 raeburn 13996: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 13997: my %domdef;
13998: unless ($domain eq 'public') {
13999: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14000: }
1.980 raeburn 14001:
1.1081 raeburn 14002: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14003: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14004: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14005: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14006: }
14007:
1.864 raeburn 14008: foreach my $crstype ('official','unofficial','community') {
1.765 raeburn 14009: $userenv{'canrequest.'.$crstype} =
14010: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14011: 'reload','requestcourses',
14012: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14013: }
14014:
1.1092 raeburn 14015: $userenv{'canrequest.author'} =
14016: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14017: 'reload','requestauthor',
14018: \%userenv,\%domdef,\%is_adv);
14019: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14020: $domain,$username);
14021: my $reqstatus = $reqauthor{'author_status'};
14022: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14023: if (ref($reqauthor{'author'}) eq 'HASH') {
14024: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14025: $reqauthor{'author'}{'timestamp'};
14026: }
14027: }
14028:
1.462 albertel 14029: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14030:
1.462 albertel 14031: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14032: &GDBM_WRCREAT(),0640)) {
14033: &_add_to_env(\%disk_env,\%initial_env);
14034: &_add_to_env(\%disk_env,\%userenv,'environment.');
14035: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14036: if (ref($firstaccenv) eq 'HASH') {
14037: &_add_to_env(\%disk_env,$firstaccenv);
14038: }
14039: if (ref($timerintenv) eq 'HASH') {
14040: &_add_to_env(\%disk_env,$timerintenv);
14041: }
1.463 albertel 14042: if (ref($args->{'extra_env'})) {
14043: &_add_to_env(\%disk_env,$args->{'extra_env'});
14044: }
1.462 albertel 14045: untie(%disk_env);
14046: } else {
1.705 tempelho 14047: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14048: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14049: return 'error: '.$!;
14050: }
14051: }
14052: $env{'request.role'}='cm';
14053: $env{'request.role.adv'}=$env{'user.adv'};
14054: $env{'browser.type'}=$clientbrowser;
14055:
14056: return $cookie;
14057:
14058: }
14059:
14060: sub _add_to_env {
14061: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14062: if (ref($env_data) eq 'HASH') {
14063: while (my ($key,$value) = each(%$env_data)) {
14064: $idf->{$prefix.$key} = $value;
14065: $env{$prefix.$key} = $value;
14066: }
1.462 albertel 14067: }
14068: }
14069:
1.685 tempelho 14070: # --- Get the symbolic name of a problem and the url
14071: sub get_symb {
14072: my ($request,$silent) = @_;
1.726 raeburn 14073: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14074: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14075: if ($symb eq '') {
14076: if (!$silent) {
1.1071 raeburn 14077: if (ref($request)) {
14078: $request->print("Unable to handle ambiguous references:$url:.");
14079: }
1.685 tempelho 14080: return ();
14081: }
14082: }
14083: &Apache::lonenc::check_decrypt(\$symb);
14084: return ($symb);
14085: }
14086:
14087: # --------------------------------------------------------------Get annotation
14088:
14089: sub get_annotation {
14090: my ($symb,$enc) = @_;
14091:
14092: my $key = $symb;
14093: if (!$enc) {
14094: $key =
14095: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14096: }
14097: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14098: return $annotation{$key};
14099: }
14100:
14101: sub clean_symb {
1.731 raeburn 14102: my ($symb,$delete_enc) = @_;
1.685 tempelho 14103:
14104: &Apache::lonenc::check_decrypt(\$symb);
14105: my $enc = $env{'request.enc'};
1.731 raeburn 14106: if ($delete_enc) {
1.730 raeburn 14107: delete($env{'request.enc'});
14108: }
1.685 tempelho 14109:
14110: return ($symb,$enc);
14111: }
1.462 albertel 14112:
1.990 raeburn 14113: sub build_release_hashes {
14114: my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
14115: return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
14116: (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
14117: (ref($randomizetry) eq 'HASH'));
14118: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14119: my ($item,$name,$value) = split(/:/,$key);
14120: if ($item eq 'parameter') {
14121: if (ref($checkparms->{$name}) eq 'ARRAY') {
14122: unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
14123: push(@{$checkparms->{$name}},$value);
14124: }
14125: } else {
14126: push(@{$checkparms->{$name}},$value);
14127: }
14128: } elsif ($item eq 'resourcetag') {
14129: if ($name eq 'responsetype') {
14130: $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
14131: }
14132: } elsif ($item eq 'course') {
14133: if ($name eq 'crstype') {
14134: $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
14135: }
14136: }
14137: }
14138: ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
14139: ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
14140: return;
14141: }
14142:
1.1083 raeburn 14143: sub update_content_constraints {
14144: my ($cdom,$cnum,$chome,$cid) = @_;
14145: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
14146: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
14147: my %checkresponsetypes;
14148: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
14149: my ($item,$name,$value) = split(/:/,$key);
14150: if ($item eq 'resourcetag') {
14151: if ($name eq 'responsetype') {
14152: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
14153: }
14154: }
14155: }
14156: my $navmap = Apache::lonnavmaps::navmap->new();
14157: if (defined($navmap)) {
14158: my %allresponses;
14159: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
14160: my %responses = $res->responseTypes();
14161: foreach my $key (keys(%responses)) {
14162: next unless(exists($checkresponsetypes{$key}));
14163: $allresponses{$key} += $responses{$key};
14164: }
14165: }
14166: foreach my $key (keys(%allresponses)) {
14167: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
14168: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
14169: ($reqdmajor,$reqdminor) = ($major,$minor);
14170: }
14171: }
14172: undef($navmap);
14173: }
14174: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
14175: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
14176: }
14177: return;
14178: }
14179:
1.1110 raeburn 14180: sub allmaps_incourse {
14181: my ($cdom,$cnum,$chome,$cid) = @_;
14182: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
14183: $cid = $env{'request.course.id'};
14184: $cdom = $env{'course.'.$cid.'.domain'};
14185: $cnum = $env{'course.'.$cid.'.num'};
14186: $chome = $env{'course.'.$cid.'.home'};
14187: }
14188: my %allmaps = ();
14189: my $lastchange =
14190: &Apache::lonnet::get_coursechange($cdom,$cnum);
14191: if ($lastchange > $env{'request.course.tied'}) {
14192: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
14193: unless ($ferr) {
14194: &update_content_constraints($cdom,$cnum,$chome,$cid);
14195: }
14196: }
14197: my $navmap = Apache::lonnavmaps::navmap->new();
14198: if (defined($navmap)) {
14199: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
14200: $allmaps{$res->src()} = 1;
14201: }
14202: }
14203: return \%allmaps;
14204: }
14205:
1.1083 raeburn 14206: sub parse_supplemental_title {
14207: my ($title) = @_;
14208:
14209: my ($foldertitle,$renametitle);
14210: if ($title =~ /&&&/) {
14211: $title = &HTML::Entites::decode($title);
14212: }
14213: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
14214: $renametitle=$4;
14215: my ($time,$uname,$udom) = ($1,$2,$3);
14216: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
14217: my $name = &plainname($uname,$udom);
14218: $name = &HTML::Entities::encode($name,'"<>&\'');
14219: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
14220: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
14221: $name.': <br />'.$foldertitle;
14222: }
14223: if (wantarray) {
14224: return ($title,$foldertitle,$renametitle);
14225: }
14226: return $title;
14227: }
14228:
1.1101 raeburn 14229: sub symb_to_docspath {
14230: my ($symb) = @_;
14231: return unless ($symb);
14232: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
14233: if ($resurl=~/\.(sequence|page)$/) {
14234: $mapurl=$resurl;
14235: } elsif ($resurl eq 'adm/navmaps') {
14236: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
14237: }
14238: my $mapresobj;
14239: my $navmap = Apache::lonnavmaps::navmap->new();
14240: if (ref($navmap)) {
14241: $mapresobj = $navmap->getResourceByUrl($mapurl);
14242: }
14243: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
14244: my $type=$2;
14245: my $path;
14246: if (ref($mapresobj)) {
14247: my $pcslist = $mapresobj->map_hierarchy();
14248: if ($pcslist ne '') {
14249: foreach my $pc (split(/,/,$pcslist)) {
14250: next if ($pc <= 1);
14251: my $res = $navmap->getByMapPc($pc);
14252: if (ref($res)) {
14253: my $thisurl = $res->src();
14254: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
14255: my $thistitle = $res->title();
14256: $path .= '&'.
14257: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
14258: &Apache::lonhtmlcommon::entity_encode($thistitle).
14259: ':'.$res->randompick().
14260: ':'.$res->randomout().
14261: ':'.$res->encrypted().
14262: ':'.$res->randomorder().
14263: ':'.$res->is_page();
14264: }
14265: }
14266: }
14267: $path =~ s/^\&//;
14268: my $maptitle = $mapresobj->title();
14269: if ($mapurl eq 'default') {
14270: $maptitle = 'Main Course Documents';
14271: }
14272: $path .= (($path ne '')? '&' : '').
14273: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14274: &Apache::lonhtmlcommon::entity_encode($maptitle).
14275: ':'.$mapresobj->randompick().
14276: ':'.$mapresobj->randomout().
14277: ':'.$mapresobj->encrypted().
14278: ':'.$mapresobj->randomorder().
14279: ':'.$mapresobj->is_page();
14280: } else {
14281: my $maptitle = &Apache::lonnet::gettitle($mapurl);
14282: my $ispage = (($type eq 'page')? 1 : '');
14283: if ($mapurl eq 'default') {
14284: $maptitle = 'Main Course Documents';
14285: }
14286: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
14287: &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
14288: }
14289: unless ($mapurl eq 'default') {
14290: $path = 'default&'.
14291: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
14292: ':::::&'.$path;
14293: }
14294: return $path;
14295: }
14296:
1.1094 raeburn 14297: sub captcha_display {
14298: my ($context,$lonhost) = @_;
14299: my ($output,$error);
14300: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14301: if ($captcha eq 'original') {
1.1094 raeburn 14302: $output = &create_captcha();
14303: unless ($output) {
14304: $error = 'captcha';
14305: }
14306: } elsif ($captcha eq 'recaptcha') {
14307: $output = &create_recaptcha($pubkey);
14308: unless ($output) {
1.1095 raeburn 14309: $error = 'recaptcha';
1.1094 raeburn 14310: }
14311: }
14312: return ($output,$error);
14313: }
14314:
14315: sub captcha_response {
14316: my ($context,$lonhost) = @_;
14317: my ($captcha_chk,$captcha_error);
14318: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 14319: if ($captcha eq 'original') {
1.1094 raeburn 14320: ($captcha_chk,$captcha_error) = &check_captcha();
14321: } elsif ($captcha eq 'recaptcha') {
14322: $captcha_chk = &check_recaptcha($privkey);
14323: } else {
14324: $captcha_chk = 1;
14325: }
14326: return ($captcha_chk,$captcha_error);
14327: }
14328:
14329: sub get_captcha_config {
14330: my ($context,$lonhost) = @_;
1.1095 raeburn 14331: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 14332: my $hostname = &Apache::lonnet::hostname($lonhost);
14333: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
14334: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 14335: if ($context eq 'usercreation') {
14336: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
14337: if (ref($domconfig{$context}) eq 'HASH') {
14338: $hashtocheck = $domconfig{$context}{'cancreate'};
14339: if (ref($hashtocheck) eq 'HASH') {
14340: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
14341: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
14342: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
14343: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
14344: }
14345: if ($privkey && $pubkey) {
14346: $captcha = 'recaptcha';
14347: } else {
14348: $captcha = 'original';
14349: }
14350: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
14351: $captcha = 'original';
14352: }
1.1094 raeburn 14353: }
1.1095 raeburn 14354: } else {
14355: $captcha = 'captcha';
14356: }
14357: } elsif ($context eq 'login') {
14358: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
14359: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
14360: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
14361: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 14362: if ($privkey && $pubkey) {
14363: $captcha = 'recaptcha';
1.1095 raeburn 14364: } else {
14365: $captcha = 'original';
1.1094 raeburn 14366: }
1.1095 raeburn 14367: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
14368: $captcha = 'original';
1.1094 raeburn 14369: }
14370: }
14371: return ($captcha,$pubkey,$privkey);
14372: }
14373:
14374: sub create_captcha {
14375: my %captcha_params = &captcha_settings();
14376: my ($output,$maxtries,$tries) = ('',10,0);
14377: while ($tries < $maxtries) {
14378: $tries ++;
14379: my $captcha = Authen::Captcha->new (
14380: output_folder => $captcha_params{'output_dir'},
14381: data_folder => $captcha_params{'db_dir'},
14382: );
14383: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
14384:
14385: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
14386: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
14387: &mt('Type in the letters/numbers shown below').' '.
14388: '<input type="text" size="5" name="code" value="" /><br />'.
14389: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" />';
14390: last;
14391: }
14392: }
14393: return $output;
14394: }
14395:
14396: sub captcha_settings {
14397: my %captcha_params = (
14398: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
14399: www_output_dir => "/captchaspool",
14400: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
14401: numchars => '5',
14402: );
14403: return %captcha_params;
14404: }
14405:
14406: sub check_captcha {
14407: my ($captcha_chk,$captcha_error);
14408: my $code = $env{'form.code'};
14409: my $md5sum = $env{'form.crypt'};
14410: my %captcha_params = &captcha_settings();
14411: my $captcha = Authen::Captcha->new(
14412: output_folder => $captcha_params{'output_dir'},
14413: data_folder => $captcha_params{'db_dir'},
14414: );
1.1109 raeburn 14415: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 14416: my %captcha_hash = (
14417: 0 => 'Code not checked (file error)',
14418: -1 => 'Failed: code expired',
14419: -2 => 'Failed: invalid code (not in database)',
14420: -3 => 'Failed: invalid code (code does not match crypt)',
14421: );
14422: if ($captcha_chk != 1) {
14423: $captcha_error = $captcha_hash{$captcha_chk}
14424: }
14425: return ($captcha_chk,$captcha_error);
14426: }
14427:
14428: sub create_recaptcha {
14429: my ($pubkey) = @_;
14430: my $captcha = Captcha::reCAPTCHA->new;
14431: return $captcha->get_options_setter({theme => 'white'})."\n".
14432: $captcha->get_html($pubkey).
14433: &mt('If either word is hard to read, [_1] will replace them.',
14434: '<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
14435: '<br /><br />';
14436: }
14437:
14438: sub check_recaptcha {
14439: my ($privkey) = @_;
14440: my $captcha_chk;
14441: my $captcha = Captcha::reCAPTCHA->new;
14442: my $captcha_result =
14443: $captcha->check_answer(
14444: $privkey,
14445: $ENV{'REMOTE_ADDR'},
14446: $env{'form.recaptcha_challenge_field'},
14447: $env{'form.recaptcha_response_field'},
14448: );
14449: if ($captcha_result->{is_valid}) {
14450: $captcha_chk = 1;
14451: }
14452: return $captcha_chk;
14453: }
14454:
1.41 ng 14455: =pod
14456:
14457: =back
14458:
1.112 bowersj2 14459: =cut
1.41 ng 14460:
1.112 bowersj2 14461: 1;
14462: __END__;
1.41 ng 14463:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>